elysia 2.0.0-exp.2 → 2.0.0-exp.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.
Files changed (135) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +2 -0
  2. package/dist/adapter/bun/index.d.ts +2 -25
  3. package/dist/adapter/bun/index.js +18 -12
  4. package/dist/adapter/bun/index.mjs +19 -13
  5. package/dist/adapter/bun/router.js +1 -1
  6. package/dist/adapter/bun/router.mjs +1 -1
  7. package/dist/adapter/constants.d.ts +3 -26
  8. package/dist/adapter/index.d.ts +1 -26
  9. package/dist/adapter/index.js +1 -17
  10. package/dist/adapter/index.mjs +1 -17
  11. package/dist/adapter/types.d.ts +1 -0
  12. package/dist/adapter/utils.d.ts +3 -4
  13. package/dist/adapter/utils.js +83 -81
  14. package/dist/adapter/utils.mjs +82 -80
  15. package/dist/adapter/web-standard/handler.js +6 -3
  16. package/dist/adapter/web-standard/handler.mjs +6 -3
  17. package/dist/adapter/web-standard/index.d.ts +2 -26
  18. package/dist/adapter/web-standard/index.js +12 -1
  19. package/dist/adapter/web-standard/index.mjs +12 -1
  20. package/dist/base.d.ts +38 -68
  21. package/dist/base.js +133 -97
  22. package/dist/base.mjs +133 -97
  23. package/dist/compile/aot.d.ts +22 -1
  24. package/dist/compile/aot.js +22 -0
  25. package/dist/compile/aot.mjs +22 -0
  26. package/dist/compile/handler/index.d.ts +2 -2
  27. package/dist/compile/handler/index.js +85 -456
  28. package/dist/compile/handler/index.mjs +86 -457
  29. package/dist/compile/handler/jit.d.ts +35 -0
  30. package/dist/compile/handler/jit.js +445 -0
  31. package/dist/compile/handler/jit.mjs +443 -0
  32. package/dist/compile/handler/params.js +3 -2
  33. package/dist/compile/handler/params.mjs +4 -3
  34. package/dist/compile/handler/reconstruct.d.ts +13 -0
  35. package/dist/compile/handler/reconstruct.js +29 -0
  36. package/dist/compile/handler/reconstruct.mjs +28 -0
  37. package/dist/compile/handler/utils.d.ts +2 -1
  38. package/dist/compile/handler/utils.js +9 -3
  39. package/dist/compile/handler/utils.mjs +9 -4
  40. package/dist/compile/jit-probe.d.ts +19 -0
  41. package/dist/compile/jit-probe.js +38 -0
  42. package/dist/compile/jit-probe.mjs +36 -0
  43. package/dist/cookie/index.d.ts +4 -3
  44. package/dist/cookie/index.js +2 -1
  45. package/dist/cookie/index.mjs +2 -1
  46. package/dist/cookie/serialize.d.ts +6 -0
  47. package/dist/cookie/serialize.js +28 -0
  48. package/dist/cookie/serialize.mjs +27 -0
  49. package/dist/cookie/utils.d.ts +1 -2
  50. package/dist/cookie/utils.js +2 -23
  51. package/dist/cookie/utils.mjs +5 -25
  52. package/dist/handler/error.js +2 -2
  53. package/dist/handler/error.mjs +3 -3
  54. package/dist/handler/fetch.js +49 -42
  55. package/dist/handler/fetch.mjs +50 -43
  56. package/dist/index.d.ts +13 -8
  57. package/dist/index.js +11 -4
  58. package/dist/index.mjs +7 -6
  59. package/dist/parse-query.js +1 -1
  60. package/dist/parse-query.mjs +1 -1
  61. package/dist/plugin/bun.d.ts +10 -0
  62. package/dist/plugin/bun.js +18 -1
  63. package/dist/plugin/bun.mjs +19 -2
  64. package/dist/plugin/core.d.ts +61 -1
  65. package/dist/plugin/core.js +90 -10
  66. package/dist/plugin/core.mjs +90 -12
  67. package/dist/plugin/esbuild.d.ts +10 -0
  68. package/dist/plugin/esbuild.js +18 -1
  69. package/dist/plugin/esbuild.mjs +19 -2
  70. package/dist/plugin/source.d.ts +38 -1
  71. package/dist/plugin/source.js +104 -13
  72. package/dist/plugin/source.mjs +102 -14
  73. package/dist/plugin/vite.d.ts +7 -0
  74. package/dist/plugin/vite.js +22 -1
  75. package/dist/plugin/vite.mjs +23 -2
  76. package/dist/sucrose.js +23 -10
  77. package/dist/sucrose.mjs +23 -10
  78. package/dist/trace.d.ts +1 -1
  79. package/dist/trace.js +4 -6
  80. package/dist/trace.mjs +4 -6
  81. package/dist/type/bridge.d.ts +9 -8
  82. package/dist/type/coerce.d.ts +20 -2
  83. package/dist/type/coerce.js +110 -0
  84. package/dist/type/coerce.mjs +109 -2
  85. package/dist/type/compat.js +4 -3
  86. package/dist/type/compat.mjs +2 -1
  87. package/dist/type/constants.d.ts +1 -1
  88. package/dist/type/elysia/boolean-string.js +1 -1
  89. package/dist/type/elysia/boolean-string.mjs +1 -1
  90. package/dist/type/elysia/file-type.js +1 -1
  91. package/dist/type/elysia/file-type.mjs +1 -1
  92. package/dist/type/elysia/integer-string.js +1 -1
  93. package/dist/type/elysia/integer-string.mjs +1 -1
  94. package/dist/type/exports.js +29 -2059
  95. package/dist/type/exports.mjs +7 -295
  96. package/dist/type/index.d.ts +6 -2
  97. package/dist/type/index.js +4 -0
  98. package/dist/type/index.mjs +3 -1
  99. package/dist/type/types.d.ts +1 -1
  100. package/dist/type/utils.js +4 -4
  101. package/dist/type/utils.mjs +4 -4
  102. package/dist/type/validator/custom-error.d.ts +10 -0
  103. package/dist/type/validator/custom-error.js +113 -0
  104. package/dist/type/validator/custom-error.mjs +110 -0
  105. package/dist/type/validator/default-precompute.d.ts +22 -0
  106. package/dist/type/validator/default-precompute.js +476 -0
  107. package/dist/type/validator/default-precompute.mjs +465 -0
  108. package/dist/type/validator/frozen-check.d.ts +11 -0
  109. package/dist/type/validator/frozen-check.js +19 -0
  110. package/dist/type/validator/frozen-check.mjs +18 -0
  111. package/dist/type/{validator.d.ts → validator/index.d.ts} +7 -20
  112. package/dist/type/validator/index.js +572 -0
  113. package/dist/type/validator/index.mjs +567 -0
  114. package/dist/type/validator/string-codec-aot.d.ts +9 -0
  115. package/dist/type/validator/string-codec-aot.js +106 -0
  116. package/dist/type/validator/string-codec-aot.mjs +102 -0
  117. package/dist/type/validator/validator-cache.d.ts +21 -0
  118. package/dist/type/validator/validator-cache.js +163 -0
  119. package/dist/type/validator/validator-cache.mjs +161 -0
  120. package/dist/types.d.ts +22 -14
  121. package/dist/universal/file.d.ts +1 -1
  122. package/dist/universal/file.js +35 -29
  123. package/dist/universal/file.mjs +35 -29
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/utils.js +89 -45
  126. package/dist/utils.mjs +88 -46
  127. package/dist/validator/index.d.ts +1 -1
  128. package/dist/validator/index.js +15 -2
  129. package/dist/validator/index.mjs +15 -2
  130. package/dist/validator/route.d.ts +0 -1
  131. package/dist/ws/route.js +47 -24
  132. package/dist/ws/route.mjs +48 -25
  133. package/package.json +10 -4
  134. package/dist/type/validator.js +0 -1033
  135. package/dist/type/validator.mjs +0 -1029
@@ -0,0 +1,572 @@
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
+ const require_error = require('../../error.js');
5
+ const require_compile_aot = require('../../compile/aot.js');
6
+ const require_validator_index = require('../../validator/index.js');
7
+ const require_type_constants = require('../constants.js');
8
+ const require_compile_utils = require('../../compile/utils.js');
9
+ const require_type_coerce = require('../coerce.js');
10
+ const require_type_utils = require('../utils.js');
11
+ const require_type_elysia_file_type = require('../elysia/file-type.js');
12
+ const require_type_validator_default_precompute = require('./default-precompute.js');
13
+ const require_type_validator_frozen_check = require('./frozen-check.js');
14
+ const require_type_validator_custom_error = require('./custom-error.js');
15
+ const require_type_validator_string_codec_aot = require('./string-codec-aot.js');
16
+ const require_type_validator_validator_cache = require('./validator-cache.js');
17
+ let typebox_type = require("typebox/type");
18
+ let typebox_value = require("typebox/value");
19
+ let typebox_schema = require("typebox/schema");
20
+ let exact_mirror = require("exact-mirror");
21
+ exact_mirror = require_runtime.__toESM(exact_mirror);
22
+
23
+ //#region src/type/validator/index.ts
24
+ const moduleCache = /* @__PURE__ */ new WeakMap();
25
+ function schemaContainsRef(node, seen = /* @__PURE__ */ new WeakSet()) {
26
+ if (!node || typeof node !== "object" || seen.has(node)) return false;
27
+ seen.add(node);
28
+ if (node.$ref) return true;
29
+ const props = node.properties;
30
+ if (props) {
31
+ for (const k in props) if (schemaContainsRef(props[k], seen)) return true;
32
+ }
33
+ const items = node.items;
34
+ if (Array.isArray(items)) {
35
+ for (const it of items) if (schemaContainsRef(it, seen)) return true;
36
+ } else if (items && schemaContainsRef(items, seen)) return true;
37
+ for (const key of [
38
+ "anyOf",
39
+ "allOf",
40
+ "oneOf"
41
+ ]) {
42
+ const arr = node[key];
43
+ if (Array.isArray(arr)) {
44
+ for (const x of arr) if (schemaContainsRef(x, seen)) return true;
45
+ }
46
+ }
47
+ if (node.additionalProperties && typeof node.additionalProperties === "object" && schemaContainsRef(node.additionalProperties, seen)) return true;
48
+ if (node.not && schemaContainsRef(node.not, seen)) return true;
49
+ const pp = node.patternProperties;
50
+ if (pp) {
51
+ for (const k in pp) if (schemaContainsRef(pp[k], seen)) return true;
52
+ }
53
+ return false;
54
+ }
55
+ function divergesFromEvaluate(node, seen) {
56
+ if (!node || typeof node !== "object" || seen.has(node)) return false;
57
+ seen.add(node);
58
+ for (const k in node) {
59
+ if (!Object.hasOwn(node, k)) return true;
60
+ const v = node[k];
61
+ if (typeof v === "object" && v && divergesFromEvaluate(v, seen)) return true;
62
+ }
63
+ return false;
64
+ }
65
+ const SIMPLE_OBJECT_KEYS = new Set([
66
+ "type",
67
+ "properties",
68
+ "required"
69
+ ]);
70
+ function shallowMergeObjects(members) {
71
+ const properties = {};
72
+ let required;
73
+ for (const m of members) {
74
+ if (!m || m["~kind"] !== "Object" || m["~elyTyp"] !== void 0 || !m.properties || divergesFromEvaluate(m, /* @__PURE__ */ new WeakSet())) return null;
75
+ for (const k of Object.keys(m)) if (!SIMPLE_OBJECT_KEYS.has(k)) return null;
76
+ for (const k in m.properties) {
77
+ if (k in properties) return null;
78
+ properties[k] = m.properties[k];
79
+ }
80
+ if (Array.isArray(m.required) && m.required.length) (required ??= []).push(...m.required);
81
+ }
82
+ const out = {
83
+ type: "object",
84
+ properties
85
+ };
86
+ if (required) out.required = required;
87
+ return Object.defineProperty(out, "~kind", {
88
+ value: "Object",
89
+ enumerable: false
90
+ });
91
+ }
92
+ let inlineRefId = 0;
93
+ const isAsyncPredicate = (v) => Array.isArray(v) ? v.some((x) => typeof x.check === "function" ? require_compile_utils.isAsyncFunction(x.check) || x.check["~elyAsyncRefine"] === true : false) : false;
94
+ async function enforceFileTypeChecks(pending, type, value, schema) {
95
+ const results = await Promise.all(pending.map((x) => x.check));
96
+ for (let i = 0; i < results.length; i++) if (results[i] !== true) throw new require_error.ValidationError(type, value, [{
97
+ instancePath: findInstancePath(value, pending[i].file) ?? "",
98
+ message: results[i]
99
+ }], schema);
100
+ }
101
+ function findInstancePath(value, target, path = "") {
102
+ if (value === target) return path;
103
+ if (!value || typeof value !== "object") return;
104
+ if (Array.isArray(value)) {
105
+ for (let i = 0; i < value.length; i++) {
106
+ const found = findInstancePath(value[i], target, `${path}/${i}`);
107
+ if (found !== void 0) return found;
108
+ }
109
+ return;
110
+ }
111
+ for (const key in value) {
112
+ const found = findInstancePath(value[key], target, `${path}/${key}`);
113
+ if (found !== void 0) return found;
114
+ }
115
+ }
116
+ function externalsShape(schema) {
117
+ let out = "";
118
+ for (const e of require_compile_aot.collectExternals(schema)) out += e instanceof RegExp ? "r" : typeof e === "function" ? "f" : "v";
119
+ return out;
120
+ }
121
+ function sourceOnlyValidator(schema) {
122
+ const buildResult = (0, typebox_schema.Build)(schema);
123
+ let full;
124
+ return new Proxy({}, { get(_, prop) {
125
+ if (prop === "buildResult") return buildResult;
126
+ const f = full ??= (0, typebox_schema.Compile)(schema);
127
+ const value = f[prop];
128
+ return typeof value === "function" ? value.bind(f) : value;
129
+ } });
130
+ }
131
+ var TypeBoxValidator = class extends require_validator_index.Validator {
132
+ #decodeMirror;
133
+ #encodeMirror;
134
+ #findCustomError;
135
+ #defaultFastPath;
136
+ #noValidate;
137
+ #isForm;
138
+ #hasOptional;
139
+ constructor(schema, options, name, isIntersectable) {
140
+ super();
141
+ this.precomputeSafe = false;
142
+ this.#isForm = false;
143
+ this.#hasOptional = false;
144
+ if (isIntersectable) {
145
+ const members = [schema, ...options.schemas];
146
+ schema = shallowMergeObjects(members) ?? (0, typebox_type.Evaluate)((0, typebox_type.Intersect)(members));
147
+ }
148
+ const originalElyTyp = schema?.["~elyTyp"];
149
+ const frozen = options?.aot && options.slot ? require_compile_aot.Compiled.getValidator(options.aot.method, options.aot.path, options.slot) : void 0;
150
+ let schemaHasRef = false;
151
+ if (name && options?.models) schema = moduleCache.getOrInsertComputed(options.models, () => (0, typebox_type.Module)(options.models))[name];
152
+ else if (options?.models && typeof name !== "string") {
153
+ schemaHasRef = frozen ? frozen.r === 1 : schemaContainsRef(schema);
154
+ if (schemaHasRef) {
155
+ const id = `inline@${++inlineRefId}`;
156
+ schema = (0, typebox_type.Module)({
157
+ ...options.models,
158
+ [id]: schema
159
+ })[id];
160
+ }
161
+ }
162
+ const isFrozen = this.#reconstruct(options, frozen);
163
+ this.schema = isFrozen && frozen.cp ? require_type_coerce.buildCoercedFromPlan(schema, frozen.cp) : isFrozen && !this.hasCodec ? schema : require_type_coerce.applyCoercions(schema, options?.coerces);
164
+ if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = require_type_coerce.nonAdditionalProperties(this.schema);
165
+ if (!isFrozen) {
166
+ const capturing = require_compile_aot.Capture.isCapturing();
167
+ this.tb = capturing ? sourceOnlyValidator(this.schema) : (0, typebox_schema.Compile)(this.schema);
168
+ this.hasCodec = (0, typebox_value.HasCodec)(this.schema);
169
+ this.isAsync = this.tb.buildResult.external.variables.some(isAsyncPredicate) ?? false;
170
+ this.hasDefault = require_type_utils.hasProperty("default", this.schema);
171
+ if (capturing) this.#maybeCapture(options, schemaHasRef, schema);
172
+ else this.#dropCompiledSource();
173
+ }
174
+ if (frozen?.ps === 1) {
175
+ const objectTemplate = frozen.pod !== void 0 ? Object.freeze(frozen.pod) : void 0;
176
+ this.precomputeSafe = true;
177
+ this.#defaultFastPath = {
178
+ value: frozen.pd,
179
+ appliesToNull: frozen.pn === 1,
180
+ objectTemplate,
181
+ clone: frozen.dc,
182
+ merge: frozen.pm
183
+ };
184
+ } else {
185
+ const defaults = this.hasDefault ? require_type_validator_default_precompute.verifyPreallocatableDefault(this.schema, require_compile_aot.Capture.isCapturing()) : void 0;
186
+ if (defaults) {
187
+ this.precomputeSafe = true;
188
+ const objectTemplate = defaults.pod !== void 0 ? Object.freeze(defaults.pod) : void 0;
189
+ this.#defaultFastPath = {
190
+ value: defaults.pd,
191
+ appliesToNull: defaults.pn,
192
+ objectTemplate,
193
+ clone: defaults.pd !== void 0 ? require_type_validator_default_precompute.createDefaultCloner(defaults.pd) : void 0,
194
+ merge: defaults.ms ? require_type_validator_default_precompute.createMergerFromSource(defaults.ms) : objectTemplate !== void 0 ? require_type_validator_default_precompute.createObjectDefaultMerger(objectTemplate) : void 0
195
+ };
196
+ } else {
197
+ this.precomputeSafe = false;
198
+ this.#defaultFastPath = void 0;
199
+ }
200
+ }
201
+ this.#noValidate = originalElyTyp === require_type_constants.ELYSIA_TYPES.NoValidate;
202
+ this.#isForm = originalElyTyp === require_type_constants.ELYSIA_TYPES.Form;
203
+ this.#hasOptional = !!this.schema?.["~optional"];
204
+ if (frozen?.ic) require_type_validator_string_codec_aot.reconstructInnerCodecs(frozen.ic, this.schema);
205
+ if (isFrozen && frozen.cm) {
206
+ const both = require_compile_aot.instantiateFrozenBoth(frozen, this.schema, schema);
207
+ this.reconstructedCheck = both.check;
208
+ this.Clean = options?.normalize === false ? void 0 : both.clean;
209
+ } else {
210
+ if (isFrozen) this.reconstructedCheck = frozen.c(frozen.e ? require_compile_aot.collectExternals(this.schema) : require_compile_aot.EMPTY_EXTERNALS);
211
+ try {
212
+ this.Clean = options?.normalize === false ? void 0 : options?.normalize === "typebox" ? (value) => (0, typebox_value.Clean)(this.schema, value) : this.#setupMirror(schema, options, frozen);
213
+ } catch (error) {
214
+ console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
215
+ console.warn(schema);
216
+ console.warn(error);
217
+ if (options?.normalize !== false) this.Clean = (value) => (0, typebox_value.Clean)(this.schema, value);
218
+ }
219
+ }
220
+ if (this.hasCodec && !this.#isForm && !this.#noValidate && !options?.slot?.startsWith("r") && options?.normalize !== false && options?.normalize !== "typebox") this.#decodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "decode");
221
+ if (this.hasCodec && !this.#isForm && !this.#noValidate && options?.slot?.startsWith("r") && options?.normalize !== false && options?.normalize !== "typebox") this.#encodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "encode");
222
+ if (!this.#noValidate) this.#findCustomError = require_type_validator_custom_error.buildFindCustomError(this.schema, frozen);
223
+ }
224
+ #error(value, type) {
225
+ return new require_error.ValidationError(type, value, () => this.Errors(value), this.schema, this.#findCustomError);
226
+ }
227
+ #setupMirror(schema, options, frozen) {
228
+ const aot = options?.aot;
229
+ const slot = options?.slot;
230
+ if (aot && slot && frozen?.m) {
231
+ const m = frozen.m;
232
+ let clean;
233
+ return (value) => {
234
+ if (clean === void 0) try {
235
+ clean = require_compile_aot.instantiateFrozenMirror(m, schema);
236
+ } catch (error) {
237
+ console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
238
+ console.warn(schema);
239
+ console.warn(error);
240
+ clean = (v) => v;
241
+ }
242
+ return clean(value);
243
+ };
244
+ }
245
+ if (aot && slot) {
246
+ if (require_compile_aot.Capture.isCapturing()) try {
247
+ const emitted = (0, exact_mirror.default)(schema, {
248
+ Compile: typebox_schema.Compile,
249
+ sanitize: options?.sanitize,
250
+ emit: true
251
+ });
252
+ if (typeof emitted?.source === "string") {
253
+ const ext = emitted.externals;
254
+ if (!ext) require_compile_aot.Capture.set({
255
+ method: aot.method,
256
+ path: aot.path,
257
+ slot
258
+ }, { mirror: {
259
+ source: emitted.source,
260
+ hasExternals: false
261
+ } });
262
+ else if (ext.unions && !ext.hof) {
263
+ const u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
264
+ if (u) require_compile_aot.Capture.set({
265
+ method: aot.method,
266
+ path: aot.path,
267
+ slot
268
+ }, { mirror: {
269
+ source: emitted.source,
270
+ hasExternals: true,
271
+ u
272
+ } });
273
+ }
274
+ }
275
+ } catch {}
276
+ }
277
+ return (0, exact_mirror.default)(schema, {
278
+ Compile: typebox_schema.Compile,
279
+ sanitize: options?.sanitize
280
+ });
281
+ }
282
+ #setupCodecMirror(schema, options, frozen, dir) {
283
+ const aot = options?.aot;
284
+ const slot = options?.slot;
285
+ const frozenMirror = dir === "decode" ? frozen?.dm : frozen?.em;
286
+ if (aot && slot && frozenMirror) {
287
+ const m = frozenMirror;
288
+ let run;
289
+ return (value) => {
290
+ if (run === void 0) try {
291
+ run = require_compile_aot.instantiateFrozenDecodeMirror(m, schema, dir);
292
+ } catch {
293
+ run = dir === "decode" ? (v) => {
294
+ const decoded = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), schema, v);
295
+ return this.Clean ? this.Clean(decoded) : decoded;
296
+ } : (v) => {
297
+ const out = (0, typebox_value.Encode)(schema, v);
298
+ return this.Clean ? this.Clean(out) : out;
299
+ };
300
+ }
301
+ return run(value);
302
+ };
303
+ }
304
+ const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
305
+ const captureSlot = dir === "decode" ? !slot?.startsWith("response") : !!slot?.startsWith("response");
306
+ if (aot && slot && require_compile_aot.Capture.isCapturing() && captureSlot) try {
307
+ const emitted = (0, exact_mirror.default)(schema, {
308
+ Compile: typebox_schema.Compile,
309
+ sanitize: options?.sanitize,
310
+ ...dirOpt,
311
+ emit: true
312
+ });
313
+ if (typeof emitted?.source === "string") {
314
+ const ext = emitted.externals;
315
+ if (ext?.codecs && !ext.hof && require_compile_aot.Capture.mirrorCodecs(schema, ext.codecs, dir)) {
316
+ let u;
317
+ let freezable = true;
318
+ if (ext.unions && ext.unions.length) {
319
+ u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
320
+ if (!u) freezable = false;
321
+ }
322
+ if (freezable) {
323
+ const mirror = {
324
+ source: emitted.source,
325
+ hasExternals: true,
326
+ u
327
+ };
328
+ require_compile_aot.Capture.set({
329
+ method: aot.method,
330
+ path: aot.path,
331
+ slot
332
+ }, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
333
+ }
334
+ }
335
+ }
336
+ } catch {}
337
+ try {
338
+ return (0, exact_mirror.default)(schema, {
339
+ Compile: typebox_schema.Compile,
340
+ sanitize: options?.sanitize,
341
+ ...dirOpt
342
+ });
343
+ } catch {}
344
+ }
345
+ Check(value) {
346
+ if (this.reconstructedCheck) return this.reconstructedCheck(value);
347
+ return this.tb.Check(value);
348
+ }
349
+ #reconstruct(options, frozen) {
350
+ if (!options?.aot || !options.slot || options.normalize === "typebox") return false;
351
+ if (!frozen?.c && !frozen?.cm) return false;
352
+ this.isAsync = frozen.a === 1;
353
+ this.hasDefault = frozen.d === 1;
354
+ this.hasCodec = frozen.k === 1;
355
+ return true;
356
+ }
357
+ #maybeCapture(options, hasRef, originalSchema) {
358
+ const aot = options?.aot;
359
+ const slot = options?.slot;
360
+ if (!aot || !slot || !require_compile_aot.Capture.isCapturing()) return;
361
+ if (this.hasCodec && !hasRef && options.coerces && options.normalize !== false && options.normalize !== "typebox") {
362
+ const plan = require_type_coerce.captureCoercePlan(originalSchema, this.schema);
363
+ if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(this.schema)) require_compile_aot.Capture.set({
364
+ method: aot.method,
365
+ path: aot.path,
366
+ slot
367
+ }, { coercePlan: plan });
368
+ }
369
+ const defaultFastPathCapture = {
370
+ precomputeSafe: void 0,
371
+ precomputedDefault: void 0,
372
+ precomputeNull: void 0,
373
+ precomputedObjectDefault: void 0,
374
+ defaultCloner: void 0,
375
+ objectDefaultMerger: void 0
376
+ };
377
+ if (this.hasDefault) {
378
+ const defaults = require_type_validator_default_precompute.verifyPreallocatableDefault(this.schema);
379
+ if (defaults) {
380
+ defaultFastPathCapture.precomputeSafe = true;
381
+ defaultFastPathCapture.precomputedDefault = defaults.pd;
382
+ defaultFastPathCapture.precomputeNull = defaults.pn;
383
+ defaultFastPathCapture.precomputedObjectDefault = defaults.pod;
384
+ defaultFastPathCapture.defaultCloner = defaults.pd !== void 0 ? require_type_validator_default_precompute.buildDefaultClonerSource(defaults.pd) : void 0;
385
+ defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? require_type_validator_default_precompute.buildObjectDefaultMergeSource(defaults.pod) : void 0);
386
+ }
387
+ }
388
+ require_compile_aot.Capture.set({
389
+ method: aot.method,
390
+ path: aot.path,
391
+ slot
392
+ }, defaultFastPathCapture);
393
+ const customErrors = require_type_validator_custom_error.captureCustomErrors(this.schema);
394
+ if (customErrors) require_compile_aot.Capture.set({
395
+ method: aot.method,
396
+ path: aot.path,
397
+ slot
398
+ }, { customErrors });
399
+ const innerCodecs = require_type_validator_string_codec_aot.captureStringCodecEntries(this.schema, options?.sanitize);
400
+ if (innerCodecs) require_compile_aot.Capture.set({
401
+ method: aot.method,
402
+ path: aot.path,
403
+ slot
404
+ }, { innerCodecs });
405
+ const build = this.tb.buildResult;
406
+ const cf = require_type_validator_frozen_check.buildFrozenCheck(build, this.schema);
407
+ if (!cf) return;
408
+ require_compile_aot.Capture.set({
409
+ method: aot.method,
410
+ path: aot.path,
411
+ slot
412
+ }, {
413
+ ...cf,
414
+ async: build.external.variables.some(isAsyncPredicate),
415
+ hasDefault: this.hasDefault,
416
+ hasCodec: this.hasCodec,
417
+ hasRef
418
+ });
419
+ }
420
+ #dropCompiledSource() {
421
+ const tb = this.tb;
422
+ if (!tb) return;
423
+ if (tb.evaluateResult) tb.evaluateResult.code = void 0;
424
+ if (tb.buildResult) tb.buildResult.functions = void 0;
425
+ }
426
+ Errors(value) {
427
+ return (0, typebox_value.Errors)(this.schema, value);
428
+ }
429
+ Decode(value) {
430
+ return (0, typebox_value.Decode)(this.schema, value);
431
+ }
432
+ Encode(value) {
433
+ return this.hasCodec ? (0, typebox_value.Encode)(this.schema, value) : value;
434
+ }
435
+ EncodeFrom(value, type) {
436
+ if (this.#isForm) {
437
+ if (!this.#noValidate && !this.Check(value)) throw this.#error(value, type);
438
+ return value;
439
+ }
440
+ if (!this.hasCodec) {
441
+ if (!this.#noValidate && !this.Check(value)) throw this.#error(value, type);
442
+ if (this.Clean) value = this.Clean(value);
443
+ return value;
444
+ }
445
+ try {
446
+ if (this.#encodeMirror) {
447
+ const out = this.#encodeMirror(value);
448
+ if (!this.#noValidate && !this.Check(out)) throw new require_error.ValidationError(type, out, () => this.Errors(out), this.schema);
449
+ return out;
450
+ }
451
+ const out = this.#noValidate ? (0, typebox_value.EncodeUnsafe)(require_utils.nullObject(), this.schema, value) : (0, typebox_value.Encode)(this.schema, value);
452
+ return this.Clean ? this.Clean(out) : out;
453
+ } catch (e) {
454
+ if (this.#noValidate) return this.Clean ? this.Clean(value) : value;
455
+ if (e instanceof require_error.ValidationError) throw e;
456
+ if (e?.error) throw e.error;
457
+ if (e?.status) throw e;
458
+ throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
459
+ }
460
+ }
461
+ #markForm(value) {
462
+ if (this.#isForm && value !== null && typeof value === "object" && !("~ely-form" in value)) Object.defineProperty(value, "~ely-form", {
463
+ value: 1,
464
+ configurable: true
465
+ });
466
+ }
467
+ #unmarkForm(value) {
468
+ if (this.#isForm && value !== null && typeof value === "object" && "~ely-form" in value && Object.getOwnPropertyDescriptor(value, "~ely-form")?.configurable) delete value["~ely-form"];
469
+ }
470
+ From(value, type) {
471
+ return this.isAsync ? this.FromAsync(value, type) : this.FromSync(value, type);
472
+ }
473
+ #cloneSharedDefault() {
474
+ const defaults = this.#defaultFastPath;
475
+ const value = defaults.value;
476
+ if (value === null || typeof value !== "object") return value;
477
+ return defaults.clone ? defaults.clone() : structuredClone(value);
478
+ }
479
+ #applyPrecomputedObjectDefault(value) {
480
+ const defaults = this.#defaultFastPath;
481
+ if (defaults.merge) return defaults.merge(value);
482
+ if (Array.isArray(value)) return value;
483
+ return require_type_validator_default_precompute.applyPrecomputed(defaults.objectTemplate, value);
484
+ }
485
+ optionalBypass(value) {
486
+ const schema = this.schema;
487
+ if (!schema?.["~optional"]) return;
488
+ if (value === void 0 || value === null) return {
489
+ bypass: true,
490
+ value: schema["~kind"] === "Object" ? require_utils.nullObject() : value
491
+ };
492
+ if (schema["~kind"] === "Object" && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) return {
493
+ bypass: true,
494
+ value: require_utils.nullObject()
495
+ };
496
+ }
497
+ async FromAsync(value, type) {
498
+ if (this.hasDefault) {
499
+ const defaults = this.#defaultFastPath;
500
+ if (defaults) {
501
+ if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
502
+ else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
503
+ } else value = (0, typebox_value.Default)(this.schema, value);
504
+ }
505
+ if (this.#hasOptional) {
506
+ const bypass = this.optionalBypass(value);
507
+ if (bypass) return bypass.value;
508
+ }
509
+ if (this.#isForm) this.#markForm(value);
510
+ if (this.hasCodec) {
511
+ if (!this.#noValidate) {
512
+ require_type_elysia_file_type.collectFileTypeChecks();
513
+ const valid = this.Check(value);
514
+ const pendingFile = require_type_elysia_file_type.takeFileTypeChecks();
515
+ if (!valid) throw this.#error(value, type);
516
+ if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
517
+ }
518
+ if (this.#decodeMirror) value = this.#decodeMirror(value);
519
+ else try {
520
+ value = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), this.schema, value);
521
+ } catch (e) {
522
+ if (e instanceof require_error.ValidationError) throw e;
523
+ if (e?.error) throw e.error;
524
+ if (e?.status) throw e;
525
+ throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
526
+ }
527
+ } else if (!this.#noValidate) {
528
+ require_type_elysia_file_type.collectFileTypeChecks();
529
+ const valid = this.Check(value);
530
+ const pendingFile = require_type_elysia_file_type.takeFileTypeChecks();
531
+ if (!valid) throw this.#error(value, type);
532
+ if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
533
+ }
534
+ if (this.Clean && !this.#decodeMirror) value = this.Clean(value);
535
+ if (this.#isForm) this.#unmarkForm(value);
536
+ return value;
537
+ }
538
+ FromSync(value, type) {
539
+ if (this.hasDefault) {
540
+ const defaults = this.#defaultFastPath;
541
+ if (defaults) {
542
+ if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
543
+ else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
544
+ } else value = (0, typebox_value.Default)(this.schema, value);
545
+ }
546
+ if (this.#hasOptional) {
547
+ const bypass = this.optionalBypass(value);
548
+ if (bypass) return bypass.value;
549
+ }
550
+ if (this.#isForm) this.#markForm(value);
551
+ if (this.hasCodec) {
552
+ if (!this.#noValidate && !this.Check(value)) throw this.#error(value, type);
553
+ if (this.#decodeMirror) value = this.#decodeMirror(value);
554
+ else try {
555
+ value = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), this.schema, value);
556
+ } catch (e) {
557
+ if (e instanceof require_error.ValidationError) throw e;
558
+ if (e?.error) throw e.error;
559
+ if (e?.status) throw e;
560
+ throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
561
+ }
562
+ } else if (!this.#noValidate && !this.Check(value)) throw this.#error(value, type);
563
+ if (this.Clean && !this.#decodeMirror) value = this.Clean(value);
564
+ if (this.#isForm) this.#unmarkForm(value);
565
+ return value;
566
+ }
567
+ };
568
+
569
+ //#endregion
570
+ exports.TypeBoxValidator = TypeBoxValidator;
571
+ exports.TypeBoxValidatorCache = require_type_validator_validator_cache.TypeBoxValidatorCache;
572
+ exports.shallowMergeObjects = shallowMergeObjects;