@stryke/capnp 0.2.6 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,977 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
4
+
5
+ // ../path/src/exists.ts
6
+ var _fs = require('fs');
7
+ var _promises = require('fs/promises');
8
+ var existsSync = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (filePath) => {
9
+ return _fs.existsSync.call(void 0, filePath);
10
+ }, "existsSync");
11
+ var exists = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (filePath) => {
12
+ return _promises.access.call(void 0, filePath, _promises.constants.F_OK).then(() => true).catch(() => false);
13
+ }, "exists");
14
+
15
+ // ../fs/src/helpers.ts
16
+ var _nanotar = require('nanotar');
17
+
18
+
19
+ async function createDirectory(path) {
20
+ if (await exists(path)) {
21
+ return;
22
+ }
23
+ return _promises.mkdir.call(void 0, path, {
24
+ recursive: true
25
+ });
26
+ }
27
+ _chunkUSNT2KNTcjs.__name.call(void 0, createDirectory, "createDirectory");
28
+
29
+ // ../fs/src/write-file.ts
30
+ var _jtoml = require('@ltd/j-toml');
31
+
32
+ // ../type-checks/src/get-object-tag.ts
33
+ var getObjectTag = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
34
+ if (value == null) {
35
+ return value === void 0 ? "[object Undefined]" : "[object Null]";
36
+ }
37
+ return Object.prototype.toString.call(value);
38
+ }, "getObjectTag");
39
+
40
+ // ../type-checks/src/is-plain-object.ts
41
+ var isObjectLike = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (obj) => {
42
+ return typeof obj === "object" && obj !== null;
43
+ }, "isObjectLike");
44
+ var isPlainObject = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (obj) => {
45
+ if (!isObjectLike(obj) || getObjectTag(obj) !== "[object Object]") {
46
+ return false;
47
+ }
48
+ if (Object.getPrototypeOf(obj) === null) {
49
+ return true;
50
+ }
51
+ let proto = obj;
52
+ while (Object.getPrototypeOf(proto) !== null) {
53
+ proto = Object.getPrototypeOf(proto);
54
+ }
55
+ return Object.getPrototypeOf(obj) === proto;
56
+ }, "isPlainObject");
57
+
58
+ // ../type-checks/src/is-object.ts
59
+ var isObject = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
60
+ try {
61
+ return typeof value === "object" || Boolean(value) && _optionalChain([value, 'optionalAccess', _ => _.constructor]) === Object || isPlainObject(value);
62
+ } catch (e) {
63
+ return false;
64
+ }
65
+ }, "isObject");
66
+
67
+ // ../type-checks/src/is-string.ts
68
+ var isString = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
69
+ try {
70
+ return typeof value === "string";
71
+ } catch (e2) {
72
+ return false;
73
+ }
74
+ }, "isString");
75
+
76
+ // ../json/src/storm-json.ts
77
+ var _jsoncparser = require('jsonc-parser');
78
+ var _buffer = require('buffer');
79
+ var _superjson = require('superjson'); var _superjson2 = _interopRequireDefault(_superjson);
80
+
81
+ // ../types/src/base.ts
82
+ var EMPTY_STRING = "";
83
+ var $NestedValue = Symbol("NestedValue");
84
+
85
+ // ../json/src/utils/strip-comments.ts
86
+ var singleComment = Symbol("singleComment");
87
+ var multiComment = Symbol("multiComment");
88
+ function stripWithoutWhitespace() {
89
+ return "";
90
+ }
91
+ _chunkUSNT2KNTcjs.__name.call(void 0, stripWithoutWhitespace, "stripWithoutWhitespace");
92
+ function stripWithWhitespace(value, start, end) {
93
+ return value.slice(start, end).replace(/\S/g, " ");
94
+ }
95
+ _chunkUSNT2KNTcjs.__name.call(void 0, stripWithWhitespace, "stripWithWhitespace");
96
+ function isEscaped(value, quotePosition) {
97
+ let index = quotePosition - 1;
98
+ let backslashCount = 0;
99
+ while (value[index] === "\\") {
100
+ index -= 1;
101
+ backslashCount += 1;
102
+ }
103
+ return Boolean(backslashCount % 2);
104
+ }
105
+ _chunkUSNT2KNTcjs.__name.call(void 0, isEscaped, "isEscaped");
106
+ function stripComments(value, { whitespace = true, trailingCommas = false } = {}) {
107
+ if (typeof value !== "string") {
108
+ throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof value}\``);
109
+ }
110
+ const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
111
+ let isInsideString = false;
112
+ let isInsideComment = false;
113
+ let offset = 0;
114
+ let buffer = "";
115
+ let result = "";
116
+ let commaIndex = -1;
117
+ for (let index = 0; index < value.length; index++) {
118
+ const currentCharacter = value[index];
119
+ const nextCharacter = value[index + 1];
120
+ if (!isInsideComment && currentCharacter === '"') {
121
+ const escaped = isEscaped(value, index);
122
+ if (!escaped) {
123
+ isInsideString = !isInsideString;
124
+ }
125
+ }
126
+ if (isInsideString) {
127
+ continue;
128
+ }
129
+ if (!isInsideComment && currentCharacter + (_nullishCoalesce(nextCharacter, () => ( EMPTY_STRING))) === "//") {
130
+ buffer += value.slice(offset, index);
131
+ offset = index;
132
+ isInsideComment = singleComment;
133
+ index++;
134
+ } else if (isInsideComment === singleComment && currentCharacter + (_nullishCoalesce(nextCharacter, () => ( EMPTY_STRING))) === "\r\n") {
135
+ index++;
136
+ isInsideComment = false;
137
+ buffer += strip(value, offset, index);
138
+ offset = index;
139
+ } else if (isInsideComment === singleComment && currentCharacter === "\n") {
140
+ isInsideComment = false;
141
+ buffer += strip(value, offset, index);
142
+ offset = index;
143
+ } else if (!isInsideComment && currentCharacter + (_nullishCoalesce(nextCharacter, () => ( EMPTY_STRING))) === "/*") {
144
+ buffer += value.slice(offset, index);
145
+ offset = index;
146
+ isInsideComment = multiComment;
147
+ index++;
148
+ } else if (isInsideComment === multiComment && currentCharacter + (_nullishCoalesce(nextCharacter, () => ( EMPTY_STRING))) === "*/") {
149
+ index++;
150
+ isInsideComment = false;
151
+ buffer += strip(value, offset, index + 1);
152
+ offset = index + 1;
153
+ } else if (trailingCommas && !isInsideComment) {
154
+ if (commaIndex !== -1) {
155
+ if (currentCharacter === "}" || currentCharacter === "]") {
156
+ buffer += value.slice(offset, index);
157
+ result += strip(buffer, 0, 1) + buffer.slice(1);
158
+ buffer = "";
159
+ offset = index;
160
+ commaIndex = -1;
161
+ } else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
162
+ buffer += value.slice(offset, index);
163
+ offset = index;
164
+ commaIndex = -1;
165
+ }
166
+ } else if (currentCharacter === ",") {
167
+ result += buffer + value.slice(offset, index);
168
+ buffer = "";
169
+ offset = index;
170
+ commaIndex = index;
171
+ }
172
+ }
173
+ }
174
+ return result + buffer + (isInsideComment ? strip(value.slice(offset)) : value.slice(offset));
175
+ }
176
+ _chunkUSNT2KNTcjs.__name.call(void 0, stripComments, "stripComments");
177
+
178
+ // ../json/src/utils/parse.ts
179
+ 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*:/;
180
+ 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*:/;
181
+ var JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:E[+-]?\d+)?\s*$/i;
182
+ function jsonParseTransform(key, value) {
183
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
184
+ console.warn(`Dropping "${key}" key to prevent prototype pollution.`);
185
+ return;
186
+ }
187
+ return value;
188
+ }
189
+ _chunkUSNT2KNTcjs.__name.call(void 0, jsonParseTransform, "jsonParseTransform");
190
+ function parse(value, options = {}) {
191
+ if (typeof value !== "string") {
192
+ return value;
193
+ }
194
+ let stripped = stripComments(value);
195
+ if (stripped[0] === '"' && stripped[stripped.length - 1] === '"' && !stripped.includes("\\")) {
196
+ return stripped.slice(1, -1);
197
+ }
198
+ stripped = stripped.trim();
199
+ if (stripped.length <= 9) {
200
+ switch (stripped.toLowerCase()) {
201
+ case "true": {
202
+ return true;
203
+ }
204
+ case "false": {
205
+ return false;
206
+ }
207
+ case "undefined": {
208
+ return void 0;
209
+ }
210
+ case "null": {
211
+ return null;
212
+ }
213
+ case "nan": {
214
+ return Number.NaN;
215
+ }
216
+ case "infinity": {
217
+ return Number.POSITIVE_INFINITY;
218
+ }
219
+ case "-infinity": {
220
+ return Number.NEGATIVE_INFINITY;
221
+ }
222
+ }
223
+ }
224
+ if (!JsonSigRx.test(stripped)) {
225
+ if (options.strict) {
226
+ throw new Error("Invalid JSON");
227
+ }
228
+ return stripped;
229
+ }
230
+ try {
231
+ if (suspectProtoRx.test(stripped) || suspectConstructorRx.test(stripped)) {
232
+ if (options.strict) {
233
+ throw new Error("Possible prototype pollution");
234
+ }
235
+ return JSON.parse(stripped, jsonParseTransform);
236
+ }
237
+ return JSON.parse(stripped);
238
+ } catch (error) {
239
+ if (options.strict) {
240
+ throw error;
241
+ }
242
+ return value;
243
+ }
244
+ }
245
+ _chunkUSNT2KNTcjs.__name.call(void 0, parse, "parse");
246
+
247
+ // ../json/src/utils/parse-error.ts
248
+
249
+ var _linesandcolumns = require('lines-and-columns');
250
+
251
+ // ../json/src/utils/code-frames.ts
252
+ var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
253
+ function getMarkerLines(loc, source, opts = {}) {
254
+ const startLoc = {
255
+ column: 0,
256
+ line: -1,
257
+ ...loc.start
258
+ };
259
+ const endLoc = {
260
+ ...startLoc,
261
+ ...loc.end
262
+ };
263
+ const { linesAbove = 2, linesBelow = 3 } = opts || {};
264
+ const startLine = startLoc.line;
265
+ const startColumn = startLoc.column;
266
+ const endLine = endLoc.line;
267
+ const endColumn = endLoc.column;
268
+ let start = Math.max(startLine - (linesAbove + 1), 0);
269
+ let end = Math.min(source.length, endLine + linesBelow);
270
+ if (startLine === -1) {
271
+ start = 0;
272
+ }
273
+ if (endLine === -1) {
274
+ end = source.length;
275
+ }
276
+ const lineDiff = endLine - startLine;
277
+ const markerLines = {};
278
+ if (lineDiff) {
279
+ for (let i = 0; i <= lineDiff; i++) {
280
+ const lineNumber = i + startLine;
281
+ if (!startColumn) {
282
+ markerLines[lineNumber] = true;
283
+ } else if (i === 0) {
284
+ const sourceLength = _nullishCoalesce(_optionalChain([source, 'access', _2 => _2[lineNumber - 1], 'optionalAccess', _3 => _3.length]), () => ( 0));
285
+ markerLines[lineNumber] = [
286
+ startColumn,
287
+ sourceLength - startColumn + 1
288
+ ];
289
+ } else if (i === lineDiff) {
290
+ markerLines[lineNumber] = [
291
+ 0,
292
+ endColumn
293
+ ];
294
+ } else {
295
+ const sourceLength = _nullishCoalesce(_optionalChain([source, 'access', _4 => _4[lineNumber - i], 'optionalAccess', _5 => _5.length]), () => ( 0));
296
+ markerLines[lineNumber] = [
297
+ 0,
298
+ sourceLength
299
+ ];
300
+ }
301
+ }
302
+ } else if (startColumn === endColumn) {
303
+ markerLines[startLine] = startColumn ? [
304
+ startColumn,
305
+ 0
306
+ ] : true;
307
+ } else {
308
+ markerLines[startLine] = [
309
+ startColumn,
310
+ endColumn - startColumn
311
+ ];
312
+ }
313
+ return {
314
+ start,
315
+ end,
316
+ markerLines
317
+ };
318
+ }
319
+ _chunkUSNT2KNTcjs.__name.call(void 0, getMarkerLines, "getMarkerLines");
320
+ function codeFrameColumns(rawLines, loc, opts = {}) {
321
+ const lines = rawLines.split(NEWLINE);
322
+ const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
323
+ const numberMaxWidth = String(end).length;
324
+ const highlightedLines = opts.highlight ? opts.highlight(rawLines) : rawLines;
325
+ const frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
326
+ const number = start + 1 + index;
327
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
328
+ const gutter = ` ${paddedNumber} | `;
329
+ const hasMarker = Boolean(_nullishCoalesce(markerLines[number], () => ( false)));
330
+ if (hasMarker) {
331
+ let markerLine = "";
332
+ if (Array.isArray(hasMarker)) {
333
+ const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
334
+ const numberOfMarkers = hasMarker[1] || 1;
335
+ markerLine = [
336
+ "\n ",
337
+ gutter.replace(/\d/g, " "),
338
+ markerSpacing,
339
+ "^".repeat(numberOfMarkers)
340
+ ].join("");
341
+ }
342
+ return [
343
+ ">",
344
+ gutter,
345
+ line,
346
+ markerLine
347
+ ].join("");
348
+ }
349
+ return ` ${gutter}${line}`;
350
+ }).join("\n");
351
+ return frame;
352
+ }
353
+ _chunkUSNT2KNTcjs.__name.call(void 0, codeFrameColumns, "codeFrameColumns");
354
+
355
+ // ../json/src/utils/parse-error.ts
356
+ function formatParseError(input, parseError) {
357
+ const { error, offset, length } = parseError;
358
+ const result = new (0, _linesandcolumns.LinesAndColumns)(input).locationForIndex(offset);
359
+ let line = _nullishCoalesce(_optionalChain([result, 'optionalAccess', _6 => _6.line]), () => ( 0));
360
+ let column = _nullishCoalesce(_optionalChain([result, 'optionalAccess', _7 => _7.column]), () => ( 0));
361
+ line++;
362
+ column++;
363
+ return `${_jsoncparser.printParseErrorCode.call(void 0, error)} in JSON at ${line}:${column}
364
+ ${codeFrameColumns(input, {
365
+ start: {
366
+ line,
367
+ column
368
+ },
369
+ end: {
370
+ line,
371
+ column: column + length
372
+ }
373
+ })}
374
+ `;
375
+ }
376
+ _chunkUSNT2KNTcjs.__name.call(void 0, formatParseError, "formatParseError");
377
+
378
+ // ../type-checks/src/is-number.ts
379
+ var isNumber = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
380
+ try {
381
+ return value instanceof Number || typeof value === "number" || Number(value) === value;
382
+ } catch (e3) {
383
+ return false;
384
+ }
385
+ }, "isNumber");
386
+
387
+ // ../type-checks/src/is-undefined.ts
388
+ var isUndefined = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value) => {
389
+ return value === void 0;
390
+ }, "isUndefined");
391
+
392
+ // ../json/src/utils/stringify.ts
393
+ var invalidKeyChars = [
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
+ var stringify = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (value, spacing = 2) => {
428
+ const space = isNumber(spacing) ? " ".repeat(spacing) : spacing;
429
+ switch (value) {
430
+ case null: {
431
+ return "null";
432
+ }
433
+ case void 0: {
434
+ return '"undefined"';
435
+ }
436
+ case true: {
437
+ return "true";
438
+ }
439
+ case false: {
440
+ return "false";
441
+ }
442
+ case Number.POSITIVE_INFINITY: {
443
+ return "infinity";
444
+ }
445
+ case Number.NEGATIVE_INFINITY: {
446
+ return "-infinity";
447
+ }
448
+ }
449
+ if (Array.isArray(value)) {
450
+ return `[${space}${value.map((v) => stringify(v, space)).join(`,${space}`)}${space}]`;
451
+ }
452
+ if (value instanceof Uint8Array) {
453
+ return value.toString();
454
+ }
455
+ switch (typeof value) {
456
+ case "number": {
457
+ return `${value}`;
458
+ }
459
+ case "string": {
460
+ return JSON.stringify(value);
461
+ }
462
+ case "object": {
463
+ const keys = Object.keys(value).filter((key) => !isUndefined(value[key]));
464
+ return `{${space}${keys.map((key) => `${invalidKeyChars.some((invalidKeyChar) => key.includes(invalidKeyChar)) ? `"${key}"` : key}: ${space}${stringify(value[key], space)}`).join(`,${space}`)}${space}}`;
465
+ }
466
+ default:
467
+ return "null";
468
+ }
469
+ }, "stringify");
470
+
471
+ // ../json/src/storm-json.ts
472
+ var StormJSON = class _StormJSON extends _superjson2.default {
473
+ static {
474
+ _chunkUSNT2KNTcjs.__name.call(void 0, this, "StormJSON");
475
+ }
476
+ static #instance;
477
+ static get instance() {
478
+ if (!_StormJSON.#instance) {
479
+ _StormJSON.#instance = new _StormJSON();
480
+ }
481
+ return _StormJSON.#instance;
482
+ }
483
+ /**
484
+ * Deserialize the given value with superjson using the given metadata
485
+ */
486
+ static deserialize(payload) {
487
+ return _StormJSON.instance.deserialize(payload);
488
+ }
489
+ /**
490
+ * Serialize the given value with superjson
491
+ */
492
+ static serialize(object) {
493
+ return _StormJSON.instance.serialize(object);
494
+ }
495
+ /**
496
+ * Parse the given string value with superjson using the given metadata
497
+ *
498
+ * @param value - The string value to parse
499
+ * @returns The parsed data
500
+ */
501
+ static parse(value) {
502
+ return parse(value);
503
+ }
504
+ /**
505
+ * Serializes the given data to a JSON string.
506
+ * By default the JSON string is formatted with a 2 space indentation to be easy readable.
507
+ *
508
+ * @param value - Object which should be serialized to JSON
509
+ * @param _options - JSON serialize options
510
+ * @returns the formatted JSON representation of the object
511
+ */
512
+ static stringify(value, _options) {
513
+ const customTransformer = _StormJSON.instance.customTransformerRegistry.findApplicable(value);
514
+ let result = value;
515
+ if (customTransformer && customTransformer.isApplicable(value)) {
516
+ result = customTransformer.serialize(result);
517
+ }
518
+ return stringify(result);
519
+ }
520
+ /**
521
+ * Parses the given JSON string and returns the object the JSON content represents.
522
+ * By default javascript-style comments and trailing commas are allowed.
523
+ *
524
+ * @param strData - JSON content as string
525
+ * @param options - JSON parse options
526
+ * @returns Object the JSON content represents
527
+ */
528
+ static parseJson(strData, options) {
529
+ try {
530
+ if (_optionalChain([options, 'optionalAccess', _8 => _8.expectComments]) === false) {
531
+ return _StormJSON.instance.parse(strData);
532
+ }
533
+ } catch (e4) {
534
+ }
535
+ const errors = [];
536
+ const opts = {
537
+ allowTrailingComma: true,
538
+ ...options
539
+ };
540
+ const result = _jsoncparser.parse.call(void 0, strData, errors, opts);
541
+ if (errors.length > 0 && errors[0]) {
542
+ throw new Error(formatParseError(strData, errors[0]));
543
+ }
544
+ return result;
545
+ }
546
+ /**
547
+ * Register a custom schema with superjson
548
+ *
549
+ * @param name - The name of the schema
550
+ * @param serialize - The function to serialize the schema
551
+ * @param deserialize - The function to deserialize the schema
552
+ * @param isApplicable - The function to check if the schema is applicable
553
+ */
554
+ static register(name, serialize, deserialize, isApplicable) {
555
+ _StormJSON.instance.registerCustom({
556
+ isApplicable,
557
+ serialize,
558
+ deserialize
559
+ }, name);
560
+ }
561
+ /**
562
+ * Register a class with superjson
563
+ *
564
+ * @param classConstructor - The class constructor to register
565
+ */
566
+ static registerClass(classConstructor, options) {
567
+ _StormJSON.instance.registerClass(classConstructor, {
568
+ identifier: isString(options) ? options : _optionalChain([options, 'optionalAccess', _9 => _9.identifier]) || classConstructor.name,
569
+ allowProps: options && isObject(options) && _optionalChain([options, 'optionalAccess', _10 => _10.allowProps]) && Array.isArray(options.allowProps) ? options.allowProps : [
570
+ "__typename"
571
+ ]
572
+ });
573
+ }
574
+ constructor() {
575
+ super({
576
+ dedupe: true
577
+ });
578
+ }
579
+ };
580
+ StormJSON.instance.registerCustom({
581
+ isApplicable: /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (v) => _buffer.Buffer.isBuffer(v), "isApplicable"),
582
+ serialize: /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (v) => v.toString("base64"), "serialize"),
583
+ deserialize: /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (v) => _buffer.Buffer.from(v, "base64"), "deserialize")
584
+ }, "Bytes");
585
+
586
+ // ../path/src/is-file.ts
587
+
588
+
589
+ // ../path/src/join-paths.ts
590
+ var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
591
+ function normalizeWindowsPath(input = "") {
592
+ if (!input) {
593
+ return input;
594
+ }
595
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
596
+ }
597
+ _chunkUSNT2KNTcjs.__name.call(void 0, normalizeWindowsPath, "normalizeWindowsPath");
598
+ var _UNC_REGEX = /^[/\\]{2}/;
599
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
600
+ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
601
+ var isAbsolute = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, function(p) {
602
+ return _IS_ABSOLUTE_RE.test(p);
603
+ }, "isAbsolute");
604
+ var correctPaths = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, function(path) {
605
+ if (!path || path.length === 0) {
606
+ return ".";
607
+ }
608
+ path = normalizeWindowsPath(path);
609
+ const isUNCPath = path.match(_UNC_REGEX);
610
+ const isPathAbsolute = isAbsolute(path);
611
+ const trailingSeparator = path[path.length - 1] === "/";
612
+ path = normalizeString(path, !isPathAbsolute);
613
+ if (path.length === 0) {
614
+ if (isPathAbsolute) {
615
+ return "/";
616
+ }
617
+ return trailingSeparator ? "./" : ".";
618
+ }
619
+ if (trailingSeparator) {
620
+ path += "/";
621
+ }
622
+ if (_DRIVE_LETTER_RE.test(path)) {
623
+ path += "/";
624
+ }
625
+ if (isUNCPath) {
626
+ if (!isPathAbsolute) {
627
+ return `//./${path}`;
628
+ }
629
+ return `//${path}`;
630
+ }
631
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
632
+ }, "correctPaths");
633
+ var joinPaths = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, function(...segments) {
634
+ let path = "";
635
+ for (const seg of segments) {
636
+ if (!seg) {
637
+ continue;
638
+ }
639
+ if (path.length > 0) {
640
+ const pathTrailing = path[path.length - 1] === "/";
641
+ const segLeading = seg[0] === "/";
642
+ const both = pathTrailing && segLeading;
643
+ if (both) {
644
+ path += seg.slice(1);
645
+ } else {
646
+ path += pathTrailing || segLeading ? seg : `/${seg}`;
647
+ }
648
+ } else {
649
+ path += seg;
650
+ }
651
+ }
652
+ return correctPaths(path);
653
+ }, "joinPaths");
654
+ function normalizeString(path, allowAboveRoot) {
655
+ let res = "";
656
+ let lastSegmentLength = 0;
657
+ let lastSlash = -1;
658
+ let dots = 0;
659
+ let char = null;
660
+ for (let index = 0; index <= path.length; ++index) {
661
+ if (index < path.length) {
662
+ char = path[index];
663
+ } else if (char === "/") {
664
+ break;
665
+ } else {
666
+ char = "/";
667
+ }
668
+ if (char === "/") {
669
+ if (lastSlash === index - 1 || dots === 1) {
670
+ } else if (dots === 2) {
671
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
672
+ if (res.length > 2) {
673
+ const lastSlashIndex = res.lastIndexOf("/");
674
+ if (lastSlashIndex === -1) {
675
+ res = "";
676
+ lastSegmentLength = 0;
677
+ } else {
678
+ res = res.slice(0, lastSlashIndex);
679
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
680
+ }
681
+ lastSlash = index;
682
+ dots = 0;
683
+ continue;
684
+ } else if (res.length > 0) {
685
+ res = "";
686
+ lastSegmentLength = 0;
687
+ lastSlash = index;
688
+ dots = 0;
689
+ continue;
690
+ }
691
+ }
692
+ if (allowAboveRoot) {
693
+ res += res.length > 0 ? "/.." : "..";
694
+ lastSegmentLength = 2;
695
+ }
696
+ } else {
697
+ if (res.length > 0) {
698
+ res += `/${path.slice(lastSlash + 1, index)}`;
699
+ } else {
700
+ res = path.slice(lastSlash + 1, index);
701
+ }
702
+ lastSegmentLength = index - lastSlash - 1;
703
+ }
704
+ lastSlash = index;
705
+ dots = 0;
706
+ } else if (char === "." && dots !== -1) {
707
+ ++dots;
708
+ } else {
709
+ dots = -1;
710
+ }
711
+ }
712
+ return res;
713
+ }
714
+ _chunkUSNT2KNTcjs.__name.call(void 0, normalizeString, "normalizeString");
715
+
716
+ // ../path/src/regex.ts
717
+ var DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
718
+ var DRIVE_LETTER_REGEX = /^[A-Z]:$/i;
719
+ var UNC_REGEX = /^[/\\]{2}/;
720
+ var ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
721
+
722
+ // ../path/src/slash.ts
723
+ function slash(path) {
724
+ if (path.startsWith("\\\\?\\")) {
725
+ return path;
726
+ }
727
+ return path.replace(/\\/g, "/");
728
+ }
729
+ _chunkUSNT2KNTcjs.__name.call(void 0, slash, "slash");
730
+
731
+ // ../path/src/is-file.ts
732
+ function isAbsolutePath(path) {
733
+ return ABSOLUTE_PATH_REGEX.test(slash(path));
734
+ }
735
+ _chunkUSNT2KNTcjs.__name.call(void 0, isAbsolutePath, "isAbsolutePath");
736
+
737
+ // ../path/src/correct-path.ts
738
+ function normalizeWindowsPath2(input = "") {
739
+ if (!input) {
740
+ return input;
741
+ }
742
+ return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
743
+ }
744
+ _chunkUSNT2KNTcjs.__name.call(void 0, normalizeWindowsPath2, "normalizeWindowsPath");
745
+ function correctPath(path) {
746
+ if (!path || path.length === 0) {
747
+ return ".";
748
+ }
749
+ path = normalizeWindowsPath2(path);
750
+ const isUNCPath = path.match(UNC_REGEX);
751
+ const isPathAbsolute = isAbsolutePath(path);
752
+ const trailingSeparator = path.endsWith("/");
753
+ path = normalizeString2(path, !isPathAbsolute);
754
+ if (path.length === 0) {
755
+ if (isPathAbsolute) {
756
+ return "/";
757
+ }
758
+ return trailingSeparator ? "./" : ".";
759
+ }
760
+ if (trailingSeparator) {
761
+ path += "/";
762
+ }
763
+ if (DRIVE_LETTER_REGEX.test(path)) {
764
+ path += "/";
765
+ }
766
+ if (isUNCPath) {
767
+ if (!isPathAbsolute) {
768
+ return `//./${path}`;
769
+ }
770
+ return `//${path}`;
771
+ }
772
+ return !path.startsWith("/") && isPathAbsolute && !DRIVE_LETTER_REGEX.test(path) ? `/${path}` : path;
773
+ }
774
+ _chunkUSNT2KNTcjs.__name.call(void 0, correctPath, "correctPath");
775
+ function normalizeString2(path, allowAboveRoot) {
776
+ let res = "";
777
+ let lastSegmentLength = 0;
778
+ let lastSlash = -1;
779
+ let dots = 0;
780
+ let char = null;
781
+ for (let index = 0; index <= path.length; ++index) {
782
+ if (index < path.length) {
783
+ char = path[index];
784
+ } else if (char === "/") {
785
+ break;
786
+ } else {
787
+ char = "/";
788
+ }
789
+ if (char === "/") {
790
+ if (lastSlash === index - 1 || dots === 1) {
791
+ } else if (dots === 2) {
792
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
793
+ if (res.length > 2) {
794
+ const lastSlashIndex = res.lastIndexOf("/");
795
+ if (lastSlashIndex === -1) {
796
+ res = "";
797
+ lastSegmentLength = 0;
798
+ } else {
799
+ res = res.slice(0, lastSlashIndex);
800
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
801
+ }
802
+ lastSlash = index;
803
+ dots = 0;
804
+ continue;
805
+ } else if (res.length > 0) {
806
+ res = "";
807
+ lastSegmentLength = 0;
808
+ lastSlash = index;
809
+ dots = 0;
810
+ continue;
811
+ }
812
+ }
813
+ if (allowAboveRoot) {
814
+ res += res.length > 0 ? "/.." : "..";
815
+ lastSegmentLength = 2;
816
+ }
817
+ } else {
818
+ if (res.length > 0) {
819
+ res += `/${path.slice(lastSlash + 1, index)}`;
820
+ } else {
821
+ res = path.slice(lastSlash + 1, index);
822
+ }
823
+ lastSegmentLength = index - lastSlash - 1;
824
+ }
825
+ lastSlash = index;
826
+ dots = 0;
827
+ } else if (char === "." && dots !== -1) {
828
+ ++dots;
829
+ } else {
830
+ dots = -1;
831
+ }
832
+ }
833
+ return res;
834
+ }
835
+ _chunkUSNT2KNTcjs.__name.call(void 0, normalizeString2, "normalizeString");
836
+
837
+ // ../path/src/file-path-fns.ts
838
+ var _path = require('path');
839
+
840
+ // ../path/src/get-workspace-root.ts
841
+ var _configtools = require('@storm-software/config-tools');
842
+
843
+ // ../path/src/file-path-fns.ts
844
+ function findFileName(filePath, options = {}) {
845
+ const { requireExtension = false, withExtension = true } = options;
846
+ const result = _nullishCoalesce(_optionalChain([normalizeWindowsPath2, 'call', _11 => _11(filePath), 'optionalAccess', _12 => _12.split, 'call', _13 => _13(_optionalChain([filePath, 'optionalAccess', _14 => _14.includes, 'call', _15 => _15("\\")]) ? "\\" : "/"), 'optionalAccess', _16 => _16.pop, 'call', _17 => _17()]), () => ( ""));
847
+ if (requireExtension === true && !result.includes(".")) {
848
+ return EMPTY_STRING;
849
+ }
850
+ if (withExtension === false && result.includes(".")) {
851
+ return result.substring(0, result.lastIndexOf(".")) || EMPTY_STRING;
852
+ }
853
+ return result;
854
+ }
855
+ _chunkUSNT2KNTcjs.__name.call(void 0, findFileName, "findFileName");
856
+ function findFilePath(filePath) {
857
+ const normalizedPath = normalizeWindowsPath2(filePath);
858
+ const result = normalizedPath.replace(findFileName(normalizedPath, {
859
+ requireExtension: true
860
+ }), "");
861
+ return result === "/" ? result : result.replace(/\/$/, "");
862
+ }
863
+ _chunkUSNT2KNTcjs.__name.call(void 0, findFilePath, "findFilePath");
864
+
865
+ // ../fs/src/write-file.ts
866
+ var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);
867
+
868
+
869
+ var writeFile = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (filePath, content = "", options = {}) => {
870
+ if (!filePath) {
871
+ throw new Error("No file path provided to read data");
872
+ }
873
+ const directory = findFilePath(correctPath(filePath));
874
+ if (!existsSync(directory)) {
875
+ if (options.createDirectory !== false) {
876
+ await createDirectory(directory);
877
+ } else {
878
+ throw new Error(`Directory ${directory} does not exist`);
879
+ }
880
+ }
881
+ return _promises.writeFile.call(void 0, filePath, content || "", options);
882
+ }, "writeFile");
883
+
884
+ // src/compile.ts
885
+ var _compiler = require('capnp-es/compiler');
886
+
887
+ var _child_process = require('child_process');
888
+
889
+ async function readStdin() {
890
+ if (process.stdin.isTTY) {
891
+ return _buffer.Buffer.alloc(0);
892
+ }
893
+ const chunks = [];
894
+ process.stdin.on("data", (chunk) => {
895
+ chunks.push(chunk);
896
+ });
897
+ await new Promise((resolve) => {
898
+ process.stdin.on("end", resolve);
899
+ });
900
+ const reqBuffer = _buffer.Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
901
+ let i = 0;
902
+ for (const chunk of chunks) {
903
+ chunk.copy(reqBuffer, i);
904
+ i += chunk.byteLength;
905
+ }
906
+ return reqBuffer;
907
+ }
908
+ _chunkUSNT2KNTcjs.__name.call(void 0, readStdin, "readStdin");
909
+ async function capnpc(options) {
910
+ try {
911
+ const { outputPath, tsconfig, sourcePath = [] } = options;
912
+ let dataBuf = await readStdin();
913
+ if (dataBuf.byteLength === 0) {
914
+ const opts = [];
915
+ if (outputPath) {
916
+ opts.push(`-o-:${outputPath}`);
917
+ } else {
918
+ opts.push("-o-");
919
+ }
920
+ dataBuf = await new Promise((resolve) => {
921
+ _child_process.exec.call(void 0, `capnpc ${opts.join(" ")} ${sourcePath.join(" ")}`, {
922
+ encoding: "buffer"
923
+ }, (error, stdout, stderr) => {
924
+ if (stderr.length > 0) {
925
+ process.stderr.write(stderr);
926
+ }
927
+ if (error) {
928
+ throw error;
929
+ }
930
+ resolve(stdout);
931
+ });
932
+ });
933
+ }
934
+ const result = await _compiler.compileAll.call(void 0, dataBuf, {
935
+ ts: _nullishCoalesce(options.ts, () => ( true)),
936
+ js: _nullishCoalesce(options.js, () => ( false)),
937
+ dts: _nullishCoalesce(options.dts, () => ( true)),
938
+ tsconfig: _optionalChain([tsconfig, 'optionalAccess', _18 => _18.options])
939
+ });
940
+ for (const [fileName, content] of result.files) {
941
+ let filePath = fileName;
942
+ if (!_fs.existsSync.call(void 0, findFilePath(filePath))) {
943
+ const fullPath = `/${filePath}`;
944
+ if (_fs.existsSync.call(void 0, findFilePath(fullPath))) {
945
+ filePath = fullPath;
946
+ }
947
+ }
948
+ if (outputPath) {
949
+ filePath = joinPaths(outputPath, fileName);
950
+ }
951
+ if (!_fs.existsSync.call(void 0, findFilePath(filePath))) {
952
+ await createDirectory(findFilePath(filePath));
953
+ }
954
+ await writeFile(
955
+ filePath,
956
+ // https://github.com/microsoft/TypeScript/issues/54632
957
+ content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
958
+ );
959
+ }
960
+ return result;
961
+ } catch (error) {
962
+ if (error instanceof Error) {
963
+ console.error(`Error: ${error.message}`);
964
+ if (error.stack) {
965
+ console.error(error.stack);
966
+ }
967
+ } else {
968
+ console.error("An unknown error occurred:", error);
969
+ }
970
+ throw error;
971
+ }
972
+ }
973
+ _chunkUSNT2KNTcjs.__name.call(void 0, capnpc, "capnpc");
974
+
975
+
976
+
977
+ exports.capnpc = capnpc;