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

Refactor and Update Dependencies #77

Merged
merged 2 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SqlStreamStoreBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getSelfAlias = (links: HalLinks) =>
.flatMap(rel => links[rel])
.filter(({ rel }) => rel && rel.indexOf('streamStore:') === 0)
.filter(
({ rel, href }) =>
({ href }) =>
!!links.self.filter(link => link.href === href).length,
)
.map(({ rel }) => rel);
Expand All @@ -58,7 +58,7 @@ const state$ = createState<SqlStreamStoreBrowserState>(
store.hal$.links$.map(links => ['_links', () => links]),
store.hal$.forms$.map(forms => ['forms', () => forms]),
store.hal$.loading$.map(loading => ['loading', () => loading]),
store.hal$.mediaType$.map(mediaType => ['mediaType', () => mediaType]),
store.mediaType$.map(mediaType => ['mediaType', () => mediaType]),
themes.theme$.map(theme => ['theme', () => theme]),
),
obs.of({
Expand Down
4 changes: 2 additions & 2 deletions src/components/AuthorizationProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { ComponentType, ReactNode, StatelessComponent } from 'react';
import React, { ComponentType, FunctionComponent, ReactNode } from 'react';
import { AuthorizationProps } from 'types';
import getDisplayName from './getDisplayName';

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

const AuthorizationProvider: StatelessComponent<
const AuthorizationProvider: FunctionComponent<
AuthorizationProps & {
children: ReactNode;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/HyperMediaControls/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@material-ui/core';
import { SlideProps } from '@material-ui/core/Slide';
import RelIcon from 'components/RelIcon';
import React, { FormEvent, PureComponent, StatelessComponent } from 'react';
import React, { FormEvent, FunctionComponent, PureComponent } from 'react';
import { HalLink } from 'types';
import HelpButton from './HelpButton';
import RelButton from './RelButton';
Expand All @@ -22,7 +22,7 @@ const styles = (theme: Theme) => ({
},
});

const SlideUp: StatelessComponent<SlideProps> = props => (
const SlideUp: FunctionComponent<SlideProps> = props => (
<Slide direction={'up'} {...props} />
);

Expand Down
4 changes: 2 additions & 2 deletions src/components/HyperMediaControls/RelButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Button } from '@material-ui/core';
import { ButtonProps } from '@material-ui/core/Button';
import RelIcon from 'components/RelIcon';
import React, { StatelessComponent } from 'react';
import React, { FunctionComponent } from 'react';

interface RelButtonProps {
rel: string;
title?: string;
}

const RelButton: StatelessComponent<RelButtonProps & ButtonProps> = ({
const RelButton: FunctionComponent<RelButtonProps & ButtonProps> = ({
rel,
onClick,
title,
Expand Down
4 changes: 2 additions & 2 deletions src/components/NavigationLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { IconButton } from '@material-ui/core';
import React, {
ComponentType,
FormEventHandler,
FunctionComponent,
PureComponent,
StatelessComponent,
} from 'react';
import { navigation } from 'stream-store';
import { HalLink, HalLinks, NavigatableProps } from 'types';
Expand Down Expand Up @@ -45,7 +45,7 @@ interface NavigationLinksProps {
_links: HalLinks;
}

const NavigationLinks: StatelessComponent<NavigationLinksProps> = ({
const NavigationLinks: FunctionComponent<NavigationLinksProps> = ({
_links,
}) => (
<nav>
Expand Down
4 changes: 2 additions & 2 deletions src/components/NavigationProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ComponentType, ReactNode, StatelessComponent } from 'react';
import React, { ComponentType, FunctionComponent, ReactNode } from 'react';
import { NavigatableProps, NavigationHandler } from 'types';
import getDisplayName from './getDisplayName';

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

const NavigationProvider: StatelessComponent<{
const NavigationProvider: FunctionComponent<{
onNavigate: NavigationHandler;
children: ReactNode;
}> = ({ onNavigate, children }) => (
Expand Down
6 changes: 3 additions & 3 deletions src/stream-store/Viewer/HalViewer/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Table } from 'components';
import inflector from 'inflector-js';
import React, { ComponentType, StatelessComponent } from 'react';
import React, { ComponentType, FunctionComponent } from 'react';
import { connect, createState } from 'reactive';
import { Observable as obs } from 'rxjs';
import rels from 'stream-store/rels';
Expand Down Expand Up @@ -63,7 +63,7 @@ const state$ = createState<IndexState>(
obs.of<IndexState>({ recent: [], info: [] }),
);

const InfoLine: StatelessComponent<InfoLineProps> = ({ id, value }) => (
const InfoLine: FunctionComponent<InfoLineProps> = ({ id, value }) => (
<Table.Row>
<Table.Cell>
<strong>{id}</strong>
Expand All @@ -72,7 +72,7 @@ const InfoLine: StatelessComponent<InfoLineProps> = ({ id, value }) => (
</Table.Row>
);

const Info: StatelessComponent<InfoState> = ({ info }) => (
const Info: FunctionComponent<InfoState> = ({ info }) => (
<Table>
<Table.Head>
<Table.Row>
Expand Down
4 changes: 2 additions & 2 deletions src/stream-store/Viewer/HalViewer/Stream.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table } from 'components';
import React, { ComponentType, StatelessComponent } from 'react';
import React, { ComponentType, FunctionComponent } from 'react';
import { connect, createState } from 'reactive';
import { Observable as obs } from 'rxjs';
import rels from 'stream-store/rels';
Expand Down Expand Up @@ -37,7 +37,7 @@ interface MessagesState {
messages: Array<Message & HalResource>;
}

const Messages: StatelessComponent<MessagesState> = ({ messages }) => (
const Messages: FunctionComponent<MessagesState> = ({ messages }) => (
<Table>
<StreamHeader />
<Table.Body>
Expand Down
6 changes: 3 additions & 3 deletions src/stream-store/Viewer/HalViewer/StreamMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hyperlink, Table } from 'components';
import React, { CSSProperties, StatelessComponent } from 'react';
import React, { CSSProperties, FunctionComponent } from 'react';
import { connect, createState } from 'reactive';
import { Observable as obs } from 'rxjs';
import rels from 'stream-store/rels';
Expand Down Expand Up @@ -49,7 +49,7 @@ interface StreamMetadataDetailsProps {
_links: HalLinks;
}

const StreamMetadataDetails: StatelessComponent<StreamMetadataDetailsProps> = ({
const StreamMetadataDetails: FunctionComponent<StreamMetadataDetailsProps> = ({
streamId,
maxAge,
maxCount,
Expand All @@ -68,7 +68,7 @@ const StreamMetadataDetails: StatelessComponent<StreamMetadataDetailsProps> = ({
</Table.Row>
);

const StreamMetadata: StatelessComponent<
const StreamMetadata: FunctionComponent<
StreamMetadataState & HalViewerProps
> = ({ metadata }) => (
<section>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hyperlink, Table } from 'components';
import React, { CSSProperties, StatelessComponent } from 'react';
import React, { CSSProperties, FunctionComponent } from 'react';
import rels from 'stream-store/rels';
import { HalResource } from 'types';

Expand All @@ -14,7 +14,7 @@ interface StreamMessageDetailsProps {
type: string;
}

const StreamMessageDetails: StatelessComponent<
const StreamMessageDetails: FunctionComponent<
StreamMessageDetailsProps & HalResource
> = ({
messageId,
Expand Down
4 changes: 2 additions & 2 deletions src/stream-store/Viewer/HalViewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HyperMediaControls, NavigationLinks } from 'components';
import React, { ComponentType, createElement, StatelessComponent } from 'react';
import React, { ComponentType, createElement, FunctionComponent } from 'react';
import actions from 'stream-store/actions';
import rels from 'stream-store/rels';
import Home from './Home';
Expand All @@ -26,7 +26,7 @@ const views: { [rel: string]: ComponentType<HalViewerProps> } = {
_unrecognized: Unrecognized,
};

const HalViewer: StatelessComponent<HalViewerProps> = ({
const HalViewer: FunctionComponent<HalViewerProps> = ({
forms,
_links,
self,
Expand Down
71 changes: 0 additions & 71 deletions src/stream-store/store/hal.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/stream-store/store/hal/body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HalResource } from '../../../types';
import { hal, mediaTypes } from '../../../utils';
import actions from '../../actions';
import mediaType$ from '../mediaType';

const body$ = actions.get.response
.zip(mediaType$)
.filter(([, mediaType]) => mediaType === mediaTypes.hal)
.map(([{ body }]) => hal.normalizeResource(body as HalResource));

export default body$;
23 changes: 23 additions & 0 deletions src/stream-store/store/hal/forms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { JSONSchema7 } from 'json-schema';
import { HalResource } from 'types';
import body$ from './body';

const isJsonSchema = (schema: JSONSchema7 & HalResource) =>
schema && schema.$schema && schema.$schema.endsWith('schema#');

const forms$ = body$
.map(({ _embedded }) => _embedded)
.map(embedded =>
Object.keys(embedded)
.filter(rel => isJsonSchema(embedded[rel][0]))
.reduce(
(akk, rel) => ({
...akk,
[rel]: embedded[rel][0],
}),
// tslint:disable-next-line:no-object-literal-type-assertion
{} as JSONSchema7,
),
);

export default forms$;
13 changes: 13 additions & 0 deletions src/stream-store/store/hal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import body$ from './body';
import forms$ from './forms';
import links$ from './links';
import loading$ from './loading';
import url$ from './url';

export default {
body$,
forms$,
links$,
loading$,
url$,
};
9 changes: 9 additions & 0 deletions src/stream-store/store/hal/links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { hal } from 'utils';
import body$ from './body';
import url$ from './url';

const links$ = body$
.zip(url$)
.map(([{ _links }, url]) => hal.resolveLinks(url, _links));

export default links$;
31 changes: 31 additions & 0 deletions src/stream-store/store/hal/loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Observable as obs } from 'rxjs';
import actions from '../../actions';

const verbs = Object.keys(actions);

const requests$ = obs.merge(
...verbs.map((verb: keyof typeof actions) => actions[verb].request),
);

const responses$ = obs.merge(
...verbs.map((verb: keyof typeof actions) => actions[verb].response),
);

const delayedRequests$ = requests$.delay(1000);

const loading$ = requests$
.timestamp()
.combineLatest(
responses$.timestamp(),
delayedRequests$.timestamp(),
(
{ timestamp: requestTs },
{ timestamp: responseTs },
{ timestamp: delayedTs },
) =>
requestTs > responseTs &&
delayedTs > responseTs &&
delayedTs >= requestTs,
);

export default loading$;
29 changes: 29 additions & 0 deletions src/stream-store/store/hal/streamBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createAction } from 'reactive';
import { Observable } from 'rxjs';
import rels from 'stream-store/rels';
import uriTemplate from 'uri-template';
import links$ from './links';

const isPotentialStreamId = (data: any) =>
typeof data === 'number' || typeof data === 'string';

const clickPotentialStreamId = createAction<any>().filter(
isPotentialStreamId,
) as Observable<number | string>;

const pattern$ = Observable.merge(
clickPotentialStreamId.map(pattern => pattern),
clickPotentialStreamId.map(pattern => String(pattern).replace(/-/g, '')),
).distinct();

const template$ = links$
.filter(links => !!links[rels.browse])
.map(links => links[rels.browse][0])
.map(link => uriTemplate.parse(decodeURI(link.href)));

pattern$.combineLatest(template$, (p, template) => ({
headers: { authorization: '' },
link: {
href: template.expand({ p, t: 'e' }),
},
}));
Loading