@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,320 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* ########
|
|
3
|
+
* 2025 mion
|
|
4
|
+
* Author: Ma-jerez
|
|
5
|
+
* License: MIT
|
|
6
|
+
* The software is provided "as is", without warranty of any kind.
|
|
7
|
+
* ######## */
|
|
8
|
+
import type {TypeFormatParams, CompiledPureFunction, TypeFormatValue, JitCompiledFn} from '@mionjs/core';
|
|
9
|
+
import type {BaseRunType} from './baseRunTypes.ts';
|
|
10
|
+
import {createJitCompiler, type JitFnCompiler, type JitErrorsFnCompiler} from './jitFnCompiler.ts';
|
|
11
|
+
import type {JitFnID, Mutable, StrNumber, JitCode, RunTypeOptions} from '../types.ts';
|
|
12
|
+
import {JitFunctions} from '../constants.functions.ts';
|
|
13
|
+
import {ReflectionKind} from '@deepkit/type';
|
|
14
|
+
import {dependenciesToLiteral, getFormatterParams, paramsToLiteral} from './formats.ts';
|
|
15
|
+
import {getFormatterHash} from './utils.ts';
|
|
16
|
+
import {getENV, getJitUtils} from '@mionjs/core';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base class for all RunType formatters.
|
|
20
|
+
* A type format is a type that satisfies some extra constrains, like emails, alphanumeric, uuids etc...
|
|
21
|
+
* All those are formats of string.
|
|
22
|
+
* At the moment only formats for string and numbers are supported.
|
|
23
|
+
* Jit formatters receive some params and generate JIT code depending on these params.
|
|
24
|
+
*/
|
|
25
|
+
export abstract class BaseRunTypeFormat<P extends TypeFormatParams = any> {
|
|
26
|
+
abstract kind: ReflectionKind;
|
|
27
|
+
abstract name: string;
|
|
28
|
+
/** The namespace for pure functions used by this formatter. Defaults to 'mionFormats'. */
|
|
29
|
+
readonly namespace: string = 'mionFormats';
|
|
30
|
+
rootFormatName: string = '';
|
|
31
|
+
/**
|
|
32
|
+
* The jit code for the formatter can be embedded together with the jit code for the type itself.
|
|
33
|
+
* but sometimes is better to create a separate function for code to be reused.
|
|
34
|
+
* This method is used to determine if the formatter code can be embedded or not.
|
|
35
|
+
*/
|
|
36
|
+
canEmbedFormatterCode(_fnId: JitFnID, rt: BaseRunType, _params?: P): boolean {
|
|
37
|
+
if (rt.src.kind === ReflectionKind.number) return true;
|
|
38
|
+
// getFormatterJitId is similar to convert params to string
|
|
39
|
+
const paramsToString = rt.getFormatTypeID() || '';
|
|
40
|
+
// if there are many params, is better to not inline the formatter so the formatter function can be reused
|
|
41
|
+
// in the future we could optimize this logic, to decide if a formatter should be embedded or not
|
|
42
|
+
return paramsToString.length < 300;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Params from parent formatter */
|
|
46
|
+
readonly paramsFromParent?: P;
|
|
47
|
+
/**
|
|
48
|
+
* When set this in the path to the params in the parent's params object.
|
|
49
|
+
* ie: if dateTime is the parent of the current formatter and params are {date: {format: 'ISO'}} then the child path will be ['date']
|
|
50
|
+
*/
|
|
51
|
+
readonly parentPath?: StrNumber[];
|
|
52
|
+
/** List of params that will be excluded from jit code */
|
|
53
|
+
readonly extraPathLiteral?: StrNumber;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The parentPath is the path to the params in the parent's params Formatter.
|
|
57
|
+
* ie: if dateTime is the parent of the current formatter and params are {date: {format: 'ISO'}} then the child path will be ['date']
|
|
58
|
+
*/
|
|
59
|
+
constructor(parentPath?: StrNumber[]) {
|
|
60
|
+
this.parentPath = parentPath;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private pushContext(paramsFromParent?: P) {
|
|
64
|
+
(this as Mutable<BaseRunTypeFormat>).paramsFromParent = paramsFromParent;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private popContext() {
|
|
68
|
+
(this as Mutable<BaseRunTypeFormat>).paramsFromParent = undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isRootFormat() {
|
|
72
|
+
return !this.parentPath?.length;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getFormatNestLevel() {
|
|
76
|
+
return this.parentPath?.length || 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getParams(rt: BaseRunType): NonNullable<P> {
|
|
80
|
+
if (this.paramsFromParent) return this.paramsFromParent as NonNullable<P>;
|
|
81
|
+
const params = getFormatterParams(rt, this.name) as NonNullable<P>;
|
|
82
|
+
return params;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getFormatName(): string {
|
|
86
|
+
return this.rootFormatName || this.name;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Returns the path to the params in the parent's params object */
|
|
90
|
+
getFormatPath(paramName?: StrNumber): StrNumber[] {
|
|
91
|
+
if (!paramName && this.parentPath) return [...this.parentPath];
|
|
92
|
+
if (!paramName) return [];
|
|
93
|
+
return this.parentPath ? [...this.parentPath, paramName] : [paramName];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getFormatExtraPathLiteral(): StrNumber | undefined {
|
|
97
|
+
return this.extraPathLiteral;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getIgnoredProps(): string[] | undefined {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
mock(opts: RunTypeOptions, rt: BaseRunType, params?: P): any {
|
|
105
|
+
if (this.validateParams) this.validateParams(rt, params || this.getParams(rt));
|
|
106
|
+
this.pushContext(params);
|
|
107
|
+
const result = this._mock(opts, rt);
|
|
108
|
+
this.popContext();
|
|
109
|
+
const formatter = this.createJitCompiledFormatter(JitFunctions.format.id, rt, undefined, params);
|
|
110
|
+
if (formatter.isNoop) return result;
|
|
111
|
+
return formatter.fn(result);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
createJitCompiledFormatter(
|
|
115
|
+
fnID: JitFnID,
|
|
116
|
+
rt: BaseRunType,
|
|
117
|
+
comp?: JitFnCompiler,
|
|
118
|
+
params?: P,
|
|
119
|
+
vλl?: string,
|
|
120
|
+
formatName?: string,
|
|
121
|
+
opts: RunTypeOptions = {}
|
|
122
|
+
): JitCompiledFn {
|
|
123
|
+
const hash = getFormatterHash(rt);
|
|
124
|
+
// created function will be an aux function prefixed with the original function id
|
|
125
|
+
// this is because the new jit function itself is a standalone function and we don't want it colliding with any other jit function
|
|
126
|
+
const jitFnHash = `${JitFunctions.aux.id}_${fnID}_${hash}`;
|
|
127
|
+
const jitCompiled = getJitUtils().getJIT(jitFnHash);
|
|
128
|
+
if (jitCompiled) {
|
|
129
|
+
if (getENV('DEBUG_JIT') === 'VERBOSE')
|
|
130
|
+
console.log(`\x1b[32m Using cached function: ${jitCompiled.jitFnHash} \x1b[0m`);
|
|
131
|
+
comp?.updateDependencies(jitCompiled);
|
|
132
|
+
return jitCompiled;
|
|
133
|
+
}
|
|
134
|
+
// TODO: decide if we should add parent compiler or not as parent to createJitCompiler
|
|
135
|
+
const newJitCompiler: JitFnCompiler = createJitCompiler(rt, fnID, undefined, jitFnHash, hash, opts);
|
|
136
|
+
try {
|
|
137
|
+
const formatterCode = this.compileFormat(fnID, newJitCompiler, rt, params, vλl, formatName);
|
|
138
|
+
const withReturn = this.handleReturnValues(rt, newJitCompiler, formatterCode);
|
|
139
|
+
newJitCompiler.createJitFunction(withReturn);
|
|
140
|
+
comp?.updateDependencies(newJitCompiler as JitCompiledFn);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
// if something goes wrong during compilation we want to remove the compiler from
|
|
143
|
+
// the cache as this is automatically added to jitUtils cache during compilation
|
|
144
|
+
newJitCompiler.removeFromJitCache();
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return newJitCompiler as JitCompiledFn;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
compileFormat(
|
|
152
|
+
fnID: JitFnID,
|
|
153
|
+
comp: JitFnCompiler,
|
|
154
|
+
rt: BaseRunType,
|
|
155
|
+
params?: P,
|
|
156
|
+
vλl?: string,
|
|
157
|
+
formatName?: string,
|
|
158
|
+
extraPathLiteral?: StrNumber
|
|
159
|
+
): JitCode {
|
|
160
|
+
if (this.validateParams) this.validateParams(rt, params || this.getParams(rt));
|
|
161
|
+
(this as Mutable<BaseRunTypeFormat>).extraPathLiteral = extraPathLiteral;
|
|
162
|
+
const v = comp.vλl;
|
|
163
|
+
comp.vλl = vλl || v;
|
|
164
|
+
this.rootFormatName = formatName || this.name;
|
|
165
|
+
this.pushContext(params);
|
|
166
|
+
let result: JitCode;
|
|
167
|
+
switch (fnID) {
|
|
168
|
+
case JitFunctions.isType.id:
|
|
169
|
+
result = this.emitIsType(comp, rt);
|
|
170
|
+
break;
|
|
171
|
+
case JitFunctions.typeErrors.id:
|
|
172
|
+
result = this.emitIsTypeErrors(comp as JitErrorsFnCompiler, rt);
|
|
173
|
+
break;
|
|
174
|
+
case JitFunctions.format.id:
|
|
175
|
+
result = this.emitFormat ? this.emitFormat(comp, rt) : {code: undefined, type: 'S'};
|
|
176
|
+
break;
|
|
177
|
+
case JitFunctions.toBinary.id:
|
|
178
|
+
result = this.emitToBinary ? this.emitToBinary(comp, rt) : {code: undefined, type: 'S'};
|
|
179
|
+
break;
|
|
180
|
+
case JitFunctions.fromBinary.id:
|
|
181
|
+
result = this.emitFromBinary ? this.emitFromBinary(comp, rt) : {code: undefined, type: 'S'};
|
|
182
|
+
break;
|
|
183
|
+
// JSON serialization functions - formats don't need special handling for JSON
|
|
184
|
+
// Just return the value as-is (expression type 'E' with empty code means use vλl)
|
|
185
|
+
case JitFunctions.prepareForJson.id:
|
|
186
|
+
case JitFunctions.restoreFromJson.id:
|
|
187
|
+
case JitFunctions.stringifyJson.id:
|
|
188
|
+
case JitFunctions.toJSCode.id:
|
|
189
|
+
result = {code: '', type: 'E'};
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
throw new Error(`Method not implemented: ${fnID}`);
|
|
193
|
+
}
|
|
194
|
+
this.popContext();
|
|
195
|
+
this.rootFormatName = this.name;
|
|
196
|
+
(this as Mutable<BaseRunTypeFormat>).extraPathLiteral = undefined;
|
|
197
|
+
comp.vλl = v;
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Adds return statements if needed
|
|
203
|
+
* Unlike handleReturnValues in BaseRunType this one is only called in the root of the formatter
|
|
204
|
+
*/
|
|
205
|
+
handleReturnValues(rt: BaseRunType, comp: JitFnCompiler, jitC: JitCode): string {
|
|
206
|
+
if (!jitC?.code) return '';
|
|
207
|
+
const codeType = jitC.type;
|
|
208
|
+
switch (codeType) {
|
|
209
|
+
case 'E':
|
|
210
|
+
return `return ${jitC.code}`;
|
|
211
|
+
case 'RB':
|
|
212
|
+
return jitC.code;
|
|
213
|
+
case 'S': {
|
|
214
|
+
// For non-expressions, add a return statement with the default return value
|
|
215
|
+
// if the code doesn't already have a return statement
|
|
216
|
+
const lastChar = jitC.code.length - 1;
|
|
217
|
+
const hasFullStop = jitC.code.lastIndexOf(';') === lastChar || jitC.code.lastIndexOf('}') === lastChar;
|
|
218
|
+
const stopChar = hasFullStop ? '' : ';';
|
|
219
|
+
return `${jitC.code}${stopChar} return ${comp.returnName}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
abstract _mock(opts: RunTypeOptions, rt: BaseRunType): any;
|
|
225
|
+
abstract emitIsType(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
226
|
+
abstract emitIsTypeErrors(comp: JitErrorsFnCompiler, rt: BaseRunType): JitCode;
|
|
227
|
+
|
|
228
|
+
// ###### optional methods for type formatters ########
|
|
229
|
+
|
|
230
|
+
/** Optional method to compile the formatter function that transforms/sanitize a value */
|
|
231
|
+
emitFormat?(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
232
|
+
|
|
233
|
+
/** Optional method that customizes the binary serialization */
|
|
234
|
+
emitToBinary?(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
235
|
+
/** Optional method that customizes the binary deserialization */
|
|
236
|
+
emitFromBinary?(comp: JitFnCompiler, rt: BaseRunType): JitCode;
|
|
237
|
+
|
|
238
|
+
/** Throws an error if params are not valid */
|
|
239
|
+
validateParams?(rt: BaseRunType, params: P): void;
|
|
240
|
+
|
|
241
|
+
compilePureFunctionCall(
|
|
242
|
+
comp: JitFnCompiler,
|
|
243
|
+
rt: BaseRunType,
|
|
244
|
+
compiledPureFn: CompiledPureFunction,
|
|
245
|
+
params?: TypeFormatValue,
|
|
246
|
+
dependenciesParams?: Record<string, string | CompiledPureFunction>
|
|
247
|
+
): {callCode: string; fnName: string; paramsName: string; dependenciesName?: string} {
|
|
248
|
+
// PureFunction arguments =>
|
|
249
|
+
|
|
250
|
+
// val: any
|
|
251
|
+
// formatParams: TypeFormatValue,
|
|
252
|
+
// deps: PureFunctionDeps
|
|
253
|
+
|
|
254
|
+
const val = comp.vλl;
|
|
255
|
+
const paramsName = paramsToLiteral(comp, params || this.getParams(rt), this.getIgnoredProps());
|
|
256
|
+
const dependenciesName = dependenciesToLiteral(comp, dependenciesParams || {});
|
|
257
|
+
const callParams = [val, paramsName, dependenciesName];
|
|
258
|
+
const fnName = comp.addPureFunction(compiledPureFn);
|
|
259
|
+
const callCode = `${fnName}(${callParams.join(',')})`;
|
|
260
|
+
return {callCode, fnName, paramsName, dependenciesName};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
compileErrorsPureFunctionCall(
|
|
264
|
+
comp: JitErrorsFnCompiler,
|
|
265
|
+
rt: BaseRunType,
|
|
266
|
+
compiledPureFn: CompiledPureFunction,
|
|
267
|
+
params: TypeFormatValue,
|
|
268
|
+
dependenciesParams?: Record<string, string | CompiledPureFunction>,
|
|
269
|
+
extraPathLiteral?: StrNumber // TODO: this might not be needed
|
|
270
|
+
): {callCode: string; fnName: string; paramsName: string; dependenciesName?: string} {
|
|
271
|
+
// ErrorsPureFunction arguments =>
|
|
272
|
+
|
|
273
|
+
// val: any,
|
|
274
|
+
// pλth: StrNumber[],
|
|
275
|
+
// εrr: RunTypeError[],
|
|
276
|
+
// expected: string,
|
|
277
|
+
|
|
278
|
+
// formatName: string,
|
|
279
|
+
// formatParams: P,
|
|
280
|
+
// formatPath: StrNumber[],
|
|
281
|
+
// deps: PureFunctionDeps,
|
|
282
|
+
// accessPath?: StrNumber[]
|
|
283
|
+
|
|
284
|
+
const val = comp.vλl;
|
|
285
|
+
const path = comp.args.pλth;
|
|
286
|
+
const err = comp.args.εrr;
|
|
287
|
+
const expected = paramsToLiteral(comp, rt.getKindName());
|
|
288
|
+
|
|
289
|
+
const formatName = paramsToLiteral(comp, this.getFormatName());
|
|
290
|
+
const formatParams = paramsToLiteral(comp, params, this.getIgnoredProps());
|
|
291
|
+
const formatPath = paramsToLiteral(comp, this.getFormatPath());
|
|
292
|
+
const deps = dependenciesToLiteral(comp, dependenciesParams || {});
|
|
293
|
+
const accessPath = comp.getAccessPathLiteral(extraPathLiteral);
|
|
294
|
+
|
|
295
|
+
const callParams = [val, path, err, expected, formatName, formatParams, formatPath, deps];
|
|
296
|
+
if (accessPath) callParams.push(accessPath);
|
|
297
|
+
|
|
298
|
+
const fnName = comp.addPureFunction(compiledPureFn);
|
|
299
|
+
const callCode = `${fnName}(${callParams.join(',')})`;
|
|
300
|
+
return {callCode, fnName, paramsName: formatParams, dependenciesName: deps};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
getCallJitFormatErr(
|
|
304
|
+
comp: JitErrorsFnCompiler,
|
|
305
|
+
expected: BaseRunType<any>,
|
|
306
|
+
formatter: BaseRunTypeFormat<any>,
|
|
307
|
+
shouldReturn = false,
|
|
308
|
+
extraPathLiteral?: StrNumber
|
|
309
|
+
) {
|
|
310
|
+
return (paramName: string, paramValue: string | number | boolean | bigint) => {
|
|
311
|
+
const callCode = comp.callJitFormatErr(expected, formatter, paramName, paramValue, extraPathLiteral);
|
|
312
|
+
if (shouldReturn) return `return ${callCode}, ${comp.args.εrr}`;
|
|
313
|
+
return callCode;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
printPath(rt: BaseRunType, paramName?: string): string {
|
|
318
|
+
return [rt.getTypeName(), ...this.getFormatPath(paramName)].join('.');
|
|
319
|
+
}
|
|
320
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
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
|
+
import {MAX_STACK_DEPTH, JitCompiledFn, createUniqueHash, getJitUtils, getENV} from '@mionjs/core';
|
|
9
|
+
import type {
|
|
10
|
+
RunType,
|
|
11
|
+
Mutable,
|
|
12
|
+
RunTypeChildAccessor,
|
|
13
|
+
JitFnID,
|
|
14
|
+
SrcType,
|
|
15
|
+
SrcCollection,
|
|
16
|
+
CustomVλl,
|
|
17
|
+
JitFn,
|
|
18
|
+
JitCode,
|
|
19
|
+
RunTypeOptions,
|
|
20
|
+
StrNumber,
|
|
21
|
+
DeepPartial,
|
|
22
|
+
RunTypeFamily,
|
|
23
|
+
} from '../types.ts';
|
|
24
|
+
import type {mockType} from '../mocking/mockType.ts';
|
|
25
|
+
import {maxStackErrorMessage} from '../constants.ts';
|
|
26
|
+
import {type CodeType, JitFunctions, CodeTypes} from '../constants.functions.ts';
|
|
27
|
+
import {ReflectionKind, stringifyType} from '@deepkit/type';
|
|
28
|
+
import type {TypeIndexSignature, TypeProperty, Type} from '@deepkit/type';
|
|
29
|
+
import {getPropIndex, memorize} from './utils.ts';
|
|
30
|
+
import {createJitCompiler, MockJitCompiler} from './jitFnCompiler.ts';
|
|
31
|
+
import {getJITFnHash} from './createJitFunction.ts';
|
|
32
|
+
import type {JitFnCompiler, JitErrorsFnCompiler} from './jitFnCompiler.ts';
|
|
33
|
+
import {type AnyKindName, getReflectionName} from '../constants.kind.ts';
|
|
34
|
+
import {initFormatAnnotations} from './formats.ts';
|
|
35
|
+
import {createTypeId} from './typeId.ts';
|
|
36
|
+
import {getJitFunctionCompiler, registerJitFunctionCompiler} from './jitFnsRegistry.ts';
|
|
37
|
+
import {defaultMockOptions} from '../mocking/constants.mock.ts';
|
|
38
|
+
|
|
39
|
+
const RB = CodeTypes.returnBlock;
|
|
40
|
+
const S = CodeTypes.statement;
|
|
41
|
+
const E = CodeTypes.expression;
|
|
42
|
+
|
|
43
|
+
export abstract class BaseRunType<T extends Type = Type> implements RunType {
|
|
44
|
+
isCircular?: boolean;
|
|
45
|
+
readonly src: SrcType<T> = null as any; // real value will be set after construction by the createRunType function
|
|
46
|
+
abstract getFamily(): RunTypeFamily; // Atomic, Collection, Member, Function
|
|
47
|
+
/**
|
|
48
|
+
* This single functions controls whether or not the code for a type should be inlined into the parent function
|
|
49
|
+
* or should create a separate jit function for it, add as a dependency and call it.
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
isJitInlined = (): boolean => {
|
|
53
|
+
// if is circular, always create a separate jit function as need to self invoke
|
|
54
|
+
if (this.isCircular) return false;
|
|
55
|
+
if (getENV('DEBUG_JIT') === 'INLINED') return true;
|
|
56
|
+
// all array are self invoked for isType and are usually repeated type like string[] or number[] so worth deduplicating
|
|
57
|
+
if (this.src.kind === ReflectionKind.array) return false;
|
|
58
|
+
// collection with name might be used in different places so worth deduplicating
|
|
59
|
+
if (this.src.typeName && this.getFamily() === 'C') return false;
|
|
60
|
+
return true;
|
|
61
|
+
};
|
|
62
|
+
getKindName = memorize((): AnyKindName => getReflectionName(this));
|
|
63
|
+
getTypeName = (): string => this.src.typeName || this.getKindName();
|
|
64
|
+
stringify = memorize((): string => stringifyType(this.src));
|
|
65
|
+
skipJit(comp: JitFnCompiler): boolean {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/** Returns the format portion of the type ID (cached in src._formatId), or undefined if no format. */
|
|
69
|
+
getFormatTypeID(): string | undefined {
|
|
70
|
+
// _formatId is cached by computeDeepkitFormatID during getDeepkitTypeId call
|
|
71
|
+
// Empty string means no format, undefined means not computed yet
|
|
72
|
+
const formatId = (this.src as any)._formatId;
|
|
73
|
+
return formatId || undefined;
|
|
74
|
+
}
|
|
75
|
+
/** Returns the type ID which is cached in src._typeId by getDeepkitTypeId(). Format ID is already included. */
|
|
76
|
+
getTypeID(): StrNumber {
|
|
77
|
+
if (this.src._typeId === undefined) {
|
|
78
|
+
throw new Error(`Missing cached type ID for ${this.getTypeName()}. Ensure getDeepkitTypeId() has been called.`);
|
|
79
|
+
}
|
|
80
|
+
return this.src._typeId;
|
|
81
|
+
}
|
|
82
|
+
getJitHash(opts: RunTypeOptions): string {
|
|
83
|
+
const optsCopy = {...opts};
|
|
84
|
+
// remove mock options as not relevant for jit functionality
|
|
85
|
+
if (optsCopy.mock) delete optsCopy.mock;
|
|
86
|
+
return createUniqueHash(this.getTypeID().toString() + JSON.stringify(optsCopy));
|
|
87
|
+
}
|
|
88
|
+
getParent = (): BaseRunType | undefined => (this.src.parent as SrcType)?._rt as BaseRunType;
|
|
89
|
+
checkIsCircularAndGetRefId(stack: RunType[] = []): StrNumber | undefined {
|
|
90
|
+
const inStackIndex = stack.findIndex((rt) => {
|
|
91
|
+
if (rt === this) return true;
|
|
92
|
+
// some nodes seems to be different objects in memory but are the same id, so we check by id as well
|
|
93
|
+
return rt.src.id && this.src.id && rt.src.id === this.src.id;
|
|
94
|
+
}); // cant use isSameJitType because it uses getTypeID and would loop forever
|
|
95
|
+
const inStackSrcId = stack.findIndex((rt) => rt.src.id && this.src.id && rt.src.id === this.src.id);
|
|
96
|
+
const isInStack = inStackIndex >= 0; // recursive reference
|
|
97
|
+
if (isInStack) {
|
|
98
|
+
this.isCircular = true;
|
|
99
|
+
const name = this.src.typeName || ''; // todo: not sure if all the circular references will have a name
|
|
100
|
+
const refId = '$' + this.src.kind + `_${inStackIndex}` + name; // ensures different circular types have different typeID
|
|
101
|
+
return refId;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Method that should be called Immediately after the RunType gets created to link the SrcType and RunType.
|
|
107
|
+
* This is more flexible than passing params to the constructor helps to avoid circular dependencies, etc.
|
|
108
|
+
* */
|
|
109
|
+
onCreated(src: SrcType<any>): void {
|
|
110
|
+
(this as Mutable<RunType>).src = src;
|
|
111
|
+
(src as Mutable<SrcType>)._rt = this;
|
|
112
|
+
initFormatAnnotations(this);
|
|
113
|
+
// Cache the type ID on the src object - this includes format information
|
|
114
|
+
createTypeId(src);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Some elements might need a standalone name variable that ignores the vλl value of the parents.
|
|
118
|
+
* returns a variable that is being compiled, ignores the parents variable names */
|
|
119
|
+
getCustomVλl(comp: JitFnCompiler): CustomVλl | undefined {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Some elements might need a custom static path to be able to reference the source of an error.
|
|
124
|
+
* ie: when validating a Map we need to differentiate if the value that failed is the key or the value of a map's entry.
|
|
125
|
+
*/
|
|
126
|
+
getStaticPathLiteral(comp: JitFnCompiler): string | number | undefined {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ########## Mock ##########
|
|
131
|
+
|
|
132
|
+
async mock(opts?: DeepPartial<RunTypeOptions>): Promise<any> {
|
|
133
|
+
// although the mock function is not jit, it is also stored in the registry
|
|
134
|
+
// this is because we don't want to load mock related functionality if not needed
|
|
135
|
+
await registerJitFunctionCompiler(JitFunctions.mock);
|
|
136
|
+
return this.mockType(opts);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** synchronous version of mock, throws an error if the mock function has not been loaded */
|
|
140
|
+
mockType(opts: DeepPartial<RunTypeOptions> = {}): any {
|
|
141
|
+
const mockFn = getJitFunctionCompiler(JitFunctions.mock) as typeof mockType;
|
|
142
|
+
if (!mockFn)
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Function ${JitFunctions.mock.name} has not been loaded. make sure you have called loadJitCompilerFunction(JitFunctions.mock) before calling mockType.`
|
|
145
|
+
);
|
|
146
|
+
const fnID = JitFunctions.mock.id;
|
|
147
|
+
// options sent to the compiler will be set to empty as mock options are handled separately from the compiler
|
|
148
|
+
const mockingOpts = {...opts, mock: {...defaultMockOptions, ...(opts.mock || {})}} as RunTypeOptions;
|
|
149
|
+
const hash = getJITFnHash(fnID, this, mockingOpts);
|
|
150
|
+
const comp = new MockJitCompiler(this, mockingOpts, undefined, hash, this.getTypeID());
|
|
151
|
+
return mockFn(this, comp);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ########## Create Jit Functions ##########
|
|
155
|
+
|
|
156
|
+
createJitFunction = (jitFn: JitFn, opts: RunTypeOptions = {}): ((...args: any[]) => any) => {
|
|
157
|
+
return this.createJitCompiledFunction(jitFn.id, undefined, opts).fn;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
createJitCompiledFunction(fnID: JitFnID, parentCop?: JitFnCompiler, opts: RunTypeOptions = {}): JitCompiledFn {
|
|
161
|
+
const fnHash = getJITFnHash(fnID, this, opts);
|
|
162
|
+
const jitCompiled = getJitUtils().getJIT(fnHash);
|
|
163
|
+
if (jitCompiled) {
|
|
164
|
+
if (getENV('DEBUG_JIT') === 'VERBOSE')
|
|
165
|
+
console.log(`\x1b[32m Using cached function: ${jitCompiled.jitFnHash} \x1b[0m`);
|
|
166
|
+
return jitCompiled;
|
|
167
|
+
}
|
|
168
|
+
const newJitCompiler: JitFnCompiler = createJitCompiler(
|
|
169
|
+
this,
|
|
170
|
+
fnID,
|
|
171
|
+
parentCop,
|
|
172
|
+
undefined,
|
|
173
|
+
undefined,
|
|
174
|
+
opts
|
|
175
|
+
) as JitFnCompiler;
|
|
176
|
+
try {
|
|
177
|
+
const codeType = this.getFamily() === 'A' ? E : S;
|
|
178
|
+
newJitCompiler.compile(this, codeType, fnID);
|
|
179
|
+
newJitCompiler.createJitFunction();
|
|
180
|
+
} catch (e: any) {
|
|
181
|
+
// if something goes wrong during compilation we want to remove the compiler from
|
|
182
|
+
// the cache as this is automatically added to jitUtils cache during compilation
|
|
183
|
+
newJitCompiler.removeFromJitCache();
|
|
184
|
+
// TODO: we need to print the full path to the type that is causing the error
|
|
185
|
+
// for this ideally we should add a parent Compiler and print the trace only from the root
|
|
186
|
+
if (typeof e?.message === 'string' && !newJitCompiler.hasStackTrace(e.message))
|
|
187
|
+
e.message += newJitCompiler.getStackTrace();
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
return newJitCompiler as JitCompiledFn;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ########## emit Methods that generates src code ##########
|
|
194
|
+
|
|
195
|
+
abstract emitIsType(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
196
|
+
abstract emitTypeErrors(comp: JitErrorsFnCompiler, expectedCType: CodeType): JitCode;
|
|
197
|
+
abstract emitHasUnknownKeys(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
198
|
+
abstract emitUnknownKeyErrors(comp: JitErrorsFnCompiler, expectedCType: CodeType): JitCode;
|
|
199
|
+
abstract emitStripUnknownKeys(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
200
|
+
abstract emitUnknownKeysToUndefined(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
201
|
+
// todo: maybe we should move these two into a single file like the rest of serializers
|
|
202
|
+
abstract emitPrepareForJson(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
203
|
+
abstract emitRestoreFromJson(comp: JitFnCompiler, expectedCType: CodeType): JitCode;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* RunType that is atomic an does not contains any other child runTypes.
|
|
208
|
+
* ie: string, number, boolean, any, null, undefined, void, never, bigint, etc.
|
|
209
|
+
* */
|
|
210
|
+
export abstract class AtomicRunType<T extends Type> extends BaseRunType<T> {
|
|
211
|
+
getFamily(): 'A' {
|
|
212
|
+
return 'A';
|
|
213
|
+
}
|
|
214
|
+
emitPrepareForJson(comp: JitFnCompiler): JitCode {
|
|
215
|
+
return {code: undefined, type: S};
|
|
216
|
+
}
|
|
217
|
+
emitRestoreFromJson(comp: JitFnCompiler): JitCode {
|
|
218
|
+
return {code: undefined, type: S};
|
|
219
|
+
}
|
|
220
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
221
|
+
return {code: undefined, type: E};
|
|
222
|
+
}
|
|
223
|
+
emitUnknownKeyErrors(comp: JitFnCompiler): JitCode {
|
|
224
|
+
return {code: undefined, type: S};
|
|
225
|
+
}
|
|
226
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
227
|
+
return {code: undefined, type: S};
|
|
228
|
+
}
|
|
229
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {
|
|
230
|
+
return {code: undefined, type: S};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* RunType that contains a collection or child runTypes.
|
|
236
|
+
* Collection RunTypes are the only ones that can have circular references. as a child of a collection RunType can be the parent of the collection RunType.
|
|
237
|
+
* i.e: interface, child runTypes are it's properties
|
|
238
|
+
* i.e: tuple, it's child runTypes are the tuple members
|
|
239
|
+
*/
|
|
240
|
+
export abstract class CollectionRunType<T extends Type> extends BaseRunType<T> {
|
|
241
|
+
getFamily(): 'C' {
|
|
242
|
+
return 'C';
|
|
243
|
+
}
|
|
244
|
+
getChildRunTypes = (): BaseRunType[] => {
|
|
245
|
+
const childTypes = ((this.src as SrcCollection).types as SrcType[]) || []; // deepkit stores child types in the types property
|
|
246
|
+
return childTypes.map((t) => t._rt as BaseRunType);
|
|
247
|
+
};
|
|
248
|
+
getJitChildren(comp: JitFnCompiler): BaseRunType[] {
|
|
249
|
+
let skipIndex = false; // if there are multiple index signatures, only the first one will be used as they must be same type just different keys
|
|
250
|
+
return this.getChildRunTypes().filter((c) => {
|
|
251
|
+
if (c.skipJit(comp)) return false;
|
|
252
|
+
const isIndex = c.src.kind === ReflectionKind.indexSignature;
|
|
253
|
+
if (isIndex && skipIndex) return false;
|
|
254
|
+
if (isIndex) skipIndex = true;
|
|
255
|
+
return true;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
areAllChildrenOptional(children: BaseRunType[]) {
|
|
259
|
+
return children.every(
|
|
260
|
+
(prop) =>
|
|
261
|
+
(prop as MemberRunType<any>)?.isOptional() ||
|
|
262
|
+
(prop.src as TypeProperty)?.optional ||
|
|
263
|
+
prop.src.kind === ReflectionKind.indexSignature
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
267
|
+
const codes = this.getJitChildren(comp)
|
|
268
|
+
.map((c) => comp.compileHasUnknownKeys(c, E).code)
|
|
269
|
+
.filter((code) => !!code);
|
|
270
|
+
return {code: codes.join(' || '), type: E};
|
|
271
|
+
}
|
|
272
|
+
emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
273
|
+
const codes = this.getJitChildren(comp)
|
|
274
|
+
.map((c) => comp.compileUnknownKeyErrors(c, S).code)
|
|
275
|
+
.filter((code) => !!code);
|
|
276
|
+
return {code: codes.join(';'), type: S};
|
|
277
|
+
}
|
|
278
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
279
|
+
const codes = this.getJitChildren(comp)
|
|
280
|
+
.map((c) => comp.compileStripUnknownKeys(c, S).code)
|
|
281
|
+
.filter((code) => !!code);
|
|
282
|
+
return {code: codes.join(';'), type: S};
|
|
283
|
+
}
|
|
284
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {
|
|
285
|
+
const codes = this.getJitChildren(comp)
|
|
286
|
+
.map((c) => comp.compileUnknownKeysToUndefined(c, S).code)
|
|
287
|
+
.filter((code) => !!code);
|
|
288
|
+
return {code: codes.join(';'), type: S};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* RunType that contains a single member or child RunType. usually part of a collection RunType.
|
|
294
|
+
* i.e object properties, {prop: memberType} where memberType is the child RunType
|
|
295
|
+
*/
|
|
296
|
+
export abstract class MemberRunType<T extends Type> extends BaseRunType<T> implements RunTypeChildAccessor {
|
|
297
|
+
abstract isOptional(): boolean;
|
|
298
|
+
abstract getChildVarName(comp: JitFnCompiler): string | number;
|
|
299
|
+
abstract getChildLiteral(comp: JitFnCompiler): string | number;
|
|
300
|
+
abstract useArrayAccessor(): boolean;
|
|
301
|
+
/** used to compile json stringify */
|
|
302
|
+
skipCommas?: boolean;
|
|
303
|
+
/** used to compile json stringify */
|
|
304
|
+
tempChildVλl?: string;
|
|
305
|
+
getFamily(): 'M' {
|
|
306
|
+
return 'M';
|
|
307
|
+
}
|
|
308
|
+
getMemberType(): BaseRunType {
|
|
309
|
+
const memberType = (this.src as any).type as SrcType; // deepkit stores member types in the type property
|
|
310
|
+
return memberType._rt as BaseRunType;
|
|
311
|
+
}
|
|
312
|
+
getChildIndex(comp: JitFnCompiler) {
|
|
313
|
+
const start = comp?.opts?.paramsSlice?.start;
|
|
314
|
+
if (start) return getPropIndex(this.src) - start;
|
|
315
|
+
return getPropIndex(this.src);
|
|
316
|
+
}
|
|
317
|
+
getJitChild(comp: JitFnCompiler): BaseRunType | undefined {
|
|
318
|
+
const member: BaseRunType = this.getMemberType();
|
|
319
|
+
if (member.skipJit(comp)) return undefined;
|
|
320
|
+
return member;
|
|
321
|
+
}
|
|
322
|
+
emitHasUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
323
|
+
const child = this.getJitChild(comp);
|
|
324
|
+
const codeResult = comp.compileHasUnknownKeys(child, E);
|
|
325
|
+
if (!codeResult?.code) return {code: undefined, type: E};
|
|
326
|
+
const childName = comp.getChildVλl();
|
|
327
|
+
const finalCode = this.isOptional() ? `(${childName} !== undefined && ${codeResult.code})` : codeResult.code;
|
|
328
|
+
return {code: finalCode, type: codeResult.type};
|
|
329
|
+
}
|
|
330
|
+
emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {
|
|
331
|
+
const child = this.getJitChild(comp);
|
|
332
|
+
const codeResult = comp.compileUnknownKeyErrors(child, S);
|
|
333
|
+
if (!codeResult?.code) return {code: undefined, type: S};
|
|
334
|
+
const finalCode = this.isOptional() ? `if (${comp.getChildVλl()} !== undefined) {${codeResult.code}}` : codeResult.code;
|
|
335
|
+
return {code: finalCode, type: codeResult.type};
|
|
336
|
+
}
|
|
337
|
+
emitStripUnknownKeys(comp: JitFnCompiler): JitCode {
|
|
338
|
+
const child = this.getJitChild(comp);
|
|
339
|
+
const codeResult = comp.compileStripUnknownKeys(child, S);
|
|
340
|
+
if (!codeResult?.code) return {code: undefined, type: S};
|
|
341
|
+
const finalCode = this.isOptional() ? `if (${comp.getChildVλl()} !== undefined) {${codeResult.code}}` : codeResult.code;
|
|
342
|
+
return {code: finalCode, type: codeResult.type};
|
|
343
|
+
}
|
|
344
|
+
emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {
|
|
345
|
+
const child = this.getJitChild(comp);
|
|
346
|
+
const codeResult = comp.compileUnknownKeysToUndefined(child, S);
|
|
347
|
+
if (!codeResult?.code) return {code: undefined, type: S};
|
|
348
|
+
const finalCode = this.isOptional() ? `if (${comp.getChildVλl()} !== undefined) {${codeResult.code}}` : codeResult.code;
|
|
349
|
+
return {code: finalCode, type: codeResult.type};
|
|
350
|
+
}
|
|
351
|
+
visitToBinary(comp: JitFnCompiler): JitCode {
|
|
352
|
+
const child = this.getJitChild(comp);
|
|
353
|
+
const code = comp.compileToBinary(child, S);
|
|
354
|
+
if (!code?.code) return {code: undefined, type: S};
|
|
355
|
+
return this.isOptional()
|
|
356
|
+
? {code: `(${comp.getChildVλl()} !== undefined ? ${code.code} : utl.writeBinaryNull())`, type: S}
|
|
357
|
+
: code;
|
|
358
|
+
}
|
|
359
|
+
visitFromBinary(comp: JitFnCompiler): JitCode {
|
|
360
|
+
const child = this.getJitChild(comp);
|
|
361
|
+
const code = comp.compileFromBinary(child, S);
|
|
362
|
+
if (!code?.code) return {code: undefined, type: S};
|
|
363
|
+
return code;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ########## Load Composable Functions ##########
|