@solidjs/web 2.0.0-rc.11 → 2.0.0-rc.14
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 +705 -151
- package/dist/server.js +604 -123
- package/dist/server.observe.js +617 -124
- package/dist/web.dev.js +102 -41
- package/dist/web.js +75 -37
- package/dist/web.observe.js +75 -39
- package/frames/dist/assets.js +92 -0
- package/frames/dist/bind.dev.js +326 -0
- package/frames/dist/bind.js +295 -0
- package/frames/dist/client.dev.js +693 -919
- package/frames/dist/client.js +636 -917
- package/frames/dist/client.observe.js +637 -917
- package/frames/dist/regions.js +130 -0
- package/frames/dist/server.dev.js +607 -212
- package/frames/dist/server.js +554 -212
- package/frames/dist/server.observe.js +554 -212
- package/frames/dist/trace.js +42 -0
- package/frames/dist/wire.js +133 -0
- package/package.json +30 -3
- package/performance-tracks/dist/performance-tracks.dev.js +2 -1
- package/performance-tracks/dist/performance-tracks.observe.js +2 -1
- package/performance-tracks/types/index.d.ts +8 -6
- package/serialization/dist/decode.js +37 -8
- package/serialization/dist/serialization.js +39 -10
- package/serialization/types/serializer-decode.d.ts +24 -2
- package/server-functions/dist/client.dev.js +178 -72
- package/server-functions/dist/client.js +99 -61
- package/server-functions/dist/client.observe.js +178 -72
- package/server-functions/dist/server.dev.js +117 -56
- package/server-functions/dist/server.js +117 -56
- package/server-functions/dist/server.observe.js +117 -56
- package/skills/server-components/SKILL.md +228 -0
- package/types/client.d.ts +37 -2
- package/types/constants.d.ts +2 -1
- package/types/diagnostics.d.ts +8 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/bind-tier.d.ts +60 -0
- package/types/frames/client.d.ts +37 -3
- package/types/frames/frame-client.d.ts +249 -96
- package/types/frames/frame-container-plugin.d.ts +2 -10
- package/types/frames/frame-sink.d.ts +33 -0
- package/types/frames/frame-transport.d.ts +66 -18
- package/types/frames/regions-tier.d.ts +45 -0
- package/types/frames/serializer-decode.d.ts +24 -2
- package/types/frames/server.d.ts +53 -1
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/tree-rewrite.d.ts +39 -0
- package/types/frames/wire-tier.d.ts +116 -0
- package/types/index.d.ts +38 -0
- package/types/index.server.d.ts +10 -1
- package/types/jsx.d.ts +11 -1
- package/types/observe.d.ts +182 -12
- package/types/request-error-hook.d.ts +5 -0
- package/types/serializer-decode.d.ts +24 -2
- package/types/server-functions/client.d.ts +26 -0
- package/types/server-functions/registry.d.ts +4 -1
- package/types/server-functions/shared.d.ts +12 -8
- package/types/server-mock.d.ts +13 -1
- package/types/server-observe.d.ts +8 -0
- package/types/server.d.ts +125 -12
|
@@ -51,7 +51,7 @@ function provideServerFunctionRPC(rpc) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const FLASH_COOKIE = "flash";
|
|
54
|
-
const FLASH_MATCHER =
|
|
54
|
+
const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
|
|
55
55
|
function hasFlashCookie(cookieHeader) {
|
|
56
56
|
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
57
57
|
}
|
|
@@ -97,6 +97,7 @@ function hasFlightMetadata(response) {
|
|
|
97
97
|
return response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
|
|
98
98
|
}
|
|
99
99
|
async function deliverFlightData(response, data) {
|
|
100
|
+
if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
|
|
100
101
|
const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
|
|
101
102
|
const metadata = hasFlightMetadata(response);
|
|
102
103
|
for (const source of getFlightDataSourceIds()) {
|
|
@@ -416,26 +417,42 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
416
417
|
return undefined;
|
|
417
418
|
}
|
|
418
419
|
function createChunk(data) {
|
|
419
|
-
const
|
|
420
|
-
const encodeData = encoder.encode(data);
|
|
420
|
+
const encodeData = CHUNK_ENCODER.encode(data);
|
|
421
421
|
const bytes = encodeData.length;
|
|
422
|
+
if (bytes > MAX_CHUNK_BYTES) {
|
|
423
|
+
throw new RangeError("Server function chunk is too large to frame.");
|
|
424
|
+
}
|
|
422
425
|
const chunk = new Uint8Array(12 + bytes);
|
|
423
|
-
chunk.set(
|
|
426
|
+
chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
424
427
|
chunk.set(encodeData, 12);
|
|
425
428
|
return chunk;
|
|
426
429
|
}
|
|
430
|
+
const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
|
|
431
|
+
const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
|
|
432
|
+
fatal: true
|
|
433
|
+
});
|
|
434
|
+
const MAX_CHUNK_BYTES = 0xffffffff;
|
|
435
|
+
const RETAINED_STORE_BYTES = 64 * 1024;
|
|
436
|
+
const DONE = {
|
|
437
|
+
done: true,
|
|
438
|
+
value: undefined
|
|
439
|
+
};
|
|
440
|
+
function malformedStream() {
|
|
441
|
+
return new Error("Malformed server function stream.");
|
|
442
|
+
}
|
|
427
443
|
class ChunkReader {
|
|
428
444
|
constructor(stream) {
|
|
429
445
|
this.reader = stream.getReader();
|
|
430
446
|
this.store = new Uint8Array(0);
|
|
431
447
|
this.buffer = this.store;
|
|
432
448
|
this.done = false;
|
|
449
|
+
this.cancelled = false;
|
|
433
450
|
}
|
|
434
451
|
async readChunk() {
|
|
435
452
|
const chunk = await this.reader.read();
|
|
436
453
|
if (chunk.done) {
|
|
437
454
|
this.done = true;
|
|
438
|
-
return;
|
|
455
|
+
return this.cancelled;
|
|
439
456
|
}
|
|
440
457
|
const incoming = chunk.value;
|
|
441
458
|
const store = this.store;
|
|
@@ -456,55 +473,66 @@ class ChunkReader {
|
|
|
456
473
|
this.store = grown;
|
|
457
474
|
this.buffer = grown.subarray(0, needed);
|
|
458
475
|
}
|
|
476
|
+
return this.cancelled;
|
|
459
477
|
}
|
|
460
478
|
async next() {
|
|
479
|
+
if (this.cancelled) return DONE;
|
|
461
480
|
while (this.buffer.length < 12) {
|
|
462
481
|
if (this.done) {
|
|
463
|
-
if (this.buffer.length === 0) return
|
|
464
|
-
|
|
465
|
-
value: undefined
|
|
466
|
-
};
|
|
467
|
-
throw new Error("Malformed server function stream.");
|
|
482
|
+
if (this.buffer.length === 0) return DONE;
|
|
483
|
+
throw malformedStream();
|
|
468
484
|
}
|
|
469
|
-
await this.readChunk();
|
|
470
|
-
}
|
|
471
|
-
const decoder = new TextDecoder();
|
|
472
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
473
|
-
if (Number.isNaN(bytes)) {
|
|
474
|
-
throw new Error("Malformed server function stream.");
|
|
485
|
+
if (await this.readChunk()) return DONE;
|
|
475
486
|
}
|
|
487
|
+
const header = String.fromCharCode(...this.buffer.subarray(0, 12));
|
|
488
|
+
if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
|
|
489
|
+
const bytes = parseInt(header.slice(3, 11), 16);
|
|
476
490
|
while (bytes > this.buffer.length - 12) {
|
|
477
491
|
if (this.done) {
|
|
478
|
-
throw
|
|
492
|
+
throw malformedStream();
|
|
479
493
|
}
|
|
480
|
-
await this.readChunk();
|
|
494
|
+
if (await this.readChunk()) return DONE;
|
|
495
|
+
}
|
|
496
|
+
let partial;
|
|
497
|
+
try {
|
|
498
|
+
partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
|
|
499
|
+
} catch {
|
|
500
|
+
throw malformedStream();
|
|
481
501
|
}
|
|
482
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
483
502
|
this.buffer = this.buffer.subarray(12 + bytes);
|
|
503
|
+
if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
|
|
504
|
+
this.store = this.buffer = this.buffer.slice();
|
|
505
|
+
}
|
|
484
506
|
return {
|
|
485
507
|
done: false,
|
|
486
508
|
value: partial
|
|
487
509
|
};
|
|
488
510
|
}
|
|
489
511
|
async drain(interpret) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
512
|
+
try {
|
|
513
|
+
while (true) {
|
|
514
|
+
const result = await this.next();
|
|
515
|
+
if (result.done) {
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
interpret(result.value);
|
|
494
519
|
}
|
|
495
|
-
|
|
520
|
+
} catch (error) {
|
|
521
|
+
this.cancel(error).catch(() => {});
|
|
522
|
+
throw error;
|
|
496
523
|
}
|
|
497
524
|
}
|
|
498
525
|
cancel(reason) {
|
|
526
|
+
this.cancelled = true;
|
|
499
527
|
return this.reader.cancel(reason);
|
|
500
528
|
}
|
|
501
529
|
}
|
|
502
530
|
function createEventChunk(data, id) {
|
|
503
531
|
let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
|
|
504
532
|
for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
|
|
505
|
-
return
|
|
533
|
+
return CHUNK_ENCODER.encode(event + "\n");
|
|
506
534
|
}
|
|
507
|
-
const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
|
|
535
|
+
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
508
536
|
function isEventStream(source) {
|
|
509
537
|
const contentType = source.headers.get("content-type");
|
|
510
538
|
return !!contentType && contentType.startsWith("text/event-stream");
|
|
@@ -647,40 +675,44 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
647
675
|
throw new Error("missing body");
|
|
648
676
|
}
|
|
649
677
|
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (result.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const {
|
|
656
|
-
createJSONDeserializer
|
|
657
|
-
} = await import('@solidjs/web/serialization/decode');
|
|
658
|
-
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
659
|
-
function interpretChunk(chunk) {
|
|
660
|
-
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
661
|
-
throw errorFromTrailer(chunk);
|
|
678
|
+
try {
|
|
679
|
+
const result = await reader.next();
|
|
680
|
+
if (!result.done) {
|
|
681
|
+
if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
682
|
+
throw errorFromTrailer(result.value);
|
|
662
683
|
}
|
|
663
|
-
|
|
684
|
+
const {
|
|
685
|
+
createJSONDeserializer
|
|
686
|
+
} = await import('@solidjs/web/serialization/decode');
|
|
687
|
+
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
688
|
+
function interpretChunk(chunk) {
|
|
689
|
+
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
690
|
+
throw errorFromTrailer(chunk);
|
|
691
|
+
}
|
|
692
|
+
return deserializeChunk(JSON.parse(chunk));
|
|
693
|
+
}
|
|
694
|
+
const connection = wire && wire.connection;
|
|
695
|
+
let endConnection;
|
|
696
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
697
|
+
const end = error => {
|
|
698
|
+
const sweep = () => deserializeChunk.abort(error);
|
|
699
|
+
if (connection) {
|
|
700
|
+
const close = () => deserializeChunk.close();
|
|
701
|
+
endConnection({
|
|
702
|
+
open: deserializeChunk.open(),
|
|
703
|
+
error,
|
|
704
|
+
sweep,
|
|
705
|
+
close
|
|
706
|
+
});
|
|
707
|
+
} else sweep();
|
|
708
|
+
};
|
|
709
|
+
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
710
|
+
return interpretChunk(result.value);
|
|
664
711
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
const end = error => {
|
|
669
|
-
const sweep = () => deserializeChunk.abort(error);
|
|
670
|
-
if (connection) {
|
|
671
|
-
const close = () => deserializeChunk.close();
|
|
672
|
-
endConnection({
|
|
673
|
-
open: deserializeChunk.open(),
|
|
674
|
-
error,
|
|
675
|
-
sweep,
|
|
676
|
-
close
|
|
677
|
-
});
|
|
678
|
-
} else sweep();
|
|
679
|
-
};
|
|
680
|
-
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
681
|
-
return interpretChunk(result.value);
|
|
712
|
+
} catch (error) {
|
|
713
|
+
reader.cancel(error).catch(() => {});
|
|
714
|
+
throw error;
|
|
682
715
|
}
|
|
683
|
-
return undefined;
|
|
684
716
|
}
|
|
685
717
|
async function decodeResponse(response, codecOptions) {
|
|
686
718
|
if (!response.body) return undefined;
|
|
@@ -885,6 +917,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
|
|
|
885
917
|
id,
|
|
886
918
|
meta
|
|
887
919
|
}) : undefined;
|
|
920
|
+
const sent = options;
|
|
888
921
|
const controller = options.signal ? undefined : new AbortController();
|
|
889
922
|
if (controller) options = {
|
|
890
923
|
...options,
|
|
@@ -896,7 +929,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
|
|
|
896
929
|
id,
|
|
897
930
|
meta,
|
|
898
931
|
args: callArgs,
|
|
899
|
-
context
|
|
932
|
+
context,
|
|
933
|
+
retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
|
|
900
934
|
};
|
|
901
935
|
if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
|
|
902
936
|
const handled = handler.handle(response, ctx);
|
|
@@ -960,7 +994,8 @@ function createServerReference(id, name, base) {
|
|
|
960
994
|
const hit = handler.intercept({
|
|
961
995
|
id,
|
|
962
996
|
meta: metadata,
|
|
963
|
-
args
|
|
997
|
+
args,
|
|
998
|
+
retry: send
|
|
964
999
|
});
|
|
965
1000
|
if (hit !== undefined) return localOrSend(hit, send);
|
|
966
1001
|
}
|
|
@@ -991,12 +1026,14 @@ function GET(fn) {
|
|
|
991
1026
|
const run = async (args, invokeOptions) => {
|
|
992
1027
|
const handler = config.responseHandler;
|
|
993
1028
|
if (handler && handler.intercept && !adoptedCall(invokeOptions)) {
|
|
1029
|
+
const retry = () => send(args, invokeOptions);
|
|
994
1030
|
const hit = handler.intercept({
|
|
995
1031
|
id,
|
|
996
1032
|
meta: metadata,
|
|
997
|
-
args
|
|
1033
|
+
args,
|
|
1034
|
+
retry
|
|
998
1035
|
});
|
|
999
|
-
if (hit !== undefined) return localOrSend(hit,
|
|
1036
|
+
if (hit !== undefined) return localOrSend(hit, retry);
|
|
1000
1037
|
}
|
|
1001
1038
|
return send(args, invokeOptions);
|
|
1002
1039
|
};
|
|
@@ -1054,6 +1091,7 @@ function live(fn) {
|
|
|
1054
1091
|
};
|
|
1055
1092
|
const makeIterable = (args, invokeOptions) => {
|
|
1056
1093
|
const handler = config.responseHandler;
|
|
1094
|
+
handler && handler.onLive && handler.onLive();
|
|
1057
1095
|
const local = handler && handler.intercept ? handler.intercept({
|
|
1058
1096
|
id,
|
|
1059
1097
|
meta: metadata,
|