elysia 2.0.0-exp.34 → 2.0.0-exp.35

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.
@@ -0,0 +1,7 @@
1
+ import { CaptureImpl } from "./aot.js";
2
+
3
+ //#region src/compile/aot-capture.d.ts
4
+ declare const impl: CaptureImpl;
5
+ declare function installCaptureImpl(): void;
6
+ //#endregion
7
+ export { impl as captureImplementation, installCaptureImpl };
@@ -0,0 +1,178 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
+ const require_compile_aot = require('./aot.js');
4
+ const require_compile_handler_frozen_validator = require('./handler/frozen-validator.js');
5
+ const require_type_coerce = require('../type/coerce.js');
6
+ const require_type_validator_default_precompute = require('../type/validator/default-precompute.js');
7
+ const require_type_validator_frozen_check = require('../type/validator/frozen-check.js');
8
+ const require_type_validator_custom_error = require('../type/validator/custom-error.js');
9
+ const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
10
+ const require_type_validator_index = require('../type/validator/index.js');
11
+ let typebox_schema = require("typebox/schema");
12
+ let exact_mirror = require("exact-mirror");
13
+ exact_mirror = require_runtime.__toESM(exact_mirror);
14
+
15
+ //#region src/compile/aot-capture.ts
16
+ function sourceOnlyValidator(schema) {
17
+ const buildResult = (0, typebox_schema.Build)(schema);
18
+ let full;
19
+ return new Proxy({}, { get(_, prop) {
20
+ if (prop === "buildResult") return buildResult;
21
+ const f = full ??= (0, typebox_schema.Compile)(schema);
22
+ const value = f[prop];
23
+ return typeof value === "function" ? value.bind(f) : value;
24
+ } });
25
+ }
26
+ function maybeCapture(args) {
27
+ const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
28
+ if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
29
+ const plan = require_type_coerce.captureCoercePlan(originalSchema, schema);
30
+ if (plan && require_type_validator_index.externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === require_type_validator_index.externalsShape(schema)) require_compile_aot.Capture.set({
31
+ method: aot.method,
32
+ path: aot.path,
33
+ slot
34
+ }, { coercePlan: plan });
35
+ }
36
+ const defaultFastPathCapture = {
37
+ precomputeSafe: void 0,
38
+ precomputedDefault: void 0,
39
+ precomputeNull: void 0,
40
+ precomputedObjectDefault: void 0,
41
+ defaultCloner: void 0,
42
+ objectDefaultMerger: void 0
43
+ };
44
+ if (hasDefault) {
45
+ const defaults = require_type_validator_default_precompute.verifyPreallocatableDefault(schema);
46
+ if (defaults) {
47
+ defaultFastPathCapture.precomputeSafe = true;
48
+ defaultFastPathCapture.precomputedDefault = defaults.pd;
49
+ defaultFastPathCapture.precomputeNull = defaults.pn;
50
+ defaultFastPathCapture.precomputedObjectDefault = defaults.pod;
51
+ defaultFastPathCapture.defaultCloner = defaults.pd !== void 0 ? require_type_validator_default_precompute.buildDefaultClonerSource(defaults.pd) : void 0;
52
+ defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? require_type_validator_default_precompute.buildObjectDefaultMergeSource(defaults.pod) : void 0);
53
+ }
54
+ }
55
+ require_compile_aot.Capture.set({
56
+ method: aot.method,
57
+ path: aot.path,
58
+ slot
59
+ }, defaultFastPathCapture);
60
+ const customErrors = require_type_validator_custom_error.captureCustomErrors(schema);
61
+ if (customErrors) require_compile_aot.Capture.set({
62
+ method: aot.method,
63
+ path: aot.path,
64
+ slot
65
+ }, { customErrors });
66
+ const innerCodecs = require_type_validator_string_codec_aot.captureStringCodecEntries(schema, args.sanitize);
67
+ if (innerCodecs) require_compile_aot.Capture.set({
68
+ method: aot.method,
69
+ path: aot.path,
70
+ slot
71
+ }, { innerCodecs });
72
+ const cf = require_type_validator_frozen_check.buildFrozenCheck(buildResult, schema);
73
+ if (!cf) return;
74
+ require_compile_aot.Capture.set({
75
+ method: aot.method,
76
+ path: aot.path,
77
+ slot
78
+ }, {
79
+ ...cf,
80
+ async: buildResult.external.variables.some(require_type_validator_index.isAsyncPredicate),
81
+ hasDefault,
82
+ hasCodec,
83
+ hasRef
84
+ });
85
+ }
86
+ function captureMirror(schema, aot, slot, sanitize) {
87
+ try {
88
+ const emitted = (0, exact_mirror.default)(schema, {
89
+ Compile: typebox_schema.Compile,
90
+ sanitize,
91
+ emit: true
92
+ });
93
+ if (typeof emitted?.source === "string") {
94
+ const ext = emitted.externals;
95
+ if (!ext) require_compile_aot.Capture.set({
96
+ method: aot.method,
97
+ path: aot.path,
98
+ slot
99
+ }, { mirror: {
100
+ source: emitted.source,
101
+ hasExternals: false
102
+ } });
103
+ else if (ext.unions && !ext.hof) {
104
+ const u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
105
+ if (u) require_compile_aot.Capture.set({
106
+ method: aot.method,
107
+ path: aot.path,
108
+ slot
109
+ }, { mirror: {
110
+ source: emitted.source,
111
+ hasExternals: true,
112
+ u
113
+ } });
114
+ }
115
+ }
116
+ } catch {}
117
+ }
118
+ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
119
+ const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
120
+ try {
121
+ const emitted = (0, exact_mirror.default)(schema, {
122
+ Compile: typebox_schema.Compile,
123
+ sanitize,
124
+ ...dirOpt,
125
+ emit: true
126
+ });
127
+ if (typeof emitted?.source === "string") {
128
+ const ext = emitted.externals;
129
+ if (ext?.codecs && !ext.hof && require_compile_aot.Capture.mirrorCodecs(schema, ext.codecs, dir)) {
130
+ let u;
131
+ let freezable = true;
132
+ if (ext.unions && ext.unions.length) {
133
+ u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
134
+ if (!u) freezable = false;
135
+ }
136
+ if (freezable) {
137
+ const mirror = {
138
+ source: emitted.source,
139
+ hasExternals: true,
140
+ u
141
+ };
142
+ require_compile_aot.Capture.set({
143
+ method: aot.method,
144
+ path: aot.path,
145
+ slot
146
+ }, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
147
+ }
148
+ }
149
+ }
150
+ } catch {}
151
+ }
152
+ function captureBridgeFree(aot, slot, rawSchema) {
153
+ const captured = require_compile_aot.Capture.get({
154
+ method: aot.method,
155
+ path: aot.path,
156
+ slot
157
+ });
158
+ if (captured) require_compile_aot.Capture.set({
159
+ method: aot.method,
160
+ path: aot.path,
161
+ slot
162
+ }, { bridgeFree: require_compile_handler_frozen_validator.isCapturedBridgeFree(captured, rawSchema, captured.coercePlan && typeof rawSchema !== "string" ? require_type_coerce.buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema) });
163
+ }
164
+ const impl = {
165
+ sourceOnlyValidator,
166
+ maybeCapture,
167
+ captureMirror,
168
+ captureCodecMirror,
169
+ captureBridgeFree
170
+ };
171
+ function installCaptureImpl() {
172
+ require_compile_aot.setCaptureImpl(impl);
173
+ }
174
+ installCaptureImpl();
175
+
176
+ //#endregion
177
+ exports.captureImplementation = impl;
178
+ exports.installCaptureImpl = installCaptureImpl;
@@ -0,0 +1,174 @@
1
+ import { Capture, setCaptureImpl } from "./aot.mjs";
2
+ import { isCapturedBridgeFree } from "./handler/frozen-validator.mjs";
3
+ import { buildCoercedFromPlan, captureCoercePlan } from "../type/coerce.mjs";
4
+ import { buildDefaultClonerSource, buildObjectDefaultMergeSource, verifyPreallocatableDefault } from "../type/validator/default-precompute.mjs";
5
+ import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
6
+ import { captureCustomErrors } from "../type/validator/custom-error.mjs";
7
+ import { captureStringCodecEntries } from "../type/validator/string-codec-aot.mjs";
8
+ import { externalsShape, isAsyncPredicate } from "../type/validator/index.mjs";
9
+ import { Build, Compile } from "typebox/schema";
10
+ import createMirror from "exact-mirror";
11
+
12
+ //#region src/compile/aot-capture.ts
13
+ function sourceOnlyValidator(schema) {
14
+ const buildResult = Build(schema);
15
+ let full;
16
+ return new Proxy({}, { get(_, prop) {
17
+ if (prop === "buildResult") return buildResult;
18
+ const f = full ??= Compile(schema);
19
+ const value = f[prop];
20
+ return typeof value === "function" ? value.bind(f) : value;
21
+ } });
22
+ }
23
+ function maybeCapture(args) {
24
+ const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
25
+ if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
26
+ const plan = captureCoercePlan(originalSchema, schema);
27
+ if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) Capture.set({
28
+ method: aot.method,
29
+ path: aot.path,
30
+ slot
31
+ }, { coercePlan: plan });
32
+ }
33
+ const defaultFastPathCapture = {
34
+ precomputeSafe: void 0,
35
+ precomputedDefault: void 0,
36
+ precomputeNull: void 0,
37
+ precomputedObjectDefault: void 0,
38
+ defaultCloner: void 0,
39
+ objectDefaultMerger: void 0
40
+ };
41
+ if (hasDefault) {
42
+ const defaults = verifyPreallocatableDefault(schema);
43
+ if (defaults) {
44
+ defaultFastPathCapture.precomputeSafe = true;
45
+ defaultFastPathCapture.precomputedDefault = defaults.pd;
46
+ defaultFastPathCapture.precomputeNull = defaults.pn;
47
+ defaultFastPathCapture.precomputedObjectDefault = defaults.pod;
48
+ defaultFastPathCapture.defaultCloner = defaults.pd !== void 0 ? buildDefaultClonerSource(defaults.pd) : void 0;
49
+ defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? buildObjectDefaultMergeSource(defaults.pod) : void 0);
50
+ }
51
+ }
52
+ Capture.set({
53
+ method: aot.method,
54
+ path: aot.path,
55
+ slot
56
+ }, defaultFastPathCapture);
57
+ const customErrors = captureCustomErrors(schema);
58
+ if (customErrors) Capture.set({
59
+ method: aot.method,
60
+ path: aot.path,
61
+ slot
62
+ }, { customErrors });
63
+ const innerCodecs = captureStringCodecEntries(schema, args.sanitize);
64
+ if (innerCodecs) Capture.set({
65
+ method: aot.method,
66
+ path: aot.path,
67
+ slot
68
+ }, { innerCodecs });
69
+ const cf = buildFrozenCheck(buildResult, schema);
70
+ if (!cf) return;
71
+ Capture.set({
72
+ method: aot.method,
73
+ path: aot.path,
74
+ slot
75
+ }, {
76
+ ...cf,
77
+ async: buildResult.external.variables.some(isAsyncPredicate),
78
+ hasDefault,
79
+ hasCodec,
80
+ hasRef
81
+ });
82
+ }
83
+ function captureMirror(schema, aot, slot, sanitize) {
84
+ try {
85
+ const emitted = createMirror(schema, {
86
+ Compile,
87
+ sanitize,
88
+ emit: true
89
+ });
90
+ if (typeof emitted?.source === "string") {
91
+ const ext = emitted.externals;
92
+ if (!ext) Capture.set({
93
+ method: aot.method,
94
+ path: aot.path,
95
+ slot
96
+ }, { mirror: {
97
+ source: emitted.source,
98
+ hasExternals: false
99
+ } });
100
+ else if (ext.unions && !ext.hof) {
101
+ const u = Capture.mirrorUnions(schema, ext.unions);
102
+ if (u) Capture.set({
103
+ method: aot.method,
104
+ path: aot.path,
105
+ slot
106
+ }, { mirror: {
107
+ source: emitted.source,
108
+ hasExternals: true,
109
+ u
110
+ } });
111
+ }
112
+ }
113
+ } catch {}
114
+ }
115
+ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
116
+ const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
117
+ try {
118
+ const emitted = createMirror(schema, {
119
+ Compile,
120
+ sanitize,
121
+ ...dirOpt,
122
+ emit: true
123
+ });
124
+ if (typeof emitted?.source === "string") {
125
+ const ext = emitted.externals;
126
+ if (ext?.codecs && !ext.hof && Capture.mirrorCodecs(schema, ext.codecs, dir)) {
127
+ let u;
128
+ let freezable = true;
129
+ if (ext.unions && ext.unions.length) {
130
+ u = Capture.mirrorUnions(schema, ext.unions);
131
+ if (!u) freezable = false;
132
+ }
133
+ if (freezable) {
134
+ const mirror = {
135
+ source: emitted.source,
136
+ hasExternals: true,
137
+ u
138
+ };
139
+ Capture.set({
140
+ method: aot.method,
141
+ path: aot.path,
142
+ slot
143
+ }, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
144
+ }
145
+ }
146
+ }
147
+ } catch {}
148
+ }
149
+ function captureBridgeFree(aot, slot, rawSchema) {
150
+ const captured = Capture.get({
151
+ method: aot.method,
152
+ path: aot.path,
153
+ slot
154
+ });
155
+ if (captured) Capture.set({
156
+ method: aot.method,
157
+ path: aot.path,
158
+ slot
159
+ }, { bridgeFree: isCapturedBridgeFree(captured, rawSchema, captured.coercePlan && typeof rawSchema !== "string" ? buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema) });
160
+ }
161
+ const impl = {
162
+ sourceOnlyValidator,
163
+ maybeCapture,
164
+ captureMirror,
165
+ captureCodecMirror,
166
+ captureBridgeFree
167
+ };
168
+ function installCaptureImpl() {
169
+ setCaptureImpl(impl);
170
+ }
171
+ installCaptureImpl();
172
+
173
+ //#endregion
174
+ export { impl as captureImplementation, installCaptureImpl };
@@ -213,19 +213,60 @@ declare function captureSet(loc: {
213
213
  path: string;
214
214
  slot: ValidatorSlot;
215
215
  }, partial: Partial<CapturedValidator>): void;
216
- declare function captureGet(loc: {
217
- method: string;
218
- path: string;
219
- slot: ValidatorSlot;
220
- }): CapturedValidator | undefined;
221
216
  declare const Capture: {
222
217
  readonly set: typeof captureSet;
223
- readonly get: typeof captureGet;
218
+ readonly get: (loc: {
219
+ method: string;
220
+ path: string;
221
+ slot: ValidatorSlot;
222
+ }) => CapturedValidator | undefined;
224
223
  readonly handler: typeof captureHandler;
225
224
  readonly mirrorUnions: typeof captureMirrorUnions;
226
225
  readonly mirrorCodecs: typeof captureMirrorCodecs;
227
226
  readonly isCapturing: () => boolean;
228
227
  readonly isAotBuildEnv: () => boolean;
229
228
  };
229
+ interface CaptureImpl {
230
+ /** Source-only TypeBox validator (retains codegen source for the manifest). */
231
+ sourceOnlyValidator(schema: any): any;
232
+ /**
233
+ * Capture the frozen check + defaults + custom-errors + inner-codecs + coerce
234
+ * plan for a validator slot. Mirrors the former `#maybeCapture`.
235
+ */
236
+ maybeCapture(args: {
237
+ aot: {
238
+ method: string;
239
+ path: string;
240
+ };
241
+ slot: ValidatorSlot;
242
+ hasRef: boolean;
243
+ originalSchema: any;
244
+ schema: any;
245
+ hasCodec: boolean;
246
+ hasDefault: boolean;
247
+ coerces: unknown;
248
+ normalize: boolean | 'exactMirror' | 'typebox' | undefined;
249
+ sanitize: unknown;
250
+ buildResult: CheckBuildResult;
251
+ }): void;
252
+ /** Capture the exact-mirror clean emit for a slot (former `#setupMirror`). */
253
+ captureMirror(schema: any, aot: {
254
+ method: string;
255
+ path: string;
256
+ }, slot: ValidatorSlot, sanitize: unknown): void;
257
+ /** Capture the codec decode/encode mirror emit (former `#setupCodecMirror`). */
258
+ captureCodecMirror(schema: any, aot: {
259
+ method: string;
260
+ path: string;
261
+ }, slot: ValidatorSlot, sanitize: unknown, dir: 'decode' | 'encode'): void;
262
+ /** Derive + store the bridge-free marker once every channel is captured. */
263
+ captureBridgeFree(aot: {
264
+ method: string;
265
+ path: string;
266
+ }, slot: ValidatorSlot, rawSchema: unknown): void;
267
+ }
268
+ /** Installed by the AOT build plugin; undefined at runtime. */
269
+ declare let captureImpl: CaptureImpl | undefined;
270
+ declare function setCaptureImpl(impl: CaptureImpl | undefined): void;
230
271
  //#endregion
231
- export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
272
+ export { Capture, CaptureImpl, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, StringCodecNode, ValidatorManifest, ValidatorSlot, beginValidatorCapture, captureImpl, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs, setCaptureImpl };
@@ -304,7 +304,9 @@ function captureEntry({ method, path, slot }) {
304
304
  });
305
305
  return e;
306
306
  }
307
+ const aotActivationError = /* @__PURE__ */ new Error("Elysia AOT capture module is not activated.");
307
308
  function beginValidatorCapture() {
309
+ if (captureImpl === void 0) throw aotActivationError;
308
310
  capture = /* @__PURE__ */ new Map();
309
311
  }
310
312
  function endValidatorCapture() {
@@ -327,13 +329,18 @@ function captureSet(loc, partial) {
327
329
  const e = captureEntry(loc);
328
330
  if (e) Object.assign(e, partial);
329
331
  }
330
- function captureGet(loc) {
331
- return capture?.get(`${loc.method}_${loc.path}_${loc.slot}`);
332
- }
332
+ const captureGet = (loc) => capture?.get(`${loc.method}_${loc.path}_${loc.slot}`);
333
333
  const isAotBuildEnv = () => !!require_universal_env.env.ELYSIA_AOT_BUILD;
334
334
  const isValidatorCapturing = () => {
335
- if (capture !== void 0) return true;
336
- return isAotBuildEnv();
335
+ if (capture !== void 0) {
336
+ if (captureImpl === void 0) throw aotActivationError;
337
+ return true;
338
+ }
339
+ if (isAotBuildEnv()) {
340
+ if (captureImpl === void 0) throw aotActivationError;
341
+ return true;
342
+ }
343
+ return false;
337
344
  };
338
345
  const Capture = {
339
346
  set: captureSet,
@@ -344,6 +351,11 @@ const Capture = {
344
351
  isCapturing: isValidatorCapturing,
345
352
  isAotBuildEnv
346
353
  };
354
+ /** Installed by the AOT build plugin; undefined at runtime. */
355
+ let captureImpl;
356
+ function setCaptureImpl(impl) {
357
+ captureImpl = impl;
358
+ }
347
359
 
348
360
  //#endregion
349
361
  exports.Capture = Capture;
@@ -351,6 +363,12 @@ exports.Compiled = Compiled;
351
363
  exports.EMPTY_EXTERNALS = EMPTY_EXTERNALS;
352
364
  exports.Source = Source;
353
365
  exports.beginValidatorCapture = beginValidatorCapture;
366
+ Object.defineProperty(exports, 'captureImpl', {
367
+ enumerable: true,
368
+ get: function () {
369
+ return captureImpl;
370
+ }
371
+ });
354
372
  exports.collectExternals = collectExternals;
355
373
  exports.collectMirrorUnions = collectMirrorUnions;
356
374
  exports.collectStringCodecNodes = collectStringCodecNodes;
@@ -362,4 +380,5 @@ exports.instantiateFrozenDecodeMirror = instantiateFrozenDecodeMirror;
362
380
  exports.instantiateFrozenEncodeMirror = instantiateFrozenEncodeMirror;
363
381
  exports.instantiateFrozenMirror = instantiateFrozenMirror;
364
382
  exports.reconstructCheck = reconstructCheck;
365
- exports.reconstructInnerCodecs = reconstructInnerCodecs;
383
+ exports.reconstructInnerCodecs = reconstructInnerCodecs;
384
+ exports.setCaptureImpl = setCaptureImpl;
@@ -303,7 +303,9 @@ function captureEntry({ method, path, slot }) {
303
303
  });
304
304
  return e;
305
305
  }
306
+ const aotActivationError = /* @__PURE__ */ new Error("Elysia AOT capture module is not activated.");
306
307
  function beginValidatorCapture() {
308
+ if (captureImpl === void 0) throw aotActivationError;
307
309
  capture = /* @__PURE__ */ new Map();
308
310
  }
309
311
  function endValidatorCapture() {
@@ -326,13 +328,18 @@ function captureSet(loc, partial) {
326
328
  const e = captureEntry(loc);
327
329
  if (e) Object.assign(e, partial);
328
330
  }
329
- function captureGet(loc) {
330
- return capture?.get(`${loc.method}_${loc.path}_${loc.slot}`);
331
- }
331
+ const captureGet = (loc) => capture?.get(`${loc.method}_${loc.path}_${loc.slot}`);
332
332
  const isAotBuildEnv = () => !!env.ELYSIA_AOT_BUILD;
333
333
  const isValidatorCapturing = () => {
334
- if (capture !== void 0) return true;
335
- return isAotBuildEnv();
334
+ if (capture !== void 0) {
335
+ if (captureImpl === void 0) throw aotActivationError;
336
+ return true;
337
+ }
338
+ if (isAotBuildEnv()) {
339
+ if (captureImpl === void 0) throw aotActivationError;
340
+ return true;
341
+ }
342
+ return false;
336
343
  };
337
344
  const Capture = {
338
345
  set: captureSet,
@@ -343,6 +350,11 @@ const Capture = {
343
350
  isCapturing: isValidatorCapturing,
344
351
  isAotBuildEnv
345
352
  };
353
+ /** Installed by the AOT build plugin; undefined at runtime. */
354
+ let captureImpl;
355
+ function setCaptureImpl(impl) {
356
+ captureImpl = impl;
357
+ }
346
358
 
347
359
  //#endregion
348
- export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs };
360
+ export { Capture, Compiled, EMPTY_EXTERNALS, Source, beginValidatorCapture, captureImpl, collectExternals, collectMirrorUnions, collectStringCodecNodes, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck, reconstructInnerCodecs, setCaptureImpl };
@@ -1,5 +1,5 @@
1
1
  //#region src/compile/lexer.d.ts
2
- declare const isSpace: (ch: string) => ch is " " | "\n" | "\t" | "\r";
2
+ declare const isSpace: (ch: string) => ch is "\n" | " " | "\t" | "\r";
3
3
  declare const isIdentChar: (ch: string) => boolean;
4
4
  declare const isIdentCharCode: (code: number) => boolean;
5
5
  declare function skipString(src: string, start: number): number;
@@ -6,8 +6,10 @@ const require_compile_jit_probe = require('../compile/jit-probe.js');
6
6
  const require_compile_handler_jit = require('../compile/handler/jit.js');
7
7
  const require_validator_index = require('../validator/index.js');
8
8
  const require_compile_handler_index = require('../compile/handler/index.js');
9
+ const require_compile_aot_capture = require('../compile/aot-capture.js');
9
10
 
10
11
  //#region src/plugin/source.ts
12
+ require_compile_aot_capture.installCaptureImpl();
11
13
  const autoGroupSize = (routes) => routes < 64 ? 1 : routes < 256 ? 2 : routes < 2048 ? 4 : routes < 8192 ? 16 : 64;
12
14
  async function compileToSource(app, options) {
13
15
  return (await captureArtifacts(app, options)).source;
@@ -5,8 +5,10 @@ import { JITProbe } from "../compile/jit-probe.mjs";
5
5
  import { setCaptureHeaderShorthand } from "../compile/handler/jit.mjs";
6
6
  import { Validator } from "../validator/index.mjs";
7
7
  import { compileHandler } from "../compile/handler/index.mjs";
8
+ import { installCaptureImpl } from "../compile/aot-capture.mjs";
8
9
 
9
10
  //#region src/plugin/source.ts
11
+ installCaptureImpl();
10
12
  const autoGroupSize = (routes) => routes < 64 ? 1 : routes < 256 ? 2 : routes < 2048 ? 4 : routes < 8192 ? 16 : 64;
11
13
  async function compileToSource(app, options) {
12
14
  return (await captureArtifacts(app, options)).source;
@@ -1,17 +1,17 @@
1
- import { Intersect as Intersect$1 } from "./elysia/intersect.js";
1
+ import { Intersect as Intersect$2 } from "./elysia/intersect.js";
2
2
  import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
3
3
  import { hasTypes as hasTypes$1 } from "./utils.js";
4
4
  import { TypeBoxValidatorCache as TypeBoxValidatorCache$1 } from "./validator/validator-cache.js";
5
5
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
6
6
  import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
7
7
  import { Compile as Compile$1 } from "typebox/compile";
8
- import { Clone as Clone$1, Create as Create$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
8
+ import { Clone as Clone$1, Create as Create$1, Decode as Decode$2, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
9
9
 
10
10
  //#region src/type/bridge.d.ts
11
11
  interface TypeboxModule {
12
12
  Compile: typeof Compile$1;
13
13
  Create: typeof Create$1;
14
- Decode: typeof Decode$1;
14
+ Decode: typeof Decode$2;
15
15
  applyCoercions: typeof applyCoercions$1;
16
16
  TypeBoxValidator: TypeBoxValidator$1;
17
17
  TypeBoxValidatorCache: TypeBoxValidatorCache$1;
@@ -22,14 +22,14 @@ interface TypeboxModule {
22
22
  coerceBody: typeof coerceBody$1;
23
23
  hasTypes: typeof hasTypes$1;
24
24
  HasCodec: typeof HasCodec$1;
25
- Intersect: typeof Intersect$1;
25
+ Intersect: typeof Intersect$2;
26
26
  Default: typeof Default$1;
27
27
  Ref: typeof Ref$1;
28
28
  Clone: typeof Clone$1;
29
29
  }
30
30
  declare let Compile: typeof Compile$1;
31
31
  declare let Create: typeof Create$1;
32
- declare let Decode: typeof Decode$1;
32
+ declare let Decode: typeof Decode$2;
33
33
  declare let applyCoercions: typeof applyCoercions$1;
34
34
  declare let TypeBoxValidator: TypeBoxValidator$1;
35
35
  type TypeBoxValidator<T extends TSchema = TAny> = TypeBoxValidator$1<T>;
@@ -42,7 +42,7 @@ declare let coerceStringToStructure: typeof coerceStringToStructure$1;
42
42
  declare let coerceBody: typeof coerceBody$1;
43
43
  declare let hasTypes: typeof hasTypes$1;
44
44
  declare let HasCodec: typeof HasCodec$1;
45
- declare let Intersect: typeof Intersect$1;
45
+ declare let Intersect: typeof Intersect$2;
46
46
  declare let Default: typeof Default$1;
47
47
  declare let Ref: typeof Ref$1;
48
48
  declare let Clone: typeof Clone$1;
@@ -1,9 +1,9 @@
1
1
  import { ELYSIA_TYPES } from "./constants.js";
2
2
  import { CookieOptions } from "../cookie/types.js";
3
3
  import { MaybeArray } from "../types.js";
4
+ import { Validator } from "typebox/schema";
4
5
  import { TObjectOptions, TSchemaOptions } from "typebox";
5
6
  import { TLocalizedValidationError } from "typebox/error";
6
- import { Validator } from "typebox/schema";
7
7
 
8
8
  //#region src/type/types.d.ts
9
9
  type FileUnit = number | `${number}${'k' | 'm'}`;
@@ -7,6 +7,8 @@ import { TLocalizedValidationError } from "typebox/error";
7
7
 
8
8
  //#region src/type/validator/index.d.ts
9
9
  declare function shallowMergeObjects(members: any[]): TSchema | null;
10
+ declare const isAsyncPredicate: (v: unknown) => boolean;
11
+ declare function externalsShape(schema: unknown): string;
10
12
  declare class TypeBoxValidator<const in out T extends TSchema = TAny> extends Validator$1 {
11
13
  #private;
12
14
  tb?: Validator;
@@ -28,4 +30,4 @@ declare class TypeBoxValidator<const in out T extends TSchema = TAny> extends Va
28
30
  FromSync(value: Static<T>, type?: string): Static<T>;
29
31
  }
30
32
  //#endregion
31
- export { TypeBoxValidator, TypeBoxValidatorCache, shallowMergeObjects };
33
+ export { TypeBoxValidator, TypeBoxValidatorCache, externalsShape, isAsyncPredicate, shallowMergeObjects };
@@ -7,14 +7,11 @@ const require_compile_aot = require('../../compile/aot.js');
7
7
  const require_compile_utils = require('../../compile/utils.js');
8
8
  const require_validator_index = require('../../validator/index.js');
9
9
  const require_type_validator_clean_safe = require('./clean-safe.js');
10
- const require_compile_handler_frozen_validator = require('../../compile/handler/frozen-validator.js');
11
10
  const require_type_coerce = require('../coerce.js');
12
11
  const require_type_utils = require('../utils.js');
13
12
  const require_type_elysia_file_type = require('../elysia/file-type.js');
14
13
  const require_type_validator_default_precompute = require('./default-precompute.js');
15
- const require_type_validator_frozen_check = require('./frozen-check.js');
16
14
  const require_type_validator_custom_error = require('./custom-error.js');
17
- const require_type_validator_string_codec_aot = require('./string-codec-aot.js');
18
15
  const require_type_validator_validator_cache = require('./validator-cache.js');
19
16
  let typebox_type = require("typebox/type");
20
17
  let typebox_value = require("typebox/value");
@@ -90,16 +87,6 @@ function externalsShape(schema) {
90
87
  for (const e of require_compile_aot.collectExternals(schema)) out += e instanceof RegExp ? "r" : typeof e === "function" ? "f" : "v";
91
88
  return out;
92
89
  }
93
- function sourceOnlyValidator(schema) {
94
- const buildResult = (0, typebox_schema.Build)(schema);
95
- let full;
96
- return new Proxy({}, { get(_, prop) {
97
- if (prop === "buildResult") return buildResult;
98
- const f = full ??= (0, typebox_schema.Compile)(schema);
99
- const value = f[prop];
100
- return typeof value === "function" ? value.bind(f) : value;
101
- } });
102
- }
103
90
  var TypeBoxValidator = class extends require_validator_index.Validator {
104
91
  #decodeMirror;
105
92
  #encodeMirror;
@@ -144,12 +131,24 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
144
131
  if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = require_type_coerce.nonAdditionalProperties(this.schema);
145
132
  if (!isFrozen) {
146
133
  const capturing = require_compile_aot.Capture.isCapturing();
147
- this.tb = capturing ? sourceOnlyValidator(this.schema) : (0, typebox_schema.Compile)(this.schema);
134
+ this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) : (0, typebox_schema.Compile)(this.schema);
148
135
  this.hasCodec = (0, typebox_value.HasCodec)(this.schema);
149
136
  this.isAsync = this.tb.buildResult.external.variables.some(isAsyncPredicate) ?? false;
150
137
  this.hasDefault = require_type_utils.hasProperty("default", this.schema);
151
- if (capturing) this.#maybeCapture(options, schemaHasRef, schema);
152
- else this.#dropCompiledSource();
138
+ if (capturing && require_compile_aot.captureImpl && options?.aot && options.slot) require_compile_aot.captureImpl.maybeCapture({
139
+ aot: options.aot,
140
+ slot: options.slot,
141
+ hasRef: schemaHasRef,
142
+ originalSchema: schema,
143
+ schema: this.schema,
144
+ hasCodec: this.hasCodec,
145
+ hasDefault: this.hasDefault,
146
+ coerces: options.coerces,
147
+ normalize: options.normalize,
148
+ sanitize: options.sanitize,
149
+ buildResult: this.tb.buildResult
150
+ });
151
+ else if (!capturing) this.#dropCompiledSource();
153
152
  }
154
153
  if (frozen?.ps === 1) {
155
154
  const objectTemplate = frozen.pod !== void 0 ? Object.freeze(frozen.pod) : void 0;
@@ -201,18 +200,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
201
200
  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");
202
201
  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");
203
202
  if (!this.#noValidate) this.#findCustomError = require_type_validator_custom_error.buildFindCustomError(this.schema, frozen);
204
- if (options?.aot && options.slot && require_compile_aot.Capture.isCapturing()) {
205
- const captured = require_compile_aot.Capture.get({
206
- method: options.aot.method,
207
- path: options.aot.path,
208
- slot: options.slot
209
- });
210
- if (captured) require_compile_aot.Capture.set({
211
- method: options.aot.method,
212
- path: options.aot.path,
213
- slot: options.slot
214
- }, { bridgeFree: require_compile_handler_frozen_validator.isCapturedBridgeFree(captured, rawSchema, captured.coercePlan && typeof rawSchema !== "string" ? require_type_coerce.buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema) });
215
- }
203
+ if (options?.aot && options.slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureBridgeFree(options.aot, options.slot, rawSchema);
216
204
  }
217
205
  #error(value, type) {
218
206
  return new require_error.ValidationError(type, value, () => this.Errors(value), this.schema, this.#findCustomError);
@@ -235,38 +223,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
235
223
  return clean(value);
236
224
  };
237
225
  }
238
- if (aot && slot) {
239
- if (require_compile_aot.Capture.isCapturing()) try {
240
- const emitted = (0, exact_mirror.default)(schema, {
241
- Compile: typebox_schema.Compile,
242
- sanitize: options?.sanitize,
243
- emit: true
244
- });
245
- if (typeof emitted?.source === "string") {
246
- const ext = emitted.externals;
247
- if (!ext) require_compile_aot.Capture.set({
248
- method: aot.method,
249
- path: aot.path,
250
- slot
251
- }, { mirror: {
252
- source: emitted.source,
253
- hasExternals: false
254
- } });
255
- else if (ext.unions && !ext.hof) {
256
- const u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
257
- if (u) require_compile_aot.Capture.set({
258
- method: aot.method,
259
- path: aot.path,
260
- slot
261
- }, { mirror: {
262
- source: emitted.source,
263
- hasExternals: true,
264
- u
265
- } });
266
- }
267
- }
268
- } catch {}
269
- }
226
+ if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
270
227
  return (0, exact_mirror.default)(schema, {
271
228
  Compile: typebox_schema.Compile,
272
229
  sanitize: options?.sanitize
@@ -296,37 +253,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
296
253
  }
297
254
  const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
298
255
  const captureSlot = dir === "decode" ? !slot?.startsWith("response") : !!slot?.startsWith("response");
299
- if (aot && slot && require_compile_aot.Capture.isCapturing() && captureSlot) try {
300
- const emitted = (0, exact_mirror.default)(schema, {
301
- Compile: typebox_schema.Compile,
302
- sanitize: options?.sanitize,
303
- ...dirOpt,
304
- emit: true
305
- });
306
- if (typeof emitted?.source === "string") {
307
- const ext = emitted.externals;
308
- if (ext?.codecs && !ext.hof && require_compile_aot.Capture.mirrorCodecs(schema, ext.codecs, dir)) {
309
- let u;
310
- let freezable = true;
311
- if (ext.unions && ext.unions.length) {
312
- u = require_compile_aot.Capture.mirrorUnions(schema, ext.unions);
313
- if (!u) freezable = false;
314
- }
315
- if (freezable) {
316
- const mirror = {
317
- source: emitted.source,
318
- hasExternals: true,
319
- u
320
- };
321
- require_compile_aot.Capture.set({
322
- method: aot.method,
323
- path: aot.path,
324
- slot
325
- }, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
326
- }
327
- }
328
- }
329
- } catch {}
256
+ if (aot && slot && require_compile_aot.Capture.isCapturing() && captureSlot && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureCodecMirror(schema, aot, slot, options?.sanitize, dir);
330
257
  try {
331
258
  return (0, exact_mirror.default)(schema, {
332
259
  Compile: typebox_schema.Compile,
@@ -347,69 +274,6 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
347
274
  this.hasCodec = frozen.k === 1;
348
275
  return true;
349
276
  }
350
- #maybeCapture(options, hasRef, originalSchema) {
351
- const aot = options?.aot;
352
- const slot = options?.slot;
353
- if (!aot || !slot || !require_compile_aot.Capture.isCapturing()) return;
354
- if (this.hasCodec && !hasRef && options.coerces && options.normalize !== false && options.normalize !== "typebox") {
355
- const plan = require_type_coerce.captureCoercePlan(originalSchema, this.schema);
356
- if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(this.schema)) require_compile_aot.Capture.set({
357
- method: aot.method,
358
- path: aot.path,
359
- slot
360
- }, { coercePlan: plan });
361
- }
362
- const defaultFastPathCapture = {
363
- precomputeSafe: void 0,
364
- precomputedDefault: void 0,
365
- precomputeNull: void 0,
366
- precomputedObjectDefault: void 0,
367
- defaultCloner: void 0,
368
- objectDefaultMerger: void 0
369
- };
370
- if (this.hasDefault) {
371
- const defaults = require_type_validator_default_precompute.verifyPreallocatableDefault(this.schema);
372
- if (defaults) {
373
- defaultFastPathCapture.precomputeSafe = true;
374
- defaultFastPathCapture.precomputedDefault = defaults.pd;
375
- defaultFastPathCapture.precomputeNull = defaults.pn;
376
- defaultFastPathCapture.precomputedObjectDefault = defaults.pod;
377
- defaultFastPathCapture.defaultCloner = defaults.pd !== void 0 ? require_type_validator_default_precompute.buildDefaultClonerSource(defaults.pd) : void 0;
378
- defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? require_type_validator_default_precompute.buildObjectDefaultMergeSource(defaults.pod) : void 0);
379
- }
380
- }
381
- require_compile_aot.Capture.set({
382
- method: aot.method,
383
- path: aot.path,
384
- slot
385
- }, defaultFastPathCapture);
386
- const customErrors = require_type_validator_custom_error.captureCustomErrors(this.schema);
387
- if (customErrors) require_compile_aot.Capture.set({
388
- method: aot.method,
389
- path: aot.path,
390
- slot
391
- }, { customErrors });
392
- const innerCodecs = require_type_validator_string_codec_aot.captureStringCodecEntries(this.schema, options?.sanitize);
393
- if (innerCodecs) require_compile_aot.Capture.set({
394
- method: aot.method,
395
- path: aot.path,
396
- slot
397
- }, { innerCodecs });
398
- const build = this.tb.buildResult;
399
- const cf = require_type_validator_frozen_check.buildFrozenCheck(build, this.schema);
400
- if (!cf) return;
401
- require_compile_aot.Capture.set({
402
- method: aot.method,
403
- path: aot.path,
404
- slot
405
- }, {
406
- ...cf,
407
- async: build.external.variables.some(isAsyncPredicate),
408
- hasDefault: this.hasDefault,
409
- hasCodec: this.hasCodec,
410
- hasRef
411
- });
412
- }
413
277
  #dropCompiledSource() {
414
278
  const tb = this.tb;
415
279
  if (!tb) return;
@@ -572,4 +436,6 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
572
436
  //#endregion
573
437
  exports.TypeBoxValidator = TypeBoxValidator;
574
438
  exports.TypeBoxValidatorCache = require_type_validator_validator_cache.TypeBoxValidatorCache;
439
+ exports.externalsShape = externalsShape;
440
+ exports.isAsyncPredicate = isAsyncPredicate;
575
441
  exports.shallowMergeObjects = shallowMergeObjects;
@@ -1,22 +1,19 @@
1
1
  import { nullObject } from "../../utils.mjs";
2
2
  import { ELYSIA_TYPES } from "../constants.mjs";
3
3
  import { ValidationError } from "../../error.mjs";
4
- import { Capture, Compiled, EMPTY_EXTERNALS, collectExternals, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenMirror, reconstructInnerCodecs } from "../../compile/aot.mjs";
4
+ import { Capture, Compiled, EMPTY_EXTERNALS, captureImpl, collectExternals, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenMirror, reconstructInnerCodecs } from "../../compile/aot.mjs";
5
5
  import { isAsyncFunction } from "../../compile/utils.mjs";
6
6
  import { Validator as Validator$1 } from "../../validator/index.mjs";
7
7
  import { isFullyClosedObject, schemaContainsRef } from "./clean-safe.mjs";
8
- import { isCapturedBridgeFree } from "../../compile/handler/frozen-validator.mjs";
9
- import { applyCoercions, buildCoercedFromPlan, captureCoercePlan, nonAdditionalProperties } from "../coerce.mjs";
8
+ import { applyCoercions, buildCoercedFromPlan, nonAdditionalProperties } from "../coerce.mjs";
10
9
  import { hasProperty } from "../utils.mjs";
11
10
  import { ASYNC_REFINE, collectFileTypeChecks, takeFileTypeChecks } from "../elysia/file-type.mjs";
12
- import { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, verifyPreallocatableDefault } from "./default-precompute.mjs";
13
- import { buildFrozenCheck } from "./frozen-check.mjs";
14
- import { buildFindCustomError, captureCustomErrors } from "./custom-error.mjs";
15
- import { captureStringCodecEntries } from "./string-codec-aot.mjs";
11
+ import { applyPrecomputed, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, verifyPreallocatableDefault } from "./default-precompute.mjs";
12
+ import { buildFindCustomError } from "./custom-error.mjs";
16
13
  import { TypeBoxValidatorCache } from "./validator-cache.mjs";
17
14
  import { Evaluate, Intersect, Module } from "typebox/type";
18
15
  import { Clean, Decode as Decode$1, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
19
- import { Build, Compile } from "typebox/schema";
16
+ import { Compile } from "typebox/schema";
20
17
  import createMirror from "exact-mirror";
21
18
 
22
19
  //#region src/type/validator/index.ts
@@ -87,16 +84,6 @@ function externalsShape(schema) {
87
84
  for (const e of collectExternals(schema)) out += e instanceof RegExp ? "r" : typeof e === "function" ? "f" : "v";
88
85
  return out;
89
86
  }
90
- function sourceOnlyValidator(schema) {
91
- const buildResult = Build(schema);
92
- let full;
93
- return new Proxy({}, { get(_, prop) {
94
- if (prop === "buildResult") return buildResult;
95
- const f = full ??= Compile(schema);
96
- const value = f[prop];
97
- return typeof value === "function" ? value.bind(f) : value;
98
- } });
99
- }
100
87
  var TypeBoxValidator = class extends Validator$1 {
101
88
  #decodeMirror;
102
89
  #encodeMirror;
@@ -141,12 +128,24 @@ var TypeBoxValidator = class extends Validator$1 {
141
128
  if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = nonAdditionalProperties(this.schema);
142
129
  if (!isFrozen) {
143
130
  const capturing = Capture.isCapturing();
144
- this.tb = capturing ? sourceOnlyValidator(this.schema) : Compile(this.schema);
131
+ this.tb = capturing && captureImpl ? captureImpl.sourceOnlyValidator(this.schema) : Compile(this.schema);
145
132
  this.hasCodec = HasCodec(this.schema);
146
133
  this.isAsync = this.tb.buildResult.external.variables.some(isAsyncPredicate) ?? false;
147
134
  this.hasDefault = hasProperty("default", this.schema);
148
- if (capturing) this.#maybeCapture(options, schemaHasRef, schema);
149
- else this.#dropCompiledSource();
135
+ if (capturing && captureImpl && options?.aot && options.slot) captureImpl.maybeCapture({
136
+ aot: options.aot,
137
+ slot: options.slot,
138
+ hasRef: schemaHasRef,
139
+ originalSchema: schema,
140
+ schema: this.schema,
141
+ hasCodec: this.hasCodec,
142
+ hasDefault: this.hasDefault,
143
+ coerces: options.coerces,
144
+ normalize: options.normalize,
145
+ sanitize: options.sanitize,
146
+ buildResult: this.tb.buildResult
147
+ });
148
+ else if (!capturing) this.#dropCompiledSource();
150
149
  }
151
150
  if (frozen?.ps === 1) {
152
151
  const objectTemplate = frozen.pod !== void 0 ? Object.freeze(frozen.pod) : void 0;
@@ -198,18 +197,7 @@ var TypeBoxValidator = class extends Validator$1 {
198
197
  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");
199
198
  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");
200
199
  if (!this.#noValidate) this.#findCustomError = buildFindCustomError(this.schema, frozen);
201
- if (options?.aot && options.slot && Capture.isCapturing()) {
202
- const captured = Capture.get({
203
- method: options.aot.method,
204
- path: options.aot.path,
205
- slot: options.slot
206
- });
207
- if (captured) Capture.set({
208
- method: options.aot.method,
209
- path: options.aot.path,
210
- slot: options.slot
211
- }, { bridgeFree: isCapturedBridgeFree(captured, rawSchema, captured.coercePlan && typeof rawSchema !== "string" ? buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema) });
212
- }
200
+ if (options?.aot && options.slot && Capture.isCapturing() && captureImpl) captureImpl.captureBridgeFree(options.aot, options.slot, rawSchema);
213
201
  }
214
202
  #error(value, type) {
215
203
  return new ValidationError(type, value, () => this.Errors(value), this.schema, this.#findCustomError);
@@ -232,38 +220,7 @@ var TypeBoxValidator = class extends Validator$1 {
232
220
  return clean(value);
233
221
  };
234
222
  }
235
- if (aot && slot) {
236
- if (Capture.isCapturing()) try {
237
- const emitted = createMirror(schema, {
238
- Compile,
239
- sanitize: options?.sanitize,
240
- emit: true
241
- });
242
- if (typeof emitted?.source === "string") {
243
- const ext = emitted.externals;
244
- if (!ext) Capture.set({
245
- method: aot.method,
246
- path: aot.path,
247
- slot
248
- }, { mirror: {
249
- source: emitted.source,
250
- hasExternals: false
251
- } });
252
- else if (ext.unions && !ext.hof) {
253
- const u = Capture.mirrorUnions(schema, ext.unions);
254
- if (u) Capture.set({
255
- method: aot.method,
256
- path: aot.path,
257
- slot
258
- }, { mirror: {
259
- source: emitted.source,
260
- hasExternals: true,
261
- u
262
- } });
263
- }
264
- }
265
- } catch {}
266
- }
223
+ if (aot && slot && Capture.isCapturing() && captureImpl) captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
267
224
  return createMirror(schema, {
268
225
  Compile,
269
226
  sanitize: options?.sanitize
@@ -293,37 +250,7 @@ var TypeBoxValidator = class extends Validator$1 {
293
250
  }
294
251
  const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
295
252
  const captureSlot = dir === "decode" ? !slot?.startsWith("response") : !!slot?.startsWith("response");
296
- if (aot && slot && Capture.isCapturing() && captureSlot) try {
297
- const emitted = createMirror(schema, {
298
- Compile,
299
- sanitize: options?.sanitize,
300
- ...dirOpt,
301
- emit: true
302
- });
303
- if (typeof emitted?.source === "string") {
304
- const ext = emitted.externals;
305
- if (ext?.codecs && !ext.hof && Capture.mirrorCodecs(schema, ext.codecs, dir)) {
306
- let u;
307
- let freezable = true;
308
- if (ext.unions && ext.unions.length) {
309
- u = Capture.mirrorUnions(schema, ext.unions);
310
- if (!u) freezable = false;
311
- }
312
- if (freezable) {
313
- const mirror = {
314
- source: emitted.source,
315
- hasExternals: true,
316
- u
317
- };
318
- Capture.set({
319
- method: aot.method,
320
- path: aot.path,
321
- slot
322
- }, dir === "decode" ? { decodeMirror: mirror } : { encodeMirror: mirror });
323
- }
324
- }
325
- }
326
- } catch {}
253
+ if (aot && slot && Capture.isCapturing() && captureSlot && captureImpl) captureImpl.captureCodecMirror(schema, aot, slot, options?.sanitize, dir);
327
254
  try {
328
255
  return createMirror(schema, {
329
256
  Compile,
@@ -344,69 +271,6 @@ var TypeBoxValidator = class extends Validator$1 {
344
271
  this.hasCodec = frozen.k === 1;
345
272
  return true;
346
273
  }
347
- #maybeCapture(options, hasRef, originalSchema) {
348
- const aot = options?.aot;
349
- const slot = options?.slot;
350
- if (!aot || !slot || !Capture.isCapturing()) return;
351
- if (this.hasCodec && !hasRef && options.coerces && options.normalize !== false && options.normalize !== "typebox") {
352
- const plan = captureCoercePlan(originalSchema, this.schema);
353
- if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(this.schema)) Capture.set({
354
- method: aot.method,
355
- path: aot.path,
356
- slot
357
- }, { coercePlan: plan });
358
- }
359
- const defaultFastPathCapture = {
360
- precomputeSafe: void 0,
361
- precomputedDefault: void 0,
362
- precomputeNull: void 0,
363
- precomputedObjectDefault: void 0,
364
- defaultCloner: void 0,
365
- objectDefaultMerger: void 0
366
- };
367
- if (this.hasDefault) {
368
- const defaults = verifyPreallocatableDefault(this.schema);
369
- if (defaults) {
370
- defaultFastPathCapture.precomputeSafe = true;
371
- defaultFastPathCapture.precomputedDefault = defaults.pd;
372
- defaultFastPathCapture.precomputeNull = defaults.pn;
373
- defaultFastPathCapture.precomputedObjectDefault = defaults.pod;
374
- defaultFastPathCapture.defaultCloner = defaults.pd !== void 0 ? buildDefaultClonerSource(defaults.pd) : void 0;
375
- defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? buildObjectDefaultMergeSource(defaults.pod) : void 0);
376
- }
377
- }
378
- Capture.set({
379
- method: aot.method,
380
- path: aot.path,
381
- slot
382
- }, defaultFastPathCapture);
383
- const customErrors = captureCustomErrors(this.schema);
384
- if (customErrors) Capture.set({
385
- method: aot.method,
386
- path: aot.path,
387
- slot
388
- }, { customErrors });
389
- const innerCodecs = captureStringCodecEntries(this.schema, options?.sanitize);
390
- if (innerCodecs) Capture.set({
391
- method: aot.method,
392
- path: aot.path,
393
- slot
394
- }, { innerCodecs });
395
- const build = this.tb.buildResult;
396
- const cf = buildFrozenCheck(build, this.schema);
397
- if (!cf) return;
398
- Capture.set({
399
- method: aot.method,
400
- path: aot.path,
401
- slot
402
- }, {
403
- ...cf,
404
- async: build.external.variables.some(isAsyncPredicate),
405
- hasDefault: this.hasDefault,
406
- hasCodec: this.hasCodec,
407
- hasRef
408
- });
409
- }
410
274
  #dropCompiledSource() {
411
275
  const tb = this.tb;
412
276
  if (!tb) return;
@@ -567,4 +431,4 @@ var TypeBoxValidator = class extends Validator$1 {
567
431
  };
568
432
 
569
433
  //#endregion
570
- export { TypeBoxValidator, TypeBoxValidatorCache, shallowMergeObjects };
434
+ export { TypeBoxValidator, TypeBoxValidatorCache, externalsShape, isAsyncPredicate, shallowMergeObjects };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elysia",
3
3
  "description": "Ergonomic Framework for Human",
4
- "version": "2.0.0-exp.34",
4
+ "version": "2.0.0-exp.35",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",