@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.
- package/.dist/cjs/src/createRunType.cjs +3 -1
- package/.dist/cjs/src/createRunType.cjs.map +1 -1
- package/.dist/cjs/src/createRunType.d.ts.map +1 -1
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs +1 -1
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.cjs.map +1 -1
- package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts.map +1 -1
- package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs +1 -1
- package/.dist/cjs/src/jitCompilers/binary/toBinary.cjs.map +1 -1
- package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts.map +1 -1
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs +1 -1
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.cjs.map +1 -1
- package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts.map +1 -1
- package/.dist/cjs/src/mocking/mockType.cjs +46 -1
- package/.dist/cjs/src/mocking/mockType.cjs.map +1 -1
- package/.dist/cjs/src/nodes/collection/templateLiteral.cjs +73 -0
- package/.dist/cjs/src/nodes/collection/templateLiteral.cjs.map +1 -0
- package/.dist/cjs/src/nodes/collection/templateLiteral.d.ts +16 -0
- package/.dist/cjs/src/nodes/collection/templateLiteral.d.ts.map +1 -0
- package/.dist/cjs/src/nodes/member/indexProperty.cjs +69 -22
- package/.dist/cjs/src/nodes/member/indexProperty.cjs.map +1 -1
- package/.dist/cjs/src/nodes/member/indexProperty.d.ts +1 -0
- package/.dist/cjs/src/nodes/member/indexProperty.d.ts.map +1 -1
- package/.dist/esm/src/createRunType.d.ts.map +1 -1
- package/.dist/esm/src/createRunType.js +3 -1
- package/.dist/esm/src/createRunType.js.map +1 -1
- package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts.map +1 -1
- package/.dist/esm/src/jitCompilers/binary/fromBinary.js +1 -1
- package/.dist/esm/src/jitCompilers/binary/fromBinary.js.map +1 -1
- package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts.map +1 -1
- package/.dist/esm/src/jitCompilers/binary/toBinary.js +1 -1
- package/.dist/esm/src/jitCompilers/binary/toBinary.js.map +1 -1
- package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts.map +1 -1
- package/.dist/esm/src/jitCompilers/json/stringifyJson.js +1 -1
- package/.dist/esm/src/jitCompilers/json/stringifyJson.js.map +1 -1
- package/.dist/esm/src/mocking/mockType.js +47 -2
- package/.dist/esm/src/mocking/mockType.js.map +1 -1
- package/.dist/esm/src/mocking/mockUtils.js +1 -1
- package/.dist/esm/src/nodes/collection/templateLiteral.d.ts +16 -0
- package/.dist/esm/src/nodes/collection/templateLiteral.d.ts.map +1 -0
- package/.dist/esm/src/nodes/collection/templateLiteral.js +73 -0
- package/.dist/esm/src/nodes/collection/templateLiteral.js.map +1 -0
- package/.dist/esm/src/nodes/member/indexProperty.d.ts +1 -0
- package/.dist/esm/src/nodes/member/indexProperty.d.ts.map +1 -1
- package/.dist/esm/src/nodes/member/indexProperty.js +70 -23
- package/.dist/esm/src/nodes/member/indexProperty.js.map +1 -1
- package/package.json +3 -3
- package/src/createRunType.ts +5 -6
- package/src/jitCompilers/binary/fromBinary.ts +2 -1
- package/src/jitCompilers/binary/toBinary.ts +2 -1
- package/src/jitCompilers/json/stringifyJson.ts +2 -1
- package/src/jitCompilers/serialization-suite.ts +52 -0
- package/src/jitCompilers/xyz-Template/fromXYZ.ts +2 -1
- package/src/jitCompilers/xyz-Template/toXYZ.ts +2 -1
- package/src/mocking/mockType.ts +56 -1
- package/src/nodes/collection/templateLiteral.ts +87 -0
- package/src/nodes/member/indexProperty.ts +66 -17
|
@@ -4,6 +4,7 @@ const type = require("@deepkit/type");
|
|
|
4
4
|
const src_lib_baseRunTypes = require("../../lib/baseRunTypes.cjs");
|
|
5
5
|
const src_constants_functions = require("../../constants.functions.cjs");
|
|
6
6
|
const src_lib_utils = require("../../lib/utils.cjs");
|
|
7
|
+
const src_nodes_collection_templateLiteral = require("../collection/templateLiteral.cjs");
|
|
7
8
|
function __assignType(fn, args) {
|
|
8
9
|
fn.__type = args;
|
|
9
10
|
return fn;
|
|
@@ -28,23 +29,44 @@ class IndexSignatureRunType extends src_lib_baseRunTypes.MemberRunType {
|
|
|
28
29
|
}
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
32
|
+
/** if the index key is a template literal type, return the JIT context var holding the compiled key-pattern regex */
|
|
33
|
+
getKeyPatternVar(comp) {
|
|
34
|
+
const idx = this.src.index;
|
|
35
|
+
if (idx?.kind !== type.ReflectionKind.templateLiteral)
|
|
36
|
+
return void 0;
|
|
37
|
+
const varName = comp.getLocalVarName("reIdx", this);
|
|
38
|
+
if (!comp.hasContextItem(varName)) {
|
|
39
|
+
const src = src_nodes_collection_templateLiteral.buildAnchoredTemplateRegexSource(idx.types || []);
|
|
40
|
+
comp.setContextItem(varName, `const ${varName} = new RegExp(${JSON.stringify(src)})`);
|
|
41
|
+
}
|
|
42
|
+
return varName;
|
|
43
|
+
}
|
|
31
44
|
// #### jit code ####
|
|
32
45
|
emitIsType(comp) {
|
|
33
46
|
const child = this.getJitChild(comp);
|
|
34
47
|
const childJit = comp.compileIsType(child, "E");
|
|
35
|
-
|
|
48
|
+
const prop = this.getChildVarName(comp);
|
|
49
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
50
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
51
|
+
const keyCheck = reVar ? `if (!${reVar}.test(${prop})) return false;` : "";
|
|
52
|
+
if (!childJit?.code && !keyCheck)
|
|
36
53
|
return { code: void 0, type: "E" };
|
|
54
|
+
const valueCheck = childJit?.code ? `if (!(${childJit.code})) return false;` : "";
|
|
37
55
|
return {
|
|
38
|
-
code: `for (const ${
|
|
56
|
+
code: `for (const ${prop} in ${comp.vλl}){${skipCode} ${keyCheck} ${valueCheck}} return true;`,
|
|
39
57
|
type: "RB"
|
|
40
58
|
};
|
|
41
59
|
}
|
|
42
60
|
emitTypeErrors(comp) {
|
|
43
61
|
const child = this.getJitChild(comp);
|
|
44
62
|
const childJit = comp.compileTypeErrors(child, "S");
|
|
45
|
-
|
|
63
|
+
const prop = this.getChildVarName(comp);
|
|
64
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
65
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
66
|
+
const keyErr = reVar ? `if (!${reVar}.test(${prop})) {${comp.callJitErrWithPath(this, prop)}; continue;}` : "";
|
|
67
|
+
if (!childJit?.code && !keyErr)
|
|
46
68
|
return { code: void 0, type: "S" };
|
|
47
|
-
return { code: `for (const ${
|
|
69
|
+
return { code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${keyErr} ${childJit?.code || ""}}`, type: "S" };
|
|
48
70
|
}
|
|
49
71
|
emitPrepareForJson(comp) {
|
|
50
72
|
const child = this.getJitChild(comp);
|
|
@@ -54,9 +76,11 @@ class IndexSignatureRunType extends src_lib_baseRunTypes.MemberRunType {
|
|
|
54
76
|
const varName = comp.vλl;
|
|
55
77
|
const prop = this.getChildVarName(comp);
|
|
56
78
|
const skipCode = this.getSkipCode(comp, prop);
|
|
79
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
80
|
+
const patternSkip = reVar ? `if (!${reVar}.test(${prop})) continue;` : "";
|
|
57
81
|
const isExpression = src_lib_utils.childIsExpression(childJit, child);
|
|
58
82
|
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || "";
|
|
59
|
-
return { code: `for (const ${prop} in ${varName}){${skipCode} ${code}}`, type: "S" };
|
|
83
|
+
return { code: `for (const ${prop} in ${varName}){${skipCode} ${patternSkip} ${code}}`, type: "S" };
|
|
60
84
|
}
|
|
61
85
|
emitRestoreFromJson(comp) {
|
|
62
86
|
const child = this.getJitChild(comp);
|
|
@@ -66,45 +90,68 @@ class IndexSignatureRunType extends src_lib_baseRunTypes.MemberRunType {
|
|
|
66
90
|
const varName = comp.vλl;
|
|
67
91
|
const prop = this.getChildVarName(comp);
|
|
68
92
|
const skipCode = this.getSkipCode(comp, prop);
|
|
93
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
94
|
+
const patternSkip = reVar ? `if (!${reVar}.test(${prop})) continue;` : "";
|
|
69
95
|
const isExpression = src_lib_utils.childIsExpression(childJit, child);
|
|
70
96
|
const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || "";
|
|
71
|
-
return { code: `for (const ${prop} in ${varName}){${skipCode} ${code}}`, type: "S" };
|
|
97
|
+
return { code: `for (const ${prop} in ${varName}){${skipCode} ${patternSkip} ${code}}`, type: "S" };
|
|
72
98
|
}
|
|
73
99
|
emitHasUnknownKeys(comp) {
|
|
74
|
-
|
|
75
|
-
return { code: void 0, type: "E" };
|
|
100
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
76
101
|
const child = this.getJitChild(comp);
|
|
77
102
|
const childJit = comp.compileHasUnknownKeys(child, "E");
|
|
78
|
-
if (!
|
|
79
|
-
return { code:
|
|
103
|
+
if (this.getMemberType().getFamily() === "A" && !reVar)
|
|
104
|
+
return { code: void 0, type: "E" };
|
|
80
105
|
const varName = comp.vλl;
|
|
81
106
|
const prop = this.getChildVarName(comp);
|
|
82
|
-
const
|
|
107
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
108
|
+
const patternCheck = reVar ? `if (!${reVar}.test(${prop})) return true;` : "";
|
|
109
|
+
const childCheck = childJit?.code ? `const ${comp.getLocalVarName("res", this)} = ${childJit.code};if (${comp.getLocalVarName("res", this)}) return true;` : "";
|
|
110
|
+
if (!patternCheck && !childCheck)
|
|
111
|
+
return { code: "", type: "E" };
|
|
83
112
|
return {
|
|
84
|
-
code: `for (const ${prop} in ${varName}) {
|
|
113
|
+
code: `for (const ${prop} in ${varName}) {${skipCode} ${patternCheck} ${childCheck}}return false;`,
|
|
85
114
|
type: "RB"
|
|
86
115
|
};
|
|
87
116
|
}
|
|
88
117
|
emitUnknownKeyErrors(comp) {
|
|
89
|
-
|
|
90
|
-
return { code: void 0, type: "S" };
|
|
118
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
91
119
|
const child = this.getJitChild(comp);
|
|
92
120
|
const childJit = comp.compileUnknownKeyErrors(child, "S");
|
|
93
|
-
|
|
121
|
+
if (this.getMemberType().getFamily() === "A" && !reVar)
|
|
122
|
+
return { code: void 0, type: "S" };
|
|
123
|
+
const prop = this.getChildVarName(comp);
|
|
124
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
125
|
+
const patternErr = reVar ? `if (!${reVar}.test(${prop})) {${comp.callJitErrWithPath("never", prop)}; continue;}` : "";
|
|
126
|
+
if (!patternErr && !childJit?.code)
|
|
127
|
+
return { code: void 0, type: "S" };
|
|
128
|
+
return { code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternErr} ${childJit?.code || ""}}`, type: "S" };
|
|
94
129
|
}
|
|
95
130
|
emitStripUnknownKeys(comp) {
|
|
96
|
-
|
|
97
|
-
return { code: void 0, type: "S" };
|
|
131
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
98
132
|
const child = this.getJitChild(comp);
|
|
99
133
|
const childJit = comp.compileStripUnknownKeys(child, "S");
|
|
100
|
-
|
|
134
|
+
if (this.getMemberType().getFamily() === "A" && !reVar)
|
|
135
|
+
return { code: void 0, type: "S" };
|
|
136
|
+
const prop = this.getChildVarName(comp);
|
|
137
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
138
|
+
const patternStrip = reVar ? `if (!${reVar}.test(${prop})) {delete ${comp.vλl}[${prop}]; continue;}` : "";
|
|
139
|
+
if (!patternStrip && !childJit?.code)
|
|
140
|
+
return { code: void 0, type: "S" };
|
|
141
|
+
return { code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternStrip} ${childJit?.code || ""}}`, type: "S" };
|
|
101
142
|
}
|
|
102
143
|
emitUnknownKeysToUndefined(comp) {
|
|
103
|
-
|
|
104
|
-
return { code: void 0, type: "S" };
|
|
144
|
+
const reVar = this.getKeyPatternVar(comp);
|
|
105
145
|
const child = this.getJitChild(comp);
|
|
106
146
|
const childJit = comp.compileUnknownKeysToUndefined(child, "S");
|
|
107
|
-
|
|
147
|
+
if (this.getMemberType().getFamily() === "A" && !reVar)
|
|
148
|
+
return { code: void 0, type: "S" };
|
|
149
|
+
const prop = this.getChildVarName(comp);
|
|
150
|
+
const skipCode = this.getSkipCode(comp, prop);
|
|
151
|
+
const patternUndef = reVar ? `if (!${reVar}.test(${prop})) {${comp.vλl}[${prop}] = undefined; continue;}` : "";
|
|
152
|
+
if (!patternUndef && !childJit?.code)
|
|
153
|
+
return { code: void 0, type: "S" };
|
|
154
|
+
return { code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternUndef} ${childJit?.code || ""}}`, type: "S" };
|
|
108
155
|
}
|
|
109
156
|
traverseCode(comp, childJit) {
|
|
110
157
|
if (!childJit?.code)
|
|
@@ -124,7 +171,7 @@ class IndexSignatureRunType extends src_lib_baseRunTypes.MemberRunType {
|
|
|
124
171
|
const skipNames = namedChildren.length ? namedChildren.map(__assignType((child) => `${child.getChildLiteral(comp)} === ${prop}`, ["child", "", 'P"2!"/"'])).join(" || ") : "";
|
|
125
172
|
return namedChildren.length ? `if (${skipNames}) continue;` : "";
|
|
126
173
|
}
|
|
127
|
-
static __type = [
|
|
174
|
+
static __type = ["TypeIndexSignature", () => src_lib_baseRunTypes.MemberRunType, "isOptional", "JitFnCompiler", "comp", "getChildVarName", "getChildLiteral", true, "useArrayAccessor", "skipJit", "getKeyPatternVar", "JitCode", "emitIsType", "JitErrorsFnCompiler", "emitTypeErrors", "emitPrepareForJson", "emitRestoreFromJson", "emitHasUnknownKeys", "emitUnknownKeyErrors", "emitStripUnknownKeys", "emitUnknownKeysToUndefined", "childJit", "traverseCode", "prop", "getSkipCode", "IndexSignatureRunType", `P"w!7"P)0#P"w$2%&0&P"w$2%&0'P.(0)P"w$2%)0*P"w$2%P&-J0+;P"w$2%"w,0-P"w.2%"w,0/P"w$2%"w,00P"w$2%"w,01P"w$2%"w,02P"w.2%"w,03P"w$2%"w,04P"w$2%"w,05P"w$2%P"w,-J26"w,07P"w$2%&28&095"w!6"w:`];
|
|
128
175
|
}
|
|
129
176
|
exports.IndexSignatureRunType = IndexSignatureRunType;
|
|
130
177
|
//# sourceMappingURL=indexProperty.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexProperty.cjs","sources":["../../../../../src/nodes/member/indexProperty.ts"],"sourcesContent":["import {ReflectionKind, TypeIndexSignature} from '@deepkit/type';\nimport {MemberRunType} from '../../lib/baseRunTypes.ts';\nimport {type JitCode} from '../../types.ts';\nimport {JitFunctions} from '../../constants.functions.ts';\nimport type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport {InterfaceRunType} from '../collection/interface.ts';\nimport {childIsExpression} from '../../lib/utils.ts';\n\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\nexport class IndexSignatureRunType extends MemberRunType<TypeIndexSignature> {\n isOptional(): boolean {\n return true;\n }\n getChildVarName(comp: JitFnCompiler): string {\n return comp.getLocalVarName('p', this);\n }\n getChildLiteral(comp: JitFnCompiler): string {\n return this.getChildVarName(comp);\n }\n useArrayAccessor(): true {\n return true;\n }\n skipJit(comp: JitFnCompiler): boolean {\n const index = (this.src as TypeIndexSignature).index?.kind;\n if (index === ReflectionKind.symbol) {\n return comp?.fnID !== JitFunctions.toJSCode.id;\n }\n return false;\n }\n\n // #### jit code ####\n emitIsType(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileIsType(child, 'E');\n if (!childJit?.code) return {code: undefined, type: 'E'};\n return {\n code: `for (const ${this.getChildVarName(comp)} in ${comp.vλl}){if (!(${childJit.code})) return false;} return true;`,\n type: 'RB',\n };\n }\n emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileTypeErrors(child, 'S');\n if (!childJit?.code) return {code: undefined, type: 'S'};\n return {code: `for (const ${this.getChildVarName(comp)} in ${comp.vλl}) {${childJit.code}}`, type: 'S'};\n }\n emitPrepareForJson(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compilePrepareForJson(child, 'S');\n if (!child || !childJit?.code) return {code: undefined, type: 'S'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';\n return {code: `for (const ${prop} in ${varName}){${skipCode} ${code}}`, type: 'S'};\n }\n emitRestoreFromJson(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileRestoreFromJson(child, 'S');\n if (!child || !childJit?.code) return {code: undefined, type: 'S'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';\n return {code: `for (const ${prop} in ${varName}){${skipCode} ${code}}`, type: 'S'};\n }\n emitHasUnknownKeys(comp: JitFnCompiler): JitCode {\n if (this.getMemberType().getFamily() === 'A') return {code: undefined, type: 'E'};\n const child = this.getJitChild(comp);\n const childJit = comp.compileHasUnknownKeys(child, 'E');\n if (!childJit?.code) return {code: '', type: 'E'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const resultVal = comp.getLocalVarName('res', this);\n return {\n code: `for (const ${prop} in ${varName}) {const ${resultVal} = ${childJit.code};if (${resultVal}) return true;}return false;`,\n type: 'RB',\n };\n }\n emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {\n if (this.getMemberType().getFamily() === 'A') return {code: undefined, type: 'S'};\n const child = this.getJitChild(comp);\n const childJit = comp.compileUnknownKeyErrors(child, 'S');\n return this.traverseCode(comp, childJit);\n }\n emitStripUnknownKeys(comp: JitFnCompiler): JitCode {\n if (this.getMemberType().getFamily() === 'A') return {code: undefined, type: 'S'};\n const child = this.getJitChild(comp);\n const childJit = comp.compileStripUnknownKeys(child, 'S');\n return this.traverseCode(comp, childJit);\n }\n emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {\n if (this.getMemberType().getFamily() === 'A') return {code: undefined, type: 'S'};\n const child = this.getJitChild(comp);\n const childJit = comp.compileUnknownKeysToUndefined(child, 'S');\n return this.traverseCode(comp, childJit);\n }\n traverseCode(comp: JitFnCompiler, childJit: JitCode | undefined): JitCode {\n if (!childJit?.code) return {code: undefined, type: 'S'};\n const prop = this.getChildVarName(comp);\n return {code: `for (const ${prop} in ${comp.vλl}) {${childJit.code}}`, type: 'S'};\n }\n /**\n * if index property should be skipped then it output some code to skip it,\n * this happen when an object/interface has an index property but also has named properties\n * that might collide with the index property. ie {[key: string]: string, a: string}\n * when executing the logic for the index property we need to skip the named properties.\n */\n getSkipCode(comp: JitFnCompiler, prop: string): string {\n const parent = this.getParent() as InterfaceRunType;\n const namedChildren = parent.getNamedChildren(comp);\n const skipNames = namedChildren.length\n ? namedChildren.map((child) => `${child.getChildLiteral(comp)} === ${prop}`).join(' || ')\n : '';\n return namedChildren.length ? `if (${skipNames}) continue;` : '';\n }\n}\n"],"names":["MemberRunType","ReflectionKind","JitFunctions","childIsExpression"],"mappings":";;;;;;;;;;AAeM,MAAO,8BAA8BA,qBAAAA,cAAiC;AAAA,EACxE,aAAU;AACN,WAAO;AAAA,EACX;AAAA,EACA,gBAAgB,MAAmB;AAC/B,WAAO,KAAK,gBAAgB,KAAK,IAAI;AAAA,EACzC;AAAA,EACA,gBAAgB,MAAmB;AAC/B,WAAO,KAAK,gBAAgB,IAAI;AAAA,EACpC;AAAA,EACA,mBAAgB;AACZ,WAAO;AAAA,EACX;AAAA,EACA,QAAQ,MAA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+
{"version":3,"file":"indexProperty.cjs","sources":["../../../../../src/nodes/member/indexProperty.ts"],"sourcesContent":["import {ReflectionKind, type TypeIndexSignature, type TypeTemplateLiteral} from '@deepkit/type';\nimport {MemberRunType} from '../../lib/baseRunTypes.ts';\nimport {type JitCode} from '../../types.ts';\nimport {JitFunctions} from '../../constants.functions.ts';\nimport type {JitFnCompiler, JitErrorsFnCompiler} from '../../lib/jitFnCompiler.ts';\nimport {InterfaceRunType} from '../collection/interface.ts';\nimport {childIsExpression} from '../../lib/utils.ts';\nimport {buildAnchoredTemplateRegexSource} from '../collection/templateLiteral.ts';\n\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\nexport class IndexSignatureRunType extends MemberRunType<TypeIndexSignature> {\n isOptional(): boolean {\n return true;\n }\n getChildVarName(comp: JitFnCompiler): string {\n return comp.getLocalVarName('p', this);\n }\n getChildLiteral(comp: JitFnCompiler): string {\n return this.getChildVarName(comp);\n }\n useArrayAccessor(): true {\n return true;\n }\n skipJit(comp: JitFnCompiler): boolean {\n const index = (this.src as TypeIndexSignature).index?.kind;\n if (index === ReflectionKind.symbol) {\n return comp?.fnID !== JitFunctions.toJSCode.id;\n }\n return false;\n }\n\n /** if the index key is a template literal type, return the JIT context var holding the compiled key-pattern regex */\n private getKeyPatternVar(comp: JitFnCompiler): string | undefined {\n const idx = this.src.index;\n if (idx?.kind !== ReflectionKind.templateLiteral) return undefined;\n const varName = comp.getLocalVarName('reIdx', this);\n if (!comp.hasContextItem(varName)) {\n const src = buildAnchoredTemplateRegexSource((idx as TypeTemplateLiteral).types || []);\n comp.setContextItem(varName, `const ${varName} = new RegExp(${JSON.stringify(src)})`);\n }\n return varName;\n }\n\n // #### jit code ####\n emitIsType(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileIsType(child, 'E');\n const prop = this.getChildVarName(comp);\n const reVar = this.getKeyPatternVar(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const keyCheck = reVar ? `if (!${reVar}.test(${prop})) return false;` : '';\n if (!childJit?.code && !keyCheck) return {code: undefined, type: 'E'};\n const valueCheck = childJit?.code ? `if (!(${childJit.code})) return false;` : '';\n return {\n code: `for (const ${prop} in ${comp.vλl}){${skipCode} ${keyCheck} ${valueCheck}} return true;`,\n type: 'RB',\n };\n }\n emitTypeErrors(comp: JitErrorsFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileTypeErrors(child, 'S');\n const prop = this.getChildVarName(comp);\n const reVar = this.getKeyPatternVar(comp);\n const skipCode = this.getSkipCode(comp, prop);\n // when the key fails the template literal pattern, report it (with the offending key in the path)\n // and skip the value check to avoid compounding errors on values whose key was already invalid\n const keyErr = reVar ? `if (!${reVar}.test(${prop})) {${comp.callJitErrWithPath(this, prop)}; continue;}` : '';\n if (!childJit?.code && !keyErr) return {code: undefined, type: 'S'};\n return {code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${keyErr} ${childJit?.code || ''}}`, type: 'S'};\n }\n emitPrepareForJson(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compilePrepareForJson(child, 'S');\n if (!child || !childJit?.code) return {code: undefined, type: 'S'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const reVar = this.getKeyPatternVar(comp);\n const patternSkip = reVar ? `if (!${reVar}.test(${prop})) continue;` : '';\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';\n return {code: `for (const ${prop} in ${varName}){${skipCode} ${patternSkip} ${code}}`, type: 'S'};\n }\n emitRestoreFromJson(comp: JitFnCompiler): JitCode {\n const child = this.getJitChild(comp);\n const childJit = comp.compileRestoreFromJson(child, 'S');\n if (!child || !childJit?.code) return {code: undefined, type: 'S'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const reVar = this.getKeyPatternVar(comp);\n const patternSkip = reVar ? `if (!${reVar}.test(${prop})) continue;` : '';\n const isExpression = childIsExpression(childJit, child);\n const code = isExpression ? `${comp.getChildVλl()} = ${childJit.code};` : childJit.code || '';\n return {code: `for (const ${prop} in ${varName}){${skipCode} ${patternSkip} ${code}}`, type: 'S'};\n }\n emitHasUnknownKeys(comp: JitFnCompiler): JitCode {\n const reVar = this.getKeyPatternVar(comp);\n const child = this.getJitChild(comp);\n const childJit = comp.compileHasUnknownKeys(child, 'E');\n // when the value is atomic and there's no key pattern, every key is \"known\" -> no check needed\n if (this.getMemberType().getFamily() === 'A' && !reVar) return {code: undefined, type: 'E'};\n const varName = comp.vλl;\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const patternCheck = reVar ? `if (!${reVar}.test(${prop})) return true;` : '';\n const childCheck = childJit?.code\n ? `const ${comp.getLocalVarName('res', this)} = ${childJit.code};if (${comp.getLocalVarName('res', this)}) return true;`\n : '';\n if (!patternCheck && !childCheck) return {code: '', type: 'E'};\n return {\n code: `for (const ${prop} in ${varName}) {${skipCode} ${patternCheck} ${childCheck}}return false;`,\n type: 'RB',\n };\n }\n emitUnknownKeyErrors(comp: JitErrorsFnCompiler): JitCode {\n const reVar = this.getKeyPatternVar(comp);\n const child = this.getJitChild(comp);\n const childJit = comp.compileUnknownKeyErrors(child, 'S');\n if (this.getMemberType().getFamily() === 'A' && !reVar) return {code: undefined, type: 'S'};\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const patternErr = reVar ? `if (!${reVar}.test(${prop})) {${comp.callJitErrWithPath('never', prop)}; continue;}` : '';\n if (!patternErr && !childJit?.code) return {code: undefined, type: 'S'};\n return {code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternErr} ${childJit?.code || ''}}`, type: 'S'};\n }\n emitStripUnknownKeys(comp: JitFnCompiler): JitCode {\n const reVar = this.getKeyPatternVar(comp);\n const child = this.getJitChild(comp);\n const childJit = comp.compileStripUnknownKeys(child, 'S');\n if (this.getMemberType().getFamily() === 'A' && !reVar) return {code: undefined, type: 'S'};\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const patternStrip = reVar ? `if (!${reVar}.test(${prop})) {delete ${comp.vλl}[${prop}]; continue;}` : '';\n if (!patternStrip && !childJit?.code) return {code: undefined, type: 'S'};\n return {code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternStrip} ${childJit?.code || ''}}`, type: 'S'};\n }\n emitUnknownKeysToUndefined(comp: JitFnCompiler): JitCode {\n const reVar = this.getKeyPatternVar(comp);\n const child = this.getJitChild(comp);\n const childJit = comp.compileUnknownKeysToUndefined(child, 'S');\n if (this.getMemberType().getFamily() === 'A' && !reVar) return {code: undefined, type: 'S'};\n const prop = this.getChildVarName(comp);\n const skipCode = this.getSkipCode(comp, prop);\n const patternUndef = reVar ? `if (!${reVar}.test(${prop})) {${comp.vλl}[${prop}] = undefined; continue;}` : '';\n if (!patternUndef && !childJit?.code) return {code: undefined, type: 'S'};\n return {code: `for (const ${prop} in ${comp.vλl}) {${skipCode} ${patternUndef} ${childJit?.code || ''}}`, type: 'S'};\n }\n traverseCode(comp: JitFnCompiler, childJit: JitCode | undefined): JitCode {\n if (!childJit?.code) return {code: undefined, type: 'S'};\n const prop = this.getChildVarName(comp);\n return {code: `for (const ${prop} in ${comp.vλl}) {${childJit.code}}`, type: 'S'};\n }\n /**\n * if index property should be skipped then it output some code to skip it,\n * this happen when an object/interface has an index property but also has named properties\n * that might collide with the index property. ie {[key: string]: string, a: string}\n * when executing the logic for the index property we need to skip the named properties.\n */\n getSkipCode(comp: JitFnCompiler, prop: string): string {\n const parent = this.getParent() as InterfaceRunType;\n const namedChildren = parent.getNamedChildren(comp);\n const skipNames = namedChildren.length\n ? namedChildren.map((child) => `${child.getChildLiteral(comp)} === ${prop}`).join(' || ')\n : '';\n return namedChildren.length ? `if (${skipNames}) continue;` : '';\n }\n}\n"],"names":["MemberRunType","ReflectionKind","JitFunctions","buildAnchoredTemplateRegexSource","childIsExpression"],"mappings":";;;;;;;;;;;AAgBM,MAAO,8BAA8BA,qBAAAA,cAAiC;AAAA,EACxE,aAAU;AACN,WAAO;AAAA,EACX;AAAA,EACA,gBAAgB,MAAmB;AAC/B,WAAO,KAAK,gBAAgB,KAAK,IAAI;AAAA,EACzC;AAAA,EACA,gBAAgB,MAAmB;AAC/B,WAAO,KAAK,gBAAgB,IAAI;AAAA,EACpC;AAAA,EACA,mBAAgB;AACZ,WAAO;AAAA,EACX;AAAA,EACA,QAAQ,MAAmB;AACvB,UAAM,QAAS,KAAK,IAA2B,OAAO;AACtD,QAAI,UAAUC,KAAAA,eAAe,QAAQ;AACjC,aAAO,MAAM,SAASC,wBAAAA,aAAa,SAAS;AAAA,IAChD;AACA,WAAO;AAAA,EACX;AAAA;AAAA,EAGQ,iBAAiB,MAAmB;AACxC,UAAM,MAAM,KAAK,IAAI;AACrB,QAAI,KAAK,SAASD,KAAAA,eAAe;AAAiB,aAAO;AACzD,UAAM,UAAU,KAAK,gBAAgB,SAAS,IAAI;AAClD,QAAI,CAAC,KAAK,eAAe,OAAO,GAAG;AAC/B,YAAM,MAAME,qCAAAA,iCAAkC,IAA4B,SAAS,CAAA,CAAE;AACrF,WAAK,eAAe,SAAS,SAAS,OAAO,iBAAiB,KAAK,UAAU,GAAG,CAAC,GAAG;AAAA,IACxF;AACA,WAAO;AAAA,EACX;AAAA;AAAA,EAGA,WAAW,MAAmB;AAC1B,UAAM,QAAQ,KAAK,YAAY,IAAI;AACnC,UAAM,WAAW,KAAK,cAAc,OAAO,GAAG;AAC9C,UAAM,OAAO,KAAK,gBAAgB,IAAI;AACtC,UAAM,QAAQ,KAAK,iBAAiB,IAAI;AACxC,UAAM,WAAW,KAAK,YAAY,MAAM,IAAI;AAC5C,UAAM,WAAW,QAAQ,QAAQ,KAAK,SAAS,IAAI,qBAAqB;AACxE,QAAI,CA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AAO,KAAK,GAAG,MAAM,SAAS,IAAI,KAAK,MAAM,IAAA;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,MAAqB,MAAY;AACzC,UAAM,SAAS,KAAK,UAAA;AACpB,UAAM,gBAAgB,OAAO,iBAAiB,IAAI;AAClD,UAAM,YAAY,cAAc,SAC1B,cAAc,IAAG,aAAC,CAAC,UAAU,GAAG,MAAM,gBAAgB,IAAI,CAAC,QAAQ,IAAI,IAAE,CAAA,SAAA,IAAA,SAAA,CAAA,CAAA,EAAE,KAAK,MAAM,IACtF;AACN,WAAO,cAAc,SAAS,OAAO,SAAS,gBAAgB;AAAA,EAClE;AAAA;;;"}
|
|
@@ -8,6 +8,7 @@ export declare class IndexSignatureRunType extends MemberRunType<TypeIndexSignat
|
|
|
8
8
|
getChildLiteral(comp: JitFnCompiler): string;
|
|
9
9
|
useArrayAccessor(): true;
|
|
10
10
|
skipJit(comp: JitFnCompiler): boolean;
|
|
11
|
+
private getKeyPatternVar;
|
|
11
12
|
emitIsType(comp: JitFnCompiler): JitCode;
|
|
12
13
|
emitTypeErrors(comp: JitErrorsFnCompiler): JitCode;
|
|
13
14
|
emitPrepareForJson(comp: JitFnCompiler): JitCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexProperty.d.ts","sourceRoot":"","sources":["../../../../../src/nodes/member/indexProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"indexProperty.d.ts","sourceRoot":"","sources":["../../../../../src/nodes/member/indexProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAA2B,MAAM,eAAe,CAAC;AAChG,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,KAAK,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAC,aAAa,EAAE,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAYnF,qBAAa,qBAAsB,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACxE,UAAU,IAAI,OAAO;IAGrB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM;IAG5C,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM;IAG5C,gBAAgB,IAAI,IAAI;IAGxB,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IASrC,OAAO,CAAC,gBAAgB;IAYxB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAcxC,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO;IAYlD,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAahD,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAajD,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAmBhD,oBAAoB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO;IAWxD,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAWlD,0BAA0B,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO;IAWxD,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO;IAWzE,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAQzD"}
|
|
@@ -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;
|
|
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"}
|
|
@@ -29,6 +29,7 @@ import { FunctionRunType } from "./nodes/function/function.js";
|
|
|
29
29
|
import { PromiseRunType } from "./nodes/native/promise.js";
|
|
30
30
|
import { ObjectRunType } from "./nodes/atomic/object.js";
|
|
31
31
|
import { IntersectionRunType } from "./nodes/collection/intersection.js";
|
|
32
|
+
import { TemplateLiteralRunType } from "./nodes/collection/templateLiteral.js";
|
|
32
33
|
import { ParameterRunType } from "./nodes/member/param.js";
|
|
33
34
|
import { MethodRunType } from "./nodes/member/method.js";
|
|
34
35
|
import { RestParamsRunType } from "./nodes/member/restParams.js";
|
|
@@ -171,7 +172,8 @@ function createRunType(deepkitType) {
|
|
|
171
172
|
rt = new SymbolRunType();
|
|
172
173
|
break;
|
|
173
174
|
case ReflectionKind.templateLiteral:
|
|
174
|
-
|
|
175
|
+
rt = new TemplateLiteralRunType();
|
|
176
|
+
break;
|
|
175
177
|
case ReflectionKind.undefined:
|
|
176
178
|
rt = new UndefinedRunType();
|
|
177
179
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRunType.js","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":[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uBAAA;AAAA,MACf;AACA,aAAO,IAAI,aAAA;AAAA,EAAY;AAEnC;;"}
|
|
1
|
+
{"version":3,"file":"createRunType.js","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 {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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEM,SAAU,QAAW,OAAX,QAAO,IAAA,CAAA,GAAyB;AAAhC,UAAO,IAAA;AACnB,QAAM,QAAQ,KAAK,IAAA;AACnB,QAAM,MAAM,mBAAmB,IAAI;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,UAAU,cAAc,GAAG,CAAC,EAAE;AAChG,SAAO,IAAI;AACd;;AAEK,SAAU,gBAAoD,IAAM;AACtE,QAAM,MAAM,QAAQ,EAAE;AACtB,UAAQ,GAAG;AACX,SAAO,IAAI;AACf;;AAGA,SAAS,eAAe,KAAY;AAChC,6BAAA;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,QAAI,QAAQ,OAAO;AAAG,YAAM,KAAK,QAAQ,IAAI;AAC7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aAAO,IAAI,YAAA;AAAA,IACf,KAAK;AACD,UAAI,UAAU,kBAAkB;AAChC,aAAO,IAAI,WAAA;AAAA,IACf,KAAK;AACD,UAAI,UAAU,kBAAkB;AAChC,aAAO,IAAI,WAAA;AAAA,IACf;AACI,UAAI,uBAAuB,GAAG,GAAG;AAC7B,YAAI,UAAU,kBAAkB;AAChC,eAAO,IAAI,uBAAA;AAAA,MACf;AACA,aAAO,IAAI,aAAA;AAAA,EAAY;AAEnC;;"}
|
|
@@ -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,
|
|
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"}
|
|
@@ -47,7 +47,7 @@ function emitFromBinary(runType, comp) {
|
|
|
47
47
|
case ReflectionKind.never:
|
|
48
48
|
throw new Error("Never type cannot be deserialized from Binary");
|
|
49
49
|
case ReflectionKind.templateLiteral:
|
|
50
|
-
|
|
50
|
+
return { code: `${dεs}.desString()`, type: "E" };
|
|
51
51
|
case ReflectionKind.literal: {
|
|
52
52
|
if (comp.opts.noLiterals) {
|
|
53
53
|
const lit = runType.src.literal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromBinary.js","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":["code"],"mappings":";;;;;;AA+BA,MAAM,OAAO,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,KAAK,eAAe;AAAA,IACpB,KAAK,eAAe,KAAK;AAErB,aAAO,EAAC,MAAM,cAAc,GAAG,iBAAiB,MAAM,IAAA;AAAA,IAC1D;AAAA,IACA,KAAK,eAAe;AAChB,aAAO,EAAC,MAAM,IAAI,GAAG,mBAAmB,MAAM,IAAA;AAAA,IAClD,KAAK,eAAe;AAChB,aAAO,EAAC,MAAM,GAAG,GAAG,kBAAkB,GAAG,mBAAmB,MAAM,IAAA;AAAA,IACtE,KAAK,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GAAG,oBAAoB,GAAG,eAAe,GAAG,iBAAiB,MAAM,IAAA;AAAA,IACxF;AAAA,IACA,KAAK,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,GAAG,GAAG,gBAAgB,MAAM,IAAA;AAAA,IAC9C;AAAA,IACA,KAAK,eAAe,QAAQ;AACxB,aAAO,EAAC,MAAM,UAAU,GAAG,qBAAqB,MAAM,IAAA;AAAA,IAC1D;AAAA,IACA,KA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O;AAC1E,YAAM,OAAO;AAAA,kBACP,SAAS;AAAA,kBACT,YAAY;AAAA,kBACZ,QAAQ;AAAA;AAEd,aAAO,EAAC,MAAM,MAAM,IAAA;AAAA,IACxB;AAAA,IAEA;AACI,YAAM,IAAI,MAAM,4CAA4C,eAAe,IAAI,CAAC,QAAQ;AAAA,EAAA;AAEhG,QAAM,IAAI,MAAM,kCAAkC,QAAQ,YAAA,CAAa,eAAe;AAC1F;AAEA,SAAS,YAAY,IAAqB,MAAsB,qBAA+C;AAC3G,QAAM,SAAS,eAAe,GAAG,IAAI,IAAI;SACT,SAAS,GAAG,gBAAgB,IAAI,IAAI,GAAG,gBAAgB,IAAI;AAE/F;AAGA,SAAS,uBACL,IACA,MACA,iBAAiB,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
|
+
{"version":3,"file":"fromBinary.js","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":["code"],"mappings":";;;;;;AA+BA,MAAM,OAAO,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,KAAK,eAAe;AAAA,IACpB,KAAK,eAAe,KAAK;AAErB,aAAO,EAA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AAK,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":"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,
|
|
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"}
|
|
@@ -46,7 +46,7 @@ function emitToBinary(runType, comp) {
|
|
|
46
46
|
case ReflectionKind.never:
|
|
47
47
|
throw new Error("Never type cannot be serialized to Binary");
|
|
48
48
|
case ReflectionKind.templateLiteral:
|
|
49
|
-
|
|
49
|
+
return { code: `${sεr}.serString(${comp.vλl})`, type: "S" };
|
|
50
50
|
case ReflectionKind.literal: {
|
|
51
51
|
if (comp.opts.noLiterals) {
|
|
52
52
|
const lit = runType.src.literal;
|