@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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OBSERVE,
|
|
2
|
-
import { reportServerError } from 'solid-js/internal';
|
|
1
|
+
import { OBSERVE, getOwner, DEV as DEV$1 } from 'solid-js';
|
|
2
|
+
import { sharedConfig, reportServerError } from 'solid-js/internal';
|
|
3
3
|
|
|
4
4
|
const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
|
|
5
5
|
function isHttpNavigationTarget(target) {
|
|
@@ -23,6 +23,15 @@ const REVALIDATE_HEADER = "X-Revalidate";
|
|
|
23
23
|
const RESPONSE_HEADER_VALUE_LIMIT = 4096;
|
|
24
24
|
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
25
25
|
|
|
26
|
+
const REQUEST_ERROR_HOOK = Symbol.for("solid-js/server/request-error-hook");
|
|
27
|
+
function hooks() {
|
|
28
|
+
const g = globalThis;
|
|
29
|
+
return g[REQUEST_ERROR_HOOK] || (g[REQUEST_ERROR_HOOK] = new WeakMap());
|
|
30
|
+
}
|
|
31
|
+
function requestErrorHook(event) {
|
|
32
|
+
return event === undefined ? undefined : hooks().get(event);
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
const PROVIDER = Symbol.for("solid-js/observe/server/provider");
|
|
27
36
|
function currentProvider() {
|
|
28
37
|
if (OBSERVE === undefined) return undefined;
|
|
@@ -384,7 +393,7 @@ function assertServableCookie(name, options) {
|
|
|
384
393
|
}
|
|
385
394
|
}
|
|
386
395
|
const FLASH_COOKIE = "flash";
|
|
387
|
-
const FLASH_MATCHER =
|
|
396
|
+
const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
|
|
388
397
|
function hasFlashCookie(cookieHeader) {
|
|
389
398
|
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
390
399
|
}
|
|
@@ -702,7 +711,7 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
702
711
|
const format = source.headers.get(BODY_FORMAT_HEADER);
|
|
703
712
|
switch (true) {
|
|
704
713
|
case format === BodyFormat.Serialized:
|
|
705
|
-
return await deserializeStream(source, codecOptions);
|
|
714
|
+
return await deserializeStream(source, codecOptions, wire);
|
|
706
715
|
case format === BodyFormat.Json:
|
|
707
716
|
return JSON.parse(await source.text());
|
|
708
717
|
case format === BodyFormat.String:
|
|
@@ -728,26 +737,42 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
728
737
|
return undefined;
|
|
729
738
|
}
|
|
730
739
|
function createChunk(data) {
|
|
731
|
-
const
|
|
732
|
-
const encodeData = encoder.encode(data);
|
|
740
|
+
const encodeData = CHUNK_ENCODER.encode(data);
|
|
733
741
|
const bytes = encodeData.length;
|
|
742
|
+
if (bytes > MAX_CHUNK_BYTES) {
|
|
743
|
+
throw new RangeError("Server function chunk is too large to frame.");
|
|
744
|
+
}
|
|
734
745
|
const chunk = new Uint8Array(12 + bytes);
|
|
735
|
-
chunk.set(
|
|
746
|
+
chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
736
747
|
chunk.set(encodeData, 12);
|
|
737
748
|
return chunk;
|
|
738
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
|
+
}
|
|
739
763
|
class ChunkReader {
|
|
740
764
|
constructor(stream) {
|
|
741
765
|
this.reader = stream.getReader();
|
|
742
766
|
this.store = new Uint8Array(0);
|
|
743
767
|
this.buffer = this.store;
|
|
744
768
|
this.done = false;
|
|
769
|
+
this.cancelled = false;
|
|
745
770
|
}
|
|
746
771
|
async readChunk() {
|
|
747
772
|
const chunk = await this.reader.read();
|
|
748
773
|
if (chunk.done) {
|
|
749
774
|
this.done = true;
|
|
750
|
-
return;
|
|
775
|
+
return this.cancelled;
|
|
751
776
|
}
|
|
752
777
|
const incoming = chunk.value;
|
|
753
778
|
const store = this.store;
|
|
@@ -768,55 +793,66 @@ class ChunkReader {
|
|
|
768
793
|
this.store = grown;
|
|
769
794
|
this.buffer = grown.subarray(0, needed);
|
|
770
795
|
}
|
|
796
|
+
return this.cancelled;
|
|
771
797
|
}
|
|
772
798
|
async next() {
|
|
799
|
+
if (this.cancelled) return DONE;
|
|
773
800
|
while (this.buffer.length < 12) {
|
|
774
801
|
if (this.done) {
|
|
775
|
-
if (this.buffer.length === 0) return
|
|
776
|
-
|
|
777
|
-
value: undefined
|
|
778
|
-
};
|
|
779
|
-
throw new Error("Malformed server function stream.");
|
|
802
|
+
if (this.buffer.length === 0) return DONE;
|
|
803
|
+
throw malformedStream();
|
|
780
804
|
}
|
|
781
|
-
await this.readChunk();
|
|
782
|
-
}
|
|
783
|
-
const decoder = new TextDecoder();
|
|
784
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
785
|
-
if (Number.isNaN(bytes)) {
|
|
786
|
-
throw new Error("Malformed server function stream.");
|
|
805
|
+
if (await this.readChunk()) return DONE;
|
|
787
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);
|
|
788
810
|
while (bytes > this.buffer.length - 12) {
|
|
789
811
|
if (this.done) {
|
|
790
|
-
throw
|
|
812
|
+
throw malformedStream();
|
|
791
813
|
}
|
|
792
|
-
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();
|
|
793
821
|
}
|
|
794
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
795
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
|
+
}
|
|
796
826
|
return {
|
|
797
827
|
done: false,
|
|
798
828
|
value: partial
|
|
799
829
|
};
|
|
800
830
|
}
|
|
801
831
|
async drain(interpret) {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
832
|
+
try {
|
|
833
|
+
while (true) {
|
|
834
|
+
const result = await this.next();
|
|
835
|
+
if (result.done) {
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
interpret(result.value);
|
|
806
839
|
}
|
|
807
|
-
|
|
840
|
+
} catch (error) {
|
|
841
|
+
this.cancel(error).catch(() => {});
|
|
842
|
+
throw error;
|
|
808
843
|
}
|
|
809
844
|
}
|
|
810
845
|
cancel(reason) {
|
|
846
|
+
this.cancelled = true;
|
|
811
847
|
return this.reader.cancel(reason);
|
|
812
848
|
}
|
|
813
849
|
}
|
|
814
850
|
function createEventChunk(data, id) {
|
|
815
851
|
let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
|
|
816
852
|
for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
|
|
817
|
-
return
|
|
853
|
+
return CHUNK_ENCODER.encode(event + "\n");
|
|
818
854
|
}
|
|
819
|
-
const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
|
|
855
|
+
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
820
856
|
function positionDigest(value) {
|
|
821
857
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
822
858
|
const text = JSON.stringify(value);
|
|
@@ -880,29 +916,36 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
880
916
|
throw new Error("missing body");
|
|
881
917
|
}
|
|
882
918
|
const reader = new ChunkReader(source.body);
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (result.
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
const {
|
|
889
|
-
createJSONDeserializer
|
|
890
|
-
} = await import('@solidjs/web/serialization/decode');
|
|
891
|
-
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
892
|
-
function interpretChunk(chunk) {
|
|
893
|
-
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
894
|
-
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);
|
|
895
924
|
}
|
|
896
|
-
|
|
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);
|
|
897
944
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
};
|
|
902
|
-
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
903
|
-
return interpretChunk(result.value);
|
|
945
|
+
} catch (error) {
|
|
946
|
+
reader.cancel(error).catch(() => {});
|
|
947
|
+
throw error;
|
|
904
948
|
}
|
|
905
|
-
return undefined;
|
|
906
949
|
}
|
|
907
950
|
async function deserializeString(text, codecOptions) {
|
|
908
951
|
return await deserializeStream(new Response(text), codecOptions);
|
|
@@ -940,7 +983,21 @@ function errorText(error) {
|
|
|
940
983
|
typeof setImmediate === "function" ? setImmediate : fn => setTimeout(fn, 0);
|
|
941
984
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
942
985
|
function getRequestEvent() {
|
|
943
|
-
|
|
986
|
+
const store = globalThis[RequestContext];
|
|
987
|
+
if (!store) return undefined;
|
|
988
|
+
const event = store.getStore();
|
|
989
|
+
if (event) return event;
|
|
990
|
+
const ctx = renderContextOf(getOwner());
|
|
991
|
+
return ctx && ctx.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.");
|
|
992
|
+
}
|
|
993
|
+
const RENDER_ROOTS = Symbol.for("@solidjs/web/render-roots");
|
|
994
|
+
function renderContextOf(owner) {
|
|
995
|
+
const roots = globalThis[RENDER_ROOTS];
|
|
996
|
+
if (!roots) return undefined;
|
|
997
|
+
for (; owner; owner = owner._parent) {
|
|
998
|
+
const context = roots.get(owner);
|
|
999
|
+
if (context) return context;
|
|
1000
|
+
}
|
|
944
1001
|
}
|
|
945
1002
|
function peekRequestEvent() {
|
|
946
1003
|
const store = globalThis[RequestContext];
|
|
@@ -999,10 +1056,13 @@ function copyInitHeaders(init) {
|
|
|
999
1056
|
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
1000
1057
|
return headers;
|
|
1001
1058
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
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
|
+
}
|
|
1004
1064
|
function fillsStubGap(key, headers, response) {
|
|
1005
|
-
if (key === "set-cookie" ||
|
|
1065
|
+
if (key === "set-cookie" || isStubGapFillExcluded(key)) return false;
|
|
1006
1066
|
if (response.body === null && (key === "content-type" || key === "content-length")) return false;
|
|
1007
1067
|
return !headers.has(key);
|
|
1008
1068
|
}
|
|
@@ -1564,6 +1624,7 @@ function createServerReference({
|
|
|
1564
1624
|
evt.serverOnly = true;
|
|
1565
1625
|
const scope = run => provideEvent(evt, run);
|
|
1566
1626
|
const wrap = resolveWrapInvocation(config.wrapInvocation);
|
|
1627
|
+
const hook = requestErrorHook(ogEvt);
|
|
1567
1628
|
let result = provideEventOnce(provideEvent, evt, () => {
|
|
1568
1629
|
const run = () => fn.apply(thisArg, args);
|
|
1569
1630
|
return observeInvocation({
|
|
@@ -1576,7 +1637,7 @@ function createServerReference({
|
|
|
1576
1637
|
args,
|
|
1577
1638
|
event: evt,
|
|
1578
1639
|
direct: true
|
|
1579
|
-
}) : run(), id));
|
|
1640
|
+
}) : run(), id, hook));
|
|
1580
1641
|
});
|
|
1581
1642
|
result = scopeDeferredResult(result, scope);
|
|
1582
1643
|
const transform = config.transformDirectResult;
|
|
@@ -2546,14 +2607,14 @@ function currentEvent() {
|
|
|
2546
2607
|
const store = globalThis[RequestContext];
|
|
2547
2608
|
return store ? store.getStore() : undefined;
|
|
2548
2609
|
}
|
|
2549
|
-
function reportDirectFailure(run, id) {
|
|
2610
|
+
function reportDirectFailure(run, id, hook) {
|
|
2550
2611
|
const report = error => {
|
|
2551
2612
|
reportServerError(error, {
|
|
2552
2613
|
kind: "server-function",
|
|
2553
2614
|
handling: "thrown",
|
|
2554
2615
|
functionId: id,
|
|
2555
2616
|
direct: true
|
|
2556
|
-
}, null);
|
|
2617
|
+
}, null, hook);
|
|
2557
2618
|
throw error;
|
|
2558
2619
|
};
|
|
2559
2620
|
let result;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { reportServerError } from 'solid-js/internal';
|
|
1
|
+
import { getOwner } from 'solid-js';
|
|
2
|
+
import { sharedConfig, reportServerError } from 'solid-js/internal';
|
|
3
3
|
|
|
4
4
|
const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
|
|
5
5
|
function isHttpNavigationTarget(target) {
|
|
@@ -23,6 +23,15 @@ const REVALIDATE_HEADER = "X-Revalidate";
|
|
|
23
23
|
const RESPONSE_HEADER_VALUE_LIMIT = 4096;
|
|
24
24
|
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
25
25
|
|
|
26
|
+
const REQUEST_ERROR_HOOK = Symbol.for("solid-js/server/request-error-hook");
|
|
27
|
+
function hooks() {
|
|
28
|
+
const g = globalThis;
|
|
29
|
+
return g[REQUEST_ERROR_HOOK] || (g[REQUEST_ERROR_HOOK] = new WeakMap());
|
|
30
|
+
}
|
|
31
|
+
function requestErrorHook(event) {
|
|
32
|
+
return event === undefined ? undefined : hooks().get(event);
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
|
|
27
36
|
const ZERO_TRACE = "00000000000000000000000000000000";
|
|
28
37
|
const ZERO_SPAN = "0000000000000000";
|
|
@@ -333,7 +342,7 @@ function serializeCookie(name, value, options = {}) {
|
|
|
333
342
|
return cookie;
|
|
334
343
|
}
|
|
335
344
|
const FLASH_COOKIE = "flash";
|
|
336
|
-
const FLASH_MATCHER =
|
|
345
|
+
const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
|
|
337
346
|
function hasFlashCookie(cookieHeader) {
|
|
338
347
|
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
339
348
|
}
|
|
@@ -651,7 +660,7 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
651
660
|
const format = source.headers.get(BODY_FORMAT_HEADER);
|
|
652
661
|
switch (true) {
|
|
653
662
|
case format === BodyFormat.Serialized:
|
|
654
|
-
return await deserializeStream(source, codecOptions);
|
|
663
|
+
return await deserializeStream(source, codecOptions, wire);
|
|
655
664
|
case format === BodyFormat.Json:
|
|
656
665
|
return JSON.parse(await source.text());
|
|
657
666
|
case format === BodyFormat.String:
|
|
@@ -677,26 +686,42 @@ async function extractBody(source, codecOptions, wire) {
|
|
|
677
686
|
return undefined;
|
|
678
687
|
}
|
|
679
688
|
function createChunk(data) {
|
|
680
|
-
const
|
|
681
|
-
const encodeData = encoder.encode(data);
|
|
689
|
+
const encodeData = CHUNK_ENCODER.encode(data);
|
|
682
690
|
const bytes = encodeData.length;
|
|
691
|
+
if (bytes > MAX_CHUNK_BYTES) {
|
|
692
|
+
throw new RangeError("Server function chunk is too large to frame.");
|
|
693
|
+
}
|
|
683
694
|
const chunk = new Uint8Array(12 + bytes);
|
|
684
|
-
chunk.set(
|
|
695
|
+
chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
685
696
|
chunk.set(encodeData, 12);
|
|
686
697
|
return chunk;
|
|
687
698
|
}
|
|
699
|
+
const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
|
|
700
|
+
const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
|
|
701
|
+
fatal: true
|
|
702
|
+
});
|
|
703
|
+
const MAX_CHUNK_BYTES = 0xffffffff;
|
|
704
|
+
const RETAINED_STORE_BYTES = 64 * 1024;
|
|
705
|
+
const DONE = {
|
|
706
|
+
done: true,
|
|
707
|
+
value: undefined
|
|
708
|
+
};
|
|
709
|
+
function malformedStream() {
|
|
710
|
+
return new Error("Malformed server function stream.");
|
|
711
|
+
}
|
|
688
712
|
class ChunkReader {
|
|
689
713
|
constructor(stream) {
|
|
690
714
|
this.reader = stream.getReader();
|
|
691
715
|
this.store = new Uint8Array(0);
|
|
692
716
|
this.buffer = this.store;
|
|
693
717
|
this.done = false;
|
|
718
|
+
this.cancelled = false;
|
|
694
719
|
}
|
|
695
720
|
async readChunk() {
|
|
696
721
|
const chunk = await this.reader.read();
|
|
697
722
|
if (chunk.done) {
|
|
698
723
|
this.done = true;
|
|
699
|
-
return;
|
|
724
|
+
return this.cancelled;
|
|
700
725
|
}
|
|
701
726
|
const incoming = chunk.value;
|
|
702
727
|
const store = this.store;
|
|
@@ -717,55 +742,66 @@ class ChunkReader {
|
|
|
717
742
|
this.store = grown;
|
|
718
743
|
this.buffer = grown.subarray(0, needed);
|
|
719
744
|
}
|
|
745
|
+
return this.cancelled;
|
|
720
746
|
}
|
|
721
747
|
async next() {
|
|
748
|
+
if (this.cancelled) return DONE;
|
|
722
749
|
while (this.buffer.length < 12) {
|
|
723
750
|
if (this.done) {
|
|
724
|
-
if (this.buffer.length === 0) return
|
|
725
|
-
|
|
726
|
-
value: undefined
|
|
727
|
-
};
|
|
728
|
-
throw new Error("Malformed server function stream.");
|
|
751
|
+
if (this.buffer.length === 0) return DONE;
|
|
752
|
+
throw malformedStream();
|
|
729
753
|
}
|
|
730
|
-
await this.readChunk();
|
|
731
|
-
}
|
|
732
|
-
const decoder = new TextDecoder();
|
|
733
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
734
|
-
if (Number.isNaN(bytes)) {
|
|
735
|
-
throw new Error("Malformed server function stream.");
|
|
754
|
+
if (await this.readChunk()) return DONE;
|
|
736
755
|
}
|
|
756
|
+
const header = String.fromCharCode(...this.buffer.subarray(0, 12));
|
|
757
|
+
if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
|
|
758
|
+
const bytes = parseInt(header.slice(3, 11), 16);
|
|
737
759
|
while (bytes > this.buffer.length - 12) {
|
|
738
760
|
if (this.done) {
|
|
739
|
-
throw
|
|
761
|
+
throw malformedStream();
|
|
740
762
|
}
|
|
741
|
-
await this.readChunk();
|
|
763
|
+
if (await this.readChunk()) return DONE;
|
|
764
|
+
}
|
|
765
|
+
let partial;
|
|
766
|
+
try {
|
|
767
|
+
partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
|
|
768
|
+
} catch {
|
|
769
|
+
throw malformedStream();
|
|
742
770
|
}
|
|
743
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
744
771
|
this.buffer = this.buffer.subarray(12 + bytes);
|
|
772
|
+
if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
|
|
773
|
+
this.store = this.buffer = this.buffer.slice();
|
|
774
|
+
}
|
|
745
775
|
return {
|
|
746
776
|
done: false,
|
|
747
777
|
value: partial
|
|
748
778
|
};
|
|
749
779
|
}
|
|
750
780
|
async drain(interpret) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
781
|
+
try {
|
|
782
|
+
while (true) {
|
|
783
|
+
const result = await this.next();
|
|
784
|
+
if (result.done) {
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
interpret(result.value);
|
|
755
788
|
}
|
|
756
|
-
|
|
789
|
+
} catch (error) {
|
|
790
|
+
this.cancel(error).catch(() => {});
|
|
791
|
+
throw error;
|
|
757
792
|
}
|
|
758
793
|
}
|
|
759
794
|
cancel(reason) {
|
|
795
|
+
this.cancelled = true;
|
|
760
796
|
return this.reader.cancel(reason);
|
|
761
797
|
}
|
|
762
798
|
}
|
|
763
799
|
function createEventChunk(data, id) {
|
|
764
800
|
let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
|
|
765
801
|
for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
|
|
766
|
-
return
|
|
802
|
+
return CHUNK_ENCODER.encode(event + "\n");
|
|
767
803
|
}
|
|
768
|
-
const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
|
|
804
|
+
const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
|
|
769
805
|
function positionDigest(value) {
|
|
770
806
|
if (value === undefined || !isJSONSafe(value)) return undefined;
|
|
771
807
|
const text = JSON.stringify(value);
|
|
@@ -829,29 +865,36 @@ async function deserializeStream(source, codecOptions, wire) {
|
|
|
829
865
|
throw new Error("missing body");
|
|
830
866
|
}
|
|
831
867
|
const reader = new ChunkReader(source.body);
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
if (result.
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
const {
|
|
838
|
-
createJSONDeserializer
|
|
839
|
-
} = await import('@solidjs/web/serialization/decode');
|
|
840
|
-
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
841
|
-
function interpretChunk(chunk) {
|
|
842
|
-
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
843
|
-
throw errorFromTrailer(chunk);
|
|
868
|
+
try {
|
|
869
|
+
const result = await reader.next();
|
|
870
|
+
if (!result.done) {
|
|
871
|
+
if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
872
|
+
throw errorFromTrailer(result.value);
|
|
844
873
|
}
|
|
845
|
-
|
|
874
|
+
const {
|
|
875
|
+
createJSONDeserializer
|
|
876
|
+
} = await import('@solidjs/web/serialization/decode');
|
|
877
|
+
const deserializeChunk = createJSONDeserializer(codecOptions);
|
|
878
|
+
function interpretChunk(chunk) {
|
|
879
|
+
if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
|
|
880
|
+
throw errorFromTrailer(chunk);
|
|
881
|
+
}
|
|
882
|
+
return deserializeChunk(JSON.parse(chunk));
|
|
883
|
+
}
|
|
884
|
+
const connection = wire && wire.connection;
|
|
885
|
+
let endConnection;
|
|
886
|
+
if (connection) ;
|
|
887
|
+
const end = error => {
|
|
888
|
+
const sweep = () => deserializeChunk.abort(error);
|
|
889
|
+
if (connection) ; else sweep();
|
|
890
|
+
};
|
|
891
|
+
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
892
|
+
return interpretChunk(result.value);
|
|
846
893
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
};
|
|
851
|
-
reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
|
|
852
|
-
return interpretChunk(result.value);
|
|
894
|
+
} catch (error) {
|
|
895
|
+
reader.cancel(error).catch(() => {});
|
|
896
|
+
throw error;
|
|
853
897
|
}
|
|
854
|
-
return undefined;
|
|
855
898
|
}
|
|
856
899
|
async function deserializeString(text, codecOptions) {
|
|
857
900
|
return await deserializeStream(new Response(text), codecOptions);
|
|
@@ -876,7 +919,21 @@ async function decodeResponsePayload(response, codecOptions) {
|
|
|
876
919
|
typeof setImmediate === "function" ? setImmediate : fn => setTimeout(fn, 0);
|
|
877
920
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
878
921
|
function getRequestEvent() {
|
|
879
|
-
|
|
922
|
+
const store = globalThis[RequestContext];
|
|
923
|
+
if (!store) return undefined;
|
|
924
|
+
const event = store.getStore();
|
|
925
|
+
if (event) return event;
|
|
926
|
+
const ctx = renderContextOf(getOwner());
|
|
927
|
+
return ctx && ctx.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.");
|
|
928
|
+
}
|
|
929
|
+
const RENDER_ROOTS = Symbol.for("@solidjs/web/render-roots");
|
|
930
|
+
function renderContextOf(owner) {
|
|
931
|
+
const roots = globalThis[RENDER_ROOTS];
|
|
932
|
+
if (!roots) return undefined;
|
|
933
|
+
for (; owner; owner = owner._parent) {
|
|
934
|
+
const context = roots.get(owner);
|
|
935
|
+
if (context) return context;
|
|
936
|
+
}
|
|
880
937
|
}
|
|
881
938
|
function peekRequestEvent() {
|
|
882
939
|
const store = globalThis[RequestContext];
|
|
@@ -925,10 +982,13 @@ function copyInitHeaders(init) {
|
|
|
925
982
|
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
926
983
|
return headers;
|
|
927
984
|
}
|
|
928
|
-
|
|
929
|
-
|
|
985
|
+
let stubGapFillExcluded;
|
|
986
|
+
function isStubGapFillExcluded(key) {
|
|
987
|
+
return (stubGapFillExcluded ||= new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
|
|
988
|
+
...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()))).has(key);
|
|
989
|
+
}
|
|
930
990
|
function fillsStubGap(key, headers, response) {
|
|
931
|
-
if (key === "set-cookie" ||
|
|
991
|
+
if (key === "set-cookie" || isStubGapFillExcluded(key)) return false;
|
|
932
992
|
if (response.body === null && (key === "content-type" || key === "content-length")) return false;
|
|
933
993
|
return !headers.has(key);
|
|
934
994
|
}
|
|
@@ -1482,6 +1542,7 @@ function createServerReference({
|
|
|
1482
1542
|
evt.serverOnly = true;
|
|
1483
1543
|
const scope = run => provideEvent(evt, run);
|
|
1484
1544
|
const wrap = resolveWrapInvocation(config.wrapInvocation);
|
|
1545
|
+
const hook = requestErrorHook(ogEvt);
|
|
1485
1546
|
let result = provideEventOnce(provideEvent, evt, () => {
|
|
1486
1547
|
const run = () => fn.apply(thisArg, args);
|
|
1487
1548
|
return observeInvocation({
|
|
@@ -1494,7 +1555,7 @@ function createServerReference({
|
|
|
1494
1555
|
args,
|
|
1495
1556
|
event: evt,
|
|
1496
1557
|
direct: true
|
|
1497
|
-
}) : run(), id));
|
|
1558
|
+
}) : run(), id, hook));
|
|
1498
1559
|
});
|
|
1499
1560
|
result = scopeDeferredResult(result, scope);
|
|
1500
1561
|
const transform = config.transformDirectResult;
|
|
@@ -2464,14 +2525,14 @@ function currentEvent() {
|
|
|
2464
2525
|
const store = globalThis[RequestContext];
|
|
2465
2526
|
return store ? store.getStore() : undefined;
|
|
2466
2527
|
}
|
|
2467
|
-
function reportDirectFailure(run, id) {
|
|
2528
|
+
function reportDirectFailure(run, id, hook) {
|
|
2468
2529
|
const report = error => {
|
|
2469
2530
|
reportServerError(error, {
|
|
2470
2531
|
kind: "server-function",
|
|
2471
2532
|
handling: "thrown",
|
|
2472
2533
|
functionId: id,
|
|
2473
2534
|
direct: true
|
|
2474
|
-
}, null);
|
|
2535
|
+
}, null, hook);
|
|
2475
2536
|
throw error;
|
|
2476
2537
|
};
|
|
2477
2538
|
let result;
|