@solidjs/web 2.0.0-beta.25 → 2.0.0-beta.27
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/dev.cjs +14 -9
- package/dist/dev.js +14 -10
- package/dist/server.cjs +41 -78
- package/dist/server.js +42 -80
- package/dist/web.cjs +14 -9
- package/dist/web.js +14 -10
- package/frames/dist/client.cjs +180 -224
- package/frames/dist/client.dev.cjs +1456 -0
- package/frames/dist/client.dev.js +1444 -0
- package/frames/dist/client.js +181 -225
- package/frames/dist/server.cjs +139 -123
- package/frames/dist/server.js +139 -123
- package/package.json +24 -4
- package/serialization/dist/serialization.cjs +6 -3
- package/serialization/dist/serialization.js +6 -3
- package/serialization/types/index.d.ts +7 -1
- package/serialization/types-cjs/index.d.cts +7 -1
- package/server-functions/dist/client.cjs +18 -5
- package/server-functions/dist/client.js +16 -6
- package/server-functions/dist/server.cjs +164 -8
- package/server-functions/dist/server.js +158 -9
- package/types/client.d.ts +3 -3
- package/types/frames/client.d.ts +1 -1
- package/types/frames/frame-client.d.ts +34 -28
- package/types/frames/serializer.d.ts +7 -1
- package/types/jsx.d.ts +1 -1
- package/types/response.d.ts +10 -0
- package/types/serializer.d.ts +7 -1
- package/types/server-functions/client.d.ts +3 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/server.d.ts +79 -4
- package/types/server-functions/shared.d.ts +35 -0
- package/types-cjs/client.d.cts +3 -3
- package/types-cjs/frames/client.d.cts +1 -1
- package/types-cjs/frames/frame-client.d.cts +34 -28
- package/types-cjs/frames/serializer.d.cts +7 -1
- package/types-cjs/jsx.d.cts +1 -1
- package/types-cjs/response.d.cts +10 -0
- package/types-cjs/serializer.d.cts +7 -1
- package/types-cjs/server-functions/client.d.cts +3 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/server.d.cts +79 -4
- package/types-cjs/server-functions/shared.d.cts +35 -0
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var seroval = require('seroval');
|
|
4
4
|
var web = require('seroval-plugins/web');
|
|
5
5
|
|
|
6
|
+
const REVALIDATE_HEADER = "X-Revalidate";
|
|
7
|
+
|
|
6
8
|
seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
7
9
|
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
8
10
|
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
@@ -98,6 +100,14 @@ const INSTANCE_HEADER = "X-Server-Function-Instance";
|
|
|
98
100
|
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
99
101
|
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
100
102
|
const FILE_FORM_KEY = "__server_function_file__";
|
|
103
|
+
const FLASH_COOKIE = "flash";
|
|
104
|
+
const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
|
|
105
|
+
function hasFlashCookie(cookieHeader) {
|
|
106
|
+
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
107
|
+
}
|
|
108
|
+
function clearFlashCookie() {
|
|
109
|
+
return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
|
|
110
|
+
}
|
|
101
111
|
const BodyFormat = {
|
|
102
112
|
Serialized: "0",
|
|
103
113
|
String: "1",
|
|
@@ -219,15 +229,15 @@ class ChunkReader {
|
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
231
|
async next() {
|
|
222
|
-
|
|
232
|
+
while (this.buffer.length < 12) {
|
|
223
233
|
if (this.done) {
|
|
224
|
-
return {
|
|
234
|
+
if (this.buffer.length === 0) return {
|
|
225
235
|
done: true,
|
|
226
236
|
value: undefined
|
|
227
237
|
};
|
|
238
|
+
throw new Error("Malformed server function stream.");
|
|
228
239
|
}
|
|
229
240
|
await this.readChunk();
|
|
230
|
-
return await this.next();
|
|
231
241
|
}
|
|
232
242
|
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
233
243
|
const bytes = Number.parseInt(head, 16);
|
|
@@ -403,13 +413,13 @@ async function fetchServerFunction(base, id, options, args, meta) {
|
|
|
403
413
|
await consumer(payload.data, {
|
|
404
414
|
response
|
|
405
415
|
});
|
|
406
|
-
if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(
|
|
416
|
+
if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
|
|
407
417
|
throw payload.value;
|
|
408
418
|
}
|
|
409
419
|
return payload.value;
|
|
410
420
|
}
|
|
411
421
|
}
|
|
412
|
-
if (response.headers.has("Location") || response.headers.has(
|
|
422
|
+
if (response.headers.has("Location") || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER)) {
|
|
413
423
|
return response;
|
|
414
424
|
}
|
|
415
425
|
const result = await decodeResponse(response.clone());
|
|
@@ -487,16 +497,19 @@ function registerServerReference() {
|
|
|
487
497
|
}
|
|
488
498
|
|
|
489
499
|
exports.ERROR_HEADER = ERROR_HEADER;
|
|
500
|
+
exports.FLASH_COOKIE = FLASH_COOKIE;
|
|
490
501
|
exports.FUNCTION_HEADER = FUNCTION_HEADER;
|
|
491
502
|
exports.GET = GET;
|
|
492
503
|
exports.INSTANCE_HEADER = INSTANCE_HEADER;
|
|
493
504
|
exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
|
|
505
|
+
exports.clearFlashCookie = clearFlashCookie;
|
|
494
506
|
exports.configureServerFunctionsClient = configureServerFunctionsClient;
|
|
495
507
|
exports.createServerReference = createServerReference;
|
|
496
508
|
exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
|
|
497
509
|
exports.decodeResponse = decodeResponse;
|
|
498
510
|
exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
|
|
499
511
|
exports.getServerFunctionMetadata = getServerFunctionMetadata;
|
|
512
|
+
exports.hasFlashCookie = hasFlashCookie;
|
|
500
513
|
exports.isServerFunction = isServerFunction;
|
|
501
514
|
exports.registerServerReference = registerServerReference;
|
|
502
515
|
exports.subscribeFlightData = subscribeFlightData;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { fromCrossJSON, Feature } from 'seroval';
|
|
2
2
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
3
3
|
|
|
4
|
+
const REVALIDATE_HEADER = "X-Revalidate";
|
|
5
|
+
|
|
4
6
|
Feature.AggregateError | Feature.BigIntTypedArray;
|
|
5
7
|
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
6
8
|
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
@@ -96,6 +98,14 @@ const INSTANCE_HEADER = "X-Server-Function-Instance";
|
|
|
96
98
|
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
97
99
|
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
98
100
|
const FILE_FORM_KEY = "__server_function_file__";
|
|
101
|
+
const FLASH_COOKIE = "flash";
|
|
102
|
+
const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
|
|
103
|
+
function hasFlashCookie(cookieHeader) {
|
|
104
|
+
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
105
|
+
}
|
|
106
|
+
function clearFlashCookie() {
|
|
107
|
+
return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
|
|
108
|
+
}
|
|
99
109
|
const BodyFormat = {
|
|
100
110
|
Serialized: "0",
|
|
101
111
|
String: "1",
|
|
@@ -217,15 +227,15 @@ class ChunkReader {
|
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
async next() {
|
|
220
|
-
|
|
230
|
+
while (this.buffer.length < 12) {
|
|
221
231
|
if (this.done) {
|
|
222
|
-
return {
|
|
232
|
+
if (this.buffer.length === 0) return {
|
|
223
233
|
done: true,
|
|
224
234
|
value: undefined
|
|
225
235
|
};
|
|
236
|
+
throw new Error("Malformed server function stream.");
|
|
226
237
|
}
|
|
227
238
|
await this.readChunk();
|
|
228
|
-
return await this.next();
|
|
229
239
|
}
|
|
230
240
|
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
231
241
|
const bytes = Number.parseInt(head, 16);
|
|
@@ -401,13 +411,13 @@ async function fetchServerFunction(base, id, options, args, meta) {
|
|
|
401
411
|
await consumer(payload.data, {
|
|
402
412
|
response
|
|
403
413
|
});
|
|
404
|
-
if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(
|
|
414
|
+
if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
|
|
405
415
|
throw payload.value;
|
|
406
416
|
}
|
|
407
417
|
return payload.value;
|
|
408
418
|
}
|
|
409
419
|
}
|
|
410
|
-
if (response.headers.has("Location") || response.headers.has(
|
|
420
|
+
if (response.headers.has("Location") || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER)) {
|
|
411
421
|
return response;
|
|
412
422
|
}
|
|
413
423
|
const result = await decodeResponse(response.clone());
|
|
@@ -484,4 +494,4 @@ function registerServerReference() {
|
|
|
484
494
|
throw new Error("registerServerReference must not be called in the client build");
|
|
485
495
|
}
|
|
486
496
|
|
|
487
|
-
export { ERROR_HEADER, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, configureServerFunctionsClient, createServerReference, decodeErrorHeaderValue, decodeResponse, encodeErrorHeaderValue, getServerFunctionMetadata, isServerFunction, registerServerReference, subscribeFlightData, withMeta };
|
|
497
|
+
export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createServerReference, decodeErrorHeaderValue, decodeResponse, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, isServerFunction, registerServerReference, subscribeFlightData, withMeta };
|
|
@@ -10,6 +10,7 @@ function isResponseEnvelope(value) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
13
|
+
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
|
|
13
14
|
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
14
15
|
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
15
16
|
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
|
|
@@ -35,11 +36,13 @@ function serializeJSON(value, {
|
|
|
35
36
|
onError,
|
|
36
37
|
...codecOptions
|
|
37
38
|
}) {
|
|
39
|
+
const resolved = resolveCodecOptions(codecOptions);
|
|
38
40
|
return seroval.toCrossJSONStream(value, {
|
|
39
41
|
onParse,
|
|
40
42
|
onDone,
|
|
41
43
|
onError,
|
|
42
|
-
...
|
|
44
|
+
...resolved,
|
|
45
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
function createJSONDeserializer(options) {
|
|
@@ -117,6 +120,18 @@ const INSTANCE_HEADER = "X-Server-Function-Instance";
|
|
|
117
120
|
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
118
121
|
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
119
122
|
const FILE_FORM_KEY = "__server_function_file__";
|
|
123
|
+
const FLASH_COOKIE = "flash";
|
|
124
|
+
const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
|
|
125
|
+
function hasFlashCookie(cookieHeader) {
|
|
126
|
+
return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
|
|
127
|
+
}
|
|
128
|
+
function matchFlashCookie(cookieHeader) {
|
|
129
|
+
const match = cookieHeader && cookieHeader.match(FLASH_MATCHER);
|
|
130
|
+
return match ? match[1] : undefined;
|
|
131
|
+
}
|
|
132
|
+
function clearFlashCookie() {
|
|
133
|
+
return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
|
|
134
|
+
}
|
|
120
135
|
const BodyFormat = {
|
|
121
136
|
Serialized: "0",
|
|
122
137
|
String: "1",
|
|
@@ -249,15 +264,15 @@ class ChunkReader {
|
|
|
249
264
|
}
|
|
250
265
|
}
|
|
251
266
|
async next() {
|
|
252
|
-
|
|
267
|
+
while (this.buffer.length < 12) {
|
|
253
268
|
if (this.done) {
|
|
254
|
-
return {
|
|
269
|
+
if (this.buffer.length === 0) return {
|
|
255
270
|
done: true,
|
|
256
271
|
value: undefined
|
|
257
272
|
};
|
|
273
|
+
throw new Error("Malformed server function stream.");
|
|
258
274
|
}
|
|
259
275
|
await this.readChunk();
|
|
260
|
-
return await this.next();
|
|
261
276
|
}
|
|
262
277
|
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
263
278
|
const bytes = Number.parseInt(head, 16);
|
|
@@ -329,11 +344,61 @@ async function decodeResponse(response, codecOptions) {
|
|
|
329
344
|
return await extractBody(response, codecOptions === undefined ? codecConfig.codec : codecOptions);
|
|
330
345
|
}
|
|
331
346
|
|
|
347
|
+
function encodeInputValue(value) {
|
|
348
|
+
if (value instanceof FormData) return {
|
|
349
|
+
$f: [...value.entries()].filter(([, v]) => typeof v === "string")
|
|
350
|
+
};
|
|
351
|
+
if (value instanceof URLSearchParams) return {
|
|
352
|
+
$u: [...value.entries()]
|
|
353
|
+
};
|
|
354
|
+
return value;
|
|
355
|
+
}
|
|
356
|
+
function decodeInputValue(value) {
|
|
357
|
+
if (value && typeof value === "object") {
|
|
358
|
+
if (Array.isArray(value.$f)) {
|
|
359
|
+
const form = new FormData();
|
|
360
|
+
for (const [k, v] of value.$f) form.append(k, v);
|
|
361
|
+
return form;
|
|
362
|
+
}
|
|
363
|
+
if (Array.isArray(value.$u)) return new URLSearchParams(value.$u);
|
|
364
|
+
}
|
|
365
|
+
return value;
|
|
366
|
+
}
|
|
367
|
+
function encodeFlashCookie(url, result, input, thrown) {
|
|
368
|
+
const isError = result instanceof Error;
|
|
369
|
+
const payload = {
|
|
370
|
+
url,
|
|
371
|
+
result: isError ? result.message : result,
|
|
372
|
+
error: isError,
|
|
373
|
+
thrown: !!thrown,
|
|
374
|
+
input: input.map(encodeInputValue)
|
|
375
|
+
};
|
|
376
|
+
return `${FLASH_COOKIE}=${encodeURIComponent(JSON.stringify(payload))}; Secure; HttpOnly; Path=/`;
|
|
377
|
+
}
|
|
378
|
+
function decodeFlashCookie(cookieHeader) {
|
|
379
|
+
const match = matchFlashCookie(cookieHeader);
|
|
380
|
+
if (!match) return;
|
|
381
|
+
try {
|
|
382
|
+
const payload = JSON.parse(decodeURIComponent(match));
|
|
383
|
+
if (!payload || !payload.result) return;
|
|
384
|
+
const result = payload.error ? new Error(payload.result) : payload.result;
|
|
385
|
+
return {
|
|
386
|
+
input: Array.isArray(payload.input) ? payload.input.map(decodeInputValue) : [],
|
|
387
|
+
url: payload.url,
|
|
388
|
+
result: payload.thrown ? undefined : result,
|
|
389
|
+
error: payload.thrown ? result : undefined
|
|
390
|
+
};
|
|
391
|
+
} catch (error) {
|
|
392
|
+
console.error(error);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
332
396
|
const config = {
|
|
333
397
|
provideEvent: undefined,
|
|
334
398
|
collectFlightData: undefined,
|
|
335
399
|
transformResult: undefined,
|
|
336
400
|
transformDirectResult: undefined,
|
|
401
|
+
handleNoJS: undefined,
|
|
337
402
|
endpoint: "/_server"
|
|
338
403
|
};
|
|
339
404
|
function configureServerFunctionsServer({
|
|
@@ -341,6 +406,7 @@ function configureServerFunctionsServer({
|
|
|
341
406
|
collectFlightData,
|
|
342
407
|
transformResult,
|
|
343
408
|
transformDirectResult,
|
|
409
|
+
handleNoJS,
|
|
344
410
|
endpoint,
|
|
345
411
|
codec
|
|
346
412
|
} = {}) {
|
|
@@ -348,6 +414,7 @@ function configureServerFunctionsServer({
|
|
|
348
414
|
if (collectFlightData !== undefined) config.collectFlightData = collectFlightData;
|
|
349
415
|
if (transformResult !== undefined) config.transformResult = transformResult;
|
|
350
416
|
if (transformDirectResult !== undefined) config.transformDirectResult = transformDirectResult;
|
|
417
|
+
if (handleNoJS !== undefined) config.handleNoJS = handleNoJS;
|
|
351
418
|
if (endpoint !== undefined) config.endpoint = endpoint;
|
|
352
419
|
if (codec !== undefined) configureServerFunctionsCodec(codec);
|
|
353
420
|
}
|
|
@@ -473,6 +540,87 @@ async function foldFlightData(hook, event, headers, outcome) {
|
|
|
473
540
|
data
|
|
474
541
|
};
|
|
475
542
|
}
|
|
543
|
+
function parseSetCookie(setCookie) {
|
|
544
|
+
const [pair, ...attributes] = setCookie.split(";");
|
|
545
|
+
const eq = pair.indexOf("=");
|
|
546
|
+
if (eq < 0) return undefined;
|
|
547
|
+
const parsed = {
|
|
548
|
+
name: pair.slice(0, eq).trim(),
|
|
549
|
+
value: pair.slice(eq + 1).trim()
|
|
550
|
+
};
|
|
551
|
+
for (const attribute of attributes) {
|
|
552
|
+
const attrEq = attribute.indexOf("=");
|
|
553
|
+
const key = (attrEq < 0 ? attribute : attribute.slice(0, attrEq)).trim().toLowerCase();
|
|
554
|
+
const value = attrEq < 0 ? "" : attribute.slice(attrEq + 1).trim();
|
|
555
|
+
if (key === "max-age") parsed.maxAge = Number(value);else if (key === "expires") parsed.expires = new Date(value);
|
|
556
|
+
}
|
|
557
|
+
return parsed;
|
|
558
|
+
}
|
|
559
|
+
function foldSetCookies(headers, setCookies) {
|
|
560
|
+
const folded = new Headers(headers);
|
|
561
|
+
if (!setCookies.length) return folded;
|
|
562
|
+
const cookies = {};
|
|
563
|
+
for (const pair of folded.get("cookie")?.split(";") ?? []) {
|
|
564
|
+
const eq = pair.indexOf("=");
|
|
565
|
+
if (eq > -1) cookies[pair.slice(0, eq).trim()] = pair.slice(eq + 1).trim();
|
|
566
|
+
}
|
|
567
|
+
for (const setCookie of setCookies) {
|
|
568
|
+
const parsed = parseSetCookie(setCookie);
|
|
569
|
+
if (!parsed) continue;
|
|
570
|
+
if (parsed.maxAge != null && parsed.maxAge <= 0 || parsed.expires != null && parsed.expires.getTime() <= Date.now()) {
|
|
571
|
+
delete cookies[parsed.name];
|
|
572
|
+
} else {
|
|
573
|
+
cookies[parsed.name] = parsed.value;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
folded.delete("cookie");
|
|
577
|
+
const serialized = Object.entries(cookies).map(([name, value]) => `${name}=${value}`).join("; ");
|
|
578
|
+
if (serialized) folded.set("cookie", serialized);
|
|
579
|
+
return folded;
|
|
580
|
+
}
|
|
581
|
+
const validRedirectStatuses = new Set([301, 302, 303, 307, 308]);
|
|
582
|
+
function createNoJSHandler({
|
|
583
|
+
base = ""
|
|
584
|
+
} = {}) {
|
|
585
|
+
return function handleNoJS(result, request, args, thrown) {
|
|
586
|
+
const url = new URL(request.url);
|
|
587
|
+
let back = new URL(base || "/", url.origin).toString();
|
|
588
|
+
try {
|
|
589
|
+
const referer = request.headers.get("referer");
|
|
590
|
+
if (referer) back = new URL(referer).toString();
|
|
591
|
+
} catch {}
|
|
592
|
+
let status = 303;
|
|
593
|
+
let headers;
|
|
594
|
+
if (result instanceof Response) {
|
|
595
|
+
headers = new Headers(result.headers);
|
|
596
|
+
if (result.headers.has("Location")) {
|
|
597
|
+
headers.set("Location", new URL(result.headers.get("Location"), url.origin + base).toString());
|
|
598
|
+
if (validRedirectStatuses.has(result.status)) status = result.status;
|
|
599
|
+
} else {
|
|
600
|
+
headers.set("Location", back);
|
|
601
|
+
}
|
|
602
|
+
headers.delete("Content-Type");
|
|
603
|
+
headers.delete("Content-Length");
|
|
604
|
+
} else {
|
|
605
|
+
headers = new Headers({
|
|
606
|
+
Location: back
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (result && !(result instanceof Response)) {
|
|
610
|
+
headers.append("Set-Cookie", encodeFlashCookie(url.pathname + url.search, result, args, thrown));
|
|
611
|
+
}
|
|
612
|
+
return new Response(null, {
|
|
613
|
+
status,
|
|
614
|
+
headers
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
let defaultNoJSHandler;
|
|
619
|
+
function isFormPost(request) {
|
|
620
|
+
if (request.method !== "POST" || request.headers.has(BODY_FORMAT_HEADER)) return false;
|
|
621
|
+
const type = request.headers.get("content-type") || "";
|
|
622
|
+
return type.startsWith("application/x-www-form-urlencoded") || type.startsWith("multipart/form-data");
|
|
623
|
+
}
|
|
476
624
|
function serializedResponse(value, headers, codec) {
|
|
477
625
|
headers.set(BODY_FORMAT_HEADER, BodyFormat.Serialized);
|
|
478
626
|
headers.set("Content-Type", "text/plain");
|
|
@@ -530,6 +678,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
530
678
|
const provide = options.provideEvent || provideEvent;
|
|
531
679
|
const flightHook = options.collectFlightData !== undefined ? options.collectFlightData : config.collectFlightData;
|
|
532
680
|
const transformResult = options.transformResult !== undefined ? options.transformResult : config.transformResult;
|
|
681
|
+
const handleNoJS = options.handleNoJS !== undefined ? options.handleNoJS : config.handleNoJS !== undefined ? config.handleNoJS : isFormPost(request) ? defaultNoJSHandler || (defaultNoJSHandler = createNoJSHandler()) : undefined;
|
|
533
682
|
const collectsFlight = !!(flightHook && instance && request.headers.has(SINGLE_FLIGHT_HEADER));
|
|
534
683
|
const parsed = await parseArguments(request, url, instance, codec);
|
|
535
684
|
const headers = new Headers();
|
|
@@ -553,7 +702,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
553
702
|
response,
|
|
554
703
|
value
|
|
555
704
|
} = result;
|
|
556
|
-
if (!instance && !
|
|
705
|
+
if (!instance && !handleNoJS && response && response.body) {
|
|
557
706
|
return response;
|
|
558
707
|
}
|
|
559
708
|
if (response && response.headers) {
|
|
@@ -589,7 +738,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
589
738
|
});
|
|
590
739
|
}
|
|
591
740
|
if (!instance) {
|
|
592
|
-
if (
|
|
741
|
+
if (handleNoJS) return handleNoJS(result, request, parsed);
|
|
593
742
|
if (result instanceof Response) return result;
|
|
594
743
|
return encodeResult(result, headers, 200, codec);
|
|
595
744
|
}
|
|
@@ -641,13 +790,13 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
641
790
|
}
|
|
642
791
|
headers.set(ERROR_HEADER, "true");
|
|
643
792
|
if (!instance) {
|
|
644
|
-
if (
|
|
793
|
+
if (handleNoJS) return handleNoJS(x ?? metadata, request, parsed, true);
|
|
645
794
|
if (x instanceof Response) return x;
|
|
646
795
|
}
|
|
647
796
|
return encodeResult(x, headers, status, codec);
|
|
648
797
|
}
|
|
649
798
|
if (!instance) {
|
|
650
|
-
if (
|
|
799
|
+
if (handleNoJS) return handleNoJS(x, request, parsed, true);
|
|
651
800
|
const message = x instanceof Error ? x.message : String(x);
|
|
652
801
|
return new Response(process.env.NODE_ENV === "development" ? message : null, {
|
|
653
802
|
status: 500
|
|
@@ -660,19 +809,26 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
660
809
|
}
|
|
661
810
|
|
|
662
811
|
exports.ERROR_HEADER = ERROR_HEADER;
|
|
812
|
+
exports.FLASH_COOKIE = FLASH_COOKIE;
|
|
663
813
|
exports.FUNCTION_HEADER = FUNCTION_HEADER;
|
|
664
814
|
exports.GET = GET;
|
|
665
815
|
exports.INSTANCE_HEADER = INSTANCE_HEADER;
|
|
666
816
|
exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
|
|
817
|
+
exports.clearFlashCookie = clearFlashCookie;
|
|
667
818
|
exports.configureServerFunctionsServer = configureServerFunctionsServer;
|
|
819
|
+
exports.createNoJSHandler = createNoJSHandler;
|
|
668
820
|
exports.createServerReference = createServerReference;
|
|
669
821
|
exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
|
|
822
|
+
exports.decodeFlashCookie = decodeFlashCookie;
|
|
670
823
|
exports.decodeResponse = decodeResponse;
|
|
671
824
|
exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
|
|
825
|
+
exports.encodeFlashCookie = encodeFlashCookie;
|
|
826
|
+
exports.foldSetCookies = foldSetCookies;
|
|
672
827
|
exports.getServerFunction = getServerFunction;
|
|
673
828
|
exports.getServerFunctionMeta = getServerFunctionMeta;
|
|
674
829
|
exports.getServerFunctionMetadata = getServerFunctionMetadata;
|
|
675
830
|
exports.handleServerFunctionRequest = handleServerFunctionRequest;
|
|
831
|
+
exports.hasFlashCookie = hasFlashCookie;
|
|
676
832
|
exports.isServerFunction = isServerFunction;
|
|
677
833
|
exports.registerServerFunction = registerServerFunction;
|
|
678
834
|
exports.registerServerReference = registerServerReference;
|