@quilted/quilt 0.5.65 → 0.5.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import '@quilted/polyfills/crypto';
2
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/polyfills/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
@@ -1,13 +1,15 @@
1
- import type { ComponentType } from 'react';
1
+ import type { ComponentType, ReactElement } from 'react';
2
2
  import type { AssetLoader } from '@quilted/async/server';
3
- import type { Request, HttpHandler, RequestHandler, HttpHandlerOptions } from '@quilted/http-handlers';
4
- export interface Options<Props = Record<string, never>> extends Pick<HttpHandlerOptions, 'before'> {
5
- assets: AssetLoader<unknown>;
3
+ import type { Options as ExtractOptions } from '@quilted/react-server-render/server';
4
+ import type { Request, HttpHandler, RequestHandler } from '@quilted/http-handlers';
5
+ export interface Options<Props = Record<string, never>> extends ExtractOptions {
6
+ assets?: AssetLoader<unknown>;
6
7
  handler?: HttpHandler;
7
8
  renderProps?(options: {
8
9
  request: Request;
9
10
  }): Props;
10
11
  }
11
- export declare function createServerRenderingRequestHandler<Props>(App: ComponentType<Props>, { assets, renderProps, }: Pick<Options<Props>, 'assets' | 'renderProps'>): RequestHandler;
12
- export declare function createServerRenderingHttpHandler<Props>(App: ComponentType<Props>, { assets, before, renderProps, handler, }: Options<Props>): HttpHandler;
12
+ export declare function createServerRenderingHttpHandler<Props>(App: ComponentType<Props>, { handler, ...options }: Options<Props>): HttpHandler;
13
+ export declare function createServerRenderingRequestHandler<Props>(App: ComponentType<Props>, { renderProps, ...options }?: Omit<Options<Props>, 'handler'>): RequestHandler;
14
+ export declare function renderToResponse<Props>(element: ReactElement<Props>, request: Request, { assets, ...options }?: Omit<Options<Props>, 'handler' | 'renderProps'>): Promise<import("@quilted/http-handlers").Response | undefined>;
13
15
  //# sourceMappingURL=http-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEzC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAIvD,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACd,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAIhC,MAAM,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CACpD,SAAQ,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;IAC1C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,WAAW,CAAC,CAAC,OAAO,EAAE;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,GAAG,KAAK,CAAC;CAClD;AAED,wBAAgB,mCAAmC,CAAC,KAAK,EACvD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EACE,MAAM,EACN,WAA+B,GAChC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC,GAChD,cAAc,CAqDhB;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EACpD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EACE,MAAM,EACN,MAAM,EACN,WAAW,EACX,OAAqC,GACtC,EAAE,OAAO,CAAC,KAAK,CAAC,eAIlB"}
1
+ {"version":3,"file":"http-handler.d.ts","sourceRoot":"","sources":["../../../src/server/http-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,YAAY,EAAC,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,qCAAqC,CAAC;AAGnF,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACf,MAAM,wBAAwB,CAAC;AAIhC,MAAM,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAE,SAAQ,cAAc;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,WAAW,CAAC,CAAC,OAAO,EAAE;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,GAAG,KAAK,CAAC;CAClD;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EACpD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,OAA6B,EAAE,GAAG,OAAO,EAAC,EAAE,OAAO,CAAC,KAAK,CAAC,eAI5D;AAED,wBAAgB,mCAAmC,CAAC,KAAK,EACvD,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,EACzB,EAAC,WAAW,EAAE,GAAG,OAAO,EAAC,GAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAM,GAC9D,cAAc,CAQhB;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAC1C,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,OAAO,EAAE,OAAO,EAChB,EAAC,MAAM,EAAE,GAAG,OAAO,EAAC,GAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,aAAa,CAAM,kEAuD3E"}
@@ -9,5 +9,5 @@ export type { HttpState } from '@quilted/react-http/server';
9
9
  export { createHttpHandler } from '@quilted/http-handlers';
10
10
  export { renderApp } from './render';
11
11
  export { ServerContext } from './ServerContext';
12
- export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, } from './http-handler';
12
+ export { createServerRenderingRequestHandler, createServerRenderingHttpHandler, renderToResponse, } from './http-handler';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,GACR,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,IAAI,6BAA6B,GAClD,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,GACjC,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,EACX,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,GACR,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,YAAY,EACV,KAAK,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,IAAI,6BAA6B,GAClD,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAC,gBAAgB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,YAAY,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,mCAAmC,EACnC,gCAAgC,EAChC,gBAAgB,GACjB,MAAM,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/quilt",
3
3
  "type": "module",
4
- "version": "0.5.65",
4
+ "version": "0.5.68",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/lemonmade/quilt.git",
@@ -103,6 +103,12 @@
103
103
  "import": "./build/esm/polyfills/base.mjs",
104
104
  "require": "./build/cjs/polyfills/base.cjs"
105
105
  },
106
+ "./polyfills/crypto": {
107
+ "quilt:from-source": "./src/polyfills/crypto.ts",
108
+ "quilt:esnext": "./build/esnext/polyfills/crypto.esnext",
109
+ "import": "./build/esm/polyfills/crypto.mjs",
110
+ "require": "./build/cjs/polyfills/crypto.cjs"
111
+ },
106
112
  "./polyfills/fetch": {
107
113
  "quilt:from-source": "./src/polyfills/fetch.ts",
108
114
  "quilt:esnext": "./build/esnext/polyfills/fetch.esnext",
@@ -167,6 +173,9 @@
167
173
  "polyfills/fetch": [
168
174
  "./build/typescript/polyfills/fetch.d.ts"
169
175
  ],
176
+ "polyfills/crypto": [
177
+ "./build/typescript/polyfills/crypto.d.ts"
178
+ ],
170
179
  "polyfills/noop": [
171
180
  "./build/typescript/polyfills/noop.d.ts"
172
181
  ],
@@ -0,0 +1 @@
1
+ import '@quilted/polyfills/crypto';
@@ -1,95 +1,101 @@
1
- import type {ComponentType} from 'react';
1
+ import type {ComponentType, ReactElement} from 'react';
2
2
 
3
3
  import type {AssetLoader} from '@quilted/async/server';
4
4
  import {render as renderToString, Html} from '@quilted/react-html/server';
5
+ import type {Options as ExtractOptions} from '@quilted/react-server-render/server';
5
6
 
6
7
  import {createHttpHandler, html, redirect} from '@quilted/http-handlers';
7
8
  import type {
8
9
  Request,
9
10
  HttpHandler,
10
11
  RequestHandler,
11
- HttpHandlerOptions,
12
12
  } from '@quilted/http-handlers';
13
13
 
14
14
  import {renderApp} from './render';
15
15
 
16
- export interface Options<Props = Record<string, never>>
17
- extends Pick<HttpHandlerOptions, 'before'> {
18
- assets: AssetLoader<unknown>;
16
+ export interface Options<Props = Record<string, never>> extends ExtractOptions {
17
+ assets?: AssetLoader<unknown>;
19
18
  handler?: HttpHandler;
20
19
  renderProps?(options: {request: Request}): Props;
21
20
  }
22
21
 
22
+ export function createServerRenderingHttpHandler<Props>(
23
+ App: ComponentType<Props>,
24
+ {handler = createHttpHandler(), ...options}: Options<Props>,
25
+ ) {
26
+ handler.get(createServerRenderingRequestHandler(App, options));
27
+ return handler;
28
+ }
29
+
23
30
  export function createServerRenderingRequestHandler<Props>(
24
31
  App: ComponentType<Props>,
25
- {
26
- assets,
27
- renderProps = () => ({} as any),
28
- }: Pick<Options<Props>, 'assets' | 'renderProps'>,
32
+ {renderProps, ...options}: Omit<Options<Props>, 'handler'> = {},
29
33
  ): RequestHandler {
30
- return async (request) => {
31
- const accepts = request.headers.get('Accept');
34
+ return (request) => {
35
+ return renderToResponse(
36
+ <App {...(renderProps?.({request}) as any)} />,
37
+ request,
38
+ options,
39
+ );
40
+ };
41
+ }
32
42
 
33
- if (accepts != null && !accepts.includes('text/html')) return;
43
+ export async function renderToResponse<Props>(
44
+ element: ReactElement<Props>,
45
+ request: Request,
46
+ {assets, ...options}: Omit<Options<Props>, 'handler' | 'renderProps'> = {},
47
+ ) {
48
+ const accepts = request.headers.get('Accept');
34
49
 
35
- const {
36
- html: htmlManager,
37
- http,
38
- markup,
39
- asyncAssets,
40
- } = await renderApp(<App {...renderProps?.({request})} />, {
41
- url: request.url,
42
- headers: request.headers,
43
- });
50
+ if (accepts != null && !accepts.includes('text/html')) return;
44
51
 
45
- const {headers, statusCode = 200, redirectUrl} = http.state;
52
+ const {
53
+ html: htmlManager,
54
+ http,
55
+ markup,
56
+ asyncAssets,
57
+ } = await renderApp(element, {
58
+ ...options,
59
+ url: request.url,
60
+ headers: request.headers,
61
+ });
46
62
 
47
- if (redirectUrl) {
48
- return redirect(redirectUrl, {
49
- status: statusCode as 301,
50
- headers,
51
- });
52
- }
63
+ const {headers, statusCode = 200, redirectUrl} = http.state;
53
64
 
54
- const usedAssets = asyncAssets.used({timing: 'load'});
55
- const assetOptions = {userAgent: request.headers.get('User-Agent')};
65
+ if (redirectUrl) {
66
+ return redirect(redirectUrl, {
67
+ status: statusCode as 301,
68
+ headers,
69
+ });
70
+ }
56
71
 
57
- const [styles, scripts, preload] = await Promise.all([
58
- assets.styles({async: usedAssets, options: assetOptions}),
59
- assets.scripts({async: usedAssets, options: assetOptions}),
60
- assets.asyncAssets(asyncAssets.used({timing: 'preload'}), {
61
- options: assetOptions,
62
- }),
63
- ]);
72
+ const usedAssets = asyncAssets.used({timing: 'load'});
73
+ const assetOptions = {userAgent: request.headers.get('User-Agent')};
64
74
 
65
- return html(
66
- renderToString(
67
- <Html
68
- manager={htmlManager}
69
- styles={styles}
70
- scripts={scripts}
71
- preloadAssets={preload}
72
- >
73
- {markup}
74
- </Html>,
75
- ),
76
- {
77
- headers,
78
- status: statusCode,
79
- },
80
- );
81
- };
82
- }
75
+ const [styles, scripts, preload] = assets
76
+ ? await Promise.all([
77
+ assets.styles({async: usedAssets, options: assetOptions}),
78
+ assets.scripts({async: usedAssets, options: assetOptions}),
79
+ assets.asyncAssets(asyncAssets.used({timing: 'preload'}), {
80
+ options: assetOptions,
81
+ }),
82
+ ])
83
+ : [];
83
84
 
84
- export function createServerRenderingHttpHandler<Props>(
85
- App: ComponentType<Props>,
86
- {
87
- assets,
88
- before,
89
- renderProps,
90
- handler = createHttpHandler({before}),
91
- }: Options<Props>,
92
- ) {
93
- handler.get(createServerRenderingRequestHandler(App, {assets, renderProps}));
94
- return handler;
85
+ return html(
86
+ renderToString(
87
+ <Html
88
+ manager={htmlManager}
89
+ styles={styles}
90
+ scripts={scripts}
91
+ preloadAssets={preload}
92
+ >
93
+ {markup}
94
+ </Html>,
95
+ ),
96
+ {
97
+ headers,
98
+ status: statusCode,
99
+ },
100
+ );
95
101
  }
@@ -36,4 +36,5 @@ export {ServerContext} from './ServerContext';
36
36
  export {
37
37
  createServerRenderingRequestHandler,
38
38
  createServerRenderingHttpHandler,
39
+ renderToResponse,
39
40
  } from './http-handler';