Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit e743f57

Browse files
split up hal store into multiple files
1 parent b4eecb1 commit e743f57

File tree

11 files changed

+126
-74
lines changed

11 files changed

+126
-74
lines changed

src/SqlStreamStoreBrowser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const getSelfAlias = (links: HalLinks) =>
3333
.flatMap(rel => links[rel])
3434
.filter(({ rel }) => rel && rel.indexOf('streamStore:') === 0)
3535
.filter(
36-
({ rel, href }) =>
36+
({ href }) =>
3737
!!links.self.filter(link => link.href === href).length,
3838
)
3939
.map(({ rel }) => rel);
@@ -58,7 +58,7 @@ const state$ = createState<SqlStreamStoreBrowserState>(
5858
store.hal$.links$.map(links => ['_links', () => links]),
5959
store.hal$.forms$.map(forms => ['forms', () => forms]),
6060
store.hal$.loading$.map(loading => ['loading', () => loading]),
61-
store.hal$.mediaType$.map(mediaType => ['mediaType', () => mediaType]),
61+
store.mediaType$.map(mediaType => ['mediaType', () => mediaType]),
6262
themes.theme$.map(theme => ['theme', () => theme]),
6363
),
6464
obs.of({

src/stream-store/store/hal.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/stream-store/store/hal/body.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { HalResource } from '../../../types';
2+
import { hal, mediaTypes } from '../../../utils';
3+
import actions from '../../actions';
4+
import mediaType$ from '../mediaType';
5+
6+
const body$ = actions.get.response
7+
.zip(mediaType$)
8+
.filter(([, mediaType]) => mediaType === mediaTypes.hal)
9+
.map(([{ body }]) => hal.normalizeResource(body as HalResource));
10+
11+
export default body$;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { JSONSchema7 } from 'json-schema';
2+
import { HalResource } from 'types';
3+
import body$ from './body';
4+
5+
const isJsonSchema = (schema: JSONSchema7 & HalResource) =>
6+
schema && schema.$schema && schema.$schema.endsWith('schema#');
7+
8+
const forms$ = body$
9+
.map(({ _embedded }) => _embedded)
10+
.map(embedded =>
11+
Object.keys(embedded)
12+
.filter(rel => isJsonSchema(embedded[rel][0]))
13+
.reduce(
14+
(akk, rel) => ({
15+
...akk,
16+
[rel]: embedded[rel][0],
17+
}),
18+
// tslint:disable-next-line:no-object-literal-type-assertion
19+
{} as JSONSchema7,
20+
),
21+
);
22+
23+
export default forms$;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import body$ from './body';
2+
import forms$ from './forms';
3+
import links$ from './links';
4+
import loading$ from './loading';
5+
import url$ from './url';
6+
7+
export default {
8+
body$,
9+
forms$,
10+
links$,
11+
loading$,
12+
url$,
13+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { hal } from 'utils';
2+
import body$ from './body';
3+
import url$ from './url';
4+
5+
const links$ = body$
6+
.zip(url$)
7+
.map(([{ _links }, url]) => hal.resolveLinks(url, _links));
8+
9+
export default links$;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Observable as obs } from 'rxjs';
2+
import actions from '../../actions';
3+
4+
const verbs = Object.keys(actions);
5+
6+
const requests$ = obs.merge(
7+
...verbs.map((verb: keyof typeof actions) => actions[verb].request),
8+
);
9+
10+
const responses$ = obs.merge(
11+
...verbs.map((verb: keyof typeof actions) => actions[verb].response),
12+
);
13+
14+
const delayedRequests$ = requests$.delay(1000);
15+
16+
const loading$ = requests$
17+
.timestamp()
18+
.combineLatest(
19+
responses$.timestamp(),
20+
delayedRequests$.timestamp(),
21+
(
22+
{ timestamp: requestTs },
23+
{ timestamp: responseTs },
24+
{ timestamp: delayedTs },
25+
) =>
26+
requestTs > responseTs &&
27+
delayedTs > responseTs &&
28+
delayedTs >= requestTs,
29+
);
30+
31+
export default loading$;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createAction } from 'reactive';
2+
import { Observable } from 'rxjs';
3+
import rels from 'stream-store/rels';
4+
import uriTemplate from 'uri-template';
5+
import links$ from './links';
6+
7+
const isPotentialStreamId = (data: any) =>
8+
typeof data === 'number' || typeof data === 'string';
9+
10+
const clickPotentialStreamId = createAction<any>().filter(
11+
isPotentialStreamId,
12+
) as Observable<number | string>;
13+
14+
const pattern$ = Observable.merge(
15+
clickPotentialStreamId.map(pattern => pattern),
16+
clickPotentialStreamId.map(pattern => String(pattern).replace(/-/g, '')),
17+
).distinct();
18+
19+
const template$ = links$
20+
.filter(links => !!links[rels.browse])
21+
.map(links => links[rels.browse][0])
22+
.map(link => uriTemplate.parse(decodeURI(link.href)));
23+
24+
pattern$.combineLatest(template$, (p, template) => ({
25+
headers: { authorization: '' },
26+
link: {
27+
href: template.expand({ p, t: 'e' }),
28+
},
29+
}));

src/stream-store/store/hal/url.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import actions from '../../actions';
2+
3+
const url$ = actions.get.response.map(({ url }) => url);
4+
5+
export default url$;

src/stream-store/store/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import hal$ from './hal';
22
import markdown$ from './markdown';
3+
import mediaType$ from './mediaType';
34

45
export default {
56
hal$,
67
markdown$,
8+
mediaType$,
79
};

0 commit comments

Comments
 (0)