@mionjs/run-types 0.8.6 → 0.8.8
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.d.ts +1 -0
- package/.dist/cjs/index.d.ts.map +1 -0
- package/.dist/cjs/src/constants.d.ts +1 -0
- package/.dist/cjs/src/constants.d.ts.map +1 -0
- package/.dist/cjs/src/constants.functions.d.ts +1 -0
- package/.dist/cjs/src/constants.functions.d.ts.map +1 -0
- package/.dist/cjs/src/constants.kind.d.ts +1 -0
- package/.dist/cjs/src/constants.kind.d.ts.map +1 -0
- package/.dist/cjs/src/createRunType.d.ts +1 -0
- package/.dist/cjs/src/createRunType.d.ts.map +1 -0
- package/.dist/cjs/src/createRunTypeFunctions.d.ts +1 -0
- package/.dist/cjs/src/createRunTypeFunctions.d.ts.map +1 -0
- package/.dist/cjs/src/formats.runtype.d.ts +1 -0
- package/.dist/cjs/src/formats.runtype.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/equalsHelpers.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/equalsHelpers.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts.map +1 -0
- package/.dist/cjs/src/jitCompilers/json/toJsCode.d.ts +1 -0
- package/.dist/cjs/src/jitCompilers/json/toJsCode.d.ts.map +1 -0
- package/.dist/cjs/src/lib/baseRunTypeFormat.d.ts +1 -0
- package/.dist/cjs/src/lib/baseRunTypeFormat.d.ts.map +1 -0
- package/.dist/cjs/src/lib/baseRunTypes.d.ts +1 -0
- package/.dist/cjs/src/lib/baseRunTypes.d.ts.map +1 -0
- package/.dist/cjs/src/lib/createJitFunction.d.ts +1 -0
- package/.dist/cjs/src/lib/createJitFunction.d.ts.map +1 -0
- package/.dist/cjs/src/lib/dkProxy.d.ts +1 -0
- package/.dist/cjs/src/lib/dkProxy.d.ts.map +1 -0
- package/.dist/cjs/src/lib/formats.d.ts +1 -0
- package/.dist/cjs/src/lib/formats.d.ts.map +1 -0
- package/.dist/cjs/src/lib/guards.d.ts +1 -0
- package/.dist/cjs/src/lib/guards.d.ts.map +1 -0
- package/.dist/cjs/src/lib/jitFnCompiler.d.ts +1 -0
- package/.dist/cjs/src/lib/jitFnCompiler.d.ts.map +1 -0
- package/.dist/cjs/src/lib/jitFnsRegistry.d.ts +1 -0
- package/.dist/cjs/src/lib/jitFnsRegistry.d.ts.map +1 -0
- package/.dist/cjs/src/lib/typeId.d.ts +1 -0
- package/.dist/cjs/src/lib/typeId.d.ts.map +1 -0
- package/.dist/cjs/src/lib/utils.d.ts +1 -0
- package/.dist/cjs/src/lib/utils.d.ts.map +1 -0
- package/.dist/cjs/src/mocking/constants.mock.d.ts +1 -0
- package/.dist/cjs/src/mocking/constants.mock.d.ts.map +1 -0
- package/.dist/cjs/src/mocking/mockRegistry.d.ts +1 -0
- package/.dist/cjs/src/mocking/mockRegistry.d.ts.map +1 -0
- package/.dist/cjs/src/mocking/mockType.d.ts +1 -0
- package/.dist/cjs/src/mocking/mockType.d.ts.map +1 -0
- package/.dist/cjs/src/mocking/mockUtils.d.ts +1 -0
- package/.dist/cjs/src/mocking/mockUtils.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/any.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/any.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/bigInt.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/bigInt.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/boolean.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/boolean.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/date.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/date.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/enum.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/enum.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/enumMember.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/enumMember.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/literal.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/literal.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/never.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/never.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/null.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/null.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/number.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/number.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/object.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/object.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/regexp.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/regexp.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/string.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/string.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/symbol.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/symbol.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/undefined.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/undefined.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/unknown.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/unknown.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/atomic/void.d.ts +1 -0
- package/.dist/cjs/src/nodes/atomic/void.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/class.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/class.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/functionParams.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/functionParams.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/interface.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/interface.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/intersection.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/intersection.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/tuple.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/tuple.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/union.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/union.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/collection/unionDiscriminator.d.ts +1 -0
- package/.dist/cjs/src/nodes/collection/unionDiscriminator.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/function/function.d.ts +1 -0
- package/.dist/cjs/src/nodes/function/function.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/array.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/array.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/callSignature.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/callSignature.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/genericMember.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/genericMember.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/indexProperty.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/indexProperty.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/method.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/method.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/methodSignature.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/methodSignature.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/param.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/param.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/property.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/property.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/restParams.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/restParams.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/tupleMember.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/tupleMember.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/native/Iterable.d.ts +1 -0
- package/.dist/cjs/src/nodes/native/Iterable.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/native/map.d.ts +1 -0
- package/.dist/cjs/src/nodes/native/map.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/native/nonSerializable.d.ts +1 -0
- package/.dist/cjs/src/nodes/native/nonSerializable.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/native/promise.d.ts +1 -0
- package/.dist/cjs/src/nodes/native/promise.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/native/set.d.ts +1 -0
- package/.dist/cjs/src/nodes/native/set.d.ts.map +1 -0
- package/.dist/cjs/src/run-types-pure-fns.d.ts +1 -0
- package/.dist/cjs/src/run-types-pure-fns.d.ts.map +1 -0
- package/.dist/cjs/src/types.d.ts +1 -0
- package/.dist/cjs/src/types.d.ts.map +1 -0
- package/.dist/esm/index.d.ts +1 -0
- package/.dist/esm/index.d.ts.map +1 -0
- package/.dist/esm/src/constants.d.ts +1 -0
- package/.dist/esm/src/constants.d.ts.map +1 -0
- package/.dist/esm/src/constants.functions.d.ts +1 -0
- package/.dist/esm/src/constants.functions.d.ts.map +1 -0
- package/.dist/esm/src/constants.kind.d.ts +1 -0
- package/.dist/esm/src/constants.kind.d.ts.map +1 -0
- package/.dist/esm/src/createRunType.d.ts +1 -0
- package/.dist/esm/src/createRunType.d.ts.map +1 -0
- package/.dist/esm/src/createRunTypeFunctions.d.ts +1 -0
- package/.dist/esm/src/createRunTypeFunctions.d.ts.map +1 -0
- package/.dist/esm/src/formats.runtype.d.ts +1 -0
- package/.dist/esm/src/formats.runtype.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/equalsHelpers.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/equalsHelpers.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts.map +1 -0
- package/.dist/esm/src/jitCompilers/json/toJsCode.d.ts +1 -0
- package/.dist/esm/src/jitCompilers/json/toJsCode.d.ts.map +1 -0
- package/.dist/esm/src/lib/baseRunTypeFormat.d.ts +1 -0
- package/.dist/esm/src/lib/baseRunTypeFormat.d.ts.map +1 -0
- package/.dist/esm/src/lib/baseRunTypes.d.ts +1 -0
- package/.dist/esm/src/lib/baseRunTypes.d.ts.map +1 -0
- package/.dist/esm/src/lib/createJitFunction.d.ts +1 -0
- package/.dist/esm/src/lib/createJitFunction.d.ts.map +1 -0
- package/.dist/esm/src/lib/dkProxy.d.ts +1 -0
- package/.dist/esm/src/lib/dkProxy.d.ts.map +1 -0
- package/.dist/esm/src/lib/formats.d.ts +1 -0
- package/.dist/esm/src/lib/formats.d.ts.map +1 -0
- package/.dist/esm/src/lib/guards.d.ts +1 -0
- package/.dist/esm/src/lib/guards.d.ts.map +1 -0
- package/.dist/esm/src/lib/jitFnCompiler.d.ts +1 -0
- package/.dist/esm/src/lib/jitFnCompiler.d.ts.map +1 -0
- package/.dist/esm/src/lib/jitFnsRegistry.d.ts +1 -0
- package/.dist/esm/src/lib/jitFnsRegistry.d.ts.map +1 -0
- package/.dist/esm/src/lib/typeId.d.ts +1 -0
- package/.dist/esm/src/lib/typeId.d.ts.map +1 -0
- package/.dist/esm/src/lib/utils.d.ts +1 -0
- package/.dist/esm/src/lib/utils.d.ts.map +1 -0
- package/.dist/esm/src/mocking/constants.mock.d.ts +1 -0
- package/.dist/esm/src/mocking/constants.mock.d.ts.map +1 -0
- package/.dist/esm/src/mocking/mockRegistry.d.ts +1 -0
- package/.dist/esm/src/mocking/mockRegistry.d.ts.map +1 -0
- package/.dist/esm/src/mocking/mockType.d.ts +1 -0
- package/.dist/esm/src/mocking/mockType.d.ts.map +1 -0
- package/.dist/esm/src/mocking/mockUtils.d.ts +1 -0
- package/.dist/esm/src/mocking/mockUtils.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/any.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/any.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/bigInt.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/bigInt.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/boolean.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/boolean.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/date.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/date.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/enum.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/enum.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/enumMember.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/enumMember.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/literal.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/literal.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/never.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/never.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/null.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/null.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/number.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/number.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/object.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/object.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/regexp.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/regexp.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/string.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/string.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/symbol.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/symbol.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/undefined.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/undefined.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/unknown.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/unknown.d.ts.map +1 -0
- package/.dist/esm/src/nodes/atomic/void.d.ts +1 -0
- package/.dist/esm/src/nodes/atomic/void.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/class.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/class.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/functionParams.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/functionParams.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/interface.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/interface.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/intersection.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/intersection.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/tuple.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/tuple.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/union.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/union.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/unionDiscriminator.d.ts +1 -0
- package/.dist/esm/src/nodes/collection/unionDiscriminator.d.ts.map +1 -0
- package/.dist/esm/src/nodes/function/function.d.ts +1 -0
- package/.dist/esm/src/nodes/function/function.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/array.d.ts +1 -0
- package/.dist/esm/src/nodes/member/array.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/callSignature.d.ts +1 -0
- package/.dist/esm/src/nodes/member/callSignature.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/genericMember.d.ts +1 -0
- package/.dist/esm/src/nodes/member/genericMember.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/indexProperty.d.ts +1 -0
- package/.dist/esm/src/nodes/member/indexProperty.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/method.d.ts +1 -0
- package/.dist/esm/src/nodes/member/method.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/methodSignature.d.ts +1 -0
- package/.dist/esm/src/nodes/member/methodSignature.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/param.d.ts +1 -0
- package/.dist/esm/src/nodes/member/param.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/property.d.ts +1 -0
- package/.dist/esm/src/nodes/member/property.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/restParams.d.ts +1 -0
- package/.dist/esm/src/nodes/member/restParams.d.ts.map +1 -0
- package/.dist/esm/src/nodes/member/tupleMember.d.ts +1 -0
- package/.dist/esm/src/nodes/member/tupleMember.d.ts.map +1 -0
- package/.dist/esm/src/nodes/native/Iterable.d.ts +1 -0
- package/.dist/esm/src/nodes/native/Iterable.d.ts.map +1 -0
- package/.dist/esm/src/nodes/native/map.d.ts +1 -0
- package/.dist/esm/src/nodes/native/map.d.ts.map +1 -0
- package/.dist/esm/src/nodes/native/nonSerializable.d.ts +1 -0
- package/.dist/esm/src/nodes/native/nonSerializable.d.ts.map +1 -0
- package/.dist/esm/src/nodes/native/promise.d.ts +1 -0
- package/.dist/esm/src/nodes/native/promise.d.ts.map +1 -0
- package/.dist/esm/src/nodes/native/set.d.ts +1 -0
- package/.dist/esm/src/nodes/native/set.d.ts.map +1 -0
- package/.dist/esm/src/run-types-pure-fns.d.ts +1 -0
- package/.dist/esm/src/run-types-pure-fns.d.ts.map +1 -0
- package/.dist/esm/src/types.d.ts +1 -0
- package/.dist/esm/src/types.d.ts.map +1 -0
- package/index.ts +70 -0
- package/package.json +11 -4
- package/src/constants.functions.ts +196 -0
- package/src/constants.kind.ts +76 -0
- package/src/constants.ts +85 -0
- package/src/createRunType.ts +323 -0
- package/src/createRunTypeFunctions.ts +93 -0
- package/src/formats.runtype.ts +35 -0
- package/src/jitCompilers/binary/binarySPEC.md +138 -0
- package/src/jitCompilers/binary/binarySpec/binaryHelpers.ts +118 -0
- package/src/jitCompilers/binary/fromBinary.ts +492 -0
- package/src/jitCompilers/binary/toBinary.ts +435 -0
- package/src/jitCompilers/equalsHelpers.ts +62 -0
- package/src/jitCompilers/json/jsonSpec/jsonHelpers.ts +64 -0
- package/src/jitCompilers/json/stringifyJson.ts +475 -0
- package/src/jitCompilers/json/stringifySpec/stringifyHelpers.ts +59 -0
- package/src/jitCompilers/json/toJsCode.ts +182 -0
- package/src/jitCompilers/serialization-suite.ts +1637 -0
- package/src/jitCompilers/xyz-Template/fromXYZ.ts +211 -0
- package/src/jitCompilers/xyz-Template/toXYZ.ts +216 -0
- package/src/jitCompilers/xyz-Template/xyzReadme.md +6 -0
- package/src/jitCompilers/xyz-Template/xyzSpec/xyzHelpers.ts +66 -0
- package/src/lib/baseRunTypeFormat.ts +320 -0
- package/src/lib/baseRunTypes.ts +367 -0
- package/src/lib/createJitFunction.ts +87 -0
- package/src/lib/dkProxy.ts +47 -0
- package/src/lib/formats.ts +144 -0
- package/src/lib/guards.ts +290 -0
- package/src/lib/jitFnCompiler.ts +783 -0
- package/src/lib/jitFnsRegistry.ts +53 -0
- package/src/lib/typeId.ts +225 -0
- package/src/lib/utils.ts +402 -0
- package/src/mocking/constants.mock.ts +87 -0
- package/src/mocking/mockRegistry.ts +20 -0
- package/src/mocking/mockType.ts +354 -0
- package/src/mocking/mockUtils.ts +82 -0
- package/src/nodes/atomic/any.ts +22 -0
- package/src/nodes/atomic/bigInt.ts +26 -0
- package/src/nodes/atomic/boolean.ts +26 -0
- package/src/nodes/atomic/date.ts +26 -0
- package/src/nodes/atomic/enum.ts +23 -0
- package/src/nodes/atomic/enumMember.ts +29 -0
- package/src/nodes/atomic/literal.ts +125 -0
- package/src/nodes/atomic/never.ts +26 -0
- package/src/nodes/atomic/null.ts +26 -0
- package/src/nodes/atomic/number.ts +26 -0
- package/src/nodes/atomic/object.ts +20 -0
- package/src/nodes/atomic/regexp.ts +29 -0
- package/src/nodes/atomic/string.ts +20 -0
- package/src/nodes/atomic/symbol.ts +31 -0
- package/src/nodes/atomic/undefined.ts +23 -0
- package/src/nodes/atomic/unknown.ts +10 -0
- package/src/nodes/atomic/void.ts +26 -0
- package/src/nodes/collection/class.ts +36 -0
- package/src/nodes/collection/functionParams.ts +42 -0
- package/src/nodes/collection/interface.ts +300 -0
- package/src/nodes/collection/intersection.ts +30 -0
- package/src/nodes/collection/tuple.ts +80 -0
- package/src/nodes/collection/union.ts +205 -0
- package/src/nodes/collection/unionDiscriminator.ts +259 -0
- package/src/nodes/function/function.ts +166 -0
- package/src/nodes/member/array.ts +150 -0
- package/src/nodes/member/callSignature.ts +34 -0
- package/src/nodes/member/genericMember.ts +63 -0
- package/src/nodes/member/indexProperty.ts +125 -0
- package/src/nodes/member/method.ts +30 -0
- package/src/nodes/member/methodSignature.ts +31 -0
- package/src/nodes/member/param.ts +22 -0
- package/src/nodes/member/property.ts +75 -0
- package/src/nodes/member/restParams.ts +22 -0
- package/src/nodes/member/tupleMember.ts +93 -0
- package/src/nodes/native/Iterable.ts +153 -0
- package/src/nodes/native/map.ts +91 -0
- package/src/nodes/native/nonSerializable.ts +42 -0
- package/src/nodes/native/promise.ts +43 -0
- package/src/nodes/native/set.ts +56 -0
- package/src/run-types-pure-fns.ts +116 -0
- package/src/types.ts +206 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2024 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
import {TypeObjectLiteral, TypeClass, TypeIntersection, ReflectionKind} from '@deepkit/type';
|
|
8
|
+
import type {JitCode} from '../../types.ts';
|
|
9
|
+
import type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
10
|
+
import {arrayToLiteral, getJitFnArgCallVarName, memorize, sortDiscriminatorsFirst} from '../../lib/utils.ts';
|
|
11
|
+
import {PropertyRunType} from '../member/property.ts';
|
|
12
|
+
import {BaseRunType, CollectionRunType, MemberRunType} from '../../lib/baseRunTypes.ts';
|
|
13
|
+
import {MethodSignatureRunType} from '../member/methodSignature.ts';
|
|
14
|
+
import {IndexSignatureRunType} from '../member/indexProperty.ts';
|
|
15
|
+
import {MethodRunType} from '../member/method.ts';
|
|
16
|
+
import {CallSignatureRunType} from '../member/callSignature.ts';
|
|
17
|
+
import {JitFunctions} from '../../constants.functions.ts';
|
|
18
|
+
import {isIndexSignatureRunType} from '../../lib/guards.ts';
|
|
19
|
+
import {cpf_getUnknownKeysFromArray, cpf_hasUnknownKeysFromArray} from '../../run-types-pure-fns.ts';
|
|
20
|
+
|
|
21
|
+
export type InterfaceMember =
|
|
22
|
+
| PropertyRunType
|
|
23
|
+
| MethodSignatureRunType
|
|
24
|
+
| IndexSignatureRunType
|
|
25
|
+
| MethodRunType
|
|
26
|
+
| CallSignatureRunType;
|
|
27
|
+
|
|
28
|
+
export class InterfaceRunType<
|
|
29
|
+
T extends TypeObjectLiteral | TypeClass | TypeIntersection = TypeObjectLiteral,
|
|
30
|
+
> extends CollectionRunType<T> {
|
|
31
|
+
getNamedChildren(comp: JitFnCompiler): InterfaceMember[] {
|
|
32
|
+
return this.getJitChildren(comp).filter((prop) => !!(prop.src as any).name) as InterfaceMember[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
isCallable(): boolean {
|
|
36
|
+
return this.getCallSignature() !== undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCallSignature = memorize((): CallSignatureRunType | undefined => {
|
|
40
|
+
return this.getChildRunTypes().find((prop) => prop.src.kind === ReflectionKind.callSignature) as CallSignatureRunType;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
getJitChildren(comp: JitFnCompiler): InterfaceMember[] {
|
|
44
|
+
const children = super.getJitChildren(comp) as InterfaceMember[];
|
|
45
|
+
return children.toSorted((a, b) => sortDiscriminatorsFirst(a, b)) as InterfaceMember[];
|
|
46
|
+
}
|
|
47
|
+
/** Split children in two groups: required and optional */
|
|
48
|
+
splitJitSplitChildren(comp: JitFnCompiler): {
|
|
49
|
+
/** all required properties */
|
|
50
|
+
required: PropertyRunType[];
|
|
51
|
+
/** all optional properties */
|
|
52
|
+
optional: PropertyRunType[];
|
|
53
|
+
/** all index signatures */
|
|
54
|
+
indexSignatures: IndexSignatureRunType[];
|
|
55
|
+
} {
|
|
56
|
+
const children = super.getJitChildren(comp) as InterfaceMember[];
|
|
57
|
+
const required = children.filter((prop) => !prop.isOptional()) as PropertyRunType[];
|
|
58
|
+
const optional = children.filter((prop) => prop.isOptional() && !isIndexSignatureRunType(prop)) as PropertyRunType[];
|
|
59
|
+
const indexSignatures = children.filter((prop) => isIndexSignatureRunType(prop)) as IndexSignatureRunType[];
|
|
60
|
+
return {required, optional, indexSignatures};
|
|
61
|
+
}
|
|
62
|
+
isPartOfUnion(): boolean {
|
|
63
|
+
return this.getParent()?.src.kind === ReflectionKind.union;
|
|
64
|
+
}
|
|
65
|
+
hasIndexSignature(comp: JitFnCompiler): boolean {
|
|
66
|
+
return this.getJitChildren(comp).some((prop) => isIndexSignatureRunType(prop));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// #### collection's jit code ####
|
|
70
|
+
|
|
71
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
72
|
+
const varName = comp.vλl;
|
|
73
|
+
const children = this.getJitChildren(comp);
|
|
74
|
+
const childrenCode = children
|
|
75
|
+
.map((prop) => comp.compileIsType(prop, 'E').code)
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join(' && ');
|
|
78
|
+
if (this.isCallable())
|
|
79
|
+
return {
|
|
80
|
+
code: [this.getCallSignature()!.emitIsType(comp).code, childrenCode].filter(Boolean).join(' && '),
|
|
81
|
+
type: 'E',
|
|
82
|
+
};
|
|
83
|
+
let propsCode = '';
|
|
84
|
+
if (comp.opts.strictTypes && !this.hasIndexSignature(comp)) {
|
|
85
|
+
const unknownCheck = callCheckUnknownProperties(this, comp, children, false, false);
|
|
86
|
+
if (unknownCheck) propsCode = `!${unknownCheck}`;
|
|
87
|
+
}
|
|
88
|
+
const objectCheck = this.isPartOfUnion() ? '' : `typeof ${varName} === 'object' && ${varName} !== null`;
|
|
89
|
+
const itemsCode = [objectCheck, this.allOptionalCode(comp), childrenCode, propsCode].filter(Boolean).join(' && ');
|
|
90
|
+
return {code: `(${itemsCode})`, type: 'E'};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
94
|
+
const varName = comp.vλl;
|
|
95
|
+
const children = this.getJitChildren(comp);
|
|
96
|
+
const childrenCode = children
|
|
97
|
+
.map((prop) => comp.compileTypeErrors(prop, 'S').code)
|
|
98
|
+
.filter(Boolean)
|
|
99
|
+
.join(';');
|
|
100
|
+
if (this.isCallable()) {
|
|
101
|
+
return {code: `${this.getCallSignature()!.emitTypeErrors(comp).code} else {${childrenCode}}`, type: 'S'};
|
|
102
|
+
}
|
|
103
|
+
let propsCode = '';
|
|
104
|
+
if (comp.opts.strictTypes && !this.hasIndexSignature(comp)) {
|
|
105
|
+
const unknownVar = comp.getLocalVarName('unk', this);
|
|
106
|
+
const keyVar = comp.getLocalVarName('ky', this);
|
|
107
|
+
const unknownValue = callCheckUnknownProperties(this, comp, children, true, false);
|
|
108
|
+
if (unknownValue) {
|
|
109
|
+
propsCode = `
|
|
110
|
+
const ${unknownVar} = ${unknownValue};
|
|
111
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}) {${comp.callJitErrWithPath('never', keyVar)}}}
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const objectCheck = this.isPartOfUnion() ? '' : `typeof ${varName} === 'object' && ${varName} !== null`;
|
|
116
|
+
const isObjectCode = [objectCheck, this.allOptionalCode(comp)].filter(Boolean).join(' && ');
|
|
117
|
+
return {
|
|
118
|
+
code: `
|
|
119
|
+
if (!(${isObjectCode})) {
|
|
120
|
+
${comp.callJitErr(this)};
|
|
121
|
+
} else {
|
|
122
|
+
${childrenCode}
|
|
123
|
+
${propsCode}
|
|
124
|
+
}
|
|
125
|
+
`,
|
|
126
|
+
type: 'S',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
130
|
+
if (this.isCallable()) return this.getCallSignature()!.emitPrepareForJson();
|
|
131
|
+
const children = this.getJitChildren(comp);
|
|
132
|
+
const childrenCode = children
|
|
133
|
+
.map((prop) => comp.compilePrepareForJson(prop, 'S').code)
|
|
134
|
+
.filter(Boolean)
|
|
135
|
+
.join(';');
|
|
136
|
+
return {code: childrenCode, type: 'S'};
|
|
137
|
+
}
|
|
138
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
139
|
+
if (this.isCallable()) return this.getCallSignature()!.emitRestoreFromJson();
|
|
140
|
+
const children = this.getJitChildren(comp);
|
|
141
|
+
const childrenCode = children
|
|
142
|
+
.map((prop) => comp.compileRestoreFromJson(prop, 'S').code)
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
.join(';');
|
|
145
|
+
return {code: childrenCode, type: 'S'};
|
|
146
|
+
}
|
|
147
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
148
|
+
const children = this.getJitChildren(comp);
|
|
149
|
+
const allChildren = this.getChildRunTypes().filter((prop) => !isIndexSignatureRunType(prop));
|
|
150
|
+
const hasIndexProp = children.some((prop) => isIndexSignatureRunType(prop));
|
|
151
|
+
const parentCode = hasIndexProp
|
|
152
|
+
? ''
|
|
153
|
+
: callCheckUnknownProperties(this, comp, children, false, !this.isPartOfUnion(), allChildren);
|
|
154
|
+
const childrenCode = super.emitHasUnknownKeys(comp).code;
|
|
155
|
+
return {code: [parentCode, childrenCode].filter(Boolean).join(' || '), type: 'E'};
|
|
156
|
+
}
|
|
157
|
+
emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
158
|
+
const children = this.getJitChildren(comp);
|
|
159
|
+
const allChildren = this.getChildRunTypes().filter((prop) => !isIndexSignatureRunType(prop));
|
|
160
|
+
const hasIndexProp = children.some((prop) => isIndexSignatureRunType(prop));
|
|
161
|
+
const unknownVar = comp.getLocalVarName('unk', this);
|
|
162
|
+
const keyVar = comp.getLocalVarName('ky', this);
|
|
163
|
+
const unknownValue = hasIndexProp
|
|
164
|
+
? undefined
|
|
165
|
+
: callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion(), allChildren);
|
|
166
|
+
const parentCode = `
|
|
167
|
+
const ${unknownVar} = ${unknownValue};
|
|
168
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}) {${comp.callJitErrWithPath('never', keyVar)}}}
|
|
169
|
+
`;
|
|
170
|
+
const childrenCode = super.emitUnknownKeyErrors(comp).code;
|
|
171
|
+
return {code: [unknownValue ? parentCode : '', childrenCode].filter(Boolean).join('\n'), type: 'S'};
|
|
172
|
+
}
|
|
173
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
174
|
+
const children = this.getJitChildren(comp);
|
|
175
|
+
const unknownVar = comp.getLocalVarName('unk', this);
|
|
176
|
+
const keyVar = comp.getLocalVarName('ky', this);
|
|
177
|
+
const hasIndexProp = children.some((prop) => isIndexSignatureRunType(prop));
|
|
178
|
+
const unknownValue = hasIndexProp
|
|
179
|
+
? undefined
|
|
180
|
+
: callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion());
|
|
181
|
+
const parentCode = `
|
|
182
|
+
const ${unknownVar} = ${unknownValue};
|
|
183
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}){delete ${comp.vλl}[${keyVar}]}}
|
|
184
|
+
`;
|
|
185
|
+
const childrenCode = super.emitStripUnknownKeys(comp).code;
|
|
186
|
+
return {code: [unknownValue ? parentCode : '', childrenCode].filter(Boolean).join('\n'), type: 'S'};
|
|
187
|
+
}
|
|
188
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {
|
|
189
|
+
const children = this.getJitChildren(comp);
|
|
190
|
+
const unknownVar = comp.getLocalVarName('unk', this);
|
|
191
|
+
const keyVar = comp.getLocalVarName('ky', this);
|
|
192
|
+
const hasIndexProp = children.some((prop) => isIndexSignatureRunType(prop));
|
|
193
|
+
const unknownValue = hasIndexProp
|
|
194
|
+
? undefined
|
|
195
|
+
: callCheckUnknownProperties(this, comp, children, true, !this.isPartOfUnion());
|
|
196
|
+
const parentCode = `
|
|
197
|
+
const ${unknownVar} = ${unknownValue};
|
|
198
|
+
if (${unknownVar}) {for (const ${keyVar} of ${unknownVar}){${comp.vλl}[${keyVar}] = undefined}}
|
|
199
|
+
`;
|
|
200
|
+
const childrenCode = super.emitUnknownKeysToUndefined(comp).code;
|
|
201
|
+
return {code: [unknownValue ? parentCode : '', childrenCode].filter(Boolean).join('\n'), type: 'S'};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// In order to json stringify to work properly optional properties must come first
|
|
205
|
+
getJsonStringifySortedChildren(comp: JitFnCompiler): MemberRunType<any>[] {
|
|
206
|
+
return this.getJitChildren(comp).toSorted((a, b) => {
|
|
207
|
+
const aOptional = a instanceof MemberRunType && a.isOptional();
|
|
208
|
+
const bOptional = b instanceof MemberRunType && b.isOptional();
|
|
209
|
+
if (aOptional && !bOptional) return -1;
|
|
210
|
+
if (!aOptional && bOptional) return 1;
|
|
211
|
+
return 0;
|
|
212
|
+
}) as MemberRunType<any>[];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// extra check to prevent empty array passing as object where all properties are optional
|
|
216
|
+
// when this check is disabled empty array will pass as object but fail when checking for properties
|
|
217
|
+
allOptionalCode(comp: JitFnCompiler): string {
|
|
218
|
+
const children = this.getJitChildren(comp);
|
|
219
|
+
if (children.length !== 0 && !this.areAllChildrenOptional(children)) return '';
|
|
220
|
+
const isNotArray = `!Array.isArray(${comp.vλl})`;
|
|
221
|
+
const ifNoNative = `Object.prototype.toString.call(${comp.vλl}) === '[object Object]'`;
|
|
222
|
+
return `(${isNotArray} && ${ifNoNative})`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
addObjectPropsToContext(comp: JitFnCompiler, jitChildrenRunTypes?: BaseRunType[], allChildrenRuntypes?: BaseRunType[]) {
|
|
226
|
+
const children = jitChildrenRunTypes || this.getJitChildren(comp);
|
|
227
|
+
const allChildren = allChildrenRuntypes || this.getChildRunTypes();
|
|
228
|
+
return addObjectPropsToContext(this, comp, children, allChildren);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface ObjectPropsContextResult {
|
|
233
|
+
keysName: string;
|
|
234
|
+
allKeysName: string;
|
|
235
|
+
hasNonJitChildren: boolean;
|
|
236
|
+
jitChildrenNames: string[];
|
|
237
|
+
allChildrenNames: string[];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Extracts object property names and adds them to the JIT compiler context.
|
|
242
|
+
*/
|
|
243
|
+
function addObjectPropsToContext(
|
|
244
|
+
rt: InterfaceRunType<any>,
|
|
245
|
+
comp: JitFnCompiler,
|
|
246
|
+
jitChildrenRunTypes: BaseRunType[],
|
|
247
|
+
allChildrenRuntypes?: BaseRunType[]
|
|
248
|
+
): ObjectPropsContextResult {
|
|
249
|
+
const jitArrNames = jitChildrenRunTypes.filter((prop) => !!(prop.src as any).name).map((prop) => (prop.src as any).name);
|
|
250
|
+
const AllArrNames = allChildrenRuntypes?.filter((prop) => !!(prop.src as any).name).map((prop) => (prop.src as any).name);
|
|
251
|
+
const jitChildrenNames = Array.from(new Set(jitArrNames));
|
|
252
|
+
const allChildrenNames = Array.from(new Set(AllArrNames));
|
|
253
|
+
const isSameLength = jitChildrenNames.length === allChildrenNames.length;
|
|
254
|
+
const isSameSet = isSameLength && jitChildrenNames.every((v) => allChildrenNames.includes(v));
|
|
255
|
+
const hasNonJitChildren = !(isSameLength && isSameSet);
|
|
256
|
+
const keysName = `k_${rt.getJitHash(comp.opts)}`;
|
|
257
|
+
const allKeysName = `kA_${rt.getJitHash(comp.opts)}`;
|
|
258
|
+
|
|
259
|
+
comp.setContextItem(keysName, `const ${keysName} = ${arrayToLiteral(jitChildrenNames)}`);
|
|
260
|
+
if (hasNonJitChildren) comp.setContextItem(allKeysName, `const ${allKeysName} = ${arrayToLiteral(allChildrenNames)}`);
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
keysName,
|
|
264
|
+
allKeysName,
|
|
265
|
+
hasNonJitChildren,
|
|
266
|
+
jitChildrenNames,
|
|
267
|
+
allChildrenNames,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// TODO: look like some of this logic should be moved to index prop ? Also the runtime
|
|
272
|
+
function callCheckUnknownProperties(
|
|
273
|
+
rt: InterfaceRunType<any>,
|
|
274
|
+
comp: JitFnCompiler,
|
|
275
|
+
jitChildrenRunTypes: BaseRunType[],
|
|
276
|
+
returnKeys: boolean,
|
|
277
|
+
checkObject = true,
|
|
278
|
+
allChildrenRuntypes?: BaseRunType[]
|
|
279
|
+
): string {
|
|
280
|
+
const result = addObjectPropsToContext(rt, comp, jitChildrenRunTypes, allChildrenRuntypes);
|
|
281
|
+
|
|
282
|
+
if (result.jitChildrenNames.length === 0 && result.allChildrenNames.length === 0) return '';
|
|
283
|
+
|
|
284
|
+
const objectCheckCode = checkObject ? [`typeof ${comp.vλl} === 'object'`, `${comp.vλl} !== null`] : [];
|
|
285
|
+
const checkPropName = JitFunctions.hasUnknownKeys.runTimeOptions.checkNonJitProps.keyName;
|
|
286
|
+
const optsVarName = getJitFnArgCallVarName(comp, rt, JitFunctions.hasUnknownKeys.id, 'θpts');
|
|
287
|
+
const conditional =
|
|
288
|
+
allChildrenRuntypes?.length && result.hasNonJitChildren
|
|
289
|
+
? `${optsVarName}.${checkPropName} ? ${result.allKeysName} : ${result.keysName}`
|
|
290
|
+
: result.keysName;
|
|
291
|
+
if (returnKeys) {
|
|
292
|
+
const getUnknownKeysFn = comp.addPureFunction(cpf_getUnknownKeysFromArray);
|
|
293
|
+
return `${getUnknownKeysFn}(${comp.vλl}, ${conditional})`;
|
|
294
|
+
}
|
|
295
|
+
const hasUnknownKeysFn = comp.addPureFunction(cpf_hasUnknownKeysFromArray);
|
|
296
|
+
objectCheckCode.push(`${hasUnknownKeysFn}(${comp.vλl}, ${conditional})`);
|
|
297
|
+
const filtered = objectCheckCode.filter(Boolean);
|
|
298
|
+
if (filtered.length > 1) return `(${filtered.join(' && ')})`;
|
|
299
|
+
return filtered[0];
|
|
300
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2024 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
|
|
8
|
+
import {TypeIntersection} from '@deepkit/type';
|
|
9
|
+
import {InterfaceRunType} from './interface.ts';
|
|
10
|
+
import {type JitCode} from '../../types.ts';
|
|
11
|
+
|
|
12
|
+
/** IMPORTANT:
|
|
13
|
+
* Intersection are already resolved by deepkit so seems like this runType wont ever be called
|
|
14
|
+
* ie: type A = {a: string} & {b: number} will be resolved to ObjectLiteral {a: string, b: number}
|
|
15
|
+
* ie: type NeVer = string & number will be resolved to never
|
|
16
|
+
* */
|
|
17
|
+
export class IntersectionRunType extends InterfaceRunType<TypeIntersection> {
|
|
18
|
+
compileIsType(): JitCode {
|
|
19
|
+
throw new Error('Intersection validation not supported, should be resolve to other RunTypes');
|
|
20
|
+
}
|
|
21
|
+
compileTypeErrors(): JitCode {
|
|
22
|
+
throw new Error('Intersection validation not supported, should be resolve to other RunTypes');
|
|
23
|
+
}
|
|
24
|
+
compilePrepareForJson(): JitCode {
|
|
25
|
+
throw new Error('Intersection serialization not supported, should be resolve to other RunTypes');
|
|
26
|
+
}
|
|
27
|
+
compileRestoreFromJson(): JitCode {
|
|
28
|
+
throw new Error('Intersection serialization not supported, should be resolve to other RunTypes');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2024 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
|
|
8
|
+
import type {TypeFunction, TypeTuple} from '@deepkit/type';
|
|
9
|
+
import type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
10
|
+
import type {AnyParameterListRunType, SrcType, JitCode} from '../../types.ts';
|
|
11
|
+
import {ParameterRunType} from '../member/param.ts';
|
|
12
|
+
import {CollectionRunType} from '../../lib/baseRunTypes.ts';
|
|
13
|
+
import {TupleMemberRunType} from '../member/tupleMember.ts';
|
|
14
|
+
|
|
15
|
+
type AnyParamRunType = ParameterRunType | TupleMemberRunType;
|
|
16
|
+
|
|
17
|
+
export class TupleRunType<
|
|
18
|
+
ParamList extends AnyParameterListRunType = TypeTuple,
|
|
19
|
+
ParamType extends AnyParamRunType = TupleMemberRunType,
|
|
20
|
+
> extends CollectionRunType<ParamList> {
|
|
21
|
+
getChildRunTypes = (): ParamType[] => {
|
|
22
|
+
const childTypes = ((this.src as TypeFunction).parameters || (this.src as TypeTuple).types || []) as SrcType[];
|
|
23
|
+
return childTypes.map((t) => t._rt as ParamType);
|
|
24
|
+
};
|
|
25
|
+
getParamRunTypes(comp: JitFnCompiler): ParamType[] {
|
|
26
|
+
const start = comp.opts?.paramsSlice?.start;
|
|
27
|
+
const end = comp.opts?.paramsSlice?.end;
|
|
28
|
+
const children = this.getChildRunTypes();
|
|
29
|
+
if (!start && !end) return children;
|
|
30
|
+
// Get all child run types first without using comp to avoid recursion
|
|
31
|
+
return children.slice(start, end);
|
|
32
|
+
}
|
|
33
|
+
hasRestParameter(comp: JitFnCompiler): boolean {
|
|
34
|
+
return (
|
|
35
|
+
!!this.getParamRunTypes(comp).length && this.getParamRunTypes(comp)[this.getParamRunTypes(comp).length - 1].isRest()
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
totalRequiredParams(comp: JitFnCompiler): number {
|
|
39
|
+
return this.getParamRunTypes(comp).filter((p) => !p.isOptional() && !p.isRest()).length;
|
|
40
|
+
}
|
|
41
|
+
// ####### params #######
|
|
42
|
+
|
|
43
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
44
|
+
const children = this.getParamRunTypes(comp);
|
|
45
|
+
if (children.length === 0 && comp.opts.noIsArrayCheck) return {code: undefined, type: 'E'};
|
|
46
|
+
if (children.length === 0) return {code: `Array.isArray(${comp.vλl}) && ${comp.vλl}.length === 0`, type: 'E'};
|
|
47
|
+
const lengthCode = this.hasRestParameter(comp) ? '' : `&& ${comp.vλl}.length <= ${this.getParamRunTypes(comp).length}`;
|
|
48
|
+
const paramsCode = children.map((p) => `(${comp.compileIsType(p, 'E').code})`).join(' && ');
|
|
49
|
+
const checkIsArrayCode = comp.opts.noIsArrayCheck ? '' : `Array.isArray(${comp.vλl})${lengthCode} && `;
|
|
50
|
+
return {code: `(${checkIsArrayCode} ${paramsCode})`, type: 'E'};
|
|
51
|
+
}
|
|
52
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
53
|
+
const children = this.getParamRunTypes(comp);
|
|
54
|
+
if (children.length === 0 && comp.opts.noIsArrayCheck) return {code: undefined, type: 'S'};
|
|
55
|
+
if (children.length === 0)
|
|
56
|
+
return {code: `if (!Array.isArray(${comp.vλl}) || && ${comp.vλl}.length === 0) ${comp.callJitErr(this)}`, type: 'S'};
|
|
57
|
+
const lengthCode = this.hasRestParameter(comp) ? '' : `|| ${comp.vλl}.length > ${this.getParamRunTypes(comp).length}`;
|
|
58
|
+
const paramsCode = children.map((p) => comp.compileTypeErrors(p, 'S').code).join(';');
|
|
59
|
+
if (comp.opts.noIsArrayCheck) return {code: paramsCode, type: 'S'};
|
|
60
|
+
return {code: `if (!Array.isArray(${comp.vλl})${lengthCode}) ${comp.callJitErr(this)}; else {${paramsCode}}`, type: 'S'};
|
|
61
|
+
}
|
|
62
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
63
|
+
const children = this.getParamRunTypes(comp);
|
|
64
|
+
if (!children.length) return {code: undefined, type: 'S'};
|
|
65
|
+
const code = children
|
|
66
|
+
.map((p) => comp.compilePrepareForJson(p, 'S').code)
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join(';');
|
|
69
|
+
return {code: code, type: 'S'};
|
|
70
|
+
}
|
|
71
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
72
|
+
const children = this.getParamRunTypes(comp);
|
|
73
|
+
if (!children.length) return {code: undefined, type: 'S'};
|
|
74
|
+
const code = children
|
|
75
|
+
.map((p) => comp.compileRestoreFromJson(p, 'S').code)
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join(';');
|
|
78
|
+
return {code: code, type: 'S'};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2024 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
|
|
8
|
+
import {ReflectionKind, type TypeUnion} from '@deepkit/type';
|
|
9
|
+
import type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
10
|
+
import type {JitCode} from '../../types.ts';
|
|
11
|
+
import {BaseRunType, CollectionRunType} from '../../lib/baseRunTypes.ts';
|
|
12
|
+
import {childIsExpression, createIfElseFn, toLiteral} from '../../lib/utils.ts';
|
|
13
|
+
import {isClassRunType, isInterfaceRunType, isIntersectionRunType, isObjectLiteralRunType} from '../../lib/guards.ts';
|
|
14
|
+
import {markDiscriminators, splitUnionItems, SplitUnionResult} from './unionDiscriminator.ts';
|
|
15
|
+
import type {PropertyRunType} from '../member/property.ts';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Unions get encoded into an array where arr[0] is the discriminator and arr[1] is the value.
|
|
19
|
+
* this is because some times we can't distinguish the type of an union.
|
|
20
|
+
* ie: bigint gets encoded into an string, so if we have an union 'type U = string | bigint' we can't distinguish between the when encoding/decoding the json.
|
|
21
|
+
* to solve this issue the index of the type is used as a discriminator.
|
|
22
|
+
* So [0, "123n"] is interpreted as a string and [1, "123n"] is interpreted as a bigint.
|
|
23
|
+
* */
|
|
24
|
+
export class UnionRunType extends CollectionRunType<TypeUnion> {
|
|
25
|
+
hasDiscriminators: boolean | undefined = undefined;
|
|
26
|
+
hasObjectTypes: boolean | undefined = undefined;
|
|
27
|
+
|
|
28
|
+
isTypeWithProperties(rt: BaseRunType) {
|
|
29
|
+
return (
|
|
30
|
+
rt.getFamily() === 'C' &&
|
|
31
|
+
(isInterfaceRunType(rt) || isClassRunType(rt) || isObjectLiteralRunType(rt) || isIntersectionRunType(rt))
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getUnionChildren(comp: JitFnCompiler): SplitUnionResult {
|
|
36
|
+
const children = this.getJitChildren(comp);
|
|
37
|
+
markDiscriminators(comp, this, children);
|
|
38
|
+
return splitUnionItems(comp, this, children);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getUnionItemIndex(comp: JitFnCompiler, unionItem: BaseRunType): number {
|
|
42
|
+
const children = this.getJitChildren(comp);
|
|
43
|
+
const index = children.findIndex((child) => child === unionItem);
|
|
44
|
+
if (index === -1) throw new Error(`Item ${unionItem.getTypeName()} not found in union ${this.getTypeName()}`);
|
|
45
|
+
return index;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns isType check for a union child with loose matching.
|
|
50
|
+
* Uses first-match strategy: returns first matching type in declaration order.
|
|
51
|
+
* For all-optional types (weak types), ensures at least one property matches or is empty object.
|
|
52
|
+
* Note: Use ESLint rules @mionjs/no-unreachable-union-types and @mionjs/no-mixed-union-properties
|
|
53
|
+
* to detect overlapping union types at compile time.
|
|
54
|
+
* @see union.spec.ts 'Union Obj' and 'Union Mixed' test suites for examples.
|
|
55
|
+
*/
|
|
56
|
+
getChildIsTypeWithLooseCheck(rt: BaseRunType, comp: JitFnCompiler): string {
|
|
57
|
+
const isTypeCode = comp.compileIsType(rt, 'E').code || '';
|
|
58
|
+
const isTypeWithProperties =
|
|
59
|
+
isInterfaceRunType(rt) || isClassRunType(rt) || isObjectLiteralRunType(rt) || isIntersectionRunType(rt);
|
|
60
|
+
if (!isTypeWithProperties || rt.getFamily() !== 'C') return isTypeCode;
|
|
61
|
+
const props = rt.getJitChildren(comp);
|
|
62
|
+
const hasIndexProperty = props.some((prop) => prop.src.kind === ReflectionKind.indexSignature);
|
|
63
|
+
if (hasIndexProperty) return isTypeCode;
|
|
64
|
+
const isAllOptional = rt.areAllChildrenOptional(props);
|
|
65
|
+
// For all-optional types (weak types), TypeScript requires at least one matching property
|
|
66
|
+
// or an empty object. This prevents {c: 'hello'} from matching {a?: string; b?: string}
|
|
67
|
+
if (isAllOptional && props.length > 0) {
|
|
68
|
+
// Must have at least one of this type's own props OR be empty
|
|
69
|
+
const hasOwnPropCheck = props.map((p) => {
|
|
70
|
+
const name = (p as PropertyRunType).getPropertyName();
|
|
71
|
+
return `(${toLiteral(name)} in ${comp.vλl})`;
|
|
72
|
+
});
|
|
73
|
+
hasOwnPropCheck.push(`Object.keys(${comp.vλl}).length === 0`);
|
|
74
|
+
const weakTypeCheck = `(${hasOwnPropCheck.join(' || ')})`;
|
|
75
|
+
return `(${isTypeCode} && ${weakTypeCheck})`;
|
|
76
|
+
}
|
|
77
|
+
return isTypeCode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Loose union matching: returns first matching type in declaration order.
|
|
82
|
+
* Objects with properties from multiple union types will match the first compatible type.
|
|
83
|
+
* Use ESLint rules to detect overlapping types at compile time.
|
|
84
|
+
*/
|
|
85
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
86
|
+
this.checkAllowedChildren(comp);
|
|
87
|
+
const {simpleItems, objectTypes, anyItem} = this.getUnionChildren(comp);
|
|
88
|
+
// Simple items (atomic types) don't need null guard
|
|
89
|
+
const simpleChecks = simpleItems.map((rt) => this.getChildIsTypeWithLooseCheck(rt, comp)).filter(Boolean);
|
|
90
|
+
// Object types need null guard to prevent accessing properties on null
|
|
91
|
+
const objChecks = objectTypes.map((rt) => this.getChildIsTypeWithLooseCheck(rt, comp)).filter(Boolean);
|
|
92
|
+
const objCode = objChecks.length
|
|
93
|
+
? `(typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && (${objChecks.join(' || ')}))`
|
|
94
|
+
: '';
|
|
95
|
+
// any/unknown checked last as fallback
|
|
96
|
+
const anyCheck = anyItem ? this.getChildIsTypeWithLooseCheck(anyItem, comp) : '';
|
|
97
|
+
const allChecks = [...simpleChecks, objCode, anyCheck].filter(Boolean);
|
|
98
|
+
return {code: `(${allChecks.join(' || ')})`, type: 'E'};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
102
|
+
this.checkAllowedChildren(comp);
|
|
103
|
+
const isType = comp.compileIsType(this, 'E').code;
|
|
104
|
+
const code = `if (!${isType}) ${comp.callJitErr(this)};`;
|
|
105
|
+
return {code, type: 'S'};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* When a union is encodes to json is encode into and array with two elements: [unionDiscriminator, encoded Value]
|
|
110
|
+
* the first element is the index of the type in the union.
|
|
111
|
+
* the second element is the encoded value of the type.
|
|
112
|
+
* ie: type union = string | number | bigint; var v1: union = 123n; v1 is encoded as [2, "123n"]
|
|
113
|
+
*/
|
|
114
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
115
|
+
this.checkAllowedChildren(comp);
|
|
116
|
+
const {simpleItems, objectTypes, anyItem} = this.getUnionChildren(comp);
|
|
117
|
+
const errName = comp.getLocalVarName('uErr', this);
|
|
118
|
+
const fail = `throw new Error(${errName});`;
|
|
119
|
+
comp.setContextItem(errName, `const ${errName} = "Can not json encode union: item does not belong to the union"`);
|
|
120
|
+
|
|
121
|
+
const ifElse = createIfElseFn();
|
|
122
|
+
|
|
123
|
+
// Helper to generate encode code for a union item
|
|
124
|
+
const getEncodeCode = (childRt: BaseRunType) => {
|
|
125
|
+
const toJit = comp.compilePrepareForJson(childRt, 'S');
|
|
126
|
+
const fromJit = comp.compileRestoreFromJson(childRt, 'S');
|
|
127
|
+
const needsTupleEncoding = !!toJit.code || !!fromJit.code;
|
|
128
|
+
const isExpression = childIsExpression(toJit, childRt);
|
|
129
|
+
const encodeCode = isExpression && toJit.code ? `${comp.vλl} = ${toJit.code};` : toJit.code || '';
|
|
130
|
+
const index = this.getUnionItemIndex(comp, childRt);
|
|
131
|
+
const tupleEncode = needsTupleEncoding ? `${comp.vλl} = [${index}, ${comp.vλl}]` : '/*noop*/';
|
|
132
|
+
return `${encodeCode} ${tupleEncode}`;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Generate code for simple items (atomic types)
|
|
136
|
+
const simpleCode = simpleItems.map((rt) => {
|
|
137
|
+
const isTypeCode = this.getChildIsTypeWithLooseCheck(rt, comp);
|
|
138
|
+
return `${ifElse()} (${isTypeCode}) {${getEncodeCode(rt)}}`;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Generate code for object types (need null guard)
|
|
142
|
+
const objCode = objectTypes.length
|
|
143
|
+
? objectTypes.map((rt) => {
|
|
144
|
+
const isTypeCode = this.getChildIsTypeWithLooseCheck(rt, comp);
|
|
145
|
+
return `${ifElse()} (typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && ${isTypeCode}) {${getEncodeCode(rt)}}`;
|
|
146
|
+
})
|
|
147
|
+
: [];
|
|
148
|
+
|
|
149
|
+
// Generate code for anyItem (always matches, checked last as fallback)
|
|
150
|
+
const anyCode = anyItem ? `${ifElse(true)} {${getEncodeCode(anyItem)}}` : `${ifElse(true)} {${fail}}`;
|
|
151
|
+
|
|
152
|
+
return {code: [...simpleCode, ...objCode, anyCode].join(''), type: 'S'};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* When a union is decoded from json it expects de two elements array format: [unionDiscriminator, Value to decode]
|
|
157
|
+
* the first element is the index of the type in the union.
|
|
158
|
+
* the second element is the encoded value of the type.
|
|
159
|
+
* ie: type union = string | number | bigint; var v1: union = 123n; v1 is encoded as [2, "123n"]
|
|
160
|
+
*/
|
|
161
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
162
|
+
this.checkAllowedChildren(comp);
|
|
163
|
+
const decVar = comp.getLocalVarName('dec', this);
|
|
164
|
+
const errVarName = comp.getLocalVarName('uErr', this);
|
|
165
|
+
comp.setContextItem(errVarName, `const ${errVarName} = "Can not json decode union: invalid union index"`);
|
|
166
|
+
const children = this.getJitChildren(comp);
|
|
167
|
+
const ifElse = createIfElseFn();
|
|
168
|
+
const itemsCode = children
|
|
169
|
+
.map((unionItem) => {
|
|
170
|
+
const childJit = comp.compileRestoreFromJson(unionItem, 'S');
|
|
171
|
+
const isExpression = childIsExpression(childJit, unionItem);
|
|
172
|
+
const code =
|
|
173
|
+
isExpression && childJit.code && childJit.code !== comp.vλl
|
|
174
|
+
? `${comp.vλl} = ${childJit.code}`
|
|
175
|
+
: childJit.code || '';
|
|
176
|
+
// item is decoded before being extracted from the array
|
|
177
|
+
const index = this.getUnionItemIndex(comp, unionItem);
|
|
178
|
+
return `${ifElse()} (${decVar} === ${index}) {${code || '/*noop*/'}}`;
|
|
179
|
+
})
|
|
180
|
+
.filter(Boolean);
|
|
181
|
+
const childrenCode = itemsCode.join('');
|
|
182
|
+
const failCode = childrenCode ? `else {throw new Error(${errVarName})}` : '';
|
|
183
|
+
const code = `
|
|
184
|
+
if (${comp.vλl}?.length === 2 && Array.isArray(${comp.vλl}) && typeof ${comp.vλl}[0] === 'number') {
|
|
185
|
+
const ${decVar} = ${comp.vλl}[0]; ${comp.vλl} = ${comp.vλl}[1];
|
|
186
|
+
${childrenCode}
|
|
187
|
+
${failCode}
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
return {code, type: 'S'};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getUnionTypeNames(): string {
|
|
194
|
+
return this.getChildRunTypes()
|
|
195
|
+
.map((rt) => rt.getTypeName())
|
|
196
|
+
.join(' | ');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
checkAllowedChildren(comp: JitFnCompiler) {
|
|
200
|
+
const allChildren = this.getChildRunTypes();
|
|
201
|
+
const toSkip = allChildren.filter((rt) => rt.skipJit(comp));
|
|
202
|
+
if (toSkip.length)
|
|
203
|
+
throw new Error(`Union can not have non serializable types, ie: Symbol, Function, etc. \nType: ${this.stringify()}`);
|
|
204
|
+
}
|
|
205
|
+
}
|