@stryke/capnp 0.9.13 → 0.10.1
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 +1849 -1797
- package/bin/capnpc.js +1848 -1796
- package/dist/compile.cjs +78 -0
- package/dist/compile.d.cts +38 -0
- package/dist/compile.d.ts +38 -0
- package/dist/compile.js +78 -0
- package/dist/helpers.cjs +70 -0
- package/dist/helpers.d.cts +13 -0
- package/dist/helpers.d.ts +13 -0
- package/dist/helpers.js +70 -0
- package/dist/index.cjs +4 -129
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- 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 +11 -2
- package/dist/types.d.ts +11 -2
- package/dist/types.js +8 -3
- package/dts/index.d.cts +658 -489
- package/dts/index.d.ts +658 -489
- package/package.json +21 -5
- package/schemas/{chunk-3Y2DQ67Z.cjs → chunk-BM2HWFSD.cjs} +597 -1
- package/schemas/{chunk-SCCB7KM2.js → chunk-TAKPBFYZ.js} +596 -0
- 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,1560 +61,944 @@ 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");
|
|
255
|
+
// src/compile.ts
|
|
256
|
+
var import_console2 = require("@storm-software/config-tools/logger/console");
|
|
502
257
|
|
|
503
|
-
//
|
|
504
|
-
var
|
|
505
|
-
|
|
506
|
-
|
|
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
|
|
259
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
260
|
+
|
|
261
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs
|
|
262
|
+
var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
|
|
263
|
+
ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
|
|
264
|
+
ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
|
|
265
|
+
ListElementSize2[ListElementSize2["BYTE"] = 2] = "BYTE";
|
|
266
|
+
ListElementSize2[ListElementSize2["BYTE_2"] = 3] = "BYTE_2";
|
|
267
|
+
ListElementSize2[ListElementSize2["BYTE_4"] = 4] = "BYTE_4";
|
|
268
|
+
ListElementSize2[ListElementSize2["BYTE_8"] = 5] = "BYTE_8";
|
|
269
|
+
ListElementSize2[ListElementSize2["POINTER"] = 6] = "POINTER";
|
|
270
|
+
ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
|
|
271
|
+
return ListElementSize2;
|
|
272
|
+
})(ListElementSize || {});
|
|
273
|
+
var tmpWord = new DataView(new ArrayBuffer(8));
|
|
274
|
+
new Uint16Array(tmpWord.buffer)[0] = 258;
|
|
275
|
+
var DEFAULT_BUFFER_SIZE = 4096;
|
|
276
|
+
var DEFAULT_TRAVERSE_LIMIT = 64 << 20;
|
|
277
|
+
var LIST_SIZE_MASK = 7;
|
|
278
|
+
var MAX_BUFFER_DUMP_BYTES = 8192;
|
|
279
|
+
var MAX_INT32 = 2147483647;
|
|
280
|
+
var MAX_UINT32 = 4294967295;
|
|
281
|
+
var MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
|
282
|
+
var NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
|
|
283
|
+
var PACK_SPAN_THRESHOLD = 2;
|
|
284
|
+
var POINTER_DOUBLE_FAR_MASK = 4;
|
|
285
|
+
var POINTER_TYPE_MASK = 3;
|
|
286
|
+
var MAX_DEPTH = MAX_INT32;
|
|
287
|
+
var MAX_SEGMENT_LENGTH = MAX_UINT32;
|
|
288
|
+
var INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
|
289
|
+
function assertNever(n) {
|
|
290
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
|
291
|
+
}
|
|
292
|
+
__name(assertNever, "assertNever");
|
|
293
|
+
var MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
|
294
|
+
var MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
|
295
|
+
var MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
|
296
|
+
var MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
|
297
|
+
var PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
|
298
|
+
var PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
|
299
|
+
var PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
|
300
|
+
var PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
|
301
|
+
var PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
|
302
|
+
var PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
|
303
|
+
var PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
|
304
|
+
var PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
|
305
|
+
var PTR_INVALID_UNION_ACCESS = "CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
|
|
306
|
+
var PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
|
307
|
+
var PTR_STRUCT_DATA_OUT_OF_BOUNDS = "CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
|
|
308
|
+
var PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
|
309
|
+
var PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
|
310
|
+
var PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
|
311
|
+
var PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
|
312
|
+
var SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
|
313
|
+
var SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
|
314
|
+
var SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
|
315
|
+
var SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
|
316
|
+
var SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
|
317
|
+
var TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
|
318
|
+
var LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
|
|
319
|
+
var LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
|
|
320
|
+
function bufferToHex(buffer) {
|
|
321
|
+
const a = new Uint8Array(buffer);
|
|
322
|
+
const h = [];
|
|
323
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
324
|
+
h.push(pad(a[i].toString(16), 2));
|
|
507
325
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
326
|
+
return `[${h.join(" ")}]`;
|
|
327
|
+
}
|
|
328
|
+
__name(bufferToHex, "bufferToHex");
|
|
329
|
+
function dumpBuffer(buffer) {
|
|
330
|
+
const b = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
331
|
+
const byteLength = Math.min(b.byteLength, MAX_BUFFER_DUMP_BYTES);
|
|
332
|
+
let r = format("\n=== buffer[%d] ===", byteLength);
|
|
333
|
+
for (let j = 0; j < byteLength; j += 16) {
|
|
334
|
+
r += `
|
|
335
|
+
${pad(j.toString(16), 8)}: `;
|
|
336
|
+
let s = "";
|
|
337
|
+
let k;
|
|
338
|
+
for (k = 0; k < 16 && j + k < b.byteLength; k++) {
|
|
339
|
+
const v = b[j + k];
|
|
340
|
+
r += `${pad(v.toString(16), 2)} `;
|
|
341
|
+
s += v > 31 && v < 255 ? String.fromCharCode(v) : "\xB7";
|
|
342
|
+
if (k === 7) {
|
|
343
|
+
r += " ";
|
|
344
|
+
}
|
|
512
345
|
}
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Deserialize the given value with superjson using the given metadata
|
|
517
|
-
*/
|
|
518
|
-
static deserialize(payload) {
|
|
519
|
-
return _StormJSON.instance.deserialize(payload);
|
|
346
|
+
r += `${" ".repeat((17 - k) * 3)}${s}`;
|
|
520
347
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
static serialize(object) {
|
|
525
|
-
return _StormJSON.instance.serialize(object);
|
|
348
|
+
r += "\n";
|
|
349
|
+
if (byteLength !== b.byteLength) {
|
|
350
|
+
r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
|
|
526
351
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
352
|
+
return r;
|
|
353
|
+
}
|
|
354
|
+
__name(dumpBuffer, "dumpBuffer");
|
|
355
|
+
function format(s, ...args) {
|
|
356
|
+
const n = s.length;
|
|
357
|
+
let arg;
|
|
358
|
+
let argIndex = 0;
|
|
359
|
+
let c;
|
|
360
|
+
let escaped = false;
|
|
361
|
+
let i = 0;
|
|
362
|
+
let leadingZero = false;
|
|
363
|
+
let precision;
|
|
364
|
+
let result = "";
|
|
365
|
+
function nextArg() {
|
|
366
|
+
return args[argIndex++];
|
|
535
367
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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);
|
|
368
|
+
__name(nextArg, "nextArg");
|
|
369
|
+
function slurpNumber() {
|
|
370
|
+
let digits = "";
|
|
371
|
+
while (/\d/.test(s[i])) {
|
|
372
|
+
digits += s[i++];
|
|
373
|
+
c = s[i];
|
|
549
374
|
}
|
|
550
|
-
return
|
|
375
|
+
return digits.length > 0 ? Number.parseInt(digits, 10) : null;
|
|
551
376
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
377
|
+
__name(slurpNumber, "slurpNumber");
|
|
378
|
+
for (; i < n; ++i) {
|
|
379
|
+
c = s[i];
|
|
380
|
+
if (escaped) {
|
|
381
|
+
escaped = false;
|
|
382
|
+
if (c === ".") {
|
|
383
|
+
leadingZero = false;
|
|
384
|
+
c = s[++i];
|
|
385
|
+
} else if (c === "0" && s[i + 1] === ".") {
|
|
386
|
+
leadingZero = true;
|
|
387
|
+
i += 2;
|
|
388
|
+
c = s[i];
|
|
389
|
+
} else {
|
|
390
|
+
leadingZero = true;
|
|
564
391
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
392
|
+
precision = slurpNumber();
|
|
393
|
+
switch (c) {
|
|
394
|
+
case "a": {
|
|
395
|
+
result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
case "b": {
|
|
399
|
+
result += Number.parseInt(String(nextArg()), 10).toString(2);
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
case "c": {
|
|
403
|
+
arg = nextArg();
|
|
404
|
+
result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
case "d": {
|
|
408
|
+
result += Number.parseInt(String(nextArg()), 10);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
case "f": {
|
|
412
|
+
const tmp = Number.parseFloat(String(nextArg())).toFixed(
|
|
413
|
+
precision || 6
|
|
414
|
+
);
|
|
415
|
+
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case "j": {
|
|
419
|
+
result += JSON.stringify(nextArg());
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case "o": {
|
|
423
|
+
result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
case "s": {
|
|
427
|
+
result += nextArg();
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case "x": {
|
|
431
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
case "X": {
|
|
435
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
default: {
|
|
439
|
+
result += c;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
} else if (c === "%") {
|
|
444
|
+
escaped = true;
|
|
445
|
+
} else {
|
|
446
|
+
result += c;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
__name(format, "format");
|
|
452
|
+
function pad(v, width, pad2 = "0") {
|
|
453
|
+
return v.length >= width ? v : Array.from({ length: width - v.length + 1 }).join(pad2) + v;
|
|
454
|
+
}
|
|
455
|
+
__name(pad, "pad");
|
|
456
|
+
function padToWord$1(size) {
|
|
457
|
+
return size + 7 & -8;
|
|
458
|
+
}
|
|
459
|
+
__name(padToWord$1, "padToWord$1");
|
|
460
|
+
var ObjectSize = class {
|
|
461
|
+
static {
|
|
462
|
+
__name(this, "ObjectSize");
|
|
592
463
|
}
|
|
593
464
|
/**
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
"__typename"
|
|
603
|
-
]
|
|
604
|
-
});
|
|
465
|
+
* Creates a new ObjectSize instance.
|
|
466
|
+
*
|
|
467
|
+
* @param dataByteLength - The number of bytes in the data section of the struct
|
|
468
|
+
* @param pointerLength - The number of pointers in the pointer section of the struct
|
|
469
|
+
*/
|
|
470
|
+
constructor(dataByteLength, pointerLength) {
|
|
471
|
+
this.dataByteLength = dataByteLength;
|
|
472
|
+
this.pointerLength = pointerLength;
|
|
605
473
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
474
|
+
toString() {
|
|
475
|
+
return format(
|
|
476
|
+
"ObjectSize_dw:%d,pc:%d",
|
|
477
|
+
getDataWordLength(this),
|
|
478
|
+
this.pointerLength
|
|
479
|
+
);
|
|
610
480
|
}
|
|
611
481
|
};
|
|
612
|
-
|
|
613
|
-
|
|
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());
|
|
482
|
+
function getByteLength(o) {
|
|
483
|
+
return o.dataByteLength + o.pointerLength * 8;
|
|
653
484
|
}
|
|
654
|
-
__name(
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
485
|
+
__name(getByteLength, "getByteLength");
|
|
486
|
+
function getDataWordLength(o) {
|
|
487
|
+
return o.dataByteLength / 8;
|
|
488
|
+
}
|
|
489
|
+
__name(getDataWordLength, "getDataWordLength");
|
|
490
|
+
function getWordLength(o) {
|
|
491
|
+
return o.dataByteLength / 8 + o.pointerLength;
|
|
492
|
+
}
|
|
493
|
+
__name(getWordLength, "getWordLength");
|
|
494
|
+
function padToWord(o) {
|
|
495
|
+
return new ObjectSize(padToWord$1(o.dataByteLength), o.pointerLength);
|
|
496
|
+
}
|
|
497
|
+
__name(padToWord, "padToWord");
|
|
498
|
+
var Orphan = class {
|
|
499
|
+
static {
|
|
500
|
+
__name(this, "Orphan");
|
|
664
501
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
502
|
+
/** If this member is not present then the orphan has already been adopted, or something went very wrong. */
|
|
503
|
+
_capnp;
|
|
504
|
+
byteOffset;
|
|
505
|
+
segment;
|
|
506
|
+
constructor(src) {
|
|
507
|
+
const c = getContent(src);
|
|
508
|
+
this.segment = c.segment;
|
|
509
|
+
this.byteOffset = c.byteOffset;
|
|
510
|
+
this._capnp = {};
|
|
511
|
+
this._capnp.type = getTargetPointerType(src);
|
|
512
|
+
switch (this._capnp.type) {
|
|
513
|
+
case PointerType.STRUCT: {
|
|
514
|
+
this._capnp.size = getTargetStructSize(src);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case PointerType.LIST: {
|
|
518
|
+
this._capnp.length = getTargetListLength(src);
|
|
519
|
+
this._capnp.elementSize = getTargetListElementSize(src);
|
|
520
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
521
|
+
this._capnp.size = getTargetCompositeListSize(src);
|
|
522
|
+
}
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
case PointerType.OTHER: {
|
|
526
|
+
this._capnp.capId = getCapabilityId(src);
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
default: {
|
|
530
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
531
|
+
}
|
|
673
532
|
}
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
if (trailingSeparator) {
|
|
677
|
-
path += "/";
|
|
678
|
-
}
|
|
679
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
680
|
-
path += "/";
|
|
533
|
+
erasePointer(src);
|
|
681
534
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
535
|
+
/**
|
|
536
|
+
* Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed.
|
|
537
|
+
*
|
|
538
|
+
* @param dst The destination pointer.
|
|
539
|
+
*/
|
|
540
|
+
_moveTo(dst) {
|
|
541
|
+
if (this._capnp === void 0) {
|
|
542
|
+
throw new Error(format(PTR_ALREADY_ADOPTED, this));
|
|
685
543
|
}
|
|
686
|
-
|
|
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;
|
|
544
|
+
if (this.segment.message !== dst.segment.message) {
|
|
545
|
+
throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst));
|
|
695
546
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
|
|
547
|
+
erase(dst);
|
|
548
|
+
const res = initPointer(this.segment, this.byteOffset, dst);
|
|
549
|
+
switch (this._capnp.type) {
|
|
550
|
+
case PointerType.STRUCT: {
|
|
551
|
+
setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case PointerType.LIST: {
|
|
555
|
+
let { offsetWords } = res;
|
|
556
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
557
|
+
offsetWords--;
|
|
558
|
+
}
|
|
559
|
+
setListPointer(
|
|
560
|
+
offsetWords,
|
|
561
|
+
this._capnp.elementSize,
|
|
562
|
+
this._capnp.length,
|
|
563
|
+
res.pointer,
|
|
564
|
+
this._capnp.size
|
|
565
|
+
);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
case PointerType.OTHER: {
|
|
569
|
+
setInterfacePointer(this._capnp.capId, res.pointer);
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
/* istanbul ignore next */
|
|
573
|
+
default: {
|
|
574
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
704
575
|
}
|
|
705
|
-
} else {
|
|
706
|
-
path += seg;
|
|
707
576
|
}
|
|
577
|
+
this._capnp = void 0;
|
|
708
578
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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 = "/";
|
|
579
|
+
dispose() {
|
|
580
|
+
if (this._capnp === void 0) {
|
|
581
|
+
return;
|
|
724
582
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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;
|
|
583
|
+
switch (this._capnp.type) {
|
|
584
|
+
case PointerType.STRUCT: {
|
|
585
|
+
this.segment.fillZeroWords(
|
|
586
|
+
this.byteOffset,
|
|
587
|
+
getWordLength(this._capnp.size)
|
|
588
|
+
);
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
case PointerType.LIST: {
|
|
592
|
+
const byteLength = getListByteLength(
|
|
593
|
+
this._capnp.elementSize,
|
|
594
|
+
this._capnp.length,
|
|
595
|
+
this._capnp.size
|
|
596
|
+
);
|
|
597
|
+
this.segment.fillZeroWords(this.byteOffset, byteLength);
|
|
598
|
+
break;
|
|
760
599
|
}
|
|
761
|
-
lastSlash = index;
|
|
762
|
-
dots = 0;
|
|
763
|
-
} else if (char === "." && dots !== -1) {
|
|
764
|
-
++dots;
|
|
765
|
-
} else {
|
|
766
|
-
dots = -1;
|
|
767
600
|
}
|
|
601
|
+
this._capnp = void 0;
|
|
768
602
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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;
|
|
603
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
604
|
+
return format(
|
|
605
|
+
"Orphan_%d@%a,type:%s",
|
|
606
|
+
this.segment.id,
|
|
607
|
+
this.byteOffset,
|
|
608
|
+
this._capnp && this._capnp.type
|
|
609
|
+
);
|
|
809
610
|
}
|
|
810
|
-
|
|
611
|
+
};
|
|
612
|
+
function adopt(src, p) {
|
|
613
|
+
src._moveTo(p);
|
|
811
614
|
}
|
|
812
|
-
__name(
|
|
813
|
-
function
|
|
814
|
-
|
|
815
|
-
const result = normalizedPath.replace(findFileName(normalizedPath, {
|
|
816
|
-
requireExtension: true
|
|
817
|
-
}), "");
|
|
818
|
-
return result === "/" ? result : result.replace(/\/$/, "");
|
|
615
|
+
__name(adopt, "adopt");
|
|
616
|
+
function disown(p) {
|
|
617
|
+
return new Orphan(p);
|
|
819
618
|
}
|
|
820
|
-
__name(
|
|
821
|
-
function
|
|
822
|
-
return (
|
|
619
|
+
__name(disown, "disown");
|
|
620
|
+
function dump(p) {
|
|
621
|
+
return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8));
|
|
823
622
|
}
|
|
824
|
-
__name(
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
623
|
+
__name(dump, "dump");
|
|
624
|
+
function getListByteLength(elementSize, length, compositeSize) {
|
|
625
|
+
switch (elementSize) {
|
|
626
|
+
case ListElementSize.BIT: {
|
|
627
|
+
return padToWord$1(length + 7 >>> 3);
|
|
628
|
+
}
|
|
629
|
+
case ListElementSize.BYTE:
|
|
630
|
+
case ListElementSize.BYTE_2:
|
|
631
|
+
case ListElementSize.BYTE_4:
|
|
632
|
+
case ListElementSize.BYTE_8:
|
|
633
|
+
case ListElementSize.POINTER:
|
|
634
|
+
case ListElementSize.VOID: {
|
|
635
|
+
return padToWord$1(getListElementByteLength(elementSize) * length);
|
|
636
|
+
}
|
|
637
|
+
/* istanbul ignore next */
|
|
638
|
+
case ListElementSize.COMPOSITE: {
|
|
639
|
+
if (compositeSize === void 0) {
|
|
640
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));
|
|
641
|
+
}
|
|
642
|
+
return length * padToWord$1(getByteLength(compositeSize));
|
|
643
|
+
}
|
|
644
|
+
/* istanbul ignore next */
|
|
645
|
+
default: {
|
|
646
|
+
throw new Error(PTR_INVALID_LIST_SIZE);
|
|
647
|
+
}
|
|
835
648
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
649
|
+
}
|
|
650
|
+
__name(getListByteLength, "getListByteLength");
|
|
651
|
+
function getListElementByteLength(elementSize) {
|
|
652
|
+
switch (elementSize) {
|
|
653
|
+
/* istanbul ignore next */
|
|
654
|
+
case ListElementSize.BIT: {
|
|
655
|
+
return Number.NaN;
|
|
656
|
+
}
|
|
657
|
+
case ListElementSize.BYTE: {
|
|
658
|
+
return 1;
|
|
659
|
+
}
|
|
660
|
+
case ListElementSize.BYTE_2: {
|
|
661
|
+
return 2;
|
|
662
|
+
}
|
|
663
|
+
case ListElementSize.BYTE_4: {
|
|
664
|
+
return 4;
|
|
665
|
+
}
|
|
666
|
+
case ListElementSize.BYTE_8:
|
|
667
|
+
case ListElementSize.POINTER: {
|
|
668
|
+
return 8;
|
|
669
|
+
}
|
|
670
|
+
/* istanbul ignore next */
|
|
671
|
+
case ListElementSize.COMPOSITE: {
|
|
672
|
+
return Number.NaN;
|
|
673
|
+
}
|
|
674
|
+
/* istanbul ignore next */
|
|
675
|
+
case ListElementSize.VOID: {
|
|
676
|
+
return 0;
|
|
677
|
+
}
|
|
678
|
+
/* istanbul ignore next */
|
|
679
|
+
default: {
|
|
680
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
842
681
|
}
|
|
843
|
-
throw new Error(`Failed to parse JSON: ${path}`);
|
|
844
682
|
}
|
|
845
683
|
}
|
|
846
|
-
__name(
|
|
847
|
-
|
|
848
|
-
|
|
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));
|
|
684
|
+
__name(getListElementByteLength, "getListElementByteLength");
|
|
685
|
+
function add(offset, p) {
|
|
686
|
+
return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit);
|
|
856
687
|
}
|
|
857
|
-
__name(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
862
|
-
if (!options?.withFileTypes) {
|
|
863
|
-
return result.map((file) => file.fullpath());
|
|
688
|
+
__name(add, "add");
|
|
689
|
+
function copyFrom(src, p) {
|
|
690
|
+
if (p.segment === src.segment && p.byteOffset === src.byteOffset) {
|
|
691
|
+
return;
|
|
864
692
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
|
|
887
|
-
return ListElementSize2;
|
|
888
|
-
})(ListElementSize || {});
|
|
889
|
-
var tmpWord = new DataView(new ArrayBuffer(8));
|
|
890
|
-
new Uint16Array(tmpWord.buffer)[0] = 258;
|
|
891
|
-
var DEFAULT_BUFFER_SIZE = 4096;
|
|
892
|
-
var DEFAULT_TRAVERSE_LIMIT = 64 << 20;
|
|
893
|
-
var LIST_SIZE_MASK = 7;
|
|
894
|
-
var MAX_BUFFER_DUMP_BYTES = 8192;
|
|
895
|
-
var MAX_INT32 = 2147483647;
|
|
896
|
-
var MAX_UINT32 = 4294967295;
|
|
897
|
-
var MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
|
898
|
-
var NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
|
|
899
|
-
var PACK_SPAN_THRESHOLD = 2;
|
|
900
|
-
var POINTER_DOUBLE_FAR_MASK = 4;
|
|
901
|
-
var POINTER_TYPE_MASK = 3;
|
|
902
|
-
var MAX_DEPTH = MAX_INT32;
|
|
903
|
-
var MAX_SEGMENT_LENGTH = MAX_UINT32;
|
|
904
|
-
var INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
|
905
|
-
function assertNever(n) {
|
|
906
|
-
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
|
907
|
-
}
|
|
908
|
-
__name(assertNever, "assertNever");
|
|
909
|
-
var MSG_INVALID_FRAME_HEADER = "CAPNP-TS001 Attempted to parse an invalid message frame header; are you sure this is a Cap'n Proto message?";
|
|
910
|
-
var MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
|
911
|
-
var MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
|
912
|
-
var MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
|
913
|
-
var PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
|
914
|
-
var PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
|
915
|
-
var PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
|
916
|
-
var PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
|
917
|
-
var PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
|
918
|
-
var PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
|
919
|
-
var PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
|
920
|
-
var PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
|
921
|
-
var PTR_INVALID_UNION_ACCESS = "CAPNP-TS018 Attempted to access getter on %s for union field %s that is not currently set (wanted: %d, found: %d).";
|
|
922
|
-
var PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
|
923
|
-
var PTR_STRUCT_DATA_OUT_OF_BOUNDS = "CAPNP-TS020 Attempted to access out-of-bounds struct data (struct: %s, %d bytes at %a, data words: %d).";
|
|
924
|
-
var PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
|
925
|
-
var PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
|
926
|
-
var PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
|
927
|
-
var PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
|
928
|
-
var SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
|
929
|
-
var SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
|
930
|
-
var SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
|
931
|
-
var SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
|
932
|
-
var SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
|
933
|
-
var TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
|
934
|
-
var LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
|
|
935
|
-
var LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
|
|
936
|
-
function bufferToHex(buffer) {
|
|
937
|
-
const a = new Uint8Array(buffer);
|
|
938
|
-
const h = [];
|
|
939
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
940
|
-
h.push(pad(a[i].toString(16), 2));
|
|
693
|
+
erase(p);
|
|
694
|
+
if (isNull(src)) return;
|
|
695
|
+
switch (getTargetPointerType(src)) {
|
|
696
|
+
case PointerType.STRUCT: {
|
|
697
|
+
copyFromStruct(src, p);
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
case PointerType.LIST: {
|
|
701
|
+
copyFromList(src, p);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
case PointerType.OTHER: {
|
|
705
|
+
copyFromInterface(src, p);
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
/* istanbul ignore next */
|
|
709
|
+
default: {
|
|
710
|
+
throw new Error(
|
|
711
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
712
|
+
);
|
|
713
|
+
}
|
|
941
714
|
}
|
|
942
|
-
return `[${h.join(" ")}]`;
|
|
943
715
|
}
|
|
944
|
-
__name(
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const v = b[j + k];
|
|
956
|
-
r += `${pad(v.toString(16), 2)} `;
|
|
957
|
-
s += v > 31 && v < 255 ? String.fromCharCode(v) : "\xB7";
|
|
958
|
-
if (k === 7) {
|
|
959
|
-
r += " ";
|
|
716
|
+
__name(copyFrom, "copyFrom");
|
|
717
|
+
function erase(p) {
|
|
718
|
+
if (isNull(p)) return;
|
|
719
|
+
let c;
|
|
720
|
+
switch (getTargetPointerType(p)) {
|
|
721
|
+
case PointerType.STRUCT: {
|
|
722
|
+
const size = getTargetStructSize(p);
|
|
723
|
+
c = getContent(p);
|
|
724
|
+
c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
|
|
725
|
+
for (let i = 0; i < size.pointerLength; i++) {
|
|
726
|
+
erase(add(i * 8, c));
|
|
960
727
|
}
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
case PointerType.LIST: {
|
|
731
|
+
const elementSize = getTargetListElementSize(p);
|
|
732
|
+
const length = getTargetListLength(p);
|
|
733
|
+
let contentWords = padToWord$1(
|
|
734
|
+
length * getListElementByteLength(elementSize)
|
|
735
|
+
);
|
|
736
|
+
c = getContent(p);
|
|
737
|
+
if (elementSize === ListElementSize.POINTER) {
|
|
738
|
+
for (let i = 0; i < length; i++) {
|
|
739
|
+
erase(
|
|
740
|
+
new Pointer(
|
|
741
|
+
c.segment,
|
|
742
|
+
c.byteOffset + i * 8,
|
|
743
|
+
p._capnp.depthLimit - 1
|
|
744
|
+
)
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
break;
|
|
748
|
+
} else if (elementSize === ListElementSize.COMPOSITE) {
|
|
749
|
+
const tag = add(-8, c);
|
|
750
|
+
const compositeSize = getStructSize(tag);
|
|
751
|
+
const compositeByteLength = getByteLength(compositeSize);
|
|
752
|
+
contentWords = getOffsetWords(tag);
|
|
753
|
+
c.segment.setWordZero(c.byteOffset - 8);
|
|
754
|
+
for (let i = 0; i < length; i++) {
|
|
755
|
+
for (let j = 0; j < compositeSize.pointerLength; j++) {
|
|
756
|
+
erase(
|
|
757
|
+
new Pointer(
|
|
758
|
+
c.segment,
|
|
759
|
+
c.byteOffset + i * compositeByteLength + j * 8,
|
|
760
|
+
p._capnp.depthLimit - 1
|
|
761
|
+
)
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
c.segment.fillZeroWords(c.byteOffset, contentWords);
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
case PointerType.OTHER: {
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
default: {
|
|
773
|
+
throw new Error(
|
|
774
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
775
|
+
);
|
|
961
776
|
}
|
|
962
|
-
r += `${" ".repeat((17 - k) * 3)}${s}`;
|
|
963
|
-
}
|
|
964
|
-
r += "\n";
|
|
965
|
-
if (byteLength !== b.byteLength) {
|
|
966
|
-
r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
|
|
967
777
|
}
|
|
968
|
-
|
|
778
|
+
erasePointer(p);
|
|
969
779
|
}
|
|
970
|
-
__name(
|
|
971
|
-
function
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
let leadingZero = false;
|
|
979
|
-
let precision;
|
|
980
|
-
let result = "";
|
|
981
|
-
function nextArg() {
|
|
982
|
-
return args[argIndex++];
|
|
780
|
+
__name(erase, "erase");
|
|
781
|
+
function erasePointer(p) {
|
|
782
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
783
|
+
const landingPad = followFar(p);
|
|
784
|
+
if (isDoubleFar(p)) {
|
|
785
|
+
landingPad.segment.setWordZero(landingPad.byteOffset + 8);
|
|
786
|
+
}
|
|
787
|
+
landingPad.segment.setWordZero(landingPad.byteOffset);
|
|
983
788
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
789
|
+
p.segment.setWordZero(p.byteOffset);
|
|
790
|
+
}
|
|
791
|
+
__name(erasePointer, "erasePointer");
|
|
792
|
+
function followFar(p) {
|
|
793
|
+
const targetSegment = p.segment.message.getSegment(
|
|
794
|
+
p.segment.getUint32(p.byteOffset + 4)
|
|
795
|
+
);
|
|
796
|
+
const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;
|
|
797
|
+
return new Pointer(
|
|
798
|
+
targetSegment,
|
|
799
|
+
targetWordOffset * 8,
|
|
800
|
+
p._capnp.depthLimit - 1
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
__name(followFar, "followFar");
|
|
804
|
+
function followFars(p) {
|
|
805
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
806
|
+
const landingPad = followFar(p);
|
|
807
|
+
if (isDoubleFar(p)) {
|
|
808
|
+
landingPad.byteOffset += 8;
|
|
990
809
|
}
|
|
991
|
-
return
|
|
810
|
+
return landingPad;
|
|
992
811
|
}
|
|
993
|
-
|
|
994
|
-
for (; i < n; ++i) {
|
|
995
|
-
c = s[i];
|
|
996
|
-
if (escaped) {
|
|
997
|
-
escaped = false;
|
|
998
|
-
if (c === ".") {
|
|
999
|
-
leadingZero = false;
|
|
1000
|
-
c = s[++i];
|
|
1001
|
-
} else if (c === "0" && s[i + 1] === ".") {
|
|
1002
|
-
leadingZero = true;
|
|
1003
|
-
i += 2;
|
|
1004
|
-
c = s[i];
|
|
1005
|
-
} else {
|
|
1006
|
-
leadingZero = true;
|
|
1007
|
-
}
|
|
1008
|
-
precision = slurpNumber();
|
|
1009
|
-
switch (c) {
|
|
1010
|
-
case "a": {
|
|
1011
|
-
result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
|
|
1012
|
-
break;
|
|
1013
|
-
}
|
|
1014
|
-
case "b": {
|
|
1015
|
-
result += Number.parseInt(String(nextArg()), 10).toString(2);
|
|
1016
|
-
break;
|
|
1017
|
-
}
|
|
1018
|
-
case "c": {
|
|
1019
|
-
arg = nextArg();
|
|
1020
|
-
result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
|
|
1021
|
-
break;
|
|
1022
|
-
}
|
|
1023
|
-
case "d": {
|
|
1024
|
-
result += Number.parseInt(String(nextArg()), 10);
|
|
1025
|
-
break;
|
|
1026
|
-
}
|
|
1027
|
-
case "f": {
|
|
1028
|
-
const tmp = Number.parseFloat(String(nextArg())).toFixed(
|
|
1029
|
-
precision || 6
|
|
1030
|
-
);
|
|
1031
|
-
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
1032
|
-
break;
|
|
1033
|
-
}
|
|
1034
|
-
case "j": {
|
|
1035
|
-
result += JSON.stringify(nextArg());
|
|
1036
|
-
break;
|
|
1037
|
-
}
|
|
1038
|
-
case "o": {
|
|
1039
|
-
result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
|
-
case "s": {
|
|
1043
|
-
result += nextArg();
|
|
1044
|
-
break;
|
|
1045
|
-
}
|
|
1046
|
-
case "x": {
|
|
1047
|
-
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
|
|
1048
|
-
break;
|
|
1049
|
-
}
|
|
1050
|
-
case "X": {
|
|
1051
|
-
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
|
|
1052
|
-
break;
|
|
1053
|
-
}
|
|
1054
|
-
default: {
|
|
1055
|
-
result += c;
|
|
1056
|
-
break;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
} else if (c === "%") {
|
|
1060
|
-
escaped = true;
|
|
1061
|
-
} else {
|
|
1062
|
-
result += c;
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
return result;
|
|
812
|
+
return p;
|
|
1066
813
|
}
|
|
1067
|
-
__name(
|
|
1068
|
-
function
|
|
1069
|
-
return
|
|
814
|
+
__name(followFars, "followFars");
|
|
815
|
+
function getCapabilityId(p) {
|
|
816
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
1070
817
|
}
|
|
1071
|
-
__name(
|
|
1072
|
-
function
|
|
1073
|
-
return
|
|
818
|
+
__name(getCapabilityId, "getCapabilityId");
|
|
819
|
+
function isCompositeList(p) {
|
|
820
|
+
return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
|
|
1074
821
|
}
|
|
1075
|
-
__name(
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
822
|
+
__name(isCompositeList, "isCompositeList");
|
|
823
|
+
function getContent(p, ignoreCompositeIndex) {
|
|
824
|
+
let c;
|
|
825
|
+
if (isDoubleFar(p)) {
|
|
826
|
+
const landingPad = followFar(p);
|
|
827
|
+
c = new Pointer(
|
|
828
|
+
p.segment.message.getSegment(getFarSegmentId(landingPad)),
|
|
829
|
+
getOffsetWords(landingPad) * 8
|
|
830
|
+
);
|
|
831
|
+
} else {
|
|
832
|
+
const target = followFars(p);
|
|
833
|
+
c = new Pointer(
|
|
834
|
+
target.segment,
|
|
835
|
+
target.byteOffset + 8 + getOffsetWords(target) * 8
|
|
836
|
+
);
|
|
1079
837
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
*
|
|
1083
|
-
* @param dataByteLength - The number of bytes in the data section of the struct
|
|
1084
|
-
* @param pointerLength - The number of pointers in the pointer section of the struct
|
|
1085
|
-
*/
|
|
1086
|
-
constructor(dataByteLength, pointerLength) {
|
|
1087
|
-
this.dataByteLength = dataByteLength;
|
|
1088
|
-
this.pointerLength = pointerLength;
|
|
838
|
+
if (isCompositeList(p)) {
|
|
839
|
+
c.byteOffset += 8;
|
|
1089
840
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
getDataWordLength(this),
|
|
1094
|
-
this.pointerLength
|
|
1095
|
-
);
|
|
841
|
+
if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
|
|
842
|
+
c.byteOffset -= 8;
|
|
843
|
+
c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
|
|
1096
844
|
}
|
|
1097
|
-
|
|
1098
|
-
function getByteLength(o) {
|
|
1099
|
-
return o.dataByteLength + o.pointerLength * 8;
|
|
845
|
+
return c;
|
|
1100
846
|
}
|
|
1101
|
-
__name(
|
|
1102
|
-
function
|
|
1103
|
-
return
|
|
847
|
+
__name(getContent, "getContent");
|
|
848
|
+
function getFarSegmentId(p) {
|
|
849
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
1104
850
|
}
|
|
1105
|
-
__name(
|
|
1106
|
-
function
|
|
1107
|
-
return
|
|
851
|
+
__name(getFarSegmentId, "getFarSegmentId");
|
|
852
|
+
function getListElementSize(p) {
|
|
853
|
+
return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1108
854
|
}
|
|
1109
|
-
__name(
|
|
1110
|
-
function
|
|
1111
|
-
return
|
|
855
|
+
__name(getListElementSize, "getListElementSize");
|
|
856
|
+
function getListLength(p) {
|
|
857
|
+
return p.segment.getUint32(p.byteOffset + 4) >>> 3;
|
|
1112
858
|
}
|
|
1113
|
-
__name(
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
859
|
+
__name(getListLength, "getListLength");
|
|
860
|
+
function getOffsetWords(p) {
|
|
861
|
+
const o = p.segment.getInt32(p.byteOffset);
|
|
862
|
+
return o & 2 ? o >> 3 : o >> 2;
|
|
863
|
+
}
|
|
864
|
+
__name(getOffsetWords, "getOffsetWords");
|
|
865
|
+
function getPointerType(p) {
|
|
866
|
+
return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
|
|
867
|
+
}
|
|
868
|
+
__name(getPointerType, "getPointerType");
|
|
869
|
+
function getStructDataWords(p) {
|
|
870
|
+
return p.segment.getUint16(p.byteOffset + 4);
|
|
871
|
+
}
|
|
872
|
+
__name(getStructDataWords, "getStructDataWords");
|
|
873
|
+
function getStructPointerLength(p) {
|
|
874
|
+
return p.segment.getUint16(p.byteOffset + 6);
|
|
875
|
+
}
|
|
876
|
+
__name(getStructPointerLength, "getStructPointerLength");
|
|
877
|
+
function getStructSize(p) {
|
|
878
|
+
return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
|
|
879
|
+
}
|
|
880
|
+
__name(getStructSize, "getStructSize");
|
|
881
|
+
function getTargetCompositeListTag(p) {
|
|
882
|
+
const c = getContent(p);
|
|
883
|
+
c.byteOffset -= 8;
|
|
884
|
+
return c;
|
|
885
|
+
}
|
|
886
|
+
__name(getTargetCompositeListTag, "getTargetCompositeListTag");
|
|
887
|
+
function getTargetCompositeListSize(p) {
|
|
888
|
+
return getStructSize(getTargetCompositeListTag(p));
|
|
889
|
+
}
|
|
890
|
+
__name(getTargetCompositeListSize, "getTargetCompositeListSize");
|
|
891
|
+
function getTargetListElementSize(p) {
|
|
892
|
+
return getListElementSize(followFars(p));
|
|
893
|
+
}
|
|
894
|
+
__name(getTargetListElementSize, "getTargetListElementSize");
|
|
895
|
+
function getTargetListLength(p) {
|
|
896
|
+
const t = followFars(p);
|
|
897
|
+
if (getListElementSize(t) === ListElementSize.COMPOSITE) {
|
|
898
|
+
return getOffsetWords(getTargetCompositeListTag(p));
|
|
1117
899
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
this.byteOffset = c.byteOffset;
|
|
1126
|
-
this._capnp = {};
|
|
1127
|
-
this._capnp.type = getTargetPointerType(src);
|
|
1128
|
-
switch (this._capnp.type) {
|
|
1129
|
-
case PointerType.STRUCT: {
|
|
1130
|
-
this._capnp.size = getTargetStructSize(src);
|
|
1131
|
-
break;
|
|
1132
|
-
}
|
|
1133
|
-
case PointerType.LIST: {
|
|
1134
|
-
this._capnp.length = getTargetListLength(src);
|
|
1135
|
-
this._capnp.elementSize = getTargetListElementSize(src);
|
|
1136
|
-
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
1137
|
-
this._capnp.size = getTargetCompositeListSize(src);
|
|
1138
|
-
}
|
|
1139
|
-
break;
|
|
1140
|
-
}
|
|
1141
|
-
case PointerType.OTHER: {
|
|
1142
|
-
this._capnp.capId = getCapabilityId(src);
|
|
1143
|
-
break;
|
|
1144
|
-
}
|
|
1145
|
-
default: {
|
|
1146
|
-
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
erasePointer(src);
|
|
900
|
+
return getListLength(t);
|
|
901
|
+
}
|
|
902
|
+
__name(getTargetListLength, "getTargetListLength");
|
|
903
|
+
function getTargetPointerType(p) {
|
|
904
|
+
const t = getPointerType(followFars(p));
|
|
905
|
+
if (t === PointerType.FAR) {
|
|
906
|
+
throw new Error(format(PTR_INVALID_FAR_TARGET, p));
|
|
1150
907
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
908
|
+
return t;
|
|
909
|
+
}
|
|
910
|
+
__name(getTargetPointerType, "getTargetPointerType");
|
|
911
|
+
function getTargetStructSize(p) {
|
|
912
|
+
return getStructSize(followFars(p));
|
|
913
|
+
}
|
|
914
|
+
__name(getTargetStructSize, "getTargetStructSize");
|
|
915
|
+
function initPointer(contentSegment, contentOffset, p) {
|
|
916
|
+
if (p.segment !== contentSegment) {
|
|
917
|
+
if (!contentSegment.hasCapacity(8)) {
|
|
918
|
+
const landingPad2 = p.segment.allocate(16);
|
|
919
|
+
setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
|
|
920
|
+
setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
|
|
921
|
+
landingPad2.byteOffset += 8;
|
|
922
|
+
return new PointerAllocationResult(landingPad2, 0);
|
|
1159
923
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
924
|
+
const landingPad = contentSegment.allocate(8);
|
|
925
|
+
if (landingPad.segment.id !== contentSegment.id) {
|
|
926
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
|
1162
927
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
|
|
1168
|
-
break;
|
|
1169
|
-
}
|
|
1170
|
-
case PointerType.LIST: {
|
|
1171
|
-
let { offsetWords } = res;
|
|
1172
|
-
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
1173
|
-
offsetWords--;
|
|
1174
|
-
}
|
|
1175
|
-
setListPointer(
|
|
1176
|
-
offsetWords,
|
|
1177
|
-
this._capnp.elementSize,
|
|
1178
|
-
this._capnp.length,
|
|
1179
|
-
res.pointer,
|
|
1180
|
-
this._capnp.size
|
|
1181
|
-
);
|
|
1182
|
-
break;
|
|
1183
|
-
}
|
|
1184
|
-
case PointerType.OTHER: {
|
|
1185
|
-
setInterfacePointer(this._capnp.capId, res.pointer);
|
|
1186
|
-
break;
|
|
1187
|
-
}
|
|
1188
|
-
/* istanbul ignore next */
|
|
1189
|
-
default: {
|
|
1190
|
-
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
this._capnp = void 0;
|
|
1194
|
-
}
|
|
1195
|
-
dispose() {
|
|
1196
|
-
if (this._capnp === void 0) {
|
|
1197
|
-
return;
|
|
1198
|
-
}
|
|
1199
|
-
switch (this._capnp.type) {
|
|
1200
|
-
case PointerType.STRUCT: {
|
|
1201
|
-
this.segment.fillZeroWords(
|
|
1202
|
-
this.byteOffset,
|
|
1203
|
-
getWordLength(this._capnp.size)
|
|
1204
|
-
);
|
|
1205
|
-
break;
|
|
1206
|
-
}
|
|
1207
|
-
case PointerType.LIST: {
|
|
1208
|
-
const byteLength = getListByteLength(
|
|
1209
|
-
this._capnp.elementSize,
|
|
1210
|
-
this._capnp.length,
|
|
1211
|
-
this._capnp.size
|
|
1212
|
-
);
|
|
1213
|
-
this.segment.fillZeroWords(this.byteOffset, byteLength);
|
|
1214
|
-
break;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
this._capnp = void 0;
|
|
1218
|
-
}
|
|
1219
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1220
|
-
return format(
|
|
1221
|
-
"Orphan_%d@%a,type:%s",
|
|
1222
|
-
this.segment.id,
|
|
1223
|
-
this.byteOffset,
|
|
1224
|
-
this._capnp && this._capnp.type
|
|
928
|
+
setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
|
|
929
|
+
return new PointerAllocationResult(
|
|
930
|
+
landingPad,
|
|
931
|
+
(contentOffset - landingPad.byteOffset - 8) / 8
|
|
1225
932
|
);
|
|
1226
933
|
}
|
|
1227
|
-
|
|
1228
|
-
function adopt(src, p) {
|
|
1229
|
-
src._moveTo(p);
|
|
934
|
+
return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
|
|
1230
935
|
}
|
|
1231
|
-
__name(
|
|
1232
|
-
function
|
|
1233
|
-
return
|
|
936
|
+
__name(initPointer, "initPointer");
|
|
937
|
+
function isDoubleFar(p) {
|
|
938
|
+
return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
|
|
1234
939
|
}
|
|
1235
|
-
__name(
|
|
1236
|
-
function
|
|
1237
|
-
return
|
|
940
|
+
__name(isDoubleFar, "isDoubleFar");
|
|
941
|
+
function isNull(p) {
|
|
942
|
+
return p.segment.isWordZero(p.byteOffset);
|
|
1238
943
|
}
|
|
1239
|
-
__name(
|
|
1240
|
-
function
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
case ListElementSize.BYTE_4:
|
|
1248
|
-
case ListElementSize.BYTE_8:
|
|
1249
|
-
case ListElementSize.POINTER:
|
|
1250
|
-
case ListElementSize.VOID: {
|
|
1251
|
-
return padToWord$1(getListElementByteLength(elementSize) * length);
|
|
1252
|
-
}
|
|
1253
|
-
/* istanbul ignore next */
|
|
1254
|
-
case ListElementSize.COMPOSITE: {
|
|
1255
|
-
if (compositeSize === void 0) {
|
|
1256
|
-
throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));
|
|
1257
|
-
}
|
|
1258
|
-
return length * padToWord$1(getByteLength(compositeSize));
|
|
1259
|
-
}
|
|
1260
|
-
/* istanbul ignore next */
|
|
1261
|
-
default: {
|
|
1262
|
-
throw new Error(PTR_INVALID_LIST_SIZE);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
944
|
+
__name(isNull, "isNull");
|
|
945
|
+
function setFarPointer(doubleFar, offsetWords, segmentId, p) {
|
|
946
|
+
const A = PointerType.FAR;
|
|
947
|
+
const B = doubleFar ? 1 : 0;
|
|
948
|
+
const C = offsetWords;
|
|
949
|
+
const D = segmentId;
|
|
950
|
+
p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
|
|
951
|
+
p.segment.setUint32(p.byteOffset + 4, D);
|
|
1265
952
|
}
|
|
1266
|
-
__name(
|
|
1267
|
-
function
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
return 8;
|
|
1285
|
-
}
|
|
1286
|
-
/* istanbul ignore next */
|
|
1287
|
-
case ListElementSize.COMPOSITE: {
|
|
1288
|
-
return Number.NaN;
|
|
1289
|
-
}
|
|
1290
|
-
/* istanbul ignore next */
|
|
1291
|
-
case ListElementSize.VOID: {
|
|
1292
|
-
return 0;
|
|
1293
|
-
}
|
|
1294
|
-
/* istanbul ignore next */
|
|
1295
|
-
default: {
|
|
1296
|
-
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
953
|
+
__name(setFarPointer, "setFarPointer");
|
|
954
|
+
function setInterfacePointer(capId, p) {
|
|
955
|
+
p.segment.setUint32(p.byteOffset, PointerType.OTHER);
|
|
956
|
+
p.segment.setUint32(p.byteOffset + 4, capId);
|
|
957
|
+
}
|
|
958
|
+
__name(setInterfacePointer, "setInterfacePointer");
|
|
959
|
+
function getInterfacePointer(p) {
|
|
960
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
961
|
+
}
|
|
962
|
+
__name(getInterfacePointer, "getInterfacePointer");
|
|
963
|
+
function setListPointer(offsetWords, size, length, p, compositeSize) {
|
|
964
|
+
const A = PointerType.LIST;
|
|
965
|
+
const B = offsetWords;
|
|
966
|
+
const C = size;
|
|
967
|
+
let D = length;
|
|
968
|
+
if (size === ListElementSize.COMPOSITE) {
|
|
969
|
+
if (compositeSize === void 0) {
|
|
970
|
+
throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
|
|
1297
971
|
}
|
|
972
|
+
D *= getWordLength(compositeSize);
|
|
1298
973
|
}
|
|
974
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
975
|
+
p.segment.setUint32(p.byteOffset + 4, C | D << 3);
|
|
1299
976
|
}
|
|
1300
|
-
__name(
|
|
1301
|
-
function
|
|
1302
|
-
|
|
977
|
+
__name(setListPointer, "setListPointer");
|
|
978
|
+
function setStructPointer(offsetWords, size, p) {
|
|
979
|
+
const A = PointerType.STRUCT;
|
|
980
|
+
const B = offsetWords;
|
|
981
|
+
const C = getDataWordLength(size);
|
|
982
|
+
const D = size.pointerLength;
|
|
983
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
984
|
+
p.segment.setUint16(p.byteOffset + 4, C);
|
|
985
|
+
p.segment.setUint16(p.byteOffset + 6, D);
|
|
1303
986
|
}
|
|
1304
|
-
__name(
|
|
1305
|
-
function
|
|
1306
|
-
if (p
|
|
987
|
+
__name(setStructPointer, "setStructPointer");
|
|
988
|
+
function validate(pointerType, p, elementSize) {
|
|
989
|
+
if (isNull(p)) {
|
|
1307
990
|
return;
|
|
1308
991
|
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
copyFromList(src, p);
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
case PointerType.OTHER: {
|
|
1321
|
-
copyFromInterface(src, p);
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
/* istanbul ignore next */
|
|
1325
|
-
default: {
|
|
992
|
+
const t = followFars(p);
|
|
993
|
+
const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;
|
|
994
|
+
if (A !== pointerType) {
|
|
995
|
+
throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
|
|
996
|
+
}
|
|
997
|
+
if (elementSize !== void 0) {
|
|
998
|
+
const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;
|
|
999
|
+
if (C !== elementSize) {
|
|
1326
1000
|
throw new Error(
|
|
1327
|
-
format(
|
|
1328
|
-
);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
__name(copyFrom, "copyFrom");
|
|
1333
|
-
function erase(p) {
|
|
1334
|
-
if (isNull(p)) return;
|
|
1335
|
-
let c;
|
|
1336
|
-
switch (getTargetPointerType(p)) {
|
|
1337
|
-
case PointerType.STRUCT: {
|
|
1338
|
-
const size = getTargetStructSize(p);
|
|
1339
|
-
c = getContent(p);
|
|
1340
|
-
c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
|
|
1341
|
-
for (let i = 0; i < size.pointerLength; i++) {
|
|
1342
|
-
erase(add(i * 8, c));
|
|
1343
|
-
}
|
|
1344
|
-
break;
|
|
1345
|
-
}
|
|
1346
|
-
case PointerType.LIST: {
|
|
1347
|
-
const elementSize = getTargetListElementSize(p);
|
|
1348
|
-
const length = getTargetListLength(p);
|
|
1349
|
-
let contentWords = padToWord$1(
|
|
1350
|
-
length * getListElementByteLength(elementSize)
|
|
1351
|
-
);
|
|
1352
|
-
c = getContent(p);
|
|
1353
|
-
if (elementSize === ListElementSize.POINTER) {
|
|
1354
|
-
for (let i = 0; i < length; i++) {
|
|
1355
|
-
erase(
|
|
1356
|
-
new Pointer(
|
|
1357
|
-
c.segment,
|
|
1358
|
-
c.byteOffset + i * 8,
|
|
1359
|
-
p._capnp.depthLimit - 1
|
|
1360
|
-
)
|
|
1361
|
-
);
|
|
1362
|
-
}
|
|
1363
|
-
break;
|
|
1364
|
-
} else if (elementSize === ListElementSize.COMPOSITE) {
|
|
1365
|
-
const tag = add(-8, c);
|
|
1366
|
-
const compositeSize = getStructSize(tag);
|
|
1367
|
-
const compositeByteLength = getByteLength(compositeSize);
|
|
1368
|
-
contentWords = getOffsetWords(tag);
|
|
1369
|
-
c.segment.setWordZero(c.byteOffset - 8);
|
|
1370
|
-
for (let i = 0; i < length; i++) {
|
|
1371
|
-
for (let j = 0; j < compositeSize.pointerLength; j++) {
|
|
1372
|
-
erase(
|
|
1373
|
-
new Pointer(
|
|
1374
|
-
c.segment,
|
|
1375
|
-
c.byteOffset + i * compositeByteLength + j * 8,
|
|
1376
|
-
p._capnp.depthLimit - 1
|
|
1377
|
-
)
|
|
1378
|
-
);
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
c.segment.fillZeroWords(c.byteOffset, contentWords);
|
|
1383
|
-
break;
|
|
1384
|
-
}
|
|
1385
|
-
case PointerType.OTHER: {
|
|
1386
|
-
break;
|
|
1387
|
-
}
|
|
1388
|
-
default: {
|
|
1389
|
-
throw new Error(
|
|
1390
|
-
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
1391
|
-
);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
erasePointer(p);
|
|
1395
|
-
}
|
|
1396
|
-
__name(erase, "erase");
|
|
1397
|
-
function erasePointer(p) {
|
|
1398
|
-
if (getPointerType(p) === PointerType.FAR) {
|
|
1399
|
-
const landingPad = followFar(p);
|
|
1400
|
-
if (isDoubleFar(p)) {
|
|
1401
|
-
landingPad.segment.setWordZero(landingPad.byteOffset + 8);
|
|
1402
|
-
}
|
|
1403
|
-
landingPad.segment.setWordZero(landingPad.byteOffset);
|
|
1404
|
-
}
|
|
1405
|
-
p.segment.setWordZero(p.byteOffset);
|
|
1406
|
-
}
|
|
1407
|
-
__name(erasePointer, "erasePointer");
|
|
1408
|
-
function followFar(p) {
|
|
1409
|
-
const targetSegment = p.segment.message.getSegment(
|
|
1410
|
-
p.segment.getUint32(p.byteOffset + 4)
|
|
1411
|
-
);
|
|
1412
|
-
const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;
|
|
1413
|
-
return new Pointer(
|
|
1414
|
-
targetSegment,
|
|
1415
|
-
targetWordOffset * 8,
|
|
1416
|
-
p._capnp.depthLimit - 1
|
|
1417
|
-
);
|
|
1418
|
-
}
|
|
1419
|
-
__name(followFar, "followFar");
|
|
1420
|
-
function followFars(p) {
|
|
1421
|
-
if (getPointerType(p) === PointerType.FAR) {
|
|
1422
|
-
const landingPad = followFar(p);
|
|
1423
|
-
if (isDoubleFar(p)) {
|
|
1424
|
-
landingPad.byteOffset += 8;
|
|
1425
|
-
}
|
|
1426
|
-
return landingPad;
|
|
1427
|
-
}
|
|
1428
|
-
return p;
|
|
1429
|
-
}
|
|
1430
|
-
__name(followFars, "followFars");
|
|
1431
|
-
function getCapabilityId(p) {
|
|
1432
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1433
|
-
}
|
|
1434
|
-
__name(getCapabilityId, "getCapabilityId");
|
|
1435
|
-
function isCompositeList(p) {
|
|
1436
|
-
return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
|
|
1437
|
-
}
|
|
1438
|
-
__name(isCompositeList, "isCompositeList");
|
|
1439
|
-
function getContent(p, ignoreCompositeIndex) {
|
|
1440
|
-
let c;
|
|
1441
|
-
if (isDoubleFar(p)) {
|
|
1442
|
-
const landingPad = followFar(p);
|
|
1443
|
-
c = new Pointer(
|
|
1444
|
-
p.segment.message.getSegment(getFarSegmentId(landingPad)),
|
|
1445
|
-
getOffsetWords(landingPad) * 8
|
|
1446
|
-
);
|
|
1447
|
-
} else {
|
|
1448
|
-
const target = followFars(p);
|
|
1449
|
-
c = new Pointer(
|
|
1450
|
-
target.segment,
|
|
1451
|
-
target.byteOffset + 8 + getOffsetWords(target) * 8
|
|
1452
|
-
);
|
|
1453
|
-
}
|
|
1454
|
-
if (isCompositeList(p)) {
|
|
1455
|
-
c.byteOffset += 8;
|
|
1456
|
-
}
|
|
1457
|
-
if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
|
|
1458
|
-
c.byteOffset -= 8;
|
|
1459
|
-
c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
|
|
1460
|
-
}
|
|
1461
|
-
return c;
|
|
1462
|
-
}
|
|
1463
|
-
__name(getContent, "getContent");
|
|
1464
|
-
function getFarSegmentId(p) {
|
|
1465
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1466
|
-
}
|
|
1467
|
-
__name(getFarSegmentId, "getFarSegmentId");
|
|
1468
|
-
function getListElementSize(p) {
|
|
1469
|
-
return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1470
|
-
}
|
|
1471
|
-
__name(getListElementSize, "getListElementSize");
|
|
1472
|
-
function getListLength(p) {
|
|
1473
|
-
return p.segment.getUint32(p.byteOffset + 4) >>> 3;
|
|
1474
|
-
}
|
|
1475
|
-
__name(getListLength, "getListLength");
|
|
1476
|
-
function getOffsetWords(p) {
|
|
1477
|
-
const o = p.segment.getInt32(p.byteOffset);
|
|
1478
|
-
return o & 2 ? o >> 3 : o >> 2;
|
|
1479
|
-
}
|
|
1480
|
-
__name(getOffsetWords, "getOffsetWords");
|
|
1481
|
-
function getPointerType(p) {
|
|
1482
|
-
return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
|
|
1483
|
-
}
|
|
1484
|
-
__name(getPointerType, "getPointerType");
|
|
1485
|
-
function getStructDataWords(p) {
|
|
1486
|
-
return p.segment.getUint16(p.byteOffset + 4);
|
|
1487
|
-
}
|
|
1488
|
-
__name(getStructDataWords, "getStructDataWords");
|
|
1489
|
-
function getStructPointerLength(p) {
|
|
1490
|
-
return p.segment.getUint16(p.byteOffset + 6);
|
|
1491
|
-
}
|
|
1492
|
-
__name(getStructPointerLength, "getStructPointerLength");
|
|
1493
|
-
function getStructSize(p) {
|
|
1494
|
-
return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
|
|
1495
|
-
}
|
|
1496
|
-
__name(getStructSize, "getStructSize");
|
|
1497
|
-
function getTargetCompositeListTag(p) {
|
|
1498
|
-
const c = getContent(p);
|
|
1499
|
-
c.byteOffset -= 8;
|
|
1500
|
-
return c;
|
|
1501
|
-
}
|
|
1502
|
-
__name(getTargetCompositeListTag, "getTargetCompositeListTag");
|
|
1503
|
-
function getTargetCompositeListSize(p) {
|
|
1504
|
-
return getStructSize(getTargetCompositeListTag(p));
|
|
1505
|
-
}
|
|
1506
|
-
__name(getTargetCompositeListSize, "getTargetCompositeListSize");
|
|
1507
|
-
function getTargetListElementSize(p) {
|
|
1508
|
-
return getListElementSize(followFars(p));
|
|
1509
|
-
}
|
|
1510
|
-
__name(getTargetListElementSize, "getTargetListElementSize");
|
|
1511
|
-
function getTargetListLength(p) {
|
|
1512
|
-
const t = followFars(p);
|
|
1513
|
-
if (getListElementSize(t) === ListElementSize.COMPOSITE) {
|
|
1514
|
-
return getOffsetWords(getTargetCompositeListTag(p));
|
|
1515
|
-
}
|
|
1516
|
-
return getListLength(t);
|
|
1517
|
-
}
|
|
1518
|
-
__name(getTargetListLength, "getTargetListLength");
|
|
1519
|
-
function getTargetPointerType(p) {
|
|
1520
|
-
const t = getPointerType(followFars(p));
|
|
1521
|
-
if (t === PointerType.FAR) {
|
|
1522
|
-
throw new Error(format(PTR_INVALID_FAR_TARGET, p));
|
|
1523
|
-
}
|
|
1524
|
-
return t;
|
|
1525
|
-
}
|
|
1526
|
-
__name(getTargetPointerType, "getTargetPointerType");
|
|
1527
|
-
function getTargetStructSize(p) {
|
|
1528
|
-
return getStructSize(followFars(p));
|
|
1529
|
-
}
|
|
1530
|
-
__name(getTargetStructSize, "getTargetStructSize");
|
|
1531
|
-
function initPointer(contentSegment, contentOffset, p) {
|
|
1532
|
-
if (p.segment !== contentSegment) {
|
|
1533
|
-
if (!contentSegment.hasCapacity(8)) {
|
|
1534
|
-
const landingPad2 = p.segment.allocate(16);
|
|
1535
|
-
setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
|
|
1536
|
-
setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
|
|
1537
|
-
landingPad2.byteOffset += 8;
|
|
1538
|
-
return new PointerAllocationResult(landingPad2, 0);
|
|
1539
|
-
}
|
|
1540
|
-
const landingPad = contentSegment.allocate(8);
|
|
1541
|
-
if (landingPad.segment.id !== contentSegment.id) {
|
|
1542
|
-
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
|
1543
|
-
}
|
|
1544
|
-
setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
|
|
1545
|
-
return new PointerAllocationResult(
|
|
1546
|
-
landingPad,
|
|
1547
|
-
(contentOffset - landingPad.byteOffset - 8) / 8
|
|
1548
|
-
);
|
|
1549
|
-
}
|
|
1550
|
-
return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
|
|
1551
|
-
}
|
|
1552
|
-
__name(initPointer, "initPointer");
|
|
1553
|
-
function isDoubleFar(p) {
|
|
1554
|
-
return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
|
|
1555
|
-
}
|
|
1556
|
-
__name(isDoubleFar, "isDoubleFar");
|
|
1557
|
-
function isNull(p) {
|
|
1558
|
-
return p.segment.isWordZero(p.byteOffset);
|
|
1559
|
-
}
|
|
1560
|
-
__name(isNull, "isNull");
|
|
1561
|
-
function setFarPointer(doubleFar, offsetWords, segmentId, p) {
|
|
1562
|
-
const A = PointerType.FAR;
|
|
1563
|
-
const B = doubleFar ? 1 : 0;
|
|
1564
|
-
const C = offsetWords;
|
|
1565
|
-
const D = segmentId;
|
|
1566
|
-
p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
|
|
1567
|
-
p.segment.setUint32(p.byteOffset + 4, D);
|
|
1568
|
-
}
|
|
1569
|
-
__name(setFarPointer, "setFarPointer");
|
|
1570
|
-
function setInterfacePointer(capId, p) {
|
|
1571
|
-
p.segment.setUint32(p.byteOffset, PointerType.OTHER);
|
|
1572
|
-
p.segment.setUint32(p.byteOffset + 4, capId);
|
|
1573
|
-
}
|
|
1574
|
-
__name(setInterfacePointer, "setInterfacePointer");
|
|
1575
|
-
function getInterfacePointer(p) {
|
|
1576
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1577
|
-
}
|
|
1578
|
-
__name(getInterfacePointer, "getInterfacePointer");
|
|
1579
|
-
function setListPointer(offsetWords, size, length, p, compositeSize) {
|
|
1580
|
-
const A = PointerType.LIST;
|
|
1581
|
-
const B = offsetWords;
|
|
1582
|
-
const C = size;
|
|
1583
|
-
let D = length;
|
|
1584
|
-
if (size === ListElementSize.COMPOSITE) {
|
|
1585
|
-
if (compositeSize === void 0) {
|
|
1586
|
-
throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
|
|
1587
|
-
}
|
|
1588
|
-
D *= getWordLength(compositeSize);
|
|
1589
|
-
}
|
|
1590
|
-
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
1591
|
-
p.segment.setUint32(p.byteOffset + 4, C | D << 3);
|
|
1592
|
-
}
|
|
1593
|
-
__name(setListPointer, "setListPointer");
|
|
1594
|
-
function setStructPointer(offsetWords, size, p) {
|
|
1595
|
-
const A = PointerType.STRUCT;
|
|
1596
|
-
const B = offsetWords;
|
|
1597
|
-
const C = getDataWordLength(size);
|
|
1598
|
-
const D = size.pointerLength;
|
|
1599
|
-
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
1600
|
-
p.segment.setUint16(p.byteOffset + 4, C);
|
|
1601
|
-
p.segment.setUint16(p.byteOffset + 6, D);
|
|
1602
|
-
}
|
|
1603
|
-
__name(setStructPointer, "setStructPointer");
|
|
1604
|
-
function validate(pointerType, p, elementSize) {
|
|
1605
|
-
if (isNull(p)) {
|
|
1606
|
-
return;
|
|
1607
|
-
}
|
|
1608
|
-
const t = followFars(p);
|
|
1609
|
-
const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;
|
|
1610
|
-
if (A !== pointerType) {
|
|
1611
|
-
throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
|
|
1612
|
-
}
|
|
1613
|
-
if (elementSize !== void 0) {
|
|
1614
|
-
const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1615
|
-
if (C !== elementSize) {
|
|
1616
|
-
throw new Error(
|
|
1617
|
-
format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])
|
|
1001
|
+
format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])
|
|
1618
1002
|
);
|
|
1619
1003
|
}
|
|
1620
1004
|
}
|
|
@@ -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;
|
|
@@ -7574,340 +6958,1032 @@ function createValue(value) {
|
|
|
7574
6958
|
p = value.data;
|
|
7575
6959
|
break;
|
|
7576
6960
|
}
|
|
7577
|
-
case Value.LIST: {
|
|
7578
|
-
p = value.list;
|
|
7579
|
-
break;
|
|
6961
|
+
case Value.LIST: {
|
|
6962
|
+
p = value.list;
|
|
6963
|
+
break;
|
|
6964
|
+
}
|
|
6965
|
+
case Value.STRUCT: {
|
|
6966
|
+
p = value.struct;
|
|
6967
|
+
break;
|
|
6968
|
+
}
|
|
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)`;
|
|
6986
|
+
}
|
|
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) {
|
|
6995
|
+
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
6996
|
+
const fullClassName = getFullClassName(node);
|
|
6997
|
+
const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
|
|
6998
|
+
const nodeId = node.id;
|
|
6999
|
+
const nodeIdHex = nodeId.toString(16);
|
|
7000
|
+
const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
|
|
7001
|
+
const members = [];
|
|
7002
|
+
members.push(
|
|
7003
|
+
...consts.map((node2) => {
|
|
7004
|
+
const name = c2s(getDisplayNamePrefix(node2));
|
|
7005
|
+
const value = createValue(node2.const.value);
|
|
7006
|
+
return `static readonly ${name} = ${value}`;
|
|
7007
|
+
}),
|
|
7008
|
+
...nestedNodes.map((node2) => createNestedNodeProperty(node2)),
|
|
7009
|
+
`static readonly Client = ${fullClassName}$Client;
|
|
7010
|
+
static readonly Server = ${fullClassName}$Server;
|
|
7011
|
+
public static override readonly _capnp = {
|
|
7012
|
+
displayName: "${displayNamePrefix}",
|
|
7013
|
+
id: "${nodeIdHex}",
|
|
7014
|
+
size: new $.ObjectSize(0, 0),
|
|
7015
|
+
}
|
|
7016
|
+
public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
7017
|
+
);
|
|
7018
|
+
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
7019
|
+
const classCode = `
|
|
7020
|
+
${docComment}
|
|
7021
|
+
export class ${fullClassName} extends $.Interface {
|
|
7022
|
+
${members.join("\n")}
|
|
7023
|
+
}`;
|
|
7024
|
+
generateInterfaceClasses(ctx, node);
|
|
7025
|
+
ctx.codeParts.push(classCode);
|
|
7026
|
+
}
|
|
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;
|
|
7033
|
+
}
|
|
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);
|
|
7038
|
+
}
|
|
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);
|
|
7049
|
+
break;
|
|
7050
|
+
}
|
|
7051
|
+
case Node.CONST: {
|
|
7052
|
+
break;
|
|
7053
|
+
}
|
|
7054
|
+
case Node.ENUM: {
|
|
7055
|
+
generateEnumNode(
|
|
7056
|
+
ctx,
|
|
7057
|
+
getFullClassName(node),
|
|
7058
|
+
node,
|
|
7059
|
+
node.enum.enumerants.toArray()
|
|
7060
|
+
);
|
|
7061
|
+
break;
|
|
7062
|
+
}
|
|
7063
|
+
case Node.INTERFACE: {
|
|
7064
|
+
generateInterfaceNode(ctx, node);
|
|
7065
|
+
break;
|
|
7066
|
+
}
|
|
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}`;
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
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`];
|
|
7153
|
+
}
|
|
7154
|
+
return fullClassName;
|
|
7155
|
+
}).sort().join(", ");
|
|
7156
|
+
if (imports.length === 0) {
|
|
7157
|
+
continue;
|
|
7158
|
+
}
|
|
7159
|
+
ctx.codeParts.push(`import { ${imports} } from "${importPath}";`);
|
|
7160
|
+
}
|
|
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);
|
|
7181
|
+
}
|
|
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);
|
|
7187
|
+
}
|
|
7188
|
+
if (opts?.dts === true || opts?.js === true) {
|
|
7189
|
+
tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
|
|
7190
|
+
}
|
|
7191
|
+
if (!opts?.ts) {
|
|
7192
|
+
for (const [fileName] of files) {
|
|
7193
|
+
if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
|
|
7194
|
+
files.delete(fileName);
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7197
|
+
}
|
|
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}`);
|
|
7282
|
+
}
|
|
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
|
+
// ../convert/src/to-array.ts
|
|
7301
|
+
function toArray(array) {
|
|
7302
|
+
array = array ?? [];
|
|
7303
|
+
return Array.isArray(array) ? array : [
|
|
7304
|
+
array
|
|
7305
|
+
];
|
|
7306
|
+
}
|
|
7307
|
+
__name(toArray, "toArray");
|
|
7308
|
+
|
|
7309
|
+
// ../type-checks/src/get-object-tag.ts
|
|
7310
|
+
var getObjectTag = /* @__PURE__ */ __name((value) => {
|
|
7311
|
+
if (value == null) {
|
|
7312
|
+
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
7313
|
+
}
|
|
7314
|
+
return Object.prototype.toString.call(value);
|
|
7315
|
+
}, "getObjectTag");
|
|
7316
|
+
|
|
7317
|
+
// ../type-checks/src/is-plain-object.ts
|
|
7318
|
+
var isObjectLike = /* @__PURE__ */ __name((obj) => {
|
|
7319
|
+
return typeof obj === "object" && obj !== null;
|
|
7320
|
+
}, "isObjectLike");
|
|
7321
|
+
var isPlainObject = /* @__PURE__ */ __name((obj) => {
|
|
7322
|
+
if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
|
|
7323
|
+
return false;
|
|
7324
|
+
}
|
|
7325
|
+
if (Object.getPrototypeOf(obj) === null) {
|
|
7326
|
+
return true;
|
|
7327
|
+
}
|
|
7328
|
+
let proto = obj;
|
|
7329
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
7330
|
+
proto = Object.getPrototypeOf(proto);
|
|
7331
|
+
}
|
|
7332
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
7333
|
+
}, "isPlainObject");
|
|
7334
|
+
|
|
7335
|
+
// ../type-checks/src/is-object.ts
|
|
7336
|
+
var isObject = /* @__PURE__ */ __name((value) => {
|
|
7337
|
+
try {
|
|
7338
|
+
return typeof value === "object" || Boolean(value) && value?.constructor === Object || isPlainObject(value);
|
|
7339
|
+
} catch {
|
|
7340
|
+
return false;
|
|
7341
|
+
}
|
|
7342
|
+
}, "isObject");
|
|
7343
|
+
|
|
7344
|
+
// ../type-checks/src/is-string.ts
|
|
7345
|
+
var isString = /* @__PURE__ */ __name((value) => {
|
|
7346
|
+
try {
|
|
7347
|
+
return typeof value === "string";
|
|
7348
|
+
} catch {
|
|
7349
|
+
return false;
|
|
7350
|
+
}
|
|
7351
|
+
}, "isString");
|
|
7352
|
+
|
|
7353
|
+
// ../json/src/storm-json.ts
|
|
7354
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
7355
|
+
var import_node_buffer = require("buffer");
|
|
7356
|
+
var import_superjson = __toESM(require("superjson"), 1);
|
|
7357
|
+
|
|
7358
|
+
// ../json/src/utils/strip-comments.ts
|
|
7359
|
+
var singleComment = Symbol("singleComment");
|
|
7360
|
+
var multiComment = Symbol("multiComment");
|
|
7361
|
+
function stripWithoutWhitespace() {
|
|
7362
|
+
return "";
|
|
7363
|
+
}
|
|
7364
|
+
__name(stripWithoutWhitespace, "stripWithoutWhitespace");
|
|
7365
|
+
function stripWithWhitespace(value, start, end) {
|
|
7366
|
+
return value.slice(start, end).replace(/\S/g, " ");
|
|
7367
|
+
}
|
|
7368
|
+
__name(stripWithWhitespace, "stripWithWhitespace");
|
|
7369
|
+
function isEscaped(value, quotePosition) {
|
|
7370
|
+
let index = quotePosition - 1;
|
|
7371
|
+
let backslashCount = 0;
|
|
7372
|
+
while (value[index] === "\\") {
|
|
7373
|
+
index -= 1;
|
|
7374
|
+
backslashCount += 1;
|
|
7375
|
+
}
|
|
7376
|
+
return Boolean(backslashCount % 2);
|
|
7377
|
+
}
|
|
7378
|
+
__name(isEscaped, "isEscaped");
|
|
7379
|
+
function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
|
|
7380
|
+
if (typeof value !== "string") {
|
|
7381
|
+
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
|
|
7382
|
+
}
|
|
7383
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
7384
|
+
let isInsideString = false;
|
|
7385
|
+
let isInsideComment = false;
|
|
7386
|
+
let offset = 0;
|
|
7387
|
+
let buffer = "";
|
|
7388
|
+
let result = "";
|
|
7389
|
+
let commaIndex = -1;
|
|
7390
|
+
for (let index = 0; index < value.length; index++) {
|
|
7391
|
+
const currentCharacter = value[index];
|
|
7392
|
+
const nextCharacter = value[index + 1];
|
|
7393
|
+
if (!isInsideComment && currentCharacter === '"') {
|
|
7394
|
+
const escaped = isEscaped(value, index);
|
|
7395
|
+
if (!escaped) {
|
|
7396
|
+
isInsideString = !isInsideString;
|
|
7397
|
+
}
|
|
7398
|
+
}
|
|
7399
|
+
if (isInsideString) {
|
|
7400
|
+
continue;
|
|
7401
|
+
}
|
|
7402
|
+
if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
|
|
7403
|
+
buffer += value.slice(offset, index);
|
|
7404
|
+
offset = index;
|
|
7405
|
+
isInsideComment = singleComment;
|
|
7406
|
+
index++;
|
|
7407
|
+
} else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
|
|
7408
|
+
index++;
|
|
7409
|
+
isInsideComment = false;
|
|
7410
|
+
buffer += strip(value, offset, index);
|
|
7411
|
+
offset = index;
|
|
7412
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
7413
|
+
isInsideComment = false;
|
|
7414
|
+
buffer += strip(value, offset, index);
|
|
7415
|
+
offset = index;
|
|
7416
|
+
} else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
|
|
7417
|
+
buffer += value.slice(offset, index);
|
|
7418
|
+
offset = index;
|
|
7419
|
+
isInsideComment = multiComment;
|
|
7420
|
+
index++;
|
|
7421
|
+
} else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
|
|
7422
|
+
index++;
|
|
7423
|
+
isInsideComment = false;
|
|
7424
|
+
buffer += strip(value, offset, index + 1);
|
|
7425
|
+
offset = index + 1;
|
|
7426
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
7427
|
+
if (commaIndex !== -1) {
|
|
7428
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
7429
|
+
buffer += value.slice(offset, index);
|
|
7430
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
7431
|
+
buffer = "";
|
|
7432
|
+
offset = index;
|
|
7433
|
+
commaIndex = -1;
|
|
7434
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
7435
|
+
buffer += value.slice(offset, index);
|
|
7436
|
+
offset = index;
|
|
7437
|
+
commaIndex = -1;
|
|
7438
|
+
}
|
|
7439
|
+
} else if (currentCharacter === ",") {
|
|
7440
|
+
result += buffer + value.slice(offset, index);
|
|
7441
|
+
buffer = "";
|
|
7442
|
+
offset = index;
|
|
7443
|
+
commaIndex = index;
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7446
|
+
}
|
|
7447
|
+
return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
|
|
7448
|
+
}
|
|
7449
|
+
__name(stripComments, "stripComments");
|
|
7450
|
+
|
|
7451
|
+
// ../json/src/utils/parse.ts
|
|
7452
|
+
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*:/;
|
|
7453
|
+
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*:/;
|
|
7454
|
+
var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
7455
|
+
function jsonParseTransform(key, value) {
|
|
7456
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
7457
|
+
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
7458
|
+
return;
|
|
7459
|
+
}
|
|
7460
|
+
return value;
|
|
7461
|
+
}
|
|
7462
|
+
__name(jsonParseTransform, "jsonParseTransform");
|
|
7463
|
+
function parse(value, options = {}) {
|
|
7464
|
+
if (typeof value !== "string") {
|
|
7465
|
+
return value;
|
|
7466
|
+
}
|
|
7467
|
+
let stripped = stripComments(value);
|
|
7468
|
+
if (stripped[0] === '"' && stripped[stripped.length - 1] === '"' && !stripped.includes("\\")) {
|
|
7469
|
+
return stripped.slice(1, -1);
|
|
7470
|
+
}
|
|
7471
|
+
stripped = stripped.trim();
|
|
7472
|
+
if (stripped.length <= 9) {
|
|
7473
|
+
switch (stripped.toLowerCase()) {
|
|
7474
|
+
case "true": {
|
|
7475
|
+
return true;
|
|
7476
|
+
}
|
|
7477
|
+
case "false": {
|
|
7478
|
+
return false;
|
|
7479
|
+
}
|
|
7480
|
+
case "undefined": {
|
|
7481
|
+
return void 0;
|
|
7482
|
+
}
|
|
7483
|
+
case "null": {
|
|
7484
|
+
return null;
|
|
7485
|
+
}
|
|
7486
|
+
case "nan": {
|
|
7487
|
+
return Number.NaN;
|
|
7488
|
+
}
|
|
7489
|
+
case "infinity": {
|
|
7490
|
+
return Number.POSITIVE_INFINITY;
|
|
7491
|
+
}
|
|
7492
|
+
case "-infinity": {
|
|
7493
|
+
return Number.NEGATIVE_INFINITY;
|
|
7494
|
+
}
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
if (!JsonSigRx.test(stripped)) {
|
|
7498
|
+
if (options.strict) {
|
|
7499
|
+
throw new Error("Invalid JSON");
|
|
7500
|
+
}
|
|
7501
|
+
return stripped;
|
|
7502
|
+
}
|
|
7503
|
+
try {
|
|
7504
|
+
if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
|
|
7505
|
+
if (options.strict) {
|
|
7506
|
+
throw new Error("Possible prototype pollution");
|
|
7507
|
+
}
|
|
7508
|
+
return JSON.parse(stripped, jsonParseTransform);
|
|
7509
|
+
}
|
|
7510
|
+
return JSON.parse(stripped);
|
|
7511
|
+
} catch (error) {
|
|
7512
|
+
if (options.strict) {
|
|
7513
|
+
throw error;
|
|
7514
|
+
}
|
|
7515
|
+
return value;
|
|
7516
|
+
}
|
|
7517
|
+
}
|
|
7518
|
+
__name(parse, "parse");
|
|
7519
|
+
|
|
7520
|
+
// ../json/src/utils/parse-error.ts
|
|
7521
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
7522
|
+
var import_lines_and_columns = require("lines-and-columns");
|
|
7523
|
+
|
|
7524
|
+
// ../json/src/utils/code-frames.ts
|
|
7525
|
+
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
7526
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
7527
|
+
const startLoc = {
|
|
7528
|
+
column: 0,
|
|
7529
|
+
line: -1,
|
|
7530
|
+
...loc.start
|
|
7531
|
+
};
|
|
7532
|
+
const endLoc = {
|
|
7533
|
+
...startLoc,
|
|
7534
|
+
...loc.end
|
|
7535
|
+
};
|
|
7536
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
7537
|
+
const startLine = startLoc.line;
|
|
7538
|
+
const startColumn = startLoc.column;
|
|
7539
|
+
const endLine = endLoc.line;
|
|
7540
|
+
const endColumn = endLoc.column;
|
|
7541
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
7542
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
7543
|
+
if (startLine === -1) {
|
|
7544
|
+
start = 0;
|
|
7545
|
+
}
|
|
7546
|
+
if (endLine === -1) {
|
|
7547
|
+
end = source.length;
|
|
7548
|
+
}
|
|
7549
|
+
const lineDiff = endLine - startLine;
|
|
7550
|
+
const markerLines = {};
|
|
7551
|
+
if (lineDiff) {
|
|
7552
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
7553
|
+
const lineNumber = i + startLine;
|
|
7554
|
+
if (!startColumn) {
|
|
7555
|
+
markerLines[lineNumber] = true;
|
|
7556
|
+
} else if (i === 0) {
|
|
7557
|
+
const sourceLength = source[lineNumber - 1]?.length ?? 0;
|
|
7558
|
+
markerLines[lineNumber] = [
|
|
7559
|
+
startColumn,
|
|
7560
|
+
sourceLength - startColumn + 1
|
|
7561
|
+
];
|
|
7562
|
+
} else if (i === lineDiff) {
|
|
7563
|
+
markerLines[lineNumber] = [
|
|
7564
|
+
0,
|
|
7565
|
+
endColumn
|
|
7566
|
+
];
|
|
7567
|
+
} else {
|
|
7568
|
+
const sourceLength = source[lineNumber - i]?.length ?? 0;
|
|
7569
|
+
markerLines[lineNumber] = [
|
|
7570
|
+
0,
|
|
7571
|
+
sourceLength
|
|
7572
|
+
];
|
|
7573
|
+
}
|
|
7574
|
+
}
|
|
7575
|
+
} else if (startColumn === endColumn) {
|
|
7576
|
+
markerLines[startLine] = startColumn ? [
|
|
7577
|
+
startColumn,
|
|
7578
|
+
0
|
|
7579
|
+
] : true;
|
|
7580
|
+
} else {
|
|
7581
|
+
markerLines[startLine] = [
|
|
7582
|
+
startColumn,
|
|
7583
|
+
endColumn - startColumn
|
|
7584
|
+
];
|
|
7585
|
+
}
|
|
7586
|
+
return {
|
|
7587
|
+
start,
|
|
7588
|
+
end,
|
|
7589
|
+
markerLines
|
|
7590
|
+
};
|
|
7591
|
+
}
|
|
7592
|
+
__name(getMarkerLines, "getMarkerLines");
|
|
7593
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
7594
|
+
const lines = rawLines.split(NEWLINE);
|
|
7595
|
+
const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
|
|
7596
|
+
const numberMaxWidth = String(end).length;
|
|
7597
|
+
const highlightedLines = opts.highlight ? opts.highlight(rawLines) : rawLines;
|
|
7598
|
+
const frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
|
|
7599
|
+
const number = start + 1 + index;
|
|
7600
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
7601
|
+
const gutter = ` ${paddedNumber} | `;
|
|
7602
|
+
const hasMarker = Boolean(markerLines[number] ?? false);
|
|
7603
|
+
if (hasMarker) {
|
|
7604
|
+
let markerLine = "";
|
|
7605
|
+
if (Array.isArray(hasMarker)) {
|
|
7606
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
7607
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
7608
|
+
markerLine = [
|
|
7609
|
+
"\n ",
|
|
7610
|
+
gutter.replace(/\d/g, " "),
|
|
7611
|
+
markerSpacing,
|
|
7612
|
+
"^".repeat(numberOfMarkers)
|
|
7613
|
+
].join("");
|
|
7614
|
+
}
|
|
7615
|
+
return [
|
|
7616
|
+
">",
|
|
7617
|
+
gutter,
|
|
7618
|
+
line,
|
|
7619
|
+
markerLine
|
|
7620
|
+
].join("");
|
|
7621
|
+
}
|
|
7622
|
+
return ` ${gutter}${line}`;
|
|
7623
|
+
}).join("\n");
|
|
7624
|
+
return frame;
|
|
7625
|
+
}
|
|
7626
|
+
__name(codeFrameColumns, "codeFrameColumns");
|
|
7627
|
+
|
|
7628
|
+
// ../json/src/utils/parse-error.ts
|
|
7629
|
+
function formatParseError(input, parseError) {
|
|
7630
|
+
const { error, offset, length } = parseError;
|
|
7631
|
+
const result = new import_lines_and_columns.LinesAndColumns(input).locationForIndex(offset);
|
|
7632
|
+
let line = result?.line ?? 0;
|
|
7633
|
+
let column = result?.column ?? 0;
|
|
7634
|
+
line++;
|
|
7635
|
+
column++;
|
|
7636
|
+
return `${(0, import_jsonc_parser.printParseErrorCode)(error)} in JSON at ${line}:${column}
|
|
7637
|
+
${codeFrameColumns(input, {
|
|
7638
|
+
start: {
|
|
7639
|
+
line,
|
|
7640
|
+
column
|
|
7641
|
+
},
|
|
7642
|
+
end: {
|
|
7643
|
+
line,
|
|
7644
|
+
column: column + length
|
|
7645
|
+
}
|
|
7646
|
+
})}
|
|
7647
|
+
`;
|
|
7648
|
+
}
|
|
7649
|
+
__name(formatParseError, "formatParseError");
|
|
7650
|
+
|
|
7651
|
+
// ../type-checks/src/is-number.ts
|
|
7652
|
+
var isNumber = /* @__PURE__ */ __name((value) => {
|
|
7653
|
+
try {
|
|
7654
|
+
return value instanceof Number || typeof value === "number" || Number(value) === value;
|
|
7655
|
+
} catch {
|
|
7656
|
+
return false;
|
|
7657
|
+
}
|
|
7658
|
+
}, "isNumber");
|
|
7659
|
+
|
|
7660
|
+
// ../type-checks/src/is-undefined.ts
|
|
7661
|
+
var isUndefined = /* @__PURE__ */ __name((value) => {
|
|
7662
|
+
return value === void 0;
|
|
7663
|
+
}, "isUndefined");
|
|
7664
|
+
|
|
7665
|
+
// ../json/src/utils/stringify.ts
|
|
7666
|
+
var invalidKeyChars = [
|
|
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
|
+
"{",
|
|
7692
|
+
"}",
|
|
7693
|
+
"[",
|
|
7694
|
+
"]",
|
|
7695
|
+
"(",
|
|
7696
|
+
")",
|
|
7697
|
+
"<",
|
|
7698
|
+
">"
|
|
7699
|
+
];
|
|
7700
|
+
var stringify = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
7701
|
+
const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
|
|
7702
|
+
switch (value) {
|
|
7703
|
+
case null: {
|
|
7704
|
+
return "null";
|
|
7705
|
+
}
|
|
7706
|
+
case void 0: {
|
|
7707
|
+
return '"undefined"';
|
|
7580
7708
|
}
|
|
7581
|
-
case
|
|
7582
|
-
|
|
7583
|
-
break;
|
|
7709
|
+
case true: {
|
|
7710
|
+
return "true";
|
|
7584
7711
|
}
|
|
7585
|
-
case
|
|
7586
|
-
|
|
7587
|
-
p = getPointer(0, value);
|
|
7588
|
-
break;
|
|
7712
|
+
case false: {
|
|
7713
|
+
return "false";
|
|
7589
7714
|
}
|
|
7590
|
-
|
|
7591
|
-
|
|
7715
|
+
case Number.POSITIVE_INFINITY: {
|
|
7716
|
+
return "infinity";
|
|
7717
|
+
}
|
|
7718
|
+
case Number.NEGATIVE_INFINITY: {
|
|
7719
|
+
return "-infinity";
|
|
7592
7720
|
}
|
|
7593
7721
|
}
|
|
7594
|
-
|
|
7595
|
-
|
|
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
|
-
}
|
|
7603
|
-
__name(createValue, "createValue");
|
|
7604
|
-
function createNestedNodeProperty(node) {
|
|
7605
|
-
const name = getDisplayNamePrefix(node);
|
|
7606
|
-
const initializer = getFullClassName(node);
|
|
7607
|
-
return `static readonly ${name} = ${initializer};`;
|
|
7608
|
-
}
|
|
7609
|
-
__name(createNestedNodeProperty, "createNestedNodeProperty");
|
|
7610
|
-
function generateInterfaceNode(ctx, node) {
|
|
7611
|
-
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
7612
|
-
const fullClassName = getFullClassName(node);
|
|
7613
|
-
const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
|
|
7614
|
-
const nodeId = node.id;
|
|
7615
|
-
const nodeIdHex = nodeId.toString(16);
|
|
7616
|
-
const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
|
|
7617
|
-
const members = [];
|
|
7618
|
-
members.push(
|
|
7619
|
-
...consts.map((node2) => {
|
|
7620
|
-
const name = c2s(getDisplayNamePrefix(node2));
|
|
7621
|
-
const value = createValue(node2.const.value);
|
|
7622
|
-
return `static readonly ${name} = ${value}`;
|
|
7623
|
-
}),
|
|
7624
|
-
...nestedNodes.map((node2) => createNestedNodeProperty(node2)),
|
|
7625
|
-
`static readonly Client = ${fullClassName}$Client;
|
|
7626
|
-
static readonly Server = ${fullClassName}$Server;
|
|
7627
|
-
public static override readonly _capnp = {
|
|
7628
|
-
displayName: "${displayNamePrefix}",
|
|
7629
|
-
id: "${nodeIdHex}",
|
|
7630
|
-
size: new $.ObjectSize(0, 0),
|
|
7631
|
-
}
|
|
7632
|
-
public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
7633
|
-
);
|
|
7634
|
-
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
7635
|
-
const classCode = `
|
|
7636
|
-
${docComment}
|
|
7637
|
-
export class ${fullClassName} extends $.Interface {
|
|
7638
|
-
${members.join("\n")}
|
|
7639
|
-
}`;
|
|
7640
|
-
generateInterfaceClasses(ctx, node);
|
|
7641
|
-
ctx.codeParts.push(classCode);
|
|
7642
|
-
}
|
|
7643
|
-
__name(generateInterfaceNode, "generateInterfaceNode");
|
|
7644
|
-
function generateNode(ctx, node) {
|
|
7645
|
-
const nodeId = node.id;
|
|
7646
|
-
const nodeIdHex = nodeId.toString(16);
|
|
7647
|
-
if (ctx.generatedNodeIds.has(nodeIdHex)) {
|
|
7648
|
-
return;
|
|
7649
|
-
}
|
|
7650
|
-
ctx.generatedNodeIds.add(nodeIdHex);
|
|
7651
|
-
const nestedNodes = node.nestedNodes.map((node2) => lookupNode(ctx, node2));
|
|
7652
|
-
for (const nestedNode of nestedNodes) {
|
|
7653
|
-
generateNode(ctx, nestedNode);
|
|
7722
|
+
if (Array.isArray(value)) {
|
|
7723
|
+
return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
|
|
7654
7724
|
}
|
|
7655
|
-
|
|
7656
|
-
(
|
|
7657
|
-
);
|
|
7658
|
-
for (const groupNode of groupNodes) {
|
|
7659
|
-
generateNode(ctx, groupNode);
|
|
7725
|
+
if (value instanceof Uint8Array) {
|
|
7726
|
+
return value.toString();
|
|
7660
7727
|
}
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
generateStructNode(ctx, node);
|
|
7665
|
-
break;
|
|
7666
|
-
}
|
|
7667
|
-
case Node.CONST: {
|
|
7668
|
-
break;
|
|
7669
|
-
}
|
|
7670
|
-
case Node.ENUM: {
|
|
7671
|
-
generateEnumNode(
|
|
7672
|
-
ctx,
|
|
7673
|
-
getFullClassName(node),
|
|
7674
|
-
node,
|
|
7675
|
-
node.enum.enumerants.toArray()
|
|
7676
|
-
);
|
|
7677
|
-
break;
|
|
7678
|
-
}
|
|
7679
|
-
case Node.INTERFACE: {
|
|
7680
|
-
generateInterfaceNode(ctx, node);
|
|
7681
|
-
break;
|
|
7728
|
+
switch (typeof value) {
|
|
7729
|
+
case "number": {
|
|
7730
|
+
return `${value}`;
|
|
7682
7731
|
}
|
|
7683
|
-
case
|
|
7684
|
-
|
|
7732
|
+
case "string": {
|
|
7733
|
+
return JSON.stringify(value);
|
|
7685
7734
|
}
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
format(
|
|
7690
|
-
GEN_NODE_UNKNOWN_TYPE,
|
|
7691
|
-
nodeType
|
|
7692
|
-
/* s.Node_Which[whichNode] */
|
|
7693
|
-
)
|
|
7694
|
-
);
|
|
7735
|
+
case "object": {
|
|
7736
|
+
const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
|
|
7737
|
+
return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
|
|
7695
7738
|
}
|
|
7739
|
+
default:
|
|
7740
|
+
return "null";
|
|
7696
7741
|
}
|
|
7697
|
-
}
|
|
7698
|
-
|
|
7699
|
-
|
|
7742
|
+
}, "stringify");
|
|
7743
|
+
|
|
7744
|
+
// ../json/src/storm-json.ts
|
|
7745
|
+
var StormJSON = class _StormJSON extends import_superjson.default {
|
|
7700
7746
|
static {
|
|
7701
|
-
__name(this, "
|
|
7747
|
+
__name(this, "StormJSON");
|
|
7702
7748
|
}
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7749
|
+
static #instance;
|
|
7750
|
+
static get instance() {
|
|
7751
|
+
if (!_StormJSON.#instance) {
|
|
7752
|
+
_StormJSON.#instance = new _StormJSON();
|
|
7753
|
+
}
|
|
7754
|
+
return _StormJSON.#instance;
|
|
7708
7755
|
}
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7756
|
+
/**
|
|
7757
|
+
* Deserialize the given value with superjson using the given metadata
|
|
7758
|
+
*/
|
|
7759
|
+
static deserialize(payload) {
|
|
7760
|
+
return _StormJSON.instance.deserialize(payload);
|
|
7714
7761
|
}
|
|
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()";
|
|
7762
|
+
/**
|
|
7763
|
+
* Serialize the given value with superjson
|
|
7764
|
+
*/
|
|
7765
|
+
static serialize(object) {
|
|
7766
|
+
return _StormJSON.instance.serialize(object);
|
|
7726
7767
|
}
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
ctx.codeParts.push(`import * as $ from '${importPath}';`);
|
|
7750
|
-
}
|
|
7751
|
-
__name(generateCapnpImport, "generateCapnpImport");
|
|
7752
|
-
function generateNestedImports(ctx) {
|
|
7753
|
-
for (const imp of ctx.imports) {
|
|
7754
|
-
const { name } = imp;
|
|
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
|
-
}
|
|
7768
|
+
/**
|
|
7769
|
+
* Parse the given string value with superjson using the given metadata
|
|
7770
|
+
*
|
|
7771
|
+
* @param value - The string value to parse
|
|
7772
|
+
* @returns The parsed data
|
|
7773
|
+
*/
|
|
7774
|
+
static parse(value) {
|
|
7775
|
+
return parse(value);
|
|
7776
|
+
}
|
|
7777
|
+
/**
|
|
7778
|
+
* Serializes the given data to a JSON string.
|
|
7779
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
7780
|
+
*
|
|
7781
|
+
* @param value - Object which should be serialized to JSON
|
|
7782
|
+
* @param _options - JSON serialize options
|
|
7783
|
+
* @returns the formatted JSON representation of the object
|
|
7784
|
+
*/
|
|
7785
|
+
static stringify(value, _options) {
|
|
7786
|
+
const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
7787
|
+
let result = value;
|
|
7788
|
+
if (customTransformer && customTransformer.isApplicable(value)) {
|
|
7789
|
+
result = customTransformer.serialize(result);
|
|
7763
7790
|
}
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7791
|
+
return stringify(result);
|
|
7792
|
+
}
|
|
7793
|
+
/**
|
|
7794
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
7795
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
7796
|
+
*
|
|
7797
|
+
* @param strData - JSON content as string
|
|
7798
|
+
* @param options - JSON parse options
|
|
7799
|
+
* @returns Object the JSON content represents
|
|
7800
|
+
*/
|
|
7801
|
+
static parseJson(strData, options) {
|
|
7802
|
+
try {
|
|
7803
|
+
if (options?.expectComments === false) {
|
|
7804
|
+
return _StormJSON.instance.parse(strData);
|
|
7769
7805
|
}
|
|
7770
|
-
|
|
7771
|
-
}).sort().join(", ");
|
|
7772
|
-
if (imports.length === 0) {
|
|
7773
|
-
continue;
|
|
7806
|
+
} catch {
|
|
7774
7807
|
}
|
|
7775
|
-
|
|
7808
|
+
const errors = [];
|
|
7809
|
+
const opts = {
|
|
7810
|
+
allowTrailingComma: true,
|
|
7811
|
+
...options
|
|
7812
|
+
};
|
|
7813
|
+
const result = (0, import_jsonc_parser2.parse)(strData, errors, opts);
|
|
7814
|
+
if (errors.length > 0 && errors[0]) {
|
|
7815
|
+
throw new Error(formatParseError(strData, errors[0]));
|
|
7816
|
+
}
|
|
7817
|
+
return result;
|
|
7776
7818
|
}
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
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);
|
|
7819
|
+
/**
|
|
7820
|
+
* Register a custom schema with superjson
|
|
7821
|
+
*
|
|
7822
|
+
* @param name - The name of the schema
|
|
7823
|
+
* @param serialize - The function to serialize the schema
|
|
7824
|
+
* @param deserialize - The function to deserialize the schema
|
|
7825
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
7826
|
+
*/
|
|
7827
|
+
static register(name, serialize, deserialize, isApplicable) {
|
|
7828
|
+
_StormJSON.instance.registerCustom({
|
|
7829
|
+
isApplicable,
|
|
7830
|
+
serialize,
|
|
7831
|
+
deserialize
|
|
7832
|
+
}, name);
|
|
7797
7833
|
}
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7834
|
+
/**
|
|
7835
|
+
* Register a class with superjson
|
|
7836
|
+
*
|
|
7837
|
+
* @param classConstructor - The class constructor to register
|
|
7838
|
+
*/
|
|
7839
|
+
static registerClass(classConstructor, options) {
|
|
7840
|
+
_StormJSON.instance.registerClass(classConstructor, {
|
|
7841
|
+
identifier: isString(options) ? options : options?.identifier || classConstructor.name,
|
|
7842
|
+
allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : [
|
|
7843
|
+
"__typename"
|
|
7844
|
+
]
|
|
7845
|
+
});
|
|
7803
7846
|
}
|
|
7804
|
-
|
|
7805
|
-
|
|
7847
|
+
constructor() {
|
|
7848
|
+
super({
|
|
7849
|
+
dedupe: true
|
|
7850
|
+
});
|
|
7806
7851
|
}
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7852
|
+
};
|
|
7853
|
+
StormJSON.instance.registerCustom({
|
|
7854
|
+
isApplicable: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.isBuffer(v), "isApplicable"),
|
|
7855
|
+
serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
|
|
7856
|
+
deserialize: /* @__PURE__ */ __name((v) => import_node_buffer.Buffer.from(v, "base64"), "deserialize")
|
|
7857
|
+
}, "Bytes");
|
|
7858
|
+
|
|
7859
|
+
// ../type-checks/src/is-error.ts
|
|
7860
|
+
var isError = /* @__PURE__ */ __name((obj) => {
|
|
7861
|
+
if (!isObject(obj)) {
|
|
7862
|
+
return false;
|
|
7863
|
+
}
|
|
7864
|
+
const tag = getObjectTag(obj);
|
|
7865
|
+
return tag === "[object Error]" || tag === "[object DOMException]" || typeof obj?.message === "string" && typeof obj?.name === "string" && !isPlainObject(obj);
|
|
7866
|
+
}, "isError");
|
|
7867
|
+
|
|
7868
|
+
// ../fs/src/read-file.ts
|
|
7869
|
+
var import_node_fs4 = require("fs");
|
|
7870
|
+
var import_promises3 = require("fs/promises");
|
|
7871
|
+
var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
|
|
7872
|
+
try {
|
|
7873
|
+
if (!filePath) {
|
|
7874
|
+
throw new Error("No file path provided to read data");
|
|
7812
7875
|
}
|
|
7876
|
+
return await (0, import_promises3.readFile)(filePath, {
|
|
7877
|
+
encoding: "utf8"
|
|
7878
|
+
});
|
|
7879
|
+
} catch {
|
|
7880
|
+
throw new Error("An error occurred writing data to file");
|
|
7813
7881
|
}
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
(n) => lookupNode(ctx, n)
|
|
7826
|
-
);
|
|
7827
|
-
for (const node of nestedNodes) {
|
|
7828
|
-
generateNode(ctx, node);
|
|
7882
|
+
}, "readFile");
|
|
7883
|
+
|
|
7884
|
+
// ../fs/src/write-file.ts
|
|
7885
|
+
var import_node_fs5 = require("fs");
|
|
7886
|
+
var import_promises4 = require("fs/promises");
|
|
7887
|
+
|
|
7888
|
+
// ../fs/src/json.ts
|
|
7889
|
+
async function readJsonFile(path, options) {
|
|
7890
|
+
const content = await readFile2(path);
|
|
7891
|
+
if (options) {
|
|
7892
|
+
options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
|
|
7829
7893
|
}
|
|
7830
|
-
|
|
7831
|
-
|
|
7894
|
+
try {
|
|
7895
|
+
return StormJSON.parseJson(content, options);
|
|
7896
|
+
} catch (error) {
|
|
7897
|
+
if (isError(error)) {
|
|
7898
|
+
error.message = error.message.replace("JSON", path);
|
|
7899
|
+
throw error;
|
|
7900
|
+
}
|
|
7901
|
+
throw new Error(`Failed to parse JSON: ${path}`);
|
|
7832
7902
|
}
|
|
7833
|
-
const sourceFile = import_typescript.default.createSourceFile(
|
|
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);
|
|
7841
7903
|
}
|
|
7842
|
-
__name(
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7904
|
+
__name(readJsonFile, "readJsonFile");
|
|
7905
|
+
|
|
7906
|
+
// ../fs/src/list-files.ts
|
|
7907
|
+
var import_defu = __toESM(require("defu"), 1);
|
|
7908
|
+
var import_glob = require("glob");
|
|
7909
|
+
var DEFAULT_OPTIONS = {
|
|
7910
|
+
dot: true
|
|
7911
|
+
};
|
|
7912
|
+
async function list(filesGlob, options) {
|
|
7913
|
+
return (0, import_glob.glob)(filesGlob, (0, import_defu.default)(options ?? {}, DEFAULT_OPTIONS));
|
|
7914
|
+
}
|
|
7915
|
+
__name(list, "list");
|
|
7916
|
+
async function listFiles(filesGlob, options) {
|
|
7917
|
+
const result = (await list(filesGlob, (0, import_defu.default)({
|
|
7918
|
+
withFileTypes: true
|
|
7919
|
+
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
7920
|
+
if (!options?.withFileTypes) {
|
|
7921
|
+
return result.map((file) => file.fullpath());
|
|
7846
7922
|
}
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
const
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
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}`);
|
|
7923
|
+
return result;
|
|
7924
|
+
}
|
|
7925
|
+
__name(listFiles, "listFiles");
|
|
7926
|
+
|
|
7927
|
+
// src/helpers.ts
|
|
7928
|
+
var import_typescript3 = require("typescript");
|
|
7929
|
+
async function resolveOptions(options) {
|
|
7930
|
+
const tsconfigPath = options.tsconfigPath ? options.tsconfigPath.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : void 0;
|
|
7931
|
+
const schemas = toArray(options.schemas ? Array.isArray(options.schemas) ? options.schemas.map((schema) => schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot)) : options.schemas : joinPaths(options.projectRoot, "schemas/**/*.capnp"));
|
|
7932
|
+
let resolvedTsconfig;
|
|
7933
|
+
if (options.tsconfig) {
|
|
7934
|
+
resolvedTsconfig = options.tsconfig;
|
|
7935
|
+
} else {
|
|
7936
|
+
if (!tsconfigPath || !existsSync(tsconfigPath)) {
|
|
7937
|
+
const errorMessage = tsconfigPath ? `\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.";
|
|
7938
|
+
(0, import_console.writeFatal)(errorMessage, {
|
|
7939
|
+
logLevel: "all"
|
|
7940
|
+
});
|
|
7941
|
+
throw new Error(errorMessage);
|
|
7942
|
+
}
|
|
7943
|
+
const tsconfigFile = await readJsonFile(tsconfigPath);
|
|
7944
|
+
resolvedTsconfig = (0, import_typescript3.parseJsonConfigFileContent)(tsconfigFile, import_typescript3.sys, findFilePath(tsconfigPath));
|
|
7945
|
+
if (!resolvedTsconfig) {
|
|
7946
|
+
const errorMessage = `\u2716 The specified TypeScript configuration file "${tsconfigPath}" is invalid. Please provide a valid configuration.`;
|
|
7947
|
+
(0, import_console.writeFatal)(errorMessage, {
|
|
7948
|
+
logLevel: "all"
|
|
7949
|
+
});
|
|
7950
|
+
throw new Error(errorMessage);
|
|
7951
|
+
}
|
|
7952
|
+
resolvedTsconfig.options.configFilePath = tsconfigPath;
|
|
7953
|
+
resolvedTsconfig.options.noImplicitOverride = false;
|
|
7954
|
+
resolvedTsconfig.options.noUnusedLocals = false;
|
|
7955
|
+
resolvedTsconfig.options.noUnusedParameters = false;
|
|
7956
|
+
}
|
|
7957
|
+
const resolvedSchemas = [];
|
|
7958
|
+
for (const schema of schemas) {
|
|
7959
|
+
if (!schema || !schema.includes("*") && !existsSync(schema)) {
|
|
7960
|
+
if (schemas.length <= 1) {
|
|
7961
|
+
throw new Error(`\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`);
|
|
7898
7962
|
}
|
|
7963
|
+
} else {
|
|
7964
|
+
resolvedSchemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
|
|
7899
7965
|
}
|
|
7900
|
-
throw new Error(GEN_TS_EMIT_FAILED);
|
|
7901
7966
|
}
|
|
7967
|
+
if (resolvedSchemas.length === 0 || !resolvedSchemas[0]) {
|
|
7968
|
+
(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.`, {
|
|
7969
|
+
logLevel: "all"
|
|
7970
|
+
});
|
|
7971
|
+
return null;
|
|
7972
|
+
}
|
|
7973
|
+
resolvedTsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(tsconfigPath ? findFilePath(tsconfigPath) : options.projectRoot, joinPaths(options.workspaceRoot, resolvedSchemas[0].endsWith(".capnp") ? findFilePath(resolvedSchemas[0]) : resolvedSchemas[0])));
|
|
7974
|
+
return {
|
|
7975
|
+
workspaceRoot: options.workspaceRoot,
|
|
7976
|
+
projectRoot: options.projectRoot,
|
|
7977
|
+
schemas: resolvedSchemas,
|
|
7978
|
+
js: options.js ?? false,
|
|
7979
|
+
ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
|
|
7980
|
+
dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true),
|
|
7981
|
+
tsconfig: resolvedTsconfig
|
|
7982
|
+
};
|
|
7902
7983
|
}
|
|
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");
|
|
7984
|
+
__name(resolveOptions, "resolveOptions");
|
|
7907
7985
|
|
|
7908
7986
|
// src/compile.ts
|
|
7909
|
-
var import_node_buffer2 = require("buffer");
|
|
7910
|
-
var import_node_child_process = require("child_process");
|
|
7911
7987
|
async function capnpc(options) {
|
|
7912
7988
|
const { output, tsconfig, schemas = [], tty } = options;
|
|
7913
7989
|
let dataBuf = import_node_buffer2.Buffer.alloc(0);
|
|
@@ -7952,14 +8028,14 @@ async function capnpc(options) {
|
|
|
7952
8028
|
ts: options.ts ?? true,
|
|
7953
8029
|
js: false,
|
|
7954
8030
|
dts: false,
|
|
7955
|
-
tsconfig: tsconfig
|
|
8031
|
+
tsconfig: tsconfig.options
|
|
7956
8032
|
});
|
|
7957
8033
|
}
|
|
7958
8034
|
__name(capnpc, "capnpc");
|
|
7959
8035
|
|
|
7960
8036
|
// bin/capnpc.ts
|
|
7961
8037
|
function createProgram() {
|
|
7962
|
-
(0,
|
|
8038
|
+
(0, import_console3.writeInfo)("\u26A1 Running Storm Cap'n Proto Compiler Tools", {
|
|
7963
8039
|
logLevel: "all"
|
|
7964
8040
|
});
|
|
7965
8041
|
const root = (0, import_utilities.findWorkspaceRootSafe)(process.cwd());
|
|
@@ -7998,54 +8074,30 @@ function createProgram() {
|
|
|
7998
8074
|
}
|
|
7999
8075
|
__name(createProgram, "createProgram");
|
|
8000
8076
|
async function compileAction(options) {
|
|
8001
|
-
const
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
(
|
|
8006
|
-
|
|
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"
|
|
8077
|
+
const resolvedOptions = await resolveOptions({
|
|
8078
|
+
...options,
|
|
8079
|
+
projectRoot: options.projectRoot,
|
|
8080
|
+
tsconfig: void 0,
|
|
8081
|
+
tsconfigPath: options.tsconfig || joinPaths(options.projectRoot, "tsconfig.json"),
|
|
8082
|
+
schemas: options.schema
|
|
8019
8083
|
});
|
|
8020
|
-
|
|
8021
|
-
|
|
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.`, {
|
|
8084
|
+
if (!resolvedOptions) {
|
|
8085
|
+
(0, import_console3.writeWarning)("\u2716 Unable to resolve Cap'n Proto compiler options - the program will terminate", {
|
|
8031
8086
|
logLevel: "all"
|
|
8032
8087
|
});
|
|
8033
8088
|
return;
|
|
8034
8089
|
}
|
|
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)
|
|
8090
|
+
(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.options.outDir}...`, {
|
|
8091
|
+
logLevel: "all"
|
|
8041
8092
|
});
|
|
8093
|
+
const result = await capnpc(resolvedOptions);
|
|
8042
8094
|
if (result.files.size === 0) {
|
|
8043
|
-
(0,
|
|
8095
|
+
(0, import_console3.writeWarning)("\u26A0\uFE0F No files were generated. Please check your schema files.", {
|
|
8044
8096
|
logLevel: "all"
|
|
8045
8097
|
});
|
|
8046
8098
|
return;
|
|
8047
8099
|
}
|
|
8048
|
-
(0,
|
|
8100
|
+
(0, import_console3.writeInfo)(`\u{1F4CB} Writing ${result.files.size} generated files to disk...`, {
|
|
8049
8101
|
logLevel: "all"
|
|
8050
8102
|
});
|
|
8051
8103
|
for (const [fileName, content] of result.files) {
|
|
@@ -8068,7 +8120,7 @@ async function compileAction(options) {
|
|
|
8068
8120
|
content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
|
|
8069
8121
|
);
|
|
8070
8122
|
}
|
|
8071
|
-
(0,
|
|
8123
|
+
(0, import_console3.writeSuccess)("\u26A1 Storm Cap'n Proto Compiler completed successfully.", {
|
|
8072
8124
|
logLevel: "all"
|
|
8073
8125
|
});
|
|
8074
8126
|
}
|
|
@@ -8080,7 +8132,7 @@ void (async () => {
|
|
|
8080
8132
|
await program.parseAsync(process.argv);
|
|
8081
8133
|
(0, import_utilities.exitWithSuccess)();
|
|
8082
8134
|
} catch (error) {
|
|
8083
|
-
(0,
|
|
8135
|
+
(0, import_console3.writeFatal)(`\u2716 A fatal error occurred while running the Storm Cap'n Proto compiler tool:
|
|
8084
8136
|
${error?.message ? error?.name ? `[${error.name}]: ${error.message}` : error.message : JSON.stringify(error)}${error?.stack ? `
|
|
8085
8137
|
|
|
8086
8138
|
Stack Trace: ${error.stack}` : ""}`, {
|