@nuucognition/flint-cli 0.5.6-dev.7 → 0.6.0-dev.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.
@@ -1,1629 +0,0 @@
1
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/error.js
2
- function getLineColFromPtr(string, ptr) {
3
- let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
4
- return [lines.length, lines.pop().length + 1];
5
- }
6
- function makeCodeBlock(string, line, column) {
7
- let lines = string.split(/\r\n|\n|\r/g);
8
- let codeblock = "";
9
- let numberLen = (Math.log10(line + 1) | 0) + 1;
10
- for (let i = line - 1; i <= line + 1; i++) {
11
- let l = lines[i - 1];
12
- if (!l)
13
- continue;
14
- codeblock += i.toString().padEnd(numberLen, " ");
15
- codeblock += ": ";
16
- codeblock += l;
17
- codeblock += "\n";
18
- if (i === line) {
19
- codeblock += " ".repeat(numberLen + column + 2);
20
- codeblock += "^\n";
21
- }
22
- }
23
- return codeblock;
24
- }
25
- var TomlError = class extends Error {
26
- line;
27
- column;
28
- codeblock;
29
- constructor(message, options) {
30
- const [line, column] = getLineColFromPtr(options.toml, options.ptr);
31
- const codeblock = makeCodeBlock(options.toml, line, column);
32
- super(`Invalid TOML document: ${message}
33
-
34
- ${codeblock}`, options);
35
- this.line = line;
36
- this.column = column;
37
- this.codeblock = codeblock;
38
- }
39
- };
40
-
41
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/util.js
42
- function isEscaped(str, ptr) {
43
- let i = 0;
44
- while (str[ptr - ++i] === "\\")
45
- ;
46
- return --i && i % 2;
47
- }
48
- function indexOfNewline(str, start = 0, end = str.length) {
49
- let idx = str.indexOf("\n", start);
50
- if (str[idx - 1] === "\r")
51
- idx--;
52
- return idx <= end ? idx : -1;
53
- }
54
- function skipComment(str, ptr) {
55
- for (let i = ptr; i < str.length; i++) {
56
- let c = str[i];
57
- if (c === "\n")
58
- return i;
59
- if (c === "\r" && str[i + 1] === "\n")
60
- return i + 1;
61
- if (c < " " && c !== " " || c === "\x7F") {
62
- throw new TomlError("control characters are not allowed in comments", {
63
- toml: str,
64
- ptr
65
- });
66
- }
67
- }
68
- return str.length;
69
- }
70
- function skipVoid(str, ptr, banNewLines, banComments) {
71
- let c;
72
- while ((c = str[ptr]) === " " || c === " " || !banNewLines && (c === "\n" || c === "\r" && str[ptr + 1] === "\n"))
73
- ptr++;
74
- return banComments || c !== "#" ? ptr : skipVoid(str, skipComment(str, ptr), banNewLines);
75
- }
76
- function skipUntil(str, ptr, sep, end, banNewLines = false) {
77
- if (!end) {
78
- ptr = indexOfNewline(str, ptr);
79
- return ptr < 0 ? str.length : ptr;
80
- }
81
- for (let i = ptr; i < str.length; i++) {
82
- let c = str[i];
83
- if (c === "#") {
84
- i = indexOfNewline(str, i);
85
- } else if (c === sep) {
86
- return i + 1;
87
- } else if (c === end || banNewLines && (c === "\n" || c === "\r" && str[i + 1] === "\n")) {
88
- return i;
89
- }
90
- }
91
- throw new TomlError("cannot find end of structure", {
92
- toml: str,
93
- ptr
94
- });
95
- }
96
- function getStringEnd(str, seek) {
97
- let first = str[seek];
98
- let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2] ? str.slice(seek, seek + 3) : first;
99
- seek += target.length - 1;
100
- do
101
- seek = str.indexOf(target, ++seek);
102
- while (seek > -1 && first !== "'" && isEscaped(str, seek));
103
- if (seek > -1) {
104
- seek += target.length;
105
- if (target.length > 1) {
106
- if (str[seek] === first)
107
- seek++;
108
- if (str[seek] === first)
109
- seek++;
110
- }
111
- }
112
- return seek;
113
- }
114
-
115
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/date.js
116
- var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
117
- var TomlDate = class _TomlDate extends Date {
118
- #hasDate = false;
119
- #hasTime = false;
120
- #offset = null;
121
- constructor(date) {
122
- let hasDate = true;
123
- let hasTime = true;
124
- let offset = "Z";
125
- if (typeof date === "string") {
126
- let match = date.match(DATE_TIME_RE);
127
- if (match) {
128
- if (!match[1]) {
129
- hasDate = false;
130
- date = `0000-01-01T${date}`;
131
- }
132
- hasTime = !!match[2];
133
- hasTime && date[10] === " " && (date = date.replace(" ", "T"));
134
- if (match[2] && +match[2] > 23) {
135
- date = "";
136
- } else {
137
- offset = match[3] || null;
138
- date = date.toUpperCase();
139
- if (!offset && hasTime)
140
- date += "Z";
141
- }
142
- } else {
143
- date = "";
144
- }
145
- }
146
- super(date);
147
- if (!isNaN(this.getTime())) {
148
- this.#hasDate = hasDate;
149
- this.#hasTime = hasTime;
150
- this.#offset = offset;
151
- }
152
- }
153
- isDateTime() {
154
- return this.#hasDate && this.#hasTime;
155
- }
156
- isLocal() {
157
- return !this.#hasDate || !this.#hasTime || !this.#offset;
158
- }
159
- isDate() {
160
- return this.#hasDate && !this.#hasTime;
161
- }
162
- isTime() {
163
- return this.#hasTime && !this.#hasDate;
164
- }
165
- isValid() {
166
- return this.#hasDate || this.#hasTime;
167
- }
168
- toISOString() {
169
- let iso = super.toISOString();
170
- if (this.isDate())
171
- return iso.slice(0, 10);
172
- if (this.isTime())
173
- return iso.slice(11, 23);
174
- if (this.#offset === null)
175
- return iso.slice(0, -1);
176
- if (this.#offset === "Z")
177
- return iso;
178
- let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
179
- offset = this.#offset[0] === "-" ? offset : -offset;
180
- let offsetDate = new Date(this.getTime() - offset * 6e4);
181
- return offsetDate.toISOString().slice(0, -1) + this.#offset;
182
- }
183
- static wrapAsOffsetDateTime(jsDate, offset = "Z") {
184
- let date = new _TomlDate(jsDate);
185
- date.#offset = offset;
186
- return date;
187
- }
188
- static wrapAsLocalDateTime(jsDate) {
189
- let date = new _TomlDate(jsDate);
190
- date.#offset = null;
191
- return date;
192
- }
193
- static wrapAsLocalDate(jsDate) {
194
- let date = new _TomlDate(jsDate);
195
- date.#hasTime = false;
196
- date.#offset = null;
197
- return date;
198
- }
199
- static wrapAsLocalTime(jsDate) {
200
- let date = new _TomlDate(jsDate);
201
- date.#hasDate = false;
202
- date.#offset = null;
203
- return date;
204
- }
205
- };
206
-
207
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/primitive.js
208
- var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
209
- var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
210
- var LEADING_ZERO = /^[+-]?0[0-9_]/;
211
- var ESCAPE_REGEX = /^[0-9a-f]{2,8}$/i;
212
- var ESC_MAP = {
213
- b: "\b",
214
- t: " ",
215
- n: "\n",
216
- f: "\f",
217
- r: "\r",
218
- e: "\x1B",
219
- '"': '"',
220
- "\\": "\\"
221
- };
222
- function parseString(str, ptr = 0, endPtr = str.length) {
223
- let isLiteral = str[ptr] === "'";
224
- let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
225
- if (isMultiline) {
226
- endPtr -= 2;
227
- if (str[ptr += 2] === "\r")
228
- ptr++;
229
- if (str[ptr] === "\n")
230
- ptr++;
231
- }
232
- let tmp = 0;
233
- let isEscape;
234
- let parsed = "";
235
- let sliceStart = ptr;
236
- while (ptr < endPtr - 1) {
237
- let c = str[ptr++];
238
- if (c === "\n" || c === "\r" && str[ptr] === "\n") {
239
- if (!isMultiline) {
240
- throw new TomlError("newlines are not allowed in strings", {
241
- toml: str,
242
- ptr: ptr - 1
243
- });
244
- }
245
- } else if (c < " " && c !== " " || c === "\x7F") {
246
- throw new TomlError("control characters are not allowed in strings", {
247
- toml: str,
248
- ptr: ptr - 1
249
- });
250
- }
251
- if (isEscape) {
252
- isEscape = false;
253
- if (c === "x" || c === "u" || c === "U") {
254
- let code = str.slice(ptr, ptr += c === "x" ? 2 : c === "u" ? 4 : 8);
255
- if (!ESCAPE_REGEX.test(code)) {
256
- throw new TomlError("invalid unicode escape", {
257
- toml: str,
258
- ptr: tmp
259
- });
260
- }
261
- try {
262
- parsed += String.fromCodePoint(parseInt(code, 16));
263
- } catch {
264
- throw new TomlError("invalid unicode escape", {
265
- toml: str,
266
- ptr: tmp
267
- });
268
- }
269
- } else if (isMultiline && (c === "\n" || c === " " || c === " " || c === "\r")) {
270
- ptr = skipVoid(str, ptr - 1, true);
271
- if (str[ptr] !== "\n" && str[ptr] !== "\r") {
272
- throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
273
- toml: str,
274
- ptr: tmp
275
- });
276
- }
277
- ptr = skipVoid(str, ptr);
278
- } else if (c in ESC_MAP) {
279
- parsed += ESC_MAP[c];
280
- } else {
281
- throw new TomlError("unrecognized escape sequence", {
282
- toml: str,
283
- ptr: tmp
284
- });
285
- }
286
- sliceStart = ptr;
287
- } else if (!isLiteral && c === "\\") {
288
- tmp = ptr - 1;
289
- isEscape = true;
290
- parsed += str.slice(sliceStart, tmp);
291
- }
292
- }
293
- return parsed + str.slice(sliceStart, endPtr - 1);
294
- }
295
- function parseValue(value, toml, ptr, integersAsBigInt) {
296
- if (value === "true")
297
- return true;
298
- if (value === "false")
299
- return false;
300
- if (value === "-inf")
301
- return -Infinity;
302
- if (value === "inf" || value === "+inf")
303
- return Infinity;
304
- if (value === "nan" || value === "+nan" || value === "-nan")
305
- return NaN;
306
- if (value === "-0")
307
- return integersAsBigInt ? 0n : 0;
308
- let isInt = INT_REGEX.test(value);
309
- if (isInt || FLOAT_REGEX.test(value)) {
310
- if (LEADING_ZERO.test(value)) {
311
- throw new TomlError("leading zeroes are not allowed", {
312
- toml,
313
- ptr
314
- });
315
- }
316
- value = value.replace(/_/g, "");
317
- let numeric = +value;
318
- if (isNaN(numeric)) {
319
- throw new TomlError("invalid number", {
320
- toml,
321
- ptr
322
- });
323
- }
324
- if (isInt) {
325
- if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
326
- throw new TomlError("integer value cannot be represented losslessly", {
327
- toml,
328
- ptr
329
- });
330
- }
331
- if (isInt || integersAsBigInt === true)
332
- numeric = BigInt(value);
333
- }
334
- return numeric;
335
- }
336
- const date = new TomlDate(value);
337
- if (!date.isValid()) {
338
- throw new TomlError("invalid value", {
339
- toml,
340
- ptr
341
- });
342
- }
343
- return date;
344
- }
345
-
346
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/extract.js
347
- function sliceAndTrimEndOf(str, startPtr, endPtr) {
348
- let value = str.slice(startPtr, endPtr);
349
- let commentIdx = value.indexOf("#");
350
- if (commentIdx > -1) {
351
- skipComment(str, commentIdx);
352
- value = value.slice(0, commentIdx);
353
- }
354
- return [value.trimEnd(), commentIdx];
355
- }
356
- function extractValue(str, ptr, end, depth, integersAsBigInt) {
357
- if (depth === 0) {
358
- throw new TomlError("document contains excessively nested structures. aborting.", {
359
- toml: str,
360
- ptr
361
- });
362
- }
363
- let c = str[ptr];
364
- if (c === "[" || c === "{") {
365
- let [value, endPtr2] = c === "[" ? parseArray(str, ptr, depth, integersAsBigInt) : parseInlineTable(str, ptr, depth, integersAsBigInt);
366
- if (end) {
367
- endPtr2 = skipVoid(str, endPtr2);
368
- if (str[endPtr2] === ",")
369
- endPtr2++;
370
- else if (str[endPtr2] !== end) {
371
- throw new TomlError("expected comma or end of structure", {
372
- toml: str,
373
- ptr: endPtr2
374
- });
375
- }
376
- }
377
- return [value, endPtr2];
378
- }
379
- let endPtr;
380
- if (c === '"' || c === "'") {
381
- endPtr = getStringEnd(str, ptr);
382
- let parsed = parseString(str, ptr, endPtr);
383
- if (end) {
384
- endPtr = skipVoid(str, endPtr);
385
- if (str[endPtr] && str[endPtr] !== "," && str[endPtr] !== end && str[endPtr] !== "\n" && str[endPtr] !== "\r") {
386
- throw new TomlError("unexpected character encountered", {
387
- toml: str,
388
- ptr: endPtr
389
- });
390
- }
391
- endPtr += +(str[endPtr] === ",");
392
- }
393
- return [parsed, endPtr];
394
- }
395
- endPtr = skipUntil(str, ptr, ",", end);
396
- let slice = sliceAndTrimEndOf(str, ptr, endPtr - +(str[endPtr - 1] === ","));
397
- if (!slice[0]) {
398
- throw new TomlError("incomplete key-value declaration: no value specified", {
399
- toml: str,
400
- ptr
401
- });
402
- }
403
- if (end && slice[1] > -1) {
404
- endPtr = skipVoid(str, ptr + slice[1]);
405
- endPtr += +(str[endPtr] === ",");
406
- }
407
- return [
408
- parseValue(slice[0], str, ptr, integersAsBigInt),
409
- endPtr
410
- ];
411
- }
412
-
413
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/struct.js
414
- var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
415
- function parseKey(str, ptr, end = "=") {
416
- let dot = ptr - 1;
417
- let parsed = [];
418
- let endPtr = str.indexOf(end, ptr);
419
- if (endPtr < 0) {
420
- throw new TomlError("incomplete key-value: cannot find end of key", {
421
- toml: str,
422
- ptr
423
- });
424
- }
425
- do {
426
- let c = str[ptr = ++dot];
427
- if (c !== " " && c !== " ") {
428
- if (c === '"' || c === "'") {
429
- if (c === str[ptr + 1] && c === str[ptr + 2]) {
430
- throw new TomlError("multiline strings are not allowed in keys", {
431
- toml: str,
432
- ptr
433
- });
434
- }
435
- let eos = getStringEnd(str, ptr);
436
- if (eos < 0) {
437
- throw new TomlError("unfinished string encountered", {
438
- toml: str,
439
- ptr
440
- });
441
- }
442
- dot = str.indexOf(".", eos);
443
- let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
444
- let newLine = indexOfNewline(strEnd);
445
- if (newLine > -1) {
446
- throw new TomlError("newlines are not allowed in keys", {
447
- toml: str,
448
- ptr: ptr + dot + newLine
449
- });
450
- }
451
- if (strEnd.trimStart()) {
452
- throw new TomlError("found extra tokens after the string part", {
453
- toml: str,
454
- ptr: eos
455
- });
456
- }
457
- if (endPtr < eos) {
458
- endPtr = str.indexOf(end, eos);
459
- if (endPtr < 0) {
460
- throw new TomlError("incomplete key-value: cannot find end of key", {
461
- toml: str,
462
- ptr
463
- });
464
- }
465
- }
466
- parsed.push(parseString(str, ptr, eos));
467
- } else {
468
- dot = str.indexOf(".", ptr);
469
- let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
470
- if (!KEY_PART_RE.test(part)) {
471
- throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
472
- toml: str,
473
- ptr
474
- });
475
- }
476
- parsed.push(part.trimEnd());
477
- }
478
- }
479
- } while (dot + 1 && dot < endPtr);
480
- return [parsed, skipVoid(str, endPtr + 1, true, true)];
481
- }
482
- function parseInlineTable(str, ptr, depth, integersAsBigInt) {
483
- let res = {};
484
- let seen = /* @__PURE__ */ new Set();
485
- let c;
486
- ptr++;
487
- while ((c = str[ptr++]) !== "}" && c) {
488
- if (c === ",") {
489
- throw new TomlError("expected value, found comma", {
490
- toml: str,
491
- ptr: ptr - 1
492
- });
493
- } else if (c === "#")
494
- ptr = skipComment(str, ptr);
495
- else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
496
- let k;
497
- let t = res;
498
- let hasOwn = false;
499
- let [key, keyEndPtr] = parseKey(str, ptr - 1);
500
- for (let i = 0; i < key.length; i++) {
501
- if (i)
502
- t = hasOwn ? t[k] : t[k] = {};
503
- k = key[i];
504
- if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
505
- throw new TomlError("trying to redefine an already defined value", {
506
- toml: str,
507
- ptr
508
- });
509
- }
510
- if (!hasOwn && k === "__proto__") {
511
- Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
512
- }
513
- }
514
- if (hasOwn) {
515
- throw new TomlError("trying to redefine an already defined value", {
516
- toml: str,
517
- ptr
518
- });
519
- }
520
- let [value, valueEndPtr] = extractValue(str, keyEndPtr, "}", depth - 1, integersAsBigInt);
521
- seen.add(value);
522
- t[k] = value;
523
- ptr = valueEndPtr;
524
- }
525
- }
526
- if (!c) {
527
- throw new TomlError("unfinished table encountered", {
528
- toml: str,
529
- ptr
530
- });
531
- }
532
- return [res, ptr];
533
- }
534
- function parseArray(str, ptr, depth, integersAsBigInt) {
535
- let res = [];
536
- let c;
537
- ptr++;
538
- while ((c = str[ptr++]) !== "]" && c) {
539
- if (c === ",") {
540
- throw new TomlError("expected value, found comma", {
541
- toml: str,
542
- ptr: ptr - 1
543
- });
544
- } else if (c === "#")
545
- ptr = skipComment(str, ptr);
546
- else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
547
- let e = extractValue(str, ptr - 1, "]", depth - 1, integersAsBigInt);
548
- res.push(e[0]);
549
- ptr = e[1];
550
- }
551
- }
552
- if (!c) {
553
- throw new TomlError("unfinished array encountered", {
554
- toml: str,
555
- ptr
556
- });
557
- }
558
- return [res, ptr];
559
- }
560
-
561
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/parse.js
562
- function peekTable(key, table, meta, type) {
563
- let t = table;
564
- let m = meta;
565
- let k;
566
- let hasOwn = false;
567
- let state;
568
- for (let i = 0; i < key.length; i++) {
569
- if (i) {
570
- t = hasOwn ? t[k] : t[k] = {};
571
- m = (state = m[k]).c;
572
- if (type === 0 && (state.t === 1 || state.t === 2)) {
573
- return null;
574
- }
575
- if (state.t === 2) {
576
- let l = t.length - 1;
577
- t = t[l];
578
- m = m[l].c;
579
- }
580
- }
581
- k = key[i];
582
- if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
583
- return null;
584
- }
585
- if (!hasOwn) {
586
- if (k === "__proto__") {
587
- Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
588
- Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
589
- }
590
- m[k] = {
591
- t: i < key.length - 1 && type === 2 ? 3 : type,
592
- d: false,
593
- i: 0,
594
- c: {}
595
- };
596
- }
597
- }
598
- state = m[k];
599
- if (state.t !== type && !(type === 1 && state.t === 3)) {
600
- return null;
601
- }
602
- if (type === 2) {
603
- if (!state.d) {
604
- state.d = true;
605
- t[k] = [];
606
- }
607
- t[k].push(t = {});
608
- state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
609
- }
610
- if (state.d) {
611
- return null;
612
- }
613
- state.d = true;
614
- if (type === 1) {
615
- t = hasOwn ? t[k] : t[k] = {};
616
- } else if (type === 0 && hasOwn) {
617
- return null;
618
- }
619
- return [k, t, state.c];
620
- }
621
- function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
622
- let res = {};
623
- let meta = {};
624
- let tbl = res;
625
- let m = meta;
626
- for (let ptr = skipVoid(toml, 0); ptr < toml.length; ) {
627
- if (toml[ptr] === "[") {
628
- let isTableArray = toml[++ptr] === "[";
629
- let k = parseKey(toml, ptr += +isTableArray, "]");
630
- if (isTableArray) {
631
- if (toml[k[1] - 1] !== "]") {
632
- throw new TomlError("expected end of table declaration", {
633
- toml,
634
- ptr: k[1] - 1
635
- });
636
- }
637
- k[1]++;
638
- }
639
- let p = peekTable(
640
- k[0],
641
- res,
642
- meta,
643
- isTableArray ? 2 : 1
644
- /* Type.EXPLICIT */
645
- );
646
- if (!p) {
647
- throw new TomlError("trying to redefine an already defined table or value", {
648
- toml,
649
- ptr
650
- });
651
- }
652
- m = p[2];
653
- tbl = p[1];
654
- ptr = k[1];
655
- } else {
656
- let k = parseKey(toml, ptr);
657
- let p = peekTable(
658
- k[0],
659
- tbl,
660
- m,
661
- 0
662
- /* Type.DOTTED */
663
- );
664
- if (!p) {
665
- throw new TomlError("trying to redefine an already defined table or value", {
666
- toml,
667
- ptr
668
- });
669
- }
670
- let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
671
- p[1][p[0]] = v[0];
672
- ptr = v[1];
673
- }
674
- ptr = skipVoid(toml, ptr, true);
675
- if (toml[ptr] && toml[ptr] !== "\n" && toml[ptr] !== "\r") {
676
- throw new TomlError("each key-value declaration must be followed by an end-of-line", {
677
- toml,
678
- ptr
679
- });
680
- }
681
- ptr = skipVoid(toml, ptr);
682
- }
683
- return res;
684
- }
685
-
686
- // ../../node_modules/.pnpm/smol-toml@1.6.0/node_modules/smol-toml/dist/stringify.js
687
- var BARE_KEY = /^[a-z0-9-_]+$/i;
688
- function extendedTypeOf(obj) {
689
- let type = typeof obj;
690
- if (type === "object") {
691
- if (Array.isArray(obj))
692
- return "array";
693
- if (obj instanceof Date)
694
- return "date";
695
- }
696
- return type;
697
- }
698
- function isArrayOfTables(obj) {
699
- for (let i = 0; i < obj.length; i++) {
700
- if (extendedTypeOf(obj[i]) !== "object")
701
- return false;
702
- }
703
- return obj.length != 0;
704
- }
705
- function formatString(s) {
706
- return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
707
- }
708
- function stringifyValue(val, type, depth, numberAsFloat) {
709
- if (depth === 0) {
710
- throw new Error("Could not stringify the object: maximum object depth exceeded");
711
- }
712
- if (type === "number") {
713
- if (isNaN(val))
714
- return "nan";
715
- if (val === Infinity)
716
- return "inf";
717
- if (val === -Infinity)
718
- return "-inf";
719
- if (numberAsFloat && Number.isInteger(val))
720
- return val.toFixed(1);
721
- return val.toString();
722
- }
723
- if (type === "bigint" || type === "boolean") {
724
- return val.toString();
725
- }
726
- if (type === "string") {
727
- return formatString(val);
728
- }
729
- if (type === "date") {
730
- if (isNaN(val.getTime())) {
731
- throw new TypeError("cannot serialize invalid date");
732
- }
733
- return val.toISOString();
734
- }
735
- if (type === "object") {
736
- return stringifyInlineTable(val, depth, numberAsFloat);
737
- }
738
- if (type === "array") {
739
- return stringifyArray(val, depth, numberAsFloat);
740
- }
741
- }
742
- function stringifyInlineTable(obj, depth, numberAsFloat) {
743
- let keys = Object.keys(obj);
744
- if (keys.length === 0)
745
- return "{}";
746
- let res = "{ ";
747
- for (let i = 0; i < keys.length; i++) {
748
- let k = keys[i];
749
- if (i)
750
- res += ", ";
751
- res += BARE_KEY.test(k) ? k : formatString(k);
752
- res += " = ";
753
- res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
754
- }
755
- return res + " }";
756
- }
757
- function stringifyArray(array, depth, numberAsFloat) {
758
- if (array.length === 0)
759
- return "[]";
760
- let res = "[ ";
761
- for (let i = 0; i < array.length; i++) {
762
- if (i)
763
- res += ", ";
764
- if (array[i] === null || array[i] === void 0) {
765
- throw new TypeError("arrays cannot contain null or undefined values");
766
- }
767
- res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
768
- }
769
- return res + " ]";
770
- }
771
- function stringifyArrayTable(array, key, depth, numberAsFloat) {
772
- if (depth === 0) {
773
- throw new Error("Could not stringify the object: maximum object depth exceeded");
774
- }
775
- let res = "";
776
- for (let i = 0; i < array.length; i++) {
777
- res += `${res && "\n"}[[${key}]]
778
- `;
779
- res += stringifyTable(0, array[i], key, depth, numberAsFloat);
780
- }
781
- return res;
782
- }
783
- function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
784
- if (depth === 0) {
785
- throw new Error("Could not stringify the object: maximum object depth exceeded");
786
- }
787
- let preamble = "";
788
- let tables = "";
789
- let keys = Object.keys(obj);
790
- for (let i = 0; i < keys.length; i++) {
791
- let k = keys[i];
792
- if (obj[k] !== null && obj[k] !== void 0) {
793
- let type = extendedTypeOf(obj[k]);
794
- if (type === "symbol" || type === "function") {
795
- throw new TypeError(`cannot serialize values of type '${type}'`);
796
- }
797
- let key = BARE_KEY.test(k) ? k : formatString(k);
798
- if (type === "array" && isArrayOfTables(obj[k])) {
799
- tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
800
- } else if (type === "object") {
801
- let tblKey = prefix ? `${prefix}.${key}` : key;
802
- tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
803
- } else {
804
- preamble += key;
805
- preamble += " = ";
806
- preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
807
- preamble += "\n";
808
- }
809
- }
810
- }
811
- if (tableKey && (preamble || !tables))
812
- preamble = preamble ? `[${tableKey}]
813
- ${preamble}` : `[${tableKey}]`;
814
- return preamble && tables ? `${preamble}
815
- ${tables}` : preamble || tables;
816
- }
817
- function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
818
- if (extendedTypeOf(obj) !== "object") {
819
- throw new TypeError("stringify can only be called with an object");
820
- }
821
- let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
822
- if (str[str.length - 1] !== "\n")
823
- return str + "\n";
824
- return str;
825
- }
826
-
827
- // ../../packages/flint/dist/chunk-52SE24LG.js
828
- import { readFile, writeFile, stat as stat2, mkdir } from "fs/promises";
829
- import { join as join2 } from "path";
830
- import { randomUUID } from "crypto";
831
- import { stat } from "fs/promises";
832
- import { join, dirname, basename } from "path";
833
- var FLINT_DIR = ".flint";
834
- function getFlintConfigDir(flintPath) {
835
- return join(flintPath, FLINT_DIR);
836
- }
837
- async function isInsideMesh(dir) {
838
- let current = dir;
839
- while (current !== dirname(current)) {
840
- try {
841
- const tomlPath = join(current, "flint.toml");
842
- await stat(tomlPath);
843
- return current;
844
- } catch {
845
- current = dirname(current);
846
- }
847
- }
848
- return null;
849
- }
850
- function getTypePrefix() {
851
- return "(Flint)";
852
- }
853
- function getFlintName(flintPath) {
854
- const folderName = basename(flintPath);
855
- const match = folderName.match(/^\((Mesh|Flint)\)\s+(.+)$/);
856
- if (match && match[2]) {
857
- return match[2];
858
- }
859
- return folderName;
860
- }
861
- function resolveShardMode(decl) {
862
- return decl.mode;
863
- }
864
- function isLocalShard(decl) {
865
- const mode = resolveShardMode(decl);
866
- return mode === "dev" || mode === "custom";
867
- }
868
- var FLINT_CONFIG_FILENAME = "flint.toml";
869
- var FLINT_JSON_FILENAME = "flint.json";
870
- var FLINT_VERSION = "0.4.0";
871
- function toKebabCase(name) {
872
- return name.replace(/\([^)]*\)\s*/g, "").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/^-+|-+$/g, "");
873
- }
874
- function toSnakeCase(name) {
875
- return name.replace(/\([^)]*\)\s*/g, "").toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "");
876
- }
877
- function nameFormats(name) {
878
- return {
879
- proper: name,
880
- slug: toKebabCase(name),
881
- snake: toSnakeCase(name)
882
- };
883
- }
884
- function getFlintConfigPath(flintPath) {
885
- return join2(flintPath, FLINT_CONFIG_FILENAME);
886
- }
887
- function getFlintJsonPath(flintPath) {
888
- return join2(flintPath, FLINT_JSON_FILENAME);
889
- }
890
- async function exists(path) {
891
- try {
892
- await stat2(path);
893
- return true;
894
- } catch {
895
- return false;
896
- }
897
- }
898
- function createFlintToml(name, shards = []) {
899
- const shardDeclarations = {};
900
- for (const source of shards) {
901
- const repo = source.includes("/") ? source.split("/").pop() : source;
902
- const key = repo.replace(/^shard-/, "");
903
- shardDeclarations[key] = { source };
904
- }
905
- const config = {
906
- flint: {
907
- name
908
- },
909
- shards: shardDeclarations
910
- };
911
- return config;
912
- }
913
- function createFlintJson() {
914
- return {
915
- version: FLINT_VERSION,
916
- id: randomUUID(),
917
- type: "flint",
918
- created: (/* @__PURE__ */ new Date()).toISOString()
919
- };
920
- }
921
- async function readFlintJson(flintPath) {
922
- const jsonPath = getFlintJsonPath(flintPath);
923
- try {
924
- const content = await readFile(jsonPath, "utf-8");
925
- return JSON.parse(content);
926
- } catch (error) {
927
- if (error.code === "ENOENT") {
928
- return null;
929
- }
930
- throw error;
931
- }
932
- }
933
- async function writeFlintJson(flintPath, json) {
934
- const jsonPath = getFlintJsonPath(flintPath);
935
- await writeFile(jsonPath, JSON.stringify(json, null, 2) + "\n");
936
- }
937
- async function hasFlintJson(flintPath) {
938
- return exists(getFlintJsonPath(flintPath));
939
- }
940
- async function recordMigration(flintPath, migrationId) {
941
- let json = await readFlintJson(flintPath);
942
- if (!json) {
943
- json = createFlintJson();
944
- }
945
- if (!json.migrations) {
946
- json.migrations = {};
947
- }
948
- json.migrations[migrationId] = (/* @__PURE__ */ new Date()).toISOString();
949
- await writeFlintJson(flintPath, json);
950
- }
951
- async function hasMigration(flintPath, migrationId) {
952
- const json = await readFlintJson(flintPath);
953
- return !!json?.migrations?.[migrationId];
954
- }
955
- async function getFlintJsonVersion(flintPath) {
956
- const json = await readFlintJson(flintPath);
957
- return json?.version ?? null;
958
- }
959
- async function stampVersion(flintPath) {
960
- let json = await readFlintJson(flintPath);
961
- if (!json) {
962
- json = createFlintJson();
963
- }
964
- json.version = FLINT_VERSION;
965
- if (!json.id) json.id = randomUUID();
966
- if (!json.type) json.type = "flint";
967
- if (!json.created) json.created = (/* @__PURE__ */ new Date()).toISOString();
968
- await writeFlintJson(flintPath, json);
969
- }
970
- async function stampSynced(flintPath) {
971
- const syncPath = join2(getFlintConfigDir(flintPath), "sync.json");
972
- let data = {};
973
- try {
974
- data = JSON.parse(await readFile(syncPath, "utf-8"));
975
- } catch {
976
- }
977
- data.synced = (/* @__PURE__ */ new Date()).toISOString();
978
- await writeFile(syncPath, JSON.stringify(data, null, 2) + "\n", "utf-8");
979
- }
980
- async function readFlintToml(flintPath) {
981
- const configPath = getFlintConfigPath(flintPath);
982
- try {
983
- const content = await readFile(configPath, "utf-8");
984
- return parse(content);
985
- } catch (error) {
986
- if (error.code === "ENOENT") {
987
- return null;
988
- }
989
- throw error;
990
- }
991
- }
992
- function tv(v) {
993
- if (typeof v === "string") return `"${v}"`;
994
- if (typeof v === "boolean") return v ? "true" : "false";
995
- if (typeof v === "number") return String(v);
996
- if (Array.isArray(v)) return `[${v.map(tv).join(", ")}]`;
997
- return String(v);
998
- }
999
- function inlineTable(obj) {
1000
- const parts = Object.entries(obj).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${k} = ${tv(v)}`);
1001
- return `{ ${parts.join(", ")} }`;
1002
- }
1003
- function inlineTableArray(items) {
1004
- return [
1005
- "[",
1006
- ...items.map((item) => ` ${inlineTable(item)},`),
1007
- "]"
1008
- ];
1009
- }
1010
- function stringArray(items) {
1011
- return [
1012
- "[",
1013
- ...items.map((s) => ` "${s}",`),
1014
- "]"
1015
- ];
1016
- }
1017
- function formatFlintToml(config) {
1018
- const lines = [];
1019
- lines.push("[flint]");
1020
- lines.push(`name = ${tv(config.flint.name)}`);
1021
- if (config.flint.type) lines.push(`type = ${tv(config.flint.type)}`);
1022
- if (config.flint.description) lines.push(`description = ${tv(config.flint.description)}`);
1023
- if (config.flint.tags?.length) lines.push(`tags = ${tv(config.flint.tags)}`);
1024
- if (config.flint.org) lines.push(`org = ${tv(config.flint.org)}`);
1025
- lines.push("");
1026
- if (config.shards) {
1027
- const declarations = getShardDeclarationsFromConfig(config);
1028
- if (Object.keys(declarations).length > 0) {
1029
- lines.push("[shards]");
1030
- for (const [shorthand, decl] of Object.entries(declarations)) {
1031
- const mode = resolveShardMode(decl);
1032
- const fields = { source: decl.source };
1033
- if (decl.version) fields.version = decl.version;
1034
- if (mode) fields.mode = mode;
1035
- lines.push(`${shorthand} = ${inlineTable(fields)}`);
1036
- }
1037
- lines.push("");
1038
- }
1039
- }
1040
- if (config.exports?.required?.length) {
1041
- lines.push("[exports]");
1042
- const items = config.exports.required.map((e) => {
1043
- const fields = { name: e.name, file: e.file, mode: e.mode };
1044
- if (e.depth !== void 0 && e.depth !== 1) fields.depth = e.depth;
1045
- return fields;
1046
- });
1047
- lines.push(`required = ${inlineTableArray(items).join("\n")}`);
1048
- lines.push("");
1049
- }
1050
- const hasSourceRepositories = Boolean(config.sources?.repositories?.length);
1051
- const hasMeshExportSources = Boolean(config.sources?.meshexports?.length);
1052
- if (hasSourceRepositories || hasMeshExportSources) {
1053
- lines.push("[sources]");
1054
- if (hasSourceRepositories) {
1055
- const items = config.sources.repositories.map((r) => ({ name: r.name, url: r.url }));
1056
- lines.push(`repositories = ${inlineTableArray(items).join("\n")}`);
1057
- }
1058
- if (hasMeshExportSources) {
1059
- lines.push(`meshexports = ${stringArray(config.sources.meshexports).join("\n")}`);
1060
- }
1061
- lines.push("");
1062
- }
1063
- if (config.workspace?.repositories?.length) {
1064
- lines.push("[workspace]");
1065
- const items = config.workspace.repositories.map((r) => ({ name: r.name, url: r.url }));
1066
- lines.push(`repositories = ${inlineTableArray(items).join("\n")}`);
1067
- lines.push("");
1068
- }
1069
- {
1070
- const plateDecls = getPlateDeclarationsFromConfig(config);
1071
- if (Object.keys(plateDecls).length > 0) {
1072
- lines.push("[plates]");
1073
- for (const [name, decl] of Object.entries(plateDecls)) {
1074
- const fields = {};
1075
- if (decl.title) fields.title = decl.title;
1076
- if (decl.source) fields.source = decl.source;
1077
- if (decl.version) fields.version = decl.version;
1078
- if (decl.path) fields.path = decl.path;
1079
- if (decl.repo) fields.repo = decl.repo;
1080
- lines.push(`${name} = ${inlineTable(fields)}`);
1081
- }
1082
- lines.push("");
1083
- }
1084
- }
1085
- const hasRefCodebases = config.references?.codebases?.length;
1086
- const hasRefFlints = config.references?.flints?.length;
1087
- if (hasRefCodebases || hasRefFlints) {
1088
- lines.push("[references]");
1089
- if (hasRefCodebases) {
1090
- const items = config.references.codebases.map((c) => ({ name: c.name }));
1091
- lines.push(`codebases = ${inlineTableArray(items).join("\n")}`);
1092
- }
1093
- if (hasRefFlints) {
1094
- const items = config.references.flints.map((f) => ({ name: f.name }));
1095
- lines.push(`flints = ${inlineTableArray(items).join("\n")}`);
1096
- }
1097
- lines.push("");
1098
- }
1099
- if (config.lattices?.references?.length) {
1100
- lines.push("[lattices]");
1101
- const items = config.lattices.references.map((l) => ({ name: l.name }));
1102
- lines.push(`references = ${inlineTableArray(items).join("\n")}`);
1103
- lines.push("");
1104
- }
1105
- const knownKeys = /* @__PURE__ */ new Set(["flint", "shards", "exports", "imports", "sources", "workspace", "plates", "connections", "references", "lattices"]);
1106
- const unknownKeys = Object.keys(config).filter((k) => !knownKeys.has(k));
1107
- if (unknownKeys.length > 0) {
1108
- const unknownConfig = {};
1109
- for (const key of unknownKeys) {
1110
- unknownConfig[key] = config[key];
1111
- }
1112
- lines.push(stringify(unknownConfig));
1113
- lines.push("");
1114
- }
1115
- return lines.join("\n");
1116
- }
1117
- async function writeFlintToml(flintPath, config) {
1118
- const configPath = getFlintConfigPath(flintPath);
1119
- const content = formatFlintToml(config);
1120
- await writeFile(configPath, content);
1121
- }
1122
- async function addShardToConfig(flintPath, shardName, source, options = {}) {
1123
- let config = await readFlintToml(flintPath);
1124
- if (!config) {
1125
- throw new Error("flint.toml not found");
1126
- }
1127
- const kebabName = toKebabCase(shardName);
1128
- if (!config.shards) {
1129
- config.shards = {};
1130
- }
1131
- if (config.shards.required && Array.isArray(config.shards.required)) {
1132
- await migrateShardConfig(flintPath);
1133
- config = await readFlintToml(flintPath);
1134
- }
1135
- const declarations = getShardDeclarationsFromConfig(config);
1136
- const existing = declarations[kebabName];
1137
- const effectiveSource = source || kebabName;
1138
- if (!existing || existing.source !== effectiveSource || options.version !== existing?.version) {
1139
- const decl = { source: effectiveSource };
1140
- if (options.version) decl.version = options.version;
1141
- if (options.mode) decl.mode = options.mode;
1142
- config.shards[kebabName] = decl;
1143
- await writeFlintToml(flintPath, config);
1144
- }
1145
- }
1146
- async function removeShardFromConfig(flintPath, shardName) {
1147
- let config = await readFlintToml(flintPath);
1148
- if (!config?.shards) return;
1149
- const kebabName = toKebabCase(shardName);
1150
- if (config.shards.required && Array.isArray(config.shards.required)) {
1151
- config.shards.required = config.shards.required.filter((n) => n !== kebabName);
1152
- }
1153
- if (kebabName in config.shards) {
1154
- delete config.shards[kebabName];
1155
- }
1156
- await writeFlintToml(flintPath, config);
1157
- }
1158
- async function getRequiredShardNames(flintPath) {
1159
- const config = await readFlintToml(flintPath);
1160
- if (!config?.shards) return [];
1161
- const declarations = getShardDeclarationsFromConfig(config);
1162
- return Object.keys(declarations);
1163
- }
1164
- function getShardDeclarationsFromConfig(config) {
1165
- if (!config.shards) return {};
1166
- const declarations = {};
1167
- for (const [key, value] of Object.entries(config.shards)) {
1168
- if (key === "required") continue;
1169
- if (value && typeof value === "object" && !Array.isArray(value) && "source" in value) {
1170
- declarations[key] = value;
1171
- }
1172
- }
1173
- if (config.shards.required && Array.isArray(config.shards.required)) {
1174
- for (const name of config.shards.required) {
1175
- if (!declarations[name]) {
1176
- declarations[name] = { source: name };
1177
- }
1178
- }
1179
- }
1180
- return declarations;
1181
- }
1182
- async function getShardDeclarations(flintPath) {
1183
- const config = await readFlintToml(flintPath);
1184
- if (!config) return {};
1185
- return getShardDeclarationsFromConfig(config);
1186
- }
1187
- async function migrateShardConfig(flintPath) {
1188
- const config = await readFlintToml(flintPath);
1189
- if (!config?.shards?.required || !Array.isArray(config.shards.required)) {
1190
- return false;
1191
- }
1192
- const hasNewFormat = Object.keys(config.shards).some(
1193
- (k) => k !== "required" && typeof config.shards[k] === "object" && !Array.isArray(config.shards[k])
1194
- );
1195
- if (hasNewFormat && config.shards.required.length === 0) {
1196
- return false;
1197
- }
1198
- const declarations = {};
1199
- for (const name of config.shards.required) {
1200
- declarations[name] = { source: name };
1201
- }
1202
- for (const [key, value] of Object.entries(config.shards)) {
1203
- if (key === "required") continue;
1204
- if (value && typeof value === "object" && !Array.isArray(value) && "source" in value) {
1205
- declarations[key] = value;
1206
- }
1207
- }
1208
- config.shards = declarations;
1209
- await writeFlintToml(flintPath, config);
1210
- return true;
1211
- }
1212
- async function hasFlintToml(flintPath) {
1213
- return exists(getFlintConfigPath(flintPath));
1214
- }
1215
- async function isFlint(flintPath) {
1216
- return hasFlintToml(flintPath);
1217
- }
1218
- async function addWorkspaceRepository(flintPath, name, url) {
1219
- let config = await readFlintToml(flintPath);
1220
- if (!config) {
1221
- throw new Error("flint.toml not found");
1222
- }
1223
- if (!config.workspace) {
1224
- config.workspace = {};
1225
- }
1226
- if (!config.workspace.repositories) {
1227
- config.workspace.repositories = [];
1228
- }
1229
- const existing = config.workspace.repositories.find((r) => r.name.toLowerCase() === name.toLowerCase());
1230
- if (existing) {
1231
- throw new Error(`Repository "${name}" already exists`);
1232
- }
1233
- config.workspace.repositories.push({ name, url });
1234
- await writeFlintToml(flintPath, config);
1235
- }
1236
- async function removeWorkspaceRepository(flintPath, name) {
1237
- let config = await readFlintToml(flintPath);
1238
- if (!config?.workspace?.repositories) return false;
1239
- const normalizedName = name.toLowerCase();
1240
- const index = config.workspace.repositories.findIndex((r) => r.name.toLowerCase() === normalizedName);
1241
- if (index === -1) return false;
1242
- config.workspace.repositories.splice(index, 1);
1243
- await writeFlintToml(flintPath, config);
1244
- return true;
1245
- }
1246
- async function getWorkspaceRepositories(flintPath) {
1247
- const config = await readFlintToml(flintPath);
1248
- return config?.workspace?.repositories || [];
1249
- }
1250
- async function getWorkspaceRepository(flintPath, name) {
1251
- const config = await readFlintToml(flintPath);
1252
- const normalizedName = name.toLowerCase();
1253
- return config?.workspace?.repositories?.find((r) => r.name.toLowerCase() === normalizedName) || null;
1254
- }
1255
- async function addPlateDeclaration(flintPath, name, platePath, options = {}) {
1256
- const config = await readFlintToml(flintPath);
1257
- if (!config) {
1258
- throw new Error("flint.toml not found");
1259
- }
1260
- if (!config.plates) {
1261
- config.plates = {};
1262
- }
1263
- const decl = { path: platePath };
1264
- if (options.title) decl.title = options.title;
1265
- config.plates[name] = decl;
1266
- await writeFlintToml(flintPath, config);
1267
- }
1268
- async function setPlateDeclaration(flintPath, name, declaration) {
1269
- const config = await readFlintToml(flintPath);
1270
- if (!config) {
1271
- throw new Error("flint.toml not found");
1272
- }
1273
- if (!config.plates) {
1274
- config.plates = {};
1275
- }
1276
- config.plates[name] = declaration;
1277
- await writeFlintToml(flintPath, config);
1278
- }
1279
- async function removePlateDeclaration(flintPath, name) {
1280
- const config = await readFlintToml(flintPath);
1281
- if (!config?.plates?.[name]) {
1282
- return false;
1283
- }
1284
- delete config.plates[name];
1285
- await writeFlintToml(flintPath, config);
1286
- return true;
1287
- }
1288
- async function getPlateDeclarations(flintPath) {
1289
- const config = await readFlintToml(flintPath);
1290
- return getPlateDeclarationsFromConfig(config);
1291
- }
1292
- function getPlateDeclarationsFromConfig(config) {
1293
- if (!config?.plates) return {};
1294
- const declarations = {};
1295
- for (const [key, value] of Object.entries(config.plates)) {
1296
- if (value && typeof value === "object" && ("path" in value || "source" in value)) {
1297
- declarations[key] = value;
1298
- }
1299
- }
1300
- return declarations;
1301
- }
1302
- async function setPlateRepo(flintPath, name, url) {
1303
- const config = await readFlintToml(flintPath);
1304
- if (!config) {
1305
- throw new Error("flint.toml not found");
1306
- }
1307
- if (!config.plates) {
1308
- config.plates = {};
1309
- }
1310
- const existing = config.plates[name];
1311
- if (!existing) {
1312
- throw new Error(`Plate "${name}" not found in flint.toml`);
1313
- }
1314
- config.plates[name] = { ...existing, repo: url };
1315
- await writeFlintToml(flintPath, config);
1316
- }
1317
- async function getPlateDeclaration(flintPath, name) {
1318
- const declarations = await getPlateDeclarations(flintPath);
1319
- return declarations[name] ?? null;
1320
- }
1321
- async function addSourceRepository(flintPath, name, url) {
1322
- const config = await readFlintToml(flintPath);
1323
- if (!config) {
1324
- throw new Error("flint.toml not found");
1325
- }
1326
- if (!config.sources) {
1327
- config.sources = {};
1328
- }
1329
- if (!config.sources.repositories) {
1330
- config.sources.repositories = [];
1331
- }
1332
- const existing = config.sources.repositories.find((r) => r.name.toLowerCase() === name.toLowerCase());
1333
- if (existing) {
1334
- throw new Error(`Source repository "${name}" already exists`);
1335
- }
1336
- config.sources.repositories.push({ name, url });
1337
- await writeFlintToml(flintPath, config);
1338
- }
1339
- async function removeSourceRepository(flintPath, name) {
1340
- const config = await readFlintToml(flintPath);
1341
- if (!config?.sources?.repositories) return false;
1342
- const normalizedName = name.toLowerCase();
1343
- const index = config.sources.repositories.findIndex((r) => r.name.toLowerCase() === normalizedName);
1344
- if (index === -1) return false;
1345
- config.sources.repositories.splice(index, 1);
1346
- await writeFlintToml(flintPath, config);
1347
- return true;
1348
- }
1349
- async function getSourceRepositories(flintPath) {
1350
- const config = await readFlintToml(flintPath);
1351
- return config?.sources?.repositories || [];
1352
- }
1353
- async function getSourceRepository(flintPath, name) {
1354
- const config = await readFlintToml(flintPath);
1355
- const normalizedName = name.toLowerCase();
1356
- return config?.sources?.repositories?.find((r) => r.name.toLowerCase() === normalizedName) || null;
1357
- }
1358
- function getLatticesStatePath(flintPath) {
1359
- return join2(flintPath, ".flint", "lattices.json");
1360
- }
1361
- async function readLatticesState(flintPath) {
1362
- const statePath = getLatticesStatePath(flintPath);
1363
- try {
1364
- const content = await readFile(statePath, "utf-8");
1365
- return JSON.parse(content);
1366
- } catch {
1367
- return { version: 1, lattices: [] };
1368
- }
1369
- }
1370
- async function writeLatticesState(flintPath, state) {
1371
- const statePath = getLatticesStatePath(flintPath);
1372
- const dir = join2(flintPath, ".flint");
1373
- await mkdir(dir, { recursive: true });
1374
- await writeFile(statePath, JSON.stringify(state, null, 2) + "\n");
1375
- }
1376
- async function addLatticeDeclaration(flintPath, name) {
1377
- let config = await readFlintToml(flintPath);
1378
- if (!config) {
1379
- throw new Error("flint.toml not found");
1380
- }
1381
- if (!config.lattices) {
1382
- config.lattices = { references: [] };
1383
- }
1384
- if (!config.lattices.references) {
1385
- config.lattices.references = [];
1386
- }
1387
- const existing = config.lattices.references.find(
1388
- (entry) => entry.name.toLowerCase() === name.toLowerCase()
1389
- );
1390
- if (existing) {
1391
- throw new Error(`Lattice "${name}" is already declared`);
1392
- }
1393
- config.lattices.references.push({ name });
1394
- await writeFlintToml(flintPath, config);
1395
- }
1396
- async function removeLatticeDeclaration(flintPath, name) {
1397
- let config = await readFlintToml(flintPath);
1398
- if (!config?.lattices?.references) return false;
1399
- const normalizedName = name.toLowerCase();
1400
- const index = config.lattices.references.findIndex(
1401
- (entry) => entry.name.toLowerCase() === normalizedName
1402
- );
1403
- if (index === -1) return false;
1404
- config.lattices.references.splice(index, 1);
1405
- await writeFlintToml(flintPath, config);
1406
- const state = await readLatticesState(flintPath);
1407
- state.lattices = state.lattices.filter(
1408
- (l) => l.name.toLowerCase() !== normalizedName
1409
- );
1410
- await writeLatticesState(flintPath, state);
1411
- return true;
1412
- }
1413
- async function fulfillLattice(flintPath, name, latticePath, lang) {
1414
- const fulfillment = {
1415
- name,
1416
- path: latticePath,
1417
- lang,
1418
- fulfilled: (/* @__PURE__ */ new Date()).toISOString()
1419
- };
1420
- const state = await readLatticesState(flintPath);
1421
- const existingIndex = state.lattices.findIndex(
1422
- (l) => l.name.toLowerCase() === name.toLowerCase()
1423
- );
1424
- if (existingIndex >= 0) {
1425
- state.lattices[existingIndex] = fulfillment;
1426
- } else {
1427
- state.lattices.push(fulfillment);
1428
- }
1429
- await writeLatticesState(flintPath, state);
1430
- return fulfillment;
1431
- }
1432
- async function getLatticeDeclarations(flintPath) {
1433
- const config = await readFlintToml(flintPath);
1434
- return config?.lattices?.references || [];
1435
- }
1436
- async function getLatticeDeclaration(flintPath, name) {
1437
- const config = await readFlintToml(flintPath);
1438
- const normalizedName = name.toLowerCase();
1439
- return config?.lattices?.references?.find(
1440
- (entry) => entry.name.toLowerCase() === normalizedName
1441
- ) || null;
1442
- }
1443
- async function getLatticeFulfillment(flintPath, name) {
1444
- const state = await readLatticesState(flintPath);
1445
- return state.lattices.find(
1446
- (l) => l.name.toLowerCase() === name.toLowerCase()
1447
- ) || null;
1448
- }
1449
- async function addExportToConfig(flintPath, declaration) {
1450
- let config = await readFlintToml(flintPath);
1451
- if (!config) {
1452
- throw new Error("flint.toml not found");
1453
- }
1454
- if (!config.exports) {
1455
- config.exports = { required: [] };
1456
- }
1457
- if (!config.exports.required) {
1458
- config.exports.required = [];
1459
- }
1460
- const existing = config.exports.required.find(
1461
- (e) => e.name.toLowerCase() === declaration.name.toLowerCase()
1462
- );
1463
- if (existing) {
1464
- throw new Error(`Export "${declaration.name}" already declared`);
1465
- }
1466
- config.exports.required.push({
1467
- name: declaration.name,
1468
- file: declaration.file,
1469
- mode: declaration.mode,
1470
- ...declaration.depth !== void 0 ? { depth: declaration.depth } : {}
1471
- });
1472
- await writeFlintToml(flintPath, config);
1473
- }
1474
- async function removeExportFromConfig(flintPath, exportName) {
1475
- let config = await readFlintToml(flintPath);
1476
- if (!config?.exports?.required) return false;
1477
- const index = config.exports.required.findIndex(
1478
- (e) => e.name.toLowerCase() === exportName.toLowerCase()
1479
- );
1480
- if (index === -1) return false;
1481
- config.exports.required.splice(index, 1);
1482
- await writeFlintToml(flintPath, config);
1483
- return true;
1484
- }
1485
- async function getExportDeclarations(flintPath) {
1486
- const config = await readFlintToml(flintPath);
1487
- return config?.exports?.required || [];
1488
- }
1489
- async function getMeshExportSources(flintPath) {
1490
- const config = await readFlintToml(flintPath);
1491
- return config?.sources?.meshexports || [];
1492
- }
1493
- async function addMeshExportToConfig(flintPath, ref) {
1494
- const config = await readFlintToml(flintPath);
1495
- if (!config) {
1496
- throw new Error("flint.toml not found");
1497
- }
1498
- if (!config.sources) {
1499
- config.sources = {};
1500
- }
1501
- if (!config.sources.meshexports) {
1502
- config.sources.meshexports = [];
1503
- }
1504
- if (!config.sources.meshexports.includes(ref)) {
1505
- config.sources.meshexports.push(ref);
1506
- await writeFlintToml(flintPath, config);
1507
- }
1508
- }
1509
- async function removeMeshExportFromConfig(flintPath, ref) {
1510
- const config = await readFlintToml(flintPath);
1511
- if (!config?.sources?.meshexports) return false;
1512
- const meshexports = config.sources.meshexports;
1513
- const index = meshexports.indexOf(ref);
1514
- if (index === -1) {
1515
- const lowerRef = ref.toLowerCase();
1516
- const foundIndex = meshexports.findIndex((r) => r.toLowerCase() === lowerRef);
1517
- if (foundIndex === -1) return false;
1518
- meshexports.splice(foundIndex, 1);
1519
- } else {
1520
- meshexports.splice(index, 1);
1521
- }
1522
- await writeFlintToml(flintPath, config);
1523
- return true;
1524
- }
1525
-
1526
- export {
1527
- parse,
1528
- getFlintConfigDir,
1529
- isInsideMesh,
1530
- getTypePrefix,
1531
- getFlintName,
1532
- resolveShardMode,
1533
- isLocalShard,
1534
- FLINT_CONFIG_FILENAME,
1535
- FLINT_JSON_FILENAME,
1536
- FLINT_VERSION,
1537
- toKebabCase,
1538
- toSnakeCase,
1539
- nameFormats,
1540
- getFlintConfigPath,
1541
- getFlintJsonPath,
1542
- createFlintToml,
1543
- createFlintJson,
1544
- readFlintJson,
1545
- writeFlintJson,
1546
- hasFlintJson,
1547
- recordMigration,
1548
- hasMigration,
1549
- getFlintJsonVersion,
1550
- stampVersion,
1551
- stampSynced,
1552
- readFlintToml,
1553
- writeFlintToml,
1554
- addShardToConfig,
1555
- removeShardFromConfig,
1556
- getRequiredShardNames,
1557
- getShardDeclarationsFromConfig,
1558
- getShardDeclarations,
1559
- migrateShardConfig,
1560
- hasFlintToml,
1561
- isFlint,
1562
- addWorkspaceRepository,
1563
- removeWorkspaceRepository,
1564
- getWorkspaceRepositories,
1565
- getWorkspaceRepository,
1566
- addPlateDeclaration,
1567
- setPlateDeclaration,
1568
- removePlateDeclaration,
1569
- getPlateDeclarations,
1570
- getPlateDeclarationsFromConfig,
1571
- setPlateRepo,
1572
- getPlateDeclaration,
1573
- addSourceRepository,
1574
- removeSourceRepository,
1575
- getSourceRepositories,
1576
- getSourceRepository,
1577
- readLatticesState,
1578
- addLatticeDeclaration,
1579
- removeLatticeDeclaration,
1580
- fulfillLattice,
1581
- getLatticeDeclarations,
1582
- getLatticeDeclaration,
1583
- getLatticeFulfillment,
1584
- addExportToConfig,
1585
- removeExportFromConfig,
1586
- getExportDeclarations,
1587
- getMeshExportSources,
1588
- addMeshExportToConfig,
1589
- removeMeshExportFromConfig
1590
- };
1591
- /*! Bundled license information:
1592
-
1593
- smol-toml/dist/error.js:
1594
- smol-toml/dist/util.js:
1595
- smol-toml/dist/date.js:
1596
- smol-toml/dist/primitive.js:
1597
- smol-toml/dist/extract.js:
1598
- smol-toml/dist/struct.js:
1599
- smol-toml/dist/parse.js:
1600
- smol-toml/dist/stringify.js:
1601
- smol-toml/dist/index.js:
1602
- (*!
1603
- * Copyright (c) Squirrel Chat et al., All rights reserved.
1604
- * SPDX-License-Identifier: BSD-3-Clause
1605
- *
1606
- * Redistribution and use in source and binary forms, with or without
1607
- * modification, are permitted provided that the following conditions are met:
1608
- *
1609
- * 1. Redistributions of source code must retain the above copyright notice, this
1610
- * list of conditions and the following disclaimer.
1611
- * 2. Redistributions in binary form must reproduce the above copyright notice,
1612
- * this list of conditions and the following disclaimer in the
1613
- * documentation and/or other materials provided with the distribution.
1614
- * 3. Neither the name of the copyright holder nor the names of its contributors
1615
- * may be used to endorse or promote products derived from this software without
1616
- * specific prior written permission.
1617
- *
1618
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1619
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1620
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1621
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1622
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1623
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1624
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1625
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1626
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1627
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1628
- *)
1629
- */