elysia 2.0.0-exp.0 → 2.0.0-exp.10
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/_virtual/_rolldown/runtime.js +0 -2
- package/dist/adapter/bun/index.d.ts +1 -1
- package/dist/adapter/bun/index.js +10 -2
- package/dist/adapter/bun/index.mjs +10 -2
- package/dist/adapter/bun/router.js +2 -2
- package/dist/adapter/bun/router.mjs +2 -2
- package/dist/adapter/constants.d.ts +1 -1
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/utils.d.ts +2 -5
- package/dist/adapter/utils.js +89 -84
- package/dist/adapter/utils.mjs +88 -83
- package/dist/adapter/web-standard/handler.js +6 -3
- package/dist/adapter/web-standard/handler.mjs +6 -3
- package/dist/adapter/web-standard/index.d.ts +1 -1
- package/dist/base.d.ts +11 -28
- package/dist/base.js +87 -65
- package/dist/base.mjs +89 -67
- package/dist/compile/aot.d.ts +65 -28
- package/dist/compile/aot.js +45 -37
- package/dist/compile/aot.mjs +44 -38
- package/dist/compile/handler/index.d.ts +5 -3
- package/dist/compile/handler/index.js +99 -457
- package/dist/compile/handler/index.mjs +100 -459
- package/dist/compile/handler/jit.d.ts +35 -0
- package/dist/compile/handler/jit.js +445 -0
- package/dist/compile/handler/jit.mjs +443 -0
- package/dist/compile/handler/params.js +3 -2
- package/dist/compile/handler/params.mjs +4 -3
- package/dist/compile/handler/reconstruct.d.ts +13 -0
- package/dist/compile/handler/reconstruct.js +29 -0
- package/dist/compile/handler/reconstruct.mjs +28 -0
- package/dist/compile/handler/utils.d.ts +2 -1
- package/dist/compile/handler/utils.js +12 -6
- package/dist/compile/handler/utils.mjs +12 -7
- package/dist/compile/index.d.ts +2 -2
- package/dist/compile/index.js +2 -1
- package/dist/compile/index.mjs +2 -2
- package/dist/compile/jit-probe.d.ts +19 -0
- package/dist/compile/jit-probe.js +38 -0
- package/dist/compile/jit-probe.mjs +36 -0
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +9 -1
- package/dist/compile/utils.mjs +8 -1
- package/dist/cookie/config.js +7 -6
- package/dist/cookie/config.mjs +7 -6
- package/dist/cookie/cookie.js +1 -3
- package/dist/cookie/cookie.mjs +1 -3
- package/dist/cookie/index.d.ts +2 -1
- package/dist/cookie/index.js +2 -1
- package/dist/cookie/index.mjs +2 -1
- package/dist/cookie/serialize.d.ts +6 -0
- package/dist/cookie/serialize.js +28 -0
- package/dist/cookie/serialize.mjs +27 -0
- package/dist/cookie/utils.d.ts +1 -2
- package/dist/cookie/utils.js +7 -26
- package/dist/cookie/utils.mjs +10 -28
- package/dist/error.d.ts +5 -8
- package/dist/error.js +26 -19
- package/dist/error.mjs +26 -19
- package/dist/handler/error.js +4 -4
- package/dist/handler/error.mjs +5 -5
- package/dist/handler/fetch.js +58 -17
- package/dist/handler/fetch.mjs +59 -18
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -10
- package/dist/index.mjs +4 -4
- package/dist/parse-query.js +1 -1
- package/dist/parse-query.mjs +1 -1
- package/dist/plugin/bun.js +37 -4
- package/dist/plugin/bun.mjs +37 -5
- package/dist/plugin/core.d.ts +69 -2
- package/dist/plugin/core.js +90 -10
- package/dist/plugin/core.mjs +90 -12
- package/dist/plugin/esbuild.js +36 -4
- package/dist/plugin/esbuild.mjs +37 -5
- package/dist/plugin/source.d.ts +38 -1
- package/dist/plugin/source.js +131 -12
- package/dist/plugin/source.mjs +129 -13
- package/dist/plugin/treeshake.d.ts +10 -0
- package/dist/plugin/treeshake.js +63 -0
- package/dist/plugin/treeshake.mjs +61 -0
- package/dist/plugin/vite.js +22 -2
- package/dist/plugin/vite.mjs +23 -3
- package/dist/sucrose.js +23 -10
- package/dist/sucrose.mjs +23 -10
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +5 -7
- package/dist/trace.mjs +5 -7
- package/dist/type/bridge.d.ts +4 -7
- package/dist/type/bridge.js +0 -10
- package/dist/type/bridge.mjs +1 -9
- package/dist/type/coerce.d.ts +19 -1
- package/dist/type/coerce.js +148 -4
- package/dist/type/coerce.mjs +147 -6
- package/dist/type/compat.js +8 -7
- package/dist/type/compat.mjs +9 -8
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/array-buffer.js +4 -4
- package/dist/type/elysia/array-buffer.mjs +4 -4
- package/dist/type/elysia/array-string.d.ts +2 -2
- package/dist/type/elysia/array-string.js +5 -5
- package/dist/type/elysia/array-string.mjs +6 -6
- package/dist/type/elysia/array.js +11 -8
- package/dist/type/elysia/array.mjs +11 -8
- package/dist/type/elysia/boolean-string.d.ts +1 -1
- package/dist/type/elysia/boolean-string.js +5 -6
- package/dist/type/elysia/boolean-string.mjs +5 -6
- package/dist/type/elysia/boolean.js +2 -2
- package/dist/type/elysia/boolean.mjs +2 -2
- package/dist/type/elysia/cookie.js +1 -4
- package/dist/type/elysia/cookie.mjs +1 -4
- package/dist/type/elysia/date.js +17 -10
- package/dist/type/elysia/date.mjs +17 -10
- package/dist/type/elysia/file-type.js +1 -1
- package/dist/type/elysia/file-type.mjs +1 -1
- package/dist/type/elysia/file.js +4 -4
- package/dist/type/elysia/file.mjs +4 -4
- package/dist/type/elysia/files.js +4 -4
- package/dist/type/elysia/files.mjs +4 -4
- package/dist/type/elysia/form.js +3 -3
- package/dist/type/elysia/form.mjs +4 -4
- package/dist/type/elysia/integer-string.js +8 -7
- package/dist/type/elysia/integer-string.mjs +9 -8
- package/dist/type/elysia/integer.js +2 -2
- package/dist/type/elysia/integer.mjs +2 -2
- package/dist/type/elysia/maybe-empty.d.ts +3 -2
- package/dist/type/elysia/maybe-empty.js +4 -4
- package/dist/type/elysia/maybe-empty.mjs +4 -4
- package/dist/type/elysia/nullable.d.ts +3 -2
- package/dist/type/elysia/nullable.js +3 -3
- package/dist/type/elysia/nullable.mjs +3 -3
- package/dist/type/elysia/number.js +2 -2
- package/dist/type/elysia/number.mjs +2 -2
- package/dist/type/elysia/numeric-enum.js +4 -3
- package/dist/type/elysia/numeric-enum.mjs +4 -3
- package/dist/type/elysia/numeric.js +7 -6
- package/dist/type/elysia/numeric.mjs +7 -6
- package/dist/type/elysia/object-string.d.ts +2 -2
- package/dist/type/elysia/object-string.js +5 -5
- package/dist/type/elysia/object-string.mjs +6 -6
- package/dist/type/elysia/object.js +12 -9
- package/dist/type/elysia/object.mjs +12 -9
- package/dist/type/elysia/optional.js +12 -5
- package/dist/type/elysia/optional.mjs +12 -5
- package/dist/type/elysia/string.js +2 -2
- package/dist/type/elysia/string.mjs +2 -2
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +2 -2
- package/dist/type/elysia/union-enum.d.ts +3 -2
- package/dist/type/elysia/union-enum.js +2 -2
- package/dist/type/elysia/union-enum.mjs +2 -2
- package/dist/type/elysia/utils.js +4 -8
- package/dist/type/elysia/utils.mjs +4 -8
- package/dist/type/exports.js +2071 -39
- package/dist/type/exports.mjs +307 -17
- package/dist/type/index.d.ts +3 -3
- package/dist/type/index.js +4 -31
- package/dist/type/index.mjs +4 -26
- package/dist/type/types.d.ts +1 -1
- package/dist/type/utils.js +4 -4
- package/dist/type/utils.mjs +4 -4
- package/dist/type/validator/custom-error.d.ts +10 -0
- package/dist/type/validator/custom-error.js +113 -0
- package/dist/type/validator/custom-error.mjs +110 -0
- package/dist/type/validator/default-precompute.d.ts +22 -0
- package/dist/type/validator/default-precompute.js +476 -0
- package/dist/type/validator/default-precompute.mjs +465 -0
- package/dist/type/validator/frozen-check.d.ts +11 -0
- package/dist/type/validator/frozen-check.js +19 -0
- package/dist/type/validator/frozen-check.mjs +18 -0
- package/dist/type/{validator.d.ts → validator/index.d.ts} +7 -20
- package/dist/type/validator/index.js +572 -0
- package/dist/type/validator/index.mjs +567 -0
- package/dist/type/validator/string-codec-aot.d.ts +9 -0
- package/dist/type/validator/string-codec-aot.js +106 -0
- package/dist/type/validator/string-codec-aot.mjs +102 -0
- package/dist/type/validator/validator-cache.d.ts +21 -0
- package/dist/type/validator/validator-cache.js +163 -0
- package/dist/type/validator/validator-cache.mjs +161 -0
- package/dist/types.d.ts +21 -3
- package/dist/universal/file.js +6 -5
- package/dist/universal/file.mjs +6 -5
- package/dist/utils.d.ts +8 -1
- package/dist/utils.js +88 -52
- package/dist/utils.mjs +88 -53
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +13 -6
- package/dist/validator/index.mjs +13 -6
- package/dist/validator/route.js +9 -9
- package/dist/validator/route.mjs +9 -9
- package/dist/ws/context.js +4 -7
- package/dist/ws/context.mjs +4 -7
- package/dist/ws/parser.js +6 -1
- package/dist/ws/parser.mjs +6 -1
- package/dist/ws/route.js +48 -27
- package/dist/ws/route.mjs +48 -27
- package/package.json +14 -5
- package/dist/type/validator.js +0 -603
- package/dist/type/validator.mjs +0 -599
|
@@ -32,7 +32,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
32
|
}
|
|
33
33
|
return to;
|
|
34
34
|
};
|
|
35
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
35
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
36
|
value: mod,
|
|
38
37
|
enumerable: true
|
|
@@ -41,5 +40,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
41
40
|
//#endregion
|
|
42
41
|
|
|
43
42
|
exports.__exportAll = __exportAll;
|
|
44
|
-
exports.__reExport = __reExport;
|
|
45
43
|
exports.__toESM = __toESM;
|
|
@@ -6,7 +6,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
6
6
|
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
|
|
7
7
|
declare const BunAdapter: {
|
|
8
8
|
parse: {
|
|
9
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
9
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
10
10
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
11
|
text: (context: Context) => MaybePromise<string>;
|
|
12
12
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
@@ -35,9 +35,17 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
35
35
|
name: "bun",
|
|
36
36
|
runtime: "bun",
|
|
37
37
|
listen(app, options, callback) {
|
|
38
|
-
const
|
|
38
|
+
const _config = app["~config"]?.serve;
|
|
39
|
+
const _options = typeof options === "object" ? options : {
|
|
40
|
+
port: +options,
|
|
41
|
+
fetch: (request, server) => app.fetch(request, server)
|
|
42
|
+
};
|
|
43
|
+
const serve = _config ? {
|
|
44
|
+
..._config,
|
|
45
|
+
..._options
|
|
46
|
+
} : _options;
|
|
39
47
|
const hasWs = app["~hasWS"];
|
|
40
|
-
serve.fetch = (request, server) => app.fetch(request, server);
|
|
48
|
+
if (!serve.fetch) serve.fetch = (request, server) => app.fetch(request, server);
|
|
41
49
|
app.server = Bun.serve(serve);
|
|
42
50
|
if (!hasWs) callback?.(app.server);
|
|
43
51
|
queueMicrotask(() => {
|
|
@@ -34,9 +34,17 @@ const BunAdapter = createAdapter({
|
|
|
34
34
|
name: "bun",
|
|
35
35
|
runtime: "bun",
|
|
36
36
|
listen(app, options, callback) {
|
|
37
|
-
const
|
|
37
|
+
const _config = app["~config"]?.serve;
|
|
38
|
+
const _options = typeof options === "object" ? options : {
|
|
39
|
+
port: +options,
|
|
40
|
+
fetch: (request, server) => app.fetch(request, server)
|
|
41
|
+
};
|
|
42
|
+
const serve = _config ? {
|
|
43
|
+
..._config,
|
|
44
|
+
..._options
|
|
45
|
+
} : _options;
|
|
38
46
|
const hasWs = app["~hasWS"];
|
|
39
|
-
serve.fetch = (request, server) => app.fetch(request, server);
|
|
47
|
+
if (!serve.fetch) serve.fetch = (request, server) => app.fetch(request, server);
|
|
40
48
|
app.server = Bun.serve(serve);
|
|
41
49
|
if (!hasWs) callback?.(app.server);
|
|
42
50
|
queueMicrotask(() => {
|
|
@@ -9,7 +9,7 @@ const require_handler_error = require('../../handler/error.js');
|
|
|
9
9
|
|
|
10
10
|
//#region src/adapter/bun/router.ts
|
|
11
11
|
function createBunContext(app) {
|
|
12
|
-
const headers = app["~ext"]?.headers ? Object.assign(require_utils.nullObject(),
|
|
12
|
+
const headers = app["~ext"]?.headers ? Object.assign(require_utils.nullObject(), app["~ext"].headers) : null;
|
|
13
13
|
return class Context extends require_context.createBaseContext(app) {
|
|
14
14
|
constructor(request) {
|
|
15
15
|
super();
|
|
@@ -62,13 +62,13 @@ function createPlainHandler(handler, handleError, Context) {
|
|
|
62
62
|
}
|
|
63
63
|
function createRouteMap(app) {
|
|
64
64
|
const Context = createBunContext(app);
|
|
65
|
+
const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
65
66
|
function fetch(request) {
|
|
66
67
|
return handleError(new Context(request), new require_error.NotFound());
|
|
67
68
|
}
|
|
68
69
|
const history = app.history;
|
|
69
70
|
const length = history?.length ?? 0;
|
|
70
71
|
if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
|
|
71
|
-
const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
72
72
|
const routes = require_utils.nullObject();
|
|
73
73
|
for (let i = 0; i < length; i++) {
|
|
74
74
|
const route = history[i];
|
|
@@ -8,7 +8,7 @@ import { createErrorHandler } from "../../handler/error.mjs";
|
|
|
8
8
|
|
|
9
9
|
//#region src/adapter/bun/router.ts
|
|
10
10
|
function createBunContext(app) {
|
|
11
|
-
const headers = app["~ext"]?.headers ? Object.assign(nullObject(),
|
|
11
|
+
const headers = app["~ext"]?.headers ? Object.assign(nullObject(), app["~ext"].headers) : null;
|
|
12
12
|
return class Context extends createBaseContext(app) {
|
|
13
13
|
constructor(request) {
|
|
14
14
|
super();
|
|
@@ -61,13 +61,13 @@ function createPlainHandler(handler, handleError, Context) {
|
|
|
61
61
|
}
|
|
62
62
|
function createRouteMap(app) {
|
|
63
63
|
const Context = createBunContext(app);
|
|
64
|
+
const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
64
65
|
function fetch(request) {
|
|
65
66
|
return handleError(new Context(request), new NotFound());
|
|
66
67
|
}
|
|
67
68
|
const history = app.history;
|
|
68
69
|
const length = history?.length ?? 0;
|
|
69
70
|
if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
|
|
70
|
-
const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
71
71
|
const routes = nullObject();
|
|
72
72
|
for (let i = 0; i < length; i++) {
|
|
73
73
|
const route = history[i];
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../base.js";
|
|
|
5
5
|
//#region src/adapter/constants.d.ts
|
|
6
6
|
declare const defaultAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
8
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { AnyElysia } from "../base.js";
|
|
|
7
7
|
//#region src/adapter/index.d.ts
|
|
8
8
|
declare function createAdapter(adapter: ElysiaAdapterOptions): {
|
|
9
9
|
parse: {
|
|
10
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<
|
|
10
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
11
11
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
12
12
|
text: (context: Context) => MaybePromise<string>;
|
|
13
13
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -18,15 +18,12 @@ interface CreateHandlerParameter {
|
|
|
18
18
|
mapResponse(response: unknown, set: Context['set'], request?: Request): Response;
|
|
19
19
|
mapCompactResponse(response: unknown, request?: Request): Response;
|
|
20
20
|
}
|
|
21
|
-
declare
|
|
22
|
-
mapResponse,
|
|
23
|
-
mapCompactResponse
|
|
24
|
-
}: CreateHandlerParameter) => (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
|
|
21
|
+
declare function createStreamHandler(_: CreateHandlerParameter): (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
|
|
25
22
|
declare function streamResponse(response: Response): AsyncGenerator<any, void, any>;
|
|
26
23
|
declare function handleSet(set: Context['set']): void;
|
|
27
24
|
declare function mergeHeaders(responseHeaders: Headers, setHeaders: Context['set']['headers']): Headers;
|
|
28
25
|
declare function mergeStatus(responseStatus: number, setStatus: Context['set']['status']): number | undefined;
|
|
29
|
-
declare
|
|
26
|
+
declare function createResponseHandler(handler: CreateHandlerParameter): (response: Response, set?: Context["set"], request?: Request) => any;
|
|
30
27
|
/**
|
|
31
28
|
* Split async source into `branches` independent iterators
|
|
32
29
|
*
|
package/dist/adapter/utils.js
CHANGED
|
@@ -2,7 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_universal_constants = require('../universal/constants.js');
|
|
3
3
|
const require_constants = require('../constants.js');
|
|
4
4
|
const require_utils = require('../utils.js');
|
|
5
|
-
const
|
|
5
|
+
const require_cookie_serialize = require('../cookie/serialize.js');
|
|
6
|
+
const require_adapter_web_standard_handler = require('./web-standard/handler.js');
|
|
6
7
|
|
|
7
8
|
//#region src/adapter/utils.ts
|
|
8
9
|
const setCookie = "set-cookie";
|
|
@@ -51,7 +52,7 @@ function handleFile(response, set, request) {
|
|
|
51
52
|
if (!set && !size) return new Response(response);
|
|
52
53
|
if (!set) return new Response(response, { headers: defaultHeader });
|
|
53
54
|
if (set.headers instanceof Headers) {
|
|
54
|
-
for (const key of Object.keys(defaultHeader)) if (
|
|
55
|
+
for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
|
|
55
56
|
if (immutable) {
|
|
56
57
|
set.headers.delete("content-length");
|
|
57
58
|
set.headers.delete("accept-ranges");
|
|
@@ -96,10 +97,12 @@ function responseToSetHeaders(response, set) {
|
|
|
96
97
|
};
|
|
97
98
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
98
99
|
}
|
|
99
|
-
if (set.headers
|
|
100
|
+
if (set.headers instanceof Headers) {
|
|
101
|
+
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
102
|
+
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
100
103
|
return set;
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
function enqueueBinaryChunk(controller, chunk) {
|
|
103
106
|
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
104
107
|
controller.enqueue(new Uint8Array(buffer));
|
|
105
108
|
return true;
|
|
@@ -117,91 +120,93 @@ const enqueueBinaryChunk = (controller, chunk) => {
|
|
|
117
120
|
return true;
|
|
118
121
|
}
|
|
119
122
|
return false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
|
|
131
|
-
const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
|
|
132
|
-
const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
|
|
133
|
-
const headers = set?.headers;
|
|
134
|
-
if (headers) {
|
|
135
|
-
if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
|
|
136
|
-
if (!headers["content-type"]) headers["content-type"] = contentType;
|
|
137
|
-
if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
|
|
138
|
-
} else set = {
|
|
139
|
-
status: 200,
|
|
140
|
-
headers: {
|
|
141
|
-
"content-type": contentType,
|
|
142
|
-
"transfer-encoding": "chunked",
|
|
143
|
-
"cache-control": "no-cache",
|
|
144
|
-
connection: "keep-alive"
|
|
123
|
+
}
|
|
124
|
+
function createStreamHandler(_) {
|
|
125
|
+
return async (generator, set, request, skipFormat) => {
|
|
126
|
+
let init = generator.next?.();
|
|
127
|
+
if (set) handleSet(set);
|
|
128
|
+
if (init instanceof Promise) init = await init;
|
|
129
|
+
if (init?.value instanceof ReadableStream) generator = init.value;
|
|
130
|
+
else if (init && (typeof init?.done === "undefined" || init?.done)) {
|
|
131
|
+
if (set) return require_adapter_web_standard_handler.mapResponse(init.value, set, request);
|
|
132
|
+
return require_adapter_web_standard_handler.mapCompactResponse(init.value, request);
|
|
145
133
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
else if (typeof init.value === "object") try {
|
|
162
|
-
controller.enqueue(format(JSON.stringify(init.value)));
|
|
163
|
-
} catch {
|
|
164
|
-
controller.enqueue(format(init.value.toString()));
|
|
165
|
-
}
|
|
166
|
-
else controller.enqueue(format(init.value.toString()));
|
|
167
|
-
},
|
|
168
|
-
async pull(controller) {
|
|
169
|
-
if (end) {
|
|
170
|
-
try {
|
|
171
|
-
controller.close();
|
|
172
|
-
} catch {}
|
|
173
|
-
return;
|
|
134
|
+
const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
|
|
135
|
+
const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
|
|
136
|
+
const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
|
|
137
|
+
const headers = set?.headers;
|
|
138
|
+
if (headers) {
|
|
139
|
+
if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
|
|
140
|
+
if (!headers["content-type"]) headers["content-type"] = contentType;
|
|
141
|
+
if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
|
|
142
|
+
} else set = {
|
|
143
|
+
status: 200,
|
|
144
|
+
headers: {
|
|
145
|
+
"content-type": contentType,
|
|
146
|
+
"transfer-encoding": "chunked",
|
|
147
|
+
"cache-control": "no-cache",
|
|
148
|
+
connection: "keep-alive"
|
|
174
149
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
150
|
+
};
|
|
151
|
+
const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
|
|
152
|
+
let end = false;
|
|
153
|
+
return new Response(new ReadableStream({
|
|
154
|
+
start(controller) {
|
|
155
|
+
request?.signal?.addEventListener("abort", () => {
|
|
156
|
+
end = true;
|
|
157
|
+
iterator.return?.();
|
|
178
158
|
try {
|
|
179
159
|
controller.close();
|
|
180
160
|
} catch {}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
if (
|
|
185
|
-
else if (
|
|
186
|
-
|
|
187
|
-
controller.enqueue(format(JSON.stringify(chunk)));
|
|
161
|
+
});
|
|
162
|
+
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
163
|
+
if (init.value.toSSE) controller.enqueue(init.value.toSSE());
|
|
164
|
+
else if (enqueueBinaryChunk(controller, init.value)) return;
|
|
165
|
+
else if (typeof init.value === "object") try {
|
|
166
|
+
controller.enqueue(format(JSON.stringify(init.value)));
|
|
188
167
|
} catch {
|
|
189
|
-
controller.enqueue(format(
|
|
168
|
+
controller.enqueue(format(init.value.toString()));
|
|
169
|
+
}
|
|
170
|
+
else controller.enqueue(format(init.value.toString()));
|
|
171
|
+
},
|
|
172
|
+
async pull(controller) {
|
|
173
|
+
if (end) {
|
|
174
|
+
try {
|
|
175
|
+
controller.close();
|
|
176
|
+
} catch {}
|
|
177
|
+
return;
|
|
190
178
|
}
|
|
191
|
-
else controller.enqueue(format(chunk.toString()));
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.warn(error);
|
|
194
179
|
try {
|
|
195
|
-
|
|
196
|
-
|
|
180
|
+
const { value: chunk, done } = await iterator.next();
|
|
181
|
+
if (done || end) {
|
|
182
|
+
try {
|
|
183
|
+
controller.close();
|
|
184
|
+
} catch {}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (chunk === void 0 || chunk === null) return;
|
|
188
|
+
if (chunk.toSSE) controller.enqueue(chunk.toSSE());
|
|
189
|
+
else if (enqueueBinaryChunk(controller, chunk)) return;
|
|
190
|
+
else if (typeof chunk === "object") try {
|
|
191
|
+
controller.enqueue(format(JSON.stringify(chunk)));
|
|
192
|
+
} catch {
|
|
193
|
+
controller.enqueue(format(chunk.toString()));
|
|
194
|
+
}
|
|
195
|
+
else controller.enqueue(format(chunk.toString()));
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.warn(error);
|
|
198
|
+
try {
|
|
199
|
+
controller.close();
|
|
200
|
+
} catch {}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
cancel() {
|
|
204
|
+
end = true;
|
|
205
|
+
iterator.return?.();
|
|
197
206
|
}
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
iterator.return?.();
|
|
202
|
-
}
|
|
203
|
-
}), set);
|
|
204
|
-
};
|
|
207
|
+
}), set);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
205
210
|
async function* streamResponse(response) {
|
|
206
211
|
const body = response.body;
|
|
207
212
|
if (body) yield* body;
|
|
@@ -209,13 +214,13 @@ async function* streamResponse(response) {
|
|
|
209
214
|
function handleSet(set) {
|
|
210
215
|
if (typeof set.status === "string") set.status = require_constants.StatusMap[set.status];
|
|
211
216
|
const proto = Object.getPrototypeOf(set.headers);
|
|
212
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
217
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
213
218
|
const flat = Object.create(null);
|
|
214
219
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
215
220
|
set.headers = flat;
|
|
216
221
|
}
|
|
217
222
|
if (set.cookie && require_utils.isNotEmpty(set.cookie)) {
|
|
218
|
-
const cookie =
|
|
223
|
+
const cookie = require_cookie_serialize.serializeCookie(set.cookie);
|
|
219
224
|
if (cookie) set.headers[setCookie] = cookie;
|
|
220
225
|
}
|
|
221
226
|
if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
|
|
@@ -239,7 +244,7 @@ function mergeStatus(responseStatus, setStatus) {
|
|
|
239
244
|
if (responseStatus === 200) return setStatus;
|
|
240
245
|
return responseStatus;
|
|
241
246
|
}
|
|
242
|
-
|
|
247
|
+
function createResponseHandler(handler) {
|
|
243
248
|
const handleStream = createStreamHandler(handler);
|
|
244
249
|
return (response, set, request) => {
|
|
245
250
|
if (set) {
|
|
@@ -263,7 +268,7 @@ const createResponseHandler = (handler) => {
|
|
|
263
268
|
if (!newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
|
|
264
269
|
return newResponse;
|
|
265
270
|
};
|
|
266
|
-
}
|
|
271
|
+
}
|
|
267
272
|
/**
|
|
268
273
|
* Split async source into `branches` independent iterators
|
|
269
274
|
*
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { hasHeaderShorthand, isBun } from "../universal/constants.mjs";
|
|
2
2
|
import { StatusMap } from "../constants.mjs";
|
|
3
3
|
import { isNotEmpty, nullObject } from "../utils.mjs";
|
|
4
|
-
import { serializeCookie } from "../cookie/
|
|
4
|
+
import { serializeCookie } from "../cookie/serialize.mjs";
|
|
5
|
+
import { mapCompactResponse, mapResponse } from "./web-standard/handler.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/adapter/utils.ts
|
|
7
8
|
const setCookie = "set-cookie";
|
|
@@ -50,7 +51,7 @@ function handleFile(response, set, request) {
|
|
|
50
51
|
if (!set && !size) return new Response(response);
|
|
51
52
|
if (!set) return new Response(response, { headers: defaultHeader });
|
|
52
53
|
if (set.headers instanceof Headers) {
|
|
53
|
-
for (const key of Object.keys(defaultHeader)) if (
|
|
54
|
+
for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
|
|
54
55
|
if (immutable) {
|
|
55
56
|
set.headers.delete("content-length");
|
|
56
57
|
set.headers.delete("accept-ranges");
|
|
@@ -95,10 +96,12 @@ function responseToSetHeaders(response, set) {
|
|
|
95
96
|
};
|
|
96
97
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
97
98
|
}
|
|
98
|
-
if (set.headers
|
|
99
|
+
if (set.headers instanceof Headers) {
|
|
100
|
+
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
101
|
+
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
99
102
|
return set;
|
|
100
103
|
}
|
|
101
|
-
|
|
104
|
+
function enqueueBinaryChunk(controller, chunk) {
|
|
102
105
|
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
103
106
|
controller.enqueue(new Uint8Array(buffer));
|
|
104
107
|
return true;
|
|
@@ -116,91 +119,93 @@ const enqueueBinaryChunk = (controller, chunk) => {
|
|
|
116
119
|
return true;
|
|
117
120
|
}
|
|
118
121
|
return false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
|
|
130
|
-
const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
|
|
131
|
-
const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
|
|
132
|
-
const headers = set?.headers;
|
|
133
|
-
if (headers) {
|
|
134
|
-
if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
|
|
135
|
-
if (!headers["content-type"]) headers["content-type"] = contentType;
|
|
136
|
-
if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
|
|
137
|
-
} else set = {
|
|
138
|
-
status: 200,
|
|
139
|
-
headers: {
|
|
140
|
-
"content-type": contentType,
|
|
141
|
-
"transfer-encoding": "chunked",
|
|
142
|
-
"cache-control": "no-cache",
|
|
143
|
-
connection: "keep-alive"
|
|
122
|
+
}
|
|
123
|
+
function createStreamHandler(_) {
|
|
124
|
+
return async (generator, set, request, skipFormat) => {
|
|
125
|
+
let init = generator.next?.();
|
|
126
|
+
if (set) handleSet(set);
|
|
127
|
+
if (init instanceof Promise) init = await init;
|
|
128
|
+
if (init?.value instanceof ReadableStream) generator = init.value;
|
|
129
|
+
else if (init && (typeof init?.done === "undefined" || init?.done)) {
|
|
130
|
+
if (set) return mapResponse(init.value, set, request);
|
|
131
|
+
return mapCompactResponse(init.value, request);
|
|
144
132
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
else if (typeof init.value === "object") try {
|
|
161
|
-
controller.enqueue(format(JSON.stringify(init.value)));
|
|
162
|
-
} catch {
|
|
163
|
-
controller.enqueue(format(init.value.toString()));
|
|
164
|
-
}
|
|
165
|
-
else controller.enqueue(format(init.value.toString()));
|
|
166
|
-
},
|
|
167
|
-
async pull(controller) {
|
|
168
|
-
if (end) {
|
|
169
|
-
try {
|
|
170
|
-
controller.close();
|
|
171
|
-
} catch {}
|
|
172
|
-
return;
|
|
133
|
+
const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
|
|
134
|
+
const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
|
|
135
|
+
const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
|
|
136
|
+
const headers = set?.headers;
|
|
137
|
+
if (headers) {
|
|
138
|
+
if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
|
|
139
|
+
if (!headers["content-type"]) headers["content-type"] = contentType;
|
|
140
|
+
if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
|
|
141
|
+
} else set = {
|
|
142
|
+
status: 200,
|
|
143
|
+
headers: {
|
|
144
|
+
"content-type": contentType,
|
|
145
|
+
"transfer-encoding": "chunked",
|
|
146
|
+
"cache-control": "no-cache",
|
|
147
|
+
connection: "keep-alive"
|
|
173
148
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
149
|
+
};
|
|
150
|
+
const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
|
|
151
|
+
let end = false;
|
|
152
|
+
return new Response(new ReadableStream({
|
|
153
|
+
start(controller) {
|
|
154
|
+
request?.signal?.addEventListener("abort", () => {
|
|
155
|
+
end = true;
|
|
156
|
+
iterator.return?.();
|
|
177
157
|
try {
|
|
178
158
|
controller.close();
|
|
179
159
|
} catch {}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
if (
|
|
184
|
-
else if (
|
|
185
|
-
|
|
186
|
-
controller.enqueue(format(JSON.stringify(chunk)));
|
|
160
|
+
});
|
|
161
|
+
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
162
|
+
if (init.value.toSSE) controller.enqueue(init.value.toSSE());
|
|
163
|
+
else if (enqueueBinaryChunk(controller, init.value)) return;
|
|
164
|
+
else if (typeof init.value === "object") try {
|
|
165
|
+
controller.enqueue(format(JSON.stringify(init.value)));
|
|
187
166
|
} catch {
|
|
188
|
-
controller.enqueue(format(
|
|
167
|
+
controller.enqueue(format(init.value.toString()));
|
|
168
|
+
}
|
|
169
|
+
else controller.enqueue(format(init.value.toString()));
|
|
170
|
+
},
|
|
171
|
+
async pull(controller) {
|
|
172
|
+
if (end) {
|
|
173
|
+
try {
|
|
174
|
+
controller.close();
|
|
175
|
+
} catch {}
|
|
176
|
+
return;
|
|
189
177
|
}
|
|
190
|
-
else controller.enqueue(format(chunk.toString()));
|
|
191
|
-
} catch (error) {
|
|
192
|
-
console.warn(error);
|
|
193
178
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
179
|
+
const { value: chunk, done } = await iterator.next();
|
|
180
|
+
if (done || end) {
|
|
181
|
+
try {
|
|
182
|
+
controller.close();
|
|
183
|
+
} catch {}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (chunk === void 0 || chunk === null) return;
|
|
187
|
+
if (chunk.toSSE) controller.enqueue(chunk.toSSE());
|
|
188
|
+
else if (enqueueBinaryChunk(controller, chunk)) return;
|
|
189
|
+
else if (typeof chunk === "object") try {
|
|
190
|
+
controller.enqueue(format(JSON.stringify(chunk)));
|
|
191
|
+
} catch {
|
|
192
|
+
controller.enqueue(format(chunk.toString()));
|
|
193
|
+
}
|
|
194
|
+
else controller.enqueue(format(chunk.toString()));
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.warn(error);
|
|
197
|
+
try {
|
|
198
|
+
controller.close();
|
|
199
|
+
} catch {}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
cancel() {
|
|
203
|
+
end = true;
|
|
204
|
+
iterator.return?.();
|
|
196
205
|
}
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
iterator.return?.();
|
|
201
|
-
}
|
|
202
|
-
}), set);
|
|
203
|
-
};
|
|
206
|
+
}), set);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
204
209
|
async function* streamResponse(response) {
|
|
205
210
|
const body = response.body;
|
|
206
211
|
if (body) yield* body;
|
|
@@ -208,7 +213,7 @@ async function* streamResponse(response) {
|
|
|
208
213
|
function handleSet(set) {
|
|
209
214
|
if (typeof set.status === "string") set.status = StatusMap[set.status];
|
|
210
215
|
const proto = Object.getPrototypeOf(set.headers);
|
|
211
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
216
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
212
217
|
const flat = Object.create(null);
|
|
213
218
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
214
219
|
set.headers = flat;
|
|
@@ -238,7 +243,7 @@ function mergeStatus(responseStatus, setStatus) {
|
|
|
238
243
|
if (responseStatus === 200) return setStatus;
|
|
239
244
|
return responseStatus;
|
|
240
245
|
}
|
|
241
|
-
|
|
246
|
+
function createResponseHandler(handler) {
|
|
242
247
|
const handleStream = createStreamHandler(handler);
|
|
243
248
|
return (response, set, request) => {
|
|
244
249
|
if (set) {
|
|
@@ -262,7 +267,7 @@ const createResponseHandler = (handler) => {
|
|
|
262
267
|
if (!newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
|
|
263
268
|
return newResponse;
|
|
264
269
|
};
|
|
265
|
-
}
|
|
270
|
+
}
|
|
266
271
|
/**
|
|
267
272
|
* Split async source into `branches` independent iterators
|
|
268
273
|
*
|