elysia 2.0.0-beta.21 → 2.0.0-beta.22
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 +213 -193
- package/dist/base.mjs +220 -199
- 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 +77 -118
- package/dist/compile/handler/index.mjs +83 -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.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.mjs +1 -0
- 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 +105 -69
- 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
|
@@ -3,16 +3,16 @@ const require_utils = require('../../utils.js');
|
|
|
3
3
|
const require_type_typebox_type = require('../typebox-type.js');
|
|
4
4
|
|
|
5
5
|
//#region src/type/elysia/keep-config.ts
|
|
6
|
-
const
|
|
6
|
+
const mayCarryCookieConfig = (schema, isProperty = false, seen = /* @__PURE__ */ new Set()) => {
|
|
7
7
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
8
8
|
seen.add(schema);
|
|
9
|
-
if (schema.config !== void 0 || schema.$ref !== void 0 || schema["~kind"] === "Deferred" || require_utils.compositionKeys.some((key) => Array.isArray(schema[key]) && schema[key].some((member) =>
|
|
10
|
-
if (!
|
|
11
|
-
for (const name in schema.properties) if (
|
|
9
|
+
if (schema.config !== void 0 || schema.$ref !== void 0 || schema["~kind"] === "Deferred" || require_utils.compositionKeys.some((key) => Array.isArray(schema[key]) && schema[key].some((member) => mayCarryCookieConfig(member, isProperty, seen)))) return true;
|
|
10
|
+
if (!isProperty) {
|
|
11
|
+
for (const name in schema.properties) if (mayCarryCookieConfig(schema.properties[name], true)) return true;
|
|
12
12
|
}
|
|
13
13
|
return false;
|
|
14
14
|
};
|
|
15
|
-
const
|
|
15
|
+
const withSources = (schema, sources) => Object.defineProperty(Object.create(Object.getPrototypeOf(schema), Object.getOwnPropertyDescriptors(schema)), "~cookieFrom", {
|
|
16
16
|
value: sources,
|
|
17
17
|
writable: true,
|
|
18
18
|
configurable: true
|
|
@@ -20,13 +20,13 @@ const from = (schema, sources) => Object.defineProperty(Object.create(Object.get
|
|
|
20
20
|
const keep = (build, sourcesOf) => ((...args) => {
|
|
21
21
|
const sources = sourcesOf(...args);
|
|
22
22
|
const result = build(...args);
|
|
23
|
-
if (!sources.some((source) =>
|
|
24
|
-
const built =
|
|
23
|
+
if (!sources.some((source) => mayCarryCookieConfig(source))) return result;
|
|
24
|
+
const built = withSources(result, sources);
|
|
25
25
|
const ref = built.$ref;
|
|
26
26
|
const replaced = sources[0]?.$defs?.[ref];
|
|
27
27
|
if (replaced && built.$defs?.[ref] && built.$defs[ref] !== replaced) built.$defs = {
|
|
28
28
|
...built.$defs,
|
|
29
|
-
[ref]:
|
|
29
|
+
[ref]: withSources(built.$defs[ref], [replaced])
|
|
30
30
|
};
|
|
31
31
|
return built;
|
|
32
32
|
});
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { compositionKeys } from "../../utils.mjs";
|
|
2
3
|
import { Composite, Evaluate, Interface, Mapped, Omit, Partial, Pick, ReadonlyObject, Required } from "../typebox-type.mjs";
|
|
3
4
|
|
|
4
5
|
//#region src/type/elysia/keep-config.ts
|
|
5
|
-
const
|
|
6
|
+
const mayCarryCookieConfig = (schema, isProperty = false, seen = /* @__PURE__ */ new Set()) => {
|
|
6
7
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
7
8
|
seen.add(schema);
|
|
8
|
-
if (schema.config !== void 0 || schema.$ref !== void 0 || schema["~kind"] === "Deferred" || compositionKeys.some((key) => Array.isArray(schema[key]) && schema[key].some((member) =>
|
|
9
|
-
if (!
|
|
10
|
-
for (const name in schema.properties) if (
|
|
9
|
+
if (schema.config !== void 0 || schema.$ref !== void 0 || schema["~kind"] === "Deferred" || compositionKeys.some((key) => Array.isArray(schema[key]) && schema[key].some((member) => mayCarryCookieConfig(member, isProperty, seen)))) return true;
|
|
10
|
+
if (!isProperty) {
|
|
11
|
+
for (const name in schema.properties) if (mayCarryCookieConfig(schema.properties[name], true)) return true;
|
|
11
12
|
}
|
|
12
13
|
return false;
|
|
13
14
|
};
|
|
14
|
-
const
|
|
15
|
+
const withSources = (schema, sources) => Object.defineProperty(Object.create(Object.getPrototypeOf(schema), Object.getOwnPropertyDescriptors(schema)), "~cookieFrom", {
|
|
15
16
|
value: sources,
|
|
16
17
|
writable: true,
|
|
17
18
|
configurable: true
|
|
@@ -19,13 +20,13 @@ const from = (schema, sources) => Object.defineProperty(Object.create(Object.get
|
|
|
19
20
|
const keep = (build, sourcesOf) => ((...args) => {
|
|
20
21
|
const sources = sourcesOf(...args);
|
|
21
22
|
const result = build(...args);
|
|
22
|
-
if (!sources.some((source) =>
|
|
23
|
-
const built =
|
|
23
|
+
if (!sources.some((source) => mayCarryCookieConfig(source))) return result;
|
|
24
|
+
const built = withSources(result, sources);
|
|
24
25
|
const ref = built.$ref;
|
|
25
26
|
const replaced = sources[0]?.$defs?.[ref];
|
|
26
27
|
if (replaced && built.$defs?.[ref] && built.$defs[ref] !== replaced) built.$defs = {
|
|
27
28
|
...built.$defs,
|
|
28
|
-
[ref]:
|
|
29
|
+
[ref]: withSources(built.$defs[ref], [replaced])
|
|
29
30
|
};
|
|
30
31
|
return built;
|
|
31
32
|
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { TSchemaOptions } from "typebox";
|
|
1
|
+
import { TSchemaOptions, Type } from "typebox";
|
|
2
2
|
|
|
3
3
|
//#region src/type/elysia/numeric-enum.d.ts
|
|
4
4
|
type AssertNumericEnum<T extends Record<string, string | number>> = { [K in keyof T]: K extends number ? string : K extends `${number}` ? string : K extends string ? number : never };
|
|
5
|
+
type NumericEnumValue<T> = Extract<T[keyof T], number>;
|
|
6
|
+
type NumericEnumSchema<T> = Type.TCodec<Type.TRefine<Type.TUnsafe<NumericEnumValue<T> | `${NumericEnumValue<T>}`>>, NumericEnumValue<T>>;
|
|
5
7
|
/**
|
|
6
8
|
* Numeric enum: accepts a numeric string or a number, decodes to the
|
|
7
9
|
* matching enum value.
|
|
8
10
|
*/
|
|
9
|
-
declare function NumericEnum<T extends AssertNumericEnum<T>>(item: T, property?: TSchemaOptions):
|
|
11
|
+
declare function NumericEnum<T extends AssertNumericEnum<T>>(item: T, property?: TSchemaOptions): Readonly<NumericEnumSchema<T>>;
|
|
10
12
|
//#endregion
|
|
11
13
|
export { AssertNumericEnum, NumericEnum };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ArrayBufferOptions } from "../types.js";
|
|
2
|
+
import * as _$typebox from "typebox";
|
|
2
3
|
|
|
3
4
|
//#region src/type/elysia/uint8-array.d.ts
|
|
4
|
-
declare const Uint8ArrayType: (property?: ArrayBufferOptions) =>
|
|
5
|
+
declare const Uint8ArrayType: (property?: ArrayBufferOptions) => Readonly<_$typebox.TCodec<_$typebox.TRefine<_$typebox.TUnsafe<Uint8Array<ArrayBufferLike>>>, Uint8Array<ArrayBufferLike>>>;
|
|
5
6
|
//#endregion
|
|
6
7
|
export { Uint8ArrayType };
|
|
@@ -4,8 +4,8 @@ const require_type_typebox_type = require('../typebox-type.js');
|
|
|
4
4
|
const require_type_elysia_array_buffer = require('./array-buffer.js');
|
|
5
5
|
|
|
6
6
|
//#region src/type/elysia/uint8-array.ts
|
|
7
|
-
const
|
|
8
|
-
const uint8Array = /* @__PURE__ */ require_type_elysia_array_buffer.bufferType(require_type_constants.ELYSIA_TYPES.Uint8Array, () => require_type_typebox_type.Codec(require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "Uint8Array" }),
|
|
7
|
+
const isUint8ArrayOrArrayBuffer = (value) => value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
8
|
+
const uint8Array = /* @__PURE__ */ require_type_elysia_array_buffer.bufferType(require_type_constants.ELYSIA_TYPES.Uint8Array, () => require_type_typebox_type.Codec(require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "Uint8Array" }), isUint8ArrayOrArrayBuffer, () => "must be Uint8Array")).Decode((value) => value instanceof Uint8Array ? value : new Uint8Array(value)).Encode((value) => value));
|
|
9
9
|
const Uint8ArrayType = (property) => uint8Array(property);
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
2
3
|
import { Codec, Refine, Unsafe } from "../typebox-type.mjs";
|
|
3
4
|
import { bufferType } from "./array-buffer.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/type/elysia/uint8-array.ts
|
|
6
|
-
const
|
|
7
|
-
const uint8Array = /* @__PURE__ */ bufferType(ELYSIA_TYPES.Uint8Array, () => Codec(Refine(Unsafe({ "~kind": "Uint8Array" }),
|
|
7
|
+
const isUint8ArrayOrArrayBuffer = (value) => value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
8
|
+
const uint8Array = /* @__PURE__ */ bufferType(ELYSIA_TYPES.Uint8Array, () => Codec(Refine(Unsafe({ "~kind": "Uint8Array" }), isUint8ArrayOrArrayBuffer, () => "must be Uint8Array")).Decode((value) => value instanceof Uint8Array ? value : new Uint8Array(value)).Encode((value) => value));
|
|
8
9
|
const Uint8ArrayType = (property) => uint8Array(property);
|
|
9
10
|
|
|
10
11
|
//#endregion
|
|
@@ -25,9 +25,9 @@ function createSharedReference(createType) {
|
|
|
25
25
|
const hash = propertyChecksum(property);
|
|
26
26
|
if (hash[1]) return createType(property);
|
|
27
27
|
const h = hash[0];
|
|
28
|
-
const
|
|
28
|
+
const serialized = JSON.stringify(property);
|
|
29
29
|
const bucket = shared.get(h);
|
|
30
|
-
if (bucket?.key ===
|
|
30
|
+
if (bucket?.key === serialized) {
|
|
31
31
|
if (shared.size >= 1024) {
|
|
32
32
|
shared.delete(h);
|
|
33
33
|
shared.set(h, bucket);
|
|
@@ -37,7 +37,7 @@ function createSharedReference(createType) {
|
|
|
37
37
|
const schema = Object.freeze(createType(property));
|
|
38
38
|
if (!bucket && shared.size >= 1024) require_utils.evictOldestHalf(shared);
|
|
39
39
|
shared.set(h, {
|
|
40
|
-
key:
|
|
40
|
+
key: serialized,
|
|
41
41
|
schema
|
|
42
42
|
});
|
|
43
43
|
return schema;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { evictOldestHalf, fnv1a } from "../../utils.mjs";
|
|
2
3
|
import { SHARED_REFERENCE_CACHE_LIMIT, copyNonEnumerable, referenceCache } from "../shared.mjs";
|
|
3
4
|
import { Refine } from "../typebox-type.mjs";
|
|
@@ -24,9 +25,9 @@ function createSharedReference(createType) {
|
|
|
24
25
|
const hash = propertyChecksum(property);
|
|
25
26
|
if (hash[1]) return createType(property);
|
|
26
27
|
const h = hash[0];
|
|
27
|
-
const
|
|
28
|
+
const serialized = JSON.stringify(property);
|
|
28
29
|
const bucket = shared.get(h);
|
|
29
|
-
if (bucket?.key ===
|
|
30
|
+
if (bucket?.key === serialized) {
|
|
30
31
|
if (shared.size >= 1024) {
|
|
31
32
|
shared.delete(h);
|
|
32
33
|
shared.set(h, bucket);
|
|
@@ -36,7 +37,7 @@ function createSharedReference(createType) {
|
|
|
36
37
|
const schema = Object.freeze(createType(property));
|
|
37
38
|
if (!bucket && shared.size >= 1024) evictOldestHalf(shared);
|
|
38
39
|
shared.set(h, {
|
|
39
|
-
key:
|
|
40
|
+
key: serialized,
|
|
40
41
|
schema
|
|
41
42
|
});
|
|
42
43
|
return schema;
|
package/dist/type/exports.mjs
CHANGED
package/dist/type/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { loadTypeNamespace, markTypeUsed } from "./typebox-type.mjs";
|
|
2
3
|
import { ArrayType } from "./elysia/array.mjs";
|
|
3
4
|
import { StringType } from "./elysia/string.mjs";
|
|
@@ -113,7 +114,7 @@ const t = lazyNamespace(() => loadTypeNamespace().type, {
|
|
|
113
114
|
* `typebox/system` is a subgraph of `typebox/type`, so a static re-export here
|
|
114
115
|
* would pin ~231 KB of the deferral back into the eager graph. The proxy also
|
|
115
116
|
* guarantees Elysia's own `Settings` default lands BEFORE the namespace is
|
|
116
|
-
* handed out, keeping a user's explicit `TypeSystem.Settings.Set(...)` last
|
|
117
|
+
* handed out, keeping a user's explicit `TypeSystem.Settings.Set(...)` last \u2014
|
|
117
118
|
* the ordering the eager `setupTypebox()` used to provide
|
|
118
119
|
*/
|
|
119
120
|
const TypeSystem = lazyNamespace(() => typeSystem(loadTypeNamespace().system), Object.create(null));
|
package/dist/type/shared.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import * as type from "typebox/type";
|
|
2
3
|
import { Codec, Composite, Decode, Evaluate, Interface, Intersect, Mapped, Module, Null, Omit, Partial, Pick, ReadonlyObject, Ref, Refine, Required, Undefined, Unsafe } from "typebox/type";
|
|
3
4
|
import * as system from "./typebox-system-lite.mjs";
|
package/dist/type/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ELYSIA_TYPES } from "./constants.js";
|
|
2
1
|
import { CookieOptions } from "../cookie/types.js";
|
|
2
|
+
import { ELYSIA_TYPES } from "./constants.js";
|
|
3
3
|
import { TObjectOptions, TSchemaOptions } from "typebox";
|
|
4
4
|
import { TLocalizedValidationError } from "typebox/error";
|
|
5
5
|
|
package/dist/type/types.mjs
CHANGED
package/dist/type/utils.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_utils = require('../../utils.js');
|
|
3
|
-
const require_error = require('../../error.js');
|
|
4
3
|
const require_compile_aot = require('../../compile/aot.js');
|
|
5
4
|
const require_type_typebox_value = require('../typebox-value.js');
|
|
6
5
|
const require_type_validator_frozen_check = require('./frozen-check.js');
|
|
@@ -8,10 +7,10 @@ const require_type_validator_frozen_check = require('./frozen-check.js');
|
|
|
8
7
|
//#region src/type/validator/custom-error.ts
|
|
9
8
|
function encodePointer(segments) {
|
|
10
9
|
let out = "";
|
|
11
|
-
for (const s of segments) out += "/" + s.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
10
|
+
for (const s of segments) out += "/" + (typeof s === "object" ? "[]" : String(s).replace(/~/g, "~0").replace(/\//g, "~1"));
|
|
12
11
|
return out;
|
|
13
12
|
}
|
|
14
|
-
function collectCustomErrorNodes(schema, segments, out, seen, union) {
|
|
13
|
+
function collectCustomErrorNodes(schema, segments, out, seen, union, required) {
|
|
15
14
|
if (!schema || typeof schema !== "object") return out;
|
|
16
15
|
if (seen.has(schema)) return out;
|
|
17
16
|
seen.add(schema);
|
|
@@ -19,22 +18,16 @@ function collectCustomErrorNodes(schema, segments, out, seen, union) {
|
|
|
19
18
|
path: encodePointer(segments),
|
|
20
19
|
node: schema,
|
|
21
20
|
segments,
|
|
21
|
+
required,
|
|
22
22
|
union
|
|
23
23
|
});
|
|
24
|
-
if (schema.properties)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
else if (items && typeof items === "object") {
|
|
28
|
-
const inner = [];
|
|
29
|
-
collectCustomErrorNodes(items, [], inner, seen, union);
|
|
30
|
-
for (const child of inner) out.push({
|
|
31
|
-
path: encodePointer(segments) + "/[]" + child.path,
|
|
32
|
-
node: child.node,
|
|
33
|
-
segments,
|
|
34
|
-
each: { itemSegments: child.segments },
|
|
35
|
-
union: child.union
|
|
36
|
-
});
|
|
24
|
+
if (schema.properties) {
|
|
25
|
+
const keys = union?.segments !== segments && Array.isArray(schema.required) ? schema.required : void 0;
|
|
26
|
+
for (const k in schema.properties) collectCustomErrorNodes(schema.properties[k], [...segments, k], out, seen, union, keys?.includes(k));
|
|
37
27
|
}
|
|
28
|
+
const items = schema.items;
|
|
29
|
+
if (Array.isArray(items)) for (let i = 0; i < items.length; i++) collectCustomErrorNodes(items[i], [...segments, i], out, seen, union);
|
|
30
|
+
else if (items && typeof items === "object") collectCustomErrorNodes(items, [...segments, { items }], out, seen, union);
|
|
38
31
|
const branches = schema.anyOf ?? schema.oneOf;
|
|
39
32
|
if (Array.isArray(branches)) for (let i = 0; i < branches.length; i++) collectCustomErrorNodes(branches[i], segments, out, seen, {
|
|
40
33
|
node: schema,
|
|
@@ -77,26 +70,43 @@ function buildFindCustomError(schema, frozen) {
|
|
|
77
70
|
const nodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
|
|
78
71
|
if (!nodes.length) return;
|
|
79
72
|
const frozenByPath = frozen?.ce ? new Map(frozen.ce.map((e) => [e.p, e])) : void 0;
|
|
80
|
-
const
|
|
73
|
+
const checkCache = /* @__PURE__ */ new WeakMap();
|
|
81
74
|
const discriminatorCache = /* @__PURE__ */ new WeakMap();
|
|
82
|
-
const
|
|
83
|
-
const cached =
|
|
75
|
+
const compileOnce = (node) => {
|
|
76
|
+
const cached = checkCache.get(node);
|
|
84
77
|
if (cached) return cached;
|
|
85
78
|
try {
|
|
86
79
|
const uc = require_type_typebox_value.SchemaCompile(node);
|
|
87
80
|
const fn = (v) => uc.Check(v);
|
|
88
|
-
|
|
81
|
+
checkCache.set(node, fn);
|
|
89
82
|
return fn;
|
|
90
83
|
} catch {
|
|
91
84
|
return;
|
|
92
85
|
}
|
|
93
86
|
};
|
|
87
|
+
let found;
|
|
88
|
+
const reach = (value, segments) => {
|
|
89
|
+
let current = value;
|
|
90
|
+
for (let i = 0; i < segments.length; i++) {
|
|
91
|
+
const s = segments[i];
|
|
92
|
+
if (current === null || typeof current !== "object" || Array.isArray(current) === (typeof s === "string")) return -1;
|
|
93
|
+
if (typeof s === "object") {
|
|
94
|
+
const check = compileOnce(s.items);
|
|
95
|
+
const at = check ? current.findIndex((x) => !check(x)) : -1;
|
|
96
|
+
if (at < 0) return -1;
|
|
97
|
+
current = current[at];
|
|
98
|
+
} else if (s in current) current = current[s];
|
|
99
|
+
else return i === segments.length - 1 ? 0 : -1;
|
|
100
|
+
}
|
|
101
|
+
found = current;
|
|
102
|
+
return 1;
|
|
103
|
+
};
|
|
94
104
|
const discriminatorsOf = (node, branches) => {
|
|
95
105
|
if (!discriminatorCache.has(node)) discriminatorCache.set(node, findDiscriminators(branches));
|
|
96
106
|
return discriminatorCache.get(node) ?? void 0;
|
|
97
107
|
};
|
|
98
108
|
const checks = [];
|
|
99
|
-
for (const { path, node,
|
|
109
|
+
for (const { path, node, segments, required, union } of nodes) {
|
|
100
110
|
let check;
|
|
101
111
|
const fe = union ? void 0 : frozenByPath?.get(path);
|
|
102
112
|
if (fe) try {
|
|
@@ -107,23 +117,19 @@ function buildFindCustomError(schema, frozen) {
|
|
|
107
117
|
check = (v) => c.Check(v);
|
|
108
118
|
} catch {}
|
|
109
119
|
if (!check) continue;
|
|
110
|
-
if (each) {
|
|
111
|
-
const leafCheck = check;
|
|
112
|
-
const itemSegments = each.itemSegments;
|
|
113
|
-
check = (v) => !Array.isArray(v) || v.every((x) => leafCheck(require_error.subValueAt(x, itemSegments)));
|
|
114
|
-
}
|
|
115
120
|
let gate;
|
|
116
121
|
if (union) {
|
|
117
122
|
const branches = union.node.anyOf ?? union.node.oneOf ?? [];
|
|
118
123
|
const discriminators = discriminatorsOf(union.node, branches);
|
|
119
124
|
if (!discriminators) gate = () => true;
|
|
120
125
|
else {
|
|
121
|
-
const unionCheck =
|
|
126
|
+
const unionCheck = compileOnce(union.node);
|
|
122
127
|
if (!unionCheck) continue;
|
|
123
128
|
const unionSegments = union.segments;
|
|
124
129
|
const branchIndex = union.branchIndex;
|
|
125
130
|
gate = (root) => {
|
|
126
|
-
|
|
131
|
+
if (reach(root, unionSegments) < 1) return true;
|
|
132
|
+
const unionValue = found;
|
|
127
133
|
if (unionCheck(unionValue)) return true;
|
|
128
134
|
if (unionValue === null || typeof unionValue !== "object") return true;
|
|
129
135
|
let matches = 0;
|
|
@@ -146,7 +152,7 @@ function buildFindCustomError(schema, frozen) {
|
|
|
146
152
|
}
|
|
147
153
|
checks.push({
|
|
148
154
|
segments,
|
|
149
|
-
|
|
155
|
+
required,
|
|
150
156
|
check,
|
|
151
157
|
gate,
|
|
152
158
|
path,
|
|
@@ -154,11 +160,13 @@ function buildFindCustomError(schema, frozen) {
|
|
|
154
160
|
});
|
|
155
161
|
}
|
|
156
162
|
if (!checks.length) return;
|
|
157
|
-
checks.sort((a, b) => b.segments.length - a.segments.length
|
|
163
|
+
checks.sort((a, b) => b.segments.length - a.segments.length);
|
|
158
164
|
return (value) => {
|
|
159
165
|
for (const c of checks) {
|
|
160
166
|
if (c.gate && c.gate(value)) continue;
|
|
161
|
-
|
|
167
|
+
const at = reach(value, c.segments);
|
|
168
|
+
if (at < 0 || !at && !c.required) continue;
|
|
169
|
+
if (!at || !c.check(found)) return {
|
|
162
170
|
instancePath: c.path,
|
|
163
171
|
error: c.error
|
|
164
172
|
};
|
|
@@ -169,8 +177,8 @@ function captureCustomErrors(schema) {
|
|
|
169
177
|
const ceNodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
|
|
170
178
|
if (!ceNodes.length) return;
|
|
171
179
|
const entries = [];
|
|
172
|
-
for (const { path, node, union,
|
|
173
|
-
if (union ||
|
|
180
|
+
for (const { path, node, union, segments } of ceNodes) {
|
|
181
|
+
if (union || segments.some((s) => typeof s === "object")) continue;
|
|
174
182
|
try {
|
|
175
183
|
const cf = require_type_validator_frozen_check.buildFrozenCheck(require_type_typebox_value.Build(node), node);
|
|
176
184
|
if (cf) entries.push({
|