@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,118 @@
|
|
|
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 {FunctionRunType} from '../../../nodes/function/function.ts';
|
|
10
|
+
import type {DataViewDeserializer, DataViewSerializer, StrictArrayBuffer} from '@mionjs/core';
|
|
11
|
+
import type {InterfaceRunType} from '../../../nodes/collection/interface.ts';
|
|
12
|
+
import type {RunType} from '../../../types.ts';
|
|
13
|
+
import {createDataViewDeserializer, createDataViewSerializer, setSerializationOptions, getENV} from '@mionjs/core';
|
|
14
|
+
import {afterAll, expect} from 'vitest';
|
|
15
|
+
|
|
16
|
+
const DEBUG = getENV('DEBUG_JIT') === 'print';
|
|
17
|
+
/** maps a binary serializer to json serializer */
|
|
18
|
+
const toJsonSerializers: Map<(v: any) => any, (v: any) => string> = new Map();
|
|
19
|
+
|
|
20
|
+
setSerializationOptions({bufferSize: 1024});
|
|
21
|
+
export const serContext: DataViewSerializer = createDataViewSerializer('test');
|
|
22
|
+
export const desContext: DataViewDeserializer = createDataViewDeserializer('test', new ArrayBuffer(0));
|
|
23
|
+
|
|
24
|
+
const SERIALIZE_FN = JitFunctions.toBinary;
|
|
25
|
+
const DESERIALIZE_FN = JitFunctions.fromBinary;
|
|
26
|
+
|
|
27
|
+
export function createSerializationFns(rt: RunType) {
|
|
28
|
+
const toBinary = rt.createJitFunction(SERIALIZE_FN);
|
|
29
|
+
const fromBinary = rt.createJitFunction(DESERIALIZE_FN);
|
|
30
|
+
const serialize = (v: any) => (toBinary(v, serContext), serContext.getBuffer());
|
|
31
|
+
const deserialize = (data: StrictArrayBuffer) => (desContext.setBuffer(data), fromBinary(undefined, desContext));
|
|
32
|
+
if (DEBUG) {
|
|
33
|
+
const toJson = rt.createJitFunction(JitFunctions.prepareForJson);
|
|
34
|
+
const stringify = (v: any) => JSON.stringify(toJson(v));
|
|
35
|
+
toJsonSerializers.set(serialize, stringify);
|
|
36
|
+
}
|
|
37
|
+
return {serialize, deserialize};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createSerializationParamsFn(rt: FunctionRunType, sliceStart?: number) {
|
|
41
|
+
const params = typeof sliceStart === 'number' ? {paramsSlice: {start: sliceStart}} : undefined;
|
|
42
|
+
const toBinary = rt.createJitParamsFunction(SERIALIZE_FN, params);
|
|
43
|
+
const fromBinary = rt.createJitParamsFunction(DESERIALIZE_FN, params);
|
|
44
|
+
const serialize = (v: any) => (toBinary(v, serContext), serContext.getBuffer());
|
|
45
|
+
const deserialize = (data: StrictArrayBuffer) => (desContext.setBuffer(data), fromBinary(undefined, desContext));
|
|
46
|
+
if (DEBUG) {
|
|
47
|
+
const toJson = rt.createJitParamsFunction(JitFunctions.prepareForJson, params);
|
|
48
|
+
const stringify = (v: any) => JSON.stringify(toJson(v));
|
|
49
|
+
toJsonSerializers.set(serialize, stringify);
|
|
50
|
+
}
|
|
51
|
+
return {serialize, deserialize};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createSerializationReturnFn(rt: FunctionRunType) {
|
|
55
|
+
const toBinary = rt.createJitReturnFunction(SERIALIZE_FN);
|
|
56
|
+
const fromBinary = rt.createJitReturnFunction(DESERIALIZE_FN);
|
|
57
|
+
const serialize = (v: any) => (toBinary(v, serContext), serContext.getBuffer());
|
|
58
|
+
const deserialize = (data: StrictArrayBuffer) => (desContext.setBuffer(data), fromBinary(undefined, desContext));
|
|
59
|
+
if (DEBUG) {
|
|
60
|
+
const toJson = rt.createJitReturnFunction(JitFunctions.prepareForJson);
|
|
61
|
+
const stringify = (v: any) => JSON.stringify(toJson(v));
|
|
62
|
+
toJsonSerializers.set(serialize, stringify);
|
|
63
|
+
}
|
|
64
|
+
return {serialize, deserialize};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createSerializationCallSignatureParamsFn(rt: InterfaceRunType) {
|
|
68
|
+
const callSignature = rt.getCallSignature()!;
|
|
69
|
+
const toBinary = callSignature.createJitParamsFunction(SERIALIZE_FN);
|
|
70
|
+
const fromBinary = callSignature.createJitParamsFunction(DESERIALIZE_FN);
|
|
71
|
+
const serialize = (v: any) => (toBinary(v, serContext), serContext.getBuffer());
|
|
72
|
+
const deserialize = (data: StrictArrayBuffer) => (desContext.setBuffer(data), fromBinary(undefined, desContext));
|
|
73
|
+
if (DEBUG) {
|
|
74
|
+
const toJson = callSignature.createJitParamsFunction(JitFunctions.prepareForJson);
|
|
75
|
+
const stringify = (v: any) => JSON.stringify(toJson(v));
|
|
76
|
+
toJsonSerializers.set(serialize, stringify);
|
|
77
|
+
}
|
|
78
|
+
return {serialize, deserialize};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createSerializationCallSignatureReturnFn(rt: InterfaceRunType) {
|
|
82
|
+
const callSignature = rt.getCallSignature()!;
|
|
83
|
+
const toBinary = callSignature.createJitReturnFunction(SERIALIZE_FN);
|
|
84
|
+
const fromBinary = callSignature.createJitReturnFunction(DESERIALIZE_FN);
|
|
85
|
+
const serialize = (v: any) => (toBinary(v, serContext), serContext.getBuffer());
|
|
86
|
+
const deserialize = (data: StrictArrayBuffer) => (desContext.setBuffer(data), fromBinary(undefined, desContext));
|
|
87
|
+
if (DEBUG) {
|
|
88
|
+
const toJson = callSignature.createJitReturnFunction(JitFunctions.prepareForJson);
|
|
89
|
+
const stringify = (v: any) => JSON.stringify(toJson(v));
|
|
90
|
+
toJsonSerializers.set(serialize, stringify);
|
|
91
|
+
}
|
|
92
|
+
return {serialize, deserialize};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const sizesEntries: any[] = [];
|
|
96
|
+
const valuesEntries: any[] = [];
|
|
97
|
+
|
|
98
|
+
export function roundTrip(serialize: (v: any) => StrictArrayBuffer, deserialize: (v: StrictArrayBuffer) => any, value: any) {
|
|
99
|
+
serContext.reset();
|
|
100
|
+
const serialized = serialize(value);
|
|
101
|
+
const deserialized = deserialize(serialized);
|
|
102
|
+
if (DEBUG) {
|
|
103
|
+
const stringify = toJsonSerializers.get(serialize)!;
|
|
104
|
+
let json: number | string = '';
|
|
105
|
+
// eslint-disable-next-line
|
|
106
|
+
try { json = new Blob([stringify(value)]).size; } catch (e) { json = '-'; } // prettier-ignore
|
|
107
|
+
const sizes = {name: expect.getState().currentTestName, json, binary: serialized.byteLength};
|
|
108
|
+
sizesEntries.push(sizes);
|
|
109
|
+
valuesEntries.push({value, deserialized});
|
|
110
|
+
}
|
|
111
|
+
const result = {serialized, deserialized};
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
afterAll(() => {
|
|
116
|
+
if (sizesEntries.length) console.table(sizesEntries);
|
|
117
|
+
if (valuesEntries.length) console.table(valuesEntries);
|
|
118
|
+
});
|
|
@@ -0,0 +1,492 @@
|
|
|
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 {ReflectionKind} from '@deepkit/type';
|
|
9
|
+
import {getJitUtils} from '@mionjs/core';
|
|
10
|
+
import {ReflectionSubKind} from '../../constants.kind.ts';
|
|
11
|
+
import {childIsExpression, createIfElseFn, isSafePropName, toLiteral} from '../../lib/utils.ts';
|
|
12
|
+
import {jitBinaryDeserializerArgs, JitFunctions} from '../../constants.functions.ts';
|
|
13
|
+
import {MAX_UNION_ITEMS} from '../../constants.ts';
|
|
14
|
+
import type {JitCode} from '../../types.ts';
|
|
15
|
+
import type {BaseRunType} from '../../lib/baseRunTypes.ts';
|
|
16
|
+
import {type BaseFnCompiler} from '../../lib/jitFnCompiler.ts';
|
|
17
|
+
import type {LiteralRunType} from '../../nodes/atomic/literal.ts';
|
|
18
|
+
import type {ArrayRunType} from '../../nodes/member/array.ts';
|
|
19
|
+
import type {PropertyRunType} from '../../nodes/member/property.ts';
|
|
20
|
+
import type {InterfaceRunType} from '../../nodes/collection/interface.ts';
|
|
21
|
+
import type {IndexSignatureRunType} from '../../nodes/member/indexProperty.ts';
|
|
22
|
+
import type {ClassRunType} from '../../nodes/collection/class.ts';
|
|
23
|
+
import type {TupleRunType} from '../../nodes/collection/tuple.ts';
|
|
24
|
+
import type {ParameterRunType} from '../../nodes/member/param.ts';
|
|
25
|
+
import type {RestParamsRunType} from '../../nodes/member/restParams.ts';
|
|
26
|
+
import type {UnionRunType} from '../../nodes/collection/union.ts';
|
|
27
|
+
import type {IterableRunType} from '../../nodes/native/Iterable.ts';
|
|
28
|
+
import type {MapRunType} from '../../nodes/native/map.ts';
|
|
29
|
+
|
|
30
|
+
type BinaryCompiler = BaseFnCompiler<typeof jitBinaryDeserializerArgs, typeof JitFunctions.fromBinary.id>;
|
|
31
|
+
|
|
32
|
+
const fnID = JitFunctions.fromBinary.id;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Main Binary deserialization compiler function
|
|
36
|
+
* Generates JIT code to deserialize Binary data to JavaScript values
|
|
37
|
+
*/
|
|
38
|
+
export function emitFromBinary(runType: BaseRunType, comp: BinaryCompiler): JitCode {
|
|
39
|
+
const src = runType.src;
|
|
40
|
+
const kind = src.kind;
|
|
41
|
+
const dεs = comp.args.dεs;
|
|
42
|
+
|
|
43
|
+
// hack is used in some case to increase the index passing an extra argument to view.get methods
|
|
44
|
+
// ie: view.getUint32(index, littleEndian, index += 4);
|
|
45
|
+
// getUint32 only accepts 2 arguments, but we use the 3rd one to increase the index on a single statement so code can be used as an expression
|
|
46
|
+
|
|
47
|
+
switch (kind) {
|
|
48
|
+
// ###################### ATOMIC TYPES ######################
|
|
49
|
+
case ReflectionKind.unknown:
|
|
50
|
+
case ReflectionKind.any: {
|
|
51
|
+
// any is deserialized from json string
|
|
52
|
+
return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};
|
|
53
|
+
}
|
|
54
|
+
case ReflectionKind.null:
|
|
55
|
+
return {code: `(${dεs}.index++, null)`, type: 'E'};
|
|
56
|
+
case ReflectionKind.boolean:
|
|
57
|
+
return {code: `${dεs}.view.getUint8(${dεs}.index++) === 1`, type: 'E'};
|
|
58
|
+
case ReflectionKind.number: {
|
|
59
|
+
return {code: `${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8))`, type: 'E'};
|
|
60
|
+
}
|
|
61
|
+
case ReflectionKind.string: {
|
|
62
|
+
return {code: `${dεs}.desString()`, type: 'E'};
|
|
63
|
+
}
|
|
64
|
+
case ReflectionKind.bigint: {
|
|
65
|
+
return {code: `BigInt(${dεs}.desString(true))`, type: 'E'};
|
|
66
|
+
}
|
|
67
|
+
case ReflectionKind.undefined:
|
|
68
|
+
case ReflectionKind.void:
|
|
69
|
+
return {code: `(${dεs}.index++, undefined)`, type: 'E'};
|
|
70
|
+
case ReflectionKind.symbol: {
|
|
71
|
+
return {code: `Symbol(${dεs}.desString() || undefined)`, type: 'E'};
|
|
72
|
+
}
|
|
73
|
+
case ReflectionKind.regexp: {
|
|
74
|
+
return {code: `new RegExp(${dεs}.desString(), ${dεs}.desString())`, type: 'E'};
|
|
75
|
+
}
|
|
76
|
+
case ReflectionKind.object:
|
|
77
|
+
// similar to any, this is deserialized as json string
|
|
78
|
+
return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};
|
|
79
|
+
case ReflectionKind.enum: {
|
|
80
|
+
return {code: `${dεs}.desEnum()`, type: 'E'};
|
|
81
|
+
}
|
|
82
|
+
case ReflectionKind.enumMember:
|
|
83
|
+
throw new Error('Binary deserialization not supported for enum member types');
|
|
84
|
+
case ReflectionKind.never:
|
|
85
|
+
throw new Error('Never type cannot be deserialized from Binary');
|
|
86
|
+
case ReflectionKind.templateLiteral:
|
|
87
|
+
throw new Error('Template literals are not supported in Binary deserialization');
|
|
88
|
+
case ReflectionKind.literal: {
|
|
89
|
+
if (comp.opts.noLiterals) {
|
|
90
|
+
const lit = (runType as LiteralRunType).src.literal;
|
|
91
|
+
if (lit instanceof RegExp) return emitFromBinaryAs(runType, comp, ReflectionKind.regexp);
|
|
92
|
+
switch (typeof lit) {
|
|
93
|
+
case 'string':
|
|
94
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.string);
|
|
95
|
+
case 'number':
|
|
96
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.number);
|
|
97
|
+
case 'boolean':
|
|
98
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.boolean);
|
|
99
|
+
case 'bigint':
|
|
100
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.bigint);
|
|
101
|
+
case 'symbol':
|
|
102
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.symbol);
|
|
103
|
+
default:
|
|
104
|
+
throw new Error(`Unsupported literal type ${typeof lit}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {code: toLiteral((runType as LiteralRunType).src.literal), type: 'E'};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ###################### MEMBER RUNTYPES ######################
|
|
111
|
+
// Types that represent members of collections or other structures
|
|
112
|
+
case ReflectionKind.rest: // rest params are deserialized as array but start at rest item index
|
|
113
|
+
case ReflectionKind.array: {
|
|
114
|
+
const rt = runType as ArrayRunType | RestParamsRunType;
|
|
115
|
+
rt.checkNonSkipTypes(comp);
|
|
116
|
+
const child = rt.getMemberType()!;
|
|
117
|
+
const childCode = comp.compile(child, 'S', fnID);
|
|
118
|
+
if (!childCode?.code) throw new Error(`Do not know how to deserialize Array<${child.getTypeName()}> from Binary.`);
|
|
119
|
+
const isRest = rt.src.kind === ReflectionKind.rest;
|
|
120
|
+
const index = rt.getChildVarName(comp);
|
|
121
|
+
const isExpression = childIsExpression(childCode, child);
|
|
122
|
+
const code = isExpression ? `${comp.getChildVλl()} = ${childCode.code};` : childCode.code;
|
|
123
|
+
// deserialized from [length, items...]
|
|
124
|
+
const lengthVal = comp.getLocalVarName('arrL', rt);
|
|
125
|
+
const arrayInit = isRest ? '' : `${comp.vλl} = new Array(${lengthVal})`; // res array already initialized in parent
|
|
126
|
+
return {
|
|
127
|
+
code: `
|
|
128
|
+
const ${lengthVal} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${arrayInit};
|
|
129
|
+
for (let ${index} = ${rt.startIndex(comp)}; ${index} < ${lengthVal}; ${index}++) {${code}}
|
|
130
|
+
`,
|
|
131
|
+
type: 'S',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case ReflectionKind.indexSignature: {
|
|
136
|
+
const rt = runType as IndexSignatureRunType;
|
|
137
|
+
const indexKind = (rt.src as any).index?.kind;
|
|
138
|
+
const memberCode = comp.compile(rt.getJitChild(comp), 'S', fnID);
|
|
139
|
+
if (!memberCode?.code) return {code: undefined, type: 'E'};
|
|
140
|
+
|
|
141
|
+
const prop = rt.getChildVarName(comp);
|
|
142
|
+
const countVar = comp.getLocalVarName('cnt', rt);
|
|
143
|
+
const indexVar = comp.getLocalVarName('propI', rt);
|
|
144
|
+
|
|
145
|
+
// Deserialize key based on index type
|
|
146
|
+
let keyDeserializationCode: string;
|
|
147
|
+
if (indexKind === ReflectionKind.number) {
|
|
148
|
+
// For number indices, deserialize as uint32
|
|
149
|
+
keyDeserializationCode = `const ${prop} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4;`;
|
|
150
|
+
} else {
|
|
151
|
+
// For string indices, deserialize as string with prototype pollution protection
|
|
152
|
+
keyDeserializationCode = `const ${prop} = ${dεs}.desSafePropName();`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const memberInit = memberCode.type === 'E' ? `${comp.vλl}[${prop}] = ${memberCode.code};` : memberCode.code;
|
|
156
|
+
const deserializeCode = `for (let ${indexVar} = 0; ${indexVar} < ${countVar}; ${indexVar}++) {${keyDeserializationCode}${memberInit}}`;
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
code: `const ${countVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${comp.vλl} = {}; ${deserializeCode}`,
|
|
160
|
+
type: 'S',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
case ReflectionKind.function:
|
|
165
|
+
case ReflectionKind.method:
|
|
166
|
+
case ReflectionKind.methodSignature:
|
|
167
|
+
case ReflectionKind.callSignature:
|
|
168
|
+
if (runType.src.subKind === ReflectionSubKind.params) {
|
|
169
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.tuple);
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error(
|
|
172
|
+
'Binary deserialization not supported for functions, call compileParams or compileReturn instead.'
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
case ReflectionKind.parameter: {
|
|
177
|
+
const rt = runType as ParameterRunType;
|
|
178
|
+
switch (src.subKind) {
|
|
179
|
+
case ReflectionSubKind.mapKey:
|
|
180
|
+
case ReflectionSubKind.mapValue:
|
|
181
|
+
case ReflectionSubKind.setItem: {
|
|
182
|
+
const child = rt.getJitChild(comp);
|
|
183
|
+
const childJit = comp.compile(child, 'S', fnID);
|
|
184
|
+
if (!childJit?.code || !child)
|
|
185
|
+
throw new Error(`Do not know how to deserialize ${rt.getTypeName()} from Binary.`);
|
|
186
|
+
const parent = rt.getParent()!;
|
|
187
|
+
const parentVλl = parent.getCustomVλl(comp)?.vλl || comp.vλl;
|
|
188
|
+
const vλl = rt.getCustomVλl(comp)?.vλl;
|
|
189
|
+
const isExpression = childIsExpression(childJit, child);
|
|
190
|
+
const code = isExpression ? `const ${vλl} = ${childJit.code};` : childJit.code || '';
|
|
191
|
+
let setOperation = '';
|
|
192
|
+
switch (rt.src.subKind) {
|
|
193
|
+
case ReflectionSubKind.mapKey:
|
|
194
|
+
break; // we set map item once we have the key and value
|
|
195
|
+
case ReflectionSubKind.mapValue: {
|
|
196
|
+
const mapKey = (parent as MapRunType).getMapKeyVλl(comp); // not the best solution but works
|
|
197
|
+
setOperation = `${parentVλl}.set(${mapKey}, ${vλl})`;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case ReflectionSubKind.setItem:
|
|
201
|
+
setOperation = `${parentVλl}.add(${vλl})`;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
return {code: `${code}; ${setOperation};`, type: 'S'};
|
|
205
|
+
}
|
|
206
|
+
default:
|
|
207
|
+
return emitFromBinaryAs(runType, comp, ReflectionKind.tupleMember);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
case ReflectionKind.property:
|
|
212
|
+
case ReflectionKind.propertySignature: {
|
|
213
|
+
const rt = runType as PropertyRunType;
|
|
214
|
+
const parent = rt.getParent() as InterfaceRunType;
|
|
215
|
+
const child = rt.getJitChild(comp)!;
|
|
216
|
+
const childJit = comp.compile(child, 'S', fnID);
|
|
217
|
+
if (rt.isOptional()) {
|
|
218
|
+
const {bitMIndexVar, bitIndex} = getOptionalBitmapItems(parent, comp, 0, rt.optionalIndex, false);
|
|
219
|
+
const initCode = childJit.type === 'E' ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code;
|
|
220
|
+
return {
|
|
221
|
+
code: `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`,
|
|
222
|
+
type: 'S',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// block or statements code are initialized as obj.a = deserializeA; obj.b = deserializeB; after initial object has been created
|
|
226
|
+
const isExpression = childIsExpression(childJit, child);
|
|
227
|
+
if (!isExpression) {
|
|
228
|
+
return childJit; // block statements already include variable assignment
|
|
229
|
+
}
|
|
230
|
+
// required props that are simple expressions code are part of an object constructor {a: deserializeA, b: deserializeB, c: deserializeC}
|
|
231
|
+
const propName = getPropName(rt, comp, true);
|
|
232
|
+
return {code: `${propName}:${childJit?.code}`, type: 'E'};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
case ReflectionKind.tupleMember: {
|
|
236
|
+
const rt = runType as ParameterRunType;
|
|
237
|
+
const childJit = comp.compile(rt.getJitChild(comp), 'S', fnID);
|
|
238
|
+
const nullJIt = emitFromBinaryAs(rt, comp, ReflectionKind.undefined);
|
|
239
|
+
const itemJit = childJit?.code ? childJit : nullJIt; // if child is not serializable, we serialize null as need to fill the space in the tuple
|
|
240
|
+
const initCode = itemJit.type === 'E' ? `${comp.getChildVλl()} = ${itemJit.code}` : itemJit.code;
|
|
241
|
+
if (rt.isRest()) return itemJit;
|
|
242
|
+
// Optional handling uses bitmap set at tuple level
|
|
243
|
+
const optionalIndex = (rt as any).optionalIndex;
|
|
244
|
+
const bitMIndexVar = (rt as any)._bitmapVar;
|
|
245
|
+
const isFnParam = (rt as any)._isFnParam;
|
|
246
|
+
// Treat as optional if either isOptional() is true OR it's a function param (all fn params are optional in binary)
|
|
247
|
+
const isOptional = rt.isOptional() || isFnParam;
|
|
248
|
+
if (isOptional && optionalIndex !== undefined && bitMIndexVar) {
|
|
249
|
+
const bitIndex = optionalIndex & 7; // equivalent to optionalIndex % 8
|
|
250
|
+
const code = `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`;
|
|
251
|
+
return {code, type: 'S'};
|
|
252
|
+
}
|
|
253
|
+
return {code: initCode, type: 'S'};
|
|
254
|
+
}
|
|
255
|
+
case ReflectionKind.promise:
|
|
256
|
+
throw new Error('Jit compilation disabled for Non Serializable types.');
|
|
257
|
+
|
|
258
|
+
// ###################### COLLECTION RUNTYPES ######################
|
|
259
|
+
// Types that contain other types as members
|
|
260
|
+
case ReflectionKind.objectLiteral:
|
|
261
|
+
case ReflectionKind.intersection: {
|
|
262
|
+
const rt = runType as InterfaceRunType;
|
|
263
|
+
if (rt.isCallable()) return comp.compile(rt.getCallSignature(), 'S', fnID);
|
|
264
|
+
if (runType.src.subKind === ReflectionSubKind.nonSerializable) {
|
|
265
|
+
throw new Error('Binary deserialization is disabled for Non Serializable types');
|
|
266
|
+
} else {
|
|
267
|
+
const {required, optional, indexSignatures} = rt.splitJitSplitChildren(comp);
|
|
268
|
+
if (indexSignatures.length) {
|
|
269
|
+
return comp.compile(indexSignatures[0], 'S', fnID); // index signature code already contains the loop
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// required props that are simple expressions are restored as: '{a: deserializeA, b: deserializeB, c: deserializeC};
|
|
273
|
+
// and are serialized/deserialised in the same order they are declared in the type
|
|
274
|
+
const requiredItemsJit = required.map((prop) => comp.compile(prop, 'S', fnID));
|
|
275
|
+
const expressionItemsJit = requiredItemsJit
|
|
276
|
+
.filter((childJit, i) => childIsExpression(childJit, required[i]))
|
|
277
|
+
.map((prop) => prop.code)
|
|
278
|
+
.filter(Boolean);
|
|
279
|
+
const statementItemsCode = requiredItemsJit
|
|
280
|
+
.filter(Boolean)
|
|
281
|
+
.filter((childJit, i) => !childIsExpression(childJit, required[i]))
|
|
282
|
+
.map((prop) => prop.code);
|
|
283
|
+
const expressionsPropsCode = expressionItemsJit.join(',');
|
|
284
|
+
const requiredPropsCode = statementItemsCode.join(';');
|
|
285
|
+
|
|
286
|
+
// optional props are initialized as obj.a = deserializeA; obj.b = deserializeB; obj.c = deserializeC;
|
|
287
|
+
// bitmap is used to determine which optional props are present
|
|
288
|
+
// header format: [bitmap, optional props]
|
|
289
|
+
let optionalPropsCode = '';
|
|
290
|
+
if (optional.length) {
|
|
291
|
+
// optional properties are restored using a loop
|
|
292
|
+
const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, false);
|
|
293
|
+
const propsCode = optional
|
|
294
|
+
.map((prop, i) => {
|
|
295
|
+
prop.optionalIndex = i;
|
|
296
|
+
const modIndex = i + 1;
|
|
297
|
+
const shouldIncreaseBufferIndex = modIndex % 8 === 0;
|
|
298
|
+
const propCode = comp.compile(prop, 'S', fnID).code;
|
|
299
|
+
if (!shouldIncreaseBufferIndex) return propCode;
|
|
300
|
+
// every 8 props we need to increase the bitmap index
|
|
301
|
+
return `${propCode} ${bitMIndexVar}++; `;
|
|
302
|
+
})
|
|
303
|
+
.filter(Boolean)
|
|
304
|
+
.join('');
|
|
305
|
+
const sep = requiredPropsCode ? ';' : '';
|
|
306
|
+
optionalPropsCode = `${sep}\n${bitMapInit}\n${propsCode}`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const canBeExpression = !requiredPropsCode && !optionalPropsCode;
|
|
310
|
+
if (canBeExpression) return {code: `{${expressionsPropsCode}}`, type: 'E'};
|
|
311
|
+
return {code: `${comp.vλl} = {${expressionsPropsCode}}\n${requiredPropsCode}${optionalPropsCode}`, type: 'S'};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
case ReflectionKind.class:
|
|
315
|
+
switch (runType.src.subKind) {
|
|
316
|
+
case ReflectionSubKind.date:
|
|
317
|
+
return {code: `new Date(${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8)))`, type: 'E'};
|
|
318
|
+
case ReflectionSubKind.map:
|
|
319
|
+
case ReflectionSubKind.set: {
|
|
320
|
+
const rt = runType as IterableRunType;
|
|
321
|
+
const children = rt.getJitChildren(comp);
|
|
322
|
+
const vλl = rt.getCustomVλl(comp)?.vλl || comp.vλl;
|
|
323
|
+
const initCode = `const ${vλl} = new ${rt.constructorName}()`;
|
|
324
|
+
if (!children.length) return {code: `new ${rt.constructorName}()`, type: 'E'};
|
|
325
|
+
const childrenCode = children
|
|
326
|
+
.map((c) => comp.compile(c, 'S', fnID).code)
|
|
327
|
+
.filter(Boolean)
|
|
328
|
+
.join(';');
|
|
329
|
+
if (!childrenCode) return {code: initCode, type: 'E'};
|
|
330
|
+
const index = comp.getLocalVarName('itI', rt);
|
|
331
|
+
const lengthVar = comp.getLocalVarName('itL', rt);
|
|
332
|
+
const readLength = `const ${lengthVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4`;
|
|
333
|
+
return {
|
|
334
|
+
code: `${initCode}; ${readLength}; for (let ${index} = 0; ${index} < ${lengthVar}; ${index}++) {${childrenCode}} ${comp.vλl} = ${vλl};`,
|
|
335
|
+
type: 'S',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
case ReflectionSubKind.nonSerializable:
|
|
339
|
+
throw new Error('Binary deserialization disabled for Non Serializable types');
|
|
340
|
+
default: {
|
|
341
|
+
const rt = runType as ClassRunType;
|
|
342
|
+
if (rt.isCallable()) {
|
|
343
|
+
const callSignature = rt.getCallSignature();
|
|
344
|
+
if (callSignature) return comp.compile(callSignature, 'S', fnID);
|
|
345
|
+
}
|
|
346
|
+
const originalKind = rt.src.kind;
|
|
347
|
+
(runType.src as any).kind = ReflectionKind.objectLiteral;
|
|
348
|
+
const plainObjCode = emitFromBinary(rt, comp);
|
|
349
|
+
(runType.src as any).kind = originalKind;
|
|
350
|
+
const desFnVarName = comp.getLocalVarName('desFn', rt);
|
|
351
|
+
const desFnInit = `let ${desFnVarName} = utl.${getJitUtils().getDeserializeFn.name}(${toLiteral(rt.getClassName())})`;
|
|
352
|
+
const desFnCode = `if (${desFnVarName}) {${comp.vλl} = ${desFnVarName}(${comp.vλl})}`;
|
|
353
|
+
const desClassCode = `else if (${desFnVarName} = utl.${getJitUtils().getSerializeClass.name}(${toLiteral(rt.getClassName())})) {${comp.vλl} = new ${desFnVarName}(${comp.vλl})}`;
|
|
354
|
+
const initCode = plainObjCode.type === 'E' ? `${comp.vλl} = ${plainObjCode.code}` : plainObjCode.code;
|
|
355
|
+
return {code: `${initCode};${desFnInit};${desFnCode} ${desClassCode}`, type: 'S'};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
|
|
360
|
+
case ReflectionKind.infer:
|
|
361
|
+
throw new Error('Infer is not supported in Binary deserialization');
|
|
362
|
+
|
|
363
|
+
case ReflectionKind.tuple: {
|
|
364
|
+
const rt = runType as TupleRunType;
|
|
365
|
+
const skip = rt.skipJit(comp);
|
|
366
|
+
if (skip) return {code: undefined, type: 'S'};
|
|
367
|
+
const params = rt.getParamRunTypes(comp);
|
|
368
|
+
|
|
369
|
+
// For function params, all params are treated as optional in binary serialization
|
|
370
|
+
// This allows sending null/undefined values over the wire even if the type is not optional
|
|
371
|
+
const isFnParams = runType.src.subKind === ReflectionSubKind.params;
|
|
372
|
+
|
|
373
|
+
// For function params, all params are optional so we can't use fixed size
|
|
374
|
+
const hasFixedSize = !isFnParams && params.every((p) => !p.isOptional() && !p.isRest());
|
|
375
|
+
const initTuple = hasFixedSize ? `${comp.vλl} = new Array(${params.length});` : `${comp.vλl} = [];`;
|
|
376
|
+
if (params.length === 0) return {code: initTuple, type: 'S'};
|
|
377
|
+
|
|
378
|
+
// Split params into required, optional, and rest
|
|
379
|
+
// For function params, all non-rest params are treated as optional
|
|
380
|
+
const required = isFnParams ? [] : params.filter((p) => !p.isOptional() && !p.isRest());
|
|
381
|
+
const optional = isFnParams ? params.filter((p) => !p.isRest()) : params.filter((p) => p.isOptional() && !p.isRest());
|
|
382
|
+
const rest = params.filter((p) => p.isRest());
|
|
383
|
+
|
|
384
|
+
// Deserialize required params first
|
|
385
|
+
const requiredCode = required.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');
|
|
386
|
+
|
|
387
|
+
// Deserialize optional params with bitmap (groups of 8)
|
|
388
|
+
let optionalCode = '';
|
|
389
|
+
if (optional.length) {
|
|
390
|
+
const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, true);
|
|
391
|
+
const optionalParamsCode = optional
|
|
392
|
+
.map((p, i) => {
|
|
393
|
+
(p as any).optionalIndex = i; // set optionalIndex for use in tupleMember case
|
|
394
|
+
(p as any)._bitmapVar = bitMIndexVar; // pass bitmap variable name to tupleMember case
|
|
395
|
+
(p as any)._isFnParam = isFnParams; // flag to indicate this is a function param
|
|
396
|
+
const paramCode = comp.compile(p, 'S', fnID).code || '';
|
|
397
|
+
const modIndex = i + 1;
|
|
398
|
+
const shouldIncreaseBufferIndex = modIndex % 8 === 0 && modIndex < optional.length;
|
|
399
|
+
const increaseIndex = shouldIncreaseBufferIndex ? `${bitMIndexVar}++;` : '';
|
|
400
|
+
return `${paramCode} ${increaseIndex}`;
|
|
401
|
+
})
|
|
402
|
+
.join('');
|
|
403
|
+
optionalCode = `${bitMapInit}\n${optionalParamsCode}`;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Deserialize rest params (handled as array by the rest param itself)
|
|
407
|
+
const restCode = rest.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');
|
|
408
|
+
|
|
409
|
+
const allCode = [requiredCode, optionalCode, restCode].filter(Boolean).join(';');
|
|
410
|
+
return {code: `${initTuple}${allCode}`, type: 'S'};
|
|
411
|
+
}
|
|
412
|
+
case ReflectionKind.typeParameter:
|
|
413
|
+
throw new Error('Type parameter not implemented in Binary deserialization');
|
|
414
|
+
|
|
415
|
+
case ReflectionKind.union: {
|
|
416
|
+
const rt = runType as UnionRunType;
|
|
417
|
+
rt.checkAllowedChildren(comp);
|
|
418
|
+
const decVar = comp.getLocalVarName('dec', rt);
|
|
419
|
+
const errVarName = comp.getLocalVarName('uErr', rt);
|
|
420
|
+
comp.setContextItem(errVarName, `const ${errVarName} = "Can not binary decode union: invalid union index"`);
|
|
421
|
+
const children = rt.getJitChildren(comp);
|
|
422
|
+
if (children.length > MAX_UNION_ITEMS) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Binary deserialization not supported for Union with more than ${MAX_UNION_ITEMS} items.` +
|
|
425
|
+
` Found ${children.length} in ${rt.getUnionTypeNames()}`
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
const maxIndex = children.length - 1;
|
|
429
|
+
const isUint16 = maxIndex > 255;
|
|
430
|
+
const readIndex = isUint16
|
|
431
|
+
? `const ${decVar} = ${dεs}.view.getUint16(${dεs}.index, 1); ${dεs}.index += 2;`
|
|
432
|
+
: `const ${decVar} = ${dεs}.view.getUint8(${dεs}.index++);`;
|
|
433
|
+
const ifElse = createIfElseFn();
|
|
434
|
+
const itemsCode = children
|
|
435
|
+
.map((unionItem) => {
|
|
436
|
+
const childJit = comp.compile(unionItem, 'S', fnID);
|
|
437
|
+
const isExpression = childIsExpression(childJit, unionItem);
|
|
438
|
+
const code =
|
|
439
|
+
isExpression && childJit.code && childJit.code !== comp.vλl
|
|
440
|
+
? `${comp.vλl} = ${childJit.code}`
|
|
441
|
+
: childJit.code || '';
|
|
442
|
+
const index = rt.getUnionItemIndex(comp, unionItem);
|
|
443
|
+
return `${ifElse()} (${decVar} === ${index}) {${code || '/*noop*/'}}`;
|
|
444
|
+
})
|
|
445
|
+
.filter(Boolean);
|
|
446
|
+
const childrenCode = itemsCode.join('');
|
|
447
|
+
const failCode = childrenCode ? `else {throw new Error(${errVarName})}` : '';
|
|
448
|
+
const code = `
|
|
449
|
+
${readIndex}
|
|
450
|
+
${childrenCode}
|
|
451
|
+
${failCode}
|
|
452
|
+
`;
|
|
453
|
+
return {code, type: 'S'};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
default:
|
|
457
|
+
throw new Error(`Binary deserialization not supported for ${ReflectionKind[kind]} types`);
|
|
458
|
+
}
|
|
459
|
+
throw new Error(`Do not know how to deserialize ${runType.getTypeName()} from Binary.`);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function getPropName(rt: PropertyRunType, comp: BinaryCompiler, isObjectConstructor: boolean): string | number {
|
|
463
|
+
const isSafe = isSafePropName(rt.src.name);
|
|
464
|
+
if (isObjectConstructor) return isSafe ? rt.getChildVarName(comp) : rt.getChildLiteral(comp);
|
|
465
|
+
return isSafe ? `.${rt.getChildVarName(comp)}` : `[${rt.getChildLiteral(comp)}]`;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** Generates bitmap reading code for optional properties/params. Uses 1 bit per optional item (8 items per byte). */
|
|
469
|
+
function getOptionalBitmapItems(
|
|
470
|
+
rt: InterfaceRunType | TupleRunType,
|
|
471
|
+
comp: BinaryCompiler,
|
|
472
|
+
optionalLength = 0,
|
|
473
|
+
currentIndex = 0,
|
|
474
|
+
isTuple = false
|
|
475
|
+
) {
|
|
476
|
+
const dεs = comp.args.dεs;
|
|
477
|
+
const prefix = isTuple ? 't' : '';
|
|
478
|
+
const bitMIndexVar = comp.getLocalVarName(`${prefix}bimI`, rt); // index of the bitmap
|
|
479
|
+
const bitmapLength = Math.ceil(optionalLength / 8);
|
|
480
|
+
const bitIndex = `${currentIndex} & 7`; // equivalent to index % 8
|
|
481
|
+
// bitmap for present optional items
|
|
482
|
+
const bitMapInit = `${bitmapLength > 1 ? 'let ' : 'const'} ${bitMIndexVar} = ${dεs}.index; ${dεs}.index += ${bitmapLength};`;
|
|
483
|
+
return {bitMIndexVar, bitmapLength, bitIndex, bitMapInit};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function emitFromBinaryAs(rt: BaseRunType, comp: BinaryCompiler, kind: ReflectionKind): JitCode {
|
|
487
|
+
const originalKind = rt.src.kind;
|
|
488
|
+
(rt.src as any).kind = kind;
|
|
489
|
+
const result = emitFromBinary(rt, comp);
|
|
490
|
+
(rt.src as any).kind = originalKind;
|
|
491
|
+
return result;
|
|
492
|
+
}
|