@tinacms/schema-tools 1.4.17 → 1.4.19

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/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import picomatch from "picomatch-browser";
2
1
  import * as yup from "yup";
3
2
  import UrlPattern from "url-pattern";
4
3
  import z$1, { z, ZodError } from "zod";
@@ -40,6 +39,1504 @@ function addNamespaceToSchema(maybeNode, namespace = []) {
40
39
  });
41
40
  return { ...newNode, namespace };
42
41
  }
42
+ function getDefaultExportFromCjs(x) {
43
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
44
+ }
45
+ var utils$4 = {};
46
+ const WIN_SLASH = "\\\\/";
47
+ const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
48
+ const DOT_LITERAL = "\\.";
49
+ const PLUS_LITERAL = "\\+";
50
+ const QMARK_LITERAL = "\\?";
51
+ const SLASH_LITERAL = "\\/";
52
+ const ONE_CHAR = "(?=.)";
53
+ const QMARK = "[^/]";
54
+ const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
55
+ const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
56
+ const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
57
+ const NO_DOT = `(?!${DOT_LITERAL})`;
58
+ const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
59
+ const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
60
+ const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
61
+ const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
62
+ const STAR = `${QMARK}*?`;
63
+ const SEP = "/";
64
+ const POSIX_CHARS = {
65
+ DOT_LITERAL,
66
+ PLUS_LITERAL,
67
+ QMARK_LITERAL,
68
+ SLASH_LITERAL,
69
+ ONE_CHAR,
70
+ QMARK,
71
+ END_ANCHOR,
72
+ DOTS_SLASH,
73
+ NO_DOT,
74
+ NO_DOTS,
75
+ NO_DOT_SLASH,
76
+ NO_DOTS_SLASH,
77
+ QMARK_NO_DOT,
78
+ STAR,
79
+ START_ANCHOR,
80
+ SEP
81
+ };
82
+ const WINDOWS_CHARS = {
83
+ ...POSIX_CHARS,
84
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
85
+ QMARK: WIN_NO_SLASH,
86
+ STAR: `${WIN_NO_SLASH}*?`,
87
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
88
+ NO_DOT: `(?!${DOT_LITERAL})`,
89
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
90
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
91
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
92
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
93
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
94
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
95
+ SEP: "\\"
96
+ };
97
+ const POSIX_REGEX_SOURCE$1 = {
98
+ alnum: "a-zA-Z0-9",
99
+ alpha: "a-zA-Z",
100
+ ascii: "\\x00-\\x7F",
101
+ blank: " \\t",
102
+ cntrl: "\\x00-\\x1F\\x7F",
103
+ digit: "0-9",
104
+ graph: "\\x21-\\x7E",
105
+ lower: "a-z",
106
+ print: "\\x20-\\x7E ",
107
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
108
+ space: " \\t\\r\\n\\v\\f",
109
+ upper: "A-Z",
110
+ word: "A-Za-z0-9_",
111
+ xdigit: "A-Fa-f0-9"
112
+ };
113
+ var constants$2 = {
114
+ MAX_LENGTH: 1024 * 64,
115
+ POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
116
+ // regular expressions
117
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
118
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
119
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
120
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
121
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
122
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
123
+ // Replace globs with equivalent patterns to reduce parsing time.
124
+ REPLACEMENTS: {
125
+ "***": "*",
126
+ "**/**": "**",
127
+ "**/**/**": "**"
128
+ },
129
+ // Digits
130
+ CHAR_0: 48,
131
+ /* 0 */
132
+ CHAR_9: 57,
133
+ /* 9 */
134
+ // Alphabet chars.
135
+ CHAR_UPPERCASE_A: 65,
136
+ /* A */
137
+ CHAR_LOWERCASE_A: 97,
138
+ /* a */
139
+ CHAR_UPPERCASE_Z: 90,
140
+ /* Z */
141
+ CHAR_LOWERCASE_Z: 122,
142
+ /* z */
143
+ CHAR_LEFT_PARENTHESES: 40,
144
+ /* ( */
145
+ CHAR_RIGHT_PARENTHESES: 41,
146
+ /* ) */
147
+ CHAR_ASTERISK: 42,
148
+ /* * */
149
+ // Non-alphabetic chars.
150
+ CHAR_AMPERSAND: 38,
151
+ /* & */
152
+ CHAR_AT: 64,
153
+ /* @ */
154
+ CHAR_BACKWARD_SLASH: 92,
155
+ /* \ */
156
+ CHAR_CARRIAGE_RETURN: 13,
157
+ /* \r */
158
+ CHAR_CIRCUMFLEX_ACCENT: 94,
159
+ /* ^ */
160
+ CHAR_COLON: 58,
161
+ /* : */
162
+ CHAR_COMMA: 44,
163
+ /* , */
164
+ CHAR_DOT: 46,
165
+ /* . */
166
+ CHAR_DOUBLE_QUOTE: 34,
167
+ /* " */
168
+ CHAR_EQUAL: 61,
169
+ /* = */
170
+ CHAR_EXCLAMATION_MARK: 33,
171
+ /* ! */
172
+ CHAR_FORM_FEED: 12,
173
+ /* \f */
174
+ CHAR_FORWARD_SLASH: 47,
175
+ /* / */
176
+ CHAR_GRAVE_ACCENT: 96,
177
+ /* ` */
178
+ CHAR_HASH: 35,
179
+ /* # */
180
+ CHAR_HYPHEN_MINUS: 45,
181
+ /* - */
182
+ CHAR_LEFT_ANGLE_BRACKET: 60,
183
+ /* < */
184
+ CHAR_LEFT_CURLY_BRACE: 123,
185
+ /* { */
186
+ CHAR_LEFT_SQUARE_BRACKET: 91,
187
+ /* [ */
188
+ CHAR_LINE_FEED: 10,
189
+ /* \n */
190
+ CHAR_NO_BREAK_SPACE: 160,
191
+ /* \u00A0 */
192
+ CHAR_PERCENT: 37,
193
+ /* % */
194
+ CHAR_PLUS: 43,
195
+ /* + */
196
+ CHAR_QUESTION_MARK: 63,
197
+ /* ? */
198
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
199
+ /* > */
200
+ CHAR_RIGHT_CURLY_BRACE: 125,
201
+ /* } */
202
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
203
+ /* ] */
204
+ CHAR_SEMICOLON: 59,
205
+ /* ; */
206
+ CHAR_SINGLE_QUOTE: 39,
207
+ /* ' */
208
+ CHAR_SPACE: 32,
209
+ /* */
210
+ CHAR_TAB: 9,
211
+ /* \t */
212
+ CHAR_UNDERSCORE: 95,
213
+ /* _ */
214
+ CHAR_VERTICAL_LINE: 124,
215
+ /* | */
216
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
217
+ /* \uFEFF */
218
+ /**
219
+ * Create EXTGLOB_CHARS
220
+ */
221
+ extglobChars(chars) {
222
+ return {
223
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
224
+ "?": { type: "qmark", open: "(?:", close: ")?" },
225
+ "+": { type: "plus", open: "(?:", close: ")+" },
226
+ "*": { type: "star", open: "(?:", close: ")*" },
227
+ "@": { type: "at", open: "(?:", close: ")" }
228
+ };
229
+ },
230
+ /**
231
+ * Create GLOB_CHARS
232
+ */
233
+ globChars(win32) {
234
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
235
+ }
236
+ };
237
+ (function(exports) {
238
+ const {
239
+ REGEX_BACKSLASH,
240
+ REGEX_REMOVE_BACKSLASH,
241
+ REGEX_SPECIAL_CHARS,
242
+ REGEX_SPECIAL_CHARS_GLOBAL
243
+ } = constants$2;
244
+ exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
245
+ exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
246
+ exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
247
+ exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
248
+ exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
249
+ exports.isWindows = () => {
250
+ if (typeof navigator !== "undefined" && navigator.platform) {
251
+ const platform = navigator.platform.toLowerCase();
252
+ return platform === "win32" || platform === "windows";
253
+ }
254
+ if (typeof process !== "undefined" && process.platform) {
255
+ return process.platform === "win32";
256
+ }
257
+ return false;
258
+ };
259
+ exports.removeBackslashes = (str) => {
260
+ return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
261
+ return match === "\\" ? "" : match;
262
+ });
263
+ };
264
+ exports.escapeLast = (input, char, lastIdx) => {
265
+ const idx = input.lastIndexOf(char, lastIdx);
266
+ if (idx === -1)
267
+ return input;
268
+ if (input[idx - 1] === "\\")
269
+ return exports.escapeLast(input, char, idx - 1);
270
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
271
+ };
272
+ exports.removePrefix = (input, state = {}) => {
273
+ let output = input;
274
+ if (output.startsWith("./")) {
275
+ output = output.slice(2);
276
+ state.prefix = "./";
277
+ }
278
+ return output;
279
+ };
280
+ exports.wrapOutput = (input, state = {}, options = {}) => {
281
+ const prepend = options.contains ? "" : "^";
282
+ const append = options.contains ? "" : "$";
283
+ let output = `${prepend}(?:${input})${append}`;
284
+ if (state.negated === true) {
285
+ output = `(?:^(?!${output}).*$)`;
286
+ }
287
+ return output;
288
+ };
289
+ exports.basename = (path, { windows } = {}) => {
290
+ const segs = path.split(windows ? /[\\/]/ : "/");
291
+ const last = segs[segs.length - 1];
292
+ if (last === "") {
293
+ return segs[segs.length - 2];
294
+ }
295
+ return last;
296
+ };
297
+ })(utils$4);
298
+ const utils$3 = utils$4;
299
+ const {
300
+ CHAR_ASTERISK,
301
+ /* * */
302
+ CHAR_AT,
303
+ /* @ */
304
+ CHAR_BACKWARD_SLASH,
305
+ /* \ */
306
+ CHAR_COMMA,
307
+ /* , */
308
+ CHAR_DOT,
309
+ /* . */
310
+ CHAR_EXCLAMATION_MARK,
311
+ /* ! */
312
+ CHAR_FORWARD_SLASH,
313
+ /* / */
314
+ CHAR_LEFT_CURLY_BRACE,
315
+ /* { */
316
+ CHAR_LEFT_PARENTHESES,
317
+ /* ( */
318
+ CHAR_LEFT_SQUARE_BRACKET,
319
+ /* [ */
320
+ CHAR_PLUS,
321
+ /* + */
322
+ CHAR_QUESTION_MARK,
323
+ /* ? */
324
+ CHAR_RIGHT_CURLY_BRACE,
325
+ /* } */
326
+ CHAR_RIGHT_PARENTHESES,
327
+ /* ) */
328
+ CHAR_RIGHT_SQUARE_BRACKET
329
+ /* ] */
330
+ } = constants$2;
331
+ const isPathSeparator = (code) => {
332
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
333
+ };
334
+ const depth = (token) => {
335
+ if (token.isPrefix !== true) {
336
+ token.depth = token.isGlobstar ? Infinity : 1;
337
+ }
338
+ };
339
+ const scan$1 = (input, options) => {
340
+ const opts = options || {};
341
+ const length = input.length - 1;
342
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
343
+ const slashes = [];
344
+ const tokens = [];
345
+ const parts = [];
346
+ let str = input;
347
+ let index = -1;
348
+ let start = 0;
349
+ let lastIndex = 0;
350
+ let isBrace = false;
351
+ let isBracket = false;
352
+ let isGlob = false;
353
+ let isExtglob = false;
354
+ let isGlobstar = false;
355
+ let braceEscaped = false;
356
+ let backslashes = false;
357
+ let negated = false;
358
+ let negatedExtglob = false;
359
+ let finished = false;
360
+ let braces = 0;
361
+ let prev;
362
+ let code;
363
+ let token = { value: "", depth: 0, isGlob: false };
364
+ const eos = () => index >= length;
365
+ const peek = () => str.charCodeAt(index + 1);
366
+ const advance = () => {
367
+ prev = code;
368
+ return str.charCodeAt(++index);
369
+ };
370
+ while (index < length) {
371
+ code = advance();
372
+ let next;
373
+ if (code === CHAR_BACKWARD_SLASH) {
374
+ backslashes = token.backslashes = true;
375
+ code = advance();
376
+ if (code === CHAR_LEFT_CURLY_BRACE) {
377
+ braceEscaped = true;
378
+ }
379
+ continue;
380
+ }
381
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
382
+ braces++;
383
+ while (eos() !== true && (code = advance())) {
384
+ if (code === CHAR_BACKWARD_SLASH) {
385
+ backslashes = token.backslashes = true;
386
+ advance();
387
+ continue;
388
+ }
389
+ if (code === CHAR_LEFT_CURLY_BRACE) {
390
+ braces++;
391
+ continue;
392
+ }
393
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
394
+ isBrace = token.isBrace = true;
395
+ isGlob = token.isGlob = true;
396
+ finished = true;
397
+ if (scanToEnd === true) {
398
+ continue;
399
+ }
400
+ break;
401
+ }
402
+ if (braceEscaped !== true && code === CHAR_COMMA) {
403
+ isBrace = token.isBrace = true;
404
+ isGlob = token.isGlob = true;
405
+ finished = true;
406
+ if (scanToEnd === true) {
407
+ continue;
408
+ }
409
+ break;
410
+ }
411
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
412
+ braces--;
413
+ if (braces === 0) {
414
+ braceEscaped = false;
415
+ isBrace = token.isBrace = true;
416
+ finished = true;
417
+ break;
418
+ }
419
+ }
420
+ }
421
+ if (scanToEnd === true) {
422
+ continue;
423
+ }
424
+ break;
425
+ }
426
+ if (code === CHAR_FORWARD_SLASH) {
427
+ slashes.push(index);
428
+ tokens.push(token);
429
+ token = { value: "", depth: 0, isGlob: false };
430
+ if (finished === true)
431
+ continue;
432
+ if (prev === CHAR_DOT && index === start + 1) {
433
+ start += 2;
434
+ continue;
435
+ }
436
+ lastIndex = index + 1;
437
+ continue;
438
+ }
439
+ if (opts.noext !== true) {
440
+ const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
441
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
442
+ isGlob = token.isGlob = true;
443
+ isExtglob = token.isExtglob = true;
444
+ finished = true;
445
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
446
+ negatedExtglob = true;
447
+ }
448
+ if (scanToEnd === true) {
449
+ while (eos() !== true && (code = advance())) {
450
+ if (code === CHAR_BACKWARD_SLASH) {
451
+ backslashes = token.backslashes = true;
452
+ code = advance();
453
+ continue;
454
+ }
455
+ if (code === CHAR_RIGHT_PARENTHESES) {
456
+ isGlob = token.isGlob = true;
457
+ finished = true;
458
+ break;
459
+ }
460
+ }
461
+ continue;
462
+ }
463
+ break;
464
+ }
465
+ }
466
+ if (code === CHAR_ASTERISK) {
467
+ if (prev === CHAR_ASTERISK)
468
+ isGlobstar = token.isGlobstar = true;
469
+ isGlob = token.isGlob = true;
470
+ finished = true;
471
+ if (scanToEnd === true) {
472
+ continue;
473
+ }
474
+ break;
475
+ }
476
+ if (code === CHAR_QUESTION_MARK) {
477
+ isGlob = token.isGlob = true;
478
+ finished = true;
479
+ if (scanToEnd === true) {
480
+ continue;
481
+ }
482
+ break;
483
+ }
484
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
485
+ while (eos() !== true && (next = advance())) {
486
+ if (next === CHAR_BACKWARD_SLASH) {
487
+ backslashes = token.backslashes = true;
488
+ advance();
489
+ continue;
490
+ }
491
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
492
+ isBracket = token.isBracket = true;
493
+ isGlob = token.isGlob = true;
494
+ finished = true;
495
+ break;
496
+ }
497
+ }
498
+ if (scanToEnd === true) {
499
+ continue;
500
+ }
501
+ break;
502
+ }
503
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
504
+ negated = token.negated = true;
505
+ start++;
506
+ continue;
507
+ }
508
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
509
+ isGlob = token.isGlob = true;
510
+ if (scanToEnd === true) {
511
+ while (eos() !== true && (code = advance())) {
512
+ if (code === CHAR_LEFT_PARENTHESES) {
513
+ backslashes = token.backslashes = true;
514
+ code = advance();
515
+ continue;
516
+ }
517
+ if (code === CHAR_RIGHT_PARENTHESES) {
518
+ finished = true;
519
+ break;
520
+ }
521
+ }
522
+ continue;
523
+ }
524
+ break;
525
+ }
526
+ if (isGlob === true) {
527
+ finished = true;
528
+ if (scanToEnd === true) {
529
+ continue;
530
+ }
531
+ break;
532
+ }
533
+ }
534
+ if (opts.noext === true) {
535
+ isExtglob = false;
536
+ isGlob = false;
537
+ }
538
+ let base = str;
539
+ let prefix = "";
540
+ let glob = "";
541
+ if (start > 0) {
542
+ prefix = str.slice(0, start);
543
+ str = str.slice(start);
544
+ lastIndex -= start;
545
+ }
546
+ if (base && isGlob === true && lastIndex > 0) {
547
+ base = str.slice(0, lastIndex);
548
+ glob = str.slice(lastIndex);
549
+ } else if (isGlob === true) {
550
+ base = "";
551
+ glob = str;
552
+ } else {
553
+ base = str;
554
+ }
555
+ if (base && base !== "" && base !== "/" && base !== str) {
556
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
557
+ base = base.slice(0, -1);
558
+ }
559
+ }
560
+ if (opts.unescape === true) {
561
+ if (glob)
562
+ glob = utils$3.removeBackslashes(glob);
563
+ if (base && backslashes === true) {
564
+ base = utils$3.removeBackslashes(base);
565
+ }
566
+ }
567
+ const state = {
568
+ prefix,
569
+ input,
570
+ start,
571
+ base,
572
+ glob,
573
+ isBrace,
574
+ isBracket,
575
+ isGlob,
576
+ isExtglob,
577
+ isGlobstar,
578
+ negated,
579
+ negatedExtglob
580
+ };
581
+ if (opts.tokens === true) {
582
+ state.maxDepth = 0;
583
+ if (!isPathSeparator(code)) {
584
+ tokens.push(token);
585
+ }
586
+ state.tokens = tokens;
587
+ }
588
+ if (opts.parts === true || opts.tokens === true) {
589
+ let prevIndex;
590
+ for (let idx = 0; idx < slashes.length; idx++) {
591
+ const n = prevIndex ? prevIndex + 1 : start;
592
+ const i = slashes[idx];
593
+ const value = input.slice(n, i);
594
+ if (opts.tokens) {
595
+ if (idx === 0 && start !== 0) {
596
+ tokens[idx].isPrefix = true;
597
+ tokens[idx].value = prefix;
598
+ } else {
599
+ tokens[idx].value = value;
600
+ }
601
+ depth(tokens[idx]);
602
+ state.maxDepth += tokens[idx].depth;
603
+ }
604
+ if (idx !== 0 || value !== "") {
605
+ parts.push(value);
606
+ }
607
+ prevIndex = i;
608
+ }
609
+ if (prevIndex && prevIndex + 1 < input.length) {
610
+ const value = input.slice(prevIndex + 1);
611
+ parts.push(value);
612
+ if (opts.tokens) {
613
+ tokens[tokens.length - 1].value = value;
614
+ depth(tokens[tokens.length - 1]);
615
+ state.maxDepth += tokens[tokens.length - 1].depth;
616
+ }
617
+ }
618
+ state.slashes = slashes;
619
+ state.parts = parts;
620
+ }
621
+ return state;
622
+ };
623
+ var scan_1 = scan$1;
624
+ const constants$1 = constants$2;
625
+ const utils$2 = utils$4;
626
+ const {
627
+ MAX_LENGTH,
628
+ POSIX_REGEX_SOURCE,
629
+ REGEX_NON_SPECIAL_CHARS,
630
+ REGEX_SPECIAL_CHARS_BACKREF,
631
+ REPLACEMENTS
632
+ } = constants$1;
633
+ const expandRange = (args, options) => {
634
+ if (typeof options.expandRange === "function") {
635
+ return options.expandRange(...args, options);
636
+ }
637
+ args.sort();
638
+ const value = `[${args.join("-")}]`;
639
+ try {
640
+ new RegExp(value);
641
+ } catch (ex) {
642
+ return args.map((v) => utils$2.escapeRegex(v)).join("..");
643
+ }
644
+ return value;
645
+ };
646
+ const syntaxError = (type, char) => {
647
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
648
+ };
649
+ const parse$1 = (input, options) => {
650
+ if (typeof input !== "string") {
651
+ throw new TypeError("Expected a string");
652
+ }
653
+ input = REPLACEMENTS[input] || input;
654
+ const opts = { ...options };
655
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
656
+ let len = input.length;
657
+ if (len > max) {
658
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
659
+ }
660
+ const bos = { type: "bos", value: "", output: opts.prepend || "" };
661
+ const tokens = [bos];
662
+ const capture = opts.capture ? "" : "?:";
663
+ const PLATFORM_CHARS = constants$1.globChars(opts.windows);
664
+ const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
665
+ const {
666
+ DOT_LITERAL: DOT_LITERAL2,
667
+ PLUS_LITERAL: PLUS_LITERAL2,
668
+ SLASH_LITERAL: SLASH_LITERAL2,
669
+ ONE_CHAR: ONE_CHAR2,
670
+ DOTS_SLASH: DOTS_SLASH2,
671
+ NO_DOT: NO_DOT2,
672
+ NO_DOT_SLASH: NO_DOT_SLASH2,
673
+ NO_DOTS_SLASH: NO_DOTS_SLASH2,
674
+ QMARK: QMARK2,
675
+ QMARK_NO_DOT: QMARK_NO_DOT2,
676
+ STAR: STAR2,
677
+ START_ANCHOR: START_ANCHOR2
678
+ } = PLATFORM_CHARS;
679
+ const globstar = (opts2) => {
680
+ return `(${capture}(?:(?!${START_ANCHOR2}${opts2.dot ? DOTS_SLASH2 : DOT_LITERAL2}).)*?)`;
681
+ };
682
+ const nodot = opts.dot ? "" : NO_DOT2;
683
+ const qmarkNoDot = opts.dot ? QMARK2 : QMARK_NO_DOT2;
684
+ let star = opts.bash === true ? globstar(opts) : STAR2;
685
+ if (opts.capture) {
686
+ star = `(${star})`;
687
+ }
688
+ if (typeof opts.noext === "boolean") {
689
+ opts.noextglob = opts.noext;
690
+ }
691
+ const state = {
692
+ input,
693
+ index: -1,
694
+ start: 0,
695
+ dot: opts.dot === true,
696
+ consumed: "",
697
+ output: "",
698
+ prefix: "",
699
+ backtrack: false,
700
+ negated: false,
701
+ brackets: 0,
702
+ braces: 0,
703
+ parens: 0,
704
+ quotes: 0,
705
+ globstar: false,
706
+ tokens
707
+ };
708
+ input = utils$2.removePrefix(input, state);
709
+ len = input.length;
710
+ const extglobs = [];
711
+ const braces = [];
712
+ const stack = [];
713
+ let prev = bos;
714
+ let value;
715
+ const eos = () => state.index === len - 1;
716
+ const peek = state.peek = (n = 1) => input[state.index + n];
717
+ const advance = state.advance = () => input[++state.index] || "";
718
+ const remaining = () => input.slice(state.index + 1);
719
+ const consume = (value2 = "", num = 0) => {
720
+ state.consumed += value2;
721
+ state.index += num;
722
+ };
723
+ const append = (token) => {
724
+ state.output += token.output != null ? token.output : token.value;
725
+ consume(token.value);
726
+ };
727
+ const negate = () => {
728
+ let count = 1;
729
+ while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
730
+ advance();
731
+ state.start++;
732
+ count++;
733
+ }
734
+ if (count % 2 === 0) {
735
+ return false;
736
+ }
737
+ state.negated = true;
738
+ state.start++;
739
+ return true;
740
+ };
741
+ const increment = (type) => {
742
+ state[type]++;
743
+ stack.push(type);
744
+ };
745
+ const decrement = (type) => {
746
+ state[type]--;
747
+ stack.pop();
748
+ };
749
+ const push = (tok) => {
750
+ if (prev.type === "globstar") {
751
+ const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
752
+ const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
753
+ if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
754
+ state.output = state.output.slice(0, -prev.output.length);
755
+ prev.type = "star";
756
+ prev.value = "*";
757
+ prev.output = star;
758
+ state.output += prev.output;
759
+ }
760
+ }
761
+ if (extglobs.length && tok.type !== "paren") {
762
+ extglobs[extglobs.length - 1].inner += tok.value;
763
+ }
764
+ if (tok.value || tok.output)
765
+ append(tok);
766
+ if (prev && prev.type === "text" && tok.type === "text") {
767
+ prev.output = (prev.output || prev.value) + tok.value;
768
+ prev.value += tok.value;
769
+ return;
770
+ }
771
+ tok.prev = prev;
772
+ tokens.push(tok);
773
+ prev = tok;
774
+ };
775
+ const extglobOpen = (type, value2) => {
776
+ const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
777
+ token.prev = prev;
778
+ token.parens = state.parens;
779
+ token.output = state.output;
780
+ const output = (opts.capture ? "(" : "") + token.open;
781
+ increment("parens");
782
+ push({ type, value: value2, output: state.output ? "" : ONE_CHAR2 });
783
+ push({ type: "paren", extglob: true, value: advance(), output });
784
+ extglobs.push(token);
785
+ };
786
+ const extglobClose = (token) => {
787
+ let output = token.close + (opts.capture ? ")" : "");
788
+ let rest;
789
+ if (token.type === "negate") {
790
+ let extglobStar = star;
791
+ if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
792
+ extglobStar = globstar(opts);
793
+ }
794
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
795
+ output = token.close = `)$))${extglobStar}`;
796
+ }
797
+ if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
798
+ const expression = parse$1(rest, { ...options, fastpaths: false }).output;
799
+ output = token.close = `)${expression})${extglobStar})`;
800
+ }
801
+ if (token.prev.type === "bos") {
802
+ state.negatedExtglob = true;
803
+ }
804
+ }
805
+ push({ type: "paren", extglob: true, value, output });
806
+ decrement("parens");
807
+ };
808
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
809
+ let backslashes = false;
810
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
811
+ if (first === "\\") {
812
+ backslashes = true;
813
+ return m;
814
+ }
815
+ if (first === "?") {
816
+ if (esc) {
817
+ return esc + first + (rest ? QMARK2.repeat(rest.length) : "");
818
+ }
819
+ if (index === 0) {
820
+ return qmarkNoDot + (rest ? QMARK2.repeat(rest.length) : "");
821
+ }
822
+ return QMARK2.repeat(chars.length);
823
+ }
824
+ if (first === ".") {
825
+ return DOT_LITERAL2.repeat(chars.length);
826
+ }
827
+ if (first === "*") {
828
+ if (esc) {
829
+ return esc + first + (rest ? star : "");
830
+ }
831
+ return star;
832
+ }
833
+ return esc ? m : `\\${m}`;
834
+ });
835
+ if (backslashes === true) {
836
+ if (opts.unescape === true) {
837
+ output = output.replace(/\\/g, "");
838
+ } else {
839
+ output = output.replace(/\\+/g, (m) => {
840
+ return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
841
+ });
842
+ }
843
+ }
844
+ if (output === input && opts.contains === true) {
845
+ state.output = input;
846
+ return state;
847
+ }
848
+ state.output = utils$2.wrapOutput(output, state, options);
849
+ return state;
850
+ }
851
+ while (!eos()) {
852
+ value = advance();
853
+ if (value === "\0") {
854
+ continue;
855
+ }
856
+ if (value === "\\") {
857
+ const next = peek();
858
+ if (next === "/" && opts.bash !== true) {
859
+ continue;
860
+ }
861
+ if (next === "." || next === ";") {
862
+ continue;
863
+ }
864
+ if (!next) {
865
+ value += "\\";
866
+ push({ type: "text", value });
867
+ continue;
868
+ }
869
+ const match = /^\\+/.exec(remaining());
870
+ let slashes = 0;
871
+ if (match && match[0].length > 2) {
872
+ slashes = match[0].length;
873
+ state.index += slashes;
874
+ if (slashes % 2 !== 0) {
875
+ value += "\\";
876
+ }
877
+ }
878
+ if (opts.unescape === true) {
879
+ value = advance();
880
+ } else {
881
+ value += advance();
882
+ }
883
+ if (state.brackets === 0) {
884
+ push({ type: "text", value });
885
+ continue;
886
+ }
887
+ }
888
+ if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
889
+ if (opts.posix !== false && value === ":") {
890
+ const inner = prev.value.slice(1);
891
+ if (inner.includes("[")) {
892
+ prev.posix = true;
893
+ if (inner.includes(":")) {
894
+ const idx = prev.value.lastIndexOf("[");
895
+ const pre = prev.value.slice(0, idx);
896
+ const rest2 = prev.value.slice(idx + 2);
897
+ const posix = POSIX_REGEX_SOURCE[rest2];
898
+ if (posix) {
899
+ prev.value = pre + posix;
900
+ state.backtrack = true;
901
+ advance();
902
+ if (!bos.output && tokens.indexOf(prev) === 1) {
903
+ bos.output = ONE_CHAR2;
904
+ }
905
+ continue;
906
+ }
907
+ }
908
+ }
909
+ }
910
+ if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
911
+ value = `\\${value}`;
912
+ }
913
+ if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
914
+ value = `\\${value}`;
915
+ }
916
+ if (opts.posix === true && value === "!" && prev.value === "[") {
917
+ value = "^";
918
+ }
919
+ prev.value += value;
920
+ append({ value });
921
+ continue;
922
+ }
923
+ if (state.quotes === 1 && value !== '"') {
924
+ value = utils$2.escapeRegex(value);
925
+ prev.value += value;
926
+ append({ value });
927
+ continue;
928
+ }
929
+ if (value === '"') {
930
+ state.quotes = state.quotes === 1 ? 0 : 1;
931
+ if (opts.keepQuotes === true) {
932
+ push({ type: "text", value });
933
+ }
934
+ continue;
935
+ }
936
+ if (value === "(") {
937
+ increment("parens");
938
+ push({ type: "paren", value });
939
+ continue;
940
+ }
941
+ if (value === ")") {
942
+ if (state.parens === 0 && opts.strictBrackets === true) {
943
+ throw new SyntaxError(syntaxError("opening", "("));
944
+ }
945
+ const extglob = extglobs[extglobs.length - 1];
946
+ if (extglob && state.parens === extglob.parens + 1) {
947
+ extglobClose(extglobs.pop());
948
+ continue;
949
+ }
950
+ push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
951
+ decrement("parens");
952
+ continue;
953
+ }
954
+ if (value === "[") {
955
+ if (opts.nobracket === true || !remaining().includes("]")) {
956
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
957
+ throw new SyntaxError(syntaxError("closing", "]"));
958
+ }
959
+ value = `\\${value}`;
960
+ } else {
961
+ increment("brackets");
962
+ }
963
+ push({ type: "bracket", value });
964
+ continue;
965
+ }
966
+ if (value === "]") {
967
+ if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
968
+ push({ type: "text", value, output: `\\${value}` });
969
+ continue;
970
+ }
971
+ if (state.brackets === 0) {
972
+ if (opts.strictBrackets === true) {
973
+ throw new SyntaxError(syntaxError("opening", "["));
974
+ }
975
+ push({ type: "text", value, output: `\\${value}` });
976
+ continue;
977
+ }
978
+ decrement("brackets");
979
+ const prevValue = prev.value.slice(1);
980
+ if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
981
+ value = `/${value}`;
982
+ }
983
+ prev.value += value;
984
+ append({ value });
985
+ if (opts.literalBrackets === false || utils$2.hasRegexChars(prevValue)) {
986
+ continue;
987
+ }
988
+ const escaped = utils$2.escapeRegex(prev.value);
989
+ state.output = state.output.slice(0, -prev.value.length);
990
+ if (opts.literalBrackets === true) {
991
+ state.output += escaped;
992
+ prev.value = escaped;
993
+ continue;
994
+ }
995
+ prev.value = `(${capture}${escaped}|${prev.value})`;
996
+ state.output += prev.value;
997
+ continue;
998
+ }
999
+ if (value === "{" && opts.nobrace !== true) {
1000
+ increment("braces");
1001
+ const open = {
1002
+ type: "brace",
1003
+ value,
1004
+ output: "(",
1005
+ outputIndex: state.output.length,
1006
+ tokensIndex: state.tokens.length
1007
+ };
1008
+ braces.push(open);
1009
+ push(open);
1010
+ continue;
1011
+ }
1012
+ if (value === "}") {
1013
+ const brace = braces[braces.length - 1];
1014
+ if (opts.nobrace === true || !brace) {
1015
+ push({ type: "text", value, output: value });
1016
+ continue;
1017
+ }
1018
+ let output = ")";
1019
+ if (brace.dots === true) {
1020
+ const arr = tokens.slice();
1021
+ const range = [];
1022
+ for (let i = arr.length - 1; i >= 0; i--) {
1023
+ tokens.pop();
1024
+ if (arr[i].type === "brace") {
1025
+ break;
1026
+ }
1027
+ if (arr[i].type !== "dots") {
1028
+ range.unshift(arr[i].value);
1029
+ }
1030
+ }
1031
+ output = expandRange(range, opts);
1032
+ state.backtrack = true;
1033
+ }
1034
+ if (brace.comma !== true && brace.dots !== true) {
1035
+ const out = state.output.slice(0, brace.outputIndex);
1036
+ const toks = state.tokens.slice(brace.tokensIndex);
1037
+ brace.value = brace.output = "\\{";
1038
+ value = output = "\\}";
1039
+ state.output = out;
1040
+ for (const t of toks) {
1041
+ state.output += t.output || t.value;
1042
+ }
1043
+ }
1044
+ push({ type: "brace", value, output });
1045
+ decrement("braces");
1046
+ braces.pop();
1047
+ continue;
1048
+ }
1049
+ if (value === "|") {
1050
+ if (extglobs.length > 0) {
1051
+ extglobs[extglobs.length - 1].conditions++;
1052
+ }
1053
+ push({ type: "text", value });
1054
+ continue;
1055
+ }
1056
+ if (value === ",") {
1057
+ let output = value;
1058
+ const brace = braces[braces.length - 1];
1059
+ if (brace && stack[stack.length - 1] === "braces") {
1060
+ brace.comma = true;
1061
+ output = "|";
1062
+ }
1063
+ push({ type: "comma", value, output });
1064
+ continue;
1065
+ }
1066
+ if (value === "/") {
1067
+ if (prev.type === "dot" && state.index === state.start + 1) {
1068
+ state.start = state.index + 1;
1069
+ state.consumed = "";
1070
+ state.output = "";
1071
+ tokens.pop();
1072
+ prev = bos;
1073
+ continue;
1074
+ }
1075
+ push({ type: "slash", value, output: SLASH_LITERAL2 });
1076
+ continue;
1077
+ }
1078
+ if (value === ".") {
1079
+ if (state.braces > 0 && prev.type === "dot") {
1080
+ if (prev.value === ".")
1081
+ prev.output = DOT_LITERAL2;
1082
+ const brace = braces[braces.length - 1];
1083
+ prev.type = "dots";
1084
+ prev.output += value;
1085
+ prev.value += value;
1086
+ brace.dots = true;
1087
+ continue;
1088
+ }
1089
+ if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1090
+ push({ type: "text", value, output: DOT_LITERAL2 });
1091
+ continue;
1092
+ }
1093
+ push({ type: "dot", value, output: DOT_LITERAL2 });
1094
+ continue;
1095
+ }
1096
+ if (value === "?") {
1097
+ const isGroup = prev && prev.value === "(";
1098
+ if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1099
+ extglobOpen("qmark", value);
1100
+ continue;
1101
+ }
1102
+ if (prev && prev.type === "paren") {
1103
+ const next = peek();
1104
+ let output = value;
1105
+ if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
1106
+ output = `\\${value}`;
1107
+ }
1108
+ push({ type: "text", value, output });
1109
+ continue;
1110
+ }
1111
+ if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
1112
+ push({ type: "qmark", value, output: QMARK_NO_DOT2 });
1113
+ continue;
1114
+ }
1115
+ push({ type: "qmark", value, output: QMARK2 });
1116
+ continue;
1117
+ }
1118
+ if (value === "!") {
1119
+ if (opts.noextglob !== true && peek() === "(") {
1120
+ if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
1121
+ extglobOpen("negate", value);
1122
+ continue;
1123
+ }
1124
+ }
1125
+ if (opts.nonegate !== true && state.index === 0) {
1126
+ negate();
1127
+ continue;
1128
+ }
1129
+ }
1130
+ if (value === "+") {
1131
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1132
+ extglobOpen("plus", value);
1133
+ continue;
1134
+ }
1135
+ if (prev && prev.value === "(" || opts.regex === false) {
1136
+ push({ type: "plus", value, output: PLUS_LITERAL2 });
1137
+ continue;
1138
+ }
1139
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1140
+ push({ type: "plus", value });
1141
+ continue;
1142
+ }
1143
+ push({ type: "plus", value: PLUS_LITERAL2 });
1144
+ continue;
1145
+ }
1146
+ if (value === "@") {
1147
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1148
+ push({ type: "at", extglob: true, value, output: "" });
1149
+ continue;
1150
+ }
1151
+ push({ type: "text", value });
1152
+ continue;
1153
+ }
1154
+ if (value !== "*") {
1155
+ if (value === "$" || value === "^") {
1156
+ value = `\\${value}`;
1157
+ }
1158
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1159
+ if (match) {
1160
+ value += match[0];
1161
+ state.index += match[0].length;
1162
+ }
1163
+ push({ type: "text", value });
1164
+ continue;
1165
+ }
1166
+ if (prev && (prev.type === "globstar" || prev.star === true)) {
1167
+ prev.type = "star";
1168
+ prev.star = true;
1169
+ prev.value += value;
1170
+ prev.output = star;
1171
+ state.backtrack = true;
1172
+ state.globstar = true;
1173
+ consume(value);
1174
+ continue;
1175
+ }
1176
+ let rest = remaining();
1177
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
1178
+ extglobOpen("star", value);
1179
+ continue;
1180
+ }
1181
+ if (prev.type === "star") {
1182
+ if (opts.noglobstar === true) {
1183
+ consume(value);
1184
+ continue;
1185
+ }
1186
+ const prior = prev.prev;
1187
+ const before = prior.prev;
1188
+ const isStart = prior.type === "slash" || prior.type === "bos";
1189
+ const afterStar = before && (before.type === "star" || before.type === "globstar");
1190
+ if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
1191
+ push({ type: "star", value, output: "" });
1192
+ continue;
1193
+ }
1194
+ const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1195
+ const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1196
+ if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1197
+ push({ type: "star", value, output: "" });
1198
+ continue;
1199
+ }
1200
+ while (rest.slice(0, 3) === "/**") {
1201
+ const after = input[state.index + 4];
1202
+ if (after && after !== "/") {
1203
+ break;
1204
+ }
1205
+ rest = rest.slice(3);
1206
+ consume("/**", 3);
1207
+ }
1208
+ if (prior.type === "bos" && eos()) {
1209
+ prev.type = "globstar";
1210
+ prev.value += value;
1211
+ prev.output = globstar(opts);
1212
+ state.output = prev.output;
1213
+ state.globstar = true;
1214
+ consume(value);
1215
+ continue;
1216
+ }
1217
+ if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1218
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1219
+ prior.output = `(?:${prior.output}`;
1220
+ prev.type = "globstar";
1221
+ prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1222
+ prev.value += value;
1223
+ state.globstar = true;
1224
+ state.output += prior.output + prev.output;
1225
+ consume(value);
1226
+ continue;
1227
+ }
1228
+ if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1229
+ const end = rest[1] !== void 0 ? "|$" : "";
1230
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1231
+ prior.output = `(?:${prior.output}`;
1232
+ prev.type = "globstar";
1233
+ prev.output = `${globstar(opts)}${SLASH_LITERAL2}|${SLASH_LITERAL2}${end})`;
1234
+ prev.value += value;
1235
+ state.output += prior.output + prev.output;
1236
+ state.globstar = true;
1237
+ consume(value + advance());
1238
+ push({ type: "slash", value: "/", output: "" });
1239
+ continue;
1240
+ }
1241
+ if (prior.type === "bos" && rest[0] === "/") {
1242
+ prev.type = "globstar";
1243
+ prev.value += value;
1244
+ prev.output = `(?:^|${SLASH_LITERAL2}|${globstar(opts)}${SLASH_LITERAL2})`;
1245
+ state.output = prev.output;
1246
+ state.globstar = true;
1247
+ consume(value + advance());
1248
+ push({ type: "slash", value: "/", output: "" });
1249
+ continue;
1250
+ }
1251
+ state.output = state.output.slice(0, -prev.output.length);
1252
+ prev.type = "globstar";
1253
+ prev.output = globstar(opts);
1254
+ prev.value += value;
1255
+ state.output += prev.output;
1256
+ state.globstar = true;
1257
+ consume(value);
1258
+ continue;
1259
+ }
1260
+ const token = { type: "star", value, output: star };
1261
+ if (opts.bash === true) {
1262
+ token.output = ".*?";
1263
+ if (prev.type === "bos" || prev.type === "slash") {
1264
+ token.output = nodot + token.output;
1265
+ }
1266
+ push(token);
1267
+ continue;
1268
+ }
1269
+ if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
1270
+ token.output = value;
1271
+ push(token);
1272
+ continue;
1273
+ }
1274
+ if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1275
+ if (prev.type === "dot") {
1276
+ state.output += NO_DOT_SLASH2;
1277
+ prev.output += NO_DOT_SLASH2;
1278
+ } else if (opts.dot === true) {
1279
+ state.output += NO_DOTS_SLASH2;
1280
+ prev.output += NO_DOTS_SLASH2;
1281
+ } else {
1282
+ state.output += nodot;
1283
+ prev.output += nodot;
1284
+ }
1285
+ if (peek() !== "*") {
1286
+ state.output += ONE_CHAR2;
1287
+ prev.output += ONE_CHAR2;
1288
+ }
1289
+ }
1290
+ push(token);
1291
+ }
1292
+ while (state.brackets > 0) {
1293
+ if (opts.strictBrackets === true)
1294
+ throw new SyntaxError(syntaxError("closing", "]"));
1295
+ state.output = utils$2.escapeLast(state.output, "[");
1296
+ decrement("brackets");
1297
+ }
1298
+ while (state.parens > 0) {
1299
+ if (opts.strictBrackets === true)
1300
+ throw new SyntaxError(syntaxError("closing", ")"));
1301
+ state.output = utils$2.escapeLast(state.output, "(");
1302
+ decrement("parens");
1303
+ }
1304
+ while (state.braces > 0) {
1305
+ if (opts.strictBrackets === true)
1306
+ throw new SyntaxError(syntaxError("closing", "}"));
1307
+ state.output = utils$2.escapeLast(state.output, "{");
1308
+ decrement("braces");
1309
+ }
1310
+ if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1311
+ push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL2}?` });
1312
+ }
1313
+ if (state.backtrack === true) {
1314
+ state.output = "";
1315
+ for (const token of state.tokens) {
1316
+ state.output += token.output != null ? token.output : token.value;
1317
+ if (token.suffix) {
1318
+ state.output += token.suffix;
1319
+ }
1320
+ }
1321
+ }
1322
+ return state;
1323
+ };
1324
+ parse$1.fastpaths = (input, options) => {
1325
+ const opts = { ...options };
1326
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1327
+ const len = input.length;
1328
+ if (len > max) {
1329
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1330
+ }
1331
+ input = REPLACEMENTS[input] || input;
1332
+ const {
1333
+ DOT_LITERAL: DOT_LITERAL2,
1334
+ SLASH_LITERAL: SLASH_LITERAL2,
1335
+ ONE_CHAR: ONE_CHAR2,
1336
+ DOTS_SLASH: DOTS_SLASH2,
1337
+ NO_DOT: NO_DOT2,
1338
+ NO_DOTS: NO_DOTS2,
1339
+ NO_DOTS_SLASH: NO_DOTS_SLASH2,
1340
+ STAR: STAR2,
1341
+ START_ANCHOR: START_ANCHOR2
1342
+ } = constants$1.globChars(opts.windows);
1343
+ const nodot = opts.dot ? NO_DOTS2 : NO_DOT2;
1344
+ const slashDot = opts.dot ? NO_DOTS_SLASH2 : NO_DOT2;
1345
+ const capture = opts.capture ? "" : "?:";
1346
+ const state = { negated: false, prefix: "" };
1347
+ let star = opts.bash === true ? ".*?" : STAR2;
1348
+ if (opts.capture) {
1349
+ star = `(${star})`;
1350
+ }
1351
+ const globstar = (opts2) => {
1352
+ if (opts2.noglobstar === true)
1353
+ return star;
1354
+ return `(${capture}(?:(?!${START_ANCHOR2}${opts2.dot ? DOTS_SLASH2 : DOT_LITERAL2}).)*?)`;
1355
+ };
1356
+ const create = (str) => {
1357
+ switch (str) {
1358
+ case "*":
1359
+ return `${nodot}${ONE_CHAR2}${star}`;
1360
+ case ".*":
1361
+ return `${DOT_LITERAL2}${ONE_CHAR2}${star}`;
1362
+ case "*.*":
1363
+ return `${nodot}${star}${DOT_LITERAL2}${ONE_CHAR2}${star}`;
1364
+ case "*/*":
1365
+ return `${nodot}${star}${SLASH_LITERAL2}${ONE_CHAR2}${slashDot}${star}`;
1366
+ case "**":
1367
+ return nodot + globstar(opts);
1368
+ case "**/*":
1369
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${slashDot}${ONE_CHAR2}${star}`;
1370
+ case "**/*.*":
1371
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${slashDot}${star}${DOT_LITERAL2}${ONE_CHAR2}${star}`;
1372
+ case "**/.*":
1373
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${DOT_LITERAL2}${ONE_CHAR2}${star}`;
1374
+ default: {
1375
+ const match = /^(.*?)\.(\w+)$/.exec(str);
1376
+ if (!match)
1377
+ return;
1378
+ const source2 = create(match[1]);
1379
+ if (!source2)
1380
+ return;
1381
+ return source2 + DOT_LITERAL2 + match[2];
1382
+ }
1383
+ }
1384
+ };
1385
+ const output = utils$2.removePrefix(input, state);
1386
+ let source = create(output);
1387
+ if (source && opts.strictSlashes !== true) {
1388
+ source += `${SLASH_LITERAL2}?`;
1389
+ }
1390
+ return source;
1391
+ };
1392
+ var parse_1 = parse$1;
1393
+ const scan = scan_1;
1394
+ const parse = parse_1;
1395
+ const utils$1 = utils$4;
1396
+ const constants = constants$2;
1397
+ const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
1398
+ const picomatch$2 = (glob, options, returnState = false) => {
1399
+ if (Array.isArray(glob)) {
1400
+ const fns = glob.map((input) => picomatch$2(input, options, returnState));
1401
+ const arrayMatcher = (str) => {
1402
+ for (const isMatch of fns) {
1403
+ const state2 = isMatch(str);
1404
+ if (state2)
1405
+ return state2;
1406
+ }
1407
+ return false;
1408
+ };
1409
+ return arrayMatcher;
1410
+ }
1411
+ const isState = isObject(glob) && glob.tokens && glob.input;
1412
+ if (glob === "" || typeof glob !== "string" && !isState) {
1413
+ throw new TypeError("Expected pattern to be a non-empty string");
1414
+ }
1415
+ const opts = options || {};
1416
+ const posix = opts.windows;
1417
+ const regex = isState ? picomatch$2.compileRe(glob, options) : picomatch$2.makeRe(glob, options, false, true);
1418
+ const state = regex.state;
1419
+ delete regex.state;
1420
+ let isIgnored = () => false;
1421
+ if (opts.ignore) {
1422
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
1423
+ isIgnored = picomatch$2(opts.ignore, ignoreOpts, returnState);
1424
+ }
1425
+ const matcher = (input, returnObject = false) => {
1426
+ const { isMatch, match, output } = picomatch$2.test(input, regex, options, { glob, posix });
1427
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
1428
+ if (typeof opts.onResult === "function") {
1429
+ opts.onResult(result);
1430
+ }
1431
+ if (isMatch === false) {
1432
+ result.isMatch = false;
1433
+ return returnObject ? result : false;
1434
+ }
1435
+ if (isIgnored(input)) {
1436
+ if (typeof opts.onIgnore === "function") {
1437
+ opts.onIgnore(result);
1438
+ }
1439
+ result.isMatch = false;
1440
+ return returnObject ? result : false;
1441
+ }
1442
+ if (typeof opts.onMatch === "function") {
1443
+ opts.onMatch(result);
1444
+ }
1445
+ return returnObject ? result : true;
1446
+ };
1447
+ if (returnState) {
1448
+ matcher.state = state;
1449
+ }
1450
+ return matcher;
1451
+ };
1452
+ picomatch$2.test = (input, regex, options, { glob, posix } = {}) => {
1453
+ if (typeof input !== "string") {
1454
+ throw new TypeError("Expected input to be a string");
1455
+ }
1456
+ if (input === "") {
1457
+ return { isMatch: false, output: "" };
1458
+ }
1459
+ const opts = options || {};
1460
+ const format = opts.format || (posix ? utils$1.toPosixSlashes : null);
1461
+ let match = input === glob;
1462
+ let output = match && format ? format(input) : input;
1463
+ if (match === false) {
1464
+ output = format ? format(input) : input;
1465
+ match = output === glob;
1466
+ }
1467
+ if (match === false || opts.capture === true) {
1468
+ if (opts.matchBase === true || opts.basename === true) {
1469
+ match = picomatch$2.matchBase(input, regex, options, posix);
1470
+ } else {
1471
+ match = regex.exec(output);
1472
+ }
1473
+ }
1474
+ return { isMatch: Boolean(match), match, output };
1475
+ };
1476
+ picomatch$2.matchBase = (input, glob, options) => {
1477
+ const regex = glob instanceof RegExp ? glob : picomatch$2.makeRe(glob, options);
1478
+ return regex.test(utils$1.basename(input));
1479
+ };
1480
+ picomatch$2.isMatch = (str, patterns, options) => picomatch$2(patterns, options)(str);
1481
+ picomatch$2.parse = (pattern, options) => {
1482
+ if (Array.isArray(pattern))
1483
+ return pattern.map((p) => picomatch$2.parse(p, options));
1484
+ return parse(pattern, { ...options, fastpaths: false });
1485
+ };
1486
+ picomatch$2.scan = (input, options) => scan(input, options);
1487
+ picomatch$2.compileRe = (state, options, returnOutput = false, returnState = false) => {
1488
+ if (returnOutput === true) {
1489
+ return state.output;
1490
+ }
1491
+ const opts = options || {};
1492
+ const prepend = opts.contains ? "" : "^";
1493
+ const append = opts.contains ? "" : "$";
1494
+ let source = `${prepend}(?:${state.output})${append}`;
1495
+ if (state && state.negated === true) {
1496
+ source = `^(?!${source}).*$`;
1497
+ }
1498
+ const regex = picomatch$2.toRegex(source, options);
1499
+ if (returnState === true) {
1500
+ regex.state = state;
1501
+ }
1502
+ return regex;
1503
+ };
1504
+ picomatch$2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
1505
+ if (!input || typeof input !== "string") {
1506
+ throw new TypeError("Expected a non-empty string");
1507
+ }
1508
+ let parsed = { negated: false, fastpaths: true };
1509
+ if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
1510
+ parsed.output = parse.fastpaths(input, options);
1511
+ }
1512
+ if (!parsed.output) {
1513
+ parsed = parse(input, options);
1514
+ }
1515
+ return picomatch$2.compileRe(parsed, options, returnOutput, returnState);
1516
+ };
1517
+ picomatch$2.toRegex = (source, options) => {
1518
+ try {
1519
+ const opts = options || {};
1520
+ return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
1521
+ } catch (err) {
1522
+ if (options && options.debug === true)
1523
+ throw err;
1524
+ return /$^/;
1525
+ }
1526
+ };
1527
+ picomatch$2.constants = constants;
1528
+ var picomatch_1$1 = picomatch$2;
1529
+ const pico = picomatch_1$1;
1530
+ const utils = utils$4;
1531
+ function picomatch(glob, options, returnState = false) {
1532
+ if (options && (options.windows === null || options.windows === void 0)) {
1533
+ options = { ...options, windows: utils.isWindows() };
1534
+ }
1535
+ return pico(glob, options, returnState);
1536
+ }
1537
+ Object.assign(picomatch, pico);
1538
+ var picomatch_1 = picomatch;
1539
+ const picomatch$1 = /* @__PURE__ */ getDefaultExportFromCjs(picomatch_1);
43
1540
  function assertShape(value, yupSchema, errorMessage) {
44
1541
  const shape = yupSchema(yup);
45
1542
  try {
@@ -193,10 +1690,10 @@ class TinaSchema {
193
1690
  const templateInfo = this.getTemplatesForCollectable(collection);
194
1691
  switch (templateInfo.type) {
195
1692
  case "object":
196
- extraFields["fields"] = templateInfo.template.fields;
1693
+ extraFields.fields = templateInfo.template.fields;
197
1694
  break;
198
1695
  case "union":
199
- extraFields["templates"] = templateInfo.templates;
1696
+ extraFields.templates = templateInfo.templates;
200
1697
  break;
201
1698
  }
202
1699
  return {
@@ -222,7 +1719,7 @@ class TinaSchema {
222
1719
  }
223
1720
  if (((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) || ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude)) {
224
1721
  const matches = this.getMatches({ collection });
225
- const match = picomatch.isMatch(normalizedPath, matches);
1722
+ const match = picomatch$1.isMatch(normalizedPath, matches);
226
1723
  if (!match) {
227
1724
  return false;
228
1725
  }
@@ -247,8 +1744,11 @@ class TinaSchema {
247
1744
  }
248
1745
  };
249
1746
  this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
250
- let template;
251
1747
  const collection = this.getCollectionByFullPath(filepath);
1748
+ if (!collection) {
1749
+ return void 0;
1750
+ }
1751
+ let template;
252
1752
  const templates = this.getTemplatesForCollectable(collection);
253
1753
  if (templates.type === "union") {
254
1754
  if (templateName) {
@@ -284,7 +1784,7 @@ class TinaSchema {
284
1784
  switch (templateInfo.type) {
285
1785
  case "object":
286
1786
  return templateInfo.template;
287
- case "union":
1787
+ case "union": {
288
1788
  assertShape(
289
1789
  data,
290
1790
  (yup2) => yup2.object({ _template: yup2.string().required() })
@@ -298,6 +1798,7 @@ class TinaSchema {
298
1798
  );
299
1799
  }
300
1800
  return template;
1801
+ }
301
1802
  }
302
1803
  };
303
1804
  this.transformPayload = (collectionName, payload) => {
@@ -307,11 +1808,11 @@ class TinaSchema {
307
1808
  if (typeof template2 === "string") {
308
1809
  throw new Error("Global templates not supported");
309
1810
  }
310
- return payload["_template"] === template2.name;
1811
+ return (payload == null ? void 0 : payload._template) === template2.name;
311
1812
  });
312
1813
  if (!template) {
313
1814
  console.error(payload);
314
- throw new Error(`Unable to find template for payload`);
1815
+ throw new Error("Unable to find template for payload");
315
1816
  }
316
1817
  if (typeof template === "string") {
317
1818
  throw new Error("Global templates not supported");
@@ -321,19 +1822,19 @@ class TinaSchema {
321
1822
  [template.name]: this.transformCollectablePayload(payload, template)
322
1823
  }
323
1824
  };
324
- } else {
325
- return {
326
- [collectionName]: this.transformCollectablePayload(payload, collection)
327
- };
328
1825
  }
1826
+ return {
1827
+ [collectionName]: this.transformCollectablePayload(payload, collection)
1828
+ };
329
1829
  };
330
1830
  this.transformCollectablePayload = (payload, collection) => {
331
1831
  const accumulator = {};
332
1832
  Object.entries(payload).forEach(([key, value]) => {
1833
+ var _a;
333
1834
  if (typeof collection.fields === "string") {
334
1835
  throw new Error("Global templates not supported");
335
1836
  }
336
- const field = collection.fields.find((field2) => {
1837
+ const field = (_a = collection == null ? void 0 : collection.fields) == null ? void 0 : _a.find((field2) => {
337
1838
  if (typeof field2 === "string") {
338
1839
  throw new Error("Global templates not supported");
339
1840
  }
@@ -364,6 +1865,9 @@ class TinaSchema {
364
1865
  if (typeof template === "string") {
365
1866
  throw new Error("Global templates not supported");
366
1867
  }
1868
+ if (!template) {
1869
+ throw new Error(`Expected to find template named '${_template}'`);
1870
+ }
367
1871
  return {
368
1872
  [_template]: this.transformCollectablePayload(rest, template)
369
1873
  };
@@ -512,7 +2016,8 @@ class TinaSchema {
512
2016
  files
513
2017
  }) {
514
2018
  const matches = this.getMatches({ collection });
515
- const matchedFiles = picomatch(files, matches);
2019
+ const matcher = picomatch$1(matches);
2020
+ const matchedFiles = files.filter((file) => matcher(file));
516
2021
  return matchedFiles;
517
2022
  }
518
2023
  }
@@ -577,7 +2082,7 @@ const resolveField = (field, schema) => {
577
2082
  component: "select",
578
2083
  ...field,
579
2084
  ...extraFields,
580
- options: field.ui && field.ui.component !== "select" ? field.options : [{ label: `Choose an option`, value: "" }, ...field.options]
2085
+ options: field.ui && field.ui.component !== "select" ? field.options : [{ label: "Choose an option", value: "" }, ...field.options]
581
2086
  };
582
2087
  }
583
2088
  if (field.list) {
@@ -597,7 +2102,7 @@ const resolveField = (field, schema) => {
597
2102
  ...field,
598
2103
  ...extraFields
599
2104
  };
600
- case "object":
2105
+ case "object": {
601
2106
  const templateInfo = schema.getTemplatesForCollectable(field);
602
2107
  if (templateInfo.type === "object") {
603
2108
  return {
@@ -635,6 +2140,7 @@ const resolveField = (field, schema) => {
635
2140
  } else {
636
2141
  throw new Error(`Unknown object for resolveField function`);
637
2142
  }
2143
+ }
638
2144
  case "rich-text":
639
2145
  const templates = {};
640
2146
  (_a = field.templates) == null ? void 0 : _a.forEach((template) => {
@@ -904,7 +2410,7 @@ const TinaFieldZod = z.lazy(() => {
904
2410
  };
905
2411
  }
906
2412
  return {
907
- message: issue.message
2413
+ message: issue.message || ""
908
2414
  };
909
2415
  }
910
2416
  }
@@ -1171,9 +2677,8 @@ const validateSchema = ({ schema }) => {
1171
2677
  if (e instanceof ZodError) {
1172
2678
  const errors = parseZodError({ zodError: e });
1173
2679
  throw new TinaSchemaValidationError(errors.join(", \n"));
1174
- } else {
1175
- throw new Error(e);
1176
2680
  }
2681
+ throw new Error(e);
1177
2682
  }
1178
2683
  };
1179
2684
  export {