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
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
import { isEmpty } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
|
+
import { Codec, Refine, Unsafe } from "../typebox-type.mjs";
|
|
3
4
|
import { StringType } from "./string.mjs";
|
|
4
5
|
import { Union } from "./union.mjs";
|
|
5
6
|
import { cloneSchema, createSharedReference, elyType, getMeta } from "./utils.mjs";
|
|
6
|
-
import {
|
|
7
|
+
import { NumberType } from "./number.mjs";
|
|
7
8
|
|
|
8
9
|
//#region src/type/elysia/date.ts
|
|
9
10
|
const ISO8601 = /T\d\d(?::\d\d){1,2} \d\d:\d\d$/;
|
|
10
11
|
const removeTime = / (\d{2}:\d{2})$/;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
12
|
+
function toDate(value) {
|
|
13
|
+
const date = new Date(value);
|
|
14
|
+
return isNaN(date.getTime()) && typeof value === "string" && ISO8601.test(value) ? new Date(value.replace(removeTime, "+$1")) : date;
|
|
15
|
+
}
|
|
17
16
|
let StringifiedDate;
|
|
18
17
|
let emptyDate;
|
|
19
18
|
let sharedDate;
|
|
20
19
|
function DateType(property) {
|
|
21
20
|
StringifiedDate ??= Codec(Union([
|
|
22
21
|
Refine(Unsafe({ "~kind": "Date" }), (value) => value instanceof Date, () => "must be Date"),
|
|
23
|
-
Refine(StringType(), (value) =>
|
|
24
|
-
|
|
25
|
-
if (ISO8601.test(value)) return !isNaN(new Date(value.replace(removeTime, "+$1")).getTime());
|
|
26
|
-
return false;
|
|
27
|
-
}, () => "must be Date"),
|
|
28
|
-
Number()
|
|
22
|
+
Refine(StringType(), (value) => !isNaN(toDate(value).getTime()), () => "must be Date"),
|
|
23
|
+
NumberType()
|
|
29
24
|
])).Decode((value) => {
|
|
30
25
|
if (value instanceof Date) return value;
|
|
31
|
-
|
|
32
|
-
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"));
|
|
26
|
+
const d = toDate(value);
|
|
33
27
|
if (isNaN(d.getTime())) throw new Error(`Expected Date, got: ${String(value)}`);
|
|
34
28
|
return d;
|
|
35
29
|
}).Encode((value) => {
|
|
@@ -55,7 +49,7 @@ function DateWithProperty(options) {
|
|
|
55
49
|
if (minMessage || maxMessage || xMinMessage || xMaxMessage || stepMessage) {
|
|
56
50
|
let failed = "must be Date";
|
|
57
51
|
schema = Refine(schema, (value) => {
|
|
58
|
-
const t =
|
|
52
|
+
const t = value instanceof Date ? value.getTime() : toDate(value).getTime();
|
|
59
53
|
if (minMessage && t < min) {
|
|
60
54
|
failed = minMessage;
|
|
61
55
|
return false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MaybeArray, MaybePromise } from "../../types.js";
|
|
2
1
|
import { FileType, FileUnit } from "../types.js";
|
|
2
|
+
import { MaybeArray, MaybePromise } from "../../types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/type/elysia/file-type.d.ts
|
|
5
5
|
type FileTypeDetector = (file: File) => MaybePromise<string | {
|
|
@@ -13,13 +13,20 @@ interface PendingFileTypeCheck {
|
|
|
13
13
|
* (identity walk on failure only) for a path-aware error */
|
|
14
14
|
file: File;
|
|
15
15
|
}
|
|
16
|
+
declare const MAX_QUEUED_FILE_TYPE_CHECKS = 64;
|
|
17
|
+
/** per-slot detector budget, reset on each validation pass via `epoch` */
|
|
18
|
+
interface FileTypeBudget {
|
|
19
|
+
epoch: number;
|
|
20
|
+
count: number;
|
|
21
|
+
limit: number;
|
|
22
|
+
}
|
|
16
23
|
declare const ASYNC_REFINE = "~elyAsyncRefine";
|
|
17
|
-
declare const isAsyncPredicate: (v:
|
|
24
|
+
declare const isAsyncPredicate: (v: any) => boolean;
|
|
18
25
|
declare function collectFileTypeChecks(): void;
|
|
19
26
|
declare function takeFileTypeChecks(): PendingFileTypeCheck[] | undefined;
|
|
20
|
-
declare function maybeQueueFileTypeCheck(value: File, types: FileType[], message: string): void;
|
|
27
|
+
declare function maybeQueueFileTypeCheck(value: File, types: FileType[], message: string, budget: FileTypeBudget): void;
|
|
21
28
|
declare function matchesAnyFileType(mime: string, types: FileType[]): boolean;
|
|
22
29
|
declare function checkFileExtension(type: string, extension: string): boolean;
|
|
23
30
|
declare function parseFileUnit(size: FileUnit): number;
|
|
24
31
|
//#endregion
|
|
25
|
-
export { ASYNC_REFINE, FileTypeDetector, PendingFileTypeCheck, checkFileExtension, collectFileTypeChecks, fileType, isAsyncPredicate, matchesAnyFileType, maybeQueueFileTypeCheck, parseFileUnit, setFileTypeDetector, takeFileTypeChecks };
|
|
32
|
+
export { ASYNC_REFINE, FileTypeBudget, FileTypeDetector, MAX_QUEUED_FILE_TYPE_CHECKS, PendingFileTypeCheck, checkFileExtension, collectFileTypeChecks, fileType, isAsyncPredicate, matchesAnyFileType, maybeQueueFileTypeCheck, parseFileUnit, setFileTypeDetector, takeFileTypeChecks };
|
|
@@ -33,11 +33,14 @@ async function fileType(file, type) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
let collecting = false;
|
|
36
|
+
let collectEpoch = 0;
|
|
36
37
|
let pendingFileTypeChecks;
|
|
38
|
+
const MAX_QUEUED_FILE_TYPE_CHECKS = 64;
|
|
37
39
|
const ASYNC_REFINE = "~elyAsyncRefine";
|
|
38
|
-
const isAsyncPredicate = (v) => Array.isArray(v) ? v.some(
|
|
40
|
+
const isAsyncPredicate = (v) => Array.isArray(v) ? v.some(isAsyncPredicate) : typeof v?.check === "function" && (require_compile_utils.isAsyncFunction(v.check) || v.check["~elyAsyncRefine"] === true);
|
|
39
41
|
function collectFileTypeChecks() {
|
|
40
42
|
collecting = true;
|
|
43
|
+
collectEpoch++;
|
|
41
44
|
}
|
|
42
45
|
function takeFileTypeChecks() {
|
|
43
46
|
collecting = false;
|
|
@@ -45,8 +48,19 @@ function takeFileTypeChecks() {
|
|
|
45
48
|
pendingFileTypeChecks = void 0;
|
|
46
49
|
return pending;
|
|
47
50
|
}
|
|
48
|
-
function maybeQueueFileTypeCheck(value, types, message) {
|
|
51
|
+
function maybeQueueFileTypeCheck(value, types, message, budget) {
|
|
49
52
|
if (!collecting) return;
|
|
53
|
+
if (budget.epoch !== collectEpoch) {
|
|
54
|
+
budget.epoch = collectEpoch;
|
|
55
|
+
budget.count = 0;
|
|
56
|
+
}
|
|
57
|
+
if (budget.count++ >= budget.limit) {
|
|
58
|
+
if (budget.count === budget.limit + 1) (pendingFileTypeChecks ??= []).push({
|
|
59
|
+
file: value,
|
|
60
|
+
check: Promise.resolve(`Expect at most ${budget.limit} files`)
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
50
64
|
if (!fileTypeDetectors) {
|
|
51
65
|
if (!require_universal_is_production.isProduction() && !warnedMissingDetector) warnMissingFileTypeDetector();
|
|
52
66
|
(pendingFileTypeChecks ??= []).push({
|
|
@@ -80,6 +94,7 @@ function parseFileUnit(size) {
|
|
|
80
94
|
|
|
81
95
|
//#endregion
|
|
82
96
|
exports.ASYNC_REFINE = ASYNC_REFINE;
|
|
97
|
+
exports.MAX_QUEUED_FILE_TYPE_CHECKS = MAX_QUEUED_FILE_TYPE_CHECKS;
|
|
83
98
|
exports.checkFileExtension = checkFileExtension;
|
|
84
99
|
exports.collectFileTypeChecks = collectFileTypeChecks;
|
|
85
100
|
exports.fileType = fileType;
|
|
@@ -32,11 +32,14 @@ async function fileType(file, type) {
|
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
let collecting = false;
|
|
35
|
+
let collectEpoch = 0;
|
|
35
36
|
let pendingFileTypeChecks;
|
|
37
|
+
const MAX_QUEUED_FILE_TYPE_CHECKS = 64;
|
|
36
38
|
const ASYNC_REFINE = "~elyAsyncRefine";
|
|
37
|
-
const isAsyncPredicate = (v) => Array.isArray(v) ? v.some(
|
|
39
|
+
const isAsyncPredicate = (v) => Array.isArray(v) ? v.some(isAsyncPredicate) : typeof v?.check === "function" && (isAsyncFunction(v.check) || v.check["~elyAsyncRefine"] === true);
|
|
38
40
|
function collectFileTypeChecks() {
|
|
39
41
|
collecting = true;
|
|
42
|
+
collectEpoch++;
|
|
40
43
|
}
|
|
41
44
|
function takeFileTypeChecks() {
|
|
42
45
|
collecting = false;
|
|
@@ -44,8 +47,19 @@ function takeFileTypeChecks() {
|
|
|
44
47
|
pendingFileTypeChecks = void 0;
|
|
45
48
|
return pending;
|
|
46
49
|
}
|
|
47
|
-
function maybeQueueFileTypeCheck(value, types, message) {
|
|
50
|
+
function maybeQueueFileTypeCheck(value, types, message, budget) {
|
|
48
51
|
if (!collecting) return;
|
|
52
|
+
if (budget.epoch !== collectEpoch) {
|
|
53
|
+
budget.epoch = collectEpoch;
|
|
54
|
+
budget.count = 0;
|
|
55
|
+
}
|
|
56
|
+
if (budget.count++ >= budget.limit) {
|
|
57
|
+
if (budget.count === budget.limit + 1) (pendingFileTypeChecks ??= []).push({
|
|
58
|
+
file: value,
|
|
59
|
+
check: Promise.resolve(`Expect at most ${budget.limit} files`)
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
49
63
|
if (!fileTypeDetectors) {
|
|
50
64
|
if (!isProduction() && !warnedMissingDetector) warnMissingFileTypeDetector();
|
|
51
65
|
(pendingFileTypeChecks ??= []).push({
|
|
@@ -78,4 +92,4 @@ function parseFileUnit(size) {
|
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
//#endregion
|
|
81
|
-
export { ASYNC_REFINE, checkFileExtension, collectFileTypeChecks, fileType, isAsyncPredicate, matchesAnyFileType, maybeQueueFileTypeCheck, parseFileUnit, setFileTypeDetector, takeFileTypeChecks };
|
|
95
|
+
export { ASYNC_REFINE, MAX_QUEUED_FILE_TYPE_CHECKS, checkFileExtension, collectFileTypeChecks, fileType, isAsyncPredicate, matchesAnyFileType, maybeQueueFileTypeCheck, parseFileUnit, setFileTypeDetector, takeFileTypeChecks };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { FileOptions } from "../types.js";
|
|
2
|
-
import { ASYNC_REFINE, FileTypeDetector, PendingFileTypeCheck, checkFileExtension, collectFileTypeChecks, fileType, maybeQueueFileTypeCheck, parseFileUnit, setFileTypeDetector, takeFileTypeChecks } from "./file-type.js";
|
|
3
2
|
import { Type } from "typebox";
|
|
4
3
|
|
|
5
4
|
//#region src/type/elysia/file.d.ts
|
|
6
|
-
declare let BaseFile: Type.TRefine<Type.TUnsafe<File>>;
|
|
7
5
|
declare function File(options?: FileOptions): Readonly<Type.TRefine<Type.TUnsafe<File>>>;
|
|
8
6
|
//#endregion
|
|
9
|
-
export {
|
|
7
|
+
export { File };
|
package/dist/type/elysia/file.js
CHANGED
|
@@ -1,17 +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
3
|
const require_type_constants = require('../constants.js');
|
|
5
|
-
const
|
|
4
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
6
5
|
const require_type_elysia_utils = require('./utils.js');
|
|
7
|
-
|
|
6
|
+
const require_type_elysia_file_type = require('./file-type.js');
|
|
8
7
|
|
|
9
8
|
//#region src/type/elysia/file.ts
|
|
10
9
|
let BaseFile;
|
|
11
10
|
let emptyFile;
|
|
12
11
|
let sharedFile;
|
|
13
12
|
function File(options) {
|
|
14
|
-
BaseFile ??=
|
|
13
|
+
BaseFile ??= require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "File" }), require_utils.isBlob, () => "must be instance of Blob");
|
|
15
14
|
if (!options || require_utils.isEmpty(options)) return emptyFile ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.File, require_type_elysia_utils.cloneSchema(BaseFile)));
|
|
16
15
|
sharedFile ??= require_type_elysia_utils.createSharedReference(FileWithProperty);
|
|
17
16
|
return sharedFile(options);
|
|
@@ -29,36 +28,21 @@ function FileWithProperty(options) {
|
|
|
29
28
|
if (options.type) {
|
|
30
29
|
const types = typeof options.type === "string" ? [options.type] : options.type;
|
|
31
30
|
const message = types.length === 1 ? `Expect file type to be ${types[0]}` : `Expect file type to be one of ${types.join(", ")}`;
|
|
31
|
+
const budget = {
|
|
32
|
+
epoch: -1,
|
|
33
|
+
count: 0,
|
|
34
|
+
limit: options.maxItems ?? 64
|
|
35
|
+
};
|
|
32
36
|
const checkType = (value) => {
|
|
33
37
|
if (!require_type_elysia_file_type.matchesAnyFileType(value.type, types)) return false;
|
|
34
|
-
require_type_elysia_file_type.maybeQueueFileTypeCheck(value, types, message);
|
|
38
|
+
require_type_elysia_file_type.maybeQueueFileTypeCheck(value, types, message, budget);
|
|
35
39
|
return true;
|
|
36
40
|
};
|
|
37
41
|
checkType[require_type_elysia_file_type.ASYNC_REFINE] = true;
|
|
38
42
|
refines.push([checkType, message]);
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
const [, meta] = require_type_elysia_utils.getMeta(options);
|
|
42
|
-
if (meta) {
|
|
43
|
-
schema = require_type_elysia_utils.cloneSchema(schema);
|
|
44
|
-
Object.assign(schema, meta);
|
|
45
|
-
}
|
|
46
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.File, schema);
|
|
44
|
+
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.File, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(BaseFile, refines), options));
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
//#endregion
|
|
50
|
-
exports.
|
|
51
|
-
Object.defineProperty(exports, 'BaseFile', {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return BaseFile;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
exports.File = File;
|
|
58
|
-
exports.checkFileExtension = require_type_elysia_file_type.checkFileExtension;
|
|
59
|
-
exports.collectFileTypeChecks = require_type_elysia_file_type.collectFileTypeChecks;
|
|
60
|
-
exports.fileType = require_type_elysia_file_type.fileType;
|
|
61
|
-
exports.maybeQueueFileTypeCheck = require_type_elysia_file_type.maybeQueueFileTypeCheck;
|
|
62
|
-
exports.parseFileUnit = require_type_elysia_file_type.parseFileUnit;
|
|
63
|
-
exports.setFileTypeDetector = require_type_elysia_file_type.setFileTypeDetector;
|
|
64
|
-
exports.takeFileTypeChecks = require_type_elysia_file_type.takeFileTypeChecks;
|
|
48
|
+
exports.File = File;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isBlob, isEmpty } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { Refines, cloneSchema, createSharedReference, elyType,
|
|
5
|
-
import {
|
|
3
|
+
import { Refine, Unsafe } from "../typebox-type.mjs";
|
|
4
|
+
import { Refines, cloneSchema, createSharedReference, elyType, withMeta } from "./utils.mjs";
|
|
5
|
+
import { ASYNC_REFINE, MAX_QUEUED_FILE_TYPE_CHECKS, matchesAnyFileType, maybeQueueFileTypeCheck, parseFileUnit } from "./file-type.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/type/elysia/file.ts
|
|
8
8
|
let BaseFile;
|
|
@@ -27,22 +27,21 @@ function FileWithProperty(options) {
|
|
|
27
27
|
if (options.type) {
|
|
28
28
|
const types = typeof options.type === "string" ? [options.type] : options.type;
|
|
29
29
|
const message = types.length === 1 ? `Expect file type to be ${types[0]}` : `Expect file type to be one of ${types.join(", ")}`;
|
|
30
|
+
const budget = {
|
|
31
|
+
epoch: -1,
|
|
32
|
+
count: 0,
|
|
33
|
+
limit: options.maxItems ?? 64
|
|
34
|
+
};
|
|
30
35
|
const checkType = (value) => {
|
|
31
36
|
if (!matchesAnyFileType(value.type, types)) return false;
|
|
32
|
-
maybeQueueFileTypeCheck(value, types, message);
|
|
37
|
+
maybeQueueFileTypeCheck(value, types, message, budget);
|
|
33
38
|
return true;
|
|
34
39
|
};
|
|
35
40
|
checkType[ASYNC_REFINE] = true;
|
|
36
41
|
refines.push([checkType, message]);
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
const [, meta] = getMeta(options);
|
|
40
|
-
if (meta) {
|
|
41
|
-
schema = cloneSchema(schema);
|
|
42
|
-
Object.assign(schema, meta);
|
|
43
|
-
}
|
|
44
|
-
return elyType(ELYSIA_TYPES.File, schema);
|
|
43
|
+
return elyType(ELYSIA_TYPES.File, withMeta(Refines(BaseFile, refines), options));
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
//#endregion
|
|
48
|
-
export {
|
|
47
|
+
export { File };
|
|
@@ -1,18 +1,17 @@
|
|
|
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_array = require('./array.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_file = require('./file.js');
|
|
9
|
-
let typebox_type = require("typebox/type");
|
|
10
9
|
|
|
11
10
|
//#region src/type/elysia/files.ts
|
|
12
11
|
let BaseFiles;
|
|
13
12
|
let emptyFiles;
|
|
14
13
|
let sharedFiles;
|
|
15
|
-
const filesUnion = (options) => require_type_elysia_union.Union([require_type_elysia_array.ArrayType(require_type_elysia_file.File(options)),
|
|
14
|
+
const filesUnion = (options) => require_type_elysia_union.Union([require_type_elysia_array.ArrayType(require_type_elysia_file.File(options)), require_type_typebox_type.Decode(require_type_elysia_file.File(options), (value) => [value])]);
|
|
16
15
|
function Files(options) {
|
|
17
16
|
BaseFiles ??= filesUnion();
|
|
18
17
|
if (!options || require_utils.isEmpty(options)) return emptyFiles ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Files, require_type_elysia_utils.cloneSchema(BaseFiles)));
|
|
@@ -21,7 +20,10 @@ function Files(options) {
|
|
|
21
20
|
}
|
|
22
21
|
function FilesWithProperty(options) {
|
|
23
22
|
const fileOptions = {};
|
|
24
|
-
if (options.type !== void 0)
|
|
23
|
+
if (options.type !== void 0) {
|
|
24
|
+
fileOptions.type = options.type;
|
|
25
|
+
if (options.maxItems !== void 0) fileOptions.maxItems = options.maxItems;
|
|
26
|
+
}
|
|
25
27
|
if (options.minSize !== void 0) fileOptions.minSize = options.minSize;
|
|
26
28
|
if (options.maxSize !== void 0) fileOptions.maxSize = options.maxSize;
|
|
27
29
|
const base = require_utils.isEmpty(fileOptions) ? BaseFiles : filesUnion(fileOptions);
|
|
@@ -32,13 +34,7 @@ function FilesWithProperty(options) {
|
|
|
32
34
|
if (options.maxItems !== void 0) refines.push([(value) => {
|
|
33
35
|
return (Array.isArray(value) ? value.length : require_utils.isBlob(value) ? 1 : 0) <= options.maxItems;
|
|
34
36
|
}, `Expect less than ${options.maxItems} files`]);
|
|
35
|
-
|
|
36
|
-
const [, meta] = require_type_elysia_utils.getMeta(options);
|
|
37
|
-
if (meta) {
|
|
38
|
-
schema = require_type_elysia_utils.cloneSchema(schema);
|
|
39
|
-
Object.assign(schema, meta);
|
|
40
|
-
}
|
|
41
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Files, schema);
|
|
37
|
+
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Files, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(base, refines), options));
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
//#endregion
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isBlob, isEmpty } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
|
+
import { Decode } from "../typebox-type.mjs";
|
|
3
4
|
import { ArrayType } from "./array.mjs";
|
|
4
5
|
import { Union } from "./union.mjs";
|
|
5
|
-
import { Refines, cloneSchema, createSharedReference, elyType,
|
|
6
|
+
import { Refines, cloneSchema, createSharedReference, elyType, withMeta } from "./utils.mjs";
|
|
6
7
|
import { File } from "./file.mjs";
|
|
7
|
-
import { Decode } from "typebox/type";
|
|
8
8
|
|
|
9
9
|
//#region src/type/elysia/files.ts
|
|
10
10
|
let BaseFiles;
|
|
@@ -19,7 +19,10 @@ function Files(options) {
|
|
|
19
19
|
}
|
|
20
20
|
function FilesWithProperty(options) {
|
|
21
21
|
const fileOptions = {};
|
|
22
|
-
if (options.type !== void 0)
|
|
22
|
+
if (options.type !== void 0) {
|
|
23
|
+
fileOptions.type = options.type;
|
|
24
|
+
if (options.maxItems !== void 0) fileOptions.maxItems = options.maxItems;
|
|
25
|
+
}
|
|
23
26
|
if (options.minSize !== void 0) fileOptions.minSize = options.minSize;
|
|
24
27
|
if (options.maxSize !== void 0) fileOptions.maxSize = options.maxSize;
|
|
25
28
|
const base = isEmpty(fileOptions) ? BaseFiles : filesUnion(fileOptions);
|
|
@@ -30,13 +33,7 @@ function FilesWithProperty(options) {
|
|
|
30
33
|
if (options.maxItems !== void 0) refines.push([(value) => {
|
|
31
34
|
return (Array.isArray(value) ? value.length : isBlob(value) ? 1 : 0) <= options.maxItems;
|
|
32
35
|
}, `Expect less than ${options.maxItems} files`]);
|
|
33
|
-
|
|
34
|
-
const [, meta] = getMeta(options);
|
|
35
|
-
if (meta) {
|
|
36
|
-
schema = cloneSchema(schema);
|
|
37
|
-
Object.assign(schema, meta);
|
|
38
|
-
}
|
|
39
|
-
return elyType(ELYSIA_TYPES.Files, schema);
|
|
36
|
+
return elyType(ELYSIA_TYPES.Files, withMeta(Refines(base, refines), options));
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
//#endregion
|
package/dist/type/elysia/form.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
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
6
|
const require_type_elysia_object = require('./object.js');
|
|
7
7
|
const require_type_elysia_intersect = require('./intersect.js');
|
|
8
|
-
let typebox_type = require("typebox/type");
|
|
9
8
|
|
|
10
9
|
//#region src/type/elysia/form.ts
|
|
11
10
|
let BaseForm;
|
|
12
11
|
const Form = (property, options) => {
|
|
13
|
-
BaseForm ??= Object.freeze(
|
|
12
|
+
BaseForm ??= Object.freeze(require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "FormData" }), (value) => require_utils.isElysiaForm(value), () => "must be instance of Elysia.form"), (value) => value));
|
|
14
13
|
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Form, require_type_elysia_intersect.Intersect([BaseForm, require_type_elysia_object.ObjectType(property, options)]));
|
|
15
14
|
};
|
|
16
15
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { isElysiaForm } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
|
+
import { Decode, Refine, Unsafe } from "../typebox-type.mjs";
|
|
3
4
|
import { elyType } from "./utils.mjs";
|
|
4
5
|
import { ObjectType } from "./object.mjs";
|
|
5
|
-
import { Intersect
|
|
6
|
-
import { Decode, Refine, Unsafe } from "typebox/type";
|
|
6
|
+
import { Intersect } from "./intersect.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/type/elysia/form.ts
|
|
9
9
|
let BaseForm;
|
|
10
10
|
const Form = (property, options) => {
|
|
11
11
|
BaseForm ??= Object.freeze(Decode(Refine(Unsafe({ "~kind": "FormData" }), (value) => isElysiaForm(value), () => "must be instance of Elysia.form"), (value) => value));
|
|
12
|
-
return elyType(ELYSIA_TYPES.Form, Intersect
|
|
12
|
+
return elyType(ELYSIA_TYPES.Form, Intersect([BaseForm, ObjectType(property, options)]));
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
//#endregion
|
|
@@ -2,6 +2,6 @@ import { TNumberOptions, Type } from "typebox";
|
|
|
2
2
|
|
|
3
3
|
//#region src/type/elysia/integer-string.d.ts
|
|
4
4
|
type IntegerStringSchema = Type.TUnion<[Type.TInteger, Type.TCodec<Type.TRefine<Type.TString>, number>]>;
|
|
5
|
-
declare
|
|
5
|
+
declare const IntegerString: (property?: TNumberOptions) => Readonly<IntegerStringSchema>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { IntegerString };
|
|
@@ -1,40 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_utils = require('../../utils.js');
|
|
4
2
|
const require_type_constants = require('../constants.js');
|
|
5
3
|
const require_type_shared = require('../shared.js');
|
|
6
|
-
const
|
|
7
|
-
const require_type_elysia_union = require('./union.js');
|
|
8
|
-
const require_type_elysia_utils = require('./utils.js');
|
|
4
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
9
5
|
const require_type_elysia_number = require('./number.js');
|
|
6
|
+
const require_type_elysia_numeric = require('./numeric.js');
|
|
10
7
|
const require_type_elysia_integer = require('./integer.js');
|
|
11
|
-
let typebox_type = require("typebox/type");
|
|
12
8
|
|
|
13
9
|
//#region src/type/elysia/integer-string.ts
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let emptyIntegerString;
|
|
17
|
-
function IntegerString(property) {
|
|
18
|
-
StringifiedInteger ??= require_type_shared.pureRefine((0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), (value) => /^[+-]?\d+$/.test(value) && Number.isInteger(+value), () => "must be integer"), (value) => +value));
|
|
19
|
-
StrictInteger ??= require_type_shared.pureRefine((0, typebox_type.Refine)(require_type_elysia_number.NumberType(), (value) => Number.isInteger(value), () => "must be integer"));
|
|
20
|
-
if (!property || require_utils.isEmpty(property)) return emptyIntegerString ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Integer, require_type_elysia_union.Union([StrictInteger, StringifiedInteger])));
|
|
21
|
-
const [constraints, meta] = require_type_elysia_utils.getMeta(property);
|
|
22
|
-
const integer = require_type_elysia_integer.Integer(constraints);
|
|
23
|
-
const c = constraints;
|
|
24
|
-
const stringified = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), (value) => {
|
|
25
|
-
if (!/^[+-]?\d+$/.test(value)) return false;
|
|
26
|
-
const n = +value;
|
|
27
|
-
if (!Number.isInteger(n)) return false;
|
|
28
|
-
if (typeof c.minimum === "number" && n < c.minimum) return false;
|
|
29
|
-
if (typeof c.maximum === "number" && n > c.maximum) return false;
|
|
30
|
-
if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
|
|
31
|
-
if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
|
|
32
|
-
if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
|
|
33
|
-
return true;
|
|
34
|
-
}, () => "must be integer"), (value) => +value);
|
|
35
|
-
require_type_shared.pureRefine(stringified);
|
|
36
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Integer, require_type_elysia_union.Union([integer, stringified], meta));
|
|
37
|
-
}
|
|
10
|
+
const integerString = /* @__PURE__ */ require_type_elysia_numeric.numericString(require_type_constants.ELYSIA_TYPES.Integer, "must be integer", (value) => /^[+-]?\d+$/.test(value) && (value.length < 309 || Number.isInteger(+value)), require_type_elysia_integer.Integer, () => require_type_shared.pureRefine(require_type_typebox_type.Refine(require_type_elysia_number.NumberType(), (value) => Number.isInteger(value), () => "must be integer")));
|
|
11
|
+
const IntegerString = (property) => integerString(property);
|
|
38
12
|
|
|
39
13
|
//#endregion
|
|
40
14
|
exports.IntegerString = IntegerString;
|
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
import { isEmpty } from "../../utils.mjs";
|
|
2
1
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
3
2
|
import { pureRefine } from "../shared.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { Union } from "./union.mjs";
|
|
6
|
-
import { elyType, getMeta } from "./utils.mjs";
|
|
3
|
+
import { Refine } from "../typebox-type.mjs";
|
|
7
4
|
import { NumberType } from "./number.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { numericString } from "./numeric.mjs";
|
|
6
|
+
import { Integer } from "./integer.mjs";
|
|
10
7
|
|
|
11
8
|
//#region src/type/elysia/integer-string.ts
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let emptyIntegerString;
|
|
15
|
-
function IntegerString(property) {
|
|
16
|
-
StringifiedInteger ??= pureRefine(Decode(Refine(StringType(), (value) => /^[+-]?\d+$/.test(value) && Number.isInteger(+value), () => "must be integer"), (value) => +value));
|
|
17
|
-
StrictInteger ??= pureRefine(Refine(NumberType(), (value) => Number.isInteger(value), () => "must be integer"));
|
|
18
|
-
if (!property || isEmpty(property)) return emptyIntegerString ??= Object.freeze(elyType(ELYSIA_TYPES.Integer, Union([StrictInteger, StringifiedInteger])));
|
|
19
|
-
const [constraints, meta] = getMeta(property);
|
|
20
|
-
const integer = Integer$1(constraints);
|
|
21
|
-
const c = constraints;
|
|
22
|
-
const stringified = Decode(Refine(StringType(), (value) => {
|
|
23
|
-
if (!/^[+-]?\d+$/.test(value)) return false;
|
|
24
|
-
const n = +value;
|
|
25
|
-
if (!Number.isInteger(n)) return false;
|
|
26
|
-
if (typeof c.minimum === "number" && n < c.minimum) return false;
|
|
27
|
-
if (typeof c.maximum === "number" && n > c.maximum) return false;
|
|
28
|
-
if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
|
|
29
|
-
if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
|
|
30
|
-
if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
|
|
31
|
-
return true;
|
|
32
|
-
}, () => "must be integer"), (value) => +value);
|
|
33
|
-
pureRefine(stringified);
|
|
34
|
-
return elyType(ELYSIA_TYPES.Integer, Union([integer, stringified], meta));
|
|
35
|
-
}
|
|
9
|
+
const integerString = /* @__PURE__ */ numericString(ELYSIA_TYPES.Integer, "must be integer", (value) => /^[+-]?\d+$/.test(value) && (value.length < 309 || Number.isInteger(+value)), Integer, () => pureRefine(Refine(NumberType(), (value) => Number.isInteger(value), () => "must be integer")));
|
|
10
|
+
const IntegerString = (property) => integerString(property);
|
|
36
11
|
|
|
37
12
|
//#endregion
|
|
38
13
|
export { IntegerString };
|
|
@@ -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/integer.ts
|
|
8
|
-
const
|
|
5
|
+
const integer = /* @__PURE__ */ require_type_elysia_number.primitive("integer", "Integer");
|
|
9
6
|
function Integer(options) {
|
|
10
|
-
|
|
11
|
-
const schema = {
|
|
12
|
-
...options,
|
|
13
|
-
type: "integer",
|
|
14
|
-
"~kind": "Integer"
|
|
15
|
-
};
|
|
16
|
-
return Object.defineProperty(schema, "~kind", require_type_constants.noEnumerable);
|
|
7
|
+
return integer(options);
|
|
17
8
|
}
|
|
18
9
|
|
|
19
10
|
//#endregion
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { noEnumerable } from "../constants.mjs";
|
|
3
|
-
import { Integer as Integer$1 } from "typebox/type";
|
|
1
|
+
import { primitive } from "./number.mjs";
|
|
4
2
|
|
|
5
3
|
//#region src/type/elysia/integer.ts
|
|
6
|
-
const
|
|
4
|
+
const integer = /* @__PURE__ */ primitive("integer", "Integer");
|
|
7
5
|
function Integer(options) {
|
|
8
|
-
|
|
9
|
-
const schema = {
|
|
10
|
-
...options,
|
|
11
|
-
type: "integer",
|
|
12
|
-
"~kind": "Integer"
|
|
13
|
-
};
|
|
14
|
-
return Object.defineProperty(schema, "~kind", noEnumerable);
|
|
6
|
+
return integer(options);
|
|
15
7
|
}
|
|
16
8
|
|
|
17
9
|
//#endregion
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_utils = require('../../utils.js');
|
|
3
2
|
const require_type_constants = require('../constants.js');
|
|
4
3
|
|
|
5
4
|
//#region src/type/elysia/intersect.ts
|
|
6
5
|
function Intersect(schemas, options) {
|
|
7
|
-
if (!options || require_utils.isEmpty(options)) return Object.defineProperty({
|
|
8
|
-
"~kind": "Intersect",
|
|
9
|
-
allOf: schemas
|
|
10
|
-
}, "~kind", require_type_constants.noEnumerable);
|
|
11
6
|
const schema = {
|
|
12
7
|
...options,
|
|
13
8
|
"~kind": "Intersect",
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { isEmpty } from "../../utils.mjs";
|
|
2
1
|
import { noEnumerable } from "../constants.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/type/elysia/intersect.ts
|
|
5
4
|
function Intersect(schemas, options) {
|
|
6
|
-
if (!options || isEmpty(options)) return Object.defineProperty({
|
|
7
|
-
"~kind": "Intersect",
|
|
8
|
-
allOf: schemas
|
|
9
|
-
}, "~kind", noEnumerable);
|
|
10
5
|
const schema = {
|
|
11
6
|
...options,
|
|
12
7
|
"~kind": "Intersect",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _$typebox from "typebox";
|
|
2
|
+
import { TSchema } from "typebox";
|
|
3
|
+
|
|
4
|
+
//#region src/type/elysia/json-string.d.ts
|
|
5
|
+
declare function jsonString<T extends TSchema>(inner: T, open: number, message: string): _$typebox.TCodec<_$typebox.TRefine<_$typebox.TString>, _$typebox.StaticType<[], "Decode", {}, {}, T>>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { jsonString };
|