deukpack 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +6 -0
  3. package/README.ko.md +138 -0
  4. package/README.md +182 -0
  5. package/RELEASING.md +71 -0
  6. package/bin/deukpack.js +9 -0
  7. package/dist/ast/DeukPackASTBuilder.d.ts +153 -0
  8. package/dist/ast/DeukPackASTBuilder.d.ts.map +1 -0
  9. package/dist/ast/DeukPackASTBuilder.js +931 -0
  10. package/dist/ast/DeukPackASTBuilder.js.map +1 -0
  11. package/dist/codegen/CSharpGenerator.d.ts +136 -0
  12. package/dist/codegen/CSharpGenerator.d.ts.map +1 -0
  13. package/dist/codegen/CSharpGenerator.js +2303 -0
  14. package/dist/codegen/CSharpGenerator.js.map +1 -0
  15. package/dist/codegen/CodeGenerator.d.ts +11 -0
  16. package/dist/codegen/CodeGenerator.d.ts.map +1 -0
  17. package/dist/codegen/CodeGenerator.js +11 -0
  18. package/dist/codegen/CodeGenerator.js.map +1 -0
  19. package/dist/codegen/CppGenerator.d.ts +23 -0
  20. package/dist/codegen/CppGenerator.d.ts.map +1 -0
  21. package/dist/codegen/CppGenerator.js +215 -0
  22. package/dist/codegen/CppGenerator.js.map +1 -0
  23. package/dist/codegen/HighPerformanceCSharpGenerator.d.ts +29 -0
  24. package/dist/codegen/HighPerformanceCSharpGenerator.d.ts.map +1 -0
  25. package/dist/codegen/HighPerformanceCSharpGenerator.js +486 -0
  26. package/dist/codegen/HighPerformanceCSharpGenerator.js.map +1 -0
  27. package/dist/core/DeukPackEngine.d.ts +69 -0
  28. package/dist/core/DeukPackEngine.d.ts.map +1 -0
  29. package/dist/core/DeukPackEngine.js +379 -0
  30. package/dist/core/DeukPackEngine.js.map +1 -0
  31. package/dist/core/DeukPackGenerator.d.ts +9 -0
  32. package/dist/core/DeukPackGenerator.d.ts.map +1 -0
  33. package/dist/core/DeukPackGenerator.js +15 -0
  34. package/dist/core/DeukPackGenerator.js.map +1 -0
  35. package/dist/core/DeukParser.d.ts +12 -0
  36. package/dist/core/DeukParser.d.ts.map +1 -0
  37. package/dist/core/DeukParser.js +27 -0
  38. package/dist/core/DeukParser.js.map +1 -0
  39. package/dist/core/IdlParser.d.ts +27 -0
  40. package/dist/core/IdlParser.d.ts.map +1 -0
  41. package/dist/core/IdlParser.js +157 -0
  42. package/dist/core/IdlParser.js.map +1 -0
  43. package/dist/core/ProtoParser.d.ts +12 -0
  44. package/dist/core/ProtoParser.d.ts.map +1 -0
  45. package/dist/core/ProtoParser.js +27 -0
  46. package/dist/core/ProtoParser.js.map +1 -0
  47. package/dist/csharp/DpExcelProtocol.cs +3005 -0
  48. package/dist/csharp/DpProtocolLibrary.cs +13 -0
  49. package/dist/index.d.ts +22 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +43 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/lexer/DeukLexer.d.ts +31 -0
  54. package/dist/lexer/DeukLexer.d.ts.map +1 -0
  55. package/dist/lexer/DeukLexer.js +292 -0
  56. package/dist/lexer/DeukLexer.js.map +1 -0
  57. package/dist/lexer/IdlLexer.d.ts +33 -0
  58. package/dist/lexer/IdlLexer.d.ts.map +1 -0
  59. package/dist/lexer/IdlLexer.js +286 -0
  60. package/dist/lexer/IdlLexer.js.map +1 -0
  61. package/dist/native/NativeDeukPackEngine.d.ts +30 -0
  62. package/dist/native/NativeDeukPackEngine.d.ts.map +1 -0
  63. package/dist/native/NativeDeukPackEngine.js +99 -0
  64. package/dist/native/NativeDeukPackEngine.js.map +1 -0
  65. package/dist/proto/ProtoASTBuilder.d.ts +29 -0
  66. package/dist/proto/ProtoASTBuilder.d.ts.map +1 -0
  67. package/dist/proto/ProtoASTBuilder.js +239 -0
  68. package/dist/proto/ProtoASTBuilder.js.map +1 -0
  69. package/dist/proto/ProtoLexer.d.ts +29 -0
  70. package/dist/proto/ProtoLexer.d.ts.map +1 -0
  71. package/dist/proto/ProtoLexer.js +264 -0
  72. package/dist/proto/ProtoLexer.js.map +1 -0
  73. package/dist/proto/ProtoTypes.d.ts +40 -0
  74. package/dist/proto/ProtoTypes.d.ts.map +1 -0
  75. package/dist/proto/ProtoTypes.js +37 -0
  76. package/dist/proto/ProtoTypes.js.map +1 -0
  77. package/dist/protocols/BinaryProtocol.d.ts +7 -0
  78. package/dist/protocols/BinaryProtocol.d.ts.map +1 -0
  79. package/dist/protocols/BinaryProtocol.js +11 -0
  80. package/dist/protocols/BinaryProtocol.js.map +1 -0
  81. package/dist/protocols/BinaryWriter.d.ts +22 -0
  82. package/dist/protocols/BinaryWriter.d.ts.map +1 -0
  83. package/dist/protocols/BinaryWriter.js +104 -0
  84. package/dist/protocols/BinaryWriter.js.map +1 -0
  85. package/dist/protocols/CompactProtocol.d.ts +7 -0
  86. package/dist/protocols/CompactProtocol.d.ts.map +1 -0
  87. package/dist/protocols/CompactProtocol.js +11 -0
  88. package/dist/protocols/CompactProtocol.js.map +1 -0
  89. package/dist/protocols/ExcelProtocol.d.ts +98 -0
  90. package/dist/protocols/ExcelProtocol.d.ts.map +1 -0
  91. package/dist/protocols/ExcelProtocol.js +639 -0
  92. package/dist/protocols/ExcelProtocol.js.map +1 -0
  93. package/dist/protocols/JsonProtocol.d.ts +68 -0
  94. package/dist/protocols/JsonProtocol.d.ts.map +1 -0
  95. package/dist/protocols/JsonProtocol.js +422 -0
  96. package/dist/protocols/JsonProtocol.js.map +1 -0
  97. package/dist/protocols/WireProtocol.d.ts +348 -0
  98. package/dist/protocols/WireProtocol.d.ts.map +1 -0
  99. package/dist/protocols/WireProtocol.js +912 -0
  100. package/dist/protocols/WireProtocol.js.map +1 -0
  101. package/dist/serialization/WireDeserializer.d.ts +8 -0
  102. package/dist/serialization/WireDeserializer.d.ts.map +1 -0
  103. package/dist/serialization/WireDeserializer.js +13 -0
  104. package/dist/serialization/WireDeserializer.js.map +1 -0
  105. package/dist/serialization/WireSerializer.d.ts +20 -0
  106. package/dist/serialization/WireSerializer.d.ts.map +1 -0
  107. package/dist/serialization/WireSerializer.js +100 -0
  108. package/dist/serialization/WireSerializer.js.map +1 -0
  109. package/dist/types/DeukPackTypes.d.ts +291 -0
  110. package/dist/types/DeukPackTypes.d.ts.map +1 -0
  111. package/dist/types/DeukPackTypes.js +76 -0
  112. package/dist/types/DeukPackTypes.js.map +1 -0
  113. package/dist/utils/EndianUtils.d.ts +11 -0
  114. package/dist/utils/EndianUtils.d.ts.map +1 -0
  115. package/dist/utils/EndianUtils.js +32 -0
  116. package/dist/utils/EndianUtils.js.map +1 -0
  117. package/dist/utils/PerformanceMonitor.d.ts +26 -0
  118. package/dist/utils/PerformanceMonitor.d.ts.map +1 -0
  119. package/dist/utils/PerformanceMonitor.js +57 -0
  120. package/dist/utils/PerformanceMonitor.js.map +1 -0
  121. package/package.json +77 -0
  122. package/scripts/build_deukpack.js +669 -0
@@ -0,0 +1,639 @@
1
+ "use strict";
2
+ /**
3
+ * DeukPack Excel Protocol for TypeScript
4
+ * DpProtocol implementation that reads Excel data using numeric field-ID hierarchy headers.
5
+ *
6
+ * Excel layout (same as C# DpExcelProtocol):
7
+ * Row 0: schema info
8
+ * Row 1: HIERARCHY_ID (numeric field IDs, dot-separated: "1", "20", "20.1", "40.22.1")
9
+ * Row 2: DATATYPE 득팩 표준 (int32, int64, list, list<T>, record, enum<T>, ...). 레거시 i64/rec/lst 도 수용.
10
+ * Row 3: COLUMN_NAME (human-readable)
11
+ * Row 4: COMMENT
12
+ * Row 5+: DATA
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DpExcelProtocol = exports.FIRST_DATA_ROW = exports.COLUMN_NAME_ROW = exports.DATATYPE_ROW = exports.HIERARCHY_ID_ROW = void 0;
16
+ exports.fromExcelRow = fromExcelRow;
17
+ exports.fromExcelSheet = fromExcelSheet;
18
+ const WireProtocol_1 = require("./WireProtocol");
19
+ exports.HIERARCHY_ID_ROW = 1;
20
+ exports.DATATYPE_ROW = 2;
21
+ exports.COLUMN_NAME_ROW = 3;
22
+ exports.FIRST_DATA_ROW = 5;
23
+ class DpExcelProtocol {
24
+ constructor(sheet, dataRow = exports.FIRST_DATA_ROW, enumResolver) {
25
+ this._fieldIdToCol = new Map();
26
+ this._colDataType = new Map();
27
+ this._pathStack = [];
28
+ this._currentPath = '';
29
+ this._structStack = [];
30
+ this._pendingFields = [];
31
+ this._pendingIdx = 0;
32
+ this._listStack = [];
33
+ this._lastField = { id: 0, type: WireProtocol_1.DpWireType.Stop, col: -1, path: '' };
34
+ this._sheet = sheet;
35
+ this._dataRow = dataRow;
36
+ this._enumResolver = enumResolver ?? null;
37
+ this.buildColumnMap();
38
+ }
39
+ getDataRow() { return this._dataRow; }
40
+ setDataRow(row) { this._dataRow = row; }
41
+ // ─── Column Map ───
42
+ buildColumnMap() {
43
+ this._fieldIdToCol.clear();
44
+ this._colDataType.clear();
45
+ for (let col = 1; col <= this._sheet.lastColumn; col++) {
46
+ const hier = this._sheet.cellValue(exports.HIERARCHY_ID_ROW, col)?.trim();
47
+ if (!hier)
48
+ break;
49
+ const dt = this._sheet.cellValue(exports.DATATYPE_ROW, col)?.trim() ?? '';
50
+ this._fieldIdToCol.set(hier, col);
51
+ this._colDataType.set(col, dt);
52
+ }
53
+ }
54
+ collectChildFields(parentPath) {
55
+ const entries = new Map();
56
+ const prefix = parentPath ? parentPath + '.' : '';
57
+ for (const [path, col] of this._fieldIdToCol) {
58
+ let remainder;
59
+ if (prefix) {
60
+ if (!path.startsWith(prefix))
61
+ continue;
62
+ remainder = path.substring(prefix.length);
63
+ }
64
+ else {
65
+ remainder = path;
66
+ }
67
+ const dotPos = remainder.indexOf('.');
68
+ const firstSeg = dotPos >= 0 ? remainder.substring(0, dotPos) : remainder;
69
+ const fieldId = parseInt(firstSeg, 10);
70
+ if (isNaN(fieldId))
71
+ continue;
72
+ const childPath = prefix ? prefix + firstSeg : firstSeg;
73
+ const isExactColumn = (path === childPath);
74
+ if (isExactColumn) {
75
+ const dt = this._colDataType.get(col) ?? '';
76
+ entries.set(fieldId, { id: fieldId, type: dataTypeToDpWireType(dt), col, path: childPath });
77
+ }
78
+ else if (!entries.has(fieldId)) {
79
+ const explicitCol = this._fieldIdToCol.get(childPath);
80
+ if (explicitCol !== undefined) {
81
+ const dt = this._colDataType.get(explicitCol) ?? '';
82
+ entries.set(fieldId, { id: fieldId, type: dataTypeToDpWireType(dt), col: explicitCol, path: childPath });
83
+ }
84
+ else {
85
+ entries.set(fieldId, { id: fieldId, type: WireProtocol_1.DpWireType.Struct, col: -1, path: childPath });
86
+ }
87
+ }
88
+ }
89
+ const result = Array.from(entries.values());
90
+ result.sort((a, b) => a.id - b.id);
91
+ return result;
92
+ }
93
+ // ─── Read - Struct ───
94
+ readStructBegin() {
95
+ if (this._listStack.length > 0) {
96
+ const ls = this._listStack[this._listStack.length - 1];
97
+ if (ls.structDepth === 0) {
98
+ this._pathStack.push(this._currentPath);
99
+ this._dataRow = ls.startRow + ls.currentElement;
100
+ ls.currentElement++;
101
+ }
102
+ ls.structDepth++;
103
+ }
104
+ if (this._pendingFields.length > 0 || this._pendingIdx > 0) {
105
+ this._structStack.push({ fields: this._pendingFields, index: this._pendingIdx });
106
+ }
107
+ this._pendingFields = this.collectChildFields(this._currentPath);
108
+ this._pendingIdx = 0;
109
+ return { name: 'record' };
110
+ }
111
+ readStructEnd() {
112
+ if (this._listStack.length > 0) {
113
+ const ls = this._listStack[this._listStack.length - 1];
114
+ ls.structDepth--;
115
+ }
116
+ if (this._pathStack.length > 0) {
117
+ this._currentPath = this._pathStack.pop();
118
+ }
119
+ if (this._structStack.length > 0) {
120
+ const s = this._structStack.pop();
121
+ this._pendingFields = s.fields;
122
+ this._pendingIdx = s.index;
123
+ }
124
+ }
125
+ readFieldBegin() {
126
+ while (this._pendingIdx < this._pendingFields.length) {
127
+ const entry = this._pendingFields[this._pendingIdx];
128
+ this._pendingIdx++;
129
+ if (entry.type !== WireProtocol_1.DpWireType.Struct && entry.type !== WireProtocol_1.DpWireType.List &&
130
+ entry.type !== WireProtocol_1.DpWireType.Map && entry.type !== WireProtocol_1.DpWireType.Set) {
131
+ if (entry.col <= 0 || this._sheet.isCellEmpty(this._dataRow, entry.col))
132
+ continue;
133
+ }
134
+ if (entry.type === WireProtocol_1.DpWireType.Struct && !this.hasAnyChildData(entry.path))
135
+ continue;
136
+ if (entry.type === WireProtocol_1.DpWireType.List && this.countListElements(entry) === 0)
137
+ continue;
138
+ this._lastField = entry;
139
+ if (entry.type === WireProtocol_1.DpWireType.Struct) {
140
+ this._pathStack.push(this._currentPath);
141
+ this._currentPath = entry.path;
142
+ }
143
+ return { name: entry.path, type: entry.type, id: entry.id };
144
+ }
145
+ return { name: '', type: WireProtocol_1.DpWireType.Stop, id: 0 };
146
+ }
147
+ readFieldEnd() { }
148
+ hasAnyChildData(parentPath) {
149
+ const prefix = parentPath + '.';
150
+ for (const [path, col] of this._fieldIdToCol) {
151
+ if (!path.startsWith(prefix))
152
+ continue;
153
+ const dt = this._colDataType.get(col);
154
+ if (dt) {
155
+ const lower = dt.toLowerCase();
156
+ if (lower === 'rec' || lower === 'record' || lower.startsWith('lst') || lower.startsWith('list') ||
157
+ lower.startsWith('set') || lower.startsWith('map'))
158
+ continue;
159
+ }
160
+ if (!this._sheet.isCellEmpty(this._dataRow, col))
161
+ return true;
162
+ }
163
+ return false;
164
+ }
165
+ // ─── Read - List ───
166
+ countListElements(listField) {
167
+ const rootCol = listField.col;
168
+ const prefix = listField.path + '.';
169
+ let count = 0;
170
+ const metaId = this._sheet.cellValue(this._dataRow, 1) ?? '';
171
+ for (let r = this._dataRow; r <= this._sheet.lastRow; r++) {
172
+ if (r > this._dataRow) {
173
+ const rid = this._sheet.cellValue(r, 1) ?? '';
174
+ if (rid && rid !== metaId)
175
+ break;
176
+ }
177
+ let hasData = false;
178
+ if (rootCol > 0 && !this._sheet.isCellEmpty(r, rootCol))
179
+ hasData = true;
180
+ if (!hasData) {
181
+ for (const [p, c] of this._fieldIdToCol) {
182
+ if (p.startsWith(prefix) && !this._sheet.isCellEmpty(r, c)) {
183
+ hasData = true;
184
+ break;
185
+ }
186
+ }
187
+ }
188
+ if (hasData)
189
+ count++;
190
+ else if (count > 0)
191
+ break;
192
+ }
193
+ return count;
194
+ }
195
+ inferListElementType(listEntry) {
196
+ const dt = (listEntry.col > 0 ? this._colDataType.get(listEntry.col) : undefined) ?? 'list';
197
+ const lt = dt.indexOf('<');
198
+ if (lt >= 0) {
199
+ return dataTypeToDpWireType(extractContainerElemType(dt));
200
+ }
201
+ const prefix = listEntry.path + '.';
202
+ const childIds = new Map();
203
+ for (const [path, col] of this._fieldIdToCol) {
204
+ if (!path.startsWith(prefix))
205
+ continue;
206
+ const remainder = path.substring(prefix.length);
207
+ const dotPos = remainder.indexOf('.');
208
+ const firstSeg = dotPos >= 0 ? remainder.substring(0, dotPos) : remainder;
209
+ const fid = parseInt(firstSeg, 10);
210
+ if (isNaN(fid))
211
+ continue;
212
+ const childPath = listEntry.path + '.' + firstSeg;
213
+ const isExactChild = (path === childPath);
214
+ if (isExactChild) {
215
+ const childDt = this._colDataType.get(col) ?? '';
216
+ childIds.set(fid, { dt: childDt, col, path: childPath });
217
+ }
218
+ else if (!childIds.has(fid)) {
219
+ const explicitCol = this._fieldIdToCol.get(childPath);
220
+ if (explicitCol !== undefined) {
221
+ const childDt = this._colDataType.get(explicitCol) ?? '';
222
+ childIds.set(fid, { dt: childDt, col: explicitCol, path: childPath });
223
+ }
224
+ else {
225
+ childIds.set(fid, { dt: 'record', col: -1, path: childPath });
226
+ }
227
+ }
228
+ }
229
+ if (childIds.size === 0)
230
+ return WireProtocol_1.DpWireType.Struct;
231
+ if (childIds.size === 1) {
232
+ for (const c of childIds.values()) {
233
+ const childDpWireType = dataTypeToDpWireType(c.dt);
234
+ if (childDpWireType !== WireProtocol_1.DpWireType.Struct && childDpWireType !== WireProtocol_1.DpWireType.List &&
235
+ childDpWireType !== WireProtocol_1.DpWireType.Map && childDpWireType !== WireProtocol_1.DpWireType.Set) {
236
+ return childDpWireType;
237
+ }
238
+ }
239
+ }
240
+ return WireProtocol_1.DpWireType.Struct;
241
+ }
242
+ readListBegin() {
243
+ const entry = this._lastField;
244
+ const elemDpWireType = this.inferListElementType(entry);
245
+ const count = this.countListElements(entry);
246
+ let primitiveElemCol = -1;
247
+ if (elemDpWireType !== WireProtocol_1.DpWireType.Struct) {
248
+ const prefix = entry.path + '.';
249
+ for (const [p, c] of this._fieldIdToCol) {
250
+ if (p.startsWith(prefix)) {
251
+ primitiveElemCol = c;
252
+ break;
253
+ }
254
+ }
255
+ }
256
+ const state = {
257
+ startRow: this._dataRow,
258
+ currentElement: 0,
259
+ count,
260
+ elementType: elemDpWireType,
261
+ rootCol: entry.col,
262
+ listPath: entry.path,
263
+ savedDataRow: this._dataRow,
264
+ structDepth: 0,
265
+ primitiveElemCol
266
+ };
267
+ this._listStack.push(state);
268
+ if (primitiveElemCol > 0) {
269
+ this._lastField = { id: 0, type: elemDpWireType, col: primitiveElemCol, path: entry.path };
270
+ }
271
+ this._pathStack.push(this._currentPath);
272
+ this._currentPath = entry.path;
273
+ return { elementType: elemDpWireType, count };
274
+ }
275
+ readListEnd() {
276
+ if (this._listStack.length > 0) {
277
+ const state = this._listStack.pop();
278
+ this._dataRow = state.savedDataRow;
279
+ }
280
+ if (this._pathStack.length > 0) {
281
+ this._currentPath = this._pathStack.pop();
282
+ }
283
+ }
284
+ advanceListElementIfPrimitive() {
285
+ if (this._listStack.length === 0)
286
+ return;
287
+ const state = this._listStack[this._listStack.length - 1];
288
+ if (state.structDepth > 0)
289
+ return;
290
+ this._dataRow = state.startRow + state.currentElement;
291
+ state.currentElement++;
292
+ }
293
+ // ─── Read - Primitives ───
294
+ readBool() {
295
+ this.advanceListElementIfPrimitive();
296
+ const val = this.readCurrentCellValue();
297
+ if (!val)
298
+ return false;
299
+ if (val === '1')
300
+ return true;
301
+ if (val === '0')
302
+ return false;
303
+ return val.toLowerCase() === 'true';
304
+ }
305
+ readByte() {
306
+ this.advanceListElementIfPrimitive();
307
+ const val = this.readCurrentCellValue();
308
+ if (!val)
309
+ return 0;
310
+ return parseInt(val.split(':')[0].trim(), 10) || 0;
311
+ }
312
+ readI16() {
313
+ this.advanceListElementIfPrimitive();
314
+ const val = this.readCurrentCellValue();
315
+ if (!val)
316
+ return 0;
317
+ return parseInt(val.split(':')[0].trim(), 10) || 0;
318
+ }
319
+ readI32() {
320
+ this.advanceListElementIfPrimitive();
321
+ const val = this.readCurrentCellValue();
322
+ if (!val)
323
+ return 0;
324
+ const token = val.split(':')[0].trim();
325
+ const num = parseInt(token, 10);
326
+ if (!isNaN(num))
327
+ return num;
328
+ return this.resolveEnumName(token);
329
+ }
330
+ readI64() {
331
+ this.advanceListElementIfPrimitive();
332
+ const val = this.readCurrentCellValue();
333
+ if (!val)
334
+ return 0n;
335
+ const token = val.split(':')[0].trim();
336
+ try {
337
+ return BigInt(token);
338
+ }
339
+ catch {
340
+ return 0n;
341
+ }
342
+ }
343
+ readDouble() {
344
+ this.advanceListElementIfPrimitive();
345
+ const val = this.readCurrentCellValue();
346
+ return parseFloat(val) || 0;
347
+ }
348
+ readString() {
349
+ this.advanceListElementIfPrimitive();
350
+ return (this.readCurrentCellValue() ?? '').trim();
351
+ }
352
+ readBinary() {
353
+ this.advanceListElementIfPrimitive();
354
+ const val = this.readCurrentCellValue();
355
+ if (!val)
356
+ return new Uint8Array(0);
357
+ const encoder = new TextEncoder();
358
+ return encoder.encode(val);
359
+ }
360
+ readSetBegin() {
361
+ const lb = this.readListBegin();
362
+ return { elementType: lb.elementType, count: lb.count };
363
+ }
364
+ readSetEnd() { this.readListEnd(); }
365
+ readMapBegin() {
366
+ return { keyType: WireProtocol_1.DpWireType.I64, valueType: WireProtocol_1.DpWireType.Struct, count: 0 };
367
+ }
368
+ readMapEnd() { }
369
+ readCurrentCellValue() {
370
+ if (this._lastField.col <= 0)
371
+ return '';
372
+ return this._sheet.cellValue(this._dataRow, this._lastField.col) ?? '';
373
+ }
374
+ resolveEnumName(name) {
375
+ if (!this._enumResolver)
376
+ return 0;
377
+ if (this._lastField.col <= 0)
378
+ return 0;
379
+ const dt = this._colDataType.get(this._lastField.col);
380
+ if (!dt)
381
+ return 0;
382
+ const enumTypeName = extractContainerElemType(dt);
383
+ if (!enumTypeName || enumTypeName === 'rec' || enumTypeName === 'record')
384
+ return 0;
385
+ return this._enumResolver(enumTypeName, name) ?? 0;
386
+ }
387
+ // ─── Write (placeholder) ───
388
+ writeStructBegin(_s) { }
389
+ writeStructEnd() { }
390
+ writeFieldBegin(_f) { }
391
+ writeFieldEnd() { }
392
+ writeFieldStop() { }
393
+ writeBool(_b) { }
394
+ writeByte(_b) { }
395
+ writeI16(_i16) { }
396
+ writeI32(_i32) { }
397
+ writeI64(_i64) { }
398
+ writeDouble(_d) { }
399
+ writeString(_s) { }
400
+ writeBinary(_b) { }
401
+ writeListBegin(_list) { }
402
+ writeListEnd() { }
403
+ writeSetBegin(_set) { }
404
+ writeSetEnd() { }
405
+ writeMapBegin(_map) { }
406
+ writeMapEnd() { }
407
+ }
408
+ exports.DpExcelProtocol = DpExcelProtocol;
409
+ // ─── Helpers ───
410
+ function dataTypeToDpWireType(dt) {
411
+ if (!dt)
412
+ return WireProtocol_1.DpWireType.String;
413
+ const lower = dt.toLowerCase();
414
+ if (lower === 'int64' || lower === 'i64')
415
+ return WireProtocol_1.DpWireType.I64;
416
+ if (lower === 'int32' || lower === 'i32')
417
+ return WireProtocol_1.DpWireType.I32;
418
+ if (lower === 'int16' || lower === 'i16')
419
+ return WireProtocol_1.DpWireType.I16;
420
+ if (lower === 'int8' || lower === 'i8')
421
+ return WireProtocol_1.DpWireType.Byte;
422
+ if (lower === 'float')
423
+ return WireProtocol_1.DpWireType.Double;
424
+ if (lower === 'str')
425
+ return WireProtocol_1.DpWireType.String;
426
+ if (lower === 'dbl')
427
+ return WireProtocol_1.DpWireType.Double;
428
+ if (lower === 'tf')
429
+ return WireProtocol_1.DpWireType.Bool;
430
+ if (lower === 'rec' || lower === 'record')
431
+ return WireProtocol_1.DpWireType.Struct;
432
+ if (lower.startsWith('lst') || lower.startsWith('list'))
433
+ return WireProtocol_1.DpWireType.List;
434
+ if (lower.startsWith('set'))
435
+ return WireProtocol_1.DpWireType.Set;
436
+ if (lower.startsWith('map'))
437
+ return WireProtocol_1.DpWireType.Map;
438
+ if (lower.startsWith('enum'))
439
+ return WireProtocol_1.DpWireType.I32;
440
+ return WireProtocol_1.DpWireType.String;
441
+ }
442
+ function extractContainerElemType(dt) {
443
+ const lt = dt.indexOf('<');
444
+ const gt = dt.lastIndexOf('>');
445
+ if (lt >= 0 && gt > lt)
446
+ return dt.substring(lt + 1, gt).trim();
447
+ return 'record';
448
+ }
449
+ /**
450
+ * Schema-driven Excel reader for plain JS objects (no DpProtocol / generated Read()).
451
+ * Used by meta editor JS runtime to create objects from Excel sheets.
452
+ */
453
+ function fromExcelRow(schema, sheet, row, schemas, enumMap) {
454
+ if (!schema || schema.type !== 'Struct' || !schema.fields)
455
+ return {};
456
+ const colMap = buildColMap(sheet);
457
+ const result = {};
458
+ const fields = schema.fields;
459
+ for (const fid of Object.keys(fields)) {
460
+ const field = fields[fid];
461
+ const val = readFieldValue(field, fid, colMap, sheet, row, schemas, enumMap, '');
462
+ if (val !== undefined && val !== null) {
463
+ result[field['name']] = val;
464
+ }
465
+ }
466
+ return result;
467
+ }
468
+ /**
469
+ * Read all records from an Excel sheet.
470
+ * Returns a map of metaId → object (matching the container.Infos structure).
471
+ */
472
+ function fromExcelSheet(schema, sheet, schemas, enumMap, firstDataRow = exports.FIRST_DATA_ROW) {
473
+ const result = new Map();
474
+ for (let row = firstDataRow; row <= sheet.lastRow; row++) {
475
+ const metaIdStr = sheet.cellValue(row, 1);
476
+ if (!metaIdStr)
477
+ continue;
478
+ const metaId = parseInt(metaIdStr.split(':')[0].trim(), 10);
479
+ if (isNaN(metaId))
480
+ continue;
481
+ const obj = fromExcelRow(schema, sheet, row, schemas, enumMap);
482
+ result.set(metaId, obj);
483
+ }
484
+ return result;
485
+ }
486
+ function buildColMap(sheet) {
487
+ const map = new Map();
488
+ for (let col = 1; col <= sheet.lastColumn; col++) {
489
+ const hier = sheet.cellValue(exports.HIERARCHY_ID_ROW, col)?.trim();
490
+ if (!hier)
491
+ break;
492
+ const dt = sheet.cellValue(exports.DATATYPE_ROW, col)?.trim() ?? '';
493
+ map.set(hier, { col, datatype: dt });
494
+ }
495
+ return map;
496
+ }
497
+ function readFieldValue(field, fieldId, colMap, sheet, row, schemas, enumMap, parentPath) {
498
+ const fieldPath = parentPath ? parentPath + '.' + fieldId : fieldId;
499
+ const type = field['type'];
500
+ const typeName = field['typeName'];
501
+ if (type === 'Struct') {
502
+ const childSchema = schemas[typeName];
503
+ if (!childSchema?.['fields'])
504
+ return undefined;
505
+ const obj = {};
506
+ let hasData = false;
507
+ const childFields = childSchema['fields'];
508
+ for (const cid of Object.keys(childFields)) {
509
+ const cf = childFields[cid];
510
+ const val = readFieldValue(cf, cid, colMap, sheet, row, schemas, enumMap, fieldPath);
511
+ if (val !== undefined && val !== null) {
512
+ obj[cf['name']] = val;
513
+ hasData = true;
514
+ }
515
+ }
516
+ return hasData ? obj : undefined;
517
+ }
518
+ if (type === 'List' || type === 'Set') {
519
+ return readListValue(fieldPath, typeName, colMap, sheet, row, schemas, enumMap);
520
+ }
521
+ const entry = colMap.get(fieldPath);
522
+ if (!entry)
523
+ return undefined;
524
+ if (sheet.isCellEmpty(row, entry.col))
525
+ return undefined;
526
+ const raw = sheet.cellValue(row, entry.col) ?? '';
527
+ return parsePrimitiveValue(type, raw, entry.datatype, enumMap);
528
+ }
529
+ function readListValue(listPath, typeName, colMap, sheet, row, schemas, enumMap) {
530
+ const prefix = listPath + '.';
531
+ const metaId = sheet.cellValue(row, 1) ?? '';
532
+ let count = 0;
533
+ for (let r = row; r <= sheet.lastRow; r++) {
534
+ if (r > row) {
535
+ const rid = sheet.cellValue(r, 1) ?? '';
536
+ if (rid && rid !== metaId)
537
+ break;
538
+ }
539
+ let hasData = false;
540
+ for (const [p, e] of colMap) {
541
+ if ((p === listPath || p.startsWith(prefix)) && !sheet.isCellEmpty(r, e.col)) {
542
+ hasData = true;
543
+ break;
544
+ }
545
+ }
546
+ if (hasData)
547
+ count++;
548
+ else if (count > 0)
549
+ break;
550
+ }
551
+ if (count === 0)
552
+ return undefined;
553
+ const elemMatch = typeName.match(/^(?:list|set)<(.+)>$/i);
554
+ const elemTypeName = elemMatch ? elemMatch[1] : (typeName && typeName.trim()) || 'record';
555
+ const primitiveTypes = ['int32', 'int64', 'int16', 'int8', 'float', 'double', 'string', 'bool', 'byte'];
556
+ const elemIsPrimitive = primitiveTypes.includes(elemTypeName);
557
+ const result = [];
558
+ for (let i = 0; i < count; i++) {
559
+ const elemRow = row + i;
560
+ if (elemIsPrimitive) {
561
+ for (const [p, e] of colMap) {
562
+ if (p.startsWith(prefix)) {
563
+ const raw = sheet.cellValue(elemRow, e.col) ?? '';
564
+ result.push(parsePrimitiveValue(mapSchemaTypeToWire(elemTypeName), raw, e.datatype, enumMap));
565
+ break;
566
+ }
567
+ }
568
+ }
569
+ else {
570
+ const elemSchema = schemas[elemTypeName];
571
+ if (elemSchema?.['fields']) {
572
+ const obj = {};
573
+ const childFields = elemSchema['fields'];
574
+ for (const cid of Object.keys(childFields)) {
575
+ const cf = childFields[cid];
576
+ const val = readFieldValue(cf, cid, colMap, sheet, elemRow, schemas, enumMap, listPath);
577
+ if (val !== undefined && val !== null)
578
+ obj[cf['name']] = val;
579
+ }
580
+ result.push(obj);
581
+ }
582
+ else {
583
+ const obj = {};
584
+ for (const [p, e] of colMap) {
585
+ if (!p.startsWith(prefix))
586
+ continue;
587
+ const remainder = p.substring(prefix.length);
588
+ if (remainder.includes('.'))
589
+ continue;
590
+ if (!sheet.isCellEmpty(elemRow, e.col)) {
591
+ obj[remainder] = sheet.cellValue(elemRow, e.col);
592
+ }
593
+ }
594
+ result.push(obj);
595
+ }
596
+ }
597
+ }
598
+ return result.length > 0 ? result : undefined;
599
+ }
600
+ function parsePrimitiveValue(type, raw, datatype, enumMap) {
601
+ if (!raw && raw !== '0')
602
+ return type === 'String' ? '' : undefined;
603
+ const token = raw.split(':')[0].trim();
604
+ switch (type) {
605
+ case 'Bool': return token === '1' || token.toLowerCase() === 'true';
606
+ case 'Byte':
607
+ case 'I16':
608
+ case 'I32': {
609
+ const n = parseInt(token, 10);
610
+ if (!isNaN(n))
611
+ return n;
612
+ if (enumMap && datatype.startsWith('enum')) {
613
+ const enumTypeName = extractContainerElemType(datatype);
614
+ const enumDef = enumMap[enumTypeName];
615
+ const values = enumDef?.['values'];
616
+ if (values) {
617
+ const v = values[token];
618
+ if (v !== undefined)
619
+ return v;
620
+ }
621
+ }
622
+ return 0;
623
+ }
624
+ case 'I64': return parseInt(token, 10) || 0;
625
+ case 'Double': return parseFloat(raw) || 0;
626
+ case 'String': return raw.trim();
627
+ default: return raw.trim();
628
+ }
629
+ }
630
+ function mapSchemaTypeToWire(tn) {
631
+ const m = {
632
+ 'int32': 'I32', 'int64': 'I64', 'int16': 'I16', 'int8': 'Byte',
633
+ 'byte': 'Byte', 'float': 'Double',
634
+ 'double': 'Double', 'dbl': 'Double', 'string': 'String', 'str': 'String',
635
+ 'bool': 'Bool', 'tf': 'Bool'
636
+ };
637
+ return m[tn] ?? 'Struct';
638
+ }
639
+ //# sourceMappingURL=ExcelProtocol.js.map