@solidjs/web 2.0.0-rc.7 → 2.0.0-rc.9
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 +638 -124
- package/dist/server.js +445 -94
- package/dist/{server.dev.cjs → server.observe.js} +602 -416
- package/dist/web.dev.js +229 -49
- package/dist/web.js +194 -46
- package/dist/{web.cjs → web.observe.js} +290 -275
- package/frames/dist/client.dev.js +103 -4
- package/frames/dist/client.js +5 -2
- package/frames/dist/{client.dev.cjs → client.observe.js} +139 -79
- package/frames/dist/server.dev.js +540 -79
- package/frames/dist/server.js +371 -52
- package/frames/dist/{server.cjs → server.observe.js} +544 -140
- package/frames/package.json +15 -21
- package/package.json +145 -294
- package/serialization/decode/package.json +3 -9
- package/serialization/package.json +3 -9
- package/serialization/types/serializer-decode.d.ts +49 -2
- package/server-functions/dist/{client.cjs → client.dev.js} +140 -107
- package/server-functions/dist/client.js +74 -69
- package/server-functions/dist/client.observe.js +1102 -0
- package/server-functions/dist/server.dev.js +430 -41
- package/server-functions/dist/server.js +367 -40
- package/server-functions/dist/{server.cjs → server.observe.js} +430 -85
- package/server-functions/package.json +15 -21
- package/server-functions/rich-args/package.json +3 -9
- package/storage/package.json +3 -9
- package/types/client.d.ts +39 -1
- package/types/diagnostics.d.ts +24 -0
- package/types/frames/frame-transport.d.ts +1 -1
- package/types/frames/serializer-decode.d.ts +49 -2
- package/types/index.d.ts +25 -15
- package/types/index.server.d.ts +35 -8
- package/types/jsx.d.ts +15 -4
- package/types/observe.d.ts +294 -0
- package/types/response.d.ts +18 -0
- package/types/serializer-decode.d.ts +49 -2
- package/types/server-functions/client.d.ts +32 -22
- package/types/server-functions/server.d.ts +55 -41
- package/types/server-functions/shared.d.ts +39 -9
- package/types/server-mock.d.ts +26 -4
- package/types/server-observe.d.ts +39 -0
- package/types/server.d.ts +105 -6
- package/types/trace.d.ts +79 -0
- package/dist/server.cjs +0 -3708
- package/dist/web.dev.cjs +0 -2285
- package/frames/dist/client.cjs +0 -2043
- package/frames/dist/server.dev.cjs +0 -4584
- package/serialization/dist/decode.cjs +0 -155
- package/serialization/dist/serialization.cjs +0 -275
- package/serialization/types-cjs/index.d.cts +0 -101
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -172
- package/serialization/types-cjs/serializer.d.cts +0 -101
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.dev.cjs +0 -2409
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types-cjs/client.d.cts +0 -197
- package/types-cjs/constants.d.cts +0 -20
- package/types-cjs/cookies.d.cts +0 -41
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -370
- package/types-cjs/frames/frame-container-plugin.d.cts +0 -71
- package/types-cjs/frames/frame-sink.d.cts +0 -92
- package/types-cjs/frames/frame-transport.d.cts +0 -189
- package/types-cjs/frames/serializer-decode.d.cts +0 -172
- package/types-cjs/frames/serializer.d.cts +0 -101
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/head.d.cts +0 -19
- package/types-cjs/index.d.cts +0 -191
- package/types-cjs/index.server.d.cts +0 -147
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4146
- package/types-cjs/package.json +0 -3
- package/types-cjs/reconcile.d.cts +0 -1
- package/types-cjs/render.d.cts +0 -6
- package/types-cjs/response.d.cts +0 -81
- package/types-cjs/serializer-decode.d.cts +0 -172
- package/types-cjs/serializer.d.cts +0 -101
- package/types-cjs/server-functions/client.d.cts +0 -184
- package/types-cjs/server-functions/flash.d.cts +0 -36
- package/types-cjs/server-functions/registry.d.cts +0 -100
- package/types-cjs/server-functions/rich-args.d.cts +0 -1
- package/types-cjs/server-functions/server.d.cts +0 -546
- package/types-cjs/server-functions/shared.d.cts +0 -283
- package/types-cjs/server-mock.d.cts +0 -337
- package/types-cjs/server.d.cts +0 -408
|
@@ -164,6 +164,40 @@ function parseServerFunctionAddress(pathname, endpoint) {
|
|
|
164
164
|
return null;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
const MAX_GET_URL_LENGTH = 2000;
|
|
168
|
+
function urlTargetId(target, helper) {
|
|
169
|
+
if (typeof target === "string") return target;
|
|
170
|
+
if (isServerFunction(target) && typeof target.id === "string") return target.id;
|
|
171
|
+
throw new Error(`${helper} expects a server function reference (or its id).`);
|
|
172
|
+
}
|
|
173
|
+
function serverFunctionActionUrlFor(endpoint, target, boundArgs) {
|
|
174
|
+
const address = serverFunctionAddress(endpoint, urlTargetId(target, "serverFunctionActionUrl"));
|
|
175
|
+
if (!boundArgs.length) return address;
|
|
176
|
+
if (!isJSONSafe(boundArgs)) {
|
|
177
|
+
throw new Error("Bound arguments in an action url must be JSON-safe: the server reads them the way it " + "reads a form post's, and that convention has no codec. Pass the value through the " + "function's body, or call the reference instead of rendering a url for it.");
|
|
178
|
+
}
|
|
179
|
+
return `${address}?args=${encodeURIComponent(JSON.stringify(boundArgs))}`;
|
|
180
|
+
}
|
|
181
|
+
function serverFunctionUrlFor(endpoint, fn, args) {
|
|
182
|
+
if (!isServerFunction(fn) || typeof fn.id !== "string") {
|
|
183
|
+
throw new Error("serverFunctionUrl expects a server function reference.");
|
|
184
|
+
}
|
|
185
|
+
const metadata = getServerFunctionMetadata(fn);
|
|
186
|
+
if (!metadata || metadata.method !== "GET") {
|
|
187
|
+
throw new Error(`serverFunctionUrl: "${fn.id}" is not a declared read. A call over the default ` + "transport is a POST — its arguments travel in the body, so no url describes it. " + "Declare the function with GET(fn) for a cacheable read that has a url, or start " + 'the call itself: invoke(fn, { priority: "low" }, ...args).');
|
|
188
|
+
}
|
|
189
|
+
const address = serverFunctionDataAddress(endpoint, fn.id);
|
|
190
|
+
if (!args.length) return address;
|
|
191
|
+
if (!isJSONSafe(args)) {
|
|
192
|
+
throw new Error("Arguments in a server function url must be JSON-safe: the transport encodes anything " + "else through the codec asynchronously, and a url rendered as a value cannot wait for " + "it. Pass JSON-safe arguments, or call the reference instead of rendering a url for it.");
|
|
193
|
+
}
|
|
194
|
+
const url = `${address}?args=${encodeURIComponent(JSON.stringify(args))}`;
|
|
195
|
+
const length = new URL(url, globalThis.location?.href || "http://localhost").href.length;
|
|
196
|
+
if (length > MAX_GET_URL_LENGTH) {
|
|
197
|
+
throw new Error(`serverFunctionUrl: the url for "${fn.id}" with these arguments is ${length} characters; ` + `past ${MAX_GET_URL_LENGTH} the call dispatches over POST (a cache miss rather than a ` + "414), so no url describes it. Shorten the arguments, or call the reference instead.");
|
|
198
|
+
}
|
|
199
|
+
return url;
|
|
200
|
+
}
|
|
167
201
|
const ERROR_HEADER = "X-Server-Function-Error";
|
|
168
202
|
const ERROR_HEADER_MARKER = "=?1?";
|
|
169
203
|
const NEEDS_ENCODING = /[^\x20-\x7e\xa0-\xff]/;
|
|
@@ -189,7 +223,6 @@ function decodeErrorHeaderValue(value) {
|
|
|
189
223
|
return value;
|
|
190
224
|
}
|
|
191
225
|
}
|
|
192
|
-
const INSTANCE_HEADER = "X-Server-Function-Instance";
|
|
193
226
|
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
194
227
|
const UNKNOWN_HEADER = "X-Server-Function-Unknown";
|
|
195
228
|
const REDIRECT_HEADER = "X-Server-Function-Redirect";
|
|
@@ -522,39 +555,13 @@ const config = {
|
|
|
522
555
|
responseHandler: undefined,
|
|
523
556
|
serializeArgs: undefined
|
|
524
557
|
};
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (CALL_OBSERVERS.size === 0) return;
|
|
528
|
-
const field = type === "request" ? "request" : "response";
|
|
529
|
-
const time = performance.now();
|
|
530
|
-
for (const observer of new Set(CALL_OBSERVERS)) {
|
|
531
|
-
try {
|
|
532
|
-
observer({
|
|
533
|
-
type,
|
|
534
|
-
id,
|
|
535
|
-
instance,
|
|
536
|
-
[field]: value.clone(),
|
|
537
|
-
meta,
|
|
538
|
-
time
|
|
539
|
-
});
|
|
540
|
-
} catch (error) {
|
|
541
|
-
console.error(error);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
558
|
+
function serverFunctionUrl(fn, ...args) {
|
|
559
|
+
return serverFunctionUrlFor(config.endpoint, fn, args);
|
|
544
560
|
}
|
|
545
|
-
function
|
|
546
|
-
|
|
547
|
-
return () => CALL_OBSERVERS.delete(observer);
|
|
561
|
+
function serverFunctionActionUrl(fn, ...boundArgs) {
|
|
562
|
+
return serverFunctionActionUrlFor(config.endpoint, fn, boundArgs);
|
|
548
563
|
}
|
|
549
|
-
function
|
|
550
|
-
const address = serverFunctionAddress(config.endpoint, id);
|
|
551
|
-
if (!boundArgs || !boundArgs.length) return address;
|
|
552
|
-
if (!isJSONSafe(boundArgs)) {
|
|
553
|
-
throw new Error("Bound arguments in an action url must be JSON-safe: the server reads them the way it " + "reads a form post's, and that convention has no codec. Pass the value through the " + "function's body, or call the reference instead of rendering a url for it.");
|
|
554
|
-
}
|
|
555
|
-
return `${address}?args=${encodeURIComponent(JSON.stringify(boundArgs))}`;
|
|
556
|
-
}
|
|
557
|
-
function parseServerFunctionUrl(url) {
|
|
564
|
+
function parseServerFunctionActionUrl(url) {
|
|
558
565
|
const parsed = parseServerFunctionAddress(new URL(url, globalThis.location?.href || "http://localhost").pathname, config.endpoint);
|
|
559
566
|
return parsed && parsed.id;
|
|
560
567
|
}
|
|
@@ -579,8 +586,6 @@ function configureServerFunctionsClient({
|
|
|
579
586
|
if (responseHandler !== undefined) config.responseHandler = responseHandler;
|
|
580
587
|
if (serializeArgs !== undefined) config.serializeArgs = serializeArgs;
|
|
581
588
|
}
|
|
582
|
-
let INSTANCE = 0;
|
|
583
|
-
const MAX_GET_URL_LENGTH = 2000;
|
|
584
589
|
let rpcProvided = false;
|
|
585
590
|
function provideRPC() {
|
|
586
591
|
if (rpcProvided) return;
|
|
@@ -617,13 +622,15 @@ function parseRetryAfter(header) {
|
|
|
617
622
|
if (!Number.isNaN(date)) return Math.max(0, Math.ceil((date - Date.now()) / 1000));
|
|
618
623
|
return undefined;
|
|
619
624
|
}
|
|
620
|
-
|
|
625
|
+
function isReadCall(options) {
|
|
626
|
+
return !!options.read || !!options.method && options.method.toUpperCase() === "GET";
|
|
627
|
+
}
|
|
628
|
+
async function createRequest(base, id, options, meta) {
|
|
621
629
|
const headers = {
|
|
622
|
-
...options.headers
|
|
623
|
-
[INSTANCE_HEADER]: instance
|
|
630
|
+
...options.headers
|
|
624
631
|
};
|
|
625
632
|
const flightSources = getFlightDataSourceIds();
|
|
626
|
-
if (flightSources.length > 0 && !
|
|
633
|
+
if (flightSources.length > 0 && !isReadCall(options)) {
|
|
627
634
|
headers[SINGLE_FLIGHT_HEADER] = flightSources.join(",");
|
|
628
635
|
}
|
|
629
636
|
let init = {
|
|
@@ -640,31 +647,23 @@ async function createRequest(base, id, instance, options, meta) {
|
|
|
640
647
|
if (typeof prepared !== "object") {
|
|
641
648
|
throw new Error("prepareRequest must return (or mutate and return) the RequestInit it received; " + `it returned a ${typeof prepared}. Spread the init: ` + "init => ({ ...init, headers: { ...init.headers, ... } })");
|
|
642
649
|
}
|
|
643
|
-
if (
|
|
644
|
-
throw new Error(
|
|
650
|
+
if (typeof prepared.method !== "string" || prepared.method.toUpperCase() !== init.method.toUpperCase()) {
|
|
651
|
+
throw new Error(`prepareRequest returned an init without the transport's ${init.method} method, ` + "which would send the call without its payload or protocol. Spread the init it " + "received: init => ({ ...init, headers: { ...init.headers, ... } })");
|
|
645
652
|
}
|
|
646
653
|
}
|
|
647
654
|
init = prepared || init;
|
|
648
655
|
}
|
|
649
656
|
const send = config.fetch || fetch;
|
|
650
|
-
|
|
651
|
-
const request = new Request(new URL(base, globalThis.location?.href || "http://localhost"), {
|
|
652
|
-
...init,
|
|
653
|
-
body: init.body instanceof ReadableStream ? undefined : init.body
|
|
654
|
-
});
|
|
655
|
-
notifyCallObservers("request", id, instance, request, meta);
|
|
656
|
-
const response = await send(base, init);
|
|
657
|
-
notifyCallObservers("response", id, instance, response, meta);
|
|
658
|
-
return response;
|
|
657
|
+
return send(base, init);
|
|
659
658
|
}
|
|
660
|
-
async function initializeResponse(base, id,
|
|
659
|
+
async function initializeResponse(base, id, options, args, meta) {
|
|
661
660
|
if (args.length === 0) {
|
|
662
|
-
return createRequest(base, id,
|
|
661
|
+
return createRequest(base, id, options, meta);
|
|
663
662
|
}
|
|
664
663
|
if (args.length === 1) {
|
|
665
664
|
const result = getHeadersAndBody(args[0]);
|
|
666
665
|
if (result) {
|
|
667
|
-
return createRequest(base, id,
|
|
666
|
+
return createRequest(base, id, {
|
|
668
667
|
...options,
|
|
669
668
|
body: result.body,
|
|
670
669
|
headers: {
|
|
@@ -676,7 +675,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
|
|
|
676
675
|
}
|
|
677
676
|
try {
|
|
678
677
|
if (isJSONSafe(args)) {
|
|
679
|
-
return createRequest(base, id,
|
|
678
|
+
return createRequest(base, id, {
|
|
680
679
|
...options,
|
|
681
680
|
body: JSON.stringify(args),
|
|
682
681
|
headers: {
|
|
@@ -694,7 +693,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
|
|
|
694
693
|
const leading = args.slice(0, -1).map(arg => arg === undefined ? null : arg);
|
|
695
694
|
if (trailing && isJSONSafe(leading)) {
|
|
696
695
|
const target = base + (base.includes("?") ? "&" : "?") + "args=" + encodeURIComponent(JSON.stringify(leading));
|
|
697
|
-
return createRequest(target, id,
|
|
696
|
+
return createRequest(target, id, {
|
|
698
697
|
...options,
|
|
699
698
|
body: trailing.body,
|
|
700
699
|
headers: {
|
|
@@ -706,7 +705,7 @@ async function initializeResponse(base, id, instance, options, args, meta) {
|
|
|
706
705
|
} catch {
|
|
707
706
|
}
|
|
708
707
|
}
|
|
709
|
-
return createRequest(base, id,
|
|
708
|
+
return createRequest(base, id, {
|
|
710
709
|
...options,
|
|
711
710
|
body: await serializeArguments(args),
|
|
712
711
|
headers: {
|
|
@@ -716,8 +715,8 @@ async function initializeResponse(base, id, instance, options, args, meta) {
|
|
|
716
715
|
}
|
|
717
716
|
}, meta);
|
|
718
717
|
}
|
|
719
|
-
|
|
720
|
-
|
|
718
|
+
const fetchServerFunction = dispatchServerFunction;
|
|
719
|
+
async function dispatchServerFunction(base, id, options, args, meta, callArgs = args, observation) {
|
|
721
720
|
const handler = config.responseHandler;
|
|
722
721
|
const context = handler && handler.capture ? handler.capture({
|
|
723
722
|
id,
|
|
@@ -728,7 +727,7 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
728
727
|
...options,
|
|
729
728
|
signal: controller.signal
|
|
730
729
|
};
|
|
731
|
-
const response = await initializeResponse(base, id,
|
|
730
|
+
const response = await initializeResponse(base, id, options, args, meta);
|
|
732
731
|
if (handler) {
|
|
733
732
|
const handled = handler.handle(response, {
|
|
734
733
|
id,
|
|
@@ -742,20 +741,26 @@ async function fetchServerFunction(base, id, options, args, meta, callArgs = arg
|
|
|
742
741
|
throw serverFunctionFailure(response, undefined);
|
|
743
742
|
}
|
|
744
743
|
const failed = response.headers.has(ERROR_HEADER);
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
744
|
+
const registered = isReadCall(options) ? [] : getFlightDataSourceIds();
|
|
745
|
+
if (registered.length > 0) {
|
|
746
|
+
const folded = response.headers.has(SINGLE_FLIGHT_HEADER) ? response.headers.get(SINGLE_FLIGHT_HEADER).split(",") : [];
|
|
747
|
+
const metadata = response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
|
|
748
|
+
if (metadata || folded.length > 0) {
|
|
749
|
+
const decoded = response.body ? await extractBody(response, getServerFunctionsCodec()) : undefined;
|
|
750
|
+
const enveloped = folded.length > 0 && decoded !== undefined;
|
|
751
|
+
const value = enveloped ? decoded.value : decoded;
|
|
752
|
+
const data = enveloped ? decoded.data : undefined;
|
|
753
|
+
for (const source of registered) {
|
|
754
|
+
if (!metadata && !folded.includes(source)) continue;
|
|
755
|
+
const consumer = getFlightDataConsumer(source);
|
|
756
|
+
if (consumer) await consumer(data ? data[source] : undefined, {
|
|
752
757
|
response
|
|
753
758
|
});
|
|
754
759
|
}
|
|
755
|
-
if (failed && !
|
|
756
|
-
throw serverFunctionFailure(response,
|
|
760
|
+
if (failed && !metadata) {
|
|
761
|
+
throw serverFunctionFailure(response, value);
|
|
757
762
|
}
|
|
758
|
-
return
|
|
763
|
+
return value;
|
|
759
764
|
}
|
|
760
765
|
}
|
|
761
766
|
if (response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER) || response.status >= 300 && response.status < 400 && response.status !== 304) {
|
|
@@ -1028,4 +1033,4 @@ function getServerFunctionInvocation() {
|
|
|
1028
1033
|
return undefined;
|
|
1029
1034
|
}
|
|
1030
1035
|
|
|
1031
|
-
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, GET,
|
|
1036
|
+
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, GET, REDIRECT_HEADER, REVALIDATE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, clearFlashCookie, configureServerFunctionsClient, createChunk, createServerReference, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getFlightDataSourceIds, getServerFunctionInvocation, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, invoke, isServerFunction, live, parseServerFunctionActionUrl, registerServerReference, serializeString, serverFunctionActionUrl, serverFunctionUrl, subscribeFlightData, withMeta };
|