elysia 2.0.0-beta.21 → 2.0.0-beta.23
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.mjs +1 -0
- package/dist/adapter/bun/index.d.ts +6 -8
- package/dist/adapter/bun/index.js +6 -8
- package/dist/adapter/bun/index.mjs +7 -8
- package/dist/adapter/constants.mjs +1 -0
- package/dist/adapter/default-headers.mjs +1 -0
- package/dist/adapter/index.mjs +1 -0
- package/dist/adapter/origin.mjs +1 -0
- package/dist/adapter/response-ownership.mjs +1 -0
- package/dist/adapter/skip-clone.mjs +1 -0
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +5 -8
- package/dist/adapter/utils.js +24 -18
- package/dist/adapter/utils.mjs +25 -18
- package/dist/adapter/web-standard/handler.mjs +2 -1
- package/dist/adapter/web-standard/index.mjs +1 -0
- package/dist/adapter/web-standard/utils.mjs +1 -0
- package/dist/base.d.ts +118 -69
- package/dist/base.js +214 -194
- package/dist/base.mjs +221 -200
- package/dist/compile/aot-capture.js +2 -2
- package/dist/compile/aot-capture.mjs +4 -3
- package/dist/compile/aot-emit.js +7 -8
- package/dist/compile/aot-emit.mjs +8 -8
- package/dist/compile/aot-reconstruct.mjs +3 -2
- package/dist/compile/aot.d.ts +3 -3
- package/dist/compile/aot.js +5 -5
- package/dist/compile/aot.mjs +6 -5
- package/dist/compile/handler/descriptor.d.ts +2 -5
- package/dist/compile/handler/descriptor.js +12 -17
- package/dist/compile/handler/descriptor.mjs +16 -21
- package/dist/compile/handler/frozen-validator.d.ts +2 -2
- package/dist/compile/handler/frozen-validator.js +3 -3
- package/dist/compile/handler/frozen-validator.mjs +4 -3
- package/dist/compile/handler/index.d.ts +3 -1
- package/dist/compile/handler/index.js +78 -118
- package/dist/compile/handler/index.mjs +84 -125
- package/dist/compile/handler/jit.d.ts +12 -12
- package/dist/compile/handler/jit.js +60 -43
- package/dist/compile/handler/jit.mjs +63 -47
- package/dist/compile/handler/params.d.ts +5 -1
- package/dist/compile/handler/params.js +14 -5
- package/dist/compile/handler/params.mjs +16 -7
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +2 -2
- package/dist/compile/handler/reconstruct.mjs +3 -2
- package/dist/compile/handler/static-clone-resolver.mjs +1 -0
- package/dist/compile/handler/utils.d.ts +13 -7
- package/dist/compile/handler/utils.js +75 -52
- package/dist/compile/handler/utils.mjs +77 -54
- package/dist/compile/jit-probe.mjs +1 -0
- package/dist/compile/lexer.js +4 -4
- package/dist/compile/lexer.mjs +5 -4
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +8 -3
- package/dist/compile/utils.mjs +8 -3
- package/dist/compiled.mjs +1 -0
- package/dist/constants.mjs +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.d.ts +2 -2
- package/dist/cookie/config.js +21 -26
- package/dist/cookie/config.mjs +22 -26
- package/dist/cookie/cookie.mjs +1 -0
- package/dist/cookie/crypto.mjs +1 -0
- package/dist/cookie/error.mjs +1 -0
- package/dist/cookie/lib.mjs +1 -0
- package/dist/cookie/serialize.mjs +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +1 -1
- package/dist/cookie/utils.js +64 -45
- package/dist/cookie/utils.mjs +66 -46
- package/dist/error.d.ts +10 -6
- package/dist/error.js +22 -6
- package/dist/error.mjs +25 -9
- package/dist/generation.mjs +1 -0
- package/dist/handler/error.d.ts +12 -15
- package/dist/handler/error.js +43 -40
- package/dist/handler/error.mjs +45 -41
- package/dist/handler/fetch.js +59 -21
- package/dist/handler/fetch.mjs +61 -22
- package/dist/handler/utils.d.ts +16 -3
- package/dist/handler/utils.js +14 -13
- package/dist/handler/utils.mjs +16 -15
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -0
- package/dist/index.mjs +3 -2
- package/dist/memory.mjs +1 -0
- package/dist/package.js +1 -1
- package/dist/package.mjs +2 -1
- package/dist/parse-query.js +76 -76
- package/dist/parse-query.mjs +77 -76
- package/dist/plugin/aot/bun.mjs +1 -0
- package/dist/plugin/aot/core.d.ts +1 -1
- package/dist/plugin/aot/core.js +7 -4
- package/dist/plugin/aot/core.mjs +8 -5
- package/dist/plugin/aot/esbuild.mjs +1 -0
- package/dist/plugin/aot/rspack-loader.mjs +1 -0
- package/dist/plugin/aot/rspack.mjs +1 -0
- package/dist/plugin/aot/treeshake.mjs +1 -0
- package/dist/plugin/aot/unplugin.mjs +4 -3
- package/dist/plugin/aot/vite.mjs +1 -0
- package/dist/plugin/aot/worker.mjs +1 -0
- package/dist/plugin/auto-head.mjs +1 -0
- package/dist/plugin/trace.mjs +1 -0
- package/dist/plugin/websocket.mjs +1 -0
- package/dist/route-table.mjs +1 -0
- package/dist/schema-snapshot.js +28 -3
- package/dist/schema-snapshot.mjs +29 -3
- package/dist/sucrose.d.ts +2 -2
- package/dist/sucrose.js +11 -11
- package/dist/sucrose.mjs +12 -11
- package/dist/trace.js +8 -10
- package/dist/trace.mjs +10 -11
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.mjs +1 -0
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/bridge.mjs +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.mjs +1 -0
- package/dist/type/compat.mjs +1 -0
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/constants.mjs +1 -0
- package/dist/type/elysia/accelerate.mjs +1 -0
- package/dist/type/elysia/array-buffer.d.ts +3 -2
- package/dist/type/elysia/array-buffer.js +5 -5
- package/dist/type/elysia/array-buffer.mjs +6 -5
- package/dist/type/elysia/array-string.mjs +1 -0
- package/dist/type/elysia/array.mjs +1 -0
- package/dist/type/elysia/boolean-string.mjs +1 -0
- package/dist/type/elysia/boolean.mjs +1 -0
- package/dist/type/elysia/cookie.mjs +1 -0
- package/dist/type/elysia/date.mjs +1 -0
- package/dist/type/elysia/file-type.mjs +1 -0
- package/dist/type/elysia/file.mjs +1 -0
- package/dist/type/elysia/files.mjs +1 -0
- package/dist/type/elysia/form.mjs +1 -0
- package/dist/type/elysia/integer-string.mjs +1 -0
- package/dist/type/elysia/integer.mjs +1 -0
- package/dist/type/elysia/intersect.mjs +1 -0
- package/dist/type/elysia/json-string.mjs +1 -0
- package/dist/type/elysia/keep-config.js +8 -8
- package/dist/type/elysia/keep-config.mjs +9 -8
- package/dist/type/elysia/maybe-empty.mjs +1 -0
- package/dist/type/elysia/no-validate.mjs +1 -0
- package/dist/type/elysia/nullable.mjs +1 -0
- package/dist/type/elysia/number.mjs +1 -0
- package/dist/type/elysia/numeric-enum.d.ts +4 -2
- package/dist/type/elysia/numeric-enum.mjs +1 -0
- package/dist/type/elysia/numeric.mjs +1 -0
- package/dist/type/elysia/object-string.mjs +1 -0
- package/dist/type/elysia/object.mjs +1 -0
- package/dist/type/elysia/optional.mjs +1 -0
- package/dist/type/elysia/problem.mjs +1 -0
- package/dist/type/elysia/string.mjs +1 -0
- package/dist/type/elysia/uint8-array.d.ts +2 -1
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +3 -2
- package/dist/type/elysia/union-enum.mjs +1 -0
- package/dist/type/elysia/union.mjs +1 -0
- package/dist/type/elysia/utils.js +3 -3
- package/dist/type/elysia/utils.mjs +4 -3
- package/dist/type/exports.mjs +1 -0
- package/dist/type/index.mjs +2 -1
- package/dist/type/shared.mjs +1 -0
- package/dist/type/sync-require.mjs +1 -0
- package/dist/type/typebox-system-lite.mjs +1 -0
- package/dist/type/typebox-system-require.mjs +1 -0
- package/dist/type/typebox-type-live.mjs +1 -0
- package/dist/type/typebox-value-live.mjs +1 -0
- package/dist/type/typebox-value-ops.mjs +1 -0
- package/dist/type/typebox-value.mjs +1 -0
- package/dist/type/types.d.ts +1 -1
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.mjs +1 -0
- package/dist/type/validator/clean-safe.mjs +1 -0
- package/dist/type/validator/custom-error.js +41 -33
- package/dist/type/validator/custom-error.mjs +42 -33
- package/dist/type/validator/default-precompute.d.ts +2 -2
- package/dist/type/validator/default-precompute.js +10 -11
- package/dist/type/validator/default-precompute.mjs +13 -13
- package/dist/type/validator/exact-mirror.mjs +1 -0
- package/dist/type/validator/frozen-check.js +7 -7
- package/dist/type/validator/frozen-check.mjs +8 -7
- package/dist/type/validator/index.d.ts +2 -2
- package/dist/type/validator/index.js +4 -8
- package/dist/type/validator/index.mjs +5 -8
- package/dist/type/validator/string-codec-aot.d.ts +1 -1
- package/dist/type/validator/string-codec-aot.mjs +1 -0
- package/dist/type/validator/validator-cache.js +18 -18
- package/dist/type/validator/validator-cache.mjs +19 -18
- package/dist/types.d.ts +108 -70
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.mjs +1 -0
- package/dist/universal/file.mjs +1 -0
- package/dist/universal/index.mjs +1 -0
- package/dist/universal/is-production.mjs +1 -0
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +49 -31
- package/dist/utils.js +221 -109
- package/dist/utils.mjs +215 -106
- package/dist/validator/index.d.ts +3 -3
- package/dist/validator/index.js +4 -4
- package/dist/validator/index.mjs +5 -4
- package/dist/validator/route.d.ts +2 -2
- package/dist/validator/route.mjs +1 -0
- package/dist/ws/context.js +1 -1
- package/dist/ws/context.mjs +2 -1
- package/dist/ws/index.mjs +1 -0
- package/dist/ws/parser.mjs +1 -0
- package/dist/ws/route.js +34 -25
- package/dist/ws/route.mjs +40 -30
- package/dist/ws/types.d.ts +2 -3
- package/dist/ws/types.mjs +1 -0
- package/package.json +2 -2
|
@@ -75,24 +75,22 @@ function walk(value, key, mode, state) {
|
|
|
75
75
|
}
|
|
76
76
|
function walkObject(value, mode, state) {
|
|
77
77
|
const keys = Object.keys(value);
|
|
78
|
-
|
|
79
|
-
let first = true;
|
|
78
|
+
const parts = ["{"];
|
|
80
79
|
for (let i = 0; i < keys.length; i++) {
|
|
81
80
|
const key = keys[i];
|
|
82
81
|
const child = value[key];
|
|
83
82
|
const piece = walk(child, key, mode === CONTAINER ? NODE : mode === NODE ? childMode(key, child) : OFF, state);
|
|
84
83
|
if (piece === void 0) continue;
|
|
85
84
|
if (state.buildKey) {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
serialized += quote(key) + ":" + piece;
|
|
85
|
+
if (parts.length > 1) parts.push(",");
|
|
86
|
+
parts.push(quote(key), ":", piece);
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
|
-
|
|
89
|
+
parts.push("}");
|
|
90
|
+
return parts.join("");
|
|
92
91
|
}
|
|
93
92
|
function walkOptional(value, mode, state) {
|
|
94
|
-
|
|
95
|
-
let first = true;
|
|
93
|
+
const parts = ["{"];
|
|
96
94
|
let emittedOptional = false;
|
|
97
95
|
for (const key in value) {
|
|
98
96
|
const child = value[key];
|
|
@@ -100,28 +98,29 @@ function walkOptional(value, mode, state) {
|
|
|
100
98
|
if (key === "~optional") emittedOptional = true;
|
|
101
99
|
if (piece === void 0) continue;
|
|
102
100
|
if (state.buildKey) {
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
serialized += quote(key) + ":" + piece;
|
|
101
|
+
if (parts.length > 1) parts.push(",");
|
|
102
|
+
parts.push(quote(key), ":", piece);
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
if (!emittedOptional && state.buildKey) {
|
|
109
|
-
if (
|
|
110
|
-
|
|
106
|
+
if (parts.length > 1) parts.push(",");
|
|
107
|
+
parts.push("\"~optional\":true");
|
|
111
108
|
}
|
|
112
|
-
|
|
109
|
+
parts.push("}");
|
|
110
|
+
return parts.join("");
|
|
113
111
|
}
|
|
114
112
|
function walkArray(value, mode, state) {
|
|
115
113
|
const elementMode = mode === CONTAINER ? NODE : OFF;
|
|
116
|
-
|
|
114
|
+
const parts = ["["];
|
|
117
115
|
for (let i = 0; i < value.length; i++) {
|
|
118
116
|
const piece = walk(value[i], i, elementMode, state);
|
|
119
117
|
if (state.buildKey) {
|
|
120
|
-
if (i)
|
|
121
|
-
|
|
118
|
+
if (i) parts.push(",");
|
|
119
|
+
parts.push(piece === void 0 ? "null" : piece);
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
|
-
|
|
122
|
+
parts.push("]");
|
|
123
|
+
return parts.join("");
|
|
125
124
|
}
|
|
126
125
|
function computeSchemaMeta(schema, forceKey) {
|
|
127
126
|
const state = {
|
|
@@ -253,6 +252,7 @@ var TypeBoxValidatorCache = class TypeBoxValidatorCache {
|
|
|
253
252
|
this.#referenceCache = /* @__PURE__ */ new WeakMap();
|
|
254
253
|
TypeBoxValidatorCache.#lastSchema = void 0;
|
|
255
254
|
TypeBoxValidatorCache.#lastMeta = void 0;
|
|
255
|
+
TypeBoxValidatorCache.#metaCache = /* @__PURE__ */ new WeakMap();
|
|
256
256
|
require_type_coerce.deferCoercions();
|
|
257
257
|
}
|
|
258
258
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { isCloudflareWorker } from "../../universal/constants.mjs";
|
|
2
3
|
import { evictOldestHalf, nullObject } from "../../utils.mjs";
|
|
3
4
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
@@ -74,24 +75,22 @@ function walk(value, key, mode, state) {
|
|
|
74
75
|
}
|
|
75
76
|
function walkObject(value, mode, state) {
|
|
76
77
|
const keys = Object.keys(value);
|
|
77
|
-
|
|
78
|
-
let first = true;
|
|
78
|
+
const parts = ["{"];
|
|
79
79
|
for (let i = 0; i < keys.length; i++) {
|
|
80
80
|
const key = keys[i];
|
|
81
81
|
const child = value[key];
|
|
82
82
|
const piece = walk(child, key, mode === CONTAINER ? NODE : mode === NODE ? childMode(key, child) : OFF, state);
|
|
83
83
|
if (piece === void 0) continue;
|
|
84
84
|
if (state.buildKey) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
serialized += quote(key) + ":" + piece;
|
|
85
|
+
if (parts.length > 1) parts.push(",");
|
|
86
|
+
parts.push(quote(key), ":", piece);
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
|
|
89
|
+
parts.push("}");
|
|
90
|
+
return parts.join("");
|
|
91
91
|
}
|
|
92
92
|
function walkOptional(value, mode, state) {
|
|
93
|
-
|
|
94
|
-
let first = true;
|
|
93
|
+
const parts = ["{"];
|
|
95
94
|
let emittedOptional = false;
|
|
96
95
|
for (const key in value) {
|
|
97
96
|
const child = value[key];
|
|
@@ -99,28 +98,29 @@ function walkOptional(value, mode, state) {
|
|
|
99
98
|
if (key === "~optional") emittedOptional = true;
|
|
100
99
|
if (piece === void 0) continue;
|
|
101
100
|
if (state.buildKey) {
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
serialized += quote(key) + ":" + piece;
|
|
101
|
+
if (parts.length > 1) parts.push(",");
|
|
102
|
+
parts.push(quote(key), ":", piece);
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
if (!emittedOptional && state.buildKey) {
|
|
108
|
-
if (
|
|
109
|
-
|
|
106
|
+
if (parts.length > 1) parts.push(",");
|
|
107
|
+
parts.push("\"~optional\":true");
|
|
110
108
|
}
|
|
111
|
-
|
|
109
|
+
parts.push("}");
|
|
110
|
+
return parts.join("");
|
|
112
111
|
}
|
|
113
112
|
function walkArray(value, mode, state) {
|
|
114
113
|
const elementMode = mode === CONTAINER ? NODE : OFF;
|
|
115
|
-
|
|
114
|
+
const parts = ["["];
|
|
116
115
|
for (let i = 0; i < value.length; i++) {
|
|
117
116
|
const piece = walk(value[i], i, elementMode, state);
|
|
118
117
|
if (state.buildKey) {
|
|
119
|
-
if (i)
|
|
120
|
-
|
|
118
|
+
if (i) parts.push(",");
|
|
119
|
+
parts.push(piece === void 0 ? "null" : piece);
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
parts.push("]");
|
|
123
|
+
return parts.join("");
|
|
124
124
|
}
|
|
125
125
|
function computeSchemaMeta(schema, forceKey) {
|
|
126
126
|
const state = {
|
|
@@ -252,6 +252,7 @@ var TypeBoxValidatorCache = class TypeBoxValidatorCache {
|
|
|
252
252
|
this.#referenceCache = /* @__PURE__ */ new WeakMap();
|
|
253
253
|
TypeBoxValidatorCache.#lastSchema = void 0;
|
|
254
254
|
TypeBoxValidatorCache.#lastMeta = void 0;
|
|
255
|
+
TypeBoxValidatorCache.#metaCache = /* @__PURE__ */ new WeakMap();
|
|
255
256
|
deferCoercions();
|
|
256
257
|
}
|
|
257
258
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { CookieOptions } from "./cookie/types.js";
|
|
2
|
-
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
3
1
|
import { StatusMap, StatusMapBack } from "./constants.js";
|
|
4
2
|
import { ElysiaError, ElysiaStatus, ProblemResponseBody, ValidationErrorResponse } from "./error.js";
|
|
5
3
|
import { ChainNode } from "./utils.js";
|
|
6
4
|
import { Serve } from "./universal/server.js";
|
|
5
|
+
import { CookieOptions } from "./cookie/types.js";
|
|
7
6
|
import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
|
|
8
7
|
import { TraceHandler } from "./trace.js";
|
|
9
8
|
import { ElysiaFile } from "./universal/file.js";
|
|
9
|
+
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
10
10
|
import { AnyElysia, Elysia } from "./base.js";
|
|
11
11
|
import { ElysiaAdapter } from "./adapter/index.js";
|
|
12
|
-
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TRef, TSchema } from "typebox";
|
|
13
12
|
import { OpenAPIV3 } from "openapi-types";
|
|
13
|
+
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TRef, TSchema } from "typebox";
|
|
14
14
|
|
|
15
15
|
//#region src/types.d.ts
|
|
16
16
|
interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope extends EventScope, in out Adapter extends ElysiaAdapter = ElysiaAdapter> {
|
|
@@ -235,43 +235,43 @@ type LocalHook<Input extends BaseMacro, Schema extends RouteSchemaWithResolvedMa
|
|
|
235
235
|
* - 'arraybuffer': parse body as readable stream
|
|
236
236
|
*/
|
|
237
237
|
parse?: MaybeArray<BodyHandler<Schema, Singleton & {
|
|
238
|
-
derive: Schema['
|
|
238
|
+
derive: Schema['derive'];
|
|
239
239
|
}> | ContentType | Parser>;
|
|
240
240
|
/**
|
|
241
241
|
* Transform context's value
|
|
242
242
|
*/
|
|
243
243
|
transform?: MaybeArray<TransformHandler<Schema, Singleton & {
|
|
244
|
-
derive: Schema['
|
|
244
|
+
derive: Schema['derive'];
|
|
245
245
|
}>>;
|
|
246
246
|
/**
|
|
247
247
|
* Execute before main handler
|
|
248
248
|
*/
|
|
249
249
|
beforeHandle?: MaybeArray<OptionalHandler<Schema, Singleton & {
|
|
250
|
-
derive: Schema['
|
|
250
|
+
derive: Schema['derive'];
|
|
251
251
|
}>>;
|
|
252
252
|
/**
|
|
253
253
|
* Execute after main handler
|
|
254
254
|
*/
|
|
255
255
|
afterHandle?: MaybeArray<AfterHandler<Schema, Singleton & {
|
|
256
|
-
derive: Schema['
|
|
256
|
+
derive: Schema['derive'];
|
|
257
257
|
}>>;
|
|
258
258
|
/**
|
|
259
259
|
* Execute after main handler
|
|
260
260
|
*/
|
|
261
261
|
mapResponse?: MaybeArray<MapResponse<Schema, Singleton & {
|
|
262
|
-
derive: Schema['
|
|
262
|
+
derive: Schema['derive'];
|
|
263
263
|
}>>;
|
|
264
264
|
/**
|
|
265
265
|
* Execute after response is sent
|
|
266
266
|
*/
|
|
267
267
|
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton & {
|
|
268
|
-
derive: Schema['
|
|
268
|
+
derive: Schema['derive'];
|
|
269
269
|
}>>;
|
|
270
270
|
/**
|
|
271
271
|
* Catch error
|
|
272
272
|
*/
|
|
273
273
|
error?: MaybeArray<ErrorHandler<Errors, Schema, Singleton & {
|
|
274
|
-
derive: Schema['
|
|
274
|
+
derive: Schema['derive'];
|
|
275
275
|
}>>;
|
|
276
276
|
tags?: DocumentDecoration['tags'];
|
|
277
277
|
} & (Input extends any ? Input : Prettify<Input>);
|
|
@@ -433,13 +433,13 @@ type InlineHandlerResponse<Route extends RouteSchema['response']> = { [Status in
|
|
|
433
433
|
type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton, MacroContext extends {
|
|
434
434
|
response: PossibleResponse;
|
|
435
435
|
return: PossibleResponse;
|
|
436
|
-
|
|
436
|
+
derive: Record<string, unknown>;
|
|
437
437
|
} = {
|
|
438
438
|
response: {};
|
|
439
439
|
return: {};
|
|
440
|
-
|
|
440
|
+
derive: {};
|
|
441
441
|
}> = InlineHandlerNonMacro<Route & MacroContext, Singleton & {
|
|
442
|
-
derive: MacroContext['
|
|
442
|
+
derive: MacroContext['derive'];
|
|
443
443
|
}>;
|
|
444
444
|
type InlineHandlerNonMacro<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton> = (Route['response'] extends infer ResponseSchema ? {} extends ResponseSchema ? MaybePromise<InlineResponse> : MaybePromise<ResponseSchema[keyof ResponseSchema] | InlineHandlerResponse<ResponseSchema>> : never) | ((context: Context<Route, Singleton>) => MaybePromise<Response> | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
|
|
445
445
|
200: any;
|
|
@@ -460,9 +460,9 @@ type ErrorHandler<T extends ErrorDefinition[] = [], in out Route extends RouteSc
|
|
|
460
460
|
}> & {
|
|
461
461
|
error: T[number]['error'] | unknown;
|
|
462
462
|
}) => unknown;
|
|
463
|
-
type MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends string = '', AParamsPathDerived extends boolean = false> = {} extends A ? Path extends PathParameterLike ? Omit<B, 'params'> & {
|
|
463
|
+
type MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends string = '', AParamsPathDerived extends boolean = false> = {} extends A ? Path extends PathParameterLike ? IsNever<keyof B['params']> extends true ? Omit<B, 'params'> & {
|
|
464
464
|
params: ResolvePath<Path>;
|
|
465
|
-
} : B : {} extends B ? Path extends PathParameterLike ? Omit<A, 'params'> & {
|
|
465
|
+
} : B : B : {} extends B ? Path extends PathParameterLike ? Omit<A, 'params'> & {
|
|
466
466
|
params: ResolvePath<Path>;
|
|
467
467
|
} : A : {
|
|
468
468
|
body: undefined extends A['body'] ? B['body'] : A['body'];
|
|
@@ -499,22 +499,33 @@ type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema
|
|
|
499
499
|
mapResponse?: MaybeArray<MapResponse<TypedRoute, Singleton>>;
|
|
500
500
|
afterResponse?: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>;
|
|
501
501
|
derive?: MaybeArray<ResolveHandler<TypedRoute, Singleton>>;
|
|
502
|
+
/**
|
|
503
|
+
* Wrap the route handler. The wrapper's return is the handler value.
|
|
504
|
+
* A macro listed later in the route options wraps outside an earlier one
|
|
505
|
+
*/
|
|
506
|
+
handler?: (handler: (context: Context<TypedRoute, Singleton>) => unknown) => (context: Context<TypedRoute, Singleton>) => unknown;
|
|
502
507
|
detail?: DocumentDecoration;
|
|
503
508
|
/**
|
|
504
509
|
* Type-level route metadata surfaced on the route's Eden type
|
|
505
510
|
* (`CreateEdenResponse['meta']`). Reserved key like `seed`/`detail`/
|
|
506
|
-
* `introspect`
|
|
511
|
+
* `introspect` stripped at runtime, never lands on route hooks
|
|
507
512
|
*/
|
|
508
513
|
meta?: unknown;
|
|
509
514
|
/**
|
|
510
515
|
* Phantom {@link MacroTypeLambda} computing per call site context from
|
|
511
516
|
* the route's literal hook value. Reserved key like `seed`/`meta`/
|
|
512
|
-
* `introspect`
|
|
513
|
-
* value is tolerated and stripped
|
|
517
|
+
* `introspect` set it with `macroType<Lambda>()`; stripped at runtime
|
|
514
518
|
*/
|
|
515
519
|
$type?: MacroTypeLambda;
|
|
516
520
|
/**
|
|
517
|
-
*
|
|
521
|
+
* Inspect or rewrite the hooks a route compiles with. Runs once per
|
|
522
|
+
* route at compile time, after every macro on the route has expanded,
|
|
523
|
+
* on the route's final hooks: its own, the ones every macro added and
|
|
524
|
+
* the ones it inherits from hooks registered before it. A WebSocket
|
|
525
|
+
* route hands over its own hooks only. Applied by
|
|
526
|
+
* a guard, it sees the guard's hooks once instead of each route's.
|
|
527
|
+
* A `schema: 'merge'` guard's response map
|
|
528
|
+
* (`hooks.schemas[i].response`) is read-only
|
|
518
529
|
*
|
|
519
530
|
* @param option
|
|
520
531
|
*/
|
|
@@ -698,11 +709,11 @@ interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions
|
|
|
698
709
|
} : Schema['response'] extends { [status in number]: AnySchema | string } ? { [k in keyof Schema['response']]: UnwrapResponseSchema<Schema['response'][k], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown } : unknown | void;
|
|
699
710
|
}
|
|
700
711
|
type UnwrapModels<T extends Record<string, unknown>, Iteration extends number[] = []> = Iteration['length'] extends 8 ? T : { [K in keyof T]: T[K] extends AnySchema ? UnwrapSchema<T[K]> : T[K] extends Record<string, unknown> ? UnwrapModels<T[K], [...Iteration, 0]> : T[K] };
|
|
701
|
-
type MacroToProperty<in out T> = Prettify<{ [K in keyof T]: T[K] extends Function ? T[K] extends ((a: infer Params) => any) ? Params : boolean : boolean }>;
|
|
712
|
+
type MacroToProperty<in out T> = Prettify<{ [K in keyof T]: T[K] extends Function ? T[K] extends ((a: infer Params) => any) ? MacroOptionLambda<T[K]> extends never ? Params : unknown : boolean : boolean }>;
|
|
702
713
|
interface RouteSchemaWithResolvedMacro extends RouteSchema {
|
|
703
714
|
response: PossibleResponse;
|
|
704
715
|
return: PossibleResponse;
|
|
705
|
-
|
|
716
|
+
derive: Record<string, unknown>;
|
|
706
717
|
}
|
|
707
718
|
type IntersectIfObject<A, B> = unknown extends A ? B : A extends Record<any, any> ? B extends Record<any, any> ? A & B : A : B extends Record<any, any> ? B : A;
|
|
708
719
|
interface IntersectIfObjectSchema<A extends RouteSchema, B extends RouteSchema> {
|
|
@@ -734,7 +745,7 @@ type FunctionArrayReturnTypeNonNullable<T> = any[] extends T ? never : T extends
|
|
|
734
745
|
type _FunctionArrayReturnTypeNonNullable<T, Carry = undefined> = T extends [infer Fn, ...infer Rest] ? _FunctionArrayReturnTypeNonNullable<Rest, NonNullable<Awaited<ReturnType<Fn>>> extends infer A ? IsNever<A> extends true ? Carry : A | Carry : Carry> : Carry;
|
|
735
746
|
type AnyElysiaStatus = ElysiaStatus<any, any, any>;
|
|
736
747
|
type ExcludeElysiaResponse<T> = Exclude<Awaited<T>, AnyElysiaStatus> extends infer A ? IsNever<A & {}> extends true ? {} : undefined extends A ? Partial<A & {}> : A & {} : {};
|
|
737
|
-
type
|
|
748
|
+
type ExtractDeriveFromMacro<A> = IsNever<A> extends true ? {} : A extends AnyElysiaStatus ? A : Exclude<A, AnyElysiaStatus> extends infer A ? IsAny<A> extends true ? {} : A : {};
|
|
738
749
|
type ExtractOnlyResponseFromMacro<A> = IsNever<A> extends true ? {} : Extract<A, AnyElysiaStatus> extends infer A ? IsNever<A> extends true ? {} : {
|
|
739
750
|
return: MergeResponseStatus<A>;
|
|
740
751
|
} : {};
|
|
@@ -748,14 +759,44 @@ type ExtractAllResponseFromMacro<A> = IsNever<A> extends true ? {} : {
|
|
|
748
759
|
};
|
|
749
760
|
type FlattenMacroResponse<T> = T extends object ? '_' extends keyof T ? UnionResponseStatus<Omit<T, '_'>, FlattenMacroResponse<MergeStatusUnion<T['_']>>> : T : T;
|
|
750
761
|
/**
|
|
751
|
-
* Type-level lambda applied to a macro's per call site hook value
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
762
|
+
* Type-level lambda applied to a macro's per call site hook value
|
|
763
|
+
*
|
|
764
|
+
* Return type as `$type: macroType<Lambda>()`
|
|
765
|
+
* `output` will be added to route's context
|
|
766
|
+
*
|
|
767
|
+
* A function-form macro may also compute `option` from `this['context']`.
|
|
768
|
+
* The hook value is then typed as `option` per route, guard, group and ws,
|
|
769
|
+
* replacing the macro's declared parameter
|
|
770
|
+
*
|
|
771
|
+
* `this` is not allowed in a nested type literal
|
|
772
|
+
*
|
|
773
|
+
* ```ts
|
|
774
|
+
* interface LiveOption<Context> { topic?: (ctx: Context) => string }
|
|
775
|
+
* interface Live extends MacroTypeLambda { option: LiveOption<this['context']> }
|
|
776
|
+
*
|
|
777
|
+
* new Elysia().macro({
|
|
778
|
+
* live: (option: LiveOption<Context>) => ({
|
|
779
|
+
* $type: macroType<Live>(),
|
|
780
|
+
* beforeHandle() {}
|
|
781
|
+
* })
|
|
782
|
+
* })
|
|
783
|
+
* ```
|
|
755
784
|
*/
|
|
756
785
|
interface MacroTypeLambda {
|
|
757
786
|
input: unknown;
|
|
787
|
+
/**
|
|
788
|
+
* The call-site schema and accumulated singleton context, excluding output
|
|
789
|
+
* from macros selected at the same call site
|
|
790
|
+
*/
|
|
791
|
+
context: unknown;
|
|
758
792
|
}
|
|
793
|
+
type MacroOptionLambda<Fn> = Fn extends ((option: any) => infer Def) ? NonNullable<Def> extends {
|
|
794
|
+
$type?: infer Lambda extends MacroTypeLambda;
|
|
795
|
+
} ? 'option' extends keyof Lambda ? Lambda : never : never : never;
|
|
796
|
+
type MacroOptionContext<MacroFn, Route extends RouteSchema, Singleton extends SingletonBase> = { [K in keyof MacroFn]?: MacroOptionLambda<MacroFn[K]> extends never ? unknown : ElaborateOption<(MacroOptionLambda<MacroFn[K]> & {
|
|
797
|
+
context: Context<Route, Singleton>;
|
|
798
|
+
})['option']> };
|
|
799
|
+
type ElaborateOption<Option, Keys extends PropertyKey = keyof Extract<Option, object>> = unknown extends Option ? Option : Option extends boolean ? Option & { [K in Exclude<Keys, keyof Option> as {} extends Record<K, 0> ? never : K]?: never } : Option;
|
|
759
800
|
type MacroLambdaContext<Value, HookValue> = NonNullable<Value> extends {
|
|
760
801
|
$type?: infer Lambda extends MacroTypeLambda;
|
|
761
802
|
} ? Lambda & {
|
|
@@ -763,17 +804,21 @@ type MacroLambdaContext<Value, HookValue> = NonNullable<Value> extends {
|
|
|
763
804
|
} extends {
|
|
764
805
|
output: infer Output;
|
|
765
806
|
} ? Output : {} : {};
|
|
766
|
-
type UnionMacroContext<A> = UnionToIntersect<{ [K in Exclude<keyof A, 'return'>]: A[K] }> & {
|
|
807
|
+
type UnionMacroContext<A> = UnionToIntersect<A extends unknown ? { [K in Exclude<keyof A, 'return'>]: A[K] } : never> & {
|
|
767
808
|
return: {
|
|
768
809
|
_: A['return'];
|
|
769
810
|
};
|
|
770
811
|
};
|
|
771
|
-
type MacroToContext<in out MacroFn extends Macro = {}, in out SelectedMacro extends BaseMacro = {}, in out Definitions extends DefinitionBase['typebox'] = {}, in out R extends 1[] = []> = Prettify<InnerMacroToContext<MacroFn, Pick<SelectedMacro, Extract<keyof MacroFn, keyof SelectedMacro>>, Definitions, R> extends infer A ? { [K in Exclude<keyof A, 'return'>]: UnionToIntersect<A[K]>
|
|
812
|
+
type MacroToContext<in out MacroFn extends Macro = {}, in out SelectedMacro extends BaseMacro = {}, in out Definitions extends DefinitionBase['typebox'] = {}, in out R extends 1[] = []> = Prettify<InnerMacroToContext<MacroFn, Pick<SelectedMacro, Extract<keyof MacroFn, keyof SelectedMacro>>, Definitions, R> extends infer A ? { [K in Exclude<keyof A, 'return'>]: K extends 'derive' ? UnionToIntersect<A[K]> : K extends 'meta' ? (A[K] & {
|
|
813
|
+
value: unknown;
|
|
814
|
+
})['value'] : A[K] } & Prettify<{
|
|
772
815
|
return: FlattenMacroResponse<A['return']>;
|
|
773
816
|
}> : {}>;
|
|
774
817
|
type InnerMacroToContext<MacroFn extends Macro = {}, SelectedMacro extends BaseMacro = {}, Definitions extends DefinitionBase['typebox'] = {}, R extends 1[] = []> = {} extends SelectedMacro ? {} : R['length'] extends 15 ? {} : UnionMacroContext<{ [key in keyof SelectedMacro]: ReturnTypeIfPossible<MacroFn[key], SelectedMacro[key]> extends infer Value ? NonNullable<Value> extends infer Def ? {
|
|
775
|
-
meta: 'meta' extends keyof Def ?
|
|
776
|
-
|
|
818
|
+
meta: 'meta' extends keyof Def ? {
|
|
819
|
+
value: Def['meta'];
|
|
820
|
+
} : unknown;
|
|
821
|
+
derive: ExtractDeriveFromMacro<Extract<Exclude<FunctionArrayReturnType<Def['derive']>, AnyElysiaStatus>, Record<any, unknown>>> & MacroLambdaContext<Value, SelectedMacro[key]>;
|
|
777
822
|
} & UnwrapMacroSchema<Def, Definitions> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['beforeHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['afterHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnType<Def['error']>> & ExtractOnlyResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['derive']>> & InnerMacroToContext<MacroFn, Pick<Def, Extract<keyof MacroFn, keyof Def>>, Definitions, [...R, 1]> : {} : {} }[keyof SelectedMacro]>;
|
|
778
823
|
type UnwrapMacroSchema<T extends Partial<InputSchema<any>>, Definitions extends DefinitionBase['typebox'] = {}> = UnwrapRoute<{
|
|
779
824
|
body: 'body' extends keyof T ? T['body'] : undefined;
|
|
@@ -804,22 +849,21 @@ type RefDefSchema<D> = {
|
|
|
804
849
|
response: undefined;
|
|
805
850
|
};
|
|
806
851
|
/**
|
|
807
|
-
* Captures the verbatim `.macro()` definition record
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* cycle documented on {@link ObjectMacroDefs}.
|
|
852
|
+
* Captures the verbatim `.macro()` definition record in a first-pass generic,
|
|
853
|
+
* so each definition's sibling flags (`{ auth: true }`) are read back without
|
|
854
|
+
* reusing the contextually typed `NewMacro`, which would form the inference
|
|
855
|
+
* cycle documented on {@link ObjectMacroDefs}
|
|
812
856
|
*/
|
|
813
857
|
type MacroRefChannel<Refs> = { [K in keyof Refs]: MaybeValueOrVoidFunction<{ [M in keyof Refs[K]]?: Refs[K][M] } & Record<string, unknown>> };
|
|
814
858
|
/**
|
|
815
|
-
* `
|
|
859
|
+
* `derive` context contributed by the sibling macros a definition
|
|
816
860
|
* enables via `{ name: true }`. Extracted through `infer` because
|
|
817
|
-
* {@link MacroToContext} is a mapped type whose `
|
|
818
|
-
* with a plain `['
|
|
861
|
+
* {@link MacroToContext} is a mapped type whose `derive` key cannot be indexed
|
|
862
|
+
* with a plain `['derive']` on the generic form.
|
|
819
863
|
*/
|
|
820
|
-
type
|
|
821
|
-
|
|
822
|
-
} ?
|
|
864
|
+
type MacroRefDerive<MacroFn, SelectedMacro, Definitions> = MacroToContext<MacroFn, SelectedMacro, Definitions> extends {
|
|
865
|
+
derive: infer Derive;
|
|
866
|
+
} ? Derive : {};
|
|
823
867
|
/**
|
|
824
868
|
* Parameter type of the object-form `.macro({ name: definition })`
|
|
825
869
|
*
|
|
@@ -833,7 +877,7 @@ type MacroRefResolve<MacroFn, SelectedMacro, Definitions> = MacroToContext<Macro
|
|
|
833
877
|
* `Metadata['macroFn']` for the consuming route)
|
|
834
878
|
*/
|
|
835
879
|
type ObjectMacroDefs<N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro, MacroFn = {}, Refs = {}> = MacroRefChannel<Refs> & { [K in keyof N]: MaybeValueOrVoidFunction<MacroProperty<MacroNames & InputSchema<keyof Definitions['typebox'] & string>, IntersectIfObjectSchema<MergeSchema<UnwrapMacroSchema<RefDefSchema<K extends keyof Refs ? Refs[K] : {}>, Definitions['typebox']>, AmbientSchema>, ScopedSchemas>, Singleton & {
|
|
836
|
-
derive: Singleton['derive'] &
|
|
880
|
+
derive: Singleton['derive'] & MacroRefDerive<MacroFn, K extends keyof Refs ? Refs[K] : {}, Definitions['typebox']>;
|
|
837
881
|
}, Definitions['error']>> } & { [K in keyof N]: N[K] extends ((...a: any[]) => any) ? unknown : string extends keyof N[K] ? unknown : { [P in Exclude<keyof N[K], MacroPropertyKey | InputSchemaKey | keyof MacroFn | keyof N>]: `Unknown macro property '${P & string}'` } } & N;
|
|
838
882
|
type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' | '/' ? Property : _CreateEden<Path, Property>;
|
|
839
883
|
type CreateRouteEden<BasePath extends string, Path extends string, Property extends Record<string, unknown>> = string extends Path ? {} : CreateEden<JoinPath<BasePath, Path>, Property>;
|
|
@@ -842,13 +886,8 @@ type _CreateEden<Path extends string, Property extends Record<string, unknown> =
|
|
|
842
886
|
* Value an annotation knob resolves to, `never` when it annotates nothing.
|
|
843
887
|
*
|
|
844
888
|
* Both knobs are canonically methods, so what they *return* is the
|
|
845
|
-
* annotation. A value or getter reads as the value itself.
|
|
846
|
-
*
|
|
847
|
-
* returns and can't see its declared type — and `undefined` is excluded, it
|
|
848
|
-
* falls through to the next tier rather than being served.
|
|
849
|
-
*
|
|
850
|
-
* The base declares both knobs optional, so a subclass that doesn't override
|
|
851
|
-
* them never reaches here
|
|
889
|
+
* annotation. A value or getter reads as the value itself. `unknown` stays
|
|
890
|
+
* `unknown`, and `undefined` is excluded: it falls through to the next tier
|
|
852
891
|
*/
|
|
853
892
|
type ResolveAnnotation<V> = (V extends ((...args: any) => infer Returned) ? Returned : V) extends infer Value ? Exclude<Awaited<Value>, undefined> extends infer Resolved ? IsNever<Resolved> extends true ? never : Resolved : never : never;
|
|
854
893
|
/** Whether a knob may resolve `undefined` and fall through to the next tier */
|
|
@@ -979,16 +1018,10 @@ type ComposeElysiaResponse<Schema extends RouteSchema, Handle, Possibility exten
|
|
|
979
1018
|
})>>;
|
|
980
1019
|
type ExtractErrorFromHandle<in out Handle> = { [ErrorResponse in Extract<Handle, AnyElysiaStatus> as ErrorResponse extends AnyElysiaStatus ? ErrorResponse['status'] : never]: Prettify<ErrorResponse['response']> };
|
|
981
1020
|
/**
|
|
982
|
-
* Status used when an error handler returns a plain value
|
|
983
|
-
*
|
|
1021
|
+
* Status used when an error handler returns a plain value: the error's
|
|
1022
|
+
* declared literal `status`, otherwise 500
|
|
984
1023
|
*/
|
|
985
1024
|
type ErrorFallbackStatus<E> = IsNever<LiteralErrorStatus<E>> extends true ? 500 : LiteralErrorStatus<E>;
|
|
986
|
-
/**
|
|
987
|
-
* Body produced when no error handler returns a value. Falling through lands
|
|
988
|
-
* on exactly the lane an unhandled error takes, so it resolves the same three
|
|
989
|
-
* tiers — `MessageTier` already carries the foreign `response` fallback
|
|
990
|
-
*/
|
|
991
|
-
type ErrorFallbackBody<E> = ValueTier<E>;
|
|
992
1025
|
/**
|
|
993
1026
|
* `Definitions['error']` / `EphemeralType['error']` entry registered by an
|
|
994
1027
|
* `.error(Class, handler)` call
|
|
@@ -996,10 +1029,22 @@ type ErrorFallbackBody<E> = ValueTier<E>;
|
|
|
996
1029
|
type ErrorDefinitionEntry<E extends abstract new (...args: any) => Error, R> = {
|
|
997
1030
|
error: InstanceType<E>;
|
|
998
1031
|
response: ErrorHandlerResponseSchema<Awaited<R>, InstanceType<E>>;
|
|
1032
|
+
/**
|
|
1033
|
+
* The handler may return nothing, which passes the error on to the next
|
|
1034
|
+
* hook: it answers sometimes, but doesn't handle the error
|
|
1035
|
+
*/
|
|
1036
|
+
passes: undefined extends Awaited<R> ? true : false;
|
|
999
1037
|
};
|
|
1000
|
-
type ErrorHandlerResponseSchema<R, E> = ExtractErrorFromHandle<Exclude<R, Error>> & (Exclude<R, Extract<Exclude<R, Error>, AnyElysiaStatus> | undefined
|
|
1001
|
-
type
|
|
1002
|
-
|
|
1038
|
+
type ErrorHandlerResponseSchema<R, E> = ExtractErrorFromHandle<Exclude<R, Error>> & (Exclude<R, Extract<Exclude<R, Error>, AnyElysiaStatus> | undefined | void> extends infer Served ? ServedAtStatus<Served, ErrorFallbackStatus<E>> : {});
|
|
1039
|
+
type PassesError<Entry> = Entry extends {
|
|
1040
|
+
passes: true;
|
|
1041
|
+
} ? true : false;
|
|
1042
|
+
/**
|
|
1043
|
+
* What the handlers registered for `V` respond with: the first one that
|
|
1044
|
+
* always answers, and every one before it that may pass the error on
|
|
1045
|
+
*/
|
|
1046
|
+
type MatchRegisteredError<V, Errors extends ErrorDefinition[]> = Errors extends [infer Head extends ErrorDefinition, ...infer Rest extends ErrorDefinition[]] ? V extends Head['error'] ? PassesError<Head> extends true ? Head['response'] | MatchRegisteredError<V, Rest> : Head['response'] : MatchRegisteredError<V, Rest> : never;
|
|
1047
|
+
type HasErrorMatch<V, Errors extends ErrorDefinition[]> = Errors extends [infer Head extends ErrorDefinition, ...infer Rest extends ErrorDefinition[]] ? [V] extends [Head['error']] ? PassesError<Head> extends true ? HasErrorMatch<V, Rest> : true : HasErrorMatch<V, Rest> : false;
|
|
1003
1048
|
type UnhandledReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? never : ErrorOf<Value> extends infer Es ? Es extends Error ? HasErrorMatch<Es, Errors> extends true ? never : Es : never : never;
|
|
1004
1049
|
type UnhandledReturnedErrorOf<T, Errors extends ErrorDefinition[]> = T extends ((...a: any) => MaybePromise<infer R>) ? UnhandledReturnedError<R, Errors> : UnhandledReturnedError<T, Errors>;
|
|
1005
1050
|
/**
|
|
@@ -1053,13 +1098,6 @@ type ResolveRouteLeafErrors<Route extends {
|
|
|
1053
1098
|
response: Prettify<UnionResponseStatus<WithoutUnhandledErrorResponse<Route['response'], Route['error']>, UnionResponseStatus<ExtractReturnedError<Route['error'], Errors>, UnhandledErrorResponse<UnhandledReturnedError<Route['error'], Errors>>>>>;
|
|
1054
1099
|
error: UnhandledReturnedError<Route['error'], Errors>;
|
|
1055
1100
|
} & HandledErrorKey<RouteHandled<Route> | HandledReturnedError<Route['error'], Errors>>;
|
|
1056
|
-
type ResolveRouteErrors<Routes, Errors extends ErrorDefinition[]> = Errors extends [] ? Routes : { [K in keyof Routes]: Routes[K] extends {
|
|
1057
|
-
params: any;
|
|
1058
|
-
query: any;
|
|
1059
|
-
headers: any;
|
|
1060
|
-
response: any;
|
|
1061
|
-
error: any;
|
|
1062
|
-
} ? ResolveRouteLeafErrors<Routes[K], Errors> : Routes[K] extends Record<keyof any, any> ? ResolveRouteErrors<Routes[K], Errors> : Routes[K] };
|
|
1063
1101
|
/**
|
|
1064
1102
|
* Take a parent's handlers registered before `.use()` in front of the
|
|
1065
1103
|
* plugin's own: at runtime they run first, so an error the plugin already
|
|
@@ -1107,7 +1145,7 @@ type MergeElysiaInstances<Instances extends AnyElysia[] = [], Prefix extends str
|
|
|
1107
1145
|
schemas: Volatile['schemas'] & Current['~Ephemeral']['schemas'];
|
|
1108
1146
|
response: Volatile['response'] & Current['~Ephemeral']['response'];
|
|
1109
1147
|
error: [...Volatile['error'], ...Current['~Ephemeral']['error']];
|
|
1110
|
-
},
|
|
1148
|
+
}, Routes & (Prefix extends `` ? ResolveUsedRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], ParentResponse<Metadata, Ephemeral, Volatile>> : CreateEden<Prefix, ResolveUsedRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], ParentResponse<Metadata, Ephemeral, Volatile>>>)> : Elysia<Prefix, Scope, {
|
|
1111
1149
|
decorator: Singleton['decorator'];
|
|
1112
1150
|
store: Prettify<Singleton['store']>;
|
|
1113
1151
|
derive: Singleton['derive'];
|
|
@@ -1218,11 +1256,11 @@ type AddWSRoute<BasePath extends string, Scope extends EventScope, Singleton ext
|
|
|
1218
1256
|
subscribe: CreateWSEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Response, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], Path>>;
|
|
1219
1257
|
}>, Ephemeral, Volatile>;
|
|
1220
1258
|
type GuardHookSingleton<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, MacroContext> = Singleton & {
|
|
1221
|
-
derive: Ephemeral['derive'] & Volatile['derive'] & MacroContext['
|
|
1259
|
+
derive: Ephemeral['derive'] & Volatile['derive'] & MacroContext['derive'];
|
|
1222
1260
|
};
|
|
1223
1261
|
interface StaticMapAliases {
|
|
1224
1262
|
method: string;
|
|
1225
1263
|
paths: string[];
|
|
1226
1264
|
}
|
|
1227
1265
|
//#endregion
|
|
1228
|
-
export { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, type AnySchema, AnyWSLocalHook, AppEvent, AppHook, BaseMacro, BodyHandler, BunHTMLBundlelike, CompiledHandler, ComposeElysiaResponse, ContentType, ContextAppendType, CreateEden, CreateEdenResponse, CreateWSEdenResponse, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaFormData, ElysiaHandlerToResponseSchema, ElysiaHandlerToResponseSchemaAmbiguous, ElysiaHandlerToResponseSchemas, EmptyInputSchema, EphemeralType, Equal, ErrorDefinition, ErrorDefinitionEntry, ErrorHandler, ErrorHandlerResponseSchema, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, ExtractReturnedError, GetPathParameter, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, GuardSchemaType, HTTPHeaders, HTTPMethod, HandledErrorKey, HandledReturnedErrorOf, Handler, HistoryEntry, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, JoinPath, LocalHook, LocalHookReturn, Macro, MacroProperty, MacroPropertyKey, MacroToContext, MacroToProperty, MacroTypeLambda, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, ObjectMacroDefs, OptionalHandler, ParentResponse, PluginHookReturn, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath,
|
|
1266
|
+
export { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, type AnySchema, AnyWSLocalHook, AppEvent, AppHook, BaseMacro, BodyHandler, BunHTMLBundlelike, CompiledHandler, ComposeElysiaResponse, ContentType, ContextAppendType, CreateEden, CreateEdenResponse, CreateWSEdenResponse, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaFormData, ElysiaHandlerToResponseSchema, ElysiaHandlerToResponseSchemaAmbiguous, ElysiaHandlerToResponseSchemas, EmptyInputSchema, EphemeralType, Equal, ErrorDefinition, ErrorDefinitionEntry, ErrorHandler, ErrorHandlerResponseSchema, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, ExtractReturnedError, GetPathParameter, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, GuardSchemaType, HTTPHeaders, HTTPMethod, HandledErrorKey, HandledReturnedErrorOf, Handler, HistoryEntry, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, JoinPath, LocalHook, LocalHookReturn, Macro, MacroOptionContext, MacroProperty, MacroPropertyKey, MacroToContext, MacroToProperty, MacroTypeLambda, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, ObjectMacroDefs, OptionalHandler, ParentResponse, PluginHookReturn, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath, ResolveUsedRouteErrors, RouteBase, RouteInput, RouteSchema, SSEPayload, ScopedHookReturn, ScopedMapDeriveReturn, SingletonBase, type StandardSchemaV1Like, StaticMapAliases, TransformHandler, type TypeBoxSchema, UnhandledReturnedError, UnhandledReturnedErrorOf, UnionResponseStatus, UnionToIntersect, UnwrapArray, UnwrapBodySchema, UnwrapMacroSchema, UnwrapModels, UnwrapRoute, UnwrapSchema, ValueOrFunctionToResponseSchema, ValueToResponseSchema, VoidHandler, WithHandledErrors, WrapFn };
|
package/dist/types.mjs
CHANGED
package/dist/universal/file.mjs
CHANGED
package/dist/universal/index.mjs
CHANGED