@valbuild/next 0.150.22 → 0.151.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 +174 -0
- package/README.md +82 -1
- package/client/dist/valbuild-next-client.cjs.dev.js +123 -256
- package/client/dist/valbuild-next-client.cjs.prod.js +123 -256
- package/client/dist/valbuild-next-client.esm.js +122 -255
- package/dist/{ValApp-a88a9ded.esm.js → ValApp-69cd599c.esm.js} +3 -3
- package/dist/{ValApp-c718d1a6.cjs.dev.js → ValApp-826dca6c.cjs.dev.js} +3 -3
- package/dist/ValApp-866089f6.cjs.js +7 -0
- package/dist/{ValApp-6c3da222.cjs.prod.js → ValApp-866089f6.cjs.prod.js} +3 -3
- package/dist/{ValCanvasBridge-9d221d32.cjs.dev.js → ValCanvasBridge-4b81f653.cjs.dev.js} +46 -13
- package/dist/ValCanvasBridge-6f568f1d.cjs.js +7 -0
- package/dist/{ValCanvasBridge-134c3ae1.cjs.prod.js → ValCanvasBridge-6f568f1d.cjs.prod.js} +46 -13
- package/dist/{ValCanvasBridge-4a5ef73c.esm.js → ValCanvasBridge-badc186b.esm.js} +46 -13
- package/dist/ValNextProvider-41d622a7.cjs.js +7 -0
- package/dist/{ValNextProvider-35d0b521.cjs.prod.js → ValNextProvider-41d622a7.cjs.prod.js} +124 -234
- package/dist/{ValNextProvider-a85a1d33.cjs.dev.js → ValNextProvider-4b9bcfc0.cjs.dev.js} +124 -234
- package/dist/{ValNextProvider-df6f351e.esm.js → ValNextProvider-745ed99e.esm.js} +124 -234
- package/dist/ValOverlayContext-0c29b6a7.cjs.dev.js +51 -0
- package/dist/ValOverlayContext-0f51d111.cjs.js +7 -0
- package/dist/ValOverlayContext-0f51d111.cjs.prod.js +51 -0
- package/dist/ValOverlayContext-178db68e.esm.js +37 -0
- package/dist/ValVideo-02f43a7c.cjs.js +7 -0
- package/dist/{ValVideo-dcd2b9f8.cjs.prod.js → ValVideo-02f43a7c.cjs.prod.js} +1 -2
- package/dist/{ValVideo-6e410ad8.cjs.dev.js → ValVideo-15e5c4fa.cjs.dev.js} +1 -2
- package/dist/{ValVideo-d377f06e.esm.js → ValVideo-8acf31b6.esm.js} +1 -2
- package/dist/{createForOfIteratorHelper-d4afcad8.cjs.prod.js → createForOfIteratorHelper-8459fbc7.cjs.prod.js} +1 -1
- package/dist/{createForOfIteratorHelper-5758a730.esm.js → createForOfIteratorHelper-9209e9dd.esm.js} +1 -1
- package/dist/{createForOfIteratorHelper-0445603c.cjs.dev.js → createForOfIteratorHelper-9c6aa3c7.cjs.dev.js} +1 -1
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
- package/dist/declarations/src/rsc/index.d.ts +1 -0
- package/dist/declarations/src/rsc/initValRsc.d.ts +56 -118
- package/dist/declarations/src/server/initValServer.d.ts +2 -1
- package/dist/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
- package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
- package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
- package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
- package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
- package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
- package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
- package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
- package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
- package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
- package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
- package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
- package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
- package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
- package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
- package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
- package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
- package/dist/useHydrated-afcdbb66.esm.js +26 -0
- package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
- package/dist/valbuild-next.cjs.dev.js +7 -8
- package/dist/valbuild-next.cjs.prod.js +7 -8
- package/dist/valbuild-next.esm.js +7 -8
- package/dist/{version-18c11a6d.cjs.prod.js → version-114c45b6.cjs.prod.js} +1 -1
- package/dist/{version-70b7333d.cjs.dev.js → version-cc1bc4e5.cjs.dev.js} +1 -1
- package/dist/{version-a2218191.esm.js → version-d8f64e54.esm.js} +1 -1
- package/package.json +8 -8
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
- package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
- package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
- package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
- package/server/dist/valbuild-next-server.esm.js +4 -5
- package/dist/ValApp-6c3da222.cjs.js +0 -7
- package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
- package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
- package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
- package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
- package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
- package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
- package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
- package/dist/defineProperty-cca5affa.esm.js +0 -26
- package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
|
@@ -1,808 +1,279 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import { f as fillJsonValuesRecord, j as jsonValuesRecordToFill, i as initValRouteFromVal, g as getJsonEntryStegaRoot, a as isJsonValuesRecordSchema, b as getValRouteUrlFromVal, c as bundledJsonEntryImport, _ as _typeof } from '../../dist/routeFromVal-64cba2a6.esm.js';
|
|
3
|
-
import { _ as _defineProperty } from '../../dist/defineProperty-cca5affa.esm.js';
|
|
4
|
-
import { _ as _objectSpread2 } from '../../dist/objectSpread2-60d1bd93.esm.js';
|
|
5
2
|
import { _ as _asyncToGenerator, a as _regenerator } from '../../dist/asyncToGenerator-500f022f.esm.js';
|
|
6
|
-
import {
|
|
3
|
+
import { _ as _objectSpread2 } from '../../dist/objectSpread2-f1f0d77a.esm.js';
|
|
4
|
+
import { SET_RSC, SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
|
|
5
|
+
import { fetchValFrom, isJsonValuesRecordSchema, awaitResolved, resolveValEntry, resolveVal } from '@valbuild/react/internal';
|
|
7
6
|
import { Internal } from '@valbuild/core';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import '../../dist/
|
|
13
|
-
import '../../dist/
|
|
14
|
-
import '../../dist/slicedToArray-aa291011.esm.js';
|
|
7
|
+
import { createValRuntime, readDraftChanges, draftForRequest, readerSchemaVersion } from '@valbuild/server/internal';
|
|
8
|
+
import { V as VERSION } from '../../dist/version-d8f64e54.esm.js';
|
|
9
|
+
import { i as initValRouteFromVal, g as getValRouteUrlFromVal } from '../../dist/routeFromVal-80976677.esm.js';
|
|
10
|
+
import '../../dist/createForOfIteratorHelper-9209e9dd.esm.js';
|
|
11
|
+
import '../../dist/unsupportedIterableToArray-f57eb659.esm.js';
|
|
12
|
+
import '../../dist/slicedToArray-5ff32315.esm.js';
|
|
15
13
|
import '@valbuild/shared/client';
|
|
16
14
|
|
|
17
15
|
SET_RSC(true);
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
* The
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
17
|
+
/*
|
|
18
|
+
* The readers below are `resolveVal` (`@valbuild/react/stega`) over this
|
|
19
|
+
* request's sources: the draft (`serverDraftSource`, in `@valbuild/server`),
|
|
20
|
+
* then the bundle. Only the sources are Next's; the rule that picks between
|
|
21
|
+
* them is the same in `@valbuild/tanstack` and in the hooks. See
|
|
22
|
+
* `docs/plans/one-content-model.md`, "One way to load".
|
|
24
23
|
*/
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* it says what the dependency IS, and it lets a test drive the reader with a
|
|
31
|
-
* one-route fake instead of casting a partial object to the whole server type.
|
|
26
|
+
* What the readers read: this process's runtime for the app's `val.modules`
|
|
27
|
+
* (`createValRuntime`), the same one the API route's server is built on.
|
|
28
|
+
* Its head is the draft, read with the request's session.
|
|
32
29
|
*/
|
|
33
30
|
|
|
34
|
-
/** What
|
|
31
|
+
/** What a misuse of a reader is told, beside what went wrong. */
|
|
32
|
+
var WHERE = "fetchVal can only be used server-side. Use useVal on clients.";
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* scope its cache to" is part of its contract and a test can supply a scope it
|
|
41
|
-
* controls — in jest, React's non-`react-server` build makes `cache` a
|
|
42
|
-
* pass-through, so the real wiring memoises nothing there.
|
|
35
|
+
* What a read in this request reads, in order: the draft (in draft mode),
|
|
36
|
+
* then -- added by every read -- the bundle. Edit tags are decided here,
|
|
37
|
+
* once, from draft mode.
|
|
43
38
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* See `memoizePerRequest`. `fetchVal` is an RSC API (`SET_RSC(true)` above, and
|
|
54
|
-
* its own error messages say so), so the effective case is the normal one.
|
|
55
|
-
*
|
|
56
|
-
* Built PER `initValRsc` rather than once for the module, because the box is
|
|
57
|
-
* only as specific as the `cache()` it came from: two Val servers in one
|
|
58
|
-
* process sharing one would answer each other's reads within a request, and
|
|
59
|
-
* they hold different content.
|
|
60
|
-
*/
|
|
61
|
-
function createReactCacheScope() {
|
|
62
|
-
var getBox = cache(function () {
|
|
63
|
-
return {};
|
|
64
|
-
});
|
|
65
|
-
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
66
|
-
return _regenerator().w(function (_context) {
|
|
67
|
-
while (1) switch (_context.n) {
|
|
68
|
-
case 0:
|
|
69
|
-
return _context.a(2, getBox());
|
|
70
|
-
}
|
|
71
|
-
}, _callee);
|
|
72
|
-
}));
|
|
39
|
+
function requestEnv(enabled, draft) {
|
|
40
|
+
if (enabled) {
|
|
41
|
+
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
sources: draft === null ? [] : [draft],
|
|
45
|
+
encode: enabled,
|
|
46
|
+
schemaVersionOf: readerSchemaVersion
|
|
47
|
+
};
|
|
73
48
|
}
|
|
74
49
|
|
|
75
|
-
/**
|
|
76
|
-
* ONE read of the whole module tree, for the session in `sessionCookie`.
|
|
77
|
-
*
|
|
78
|
-
* `path` stays `"/"` on purpose, and the measurement is why. `/sources/~`
|
|
79
|
-
* evaluates, previews and validates EVERY module and only THEN filters the
|
|
80
|
-
* response by `req.path` (the two TODOs in `ValServer.ts` say so), so narrowing
|
|
81
|
-
* the path shrinks the answer and changes the work not at all: on a 60-module
|
|
82
|
-
* project, `path: "/"` took 53.6ms and a single-module path 53.5ms. And this is
|
|
83
|
-
* an in-process call rather than a round trip, so the object it builds is never
|
|
84
|
-
* serialised or sent anywhere — the bytes it saves are not bytes anyone pays
|
|
85
|
-
* for. Narrowing would also give each caller a different answer to cache, which
|
|
86
|
-
* is what would cost the saving that IS real (2.7x on the same project).
|
|
87
|
-
*
|
|
88
|
-
* `draftRead.perf.test.ts` prints both numbers; re-run it before believing
|
|
89
|
-
* anything different.
|
|
90
|
-
*
|
|
91
|
-
* Returns `null` when the session is not one the server accepts; the caller
|
|
92
|
-
* then renders published content, which is what it did before.
|
|
93
|
-
*/
|
|
94
|
-
function loadDraftSources(_x, _x2) {
|
|
95
|
-
return _loadDraftSources.apply(this, arguments);
|
|
96
|
-
}
|
|
97
|
-
function _loadDraftSources() {
|
|
98
|
-
_loadDraftSources = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(valServerPromise, sessionCookie) {
|
|
99
|
-
var valServer, treeRes;
|
|
100
|
-
return _regenerator().w(function (_context19) {
|
|
101
|
-
while (1) switch (_context19.n) {
|
|
102
|
-
case 0:
|
|
103
|
-
_context19.n = 1;
|
|
104
|
-
return valServerPromise;
|
|
105
|
-
case 1:
|
|
106
|
-
valServer = _context19.v;
|
|
107
|
-
_context19.n = 2;
|
|
108
|
-
return valServer["/sources/~"]["PUT"]({
|
|
109
|
-
path: "/",
|
|
110
|
-
query: {
|
|
111
|
-
validate_sources: true,
|
|
112
|
-
validate_binary_files: false,
|
|
113
|
-
exclude_patches: false,
|
|
114
|
-
// RSC pre-render uses the legacy "server applies patches" path.
|
|
115
|
-
apply_patches: undefined
|
|
116
|
-
},
|
|
117
|
-
cookies: _defineProperty({}, VAL_SESSION_COOKIE, sessionCookie)
|
|
118
|
-
});
|
|
119
|
-
case 2:
|
|
120
|
-
treeRes = _context19.v;
|
|
121
|
-
if (!(treeRes.status === 200)) {
|
|
122
|
-
_context19.n = 3;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
return _context19.a(2, treeRes.json.modules);
|
|
126
|
-
case 3:
|
|
127
|
-
if (!(treeRes.status === 401)) {
|
|
128
|
-
_context19.n = 4;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
Internal.log.debug("authentication error: ", treeRes.json.message);
|
|
132
|
-
return _context19.a(2, null);
|
|
133
|
-
case 4:
|
|
134
|
-
throw Error(JSON.stringify(treeRes.json, null, 2));
|
|
135
|
-
case 5:
|
|
136
|
-
return _context19.a(2);
|
|
137
|
-
}
|
|
138
|
-
}, _callee19);
|
|
139
|
-
}));
|
|
140
|
-
return _loadDraftSources.apply(this, arguments);
|
|
141
|
-
}
|
|
142
|
-
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
|
|
143
|
-
return function (selector) {
|
|
144
|
-
var exec = /*#__PURE__*/function () {
|
|
145
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
146
|
-
var enabled, headers, cookies, host, _cookies, sessionCookie, modules, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10;
|
|
147
|
-
return _regenerator().w(function (_context2) {
|
|
148
|
-
while (1) switch (_context2.p = _context2.n) {
|
|
149
|
-
case 0:
|
|
150
|
-
enabled = false;
|
|
151
|
-
_context2.p = 1;
|
|
152
|
-
_context2.n = 2;
|
|
153
|
-
return isEnabled();
|
|
154
|
-
case 2:
|
|
155
|
-
enabled = _context2.v;
|
|
156
|
-
_context2.n = 4;
|
|
157
|
-
break;
|
|
158
|
-
case 3:
|
|
159
|
-
_context2.p = 3;
|
|
160
|
-
_t = _context2.v;
|
|
161
|
-
Internal.log.error("could not check if Val is enabled! This might be due to an error to check draftMode. fetchVal can only be used server-side. Use useVal on clients.", _t);
|
|
162
|
-
case 4:
|
|
163
|
-
if (!enabled) {
|
|
164
|
-
_context2.n = 16;
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
168
|
-
_context2.p = 5;
|
|
169
|
-
_context2.n = 6;
|
|
170
|
-
return getHeaders();
|
|
171
|
-
case 6:
|
|
172
|
-
headers = _context2.v;
|
|
173
|
-
if (!(typeof headers.get !== "function")) {
|
|
174
|
-
_context2.n = 7;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
throw new Error("Invalid headers");
|
|
178
|
-
case 7:
|
|
179
|
-
_context2.n = 9;
|
|
180
|
-
break;
|
|
181
|
-
case 8:
|
|
182
|
-
_context2.p = 8;
|
|
183
|
-
_t2 = _context2.v;
|
|
184
|
-
Internal.log.error("could not read headers! fetchVal can only be used server-side. Use useVal on clients.", _t2);
|
|
185
|
-
headers = null;
|
|
186
|
-
case 9:
|
|
187
|
-
_context2.p = 9;
|
|
188
|
-
_context2.n = 10;
|
|
189
|
-
return getCookies();
|
|
190
|
-
case 10:
|
|
191
|
-
cookies = _context2.v;
|
|
192
|
-
_context2.n = 12;
|
|
193
|
-
break;
|
|
194
|
-
case 11:
|
|
195
|
-
_context2.p = 11;
|
|
196
|
-
_t3 = _context2.v;
|
|
197
|
-
Internal.log.error("could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", _t3);
|
|
198
|
-
cookies = null;
|
|
199
|
-
case 12:
|
|
200
|
-
host = headers && getHost(headers);
|
|
201
|
-
if (!(host && cookies)) {
|
|
202
|
-
_context2.n = 16;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
sessionCookie = (_cookies = cookies) === null || _cookies === void 0 || (_cookies = _cookies.get(VAL_SESSION_COOKIE)) === null || _cookies === void 0 ? void 0 : _cookies.value;
|
|
206
|
-
/*
|
|
207
|
-
* Once per request, however many times the page reads.
|
|
208
|
-
*
|
|
209
|
-
* Every `fetchVal` in one render asks the same question — same query,
|
|
210
|
-
* same session — so the second and third answer were identical and
|
|
211
|
-
* cost the same as the first. `fetchValRouteUrl` made that worse by
|
|
212
|
-
* calling `fetchVal` again on top of the caller's own.
|
|
213
|
-
*
|
|
214
|
-
* The key is the session, so a box that somehow outlived its request
|
|
215
|
-
* misses rather than serving another author's draft. See
|
|
216
|
-
* `memoizePerRequest`.
|
|
217
|
-
*/
|
|
218
|
-
_t4 = memoizePerRequest;
|
|
219
|
-
_context2.n = 13;
|
|
220
|
-
return getDraftSourcesScope();
|
|
221
|
-
case 13:
|
|
222
|
-
_context2.n = 14;
|
|
223
|
-
return _t4(_context2.v, sessionCookie !== null && sessionCookie !== void 0 ? sessionCookie : "", function () {
|
|
224
|
-
return loadDraftSources(valServerPromise, sessionCookie);
|
|
225
|
-
});
|
|
226
|
-
case 14:
|
|
227
|
-
modules = _context2.v;
|
|
228
|
-
if (!modules) {
|
|
229
|
-
_context2.n = 16;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
_t5 = stegaEncode;
|
|
233
|
-
_t6 = selector;
|
|
234
|
-
_t7 = !enabled;
|
|
235
|
-
_context2.n = 15;
|
|
236
|
-
return withJsonValuesEntries(selector, function (path) {
|
|
237
|
-
var _modules$path;
|
|
238
|
-
return [(_modules$path = modules[path]) === null || _modules$path === void 0 ? void 0 : _modules$path.source];
|
|
239
|
-
});
|
|
240
|
-
case 15:
|
|
241
|
-
_t8 = _context2.v;
|
|
242
|
-
return _context2.a(2, _t5(_t6, {
|
|
243
|
-
disabled: _t7,
|
|
244
|
-
getModule: _t8
|
|
245
|
-
}));
|
|
246
|
-
case 16:
|
|
247
|
-
_t9 = stegaEncode;
|
|
248
|
-
_t0 = selector;
|
|
249
|
-
_t1 = !enabled;
|
|
250
|
-
_context2.n = 17;
|
|
251
|
-
return withJsonValuesEntries(selector, function () {
|
|
252
|
-
return [];
|
|
253
|
-
});
|
|
254
|
-
case 17:
|
|
255
|
-
_t10 = _context2.v;
|
|
256
|
-
return _context2.a(2, _t9(_t0, {
|
|
257
|
-
disabled: _t1,
|
|
258
|
-
getModule: _t10
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
}, _callee2, null, [[9, 11], [5, 8], [1, 3]]);
|
|
262
|
-
}));
|
|
263
|
-
return function exec() {
|
|
264
|
-
return _ref2.apply(this, arguments);
|
|
265
|
-
};
|
|
266
|
-
}();
|
|
267
|
-
return exec()["catch"](/*#__PURE__*/function () {
|
|
268
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(err) {
|
|
269
|
-
var _t11, _t12, _t13;
|
|
270
|
-
return _regenerator().w(function (_context3) {
|
|
271
|
-
while (1) switch (_context3.n) {
|
|
272
|
-
case 0:
|
|
273
|
-
Internal.log.error("failed to fetch ", err);
|
|
274
|
-
_t11 = stegaEncode;
|
|
275
|
-
_t12 = selector;
|
|
276
|
-
_context3.n = 1;
|
|
277
|
-
return withJsonValuesEntries(selector, function () {
|
|
278
|
-
return [];
|
|
279
|
-
})["catch"](function () {
|
|
280
|
-
return function () {
|
|
281
|
-
return undefined;
|
|
282
|
-
};
|
|
283
|
-
});
|
|
284
|
-
case 1:
|
|
285
|
-
_t13 = _context3.v;
|
|
286
|
-
return _context3.a(2, _t11(_t12, {
|
|
287
|
-
getModule: _t13
|
|
288
|
-
}));
|
|
289
|
-
}
|
|
290
|
-
}, _callee3);
|
|
291
|
-
}));
|
|
292
|
-
return function (_x3) {
|
|
293
|
-
return _ref3.apply(this, arguments);
|
|
294
|
-
};
|
|
295
|
-
}());
|
|
296
|
-
};
|
|
297
|
-
};
|
|
50
|
+
/** What a reader needs from the app and the request. */
|
|
298
51
|
|
|
299
|
-
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
case 0:
|
|
317
|
-
first = function first(path) {
|
|
318
|
-
return sourcesOf(path).find(function (source) {
|
|
319
|
-
return source !== undefined;
|
|
52
|
+
/** `fetchVal`, with what it read: see `readsOfFetchVal`. */
|
|
53
|
+
function fetchValWithReads(deps) {
|
|
54
|
+
return /*#__PURE__*/function () {
|
|
55
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(selector, opts) {
|
|
56
|
+
var _yield$draftForReques, enabled, draft, env;
|
|
57
|
+
return _regenerator().w(function (_context) {
|
|
58
|
+
while (1) switch (_context.n) {
|
|
59
|
+
case 0:
|
|
60
|
+
_context.n = 1;
|
|
61
|
+
return draftForRequest({
|
|
62
|
+
runtime: deps.runtime,
|
|
63
|
+
isEnabled: deps.isEnabled,
|
|
64
|
+
getCookies: deps.getCookies,
|
|
65
|
+
modules: {
|
|
66
|
+
getHeaders: deps.getHeaders
|
|
67
|
+
},
|
|
68
|
+
where: WHERE
|
|
320
69
|
});
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
_context21.n = 2;
|
|
331
|
-
return Promise.all(plan.load.map(/*#__PURE__*/function () {
|
|
332
|
-
var _ref16 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(key) {
|
|
333
|
-
var thunk, _t19, _t20, _t21;
|
|
334
|
-
return _regenerator().w(function (_context20) {
|
|
335
|
-
while (1) switch (_context20.n) {
|
|
336
|
-
case 0:
|
|
337
|
-
thunk = bundledJsonEntryImport(plan.module, key);
|
|
338
|
-
_t19 = key;
|
|
339
|
-
if (!thunk) {
|
|
340
|
-
_context20.n = 2;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
_context20.n = 1;
|
|
344
|
-
return thunk();
|
|
345
|
-
case 1:
|
|
346
|
-
_t20 = _context20.v["default"];
|
|
347
|
-
_context20.n = 3;
|
|
348
|
-
break;
|
|
349
|
-
case 2:
|
|
350
|
-
_t20 = undefined;
|
|
351
|
-
case 3:
|
|
352
|
-
_t21 = _t20;
|
|
353
|
-
return _context20.a(2, [_t19, _t21]);
|
|
354
|
-
}
|
|
355
|
-
}, _callee20);
|
|
70
|
+
case 1:
|
|
71
|
+
_yield$draftForReques = _context.v;
|
|
72
|
+
enabled = _yield$draftForReques.enabled;
|
|
73
|
+
draft = _yield$draftForReques.draft;
|
|
74
|
+
env = requestEnv(enabled, draft);
|
|
75
|
+
return _context.a(2, awaitResolved(function (settled) {
|
|
76
|
+
return resolveVal(selector, env, _objectSpread2({
|
|
77
|
+
settled: settled
|
|
78
|
+
}, opts));
|
|
356
79
|
}));
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return _context21.a(2, function (path) {
|
|
365
|
-
return path === plan.modulePath ? filled : first(path);
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}, _callee21);
|
|
369
|
-
}));
|
|
370
|
-
return _withJsonValuesEntries.apply(this, arguments);
|
|
371
|
-
}
|
|
372
|
-
function getHost(headers) {
|
|
373
|
-
var _headers$get;
|
|
374
|
-
// TODO: does NextJs have a way to determine this?
|
|
375
|
-
var host = headers === null || headers === void 0 ? void 0 : headers.get("host");
|
|
376
|
-
var proto = "https";
|
|
377
|
-
if ((headers === null || headers === void 0 ? void 0 : headers.get("x-forwarded-proto")) === "http") {
|
|
378
|
-
proto = "http";
|
|
379
|
-
} else if (headers !== null && headers !== void 0 && (_headers$get = headers.get("referer")) !== null && _headers$get !== void 0 && _headers$get.startsWith("http://")) {
|
|
380
|
-
proto = "http";
|
|
381
|
-
} else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
|
|
382
|
-
proto = "http";
|
|
383
|
-
}
|
|
384
|
-
if (host && proto) {
|
|
385
|
-
return "".concat(proto, "://").concat(host);
|
|
386
|
-
}
|
|
387
|
-
return null;
|
|
80
|
+
}
|
|
81
|
+
}, _callee);
|
|
82
|
+
}));
|
|
83
|
+
return function (_x, _x2) {
|
|
84
|
+
return _ref.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
}();
|
|
388
87
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
// const session = cookies.get(Internal.VAL_SESSION_COOKIE);
|
|
396
|
-
// if (session) {
|
|
397
|
-
// return {
|
|
398
|
-
// Cookie: `${Internal.VAL_SESSION_COOKIE}=${encodeURIComponent(
|
|
399
|
-
// session.value
|
|
400
|
-
// )}`,
|
|
401
|
-
// };
|
|
402
|
-
// }
|
|
403
|
-
// return {};
|
|
404
|
-
// } catch (err) {
|
|
405
|
-
// console.error(
|
|
406
|
-
// "Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.",
|
|
407
|
-
// err
|
|
408
|
-
// );
|
|
409
|
-
// return {};
|
|
410
|
-
// }
|
|
411
|
-
// }
|
|
412
|
-
|
|
413
|
-
var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope) {
|
|
88
|
+
var initFetchValStega = function initFetchValStega(deps) {
|
|
89
|
+
return fetchValFrom(fetchValWithReads(deps));
|
|
90
|
+
};
|
|
91
|
+
var initFetchValRouteStega = function initFetchValRouteStega(deps) {
|
|
92
|
+
var fetchVal = fetchValWithReads(deps);
|
|
93
|
+
var fetchValKey = initFetchValKeyStega(deps);
|
|
414
94
|
return /*#__PURE__*/function () {
|
|
415
|
-
var
|
|
416
|
-
var resolvedParams, valModule, path, schema,
|
|
417
|
-
return _regenerator().w(function (
|
|
418
|
-
while (1) switch (
|
|
95
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(selector, params) {
|
|
96
|
+
var resolvedParams, valModule, path, schema, url, content, val, _t;
|
|
97
|
+
return _regenerator().w(function (_context2) {
|
|
98
|
+
while (1) switch (_context2.n) {
|
|
419
99
|
case 0:
|
|
420
|
-
|
|
100
|
+
_context2.n = 1;
|
|
421
101
|
return Promise.resolve(params);
|
|
422
102
|
case 1:
|
|
423
|
-
resolvedParams =
|
|
103
|
+
resolvedParams = _context2.v;
|
|
424
104
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
425
105
|
// off this, and a pointer has none of them. See `resolveViewedModule`.
|
|
426
106
|
valModule = Internal.resolveViewedModule(selector);
|
|
427
107
|
path = valModule && Internal.getValPath(valModule);
|
|
428
108
|
schema = valModule && Internal.getSchema(valModule); // `.jsonValues()` router: map params → the entry key and load ONLY that
|
|
429
|
-
// entry
|
|
430
|
-
// record via `fetchVal`.
|
|
109
|
+
// entry, instead of the whole record.
|
|
431
110
|
if (!isJsonValuesRecordSchema(schema)) {
|
|
432
|
-
|
|
111
|
+
_context2.n = 4;
|
|
433
112
|
break;
|
|
434
113
|
}
|
|
435
|
-
|
|
436
|
-
url = getValRouteUrlFromVal(resolvedParams, "fetchValRoute", path, schema, source);
|
|
114
|
+
url = getValRouteUrlFromVal(resolvedParams, "fetchValRoute", path, schema, valModule && Internal.getSource(valModule));
|
|
437
115
|
if (url) {
|
|
438
|
-
|
|
116
|
+
_context2.n = 2;
|
|
439
117
|
break;
|
|
440
118
|
}
|
|
441
|
-
return
|
|
119
|
+
return _context2.a(2, null);
|
|
442
120
|
case 2:
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
121
|
+
_context2.n = 3;
|
|
122
|
+
return fetchValKey(valModule, url);
|
|
123
|
+
case 3:
|
|
124
|
+
content = _context2.v;
|
|
125
|
+
return _context2.a(2, content === undefined ? null : content);
|
|
447
126
|
case 4:
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
case 5:
|
|
452
|
-
_context4.p = 5;
|
|
453
|
-
_context4.v;
|
|
454
|
-
case 6:
|
|
455
|
-
draft = {
|
|
456
|
-
status: "unavailable"
|
|
457
|
-
};
|
|
458
|
-
if (!(enabled && path)) {
|
|
459
|
-
_context4.n = 8;
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
463
|
-
_context4.n = 7;
|
|
464
|
-
return loadDraftJsonEntry(valServerPromise, getCookies, path, url);
|
|
465
|
-
case 7:
|
|
466
|
-
draft = _context4.v;
|
|
467
|
-
case 8:
|
|
468
|
-
_context4.n = 9;
|
|
469
|
-
return resolveDraftOrCommittedEntry(draft, function () {
|
|
470
|
-
return loadJsonEntryContent(source, url);
|
|
471
|
-
});
|
|
472
|
-
case 9:
|
|
473
|
-
content = _context4.v;
|
|
474
|
-
if (!(content === undefined)) {
|
|
475
|
-
_context4.n = 10;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
return _context4.a(2, null);
|
|
479
|
-
case 10:
|
|
480
|
-
return _context4.a(2, stegaEncode(content, {
|
|
481
|
-
disabled: !enabled,
|
|
482
|
-
root: getJsonEntryStegaRoot(valModule, url)
|
|
483
|
-
}));
|
|
484
|
-
case 11:
|
|
485
|
-
fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
|
|
486
|
-
_t15 = valModule;
|
|
487
|
-
if (!_t15) {
|
|
488
|
-
_context4.n = 13;
|
|
127
|
+
_t = valModule;
|
|
128
|
+
if (!_t) {
|
|
129
|
+
_context2.n = 6;
|
|
489
130
|
break;
|
|
490
131
|
}
|
|
491
|
-
|
|
132
|
+
_context2.n = 5;
|
|
492
133
|
return fetchVal(valModule);
|
|
493
|
-
case
|
|
494
|
-
|
|
495
|
-
case
|
|
496
|
-
val =
|
|
497
|
-
|
|
498
|
-
return _context4.a(2, route);
|
|
134
|
+
case 5:
|
|
135
|
+
_t = _context2.v.value;
|
|
136
|
+
case 6:
|
|
137
|
+
val = _t;
|
|
138
|
+
return _context2.a(2, initValRouteFromVal(resolvedParams, "fetchValRoute", path, schema, val));
|
|
499
139
|
}
|
|
500
|
-
},
|
|
140
|
+
}, _callee2);
|
|
501
141
|
}));
|
|
502
|
-
return function (
|
|
503
|
-
return
|
|
142
|
+
return function (_x3, _x4) {
|
|
143
|
+
return _ref2.apply(this, arguments);
|
|
504
144
|
};
|
|
505
145
|
}();
|
|
506
146
|
};
|
|
507
147
|
|
|
508
|
-
/**
|
|
509
|
-
* Resolves a single `.jsonValues()` entry's content by key from a module's local
|
|
510
|
-
* source markers (one dynamic import). Returns `undefined` when the key is
|
|
511
|
-
* missing or its marker has no runtime thunk (transport marker / draft entry).
|
|
512
|
-
*/
|
|
513
|
-
function loadJsonEntryContent(_x8, _x9) {
|
|
514
|
-
return _loadJsonEntryContent.apply(this, arguments);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Loads a single `.jsonValues()` entry's DRAFT content via the in-process
|
|
518
|
-
* `/json` endpoint (which replays pending patches). Returns `undefined` when the
|
|
519
|
-
* entry has no draft content to serve — the caller then falls back to the
|
|
520
|
-
* locally-bundled committed content.
|
|
521
|
-
*/
|
|
522
|
-
/**
|
|
523
|
-
* What the draft state says about an entry.
|
|
524
|
-
*
|
|
525
|
-
* The three cases have to stay distinct: `absent` is an ANSWER — the entry is not
|
|
526
|
-
* there in the draft state, e.g. a pending patch removed it — while `unavailable`
|
|
527
|
-
* means we could not ask. Collapsing them into `undefined` is what made a
|
|
528
|
-
* draft-deleted entry keep rendering its committed content: the caller could not
|
|
529
|
-
* tell "it is gone" from "ask the committed source instead".
|
|
530
|
-
*/
|
|
531
|
-
/**
|
|
532
|
-
* The slice of `ValServer` the single-entry readers actually use. Narrower than
|
|
533
|
-
* `ValServer` on purpose: it says what the dependency IS, and it lets a test
|
|
534
|
-
* drive these readers with a one-route fake instead of casting a partial object
|
|
535
|
-
* to the whole server type.
|
|
536
|
-
*/
|
|
537
|
-
function _loadJsonEntryContent() {
|
|
538
|
-
_loadJsonEntryContent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(source, key) {
|
|
539
|
-
var marker, thunk;
|
|
540
|
-
return _regenerator().w(function (_context22) {
|
|
541
|
-
while (1) switch (_context22.n) {
|
|
542
|
-
case 0:
|
|
543
|
-
if (!(!source || _typeof(source) !== "object")) {
|
|
544
|
-
_context22.n = 1;
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
return _context22.a(2, undefined);
|
|
548
|
-
case 1:
|
|
549
|
-
marker = source[key];
|
|
550
|
-
if (Internal.isJson(marker)) {
|
|
551
|
-
_context22.n = 2;
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
return _context22.a(2, undefined);
|
|
555
|
-
case 2:
|
|
556
|
-
thunk = Internal.getJsonImport(marker);
|
|
557
|
-
if (thunk) {
|
|
558
|
-
_context22.n = 3;
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
return _context22.a(2, undefined);
|
|
562
|
-
case 3:
|
|
563
|
-
_context22.n = 4;
|
|
564
|
-
return thunk();
|
|
565
|
-
case 4:
|
|
566
|
-
return _context22.a(2, _context22.v["default"]);
|
|
567
|
-
}
|
|
568
|
-
}, _callee22);
|
|
569
|
-
}));
|
|
570
|
-
return _loadJsonEntryContent.apply(this, arguments);
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* Picks the content a draft-aware single-entry read should render.
|
|
574
|
-
*
|
|
575
|
-
* The rule the two callers share: the draft state WINS when it has an answer —
|
|
576
|
-
* including the answer "this entry is gone" — and the committed content is used
|
|
577
|
-
* only when there is no draft answer to be had (Val disabled, or we could not
|
|
578
|
-
* ask). Returning `undefined` means "render nothing"; both callers turn that into
|
|
579
|
-
* a null/undefined result.
|
|
580
|
-
*/
|
|
581
|
-
function resolveDraftOrCommittedEntry(_x0, _x1) {
|
|
582
|
-
return _resolveDraftOrCommittedEntry.apply(this, arguments);
|
|
583
|
-
}
|
|
584
|
-
function _resolveDraftOrCommittedEntry() {
|
|
585
|
-
_resolveDraftOrCommittedEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(draft, loadCommitted) {
|
|
586
|
-
return _regenerator().w(function (_context23) {
|
|
587
|
-
while (1) switch (_context23.n) {
|
|
588
|
-
case 0:
|
|
589
|
-
if (!(draft.status === "content")) {
|
|
590
|
-
_context23.n = 1;
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
return _context23.a(2, draft.content);
|
|
594
|
-
case 1:
|
|
595
|
-
if (!(draft.status === "absent")) {
|
|
596
|
-
_context23.n = 2;
|
|
597
|
-
break;
|
|
598
|
-
}
|
|
599
|
-
return _context23.a(2, undefined);
|
|
600
|
-
case 2:
|
|
601
|
-
return _context23.a(2, loadCommitted());
|
|
602
|
-
}
|
|
603
|
-
}, _callee23);
|
|
604
|
-
}));
|
|
605
|
-
return _resolveDraftOrCommittedEntry.apply(this, arguments);
|
|
606
|
-
}
|
|
607
|
-
function loadDraftJsonEntry(_x10, _x11, _x12, _x13) {
|
|
608
|
-
return _loadDraftJsonEntry.apply(this, arguments);
|
|
609
|
-
}
|
|
610
148
|
/**
|
|
611
149
|
* Resolves ONE `.jsonValues()` entry by key, loading only that entry instead of
|
|
612
150
|
* the whole record — the runtime-scaling counterpart to the eager `fetchVal`.
|
|
613
151
|
*
|
|
614
|
-
* Production (Val disabled):
|
|
615
|
-
*
|
|
152
|
+
* Production (Val disabled): the entry's lazy import from the bundle. One
|
|
153
|
+
* dynamic import, no server round-trip.
|
|
616
154
|
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
155
|
+
* Draft mode: the entry from the runtime's head, with the pending patches the
|
|
156
|
+
* draft holds for it, so uncommitted Studio edits show up; an entry the draft
|
|
157
|
+
* deleted is not there. An entry of a record no patch touched is the bundle's.
|
|
620
158
|
*/
|
|
621
|
-
function
|
|
622
|
-
_loadDraftJsonEntry = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(valServerPromise, getCookies, moduleFilePath, key) {
|
|
623
|
-
var _cookies3;
|
|
624
|
-
var cookies, valServer, res;
|
|
625
|
-
return _regenerator().w(function (_context24) {
|
|
626
|
-
while (1) switch (_context24.p = _context24.n) {
|
|
627
|
-
case 0:
|
|
628
|
-
_context24.p = 0;
|
|
629
|
-
_context24.n = 1;
|
|
630
|
-
return getCookies();
|
|
631
|
-
case 1:
|
|
632
|
-
cookies = _context24.v;
|
|
633
|
-
_context24.n = 3;
|
|
634
|
-
break;
|
|
635
|
-
case 2:
|
|
636
|
-
_context24.p = 2;
|
|
637
|
-
_context24.v;
|
|
638
|
-
return _context24.a(2, {
|
|
639
|
-
status: "unavailable"
|
|
640
|
-
});
|
|
641
|
-
case 3:
|
|
642
|
-
_context24.n = 4;
|
|
643
|
-
return valServerPromise;
|
|
644
|
-
case 4:
|
|
645
|
-
valServer = _context24.v;
|
|
646
|
-
_context24.n = 5;
|
|
647
|
-
return valServer["/json"]["GET"]({
|
|
648
|
-
query: {
|
|
649
|
-
path: moduleFilePath,
|
|
650
|
-
key: key,
|
|
651
|
-
keys: undefined,
|
|
652
|
-
// single-entry shape
|
|
653
|
-
offset: undefined,
|
|
654
|
-
limit: undefined,
|
|
655
|
-
apply_patches: true
|
|
656
|
-
},
|
|
657
|
-
cookies: _defineProperty({}, VAL_SESSION_COOKIE, (_cookies3 = cookies) === null || _cookies3 === void 0 || (_cookies3 = _cookies3.get(VAL_SESSION_COOKIE)) === null || _cookies3 === void 0 ? void 0 : _cookies3.value)
|
|
658
|
-
});
|
|
659
|
-
case 5:
|
|
660
|
-
res = _context24.v;
|
|
661
|
-
if (!(res.status === 200 && "content" in res.json)) {
|
|
662
|
-
_context24.n = 6;
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
return _context24.a(2, {
|
|
666
|
-
status: "content",
|
|
667
|
-
content: res.json.content
|
|
668
|
-
});
|
|
669
|
-
case 6:
|
|
670
|
-
if (!(res.status === 401)) {
|
|
671
|
-
_context24.n = 7;
|
|
672
|
-
break;
|
|
673
|
-
}
|
|
674
|
-
Internal.log.debug("authentication error: ", res.json.message);
|
|
675
|
-
return _context24.a(2, {
|
|
676
|
-
status: "unavailable"
|
|
677
|
-
});
|
|
678
|
-
case 7:
|
|
679
|
-
if (!(res.status === 404)) {
|
|
680
|
-
_context24.n = 8;
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
return _context24.a(2, {
|
|
684
|
-
status: "absent"
|
|
685
|
-
});
|
|
686
|
-
case 8:
|
|
687
|
-
Internal.log.error("could not load draft JSON entry: ", "message" in res.json ? res.json.message : "status ".concat(res.status));
|
|
688
|
-
return _context24.a(2, {
|
|
689
|
-
status: "unavailable"
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
}, _callee24, null, [[0, 2]]);
|
|
693
|
-
}));
|
|
694
|
-
return _loadDraftJsonEntry.apply(this, arguments);
|
|
695
|
-
}
|
|
696
|
-
var initFetchValKeyStega = function initFetchValKeyStega(valServerPromise, isEnabled, getCookies) {
|
|
159
|
+
var initFetchValKeyStega = function initFetchValKeyStega(deps) {
|
|
697
160
|
return /*#__PURE__*/function () {
|
|
698
|
-
var
|
|
699
|
-
var
|
|
700
|
-
return _regenerator().w(function (
|
|
701
|
-
while (1) switch (
|
|
161
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(selector, key) {
|
|
162
|
+
var _yield$draftForReques2, enabled, draft, env;
|
|
163
|
+
return _regenerator().w(function (_context3) {
|
|
164
|
+
while (1) switch (_context3.n) {
|
|
702
165
|
case 0:
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
enabled = _context5.v;
|
|
709
|
-
_context5.n = 4;
|
|
710
|
-
break;
|
|
711
|
-
case 3:
|
|
712
|
-
_context5.p = 3;
|
|
713
|
-
_context5.v;
|
|
714
|
-
case 4:
|
|
715
|
-
// A view is a pointer: everything below reads a path and a source off this,
|
|
716
|
-
// and a pointer has neither. See `resolveViewedModule`.
|
|
717
|
-
valModule = Internal.resolveViewedModule(selector);
|
|
718
|
-
source = valModule && Internal.getSource(valModule);
|
|
719
|
-
moduleFilePath = valModule && Internal.getValPath(valModule);
|
|
720
|
-
draft = {
|
|
721
|
-
status: "unavailable"
|
|
722
|
-
};
|
|
723
|
-
if (!(enabled && moduleFilePath)) {
|
|
724
|
-
_context5.n = 6;
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
728
|
-
_context5.n = 5;
|
|
729
|
-
return loadDraftJsonEntry(valServerPromise, getCookies, moduleFilePath, key);
|
|
730
|
-
case 5:
|
|
731
|
-
draft = _context5.v;
|
|
732
|
-
case 6:
|
|
733
|
-
_context5.n = 7;
|
|
734
|
-
return resolveDraftOrCommittedEntry(draft, function () {
|
|
735
|
-
return loadJsonEntryContent(source, key);
|
|
166
|
+
_context3.n = 1;
|
|
167
|
+
return draftForRequest({
|
|
168
|
+
runtime: deps.runtime,
|
|
169
|
+
isEnabled: deps.isEnabled,
|
|
170
|
+
getCookies: deps.getCookies
|
|
736
171
|
});
|
|
737
|
-
case
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
return
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
172
|
+
case 1:
|
|
173
|
+
_yield$draftForReques2 = _context3.v;
|
|
174
|
+
enabled = _yield$draftForReques2.enabled;
|
|
175
|
+
draft = _yield$draftForReques2.draft;
|
|
176
|
+
env = requestEnv(enabled, draft);
|
|
177
|
+
_context3.n = 2;
|
|
178
|
+
return awaitResolved(function (settled) {
|
|
179
|
+
return resolveValEntry(selector, key, env, {
|
|
180
|
+
settled: settled
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
case 2:
|
|
184
|
+
return _context3.a(2, _context3.v.value);
|
|
749
185
|
}
|
|
750
|
-
},
|
|
186
|
+
}, _callee3);
|
|
751
187
|
}));
|
|
752
|
-
return function (
|
|
753
|
-
return
|
|
188
|
+
return function (_x5, _x6) {
|
|
189
|
+
return _ref3.apply(this, arguments);
|
|
754
190
|
};
|
|
755
191
|
}();
|
|
756
192
|
};
|
|
757
|
-
var initFetchValRouteUrl = function initFetchValRouteUrl(
|
|
193
|
+
var initFetchValRouteUrl = function initFetchValRouteUrl(deps) {
|
|
194
|
+
var fetchVal = fetchValWithReads(deps);
|
|
758
195
|
return /*#__PURE__*/function () {
|
|
759
|
-
var
|
|
760
|
-
var
|
|
761
|
-
return _regenerator().w(function (
|
|
762
|
-
while (1) switch (
|
|
196
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(selector, params) {
|
|
197
|
+
var resolvedParams, valModule, val, _t2, _t3;
|
|
198
|
+
return _regenerator().w(function (_context4) {
|
|
199
|
+
while (1) switch (_context4.n) {
|
|
763
200
|
case 0:
|
|
764
|
-
fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies, getDraftSourcesScope);
|
|
765
201
|
if (!(params === undefined)) {
|
|
766
|
-
|
|
202
|
+
_context4.n = 1;
|
|
767
203
|
break;
|
|
768
204
|
}
|
|
769
|
-
|
|
770
|
-
|
|
205
|
+
_t2 = undefined;
|
|
206
|
+
_context4.n = 3;
|
|
771
207
|
break;
|
|
772
208
|
case 1:
|
|
773
|
-
|
|
209
|
+
_context4.n = 2;
|
|
774
210
|
return Promise.resolve(params);
|
|
775
211
|
case 2:
|
|
776
|
-
|
|
212
|
+
_t2 = _context4.v;
|
|
777
213
|
case 3:
|
|
778
|
-
resolvedParams =
|
|
214
|
+
resolvedParams = _t2;
|
|
779
215
|
// A view is a pointer: everything below reads a path, a schema and a source
|
|
780
216
|
// off this, and a pointer has none of them. See `resolveViewedModule`.
|
|
781
|
-
valModule = Internal.resolveViewedModule(selector);
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
_context6.n = 5;
|
|
217
|
+
valModule = Internal.resolveViewedModule(selector); // The url is made of the params and the module's path: a `.jsonValues()`
|
|
218
|
+
// router's entries are not imported for it.
|
|
219
|
+
_t3 = valModule;
|
|
220
|
+
if (!_t3) {
|
|
221
|
+
_context4.n = 5;
|
|
787
222
|
break;
|
|
788
223
|
}
|
|
789
|
-
|
|
790
|
-
return fetchVal(valModule
|
|
224
|
+
_context4.n = 4;
|
|
225
|
+
return fetchVal(valModule, {
|
|
226
|
+
entries: false
|
|
227
|
+
});
|
|
791
228
|
case 4:
|
|
792
|
-
|
|
229
|
+
_t3 = _context4.v.value;
|
|
793
230
|
case 5:
|
|
794
|
-
val =
|
|
795
|
-
|
|
796
|
-
return _context6.a(2, route);
|
|
231
|
+
val = _t3;
|
|
232
|
+
return _context4.a(2, getValRouteUrlFromVal(resolvedParams, "fetchValRouteUrl", valModule && Internal.getValPath(valModule), valModule && Internal.getSchema(valModule), val));
|
|
797
233
|
}
|
|
798
|
-
},
|
|
234
|
+
}, _callee4);
|
|
799
235
|
}));
|
|
800
|
-
return function (
|
|
801
|
-
return
|
|
236
|
+
return function (_x7, _x8) {
|
|
237
|
+
return _ref4.apply(this, arguments);
|
|
802
238
|
};
|
|
803
239
|
}();
|
|
804
240
|
};
|
|
805
|
-
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The draft a page in this request should start from, or `null` for none:
|
|
244
|
+
* what `<ValProvider draft>` takes. See `ValDraft`.
|
|
245
|
+
*
|
|
246
|
+
* `null` -- and no read at all -- unless the request is in draft mode: a
|
|
247
|
+
* visitor pays one `draftMode()` lookup, which does not make a static route
|
|
248
|
+
* dynamic. In draft mode it is the source of every module the editor's draft
|
|
249
|
+
* changes, from the runtime's head -- the one every `fetchVal` reads -- so
|
|
250
|
+
* the server renders the draft and the browser hydrates the same thing, with
|
|
251
|
+
* the version of each, so the page compares versions with what the Studio
|
|
252
|
+
* relays rather than content. Also `null` when the session is not one Val
|
|
253
|
+
* accepts, or the draft could not be read (logged): the published page.
|
|
254
|
+
*
|
|
255
|
+
* The read is `readDraftChanges` in `@valbuild/server`, which
|
|
256
|
+
* `@valbuild/tanstack/server`'s `fetchValDraft` is too; only where draft mode
|
|
257
|
+
* and the cookies come from is Next's.
|
|
258
|
+
*/
|
|
259
|
+
var initFetchValDraft = function initFetchValDraft(deps) {
|
|
260
|
+
return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
261
|
+
var changes;
|
|
262
|
+
return _regenerator().w(function (_context5) {
|
|
263
|
+
while (1) switch (_context5.n) {
|
|
264
|
+
case 0:
|
|
265
|
+
_context5.n = 1;
|
|
266
|
+
return readDraftChanges(deps);
|
|
267
|
+
case 1:
|
|
268
|
+
changes = _context5.v;
|
|
269
|
+
return _context5.a(2, changes === null ? null : {
|
|
270
|
+
sources: changes.sources,
|
|
271
|
+
versions: changes.versions
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}, _callee5);
|
|
275
|
+
}));
|
|
276
|
+
};
|
|
806
277
|
function initValRsc(config, valModules, rscNextConfig) {
|
|
807
278
|
var coreVersion = Internal.VERSION.core;
|
|
808
279
|
if (!coreVersion) {
|
|
@@ -812,175 +283,75 @@ function initValRsc(config, valModules, rscNextConfig) {
|
|
|
812
283
|
if (!nextVersion) {
|
|
813
284
|
throw new Error("Could not get @valbuild/next package version");
|
|
814
285
|
}
|
|
815
|
-
|
|
816
|
-
|
|
286
|
+
// One runtime per process for these modules: the API route's server is
|
|
287
|
+
// built on the same one, so a save through it moves what these read.
|
|
288
|
+
var runtime = createValRuntime(valModules, "/api/val", _objectSpread2({
|
|
817
289
|
versions: {
|
|
818
290
|
next: nextVersion,
|
|
819
291
|
core: coreVersion,
|
|
820
292
|
framework: "next"
|
|
821
293
|
}
|
|
822
|
-
}, config), config
|
|
823
|
-
|
|
824
|
-
|
|
294
|
+
}, config), config);
|
|
295
|
+
var deps = {
|
|
296
|
+
runtime: runtime,
|
|
297
|
+
isEnabled: function () {
|
|
298
|
+
var _isEnabled = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
299
|
+
return _regenerator().w(function (_context6) {
|
|
300
|
+
while (1) switch (_context6.n) {
|
|
301
|
+
case 0:
|
|
302
|
+
_context6.n = 1;
|
|
303
|
+
return rscNextConfig.draftMode();
|
|
304
|
+
case 1:
|
|
305
|
+
return _context6.a(2, _context6.v.isEnabled);
|
|
306
|
+
}
|
|
307
|
+
}, _callee6);
|
|
308
|
+
}));
|
|
309
|
+
function isEnabled() {
|
|
310
|
+
return _isEnabled.apply(this, arguments);
|
|
311
|
+
}
|
|
312
|
+
return isEnabled;
|
|
313
|
+
}(),
|
|
314
|
+
getHeaders: function () {
|
|
315
|
+
var _getHeaders = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
825
316
|
return _regenerator().w(function (_context7) {
|
|
826
317
|
while (1) switch (_context7.n) {
|
|
827
318
|
case 0:
|
|
828
319
|
_context7.n = 1;
|
|
829
|
-
return rscNextConfig.
|
|
320
|
+
return rscNextConfig.headers();
|
|
830
321
|
case 1:
|
|
831
|
-
return _context7.a(2, _context7.v
|
|
322
|
+
return _context7.a(2, _context7.v);
|
|
832
323
|
}
|
|
833
324
|
}, _callee7);
|
|
834
|
-
}))
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
325
|
+
}));
|
|
326
|
+
function getHeaders() {
|
|
327
|
+
return _getHeaders.apply(this, arguments);
|
|
328
|
+
}
|
|
329
|
+
return getHeaders;
|
|
330
|
+
}(),
|
|
331
|
+
getCookies: function () {
|
|
332
|
+
var _getCookies = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
838
333
|
return _regenerator().w(function (_context8) {
|
|
839
334
|
while (1) switch (_context8.n) {
|
|
840
335
|
case 0:
|
|
841
336
|
_context8.n = 1;
|
|
842
|
-
return rscNextConfig.
|
|
337
|
+
return rscNextConfig.cookies();
|
|
843
338
|
case 1:
|
|
844
|
-
_context8.v
|
|
845
|
-
case 2:
|
|
846
|
-
return _context8.a(2);
|
|
339
|
+
return _context8.a(2, _context8.v);
|
|
847
340
|
}
|
|
848
341
|
}, _callee8);
|
|
849
|
-
}))
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
_context9.n = 1;
|
|
857
|
-
return rscNextConfig.draftMode();
|
|
858
|
-
case 1:
|
|
859
|
-
_context9.v.disable();
|
|
860
|
-
case 2:
|
|
861
|
-
return _context9.a(2);
|
|
862
|
-
}
|
|
863
|
-
}, _callee9);
|
|
864
|
-
}))();
|
|
865
|
-
}
|
|
866
|
-
});
|
|
342
|
+
}));
|
|
343
|
+
function getCookies() {
|
|
344
|
+
return _getCookies.apply(this, arguments);
|
|
345
|
+
}
|
|
346
|
+
return getCookies;
|
|
347
|
+
}()
|
|
348
|
+
};
|
|
867
349
|
return {
|
|
868
|
-
fetchValStega: initFetchValStega(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
case 0:
|
|
874
|
-
_context0.n = 1;
|
|
875
|
-
return rscNextConfig.draftMode();
|
|
876
|
-
case 1:
|
|
877
|
-
return _context0.a(2, _context0.v.isEnabled);
|
|
878
|
-
}
|
|
879
|
-
}, _callee0);
|
|
880
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
881
|
-
return _regenerator().w(function (_context1) {
|
|
882
|
-
while (1) switch (_context1.n) {
|
|
883
|
-
case 0:
|
|
884
|
-
_context1.n = 1;
|
|
885
|
-
return rscNextConfig.headers();
|
|
886
|
-
case 1:
|
|
887
|
-
return _context1.a(2, _context1.v);
|
|
888
|
-
}
|
|
889
|
-
}, _callee1);
|
|
890
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
891
|
-
return _regenerator().w(function (_context10) {
|
|
892
|
-
while (1) switch (_context10.n) {
|
|
893
|
-
case 0:
|
|
894
|
-
_context10.n = 1;
|
|
895
|
-
return rscNextConfig.cookies();
|
|
896
|
-
case 1:
|
|
897
|
-
return _context10.a(2, _context10.v);
|
|
898
|
-
}
|
|
899
|
-
}, _callee10);
|
|
900
|
-
})), draftSourcesScope),
|
|
901
|
-
fetchValKeyStega: initFetchValKeyStega(valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
|
|
902
|
-
return _regenerator().w(function (_context11) {
|
|
903
|
-
while (1) switch (_context11.n) {
|
|
904
|
-
case 0:
|
|
905
|
-
_context11.n = 1;
|
|
906
|
-
return rscNextConfig.draftMode();
|
|
907
|
-
case 1:
|
|
908
|
-
return _context11.a(2, _context11.v.isEnabled);
|
|
909
|
-
}
|
|
910
|
-
}, _callee11);
|
|
911
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
912
|
-
return _regenerator().w(function (_context12) {
|
|
913
|
-
while (1) switch (_context12.n) {
|
|
914
|
-
case 0:
|
|
915
|
-
_context12.n = 1;
|
|
916
|
-
return rscNextConfig.cookies();
|
|
917
|
-
case 1:
|
|
918
|
-
return _context12.a(2, _context12.v);
|
|
919
|
-
}
|
|
920
|
-
}, _callee12);
|
|
921
|
-
}))),
|
|
922
|
-
fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
923
|
-
return _regenerator().w(function (_context13) {
|
|
924
|
-
while (1) switch (_context13.n) {
|
|
925
|
-
case 0:
|
|
926
|
-
_context13.n = 1;
|
|
927
|
-
return rscNextConfig.draftMode();
|
|
928
|
-
case 1:
|
|
929
|
-
return _context13.a(2, _context13.v.isEnabled);
|
|
930
|
-
}
|
|
931
|
-
}, _callee13);
|
|
932
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
|
|
933
|
-
return _regenerator().w(function (_context14) {
|
|
934
|
-
while (1) switch (_context14.n) {
|
|
935
|
-
case 0:
|
|
936
|
-
_context14.n = 1;
|
|
937
|
-
return rscNextConfig.headers();
|
|
938
|
-
case 1:
|
|
939
|
-
return _context14.a(2, _context14.v);
|
|
940
|
-
}
|
|
941
|
-
}, _callee14);
|
|
942
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
|
|
943
|
-
return _regenerator().w(function (_context15) {
|
|
944
|
-
while (1) switch (_context15.n) {
|
|
945
|
-
case 0:
|
|
946
|
-
_context15.n = 1;
|
|
947
|
-
return rscNextConfig.cookies();
|
|
948
|
-
case 1:
|
|
949
|
-
return _context15.a(2, _context15.v);
|
|
950
|
-
}
|
|
951
|
-
}, _callee15);
|
|
952
|
-
})), draftSourcesScope),
|
|
953
|
-
fetchValRouteUrl: initFetchValRouteUrl(config, valApiEndpoints, valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
|
|
954
|
-
return _regenerator().w(function (_context16) {
|
|
955
|
-
while (1) switch (_context16.n) {
|
|
956
|
-
case 0:
|
|
957
|
-
_context16.n = 1;
|
|
958
|
-
return rscNextConfig.draftMode();
|
|
959
|
-
case 1:
|
|
960
|
-
return _context16.a(2, _context16.v.isEnabled);
|
|
961
|
-
}
|
|
962
|
-
}, _callee16);
|
|
963
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
|
|
964
|
-
return _regenerator().w(function (_context17) {
|
|
965
|
-
while (1) switch (_context17.n) {
|
|
966
|
-
case 0:
|
|
967
|
-
_context17.n = 1;
|
|
968
|
-
return rscNextConfig.headers();
|
|
969
|
-
case 1:
|
|
970
|
-
return _context17.a(2, _context17.v);
|
|
971
|
-
}
|
|
972
|
-
}, _callee17);
|
|
973
|
-
})), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
|
|
974
|
-
return _regenerator().w(function (_context18) {
|
|
975
|
-
while (1) switch (_context18.n) {
|
|
976
|
-
case 0:
|
|
977
|
-
_context18.n = 1;
|
|
978
|
-
return rscNextConfig.cookies();
|
|
979
|
-
case 1:
|
|
980
|
-
return _context18.a(2, _context18.v);
|
|
981
|
-
}
|
|
982
|
-
}, _callee18);
|
|
983
|
-
})), draftSourcesScope)
|
|
350
|
+
fetchValStega: initFetchValStega(deps),
|
|
351
|
+
fetchValKeyStega: initFetchValKeyStega(deps),
|
|
352
|
+
fetchValRouteStega: initFetchValRouteStega(deps),
|
|
353
|
+
fetchValRouteUrl: initFetchValRouteUrl(deps),
|
|
354
|
+
fetchValDraft: initFetchValDraft(deps)
|
|
984
355
|
};
|
|
985
356
|
}
|
|
986
357
|
|