@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.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
4
|
|
|
5
5
|
// bin/capnpc.ts
|
|
6
|
-
import { writeFatal, writeInfo, writeSuccess, writeWarning } from "@storm-software/config-tools/logger/console";
|
|
6
|
+
import { writeFatal as writeFatal2, writeInfo, writeSuccess, writeWarning as writeWarning3 } from "@storm-software/config-tools/logger/console";
|
|
7
7
|
import { exitWithError, exitWithSuccess, findWorkspaceRootSafe as findWorkspaceRootSafe2, handleProcess } from "@storm-software/config-tools/utilities";
|
|
8
8
|
|
|
9
9
|
// ../path/src/exists.ts
|
|
@@ -30,1560 +30,944 @@ async function createDirectory(path) {
|
|
|
30
30
|
}
|
|
31
31
|
__name(createDirectory, "createDirectory");
|
|
32
32
|
|
|
33
|
-
// ../type-checks/src/get-object-tag.ts
|
|
34
|
-
var getObjectTag = /* @__PURE__ */ __name((value) => {
|
|
35
|
-
if (value == null) {
|
|
36
|
-
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
37
|
-
}
|
|
38
|
-
return Object.prototype.toString.call(value);
|
|
39
|
-
}, "getObjectTag");
|
|
40
|
-
|
|
41
|
-
// ../type-checks/src/is-plain-object.ts
|
|
42
|
-
var isObjectLike = /* @__PURE__ */ __name((obj) => {
|
|
43
|
-
return typeof obj === "object" && obj !== null;
|
|
44
|
-
}, "isObjectLike");
|
|
45
|
-
var isPlainObject = /* @__PURE__ */ __name((obj) => {
|
|
46
|
-
if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (Object.getPrototypeOf(obj) === null) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
let proto = obj;
|
|
53
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
54
|
-
proto = Object.getPrototypeOf(proto);
|
|
55
|
-
}
|
|
56
|
-
return Object.getPrototypeOf(obj) === proto;
|
|
57
|
-
}, "isPlainObject");
|
|
58
|
-
|
|
59
|
-
// ../type-checks/src/is-object.ts
|
|
60
|
-
var isObject = /* @__PURE__ */ __name((value) => {
|
|
61
|
-
try {
|
|
62
|
-
return typeof value === "object" || Boolean(value) && value?.constructor === Object || isPlainObject(value);
|
|
63
|
-
} catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}, "isObject");
|
|
67
|
-
|
|
68
|
-
// ../type-checks/src/is-string.ts
|
|
69
|
-
var isString = /* @__PURE__ */ __name((value) => {
|
|
70
|
-
try {
|
|
71
|
-
return typeof value === "string";
|
|
72
|
-
} catch {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}, "isString");
|
|
76
|
-
|
|
77
|
-
// ../json/src/storm-json.ts
|
|
78
|
-
import { parse as parse2 } from "jsonc-parser";
|
|
79
|
-
import { Buffer as Buffer2 } from "node:buffer";
|
|
80
|
-
import SuperJSON from "superjson";
|
|
81
|
-
|
|
82
33
|
// ../types/src/base.ts
|
|
83
34
|
var EMPTY_STRING = "";
|
|
84
35
|
var $NestedValue = Symbol("NestedValue");
|
|
85
36
|
|
|
86
|
-
// ../
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
function isEscaped(value, quotePosition) {
|
|
98
|
-
let index = quotePosition - 1;
|
|
99
|
-
let backslashCount = 0;
|
|
100
|
-
while (value[index] === "\\") {
|
|
101
|
-
index -= 1;
|
|
102
|
-
backslashCount += 1;
|
|
37
|
+
// ../path/src/file-path-fns.ts
|
|
38
|
+
import { relative } from "node:path";
|
|
39
|
+
|
|
40
|
+
// ../path/src/is-file.ts
|
|
41
|
+
import { lstatSync, statSync } from "node:fs";
|
|
42
|
+
|
|
43
|
+
// ../path/src/join-paths.ts
|
|
44
|
+
var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
|
|
45
|
+
function normalizeWindowsPath(input = "") {
|
|
46
|
+
if (!input) {
|
|
47
|
+
return input;
|
|
103
48
|
}
|
|
104
|
-
return
|
|
49
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
105
50
|
}
|
|
106
|
-
__name(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
51
|
+
__name(normalizeWindowsPath, "normalizeWindowsPath");
|
|
52
|
+
var _UNC_REGEX = /^[/\\]{2}/;
|
|
53
|
+
var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
|
|
54
|
+
var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
55
|
+
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
56
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
57
|
+
}, "isAbsolute");
|
|
58
|
+
var correctPaths = /* @__PURE__ */ __name(function(path) {
|
|
59
|
+
if (!path || path.length === 0) {
|
|
60
|
+
return ".";
|
|
110
61
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const currentCharacter = value[index];
|
|
120
|
-
const nextCharacter = value[index + 1];
|
|
121
|
-
if (!isInsideComment && currentCharacter === '"') {
|
|
122
|
-
const escaped = isEscaped(value, index);
|
|
123
|
-
if (!escaped) {
|
|
124
|
-
isInsideString = !isInsideString;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (isInsideString) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
|
|
131
|
-
buffer += value.slice(offset, index);
|
|
132
|
-
offset = index;
|
|
133
|
-
isInsideComment = singleComment;
|
|
134
|
-
index++;
|
|
135
|
-
} else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
|
|
136
|
-
index++;
|
|
137
|
-
isInsideComment = false;
|
|
138
|
-
buffer += strip(value, offset, index);
|
|
139
|
-
offset = index;
|
|
140
|
-
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
141
|
-
isInsideComment = false;
|
|
142
|
-
buffer += strip(value, offset, index);
|
|
143
|
-
offset = index;
|
|
144
|
-
} else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
|
|
145
|
-
buffer += value.slice(offset, index);
|
|
146
|
-
offset = index;
|
|
147
|
-
isInsideComment = multiComment;
|
|
148
|
-
index++;
|
|
149
|
-
} else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
|
|
150
|
-
index++;
|
|
151
|
-
isInsideComment = false;
|
|
152
|
-
buffer += strip(value, offset, index + 1);
|
|
153
|
-
offset = index + 1;
|
|
154
|
-
} else if (trailingCommas && !isInsideComment) {
|
|
155
|
-
if (commaIndex !== -1) {
|
|
156
|
-
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
157
|
-
buffer += value.slice(offset, index);
|
|
158
|
-
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
159
|
-
buffer = "";
|
|
160
|
-
offset = index;
|
|
161
|
-
commaIndex = -1;
|
|
162
|
-
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
163
|
-
buffer += value.slice(offset, index);
|
|
164
|
-
offset = index;
|
|
165
|
-
commaIndex = -1;
|
|
166
|
-
}
|
|
167
|
-
} else if (currentCharacter === ",") {
|
|
168
|
-
result += buffer + value.slice(offset, index);
|
|
169
|
-
buffer = "";
|
|
170
|
-
offset = index;
|
|
171
|
-
commaIndex = index;
|
|
172
|
-
}
|
|
62
|
+
path = normalizeWindowsPath(path);
|
|
63
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
64
|
+
const isPathAbsolute = isAbsolute(path);
|
|
65
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
66
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
67
|
+
if (path.length === 0) {
|
|
68
|
+
if (isPathAbsolute) {
|
|
69
|
+
return "/";
|
|
173
70
|
}
|
|
71
|
+
return trailingSeparator ? "./" : ".";
|
|
174
72
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
__name(stripComments, "stripComments");
|
|
178
|
-
|
|
179
|
-
// ../json/src/utils/parse.ts
|
|
180
|
-
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*:/;
|
|
181
|
-
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*:/;
|
|
182
|
-
var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
183
|
-
function jsonParseTransform(key, value) {
|
|
184
|
-
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
185
|
-
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
return value;
|
|
189
|
-
}
|
|
190
|
-
__name(jsonParseTransform, "jsonParseTransform");
|
|
191
|
-
function parse(value, options = {}) {
|
|
192
|
-
if (typeof value !== "string") {
|
|
193
|
-
return value;
|
|
73
|
+
if (trailingSeparator) {
|
|
74
|
+
path += "/";
|
|
194
75
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return stripped.slice(1, -1);
|
|
76
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
77
|
+
path += "/";
|
|
198
78
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
case "true": {
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
case "false": {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
case "undefined": {
|
|
209
|
-
return void 0;
|
|
210
|
-
}
|
|
211
|
-
case "null": {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
case "nan": {
|
|
215
|
-
return Number.NaN;
|
|
216
|
-
}
|
|
217
|
-
case "infinity": {
|
|
218
|
-
return Number.POSITIVE_INFINITY;
|
|
219
|
-
}
|
|
220
|
-
case "-infinity": {
|
|
221
|
-
return Number.NEGATIVE_INFINITY;
|
|
222
|
-
}
|
|
79
|
+
if (isUNCPath) {
|
|
80
|
+
if (!isPathAbsolute) {
|
|
81
|
+
return `//./${path}`;
|
|
223
82
|
}
|
|
83
|
+
return `//${path}`;
|
|
224
84
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
85
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
86
|
+
}, "correctPaths");
|
|
87
|
+
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
88
|
+
let path = "";
|
|
89
|
+
for (const seg of segments) {
|
|
90
|
+
if (!seg) {
|
|
91
|
+
continue;
|
|
228
92
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
|
|
93
|
+
if (path.length > 0) {
|
|
94
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
95
|
+
const segLeading = seg[0] === "/";
|
|
96
|
+
const both = pathTrailing && segLeading;
|
|
97
|
+
if (both) {
|
|
98
|
+
path += seg.slice(1);
|
|
99
|
+
} else {
|
|
100
|
+
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
235
101
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return JSON.parse(stripped);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (options.strict) {
|
|
241
|
-
throw error;
|
|
102
|
+
} else {
|
|
103
|
+
path += seg;
|
|
242
104
|
}
|
|
243
|
-
return value;
|
|
244
105
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
];
|
|
290
|
-
} else if (i === lineDiff) {
|
|
291
|
-
markerLines[lineNumber] = [
|
|
292
|
-
0,
|
|
293
|
-
endColumn
|
|
294
|
-
];
|
|
106
|
+
return correctPaths(path);
|
|
107
|
+
}, "joinPaths");
|
|
108
|
+
function normalizeString(path, allowAboveRoot) {
|
|
109
|
+
let res = "";
|
|
110
|
+
let lastSegmentLength = 0;
|
|
111
|
+
let lastSlash = -1;
|
|
112
|
+
let dots = 0;
|
|
113
|
+
let char = null;
|
|
114
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
115
|
+
if (index < path.length) {
|
|
116
|
+
char = path[index];
|
|
117
|
+
} else if (char === "/") {
|
|
118
|
+
break;
|
|
119
|
+
} else {
|
|
120
|
+
char = "/";
|
|
121
|
+
}
|
|
122
|
+
if (char === "/") {
|
|
123
|
+
if (lastSlash === index - 1 || dots === 1) {
|
|
124
|
+
} else if (dots === 2) {
|
|
125
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
126
|
+
if (res.length > 2) {
|
|
127
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
128
|
+
if (lastSlashIndex === -1) {
|
|
129
|
+
res = "";
|
|
130
|
+
lastSegmentLength = 0;
|
|
131
|
+
} else {
|
|
132
|
+
res = res.slice(0, lastSlashIndex);
|
|
133
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
134
|
+
}
|
|
135
|
+
lastSlash = index;
|
|
136
|
+
dots = 0;
|
|
137
|
+
continue;
|
|
138
|
+
} else if (res.length > 0) {
|
|
139
|
+
res = "";
|
|
140
|
+
lastSegmentLength = 0;
|
|
141
|
+
lastSlash = index;
|
|
142
|
+
dots = 0;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (allowAboveRoot) {
|
|
147
|
+
res += res.length > 0 ? "/.." : "..";
|
|
148
|
+
lastSegmentLength = 2;
|
|
149
|
+
}
|
|
295
150
|
} else {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
151
|
+
if (res.length > 0) {
|
|
152
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
153
|
+
} else {
|
|
154
|
+
res = path.slice(lastSlash + 1, index);
|
|
155
|
+
}
|
|
156
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
301
157
|
}
|
|
158
|
+
lastSlash = index;
|
|
159
|
+
dots = 0;
|
|
160
|
+
} else if (char === "." && dots !== -1) {
|
|
161
|
+
++dots;
|
|
162
|
+
} else {
|
|
163
|
+
dots = -1;
|
|
302
164
|
}
|
|
303
|
-
} else if (startColumn === endColumn) {
|
|
304
|
-
markerLines[startLine] = startColumn ? [
|
|
305
|
-
startColumn,
|
|
306
|
-
0
|
|
307
|
-
] : true;
|
|
308
|
-
} else {
|
|
309
|
-
markerLines[startLine] = [
|
|
310
|
-
startColumn,
|
|
311
|
-
endColumn - startColumn
|
|
312
|
-
];
|
|
313
165
|
}
|
|
314
|
-
return
|
|
315
|
-
start,
|
|
316
|
-
end,
|
|
317
|
-
markerLines
|
|
318
|
-
};
|
|
166
|
+
return res;
|
|
319
167
|
}
|
|
320
|
-
__name(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (hasMarker) {
|
|
332
|
-
let markerLine = "";
|
|
333
|
-
if (Array.isArray(hasMarker)) {
|
|
334
|
-
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
335
|
-
const numberOfMarkers = hasMarker[1] || 1;
|
|
336
|
-
markerLine = [
|
|
337
|
-
"\n ",
|
|
338
|
-
gutter.replace(/\d/g, " "),
|
|
339
|
-
markerSpacing,
|
|
340
|
-
"^".repeat(numberOfMarkers)
|
|
341
|
-
].join("");
|
|
342
|
-
}
|
|
343
|
-
return [
|
|
344
|
-
">",
|
|
345
|
-
gutter,
|
|
346
|
-
line,
|
|
347
|
-
markerLine
|
|
348
|
-
].join("");
|
|
349
|
-
}
|
|
350
|
-
return ` ${gutter}${line}`;
|
|
351
|
-
}).join("\n");
|
|
352
|
-
return frame;
|
|
168
|
+
__name(normalizeString, "normalizeString");
|
|
169
|
+
|
|
170
|
+
// ../path/src/regex.ts
|
|
171
|
+
var DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
|
|
172
|
+
|
|
173
|
+
// ../path/src/slash.ts
|
|
174
|
+
function slash(path) {
|
|
175
|
+
if (path.startsWith("\\\\?\\")) {
|
|
176
|
+
return path;
|
|
177
|
+
}
|
|
178
|
+
return path.replace(/\\/g, "/");
|
|
353
179
|
}
|
|
354
|
-
__name(
|
|
180
|
+
__name(slash, "slash");
|
|
355
181
|
|
|
356
|
-
// ../
|
|
357
|
-
function
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
line++;
|
|
363
|
-
column++;
|
|
364
|
-
return `${printParseErrorCode(error)} in JSON at ${line}:${column}
|
|
365
|
-
${codeFrameColumns(input, {
|
|
366
|
-
start: {
|
|
367
|
-
line,
|
|
368
|
-
column
|
|
369
|
-
},
|
|
370
|
-
end: {
|
|
371
|
-
line,
|
|
372
|
-
column: column + length
|
|
373
|
-
}
|
|
374
|
-
})}
|
|
375
|
-
`;
|
|
182
|
+
// ../path/src/correct-path.ts
|
|
183
|
+
function normalizeWindowsPath2(input = "") {
|
|
184
|
+
if (!input) {
|
|
185
|
+
return input;
|
|
186
|
+
}
|
|
187
|
+
return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
376
188
|
}
|
|
377
|
-
__name(
|
|
189
|
+
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
378
190
|
|
|
379
|
-
// ../
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
191
|
+
// ../path/src/get-workspace-root.ts
|
|
192
|
+
import { findWorkspaceRootSafe } from "@storm-software/config-tools";
|
|
193
|
+
|
|
194
|
+
// ../path/src/file-path-fns.ts
|
|
195
|
+
function findFileName(filePath, options = {}) {
|
|
196
|
+
const { requireExtension = false, withExtension = true } = options;
|
|
197
|
+
const result = normalizeWindowsPath2(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
198
|
+
if (requireExtension === true && !result.includes(".")) {
|
|
199
|
+
return EMPTY_STRING;
|
|
385
200
|
}
|
|
386
|
-
|
|
201
|
+
if (withExtension === false && result.includes(".")) {
|
|
202
|
+
return result.substring(0, result.lastIndexOf(".")) || EMPTY_STRING;
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
__name(findFileName, "findFileName");
|
|
207
|
+
function findFilePath(filePath) {
|
|
208
|
+
const normalizedPath = normalizeWindowsPath2(filePath);
|
|
209
|
+
const result = normalizedPath.replace(findFileName(normalizedPath, {
|
|
210
|
+
requireExtension: true
|
|
211
|
+
}), "");
|
|
212
|
+
return result === "/" ? result : result.replace(/\/$/, "");
|
|
213
|
+
}
|
|
214
|
+
__name(findFilePath, "findFilePath");
|
|
215
|
+
function relativePath(from, to, withEndSlash = false) {
|
|
216
|
+
return relative(withEndSlash !== true ? from.replace(/\/$/, "") : from, withEndSlash !== true ? to.replace(/\/$/, "") : to);
|
|
217
|
+
}
|
|
218
|
+
__name(relativePath, "relativePath");
|
|
387
219
|
|
|
388
|
-
//
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}, "isUndefined");
|
|
220
|
+
// bin/capnpc.ts
|
|
221
|
+
import { Command, Option } from "commander";
|
|
222
|
+
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
392
223
|
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
"@",
|
|
396
|
-
"/",
|
|
397
|
-
"#",
|
|
398
|
-
"$",
|
|
399
|
-
" ",
|
|
400
|
-
":",
|
|
401
|
-
";",
|
|
402
|
-
",",
|
|
403
|
-
".",
|
|
404
|
-
"!",
|
|
405
|
-
"?",
|
|
406
|
-
"&",
|
|
407
|
-
"=",
|
|
408
|
-
"+",
|
|
409
|
-
"-",
|
|
410
|
-
"*",
|
|
411
|
-
"%",
|
|
412
|
-
"^",
|
|
413
|
-
"~",
|
|
414
|
-
"|",
|
|
415
|
-
"\\",
|
|
416
|
-
'"',
|
|
417
|
-
"'",
|
|
418
|
-
"`",
|
|
419
|
-
"{",
|
|
420
|
-
"}",
|
|
421
|
-
"[",
|
|
422
|
-
"]",
|
|
423
|
-
"(",
|
|
424
|
-
")",
|
|
425
|
-
"<",
|
|
426
|
-
">"
|
|
427
|
-
];
|
|
428
|
-
var stringify = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
429
|
-
const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
|
|
430
|
-
switch (value) {
|
|
431
|
-
case null: {
|
|
432
|
-
return "null";
|
|
433
|
-
}
|
|
434
|
-
case void 0: {
|
|
435
|
-
return '"undefined"';
|
|
436
|
-
}
|
|
437
|
-
case true: {
|
|
438
|
-
return "true";
|
|
439
|
-
}
|
|
440
|
-
case false: {
|
|
441
|
-
return "false";
|
|
442
|
-
}
|
|
443
|
-
case Number.POSITIVE_INFINITY: {
|
|
444
|
-
return "infinity";
|
|
445
|
-
}
|
|
446
|
-
case Number.NEGATIVE_INFINITY: {
|
|
447
|
-
return "-infinity";
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (Array.isArray(value)) {
|
|
451
|
-
return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
|
|
452
|
-
}
|
|
453
|
-
if (value instanceof Uint8Array) {
|
|
454
|
-
return value.toString();
|
|
455
|
-
}
|
|
456
|
-
switch (typeof value) {
|
|
457
|
-
case "number": {
|
|
458
|
-
return `${value}`;
|
|
459
|
-
}
|
|
460
|
-
case "string": {
|
|
461
|
-
return JSON.stringify(value);
|
|
462
|
-
}
|
|
463
|
-
case "object": {
|
|
464
|
-
const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
|
|
465
|
-
return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
|
|
466
|
-
}
|
|
467
|
-
default:
|
|
468
|
-
return "null";
|
|
469
|
-
}
|
|
470
|
-
}, "stringify");
|
|
224
|
+
// src/compile.ts
|
|
225
|
+
import { writeWarning as writeWarning2 } from "@storm-software/config-tools/logger/console";
|
|
471
226
|
|
|
472
|
-
//
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
227
|
+
// ../../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
|
|
228
|
+
import ts from "typescript";
|
|
229
|
+
|
|
230
|
+
// ../../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
|
|
231
|
+
var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
|
|
232
|
+
ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
|
|
233
|
+
ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
|
|
234
|
+
ListElementSize2[ListElementSize2["BYTE"] = 2] = "BYTE";
|
|
235
|
+
ListElementSize2[ListElementSize2["BYTE_2"] = 3] = "BYTE_2";
|
|
236
|
+
ListElementSize2[ListElementSize2["BYTE_4"] = 4] = "BYTE_4";
|
|
237
|
+
ListElementSize2[ListElementSize2["BYTE_8"] = 5] = "BYTE_8";
|
|
238
|
+
ListElementSize2[ListElementSize2["POINTER"] = 6] = "POINTER";
|
|
239
|
+
ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
|
|
240
|
+
return ListElementSize2;
|
|
241
|
+
})(ListElementSize || {});
|
|
242
|
+
var tmpWord = new DataView(new ArrayBuffer(8));
|
|
243
|
+
new Uint16Array(tmpWord.buffer)[0] = 258;
|
|
244
|
+
var DEFAULT_BUFFER_SIZE = 4096;
|
|
245
|
+
var DEFAULT_TRAVERSE_LIMIT = 64 << 20;
|
|
246
|
+
var LIST_SIZE_MASK = 7;
|
|
247
|
+
var MAX_BUFFER_DUMP_BYTES = 8192;
|
|
248
|
+
var MAX_INT32 = 2147483647;
|
|
249
|
+
var MAX_UINT32 = 4294967295;
|
|
250
|
+
var MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
|
251
|
+
var NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
|
|
252
|
+
var PACK_SPAN_THRESHOLD = 2;
|
|
253
|
+
var POINTER_DOUBLE_FAR_MASK = 4;
|
|
254
|
+
var POINTER_TYPE_MASK = 3;
|
|
255
|
+
var MAX_DEPTH = MAX_INT32;
|
|
256
|
+
var MAX_SEGMENT_LENGTH = MAX_UINT32;
|
|
257
|
+
var INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
|
258
|
+
function assertNever(n) {
|
|
259
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
|
260
|
+
}
|
|
261
|
+
__name(assertNever, "assertNever");
|
|
262
|
+
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?";
|
|
263
|
+
var MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
|
264
|
+
var MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
|
265
|
+
var MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
|
266
|
+
var PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
|
267
|
+
var PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
|
268
|
+
var PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
|
269
|
+
var PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
|
270
|
+
var PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
|
271
|
+
var PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
|
272
|
+
var PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
|
273
|
+
var PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
|
274
|
+
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).";
|
|
275
|
+
var PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
|
276
|
+
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).";
|
|
277
|
+
var PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
|
278
|
+
var PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
|
279
|
+
var PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
|
280
|
+
var PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
|
281
|
+
var SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
|
282
|
+
var SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
|
283
|
+
var SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
|
284
|
+
var SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
|
285
|
+
var SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
|
286
|
+
var TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
|
287
|
+
var LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
|
|
288
|
+
var LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
|
|
289
|
+
function bufferToHex(buffer) {
|
|
290
|
+
const a = new Uint8Array(buffer);
|
|
291
|
+
const h = [];
|
|
292
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
293
|
+
h.push(pad(a[i].toString(16), 2));
|
|
476
294
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
295
|
+
return `[${h.join(" ")}]`;
|
|
296
|
+
}
|
|
297
|
+
__name(bufferToHex, "bufferToHex");
|
|
298
|
+
function dumpBuffer(buffer) {
|
|
299
|
+
const b = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
300
|
+
const byteLength = Math.min(b.byteLength, MAX_BUFFER_DUMP_BYTES);
|
|
301
|
+
let r = format("\n=== buffer[%d] ===", byteLength);
|
|
302
|
+
for (let j = 0; j < byteLength; j += 16) {
|
|
303
|
+
r += `
|
|
304
|
+
${pad(j.toString(16), 8)}: `;
|
|
305
|
+
let s = "";
|
|
306
|
+
let k;
|
|
307
|
+
for (k = 0; k < 16 && j + k < b.byteLength; k++) {
|
|
308
|
+
const v = b[j + k];
|
|
309
|
+
r += `${pad(v.toString(16), 2)} `;
|
|
310
|
+
s += v > 31 && v < 255 ? String.fromCharCode(v) : "\xB7";
|
|
311
|
+
if (k === 7) {
|
|
312
|
+
r += " ";
|
|
313
|
+
}
|
|
481
314
|
}
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Deserialize the given value with superjson using the given metadata
|
|
486
|
-
*/
|
|
487
|
-
static deserialize(payload) {
|
|
488
|
-
return _StormJSON.instance.deserialize(payload);
|
|
315
|
+
r += `${" ".repeat((17 - k) * 3)}${s}`;
|
|
489
316
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
static serialize(object) {
|
|
494
|
-
return _StormJSON.instance.serialize(object);
|
|
317
|
+
r += "\n";
|
|
318
|
+
if (byteLength !== b.byteLength) {
|
|
319
|
+
r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
|
|
495
320
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
321
|
+
return r;
|
|
322
|
+
}
|
|
323
|
+
__name(dumpBuffer, "dumpBuffer");
|
|
324
|
+
function format(s, ...args) {
|
|
325
|
+
const n = s.length;
|
|
326
|
+
let arg;
|
|
327
|
+
let argIndex = 0;
|
|
328
|
+
let c;
|
|
329
|
+
let escaped = false;
|
|
330
|
+
let i = 0;
|
|
331
|
+
let leadingZero = false;
|
|
332
|
+
let precision;
|
|
333
|
+
let result = "";
|
|
334
|
+
function nextArg() {
|
|
335
|
+
return args[argIndex++];
|
|
504
336
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
* @returns the formatted JSON representation of the object
|
|
512
|
-
*/
|
|
513
|
-
static stringify(value, _options) {
|
|
514
|
-
const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
515
|
-
let result = value;
|
|
516
|
-
if (customTransformer && customTransformer.isApplicable(value)) {
|
|
517
|
-
result = customTransformer.serialize(result);
|
|
337
|
+
__name(nextArg, "nextArg");
|
|
338
|
+
function slurpNumber() {
|
|
339
|
+
let digits = "";
|
|
340
|
+
while (/\d/.test(s[i])) {
|
|
341
|
+
digits += s[i++];
|
|
342
|
+
c = s[i];
|
|
518
343
|
}
|
|
519
|
-
return
|
|
344
|
+
return digits.length > 0 ? Number.parseInt(digits, 10) : null;
|
|
520
345
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
346
|
+
__name(slurpNumber, "slurpNumber");
|
|
347
|
+
for (; i < n; ++i) {
|
|
348
|
+
c = s[i];
|
|
349
|
+
if (escaped) {
|
|
350
|
+
escaped = false;
|
|
351
|
+
if (c === ".") {
|
|
352
|
+
leadingZero = false;
|
|
353
|
+
c = s[++i];
|
|
354
|
+
} else if (c === "0" && s[i + 1] === ".") {
|
|
355
|
+
leadingZero = true;
|
|
356
|
+
i += 2;
|
|
357
|
+
c = s[i];
|
|
358
|
+
} else {
|
|
359
|
+
leadingZero = true;
|
|
533
360
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
361
|
+
precision = slurpNumber();
|
|
362
|
+
switch (c) {
|
|
363
|
+
case "a": {
|
|
364
|
+
result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case "b": {
|
|
368
|
+
result += Number.parseInt(String(nextArg()), 10).toString(2);
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case "c": {
|
|
372
|
+
arg = nextArg();
|
|
373
|
+
result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case "d": {
|
|
377
|
+
result += Number.parseInt(String(nextArg()), 10);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "f": {
|
|
381
|
+
const tmp = Number.parseFloat(String(nextArg())).toFixed(
|
|
382
|
+
precision || 6
|
|
383
|
+
);
|
|
384
|
+
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
case "j": {
|
|
388
|
+
result += JSON.stringify(nextArg());
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
case "o": {
|
|
392
|
+
result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case "s": {
|
|
396
|
+
result += nextArg();
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case "x": {
|
|
400
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
case "X": {
|
|
404
|
+
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
default: {
|
|
408
|
+
result += c;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} else if (c === "%") {
|
|
413
|
+
escaped = true;
|
|
414
|
+
} else {
|
|
415
|
+
result += c;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return result;
|
|
419
|
+
}
|
|
420
|
+
__name(format, "format");
|
|
421
|
+
function pad(v, width, pad2 = "0") {
|
|
422
|
+
return v.length >= width ? v : Array.from({ length: width - v.length + 1 }).join(pad2) + v;
|
|
423
|
+
}
|
|
424
|
+
__name(pad, "pad");
|
|
425
|
+
function padToWord$1(size) {
|
|
426
|
+
return size + 7 & -8;
|
|
427
|
+
}
|
|
428
|
+
__name(padToWord$1, "padToWord$1");
|
|
429
|
+
var ObjectSize = class {
|
|
430
|
+
static {
|
|
431
|
+
__name(this, "ObjectSize");
|
|
561
432
|
}
|
|
562
433
|
/**
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
"__typename"
|
|
572
|
-
]
|
|
573
|
-
});
|
|
434
|
+
* Creates a new ObjectSize instance.
|
|
435
|
+
*
|
|
436
|
+
* @param dataByteLength - The number of bytes in the data section of the struct
|
|
437
|
+
* @param pointerLength - The number of pointers in the pointer section of the struct
|
|
438
|
+
*/
|
|
439
|
+
constructor(dataByteLength, pointerLength) {
|
|
440
|
+
this.dataByteLength = dataByteLength;
|
|
441
|
+
this.pointerLength = pointerLength;
|
|
574
442
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
443
|
+
toString() {
|
|
444
|
+
return format(
|
|
445
|
+
"ObjectSize_dw:%d,pc:%d",
|
|
446
|
+
getDataWordLength(this),
|
|
447
|
+
this.pointerLength
|
|
448
|
+
);
|
|
579
449
|
}
|
|
580
450
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
|
|
584
|
-
deserialize: /* @__PURE__ */ __name((v) => Buffer2.from(v, "base64"), "deserialize")
|
|
585
|
-
}, "Bytes");
|
|
586
|
-
|
|
587
|
-
// ../type-checks/src/is-error.ts
|
|
588
|
-
var isError = /* @__PURE__ */ __name((obj) => {
|
|
589
|
-
if (!isObject(obj)) {
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
const tag = getObjectTag(obj);
|
|
593
|
-
return tag === "[object Error]" || tag === "[object DOMException]" || typeof obj?.message === "string" && typeof obj?.name === "string" && !isPlainObject(obj);
|
|
594
|
-
}, "isError");
|
|
595
|
-
|
|
596
|
-
// ../fs/src/read-file.ts
|
|
597
|
-
import { existsSync as existsSync2, readFileSync as readFileSyncFs } from "node:fs";
|
|
598
|
-
import { readFile as readFileFs } from "node:fs/promises";
|
|
599
|
-
var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
|
|
600
|
-
try {
|
|
601
|
-
if (!filePath) {
|
|
602
|
-
throw new Error("No file path provided to read data");
|
|
603
|
-
}
|
|
604
|
-
return await readFileFs(filePath, {
|
|
605
|
-
encoding: "utf8"
|
|
606
|
-
});
|
|
607
|
-
} catch {
|
|
608
|
-
throw new Error("An error occurred writing data to file");
|
|
609
|
-
}
|
|
610
|
-
}, "readFile");
|
|
611
|
-
|
|
612
|
-
// ../path/src/is-file.ts
|
|
613
|
-
import { lstatSync, statSync } from "node:fs";
|
|
614
|
-
|
|
615
|
-
// ../path/src/join-paths.ts
|
|
616
|
-
var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
|
|
617
|
-
function normalizeWindowsPath(input = "") {
|
|
618
|
-
if (!input) {
|
|
619
|
-
return input;
|
|
620
|
-
}
|
|
621
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
451
|
+
function getByteLength(o) {
|
|
452
|
+
return o.dataByteLength + o.pointerLength * 8;
|
|
622
453
|
}
|
|
623
|
-
__name(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
454
|
+
__name(getByteLength, "getByteLength");
|
|
455
|
+
function getDataWordLength(o) {
|
|
456
|
+
return o.dataByteLength / 8;
|
|
457
|
+
}
|
|
458
|
+
__name(getDataWordLength, "getDataWordLength");
|
|
459
|
+
function getWordLength(o) {
|
|
460
|
+
return o.dataByteLength / 8 + o.pointerLength;
|
|
461
|
+
}
|
|
462
|
+
__name(getWordLength, "getWordLength");
|
|
463
|
+
function padToWord(o) {
|
|
464
|
+
return new ObjectSize(padToWord$1(o.dataByteLength), o.pointerLength);
|
|
465
|
+
}
|
|
466
|
+
__name(padToWord, "padToWord");
|
|
467
|
+
var Orphan = class {
|
|
468
|
+
static {
|
|
469
|
+
__name(this, "Orphan");
|
|
633
470
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
471
|
+
/** If this member is not present then the orphan has already been adopted, or something went very wrong. */
|
|
472
|
+
_capnp;
|
|
473
|
+
byteOffset;
|
|
474
|
+
segment;
|
|
475
|
+
constructor(src) {
|
|
476
|
+
const c = getContent(src);
|
|
477
|
+
this.segment = c.segment;
|
|
478
|
+
this.byteOffset = c.byteOffset;
|
|
479
|
+
this._capnp = {};
|
|
480
|
+
this._capnp.type = getTargetPointerType(src);
|
|
481
|
+
switch (this._capnp.type) {
|
|
482
|
+
case PointerType.STRUCT: {
|
|
483
|
+
this._capnp.size = getTargetStructSize(src);
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
case PointerType.LIST: {
|
|
487
|
+
this._capnp.length = getTargetListLength(src);
|
|
488
|
+
this._capnp.elementSize = getTargetListElementSize(src);
|
|
489
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
490
|
+
this._capnp.size = getTargetCompositeListSize(src);
|
|
491
|
+
}
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
case PointerType.OTHER: {
|
|
495
|
+
this._capnp.capId = getCapabilityId(src);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
default: {
|
|
499
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
500
|
+
}
|
|
642
501
|
}
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
if (trailingSeparator) {
|
|
646
|
-
path += "/";
|
|
647
|
-
}
|
|
648
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
649
|
-
path += "/";
|
|
502
|
+
erasePointer(src);
|
|
650
503
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
504
|
+
/**
|
|
505
|
+
* Adopt (move) this orphan into the target pointer location. This will allocate far pointers in `dst` as needed.
|
|
506
|
+
*
|
|
507
|
+
* @param dst The destination pointer.
|
|
508
|
+
*/
|
|
509
|
+
_moveTo(dst) {
|
|
510
|
+
if (this._capnp === void 0) {
|
|
511
|
+
throw new Error(format(PTR_ALREADY_ADOPTED, this));
|
|
654
512
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
658
|
-
}, "correctPaths");
|
|
659
|
-
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
660
|
-
let path = "";
|
|
661
|
-
for (const seg of segments) {
|
|
662
|
-
if (!seg) {
|
|
663
|
-
continue;
|
|
513
|
+
if (this.segment.message !== dst.segment.message) {
|
|
514
|
+
throw new Error(format(PTR_ADOPT_WRONG_MESSAGE, this, dst));
|
|
664
515
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
516
|
+
erase(dst);
|
|
517
|
+
const res = initPointer(this.segment, this.byteOffset, dst);
|
|
518
|
+
switch (this._capnp.type) {
|
|
519
|
+
case PointerType.STRUCT: {
|
|
520
|
+
setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
case PointerType.LIST: {
|
|
524
|
+
let { offsetWords } = res;
|
|
525
|
+
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
526
|
+
offsetWords--;
|
|
527
|
+
}
|
|
528
|
+
setListPointer(
|
|
529
|
+
offsetWords,
|
|
530
|
+
this._capnp.elementSize,
|
|
531
|
+
this._capnp.length,
|
|
532
|
+
res.pointer,
|
|
533
|
+
this._capnp.size
|
|
534
|
+
);
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
case PointerType.OTHER: {
|
|
538
|
+
setInterfacePointer(this._capnp.capId, res.pointer);
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
/* istanbul ignore next */
|
|
542
|
+
default: {
|
|
543
|
+
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
673
544
|
}
|
|
674
|
-
} else {
|
|
675
|
-
path += seg;
|
|
676
545
|
}
|
|
546
|
+
this._capnp = void 0;
|
|
677
547
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
let res = "";
|
|
682
|
-
let lastSegmentLength = 0;
|
|
683
|
-
let lastSlash = -1;
|
|
684
|
-
let dots = 0;
|
|
685
|
-
let char = null;
|
|
686
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
687
|
-
if (index < path.length) {
|
|
688
|
-
char = path[index];
|
|
689
|
-
} else if (char === "/") {
|
|
690
|
-
break;
|
|
691
|
-
} else {
|
|
692
|
-
char = "/";
|
|
548
|
+
dispose() {
|
|
549
|
+
if (this._capnp === void 0) {
|
|
550
|
+
return;
|
|
693
551
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
} else if (res.length > 0) {
|
|
711
|
-
res = "";
|
|
712
|
-
lastSegmentLength = 0;
|
|
713
|
-
lastSlash = index;
|
|
714
|
-
dots = 0;
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
if (allowAboveRoot) {
|
|
719
|
-
res += res.length > 0 ? "/.." : "..";
|
|
720
|
-
lastSegmentLength = 2;
|
|
721
|
-
}
|
|
722
|
-
} else {
|
|
723
|
-
if (res.length > 0) {
|
|
724
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
725
|
-
} else {
|
|
726
|
-
res = path.slice(lastSlash + 1, index);
|
|
727
|
-
}
|
|
728
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
552
|
+
switch (this._capnp.type) {
|
|
553
|
+
case PointerType.STRUCT: {
|
|
554
|
+
this.segment.fillZeroWords(
|
|
555
|
+
this.byteOffset,
|
|
556
|
+
getWordLength(this._capnp.size)
|
|
557
|
+
);
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
case PointerType.LIST: {
|
|
561
|
+
const byteLength = getListByteLength(
|
|
562
|
+
this._capnp.elementSize,
|
|
563
|
+
this._capnp.length,
|
|
564
|
+
this._capnp.size
|
|
565
|
+
);
|
|
566
|
+
this.segment.fillZeroWords(this.byteOffset, byteLength);
|
|
567
|
+
break;
|
|
729
568
|
}
|
|
730
|
-
lastSlash = index;
|
|
731
|
-
dots = 0;
|
|
732
|
-
} else if (char === "." && dots !== -1) {
|
|
733
|
-
++dots;
|
|
734
|
-
} else {
|
|
735
|
-
dots = -1;
|
|
736
569
|
}
|
|
570
|
+
this._capnp = void 0;
|
|
737
571
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
// ../path/src/slash.ts
|
|
746
|
-
function slash(path) {
|
|
747
|
-
if (path.startsWith("\\\\?\\")) {
|
|
748
|
-
return path;
|
|
749
|
-
}
|
|
750
|
-
return path.replace(/\\/g, "/");
|
|
751
|
-
}
|
|
752
|
-
__name(slash, "slash");
|
|
753
|
-
|
|
754
|
-
// ../path/src/correct-path.ts
|
|
755
|
-
function normalizeWindowsPath2(input = "") {
|
|
756
|
-
if (!input) {
|
|
757
|
-
return input;
|
|
758
|
-
}
|
|
759
|
-
return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
760
|
-
}
|
|
761
|
-
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
762
|
-
|
|
763
|
-
// ../path/src/file-path-fns.ts
|
|
764
|
-
import { relative } from "node:path";
|
|
765
|
-
|
|
766
|
-
// ../path/src/get-workspace-root.ts
|
|
767
|
-
import { findWorkspaceRootSafe } from "@storm-software/config-tools";
|
|
768
|
-
|
|
769
|
-
// ../path/src/file-path-fns.ts
|
|
770
|
-
function findFileName(filePath, options = {}) {
|
|
771
|
-
const { requireExtension = false, withExtension = true } = options;
|
|
772
|
-
const result = normalizeWindowsPath2(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
773
|
-
if (requireExtension === true && !result.includes(".")) {
|
|
774
|
-
return EMPTY_STRING;
|
|
775
|
-
}
|
|
776
|
-
if (withExtension === false && result.includes(".")) {
|
|
777
|
-
return result.substring(0, result.lastIndexOf(".")) || EMPTY_STRING;
|
|
572
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
573
|
+
return format(
|
|
574
|
+
"Orphan_%d@%a,type:%s",
|
|
575
|
+
this.segment.id,
|
|
576
|
+
this.byteOffset,
|
|
577
|
+
this._capnp && this._capnp.type
|
|
578
|
+
);
|
|
778
579
|
}
|
|
779
|
-
|
|
580
|
+
};
|
|
581
|
+
function adopt(src, p) {
|
|
582
|
+
src._moveTo(p);
|
|
780
583
|
}
|
|
781
|
-
__name(
|
|
782
|
-
function
|
|
783
|
-
|
|
784
|
-
const result = normalizedPath.replace(findFileName(normalizedPath, {
|
|
785
|
-
requireExtension: true
|
|
786
|
-
}), "");
|
|
787
|
-
return result === "/" ? result : result.replace(/\/$/, "");
|
|
584
|
+
__name(adopt, "adopt");
|
|
585
|
+
function disown(p) {
|
|
586
|
+
return new Orphan(p);
|
|
788
587
|
}
|
|
789
|
-
__name(
|
|
790
|
-
function
|
|
791
|
-
return
|
|
588
|
+
__name(disown, "disown");
|
|
589
|
+
function dump(p) {
|
|
590
|
+
return bufferToHex(p.segment.buffer.slice(p.byteOffset, p.byteOffset + 8));
|
|
792
591
|
}
|
|
793
|
-
__name(
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
592
|
+
__name(dump, "dump");
|
|
593
|
+
function getListByteLength(elementSize, length, compositeSize) {
|
|
594
|
+
switch (elementSize) {
|
|
595
|
+
case ListElementSize.BIT: {
|
|
596
|
+
return padToWord$1(length + 7 >>> 3);
|
|
597
|
+
}
|
|
598
|
+
case ListElementSize.BYTE:
|
|
599
|
+
case ListElementSize.BYTE_2:
|
|
600
|
+
case ListElementSize.BYTE_4:
|
|
601
|
+
case ListElementSize.BYTE_8:
|
|
602
|
+
case ListElementSize.POINTER:
|
|
603
|
+
case ListElementSize.VOID: {
|
|
604
|
+
return padToWord$1(getListElementByteLength(elementSize) * length);
|
|
605
|
+
}
|
|
606
|
+
/* istanbul ignore next */
|
|
607
|
+
case ListElementSize.COMPOSITE: {
|
|
608
|
+
if (compositeSize === void 0) {
|
|
609
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));
|
|
610
|
+
}
|
|
611
|
+
return length * padToWord$1(getByteLength(compositeSize));
|
|
612
|
+
}
|
|
613
|
+
/* istanbul ignore next */
|
|
614
|
+
default: {
|
|
615
|
+
throw new Error(PTR_INVALID_LIST_SIZE);
|
|
616
|
+
}
|
|
804
617
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
618
|
+
}
|
|
619
|
+
__name(getListByteLength, "getListByteLength");
|
|
620
|
+
function getListElementByteLength(elementSize) {
|
|
621
|
+
switch (elementSize) {
|
|
622
|
+
/* istanbul ignore next */
|
|
623
|
+
case ListElementSize.BIT: {
|
|
624
|
+
return Number.NaN;
|
|
625
|
+
}
|
|
626
|
+
case ListElementSize.BYTE: {
|
|
627
|
+
return 1;
|
|
628
|
+
}
|
|
629
|
+
case ListElementSize.BYTE_2: {
|
|
630
|
+
return 2;
|
|
631
|
+
}
|
|
632
|
+
case ListElementSize.BYTE_4: {
|
|
633
|
+
return 4;
|
|
634
|
+
}
|
|
635
|
+
case ListElementSize.BYTE_8:
|
|
636
|
+
case ListElementSize.POINTER: {
|
|
637
|
+
return 8;
|
|
638
|
+
}
|
|
639
|
+
/* istanbul ignore next */
|
|
640
|
+
case ListElementSize.COMPOSITE: {
|
|
641
|
+
return Number.NaN;
|
|
642
|
+
}
|
|
643
|
+
/* istanbul ignore next */
|
|
644
|
+
case ListElementSize.VOID: {
|
|
645
|
+
return 0;
|
|
646
|
+
}
|
|
647
|
+
/* istanbul ignore next */
|
|
648
|
+
default: {
|
|
649
|
+
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
811
650
|
}
|
|
812
|
-
throw new Error(`Failed to parse JSON: ${path}`);
|
|
813
651
|
}
|
|
814
652
|
}
|
|
815
|
-
__name(
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
import defu from "defu";
|
|
819
|
-
import { glob } from "glob";
|
|
820
|
-
var DEFAULT_OPTIONS = {
|
|
821
|
-
dot: true
|
|
822
|
-
};
|
|
823
|
-
async function list(filesGlob, options) {
|
|
824
|
-
return glob(filesGlob, defu(options ?? {}, DEFAULT_OPTIONS));
|
|
653
|
+
__name(getListElementByteLength, "getListElementByteLength");
|
|
654
|
+
function add(offset, p) {
|
|
655
|
+
return new Pointer(p.segment, p.byteOffset + offset, p._capnp.depthLimit);
|
|
825
656
|
}
|
|
826
|
-
__name(
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
831
|
-
if (!options?.withFileTypes) {
|
|
832
|
-
return result.map((file) => file.fullpath());
|
|
657
|
+
__name(add, "add");
|
|
658
|
+
function copyFrom(src, p) {
|
|
659
|
+
if (p.segment === src.segment && p.byteOffset === src.byteOffset) {
|
|
660
|
+
return;
|
|
833
661
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
ListElementSize2[ListElementSize2["COMPOSITE"] = 7] = "COMPOSITE";
|
|
856
|
-
return ListElementSize2;
|
|
857
|
-
})(ListElementSize || {});
|
|
858
|
-
var tmpWord = new DataView(new ArrayBuffer(8));
|
|
859
|
-
new Uint16Array(tmpWord.buffer)[0] = 258;
|
|
860
|
-
var DEFAULT_BUFFER_SIZE = 4096;
|
|
861
|
-
var DEFAULT_TRAVERSE_LIMIT = 64 << 20;
|
|
862
|
-
var LIST_SIZE_MASK = 7;
|
|
863
|
-
var MAX_BUFFER_DUMP_BYTES = 8192;
|
|
864
|
-
var MAX_INT32 = 2147483647;
|
|
865
|
-
var MAX_UINT32 = 4294967295;
|
|
866
|
-
var MIN_SINGLE_SEGMENT_GROWTH = 4096;
|
|
867
|
-
var NATIVE_LITTLE_ENDIAN = tmpWord.getUint8(0) === 2;
|
|
868
|
-
var PACK_SPAN_THRESHOLD = 2;
|
|
869
|
-
var POINTER_DOUBLE_FAR_MASK = 4;
|
|
870
|
-
var POINTER_TYPE_MASK = 3;
|
|
871
|
-
var MAX_DEPTH = MAX_INT32;
|
|
872
|
-
var MAX_SEGMENT_LENGTH = MAX_UINT32;
|
|
873
|
-
var INVARIANT_UNREACHABLE_CODE = "CAPNP-TS000 Unreachable code detected.";
|
|
874
|
-
function assertNever(n) {
|
|
875
|
-
throw new Error(INVARIANT_UNREACHABLE_CODE + ` (never block hit with: ${n})`);
|
|
876
|
-
}
|
|
877
|
-
__name(assertNever, "assertNever");
|
|
878
|
-
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?";
|
|
879
|
-
var MSG_PACK_NOT_WORD_ALIGNED = "CAPNP-TS003 Attempted to pack a message that was not word-aligned.";
|
|
880
|
-
var MSG_SEGMENT_OUT_OF_BOUNDS = "CAPNP-TS004 Segment ID %X is out of bounds for message %s.";
|
|
881
|
-
var MSG_SEGMENT_TOO_SMALL = "CAPNP-TS005 First segment must have at least enough room to hold the root pointer (8 bytes).";
|
|
882
|
-
var PTR_ADOPT_WRONG_MESSAGE = "CAPNP-TS008 Attempted to adopt %s into a pointer in a different message %s.";
|
|
883
|
-
var PTR_ALREADY_ADOPTED = "CAPNP-TS009 Attempted to adopt %s more than once.";
|
|
884
|
-
var PTR_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS010 Attempted to set a composite list without providing a composite element size.";
|
|
885
|
-
var PTR_DEPTH_LIMIT_EXCEEDED = "CAPNP-TS011 Nesting depth limit exceeded for %s.";
|
|
886
|
-
var PTR_INIT_COMPOSITE_STRUCT = "CAPNP-TS013 Attempted to initialize a struct member from a composite list (%s).";
|
|
887
|
-
var PTR_INVALID_FAR_TARGET = "CAPNP-TS015 Target of a far pointer (%s) is another far pointer.";
|
|
888
|
-
var PTR_INVALID_LIST_SIZE = "CAPNP-TS016 Invalid list element size: %x.";
|
|
889
|
-
var PTR_INVALID_POINTER_TYPE = "CAPNP-TS017 Invalid pointer type: %x.";
|
|
890
|
-
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).";
|
|
891
|
-
var PTR_OFFSET_OUT_OF_BOUNDS = "CAPNP-TS019 Pointer offset %a is out of bounds for underlying buffer.";
|
|
892
|
-
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).";
|
|
893
|
-
var PTR_STRUCT_POINTER_OUT_OF_BOUNDS = "CAPNP-TS021 Attempted to access out-of-bounds struct pointer (%s, index: %d, length: %d).";
|
|
894
|
-
var PTR_TRAVERSAL_LIMIT_EXCEEDED = "CAPNP-TS022 Traversal limit exceeded! Slow down! %s";
|
|
895
|
-
var PTR_WRONG_LIST_TYPE = "CAPNP-TS023 Cannot convert %s to a %s list.";
|
|
896
|
-
var PTR_WRONG_POINTER_TYPE = "CAPNP-TS024 Attempted to convert pointer %s to a %s type.";
|
|
897
|
-
var SEG_GET_NON_ZERO_SINGLE = "CAPNP-TS035 Attempted to get a segment other than 0 (%d) from a single segment arena.";
|
|
898
|
-
var SEG_ID_OUT_OF_BOUNDS = "CAPNP-TS036 Attempted to get an out-of-bounds segment (%d).";
|
|
899
|
-
var SEG_NOT_WORD_ALIGNED = "CAPNP-TS037 Segment buffer length %d is not a multiple of 8.";
|
|
900
|
-
var SEG_REPLACEMENT_BUFFER_TOO_SMALL = "CAPNP-TS038 Attempted to replace a segment buffer with one that is smaller than the allocated space.";
|
|
901
|
-
var SEG_SIZE_OVERFLOW = `CAPNP-TS039 Requested size %x exceeds maximum value (${MAX_SEGMENT_LENGTH}).`;
|
|
902
|
-
var TYPE_COMPOSITE_SIZE_UNDEFINED = "CAPNP-TS040 Must provide a composite element size for composite list pointers.";
|
|
903
|
-
var LIST_NO_MUTABLE = "CAPNP-TS045: Cannot call mutative methods on an immutable list.";
|
|
904
|
-
var LIST_NO_SEARCH = "CAPNP-TS046: Search is not supported for list.";
|
|
905
|
-
function bufferToHex(buffer) {
|
|
906
|
-
const a = new Uint8Array(buffer);
|
|
907
|
-
const h = [];
|
|
908
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
909
|
-
h.push(pad(a[i].toString(16), 2));
|
|
662
|
+
erase(p);
|
|
663
|
+
if (isNull(src)) return;
|
|
664
|
+
switch (getTargetPointerType(src)) {
|
|
665
|
+
case PointerType.STRUCT: {
|
|
666
|
+
copyFromStruct(src, p);
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
case PointerType.LIST: {
|
|
670
|
+
copyFromList(src, p);
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
case PointerType.OTHER: {
|
|
674
|
+
copyFromInterface(src, p);
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
/* istanbul ignore next */
|
|
678
|
+
default: {
|
|
679
|
+
throw new Error(
|
|
680
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
681
|
+
);
|
|
682
|
+
}
|
|
910
683
|
}
|
|
911
|
-
return `[${h.join(" ")}]`;
|
|
912
684
|
}
|
|
913
|
-
__name(
|
|
914
|
-
function
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
const v = b[j + k];
|
|
925
|
-
r += `${pad(v.toString(16), 2)} `;
|
|
926
|
-
s += v > 31 && v < 255 ? String.fromCharCode(v) : "\xB7";
|
|
927
|
-
if (k === 7) {
|
|
928
|
-
r += " ";
|
|
685
|
+
__name(copyFrom, "copyFrom");
|
|
686
|
+
function erase(p) {
|
|
687
|
+
if (isNull(p)) return;
|
|
688
|
+
let c;
|
|
689
|
+
switch (getTargetPointerType(p)) {
|
|
690
|
+
case PointerType.STRUCT: {
|
|
691
|
+
const size = getTargetStructSize(p);
|
|
692
|
+
c = getContent(p);
|
|
693
|
+
c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
|
|
694
|
+
for (let i = 0; i < size.pointerLength; i++) {
|
|
695
|
+
erase(add(i * 8, c));
|
|
929
696
|
}
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
case PointerType.LIST: {
|
|
700
|
+
const elementSize = getTargetListElementSize(p);
|
|
701
|
+
const length = getTargetListLength(p);
|
|
702
|
+
let contentWords = padToWord$1(
|
|
703
|
+
length * getListElementByteLength(elementSize)
|
|
704
|
+
);
|
|
705
|
+
c = getContent(p);
|
|
706
|
+
if (elementSize === ListElementSize.POINTER) {
|
|
707
|
+
for (let i = 0; i < length; i++) {
|
|
708
|
+
erase(
|
|
709
|
+
new Pointer(
|
|
710
|
+
c.segment,
|
|
711
|
+
c.byteOffset + i * 8,
|
|
712
|
+
p._capnp.depthLimit - 1
|
|
713
|
+
)
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
break;
|
|
717
|
+
} else if (elementSize === ListElementSize.COMPOSITE) {
|
|
718
|
+
const tag = add(-8, c);
|
|
719
|
+
const compositeSize = getStructSize(tag);
|
|
720
|
+
const compositeByteLength = getByteLength(compositeSize);
|
|
721
|
+
contentWords = getOffsetWords(tag);
|
|
722
|
+
c.segment.setWordZero(c.byteOffset - 8);
|
|
723
|
+
for (let i = 0; i < length; i++) {
|
|
724
|
+
for (let j = 0; j < compositeSize.pointerLength; j++) {
|
|
725
|
+
erase(
|
|
726
|
+
new Pointer(
|
|
727
|
+
c.segment,
|
|
728
|
+
c.byteOffset + i * compositeByteLength + j * 8,
|
|
729
|
+
p._capnp.depthLimit - 1
|
|
730
|
+
)
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
c.segment.fillZeroWords(c.byteOffset, contentWords);
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
case PointerType.OTHER: {
|
|
739
|
+
break;
|
|
740
|
+
}
|
|
741
|
+
default: {
|
|
742
|
+
throw new Error(
|
|
743
|
+
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
744
|
+
);
|
|
930
745
|
}
|
|
931
|
-
r += `${" ".repeat((17 - k) * 3)}${s}`;
|
|
932
|
-
}
|
|
933
|
-
r += "\n";
|
|
934
|
-
if (byteLength !== b.byteLength) {
|
|
935
|
-
r += format("=== (truncated %d bytes) ===\n", b.byteLength - byteLength);
|
|
936
746
|
}
|
|
937
|
-
|
|
747
|
+
erasePointer(p);
|
|
938
748
|
}
|
|
939
|
-
__name(
|
|
940
|
-
function
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
let leadingZero = false;
|
|
948
|
-
let precision;
|
|
949
|
-
let result = "";
|
|
950
|
-
function nextArg() {
|
|
951
|
-
return args[argIndex++];
|
|
749
|
+
__name(erase, "erase");
|
|
750
|
+
function erasePointer(p) {
|
|
751
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
752
|
+
const landingPad = followFar(p);
|
|
753
|
+
if (isDoubleFar(p)) {
|
|
754
|
+
landingPad.segment.setWordZero(landingPad.byteOffset + 8);
|
|
755
|
+
}
|
|
756
|
+
landingPad.segment.setWordZero(landingPad.byteOffset);
|
|
952
757
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
758
|
+
p.segment.setWordZero(p.byteOffset);
|
|
759
|
+
}
|
|
760
|
+
__name(erasePointer, "erasePointer");
|
|
761
|
+
function followFar(p) {
|
|
762
|
+
const targetSegment = p.segment.message.getSegment(
|
|
763
|
+
p.segment.getUint32(p.byteOffset + 4)
|
|
764
|
+
);
|
|
765
|
+
const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;
|
|
766
|
+
return new Pointer(
|
|
767
|
+
targetSegment,
|
|
768
|
+
targetWordOffset * 8,
|
|
769
|
+
p._capnp.depthLimit - 1
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
__name(followFar, "followFar");
|
|
773
|
+
function followFars(p) {
|
|
774
|
+
if (getPointerType(p) === PointerType.FAR) {
|
|
775
|
+
const landingPad = followFar(p);
|
|
776
|
+
if (isDoubleFar(p)) {
|
|
777
|
+
landingPad.byteOffset += 8;
|
|
959
778
|
}
|
|
960
|
-
return
|
|
779
|
+
return landingPad;
|
|
961
780
|
}
|
|
962
|
-
|
|
963
|
-
for (; i < n; ++i) {
|
|
964
|
-
c = s[i];
|
|
965
|
-
if (escaped) {
|
|
966
|
-
escaped = false;
|
|
967
|
-
if (c === ".") {
|
|
968
|
-
leadingZero = false;
|
|
969
|
-
c = s[++i];
|
|
970
|
-
} else if (c === "0" && s[i + 1] === ".") {
|
|
971
|
-
leadingZero = true;
|
|
972
|
-
i += 2;
|
|
973
|
-
c = s[i];
|
|
974
|
-
} else {
|
|
975
|
-
leadingZero = true;
|
|
976
|
-
}
|
|
977
|
-
precision = slurpNumber();
|
|
978
|
-
switch (c) {
|
|
979
|
-
case "a": {
|
|
980
|
-
result += "0x" + pad(Number.parseInt(String(nextArg()), 10).toString(16), 8);
|
|
981
|
-
break;
|
|
982
|
-
}
|
|
983
|
-
case "b": {
|
|
984
|
-
result += Number.parseInt(String(nextArg()), 10).toString(2);
|
|
985
|
-
break;
|
|
986
|
-
}
|
|
987
|
-
case "c": {
|
|
988
|
-
arg = nextArg();
|
|
989
|
-
result += typeof arg === "string" || arg instanceof String ? arg : String.fromCharCode(Number.parseInt(String(arg), 10));
|
|
990
|
-
break;
|
|
991
|
-
}
|
|
992
|
-
case "d": {
|
|
993
|
-
result += Number.parseInt(String(nextArg()), 10);
|
|
994
|
-
break;
|
|
995
|
-
}
|
|
996
|
-
case "f": {
|
|
997
|
-
const tmp = Number.parseFloat(String(nextArg())).toFixed(
|
|
998
|
-
precision || 6
|
|
999
|
-
);
|
|
1000
|
-
result += leadingZero ? tmp : tmp.replace(/^0/, "");
|
|
1001
|
-
break;
|
|
1002
|
-
}
|
|
1003
|
-
case "j": {
|
|
1004
|
-
result += JSON.stringify(nextArg());
|
|
1005
|
-
break;
|
|
1006
|
-
}
|
|
1007
|
-
case "o": {
|
|
1008
|
-
result += "0" + Number.parseInt(String(nextArg()), 10).toString(8);
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
case "s": {
|
|
1012
|
-
result += nextArg();
|
|
1013
|
-
break;
|
|
1014
|
-
}
|
|
1015
|
-
case "x": {
|
|
1016
|
-
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16);
|
|
1017
|
-
break;
|
|
1018
|
-
}
|
|
1019
|
-
case "X": {
|
|
1020
|
-
result += "0x" + Number.parseInt(String(nextArg()), 10).toString(16).toUpperCase();
|
|
1021
|
-
break;
|
|
1022
|
-
}
|
|
1023
|
-
default: {
|
|
1024
|
-
result += c;
|
|
1025
|
-
break;
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
} else if (c === "%") {
|
|
1029
|
-
escaped = true;
|
|
1030
|
-
} else {
|
|
1031
|
-
result += c;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
return result;
|
|
781
|
+
return p;
|
|
1035
782
|
}
|
|
1036
|
-
__name(
|
|
1037
|
-
function
|
|
1038
|
-
return
|
|
783
|
+
__name(followFars, "followFars");
|
|
784
|
+
function getCapabilityId(p) {
|
|
785
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
1039
786
|
}
|
|
1040
|
-
__name(
|
|
1041
|
-
function
|
|
1042
|
-
return
|
|
787
|
+
__name(getCapabilityId, "getCapabilityId");
|
|
788
|
+
function isCompositeList(p) {
|
|
789
|
+
return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
|
|
1043
790
|
}
|
|
1044
|
-
__name(
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
791
|
+
__name(isCompositeList, "isCompositeList");
|
|
792
|
+
function getContent(p, ignoreCompositeIndex) {
|
|
793
|
+
let c;
|
|
794
|
+
if (isDoubleFar(p)) {
|
|
795
|
+
const landingPad = followFar(p);
|
|
796
|
+
c = new Pointer(
|
|
797
|
+
p.segment.message.getSegment(getFarSegmentId(landingPad)),
|
|
798
|
+
getOffsetWords(landingPad) * 8
|
|
799
|
+
);
|
|
800
|
+
} else {
|
|
801
|
+
const target = followFars(p);
|
|
802
|
+
c = new Pointer(
|
|
803
|
+
target.segment,
|
|
804
|
+
target.byteOffset + 8 + getOffsetWords(target) * 8
|
|
805
|
+
);
|
|
1048
806
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
*
|
|
1052
|
-
* @param dataByteLength - The number of bytes in the data section of the struct
|
|
1053
|
-
* @param pointerLength - The number of pointers in the pointer section of the struct
|
|
1054
|
-
*/
|
|
1055
|
-
constructor(dataByteLength, pointerLength) {
|
|
1056
|
-
this.dataByteLength = dataByteLength;
|
|
1057
|
-
this.pointerLength = pointerLength;
|
|
807
|
+
if (isCompositeList(p)) {
|
|
808
|
+
c.byteOffset += 8;
|
|
1058
809
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
getDataWordLength(this),
|
|
1063
|
-
this.pointerLength
|
|
1064
|
-
);
|
|
810
|
+
if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
|
|
811
|
+
c.byteOffset -= 8;
|
|
812
|
+
c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
|
|
1065
813
|
}
|
|
1066
|
-
|
|
1067
|
-
function getByteLength(o) {
|
|
1068
|
-
return o.dataByteLength + o.pointerLength * 8;
|
|
814
|
+
return c;
|
|
1069
815
|
}
|
|
1070
|
-
__name(
|
|
1071
|
-
function
|
|
1072
|
-
return
|
|
816
|
+
__name(getContent, "getContent");
|
|
817
|
+
function getFarSegmentId(p) {
|
|
818
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
1073
819
|
}
|
|
1074
|
-
__name(
|
|
1075
|
-
function
|
|
1076
|
-
return
|
|
820
|
+
__name(getFarSegmentId, "getFarSegmentId");
|
|
821
|
+
function getListElementSize(p) {
|
|
822
|
+
return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1077
823
|
}
|
|
1078
|
-
__name(
|
|
1079
|
-
function
|
|
1080
|
-
return
|
|
824
|
+
__name(getListElementSize, "getListElementSize");
|
|
825
|
+
function getListLength(p) {
|
|
826
|
+
return p.segment.getUint32(p.byteOffset + 4) >>> 3;
|
|
1081
827
|
}
|
|
1082
|
-
__name(
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
828
|
+
__name(getListLength, "getListLength");
|
|
829
|
+
function getOffsetWords(p) {
|
|
830
|
+
const o = p.segment.getInt32(p.byteOffset);
|
|
831
|
+
return o & 2 ? o >> 3 : o >> 2;
|
|
832
|
+
}
|
|
833
|
+
__name(getOffsetWords, "getOffsetWords");
|
|
834
|
+
function getPointerType(p) {
|
|
835
|
+
return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
|
|
836
|
+
}
|
|
837
|
+
__name(getPointerType, "getPointerType");
|
|
838
|
+
function getStructDataWords(p) {
|
|
839
|
+
return p.segment.getUint16(p.byteOffset + 4);
|
|
840
|
+
}
|
|
841
|
+
__name(getStructDataWords, "getStructDataWords");
|
|
842
|
+
function getStructPointerLength(p) {
|
|
843
|
+
return p.segment.getUint16(p.byteOffset + 6);
|
|
844
|
+
}
|
|
845
|
+
__name(getStructPointerLength, "getStructPointerLength");
|
|
846
|
+
function getStructSize(p) {
|
|
847
|
+
return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
|
|
848
|
+
}
|
|
849
|
+
__name(getStructSize, "getStructSize");
|
|
850
|
+
function getTargetCompositeListTag(p) {
|
|
851
|
+
const c = getContent(p);
|
|
852
|
+
c.byteOffset -= 8;
|
|
853
|
+
return c;
|
|
854
|
+
}
|
|
855
|
+
__name(getTargetCompositeListTag, "getTargetCompositeListTag");
|
|
856
|
+
function getTargetCompositeListSize(p) {
|
|
857
|
+
return getStructSize(getTargetCompositeListTag(p));
|
|
858
|
+
}
|
|
859
|
+
__name(getTargetCompositeListSize, "getTargetCompositeListSize");
|
|
860
|
+
function getTargetListElementSize(p) {
|
|
861
|
+
return getListElementSize(followFars(p));
|
|
862
|
+
}
|
|
863
|
+
__name(getTargetListElementSize, "getTargetListElementSize");
|
|
864
|
+
function getTargetListLength(p) {
|
|
865
|
+
const t = followFars(p);
|
|
866
|
+
if (getListElementSize(t) === ListElementSize.COMPOSITE) {
|
|
867
|
+
return getOffsetWords(getTargetCompositeListTag(p));
|
|
1086
868
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
this.byteOffset = c.byteOffset;
|
|
1095
|
-
this._capnp = {};
|
|
1096
|
-
this._capnp.type = getTargetPointerType(src);
|
|
1097
|
-
switch (this._capnp.type) {
|
|
1098
|
-
case PointerType.STRUCT: {
|
|
1099
|
-
this._capnp.size = getTargetStructSize(src);
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
case PointerType.LIST: {
|
|
1103
|
-
this._capnp.length = getTargetListLength(src);
|
|
1104
|
-
this._capnp.elementSize = getTargetListElementSize(src);
|
|
1105
|
-
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
1106
|
-
this._capnp.size = getTargetCompositeListSize(src);
|
|
1107
|
-
}
|
|
1108
|
-
break;
|
|
1109
|
-
}
|
|
1110
|
-
case PointerType.OTHER: {
|
|
1111
|
-
this._capnp.capId = getCapabilityId(src);
|
|
1112
|
-
break;
|
|
1113
|
-
}
|
|
1114
|
-
default: {
|
|
1115
|
-
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
erasePointer(src);
|
|
869
|
+
return getListLength(t);
|
|
870
|
+
}
|
|
871
|
+
__name(getTargetListLength, "getTargetListLength");
|
|
872
|
+
function getTargetPointerType(p) {
|
|
873
|
+
const t = getPointerType(followFars(p));
|
|
874
|
+
if (t === PointerType.FAR) {
|
|
875
|
+
throw new Error(format(PTR_INVALID_FAR_TARGET, p));
|
|
1119
876
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
877
|
+
return t;
|
|
878
|
+
}
|
|
879
|
+
__name(getTargetPointerType, "getTargetPointerType");
|
|
880
|
+
function getTargetStructSize(p) {
|
|
881
|
+
return getStructSize(followFars(p));
|
|
882
|
+
}
|
|
883
|
+
__name(getTargetStructSize, "getTargetStructSize");
|
|
884
|
+
function initPointer(contentSegment, contentOffset, p) {
|
|
885
|
+
if (p.segment !== contentSegment) {
|
|
886
|
+
if (!contentSegment.hasCapacity(8)) {
|
|
887
|
+
const landingPad2 = p.segment.allocate(16);
|
|
888
|
+
setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
|
|
889
|
+
setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
|
|
890
|
+
landingPad2.byteOffset += 8;
|
|
891
|
+
return new PointerAllocationResult(landingPad2, 0);
|
|
1128
892
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
893
|
+
const landingPad = contentSegment.allocate(8);
|
|
894
|
+
if (landingPad.segment.id !== contentSegment.id) {
|
|
895
|
+
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
|
1131
896
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
setStructPointer(res.offsetWords, this._capnp.size, res.pointer);
|
|
1137
|
-
break;
|
|
1138
|
-
}
|
|
1139
|
-
case PointerType.LIST: {
|
|
1140
|
-
let { offsetWords } = res;
|
|
1141
|
-
if (this._capnp.elementSize === ListElementSize.COMPOSITE) {
|
|
1142
|
-
offsetWords--;
|
|
1143
|
-
}
|
|
1144
|
-
setListPointer(
|
|
1145
|
-
offsetWords,
|
|
1146
|
-
this._capnp.elementSize,
|
|
1147
|
-
this._capnp.length,
|
|
1148
|
-
res.pointer,
|
|
1149
|
-
this._capnp.size
|
|
1150
|
-
);
|
|
1151
|
-
break;
|
|
1152
|
-
}
|
|
1153
|
-
case PointerType.OTHER: {
|
|
1154
|
-
setInterfacePointer(this._capnp.capId, res.pointer);
|
|
1155
|
-
break;
|
|
1156
|
-
}
|
|
1157
|
-
/* istanbul ignore next */
|
|
1158
|
-
default: {
|
|
1159
|
-
throw new Error(PTR_INVALID_POINTER_TYPE);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
this._capnp = void 0;
|
|
1163
|
-
}
|
|
1164
|
-
dispose() {
|
|
1165
|
-
if (this._capnp === void 0) {
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
switch (this._capnp.type) {
|
|
1169
|
-
case PointerType.STRUCT: {
|
|
1170
|
-
this.segment.fillZeroWords(
|
|
1171
|
-
this.byteOffset,
|
|
1172
|
-
getWordLength(this._capnp.size)
|
|
1173
|
-
);
|
|
1174
|
-
break;
|
|
1175
|
-
}
|
|
1176
|
-
case PointerType.LIST: {
|
|
1177
|
-
const byteLength = getListByteLength(
|
|
1178
|
-
this._capnp.elementSize,
|
|
1179
|
-
this._capnp.length,
|
|
1180
|
-
this._capnp.size
|
|
1181
|
-
);
|
|
1182
|
-
this.segment.fillZeroWords(this.byteOffset, byteLength);
|
|
1183
|
-
break;
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
this._capnp = void 0;
|
|
1187
|
-
}
|
|
1188
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1189
|
-
return format(
|
|
1190
|
-
"Orphan_%d@%a,type:%s",
|
|
1191
|
-
this.segment.id,
|
|
1192
|
-
this.byteOffset,
|
|
1193
|
-
this._capnp && this._capnp.type
|
|
897
|
+
setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
|
|
898
|
+
return new PointerAllocationResult(
|
|
899
|
+
landingPad,
|
|
900
|
+
(contentOffset - landingPad.byteOffset - 8) / 8
|
|
1194
901
|
);
|
|
1195
902
|
}
|
|
1196
|
-
|
|
1197
|
-
function adopt(src, p) {
|
|
1198
|
-
src._moveTo(p);
|
|
903
|
+
return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
|
|
1199
904
|
}
|
|
1200
|
-
__name(
|
|
1201
|
-
function
|
|
1202
|
-
return
|
|
905
|
+
__name(initPointer, "initPointer");
|
|
906
|
+
function isDoubleFar(p) {
|
|
907
|
+
return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
|
|
1203
908
|
}
|
|
1204
|
-
__name(
|
|
1205
|
-
function
|
|
1206
|
-
return
|
|
909
|
+
__name(isDoubleFar, "isDoubleFar");
|
|
910
|
+
function isNull(p) {
|
|
911
|
+
return p.segment.isWordZero(p.byteOffset);
|
|
1207
912
|
}
|
|
1208
|
-
__name(
|
|
1209
|
-
function
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
case ListElementSize.BYTE_4:
|
|
1217
|
-
case ListElementSize.BYTE_8:
|
|
1218
|
-
case ListElementSize.POINTER:
|
|
1219
|
-
case ListElementSize.VOID: {
|
|
1220
|
-
return padToWord$1(getListElementByteLength(elementSize) * length);
|
|
1221
|
-
}
|
|
1222
|
-
/* istanbul ignore next */
|
|
1223
|
-
case ListElementSize.COMPOSITE: {
|
|
1224
|
-
if (compositeSize === void 0) {
|
|
1225
|
-
throw new Error(format(PTR_INVALID_LIST_SIZE, Number.NaN));
|
|
1226
|
-
}
|
|
1227
|
-
return length * padToWord$1(getByteLength(compositeSize));
|
|
1228
|
-
}
|
|
1229
|
-
/* istanbul ignore next */
|
|
1230
|
-
default: {
|
|
1231
|
-
throw new Error(PTR_INVALID_LIST_SIZE);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
913
|
+
__name(isNull, "isNull");
|
|
914
|
+
function setFarPointer(doubleFar, offsetWords, segmentId, p) {
|
|
915
|
+
const A = PointerType.FAR;
|
|
916
|
+
const B = doubleFar ? 1 : 0;
|
|
917
|
+
const C = offsetWords;
|
|
918
|
+
const D = segmentId;
|
|
919
|
+
p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
|
|
920
|
+
p.segment.setUint32(p.byteOffset + 4, D);
|
|
1234
921
|
}
|
|
1235
|
-
__name(
|
|
1236
|
-
function
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
return 8;
|
|
1254
|
-
}
|
|
1255
|
-
/* istanbul ignore next */
|
|
1256
|
-
case ListElementSize.COMPOSITE: {
|
|
1257
|
-
return Number.NaN;
|
|
1258
|
-
}
|
|
1259
|
-
/* istanbul ignore next */
|
|
1260
|
-
case ListElementSize.VOID: {
|
|
1261
|
-
return 0;
|
|
1262
|
-
}
|
|
1263
|
-
/* istanbul ignore next */
|
|
1264
|
-
default: {
|
|
1265
|
-
throw new Error(format(PTR_INVALID_LIST_SIZE, elementSize));
|
|
922
|
+
__name(setFarPointer, "setFarPointer");
|
|
923
|
+
function setInterfacePointer(capId, p) {
|
|
924
|
+
p.segment.setUint32(p.byteOffset, PointerType.OTHER);
|
|
925
|
+
p.segment.setUint32(p.byteOffset + 4, capId);
|
|
926
|
+
}
|
|
927
|
+
__name(setInterfacePointer, "setInterfacePointer");
|
|
928
|
+
function getInterfacePointer(p) {
|
|
929
|
+
return p.segment.getUint32(p.byteOffset + 4);
|
|
930
|
+
}
|
|
931
|
+
__name(getInterfacePointer, "getInterfacePointer");
|
|
932
|
+
function setListPointer(offsetWords, size, length, p, compositeSize) {
|
|
933
|
+
const A = PointerType.LIST;
|
|
934
|
+
const B = offsetWords;
|
|
935
|
+
const C = size;
|
|
936
|
+
let D = length;
|
|
937
|
+
if (size === ListElementSize.COMPOSITE) {
|
|
938
|
+
if (compositeSize === void 0) {
|
|
939
|
+
throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
|
|
1266
940
|
}
|
|
941
|
+
D *= getWordLength(compositeSize);
|
|
1267
942
|
}
|
|
943
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
944
|
+
p.segment.setUint32(p.byteOffset + 4, C | D << 3);
|
|
1268
945
|
}
|
|
1269
|
-
__name(
|
|
1270
|
-
function
|
|
1271
|
-
|
|
946
|
+
__name(setListPointer, "setListPointer");
|
|
947
|
+
function setStructPointer(offsetWords, size, p) {
|
|
948
|
+
const A = PointerType.STRUCT;
|
|
949
|
+
const B = offsetWords;
|
|
950
|
+
const C = getDataWordLength(size);
|
|
951
|
+
const D = size.pointerLength;
|
|
952
|
+
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
953
|
+
p.segment.setUint16(p.byteOffset + 4, C);
|
|
954
|
+
p.segment.setUint16(p.byteOffset + 6, D);
|
|
1272
955
|
}
|
|
1273
|
-
__name(
|
|
1274
|
-
function
|
|
1275
|
-
if (p
|
|
956
|
+
__name(setStructPointer, "setStructPointer");
|
|
957
|
+
function validate(pointerType, p, elementSize) {
|
|
958
|
+
if (isNull(p)) {
|
|
1276
959
|
return;
|
|
1277
960
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
copyFromList(src, p);
|
|
1287
|
-
break;
|
|
1288
|
-
}
|
|
1289
|
-
case PointerType.OTHER: {
|
|
1290
|
-
copyFromInterface(src, p);
|
|
1291
|
-
break;
|
|
1292
|
-
}
|
|
1293
|
-
/* istanbul ignore next */
|
|
1294
|
-
default: {
|
|
961
|
+
const t = followFars(p);
|
|
962
|
+
const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;
|
|
963
|
+
if (A !== pointerType) {
|
|
964
|
+
throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
|
|
965
|
+
}
|
|
966
|
+
if (elementSize !== void 0) {
|
|
967
|
+
const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;
|
|
968
|
+
if (C !== elementSize) {
|
|
1295
969
|
throw new Error(
|
|
1296
|
-
format(
|
|
1297
|
-
);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
__name(copyFrom, "copyFrom");
|
|
1302
|
-
function erase(p) {
|
|
1303
|
-
if (isNull(p)) return;
|
|
1304
|
-
let c;
|
|
1305
|
-
switch (getTargetPointerType(p)) {
|
|
1306
|
-
case PointerType.STRUCT: {
|
|
1307
|
-
const size = getTargetStructSize(p);
|
|
1308
|
-
c = getContent(p);
|
|
1309
|
-
c.segment.fillZeroWords(c.byteOffset, size.dataByteLength / 8);
|
|
1310
|
-
for (let i = 0; i < size.pointerLength; i++) {
|
|
1311
|
-
erase(add(i * 8, c));
|
|
1312
|
-
}
|
|
1313
|
-
break;
|
|
1314
|
-
}
|
|
1315
|
-
case PointerType.LIST: {
|
|
1316
|
-
const elementSize = getTargetListElementSize(p);
|
|
1317
|
-
const length = getTargetListLength(p);
|
|
1318
|
-
let contentWords = padToWord$1(
|
|
1319
|
-
length * getListElementByteLength(elementSize)
|
|
1320
|
-
);
|
|
1321
|
-
c = getContent(p);
|
|
1322
|
-
if (elementSize === ListElementSize.POINTER) {
|
|
1323
|
-
for (let i = 0; i < length; i++) {
|
|
1324
|
-
erase(
|
|
1325
|
-
new Pointer(
|
|
1326
|
-
c.segment,
|
|
1327
|
-
c.byteOffset + i * 8,
|
|
1328
|
-
p._capnp.depthLimit - 1
|
|
1329
|
-
)
|
|
1330
|
-
);
|
|
1331
|
-
}
|
|
1332
|
-
break;
|
|
1333
|
-
} else if (elementSize === ListElementSize.COMPOSITE) {
|
|
1334
|
-
const tag = add(-8, c);
|
|
1335
|
-
const compositeSize = getStructSize(tag);
|
|
1336
|
-
const compositeByteLength = getByteLength(compositeSize);
|
|
1337
|
-
contentWords = getOffsetWords(tag);
|
|
1338
|
-
c.segment.setWordZero(c.byteOffset - 8);
|
|
1339
|
-
for (let i = 0; i < length; i++) {
|
|
1340
|
-
for (let j = 0; j < compositeSize.pointerLength; j++) {
|
|
1341
|
-
erase(
|
|
1342
|
-
new Pointer(
|
|
1343
|
-
c.segment,
|
|
1344
|
-
c.byteOffset + i * compositeByteLength + j * 8,
|
|
1345
|
-
p._capnp.depthLimit - 1
|
|
1346
|
-
)
|
|
1347
|
-
);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
c.segment.fillZeroWords(c.byteOffset, contentWords);
|
|
1352
|
-
break;
|
|
1353
|
-
}
|
|
1354
|
-
case PointerType.OTHER: {
|
|
1355
|
-
break;
|
|
1356
|
-
}
|
|
1357
|
-
default: {
|
|
1358
|
-
throw new Error(
|
|
1359
|
-
format(PTR_INVALID_POINTER_TYPE, getTargetPointerType(p))
|
|
1360
|
-
);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
erasePointer(p);
|
|
1364
|
-
}
|
|
1365
|
-
__name(erase, "erase");
|
|
1366
|
-
function erasePointer(p) {
|
|
1367
|
-
if (getPointerType(p) === PointerType.FAR) {
|
|
1368
|
-
const landingPad = followFar(p);
|
|
1369
|
-
if (isDoubleFar(p)) {
|
|
1370
|
-
landingPad.segment.setWordZero(landingPad.byteOffset + 8);
|
|
1371
|
-
}
|
|
1372
|
-
landingPad.segment.setWordZero(landingPad.byteOffset);
|
|
1373
|
-
}
|
|
1374
|
-
p.segment.setWordZero(p.byteOffset);
|
|
1375
|
-
}
|
|
1376
|
-
__name(erasePointer, "erasePointer");
|
|
1377
|
-
function followFar(p) {
|
|
1378
|
-
const targetSegment = p.segment.message.getSegment(
|
|
1379
|
-
p.segment.getUint32(p.byteOffset + 4)
|
|
1380
|
-
);
|
|
1381
|
-
const targetWordOffset = p.segment.getUint32(p.byteOffset) >>> 3;
|
|
1382
|
-
return new Pointer(
|
|
1383
|
-
targetSegment,
|
|
1384
|
-
targetWordOffset * 8,
|
|
1385
|
-
p._capnp.depthLimit - 1
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
1388
|
-
__name(followFar, "followFar");
|
|
1389
|
-
function followFars(p) {
|
|
1390
|
-
if (getPointerType(p) === PointerType.FAR) {
|
|
1391
|
-
const landingPad = followFar(p);
|
|
1392
|
-
if (isDoubleFar(p)) {
|
|
1393
|
-
landingPad.byteOffset += 8;
|
|
1394
|
-
}
|
|
1395
|
-
return landingPad;
|
|
1396
|
-
}
|
|
1397
|
-
return p;
|
|
1398
|
-
}
|
|
1399
|
-
__name(followFars, "followFars");
|
|
1400
|
-
function getCapabilityId(p) {
|
|
1401
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1402
|
-
}
|
|
1403
|
-
__name(getCapabilityId, "getCapabilityId");
|
|
1404
|
-
function isCompositeList(p) {
|
|
1405
|
-
return getTargetPointerType(p) === PointerType.LIST && getTargetListElementSize(p) === ListElementSize.COMPOSITE;
|
|
1406
|
-
}
|
|
1407
|
-
__name(isCompositeList, "isCompositeList");
|
|
1408
|
-
function getContent(p, ignoreCompositeIndex) {
|
|
1409
|
-
let c;
|
|
1410
|
-
if (isDoubleFar(p)) {
|
|
1411
|
-
const landingPad = followFar(p);
|
|
1412
|
-
c = new Pointer(
|
|
1413
|
-
p.segment.message.getSegment(getFarSegmentId(landingPad)),
|
|
1414
|
-
getOffsetWords(landingPad) * 8
|
|
1415
|
-
);
|
|
1416
|
-
} else {
|
|
1417
|
-
const target = followFars(p);
|
|
1418
|
-
c = new Pointer(
|
|
1419
|
-
target.segment,
|
|
1420
|
-
target.byteOffset + 8 + getOffsetWords(target) * 8
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
if (isCompositeList(p)) {
|
|
1424
|
-
c.byteOffset += 8;
|
|
1425
|
-
}
|
|
1426
|
-
if (!ignoreCompositeIndex && p._capnp.compositeIndex !== void 0) {
|
|
1427
|
-
c.byteOffset -= 8;
|
|
1428
|
-
c.byteOffset += 8 + p._capnp.compositeIndex * getByteLength(padToWord(getStructSize(c)));
|
|
1429
|
-
}
|
|
1430
|
-
return c;
|
|
1431
|
-
}
|
|
1432
|
-
__name(getContent, "getContent");
|
|
1433
|
-
function getFarSegmentId(p) {
|
|
1434
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1435
|
-
}
|
|
1436
|
-
__name(getFarSegmentId, "getFarSegmentId");
|
|
1437
|
-
function getListElementSize(p) {
|
|
1438
|
-
return p.segment.getUint32(p.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1439
|
-
}
|
|
1440
|
-
__name(getListElementSize, "getListElementSize");
|
|
1441
|
-
function getListLength(p) {
|
|
1442
|
-
return p.segment.getUint32(p.byteOffset + 4) >>> 3;
|
|
1443
|
-
}
|
|
1444
|
-
__name(getListLength, "getListLength");
|
|
1445
|
-
function getOffsetWords(p) {
|
|
1446
|
-
const o = p.segment.getInt32(p.byteOffset);
|
|
1447
|
-
return o & 2 ? o >> 3 : o >> 2;
|
|
1448
|
-
}
|
|
1449
|
-
__name(getOffsetWords, "getOffsetWords");
|
|
1450
|
-
function getPointerType(p) {
|
|
1451
|
-
return p.segment.getUint32(p.byteOffset) & POINTER_TYPE_MASK;
|
|
1452
|
-
}
|
|
1453
|
-
__name(getPointerType, "getPointerType");
|
|
1454
|
-
function getStructDataWords(p) {
|
|
1455
|
-
return p.segment.getUint16(p.byteOffset + 4);
|
|
1456
|
-
}
|
|
1457
|
-
__name(getStructDataWords, "getStructDataWords");
|
|
1458
|
-
function getStructPointerLength(p) {
|
|
1459
|
-
return p.segment.getUint16(p.byteOffset + 6);
|
|
1460
|
-
}
|
|
1461
|
-
__name(getStructPointerLength, "getStructPointerLength");
|
|
1462
|
-
function getStructSize(p) {
|
|
1463
|
-
return new ObjectSize(getStructDataWords(p) * 8, getStructPointerLength(p));
|
|
1464
|
-
}
|
|
1465
|
-
__name(getStructSize, "getStructSize");
|
|
1466
|
-
function getTargetCompositeListTag(p) {
|
|
1467
|
-
const c = getContent(p);
|
|
1468
|
-
c.byteOffset -= 8;
|
|
1469
|
-
return c;
|
|
1470
|
-
}
|
|
1471
|
-
__name(getTargetCompositeListTag, "getTargetCompositeListTag");
|
|
1472
|
-
function getTargetCompositeListSize(p) {
|
|
1473
|
-
return getStructSize(getTargetCompositeListTag(p));
|
|
1474
|
-
}
|
|
1475
|
-
__name(getTargetCompositeListSize, "getTargetCompositeListSize");
|
|
1476
|
-
function getTargetListElementSize(p) {
|
|
1477
|
-
return getListElementSize(followFars(p));
|
|
1478
|
-
}
|
|
1479
|
-
__name(getTargetListElementSize, "getTargetListElementSize");
|
|
1480
|
-
function getTargetListLength(p) {
|
|
1481
|
-
const t = followFars(p);
|
|
1482
|
-
if (getListElementSize(t) === ListElementSize.COMPOSITE) {
|
|
1483
|
-
return getOffsetWords(getTargetCompositeListTag(p));
|
|
1484
|
-
}
|
|
1485
|
-
return getListLength(t);
|
|
1486
|
-
}
|
|
1487
|
-
__name(getTargetListLength, "getTargetListLength");
|
|
1488
|
-
function getTargetPointerType(p) {
|
|
1489
|
-
const t = getPointerType(followFars(p));
|
|
1490
|
-
if (t === PointerType.FAR) {
|
|
1491
|
-
throw new Error(format(PTR_INVALID_FAR_TARGET, p));
|
|
1492
|
-
}
|
|
1493
|
-
return t;
|
|
1494
|
-
}
|
|
1495
|
-
__name(getTargetPointerType, "getTargetPointerType");
|
|
1496
|
-
function getTargetStructSize(p) {
|
|
1497
|
-
return getStructSize(followFars(p));
|
|
1498
|
-
}
|
|
1499
|
-
__name(getTargetStructSize, "getTargetStructSize");
|
|
1500
|
-
function initPointer(contentSegment, contentOffset, p) {
|
|
1501
|
-
if (p.segment !== contentSegment) {
|
|
1502
|
-
if (!contentSegment.hasCapacity(8)) {
|
|
1503
|
-
const landingPad2 = p.segment.allocate(16);
|
|
1504
|
-
setFarPointer(true, landingPad2.byteOffset / 8, landingPad2.segment.id, p);
|
|
1505
|
-
setFarPointer(false, contentOffset / 8, contentSegment.id, landingPad2);
|
|
1506
|
-
landingPad2.byteOffset += 8;
|
|
1507
|
-
return new PointerAllocationResult(landingPad2, 0);
|
|
1508
|
-
}
|
|
1509
|
-
const landingPad = contentSegment.allocate(8);
|
|
1510
|
-
if (landingPad.segment.id !== contentSegment.id) {
|
|
1511
|
-
throw new Error(INVARIANT_UNREACHABLE_CODE);
|
|
1512
|
-
}
|
|
1513
|
-
setFarPointer(false, landingPad.byteOffset / 8, landingPad.segment.id, p);
|
|
1514
|
-
return new PointerAllocationResult(
|
|
1515
|
-
landingPad,
|
|
1516
|
-
(contentOffset - landingPad.byteOffset - 8) / 8
|
|
1517
|
-
);
|
|
1518
|
-
}
|
|
1519
|
-
return new PointerAllocationResult(p, (contentOffset - p.byteOffset - 8) / 8);
|
|
1520
|
-
}
|
|
1521
|
-
__name(initPointer, "initPointer");
|
|
1522
|
-
function isDoubleFar(p) {
|
|
1523
|
-
return getPointerType(p) === PointerType.FAR && (p.segment.getUint32(p.byteOffset) & POINTER_DOUBLE_FAR_MASK) !== 0;
|
|
1524
|
-
}
|
|
1525
|
-
__name(isDoubleFar, "isDoubleFar");
|
|
1526
|
-
function isNull(p) {
|
|
1527
|
-
return p.segment.isWordZero(p.byteOffset);
|
|
1528
|
-
}
|
|
1529
|
-
__name(isNull, "isNull");
|
|
1530
|
-
function setFarPointer(doubleFar, offsetWords, segmentId, p) {
|
|
1531
|
-
const A = PointerType.FAR;
|
|
1532
|
-
const B = doubleFar ? 1 : 0;
|
|
1533
|
-
const C = offsetWords;
|
|
1534
|
-
const D = segmentId;
|
|
1535
|
-
p.segment.setUint32(p.byteOffset, A | B << 2 | C << 3);
|
|
1536
|
-
p.segment.setUint32(p.byteOffset + 4, D);
|
|
1537
|
-
}
|
|
1538
|
-
__name(setFarPointer, "setFarPointer");
|
|
1539
|
-
function setInterfacePointer(capId, p) {
|
|
1540
|
-
p.segment.setUint32(p.byteOffset, PointerType.OTHER);
|
|
1541
|
-
p.segment.setUint32(p.byteOffset + 4, capId);
|
|
1542
|
-
}
|
|
1543
|
-
__name(setInterfacePointer, "setInterfacePointer");
|
|
1544
|
-
function getInterfacePointer(p) {
|
|
1545
|
-
return p.segment.getUint32(p.byteOffset + 4);
|
|
1546
|
-
}
|
|
1547
|
-
__name(getInterfacePointer, "getInterfacePointer");
|
|
1548
|
-
function setListPointer(offsetWords, size, length, p, compositeSize) {
|
|
1549
|
-
const A = PointerType.LIST;
|
|
1550
|
-
const B = offsetWords;
|
|
1551
|
-
const C = size;
|
|
1552
|
-
let D = length;
|
|
1553
|
-
if (size === ListElementSize.COMPOSITE) {
|
|
1554
|
-
if (compositeSize === void 0) {
|
|
1555
|
-
throw new TypeError(TYPE_COMPOSITE_SIZE_UNDEFINED);
|
|
1556
|
-
}
|
|
1557
|
-
D *= getWordLength(compositeSize);
|
|
1558
|
-
}
|
|
1559
|
-
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
1560
|
-
p.segment.setUint32(p.byteOffset + 4, C | D << 3);
|
|
1561
|
-
}
|
|
1562
|
-
__name(setListPointer, "setListPointer");
|
|
1563
|
-
function setStructPointer(offsetWords, size, p) {
|
|
1564
|
-
const A = PointerType.STRUCT;
|
|
1565
|
-
const B = offsetWords;
|
|
1566
|
-
const C = getDataWordLength(size);
|
|
1567
|
-
const D = size.pointerLength;
|
|
1568
|
-
p.segment.setUint32(p.byteOffset, A | B << 2);
|
|
1569
|
-
p.segment.setUint16(p.byteOffset + 4, C);
|
|
1570
|
-
p.segment.setUint16(p.byteOffset + 6, D);
|
|
1571
|
-
}
|
|
1572
|
-
__name(setStructPointer, "setStructPointer");
|
|
1573
|
-
function validate(pointerType, p, elementSize) {
|
|
1574
|
-
if (isNull(p)) {
|
|
1575
|
-
return;
|
|
1576
|
-
}
|
|
1577
|
-
const t = followFars(p);
|
|
1578
|
-
const A = t.segment.getUint32(t.byteOffset) & POINTER_TYPE_MASK;
|
|
1579
|
-
if (A !== pointerType) {
|
|
1580
|
-
throw new Error(format(PTR_WRONG_POINTER_TYPE, p, pointerType));
|
|
1581
|
-
}
|
|
1582
|
-
if (elementSize !== void 0) {
|
|
1583
|
-
const C = t.segment.getUint32(t.byteOffset + 4) & LIST_SIZE_MASK;
|
|
1584
|
-
if (C !== elementSize) {
|
|
1585
|
-
throw new Error(
|
|
1586
|
-
format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])
|
|
970
|
+
format(PTR_WRONG_LIST_TYPE, p, ListElementSize[elementSize])
|
|
1587
971
|
);
|
|
1588
972
|
}
|
|
1589
973
|
}
|
|
@@ -2602,8 +1986,8 @@ function getStruct(index, StructClass, s, defaultValue) {
|
|
|
2602
1986
|
}
|
|
2603
1987
|
} else {
|
|
2604
1988
|
validate(PointerType.STRUCT, t);
|
|
2605
|
-
const
|
|
2606
|
-
if (
|
|
1989
|
+
const ts2 = getTargetStructSize(t);
|
|
1990
|
+
if (ts2.dataByteLength < StructClass._capnp.size.dataByteLength || ts2.pointerLength < StructClass._capnp.size.pointerLength) {
|
|
2607
1991
|
resize(StructClass._capnp.size, t);
|
|
2608
1992
|
}
|
|
2609
1993
|
}
|
|
@@ -6462,8 +5846,8 @@ __name(dump2, "dump");
|
|
|
6462
5846
|
function getRoot(RootStruct, m) {
|
|
6463
5847
|
const root = new RootStruct(m.getSegment(0), 0);
|
|
6464
5848
|
validate(PointerType.STRUCT, root);
|
|
6465
|
-
const
|
|
6466
|
-
if (
|
|
5849
|
+
const ts2 = getTargetStructSize(root);
|
|
5850
|
+
if (ts2.dataByteLength < RootStruct._capnp.size.dataByteLength || ts2.pointerLength < RootStruct._capnp.size.pointerLength) {
|
|
6467
5851
|
resize(RootStruct._capnp.size, root);
|
|
6468
5852
|
}
|
|
6469
5853
|
return root;
|
|
@@ -7543,340 +6927,1032 @@ function createValue(value) {
|
|
|
7543
6927
|
p = value.data;
|
|
7544
6928
|
break;
|
|
7545
6929
|
}
|
|
7546
|
-
case Value.LIST: {
|
|
7547
|
-
p = value.list;
|
|
7548
|
-
break;
|
|
6930
|
+
case Value.LIST: {
|
|
6931
|
+
p = value.list;
|
|
6932
|
+
break;
|
|
6933
|
+
}
|
|
6934
|
+
case Value.STRUCT: {
|
|
6935
|
+
p = value.struct;
|
|
6936
|
+
break;
|
|
6937
|
+
}
|
|
6938
|
+
case Value.INTERFACE: {
|
|
6939
|
+
testWhich("interface", getUint16(0, value), 17, value);
|
|
6940
|
+
p = getPointer(0, value);
|
|
6941
|
+
break;
|
|
6942
|
+
}
|
|
6943
|
+
default: {
|
|
6944
|
+
throw new Error(format(GEN_SERIALIZE_UNKNOWN_VALUE, value.which()));
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
const message = new Message();
|
|
6948
|
+
message.setRoot(p);
|
|
6949
|
+
const buf = new Uint8Array(message.toPackedArrayBuffer());
|
|
6950
|
+
const values = [];
|
|
6951
|
+
for (let i = 0; i < buf.byteLength; i++) {
|
|
6952
|
+
values.push(`0x${pad(buf[i].toString(16), 2)}`);
|
|
6953
|
+
}
|
|
6954
|
+
return `$.readRawPointer(new Uint8Array([${values.join(",")}]).buffer)`;
|
|
6955
|
+
}
|
|
6956
|
+
__name(createValue, "createValue");
|
|
6957
|
+
function createNestedNodeProperty(node) {
|
|
6958
|
+
const name = getDisplayNamePrefix(node);
|
|
6959
|
+
const initializer = getFullClassName(node);
|
|
6960
|
+
return `static readonly ${name} = ${initializer};`;
|
|
6961
|
+
}
|
|
6962
|
+
__name(createNestedNodeProperty, "createNestedNodeProperty");
|
|
6963
|
+
function generateInterfaceNode(ctx, node) {
|
|
6964
|
+
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
6965
|
+
const fullClassName = getFullClassName(node);
|
|
6966
|
+
const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
|
|
6967
|
+
const nodeId = node.id;
|
|
6968
|
+
const nodeIdHex = nodeId.toString(16);
|
|
6969
|
+
const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
|
|
6970
|
+
const members = [];
|
|
6971
|
+
members.push(
|
|
6972
|
+
...consts.map((node2) => {
|
|
6973
|
+
const name = c2s(getDisplayNamePrefix(node2));
|
|
6974
|
+
const value = createValue(node2.const.value);
|
|
6975
|
+
return `static readonly ${name} = ${value}`;
|
|
6976
|
+
}),
|
|
6977
|
+
...nestedNodes.map((node2) => createNestedNodeProperty(node2)),
|
|
6978
|
+
`static readonly Client = ${fullClassName}$Client;
|
|
6979
|
+
static readonly Server = ${fullClassName}$Server;
|
|
6980
|
+
public static override readonly _capnp = {
|
|
6981
|
+
displayName: "${displayNamePrefix}",
|
|
6982
|
+
id: "${nodeIdHex}",
|
|
6983
|
+
size: new $.ObjectSize(0, 0),
|
|
6984
|
+
}
|
|
6985
|
+
public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
6986
|
+
);
|
|
6987
|
+
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
6988
|
+
const classCode = `
|
|
6989
|
+
${docComment}
|
|
6990
|
+
export class ${fullClassName} extends $.Interface {
|
|
6991
|
+
${members.join("\n")}
|
|
6992
|
+
}`;
|
|
6993
|
+
generateInterfaceClasses(ctx, node);
|
|
6994
|
+
ctx.codeParts.push(classCode);
|
|
6995
|
+
}
|
|
6996
|
+
__name(generateInterfaceNode, "generateInterfaceNode");
|
|
6997
|
+
function generateNode(ctx, node) {
|
|
6998
|
+
const nodeId = node.id;
|
|
6999
|
+
const nodeIdHex = nodeId.toString(16);
|
|
7000
|
+
if (ctx.generatedNodeIds.has(nodeIdHex)) {
|
|
7001
|
+
return;
|
|
7002
|
+
}
|
|
7003
|
+
ctx.generatedNodeIds.add(nodeIdHex);
|
|
7004
|
+
const nestedNodes = node.nestedNodes.map((node2) => lookupNode(ctx, node2));
|
|
7005
|
+
for (const nestedNode of nestedNodes) {
|
|
7006
|
+
generateNode(ctx, nestedNode);
|
|
7007
|
+
}
|
|
7008
|
+
const groupNodes = ctx.nodes.filter(
|
|
7009
|
+
(node2) => node2.scopeId === nodeId && node2._isStruct && node2.struct.isGroup
|
|
7010
|
+
);
|
|
7011
|
+
for (const groupNode of groupNodes) {
|
|
7012
|
+
generateNode(ctx, groupNode);
|
|
7013
|
+
}
|
|
7014
|
+
const nodeType = node.which();
|
|
7015
|
+
switch (nodeType) {
|
|
7016
|
+
case Node.STRUCT: {
|
|
7017
|
+
generateStructNode(ctx, node);
|
|
7018
|
+
break;
|
|
7019
|
+
}
|
|
7020
|
+
case Node.CONST: {
|
|
7021
|
+
break;
|
|
7022
|
+
}
|
|
7023
|
+
case Node.ENUM: {
|
|
7024
|
+
generateEnumNode(
|
|
7025
|
+
ctx,
|
|
7026
|
+
getFullClassName(node),
|
|
7027
|
+
node,
|
|
7028
|
+
node.enum.enumerants.toArray()
|
|
7029
|
+
);
|
|
7030
|
+
break;
|
|
7031
|
+
}
|
|
7032
|
+
case Node.INTERFACE: {
|
|
7033
|
+
generateInterfaceNode(ctx, node);
|
|
7034
|
+
break;
|
|
7035
|
+
}
|
|
7036
|
+
case Node.ANNOTATION: {
|
|
7037
|
+
break;
|
|
7038
|
+
}
|
|
7039
|
+
// case s.Node.FILE:
|
|
7040
|
+
default: {
|
|
7041
|
+
throw new Error(
|
|
7042
|
+
format(
|
|
7043
|
+
GEN_NODE_UNKNOWN_TYPE,
|
|
7044
|
+
nodeType
|
|
7045
|
+
/* s.Node_Which[whichNode] */
|
|
7046
|
+
)
|
|
7047
|
+
);
|
|
7048
|
+
}
|
|
7049
|
+
}
|
|
7050
|
+
}
|
|
7051
|
+
__name(generateNode, "generateNode");
|
|
7052
|
+
var CodeGeneratorContext = class {
|
|
7053
|
+
static {
|
|
7054
|
+
__name(this, "CodeGeneratorContext");
|
|
7055
|
+
}
|
|
7056
|
+
files = [];
|
|
7057
|
+
};
|
|
7058
|
+
var CodeGeneratorFileContext = class {
|
|
7059
|
+
static {
|
|
7060
|
+
__name(this, "CodeGeneratorFileContext");
|
|
7061
|
+
}
|
|
7062
|
+
constructor(req, file) {
|
|
7063
|
+
this.req = req;
|
|
7064
|
+
this.file = file;
|
|
7065
|
+
this.nodes = req.nodes.toArray();
|
|
7066
|
+
this.imports = file.imports.toArray();
|
|
7067
|
+
}
|
|
7068
|
+
// inputs
|
|
7069
|
+
nodes;
|
|
7070
|
+
imports;
|
|
7071
|
+
// outputs
|
|
7072
|
+
concreteLists = [];
|
|
7073
|
+
generatedNodeIds = /* @__PURE__ */ new Set();
|
|
7074
|
+
generatedResultsPromiseIds = /* @__PURE__ */ new Set();
|
|
7075
|
+
tsPath = "";
|
|
7076
|
+
codeParts = [];
|
|
7077
|
+
toString() {
|
|
7078
|
+
return this.file?.filename ?? "CodeGeneratorFileContext()";
|
|
7079
|
+
}
|
|
7080
|
+
};
|
|
7081
|
+
function generateFileId(ctx) {
|
|
7082
|
+
ctx.codeParts.push(
|
|
7083
|
+
`export const _capnpFileId = BigInt("0x${ctx.file.id.toString(16)}");`
|
|
7084
|
+
);
|
|
7085
|
+
}
|
|
7086
|
+
__name(generateFileId, "generateFileId");
|
|
7087
|
+
function generateConcreteListInitializer(ctx, fullClassName, field) {
|
|
7088
|
+
const name = `_${c2t(field.name)}`;
|
|
7089
|
+
const type = getConcreteListType(ctx, field.slot.type);
|
|
7090
|
+
ctx.codeParts.push(`${fullClassName}.${name} = ${type};`);
|
|
7091
|
+
}
|
|
7092
|
+
__name(generateConcreteListInitializer, "generateConcreteListInitializer");
|
|
7093
|
+
function generateCapnpImport(ctx) {
|
|
7094
|
+
const fileNode = lookupNode(ctx, ctx.file);
|
|
7095
|
+
const tsFileId = hexToBigInt(TS_FILE_ID);
|
|
7096
|
+
const tsAnnotationFile = ctx.nodes.find((n) => n.id === tsFileId);
|
|
7097
|
+
const tsImportPathAnnotation = tsAnnotationFile?.nestedNodes.find(
|
|
7098
|
+
(n) => n.name === "importPath"
|
|
7099
|
+
);
|
|
7100
|
+
const importAnnotation = tsImportPathAnnotation && fileNode.annotations.find((a) => a.id === tsImportPathAnnotation.id);
|
|
7101
|
+
const importPath = importAnnotation === void 0 ? "@stryke/capnp" : importAnnotation.value.text;
|
|
7102
|
+
ctx.codeParts.push(`import * as $ from '${importPath}';`);
|
|
7103
|
+
}
|
|
7104
|
+
__name(generateCapnpImport, "generateCapnpImport");
|
|
7105
|
+
function generateNestedImports(ctx) {
|
|
7106
|
+
for (const imp of ctx.imports) {
|
|
7107
|
+
const { name } = imp;
|
|
7108
|
+
let importPath;
|
|
7109
|
+
if (name.startsWith("/capnp/")) {
|
|
7110
|
+
importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
|
|
7111
|
+
} else {
|
|
7112
|
+
importPath = name.replace(/\.capnp$/, "");
|
|
7113
|
+
if (importPath[0] !== ".") {
|
|
7114
|
+
importPath = `./${importPath}`;
|
|
7115
|
+
}
|
|
7116
|
+
}
|
|
7117
|
+
const importNode = lookupNode(ctx, imp);
|
|
7118
|
+
const imports = getImportNodes(ctx, importNode).flatMap((node) => {
|
|
7119
|
+
const fullClassName = getFullClassName(node);
|
|
7120
|
+
if (node._isInterface) {
|
|
7121
|
+
return [fullClassName, `${fullClassName}$Client`];
|
|
7122
|
+
}
|
|
7123
|
+
return fullClassName;
|
|
7124
|
+
}).sort().join(", ");
|
|
7125
|
+
if (imports.length === 0) {
|
|
7126
|
+
continue;
|
|
7127
|
+
}
|
|
7128
|
+
ctx.codeParts.push(`import { ${imports} } from "${importPath}";`);
|
|
7129
|
+
}
|
|
7130
|
+
}
|
|
7131
|
+
__name(generateNestedImports, "generateNestedImports");
|
|
7132
|
+
function getImportNodes(ctx, node, visitedIds = /* @__PURE__ */ new Set()) {
|
|
7133
|
+
visitedIds.add(node.id);
|
|
7134
|
+
const nestedNodes = node.nestedNodes.filter(({ id }) => hasNode(ctx, id));
|
|
7135
|
+
const newNestedNodes = nestedNodes.filter(({ id }) => !visitedIds.has(id));
|
|
7136
|
+
const nodes = newNestedNodes.map(({ id }) => lookupNode(ctx, id)).filter((node2) => node2._isStruct || node2._isEnum || node2._isInterface);
|
|
7137
|
+
return nodes.concat(
|
|
7138
|
+
nodes.flatMap((node2) => getImportNodes(ctx, node2, visitedIds))
|
|
7139
|
+
);
|
|
7140
|
+
}
|
|
7141
|
+
__name(getImportNodes, "getImportNodes");
|
|
7142
|
+
async function compileAll(codeGenRequest, opts) {
|
|
7143
|
+
const req = new Message(codeGenRequest, false).getRoot(
|
|
7144
|
+
CodeGeneratorRequest
|
|
7145
|
+
);
|
|
7146
|
+
const ctx = new CodeGeneratorContext();
|
|
7147
|
+
ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
|
|
7148
|
+
if (ctx.files.length === 0) {
|
|
7149
|
+
throw new Error(GEN_NO_FILES);
|
|
7150
|
+
}
|
|
7151
|
+
const files = new Map(
|
|
7152
|
+
ctx.files.map((file) => [file.tsPath, compileFile(file)])
|
|
7153
|
+
);
|
|
7154
|
+
if (files.size === 0) {
|
|
7155
|
+
throw new Error(GEN_NO_FILES);
|
|
7156
|
+
}
|
|
7157
|
+
if (opts?.dts === true || opts?.js === true) {
|
|
7158
|
+
tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
|
|
7159
|
+
}
|
|
7160
|
+
if (!opts?.ts) {
|
|
7161
|
+
for (const [fileName] of files) {
|
|
7162
|
+
if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
|
|
7163
|
+
files.delete(fileName);
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
return {
|
|
7168
|
+
ctx,
|
|
7169
|
+
files
|
|
7170
|
+
};
|
|
7171
|
+
}
|
|
7172
|
+
__name(compileAll, "compileAll");
|
|
7173
|
+
function compileFile(ctx) {
|
|
7174
|
+
generateCapnpImport(ctx);
|
|
7175
|
+
generateNestedImports(ctx);
|
|
7176
|
+
generateFileId(ctx);
|
|
7177
|
+
const nestedNodes = lookupNode(ctx, ctx.file).nestedNodes.map(
|
|
7178
|
+
(n) => lookupNode(ctx, n)
|
|
7179
|
+
);
|
|
7180
|
+
for (const node of nestedNodes) {
|
|
7181
|
+
generateNode(ctx, node);
|
|
7182
|
+
}
|
|
7183
|
+
for (const [fullClassName, field] of ctx.concreteLists) {
|
|
7184
|
+
generateConcreteListInitializer(ctx, fullClassName, field);
|
|
7185
|
+
}
|
|
7186
|
+
const sourceFile = ts.createSourceFile(
|
|
7187
|
+
ctx.tsPath,
|
|
7188
|
+
ctx.codeParts.map((p) => p.toString()).join(""),
|
|
7189
|
+
ts.ScriptTarget.Latest,
|
|
7190
|
+
false,
|
|
7191
|
+
ts.ScriptKind.TS
|
|
7192
|
+
);
|
|
7193
|
+
return SOURCE_COMMENT + ts.createPrinter().printFile(sourceFile);
|
|
7194
|
+
}
|
|
7195
|
+
__name(compileFile, "compileFile");
|
|
7196
|
+
function tsCompile(files, dts, js, tsconfig) {
|
|
7197
|
+
if (!dts && !js) {
|
|
7198
|
+
return;
|
|
7199
|
+
}
|
|
7200
|
+
const compileOptions = {
|
|
7201
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
7202
|
+
target: ts.ScriptTarget.ESNext,
|
|
7203
|
+
strict: true,
|
|
7204
|
+
...tsconfig,
|
|
7205
|
+
noEmitOnError: false,
|
|
7206
|
+
noFallthroughCasesInSwitch: true,
|
|
7207
|
+
preserveConstEnums: true,
|
|
7208
|
+
noImplicitReturns: true,
|
|
7209
|
+
noUnusedLocals: false,
|
|
7210
|
+
noUnusedParameters: false,
|
|
7211
|
+
removeComments: false,
|
|
7212
|
+
skipLibCheck: true,
|
|
7213
|
+
sourceMap: false,
|
|
7214
|
+
emitDeclarationOnly: dts && !js,
|
|
7215
|
+
declaration: dts
|
|
7216
|
+
};
|
|
7217
|
+
const compilerHost = ts.createCompilerHost(compileOptions);
|
|
7218
|
+
compilerHost.writeFile = (fileName, declaration) => {
|
|
7219
|
+
files.set(fileName, declaration);
|
|
7220
|
+
};
|
|
7221
|
+
const _readFile = compilerHost.readFile;
|
|
7222
|
+
compilerHost.readFile = (filename) => {
|
|
7223
|
+
if (files.has(filename)) {
|
|
7224
|
+
return files.get(filename);
|
|
7225
|
+
}
|
|
7226
|
+
return _readFile(filename);
|
|
7227
|
+
};
|
|
7228
|
+
const program = ts.createProgram(
|
|
7229
|
+
[...files.keys()],
|
|
7230
|
+
compileOptions,
|
|
7231
|
+
compilerHost
|
|
7232
|
+
);
|
|
7233
|
+
const emitResult = program.emit();
|
|
7234
|
+
const allDiagnostics = [
|
|
7235
|
+
...ts.getPreEmitDiagnostics(program),
|
|
7236
|
+
...emitResult.diagnostics
|
|
7237
|
+
];
|
|
7238
|
+
if (allDiagnostics.length > 0) {
|
|
7239
|
+
for (const diagnostic of allDiagnostics) {
|
|
7240
|
+
const message = ts.flattenDiagnosticMessageText(
|
|
7241
|
+
diagnostic.messageText,
|
|
7242
|
+
"\n"
|
|
7243
|
+
);
|
|
7244
|
+
if (diagnostic.file && diagnostic.start) {
|
|
7245
|
+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
7246
|
+
console.log(
|
|
7247
|
+
`${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`
|
|
7248
|
+
);
|
|
7249
|
+
} else {
|
|
7250
|
+
console.log(`==> ${message}`);
|
|
7251
|
+
}
|
|
7252
|
+
}
|
|
7253
|
+
throw new Error(GEN_TS_EMIT_FAILED);
|
|
7254
|
+
}
|
|
7255
|
+
}
|
|
7256
|
+
__name(tsCompile, "tsCompile");
|
|
7257
|
+
|
|
7258
|
+
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/compiler/index.mjs
|
|
7259
|
+
import "typescript";
|
|
7260
|
+
|
|
7261
|
+
// src/compile.ts
|
|
7262
|
+
import defu2 from "defu";
|
|
7263
|
+
import { Buffer as Buffer3 } from "node:buffer";
|
|
7264
|
+
import { exec } from "node:child_process";
|
|
7265
|
+
|
|
7266
|
+
// src/helpers.ts
|
|
7267
|
+
import { writeFatal, writeWarning } from "@storm-software/config-tools/logger/console";
|
|
7268
|
+
|
|
7269
|
+
// ../convert/src/to-array.ts
|
|
7270
|
+
function toArray(array) {
|
|
7271
|
+
array = array ?? [];
|
|
7272
|
+
return Array.isArray(array) ? array : [
|
|
7273
|
+
array
|
|
7274
|
+
];
|
|
7275
|
+
}
|
|
7276
|
+
__name(toArray, "toArray");
|
|
7277
|
+
|
|
7278
|
+
// ../type-checks/src/get-object-tag.ts
|
|
7279
|
+
var getObjectTag = /* @__PURE__ */ __name((value) => {
|
|
7280
|
+
if (value == null) {
|
|
7281
|
+
return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
7282
|
+
}
|
|
7283
|
+
return Object.prototype.toString.call(value);
|
|
7284
|
+
}, "getObjectTag");
|
|
7285
|
+
|
|
7286
|
+
// ../type-checks/src/is-plain-object.ts
|
|
7287
|
+
var isObjectLike = /* @__PURE__ */ __name((obj) => {
|
|
7288
|
+
return typeof obj === "object" && obj !== null;
|
|
7289
|
+
}, "isObjectLike");
|
|
7290
|
+
var isPlainObject = /* @__PURE__ */ __name((obj) => {
|
|
7291
|
+
if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
|
|
7292
|
+
return false;
|
|
7293
|
+
}
|
|
7294
|
+
if (Object.getPrototypeOf(obj) === null) {
|
|
7295
|
+
return true;
|
|
7296
|
+
}
|
|
7297
|
+
let proto = obj;
|
|
7298
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
7299
|
+
proto = Object.getPrototypeOf(proto);
|
|
7300
|
+
}
|
|
7301
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
7302
|
+
}, "isPlainObject");
|
|
7303
|
+
|
|
7304
|
+
// ../type-checks/src/is-object.ts
|
|
7305
|
+
var isObject = /* @__PURE__ */ __name((value) => {
|
|
7306
|
+
try {
|
|
7307
|
+
return typeof value === "object" || Boolean(value) && value?.constructor === Object || isPlainObject(value);
|
|
7308
|
+
} catch {
|
|
7309
|
+
return false;
|
|
7310
|
+
}
|
|
7311
|
+
}, "isObject");
|
|
7312
|
+
|
|
7313
|
+
// ../type-checks/src/is-string.ts
|
|
7314
|
+
var isString = /* @__PURE__ */ __name((value) => {
|
|
7315
|
+
try {
|
|
7316
|
+
return typeof value === "string";
|
|
7317
|
+
} catch {
|
|
7318
|
+
return false;
|
|
7319
|
+
}
|
|
7320
|
+
}, "isString");
|
|
7321
|
+
|
|
7322
|
+
// ../json/src/storm-json.ts
|
|
7323
|
+
import { parse as parse2 } from "jsonc-parser";
|
|
7324
|
+
import { Buffer as Buffer2 } from "node:buffer";
|
|
7325
|
+
import SuperJSON from "superjson";
|
|
7326
|
+
|
|
7327
|
+
// ../json/src/utils/strip-comments.ts
|
|
7328
|
+
var singleComment = Symbol("singleComment");
|
|
7329
|
+
var multiComment = Symbol("multiComment");
|
|
7330
|
+
function stripWithoutWhitespace() {
|
|
7331
|
+
return "";
|
|
7332
|
+
}
|
|
7333
|
+
__name(stripWithoutWhitespace, "stripWithoutWhitespace");
|
|
7334
|
+
function stripWithWhitespace(value, start, end) {
|
|
7335
|
+
return value.slice(start, end).replace(/\S/g, " ");
|
|
7336
|
+
}
|
|
7337
|
+
__name(stripWithWhitespace, "stripWithWhitespace");
|
|
7338
|
+
function isEscaped(value, quotePosition) {
|
|
7339
|
+
let index = quotePosition - 1;
|
|
7340
|
+
let backslashCount = 0;
|
|
7341
|
+
while (value[index] === "\\") {
|
|
7342
|
+
index -= 1;
|
|
7343
|
+
backslashCount += 1;
|
|
7344
|
+
}
|
|
7345
|
+
return Boolean(backslashCount % 2);
|
|
7346
|
+
}
|
|
7347
|
+
__name(isEscaped, "isEscaped");
|
|
7348
|
+
function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
|
|
7349
|
+
if (typeof value !== "string") {
|
|
7350
|
+
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
|
|
7351
|
+
}
|
|
7352
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
7353
|
+
let isInsideString = false;
|
|
7354
|
+
let isInsideComment = false;
|
|
7355
|
+
let offset = 0;
|
|
7356
|
+
let buffer = "";
|
|
7357
|
+
let result = "";
|
|
7358
|
+
let commaIndex = -1;
|
|
7359
|
+
for (let index = 0; index < value.length; index++) {
|
|
7360
|
+
const currentCharacter = value[index];
|
|
7361
|
+
const nextCharacter = value[index + 1];
|
|
7362
|
+
if (!isInsideComment && currentCharacter === '"') {
|
|
7363
|
+
const escaped = isEscaped(value, index);
|
|
7364
|
+
if (!escaped) {
|
|
7365
|
+
isInsideString = !isInsideString;
|
|
7366
|
+
}
|
|
7367
|
+
}
|
|
7368
|
+
if (isInsideString) {
|
|
7369
|
+
continue;
|
|
7370
|
+
}
|
|
7371
|
+
if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "//") {
|
|
7372
|
+
buffer += value.slice(offset, index);
|
|
7373
|
+
offset = index;
|
|
7374
|
+
isInsideComment = singleComment;
|
|
7375
|
+
index++;
|
|
7376
|
+
} else if (isInsideComment === singleComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "\r\n") {
|
|
7377
|
+
index++;
|
|
7378
|
+
isInsideComment = false;
|
|
7379
|
+
buffer += strip(value, offset, index);
|
|
7380
|
+
offset = index;
|
|
7381
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
7382
|
+
isInsideComment = false;
|
|
7383
|
+
buffer += strip(value, offset, index);
|
|
7384
|
+
offset = index;
|
|
7385
|
+
} else if (!isInsideComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "/*") {
|
|
7386
|
+
buffer += value.slice(offset, index);
|
|
7387
|
+
offset = index;
|
|
7388
|
+
isInsideComment = multiComment;
|
|
7389
|
+
index++;
|
|
7390
|
+
} else if (isInsideComment === multiComment && currentCharacter + (nextCharacter ?? EMPTY_STRING) === "*/") {
|
|
7391
|
+
index++;
|
|
7392
|
+
isInsideComment = false;
|
|
7393
|
+
buffer += strip(value, offset, index + 1);
|
|
7394
|
+
offset = index + 1;
|
|
7395
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
7396
|
+
if (commaIndex !== -1) {
|
|
7397
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
7398
|
+
buffer += value.slice(offset, index);
|
|
7399
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
7400
|
+
buffer = "";
|
|
7401
|
+
offset = index;
|
|
7402
|
+
commaIndex = -1;
|
|
7403
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
7404
|
+
buffer += value.slice(offset, index);
|
|
7405
|
+
offset = index;
|
|
7406
|
+
commaIndex = -1;
|
|
7407
|
+
}
|
|
7408
|
+
} else if (currentCharacter === ",") {
|
|
7409
|
+
result += buffer + value.slice(offset, index);
|
|
7410
|
+
buffer = "";
|
|
7411
|
+
offset = index;
|
|
7412
|
+
commaIndex = index;
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
}
|
|
7416
|
+
return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
|
|
7417
|
+
}
|
|
7418
|
+
__name(stripComments, "stripComments");
|
|
7419
|
+
|
|
7420
|
+
// ../json/src/utils/parse.ts
|
|
7421
|
+
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*:/;
|
|
7422
|
+
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*:/;
|
|
7423
|
+
var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
|
|
7424
|
+
function jsonParseTransform(key, value) {
|
|
7425
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
7426
|
+
console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
|
|
7427
|
+
return;
|
|
7428
|
+
}
|
|
7429
|
+
return value;
|
|
7430
|
+
}
|
|
7431
|
+
__name(jsonParseTransform, "jsonParseTransform");
|
|
7432
|
+
function parse(value, options = {}) {
|
|
7433
|
+
if (typeof value !== "string") {
|
|
7434
|
+
return value;
|
|
7435
|
+
}
|
|
7436
|
+
let stripped = stripComments(value);
|
|
7437
|
+
if (stripped[0] === '"' && stripped[stripped.length - 1] === '"' && !stripped.includes("\\")) {
|
|
7438
|
+
return stripped.slice(1, -1);
|
|
7439
|
+
}
|
|
7440
|
+
stripped = stripped.trim();
|
|
7441
|
+
if (stripped.length <= 9) {
|
|
7442
|
+
switch (stripped.toLowerCase()) {
|
|
7443
|
+
case "true": {
|
|
7444
|
+
return true;
|
|
7445
|
+
}
|
|
7446
|
+
case "false": {
|
|
7447
|
+
return false;
|
|
7448
|
+
}
|
|
7449
|
+
case "undefined": {
|
|
7450
|
+
return void 0;
|
|
7451
|
+
}
|
|
7452
|
+
case "null": {
|
|
7453
|
+
return null;
|
|
7454
|
+
}
|
|
7455
|
+
case "nan": {
|
|
7456
|
+
return Number.NaN;
|
|
7457
|
+
}
|
|
7458
|
+
case "infinity": {
|
|
7459
|
+
return Number.POSITIVE_INFINITY;
|
|
7460
|
+
}
|
|
7461
|
+
case "-infinity": {
|
|
7462
|
+
return Number.NEGATIVE_INFINITY;
|
|
7463
|
+
}
|
|
7464
|
+
}
|
|
7465
|
+
}
|
|
7466
|
+
if (!JsonSigRx.test(stripped)) {
|
|
7467
|
+
if (options.strict) {
|
|
7468
|
+
throw new Error("Invalid JSON");
|
|
7469
|
+
}
|
|
7470
|
+
return stripped;
|
|
7471
|
+
}
|
|
7472
|
+
try {
|
|
7473
|
+
if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
|
|
7474
|
+
if (options.strict) {
|
|
7475
|
+
throw new Error("Possible prototype pollution");
|
|
7476
|
+
}
|
|
7477
|
+
return JSON.parse(stripped, jsonParseTransform);
|
|
7478
|
+
}
|
|
7479
|
+
return JSON.parse(stripped);
|
|
7480
|
+
} catch (error) {
|
|
7481
|
+
if (options.strict) {
|
|
7482
|
+
throw error;
|
|
7483
|
+
}
|
|
7484
|
+
return value;
|
|
7485
|
+
}
|
|
7486
|
+
}
|
|
7487
|
+
__name(parse, "parse");
|
|
7488
|
+
|
|
7489
|
+
// ../json/src/utils/parse-error.ts
|
|
7490
|
+
import { printParseErrorCode } from "jsonc-parser";
|
|
7491
|
+
import { LinesAndColumns } from "lines-and-columns";
|
|
7492
|
+
|
|
7493
|
+
// ../json/src/utils/code-frames.ts
|
|
7494
|
+
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
7495
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
7496
|
+
const startLoc = {
|
|
7497
|
+
column: 0,
|
|
7498
|
+
line: -1,
|
|
7499
|
+
...loc.start
|
|
7500
|
+
};
|
|
7501
|
+
const endLoc = {
|
|
7502
|
+
...startLoc,
|
|
7503
|
+
...loc.end
|
|
7504
|
+
};
|
|
7505
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
7506
|
+
const startLine = startLoc.line;
|
|
7507
|
+
const startColumn = startLoc.column;
|
|
7508
|
+
const endLine = endLoc.line;
|
|
7509
|
+
const endColumn = endLoc.column;
|
|
7510
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
7511
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
7512
|
+
if (startLine === -1) {
|
|
7513
|
+
start = 0;
|
|
7514
|
+
}
|
|
7515
|
+
if (endLine === -1) {
|
|
7516
|
+
end = source.length;
|
|
7517
|
+
}
|
|
7518
|
+
const lineDiff = endLine - startLine;
|
|
7519
|
+
const markerLines = {};
|
|
7520
|
+
if (lineDiff) {
|
|
7521
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
7522
|
+
const lineNumber = i + startLine;
|
|
7523
|
+
if (!startColumn) {
|
|
7524
|
+
markerLines[lineNumber] = true;
|
|
7525
|
+
} else if (i === 0) {
|
|
7526
|
+
const sourceLength = source[lineNumber - 1]?.length ?? 0;
|
|
7527
|
+
markerLines[lineNumber] = [
|
|
7528
|
+
startColumn,
|
|
7529
|
+
sourceLength - startColumn + 1
|
|
7530
|
+
];
|
|
7531
|
+
} else if (i === lineDiff) {
|
|
7532
|
+
markerLines[lineNumber] = [
|
|
7533
|
+
0,
|
|
7534
|
+
endColumn
|
|
7535
|
+
];
|
|
7536
|
+
} else {
|
|
7537
|
+
const sourceLength = source[lineNumber - i]?.length ?? 0;
|
|
7538
|
+
markerLines[lineNumber] = [
|
|
7539
|
+
0,
|
|
7540
|
+
sourceLength
|
|
7541
|
+
];
|
|
7542
|
+
}
|
|
7543
|
+
}
|
|
7544
|
+
} else if (startColumn === endColumn) {
|
|
7545
|
+
markerLines[startLine] = startColumn ? [
|
|
7546
|
+
startColumn,
|
|
7547
|
+
0
|
|
7548
|
+
] : true;
|
|
7549
|
+
} else {
|
|
7550
|
+
markerLines[startLine] = [
|
|
7551
|
+
startColumn,
|
|
7552
|
+
endColumn - startColumn
|
|
7553
|
+
];
|
|
7554
|
+
}
|
|
7555
|
+
return {
|
|
7556
|
+
start,
|
|
7557
|
+
end,
|
|
7558
|
+
markerLines
|
|
7559
|
+
};
|
|
7560
|
+
}
|
|
7561
|
+
__name(getMarkerLines, "getMarkerLines");
|
|
7562
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
7563
|
+
const lines = rawLines.split(NEWLINE);
|
|
7564
|
+
const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
|
|
7565
|
+
const numberMaxWidth = String(end).length;
|
|
7566
|
+
const highlightedLines = opts.highlight ? opts.highlight(rawLines) : rawLines;
|
|
7567
|
+
const frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
|
|
7568
|
+
const number = start + 1 + index;
|
|
7569
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
7570
|
+
const gutter = ` ${paddedNumber} | `;
|
|
7571
|
+
const hasMarker = Boolean(markerLines[number] ?? false);
|
|
7572
|
+
if (hasMarker) {
|
|
7573
|
+
let markerLine = "";
|
|
7574
|
+
if (Array.isArray(hasMarker)) {
|
|
7575
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
7576
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
7577
|
+
markerLine = [
|
|
7578
|
+
"\n ",
|
|
7579
|
+
gutter.replace(/\d/g, " "),
|
|
7580
|
+
markerSpacing,
|
|
7581
|
+
"^".repeat(numberOfMarkers)
|
|
7582
|
+
].join("");
|
|
7583
|
+
}
|
|
7584
|
+
return [
|
|
7585
|
+
">",
|
|
7586
|
+
gutter,
|
|
7587
|
+
line,
|
|
7588
|
+
markerLine
|
|
7589
|
+
].join("");
|
|
7590
|
+
}
|
|
7591
|
+
return ` ${gutter}${line}`;
|
|
7592
|
+
}).join("\n");
|
|
7593
|
+
return frame;
|
|
7594
|
+
}
|
|
7595
|
+
__name(codeFrameColumns, "codeFrameColumns");
|
|
7596
|
+
|
|
7597
|
+
// ../json/src/utils/parse-error.ts
|
|
7598
|
+
function formatParseError(input, parseError) {
|
|
7599
|
+
const { error, offset, length } = parseError;
|
|
7600
|
+
const result = new LinesAndColumns(input).locationForIndex(offset);
|
|
7601
|
+
let line = result?.line ?? 0;
|
|
7602
|
+
let column = result?.column ?? 0;
|
|
7603
|
+
line++;
|
|
7604
|
+
column++;
|
|
7605
|
+
return `${printParseErrorCode(error)} in JSON at ${line}:${column}
|
|
7606
|
+
${codeFrameColumns(input, {
|
|
7607
|
+
start: {
|
|
7608
|
+
line,
|
|
7609
|
+
column
|
|
7610
|
+
},
|
|
7611
|
+
end: {
|
|
7612
|
+
line,
|
|
7613
|
+
column: column + length
|
|
7614
|
+
}
|
|
7615
|
+
})}
|
|
7616
|
+
`;
|
|
7617
|
+
}
|
|
7618
|
+
__name(formatParseError, "formatParseError");
|
|
7619
|
+
|
|
7620
|
+
// ../type-checks/src/is-number.ts
|
|
7621
|
+
var isNumber = /* @__PURE__ */ __name((value) => {
|
|
7622
|
+
try {
|
|
7623
|
+
return value instanceof Number || typeof value === "number" || Number(value) === value;
|
|
7624
|
+
} catch {
|
|
7625
|
+
return false;
|
|
7626
|
+
}
|
|
7627
|
+
}, "isNumber");
|
|
7628
|
+
|
|
7629
|
+
// ../type-checks/src/is-undefined.ts
|
|
7630
|
+
var isUndefined = /* @__PURE__ */ __name((value) => {
|
|
7631
|
+
return value === void 0;
|
|
7632
|
+
}, "isUndefined");
|
|
7633
|
+
|
|
7634
|
+
// ../json/src/utils/stringify.ts
|
|
7635
|
+
var invalidKeyChars = [
|
|
7636
|
+
"@",
|
|
7637
|
+
"/",
|
|
7638
|
+
"#",
|
|
7639
|
+
"$",
|
|
7640
|
+
" ",
|
|
7641
|
+
":",
|
|
7642
|
+
";",
|
|
7643
|
+
",",
|
|
7644
|
+
".",
|
|
7645
|
+
"!",
|
|
7646
|
+
"?",
|
|
7647
|
+
"&",
|
|
7648
|
+
"=",
|
|
7649
|
+
"+",
|
|
7650
|
+
"-",
|
|
7651
|
+
"*",
|
|
7652
|
+
"%",
|
|
7653
|
+
"^",
|
|
7654
|
+
"~",
|
|
7655
|
+
"|",
|
|
7656
|
+
"\\",
|
|
7657
|
+
'"',
|
|
7658
|
+
"'",
|
|
7659
|
+
"`",
|
|
7660
|
+
"{",
|
|
7661
|
+
"}",
|
|
7662
|
+
"[",
|
|
7663
|
+
"]",
|
|
7664
|
+
"(",
|
|
7665
|
+
")",
|
|
7666
|
+
"<",
|
|
7667
|
+
">"
|
|
7668
|
+
];
|
|
7669
|
+
var stringify = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
7670
|
+
const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
|
|
7671
|
+
switch (value) {
|
|
7672
|
+
case null: {
|
|
7673
|
+
return "null";
|
|
7674
|
+
}
|
|
7675
|
+
case void 0: {
|
|
7676
|
+
return '"undefined"';
|
|
7549
7677
|
}
|
|
7550
|
-
case
|
|
7551
|
-
|
|
7552
|
-
break;
|
|
7678
|
+
case true: {
|
|
7679
|
+
return "true";
|
|
7553
7680
|
}
|
|
7554
|
-
case
|
|
7555
|
-
|
|
7556
|
-
p = getPointer(0, value);
|
|
7557
|
-
break;
|
|
7681
|
+
case false: {
|
|
7682
|
+
return "false";
|
|
7558
7683
|
}
|
|
7559
|
-
|
|
7560
|
-
|
|
7684
|
+
case Number.POSITIVE_INFINITY: {
|
|
7685
|
+
return "infinity";
|
|
7686
|
+
}
|
|
7687
|
+
case Number.NEGATIVE_INFINITY: {
|
|
7688
|
+
return "-infinity";
|
|
7561
7689
|
}
|
|
7562
7690
|
}
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
const buf = new Uint8Array(message.toPackedArrayBuffer());
|
|
7566
|
-
const values = [];
|
|
7567
|
-
for (let i = 0; i < buf.byteLength; i++) {
|
|
7568
|
-
values.push(`0x${pad(buf[i].toString(16), 2)}`);
|
|
7569
|
-
}
|
|
7570
|
-
return `$.readRawPointer(new Uint8Array([${values.join(",")}]).buffer)`;
|
|
7571
|
-
}
|
|
7572
|
-
__name(createValue, "createValue");
|
|
7573
|
-
function createNestedNodeProperty(node) {
|
|
7574
|
-
const name = getDisplayNamePrefix(node);
|
|
7575
|
-
const initializer = getFullClassName(node);
|
|
7576
|
-
return `static readonly ${name} = ${initializer};`;
|
|
7577
|
-
}
|
|
7578
|
-
__name(createNestedNodeProperty, "createNestedNodeProperty");
|
|
7579
|
-
function generateInterfaceNode(ctx, node) {
|
|
7580
|
-
const displayNamePrefix = getDisplayNamePrefix(node);
|
|
7581
|
-
const fullClassName = getFullClassName(node);
|
|
7582
|
-
const nestedNodes = node.nestedNodes.map((n) => lookupNode(ctx, n)).filter((n) => !n._isConst && !n._isAnnotation);
|
|
7583
|
-
const nodeId = node.id;
|
|
7584
|
-
const nodeIdHex = nodeId.toString(16);
|
|
7585
|
-
const consts = ctx.nodes.filter((n) => n.scopeId === nodeId && n._isConst);
|
|
7586
|
-
const members = [];
|
|
7587
|
-
members.push(
|
|
7588
|
-
...consts.map((node2) => {
|
|
7589
|
-
const name = c2s(getDisplayNamePrefix(node2));
|
|
7590
|
-
const value = createValue(node2.const.value);
|
|
7591
|
-
return `static readonly ${name} = ${value}`;
|
|
7592
|
-
}),
|
|
7593
|
-
...nestedNodes.map((node2) => createNestedNodeProperty(node2)),
|
|
7594
|
-
`static readonly Client = ${fullClassName}$Client;
|
|
7595
|
-
static readonly Server = ${fullClassName}$Server;
|
|
7596
|
-
public static override readonly _capnp = {
|
|
7597
|
-
displayName: "${displayNamePrefix}",
|
|
7598
|
-
id: "${nodeIdHex}",
|
|
7599
|
-
size: new $.ObjectSize(0, 0),
|
|
7600
|
-
}
|
|
7601
|
-
public override toString(): string { return "${fullClassName}_" + super.toString(); }`
|
|
7602
|
-
);
|
|
7603
|
-
const docComment = extractJSDocs(lookupNodeSourceInfo(ctx, node));
|
|
7604
|
-
const classCode = `
|
|
7605
|
-
${docComment}
|
|
7606
|
-
export class ${fullClassName} extends $.Interface {
|
|
7607
|
-
${members.join("\n")}
|
|
7608
|
-
}`;
|
|
7609
|
-
generateInterfaceClasses(ctx, node);
|
|
7610
|
-
ctx.codeParts.push(classCode);
|
|
7611
|
-
}
|
|
7612
|
-
__name(generateInterfaceNode, "generateInterfaceNode");
|
|
7613
|
-
function generateNode(ctx, node) {
|
|
7614
|
-
const nodeId = node.id;
|
|
7615
|
-
const nodeIdHex = nodeId.toString(16);
|
|
7616
|
-
if (ctx.generatedNodeIds.has(nodeIdHex)) {
|
|
7617
|
-
return;
|
|
7618
|
-
}
|
|
7619
|
-
ctx.generatedNodeIds.add(nodeIdHex);
|
|
7620
|
-
const nestedNodes = node.nestedNodes.map((node2) => lookupNode(ctx, node2));
|
|
7621
|
-
for (const nestedNode of nestedNodes) {
|
|
7622
|
-
generateNode(ctx, nestedNode);
|
|
7691
|
+
if (Array.isArray(value)) {
|
|
7692
|
+
return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
|
|
7623
7693
|
}
|
|
7624
|
-
|
|
7625
|
-
(
|
|
7626
|
-
);
|
|
7627
|
-
for (const groupNode of groupNodes) {
|
|
7628
|
-
generateNode(ctx, groupNode);
|
|
7694
|
+
if (value instanceof Uint8Array) {
|
|
7695
|
+
return value.toString();
|
|
7629
7696
|
}
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
generateStructNode(ctx, node);
|
|
7634
|
-
break;
|
|
7635
|
-
}
|
|
7636
|
-
case Node.CONST: {
|
|
7637
|
-
break;
|
|
7638
|
-
}
|
|
7639
|
-
case Node.ENUM: {
|
|
7640
|
-
generateEnumNode(
|
|
7641
|
-
ctx,
|
|
7642
|
-
getFullClassName(node),
|
|
7643
|
-
node,
|
|
7644
|
-
node.enum.enumerants.toArray()
|
|
7645
|
-
);
|
|
7646
|
-
break;
|
|
7647
|
-
}
|
|
7648
|
-
case Node.INTERFACE: {
|
|
7649
|
-
generateInterfaceNode(ctx, node);
|
|
7650
|
-
break;
|
|
7697
|
+
switch (typeof value) {
|
|
7698
|
+
case "number": {
|
|
7699
|
+
return `${value}`;
|
|
7651
7700
|
}
|
|
7652
|
-
case
|
|
7653
|
-
|
|
7701
|
+
case "string": {
|
|
7702
|
+
return JSON.stringify(value);
|
|
7654
7703
|
}
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
format(
|
|
7659
|
-
GEN_NODE_UNKNOWN_TYPE,
|
|
7660
|
-
nodeType
|
|
7661
|
-
/* s.Node_Which[whichNode] */
|
|
7662
|
-
)
|
|
7663
|
-
);
|
|
7704
|
+
case "object": {
|
|
7705
|
+
const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
|
|
7706
|
+
return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
|
|
7664
7707
|
}
|
|
7708
|
+
default:
|
|
7709
|
+
return "null";
|
|
7665
7710
|
}
|
|
7666
|
-
}
|
|
7667
|
-
|
|
7668
|
-
|
|
7711
|
+
}, "stringify");
|
|
7712
|
+
|
|
7713
|
+
// ../json/src/storm-json.ts
|
|
7714
|
+
var StormJSON = class _StormJSON extends SuperJSON {
|
|
7669
7715
|
static {
|
|
7670
|
-
__name(this, "
|
|
7716
|
+
__name(this, "StormJSON");
|
|
7671
7717
|
}
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7676
|
-
|
|
7718
|
+
static #instance;
|
|
7719
|
+
static get instance() {
|
|
7720
|
+
if (!_StormJSON.#instance) {
|
|
7721
|
+
_StormJSON.#instance = new _StormJSON();
|
|
7722
|
+
}
|
|
7723
|
+
return _StormJSON.#instance;
|
|
7677
7724
|
}
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7725
|
+
/**
|
|
7726
|
+
* Deserialize the given value with superjson using the given metadata
|
|
7727
|
+
*/
|
|
7728
|
+
static deserialize(payload) {
|
|
7729
|
+
return _StormJSON.instance.deserialize(payload);
|
|
7683
7730
|
}
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
generatedNodeIds = /* @__PURE__ */ new Set();
|
|
7690
|
-
generatedResultsPromiseIds = /* @__PURE__ */ new Set();
|
|
7691
|
-
tsPath = "";
|
|
7692
|
-
codeParts = [];
|
|
7693
|
-
toString() {
|
|
7694
|
-
return this.file?.filename ?? "CodeGeneratorFileContext()";
|
|
7731
|
+
/**
|
|
7732
|
+
* Serialize the given value with superjson
|
|
7733
|
+
*/
|
|
7734
|
+
static serialize(object) {
|
|
7735
|
+
return _StormJSON.instance.serialize(object);
|
|
7695
7736
|
}
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
ctx.codeParts.push(`import * as $ from '${importPath}';`);
|
|
7719
|
-
}
|
|
7720
|
-
__name(generateCapnpImport, "generateCapnpImport");
|
|
7721
|
-
function generateNestedImports(ctx) {
|
|
7722
|
-
for (const imp of ctx.imports) {
|
|
7723
|
-
const { name } = imp;
|
|
7724
|
-
let importPath;
|
|
7725
|
-
if (name.startsWith("/capnp/")) {
|
|
7726
|
-
importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
|
|
7727
|
-
} else {
|
|
7728
|
-
importPath = name.replace(/\.capnp$/, "");
|
|
7729
|
-
if (importPath[0] !== ".") {
|
|
7730
|
-
importPath = `./${importPath}`;
|
|
7731
|
-
}
|
|
7737
|
+
/**
|
|
7738
|
+
* Parse the given string value with superjson using the given metadata
|
|
7739
|
+
*
|
|
7740
|
+
* @param value - The string value to parse
|
|
7741
|
+
* @returns The parsed data
|
|
7742
|
+
*/
|
|
7743
|
+
static parse(value) {
|
|
7744
|
+
return parse(value);
|
|
7745
|
+
}
|
|
7746
|
+
/**
|
|
7747
|
+
* Serializes the given data to a JSON string.
|
|
7748
|
+
* By default the JSON string is formatted with a 2 space indentation to be easy readable.
|
|
7749
|
+
*
|
|
7750
|
+
* @param value - Object which should be serialized to JSON
|
|
7751
|
+
* @param _options - JSON serialize options
|
|
7752
|
+
* @returns the formatted JSON representation of the object
|
|
7753
|
+
*/
|
|
7754
|
+
static stringify(value, _options) {
|
|
7755
|
+
const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
|
|
7756
|
+
let result = value;
|
|
7757
|
+
if (customTransformer && customTransformer.isApplicable(value)) {
|
|
7758
|
+
result = customTransformer.serialize(result);
|
|
7732
7759
|
}
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7760
|
+
return stringify(result);
|
|
7761
|
+
}
|
|
7762
|
+
/**
|
|
7763
|
+
* Parses the given JSON string and returns the object the JSON content represents.
|
|
7764
|
+
* By default javascript-style comments and trailing commas are allowed.
|
|
7765
|
+
*
|
|
7766
|
+
* @param strData - JSON content as string
|
|
7767
|
+
* @param options - JSON parse options
|
|
7768
|
+
* @returns Object the JSON content represents
|
|
7769
|
+
*/
|
|
7770
|
+
static parseJson(strData, options) {
|
|
7771
|
+
try {
|
|
7772
|
+
if (options?.expectComments === false) {
|
|
7773
|
+
return _StormJSON.instance.parse(strData);
|
|
7738
7774
|
}
|
|
7739
|
-
|
|
7740
|
-
}).sort().join(", ");
|
|
7741
|
-
if (imports.length === 0) {
|
|
7742
|
-
continue;
|
|
7775
|
+
} catch {
|
|
7743
7776
|
}
|
|
7744
|
-
|
|
7777
|
+
const errors = [];
|
|
7778
|
+
const opts = {
|
|
7779
|
+
allowTrailingComma: true,
|
|
7780
|
+
...options
|
|
7781
|
+
};
|
|
7782
|
+
const result = parse2(strData, errors, opts);
|
|
7783
|
+
if (errors.length > 0 && errors[0]) {
|
|
7784
|
+
throw new Error(formatParseError(strData, errors[0]));
|
|
7785
|
+
}
|
|
7786
|
+
return result;
|
|
7745
7787
|
}
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
CodeGeneratorRequest
|
|
7761
|
-
);
|
|
7762
|
-
const ctx = new CodeGeneratorContext();
|
|
7763
|
-
ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
|
|
7764
|
-
if (ctx.files.length === 0) {
|
|
7765
|
-
throw new Error(GEN_NO_FILES);
|
|
7788
|
+
/**
|
|
7789
|
+
* Register a custom schema with superjson
|
|
7790
|
+
*
|
|
7791
|
+
* @param name - The name of the schema
|
|
7792
|
+
* @param serialize - The function to serialize the schema
|
|
7793
|
+
* @param deserialize - The function to deserialize the schema
|
|
7794
|
+
* @param isApplicable - The function to check if the schema is applicable
|
|
7795
|
+
*/
|
|
7796
|
+
static register(name, serialize, deserialize, isApplicable) {
|
|
7797
|
+
_StormJSON.instance.registerCustom({
|
|
7798
|
+
isApplicable,
|
|
7799
|
+
serialize,
|
|
7800
|
+
deserialize
|
|
7801
|
+
}, name);
|
|
7766
7802
|
}
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7803
|
+
/**
|
|
7804
|
+
* Register a class with superjson
|
|
7805
|
+
*
|
|
7806
|
+
* @param classConstructor - The class constructor to register
|
|
7807
|
+
*/
|
|
7808
|
+
static registerClass(classConstructor, options) {
|
|
7809
|
+
_StormJSON.instance.registerClass(classConstructor, {
|
|
7810
|
+
identifier: isString(options) ? options : options?.identifier || classConstructor.name,
|
|
7811
|
+
allowProps: options && isObject(options) && options?.allowProps && Array.isArray(options.allowProps) ? options.allowProps : [
|
|
7812
|
+
"__typename"
|
|
7813
|
+
]
|
|
7814
|
+
});
|
|
7772
7815
|
}
|
|
7773
|
-
|
|
7774
|
-
|
|
7816
|
+
constructor() {
|
|
7817
|
+
super({
|
|
7818
|
+
dedupe: true
|
|
7819
|
+
});
|
|
7775
7820
|
}
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7821
|
+
};
|
|
7822
|
+
StormJSON.instance.registerCustom({
|
|
7823
|
+
isApplicable: /* @__PURE__ */ __name((v) => Buffer2.isBuffer(v), "isApplicable"),
|
|
7824
|
+
serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
|
|
7825
|
+
deserialize: /* @__PURE__ */ __name((v) => Buffer2.from(v, "base64"), "deserialize")
|
|
7826
|
+
}, "Bytes");
|
|
7827
|
+
|
|
7828
|
+
// ../type-checks/src/is-error.ts
|
|
7829
|
+
var isError = /* @__PURE__ */ __name((obj) => {
|
|
7830
|
+
if (!isObject(obj)) {
|
|
7831
|
+
return false;
|
|
7832
|
+
}
|
|
7833
|
+
const tag = getObjectTag(obj);
|
|
7834
|
+
return tag === "[object Error]" || tag === "[object DOMException]" || typeof obj?.message === "string" && typeof obj?.name === "string" && !isPlainObject(obj);
|
|
7835
|
+
}, "isError");
|
|
7836
|
+
|
|
7837
|
+
// ../fs/src/read-file.ts
|
|
7838
|
+
import { existsSync as existsSync2, readFileSync as readFileSyncFs } from "node:fs";
|
|
7839
|
+
import { readFile as readFileFs } from "node:fs/promises";
|
|
7840
|
+
var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
|
|
7841
|
+
try {
|
|
7842
|
+
if (!filePath) {
|
|
7843
|
+
throw new Error("No file path provided to read data");
|
|
7781
7844
|
}
|
|
7845
|
+
return await readFileFs(filePath, {
|
|
7846
|
+
encoding: "utf8"
|
|
7847
|
+
});
|
|
7848
|
+
} catch {
|
|
7849
|
+
throw new Error("An error occurred writing data to file");
|
|
7782
7850
|
}
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
}
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
(n) => lookupNode(ctx, n)
|
|
7795
|
-
);
|
|
7796
|
-
for (const node of nestedNodes) {
|
|
7797
|
-
generateNode(ctx, node);
|
|
7851
|
+
}, "readFile");
|
|
7852
|
+
|
|
7853
|
+
// ../fs/src/write-file.ts
|
|
7854
|
+
import { writeFileSync as writeFileSyncFs } from "node:fs";
|
|
7855
|
+
import { writeFile as writeFileFs } from "node:fs/promises";
|
|
7856
|
+
|
|
7857
|
+
// ../fs/src/json.ts
|
|
7858
|
+
async function readJsonFile(path, options) {
|
|
7859
|
+
const content = await readFile2(path);
|
|
7860
|
+
if (options) {
|
|
7861
|
+
options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
|
|
7798
7862
|
}
|
|
7799
|
-
|
|
7800
|
-
|
|
7863
|
+
try {
|
|
7864
|
+
return StormJSON.parseJson(content, options);
|
|
7865
|
+
} catch (error) {
|
|
7866
|
+
if (isError(error)) {
|
|
7867
|
+
error.message = error.message.replace("JSON", path);
|
|
7868
|
+
throw error;
|
|
7869
|
+
}
|
|
7870
|
+
throw new Error(`Failed to parse JSON: ${path}`);
|
|
7801
7871
|
}
|
|
7802
|
-
const sourceFile = ts.createSourceFile(
|
|
7803
|
-
ctx.tsPath,
|
|
7804
|
-
ctx.codeParts.map((p) => p.toString()).join(""),
|
|
7805
|
-
ts.ScriptTarget.Latest,
|
|
7806
|
-
false,
|
|
7807
|
-
ts.ScriptKind.TS
|
|
7808
|
-
);
|
|
7809
|
-
return SOURCE_COMMENT + ts.createPrinter().printFile(sourceFile);
|
|
7810
7872
|
}
|
|
7811
|
-
__name(
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7873
|
+
__name(readJsonFile, "readJsonFile");
|
|
7874
|
+
|
|
7875
|
+
// ../fs/src/list-files.ts
|
|
7876
|
+
import defu from "defu";
|
|
7877
|
+
import { glob } from "glob";
|
|
7878
|
+
var DEFAULT_OPTIONS = {
|
|
7879
|
+
dot: true
|
|
7880
|
+
};
|
|
7881
|
+
async function list(filesGlob, options) {
|
|
7882
|
+
return glob(filesGlob, defu(options ?? {}, DEFAULT_OPTIONS));
|
|
7883
|
+
}
|
|
7884
|
+
__name(list, "list");
|
|
7885
|
+
async function listFiles(filesGlob, options) {
|
|
7886
|
+
const result = (await list(filesGlob, defu({
|
|
7887
|
+
withFileTypes: true
|
|
7888
|
+
}, options ?? {}))).filter((ret) => ret.isFile());
|
|
7889
|
+
if (!options?.withFileTypes) {
|
|
7890
|
+
return result.map((file) => file.fullpath());
|
|
7815
7891
|
}
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
const
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
for (const diagnostic of allDiagnostics) {
|
|
7856
|
-
const message = ts.flattenDiagnosticMessageText(
|
|
7857
|
-
diagnostic.messageText,
|
|
7858
|
-
"\n"
|
|
7859
|
-
);
|
|
7860
|
-
if (diagnostic.file && diagnostic.start) {
|
|
7861
|
-
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
7862
|
-
console.log(
|
|
7863
|
-
`${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`
|
|
7864
|
-
);
|
|
7865
|
-
} else {
|
|
7866
|
-
console.log(`==> ${message}`);
|
|
7892
|
+
return result;
|
|
7893
|
+
}
|
|
7894
|
+
__name(listFiles, "listFiles");
|
|
7895
|
+
|
|
7896
|
+
// src/helpers.ts
|
|
7897
|
+
import { parseJsonConfigFileContent, sys } from "typescript";
|
|
7898
|
+
async function resolveOptions(options) {
|
|
7899
|
+
const tsconfigPath = options.tsconfigPath ? options.tsconfigPath.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : void 0;
|
|
7900
|
+
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"));
|
|
7901
|
+
let resolvedTsconfig;
|
|
7902
|
+
if (options.tsconfig) {
|
|
7903
|
+
resolvedTsconfig = options.tsconfig;
|
|
7904
|
+
} else {
|
|
7905
|
+
if (!tsconfigPath || !existsSync(tsconfigPath)) {
|
|
7906
|
+
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.";
|
|
7907
|
+
writeFatal(errorMessage, {
|
|
7908
|
+
logLevel: "all"
|
|
7909
|
+
});
|
|
7910
|
+
throw new Error(errorMessage);
|
|
7911
|
+
}
|
|
7912
|
+
const tsconfigFile = await readJsonFile(tsconfigPath);
|
|
7913
|
+
resolvedTsconfig = parseJsonConfigFileContent(tsconfigFile, sys, findFilePath(tsconfigPath));
|
|
7914
|
+
if (!resolvedTsconfig) {
|
|
7915
|
+
const errorMessage = `\u2716 The specified TypeScript configuration file "${tsconfigPath}" is invalid. Please provide a valid configuration.`;
|
|
7916
|
+
writeFatal(errorMessage, {
|
|
7917
|
+
logLevel: "all"
|
|
7918
|
+
});
|
|
7919
|
+
throw new Error(errorMessage);
|
|
7920
|
+
}
|
|
7921
|
+
resolvedTsconfig.options.configFilePath = tsconfigPath;
|
|
7922
|
+
resolvedTsconfig.options.noImplicitOverride = false;
|
|
7923
|
+
resolvedTsconfig.options.noUnusedLocals = false;
|
|
7924
|
+
resolvedTsconfig.options.noUnusedParameters = false;
|
|
7925
|
+
}
|
|
7926
|
+
const resolvedSchemas = [];
|
|
7927
|
+
for (const schema of schemas) {
|
|
7928
|
+
if (!schema || !schema.includes("*") && !existsSync(schema)) {
|
|
7929
|
+
if (schemas.length <= 1) {
|
|
7930
|
+
throw new Error(`\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`);
|
|
7867
7931
|
}
|
|
7932
|
+
} else {
|
|
7933
|
+
resolvedSchemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
|
|
7868
7934
|
}
|
|
7869
|
-
throw new Error(GEN_TS_EMIT_FAILED);
|
|
7870
7935
|
}
|
|
7936
|
+
if (resolvedSchemas.length === 0 || !resolvedSchemas[0]) {
|
|
7937
|
+
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.`, {
|
|
7938
|
+
logLevel: "all"
|
|
7939
|
+
});
|
|
7940
|
+
return null;
|
|
7941
|
+
}
|
|
7942
|
+
resolvedTsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(tsconfigPath ? findFilePath(tsconfigPath) : options.projectRoot, joinPaths(options.workspaceRoot, resolvedSchemas[0].endsWith(".capnp") ? findFilePath(resolvedSchemas[0]) : resolvedSchemas[0])));
|
|
7943
|
+
return {
|
|
7944
|
+
workspaceRoot: options.workspaceRoot,
|
|
7945
|
+
projectRoot: options.projectRoot,
|
|
7946
|
+
schemas: resolvedSchemas,
|
|
7947
|
+
js: options.js ?? false,
|
|
7948
|
+
ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
|
|
7949
|
+
dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true),
|
|
7950
|
+
tsconfig: resolvedTsconfig
|
|
7951
|
+
};
|
|
7871
7952
|
}
|
|
7872
|
-
__name(
|
|
7873
|
-
|
|
7874
|
-
// ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=503a440bd2bef41c0cb22819bc4ced5a7f04993fb999f0d944e284220f14916b_typescript@5.9.2/node_modules/capnp-es/dist/compiler/index.mjs
|
|
7875
|
-
import "typescript";
|
|
7953
|
+
__name(resolveOptions, "resolveOptions");
|
|
7876
7954
|
|
|
7877
7955
|
// src/compile.ts
|
|
7878
|
-
import { Buffer as Buffer3 } from "node:buffer";
|
|
7879
|
-
import { exec } from "node:child_process";
|
|
7880
7956
|
async function capnpc(options) {
|
|
7881
7957
|
const { output, tsconfig, schemas = [], tty } = options;
|
|
7882
7958
|
let dataBuf = Buffer3.alloc(0);
|
|
@@ -7921,7 +7997,7 @@ async function capnpc(options) {
|
|
|
7921
7997
|
ts: options.ts ?? true,
|
|
7922
7998
|
js: false,
|
|
7923
7999
|
dts: false,
|
|
7924
|
-
tsconfig: tsconfig
|
|
8000
|
+
tsconfig: tsconfig.options
|
|
7925
8001
|
});
|
|
7926
8002
|
}
|
|
7927
8003
|
__name(capnpc, "capnpc");
|
|
@@ -7967,54 +8043,30 @@ function createProgram() {
|
|
|
7967
8043
|
}
|
|
7968
8044
|
__name(createProgram, "createProgram");
|
|
7969
8045
|
async function compileAction(options) {
|
|
7970
|
-
const
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
});
|
|
7977
|
-
throw new Error(errorMessage);
|
|
7978
|
-
}
|
|
7979
|
-
const resolvedTsconfig = await readJsonFile(tsconfigPath);
|
|
7980
|
-
const tsconfig = ts2.parseJsonConfigFileContent(resolvedTsconfig, ts2.sys, findFilePath(tsconfigPath));
|
|
7981
|
-
tsconfig.options.configFilePath = tsconfigPath;
|
|
7982
|
-
tsconfig.options.noImplicitOverride = false;
|
|
7983
|
-
tsconfig.options.noUnusedLocals = false;
|
|
7984
|
-
tsconfig.options.noUnusedParameters = false;
|
|
7985
|
-
tsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(findFilePath(tsconfigPath), joinPaths(options.workspaceRoot, schema.endsWith(".capnp") ? findFilePath(schema) : schema)));
|
|
7986
|
-
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}...`, {
|
|
7987
|
-
logLevel: "all"
|
|
8046
|
+
const resolvedOptions = await resolveOptions({
|
|
8047
|
+
...options,
|
|
8048
|
+
projectRoot: options.projectRoot,
|
|
8049
|
+
tsconfig: void 0,
|
|
8050
|
+
tsconfigPath: options.tsconfig || joinPaths(options.projectRoot, "tsconfig.json"),
|
|
8051
|
+
schemas: options.schema
|
|
7988
8052
|
});
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
const errorMessage = `\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`;
|
|
7992
|
-
writeFatal(errorMessage, {
|
|
7993
|
-
logLevel: "all"
|
|
7994
|
-
});
|
|
7995
|
-
throw new Error(errorMessage);
|
|
7996
|
-
}
|
|
7997
|
-
schemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
|
|
7998
|
-
if (schemas.length === 0) {
|
|
7999
|
-
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.`, {
|
|
8053
|
+
if (!resolvedOptions) {
|
|
8054
|
+
writeWarning3("\u2716 Unable to resolve Cap'n Proto compiler options - the program will terminate", {
|
|
8000
8055
|
logLevel: "all"
|
|
8001
8056
|
});
|
|
8002
8057
|
return;
|
|
8003
8058
|
}
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
tsconfig,
|
|
8007
|
-
schemas,
|
|
8008
|
-
ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
|
|
8009
|
-
dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true)
|
|
8059
|
+
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}...`, {
|
|
8060
|
+
logLevel: "all"
|
|
8010
8061
|
});
|
|
8062
|
+
const result = await capnpc(resolvedOptions);
|
|
8011
8063
|
if (result.files.size === 0) {
|
|
8012
|
-
|
|
8064
|
+
writeWarning3("\u26A0\uFE0F No files were generated. Please check your schema files.", {
|
|
8013
8065
|
logLevel: "all"
|
|
8014
8066
|
});
|
|
8015
8067
|
return;
|
|
8016
8068
|
}
|
|
8017
|
-
writeInfo(
|
|
8069
|
+
writeInfo(`\u{1F4CB} Writing ${result.files.size} generated files to disk...`, {
|
|
8018
8070
|
logLevel: "all"
|
|
8019
8071
|
});
|
|
8020
8072
|
for (const [fileName, content] of result.files) {
|
|
@@ -8037,7 +8089,7 @@ async function compileAction(options) {
|
|
|
8037
8089
|
content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
|
|
8038
8090
|
);
|
|
8039
8091
|
}
|
|
8040
|
-
writeSuccess("\u26A1
|
|
8092
|
+
writeSuccess("\u26A1 Storm Cap'n Proto Compiler completed successfully.", {
|
|
8041
8093
|
logLevel: "all"
|
|
8042
8094
|
});
|
|
8043
8095
|
}
|
|
@@ -8049,7 +8101,7 @@ void (async () => {
|
|
|
8049
8101
|
await program.parseAsync(process.argv);
|
|
8050
8102
|
exitWithSuccess();
|
|
8051
8103
|
} catch (error) {
|
|
8052
|
-
|
|
8104
|
+
writeFatal2(`\u2716 A fatal error occurred while running the Storm Cap'n Proto compiler tool:
|
|
8053
8105
|
${error?.message ? error?.name ? `[${error.name}]: ${error.message}` : error.message : JSON.stringify(error)}${error?.stack ? `
|
|
8054
8106
|
|
|
8055
8107
|
Stack Trace: ${error.stack}` : ""}`, {
|