@solidjs/web 2.0.0-beta.27 → 2.0.0-beta.29
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/dev.cjs +40 -2
- package/dist/dev.js +39 -4
- package/dist/server.cjs +113 -37
- package/dist/server.js +112 -39
- package/dist/web.cjs +40 -2
- package/dist/web.js +39 -4
- package/frames/dist/client.cjs +370 -209
- package/frames/dist/client.dev.cjs +370 -210
- package/frames/dist/client.dev.js +371 -211
- package/frames/dist/client.js +371 -210
- package/frames/dist/server.cjs +373 -74
- package/frames/dist/server.js +373 -75
- package/package.json +3 -3
- package/server-functions/dist/client.cjs +100 -3
- package/server-functions/dist/client.js +92 -4
- package/server-functions/dist/server.cjs +85 -17
- package/server-functions/dist/server.js +83 -17
- package/types/client.d.ts +15 -0
- package/types/core.d.ts +1 -1
- package/types/frames/client.d.ts +8 -5
- package/types/frames/frame-client.d.ts +17 -0
- package/types/frames/frame-sink.d.ts +29 -6
- package/types/frames/frame-transport.d.ts +76 -12
- package/types/frames/server.d.ts +29 -1
- package/types/index.d.ts +74 -0
- package/types/server-functions/client.d.ts +25 -0
- package/types/server-functions/server.d.ts +105 -18
- package/types/server-functions/shared.d.ts +22 -0
- package/types/server-mock.d.ts +6 -2
- package/types/server.d.ts +39 -1
- package/types-cjs/client.d.cts +15 -0
- package/types-cjs/core.d.cts +1 -1
- package/types-cjs/frames/client.d.cts +8 -5
- package/types-cjs/frames/frame-client.d.cts +17 -0
- package/types-cjs/frames/frame-sink.d.cts +29 -6
- package/types-cjs/frames/frame-transport.d.cts +76 -12
- package/types-cjs/frames/server.d.cts +29 -1
- package/types-cjs/index.d.cts +74 -0
- package/types-cjs/server-functions/client.d.cts +25 -0
- package/types-cjs/server-functions/server.d.cts +105 -18
- package/types-cjs/server-functions/shared.d.cts +22 -0
- package/types-cjs/server-mock.d.cts +6 -2
- package/types-cjs/server.d.cts +39 -1
package/frames/dist/server.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var seroval = require('seroval');
|
|
4
3
|
var solidJs = require('solid-js');
|
|
4
|
+
var seroval = require('seroval');
|
|
5
5
|
var web = require('seroval-plugins/web');
|
|
6
6
|
|
|
7
7
|
const runWithHydrationScope = (id, fn) => solidJs.runWithOwner(solidJs.createOwner({
|
|
@@ -56,6 +56,21 @@ function resolveCodecOptions({
|
|
|
56
56
|
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
+
function serializeJSON(value, {
|
|
60
|
+
onParse,
|
|
61
|
+
onDone,
|
|
62
|
+
onError,
|
|
63
|
+
...codecOptions
|
|
64
|
+
}) {
|
|
65
|
+
const resolved = resolveCodecOptions(codecOptions);
|
|
66
|
+
return seroval.toCrossJSONStream(value, {
|
|
67
|
+
onParse,
|
|
68
|
+
onDone,
|
|
69
|
+
onError,
|
|
70
|
+
...resolved,
|
|
71
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
59
74
|
function createJSONSerializer({
|
|
60
75
|
onData,
|
|
61
76
|
onDone,
|
|
@@ -220,7 +235,24 @@ function createAssetTracking() {
|
|
|
220
235
|
}
|
|
221
236
|
};
|
|
222
237
|
}
|
|
223
|
-
function
|
|
238
|
+
function warnUnresolvedModuleAssets(moduleUrl, warned) {
|
|
239
|
+
if (warned.has(moduleUrl)) return;
|
|
240
|
+
warned.add(moduleUrl);
|
|
241
|
+
console.error(`Asset manifest returned no client assets for module "${moduleUrl}". ` + "If this module is a server-rendered lazy() component, its entry will be missing from " + "the serialized hydration asset map, the client will be unable to preload it, and " + "hydration will fail with 'lazy() module \"…\" was not preloaded before hydration'. " + "This means the integration's asset resolver (dev manifest bridge or build client " + "manifest) failed to answer for this module — check the integration's server logs, " + "restart the dev server, or verify the module is included in the client build.");
|
|
242
|
+
}
|
|
243
|
+
function guardResolvedAssets(moduleUrl, result, warned) {
|
|
244
|
+
if (result && typeof result.then === "function") {
|
|
245
|
+
return result.then(assets => {
|
|
246
|
+
if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
247
|
+
return assets;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
function applyAssetTracking(context, tracking, manifest, noScripts) {
|
|
254
|
+
const warned = new Set();
|
|
255
|
+
const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
|
|
224
256
|
Object.defineProperty(context, "_currentBoundaryId", {
|
|
225
257
|
get() {
|
|
226
258
|
return tracking.currentBoundaryId;
|
|
@@ -234,15 +266,15 @@ function applyAssetTracking(context, tracking, manifest) {
|
|
|
234
266
|
context.registerModule = tracking.registerModule;
|
|
235
267
|
context.getBoundaryModules = tracking.getBoundaryModules;
|
|
236
268
|
if (typeof manifest === "function") {
|
|
237
|
-
context.resolveAssets = manifest;
|
|
269
|
+
context.resolveAssets = guard(manifest);
|
|
238
270
|
} else if (manifest && typeof manifest.resolve === "function") {
|
|
239
|
-
context.resolveAssets = key => manifest.resolve(key);
|
|
271
|
+
context.resolveAssets = guard(key => manifest.resolve(key));
|
|
240
272
|
if (typeof manifest.resolveSync === "function") {
|
|
241
273
|
context.resolveAssetsSync = key => manifest.resolveSync(key);
|
|
242
274
|
}
|
|
243
275
|
} else if (manifest) {
|
|
244
276
|
const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
|
|
245
|
-
context.resolveAssets = resolve;
|
|
277
|
+
context.resolveAssets = guard(resolve);
|
|
246
278
|
context.resolveAssetsSync = resolve;
|
|
247
279
|
}
|
|
248
280
|
}
|
|
@@ -521,7 +553,7 @@ function renderToStream(code, options = {}) {
|
|
|
521
553
|
});
|
|
522
554
|
}
|
|
523
555
|
};
|
|
524
|
-
applyAssetTracking(context, tracking, manifest);
|
|
556
|
+
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
525
557
|
registerEntryAssets(manifest);
|
|
526
558
|
let html = solidJs.createRoot(d => {
|
|
527
559
|
dispose = d;
|
|
@@ -618,6 +650,51 @@ function renderToStream(code, options = {}) {
|
|
|
618
650
|
drainTurn = 0;
|
|
619
651
|
progressed ? queue(attempt) : setTimeout(attempt);
|
|
620
652
|
};
|
|
653
|
+
let cachedReadable;
|
|
654
|
+
let consumer;
|
|
655
|
+
const claimConsumer = name => {
|
|
656
|
+
if (consumer && consumer !== name) {
|
|
657
|
+
throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
|
|
658
|
+
}
|
|
659
|
+
consumer = name;
|
|
660
|
+
};
|
|
661
|
+
const pipeToImpl = w => {
|
|
662
|
+
let resolve;
|
|
663
|
+
const p = new Promise(r => resolve = r);
|
|
664
|
+
function flush() {
|
|
665
|
+
allSettled(blockingPromises).then(() => {
|
|
666
|
+
scheduleFlush(() => {
|
|
667
|
+
doShell();
|
|
668
|
+
if (!shellCompleted) return flush();
|
|
669
|
+
const encoder = new TextEncoder();
|
|
670
|
+
const writer = w.getWriter();
|
|
671
|
+
let pendingWrites = Promise.resolve();
|
|
672
|
+
writable = {
|
|
673
|
+
end() {
|
|
674
|
+
pendingWrites.then(() => {
|
|
675
|
+
writer.releaseLock();
|
|
676
|
+
w.close().catch(() => {});
|
|
677
|
+
resolve();
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
buffer = {
|
|
682
|
+
write(payload) {
|
|
683
|
+
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(() => {});
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
buffer.write(tmp);
|
|
687
|
+
firstFlushed = true;
|
|
688
|
+
if (completed) {
|
|
689
|
+
dispose();
|
|
690
|
+
writable.end();
|
|
691
|
+
} else flushEnd();
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
flush();
|
|
696
|
+
return p;
|
|
697
|
+
};
|
|
621
698
|
return {
|
|
622
699
|
then(fn) {
|
|
623
700
|
function complete() {
|
|
@@ -642,6 +719,7 @@ function renderToStream(code, options = {}) {
|
|
|
642
719
|
flush();
|
|
643
720
|
},
|
|
644
721
|
pipe(w) {
|
|
722
|
+
claimConsumer("pipe");
|
|
645
723
|
function flush() {
|
|
646
724
|
allSettled(blockingPromises).then(() => {
|
|
647
725
|
scheduleFlush(() => {
|
|
@@ -660,38 +738,17 @@ function renderToStream(code, options = {}) {
|
|
|
660
738
|
flush();
|
|
661
739
|
},
|
|
662
740
|
pipeTo(w) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
writable = {
|
|
673
|
-
end() {
|
|
674
|
-
writer.releaseLock();
|
|
675
|
-
w.close().catch(() => {});
|
|
676
|
-
resolve();
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
buffer = {
|
|
680
|
-
write(payload) {
|
|
681
|
-
writer.write(encoder.encode(payload)).catch(() => {});
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
buffer.write(tmp);
|
|
685
|
-
firstFlushed = true;
|
|
686
|
-
if (completed) {
|
|
687
|
-
dispose();
|
|
688
|
-
writable.end();
|
|
689
|
-
} else flushEnd();
|
|
690
|
-
});
|
|
691
|
-
});
|
|
741
|
+
claimConsumer("pipeTo");
|
|
742
|
+
return pipeToImpl(w);
|
|
743
|
+
},
|
|
744
|
+
get readable() {
|
|
745
|
+
claimConsumer("readable");
|
|
746
|
+
if (!cachedReadable) {
|
|
747
|
+
const t = new TransformStream();
|
|
748
|
+
pipeToImpl(t.writable);
|
|
749
|
+
cachedReadable = t.readable;
|
|
692
750
|
}
|
|
693
|
-
|
|
694
|
-
return p;
|
|
751
|
+
return cachedReadable;
|
|
695
752
|
}
|
|
696
753
|
};
|
|
697
754
|
}
|
|
@@ -1136,6 +1193,51 @@ function resolveSSRSync(node) {
|
|
|
1136
1193
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
1137
1194
|
}
|
|
1138
1195
|
|
|
1196
|
+
function frameAddress(id, args) {
|
|
1197
|
+
return args && args.length ? id + ":" + hashArguments(args) : id;
|
|
1198
|
+
}
|
|
1199
|
+
function hashArguments(args) {
|
|
1200
|
+
let hash = 0;
|
|
1201
|
+
const text = stableString(args);
|
|
1202
|
+
for (let i = 0; i < text.length; i++) {
|
|
1203
|
+
hash = (hash << 5) - hash + text.charCodeAt(i);
|
|
1204
|
+
hash |= 0;
|
|
1205
|
+
}
|
|
1206
|
+
return (hash >>> 0).toString(36);
|
|
1207
|
+
}
|
|
1208
|
+
function stableString(value, seen) {
|
|
1209
|
+
if (value === null || typeof value !== "object") {
|
|
1210
|
+
return typeof value === "bigint" ? value + "n" : String(value);
|
|
1211
|
+
}
|
|
1212
|
+
if (value instanceof Date) return "Date:" + value.getTime();
|
|
1213
|
+
seen || (seen = new Set());
|
|
1214
|
+
if (seen.has(value)) return "~";
|
|
1215
|
+
seen.add(value);
|
|
1216
|
+
if (value instanceof Map) {
|
|
1217
|
+
const entries = [];
|
|
1218
|
+
for (const [k, v] of value) {
|
|
1219
|
+
entries.push(stableString(k, seen) + "=>" + stableString(v, seen));
|
|
1220
|
+
}
|
|
1221
|
+
return "Map{" + entries.sort().join(",") + "}";
|
|
1222
|
+
}
|
|
1223
|
+
if (value instanceof Set) {
|
|
1224
|
+
const members = [];
|
|
1225
|
+
for (const v of value) members.push(stableString(v, seen));
|
|
1226
|
+
return "Set{" + members.sort().join(",") + "}";
|
|
1227
|
+
}
|
|
1228
|
+
if (Array.isArray(value)) {
|
|
1229
|
+
let out = "[";
|
|
1230
|
+
for (let i = 0; i < value.length; i++) out += (i ? "," : "") + stableString(value[i], seen);
|
|
1231
|
+
return out + "]";
|
|
1232
|
+
}
|
|
1233
|
+
const keys = Object.keys(value).sort();
|
|
1234
|
+
let out = "{";
|
|
1235
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1236
|
+
out += (i ? "," : "") + keys[i] + ":" + stableString(value[keys[i]], seen);
|
|
1237
|
+
}
|
|
1238
|
+
return out + "}";
|
|
1239
|
+
}
|
|
1240
|
+
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
1139
1241
|
function createChunk(data) {
|
|
1140
1242
|
const encodeData = new TextEncoder().encode(data);
|
|
1141
1243
|
const bytes = encodeData.length;
|
|
@@ -1147,16 +1249,138 @@ function createChunk(data) {
|
|
|
1147
1249
|
chunk.set(encodeData, 12);
|
|
1148
1250
|
return chunk;
|
|
1149
1251
|
}
|
|
1252
|
+
class ChunkReader {
|
|
1253
|
+
constructor(stream) {
|
|
1254
|
+
this.reader = stream.getReader();
|
|
1255
|
+
this.buffer = new Uint8Array(0);
|
|
1256
|
+
this.done = false;
|
|
1257
|
+
}
|
|
1258
|
+
async readChunk() {
|
|
1259
|
+
const chunk = await this.reader.read();
|
|
1260
|
+
if (!chunk.done) {
|
|
1261
|
+
const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
|
|
1262
|
+
newBuffer.set(this.buffer);
|
|
1263
|
+
newBuffer.set(chunk.value, this.buffer.length);
|
|
1264
|
+
this.buffer = newBuffer;
|
|
1265
|
+
} else {
|
|
1266
|
+
this.done = true;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
async next() {
|
|
1270
|
+
while (this.buffer.length < 12) {
|
|
1271
|
+
if (this.done) {
|
|
1272
|
+
if (this.buffer.length === 0) return {
|
|
1273
|
+
done: true,
|
|
1274
|
+
value: undefined
|
|
1275
|
+
};
|
|
1276
|
+
throw new Error("Malformed server function stream.");
|
|
1277
|
+
}
|
|
1278
|
+
await this.readChunk();
|
|
1279
|
+
}
|
|
1280
|
+
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
1281
|
+
const bytes = Number.parseInt(head, 16);
|
|
1282
|
+
if (Number.isNaN(bytes)) {
|
|
1283
|
+
throw new Error("Malformed server function stream.");
|
|
1284
|
+
}
|
|
1285
|
+
while (bytes > this.buffer.length - 12) {
|
|
1286
|
+
if (this.done) {
|
|
1287
|
+
throw new Error("Malformed server function stream.");
|
|
1288
|
+
}
|
|
1289
|
+
await this.readChunk();
|
|
1290
|
+
}
|
|
1291
|
+
const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
|
|
1292
|
+
this.buffer = this.buffer.subarray(12 + bytes);
|
|
1293
|
+
return {
|
|
1294
|
+
done: false,
|
|
1295
|
+
value: partial
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
async drain(interpret) {
|
|
1299
|
+
while (true) {
|
|
1300
|
+
const result = await this.next();
|
|
1301
|
+
if (result.done) {
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
interpret(result.value);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
function serializeStream(value, codecOptions) {
|
|
1309
|
+
return new ReadableStream({
|
|
1310
|
+
start(controller) {
|
|
1311
|
+
serializeJSON(value, {
|
|
1312
|
+
...codecOptions,
|
|
1313
|
+
onParse(node) {
|
|
1314
|
+
controller.enqueue(createChunk(JSON.stringify(node)));
|
|
1315
|
+
},
|
|
1316
|
+
onDone() {
|
|
1317
|
+
controller.close();
|
|
1318
|
+
},
|
|
1319
|
+
onError(error) {
|
|
1320
|
+
controller.error(error);
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1150
1326
|
|
|
1151
1327
|
const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
|
|
1152
1328
|
function isResponseEnvelope(value) {
|
|
1153
1329
|
return !!(value && typeof value === "object" && value[ENVELOPE]);
|
|
1154
1330
|
}
|
|
1155
1331
|
|
|
1332
|
+
const INVOCATIONS = new WeakMap();
|
|
1333
|
+
function getEventServerFunctionInvocation(event) {
|
|
1334
|
+
return event && INVOCATIONS.get(event);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1156
1337
|
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
1157
1338
|
function isFrameStreamResponse(response) {
|
|
1158
1339
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
1159
1340
|
}
|
|
1341
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("dom-expressions.server-component");
|
|
1342
|
+
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("dom-expressions.server-component-source");
|
|
1343
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("dom-expressions.server-component-address");
|
|
1344
|
+
function parseServerComponent(value, ctx) {
|
|
1345
|
+
return {
|
|
1346
|
+
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
1347
|
+
address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
const ServerComponentPlugin = /*#__PURE__*/seroval.createPlugin({
|
|
1351
|
+
tag: "dom-expressions/server-component",
|
|
1352
|
+
test(value) {
|
|
1353
|
+
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
1354
|
+
},
|
|
1355
|
+
parse: {
|
|
1356
|
+
sync: parseServerComponent,
|
|
1357
|
+
async async(value, ctx) {
|
|
1358
|
+
return {
|
|
1359
|
+
id: await ctx.parse(value[SERVER_COMPONENT]),
|
|
1360
|
+
address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
1361
|
+
};
|
|
1362
|
+
},
|
|
1363
|
+
stream: parseServerComponent
|
|
1364
|
+
},
|
|
1365
|
+
serialize(node, ctx) {
|
|
1366
|
+
return "self._$SC.r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
|
|
1367
|
+
},
|
|
1368
|
+
deserialize(node, ctx) {
|
|
1369
|
+
const id = ctx.deserialize(node.id);
|
|
1370
|
+
ctx.deserialize(node.address);
|
|
1371
|
+
return globalThis._$SC.r(id);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
function flightCodec(codec) {
|
|
1375
|
+
const plugins = codec && codec.plugins || [];
|
|
1376
|
+
for (const plugin of plugins) {
|
|
1377
|
+
if (plugin && plugin.tag === "dom-expressions/server-component") return codec;
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
...codec,
|
|
1381
|
+
plugins: [...plugins, ServerComponentPlugin]
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1160
1384
|
|
|
1161
1385
|
function serverOwned(render) {
|
|
1162
1386
|
return solidJs.NoHydration ? solidJs.NoHydration({
|
|
@@ -1165,6 +1389,9 @@ function serverOwned(render) {
|
|
|
1165
1389
|
}
|
|
1166
1390
|
}) : render();
|
|
1167
1391
|
}
|
|
1392
|
+
function serverComponentScope(render) {
|
|
1393
|
+
return solidJs.runInServerComponentScope ? solidJs.runInServerComponentScope(render) : render();
|
|
1394
|
+
}
|
|
1168
1395
|
function createFrameSink(emit, frame) {
|
|
1169
1396
|
const {
|
|
1170
1397
|
id,
|
|
@@ -1346,7 +1573,7 @@ function renderToFrameStream(code, options = {}) {
|
|
|
1346
1573
|
function renderServerComponent(component, options = {}) {
|
|
1347
1574
|
return frameStream((sink, frame) => {
|
|
1348
1575
|
const props = createSlotProps(sink, frame);
|
|
1349
|
-
return () => component(props);
|
|
1576
|
+
return () => serverComponentScope(() => component(props));
|
|
1350
1577
|
}, options);
|
|
1351
1578
|
}
|
|
1352
1579
|
function frameStream(makeCode, options) {
|
|
@@ -1539,16 +1766,23 @@ function frameElementOpen(id) {
|
|
|
1539
1766
|
}
|
|
1540
1767
|
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
1541
1768
|
function frameTransformDirectResult(value, {
|
|
1542
|
-
id
|
|
1769
|
+
id,
|
|
1770
|
+
args
|
|
1543
1771
|
}) {
|
|
1544
1772
|
if (typeof value !== "function") return value;
|
|
1545
1773
|
const component = value;
|
|
1546
1774
|
const wrapped = props => [{
|
|
1547
1775
|
t: frameElementOpen(id)
|
|
1548
|
-
},
|
|
1776
|
+
},
|
|
1777
|
+
serverOwned(() => {
|
|
1778
|
+
const slotProps = createDocumentSlotProps(props, id);
|
|
1779
|
+
return serverComponentScope(() => component(slotProps));
|
|
1780
|
+
}), {
|
|
1549
1781
|
t: FRAME_ELEMENT_CLOSE
|
|
1550
1782
|
}];
|
|
1551
1783
|
wrapped[SERVER_COMPONENT] = id;
|
|
1784
|
+
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1785
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = frameAddress(id, args);
|
|
1552
1786
|
return wrapped;
|
|
1553
1787
|
}
|
|
1554
1788
|
function resolveRegionHtml(ctx, node) {
|
|
@@ -1565,37 +1799,7 @@ function resolveRegionHtml(ctx, node) {
|
|
|
1565
1799
|
return out;
|
|
1566
1800
|
});
|
|
1567
1801
|
}
|
|
1568
|
-
const
|
|
1569
|
-
const ServerComponentPlugin = /*#__PURE__*/seroval.createPlugin({
|
|
1570
|
-
tag: "dom-expressions/server-component",
|
|
1571
|
-
test(value) {
|
|
1572
|
-
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
1573
|
-
},
|
|
1574
|
-
parse: {
|
|
1575
|
-
sync(value, ctx) {
|
|
1576
|
-
return {
|
|
1577
|
-
id: ctx.parse(value[SERVER_COMPONENT])
|
|
1578
|
-
};
|
|
1579
|
-
},
|
|
1580
|
-
async async(value, ctx) {
|
|
1581
|
-
return {
|
|
1582
|
-
id: await ctx.parse(value[SERVER_COMPONENT])
|
|
1583
|
-
};
|
|
1584
|
-
},
|
|
1585
|
-
stream(value, ctx) {
|
|
1586
|
-
return {
|
|
1587
|
-
id: ctx.parse(value[SERVER_COMPONENT])
|
|
1588
|
-
};
|
|
1589
|
-
}
|
|
1590
|
-
},
|
|
1591
|
-
serialize(node, ctx) {
|
|
1592
|
-
return "self._$SC.r(" + ctx.serialize(node.id) + ")";
|
|
1593
|
-
},
|
|
1594
|
-
deserialize(node, ctx) {
|
|
1595
|
-
return globalThis._$SC.r(ctx.deserialize(node.id));
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
const SERVER_COMPONENT_BOOTSTRAP = "self._$SC={c:{},r(i){return this.c[i]||(this.c[i]=(p)=>self._$SC.impl(i,p))}};";
|
|
1802
|
+
const SERVER_COMPONENT_BOOTSTRAP = "self._$SC={c:{},a:{},r(i,a){a&&(this.a[a]=i,this.reg&&this.reg(a,i));return this.c[i]||(this.c[i]=(p)=>self._$SC.impl(i,p))}};";
|
|
1599
1803
|
function isServerContent(value) {
|
|
1600
1804
|
if (value && typeof value === "object") {
|
|
1601
1805
|
if ("t" in value) return true;
|
|
@@ -1704,7 +1908,7 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1704
1908
|
headers
|
|
1705
1909
|
});
|
|
1706
1910
|
}
|
|
1707
|
-
function frameTransformResult(event, result) {
|
|
1911
|
+
function frameTransformResult(event, result, context) {
|
|
1708
1912
|
let init;
|
|
1709
1913
|
if (isResponseEnvelope(result)) {
|
|
1710
1914
|
const {
|
|
@@ -1719,19 +1923,114 @@ function frameTransformResult(event, result) {
|
|
|
1719
1923
|
result = value;
|
|
1720
1924
|
}
|
|
1721
1925
|
if (typeof result !== "function") return result;
|
|
1722
|
-
|
|
1926
|
+
if (context && context.collectsFlight) return init ? {
|
|
1927
|
+
response: init,
|
|
1928
|
+
value: result
|
|
1929
|
+
} : result;
|
|
1930
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
1723
1931
|
return serverComponentResponse(result, {
|
|
1724
1932
|
frame: {
|
|
1725
|
-
id:
|
|
1933
|
+
id: invocation && invocation.id || ""
|
|
1726
1934
|
}
|
|
1727
1935
|
}, init);
|
|
1728
1936
|
}
|
|
1937
|
+
async function frameTransformFlightResult(event, outcome, context) {
|
|
1938
|
+
const {
|
|
1939
|
+
value,
|
|
1940
|
+
data
|
|
1941
|
+
} = outcome;
|
|
1942
|
+
const regions = [];
|
|
1943
|
+
let serialized = data;
|
|
1944
|
+
if (data && typeof data === "object") {
|
|
1945
|
+
serialized = {};
|
|
1946
|
+
const keys = Object.keys(data);
|
|
1947
|
+
const values = await Promise.all(keys.map(key => data[key]));
|
|
1948
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1949
|
+
const entry = values[i];
|
|
1950
|
+
serialized[keys[i]] = entry;
|
|
1951
|
+
if (typeof entry === "function") {
|
|
1952
|
+
regions.push({
|
|
1953
|
+
id: entry[SERVER_COMPONENT_ADDRESS] || keys[i],
|
|
1954
|
+
component: entry[SERVER_COMPONENT_SOURCE] || entry
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
1960
|
+
const primary = typeof value === "function" ? {
|
|
1961
|
+
id: invocation && invocation.id || "",
|
|
1962
|
+
component: value
|
|
1963
|
+
} : undefined;
|
|
1964
|
+
if (!primary && !regions.length) return undefined;
|
|
1965
|
+
return frameFlightResponse({
|
|
1966
|
+
primary,
|
|
1967
|
+
regions,
|
|
1968
|
+
outcome: {
|
|
1969
|
+
value: primary ? undefined : value,
|
|
1970
|
+
data: serialized
|
|
1971
|
+
},
|
|
1972
|
+
codec: context && context.codec
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
function frameFlightResponse({
|
|
1976
|
+
primary,
|
|
1977
|
+
regions = [],
|
|
1978
|
+
outcome,
|
|
1979
|
+
codec
|
|
1980
|
+
}, init = {}) {
|
|
1981
|
+
const frames = primary ? [primary, ...regions] : regions;
|
|
1982
|
+
const headers = new Headers(init.headers);
|
|
1983
|
+
headers.set("Content-Type", "application/x-frame-stream");
|
|
1984
|
+
headers.set(FRAME_STREAM_HEADER, primary ? primary.id : "");
|
|
1985
|
+
headers.set("X-Content-Raw", "1");
|
|
1986
|
+
headers.set(SINGLE_FLIGHT_HEADER, "true");
|
|
1987
|
+
const body = new ReadableStream({
|
|
1988
|
+
async start(controller) {
|
|
1989
|
+
const write = chunk => controller.enqueue(createChunk(JSON.stringify(chunk)));
|
|
1990
|
+
try {
|
|
1991
|
+
for (const {
|
|
1992
|
+
id,
|
|
1993
|
+
component
|
|
1994
|
+
} of frames) {
|
|
1995
|
+
await new Promise(resolve => {
|
|
1996
|
+
renderServerComponent(component, {
|
|
1997
|
+
frame: {
|
|
1998
|
+
id,
|
|
1999
|
+
version: 1
|
|
2000
|
+
}
|
|
2001
|
+
}).pipe({
|
|
2002
|
+
write,
|
|
2003
|
+
end: resolve
|
|
2004
|
+
});
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
if (outcome) {
|
|
2008
|
+
const reader = new ChunkReader(serializeStream(outcome, flightCodec(codec)));
|
|
2009
|
+
for (let node = await reader.next(); !node.done; node = await reader.next()) {
|
|
2010
|
+
write({
|
|
2011
|
+
type: "outcome",
|
|
2012
|
+
payload: node.value
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
controller.close();
|
|
2017
|
+
} catch (err) {
|
|
2018
|
+
controller.error(err);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
return new Response(body, {
|
|
2023
|
+
status: init.status || 200,
|
|
2024
|
+
headers
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
1729
2027
|
|
|
1730
2028
|
exports.FRAME_STREAM_HEADER = FRAME_STREAM_HEADER;
|
|
1731
2029
|
exports.SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP;
|
|
1732
2030
|
exports.ServerComponentPlugin = ServerComponentPlugin;
|
|
1733
2031
|
exports.createFrameSink = createFrameSink;
|
|
1734
2032
|
exports.frameTransformDirectResult = frameTransformDirectResult;
|
|
2033
|
+
exports.frameTransformFlightResult = frameTransformFlightResult;
|
|
1735
2034
|
exports.frameTransformResult = frameTransformResult;
|
|
1736
2035
|
exports.isFrameStreamResponse = isFrameStreamResponse;
|
|
1737
2036
|
exports.renderServerComponent = renderServerComponent;
|