@bgub/fig-server 0.1.0-alpha.6 → 0.1.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/dist/escaping-C2DNLoj9.js +34 -0
- package/dist/escaping-C2DNLoj9.js.map +1 -0
- package/dist/html-entry.js +1 -1
- package/dist/{image-preloads-BIFcrqm9.js → image-preloads-CWbCdmNa.js} +44 -46
- package/dist/image-preloads-CWbCdmNa.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +363 -448
- package/dist/index.js.map +1 -1
- package/dist/payload.d.ts +1 -1
- package/dist/payload.js +164 -186
- package/dist/payload.js.map +1 -1
- package/dist/{types-mrjoQDOc.d.ts → types-CZvaho7_.d.ts} +1 -1
- package/dist-development/escaping-C2DNLoj9.js +34 -0
- package/dist-development/escaping-C2DNLoj9.js.map +1 -0
- package/dist-development/html-entry.js +1 -1
- package/dist-development/{image-preloads-D3OBEaWp.js → image-preloads-C7OgNxdv.js} +44 -46
- package/dist-development/image-preloads-C7OgNxdv.js.map +1 -0
- package/dist-development/index.js +363 -448
- package/dist-development/index.js.map +1 -1
- package/dist-development/payload.js +163 -185
- package/dist-development/payload.js.map +1 -1
- package/package.json +4 -4
- package/dist/escaping-DAot8sFu.js +0 -26
- package/dist/escaping-DAot8sFu.js.map +0 -1
- package/dist/image-preloads-BIFcrqm9.js.map +0 -1
- package/dist-development/escaping-DAot8sFu.js +0 -26
- package/dist-development/escaping-DAot8sFu.js.map +0 -1
- package/dist-development/image-preloads-D3OBEaWp.js.map +0 -1
package/dist/payload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ServerErrorInfo, r as ServerErrorPayload } from "./types-
|
|
1
|
+
import { n as ServerErrorInfo, r as ServerErrorPayload } from "./types-CZvaho7_.js";
|
|
2
2
|
import { DataResourceKeyInput, FigAssetResourceList, FigNode, Props } from "@bgub/fig";
|
|
3
3
|
//#region src/payload.d.ts
|
|
4
4
|
interface PayloadRenderResult {
|
package/dist/payload.js
CHANGED
|
@@ -1,6 +1,101 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as createStaticDispatcher, d as streamFlowBlocked, f as streamHighWaterMark, i as cloneContextValues, l as noop, n as suppressesImagePreloads, o as deferred, p as withContextValue, s as noLane, t as imagePreloadFromHostProps, u as serverErrorPayload } from "./image-preloads-CWbCdmNa.js";
|
|
2
2
|
import { Fragment, isValidElement } from "@bgub/fig";
|
|
3
3
|
import { assetResourceDestination, assetResourceKey, checkpointPayloadGraph, clientOnlyHostBehavior, clientReferenceAssets, createPayloadGraphEncodeContext, createRendererDataStore, definePayloadGraphElement, describeInvalidChild, encodePayloadDataEntries, encodePayloadValueWithGraph, isActivity, isAssets, isClientReference, isContext, isErrorBoundary, isFigAssetResource, isPlainPayloadValue, isPortal, isSuspense, isThenable, isViewTransition, jsonPayloadCodec, readThenable, rollbackPayloadGraph, serializePayloadArray, serializePayloadMap, serializePayloadPlainObject, serializePayloadSet, setCurrentDataStore, setCurrentDispatcher } from "@bgub/fig/internal";
|
|
4
|
+
//#region src/payload-assets.ts
|
|
5
|
+
/** Owns request-wide delivery-asset dedupe and wire lowering. */
|
|
6
|
+
var PayloadAssets = class {
|
|
7
|
+
resolveClientReference;
|
|
8
|
+
emittedKeys = /* @__PURE__ */ new Set();
|
|
9
|
+
constructor(resolveClientReference) {
|
|
10
|
+
this.resolveClientReference = resolveClientReference;
|
|
11
|
+
}
|
|
12
|
+
append(value, output) {
|
|
13
|
+
if (isFigAssetResource(value)) {
|
|
14
|
+
this.appendResource(value, output);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(value)) return;
|
|
18
|
+
for (const resource of value) if (isFigAssetResource(resource)) this.appendResource(resource, output);
|
|
19
|
+
}
|
|
20
|
+
serializeClientReference(reference) {
|
|
21
|
+
const declared = clientReferenceAssets(reference);
|
|
22
|
+
const resolved = this.resolveClientReference?.({ id: reference.id });
|
|
23
|
+
const serialized = [];
|
|
24
|
+
this.append(declared, serialized);
|
|
25
|
+
this.append(resolved, serialized);
|
|
26
|
+
return serialized;
|
|
27
|
+
}
|
|
28
|
+
appendResource(resource, output) {
|
|
29
|
+
if (assetResourceDestination(resource) === "stream") {
|
|
30
|
+
const key = assetResourceKey(resource);
|
|
31
|
+
if (this.emittedKeys.has(key)) return;
|
|
32
|
+
this.emittedKeys.add(key);
|
|
33
|
+
}
|
|
34
|
+
output.push(serializeAssetResource(resource));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function serializeAssetResource(resource) {
|
|
38
|
+
switch (resource.kind) {
|
|
39
|
+
case "stylesheet": return {
|
|
40
|
+
href: resource.href,
|
|
41
|
+
kind: resource.kind,
|
|
42
|
+
crossorigin: resource.crossorigin,
|
|
43
|
+
media: resource.media,
|
|
44
|
+
precedence: resource.precedence
|
|
45
|
+
};
|
|
46
|
+
case "preload": return {
|
|
47
|
+
as: resource.as,
|
|
48
|
+
kind: resource.kind,
|
|
49
|
+
crossorigin: resource.crossorigin,
|
|
50
|
+
fetchpriority: resource.fetchpriority,
|
|
51
|
+
href: resource.href,
|
|
52
|
+
imagesizes: resource.imagesizes,
|
|
53
|
+
imagesrcset: resource.imagesrcset,
|
|
54
|
+
referrerpolicy: resource.referrerpolicy,
|
|
55
|
+
type: resource.type
|
|
56
|
+
};
|
|
57
|
+
case "modulepreload": return {
|
|
58
|
+
href: resource.href,
|
|
59
|
+
kind: resource.kind,
|
|
60
|
+
crossorigin: resource.crossorigin,
|
|
61
|
+
fetchpriority: resource.fetchpriority
|
|
62
|
+
};
|
|
63
|
+
case "script": return {
|
|
64
|
+
kind: resource.kind,
|
|
65
|
+
src: resource.src,
|
|
66
|
+
async: resource.async,
|
|
67
|
+
crossorigin: resource.crossorigin,
|
|
68
|
+
defer: resource.defer,
|
|
69
|
+
module: resource.module
|
|
70
|
+
};
|
|
71
|
+
case "font": return {
|
|
72
|
+
href: resource.href,
|
|
73
|
+
kind: resource.kind,
|
|
74
|
+
type: resource.type,
|
|
75
|
+
crossorigin: resource.crossorigin,
|
|
76
|
+
fetchpriority: resource.fetchpriority
|
|
77
|
+
};
|
|
78
|
+
case "preconnect": return {
|
|
79
|
+
href: resource.href,
|
|
80
|
+
kind: resource.kind,
|
|
81
|
+
crossorigin: resource.crossorigin
|
|
82
|
+
};
|
|
83
|
+
case "title": return {
|
|
84
|
+
kind: resource.kind,
|
|
85
|
+
value: resource.value
|
|
86
|
+
};
|
|
87
|
+
case "meta": return {
|
|
88
|
+
kind: resource.kind,
|
|
89
|
+
charset: resource.charset,
|
|
90
|
+
content: resource.content,
|
|
91
|
+
"http-equiv": resource["http-equiv"],
|
|
92
|
+
key: resource.key,
|
|
93
|
+
name: resource.name,
|
|
94
|
+
property: resource.property
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
4
99
|
//#region src/payload.ts
|
|
5
100
|
var PayloadRequestCancelledError = class extends Error {
|
|
6
101
|
constructor() {
|
|
@@ -9,36 +104,24 @@ var PayloadRequestCancelledError = class extends Error {
|
|
|
9
104
|
}
|
|
10
105
|
};
|
|
11
106
|
const errorStacks = /* @__PURE__ */ new WeakMap();
|
|
12
|
-
const childrenTreeProps = /* @__PURE__ */ new Set(["children"]);
|
|
13
|
-
const emptyTreeProps = /* @__PURE__ */ new Set();
|
|
14
|
-
const suspenseTreeProps = /* @__PURE__ */ new Set(["children", "fallback"]);
|
|
15
107
|
function renderToPayloadStream(node, options = {}) {
|
|
16
|
-
const { request, stream } = createPayloadRequest(node, options);
|
|
17
|
-
return {
|
|
18
|
-
allReady: request.allReady.promise,
|
|
19
|
-
contentType: jsonPayloadCodec.contentType,
|
|
20
|
-
stream
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function createPayloadRequest(node, options) {
|
|
24
108
|
throwIfAborted(options.signal);
|
|
25
109
|
const pendingDataSnapshots = /* @__PURE__ */ new Map();
|
|
26
110
|
const request = {
|
|
27
111
|
allReady: deferred(),
|
|
28
|
-
|
|
112
|
+
assets: new PayloadAssets(options.clientReferenceAssets),
|
|
113
|
+
cleanupAbortListener: null,
|
|
29
114
|
clientReferenceRows: /* @__PURE__ */ new Map(),
|
|
30
|
-
clientReferenceAssets: options.clientReferenceAssets,
|
|
31
115
|
componentAssets: options.componentAssets,
|
|
32
116
|
controller: null,
|
|
33
117
|
dataStore: createRendererDataStore({
|
|
34
|
-
getLane:
|
|
118
|
+
getLane: noLane,
|
|
35
119
|
onEntryChange: (entry) => {
|
|
36
120
|
pendingDataSnapshots.set(entry.canonicalKey, entry);
|
|
37
121
|
},
|
|
38
122
|
partition: options.dataPartition,
|
|
39
|
-
schedule:
|
|
123
|
+
schedule: noop
|
|
40
124
|
}),
|
|
41
|
-
emittedAssetKeys: /* @__PURE__ */ new Set(),
|
|
42
125
|
emittedDataKeys: /* @__PURE__ */ new Set(),
|
|
43
126
|
graph: createPayloadGraphEncodeContext(),
|
|
44
127
|
nextRowId: 1,
|
|
@@ -49,10 +132,10 @@ function createPayloadRequest(node, options) {
|
|
|
49
132
|
pingedTasks: [],
|
|
50
133
|
queuedRows: [],
|
|
51
134
|
flushingRows: false,
|
|
52
|
-
|
|
135
|
+
closed: false,
|
|
53
136
|
workScheduled: false
|
|
54
137
|
};
|
|
55
|
-
request.allReady.promise.catch(
|
|
138
|
+
request.allReady.promise.catch(noop);
|
|
56
139
|
request.pingedTasks.push(createTask(request, 0, {
|
|
57
140
|
kind: "node",
|
|
58
141
|
value: node
|
|
@@ -75,12 +158,13 @@ function createPayloadRequest(node, options) {
|
|
|
75
158
|
signal.addEventListener("abort", abortListener, { once: true });
|
|
76
159
|
request.cleanupAbortListener = () => {
|
|
77
160
|
signal.removeEventListener("abort", abortListener);
|
|
78
|
-
request.cleanupAbortListener =
|
|
161
|
+
request.cleanupAbortListener = null;
|
|
79
162
|
};
|
|
80
163
|
}
|
|
81
164
|
scheduleWork(request);
|
|
82
165
|
return {
|
|
83
|
-
request,
|
|
166
|
+
allReady: request.allReady.promise,
|
|
167
|
+
contentType: jsonPayloadCodec.contentType,
|
|
84
168
|
stream
|
|
85
169
|
};
|
|
86
170
|
}
|
|
@@ -95,7 +179,7 @@ function createTask(request, id, value, contextValues, imagePreloadsSuppressed,
|
|
|
95
179
|
};
|
|
96
180
|
}
|
|
97
181
|
function performWork(request) {
|
|
98
|
-
if (request.
|
|
182
|
+
if (request.closed) return;
|
|
99
183
|
const tasks = request.pingedTasks;
|
|
100
184
|
request.pingedTasks = [];
|
|
101
185
|
for (const task of tasks) retryTask(request, task);
|
|
@@ -103,7 +187,7 @@ function performWork(request) {
|
|
|
103
187
|
}
|
|
104
188
|
function retryTask(request, task) {
|
|
105
189
|
const frame = {
|
|
106
|
-
contextValues:
|
|
190
|
+
contextValues: task.contextValues,
|
|
107
191
|
dispatcher: null,
|
|
108
192
|
pendingAssets: [],
|
|
109
193
|
request,
|
|
@@ -119,9 +203,7 @@ function retryTask(request, task) {
|
|
|
119
203
|
case "node-promise":
|
|
120
204
|
value = serializeNode(readThenable(task.value), frame);
|
|
121
205
|
break;
|
|
122
|
-
case "promise":
|
|
123
|
-
value = serializeValue(readThenable(task.value), frame);
|
|
124
|
-
break;
|
|
206
|
+
case "promise": value = serializeValue(readThenable(task.value), frame);
|
|
125
207
|
}
|
|
126
208
|
flushFrameAssets(frame, task.id);
|
|
127
209
|
emitDataRows(request);
|
|
@@ -134,7 +216,8 @@ function retryTask(request, task) {
|
|
|
134
216
|
} catch (error) {
|
|
135
217
|
if (isThenable(error)) {
|
|
136
218
|
flushFrameAssets(frame, task.id);
|
|
137
|
-
|
|
219
|
+
const ping = () => pingTask(request, task);
|
|
220
|
+
error.then(ping, ping);
|
|
138
221
|
return;
|
|
139
222
|
}
|
|
140
223
|
flushFrameAssets(frame, task.id);
|
|
@@ -151,6 +234,7 @@ function finishTask(request) {
|
|
|
151
234
|
if (request.pendingTasks === 0) request.allReady.resolve(void 0);
|
|
152
235
|
}
|
|
153
236
|
function emitDataRows(request) {
|
|
237
|
+
if (request.pendingDataSnapshots.size === 0) return;
|
|
154
238
|
const entries = [];
|
|
155
239
|
for (const snapshot of request.pendingDataSnapshots.values()) {
|
|
156
240
|
if (!snapshot.hasValue || snapshot.status === "refreshing") continue;
|
|
@@ -173,7 +257,8 @@ function emitDataRows(request) {
|
|
|
173
257
|
}
|
|
174
258
|
function flushFrameAssets(frame, rowId) {
|
|
175
259
|
if (frame.pendingAssets.length === 0) return;
|
|
176
|
-
const value = frame.pendingAssets
|
|
260
|
+
const value = frame.pendingAssets;
|
|
261
|
+
frame.pendingAssets = [];
|
|
177
262
|
emitRow(frame.request, {
|
|
178
263
|
for: rowId,
|
|
179
264
|
tag: "assets",
|
|
@@ -200,7 +285,7 @@ function createPayloadDispatcher(frame) {
|
|
|
200
285
|
});
|
|
201
286
|
}
|
|
202
287
|
function serializeNode(node, frame) {
|
|
203
|
-
if (Array.isArray(node)) return
|
|
288
|
+
if (Array.isArray(node)) return serializeTreeArray(node, frame);
|
|
204
289
|
if (node === null || node === void 0 || typeof node === "boolean") return node === void 0 ? { $fig: "undefined" } : node;
|
|
205
290
|
if (typeof node === "string" || typeof node === "number") return node;
|
|
206
291
|
if (isPortal(node)) return null;
|
|
@@ -230,32 +315,32 @@ function serializeNodeOrLazy(node, frame, preserveElementIdentity = false) {
|
|
|
230
315
|
function serializeElement(element, frame, preserveIdentity) {
|
|
231
316
|
const type = element.type;
|
|
232
317
|
if (typeof type === "string") return serializeHostElement(element, type, frame, preserveIdentity);
|
|
233
|
-
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity,
|
|
318
|
+
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity, "children");
|
|
234
319
|
if (isClientReference(type)) return serializeElementModel(element, {
|
|
235
320
|
$fig: "client",
|
|
236
321
|
id: emitClientReference(frame.request, type)
|
|
237
322
|
}, frame, preserveIdentity);
|
|
238
323
|
if (isContext(type)) return serializeContextProvider(type, element.props, frame);
|
|
239
324
|
if (isAssets(type)) return serializeAssets(element.props, frame);
|
|
240
|
-
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity,
|
|
325
|
+
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity, "suspense");
|
|
241
326
|
if (isErrorBoundary(type)) return serializeNode(element.props.children, frame);
|
|
242
327
|
if (isActivity(type)) return serializeNode(element.props.children, frame);
|
|
243
|
-
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity,
|
|
328
|
+
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity, "children");
|
|
244
329
|
if (typeof type === "function") return serializeFunctionComponent(type, element.props, frame);
|
|
245
330
|
throw new Error("Unsupported Fig element type during payload render.");
|
|
246
331
|
}
|
|
247
332
|
function serializeHostElement(element, type, frame, preserveIdentity) {
|
|
248
333
|
const preload = imagePreloadFromHostProps(type, element.props, frame.imagePreloadsSuppressed);
|
|
249
|
-
if (preload !== null) frame.
|
|
334
|
+
if (preload !== null) frame.request.assets.append(preload, frame.pendingAssets);
|
|
250
335
|
const previousImagePreloadsSuppressed = frame.imagePreloadsSuppressed;
|
|
251
336
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed || suppressesImagePreloads(type);
|
|
252
337
|
try {
|
|
253
|
-
return serializeElementModel(element, type, frame, preserveIdentity,
|
|
338
|
+
return serializeElementModel(element, type, frame, preserveIdentity, "children");
|
|
254
339
|
} finally {
|
|
255
340
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed;
|
|
256
341
|
}
|
|
257
342
|
}
|
|
258
|
-
function serializeElementModel(element, type, frame, preserveIdentity, treeProps =
|
|
343
|
+
function serializeElementModel(element, type, frame, preserveIdentity, treeProps = null) {
|
|
259
344
|
const id = preserveIdentity ? definePayloadGraphElement(frame.request.graph, element) : void 0;
|
|
260
345
|
if (typeof id === "object") return id;
|
|
261
346
|
const model = {
|
|
@@ -269,12 +354,12 @@ function serializeElementModel(element, type, frame, preserveIdentity, treeProps
|
|
|
269
354
|
}
|
|
270
355
|
function serializeFunctionComponent(type, props, frame) {
|
|
271
356
|
const assetCheckpoint = frame.pendingAssets.length;
|
|
272
|
-
frame.
|
|
357
|
+
frame.request.assets.append(frame.request.componentAssets?.(type), frame.pendingAssets);
|
|
273
358
|
frame.dispatcher ??= createPayloadDispatcher(frame);
|
|
274
359
|
const previousDispatcher = setCurrentDispatcher(frame.dispatcher);
|
|
275
360
|
const previousDataStore = setCurrentDataStore(frame.request.dataStore);
|
|
276
361
|
const previousStack = frame.stack;
|
|
277
|
-
frame.stack = {
|
|
362
|
+
if (frame.request.onError !== void 0) frame.stack = {
|
|
278
363
|
name: type.name || "Anonymous",
|
|
279
364
|
parent: previousStack
|
|
280
365
|
};
|
|
@@ -301,7 +386,7 @@ function serializeContextProvider(context, props, frame) {
|
|
|
301
386
|
return withContextValue(frame.contextValues, context, props.value, () => serializeNode(props.children, frame));
|
|
302
387
|
}
|
|
303
388
|
function serializeAssets(props, frame) {
|
|
304
|
-
frame.
|
|
389
|
+
frame.request.assets.append(props.assets, frame.pendingAssets);
|
|
305
390
|
return serializeNode(props.children, frame);
|
|
306
391
|
}
|
|
307
392
|
function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
@@ -311,7 +396,7 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
311
396
|
for (const name of Object.keys(props)) {
|
|
312
397
|
if (hostElement && name === "mix") continue;
|
|
313
398
|
const child = props[name];
|
|
314
|
-
value[name] = treeProps
|
|
399
|
+
value[name] = treeProps !== null && (name === "children" || treeProps === "suspense" && name === "fallback") ? serializeTreeProp(child, frame) : serializeValue(child, frame);
|
|
315
400
|
}
|
|
316
401
|
return {
|
|
317
402
|
$fig: "object",
|
|
@@ -319,9 +404,19 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
319
404
|
};
|
|
320
405
|
}
|
|
321
406
|
function serializeTreeProp(value, frame) {
|
|
322
|
-
if (Array.isArray(value)) return
|
|
407
|
+
if (Array.isArray(value)) return serializeTreeArray(value, frame);
|
|
323
408
|
return serializeNodeOrLazy(value, frame);
|
|
324
409
|
}
|
|
410
|
+
function serializeTreeArray(value, frame) {
|
|
411
|
+
if (!value.some(Array.isArray)) return value.map((child) => serializeNodeOrLazy(child, frame));
|
|
412
|
+
const serialized = [];
|
|
413
|
+
appendTreeArray(value, frame, serialized);
|
|
414
|
+
return serialized;
|
|
415
|
+
}
|
|
416
|
+
function appendTreeArray(children, frame, output) {
|
|
417
|
+
for (const child of children) if (Array.isArray(child)) appendTreeArray(child, frame, output);
|
|
418
|
+
else output.push(serializeNodeOrLazy(child, frame));
|
|
419
|
+
}
|
|
325
420
|
function serializeValue(value, frame) {
|
|
326
421
|
if (isPlainPayloadValue(value)) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
327
422
|
if (isClientReference(value)) return {
|
|
@@ -339,52 +434,43 @@ function serializeValue(value, frame) {
|
|
|
339
434
|
if (value instanceof Date) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
340
435
|
if (value instanceof Map) return serializePayloadMap(value, frame.request.graph, ([key, item]) => [serializeValue(key, frame), serializeValue(item, frame)]);
|
|
341
436
|
if (value instanceof Set) return serializePayloadSet(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
342
|
-
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (
|
|
437
|
+
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
343
438
|
return serializePayloadPlainObject(value, frame.request.graph, (child) => serializeValue(child, frame));
|
|
344
439
|
}
|
|
345
440
|
throw new Error(`Cannot serialize ${typeof value} into the payload.`);
|
|
346
441
|
}
|
|
347
442
|
function outlineTask(frame, value, referenceKind, wakeable, scopedAssets = []) {
|
|
348
443
|
const request = frame.request;
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
});
|
|
355
|
-
const task = createTask(request, id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
356
|
-
wakeable.then(() => pingTask(request, task), () => pingTask(request, task));
|
|
357
|
-
return {
|
|
358
|
-
$fig: referenceKind,
|
|
359
|
-
id
|
|
360
|
-
};
|
|
444
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
445
|
+
const task = createTask(request, outline.id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
446
|
+
const ping = () => pingTask(request, task);
|
|
447
|
+
wakeable.then(ping, ping);
|
|
448
|
+
return outline;
|
|
361
449
|
}
|
|
362
450
|
function outlineError(frame, error, referenceKind, scopedAssets) {
|
|
363
451
|
const request = frame.request;
|
|
364
|
-
const
|
|
365
|
-
if (scopedAssets.length > 0) emitRow(request, {
|
|
366
|
-
for: id,
|
|
367
|
-
tag: "assets",
|
|
368
|
-
value: scopedAssets
|
|
369
|
-
});
|
|
452
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
370
453
|
emitRow(request, {
|
|
371
|
-
id,
|
|
454
|
+
id: outline.id,
|
|
372
455
|
tag: "error",
|
|
373
456
|
value: errorRowPayload(request, error, frame.stack)
|
|
374
457
|
});
|
|
375
|
-
return
|
|
376
|
-
|
|
377
|
-
|
|
458
|
+
return outline;
|
|
459
|
+
}
|
|
460
|
+
function createOutline(request, kind, assets) {
|
|
461
|
+
const outline = {
|
|
462
|
+
$fig: kind,
|
|
463
|
+
id: request.nextRowId++
|
|
378
464
|
};
|
|
465
|
+
if (assets.length > 0) emitRow(request, {
|
|
466
|
+
for: outline.id,
|
|
467
|
+
tag: "assets",
|
|
468
|
+
value: assets
|
|
469
|
+
});
|
|
470
|
+
return outline;
|
|
379
471
|
}
|
|
380
472
|
function errorRowPayload(request, error, stack) {
|
|
381
|
-
|
|
382
|
-
if (request.onError === void 0) return {};
|
|
383
|
-
try {
|
|
384
|
-
return request.onError(error, info) ?? {};
|
|
385
|
-
} catch {
|
|
386
|
-
return {};
|
|
387
|
-
}
|
|
473
|
+
return serverErrorPayload(error, stackForError(error, stack), request.onError);
|
|
388
474
|
}
|
|
389
475
|
function recordErrorStack(error, stack) {
|
|
390
476
|
if (stack === null) return;
|
|
@@ -403,7 +489,7 @@ function clientReferenceExportName(id) {
|
|
|
403
489
|
function emitClientReference(request, reference) {
|
|
404
490
|
const existing = request.clientReferenceRows.get(reference.id);
|
|
405
491
|
if (existing !== void 0) return existing;
|
|
406
|
-
const assets =
|
|
492
|
+
const assets = request.assets.serializeClientReference(reference);
|
|
407
493
|
const value = { id: reference.id };
|
|
408
494
|
if (assets.length > 0) value.assets = assets;
|
|
409
495
|
const exportName = clientReferenceExportName(reference.id);
|
|
@@ -418,113 +504,12 @@ function emitClientReference(request, reference) {
|
|
|
418
504
|
});
|
|
419
505
|
return id;
|
|
420
506
|
}
|
|
421
|
-
function serializeAssetResources(request, value) {
|
|
422
|
-
const input = isFigAssetResource(value) ? [value] : Array.isArray(value) ? value : [];
|
|
423
|
-
const resources = [];
|
|
424
|
-
for (const resource of input) {
|
|
425
|
-
if (!isFigAssetResource(resource)) continue;
|
|
426
|
-
if (assetResourceDestination(resource) === "stream") {
|
|
427
|
-
const key = assetResourceKey(resource);
|
|
428
|
-
if (request.emittedAssetKeys.has(key)) continue;
|
|
429
|
-
request.emittedAssetKeys.add(key);
|
|
430
|
-
}
|
|
431
|
-
resources.push(serializeAssetResource(resource));
|
|
432
|
-
}
|
|
433
|
-
return resources;
|
|
434
|
-
}
|
|
435
|
-
function collectClientReferenceAssets(request, reference) {
|
|
436
|
-
const resources = [...clientReferenceAssets(reference)];
|
|
437
|
-
const resolved = request.clientReferenceAssets?.({ id: reference.id });
|
|
438
|
-
if (resolved === void 0) return resources;
|
|
439
|
-
if (isFigAssetResource(resolved)) return [...resources, resolved];
|
|
440
|
-
return Array.isArray(resolved) ? [...resources, ...resolved] : resources;
|
|
441
|
-
}
|
|
442
|
-
function serializeAssetResource(resource) {
|
|
443
|
-
switch (resource.kind) {
|
|
444
|
-
case "stylesheet": {
|
|
445
|
-
const model = {
|
|
446
|
-
href: resource.href,
|
|
447
|
-
kind: resource.kind
|
|
448
|
-
};
|
|
449
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
450
|
-
if (resource.media !== void 0) model.media = resource.media;
|
|
451
|
-
if (resource.precedence !== void 0) model.precedence = resource.precedence;
|
|
452
|
-
return model;
|
|
453
|
-
}
|
|
454
|
-
case "preload": {
|
|
455
|
-
const model = {
|
|
456
|
-
as: resource.as,
|
|
457
|
-
kind: resource.kind
|
|
458
|
-
};
|
|
459
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
460
|
-
if (resource.fetchpriority !== void 0) model.fetchpriority = resource.fetchpriority;
|
|
461
|
-
if (resource.href !== void 0) model.href = resource.href;
|
|
462
|
-
if (resource.imagesizes !== void 0) model.imagesizes = resource.imagesizes;
|
|
463
|
-
if (resource.imagesrcset !== void 0) model.imagesrcset = resource.imagesrcset;
|
|
464
|
-
if (resource.referrerpolicy !== void 0) model.referrerpolicy = resource.referrerpolicy;
|
|
465
|
-
if (resource.type !== void 0) model.type = resource.type;
|
|
466
|
-
return model;
|
|
467
|
-
}
|
|
468
|
-
case "modulepreload": {
|
|
469
|
-
const model = {
|
|
470
|
-
href: resource.href,
|
|
471
|
-
kind: resource.kind
|
|
472
|
-
};
|
|
473
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
474
|
-
if (resource.fetchpriority !== void 0) model.fetchpriority = resource.fetchpriority;
|
|
475
|
-
return model;
|
|
476
|
-
}
|
|
477
|
-
case "script": {
|
|
478
|
-
const model = {
|
|
479
|
-
kind: resource.kind,
|
|
480
|
-
src: resource.src
|
|
481
|
-
};
|
|
482
|
-
if (resource.async !== void 0) model.async = resource.async;
|
|
483
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
484
|
-
if (resource.defer !== void 0) model.defer = resource.defer;
|
|
485
|
-
if (resource.module !== void 0) model.module = resource.module;
|
|
486
|
-
return model;
|
|
487
|
-
}
|
|
488
|
-
case "font": {
|
|
489
|
-
const model = {
|
|
490
|
-
href: resource.href,
|
|
491
|
-
kind: resource.kind,
|
|
492
|
-
type: resource.type
|
|
493
|
-
};
|
|
494
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
495
|
-
if (resource.fetchpriority !== void 0) model.fetchpriority = resource.fetchpriority;
|
|
496
|
-
return model;
|
|
497
|
-
}
|
|
498
|
-
case "preconnect": {
|
|
499
|
-
const model = {
|
|
500
|
-
href: resource.href,
|
|
501
|
-
kind: resource.kind
|
|
502
|
-
};
|
|
503
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
504
|
-
return model;
|
|
505
|
-
}
|
|
506
|
-
case "title": return {
|
|
507
|
-
kind: resource.kind,
|
|
508
|
-
value: resource.value
|
|
509
|
-
};
|
|
510
|
-
case "meta": {
|
|
511
|
-
const model = { kind: resource.kind };
|
|
512
|
-
if (resource.charset !== void 0) model.charset = resource.charset;
|
|
513
|
-
if (resource.content !== void 0) model.content = resource.content;
|
|
514
|
-
if (resource["http-equiv"] !== void 0) model["http-equiv"] = resource["http-equiv"];
|
|
515
|
-
if (resource.key !== void 0) model.key = resource.key;
|
|
516
|
-
if (resource.name !== void 0) model.name = resource.name;
|
|
517
|
-
if (resource.property !== void 0) model.property = resource.property;
|
|
518
|
-
return model;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
507
|
function emitRow(request, row) {
|
|
523
508
|
request.queuedRows.push(jsonPayloadCodec.encodeRow(row));
|
|
524
509
|
flushRows(request);
|
|
525
510
|
}
|
|
526
511
|
function pingTask(request, task) {
|
|
527
|
-
if (request.
|
|
512
|
+
if (request.closed) return;
|
|
528
513
|
request.pingedTasks.push(task);
|
|
529
514
|
scheduleWork(request);
|
|
530
515
|
}
|
|
@@ -537,7 +522,7 @@ function scheduleWork(request) {
|
|
|
537
522
|
});
|
|
538
523
|
}
|
|
539
524
|
function flushRows(request) {
|
|
540
|
-
if (request.controller === null || request.
|
|
525
|
+
if (request.controller === null || request.closed) return;
|
|
541
526
|
if (request.flushingRows) return;
|
|
542
527
|
request.flushingRows = true;
|
|
543
528
|
try {
|
|
@@ -552,16 +537,16 @@ function flushRows(request) {
|
|
|
552
537
|
request.flushingRows = false;
|
|
553
538
|
}
|
|
554
539
|
if (request.pendingTasks === 0 && request.queuedRows.length === 0) {
|
|
555
|
-
request.
|
|
556
|
-
request.cleanupAbortListener();
|
|
540
|
+
request.closed = true;
|
|
541
|
+
request.cleanupAbortListener?.();
|
|
557
542
|
request.dataStore.dispose();
|
|
558
543
|
request.controller.close();
|
|
559
544
|
}
|
|
560
545
|
}
|
|
561
546
|
function closeWithError(request, error) {
|
|
562
|
-
if (request.
|
|
563
|
-
request.cleanupAbortListener();
|
|
564
|
-
request.
|
|
547
|
+
if (request.closed) return;
|
|
548
|
+
request.cleanupAbortListener?.();
|
|
549
|
+
request.closed = true;
|
|
565
550
|
request.dataStore.dispose();
|
|
566
551
|
request.allReady.reject(error);
|
|
567
552
|
request.controller?.error(error);
|
|
@@ -569,13 +554,6 @@ function closeWithError(request, error) {
|
|
|
569
554
|
function abortPayloadRequest(request, reason) {
|
|
570
555
|
closeWithError(request, reason ?? new PayloadRequestCancelledError());
|
|
571
556
|
}
|
|
572
|
-
function flattenChildArrays(children) {
|
|
573
|
-
if (!children.some(Array.isArray)) return children;
|
|
574
|
-
const collected = [];
|
|
575
|
-
for (const child of children) if (Array.isArray(child)) for (const nested of flattenChildArrays(child)) collected.push(nested);
|
|
576
|
-
else collected.push(child);
|
|
577
|
-
return collected;
|
|
578
|
-
}
|
|
579
557
|
function invalidChildError$1(value) {
|
|
580
558
|
return /* @__PURE__ */ new Error(`Invalid Fig child in payload render: ${describeInvalidChild(value)}.`);
|
|
581
559
|
}
|