@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
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,
|
|
@@ -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",
|
|
@@ -200,7 +287,7 @@ function createPayloadDispatcher(frame) {
|
|
|
200
287
|
});
|
|
201
288
|
}
|
|
202
289
|
function serializeNode(node, frame) {
|
|
203
|
-
if (Array.isArray(node)) return
|
|
290
|
+
if (Array.isArray(node)) return serializeTreeArray(node, frame);
|
|
204
291
|
if (node === null || node === void 0 || typeof node === "boolean") return node === void 0 ? { $fig: "undefined" } : node;
|
|
205
292
|
if (typeof node === "string" || typeof node === "number") return node;
|
|
206
293
|
if (isPortal(node)) return null;
|
|
@@ -230,32 +317,32 @@ function serializeNodeOrLazy(node, frame, preserveElementIdentity = false) {
|
|
|
230
317
|
function serializeElement(element, frame, preserveIdentity) {
|
|
231
318
|
const type = element.type;
|
|
232
319
|
if (typeof type === "string") return serializeHostElement(element, type, frame, preserveIdentity);
|
|
233
|
-
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity,
|
|
320
|
+
if (type === Fragment) return serializeElementModel(element, { $fig: "fragment" }, frame, preserveIdentity, "children");
|
|
234
321
|
if (isClientReference(type)) return serializeElementModel(element, {
|
|
235
322
|
$fig: "client",
|
|
236
323
|
id: emitClientReference(frame.request, type)
|
|
237
324
|
}, frame, preserveIdentity);
|
|
238
325
|
if (isContext(type)) return serializeContextProvider(type, element.props, frame);
|
|
239
326
|
if (isAssets(type)) return serializeAssets(element.props, frame);
|
|
240
|
-
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity,
|
|
327
|
+
if (isSuspense(type)) return serializeElementModel(element, { $fig: "suspense" }, frame, preserveIdentity, "suspense");
|
|
241
328
|
if (isErrorBoundary(type)) return serializeNode(element.props.children, frame);
|
|
242
329
|
if (isActivity(type)) return serializeNode(element.props.children, frame);
|
|
243
|
-
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity,
|
|
330
|
+
if (isViewTransition(type)) return serializeElementModel(element, { $fig: "view-transition" }, frame, preserveIdentity, "children");
|
|
244
331
|
if (typeof type === "function") return serializeFunctionComponent(type, element.props, frame);
|
|
245
332
|
throw new Error("Unsupported Fig element type during payload render.");
|
|
246
333
|
}
|
|
247
334
|
function serializeHostElement(element, type, frame, preserveIdentity) {
|
|
248
335
|
const preload = imagePreloadFromHostProps(type, element.props, frame.imagePreloadsSuppressed);
|
|
249
|
-
if (preload !== null) frame.
|
|
336
|
+
if (preload !== null) frame.request.assets.append(preload, frame.pendingAssets);
|
|
250
337
|
const previousImagePreloadsSuppressed = frame.imagePreloadsSuppressed;
|
|
251
338
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed || suppressesImagePreloads(type);
|
|
252
339
|
try {
|
|
253
|
-
return serializeElementModel(element, type, frame, preserveIdentity,
|
|
340
|
+
return serializeElementModel(element, type, frame, preserveIdentity, "children");
|
|
254
341
|
} finally {
|
|
255
342
|
frame.imagePreloadsSuppressed = previousImagePreloadsSuppressed;
|
|
256
343
|
}
|
|
257
344
|
}
|
|
258
|
-
function serializeElementModel(element, type, frame, preserveIdentity, treeProps =
|
|
345
|
+
function serializeElementModel(element, type, frame, preserveIdentity, treeProps = null) {
|
|
259
346
|
const id = preserveIdentity ? definePayloadGraphElement(frame.request.graph, element) : void 0;
|
|
260
347
|
if (typeof id === "object") return id;
|
|
261
348
|
const model = {
|
|
@@ -269,12 +356,12 @@ function serializeElementModel(element, type, frame, preserveIdentity, treeProps
|
|
|
269
356
|
}
|
|
270
357
|
function serializeFunctionComponent(type, props, frame) {
|
|
271
358
|
const assetCheckpoint = frame.pendingAssets.length;
|
|
272
|
-
frame.
|
|
359
|
+
frame.request.assets.append(frame.request.componentAssets?.(type), frame.pendingAssets);
|
|
273
360
|
frame.dispatcher ??= createPayloadDispatcher(frame);
|
|
274
361
|
const previousDispatcher = setCurrentDispatcher(frame.dispatcher);
|
|
275
362
|
const previousDataStore = setCurrentDataStore(frame.request.dataStore);
|
|
276
363
|
const previousStack = frame.stack;
|
|
277
|
-
frame.stack = {
|
|
364
|
+
if (frame.request.onError !== void 0) frame.stack = {
|
|
278
365
|
name: type.name || "Anonymous",
|
|
279
366
|
parent: previousStack
|
|
280
367
|
};
|
|
@@ -301,7 +388,7 @@ function serializeContextProvider(context, props, frame) {
|
|
|
301
388
|
return withContextValue(frame.contextValues, context, props.value, () => serializeNode(props.children, frame));
|
|
302
389
|
}
|
|
303
390
|
function serializeAssets(props, frame) {
|
|
304
|
-
frame.
|
|
391
|
+
frame.request.assets.append(props.assets, frame.pendingAssets);
|
|
305
392
|
return serializeNode(props.children, frame);
|
|
306
393
|
}
|
|
307
394
|
function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
@@ -311,7 +398,7 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
311
398
|
for (const name of Object.keys(props)) {
|
|
312
399
|
if (hostElement && name === "mix") continue;
|
|
313
400
|
const child = props[name];
|
|
314
|
-
value[name] = treeProps
|
|
401
|
+
value[name] = treeProps !== null && (name === "children" || treeProps === "suspense" && name === "fallback") ? serializeTreeProp(child, frame) : serializeValue(child, frame);
|
|
315
402
|
}
|
|
316
403
|
return {
|
|
317
404
|
$fig: "object",
|
|
@@ -319,9 +406,19 @@ function serializeProps(props, frame, treeProps, hostElement = false) {
|
|
|
319
406
|
};
|
|
320
407
|
}
|
|
321
408
|
function serializeTreeProp(value, frame) {
|
|
322
|
-
if (Array.isArray(value)) return
|
|
409
|
+
if (Array.isArray(value)) return serializeTreeArray(value, frame);
|
|
323
410
|
return serializeNodeOrLazy(value, frame);
|
|
324
411
|
}
|
|
412
|
+
function serializeTreeArray(value, frame) {
|
|
413
|
+
if (!value.some(Array.isArray)) return value.map((child) => serializeNodeOrLazy(child, frame));
|
|
414
|
+
const serialized = [];
|
|
415
|
+
appendTreeArray(value, frame, serialized);
|
|
416
|
+
return serialized;
|
|
417
|
+
}
|
|
418
|
+
function appendTreeArray(children, frame, output) {
|
|
419
|
+
for (const child of children) if (Array.isArray(child)) appendTreeArray(child, frame, output);
|
|
420
|
+
else output.push(serializeNodeOrLazy(child, frame));
|
|
421
|
+
}
|
|
325
422
|
function serializeValue(value, frame) {
|
|
326
423
|
if (isPlainPayloadValue(value)) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
327
424
|
if (isClientReference(value)) return {
|
|
@@ -339,52 +436,43 @@ function serializeValue(value, frame) {
|
|
|
339
436
|
if (value instanceof Date) return encodePayloadValueWithGraph(value, frame.request.graph);
|
|
340
437
|
if (value instanceof Map) return serializePayloadMap(value, frame.request.graph, ([key, item]) => [serializeValue(key, frame), serializeValue(item, frame)]);
|
|
341
438
|
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, (
|
|
439
|
+
if (Array.isArray(value)) return serializePayloadArray(value, frame.request.graph, (item) => serializeValue(item, frame));
|
|
343
440
|
return serializePayloadPlainObject(value, frame.request.graph, (child) => serializeValue(child, frame));
|
|
344
441
|
}
|
|
345
442
|
throw new Error(`Cannot serialize ${typeof value} into the payload.`);
|
|
346
443
|
}
|
|
347
444
|
function outlineTask(frame, value, referenceKind, wakeable, scopedAssets = []) {
|
|
348
445
|
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
|
-
};
|
|
446
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
447
|
+
const task = createTask(request, outline.id, value, cloneContextValues(frame.contextValues), frame.imagePreloadsSuppressed, stackForError(wakeable, frame.stack));
|
|
448
|
+
const ping = () => pingTask(request, task);
|
|
449
|
+
wakeable.then(ping, ping);
|
|
450
|
+
return outline;
|
|
361
451
|
}
|
|
362
452
|
function outlineError(frame, error, referenceKind, scopedAssets) {
|
|
363
453
|
const request = frame.request;
|
|
364
|
-
const
|
|
365
|
-
if (scopedAssets.length > 0) emitRow(request, {
|
|
366
|
-
for: id,
|
|
367
|
-
tag: "assets",
|
|
368
|
-
value: scopedAssets
|
|
369
|
-
});
|
|
454
|
+
const outline = createOutline(request, referenceKind, scopedAssets);
|
|
370
455
|
emitRow(request, {
|
|
371
|
-
id,
|
|
456
|
+
id: outline.id,
|
|
372
457
|
tag: "error",
|
|
373
458
|
value: errorRowPayload(request, error, frame.stack)
|
|
374
459
|
});
|
|
375
|
-
return
|
|
376
|
-
|
|
377
|
-
|
|
460
|
+
return outline;
|
|
461
|
+
}
|
|
462
|
+
function createOutline(request, kind, assets) {
|
|
463
|
+
const outline = {
|
|
464
|
+
$fig: kind,
|
|
465
|
+
id: request.nextRowId++
|
|
378
466
|
};
|
|
467
|
+
if (assets.length > 0) emitRow(request, {
|
|
468
|
+
for: outline.id,
|
|
469
|
+
tag: "assets",
|
|
470
|
+
value: assets
|
|
471
|
+
});
|
|
472
|
+
return outline;
|
|
379
473
|
}
|
|
380
474
|
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
|
-
}
|
|
475
|
+
return serverErrorPayload(error, stackForError(error, stack), request.onError);
|
|
388
476
|
}
|
|
389
477
|
function recordErrorStack(error, stack) {
|
|
390
478
|
if (stack === null) return;
|
|
@@ -403,7 +491,7 @@ function clientReferenceExportName(id) {
|
|
|
403
491
|
function emitClientReference(request, reference) {
|
|
404
492
|
const existing = request.clientReferenceRows.get(reference.id);
|
|
405
493
|
if (existing !== void 0) return existing;
|
|
406
|
-
const assets =
|
|
494
|
+
const assets = request.assets.serializeClientReference(reference);
|
|
407
495
|
const value = { id: reference.id };
|
|
408
496
|
if (assets.length > 0) value.assets = assets;
|
|
409
497
|
const exportName = clientReferenceExportName(reference.id);
|
|
@@ -418,113 +506,12 @@ function emitClientReference(request, reference) {
|
|
|
418
506
|
});
|
|
419
507
|
return id;
|
|
420
508
|
}
|
|
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
509
|
function emitRow(request, row) {
|
|
523
510
|
request.queuedRows.push(jsonPayloadCodec.encodeRow(row));
|
|
524
511
|
flushRows(request);
|
|
525
512
|
}
|
|
526
513
|
function pingTask(request, task) {
|
|
527
|
-
if (request.
|
|
514
|
+
if (request.closed) return;
|
|
528
515
|
request.pingedTasks.push(task);
|
|
529
516
|
scheduleWork(request);
|
|
530
517
|
}
|
|
@@ -537,7 +524,7 @@ function scheduleWork(request) {
|
|
|
537
524
|
});
|
|
538
525
|
}
|
|
539
526
|
function flushRows(request) {
|
|
540
|
-
if (request.controller === null || request.
|
|
527
|
+
if (request.controller === null || request.closed) return;
|
|
541
528
|
if (request.flushingRows) return;
|
|
542
529
|
request.flushingRows = true;
|
|
543
530
|
try {
|
|
@@ -552,16 +539,16 @@ function flushRows(request) {
|
|
|
552
539
|
request.flushingRows = false;
|
|
553
540
|
}
|
|
554
541
|
if (request.pendingTasks === 0 && request.queuedRows.length === 0) {
|
|
555
|
-
request.
|
|
556
|
-
request.cleanupAbortListener();
|
|
542
|
+
request.closed = true;
|
|
543
|
+
request.cleanupAbortListener?.();
|
|
557
544
|
request.dataStore.dispose();
|
|
558
545
|
request.controller.close();
|
|
559
546
|
}
|
|
560
547
|
}
|
|
561
548
|
function closeWithError(request, error) {
|
|
562
|
-
if (request.
|
|
563
|
-
request.cleanupAbortListener();
|
|
564
|
-
request.
|
|
549
|
+
if (request.closed) return;
|
|
550
|
+
request.cleanupAbortListener?.();
|
|
551
|
+
request.closed = true;
|
|
565
552
|
request.dataStore.dispose();
|
|
566
553
|
request.allReady.reject(error);
|
|
567
554
|
request.controller?.error(error);
|
|
@@ -569,13 +556,6 @@ function closeWithError(request, error) {
|
|
|
569
556
|
function abortPayloadRequest(request, reason) {
|
|
570
557
|
closeWithError(request, reason ?? new PayloadRequestCancelledError());
|
|
571
558
|
}
|
|
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
559
|
function invalidChildError$1(value) {
|
|
580
560
|
return /* @__PURE__ */ new Error(`Invalid Fig child in payload render: ${describeInvalidChild(value)}.`);
|
|
581
561
|
}
|