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