@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
|
@@ -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,
|
|
@@ -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",
|
|
@@ -213,7 +298,7 @@ function createPayloadDispatcher(frame) {
|
|
|
213
298
|
return dispatcher;
|
|
214
299
|
}
|
|
215
300
|
function serializeNode(node, frame) {
|
|
216
|
-
if (Array.isArray(node)) return
|
|
301
|
+
if (Array.isArray(node)) return serializeTreeArray(node, frame);
|
|
217
302
|
if (node === null || node === void 0 || typeof node === "boolean") return node === void 0 ? { $fig: "undefined" } : node;
|
|
218
303
|
if (typeof node === "string" || typeof node === "number") return node;
|
|
219
304
|
if (isPortal(node)) return null;
|
|
@@ -243,32 +328,32 @@ function serializeNodeOrLazy(node, frame, preserveElementIdentity = false) {
|
|
|
243
328
|
function serializeElement(element, frame, preserveIdentity) {
|
|
244
329
|
const type = element.type;
|
|
245
330
|
if (typeof type === "string") return serializeHostElement(element, type, frame, preserveIdentity);
|
|
246
|
-
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity,
|
|
331
|
+
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity, "children");
|
|
247
332
|
if (isClientReference(type)) return serializeElementModel(element, {
|
|
248
333
|
$fig: "client",
|
|
249
334
|
id: emitClientReference(frame.request, type)
|
|
250
335
|
}, frame, preserveIdentity);
|
|
251
336
|
if (isContext(type)) return serializeContextProvider(type, element.props, frame);
|
|
252
337
|
if (isAssets(type)) return serializeAssets(element.props, frame);
|
|
253
|
-
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity,
|
|
338
|
+
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity, "suspense");
|
|
254
339
|
if (isErrorBoundary(type)) return serializeNode(element.props.children, frame);
|
|
255
340
|
if (isActivity(type)) return serializeNode(element.props.children, frame);
|
|
256
|
-
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity,
|
|
341
|
+
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity, "children");
|
|
257
342
|
if (typeof type === "function") return serializeFunctionComponent(type, element.props, frame);
|
|
258
343
|
throw new Error("Unsupported Fig element type during payload render.");
|
|
259
344
|
}
|
|
260
345
|
function serializeHostElement(element, type, frame, preserveIdentity) {
|
|
261
346
|
const preload = imagePreloadFromHostProps(type, element.props, frame.imagePreloadsSuppressed);
|
|
262
|
-
if (preload !== null) frame.
|
|
347
|
+
if (preload !== null) frame.request.assets.append(preload, frame.pendingAssets);
|
|
263
348
|
const previousImagePreloadsSuppressed = frame.imagePreloadsSuppressed;
|
|
264
349
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed || suppressesImagePreloads(type);
|
|
265
350
|
try {
|
|
266
|
-
return serializeElementModel(element, type, frame, preserveIdentity,
|
|
351
|
+
return serializeElementModel(element, type, frame, preserveIdentity, "children");
|
|
267
352
|
} finally {
|
|
268
353
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed;
|
|
269
354
|
}
|
|
270
355
|
}
|
|
271
|
-
function serializeElementModel(element, type, frame, preserveIdentity, treeProps =
|
|
356
|
+
function serializeElementModel(element, type, frame, preserveIdentity, treeProps = null) {
|
|
272
357
|
const id = preserveIdentity ? definePayloadGraphElement(frame.request.graph, element) : void 0;
|
|
273
358
|
if (typeof id === "object") return id;
|
|
274
359
|
const model = {
|
|
@@ -282,7 +367,7 @@ function serializeElementModel(element, type, frame, preserveIdentity, treeProps
|
|
|
282
367
|
}
|
|
283
368
|
function serializeFunctionComponent(type, props, frame) {
|
|
284
369
|
const assetCheckpoint = frame.pendingAssets.length;
|
|
285
|
-
frame.
|
|
370
|
+
frame.request.assets.append(frame.request.componentAssets?.(type), frame.pendingAssets);
|
|
286
371
|
frame.dispatcher ??= createPayloadDispatcher(frame);
|
|
287
372
|
const previousDispatcher = setCurrentDispatcher(frame.dispatcher);
|
|
288
373
|
const previousDataStore = setCurrentDataStore(frame.request.dataStore);
|
|
@@ -315,7 +400,7 @@ function serializeContextProvider(context, props, frame) {
|
|
|
315
400
|
return withContextValue(frame.contextValues, context, props.value, () => serializeNode(props.children, frame));
|
|
316
401
|
}
|
|
317
402
|
function serializeAssets(props, frame) {
|
|
318
|
-
frame.
|
|
403
|
+
frame.request.assets.append(props.assets, frame.pendingAssets);
|
|
319
404
|
return serializeNode(props.children, frame);
|
|
320
405
|
}
|
|
321
406
|
function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
@@ -325,7 +410,7 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
325
410
|
for (const name of Object.keys(props)) {
|
|
326
411
|
if (hostElement && name === "mix") continue;
|
|
327
412
|
const child = props[name];
|
|
328
|
-
value[name] = treeProps
|
|
413
|
+
value[name] = treeProps !== null && (name === "children" || treeProps === "suspense" && name === "fallback") ? serializeTreeProp(child, frame) : serializeValue(child, frame);
|
|
329
414
|
}
|
|
330
415
|
return {
|
|
331
416
|
$fig: "object",
|
|
@@ -333,9 +418,19 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
333
418
|
};
|
|
334
419
|
}
|
|
335
420
|
function serializeTreeProp(value, frame) {
|
|
336
|
-
if (Array.isArray(value)) return
|
|
421
|
+
if (Array.isArray(value)) return serializeTreeArray(value, frame);
|
|
337
422
|
return serializeNodeOrLazy(value, frame);
|
|
338
423
|
}
|
|
424
|
+
function serializeTreeArray(value, frame) {
|
|
425
|
+
if (!value.some(Array.isArray)) return value.map((child) => serializeNodeOrLazy(child, frame));
|
|
426
|
+
const serialized = [];
|
|
427
|
+
appendTreeArray(value, frame, serialized);
|
|
428
|
+
return serialized;
|
|
429
|
+
}
|
|
430
|
+
function appendTreeArray(children, frame, output) {
|
|
431
|
+
for (const child of children) if (Array.isArray(child)) appendTreeArray(child, frame, output);
|
|
432
|
+
else output.push(serializeNodeOrLazy(child, frame));
|
|
433
|
+
}
|
|
339
434
|
function serializeValue(value, frame) {
|
|
340
435
|
if (isPlainPayloadValue(value)) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
341
436
|
if (isClientReference(value)) return {
|
|
@@ -353,52 +448,43 @@ function serializeValue(value, frame) {
|
|
|
353
448
|
if (value instanceof Date) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
354
449
|
if (value instanceof Map) return serializePayloadMap(value, frame.request.graph, ([key, item]) => [serializeValue(key, frame), serializeValue(item, frame)]);
|
|
355
450
|
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, (
|
|
451
|
+
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
357
452
|
return serializePayloadPlainObject(value, frame.request.graph, (child) => serializeValue(child, frame));
|
|
358
453
|
}
|
|
359
454
|
throw new Error(`Cannot serialize ${typeof value} into the payload.`);
|
|
360
455
|
}
|
|
361
456
|
function outlineTask(frame, value, referenceKind, wakeable, scopedAssets = []) {
|
|
362
457
|
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
|
-
};
|
|
458
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
459
|
+
const task = createTask(request, outline.id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
460
|
+
const ping = () => pingTask(request, task);
|
|
461
|
+
wakeable.then(ping, ping);
|
|
462
|
+
return outline;
|
|
375
463
|
}
|
|
376
464
|
function outlineError(frame, error, referenceKind, scopedAssets) {
|
|
377
465
|
const request = frame.request;
|
|
378
|
-
const
|
|
379
|
-
if (scopedAssets.length > 0) emitRow(request, {
|
|
380
|
-
for: id,
|
|
381
|
-
tag: "assets",
|
|
382
|
-
value: scopedAssets
|
|
383
|
-
});
|
|
466
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
384
467
|
emitRow(request, {
|
|
385
|
-
id,
|
|
468
|
+
id: outline.id,
|
|
386
469
|
tag: "error",
|
|
387
470
|
value: errorRowPayload(request, error, frame.stack)
|
|
388
471
|
});
|
|
389
|
-
return
|
|
390
|
-
|
|
391
|
-
|
|
472
|
+
return outline;
|
|
473
|
+
}
|
|
474
|
+
function createOutline(request, kind, assets) {
|
|
475
|
+
const outline = {
|
|
476
|
+
$fig: kind,
|
|
477
|
+
id: request.nextRowId++
|
|
392
478
|
};
|
|
479
|
+
if (assets.length > 0) emitRow(request, {
|
|
480
|
+
for: outline.id,
|
|
481
|
+
tag: "assets",
|
|
482
|
+
value: assets
|
|
483
|
+
});
|
|
484
|
+
return outline;
|
|
393
485
|
}
|
|
394
486
|
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
|
-
}
|
|
487
|
+
return serverErrorPayload(error, stackForError(error, stack), request.onError);
|
|
402
488
|
}
|
|
403
489
|
function recordErrorStack(error, stack) {
|
|
404
490
|
if (stack === null) return;
|
|
@@ -417,7 +503,7 @@ function clientReferenceExportName(id) {
|
|
|
417
503
|
function emitClientReference(request, reference) {
|
|
418
504
|
const existing = request.clientReferenceRows.get(reference.id);
|
|
419
505
|
if (existing !== void 0) return existing;
|
|
420
|
-
const assets =
|
|
506
|
+
const assets = request.assets.serializeClientReference(reference);
|
|
421
507
|
const value = { id: reference.id };
|
|
422
508
|
if (assets.length > 0) value.assets = assets;
|
|
423
509
|
const exportName = clientReferenceExportName(reference.id);
|
|
@@ -432,113 +518,12 @@ function emitClientReference(request, reference) {
|
|
|
432
518
|
});
|
|
433
519
|
return id;
|
|
434
520
|
}
|
|
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
521
|
function emitRow(request, row) {
|
|
537
522
|
request.queuedRows.push(jsonPayloadCodec.encodeRow(row));
|
|
538
523
|
flushRows(request);
|
|
539
524
|
}
|
|
540
525
|
function pingTask(request, task) {
|
|
541
|
-
if (request.
|
|
526
|
+
if (request.closed) return;
|
|
542
527
|
request.pingedTasks.push(task);
|
|
543
528
|
scheduleWork(request);
|
|
544
529
|
}
|
|
@@ -551,7 +536,7 @@ function scheduleWork(request) {
|
|
|
551
536
|
});
|
|
552
537
|
}
|
|
553
538
|
function flushRows(request) {
|
|
554
|
-
if (request.controller === null || request.
|
|
539
|
+
if (request.controller === null || request.closed) return;
|
|
555
540
|
if (request.flushingRows) return;
|
|
556
541
|
request.flushingRows = true;
|
|
557
542
|
try {
|
|
@@ -566,16 +551,16 @@ function flushRows(request) {
|
|
|
566
551
|
request.flushingRows = false;
|
|
567
552
|
}
|
|
568
553
|
if (request.pendingTasks === 0 && request.queuedRows.length === 0) {
|
|
569
|
-
request.
|
|
570
|
-
request.cleanupAbortListener();
|
|
554
|
+
request.closed = true;
|
|
555
|
+
request.cleanupAbortListener?.();
|
|
571
556
|
request.dataStore.dispose();
|
|
572
557
|
request.controller.close();
|
|
573
558
|
}
|
|
574
559
|
}
|
|
575
560
|
function closeWithError(request, error) {
|
|
576
|
-
if (request.
|
|
577
|
-
request.cleanupAbortListener();
|
|
578
|
-
request.
|
|
561
|
+
if (request.closed) return;
|
|
562
|
+
request.cleanupAbortListener?.();
|
|
563
|
+
request.closed = true;
|
|
579
564
|
request.dataStore.dispose();
|
|
580
565
|
request.allReady.reject(error);
|
|
581
566
|
request.controller?.error(error);
|
|
@@ -583,13 +568,6 @@ function closeWithError(request, error) {
|
|
|
583
568
|
function abortPayloadRequest(request, reason) {
|
|
584
569
|
closeWithError(request, reason ?? new PayloadRequestCancelledError());
|
|
585
570
|
}
|
|
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
571
|
function invalidChildError$1(value) {
|
|
594
572
|
return /* @__PURE__ */ new Error(`Invalid Fig child in payload render: ${describeInvalidChild(value)}.`);
|
|
595
573
|
}
|