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

Commit 7eaf543

Browse files
Merge pull request #77 from thefringeninja/moving
Refactor and Update Dependencies
2 parents ca370ea + cef198e commit 7eaf543

21 files changed

+148
-96
lines changed

Diff for: src/SqlStreamStoreBrowser.tsx

+2-2
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({

Diff for: src/components/AuthorizationProvider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { ComponentType, ReactNode, StatelessComponent } from 'react';
1+
import React, { ComponentType, FunctionComponent, ReactNode } from 'react';
22
import { AuthorizationProps } from 'types';
33
import getDisplayName from './getDisplayName';
44

55
const { Consumer, Provider } = React.createContext<string | undefined>(
66
undefined,
77
);
88

9-
const AuthorizationProvider: StatelessComponent<
9+
const AuthorizationProvider: FunctionComponent<
1010
AuthorizationProps & {
1111
children: ReactNode;
1212
}

Diff for: src/components/HyperMediaControls/Dialog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@material-ui/core';
1212
import { SlideProps } from '@material-ui/core/Slide';
1313
import RelIcon from 'components/RelIcon';
14-
import React, { FormEvent, PureComponent, StatelessComponent } from 'react';
14+
import React, { FormEvent, FunctionComponent, PureComponent } from 'react';
1515
import { HalLink } from 'types';
1616
import HelpButton from './HelpButton';
1717
import RelButton from './RelButton';
@@ -22,7 +22,7 @@ const styles = (theme: Theme) => ({
2222
},
2323
});
2424

25-
const SlideUp: StatelessComponent<SlideProps> = props => (
25+
const SlideUp: FunctionComponent<SlideProps> = props => (
2626
<Slide direction={'up'} {...props} />
2727
);
2828

Diff for: src/components/HyperMediaControls/RelButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Button } from '@material-ui/core';
22
import { ButtonProps } from '@material-ui/core/Button';
33
import RelIcon from 'components/RelIcon';
4-
import React, { StatelessComponent } from 'react';
4+
import React, { FunctionComponent } from 'react';
55

66
interface RelButtonProps {
77
rel: string;
88
title?: string;
99
}
1010

11-
const RelButton: StatelessComponent<RelButtonProps & ButtonProps> = ({
11+
const RelButton: FunctionComponent<RelButtonProps & ButtonProps> = ({
1212
rel,
1313
onClick,
1414
title,

Diff for: src/components/NavigationLinks.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { IconButton } from '@material-ui/core';
22
import React, {
33
ComponentType,
44
FormEventHandler,
5+
FunctionComponent,
56
PureComponent,
6-
StatelessComponent,
77
} from 'react';
88
import { navigation } from 'stream-store';
99
import { HalLink, HalLinks, NavigatableProps } from 'types';
@@ -45,7 +45,7 @@ interface NavigationLinksProps {
4545
_links: HalLinks;
4646
}
4747

48-
const NavigationLinks: StatelessComponent<NavigationLinksProps> = ({
48+
const NavigationLinks: FunctionComponent<NavigationLinksProps> = ({
4949
_links,
5050
}) => (
5151
<nav>

Diff for: src/components/NavigationProvider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ComponentType, ReactNode, StatelessComponent } from 'react';
1+
import React, { ComponentType, FunctionComponent, ReactNode } from 'react';
22
import { NavigatableProps, NavigationHandler } from 'types';
33
import getDisplayName from './getDisplayName';
44

@@ -10,7 +10,7 @@ const { Consumer, Provider } = React.createContext<NavigationHandler>(
1010
defaultNavigationHandler,
1111
);
1212

13-
const NavigationProvider: StatelessComponent<{
13+
const NavigationProvider: FunctionComponent<{
1414
onNavigate: NavigationHandler;
1515
children: ReactNode;
1616
}> = ({ onNavigate, children }) => (

Diff for: src/stream-store/Viewer/HalViewer/Home.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Table } from 'components';
22
import inflector from 'inflector-js';
3-
import React, { ComponentType, StatelessComponent } from 'react';
3+
import React, { ComponentType, FunctionComponent } from 'react';
44
import { connect, createState } from 'reactive';
55
import { Observable as obs } from 'rxjs';
66
import rels from 'stream-store/rels';
@@ -63,7 +63,7 @@ const state$ = createState<IndexState>(
6363
obs.of<IndexState>({ recent: [], info: [] }),
6464
);
6565

66-
const InfoLine: StatelessComponent<InfoLineProps> = ({ id, value }) => (
66+
const InfoLine: FunctionComponent<InfoLineProps> = ({ id, value }) => (
6767
<Table.Row>
6868
<Table.Cell>
6969
<strong>{id}</strong>
@@ -72,7 +72,7 @@ const InfoLine: StatelessComponent<InfoLineProps> = ({ id, value }) => (
7272
</Table.Row>
7373
);
7474

75-
const Info: StatelessComponent<InfoState> = ({ info }) => (
75+
const Info: FunctionComponent<InfoState> = ({ info }) => (
7676
<Table>
7777
<Table.Head>
7878
<Table.Row>

Diff for: src/stream-store/Viewer/HalViewer/Stream.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Table } from 'components';
2-
import React, { ComponentType, StatelessComponent } from 'react';
2+
import React, { ComponentType, FunctionComponent } from 'react';
33
import { connect, createState } from 'reactive';
44
import { Observable as obs } from 'rxjs';
55
import rels from 'stream-store/rels';
@@ -37,7 +37,7 @@ interface MessagesState {
3737
messages: Array<Message & HalResource>;
3838
}
3939

40-
const Messages: StatelessComponent<MessagesState> = ({ messages }) => (
40+
const Messages: FunctionComponent<MessagesState> = ({ messages }) => (
4141
<Table>
4242
<StreamHeader />
4343
<Table.Body>

Diff for: src/stream-store/Viewer/HalViewer/StreamMetadata.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hyperlink, Table } from 'components';
2-
import React, { CSSProperties, StatelessComponent } from 'react';
2+
import React, { CSSProperties, FunctionComponent } from 'react';
33
import { connect, createState } from 'reactive';
44
import { Observable as obs } from 'rxjs';
55
import rels from 'stream-store/rels';
@@ -49,7 +49,7 @@ interface StreamMetadataDetailsProps {
4949
_links: HalLinks;
5050
}
5151

52-
const StreamMetadataDetails: StatelessComponent<StreamMetadataDetailsProps> = ({
52+
const StreamMetadataDetails: FunctionComponent<StreamMetadataDetailsProps> = ({
5353
streamId,
5454
maxAge,
5555
maxCount,
@@ -68,7 +68,7 @@ const StreamMetadataDetails: StatelessComponent<StreamMetadataDetailsProps> = ({
6868
</Table.Row>
6969
);
7070

71-
const StreamMetadata: StatelessComponent<
71+
const StreamMetadata: FunctionComponent<
7272
StreamMetadataState & HalViewerProps
7373
> = ({ metadata }) => (
7474
<section>

Diff for: src/stream-store/Viewer/HalViewer/components/StreamMessageDetails.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hyperlink, Table } from 'components';
2-
import React, { CSSProperties, StatelessComponent } from 'react';
2+
import React, { CSSProperties, FunctionComponent } from 'react';
33
import rels from 'stream-store/rels';
44
import { HalResource } from 'types';
55

@@ -14,7 +14,7 @@ interface StreamMessageDetailsProps {
1414
type: string;
1515
}
1616

17-
const StreamMessageDetails: StatelessComponent<
17+
const StreamMessageDetails: FunctionComponent<
1818
StreamMessageDetailsProps & HalResource
1919
> = ({
2020
messageId,

Diff for: src/stream-store/Viewer/HalViewer/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HyperMediaControls, NavigationLinks } from 'components';
2-
import React, { ComponentType, createElement, StatelessComponent } from 'react';
2+
import React, { ComponentType, createElement, FunctionComponent } from 'react';
33
import actions from 'stream-store/actions';
44
import rels from 'stream-store/rels';
55
import Home from './Home';
@@ -26,7 +26,7 @@ const views: { [rel: string]: ComponentType<HalViewerProps> } = {
2626
_unrecognized: Unrecognized,
2727
};
2828

29-
const HalViewer: StatelessComponent<HalViewerProps> = ({
29+
const HalViewer: FunctionComponent<HalViewerProps> = ({
3030
forms,
3131
_links,
3232
self,

Diff for: src/stream-store/store/hal.ts

-71
This file was deleted.

Diff for: src/stream-store/store/hal/body.ts

+11
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$;

Diff for: src/stream-store/store/hal/forms.ts

+23
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$;

Diff for: src/stream-store/store/hal/index.ts

+13
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+
};

Diff for: src/stream-store/store/hal/links.ts

+9
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$;

Diff for: src/stream-store/store/hal/loading.ts

+31
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$;

Diff for: src/stream-store/store/hal/streamBrowser.ts

+29
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+
}));

0 commit comments

Comments
 (0)