@solidjs/web 2.0.0-rc.16 → 2.0.0-rc.18
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/server.dev.js +195 -35
- package/dist/server.js +190 -35
- package/dist/server.observe.js +190 -35
- package/dist/web.dev.js +53 -1
- package/dist/web.js +4 -1
- package/dist/web.observe.js +4 -1
- package/frames/dist/server.dev.js +356 -43
- package/frames/dist/server.js +355 -43
- package/frames/dist/server.observe.js +355 -43
- package/frames/dist/wire.js +110 -14
- package/package.json +4 -4
- package/serialization/dist/decode.js +10 -5
- package/serialization/dist/serialization.js +121 -61
- package/serialization/types/index.d.ts +12 -4
- package/serialization/types/serializer.d.ts +12 -4
- package/server-functions/dist/client.dev.js +10 -21
- package/server-functions/dist/client.js +10 -21
- package/server-functions/dist/client.observe.js +10 -21
- package/server-functions/dist/rich-args.js +54 -3
- package/server-functions/dist/server.dev.js +313 -11
- package/server-functions/dist/server.js +313 -11
- package/server-functions/dist/server.observe.js +313 -11
- package/types/client.d.ts +12 -0
- package/types/diagnostics.d.ts +16 -0
- package/types/frames/frame-morph.d.ts +1 -0
- package/types/frames/serializer.d.ts +12 -4
- package/types/serializer.d.ts +12 -4
- package/types/server-functions/argument-codec.d.ts +11 -2
- package/types/server-functions/client.d.ts +13 -4
- package/types/server-functions/server.d.ts +33 -0
- package/types/server-functions/shared.d.ts +9 -0
- package/types/server-functions/uploads.d.ts +50 -0
- package/types/server.d.ts +1 -1
|
@@ -550,6 +550,7 @@ function decodeErrorHeaderValue(value) {
|
|
|
550
550
|
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
551
551
|
const LAST_EVENT_ID_HEADER = "Last-Event-ID";
|
|
552
552
|
const UNKNOWN_HEADER = "X-Server-Function-Unknown";
|
|
553
|
+
const BUILD_HEADER = "X-Server-Function-Build";
|
|
553
554
|
const REDIRECT_HEADER = "X-Server-Function-Redirect";
|
|
554
555
|
function decodeRedirectHeaderValue(value) {
|
|
555
556
|
if (typeof value !== "string") return undefined;
|
|
@@ -1295,6 +1296,45 @@ function namesRefusedType(payload) {
|
|
|
1295
1296
|
for (const tag of REFUSED_TAGS) if (payload.includes(`"c":"${tag}"`)) return true;
|
|
1296
1297
|
return false;
|
|
1297
1298
|
}
|
|
1299
|
+
function withArgumentPlugins(argumentCodec, extra) {
|
|
1300
|
+
return {
|
|
1301
|
+
...argumentCodec,
|
|
1302
|
+
[RESOLVED_PLUGINS]: [...extra, ...argumentCodec[RESOLVED_PLUGINS]]
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
const UPLOAD_ARGS_PART = "args";
|
|
1307
|
+
const UPLOAD_FILE_PART = "file";
|
|
1308
|
+
const UPLOAD_TAG = "solid/server-function-upload";
|
|
1309
|
+
function isBlob(value) {
|
|
1310
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) return true;
|
|
1311
|
+
return typeof value === "object" && value !== null && typeof value.size === "number" && typeof value.type === "string" && typeof value.arrayBuffer === "function" && typeof value.slice === "function";
|
|
1312
|
+
}
|
|
1313
|
+
function malformed() {
|
|
1314
|
+
return new TypeError("Malformed server function upload");
|
|
1315
|
+
}
|
|
1316
|
+
function createUploadDeserializer(form) {
|
|
1317
|
+
const refuse = () => {
|
|
1318
|
+
throw malformed();
|
|
1319
|
+
};
|
|
1320
|
+
return {
|
|
1321
|
+
tag: UPLOAD_TAG,
|
|
1322
|
+
test: () => false,
|
|
1323
|
+
parse: {
|
|
1324
|
+
sync: refuse,
|
|
1325
|
+
async: refuse,
|
|
1326
|
+
stream: refuse
|
|
1327
|
+
},
|
|
1328
|
+
serialize: refuse,
|
|
1329
|
+
deserialize: (node, ctx) => {
|
|
1330
|
+
const index = ctx.deserialize(node.i);
|
|
1331
|
+
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) refuse();
|
|
1332
|
+
const part = form.get(UPLOAD_FILE_PART + index);
|
|
1333
|
+
if (!isBlob(part)) refuse();
|
|
1334
|
+
return part;
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1298
1338
|
|
|
1299
1339
|
const config = {
|
|
1300
1340
|
provideEvent: undefined,
|
|
@@ -1308,7 +1348,8 @@ const config = {
|
|
|
1308
1348
|
csrf: true,
|
|
1309
1349
|
bodySizeLimit: 1_048_576,
|
|
1310
1350
|
maxArguments: 1000,
|
|
1311
|
-
chaosReconnectEvery: 0
|
|
1351
|
+
chaosReconnectEvery: 0,
|
|
1352
|
+
buildId: undefined
|
|
1312
1353
|
};
|
|
1313
1354
|
function configureServerFunctionsServer({
|
|
1314
1355
|
provideEvent,
|
|
@@ -1324,7 +1365,8 @@ function configureServerFunctionsServer({
|
|
|
1324
1365
|
bodySizeLimit,
|
|
1325
1366
|
maxArguments,
|
|
1326
1367
|
secret,
|
|
1327
|
-
chaosReconnectEvery
|
|
1368
|
+
chaosReconnectEvery,
|
|
1369
|
+
buildId
|
|
1328
1370
|
} = {}) {
|
|
1329
1371
|
if (provideEvent !== undefined) config.provideEvent = provideEvent;
|
|
1330
1372
|
if (wrapInvocation !== undefined) config.wrapInvocation = wrapInvocation;
|
|
@@ -1340,6 +1382,7 @@ function configureServerFunctionsServer({
|
|
|
1340
1382
|
if (maxArguments !== undefined) config.maxArguments = maxArguments;
|
|
1341
1383
|
if (secret !== undefined) setFlashSecret(secret);
|
|
1342
1384
|
if (chaosReconnectEvery !== undefined) config.chaosReconnectEvery = chaosReconnectEvery;
|
|
1385
|
+
if (buildId !== undefined) config.buildId = buildId;
|
|
1343
1386
|
}
|
|
1344
1387
|
const flightSources = new Map();
|
|
1345
1388
|
function registerFlightDataSource(source, hook) {
|
|
@@ -1737,6 +1780,7 @@ function live(fn) {
|
|
|
1737
1780
|
if (!isServerFunction(fn) || typeof fn.id !== "string") {
|
|
1738
1781
|
throw new Error("live expects a server function reference");
|
|
1739
1782
|
}
|
|
1783
|
+
if (getServerFunctionMetadata(fn)?.method !== "GET") fn = GET(fn);
|
|
1740
1784
|
const metadata = {
|
|
1741
1785
|
...getServerFunctionMetadata(fn),
|
|
1742
1786
|
live: true
|
|
@@ -1751,6 +1795,18 @@ function live(fn) {
|
|
|
1751
1795
|
});
|
|
1752
1796
|
return wrapped;
|
|
1753
1797
|
}
|
|
1798
|
+
function broadcast(fn) {
|
|
1799
|
+
const ref = live(fn);
|
|
1800
|
+
ref[SERVER_FUNCTION_METADATA].broadcast = true;
|
|
1801
|
+
BROADCASTS.add(fn.id);
|
|
1802
|
+
return ref;
|
|
1803
|
+
}
|
|
1804
|
+
function encodedArguments(request, argsEncoding, argumentBytes) {
|
|
1805
|
+
if (request.method !== "POST") return argsEncoding || "";
|
|
1806
|
+
if (!argumentBytes) return undefined;
|
|
1807
|
+
return (request.headers.get("content-type") || "") + "\0" + (argsEncoding || "") + "\0" + new TextDecoder("latin1").decode(argumentBytes);
|
|
1808
|
+
}
|
|
1809
|
+
const BROADCASTS = new Set();
|
|
1754
1810
|
function brandLive(answer) {
|
|
1755
1811
|
if (typeof answer === "function" || answer !== null && typeof answer === "object" && answer[Symbol.asyncIterator]) {
|
|
1756
1812
|
answer[LIVE_SOURCE] = true;
|
|
@@ -1927,7 +1983,17 @@ async function parseArguments(request, url, scripted, codec, buffered) {
|
|
|
1927
1983
|
if (bodyFormat === BodyFormat.Serialized) {
|
|
1928
1984
|
let argumentCodec = argumentCodecFor(codec);
|
|
1929
1985
|
if (argumentCodec instanceof Promise) argumentCodec = await argumentCodec;
|
|
1930
|
-
|
|
1986
|
+
if ((request.headers.get("content-type") || "").startsWith("multipart/form-data")) {
|
|
1987
|
+
const form = await body.formData();
|
|
1988
|
+
const encoded = form.get(UPLOAD_ARGS_PART);
|
|
1989
|
+
if (typeof encoded !== "string") {
|
|
1990
|
+
throw new TypeError("Malformed server function upload");
|
|
1991
|
+
}
|
|
1992
|
+
const uploadCodec = withArgumentPlugins(argumentCodec, [createUploadDeserializer(form)]);
|
|
1993
|
+
decoded = await decodeArguments(wire => deserializeStream(new Response(encoded), uploadCodec, wire), encoded);
|
|
1994
|
+
} else {
|
|
1995
|
+
decoded = await decodeArguments(wire => extractBody(body, argumentCodec, wire), buffered);
|
|
1996
|
+
}
|
|
1931
1997
|
} else {
|
|
1932
1998
|
decoded = await extractBody(body, codec);
|
|
1933
1999
|
}
|
|
@@ -2441,7 +2507,7 @@ function serializeResponseStream(value, codecOptions, signal, scope, live) {
|
|
|
2441
2507
|
return new ReadableStream({
|
|
2442
2508
|
async start(controller) {
|
|
2443
2509
|
streamController = controller;
|
|
2444
|
-
if (live) stopLive = armLiveBody(controller, teardown);
|
|
2510
|
+
if (live && !live.nodes) stopLive = armLiveBody(controller, teardown);
|
|
2445
2511
|
if (signal) {
|
|
2446
2512
|
if (signal.aborted) {
|
|
2447
2513
|
teardown();
|
|
@@ -2471,7 +2537,10 @@ function serializeResponseStream(value, codecOptions, signal, scope, live) {
|
|
|
2471
2537
|
cancelSerialize = serializeJSON(value, {
|
|
2472
2538
|
...codecOptions,
|
|
2473
2539
|
onParse(node) {
|
|
2474
|
-
if (
|
|
2540
|
+
if (closed) return;
|
|
2541
|
+
const chunk = frame(JSON.stringify(node));
|
|
2542
|
+
if (live && live.nodes) live.nodes.set(chunk, node);
|
|
2543
|
+
controller.enqueue(chunk);
|
|
2475
2544
|
},
|
|
2476
2545
|
onDone() {
|
|
2477
2546
|
if (closed) return;
|
|
@@ -2542,7 +2611,7 @@ function armLiveBody(controller, teardown) {
|
|
|
2542
2611
|
if (chaos !== null) clearTimeout(chaos);
|
|
2543
2612
|
};
|
|
2544
2613
|
}
|
|
2545
|
-
function liveSource(value, lastEventId, position, scope) {
|
|
2614
|
+
function liveSource(value, lastEventId, position, scope, refs) {
|
|
2546
2615
|
const digestOf = v => scope ? scope(() => positionDigest(v)) : positionDigest(v);
|
|
2547
2616
|
if (value === null || typeof value !== "object" || typeof value[Symbol.asyncIterator] !== "function") {
|
|
2548
2617
|
const digest = digestOf(value);
|
|
@@ -2557,7 +2626,12 @@ function liveSource(value, lastEventId, position, scope) {
|
|
|
2557
2626
|
let first = true;
|
|
2558
2627
|
const step = () => iterator.next().then(result => {
|
|
2559
2628
|
if (result.done) return result;
|
|
2629
|
+
if (refs) refs.turn();
|
|
2560
2630
|
const digest = digestOf(result.value);
|
|
2631
|
+
if (refs) position.yields.push({
|
|
2632
|
+
value: result.value,
|
|
2633
|
+
digest
|
|
2634
|
+
});
|
|
2561
2635
|
if (first) {
|
|
2562
2636
|
first = false;
|
|
2563
2637
|
if (digest !== undefined && digest === lastEventId) return step();
|
|
@@ -2576,10 +2650,14 @@ function liveSource(value, lastEventId, position, scope) {
|
|
|
2576
2650
|
}
|
|
2577
2651
|
};
|
|
2578
2652
|
}
|
|
2579
|
-
function encodeLiveResult(value, headers, status, codec, request, scope) {
|
|
2653
|
+
function encodeLiveResult(value, headers, status, codec, request, scope, shareKey) {
|
|
2580
2654
|
if (NULL_BODY_STATUSES.has(status) || value === undefined || getHeadersAndBody(value)) {
|
|
2581
2655
|
return encodeResult(value, headers, status, codec, request.signal, scope);
|
|
2582
2656
|
}
|
|
2657
|
+
if (shareKey !== undefined && value !== null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function") {
|
|
2658
|
+
const shared = sharedSourceResponse(shareKey, value, headers, status, codec, request);
|
|
2659
|
+
if (shared) return shared;
|
|
2660
|
+
}
|
|
2583
2661
|
const position = {
|
|
2584
2662
|
pending: undefined
|
|
2585
2663
|
};
|
|
@@ -2597,6 +2675,213 @@ function encodeLiveResult(value, headers, status, codec, request, scope) {
|
|
|
2597
2675
|
throw DEV && error instanceof Error ? new Error(`Server function result could not be encoded: ${error.message}`) : error;
|
|
2598
2676
|
}
|
|
2599
2677
|
}
|
|
2678
|
+
const SHARED_SOURCES = new Map();
|
|
2679
|
+
class GenerationalRefs extends Map {
|
|
2680
|
+
count = 0;
|
|
2681
|
+
touched = new Set();
|
|
2682
|
+
get size() {
|
|
2683
|
+
return this.count;
|
|
2684
|
+
}
|
|
2685
|
+
get(key) {
|
|
2686
|
+
const id = super.get(key);
|
|
2687
|
+
if (id !== undefined) this.touched.add(key);
|
|
2688
|
+
return id;
|
|
2689
|
+
}
|
|
2690
|
+
set(key, value) {
|
|
2691
|
+
if (!super.has(key)) this.count++;
|
|
2692
|
+
this.touched.add(key);
|
|
2693
|
+
return super.set(key, value);
|
|
2694
|
+
}
|
|
2695
|
+
turn() {
|
|
2696
|
+
for (const key of [...super.keys()]) if (!this.touched.has(key)) super.delete(key);
|
|
2697
|
+
this.touched = new Set();
|
|
2698
|
+
}
|
|
2699
|
+
idOf(key) {
|
|
2700
|
+
return super.get(key);
|
|
2701
|
+
}
|
|
2702
|
+
reserve() {
|
|
2703
|
+
return this.count++;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
function sharedSourceResponse(key, value, headers, status, codec, request) {
|
|
2707
|
+
let shared = SHARED_SOURCES.get(key);
|
|
2708
|
+
let snapshot;
|
|
2709
|
+
if (shared && !shared.ended) {
|
|
2710
|
+
snapshot = sharedSnapshot(shared);
|
|
2711
|
+
if (snapshot === null) return undefined;
|
|
2712
|
+
if (value !== shared.source) closeUnread(value);
|
|
2713
|
+
} else shared = startSharedSource(key, value, codec);
|
|
2714
|
+
return tapSharedSource(shared, request, headers, status, snapshot);
|
|
2715
|
+
}
|
|
2716
|
+
function closeUnread(value) {
|
|
2717
|
+
try {
|
|
2718
|
+
const closing = typeof value.return === "function" ? value.return() : typeof value.cancel === "function" ? value.cancel() : undefined;
|
|
2719
|
+
if (closing && typeof closing.then === "function") closing.then(undefined, () => {});
|
|
2720
|
+
} catch {}
|
|
2721
|
+
}
|
|
2722
|
+
function startSharedSource(key, value, codec) {
|
|
2723
|
+
const refs = new GenerationalRefs();
|
|
2724
|
+
const shared = {
|
|
2725
|
+
key,
|
|
2726
|
+
codec,
|
|
2727
|
+
refs,
|
|
2728
|
+
encode: null,
|
|
2729
|
+
head: null,
|
|
2730
|
+
node: null,
|
|
2731
|
+
value: undefined,
|
|
2732
|
+
position: undefined,
|
|
2733
|
+
stream: undefined,
|
|
2734
|
+
source: value,
|
|
2735
|
+
taps: new Set(),
|
|
2736
|
+
ended: false,
|
|
2737
|
+
teardown: new AbortController()
|
|
2738
|
+
};
|
|
2739
|
+
SHARED_SOURCES.set(key, shared);
|
|
2740
|
+
const event = broadcastEvent();
|
|
2741
|
+
const store = globalThis[RequestContext];
|
|
2742
|
+
const scope = run => store ? store.run(event, run) : run();
|
|
2743
|
+
const live = {
|
|
2744
|
+
pending: undefined,
|
|
2745
|
+
yields: [],
|
|
2746
|
+
nodes: new WeakMap()
|
|
2747
|
+
};
|
|
2748
|
+
const body = serializeResponseStream(liveSource(value, undefined, live, scope, refs), {
|
|
2749
|
+
...codec,
|
|
2750
|
+
refs
|
|
2751
|
+
}, shared.teardown.signal, scope, live);
|
|
2752
|
+
pumpSharedSource(shared, body.getReader(), live);
|
|
2753
|
+
return shared;
|
|
2754
|
+
}
|
|
2755
|
+
async function pumpSharedSource(shared, reader, {
|
|
2756
|
+
nodes,
|
|
2757
|
+
yields
|
|
2758
|
+
}) {
|
|
2759
|
+
try {
|
|
2760
|
+
shared.encode = (await import('@solidjs/web/serialization')).serializeJSON;
|
|
2761
|
+
while (true) {
|
|
2762
|
+
const {
|
|
2763
|
+
done,
|
|
2764
|
+
value: chunk
|
|
2765
|
+
} = await reader.read();
|
|
2766
|
+
if (done) break;
|
|
2767
|
+
const node = nodes.get(chunk);
|
|
2768
|
+
if (shared.head === null) shared.head = chunk;else if (node && node.t === 32 && (shared.stream ??= node.i) === node.i) {
|
|
2769
|
+
const {
|
|
2770
|
+
value,
|
|
2771
|
+
digest
|
|
2772
|
+
} = yields.shift();
|
|
2773
|
+
shared.node = node;
|
|
2774
|
+
shared.value = value;
|
|
2775
|
+
shared.position = digest;
|
|
2776
|
+
}
|
|
2777
|
+
for (const tap of shared.taps) tap.write(chunk);
|
|
2778
|
+
}
|
|
2779
|
+
} catch {}
|
|
2780
|
+
shared.ended = true;
|
|
2781
|
+
if (SHARED_SOURCES.get(shared.key) === shared) SHARED_SOURCES.delete(shared.key);
|
|
2782
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2783
|
+
}
|
|
2784
|
+
function sharedSnapshot(shared) {
|
|
2785
|
+
if (shared.node === null) return undefined;
|
|
2786
|
+
const own = new Map();
|
|
2787
|
+
let root;
|
|
2788
|
+
let done = false;
|
|
2789
|
+
const cancel = shared.encode(shared.value, {
|
|
2790
|
+
...shared.codec,
|
|
2791
|
+
refs: own,
|
|
2792
|
+
onParse(node) {
|
|
2793
|
+
root ??= node;
|
|
2794
|
+
},
|
|
2795
|
+
onDone() {
|
|
2796
|
+
done = true;
|
|
2797
|
+
},
|
|
2798
|
+
onError() {}
|
|
2799
|
+
});
|
|
2800
|
+
if (!done || root === undefined) {
|
|
2801
|
+
cancel();
|
|
2802
|
+
return null;
|
|
2803
|
+
}
|
|
2804
|
+
const ids = new Map();
|
|
2805
|
+
for (const [value, id] of own) ids.set(id, shared.refs.idOf(value) ?? shared.refs.reserve());
|
|
2806
|
+
return createEventChunk(JSON.stringify({
|
|
2807
|
+
...shared.node,
|
|
2808
|
+
f: renumberNode(root, ids)
|
|
2809
|
+
}), shared.position);
|
|
2810
|
+
}
|
|
2811
|
+
function renumberNode(node, ids) {
|
|
2812
|
+
if (Array.isArray(node)) return node.map(item => renumberNode(item, ids));
|
|
2813
|
+
if (node === null || typeof node !== "object") return node;
|
|
2814
|
+
const out = {};
|
|
2815
|
+
for (const key in node) out[key] = key === "i" && typeof node[key] === "number" ? ids.get(node[key]) ?? node[key] : renumberNode(node[key], ids);
|
|
2816
|
+
return out;
|
|
2817
|
+
}
|
|
2818
|
+
function tapSharedSource(shared, request, headers, status, snapshot) {
|
|
2819
|
+
headers.set(BODY_FORMAT_HEADER, BodyFormat.Serialized);
|
|
2820
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2821
|
+
headers.set("Cache-Control", "no-store");
|
|
2822
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2823
|
+
const signal = request.signal;
|
|
2824
|
+
let closed = false;
|
|
2825
|
+
let stopLive = null;
|
|
2826
|
+
let tap = null;
|
|
2827
|
+
const leave = () => {
|
|
2828
|
+
if (closed) return;
|
|
2829
|
+
closed = true;
|
|
2830
|
+
if (stopLive) stopLive();
|
|
2831
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2832
|
+
shared.taps.delete(tap);
|
|
2833
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2834
|
+
shared.ended = true;
|
|
2835
|
+
if (SHARED_SOURCES.get(shared.key) === shared) SHARED_SOURCES.delete(shared.key);
|
|
2836
|
+
shared.teardown.abort();
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
const body = new ReadableStream({
|
|
2840
|
+
start(controller) {
|
|
2841
|
+
tap = {
|
|
2842
|
+
write(chunk) {
|
|
2843
|
+
if (closed) return;
|
|
2844
|
+
try {
|
|
2845
|
+
controller.enqueue(chunk);
|
|
2846
|
+
} catch {
|
|
2847
|
+
leave();
|
|
2848
|
+
}
|
|
2849
|
+
},
|
|
2850
|
+
end() {
|
|
2851
|
+
leave();
|
|
2852
|
+
try {
|
|
2853
|
+
controller.close();
|
|
2854
|
+
} catch {}
|
|
2855
|
+
}
|
|
2856
|
+
};
|
|
2857
|
+
stopLive = armLiveBody(controller, leave);
|
|
2858
|
+
if (shared.head) controller.enqueue(shared.head);
|
|
2859
|
+
if (snapshot) controller.enqueue(snapshot);
|
|
2860
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2861
|
+
shared.taps.add(tap);
|
|
2862
|
+
if (signal) signal.addEventListener("abort", leave);
|
|
2863
|
+
},
|
|
2864
|
+
cancel() {
|
|
2865
|
+
leave();
|
|
2866
|
+
}
|
|
2867
|
+
});
|
|
2868
|
+
return new Response(body, {
|
|
2869
|
+
status,
|
|
2870
|
+
headers
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
function broadcastEvent() {
|
|
2874
|
+
const event = {
|
|
2875
|
+
broadcast: true
|
|
2876
|
+
};
|
|
2877
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2878
|
+
get() {
|
|
2879
|
+
if (DEV) console.warn(`A broadcast server function read the request (\`event.${name}\`) while producing ` + "its answer, which every viewer shares; read per-viewer state before returning it.");
|
|
2880
|
+
return undefined;
|
|
2881
|
+
}
|
|
2882
|
+
});
|
|
2883
|
+
return event;
|
|
2884
|
+
}
|
|
2600
2885
|
function encodeResult(value, headers, status, codec, signal, scope) {
|
|
2601
2886
|
if (NULL_BODY_STATUSES.has(status)) {
|
|
2602
2887
|
if (value === undefined || value === null) {
|
|
@@ -2801,7 +3086,7 @@ function withHeaders(response, write) {
|
|
|
2801
3086
|
function withCSRFVary(response) {
|
|
2802
3087
|
return withHeaders(response, headers => appendVary(headers, CSRF_VARY));
|
|
2803
3088
|
}
|
|
2804
|
-
const TRANSPORT_REQUEST_HEADERS = ["Content-Type", BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER].join(", ");
|
|
3089
|
+
const TRANSPORT_REQUEST_HEADERS = ["Content-Type", BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, BUILD_HEADER].join(", ");
|
|
2805
3090
|
const PREFLIGHT_MAX_AGE = "600";
|
|
2806
3091
|
const CORS_SAFELISTED_RESPONSE_HEADERS = new Set(["cache-control", "content-language", "content-length", "content-type", "expires", "last-modified", "pragma"]);
|
|
2807
3092
|
function withCORS(response, cors) {
|
|
@@ -2903,6 +3188,17 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
2903
3188
|
});
|
|
2904
3189
|
return finish(protectsRequest ? withCSRFVary(response) : response);
|
|
2905
3190
|
}
|
|
3191
|
+
const callerBuild = request.headers.get(BUILD_HEADER);
|
|
3192
|
+
if (config.buildId && callerBuild !== null && callerBuild !== config.buildId) {
|
|
3193
|
+
return finish(new Response(DEV ? `Server function call from build "${callerBuild}" refused by build "${config.buildId}"` : null, {
|
|
3194
|
+
status: 409,
|
|
3195
|
+
headers: {
|
|
3196
|
+
[UNKNOWN_HEADER]: "true",
|
|
3197
|
+
[BUILD_HEADER]: config.buildId,
|
|
3198
|
+
"Cache-Control": "no-store"
|
|
3199
|
+
}
|
|
3200
|
+
}));
|
|
3201
|
+
}
|
|
2906
3202
|
const scripted = address.data || address.live;
|
|
2907
3203
|
const live = address.live;
|
|
2908
3204
|
if (method !== "POST" && !declaredRead) {
|
|
@@ -3032,9 +3328,12 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3032
3328
|
const dispatch = async () => {
|
|
3033
3329
|
try {
|
|
3034
3330
|
const invokeOnce = async () => {
|
|
3331
|
+
const shared = !!live && BROADCASTS.has(functionId);
|
|
3035
3332
|
INVOCATIONS.set(event, {
|
|
3036
3333
|
id: functionId,
|
|
3037
|
-
live: !!live
|
|
3334
|
+
live: !!live,
|
|
3335
|
+
broadcast: shared || undefined,
|
|
3336
|
+
shareKey: shared ? encodedArguments(request, argsEncoding, argumentBytes) : undefined
|
|
3038
3337
|
});
|
|
3039
3338
|
const run = () => serverFunction(...parsed);
|
|
3040
3339
|
return observeInvocation({
|
|
@@ -3110,7 +3409,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3110
3409
|
return encodeResult(result, headers, status, codec, request.signal, scope);
|
|
3111
3410
|
}
|
|
3112
3411
|
if (status === 304) warnScripted304(functionId);
|
|
3113
|
-
if (live)
|
|
3412
|
+
if (live) {
|
|
3413
|
+
const invocation = INVOCATIONS.get(event);
|
|
3414
|
+
return encodeLiveResult(result, headers, status, codec, request, scope, invocation && invocation.broadcast && invocation.shareKey !== undefined ? invocation.id + "\0" + invocation.shareKey : undefined);
|
|
3415
|
+
}
|
|
3114
3416
|
return encodeResult(result, headers, status, codec, request.signal, scope);
|
|
3115
3417
|
} catch (x) {
|
|
3116
3418
|
const respondThrown = value => {
|
|
@@ -3284,4 +3586,4 @@ function finalizeTransportResponse(response, method) {
|
|
|
3284
3586
|
return response;
|
|
3285
3587
|
}
|
|
3286
3588
|
|
|
3287
|
-
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, GENERIC_SERVER_ERROR_MESSAGE, GET, REDIRECT_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, armLiveBody, clearFlashCookie, configureServerFunctionsServer, createChunk, createEventChunk, createNoJSHandler, createServerReference, decodeErrorHeaderValue, decodeFlashCookie, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, encodeFlashCookie, foldSetCookies, frameAddress, getEventServerFunctionInvocation, getServerFunction, getServerFunctionInvocation, getServerFunctionMetadata, guardFailures, handleServerFunctionRequest, hasFlashCookie, invoke, isServerFunction, live, parseServerFunctionActionUrl, registerFlightDataSource, registerServerFunction, registerServerReference, sanitizeServerError, serializeResponseStream, serializeStream, serverFunctionActionUrl, serverFunctionUrl, setServerFunctionsDev, subscribeFlightData, textDigest, withMeta };
|
|
3589
|
+
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, GENERIC_SERVER_ERROR_MESSAGE, GET, REDIRECT_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, armLiveBody, broadcast, clearFlashCookie, configureServerFunctionsServer, createChunk, createEventChunk, createNoJSHandler, createServerReference, decodeErrorHeaderValue, decodeFlashCookie, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, encodeFlashCookie, foldSetCookies, frameAddress, getEventServerFunctionInvocation, getServerFunction, getServerFunctionInvocation, getServerFunctionMetadata, guardFailures, handleServerFunctionRequest, hasFlashCookie, invoke, isServerFunction, live, parseServerFunctionActionUrl, registerFlightDataSource, registerServerFunction, registerServerReference, sanitizeServerError, serializeResponseStream, serializeStream, serverFunctionActionUrl, serverFunctionUrl, setServerFunctionsDev, subscribeFlightData, textDigest, withMeta };
|
package/types/client.d.ts
CHANGED
|
@@ -203,6 +203,18 @@ export declare function unregisterDelegatedContainer(container: MountableElement
|
|
|
203
203
|
export declare function dispatchAsInteraction<T>(e: Event, fn: () => T): T;
|
|
204
204
|
export declare function getDelegatedRoot(node: MountableElement): MountableElement | undefined;
|
|
205
205
|
export declare function setProperty(node: Element, name: string, value: any): void;
|
|
206
|
+
/**
|
|
207
|
+
* A stateful DOM property write (`input.value`, `input.checked`,
|
|
208
|
+
* `option.selected`, `video.muted`, ...) from dev-compiled, non-hydratable
|
|
209
|
+
* DOM output: exactly `node[name] = value`, which is what production
|
|
210
|
+
* output inlines. The dev runtime checks it first and warns
|
|
211
|
+
* (`UNCOMMITTED_INPUT_OVERWRITTEN`) when it re-applies an unchanged bound
|
|
212
|
+
* value over an edit the user never committed to the signal. Production
|
|
213
|
+
* compile output never imports it, so it tree-shakes away.
|
|
214
|
+
*
|
|
215
|
+
* @internal Compiler output only.
|
|
216
|
+
*/
|
|
217
|
+
export declare function setStatefulProperty(node: Element, name: string, value: any): void;
|
|
206
218
|
/**
|
|
207
219
|
* Options for `registerElementClaim`.
|
|
208
220
|
* @internal
|
package/types/diagnostics.d.ts
CHANGED
|
@@ -60,5 +60,21 @@ export declare function unscopedHoleAllocatedIds(before: string, after: string,
|
|
|
60
60
|
* text. Reported once per attribute name so a row template reports once.
|
|
61
61
|
*/
|
|
62
62
|
export declare function lowercaseEventAttribute(name: string, node: Element): void;
|
|
63
|
+
/**
|
|
64
|
+
* Dev CHECK, before every compiled or spread write of a stateful DOM
|
|
65
|
+
* property (`input.value`, `input.checked`, `option.selected`,
|
|
66
|
+
* `video.muted`, ...): Solid is about to write the same value it wrote last
|
|
67
|
+
* time, but the element no longer holds what that write left there. Nothing
|
|
68
|
+
* Solid wrote changed it, so the user did — typed, clicked, toggled — and
|
|
69
|
+
* that edit never reached the bound signal; the write is about to erase it.
|
|
70
|
+
* The write re-applies an unchanged value because the binding re-ran
|
|
71
|
+
* without its value changing: another binding in the same template effect
|
|
72
|
+
* changed, a spread re-ran, or the source fired with an equal value
|
|
73
|
+
* (`equals: false`). Warns once per element and property; the write itself
|
|
74
|
+
* goes ahead unchanged. Pair with `recordStatefulWrite` after the write.
|
|
75
|
+
*/
|
|
76
|
+
export declare function checkStatefulWrite(node: Element, prop: string, value: unknown): void;
|
|
77
|
+
/** Dev: remembers what a stateful write left on the element (see `checkStatefulWrite`). */
|
|
78
|
+
export declare function recordStatefulWrite(node: Element, prop: string, value: unknown): void;
|
|
63
79
|
/** `Name: message` for an Error, `String(value)` otherwise. */
|
|
64
80
|
export declare function errorText(error: unknown): string;
|
|
@@ -8,6 +8,7 @@ export declare function morph(parent: any, fragment: any, claim: any, ranges: an
|
|
|
8
8
|
/** Land each displaced range a morph pass left in `ranges` where its
|
|
9
9
|
* occurrence now is under `roots` (see `flushGrafts`). @internal */
|
|
10
10
|
export declare function graft(roots: any, ranges: any): void;
|
|
11
|
+
export declare function morphAttributes(oldEl: any, newEl: any, claim: any): void;
|
|
11
12
|
/**
|
|
12
13
|
* Reconcile the children of `parent` toward the children of `source`, reusing
|
|
13
14
|
* existing DOM in place. `source` is a freshly parsed, disposable node whose
|
|
@@ -36,10 +36,11 @@ export interface WebSerializerOptions {
|
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
39
|
-
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures
|
|
39
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`,
|
|
40
|
+
* `serializeErrorStacks`: its stacks follow `NODE_ENV`).
|
|
40
41
|
* @internal
|
|
41
42
|
*/
|
|
42
|
-
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures">;
|
|
43
|
+
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures" | "serializeErrorStacks">;
|
|
43
44
|
/**
|
|
44
45
|
* Options for `serializeJSON`.
|
|
45
46
|
*
|
|
@@ -69,7 +70,10 @@ export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
|
69
70
|
initial: boolean;
|
|
70
71
|
}) => void;
|
|
71
72
|
onError?: (error: unknown) => void;
|
|
72
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Fires once `flush()` has been called and every pending value settled, or
|
|
75
|
+
* once `close()` runs.
|
|
76
|
+
*/
|
|
73
77
|
onDone?: () => void;
|
|
74
78
|
}
|
|
75
79
|
export declare const createPlugin: <Value, Info extends PluginInfo>(plugin: SerializerPlugin<Value, Info>) => SerializerPlugin<Value, Info>;
|
|
@@ -91,7 +95,11 @@ export declare const OpaqueReference: {
|
|
|
91
95
|
* Integration-facing; may change (see the entry banner).
|
|
92
96
|
*/
|
|
93
97
|
export declare function createSerializer(options: WebSerializerOptions): Serializer;
|
|
94
|
-
export declare function createHydrationSerializer(options: HydrationSerializerOptions):
|
|
98
|
+
export declare function createHydrationSerializer(options: HydrationSerializerOptions): {
|
|
99
|
+
write(key: string, value: unknown): void;
|
|
100
|
+
flush(): void;
|
|
101
|
+
close(): void;
|
|
102
|
+
};
|
|
95
103
|
export declare function getLocalHeaderScript(id?: string): string;
|
|
96
104
|
export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
97
105
|
export declare function createJSONSerializer(options: JSONSerializerOptions): {
|
package/types/serializer.d.ts
CHANGED
|
@@ -36,10 +36,11 @@ export interface WebSerializerOptions {
|
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
39
|
-
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures
|
|
39
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`,
|
|
40
|
+
* `serializeErrorStacks`: its stacks follow `NODE_ENV`).
|
|
40
41
|
* @internal
|
|
41
42
|
*/
|
|
42
|
-
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures">;
|
|
43
|
+
export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures" | "serializeErrorStacks">;
|
|
43
44
|
/**
|
|
44
45
|
* Options for `serializeJSON`.
|
|
45
46
|
*
|
|
@@ -69,7 +70,10 @@ export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
|
69
70
|
initial: boolean;
|
|
70
71
|
}) => void;
|
|
71
72
|
onError?: (error: unknown) => void;
|
|
72
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Fires once `flush()` has been called and every pending value settled, or
|
|
75
|
+
* once `close()` runs.
|
|
76
|
+
*/
|
|
73
77
|
onDone?: () => void;
|
|
74
78
|
}
|
|
75
79
|
export declare const createPlugin: <Value, Info extends PluginInfo>(plugin: SerializerPlugin<Value, Info>) => SerializerPlugin<Value, Info>;
|
|
@@ -91,7 +95,11 @@ export declare const OpaqueReference: {
|
|
|
91
95
|
* Integration-facing; may change (see the entry banner).
|
|
92
96
|
*/
|
|
93
97
|
export declare function createSerializer(options: WebSerializerOptions): Serializer;
|
|
94
|
-
export declare function createHydrationSerializer(options: HydrationSerializerOptions):
|
|
98
|
+
export declare function createHydrationSerializer(options: HydrationSerializerOptions): {
|
|
99
|
+
write(key: string, value: unknown): void;
|
|
100
|
+
flush(): void;
|
|
101
|
+
close(): void;
|
|
102
|
+
};
|
|
95
103
|
export declare function getLocalHeaderScript(id?: string): string;
|
|
96
104
|
export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
97
105
|
export declare function createJSONSerializer(options: JSONSerializerOptions): {
|
|
@@ -17,5 +17,14 @@ export declare function argumentDecodeCodec(codec: any, defaults: any): any;
|
|
|
17
17
|
* JSON string the quotes would be escaped, so payload data cannot spell it.
|
|
18
18
|
*/
|
|
19
19
|
export declare function namesRefusedType(payload: any): boolean;
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The configured codec options with encode-side refusals ahead of every
|
|
22
|
+
* plugin. `extra` holds plugins for one call (the upload serializer), which
|
|
23
|
+
* go first.
|
|
24
|
+
*/
|
|
25
|
+
export declare function argumentEncodeCodec(codec: any, extra?: any[]): any;
|
|
26
|
+
/**
|
|
27
|
+
* Decode options from `argumentDecodeCodec` with plugins for one request
|
|
28
|
+
* (the upload deserializer) ahead of the resolved list.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withArgumentPlugins(argumentCodec: any, extra: any): any;
|
|
@@ -179,9 +179,11 @@ export interface ServerFunctionsClientConfig {
|
|
|
179
179
|
* Encoder for argument lists JSON can't carry faithfully. JSON-safe args
|
|
180
180
|
* always go as plain JSON (no codec in the bundle); anything else throws
|
|
181
181
|
* unless this is set. Installed by `enableRichArguments()` from the
|
|
182
|
-
* rich-args entry — set directly only for custom wire encodings.
|
|
182
|
+
* rich-args entry — set directly only for custom wire encodings. A
|
|
183
|
+
* `FormData` answer is sent as an upload: the codec output in its `args`
|
|
184
|
+
* field and each file in a `file<index>` part.
|
|
183
185
|
*/
|
|
184
|
-
serializeArgs?(args: unknown[]): string | Promise<string>;
|
|
186
|
+
serializeArgs?(args: unknown[]): string | FormData | Promise<string | FormData>;
|
|
185
187
|
}
|
|
186
188
|
/** Wire-state transitions a live call's iterable can report. */
|
|
187
189
|
export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
|
|
@@ -227,7 +229,7 @@ export interface ServerFunctionInvocation {
|
|
|
227
229
|
* <link rel="preload" as="fetch" crossorigin href={serverFunctionUrl(getUser, id)} />
|
|
228
230
|
* ```
|
|
229
231
|
*
|
|
230
|
-
* A `live(
|
|
232
|
+
* A `live(fn)` reference's call connects at the live address, so that
|
|
231
233
|
* is the url returned for one (`<endpoint>/live/<id>[?args=...]`): a
|
|
232
234
|
* standing event stream of the answer — fetch it by hand (`curl -N`) to
|
|
233
235
|
* watch it; do not preload or prefetch it, which would open a stream
|
|
@@ -251,6 +253,12 @@ export interface LiveServerFunction<A extends readonly any[] = any[], R = any> {
|
|
|
251
253
|
/** URL invoking this function directly over HTTP. */
|
|
252
254
|
readonly url: string;
|
|
253
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Declares a live server function whose answer is the same for every
|
|
258
|
+
* viewer: on the client exactly `live(fn)` — the sharing is the server's.
|
|
259
|
+
* @experimental
|
|
260
|
+
*/
|
|
261
|
+
export declare function broadcast<A extends readonly any[], R>(fn: (...args: A) => R): LiveServerFunction<A, Awaited<R>>;
|
|
254
262
|
/**
|
|
255
263
|
* Declares a value-shaped live source: a server function returning an async
|
|
256
264
|
* iterable whose yields are successive VALUES of one logical query, with the
|
|
@@ -261,7 +269,8 @@ export interface LiveServerFunction<A extends readonly any[] = any[], R = any> {
|
|
|
261
269
|
* first-connect failures reject like a normal call, and `break` aborts the
|
|
262
270
|
* in-flight request. Live calls are reads and never opt into single-flight
|
|
263
271
|
* enveloping. Wire state, if wanted, rides the returned iterable's
|
|
264
|
-
* `onstatus` hook.
|
|
272
|
+
* `onstatus` hook. Implies `GET` (a live source is a read); an explicit
|
|
273
|
+
* `live(GET(fn))` is equivalent.
|
|
265
274
|
*/
|
|
266
275
|
export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): LiveServerFunction<A, Awaited<R>>;
|
|
267
276
|
export declare function registerServerReference(): never;
|