@mionjs/run-types 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/cjs/index.cjs +209 -0
- package/.dist/cjs/index.cjs.map +1 -0
- package/.dist/cjs/index.d.ts +60 -0
- package/.dist/cjs/package.json +1 -0
- package/.dist/cjs/src/constants.cjs +79 -0
- package/.dist/cjs/src/constants.cjs.map +1 -0
- package/.dist/cjs/src/constants.d.ts +7 -0
- package/.dist/cjs/src/constants.functions.cjs +181 -0
- package/.dist/cjs/src/constants.functions.cjs.map +1 -0
- package/.dist/cjs/src/constants.functions.d.ts +385 -0
- package/.dist/cjs/src/constants.kind.cjs +74 -0
- package/.dist/cjs/src/constants.kind.cjs.map +1 -0
- package/.dist/cjs/src/constants.kind.d.ts +21 -0
- package/.dist/cjs/src/createRunType.cjs +284 -0
- package/.dist/cjs/src/createRunType.cjs.map +1 -0
- package/.dist/cjs/src/createRunType.d.ts +5 -0
- package/.dist/cjs/src/createRunTypeFunctions.cjs +78 -0
- package/.dist/cjs/src/createRunTypeFunctions.cjs.map +1 -0
- package/.dist/cjs/src/createRunTypeFunctions.d.ts +12 -0
- package/.dist/cjs/src/formats.runtype.cjs +7 -0
- package/.dist/cjs/src/formats.runtype.cjs.map +1 -0
- package/.dist/cjs/src/formats.runtype.d.ts +6 -0
- package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.cjs +109 -0
- package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +30 -0
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs +383 -0
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts +7 -0
- package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs +338 -0
- package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts +7 -0
- package/.dist/cjs/src/jitCompilers/equalsHelpers.cjs +37 -0
- package/.dist/cjs/src/jitCompilers/equalsHelpers.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/equalsHelpers.d.ts +4 -0
- package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.cjs +56 -0
- package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +27 -0
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs +399 -0
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts +10 -0
- package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.cjs +51 -0
- package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +27 -0
- package/.dist/cjs/src/jitCompilers/json/toJsCode.cjs +123 -0
- package/.dist/cjs/src/jitCompilers/json/toJsCode.cjs.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/toJsCode.d.ts +5 -0
- package/.dist/cjs/src/lib/baseRunTypeFormat.cjs +200 -0
- package/.dist/cjs/src/lib/baseRunTypeFormat.cjs.map +1 -0
- package/.dist/cjs/src/lib/baseRunTypeFormat.d.ts +50 -0
- package/.dist/cjs/src/lib/baseRunTypes.cjs +308 -0
- package/.dist/cjs/src/lib/baseRunTypes.cjs.map +1 -0
- package/.dist/cjs/src/lib/baseRunTypes.d.ts +75 -0
- package/.dist/cjs/src/lib/createJitFunction.cjs +60 -0
- package/.dist/cjs/src/lib/createJitFunction.cjs.map +1 -0
- package/.dist/cjs/src/lib/createJitFunction.d.ts +5 -0
- package/.dist/cjs/src/lib/dkProxy.cjs +23 -0
- package/.dist/cjs/src/lib/dkProxy.cjs.map +1 -0
- package/.dist/cjs/src/lib/dkProxy.d.ts +4 -0
- package/.dist/cjs/src/lib/formats.cjs +89 -0
- package/.dist/cjs/src/lib/formats.cjs.map +1 -0
- package/.dist/cjs/src/lib/formats.d.ts +18 -0
- package/.dist/cjs/src/lib/guards.cjs +243 -0
- package/.dist/cjs/src/lib/guards.cjs.map +1 -0
- package/.dist/cjs/src/lib/guards.d.ts +120 -0
- package/.dist/cjs/src/lib/jitFnCompiler.cjs +648 -0
- package/.dist/cjs/src/lib/jitFnCompiler.cjs.map +1 -0
- package/.dist/cjs/src/lib/jitFnCompiler.d.ts +109 -0
- package/.dist/cjs/src/lib/jitFnsRegistry.cjs +41 -0
- package/.dist/cjs/src/lib/jitFnsRegistry.cjs.map +1 -0
- package/.dist/cjs/src/lib/jitFnsRegistry.d.ts +6 -0
- package/.dist/cjs/src/lib/typeId.cjs +205 -0
- package/.dist/cjs/src/lib/typeId.cjs.map +1 -0
- package/.dist/cjs/src/lib/typeId.d.ts +6 -0
- package/.dist/cjs/src/lib/utils.cjs +325 -0
- package/.dist/cjs/src/lib/utils.cjs.map +1 -0
- package/.dist/cjs/src/lib/utils.d.ts +32 -0
- package/.dist/cjs/src/mocking/constants.mock.cjs +108 -0
- package/.dist/cjs/src/mocking/constants.mock.cjs.map +1 -0
- package/.dist/cjs/src/mocking/constants.mock.d.ts +85 -0
- package/.dist/cjs/src/mocking/mockRegistry.cjs +12 -0
- package/.dist/cjs/src/mocking/mockRegistry.cjs.map +1 -0
- package/.dist/cjs/src/mocking/mockRegistry.d.ts +3 -0
- package/.dist/cjs/src/mocking/mockType.cjs +310 -0
- package/.dist/cjs/src/mocking/mockType.cjs.map +1 -0
- package/.dist/cjs/src/mocking/mockType.d.ts +3 -0
- package/.dist/cjs/src/mocking/mockUtils.cjs +62 -0
- package/.dist/cjs/src/mocking/mockUtils.cjs.map +1 -0
- package/.dist/cjs/src/mocking/mockUtils.d.ts +15 -0
- package/.dist/cjs/src/nodes/atomic/any.cjs +18 -0
- package/.dist/cjs/src/nodes/atomic/any.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/any.d.ts +8 -0
- package/.dist/cjs/src/nodes/atomic/bigInt.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/bigInt.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/bigInt.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/boolean.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/boolean.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/boolean.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/date.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/date.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/date.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/enum.cjs +22 -0
- package/.dist/cjs/src/nodes/atomic/enum.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/enum.d.ts +8 -0
- package/.dist/cjs/src/nodes/atomic/enumMember.cjs +24 -0
- package/.dist/cjs/src/nodes/atomic/enumMember.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/enumMember.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/literal.cjs +126 -0
- package/.dist/cjs/src/nodes/atomic/literal.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/literal.d.ts +20 -0
- package/.dist/cjs/src/nodes/atomic/never.cjs +22 -0
- package/.dist/cjs/src/nodes/atomic/never.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/never.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/null.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/null.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/null.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/number.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/number.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/number.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/object.cjs +14 -0
- package/.dist/cjs/src/nodes/atomic/object.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/object.d.ts +8 -0
- package/.dist/cjs/src/nodes/atomic/regexp.cjs +23 -0
- package/.dist/cjs/src/nodes/atomic/regexp.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/regexp.d.ts +10 -0
- package/.dist/cjs/src/nodes/atomic/string.cjs +14 -0
- package/.dist/cjs/src/nodes/atomic/string.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/string.d.ts +8 -0
- package/.dist/cjs/src/nodes/atomic/symbol.cjs +26 -0
- package/.dist/cjs/src/nodes/atomic/symbol.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/symbol.d.ts +11 -0
- package/.dist/cjs/src/nodes/atomic/undefined.cjs +17 -0
- package/.dist/cjs/src/nodes/atomic/undefined.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/undefined.d.ts +9 -0
- package/.dist/cjs/src/nodes/atomic/unknown.cjs +8 -0
- package/.dist/cjs/src/nodes/atomic/unknown.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/unknown.d.ts +3 -0
- package/.dist/cjs/src/nodes/atomic/void.cjs +20 -0
- package/.dist/cjs/src/nodes/atomic/void.cjs.map +1 -0
- package/.dist/cjs/src/nodes/atomic/void.d.ts +10 -0
- package/.dist/cjs/src/nodes/collection/class.cjs +38 -0
- package/.dist/cjs/src/nodes/collection/class.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/class.d.ts +9 -0
- package/.dist/cjs/src/nodes/collection/functionParams.cjs +33 -0
- package/.dist/cjs/src/nodes/collection/functionParams.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/functionParams.d.ts +9 -0
- package/.dist/cjs/src/nodes/collection/interface.cjs +221 -0
- package/.dist/cjs/src/nodes/collection/interface.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/interface.d.ts +43 -0
- package/.dist/cjs/src/nodes/collection/intersection.cjs +21 -0
- package/.dist/cjs/src/nodes/collection/intersection.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/intersection.d.ts +9 -0
- package/.dist/cjs/src/nodes/collection/tuple.cjs +74 -0
- package/.dist/cjs/src/nodes/collection/tuple.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/tuple.d.ts +18 -0
- package/.dist/cjs/src/nodes/collection/union.cjs +162 -0
- package/.dist/cjs/src/nodes/collection/union.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/union.d.ts +19 -0
- package/.dist/cjs/src/nodes/collection/unionDiscriminator.cjs +198 -0
- package/.dist/cjs/src/nodes/collection/unionDiscriminator.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/unionDiscriminator.d.ts +21 -0
- package/.dist/cjs/src/nodes/function/function.cjs +155 -0
- package/.dist/cjs/src/nodes/function/function.cjs.map +1 -0
- package/.dist/cjs/src/nodes/function/function.d.ts +33 -0
- package/.dist/cjs/src/nodes/member/array.cjs +154 -0
- package/.dist/cjs/src/nodes/member/array.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/array.d.ts +24 -0
- package/.dist/cjs/src/nodes/member/callSignature.cjs +40 -0
- package/.dist/cjs/src/nodes/member/callSignature.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/callSignature.d.ts +11 -0
- package/.dist/cjs/src/nodes/member/genericMember.cjs +68 -0
- package/.dist/cjs/src/nodes/member/genericMember.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/genericMember.d.ts +15 -0
- package/.dist/cjs/src/nodes/member/indexProperty.cjs +130 -0
- package/.dist/cjs/src/nodes/member/indexProperty.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/indexProperty.d.ts +21 -0
- package/.dist/cjs/src/nodes/member/method.cjs +41 -0
- package/.dist/cjs/src/nodes/member/method.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/method.d.ts +11 -0
- package/.dist/cjs/src/nodes/member/methodSignature.cjs +44 -0
- package/.dist/cjs/src/nodes/member/methodSignature.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/methodSignature.d.ts +12 -0
- package/.dist/cjs/src/nodes/member/param.cjs +17 -0
- package/.dist/cjs/src/nodes/member/param.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/param.d.ts +8 -0
- package/.dist/cjs/src/nodes/member/property.cjs +85 -0
- package/.dist/cjs/src/nodes/member/property.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/property.d.ts +19 -0
- package/.dist/cjs/src/nodes/member/restParams.cjs +15 -0
- package/.dist/cjs/src/nodes/member/restParams.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/restParams.d.ts +7 -0
- package/.dist/cjs/src/nodes/member/tupleMember.cjs +93 -0
- package/.dist/cjs/src/nodes/member/tupleMember.cjs.map +1 -0
- package/.dist/cjs/src/nodes/member/tupleMember.d.ts +20 -0
- package/.dist/cjs/src/nodes/native/Iterable.cjs +135 -0
- package/.dist/cjs/src/nodes/native/Iterable.cjs.map +1 -0
- package/.dist/cjs/src/nodes/native/Iterable.d.ts +18 -0
- package/.dist/cjs/src/nodes/native/map.cjs +96 -0
- package/.dist/cjs/src/nodes/native/map.cjs.map +1 -0
- package/.dist/cjs/src/nodes/native/map.d.ts +42 -0
- package/.dist/cjs/src/nodes/native/nonSerializable.cjs +36 -0
- package/.dist/cjs/src/nodes/native/nonSerializable.cjs.map +1 -0
- package/.dist/cjs/src/nodes/native/nonSerializable.d.ts +14 -0
- package/.dist/cjs/src/nodes/native/promise.cjs +38 -0
- package/.dist/cjs/src/nodes/native/promise.cjs.map +1 -0
- package/.dist/cjs/src/nodes/native/promise.d.ts +15 -0
- package/.dist/cjs/src/nodes/native/set.cjs +60 -0
- package/.dist/cjs/src/nodes/native/set.cjs.map +1 -0
- package/.dist/cjs/src/nodes/native/set.d.ts +30 -0
- package/.dist/cjs/src/run-types-pure-fns.cjs +112 -0
- package/.dist/cjs/src/run-types-pure-fns.cjs.map +1 -0
- package/.dist/cjs/src/run-types-pure-fns.d.ts +7 -0
- package/.dist/cjs/src/types.cjs +59 -0
- package/.dist/cjs/src/types.cjs.map +1 -0
- package/.dist/cjs/src/types.d.ts +152 -0
- package/.dist/esm/index.d.ts +60 -0
- package/.dist/esm/index.js +209 -0
- package/.dist/esm/index.js.map +1 -0
- package/.dist/esm/src/constants.d.ts +7 -0
- package/.dist/esm/src/constants.functions.d.ts +385 -0
- package/.dist/esm/src/constants.functions.js +181 -0
- package/.dist/esm/src/constants.functions.js.map +1 -0
- package/.dist/esm/src/constants.js +79 -0
- package/.dist/esm/src/constants.js.map +1 -0
- package/.dist/esm/src/constants.kind.d.ts +21 -0
- package/.dist/esm/src/constants.kind.js +74 -0
- package/.dist/esm/src/constants.kind.js.map +1 -0
- package/.dist/esm/src/createRunType.d.ts +5 -0
- package/.dist/esm/src/createRunType.js +284 -0
- package/.dist/esm/src/createRunType.js.map +1 -0
- package/.dist/esm/src/createRunTypeFunctions.d.ts +12 -0
- package/.dist/esm/src/createRunTypeFunctions.js +78 -0
- package/.dist/esm/src/createRunTypeFunctions.js.map +1 -0
- package/.dist/esm/src/formats.runtype.d.ts +6 -0
- package/.dist/esm/src/formats.runtype.js +7 -0
- package/.dist/esm/src/formats.runtype.js.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +30 -0
- package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.js +109 -0
- package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.js.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts +7 -0
- package/.dist/esm/src/jitCompilers/binary/fromBinary.js +383 -0
- package/.dist/esm/src/jitCompilers/binary/fromBinary.js.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts +7 -0
- package/.dist/esm/src/jitCompilers/binary/toBinary.js +338 -0
- package/.dist/esm/src/jitCompilers/binary/toBinary.js.map +1 -0
- package/.dist/esm/src/jitCompilers/equalsHelpers.d.ts +4 -0
- package/.dist/esm/src/jitCompilers/equalsHelpers.js +37 -0
- package/.dist/esm/src/jitCompilers/equalsHelpers.js.map +1 -0
- package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +27 -0
- package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.js +56 -0
- package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.js.map +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts +10 -0
- package/.dist/esm/src/jitCompilers/json/stringifyJson.js +399 -0
- package/.dist/esm/src/jitCompilers/json/stringifyJson.js.map +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +27 -0
- package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.js +51 -0
- package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.js.map +1 -0
- package/.dist/esm/src/jitCompilers/json/toJsCode.d.ts +5 -0
- package/.dist/esm/src/jitCompilers/json/toJsCode.js +123 -0
- package/.dist/esm/src/jitCompilers/json/toJsCode.js.map +1 -0
- package/.dist/esm/src/lib/baseRunTypeFormat.d.ts +50 -0
- package/.dist/esm/src/lib/baseRunTypeFormat.js +200 -0
- package/.dist/esm/src/lib/baseRunTypeFormat.js.map +1 -0
- package/.dist/esm/src/lib/baseRunTypes.d.ts +75 -0
- package/.dist/esm/src/lib/baseRunTypes.js +308 -0
- package/.dist/esm/src/lib/baseRunTypes.js.map +1 -0
- package/.dist/esm/src/lib/createJitFunction.d.ts +5 -0
- package/.dist/esm/src/lib/createJitFunction.js +60 -0
- package/.dist/esm/src/lib/createJitFunction.js.map +1 -0
- package/.dist/esm/src/lib/dkProxy.d.ts +4 -0
- package/.dist/esm/src/lib/dkProxy.js +23 -0
- package/.dist/esm/src/lib/dkProxy.js.map +1 -0
- package/.dist/esm/src/lib/formats.d.ts +18 -0
- package/.dist/esm/src/lib/formats.js +89 -0
- package/.dist/esm/src/lib/formats.js.map +1 -0
- package/.dist/esm/src/lib/guards.d.ts +120 -0
- package/.dist/esm/src/lib/guards.js +243 -0
- package/.dist/esm/src/lib/guards.js.map +1 -0
- package/.dist/esm/src/lib/jitFnCompiler.d.ts +109 -0
- package/.dist/esm/src/lib/jitFnCompiler.js +648 -0
- package/.dist/esm/src/lib/jitFnCompiler.js.map +1 -0
- package/.dist/esm/src/lib/jitFnsRegistry.d.ts +6 -0
- package/.dist/esm/src/lib/jitFnsRegistry.js +41 -0
- package/.dist/esm/src/lib/jitFnsRegistry.js.map +1 -0
- package/.dist/esm/src/lib/typeId.d.ts +6 -0
- package/.dist/esm/src/lib/typeId.js +205 -0
- package/.dist/esm/src/lib/typeId.js.map +1 -0
- package/.dist/esm/src/lib/utils.d.ts +32 -0
- package/.dist/esm/src/lib/utils.js +325 -0
- package/.dist/esm/src/lib/utils.js.map +1 -0
- package/.dist/esm/src/mocking/constants.mock.d.ts +85 -0
- package/.dist/esm/src/mocking/constants.mock.js +108 -0
- package/.dist/esm/src/mocking/constants.mock.js.map +1 -0
- package/.dist/esm/src/mocking/mockRegistry.d.ts +3 -0
- package/.dist/esm/src/mocking/mockRegistry.js +12 -0
- package/.dist/esm/src/mocking/mockRegistry.js.map +1 -0
- package/.dist/esm/src/mocking/mockType.d.ts +3 -0
- package/.dist/esm/src/mocking/mockType.js +310 -0
- package/.dist/esm/src/mocking/mockType.js.map +1 -0
- package/.dist/esm/src/mocking/mockUtils.d.ts +15 -0
- package/.dist/esm/src/mocking/mockUtils.js +62 -0
- package/.dist/esm/src/mocking/mockUtils.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/any.d.ts +8 -0
- package/.dist/esm/src/nodes/atomic/any.js +18 -0
- package/.dist/esm/src/nodes/atomic/any.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/bigInt.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/bigInt.js +20 -0
- package/.dist/esm/src/nodes/atomic/bigInt.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/boolean.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/boolean.js +20 -0
- package/.dist/esm/src/nodes/atomic/boolean.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/date.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/date.js +20 -0
- package/.dist/esm/src/nodes/atomic/date.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/enum.d.ts +8 -0
- package/.dist/esm/src/nodes/atomic/enum.js +22 -0
- package/.dist/esm/src/nodes/atomic/enum.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/enumMember.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/enumMember.js +24 -0
- package/.dist/esm/src/nodes/atomic/enumMember.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/literal.d.ts +20 -0
- package/.dist/esm/src/nodes/atomic/literal.js +126 -0
- package/.dist/esm/src/nodes/atomic/literal.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/never.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/never.js +22 -0
- package/.dist/esm/src/nodes/atomic/never.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/null.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/null.js +20 -0
- package/.dist/esm/src/nodes/atomic/null.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/number.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/number.js +20 -0
- package/.dist/esm/src/nodes/atomic/number.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/object.d.ts +8 -0
- package/.dist/esm/src/nodes/atomic/object.js +14 -0
- package/.dist/esm/src/nodes/atomic/object.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/regexp.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/regexp.js +23 -0
- package/.dist/esm/src/nodes/atomic/regexp.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/string.d.ts +8 -0
- package/.dist/esm/src/nodes/atomic/string.js +14 -0
- package/.dist/esm/src/nodes/atomic/string.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/symbol.d.ts +11 -0
- package/.dist/esm/src/nodes/atomic/symbol.js +26 -0
- package/.dist/esm/src/nodes/atomic/symbol.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/undefined.d.ts +9 -0
- package/.dist/esm/src/nodes/atomic/undefined.js +17 -0
- package/.dist/esm/src/nodes/atomic/undefined.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/unknown.d.ts +3 -0
- package/.dist/esm/src/nodes/atomic/unknown.js +8 -0
- package/.dist/esm/src/nodes/atomic/unknown.js.map +1 -0
- package/.dist/esm/src/nodes/atomic/void.d.ts +10 -0
- package/.dist/esm/src/nodes/atomic/void.js +20 -0
- package/.dist/esm/src/nodes/atomic/void.js.map +1 -0
- package/.dist/esm/src/nodes/collection/class.d.ts +9 -0
- package/.dist/esm/src/nodes/collection/class.js +38 -0
- package/.dist/esm/src/nodes/collection/class.js.map +1 -0
- package/.dist/esm/src/nodes/collection/functionParams.d.ts +9 -0
- package/.dist/esm/src/nodes/collection/functionParams.js +33 -0
- package/.dist/esm/src/nodes/collection/functionParams.js.map +1 -0
- package/.dist/esm/src/nodes/collection/interface.d.ts +43 -0
- package/.dist/esm/src/nodes/collection/interface.js +221 -0
- package/.dist/esm/src/nodes/collection/interface.js.map +1 -0
- package/.dist/esm/src/nodes/collection/intersection.d.ts +9 -0
- package/.dist/esm/src/nodes/collection/intersection.js +21 -0
- package/.dist/esm/src/nodes/collection/intersection.js.map +1 -0
- package/.dist/esm/src/nodes/collection/tuple.d.ts +18 -0
- package/.dist/esm/src/nodes/collection/tuple.js +74 -0
- package/.dist/esm/src/nodes/collection/tuple.js.map +1 -0
- package/.dist/esm/src/nodes/collection/union.d.ts +19 -0
- package/.dist/esm/src/nodes/collection/union.js +162 -0
- package/.dist/esm/src/nodes/collection/union.js.map +1 -0
- package/.dist/esm/src/nodes/collection/unionDiscriminator.d.ts +21 -0
- package/.dist/esm/src/nodes/collection/unionDiscriminator.js +198 -0
- package/.dist/esm/src/nodes/collection/unionDiscriminator.js.map +1 -0
- package/.dist/esm/src/nodes/function/function.d.ts +33 -0
- package/.dist/esm/src/nodes/function/function.js +155 -0
- package/.dist/esm/src/nodes/function/function.js.map +1 -0
- package/.dist/esm/src/nodes/member/array.d.ts +24 -0
- package/.dist/esm/src/nodes/member/array.js +154 -0
- package/.dist/esm/src/nodes/member/array.js.map +1 -0
- package/.dist/esm/src/nodes/member/callSignature.d.ts +11 -0
- package/.dist/esm/src/nodes/member/callSignature.js +40 -0
- package/.dist/esm/src/nodes/member/callSignature.js.map +1 -0
- package/.dist/esm/src/nodes/member/genericMember.d.ts +15 -0
- package/.dist/esm/src/nodes/member/genericMember.js +68 -0
- package/.dist/esm/src/nodes/member/genericMember.js.map +1 -0
- package/.dist/esm/src/nodes/member/indexProperty.d.ts +21 -0
- package/.dist/esm/src/nodes/member/indexProperty.js +130 -0
- package/.dist/esm/src/nodes/member/indexProperty.js.map +1 -0
- package/.dist/esm/src/nodes/member/method.d.ts +11 -0
- package/.dist/esm/src/nodes/member/method.js +41 -0
- package/.dist/esm/src/nodes/member/method.js.map +1 -0
- package/.dist/esm/src/nodes/member/methodSignature.d.ts +12 -0
- package/.dist/esm/src/nodes/member/methodSignature.js +44 -0
- package/.dist/esm/src/nodes/member/methodSignature.js.map +1 -0
- package/.dist/esm/src/nodes/member/param.d.ts +8 -0
- package/.dist/esm/src/nodes/member/param.js +17 -0
- package/.dist/esm/src/nodes/member/param.js.map +1 -0
- package/.dist/esm/src/nodes/member/property.d.ts +19 -0
- package/.dist/esm/src/nodes/member/property.js +85 -0
- package/.dist/esm/src/nodes/member/property.js.map +1 -0
- package/.dist/esm/src/nodes/member/restParams.d.ts +7 -0
- package/.dist/esm/src/nodes/member/restParams.js +15 -0
- package/.dist/esm/src/nodes/member/restParams.js.map +1 -0
- package/.dist/esm/src/nodes/member/tupleMember.d.ts +20 -0
- package/.dist/esm/src/nodes/member/tupleMember.js +93 -0
- package/.dist/esm/src/nodes/member/tupleMember.js.map +1 -0
- package/.dist/esm/src/nodes/native/Iterable.d.ts +18 -0
- package/.dist/esm/src/nodes/native/Iterable.js +135 -0
- package/.dist/esm/src/nodes/native/Iterable.js.map +1 -0
- package/.dist/esm/src/nodes/native/map.d.ts +42 -0
- package/.dist/esm/src/nodes/native/map.js +96 -0
- package/.dist/esm/src/nodes/native/map.js.map +1 -0
- package/.dist/esm/src/nodes/native/nonSerializable.d.ts +14 -0
- package/.dist/esm/src/nodes/native/nonSerializable.js +36 -0
- package/.dist/esm/src/nodes/native/nonSerializable.js.map +1 -0
- package/.dist/esm/src/nodes/native/promise.d.ts +15 -0
- package/.dist/esm/src/nodes/native/promise.js +38 -0
- package/.dist/esm/src/nodes/native/promise.js.map +1 -0
- package/.dist/esm/src/nodes/native/set.d.ts +30 -0
- package/.dist/esm/src/nodes/native/set.js +60 -0
- package/.dist/esm/src/nodes/native/set.js.map +1 -0
- package/.dist/esm/src/run-types-pure-fns.d.ts +7 -0
- package/.dist/esm/src/run-types-pure-fns.js +112 -0
- package/.dist/esm/src/run-types-pure-fns.js.map +1 -0
- package/.dist/esm/src/types.d.ts +152 -0
- package/.dist/esm/src/types.js +59 -0
- package/.dist/esm/src/types.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/package.json +66 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const src_nodes_collection_tuple = require("./tuple.cjs");
|
|
4
|
+
const src_nodes_member_param = require("../member/param.cjs");
|
|
5
|
+
function __assignType(fn, args) {
|
|
6
|
+
fn.__type = args;
|
|
7
|
+
return fn;
|
|
8
|
+
}
|
|
9
|
+
class FunctionParamsRunType extends src_nodes_collection_tuple.TupleRunType {
|
|
10
|
+
emitIsType(comp) {
|
|
11
|
+
const children = this.getParamRunTypes(comp);
|
|
12
|
+
if (children.length === 0)
|
|
13
|
+
return { code: `${comp.vλl}.length === 0`, type: "E" };
|
|
14
|
+
const lengthCode = this.hasRestParameter(comp) ? "" : `${comp.vλl}.length <= ${children.length}`;
|
|
15
|
+
const paramsCode = children.map(__assignType((p) => comp.compileIsType(p, "E").code, ["p", "", 'P"2!"/"'])).filter(Boolean);
|
|
16
|
+
if (paramsCode.length === 0)
|
|
17
|
+
return lengthCode ? { code: `(${lengthCode})`, type: "E" } : { code: void 0, type: "E" };
|
|
18
|
+
return lengthCode ? { code: `(${lengthCode} && ${paramsCode.join(" && ")})`, type: "E" } : { code: `(${paramsCode.join(" && ")})`, type: "E" };
|
|
19
|
+
}
|
|
20
|
+
emitTypeErrors(comp) {
|
|
21
|
+
const children = this.getParamRunTypes(comp);
|
|
22
|
+
if (children.length === 0)
|
|
23
|
+
return { code: `if (${comp.vλl}.length !== 0) ${comp.callJitErr(this)}`, type: "S" };
|
|
24
|
+
const lengthCode = this.hasRestParameter(comp) ? "" : `${comp.vλl}.length > ${children.length}`;
|
|
25
|
+
const paramsCode = children.map(__assignType((p) => comp.compileTypeErrors(p, "S").code, ["p", "", 'P"2!"/"'])).filter(Boolean);
|
|
26
|
+
if (paramsCode.length === 0)
|
|
27
|
+
return lengthCode ? { code: `if (${lengthCode}) ${comp.callJitErr(this)}`, type: "S" } : { code: void 0, type: "S" };
|
|
28
|
+
return lengthCode ? { code: `if (${lengthCode}) ${comp.callJitErr(this)}; else {${paramsCode.join(";")}}`, type: "S" } : { code: paramsCode.join(";"), type: "S" };
|
|
29
|
+
}
|
|
30
|
+
static __type = ["TypeFunction", "ParamList", () => src_nodes_member_param.ParameterRunType, () => src_nodes_collection_tuple.TupleRunType, "JitFnCompiler", "comp", "JitCode", "emitIsType", "JitErrorsFnCompiler", "emitTypeErrors", () => src_nodes_member_param.ParameterRunType, "FunctionParamsRunType", `"w!c"Pe"!P7#7$P"w%2&"w'0(P"w)2&"w'0*5e!!P7+6#w,`];
|
|
31
|
+
}
|
|
32
|
+
exports.FunctionParamsRunType = FunctionParamsRunType;
|
|
33
|
+
//# sourceMappingURL=functionParams.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functionParams.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TypeFunction } from '@deepkit/type';
|
|
2
|
+
import { JitFnCompiler, JitErrorsFnCompiler } from '../../lib/jitFnCompiler.ts';
|
|
3
|
+
import { AnyParameterListRunType, JitCode } from '../../types.ts';
|
|
4
|
+
import { TupleRunType } from './tuple.ts';
|
|
5
|
+
import { ParameterRunType } from '../member/param.ts';
|
|
6
|
+
export declare class FunctionParamsRunType<ParamList extends AnyParameterListRunType = TypeFunction> extends TupleRunType<ParamList, ParameterRunType> {
|
|
7
|
+
emitIsType(comp: JitFnCompiler): JitCode;
|
|
8
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode;
|
|
9
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const type = require("@deepkit/type");
|
|
4
|
+
const src_lib_utils = require("../../lib/utils.cjs");
|
|
5
|
+
const src_nodes_member_property = require("../member/property.cjs");
|
|
6
|
+
const src_lib_baseRunTypes = require("../../lib/baseRunTypes.cjs");
|
|
7
|
+
const src_nodes_member_methodSignature = require("../member/methodSignature.cjs");
|
|
8
|
+
const src_nodes_member_indexProperty = require("../member/indexProperty.cjs");
|
|
9
|
+
const src_nodes_member_method = require("../member/method.cjs");
|
|
10
|
+
const src_nodes_member_callSignature = require("../member/callSignature.cjs");
|
|
11
|
+
const src_constants_functions = require("../../constants.functions.cjs");
|
|
12
|
+
const src_lib_guards = require("../../lib/guards.cjs");
|
|
13
|
+
const src_runTypesPureFns = require("../../run-types-pure-fns.cjs");
|
|
14
|
+
function __assignType(fn, args) {
|
|
15
|
+
fn.__type = args;
|
|
16
|
+
return fn;
|
|
17
|
+
}
|
|
18
|
+
const __ΩInterfaceMember = [() => src_nodes_member_property.PropertyRunType, () => src_nodes_member_methodSignature.MethodSignatureRunType, () => src_nodes_member_indexProperty.IndexSignatureRunType, () => src_nodes_member_method.MethodRunType, () => src_nodes_member_callSignature.CallSignatureRunType, "InterfaceMember", 'PP7!P7"P7#P7$P7%Jw&y'];
|
|
19
|
+
class InterfaceRunType extends src_lib_baseRunTypes.CollectionRunType {
|
|
20
|
+
getNamedChildren(comp) {
|
|
21
|
+
return this.getJitChildren(comp).filter(__assignType((prop) => !!prop.src.name, ["prop", "", 'P"2!"/"']));
|
|
22
|
+
}
|
|
23
|
+
isCallable() {
|
|
24
|
+
return this.getCallSignature() !== void 0;
|
|
25
|
+
}
|
|
26
|
+
getCallSignature = src_lib_utils.memorize(__assignType(() => {
|
|
27
|
+
return this.getChildRunTypes().find(__assignType((prop) => prop.src.kind === type.ReflectionKind.callSignature, ["prop", "", 'P"2!"/"']));
|
|
28
|
+
}, [() => src_nodes_member_callSignature.CallSignatureRunType, "", 'PPP7!-J/"']));
|
|
29
|
+
getJitChildren(comp) {
|
|
30
|
+
const children = super.getJitChildren(comp);
|
|
31
|
+
return children.toSorted(__assignType((a, b) => src_lib_utils.sortDiscriminatorsFirst(a, b), ["a", "b", "", 'P"2!"2""/#']));
|
|
32
|
+
}
|
|
33
|
+
/** Split children in two groups: required and optional */
|
|
34
|
+
splitJitSplitChildren(comp) {
|
|
35
|
+
const children = super.getJitChildren(comp);
|
|
36
|
+
const required = children.filter(__assignType((prop) => !prop.isOptional(), ["prop", "", 'P"2!"/"']));
|
|
37
|
+
const optional = children.filter(__assignType((prop) => prop.isOptional() && !src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
38
|
+
const indexSignatures = children.filter(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
39
|
+
return { required, optional, indexSignatures };
|
|
40
|
+
}
|
|
41
|
+
isPartOfUnion() {
|
|
42
|
+
return this.getParent()?.src.kind === type.ReflectionKind.union;
|
|
43
|
+
}
|
|
44
|
+
hasIndexSignature(comp) {
|
|
45
|
+
return this.getJitChildren(comp).some(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
46
|
+
}
|
|
47
|
+
// #### collection's jit code ####
|
|
48
|
+
emitIsType(comp) {
|
|
49
|
+
const varName = comp.vλl;
|
|
50
|
+
const children = this.getJitChildren(comp);
|
|
51
|
+
const childrenCode = children.map(__assignType((prop) => comp.compileIsType(prop, "E").code, ["prop", "", 'P"2!"/"'])).filter(Boolean).join(" && ");
|
|
52
|
+
if (this.isCallable())
|
|
53
|
+
return {
|
|
54
|
+
code: [this.getCallSignature().emitIsType(comp).code, childrenCode].filter(Boolean).join(" && "),
|
|
55
|
+
type: "E"
|
|
56
|
+
};
|
|
57
|
+
const objectCheck = this.isPartOfUnion() ? "" : `typeof ${varName} === 'object' && ${varName} !== null`;
|
|
58
|
+
const itemsCode = [objectCheck, this.allOptionalCode(comp), childrenCode].filter(Boolean).join(" && ");
|
|
59
|
+
return { code: `(${itemsCode})`, type: "E" };
|
|
60
|
+
}
|
|
61
|
+
emitTypeErrors(comp) {
|
|
62
|
+
const varName = comp.vλl;
|
|
63
|
+
const children = this.getJitChildren(comp);
|
|
64
|
+
const childrenCode = children.map(__assignType((prop) => comp.compileTypeErrors(prop, "S").code, ["prop", "", 'P"2!"/"'])).filter(Boolean).join(";");
|
|
65
|
+
if (this.isCallable()) {
|
|
66
|
+
return { code: `${this.getCallSignature().emitTypeErrors(comp).code} else {${childrenCode}}`, type: "S" };
|
|
67
|
+
}
|
|
68
|
+
const objectCheck = this.isPartOfUnion() ? "" : `typeof ${varName} === 'object' && ${varName} !== null`;
|
|
69
|
+
const isObjectCode = [objectCheck, this.allOptionalCode(comp)].filter(Boolean).join(" && ");
|
|
70
|
+
return {
|
|
71
|
+
code: `
|
|
72
|
+
if (!(${isObjectCode})) {
|
|
73
|
+
${comp.callJitErr(this)};
|
|
74
|
+
} else {
|
|
75
|
+
${childrenCode}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
type: "S"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
emitPrepareForJson(comp) {
|
|
82
|
+
if (this.isCallable())
|
|
83
|
+
return this.getCallSignature().emitPrepareForJson();
|
|
84
|
+
const children = this.getJitChildren(comp);
|
|
85
|
+
const childrenCode = children.map(__assignType((prop) => comp.compilePrepareForJson(prop, "S").code, ["prop", "", 'P"2!"/"'])).filter(Boolean).join(";");
|
|
86
|
+
return { code: childrenCode, type: "S" };
|
|
87
|
+
}
|
|
88
|
+
emitRestoreFromJson(comp) {
|
|
89
|
+
if (this.isCallable())
|
|
90
|
+
return this.getCallSignature().emitRestoreFromJson();
|
|
91
|
+
const children = this.getJitChildren(comp);
|
|
92
|
+
const childrenCode = children.map(__assignType((prop) => comp.compileRestoreFromJson(prop, "S").code, ["prop", "", 'P"2!"/"'])).filter(Boolean).join(";");
|
|
93
|
+
return { code: childrenCode, type: "S" };
|
|
94
|
+
}
|
|
95
|
+
emitHasUnknownKeys(comp) {
|
|
96
|
+
const children = this.getJitChildren(comp);
|
|
97
|
+
const allChildren = this.getChildRunTypes().filter(__assignType((prop) => !src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
98
|
+
const hasIndexProp = children.some(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
99
|
+
const parentCode = hasIndexProp ? "" : callCheckUnknownProperties(this, comp, children, false, !this.isPartOfUnion(), allChildren);
|
|
100
|
+
const childrenCode = super.emitHasUnknownKeys(comp).code;
|
|
101
|
+
return { code: [parentCode, childrenCode].filter(Boolean).join(" || "), type: "E" };
|
|
102
|
+
}
|
|
103
|
+
emitUnknownKeyErrors(comp) {
|
|
104
|
+
const children = this.getJitChildren(comp);
|
|
105
|
+
const allChildren = this.getChildRunTypes().filter(__assignType((prop) => !src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
106
|
+
const hasIndexProp = children.some(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
107
|
+
const unknownVar = comp.getLocalVarName("unk", this);
|
|
108
|
+
const keyVar = comp.getLocalVarName("ky", this);
|
|
109
|
+
const unknownValue = hasIndexProp ? void 0 : callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion(), allChildren);
|
|
110
|
+
const parentCode = `
|
|
111
|
+
const ${unknownVar} = ${unknownValue};
|
|
112
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}) {${comp.callJitErrWithPath("never", keyVar)}}}
|
|
113
|
+
`;
|
|
114
|
+
const childrenCode = super.emitUnknownKeyErrors(comp).code;
|
|
115
|
+
return { code: [unknownValue ? parentCode : "", childrenCode].filter(Boolean).join("\n"), type: "S" };
|
|
116
|
+
}
|
|
117
|
+
emitStripUnknownKeys(comp) {
|
|
118
|
+
const children = this.getJitChildren(comp);
|
|
119
|
+
const unknownVar = comp.getLocalVarName("unk", this);
|
|
120
|
+
const keyVar = comp.getLocalVarName("ky", this);
|
|
121
|
+
const hasIndexProp = children.some(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
122
|
+
const unknownValue = hasIndexProp ? void 0 : callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion());
|
|
123
|
+
const parentCode = `
|
|
124
|
+
const ${unknownVar} = ${unknownValue};
|
|
125
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}){delete ${comp.vλl}[${keyVar}]}}
|
|
126
|
+
`;
|
|
127
|
+
const childrenCode = super.emitStripUnknownKeys(comp).code;
|
|
128
|
+
return { code: [unknownValue ? parentCode : "", childrenCode].filter(Boolean).join("\n"), type: "S" };
|
|
129
|
+
}
|
|
130
|
+
emitUnknownKeysToUndefined(comp) {
|
|
131
|
+
const children = this.getJitChildren(comp);
|
|
132
|
+
const unknownVar = comp.getLocalVarName("unk", this);
|
|
133
|
+
const keyVar = comp.getLocalVarName("ky", this);
|
|
134
|
+
const hasIndexProp = children.some(__assignType((prop) => src_lib_guards.isIndexSignatureRunType(prop), ["prop", "", 'P"2!"/"']));
|
|
135
|
+
const unknownValue = hasIndexProp ? void 0 : callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion());
|
|
136
|
+
const parentCode = `
|
|
137
|
+
const ${unknownVar} = ${unknownValue};
|
|
138
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}){${comp.vλl}[${keyVar}] = undefined}}
|
|
139
|
+
`;
|
|
140
|
+
const childrenCode = super.emitUnknownKeysToUndefined(comp).code;
|
|
141
|
+
return { code: [unknownValue ? parentCode : "", childrenCode].filter(Boolean).join("\n"), type: "S" };
|
|
142
|
+
}
|
|
143
|
+
// In order to json stringify to work properly optional properties must come first
|
|
144
|
+
getJsonStringifySortedChildren(comp) {
|
|
145
|
+
return this.getJitChildren(comp).toSorted(__assignType((a, b) => {
|
|
146
|
+
const aOptional = a instanceof src_lib_baseRunTypes.MemberRunType && a.isOptional();
|
|
147
|
+
const bOptional = b instanceof src_lib_baseRunTypes.MemberRunType && b.isOptional();
|
|
148
|
+
if (aOptional && !bOptional)
|
|
149
|
+
return -1;
|
|
150
|
+
if (!aOptional && bOptional)
|
|
151
|
+
return 1;
|
|
152
|
+
return 0;
|
|
153
|
+
}, ["a", "b", "", 'P"2!"2""/#']));
|
|
154
|
+
}
|
|
155
|
+
// extra check to prevent empty array passing as object where all properties are optional
|
|
156
|
+
// when this check is disabled empty array will pass as object but fail when checking for properties
|
|
157
|
+
allOptionalCode(comp) {
|
|
158
|
+
const children = this.getJitChildren(comp);
|
|
159
|
+
if (children.length !== 0 && !this.areAllChildrenOptional(children))
|
|
160
|
+
return "";
|
|
161
|
+
const isNotArray = `!Array.isArray(${comp.vλl})`;
|
|
162
|
+
const ifNoNative = `Object.prototype.toString.call(${comp.vλl}) === '[object Object]'`;
|
|
163
|
+
return `(${isNotArray} && ${ifNoNative})`;
|
|
164
|
+
}
|
|
165
|
+
addObjectPropsToContext(comp, jitChildrenRunTypes, allChildrenRuntypes) {
|
|
166
|
+
const children = jitChildrenRunTypes || this.getJitChildren(comp);
|
|
167
|
+
const allChildren = allChildrenRuntypes || this.getChildRunTypes();
|
|
168
|
+
return addObjectPropsToContext(this, comp, children, allChildren);
|
|
169
|
+
}
|
|
170
|
+
static __type = [() => type.__ΩTypeObjectLiteral, "T", () => src_lib_baseRunTypes.CollectionRunType, "JitFnCompiler", "comp", () => __ΩInterfaceMember, "getNamedChildren", "isCallable", "getCallSignature", function() {
|
|
171
|
+
return src_lib_utils.memorize(__assignType(() => {
|
|
172
|
+
return this.getChildRunTypes().find(__assignType((prop) => prop.src.kind === type.ReflectionKind.callSignature, ["prop", "", 'P"2!"/"']));
|
|
173
|
+
}, [() => src_nodes_member_callSignature.CallSignatureRunType, "", 'PPP7!-J/"']));
|
|
174
|
+
}, () => __ΩInterfaceMember, "getJitChildren", () => src_nodes_member_property.PropertyRunType, "required", () => src_nodes_member_property.PropertyRunType, "optional", () => src_nodes_member_indexProperty.IndexSignatureRunType, "indexSignatures", "splitJitSplitChildren", "isPartOfUnion", "hasIndexSignature", "JitCode", "emitIsType", "JitErrorsFnCompiler", "emitTypeErrors", "emitPrepareForJson", "emitRestoreFromJson", "emitHasUnknownKeys", "emitUnknownKeyErrors", "emitStripUnknownKeys", "emitUnknownKeysToUndefined", () => src_lib_baseRunTypes.MemberRunType, "getJsonStringifySortedChildren", "allOptionalCode", () => src_lib_baseRunTypes.BaseRunType, "jitChildrenRunTypes", () => src_lib_baseRunTypes.BaseRunType, "allChildrenRuntypes", "addObjectPropsToContext", "InterfaceRunType", `n!c"Pe"!7#P"w$2%n&F0'P)0(!3)>*P"w$2%n+F0,P"w$2%PP7-F4.P7/F40P71F42M03P)04P"w$2%)05P"w$2%"w607P"w82%"w609P"w$2%"w60:P"w$2%"w60;P"w$2%"w60<P"w82%"w60=P"w$2%"w60>P"w$2%"w60?P"w$2%P"7@F0AP"w$2%&0BP"w$2%P7CF2D8P7EF2F8"0G5e!!6"wH`];
|
|
175
|
+
}
|
|
176
|
+
const __ΩObjectPropsContextResult = ["keysName", "allKeysName", "hasNonJitChildren", "jitChildrenNames", "allChildrenNames", "ObjectPropsContextResult", 'P&4!&4")4#&F4$&F4%Mw&y'];
|
|
177
|
+
function addObjectPropsToContext(rt, comp, jitChildrenRunTypes, allChildrenRuntypes) {
|
|
178
|
+
const jitArrNames = jitChildrenRunTypes.filter(__assignType((prop) => !!prop.src.name, ["prop", "", 'P"2!"/"'])).map(__assignType((prop) => prop.src.name, ["prop", "", 'P"2!"/"']));
|
|
179
|
+
const AllArrNames = allChildrenRuntypes?.filter(__assignType((prop) => !!prop.src.name, ["prop", "", 'P"2!"/"'])).map(__assignType((prop) => prop.src.name, ["prop", "", 'P"2!"/"']));
|
|
180
|
+
const jitChildrenNames = Array.from(new Set(jitArrNames));
|
|
181
|
+
const allChildrenNames = Array.from(new Set(AllArrNames));
|
|
182
|
+
const isSameLength = jitChildrenNames.length === allChildrenNames.length;
|
|
183
|
+
const isSameSet = isSameLength && jitChildrenNames.every(__assignType((v) => allChildrenNames.includes(v), ["v", "", 'P"2!"/"']));
|
|
184
|
+
const hasNonJitChildren = !(isSameLength && isSameSet);
|
|
185
|
+
const keysName = `k_${rt.getJitHash(comp.opts)}`;
|
|
186
|
+
const allKeysName = `kA_${rt.getJitHash(comp.opts)}`;
|
|
187
|
+
comp.setContextItem(keysName, `const ${keysName} = ${src_lib_utils.arrayToLiteral(jitChildrenNames)}`);
|
|
188
|
+
if (hasNonJitChildren)
|
|
189
|
+
comp.setContextItem(allKeysName, `const ${allKeysName} = ${src_lib_utils.arrayToLiteral(allChildrenNames)}`);
|
|
190
|
+
return {
|
|
191
|
+
keysName,
|
|
192
|
+
allKeysName,
|
|
193
|
+
hasNonJitChildren,
|
|
194
|
+
jitChildrenNames,
|
|
195
|
+
allChildrenNames
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
addObjectPropsToContext.__type = [() => InterfaceRunType, "rt", "JitFnCompiler", "comp", () => src_lib_baseRunTypes.BaseRunType, "jitChildrenRunTypes", () => src_lib_baseRunTypes.BaseRunType, "allChildrenRuntypes", () => __ΩObjectPropsContextResult, "addObjectPropsToContext", `PP"7!2""w#2$P7%F2&P7'F2(8n)/*`];
|
|
199
|
+
function callCheckUnknownProperties(rt, comp, jitChildrenRunTypes, returnKeys, checkObject = true, allChildrenRuntypes) {
|
|
200
|
+
const result = addObjectPropsToContext(rt, comp, jitChildrenRunTypes, allChildrenRuntypes);
|
|
201
|
+
if (result.jitChildrenNames.length === 0 && result.allChildrenNames.length === 0)
|
|
202
|
+
return "";
|
|
203
|
+
const objectCheckCode = checkObject ? [`typeof ${comp.vλl} === 'object'`, `${comp.vλl} !== null`] : [];
|
|
204
|
+
const checkPropName = src_constants_functions.JitFunctions.hasUnknownKeys.runTimeOptions.checkNonJitProps.keyName;
|
|
205
|
+
const optsVarName = src_lib_utils.getJitFnArgCallVarName(comp, rt, src_constants_functions.JitFunctions.hasUnknownKeys.id, "θpts");
|
|
206
|
+
const conditional = allChildrenRuntypes?.length && result.hasNonJitChildren ? `${optsVarName}.${checkPropName} ? ${result.allKeysName} : ${result.keysName}` : result.keysName;
|
|
207
|
+
const getUnknownKeysFn = comp.addPureFunction(src_runTypesPureFns.cpf_getUnknownKeysFromArray);
|
|
208
|
+
const hasUnknownKeysFn = comp.addPureFunction(src_runTypesPureFns.cpf_hasUnknownKeysFromArray);
|
|
209
|
+
if (returnKeys)
|
|
210
|
+
return `${getUnknownKeysFn}(${comp.vλl}, ${conditional})`;
|
|
211
|
+
objectCheckCode.push(`${hasUnknownKeysFn}(${comp.vλl}, ${conditional})`);
|
|
212
|
+
const filtered = objectCheckCode.filter(Boolean);
|
|
213
|
+
if (filtered.length > 1)
|
|
214
|
+
return `(${filtered.join(" && ")})`;
|
|
215
|
+
return filtered[0];
|
|
216
|
+
}
|
|
217
|
+
callCheckUnknownProperties.__type = [() => InterfaceRunType, "rt", "JitFnCompiler", "comp", () => src_lib_baseRunTypes.BaseRunType, "jitChildrenRunTypes", "returnKeys", "checkObject", () => src_lib_baseRunTypes.BaseRunType, "allChildrenRuntypes", "callCheckUnknownProperties", `PP"7!2""w#2$P7%F2&)2'"2(P7)F2*8&/+`];
|
|
218
|
+
exports.InterfaceRunType = InterfaceRunType;
|
|
219
|
+
exports.__ΩInterfaceMember = __ΩInterfaceMember;
|
|
220
|
+
exports.__ΩObjectPropsContextResult = __ΩObjectPropsContextResult;
|
|
221
|
+
//# sourceMappingURL=interface.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TypeObjectLiteral, TypeClass, TypeIntersection } from '@deepkit/type';
|
|
2
|
+
import { JitCode } from '../../types.ts';
|
|
3
|
+
import { JitFnCompiler, JitErrorsFnCompiler } from '../../lib/jitFnCompiler.ts';
|
|
4
|
+
import { PropertyRunType } from '../member/property.ts';
|
|
5
|
+
import { BaseRunType, CollectionRunType, MemberRunType } from '../../lib/baseRunTypes.ts';
|
|
6
|
+
import { MethodSignatureRunType } from '../member/methodSignature.ts';
|
|
7
|
+
import { IndexSignatureRunType } from '../member/indexProperty.ts';
|
|
8
|
+
import { MethodRunType } from '../member/method.ts';
|
|
9
|
+
import { CallSignatureRunType } from '../member/callSignature.ts';
|
|
10
|
+
export type InterfaceMember = PropertyRunType | MethodSignatureRunType | IndexSignatureRunType | MethodRunType | CallSignatureRunType;
|
|
11
|
+
export declare class InterfaceRunType<T extends TypeObjectLiteral | TypeClass | TypeIntersection = TypeObjectLiteral> extends CollectionRunType<T> {
|
|
12
|
+
getNamedChildren(comp: JitFnCompiler): InterfaceMember[];
|
|
13
|
+
isCallable(): boolean;
|
|
14
|
+
getCallSignature: () => CallSignatureRunType | undefined;
|
|
15
|
+
getJitChildren(comp: JitFnCompiler): InterfaceMember[];
|
|
16
|
+
splitJitSplitChildren(comp: JitFnCompiler): {
|
|
17
|
+
required: PropertyRunType[];
|
|
18
|
+
optional: PropertyRunType[];
|
|
19
|
+
indexSignatures: IndexSignatureRunType[];
|
|
20
|
+
};
|
|
21
|
+
isPartOfUnion(): boolean;
|
|
22
|
+
hasIndexSignature(comp: JitFnCompiler): boolean;
|
|
23
|
+
emitIsType(comp: JitFnCompiler): JitCode;
|
|
24
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode;
|
|
25
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode;
|
|
26
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode;
|
|
27
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode;
|
|
28
|
+
emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode;
|
|
29
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode;
|
|
30
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode;
|
|
31
|
+
getJsonStringifySortedChildren(comp: JitFnCompiler): MemberRunType<any>[];
|
|
32
|
+
allOptionalCode(comp: JitFnCompiler): string;
|
|
33
|
+
addObjectPropsToContext(comp: JitFnCompiler, jitChildrenRunTypes?: BaseRunType[], allChildrenRuntypes?: BaseRunType[]): ObjectPropsContextResult;
|
|
34
|
+
}
|
|
35
|
+
export interface ObjectPropsContextResult {
|
|
36
|
+
keysName: string;
|
|
37
|
+
allKeysName: string;
|
|
38
|
+
hasNonJitChildren: boolean;
|
|
39
|
+
jitChildrenNames: string[];
|
|
40
|
+
allChildrenNames: string[];
|
|
41
|
+
}
|
|
42
|
+
export declare type __ΩInterfaceMember = any[];
|
|
43
|
+
export declare type __ΩObjectPropsContextResult = any[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const type = require("@deepkit/type");
|
|
4
|
+
const src_nodes_collection_interface = require("./interface.cjs");
|
|
5
|
+
class IntersectionRunType extends src_nodes_collection_interface.InterfaceRunType {
|
|
6
|
+
compileIsType() {
|
|
7
|
+
throw new Error("Intersection validation not supported, should be resolve to other RunTypes");
|
|
8
|
+
}
|
|
9
|
+
compileTypeErrors() {
|
|
10
|
+
throw new Error("Intersection validation not supported, should be resolve to other RunTypes");
|
|
11
|
+
}
|
|
12
|
+
compilePrepareForJson() {
|
|
13
|
+
throw new Error("Intersection serialization not supported, should be resolve to other RunTypes");
|
|
14
|
+
}
|
|
15
|
+
compileRestoreFromJson() {
|
|
16
|
+
throw new Error("Intersection serialization not supported, should be resolve to other RunTypes");
|
|
17
|
+
}
|
|
18
|
+
static __type = [() => type.__ΩTypeIntersection, () => src_nodes_collection_interface.InterfaceRunType, "JitCode", "compileIsType", "compileTypeErrors", "compilePrepareForJson", "compileRestoreFromJson", () => type.__ΩTypeIntersection, "IntersectionRunType", `Pn!7"P"w#0$P"w#0%P"w#0&P"w#0'5n(6"w)`];
|
|
19
|
+
}
|
|
20
|
+
exports.IntersectionRunType = IntersectionRunType;
|
|
21
|
+
//# sourceMappingURL=intersection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TypeIntersection } from '@deepkit/type';
|
|
2
|
+
import { InterfaceRunType } from './interface.ts';
|
|
3
|
+
import { JitCode } from '../../types.ts';
|
|
4
|
+
export declare class IntersectionRunType extends InterfaceRunType<TypeIntersection> {
|
|
5
|
+
compileIsType(): JitCode;
|
|
6
|
+
compileTypeErrors(): JitCode;
|
|
7
|
+
compilePrepareForJson(): JitCode;
|
|
8
|
+
compileRestoreFromJson(): JitCode;
|
|
9
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const src_nodes_member_tupleMember = require("../member/tupleMember.cjs");
|
|
4
|
+
const src_lib_baseRunTypes = require("../../lib/baseRunTypes.cjs");
|
|
5
|
+
function __assignType(fn, args) {
|
|
6
|
+
fn.__type = args;
|
|
7
|
+
return fn;
|
|
8
|
+
}
|
|
9
|
+
class TupleRunType extends src_lib_baseRunTypes.CollectionRunType {
|
|
10
|
+
getChildRunTypes = __assignType(() => {
|
|
11
|
+
const childTypes = this.src.parameters || this.src.types || [];
|
|
12
|
+
return childTypes.map(__assignType((t) => t._rt, ["t", "", 'P"2!"/"']));
|
|
13
|
+
}, ["", "P!F/!"]);
|
|
14
|
+
getParamRunTypes(comp) {
|
|
15
|
+
const start = comp.opts?.paramsSlice?.start;
|
|
16
|
+
const end = comp.opts?.paramsSlice?.end;
|
|
17
|
+
const children = this.getChildRunTypes();
|
|
18
|
+
if (!start && !end)
|
|
19
|
+
return children;
|
|
20
|
+
return children.slice(start, end);
|
|
21
|
+
}
|
|
22
|
+
hasRestParameter(comp) {
|
|
23
|
+
return !!this.getParamRunTypes(comp).length && this.getParamRunTypes(comp)[this.getParamRunTypes(comp).length - 1].isRest();
|
|
24
|
+
}
|
|
25
|
+
totalRequiredParams(comp) {
|
|
26
|
+
return this.getParamRunTypes(comp).filter(__assignType((p) => !p.isOptional() && !p.isRest(), ["p", "", 'P"2!"/"'])).length;
|
|
27
|
+
}
|
|
28
|
+
// ####### params #######
|
|
29
|
+
emitIsType(comp) {
|
|
30
|
+
const children = this.getParamRunTypes(comp);
|
|
31
|
+
if (children.length === 0 && comp.opts.noIsArrayCheck)
|
|
32
|
+
return { code: void 0, type: "E" };
|
|
33
|
+
if (children.length === 0)
|
|
34
|
+
return { code: `Array.isArray(${comp.vλl}) && ${comp.vλl}.length === 0`, type: "E" };
|
|
35
|
+
const lengthCode = this.hasRestParameter(comp) ? "" : `&& ${comp.vλl}.length <= ${this.getParamRunTypes(comp).length}`;
|
|
36
|
+
const paramsCode = children.map(__assignType((p) => `(${comp.compileIsType(p, "E").code})`, ["p", "", 'P"2!"/"'])).join(" && ");
|
|
37
|
+
const checkIsArrayCode = comp.opts.noIsArrayCheck ? "" : `Array.isArray(${comp.vλl})${lengthCode} && `;
|
|
38
|
+
return { code: `(${checkIsArrayCode} ${paramsCode})`, type: "E" };
|
|
39
|
+
}
|
|
40
|
+
emitTypeErrors(comp) {
|
|
41
|
+
const children = this.getParamRunTypes(comp);
|
|
42
|
+
if (children.length === 0 && comp.opts.noIsArrayCheck)
|
|
43
|
+
return { code: void 0, type: "S" };
|
|
44
|
+
if (children.length === 0)
|
|
45
|
+
return { code: `if (!Array.isArray(${comp.vλl}) || && ${comp.vλl}.length === 0) ${comp.callJitErr(this)}`, type: "S" };
|
|
46
|
+
const lengthCode = this.hasRestParameter(comp) ? "" : `|| ${comp.vλl}.length > ${this.getParamRunTypes(comp).length}`;
|
|
47
|
+
const paramsCode = children.map(__assignType((p) => comp.compileTypeErrors(p, "S").code, ["p", "", 'P"2!"/"'])).join(";");
|
|
48
|
+
if (comp.opts.noIsArrayCheck)
|
|
49
|
+
return { code: paramsCode, type: "S" };
|
|
50
|
+
return { code: `if (!Array.isArray(${comp.vλl})${lengthCode}) ${comp.callJitErr(this)}; else {${paramsCode}}`, type: "S" };
|
|
51
|
+
}
|
|
52
|
+
emitPrepareForJson(comp) {
|
|
53
|
+
const children = this.getParamRunTypes(comp);
|
|
54
|
+
if (!children.length)
|
|
55
|
+
return { code: void 0, type: "S" };
|
|
56
|
+
const code = children.map(__assignType((p) => comp.compilePrepareForJson(p, "S").code, ["p", "", 'P"2!"/"'])).filter(Boolean).join(";");
|
|
57
|
+
return { code, type: "S" };
|
|
58
|
+
}
|
|
59
|
+
emitRestoreFromJson(comp) {
|
|
60
|
+
const children = this.getParamRunTypes(comp);
|
|
61
|
+
if (!children.length)
|
|
62
|
+
return { code: void 0, type: "S" };
|
|
63
|
+
const code = children.map(__assignType((p) => comp.compileRestoreFromJson(p, "S").code, ["p", "", 'P"2!"/"'])).filter(Boolean).join(";");
|
|
64
|
+
return { code, type: "S" };
|
|
65
|
+
}
|
|
66
|
+
static __type = ["TypeTuple", "ParamList", () => src_nodes_member_tupleMember.TupleMemberRunType, "ParamType", () => src_lib_baseRunTypes.CollectionRunType, "getChildRunTypes", function() {
|
|
67
|
+
return __assignType(() => {
|
|
68
|
+
const childTypes = this.src.parameters || this.src.types || [];
|
|
69
|
+
return childTypes.map(__assignType((t) => t._rt, ["t", "", 'P"2!"/"']));
|
|
70
|
+
}, ["", "P!F/!"]);
|
|
71
|
+
}, "JitFnCompiler", "comp", "getParamRunTypes", "hasRestParameter", "totalRequiredParams", "JitCode", "emitIsType", "JitErrorsFnCompiler", "emitTypeErrors", "emitPrepareForJson", "emitRestoreFromJson", "TupleRunType", `"w!c"P7#c$Pe"!7%!3&>'P"w(2)e""F0*P"w(2))0+P"w(2)'0,P"w(2)"w-0.P"w/2)"w-00P"w(2)"w-01P"w(2)"w-025e!!6"w3`];
|
|
72
|
+
}
|
|
73
|
+
exports.TupleRunType = TupleRunType;
|
|
74
|
+
//# sourceMappingURL=tuple.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypeTuple } from '@deepkit/type';
|
|
2
|
+
import { JitFnCompiler, JitErrorsFnCompiler } from '../../lib/jitFnCompiler.ts';
|
|
3
|
+
import { AnyParameterListRunType, JitCode } from '../../types.ts';
|
|
4
|
+
import { ParameterRunType } from '../member/param.ts';
|
|
5
|
+
import { CollectionRunType } from '../../lib/baseRunTypes.ts';
|
|
6
|
+
import { TupleMemberRunType } from '../member/tupleMember.ts';
|
|
7
|
+
type AnyParamRunType = ParameterRunType | TupleMemberRunType;
|
|
8
|
+
export declare class TupleRunType<ParamList extends AnyParameterListRunType = TypeTuple, ParamType extends AnyParamRunType = TupleMemberRunType> extends CollectionRunType<ParamList> {
|
|
9
|
+
getChildRunTypes: () => ParamType[];
|
|
10
|
+
getParamRunTypes(comp: JitFnCompiler): ParamType[];
|
|
11
|
+
hasRestParameter(comp: JitFnCompiler): boolean;
|
|
12
|
+
totalRequiredParams(comp: JitFnCompiler): number;
|
|
13
|
+
emitIsType(comp: JitFnCompiler): JitCode;
|
|
14
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode;
|
|
15
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode;
|
|
16
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const type = require("@deepkit/type");
|
|
4
|
+
const src_lib_baseRunTypes = require("../../lib/baseRunTypes.cjs");
|
|
5
|
+
const src_lib_utils = require("../../lib/utils.cjs");
|
|
6
|
+
const src_lib_guards = require("../../lib/guards.cjs");
|
|
7
|
+
const src_nodes_collection_unionDiscriminator = require("./unionDiscriminator.cjs");
|
|
8
|
+
function __assignType(fn, args) {
|
|
9
|
+
fn.__type = args;
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
12
|
+
class UnionRunType extends src_lib_baseRunTypes.CollectionRunType {
|
|
13
|
+
hasDiscriminators = void 0;
|
|
14
|
+
hasObjectTypes = void 0;
|
|
15
|
+
isTypeWithProperties(rt) {
|
|
16
|
+
return rt.getFamily() === "C" && (src_lib_guards.isInterfaceRunType(rt) || src_lib_guards.isClassRunType(rt) || src_lib_guards.isObjectLiteralRunType(rt) || src_lib_guards.isIntersectionRunType(rt));
|
|
17
|
+
}
|
|
18
|
+
getUnionChildren(comp) {
|
|
19
|
+
const children = this.getJitChildren(comp);
|
|
20
|
+
src_nodes_collection_unionDiscriminator.markDiscriminators(comp, this, children);
|
|
21
|
+
return src_nodes_collection_unionDiscriminator.splitUnionItems(comp, this, children);
|
|
22
|
+
}
|
|
23
|
+
getUnionItemIndex(comp, unionItem) {
|
|
24
|
+
const children = this.getJitChildren(comp);
|
|
25
|
+
const index = children.findIndex(__assignType((child) => child === unionItem, ["child", "", 'P"2!"/"']));
|
|
26
|
+
if (index === -1)
|
|
27
|
+
throw new Error(`Item ${unionItem.getTypeName()} not found in union ${this.getTypeName()}`);
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns isType check for a union child with loose matching.
|
|
32
|
+
* Uses first-match strategy: returns first matching type in declaration order.
|
|
33
|
+
* For all-optional types (weak types), ensures at least one property matches or is empty object.
|
|
34
|
+
* Note: Use ESLint rules @mionjs/no-unreachable-union-types and @mionjs/no-mixed-union-properties
|
|
35
|
+
* to detect overlapping union types at compile time.
|
|
36
|
+
* @see union.spec.ts 'Union Obj' and 'Union Mixed' test suites for examples.
|
|
37
|
+
*/
|
|
38
|
+
getChildIsTypeWithLooseCheck(rt, comp) {
|
|
39
|
+
const isTypeCode = comp.compileIsType(rt, "E").code || "";
|
|
40
|
+
const isTypeWithProperties = src_lib_guards.isInterfaceRunType(rt) || src_lib_guards.isClassRunType(rt) || src_lib_guards.isObjectLiteralRunType(rt) || src_lib_guards.isIntersectionRunType(rt);
|
|
41
|
+
if (!isTypeWithProperties || rt.getFamily() !== "C")
|
|
42
|
+
return isTypeCode;
|
|
43
|
+
const props = rt.getJitChildren(comp);
|
|
44
|
+
const hasIndexProperty = props.some(__assignType((prop) => prop.src.kind === type.ReflectionKind.indexSignature, ["prop", "", 'P"2!"/"']));
|
|
45
|
+
if (hasIndexProperty)
|
|
46
|
+
return isTypeCode;
|
|
47
|
+
const isAllOptional = rt.areAllChildrenOptional(props);
|
|
48
|
+
if (isAllOptional && props.length > 0) {
|
|
49
|
+
const hasOwnPropCheck = props.map(__assignType((p) => {
|
|
50
|
+
const name = p.getPropertyName();
|
|
51
|
+
return `(${src_lib_utils.toLiteral(name)} in ${comp.vλl})`;
|
|
52
|
+
}, ["p", "", 'P"2!"/"']));
|
|
53
|
+
hasOwnPropCheck.push(`Object.keys(${comp.vλl}).length === 0`);
|
|
54
|
+
const weakTypeCheck = `(${hasOwnPropCheck.join(" || ")})`;
|
|
55
|
+
return `(${isTypeCode} && ${weakTypeCheck})`;
|
|
56
|
+
}
|
|
57
|
+
return isTypeCode;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Loose union matching: returns first matching type in declaration order.
|
|
61
|
+
* Objects with properties from multiple union types will match the first compatible type.
|
|
62
|
+
* Use ESLint rules to detect overlapping types at compile time.
|
|
63
|
+
*/
|
|
64
|
+
emitIsType(comp) {
|
|
65
|
+
this.checkAllowedChildren(comp);
|
|
66
|
+
const { simpleItems, objectTypes, anyItem } = this.getUnionChildren(comp);
|
|
67
|
+
const simpleChecks = simpleItems.map(__assignType((rt) => this.getChildIsTypeWithLooseCheck(rt, comp), ["rt", "", 'P"2!"/"'])).filter(Boolean);
|
|
68
|
+
const objChecks = objectTypes.map(__assignType((rt) => this.getChildIsTypeWithLooseCheck(rt, comp), ["rt", "", 'P"2!"/"'])).filter(Boolean);
|
|
69
|
+
const objCode = objChecks.length ? `(typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && (${objChecks.join(" || ")}))` : "";
|
|
70
|
+
const anyCheck = anyItem ? this.getChildIsTypeWithLooseCheck(anyItem, comp) : "";
|
|
71
|
+
const allChecks = [...simpleChecks, objCode, anyCheck].filter(Boolean);
|
|
72
|
+
return { code: `(${allChecks.join(" || ")})`, type: "E" };
|
|
73
|
+
}
|
|
74
|
+
emitTypeErrors(comp) {
|
|
75
|
+
this.checkAllowedChildren(comp);
|
|
76
|
+
const isType = comp.compileIsType(this, "E").code;
|
|
77
|
+
const code = `if (!${isType}) ${comp.callJitErr(this)};`;
|
|
78
|
+
return { code, type: "S" };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* When a union is encodes to json is encode into and array with two elements: [unionDiscriminator, encoded Value]
|
|
82
|
+
* the first element is the index of the type in the union.
|
|
83
|
+
* the second element is the encoded value of the type.
|
|
84
|
+
* ie: type union = string | number | bigint; var v1: union = 123n; v1 is encoded as [2, "123n"]
|
|
85
|
+
*/
|
|
86
|
+
emitPrepareForJson(comp) {
|
|
87
|
+
this.checkAllowedChildren(comp);
|
|
88
|
+
const { simpleItems, objectTypes, anyItem } = this.getUnionChildren(comp);
|
|
89
|
+
const errName = comp.getLocalVarName("uErr", this);
|
|
90
|
+
const fail = `throw new Error(${errName});`;
|
|
91
|
+
comp.setContextItem(errName, `const ${errName} = "Can not json encode union: item does not belong to the union"`);
|
|
92
|
+
const ifElse = src_lib_utils.createIfElseFn();
|
|
93
|
+
const getEncodeCode = __assignType((childRt) => {
|
|
94
|
+
const toJit = comp.compilePrepareForJson(childRt, "S");
|
|
95
|
+
const fromJit = comp.compileRestoreFromJson(childRt, "S");
|
|
96
|
+
const needsTupleEncoding = !!toJit.code || !!fromJit.code;
|
|
97
|
+
const isExpression = src_lib_utils.childIsExpression(toJit, childRt);
|
|
98
|
+
const encodeCode = isExpression && toJit.code ? `${comp.vλl} = ${toJit.code};` : toJit.code || "";
|
|
99
|
+
const index = this.getUnionItemIndex(comp, childRt);
|
|
100
|
+
const tupleEncode = needsTupleEncoding ? `${comp.vλl} = [${index}, ${comp.vλl}]` : "/*noop*/";
|
|
101
|
+
return `${encodeCode} ${tupleEncode}`;
|
|
102
|
+
}, [() => src_lib_baseRunTypes.BaseRunType, "childRt", "", 'PP7!2""/#']);
|
|
103
|
+
const simpleCode = simpleItems.map(__assignType((rt) => {
|
|
104
|
+
const isTypeCode = this.getChildIsTypeWithLooseCheck(rt, comp);
|
|
105
|
+
return `${ifElse()} (${isTypeCode}) {${getEncodeCode(rt)}}`;
|
|
106
|
+
}, ["rt", "", 'P"2!"/"']));
|
|
107
|
+
const objCode = objectTypes.length ? objectTypes.map(__assignType((rt) => {
|
|
108
|
+
const isTypeCode = this.getChildIsTypeWithLooseCheck(rt, comp);
|
|
109
|
+
return `${ifElse()} (typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && ${isTypeCode}) {${getEncodeCode(rt)}}`;
|
|
110
|
+
}, ["rt", "", 'P"2!"/"'])) : [];
|
|
111
|
+
const anyCode = anyItem ? `${ifElse(true)} {${getEncodeCode(anyItem)}}` : `${ifElse(true)} {${fail}}`;
|
|
112
|
+
return { code: [...simpleCode, ...objCode, anyCode].join(""), type: "S" };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* When a union is decoded from json it expects de two elements array format: [unionDiscriminator, Value to decode]
|
|
116
|
+
* the first element is the index of the type in the union.
|
|
117
|
+
* the second element is the encoded value of the type.
|
|
118
|
+
* ie: type union = string | number | bigint; var v1: union = 123n; v1 is encoded as [2, "123n"]
|
|
119
|
+
*/
|
|
120
|
+
emitRestoreFromJson(comp) {
|
|
121
|
+
this.checkAllowedChildren(comp);
|
|
122
|
+
const decVar = comp.getLocalVarName("dec", this);
|
|
123
|
+
const errVarName = comp.getLocalVarName("uErr", this);
|
|
124
|
+
comp.setContextItem(errVarName, `const ${errVarName} = "Can not json decode union: invalid union index"`);
|
|
125
|
+
const children = this.getJitChildren(comp);
|
|
126
|
+
const ifElse = src_lib_utils.createIfElseFn();
|
|
127
|
+
const itemsCode = children.map(__assignType((unionItem) => {
|
|
128
|
+
const childJit = comp.compileRestoreFromJson(unionItem, "S");
|
|
129
|
+
const isExpression = src_lib_utils.childIsExpression(childJit, unionItem);
|
|
130
|
+
const code2 = isExpression && childJit.code && childJit.code !== comp.vλl ? `${comp.vλl} = ${childJit.code}` : childJit.code || "";
|
|
131
|
+
const index = this.getUnionItemIndex(comp, unionItem);
|
|
132
|
+
return `${ifElse()} (${decVar} === ${index}) {${code2 || "/*noop*/"}}`;
|
|
133
|
+
}, ["unionItem", "", 'P"2!"/"'])).filter(Boolean);
|
|
134
|
+
const childrenCode = itemsCode.join("");
|
|
135
|
+
const failCode = childrenCode ? `else {throw new Error(${errVarName})}` : "";
|
|
136
|
+
const code = `
|
|
137
|
+
if (${comp.vλl}?.length === 2 && Array.isArray(${comp.vλl}) && typeof ${comp.vλl}[0] === 'number') {
|
|
138
|
+
const ${decVar} = ${comp.vλl}[0]; ${comp.vλl} = ${comp.vλl}[1];
|
|
139
|
+
${childrenCode}
|
|
140
|
+
${failCode}
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
return { code, type: "S" };
|
|
144
|
+
}
|
|
145
|
+
getUnionTypeNames() {
|
|
146
|
+
return this.getChildRunTypes().map(__assignType((rt) => rt.getTypeName(), ["rt", "", 'P"2!"/"'])).join(" | ");
|
|
147
|
+
}
|
|
148
|
+
checkAllowedChildren(comp) {
|
|
149
|
+
const allChildren = this.getChildRunTypes();
|
|
150
|
+
const toSkip = allChildren.filter(__assignType((rt) => rt.skipJit(comp), ["rt", "", 'P"2!"/"']));
|
|
151
|
+
if (toSkip.length)
|
|
152
|
+
throw new Error(`Union can not have non serializable types, ie: Symbol, Function, etc.
|
|
153
|
+
Type: ${this.stringify()}`);
|
|
154
|
+
}
|
|
155
|
+
static __type = ["TypeUnion", () => src_lib_baseRunTypes.CollectionRunType, "hasDiscriminators", function() {
|
|
156
|
+
return void 0;
|
|
157
|
+
}, "hasObjectTypes", function() {
|
|
158
|
+
return void 0;
|
|
159
|
+
}, () => src_lib_baseRunTypes.BaseRunType, "rt", "isTypeWithProperties", "JitFnCompiler", "comp", () => src_nodes_collection_unionDiscriminator.__ΩSplitUnionResult, "getUnionChildren", () => src_lib_baseRunTypes.BaseRunType, "unionItem", "getUnionItemIndex", () => src_lib_baseRunTypes.BaseRunType, "getChildIsTypeWithLooseCheck", "JitCode", "emitIsType", "JitErrorsFnCompiler", "emitTypeErrors", "emitPrepareForJson", "emitRestoreFromJson", "getUnionTypeNames", "checkAllowedChildren", "UnionRunType", `P"w!7"P)-J3#>$P)-J3%>&PP7'2("0)P"w*2+n,0-P"w*2+P7.2/'00PP712("w*2+&02P"w*2+"w304P"w52+"w306P"w*2+"w307P"w*2+"w308P&09P"w*2+"0:5"w!6"w;`];
|
|
160
|
+
}
|
|
161
|
+
exports.UnionRunType = UnionRunType;
|
|
162
|
+
//# sourceMappingURL=union.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|