@anansi/core 0.11.1 → 0.13.0
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.
- package/CHANGELOG.md +47 -0
- package/README.md +18 -7
- package/dist/client.js +29 -12
- package/dist/client.js.map +1 -1
- package/dist/server.js +97 -79
- package/dist/server.js.map +1 -1
- package/lib/floodSpouts.d.ts +1 -1
- package/lib/floodSpouts.d.ts.map +1 -1
- package/lib/floodSpouts.js +2 -2
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -2
- package/lib/index.server.d.ts +2 -0
- package/lib/index.server.d.ts.map +1 -1
- package/lib/index.server.js +10 -2
- package/lib/laySpouts.d.ts +2 -1
- package/lib/laySpouts.d.ts.map +1 -1
- package/lib/laySpouts.js +45 -54
- package/lib/scripts/startDevserver.d.ts.map +1 -1
- package/lib/scripts/startDevserver.js +8 -3
- package/lib/spouts/DocumentComponent.d.ts.map +1 -1
- package/lib/spouts/DocumentComponent.js +3 -2
- package/lib/spouts/app.d.ts +5 -0
- package/lib/spouts/app.d.ts.map +1 -0
- package/lib/spouts/app.js +12 -0
- package/lib/spouts/app.server.d.ts +6 -0
- package/lib/spouts/app.server.d.ts.map +1 -0
- package/lib/spouts/app.server.js +12 -0
- package/lib/spouts/document.d.ts +2 -2
- package/lib/spouts/document.d.ts.map +1 -1
- package/lib/spouts/document.js +3 -3
- package/lib/spouts/document.server.d.ts +2 -2
- package/lib/spouts/document.server.d.ts.map +1 -1
- package/lib/spouts/document.server.js +1 -1
- package/lib/spouts/json.d.ts +3 -1
- package/lib/spouts/json.d.ts.map +1 -1
- package/lib/spouts/json.js +6 -5
- package/lib/spouts/json.server.d.ts +2 -2
- package/lib/spouts/json.server.d.ts.map +1 -1
- package/lib/spouts/json.server.js +1 -1
- package/lib/spouts/prefetch.server.d.ts +1 -1
- package/lib/spouts/prefetch.server.d.ts.map +1 -1
- package/lib/spouts/prefetch.server.js +1 -1
- package/lib/spouts/restHooks.d.ts +3 -1
- package/lib/spouts/restHooks.d.ts.map +1 -1
- package/lib/spouts/restHooks.js +4 -4
- package/lib/spouts/restHooks.server.d.ts +44 -4
- package/lib/spouts/restHooks.server.d.ts.map +1 -1
- package/lib/spouts/restHooks.server.js +9 -4
- package/lib/spouts/router.d.ts +1 -1
- package/lib/spouts/router.d.ts.map +1 -1
- package/lib/spouts/router.js +3 -3
- package/lib/spouts/router.server.d.ts +5 -2
- package/lib/spouts/router.server.d.ts.map +1 -1
- package/lib/spouts/router.server.js +8 -4
- package/package.json +6 -6
- package/src/floodSpouts.tsx +2 -2
- package/src/index.server.ts +2 -0
- package/src/index.ts +2 -0
- package/src/laySpouts.tsx +23 -29
- package/src/scripts/startDevserver.ts +6 -2
- package/src/spouts/DocumentComponent.tsx +6 -1
- package/src/spouts/app.server.tsx +8 -0
- package/src/spouts/app.tsx +6 -0
- package/src/spouts/document.server.tsx +4 -4
- package/src/spouts/document.tsx +5 -5
- package/src/spouts/json.server.tsx +4 -8
- package/src/spouts/json.tsx +7 -12
- package/src/spouts/prefetch.server.tsx +8 -4
- package/src/spouts/restHooks.server.tsx +16 -7
- package/src/spouts/restHooks.tsx +6 -6
- package/src/spouts/router.server.tsx +17 -6
- package/src/spouts/router.tsx +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.13.0](https://github.com/ntucker/anansi/compare/@anansi/core@0.12.0...@anansi/core@0.13.0) (2022-06-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚠ 💥 BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* Must use appSpout; Spouts need two generics
|
|
12
|
+
|
|
13
|
+
### 💅 Enhancement
|
|
14
|
+
|
|
15
|
+
* Spouts produce props in both directions ([#1559](https://github.com/ntucker/anansi/issues/1559)) ([898cdde](https://github.com/ntucker/anansi/commit/898cdde500a204a7a4dc155ac7ee51930172380e))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [0.12.0](https://github.com/ntucker/anansi/compare/@anansi/core@0.11.2...@anansi/core@0.12.0) (2022-06-15)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 🚀 Features
|
|
23
|
+
|
|
24
|
+
* Add onError option to laySpouts ([a0ef72b](https://github.com/ntucker/anansi/commit/a0ef72bcaab1440a3d997d21636f81ca767a5a1c))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### 💅 Enhancement
|
|
28
|
+
|
|
29
|
+
* Don't crash devserver on compiler errors ([3c764e4](https://github.com/ntucker/anansi/commit/3c764e4dd67a57409c64ff7dd144386623a1d93f))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### 📦 Package
|
|
33
|
+
|
|
34
|
+
* Update babel monorepo to v7.18.5 ([#1545](https://github.com/ntucker/anansi/issues/1545)) ([aaaa8bc](https://github.com/ntucker/anansi/commit/aaaa8bcaa4d9188e9671ee31dc09b7aa9e3ce988))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### [0.11.2](https://github.com/ntucker/anansi/compare/@anansi/core@0.11.1...@anansi/core@0.11.2) (2022-06-13)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### 💅 Enhancement
|
|
42
|
+
|
|
43
|
+
* Do not override 'unsafe-inline' with nonce for CSP ([cfbd2bd](https://github.com/ntucker/anansi/commit/cfbd2bdfa69ae97ef2db6a824496888420251371))
|
|
44
|
+
* Use 'text' to get inline JSON ([9ecdb07](https://github.com/ntucker/anansi/commit/9ecdb074d01e6f09c28a685433105cf0d6f711cc))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### 📦 Package
|
|
48
|
+
|
|
49
|
+
* Update `webpack-cli` to v4.10.0 ([#1543](https://github.com/ntucker/anansi/issues/1543)) ([298cb01](https://github.com/ntucker/anansi/commit/298cb018db2975fb5c926c48d2145d7c1f4515b9))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
6
53
|
### [0.11.1](https://github.com/ntucker/anansi/compare/@anansi/core@0.11.0...@anansi/core@0.11.1) (2022-06-13)
|
|
7
54
|
|
|
8
55
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @anansi/core
|
|
2
|
+
|
|
2
3
|
<!--[](https://circleci.com/gh/notwillk/pojo-router)-->
|
|
4
|
+
|
|
3
5
|
[](https://www.npmjs.com/package/@anansi/core)
|
|
4
6
|
[](https://bundlephobia.com/result?p=@anansi/core)
|
|
5
7
|
[](https://www.npmjs.com/package/@anansi/core)
|
|
@@ -28,24 +30,27 @@ import {
|
|
|
28
30
|
restHooksSpout,
|
|
29
31
|
prefetchSpout,
|
|
30
32
|
routerSpout,
|
|
33
|
+
JSONSpout,
|
|
34
|
+
appSpout,
|
|
31
35
|
} from '@anansi/core/server';
|
|
32
36
|
|
|
33
37
|
import app from 'app';
|
|
34
38
|
|
|
35
39
|
import { createRouter } from './routing';
|
|
36
40
|
|
|
37
|
-
const appSpout = () => Promise.resolve({ app });
|
|
38
|
-
|
|
39
41
|
const spouts = prefetchSpout('controller')(
|
|
40
42
|
documentSpout({ title: 'anansi' })(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
JSONSpout()(
|
|
44
|
+
restHooksSpout()(
|
|
45
|
+
routerSpout({ useResolveWith: useController, createRouter })(
|
|
46
|
+
appSpout(app),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
43
49
|
),
|
|
44
50
|
),
|
|
45
51
|
);
|
|
46
52
|
|
|
47
53
|
export default laySpouts(spouts);
|
|
48
|
-
|
|
49
54
|
```
|
|
50
55
|
|
|
51
56
|
</details>
|
|
@@ -59,6 +64,8 @@ import {
|
|
|
59
64
|
documentSpout,
|
|
60
65
|
restHooksSpout,
|
|
61
66
|
routerSpout,
|
|
67
|
+
JSONSpout,
|
|
68
|
+
appSpout,
|
|
62
69
|
} from '@anansi/core';
|
|
63
70
|
|
|
64
71
|
import app from 'app';
|
|
@@ -68,8 +75,12 @@ import { createRouter } from './routing';
|
|
|
68
75
|
const appSpout = () => Promise.resolve({ app });
|
|
69
76
|
|
|
70
77
|
const spouts = documentSpout({ title: 'anansi' })(
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
JSONSpout()(
|
|
79
|
+
restHooksSpout()(
|
|
80
|
+
routerSpout({ useResolveWith: useController, createRouter })(
|
|
81
|
+
appSpout(app),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
73
84
|
),
|
|
74
85
|
);
|
|
75
86
|
|
package/dist/client.js
CHANGED
|
@@ -52,12 +52,18 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
52
52
|
// EXPORTS
|
|
53
53
|
__webpack_require__.d(__webpack_exports__, {
|
|
54
54
|
"JSONSpout": () => (/* reexport */ JSONSpout),
|
|
55
|
+
"ServerProps": () => (/* reexport */ types_namespaceObject.ServerProps),
|
|
56
|
+
"appSpout": () => (/* reexport */ app),
|
|
55
57
|
"documentSpout": () => (/* reexport */ documentSpout),
|
|
56
58
|
"floodSpouts": () => (/* reexport */ floodSpouts),
|
|
57
59
|
"restHooksSpout": () => (/* reexport */ restHooksSpout),
|
|
58
60
|
"routerSpout": () => (/* reexport */ routerSpout)
|
|
59
61
|
});
|
|
60
62
|
|
|
63
|
+
// NAMESPACE OBJECT: ./src/spouts/types.ts
|
|
64
|
+
var types_namespaceObject = {};
|
|
65
|
+
__webpack_require__.r(types_namespaceObject);
|
|
66
|
+
|
|
61
67
|
;// CONCATENATED MODULE: external "react-dom/client"
|
|
62
68
|
const client_namespaceObject = require("react-dom/client");
|
|
63
69
|
;// CONCATENATED MODULE: ./src/floodSpouts.tsx
|
|
@@ -69,14 +75,14 @@ async function floodSpouts(spouts, {
|
|
|
69
75
|
|
|
70
76
|
const {
|
|
71
77
|
app
|
|
72
|
-
} = await spouts();
|
|
78
|
+
} = await spouts({});
|
|
73
79
|
(0,client_namespaceObject.hydrateRoot)((_document$getElementB = document.getElementById(rootId)) != null ? _document$getElementB : document, app);
|
|
74
80
|
}
|
|
75
81
|
;// CONCATENATED MODULE: ./src/spouts/document.tsx
|
|
76
82
|
function documentSpout(options) {
|
|
77
83
|
return function (next) {
|
|
78
|
-
return async
|
|
79
|
-
const nextProps = await next(
|
|
84
|
+
return async props => {
|
|
85
|
+
const nextProps = await next(props);
|
|
80
86
|
return nextProps;
|
|
81
87
|
};
|
|
82
88
|
};
|
|
@@ -94,9 +100,9 @@ function restHooksSpout(options = {
|
|
|
94
100
|
getManagers: () => [new core_namespaceObject.NetworkManager()]
|
|
95
101
|
}) {
|
|
96
102
|
return function (next) {
|
|
97
|
-
return async
|
|
98
|
-
const data = initData.resthooks;
|
|
99
|
-
const nextProps = await next(
|
|
103
|
+
return async props => {
|
|
104
|
+
const data = props.initData.resthooks;
|
|
105
|
+
const nextProps = await next(props);
|
|
100
106
|
return { ...nextProps,
|
|
101
107
|
app: /*#__PURE__*/external_react_default().createElement(core_namespaceObject.CacheProvider, {
|
|
102
108
|
initialState: data,
|
|
@@ -140,11 +146,11 @@ function routerSpout(options) {
|
|
|
140
146
|
};
|
|
141
147
|
|
|
142
148
|
return function (next) {
|
|
143
|
-
return async
|
|
149
|
+
return async props => {
|
|
144
150
|
const history = (0,external_history_namespaceObject.createBrowserHistory)();
|
|
145
151
|
const router = options.createRouter(history);
|
|
146
152
|
const matchedRoutes = router.getMatchedRoutes(history.location.pathname);
|
|
147
|
-
const nextProps = await next(
|
|
153
|
+
const nextProps = await next(props);
|
|
148
154
|
const Router = createRouteComponent(router);
|
|
149
155
|
return { ...nextProps,
|
|
150
156
|
matchedRoutes,
|
|
@@ -166,24 +172,35 @@ function JSONSpout({
|
|
|
166
172
|
id = 'anansi-json'
|
|
167
173
|
} = {}) {
|
|
168
174
|
return function (next) {
|
|
169
|
-
return async
|
|
175
|
+
return async props => {
|
|
170
176
|
const initData = getDatafromDOM(id);
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
return await next({ ...props,
|
|
178
|
+
initData
|
|
179
|
+
});
|
|
173
180
|
};
|
|
174
181
|
};
|
|
175
182
|
}
|
|
176
183
|
|
|
177
184
|
function getDatafromDOM(id) {
|
|
178
185
|
const element = document.querySelector(`#${id}`);
|
|
179
|
-
return element !== null && element !== void 0 && element.
|
|
186
|
+
return element !== null && element !== void 0 && element.text ? JSON.parse(element === null || element === void 0 ? void 0 : element.text) : undefined;
|
|
180
187
|
}
|
|
188
|
+
;// CONCATENATED MODULE: ./src/spouts/app.tsx
|
|
189
|
+
const appSpout = app => props => Promise.resolve({ ...props,
|
|
190
|
+
app
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/* harmony default export */ const app = (appSpout);
|
|
194
|
+
;// CONCATENATED MODULE: ./src/spouts/types.ts
|
|
195
|
+
|
|
181
196
|
;// CONCATENATED MODULE: ./src/index.ts
|
|
182
197
|
|
|
183
198
|
|
|
184
199
|
|
|
185
200
|
|
|
186
201
|
|
|
202
|
+
|
|
203
|
+
|
|
187
204
|
module.exports = __webpack_exports__;
|
|
188
205
|
/******/ })()
|
|
189
206
|
;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACPA;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"file":"client.js","mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACPA;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;ACNA;;ACAA;AAEA;AAIA;AAAA;AACA;;AACA;AAAA;AAAA;AAEA;AACA;;ACDA;AAIA;AAGA;AACA;AAEA;AACA;AACA;AACA;;ACvBA;;;ACAA;;;;ACAA;AAWA;AAGA;AAAA;AAEA;AAGA;AACA;AAEA;AAEA;AAEA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAHA;AAQA;AACA;AACA;;AClCA;;ACAA;;;ACAA;AACA;AACA;AAOA;AAMA;AAGA;AAAA;AACA;AAEA;AAEA;AACA;AACA;AAHA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;;AAEA;AAGA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAJA;AAMA;AACA;AACA;;AC/CA;AACA;AADA;AAGA;AAGA;AACA;AACA;AAAA;AAAA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;ACnBA;AAGA;AAAA;;AAEA;;;;AELA;AACA;AACA;AACA;AACA;AACA","sources":["/home/ntucker/src/anansi/packages/core/webpack/bootstrap","/home/ntucker/src/anansi/packages/core/webpack/runtime/compat get default export","/home/ntucker/src/anansi/packages/core/webpack/runtime/define property getters","/home/ntucker/src/anansi/packages/core/webpack/runtime/hasOwnProperty shorthand","/home/ntucker/src/anansi/packages/core/webpack/runtime/make namespace object","/home/ntucker/src/anansi/packages/core/external commonjs \"react-dom/client\"","/home/ntucker/src/anansi/packages/core/src/floodSpouts.tsx","/home/ntucker/src/anansi/packages/core/src/spouts/document.tsx","/home/ntucker/src/anansi/packages/core/external commonjs \"react\"","/home/ntucker/src/anansi/packages/core/external commonjs \"@rest-hooks/core\"","/home/ntucker/src/anansi/packages/core/src/spouts/restHooks.tsx","/home/ntucker/src/anansi/packages/core/external commonjs \"@anansi/router\"","/home/ntucker/src/anansi/packages/core/external commonjs \"history\"","/home/ntucker/src/anansi/packages/core/src/spouts/router.tsx","/home/ntucker/src/anansi/packages/core/src/spouts/json.tsx","/home/ntucker/src/anansi/packages/core/src/spouts/app.tsx","/home/ntucker/src/anansi/packages/core/src/spouts/types.ts","/home/ntucker/src/anansi/packages/core/src/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react-dom/client\");","import { hydrateRoot } from 'react-dom/client';\n\nexport default async function floodSpouts(\n spouts: (props: Record<string, unknown>) => Promise<{\n app: JSX.Element;\n }>,\n { rootId = 'anansi-root' }: { rootId?: string } = {},\n) {\n const { app } = await spouts({});\n\n hydrateRoot(document.getElementById(rootId) ?? document, app);\n}\n","import React from 'react';\nimport type { Route } from '@anansi/router';\n\nimport type { ResolveProps } from './types';\n\ntype NeededNext = {\n matchedRoutes: Route<any>[];\n title?: string;\n} & ResolveProps;\n\nexport default function documentSpout(options: {\n head?: React.ReactNode;\n title: string;\n}) {\n return function <N extends NeededNext, I extends Record<string, unknown>>(\n next: (props: I) => Promise<N>,\n ) {\n return async (props: I) => {\n const nextProps = await next(props);\n\n return nextProps;\n };\n };\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@rest-hooks/core\");","import {\n CacheProvider,\n Manager,\n NetworkManager,\n State,\n} from '@rest-hooks/core';\n\nimport type { ResolveProps } from './types';\n\ntype NeededNext = ResolveProps;\n\nexport default function restHooksSpout(\n options: {\n getManagers: () => Manager[];\n } = { getManagers: () => [new NetworkManager()] },\n) {\n return function <N extends NeededNext, I extends Record<string, unknown>>(\n next: (props: I) => Promise<N>,\n ) {\n return async (props: I & { initData: Record<string, unknown> }) => {\n const data = props.initData.resthooks as State<unknown>;\n\n const nextProps = await next(props);\n\n return {\n ...nextProps,\n app: (\n <CacheProvider initialState={data} managers={options.getManagers()}>\n {nextProps.app}\n </CacheProvider>\n ),\n };\n };\n };\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@anansi/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"history\");","import { Route, RouteProvider, RouteController } from '@anansi/router';\nimport React from 'react';\nimport { createBrowserHistory } from 'history';\nimport type { Update } from 'history';\n\nimport type { ResolveProps, CreateRouter } from './types';\n\ntype NeededNext = ResolveProps;\n\nexport default function routerSpout<ResolveWith>(options: {\n resolveWith?: any;\n useResolveWith: () => ResolveWith;\n createRouter: CreateRouter<ResolveWith>;\n onChange?: (update: Update, callback: () => void | undefined) => void;\n}) {\n const createRouteComponent = (\n router: RouteController<Route<ResolveWith, any>>,\n ) =>\n function Router({ children }: { children: React.ReactNode }) {\n const resolveWith = options.useResolveWith();\n\n return (\n <RouteProvider\n router={router}\n resolveWith={resolveWith}\n onChange={options.onChange}\n >\n {children}\n </RouteProvider>\n );\n };\n\n return function <N extends NeededNext, I extends Record<string, unknown>>(\n next: (initData: Record<string, unknown>) => Promise<N>,\n ) {\n return async (props: I) => {\n const history = createBrowserHistory();\n const router = options.createRouter(history);\n const matchedRoutes = router.getMatchedRoutes(history.location.pathname);\n\n const nextProps = await next(props);\n\n const Router = createRouteComponent(router);\n return {\n ...nextProps,\n matchedRoutes,\n router,\n app: <Router>{nextProps.app}</Router>,\n };\n };\n };\n}\n","import type { ResolveProps } from './types';\n\ntype NeededNext = ResolveProps;\n\nexport default function JSONSpout({\n id = 'anansi-json',\n}: { id?: string } = {}) {\n return function <N extends NeededNext, I extends Record<string, unknown>>(\n next: (props: I & { initData: Record<string, unknown> }) => Promise<N>,\n ) {\n return async (props: I) => {\n const initData = getDatafromDOM(id);\n return await next({ ...props, initData });\n };\n };\n}\nfunction getDatafromDOM(id: string): Record<string, unknown> {\n const element: HTMLScriptElement | null = document.querySelector(`#${id}`);\n return element?.text ? JSON.parse(element?.text) : undefined;\n}\n","const appSpout =\n (app: JSX.Element) =>\n <P extends Record<string, unknown>>(props: P) =>\n Promise.resolve({ ...props, app });\n\nexport default appSpout;\n","import { IncomingMessage, ServerResponse } from 'http';\nimport { Request, Response } from 'express';\nimport type { StatsCompilation } from 'webpack';\nimport { History } from 'history';\nimport { Route, RouteController } from '@anansi/router';\n\n/* Variables from the rendering call */\nexport type ServerProps = {\n req: Request | IncomingMessage;\n res: Response | ServerResponse;\n clientManifest: StatsCompilation;\n nonce: string;\n};\n\n/* Baseline expectations of return value */\nexport type ResolveProps = {\n app: JSX.Element;\n};\n\nexport type CreateRouter<T> = (\n history: History,\n) => RouteController<Route<T, any>>;\n","export { default as floodSpouts } from './floodSpouts';\nexport { default as documentSpout } from './spouts/document';\nexport { default as restHooksSpout } from './spouts/restHooks';\nexport { default as routerSpout } from './spouts/router';\nexport { default as JSONSpout } from './spouts/json';\nexport { default as appSpout } from './spouts/app';\nexport { ServerProps } from './spouts/types';\n"],"names":[],"sourceRoot":""}
|
package/dist/server.js
CHANGED
|
@@ -52,6 +52,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
52
52
|
// EXPORTS
|
|
53
53
|
__webpack_require__.d(__webpack_exports__, {
|
|
54
54
|
"JSONSpout": () => (/* reexport */ JSONSpout),
|
|
55
|
+
"ServerProps": () => (/* reexport */ types_namespaceObject.ServerProps),
|
|
56
|
+
"appSpout": () => (/* reexport */ app_server),
|
|
55
57
|
"documentSpout": () => (/* reexport */ DocumentSpout),
|
|
56
58
|
"laySpouts": () => (/* reexport */ laySpouts),
|
|
57
59
|
"prefetchSpout": () => (/* reexport */ prefetchSpout),
|
|
@@ -59,6 +61,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
59
61
|
"routerSpout": () => (/* reexport */ routerSpout)
|
|
60
62
|
});
|
|
61
63
|
|
|
64
|
+
// NAMESPACE OBJECT: ./src/spouts/types.ts
|
|
65
|
+
var types_namespaceObject = {};
|
|
66
|
+
__webpack_require__.r(types_namespaceObject);
|
|
67
|
+
|
|
62
68
|
;// CONCATENATED MODULE: external "react-dom/server"
|
|
63
69
|
const server_namespaceObject = require("react-dom/server");
|
|
64
70
|
;// CONCATENATED MODULE: external "crypto"
|
|
@@ -68,67 +74,59 @@ var external_crypto_default = /*#__PURE__*/__webpack_require__.n(external_crypto
|
|
|
68
74
|
|
|
69
75
|
|
|
70
76
|
function laySpouts(spouts, {
|
|
71
|
-
timeoutMS = 200
|
|
77
|
+
timeoutMS = 200,
|
|
78
|
+
onError
|
|
72
79
|
} = {}) {
|
|
73
80
|
const render = async (clientManifest, req, res) => {
|
|
74
81
|
const nonce = external_crypto_default().randomBytes(16).toString('base64');
|
|
75
|
-
const {
|
|
76
|
-
app
|
|
77
|
-
} = await spouts({
|
|
78
|
-
clientManifest,
|
|
79
|
-
req,
|
|
80
|
-
res,
|
|
81
|
-
nonce
|
|
82
|
-
});
|
|
83
|
-
let didError = false;
|
|
84
|
-
const {
|
|
85
|
-
pipe,
|
|
86
|
-
abort
|
|
87
|
-
} = (0,server_namespaceObject.renderToPipeableStream)(app,
|
|
88
|
-
/*
|
|
89
|
-
This is not documented, so included the types here for reference:
|
|
90
|
-
type Options = {|
|
|
91
|
-
identifierPrefix?: string,
|
|
92
|
-
namespaceURI?: string,
|
|
93
|
-
nonce?: string,
|
|
94
|
-
bootstrapScriptContent?: string,
|
|
95
|
-
bootstrapScripts?: Array<string>,
|
|
96
|
-
bootstrapModules?: Array<string>,
|
|
97
|
-
progressiveChunkSize?: number,
|
|
98
|
-
onShellReady?: () => void,
|
|
99
|
-
onShellError?: () => void,
|
|
100
|
-
onAllReady?: () => void,
|
|
101
|
-
onError?: (error: mixed) => void,
|
|
102
|
-
|};
|
|
103
|
-
*/
|
|
104
|
-
{
|
|
105
|
-
nonce,
|
|
106
|
-
|
|
107
|
-
//bootstrapScripts: assets.filter(asset => asset.endsWith('.js')),
|
|
108
|
-
onShellReady() {
|
|
109
|
-
//managers.forEach(manager => manager.cleanup());
|
|
110
|
-
// If something errored before we started streaming, we set the error code appropriately.
|
|
111
|
-
res.statusCode = didError ? 500 : 200;
|
|
112
|
-
res.setHeader('Content-type', 'text/html');
|
|
113
|
-
pipe(res);
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
onShellError() {
|
|
117
|
-
didError = true;
|
|
118
|
-
res.statusCode = 500;
|
|
119
|
-
pipe(res);
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
onError(x) {
|
|
123
|
-
didError = true;
|
|
124
|
-
console.error(x);
|
|
125
|
-
res.statusCode = 500; //pipe(res); Removing this avoids, "React currently only supports piping to one writable stream."
|
|
126
|
-
}
|
|
127
82
|
|
|
128
|
-
|
|
129
|
-
|
|
83
|
+
try {
|
|
84
|
+
const {
|
|
85
|
+
app
|
|
86
|
+
} = await spouts({
|
|
87
|
+
clientManifest,
|
|
88
|
+
req,
|
|
89
|
+
res,
|
|
90
|
+
nonce
|
|
91
|
+
});
|
|
92
|
+
let didError = false;
|
|
93
|
+
const {
|
|
94
|
+
pipe,
|
|
95
|
+
abort
|
|
96
|
+
} = (0,server_namespaceObject.renderToPipeableStream)(app, {
|
|
97
|
+
nonce,
|
|
98
|
+
|
|
99
|
+
//bootstrapScripts: assets.filter(asset => asset.endsWith('.js')),
|
|
100
|
+
onShellReady() {
|
|
101
|
+
//managers.forEach(manager => manager.cleanup());
|
|
102
|
+
// If something errored before we started streaming, we set the error code appropriately.
|
|
103
|
+
res.statusCode = didError ? 500 : 200;
|
|
104
|
+
res.setHeader('Content-type', 'text/html');
|
|
105
|
+
pipe(res);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
onShellError() {
|
|
109
|
+
didError = true;
|
|
110
|
+
res.statusCode = 500;
|
|
111
|
+
pipe(res);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
onError(e) {
|
|
115
|
+
didError = true;
|
|
116
|
+
console.error(e);
|
|
117
|
+
res.statusCode = 500; //pipe(res); Removing this avoids, "React currently only supports piping to one writable stream."
|
|
118
|
+
|
|
119
|
+
if (onError) onError(e);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}); // Abandon and switch to client rendering if enough time passes.
|
|
123
|
+
// Try lowering this to see the client recover.
|
|
130
124
|
|
|
131
|
-
|
|
125
|
+
setTimeout(() => abort(`Timeout of ${timeoutMS}ms exceeded`), timeoutMS);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (onError) onError(e);
|
|
128
|
+
throw e;
|
|
129
|
+
}
|
|
132
130
|
};
|
|
133
131
|
|
|
134
132
|
return render;
|
|
@@ -175,7 +173,8 @@ function Document({
|
|
|
175
173
|
const policy = { ...csPolicy
|
|
176
174
|
};
|
|
177
175
|
|
|
178
|
-
if (nonce
|
|
176
|
+
if (nonce && ( // nonces negate 'unsafe-inline' so do not add it if that directive exists
|
|
177
|
+
!policy['script-src'] || !policy['script-src'].includes("'unsafe-inline'"))) {
|
|
179
178
|
if (typeof policy['script-src'] === 'string') {
|
|
180
179
|
policy['script-src'] = [policy['script-src'], `'nonce-${nonce}'`];
|
|
181
180
|
} else {
|
|
@@ -189,7 +188,7 @@ function Document({
|
|
|
189
188
|
__self: this,
|
|
190
189
|
__source: {
|
|
191
190
|
fileName: _jsxFileName,
|
|
192
|
-
lineNumber:
|
|
191
|
+
lineNumber: 46,
|
|
193
192
|
columnNumber: 7
|
|
194
193
|
}
|
|
195
194
|
});
|
|
@@ -199,14 +198,14 @@ function Document({
|
|
|
199
198
|
__self: this,
|
|
200
199
|
__source: {
|
|
201
200
|
fileName: _jsxFileName,
|
|
202
|
-
lineNumber:
|
|
201
|
+
lineNumber: 50,
|
|
203
202
|
columnNumber: 5
|
|
204
203
|
}
|
|
205
204
|
}, /*#__PURE__*/external_react_default().createElement("head", {
|
|
206
205
|
__self: this,
|
|
207
206
|
__source: {
|
|
208
207
|
fileName: _jsxFileName,
|
|
209
|
-
lineNumber:
|
|
208
|
+
lineNumber: 51,
|
|
210
209
|
columnNumber: 7
|
|
211
210
|
}
|
|
212
211
|
}, /*#__PURE__*/external_react_default().createElement("meta", {
|
|
@@ -214,7 +213,7 @@ function Document({
|
|
|
214
213
|
__self: this,
|
|
215
214
|
__source: {
|
|
216
215
|
fileName: _jsxFileName,
|
|
217
|
-
lineNumber:
|
|
216
|
+
lineNumber: 52,
|
|
218
217
|
columnNumber: 9
|
|
219
218
|
}
|
|
220
219
|
}), cspMeta, head, assets.map((asset, i) => /*#__PURE__*/external_react_default().createElement("link", {
|
|
@@ -224,21 +223,21 @@ function Document({
|
|
|
224
223
|
__self: this,
|
|
225
224
|
__source: {
|
|
226
225
|
fileName: _jsxFileName,
|
|
227
|
-
lineNumber:
|
|
226
|
+
lineNumber: 56,
|
|
228
227
|
columnNumber: 11
|
|
229
228
|
}
|
|
230
229
|
})), /*#__PURE__*/external_react_default().createElement("title", {
|
|
231
230
|
__self: this,
|
|
232
231
|
__source: {
|
|
233
232
|
fileName: _jsxFileName,
|
|
234
|
-
lineNumber:
|
|
233
|
+
lineNumber: 58,
|
|
235
234
|
columnNumber: 9
|
|
236
235
|
}
|
|
237
236
|
}, title)), /*#__PURE__*/external_react_default().createElement("body", {
|
|
238
237
|
__self: this,
|
|
239
238
|
__source: {
|
|
240
239
|
fileName: _jsxFileName,
|
|
241
|
-
lineNumber:
|
|
240
|
+
lineNumber: 60,
|
|
242
241
|
columnNumber: 7
|
|
243
242
|
}
|
|
244
243
|
}, /*#__PURE__*/external_react_default().createElement("div", {
|
|
@@ -246,7 +245,7 @@ function Document({
|
|
|
246
245
|
__self: this,
|
|
247
246
|
__source: {
|
|
248
247
|
fileName: _jsxFileName,
|
|
249
|
-
lineNumber:
|
|
248
|
+
lineNumber: 61,
|
|
250
249
|
columnNumber: 9
|
|
251
250
|
}
|
|
252
251
|
}, children), scripts, assets.filter(({
|
|
@@ -260,7 +259,7 @@ function Document({
|
|
|
260
259
|
__self: this,
|
|
261
260
|
__source: {
|
|
262
261
|
fileName: _jsxFileName,
|
|
263
|
-
lineNumber:
|
|
262
|
+
lineNumber: 66,
|
|
264
263
|
columnNumber: 13
|
|
265
264
|
}
|
|
266
265
|
}))));
|
|
@@ -272,7 +271,7 @@ Document.defaultProps = {
|
|
|
272
271
|
__self: undefined,
|
|
273
272
|
__source: {
|
|
274
273
|
fileName: _jsxFileName,
|
|
275
|
-
lineNumber:
|
|
274
|
+
lineNumber: 75,
|
|
276
275
|
columnNumber: 7
|
|
277
276
|
}
|
|
278
277
|
}), /*#__PURE__*/external_react_default().createElement("link", {
|
|
@@ -281,7 +280,7 @@ Document.defaultProps = {
|
|
|
281
280
|
__self: undefined,
|
|
282
281
|
__source: {
|
|
283
282
|
fileName: _jsxFileName,
|
|
284
|
-
lineNumber:
|
|
283
|
+
lineNumber: 76,
|
|
285
284
|
columnNumber: 7
|
|
286
285
|
}
|
|
287
286
|
})),
|
|
@@ -416,9 +415,11 @@ function restHooksSpout(options = {
|
|
|
416
415
|
return function (next) {
|
|
417
416
|
return async props => {
|
|
418
417
|
const [ServerCacheProvider, controller, store] = createPersistedStore(options.getManagers());
|
|
419
|
-
const nextProps = await next(props
|
|
420
|
-
return { ...nextProps,
|
|
418
|
+
const nextProps = await next({ ...props,
|
|
421
419
|
controller,
|
|
420
|
+
store
|
|
421
|
+
});
|
|
422
|
+
return { ...nextProps,
|
|
422
423
|
initData: { ...nextProps.initData,
|
|
423
424
|
resthooks: () => store.getState()
|
|
424
425
|
},
|
|
@@ -426,10 +427,13 @@ function restHooksSpout(options = {
|
|
|
426
427
|
__self: this,
|
|
427
428
|
__source: {
|
|
428
429
|
fileName: restHooks_server_jsxFileName,
|
|
429
|
-
lineNumber:
|
|
430
|
+
lineNumber: 36,
|
|
430
431
|
columnNumber: 14
|
|
431
432
|
}
|
|
432
|
-
}, nextProps.app)
|
|
433
|
+
}, nextProps.app),
|
|
434
|
+
// TODO: figure out how to only inject in next and not have to also put here
|
|
435
|
+
controller,
|
|
436
|
+
store
|
|
433
437
|
};
|
|
434
438
|
};
|
|
435
439
|
};
|
|
@@ -467,19 +471,23 @@ function routerSpout(options) {
|
|
|
467
471
|
initialEntries: [url]
|
|
468
472
|
}));
|
|
469
473
|
const matchedRoutes = router.getMatchedRoutes(url);
|
|
470
|
-
const nextProps = await next(props
|
|
474
|
+
const nextProps = await next({ ...props,
|
|
475
|
+
matchedRoutes,
|
|
476
|
+
router
|
|
477
|
+
});
|
|
471
478
|
const Router = createRouteComponent(router);
|
|
472
479
|
return { ...nextProps,
|
|
473
|
-
matchedRoutes,
|
|
474
|
-
router,
|
|
475
480
|
app: /*#__PURE__*/external_react_default().createElement(Router, {
|
|
476
481
|
__self: this,
|
|
477
482
|
__source: {
|
|
478
483
|
fileName: router_server_jsxFileName,
|
|
479
|
-
lineNumber:
|
|
484
|
+
lineNumber: 52,
|
|
480
485
|
columnNumber: 14
|
|
481
486
|
}
|
|
482
|
-
}, nextProps.app)
|
|
487
|
+
}, nextProps.app),
|
|
488
|
+
// TODO: figure out how to only inject in next and not have to also put here
|
|
489
|
+
matchedRoutes,
|
|
490
|
+
router
|
|
483
491
|
};
|
|
484
492
|
};
|
|
485
493
|
};
|
|
@@ -559,7 +567,7 @@ function JSONSpout({
|
|
|
559
567
|
__self: this,
|
|
560
568
|
__source: {
|
|
561
569
|
fileName: json_server_jsxFileName,
|
|
562
|
-
lineNumber:
|
|
570
|
+
lineNumber: 48,
|
|
563
571
|
columnNumber: 13
|
|
564
572
|
}
|
|
565
573
|
});
|
|
@@ -575,7 +583,7 @@ function JSONSpout({
|
|
|
575
583
|
__self: this,
|
|
576
584
|
__source: {
|
|
577
585
|
fileName: json_server_jsxFileName,
|
|
578
|
-
lineNumber:
|
|
586
|
+
lineNumber: 65,
|
|
579
587
|
columnNumber: 20
|
|
580
588
|
}
|
|
581
589
|
}));
|
|
@@ -585,6 +593,14 @@ function JSONSpout({
|
|
|
585
593
|
};
|
|
586
594
|
};
|
|
587
595
|
}
|
|
596
|
+
;// CONCATENATED MODULE: ./src/spouts/app.server.tsx
|
|
597
|
+
const appSpout = app => props => Promise.resolve({ ...props,
|
|
598
|
+
app
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
/* harmony default export */ const app_server = (appSpout);
|
|
602
|
+
;// CONCATENATED MODULE: ./src/spouts/types.ts
|
|
603
|
+
|
|
588
604
|
;// CONCATENATED MODULE: ./src/index.server.ts
|
|
589
605
|
|
|
590
606
|
|
|
@@ -592,6 +608,8 @@ function JSONSpout({
|
|
|
592
608
|
|
|
593
609
|
|
|
594
610
|
|
|
611
|
+
|
|
612
|
+
|
|
595
613
|
module.exports = __webpack_exports__;
|
|
596
614
|
/******/ })()
|
|
597
615
|
;
|