@bgub/fig-server 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +387 -462
- package/dist/index.js.map +1 -1
- package/dist/payload.d.ts +1 -1
- package/dist/payload.js +163 -183
- 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 +386 -461
- package/dist-development/index.js.map +1 -1
- package/dist-development/payload.js +162 -182
- package/dist-development/payload.js.map +1 -1
- package/package.json +3 -3
- 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
|
@@ -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-C7OgNxdv.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,
|
|
@@ -134,7 +218,8 @@ function retryTask(request, task) {
|
|
|
134
218
|
} catch (error) {
|
|
135
219
|
if (isThenable(error)) {
|
|
136
220
|
flushFrameAssets(frame, task.id);
|
|
137
|
-
|
|
221
|
+
const ping = () => pingTask(request, task);
|
|
222
|
+
error.then(ping, ping);
|
|
138
223
|
return;
|
|
139
224
|
}
|
|
140
225
|
flushFrameAssets(frame, task.id);
|
|
@@ -151,6 +236,7 @@ function finishTask(request) {
|
|
|
151
236
|
if (request.pendingTasks === 0) request.allReady.resolve(void 0);
|
|
152
237
|
}
|
|
153
238
|
function emitDataRows(request) {
|
|
239
|
+
if (request.pendingDataSnapshots.size === 0) return;
|
|
154
240
|
const entries = [];
|
|
155
241
|
for (const snapshot of request.pendingDataSnapshots.values()) {
|
|
156
242
|
if (!snapshot.hasValue || snapshot.status === "refreshing") continue;
|
|
@@ -173,7 +259,8 @@ function emitDataRows(request) {
|
|
|
173
259
|
}
|
|
174
260
|
function flushFrameAssets(frame, rowId) {
|
|
175
261
|
if (frame.pendingAssets.length === 0) return;
|
|
176
|
-
const value = frame.pendingAssets
|
|
262
|
+
const value = frame.pendingAssets;
|
|
263
|
+
frame.pendingAssets = [];
|
|
177
264
|
emitRow(frame.request, {
|
|
178
265
|
for: rowId,
|
|
179
266
|
tag: "assets",
|
|
@@ -213,7 +300,7 @@ function createPayloadDispatcher(frame) {
|
|
|
213
300
|
return dispatcher;
|
|
214
301
|
}
|
|
215
302
|
function serializeNode(node, frame) {
|
|
216
|
-
if (Array.isArray(node)) return
|
|
303
|
+
if (Array.isArray(node)) return serializeTreeArray(node, frame);
|
|
217
304
|
if (node === null || node === void 0 || typeof node === "boolean") return node === void 0 ? { $fig: "undefined" } : node;
|
|
218
305
|
if (typeof node === "string" || typeof node === "number") return node;
|
|
219
306
|
if (isPortal(node)) return null;
|
|
@@ -243,32 +330,32 @@ function serializeNodeOrLazy(node, frame, preserveElementIdentity = false) {
|
|
|
243
330
|
function serializeElement(element, frame, preserveIdentity) {
|
|
244
331
|
const type = element.type;
|
|
245
332
|
if (typeof type === "string") return serializeHostElement(element, type, frame, preserveIdentity);
|
|
246
|
-
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity,
|
|
333
|
+
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity, "children");
|
|
247
334
|
if (isClientReference(type)) return serializeElementModel(element, {
|
|
248
335
|
$fig: "client",
|
|
249
336
|
id: emitClientReference(frame.request, type)
|
|
250
337
|
}, frame, preserveIdentity);
|
|
251
338
|
if (isContext(type)) return serializeContextProvider(type, element.props, frame);
|
|
252
339
|
if (isAssets(type)) return serializeAssets(element.props, frame);
|
|
253
|
-
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity,
|
|
340
|
+
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity, "suspense");
|
|
254
341
|
if (isErrorBoundary(type)) return serializeNode(element.props.children, frame);
|
|
255
342
|
if (isActivity(type)) return serializeNode(element.props.children, frame);
|
|
256
|
-
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity,
|
|
343
|
+
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity, "children");
|
|
257
344
|
if (typeof type === "function") return serializeFunctionComponent(type, element.props, frame);
|
|
258
345
|
throw new Error("Unsupported Fig element type during payload render.");
|
|
259
346
|
}
|
|
260
347
|
function serializeHostElement(element, type, frame, preserveIdentity) {
|
|
261
348
|
const preload = imagePreloadFromHostProps(type, element.props, frame.imagePreloadsSuppressed);
|
|
262
|
-
if (preload !== null) frame.
|
|
349
|
+
if (preload !== null) frame.request.assets.append(preload, frame.pendingAssets);
|
|
263
350
|
const previousImagePreloadsSuppressed = frame.imagePreloadsSuppressed;
|
|
264
351
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed || suppressesImagePreloads(type);
|
|
265
352
|
try {
|
|
266
|
-
return serializeElementModel(element, type, frame, preserveIdentity,
|
|
353
|
+
return serializeElementModel(element, type, frame, preserveIdentity, "children");
|
|
267
354
|
} finally {
|
|
268
355
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed;
|
|
269
356
|
}
|
|
270
357
|
}
|
|
271
|
-
function serializeElementModel(element, type, frame, preserveIdentity, treeProps =
|
|
358
|
+
function serializeElementModel(element, type, frame, preserveIdentity, treeProps = null) {
|
|
272
359
|
const id = preserveIdentity ? definePayloadGraphElement(frame.request.graph, element) : void 0;
|
|
273
360
|
if (typeof id === "object") return id;
|
|
274
361
|
const model = {
|
|
@@ -282,7 +369,7 @@ function serializeElementModel(element, type, frame, preserveIdentity, treeProps
|
|
|
282
369
|
}
|
|
283
370
|
function serializeFunctionComponent(type, props, frame) {
|
|
284
371
|
const assetCheckpoint = frame.pendingAssets.length;
|
|
285
|
-
frame.
|
|
372
|
+
frame.request.assets.append(frame.request.componentAssets?.(type), frame.pendingAssets);
|
|
286
373
|
frame.dispatcher ??= createPayloadDispatcher(frame);
|
|
287
374
|
const previousDispatcher = setCurrentDispatcher(frame.dispatcher);
|
|
288
375
|
const previousDataStore = setCurrentDataStore(frame.request.dataStore);
|
|
@@ -315,7 +402,7 @@ function serializeContextProvider(context, props, frame) {
|
|
|
315
402
|
return withContextValue(frame.contextValues, context, props.value, () => serializeNode(props.children, frame));
|
|
316
403
|
}
|
|
317
404
|
function serializeAssets(props, frame) {
|
|
318
|
-
frame.
|
|
405
|
+
frame.request.assets.append(props.assets, frame.pendingAssets);
|
|
319
406
|
return serializeNode(props.children, frame);
|
|
320
407
|
}
|
|
321
408
|
function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
@@ -325,7 +412,7 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
325
412
|
for (const name of Object.keys(props)) {
|
|
326
413
|
if (hostElement && name === "mix") continue;
|
|
327
414
|
const child = props[name];
|
|
328
|
-
value[name] = treeProps
|
|
415
|
+
value[name] = treeProps !== null && (name === "children" || treeProps === "suspense" && name === "fallback") ? serializeTreeProp(child, frame) : serializeValue(child, frame);
|
|
329
416
|
}
|
|
330
417
|
return {
|
|
331
418
|
$fig: "object",
|
|
@@ -333,9 +420,19 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
333
420
|
};
|
|
334
421
|
}
|
|
335
422
|
function serializeTreeProp(value, frame) {
|
|
336
|
-
if (Array.isArray(value)) return
|
|
423
|
+
if (Array.isArray(value)) return serializeTreeArray(value, frame);
|
|
337
424
|
return serializeNodeOrLazy(value, frame);
|
|
338
425
|
}
|
|
426
|
+
function serializeTreeArray(value, frame) {
|
|
427
|
+
if (!value.some(Array.isArray)) return value.map((child) => serializeNodeOrLazy(child, frame));
|
|
428
|
+
const serialized = [];
|
|
429
|
+
appendTreeArray(value, frame, serialized);
|
|
430
|
+
return serialized;
|
|
431
|
+
}
|
|
432
|
+
function appendTreeArray(children, frame, output) {
|
|
433
|
+
for (const child of children) if (Array.isArray(child)) appendTreeArray(child, frame, output);
|
|
434
|
+
else output.push(serializeNodeOrLazy(child, frame));
|
|
435
|
+
}
|
|
339
436
|
function serializeValue(value, frame) {
|
|
340
437
|
if (isPlainPayloadValue(value)) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
341
438
|
if (isClientReference(value)) return {
|
|
@@ -353,52 +450,43 @@ function serializeValue(value, frame) {
|
|
|
353
450
|
if (value instanceof Date) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
354
451
|
if (value instanceof Map) return serializePayloadMap(value, frame.request.graph, ([key, item]) => [serializeValue(key, frame), serializeValue(item, frame)]);
|
|
355
452
|
if (value instanceof Set) return serializePayloadSet(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
356
|
-
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (
|
|
453
|
+
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
357
454
|
return serializePayloadPlainObject(value, frame.request.graph, (child) => serializeValue(child, frame));
|
|
358
455
|
}
|
|
359
456
|
throw new Error(`Cannot serialize ${typeof value} into the payload.`);
|
|
360
457
|
}
|
|
361
458
|
function outlineTask(frame, value, referenceKind, wakeable, scopedAssets = []) {
|
|
362
459
|
const request = frame.request;
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
});
|
|
369
|
-
const task = createTask(request, id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
370
|
-
wakeable.then(() => pingTask(request, task), () => pingTask(request, task));
|
|
371
|
-
return {
|
|
372
|
-
$fig: referenceKind,
|
|
373
|
-
id
|
|
374
|
-
};
|
|
460
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
461
|
+
const task = createTask(request, outline.id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
462
|
+
const ping = () => pingTask(request, task);
|
|
463
|
+
wakeable.then(ping, ping);
|
|
464
|
+
return outline;
|
|
375
465
|
}
|
|
376
466
|
function outlineError(frame, error, referenceKind, scopedAssets) {
|
|
377
467
|
const request = frame.request;
|
|
378
|
-
const
|
|
379
|
-
if (scopedAssets.length > 0) emitRow(request, {
|
|
380
|
-
for: id,
|
|
381
|
-
tag: "assets",
|
|
382
|
-
value: scopedAssets
|
|
383
|
-
});
|
|
468
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
384
469
|
emitRow(request, {
|
|
385
|
-
id,
|
|
470
|
+
id: outline.id,
|
|
386
471
|
tag: "error",
|
|
387
472
|
value: errorRowPayload(request, error, frame.stack)
|
|
388
473
|
});
|
|
389
|
-
return
|
|
390
|
-
|
|
391
|
-
|
|
474
|
+
return outline;
|
|
475
|
+
}
|
|
476
|
+
function createOutline(request, kind, assets) {
|
|
477
|
+
const outline = {
|
|
478
|
+
$fig: kind,
|
|
479
|
+
id: request.nextRowId++
|
|
392
480
|
};
|
|
481
|
+
if (assets.length > 0) emitRow(request, {
|
|
482
|
+
for: outline.id,
|
|
483
|
+
tag: "assets",
|
|
484
|
+
value: assets
|
|
485
|
+
});
|
|
486
|
+
return outline;
|
|
393
487
|
}
|
|
394
488
|
function errorRowPayload(request, error, stack) {
|
|
395
|
-
|
|
396
|
-
if (request.onError === void 0) return { message: errorMessage(error) };
|
|
397
|
-
try {
|
|
398
|
-
return request.onError(error, info) ?? {};
|
|
399
|
-
} catch {
|
|
400
|
-
return {};
|
|
401
|
-
}
|
|
489
|
+
return serverErrorPayload(error, stackForError(error, stack), request.onError);
|
|
402
490
|
}
|
|
403
491
|
function recordErrorStack(error, stack) {
|
|
404
492
|
if (stack === null) return;
|
|
@@ -417,7 +505,7 @@ function clientReferenceExportName(id) {
|
|
|
417
505
|
function emitClientReference(request, reference) {
|
|
418
506
|
const existing = request.clientReferenceRows.get(reference.id);
|
|
419
507
|
if (existing !== void 0) return existing;
|
|
420
|
-
const assets =
|
|
508
|
+
const assets = request.assets.serializeClientReference(reference);
|
|
421
509
|
const value = { id: reference.id };
|
|
422
510
|
if (assets.length > 0) value.assets = assets;
|
|
423
511
|
const exportName = clientReferenceExportName(reference.id);
|
|
@@ -432,113 +520,12 @@ function emitClientReference(request, reference) {
|
|
|
432
520
|
});
|
|
433
521
|
return id;
|
|
434
522
|
}
|
|
435
|
-
function serializeAssetResources(request, value) {
|
|
436
|
-
const input = isFigAssetResource(value) ? [value] : Array.isArray(value) ? value : [];
|
|
437
|
-
const resources = [];
|
|
438
|
-
for (const resource of input) {
|
|
439
|
-
if (!isFigAssetResource(resource)) continue;
|
|
440
|
-
if (assetResourceDestination(resource) === "stream") {
|
|
441
|
-
const key = assetResourceKey(resource);
|
|
442
|
-
if (request.emittedAssetKeys.has(key)) continue;
|
|
443
|
-
request.emittedAssetKeys.add(key);
|
|
444
|
-
}
|
|
445
|
-
resources.push(serializeAssetResource(resource));
|
|
446
|
-
}
|
|
447
|
-
return resources;
|
|
448
|
-
}
|
|
449
|
-
function collectClientReferenceAssets(request, reference) {
|
|
450
|
-
const resources = [...clientReferenceAssets(reference)];
|
|
451
|
-
const resolved = request.clientReferenceAssets?.({ id: reference.id });
|
|
452
|
-
if (resolved === void 0) return resources;
|
|
453
|
-
if (isFigAssetResource(resolved)) return [...resources, resolved];
|
|
454
|
-
return Array.isArray(resolved) ? [...resources, ...resolved] : resources;
|
|
455
|
-
}
|
|
456
|
-
function serializeAssetResource(resource) {
|
|
457
|
-
switch (resource.kind) {
|
|
458
|
-
case "stylesheet": {
|
|
459
|
-
const model = {
|
|
460
|
-
href: resource.href,
|
|
461
|
-
kind: resource.kind
|
|
462
|
-
};
|
|
463
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
464
|
-
if (resource.media !== void 0) model.media = resource.media;
|
|
465
|
-
if (resource.precedence !== void 0) model.precedence = resource.precedence;
|
|
466
|
-
return model;
|
|
467
|
-
}
|
|
468
|
-
case "preload": {
|
|
469
|
-
const model = {
|
|
470
|
-
as: resource.as,
|
|
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
|
-
if (resource.href !== void 0) model.href = resource.href;
|
|
476
|
-
if (resource.imagesizes !== void 0) model.imagesizes = resource.imagesizes;
|
|
477
|
-
if (resource.imagesrcset !== void 0) model.imagesrcset = resource.imagesrcset;
|
|
478
|
-
if (resource.referrerpolicy !== void 0) model.referrerpolicy = resource.referrerpolicy;
|
|
479
|
-
if (resource.type !== void 0) model.type = resource.type;
|
|
480
|
-
return model;
|
|
481
|
-
}
|
|
482
|
-
case "modulepreload": {
|
|
483
|
-
const model = {
|
|
484
|
-
href: resource.href,
|
|
485
|
-
kind: resource.kind
|
|
486
|
-
};
|
|
487
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
488
|
-
if (resource.fetchpriority !== void 0) model.fetchpriority = resource.fetchpriority;
|
|
489
|
-
return model;
|
|
490
|
-
}
|
|
491
|
-
case "script": {
|
|
492
|
-
const model = {
|
|
493
|
-
kind: resource.kind,
|
|
494
|
-
src: resource.src
|
|
495
|
-
};
|
|
496
|
-
if (resource.async !== void 0) model.async = resource.async;
|
|
497
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
498
|
-
if (resource.defer !== void 0) model.defer = resource.defer;
|
|
499
|
-
if (resource.module !== void 0) model.module = resource.module;
|
|
500
|
-
return model;
|
|
501
|
-
}
|
|
502
|
-
case "font": {
|
|
503
|
-
const model = {
|
|
504
|
-
href: resource.href,
|
|
505
|
-
kind: resource.kind,
|
|
506
|
-
type: resource.type
|
|
507
|
-
};
|
|
508
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
509
|
-
if (resource.fetchpriority !== void 0) model.fetchpriority = resource.fetchpriority;
|
|
510
|
-
return model;
|
|
511
|
-
}
|
|
512
|
-
case "preconnect": {
|
|
513
|
-
const model = {
|
|
514
|
-
href: resource.href,
|
|
515
|
-
kind: resource.kind
|
|
516
|
-
};
|
|
517
|
-
if (resource.crossorigin !== void 0) model.crossorigin = resource.crossorigin;
|
|
518
|
-
return model;
|
|
519
|
-
}
|
|
520
|
-
case "title": return {
|
|
521
|
-
kind: resource.kind,
|
|
522
|
-
value: resource.value
|
|
523
|
-
};
|
|
524
|
-
case "meta": {
|
|
525
|
-
const model = { kind: resource.kind };
|
|
526
|
-
if (resource.charset !== void 0) model.charset = resource.charset;
|
|
527
|
-
if (resource.content !== void 0) model.content = resource.content;
|
|
528
|
-
if (resource["http-equiv"] !== void 0) model["http-equiv"] = resource["http-equiv"];
|
|
529
|
-
if (resource.key !== void 0) model.key = resource.key;
|
|
530
|
-
if (resource.name !== void 0) model.name = resource.name;
|
|
531
|
-
if (resource.property !== void 0) model.property = resource.property;
|
|
532
|
-
return model;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
523
|
function emitRow(request, row) {
|
|
537
524
|
request.queuedRows.push(jsonPayloadCodec.encodeRow(row));
|
|
538
525
|
flushRows(request);
|
|
539
526
|
}
|
|
540
527
|
function pingTask(request, task) {
|
|
541
|
-
if (request.
|
|
528
|
+
if (request.closed) return;
|
|
542
529
|
request.pingedTasks.push(task);
|
|
543
530
|
scheduleWork(request);
|
|
544
531
|
}
|
|
@@ -551,7 +538,7 @@ function scheduleWork(request) {
|
|
|
551
538
|
});
|
|
552
539
|
}
|
|
553
540
|
function flushRows(request) {
|
|
554
|
-
if (request.controller === null || request.
|
|
541
|
+
if (request.controller === null || request.closed) return;
|
|
555
542
|
if (request.flushingRows) return;
|
|
556
543
|
request.flushingRows = true;
|
|
557
544
|
try {
|
|
@@ -566,16 +553,16 @@ function flushRows(request) {
|
|
|
566
553
|
request.flushingRows = false;
|
|
567
554
|
}
|
|
568
555
|
if (request.pendingTasks === 0 && request.queuedRows.length === 0) {
|
|
569
|
-
request.
|
|
570
|
-
request.cleanupAbortListener();
|
|
556
|
+
request.closed = true;
|
|
557
|
+
request.cleanupAbortListener?.();
|
|
571
558
|
request.dataStore.dispose();
|
|
572
559
|
request.controller.close();
|
|
573
560
|
}
|
|
574
561
|
}
|
|
575
562
|
function closeWithError(request, error) {
|
|
576
|
-
if (request.
|
|
577
|
-
request.cleanupAbortListener();
|
|
578
|
-
request.
|
|
563
|
+
if (request.closed) return;
|
|
564
|
+
request.cleanupAbortListener?.();
|
|
565
|
+
request.closed = true;
|
|
579
566
|
request.dataStore.dispose();
|
|
580
567
|
request.allReady.reject(error);
|
|
581
568
|
request.controller?.error(error);
|
|
@@ -583,13 +570,6 @@ function closeWithError(request, error) {
|
|
|
583
570
|
function abortPayloadRequest(request, reason) {
|
|
584
571
|
closeWithError(request, reason ?? new PayloadRequestCancelledError());
|
|
585
572
|
}
|
|
586
|
-
function flattenChildArrays(children) {
|
|
587
|
-
if (!children.some(Array.isArray)) return children;
|
|
588
|
-
const collected = [];
|
|
589
|
-
for (const child of children) if (Array.isArray(child)) for (const nested of flattenChildArrays(child)) collected.push(nested);
|
|
590
|
-
else collected.push(child);
|
|
591
|
-
return collected;
|
|
592
|
-
}
|
|
593
573
|
function invalidChildError$1(value) {
|
|
594
574
|
return /* @__PURE__ */ new Error(`Invalid Fig child in payload render: ${describeInvalidChild(value)}.`);
|
|
595
575
|
}
|