elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/type/compat.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_type_bridge = require('./bridge.js');
|
|
4
3
|
const require_type_utils = require('./utils.js');
|
|
4
|
+
const require_type_typebox_type = require('./typebox-type.js');
|
|
5
|
+
const require_type_typebox_value = require('./typebox-value.js');
|
|
5
6
|
const require_type_coerce = require('./coerce.js');
|
|
6
7
|
const require_type_validator_exact_mirror = require('./validator/exact-mirror.js');
|
|
7
8
|
const require_type_validator_validator_cache = require('./validator/validator-cache.js');
|
|
8
9
|
const require_type_validator_index = require('./validator/index.js');
|
|
9
10
|
const require_type_elysia_intersect = require('./elysia/intersect.js');
|
|
10
|
-
let typebox_type = require("typebox/type");
|
|
11
|
-
let typebox_compile = require("typebox/compile");
|
|
12
|
-
let typebox_value = require("typebox/value");
|
|
13
|
-
let typebox_system = require("typebox/system");
|
|
14
11
|
|
|
15
12
|
//#region src/type/compat.ts
|
|
16
13
|
let setup = false;
|
|
17
14
|
function setupTypebox(options) {
|
|
18
15
|
if (options?.exactMirror) require_type_validator_exact_mirror.setExactMirror(options.exactMirror);
|
|
16
|
+
const typebox = options?.typebox;
|
|
17
|
+
if (typebox) {
|
|
18
|
+
if (!typebox.type !== !typebox.system) throw new Error(`setupTypebox({ typebox }) received an incomplete type-side namespace (only '${typebox.type ? "type" : "system"}' was set). 'type' and 'system' must be provided together.`);
|
|
19
|
+
const missing = [
|
|
20
|
+
"value",
|
|
21
|
+
"schema",
|
|
22
|
+
"compile"
|
|
23
|
+
].filter((key) => !typebox[key]);
|
|
24
|
+
if (missing.length === 1 || missing.length === 2) throw new Error(`setupTypebox({ typebox }) received an incomplete value-side namespace (missing '${missing.join("', '")}'). 'value', 'schema', and 'compile' must be provided together.`);
|
|
25
|
+
if (typebox.type && typebox.system) require_type_typebox_type.injectTypeboxType(typebox);
|
|
26
|
+
if (typebox.value && typebox.schema && typebox.compile) require_type_typebox_value.injectTypebox(typebox);
|
|
27
|
+
}
|
|
19
28
|
if (setup) return;
|
|
20
29
|
setup = true;
|
|
21
|
-
typebox_system.Settings.Set({ unionPrioritySort: false });
|
|
22
30
|
require_type_bridge.useTypebox({
|
|
23
|
-
Compile:
|
|
24
|
-
Create:
|
|
25
|
-
Decode:
|
|
31
|
+
Compile: require_type_typebox_value.Compile,
|
|
32
|
+
Create: require_type_typebox_value.Create,
|
|
33
|
+
Decode: require_type_typebox_value.Decode,
|
|
26
34
|
applyCoercions: require_type_coerce.applyCoercions,
|
|
27
35
|
TypeBoxValidator: require_type_validator_index.TypeBoxValidator,
|
|
28
36
|
TypeBoxValidatorCache: require_type_validator_validator_cache.TypeBoxValidatorCache,
|
|
@@ -33,12 +41,13 @@ function setupTypebox(options) {
|
|
|
33
41
|
coerceBody: require_type_coerce.coerceBody,
|
|
34
42
|
hasTypes: require_type_utils.hasTypes,
|
|
35
43
|
mayHaveFileType: require_type_validator_validator_cache.mayHaveFileType,
|
|
36
|
-
HasCodec:
|
|
44
|
+
HasCodec: require_type_typebox_value.HasCodec,
|
|
37
45
|
Intersect: require_type_elysia_intersect.Intersect,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
Ref: require_type_typebox_type.Ref,
|
|
47
|
+
Clone: require_type_typebox_value.Clone,
|
|
48
|
+
Check: require_type_typebox_value.Check,
|
|
49
|
+
warmTypebox: require_type_typebox_value.warmTypebox,
|
|
50
|
+
preloadTypebox: require_type_typebox_value.preloadTypebox
|
|
42
51
|
});
|
|
43
52
|
}
|
|
44
53
|
|
package/dist/type/compat.mjs
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import { useTypebox } from "./bridge.mjs";
|
|
2
2
|
import { hasTypes } from "./utils.mjs";
|
|
3
|
+
import { Ref, injectTypeboxType } from "./typebox-type.mjs";
|
|
4
|
+
import { Check, Clone, Compile, Create, Decode, HasCodec, injectTypebox, preloadTypebox, warmTypebox as load } from "./typebox-value.mjs";
|
|
3
5
|
import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.mjs";
|
|
4
6
|
import { setExactMirror } from "./validator/exact-mirror.mjs";
|
|
5
7
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.mjs";
|
|
6
8
|
import { TypeBoxValidator } from "./validator/index.mjs";
|
|
7
|
-
import { Intersect
|
|
8
|
-
import { Ref } from "typebox/type";
|
|
9
|
-
import { Compile } from "typebox/compile";
|
|
10
|
-
import { Check, Clone, Create, Decode as Decode$1, Default, HasCodec } from "typebox/value";
|
|
11
|
-
import { Settings } from "typebox/system";
|
|
9
|
+
import { Intersect } from "./elysia/intersect.mjs";
|
|
12
10
|
|
|
13
11
|
//#region src/type/compat.ts
|
|
14
12
|
let setup = false;
|
|
15
13
|
function setupTypebox(options) {
|
|
16
14
|
if (options?.exactMirror) setExactMirror(options.exactMirror);
|
|
15
|
+
const typebox = options?.typebox;
|
|
16
|
+
if (typebox) {
|
|
17
|
+
if (!typebox.type !== !typebox.system) throw new Error(`setupTypebox({ typebox }) received an incomplete type-side namespace (only '${typebox.type ? "type" : "system"}' was set). 'type' and 'system' must be provided together.`);
|
|
18
|
+
const missing = [
|
|
19
|
+
"value",
|
|
20
|
+
"schema",
|
|
21
|
+
"compile"
|
|
22
|
+
].filter((key) => !typebox[key]);
|
|
23
|
+
if (missing.length === 1 || missing.length === 2) throw new Error(`setupTypebox({ typebox }) received an incomplete value-side namespace (missing '${missing.join("', '")}'). 'value', 'schema', and 'compile' must be provided together.`);
|
|
24
|
+
if (typebox.type && typebox.system) injectTypeboxType(typebox);
|
|
25
|
+
if (typebox.value && typebox.schema && typebox.compile) injectTypebox(typebox);
|
|
26
|
+
}
|
|
17
27
|
if (setup) return;
|
|
18
28
|
setup = true;
|
|
19
|
-
Settings.Set({ unionPrioritySort: false });
|
|
20
29
|
useTypebox({
|
|
21
30
|
Compile,
|
|
22
31
|
Create,
|
|
23
|
-
Decode
|
|
32
|
+
Decode,
|
|
24
33
|
applyCoercions,
|
|
25
34
|
TypeBoxValidator,
|
|
26
35
|
TypeBoxValidatorCache,
|
|
@@ -32,11 +41,12 @@ function setupTypebox(options) {
|
|
|
32
41
|
hasTypes,
|
|
33
42
|
mayHaveFileType,
|
|
34
43
|
HasCodec,
|
|
35
|
-
Intersect
|
|
36
|
-
Default,
|
|
44
|
+
Intersect,
|
|
37
45
|
Ref,
|
|
38
46
|
Clone,
|
|
39
|
-
Check
|
|
47
|
+
Check,
|
|
48
|
+
warmTypebox: load,
|
|
49
|
+
preloadTypebox
|
|
40
50
|
});
|
|
41
51
|
}
|
|
42
52
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { ELYSIA_TYPES } from "../constants.js";
|
|
1
2
|
import { ArrayBufferOptions } from "../types.js";
|
|
3
|
+
import { TSchema } from "typebox";
|
|
2
4
|
|
|
3
5
|
//#region src/type/elysia/array-buffer.d.ts
|
|
6
|
+
declare function bufferType(tag: ELYSIA_TYPES[keyof ELYSIA_TYPES], base: () => TSchema): (property?: ArrayBufferOptions) => any;
|
|
4
7
|
declare function ArrayBufferType(property?: ArrayBufferOptions): any;
|
|
5
8
|
//#endregion
|
|
6
|
-
export { ArrayBufferType };
|
|
9
|
+
export { ArrayBufferType, bufferType };
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
3
|
const require_type_constants = require('../constants.js');
|
|
4
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
5
5
|
const require_type_elysia_utils = require('./utils.js');
|
|
6
|
-
let typebox_type = require("typebox/type");
|
|
7
6
|
|
|
8
7
|
//#region src/type/elysia/array-buffer.ts
|
|
9
|
-
|
|
10
|
-
let
|
|
8
|
+
function bufferType(tag, base) {
|
|
9
|
+
let Base;
|
|
10
|
+
let empty;
|
|
11
|
+
return (property) => {
|
|
12
|
+
Base ??= base();
|
|
13
|
+
if (!property || require_utils.isEmpty(property)) return empty ??= Object.freeze(require_type_elysia_utils.elyType(tag, Base));
|
|
14
|
+
const refines = [];
|
|
15
|
+
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
16
|
+
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
17
|
+
return require_type_elysia_utils.elyType(tag, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(Base, refines), property));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const arrayBuffer = /* @__PURE__ */ bufferType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, () => require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer"));
|
|
11
21
|
function ArrayBufferType(property) {
|
|
12
|
-
|
|
13
|
-
if (!property || require_utils.isEmpty(property)) return emptyArrayBuffer ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, BaseArrayBuffer));
|
|
14
|
-
const refines = [[(value) => value instanceof ArrayBuffer, "must be ArrayBuffer"]];
|
|
15
|
-
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
16
|
-
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
17
|
-
let schema = require_type_elysia_utils.Refines(BaseArrayBuffer, refines);
|
|
18
|
-
const [, meta] = require_type_elysia_utils.getMeta(property);
|
|
19
|
-
if (meta) {
|
|
20
|
-
schema = require_type_elysia_utils.cloneSchema(schema);
|
|
21
|
-
Object.assign(schema, meta);
|
|
22
|
-
}
|
|
23
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, schema);
|
|
22
|
+
return arrayBuffer(property);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
//#endregion
|
|
27
|
-
exports.ArrayBufferType = ArrayBufferType;
|
|
26
|
+
exports.ArrayBufferType = ArrayBufferType;
|
|
27
|
+
exports.bufferType = bufferType;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { isEmpty } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Refine, Unsafe } from "../typebox-type.mjs";
|
|
4
|
+
import { Refines, elyType, withMeta } from "./utils.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/type/elysia/array-buffer.ts
|
|
7
|
-
|
|
8
|
-
let
|
|
7
|
+
function bufferType(tag, base) {
|
|
8
|
+
let Base;
|
|
9
|
+
let empty;
|
|
10
|
+
return (property) => {
|
|
11
|
+
Base ??= base();
|
|
12
|
+
if (!property || isEmpty(property)) return empty ??= Object.freeze(elyType(tag, Base));
|
|
13
|
+
const refines = [];
|
|
14
|
+
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
15
|
+
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
16
|
+
return elyType(tag, withMeta(Refines(Base, refines), property));
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const arrayBuffer = /* @__PURE__ */ bufferType(ELYSIA_TYPES.ArrayBuffer, () => Refine(Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer"));
|
|
9
20
|
function ArrayBufferType(property) {
|
|
10
|
-
|
|
11
|
-
if (!property || isEmpty(property)) return emptyArrayBuffer ??= Object.freeze(elyType(ELYSIA_TYPES.ArrayBuffer, BaseArrayBuffer));
|
|
12
|
-
const refines = [[(value) => value instanceof ArrayBuffer, "must be ArrayBuffer"]];
|
|
13
|
-
if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
|
|
14
|
-
if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
|
|
15
|
-
let schema = Refines(BaseArrayBuffer, refines);
|
|
16
|
-
const [, meta] = getMeta(property);
|
|
17
|
-
if (meta) {
|
|
18
|
-
schema = cloneSchema(schema);
|
|
19
|
-
Object.assign(schema, meta);
|
|
20
|
-
}
|
|
21
|
-
return elyType(ELYSIA_TYPES.ArrayBuffer, schema);
|
|
21
|
+
return arrayBuffer(property);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
|
-
export { ArrayBufferType };
|
|
25
|
+
export { ArrayBufferType, bufferType };
|
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
|
-
const require_type_bridge = require('../bridge.js');
|
|
5
3
|
const require_type_constants = require('../constants.js');
|
|
6
4
|
const require_type_elysia_array = require('./array.js');
|
|
7
|
-
const
|
|
5
|
+
const require_type_elysia_json_string = require('./json-string.js');
|
|
8
6
|
const require_type_elysia_union = require('./union.js');
|
|
9
7
|
const require_type_elysia_utils = require('./utils.js');
|
|
10
|
-
let typebox_type = require("typebox/type");
|
|
11
8
|
|
|
12
9
|
//#region src/type/elysia/array-string.ts
|
|
13
|
-
const MEMO_LIMIT = 8192;
|
|
14
10
|
function ArrayString(property, _options) {
|
|
15
11
|
const [constraints, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
|
|
16
12
|
const array = require_type_elysia_array.ArrayType(property, constraints);
|
|
17
|
-
|
|
18
|
-
const checkInner = (value) => {
|
|
19
|
-
if (!check) try {
|
|
20
|
-
const compiled = require_type_bridge.Compile(array);
|
|
21
|
-
if (compiled.evaluateResult) compiled.evaluateResult.code = void 0;
|
|
22
|
-
if (compiled.buildResult) compiled.buildResult.functions = void 0;
|
|
23
|
-
check = (v) => compiled.Check(v);
|
|
24
|
-
} catch {
|
|
25
|
-
check = (v) => require_type_bridge.Check(array, v);
|
|
26
|
-
}
|
|
27
|
-
return check(value);
|
|
28
|
-
};
|
|
29
|
-
let raw;
|
|
30
|
-
let parsed;
|
|
31
|
-
const arrayString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), (value) => {
|
|
32
|
-
if (value.charCodeAt(0) !== 91) return false;
|
|
33
|
-
if (value === raw) return true;
|
|
34
|
-
try {
|
|
35
|
-
const next = JSON.parse(value);
|
|
36
|
-
if (!checkInner(next)) return false;
|
|
37
|
-
if (value.length <= MEMO_LIMIT) {
|
|
38
|
-
raw = value;
|
|
39
|
-
parsed = next;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
} catch {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}, () => "must be an array"), (value) => {
|
|
46
|
-
const decoded = value === raw ? parsed : JSON.parse(value);
|
|
47
|
-
raw = void 0;
|
|
48
|
-
parsed = void 0;
|
|
49
|
-
return require_type_bridge.Decode(array, decoded);
|
|
50
|
-
});
|
|
51
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, arrayString], meta));
|
|
13
|
+
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, require_type_elysia_json_string.jsonString(array, 91, "must be an array")], meta));
|
|
52
14
|
}
|
|
53
15
|
|
|
54
16
|
//#endregion
|
|
@@ -1,52 +1,15 @@
|
|
|
1
1
|
import { nullObject } from "../../utils.mjs";
|
|
2
|
-
import { Check, Compile, Decode as Decode$1 } from "../bridge.mjs";
|
|
3
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
4
3
|
import { ArrayType } from "./array.mjs";
|
|
5
|
-
import {
|
|
4
|
+
import { jsonString } from "./json-string.mjs";
|
|
6
5
|
import { Union } from "./union.mjs";
|
|
7
6
|
import { elyType, getMeta } from "./utils.mjs";
|
|
8
|
-
import { Decode, Refine } from "typebox/type";
|
|
9
7
|
|
|
10
8
|
//#region src/type/elysia/array-string.ts
|
|
11
|
-
const MEMO_LIMIT = 8192;
|
|
12
9
|
function ArrayString(property, _options) {
|
|
13
10
|
const [constraints, meta] = getMeta(_options ?? nullObject());
|
|
14
11
|
const array = ArrayType(property, constraints);
|
|
15
|
-
|
|
16
|
-
const checkInner = (value) => {
|
|
17
|
-
if (!check) try {
|
|
18
|
-
const compiled = Compile(array);
|
|
19
|
-
if (compiled.evaluateResult) compiled.evaluateResult.code = void 0;
|
|
20
|
-
if (compiled.buildResult) compiled.buildResult.functions = void 0;
|
|
21
|
-
check = (v) => compiled.Check(v);
|
|
22
|
-
} catch {
|
|
23
|
-
check = (v) => Check(array, v);
|
|
24
|
-
}
|
|
25
|
-
return check(value);
|
|
26
|
-
};
|
|
27
|
-
let raw;
|
|
28
|
-
let parsed;
|
|
29
|
-
const arrayString = Decode(Refine(StringType(), (value) => {
|
|
30
|
-
if (value.charCodeAt(0) !== 91) return false;
|
|
31
|
-
if (value === raw) return true;
|
|
32
|
-
try {
|
|
33
|
-
const next = JSON.parse(value);
|
|
34
|
-
if (!checkInner(next)) return false;
|
|
35
|
-
if (value.length <= MEMO_LIMIT) {
|
|
36
|
-
raw = value;
|
|
37
|
-
parsed = next;
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
} catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}, () => "must be an array"), (value) => {
|
|
44
|
-
const decoded = value === raw ? parsed : JSON.parse(value);
|
|
45
|
-
raw = void 0;
|
|
46
|
-
parsed = void 0;
|
|
47
|
-
return Decode$1(array, decoded);
|
|
48
|
-
});
|
|
49
|
-
return elyType(ELYSIA_TYPES.ArrayString, Union([array, arrayString], meta));
|
|
12
|
+
return elyType(ELYSIA_TYPES.ArrayString, Union([array, jsonString(array, 91, "must be an array")], meta));
|
|
50
13
|
}
|
|
51
14
|
|
|
52
15
|
//#endregion
|
|
@@ -2,23 +2,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_utils = require('../../utils.js');
|
|
3
3
|
|
|
4
4
|
//#region src/type/elysia/array.ts
|
|
5
|
-
|
|
5
|
+
const arrayKind = {
|
|
6
|
+
value: "Array",
|
|
7
|
+
enumerable: false
|
|
8
|
+
};
|
|
6
9
|
let arrayProto;
|
|
7
10
|
function ArrayType(items, options) {
|
|
8
11
|
if (!options || require_utils.isEmpty(options)) {
|
|
9
|
-
arrayProto ??= Object.defineProperty({}, "~kind",
|
|
10
|
-
value: "Array",
|
|
11
|
-
enumerable: false
|
|
12
|
-
});
|
|
12
|
+
arrayProto ??= Object.defineProperty({}, "~kind", arrayKind);
|
|
13
13
|
const schema = Object.create(arrayProto);
|
|
14
14
|
schema.type = "array";
|
|
15
15
|
schema.items = items;
|
|
16
16
|
return schema;
|
|
17
17
|
}
|
|
18
|
-
arrayKind ??= {
|
|
19
|
-
value: "Array",
|
|
20
|
-
enumerable: false
|
|
21
|
-
};
|
|
22
18
|
const schema = {
|
|
23
19
|
...options,
|
|
24
20
|
type: "array",
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { isEmpty } from "../../utils.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/type/elysia/array.ts
|
|
4
|
-
|
|
4
|
+
const arrayKind = {
|
|
5
|
+
value: "Array",
|
|
6
|
+
enumerable: false
|
|
7
|
+
};
|
|
5
8
|
let arrayProto;
|
|
6
9
|
function ArrayType(items, options) {
|
|
7
10
|
if (!options || isEmpty(options)) {
|
|
8
|
-
arrayProto ??= Object.defineProperty({}, "~kind",
|
|
9
|
-
value: "Array",
|
|
10
|
-
enumerable: false
|
|
11
|
-
});
|
|
11
|
+
arrayProto ??= Object.defineProperty({}, "~kind", arrayKind);
|
|
12
12
|
const schema = Object.create(arrayProto);
|
|
13
13
|
schema.type = "array";
|
|
14
14
|
schema.items = items;
|
|
15
15
|
return schema;
|
|
16
16
|
}
|
|
17
|
-
arrayKind ??= {
|
|
18
|
-
value: "Array",
|
|
19
|
-
enumerable: false
|
|
20
|
-
};
|
|
21
17
|
const schema = {
|
|
22
18
|
...options,
|
|
23
19
|
type: "array",
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
3
|
const require_type_constants = require('../constants.js');
|
|
5
4
|
const require_type_shared = require('../shared.js');
|
|
5
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
6
6
|
const require_type_elysia_string = require('./string.js');
|
|
7
7
|
const require_type_elysia_union = require('./union.js');
|
|
8
8
|
const require_type_elysia_utils = require('./utils.js');
|
|
9
9
|
const require_type_elysia_boolean = require('./boolean.js');
|
|
10
|
-
let typebox_type = require("typebox/type");
|
|
11
10
|
|
|
12
11
|
//#region src/type/elysia/boolean-string.ts
|
|
13
12
|
let StringifiedBoolean;
|
|
14
13
|
let emptyBooleanString;
|
|
15
14
|
function BooleanString(property) {
|
|
16
|
-
StringifiedBoolean ??= require_type_shared.pureRefine(
|
|
15
|
+
StringifiedBoolean ??= require_type_shared.pureRefine(require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), (value) => value === "true" || value === "false", () => "must be boolean"), (value) => value === "true" ? true : false));
|
|
17
16
|
if (!property || require_utils.isEmpty(property)) return emptyBooleanString ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.BooleanString, require_type_elysia_union.Union([require_type_elysia_boolean.BooleanType(), StringifiedBoolean])));
|
|
18
17
|
const [, meta] = require_type_elysia_utils.getMeta(property);
|
|
19
18
|
const boolean = require_type_elysia_boolean.BooleanType(property);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isEmpty } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
3
|
import { pureRefine } from "../shared.mjs";
|
|
4
|
+
import { Decode, Refine } from "../typebox-type.mjs";
|
|
4
5
|
import { StringType } from "./string.mjs";
|
|
5
6
|
import { Union } from "./union.mjs";
|
|
6
7
|
import { elyType, getMeta } from "./utils.mjs";
|
|
7
8
|
import { BooleanType } from "./boolean.mjs";
|
|
8
|
-
import { Decode, Refine } from "typebox/type";
|
|
9
9
|
|
|
10
10
|
//#region src/type/elysia/boolean-string.ts
|
|
11
11
|
let StringifiedBoolean;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const require_utils = require('../../utils.js');
|
|
4
|
-
const require_type_constants = require('../constants.js');
|
|
5
|
-
let typebox_type = require("typebox/type");
|
|
2
|
+
const require_type_elysia_number = require('./number.js');
|
|
6
3
|
|
|
7
4
|
//#region src/type/elysia/boolean.ts
|
|
8
|
-
const
|
|
5
|
+
const boolean = /* @__PURE__ */ require_type_elysia_number.primitive("boolean", "Boolean");
|
|
9
6
|
function BooleanType(options) {
|
|
10
|
-
|
|
11
|
-
const schema = {
|
|
12
|
-
...options,
|
|
13
|
-
type: "boolean",
|
|
14
|
-
"~kind": "Boolean"
|
|
15
|
-
};
|
|
16
|
-
return Object.defineProperty(schema, "~kind", require_type_constants.noEnumerable);
|
|
7
|
+
return boolean(options);
|
|
17
8
|
}
|
|
18
9
|
|
|
19
10
|
//#endregion
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { noEnumerable } from "../constants.mjs";
|
|
3
|
-
import { Boolean } from "typebox/type";
|
|
1
|
+
import { primitive } from "./number.mjs";
|
|
4
2
|
|
|
5
3
|
//#region src/type/elysia/boolean.ts
|
|
6
|
-
const
|
|
4
|
+
const boolean = /* @__PURE__ */ primitive("boolean", "Boolean");
|
|
7
5
|
function BooleanType(options) {
|
|
8
|
-
|
|
9
|
-
const schema = {
|
|
10
|
-
...options,
|
|
11
|
-
type: "boolean",
|
|
12
|
-
"~kind": "Boolean"
|
|
13
|
-
};
|
|
14
|
-
return Object.defineProperty(schema, "~kind", noEnumerable);
|
|
6
|
+
return boolean(options);
|
|
15
7
|
}
|
|
16
8
|
|
|
17
9
|
//#endregion
|
|
@@ -2,14 +2,13 @@ import { CookieValidatorOptions } from "../types.js";
|
|
|
2
2
|
import { TObject, TProperties, TSchema } from "typebox";
|
|
3
3
|
|
|
4
4
|
//#region src/type/elysia/cookie.d.ts
|
|
5
|
-
interface CookieSchemaConfig extends CookieValidatorOptions {}
|
|
6
5
|
interface TCookieObject<T extends TProperties> extends TObject<T> {
|
|
7
|
-
config?:
|
|
6
|
+
config?: CookieValidatorOptions;
|
|
8
7
|
}
|
|
9
8
|
interface TCookieField {
|
|
10
|
-
config?:
|
|
9
|
+
config?: CookieValidatorOptions;
|
|
11
10
|
}
|
|
12
11
|
declare function Cookie<T extends TProperties>(properties: T, options?: CookieValidatorOptions): TCookieObject<T>;
|
|
13
12
|
declare function Cookie<T extends TSchema>(schema: T, options?: CookieValidatorOptions): T & TCookieField;
|
|
14
13
|
//#endregion
|
|
15
|
-
export { Cookie,
|
|
14
|
+
export { Cookie, TCookieField, TCookieObject };
|
|
@@ -13,29 +13,19 @@ const COOKIE_OPTION_KEYS = [
|
|
|
13
13
|
"secure",
|
|
14
14
|
"partitioned",
|
|
15
15
|
"secrets",
|
|
16
|
-
"sign"
|
|
16
|
+
"sign",
|
|
17
|
+
"legacySignature"
|
|
17
18
|
];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config: void 0,
|
|
21
|
-
rest: void 0
|
|
22
|
-
};
|
|
19
|
+
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
20
|
+
function Cookie(first, options) {
|
|
23
21
|
let config;
|
|
24
22
|
let rest;
|
|
25
|
-
for (const key in options) {
|
|
23
|
+
if (options) for (const key in options) {
|
|
26
24
|
const value = options[key];
|
|
27
25
|
if (value === void 0) continue;
|
|
28
26
|
if (COOKIE_OPTION_KEYS.includes(key)) (config ??= {})[key] = value;
|
|
29
27
|
else (rest ??= {})[key] = value;
|
|
30
28
|
}
|
|
31
|
-
return {
|
|
32
|
-
config,
|
|
33
|
-
rest
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
37
|
-
function Cookie(first, options) {
|
|
38
|
-
const { config, rest } = extractConfig(options);
|
|
39
29
|
if (isSchema(first)) {
|
|
40
30
|
if (!config) return first;
|
|
41
31
|
const target = Object.create(Object.getPrototypeOf(first), Object.getOwnPropertyDescriptors(first));
|
|
@@ -12,29 +12,19 @@ const COOKIE_OPTION_KEYS = [
|
|
|
12
12
|
"secure",
|
|
13
13
|
"partitioned",
|
|
14
14
|
"secrets",
|
|
15
|
-
"sign"
|
|
15
|
+
"sign",
|
|
16
|
+
"legacySignature"
|
|
16
17
|
];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
config: void 0,
|
|
20
|
-
rest: void 0
|
|
21
|
-
};
|
|
18
|
+
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
19
|
+
function Cookie(first, options) {
|
|
22
20
|
let config;
|
|
23
21
|
let rest;
|
|
24
|
-
for (const key in options) {
|
|
22
|
+
if (options) for (const key in options) {
|
|
25
23
|
const value = options[key];
|
|
26
24
|
if (value === void 0) continue;
|
|
27
25
|
if (COOKIE_OPTION_KEYS.includes(key)) (config ??= {})[key] = value;
|
|
28
26
|
else (rest ??= {})[key] = value;
|
|
29
27
|
}
|
|
30
|
-
return {
|
|
31
|
-
config,
|
|
32
|
-
rest
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
36
|
-
function Cookie(first, options) {
|
|
37
|
-
const { config, rest } = extractConfig(options);
|
|
38
28
|
if (isSchema(first)) {
|
|
39
29
|
if (!config) return first;
|
|
40
30
|
const target = Object.create(Object.getPrototypeOf(first), Object.getOwnPropertyDescriptors(first));
|
package/dist/type/elysia/date.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
3
|
const require_type_constants = require('../constants.js');
|
|
4
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
5
5
|
const require_type_elysia_string = require('./string.js');
|
|
6
6
|
const require_type_elysia_union = require('./union.js');
|
|
7
7
|
const require_type_elysia_utils = require('./utils.js');
|
|
8
|
-
|
|
8
|
+
const require_type_elysia_number = require('./number.js');
|
|
9
9
|
|
|
10
10
|
//#region src/type/elysia/date.ts
|
|
11
11
|
const ISO8601 = /T\d\d(?::\d\d){1,2} \d\d:\d\d$/;
|
|
12
12
|
const removeTime = / (\d{2}:\d{2})$/;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return t;
|
|
18
|
-
};
|
|
13
|
+
function toDate(value) {
|
|
14
|
+
const date = new Date(value);
|
|
15
|
+
return isNaN(date.getTime()) && typeof value === "string" && ISO8601.test(value) ? new Date(value.replace(removeTime, "+$1")) : date;
|
|
16
|
+
}
|
|
19
17
|
let StringifiedDate;
|
|
20
18
|
let emptyDate;
|
|
21
19
|
let sharedDate;
|
|
22
20
|
function DateType(property) {
|
|
23
|
-
StringifiedDate ??=
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (ISO8601.test(value)) return !isNaN(new Date(value.replace(removeTime, "+$1")).getTime());
|
|
28
|
-
return false;
|
|
29
|
-
}, () => "must be Date"),
|
|
30
|
-
(0, typebox_type.Number)()
|
|
21
|
+
StringifiedDate ??= require_type_typebox_type.Codec(require_type_elysia_union.Union([
|
|
22
|
+
require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "Date" }), (value) => value instanceof Date, () => "must be Date"),
|
|
23
|
+
require_type_typebox_type.Refine(require_type_elysia_string.StringType(), (value) => !isNaN(toDate(value).getTime()), () => "must be Date"),
|
|
24
|
+
require_type_elysia_number.NumberType()
|
|
31
25
|
])).Decode((value) => {
|
|
32
26
|
if (value instanceof Date) return value;
|
|
33
|
-
|
|
34
|
-
if (isNaN(d.getTime()) && typeof value === "string" && /T\d{2}:\d{2}(:\d{2})? \d{2}:\d{2}$/.test(value)) d = new Date(value.replace(/ (\d{2}:\d{2})$/, "+$1"));
|
|
27
|
+
const d = toDate(value);
|
|
35
28
|
if (isNaN(d.getTime())) throw new Error(`Expected Date, got: ${String(value)}`);
|
|
36
29
|
return d;
|
|
37
30
|
}).Encode((value) => {
|
|
@@ -56,8 +49,8 @@ function DateWithProperty(options) {
|
|
|
56
49
|
let schema = StringifiedDate;
|
|
57
50
|
if (minMessage || maxMessage || xMinMessage || xMaxMessage || stepMessage) {
|
|
58
51
|
let failed = "must be Date";
|
|
59
|
-
schema =
|
|
60
|
-
const t =
|
|
52
|
+
schema = require_type_typebox_type.Refine(schema, (value) => {
|
|
53
|
+
const t = value instanceof Date ? value.getTime() : toDate(value).getTime();
|
|
61
54
|
if (minMessage && t < min) {
|
|
62
55
|
failed = minMessage;
|
|
63
56
|
return false;
|