@solidjs/web 2.0.0-rc.13 → 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 +200 -73
- package/dist/server.js +182 -59
- package/dist/server.observe.js +183 -60
- package/dist/web.dev.js +70 -35
- package/dist/web.js +43 -31
- package/dist/web.observe.js +43 -33
- 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 +605 -1086
- package/frames/dist/client.js +572 -1066
- package/frames/dist/client.observe.js +571 -1066
- package/frames/dist/regions.js +130 -0
- package/frames/dist/server.dev.js +339 -177
- package/frames/dist/server.js +335 -173
- package/frames/dist/server.observe.js +335 -173
- package/frames/dist/trace.js +42 -0
- package/frames/dist/wire.js +133 -0
- package/package.json +28 -2
- 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 +99 -61
- package/server-functions/dist/client.js +99 -61
- package/server-functions/dist/client.observe.js +99 -61
- package/server-functions/dist/server.dev.js +87 -50
- package/server-functions/dist/server.js +87 -50
- package/server-functions/dist/server.observe.js +87 -50
- package/skills/server-components/SKILL.md +65 -43
- package/types/client.d.ts +20 -0
- 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 -78
- package/types/frames/frame-container-plugin.d.ts +2 -2
- 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 +32 -8
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/wire-tier.d.ts +116 -0
- package/types/index.d.ts +38 -0
- package/types/index.server.d.ts +9 -0
- package/types/jsx.d.ts +1 -1
- package/types/observe.d.ts +4 -2
- 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.d.ts +34 -8
|
@@ -158,7 +158,7 @@ function provideServerFunctionRPC(rpc) {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
const FLASH_COOKIE = "flash";
|
|
161
|
-
const FLASH_MATCHER =
|
|
161
|
+
const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
|
|
162
162
|
function hasFlashCookie(cookieHeader) {
|
|
163
163
|
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
164
164
|
}
|
|
@@ -204,6 +204,7 @@ function hasFlightMetadata(response) {
|
|
|
204
204
|
return response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
|
|
205
205
|
}
|
|
206
206
|
async function deliverFlightData(response, data) {
|
|
207
|
+
if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
|
|
207
208
|
const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
|
|
208
209
|
const metadata = hasFlightMetadata(response);
|
|
209
210
|
for (const source of getFlightDataSourceIds()) {
|
|
@@ -523,26 +524,42 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
523
524
|
return undefined;
|
|
524
525
|
}
|
|
525
526
|
function createChunk(data) {
|
|
526
|
-
const
|
|
527
|
-
const encodeData = encoder.encode(data);
|
|
527
|
+
const encodeData = CHUNK_ENCODER.encode(data);
|
|
528
528
|
const bytes = encodeData.length;
|
|
529
|
+
if (bytes > MAX_CHUNK_BYTES) {
|
|
530
|
+
throw new RangeError("Server function chunk is too large to frame.");
|
|
531
|
+
}
|
|
529
532
|
const chunk = new Uint8Array(12 + bytes);
|
|
530
|
-
chunk.set(
|
|
533
|
+
chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
531
534
|
chunk.set(encodeData, 12);
|
|
532
535
|
return chunk;
|
|
533
536
|
}
|
|
537
|
+
const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
|
|
538
|
+
const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
|
|
539
|
+
fatal: true
|
|
540
|
+
});
|
|
541
|
+
const MAX_CHUNK_BYTES = 0xffffffff;
|
|
542
|
+
const RETAINED_STORE_BYTES = 64 * 1024;
|
|
543
|
+
const DONE = {
|
|
544
|
+
done: true,
|
|
545
|
+
value: undefined
|
|
546
|
+
};
|
|
547
|
+
function malformedStream() {
|
|
548
|
+
return new Error("Malformed server function stream.");
|
|
549
|
+
}
|
|
534
550
|
class ChunkReader {
|
|
535
551
|
constructor(stream) {
|
|
536
552
|
this.reader = stream.getReader();
|
|
537
553
|
this.store = new Uint8Array(0);
|
|
538
554
|
this.buffer = this.store;
|
|
539
555
|
this.done = false;
|
|
556
|
+
this.cancelled = false;
|
|
540
557
|
}
|
|
541
558
|
async readChunk() {
|
|
542
559
|
const chunk = await this.reader.read();
|
|
543
560
|
if (chunk.done) {
|
|
544
561
|
this.done = true;
|
|
545
|
-
return;
|
|
562
|
+
return this.cancelled;
|
|
546
563
|
}
|
|
547
564
|
const incoming = chunk.value;
|
|
548
565
|
const store = this.store;
|
|
@@ -563,55 +580,66 @@ class ChunkReader {
|
|
|
563
580
|
this.store = grown;
|
|
564
581
|
this.buffer = grown.subarray(0, needed);
|
|
565
582
|
}
|
|
583
|
+
return this.cancelled;
|
|
566
584
|
}
|
|
567
585
|
async next() {
|
|
586
|
+
if (this.cancelled) return DONE;
|
|
568
587
|
while (this.buffer.length < 12) {
|
|
569
588
|
if (this.done) {
|
|
570
|
-
if (this.buffer.length === 0) return
|
|
571
|
-
|
|
572
|
-
value: undefined
|
|
573
|
-
};
|
|
574
|
-
throw new Error("Malformed server function stream.");
|
|
589
|
+
if (this.buffer.length === 0) return DONE;
|
|
590
|
+
throw malformedStream();
|
|
575
591
|
}
|
|
576
|
-
await this.readChunk();
|
|
577
|
-
}
|
|
578
|
-
const decoder = new TextDecoder();
|
|
579
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
580
|
-
if (Number.isNaN(bytes)) {
|
|
581
|
-
throw new Error("Malformed server function stream.");
|
|
592
|
+
if (await this.readChunk()) return DONE;
|
|
582
593
|
}
|
|
594
|
+
const header = String.fromCharCode(...this.buffer.subarray(0, 12));
|
|
595
|
+
if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
|
|
596
|
+
const bytes = parseInt(header.slice(3, 11), 16);
|
|
583
597
|
while (bytes > this.buffer.length - 12) {
|
|
584
598
|
if (this.done) {
|
|
585
|
-
throw
|
|
599
|
+
throw malformedStream();
|
|
586
600
|
}
|
|
587
|
-
await this.readChunk();
|
|
601
|
+
if (await this.readChunk()) return DONE;
|
|
602
|
+
}
|
|
603
|
+
let partial;
|
|
604
|
+
try {
|
|
605
|
+
partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
|
|
606
|
+
} catch {
|
|
607
|
+
throw malformedStream();
|
|
588
608
|
}
|
|
589
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
590
609
|
this.buffer = this.buffer.subarray(12 + bytes);
|
|
610
|
+
if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
|
|
611
|
+
this.store = this.buffer = this.buffer.slice();
|
|
612
|
+
}
|
|
591
613
|
return {
|
|
592
614
|
done: false,
|
|
593
615
|
value: partial
|
|
594
616
|
};
|
|
595
617
|
}
|
|
596
618
|
async drain(interpret) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
619
|
+
try {
|
|
620
|
+
while (true) {
|
|
621
|
+
const result = await this.next();
|
|
622
|
+
if (result.done) {
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
interpret(result.value);
|
|
601
626
|
}
|
|
602
|
-
|
|
627
|
+
} catch (error) {
|
|
628
|
+
this.cancel(error).catch(() => {});
|
|
629
|
+
throw error;
|
|
603
630
|
}
|
|
604
631
|
}
|
|
605
632
|
cancel(reason) {
|
|
633
|
+
this.cancelled = true;
|
|
606
634
|
return this.reader.cancel(reason);
|
|
607
635
|
}
|
|
608
636
|
}
|
|
609
637
|
function createEventChunk(data, id) {
|
|
610
638
|
let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
|
|
611
639
|
for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
|
|
612
|
-
return
|
|
640
|
+
return CHUNK_ENCODER.encode(event + "\n");
|
|
613
641
|
}
|
|
614
|
-
const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
|
|
642
|
+
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
615
643
|
function isEventStream(source) {
|
|
616
644
|
const contentType = source.headers.get("content-type");
|
|
617
645
|
return !!contentType && contentType.startsWith("text/event-stream");
|
|
@@ -754,40 +782,44 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
754
782
|
throw new Error("missing body");
|
|
755
783
|
}
|
|
756
784
|
const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (result.
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
785
|
+
try {
|
|
786
|
+
const result = await reader.next();
|
|
787
|
+
if (!result.done) {
|
|
788
|
+
if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
789
|
+
throw errorFromTrailer(result.value);
|
|
790
|
+
}
|
|
791
|
+
const {
|
|
792
|
+
createJSONDeserializer
|
|
793
|
+
} = await import('@solidjs/web/serialization/decode');
|
|
794
|
+
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
795
|
+
function interpretChunk(chunk) {
|
|
796
|
+
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
797
|
+
throw errorFromTrailer(chunk);
|
|
798
|
+
}
|
|
799
|
+
return deserializeChunk(JSON.parse(chunk));
|
|
769
800
|
}
|
|
770
|
-
|
|
801
|
+
const connection = wire && wire.connection;
|
|
802
|
+
let endConnection;
|
|
803
|
+
if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
|
|
804
|
+
const end = error => {
|
|
805
|
+
const sweep = () => deserializeChunk.abort(error);
|
|
806
|
+
if (connection) {
|
|
807
|
+
const close = () => deserializeChunk.close();
|
|
808
|
+
endConnection({
|
|
809
|
+
open: deserializeChunk.open(),
|
|
810
|
+
error,
|
|
811
|
+
sweep,
|
|
812
|
+
close
|
|
813
|
+
});
|
|
814
|
+
} else sweep();
|
|
815
|
+
};
|
|
816
|
+
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
817
|
+
return interpretChunk(result.value);
|
|
771
818
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const end = error => {
|
|
776
|
-
const sweep = () => deserializeChunk.abort(error);
|
|
777
|
-
if (connection) {
|
|
778
|
-
const close = () => deserializeChunk.close();
|
|
779
|
-
endConnection({
|
|
780
|
-
open: deserializeChunk.open(),
|
|
781
|
-
error,
|
|
782
|
-
sweep,
|
|
783
|
-
close
|
|
784
|
-
});
|
|
785
|
-
} else sweep();
|
|
786
|
-
};
|
|
787
|
-
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
788
|
-
return interpretChunk(result.value);
|
|
819
|
+
} catch (error) {
|
|
820
|
+
reader.cancel(error).catch(() => {});
|
|
821
|
+
throw error;
|
|
789
822
|
}
|
|
790
|
-
return undefined;
|
|
791
823
|
}
|
|
792
824
|
async function decodeResponse(response, codecOptions) {
|
|
793
825
|
if (!response.body) return undefined;
|
|
@@ -1014,6 +1046,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
|
|
|
1014
1046
|
id,
|
|
1015
1047
|
meta
|
|
1016
1048
|
}) : undefined;
|
|
1049
|
+
const sent = options;
|
|
1017
1050
|
const controller = options.signal ? undefined : new AbortController();
|
|
1018
1051
|
if (controller) options = {
|
|
1019
1052
|
...options,
|
|
@@ -1030,7 +1063,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
|
|
|
1030
1063
|
id,
|
|
1031
1064
|
meta,
|
|
1032
1065
|
args: callArgs,
|
|
1033
|
-
context
|
|
1066
|
+
context,
|
|
1067
|
+
retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
|
|
1034
1068
|
};
|
|
1035
1069
|
if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
|
|
1036
1070
|
const handled = handler.handle(response, ctx);
|
|
@@ -1094,7 +1128,8 @@ function createServerReference(id, name, base) {
|
|
|
1094
1128
|
const hit = handler.intercept({
|
|
1095
1129
|
id,
|
|
1096
1130
|
meta: metadata,
|
|
1097
|
-
args
|
|
1131
|
+
args,
|
|
1132
|
+
retry: send
|
|
1098
1133
|
});
|
|
1099
1134
|
if (hit !== undefined) return localOrSend(hit, send);
|
|
1100
1135
|
}
|
|
@@ -1125,12 +1160,14 @@ function GET(fn) {
|
|
|
1125
1160
|
const run = async (args, invokeOptions) => {
|
|
1126
1161
|
const handler = config.responseHandler;
|
|
1127
1162
|
if (handler && handler.intercept && !adoptedCall(invokeOptions)) {
|
|
1163
|
+
const retry = () => send(args, invokeOptions);
|
|
1128
1164
|
const hit = handler.intercept({
|
|
1129
1165
|
id,
|
|
1130
1166
|
meta: metadata,
|
|
1131
|
-
args
|
|
1167
|
+
args,
|
|
1168
|
+
retry
|
|
1132
1169
|
});
|
|
1133
|
-
if (hit !== undefined) return localOrSend(hit,
|
|
1170
|
+
if (hit !== undefined) return localOrSend(hit, retry);
|
|
1134
1171
|
}
|
|
1135
1172
|
return send(args, invokeOptions);
|
|
1136
1173
|
};
|
|
@@ -1188,6 +1225,7 @@ function live(fn) {
|
|
|
1188
1225
|
};
|
|
1189
1226
|
const makeIterable = (args, invokeOptions) => {
|
|
1190
1227
|
const handler = config.responseHandler;
|
|
1228
|
+
handler && handler.onLive && handler.onLive();
|
|
1191
1229
|
const local = handler && handler.intercept ? handler.intercept({
|
|
1192
1230
|
id,
|
|
1193
1231
|
meta: metadata,
|
|
@@ -393,7 +393,7 @@ function assertServableCookie(name, options) {
|
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
const FLASH_COOKIE = "flash";
|
|
396
|
-
const FLASH_MATCHER =
|
|
396
|
+
const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
|
|
397
397
|
function hasFlashCookie(cookieHeader) {
|
|
398
398
|
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
399
399
|
}
|
|
@@ -711,7 +711,7 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
711
711
|
const format = source.headers.get(BODY_FORMAT_HEADER);
|
|
712
712
|
switch (true) {
|
|
713
713
|
case format === BodyFormat.Serialized:
|
|
714
|
-
return await deserializeStream(source, codecOptions);
|
|
714
|
+
return await deserializeStream(source, codecOptions, wire);
|
|
715
715
|
case format === BodyFormat.Json:
|
|
716
716
|
return JSON.parse(await source.text());
|
|
717
717
|
case format === BodyFormat.String:
|
|
@@ -737,26 +737,42 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
737
737
|
return undefined;
|
|
738
738
|
}
|
|
739
739
|
function createChunk(data) {
|
|
740
|
-
const
|
|
741
|
-
const encodeData = encoder.encode(data);
|
|
740
|
+
const encodeData = CHUNK_ENCODER.encode(data);
|
|
742
741
|
const bytes = encodeData.length;
|
|
742
|
+
if (bytes > MAX_CHUNK_BYTES) {
|
|
743
|
+
throw new RangeError("Server function chunk is too large to frame.");
|
|
744
|
+
}
|
|
743
745
|
const chunk = new Uint8Array(12 + bytes);
|
|
744
|
-
chunk.set(
|
|
746
|
+
chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
745
747
|
chunk.set(encodeData, 12);
|
|
746
748
|
return chunk;
|
|
747
749
|
}
|
|
750
|
+
const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
|
|
751
|
+
const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
|
|
752
|
+
fatal: true
|
|
753
|
+
});
|
|
754
|
+
const MAX_CHUNK_BYTES = 0xffffffff;
|
|
755
|
+
const RETAINED_STORE_BYTES = 64 * 1024;
|
|
756
|
+
const DONE = {
|
|
757
|
+
done: true,
|
|
758
|
+
value: undefined
|
|
759
|
+
};
|
|
760
|
+
function malformedStream() {
|
|
761
|
+
return new Error("Malformed server function stream.");
|
|
762
|
+
}
|
|
748
763
|
class ChunkReader {
|
|
749
764
|
constructor(stream) {
|
|
750
765
|
this.reader = stream.getReader();
|
|
751
766
|
this.store = new Uint8Array(0);
|
|
752
767
|
this.buffer = this.store;
|
|
753
768
|
this.done = false;
|
|
769
|
+
this.cancelled = false;
|
|
754
770
|
}
|
|
755
771
|
async readChunk() {
|
|
756
772
|
const chunk = await this.reader.read();
|
|
757
773
|
if (chunk.done) {
|
|
758
774
|
this.done = true;
|
|
759
|
-
return;
|
|
775
|
+
return this.cancelled;
|
|
760
776
|
}
|
|
761
777
|
const incoming = chunk.value;
|
|
762
778
|
const store = this.store;
|
|
@@ -777,55 +793,66 @@ class ChunkReader {
|
|
|
777
793
|
this.store = grown;
|
|
778
794
|
this.buffer = grown.subarray(0, needed);
|
|
779
795
|
}
|
|
796
|
+
return this.cancelled;
|
|
780
797
|
}
|
|
781
798
|
async next() {
|
|
799
|
+
if (this.cancelled) return DONE;
|
|
782
800
|
while (this.buffer.length < 12) {
|
|
783
801
|
if (this.done) {
|
|
784
|
-
if (this.buffer.length === 0) return
|
|
785
|
-
|
|
786
|
-
value: undefined
|
|
787
|
-
};
|
|
788
|
-
throw new Error("Malformed server function stream.");
|
|
802
|
+
if (this.buffer.length === 0) return DONE;
|
|
803
|
+
throw malformedStream();
|
|
789
804
|
}
|
|
790
|
-
await this.readChunk();
|
|
791
|
-
}
|
|
792
|
-
const decoder = new TextDecoder();
|
|
793
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
794
|
-
if (Number.isNaN(bytes)) {
|
|
795
|
-
throw new Error("Malformed server function stream.");
|
|
805
|
+
if (await this.readChunk()) return DONE;
|
|
796
806
|
}
|
|
807
|
+
const header = String.fromCharCode(...this.buffer.subarray(0, 12));
|
|
808
|
+
if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
|
|
809
|
+
const bytes = parseInt(header.slice(3, 11), 16);
|
|
797
810
|
while (bytes > this.buffer.length - 12) {
|
|
798
811
|
if (this.done) {
|
|
799
|
-
throw
|
|
812
|
+
throw malformedStream();
|
|
800
813
|
}
|
|
801
|
-
await this.readChunk();
|
|
814
|
+
if (await this.readChunk()) return DONE;
|
|
815
|
+
}
|
|
816
|
+
let partial;
|
|
817
|
+
try {
|
|
818
|
+
partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
|
|
819
|
+
} catch {
|
|
820
|
+
throw malformedStream();
|
|
802
821
|
}
|
|
803
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
804
822
|
this.buffer = this.buffer.subarray(12 + bytes);
|
|
823
|
+
if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
|
|
824
|
+
this.store = this.buffer = this.buffer.slice();
|
|
825
|
+
}
|
|
805
826
|
return {
|
|
806
827
|
done: false,
|
|
807
828
|
value: partial
|
|
808
829
|
};
|
|
809
830
|
}
|
|
810
831
|
async drain(interpret) {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
832
|
+
try {
|
|
833
|
+
while (true) {
|
|
834
|
+
const result = await this.next();
|
|
835
|
+
if (result.done) {
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
interpret(result.value);
|
|
815
839
|
}
|
|
816
|
-
|
|
840
|
+
} catch (error) {
|
|
841
|
+
this.cancel(error).catch(() => {});
|
|
842
|
+
throw error;
|
|
817
843
|
}
|
|
818
844
|
}
|
|
819
845
|
cancel(reason) {
|
|
846
|
+
this.cancelled = true;
|
|
820
847
|
return this.reader.cancel(reason);
|
|
821
848
|
}
|
|
822
849
|
}
|
|
823
850
|
function createEventChunk(data, id) {
|
|
824
851
|
let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
|
|
825
852
|
for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
|
|
826
|
-
return
|
|
853
|
+
return CHUNK_ENCODER.encode(event + "\n");
|
|
827
854
|
}
|
|
828
|
-
const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
|
|
855
|
+
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
829
856
|
function positionDigest(value) {
|
|
830
857
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
831
858
|
const text = JSON.stringify(value);
|
|
@@ -889,29 +916,36 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
889
916
|
throw new Error("missing body");
|
|
890
917
|
}
|
|
891
918
|
const reader = new ChunkReader(source.body);
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
if (result.
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const {
|
|
898
|
-
createJSONDeserializer
|
|
899
|
-
} = await import('@solidjs/web/serialization/decode');
|
|
900
|
-
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
901
|
-
function interpretChunk(chunk) {
|
|
902
|
-
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
903
|
-
throw errorFromTrailer(chunk);
|
|
919
|
+
try {
|
|
920
|
+
const result = await reader.next();
|
|
921
|
+
if (!result.done) {
|
|
922
|
+
if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
923
|
+
throw errorFromTrailer(result.value);
|
|
904
924
|
}
|
|
905
|
-
|
|
925
|
+
const {
|
|
926
|
+
createJSONDeserializer
|
|
927
|
+
} = await import('@solidjs/web/serialization/decode');
|
|
928
|
+
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
929
|
+
function interpretChunk(chunk) {
|
|
930
|
+
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
931
|
+
throw errorFromTrailer(chunk);
|
|
932
|
+
}
|
|
933
|
+
return deserializeChunk(JSON.parse(chunk));
|
|
934
|
+
}
|
|
935
|
+
const connection = wire && wire.connection;
|
|
936
|
+
let endConnection;
|
|
937
|
+
if (connection) ;
|
|
938
|
+
const end = error => {
|
|
939
|
+
const sweep = () => deserializeChunk.abort(error);
|
|
940
|
+
if (connection) ; else sweep();
|
|
941
|
+
};
|
|
942
|
+
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
943
|
+
return interpretChunk(result.value);
|
|
906
944
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
};
|
|
911
|
-
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
912
|
-
return interpretChunk(result.value);
|
|
945
|
+
} catch (error) {
|
|
946
|
+
reader.cancel(error).catch(() => {});
|
|
947
|
+
throw error;
|
|
913
948
|
}
|
|
914
|
-
return undefined;
|
|
915
949
|
}
|
|
916
950
|
async function deserializeString(text, codecOptions) {
|
|
917
951
|
return await deserializeStream(new Response(text), codecOptions);
|
|
@@ -1022,10 +1056,13 @@ function copyInitHeaders(init) {
|
|
|
1022
1056
|
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
1023
1057
|
return headers;
|
|
1024
1058
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1059
|
+
let stubGapFillExcluded;
|
|
1060
|
+
function isStubGapFillExcluded(key) {
|
|
1061
|
+
return (stubGapFillExcluded ||= new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
|
|
1062
|
+
...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()))).has(key);
|
|
1063
|
+
}
|
|
1027
1064
|
function fillsStubGap(key, headers, response) {
|
|
1028
|
-
if (key === "set-cookie" ||
|
|
1065
|
+
if (key === "set-cookie" || isStubGapFillExcluded(key)) return false;
|
|
1029
1066
|
if (response.body === null && (key === "content-type" || key === "content-length")) return false;
|
|
1030
1067
|
return !headers.has(key);
|
|
1031
1068
|
}
|