zod-compiler 1.23.0 → 1.23.2
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/README.md +9 -6
- package/dist/cli/commands/check.d.ts +10 -7
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +125 -148
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +22 -19
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +102 -133
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/watch.d.ts +17 -15
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +126 -154
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/emitter.d.ts +19 -16
- package/dist/cli/emitter.d.ts.map +1 -1
- package/dist/cli/emitter.js +55 -71
- package/dist/cli/emitter.js.map +1 -1
- package/dist/cli/errors.d.ts +4 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +6 -2
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/index.d.ts +1 -3
- package/dist/cli/index.js +147 -160
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/logger.d.ts +18 -15
- package/dist/cli/logger.d.ts.map +1 -1
- package/dist/cli/logger.js +38 -37
- package/dist/cli/logger.js.map +1 -1
- package/dist/core/codegen/build-path.d.ts +7 -41
- package/dist/core/codegen/build-path.d.ts.map +1 -1
- package/dist/core/codegen/build-path.js +481 -570
- package/dist/core/codegen/build-path.js.map +1 -1
- package/dist/core/codegen/context.d.ts +256 -253
- package/dist/core/codegen/context.d.ts.map +1 -1
- package/dist/core/codegen/context.js +363 -437
- package/dist/core/codegen/context.js.map +1 -1
- package/dist/core/codegen/dedupe.d.ts +22 -56
- package/dist/core/codegen/dedupe.d.ts.map +1 -1
- package/dist/core/codegen/dedupe.js +150 -242
- package/dist/core/codegen/dedupe.js.map +1 -1
- package/dist/core/codegen/emit-issue.d.ts +44 -68
- package/dist/core/codegen/emit-issue.d.ts.map +1 -1
- package/dist/core/codegen/emit-issue.js +76 -108
- package/dist/core/codegen/emit-issue.js.map +1 -1
- package/dist/core/codegen/emit.d.ts +4 -1
- package/dist/core/codegen/emit.d.ts.map +1 -1
- package/dist/core/codegen/emit.js +16 -13
- package/dist/core/codegen/emit.js.map +1 -1
- package/dist/core/codegen/fast-path.d.ts +7 -12
- package/dist/core/codegen/fast-path.d.ts.map +1 -1
- package/dist/core/codegen/fast-path.js +116 -145
- package/dist/core/codegen/fast-path.js.map +1 -1
- package/dist/core/codegen/fast-size.d.ts +12 -26
- package/dist/core/codegen/fast-size.d.ts.map +1 -1
- package/dist/core/codegen/fast-size.js +169 -244
- package/dist/core/codegen/fast-size.js.map +1 -1
- package/dist/core/codegen/index.d.ts +25 -23
- package/dist/core/codegen/index.d.ts.map +1 -1
- package/dist/core/codegen/index.js +239 -405
- package/dist/core/codegen/index.js.map +1 -1
- package/dist/core/codegen/issue-decls.d.ts +15 -12
- package/dist/core/codegen/issue-decls.d.ts.map +1 -1
- package/dist/core/codegen/issue-decls.js +131 -162
- package/dist/core/codegen/issue-decls.js.map +1 -1
- package/dist/core/codegen/regex-unroll.d.ts +4 -1
- package/dist/core/codegen/regex-unroll.d.ts.map +1 -1
- package/dist/core/codegen/regex-unroll.js +173 -197
- package/dist/core/codegen/regex-unroll.js.map +1 -1
- package/dist/core/codegen/schemas/any.d.ts +7 -4
- package/dist/core/codegen/schemas/any.d.ts.map +1 -1
- package/dist/core/codegen/schemas/any.js +8 -4
- package/dist/core/codegen/schemas/any.js.map +1 -1
- package/dist/core/codegen/schemas/array.d.ts +8 -5
- package/dist/core/codegen/schemas/array.d.ts.map +1 -1
- package/dist/core/codegen/schemas/array.js +77 -95
- package/dist/core/codegen/schemas/array.js.map +1 -1
- package/dist/core/codegen/schemas/bigint.d.ts +7 -4
- package/dist/core/codegen/schemas/bigint.d.ts.map +1 -1
- package/dist/core/codegen/schemas/bigint.js +44 -56
- package/dist/core/codegen/schemas/bigint.js.map +1 -1
- package/dist/core/codegen/schemas/boolean.d.ts +7 -4
- package/dist/core/codegen/schemas/boolean.d.ts.map +1 -1
- package/dist/core/codegen/schemas/boolean.js +12 -11
- package/dist/core/codegen/schemas/boolean.js.map +1 -1
- package/dist/core/codegen/schemas/catch.d.ts +8 -5
- package/dist/core/codegen/schemas/catch.d.ts.map +1 -1
- package/dist/core/codegen/schemas/catch.js +23 -23
- package/dist/core/codegen/schemas/catch.js.map +1 -1
- package/dist/core/codegen/schemas/date.d.ts +7 -4
- package/dist/core/codegen/schemas/date.d.ts.map +1 -1
- package/dist/core/codegen/schemas/date.js +49 -68
- package/dist/core/codegen/schemas/date.js.map +1 -1
- package/dist/core/codegen/schemas/default.d.ts +9 -6
- package/dist/core/codegen/schemas/default.d.ts.map +1 -1
- package/dist/core/codegen/schemas/default.js +29 -27
- package/dist/core/codegen/schemas/default.js.map +1 -1
- package/dist/core/codegen/schemas/discriminated-union.d.ts +12 -10
- package/dist/core/codegen/schemas/discriminated-union.d.ts.map +1 -1
- package/dist/core/codegen/schemas/discriminated-union.js +153 -178
- package/dist/core/codegen/schemas/discriminated-union.js.map +1 -1
- package/dist/core/codegen/schemas/effect.d.ts +9 -6
- package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
- package/dist/core/codegen/schemas/effect.js +54 -67
- package/dist/core/codegen/schemas/effect.js.map +1 -1
- package/dist/core/codegen/schemas/enum.d.ts +7 -4
- package/dist/core/codegen/schemas/enum.d.ts.map +1 -1
- package/dist/core/codegen/schemas/enum.js +15 -21
- package/dist/core/codegen/schemas/enum.js.map +1 -1
- package/dist/core/codegen/schemas/fallback.d.ts +6 -3
- package/dist/core/codegen/schemas/fallback.d.ts.map +1 -1
- package/dist/core/codegen/schemas/fallback.js +14 -13
- package/dist/core/codegen/schemas/fallback.js.map +1 -1
- package/dist/core/codegen/schemas/file.d.ts +7 -4
- package/dist/core/codegen/schemas/file.d.ts.map +1 -1
- package/dist/core/codegen/schemas/file.js +51 -57
- package/dist/core/codegen/schemas/file.js.map +1 -1
- package/dist/core/codegen/schemas/intersection.d.ts +8 -5
- package/dist/core/codegen/schemas/intersection.d.ts.map +1 -1
- package/dist/core/codegen/schemas/intersection.js +16 -13
- package/dist/core/codegen/schemas/intersection.js.map +1 -1
- package/dist/core/codegen/schemas/literal.d.ts +7 -4
- package/dist/core/codegen/schemas/literal.d.ts.map +1 -1
- package/dist/core/codegen/schemas/literal.js +20 -23
- package/dist/core/codegen/schemas/literal.js.map +1 -1
- package/dist/core/codegen/schemas/map.d.ts +8 -5
- package/dist/core/codegen/schemas/map.d.ts.map +1 -1
- package/dist/core/codegen/schemas/map.js +61 -67
- package/dist/core/codegen/schemas/map.js.map +1 -1
- package/dist/core/codegen/schemas/nan.d.ts +7 -4
- package/dist/core/codegen/schemas/nan.d.ts.map +1 -1
- package/dist/core/codegen/schemas/nan.js +8 -4
- package/dist/core/codegen/schemas/nan.js.map +1 -1
- package/dist/core/codegen/schemas/never.d.ts +7 -4
- package/dist/core/codegen/schemas/never.d.ts.map +1 -1
- package/dist/core/codegen/schemas/never.js +8 -4
- package/dist/core/codegen/schemas/never.js.map +1 -1
- package/dist/core/codegen/schemas/null.d.ts +7 -4
- package/dist/core/codegen/schemas/null.d.ts.map +1 -1
- package/dist/core/codegen/schemas/null.js +8 -4
- package/dist/core/codegen/schemas/null.js.map +1 -1
- package/dist/core/codegen/schemas/nullable.d.ts +8 -5
- package/dist/core/codegen/schemas/nullable.d.ts.map +1 -1
- package/dist/core/codegen/schemas/nullable.js +8 -5
- package/dist/core/codegen/schemas/nullable.js.map +1 -1
- package/dist/core/codegen/schemas/number.d.ts +7 -4
- package/dist/core/codegen/schemas/number.d.ts.map +1 -1
- package/dist/core/codegen/schemas/number.js +120 -176
- package/dist/core/codegen/schemas/number.js.map +1 -1
- package/dist/core/codegen/schemas/object.d.ts +8 -5
- package/dist/core/codegen/schemas/object.d.ts.map +1 -1
- package/dist/core/codegen/schemas/object.js +144 -231
- package/dist/core/codegen/schemas/object.js.map +1 -1
- package/dist/core/codegen/schemas/optional.d.ts +9 -6
- package/dist/core/codegen/schemas/optional.d.ts.map +1 -1
- package/dist/core/codegen/schemas/optional.js +23 -31
- package/dist/core/codegen/schemas/optional.js.map +1 -1
- package/dist/core/codegen/schemas/pipe.d.ts +8 -5
- package/dist/core/codegen/schemas/pipe.d.ts.map +1 -1
- package/dist/core/codegen/schemas/pipe.js +20 -27
- package/dist/core/codegen/schemas/pipe.js.map +1 -1
- package/dist/core/codegen/schemas/readonly.d.ts +8 -5
- package/dist/core/codegen/schemas/readonly.d.ts.map +1 -1
- package/dist/core/codegen/schemas/readonly.js +8 -5
- package/dist/core/codegen/schemas/readonly.js.map +1 -1
- package/dist/core/codegen/schemas/record.d.ts +8 -5
- package/dist/core/codegen/schemas/record.d.ts.map +1 -1
- package/dist/core/codegen/schemas/record.js +52 -65
- package/dist/core/codegen/schemas/record.js.map +1 -1
- package/dist/core/codegen/schemas/recursive-ref.d.ts +9 -6
- package/dist/core/codegen/schemas/recursive-ref.d.ts.map +1 -1
- package/dist/core/codegen/schemas/recursive-ref.js +44 -44
- package/dist/core/codegen/schemas/recursive-ref.js.map +1 -1
- package/dist/core/codegen/schemas/set.d.ts +8 -5
- package/dist/core/codegen/schemas/set.d.ts.map +1 -1
- package/dist/core/codegen/schemas/set.js +61 -73
- package/dist/core/codegen/schemas/set.js.map +1 -1
- package/dist/core/codegen/schemas/string-bool.d.ts +6 -3
- package/dist/core/codegen/schemas/string-bool.d.ts.map +1 -1
- package/dist/core/codegen/schemas/string-bool.js +22 -23
- package/dist/core/codegen/schemas/string-bool.js.map +1 -1
- package/dist/core/codegen/schemas/string.d.ts +8 -5
- package/dist/core/codegen/schemas/string.d.ts.map +1 -1
- package/dist/core/codegen/schemas/string.js +168 -207
- package/dist/core/codegen/schemas/string.js.map +1 -1
- package/dist/core/codegen/schemas/symbol.d.ts +7 -4
- package/dist/core/codegen/schemas/symbol.d.ts.map +1 -1
- package/dist/core/codegen/schemas/symbol.js +8 -4
- package/dist/core/codegen/schemas/symbol.js.map +1 -1
- package/dist/core/codegen/schemas/template-literal.d.ts +7 -4
- package/dist/core/codegen/schemas/template-literal.d.ts.map +1 -1
- package/dist/core/codegen/schemas/template-literal.js +12 -13
- package/dist/core/codegen/schemas/template-literal.js.map +1 -1
- package/dist/core/codegen/schemas/tuple.d.ts +8 -5
- package/dist/core/codegen/schemas/tuple.d.ts.map +1 -1
- package/dist/core/codegen/schemas/tuple.js +84 -94
- package/dist/core/codegen/schemas/tuple.js.map +1 -1
- package/dist/core/codegen/schemas/undefined.d.ts +7 -4
- package/dist/core/codegen/schemas/undefined.d.ts.map +1 -1
- package/dist/core/codegen/schemas/undefined.js +8 -4
- package/dist/core/codegen/schemas/undefined.js.map +1 -1
- package/dist/core/codegen/schemas/union.d.ts +8 -5
- package/dist/core/codegen/schemas/union.d.ts.map +1 -1
- package/dist/core/codegen/schemas/union.js +49 -69
- package/dist/core/codegen/schemas/union.js.map +1 -1
- package/dist/core/codegen/schemas/unknown.d.ts +7 -4
- package/dist/core/codegen/schemas/unknown.d.ts.map +1 -1
- package/dist/core/codegen/schemas/unknown.js +8 -4
- package/dist/core/codegen/schemas/unknown.js.map +1 -1
- package/dist/core/codegen/schemas/void.d.ts +7 -4
- package/dist/core/codegen/schemas/void.d.ts.map +1 -1
- package/dist/core/codegen/schemas/void.js +8 -4
- package/dist/core/codegen/schemas/void.js.map +1 -1
- package/dist/core/codegen/slow-path.d.ts +7 -4
- package/dist/core/codegen/slow-path.d.ts.map +1 -1
- package/dist/core/codegen/slow-path.js +71 -96
- package/dist/core/codegen/slow-path.js.map +1 -1
- package/dist/core/codegen/well-known-regex.d.ts +22 -19
- package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
- package/dist/core/codegen/well-known-regex.js +127 -96
- package/dist/core/codegen/well-known-regex.js.map +1 -1
- package/dist/core/compile.d.ts +7 -4
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +48 -48
- package/dist/core/compile.js.map +1 -1
- package/dist/core/diagnostic.d.ts +38 -39
- package/dist/core/diagnostic.d.ts.map +1 -1
- package/dist/core/diagnostic.js +140 -164
- package/dist/core/diagnostic.js.map +1 -1
- package/dist/core/extract/checks.d.ts +18 -15
- package/dist/core/extract/checks.d.ts.map +1 -1
- package/dist/core/extract/checks.js +318 -311
- package/dist/core/extract/checks.js.map +1 -1
- package/dist/core/extract/effects.d.ts +13 -10
- package/dist/core/extract/effects.d.ts.map +1 -1
- package/dist/core/extract/effects.js +153 -222
- package/dist/core/extract/effects.js.map +1 -1
- package/dist/core/extract/extractors/any.d.ts +5 -2
- package/dist/core/extract/extractors/any.d.ts.map +1 -1
- package/dist/core/extract/extractors/any.js +5 -1
- package/dist/core/extract/extractors/any.js.map +1 -1
- package/dist/core/extract/extractors/array.d.ts +6 -3
- package/dist/core/extract/extractors/array.d.ts.map +1 -1
- package/dist/core/extract/extractors/array.js +25 -20
- package/dist/core/extract/extractors/array.js.map +1 -1
- package/dist/core/extract/extractors/bigint.d.ts +6 -3
- package/dist/core/extract/extractors/bigint.d.ts.map +1 -1
- package/dist/core/extract/extractors/bigint.js +66 -64
- package/dist/core/extract/extractors/bigint.js.map +1 -1
- package/dist/core/extract/extractors/boolean.d.ts +5 -2
- package/dist/core/extract/extractors/boolean.d.ts.map +1 -1
- package/dist/core/extract/extractors/boolean.js +7 -3
- package/dist/core/extract/extractors/boolean.js.map +1 -1
- package/dist/core/extract/extractors/catch.d.ts +6 -3
- package/dist/core/extract/extractors/catch.d.ts.map +1 -1
- package/dist/core/extract/extractors/catch.js +26 -17
- package/dist/core/extract/extractors/catch.js.map +1 -1
- package/dist/core/extract/extractors/date.d.ts +6 -3
- package/dist/core/extract/extractors/date.d.ts.map +1 -1
- package/dist/core/extract/extractors/date.js +42 -46
- package/dist/core/extract/extractors/date.js.map +1 -1
- package/dist/core/extract/extractors/default.d.ts +6 -3
- package/dist/core/extract/extractors/default.d.ts.map +1 -1
- package/dist/core/extract/extractors/default.js +20 -14
- package/dist/core/extract/extractors/default.js.map +1 -1
- package/dist/core/extract/extractors/enum.d.ts +5 -2
- package/dist/core/extract/extractors/enum.d.ts.map +1 -1
- package/dist/core/extract/extractors/enum.js +12 -13
- package/dist/core/extract/extractors/enum.js.map +1 -1
- package/dist/core/extract/extractors/file.d.ts +6 -3
- package/dist/core/extract/extractors/file.d.ts.map +1 -1
- package/dist/core/extract/extractors/file.js +34 -28
- package/dist/core/extract/extractors/file.js.map +1 -1
- package/dist/core/extract/extractors/intersection.d.ts +5 -2
- package/dist/core/extract/extractors/intersection.d.ts.map +1 -1
- package/dist/core/extract/extractors/intersection.js +13 -11
- package/dist/core/extract/extractors/intersection.js.map +1 -1
- package/dist/core/extract/extractors/lazy.d.ts +6 -3
- package/dist/core/extract/extractors/lazy.d.ts.map +1 -1
- package/dist/core/extract/extractors/lazy.js +21 -30
- package/dist/core/extract/extractors/lazy.js.map +1 -1
- package/dist/core/extract/extractors/literal.d.ts +5 -2
- package/dist/core/extract/extractors/literal.d.ts.map +1 -1
- package/dist/core/extract/extractors/literal.js +8 -1
- package/dist/core/extract/extractors/literal.js.map +1 -1
- package/dist/core/extract/extractors/map.d.ts +6 -3
- package/dist/core/extract/extractors/map.d.ts.map +1 -1
- package/dist/core/extract/extractors/map.js +10 -4
- package/dist/core/extract/extractors/map.js.map +1 -1
- package/dist/core/extract/extractors/nan.d.ts +5 -2
- package/dist/core/extract/extractors/nan.d.ts.map +1 -1
- package/dist/core/extract/extractors/nan.js +5 -1
- package/dist/core/extract/extractors/nan.js.map +1 -1
- package/dist/core/extract/extractors/never.d.ts +5 -2
- package/dist/core/extract/extractors/never.d.ts.map +1 -1
- package/dist/core/extract/extractors/never.js +5 -1
- package/dist/core/extract/extractors/never.js.map +1 -1
- package/dist/core/extract/extractors/null.d.ts +5 -2
- package/dist/core/extract/extractors/null.d.ts.map +1 -1
- package/dist/core/extract/extractors/null.js +5 -1
- package/dist/core/extract/extractors/null.js.map +1 -1
- package/dist/core/extract/extractors/nullable.d.ts +5 -2
- package/dist/core/extract/extractors/nullable.d.ts.map +1 -1
- package/dist/core/extract/extractors/nullable.js +7 -3
- package/dist/core/extract/extractors/nullable.js.map +1 -1
- package/dist/core/extract/extractors/number.d.ts +6 -3
- package/dist/core/extract/extractors/number.d.ts.map +1 -1
- package/dist/core/extract/extractors/number.js +35 -35
- package/dist/core/extract/extractors/number.js.map +1 -1
- package/dist/core/extract/extractors/object.d.ts +6 -3
- package/dist/core/extract/extractors/object.d.ts.map +1 -1
- package/dist/core/extract/extractors/object.js +49 -76
- package/dist/core/extract/extractors/object.js.map +1 -1
- package/dist/core/extract/extractors/optional.d.ts +5 -2
- package/dist/core/extract/extractors/optional.d.ts.map +1 -1
- package/dist/core/extract/extractors/optional.js +10 -12
- package/dist/core/extract/extractors/optional.js.map +1 -1
- package/dist/core/extract/extractors/pipe.d.ts +6 -3
- package/dist/core/extract/extractors/pipe.d.ts.map +1 -1
- package/dist/core/extract/extractors/pipe.js +40 -41
- package/dist/core/extract/extractors/pipe.js.map +1 -1
- package/dist/core/extract/extractors/readonly.d.ts +5 -2
- package/dist/core/extract/extractors/readonly.d.ts.map +1 -1
- package/dist/core/extract/extractors/readonly.js +10 -6
- package/dist/core/extract/extractors/readonly.js.map +1 -1
- package/dist/core/extract/extractors/record.d.ts +6 -3
- package/dist/core/extract/extractors/record.d.ts.map +1 -1
- package/dist/core/extract/extractors/record.js +24 -35
- package/dist/core/extract/extractors/record.js.map +1 -1
- package/dist/core/extract/extractors/set.d.ts +6 -3
- package/dist/core/extract/extractors/set.d.ts.map +1 -1
- package/dist/core/extract/extractors/set.js +36 -30
- package/dist/core/extract/extractors/set.js.map +1 -1
- package/dist/core/extract/extractors/string-bool.d.ts +7 -4
- package/dist/core/extract/extractors/string-bool.d.ts.map +1 -1
- package/dist/core/extract/extractors/string-bool.js +66 -84
- package/dist/core/extract/extractors/string-bool.js.map +1 -1
- package/dist/core/extract/extractors/string.d.ts +6 -3
- package/dist/core/extract/extractors/string.d.ts.map +1 -1
- package/dist/core/extract/extractors/string.js +34 -37
- package/dist/core/extract/extractors/string.js.map +1 -1
- package/dist/core/extract/extractors/symbol.d.ts +5 -2
- package/dist/core/extract/extractors/symbol.d.ts.map +1 -1
- package/dist/core/extract/extractors/symbol.js +5 -1
- package/dist/core/extract/extractors/symbol.js.map +1 -1
- package/dist/core/extract/extractors/template-literal.d.ts +6 -3
- package/dist/core/extract/extractors/template-literal.d.ts.map +1 -1
- package/dist/core/extract/extractors/template-literal.js +11 -6
- package/dist/core/extract/extractors/template-literal.js.map +1 -1
- package/dist/core/extract/extractors/tuple.d.ts +6 -3
- package/dist/core/extract/extractors/tuple.d.ts.map +1 -1
- package/dist/core/extract/extractors/tuple.js +10 -4
- package/dist/core/extract/extractors/tuple.js.map +1 -1
- package/dist/core/extract/extractors/undefined.d.ts +5 -2
- package/dist/core/extract/extractors/undefined.d.ts.map +1 -1
- package/dist/core/extract/extractors/undefined.js +5 -1
- package/dist/core/extract/extractors/undefined.js.map +1 -1
- package/dist/core/extract/extractors/union.d.ts +6 -3
- package/dist/core/extract/extractors/union.d.ts.map +1 -1
- package/dist/core/extract/extractors/union.js +38 -64
- package/dist/core/extract/extractors/union.js.map +1 -1
- package/dist/core/extract/extractors/unknown.d.ts +5 -2
- package/dist/core/extract/extractors/unknown.d.ts.map +1 -1
- package/dist/core/extract/extractors/unknown.js +5 -1
- package/dist/core/extract/extractors/unknown.js.map +1 -1
- package/dist/core/extract/extractors/void.d.ts +5 -2
- package/dist/core/extract/extractors/void.d.ts.map +1 -1
- package/dist/core/extract/extractors/void.js +5 -1
- package/dist/core/extract/extractors/void.js.map +1 -1
- package/dist/core/extract/fallback.d.ts +6 -3
- package/dist/core/extract/fallback.d.ts.map +1 -1
- package/dist/core/extract/fallback.js +21 -7
- package/dist/core/extract/fallback.js.map +1 -1
- package/dist/core/extract/index.d.ts +6 -4
- package/dist/core/extract/index.d.ts.map +1 -1
- package/dist/core/extract/index.js +15 -15
- package/dist/core/extract/index.js.map +1 -1
- package/dist/core/extract/registry.d.ts +39 -36
- package/dist/core/extract/registry.d.ts.map +1 -1
- package/dist/core/extract/registry.js +96 -123
- package/dist/core/extract/registry.js.map +1 -1
- package/dist/core/extract/types.d.ts +124 -120
- package/dist/core/extract/types.d.ts.map +1 -1
- package/dist/core/extract/types.js +0 -1
- package/dist/core/iife.d.ts +14 -15
- package/dist/core/iife.d.ts.map +1 -1
- package/dist/core/iife.js +182 -206
- package/dist/core/iife.js.map +1 -1
- package/dist/core/pipeline.d.ts +33 -30
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +67 -74
- package/dist/core/pipeline.js.map +1 -1
- package/dist/core/types.d.ts +430 -427
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -5
- package/dist/discovery.d.ts +8 -5
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +31 -32
- package/dist/discovery.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/jit.d.ts +15 -42
- package/dist/jit.d.ts.map +1 -1
- package/dist/jit.js +187 -216
- package/dist/jit.js.map +1 -1
- package/dist/loader.d.ts +14 -11
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +226 -258
- package/dist/loader.js.map +1 -1
- package/dist/static-filter.d.ts +4 -1
- package/dist/static-filter.d.ts.map +1 -1
- package/dist/static-filter.js +240 -367
- package/dist/static-filter.js.map +1 -1
- package/dist/swc.d.ts +38 -35
- package/dist/swc.d.ts.map +1 -1
- package/dist/swc.js +83 -76
- package/dist/swc.js.map +1 -1
- package/dist/unplugin/bun.d.ts +5 -2
- package/dist/unplugin/bun.d.ts.map +1 -1
- package/dist/unplugin/bun.js +5 -1
- package/dist/unplugin/bun.js.map +1 -1
- package/dist/unplugin/dep-graph.d.ts +10 -7
- package/dist/unplugin/dep-graph.d.ts.map +1 -1
- package/dist/unplugin/dep-graph.js +216 -252
- package/dist/unplugin/dep-graph.js.map +1 -1
- package/dist/unplugin/disk-cache.d.ts +121 -92
- package/dist/unplugin/disk-cache.d.ts.map +1 -1
- package/dist/unplugin/disk-cache.js +425 -444
- package/dist/unplugin/disk-cache.js.map +1 -1
- package/dist/unplugin/edits.d.ts +15 -12
- package/dist/unplugin/edits.d.ts.map +1 -1
- package/dist/unplugin/edits.js +24 -37
- package/dist/unplugin/edits.js.map +1 -1
- package/dist/unplugin/esbuild.d.ts +5 -2
- package/dist/unplugin/esbuild.d.ts.map +1 -1
- package/dist/unplugin/esbuild.js +5 -1
- package/dist/unplugin/esbuild.js.map +1 -1
- package/dist/unplugin/farm.d.ts +5 -2
- package/dist/unplugin/farm.d.ts.map +1 -1
- package/dist/unplugin/farm.js +5 -1
- package/dist/unplugin/farm.js.map +1 -1
- package/dist/unplugin/hoist-compile.d.ts +14 -42
- package/dist/unplugin/hoist-compile.d.ts.map +1 -1
- package/dist/unplugin/hoist-compile.js +67 -112
- package/dist/unplugin/hoist-compile.js.map +1 -1
- package/dist/unplugin/hoist.d.ts +56 -54
- package/dist/unplugin/hoist.d.ts.map +1 -1
- package/dist/unplugin/hoist.js +945 -1170
- package/dist/unplugin/hoist.js.map +1 -1
- package/dist/unplugin/index.d.ts +5 -3
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +175 -250
- package/dist/unplugin/index.js.map +1 -1
- package/dist/unplugin/rolldown.d.ts +5 -2
- package/dist/unplugin/rolldown.d.ts.map +1 -1
- package/dist/unplugin/rolldown.js +5 -1
- package/dist/unplugin/rolldown.js.map +1 -1
- package/dist/unplugin/rollup.d.ts +5 -2
- package/dist/unplugin/rollup.d.ts.map +1 -1
- package/dist/unplugin/rollup.js +5 -1
- package/dist/unplugin/rollup.js.map +1 -1
- package/dist/unplugin/rsbuild.d.ts +6 -3
- package/dist/unplugin/rsbuild.d.ts.map +1 -1
- package/dist/unplugin/rsbuild.js +15 -11
- package/dist/unplugin/rsbuild.js.map +1 -1
- package/dist/unplugin/rspack.d.ts +5 -2
- package/dist/unplugin/rspack.d.ts.map +1 -1
- package/dist/unplugin/rspack.js +5 -1
- package/dist/unplugin/rspack.js.map +1 -1
- package/dist/unplugin/transform.d.ts +30 -27
- package/dist/unplugin/transform.d.ts.map +1 -1
- package/dist/unplugin/transform.js +433 -620
- package/dist/unplugin/transform.js.map +1 -1
- package/dist/unplugin/types.d.ts +189 -184
- package/dist/unplugin/types.d.ts.map +1 -1
- package/dist/unplugin/types.js +22 -18
- package/dist/unplugin/types.js.map +1 -1
- package/dist/unplugin/virtual.d.ts +11 -8
- package/dist/unplugin/virtual.d.ts.map +1 -1
- package/dist/unplugin/virtual.js +65 -83
- package/dist/unplugin/virtual.js.map +1 -1
- package/dist/unplugin/vite.d.ts +5 -2
- package/dist/unplugin/vite.d.ts.map +1 -1
- package/dist/unplugin/vite.js +5 -1
- package/dist/unplugin/vite.js.map +1 -1
- package/dist/unplugin/webpack.d.ts +5 -2
- package/dist/unplugin/webpack.d.ts.map +1 -1
- package/dist/unplugin/webpack.js +5 -1
- package/dist/unplugin/webpack.js.map +1 -1
- package/package.json +23 -14
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/core/extract/types.js.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/jit.js
CHANGED
|
@@ -1,245 +1,216 @@
|
|
|
1
|
-
|
|
2
|
-
* Runtime compilation — the same extract → codegen pipeline the build plugin
|
|
3
|
-
* runs, executed in-process and evaluated through `new Function`.
|
|
4
|
-
*
|
|
5
|
-
* The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
|
|
6
|
-
* code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
|
|
7
|
-
* suite, a serverless handler bundled by someone else's toolchain, a library
|
|
8
|
-
* that ships schemas to consumers. There `compile()` is a no-op and every parse
|
|
9
|
-
* runs plain Zod. `jit()` closes that gap — one call, no build integration,
|
|
10
|
-
* measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
|
|
11
|
-
*
|
|
12
|
-
* Nothing here re-implements validation: {@link compileSchemas} and
|
|
13
|
-
* {@link generateIIFE} are the exact modules the plugin and CLI use, so the
|
|
14
|
-
* generated validator, its Zod parity and its performance are identical to what
|
|
15
|
-
* a build would have emitted. The only difference is *when* the code is
|
|
16
|
-
* produced.
|
|
17
|
-
*
|
|
18
|
-
* Compilation is LAZY by default: `jit()` installs accessors that compile on
|
|
19
|
-
* the first read of a parse method and replace themselves with the compiled
|
|
20
|
-
* ones. Importing a module of 500 schemas therefore costs nothing, and a
|
|
21
|
-
* serverless invocation touching three of them pays for three.
|
|
22
|
-
*
|
|
23
|
-
* Runtime code generation is not always permitted — a strict CSP without
|
|
24
|
-
* `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
|
|
25
|
-
* fast-pass is itself a `new Function`) and already exposes the two switches
|
|
26
|
-
* for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
|
|
27
|
-
* `jit()` honours both and degrades to plain Zod, so one setting governs both
|
|
28
|
-
* compilers. Those targets are where the build plugin belongs anyway — it emits
|
|
29
|
-
* the same validator with no runtime evaluation at all.
|
|
30
|
-
*/
|
|
31
|
-
import { config as zodConfig, core as zodCore, ZodRealError } from "zod";
|
|
32
|
-
import { FAIL_CLASS_DECL, FAILZ_CLASS_DECL, FIN_DECL, FIN_DEFERRED_DECL, FINZ_DECL, generateIIFE, MK_VALIDATOR_DECL, ZOD_MSG_DECLARATION, } from "./core/iife.js";
|
|
1
|
+
import { FAILZ_CLASS_DECL, FAIL_CLASS_DECL, FINZ_DECL, FIN_DECL, FIN_DEFERRED_DECL, MK_VALIDATOR_DECL, ZOD_MSG_DECLARATION, generateIIFE } from "./core/iife.js";
|
|
33
2
|
import { compileSchemas } from "./core/pipeline.js";
|
|
3
|
+
import { ZodRealError, config, core } from "zod";
|
|
4
|
+
//#region src/jit.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime compilation — the same extract → codegen pipeline the build plugin
|
|
7
|
+
* runs, executed in-process and evaluated through `new Function`.
|
|
8
|
+
*
|
|
9
|
+
* The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
|
|
10
|
+
* code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
|
|
11
|
+
* suite, a serverless handler bundled by someone else's toolchain, a library
|
|
12
|
+
* that ships schemas to consumers. There `compile()` is a no-op and every parse
|
|
13
|
+
* runs plain Zod. `jit()` closes that gap — one call, no build integration,
|
|
14
|
+
* measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
|
|
15
|
+
*
|
|
16
|
+
* Nothing here re-implements validation: {@link compileSchemas} and
|
|
17
|
+
* {@link generateIIFE} are the exact modules the plugin and CLI use, so the
|
|
18
|
+
* generated validator, its Zod parity and its performance are identical to what
|
|
19
|
+
* a build would have emitted. The only difference is *when* the code is
|
|
20
|
+
* produced.
|
|
21
|
+
*
|
|
22
|
+
* Compilation is LAZY by default: `jit()` installs accessors that compile on
|
|
23
|
+
* the first read of a parse method and replace themselves with the compiled
|
|
24
|
+
* ones. Importing a module of 500 schemas therefore costs nothing, and a
|
|
25
|
+
* serverless invocation touching three of them pays for three.
|
|
26
|
+
*
|
|
27
|
+
* Runtime code generation is not always permitted — a strict CSP without
|
|
28
|
+
* `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
|
|
29
|
+
* fast-pass is itself a `new Function`) and already exposes the two switches
|
|
30
|
+
* for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
|
|
31
|
+
* `jit()` honours both and degrades to plain Zod, so one setting governs both
|
|
32
|
+
* compilers. Those targets are where the build plugin belongs anyway — it emits
|
|
33
|
+
* the same validator with no runtime evaluation at all.
|
|
34
|
+
*/
|
|
34
35
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
* The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the
|
|
37
|
+
* import itself — `zod`'s three bindings arrive as parameters instead, so the
|
|
38
|
+
* evaluated code has no module scope to resolve. Byte-for-byte the same helper
|
|
39
|
+
* source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and
|
|
40
|
+
* an AOT one share their entire runtime layer.
|
|
41
|
+
*/
|
|
41
42
|
const RUNTIME_PRELUDE = [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
ZOD_MSG_DECLARATION,
|
|
44
|
+
FAIL_CLASS_DECL,
|
|
45
|
+
MK_VALIDATOR_DECL,
|
|
46
|
+
FIN_DECL,
|
|
47
|
+
FIN_DEFERRED_DECL,
|
|
48
|
+
FAILZ_CLASS_DECL,
|
|
49
|
+
FINZ_DECL
|
|
49
50
|
].join("\n");
|
|
50
51
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const SLOTS = [
|
|
52
|
+
* Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor
|
|
53
|
+
* until the schema materializes.
|
|
54
|
+
*
|
|
55
|
+
* `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not
|
|
56
|
+
* over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,
|
|
57
|
+
* Hono, TanStack Form) that never touches `safeParse` would otherwise keep
|
|
58
|
+
* running plain Zod forever behind a "compiled" schema.
|
|
59
|
+
*/
|
|
60
|
+
const SLOTS = [
|
|
61
|
+
"parse",
|
|
62
|
+
"safeParse",
|
|
63
|
+
"parseAsync",
|
|
64
|
+
"safeParseAsync",
|
|
65
|
+
"is",
|
|
66
|
+
"~standard"
|
|
67
|
+
];
|
|
60
68
|
/** Schemas already handed to `jit()`, so a second call is a no-op rather than a recompile. */
|
|
61
|
-
const seen = new WeakSet();
|
|
69
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
62
70
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
pending = false;
|
|
111
|
-
restore(target, original);
|
|
112
|
-
materialize(schema);
|
|
113
|
-
}, () => {
|
|
114
|
-
if (!pending)
|
|
115
|
-
return;
|
|
116
|
-
pending = false;
|
|
117
|
-
// Restore EVERY slot, not just the one being written. A left-behind
|
|
118
|
-
// accessor whose trigger has been cancelled would read `target[slot]`
|
|
119
|
-
// and re-enter itself — unbounded recursion. This is the path the build
|
|
120
|
-
// plugin takes when a file uses `jit()` too: `__zcMkv` assigns the parse
|
|
121
|
-
// methods (cancelling here) and then reads `~standard`.
|
|
122
|
-
restore(target, original);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
pending = false;
|
|
127
|
-
restore(target, original);
|
|
128
|
-
}
|
|
129
|
-
return schema;
|
|
71
|
+
* Compile `schema` in-process and install the compiled `parse` / `safeParse` /
|
|
72
|
+
* `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.
|
|
73
|
+
*
|
|
74
|
+
* Returns the SAME object — identity-preserving exactly as the build plugin is,
|
|
75
|
+
* so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and
|
|
76
|
+
* composition into a larger schema all keep working, and every existing
|
|
77
|
+
* reference to the schema picks the compiled methods up.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { z } from "zod";
|
|
81
|
+
* import { jit } from "zod-compiler/jit";
|
|
82
|
+
*
|
|
83
|
+
* export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));
|
|
84
|
+
* UserSchema.safeParse(input); // compiled on this first call
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the
|
|
88
|
+
* same way they do at build time; a schema that cannot be compiled at all is
|
|
89
|
+
* left as plain Zod.
|
|
90
|
+
*/
|
|
91
|
+
function jit(schema, options) {
|
|
92
|
+
const target = schema;
|
|
93
|
+
if (seen.has(target)) return schema;
|
|
94
|
+
seen.add(target);
|
|
95
|
+
if (options?.eager === true) {
|
|
96
|
+
materialize(schema);
|
|
97
|
+
return schema;
|
|
98
|
+
}
|
|
99
|
+
const original = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const slot of SLOTS) original.set(slot, Object.getOwnPropertyDescriptor(target, slot));
|
|
101
|
+
let pending = true;
|
|
102
|
+
try {
|
|
103
|
+
installAccessors(target, original, () => {
|
|
104
|
+
if (!pending) return;
|
|
105
|
+
pending = false;
|
|
106
|
+
restore(target, original);
|
|
107
|
+
materialize(schema);
|
|
108
|
+
}, () => {
|
|
109
|
+
if (!pending) return;
|
|
110
|
+
pending = false;
|
|
111
|
+
restore(target, original);
|
|
112
|
+
});
|
|
113
|
+
} catch {
|
|
114
|
+
pending = false;
|
|
115
|
+
restore(target, original);
|
|
116
|
+
}
|
|
117
|
+
return schema;
|
|
130
118
|
}
|
|
131
119
|
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
120
|
+
* Front every installed method with a compile-on-read accessor. `trigger`
|
|
121
|
+
* materializes the schema, which replaces these accessors with the compiled
|
|
122
|
+
* methods (or restores Zod's own), so the read that follows never re-enters.
|
|
123
|
+
*/
|
|
136
124
|
function installAccessors(target, original, trigger, cancel) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
cancel();
|
|
155
|
-
Object.defineProperty(target, slot, {
|
|
156
|
-
configurable: true,
|
|
157
|
-
enumerable: original.get(slot)?.enumerable ?? false,
|
|
158
|
-
value,
|
|
159
|
-
writable: true,
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
}
|
|
125
|
+
for (const slot of SLOTS) Object.defineProperty(target, slot, {
|
|
126
|
+
configurable: true,
|
|
127
|
+
enumerable: original.get(slot)?.enumerable ?? false,
|
|
128
|
+
get() {
|
|
129
|
+
trigger();
|
|
130
|
+
return target[slot];
|
|
131
|
+
},
|
|
132
|
+
set(value) {
|
|
133
|
+
cancel();
|
|
134
|
+
Object.defineProperty(target, slot, {
|
|
135
|
+
configurable: true,
|
|
136
|
+
enumerable: original.get(slot)?.enumerable ?? false,
|
|
137
|
+
value,
|
|
138
|
+
writable: true
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
164
142
|
}
|
|
165
143
|
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (isZodSchema(value))
|
|
181
|
-
jit(value, options);
|
|
182
|
-
}
|
|
144
|
+
* Compile every Zod schema found among an object's own values — typically a
|
|
145
|
+
* module namespace, so a whole schema file opts in with one call:
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* import * as schemas from "./schemas.js";
|
|
149
|
+
* jitAll(schemas);
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* The namespace object itself is never written to (a module namespace is
|
|
153
|
+
* read-only); `jit()` mutates the schema objects it holds, which is what every
|
|
154
|
+
* importer of that module already references.
|
|
155
|
+
*/
|
|
156
|
+
function jitAll(schemas, options) {
|
|
157
|
+
for (const value of Object.values(schemas)) if (isZodSchema(value)) jit(value, options);
|
|
183
158
|
}
|
|
184
159
|
/** Zod schemas carry `_zod.def`; the same probe auto-discovery uses at build time. */
|
|
185
160
|
function isZodSchema(value) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return typeof internal === "object" && internal !== null && "def" in internal;
|
|
161
|
+
if (typeof value !== "object" || value === null || !("_zod" in value)) return false;
|
|
162
|
+
const internal = value["_zod"];
|
|
163
|
+
return typeof internal === "object" && internal !== null && "def" in internal;
|
|
190
164
|
}
|
|
191
165
|
/** Put Zod's own descriptors back, dropping the compile-on-read accessors. */
|
|
192
166
|
function restore(target, original) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
Object.defineProperty(target, slot, descriptor);
|
|
199
|
-
}
|
|
167
|
+
for (const slot of SLOTS) {
|
|
168
|
+
const descriptor = original.get(slot);
|
|
169
|
+
if (descriptor === void 0) delete target[slot];
|
|
170
|
+
else Object.defineProperty(target, slot, descriptor);
|
|
171
|
+
}
|
|
200
172
|
}
|
|
201
173
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
174
|
+
* Whether runtime code generation is permitted here. Read per call, never
|
|
175
|
+
* snapshotted: `z.config({ jitless: true })` runs in an entry point, after the
|
|
176
|
+
* schema modules it imports have already been evaluated.
|
|
177
|
+
*/
|
|
206
178
|
function codegenAllowed() {
|
|
207
|
-
|
|
179
|
+
return core.globalConfig.jitless !== true && core.util.allowsEval.value;
|
|
208
180
|
}
|
|
209
181
|
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
182
|
+
* Run the pipeline and let the generated IIFE install its methods on `schema`.
|
|
183
|
+
* Swallows failure: a schema that cannot be compiled keeps Zod's own methods,
|
|
184
|
+
* which the caller already has, so there is nothing to report and nothing to
|
|
185
|
+
* break.
|
|
186
|
+
*/
|
|
215
187
|
function materialize(schema) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
// Left as plain Zod. Deliberately silent: `jit()` is an optimization, and a
|
|
223
|
-
// schema using a construct the compiler declines is a supported outcome,
|
|
224
|
-
// not an error.
|
|
225
|
-
}
|
|
188
|
+
if (!codegenAllowed()) return;
|
|
189
|
+
try {
|
|
190
|
+
buildValidator(schema);
|
|
191
|
+
} catch {}
|
|
226
192
|
}
|
|
227
193
|
/**
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
194
|
+
* Generate the validator and evaluate it, reproducing the module a
|
|
195
|
+
* `.compiled.ts` would have been: helper preamble, the file-level shared block,
|
|
196
|
+
* then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live
|
|
197
|
+
* schema object passed in as `__schema`.
|
|
198
|
+
*/
|
|
233
199
|
function buildValidator(schema) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
200
|
+
const { schemas, shared } = compileSchemas([{
|
|
201
|
+
exportName: "jit",
|
|
202
|
+
schema
|
|
203
|
+
}], { mode: "inline" });
|
|
204
|
+
const compiled = schemas[0];
|
|
205
|
+
if (compiled === void 0) throw new Error("zod-compiler: schema produced no validator");
|
|
206
|
+
const body = [
|
|
207
|
+
RUNTIME_PRELUDE,
|
|
208
|
+
shared.code,
|
|
209
|
+
`return ${generateIIFE("__schema", compiled)};`
|
|
210
|
+
].join("\n");
|
|
211
|
+
new Function("__zodCompilerConfig", "__zcCore", "__zcZodError", "__schema", body)(config, core, ZodRealError, schema);
|
|
244
212
|
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { jit, jitAll };
|
|
215
|
+
|
|
245
216
|
//# sourceMappingURL=jit.js.map
|
package/dist/jit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jit.js","sourceRoot":"","sources":["../src/jit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,IAAI,IAAI,OAAO,EAAE,YAAY,EAA6B,MAAM,KAAK,CAAC;AACpG,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,eAAe,GAAG;IACtB,mBAAmB;IACnB,eAAe;IACf,iBAAiB;IACjB,QAAQ;IACR,iBAAiB;IACjB,gBAAgB;IAChB,SAAS;CACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;GAQG;AACH,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,CAAU,CAAC;AAEjG,8FAA8F;AAC9F,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU,CAAC;AAYnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,OAAoB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AAC,CAAC,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAE1F,MAAM,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAC/F,IAAI,CACL,CAAC;IAEF,6EAA6E;IAC7E,wDAAwD;IACxD,kFAAkF;IAClF,MAAM,OAAO,GAAG,IAAI,QAAQ,CAC1B,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,UAAU,EACV,IAAI,CAMM,CAAC;IAEb,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC"}
|
|
1
|
+
{"version":3,"file":"jit.js","names":["zodCore","zodConfig"],"sources":["../src/jit.ts"],"sourcesContent":["/**\n * Runtime compilation — the same extract → codegen pipeline the build plugin\n * runs, executed in-process and evaluated through `new Function`.\n *\n * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday\n * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest\n * suite, a serverless handler bundled by someone else's toolchain, a library\n * that ships schemas to consumers. There `compile()` is a no-op and every parse\n * runs plain Zod. `jit()` closes that gap — one call, no build integration,\n * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.\n *\n * Nothing here re-implements validation: {@link compileSchemas} and\n * {@link generateIIFE} are the exact modules the plugin and CLI use, so the\n * generated validator, its Zod parity and its performance are identical to what\n * a build would have emitted. The only difference is *when* the code is\n * produced.\n *\n * Compilation is LAZY by default: `jit()` installs accessors that compile on\n * the first read of a parse method and replace themselves with the compiled\n * ones. Importing a module of 500 schemas therefore costs nothing, and a\n * serverless invocation touching three of them pays for three.\n *\n * Runtime code generation is not always permitted — a strict CSP without\n * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object\n * fast-pass is itself a `new Function`) and already exposes the two switches\n * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.\n * `jit()` honours both and degrades to plain Zod, so one setting governs both\n * compilers. Those targets are where the build plugin belongs anyway — it emits\n * the same validator with no runtime evaluation at all.\n */\n\nimport { config as zodConfig, core as zodCore, ZodRealError, type output, type ZodType } from \"zod\";\nimport {\n FAIL_CLASS_DECL,\n FAILZ_CLASS_DECL,\n FIN_DECL,\n FIN_DEFERRED_DECL,\n FINZ_DECL,\n generateIIFE,\n MK_VALIDATOR_DECL,\n ZOD_MSG_DECLARATION,\n} from \"./core/iife.js\";\nimport { compileSchemas } from \"./core/pipeline.js\";\nimport type { CompiledSchema } from \"./core/types.js\";\n\n/**\n * The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the\n * import itself — `zod`'s three bindings arrive as parameters instead, so the\n * evaluated code has no module scope to resolve. Byte-for-byte the same helper\n * source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and\n * an AOT one share their entire runtime layer.\n */\nconst RUNTIME_PRELUDE = [\n ZOD_MSG_DECLARATION,\n FAIL_CLASS_DECL,\n MK_VALIDATOR_DECL,\n FIN_DECL,\n FIN_DEFERRED_DECL,\n FAILZ_CLASS_DECL,\n FINZ_DECL,\n].join(\"\\n\");\n\n/**\n * Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor\n * until the schema materializes.\n *\n * `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not\n * over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,\n * Hono, TanStack Form) that never touches `safeParse` would otherwise keep\n * running plain Zod forever behind a \"compiled\" schema.\n */\nconst SLOTS = [\"parse\", \"safeParse\", \"parseAsync\", \"safeParseAsync\", \"is\", \"~standard\"] as const;\n\n/** Schemas already handed to `jit()`, so a second call is a no-op rather than a recompile. */\nconst seen = new WeakSet<object>();\n\nexport interface JitOptions {\n /**\n * Compile immediately instead of on first use. Costs ~0.1-0.2 ms per schema\n * at import time; useful for a long-lived server that would rather pay during\n * startup than on the first request, or to surface a compilation failure\n * eagerly. Default `false`.\n */\n eager?: boolean | undefined;\n}\n\n/**\n * Compile `schema` in-process and install the compiled `parse` / `safeParse` /\n * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.\n *\n * Returns the SAME object — identity-preserving exactly as the build plugin is,\n * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and\n * composition into a larger schema all keep working, and every existing\n * reference to the schema picks the compiled methods up.\n *\n * ```ts\n * import { z } from \"zod\";\n * import { jit } from \"zod-compiler/jit\";\n *\n * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));\n * UserSchema.safeParse(input); // compiled on this first call\n * ```\n *\n * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the\n * same way they do at build time; a schema that cannot be compiled at all is\n * left as plain Zod.\n */\nexport function jit<T extends ZodType>(\n schema: T,\n options?: JitOptions,\n): T & CompiledSchema<output<T>> {\n const target = schema as unknown as Record<string, unknown>;\n if (seen.has(target)) return schema as T & CompiledSchema<output<T>>;\n seen.add(target);\n\n if (options?.eager === true) {\n materialize(schema);\n return schema as T & CompiledSchema<output<T>>;\n }\n\n // Snapshot Zod's own descriptors first: materialize() restores them before\n // handing the object to `__zcMkv`, so the generated code sees a pristine\n // schema — it captures `~standard`'s original `validate` as its throw path,\n // and capturing a stub there would loop back into itself.\n const original = new Map<string, PropertyDescriptor | undefined>();\n for (const slot of SLOTS) {\n original.set(slot, Object.getOwnPropertyDescriptor(target, slot));\n }\n\n // Installing the accessors is the one step that can throw rather than degrade:\n // a slot locked non-configurable (a future Zod, another wrapper) makes\n // defineProperty raise, and `jit()` is called at module scope — so an\n // unhandled throw here takes down the importing app at boot. Roll back to\n // whatever Zod had and leave the schema alone instead.\n let pending = true;\n try {\n installAccessors(\n target,\n original,\n () => {\n if (!pending) return;\n pending = false;\n restore(target, original);\n materialize(schema);\n },\n () => {\n if (!pending) return;\n pending = false;\n // Restore EVERY slot, not just the one being written. A left-behind\n // accessor whose trigger has been cancelled would read `target[slot]`\n // and re-enter itself — unbounded recursion. This is the path the build\n // plugin takes when a file uses `jit()` too: `__zcMkv` assigns the parse\n // methods (cancelling here) and then reads `~standard`.\n restore(target, original);\n },\n );\n } catch {\n pending = false;\n restore(target, original);\n }\n\n return schema as T & CompiledSchema<output<T>>;\n}\n\n/**\n * Front every installed method with a compile-on-read accessor. `trigger`\n * materializes the schema, which replaces these accessors with the compiled\n * methods (or restores Zod's own), so the read that follows never re-enters.\n */\nfunction installAccessors(\n target: Record<string, unknown>,\n original: ReadonlyMap<string, PropertyDescriptor | undefined>,\n trigger: () => void,\n cancel: () => void,\n): void {\n for (const slot of SLOTS) {\n Object.defineProperty(target, slot, {\n configurable: true,\n // Preserve Zod's own visibility: parse/safeParse/... are enumerable own\n // properties, `~standard` is not. `is` does not exist on a Zod schema, so\n // it follows the non-enumerable convention `compile()` already uses.\n enumerable: original.get(slot)?.enumerable ?? false,\n get() {\n trigger();\n // Whatever now occupies the slot: the compiled method, or — if\n // compilation was impossible — Zod's own, put back by restore().\n return target[slot];\n },\n set(value: unknown) {\n // Someone overwrote a method before first use (a test double, another\n // wrapper). Their value wins, and compilation is cancelled outright —\n // materializing later would restore Zod's descriptors over it.\n cancel();\n Object.defineProperty(target, slot, {\n configurable: true,\n enumerable: original.get(slot)?.enumerable ?? false,\n value,\n writable: true,\n });\n },\n });\n }\n}\n\n/**\n * Compile every Zod schema found among an object's own values — typically a\n * module namespace, so a whole schema file opts in with one call:\n *\n * ```ts\n * import * as schemas from \"./schemas.js\";\n * jitAll(schemas);\n * ```\n *\n * The namespace object itself is never written to (a module namespace is\n * read-only); `jit()` mutates the schema objects it holds, which is what every\n * importer of that module already references.\n */\nexport function jitAll(schemas: object, options?: JitOptions): void {\n for (const value of Object.values(schemas)) {\n if (isZodSchema(value)) jit(value, options);\n }\n}\n\n/** Zod schemas carry `_zod.def`; the same probe auto-discovery uses at build time. */\nfunction isZodSchema(value: unknown): value is ZodType {\n if (typeof value !== \"object\" || value === null || !(\"_zod\" in value)) return false;\n const internal = (value as Record<string, unknown>)[\"_zod\"];\n return typeof internal === \"object\" && internal !== null && \"def\" in internal;\n}\n\n/** Put Zod's own descriptors back, dropping the compile-on-read accessors. */\nfunction restore(\n target: Record<string, unknown>,\n original: ReadonlyMap<string, PropertyDescriptor | undefined>,\n): void {\n for (const slot of SLOTS) {\n const descriptor = original.get(slot);\n if (descriptor === undefined) delete target[slot];\n else Object.defineProperty(target, slot, descriptor);\n }\n}\n\n/**\n * Whether runtime code generation is permitted here. Read per call, never\n * snapshotted: `z.config({ jitless: true })` runs in an entry point, after the\n * schema modules it imports have already been evaluated.\n */\nfunction codegenAllowed(): boolean {\n return zodCore.globalConfig.jitless !== true && zodCore.util.allowsEval.value;\n}\n\n/**\n * Run the pipeline and let the generated IIFE install its methods on `schema`.\n * Swallows failure: a schema that cannot be compiled keeps Zod's own methods,\n * which the caller already has, so there is nothing to report and nothing to\n * break.\n */\nfunction materialize(schema: unknown): void {\n if (!codegenAllowed()) return;\n try {\n buildValidator(schema);\n } catch {\n // Left as plain Zod. Deliberately silent: `jit()` is an optimization, and a\n // schema using a construct the compiler declines is a supported outcome,\n // not an error.\n }\n}\n\n/**\n * Generate the validator and evaluate it, reproducing the module a\n * `.compiled.ts` would have been: helper preamble, the file-level shared block,\n * then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live\n * schema object passed in as `__schema`.\n */\nfunction buildValidator(schema: unknown): void {\n const { schemas, shared } = compileSchemas([{ exportName: \"jit\", schema }], { mode: \"inline\" });\n const compiled = schemas[0];\n if (compiled === undefined) throw new Error(\"zod-compiler: schema produced no validator\");\n\n const body = [RUNTIME_PRELUDE, shared.code, `return ${generateIIFE(\"__schema\", compiled)};`].join(\n \"\\n\",\n );\n\n // The three bindings ZOD_CONFIG_IMPORT would have imported, passed in so the\n // evaluated code needs no module resolution of its own.\n // oxlint-disable-next-line no-new-func -- generating the validator IS the feature\n const factory = new Function(\n \"__zodCompilerConfig\",\n \"__zcCore\",\n \"__zcZodError\",\n \"__schema\",\n body,\n ) as (\n zodConfigFn: typeof zodConfig,\n zodCoreNs: typeof zodCore,\n zodErrorCtor: typeof ZodRealError,\n target: unknown,\n ) => unknown;\n\n factory(zodConfig, zodCore, ZodRealError, schema);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWX,MAAM,QAAQ;CAAC;CAAS;CAAa;CAAc;CAAkB;CAAM;AAAW;;AAGtF,MAAM,uBAAO,IAAI,QAAgB;;;;;;;;;;;;;;;;;;;;;;AAiCjC,SAAgB,IACd,QACA,SAC+B;CAC/B,MAAM,SAAS;CACf,IAAI,KAAK,IAAI,MAAM,GAAG,OAAO;CAC7B,KAAK,IAAI,MAAM;CAEf,IAAI,SAAS,UAAU,MAAM;EAC3B,YAAY,MAAM;EAClB,OAAO;CACT;CAMA,MAAM,2BAAW,IAAI,IAA4C;CACjE,KAAK,MAAM,QAAQ,OACjB,SAAS,IAAI,MAAM,OAAO,yBAAyB,QAAQ,IAAI,CAAC;CAQlE,IAAI,UAAU;CACd,IAAI;EACF,iBACE,QACA,gBACM;GACJ,IAAI,CAAC,SAAS;GACd,UAAU;GACV,QAAQ,QAAQ,QAAQ;GACxB,YAAY,MAAM;EACpB,SACM;GACJ,IAAI,CAAC,SAAS;GACd,UAAU;GAMV,QAAQ,QAAQ,QAAQ;EAC1B,CACF;CACF,QAAQ;EACN,UAAU;EACV,QAAQ,QAAQ,QAAQ;CAC1B;CAEA,OAAO;AACT;;;;;;AAOA,SAAS,iBACP,QACA,UACA,SACA,QACM;CACN,KAAK,MAAM,QAAQ,OACjB,OAAO,eAAe,QAAQ,MAAM;EAClC,cAAc;EAId,YAAY,SAAS,IAAI,IAAI,CAAC,EAAE,cAAc;EAC9C,MAAM;GACJ,QAAQ;GAGR,OAAO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,IAboB,SAClB,uBACA,YACA,gBACA,YACA,IAQI,CAAC,CAACC,QAAWD,MAAS,cAAc,MAAM;AAClD"}
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/loader.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Candidate files for a specifier using the tsconfig path mappings visible
|
|
3
4
|
* from a directory. Used by the static dependency crawler so alias imports
|
|
@@ -15,9 +16,9 @@
|
|
|
15
16
|
* and `#` subpath imports included) and expects the caller to fall back
|
|
16
17
|
* to node resolution when the candidate does not exist.
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
declare function resolveTsconfigPathCandidates(fromDir: string, specifier: string): {
|
|
20
|
+
candidates: string[];
|
|
21
|
+
authoritative: boolean;
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
24
|
* Thrown in place of a `process.exit()` call made while a build-time module is
|
|
@@ -25,10 +26,10 @@ export declare function resolveTsconfigPathCandidates(fromDir: string, specifier
|
|
|
25
26
|
* and skips the file (falling back to runtime Zod), so a non-cooperating
|
|
26
27
|
* module's exit degrades gracefully instead of terminating the bundler.
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
declare class ProcessExitDuringLoadError extends Error {
|
|
30
|
+
/** The code passed to the intercepted `process.exit()`, if any. */
|
|
31
|
+
readonly exitCode: number | string | undefined;
|
|
32
|
+
constructor(code?: number | string);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Drop every first-party (non-node_modules) module from the shared loader
|
|
@@ -42,7 +43,7 @@ export declare class ProcessExitDuringLoadError extends Error {
|
|
|
42
43
|
* keeping node_modules (the expensive bulk — zod itself) warm is both correct
|
|
43
44
|
* and fast.
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
declare function invalidateModuleCache(): void;
|
|
46
47
|
/**
|
|
47
48
|
* Absolute paths of every first-party (non-node_modules) module currently
|
|
48
49
|
* executed by the shared loader. Used by the unplugin disk cache to record
|
|
@@ -52,7 +53,7 @@ export declare function invalidateModuleCache(): void;
|
|
|
52
53
|
* Returns null when no jiti instance exists (Bun/Deno native import — no
|
|
53
54
|
* evictable cache, so dependency tracking is unavailable).
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
+
declare function getFirstPartyModulePaths(): string[] | null;
|
|
56
57
|
/**
|
|
57
58
|
* Dynamically import a source file (.ts or .js).
|
|
58
59
|
* - Bun/Deno: native TypeScript support, direct import
|
|
@@ -62,7 +63,7 @@ export declare function getFirstPartyModulePaths(): string[] | null;
|
|
|
62
63
|
* Module executions are cached across calls; use invalidateModuleCache()
|
|
63
64
|
* when source files change (watch/HMR).
|
|
64
65
|
*/
|
|
65
|
-
|
|
66
|
+
declare function loadSourceFile(filePath: string): Promise<Record<string, unknown>>;
|
|
66
67
|
/**
|
|
67
68
|
* Import a module by SPECIFIER as `fromFile` would: relative specifiers
|
|
68
69
|
* resolve against the importing file's directory; bare specifiers (`zod`)
|
|
@@ -70,5 +71,7 @@ export declare function loadSourceFile(filePath: string): Promise<Record<string,
|
|
|
70
71
|
* the same module instance discovery executions see. Used by the hoisted-
|
|
71
72
|
* schema compile step to evaluate hoisted expressions at build time.
|
|
72
73
|
*/
|
|
73
|
-
|
|
74
|
+
declare function loadModule(specifier: string, fromFile: string): Promise<Record<string, unknown>>;
|
|
75
|
+
//#endregion
|
|
76
|
+
export { ProcessExitDuringLoadError, getFirstPartyModulePaths, invalidateModuleCache, loadModule, loadSourceFile, resolveTsconfigPathCandidates };
|
|
74
77
|
//# sourceMappingURL=loader.d.ts.map
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","
|
|
1
|
+
{"version":3,"file":"loader.d.ts","names":[],"sources":["../src/loader.ts"],"mappings":";;;;;;;;;;;;;;;;;;iBAqGgB,8BACd,iBACA;EACG;EAAsB;;;;;;;;cA8Dd,mCAAmC;;WAErC;EAEG,YAAA;;;;;;;;;;;;;;iBA8EE;;;;;;;;;;iBAoBA;;;;;;;;;;iBAqCM,eAAe,mBAAmB,QAAQ;;;;;;;;iBA+B1C,WACpB,mBACA,mBACC,QAAQ"}
|