From bdaa4599366a727148b94489e2112dbe0a7dafa2 Mon Sep 17 00:00:00 2001 From: Christian Musa <1450075+crash7@users.noreply.github.com> Date: Mon, 7 Oct 2019 14:55:50 -0300 Subject: [PATCH] fix: add missing flow types (#33) --- .../flow-typed/asyncComponent_vx.x.x.js | 91 +++++++++ .../flow-typed/beforeComponent_vx.x.x.js | 182 ++++++++++++++++++ .../flow-typed/documentComponent_vx.x.x.js | 100 ++++++++++ .../client/flow-typed/ensureReady_vx.x.x.js | 105 ++++++++++ .../flow-typed/errorComponent_vx.x.x.js | 11 ++ .../fetchInitialPropsFromRoutes_vx.x.x.js | 121 ++++++++++++ packages/client/flow-typed/render_vx.x.x.js | 138 +++++++++++++ .../flow-typed/asyncComponent_vx.x.x.js | 91 +++++++++ .../flow-typed/beforeComponent_vx.x.x.js | 182 ++++++++++++++++++ .../flow-typed/documentComponent_vx.x.x.js | 100 ++++++++++ .../server/flow-typed/ensureReady_vx.x.x.js | 105 ++++++++++ .../flow-typed/errorComponent_vx.x.x.js | 11 ++ .../fetchInitialPropsFromRoutes_vx.x.x.js | 121 ++++++++++++ packages/server/flow-typed/render_vx.x.x.js | 138 +++++++++++++ 14 files changed, 1496 insertions(+) create mode 100644 packages/client/flow-typed/asyncComponent_vx.x.x.js create mode 100644 packages/client/flow-typed/beforeComponent_vx.x.x.js create mode 100644 packages/client/flow-typed/documentComponent_vx.x.x.js create mode 100644 packages/client/flow-typed/ensureReady_vx.x.x.js create mode 100644 packages/client/flow-typed/errorComponent_vx.x.x.js create mode 100644 packages/client/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js create mode 100644 packages/client/flow-typed/render_vx.x.x.js create mode 100644 packages/server/flow-typed/asyncComponent_vx.x.x.js create mode 100644 packages/server/flow-typed/beforeComponent_vx.x.x.js create mode 100644 packages/server/flow-typed/documentComponent_vx.x.x.js create mode 100644 packages/server/flow-typed/ensureReady_vx.x.x.js create mode 100644 packages/server/flow-typed/errorComponent_vx.x.x.js create mode 100644 packages/server/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js create mode 100644 packages/server/flow-typed/render_vx.x.x.js diff --git a/packages/client/flow-typed/asyncComponent_vx.x.x.js b/packages/client/flow-typed/asyncComponent_vx.x.x.js new file mode 100644 index 0000000..22cbf12 --- /dev/null +++ b/packages/client/flow-typed/asyncComponent_vx.x.x.js @@ -0,0 +1,91 @@ +declare module 'Async.component' { + declare type DataType = { + [key: any]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare type AsyncProps = { + [key: string]: any + }; + + declare type AsyncRouteComponent = React$ComponentType & { + load: () => Promise, + getInitialProps: (context: Context) => Promise + }; + + declare type ComponentType

= { + getInitialProps(context: Context): Promise + } & $Subtype>; + + declare type AsyncOptions = { + loader(): + | Promise> + | Promise<{| +default: ComponentType |}>, + LoadableComponent: React$ComponentType + }; + + declare module.exports: { + asyncComponent(opts: AsyncOptions): (props: AsyncProps) => AsyncRouteComponent + }; +} diff --git a/packages/client/flow-typed/beforeComponent_vx.x.x.js b/packages/client/flow-typed/beforeComponent_vx.x.x.js new file mode 100644 index 0000000..da22154 --- /dev/null +++ b/packages/client/flow-typed/beforeComponent_vx.x.x.js @@ -0,0 +1,182 @@ +type Window = { + location: { + hostname: string + } +}; + +type Reviver = (key: string | number, value: any) => any; + +type JSONType = {| + parse(text: string, reviver?: Reviver): { [key: any]: any } +|}; + +declare module 'Before.component' { + declare var window: Window; + declare var JSON: JSONType; + + declare type DataType = { + [key: any]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location: LocationType, + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + declare type FixMeType = Class | typeof AsyncComponent; + + declare type AsyncRoute = { + component: FixMeType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP'; + + declare type RouterHistory = { + length: number, + location: LocationType, + action: HistoryAction, + listen(callback: (location: LocationType, action: HistoryAction) => void): () => void, + unstable_push(path: string | LocationType, state?: any): void, + push(path: string | LocationType, state?: any): void, + unstable_replace(path: string | LocationType, state?: any): void, + replace(path: string | LocationType, state?: any): void, + go(n: number): void, + goBack(): void, + goForward(): void, + canGo?: (n: number) => boolean, + block(callback: (location: LocationType, action: HistoryAction) => boolean): void, + index?: number, + entries?: Array + }; + + declare type SwitchRoutesProps = { + +data: ?DataType, + +routes: Array + }; + + declare type Match = { + params: { [key: string]: ?string }, + isExact: boolean, + path: string, + url: string + }; + + declare type BeforeProps = {| + +data: ?DataType, + +routes: Array, + +req: Request + |}; + + declare type BeforeState = { + currentLocation: LocationType + }; + + declare type BeforeAction = { + type: 'update-location' | 'update-props-location', + location: LocationType, + props?: DataType + }; + + declare type StaticRouterContext = { + url?: string + }; + + declare type ShouldRenderProps = { + children: React$Element, + location: LocationType + }; + + declare type BeforeComponentWithRouterProps = {| + +history: RouterHistory, + +location: LocationType, + +match: Match, + +staticContext?: StaticRouterContext, + +data: ?DataType, + +routes: Array, + +req: Request + |}; + + declare module.exports: { + Before: ( + props: BeforeComponentWithRouterProps + ) => React$Element< + Class< + React$Component<{| + children?: Node, + location?: Location + |}> + > + > + }; +} diff --git a/packages/client/flow-typed/documentComponent_vx.x.x.js b/packages/client/flow-typed/documentComponent_vx.x.x.js new file mode 100644 index 0000000..b1fe69b --- /dev/null +++ b/packages/client/flow-typed/documentComponent_vx.x.x.js @@ -0,0 +1,100 @@ +declare module 'Document.component' { + import type { Extractor } from '@loadable/server'; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + assets: Assets, + data: ?DataType, + renderPage(data: ?DataType): Promise, + generateCriticalCSS(): string | boolean, + title: string, + extractor: ?Extractor, + [key: string]: any + }; + + declare type TagMethods = { + toString(): string, + toComponent(): [React$Element<*>] | React$Element<*> | Array + }; + + declare type AttributeTagMethods = { + toString(): string, + toComponent(): { [key: string]: any } + }; + + declare type Helmet = { + base: TagMethods, + bodyAttributes: AttributeTagMethods, + htmlAttributes: AttributeTagMethods, + link: TagMethods, + meta: TagMethods, + noscript: TagMethods, + script: TagMethods, + style: TagMethods, + title: TagMethods + }; + + declare type ErrorProps = { + error: Error + }; + + declare type ExtraTag = { + name: string, + tag: string, + content: string, + attribs?: { + [key: string]: string + } + }; + + declare type DocumentInitialProps = { + assets: Assets, + criticalCSS: boolean | string, + data: DataType, + renderPage?: (data: { [key: string]: any }) => Promise, + generateCriticalCSS?: () => string | boolean, + title: string, + extractor: ?Extractor, + helmet: Helmet, + error: Error, + errorComponent?: React$ComponentType, + filterServerData?: (data: DataType) => DataType, + extraHeadTags?: Array, + extraBodyTags?: Array, + [key: string]: any + }; + + declare type DocumentGetInitialProps = { + criticalCSS: boolean | string, + assets: Assets, + data: DataType, + extractor: Extractor, + html: string, + [key: string]: any + }; + + declare type DocumentComponent = { + getInitialProps(context: Context): Promise + } & $Subtype>; + + declare module.exports: { + DocumentComponent: DocumentComponent, + Root: (props: { jsx: ?string }) => React$Element<'div'>, + Data: (arg: { data: DataType }) => React$Element<'script'> + }; +} diff --git a/packages/client/flow-typed/ensureReady_vx.x.x.js b/packages/client/flow-typed/ensureReady_vx.x.x.js new file mode 100644 index 0000000..70c9983 --- /dev/null +++ b/packages/client/flow-typed/ensureReady_vx.x.x.js @@ -0,0 +1,105 @@ +type Window = { + location: { + pathname: string + } +}; + +type Reviver = (key: string | number, value: any) => any; + +type JSONType = {| + parse(text: string, reviver?: Reviver): { [key: any]: any } +|}; + +declare module 'ensureReady' { + declare var window: Window; + declare var JSON: JSONType; + + declare type DataType = { + [key: string]: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + declare type Route = { + component: Class | typeof AsyncComponent, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare module.exports: { + ensureReady: (routes: Array, pathname: string) => Promise, + ensureClientReady: (rootFn: () => void) => Promise + }; +} diff --git a/packages/client/flow-typed/errorComponent_vx.x.x.js b/packages/client/flow-typed/errorComponent_vx.x.x.js new file mode 100644 index 0000000..3ddf192 --- /dev/null +++ b/packages/client/flow-typed/errorComponent_vx.x.x.js @@ -0,0 +1,11 @@ +declare module 'Error.component' { + declare type ErrorProps = {| + className?: string, + message: string, + stack: string + |}; + + declare module.exports: { + Error: ErrorProps => React$Element<'article'> + }; +} diff --git a/packages/client/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js b/packages/client/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js new file mode 100644 index 0000000..022818c --- /dev/null +++ b/packages/client/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js @@ -0,0 +1,121 @@ +declare module 'fetchInitialPropsFromRoutes' { + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + // fixme(lf): I don't why this one is not working. + declare type AsyncComponentType = Class | typeof AsyncComponent; + declare type AsyncFixMeComponentType = Class | typeof AsyncComponent; + + declare type Route = { + component: AsyncFixMeComponentType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP'; + + declare type RouterHistory = { + length: number, + location: LocationType, + action: HistoryAction, + listen(callback: (location: LocationType, action: HistoryAction) => void): () => void, + push(path: string | LocationType, state?: any): void, + replace(path: string | LocationType, state?: any): void, + go(n: number): void, + goBack(): void, + goForward(): void, + canGo?: (n: number) => boolean, + block(callback: (location: LocationType, action: HistoryAction) => boolean): void, + index?: number, + entries?: Array + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + history?: RouterHistory, + [key: string]: any + }; + + declare type Props = { + data: Error | DataType | null, + route: Route | null + }; + + declare module.exports: { + fetchInitialPropsFromRoute( + routes: Array, + pathname: string, + context: ?Context + ): Promise + }; +} diff --git a/packages/client/flow-typed/render_vx.x.x.js b/packages/client/flow-typed/render_vx.x.x.js new file mode 100644 index 0000000..48ff32b --- /dev/null +++ b/packages/client/flow-typed/render_vx.x.x.js @@ -0,0 +1,138 @@ +declare module 'render' { + import type { AsyncComponentType } from 'fetchInitialPropsFromRoutes'; + import type { DocumentComponent } from 'Document.component'; + import type { Extractor } from '@loadable/server'; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type Route = { + component: AsyncComponentType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type TagMethods = { + toString(): string, + toComponent(): Array> | React$Element | Array + }; + + declare type AttributeTagMethods = { + toString(): string, + toComponent(): { [key: string]: any } + }; + + declare type Helmet = { + base: TagMethods, + bodyAttributes: AttributeTagMethods, + htmlAttributes: AttributeTagMethods, + link: TagMethods, + meta: TagMethods, + noscript: TagMethods, + script: TagMethods, + style: TagMethods, + title: TagMethods + }; + + declare type ErrorProps = { + error: Error + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type HtmlType = { + html: string + }; + + declare type Renderer = (element: React$Element>) => HtmlType; + + declare type PageProps = { + routes: Array, + data: ?DataType, + req: Request + }; + + declare type CreatePageComponent = ( + Page: React$ComponentType + ) => (props: PageProps) => React$Element>; + + declare type RenderOptions = { + req: Request, + res: Response, + routes: Array, + assets: Assets, + document: DocumentComponent, + filterServerData(?DataType): DataType, + generateCriticalCSS(): string | boolean, + customRenderer: Renderer, + title: string, + statsPath: ?string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res: Response, + assets: Assets, + data: ?DataType, + filterServerData: (data: ?DataType) => DataType, + renderPage(data: ?DataType): Promise, + generateCriticalCSS(): string | boolean, + title: string, + extractor: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare module.exports: { + render: (options: RenderOptions) => string + }; +} diff --git a/packages/server/flow-typed/asyncComponent_vx.x.x.js b/packages/server/flow-typed/asyncComponent_vx.x.x.js new file mode 100644 index 0000000..22cbf12 --- /dev/null +++ b/packages/server/flow-typed/asyncComponent_vx.x.x.js @@ -0,0 +1,91 @@ +declare module 'Async.component' { + declare type DataType = { + [key: any]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare type AsyncProps = { + [key: string]: any + }; + + declare type AsyncRouteComponent = React$ComponentType & { + load: () => Promise, + getInitialProps: (context: Context) => Promise + }; + + declare type ComponentType

= { + getInitialProps(context: Context): Promise + } & $Subtype>; + + declare type AsyncOptions = { + loader(): + | Promise> + | Promise<{| +default: ComponentType |}>, + LoadableComponent: React$ComponentType + }; + + declare module.exports: { + asyncComponent(opts: AsyncOptions): (props: AsyncProps) => AsyncRouteComponent + }; +} diff --git a/packages/server/flow-typed/beforeComponent_vx.x.x.js b/packages/server/flow-typed/beforeComponent_vx.x.x.js new file mode 100644 index 0000000..da22154 --- /dev/null +++ b/packages/server/flow-typed/beforeComponent_vx.x.x.js @@ -0,0 +1,182 @@ +type Window = { + location: { + hostname: string + } +}; + +type Reviver = (key: string | number, value: any) => any; + +type JSONType = {| + parse(text: string, reviver?: Reviver): { [key: any]: any } +|}; + +declare module 'Before.component' { + declare var window: Window; + declare var JSON: JSONType; + + declare type DataType = { + [key: any]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location: LocationType, + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + declare type FixMeType = Class | typeof AsyncComponent; + + declare type AsyncRoute = { + component: FixMeType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP'; + + declare type RouterHistory = { + length: number, + location: LocationType, + action: HistoryAction, + listen(callback: (location: LocationType, action: HistoryAction) => void): () => void, + unstable_push(path: string | LocationType, state?: any): void, + push(path: string | LocationType, state?: any): void, + unstable_replace(path: string | LocationType, state?: any): void, + replace(path: string | LocationType, state?: any): void, + go(n: number): void, + goBack(): void, + goForward(): void, + canGo?: (n: number) => boolean, + block(callback: (location: LocationType, action: HistoryAction) => boolean): void, + index?: number, + entries?: Array + }; + + declare type SwitchRoutesProps = { + +data: ?DataType, + +routes: Array + }; + + declare type Match = { + params: { [key: string]: ?string }, + isExact: boolean, + path: string, + url: string + }; + + declare type BeforeProps = {| + +data: ?DataType, + +routes: Array, + +req: Request + |}; + + declare type BeforeState = { + currentLocation: LocationType + }; + + declare type BeforeAction = { + type: 'update-location' | 'update-props-location', + location: LocationType, + props?: DataType + }; + + declare type StaticRouterContext = { + url?: string + }; + + declare type ShouldRenderProps = { + children: React$Element, + location: LocationType + }; + + declare type BeforeComponentWithRouterProps = {| + +history: RouterHistory, + +location: LocationType, + +match: Match, + +staticContext?: StaticRouterContext, + +data: ?DataType, + +routes: Array, + +req: Request + |}; + + declare module.exports: { + Before: ( + props: BeforeComponentWithRouterProps + ) => React$Element< + Class< + React$Component<{| + children?: Node, + location?: Location + |}> + > + > + }; +} diff --git a/packages/server/flow-typed/documentComponent_vx.x.x.js b/packages/server/flow-typed/documentComponent_vx.x.x.js new file mode 100644 index 0000000..b1fe69b --- /dev/null +++ b/packages/server/flow-typed/documentComponent_vx.x.x.js @@ -0,0 +1,100 @@ +declare module 'Document.component' { + import type { Extractor } from '@loadable/server'; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + assets: Assets, + data: ?DataType, + renderPage(data: ?DataType): Promise, + generateCriticalCSS(): string | boolean, + title: string, + extractor: ?Extractor, + [key: string]: any + }; + + declare type TagMethods = { + toString(): string, + toComponent(): [React$Element<*>] | React$Element<*> | Array + }; + + declare type AttributeTagMethods = { + toString(): string, + toComponent(): { [key: string]: any } + }; + + declare type Helmet = { + base: TagMethods, + bodyAttributes: AttributeTagMethods, + htmlAttributes: AttributeTagMethods, + link: TagMethods, + meta: TagMethods, + noscript: TagMethods, + script: TagMethods, + style: TagMethods, + title: TagMethods + }; + + declare type ErrorProps = { + error: Error + }; + + declare type ExtraTag = { + name: string, + tag: string, + content: string, + attribs?: { + [key: string]: string + } + }; + + declare type DocumentInitialProps = { + assets: Assets, + criticalCSS: boolean | string, + data: DataType, + renderPage?: (data: { [key: string]: any }) => Promise, + generateCriticalCSS?: () => string | boolean, + title: string, + extractor: ?Extractor, + helmet: Helmet, + error: Error, + errorComponent?: React$ComponentType, + filterServerData?: (data: DataType) => DataType, + extraHeadTags?: Array, + extraBodyTags?: Array, + [key: string]: any + }; + + declare type DocumentGetInitialProps = { + criticalCSS: boolean | string, + assets: Assets, + data: DataType, + extractor: Extractor, + html: string, + [key: string]: any + }; + + declare type DocumentComponent = { + getInitialProps(context: Context): Promise + } & $Subtype>; + + declare module.exports: { + DocumentComponent: DocumentComponent, + Root: (props: { jsx: ?string }) => React$Element<'div'>, + Data: (arg: { data: DataType }) => React$Element<'script'> + }; +} diff --git a/packages/server/flow-typed/ensureReady_vx.x.x.js b/packages/server/flow-typed/ensureReady_vx.x.x.js new file mode 100644 index 0000000..70c9983 --- /dev/null +++ b/packages/server/flow-typed/ensureReady_vx.x.x.js @@ -0,0 +1,105 @@ +type Window = { + location: { + pathname: string + } +}; + +type Reviver = (key: string | number, value: any) => any; + +type JSONType = {| + parse(text: string, reviver?: Reviver): { [key: any]: any } +|}; + +declare module 'ensureReady' { + declare var window: Window; + declare var JSON: JSONType; + + declare type DataType = { + [key: string]: any + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + declare type Route = { + component: Class | typeof AsyncComponent, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare module.exports: { + ensureReady: (routes: Array, pathname: string) => Promise, + ensureClientReady: (rootFn: () => void) => Promise + }; +} diff --git a/packages/server/flow-typed/errorComponent_vx.x.x.js b/packages/server/flow-typed/errorComponent_vx.x.x.js new file mode 100644 index 0000000..3ddf192 --- /dev/null +++ b/packages/server/flow-typed/errorComponent_vx.x.x.js @@ -0,0 +1,11 @@ +declare module 'Error.component' { + declare type ErrorProps = {| + className?: string, + message: string, + stack: string + |}; + + declare module.exports: { + Error: ErrorProps => React$Element<'article'> + }; +} diff --git a/packages/server/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js b/packages/server/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js new file mode 100644 index 0000000..022818c --- /dev/null +++ b/packages/server/flow-typed/fetchInitialPropsFromRoutes_vx.x.x.js @@ -0,0 +1,121 @@ +declare module 'fetchInitialPropsFromRoutes' { + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type Extractor = { + getStyleTags(): Array>, + getStyleElements(): Array>, + getLinkElements(): Array> + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare class AsyncComponent extends React$PureComponent { + static getInitialProps(context: Context): Promise; + static load(): Promise; + } + + // fixme(lf): I don't why this one is not working. + declare type AsyncComponentType = Class | typeof AsyncComponent; + declare type AsyncFixMeComponentType = Class | typeof AsyncComponent; + + declare type Route = { + component: AsyncFixMeComponentType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP'; + + declare type RouterHistory = { + length: number, + location: LocationType, + action: HistoryAction, + listen(callback: (location: LocationType, action: HistoryAction) => void): () => void, + push(path: string | LocationType, state?: any): void, + replace(path: string | LocationType, state?: any): void, + go(n: number): void, + goBack(): void, + goForward(): void, + canGo?: (n: number) => boolean, + block(callback: (location: LocationType, action: HistoryAction) => boolean): void, + index?: number, + entries?: Array + }; + + declare type Context = { + req: Request, + res?: Response, + assets?: Assets, + data?: ?DataType, + filterServerData?: (data: ?DataType) => DataType, + renderPage?: (data: ?DataType) => Promise, + generateCriticalCSS?: () => string | boolean, + title?: string, + extractor?: ?Extractor, + location?: LocationType, + history?: RouterHistory, + [key: string]: any + }; + + declare type Props = { + data: Error | DataType | null, + route: Route | null + }; + + declare module.exports: { + fetchInitialPropsFromRoute( + routes: Array, + pathname: string, + context: ?Context + ): Promise + }; +} diff --git a/packages/server/flow-typed/render_vx.x.x.js b/packages/server/flow-typed/render_vx.x.x.js new file mode 100644 index 0000000..48ff32b --- /dev/null +++ b/packages/server/flow-typed/render_vx.x.x.js @@ -0,0 +1,138 @@ +declare module 'render' { + import type { AsyncComponentType } from 'fetchInitialPropsFromRoutes'; + import type { DocumentComponent } from 'Document.component'; + import type { Extractor } from '@loadable/server'; + + declare type Assets = { + client: { + css: string, + js: string + } + }; + + declare type InitialProps = { + [key: string]: any + }; + + declare type Route = { + component: AsyncComponentType, + redirectTo?: string, + prefetch?: boolean, + isExact: boolean, + params: { [key: string]: ?string }, + url: string, + path?: string, + sensitive?: boolean, + strict?: boolean, + exact?: boolean + }; + + declare type DataType = { + [key: string]: any + }; + + declare type Page = { + html: string, + [key: string]: any + }; + + declare type LocationType = { + hash: string, + key?: string, + pathname: string, + search: string, + state?: any + }; + + declare type TagMethods = { + toString(): string, + toComponent(): Array> | React$Element | Array + }; + + declare type AttributeTagMethods = { + toString(): string, + toComponent(): { [key: string]: any } + }; + + declare type Helmet = { + base: TagMethods, + bodyAttributes: AttributeTagMethods, + htmlAttributes: AttributeTagMethods, + link: TagMethods, + meta: TagMethods, + noscript: TagMethods, + script: TagMethods, + style: TagMethods, + title: TagMethods + }; + + declare type ErrorProps = { + error: Error + }; + + declare type QueryType = { + [key: string]: string + }; + + declare type Request = { + url: string, + query: QueryType, + originalUrl: string, + path: string, + [key: string]: any + }; + + declare type Response = { + status(code: number): void, + redirect(code: number, redirectTo: string): void, + [key: string]: any + }; + + declare type HtmlType = { + html: string + }; + + declare type Renderer = (element: React$Element>) => HtmlType; + + declare type PageProps = { + routes: Array, + data: ?DataType, + req: Request + }; + + declare type CreatePageComponent = ( + Page: React$ComponentType + ) => (props: PageProps) => React$Element>; + + declare type RenderOptions = { + req: Request, + res: Response, + routes: Array, + assets: Assets, + document: DocumentComponent, + filterServerData(?DataType): DataType, + generateCriticalCSS(): string | boolean, + customRenderer: Renderer, + title: string, + statsPath: ?string, + [key: string]: any + }; + + declare type Context = { + req: Request, + res: Response, + assets: Assets, + data: ?DataType, + filterServerData: (data: ?DataType) => DataType, + renderPage(data: ?DataType): Promise, + generateCriticalCSS(): string | boolean, + title: string, + extractor: ?Extractor, + location?: LocationType, + [key: string]: any + }; + + declare module.exports: { + render: (options: RenderOptions) => string + }; +}