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
|
@@ -1,108 +1,71 @@
|
|
|
1
|
-
import { declareFastTemps, emitEffectCallable, emitRuntimeHelper, escapeString, extendPath, extendStaticPath, hasMutation, keyMembershipTest, outputAlwaysDefined
|
|
1
|
+
import { declareFastTemps, emitEffectCallable, emitRuntimeHelper, escapeString, extendPath, extendStaticPath, hasMutation, keyMembershipTest, outputAlwaysDefined } from "../context.js";
|
|
2
2
|
import { emit } from "../emit.js";
|
|
3
3
|
import { invalidType, unrecognizedKeys } from "../emit-issue.js";
|
|
4
4
|
import { ZC_AB_DECL } from "../issue-decls.js";
|
|
5
|
-
import { orderByRuntimeCost } from "../fast-size.js";
|
|
6
5
|
import { refineCheck, superRefineCheck, superRefineFastTest } from "./effect.js";
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { orderByRuntimeCost } from "../fast-size.js";
|
|
7
|
+
//#region src/core/codegen/schemas/object.ts
|
|
8
|
+
function slowObject(ir, g) {
|
|
9
|
+
let code = emit`
|
|
9
10
|
if(typeof ${g.input}!=="object"||${g.input}===null||Array.isArray(${g.input})){
|
|
10
11
|
${invalidType(g, "object")}
|
|
11
12
|
}else{`;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const keyStr = escapeString(key);
|
|
42
|
-
const propPath = extendStaticPath(g.path, key);
|
|
43
|
-
// Strip validates the value read from the INPUT, held in a local, and
|
|
44
|
-
// assembles the result afterwards. Reading through the half-built copy (the
|
|
45
|
-
// previous shape) both cost a megamorphic access per key — the copy's map
|
|
46
|
-
// changes with every key added — and diverged from zod, which parses
|
|
47
|
-
// `input[key]` and so accepts a value found on the prototype.
|
|
48
|
-
const propExpr = strip ? g.temp("sv") : `${objVar}[${keyStr}]`;
|
|
49
|
-
if (strip) {
|
|
50
|
-
code += `var ${propExpr}=${g.input}[${keyStr}];`;
|
|
51
|
-
slots.push({ always: outputAlwaysDefined(propIR), keyStr, value: propExpr });
|
|
52
|
-
}
|
|
53
|
-
const propCode = g.visit(propIR, { input: propExpr, output: propExpr, path: propPath });
|
|
54
|
-
if (suppressAbsent.has(key)) {
|
|
55
|
-
// Mirrors zod's handlePropertyResult: optional-out fallback props run,
|
|
56
|
-
// but their issues are discarded when the key is absent from the input.
|
|
57
|
-
const beforeVar = g.temp("ob");
|
|
58
|
-
code += emit `
|
|
13
|
+
const strip = ir.stripUnknownKeys === true;
|
|
14
|
+
const needsClone = strip || ir.catchall !== void 0 && hasMutation(ir.catchall) || Object.values(ir.properties).some(hasMutation);
|
|
15
|
+
const objVar = g.temp("o");
|
|
16
|
+
if (!strip) code += needsClone ? `var ${objVar}={...${g.input}};` : `var ${objVar}=${g.input};`;
|
|
17
|
+
const refineMark = ir.checks && ir.checks.length > 0 ? g.temp("rm") : "";
|
|
18
|
+
if (refineMark) code += `var ${refineMark}=${g.issues}.length;`;
|
|
19
|
+
const suppressAbsent = new Set(ir.suppressAbsentKeys ?? []);
|
|
20
|
+
/** Strip only: per-property output slot + whether it is always in the result. */
|
|
21
|
+
const slots = [];
|
|
22
|
+
for (const [key, propIR] of Object.entries(ir.properties)) {
|
|
23
|
+
const keyStr = escapeString(key);
|
|
24
|
+
const propPath = extendStaticPath(g.path, key);
|
|
25
|
+
const propExpr = strip ? g.temp("sv") : `${objVar}[${keyStr}]`;
|
|
26
|
+
if (strip) {
|
|
27
|
+
code += `var ${propExpr}=${g.input}[${keyStr}];`;
|
|
28
|
+
slots.push({
|
|
29
|
+
always: outputAlwaysDefined(propIR),
|
|
30
|
+
keyStr,
|
|
31
|
+
value: propExpr
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const propCode = g.visit(propIR, {
|
|
35
|
+
input: propExpr,
|
|
36
|
+
output: propExpr,
|
|
37
|
+
path: propPath
|
|
38
|
+
});
|
|
39
|
+
if (suppressAbsent.has(key)) {
|
|
40
|
+
const beforeVar = g.temp("ob");
|
|
41
|
+
code += emit`
|
|
59
42
|
var ${beforeVar}=${g.issues}.length;
|
|
60
43
|
${propCode}
|
|
61
44
|
if(!(${keyStr} in ${strip ? g.input : objVar})&&${g.issues}.length>${beforeVar}){
|
|
62
45
|
${g.issues}.length=${beforeVar};
|
|
63
46
|
}`;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
literal.push(`${slot.keyStr}:${slot.value}`);
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
leading = false;
|
|
90
|
-
appends += slot.always
|
|
91
|
-
? `${objVar}[${slot.keyStr}]=${slot.value};`
|
|
92
|
-
: `if(${slot.value}!==undefined||(${slot.keyStr} in ${g.input})){${objVar}[${slot.keyStr}]=${slot.value};}`;
|
|
93
|
-
}
|
|
94
|
-
code += `var ${objVar}={${literal.join(",")}};${appends}`;
|
|
95
|
-
}
|
|
96
|
-
// Strict unknown-key pass — zod's handleCatchall, byte-exact: for-in over
|
|
97
|
-
// the ORIGINAL input (inherited enumerable keys count, no hasOwnProperty),
|
|
98
|
-
// ALL unknown keys collected into one issue, pushed AFTER property issues
|
|
99
|
-
// and before object-level refines.
|
|
100
|
-
if (ir.strict) {
|
|
101
|
-
const keys = Object.keys(ir.properties);
|
|
102
|
-
const ukVar = g.temp("uk");
|
|
103
|
-
const kVar = g.temp("k");
|
|
104
|
-
const test = keyMembershipTest(g.ctx, keys, kVar);
|
|
105
|
-
code += emit `
|
|
47
|
+
} else code += propCode;
|
|
48
|
+
}
|
|
49
|
+
if (strip) {
|
|
50
|
+
const literal = [];
|
|
51
|
+
let appends = "";
|
|
52
|
+
let leading = true;
|
|
53
|
+
for (const slot of slots) {
|
|
54
|
+
if (leading && slot.always) {
|
|
55
|
+
literal.push(`${slot.keyStr}:${slot.value}`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
leading = false;
|
|
59
|
+
appends += slot.always ? `${objVar}[${slot.keyStr}]=${slot.value};` : `if(${slot.value}!==undefined||(${slot.keyStr} in ${g.input})){${objVar}[${slot.keyStr}]=${slot.value};}`;
|
|
60
|
+
}
|
|
61
|
+
code += `var ${objVar}={${literal.join(",")}};${appends}`;
|
|
62
|
+
}
|
|
63
|
+
if (ir.strict) {
|
|
64
|
+
const keys = Object.keys(ir.properties);
|
|
65
|
+
const ukVar = g.temp("uk");
|
|
66
|
+
const kVar = g.temp("k");
|
|
67
|
+
const test = keyMembershipTest(g.ctx, keys, kVar);
|
|
68
|
+
code += emit`
|
|
106
69
|
var ${ukVar}=null;
|
|
107
70
|
for(var ${kVar} in ${g.input}){
|
|
108
71
|
if(!(${test})){(${ukVar}=${ukVar}||[]).push(${kVar});}
|
|
@@ -110,156 +73,106 @@ export function slowObject(ir, g) {
|
|
|
110
73
|
if(${ukVar}!==null){
|
|
111
74
|
${unrecognizedKeys(g, ukVar)}
|
|
112
75
|
}`;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// writes through the same expression it later re-reads, so splitting them
|
|
122
|
-
// makes the rewrite invisible to its own checks.
|
|
123
|
-
//
|
|
124
|
-
// When the catchall mutates, objVar is a clone, and each unknown key is
|
|
125
|
-
// copied into it before validation — which also reproduces zod, whose fresh
|
|
126
|
-
// output object gains an OWN key for every for-in key it saw, inherited ones
|
|
127
|
-
// included. A non-mutating catchall writes nothing, so objVar is the input
|
|
128
|
-
// and the object stays pass-through by reference.
|
|
129
|
-
if (ir.catchall) {
|
|
130
|
-
const keys = Object.keys(ir.properties);
|
|
131
|
-
const kVar = g.temp("ck");
|
|
132
|
-
const test = keyMembershipTest(g.ctx, keys, kVar);
|
|
133
|
-
const slot = `${objVar}[${kVar}]`;
|
|
134
|
-
const seed = needsClone ? `${slot}=${g.input}[${kVar}];` : "";
|
|
135
|
-
code += emit `
|
|
76
|
+
}
|
|
77
|
+
if (ir.catchall) {
|
|
78
|
+
const keys = Object.keys(ir.properties);
|
|
79
|
+
const kVar = g.temp("ck");
|
|
80
|
+
const test = keyMembershipTest(g.ctx, keys, kVar);
|
|
81
|
+
const slot = `${objVar}[${kVar}]`;
|
|
82
|
+
const seed = needsClone ? `${slot}=${g.input}[${kVar}];` : "";
|
|
83
|
+
code += emit`
|
|
136
84
|
for(var ${kVar} in ${g.input}){
|
|
137
85
|
if(!(${test})){
|
|
138
86
|
${seed}
|
|
139
87
|
${g.visit(ir.catchall, {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
88
|
+
input: slot,
|
|
89
|
+
output: slot,
|
|
90
|
+
path: extendPath(g.path, kVar)
|
|
91
|
+
})}
|
|
144
92
|
}
|
|
145
93
|
}`;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
for (const check of ir.checks) {
|
|
157
|
-
refines +=
|
|
158
|
-
check.kind === "super_refine_effect"
|
|
159
|
-
? superRefineCheck(check, objVar, g)
|
|
160
|
-
: refineCheck(check, objVar, g);
|
|
161
|
-
}
|
|
162
|
-
const aborted = emitRuntimeHelper(g.ctx, "__zcAb", ZC_AB_DECL);
|
|
163
|
-
code += `if(!${aborted}(${g.issues},${refineMark})){${refines}}`;
|
|
164
|
-
}
|
|
165
|
-
code += `}\n`;
|
|
166
|
-
return code;
|
|
94
|
+
}
|
|
95
|
+
if (needsClone) code += `${g.output}=${objVar};`;
|
|
96
|
+
if (ir.checks && ir.checks.length > 0) {
|
|
97
|
+
let refines = "";
|
|
98
|
+
for (const check of ir.checks) refines += check.kind === "super_refine_effect" ? superRefineCheck(check, objVar, g) : refineCheck(check, objVar, g);
|
|
99
|
+
const aborted = emitRuntimeHelper(g.ctx, "__zcAb", ZC_AB_DECL);
|
|
100
|
+
code += `if(!${aborted}(${g.issues},${refineMark})){${refines}}`;
|
|
101
|
+
}
|
|
102
|
+
code += `}\n`;
|
|
103
|
+
return code;
|
|
167
104
|
}
|
|
168
105
|
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
106
|
+
* Property entries in the order their fast-checks should be `&&`-chained:
|
|
107
|
+
* cheapest first, declaration order preserved among equals (Array#sort is
|
|
108
|
+
* stable). Valid input runs every conjunct whatever the order, so this costs
|
|
109
|
+
* nothing on the hot path; a REJECT stops at the first false conjunct, so
|
|
110
|
+
* pricing a `z.email()` behind the `kind` literal that actually discriminates
|
|
111
|
+
* is what makes union probing and `.is()` misses cheap (see
|
|
112
|
+
* estimateRuntimeCost). The SLOW path keeps declaration order — that one's
|
|
113
|
+
* output is the issue list, whose order is part of zod parity.
|
|
114
|
+
*/
|
|
178
115
|
function orderedProperties(ir, g) {
|
|
179
|
-
|
|
116
|
+
return orderByRuntimeCost(Object.entries(ir.properties), ([, propIR]) => propIR, g.ctx);
|
|
180
117
|
}
|
|
181
118
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
119
|
+
* Property/strict/refine fast-checks for an object, WITHOUT the leading
|
|
120
|
+
* `typeof===object && !==null && !Array.isArray` type-guard. Returns the
|
|
121
|
+
* conjunct parts (joinable with `&&`), or null if any child is fast-ineligible.
|
|
122
|
+
*
|
|
123
|
+
* `skipKey`, when given, omits that one property's check. Used by the
|
|
124
|
+
* discriminated-union fast path (via `g.discSkipKey`): the enclosing `switch`
|
|
125
|
+
* has already matched the discriminator's value, so re-checking it is redundant.
|
|
126
|
+
*/
|
|
190
127
|
function fastObjectBody(ir, g, skipKey) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (valCheck !== "true") {
|
|
226
|
-
const fnName = g.temp("co");
|
|
227
|
-
const test = keyMembershipTest(g.ctx, Object.keys(ir.properties), kv);
|
|
228
|
-
g.ctx.preamble.push(`function ${fnName}(o){${declareFastTemps(catchallGen.scope)}var ${kv},${vv};for(${kv} in o){if(!(${test})){${vv}=o[${kv}];if(!(${valCheck}))return false;}}return true;}`);
|
|
229
|
-
parts.push(`${fnName}(${x})`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Object-level refine effects (appended last — run after property checks short-circuit)
|
|
233
|
-
if (ir.checks) {
|
|
234
|
-
for (const check of ir.checks) {
|
|
235
|
-
if (check.kind === "refine_effect") {
|
|
236
|
-
parts.push(`${emitEffectCallable(g.ctx, check)}(${x})`);
|
|
237
|
-
}
|
|
238
|
-
else if (check.kind === "super_refine_effect") {
|
|
239
|
-
parts.push(superRefineFastTest(check, x, g));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return parts;
|
|
128
|
+
const x = g.input;
|
|
129
|
+
const parts = [];
|
|
130
|
+
for (const [key, propIR] of orderedProperties(ir, g)) {
|
|
131
|
+
if (key === skipKey) continue;
|
|
132
|
+
const propExpr = `${x}[${escapeString(key)}]`;
|
|
133
|
+
const propCheck = g.visit(propIR, { input: propExpr });
|
|
134
|
+
if (propCheck === null) return null;
|
|
135
|
+
parts.push(propCheck);
|
|
136
|
+
}
|
|
137
|
+
if (ir.strict) {
|
|
138
|
+
const keys = Object.keys(ir.properties);
|
|
139
|
+
const fnName = g.temp("so");
|
|
140
|
+
const test = keyMembershipTest(g.ctx, keys, "k");
|
|
141
|
+
g.ctx.preamble.push(`function ${fnName}(o){for(var k in o){if(!(${test}))return false;}return true;}`);
|
|
142
|
+
parts.push(`${fnName}(${x})`);
|
|
143
|
+
}
|
|
144
|
+
if (ir.catchall) {
|
|
145
|
+
const kv = g.temp("cak");
|
|
146
|
+
const vv = g.temp("cav");
|
|
147
|
+
const catchallGen = g.scoped(vv);
|
|
148
|
+
const valCheck = catchallGen.visit(ir.catchall, { input: vv });
|
|
149
|
+
if (valCheck === null) return null;
|
|
150
|
+
if (valCheck !== "true") {
|
|
151
|
+
const fnName = g.temp("co");
|
|
152
|
+
const test = keyMembershipTest(g.ctx, Object.keys(ir.properties), kv);
|
|
153
|
+
g.ctx.preamble.push(`function ${fnName}(o){${declareFastTemps(catchallGen.scope)}var ${kv},${vv};for(${kv} in o){if(!(${test})){${vv}=o[${kv}];if(!(${valCheck}))return false;}}return true;}`);
|
|
154
|
+
parts.push(`${fnName}(${x})`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (ir.checks) {
|
|
158
|
+
for (const check of ir.checks) if (check.kind === "refine_effect") parts.push(`${emitEffectCallable(g.ctx, check)}(${x})`);
|
|
159
|
+
else if (check.kind === "super_refine_effect") parts.push(superRefineFastTest(check, x, g));
|
|
160
|
+
}
|
|
161
|
+
return parts;
|
|
244
162
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
// Discriminated-union option: the enclosing switch (and the caller's guard)
|
|
257
|
-
// already established object-ness and the discriminator value, so emit only
|
|
258
|
-
// the remaining checks — no leading type-guard. An option with nothing left
|
|
259
|
-
// to check accepts unconditionally ("true").
|
|
260
|
-
if (g.discSkipKey !== undefined) {
|
|
261
|
-
return body.length > 0 ? body.join("&&") : "true";
|
|
262
|
-
}
|
|
263
|
-
return [`typeof ${x}==="object"`, `${x}!==null`, `!Array.isArray(${x})`, ...body].join("&&");
|
|
163
|
+
function fastObject(ir, g) {
|
|
164
|
+
const x = g.input;
|
|
165
|
+
const body = fastObjectBody(ir, g, g.discSkipKey);
|
|
166
|
+
if (body === null) return null;
|
|
167
|
+
if (g.discSkipKey !== void 0) return body.length > 0 ? body.join("&&") : "true";
|
|
168
|
+
return [
|
|
169
|
+
`typeof ${x}==="object"`,
|
|
170
|
+
`${x}!==null`,
|
|
171
|
+
`!Array.isArray(${x})`,
|
|
172
|
+
...body
|
|
173
|
+
].join("&&");
|
|
264
174
|
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { fastObject, slowObject };
|
|
177
|
+
|
|
265
178
|
//# sourceMappingURL=object.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../../src/core/codegen/schemas/object.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEjF,MAAM,UAAU,UAAU,CAAC,EAAiC,EAAE,CAAU;IACtE,IAAI,IAAI,GAAG,IAAI,CAAA;gBACD,CAAC,CA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nC,KAAK,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1D,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBAChD,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,EAAY,EAAE,CAAU;IACjD,8EAA8E;IAC9E,6EAA6E;IAC7E,+EAA+E;IAC/E,6EAA6E;IAC7E,6EAA6E;IAC7E,wCAAwC;IACxC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;IAClB,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAClD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAC5E,6CAA6C;IAC7C,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACpD,CAAC;IACD,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,GAAG,CAAC,SAAS,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/F,CAAC"}
|
|
1
|
+
{"version":3,"file":"object.js","names":[],"sources":["../../../../src/core/codegen/schemas/object.ts"],"sourcesContent":["import type { ObjectIR, SchemaIR } from \"../../types.js\";\nimport type { FastGen, SlowGen } from \"../context.js\";\nimport {\n declareFastTemps,\n emitEffectCallable,\n emitRuntimeHelper,\n escapeString,\n extendPath,\n extendStaticPath,\n hasMutation,\n keyMembershipTest,\n outputAlwaysDefined,\n} from \"../context.js\";\nimport { emit } from \"../emit.js\";\nimport { invalidType, unrecognizedKeys } from \"../emit-issue.js\";\nimport { ZC_AB_DECL } from \"../issue-decls.js\";\nimport { orderByRuntimeCost } from \"../fast-size.js\";\nimport { refineCheck, superRefineCheck, superRefineFastTest } from \"./effect.js\";\n\nexport function slowObject(ir: SchemaIR & { type: \"object\" }, g: SlowGen): string {\n let code = emit`\n if(typeof ${g.input}!==\"object\"||${g.input}===null||Array.isArray(${g.input})){\n ${invalidType(g, \"object\")}\n }else{`;\n\n // Strip mode (zod's default z.object() output) rebuilds a FRESH object from\n // the declared keys, so it always writes back. Otherwise clone only when a\n // property mutates the value.\n const strip = ir.stripUnknownKeys === true;\n const needsClone =\n strip ||\n (ir.catchall !== undefined && hasMutation(ir.catchall)) ||\n Object.values(ir.properties).some(hasMutation);\n const objVar = g.temp(\"o\");\n if (!strip) {\n // Spread, not Object.assign: V8's CloneObjectIC makes `{...x}` ~25% faster\n // on the whole safeParse call for mutation-bearing schemas.\n code += needsClone ? `var ${objVar}={...${g.input}};` : `var ${objVar}=${g.input};`;\n }\n\n // Object-level refines are gated on zod's ABORT rule, not on \"did anything\n // fail\": zod parses the properties (plus the strict/catchall passes) into the\n // payload and then skips its check chain only when `util.aborted` holds — i.e.\n // when one of those issues is non-continuable. A property that failed its own\n // `min`/format check reports a CONTINUABLE issue, so the outer refine still\n // runs and both messages surface; a property that failed to parse at all\n // (`invalid_type`, an unrecognized key, a bad record key) aborts and\n // suppresses it. Snapshot the issue count before the properties so the scan\n // covers exactly this node's own parse, as zod's fresh sub-payload does.\n const refineMark = ir.checks && ir.checks.length > 0 ? g.temp(\"rm\") : \"\";\n if (refineMark) code += `var ${refineMark}=${g.issues}.length;`;\n\n const suppressAbsent = new Set(ir.suppressAbsentKeys ?? []);\n /** Strip only: per-property output slot + whether it is always in the result. */\n const slots: { always: boolean; keyStr: string; value: string }[] = [];\n\n for (const [key, propIR] of Object.entries(ir.properties)) {\n const keyStr = escapeString(key);\n const propPath = extendStaticPath(g.path, key);\n // Strip validates the value read from the INPUT, held in a local, and\n // assembles the result afterwards. Reading through the half-built copy (the\n // previous shape) both cost a megamorphic access per key — the copy's map\n // changes with every key added — and diverged from zod, which parses\n // `input[key]` and so accepts a value found on the prototype.\n const propExpr = strip ? g.temp(\"sv\") : `${objVar}[${keyStr}]`;\n if (strip) {\n code += `var ${propExpr}=${g.input}[${keyStr}];`;\n slots.push({ always: outputAlwaysDefined(propIR), keyStr, value: propExpr });\n }\n const propCode = g.visit(propIR, { input: propExpr, output: propExpr, path: propPath });\n if (suppressAbsent.has(key)) {\n // Mirrors zod's handlePropertyResult: optional-out fallback props run,\n // but their issues are discarded when the key is absent from the input.\n const beforeVar = g.temp(\"ob\");\n code += emit`\n var ${beforeVar}=${g.issues}.length;\n ${propCode}\n if(!(${keyStr} in ${strip ? g.input : objVar})&&${g.issues}.length>${beforeVar}){\n ${g.issues}.length=${beforeVar};\n }`;\n } else {\n code += propCode;\n }\n }\n\n if (strip) {\n // Assemble the result in shape order (zod's key order), taking as long a\n // LEADING run of always-present keys as possible into one object literal:\n // V8 stamps a literal out of a cached boilerplate map in a single\n // allocation, where adding keys one at a time walks a transition chain and\n // re-checks the map on every store — measured 8.1x (20 keys) / 2.8x (7\n // keys, one optional) on the whole safeParse.\n //\n // Everything after the first conditional key is appended so insertion order\n // still matches zod. The per-key test is zod's own: keep the key when the\n // parsed value is defined, or when it was present on the input at all\n // (`key in input`, prototype included — an own `k: undefined` survives).\n const literal: string[] = [];\n let appends = \"\";\n let leading = true;\n for (const slot of slots) {\n if (leading && slot.always) {\n literal.push(`${slot.keyStr}:${slot.value}`);\n continue;\n }\n leading = false;\n appends += slot.always\n ? `${objVar}[${slot.keyStr}]=${slot.value};`\n : `if(${slot.value}!==undefined||(${slot.keyStr} in ${g.input})){${objVar}[${slot.keyStr}]=${slot.value};}`;\n }\n code += `var ${objVar}={${literal.join(\",\")}};${appends}`;\n }\n\n // Strict unknown-key pass — zod's handleCatchall, byte-exact: for-in over\n // the ORIGINAL input (inherited enumerable keys count, no hasOwnProperty),\n // ALL unknown keys collected into one issue, pushed AFTER property issues\n // and before object-level refines.\n if (ir.strict) {\n const keys = Object.keys(ir.properties);\n const ukVar = g.temp(\"uk\");\n const kVar = g.temp(\"k\");\n const test = keyMembershipTest(g.ctx, keys, kVar);\n code += emit`\n var ${ukVar}=null;\n for(var ${kVar} in ${g.input}){\n if(!(${test})){(${ukVar}=${ukVar}||[]).push(${kVar});}\n }\n if(${ukVar}!==null){\n ${unrecognizedKeys(g, ukVar)}\n }`;\n }\n\n // .catchall(schema): validate every key NOT in the shape, mirroring zod's\n // handleCatchall — same bare for-in over the ORIGINAL input as the strict\n // pass (inherited enumerable keys count, no hasOwnProperty guard), each\n // issue reported at the key. Runs after the properties, as zod does.\n //\n // The key's slot is BOTH the input and the output, exactly as a shape\n // property's is: a value-rewriting catchall (coerce, .trim(), a default)\n // writes through the same expression it later re-reads, so splitting them\n // makes the rewrite invisible to its own checks.\n //\n // When the catchall mutates, objVar is a clone, and each unknown key is\n // copied into it before validation — which also reproduces zod, whose fresh\n // output object gains an OWN key for every for-in key it saw, inherited ones\n // included. A non-mutating catchall writes nothing, so objVar is the input\n // and the object stays pass-through by reference.\n if (ir.catchall) {\n const keys = Object.keys(ir.properties);\n const kVar = g.temp(\"ck\");\n const test = keyMembershipTest(g.ctx, keys, kVar);\n const slot = `${objVar}[${kVar}]`;\n const seed = needsClone ? `${slot}=${g.input}[${kVar}];` : \"\";\n code += emit`\n for(var ${kVar} in ${g.input}){\n if(!(${test})){\n ${seed}\n ${g.visit(ir.catchall, {\n input: slot,\n output: slot,\n path: extendPath(g.path, kVar),\n })}\n }\n }`;\n }\n\n if (needsClone) {\n code += `${g.output}=${objVar};`;\n }\n\n // Object-level refine effects: z.object({...}).refine(fn), suppressed when the\n // parse phase aborted (see refineMark). One gate covers every effect: each of\n // them can only add a continuable `custom` issue, so zod's per-check\n // re-evaluation of `isAborted` can never flip between them.\n if (ir.checks && ir.checks.length > 0) {\n let refines = \"\";\n for (const check of ir.checks) {\n refines +=\n check.kind === \"super_refine_effect\"\n ? superRefineCheck(check, objVar, g)\n : refineCheck(check, objVar, g);\n }\n const aborted = emitRuntimeHelper(g.ctx, \"__zcAb\", ZC_AB_DECL);\n code += `if(!${aborted}(${g.issues},${refineMark})){${refines}}`;\n }\n\n code += `}\\n`;\n return code;\n}\n\n/**\n * Property entries in the order their fast-checks should be `&&`-chained:\n * cheapest first, declaration order preserved among equals (Array#sort is\n * stable). Valid input runs every conjunct whatever the order, so this costs\n * nothing on the hot path; a REJECT stops at the first false conjunct, so\n * pricing a `z.email()` behind the `kind` literal that actually discriminates\n * is what makes union probing and `.is()` misses cheap (see\n * estimateRuntimeCost). The SLOW path keeps declaration order — that one's\n * output is the issue list, whose order is part of zod parity.\n */\nfunction orderedProperties(ir: ObjectIR, g: FastGen): [string, SchemaIR][] {\n return orderByRuntimeCost(Object.entries(ir.properties), ([, propIR]) => propIR, g.ctx);\n}\n\n/**\n * Property/strict/refine fast-checks for an object, WITHOUT the leading\n * `typeof===object && !==null && !Array.isArray` type-guard. Returns the\n * conjunct parts (joinable with `&&`), or null if any child is fast-ineligible.\n *\n * `skipKey`, when given, omits that one property's check. Used by the\n * discriminated-union fast path (via `g.discSkipKey`): the enclosing `switch`\n * has already matched the discriminator's value, so re-checking it is redundant.\n */\nfunction fastObjectBody(ir: ObjectIR, g: FastGen, skipKey?: string): string[] | null {\n const x = g.input;\n const parts: string[] = [];\n\n for (const [key, propIR] of orderedProperties(ir, g)) {\n if (key === skipKey) continue;\n const propExpr = `${x}[${escapeString(key)}]`;\n const propCheck = g.visit(propIR, { input: propExpr });\n if (propCheck === null) return null; // All-or-nothing\n parts.push(propCheck);\n }\n\n // Strict unknown-key pass: hosted boolean helper (a for-in loop cannot live\n // in the && chain). Same for-in iteration as the slow path — fast/slow\n // agreement is load-bearing under the __zcFinD deferral. The membership set is\n // the FULL key list (the discriminator is a recognized key), independent of\n // skipKey, which only suppresses re-validating the discriminator's value.\n if (ir.strict) {\n const keys = Object.keys(ir.properties);\n const fnName = g.temp(\"so\");\n const test = keyMembershipTest(g.ctx, keys, \"k\");\n g.ctx.preamble.push(\n `function ${fnName}(o){for(var k in o){if(!(${test}))return false;}return true;}`,\n );\n parts.push(`${fnName}(${x})`);\n }\n\n // .catchall(schema): same hosted for-in as strict, but each unrecognized key\n // is checked against the catchall rather than rejected outright. The value is\n // hoisted into a local for the same reason fastRecord does it — repeated\n // `o[k]` computed loads are not eliminated across check boundaries.\n if (ir.catchall) {\n const kv = g.temp(\"cak\");\n const vv = g.temp(\"cav\");\n const catchallGen = g.scoped(vv);\n const valCheck = catchallGen.visit(ir.catchall, { input: vv });\n if (valCheck === null) return null;\n if (valCheck !== \"true\") {\n const fnName = g.temp(\"co\");\n const test = keyMembershipTest(g.ctx, Object.keys(ir.properties), kv);\n g.ctx.preamble.push(\n `function ${fnName}(o){${declareFastTemps(catchallGen.scope)}var ${kv},${vv};for(${kv} in o){if(!(${test})){${vv}=o[${kv}];if(!(${valCheck}))return false;}}return true;}`,\n );\n parts.push(`${fnName}(${x})`);\n }\n }\n\n // Object-level refine effects (appended last — run after property checks short-circuit)\n if (ir.checks) {\n for (const check of ir.checks) {\n if (check.kind === \"refine_effect\") {\n parts.push(`${emitEffectCallable(g.ctx, check)}(${x})`);\n } else if (check.kind === \"super_refine_effect\") {\n parts.push(superRefineFastTest(check, x, g));\n }\n }\n }\n\n return parts;\n}\n\nexport function fastObject(ir: ObjectIR, g: FastGen): string | null {\n // A strip object still gets an expression. Stripping reshapes the OUTPUT, not\n // the verdict, so this remains an exact acceptance predicate — which is what\n // `.is()` installs, and what the build path reuses to validate the subtrees it\n // passes through by reference. What it must NOT do is stand in for the parse\n // result: generateValidator withholds the `data:input` shortcut whenever the\n // schema rebuilds (see rebuildsOutput).\n const x = g.input;\n const body = fastObjectBody(ir, g, g.discSkipKey);\n if (body === null) return null;\n // Discriminated-union option: the enclosing switch (and the caller's guard)\n // already established object-ness and the discriminator value, so emit only\n // the remaining checks — no leading type-guard. An option with nothing left\n // to check accepts unconditionally (\"true\").\n if (g.discSkipKey !== undefined) {\n return body.length > 0 ? body.join(\"&&\") : \"true\";\n }\n return [`typeof ${x}===\"object\"`, `${x}!==null`, `!Array.isArray(${x})`, ...body].join(\"&&\");\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,WAAW,IAAmC,GAAoB;CAChF,IAAI,OAAO,IAAI;gBACD,EAAE,MAAM,eAAe,EAAE,MAAM,yBAAyB,EAAE,MAAM;QACxE,YAAY,GAAG,QAAQ,EAAE;;CAM/B,MAAM,QAAQ,GAAG,qBAAqB;CACtC,MAAM,aACJ,SACC,GAAG,aAAa,KAAA,KAAa,YAAY,GAAG,QAAQ,KACrD,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC,KAAK,WAAW;CAC/C,MAAM,SAAS,EAAE,KAAK,GAAG;CACzB,IAAI,CAAC,OAGH,QAAQ,aAAa,OAAO,OAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAO,GAAG,EAAE,MAAM;CAYnF,MAAM,aAAa,GAAG,UAAU,GAAG,OAAO,SAAS,IAAI,EAAE,KAAK,IAAI,IAAI;CACtE,IAAI,YAAY,QAAQ,OAAO,WAAW,GAAG,EAAE,OAAO;CAEtD,MAAM,iBAAiB,IAAI,IAAI,GAAG,sBAAsB,CAAC,CAAC;;CAE1D,MAAM,QAA8D,CAAC;CAErE,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,GAAG,UAAU,GAAG;EACzD,MAAM,SAAS,aAAa,GAAG;EAC/B,MAAM,WAAW,iBAAiB,EAAE,MAAM,GAAG;EAM7C,MAAM,WAAW,QAAQ,EAAE,KAAK,IAAI,IAAI,GAAG,OAAO,GAAG,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GAAG,EAAE,EAAE;OACjD,IAAI,MAAM,SAAS,uBACxB,MAAM,KAAK,oBAAoB,OAAO,GAAG,CAAC,CAAC;CAAA;CAKjD,OAAO;AACT;AAEA,SAAgB,WAAW,IAAc,GAA2B;CAOlE,MAAM,IAAI,EAAE;CACZ,MAAM,OAAO,eAAe,IAAI,GAAG,EAAE,WAAW;CAChD,IAAI,SAAS,MAAM,OAAO;CAK1B,IAAI,EAAE,gBAAgB,KAAA,GACpB,OAAO,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI;CAE7C,OAAO;EAAC,UAAU,EAAE;EAAc,GAAG,EAAE;EAAU,kBAAkB,EAAE;EAAI,GAAG;CAAI,CAAC,CAAC,KAAK,IAAI;AAC7F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { OptionalIR, SchemaIR } from "../../types.js";
|
|
2
|
+
import { FastGen, SlowGen } from "../context.js";
|
|
3
|
+
//#region src/core/codegen/schemas/optional.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Zod's `.optional()` short-circuits `undefined → undefined`, EXCEPT when its
|
|
5
6
|
* inner chain applies a default to undefined: `z.string().default("d").optional()`
|
|
@@ -9,9 +10,11 @@ import type { FastGen, SlowGen } from "../context.js";
|
|
|
9
10
|
* a value; `catch`, object-field defaults, and plain types do not, so the optional
|
|
10
11
|
* legitimately short-circuits there. Peel optional/nullable wrappers to decide.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
declare function innerAppliesDefaultOnUndefined(ir: SchemaIR): boolean;
|
|
14
|
+
declare function slowOptional(ir: SchemaIR & {
|
|
15
|
+
type: "optional";
|
|
15
16
|
}, g: SlowGen): string;
|
|
16
|
-
|
|
17
|
+
declare function fastOptional(ir: OptionalIR, g: FastGen): string | null;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { fastOptional, innerAppliesDefaultOnUndefined, slowOptional };
|
|
17
20
|
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.d.ts","
|
|
1
|
+
{"version":3,"file":"optional.d.ts","names":[],"sources":["../../../../src/core/codegen/schemas/optional.ts"],"mappings":";;;;;;;;;;;;iBAcgB,+BAA+B,IAAI;iBAMnC,aAAa,IAAI;EAAa;GAAoB,GAAG;iBAgBrD,aAAa,IAAI,YAAY,GAAG"}
|
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
import { fastSentinelWrapper } from "../context.js";
|
|
2
2
|
import { emit } from "../emit.js";
|
|
3
|
+
//#region src/core/codegen/schemas/optional.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return cur.type === "default";
|
|
5
|
+
* Zod's `.optional()` short-circuits `undefined → undefined`, EXCEPT when its
|
|
6
|
+
* inner chain applies a default to undefined: `z.string().default("d").optional()`
|
|
7
|
+
* yields "d", not undefined (the default fires THROUGH the optional, and through
|
|
8
|
+
* any nullable/optional wrappers between them — `default().nullish()`,
|
|
9
|
+
* `default().optional().nullable()`, ...). Only `default` consumes undefined into
|
|
10
|
+
* a value; `catch`, object-field defaults, and plain types do not, so the optional
|
|
11
|
+
* legitimately short-circuits there. Peel optional/nullable wrappers to decide.
|
|
12
|
+
*/
|
|
13
|
+
function innerAppliesDefaultOnUndefined(ir) {
|
|
14
|
+
let cur = ir;
|
|
15
|
+
while (cur.type === "optional" || cur.type === "nullable") cur = cur.inner;
|
|
16
|
+
return cur.type === "default";
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// When the inner chain handles undefined (a default), undefined must flow into
|
|
23
|
-
// it so the default applies — the inner code already gates on undefined itself.
|
|
24
|
-
if (innerAppliesDefaultOnUndefined(ir.inner)) {
|
|
25
|
-
return `${g.visit(ir.inner, fwd)}\n`;
|
|
26
|
-
}
|
|
27
|
-
return `${emit `
|
|
18
|
+
function slowOptional(ir, g) {
|
|
19
|
+
const fwd = { aborted: g.aborted };
|
|
20
|
+
if (innerAppliesDefaultOnUndefined(ir.inner)) return `${g.visit(ir.inner, fwd)}\n`;
|
|
21
|
+
return `${emit`
|
|
28
22
|
if(${g.input}!==undefined){
|
|
29
23
|
${g.visit(ir.inner, fwd)}
|
|
30
24
|
}
|
|
31
25
|
`}\n`;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// undefined before the eager slow path applies the default). The inner
|
|
37
|
-
// fast-default expr already returns false on undefined, routing to the slow path.
|
|
38
|
-
if (innerAppliesDefaultOnUndefined(ir.inner))
|
|
39
|
-
return g.visit(ir.inner);
|
|
40
|
-
return fastSentinelWrapper(g, ir.inner, "===undefined", "||");
|
|
27
|
+
function fastOptional(ir, g) {
|
|
28
|
+
if (innerAppliesDefaultOnUndefined(ir.inner)) return g.visit(ir.inner);
|
|
29
|
+
return fastSentinelWrapper(g, ir.inner, "===undefined", "||");
|
|
41
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { fastOptional, innerAppliesDefaultOnUndefined, slowOptional };
|
|
33
|
+
|
|
42
34
|
//# sourceMappingURL=optional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.js","
|
|
1
|
+
{"version":3,"file":"optional.js","names":[],"sources":["../../../../src/core/codegen/schemas/optional.ts"],"sourcesContent":["import type { OptionalIR, SchemaIR } from \"../../types.js\";\nimport type { FastGen, SlowGen } from \"../context.js\";\nimport { fastSentinelWrapper } from \"../context.js\";\nimport { emit } from \"../emit.js\";\n\n/**\n * Zod's `.optional()` short-circuits `undefined → undefined`, EXCEPT when its\n * inner chain applies a default to undefined: `z.string().default(\"d\").optional()`\n * yields \"d\", not undefined (the default fires THROUGH the optional, and through\n * any nullable/optional wrappers between them — `default().nullish()`,\n * `default().optional().nullable()`, ...). Only `default` consumes undefined into\n * a value; `catch`, object-field defaults, and plain types do not, so the optional\n * legitimately short-circuits there. Peel optional/nullable wrappers to decide.\n */\nexport function innerAppliesDefaultOnUndefined(ir: SchemaIR): boolean {\n let cur = ir;\n while (cur.type === \"optional\" || cur.type === \"nullable\") cur = cur.inner;\n return cur.type === \"default\";\n}\n\nexport function slowOptional(ir: SchemaIR & { type: \"optional\" }, g: SlowGen): string {\n // Pass-through wrapper: forward the union abort flag (zod returns the inner\n // payload unchanged, so a pipe inner's `aborted` must reach the option).\n const fwd = { aborted: g.aborted };\n // When the inner chain handles undefined (a default), undefined must flow into\n // it so the default applies — the inner code already gates on undefined itself.\n if (innerAppliesDefaultOnUndefined(ir.inner)) {\n return `${g.visit(ir.inner, fwd)}\\n`;\n }\n return `${emit`\n if(${g.input}!==undefined){\n ${g.visit(ir.inner, fwd)}\n }\n `}\\n`;\n}\n\nexport function fastOptional(ir: OptionalIR, g: FastGen): string | null {\n // Same rule as the slow path: an inner default needs undefined to reach it, so\n // drop the `===undefined` shortcut (which would let safeParse return the raw\n // undefined before the eager slow path applies the default). The inner\n // fast-default expr already returns false on undefined, routing to the slow path.\n if (innerAppliesDefaultOnUndefined(ir.inner)) return g.visit(ir.inner);\n return fastSentinelWrapper(g, ir.inner, \"===undefined\", \"||\");\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,+BAA+B,IAAuB;CACpE,IAAI,MAAM;CACV,OAAO,IAAI,SAAS,cAAc,IAAI,SAAS,YAAY,MAAM,IAAI;CACrE,OAAO,IAAI,SAAS;AACtB;AAEA,SAAgB,aAAa,IAAqC,GAAoB;CAGpF,MAAM,MAAM,EAAE,SAAS,EAAE,QAAQ;CAGjC,IAAI,+BAA+B,GAAG,KAAK,GACzC,OAAO,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,EAAE;CAEnC,OAAO,GAAG,IAAI;SACP,EAAE,MAAM;QACT,EAAE,MAAM,GAAG,OAAO,GAAG,EAAE;;IAE3B;AACJ;AAEA,SAAgB,aAAa,IAAgB,GAA2B;CAKtE,IAAI,+BAA+B,GAAG,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;CACrE,OAAO,oBAAoB,GAAG,GAAG,OAAO,gBAAgB,IAAI;AAC9D"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { PipeIR, SchemaIR } from "../../types.js";
|
|
2
|
+
import { FastGen, SlowGen } from "../context.js";
|
|
3
|
+
//#region src/core/codegen/schemas/pipe.d.ts
|
|
4
|
+
declare function slowPipe(ir: SchemaIR & {
|
|
5
|
+
type: "pipe";
|
|
5
6
|
}, g: SlowGen): string;
|
|
6
|
-
|
|
7
|
+
declare function fastPipe(ir: PipeIR, g: FastGen): string | null;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { fastPipe, slowPipe };
|
|
7
10
|
//# sourceMappingURL=pipe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.d.ts","
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","names":[],"sources":["../../../../src/core/codegen/schemas/pipe.ts"],"mappings":";;;iBAGgB,SAAS,IAAI;EAAa;GAAgB,GAAG;iBAiB7C,SAAS,IAAI,QAAQ,GAAG"}
|