@mionjs/run-types 0.8.8 → 0.8.10

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.
Files changed (56) hide show
  1. package/.dist/cjs/src/createRunType.cjs +3 -1
  2. package/.dist/cjs/src/createRunType.cjs.map +1 -1
  3. package/.dist/cjs/src/createRunType.d.ts.map +1 -1
  4. package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs +1 -1
  5. package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs.map +1 -1
  6. package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts.map +1 -1
  7. package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs +1 -1
  8. package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs.map +1 -1
  9. package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts.map +1 -1
  10. package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs +1 -1
  11. package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs.map +1 -1
  12. package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts.map +1 -1
  13. package/.dist/cjs/src/mocking/mockType.cjs +46 -1
  14. package/.dist/cjs/src/mocking/mockType.cjs.map +1 -1
  15. package/.dist/cjs/src/nodes/collection/templateLiteral.cjs +73 -0
  16. package/.dist/cjs/src/nodes/collection/templateLiteral.cjs.map +1 -0
  17. package/.dist/cjs/src/nodes/collection/templateLiteral.d.ts +16 -0
  18. package/.dist/cjs/src/nodes/collection/templateLiteral.d.ts.map +1 -0
  19. package/.dist/cjs/src/nodes/member/indexProperty.cjs +69 -22
  20. package/.dist/cjs/src/nodes/member/indexProperty.cjs.map +1 -1
  21. package/.dist/cjs/src/nodes/member/indexProperty.d.ts +1 -0
  22. package/.dist/cjs/src/nodes/member/indexProperty.d.ts.map +1 -1
  23. package/.dist/esm/src/createRunType.d.ts.map +1 -1
  24. package/.dist/esm/src/createRunType.js +3 -1
  25. package/.dist/esm/src/createRunType.js.map +1 -1
  26. package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts.map +1 -1
  27. package/.dist/esm/src/jitCompilers/binary/fromBinary.js +1 -1
  28. package/.dist/esm/src/jitCompilers/binary/fromBinary.js.map +1 -1
  29. package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts.map +1 -1
  30. package/.dist/esm/src/jitCompilers/binary/toBinary.js +1 -1
  31. package/.dist/esm/src/jitCompilers/binary/toBinary.js.map +1 -1
  32. package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts.map +1 -1
  33. package/.dist/esm/src/jitCompilers/json/stringifyJson.js +1 -1
  34. package/.dist/esm/src/jitCompilers/json/stringifyJson.js.map +1 -1
  35. package/.dist/esm/src/mocking/mockType.js +47 -2
  36. package/.dist/esm/src/mocking/mockType.js.map +1 -1
  37. package/.dist/esm/src/mocking/mockUtils.js +1 -1
  38. package/.dist/esm/src/nodes/collection/templateLiteral.d.ts +16 -0
  39. package/.dist/esm/src/nodes/collection/templateLiteral.d.ts.map +1 -0
  40. package/.dist/esm/src/nodes/collection/templateLiteral.js +73 -0
  41. package/.dist/esm/src/nodes/collection/templateLiteral.js.map +1 -0
  42. package/.dist/esm/src/nodes/member/indexProperty.d.ts +1 -0
  43. package/.dist/esm/src/nodes/member/indexProperty.d.ts.map +1 -1
  44. package/.dist/esm/src/nodes/member/indexProperty.js +70 -23
  45. package/.dist/esm/src/nodes/member/indexProperty.js.map +1 -1
  46. package/package.json +3 -3
  47. package/src/createRunType.ts +5 -6
  48. package/src/jitCompilers/binary/fromBinary.ts +2 -1
  49. package/src/jitCompilers/binary/toBinary.ts +2 -1
  50. package/src/jitCompilers/json/stringifyJson.ts +2 -1
  51. package/src/jitCompilers/serialization-suite.ts +52 -0
  52. package/src/jitCompilers/xyz-Template/fromXYZ.ts +2 -1
  53. package/src/jitCompilers/xyz-Template/toXYZ.ts +2 -1
  54. package/src/mocking/mockType.ts +56 -1
  55. package/src/nodes/collection/templateLiteral.ts +87 -0
  56. package/src/nodes/member/indexProperty.ts +66 -17
@@ -31,6 +31,7 @@ const src_nodes_function_function = require("./nodes/function/function.cjs");
31
31
  const src_nodes_native_promise = require("./nodes/native/promise.cjs");
32
32
  const src_nodes_atomic_object = require("./nodes/atomic/object.cjs");
33
33
  const src_nodes_collection_intersection = require("./nodes/collection/intersection.cjs");
34
+ const src_nodes_collection_templateLiteral = require("./nodes/collection/templateLiteral.cjs");
34
35
  const src_nodes_member_param = require("./nodes/member/param.cjs");
35
36
  const src_nodes_member_method = require("./nodes/member/method.cjs");
36
37
  const src_nodes_member_restParams = require("./nodes/member/restParams.cjs");
@@ -173,7 +174,8 @@ function createRunType(deepkitType) {
173
174
  rt = new src_nodes_atomic_symbol.SymbolRunType();
174
175
  break;
175
176
  case type.ReflectionKind.templateLiteral:
176
- throw new Error("Template Literals are resolved by the compiler to Literals ie: const tl = `${string}World`. Template literal types are not supported. ie type TL = `${string}World`");
177
+ rt = new src_nodes_collection_templateLiteral.TemplateLiteralRunType();
178
+ break;
177
179
  case type.ReflectionKind.undefined:
178
180
  rt = new src_nodes_atomic_undefined.UndefinedRunType();
179
181
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"createRunType.cjs","sources":["../../../src/createRunType.ts"],"sourcesContent":["/* eslint-disable no-case-declarations */\n/* ########\n * 2024 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {RunType, Mutable, SrcType} from './types.ts';\nimport type {BaseRunType} from './lib/baseRunTypes.ts';\nimport type {TypeClass, Type} from '@deepkit/type';\nimport {ReflectionKind, resolveReceiveType, ReceiveType, reflect, typeAnnotation, stringifyType} from '@deepkit/type';\nimport {\n hasArguments,\n hasExtendsArguments,\n hasImplements,\n hasIndexType,\n hasParameters,\n hasReturn,\n hasType,\n hasTypes,\n isNativeUtilityStringTypes,\n isNonSerializableClass,\n isNonSerializableObject,\n} from './lib/guards.ts';\nimport {StringRunType} from './nodes/atomic/string.ts';\nimport {DateRunType} from './nodes/atomic/date.ts';\nimport {NumberRunType} from './nodes/atomic/number.ts';\nimport {BooleanRunType} from './nodes/atomic/boolean.ts';\nimport {NullRunType} from './nodes/atomic/null.ts';\nimport {BigIntRunType} from './nodes/atomic/bigInt.ts';\nimport {AnyRunType} from './nodes/atomic/any.ts';\nimport {UndefinedRunType} from './nodes/atomic/undefined.ts';\nimport {UnknownRunType} from './nodes/atomic/unknown.ts';\nimport {VoidRunType} from './nodes/atomic/void.ts';\nimport {ArrayRunType} from './nodes/member/array.ts';\nimport {LiteralRunType} from './nodes/atomic/literal.ts';\nimport {RegexpRunType} from './nodes/atomic/regexp.ts';\nimport {NeverRunType} from './nodes/atomic/never.ts';\nimport {EnumRunType} from './nodes/atomic/enum.ts';\nimport {EnumMemberRunType} from './nodes/atomic/enumMember.ts';\nimport {UnionRunType} from './nodes/collection/union.ts';\nimport {TupleRunType} from './nodes/collection/tuple.ts';\nimport {FunctionParamsRunType} from './nodes/collection/functionParams.ts';\nimport {TupleMemberRunType} from './nodes/member/tupleMember.ts';\nimport {InterfaceRunType} from './nodes/collection/interface.ts';\nimport {PropertyRunType} from './nodes/member/property.ts';\nimport {IndexSignatureRunType} from './nodes/member/indexProperty.ts';\nimport {MethodSignatureRunType} from './nodes/member/methodSignature.ts';\nimport {CallSignatureRunType} from './nodes/member/callSignature.ts';\nimport {FunctionRunType} from './nodes/function/function.ts';\nimport {PromiseRunType} from './nodes/native/promise.ts';\nimport {ObjectRunType} from './nodes/atomic/object.ts';\nimport {IntersectionRunType} from './nodes/collection/intersection.ts';\nimport {ParameterRunType} from './nodes/member/param.ts';\nimport {MethodRunType} from './nodes/member/method.ts';\nimport {RestParamsRunType} from './nodes/member/restParams.ts';\nimport {ClassRunType} from './nodes/collection/class.ts';\nimport {MapRunType} from './nodes/native/map.ts';\nimport {ReflectionSubKind} from './constants.kind.ts';\nimport {SetRunType} from './nodes/native/set.ts';\nimport {SymbolRunType} from './nodes/atomic/symbol.ts';\nimport {NonSerializableRunType} from './nodes/native/nonSerializable.ts';\nimport {registerErrorDeserializers} from '@mionjs/core';\n\nexport function runType<T>(type?: ReceiveType<T>): RunType {\n const start = Date.now();\n const src = resolveReceiveType(type) as SrcType;\n const took0 = Date.now() - start;\n createRunTypes(src);\n const took1 = Date.now() - start;\n const diff = took1 - took0;\n // max RunType overhead 60 ms\n if (diff > 60) console.warn(`RunType overhead is very long: ${diff}ms for ${stringifyType(src)}`);\n return src._rt;\n}\n\nexport function reflectFunction<Fn extends (...args: any[]) => any>(fn: Fn): FunctionRunType {\n const src = reflect(fn) as SrcType;\n runType(src);\n return src._rt as FunctionRunType;\n}\n\n// We need to traverse all possible associated nodes to create all the runTypes\nfunction createRunTypes(src: SrcType): void {\n registerErrorDeserializers();\n const stack: Type[] = [src];\n\n while (stack.length > 0) {\n const current = stack.pop();\n if (!current || (current as SrcType)._rt) continue;\n\n try {\n createRunType(current as Mutable<SrcType>);\n } catch (error) {\n const typesStackMessage = '\\nTypes Stack: ' + stack.map((t) => t.typeName || t.kind).join(', ');\n (error as Error).message += typesStackMessage;\n throw error;\n }\n\n // single child type nodes\n if (hasType(current)) stack.push(current.type);\n if (hasReturn(current)) stack.push(current.return);\n if (hasIndexType(current)) stack.push(current.indexType);\n if (current.origin) stack.push(current.origin);\n if (current.indexAccessOrigin?.index) stack.push(current.indexAccessOrigin?.index);\n if (current.indexAccessOrigin?.container) stack.push(current.indexAccessOrigin?.container);\n\n // multiple child type nodes\n if (hasTypes(current)) pushToStack(current.types, stack);\n if (hasParameters(current)) pushToStack(current.parameters, stack);\n if (hasArguments(current)) pushToStack(current.arguments, stack);\n if (hasExtendsArguments(current)) pushToStack(current.extendsArguments, stack);\n if (hasImplements(current)) pushToStack(current.implements, stack);\n if (current.typeArguments) pushToStack(current.typeArguments, stack);\n if (current.decorators) pushToStack(current.decorators, stack);\n if (current.scheduleDecorators) pushToStack(current.scheduleDecorators, stack);\n\n // annotations\n if (current.annotations) {\n const annotations = typeAnnotation.getAnnotations(current);\n for (const annotation of annotations) stack.push(annotation.options);\n }\n\n // originTypes\n current.originTypes?.forEach((ot) => {\n if (ot.typeArguments) pushToStack(ot.typeArguments, stack);\n });\n\n // sometimes parent is an orphan so we need to explicitly add it to the stack\n if (current.parent && !(current.parent as SrcType)?._rt) stack.push(current.parent);\n }\n}\n\nfunction pushToStack(subTypes: Type[], stack: Type[]) {\n if (Array.isArray(subTypes)) stack.push(...subTypes);\n}\n\nfunction createRunType(deepkitType: Mutable<SrcType>): RunType {\n // console.log('deepkitType', deepkitType);\n\n /*\n RunType reference is stored in the deepkitType._runType so we can access both the deepkitType and the mion RunType,\n basically every runType stores a reference to a deepkit type and vice versa.\n This also relies on deepkit handling circular types to prevent infinite loop when we are generating RunTypes.\n */\n const existingType: RunType | undefined = deepkitType._rt;\n // TODO: IMPORTANT: seems like deepkit can generate multiple types objects for the same type, so we need to handle this\n // we are attaching the runType to the deepkit type (deepkitType._runType), to link the two types together\n // but as deepkit can generate multiple types that means existingType will be null and the markAsCircular function is not working as expected\n if (existingType) return existingType;\n\n let rt: BaseRunType;\n\n switch (deepkitType.kind) {\n // ###################### ATOMIC RUNTYPES ######################\n // Primitive types and other atomic types that don't contain other types\n case ReflectionKind.any:\n rt = new AnyRunType();\n break;\n case ReflectionKind.bigint:\n rt = new BigIntRunType();\n break;\n case ReflectionKind.boolean:\n rt = new BooleanRunType();\n break;\n case ReflectionKind.enum:\n rt = new EnumRunType();\n break;\n case ReflectionKind.enumMember:\n // enum members are resolved by the enum type, so this is not expected to be called\n rt = new EnumMemberRunType();\n break;\n case ReflectionKind.literal:\n rt = new LiteralRunType();\n break;\n case ReflectionKind.never:\n // TODO add the string format feature\n rt = isNativeUtilityStringTypes(deepkitType) ? new StringRunType() : new NeverRunType();\n break;\n case ReflectionKind.null:\n rt = new NullRunType();\n break;\n case ReflectionKind.number:\n rt = new NumberRunType();\n break;\n case ReflectionKind.object:\n rt = new ObjectRunType();\n break;\n case ReflectionKind.regexp:\n rt = new RegexpRunType();\n break;\n case ReflectionKind.string:\n rt = new StringRunType();\n break;\n case ReflectionKind.symbol:\n rt = new SymbolRunType();\n break;\n case ReflectionKind.templateLiteral:\n // deepkit automatically resolves template literals unions to literals\n // this is only called when you define the type of a template literal i.e: type T = `foo${string}`;\n // this is not supported at the moment but would be useful for type safe urls etc\n throw new Error(\n 'Template Literals are resolved by the compiler to Literals ie: const tl = `${string}World`. Template literal types are not supported. ie type TL = `${string}World`'\n );\n case ReflectionKind.undefined:\n rt = new UndefinedRunType();\n break;\n case ReflectionKind.unknown:\n rt = new UnknownRunType();\n break;\n case ReflectionKind.void:\n rt = new VoidRunType();\n break;\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.array:\n rt = new ArrayRunType();\n break;\n case ReflectionKind.callSignature:\n rt = new CallSignatureRunType();\n break;\n case ReflectionKind.function:\n if (deepkitType.subKind === ReflectionSubKind.params) {\n rt = new FunctionParamsRunType();\n } else {\n const frt = new FunctionRunType();\n // TODO review an change how we compile function parameters and return type\n // those should also be jit functions, no need to check for array\n // and maybe add option to target individual parameters\n (frt.parameterRunTypes as Mutable<RunType>).src = deepkitType;\n rt = frt;\n }\n break;\n case ReflectionKind.indexSignature:\n rt = new IndexSignatureRunType();\n break;\n case ReflectionKind.method:\n rt = new MethodRunType();\n break;\n case ReflectionKind.methodSignature:\n rt = new MethodSignatureRunType();\n break;\n case ReflectionKind.parameter:\n rt = new ParameterRunType();\n break;\n case ReflectionKind.property:\n case ReflectionKind.propertySignature:\n rt = new PropertyRunType();\n break;\n case ReflectionKind.rest:\n rt = new RestParamsRunType();\n break;\n case ReflectionKind.tupleMember:\n rt = new TupleMemberRunType();\n break;\n case ReflectionKind.promise:\n rt = new PromiseRunType();\n break;\n\n // ###################### COLLECTION RUNTYPES ######################\n case ReflectionKind.objectLiteral:\n if (isNonSerializableObject(deepkitType)) {\n rt = new NonSerializableRunType();\n } else {\n rt = new InterfaceRunType();\n }\n break;\n case ReflectionKind.class:\n rt = initClassRunType(deepkitType);\n break;\n // Types that contain other types as members\n case ReflectionKind.infer:\n throw new Error(\n 'Infer type not supported, ie: type MyType =Type<T> = T extends (...args: any[]) => infer R ? R : any; https://www.typescriptlang.org/docs/handbook/2/conditional-types.html'\n );\n\n case ReflectionKind.intersection:\n rt = new IntersectionRunType();\n break;\n\n case ReflectionKind.tuple:\n rt = new TupleRunType();\n break;\n case ReflectionKind.typeParameter:\n throw new Error(\n 'TypeParameter not implemented. Type parameters are the generic placeholders in type definitions (e.g., T in Array<T>, ErrType in TypedError<ErrType>). ' +\n 'Type parameters are typically resolved during type instantiation and should not appear in runtime type checking.' +\n 'This error is typically caused by a generic type missing type arguments, e.g.: TypedError instead of TypedError<\"my-error\">.'\n );\n // rType = resolveTypeParameter(deepkitType, opts, mapper);\n case ReflectionKind.union:\n rt = new UnionRunType();\n break;\n default:\n rt = new AnyRunType();\n break;\n }\n rt.onCreated(deepkitType);\n // console.log('rt', rt);\n return rt;\n}\n\nfunction initClassRunType(src: TypeClass & {subKind?: number}): BaseRunType {\n switch (src.classType) {\n case Date:\n src.subKind = ReflectionSubKind.date;\n return new DateRunType();\n case Map:\n src.subKind = ReflectionSubKind.map;\n return new MapRunType();\n case Set:\n src.subKind = ReflectionSubKind.set;\n return new SetRunType();\n default:\n if (isNonSerializableClass(src)) {\n src.subKind = ReflectionSubKind.nonSerializable;\n return new NonSerializableRunType();\n }\n return new ClassRunType();\n }\n}\n"],"names":["type","resolveReceiveType","stringifyType","reflect","registerErrorDeserializers","hasType","hasReturn","hasIndexType","hasTypes","hasParameters","hasArguments","hasExtendsArguments","hasImplements","typeAnnotation","ReflectionKind","AnyRunType","BigIntRunType","BooleanRunType","EnumRunType","EnumMemberRunType","LiteralRunType","isNativeUtilityStringTypes","StringRunType","NeverRunType","NullRunType","NumberRunType","ObjectRunType","RegexpRunType","SymbolRunType","UndefinedRunType","UnknownRunType","VoidRunType","ArrayRunType","CallSignatureRunType","ReflectionSubKind","FunctionParamsRunType","FunctionRunType","IndexSignatureRunType","MethodRunType","MethodSignatureRunType","ParameterRunType","PropertyRunType","RestParamsRunType","TupleMemberRunType","PromiseRunType","isNonSerializableObject","NonSerializableRunType","InterfaceRunType","IntersectionRunType","TupleRunType","UnionRunType","DateRunType","MapRunType","SetRunType","isNonSerializableClass","ClassRunType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEM,SAAU,QAAWA,SAAX,QAAO,IAAA,CAAA,GAAyB;AAAhC,UAAO,IAAA;AACnB,QAAM,QAAQ,KAAK,IAAA;AACnB,QAAM,MAAMC,KAAAA,mBAAmBD,MAAI;AACnC,QAAM,QAAQ,KAAK,IAAA,IAAQ;AAC3B,iBAAe,GAAG;AAClB,QAAM,QAAQ,KAAK,IAAA,IAAQ;AAC3B,QAAM,OAAO,QAAQ;AAErB,MAAI,OAAO;AAAI,YAAQ,KAAK,kCAAkC,IAAI,UAAUE,KAAAA,cAAc,GAAG,CAAC,EAAE;AAChG,SAAO,IAAI;AACd;;AAEK,SAAU,gBAAoD,IAAM;AACtE,QAAM,MAAMC,KAAAA,QAAQ,EAAE;AACtB,UAAQ,GAAG;AACX,SAAO,IAAI;AACf;;AAGA,SAAS,eAAe,KAAY;AAChCC,kCAAA;AACA,QAAM,QAAgB,CAAC,GAAG;AAE1B,SAAO,MAAM,SAAS,GAAG;AACrB,UAAM,UAAU,MAAM,IAAA;AACtB,QAAI,CAAC,WAAY,QAAoB;AAAK;AAE1C,QAAI;AACA,oBAAc,OAA2B;AAAA,IAC7C,SAAS,OAAO;AACZ,YAAM,oBAAoB,oBAAoB,MAAM,IAAG,aAAC,CAAC,MAAM,EAAE,YAAY,EAAE,MAAI,CAAA,KAAA,IAAA,SAAA,CAAA,CAAA,EAAE,KAAK,IAAI;AAC7F,YAAgB,WAAW;AAC5B,YAAM;AAAA,IACV;AAGA,QAAIC,eAAAA,QAAQ,OAAO;AAAG,YAAM,KAAK,QAAQ,IAAI;AAC7C,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-disable no-case-declarations */\n/* ########\n * 2024 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {RunType, Mutable, SrcType} from './types.ts';\nimport type {BaseRunType} from './lib/baseRunTypes.ts';\nimport type {TypeClass, Type} from '@deepkit/type';\nimport {ReflectionKind, resolveReceiveType, ReceiveType, reflect, typeAnnotation, stringifyType} from '@deepkit/type';\nimport {\n hasArguments,\n hasExtendsArguments,\n hasImplements,\n hasIndexType,\n hasParameters,\n hasReturn,\n hasType,\n hasTypes,\n isNativeUtilityStringTypes,\n isNonSerializableClass,\n isNonSerializableObject,\n} from './lib/guards.ts';\nimport {StringRunType} from './nodes/atomic/string.ts';\nimport {DateRunType} from './nodes/atomic/date.ts';\nimport {NumberRunType} from './nodes/atomic/number.ts';\nimport {BooleanRunType} from './nodes/atomic/boolean.ts';\nimport {NullRunType} from './nodes/atomic/null.ts';\nimport {BigIntRunType} from './nodes/atomic/bigInt.ts';\nimport {AnyRunType} from './nodes/atomic/any.ts';\nimport {UndefinedRunType} from './nodes/atomic/undefined.ts';\nimport {UnknownRunType} from './nodes/atomic/unknown.ts';\nimport {VoidRunType} from './nodes/atomic/void.ts';\nimport {ArrayRunType} from './nodes/member/array.ts';\nimport {LiteralRunType} from './nodes/atomic/literal.ts';\nimport {RegexpRunType} from './nodes/atomic/regexp.ts';\nimport {NeverRunType} from './nodes/atomic/never.ts';\nimport {EnumRunType} from './nodes/atomic/enum.ts';\nimport {EnumMemberRunType} from './nodes/atomic/enumMember.ts';\nimport {UnionRunType} from './nodes/collection/union.ts';\nimport {TupleRunType} from './nodes/collection/tuple.ts';\nimport {FunctionParamsRunType} from './nodes/collection/functionParams.ts';\nimport {TupleMemberRunType} from './nodes/member/tupleMember.ts';\nimport {InterfaceRunType} from './nodes/collection/interface.ts';\nimport {PropertyRunType} from './nodes/member/property.ts';\nimport {IndexSignatureRunType} from './nodes/member/indexProperty.ts';\nimport {MethodSignatureRunType} from './nodes/member/methodSignature.ts';\nimport {CallSignatureRunType} from './nodes/member/callSignature.ts';\nimport {FunctionRunType} from './nodes/function/function.ts';\nimport {PromiseRunType} from './nodes/native/promise.ts';\nimport {ObjectRunType} from './nodes/atomic/object.ts';\nimport {IntersectionRunType} from './nodes/collection/intersection.ts';\nimport {TemplateLiteralRunType} from './nodes/collection/templateLiteral.ts';\nimport {ParameterRunType} from './nodes/member/param.ts';\nimport {MethodRunType} from './nodes/member/method.ts';\nimport {RestParamsRunType} from './nodes/member/restParams.ts';\nimport {ClassRunType} from './nodes/collection/class.ts';\nimport {MapRunType} from './nodes/native/map.ts';\nimport {ReflectionSubKind} from './constants.kind.ts';\nimport {SetRunType} from './nodes/native/set.ts';\nimport {SymbolRunType} from './nodes/atomic/symbol.ts';\nimport {NonSerializableRunType} from './nodes/native/nonSerializable.ts';\nimport {registerErrorDeserializers} from '@mionjs/core';\n\nexport function runType<T>(type?: ReceiveType<T>): RunType {\n const start = Date.now();\n const src = resolveReceiveType(type) as SrcType;\n const took0 = Date.now() - start;\n createRunTypes(src);\n const took1 = Date.now() - start;\n const diff = took1 - took0;\n // max RunType overhead 60 ms\n if (diff > 60) console.warn(`RunType overhead is very long: ${diff}ms for ${stringifyType(src)}`);\n return src._rt;\n}\n\nexport function reflectFunction<Fn extends (...args: any[]) => any>(fn: Fn): FunctionRunType {\n const src = reflect(fn) as SrcType;\n runType(src);\n return src._rt as FunctionRunType;\n}\n\n// We need to traverse all possible associated nodes to create all the runTypes\nfunction createRunTypes(src: SrcType): void {\n registerErrorDeserializers();\n const stack: Type[] = [src];\n\n while (stack.length > 0) {\n const current = stack.pop();\n if (!current || (current as SrcType)._rt) continue;\n\n try {\n createRunType(current as Mutable<SrcType>);\n } catch (error) {\n const typesStackMessage = '\\nTypes Stack: ' + stack.map((t) => t.typeName || t.kind).join(', ');\n (error as Error).message += typesStackMessage;\n throw error;\n }\n\n // single child type nodes\n if (hasType(current)) stack.push(current.type);\n if (hasReturn(current)) stack.push(current.return);\n if (hasIndexType(current)) stack.push(current.indexType);\n if (current.origin) stack.push(current.origin);\n if (current.indexAccessOrigin?.index) stack.push(current.indexAccessOrigin?.index);\n if (current.indexAccessOrigin?.container) stack.push(current.indexAccessOrigin?.container);\n\n // multiple child type nodes\n if (hasTypes(current)) pushToStack(current.types, stack);\n if (hasParameters(current)) pushToStack(current.parameters, stack);\n if (hasArguments(current)) pushToStack(current.arguments, stack);\n if (hasExtendsArguments(current)) pushToStack(current.extendsArguments, stack);\n if (hasImplements(current)) pushToStack(current.implements, stack);\n if (current.typeArguments) pushToStack(current.typeArguments, stack);\n if (current.decorators) pushToStack(current.decorators, stack);\n if (current.scheduleDecorators) pushToStack(current.scheduleDecorators, stack);\n\n // annotations\n if (current.annotations) {\n const annotations = typeAnnotation.getAnnotations(current);\n for (const annotation of annotations) stack.push(annotation.options);\n }\n\n // originTypes\n current.originTypes?.forEach((ot) => {\n if (ot.typeArguments) pushToStack(ot.typeArguments, stack);\n });\n\n // sometimes parent is an orphan so we need to explicitly add it to the stack\n if (current.parent && !(current.parent as SrcType)?._rt) stack.push(current.parent);\n }\n}\n\nfunction pushToStack(subTypes: Type[], stack: Type[]) {\n if (Array.isArray(subTypes)) stack.push(...subTypes);\n}\n\nfunction createRunType(deepkitType: Mutable<SrcType>): RunType {\n // console.log('deepkitType', deepkitType);\n\n /*\n RunType reference is stored in the deepkitType._runType so we can access both the deepkitType and the mion RunType,\n basically every runType stores a reference to a deepkit type and vice versa.\n This also relies on deepkit handling circular types to prevent infinite loop when we are generating RunTypes.\n */\n const existingType: RunType | undefined = deepkitType._rt;\n // TODO: IMPORTANT: seems like deepkit can generate multiple types objects for the same type, so we need to handle this\n // we are attaching the runType to the deepkit type (deepkitType._runType), to link the two types together\n // but as deepkit can generate multiple types that means existingType will be null and the markAsCircular function is not working as expected\n if (existingType) return existingType;\n\n let rt: BaseRunType;\n\n switch (deepkitType.kind) {\n // ###################### ATOMIC RUNTYPES ######################\n // Primitive types and other atomic types that don't contain other types\n case ReflectionKind.any:\n rt = new AnyRunType();\n break;\n case ReflectionKind.bigint:\n rt = new BigIntRunType();\n break;\n case ReflectionKind.boolean:\n rt = new BooleanRunType();\n break;\n case ReflectionKind.enum:\n rt = new EnumRunType();\n break;\n case ReflectionKind.enumMember:\n // enum members are resolved by the enum type, so this is not expected to be called\n rt = new EnumMemberRunType();\n break;\n case ReflectionKind.literal:\n rt = new LiteralRunType();\n break;\n case ReflectionKind.never:\n // TODO add the string format feature\n rt = isNativeUtilityStringTypes(deepkitType) ? new StringRunType() : new NeverRunType();\n break;\n case ReflectionKind.null:\n rt = new NullRunType();\n break;\n case ReflectionKind.number:\n rt = new NumberRunType();\n break;\n case ReflectionKind.object:\n rt = new ObjectRunType();\n break;\n case ReflectionKind.regexp:\n rt = new RegexpRunType();\n break;\n case ReflectionKind.string:\n rt = new StringRunType();\n break;\n case ReflectionKind.symbol:\n rt = new SymbolRunType();\n break;\n case ReflectionKind.templateLiteral:\n // deepkit resolves finite template literal unions to literal-string unions before reaching here.\n // this branch handles the open form ie: type T = `api/user/${number}` (children: literal/string/number/any/infer)\n rt = new TemplateLiteralRunType();\n break;\n case ReflectionKind.undefined:\n rt = new UndefinedRunType();\n break;\n case ReflectionKind.unknown:\n rt = new UnknownRunType();\n break;\n case ReflectionKind.void:\n rt = new VoidRunType();\n break;\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.array:\n rt = new ArrayRunType();\n break;\n case ReflectionKind.callSignature:\n rt = new CallSignatureRunType();\n break;\n case ReflectionKind.function:\n if (deepkitType.subKind === ReflectionSubKind.params) {\n rt = new FunctionParamsRunType();\n } else {\n const frt = new FunctionRunType();\n // TODO review an change how we compile function parameters and return type\n // those should also be jit functions, no need to check for array\n // and maybe add option to target individual parameters\n (frt.parameterRunTypes as Mutable<RunType>).src = deepkitType;\n rt = frt;\n }\n break;\n case ReflectionKind.indexSignature:\n rt = new IndexSignatureRunType();\n break;\n case ReflectionKind.method:\n rt = new MethodRunType();\n break;\n case ReflectionKind.methodSignature:\n rt = new MethodSignatureRunType();\n break;\n case ReflectionKind.parameter:\n rt = new ParameterRunType();\n break;\n case ReflectionKind.property:\n case ReflectionKind.propertySignature:\n rt = new PropertyRunType();\n break;\n case ReflectionKind.rest:\n rt = new RestParamsRunType();\n break;\n case ReflectionKind.tupleMember:\n rt = new TupleMemberRunType();\n break;\n case ReflectionKind.promise:\n rt = new PromiseRunType();\n break;\n\n // ###################### COLLECTION RUNTYPES ######################\n case ReflectionKind.objectLiteral:\n if (isNonSerializableObject(deepkitType)) {\n rt = new NonSerializableRunType();\n } else {\n rt = new InterfaceRunType();\n }\n break;\n case ReflectionKind.class:\n rt = initClassRunType(deepkitType);\n break;\n // Types that contain other types as members\n case ReflectionKind.infer:\n throw new Error(\n 'Infer type not supported, ie: type MyType =Type<T> = T extends (...args: any[]) => infer R ? R : any; https://www.typescriptlang.org/docs/handbook/2/conditional-types.html'\n );\n\n case ReflectionKind.intersection:\n rt = new IntersectionRunType();\n break;\n\n case ReflectionKind.tuple:\n rt = new TupleRunType();\n break;\n case ReflectionKind.typeParameter:\n throw new Error(\n 'TypeParameter not implemented. Type parameters are the generic placeholders in type definitions (e.g., T in Array<T>, ErrType in TypedError<ErrType>). ' +\n 'Type parameters are typically resolved during type instantiation and should not appear in runtime type checking.' +\n 'This error is typically caused by a generic type missing type arguments, e.g.: TypedError instead of TypedError<\"my-error\">.'\n );\n // rType = resolveTypeParameter(deepkitType, opts, mapper);\n case ReflectionKind.union:\n rt = new UnionRunType();\n break;\n default:\n rt = new AnyRunType();\n break;\n }\n rt.onCreated(deepkitType);\n // console.log('rt', rt);\n return rt;\n}\n\nfunction initClassRunType(src: TypeClass & {subKind?: number}): BaseRunType {\n switch (src.classType) {\n case Date:\n src.subKind = ReflectionSubKind.date;\n return new DateRunType();\n case Map:\n src.subKind = ReflectionSubKind.map;\n return new MapRunType();\n case Set:\n src.subKind = ReflectionSubKind.set;\n return new SetRunType();\n default:\n if (isNonSerializableClass(src)) {\n src.subKind = ReflectionSubKind.nonSerializable;\n return new NonSerializableRunType();\n }\n return new ClassRunType();\n }\n}\n"],"names":["type","resolveReceiveType","stringifyType","reflect","registerErrorDeserializers","hasType","hasReturn","hasIndexType","hasTypes","hasParameters","hasArguments","hasExtendsArguments","hasImplements","typeAnnotation","ReflectionKind","AnyRunType","BigIntRunType","BooleanRunType","EnumRunType","EnumMemberRunType","LiteralRunType","isNativeUtilityStringTypes","StringRunType","NeverRunType","NullRunType","NumberRunType","ObjectRunType","RegexpRunType","SymbolRunType","TemplateLiteralRunType","UndefinedRunType","UnknownRunType","VoidRunType","ArrayRunType","CallSignatureRunType","ReflectionSubKind","FunctionParamsRunType","FunctionRunType","IndexSignatureRunType","MethodRunType","MethodSignatureRunType","ParameterRunType","PropertyRunType","RestParamsRunType","TupleMemberRunType","PromiseRunType","isNonSerializableObject","NonSerializableRunType","InterfaceRunType","IntersectionRunType","TupleRunType","UnionRunType","DateRunType","MapRunType","SetRunType","isNonSerializableClass","ClassRunType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEM,SAAU,QAAWA,SAAX,QAAO,IAAA,CAAA,GAAyB;AAAhC,UAAO,IAAA;AACnB,QAAM,QAAQ,KAAK,IAAA;AACnB,QAAM,MAAMC,KAAAA,mBAAmBD,MAAI;AACnC,QAAM,QAAQ,KAAK,IAAA,IAAQ;AAC3B,iBAAe,GAAG;AAClB,QAAM,QAAQ,KAAK,IAAA,IAAQ;AAC3B,QAAM,OAAO,QAAQ;AAErB,MAAI,OAAO;AAAI,YAAQ,KAAK,kCAAkC,IAAI,UAAUE,KAAAA,cAAc,GAAG,CAAC,EAAE;AAChG,SAAO,IAAI;AACd;;AAEK,SAAU,gBAAoD,IAAM;AACtE,QAAM,MAAMC,KAAAA,QAAQ,EAAE;AACtB,UAAQ,GAAG;AACX,SAAO,IAAI;AACf;;AAGA,SAAS,eAAe,KAAY;AACh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AAO,IAAIiB,sBAAAA,YAAA;AAAA,IACf,KAAK;AACD,UAAI,UAAUjB,mBAAAA,kBAAkB;AAChC,aAAO,IAAIkB,qBAAAA,WAAA;AAAA,IACf,KAAK;AACD,UAAI,UAAUlB,mBAAAA,kBAAkB;AAChC,aAAO,IAAImB,qBAAAA,WAAA;AAAA,IACf;AACI,UAAIC,eAAAA,uBAAuB,GAAG,GAAG;AAC7B,YAAI,UAAUpB,mBAAAA,kBAAkB;AAChC,eAAO,IAAIY,iCAAAA,uBAAA;AAAA,MACf;AACA,aAAO,IAAIS,2BAAAA,aAAA;AAAA,EAAY;AAEnC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createRunType.d.ts","sourceRoot":"","sources":["../../../src/createRunType.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAmB,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAqC,WAAW,EAAyC,MAAM,eAAe,CAAC;AAuCtH,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAe7D,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAUzD;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,eAAe,CAI3F"}
1
+ {"version":3,"file":"createRunType.d.ts","sourceRoot":"","sources":["../../../src/createRunType.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAmB,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAqC,WAAW,EAAyC,MAAM,eAAe,CAAC;AAuCtH,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAgB7D,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAUzD;AAED,wBAAgB,eAAe,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,eAAe,CAI3F"}
@@ -49,7 +49,7 @@ function emitFromBinary(runType, comp) {
49
49
  case type.ReflectionKind.never:
50
50
  throw new Error("Never type cannot be deserialized from Binary");
51
51
  case type.ReflectionKind.templateLiteral:
52
- throw new Error("Template literals are not supported in Binary deserialization");
52
+ return { code: `${dεs}.desString()`, type: "E" };
53
53
  case type.ReflectionKind.literal: {
54
54
  if (comp.opts.noLiterals) {
55
55
  const lit = runType.src.literal;
@@ -1 +1 @@
1
- {"version":3,"file":"fromBinary.cjs","sources":["../../../../../src/jitCompilers/binary/fromBinary.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport {getJitUtils} from '@mionjs/core';\nimport {ReflectionSubKind} from '../../constants.kind.ts';\nimport {childIsExpression, createIfElseFn, isSafePropName, toLiteral} from '../../lib/utils.ts';\nimport {jitBinaryDeserializerArgs, JitFunctions} from '../../constants.functions.ts';\nimport {MAX_UNION_ITEMS} from '../../constants.ts';\nimport type {JitCode} from '../../types.ts';\nimport type {BaseRunType} from '../../lib/baseRunTypes.ts';\nimport {type BaseFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport type {LiteralRunType} from '../../nodes/atomic/literal.ts';\nimport type {ArrayRunType} from '../../nodes/member/array.ts';\nimport type {PropertyRunType} from '../../nodes/member/property.ts';\nimport type {InterfaceRunType} from '../../nodes/collection/interface.ts';\nimport type {IndexSignatureRunType} from '../../nodes/member/indexProperty.ts';\nimport type {ClassRunType} from '../../nodes/collection/class.ts';\nimport type {TupleRunType} from '../../nodes/collection/tuple.ts';\nimport type {ParameterRunType} from '../../nodes/member/param.ts';\nimport type {RestParamsRunType} from '../../nodes/member/restParams.ts';\nimport type {UnionRunType} from '../../nodes/collection/union.ts';\nimport type {IterableRunType} from '../../nodes/native/Iterable.ts';\nimport type {MapRunType} from '../../nodes/native/map.ts';\n\ntype BinaryCompiler = BaseFnCompiler<typeof jitBinaryDeserializerArgs, typeof JitFunctions.fromBinary.id>;\n\nconst fnID = JitFunctions.fromBinary.id;\n\n/**\n * Main Binary deserialization compiler function\n * Generates JIT code to deserialize Binary data to JavaScript values\n */\nexport function emitFromBinary(runType: BaseRunType, comp: BinaryCompiler): JitCode {\n const src = runType.src;\n const kind = src.kind;\n const dεs = comp.args.dεs;\n\n // hack is used in some case to increase the index passing an extra argument to view.get methods\n // ie: view.getUint32(index, littleEndian, index += 4);\n // 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\n\n switch (kind) {\n // ###################### ATOMIC TYPES ######################\n case ReflectionKind.unknown:\n case ReflectionKind.any: {\n // any is deserialized from json string\n return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};\n }\n case ReflectionKind.null:\n return {code: `(${dεs}.index++, null)`, type: 'E'};\n case ReflectionKind.boolean:\n return {code: `${dεs}.view.getUint8(${dεs}.index++) === 1`, type: 'E'};\n case ReflectionKind.number: {\n return {code: `${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8))`, type: 'E'};\n }\n case ReflectionKind.string: {\n return {code: `${dεs}.desString()`, type: 'E'};\n }\n case ReflectionKind.bigint: {\n return {code: `BigInt(${dεs}.desString(true))`, type: 'E'};\n }\n case ReflectionKind.undefined:\n case ReflectionKind.void:\n return {code: `(${dεs}.index++, undefined)`, type: 'E'};\n case ReflectionKind.symbol: {\n return {code: `Symbol(${dεs}.desString() || undefined)`, type: 'E'};\n }\n case ReflectionKind.regexp: {\n return {code: `new RegExp(${dεs}.desString(), ${dεs}.desString())`, type: 'E'};\n }\n case ReflectionKind.object:\n // similar to any, this is deserialized as json string\n return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};\n case ReflectionKind.enum: {\n return {code: `${dεs}.desEnum()`, type: 'E'};\n }\n case ReflectionKind.enumMember:\n throw new Error('Binary deserialization not supported for enum member types');\n case ReflectionKind.never:\n throw new Error('Never type cannot be deserialized from Binary');\n case ReflectionKind.templateLiteral:\n throw new Error('Template literals are not supported in Binary deserialization');\n case ReflectionKind.literal: {\n if (comp.opts.noLiterals) {\n const lit = (runType as LiteralRunType).src.literal;\n if (lit instanceof RegExp) return emitFromBinaryAs(runType, comp, ReflectionKind.regexp);\n switch (typeof lit) {\n case 'string':\n return emitFromBinaryAs(runType, comp, ReflectionKind.string);\n case 'number':\n return emitFromBinaryAs(runType, comp, ReflectionKind.number);\n case 'boolean':\n return emitFromBinaryAs(runType, comp, ReflectionKind.boolean);\n case 'bigint':\n return emitFromBinaryAs(runType, comp, ReflectionKind.bigint);\n case 'symbol':\n return emitFromBinaryAs(runType, comp, ReflectionKind.symbol);\n default:\n throw new Error(`Unsupported literal type ${typeof lit}`);\n }\n }\n return {code: toLiteral((runType as LiteralRunType).src.literal), type: 'E'};\n }\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.rest: // rest params are deserialized as array but start at rest item index\n case ReflectionKind.array: {\n const rt = runType as ArrayRunType | RestParamsRunType;\n rt.checkNonSkipTypes(comp);\n const child = rt.getMemberType()!;\n const childCode = comp.compile(child, 'S', fnID);\n if (!childCode?.code) throw new Error(`Do not know how to deserialize Array<${child.getTypeName()}> from Binary.`);\n const isRest = rt.src.kind === ReflectionKind.rest;\n const index = rt.getChildVarName(comp);\n const isExpression = childIsExpression(childCode, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childCode.code};` : childCode.code;\n // deserialized from [length, items...]\n const lengthVal = comp.getLocalVarName('arrL', rt);\n const arrayInit = isRest ? '' : `${comp.vλl} = new Array(${lengthVal})`; // res array already initialized in parent\n return {\n code: `\n const ${lengthVal} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${arrayInit};\n for (let ${index} = ${rt.startIndex(comp)}; ${index} < ${lengthVal}; ${index}++) {${code}}\n `,\n type: 'S',\n };\n }\n\n case ReflectionKind.indexSignature: {\n const rt = runType as IndexSignatureRunType;\n const indexKind = (rt.src as any).index?.kind;\n const memberCode = comp.compile(rt.getJitChild(comp), 'S', fnID);\n if (!memberCode?.code) return {code: undefined, type: 'E'};\n\n const prop = rt.getChildVarName(comp);\n const countVar = comp.getLocalVarName('cnt', rt);\n const indexVar = comp.getLocalVarName('propI', rt);\n\n // Deserialize key based on index type\n let keyDeserializationCode: string;\n if (indexKind === ReflectionKind.number) {\n // For number indices, deserialize as uint32\n keyDeserializationCode = `const ${prop} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4;`;\n } else {\n // For string indices, deserialize as string with prototype pollution protection\n keyDeserializationCode = `const ${prop} = ${dεs}.desSafePropName();`;\n }\n\n const memberInit = memberCode.type === 'E' ? `${comp.vλl}[${prop}] = ${memberCode.code};` : memberCode.code;\n const deserializeCode = `for (let ${indexVar} = 0; ${indexVar} < ${countVar}; ${indexVar}++) {${keyDeserializationCode}${memberInit}}`;\n\n return {\n code: `const ${countVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${comp.vλl} = {}; ${deserializeCode}`,\n type: 'S',\n };\n }\n\n case ReflectionKind.function:\n case ReflectionKind.method:\n case ReflectionKind.methodSignature:\n case ReflectionKind.callSignature:\n if (runType.src.subKind === ReflectionSubKind.params) {\n return emitFromBinaryAs(runType, comp, ReflectionKind.tuple);\n } else {\n throw new Error(\n 'Binary deserialization not supported for functions, call compileParams or compileReturn instead.'\n );\n }\n\n case ReflectionKind.parameter: {\n const rt = runType as ParameterRunType;\n switch (src.subKind) {\n case ReflectionSubKind.mapKey:\n case ReflectionSubKind.mapValue:\n case ReflectionSubKind.setItem: {\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n if (!childJit?.code || !child)\n throw new Error(`Do not know how to deserialize ${rt.getTypeName()} from Binary.`);\n const parent = rt.getParent()!;\n const parentVλl = parent.getCustomVλl(comp)?.vλl || comp.vλl;\n const vλl = rt.getCustomVλl(comp)?.vλl;\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `const ${vλl} = ${childJit.code};` : childJit.code || '';\n let setOperation = '';\n switch (rt.src.subKind) {\n case ReflectionSubKind.mapKey:\n break; // we set map item once we have the key and value\n case ReflectionSubKind.mapValue: {\n const mapKey = (parent as MapRunType).getMapKeyVλl(comp); // not the best solution but works\n setOperation = `${parentVλl}.set(${mapKey}, ${vλl})`;\n break;\n }\n case ReflectionSubKind.setItem:\n setOperation = `${parentVλl}.add(${vλl})`;\n break;\n }\n return {code: `${code}; ${setOperation};`, type: 'S'};\n }\n default:\n return emitFromBinaryAs(runType, comp, ReflectionKind.tupleMember);\n }\n }\n\n case ReflectionKind.property:\n case ReflectionKind.propertySignature: {\n const rt = runType as PropertyRunType;\n const parent = rt.getParent() as InterfaceRunType;\n const child = rt.getJitChild(comp)!;\n const childJit = comp.compile(child, 'S', fnID);\n if (rt.isOptional()) {\n const {bitMIndexVar, bitIndex} = getOptionalBitmapItems(parent, comp, 0, rt.optionalIndex, false);\n const initCode = childJit.type === 'E' ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code;\n return {\n code: `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`,\n type: 'S',\n };\n }\n // block or statements code are initialized as obj.a = deserializeA; obj.b = deserializeB; after initial object has been created\n const isExpression = childIsExpression(childJit, child);\n if (!isExpression) {\n return childJit; // block statements already include variable assignment\n }\n // required props that are simple expressions code are part of an object constructor {a: deserializeA, b: deserializeB, c: deserializeC}\n const propName = getPropName(rt, comp, true);\n return {code: `${propName}:${childJit?.code}`, type: 'E'};\n }\n\n case ReflectionKind.tupleMember: {\n const rt = runType as ParameterRunType;\n const childJit = comp.compile(rt.getJitChild(comp), 'S', fnID);\n const nullJIt = emitFromBinaryAs(rt, comp, ReflectionKind.undefined);\n const itemJit = childJit?.code ? childJit : nullJIt; // if child is not serializable, we serialize null as need to fill the space in the tuple\n const initCode = itemJit.type === 'E' ? `${comp.getChildVλl()} = ${itemJit.code}` : itemJit.code;\n if (rt.isRest()) return itemJit;\n // Optional handling uses bitmap set at tuple level\n const optionalIndex = (rt as any).optionalIndex;\n const bitMIndexVar = (rt as any)._bitmapVar;\n const isFnParam = (rt as any)._isFnParam;\n // Treat as optional if either isOptional() is true OR it's a function param (all fn params are optional in binary)\n const isOptional = rt.isOptional() || isFnParam;\n if (isOptional && optionalIndex !== undefined && bitMIndexVar) {\n const bitIndex = optionalIndex & 7; // equivalent to optionalIndex % 8\n const code = `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`;\n return {code, type: 'S'};\n }\n return {code: initCode, type: 'S'};\n }\n case ReflectionKind.promise:\n throw new Error('Jit compilation disabled for Non Serializable types.');\n\n // ###################### COLLECTION RUNTYPES ######################\n // Types that contain other types as members\n case ReflectionKind.objectLiteral:\n case ReflectionKind.intersection: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) return comp.compile(rt.getCallSignature(), 'S', fnID);\n if (runType.src.subKind === ReflectionSubKind.nonSerializable) {\n throw new Error('Binary deserialization is disabled for Non Serializable types');\n } else {\n const {required, optional, indexSignatures} = rt.splitJitSplitChildren(comp);\n if (indexSignatures.length) {\n return comp.compile(indexSignatures[0], 'S', fnID); // index signature code already contains the loop\n }\n\n // required props that are simple expressions are restored as: '{a: deserializeA, b: deserializeB, c: deserializeC};\n // and are serialized/deserialised in the same order they are declared in the type\n const requiredItemsJit = required.map((prop) => comp.compile(prop, 'S', fnID));\n const expressionItemsJit = requiredItemsJit\n .filter((childJit, i) => childIsExpression(childJit, required[i]))\n .map((prop) => prop.code)\n .filter(Boolean);\n const statementItemsCode = requiredItemsJit\n .filter(Boolean)\n .filter((childJit, i) => !childIsExpression(childJit, required[i]))\n .map((prop) => prop.code);\n const expressionsPropsCode = expressionItemsJit.join(',');\n const requiredPropsCode = statementItemsCode.join(';');\n\n // optional props are initialized as obj.a = deserializeA; obj.b = deserializeB; obj.c = deserializeC;\n // bitmap is used to determine which optional props are present\n // header format: [bitmap, optional props]\n let optionalPropsCode = '';\n if (optional.length) {\n // optional properties are restored using a loop\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, false);\n const propsCode = optional\n .map((prop, i) => {\n prop.optionalIndex = i;\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0;\n const propCode = comp.compile(prop, 'S', fnID).code;\n if (!shouldIncreaseBufferIndex) return propCode;\n // every 8 props we need to increase the bitmap index\n return `${propCode} ${bitMIndexVar}++; `;\n })\n .filter(Boolean)\n .join('');\n const sep = requiredPropsCode ? ';' : '';\n optionalPropsCode = `${sep}\\n${bitMapInit}\\n${propsCode}`;\n }\n\n const canBeExpression = !requiredPropsCode && !optionalPropsCode;\n if (canBeExpression) return {code: `{${expressionsPropsCode}}`, type: 'E'};\n return {code: `${comp.vλl} = {${expressionsPropsCode}}\\n${requiredPropsCode}${optionalPropsCode}`, type: 'S'};\n }\n }\n case ReflectionKind.class:\n switch (runType.src.subKind) {\n case ReflectionSubKind.date:\n return {code: `new Date(${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8)))`, type: 'E'};\n case ReflectionSubKind.map:\n case ReflectionSubKind.set: {\n const rt = runType as IterableRunType;\n const children = rt.getJitChildren(comp);\n const vλl = rt.getCustomVλl(comp)?.vλl || comp.vλl;\n const initCode = `const ${vλl} = new ${rt.constructorName}()`;\n if (!children.length) return {code: `new ${rt.constructorName}()`, type: 'E'};\n const childrenCode = children\n .map((c) => comp.compile(c, 'S', fnID).code)\n .filter(Boolean)\n .join(';');\n if (!childrenCode) return {code: initCode, type: 'E'};\n const index = comp.getLocalVarName('itI', rt);\n const lengthVar = comp.getLocalVarName('itL', rt);\n const readLength = `const ${lengthVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4`;\n return {\n code: `${initCode}; ${readLength}; for (let ${index} = 0; ${index} < ${lengthVar}; ${index}++) {${childrenCode}} ${comp.vλl} = ${vλl};`,\n type: 'S',\n };\n }\n case ReflectionSubKind.nonSerializable:\n throw new Error('Binary deserialization disabled for Non Serializable types');\n default: {\n const rt = runType as ClassRunType;\n if (rt.isCallable()) {\n const callSignature = rt.getCallSignature();\n if (callSignature) return comp.compile(callSignature, 'S', fnID);\n }\n const originalKind = rt.src.kind;\n (runType.src as any).kind = ReflectionKind.objectLiteral;\n const plainObjCode = emitFromBinary(rt, comp);\n (runType.src as any).kind = originalKind;\n const desFnVarName = comp.getLocalVarName('desFn', rt);\n const desFnInit = `let ${desFnVarName} = utl.${getJitUtils().getDeserializeFn.name}(${toLiteral(rt.getClassName())})`;\n const desFnCode = `if (${desFnVarName}) {${comp.vλl} = ${desFnVarName}(${comp.vλl})}`;\n const desClassCode = `else if (${desFnVarName} = utl.${getJitUtils().getSerializeClass.name}(${toLiteral(rt.getClassName())})) {${comp.vλl} = new ${desFnVarName}(${comp.vλl})}`;\n const initCode = plainObjCode.type === 'E' ? `${comp.vλl} = ${plainObjCode.code}` : plainObjCode.code;\n return {code: `${initCode};${desFnInit};${desFnCode} ${desClassCode}`, type: 'S'};\n }\n }\n break;\n\n case ReflectionKind.infer:\n throw new Error('Infer is not supported in Binary deserialization');\n\n case ReflectionKind.tuple: {\n const rt = runType as TupleRunType;\n const skip = rt.skipJit(comp);\n if (skip) return {code: undefined, type: 'S'};\n const params = rt.getParamRunTypes(comp);\n\n // For function params, all params are treated as optional in binary serialization\n // This allows sending null/undefined values over the wire even if the type is not optional\n const isFnParams = runType.src.subKind === ReflectionSubKind.params;\n\n // For function params, all params are optional so we can't use fixed size\n const hasFixedSize = !isFnParams && params.every((p) => !p.isOptional() && !p.isRest());\n const initTuple = hasFixedSize ? `${comp.vλl} = new Array(${params.length});` : `${comp.vλl} = [];`;\n if (params.length === 0) return {code: initTuple, type: 'S'};\n\n // Split params into required, optional, and rest\n // For function params, all non-rest params are treated as optional\n const required = isFnParams ? [] : params.filter((p) => !p.isOptional() && !p.isRest());\n const optional = isFnParams ? params.filter((p) => !p.isRest()) : params.filter((p) => p.isOptional() && !p.isRest());\n const rest = params.filter((p) => p.isRest());\n\n // Deserialize required params first\n const requiredCode = required.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');\n\n // Deserialize optional params with bitmap (groups of 8)\n let optionalCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, true);\n const optionalParamsCode = optional\n .map((p, i) => {\n (p as any).optionalIndex = i; // set optionalIndex for use in tupleMember case\n (p as any)._bitmapVar = bitMIndexVar; // pass bitmap variable name to tupleMember case\n (p as any)._isFnParam = isFnParams; // flag to indicate this is a function param\n const paramCode = comp.compile(p, 'S', fnID).code || '';\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0 && modIndex < optional.length;\n const increaseIndex = shouldIncreaseBufferIndex ? `${bitMIndexVar}++;` : '';\n return `${paramCode} ${increaseIndex}`;\n })\n .join('');\n optionalCode = `${bitMapInit}\\n${optionalParamsCode}`;\n }\n\n // Deserialize rest params (handled as array by the rest param itself)\n const restCode = rest.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');\n\n const allCode = [requiredCode, optionalCode, restCode].filter(Boolean).join(';');\n return {code: `${initTuple}${allCode}`, type: 'S'};\n }\n case ReflectionKind.typeParameter:\n throw new Error('Type parameter not implemented in Binary deserialization');\n\n case ReflectionKind.union: {\n const rt = runType as UnionRunType;\n rt.checkAllowedChildren(comp);\n const decVar = comp.getLocalVarName('dec', rt);\n const errVarName = comp.getLocalVarName('uErr', rt);\n comp.setContextItem(errVarName, `const ${errVarName} = \"Can not binary decode union: invalid union index\"`);\n const children = rt.getJitChildren(comp);\n if (children.length > MAX_UNION_ITEMS) {\n throw new Error(\n `Binary deserialization not supported for Union with more than ${MAX_UNION_ITEMS} items.` +\n ` Found ${children.length} in ${rt.getUnionTypeNames()}`\n );\n }\n const maxIndex = children.length - 1;\n const isUint16 = maxIndex > 255;\n const readIndex = isUint16\n ? `const ${decVar} = ${dεs}.view.getUint16(${dεs}.index, 1); ${dεs}.index += 2;`\n : `const ${decVar} = ${dεs}.view.getUint8(${dεs}.index++);`;\n const ifElse = createIfElseFn();\n const itemsCode = children\n .map((unionItem) => {\n const childJit = comp.compile(unionItem, 'S', fnID);\n const isExpression = childIsExpression(childJit, unionItem);\n const code =\n isExpression && childJit.code && childJit.code !== comp.vλl\n ? `${comp.vλl} = ${childJit.code}`\n : childJit.code || '';\n const index = rt.getUnionItemIndex(comp, unionItem);\n return `${ifElse()} (${decVar} === ${index}) {${code || '/*noop*/'}}`;\n })\n .filter(Boolean);\n const childrenCode = itemsCode.join('');\n const failCode = childrenCode ? `else {throw new Error(${errVarName})}` : '';\n const code = `\n ${readIndex}\n ${childrenCode}\n ${failCode}\n `;\n return {code, type: 'S'};\n }\n\n default:\n throw new Error(`Binary deserialization not supported for ${ReflectionKind[kind]} types`);\n }\n throw new Error(`Do not know how to deserialize ${runType.getTypeName()} from Binary.`);\n}\n\nfunction getPropName(rt: PropertyRunType, comp: BinaryCompiler, isObjectConstructor: boolean): string | number {\n const isSafe = isSafePropName(rt.src.name);\n if (isObjectConstructor) return isSafe ? rt.getChildVarName(comp) : rt.getChildLiteral(comp);\n return isSafe ? `.${rt.getChildVarName(comp)}` : `[${rt.getChildLiteral(comp)}]`;\n}\n\n/** Generates bitmap reading code for optional properties/params. Uses 1 bit per optional item (8 items per byte). */\nfunction getOptionalBitmapItems(\n rt: InterfaceRunType | TupleRunType,\n comp: BinaryCompiler,\n optionalLength = 0,\n currentIndex = 0,\n isTuple = false\n) {\n const dεs = comp.args.dεs;\n const prefix = isTuple ? 't' : '';\n const bitMIndexVar = comp.getLocalVarName(`${prefix}bimI`, rt); // index of the bitmap\n const bitmapLength = Math.ceil(optionalLength / 8);\n const bitIndex = `${currentIndex} & 7`; // equivalent to index % 8\n // bitmap for present optional items\n const bitMapInit = `${bitmapLength > 1 ? 'let ' : 'const'} ${bitMIndexVar} = ${dεs}.index; ${dεs}.index += ${bitmapLength};`;\n return {bitMIndexVar, bitmapLength, bitIndex, bitMapInit};\n}\n\nfunction emitFromBinaryAs(rt: BaseRunType, comp: BinaryCompiler, kind: ReflectionKind): JitCode {\n const originalKind = rt.src.kind;\n (rt.src as any).kind = kind;\n const result = emitFromBinary(rt, comp);\n (rt.src as any).kind = originalKind;\n return result;\n}\n"],"names":["JitFunctions","ReflectionKind","toLiteral","childIsExpression","ReflectionSubKind","getJitUtils","MAX_UNION_ITEMS","createIfElseFn","code","isSafePropName"],"mappings":";;;;;;;;AA+BA,MAAM,OAAOA,wBAAAA,aAAa,WAAW;AAM9B,SAAS,eAAe,SAAsB,MAA+B;AAChF,QAAM,MAAM,QAAQ;AACpB,QAAM,OAAO,IAAI;AACjB,QAAM,MAAM,KAAK,KAAK;AAMtB,UAAQ,MAAA;AAAA;AAAA,IAEJ,KAAKC,KAAAA,eAAe;AAAA,IACpB,KAAKA,KAAAA,eAAe,KAAK;AAErB,aAAO,EAAC,MAAM,cAAc,GAAG,iBAAiB,MAAM,IAAA;AAAA,IAC1D;AAAA,IACA,KAAKA,KAAAA,eAAe;AAChB,aAAO,EAAC,MAAM,IAAI,GAAG,mBAAmB,MAAM,IAAA;AAAA,IAClD,KAAKA,KAAAA,eAAe;AAChB,aAAO,EAAC,MAAM,GAAG,GAAG,kBAAkB,GAAG,mBAAmB,MAAM,IAAA;AAAA,IACtE,KAAKA,KAAAA,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GAAG,oBAAoB,GAAG,eAAe,GAAG,iBAAiB,MAAM,IAAA;AAAA,IACxF;AAAA,IACA,KAAKA,KAAAA,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GAAG,gBAAgB,MAAM,IAAA;AAAA,IAC9C;AAAA,IACA,KAAKA,KAAAA,eAAe,QAAQ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eAAe,KAAK,gBAAgB,GAAG,MAAM,QAAQ,EAAE;AAC7D,QAAM,eAAe,KAAK,KAAK,iBAAiB,CAAC;AACjD,QAAM,WAAW,GAAG,YAAY;AAEhC,QAAM,aAAa,GAAG,eAAe,IAAI,SAAS,OAAO,IAAI,YAAY,MAAM,GAAG,WAAW,GAAG,aAAa,YAAY;AACzH,SAAO,EAAC,cAAc,cAAc,UAAU,WAAA;AAClD;AAEA,SAAS,iBAAiB,IAAiB,MAAsB,MAA+B;AAC5F,QAAM,eAAe,GAAG,IAAI;AAC3B,KAAG,IAAY,OAAO;AACvB,QAAM,SAAS,eAAe,IAAI,IAAI;AACrC,KAAG,IAAY,OAAO;AACvB,SAAO;AACX;;"}
1
+ {"version":3,"file":"fromBinary.cjs","sources":["../../../../../src/jitCompilers/binary/fromBinary.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport {getJitUtils} from '@mionjs/core';\nimport {ReflectionSubKind} from '../../constants.kind.ts';\nimport {childIsExpression, createIfElseFn, isSafePropName, toLiteral} from '../../lib/utils.ts';\nimport {jitBinaryDeserializerArgs, JitFunctions} from '../../constants.functions.ts';\nimport {MAX_UNION_ITEMS} from '../../constants.ts';\nimport type {JitCode} from '../../types.ts';\nimport type {BaseRunType} from '../../lib/baseRunTypes.ts';\nimport {type BaseFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport type {LiteralRunType} from '../../nodes/atomic/literal.ts';\nimport type {ArrayRunType} from '../../nodes/member/array.ts';\nimport type {PropertyRunType} from '../../nodes/member/property.ts';\nimport type {InterfaceRunType} from '../../nodes/collection/interface.ts';\nimport type {IndexSignatureRunType} from '../../nodes/member/indexProperty.ts';\nimport type {ClassRunType} from '../../nodes/collection/class.ts';\nimport type {TupleRunType} from '../../nodes/collection/tuple.ts';\nimport type {ParameterRunType} from '../../nodes/member/param.ts';\nimport type {RestParamsRunType} from '../../nodes/member/restParams.ts';\nimport type {UnionRunType} from '../../nodes/collection/union.ts';\nimport type {IterableRunType} from '../../nodes/native/Iterable.ts';\nimport type {MapRunType} from '../../nodes/native/map.ts';\n\ntype BinaryCompiler = BaseFnCompiler<typeof jitBinaryDeserializerArgs, typeof JitFunctions.fromBinary.id>;\n\nconst fnID = JitFunctions.fromBinary.id;\n\n/**\n * Main Binary deserialization compiler function\n * Generates JIT code to deserialize Binary data to JavaScript values\n */\nexport function emitFromBinary(runType: BaseRunType, comp: BinaryCompiler): JitCode {\n const src = runType.src;\n const kind = src.kind;\n const dεs = comp.args.dεs;\n\n // hack is used in some case to increase the index passing an extra argument to view.get methods\n // ie: view.getUint32(index, littleEndian, index += 4);\n // 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\n\n switch (kind) {\n // ###################### ATOMIC TYPES ######################\n case ReflectionKind.unknown:\n case ReflectionKind.any: {\n // any is deserialized from json string\n return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};\n }\n case ReflectionKind.null:\n return {code: `(${dεs}.index++, null)`, type: 'E'};\n case ReflectionKind.boolean:\n return {code: `${dεs}.view.getUint8(${dεs}.index++) === 1`, type: 'E'};\n case ReflectionKind.number: {\n return {code: `${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8))`, type: 'E'};\n }\n case ReflectionKind.string: {\n return {code: `${dεs}.desString()`, type: 'E'};\n }\n case ReflectionKind.bigint: {\n return {code: `BigInt(${dεs}.desString(true))`, type: 'E'};\n }\n case ReflectionKind.undefined:\n case ReflectionKind.void:\n return {code: `(${dεs}.index++, undefined)`, type: 'E'};\n case ReflectionKind.symbol: {\n return {code: `Symbol(${dεs}.desString() || undefined)`, type: 'E'};\n }\n case ReflectionKind.regexp: {\n return {code: `new RegExp(${dεs}.desString(), ${dεs}.desString())`, type: 'E'};\n }\n case ReflectionKind.object:\n // similar to any, this is deserialized as json string\n return {code: `JSON.parse(${dεs}.desString())`, type: 'E'};\n case ReflectionKind.enum: {\n return {code: `${dεs}.desEnum()`, type: 'E'};\n }\n case ReflectionKind.enumMember:\n throw new Error('Binary deserialization not supported for enum member types');\n case ReflectionKind.never:\n throw new Error('Never type cannot be deserialized from Binary');\n case ReflectionKind.templateLiteral:\n // runtime value is a plain string\n return {code: `${dεs}.desString()`, type: 'E'};\n case ReflectionKind.literal: {\n if (comp.opts.noLiterals) {\n const lit = (runType as LiteralRunType).src.literal;\n if (lit instanceof RegExp) return emitFromBinaryAs(runType, comp, ReflectionKind.regexp);\n switch (typeof lit) {\n case 'string':\n return emitFromBinaryAs(runType, comp, ReflectionKind.string);\n case 'number':\n return emitFromBinaryAs(runType, comp, ReflectionKind.number);\n case 'boolean':\n return emitFromBinaryAs(runType, comp, ReflectionKind.boolean);\n case 'bigint':\n return emitFromBinaryAs(runType, comp, ReflectionKind.bigint);\n case 'symbol':\n return emitFromBinaryAs(runType, comp, ReflectionKind.symbol);\n default:\n throw new Error(`Unsupported literal type ${typeof lit}`);\n }\n }\n return {code: toLiteral((runType as LiteralRunType).src.literal), type: 'E'};\n }\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.rest: // rest params are deserialized as array but start at rest item index\n case ReflectionKind.array: {\n const rt = runType as ArrayRunType | RestParamsRunType;\n rt.checkNonSkipTypes(comp);\n const child = rt.getMemberType()!;\n const childCode = comp.compile(child, 'S', fnID);\n if (!childCode?.code) throw new Error(`Do not know how to deserialize Array<${child.getTypeName()}> from Binary.`);\n const isRest = rt.src.kind === ReflectionKind.rest;\n const index = rt.getChildVarName(comp);\n const isExpression = childIsExpression(childCode, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childCode.code};` : childCode.code;\n // deserialized from [length, items...]\n const lengthVal = comp.getLocalVarName('arrL', rt);\n const arrayInit = isRest ? '' : `${comp.vλl} = new Array(${lengthVal})`; // res array already initialized in parent\n return {\n code: `\n const ${lengthVal} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${arrayInit};\n for (let ${index} = ${rt.startIndex(comp)}; ${index} < ${lengthVal}; ${index}++) {${code}}\n `,\n type: 'S',\n };\n }\n\n case ReflectionKind.indexSignature: {\n const rt = runType as IndexSignatureRunType;\n const indexKind = (rt.src as any).index?.kind;\n const memberCode = comp.compile(rt.getJitChild(comp), 'S', fnID);\n if (!memberCode?.code) return {code: undefined, type: 'E'};\n\n const prop = rt.getChildVarName(comp);\n const countVar = comp.getLocalVarName('cnt', rt);\n const indexVar = comp.getLocalVarName('propI', rt);\n\n // Deserialize key based on index type\n let keyDeserializationCode: string;\n if (indexKind === ReflectionKind.number) {\n // For number indices, deserialize as uint32\n keyDeserializationCode = `const ${prop} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4;`;\n } else {\n // For string indices, deserialize as string with prototype pollution protection\n keyDeserializationCode = `const ${prop} = ${dεs}.desSafePropName();`;\n }\n\n const memberInit = memberCode.type === 'E' ? `${comp.vλl}[${prop}] = ${memberCode.code};` : memberCode.code;\n const deserializeCode = `for (let ${indexVar} = 0; ${indexVar} < ${countVar}; ${indexVar}++) {${keyDeserializationCode}${memberInit}}`;\n\n return {\n code: `const ${countVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4; ${comp.vλl} = {}; ${deserializeCode}`,\n type: 'S',\n };\n }\n\n case ReflectionKind.function:\n case ReflectionKind.method:\n case ReflectionKind.methodSignature:\n case ReflectionKind.callSignature:\n if (runType.src.subKind === ReflectionSubKind.params) {\n return emitFromBinaryAs(runType, comp, ReflectionKind.tuple);\n } else {\n throw new Error(\n 'Binary deserialization not supported for functions, call compileParams or compileReturn instead.'\n );\n }\n\n case ReflectionKind.parameter: {\n const rt = runType as ParameterRunType;\n switch (src.subKind) {\n case ReflectionSubKind.mapKey:\n case ReflectionSubKind.mapValue:\n case ReflectionSubKind.setItem: {\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n if (!childJit?.code || !child)\n throw new Error(`Do not know how to deserialize ${rt.getTypeName()} from Binary.`);\n const parent = rt.getParent()!;\n const parentVλl = parent.getCustomVλl(comp)?.vλl || comp.vλl;\n const vλl = rt.getCustomVλl(comp)?.vλl;\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `const ${vλl} = ${childJit.code};` : childJit.code || '';\n let setOperation = '';\n switch (rt.src.subKind) {\n case ReflectionSubKind.mapKey:\n break; // we set map item once we have the key and value\n case ReflectionSubKind.mapValue: {\n const mapKey = (parent as MapRunType).getMapKeyVλl(comp); // not the best solution but works\n setOperation = `${parentVλl}.set(${mapKey}, ${vλl})`;\n break;\n }\n case ReflectionSubKind.setItem:\n setOperation = `${parentVλl}.add(${vλl})`;\n break;\n }\n return {code: `${code}; ${setOperation};`, type: 'S'};\n }\n default:\n return emitFromBinaryAs(runType, comp, ReflectionKind.tupleMember);\n }\n }\n\n case ReflectionKind.property:\n case ReflectionKind.propertySignature: {\n const rt = runType as PropertyRunType;\n const parent = rt.getParent() as InterfaceRunType;\n const child = rt.getJitChild(comp)!;\n const childJit = comp.compile(child, 'S', fnID);\n if (rt.isOptional()) {\n const {bitMIndexVar, bitIndex} = getOptionalBitmapItems(parent, comp, 0, rt.optionalIndex, false);\n const initCode = childJit.type === 'E' ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code;\n return {\n code: `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`,\n type: 'S',\n };\n }\n // block or statements code are initialized as obj.a = deserializeA; obj.b = deserializeB; after initial object has been created\n const isExpression = childIsExpression(childJit, child);\n if (!isExpression) {\n return childJit; // block statements already include variable assignment\n }\n // required props that are simple expressions code are part of an object constructor {a: deserializeA, b: deserializeB, c: deserializeC}\n const propName = getPropName(rt, comp, true);\n return {code: `${propName}:${childJit?.code}`, type: 'E'};\n }\n\n case ReflectionKind.tupleMember: {\n const rt = runType as ParameterRunType;\n const childJit = comp.compile(rt.getJitChild(comp), 'S', fnID);\n const nullJIt = emitFromBinaryAs(rt, comp, ReflectionKind.undefined);\n const itemJit = childJit?.code ? childJit : nullJIt; // if child is not serializable, we serialize null as need to fill the space in the tuple\n const initCode = itemJit.type === 'E' ? `${comp.getChildVλl()} = ${itemJit.code}` : itemJit.code;\n if (rt.isRest()) return itemJit;\n // Optional handling uses bitmap set at tuple level\n const optionalIndex = (rt as any).optionalIndex;\n const bitMIndexVar = (rt as any)._bitmapVar;\n const isFnParam = (rt as any)._isFnParam;\n // Treat as optional if either isOptional() is true OR it's a function param (all fn params are optional in binary)\n const isOptional = rt.isOptional() || isFnParam;\n if (isOptional && optionalIndex !== undefined && bitMIndexVar) {\n const bitIndex = optionalIndex & 7; // equivalent to optionalIndex % 8\n const code = `if (${dεs}.view.getUint8(${bitMIndexVar}, 1) & (1 << (${bitIndex}))) {${initCode}}`;\n return {code, type: 'S'};\n }\n return {code: initCode, type: 'S'};\n }\n case ReflectionKind.promise:\n throw new Error('Jit compilation disabled for Non Serializable types.');\n\n // ###################### COLLECTION RUNTYPES ######################\n // Types that contain other types as members\n case ReflectionKind.objectLiteral:\n case ReflectionKind.intersection: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) return comp.compile(rt.getCallSignature(), 'S', fnID);\n if (runType.src.subKind === ReflectionSubKind.nonSerializable) {\n throw new Error('Binary deserialization is disabled for Non Serializable types');\n } else {\n const {required, optional, indexSignatures} = rt.splitJitSplitChildren(comp);\n if (indexSignatures.length) {\n return comp.compile(indexSignatures[0], 'S', fnID); // index signature code already contains the loop\n }\n\n // required props that are simple expressions are restored as: '{a: deserializeA, b: deserializeB, c: deserializeC};\n // and are serialized/deserialised in the same order they are declared in the type\n const requiredItemsJit = required.map((prop) => comp.compile(prop, 'S', fnID));\n const expressionItemsJit = requiredItemsJit\n .filter((childJit, i) => childIsExpression(childJit, required[i]))\n .map((prop) => prop.code)\n .filter(Boolean);\n const statementItemsCode = requiredItemsJit\n .filter(Boolean)\n .filter((childJit, i) => !childIsExpression(childJit, required[i]))\n .map((prop) => prop.code);\n const expressionsPropsCode = expressionItemsJit.join(',');\n const requiredPropsCode = statementItemsCode.join(';');\n\n // optional props are initialized as obj.a = deserializeA; obj.b = deserializeB; obj.c = deserializeC;\n // bitmap is used to determine which optional props are present\n // header format: [bitmap, optional props]\n let optionalPropsCode = '';\n if (optional.length) {\n // optional properties are restored using a loop\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, false);\n const propsCode = optional\n .map((prop, i) => {\n prop.optionalIndex = i;\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0;\n const propCode = comp.compile(prop, 'S', fnID).code;\n if (!shouldIncreaseBufferIndex) return propCode;\n // every 8 props we need to increase the bitmap index\n return `${propCode} ${bitMIndexVar}++; `;\n })\n .filter(Boolean)\n .join('');\n const sep = requiredPropsCode ? ';' : '';\n optionalPropsCode = `${sep}\\n${bitMapInit}\\n${propsCode}`;\n }\n\n const canBeExpression = !requiredPropsCode && !optionalPropsCode;\n if (canBeExpression) return {code: `{${expressionsPropsCode}}`, type: 'E'};\n return {code: `${comp.vλl} = {${expressionsPropsCode}}\\n${requiredPropsCode}${optionalPropsCode}`, type: 'S'};\n }\n }\n case ReflectionKind.class:\n switch (runType.src.subKind) {\n case ReflectionSubKind.date:\n return {code: `new Date(${dεs}.view.getFloat64(${dεs}.index, 1, (${dεs}.index += 8)))`, type: 'E'};\n case ReflectionSubKind.map:\n case ReflectionSubKind.set: {\n const rt = runType as IterableRunType;\n const children = rt.getJitChildren(comp);\n const vλl = rt.getCustomVλl(comp)?.vλl || comp.vλl;\n const initCode = `const ${vλl} = new ${rt.constructorName}()`;\n if (!children.length) return {code: `new ${rt.constructorName}()`, type: 'E'};\n const childrenCode = children\n .map((c) => comp.compile(c, 'S', fnID).code)\n .filter(Boolean)\n .join(';');\n if (!childrenCode) return {code: initCode, type: 'E'};\n const index = comp.getLocalVarName('itI', rt);\n const lengthVar = comp.getLocalVarName('itL', rt);\n const readLength = `const ${lengthVar} = ${dεs}.view.getUint32(${dεs}.index, 1); ${dεs}.index += 4`;\n return {\n code: `${initCode}; ${readLength}; for (let ${index} = 0; ${index} < ${lengthVar}; ${index}++) {${childrenCode}} ${comp.vλl} = ${vλl};`,\n type: 'S',\n };\n }\n case ReflectionSubKind.nonSerializable:\n throw new Error('Binary deserialization disabled for Non Serializable types');\n default: {\n const rt = runType as ClassRunType;\n if (rt.isCallable()) {\n const callSignature = rt.getCallSignature();\n if (callSignature) return comp.compile(callSignature, 'S', fnID);\n }\n const originalKind = rt.src.kind;\n (runType.src as any).kind = ReflectionKind.objectLiteral;\n const plainObjCode = emitFromBinary(rt, comp);\n (runType.src as any).kind = originalKind;\n const desFnVarName = comp.getLocalVarName('desFn', rt);\n const desFnInit = `let ${desFnVarName} = utl.${getJitUtils().getDeserializeFn.name}(${toLiteral(rt.getClassName())})`;\n const desFnCode = `if (${desFnVarName}) {${comp.vλl} = ${desFnVarName}(${comp.vλl})}`;\n const desClassCode = `else if (${desFnVarName} = utl.${getJitUtils().getSerializeClass.name}(${toLiteral(rt.getClassName())})) {${comp.vλl} = new ${desFnVarName}(${comp.vλl})}`;\n const initCode = plainObjCode.type === 'E' ? `${comp.vλl} = ${plainObjCode.code}` : plainObjCode.code;\n return {code: `${initCode};${desFnInit};${desFnCode} ${desClassCode}`, type: 'S'};\n }\n }\n break;\n\n case ReflectionKind.infer:\n throw new Error('Infer is not supported in Binary deserialization');\n\n case ReflectionKind.tuple: {\n const rt = runType as TupleRunType;\n const skip = rt.skipJit(comp);\n if (skip) return {code: undefined, type: 'S'};\n const params = rt.getParamRunTypes(comp);\n\n // For function params, all params are treated as optional in binary serialization\n // This allows sending null/undefined values over the wire even if the type is not optional\n const isFnParams = runType.src.subKind === ReflectionSubKind.params;\n\n // For function params, all params are optional so we can't use fixed size\n const hasFixedSize = !isFnParams && params.every((p) => !p.isOptional() && !p.isRest());\n const initTuple = hasFixedSize ? `${comp.vλl} = new Array(${params.length});` : `${comp.vλl} = [];`;\n if (params.length === 0) return {code: initTuple, type: 'S'};\n\n // Split params into required, optional, and rest\n // For function params, all non-rest params are treated as optional\n const required = isFnParams ? [] : params.filter((p) => !p.isOptional() && !p.isRest());\n const optional = isFnParams ? params.filter((p) => !p.isRest()) : params.filter((p) => p.isOptional() && !p.isRest());\n const rest = params.filter((p) => p.isRest());\n\n // Deserialize required params first\n const requiredCode = required.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');\n\n // Deserialize optional params with bitmap (groups of 8)\n let optionalCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, true);\n const optionalParamsCode = optional\n .map((p, i) => {\n (p as any).optionalIndex = i; // set optionalIndex for use in tupleMember case\n (p as any)._bitmapVar = bitMIndexVar; // pass bitmap variable name to tupleMember case\n (p as any)._isFnParam = isFnParams; // flag to indicate this is a function param\n const paramCode = comp.compile(p, 'S', fnID).code || '';\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0 && modIndex < optional.length;\n const increaseIndex = shouldIncreaseBufferIndex ? `${bitMIndexVar}++;` : '';\n return `${paramCode} ${increaseIndex}`;\n })\n .join('');\n optionalCode = `${bitMapInit}\\n${optionalParamsCode}`;\n }\n\n // Deserialize rest params (handled as array by the rest param itself)\n const restCode = rest.map((p) => comp.compile(p, 'S', fnID).code || '').join(';');\n\n const allCode = [requiredCode, optionalCode, restCode].filter(Boolean).join(';');\n return {code: `${initTuple}${allCode}`, type: 'S'};\n }\n case ReflectionKind.typeParameter:\n throw new Error('Type parameter not implemented in Binary deserialization');\n\n case ReflectionKind.union: {\n const rt = runType as UnionRunType;\n rt.checkAllowedChildren(comp);\n const decVar = comp.getLocalVarName('dec', rt);\n const errVarName = comp.getLocalVarName('uErr', rt);\n comp.setContextItem(errVarName, `const ${errVarName} = \"Can not binary decode union: invalid union index\"`);\n const children = rt.getJitChildren(comp);\n if (children.length > MAX_UNION_ITEMS) {\n throw new Error(\n `Binary deserialization not supported for Union with more than ${MAX_UNION_ITEMS} items.` +\n ` Found ${children.length} in ${rt.getUnionTypeNames()}`\n );\n }\n const maxIndex = children.length - 1;\n const isUint16 = maxIndex > 255;\n const readIndex = isUint16\n ? `const ${decVar} = ${dεs}.view.getUint16(${dεs}.index, 1); ${dεs}.index += 2;`\n : `const ${decVar} = ${dεs}.view.getUint8(${dεs}.index++);`;\n const ifElse = createIfElseFn();\n const itemsCode = children\n .map((unionItem) => {\n const childJit = comp.compile(unionItem, 'S', fnID);\n const isExpression = childIsExpression(childJit, unionItem);\n const code =\n isExpression && childJit.code && childJit.code !== comp.vλl\n ? `${comp.vλl} = ${childJit.code}`\n : childJit.code || '';\n const index = rt.getUnionItemIndex(comp, unionItem);\n return `${ifElse()} (${decVar} === ${index}) {${code || '/*noop*/'}}`;\n })\n .filter(Boolean);\n const childrenCode = itemsCode.join('');\n const failCode = childrenCode ? `else {throw new Error(${errVarName})}` : '';\n const code = `\n ${readIndex}\n ${childrenCode}\n ${failCode}\n `;\n return {code, type: 'S'};\n }\n\n default:\n throw new Error(`Binary deserialization not supported for ${ReflectionKind[kind]} types`);\n }\n throw new Error(`Do not know how to deserialize ${runType.getTypeName()} from Binary.`);\n}\n\nfunction getPropName(rt: PropertyRunType, comp: BinaryCompiler, isObjectConstructor: boolean): string | number {\n const isSafe = isSafePropName(rt.src.name);\n if (isObjectConstructor) return isSafe ? rt.getChildVarName(comp) : rt.getChildLiteral(comp);\n return isSafe ? `.${rt.getChildVarName(comp)}` : `[${rt.getChildLiteral(comp)}]`;\n}\n\n/** Generates bitmap reading code for optional properties/params. Uses 1 bit per optional item (8 items per byte). */\nfunction getOptionalBitmapItems(\n rt: InterfaceRunType | TupleRunType,\n comp: BinaryCompiler,\n optionalLength = 0,\n currentIndex = 0,\n isTuple = false\n) {\n const dεs = comp.args.dεs;\n const prefix = isTuple ? 't' : '';\n const bitMIndexVar = comp.getLocalVarName(`${prefix}bimI`, rt); // index of the bitmap\n const bitmapLength = Math.ceil(optionalLength / 8);\n const bitIndex = `${currentIndex} & 7`; // equivalent to index % 8\n // bitmap for present optional items\n const bitMapInit = `${bitmapLength > 1 ? 'let ' : 'const'} ${bitMIndexVar} = ${dεs}.index; ${dεs}.index += ${bitmapLength};`;\n return {bitMIndexVar, bitmapLength, bitIndex, bitMapInit};\n}\n\nfunction emitFromBinaryAs(rt: BaseRunType, comp: BinaryCompiler, kind: ReflectionKind): JitCode {\n const originalKind = rt.src.kind;\n (rt.src as any).kind = kind;\n const result = emitFromBinary(rt, comp);\n (rt.src as any).kind = originalKind;\n return result;\n}\n"],"names":["JitFunctions","ReflectionKind","toLiteral","childIsExpression","ReflectionSubKind","getJitUtils","MAX_UNION_ITEMS","createIfElseFn","code","isSafePropName"],"mappings":";;;;;;;;AA+BA,MAAM,OAAOA,wBAAAA,aAAa,WAAW;AAM9B,SAAS,eAAe,SAAsB,MAA+B;AAChF,QAAM,MAAM,QAAQ;AACpB,QAAM,OAAO,IAAI;AACjB,QAAM,MAAM,KAAK,KAAK;AAMtB,UAAQ,MAAA;AAAA;AAAA,IAEJ,KAAKC,KAAAA,eAAe;AAAA,IACpB,KAAKA,KAAAA,eAAe,KAAK;AAErB,aAAO,EAAC,MAAM,cAAc,GAAG,iBAAiB,MAAM,IAAA;AAAA,IAC1D;AAAA,IACA,KAAKA,KAAAA,eAAe;AAChB,aAAO,EAAC,MAAM,IAAI,GAAG,mBAAmB,MAAM,IAAA;AAAA,IAClD,KAAKA,KAAAA,eAAe;AAChB,aAAO,EAAC,MAAM,GAAG,GAAG,kBAAkB,GAAG,mBAAmB,MAAM,IAAA;AAAA,IACtE,KAAKA,KAAAA,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GAAG,oBAAoB,GAAG,eAAe,GAAG,iBAAiB,MAAM,IAAA;AAAA,IACxF;AAAA,IACA,KAAKA,KAAAA,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GA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GACjB,eAAe,GACf,UAAU,OACZ;AACE,QAAM,MAAM,KAAK,KAAK;AACtB,QAAM,SAAS,UAAU,MAAM;AAC/B,QAAM,eAAe,KAAK,gBAAgB,GAAG,MAAM,QAAQ,EAAE;AAC7D,QAAM,eAAe,KAAK,KAAK,iBAAiB,CAAC;AACjD,QAAM,WAAW,GAAG,YAAY;AAEhC,QAAM,aAAa,GAAG,eAAe,IAAI,SAAS,OAAO,IAAI,YAAY,MAAM,GAAG,WAAW,GAAG,aAAa,YAAY;AACzH,SAAO,EAAC,cAAc,cAAc,UAAU,WAAA;AAClD;AAEA,SAAS,iBAAiB,IAAiB,MAAsB,MAA+B;AAC5F,QAAM,eAAe,GAAG,IAAI;AAC3B,KAAG,IAAY,OAAO;AACvB,QAAM,SAAS,eAAe,IAAI,IAAI;AACrC,KAAG,IAAY,OAAO;AACvB,SAAO;AACX;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"fromBinary.d.ts","sourceRoot":"","sources":["../../../../../src/jitCompilers/binary/fromBinary.ts"],"names":[],"mappings":"AAWA,OAAO,EAAC,yBAAyB,EAAE,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAErF,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,KAAK,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAc/D,KAAK,cAAc,GAAG,cAAc,CAAC,OAAO,yBAAyB,EAAE,OAAO,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAQ1G,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAsalF"}
1
+ {"version":3,"file":"fromBinary.d.ts","sourceRoot":"","sources":["../../../../../src/jitCompilers/binary/fromBinary.ts"],"names":[],"mappings":"AAWA,OAAO,EAAC,yBAAyB,EAAE,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAErF,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,KAAK,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAc/D,KAAK,cAAc,GAAG,cAAc,CAAC,OAAO,yBAAyB,EAAE,OAAO,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAQ1G,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAualF"}
@@ -48,7 +48,7 @@ function emitToBinary(runType, comp) {
48
48
  case type.ReflectionKind.never:
49
49
  throw new Error("Never type cannot be serialized to Binary");
50
50
  case type.ReflectionKind.templateLiteral:
51
- throw new Error("Template literals are not supported in Binary serialization");
51
+ return { code: `${sεr}.serString(${comp.vλl})`, type: "S" };
52
52
  case type.ReflectionKind.literal: {
53
53
  if (comp.opts.noLiterals) {
54
54
  const lit = runType.src.literal;
@@ -1 +1 @@
1
- {"version":3,"file":"toBinary.cjs","sources":["../../../../../src/jitCompilers/binary/toBinary.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport {ReflectionSubKind} from '../../constants.kind.ts';\nimport {jitBinarySerializerArgs, JitFunctions} from '../../constants.functions.ts';\nimport {createIfElseFn} from '../../lib/utils.ts';\nimport {MAX_UNION_ITEMS} from '../../constants.ts';\nimport type {JitCode} from '../../types.ts';\nimport type {BaseRunType} from '../../lib/baseRunTypes.ts';\nimport type {BaseFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport type {ArrayRunType} from '../../nodes/member/array.ts';\nimport type {PropertyRunType} from '../../nodes/member/property.ts';\nimport type {InterfaceRunType} from '../../nodes/collection/interface.ts';\nimport type {IndexSignatureRunType} from '../../nodes/member/indexProperty.ts';\nimport type {ParameterRunType} from '../../nodes/member/param.ts';\nimport type {TupleRunType} from '../../nodes/collection/tuple.ts';\nimport type {UnionRunType} from '../../nodes/collection/union.ts';\nimport type {IterableRunType} from '../../nodes/native/Iterable.ts';\nimport type {LiteralRunType} from '../../nodes/atomic/literal.ts';\n\ntype BinaryCompiler = BaseFnCompiler<typeof jitBinarySerializerArgs, typeof JitFunctions.toBinary.id>;\nconst fnID = JitFunctions.toBinary.id;\n\n/**\n * Main Binary serialization compiler function\n * Generates JIT code to serialize values to Binary format following Binary 1.1 specification\n *\n * This function generates JavaScript expressions that return Uint8Array containing Binary bytes.\n */\nexport function emitToBinary(runType: BaseRunType, comp: BinaryCompiler): JitCode {\n const src = runType.src;\n const kind = src.kind;\n const sεr = comp.args.sεr;\n\n // hack is used in some case to increase the index passing an extra argument to view.set methods\n // ie: view.setUint32(index, value, littleEndian, index += 4);\n // setUint32 only accepts 3 arguments, but we use the 4rd one to increase the index on a single statement so code can be used as an expression\n\n switch (kind) {\n // ###################### ATOMIC TYPES ######################\n case ReflectionKind.unknown:\n case ReflectionKind.any: {\n // any is serialized as json string\n return {code: `${sεr}.serString(JSON.stringify(${comp.vλl}))`, type: 'S'};\n }\n case ReflectionKind.null:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, 0)`, type: 'S'};\n case ReflectionKind.boolean:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, !!${comp.vλl})`, type: 'S'};\n case ReflectionKind.number: {\n return {code: `${sεr}.view.setFloat64(${sεr}.index,${comp.vλl}, 1, (${sεr}.index += 8))`, type: 'S'};\n }\n case ReflectionKind.string: {\n return {code: `${sεr}.serString(${comp.vλl})`, type: 'S'};\n }\n case ReflectionKind.bigint: {\n return {code: `${sεr}.serString(${comp.vλl}.toString(), true)`, type: 'S'};\n }\n case ReflectionKind.undefined:\n case ReflectionKind.void:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, 1)`, type: 'S'};\n case ReflectionKind.symbol: {\n return {code: `${sεr}.serString(${comp.vλl}.description || '')`, type: 'S'};\n }\n case ReflectionKind.regexp: {\n return {code: `${sεr}.serString(${comp.vλl}.source);${sεr}.serString(${comp.vλl}.flags)`, type: 'S'};\n }\n case ReflectionKind.object:\n // similar to any, this is serialized as json string\n return {code: `${sεr}.serString(JSON.stringify(${comp.vλl}))`, type: 'S'};\n case ReflectionKind.enum: {\n return {code: `${sεr}.serEnum(${comp.vλl})`, type: 'S'};\n }\n case ReflectionKind.enumMember:\n throw new Error('Binary serialization not supported for enum member types');\n case ReflectionKind.never:\n throw new Error('Never type cannot be serialized to Binary');\n case ReflectionKind.templateLiteral:\n throw new Error('Template literals are not supported in Binary serialization');\n case ReflectionKind.literal: {\n if (comp.opts.noLiterals) {\n const lit = (runType as LiteralRunType).src.literal;\n if (lit instanceof RegExp) return emitToBinaryAs(runType, comp, ReflectionKind.regexp);\n switch (typeof lit) {\n case 'string':\n return emitToBinaryAs(runType, comp, ReflectionKind.string);\n case 'number':\n return emitToBinaryAs(runType, comp, ReflectionKind.number);\n case 'boolean':\n return emitToBinaryAs(runType, comp, ReflectionKind.boolean);\n case 'bigint':\n return emitToBinaryAs(runType, comp, ReflectionKind.bigint);\n case 'symbol':\n return emitToBinaryAs(runType, comp, ReflectionKind.symbol);\n default:\n throw new Error(`Unsupported literal type ${typeof lit}`);\n }\n }\n return {code: '', type: 'S'}; // literals can be skipped as we restore the value directly from runType in jit code\n }\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.rest: // rest params are serialized as array but start at rest item index\n case ReflectionKind.array: {\n const rt = runType as ArrayRunType;\n rt.checkNonSkipTypes(comp);\n const child = rt.getMemberType()!;\n const memberJit = comp.compile(child, 'S', fnID);\n if (!memberJit?.code) throw new Error(`Do not know how to serialize Array<${child.getTypeName()}> to Binary.`);\n const index = rt.getChildVarName(comp);\n // serialized as [length, items...]\n return {\n code: `\n ${sεr}.view.setUint32(${sεr}.index, ${comp.vλl}.length, 1); ${sεr}.index += 4;\n for (let ${index} = ${rt.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${memberJit.code}}\n `,\n type: 'S',\n };\n }\n case ReflectionKind.indexSignature: {\n const rt = runType as IndexSignatureRunType;\n const indexKind = (rt.src as any).index?.kind;\n const memberJit = comp.compile(rt.getJitChild(comp), 'S', fnID);\n if (!memberJit?.code) return {code: undefined, type: 'S'};\n\n const propVar = rt.getChildVarName(comp);\n const lengthVar = comp.getLocalVarName('cnt', rt);\n const indexVar = comp.getLocalVarName('piI', rt);\n const varsInit = `let ${lengthVar} = 0; const ${indexVar} = ${sεr}.index; ${sεr}.index += 4;`;\n\n // Serialize entries\n let keySerializationCode: string;\n if (indexKind === ReflectionKind.number) {\n keySerializationCode = `${sεr}.view.setUint32(${sεr}.index , Number(${propVar}), 1); ${sεr}.index += 4;`;\n } else {\n keySerializationCode = `${sεr}.serString(${propVar});`;\n }\n\n return {\n code: `\n ${varsInit};\n for (const ${propVar} in ${comp.vλl}) {${keySerializationCode} ${memberJit.code}; ${lengthVar}++;}\n ${sεr}.view.setUint32(${indexVar}, ${lengthVar}, 1);\n `,\n type: 'S',\n };\n }\n\n case ReflectionKind.function:\n case ReflectionKind.method:\n case ReflectionKind.methodSignature:\n case ReflectionKind.callSignature:\n if (runType.src.subKind === ReflectionSubKind.params) {\n return emitToBinaryAs(runType, comp, ReflectionKind.tuple);\n } else {\n throw new Error('Binary serialization not supported for functions, call compileParams or compileReturn instead.');\n }\n case ReflectionKind.parameter: {\n const rt = runType as ParameterRunType;\n switch (src.subKind) {\n case ReflectionSubKind.mapKey:\n case ReflectionSubKind.mapValue:\n case ReflectionSubKind.setItem: {\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n if (!childJit?.code) throw new Error(`Do not know how to serialize ${rt.getTypeName()} to Binary.`);\n return childJit;\n }\n default: {\n return emitToBinaryAs(runType, comp, ReflectionKind.tupleMember);\n }\n }\n }\n case ReflectionKind.property:\n case ReflectionKind.propertySignature: {\n const rt = runType as PropertyRunType;\n const parent = rt.getParent() as InterfaceRunType;\n if (parent.hasIndexSignature(comp)) return {code: undefined, type: 'S'}; // all serialization is done by index signature code\n\n const memberCode = comp.compile(rt.getJitChild(comp), 'S', fnID).code || '';\n if (rt.isOptional()) {\n const {bitMIndexVar, bitIndex} = getOptionalBitmapItems(parent, comp, 0, rt.optionalIndex, false);\n const setBitMask = `${sεr}.setBitMask(${bitMIndexVar}, ${bitIndex})`;\n return {code: `if (${comp.getChildVλl()} !== undefined) {${memberCode};${setBitMask}}`, type: 'S'};\n }\n // non optional properties rely in the order they are defined in the type so no need to include the index\n return {code: `${memberCode}`, type: 'S'};\n }\n case ReflectionKind.tupleMember: {\n const rt = runType as ParameterRunType;\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n const nullJIt = emitToBinaryAs(rt, comp, ReflectionKind.undefined);\n const itemJit = childJit?.code ? childJit : nullJIt; // if child is not serializable, we serialize null as need to fill the space in the tuple\n if (rt.isRest()) return itemJit;\n // Optional handling uses bitmap set at tuple level\n const optionalIndex = (rt as any).optionalIndex;\n const bitMIndexVar = (rt as any)._bitmapVar;\n const isFnParam = (rt as any)._isFnParam;\n // Treat as optional if either isOptional() is true OR it's a function param (all fn params are optional in binary)\n const isOptional = rt.isOptional() || isFnParam;\n if (isOptional && optionalIndex !== undefined && bitMIndexVar) {\n const bitIndex = optionalIndex & 7; // equivalent to optionalIndex % 8\n const setBitMask = `${sεr}.setBitMask(${bitMIndexVar}, ${bitIndex})`;\n return {code: `if (${comp.getChildVλl()} !== undefined) {${itemJit.code};${setBitMask}}`, type: 'S'};\n }\n return itemJit;\n }\n\n case ReflectionKind.promise:\n throw new Error('Jit compilation disabled for Non Serializable types.');\n\n // ###################### COLLECTION RUNTYPES ######################\n // Types that contain other types as members\n case ReflectionKind.objectLiteral:\n case ReflectionKind.intersection: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) return comp.compile(rt.getCallSignature(), 'S', fnID);\n if (runType.src.subKind === ReflectionSubKind.nonSerializable) {\n throw new Error('Binary serialization is disabled for Non Serializable types');\n } else {\n // we need to ensure non optional properties are serialized first so then we can restore the object correctly\n // non optional properties are restored as: '{a: deserializeA, b: deserializeB, c: deserializeC};\n // and must be serialized/deserialized in the same order they are declared in the type\n const {required, optional, indexSignatures} = rt.splitJitSplitChildren(comp);\n\n if (indexSignatures.length) {\n return comp.compile(indexSignatures[0], 'S', fnID); // index signature code already contains the loop\n }\n\n const requiredProps = required.map((prop) => comp.compile(prop, 'S', fnID).code);\n const requiredPropsCode = requiredProps.join(';');\n\n let optionalPropsCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, false);\n const propsCode = optional\n .map((prop, i) => {\n prop.optionalIndex = i;\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0;\n const propCode = comp.compile(prop, 'S', fnID).code;\n if (!shouldIncreaseBufferIndex) return propCode;\n // every 8 props we need to increase the bitmap index\n return `${propCode} ${bitMIndexVar}++;`;\n })\n .filter(Boolean)\n .join('');\n optionalPropsCode = `${bitMapInit}\\n${propsCode}`;\n }\n\n return {code: `${requiredPropsCode}\\n${optionalPropsCode}`, type: 'S'};\n }\n }\n case ReflectionKind.class:\n switch (runType.src.subKind) {\n case ReflectionSubKind.date:\n return {\n code: `${sεr}.view.setFloat64(${sεr}.index, ${comp.vλl}.getTime(), 1, (${sεr}.index += 8))`,\n type: 'S',\n };\n case ReflectionSubKind.map:\n case ReflectionSubKind.set: {\n const rt = runType as IterableRunType;\n const sεr = comp.args.sεr;\n const entry = rt.getCustomVλl(comp)?.vλl || comp.vλl;\n const jitChildren = rt.getJitChildren(comp);\n const childrenCode = jitChildren\n .map((c) => comp.compile(c, 'S', fnID).code)\n .filter(Boolean)\n .join(';');\n // Serialize length at the beginning, then iterate and serialize items\n const setLength = `${sεr}.view.setUint32(${sεr}.index, ${comp.vλl}.size, 1); ${sεr}.index += 4;`;\n return {\n code: `${setLength} for (const ${entry} of ${comp.vλl}) {${childrenCode}}`,\n type: 'S',\n };\n }\n case ReflectionSubKind.nonSerializable:\n throw new Error('Binary serialization disabled for Non Serializable types');\n default: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) {\n const callSignature = rt.getCallSignature();\n if (callSignature) return comp.compile(callSignature, 'S', fnID);\n }\n const originalKind = runType.src.kind;\n (runType.src as any).kind = ReflectionKind.objectLiteral;\n const result = emitToBinary(runType, comp);\n (runType.src as any).kind = originalKind;\n return result;\n }\n }\n break;\n\n case ReflectionKind.infer:\n throw new Error('Infer is not supported in Binary serialization');\n\n case ReflectionKind.tuple: {\n const rt = runType as TupleRunType;\n const skip = rt.skipJit(comp);\n if (skip) return {code: undefined, type: 'S'};\n const params = rt.getParamRunTypes(comp);\n if (params.length === 0) return {code: undefined, type: 'S'};\n\n // For function params, all params are treated as optional in binary serialization\n // This allows sending null/undefined values over the wire even if the type is not optional\n const isFnParams = runType.src.subKind === ReflectionSubKind.params;\n\n // Split params into required, optional, and rest\n // For function params, all non-rest params are treated as optional\n const required = isFnParams ? [] : params.filter((p) => !p.isOptional() && !p.isRest());\n const optional = isFnParams ? params.filter((p) => !p.isRest()) : params.filter((p) => p.isOptional() && !p.isRest());\n const rest = params.filter((p) => p.isRest());\n\n // Serialize required params first\n const requiredCode = required.map((p) => comp.compile(p, 'S', fnID).code).join(';');\n\n // Serialize optional params with bitmap (groups of 8)\n let optionalCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, true);\n const optionalParamsCode = optional\n .map((p, i) => {\n (p as any).optionalIndex = i; // set optionalIndex for use in tupleMember case\n (p as any)._bitmapVar = bitMIndexVar; // pass bitmap variable name to tupleMember case\n (p as any)._isFnParam = isFnParams; // flag to indicate this is a function param\n const paramCode = comp.compile(p, 'S', fnID).code || '';\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0 && modIndex < optional.length;\n const increaseIndex = shouldIncreaseBufferIndex ? `${bitMIndexVar}++;` : '';\n return `${paramCode} ${increaseIndex}`;\n })\n .join('');\n optionalCode = `${bitMapInit}\\n${optionalParamsCode}`;\n }\n\n // Serialize rest params (handled as array by the rest param itself)\n const restCode = rest.map((p) => comp.compile(p, 'S', fnID).code).join(';');\n\n const allCode = [requiredCode, optionalCode, restCode].filter(Boolean).join(';');\n return {code: allCode, type: 'S'};\n }\n case ReflectionKind.typeParameter:\n throw new Error('Type parameter not implemented in Binary serialization');\n\n case ReflectionKind.union: {\n const rt = runType as UnionRunType;\n rt.checkAllowedChildren(comp);\n const {simpleItems, objectTypes, anyItem} = rt.getUnionChildren(comp);\n const totalLength = simpleItems.length + objectTypes.length + (anyItem ? 1 : 0);\n if (totalLength > MAX_UNION_ITEMS) {\n throw new Error(\n `Binary serialization not supported for Union with more than ${MAX_UNION_ITEMS} items.` +\n ` Found ${totalLength} in ${rt.getUnionTypeNames()}`\n );\n }\n const errName = comp.getLocalVarName('uErr', rt);\n const fail = `throw new Error(${errName});`;\n comp.setContextItem(\n errName,\n `const ${errName} = \"Can not encode union to binary: item does not belong to the union\"`\n );\n const ifElse = createIfElseFn();\n // Helper to generate encode code for a union item\n const getEncodeCode = (childRt: BaseRunType) => {\n const toJit = comp.compile(childRt, 'S', fnID);\n const encodeCode = toJit.code || '';\n const index = rt.getUnionItemIndex(comp, childRt);\n const isUint16 = index > 255;\n const writeIndex = isUint16\n ? `${sεr}.view.setUint16(${sεr}.index, ${index}, 1, (${sεr}.index += 2))`\n : `${sεr}.view.setUint8(${sεr}.index++, ${index})`;\n return `${writeIndex};${encodeCode}`;\n };\n // Generate code for simple items (atomic types)\n const simpleCode = simpleItems.map((childRt) => {\n const isTypeCode = rt.getChildIsTypeWithLooseCheck(childRt, comp);\n return `${ifElse()} (${isTypeCode}) {${getEncodeCode(childRt)}}`;\n });\n // Generate code for object types (need null guard)\n const objCode = objectTypes.length\n ? objectTypes.map((childRt) => {\n const isTypeCode = rt.getChildIsTypeWithLooseCheck(childRt, comp);\n return `${ifElse()} (typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && ${isTypeCode}) {${getEncodeCode(childRt)}}`;\n })\n : [];\n // Generate code for anyItem (always matches, checked last as fallback)\n const anyCode = anyItem ? `${ifElse(true)} {${getEncodeCode(anyItem)}}` : `${ifElse(true)} {${fail}}`;\n return {code: [...simpleCode, ...objCode, anyCode].join(''), type: 'S'};\n }\n default:\n throw new Error(`Binary serialization not supported for ${ReflectionKind[kind]} types`);\n }\n\n // Default return for cases that break without returning\n return {code: undefined, type: 'S'};\n}\n\n/** Generates bitmap initialization code for optional properties/params. Uses 1 bit per optional item (8 items per byte). */\nfunction getOptionalBitmapItems(\n rt: InterfaceRunType | TupleRunType,\n comp: BinaryCompiler,\n optionalLength = 0,\n currentIndex = 0,\n isTuple = false\n) {\n const sεr = comp.args.sεr;\n const prefix = isTuple ? 't' : '';\n const bitMIndexVar = comp.getLocalVarName(`${prefix}bmI`, rt); // index of the bitmap\n const bitmapLength = Math.ceil(optionalLength / 8);\n const bitIndex = `${currentIndex} & 7`; // equivalent to index % 8\n // initialize bitmap to zero as there could be values left from previous serialization\n const indexVar = comp.getLocalVarName(`${prefix}iBl`, rt);\n const setBitmapToZero =\n bitmapLength > 1\n ? `for (let ${indexVar} = 0; ${indexVar} < ${bitmapLength}; ${indexVar}++) {${sεr}.view.setUint8(${sεr}.index++, 0)}`\n : `${sεr}.view.setUint8(${sεr}.index++, 0)`;\n const bitMapInit = `${bitmapLength > 1 ? 'let ' : 'const'} ${bitMIndexVar} = ${sεr}.index; ${setBitmapToZero}`;\n return {bitMIndexVar, bitmapLength, bitIndex, bitMapInit};\n}\n\nfunction emitToBinaryAs(rt: BaseRunType, comp: BinaryCompiler, kind: ReflectionKind): JitCode {\n const originalKind = rt.src.kind;\n (rt.src as any).kind = kind;\n const result = emitToBinary(rt, comp);\n (rt.src as any).kind = originalKind;\n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AA;AAClD;AAEA,SAAS,eAAe,IAAiB,MAAsB,MAA+B;AAC1F,QAAM,eAAe,GAAG,IAAI;AAC3B,KAAG,IAAY,OAAO;AACvB,QAAM,SAAS,aAAa,IAAI,IAAI;AACnC,KAAG,IAAY,OAAO;AACvB,SAAO;AACX;;"}
1
+ {"version":3,"file":"toBinary.cjs","sources":["../../../../../src/jitCompilers/binary/toBinary.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {ReflectionKind} from '@deepkit/type';\nimport {ReflectionSubKind} from '../../constants.kind.ts';\nimport {jitBinarySerializerArgs, JitFunctions} from '../../constants.functions.ts';\nimport {createIfElseFn} from '../../lib/utils.ts';\nimport {MAX_UNION_ITEMS} from '../../constants.ts';\nimport type {JitCode} from '../../types.ts';\nimport type {BaseRunType} from '../../lib/baseRunTypes.ts';\nimport type {BaseFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport type {ArrayRunType} from '../../nodes/member/array.ts';\nimport type {PropertyRunType} from '../../nodes/member/property.ts';\nimport type {InterfaceRunType} from '../../nodes/collection/interface.ts';\nimport type {IndexSignatureRunType} from '../../nodes/member/indexProperty.ts';\nimport type {ParameterRunType} from '../../nodes/member/param.ts';\nimport type {TupleRunType} from '../../nodes/collection/tuple.ts';\nimport type {UnionRunType} from '../../nodes/collection/union.ts';\nimport type {IterableRunType} from '../../nodes/native/Iterable.ts';\nimport type {LiteralRunType} from '../../nodes/atomic/literal.ts';\n\ntype BinaryCompiler = BaseFnCompiler<typeof jitBinarySerializerArgs, typeof JitFunctions.toBinary.id>;\nconst fnID = JitFunctions.toBinary.id;\n\n/**\n * Main Binary serialization compiler function\n * Generates JIT code to serialize values to Binary format following Binary 1.1 specification\n *\n * This function generates JavaScript expressions that return Uint8Array containing Binary bytes.\n */\nexport function emitToBinary(runType: BaseRunType, comp: BinaryCompiler): JitCode {\n const src = runType.src;\n const kind = src.kind;\n const sεr = comp.args.sεr;\n\n // hack is used in some case to increase the index passing an extra argument to view.set methods\n // ie: view.setUint32(index, value, littleEndian, index += 4);\n // setUint32 only accepts 3 arguments, but we use the 4rd one to increase the index on a single statement so code can be used as an expression\n\n switch (kind) {\n // ###################### ATOMIC TYPES ######################\n case ReflectionKind.unknown:\n case ReflectionKind.any: {\n // any is serialized as json string\n return {code: `${sεr}.serString(JSON.stringify(${comp.vλl}))`, type: 'S'};\n }\n case ReflectionKind.null:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, 0)`, type: 'S'};\n case ReflectionKind.boolean:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, !!${comp.vλl})`, type: 'S'};\n case ReflectionKind.number: {\n return {code: `${sεr}.view.setFloat64(${sεr}.index,${comp.vλl}, 1, (${sεr}.index += 8))`, type: 'S'};\n }\n case ReflectionKind.string: {\n return {code: `${sεr}.serString(${comp.vλl})`, type: 'S'};\n }\n case ReflectionKind.bigint: {\n return {code: `${sεr}.serString(${comp.vλl}.toString(), true)`, type: 'S'};\n }\n case ReflectionKind.undefined:\n case ReflectionKind.void:\n return {code: `${sεr}.view.setUint8(${sεr}.index++, 1)`, type: 'S'};\n case ReflectionKind.symbol: {\n return {code: `${sεr}.serString(${comp.vλl}.description || '')`, type: 'S'};\n }\n case ReflectionKind.regexp: {\n return {code: `${sεr}.serString(${comp.vλl}.source);${sεr}.serString(${comp.vλl}.flags)`, type: 'S'};\n }\n case ReflectionKind.object:\n // similar to any, this is serialized as json string\n return {code: `${sεr}.serString(JSON.stringify(${comp.vλl}))`, type: 'S'};\n case ReflectionKind.enum: {\n return {code: `${sεr}.serEnum(${comp.vλl})`, type: 'S'};\n }\n case ReflectionKind.enumMember:\n throw new Error('Binary serialization not supported for enum member types');\n case ReflectionKind.never:\n throw new Error('Never type cannot be serialized to Binary');\n case ReflectionKind.templateLiteral:\n // runtime value is a plain string\n return {code: `${sεr}.serString(${comp.vλl})`, type: 'S'};\n case ReflectionKind.literal: {\n if (comp.opts.noLiterals) {\n const lit = (runType as LiteralRunType).src.literal;\n if (lit instanceof RegExp) return emitToBinaryAs(runType, comp, ReflectionKind.regexp);\n switch (typeof lit) {\n case 'string':\n return emitToBinaryAs(runType, comp, ReflectionKind.string);\n case 'number':\n return emitToBinaryAs(runType, comp, ReflectionKind.number);\n case 'boolean':\n return emitToBinaryAs(runType, comp, ReflectionKind.boolean);\n case 'bigint':\n return emitToBinaryAs(runType, comp, ReflectionKind.bigint);\n case 'symbol':\n return emitToBinaryAs(runType, comp, ReflectionKind.symbol);\n default:\n throw new Error(`Unsupported literal type ${typeof lit}`);\n }\n }\n return {code: '', type: 'S'}; // literals can be skipped as we restore the value directly from runType in jit code\n }\n\n // ###################### MEMBER RUNTYPES ######################\n // Types that represent members of collections or other structures\n case ReflectionKind.rest: // rest params are serialized as array but start at rest item index\n case ReflectionKind.array: {\n const rt = runType as ArrayRunType;\n rt.checkNonSkipTypes(comp);\n const child = rt.getMemberType()!;\n const memberJit = comp.compile(child, 'S', fnID);\n if (!memberJit?.code) throw new Error(`Do not know how to serialize Array<${child.getTypeName()}> to Binary.`);\n const index = rt.getChildVarName(comp);\n // serialized as [length, items...]\n return {\n code: `\n ${sεr}.view.setUint32(${sεr}.index, ${comp.vλl}.length, 1); ${sεr}.index += 4;\n for (let ${index} = ${rt.startIndex(comp)}; ${index} < ${comp.vλl}.length; ${index}++) {${memberJit.code}}\n `,\n type: 'S',\n };\n }\n case ReflectionKind.indexSignature: {\n const rt = runType as IndexSignatureRunType;\n const indexKind = (rt.src as any).index?.kind;\n const memberJit = comp.compile(rt.getJitChild(comp), 'S', fnID);\n if (!memberJit?.code) return {code: undefined, type: 'S'};\n\n const propVar = rt.getChildVarName(comp);\n const lengthVar = comp.getLocalVarName('cnt', rt);\n const indexVar = comp.getLocalVarName('piI', rt);\n const varsInit = `let ${lengthVar} = 0; const ${indexVar} = ${sεr}.index; ${sεr}.index += 4;`;\n\n // Serialize entries\n let keySerializationCode: string;\n if (indexKind === ReflectionKind.number) {\n keySerializationCode = `${sεr}.view.setUint32(${sεr}.index , Number(${propVar}), 1); ${sεr}.index += 4;`;\n } else {\n keySerializationCode = `${sεr}.serString(${propVar});`;\n }\n\n return {\n code: `\n ${varsInit};\n for (const ${propVar} in ${comp.vλl}) {${keySerializationCode} ${memberJit.code}; ${lengthVar}++;}\n ${sεr}.view.setUint32(${indexVar}, ${lengthVar}, 1);\n `,\n type: 'S',\n };\n }\n\n case ReflectionKind.function:\n case ReflectionKind.method:\n case ReflectionKind.methodSignature:\n case ReflectionKind.callSignature:\n if (runType.src.subKind === ReflectionSubKind.params) {\n return emitToBinaryAs(runType, comp, ReflectionKind.tuple);\n } else {\n throw new Error('Binary serialization not supported for functions, call compileParams or compileReturn instead.');\n }\n case ReflectionKind.parameter: {\n const rt = runType as ParameterRunType;\n switch (src.subKind) {\n case ReflectionSubKind.mapKey:\n case ReflectionSubKind.mapValue:\n case ReflectionSubKind.setItem: {\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n if (!childJit?.code) throw new Error(`Do not know how to serialize ${rt.getTypeName()} to Binary.`);\n return childJit;\n }\n default: {\n return emitToBinaryAs(runType, comp, ReflectionKind.tupleMember);\n }\n }\n }\n case ReflectionKind.property:\n case ReflectionKind.propertySignature: {\n const rt = runType as PropertyRunType;\n const parent = rt.getParent() as InterfaceRunType;\n if (parent.hasIndexSignature(comp)) return {code: undefined, type: 'S'}; // all serialization is done by index signature code\n\n const memberCode = comp.compile(rt.getJitChild(comp), 'S', fnID).code || '';\n if (rt.isOptional()) {\n const {bitMIndexVar, bitIndex} = getOptionalBitmapItems(parent, comp, 0, rt.optionalIndex, false);\n const setBitMask = `${sεr}.setBitMask(${bitMIndexVar}, ${bitIndex})`;\n return {code: `if (${comp.getChildVλl()} !== undefined) {${memberCode};${setBitMask}}`, type: 'S'};\n }\n // non optional properties rely in the order they are defined in the type so no need to include the index\n return {code: `${memberCode}`, type: 'S'};\n }\n case ReflectionKind.tupleMember: {\n const rt = runType as ParameterRunType;\n const child = rt.getJitChild(comp);\n const childJit = comp.compile(child, 'S', fnID);\n const nullJIt = emitToBinaryAs(rt, comp, ReflectionKind.undefined);\n const itemJit = childJit?.code ? childJit : nullJIt; // if child is not serializable, we serialize null as need to fill the space in the tuple\n if (rt.isRest()) return itemJit;\n // Optional handling uses bitmap set at tuple level\n const optionalIndex = (rt as any).optionalIndex;\n const bitMIndexVar = (rt as any)._bitmapVar;\n const isFnParam = (rt as any)._isFnParam;\n // Treat as optional if either isOptional() is true OR it's a function param (all fn params are optional in binary)\n const isOptional = rt.isOptional() || isFnParam;\n if (isOptional && optionalIndex !== undefined && bitMIndexVar) {\n const bitIndex = optionalIndex & 7; // equivalent to optionalIndex % 8\n const setBitMask = `${sεr}.setBitMask(${bitMIndexVar}, ${bitIndex})`;\n return {code: `if (${comp.getChildVλl()} !== undefined) {${itemJit.code};${setBitMask}}`, type: 'S'};\n }\n return itemJit;\n }\n\n case ReflectionKind.promise:\n throw new Error('Jit compilation disabled for Non Serializable types.');\n\n // ###################### COLLECTION RUNTYPES ######################\n // Types that contain other types as members\n case ReflectionKind.objectLiteral:\n case ReflectionKind.intersection: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) return comp.compile(rt.getCallSignature(), 'S', fnID);\n if (runType.src.subKind === ReflectionSubKind.nonSerializable) {\n throw new Error('Binary serialization is disabled for Non Serializable types');\n } else {\n // we need to ensure non optional properties are serialized first so then we can restore the object correctly\n // non optional properties are restored as: '{a: deserializeA, b: deserializeB, c: deserializeC};\n // and must be serialized/deserialized in the same order they are declared in the type\n const {required, optional, indexSignatures} = rt.splitJitSplitChildren(comp);\n\n if (indexSignatures.length) {\n return comp.compile(indexSignatures[0], 'S', fnID); // index signature code already contains the loop\n }\n\n const requiredProps = required.map((prop) => comp.compile(prop, 'S', fnID).code);\n const requiredPropsCode = requiredProps.join(';');\n\n let optionalPropsCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, false);\n const propsCode = optional\n .map((prop, i) => {\n prop.optionalIndex = i;\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0;\n const propCode = comp.compile(prop, 'S', fnID).code;\n if (!shouldIncreaseBufferIndex) return propCode;\n // every 8 props we need to increase the bitmap index\n return `${propCode} ${bitMIndexVar}++;`;\n })\n .filter(Boolean)\n .join('');\n optionalPropsCode = `${bitMapInit}\\n${propsCode}`;\n }\n\n return {code: `${requiredPropsCode}\\n${optionalPropsCode}`, type: 'S'};\n }\n }\n case ReflectionKind.class:\n switch (runType.src.subKind) {\n case ReflectionSubKind.date:\n return {\n code: `${sεr}.view.setFloat64(${sεr}.index, ${comp.vλl}.getTime(), 1, (${sεr}.index += 8))`,\n type: 'S',\n };\n case ReflectionSubKind.map:\n case ReflectionSubKind.set: {\n const rt = runType as IterableRunType;\n const sεr = comp.args.sεr;\n const entry = rt.getCustomVλl(comp)?.vλl || comp.vλl;\n const jitChildren = rt.getJitChildren(comp);\n const childrenCode = jitChildren\n .map((c) => comp.compile(c, 'S', fnID).code)\n .filter(Boolean)\n .join(';');\n // Serialize length at the beginning, then iterate and serialize items\n const setLength = `${sεr}.view.setUint32(${sεr}.index, ${comp.vλl}.size, 1); ${sεr}.index += 4;`;\n return {\n code: `${setLength} for (const ${entry} of ${comp.vλl}) {${childrenCode}}`,\n type: 'S',\n };\n }\n case ReflectionSubKind.nonSerializable:\n throw new Error('Binary serialization disabled for Non Serializable types');\n default: {\n const rt = runType as InterfaceRunType;\n if (rt.isCallable()) {\n const callSignature = rt.getCallSignature();\n if (callSignature) return comp.compile(callSignature, 'S', fnID);\n }\n const originalKind = runType.src.kind;\n (runType.src as any).kind = ReflectionKind.objectLiteral;\n const result = emitToBinary(runType, comp);\n (runType.src as any).kind = originalKind;\n return result;\n }\n }\n break;\n\n case ReflectionKind.infer:\n throw new Error('Infer is not supported in Binary serialization');\n\n case ReflectionKind.tuple: {\n const rt = runType as TupleRunType;\n const skip = rt.skipJit(comp);\n if (skip) return {code: undefined, type: 'S'};\n const params = rt.getParamRunTypes(comp);\n if (params.length === 0) return {code: undefined, type: 'S'};\n\n // For function params, all params are treated as optional in binary serialization\n // This allows sending null/undefined values over the wire even if the type is not optional\n const isFnParams = runType.src.subKind === ReflectionSubKind.params;\n\n // Split params into required, optional, and rest\n // For function params, all non-rest params are treated as optional\n const required = isFnParams ? [] : params.filter((p) => !p.isOptional() && !p.isRest());\n const optional = isFnParams ? params.filter((p) => !p.isRest()) : params.filter((p) => p.isOptional() && !p.isRest());\n const rest = params.filter((p) => p.isRest());\n\n // Serialize required params first\n const requiredCode = required.map((p) => comp.compile(p, 'S', fnID).code).join(';');\n\n // Serialize optional params with bitmap (groups of 8)\n let optionalCode = '';\n if (optional.length) {\n const {bitMapInit, bitMIndexVar} = getOptionalBitmapItems(rt, comp, optional.length, 0, true);\n const optionalParamsCode = optional\n .map((p, i) => {\n (p as any).optionalIndex = i; // set optionalIndex for use in tupleMember case\n (p as any)._bitmapVar = bitMIndexVar; // pass bitmap variable name to tupleMember case\n (p as any)._isFnParam = isFnParams; // flag to indicate this is a function param\n const paramCode = comp.compile(p, 'S', fnID).code || '';\n const modIndex = i + 1;\n const shouldIncreaseBufferIndex = modIndex % 8 === 0 && modIndex < optional.length;\n const increaseIndex = shouldIncreaseBufferIndex ? `${bitMIndexVar}++;` : '';\n return `${paramCode} ${increaseIndex}`;\n })\n .join('');\n optionalCode = `${bitMapInit}\\n${optionalParamsCode}`;\n }\n\n // Serialize rest params (handled as array by the rest param itself)\n const restCode = rest.map((p) => comp.compile(p, 'S', fnID).code).join(';');\n\n const allCode = [requiredCode, optionalCode, restCode].filter(Boolean).join(';');\n return {code: allCode, type: 'S'};\n }\n case ReflectionKind.typeParameter:\n throw new Error('Type parameter not implemented in Binary serialization');\n\n case ReflectionKind.union: {\n const rt = runType as UnionRunType;\n rt.checkAllowedChildren(comp);\n const {simpleItems, objectTypes, anyItem} = rt.getUnionChildren(comp);\n const totalLength = simpleItems.length + objectTypes.length + (anyItem ? 1 : 0);\n if (totalLength > MAX_UNION_ITEMS) {\n throw new Error(\n `Binary serialization not supported for Union with more than ${MAX_UNION_ITEMS} items.` +\n ` Found ${totalLength} in ${rt.getUnionTypeNames()}`\n );\n }\n const errName = comp.getLocalVarName('uErr', rt);\n const fail = `throw new Error(${errName});`;\n comp.setContextItem(\n errName,\n `const ${errName} = \"Can not encode union to binary: item does not belong to the union\"`\n );\n const ifElse = createIfElseFn();\n // Helper to generate encode code for a union item\n const getEncodeCode = (childRt: BaseRunType) => {\n const toJit = comp.compile(childRt, 'S', fnID);\n const encodeCode = toJit.code || '';\n const index = rt.getUnionItemIndex(comp, childRt);\n const isUint16 = index > 255;\n const writeIndex = isUint16\n ? `${sεr}.view.setUint16(${sεr}.index, ${index}, 1, (${sεr}.index += 2))`\n : `${sεr}.view.setUint8(${sεr}.index++, ${index})`;\n return `${writeIndex};${encodeCode}`;\n };\n // Generate code for simple items (atomic types)\n const simpleCode = simpleItems.map((childRt) => {\n const isTypeCode = rt.getChildIsTypeWithLooseCheck(childRt, comp);\n return `${ifElse()} (${isTypeCode}) {${getEncodeCode(childRt)}}`;\n });\n // Generate code for object types (need null guard)\n const objCode = objectTypes.length\n ? objectTypes.map((childRt) => {\n const isTypeCode = rt.getChildIsTypeWithLooseCheck(childRt, comp);\n return `${ifElse()} (typeof ${comp.vλl} === 'object' && ${comp.vλl} !== null && ${isTypeCode}) {${getEncodeCode(childRt)}}`;\n })\n : [];\n // Generate code for anyItem (always matches, checked last as fallback)\n const anyCode = anyItem ? `${ifElse(true)} {${getEncodeCode(anyItem)}}` : `${ifElse(true)} {${fail}}`;\n return {code: [...simpleCode, ...objCode, anyCode].join(''), type: 'S'};\n }\n default:\n throw new Error(`Binary serialization not supported for ${ReflectionKind[kind]} types`);\n }\n\n // Default return for cases that break without returning\n return {code: undefined, type: 'S'};\n}\n\n/** Generates bitmap initialization code for optional properties/params. Uses 1 bit per optional item (8 items per byte). */\nfunction getOptionalBitmapItems(\n rt: InterfaceRunType | TupleRunType,\n comp: BinaryCompiler,\n optionalLength = 0,\n currentIndex = 0,\n isTuple = false\n) {\n const sεr = comp.args.sεr;\n const prefix = isTuple ? 't' : '';\n const bitMIndexVar = comp.getLocalVarName(`${prefix}bmI`, rt); // index of the bitmap\n const bitmapLength = Math.ceil(optionalLength / 8);\n const bitIndex = `${currentIndex} & 7`; // equivalent to index % 8\n // initialize bitmap to zero as there could be values left from previous serialization\n const indexVar = comp.getLocalVarName(`${prefix}iBl`, rt);\n const setBitmapToZero =\n bitmapLength > 1\n ? `for (let ${indexVar} = 0; ${indexVar} < ${bitmapLength}; ${indexVar}++) {${sεr}.view.setUint8(${sεr}.index++, 0)}`\n : `${sεr}.view.setUint8(${sεr}.index++, 0)`;\n const bitMapInit = `${bitmapLength > 1 ? 'let ' : 'const'} ${bitMIndexVar} = ${sεr}.index; ${setBitmapToZero}`;\n return {bitMIndexVar, bitmapLength, bitIndex, bitMapInit};\n}\n\nfunction emitToBinaryAs(rt: BaseRunType, comp: BinaryCompiler, kind: ReflectionKind): JitCode {\n const originalKind = rt.src.kind;\n (rt.src as any).kind = kind;\n const result = emitToBinary(rt, comp);\n (rt.src as any).kind = originalKind;\n return result;\n}\n"],"names":["JitFunctions","ReflectionKind","ReflectionSubKind","sεr","MAX_UNION_ITEMS","createIfElseFn"],"mappings":";;;;;;;AA0BA,MAAM,OAAOA,wBAAAA,aAAa,SAAS;AAQ5B,SAAS,aAAa,SAAsB,MAA+B;AAC9E,QAAM,MAAM,QAAQ;AACpB,QAAM,OAAO,IAAI;AACjB,QAAM,MAAM,KAAK,KAAK;AAMtB,UAAQ,MAAA;AAAA;AAAA,IAEJ,KAAKC,KAAAA,eAAe;AAAA,IACpB,KAAKA,KAAAA,eAAe,KAAK;AAErB,aAAO,EAAC,MAAM,GAAG,GAAG,6BAA6B,KAAK,GAAG,MAAM,MAAM,IAAA;AAAA,IACzE;AAAA,IACA,KAAK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;AAC5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAW/D,KAAK,cAAc,GAAG,cAAc,CAAC,OAAO,uBAAuB,EAAE,OAAO,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAStG,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAiXhF"}
1
+ {"version":3,"file":"toBinary.d.ts","sourceRoot":"","sources":["../../../../../src/jitCompilers/binary/toBinary.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,uBAAuB,EAAE,YAAY,EAAC,MAAM,8BAA8B,CAAC;AAGnF,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAW/D,KAAK,cAAc,GAAG,cAAc,CAAC,OAAO,uBAAuB,EAAE,OAAO,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAStG,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAkXhF"}
@@ -80,7 +80,7 @@ function createStringifyCompiler(fnID) {
80
80
  case type.ReflectionKind.symbol:
81
81
  return { code: `JSON.stringify('Symbol:' + (${comp.vλl}.description || ''))`, type: "E" };
82
82
  case type.ReflectionKind.templateLiteral:
83
- throw new Error("Template Literals are not supported.");
83
+ return { code: `JSON.stringify(${comp.vλl})`, type: "E" };
84
84
  case type.ReflectionKind.undefined: {
85
85
  const isRoot = comp.getNestLevel(runType) === 0;
86
86
  if (isRoot) return { code: `undefined`, type: "E" };