@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,323 @@
|
|
|
1
|
+
/* eslint-disable no-case-declarations */
|
|
2
|
+
/* ########
|
|
3
|
+
* 2024 mion
|
|
4
|
+
* Author: Ma-jerez
|
|
5
|
+
* License: MIT
|
|
6
|
+
* The software is provided "as is", without warranty of any kind.
|
|
7
|
+
* ######## */
|
|
8
|
+
|
|
9
|
+
import type {RunType, Mutable, SrcType} from './types.ts';
|
|
10
|
+
import type {BaseRunType} from './lib/baseRunTypes.ts';
|
|
11
|
+
import type {TypeClass, Type} from '@deepkit/type';
|
|
12
|
+
import {ReflectionKind, resolveReceiveType, ReceiveType, reflect, typeAnnotation, stringifyType} from '@deepkit/type';
|
|
13
|
+
import {
|
|
14
|
+
hasArguments,
|
|
15
|
+
hasExtendsArguments,
|
|
16
|
+
hasImplements,
|
|
17
|
+
hasIndexType,
|
|
18
|
+
hasParameters,
|
|
19
|
+
hasReturn,
|
|
20
|
+
hasType,
|
|
21
|
+
hasTypes,
|
|
22
|
+
isNativeUtilityStringTypes,
|
|
23
|
+
isNonSerializableClass,
|
|
24
|
+
isNonSerializableObject,
|
|
25
|
+
} from './lib/guards.ts';
|
|
26
|
+
import {StringRunType} from './nodes/atomic/string.ts';
|
|
27
|
+
import {DateRunType} from './nodes/atomic/date.ts';
|
|
28
|
+
import {NumberRunType} from './nodes/atomic/number.ts';
|
|
29
|
+
import {BooleanRunType} from './nodes/atomic/boolean.ts';
|
|
30
|
+
import {NullRunType} from './nodes/atomic/null.ts';
|
|
31
|
+
import {BigIntRunType} from './nodes/atomic/bigInt.ts';
|
|
32
|
+
import {AnyRunType} from './nodes/atomic/any.ts';
|
|
33
|
+
import {UndefinedRunType} from './nodes/atomic/undefined.ts';
|
|
34
|
+
import {UnknownRunType} from './nodes/atomic/unknown.ts';
|
|
35
|
+
import {VoidRunType} from './nodes/atomic/void.ts';
|
|
36
|
+
import {ArrayRunType} from './nodes/member/array.ts';
|
|
37
|
+
import {LiteralRunType} from './nodes/atomic/literal.ts';
|
|
38
|
+
import {RegexpRunType} from './nodes/atomic/regexp.ts';
|
|
39
|
+
import {NeverRunType} from './nodes/atomic/never.ts';
|
|
40
|
+
import {EnumRunType} from './nodes/atomic/enum.ts';
|
|
41
|
+
import {EnumMemberRunType} from './nodes/atomic/enumMember.ts';
|
|
42
|
+
import {UnionRunType} from './nodes/collection/union.ts';
|
|
43
|
+
import {TupleRunType} from './nodes/collection/tuple.ts';
|
|
44
|
+
import {FunctionParamsRunType} from './nodes/collection/functionParams.ts';
|
|
45
|
+
import {TupleMemberRunType} from './nodes/member/tupleMember.ts';
|
|
46
|
+
import {InterfaceRunType} from './nodes/collection/interface.ts';
|
|
47
|
+
import {PropertyRunType} from './nodes/member/property.ts';
|
|
48
|
+
import {IndexSignatureRunType} from './nodes/member/indexProperty.ts';
|
|
49
|
+
import {MethodSignatureRunType} from './nodes/member/methodSignature.ts';
|
|
50
|
+
import {CallSignatureRunType} from './nodes/member/callSignature.ts';
|
|
51
|
+
import {FunctionRunType} from './nodes/function/function.ts';
|
|
52
|
+
import {PromiseRunType} from './nodes/native/promise.ts';
|
|
53
|
+
import {ObjectRunType} from './nodes/atomic/object.ts';
|
|
54
|
+
import {IntersectionRunType} from './nodes/collection/intersection.ts';
|
|
55
|
+
import {ParameterRunType} from './nodes/member/param.ts';
|
|
56
|
+
import {MethodRunType} from './nodes/member/method.ts';
|
|
57
|
+
import {RestParamsRunType} from './nodes/member/restParams.ts';
|
|
58
|
+
import {ClassRunType} from './nodes/collection/class.ts';
|
|
59
|
+
import {MapRunType} from './nodes/native/map.ts';
|
|
60
|
+
import {ReflectionSubKind} from './constants.kind.ts';
|
|
61
|
+
import {SetRunType} from './nodes/native/set.ts';
|
|
62
|
+
import {SymbolRunType} from './nodes/atomic/symbol.ts';
|
|
63
|
+
import {NonSerializableRunType} from './nodes/native/nonSerializable.ts';
|
|
64
|
+
import {registerErrorDeserializers} from '@mionjs/core';
|
|
65
|
+
|
|
66
|
+
export function runType<T>(type?: ReceiveType<T>): RunType {
|
|
67
|
+
const start = Date.now();
|
|
68
|
+
const src = resolveReceiveType(type) as SrcType;
|
|
69
|
+
const took0 = Date.now() - start;
|
|
70
|
+
createRunTypes(src);
|
|
71
|
+
const took1 = Date.now() - start;
|
|
72
|
+
const diff = took1 - took0;
|
|
73
|
+
// max RunType overhead 60 ms
|
|
74
|
+
if (diff > 60) console.warn(`RunType overhead is very long: ${diff}ms for ${stringifyType(src)}`);
|
|
75
|
+
return src._rt;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function reflectFunction<Fn extends (...args: any[]) => any>(fn: Fn): FunctionRunType {
|
|
79
|
+
const src = reflect(fn) as SrcType;
|
|
80
|
+
runType(src);
|
|
81
|
+
return src._rt as FunctionRunType;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// We need to traverse all possible associated nodes to create all the runTypes
|
|
85
|
+
function createRunTypes(src: SrcType): void {
|
|
86
|
+
registerErrorDeserializers();
|
|
87
|
+
const stack: Type[] = [src];
|
|
88
|
+
|
|
89
|
+
while (stack.length > 0) {
|
|
90
|
+
const current = stack.pop();
|
|
91
|
+
if (!current || (current as SrcType)._rt) continue;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
createRunType(current as Mutable<SrcType>);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
const typesStackMessage = '\nTypes Stack: ' + stack.map((t) => t.typeName || t.kind).join(', ');
|
|
97
|
+
(error as Error).message += typesStackMessage;
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// single child type nodes
|
|
102
|
+
if (hasType(current)) stack.push(current.type);
|
|
103
|
+
if (hasReturn(current)) stack.push(current.return);
|
|
104
|
+
if (hasIndexType(current)) stack.push(current.indexType);
|
|
105
|
+
if (current.origin) stack.push(current.origin);
|
|
106
|
+
if (current.indexAccessOrigin?.index) stack.push(current.indexAccessOrigin?.index);
|
|
107
|
+
if (current.indexAccessOrigin?.container) stack.push(current.indexAccessOrigin?.container);
|
|
108
|
+
|
|
109
|
+
// multiple child type nodes
|
|
110
|
+
if (hasTypes(current)) pushToStack(current.types, stack);
|
|
111
|
+
if (hasParameters(current)) pushToStack(current.parameters, stack);
|
|
112
|
+
if (hasArguments(current)) pushToStack(current.arguments, stack);
|
|
113
|
+
if (hasExtendsArguments(current)) pushToStack(current.extendsArguments, stack);
|
|
114
|
+
if (hasImplements(current)) pushToStack(current.implements, stack);
|
|
115
|
+
if (current.typeArguments) pushToStack(current.typeArguments, stack);
|
|
116
|
+
if (current.decorators) pushToStack(current.decorators, stack);
|
|
117
|
+
if (current.scheduleDecorators) pushToStack(current.scheduleDecorators, stack);
|
|
118
|
+
|
|
119
|
+
// annotations
|
|
120
|
+
if (current.annotations) {
|
|
121
|
+
const annotations = typeAnnotation.getAnnotations(current);
|
|
122
|
+
for (const annotation of annotations) stack.push(annotation.options);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// originTypes
|
|
126
|
+
current.originTypes?.forEach((ot) => {
|
|
127
|
+
if (ot.typeArguments) pushToStack(ot.typeArguments, stack);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// sometimes parent is an orphan so we need to explicitly add it to the stack
|
|
131
|
+
if (current.parent && !(current.parent as SrcType)?._rt) stack.push(current.parent);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function pushToStack(subTypes: Type[], stack: Type[]) {
|
|
136
|
+
if (Array.isArray(subTypes)) stack.push(...subTypes);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function createRunType(deepkitType: Mutable<SrcType>): RunType {
|
|
140
|
+
// console.log('deepkitType', deepkitType);
|
|
141
|
+
|
|
142
|
+
/*
|
|
143
|
+
RunType reference is stored in the deepkitType._runType so we can access both the deepkitType and the mion RunType,
|
|
144
|
+
basically every runType stores a reference to a deepkit type and vice versa.
|
|
145
|
+
This also relies on deepkit handling circular types to prevent infinite loop when we are generating RunTypes.
|
|
146
|
+
*/
|
|
147
|
+
const existingType: RunType | undefined = deepkitType._rt;
|
|
148
|
+
// TODO: IMPORTANT: seems like deepkit can generate multiple types objects for the same type, so we need to handle this
|
|
149
|
+
// we are attaching the runType to the deepkit type (deepkitType._runType), to link the two types together
|
|
150
|
+
// but as deepkit can generate multiple types that means existingType will be null and the markAsCircular function is not working as expected
|
|
151
|
+
if (existingType) return existingType;
|
|
152
|
+
|
|
153
|
+
let rt: BaseRunType;
|
|
154
|
+
|
|
155
|
+
switch (deepkitType.kind) {
|
|
156
|
+
// ###################### ATOMIC RUNTYPES ######################
|
|
157
|
+
// Primitive types and other atomic types that don't contain other types
|
|
158
|
+
case ReflectionKind.any:
|
|
159
|
+
rt = new AnyRunType();
|
|
160
|
+
break;
|
|
161
|
+
case ReflectionKind.bigint:
|
|
162
|
+
rt = new BigIntRunType();
|
|
163
|
+
break;
|
|
164
|
+
case ReflectionKind.boolean:
|
|
165
|
+
rt = new BooleanRunType();
|
|
166
|
+
break;
|
|
167
|
+
case ReflectionKind.enum:
|
|
168
|
+
rt = new EnumRunType();
|
|
169
|
+
break;
|
|
170
|
+
case ReflectionKind.enumMember:
|
|
171
|
+
// enum members are resolved by the enum type, so this is not expected to be called
|
|
172
|
+
rt = new EnumMemberRunType();
|
|
173
|
+
break;
|
|
174
|
+
case ReflectionKind.literal:
|
|
175
|
+
rt = new LiteralRunType();
|
|
176
|
+
break;
|
|
177
|
+
case ReflectionKind.never:
|
|
178
|
+
// TODO add the string format feature
|
|
179
|
+
rt = isNativeUtilityStringTypes(deepkitType) ? new StringRunType() : new NeverRunType();
|
|
180
|
+
break;
|
|
181
|
+
case ReflectionKind.null:
|
|
182
|
+
rt = new NullRunType();
|
|
183
|
+
break;
|
|
184
|
+
case ReflectionKind.number:
|
|
185
|
+
rt = new NumberRunType();
|
|
186
|
+
break;
|
|
187
|
+
case ReflectionKind.object:
|
|
188
|
+
rt = new ObjectRunType();
|
|
189
|
+
break;
|
|
190
|
+
case ReflectionKind.regexp:
|
|
191
|
+
rt = new RegexpRunType();
|
|
192
|
+
break;
|
|
193
|
+
case ReflectionKind.string:
|
|
194
|
+
rt = new StringRunType();
|
|
195
|
+
break;
|
|
196
|
+
case ReflectionKind.symbol:
|
|
197
|
+
rt = new SymbolRunType();
|
|
198
|
+
break;
|
|
199
|
+
case ReflectionKind.templateLiteral:
|
|
200
|
+
// deepkit automatically resolves template literals unions to literals
|
|
201
|
+
// this is only called when you define the type of a template literal i.e: type T = `foo${string}`;
|
|
202
|
+
// this is not supported at the moment but would be useful for type safe urls etc
|
|
203
|
+
throw new Error(
|
|
204
|
+
'Template Literals are resolved by the compiler to Literals ie: const tl = `${string}World`. Template literal types are not supported. ie type TL = `${string}World`'
|
|
205
|
+
);
|
|
206
|
+
case ReflectionKind.undefined:
|
|
207
|
+
rt = new UndefinedRunType();
|
|
208
|
+
break;
|
|
209
|
+
case ReflectionKind.unknown:
|
|
210
|
+
rt = new UnknownRunType();
|
|
211
|
+
break;
|
|
212
|
+
case ReflectionKind.void:
|
|
213
|
+
rt = new VoidRunType();
|
|
214
|
+
break;
|
|
215
|
+
|
|
216
|
+
// ###################### MEMBER RUNTYPES ######################
|
|
217
|
+
// Types that represent members of collections or other structures
|
|
218
|
+
case ReflectionKind.array:
|
|
219
|
+
rt = new ArrayRunType();
|
|
220
|
+
break;
|
|
221
|
+
case ReflectionKind.callSignature:
|
|
222
|
+
rt = new CallSignatureRunType();
|
|
223
|
+
break;
|
|
224
|
+
case ReflectionKind.function:
|
|
225
|
+
if (deepkitType.subKind === ReflectionSubKind.params) {
|
|
226
|
+
rt = new FunctionParamsRunType();
|
|
227
|
+
} else {
|
|
228
|
+
const frt = new FunctionRunType();
|
|
229
|
+
// TODO review an change how we compile function parameters and return type
|
|
230
|
+
// those should also be jit functions, no need to check for array
|
|
231
|
+
// and maybe add option to target individual parameters
|
|
232
|
+
(frt.parameterRunTypes as Mutable<RunType>).src = deepkitType;
|
|
233
|
+
rt = frt;
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case ReflectionKind.indexSignature:
|
|
237
|
+
rt = new IndexSignatureRunType();
|
|
238
|
+
break;
|
|
239
|
+
case ReflectionKind.method:
|
|
240
|
+
rt = new MethodRunType();
|
|
241
|
+
break;
|
|
242
|
+
case ReflectionKind.methodSignature:
|
|
243
|
+
rt = new MethodSignatureRunType();
|
|
244
|
+
break;
|
|
245
|
+
case ReflectionKind.parameter:
|
|
246
|
+
rt = new ParameterRunType();
|
|
247
|
+
break;
|
|
248
|
+
case ReflectionKind.property:
|
|
249
|
+
case ReflectionKind.propertySignature:
|
|
250
|
+
rt = new PropertyRunType();
|
|
251
|
+
break;
|
|
252
|
+
case ReflectionKind.rest:
|
|
253
|
+
rt = new RestParamsRunType();
|
|
254
|
+
break;
|
|
255
|
+
case ReflectionKind.tupleMember:
|
|
256
|
+
rt = new TupleMemberRunType();
|
|
257
|
+
break;
|
|
258
|
+
case ReflectionKind.promise:
|
|
259
|
+
rt = new PromiseRunType();
|
|
260
|
+
break;
|
|
261
|
+
|
|
262
|
+
// ###################### COLLECTION RUNTYPES ######################
|
|
263
|
+
case ReflectionKind.objectLiteral:
|
|
264
|
+
if (isNonSerializableObject(deepkitType)) {
|
|
265
|
+
rt = new NonSerializableRunType();
|
|
266
|
+
} else {
|
|
267
|
+
rt = new InterfaceRunType();
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
case ReflectionKind.class:
|
|
271
|
+
rt = initClassRunType(deepkitType);
|
|
272
|
+
break;
|
|
273
|
+
// Types that contain other types as members
|
|
274
|
+
case ReflectionKind.infer:
|
|
275
|
+
throw new Error(
|
|
276
|
+
'Infer type not supported, ie: type MyType =Type<T> = T extends (...args: any[]) => infer R ? R : any; https://www.typescriptlang.org/docs/handbook/2/conditional-types.html'
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
case ReflectionKind.intersection:
|
|
280
|
+
rt = new IntersectionRunType();
|
|
281
|
+
break;
|
|
282
|
+
|
|
283
|
+
case ReflectionKind.tuple:
|
|
284
|
+
rt = new TupleRunType();
|
|
285
|
+
break;
|
|
286
|
+
case ReflectionKind.typeParameter:
|
|
287
|
+
throw new Error(
|
|
288
|
+
'TypeParameter not implemented. Type parameters are the generic placeholders in type definitions (e.g., T in Array<T>, ErrType in TypedError<ErrType>). ' +
|
|
289
|
+
'Type parameters are typically resolved during type instantiation and should not appear in runtime type checking.' +
|
|
290
|
+
'This error is typically caused by a generic type missing type arguments, e.g.: TypedError instead of TypedError<"my-error">.'
|
|
291
|
+
);
|
|
292
|
+
// rType = resolveTypeParameter(deepkitType, opts, mapper);
|
|
293
|
+
case ReflectionKind.union:
|
|
294
|
+
rt = new UnionRunType();
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
rt = new AnyRunType();
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
rt.onCreated(deepkitType);
|
|
301
|
+
// console.log('rt', rt);
|
|
302
|
+
return rt;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function initClassRunType(src: TypeClass & {subKind?: number}): BaseRunType {
|
|
306
|
+
switch (src.classType) {
|
|
307
|
+
case Date:
|
|
308
|
+
src.subKind = ReflectionSubKind.date;
|
|
309
|
+
return new DateRunType();
|
|
310
|
+
case Map:
|
|
311
|
+
src.subKind = ReflectionSubKind.map;
|
|
312
|
+
return new MapRunType();
|
|
313
|
+
case Set:
|
|
314
|
+
src.subKind = ReflectionSubKind.set;
|
|
315
|
+
return new SetRunType();
|
|
316
|
+
default:
|
|
317
|
+
if (isNonSerializableClass(src)) {
|
|
318
|
+
src.subKind = ReflectionSubKind.nonSerializable;
|
|
319
|
+
return new NonSerializableRunType();
|
|
320
|
+
}
|
|
321
|
+
return new ClassRunType();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2025 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
|
|
8
|
+
import {JitFunctions} from './constants.functions.ts';
|
|
9
|
+
import {ReceiveType} from '@deepkit/type';
|
|
10
|
+
import {runType} from './createRunType.ts';
|
|
11
|
+
import {RunTypeOptions} from './types.ts';
|
|
12
|
+
import {
|
|
13
|
+
FromBinaryFn,
|
|
14
|
+
IsTypeFn,
|
|
15
|
+
JsonStringifyFn,
|
|
16
|
+
PrepareForJsonFn,
|
|
17
|
+
RestoreFromJsonFn,
|
|
18
|
+
ToBinaryFn,
|
|
19
|
+
ToCodeFn,
|
|
20
|
+
TypeErrorsFn,
|
|
21
|
+
} from '@mionjs/core';
|
|
22
|
+
import {BaseRunType} from './lib/baseRunTypes.ts';
|
|
23
|
+
import {registerJitFunctionCompiler} from './lib/jitFnsRegistry.ts';
|
|
24
|
+
|
|
25
|
+
// All these functions are async because they might need to compile the jit function first
|
|
26
|
+
// At the moment they are compiled synchronously, but in the future they might be async
|
|
27
|
+
// Also some the src code to compile or functionality of the JIT functions might be loaded dynamically
|
|
28
|
+
// ie: mocking functionality is loaded only when mockTypeFn is called
|
|
29
|
+
|
|
30
|
+
/** Returns a function that checks if the given value is of the specified type. */
|
|
31
|
+
export async function createIsTypeFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<IsTypeFn> {
|
|
32
|
+
const rt = runType(type);
|
|
33
|
+
return rt.createJitFunction(JitFunctions.isType, opts);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Returns a function that get Type error data. */
|
|
37
|
+
export async function createTypeErrorsFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<TypeErrorsFn> {
|
|
38
|
+
const rt = runType(type);
|
|
39
|
+
return rt.createJitFunction(JitFunctions.typeErrors, opts);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns a function that prepares a javascript type to be compatible with json.stringify.
|
|
44
|
+
* Allows json.stringify special types like dates, bigints, maps, set, etc... that are not supported by json.stringify
|
|
45
|
+
*/
|
|
46
|
+
export async function createPrepareForJsonFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<PrepareForJsonFn> {
|
|
47
|
+
const rt = runType(type);
|
|
48
|
+
return rt.createJitFunction(JitFunctions.prepareForJson, opts);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns a function that restores a javascript type from json.parse.
|
|
53
|
+
* Allows restoring special types like dates, bigints, maps, set, etc... that are not supported by json.parse
|
|
54
|
+
* */
|
|
55
|
+
export async function createRestoreFromJsonFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<RestoreFromJsonFn> {
|
|
56
|
+
const rt = runType(type);
|
|
57
|
+
return rt.createJitFunction(JitFunctions.restoreFromJson, opts);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns a function that stringifies a javascript value to a json string.
|
|
62
|
+
* Stringifies special types like dates, bigints, maps, set, etc...
|
|
63
|
+
* Is equivalent to calling prepareForJson and then json.stringify but more efficient.
|
|
64
|
+
*/
|
|
65
|
+
export async function createStringifyJsonFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<JsonStringifyFn> {
|
|
66
|
+
const rt = runType(type);
|
|
67
|
+
return rt.createJitFunction(JitFunctions.stringifyJson, opts);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Returns a function that serializes any type value to a binary format. */
|
|
71
|
+
export async function createToBinaryFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<ToBinaryFn> {
|
|
72
|
+
const rt = runType(type);
|
|
73
|
+
return rt.createJitFunction(JitFunctions.toBinary, opts);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Returns a function that deserializes a binary value to the specified type. */
|
|
77
|
+
export async function createFromBinaryFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): Promise<FromBinaryFn> {
|
|
78
|
+
const rt = runType(type);
|
|
79
|
+
return rt.createJitFunction(JitFunctions.fromBinary, opts);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Returns a function that converts a value to javascript code, including set etc */
|
|
83
|
+
export function createToJavascriptFn<T>(opts?: RunTypeOptions, type?: ReceiveType<T>): ToCodeFn {
|
|
84
|
+
const rt = runType(type);
|
|
85
|
+
return rt.createJitFunction(JitFunctions.toJSCode, opts);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Returns a function that mocks a value of the specified type. */
|
|
89
|
+
export async function createMockTypeFn<T>(type?: ReceiveType<T>): Promise<(opts?: Partial<RunTypeOptions>) => T> {
|
|
90
|
+
const rt = runType(type) as BaseRunType;
|
|
91
|
+
await registerJitFunctionCompiler(JitFunctions.mock);
|
|
92
|
+
return (opts?: Partial<RunTypeOptions>) => rt.mockType(opts) as T;
|
|
93
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* ########
|
|
2
|
+
* 2025 mion
|
|
3
|
+
* Author: Ma-jerez
|
|
4
|
+
* License: MIT
|
|
5
|
+
* The software is provided "as is", without warranty of any kind.
|
|
6
|
+
* ######## */
|
|
7
|
+
// ###################### Types FORMATS #####################
|
|
8
|
+
|
|
9
|
+
import {TypeAnnotation} from '@deepkit/core';
|
|
10
|
+
// ⚠️ CRITICAL: Do NOT use `import type` - Deepkit needs the actual import for reflection!
|
|
11
|
+
import {TypeFormatParams, Brand, TypeFormatPrimitives} from '@mionjs/core';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A base type that satisfies some extra constrains. (at the moment only Branded types of strings and numbers are supported)
|
|
15
|
+
* ie: an Alphanumeric type is an string that only allow letters and numbers.
|
|
16
|
+
* ie: in Integer type is a number that only allow integer values.
|
|
17
|
+
*
|
|
18
|
+
* TypeFormat is the equivalent ot TypeAnnotation in DK but with slight modifications @deepkit/type<TypeAnnotation>
|
|
19
|
+
*
|
|
20
|
+
* @param BaseType - The base type (string, number, or bigint)
|
|
21
|
+
* @param Name - The format name used for runtime validation
|
|
22
|
+
* @param P - Format parameters for validation rules
|
|
23
|
+
* @param BrandName - Optional brand name for nominal typing (defaults to never = no brand)
|
|
24
|
+
*
|
|
25
|
+
* When BrandName is provided, the type becomes nominally branded, preventing
|
|
26
|
+
* accidental assignment of plain strings/numbers to branded types.
|
|
27
|
+
* */
|
|
28
|
+
export type TypeFormat<
|
|
29
|
+
BaseType extends TypeFormatPrimitives,
|
|
30
|
+
Name extends string,
|
|
31
|
+
P extends TypeFormatParams,
|
|
32
|
+
BrandName extends string = never,
|
|
33
|
+
> = [BrandName] extends [never]
|
|
34
|
+
? BaseType & TypeAnnotation<Name, P>
|
|
35
|
+
: Brand<BaseType, BrandName> & TypeAnnotation<Name, P & {brand: BrandName}>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Binary Serialization/Deserialization Specification
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document specifies the implementation of JIT Binary serialization and deserialization for the Mion run-types package.
|
|
6
|
+
All binary serialization and deserialization functions are based on the [seqproto](https://github.com/oramasearch/seqproto) library that is highly optimized for js engines and multi-platform.
|
|
7
|
+
|
|
8
|
+
This spec is designed to work and support all TypeScript features, like Unions, Intersections, etc. while leveraging seqproto's high-performance encoding strategies.
|
|
9
|
+
|
|
10
|
+
All data is encoded/decoded into a single [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) using **32-bit aligned** memory access patterns for optimal CPU performance.
|
|
11
|
+
|
|
12
|
+
## SeqProto Alignment Strategy
|
|
13
|
+
|
|
14
|
+
Following seqproto's approach, all data is **32-bit aligned** (4-byte boundaries) for optimal performance:
|
|
15
|
+
|
|
16
|
+
- **Index tracking**: All positions tracked in 32-bit units
|
|
17
|
+
- **Memory access**: Direct typed array access (`uint32Array[index]`, `float32Array[index]`)
|
|
18
|
+
- **String encoding**: Uses `TextEncoder.encodeInto()` for zero-allocation encoding
|
|
19
|
+
- **Buffer management**: Pre-allocated reusable buffers with simple index reset
|
|
20
|
+
|
|
21
|
+
All functions used for encoding/decoding follow seqproto's optimized patterns and can be used in any JavaScript environment.
|
|
22
|
+
|
|
23
|
+
## Headers and Type Markers
|
|
24
|
+
|
|
25
|
+
Some variable length types and object properties require additional information. For these cases, we use **32-bit type markers** to indicate the length or type of the data that follows.
|
|
26
|
+
|
|
27
|
+
### SeqProto Type Headers (32-bit aligned)
|
|
28
|
+
|
|
29
|
+
SeqProto uses type markers for number encoding. All headers are 32-bit values:
|
|
30
|
+
|
|
31
|
+
| Header | Value | Description |
|
|
32
|
+
| ------------- | ----- | ----------------------- |
|
|
33
|
+
| `TYPE_FLOAT` | 0 | 32-bit IEEE 754 float |
|
|
34
|
+
| `TYPE_UINT32` | 1 | 32-bit unsigned integer |
|
|
35
|
+
| `TYPE_INT32` | 2 | 32-bit signed integer |
|
|
36
|
+
|
|
37
|
+
### Object Property Headers (Mion-specific)
|
|
38
|
+
|
|
39
|
+
SeqProto doesn't handle object properties, so we define our own property encoding system:
|
|
40
|
+
|
|
41
|
+
| Header Type | Bit Layout | Description | Max Values |
|
|
42
|
+
| -------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------- |
|
|
43
|
+
| **Known Property** | no header required | Index of the property in the Type definition, optional props that are not defined are not serialized | 65536 properties |
|
|
44
|
+
| **Unknown Property** | `[length + string prop name]` | Dynamic property name | Unlimited |
|
|
45
|
+
|
|
46
|
+
### Arrays
|
|
47
|
+
|
|
48
|
+
| Collection | Bit Layout | Description |
|
|
49
|
+
| ---------- | --------------------- | ------------------------------------ |
|
|
50
|
+
| **Array** | `[length + elements]` | Length as uint32, number of elements |
|
|
51
|
+
|
|
52
|
+
### Number Types (Type-Aware Encoding)
|
|
53
|
+
|
|
54
|
+
Following seqproto's number encoding strategy:
|
|
55
|
+
|
|
56
|
+
| Type | Bytes | Bit Layout | Notes |
|
|
57
|
+
| ---------------------- | ----- | ----------------------- | ------------------------------- |
|
|
58
|
+
| **Integer (positive)** | 4 | `TYPE_UINT32` + `value` | `value >= 0 && value % 1 === 0` |
|
|
59
|
+
| **Integer (negative)** | 4 | `TYPE_INT32` + `value` | `value < 0 && value % 1 === 0` |
|
|
60
|
+
| **Float** | 4 | `TYPE_FLOAT` + `value` | `value % 1 !== 0` |
|
|
61
|
+
| **BigInt** | 8 | `TYPE_BIGINT` + `value` | |
|
|
62
|
+
|
|
63
|
+
### Primitive Types (32-bit Aligned)
|
|
64
|
+
|
|
65
|
+
| Type | Bytes | Notes |
|
|
66
|
+
| ------------- | ----- | ----------------------------------------------------------------- |
|
|
67
|
+
| **Boolean** | 4 | 32-bit aligned for performance |
|
|
68
|
+
| **Null** | 4 | null is serialized as 0 |
|
|
69
|
+
| **Undefined** | 4 | undefined is serialized as -1, undefined props are not serialized |
|
|
70
|
+
| **Date** | 8 | serialized as number |
|
|
71
|
+
|
|
72
|
+
### String Types (Zero-Allocation Encoding)
|
|
73
|
+
|
|
74
|
+
| Type | Bit Layout | Notes |
|
|
75
|
+
| ---------- | ------------------- | --------------------- |
|
|
76
|
+
| **String** | `[length, content]` | byte length is 32 bit |
|
|
77
|
+
| **RegExp** | `[source, flags]` | |
|
|
78
|
+
|
|
79
|
+
## Complex Types (SeqProto-Compatible)
|
|
80
|
+
|
|
81
|
+
### Collection Types
|
|
82
|
+
|
|
83
|
+
| Type | Encoding Strategy | Notes |
|
|
84
|
+
| ---------- | ------------------------------------------------------------------------------------------ | -------------------------------- |
|
|
85
|
+
| **Array** | `uint32Array[index++] = TYPE_ARRAY; uint32Array[index++] = length; [encode each element]` | Length + elements |
|
|
86
|
+
| **Object** | `uint32Array[index++] = TYPE_OBJECT; uint32Array[index++] = propCount; [encode each prop]` | Property count + key-value pairs |
|
|
87
|
+
| **Map** | Serialize as Array of `[key, value]` tuples | Use seqproto function |
|
|
88
|
+
| **Set** | Serialize as Array of values | Use seqproto function |
|
|
89
|
+
| **Class** | Serialize as data only, functions are not serialized. | Use object function |
|
|
90
|
+
|
|
91
|
+
### Object Serialization
|
|
92
|
+
|
|
93
|
+
Object are serialized with all required props in order, this guarantee fast and simple sequential serialization/deserialization.
|
|
94
|
+
Optional props are serialized as [`optional props bitmap + optional props values`].
|
|
95
|
+
The bitmap for optional props is variable length but determined at compile time depending on the number of optional props min length is 4 bytes, and then the optional props.
|
|
96
|
+
Each bit in the bitmap represents whether the corresponding optional prop is present or not. so the number of optional props corresponds to the number of bits to 1 in the bitmap.
|
|
97
|
+
|
|
98
|
+
### Object Properties (32-bit Aligned)
|
|
99
|
+
|
|
100
|
+
| Property Type | Bit Layout | Encoding | Notes |
|
|
101
|
+
| ---------------------- | ------------------------------------------------- | ------------------------------------------- | -------------------------------------------------- |
|
|
102
|
+
| **Non Optional props** | `value` | `[encode value]` | Serialized in order they are declared in the type. |
|
|
103
|
+
| **Optional props** | `[optional props bitmap + optional props values]` | | |
|
|
104
|
+
| **Unknown Props** | `[string prop name + value]` | `serializeString(propName); [encode value]` | used inIndexSignature or Records |
|
|
105
|
+
|
|
106
|
+
### TypeScript Features
|
|
107
|
+
|
|
108
|
+
| Feature | Encoding Strategy | Notes |
|
|
109
|
+
| ----------------- | ---------------------------------------------------------------------------------------------- | ------------------ |
|
|
110
|
+
| **Union Types** | `uint32Array[index++] = TYPE_UNION; uint32Array[index++] = discriminatorIndex; [encode value]` | Type index + value |
|
|
111
|
+
| **Tuple** | Serialize as Array | Fixed-length array |
|
|
112
|
+
| **Enum** | `[type, value]` where type indicates string or number | |
|
|
113
|
+
| **Literal Types** | Serialize underlying value | |
|
|
114
|
+
|
|
115
|
+
#### TypeScript Features
|
|
116
|
+
|
|
117
|
+
**Maps and Sets**:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// Map<K,V> → Array<[K,V]> → Binary Array of tuples [K,V]
|
|
121
|
+
// Set<T> → Array<T> → Binary Array
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Union Types**:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Discriminated unions use type field for variant identification
|
|
128
|
+
// Primitive unions encode based on runtime type detection
|
|
129
|
+
// [discriminator, value]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Complex Collections**:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Tuples → Arrays with fixed length validation
|
|
136
|
+
// Records → Objects with dynamic key validation
|
|
137
|
+
// Classes → Objects with constructor information
|
|
138
|
+
```
|