@stryke/capnp 0.9.12 → 0.10.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.
- package/bin/capnpc.cjs +1900 -1880
- package/bin/capnpc.js +2515 -2495
- package/dist/compile.cjs +76 -0
- package/dist/compile.d.cts +38 -0
- package/dist/compile.d.ts +38 -0
- package/dist/compile.js +76 -0
- package/dist/helpers.cjs +52 -0
- package/dist/helpers.d.cts +13 -0
- package/dist/helpers.d.ts +13 -0
- package/dist/helpers.js +52 -0
- package/dist/index.cjs +4 -129
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -129
- package/dist/rpc.cjs +117 -5
- package/dist/rpc.d.cts +25 -7
- package/dist/rpc.d.ts +25 -7
- package/dist/rpc.js +116 -4
- package/dist/types.cjs +8 -3
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.js +8 -3
- package/dts/index.d.cts +650 -490
- package/dts/index.d.ts +650 -490
- package/package.json +21 -5
- package/schemas/{chunk-SCCB7KM2.js → chunk-3CJYH45H.js} +596 -0
- package/schemas/{chunk-3Y2DQ67Z.cjs → chunk-ZGPCLBI4.cjs} +597 -1
- package/schemas/persistent.cjs +20 -20
- package/schemas/persistent.js +1 -1
- package/schemas/rpc-twoparty.cjs +32 -32
- package/schemas/rpc-twoparty.js +1 -1
- package/schemas/rpc.cjs +495 -495
- package/schemas/rpc.js +1 -1
- package/schemas/schema.cjs +675 -675
- package/schemas/schema.js +1 -1
- package/dist/chunk-4Z2FMN72.cjs +0 -7924
- package/dist/chunk-CCU32X36.js +0 -15
- package/dist/chunk-L563IRIF.js +0 -7924
- package/dist/chunk-R2JXWA7Q.cjs +0 -15
package/bin/capnpc.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __export(capnpc_exports, {
|
|
|
34
34
|
createProgram: () => createProgram
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(capnpc_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_console3 = require("@storm-software/config-tools/logger/console");
|
|
38
38
|
var import_utilities = require("@storm-software/config-tools/utilities");
|
|
39
39
|
|
|
40
40
|
// ../path/src/exists.ts
|
|
@@ -61,815 +61,199 @@ async function createDirectory(path) {
|
|
|
61
61
|
}
|
|
62
62
|
__name(createDirectory, "createDirectory");
|
|
63
63
|
|
|
64
|
-
// ../type-checks/src/get-object-tag.ts
|
|
65
|
-
var getObjectTag = /* @__PURE__ */ __name((value) => {
|
|
66
|
-
if (value == null) {
|
|
67
|
-
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
68
|
-
}
|
|
69
|
-
return Object.prototype.toString.call(value);
|
|
70
|
-
}, "getObjectTag");
|
|
71
|
-
|
|
72
|
-
// ../type-checks/src/is-plain-object.ts
|
|
73
|
-
var isObjectLike = /* @__PURE__ */ __name((obj) => {
|
|
74
|
-
return typeof obj === "object" && obj !== null;
|
|
75
|
-
}, "isObjectLike");
|
|
76
|
-
var isPlainObject = /* @__PURE__ */ __name((obj) => {
|
|
77
|
-
if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (Object.getPrototypeOf(obj) === null) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
let proto = obj;
|
|
84
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
85
|
-
proto = Object.getPrototypeOf(proto);
|
|
86
|
-
}
|
|
87
|
-
return Object.getPrototypeOf(obj) === proto;
|
|
88
|
-
}, "isPlainObject");
|
|
89
|
-
|
|
90
|
-
// ../type-checks/src/is-object.ts
|
|
91
|
-
var isObject = /* @__PURE__ */ __name((value) => {
|
|
92
|
-
try {
|
|
93
|
-
return typeof value === "object" || Boolean(value) && value?.constructor === Object || isPlainObject(value);
|
|
94
|
-
} catch {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}, "isObject");
|
|
98
|
-
|
|
99
|
-
// ../type-checks/src/is-string.ts
|
|
100
|
-
var isString = /* @__PURE__ */ __name((value) => {
|
|
101
|
-
try {
|
|
102
|
-
return typeof value === "string";
|
|
103
|
-
} catch {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}, "isString");
|
|
107
|
-
|
|
108
|
-
// ../json/src/storm-json.ts
|
|
109
|
-
var import_jsonc_parser2 = require("jsonc-parser");
|
|
110
|
-
var import_node_buffer = require("buffer");
|
|
111
|
-
var import_superjson = __toESM(require("superjson"), 1);
|
|
112
|
-
|
|
113
64
|
// ../types/src/base.ts
|
|
114
65
|
var EMPTY_STRING = "";
|
|
115
66
|
var $NestedValue = Symbol("NestedValue");
|
|
116
67
|
|
|
117
|
-
// ../
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
function isEscaped(value, quotePosition) {
|
|
129
|
-
let index = quotePosition - 1;
|
|
130
|
-
let backslashCount = 0;
|
|
131
|
-
while (value[index] === "\\") {
|
|
132
|
-
index -= 1;
|
|
133
|
-
backslashCount += 1;
|
|
68
|
+
// ../path/src/file-path-fns.ts
|
|
69
|
+
var import_node_path = require("path");
|
|
70
|
+
|
|
71
|
+
// ../path/src/is-file.ts
|
|
72
|
+
var import_node_fs3 = require("fs");
|
|
73
|
+
|
|
74
|
+
// ../path/src/join-paths.ts
|
|
75
|
+
var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
|
|
76
|
+
function normalizeWindowsPath(input = "") {
|
|
77
|
+
if (!input) {
|
|
78
|
+
return input;
|
|
134
79
|
}
|
|
135
|
-
return
|
|
80
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
136
81
|
}
|
|
137
|
-
__name(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
82
|
+
__name(normalizeWindowsPath, "normalizeWindowsPath");
|
|
83
|
+
var _UNC_REGEX = /^[/\\]{2}/;
|
|
84
|
+
var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
|
|
85
|
+
var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
86
|
+
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
87
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
88
|
+
}, "isAbsolute");
|
|
89
|
+
var correctPaths = /* @__PURE__ */ __name(function(path) {
|
|
90
|
+
if (!path || path.length === 0) {
|
|
91
|
+
return ".";
|
|
141
92
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const currentCharacter = value[index];
|
|
151
|
-
const nextCharacter = value[index + 1];
|
|
152
|
-
if (!isInsideComment && currentCharacter === '"') {
|
|
153
|
-
const escaped = isEscaped(value, index);
|
|
154
|
-
if (!escaped) {
|
|
155
|
-
isInsideString = !isInsideString;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (isInsideString) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
|
|
162
|
-
buffer += value.slice(offset, index);
|
|
163
|
-
offset = index;
|
|
164
|
-
isInsideComment = singleComment;
|
|
165
|
-
index++;
|
|
166
|
-
} else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
|
|
167
|
-
index++;
|
|
168
|
-
isInsideComment = false;
|
|
169
|
-
buffer += strip(value, offset, index);
|
|
170
|
-
offset = index;
|
|
171
|
-
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
172
|
-
isInsideComment = false;
|
|
173
|
-
buffer += strip(value, offset, index);
|
|
174
|
-
offset = index;
|
|
175
|
-
} else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
|
|
176
|
-
buffer += value.slice(offset, index);
|
|
177
|
-
offset = index;
|
|
178
|
-
isInsideComment = multiComment;
|
|
179
|
-
index++;
|
|
180
|
-
} else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
|
|
181
|
-
index++;
|
|
182
|
-
isInsideComment = false;
|
|
183
|
-
buffer += strip(value, offset, index + 1);
|
|
184
|
-
offset = index + 1;
|
|
185
|
-
} else if (trailingCommas && !isInsideComment) {
|
|
186
|
-
if (commaIndex !== -1) {
|
|
187
|
-
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
188
|
-
buffer += value.slice(offset, index);
|
|
189
|
-
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
190
|
-
buffer = "";
|
|
191
|
-
offset = index;
|
|
192
|
-
commaIndex = -1;
|
|
193
|
-
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
194
|
-
buffer += value.slice(offset, index);
|
|
195
|
-
offset = index;
|
|
196
|
-
commaIndex = -1;
|
|
197
|
-
}
|
|
198
|
-
} else if (currentCharacter === ",") {
|
|
199
|
-
result += buffer + value.slice(offset, index);
|
|
200
|
-
buffer = "";
|
|
201
|
-
offset = index;
|
|
202
|
-
commaIndex = index;
|
|
203
|
-
}
|
|
93
|
+
path = normalizeWindowsPath(path);
|
|
94
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
95
|
+
const isPathAbsolute = isAbsolute(path);
|
|
96
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
97
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
98
|
+
if (path.length === 0) {
|
|
99
|
+
if (isPathAbsolute) {
|
|
100
|
+
return "/";
|
|
204
101
|
}
|
|
102
|
+
return trailingSeparator ? "./" : ".";
|
|
205
103
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
__name(stripComments, "stripComments");
|
|
209
|
-
|
|
210
|
-
// ../json/src/utils/parse.ts
|
|
211
|
-
var suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
212
|
-
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
213
|
-
var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
214
|
-
function jsonParseTransform(key, value) {
|
|
215
|
-
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
216
|
-
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
return value;
|
|
220
|
-
}
|
|
221
|
-
__name(jsonParseTransform, "jsonParseTransform");
|
|
222
|
-
function parse(value, options = {}) {
|
|
223
|
-
if (typeof value !== "string") {
|
|
224
|
-
return value;
|
|
104
|
+
if (trailingSeparator) {
|
|
105
|
+
path += "/";
|
|
225
106
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return stripped.slice(1, -1);
|
|
107
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
108
|
+
path += "/";
|
|
229
109
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
case "true": {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
case "false": {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
case "undefined": {
|
|
240
|
-
return void 0;
|
|
241
|
-
}
|
|
242
|
-
case "null": {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
case "nan": {
|
|
246
|
-
return Number.NaN;
|
|
247
|
-
}
|
|
248
|
-
case "infinity": {
|
|
249
|
-
return Number.POSITIVE_INFINITY;
|
|
250
|
-
}
|
|
251
|
-
case "-infinity": {
|
|
252
|
-
return Number.NEGATIVE_INFINITY;
|
|
253
|
-
}
|
|
110
|
+
if (isUNCPath) {
|
|
111
|
+
if (!isPathAbsolute) {
|
|
112
|
+
return `//./${path}`;
|
|
254
113
|
}
|
|
114
|
+
return `//${path}`;
|
|
255
115
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
116
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
117
|
+
}, "correctPaths");
|
|
118
|
+
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
119
|
+
let path = "";
|
|
120
|
+
for (const seg of segments) {
|
|
121
|
+
if (!seg) {
|
|
122
|
+
continue;
|
|
259
123
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
124
|
+
if (path.length > 0) {
|
|
125
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
126
|
+
const segLeading = seg[0] === "/";
|
|
127
|
+
const both = pathTrailing && segLeading;
|
|
128
|
+
if (both) {
|
|
129
|
+
path += seg.slice(1);
|
|
130
|
+
} else {
|
|
131
|
+
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
266
132
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return JSON.parse(stripped);
|
|
270
|
-
} catch (error) {
|
|
271
|
-
if (options.strict) {
|
|
272
|
-
throw error;
|
|
133
|
+
} else {
|
|
134
|
+
path += seg;
|
|
273
135
|
}
|
|
274
|
-
return value;
|
|
275
136
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
];
|
|
321
|
-
} else if (i === lineDiff) {
|
|
322
|
-
markerLines[lineNumber] = [
|
|
323
|
-
0,
|
|
324
|
-
endColumn
|
|
325
|
-
];
|
|
137
|
+
return correctPaths(path);
|
|
138
|
+
}, "joinPaths");
|
|
139
|
+
function normalizeString(path, allowAboveRoot) {
|
|
140
|
+
let res = "";
|
|
141
|
+
let lastSegmentLength = 0;
|
|
142
|
+
let lastSlash = -1;
|
|
143
|
+
let dots = 0;
|
|
144
|
+
let char = null;
|
|
145
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
146
|
+
if (index < path.length) {
|
|
147
|
+
char = path[index];
|
|
148
|
+
} else if (char === "/") {
|
|
149
|
+
break;
|
|
150
|
+
} else {
|
|
151
|
+
char = "/";
|
|
152
|
+
}
|
|
153
|
+
if (char === "/") {
|
|
154
|
+
if (lastSlash === index - 1 || dots === 1) {
|
|
155
|
+
} else if (dots === 2) {
|
|
156
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
157
|
+
if (res.length > 2) {
|
|
158
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
159
|
+
if (lastSlashIndex === -1) {
|
|
160
|
+
res = "";
|
|
161
|
+
lastSegmentLength = 0;
|
|
162
|
+
} else {
|
|
163
|
+
res = res.slice(0, lastSlashIndex);
|
|
164
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
165
|
+
}
|
|
166
|
+
lastSlash = index;
|
|
167
|
+
dots = 0;
|
|
168
|
+
continue;
|
|
169
|
+
} else if (res.length > 0) {
|
|
170
|
+
res = "";
|
|
171
|
+
lastSegmentLength = 0;
|
|
172
|
+
lastSlash = index;
|
|
173
|
+
dots = 0;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (allowAboveRoot) {
|
|
178
|
+
res += res.length > 0 ? "/.." : "..";
|
|
179
|
+
lastSegmentLength = 2;
|
|
180
|
+
}
|
|
326
181
|
} else {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
182
|
+
if (res.length > 0) {
|
|
183
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
184
|
+
} else {
|
|
185
|
+
res = path.slice(lastSlash + 1, index);
|
|
186
|
+
}
|
|
187
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
332
188
|
}
|
|
189
|
+
lastSlash = index;
|
|
190
|
+
dots = 0;
|
|
191
|
+
} else if (char === "." && dots !== -1) {
|
|
192
|
+
++dots;
|
|
193
|
+
} else {
|
|
194
|
+
dots = -1;
|
|
333
195
|
}
|
|
334
|
-
} else if (startColumn === endColumn) {
|
|
335
|
-
markerLines[startLine] = startColumn ? [
|
|
336
|
-
startColumn,
|
|
337
|
-
0
|
|
338
|
-
] : true;
|
|
339
|
-
} else {
|
|
340
|
-
markerLines[startLine] = [
|
|
341
|
-
startColumn,
|
|
342
|
-
endColumn - startColumn
|
|
343
|
-
];
|
|
344
196
|
}
|
|
345
|
-
return
|
|
346
|
-
start,
|
|
347
|
-
end,
|
|
348
|
-
markerLines
|
|
349
|
-
};
|
|
197
|
+
return res;
|
|
350
198
|
}
|
|
351
|
-
__name(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (hasMarker) {
|
|
363
|
-
let markerLine = "";
|
|
364
|
-
if (Array.isArray(hasMarker)) {
|
|
365
|
-
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
366
|
-
const numberOfMarkers = hasMarker[1] || 1;
|
|
367
|
-
markerLine = [
|
|
368
|
-
"\n ",
|
|
369
|
-
gutter.replace(/\d/g, " "),
|
|
370
|
-
markerSpacing,
|
|
371
|
-
"^".repeat(numberOfMarkers)
|
|
372
|
-
].join("");
|
|
373
|
-
}
|
|
374
|
-
return [
|
|
375
|
-
">",
|
|
376
|
-
gutter,
|
|
377
|
-
line,
|
|
378
|
-
markerLine
|
|
379
|
-
].join("");
|
|
380
|
-
}
|
|
381
|
-
return ` ${gutter}${line}`;
|
|
382
|
-
}).join("\n");
|
|
383
|
-
return frame;
|
|
199
|
+
__name(normalizeString, "normalizeString");
|
|
200
|
+
|
|
201
|
+
// ../path/src/regex.ts
|
|
202
|
+
var DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
|
|
203
|
+
|
|
204
|
+
// ../path/src/slash.ts
|
|
205
|
+
function slash(path) {
|
|
206
|
+
if (path.startsWith("\\\\?\\")) {
|
|
207
|
+
return path;
|
|
208
|
+
}
|
|
209
|
+
return path.replace(/\\/g, "/");
|
|
384
210
|
}
|
|
385
|
-
__name(
|
|
211
|
+
__name(slash, "slash");
|
|
386
212
|
|
|
387
|
-
// ../
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
line++;
|
|
394
|
-
column++;
|
|
395
|
-
return `${(0, import_jsonc_parser.printParseErrorCode)(error)} in JSON at ${line}:${column}
|
|
396
|
-
${codeFrameColumns(input, {
|
|
397
|
-
start: {
|
|
398
|
-
line,
|
|
399
|
-
column
|
|
400
|
-
},
|
|
401
|
-
end: {
|
|
402
|
-
line,
|
|
403
|
-
column: column + length
|
|
404
|
-
}
|
|
405
|
-
})}
|
|
406
|
-
`;
|
|
213
|
+
// ../path/src/correct-path.ts
|
|
214
|
+
function normalizeWindowsPath2(input = "") {
|
|
215
|
+
if (!input) {
|
|
216
|
+
return input;
|
|
217
|
+
}
|
|
218
|
+
return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
407
219
|
}
|
|
408
|
-
__name(
|
|
220
|
+
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
409
221
|
|
|
410
|
-
// ../
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
222
|
+
// ../path/src/get-workspace-root.ts
|
|
223
|
+
var import_config_tools = require("@storm-software/config-tools");
|
|
224
|
+
|
|
225
|
+
// ../path/src/file-path-fns.ts
|
|
226
|
+
function findFileName(filePath, options = {}) {
|
|
227
|
+
const { requireExtension = false, withExtension = true } = options;
|
|
228
|
+
const result = normalizeWindowsPath2(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
229
|
+
if (requireExtension === true && !result.includes(".")) {
|
|
230
|
+
return EMPTY_STRING;
|
|
416
231
|
}
|
|
417
|
-
|
|
232
|
+
if (withExtension === false && result.includes(".")) {
|
|
233
|
+
return result.substring(0, result.lastIndexOf(".")) || EMPTY_STRING;
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
__name(findFileName, "findFileName");
|
|
238
|
+
function findFilePath(filePath) {
|
|
239
|
+
const normalizedPath = normalizeWindowsPath2(filePath);
|
|
240
|
+
const result = normalizedPath.replace(findFileName(normalizedPath, {
|
|
241
|
+
requireExtension: true
|
|
242
|
+
}), "");
|
|
243
|
+
return result === "/" ? result : result.replace(/\/$/, "");
|
|
244
|
+
}
|
|
245
|
+
__name(findFilePath, "findFilePath");
|
|
246
|
+
function relativePath(from, to, withEndSlash = false) {
|
|
247
|
+
return (0, import_node_path.relative)(withEndSlash !== true ? from.replace(/\/$/, "") : from, withEndSlash !== true ? to.replace(/\/$/, "") : to);
|
|
248
|
+
}
|
|
249
|
+
__name(relativePath, "relativePath");
|
|
418
250
|
|
|
419
|
-
//
|
|
420
|
-
var
|
|
421
|
-
|
|
422
|
-
}, "isUndefined");
|
|
251
|
+
// bin/capnpc.ts
|
|
252
|
+
var import_commander = require("commander");
|
|
253
|
+
var import_promises5 = require("fs/promises");
|
|
423
254
|
|
|
424
|
-
//
|
|
425
|
-
var
|
|
426
|
-
"@",
|
|
427
|
-
"/",
|
|
428
|
-
"#",
|
|
429
|
-
"$",
|
|
430
|
-
" ",
|
|
431
|
-
":",
|
|
432
|
-
";",
|
|
433
|
-
",",
|
|
434
|
-
".",
|
|
435
|
-
"!",
|
|
436
|
-
"?",
|
|
437
|
-
"&",
|
|
438
|
-
"=",
|
|
439
|
-
"+",
|
|
440
|
-
"-",
|
|
441
|
-
"*",
|
|
442
|
-
"%",
|
|
443
|
-
"^",
|
|
444
|
-
"~",
|
|
445
|
-
"|",
|
|
446
|
-
"\\",
|
|
447
|
-
'"',
|
|
448
|
-
"'",
|
|
449
|
-
"`",
|
|
450
|
-
"{",
|
|
451
|
-
"}",
|
|
452
|
-
"[",
|
|
453
|
-
"]",
|
|
454
|
-
"(",
|
|
455
|
-
")",
|
|
456
|
-
"<",
|
|
457
|
-
">"
|
|
458
|
-
];
|
|
459
|
-
var stringify = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
460
|
-
const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
|
|
461
|
-
switch (value) {
|
|
462
|
-
case null: {
|
|
463
|
-
return "null";
|
|
464
|
-
}
|
|
465
|
-
case void 0: {
|
|
466
|
-
return '"undefined"';
|
|
467
|
-
}
|
|
468
|
-
case true: {
|
|
469
|
-
return "true";
|
|
470
|
-
}
|
|
471
|
-
case false: {
|
|
472
|
-
return "false";
|
|
473
|
-
}
|
|
474
|
-
case Number.POSITIVE_INFINITY: {
|
|
475
|
-
return "infinity";
|
|
476
|
-
}
|
|
477
|
-
case Number.NEGATIVE_INFINITY: {
|
|
478
|
-
return "-infinity";
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if (Array.isArray(value)) {
|
|
482
|
-
return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
|
|
483
|
-
}
|
|
484
|
-
if (value instanceof Uint8Array) {
|
|
485
|
-
return value.toString();
|
|
486
|
-
}
|
|
487
|
-
switch (typeof value) {
|
|
488
|
-
case "number": {
|
|
489
|
-
return `${value}`;
|
|
490
|
-
}
|
|
491
|
-
case "string": {
|
|
492
|
-
return JSON.stringify(value);
|
|
493
|
-
}
|
|
494
|
-
case "object": {
|
|
495
|
-
const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
|
|
496
|
-
return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
|
|
497
|
-
}
|
|
498
|
-
default:
|
|
499
|
-
return "null";
|
|
500
|
-
}
|
|
501
|
-
}, "stringify");
|
|
502
|
-
|
|
503
|
-
// ../json/src/storm-json.ts
|
|
504
|
-
var StormJSON = class _StormJSON extends import_superjson.default {
|
|
505
|
-
static {
|
|
506
|
-
__name(this, "StormJSON");
|
|
507
|
-
}
|
|
508
|
-
static #instance;
|
|
509
|
-
static get instance() {
|
|
510
|
-
if (!_StormJSON.#instance) {
|
|
511
|
-
_StormJSON.#instance = new _StormJSON();
|
|
512
|
-
}
|
|
513
|
-
return _StormJSON.#instance;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Deserialize the given value with superjson using the given metadata
|
|
517
|
-
*/
|
|
518
|
-
static deserialize(payload) {
|
|
519
|
-
return _StormJSON.instance.deserialize(payload);
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Serialize the given value with superjson
|
|
523
|
-
*/
|
|
524
|
-
static serialize(object) {
|
|
525
|
-
return _StormJSON.instance.serialize(object);
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Parse the given string value with superjson using the given metadata
|
|
529
|
-
*
|
|
530
|
-
* @param value - The string value to parse
|
|
531
|
-
* @returns The parsed data
|
|
532
|
-
*/
|
|
533
|
-
static parse(value) {
|
|
534
|
-
return parse(value);
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Serializes the given data to a JSON string.
|
|
538
|
-
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
539
|
-
*
|
|
540
|
-
* @param value - Object which should be serialized to JSON
|
|
541
|
-
* @param _options - JSON serialize options
|
|
542
|
-
* @returns the formatted JSON representation of the object
|
|
543
|
-
*/
|
|
544
|
-
static stringify(value, _options) {
|
|
545
|
-
const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
546
|
-
let result = value;
|
|
547
|
-
if (customTransformer && customTransformer.isApplicable(value)) {
|
|
548
|
-
result = customTransformer.serialize(result);
|
|
549
|
-
}
|
|
550
|
-
return stringify(result);
|
|
551
|
-
}
|
|
552
|
-
/**
|
|
553
|
-
* Parses the given JSON string and returns the object the JSON content represents.
|
|
554
|
-
* By default javascript-style comments and trailing commas are allowed.
|
|
555
|
-
*
|
|
556
|
-
* @param strData - JSON content as string
|
|
557
|
-
* @param options - JSON parse options
|
|
558
|
-
* @returns Object the JSON content represents
|
|
559
|
-
*/
|
|
560
|
-
static parseJson(strData, options) {
|
|
561
|
-
try {
|
|
562
|
-
if (options?.expectComments === false) {
|
|
563
|
-
return _StormJSON.instance.parse(strData);
|
|
564
|
-
}
|
|
565
|
-
} catch {
|
|
566
|
-
}
|
|
567
|
-
const errors = [];
|
|
568
|
-
const opts = {
|
|
569
|
-
allowTrailingComma: true,
|
|
570
|
-
...options
|
|
571
|
-
};
|
|
572
|
-
const result = (0, import_jsonc_parser2.parse)(strData, errors, opts);
|
|
573
|
-
if (errors.length > 0 && errors[0]) {
|
|
574
|
-
throw new Error(formatParseError(strData, errors[0]));
|
|
575
|
-
}
|
|
576
|
-
return result;
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Register a custom schema with superjson
|
|
580
|
-
*
|
|
581
|
-
* @param name - The name of the schema
|
|
582
|
-
* @param serialize - The function to serialize the schema
|
|
583
|
-
* @param deserialize - The function to deserialize the schema
|
|
584
|
-
* @param isApplicable - The function to check if the schema is applicable
|
|
585
|
-
*/
|
|
586
|
-
static register(name, serialize, deserialize, isApplicable) {
|
|
587
|
-
_StormJSON.instance.registerCustom({
|
|
588
|
-
isApplicable,
|
|
589
|
-
serialize,
|
|
590
|
-
deserialize
|
|
591
|
-
}, name);
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Register a class with superjson
|
|
595
|
-
*
|
|
596
|
-
* @param classConstructor - The class constructor to register
|
|
597
|
-
*/
|
|
598
|
-
static registerClass(classConstructor, options) {
|
|
599
|
-
_StormJSON.instance.registerClass(classConstructor, {
|
|
600
|
-
identifier: isString(options) ? options : options?.identifier || classConstructor.name,
|
|
601
|
-
allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : [
|
|
602
|
-
"__typename"
|
|
603
|
-
]
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
constructor() {
|
|
607
|
-
super({
|
|
608
|
-
dedupe: true
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
StormJSON.instance.registerCustom({
|
|
613
|
-
isApplicable: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.isBuffer(v), "isApplicable"),
|
|
614
|
-
serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
|
|
615
|
-
deserialize: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.from(v, "base64"), "deserialize")
|
|
616
|
-
}, "Bytes");
|
|
617
|
-
|
|
618
|
-
// ../type-checks/src/is-error.ts
|
|
619
|
-
var isError = /* @__PURE__ */ __name((obj) => {
|
|
620
|
-
if (!isObject(obj)) {
|
|
621
|
-
return false;
|
|
622
|
-
}
|
|
623
|
-
const tag = getObjectTag(obj);
|
|
624
|
-
return tag === "[object Error]" || tag === "[object DOMException]" || typeof obj?.message === "string" && typeof obj?.name === "string" && !isPlainObject(obj);
|
|
625
|
-
}, "isError");
|
|
626
|
-
|
|
627
|
-
// ../fs/src/read-file.ts
|
|
628
|
-
var import_node_fs3 = require("fs");
|
|
629
|
-
var import_promises3 = require("fs/promises");
|
|
630
|
-
var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
|
|
631
|
-
try {
|
|
632
|
-
if (!filePath) {
|
|
633
|
-
throw new Error("No file path provided to read data");
|
|
634
|
-
}
|
|
635
|
-
return await (0, import_promises3.readFile)(filePath, {
|
|
636
|
-
encoding: "utf8"
|
|
637
|
-
});
|
|
638
|
-
} catch {
|
|
639
|
-
throw new Error("An error occurred writing data to file");
|
|
640
|
-
}
|
|
641
|
-
}, "readFile");
|
|
642
|
-
|
|
643
|
-
// ../path/src/is-file.ts
|
|
644
|
-
var import_node_fs4 = require("fs");
|
|
645
|
-
|
|
646
|
-
// ../path/src/join-paths.ts
|
|
647
|
-
var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
|
|
648
|
-
function normalizeWindowsPath(input = "") {
|
|
649
|
-
if (!input) {
|
|
650
|
-
return input;
|
|
651
|
-
}
|
|
652
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
653
|
-
}
|
|
654
|
-
__name(normalizeWindowsPath, "normalizeWindowsPath");
|
|
655
|
-
var _UNC_REGEX = /^[/\\]{2}/;
|
|
656
|
-
var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
|
|
657
|
-
var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
658
|
-
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
659
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
660
|
-
}, "isAbsolute");
|
|
661
|
-
var correctPaths = /* @__PURE__ */ __name(function(path) {
|
|
662
|
-
if (!path || path.length === 0) {
|
|
663
|
-
return ".";
|
|
664
|
-
}
|
|
665
|
-
path = normalizeWindowsPath(path);
|
|
666
|
-
const isUNCPath = path.match(_UNC_REGEX);
|
|
667
|
-
const isPathAbsolute = isAbsolute(path);
|
|
668
|
-
const trailingSeparator = path[path.length - 1] === "/";
|
|
669
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
670
|
-
if (path.length === 0) {
|
|
671
|
-
if (isPathAbsolute) {
|
|
672
|
-
return "/";
|
|
673
|
-
}
|
|
674
|
-
return trailingSeparator ? "./" : ".";
|
|
675
|
-
}
|
|
676
|
-
if (trailingSeparator) {
|
|
677
|
-
path += "/";
|
|
678
|
-
}
|
|
679
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
680
|
-
path += "/";
|
|
681
|
-
}
|
|
682
|
-
if (isUNCPath) {
|
|
683
|
-
if (!isPathAbsolute) {
|
|
684
|
-
return `//./${path}`;
|
|
685
|
-
}
|
|
686
|
-
return `//${path}`;
|
|
687
|
-
}
|
|
688
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
689
|
-
}, "correctPaths");
|
|
690
|
-
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
691
|
-
let path = "";
|
|
692
|
-
for (const seg of segments) {
|
|
693
|
-
if (!seg) {
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
if (path.length > 0) {
|
|
697
|
-
const pathTrailing = path[path.length - 1] === "/";
|
|
698
|
-
const segLeading = seg[0] === "/";
|
|
699
|
-
const both = pathTrailing && segLeading;
|
|
700
|
-
if (both) {
|
|
701
|
-
path += seg.slice(1);
|
|
702
|
-
} else {
|
|
703
|
-
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
704
|
-
}
|
|
705
|
-
} else {
|
|
706
|
-
path += seg;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
return correctPaths(path);
|
|
710
|
-
}, "joinPaths");
|
|
711
|
-
function normalizeString(path, allowAboveRoot) {
|
|
712
|
-
let res = "";
|
|
713
|
-
let lastSegmentLength = 0;
|
|
714
|
-
let lastSlash = -1;
|
|
715
|
-
let dots = 0;
|
|
716
|
-
let char = null;
|
|
717
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
718
|
-
if (index < path.length) {
|
|
719
|
-
char = path[index];
|
|
720
|
-
} else if (char === "/") {
|
|
721
|
-
break;
|
|
722
|
-
} else {
|
|
723
|
-
char = "/";
|
|
724
|
-
}
|
|
725
|
-
if (char === "/") {
|
|
726
|
-
if (lastSlash === index - 1 || dots === 1) {
|
|
727
|
-
} else if (dots === 2) {
|
|
728
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
729
|
-
if (res.length > 2) {
|
|
730
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
731
|
-
if (lastSlashIndex === -1) {
|
|
732
|
-
res = "";
|
|
733
|
-
lastSegmentLength = 0;
|
|
734
|
-
} else {
|
|
735
|
-
res = res.slice(0, lastSlashIndex);
|
|
736
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
737
|
-
}
|
|
738
|
-
lastSlash = index;
|
|
739
|
-
dots = 0;
|
|
740
|
-
continue;
|
|
741
|
-
} else if (res.length > 0) {
|
|
742
|
-
res = "";
|
|
743
|
-
lastSegmentLength = 0;
|
|
744
|
-
lastSlash = index;
|
|
745
|
-
dots = 0;
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
if (allowAboveRoot) {
|
|
750
|
-
res += res.length > 0 ? "/.." : "..";
|
|
751
|
-
lastSegmentLength = 2;
|
|
752
|
-
}
|
|
753
|
-
} else {
|
|
754
|
-
if (res.length > 0) {
|
|
755
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
756
|
-
} else {
|
|
757
|
-
res = path.slice(lastSlash + 1, index);
|
|
758
|
-
}
|
|
759
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
760
|
-
}
|
|
761
|
-
lastSlash = index;
|
|
762
|
-
dots = 0;
|
|
763
|
-
} else if (char === "." && dots !== -1) {
|
|
764
|
-
++dots;
|
|
765
|
-
} else {
|
|
766
|
-
dots = -1;
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return res;
|
|
770
|
-
}
|
|
771
|
-
__name(normalizeString, "normalizeString");
|
|
772
|
-
|
|
773
|
-
// ../path/src/regex.ts
|
|
774
|
-
var DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
|
|
775
|
-
|
|
776
|
-
// ../path/src/slash.ts
|
|
777
|
-
function slash(path) {
|
|
778
|
-
if (path.startsWith("\\\\?\\")) {
|
|
779
|
-
return path;
|
|
780
|
-
}
|
|
781
|
-
return path.replace(/\\/g, "/");
|
|
782
|
-
}
|
|
783
|
-
__name(slash, "slash");
|
|
784
|
-
|
|
785
|
-
// ../path/src/correct-path.ts
|
|
786
|
-
function normalizeWindowsPath2(input = "") {
|
|
787
|
-
if (!input) {
|
|
788
|
-
return input;
|
|
789
|
-
}
|
|
790
|
-
return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
791
|
-
}
|
|
792
|
-
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
793
|
-
|
|
794
|
-
// ../path/src/file-path-fns.ts
|
|
795
|
-
var import_node_path = require("path");
|
|
796
|
-
|
|
797
|
-
// ../path/src/get-workspace-root.ts
|
|
798
|
-
var import_config_tools = require("@storm-software/config-tools");
|
|
799
|
-
|
|
800
|
-
// ../path/src/file-path-fns.ts
|
|
801
|
-
function findFileName(filePath, options = {}) {
|
|
802
|
-
const { requireExtension = false, withExtension = true } = options;
|
|
803
|
-
const result = normalizeWindowsPath2(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
804
|
-
if (requireExtension === true && !result.includes(".")) {
|
|
805
|
-
return EMPTY_STRING;
|
|
806
|
-
}
|
|
807
|
-
if (withExtension === false && result.includes(".")) {
|
|
808
|
-
return result.substring(0, result.lastIndexOf(".")) || EMPTY_STRING;
|
|
809
|
-
}
|
|
810
|
-
return result;
|
|
811
|
-
}
|
|
812
|
-
__name(findFileName, "findFileName");
|
|
813
|
-
function findFilePath(filePath) {
|
|
814
|
-
const normalizedPath = normalizeWindowsPath2(filePath);
|
|
815
|
-
const result = normalizedPath.replace(findFileName(normalizedPath, {
|
|
816
|
-
requireExtension: true
|
|
817
|
-
}), "");
|
|
818
|
-
return result === "/" ? result : result.replace(/\/$/, "");
|
|
819
|
-
}
|
|
820
|
-
__name(findFilePath, "findFilePath");
|
|
821
|
-
function relativePath(from, to, withEndSlash = false) {
|
|
822
|
-
return (0, import_node_path.relative)(withEndSlash !== true ? from.replace(/\/$/, "") : from, withEndSlash !== true ? to.replace(/\/$/, "") : to);
|
|
823
|
-
}
|
|
824
|
-
__name(relativePath, "relativePath");
|
|
825
|
-
|
|
826
|
-
// ../fs/src/write-file.ts
|
|
827
|
-
var import_node_fs5 = require("fs");
|
|
828
|
-
var import_promises4 = require("fs/promises");
|
|
829
|
-
|
|
830
|
-
// ../fs/src/json.ts
|
|
831
|
-
async function readJsonFile(path, options) {
|
|
832
|
-
const content = await readFile2(path);
|
|
833
|
-
if (options) {
|
|
834
|
-
options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
|
|
835
|
-
}
|
|
836
|
-
try {
|
|
837
|
-
return StormJSON.parseJson(content, options);
|
|
838
|
-
} catch (error) {
|
|
839
|
-
if (isError(error)) {
|
|
840
|
-
error.message = error.message.replace("JSON", path);
|
|
841
|
-
throw error;
|
|
842
|
-
}
|
|
843
|
-
throw new Error(`Failed to parse JSON: ${path}`);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
__name(readJsonFile, "readJsonFile");
|
|
847
|
-
|
|
848
|
-
// ../fs/src/list-files.ts
|
|
849
|
-
var import_defu = __toESM(require("defu"), 1);
|
|
850
|
-
var import_glob = require("glob");
|
|
851
|
-
var DEFAULT_OPTIONS = {
|
|
852
|
-
dot: true
|
|
853
|
-
};
|
|
854
|
-
async function list(filesGlob, options) {
|
|
855
|
-
return (0, import_glob.glob)(filesGlob, (0, import_defu.default)(options ?? {}, DEFAULT_OPTIONS));
|
|
856
|
-
}
|
|
857
|
-
__name(list, "list");
|
|
858
|
-
async function listFiles(filesGlob, options) {
|
|
859
|
-
const result = (await list(filesGlob, (0, import_defu.default)({
|
|
860
|
-
withFileTypes: true
|
|
861
|
-
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
862
|
-
if (!options?.withFileTypes) {
|
|
863
|
-
return result.map((file) => file.fullpath());
|
|
864
|
-
}
|
|
865
|
-
return result;
|
|
866
|
-
}
|
|
867
|
-
__name(listFiles, "listFiles");
|
|
868
|
-
|
|
869
|
-
// bin/capnpc.ts
|
|
870
|
-
var import_commander = require("commander");
|
|
871
|
-
var import_promises5 = require("fs/promises");
|
|
872
|
-
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
255
|
+
// src/compile.ts
|
|
256
|
+
var import_console2 = require("@storm-software/config-tools/logger/console");
|
|
873
257
|
|
|
874
258
|
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
|
|
875
259
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
@@ -2633,8 +2017,8 @@ function getStruct(index, StructClass, s, defaultValue) {
|
|
|
2633
2017
|
}
|
|
2634
2018
|
} else {
|
|
2635
2019
|
validate(PointerType.STRUCT, t);
|
|
2636
|
-
const
|
|
2637
|
-
if (
|
|
2020
|
+
const ts2 = getTargetStructSize(t);
|
|
2021
|
+
if (ts2.dataByteLength < StructClass._capnp.size.dataByteLength || ts2.pointerLength < StructClass._capnp.size.pointerLength) {
|
|
2638
2022
|
resize(StructClass._capnp.size, t);
|
|
2639
2023
|
}
|
|
2640
2024
|
}
|
|
@@ -6493,8 +5877,8 @@ __name(dump2, "dump");
|
|
|
6493
5877
|
function getRoot(RootStruct, m) {
|
|
6494
5878
|
const root = new RootStruct(m.getSegment(0), 0);
|
|
6495
5879
|
validate(PointerType.STRUCT, root);
|
|
6496
|
-
const
|
|
6497
|
-
if (
|
|
5880
|
+
const ts2 = getTargetStructSize(root);
|
|
5881
|
+
if (ts2.dataByteLength < RootStruct._capnp.size.dataByteLength || ts2.pointerLength < RootStruct._capnp.size.pointerLength) {
|
|
6498
5882
|
resize(RootStruct._capnp.size, root);
|
|
6499
5883
|
}
|
|
6500
5884
|
return root;
|
|
@@ -6706,516 +6090,914 @@ var Primitives = {
|
|
|
6706
6090
|
mask: "getVoidMask",
|
|
6707
6091
|
setter: "setVoid"
|
|
6708
6092
|
}
|
|
6709
|
-
};
|
|
6710
|
-
var SOURCE_COMMENT = `
|
|
6711
|
-
/* eslint-disable */
|
|
6712
|
-
// biome-ignore lint: disable
|
|
6713
|
-
|
|
6714
|
-
// Generated by storm-capnpc
|
|
6715
|
-
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
6093
|
+
};
|
|
6094
|
+
var SOURCE_COMMENT = `
|
|
6095
|
+
/* eslint-disable */
|
|
6096
|
+
// biome-ignore lint: disable
|
|
6097
|
+
|
|
6098
|
+
// Generated by storm-capnpc
|
|
6099
|
+
// Note: Do not edit this file manually - it will be overwritten automatically
|
|
6100
|
+
|
|
6101
|
+
`;
|
|
6102
|
+
var TS_FILE_ID = "e37ded525a68a7c9";
|
|
6103
|
+
var hex2dec;
|
|
6104
|
+
var hasRequiredHex2dec;
|
|
6105
|
+
function requireHex2dec() {
|
|
6106
|
+
if (hasRequiredHex2dec) return hex2dec;
|
|
6107
|
+
hasRequiredHex2dec = 1;
|
|
6108
|
+
function add2(x, y, base) {
|
|
6109
|
+
var z = [];
|
|
6110
|
+
var n = Math.max(x.length, y.length);
|
|
6111
|
+
var carry = 0;
|
|
6112
|
+
var i = 0;
|
|
6113
|
+
while (i < n || carry) {
|
|
6114
|
+
var xi = i < x.length ? x[i] : 0;
|
|
6115
|
+
var yi = i < y.length ? y[i] : 0;
|
|
6116
|
+
var zi = carry + xi + yi;
|
|
6117
|
+
z.push(zi % base);
|
|
6118
|
+
carry = Math.floor(zi / base);
|
|
6119
|
+
i++;
|
|
6120
|
+
}
|
|
6121
|
+
return z;
|
|
6122
|
+
}
|
|
6123
|
+
__name(add2, "add");
|
|
6124
|
+
function multiplyByNumber(num, x, base) {
|
|
6125
|
+
if (num < 0) return null;
|
|
6126
|
+
if (num == 0) return [];
|
|
6127
|
+
var result = [];
|
|
6128
|
+
var power = x;
|
|
6129
|
+
while (true) {
|
|
6130
|
+
if (num & 1) {
|
|
6131
|
+
result = add2(result, power, base);
|
|
6132
|
+
}
|
|
6133
|
+
num = num >> 1;
|
|
6134
|
+
if (num === 0) break;
|
|
6135
|
+
power = add2(power, power, base);
|
|
6136
|
+
}
|
|
6137
|
+
return result;
|
|
6138
|
+
}
|
|
6139
|
+
__name(multiplyByNumber, "multiplyByNumber");
|
|
6140
|
+
function parseToDigitsArray(str, base) {
|
|
6141
|
+
var digits = str.split("");
|
|
6142
|
+
var ary = [];
|
|
6143
|
+
for (var i = digits.length - 1; i >= 0; i--) {
|
|
6144
|
+
var n = parseInt(digits[i], base);
|
|
6145
|
+
if (isNaN(n)) return null;
|
|
6146
|
+
ary.push(n);
|
|
6147
|
+
}
|
|
6148
|
+
return ary;
|
|
6149
|
+
}
|
|
6150
|
+
__name(parseToDigitsArray, "parseToDigitsArray");
|
|
6151
|
+
function convertBase(str, fromBase, toBase) {
|
|
6152
|
+
var digits = parseToDigitsArray(str, fromBase);
|
|
6153
|
+
if (digits === null) return null;
|
|
6154
|
+
var outArray = [];
|
|
6155
|
+
var power = [1];
|
|
6156
|
+
for (var i = 0; i < digits.length; i++) {
|
|
6157
|
+
if (digits[i]) {
|
|
6158
|
+
outArray = add2(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
|
|
6159
|
+
}
|
|
6160
|
+
power = multiplyByNumber(fromBase, power, toBase);
|
|
6161
|
+
}
|
|
6162
|
+
var out = "";
|
|
6163
|
+
for (var i = outArray.length - 1; i >= 0; i--) {
|
|
6164
|
+
out += outArray[i].toString(toBase);
|
|
6165
|
+
}
|
|
6166
|
+
if (out === "") {
|
|
6167
|
+
out = "0";
|
|
6168
|
+
}
|
|
6169
|
+
return out;
|
|
6170
|
+
}
|
|
6171
|
+
__name(convertBase, "convertBase");
|
|
6172
|
+
function decToHex(decStr, opts) {
|
|
6173
|
+
var hidePrefix = opts && opts.prefix === false;
|
|
6174
|
+
var hex = convertBase(decStr, 10, 16);
|
|
6175
|
+
return hex ? hidePrefix ? hex : "0x" + hex : null;
|
|
6176
|
+
}
|
|
6177
|
+
__name(decToHex, "decToHex");
|
|
6178
|
+
function hexToDec(hexStr) {
|
|
6179
|
+
if (hexStr.substring(0, 2) === "0x") hexStr = hexStr.substring(2);
|
|
6180
|
+
hexStr = hexStr.toLowerCase();
|
|
6181
|
+
return convertBase(hexStr, 16, 10);
|
|
6182
|
+
}
|
|
6183
|
+
__name(hexToDec, "hexToDec");
|
|
6184
|
+
hex2dec = {
|
|
6185
|
+
hexToDec,
|
|
6186
|
+
decToHex
|
|
6187
|
+
};
|
|
6188
|
+
return hex2dec;
|
|
6189
|
+
}
|
|
6190
|
+
__name(requireHex2dec, "requireHex2dec");
|
|
6191
|
+
var hex2decExports = requireHex2dec();
|
|
6192
|
+
function c2s(s) {
|
|
6193
|
+
return splitCamel(s).map((x) => x.toUpperCase()).join("_");
|
|
6194
|
+
}
|
|
6195
|
+
__name(c2s, "c2s");
|
|
6196
|
+
function c2t(s) {
|
|
6197
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
6198
|
+
}
|
|
6199
|
+
__name(c2t, "c2t");
|
|
6200
|
+
function splitCamel(s) {
|
|
6201
|
+
let wasLo = false;
|
|
6202
|
+
return s.split("").reduce((a, c) => {
|
|
6203
|
+
const lo = c.toUpperCase() !== c;
|
|
6204
|
+
const up = c.toLowerCase() !== c;
|
|
6205
|
+
if (a.length === 0 || wasLo && up) {
|
|
6206
|
+
a.push(c);
|
|
6207
|
+
} else {
|
|
6208
|
+
const i = a.length - 1;
|
|
6209
|
+
a[i] = a[i] + c;
|
|
6210
|
+
}
|
|
6211
|
+
wasLo = lo;
|
|
6212
|
+
return a;
|
|
6213
|
+
}, []);
|
|
6214
|
+
}
|
|
6215
|
+
__name(splitCamel, "splitCamel");
|
|
6216
|
+
function hexToBigInt(hexString) {
|
|
6217
|
+
return BigInt(hex2decExports.hexToDec(hexString));
|
|
6218
|
+
}
|
|
6219
|
+
__name(hexToBigInt, "hexToBigInt");
|
|
6220
|
+
function compareCodeOrder(a, b) {
|
|
6221
|
+
return a.codeOrder - b.codeOrder;
|
|
6222
|
+
}
|
|
6223
|
+
__name(compareCodeOrder, "compareCodeOrder");
|
|
6224
|
+
function getConcreteListType(ctx, type) {
|
|
6225
|
+
if (!type._isList) {
|
|
6226
|
+
return getJsType(ctx, type, false);
|
|
6227
|
+
}
|
|
6228
|
+
const { elementType } = type.list;
|
|
6229
|
+
const elementTypeWhich = elementType.which();
|
|
6230
|
+
if (elementTypeWhich === Type.LIST) {
|
|
6231
|
+
return `$.PointerList(${getConcreteListType(ctx, elementType)})`;
|
|
6232
|
+
} else if (elementTypeWhich === Type.STRUCT) {
|
|
6233
|
+
const structNode = lookupNode(ctx, elementType.struct.typeId);
|
|
6234
|
+
if (structNode.struct.preferredListEncoding !== ElementSize.INLINE_COMPOSITE) {
|
|
6235
|
+
throw new Error(GEN_FIELD_NON_INLINE_STRUCT_LIST);
|
|
6236
|
+
}
|
|
6237
|
+
return `$.CompositeList(${getJsType(ctx, elementType, false)})`;
|
|
6238
|
+
}
|
|
6239
|
+
return ConcreteListType[elementTypeWhich];
|
|
6240
|
+
}
|
|
6241
|
+
__name(getConcreteListType, "getConcreteListType");
|
|
6242
|
+
function getDisplayNamePrefix(node) {
|
|
6243
|
+
return node.displayName.slice(node.displayNamePrefixLength);
|
|
6244
|
+
}
|
|
6245
|
+
__name(getDisplayNamePrefix, "getDisplayNamePrefix");
|
|
6246
|
+
function getFullClassName(node) {
|
|
6247
|
+
return node.displayName.split(":")[1].split(".").map((s) => c2t(s)).join("_");
|
|
6248
|
+
}
|
|
6249
|
+
__name(getFullClassName, "getFullClassName");
|
|
6250
|
+
function getJsType(ctx, type, constructor) {
|
|
6251
|
+
const whichType = type.which();
|
|
6252
|
+
switch (whichType) {
|
|
6253
|
+
case Type.ANY_POINTER: {
|
|
6254
|
+
return "$.Pointer";
|
|
6255
|
+
}
|
|
6256
|
+
case Type.BOOL: {
|
|
6257
|
+
return "boolean";
|
|
6258
|
+
}
|
|
6259
|
+
case Type.DATA: {
|
|
6260
|
+
return "$.Data";
|
|
6261
|
+
}
|
|
6262
|
+
case Type.ENUM: {
|
|
6263
|
+
return getFullClassName(lookupNode(ctx, type.enum.typeId));
|
|
6264
|
+
}
|
|
6265
|
+
case Type.FLOAT32:
|
|
6266
|
+
case Type.FLOAT64:
|
|
6267
|
+
case Type.INT16:
|
|
6268
|
+
case Type.INT32:
|
|
6269
|
+
case Type.INT8:
|
|
6270
|
+
case Type.UINT16:
|
|
6271
|
+
case Type.UINT32:
|
|
6272
|
+
case Type.UINT8: {
|
|
6273
|
+
return "number";
|
|
6274
|
+
}
|
|
6275
|
+
case Type.UINT64:
|
|
6276
|
+
case Type.INT64: {
|
|
6277
|
+
return "bigint";
|
|
6278
|
+
}
|
|
6279
|
+
case Type.INTERFACE: {
|
|
6280
|
+
return getFullClassName(lookupNode(ctx, type.interface.typeId));
|
|
6281
|
+
}
|
|
6282
|
+
case Type.LIST: {
|
|
6283
|
+
return `$.List${constructor ? "Ctor" : ""}<${getJsType(ctx, type.list.elementType, false)}>`;
|
|
6284
|
+
}
|
|
6285
|
+
case Type.STRUCT: {
|
|
6286
|
+
const c = getFullClassName(lookupNode(ctx, type.struct.typeId));
|
|
6287
|
+
return constructor ? `$.StructCtor<${c}>` : c;
|
|
6288
|
+
}
|
|
6289
|
+
case Type.TEXT: {
|
|
6290
|
+
return "string";
|
|
6291
|
+
}
|
|
6292
|
+
case Type.VOID: {
|
|
6293
|
+
return "$.Void";
|
|
6294
|
+
}
|
|
6295
|
+
default: {
|
|
6296
|
+
throw new Error(format(GEN_UNKNOWN_TYPE, whichType));
|
|
6297
|
+
}
|
|
6298
|
+
}
|
|
6299
|
+
}
|
|
6300
|
+
__name(getJsType, "getJsType");
|
|
6301
|
+
function getUnnamedUnionFields(node) {
|
|
6302
|
+
return node.struct.fields.filter(
|
|
6303
|
+
(field) => field.discriminantValue !== Field.NO_DISCRIMINANT
|
|
6304
|
+
);
|
|
6305
|
+
}
|
|
6306
|
+
__name(getUnnamedUnionFields, "getUnnamedUnionFields");
|
|
6307
|
+
function hasNode(ctx, lookup) {
|
|
6308
|
+
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6309
|
+
return ctx.nodes.some((n) => n.id === id);
|
|
6310
|
+
}
|
|
6311
|
+
__name(hasNode, "hasNode");
|
|
6312
|
+
function loadRequestedFile(req, file) {
|
|
6313
|
+
const ctx = new CodeGeneratorFileContext(req, file);
|
|
6314
|
+
const schema2 = lookupNode(ctx, file.id);
|
|
6315
|
+
ctx.tsPath = schema2.displayName.replace(/\.capnp$/, "") + ".ts";
|
|
6316
|
+
return ctx;
|
|
6317
|
+
}
|
|
6318
|
+
__name(loadRequestedFile, "loadRequestedFile");
|
|
6319
|
+
function lookupNode(ctx, lookup) {
|
|
6320
|
+
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6321
|
+
const node = ctx.nodes.find((n) => n.id === id);
|
|
6322
|
+
if (node === void 0) {
|
|
6323
|
+
throw new Error(format(GEN_NODE_LOOKUP_FAIL, id));
|
|
6324
|
+
}
|
|
6325
|
+
return node;
|
|
6326
|
+
}
|
|
6327
|
+
__name(lookupNode, "lookupNode");
|
|
6328
|
+
function lookupNodeSourceInfo(ctx, lookup) {
|
|
6329
|
+
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6330
|
+
return ctx.req.sourceInfo.find((s) => s.id === id);
|
|
6331
|
+
}
|
|
6332
|
+
__name(lookupNodeSourceInfo, "lookupNodeSourceInfo");
|
|
6333
|
+
function needsConcreteListClass(field) {
|
|
6334
|
+
if (!field._isSlot) {
|
|
6335
|
+
return false;
|
|
6336
|
+
}
|
|
6337
|
+
const slotType = field.slot.type;
|
|
6338
|
+
if (!slotType._isList) {
|
|
6339
|
+
return false;
|
|
6340
|
+
}
|
|
6341
|
+
const { elementType } = slotType.list;
|
|
6342
|
+
return elementType._isStruct || elementType._isList;
|
|
6343
|
+
}
|
|
6344
|
+
__name(needsConcreteListClass, "needsConcreteListClass");
|
|
6345
|
+
function createBigInt(value) {
|
|
6346
|
+
let v = value.toString(16);
|
|
6347
|
+
let sign = "";
|
|
6348
|
+
if (v[0] === "-") {
|
|
6349
|
+
v = v.slice(1);
|
|
6350
|
+
sign = "-";
|
|
6351
|
+
}
|
|
6352
|
+
return `${sign}BigInt("0x${v}")`;
|
|
6353
|
+
}
|
|
6354
|
+
__name(createBigInt, "createBigInt");
|
|
6355
|
+
function extractJSDocs(sourceInfo) {
|
|
6356
|
+
const docComment = sourceInfo?.docComment;
|
|
6357
|
+
if (!docComment) {
|
|
6358
|
+
return "";
|
|
6359
|
+
}
|
|
6360
|
+
return "/**\n" + docComment.toString().split("\n").map((l) => `* ${l}`).join("\n") + "\n*/";
|
|
6361
|
+
}
|
|
6362
|
+
__name(extractJSDocs, "extractJSDocs");
|
|
6363
|
+
function generateEnumNode(ctx, className, parentNode, fields) {
|
|
6364
|
+
const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({ fieldIndex, codeOrder })).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
|
|
6365
|
+
const sourceInfo = lookupNodeSourceInfo(ctx, parentNode);
|
|
6366
|
+
const propInits = fieldIndexInCodeOrder.map((index) => {
|
|
6367
|
+
const field = fields[index];
|
|
6368
|
+
const docComment = extractJSDocs(sourceInfo?.members.at(index));
|
|
6369
|
+
const key = c2s(field.name);
|
|
6370
|
+
const val = field.discriminantValue || index;
|
|
6371
|
+
return `
|
|
6372
|
+
${docComment}
|
|
6373
|
+
${key}: ${val}`;
|
|
6374
|
+
});
|
|
6375
|
+
ctx.codeParts.push(`
|
|
6376
|
+
export const ${className} = {
|
|
6377
|
+
${propInits.join(",\n")}
|
|
6378
|
+
} as const;
|
|
6716
6379
|
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
function
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
carry = Math.floor(zi / base);
|
|
6735
|
-
i++;
|
|
6736
|
-
}
|
|
6737
|
-
return z;
|
|
6380
|
+
export type ${className} = (typeof ${className})[keyof typeof ${className}];
|
|
6381
|
+
`);
|
|
6382
|
+
}
|
|
6383
|
+
__name(generateEnumNode, "generateEnumNode");
|
|
6384
|
+
function generateInterfaceClasses(ctx, node) {
|
|
6385
|
+
generateMethodStructs(ctx, node);
|
|
6386
|
+
generateClient(ctx, node);
|
|
6387
|
+
generateServer(ctx, node);
|
|
6388
|
+
}
|
|
6389
|
+
__name(generateInterfaceClasses, "generateInterfaceClasses");
|
|
6390
|
+
function generateMethodStructs(ctx, node) {
|
|
6391
|
+
for (const method of node.interface.methods) {
|
|
6392
|
+
const paramNode = lookupNode(ctx, method.paramStructType);
|
|
6393
|
+
const resultNode = lookupNode(ctx, method.resultStructType);
|
|
6394
|
+
generateNode(ctx, paramNode);
|
|
6395
|
+
generateNode(ctx, resultNode);
|
|
6396
|
+
generateResultPromise(ctx, resultNode);
|
|
6738
6397
|
}
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6398
|
+
}
|
|
6399
|
+
__name(generateMethodStructs, "generateMethodStructs");
|
|
6400
|
+
function generateServer(ctx, node) {
|
|
6401
|
+
const fullClassName = getFullClassName(node);
|
|
6402
|
+
const serverName = `${fullClassName}$Server`;
|
|
6403
|
+
const serverTargetName = `${serverName}$Target`;
|
|
6404
|
+
const clientName = `${fullClassName}$Client`;
|
|
6405
|
+
const methodSignatures = node.interface.methods.map((method) => {
|
|
6406
|
+
const paramTypeName = getFullClassName(
|
|
6407
|
+
lookupNode(ctx, method.paramStructType)
|
|
6408
|
+
);
|
|
6409
|
+
const resultTypeName = getFullClassName(
|
|
6410
|
+
lookupNode(ctx, method.resultStructType)
|
|
6411
|
+
);
|
|
6412
|
+
return `${method.name}(params: ${paramTypeName}, results: ${resultTypeName}): Promise<void>;`;
|
|
6413
|
+
}).join("\n");
|
|
6414
|
+
ctx.codeParts.push(`
|
|
6415
|
+
export interface ${serverTargetName} {
|
|
6416
|
+
${methodSignatures}
|
|
6417
|
+
}`);
|
|
6418
|
+
const members = [];
|
|
6419
|
+
members.push(`public override readonly target: ${serverTargetName};`);
|
|
6420
|
+
const codeServerMethods = [];
|
|
6421
|
+
let index = 0;
|
|
6422
|
+
for (const method of node.interface.methods) {
|
|
6423
|
+
codeServerMethods.push(`{
|
|
6424
|
+
...${clientName}.methods[${index}],
|
|
6425
|
+
impl: target.${method.name}
|
|
6426
|
+
}`);
|
|
6427
|
+
index++;
|
|
6428
|
+
}
|
|
6429
|
+
members.push(`
|
|
6430
|
+
constructor(target: ${serverTargetName}) {
|
|
6431
|
+
super(target, [
|
|
6432
|
+
${codeServerMethods.join(",\n")}
|
|
6433
|
+
]);
|
|
6434
|
+
this.target = target;
|
|
6748
6435
|
}
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6436
|
+
client(): ${clientName} {
|
|
6437
|
+
return new ${clientName}(this);
|
|
6438
|
+
}
|
|
6439
|
+
`);
|
|
6440
|
+
ctx.codeParts.push(`
|
|
6441
|
+
export class ${serverName} extends $.Server {
|
|
6442
|
+
${members.join("\n")}
|
|
6752
6443
|
}
|
|
6753
|
-
|
|
6444
|
+
`);
|
|
6445
|
+
}
|
|
6446
|
+
__name(generateServer, "generateServer");
|
|
6447
|
+
function generateClient(ctx, node) {
|
|
6448
|
+
const fullClassName = getFullClassName(node);
|
|
6449
|
+
const clientName = `${fullClassName}$Client`;
|
|
6450
|
+
const members = [];
|
|
6451
|
+
members.push(`
|
|
6452
|
+
client: $.Client;
|
|
6453
|
+
static readonly interfaceId: bigint = ${createBigInt(node.id)};
|
|
6454
|
+
constructor(client: $.Client) {
|
|
6455
|
+
this.client = client;
|
|
6456
|
+
}
|
|
6457
|
+
`);
|
|
6458
|
+
const methods = [];
|
|
6459
|
+
const methodDefs = [];
|
|
6460
|
+
const methodDefTypes = [];
|
|
6461
|
+
for (let index = 0; index < node.interface.methods.length; index++) {
|
|
6462
|
+
generateClientMethod(
|
|
6463
|
+
ctx,
|
|
6464
|
+
node,
|
|
6465
|
+
clientName,
|
|
6466
|
+
methods,
|
|
6467
|
+
methodDefs,
|
|
6468
|
+
methodDefTypes,
|
|
6469
|
+
index
|
|
6470
|
+
);
|
|
6754
6471
|
}
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6472
|
+
members.push(`
|
|
6473
|
+
static readonly methods:[
|
|
6474
|
+
${methodDefTypes.join(",\n")}
|
|
6475
|
+
] = [
|
|
6476
|
+
${methodDefs.join(",\n")}
|
|
6477
|
+
];
|
|
6478
|
+
${methods.join("\n")}
|
|
6479
|
+
`);
|
|
6480
|
+
ctx.codeParts.push(`
|
|
6481
|
+
export class ${clientName} {
|
|
6482
|
+
${members.join("\n")}
|
|
6763
6483
|
}
|
|
6764
|
-
|
|
6484
|
+
$.Registry.register(${clientName}.interfaceId, ${clientName});
|
|
6485
|
+
`);
|
|
6486
|
+
}
|
|
6487
|
+
__name(generateClient, "generateClient");
|
|
6488
|
+
function generateResultPromise(ctx, node) {
|
|
6489
|
+
const nodeId = node.id;
|
|
6490
|
+
if (ctx.generatedResultsPromiseIds.has(nodeId)) {
|
|
6491
|
+
return;
|
|
6765
6492
|
}
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
outArray = add2(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
|
|
6775
|
-
}
|
|
6776
|
-
power = multiplyByNumber(fromBase, power, toBase);
|
|
6493
|
+
ctx.generatedResultsPromiseIds.add(nodeId);
|
|
6494
|
+
const resultsClassName = getFullClassName(node);
|
|
6495
|
+
const fullClassName = `${resultsClassName}$Promise`;
|
|
6496
|
+
const members = [];
|
|
6497
|
+
members.push(`
|
|
6498
|
+
pipeline: $.Pipeline<any, any, ${resultsClassName}>;
|
|
6499
|
+
constructor(pipeline: $.Pipeline<any, any, ${resultsClassName}>) {
|
|
6500
|
+
this.pipeline = pipeline;
|
|
6777
6501
|
}
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6502
|
+
`);
|
|
6503
|
+
const { struct } = node;
|
|
6504
|
+
const fields = struct.fields.toArray().sort(compareCodeOrder);
|
|
6505
|
+
const generatePromiseFieldMethod = /* @__PURE__ */ __name((field) => {
|
|
6506
|
+
let jsType;
|
|
6507
|
+
let isInterface = false;
|
|
6508
|
+
let slot;
|
|
6509
|
+
if (field._isSlot) {
|
|
6510
|
+
slot = field.slot;
|
|
6511
|
+
const slotType = slot.type;
|
|
6512
|
+
if (slotType.which() !== Type.INTERFACE) {
|
|
6513
|
+
return;
|
|
6514
|
+
}
|
|
6515
|
+
isInterface = true;
|
|
6516
|
+
jsType = getJsType(ctx, slotType, false);
|
|
6517
|
+
} else if (field._isGroup) {
|
|
6518
|
+
return;
|
|
6519
|
+
} else {
|
|
6520
|
+
throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
|
|
6781
6521
|
}
|
|
6782
|
-
|
|
6783
|
-
|
|
6522
|
+
const promisedJsType = jsType;
|
|
6523
|
+
if (isInterface) {
|
|
6524
|
+
jsType = `${jsType}$Client`;
|
|
6784
6525
|
}
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
}
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
if (hexStr.substring(0, 2) === "0x") hexStr = hexStr.substring(2);
|
|
6796
|
-
hexStr = hexStr.toLowerCase();
|
|
6797
|
-
return convertBase(hexStr, 16, 10);
|
|
6526
|
+
const { name } = field;
|
|
6527
|
+
const properName = c2t(name);
|
|
6528
|
+
members.push(`
|
|
6529
|
+
get${properName}(): ${jsType} {
|
|
6530
|
+
return new ${jsType}(this.pipeline.getPipeline(${promisedJsType}, ${slot.offset}).client());
|
|
6531
|
+
}
|
|
6532
|
+
`);
|
|
6533
|
+
}, "generatePromiseFieldMethod");
|
|
6534
|
+
for (const field of fields) {
|
|
6535
|
+
generatePromiseFieldMethod(field);
|
|
6798
6536
|
}
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
decToHex
|
|
6803
|
-
};
|
|
6804
|
-
return hex2dec;
|
|
6805
|
-
}
|
|
6806
|
-
__name(requireHex2dec, "requireHex2dec");
|
|
6807
|
-
var hex2decExports = requireHex2dec();
|
|
6808
|
-
function c2s(s) {
|
|
6809
|
-
return splitCamel(s).map((x) => x.toUpperCase()).join("_");
|
|
6810
|
-
}
|
|
6811
|
-
__name(c2s, "c2s");
|
|
6812
|
-
function c2t(s) {
|
|
6813
|
-
return s[0].toUpperCase() + s.slice(1);
|
|
6814
|
-
}
|
|
6815
|
-
__name(c2t, "c2t");
|
|
6816
|
-
function splitCamel(s) {
|
|
6817
|
-
let wasLo = false;
|
|
6818
|
-
return s.split("").reduce((a, c) => {
|
|
6819
|
-
const lo = c.toUpperCase() !== c;
|
|
6820
|
-
const up = c.toLowerCase() !== c;
|
|
6821
|
-
if (a.length === 0 || wasLo && up) {
|
|
6822
|
-
a.push(c);
|
|
6823
|
-
} else {
|
|
6824
|
-
const i = a.length - 1;
|
|
6825
|
-
a[i] = a[i] + c;
|
|
6537
|
+
members.push(`
|
|
6538
|
+
async promise(): Promise<${resultsClassName}> {
|
|
6539
|
+
return await this.pipeline.struct();
|
|
6826
6540
|
}
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
}
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
return BigInt(hex2decExports.hexToDec(hexString));
|
|
6541
|
+
`);
|
|
6542
|
+
ctx.codeParts.push(`
|
|
6543
|
+
export class ${fullClassName} {
|
|
6544
|
+
${members.join("\n")}
|
|
6545
|
+
}
|
|
6546
|
+
`);
|
|
6834
6547
|
}
|
|
6835
|
-
__name(
|
|
6836
|
-
function
|
|
6837
|
-
|
|
6548
|
+
__name(generateResultPromise, "generateResultPromise");
|
|
6549
|
+
function generateClientMethod(ctx, node, clientName, methodsCode, methodDefs, methodDefTypes, index) {
|
|
6550
|
+
const method = node.interface.methods[index];
|
|
6551
|
+
const { name } = method;
|
|
6552
|
+
const paramTypeName = getFullClassName(
|
|
6553
|
+
lookupNode(ctx, method.paramStructType)
|
|
6554
|
+
);
|
|
6555
|
+
const resultTypeName = getFullClassName(
|
|
6556
|
+
lookupNode(ctx, method.resultStructType)
|
|
6557
|
+
);
|
|
6558
|
+
methodDefTypes.push(`$.Method<${paramTypeName}, ${resultTypeName}>`);
|
|
6559
|
+
methodDefs.push(`{
|
|
6560
|
+
ParamsClass: ${paramTypeName},
|
|
6561
|
+
ResultsClass: ${resultTypeName},
|
|
6562
|
+
interfaceId: ${clientName}.interfaceId,
|
|
6563
|
+
methodId: ${index},
|
|
6564
|
+
interfaceName: "${node.displayName}",
|
|
6565
|
+
methodName: "${method.name}"
|
|
6566
|
+
}`);
|
|
6567
|
+
const docComment = extractJSDocs(
|
|
6568
|
+
lookupNodeSourceInfo(ctx, node)?.members.at(index)
|
|
6569
|
+
);
|
|
6570
|
+
methodsCode.push(`
|
|
6571
|
+
${docComment}
|
|
6572
|
+
${name}(paramsFunc?: (params: ${paramTypeName}) => void): ${resultTypeName}$Promise {
|
|
6573
|
+
const answer = this.client.call({
|
|
6574
|
+
method: ${clientName}.methods[${index}],
|
|
6575
|
+
paramsFunc: paramsFunc
|
|
6576
|
+
});
|
|
6577
|
+
const pipeline = new $.Pipeline(${resultTypeName}, answer);
|
|
6578
|
+
return new ${resultTypeName}$Promise(pipeline);
|
|
6579
|
+
}
|
|
6580
|
+
`);
|
|
6838
6581
|
}
|
|
6839
|
-
__name(
|
|
6840
|
-
function
|
|
6841
|
-
|
|
6842
|
-
|
|
6582
|
+
__name(generateClientMethod, "generateClientMethod");
|
|
6583
|
+
function generateStructNode(ctx, node) {
|
|
6584
|
+
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
6585
|
+
const fullClassName = getFullClassName(node);
|
|
6586
|
+
const nestedNodes = node.nestedNodes.map(({ id }) => lookupNode(ctx, id)).filter((node2) => !node2._isConst && !node2._isAnnotation);
|
|
6587
|
+
const nodeId = node.id;
|
|
6588
|
+
const nodeIdHex = nodeId.toString(16);
|
|
6589
|
+
const unionFields = getUnnamedUnionFields(node);
|
|
6590
|
+
const { struct } = node;
|
|
6591
|
+
const { dataWordCount, discriminantCount, discriminantOffset, pointerCount } = struct;
|
|
6592
|
+
const dataByteLength = dataWordCount * 8;
|
|
6593
|
+
const fields = struct.fields.toArray();
|
|
6594
|
+
const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({ fieldIndex, codeOrder })).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
|
|
6595
|
+
const concreteLists = fields.filter((field) => needsConcreteListClass(field)).sort(compareCodeOrder);
|
|
6596
|
+
const consts = ctx.nodes.filter(
|
|
6597
|
+
(node2) => node2.scopeId === nodeId && node2._isConst
|
|
6598
|
+
);
|
|
6599
|
+
const hasUnnamedUnion = discriminantCount !== 0;
|
|
6600
|
+
if (hasUnnamedUnion) {
|
|
6601
|
+
generateEnumNode(ctx, fullClassName + "_Which", node, unionFields);
|
|
6843
6602
|
}
|
|
6844
|
-
const
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6603
|
+
const members = [];
|
|
6604
|
+
members.push(
|
|
6605
|
+
...consts.map((node2) => {
|
|
6606
|
+
const name = c2s(getDisplayNamePrefix(node2));
|
|
6607
|
+
const value = createValue(node2.const.value);
|
|
6608
|
+
return `static readonly ${name} = ${value}`;
|
|
6609
|
+
}),
|
|
6610
|
+
...unionFields.sort(compareCodeOrder).map((field) => createUnionConstProperty(fullClassName, field)),
|
|
6611
|
+
...nestedNodes.map((node2) => createNestedNodeProperty(node2))
|
|
6612
|
+
);
|
|
6613
|
+
const defaultValues = [];
|
|
6614
|
+
for (const index of fieldIndexInCodeOrder) {
|
|
6615
|
+
const field = fields[index];
|
|
6616
|
+
if (field._isSlot && field.slot.hadExplicitDefault && field.slot.type.which() !== Type.VOID) {
|
|
6617
|
+
defaultValues.push(generateDefaultValue(field));
|
|
6852
6618
|
}
|
|
6853
|
-
return `$.CompositeList(${getJsType(ctx, elementType, false)})`;
|
|
6854
6619
|
}
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
}
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6620
|
+
members.push(
|
|
6621
|
+
`
|
|
6622
|
+
public static override readonly _capnp = {
|
|
6623
|
+
displayName: "${displayNamePrefix}",
|
|
6624
|
+
id: "${nodeIdHex}",
|
|
6625
|
+
size: new $.ObjectSize(${dataByteLength}, ${pointerCount}),
|
|
6626
|
+
${defaultValues.join(",")}
|
|
6627
|
+
}`,
|
|
6628
|
+
...concreteLists.map((field) => createConcreteListProperty(ctx, field))
|
|
6629
|
+
);
|
|
6630
|
+
for (const index of fieldIndexInCodeOrder) {
|
|
6631
|
+
const field = fields[index];
|
|
6632
|
+
generateStructFieldMethods(ctx, members, node, field, index);
|
|
6633
|
+
}
|
|
6634
|
+
members.push(
|
|
6635
|
+
`public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
6636
|
+
);
|
|
6637
|
+
if (hasUnnamedUnion) {
|
|
6638
|
+
members.push(`
|
|
6639
|
+
which(): ${fullClassName}_Which {
|
|
6640
|
+
return $.utils.getUint16(${discriminantOffset * 2}, this) as ${fullClassName}_Which;
|
|
6641
|
+
}
|
|
6642
|
+
`);
|
|
6643
|
+
}
|
|
6644
|
+
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
6645
|
+
const classCode = `
|
|
6646
|
+
${docComment}
|
|
6647
|
+
export class ${fullClassName} extends $.Struct {
|
|
6648
|
+
${members.join("\n")}
|
|
6649
|
+
}`;
|
|
6650
|
+
ctx.codeParts.push(classCode);
|
|
6651
|
+
ctx.concreteLists.push(
|
|
6652
|
+
...concreteLists.map((field) => [
|
|
6653
|
+
fullClassName,
|
|
6654
|
+
field
|
|
6655
|
+
])
|
|
6656
|
+
);
|
|
6864
6657
|
}
|
|
6865
|
-
__name(
|
|
6866
|
-
function
|
|
6867
|
-
|
|
6658
|
+
__name(generateStructNode, "generateStructNode");
|
|
6659
|
+
function generateStructFieldMethods(ctx, members, node, field, fieldIndex) {
|
|
6660
|
+
let jsType;
|
|
6661
|
+
let whichType;
|
|
6662
|
+
if (field._isSlot) {
|
|
6663
|
+
const slotType = field.slot.type;
|
|
6664
|
+
jsType = getJsType(ctx, slotType, false);
|
|
6665
|
+
whichType = slotType.which();
|
|
6666
|
+
} else if (field._isGroup) {
|
|
6667
|
+
jsType = getFullClassName(lookupNode(ctx, field.group.typeId));
|
|
6668
|
+
whichType = "group";
|
|
6669
|
+
} else {
|
|
6670
|
+
throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
|
|
6671
|
+
}
|
|
6672
|
+
const isInterface = whichType === Type.INTERFACE;
|
|
6673
|
+
if (isInterface) {
|
|
6674
|
+
jsType = `${jsType}$Client`;
|
|
6675
|
+
}
|
|
6676
|
+
const { discriminantOffset } = node.struct;
|
|
6677
|
+
const { name } = field;
|
|
6678
|
+
const accessorName = name === "constructor" ? "$constructor" : name;
|
|
6679
|
+
const capitalizedName = c2t(name);
|
|
6680
|
+
const { discriminantValue } = field;
|
|
6681
|
+
const fullClassName = getFullClassName(node);
|
|
6682
|
+
const hadExplicitDefault = field._isSlot && field.slot.hadExplicitDefault;
|
|
6683
|
+
const maybeDefaultArg = hadExplicitDefault ? `, ${fullClassName}._capnp.default${capitalizedName}` : "";
|
|
6684
|
+
const union = discriminantValue !== Field.NO_DISCRIMINANT;
|
|
6685
|
+
const offset = field._isSlot ? field.slot.offset : 0;
|
|
6686
|
+
let adopt2 = false;
|
|
6687
|
+
let disown2 = false;
|
|
6688
|
+
let has = false;
|
|
6689
|
+
let init;
|
|
6690
|
+
let get;
|
|
6691
|
+
let set;
|
|
6868
6692
|
switch (whichType) {
|
|
6869
6693
|
case Type.ANY_POINTER: {
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
return "$.Data";
|
|
6877
|
-
}
|
|
6878
|
-
case Type.ENUM: {
|
|
6879
|
-
return getFullClassName(lookupNode(ctx, type.enum.typeId));
|
|
6694
|
+
adopt2 = true;
|
|
6695
|
+
disown2 = true;
|
|
6696
|
+
has = true;
|
|
6697
|
+
get = `$.utils.getPointer(${offset}, this${maybeDefaultArg})`;
|
|
6698
|
+
set = `$.utils.copyFrom(value, ${get})`;
|
|
6699
|
+
break;
|
|
6880
6700
|
}
|
|
6701
|
+
case Type.BOOL:
|
|
6702
|
+
case Type.ENUM:
|
|
6881
6703
|
case Type.FLOAT32:
|
|
6882
6704
|
case Type.FLOAT64:
|
|
6883
6705
|
case Type.INT16:
|
|
6884
6706
|
case Type.INT32:
|
|
6707
|
+
case Type.INT64:
|
|
6885
6708
|
case Type.INT8:
|
|
6886
6709
|
case Type.UINT16:
|
|
6887
6710
|
case Type.UINT32:
|
|
6711
|
+
case Type.UINT64:
|
|
6888
6712
|
case Type.UINT8: {
|
|
6889
|
-
|
|
6713
|
+
const { byteLength, getter, setter } = Primitives[whichType];
|
|
6714
|
+
const byteOffset = offset * byteLength;
|
|
6715
|
+
get = `$.utils.${getter}(${byteOffset}, this${maybeDefaultArg})`;
|
|
6716
|
+
set = `$.utils.${setter}(${byteOffset}, value, this${maybeDefaultArg})`;
|
|
6717
|
+
if (whichType === Type.ENUM) {
|
|
6718
|
+
get = `${get} as ${jsType}`;
|
|
6719
|
+
}
|
|
6720
|
+
break;
|
|
6890
6721
|
}
|
|
6891
|
-
case Type.
|
|
6892
|
-
|
|
6893
|
-
|
|
6722
|
+
case Type.DATA: {
|
|
6723
|
+
adopt2 = true;
|
|
6724
|
+
disown2 = true;
|
|
6725
|
+
has = true;
|
|
6726
|
+
get = `$.utils.getData(${offset}, this${maybeDefaultArg})`;
|
|
6727
|
+
set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
|
|
6728
|
+
init = `$.utils.initData(${offset}, length, this)`;
|
|
6729
|
+
break;
|
|
6894
6730
|
}
|
|
6895
6731
|
case Type.INTERFACE: {
|
|
6896
|
-
|
|
6732
|
+
get = `new ${jsType}($.utils.getInterfaceClientOrNullAt(${offset}, this))`;
|
|
6733
|
+
set = `$.utils.setInterfacePointer(this.segment.message.addCap(value.client), $.utils.getPointer(${offset}, this))`;
|
|
6734
|
+
break;
|
|
6897
6735
|
}
|
|
6898
6736
|
case Type.LIST: {
|
|
6899
|
-
|
|
6737
|
+
const elementType = field.slot.type.list.elementType.which();
|
|
6738
|
+
let listClass = ConcreteListType[elementType];
|
|
6739
|
+
if (elementType === Type.LIST || elementType === Type.STRUCT) {
|
|
6740
|
+
listClass = `${fullClassName}._${capitalizedName}`;
|
|
6741
|
+
} else if (listClass === void 0) {
|
|
6742
|
+
throw new Error(
|
|
6743
|
+
format(GEN_UNSUPPORTED_LIST_ELEMENT_TYPE, elementType)
|
|
6744
|
+
);
|
|
6745
|
+
}
|
|
6746
|
+
adopt2 = true;
|
|
6747
|
+
disown2 = true;
|
|
6748
|
+
has = true;
|
|
6749
|
+
get = `$.utils.getList(${offset}, ${listClass}, this${maybeDefaultArg})`;
|
|
6750
|
+
set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
|
|
6751
|
+
init = `$.utils.initList(${offset}, ${listClass}, length, this)`;
|
|
6752
|
+
if (elementType === Type.ENUM) {
|
|
6753
|
+
get = `${get} as ${jsType}`;
|
|
6754
|
+
init = `${init} as ${jsType}`;
|
|
6755
|
+
}
|
|
6756
|
+
break;
|
|
6900
6757
|
}
|
|
6901
6758
|
case Type.STRUCT: {
|
|
6902
|
-
|
|
6903
|
-
|
|
6759
|
+
adopt2 = true;
|
|
6760
|
+
disown2 = true;
|
|
6761
|
+
has = true;
|
|
6762
|
+
get = `$.utils.getStruct(${offset}, ${jsType}, this${maybeDefaultArg})`;
|
|
6763
|
+
set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
|
|
6764
|
+
init = `$.utils.initStructAt(${offset}, ${jsType}, this)`;
|
|
6765
|
+
break;
|
|
6904
6766
|
}
|
|
6905
6767
|
case Type.TEXT: {
|
|
6906
|
-
|
|
6768
|
+
get = `$.utils.getText(${offset}, this${maybeDefaultArg})`;
|
|
6769
|
+
set = `$.utils.setText(${offset}, value, this)`;
|
|
6770
|
+
break;
|
|
6907
6771
|
}
|
|
6908
6772
|
case Type.VOID: {
|
|
6909
|
-
|
|
6773
|
+
break;
|
|
6910
6774
|
}
|
|
6911
|
-
|
|
6912
|
-
|
|
6775
|
+
case "group": {
|
|
6776
|
+
if (hadExplicitDefault) {
|
|
6777
|
+
throw new Error(format(GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE, "group"));
|
|
6778
|
+
}
|
|
6779
|
+
get = `$.utils.getAs(${jsType}, this)`;
|
|
6780
|
+
init = get;
|
|
6781
|
+
break;
|
|
6913
6782
|
}
|
|
6914
6783
|
}
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
);
|
|
6921
|
-
}
|
|
6922
|
-
__name(getUnnamedUnionFields, "getUnnamedUnionFields");
|
|
6923
|
-
function hasNode(ctx, lookup) {
|
|
6924
|
-
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6925
|
-
return ctx.nodes.some((n) => n.id === id);
|
|
6926
|
-
}
|
|
6927
|
-
__name(hasNode, "hasNode");
|
|
6928
|
-
function loadRequestedFile(req, file) {
|
|
6929
|
-
const ctx = new CodeGeneratorFileContext(req, file);
|
|
6930
|
-
const schema2 = lookupNode(ctx, file.id);
|
|
6931
|
-
ctx.tsPath = schema2.displayName.replace(/\.capnp$/, "") + ".ts";
|
|
6932
|
-
return ctx;
|
|
6933
|
-
}
|
|
6934
|
-
__name(loadRequestedFile, "loadRequestedFile");
|
|
6935
|
-
function lookupNode(ctx, lookup) {
|
|
6936
|
-
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6937
|
-
const node = ctx.nodes.find((n) => n.id === id);
|
|
6938
|
-
if (node === void 0) {
|
|
6939
|
-
throw new Error(format(GEN_NODE_LOOKUP_FAIL, id));
|
|
6940
|
-
}
|
|
6941
|
-
return node;
|
|
6942
|
-
}
|
|
6943
|
-
__name(lookupNode, "lookupNode");
|
|
6944
|
-
function lookupNodeSourceInfo(ctx, lookup) {
|
|
6945
|
-
const id = typeof lookup === "bigint" ? lookup : lookup.id;
|
|
6946
|
-
return ctx.req.sourceInfo.find((s) => s.id === id);
|
|
6947
|
-
}
|
|
6948
|
-
__name(lookupNodeSourceInfo, "lookupNodeSourceInfo");
|
|
6949
|
-
function needsConcreteListClass(field) {
|
|
6950
|
-
if (!field._isSlot) {
|
|
6951
|
-
return false;
|
|
6952
|
-
}
|
|
6953
|
-
const slotType = field.slot.type;
|
|
6954
|
-
if (!slotType._isList) {
|
|
6955
|
-
return false;
|
|
6956
|
-
}
|
|
6957
|
-
const { elementType } = slotType.list;
|
|
6958
|
-
return elementType._isStruct || elementType._isList;
|
|
6959
|
-
}
|
|
6960
|
-
__name(needsConcreteListClass, "needsConcreteListClass");
|
|
6961
|
-
function createBigInt(value) {
|
|
6962
|
-
let v = value.toString(16);
|
|
6963
|
-
let sign = "";
|
|
6964
|
-
if (v[0] === "-") {
|
|
6965
|
-
v = v.slice(1);
|
|
6966
|
-
sign = "-";
|
|
6967
|
-
}
|
|
6968
|
-
return `${sign}BigInt("0x${v}")`;
|
|
6969
|
-
}
|
|
6970
|
-
__name(createBigInt, "createBigInt");
|
|
6971
|
-
function extractJSDocs(sourceInfo) {
|
|
6972
|
-
const docComment = sourceInfo?.docComment;
|
|
6973
|
-
if (!docComment) {
|
|
6974
|
-
return "";
|
|
6975
|
-
}
|
|
6976
|
-
return "/**\n" + docComment.toString().split("\n").map((l) => `* ${l}`).join("\n") + "\n*/";
|
|
6977
|
-
}
|
|
6978
|
-
__name(extractJSDocs, "extractJSDocs");
|
|
6979
|
-
function generateEnumNode(ctx, className, parentNode, fields) {
|
|
6980
|
-
const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({ fieldIndex, codeOrder })).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
|
|
6981
|
-
const sourceInfo = lookupNodeSourceInfo(ctx, parentNode);
|
|
6982
|
-
const propInits = fieldIndexInCodeOrder.map((index) => {
|
|
6983
|
-
const field = fields[index];
|
|
6984
|
-
const docComment = extractJSDocs(sourceInfo?.members.at(index));
|
|
6985
|
-
const key = c2s(field.name);
|
|
6986
|
-
const val = field.discriminantValue || index;
|
|
6987
|
-
return `
|
|
6988
|
-
${docComment}
|
|
6989
|
-
${key}: ${val}`;
|
|
6990
|
-
});
|
|
6991
|
-
ctx.codeParts.push(`
|
|
6992
|
-
export const ${className} = {
|
|
6993
|
-
${propInits.join(",\n")}
|
|
6994
|
-
} as const;
|
|
6995
|
-
|
|
6996
|
-
export type ${className} = (typeof ${className})[keyof typeof ${className}];
|
|
6997
|
-
`);
|
|
6998
|
-
}
|
|
6999
|
-
__name(generateEnumNode, "generateEnumNode");
|
|
7000
|
-
function generateInterfaceClasses(ctx, node) {
|
|
7001
|
-
generateMethodStructs(ctx, node);
|
|
7002
|
-
generateClient(ctx, node);
|
|
7003
|
-
generateServer(ctx, node);
|
|
7004
|
-
}
|
|
7005
|
-
__name(generateInterfaceClasses, "generateInterfaceClasses");
|
|
7006
|
-
function generateMethodStructs(ctx, node) {
|
|
7007
|
-
for (const method of node.interface.methods) {
|
|
7008
|
-
const paramNode = lookupNode(ctx, method.paramStructType);
|
|
7009
|
-
const resultNode = lookupNode(ctx, method.resultStructType);
|
|
7010
|
-
generateNode(ctx, paramNode);
|
|
7011
|
-
generateNode(ctx, resultNode);
|
|
7012
|
-
generateResultPromise(ctx, resultNode);
|
|
7013
|
-
}
|
|
7014
|
-
}
|
|
7015
|
-
__name(generateMethodStructs, "generateMethodStructs");
|
|
7016
|
-
function generateServer(ctx, node) {
|
|
7017
|
-
const fullClassName = getFullClassName(node);
|
|
7018
|
-
const serverName = `${fullClassName}$Server`;
|
|
7019
|
-
const serverTargetName = `${serverName}$Target`;
|
|
7020
|
-
const clientName = `${fullClassName}$Client`;
|
|
7021
|
-
const methodSignatures = node.interface.methods.map((method) => {
|
|
7022
|
-
const paramTypeName = getFullClassName(
|
|
7023
|
-
lookupNode(ctx, method.paramStructType)
|
|
7024
|
-
);
|
|
7025
|
-
const resultTypeName = getFullClassName(
|
|
7026
|
-
lookupNode(ctx, method.resultStructType)
|
|
7027
|
-
);
|
|
7028
|
-
return `${method.name}(params: ${paramTypeName}, results: ${resultTypeName}): Promise<void>;`;
|
|
7029
|
-
}).join("\n");
|
|
7030
|
-
ctx.codeParts.push(`
|
|
7031
|
-
export interface ${serverTargetName} {
|
|
7032
|
-
${methodSignatures}
|
|
7033
|
-
}`);
|
|
7034
|
-
const members = [];
|
|
7035
|
-
members.push(`public override readonly target: ${serverTargetName};`);
|
|
7036
|
-
const codeServerMethods = [];
|
|
7037
|
-
let index = 0;
|
|
7038
|
-
for (const method of node.interface.methods) {
|
|
7039
|
-
codeServerMethods.push(`{
|
|
7040
|
-
...${clientName}.methods[${index}],
|
|
7041
|
-
impl: target.${method.name}
|
|
7042
|
-
}`);
|
|
7043
|
-
index++;
|
|
7044
|
-
}
|
|
7045
|
-
members.push(`
|
|
7046
|
-
constructor(target: ${serverTargetName}) {
|
|
7047
|
-
super(target, [
|
|
7048
|
-
${codeServerMethods.join(",\n")}
|
|
7049
|
-
]);
|
|
7050
|
-
this.target = target;
|
|
7051
|
-
}
|
|
7052
|
-
client(): ${clientName} {
|
|
7053
|
-
return new ${clientName}(this);
|
|
6784
|
+
if (adopt2) {
|
|
6785
|
+
members.push(`
|
|
6786
|
+
_adopt${capitalizedName}(value: $.Orphan<${jsType}>): void {
|
|
6787
|
+
${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
|
|
6788
|
+
$.utils.adopt(value, $.utils.getPointer(${offset}, this));
|
|
7054
6789
|
}
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
}
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
members.push(`
|
|
7068
|
-
client: $.Client;
|
|
7069
|
-
static readonly interfaceId: bigint = ${createBigInt(node.id)};
|
|
7070
|
-
constructor(client: $.Client) {
|
|
7071
|
-
this.client = client;
|
|
7072
|
-
}
|
|
7073
|
-
`);
|
|
7074
|
-
const methods = [];
|
|
7075
|
-
const methodDefs = [];
|
|
7076
|
-
const methodDefTypes = [];
|
|
7077
|
-
for (let index = 0; index < node.interface.methods.length; index++) {
|
|
7078
|
-
generateClientMethod(
|
|
7079
|
-
ctx,
|
|
7080
|
-
node,
|
|
7081
|
-
clientName,
|
|
7082
|
-
methods,
|
|
7083
|
-
methodDefs,
|
|
7084
|
-
methodDefTypes,
|
|
7085
|
-
index
|
|
6790
|
+
`);
|
|
6791
|
+
}
|
|
6792
|
+
if (disown2) {
|
|
6793
|
+
members.push(`
|
|
6794
|
+
_disown${capitalizedName}(): $.Orphan<${jsType}> {
|
|
6795
|
+
return $.utils.disown(this.${name === "constructor" ? `$${name}` : name});
|
|
6796
|
+
}
|
|
6797
|
+
`);
|
|
6798
|
+
}
|
|
6799
|
+
if (get) {
|
|
6800
|
+
const docComment = extractJSDocs(
|
|
6801
|
+
lookupNodeSourceInfo(ctx, node)?.members.at(fieldIndex)
|
|
7086
6802
|
);
|
|
6803
|
+
members.push(`
|
|
6804
|
+
${docComment}
|
|
6805
|
+
get ${accessorName}(): ${jsType} {
|
|
6806
|
+
${union ? `$.utils.testWhich(${JSON.stringify(name)}, $.utils.getUint16(${discriminantOffset * 2}, this), ${discriminantValue}, this);` : ""}
|
|
6807
|
+
return ${get};
|
|
6808
|
+
}
|
|
6809
|
+
`);
|
|
7087
6810
|
}
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
${
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
];
|
|
7094
|
-
${methods.join("\n")}
|
|
6811
|
+
if (has) {
|
|
6812
|
+
members.push(`
|
|
6813
|
+
_has${capitalizedName}(): boolean {
|
|
6814
|
+
return !$.utils.isNull($.utils.getPointer(${offset}, this));
|
|
6815
|
+
}
|
|
7095
6816
|
`);
|
|
7096
|
-
ctx.codeParts.push(`
|
|
7097
|
-
export class ${clientName} {
|
|
7098
|
-
${members.join("\n")}
|
|
7099
|
-
}
|
|
7100
|
-
$.Registry.register(${clientName}.interfaceId, ${clientName});
|
|
7101
|
-
`);
|
|
7102
|
-
}
|
|
7103
|
-
__name(generateClient, "generateClient");
|
|
7104
|
-
function generateResultPromise(ctx, node) {
|
|
7105
|
-
const nodeId = node.id;
|
|
7106
|
-
if (ctx.generatedResultsPromiseIds.has(nodeId)) {
|
|
7107
|
-
return;
|
|
7108
6817
|
}
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
constructor(pipeline: $.Pipeline<any, any, ${resultsClassName}>) {
|
|
7116
|
-
this.pipeline = pipeline;
|
|
7117
|
-
}
|
|
7118
|
-
`);
|
|
7119
|
-
const { struct } = node;
|
|
7120
|
-
const fields = struct.fields.toArray().sort(compareCodeOrder);
|
|
7121
|
-
const generatePromiseFieldMethod = /* @__PURE__ */ __name((field) => {
|
|
7122
|
-
let jsType;
|
|
7123
|
-
let isInterface = false;
|
|
7124
|
-
let slot;
|
|
7125
|
-
if (field._isSlot) {
|
|
7126
|
-
slot = field.slot;
|
|
7127
|
-
const slotType = slot.type;
|
|
7128
|
-
if (slotType.which() !== Type.INTERFACE) {
|
|
7129
|
-
return;
|
|
6818
|
+
if (init) {
|
|
6819
|
+
const params = whichType === Type.DATA || whichType === Type.LIST ? `length: number` : "";
|
|
6820
|
+
members.push(`
|
|
6821
|
+
_init${capitalizedName}(${params}): ${jsType} {
|
|
6822
|
+
${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
|
|
6823
|
+
return ${init};
|
|
7130
6824
|
}
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
return;
|
|
7135
|
-
} else {
|
|
7136
|
-
throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
|
|
7137
|
-
}
|
|
7138
|
-
const promisedJsType = jsType;
|
|
7139
|
-
if (isInterface) {
|
|
7140
|
-
jsType = `${jsType}$Client`;
|
|
7141
|
-
}
|
|
7142
|
-
const { name } = field;
|
|
7143
|
-
const properName = c2t(name);
|
|
6825
|
+
`);
|
|
6826
|
+
}
|
|
6827
|
+
if (union) {
|
|
7144
6828
|
members.push(`
|
|
7145
|
-
get${
|
|
7146
|
-
return
|
|
6829
|
+
get _is${capitalizedName}(): boolean {
|
|
6830
|
+
return $.utils.getUint16(${discriminantOffset * 2}, this) === ${discriminantValue};
|
|
7147
6831
|
}
|
|
7148
6832
|
`);
|
|
7149
|
-
}, "generatePromiseFieldMethod");
|
|
7150
|
-
for (const field of fields) {
|
|
7151
|
-
generatePromiseFieldMethod(field);
|
|
7152
6833
|
}
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
6834
|
+
if (set || union) {
|
|
6835
|
+
const param = set ? `value: ${jsType}` : `_: true`;
|
|
6836
|
+
members.push(`
|
|
6837
|
+
set ${accessorName}(${param}) {
|
|
6838
|
+
${union ? `$.utils.setUint16(${discriminantOffset * 2}, ${discriminantValue}, this);` : ""}
|
|
6839
|
+
${set ? `${set};` : ""}
|
|
6840
|
+
}
|
|
6841
|
+
`);
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
__name(generateStructFieldMethods, "generateStructFieldMethods");
|
|
6845
|
+
function generateDefaultValue(field) {
|
|
6846
|
+
const { name, slot } = field;
|
|
6847
|
+
const whichSlotType = slot.type.which();
|
|
6848
|
+
const primitive = Primitives[whichSlotType];
|
|
6849
|
+
let initializer;
|
|
6850
|
+
switch (whichSlotType) {
|
|
6851
|
+
case Type_Which.ANY_POINTER:
|
|
6852
|
+
case Type_Which.DATA:
|
|
6853
|
+
case Type_Which.LIST:
|
|
6854
|
+
case Type_Which.STRUCT:
|
|
6855
|
+
case Type_Which.INTERFACE: {
|
|
6856
|
+
initializer = createValue(slot.defaultValue);
|
|
6857
|
+
break;
|
|
7156
6858
|
}
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
${members.join("\n")}
|
|
6859
|
+
case Type_Which.TEXT: {
|
|
6860
|
+
initializer = JSON.stringify(slot.defaultValue.text);
|
|
6861
|
+
break;
|
|
7161
6862
|
}
|
|
7162
|
-
|
|
6863
|
+
case Type_Which.BOOL: {
|
|
6864
|
+
const value = createValue(slot.defaultValue);
|
|
6865
|
+
const bitOffset = slot.offset % 8;
|
|
6866
|
+
initializer = `$.${primitive.mask}(${value}, ${bitOffset})`;
|
|
6867
|
+
break;
|
|
6868
|
+
}
|
|
6869
|
+
case Type_Which.ENUM:
|
|
6870
|
+
case Type_Which.FLOAT32:
|
|
6871
|
+
case Type_Which.FLOAT64:
|
|
6872
|
+
case Type_Which.INT16:
|
|
6873
|
+
case Type_Which.INT32:
|
|
6874
|
+
case Type_Which.INT64:
|
|
6875
|
+
case Type_Which.INT8:
|
|
6876
|
+
case Type_Which.UINT16:
|
|
6877
|
+
case Type_Which.UINT32:
|
|
6878
|
+
case Type_Which.UINT64:
|
|
6879
|
+
case Type_Which.UINT8: {
|
|
6880
|
+
const value = createValue(slot.defaultValue);
|
|
6881
|
+
initializer = `$.${primitive.mask}(${value})`;
|
|
6882
|
+
break;
|
|
6883
|
+
}
|
|
6884
|
+
default: {
|
|
6885
|
+
throw new Error(
|
|
6886
|
+
format(
|
|
6887
|
+
GEN_UNKNOWN_DEFAULT,
|
|
6888
|
+
whichSlotType
|
|
6889
|
+
)
|
|
6890
|
+
);
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
return `default${c2t(name)}: ${initializer}`;
|
|
7163
6894
|
}
|
|
7164
|
-
__name(
|
|
7165
|
-
function
|
|
7166
|
-
const
|
|
7167
|
-
const
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
6895
|
+
__name(generateDefaultValue, "generateDefaultValue");
|
|
6896
|
+
function createConcreteListProperty(ctx, field) {
|
|
6897
|
+
const name = `_${c2t(field.name)}`;
|
|
6898
|
+
const type = getJsType(ctx, field.slot.type, true);
|
|
6899
|
+
return `static ${name}: ${type};`;
|
|
6900
|
+
}
|
|
6901
|
+
__name(createConcreteListProperty, "createConcreteListProperty");
|
|
6902
|
+
function createUnionConstProperty(fullClassName, field) {
|
|
6903
|
+
const name = c2s(field.name);
|
|
6904
|
+
const initializer = `${fullClassName}_Which.${name}`;
|
|
6905
|
+
return `static readonly ${name} = ${initializer};`;
|
|
6906
|
+
}
|
|
6907
|
+
__name(createUnionConstProperty, "createUnionConstProperty");
|
|
6908
|
+
function createValue(value) {
|
|
6909
|
+
let p;
|
|
6910
|
+
switch (value.which()) {
|
|
6911
|
+
case Value.BOOL: {
|
|
6912
|
+
return value.bool ? `true` : `false`;
|
|
6913
|
+
}
|
|
6914
|
+
case Value.ENUM: {
|
|
6915
|
+
return String(value.enum);
|
|
6916
|
+
}
|
|
6917
|
+
case Value.FLOAT32: {
|
|
6918
|
+
return String(value.float32);
|
|
6919
|
+
}
|
|
6920
|
+
case Value.FLOAT64: {
|
|
6921
|
+
return String(value.float64);
|
|
6922
|
+
}
|
|
6923
|
+
case Value.INT8: {
|
|
6924
|
+
return String(value.int8);
|
|
6925
|
+
}
|
|
6926
|
+
case Value.INT16: {
|
|
6927
|
+
return String(value.int16);
|
|
6928
|
+
}
|
|
6929
|
+
case Value.INT32: {
|
|
6930
|
+
return String(value.int32);
|
|
6931
|
+
}
|
|
6932
|
+
case Value.INT64: {
|
|
6933
|
+
return createBigInt(value.int64);
|
|
6934
|
+
}
|
|
6935
|
+
case Value.UINT8: {
|
|
6936
|
+
return String(value.uint8);
|
|
6937
|
+
}
|
|
6938
|
+
case Value.UINT16: {
|
|
6939
|
+
return String(value.uint16);
|
|
6940
|
+
}
|
|
6941
|
+
case Value.UINT32: {
|
|
6942
|
+
return String(value.uint32);
|
|
6943
|
+
}
|
|
6944
|
+
case Value.UINT64: {
|
|
6945
|
+
return createBigInt(value.uint64);
|
|
6946
|
+
}
|
|
6947
|
+
case Value.TEXT: {
|
|
6948
|
+
return JSON.stringify(value.text);
|
|
6949
|
+
}
|
|
6950
|
+
case Value.VOID: {
|
|
6951
|
+
return "undefined";
|
|
6952
|
+
}
|
|
6953
|
+
case Value.ANY_POINTER: {
|
|
6954
|
+
p = value.anyPointer;
|
|
6955
|
+
break;
|
|
6956
|
+
}
|
|
6957
|
+
case Value.DATA: {
|
|
6958
|
+
p = value.data;
|
|
6959
|
+
break;
|
|
6960
|
+
}
|
|
6961
|
+
case Value.LIST: {
|
|
6962
|
+
p = value.list;
|
|
6963
|
+
break;
|
|
6964
|
+
}
|
|
6965
|
+
case Value.STRUCT: {
|
|
6966
|
+
p = value.struct;
|
|
6967
|
+
break;
|
|
7195
6968
|
}
|
|
7196
|
-
|
|
6969
|
+
case Value.INTERFACE: {
|
|
6970
|
+
testWhich("interface", getUint16(0, value), 17, value);
|
|
6971
|
+
p = getPointer(0, value);
|
|
6972
|
+
break;
|
|
6973
|
+
}
|
|
6974
|
+
default: {
|
|
6975
|
+
throw new Error(format(GEN_SERIALIZE_UNKNOWN_VALUE, value.which()));
|
|
6976
|
+
}
|
|
6977
|
+
}
|
|
6978
|
+
const message = new Message();
|
|
6979
|
+
message.setRoot(p);
|
|
6980
|
+
const buf = new Uint8Array(message.toPackedArrayBuffer());
|
|
6981
|
+
const values = [];
|
|
6982
|
+
for (let i = 0; i < buf.byteLength; i++) {
|
|
6983
|
+
values.push(`0x${pad(buf[i].toString(16), 2)}`);
|
|
6984
|
+
}
|
|
6985
|
+
return `$.readRawPointer(new Uint8Array([${values.join(",")}]).buffer)`;
|
|
7197
6986
|
}
|
|
7198
|
-
__name(
|
|
7199
|
-
function
|
|
6987
|
+
__name(createValue, "createValue");
|
|
6988
|
+
function createNestedNodeProperty(node) {
|
|
6989
|
+
const name = getDisplayNamePrefix(node);
|
|
6990
|
+
const initializer = getFullClassName(node);
|
|
6991
|
+
return `static readonly ${name} = ${initializer};`;
|
|
6992
|
+
}
|
|
6993
|
+
__name(createNestedNodeProperty, "createNestedNodeProperty");
|
|
6994
|
+
function generateInterfaceNode(ctx, node) {
|
|
7200
6995
|
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
7201
6996
|
const fullClassName = getFullClassName(node);
|
|
7202
|
-
const nestedNodes = node.nestedNodes.map((
|
|
6997
|
+
const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
|
|
7203
6998
|
const nodeId = node.id;
|
|
7204
6999
|
const nodeIdHex = nodeId.toString(16);
|
|
7205
|
-
const
|
|
7206
|
-
const { struct } = node;
|
|
7207
|
-
const { dataWordCount, discriminantCount, discriminantOffset, pointerCount } = struct;
|
|
7208
|
-
const dataByteLength = dataWordCount * 8;
|
|
7209
|
-
const fields = struct.fields.toArray();
|
|
7210
|
-
const fieldIndexInCodeOrder = fields.map(({ codeOrder }, fieldIndex) => ({ fieldIndex, codeOrder })).sort(compareCodeOrder).map(({ fieldIndex }) => fieldIndex);
|
|
7211
|
-
const concreteLists = fields.filter((field) => needsConcreteListClass(field)).sort(compareCodeOrder);
|
|
7212
|
-
const consts = ctx.nodes.filter(
|
|
7213
|
-
(node2) => node2.scopeId === nodeId && node2._isConst
|
|
7214
|
-
);
|
|
7215
|
-
const hasUnnamedUnion = discriminantCount !== 0;
|
|
7216
|
-
if (hasUnnamedUnion) {
|
|
7217
|
-
generateEnumNode(ctx, fullClassName + "_Which", node, unionFields);
|
|
7218
|
-
}
|
|
7000
|
+
const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
|
|
7219
7001
|
const members = [];
|
|
7220
7002
|
members.push(
|
|
7221
7003
|
...consts.map((node2) => {
|
|
@@ -7223,691 +7005,959 @@ function generateStructNode(ctx, node) {
|
|
|
7223
7005
|
const value = createValue(node2.const.value);
|
|
7224
7006
|
return `static readonly ${name} = ${value}`;
|
|
7225
7007
|
}),
|
|
7226
|
-
...
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
for (const index of fieldIndexInCodeOrder) {
|
|
7231
|
-
const field = fields[index];
|
|
7232
|
-
if (field._isSlot && field.slot.hadExplicitDefault && field.slot.type.which() !== Type.VOID) {
|
|
7233
|
-
defaultValues.push(generateDefaultValue(field));
|
|
7234
|
-
}
|
|
7235
|
-
}
|
|
7236
|
-
members.push(
|
|
7237
|
-
`
|
|
7238
|
-
public static override readonly _capnp = {
|
|
7008
|
+
...nestedNodes.map((node2) => createNestedNodeProperty(node2)),
|
|
7009
|
+
`static readonly Client = ${fullClassName}$Client;
|
|
7010
|
+
static readonly Server = ${fullClassName}$Server;
|
|
7011
|
+
public static override readonly _capnp = {
|
|
7239
7012
|
displayName: "${displayNamePrefix}",
|
|
7240
7013
|
id: "${nodeIdHex}",
|
|
7241
|
-
size: new $.ObjectSize(
|
|
7242
|
-
${defaultValues.join(",")}
|
|
7243
|
-
}`,
|
|
7244
|
-
...concreteLists.map((field) => createConcreteListProperty(ctx, field))
|
|
7245
|
-
);
|
|
7246
|
-
for (const index of fieldIndexInCodeOrder) {
|
|
7247
|
-
const field = fields[index];
|
|
7248
|
-
generateStructFieldMethods(ctx, members, node, field, index);
|
|
7249
|
-
}
|
|
7250
|
-
members.push(
|
|
7251
|
-
`public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
7252
|
-
);
|
|
7253
|
-
if (hasUnnamedUnion) {
|
|
7254
|
-
members.push(`
|
|
7255
|
-
which(): ${fullClassName}_Which {
|
|
7256
|
-
return $.utils.getUint16(${discriminantOffset * 2}, this) as ${fullClassName}_Which;
|
|
7014
|
+
size: new $.ObjectSize(0, 0),
|
|
7257
7015
|
}
|
|
7258
|
-
|
|
7259
|
-
|
|
7016
|
+
public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
7017
|
+
);
|
|
7260
7018
|
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
7261
7019
|
const classCode = `
|
|
7262
7020
|
${docComment}
|
|
7263
|
-
export class ${fullClassName} extends $.
|
|
7021
|
+
export class ${fullClassName} extends $.Interface {
|
|
7264
7022
|
${members.join("\n")}
|
|
7265
7023
|
}`;
|
|
7024
|
+
generateInterfaceClasses(ctx, node);
|
|
7266
7025
|
ctx.codeParts.push(classCode);
|
|
7267
|
-
ctx.concreteLists.push(
|
|
7268
|
-
...concreteLists.map((field) => [
|
|
7269
|
-
fullClassName,
|
|
7270
|
-
field
|
|
7271
|
-
])
|
|
7272
|
-
);
|
|
7273
7026
|
}
|
|
7274
|
-
__name(
|
|
7275
|
-
function
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
if (
|
|
7279
|
-
|
|
7280
|
-
jsType = getJsType(ctx, slotType, false);
|
|
7281
|
-
whichType = slotType.which();
|
|
7282
|
-
} else if (field._isGroup) {
|
|
7283
|
-
jsType = getFullClassName(lookupNode(ctx, field.group.typeId));
|
|
7284
|
-
whichType = "group";
|
|
7285
|
-
} else {
|
|
7286
|
-
throw new Error(format(GEN_UNKNOWN_STRUCT_FIELD, field.which()));
|
|
7027
|
+
__name(generateInterfaceNode, "generateInterfaceNode");
|
|
7028
|
+
function generateNode(ctx, node) {
|
|
7029
|
+
const nodeId = node.id;
|
|
7030
|
+
const nodeIdHex = nodeId.toString(16);
|
|
7031
|
+
if (ctx.generatedNodeIds.has(nodeIdHex)) {
|
|
7032
|
+
return;
|
|
7287
7033
|
}
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7034
|
+
ctx.generatedNodeIds.add(nodeIdHex);
|
|
7035
|
+
const nestedNodes = node.nestedNodes.map((node2) => lookupNode(ctx, node2));
|
|
7036
|
+
for (const nestedNode of nestedNodes) {
|
|
7037
|
+
generateNode(ctx, nestedNode);
|
|
7291
7038
|
}
|
|
7292
|
-
const
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
const
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
const
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
let adopt2 = false;
|
|
7303
|
-
let disown2 = false;
|
|
7304
|
-
let has = false;
|
|
7305
|
-
let init;
|
|
7306
|
-
let get;
|
|
7307
|
-
let set;
|
|
7308
|
-
switch (whichType) {
|
|
7309
|
-
case Type.ANY_POINTER: {
|
|
7310
|
-
adopt2 = true;
|
|
7311
|
-
disown2 = true;
|
|
7312
|
-
has = true;
|
|
7313
|
-
get = `$.utils.getPointer(${offset}, this${maybeDefaultArg})`;
|
|
7314
|
-
set = `$.utils.copyFrom(value, ${get})`;
|
|
7039
|
+
const groupNodes = ctx.nodes.filter(
|
|
7040
|
+
(node2) => node2.scopeId === nodeId && node2._isStruct && node2.struct.isGroup
|
|
7041
|
+
);
|
|
7042
|
+
for (const groupNode of groupNodes) {
|
|
7043
|
+
generateNode(ctx, groupNode);
|
|
7044
|
+
}
|
|
7045
|
+
const nodeType = node.which();
|
|
7046
|
+
switch (nodeType) {
|
|
7047
|
+
case Node.STRUCT: {
|
|
7048
|
+
generateStructNode(ctx, node);
|
|
7315
7049
|
break;
|
|
7316
7050
|
}
|
|
7317
|
-
case
|
|
7318
|
-
case Type.ENUM:
|
|
7319
|
-
case Type.FLOAT32:
|
|
7320
|
-
case Type.FLOAT64:
|
|
7321
|
-
case Type.INT16:
|
|
7322
|
-
case Type.INT32:
|
|
7323
|
-
case Type.INT64:
|
|
7324
|
-
case Type.INT8:
|
|
7325
|
-
case Type.UINT16:
|
|
7326
|
-
case Type.UINT32:
|
|
7327
|
-
case Type.UINT64:
|
|
7328
|
-
case Type.UINT8: {
|
|
7329
|
-
const { byteLength, getter, setter } = Primitives[whichType];
|
|
7330
|
-
const byteOffset = offset * byteLength;
|
|
7331
|
-
get = `$.utils.${getter}(${byteOffset}, this${maybeDefaultArg})`;
|
|
7332
|
-
set = `$.utils.${setter}(${byteOffset}, value, this${maybeDefaultArg})`;
|
|
7333
|
-
if (whichType === Type.ENUM) {
|
|
7334
|
-
get = `${get} as ${jsType}`;
|
|
7335
|
-
}
|
|
7051
|
+
case Node.CONST: {
|
|
7336
7052
|
break;
|
|
7337
7053
|
}
|
|
7338
|
-
case
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7054
|
+
case Node.ENUM: {
|
|
7055
|
+
generateEnumNode(
|
|
7056
|
+
ctx,
|
|
7057
|
+
getFullClassName(node),
|
|
7058
|
+
node,
|
|
7059
|
+
node.enum.enumerants.toArray()
|
|
7060
|
+
);
|
|
7345
7061
|
break;
|
|
7346
7062
|
}
|
|
7347
|
-
case
|
|
7348
|
-
|
|
7349
|
-
set = `$.utils.setInterfacePointer(this.segment.message.addCap(value.client), $.utils.getPointer(${offset}, this))`;
|
|
7063
|
+
case Node.INTERFACE: {
|
|
7064
|
+
generateInterfaceNode(ctx, node);
|
|
7350
7065
|
break;
|
|
7351
7066
|
}
|
|
7352
|
-
case
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7067
|
+
case Node.ANNOTATION: {
|
|
7068
|
+
break;
|
|
7069
|
+
}
|
|
7070
|
+
// case s.Node.FILE:
|
|
7071
|
+
default: {
|
|
7072
|
+
throw new Error(
|
|
7073
|
+
format(
|
|
7074
|
+
GEN_NODE_UNKNOWN_TYPE,
|
|
7075
|
+
nodeType
|
|
7076
|
+
/* s.Node_Which[whichNode] */
|
|
7077
|
+
)
|
|
7078
|
+
);
|
|
7079
|
+
}
|
|
7080
|
+
}
|
|
7081
|
+
}
|
|
7082
|
+
__name(generateNode, "generateNode");
|
|
7083
|
+
var CodeGeneratorContext = class {
|
|
7084
|
+
static {
|
|
7085
|
+
__name(this, "CodeGeneratorContext");
|
|
7086
|
+
}
|
|
7087
|
+
files = [];
|
|
7088
|
+
};
|
|
7089
|
+
var CodeGeneratorFileContext = class {
|
|
7090
|
+
static {
|
|
7091
|
+
__name(this, "CodeGeneratorFileContext");
|
|
7092
|
+
}
|
|
7093
|
+
constructor(req, file) {
|
|
7094
|
+
this.req = req;
|
|
7095
|
+
this.file = file;
|
|
7096
|
+
this.nodes = req.nodes.toArray();
|
|
7097
|
+
this.imports = file.imports.toArray();
|
|
7098
|
+
}
|
|
7099
|
+
// inputs
|
|
7100
|
+
nodes;
|
|
7101
|
+
imports;
|
|
7102
|
+
// outputs
|
|
7103
|
+
concreteLists = [];
|
|
7104
|
+
generatedNodeIds = /* @__PURE__ */ new Set();
|
|
7105
|
+
generatedResultsPromiseIds = /* @__PURE__ */ new Set();
|
|
7106
|
+
tsPath = "";
|
|
7107
|
+
codeParts = [];
|
|
7108
|
+
toString() {
|
|
7109
|
+
return this.file?.filename ?? "CodeGeneratorFileContext()";
|
|
7110
|
+
}
|
|
7111
|
+
};
|
|
7112
|
+
function generateFileId(ctx) {
|
|
7113
|
+
ctx.codeParts.push(
|
|
7114
|
+
`export const _capnpFileId = BigInt("0x${ctx.file.id.toString(16)}");`
|
|
7115
|
+
);
|
|
7116
|
+
}
|
|
7117
|
+
__name(generateFileId, "generateFileId");
|
|
7118
|
+
function generateConcreteListInitializer(ctx, fullClassName, field) {
|
|
7119
|
+
const name = `_${c2t(field.name)}`;
|
|
7120
|
+
const type = getConcreteListType(ctx, field.slot.type);
|
|
7121
|
+
ctx.codeParts.push(`${fullClassName}.${name} = ${type};`);
|
|
7122
|
+
}
|
|
7123
|
+
__name(generateConcreteListInitializer, "generateConcreteListInitializer");
|
|
7124
|
+
function generateCapnpImport(ctx) {
|
|
7125
|
+
const fileNode = lookupNode(ctx, ctx.file);
|
|
7126
|
+
const tsFileId = hexToBigInt(TS_FILE_ID);
|
|
7127
|
+
const tsAnnotationFile = ctx.nodes.find((n) => n.id === tsFileId);
|
|
7128
|
+
const tsImportPathAnnotation = tsAnnotationFile?.nestedNodes.find(
|
|
7129
|
+
(n) => n.name === "importPath"
|
|
7130
|
+
);
|
|
7131
|
+
const importAnnotation = tsImportPathAnnotation && fileNode.annotations.find((a) => a.id === tsImportPathAnnotation.id);
|
|
7132
|
+
const importPath = importAnnotation === void 0 ? "@stryke/capnp" : importAnnotation.value.text;
|
|
7133
|
+
ctx.codeParts.push(`import * as $ from '${importPath}';`);
|
|
7134
|
+
}
|
|
7135
|
+
__name(generateCapnpImport, "generateCapnpImport");
|
|
7136
|
+
function generateNestedImports(ctx) {
|
|
7137
|
+
for (const imp of ctx.imports) {
|
|
7138
|
+
const { name } = imp;
|
|
7139
|
+
let importPath;
|
|
7140
|
+
if (name.startsWith("/capnp/")) {
|
|
7141
|
+
importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
|
|
7142
|
+
} else {
|
|
7143
|
+
importPath = name.replace(/\.capnp$/, "");
|
|
7144
|
+
if (importPath[0] !== ".") {
|
|
7145
|
+
importPath = `./${importPath}`;
|
|
7371
7146
|
}
|
|
7372
|
-
break;
|
|
7373
|
-
}
|
|
7374
|
-
case Type.STRUCT: {
|
|
7375
|
-
adopt2 = true;
|
|
7376
|
-
disown2 = true;
|
|
7377
|
-
has = true;
|
|
7378
|
-
get = `$.utils.getStruct(${offset}, ${jsType}, this${maybeDefaultArg})`;
|
|
7379
|
-
set = `$.utils.copyFrom(value, $.utils.getPointer(${offset}, this))`;
|
|
7380
|
-
init = `$.utils.initStructAt(${offset}, ${jsType}, this)`;
|
|
7381
|
-
break;
|
|
7382
|
-
}
|
|
7383
|
-
case Type.TEXT: {
|
|
7384
|
-
get = `$.utils.getText(${offset}, this${maybeDefaultArg})`;
|
|
7385
|
-
set = `$.utils.setText(${offset}, value, this)`;
|
|
7386
|
-
break;
|
|
7387
7147
|
}
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
throw new Error(format(GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE, "group"));
|
|
7148
|
+
const importNode = lookupNode(ctx, imp);
|
|
7149
|
+
const imports = getImportNodes(ctx, importNode).flatMap((node) => {
|
|
7150
|
+
const fullClassName = getFullClassName(node);
|
|
7151
|
+
if (node._isInterface) {
|
|
7152
|
+
return [fullClassName, `${fullClassName}$Client`];
|
|
7394
7153
|
}
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7154
|
+
return fullClassName;
|
|
7155
|
+
}).sort().join(", ");
|
|
7156
|
+
if (imports.length === 0) {
|
|
7157
|
+
continue;
|
|
7398
7158
|
}
|
|
7159
|
+
ctx.codeParts.push(`import { ${imports} } from "${importPath}";`);
|
|
7399
7160
|
}
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7161
|
+
}
|
|
7162
|
+
__name(generateNestedImports, "generateNestedImports");
|
|
7163
|
+
function getImportNodes(ctx, node, visitedIds = /* @__PURE__ */ new Set()) {
|
|
7164
|
+
visitedIds.add(node.id);
|
|
7165
|
+
const nestedNodes = node.nestedNodes.filter(({ id }) => hasNode(ctx, id));
|
|
7166
|
+
const newNestedNodes = nestedNodes.filter(({ id }) => !visitedIds.has(id));
|
|
7167
|
+
const nodes = newNestedNodes.map(({ id }) => lookupNode(ctx, id)).filter((node2) => node2._isStruct || node2._isEnum || node2._isInterface);
|
|
7168
|
+
return nodes.concat(
|
|
7169
|
+
nodes.flatMap((node2) => getImportNodes(ctx, node2, visitedIds))
|
|
7170
|
+
);
|
|
7171
|
+
}
|
|
7172
|
+
__name(getImportNodes, "getImportNodes");
|
|
7173
|
+
async function compileAll(codeGenRequest, opts) {
|
|
7174
|
+
const req = new Message(codeGenRequest, false).getRoot(
|
|
7175
|
+
CodeGeneratorRequest
|
|
7176
|
+
);
|
|
7177
|
+
const ctx = new CodeGeneratorContext();
|
|
7178
|
+
ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
|
|
7179
|
+
if (ctx.files.length === 0) {
|
|
7180
|
+
throw new Error(GEN_NO_FILES);
|
|
7407
7181
|
}
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
`);
|
|
7182
|
+
const files = new Map(
|
|
7183
|
+
ctx.files.map((file) => [file.tsPath, compileFile(file)])
|
|
7184
|
+
);
|
|
7185
|
+
if (files.size === 0) {
|
|
7186
|
+
throw new Error(GEN_NO_FILES);
|
|
7414
7187
|
}
|
|
7415
|
-
if (
|
|
7416
|
-
|
|
7417
|
-
lookupNodeSourceInfo(ctx, node)?.members.at(fieldIndex)
|
|
7418
|
-
);
|
|
7419
|
-
members.push(`
|
|
7420
|
-
${docComment}
|
|
7421
|
-
get ${accessorName}(): ${jsType} {
|
|
7422
|
-
${union ? `$.utils.testWhich(${JSON.stringify(name)}, $.utils.getUint16(${discriminantOffset * 2}, this), ${discriminantValue}, this);` : ""}
|
|
7423
|
-
return ${get};
|
|
7424
|
-
}
|
|
7425
|
-
`);
|
|
7188
|
+
if (opts?.dts === true || opts?.js === true) {
|
|
7189
|
+
tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
|
|
7426
7190
|
}
|
|
7427
|
-
if (
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7191
|
+
if (!opts?.ts) {
|
|
7192
|
+
for (const [fileName] of files) {
|
|
7193
|
+
if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
|
|
7194
|
+
files.delete(fileName);
|
|
7431
7195
|
}
|
|
7432
|
-
|
|
7196
|
+
}
|
|
7433
7197
|
}
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7198
|
+
return {
|
|
7199
|
+
ctx,
|
|
7200
|
+
files
|
|
7201
|
+
};
|
|
7202
|
+
}
|
|
7203
|
+
__name(compileAll, "compileAll");
|
|
7204
|
+
function compileFile(ctx) {
|
|
7205
|
+
generateCapnpImport(ctx);
|
|
7206
|
+
generateNestedImports(ctx);
|
|
7207
|
+
generateFileId(ctx);
|
|
7208
|
+
const nestedNodes = lookupNode(ctx, ctx.file).nestedNodes.map(
|
|
7209
|
+
(n) => lookupNode(ctx, n)
|
|
7210
|
+
);
|
|
7211
|
+
for (const node of nestedNodes) {
|
|
7212
|
+
generateNode(ctx, node);
|
|
7213
|
+
}
|
|
7214
|
+
for (const [fullClassName, field] of ctx.concreteLists) {
|
|
7215
|
+
generateConcreteListInitializer(ctx, fullClassName, field);
|
|
7216
|
+
}
|
|
7217
|
+
const sourceFile = import_typescript.default.createSourceFile(
|
|
7218
|
+
ctx.tsPath,
|
|
7219
|
+
ctx.codeParts.map((p) => p.toString()).join(""),
|
|
7220
|
+
import_typescript.default.ScriptTarget.Latest,
|
|
7221
|
+
false,
|
|
7222
|
+
import_typescript.default.ScriptKind.TS
|
|
7223
|
+
);
|
|
7224
|
+
return SOURCE_COMMENT + import_typescript.default.createPrinter().printFile(sourceFile);
|
|
7225
|
+
}
|
|
7226
|
+
__name(compileFile, "compileFile");
|
|
7227
|
+
function tsCompile(files, dts, js, tsconfig) {
|
|
7228
|
+
if (!dts && !js) {
|
|
7229
|
+
return;
|
|
7230
|
+
}
|
|
7231
|
+
const compileOptions = {
|
|
7232
|
+
moduleResolution: import_typescript.default.ModuleResolutionKind.Bundler,
|
|
7233
|
+
target: import_typescript.default.ScriptTarget.ESNext,
|
|
7234
|
+
strict: true,
|
|
7235
|
+
...tsconfig,
|
|
7236
|
+
noEmitOnError: false,
|
|
7237
|
+
noFallthroughCasesInSwitch: true,
|
|
7238
|
+
preserveConstEnums: true,
|
|
7239
|
+
noImplicitReturns: true,
|
|
7240
|
+
noUnusedLocals: false,
|
|
7241
|
+
noUnusedParameters: false,
|
|
7242
|
+
removeComments: false,
|
|
7243
|
+
skipLibCheck: true,
|
|
7244
|
+
sourceMap: false,
|
|
7245
|
+
emitDeclarationOnly: dts && !js,
|
|
7246
|
+
declaration: dts
|
|
7247
|
+
};
|
|
7248
|
+
const compilerHost = import_typescript.default.createCompilerHost(compileOptions);
|
|
7249
|
+
compilerHost.writeFile = (fileName, declaration) => {
|
|
7250
|
+
files.set(fileName, declaration);
|
|
7251
|
+
};
|
|
7252
|
+
const _readFile = compilerHost.readFile;
|
|
7253
|
+
compilerHost.readFile = (filename) => {
|
|
7254
|
+
if (files.has(filename)) {
|
|
7255
|
+
return files.get(filename);
|
|
7256
|
+
}
|
|
7257
|
+
return _readFile(filename);
|
|
7258
|
+
};
|
|
7259
|
+
const program = import_typescript.default.createProgram(
|
|
7260
|
+
[...files.keys()],
|
|
7261
|
+
compileOptions,
|
|
7262
|
+
compilerHost
|
|
7263
|
+
);
|
|
7264
|
+
const emitResult = program.emit();
|
|
7265
|
+
const allDiagnostics = [
|
|
7266
|
+
...import_typescript.default.getPreEmitDiagnostics(program),
|
|
7267
|
+
...emitResult.diagnostics
|
|
7268
|
+
];
|
|
7269
|
+
if (allDiagnostics.length > 0) {
|
|
7270
|
+
for (const diagnostic of allDiagnostics) {
|
|
7271
|
+
const message = import_typescript.default.flattenDiagnosticMessageText(
|
|
7272
|
+
diagnostic.messageText,
|
|
7273
|
+
"\n"
|
|
7274
|
+
);
|
|
7275
|
+
if (diagnostic.file && diagnostic.start) {
|
|
7276
|
+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
7277
|
+
console.log(
|
|
7278
|
+
`${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`
|
|
7279
|
+
);
|
|
7280
|
+
} else {
|
|
7281
|
+
console.log(`==> ${message}`);
|
|
7440
7282
|
}
|
|
7441
|
-
|
|
7283
|
+
}
|
|
7284
|
+
throw new Error(GEN_TS_EMIT_FAILED);
|
|
7285
|
+
}
|
|
7286
|
+
}
|
|
7287
|
+
__name(tsCompile, "tsCompile");
|
|
7288
|
+
|
|
7289
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/compiler/index.mjs
|
|
7290
|
+
var import_typescript2 = require("typescript");
|
|
7291
|
+
|
|
7292
|
+
// src/compile.ts
|
|
7293
|
+
var import_defu2 = __toESM(require("defu"), 1);
|
|
7294
|
+
var import_node_buffer2 = require("buffer");
|
|
7295
|
+
var import_node_child_process = require("child_process");
|
|
7296
|
+
|
|
7297
|
+
// src/helpers.ts
|
|
7298
|
+
var import_console = require("@storm-software/config-tools/logger/console");
|
|
7299
|
+
|
|
7300
|
+
// ../type-checks/src/get-object-tag.ts
|
|
7301
|
+
var getObjectTag = /* @__PURE__ */ __name((value) => {
|
|
7302
|
+
if (value == null) {
|
|
7303
|
+
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
7304
|
+
}
|
|
7305
|
+
return Object.prototype.toString.call(value);
|
|
7306
|
+
}, "getObjectTag");
|
|
7307
|
+
|
|
7308
|
+
// ../type-checks/src/is-plain-object.ts
|
|
7309
|
+
var isObjectLike = /* @__PURE__ */ __name((obj) => {
|
|
7310
|
+
return typeof obj === "object" && obj !== null;
|
|
7311
|
+
}, "isObjectLike");
|
|
7312
|
+
var isPlainObject = /* @__PURE__ */ __name((obj) => {
|
|
7313
|
+
if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
|
|
7314
|
+
return false;
|
|
7315
|
+
}
|
|
7316
|
+
if (Object.getPrototypeOf(obj) === null) {
|
|
7317
|
+
return true;
|
|
7318
|
+
}
|
|
7319
|
+
let proto = obj;
|
|
7320
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
7321
|
+
proto = Object.getPrototypeOf(proto);
|
|
7442
7322
|
}
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7323
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
7324
|
+
}, "isPlainObject");
|
|
7325
|
+
|
|
7326
|
+
// ../type-checks/src/is-object.ts
|
|
7327
|
+
var isObject = /* @__PURE__ */ __name((value) => {
|
|
7328
|
+
try {
|
|
7329
|
+
return typeof value === "object" || Boolean(value) && value?.constructor === Object || isPlainObject(value);
|
|
7330
|
+
} catch {
|
|
7331
|
+
return false;
|
|
7449
7332
|
}
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7333
|
+
}, "isObject");
|
|
7334
|
+
|
|
7335
|
+
// ../type-checks/src/is-string.ts
|
|
7336
|
+
var isString = /* @__PURE__ */ __name((value) => {
|
|
7337
|
+
try {
|
|
7338
|
+
return typeof value === "string";
|
|
7339
|
+
} catch {
|
|
7340
|
+
return false;
|
|
7458
7341
|
}
|
|
7342
|
+
}, "isString");
|
|
7343
|
+
|
|
7344
|
+
// ../json/src/storm-json.ts
|
|
7345
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
7346
|
+
var import_node_buffer = require("buffer");
|
|
7347
|
+
var import_superjson = __toESM(require("superjson"), 1);
|
|
7348
|
+
|
|
7349
|
+
// ../json/src/utils/strip-comments.ts
|
|
7350
|
+
var singleComment = Symbol("singleComment");
|
|
7351
|
+
var multiComment = Symbol("multiComment");
|
|
7352
|
+
function stripWithoutWhitespace() {
|
|
7353
|
+
return "";
|
|
7459
7354
|
}
|
|
7460
|
-
__name(
|
|
7461
|
-
function
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7355
|
+
__name(stripWithoutWhitespace, "stripWithoutWhitespace");
|
|
7356
|
+
function stripWithWhitespace(value, start, end) {
|
|
7357
|
+
return value.slice(start, end).replace(/\S/g, " ");
|
|
7358
|
+
}
|
|
7359
|
+
__name(stripWithWhitespace, "stripWithWhitespace");
|
|
7360
|
+
function isEscaped(value, quotePosition) {
|
|
7361
|
+
let index = quotePosition - 1;
|
|
7362
|
+
let backslashCount = 0;
|
|
7363
|
+
while (value[index] === "\\") {
|
|
7364
|
+
index -= 1;
|
|
7365
|
+
backslashCount += 1;
|
|
7366
|
+
}
|
|
7367
|
+
return Boolean(backslashCount % 2);
|
|
7368
|
+
}
|
|
7369
|
+
__name(isEscaped, "isEscaped");
|
|
7370
|
+
function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
|
|
7371
|
+
if (typeof value !== "string") {
|
|
7372
|
+
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
|
|
7373
|
+
}
|
|
7374
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
7375
|
+
let isInsideString = false;
|
|
7376
|
+
let isInsideComment = false;
|
|
7377
|
+
let offset = 0;
|
|
7378
|
+
let buffer = "";
|
|
7379
|
+
let result = "";
|
|
7380
|
+
let commaIndex = -1;
|
|
7381
|
+
for (let index = 0; index < value.length; index++) {
|
|
7382
|
+
const currentCharacter = value[index];
|
|
7383
|
+
const nextCharacter = value[index + 1];
|
|
7384
|
+
if (!isInsideComment && currentCharacter === '"') {
|
|
7385
|
+
const escaped = isEscaped(value, index);
|
|
7386
|
+
if (!escaped) {
|
|
7387
|
+
isInsideString = !isInsideString;
|
|
7388
|
+
}
|
|
7484
7389
|
}
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
case Type_Which.FLOAT64:
|
|
7488
|
-
case Type_Which.INT16:
|
|
7489
|
-
case Type_Which.INT32:
|
|
7490
|
-
case Type_Which.INT64:
|
|
7491
|
-
case Type_Which.INT8:
|
|
7492
|
-
case Type_Which.UINT16:
|
|
7493
|
-
case Type_Which.UINT32:
|
|
7494
|
-
case Type_Which.UINT64:
|
|
7495
|
-
case Type_Which.UINT8: {
|
|
7496
|
-
const value = createValue(slot.defaultValue);
|
|
7497
|
-
initializer = `$.${primitive.mask}(${value})`;
|
|
7498
|
-
break;
|
|
7390
|
+
if (isInsideString) {
|
|
7391
|
+
continue;
|
|
7499
7392
|
}
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7393
|
+
if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
|
|
7394
|
+
buffer += value.slice(offset, index);
|
|
7395
|
+
offset = index;
|
|
7396
|
+
isInsideComment = singleComment;
|
|
7397
|
+
index++;
|
|
7398
|
+
} else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
|
|
7399
|
+
index++;
|
|
7400
|
+
isInsideComment = false;
|
|
7401
|
+
buffer += strip(value, offset, index);
|
|
7402
|
+
offset = index;
|
|
7403
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
7404
|
+
isInsideComment = false;
|
|
7405
|
+
buffer += strip(value, offset, index);
|
|
7406
|
+
offset = index;
|
|
7407
|
+
} else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
|
|
7408
|
+
buffer += value.slice(offset, index);
|
|
7409
|
+
offset = index;
|
|
7410
|
+
isInsideComment = multiComment;
|
|
7411
|
+
index++;
|
|
7412
|
+
} else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
|
|
7413
|
+
index++;
|
|
7414
|
+
isInsideComment = false;
|
|
7415
|
+
buffer += strip(value, offset, index + 1);
|
|
7416
|
+
offset = index + 1;
|
|
7417
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
7418
|
+
if (commaIndex !== -1) {
|
|
7419
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
7420
|
+
buffer += value.slice(offset, index);
|
|
7421
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
7422
|
+
buffer = "";
|
|
7423
|
+
offset = index;
|
|
7424
|
+
commaIndex = -1;
|
|
7425
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
7426
|
+
buffer += value.slice(offset, index);
|
|
7427
|
+
offset = index;
|
|
7428
|
+
commaIndex = -1;
|
|
7429
|
+
}
|
|
7430
|
+
} else if (currentCharacter === ",") {
|
|
7431
|
+
result += buffer + value.slice(offset, index);
|
|
7432
|
+
buffer = "";
|
|
7433
|
+
offset = index;
|
|
7434
|
+
commaIndex = index;
|
|
7435
|
+
}
|
|
7507
7436
|
}
|
|
7508
7437
|
}
|
|
7509
|
-
return
|
|
7510
|
-
}
|
|
7511
|
-
__name(generateDefaultValue, "generateDefaultValue");
|
|
7512
|
-
function createConcreteListProperty(ctx, field) {
|
|
7513
|
-
const name = `_${c2t(field.name)}`;
|
|
7514
|
-
const type = getJsType(ctx, field.slot.type, true);
|
|
7515
|
-
return `static ${name}: ${type};`;
|
|
7438
|
+
return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
|
|
7516
7439
|
}
|
|
7517
|
-
__name(
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7440
|
+
__name(stripComments, "stripComments");
|
|
7441
|
+
|
|
7442
|
+
// ../json/src/utils/parse.ts
|
|
7443
|
+
var suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
7444
|
+
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
7445
|
+
var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
7446
|
+
function jsonParseTransform(key, value) {
|
|
7447
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
7448
|
+
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
7449
|
+
return;
|
|
7450
|
+
}
|
|
7451
|
+
return value;
|
|
7522
7452
|
}
|
|
7523
|
-
__name(
|
|
7524
|
-
function
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
}
|
|
7557
|
-
case Value.UINT32: {
|
|
7558
|
-
return String(value.uint32);
|
|
7559
|
-
}
|
|
7560
|
-
case Value.UINT64: {
|
|
7561
|
-
return createBigInt(value.uint64);
|
|
7562
|
-
}
|
|
7563
|
-
case Value.TEXT: {
|
|
7564
|
-
return JSON.stringify(value.text);
|
|
7565
|
-
}
|
|
7566
|
-
case Value.VOID: {
|
|
7567
|
-
return "undefined";
|
|
7568
|
-
}
|
|
7569
|
-
case Value.ANY_POINTER: {
|
|
7570
|
-
p = value.anyPointer;
|
|
7571
|
-
break;
|
|
7572
|
-
}
|
|
7573
|
-
case Value.DATA: {
|
|
7574
|
-
p = value.data;
|
|
7575
|
-
break;
|
|
7576
|
-
}
|
|
7577
|
-
case Value.LIST: {
|
|
7578
|
-
p = value.list;
|
|
7579
|
-
break;
|
|
7453
|
+
__name(jsonParseTransform, "jsonParseTransform");
|
|
7454
|
+
function parse(value, options = {}) {
|
|
7455
|
+
if (typeof value !== "string") {
|
|
7456
|
+
return value;
|
|
7457
|
+
}
|
|
7458
|
+
let stripped = stripComments(value);
|
|
7459
|
+
if (stripped[0] === '"' && stripped[stripped.length - 1] === '"' && !stripped.includes("\\")) {
|
|
7460
|
+
return stripped.slice(1, -1);
|
|
7461
|
+
}
|
|
7462
|
+
stripped = stripped.trim();
|
|
7463
|
+
if (stripped.length <= 9) {
|
|
7464
|
+
switch (stripped.toLowerCase()) {
|
|
7465
|
+
case "true": {
|
|
7466
|
+
return true;
|
|
7467
|
+
}
|
|
7468
|
+
case "false": {
|
|
7469
|
+
return false;
|
|
7470
|
+
}
|
|
7471
|
+
case "undefined": {
|
|
7472
|
+
return void 0;
|
|
7473
|
+
}
|
|
7474
|
+
case "null": {
|
|
7475
|
+
return null;
|
|
7476
|
+
}
|
|
7477
|
+
case "nan": {
|
|
7478
|
+
return Number.NaN;
|
|
7479
|
+
}
|
|
7480
|
+
case "infinity": {
|
|
7481
|
+
return Number.POSITIVE_INFINITY;
|
|
7482
|
+
}
|
|
7483
|
+
case "-infinity": {
|
|
7484
|
+
return Number.NEGATIVE_INFINITY;
|
|
7485
|
+
}
|
|
7580
7486
|
}
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7487
|
+
}
|
|
7488
|
+
if (!JsonSigRx.test(stripped)) {
|
|
7489
|
+
if (options.strict) {
|
|
7490
|
+
throw new Error("Invalid JSON");
|
|
7584
7491
|
}
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7492
|
+
return stripped;
|
|
7493
|
+
}
|
|
7494
|
+
try {
|
|
7495
|
+
if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
|
|
7496
|
+
if (options.strict) {
|
|
7497
|
+
throw new Error("Possible prototype pollution");
|
|
7498
|
+
}
|
|
7499
|
+
return JSON.parse(stripped, jsonParseTransform);
|
|
7589
7500
|
}
|
|
7590
|
-
|
|
7591
|
-
|
|
7501
|
+
return JSON.parse(stripped);
|
|
7502
|
+
} catch (error) {
|
|
7503
|
+
if (options.strict) {
|
|
7504
|
+
throw error;
|
|
7592
7505
|
}
|
|
7506
|
+
return value;
|
|
7593
7507
|
}
|
|
7594
|
-
const message = new Message();
|
|
7595
|
-
message.setRoot(p);
|
|
7596
|
-
const buf = new Uint8Array(message.toPackedArrayBuffer());
|
|
7597
|
-
const values = [];
|
|
7598
|
-
for (let i = 0; i < buf.byteLength; i++) {
|
|
7599
|
-
values.push(`0x${pad(buf[i].toString(16), 2)}`);
|
|
7600
|
-
}
|
|
7601
|
-
return `$.readRawPointer(new Uint8Array([${values.join(",")}]).buffer)`;
|
|
7602
7508
|
}
|
|
7603
|
-
__name(
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7509
|
+
__name(parse, "parse");
|
|
7510
|
+
|
|
7511
|
+
// ../json/src/utils/parse-error.ts
|
|
7512
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
7513
|
+
var import_lines_and_columns = require("lines-and-columns");
|
|
7514
|
+
|
|
7515
|
+
// ../json/src/utils/code-frames.ts
|
|
7516
|
+
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
7517
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
7518
|
+
const startLoc = {
|
|
7519
|
+
column: 0,
|
|
7520
|
+
line: -1,
|
|
7521
|
+
...loc.start
|
|
7522
|
+
};
|
|
7523
|
+
const endLoc = {
|
|
7524
|
+
...startLoc,
|
|
7525
|
+
...loc.end
|
|
7526
|
+
};
|
|
7527
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
7528
|
+
const startLine = startLoc.line;
|
|
7529
|
+
const startColumn = startLoc.column;
|
|
7530
|
+
const endLine = endLoc.line;
|
|
7531
|
+
const endColumn = endLoc.column;
|
|
7532
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
7533
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
7534
|
+
if (startLine === -1) {
|
|
7535
|
+
start = 0;
|
|
7536
|
+
}
|
|
7537
|
+
if (endLine === -1) {
|
|
7538
|
+
end = source.length;
|
|
7539
|
+
}
|
|
7540
|
+
const lineDiff = endLine - startLine;
|
|
7541
|
+
const markerLines = {};
|
|
7542
|
+
if (lineDiff) {
|
|
7543
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
7544
|
+
const lineNumber = i + startLine;
|
|
7545
|
+
if (!startColumn) {
|
|
7546
|
+
markerLines[lineNumber] = true;
|
|
7547
|
+
} else if (i === 0) {
|
|
7548
|
+
const sourceLength = source[lineNumber - 1]?.length ?? 0;
|
|
7549
|
+
markerLines[lineNumber] = [
|
|
7550
|
+
startColumn,
|
|
7551
|
+
sourceLength - startColumn + 1
|
|
7552
|
+
];
|
|
7553
|
+
} else if (i === lineDiff) {
|
|
7554
|
+
markerLines[lineNumber] = [
|
|
7555
|
+
0,
|
|
7556
|
+
endColumn
|
|
7557
|
+
];
|
|
7558
|
+
} else {
|
|
7559
|
+
const sourceLength = source[lineNumber - i]?.length ?? 0;
|
|
7560
|
+
markerLines[lineNumber] = [
|
|
7561
|
+
0,
|
|
7562
|
+
sourceLength
|
|
7563
|
+
];
|
|
7564
|
+
}
|
|
7565
|
+
}
|
|
7566
|
+
} else if (startColumn === endColumn) {
|
|
7567
|
+
markerLines[startLine] = startColumn ? [
|
|
7568
|
+
startColumn,
|
|
7569
|
+
0
|
|
7570
|
+
] : true;
|
|
7571
|
+
} else {
|
|
7572
|
+
markerLines[startLine] = [
|
|
7573
|
+
startColumn,
|
|
7574
|
+
endColumn - startColumn
|
|
7575
|
+
];
|
|
7576
|
+
}
|
|
7577
|
+
return {
|
|
7578
|
+
start,
|
|
7579
|
+
end,
|
|
7580
|
+
markerLines
|
|
7581
|
+
};
|
|
7608
7582
|
}
|
|
7609
|
-
__name(
|
|
7610
|
-
function
|
|
7611
|
-
const
|
|
7612
|
-
const
|
|
7613
|
-
const
|
|
7614
|
-
const
|
|
7615
|
-
const
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7583
|
+
__name(getMarkerLines, "getMarkerLines");
|
|
7584
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
7585
|
+
const lines = rawLines.split(NEWLINE);
|
|
7586
|
+
const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
|
|
7587
|
+
const numberMaxWidth = String(end).length;
|
|
7588
|
+
const highlightedLines = opts.highlight ? opts.highlight(rawLines) : rawLines;
|
|
7589
|
+
const frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
|
|
7590
|
+
const number = start + 1 + index;
|
|
7591
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
7592
|
+
const gutter = ` ${paddedNumber} | `;
|
|
7593
|
+
const hasMarker = Boolean(markerLines[number] ?? false);
|
|
7594
|
+
if (hasMarker) {
|
|
7595
|
+
let markerLine = "";
|
|
7596
|
+
if (Array.isArray(hasMarker)) {
|
|
7597
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
7598
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
7599
|
+
markerLine = [
|
|
7600
|
+
"\n ",
|
|
7601
|
+
gutter.replace(/\d/g, " "),
|
|
7602
|
+
markerSpacing,
|
|
7603
|
+
"^".repeat(numberOfMarkers)
|
|
7604
|
+
].join("");
|
|
7631
7605
|
}
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7606
|
+
return [
|
|
7607
|
+
">",
|
|
7608
|
+
gutter,
|
|
7609
|
+
line,
|
|
7610
|
+
markerLine
|
|
7611
|
+
].join("");
|
|
7612
|
+
}
|
|
7613
|
+
return ` ${gutter}${line}`;
|
|
7614
|
+
}).join("\n");
|
|
7615
|
+
return frame;
|
|
7642
7616
|
}
|
|
7643
|
-
__name(
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7617
|
+
__name(codeFrameColumns, "codeFrameColumns");
|
|
7618
|
+
|
|
7619
|
+
// ../json/src/utils/parse-error.ts
|
|
7620
|
+
function formatParseError(input, parseError) {
|
|
7621
|
+
const { error, offset, length } = parseError;
|
|
7622
|
+
const result = new import_lines_and_columns.LinesAndColumns(input).locationForIndex(offset);
|
|
7623
|
+
let line = result?.line ?? 0;
|
|
7624
|
+
let column = result?.column ?? 0;
|
|
7625
|
+
line++;
|
|
7626
|
+
column++;
|
|
7627
|
+
return `${(0, import_jsonc_parser.printParseErrorCode)(error)} in JSON at ${line}:${column}
|
|
7628
|
+
${codeFrameColumns(input, {
|
|
7629
|
+
start: {
|
|
7630
|
+
line,
|
|
7631
|
+
column
|
|
7632
|
+
},
|
|
7633
|
+
end: {
|
|
7634
|
+
line,
|
|
7635
|
+
column: column + length
|
|
7636
|
+
}
|
|
7637
|
+
})}
|
|
7638
|
+
`;
|
|
7639
|
+
}
|
|
7640
|
+
__name(formatParseError, "formatParseError");
|
|
7641
|
+
|
|
7642
|
+
// ../type-checks/src/is-number.ts
|
|
7643
|
+
var isNumber = /* @__PURE__ */ __name((value) => {
|
|
7644
|
+
try {
|
|
7645
|
+
return value instanceof Number || typeof value === "number" || Number(value) === value;
|
|
7646
|
+
} catch {
|
|
7647
|
+
return false;
|
|
7660
7648
|
}
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7649
|
+
}, "isNumber");
|
|
7650
|
+
|
|
7651
|
+
// ../type-checks/src/is-undefined.ts
|
|
7652
|
+
var isUndefined = /* @__PURE__ */ __name((value) => {
|
|
7653
|
+
return value === void 0;
|
|
7654
|
+
}, "isUndefined");
|
|
7655
|
+
|
|
7656
|
+
// ../json/src/utils/stringify.ts
|
|
7657
|
+
var invalidKeyChars = [
|
|
7658
|
+
"@",
|
|
7659
|
+
"/",
|
|
7660
|
+
"#",
|
|
7661
|
+
"$",
|
|
7662
|
+
" ",
|
|
7663
|
+
":",
|
|
7664
|
+
";",
|
|
7665
|
+
",",
|
|
7666
|
+
".",
|
|
7667
|
+
"!",
|
|
7668
|
+
"?",
|
|
7669
|
+
"&",
|
|
7670
|
+
"=",
|
|
7671
|
+
"+",
|
|
7672
|
+
"-",
|
|
7673
|
+
"*",
|
|
7674
|
+
"%",
|
|
7675
|
+
"^",
|
|
7676
|
+
"~",
|
|
7677
|
+
"|",
|
|
7678
|
+
"\\",
|
|
7679
|
+
'"',
|
|
7680
|
+
"'",
|
|
7681
|
+
"`",
|
|
7682
|
+
"{",
|
|
7683
|
+
"}",
|
|
7684
|
+
"[",
|
|
7685
|
+
"]",
|
|
7686
|
+
"(",
|
|
7687
|
+
")",
|
|
7688
|
+
"<",
|
|
7689
|
+
">"
|
|
7690
|
+
];
|
|
7691
|
+
var stringify = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
7692
|
+
const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
|
|
7693
|
+
switch (value) {
|
|
7694
|
+
case null: {
|
|
7695
|
+
return "null";
|
|
7666
7696
|
}
|
|
7667
|
-
case
|
|
7668
|
-
|
|
7697
|
+
case void 0: {
|
|
7698
|
+
return '"undefined"';
|
|
7669
7699
|
}
|
|
7670
|
-
case
|
|
7671
|
-
|
|
7672
|
-
ctx,
|
|
7673
|
-
getFullClassName(node),
|
|
7674
|
-
node,
|
|
7675
|
-
node.enum.enumerants.toArray()
|
|
7676
|
-
);
|
|
7677
|
-
break;
|
|
7700
|
+
case true: {
|
|
7701
|
+
return "true";
|
|
7678
7702
|
}
|
|
7679
|
-
case
|
|
7680
|
-
|
|
7681
|
-
break;
|
|
7703
|
+
case false: {
|
|
7704
|
+
return "false";
|
|
7682
7705
|
}
|
|
7683
|
-
case
|
|
7684
|
-
|
|
7706
|
+
case Number.POSITIVE_INFINITY: {
|
|
7707
|
+
return "infinity";
|
|
7685
7708
|
}
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
throw new Error(
|
|
7689
|
-
format(
|
|
7690
|
-
GEN_NODE_UNKNOWN_TYPE,
|
|
7691
|
-
nodeType
|
|
7692
|
-
/* s.Node_Which[whichNode] */
|
|
7693
|
-
)
|
|
7694
|
-
);
|
|
7709
|
+
case Number.NEGATIVE_INFINITY: {
|
|
7710
|
+
return "-infinity";
|
|
7695
7711
|
}
|
|
7696
7712
|
}
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
var CodeGeneratorContext = class {
|
|
7700
|
-
static {
|
|
7701
|
-
__name(this, "CodeGeneratorContext");
|
|
7713
|
+
if (Array.isArray(value)) {
|
|
7714
|
+
return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
|
|
7702
7715
|
}
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7716
|
+
if (value instanceof Uint8Array) {
|
|
7717
|
+
return value.toString();
|
|
7718
|
+
}
|
|
7719
|
+
switch (typeof value) {
|
|
7720
|
+
case "number": {
|
|
7721
|
+
return `${value}`;
|
|
7722
|
+
}
|
|
7723
|
+
case "string": {
|
|
7724
|
+
return JSON.stringify(value);
|
|
7725
|
+
}
|
|
7726
|
+
case "object": {
|
|
7727
|
+
const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
|
|
7728
|
+
return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
|
|
7729
|
+
}
|
|
7730
|
+
default:
|
|
7731
|
+
return "null";
|
|
7732
|
+
}
|
|
7733
|
+
}, "stringify");
|
|
7734
|
+
|
|
7735
|
+
// ../json/src/storm-json.ts
|
|
7736
|
+
var StormJSON = class _StormJSON extends import_superjson.default {
|
|
7706
7737
|
static {
|
|
7707
|
-
__name(this, "
|
|
7738
|
+
__name(this, "StormJSON");
|
|
7708
7739
|
}
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7740
|
+
static #instance;
|
|
7741
|
+
static get instance() {
|
|
7742
|
+
if (!_StormJSON.#instance) {
|
|
7743
|
+
_StormJSON.#instance = new _StormJSON();
|
|
7744
|
+
}
|
|
7745
|
+
return _StormJSON.#instance;
|
|
7714
7746
|
}
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
generatedNodeIds = /* @__PURE__ */ new Set();
|
|
7721
|
-
generatedResultsPromiseIds = /* @__PURE__ */ new Set();
|
|
7722
|
-
tsPath = "";
|
|
7723
|
-
codeParts = [];
|
|
7724
|
-
toString() {
|
|
7725
|
-
return this.file?.filename ?? "CodeGeneratorFileContext()";
|
|
7747
|
+
/**
|
|
7748
|
+
* Deserialize the given value with superjson using the given metadata
|
|
7749
|
+
*/
|
|
7750
|
+
static deserialize(payload) {
|
|
7751
|
+
return _StormJSON.instance.deserialize(payload);
|
|
7726
7752
|
}
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
}
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
let importPath;
|
|
7756
|
-
if (name.startsWith("/capnp/")) {
|
|
7757
|
-
importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
|
|
7758
|
-
} else {
|
|
7759
|
-
importPath = name.replace(/\.capnp$/, "");
|
|
7760
|
-
if (importPath[0] !== ".") {
|
|
7761
|
-
importPath = `./${importPath}`;
|
|
7762
|
-
}
|
|
7753
|
+
/**
|
|
7754
|
+
* Serialize the given value with superjson
|
|
7755
|
+
*/
|
|
7756
|
+
static serialize(object) {
|
|
7757
|
+
return _StormJSON.instance.serialize(object);
|
|
7758
|
+
}
|
|
7759
|
+
/**
|
|
7760
|
+
* Parse the given string value with superjson using the given metadata
|
|
7761
|
+
*
|
|
7762
|
+
* @param value - The string value to parse
|
|
7763
|
+
* @returns The parsed data
|
|
7764
|
+
*/
|
|
7765
|
+
static parse(value) {
|
|
7766
|
+
return parse(value);
|
|
7767
|
+
}
|
|
7768
|
+
/**
|
|
7769
|
+
* Serializes the given data to a JSON string.
|
|
7770
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
7771
|
+
*
|
|
7772
|
+
* @param value - Object which should be serialized to JSON
|
|
7773
|
+
* @param _options - JSON serialize options
|
|
7774
|
+
* @returns the formatted JSON representation of the object
|
|
7775
|
+
*/
|
|
7776
|
+
static stringify(value, _options) {
|
|
7777
|
+
const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
7778
|
+
let result = value;
|
|
7779
|
+
if (customTransformer && customTransformer.isApplicable(value)) {
|
|
7780
|
+
result = customTransformer.serialize(result);
|
|
7763
7781
|
}
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7782
|
+
return stringify(result);
|
|
7783
|
+
}
|
|
7784
|
+
/**
|
|
7785
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
7786
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
7787
|
+
*
|
|
7788
|
+
* @param strData - JSON content as string
|
|
7789
|
+
* @param options - JSON parse options
|
|
7790
|
+
* @returns Object the JSON content represents
|
|
7791
|
+
*/
|
|
7792
|
+
static parseJson(strData, options) {
|
|
7793
|
+
try {
|
|
7794
|
+
if (options?.expectComments === false) {
|
|
7795
|
+
return _StormJSON.instance.parse(strData);
|
|
7769
7796
|
}
|
|
7770
|
-
|
|
7771
|
-
}).sort().join(", ");
|
|
7772
|
-
if (imports.length === 0) {
|
|
7773
|
-
continue;
|
|
7797
|
+
} catch {
|
|
7774
7798
|
}
|
|
7775
|
-
|
|
7799
|
+
const errors = [];
|
|
7800
|
+
const opts = {
|
|
7801
|
+
allowTrailingComma: true,
|
|
7802
|
+
...options
|
|
7803
|
+
};
|
|
7804
|
+
const result = (0, import_jsonc_parser2.parse)(strData, errors, opts);
|
|
7805
|
+
if (errors.length > 0 && errors[0]) {
|
|
7806
|
+
throw new Error(formatParseError(strData, errors[0]));
|
|
7807
|
+
}
|
|
7808
|
+
return result;
|
|
7809
|
+
}
|
|
7810
|
+
/**
|
|
7811
|
+
* Register a custom schema with superjson
|
|
7812
|
+
*
|
|
7813
|
+
* @param name - The name of the schema
|
|
7814
|
+
* @param serialize - The function to serialize the schema
|
|
7815
|
+
* @param deserialize - The function to deserialize the schema
|
|
7816
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
7817
|
+
*/
|
|
7818
|
+
static register(name, serialize, deserialize, isApplicable) {
|
|
7819
|
+
_StormJSON.instance.registerCustom({
|
|
7820
|
+
isApplicable,
|
|
7821
|
+
serialize,
|
|
7822
|
+
deserialize
|
|
7823
|
+
}, name);
|
|
7824
|
+
}
|
|
7825
|
+
/**
|
|
7826
|
+
* Register a class with superjson
|
|
7827
|
+
*
|
|
7828
|
+
* @param classConstructor - The class constructor to register
|
|
7829
|
+
*/
|
|
7830
|
+
static registerClass(classConstructor, options) {
|
|
7831
|
+
_StormJSON.instance.registerClass(classConstructor, {
|
|
7832
|
+
identifier: isString(options) ? options : options?.identifier || classConstructor.name,
|
|
7833
|
+
allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : [
|
|
7834
|
+
"__typename"
|
|
7835
|
+
]
|
|
7836
|
+
});
|
|
7776
7837
|
}
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
const nestedNodes = node.nestedNodes.filter(({ id }) => hasNode(ctx, id));
|
|
7782
|
-
const newNestedNodes = nestedNodes.filter(({ id }) => !visitedIds.has(id));
|
|
7783
|
-
const nodes = newNestedNodes.map(({ id }) => lookupNode(ctx, id)).filter((node2) => node2._isStruct || node2._isEnum || node2._isInterface);
|
|
7784
|
-
return nodes.concat(
|
|
7785
|
-
nodes.flatMap((node2) => getImportNodes(ctx, node2, visitedIds))
|
|
7786
|
-
);
|
|
7787
|
-
}
|
|
7788
|
-
__name(getImportNodes, "getImportNodes");
|
|
7789
|
-
async function compileAll(codeGenRequest, opts) {
|
|
7790
|
-
const req = new Message(codeGenRequest, false).getRoot(
|
|
7791
|
-
CodeGeneratorRequest
|
|
7792
|
-
);
|
|
7793
|
-
const ctx = new CodeGeneratorContext();
|
|
7794
|
-
ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
|
|
7795
|
-
if (ctx.files.length === 0) {
|
|
7796
|
-
throw new Error(GEN_NO_FILES);
|
|
7838
|
+
constructor() {
|
|
7839
|
+
super({
|
|
7840
|
+
dedupe: true
|
|
7841
|
+
});
|
|
7797
7842
|
}
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
)
|
|
7801
|
-
|
|
7802
|
-
|
|
7843
|
+
};
|
|
7844
|
+
StormJSON.instance.registerCustom({
|
|
7845
|
+
isApplicable: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.isBuffer(v), "isApplicable"),
|
|
7846
|
+
serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
|
|
7847
|
+
deserialize: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.from(v, "base64"), "deserialize")
|
|
7848
|
+
}, "Bytes");
|
|
7849
|
+
|
|
7850
|
+
// ../type-checks/src/is-error.ts
|
|
7851
|
+
var isError = /* @__PURE__ */ __name((obj) => {
|
|
7852
|
+
if (!isObject(obj)) {
|
|
7853
|
+
return false;
|
|
7803
7854
|
}
|
|
7804
|
-
|
|
7805
|
-
|
|
7855
|
+
const tag = getObjectTag(obj);
|
|
7856
|
+
return tag === "[object Error]" || tag === "[object DOMException]" || typeof obj?.message === "string" && typeof obj?.name === "string" && !isPlainObject(obj);
|
|
7857
|
+
}, "isError");
|
|
7858
|
+
|
|
7859
|
+
// ../fs/src/read-file.ts
|
|
7860
|
+
var import_node_fs4 = require("fs");
|
|
7861
|
+
var import_promises3 = require("fs/promises");
|
|
7862
|
+
var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
|
|
7863
|
+
try {
|
|
7864
|
+
if (!filePath) {
|
|
7865
|
+
throw new Error("No file path provided to read data");
|
|
7866
|
+
}
|
|
7867
|
+
return await (0, import_promises3.readFile)(filePath, {
|
|
7868
|
+
encoding: "utf8"
|
|
7869
|
+
});
|
|
7870
|
+
} catch {
|
|
7871
|
+
throw new Error("An error occurred writing data to file");
|
|
7806
7872
|
}
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7873
|
+
}, "readFile");
|
|
7874
|
+
|
|
7875
|
+
// ../fs/src/write-file.ts
|
|
7876
|
+
var import_node_fs5 = require("fs");
|
|
7877
|
+
var import_promises4 = require("fs/promises");
|
|
7878
|
+
|
|
7879
|
+
// ../fs/src/json.ts
|
|
7880
|
+
async function readJsonFile(path, options) {
|
|
7881
|
+
const content = await readFile2(path);
|
|
7882
|
+
if (options) {
|
|
7883
|
+
options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
|
|
7884
|
+
}
|
|
7885
|
+
try {
|
|
7886
|
+
return StormJSON.parseJson(content, options);
|
|
7887
|
+
} catch (error) {
|
|
7888
|
+
if (isError(error)) {
|
|
7889
|
+
error.message = error.message.replace("JSON", path);
|
|
7890
|
+
throw error;
|
|
7812
7891
|
}
|
|
7892
|
+
throw new Error(`Failed to parse JSON: ${path}`);
|
|
7813
7893
|
}
|
|
7814
|
-
return {
|
|
7815
|
-
ctx,
|
|
7816
|
-
files
|
|
7817
|
-
};
|
|
7818
7894
|
}
|
|
7819
|
-
__name(
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7895
|
+
__name(readJsonFile, "readJsonFile");
|
|
7896
|
+
|
|
7897
|
+
// ../fs/src/list-files.ts
|
|
7898
|
+
var import_defu = __toESM(require("defu"), 1);
|
|
7899
|
+
var import_glob = require("glob");
|
|
7900
|
+
var DEFAULT_OPTIONS = {
|
|
7901
|
+
dot: true
|
|
7902
|
+
};
|
|
7903
|
+
async function list(filesGlob, options) {
|
|
7904
|
+
return (0, import_glob.glob)(filesGlob, (0, import_defu.default)(options ?? {}, DEFAULT_OPTIONS));
|
|
7905
|
+
}
|
|
7906
|
+
__name(list, "list");
|
|
7907
|
+
async function listFiles(filesGlob, options) {
|
|
7908
|
+
const result = (await list(filesGlob, (0, import_defu.default)({
|
|
7909
|
+
withFileTypes: true
|
|
7910
|
+
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
7911
|
+
if (!options?.withFileTypes) {
|
|
7912
|
+
return result.map((file) => file.fullpath());
|
|
7832
7913
|
}
|
|
7833
|
-
|
|
7834
|
-
ctx.tsPath,
|
|
7835
|
-
ctx.codeParts.map((p) => p.toString()).join(""),
|
|
7836
|
-
import_typescript.default.ScriptTarget.Latest,
|
|
7837
|
-
false,
|
|
7838
|
-
import_typescript.default.ScriptKind.TS
|
|
7839
|
-
);
|
|
7840
|
-
return SOURCE_COMMENT + import_typescript.default.createPrinter().printFile(sourceFile);
|
|
7914
|
+
return result;
|
|
7841
7915
|
}
|
|
7842
|
-
__name(
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7916
|
+
__name(listFiles, "listFiles");
|
|
7917
|
+
|
|
7918
|
+
// src/helpers.ts
|
|
7919
|
+
var import_typescript3 = require("typescript");
|
|
7920
|
+
async function resolveOptions(options) {
|
|
7921
|
+
const tsconfigPath = options.tsconfig?.replace("{projectRoot}", options.projectRoot)?.replace("{workspaceRoot}", options.workspaceRoot);
|
|
7922
|
+
const schema = options.schema ? options.schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : options.projectRoot;
|
|
7923
|
+
if (!existsSync(tsconfigPath)) {
|
|
7924
|
+
const errorMessage = options.tsconfig ? `\u2716 The specified TypeScript configuration file "${tsconfigPath}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.";
|
|
7925
|
+
(0, import_console.writeFatal)(errorMessage, {
|
|
7926
|
+
logLevel: "all"
|
|
7927
|
+
});
|
|
7928
|
+
throw new Error(errorMessage);
|
|
7846
7929
|
}
|
|
7847
|
-
const
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
const compilerHost = import_typescript.default.createCompilerHost(compileOptions);
|
|
7865
|
-
compilerHost.writeFile = (fileName, declaration) => {
|
|
7866
|
-
files.set(fileName, declaration);
|
|
7867
|
-
};
|
|
7868
|
-
const _readFile = compilerHost.readFile;
|
|
7869
|
-
compilerHost.readFile = (filename) => {
|
|
7870
|
-
if (files.has(filename)) {
|
|
7871
|
-
return files.get(filename);
|
|
7872
|
-
}
|
|
7873
|
-
return _readFile(filename);
|
|
7874
|
-
};
|
|
7875
|
-
const program = import_typescript.default.createProgram(
|
|
7876
|
-
[...files.keys()],
|
|
7877
|
-
compileOptions,
|
|
7878
|
-
compilerHost
|
|
7879
|
-
);
|
|
7880
|
-
const emitResult = program.emit();
|
|
7881
|
-
const allDiagnostics = [
|
|
7882
|
-
...import_typescript.default.getPreEmitDiagnostics(program),
|
|
7883
|
-
...emitResult.diagnostics
|
|
7884
|
-
];
|
|
7885
|
-
if (allDiagnostics.length > 0) {
|
|
7886
|
-
for (const diagnostic of allDiagnostics) {
|
|
7887
|
-
const message = import_typescript.default.flattenDiagnosticMessageText(
|
|
7888
|
-
diagnostic.messageText,
|
|
7889
|
-
"\n"
|
|
7890
|
-
);
|
|
7891
|
-
if (diagnostic.file && diagnostic.start) {
|
|
7892
|
-
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
7893
|
-
console.log(
|
|
7894
|
-
`${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`
|
|
7895
|
-
);
|
|
7896
|
-
} else {
|
|
7897
|
-
console.log(`==> ${message}`);
|
|
7898
|
-
}
|
|
7899
|
-
}
|
|
7900
|
-
throw new Error(GEN_TS_EMIT_FAILED);
|
|
7930
|
+
const resolvedTsconfig = await readJsonFile(tsconfigPath);
|
|
7931
|
+
const tsconfig = (0, import_typescript3.parseJsonConfigFileContent)(resolvedTsconfig, import_typescript3.sys, findFilePath(tsconfigPath));
|
|
7932
|
+
tsconfig.options.configFilePath = tsconfigPath;
|
|
7933
|
+
tsconfig.options.noImplicitOverride = false;
|
|
7934
|
+
tsconfig.options.noUnusedLocals = false;
|
|
7935
|
+
tsconfig.options.noUnusedParameters = false;
|
|
7936
|
+
tsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(findFilePath(tsconfigPath), joinPaths(options.workspaceRoot, schema.endsWith(".capnp") ? findFilePath(schema) : schema)));
|
|
7937
|
+
const schemas = [];
|
|
7938
|
+
if (!schema || !schema.includes("*") && !existsSync(schema)) {
|
|
7939
|
+
throw new Error(`\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`);
|
|
7940
|
+
}
|
|
7941
|
+
schemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
|
|
7942
|
+
if (schemas.length === 0) {
|
|
7943
|
+
(0, import_console.writeWarning)(`\u2716 No Cap'n Proto schema files found in the specified source paths: ${schemas.join(", ")}. As a result, the Cap'n Proto compiler will not be able to generate any output files. Please ensure that the paths are correct and contain .capnp files.`, {
|
|
7944
|
+
logLevel: "all"
|
|
7945
|
+
});
|
|
7946
|
+
return null;
|
|
7901
7947
|
}
|
|
7948
|
+
return {
|
|
7949
|
+
workspaceRoot: options.workspaceRoot,
|
|
7950
|
+
projectRoot: options.projectRoot,
|
|
7951
|
+
schemas,
|
|
7952
|
+
js: options.js ?? false,
|
|
7953
|
+
ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
|
|
7954
|
+
dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true),
|
|
7955
|
+
tsconfig: tsconfig?.options
|
|
7956
|
+
};
|
|
7902
7957
|
}
|
|
7903
|
-
__name(
|
|
7904
|
-
|
|
7905
|
-
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/compiler/index.mjs
|
|
7906
|
-
var import_typescript2 = require("typescript");
|
|
7958
|
+
__name(resolveOptions, "resolveOptions");
|
|
7907
7959
|
|
|
7908
7960
|
// src/compile.ts
|
|
7909
|
-
var import_node_buffer2 = require("buffer");
|
|
7910
|
-
var import_node_child_process = require("child_process");
|
|
7911
7961
|
async function capnpc(options) {
|
|
7912
7962
|
const { output, tsconfig, schemas = [], tty } = options;
|
|
7913
7963
|
let dataBuf = import_node_buffer2.Buffer.alloc(0);
|
|
@@ -7952,14 +8002,14 @@ async function capnpc(options) {
|
|
|
7952
8002
|
ts: options.ts ?? true,
|
|
7953
8003
|
js: false,
|
|
7954
8004
|
dts: false,
|
|
7955
|
-
tsconfig
|
|
8005
|
+
tsconfig
|
|
7956
8006
|
});
|
|
7957
8007
|
}
|
|
7958
8008
|
__name(capnpc, "capnpc");
|
|
7959
8009
|
|
|
7960
8010
|
// bin/capnpc.ts
|
|
7961
8011
|
function createProgram() {
|
|
7962
|
-
(0,
|
|
8012
|
+
(0, import_console3.writeInfo)("\u26A1 Running Storm Cap'n Proto Compiler Tools", {
|
|
7963
8013
|
logLevel: "all"
|
|
7964
8014
|
});
|
|
7965
8015
|
const root = (0, import_utilities.findWorkspaceRootSafe)(process.cwd());
|
|
@@ -7998,54 +8048,24 @@ function createProgram() {
|
|
|
7998
8048
|
}
|
|
7999
8049
|
__name(createProgram, "createProgram");
|
|
8000
8050
|
async function compileAction(options) {
|
|
8001
|
-
const
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
const errorMessage = options.tsconfig ? `\u2716 The specified TypeScript configuration file "${tsconfigPath}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.";
|
|
8005
|
-
(0, import_console.writeFatal)(errorMessage, {
|
|
8006
|
-
logLevel: "all"
|
|
8007
|
-
});
|
|
8008
|
-
throw new Error(errorMessage);
|
|
8009
|
-
}
|
|
8010
|
-
const resolvedTsconfig = await readJsonFile(tsconfigPath);
|
|
8011
|
-
const tsconfig = import_typescript3.default.parseJsonConfigFileContent(resolvedTsconfig, import_typescript3.default.sys, findFilePath(tsconfigPath));
|
|
8012
|
-
tsconfig.options.configFilePath = tsconfigPath;
|
|
8013
|
-
tsconfig.options.noImplicitOverride = false;
|
|
8014
|
-
tsconfig.options.noUnusedLocals = false;
|
|
8015
|
-
tsconfig.options.noUnusedParameters = false;
|
|
8016
|
-
tsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(findFilePath(tsconfigPath), joinPaths(options.workspaceRoot, schema.endsWith(".capnp") ? findFilePath(schema) : schema)));
|
|
8017
|
-
(0, import_console.writeInfo)(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${schema} to ${tsconfig.options.outDir}...`, {
|
|
8018
|
-
logLevel: "all"
|
|
8019
|
-
});
|
|
8020
|
-
const schemas = [];
|
|
8021
|
-
if (!schema || !schema.includes("*") && !existsSync(schema)) {
|
|
8022
|
-
const errorMessage = `\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`;
|
|
8023
|
-
(0, import_console.writeFatal)(errorMessage, {
|
|
8024
|
-
logLevel: "all"
|
|
8025
|
-
});
|
|
8026
|
-
throw new Error(errorMessage);
|
|
8027
|
-
}
|
|
8028
|
-
schemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
|
|
8029
|
-
if (schemas.length === 0) {
|
|
8030
|
-
(0, import_console.writeFatal)(`\u2716 No Cap'n Proto schema files found in the specified source paths: ${schemas.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
|
|
8051
|
+
const resolvedOptions = await resolveOptions(options);
|
|
8052
|
+
if (!resolvedOptions) {
|
|
8053
|
+
(0, import_console3.writeWarning)("\u2716 Unable to resolve Cap'n Proto compiler options - the program will terminate", {
|
|
8031
8054
|
logLevel: "all"
|
|
8032
8055
|
});
|
|
8033
8056
|
return;
|
|
8034
8057
|
}
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
tsconfig,
|
|
8038
|
-
schemas,
|
|
8039
|
-
ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
|
|
8040
|
-
dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true)
|
|
8058
|
+
(0, import_console3.writeInfo)(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${resolvedOptions.ts ? "TypeScript code" : ""}${resolvedOptions.js ? resolvedOptions.ts ? ", JavaScript code" : "JavaScript code" : ""}${resolvedOptions.dts ? resolvedOptions.ts || resolvedOptions.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${options.schema ? options.schema.replace("{projectRoot}", resolvedOptions.projectRoot).replace("{workspaceRoot}", resolvedOptions.workspaceRoot) : resolvedOptions.projectRoot} to ${resolvedOptions.tsconfig.outDir}...`, {
|
|
8059
|
+
logLevel: "all"
|
|
8041
8060
|
});
|
|
8061
|
+
const result = await capnpc(resolvedOptions);
|
|
8042
8062
|
if (result.files.size === 0) {
|
|
8043
|
-
(0,
|
|
8063
|
+
(0, import_console3.writeWarning)("\u26A0\uFE0F No files were generated. Please check your schema files.", {
|
|
8044
8064
|
logLevel: "all"
|
|
8045
8065
|
});
|
|
8046
8066
|
return;
|
|
8047
8067
|
}
|
|
8048
|
-
(0,
|
|
8068
|
+
(0, import_console3.writeInfo)(`Writing ${result.files.size} generated files to disk...`, {
|
|
8049
8069
|
logLevel: "all"
|
|
8050
8070
|
});
|
|
8051
8071
|
for (const [fileName, content] of result.files) {
|
|
@@ -8068,7 +8088,7 @@ async function compileAction(options) {
|
|
|
8068
8088
|
content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
|
|
8069
8089
|
);
|
|
8070
8090
|
}
|
|
8071
|
-
(0,
|
|
8091
|
+
(0, import_console3.writeSuccess)("\u26A1 Storm Cap'n Proto Compiler completed successfully.", {
|
|
8072
8092
|
logLevel: "all"
|
|
8073
8093
|
});
|
|
8074
8094
|
}
|
|
@@ -8080,7 +8100,7 @@ void (async () => {
|
|
|
8080
8100
|
await program.parseAsync(process.argv);
|
|
8081
8101
|
(0, import_utilities.exitWithSuccess)();
|
|
8082
8102
|
} catch (error) {
|
|
8083
|
-
(0,
|
|
8103
|
+
(0, import_console3.writeFatal)(`\u2716 A fatal error occurred while running the Storm Cap'n Proto compiler tool:
|
|
8084
8104
|
${error?.message ? error?.name ? `[${error.name}]: ${error.message}` : error.message : JSON.stringify(error)}${error?.stack ? `
|
|
8085
8105
|
|
|
8086
8106
|
Stack Trace: ${error.stack}` : ""}`, {
|