@mionjs/run-types 0.8.7 → 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 +8 -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,259 @@
|
|
|
1
|
+
import type {BaseRunType, CollectionRunType, MemberRunType} from '../../lib/baseRunTypes.ts';
|
|
2
|
+
import type {JitFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
3
|
+
import type {UnionRunType} from './union.ts';
|
|
4
|
+
import type {PropertyRunType} from '../member/property.ts';
|
|
5
|
+
import {getTotalComplexity, sortRunTypeByComplexity} from '../../lib/utils.ts';
|
|
6
|
+
import {isAnyRunType, isUnknownRunType} from '../../lib/guards.ts';
|
|
7
|
+
|
|
8
|
+
export type FlattenedProp = {
|
|
9
|
+
/** union item, parent of the property */
|
|
10
|
+
unionItem: CollectionRunType<any>;
|
|
11
|
+
/** index of the union item in the union */
|
|
12
|
+
unionIndex: string | number;
|
|
13
|
+
/** one property of the union item */
|
|
14
|
+
prop: PropertyRunType;
|
|
15
|
+
/** typeID of the property */
|
|
16
|
+
typeID: string | number;
|
|
17
|
+
/** name of the property as it should be used in the code */
|
|
18
|
+
compiledName: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type SplitUnionResult = {
|
|
22
|
+
simpleItems: BaseRunType[];
|
|
23
|
+
objectTypes: CollectionRunType<any>[];
|
|
24
|
+
/** any or unknown type if present in the union, should be checked last */
|
|
25
|
+
anyItem?: BaseRunType;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Split the union types in two groups: interface types and simple types
|
|
30
|
+
* interface types are types that have properties, simple types are the rest (atomic types, tuples, etc)
|
|
31
|
+
* If any or unknown types are present, they are extracted and returned separately as anyItem
|
|
32
|
+
* so they can be checked last (any/unknown would match anything, so must be last resort)
|
|
33
|
+
*/
|
|
34
|
+
export function splitUnionItems(comp: JitFnCompiler, urt: UnionRunType, unionChildren?: BaseRunType[]): SplitUnionResult {
|
|
35
|
+
const unionItems = unionChildren || urt.getJitChildren(comp);
|
|
36
|
+
const objectTypes: CollectionRunType<any>[] = [];
|
|
37
|
+
const simpleItems: BaseRunType[] = [];
|
|
38
|
+
let anyItem: BaseRunType | undefined;
|
|
39
|
+
|
|
40
|
+
unionItems.forEach((unionItem) => {
|
|
41
|
+
// Extract any/unknown types to be checked last
|
|
42
|
+
if (isAnyRunType(unionItem) || isUnknownRunType(unionItem)) {
|
|
43
|
+
// Only keep the first any/unknown type (having multiple is redundant)
|
|
44
|
+
if (!anyItem) anyItem = unionItem;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const isObj = urt.isTypeWithProperties(unionItem);
|
|
48
|
+
if (!isObj) return simpleItems.push(unionItem);
|
|
49
|
+
return objectTypes.push(unionItem as CollectionRunType<any>);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Sort object types to prevent unreachable types (objects with more props should come first when they share same prop types)
|
|
53
|
+
const sortedObjectTypes = sortUnreachableTypes(comp, objectTypes);
|
|
54
|
+
|
|
55
|
+
return {simpleItems, objectTypes: sortedObjectTypes, anyItem};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sorts object types to prevent unreachable union types.
|
|
60
|
+
* When two objects share the same properties (by typeID), the one with more properties must come first.
|
|
61
|
+
* This ensures that at runtime, the more specific type is checked before the less specific one.
|
|
62
|
+
* Objects that don't share properties with others maintain their relative order.
|
|
63
|
+
*/
|
|
64
|
+
export function sortUnreachableTypes(comp: JitFnCompiler, objectTypes: CollectionRunType<any>[]): CollectionRunType<any>[] {
|
|
65
|
+
if (objectTypes.length <= 1) return objectTypes;
|
|
66
|
+
|
|
67
|
+
// Get property typeIDs for each object type
|
|
68
|
+
const typePropsMap = new Map<CollectionRunType<any>, Set<string | number>>();
|
|
69
|
+
objectTypes.forEach((objType) => {
|
|
70
|
+
const props = objType.getJitChildren(comp) as PropertyRunType[];
|
|
71
|
+
const propTypeIDs = new Set<string | number>();
|
|
72
|
+
props.forEach((prop) => propTypeIDs.add(prop.getTypeID()));
|
|
73
|
+
typePropsMap.set(objType, propTypeIDs);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Check if one object's props are a subset of another's (all props have same typeIDs)
|
|
77
|
+
const isSubsetOf = (smaller: CollectionRunType<any>, larger: CollectionRunType<any>): boolean => {
|
|
78
|
+
const smallerProps = typePropsMap.get(smaller)!;
|
|
79
|
+
const largerProps = typePropsMap.get(larger)!;
|
|
80
|
+
if (smallerProps.size >= largerProps.size) return false;
|
|
81
|
+
for (const typeID of smallerProps) {
|
|
82
|
+
if (!largerProps.has(typeID)) return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Find groups of objects that share properties (one is subset of another)
|
|
88
|
+
const processed = new Set<CollectionRunType<any>>();
|
|
89
|
+
const result: CollectionRunType<any>[] = [];
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < objectTypes.length; i++) {
|
|
92
|
+
const current = objectTypes[i];
|
|
93
|
+
if (processed.has(current)) continue;
|
|
94
|
+
|
|
95
|
+
// Find all objects that are related (subset/superset) to current
|
|
96
|
+
const relatedGroup: CollectionRunType<any>[] = [current];
|
|
97
|
+
processed.add(current);
|
|
98
|
+
|
|
99
|
+
for (let j = 0; j < objectTypes.length; j++) {
|
|
100
|
+
if (i === j) continue;
|
|
101
|
+
const other = objectTypes[j];
|
|
102
|
+
if (processed.has(other)) continue;
|
|
103
|
+
|
|
104
|
+
// Check if current and other are related (one is subset of the other)
|
|
105
|
+
if (isSubsetOf(current, other) || isSubsetOf(other, current)) {
|
|
106
|
+
relatedGroup.push(other);
|
|
107
|
+
processed.add(other);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Sort related group by number of properties (more props first)
|
|
112
|
+
if (relatedGroup.length > 1) {
|
|
113
|
+
relatedGroup.sort((a, b) => {
|
|
114
|
+
const aSize = typePropsMap.get(a)!.size;
|
|
115
|
+
const bSize = typePropsMap.get(b)!.size;
|
|
116
|
+
return bSize - aSize; // descending order (more props first)
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
result.push(...relatedGroup);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Mark discriminator properties so they can be sorted and validate union more efficiently.
|
|
128
|
+
* @param comp
|
|
129
|
+
* @param urt
|
|
130
|
+
*/
|
|
131
|
+
export function markDiscriminators(comp: JitFnCompiler, urt: UnionRunType, unionItems: BaseRunType[]) {
|
|
132
|
+
if (urt.hasDiscriminators !== undefined && urt.hasObjectTypes !== undefined) return;
|
|
133
|
+
const objectTypes = unionItems.filter((item) => urt.isTypeWithProperties(item)) as CollectionRunType<any>[];
|
|
134
|
+
const namedDiscriminators = getDiscriminatorProperties(comp, urt, objectTypes, initGetCompiledName());
|
|
135
|
+
const uniqueDiscriminators = getUniqueDiscriminatorProperties(comp, urt, objectTypes, initGetCompiledName());
|
|
136
|
+
urt.hasObjectTypes = !!objectTypes.length;
|
|
137
|
+
urt.hasDiscriminators = !!namedDiscriminators.length || !!uniqueDiscriminators.length;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
type PropUnionItemPair = {prop: PropertyRunType; unionItem: CollectionRunType<any>};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Find a property with the same name in all the types of the union and that has different types.
|
|
144
|
+
* It also marks those properties as discriminator properties so can be sorted later
|
|
145
|
+
*/
|
|
146
|
+
function getDiscriminatorProperties(
|
|
147
|
+
comp: JitFnCompiler,
|
|
148
|
+
urt: UnionRunType,
|
|
149
|
+
unionTypes: CollectionRunType<any>[],
|
|
150
|
+
getCompiledName: (comp: JitFnCompiler, urt: UnionRunType, propTypeID: string | number) => string
|
|
151
|
+
): FlattenedProp[] {
|
|
152
|
+
if (!unionTypes.length) return [];
|
|
153
|
+
const propByName = new Map<string | number, PropUnionItemPair[]>();
|
|
154
|
+
unionTypes.forEach((unionItem) => {
|
|
155
|
+
const props = unionItem.getJitChildren(comp) as PropertyRunType[];
|
|
156
|
+
props.forEach((prop) => {
|
|
157
|
+
const name = prop.getChildVarName(comp);
|
|
158
|
+
const existing = propByName.get(name) || [];
|
|
159
|
+
// index no needed now
|
|
160
|
+
propByName.set(name, [...existing, {prop, unionItem}]);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
const propsOnAllTypes = Array.from(propByName.entries())
|
|
164
|
+
// filter all properties that are in all types
|
|
165
|
+
.filter(([, props]) => props.length === unionTypes.length)
|
|
166
|
+
// calculate complexity and check if all types are different in all props
|
|
167
|
+
.map(([key, props]) => ({
|
|
168
|
+
name: key,
|
|
169
|
+
props,
|
|
170
|
+
complexity: props.reduce((acc, item) => acc + getTotalComplexity(comp, item.prop), 0),
|
|
171
|
+
isUniqueType: props.every((item) => {
|
|
172
|
+
const child = item;
|
|
173
|
+
const typeID = child.prop.getTypeID();
|
|
174
|
+
const isDiff = props.every((otherItem) => child.prop === otherItem.prop || otherItem.prop.getTypeID() !== typeID);
|
|
175
|
+
return isDiff;
|
|
176
|
+
}),
|
|
177
|
+
}))
|
|
178
|
+
.filter((item) => item.isUniqueType);
|
|
179
|
+
const lessComplexProps = propsOnAllTypes.toSorted((a, b) => a.complexity - b.complexity);
|
|
180
|
+
const lessComplex = lessComplexProps[0];
|
|
181
|
+
if (!lessComplex) return [];
|
|
182
|
+
// we need to marks the property as discriminator so they can be sorted and checked first later
|
|
183
|
+
return lessComplex.props.map((item) => {
|
|
184
|
+
item.prop.isUnionDiscriminator = true;
|
|
185
|
+
const unionIndex = urt.getUnionItemIndex(comp, item.unionItem);
|
|
186
|
+
const typeID = item.prop.getTypeID();
|
|
187
|
+
return {
|
|
188
|
+
unionItem: item.unionItem,
|
|
189
|
+
unionIndex,
|
|
190
|
+
prop: item.prop,
|
|
191
|
+
typeID,
|
|
192
|
+
compiledName: getCompiledName(comp, urt, typeID),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get unique properties in the union as discriminators.
|
|
199
|
+
* These properties can be of different name but are unique in the union so can act as discriminators.
|
|
200
|
+
* It also marks those properties as discriminator properties so can be sorted later.
|
|
201
|
+
* */
|
|
202
|
+
function getUniqueDiscriminatorProperties(
|
|
203
|
+
comp: JitFnCompiler,
|
|
204
|
+
urt: UnionRunType,
|
|
205
|
+
unionTypes: CollectionRunType<any>[],
|
|
206
|
+
getCompiledName: (comp: JitFnCompiler, urt: UnionRunType, propTypeID: string | number) => string
|
|
207
|
+
): FlattenedProp[] {
|
|
208
|
+
if (!unionTypes.length) return [];
|
|
209
|
+
const uniquePropByUnionItem = new Map<CollectionRunType<any>, PropUnionItemPair>();
|
|
210
|
+
unionTypes.forEach((unionItem) => {
|
|
211
|
+
const props = unionItem.getJitChildren(comp) as PropertyRunType[];
|
|
212
|
+
props.forEach((prop) => {
|
|
213
|
+
const typeID = prop.getTypeID();
|
|
214
|
+
const isUnique = unionTypes.every((otherUnionItem) => {
|
|
215
|
+
if (otherUnionItem === unionItem) return true;
|
|
216
|
+
const otherProps = otherUnionItem.getJitChildren(comp) as MemberRunType<any>[];
|
|
217
|
+
return otherProps.every((otherProp) => otherProp.getTypeID() !== typeID);
|
|
218
|
+
});
|
|
219
|
+
if (isUnique) {
|
|
220
|
+
const existing = uniquePropByUnionItem.get(unionItem);
|
|
221
|
+
if (!existing) {
|
|
222
|
+
uniquePropByUnionItem.set(unionItem, {
|
|
223
|
+
prop,
|
|
224
|
+
unionItem,
|
|
225
|
+
});
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const newItem = {prop, unionItem};
|
|
229
|
+
const lessComplex = [newItem, existing].toSorted((a, b) => sortRunTypeByComplexity(comp, a.prop, b.prop))[0];
|
|
230
|
+
uniquePropByUnionItem.set(unionItem, lessComplex);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
if (!uniquePropByUnionItem.size) return [];
|
|
235
|
+
const uniqueProps = Array.from(uniquePropByUnionItem.values());
|
|
236
|
+
return uniqueProps.map((item) => {
|
|
237
|
+
item.prop.isUnionDiscriminator = true;
|
|
238
|
+
const unionIndex = urt.getUnionItemIndex(comp, item.unionItem);
|
|
239
|
+
const typeID = item.prop.getTypeID();
|
|
240
|
+
return {
|
|
241
|
+
unionItem: item.unionItem,
|
|
242
|
+
unionIndex,
|
|
243
|
+
prop: item.prop,
|
|
244
|
+
typeID,
|
|
245
|
+
compiledName: getCompiledName(comp, urt, typeID),
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function initGetCompiledName() {
|
|
251
|
+
const typeIDs = new Map<string | number, number>();
|
|
252
|
+
return function getCompiledName(comp: JitFnCompiler, urt: UnionRunType, typeID: string | number): string {
|
|
253
|
+
const existingIndex = typeIDs.get(typeID);
|
|
254
|
+
if (existingIndex) return comp.getLocalVarName('prop', urt) + `_${existingIndex}`;
|
|
255
|
+
const newIndex = typeIDs.size;
|
|
256
|
+
typeIDs.set(typeID, newIndex);
|
|
257
|
+
return comp.getLocalVarName('prop', urt) + `_${newIndex}`;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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 type {AnyFunction, SrcType, JitFn, JitCode, RunTypeOptions} from '../../types.ts';
|
|
8
|
+
import {ReflectionKind, TypeFunction} from '@deepkit/type';
|
|
9
|
+
import {BaseRunType} from '../../lib/baseRunTypes.ts';
|
|
10
|
+
import {isAnyFunctionRunType, isFunctionRunType, isPromiseRunType} from '../../lib/guards.ts';
|
|
11
|
+
import {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
12
|
+
import {PromiseRunType} from '../native/promise.ts';
|
|
13
|
+
import {ReflectionSubKind} from '../../constants.kind.ts';
|
|
14
|
+
import {FunctionParamsRunType} from '../collection/functionParams.ts';
|
|
15
|
+
import {JitCompiledFn} from '@mionjs/core';
|
|
16
|
+
import {registerJitFunctionCompiler} from '../../lib/jitFnsRegistry.ts';
|
|
17
|
+
import {JitFunctions} from '../../constants.functions.ts';
|
|
18
|
+
|
|
19
|
+
export class FunctionRunType<CallType extends AnyFunction = TypeFunction> extends BaseRunType<CallType> {
|
|
20
|
+
// parameterRunTypes.src must be set after FunctionRunType creation
|
|
21
|
+
parameterRunTypes: FunctionParamsRunType = new FunctionParamsRunType();
|
|
22
|
+
skipJit(comp: JitFnCompiler): boolean {
|
|
23
|
+
if (!comp) return true;
|
|
24
|
+
return comp.fnID !== JitFunctions.toJSCode.id;
|
|
25
|
+
}
|
|
26
|
+
onCreated(deepkitType: SrcType): void {
|
|
27
|
+
// here we are mapping parameters from TypeParameter[] to TypeTuple as TupleRunType() is the same functionality as ParameterRunType[]
|
|
28
|
+
super.onCreated(deepkitType);
|
|
29
|
+
// Create a synthetic type for parameters with its own subKind
|
|
30
|
+
// Explicitly exclude _typeId and _formatId so the params type gets its own cached IDs
|
|
31
|
+
const paramsType = {...deepkitType, subKind: ReflectionSubKind.params} as any;
|
|
32
|
+
delete paramsType._typeId;
|
|
33
|
+
delete paramsType._formatId;
|
|
34
|
+
this.parameterRunTypes.onCreated(paramsType);
|
|
35
|
+
}
|
|
36
|
+
getFamily(): 'F' {
|
|
37
|
+
return 'F';
|
|
38
|
+
}
|
|
39
|
+
getFnName(): string | number {
|
|
40
|
+
const name = (this.src as TypeFunction).name;
|
|
41
|
+
if (!name) return '';
|
|
42
|
+
if (typeof name === 'symbol') return name.toString();
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
createJitParamsFunction(jitFn: JitFn, opts?: RunTypeOptions): (...args: any[]) => any {
|
|
46
|
+
return this.createJitCompiledParamsFunction(jitFn, opts).fn;
|
|
47
|
+
}
|
|
48
|
+
createJitCompiledParamsFunction(jitFn: JitFn, opts?: RunTypeOptions): JitCompiledFn {
|
|
49
|
+
const start = opts?.paramsSlice?.start;
|
|
50
|
+
const end = opts?.paramsSlice?.end;
|
|
51
|
+
if (start && end) {
|
|
52
|
+
if (start < 0 || end > this.parameterRunTypes.getChildRunTypes().length)
|
|
53
|
+
throw new Error(`Invalid paramsSlice, start: ${start}, end: ${end}.`);
|
|
54
|
+
if (end <= start) throw new Error(`Invalid paramsSlice, start: ${start}, end: ${end}`);
|
|
55
|
+
}
|
|
56
|
+
return this.parameterRunTypes.createJitCompiledFunction(jitFn.id, undefined, opts);
|
|
57
|
+
}
|
|
58
|
+
createJitReturnFunction(jitFn: JitFn): (...args: any[]) => any {
|
|
59
|
+
return this.createJitCompiledReturnFunction(jitFn).fn;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
createJitCompiledReturnFunction(jitFn: JitFn, opts?: RunTypeOptions): JitCompiledFn {
|
|
63
|
+
return this.getResolvedReturnType().createJitCompiledFunction(jitFn.id, undefined, opts);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ######## JIT functions (all throw error) ########
|
|
67
|
+
|
|
68
|
+
// can't know the types of the run type function parameters, neither the return type, so only compare function name and length
|
|
69
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
70
|
+
const minLength = this.parameterRunTypes.totalRequiredParams(comp);
|
|
71
|
+
const totalParams = this.parameterRunTypes.getParamRunTypes(comp).length;
|
|
72
|
+
const hasOptional = totalParams > minLength;
|
|
73
|
+
const maxLength =
|
|
74
|
+
this.parameterRunTypes.hasRestParameter(comp) || !hasOptional ? '' : ` && ${comp.vλl}.length <= ${totalParams}`;
|
|
75
|
+
return {code: `(typeof ${comp.vλl} === 'function' && ${comp.vλl}.length >= ${minLength} ${maxLength})`, type: 'E'};
|
|
76
|
+
}
|
|
77
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
78
|
+
return {code: `if (!(${this.emitIsType(comp).code})) ${comp.callJitErr(this)};`, type: 'S'};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* json encode a function
|
|
82
|
+
*/
|
|
83
|
+
emitPrepareForJson(): JitCode {
|
|
84
|
+
throw new Error(`Compile function PrepareForJson not supported, call compileParams or compileReturn instead.`);
|
|
85
|
+
}
|
|
86
|
+
emitRestoreFromJson(): JitCode {
|
|
87
|
+
throw new Error(`Compile function RestoreFromJson not supported, call compileParams or compileReturn instead.`);
|
|
88
|
+
}
|
|
89
|
+
emitHasUnknownKeys(): JitCode {
|
|
90
|
+
return {code: '', type: 'E'};
|
|
91
|
+
}
|
|
92
|
+
emitUnknownKeyErrors(): JitCode {
|
|
93
|
+
return {code: '', type: 'S'};
|
|
94
|
+
}
|
|
95
|
+
emitStripUnknownKeys(): JitCode {
|
|
96
|
+
return {code: '', type: 'S'};
|
|
97
|
+
}
|
|
98
|
+
emitUnknownKeysToUndefined(): JitCode {
|
|
99
|
+
return {code: '', type: 'S'};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// TODO: paramsSlice has been removed as options are not jet passed when building the run type. maybe we can pass it to the JitCompileOperation instead
|
|
103
|
+
// constructor() {
|
|
104
|
+
// const start = opts?.paramsSlice?.start;
|
|
105
|
+
// const end = opts?.paramsSlice?.end;
|
|
106
|
+
// parameterRunTypes = src.parameters.slice(start, end).map((p) => visitor(p, parents, opts)) as ParameterRunType[];
|
|
107
|
+
// }
|
|
108
|
+
getReturnType(): BaseRunType {
|
|
109
|
+
return (this.src.return as SrcType)._rt as BaseRunType;
|
|
110
|
+
}
|
|
111
|
+
/** returns the inner run-type when the handler returns Promise<T> (or nested Promise/function-return chains), or the plain return type otherwise */
|
|
112
|
+
getResolvedReturnType(): BaseRunType {
|
|
113
|
+
let currentType: PromiseRunType | FunctionRunType<any> = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
114
|
+
// eslint-disable-next-line no-constant-condition
|
|
115
|
+
while (true) {
|
|
116
|
+
if (isAnyFunctionRunType(currentType)) {
|
|
117
|
+
const returnType = currentType.getReturnType();
|
|
118
|
+
if (isPromiseRunType(returnType) || isFunctionRunType(returnType)) {
|
|
119
|
+
currentType = returnType;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
return returnType;
|
|
123
|
+
}
|
|
124
|
+
const memberType = currentType.getMemberType();
|
|
125
|
+
if (isPromiseRunType(memberType) || isFunctionRunType(memberType)) {
|
|
126
|
+
currentType = memberType;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
return memberType;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
getParameters(): FunctionParamsRunType {
|
|
133
|
+
return this.parameterRunTypes;
|
|
134
|
+
}
|
|
135
|
+
getParameterNames(opts?: RunTypeOptions): string[] {
|
|
136
|
+
const start = opts?.paramsSlice?.start;
|
|
137
|
+
const end = opts?.paramsSlice?.end;
|
|
138
|
+
if (start || end) {
|
|
139
|
+
return this.src.parameters.slice(start, end).map((p) => p.name);
|
|
140
|
+
}
|
|
141
|
+
return this.src.parameters.map((p) => p.name);
|
|
142
|
+
}
|
|
143
|
+
hasReturnData(): boolean {
|
|
144
|
+
const returnKind = this.getReturnType().src.kind;
|
|
145
|
+
return (
|
|
146
|
+
returnKind !== ReflectionKind.void && returnKind !== ReflectionKind.never && returnKind !== ReflectionKind.undefined
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
isAsync(): boolean {
|
|
150
|
+
const returnKind = this.getReturnType().src.kind;
|
|
151
|
+
return (
|
|
152
|
+
returnKind === ReflectionKind.promise || returnKind === ReflectionKind.any || returnKind === ReflectionKind.unknown
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
returnIsPromise(): boolean {
|
|
156
|
+
return isPromiseRunType(this.getReturnType());
|
|
157
|
+
}
|
|
158
|
+
async mockReturn(ctx?: RunTypeOptions): Promise<any> {
|
|
159
|
+
await registerJitFunctionCompiler(JitFunctions.mock);
|
|
160
|
+
return this.getReturnType().mockType(ctx);
|
|
161
|
+
}
|
|
162
|
+
async mockParams(ctx?: RunTypeOptions): Promise<any[]> {
|
|
163
|
+
await registerJitFunctionCompiler(JitFunctions.mock);
|
|
164
|
+
return this.parameterRunTypes.mockType(ctx);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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 {Type, TypeArray} from '@deepkit/type';
|
|
9
|
+
import type {JitCode} from '../../types.ts';
|
|
10
|
+
import type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
11
|
+
import {MemberRunType} from '../../lib/baseRunTypes.ts';
|
|
12
|
+
import {childIsExpression} from '../../lib/utils.ts';
|
|
13
|
+
|
|
14
|
+
export class ArrayRunType<T extends Type = TypeArray> extends MemberRunType<T> {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
startIndex(comp: JitFnCompiler): number {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
getChildVarName(comp: JitFnCompiler): string {
|
|
20
|
+
return comp.getLocalVarName('i', this);
|
|
21
|
+
}
|
|
22
|
+
getChildLiteral(comp: JitFnCompiler): string {
|
|
23
|
+
return this.getChildVarName(comp);
|
|
24
|
+
}
|
|
25
|
+
useArrayAccessor(): true {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
isOptional(): boolean {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// #### jit code ####
|
|
33
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
34
|
+
this.checkNonSkipTypes(comp);
|
|
35
|
+
const resultVal = comp.getLocalVarName('res', this);
|
|
36
|
+
const index = this.getChildVarName(comp);
|
|
37
|
+
const child = this.getJitChild(comp);
|
|
38
|
+
const childJit = comp.compileIsType(child, 'E');
|
|
39
|
+
if (!childJit?.code && comp.opts.noIsArrayCheck) return {code: undefined, type: 'E'};
|
|
40
|
+
if (!childJit?.code) return {code: `Array.isArray(${comp.vλl})`, type: 'E'};
|
|
41
|
+
const isArrayCheckCode = comp.opts.noIsArrayCheck ? '' : `if (!Array.isArray(${comp.vλl})) return false;`;
|
|
42
|
+
return {
|
|
43
|
+
code: `
|
|
44
|
+
${isArrayCheckCode}
|
|
45
|
+
for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {
|
|
46
|
+
const ${resultVal} = ${childJit.code};
|
|
47
|
+
if (!(${resultVal})) return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
`,
|
|
51
|
+
type: 'RB',
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
55
|
+
this.checkNonSkipTypes(comp);
|
|
56
|
+
const index = this.getChildVarName(comp);
|
|
57
|
+
const child = this.getJitChild(comp);
|
|
58
|
+
const childJit = comp.compileTypeErrors(child, 'S');
|
|
59
|
+
if (!childJit?.code && comp.opts.noIsArrayCheck) return {code: undefined, type: 'E'};
|
|
60
|
+
if (!childJit?.code) return {code: `if (!Array.isArray(${comp.vλl})) ${comp.callJitErr(this)};`, type: 'S'};
|
|
61
|
+
const itemsCode = `for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${childJit.code}}`;
|
|
62
|
+
if (comp.opts.noIsArrayCheck) return {code: itemsCode, type: 'S'};
|
|
63
|
+
return {
|
|
64
|
+
code: `if (!Array.isArray(${comp.vλl})) {${comp.callJitErr(this)}} else {${itemsCode}}`,
|
|
65
|
+
type: 'S',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
69
|
+
this.checkNonSkipTypes(comp);
|
|
70
|
+
const index = this.getChildVarName(comp);
|
|
71
|
+
const child = this.getJitChild(comp);
|
|
72
|
+
const childJit = comp.compilePrepareForJson(child, 'S');
|
|
73
|
+
if (!childJit?.code || !child) return {code: undefined, type: 'S'};
|
|
74
|
+
const isExpression = childIsExpression(childJit, child);
|
|
75
|
+
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';
|
|
76
|
+
return {
|
|
77
|
+
code: `for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${code}}`,
|
|
78
|
+
type: 'S',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
82
|
+
this.checkNonSkipTypes(comp);
|
|
83
|
+
const index = this.getChildVarName(comp);
|
|
84
|
+
const child = this.getJitChild(comp);
|
|
85
|
+
const childJit = comp.compileRestoreFromJson(child, 'S');
|
|
86
|
+
if (!childJit?.code || !child) return {code: undefined, type: 'S'};
|
|
87
|
+
const isExpression = childIsExpression(childJit, child);
|
|
88
|
+
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';
|
|
89
|
+
return {
|
|
90
|
+
code: `for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${code}}`,
|
|
91
|
+
type: 'S',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
95
|
+
this.checkNonSkipTypes(comp);
|
|
96
|
+
if (this.getMemberType().getFamily() === 'A') return {code: undefined, type: 'E'};
|
|
97
|
+
const child = this.getJitChild(comp);
|
|
98
|
+
const childJit = comp.compileHasUnknownKeys(child, 'E');
|
|
99
|
+
if (!childJit?.code) return {code: undefined, type: 'E'};
|
|
100
|
+
const resultVal = comp.getLocalVarName('res', this);
|
|
101
|
+
const index = this.getChildVarName(comp);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
code: `
|
|
105
|
+
if (!Array.isArray(${comp.vλl})) return false;
|
|
106
|
+
for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {
|
|
107
|
+
const ${resultVal} = ${childJit.code};
|
|
108
|
+
if (${resultVal}) return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
`,
|
|
112
|
+
type: 'RB',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
116
|
+
this.checkNonSkipTypes(comp);
|
|
117
|
+
if (this.getMemberType().getFamily() === 'A') return {code: '', type: 'E'};
|
|
118
|
+
const child = this.getJitChild(comp);
|
|
119
|
+
const childJit = comp.compileUnknownKeyErrors(child, 'S');
|
|
120
|
+
return this.traverseCode(comp, childJit);
|
|
121
|
+
}
|
|
122
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
123
|
+
this.checkNonSkipTypes(comp);
|
|
124
|
+
if (this.getMemberType().getFamily() === 'A') return {code: '', type: 'E'};
|
|
125
|
+
const child = this.getJitChild(comp);
|
|
126
|
+
const childJit = comp.compileStripUnknownKeys(child, 'S');
|
|
127
|
+
return this.traverseCode(comp, childJit);
|
|
128
|
+
}
|
|
129
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {
|
|
130
|
+
this.checkNonSkipTypes(comp);
|
|
131
|
+
if (this.getMemberType().getFamily() === 'A') return {code: '', type: 'E'};
|
|
132
|
+
const child = this.getJitChild(comp);
|
|
133
|
+
const childJit = comp.compileUnknownKeysToUndefined(child, 'S');
|
|
134
|
+
return this.traverseCode(comp, childJit);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
traverseCode(comp: JitFnCompiler, childJit: JitCode | undefined): {code: string | undefined; type: 'S'} {
|
|
138
|
+
if (!childJit?.code) return {code: undefined, type: 'S'};
|
|
139
|
+
const index = this.getChildVarName(comp);
|
|
140
|
+
return {
|
|
141
|
+
code: `for (let ${index} = ${this.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${childJit.code}}`,
|
|
142
|
+
type: 'S',
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
checkNonSkipTypes(comp: JitFnCompiler) {
|
|
147
|
+
const child = this.getMemberType();
|
|
148
|
+
if (child.skipJit(comp)) throw new Error(`Arrays can not have non serializable types, ie: Symbol[], Function[], etc.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 {TypeCallSignature} from '@deepkit/type';
|
|
8
|
+
import {RunTypeChildAccessor} from '../../types.ts';
|
|
9
|
+
import {getPropIndex} from '../../lib/utils.ts';
|
|
10
|
+
import {FunctionRunType} from '../function/function.ts';
|
|
11
|
+
import type {JitFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents a call signature.
|
|
15
|
+
* Call signature is an special node within in interface or object literal that represents a function signature but can have extra properties.
|
|
16
|
+
* ie:
|
|
17
|
+
* type = {
|
|
18
|
+
* (a: number, b: boolean): string; // call signature node
|
|
19
|
+
* popA: number;
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* So when a call signature is present the parent object literal or interface is considered a function.
|
|
23
|
+
*/
|
|
24
|
+
export class CallSignatureRunType extends FunctionRunType<TypeCallSignature> implements RunTypeChildAccessor {
|
|
25
|
+
getChildIndex = (comp: JitFnCompiler) => {
|
|
26
|
+
const start = comp?.opts?.paramsSlice?.start;
|
|
27
|
+
if (start) return getPropIndex(this.src) - start;
|
|
28
|
+
return getPropIndex(this.src);
|
|
29
|
+
};
|
|
30
|
+
getChildVarName = () => '';
|
|
31
|
+
getChildLiteral = () => '""';
|
|
32
|
+
useArrayAccessor = () => false;
|
|
33
|
+
isOptional = () => false;
|
|
34
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
8
|
+
import {MemberRunType} from '../../lib/baseRunTypes.ts';
|
|
9
|
+
import type {JitCode, SrcMember} from '../../types.ts';
|
|
10
|
+
import {childIsExpression} from '../../lib/utils.ts';
|
|
11
|
+
|
|
12
|
+
// TODO: investigate is other member types cloud extend this class instead of MemberRunType
|
|
13
|
+
export class GenericMemberRunType<T extends SrcMember> extends MemberRunType<T> {
|
|
14
|
+
index = 0;
|
|
15
|
+
getChildIndex() {
|
|
16
|
+
return this.index;
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
getChildVarName(comp: JitFnCompiler): string | number {
|
|
20
|
+
return this.index;
|
|
21
|
+
}
|
|
22
|
+
getChildLiteral(comp: JitFnCompiler) {
|
|
23
|
+
return this.getChildVarName(comp);
|
|
24
|
+
}
|
|
25
|
+
useArrayAccessor() {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
isOptional() {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
emitIsType(comp: JitFnCompiler): JitCode {
|
|
32
|
+
const child = this.getJitChild(comp);
|
|
33
|
+
const childJit = comp.compileIsType(child, 'E');
|
|
34
|
+
if (!childJit?.code) return {code: undefined, type: 'E'};
|
|
35
|
+
if (this.isOptional()) return {code: `${comp.getChildVλl()} === undefined || (${childJit.code})`, type: 'E'};
|
|
36
|
+
return childJit;
|
|
37
|
+
}
|
|
38
|
+
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
39
|
+
const child = this.getJitChild(comp);
|
|
40
|
+
const childJit = comp.compileTypeErrors(child, 'S');
|
|
41
|
+
if (!childJit?.code) return {code: undefined, type: 'S'};
|
|
42
|
+
if (this.isOptional()) return {code: `if (${comp.getChildVλl()} !== undefined) {${childJit.code}}`, type: 'S'};
|
|
43
|
+
return childJit;
|
|
44
|
+
}
|
|
45
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
46
|
+
const child = this.getJitChild(comp);
|
|
47
|
+
const childJit = comp.compilePrepareForJson(child, 'S');
|
|
48
|
+
if (!childJit?.code || !child) return {code: undefined, type: 'S'};
|
|
49
|
+
const isExpression = childIsExpression(childJit, child); // expressions must be assigned to a variable
|
|
50
|
+
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code}` : childJit.code || '';
|
|
51
|
+
if (this.isOptional()) return {code: `if (${comp.getChildVλl()} !== undefined) {${code}}`, type: 'S'};
|
|
52
|
+
return {code, type: 'S'};
|
|
53
|
+
}
|
|
54
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
55
|
+
const child = this.getJitChild(comp);
|
|
56
|
+
const childJit = comp.compileRestoreFromJson(child, 'S');
|
|
57
|
+
if (!childJit?.code || !child) return {code: undefined, type: 'S'};
|
|
58
|
+
const isExpression = childIsExpression(childJit, child);
|
|
59
|
+
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';
|
|
60
|
+
if (this.isOptional()) return {code: `if (${comp.getChildVλl()} !== undefined) {${code}}`, type: 'S'};
|
|
61
|
+
return {code, type: 'S'};
|
|
62
|
+
}
|
|
63
|
+
}
|