@tinacms/schema-tools 1.10.1 → 2.1.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.
- package/dist/index.js +2458 -2450
- package/dist/schema/resolveForm.d.ts +1 -1
- package/dist/types/index.d.ts +71 -2
- package/dist/validate/schema.d.ts +24 -24
- package/package.json +4 -11
- package/dist/index.mjs +0 -2754
package/dist/index.mjs
DELETED
|
@@ -1,2754 +0,0 @@
|
|
|
1
|
-
import * as yup from "yup";
|
|
2
|
-
import UrlPattern from "url-pattern";
|
|
3
|
-
import z$1, { z, ZodError } from "zod";
|
|
4
|
-
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
5
|
-
if (typeof maybeNode !== "object" || maybeNode === null) {
|
|
6
|
-
return maybeNode;
|
|
7
|
-
}
|
|
8
|
-
const newNode = { ...maybeNode, namespace: [...namespace] };
|
|
9
|
-
Object.entries(maybeNode).forEach(([key, value]) => {
|
|
10
|
-
if (Array.isArray(value)) {
|
|
11
|
-
newNode[key] = value.map((element) => {
|
|
12
|
-
if (element && typeof element === "object" && "name" in element) {
|
|
13
|
-
const valueName = element.name || element.value;
|
|
14
|
-
return addNamespaceToSchema(element, [...namespace, valueName]);
|
|
15
|
-
}
|
|
16
|
-
return element;
|
|
17
|
-
});
|
|
18
|
-
} else if (value && typeof value === "object" && "name" in value) {
|
|
19
|
-
newNode[key] = addNamespaceToSchema(value, [...namespace, value.name]);
|
|
20
|
-
} else {
|
|
21
|
-
newNode[key] = value;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return newNode;
|
|
25
|
-
}
|
|
26
|
-
function getDefaultExportFromCjs(x) {
|
|
27
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
28
|
-
}
|
|
29
|
-
var utils$4 = {};
|
|
30
|
-
const WIN_SLASH = "\\\\/";
|
|
31
|
-
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
32
|
-
const DOT_LITERAL = "\\.";
|
|
33
|
-
const PLUS_LITERAL = "\\+";
|
|
34
|
-
const QMARK_LITERAL = "\\?";
|
|
35
|
-
const SLASH_LITERAL = "\\/";
|
|
36
|
-
const ONE_CHAR = "(?=.)";
|
|
37
|
-
const QMARK = "[^/]";
|
|
38
|
-
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
39
|
-
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
40
|
-
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
41
|
-
const NO_DOT = `(?!${DOT_LITERAL})`;
|
|
42
|
-
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
43
|
-
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
44
|
-
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
45
|
-
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
46
|
-
const STAR = `${QMARK}*?`;
|
|
47
|
-
const SEP = "/";
|
|
48
|
-
const POSIX_CHARS = {
|
|
49
|
-
DOT_LITERAL,
|
|
50
|
-
PLUS_LITERAL,
|
|
51
|
-
QMARK_LITERAL,
|
|
52
|
-
SLASH_LITERAL,
|
|
53
|
-
ONE_CHAR,
|
|
54
|
-
QMARK,
|
|
55
|
-
END_ANCHOR,
|
|
56
|
-
DOTS_SLASH,
|
|
57
|
-
NO_DOT,
|
|
58
|
-
NO_DOTS,
|
|
59
|
-
NO_DOT_SLASH,
|
|
60
|
-
NO_DOTS_SLASH,
|
|
61
|
-
QMARK_NO_DOT,
|
|
62
|
-
STAR,
|
|
63
|
-
START_ANCHOR,
|
|
64
|
-
SEP
|
|
65
|
-
};
|
|
66
|
-
const WINDOWS_CHARS = {
|
|
67
|
-
...POSIX_CHARS,
|
|
68
|
-
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
69
|
-
QMARK: WIN_NO_SLASH,
|
|
70
|
-
STAR: `${WIN_NO_SLASH}*?`,
|
|
71
|
-
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
72
|
-
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
73
|
-
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
74
|
-
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
75
|
-
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
76
|
-
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
77
|
-
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
78
|
-
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
79
|
-
SEP: "\\"
|
|
80
|
-
};
|
|
81
|
-
const POSIX_REGEX_SOURCE$1 = {
|
|
82
|
-
alnum: "a-zA-Z0-9",
|
|
83
|
-
alpha: "a-zA-Z",
|
|
84
|
-
ascii: "\\x00-\\x7F",
|
|
85
|
-
blank: " \\t",
|
|
86
|
-
cntrl: "\\x00-\\x1F\\x7F",
|
|
87
|
-
digit: "0-9",
|
|
88
|
-
graph: "\\x21-\\x7E",
|
|
89
|
-
lower: "a-z",
|
|
90
|
-
print: "\\x20-\\x7E ",
|
|
91
|
-
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
92
|
-
space: " \\t\\r\\n\\v\\f",
|
|
93
|
-
upper: "A-Z",
|
|
94
|
-
word: "A-Za-z0-9_",
|
|
95
|
-
xdigit: "A-Fa-f0-9"
|
|
96
|
-
};
|
|
97
|
-
var constants$2 = {
|
|
98
|
-
MAX_LENGTH: 1024 * 64,
|
|
99
|
-
POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
|
|
100
|
-
// regular expressions
|
|
101
|
-
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
102
|
-
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
103
|
-
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
104
|
-
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
105
|
-
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
106
|
-
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
107
|
-
// Replace globs with equivalent patterns to reduce parsing time.
|
|
108
|
-
REPLACEMENTS: {
|
|
109
|
-
"***": "*",
|
|
110
|
-
"**/**": "**",
|
|
111
|
-
"**/**/**": "**"
|
|
112
|
-
},
|
|
113
|
-
// Digits
|
|
114
|
-
CHAR_0: 48,
|
|
115
|
-
/* 0 */
|
|
116
|
-
CHAR_9: 57,
|
|
117
|
-
/* 9 */
|
|
118
|
-
// Alphabet chars.
|
|
119
|
-
CHAR_UPPERCASE_A: 65,
|
|
120
|
-
/* A */
|
|
121
|
-
CHAR_LOWERCASE_A: 97,
|
|
122
|
-
/* a */
|
|
123
|
-
CHAR_UPPERCASE_Z: 90,
|
|
124
|
-
/* Z */
|
|
125
|
-
CHAR_LOWERCASE_Z: 122,
|
|
126
|
-
/* z */
|
|
127
|
-
CHAR_LEFT_PARENTHESES: 40,
|
|
128
|
-
/* ( */
|
|
129
|
-
CHAR_RIGHT_PARENTHESES: 41,
|
|
130
|
-
/* ) */
|
|
131
|
-
CHAR_ASTERISK: 42,
|
|
132
|
-
/* * */
|
|
133
|
-
// Non-alphabetic chars.
|
|
134
|
-
CHAR_AMPERSAND: 38,
|
|
135
|
-
/* & */
|
|
136
|
-
CHAR_AT: 64,
|
|
137
|
-
/* @ */
|
|
138
|
-
CHAR_BACKWARD_SLASH: 92,
|
|
139
|
-
/* \ */
|
|
140
|
-
CHAR_CARRIAGE_RETURN: 13,
|
|
141
|
-
/* \r */
|
|
142
|
-
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
143
|
-
/* ^ */
|
|
144
|
-
CHAR_COLON: 58,
|
|
145
|
-
/* : */
|
|
146
|
-
CHAR_COMMA: 44,
|
|
147
|
-
/* , */
|
|
148
|
-
CHAR_DOT: 46,
|
|
149
|
-
/* . */
|
|
150
|
-
CHAR_DOUBLE_QUOTE: 34,
|
|
151
|
-
/* " */
|
|
152
|
-
CHAR_EQUAL: 61,
|
|
153
|
-
/* = */
|
|
154
|
-
CHAR_EXCLAMATION_MARK: 33,
|
|
155
|
-
/* ! */
|
|
156
|
-
CHAR_FORM_FEED: 12,
|
|
157
|
-
/* \f */
|
|
158
|
-
CHAR_FORWARD_SLASH: 47,
|
|
159
|
-
/* / */
|
|
160
|
-
CHAR_GRAVE_ACCENT: 96,
|
|
161
|
-
/* ` */
|
|
162
|
-
CHAR_HASH: 35,
|
|
163
|
-
/* # */
|
|
164
|
-
CHAR_HYPHEN_MINUS: 45,
|
|
165
|
-
/* - */
|
|
166
|
-
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
167
|
-
/* < */
|
|
168
|
-
CHAR_LEFT_CURLY_BRACE: 123,
|
|
169
|
-
/* { */
|
|
170
|
-
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
171
|
-
/* [ */
|
|
172
|
-
CHAR_LINE_FEED: 10,
|
|
173
|
-
/* \n */
|
|
174
|
-
CHAR_NO_BREAK_SPACE: 160,
|
|
175
|
-
/* \u00A0 */
|
|
176
|
-
CHAR_PERCENT: 37,
|
|
177
|
-
/* % */
|
|
178
|
-
CHAR_PLUS: 43,
|
|
179
|
-
/* + */
|
|
180
|
-
CHAR_QUESTION_MARK: 63,
|
|
181
|
-
/* ? */
|
|
182
|
-
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
183
|
-
/* > */
|
|
184
|
-
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
185
|
-
/* } */
|
|
186
|
-
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
187
|
-
/* ] */
|
|
188
|
-
CHAR_SEMICOLON: 59,
|
|
189
|
-
/* ; */
|
|
190
|
-
CHAR_SINGLE_QUOTE: 39,
|
|
191
|
-
/* ' */
|
|
192
|
-
CHAR_SPACE: 32,
|
|
193
|
-
/* */
|
|
194
|
-
CHAR_TAB: 9,
|
|
195
|
-
/* \t */
|
|
196
|
-
CHAR_UNDERSCORE: 95,
|
|
197
|
-
/* _ */
|
|
198
|
-
CHAR_VERTICAL_LINE: 124,
|
|
199
|
-
/* | */
|
|
200
|
-
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
201
|
-
/* \uFEFF */
|
|
202
|
-
/**
|
|
203
|
-
* Create EXTGLOB_CHARS
|
|
204
|
-
*/
|
|
205
|
-
extglobChars(chars) {
|
|
206
|
-
return {
|
|
207
|
-
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
208
|
-
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
209
|
-
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
210
|
-
"*": { type: "star", open: "(?:", close: ")*" },
|
|
211
|
-
"@": { type: "at", open: "(?:", close: ")" }
|
|
212
|
-
};
|
|
213
|
-
},
|
|
214
|
-
/**
|
|
215
|
-
* Create GLOB_CHARS
|
|
216
|
-
*/
|
|
217
|
-
globChars(win32) {
|
|
218
|
-
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
(function(exports) {
|
|
222
|
-
const {
|
|
223
|
-
REGEX_BACKSLASH,
|
|
224
|
-
REGEX_REMOVE_BACKSLASH,
|
|
225
|
-
REGEX_SPECIAL_CHARS,
|
|
226
|
-
REGEX_SPECIAL_CHARS_GLOBAL
|
|
227
|
-
} = constants$2;
|
|
228
|
-
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
229
|
-
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
230
|
-
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
231
|
-
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
232
|
-
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
233
|
-
exports.isWindows = () => {
|
|
234
|
-
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
235
|
-
const platform = navigator.platform.toLowerCase();
|
|
236
|
-
return platform === "win32" || platform === "windows";
|
|
237
|
-
}
|
|
238
|
-
if (typeof process !== "undefined" && process.platform) {
|
|
239
|
-
return process.platform === "win32";
|
|
240
|
-
}
|
|
241
|
-
return false;
|
|
242
|
-
};
|
|
243
|
-
exports.removeBackslashes = (str) => {
|
|
244
|
-
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
245
|
-
return match === "\\" ? "" : match;
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
exports.escapeLast = (input, char, lastIdx) => {
|
|
249
|
-
const idx = input.lastIndexOf(char, lastIdx);
|
|
250
|
-
if (idx === -1)
|
|
251
|
-
return input;
|
|
252
|
-
if (input[idx - 1] === "\\")
|
|
253
|
-
return exports.escapeLast(input, char, idx - 1);
|
|
254
|
-
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
255
|
-
};
|
|
256
|
-
exports.removePrefix = (input, state = {}) => {
|
|
257
|
-
let output = input;
|
|
258
|
-
if (output.startsWith("./")) {
|
|
259
|
-
output = output.slice(2);
|
|
260
|
-
state.prefix = "./";
|
|
261
|
-
}
|
|
262
|
-
return output;
|
|
263
|
-
};
|
|
264
|
-
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
265
|
-
const prepend = options.contains ? "" : "^";
|
|
266
|
-
const append = options.contains ? "" : "$";
|
|
267
|
-
let output = `${prepend}(?:${input})${append}`;
|
|
268
|
-
if (state.negated === true) {
|
|
269
|
-
output = `(?:^(?!${output}).*$)`;
|
|
270
|
-
}
|
|
271
|
-
return output;
|
|
272
|
-
};
|
|
273
|
-
exports.basename = (path, { windows } = {}) => {
|
|
274
|
-
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
275
|
-
const last = segs[segs.length - 1];
|
|
276
|
-
if (last === "") {
|
|
277
|
-
return segs[segs.length - 2];
|
|
278
|
-
}
|
|
279
|
-
return last;
|
|
280
|
-
};
|
|
281
|
-
})(utils$4);
|
|
282
|
-
const utils$3 = utils$4;
|
|
283
|
-
const {
|
|
284
|
-
CHAR_ASTERISK,
|
|
285
|
-
/* * */
|
|
286
|
-
CHAR_AT,
|
|
287
|
-
/* @ */
|
|
288
|
-
CHAR_BACKWARD_SLASH,
|
|
289
|
-
/* \ */
|
|
290
|
-
CHAR_COMMA,
|
|
291
|
-
/* , */
|
|
292
|
-
CHAR_DOT,
|
|
293
|
-
/* . */
|
|
294
|
-
CHAR_EXCLAMATION_MARK,
|
|
295
|
-
/* ! */
|
|
296
|
-
CHAR_FORWARD_SLASH,
|
|
297
|
-
/* / */
|
|
298
|
-
CHAR_LEFT_CURLY_BRACE,
|
|
299
|
-
/* { */
|
|
300
|
-
CHAR_LEFT_PARENTHESES,
|
|
301
|
-
/* ( */
|
|
302
|
-
CHAR_LEFT_SQUARE_BRACKET,
|
|
303
|
-
/* [ */
|
|
304
|
-
CHAR_PLUS,
|
|
305
|
-
/* + */
|
|
306
|
-
CHAR_QUESTION_MARK,
|
|
307
|
-
/* ? */
|
|
308
|
-
CHAR_RIGHT_CURLY_BRACE,
|
|
309
|
-
/* } */
|
|
310
|
-
CHAR_RIGHT_PARENTHESES,
|
|
311
|
-
/* ) */
|
|
312
|
-
CHAR_RIGHT_SQUARE_BRACKET
|
|
313
|
-
/* ] */
|
|
314
|
-
} = constants$2;
|
|
315
|
-
const isPathSeparator = (code) => {
|
|
316
|
-
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
317
|
-
};
|
|
318
|
-
const depth = (token) => {
|
|
319
|
-
if (token.isPrefix !== true) {
|
|
320
|
-
token.depth = token.isGlobstar ? Infinity : 1;
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
const scan$1 = (input, options) => {
|
|
324
|
-
const opts = options || {};
|
|
325
|
-
const length = input.length - 1;
|
|
326
|
-
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
327
|
-
const slashes = [];
|
|
328
|
-
const tokens = [];
|
|
329
|
-
const parts = [];
|
|
330
|
-
let str = input;
|
|
331
|
-
let index = -1;
|
|
332
|
-
let start = 0;
|
|
333
|
-
let lastIndex = 0;
|
|
334
|
-
let isBrace = false;
|
|
335
|
-
let isBracket = false;
|
|
336
|
-
let isGlob = false;
|
|
337
|
-
let isExtglob = false;
|
|
338
|
-
let isGlobstar = false;
|
|
339
|
-
let braceEscaped = false;
|
|
340
|
-
let backslashes = false;
|
|
341
|
-
let negated = false;
|
|
342
|
-
let negatedExtglob = false;
|
|
343
|
-
let finished = false;
|
|
344
|
-
let braces = 0;
|
|
345
|
-
let prev;
|
|
346
|
-
let code;
|
|
347
|
-
let token = { value: "", depth: 0, isGlob: false };
|
|
348
|
-
const eos = () => index >= length;
|
|
349
|
-
const peek = () => str.charCodeAt(index + 1);
|
|
350
|
-
const advance = () => {
|
|
351
|
-
prev = code;
|
|
352
|
-
return str.charCodeAt(++index);
|
|
353
|
-
};
|
|
354
|
-
while (index < length) {
|
|
355
|
-
code = advance();
|
|
356
|
-
let next;
|
|
357
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
358
|
-
backslashes = token.backslashes = true;
|
|
359
|
-
code = advance();
|
|
360
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
361
|
-
braceEscaped = true;
|
|
362
|
-
}
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
366
|
-
braces++;
|
|
367
|
-
while (eos() !== true && (code = advance())) {
|
|
368
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
369
|
-
backslashes = token.backslashes = true;
|
|
370
|
-
advance();
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
374
|
-
braces++;
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
378
|
-
isBrace = token.isBrace = true;
|
|
379
|
-
isGlob = token.isGlob = true;
|
|
380
|
-
finished = true;
|
|
381
|
-
if (scanToEnd === true) {
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
387
|
-
isBrace = token.isBrace = true;
|
|
388
|
-
isGlob = token.isGlob = true;
|
|
389
|
-
finished = true;
|
|
390
|
-
if (scanToEnd === true) {
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
396
|
-
braces--;
|
|
397
|
-
if (braces === 0) {
|
|
398
|
-
braceEscaped = false;
|
|
399
|
-
isBrace = token.isBrace = true;
|
|
400
|
-
finished = true;
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (scanToEnd === true) {
|
|
406
|
-
continue;
|
|
407
|
-
}
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
411
|
-
slashes.push(index);
|
|
412
|
-
tokens.push(token);
|
|
413
|
-
token = { value: "", depth: 0, isGlob: false };
|
|
414
|
-
if (finished === true)
|
|
415
|
-
continue;
|
|
416
|
-
if (prev === CHAR_DOT && index === start + 1) {
|
|
417
|
-
start += 2;
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
lastIndex = index + 1;
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
if (opts.noext !== true) {
|
|
424
|
-
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
425
|
-
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
426
|
-
isGlob = token.isGlob = true;
|
|
427
|
-
isExtglob = token.isExtglob = true;
|
|
428
|
-
finished = true;
|
|
429
|
-
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
430
|
-
negatedExtglob = true;
|
|
431
|
-
}
|
|
432
|
-
if (scanToEnd === true) {
|
|
433
|
-
while (eos() !== true && (code = advance())) {
|
|
434
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
435
|
-
backslashes = token.backslashes = true;
|
|
436
|
-
code = advance();
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
440
|
-
isGlob = token.isGlob = true;
|
|
441
|
-
finished = true;
|
|
442
|
-
break;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (code === CHAR_ASTERISK) {
|
|
451
|
-
if (prev === CHAR_ASTERISK)
|
|
452
|
-
isGlobstar = token.isGlobstar = true;
|
|
453
|
-
isGlob = token.isGlob = true;
|
|
454
|
-
finished = true;
|
|
455
|
-
if (scanToEnd === true) {
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
if (code === CHAR_QUESTION_MARK) {
|
|
461
|
-
isGlob = token.isGlob = true;
|
|
462
|
-
finished = true;
|
|
463
|
-
if (scanToEnd === true) {
|
|
464
|
-
continue;
|
|
465
|
-
}
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
469
|
-
while (eos() !== true && (next = advance())) {
|
|
470
|
-
if (next === CHAR_BACKWARD_SLASH) {
|
|
471
|
-
backslashes = token.backslashes = true;
|
|
472
|
-
advance();
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
476
|
-
isBracket = token.isBracket = true;
|
|
477
|
-
isGlob = token.isGlob = true;
|
|
478
|
-
finished = true;
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (scanToEnd === true) {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
488
|
-
negated = token.negated = true;
|
|
489
|
-
start++;
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
493
|
-
isGlob = token.isGlob = true;
|
|
494
|
-
if (scanToEnd === true) {
|
|
495
|
-
while (eos() !== true && (code = advance())) {
|
|
496
|
-
if (code === CHAR_LEFT_PARENTHESES) {
|
|
497
|
-
backslashes = token.backslashes = true;
|
|
498
|
-
code = advance();
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
502
|
-
finished = true;
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
if (isGlob === true) {
|
|
511
|
-
finished = true;
|
|
512
|
-
if (scanToEnd === true) {
|
|
513
|
-
continue;
|
|
514
|
-
}
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (opts.noext === true) {
|
|
519
|
-
isExtglob = false;
|
|
520
|
-
isGlob = false;
|
|
521
|
-
}
|
|
522
|
-
let base = str;
|
|
523
|
-
let prefix = "";
|
|
524
|
-
let glob = "";
|
|
525
|
-
if (start > 0) {
|
|
526
|
-
prefix = str.slice(0, start);
|
|
527
|
-
str = str.slice(start);
|
|
528
|
-
lastIndex -= start;
|
|
529
|
-
}
|
|
530
|
-
if (base && isGlob === true && lastIndex > 0) {
|
|
531
|
-
base = str.slice(0, lastIndex);
|
|
532
|
-
glob = str.slice(lastIndex);
|
|
533
|
-
} else if (isGlob === true) {
|
|
534
|
-
base = "";
|
|
535
|
-
glob = str;
|
|
536
|
-
} else {
|
|
537
|
-
base = str;
|
|
538
|
-
}
|
|
539
|
-
if (base && base !== "" && base !== "/" && base !== str) {
|
|
540
|
-
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
541
|
-
base = base.slice(0, -1);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (opts.unescape === true) {
|
|
545
|
-
if (glob)
|
|
546
|
-
glob = utils$3.removeBackslashes(glob);
|
|
547
|
-
if (base && backslashes === true) {
|
|
548
|
-
base = utils$3.removeBackslashes(base);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
const state = {
|
|
552
|
-
prefix,
|
|
553
|
-
input,
|
|
554
|
-
start,
|
|
555
|
-
base,
|
|
556
|
-
glob,
|
|
557
|
-
isBrace,
|
|
558
|
-
isBracket,
|
|
559
|
-
isGlob,
|
|
560
|
-
isExtglob,
|
|
561
|
-
isGlobstar,
|
|
562
|
-
negated,
|
|
563
|
-
negatedExtglob
|
|
564
|
-
};
|
|
565
|
-
if (opts.tokens === true) {
|
|
566
|
-
state.maxDepth = 0;
|
|
567
|
-
if (!isPathSeparator(code)) {
|
|
568
|
-
tokens.push(token);
|
|
569
|
-
}
|
|
570
|
-
state.tokens = tokens;
|
|
571
|
-
}
|
|
572
|
-
if (opts.parts === true || opts.tokens === true) {
|
|
573
|
-
let prevIndex;
|
|
574
|
-
for (let idx = 0; idx < slashes.length; idx++) {
|
|
575
|
-
const n = prevIndex ? prevIndex + 1 : start;
|
|
576
|
-
const i = slashes[idx];
|
|
577
|
-
const value = input.slice(n, i);
|
|
578
|
-
if (opts.tokens) {
|
|
579
|
-
if (idx === 0 && start !== 0) {
|
|
580
|
-
tokens[idx].isPrefix = true;
|
|
581
|
-
tokens[idx].value = prefix;
|
|
582
|
-
} else {
|
|
583
|
-
tokens[idx].value = value;
|
|
584
|
-
}
|
|
585
|
-
depth(tokens[idx]);
|
|
586
|
-
state.maxDepth += tokens[idx].depth;
|
|
587
|
-
}
|
|
588
|
-
if (idx !== 0 || value !== "") {
|
|
589
|
-
parts.push(value);
|
|
590
|
-
}
|
|
591
|
-
prevIndex = i;
|
|
592
|
-
}
|
|
593
|
-
if (prevIndex && prevIndex + 1 < input.length) {
|
|
594
|
-
const value = input.slice(prevIndex + 1);
|
|
595
|
-
parts.push(value);
|
|
596
|
-
if (opts.tokens) {
|
|
597
|
-
tokens[tokens.length - 1].value = value;
|
|
598
|
-
depth(tokens[tokens.length - 1]);
|
|
599
|
-
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
state.slashes = slashes;
|
|
603
|
-
state.parts = parts;
|
|
604
|
-
}
|
|
605
|
-
return state;
|
|
606
|
-
};
|
|
607
|
-
var scan_1 = scan$1;
|
|
608
|
-
const constants$1 = constants$2;
|
|
609
|
-
const utils$2 = utils$4;
|
|
610
|
-
const {
|
|
611
|
-
MAX_LENGTH,
|
|
612
|
-
POSIX_REGEX_SOURCE,
|
|
613
|
-
REGEX_NON_SPECIAL_CHARS,
|
|
614
|
-
REGEX_SPECIAL_CHARS_BACKREF,
|
|
615
|
-
REPLACEMENTS
|
|
616
|
-
} = constants$1;
|
|
617
|
-
const expandRange = (args, options) => {
|
|
618
|
-
if (typeof options.expandRange === "function") {
|
|
619
|
-
return options.expandRange(...args, options);
|
|
620
|
-
}
|
|
621
|
-
args.sort();
|
|
622
|
-
const value = `[${args.join("-")}]`;
|
|
623
|
-
try {
|
|
624
|
-
new RegExp(value);
|
|
625
|
-
} catch (ex) {
|
|
626
|
-
return args.map((v) => utils$2.escapeRegex(v)).join("..");
|
|
627
|
-
}
|
|
628
|
-
return value;
|
|
629
|
-
};
|
|
630
|
-
const syntaxError = (type, char) => {
|
|
631
|
-
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
632
|
-
};
|
|
633
|
-
const parse$1 = (input, options) => {
|
|
634
|
-
if (typeof input !== "string") {
|
|
635
|
-
throw new TypeError("Expected a string");
|
|
636
|
-
}
|
|
637
|
-
input = REPLACEMENTS[input] || input;
|
|
638
|
-
const opts = { ...options };
|
|
639
|
-
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
640
|
-
let len = input.length;
|
|
641
|
-
if (len > max) {
|
|
642
|
-
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
643
|
-
}
|
|
644
|
-
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
645
|
-
const tokens = [bos];
|
|
646
|
-
const capture = opts.capture ? "" : "?:";
|
|
647
|
-
const PLATFORM_CHARS = constants$1.globChars(opts.windows);
|
|
648
|
-
const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
|
|
649
|
-
const {
|
|
650
|
-
DOT_LITERAL: DOT_LITERAL2,
|
|
651
|
-
PLUS_LITERAL: PLUS_LITERAL2,
|
|
652
|
-
SLASH_LITERAL: SLASH_LITERAL2,
|
|
653
|
-
ONE_CHAR: ONE_CHAR2,
|
|
654
|
-
DOTS_SLASH: DOTS_SLASH2,
|
|
655
|
-
NO_DOT: NO_DOT2,
|
|
656
|
-
NO_DOT_SLASH: NO_DOT_SLASH2,
|
|
657
|
-
NO_DOTS_SLASH: NO_DOTS_SLASH2,
|
|
658
|
-
QMARK: QMARK2,
|
|
659
|
-
QMARK_NO_DOT: QMARK_NO_DOT2,
|
|
660
|
-
STAR: STAR2,
|
|
661
|
-
START_ANCHOR: START_ANCHOR2
|
|
662
|
-
} = PLATFORM_CHARS;
|
|
663
|
-
const globstar = (opts2) => {
|
|
664
|
-
return `(${capture}(?:(?!${START_ANCHOR2}${opts2.dot ? DOTS_SLASH2 : DOT_LITERAL2}).)*?)`;
|
|
665
|
-
};
|
|
666
|
-
const nodot = opts.dot ? "" : NO_DOT2;
|
|
667
|
-
const qmarkNoDot = opts.dot ? QMARK2 : QMARK_NO_DOT2;
|
|
668
|
-
let star = opts.bash === true ? globstar(opts) : STAR2;
|
|
669
|
-
if (opts.capture) {
|
|
670
|
-
star = `(${star})`;
|
|
671
|
-
}
|
|
672
|
-
if (typeof opts.noext === "boolean") {
|
|
673
|
-
opts.noextglob = opts.noext;
|
|
674
|
-
}
|
|
675
|
-
const state = {
|
|
676
|
-
input,
|
|
677
|
-
index: -1,
|
|
678
|
-
start: 0,
|
|
679
|
-
dot: opts.dot === true,
|
|
680
|
-
consumed: "",
|
|
681
|
-
output: "",
|
|
682
|
-
prefix: "",
|
|
683
|
-
backtrack: false,
|
|
684
|
-
negated: false,
|
|
685
|
-
brackets: 0,
|
|
686
|
-
braces: 0,
|
|
687
|
-
parens: 0,
|
|
688
|
-
quotes: 0,
|
|
689
|
-
globstar: false,
|
|
690
|
-
tokens
|
|
691
|
-
};
|
|
692
|
-
input = utils$2.removePrefix(input, state);
|
|
693
|
-
len = input.length;
|
|
694
|
-
const extglobs = [];
|
|
695
|
-
const braces = [];
|
|
696
|
-
const stack = [];
|
|
697
|
-
let prev = bos;
|
|
698
|
-
let value;
|
|
699
|
-
const eos = () => state.index === len - 1;
|
|
700
|
-
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
701
|
-
const advance = state.advance = () => input[++state.index] || "";
|
|
702
|
-
const remaining = () => input.slice(state.index + 1);
|
|
703
|
-
const consume = (value2 = "", num = 0) => {
|
|
704
|
-
state.consumed += value2;
|
|
705
|
-
state.index += num;
|
|
706
|
-
};
|
|
707
|
-
const append = (token) => {
|
|
708
|
-
state.output += token.output != null ? token.output : token.value;
|
|
709
|
-
consume(token.value);
|
|
710
|
-
};
|
|
711
|
-
const negate = () => {
|
|
712
|
-
let count = 1;
|
|
713
|
-
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
714
|
-
advance();
|
|
715
|
-
state.start++;
|
|
716
|
-
count++;
|
|
717
|
-
}
|
|
718
|
-
if (count % 2 === 0) {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
state.negated = true;
|
|
722
|
-
state.start++;
|
|
723
|
-
return true;
|
|
724
|
-
};
|
|
725
|
-
const increment = (type) => {
|
|
726
|
-
state[type]++;
|
|
727
|
-
stack.push(type);
|
|
728
|
-
};
|
|
729
|
-
const decrement = (type) => {
|
|
730
|
-
state[type]--;
|
|
731
|
-
stack.pop();
|
|
732
|
-
};
|
|
733
|
-
const push = (tok) => {
|
|
734
|
-
if (prev.type === "globstar") {
|
|
735
|
-
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
736
|
-
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
737
|
-
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
738
|
-
state.output = state.output.slice(0, -prev.output.length);
|
|
739
|
-
prev.type = "star";
|
|
740
|
-
prev.value = "*";
|
|
741
|
-
prev.output = star;
|
|
742
|
-
state.output += prev.output;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
if (extglobs.length && tok.type !== "paren") {
|
|
746
|
-
extglobs[extglobs.length - 1].inner += tok.value;
|
|
747
|
-
}
|
|
748
|
-
if (tok.value || tok.output)
|
|
749
|
-
append(tok);
|
|
750
|
-
if (prev && prev.type === "text" && tok.type === "text") {
|
|
751
|
-
prev.output = (prev.output || prev.value) + tok.value;
|
|
752
|
-
prev.value += tok.value;
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
tok.prev = prev;
|
|
756
|
-
tokens.push(tok);
|
|
757
|
-
prev = tok;
|
|
758
|
-
};
|
|
759
|
-
const extglobOpen = (type, value2) => {
|
|
760
|
-
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
761
|
-
token.prev = prev;
|
|
762
|
-
token.parens = state.parens;
|
|
763
|
-
token.output = state.output;
|
|
764
|
-
const output = (opts.capture ? "(" : "") + token.open;
|
|
765
|
-
increment("parens");
|
|
766
|
-
push({ type, value: value2, output: state.output ? "" : ONE_CHAR2 });
|
|
767
|
-
push({ type: "paren", extglob: true, value: advance(), output });
|
|
768
|
-
extglobs.push(token);
|
|
769
|
-
};
|
|
770
|
-
const extglobClose = (token) => {
|
|
771
|
-
let output = token.close + (opts.capture ? ")" : "");
|
|
772
|
-
let rest;
|
|
773
|
-
if (token.type === "negate") {
|
|
774
|
-
let extglobStar = star;
|
|
775
|
-
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
776
|
-
extglobStar = globstar(opts);
|
|
777
|
-
}
|
|
778
|
-
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
779
|
-
output = token.close = `)$))${extglobStar}`;
|
|
780
|
-
}
|
|
781
|
-
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
782
|
-
const expression = parse$1(rest, { ...options, fastpaths: false }).output;
|
|
783
|
-
output = token.close = `)${expression})${extglobStar})`;
|
|
784
|
-
}
|
|
785
|
-
if (token.prev.type === "bos") {
|
|
786
|
-
state.negatedExtglob = true;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
push({ type: "paren", extglob: true, value, output });
|
|
790
|
-
decrement("parens");
|
|
791
|
-
};
|
|
792
|
-
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
793
|
-
let backslashes = false;
|
|
794
|
-
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
795
|
-
if (first === "\\") {
|
|
796
|
-
backslashes = true;
|
|
797
|
-
return m;
|
|
798
|
-
}
|
|
799
|
-
if (first === "?") {
|
|
800
|
-
if (esc) {
|
|
801
|
-
return esc + first + (rest ? QMARK2.repeat(rest.length) : "");
|
|
802
|
-
}
|
|
803
|
-
if (index === 0) {
|
|
804
|
-
return qmarkNoDot + (rest ? QMARK2.repeat(rest.length) : "");
|
|
805
|
-
}
|
|
806
|
-
return QMARK2.repeat(chars.length);
|
|
807
|
-
}
|
|
808
|
-
if (first === ".") {
|
|
809
|
-
return DOT_LITERAL2.repeat(chars.length);
|
|
810
|
-
}
|
|
811
|
-
if (first === "*") {
|
|
812
|
-
if (esc) {
|
|
813
|
-
return esc + first + (rest ? star : "");
|
|
814
|
-
}
|
|
815
|
-
return star;
|
|
816
|
-
}
|
|
817
|
-
return esc ? m : `\\${m}`;
|
|
818
|
-
});
|
|
819
|
-
if (backslashes === true) {
|
|
820
|
-
if (opts.unescape === true) {
|
|
821
|
-
output = output.replace(/\\/g, "");
|
|
822
|
-
} else {
|
|
823
|
-
output = output.replace(/\\+/g, (m) => {
|
|
824
|
-
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
if (output === input && opts.contains === true) {
|
|
829
|
-
state.output = input;
|
|
830
|
-
return state;
|
|
831
|
-
}
|
|
832
|
-
state.output = utils$2.wrapOutput(output, state, options);
|
|
833
|
-
return state;
|
|
834
|
-
}
|
|
835
|
-
while (!eos()) {
|
|
836
|
-
value = advance();
|
|
837
|
-
if (value === "\0") {
|
|
838
|
-
continue;
|
|
839
|
-
}
|
|
840
|
-
if (value === "\\") {
|
|
841
|
-
const next = peek();
|
|
842
|
-
if (next === "/" && opts.bash !== true) {
|
|
843
|
-
continue;
|
|
844
|
-
}
|
|
845
|
-
if (next === "." || next === ";") {
|
|
846
|
-
continue;
|
|
847
|
-
}
|
|
848
|
-
if (!next) {
|
|
849
|
-
value += "\\";
|
|
850
|
-
push({ type: "text", value });
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
const match = /^\\+/.exec(remaining());
|
|
854
|
-
let slashes = 0;
|
|
855
|
-
if (match && match[0].length > 2) {
|
|
856
|
-
slashes = match[0].length;
|
|
857
|
-
state.index += slashes;
|
|
858
|
-
if (slashes % 2 !== 0) {
|
|
859
|
-
value += "\\";
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
if (opts.unescape === true) {
|
|
863
|
-
value = advance();
|
|
864
|
-
} else {
|
|
865
|
-
value += advance();
|
|
866
|
-
}
|
|
867
|
-
if (state.brackets === 0) {
|
|
868
|
-
push({ type: "text", value });
|
|
869
|
-
continue;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
873
|
-
if (opts.posix !== false && value === ":") {
|
|
874
|
-
const inner = prev.value.slice(1);
|
|
875
|
-
if (inner.includes("[")) {
|
|
876
|
-
prev.posix = true;
|
|
877
|
-
if (inner.includes(":")) {
|
|
878
|
-
const idx = prev.value.lastIndexOf("[");
|
|
879
|
-
const pre = prev.value.slice(0, idx);
|
|
880
|
-
const rest2 = prev.value.slice(idx + 2);
|
|
881
|
-
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
882
|
-
if (posix) {
|
|
883
|
-
prev.value = pre + posix;
|
|
884
|
-
state.backtrack = true;
|
|
885
|
-
advance();
|
|
886
|
-
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
887
|
-
bos.output = ONE_CHAR2;
|
|
888
|
-
}
|
|
889
|
-
continue;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
895
|
-
value = `\\${value}`;
|
|
896
|
-
}
|
|
897
|
-
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
898
|
-
value = `\\${value}`;
|
|
899
|
-
}
|
|
900
|
-
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
901
|
-
value = "^";
|
|
902
|
-
}
|
|
903
|
-
prev.value += value;
|
|
904
|
-
append({ value });
|
|
905
|
-
continue;
|
|
906
|
-
}
|
|
907
|
-
if (state.quotes === 1 && value !== '"') {
|
|
908
|
-
value = utils$2.escapeRegex(value);
|
|
909
|
-
prev.value += value;
|
|
910
|
-
append({ value });
|
|
911
|
-
continue;
|
|
912
|
-
}
|
|
913
|
-
if (value === '"') {
|
|
914
|
-
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
915
|
-
if (opts.keepQuotes === true) {
|
|
916
|
-
push({ type: "text", value });
|
|
917
|
-
}
|
|
918
|
-
continue;
|
|
919
|
-
}
|
|
920
|
-
if (value === "(") {
|
|
921
|
-
increment("parens");
|
|
922
|
-
push({ type: "paren", value });
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
if (value === ")") {
|
|
926
|
-
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
927
|
-
throw new SyntaxError(syntaxError("opening", "("));
|
|
928
|
-
}
|
|
929
|
-
const extglob = extglobs[extglobs.length - 1];
|
|
930
|
-
if (extglob && state.parens === extglob.parens + 1) {
|
|
931
|
-
extglobClose(extglobs.pop());
|
|
932
|
-
continue;
|
|
933
|
-
}
|
|
934
|
-
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
935
|
-
decrement("parens");
|
|
936
|
-
continue;
|
|
937
|
-
}
|
|
938
|
-
if (value === "[") {
|
|
939
|
-
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
940
|
-
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
941
|
-
throw new SyntaxError(syntaxError("closing", "]"));
|
|
942
|
-
}
|
|
943
|
-
value = `\\${value}`;
|
|
944
|
-
} else {
|
|
945
|
-
increment("brackets");
|
|
946
|
-
}
|
|
947
|
-
push({ type: "bracket", value });
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
if (value === "]") {
|
|
951
|
-
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
952
|
-
push({ type: "text", value, output: `\\${value}` });
|
|
953
|
-
continue;
|
|
954
|
-
}
|
|
955
|
-
if (state.brackets === 0) {
|
|
956
|
-
if (opts.strictBrackets === true) {
|
|
957
|
-
throw new SyntaxError(syntaxError("opening", "["));
|
|
958
|
-
}
|
|
959
|
-
push({ type: "text", value, output: `\\${value}` });
|
|
960
|
-
continue;
|
|
961
|
-
}
|
|
962
|
-
decrement("brackets");
|
|
963
|
-
const prevValue = prev.value.slice(1);
|
|
964
|
-
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
965
|
-
value = `/${value}`;
|
|
966
|
-
}
|
|
967
|
-
prev.value += value;
|
|
968
|
-
append({ value });
|
|
969
|
-
if (opts.literalBrackets === false || utils$2.hasRegexChars(prevValue)) {
|
|
970
|
-
continue;
|
|
971
|
-
}
|
|
972
|
-
const escaped = utils$2.escapeRegex(prev.value);
|
|
973
|
-
state.output = state.output.slice(0, -prev.value.length);
|
|
974
|
-
if (opts.literalBrackets === true) {
|
|
975
|
-
state.output += escaped;
|
|
976
|
-
prev.value = escaped;
|
|
977
|
-
continue;
|
|
978
|
-
}
|
|
979
|
-
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
980
|
-
state.output += prev.value;
|
|
981
|
-
continue;
|
|
982
|
-
}
|
|
983
|
-
if (value === "{" && opts.nobrace !== true) {
|
|
984
|
-
increment("braces");
|
|
985
|
-
const open = {
|
|
986
|
-
type: "brace",
|
|
987
|
-
value,
|
|
988
|
-
output: "(",
|
|
989
|
-
outputIndex: state.output.length,
|
|
990
|
-
tokensIndex: state.tokens.length
|
|
991
|
-
};
|
|
992
|
-
braces.push(open);
|
|
993
|
-
push(open);
|
|
994
|
-
continue;
|
|
995
|
-
}
|
|
996
|
-
if (value === "}") {
|
|
997
|
-
const brace = braces[braces.length - 1];
|
|
998
|
-
if (opts.nobrace === true || !brace) {
|
|
999
|
-
push({ type: "text", value, output: value });
|
|
1000
|
-
continue;
|
|
1001
|
-
}
|
|
1002
|
-
let output = ")";
|
|
1003
|
-
if (brace.dots === true) {
|
|
1004
|
-
const arr = tokens.slice();
|
|
1005
|
-
const range = [];
|
|
1006
|
-
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1007
|
-
tokens.pop();
|
|
1008
|
-
if (arr[i].type === "brace") {
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
if (arr[i].type !== "dots") {
|
|
1012
|
-
range.unshift(arr[i].value);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
output = expandRange(range, opts);
|
|
1016
|
-
state.backtrack = true;
|
|
1017
|
-
}
|
|
1018
|
-
if (brace.comma !== true && brace.dots !== true) {
|
|
1019
|
-
const out = state.output.slice(0, brace.outputIndex);
|
|
1020
|
-
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1021
|
-
brace.value = brace.output = "\\{";
|
|
1022
|
-
value = output = "\\}";
|
|
1023
|
-
state.output = out;
|
|
1024
|
-
for (const t of toks) {
|
|
1025
|
-
state.output += t.output || t.value;
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
push({ type: "brace", value, output });
|
|
1029
|
-
decrement("braces");
|
|
1030
|
-
braces.pop();
|
|
1031
|
-
continue;
|
|
1032
|
-
}
|
|
1033
|
-
if (value === "|") {
|
|
1034
|
-
if (extglobs.length > 0) {
|
|
1035
|
-
extglobs[extglobs.length - 1].conditions++;
|
|
1036
|
-
}
|
|
1037
|
-
push({ type: "text", value });
|
|
1038
|
-
continue;
|
|
1039
|
-
}
|
|
1040
|
-
if (value === ",") {
|
|
1041
|
-
let output = value;
|
|
1042
|
-
const brace = braces[braces.length - 1];
|
|
1043
|
-
if (brace && stack[stack.length - 1] === "braces") {
|
|
1044
|
-
brace.comma = true;
|
|
1045
|
-
output = "|";
|
|
1046
|
-
}
|
|
1047
|
-
push({ type: "comma", value, output });
|
|
1048
|
-
continue;
|
|
1049
|
-
}
|
|
1050
|
-
if (value === "/") {
|
|
1051
|
-
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1052
|
-
state.start = state.index + 1;
|
|
1053
|
-
state.consumed = "";
|
|
1054
|
-
state.output = "";
|
|
1055
|
-
tokens.pop();
|
|
1056
|
-
prev = bos;
|
|
1057
|
-
continue;
|
|
1058
|
-
}
|
|
1059
|
-
push({ type: "slash", value, output: SLASH_LITERAL2 });
|
|
1060
|
-
continue;
|
|
1061
|
-
}
|
|
1062
|
-
if (value === ".") {
|
|
1063
|
-
if (state.braces > 0 && prev.type === "dot") {
|
|
1064
|
-
if (prev.value === ".")
|
|
1065
|
-
prev.output = DOT_LITERAL2;
|
|
1066
|
-
const brace = braces[braces.length - 1];
|
|
1067
|
-
prev.type = "dots";
|
|
1068
|
-
prev.output += value;
|
|
1069
|
-
prev.value += value;
|
|
1070
|
-
brace.dots = true;
|
|
1071
|
-
continue;
|
|
1072
|
-
}
|
|
1073
|
-
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1074
|
-
push({ type: "text", value, output: DOT_LITERAL2 });
|
|
1075
|
-
continue;
|
|
1076
|
-
}
|
|
1077
|
-
push({ type: "dot", value, output: DOT_LITERAL2 });
|
|
1078
|
-
continue;
|
|
1079
|
-
}
|
|
1080
|
-
if (value === "?") {
|
|
1081
|
-
const isGroup = prev && prev.value === "(";
|
|
1082
|
-
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1083
|
-
extglobOpen("qmark", value);
|
|
1084
|
-
continue;
|
|
1085
|
-
}
|
|
1086
|
-
if (prev && prev.type === "paren") {
|
|
1087
|
-
const next = peek();
|
|
1088
|
-
let output = value;
|
|
1089
|
-
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1090
|
-
output = `\\${value}`;
|
|
1091
|
-
}
|
|
1092
|
-
push({ type: "text", value, output });
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1096
|
-
push({ type: "qmark", value, output: QMARK_NO_DOT2 });
|
|
1097
|
-
continue;
|
|
1098
|
-
}
|
|
1099
|
-
push({ type: "qmark", value, output: QMARK2 });
|
|
1100
|
-
continue;
|
|
1101
|
-
}
|
|
1102
|
-
if (value === "!") {
|
|
1103
|
-
if (opts.noextglob !== true && peek() === "(") {
|
|
1104
|
-
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1105
|
-
extglobOpen("negate", value);
|
|
1106
|
-
continue;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
if (opts.nonegate !== true && state.index === 0) {
|
|
1110
|
-
negate();
|
|
1111
|
-
continue;
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
if (value === "+") {
|
|
1115
|
-
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1116
|
-
extglobOpen("plus", value);
|
|
1117
|
-
continue;
|
|
1118
|
-
}
|
|
1119
|
-
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1120
|
-
push({ type: "plus", value, output: PLUS_LITERAL2 });
|
|
1121
|
-
continue;
|
|
1122
|
-
}
|
|
1123
|
-
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1124
|
-
push({ type: "plus", value });
|
|
1125
|
-
continue;
|
|
1126
|
-
}
|
|
1127
|
-
push({ type: "plus", value: PLUS_LITERAL2 });
|
|
1128
|
-
continue;
|
|
1129
|
-
}
|
|
1130
|
-
if (value === "@") {
|
|
1131
|
-
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1132
|
-
push({ type: "at", extglob: true, value, output: "" });
|
|
1133
|
-
continue;
|
|
1134
|
-
}
|
|
1135
|
-
push({ type: "text", value });
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
if (value !== "*") {
|
|
1139
|
-
if (value === "$" || value === "^") {
|
|
1140
|
-
value = `\\${value}`;
|
|
1141
|
-
}
|
|
1142
|
-
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1143
|
-
if (match) {
|
|
1144
|
-
value += match[0];
|
|
1145
|
-
state.index += match[0].length;
|
|
1146
|
-
}
|
|
1147
|
-
push({ type: "text", value });
|
|
1148
|
-
continue;
|
|
1149
|
-
}
|
|
1150
|
-
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1151
|
-
prev.type = "star";
|
|
1152
|
-
prev.star = true;
|
|
1153
|
-
prev.value += value;
|
|
1154
|
-
prev.output = star;
|
|
1155
|
-
state.backtrack = true;
|
|
1156
|
-
state.globstar = true;
|
|
1157
|
-
consume(value);
|
|
1158
|
-
continue;
|
|
1159
|
-
}
|
|
1160
|
-
let rest = remaining();
|
|
1161
|
-
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1162
|
-
extglobOpen("star", value);
|
|
1163
|
-
continue;
|
|
1164
|
-
}
|
|
1165
|
-
if (prev.type === "star") {
|
|
1166
|
-
if (opts.noglobstar === true) {
|
|
1167
|
-
consume(value);
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
const prior = prev.prev;
|
|
1171
|
-
const before = prior.prev;
|
|
1172
|
-
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1173
|
-
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1174
|
-
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1175
|
-
push({ type: "star", value, output: "" });
|
|
1176
|
-
continue;
|
|
1177
|
-
}
|
|
1178
|
-
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1179
|
-
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1180
|
-
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1181
|
-
push({ type: "star", value, output: "" });
|
|
1182
|
-
continue;
|
|
1183
|
-
}
|
|
1184
|
-
while (rest.slice(0, 3) === "/**") {
|
|
1185
|
-
const after = input[state.index + 4];
|
|
1186
|
-
if (after && after !== "/") {
|
|
1187
|
-
break;
|
|
1188
|
-
}
|
|
1189
|
-
rest = rest.slice(3);
|
|
1190
|
-
consume("/**", 3);
|
|
1191
|
-
}
|
|
1192
|
-
if (prior.type === "bos" && eos()) {
|
|
1193
|
-
prev.type = "globstar";
|
|
1194
|
-
prev.value += value;
|
|
1195
|
-
prev.output = globstar(opts);
|
|
1196
|
-
state.output = prev.output;
|
|
1197
|
-
state.globstar = true;
|
|
1198
|
-
consume(value);
|
|
1199
|
-
continue;
|
|
1200
|
-
}
|
|
1201
|
-
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1202
|
-
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1203
|
-
prior.output = `(?:${prior.output}`;
|
|
1204
|
-
prev.type = "globstar";
|
|
1205
|
-
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1206
|
-
prev.value += value;
|
|
1207
|
-
state.globstar = true;
|
|
1208
|
-
state.output += prior.output + prev.output;
|
|
1209
|
-
consume(value);
|
|
1210
|
-
continue;
|
|
1211
|
-
}
|
|
1212
|
-
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1213
|
-
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1214
|
-
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1215
|
-
prior.output = `(?:${prior.output}`;
|
|
1216
|
-
prev.type = "globstar";
|
|
1217
|
-
prev.output = `${globstar(opts)}${SLASH_LITERAL2}|${SLASH_LITERAL2}${end})`;
|
|
1218
|
-
prev.value += value;
|
|
1219
|
-
state.output += prior.output + prev.output;
|
|
1220
|
-
state.globstar = true;
|
|
1221
|
-
consume(value + advance());
|
|
1222
|
-
push({ type: "slash", value: "/", output: "" });
|
|
1223
|
-
continue;
|
|
1224
|
-
}
|
|
1225
|
-
if (prior.type === "bos" && rest[0] === "/") {
|
|
1226
|
-
prev.type = "globstar";
|
|
1227
|
-
prev.value += value;
|
|
1228
|
-
prev.output = `(?:^|${SLASH_LITERAL2}|${globstar(opts)}${SLASH_LITERAL2})`;
|
|
1229
|
-
state.output = prev.output;
|
|
1230
|
-
state.globstar = true;
|
|
1231
|
-
consume(value + advance());
|
|
1232
|
-
push({ type: "slash", value: "/", output: "" });
|
|
1233
|
-
continue;
|
|
1234
|
-
}
|
|
1235
|
-
state.output = state.output.slice(0, -prev.output.length);
|
|
1236
|
-
prev.type = "globstar";
|
|
1237
|
-
prev.output = globstar(opts);
|
|
1238
|
-
prev.value += value;
|
|
1239
|
-
state.output += prev.output;
|
|
1240
|
-
state.globstar = true;
|
|
1241
|
-
consume(value);
|
|
1242
|
-
continue;
|
|
1243
|
-
}
|
|
1244
|
-
const token = { type: "star", value, output: star };
|
|
1245
|
-
if (opts.bash === true) {
|
|
1246
|
-
token.output = ".*?";
|
|
1247
|
-
if (prev.type === "bos" || prev.type === "slash") {
|
|
1248
|
-
token.output = nodot + token.output;
|
|
1249
|
-
}
|
|
1250
|
-
push(token);
|
|
1251
|
-
continue;
|
|
1252
|
-
}
|
|
1253
|
-
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1254
|
-
token.output = value;
|
|
1255
|
-
push(token);
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
|
-
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1259
|
-
if (prev.type === "dot") {
|
|
1260
|
-
state.output += NO_DOT_SLASH2;
|
|
1261
|
-
prev.output += NO_DOT_SLASH2;
|
|
1262
|
-
} else if (opts.dot === true) {
|
|
1263
|
-
state.output += NO_DOTS_SLASH2;
|
|
1264
|
-
prev.output += NO_DOTS_SLASH2;
|
|
1265
|
-
} else {
|
|
1266
|
-
state.output += nodot;
|
|
1267
|
-
prev.output += nodot;
|
|
1268
|
-
}
|
|
1269
|
-
if (peek() !== "*") {
|
|
1270
|
-
state.output += ONE_CHAR2;
|
|
1271
|
-
prev.output += ONE_CHAR2;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
push(token);
|
|
1275
|
-
}
|
|
1276
|
-
while (state.brackets > 0) {
|
|
1277
|
-
if (opts.strictBrackets === true)
|
|
1278
|
-
throw new SyntaxError(syntaxError("closing", "]"));
|
|
1279
|
-
state.output = utils$2.escapeLast(state.output, "[");
|
|
1280
|
-
decrement("brackets");
|
|
1281
|
-
}
|
|
1282
|
-
while (state.parens > 0) {
|
|
1283
|
-
if (opts.strictBrackets === true)
|
|
1284
|
-
throw new SyntaxError(syntaxError("closing", ")"));
|
|
1285
|
-
state.output = utils$2.escapeLast(state.output, "(");
|
|
1286
|
-
decrement("parens");
|
|
1287
|
-
}
|
|
1288
|
-
while (state.braces > 0) {
|
|
1289
|
-
if (opts.strictBrackets === true)
|
|
1290
|
-
throw new SyntaxError(syntaxError("closing", "}"));
|
|
1291
|
-
state.output = utils$2.escapeLast(state.output, "{");
|
|
1292
|
-
decrement("braces");
|
|
1293
|
-
}
|
|
1294
|
-
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1295
|
-
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL2}?` });
|
|
1296
|
-
}
|
|
1297
|
-
if (state.backtrack === true) {
|
|
1298
|
-
state.output = "";
|
|
1299
|
-
for (const token of state.tokens) {
|
|
1300
|
-
state.output += token.output != null ? token.output : token.value;
|
|
1301
|
-
if (token.suffix) {
|
|
1302
|
-
state.output += token.suffix;
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
return state;
|
|
1307
|
-
};
|
|
1308
|
-
parse$1.fastpaths = (input, options) => {
|
|
1309
|
-
const opts = { ...options };
|
|
1310
|
-
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1311
|
-
const len = input.length;
|
|
1312
|
-
if (len > max) {
|
|
1313
|
-
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1314
|
-
}
|
|
1315
|
-
input = REPLACEMENTS[input] || input;
|
|
1316
|
-
const {
|
|
1317
|
-
DOT_LITERAL: DOT_LITERAL2,
|
|
1318
|
-
SLASH_LITERAL: SLASH_LITERAL2,
|
|
1319
|
-
ONE_CHAR: ONE_CHAR2,
|
|
1320
|
-
DOTS_SLASH: DOTS_SLASH2,
|
|
1321
|
-
NO_DOT: NO_DOT2,
|
|
1322
|
-
NO_DOTS: NO_DOTS2,
|
|
1323
|
-
NO_DOTS_SLASH: NO_DOTS_SLASH2,
|
|
1324
|
-
STAR: STAR2,
|
|
1325
|
-
START_ANCHOR: START_ANCHOR2
|
|
1326
|
-
} = constants$1.globChars(opts.windows);
|
|
1327
|
-
const nodot = opts.dot ? NO_DOTS2 : NO_DOT2;
|
|
1328
|
-
const slashDot = opts.dot ? NO_DOTS_SLASH2 : NO_DOT2;
|
|
1329
|
-
const capture = opts.capture ? "" : "?:";
|
|
1330
|
-
const state = { negated: false, prefix: "" };
|
|
1331
|
-
let star = opts.bash === true ? ".*?" : STAR2;
|
|
1332
|
-
if (opts.capture) {
|
|
1333
|
-
star = `(${star})`;
|
|
1334
|
-
}
|
|
1335
|
-
const globstar = (opts2) => {
|
|
1336
|
-
if (opts2.noglobstar === true)
|
|
1337
|
-
return star;
|
|
1338
|
-
return `(${capture}(?:(?!${START_ANCHOR2}${opts2.dot ? DOTS_SLASH2 : DOT_LITERAL2}).)*?)`;
|
|
1339
|
-
};
|
|
1340
|
-
const create = (str) => {
|
|
1341
|
-
switch (str) {
|
|
1342
|
-
case "*":
|
|
1343
|
-
return `${nodot}${ONE_CHAR2}${star}`;
|
|
1344
|
-
case ".*":
|
|
1345
|
-
return `${DOT_LITERAL2}${ONE_CHAR2}${star}`;
|
|
1346
|
-
case "*.*":
|
|
1347
|
-
return `${nodot}${star}${DOT_LITERAL2}${ONE_CHAR2}${star}`;
|
|
1348
|
-
case "*/*":
|
|
1349
|
-
return `${nodot}${star}${SLASH_LITERAL2}${ONE_CHAR2}${slashDot}${star}`;
|
|
1350
|
-
case "**":
|
|
1351
|
-
return nodot + globstar(opts);
|
|
1352
|
-
case "**/*":
|
|
1353
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${slashDot}${ONE_CHAR2}${star}`;
|
|
1354
|
-
case "**/*.*":
|
|
1355
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${slashDot}${star}${DOT_LITERAL2}${ONE_CHAR2}${star}`;
|
|
1356
|
-
case "**/.*":
|
|
1357
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL2})?${DOT_LITERAL2}${ONE_CHAR2}${star}`;
|
|
1358
|
-
default: {
|
|
1359
|
-
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1360
|
-
if (!match)
|
|
1361
|
-
return;
|
|
1362
|
-
const source2 = create(match[1]);
|
|
1363
|
-
if (!source2)
|
|
1364
|
-
return;
|
|
1365
|
-
return source2 + DOT_LITERAL2 + match[2];
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
|
-
const output = utils$2.removePrefix(input, state);
|
|
1370
|
-
let source = create(output);
|
|
1371
|
-
if (source && opts.strictSlashes !== true) {
|
|
1372
|
-
source += `${SLASH_LITERAL2}?`;
|
|
1373
|
-
}
|
|
1374
|
-
return source;
|
|
1375
|
-
};
|
|
1376
|
-
var parse_1 = parse$1;
|
|
1377
|
-
const scan = scan_1;
|
|
1378
|
-
const parse = parse_1;
|
|
1379
|
-
const utils$1 = utils$4;
|
|
1380
|
-
const constants = constants$2;
|
|
1381
|
-
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1382
|
-
const picomatch$2 = (glob, options, returnState = false) => {
|
|
1383
|
-
if (Array.isArray(glob)) {
|
|
1384
|
-
const fns = glob.map((input) => picomatch$2(input, options, returnState));
|
|
1385
|
-
const arrayMatcher = (str) => {
|
|
1386
|
-
for (const isMatch of fns) {
|
|
1387
|
-
const state2 = isMatch(str);
|
|
1388
|
-
if (state2)
|
|
1389
|
-
return state2;
|
|
1390
|
-
}
|
|
1391
|
-
return false;
|
|
1392
|
-
};
|
|
1393
|
-
return arrayMatcher;
|
|
1394
|
-
}
|
|
1395
|
-
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1396
|
-
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1397
|
-
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1398
|
-
}
|
|
1399
|
-
const opts = options || {};
|
|
1400
|
-
const posix = opts.windows;
|
|
1401
|
-
const regex = isState ? picomatch$2.compileRe(glob, options) : picomatch$2.makeRe(glob, options, false, true);
|
|
1402
|
-
const state = regex.state;
|
|
1403
|
-
delete regex.state;
|
|
1404
|
-
let isIgnored = () => false;
|
|
1405
|
-
if (opts.ignore) {
|
|
1406
|
-
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1407
|
-
isIgnored = picomatch$2(opts.ignore, ignoreOpts, returnState);
|
|
1408
|
-
}
|
|
1409
|
-
const matcher = (input, returnObject = false) => {
|
|
1410
|
-
const { isMatch, match, output } = picomatch$2.test(input, regex, options, { glob, posix });
|
|
1411
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
1412
|
-
if (typeof opts.onResult === "function") {
|
|
1413
|
-
opts.onResult(result);
|
|
1414
|
-
}
|
|
1415
|
-
if (isMatch === false) {
|
|
1416
|
-
result.isMatch = false;
|
|
1417
|
-
return returnObject ? result : false;
|
|
1418
|
-
}
|
|
1419
|
-
if (isIgnored(input)) {
|
|
1420
|
-
if (typeof opts.onIgnore === "function") {
|
|
1421
|
-
opts.onIgnore(result);
|
|
1422
|
-
}
|
|
1423
|
-
result.isMatch = false;
|
|
1424
|
-
return returnObject ? result : false;
|
|
1425
|
-
}
|
|
1426
|
-
if (typeof opts.onMatch === "function") {
|
|
1427
|
-
opts.onMatch(result);
|
|
1428
|
-
}
|
|
1429
|
-
return returnObject ? result : true;
|
|
1430
|
-
};
|
|
1431
|
-
if (returnState) {
|
|
1432
|
-
matcher.state = state;
|
|
1433
|
-
}
|
|
1434
|
-
return matcher;
|
|
1435
|
-
};
|
|
1436
|
-
picomatch$2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1437
|
-
if (typeof input !== "string") {
|
|
1438
|
-
throw new TypeError("Expected input to be a string");
|
|
1439
|
-
}
|
|
1440
|
-
if (input === "") {
|
|
1441
|
-
return { isMatch: false, output: "" };
|
|
1442
|
-
}
|
|
1443
|
-
const opts = options || {};
|
|
1444
|
-
const format = opts.format || (posix ? utils$1.toPosixSlashes : null);
|
|
1445
|
-
let match = input === glob;
|
|
1446
|
-
let output = match && format ? format(input) : input;
|
|
1447
|
-
if (match === false) {
|
|
1448
|
-
output = format ? format(input) : input;
|
|
1449
|
-
match = output === glob;
|
|
1450
|
-
}
|
|
1451
|
-
if (match === false || opts.capture === true) {
|
|
1452
|
-
if (opts.matchBase === true || opts.basename === true) {
|
|
1453
|
-
match = picomatch$2.matchBase(input, regex, options, posix);
|
|
1454
|
-
} else {
|
|
1455
|
-
match = regex.exec(output);
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
return { isMatch: Boolean(match), match, output };
|
|
1459
|
-
};
|
|
1460
|
-
picomatch$2.matchBase = (input, glob, options) => {
|
|
1461
|
-
const regex = glob instanceof RegExp ? glob : picomatch$2.makeRe(glob, options);
|
|
1462
|
-
return regex.test(utils$1.basename(input));
|
|
1463
|
-
};
|
|
1464
|
-
picomatch$2.isMatch = (str, patterns, options) => picomatch$2(patterns, options)(str);
|
|
1465
|
-
picomatch$2.parse = (pattern, options) => {
|
|
1466
|
-
if (Array.isArray(pattern))
|
|
1467
|
-
return pattern.map((p) => picomatch$2.parse(p, options));
|
|
1468
|
-
return parse(pattern, { ...options, fastpaths: false });
|
|
1469
|
-
};
|
|
1470
|
-
picomatch$2.scan = (input, options) => scan(input, options);
|
|
1471
|
-
picomatch$2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1472
|
-
if (returnOutput === true) {
|
|
1473
|
-
return state.output;
|
|
1474
|
-
}
|
|
1475
|
-
const opts = options || {};
|
|
1476
|
-
const prepend = opts.contains ? "" : "^";
|
|
1477
|
-
const append = opts.contains ? "" : "$";
|
|
1478
|
-
let source = `${prepend}(?:${state.output})${append}`;
|
|
1479
|
-
if (state && state.negated === true) {
|
|
1480
|
-
source = `^(?!${source}).*$`;
|
|
1481
|
-
}
|
|
1482
|
-
const regex = picomatch$2.toRegex(source, options);
|
|
1483
|
-
if (returnState === true) {
|
|
1484
|
-
regex.state = state;
|
|
1485
|
-
}
|
|
1486
|
-
return regex;
|
|
1487
|
-
};
|
|
1488
|
-
picomatch$2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1489
|
-
if (!input || typeof input !== "string") {
|
|
1490
|
-
throw new TypeError("Expected a non-empty string");
|
|
1491
|
-
}
|
|
1492
|
-
let parsed = { negated: false, fastpaths: true };
|
|
1493
|
-
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1494
|
-
parsed.output = parse.fastpaths(input, options);
|
|
1495
|
-
}
|
|
1496
|
-
if (!parsed.output) {
|
|
1497
|
-
parsed = parse(input, options);
|
|
1498
|
-
}
|
|
1499
|
-
return picomatch$2.compileRe(parsed, options, returnOutput, returnState);
|
|
1500
|
-
};
|
|
1501
|
-
picomatch$2.toRegex = (source, options) => {
|
|
1502
|
-
try {
|
|
1503
|
-
const opts = options || {};
|
|
1504
|
-
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1505
|
-
} catch (err) {
|
|
1506
|
-
if (options && options.debug === true)
|
|
1507
|
-
throw err;
|
|
1508
|
-
return /$^/;
|
|
1509
|
-
}
|
|
1510
|
-
};
|
|
1511
|
-
picomatch$2.constants = constants;
|
|
1512
|
-
var picomatch_1$1 = picomatch$2;
|
|
1513
|
-
const pico = picomatch_1$1;
|
|
1514
|
-
const utils = utils$4;
|
|
1515
|
-
function picomatch(glob, options, returnState = false) {
|
|
1516
|
-
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1517
|
-
options = { ...options, windows: utils.isWindows() };
|
|
1518
|
-
}
|
|
1519
|
-
return pico(glob, options, returnState);
|
|
1520
|
-
}
|
|
1521
|
-
Object.assign(picomatch, pico);
|
|
1522
|
-
var picomatch_1 = picomatch;
|
|
1523
|
-
const picomatch$1 = /* @__PURE__ */ getDefaultExportFromCjs(picomatch_1);
|
|
1524
|
-
function assertShape(value, yupSchema, errorMessage) {
|
|
1525
|
-
const shape = yupSchema(yup);
|
|
1526
|
-
try {
|
|
1527
|
-
shape.validateSync(value);
|
|
1528
|
-
} catch (e) {
|
|
1529
|
-
const message = errorMessage || `Failed to assertShape - ${e.message}`;
|
|
1530
|
-
throw new Error(message);
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
const lastItem = (arr) => {
|
|
1534
|
-
if (typeof arr === "undefined") {
|
|
1535
|
-
throw new Error("Can not call lastItem when arr is undefined");
|
|
1536
|
-
}
|
|
1537
|
-
return arr[arr.length - 1];
|
|
1538
|
-
};
|
|
1539
|
-
const capitalize = (s) => {
|
|
1540
|
-
if (typeof s !== "string")
|
|
1541
|
-
return "";
|
|
1542
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
1543
|
-
};
|
|
1544
|
-
const generateNamespacedFieldName = (names, suffix = "") => {
|
|
1545
|
-
return (suffix ? [...names, suffix] : names).map(capitalize).join("");
|
|
1546
|
-
};
|
|
1547
|
-
const NAMER = {
|
|
1548
|
-
dataFilterTypeNameOn: (namespace) => {
|
|
1549
|
-
return generateNamespacedFieldName(namespace, "_FilterOn");
|
|
1550
|
-
},
|
|
1551
|
-
dataFilterTypeName: (namespace) => {
|
|
1552
|
-
return generateNamespacedFieldName(namespace, "Filter");
|
|
1553
|
-
},
|
|
1554
|
-
dataMutationTypeNameOn: (namespace) => {
|
|
1555
|
-
return generateNamespacedFieldName(namespace, "_MutationOn");
|
|
1556
|
-
},
|
|
1557
|
-
dataMutationTypeName: (namespace) => {
|
|
1558
|
-
return generateNamespacedFieldName(namespace, "Mutation");
|
|
1559
|
-
},
|
|
1560
|
-
updateName: (namespace) => {
|
|
1561
|
-
return "update" + generateNamespacedFieldName(namespace, "Document");
|
|
1562
|
-
},
|
|
1563
|
-
createName: (namespace) => {
|
|
1564
|
-
return "create" + generateNamespacedFieldName(namespace, "Document");
|
|
1565
|
-
},
|
|
1566
|
-
queryName: (namespace) => {
|
|
1567
|
-
return "get" + generateNamespacedFieldName(namespace, "Document");
|
|
1568
|
-
},
|
|
1569
|
-
generateQueryListName: (namespace) => {
|
|
1570
|
-
return "get" + generateNamespacedFieldName(namespace, "List");
|
|
1571
|
-
},
|
|
1572
|
-
fragmentName: (namespace) => {
|
|
1573
|
-
return generateNamespacedFieldName(namespace, "") + "Parts";
|
|
1574
|
-
},
|
|
1575
|
-
collectionTypeName: (namespace) => {
|
|
1576
|
-
return generateNamespacedFieldName(namespace, "Collection");
|
|
1577
|
-
},
|
|
1578
|
-
documentTypeName: (namespace) => {
|
|
1579
|
-
return generateNamespacedFieldName(namespace, "Document");
|
|
1580
|
-
},
|
|
1581
|
-
dataTypeName: (namespace) => {
|
|
1582
|
-
return generateNamespacedFieldName(namespace, "");
|
|
1583
|
-
},
|
|
1584
|
-
referenceConnectionType: (namespace) => {
|
|
1585
|
-
return generateNamespacedFieldName(namespace, "Connection");
|
|
1586
|
-
},
|
|
1587
|
-
referenceConnectionEdgesTypeName: (namespace) => {
|
|
1588
|
-
return generateNamespacedFieldName(namespace, "ConnectionEdges");
|
|
1589
|
-
}
|
|
1590
|
-
};
|
|
1591
|
-
function findDuplicates(array = []) {
|
|
1592
|
-
const duplicates = [
|
|
1593
|
-
...new Set(array.filter((item, index) => array.indexOf(item) !== index))
|
|
1594
|
-
].map((x) => `"${x}"`);
|
|
1595
|
-
if (duplicates.length) {
|
|
1596
|
-
return duplicates.join(", ");
|
|
1597
|
-
} else
|
|
1598
|
-
return void 0;
|
|
1599
|
-
}
|
|
1600
|
-
const TINA_HOST = "content.tinajs.io";
|
|
1601
|
-
const parseURL = (url) => {
|
|
1602
|
-
if (url.startsWith("/")) {
|
|
1603
|
-
return {
|
|
1604
|
-
branch: null,
|
|
1605
|
-
isLocalClient: false,
|
|
1606
|
-
clientId: null,
|
|
1607
|
-
host: null
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
if (url.includes("localhost")) {
|
|
1611
|
-
return {
|
|
1612
|
-
branch: null,
|
|
1613
|
-
isLocalClient: true,
|
|
1614
|
-
clientId: null,
|
|
1615
|
-
host: "localhost"
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
const params = new URL(url);
|
|
1619
|
-
const isTinaCloud = params.host.includes("tinajs.dev") || params.host.includes("tina.io") || params.host.includes("tinajs.io");
|
|
1620
|
-
if (!isTinaCloud) {
|
|
1621
|
-
return {
|
|
1622
|
-
branch: null,
|
|
1623
|
-
isLocalClient: true,
|
|
1624
|
-
clientId: null,
|
|
1625
|
-
host: params.host
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
const pattern = new UrlPattern("/:v/content/:clientId/github/*", {
|
|
1629
|
-
escapeChar: " ",
|
|
1630
|
-
// extend to allow `.` in version
|
|
1631
|
-
segmentValueCharset: "a-zA-Z0-9-_~ %."
|
|
1632
|
-
});
|
|
1633
|
-
const result = pattern.match(params.pathname);
|
|
1634
|
-
const branch = result == null ? void 0 : result._;
|
|
1635
|
-
const clientId = result == null ? void 0 : result.clientId;
|
|
1636
|
-
if (!branch || !clientId) {
|
|
1637
|
-
throw new Error(
|
|
1638
|
-
`Invalid URL format provided. Expected: https://content.tinajs.io/<Version>/content/<ClientID>/github/<Branch> but but received ${url}`
|
|
1639
|
-
);
|
|
1640
|
-
}
|
|
1641
|
-
return {
|
|
1642
|
-
host: params.host,
|
|
1643
|
-
branch,
|
|
1644
|
-
clientId,
|
|
1645
|
-
isLocalClient: false
|
|
1646
|
-
};
|
|
1647
|
-
};
|
|
1648
|
-
const normalizePath = (filepath) => filepath.replace(/\\/g, "/");
|
|
1649
|
-
const canonicalPath = (filepath) => {
|
|
1650
|
-
return normalizePath(filepath).split("/").filter((name2) => name2 !== "").join("/");
|
|
1651
|
-
};
|
|
1652
|
-
class TinaSchema {
|
|
1653
|
-
/**
|
|
1654
|
-
* Create a schema class from a user defined schema object
|
|
1655
|
-
*/
|
|
1656
|
-
constructor(config) {
|
|
1657
|
-
this.config = config;
|
|
1658
|
-
this.getIsTitleFieldName = (collection) => {
|
|
1659
|
-
var _a;
|
|
1660
|
-
const col = this.getCollection(collection);
|
|
1661
|
-
const field = (_a = col == null ? void 0 : col.fields) == null ? void 0 : _a.find((x) => x.type === "string" && x.isTitle);
|
|
1662
|
-
return field == null ? void 0 : field.name;
|
|
1663
|
-
};
|
|
1664
|
-
this.getCollectionsByName = (collectionNames) => {
|
|
1665
|
-
return this.schema.collections.filter(
|
|
1666
|
-
(collection) => collectionNames.includes(collection.name)
|
|
1667
|
-
);
|
|
1668
|
-
};
|
|
1669
|
-
this.getCollection = (collectionName) => {
|
|
1670
|
-
const collection = this.schema.collections.find(
|
|
1671
|
-
(collection2) => collection2.name === collectionName
|
|
1672
|
-
);
|
|
1673
|
-
if (!collection) {
|
|
1674
|
-
throw new Error(`Expected to find collection named ${collectionName}`);
|
|
1675
|
-
}
|
|
1676
|
-
const extraFields = {};
|
|
1677
|
-
const templateInfo = this.getTemplatesForCollectable(collection);
|
|
1678
|
-
switch (templateInfo.type) {
|
|
1679
|
-
case "object":
|
|
1680
|
-
extraFields.fields = templateInfo.template.fields;
|
|
1681
|
-
break;
|
|
1682
|
-
case "union":
|
|
1683
|
-
extraFields.templates = templateInfo.templates;
|
|
1684
|
-
break;
|
|
1685
|
-
}
|
|
1686
|
-
return {
|
|
1687
|
-
// @ts-ignore FIXME: backwards compatibility, using `slug` should probably be deprecated
|
|
1688
|
-
slug: collection.name,
|
|
1689
|
-
...extraFields,
|
|
1690
|
-
...collection,
|
|
1691
|
-
format: collection.format || "md"
|
|
1692
|
-
};
|
|
1693
|
-
};
|
|
1694
|
-
this.getCollections = () => {
|
|
1695
|
-
return this.schema.collections.map(
|
|
1696
|
-
(collection) => this.getCollection(collection.name)
|
|
1697
|
-
) || [];
|
|
1698
|
-
};
|
|
1699
|
-
this.getCollectionByFullPath = (filepath) => {
|
|
1700
|
-
const fileExtension = filepath.split(".").pop();
|
|
1701
|
-
const canonicalFilepath = canonicalPath(filepath);
|
|
1702
|
-
const possibleCollections = this.getCollections().filter((collection) => {
|
|
1703
|
-
var _a, _b;
|
|
1704
|
-
if (!canonicalFilepath.endsWith(`.gitkeep.${collection.format || "md"}`) && fileExtension !== (collection.format || "md")) {
|
|
1705
|
-
return false;
|
|
1706
|
-
}
|
|
1707
|
-
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)) {
|
|
1708
|
-
const matches = this.getMatches({ collection });
|
|
1709
|
-
const match = picomatch$1.isMatch(canonicalFilepath, matches);
|
|
1710
|
-
if (!match) {
|
|
1711
|
-
return false;
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
const collectionPath = canonicalPath(collection.path);
|
|
1715
|
-
return collectionPath === "" || canonicalFilepath.startsWith(`${collectionPath}/`);
|
|
1716
|
-
});
|
|
1717
|
-
if (possibleCollections.length === 0) {
|
|
1718
|
-
throw new Error(`Unable to find collection for file at ${filepath}`);
|
|
1719
|
-
}
|
|
1720
|
-
if (possibleCollections.length === 1) {
|
|
1721
|
-
return possibleCollections[0];
|
|
1722
|
-
}
|
|
1723
|
-
if (possibleCollections.length > 1) {
|
|
1724
|
-
const longestMatch = possibleCollections.reduce((acc, collection) => {
|
|
1725
|
-
if (collection.path.length > acc.path.length) {
|
|
1726
|
-
return collection;
|
|
1727
|
-
}
|
|
1728
|
-
return acc;
|
|
1729
|
-
});
|
|
1730
|
-
return longestMatch;
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
this.getCollectionAndTemplateByFullPath = (filepath, templateName) => {
|
|
1734
|
-
const collection = this.getCollectionByFullPath(filepath);
|
|
1735
|
-
if (!collection) {
|
|
1736
|
-
return void 0;
|
|
1737
|
-
}
|
|
1738
|
-
let template;
|
|
1739
|
-
const templates = this.getTemplatesForCollectable(collection);
|
|
1740
|
-
if (templates.type === "union") {
|
|
1741
|
-
if (templateName) {
|
|
1742
|
-
template = templates.templates.find(
|
|
1743
|
-
(template2) => lastItem(template2.namespace) === templateName
|
|
1744
|
-
);
|
|
1745
|
-
if (!template) {
|
|
1746
|
-
throw new Error(
|
|
1747
|
-
`Unable to determine template for item at ${filepath}`
|
|
1748
|
-
);
|
|
1749
|
-
}
|
|
1750
|
-
} else {
|
|
1751
|
-
throw new Error(
|
|
1752
|
-
`Unable to determine template for item at ${filepath}, no template name provided for collection with multiple templates`
|
|
1753
|
-
);
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
if (templates.type === "object") {
|
|
1757
|
-
template = templates.template;
|
|
1758
|
-
}
|
|
1759
|
-
if (!template) {
|
|
1760
|
-
throw new Error(
|
|
1761
|
-
`Something went wrong while trying to determine template for ${filepath}`
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1764
|
-
return { collection, template };
|
|
1765
|
-
};
|
|
1766
|
-
this.getTemplateForData = ({
|
|
1767
|
-
data,
|
|
1768
|
-
collection
|
|
1769
|
-
}) => {
|
|
1770
|
-
const templateInfo = this.getTemplatesForCollectable(collection);
|
|
1771
|
-
switch (templateInfo.type) {
|
|
1772
|
-
case "object":
|
|
1773
|
-
return templateInfo.template;
|
|
1774
|
-
case "union": {
|
|
1775
|
-
assertShape(
|
|
1776
|
-
data,
|
|
1777
|
-
(yup2) => yup2.object({ _template: yup2.string().required() })
|
|
1778
|
-
);
|
|
1779
|
-
const template = templateInfo.templates.find(
|
|
1780
|
-
(template2) => template2.namespace[template2.namespace.length - 1] === data._template
|
|
1781
|
-
);
|
|
1782
|
-
if (!template) {
|
|
1783
|
-
throw new Error(
|
|
1784
|
-
`Expected to find template named '${data._template}' for collection '${lastItem(collection.namespace)}'`
|
|
1785
|
-
);
|
|
1786
|
-
}
|
|
1787
|
-
return template;
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
};
|
|
1791
|
-
this.transformPayload = (collectionName, payload) => {
|
|
1792
|
-
const collection = this.getCollection(collectionName);
|
|
1793
|
-
if (collection.templates) {
|
|
1794
|
-
const template = collection.templates.find((template2) => {
|
|
1795
|
-
if (typeof template2 === "string") {
|
|
1796
|
-
throw new Error("Global templates not supported");
|
|
1797
|
-
}
|
|
1798
|
-
return (payload == null ? void 0 : payload._template) === template2.name;
|
|
1799
|
-
});
|
|
1800
|
-
if (!template) {
|
|
1801
|
-
console.error(payload);
|
|
1802
|
-
throw new Error("Unable to find template for payload");
|
|
1803
|
-
}
|
|
1804
|
-
if (typeof template === "string") {
|
|
1805
|
-
throw new Error("Global templates not supported");
|
|
1806
|
-
}
|
|
1807
|
-
return {
|
|
1808
|
-
[collectionName]: {
|
|
1809
|
-
[template.name]: this.transformCollectablePayload(payload, template)
|
|
1810
|
-
}
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
return {
|
|
1814
|
-
[collectionName]: this.transformCollectablePayload(payload, collection)
|
|
1815
|
-
};
|
|
1816
|
-
};
|
|
1817
|
-
this.transformCollectablePayload = (payload, collection) => {
|
|
1818
|
-
const accumulator = {};
|
|
1819
|
-
Object.entries(payload).forEach(([key, value]) => {
|
|
1820
|
-
var _a;
|
|
1821
|
-
if (typeof collection.fields === "string") {
|
|
1822
|
-
throw new Error("Global templates not supported");
|
|
1823
|
-
}
|
|
1824
|
-
const field = (_a = collection == null ? void 0 : collection.fields) == null ? void 0 : _a.find((field2) => {
|
|
1825
|
-
if (typeof field2 === "string") {
|
|
1826
|
-
throw new Error("Global templates not supported");
|
|
1827
|
-
}
|
|
1828
|
-
return field2.name === key;
|
|
1829
|
-
});
|
|
1830
|
-
if (field) {
|
|
1831
|
-
accumulator[key] = this.transformField(field, value);
|
|
1832
|
-
}
|
|
1833
|
-
});
|
|
1834
|
-
return accumulator;
|
|
1835
|
-
};
|
|
1836
|
-
this.transformField = (field, value) => {
|
|
1837
|
-
if (field.type === "object")
|
|
1838
|
-
if (field.templates) {
|
|
1839
|
-
if (field.list) {
|
|
1840
|
-
assertShape(
|
|
1841
|
-
value,
|
|
1842
|
-
(yup2) => yup2.array(yup2.object({ _template: yup2.string().required() }))
|
|
1843
|
-
);
|
|
1844
|
-
return value.map((item) => {
|
|
1845
|
-
const { _template, ...rest } = item;
|
|
1846
|
-
const template = field.templates.find((template2) => {
|
|
1847
|
-
if (typeof template2 === "string") {
|
|
1848
|
-
return false;
|
|
1849
|
-
}
|
|
1850
|
-
return template2.name === _template;
|
|
1851
|
-
});
|
|
1852
|
-
if (typeof template === "string") {
|
|
1853
|
-
throw new Error("Global templates not supported");
|
|
1854
|
-
}
|
|
1855
|
-
if (!template) {
|
|
1856
|
-
throw new Error(`Expected to find template named '${_template}'`);
|
|
1857
|
-
}
|
|
1858
|
-
return {
|
|
1859
|
-
[_template]: this.transformCollectablePayload(rest, template)
|
|
1860
|
-
};
|
|
1861
|
-
});
|
|
1862
|
-
} else {
|
|
1863
|
-
assertShape(
|
|
1864
|
-
value,
|
|
1865
|
-
(yup2) => yup2.object({ _template: yup2.string().required() })
|
|
1866
|
-
);
|
|
1867
|
-
const { _template, ...rest } = value;
|
|
1868
|
-
return { [_template]: this.transformCollectablePayload(rest, field) };
|
|
1869
|
-
}
|
|
1870
|
-
} else {
|
|
1871
|
-
if (field.list) {
|
|
1872
|
-
assertShape(value, (yup2) => yup2.array(yup2.object()));
|
|
1873
|
-
return value.map((item) => {
|
|
1874
|
-
return this.transformCollectablePayload(item, field);
|
|
1875
|
-
});
|
|
1876
|
-
} else {
|
|
1877
|
-
assertShape(value, (yup2) => yup2.object());
|
|
1878
|
-
return this.transformCollectablePayload(value, field);
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
else {
|
|
1882
|
-
return value;
|
|
1883
|
-
}
|
|
1884
|
-
};
|
|
1885
|
-
this.isMarkdownCollection = (collectionName) => {
|
|
1886
|
-
const collection = this.getCollection(collectionName);
|
|
1887
|
-
const format = collection.format;
|
|
1888
|
-
if (!format) {
|
|
1889
|
-
return true;
|
|
1890
|
-
}
|
|
1891
|
-
if (["markdown", "md"].includes(format)) {
|
|
1892
|
-
return true;
|
|
1893
|
-
}
|
|
1894
|
-
return false;
|
|
1895
|
-
};
|
|
1896
|
-
this.getTemplatesForCollectable = (collection) => {
|
|
1897
|
-
const extraFields = [];
|
|
1898
|
-
if (collection == null ? void 0 : collection.fields) {
|
|
1899
|
-
const template = collection;
|
|
1900
|
-
if (typeof template.fields === "string" || typeof template.fields === "undefined") {
|
|
1901
|
-
throw new Error("Expected template to have fields but none were found");
|
|
1902
|
-
}
|
|
1903
|
-
return {
|
|
1904
|
-
namespace: collection.namespace,
|
|
1905
|
-
type: "object",
|
|
1906
|
-
template: {
|
|
1907
|
-
...template,
|
|
1908
|
-
fields: [...template.fields, ...extraFields]
|
|
1909
|
-
}
|
|
1910
|
-
};
|
|
1911
|
-
} else {
|
|
1912
|
-
if (collection == null ? void 0 : collection.templates) {
|
|
1913
|
-
return {
|
|
1914
|
-
namespace: collection.namespace,
|
|
1915
|
-
type: "union",
|
|
1916
|
-
templates: collection.templates.map((templateOrTemplateString) => {
|
|
1917
|
-
const template = templateOrTemplateString;
|
|
1918
|
-
return {
|
|
1919
|
-
...template,
|
|
1920
|
-
fields: [...template.fields, ...extraFields]
|
|
1921
|
-
};
|
|
1922
|
-
})
|
|
1923
|
-
};
|
|
1924
|
-
} else {
|
|
1925
|
-
throw new Error(
|
|
1926
|
-
`Expected either fields or templates array to be defined on collection ${collection.namespace.join(
|
|
1927
|
-
"_"
|
|
1928
|
-
)}`
|
|
1929
|
-
);
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
|
-
this.legacyWalkFields = (cb) => {
|
|
1934
|
-
const walk = (collectionOrObject, collection, path) => {
|
|
1935
|
-
if (collectionOrObject.templates) {
|
|
1936
|
-
collectionOrObject.templates.forEach((template) => {
|
|
1937
|
-
template.fields.forEach((field) => {
|
|
1938
|
-
cb({ field, collection, path: [...path, template.name] });
|
|
1939
|
-
});
|
|
1940
|
-
});
|
|
1941
|
-
}
|
|
1942
|
-
if (collectionOrObject.fields) {
|
|
1943
|
-
collectionOrObject.fields.forEach((field) => {
|
|
1944
|
-
cb({ field, collection, path: [...path, field.name] });
|
|
1945
|
-
if (field.type === "rich-text" || field.type === "object") {
|
|
1946
|
-
walk(field, collection, [...path, field.name]);
|
|
1947
|
-
}
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
};
|
|
1951
|
-
const collections = this.getCollections();
|
|
1952
|
-
collections.forEach((collection) => walk(collection, collection, []));
|
|
1953
|
-
};
|
|
1954
|
-
this.schema = config;
|
|
1955
|
-
this.legacyWalkFields(({ field, collection }) => {
|
|
1956
|
-
if (!("searchable" in field)) {
|
|
1957
|
-
if (field.type === "image") {
|
|
1958
|
-
field.searchable = false;
|
|
1959
|
-
} else {
|
|
1960
|
-
field.searchable = true;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
if (field.type === "rich-text") {
|
|
1964
|
-
if (field.parser) {
|
|
1965
|
-
return;
|
|
1966
|
-
}
|
|
1967
|
-
if (collection.format === "mdx") {
|
|
1968
|
-
field.parser = { type: "mdx" };
|
|
1969
|
-
} else {
|
|
1970
|
-
field.parser = { type: "markdown" };
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
field.uid = field.uid || false;
|
|
1974
|
-
});
|
|
1975
|
-
}
|
|
1976
|
-
findReferencesFromCollection(name2) {
|
|
1977
|
-
const result = {};
|
|
1978
|
-
this.walkFields(({ field, collection: c, path }) => {
|
|
1979
|
-
if (c.name !== name2) {
|
|
1980
|
-
return;
|
|
1981
|
-
}
|
|
1982
|
-
if (field.type === "reference") {
|
|
1983
|
-
field.collections.forEach((name22) => {
|
|
1984
|
-
if (result[name22] === void 0) {
|
|
1985
|
-
result[name22] = [];
|
|
1986
|
-
}
|
|
1987
|
-
result[name22].push(path);
|
|
1988
|
-
});
|
|
1989
|
-
}
|
|
1990
|
-
});
|
|
1991
|
-
return result;
|
|
1992
|
-
}
|
|
1993
|
-
/**
|
|
1994
|
-
* Walk all fields in tina schema
|
|
1995
|
-
*
|
|
1996
|
-
* @param cb callback function invoked for each field
|
|
1997
|
-
*/
|
|
1998
|
-
walkFields(cb) {
|
|
1999
|
-
const walk = (collectionOrObject, collection, path = "$") => {
|
|
2000
|
-
if (collectionOrObject.templates) {
|
|
2001
|
-
collectionOrObject.templates.forEach((template) => {
|
|
2002
|
-
const templatePath = `${path}.${template.name}`;
|
|
2003
|
-
template.fields.forEach((field) => {
|
|
2004
|
-
const fieldPath = field.list ? `${templatePath}[*].${field.name}` : `${templatePath}.${field.name}`;
|
|
2005
|
-
cb({ field, collection, path: fieldPath });
|
|
2006
|
-
if (field.type === "object") {
|
|
2007
|
-
walk(field, collection, fieldPath);
|
|
2008
|
-
}
|
|
2009
|
-
});
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
if (collectionOrObject.fields) {
|
|
2013
|
-
collectionOrObject.fields.forEach((field) => {
|
|
2014
|
-
const fieldPath = field.list ? `${path}.${field.name}[*]` : `${path}.${field.name}`;
|
|
2015
|
-
cb({ field, collection, path: fieldPath });
|
|
2016
|
-
if (field.type === "object" && field.fields) {
|
|
2017
|
-
walk(field, collection, fieldPath);
|
|
2018
|
-
} else if (field.templates) {
|
|
2019
|
-
field.templates.forEach((template) => {
|
|
2020
|
-
const templatePath = `${fieldPath}.${template.name}`;
|
|
2021
|
-
template.fields.forEach((field2) => {
|
|
2022
|
-
const fieldPath2 = field2.list ? `${templatePath}[*].${field2.name}` : `${templatePath}.${field2.name}`;
|
|
2023
|
-
cb({ field: field2, collection, path: fieldPath2 });
|
|
2024
|
-
if (field2.type === "object") {
|
|
2025
|
-
walk(field2, collection, fieldPath2);
|
|
2026
|
-
}
|
|
2027
|
-
});
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
});
|
|
2031
|
-
}
|
|
2032
|
-
};
|
|
2033
|
-
this.getCollections().forEach((collection) => {
|
|
2034
|
-
walk(collection, collection);
|
|
2035
|
-
});
|
|
2036
|
-
}
|
|
2037
|
-
/**
|
|
2038
|
-
* This function returns an array of glob matches for a given collection.
|
|
2039
|
-
*
|
|
2040
|
-
* @param collection The collection to get the matches for. Can be a string or a collection object.
|
|
2041
|
-
* @returns An array of glob matches.
|
|
2042
|
-
*/
|
|
2043
|
-
getMatches({
|
|
2044
|
-
collection: collectionOrString
|
|
2045
|
-
}) {
|
|
2046
|
-
var _a, _b;
|
|
2047
|
-
const collection = typeof collectionOrString === "string" ? this.getCollection(collectionOrString) : collectionOrString;
|
|
2048
|
-
const collectionPath = canonicalPath(collection.path);
|
|
2049
|
-
const pathSuffix = collectionPath ? "/" : "";
|
|
2050
|
-
const format = collection.format || "md";
|
|
2051
|
-
const matches = [];
|
|
2052
|
-
if ((_a = collection == null ? void 0 : collection.match) == null ? void 0 : _a.include) {
|
|
2053
|
-
const match = `${collectionPath}${pathSuffix}${collection.match.include}.${format}`;
|
|
2054
|
-
matches.push(match);
|
|
2055
|
-
}
|
|
2056
|
-
if ((_b = collection == null ? void 0 : collection.match) == null ? void 0 : _b.exclude) {
|
|
2057
|
-
const exclude = `!(${collectionPath}${pathSuffix}${collection.match.exclude}.${format})`;
|
|
2058
|
-
matches.push(exclude);
|
|
2059
|
-
}
|
|
2060
|
-
return matches;
|
|
2061
|
-
}
|
|
2062
|
-
matchFiles({
|
|
2063
|
-
collection,
|
|
2064
|
-
files
|
|
2065
|
-
}) {
|
|
2066
|
-
const matches = this.getMatches({ collection });
|
|
2067
|
-
const matcher = picomatch$1(matches);
|
|
2068
|
-
const matchedFiles = files.filter((file) => matcher(file));
|
|
2069
|
-
return matchedFiles;
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
const resolveField = (field, schema) => {
|
|
2073
|
-
var _a;
|
|
2074
|
-
const extraFields = field.ui || {};
|
|
2075
|
-
switch (field.type) {
|
|
2076
|
-
case "number":
|
|
2077
|
-
return {
|
|
2078
|
-
component: "number",
|
|
2079
|
-
...field,
|
|
2080
|
-
...extraFields
|
|
2081
|
-
};
|
|
2082
|
-
case "datetime":
|
|
2083
|
-
return {
|
|
2084
|
-
component: "date",
|
|
2085
|
-
...field,
|
|
2086
|
-
...extraFields
|
|
2087
|
-
};
|
|
2088
|
-
case "boolean":
|
|
2089
|
-
return {
|
|
2090
|
-
component: "toggle",
|
|
2091
|
-
...field,
|
|
2092
|
-
...extraFields
|
|
2093
|
-
};
|
|
2094
|
-
case "image":
|
|
2095
|
-
if (field.list) {
|
|
2096
|
-
return {
|
|
2097
|
-
component: "list",
|
|
2098
|
-
field: {
|
|
2099
|
-
component: "image"
|
|
2100
|
-
},
|
|
2101
|
-
...field,
|
|
2102
|
-
...extraFields
|
|
2103
|
-
};
|
|
2104
|
-
}
|
|
2105
|
-
return {
|
|
2106
|
-
component: "image",
|
|
2107
|
-
clearable: true,
|
|
2108
|
-
...field,
|
|
2109
|
-
...extraFields
|
|
2110
|
-
};
|
|
2111
|
-
case "string":
|
|
2112
|
-
if (field.options) {
|
|
2113
|
-
if (field.list) {
|
|
2114
|
-
return {
|
|
2115
|
-
component: "checkbox-group",
|
|
2116
|
-
...field,
|
|
2117
|
-
...extraFields,
|
|
2118
|
-
options: field.options
|
|
2119
|
-
};
|
|
2120
|
-
}
|
|
2121
|
-
if (field.options[0] && typeof field.options[0] === "object" && field.options[0].icon) {
|
|
2122
|
-
return {
|
|
2123
|
-
component: "button-toggle",
|
|
2124
|
-
...field,
|
|
2125
|
-
...extraFields,
|
|
2126
|
-
options: field.options
|
|
2127
|
-
};
|
|
2128
|
-
}
|
|
2129
|
-
return {
|
|
2130
|
-
component: "select",
|
|
2131
|
-
...field,
|
|
2132
|
-
...extraFields,
|
|
2133
|
-
options: field.ui && field.ui.component !== "select" ? field.options : [{ label: "Choose an option", value: "" }, ...field.options]
|
|
2134
|
-
};
|
|
2135
|
-
}
|
|
2136
|
-
if (field.list) {
|
|
2137
|
-
return {
|
|
2138
|
-
// Allows component to be overridden for scalars
|
|
2139
|
-
component: "list",
|
|
2140
|
-
field: {
|
|
2141
|
-
component: "text"
|
|
2142
|
-
},
|
|
2143
|
-
...field,
|
|
2144
|
-
...extraFields
|
|
2145
|
-
};
|
|
2146
|
-
}
|
|
2147
|
-
return {
|
|
2148
|
-
// Allows component to be overridden for scalars
|
|
2149
|
-
component: "text",
|
|
2150
|
-
...field,
|
|
2151
|
-
...extraFields
|
|
2152
|
-
};
|
|
2153
|
-
case "object": {
|
|
2154
|
-
const templateInfo = schema.getTemplatesForCollectable(field);
|
|
2155
|
-
if (templateInfo.type === "object") {
|
|
2156
|
-
return {
|
|
2157
|
-
...field,
|
|
2158
|
-
component: field.list ? "group-list" : "group",
|
|
2159
|
-
fields: templateInfo.template.fields.map(
|
|
2160
|
-
(field2) => resolveField(field2, schema)
|
|
2161
|
-
),
|
|
2162
|
-
...extraFields
|
|
2163
|
-
};
|
|
2164
|
-
} else if (templateInfo.type === "union") {
|
|
2165
|
-
const templates2 = {};
|
|
2166
|
-
const typeMap2 = {};
|
|
2167
|
-
templateInfo.templates.forEach((template) => {
|
|
2168
|
-
const extraFields2 = template.ui || {};
|
|
2169
|
-
const templateName = lastItem(template.namespace);
|
|
2170
|
-
typeMap2[templateName] = NAMER.dataTypeName(template.namespace);
|
|
2171
|
-
templates2[lastItem(template.namespace)] = {
|
|
2172
|
-
label: template.label || templateName,
|
|
2173
|
-
key: templateName,
|
|
2174
|
-
namespace: [...field.namespace, templateName],
|
|
2175
|
-
fields: template.fields.map((field2) => resolveField(field2, schema)),
|
|
2176
|
-
...extraFields2
|
|
2177
|
-
};
|
|
2178
|
-
return true;
|
|
2179
|
-
});
|
|
2180
|
-
return {
|
|
2181
|
-
...field,
|
|
2182
|
-
typeMap: typeMap2,
|
|
2183
|
-
namespace: field.namespace,
|
|
2184
|
-
component: field.list ? "blocks" : "not-implemented",
|
|
2185
|
-
templates: templates2,
|
|
2186
|
-
...extraFields
|
|
2187
|
-
};
|
|
2188
|
-
} else {
|
|
2189
|
-
throw new Error(`Unknown object for resolveField function`);
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
case "rich-text":
|
|
2193
|
-
const templates = {};
|
|
2194
|
-
(_a = field.templates) == null ? void 0 : _a.forEach((template) => {
|
|
2195
|
-
if (typeof template === "string") {
|
|
2196
|
-
throw new Error(`Global templates not yet supported for rich-text`);
|
|
2197
|
-
} else {
|
|
2198
|
-
const extraFields2 = template.ui || {};
|
|
2199
|
-
const templateName = lastItem(template.namespace);
|
|
2200
|
-
NAMER.dataTypeName(template.namespace);
|
|
2201
|
-
templates[lastItem(template.namespace)] = {
|
|
2202
|
-
label: template.label || templateName,
|
|
2203
|
-
key: templateName,
|
|
2204
|
-
inline: template.inline,
|
|
2205
|
-
name: templateName,
|
|
2206
|
-
match: template.match,
|
|
2207
|
-
fields: template.fields.map((field2) => resolveField(field2, schema)),
|
|
2208
|
-
...extraFields2
|
|
2209
|
-
};
|
|
2210
|
-
return true;
|
|
2211
|
-
}
|
|
2212
|
-
});
|
|
2213
|
-
return {
|
|
2214
|
-
...field,
|
|
2215
|
-
templates: Object.values(templates),
|
|
2216
|
-
component: "rich-text",
|
|
2217
|
-
...extraFields
|
|
2218
|
-
};
|
|
2219
|
-
case "password":
|
|
2220
|
-
return {
|
|
2221
|
-
component: "password",
|
|
2222
|
-
...field,
|
|
2223
|
-
...extraFields
|
|
2224
|
-
};
|
|
2225
|
-
case "reference":
|
|
2226
|
-
return {
|
|
2227
|
-
...field,
|
|
2228
|
-
component: "reference",
|
|
2229
|
-
...extraFields
|
|
2230
|
-
};
|
|
2231
|
-
default:
|
|
2232
|
-
throw new Error(`Unknown field type ${field.type}`);
|
|
2233
|
-
}
|
|
2234
|
-
};
|
|
2235
|
-
const resolveForm = ({
|
|
2236
|
-
collection,
|
|
2237
|
-
basename,
|
|
2238
|
-
template,
|
|
2239
|
-
schema
|
|
2240
|
-
}) => {
|
|
2241
|
-
return {
|
|
2242
|
-
id: basename,
|
|
2243
|
-
label: collection.label,
|
|
2244
|
-
name: basename,
|
|
2245
|
-
fields: template.fields.map((field) => {
|
|
2246
|
-
return resolveField(field, schema);
|
|
2247
|
-
})
|
|
2248
|
-
};
|
|
2249
|
-
};
|
|
2250
|
-
const CONTENT_FORMATS = [
|
|
2251
|
-
"mdx",
|
|
2252
|
-
"md",
|
|
2253
|
-
"markdown",
|
|
2254
|
-
"json",
|
|
2255
|
-
"yaml",
|
|
2256
|
-
"yml",
|
|
2257
|
-
"toml"
|
|
2258
|
-
];
|
|
2259
|
-
const parseZodError = ({ zodError }) => {
|
|
2260
|
-
var _a, _b, _c, _d;
|
|
2261
|
-
const errors = zodError.flatten((issue) => {
|
|
2262
|
-
const moreInfo = [];
|
|
2263
|
-
if (issue.code === "invalid_union") {
|
|
2264
|
-
issue.unionErrors.map((unionError) => {
|
|
2265
|
-
moreInfo.push(parseZodError({ zodError: unionError }));
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
const errorMessage = `${issue == null ? void 0 : issue.message}
|
|
2269
|
-
Additional information:
|
|
2270
|
-
- Error found at path ${issue.path.join(
|
|
2271
|
-
"."
|
|
2272
|
-
)}
|
|
2273
|
-
`;
|
|
2274
|
-
const errorMessages = [errorMessage, ...moreInfo];
|
|
2275
|
-
return {
|
|
2276
|
-
errors: errorMessages
|
|
2277
|
-
};
|
|
2278
|
-
});
|
|
2279
|
-
const formErrors = errors.formErrors.flatMap((x) => x.errors);
|
|
2280
|
-
const parsedErrors = [
|
|
2281
|
-
...((_b = (_a = errors.fieldErrors) == null ? void 0 : _a.collections) == null ? void 0 : _b.flatMap((x) => x.errors)) || [],
|
|
2282
|
-
...((_d = (_c = errors.fieldErrors) == null ? void 0 : _c.config) == null ? void 0 : _d.flatMap((x) => x.errors)) || [],
|
|
2283
|
-
...formErrors
|
|
2284
|
-
];
|
|
2285
|
-
return parsedErrors;
|
|
2286
|
-
};
|
|
2287
|
-
const name = z.string({
|
|
2288
|
-
required_error: "Name is required but not provided",
|
|
2289
|
-
invalid_type_error: "Name must be a string"
|
|
2290
|
-
}).superRefine((val, ctx) => {
|
|
2291
|
-
if (val.match(/^[a-zA-Z0-9_]*$/) === null) {
|
|
2292
|
-
ctx.addIssue({
|
|
2293
|
-
code: "custom",
|
|
2294
|
-
message: `name, "${val}" must be alphanumeric and can only contain underscores. (No spaces, dashes, special characters, etc.)
|
|
2295
|
-
If you only want to display this value in the CMS UI, you can use the label property to customize it.
|
|
2296
|
-
|
|
2297
|
-
If you need to use this value in your content you can use the \`nameOverride\` property to customize the value. For example:
|
|
2298
|
-
\`\`\`
|
|
2299
|
-
{
|
|
2300
|
-
"name": ${val.replace(/[^a-zA-Z0-9]/g, "_")},
|
|
2301
|
-
"nameOverride": ${val},
|
|
2302
|
-
// ...
|
|
2303
|
-
}
|
|
2304
|
-
\`\`\``
|
|
2305
|
-
});
|
|
2306
|
-
}
|
|
2307
|
-
});
|
|
2308
|
-
const duplicateFieldErrorMessage = (fields) => `Fields must have unique names. Found duplicate field names: [${fields}]`;
|
|
2309
|
-
const duplicateTemplateErrorMessage = (templates) => `Templates must have unique names. Found duplicate template names: [${templates}]`;
|
|
2310
|
-
const duplicateCollectionErrorMessage = (collection) => `Collections must have unique names. Found duplicate collection names: [${collection}]`;
|
|
2311
|
-
const TypeName = [
|
|
2312
|
-
"string",
|
|
2313
|
-
"boolean",
|
|
2314
|
-
"number",
|
|
2315
|
-
"datetime",
|
|
2316
|
-
"image",
|
|
2317
|
-
"object",
|
|
2318
|
-
"reference",
|
|
2319
|
-
"rich-text"
|
|
2320
|
-
];
|
|
2321
|
-
const formattedTypes = ` - ${TypeName.join("\n - ")}`;
|
|
2322
|
-
const typeTypeError = `Invalid \`type\` property. \`type\` expected to be one of the following values:
|
|
2323
|
-
${formattedTypes}`;
|
|
2324
|
-
const typeRequiredError = `Missing \`type\` property. Please add a \`type\` property with one of the following:
|
|
2325
|
-
${formattedTypes}`;
|
|
2326
|
-
const Option = z.union(
|
|
2327
|
-
[
|
|
2328
|
-
z.string(),
|
|
2329
|
-
z.object({ label: z.string(), value: z.string() }),
|
|
2330
|
-
z.object({ icon: z.any(), value: z.string() })
|
|
2331
|
-
],
|
|
2332
|
-
{
|
|
2333
|
-
errorMap: () => {
|
|
2334
|
-
return {
|
|
2335
|
-
message: "Invalid option array. Must be a string[] or {label: string, value: string}[] or {icon: React.ComponentType<any>, value: string}[]"
|
|
2336
|
-
};
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
);
|
|
2340
|
-
const TinaField = z.object({
|
|
2341
|
-
name,
|
|
2342
|
-
label: z.string().or(z.boolean()).optional(),
|
|
2343
|
-
description: z.string().optional(),
|
|
2344
|
-
required: z.boolean().optional()
|
|
2345
|
-
});
|
|
2346
|
-
const FieldWithList = TinaField.extend({ list: z.boolean().optional() });
|
|
2347
|
-
const TinaScalerBase = FieldWithList.extend({
|
|
2348
|
-
options: z.array(Option).optional(),
|
|
2349
|
-
uid: z.boolean().optional()
|
|
2350
|
-
});
|
|
2351
|
-
const StringField = TinaScalerBase.extend({
|
|
2352
|
-
type: z.literal("string", {
|
|
2353
|
-
invalid_type_error: typeTypeError,
|
|
2354
|
-
required_error: typeRequiredError
|
|
2355
|
-
}),
|
|
2356
|
-
isTitle: z.boolean().optional()
|
|
2357
|
-
});
|
|
2358
|
-
const PasswordField = TinaScalerBase.extend({
|
|
2359
|
-
type: z.literal("password", {
|
|
2360
|
-
invalid_type_error: typeTypeError,
|
|
2361
|
-
required_error: typeRequiredError
|
|
2362
|
-
})
|
|
2363
|
-
});
|
|
2364
|
-
const BooleanField = TinaScalerBase.extend({
|
|
2365
|
-
type: z.literal("boolean", {
|
|
2366
|
-
invalid_type_error: typeTypeError,
|
|
2367
|
-
required_error: typeRequiredError
|
|
2368
|
-
})
|
|
2369
|
-
});
|
|
2370
|
-
const NumberField = TinaScalerBase.extend({
|
|
2371
|
-
type: z.literal("number", {
|
|
2372
|
-
invalid_type_error: typeTypeError,
|
|
2373
|
-
required_error: typeRequiredError
|
|
2374
|
-
})
|
|
2375
|
-
});
|
|
2376
|
-
const ImageField = TinaScalerBase.extend({
|
|
2377
|
-
type: z.literal("image", {
|
|
2378
|
-
invalid_type_error: typeTypeError,
|
|
2379
|
-
required_error: typeRequiredError
|
|
2380
|
-
}),
|
|
2381
|
-
uploadDir: z.function().args(z.any()).returns(z.string()).optional()
|
|
2382
|
-
});
|
|
2383
|
-
const DateTimeField = TinaScalerBase.extend({
|
|
2384
|
-
type: z.literal("datetime", {
|
|
2385
|
-
invalid_type_error: typeTypeError,
|
|
2386
|
-
required_error: typeRequiredError
|
|
2387
|
-
}),
|
|
2388
|
-
dateFormat: z.string().optional(),
|
|
2389
|
-
timeFormat: z.string().optional()
|
|
2390
|
-
});
|
|
2391
|
-
const ReferenceField = FieldWithList.extend({
|
|
2392
|
-
type: z.literal("reference", {
|
|
2393
|
-
invalid_type_error: typeTypeError,
|
|
2394
|
-
required_error: typeRequiredError
|
|
2395
|
-
})
|
|
2396
|
-
});
|
|
2397
|
-
const TinaFieldZod = z.lazy(() => {
|
|
2398
|
-
const TemplateTemp = z.object({
|
|
2399
|
-
label: z.string().optional(),
|
|
2400
|
-
name,
|
|
2401
|
-
fields: z.array(TinaFieldZod),
|
|
2402
|
-
match: z.object({
|
|
2403
|
-
start: z.string(),
|
|
2404
|
-
end: z.string(),
|
|
2405
|
-
name: z.string().optional()
|
|
2406
|
-
}).optional()
|
|
2407
|
-
}).superRefine((val, ctx) => {
|
|
2408
|
-
const dups = findDuplicates(val == null ? void 0 : val.fields.map((x) => x.name));
|
|
2409
|
-
if (dups) {
|
|
2410
|
-
ctx.addIssue({
|
|
2411
|
-
code: z.ZodIssueCode.custom,
|
|
2412
|
-
message: duplicateFieldErrorMessage(dups)
|
|
2413
|
-
});
|
|
2414
|
-
}
|
|
2415
|
-
});
|
|
2416
|
-
const ObjectField = FieldWithList.extend({
|
|
2417
|
-
// needs to be redefined here to avoid circle deps
|
|
2418
|
-
type: z.literal("object", {
|
|
2419
|
-
invalid_type_error: typeTypeError,
|
|
2420
|
-
required_error: typeRequiredError
|
|
2421
|
-
}),
|
|
2422
|
-
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2423
|
-
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2424
|
-
if (dups) {
|
|
2425
|
-
ctx.addIssue({
|
|
2426
|
-
code: z.ZodIssueCode.custom,
|
|
2427
|
-
message: duplicateFieldErrorMessage(dups)
|
|
2428
|
-
});
|
|
2429
|
-
}
|
|
2430
|
-
}),
|
|
2431
|
-
templates: z.array(TemplateTemp).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2432
|
-
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2433
|
-
if (dups) {
|
|
2434
|
-
ctx.addIssue({
|
|
2435
|
-
code: z.ZodIssueCode.custom,
|
|
2436
|
-
message: duplicateTemplateErrorMessage(dups)
|
|
2437
|
-
});
|
|
2438
|
-
}
|
|
2439
|
-
})
|
|
2440
|
-
});
|
|
2441
|
-
const RichTextField = FieldWithList.extend({
|
|
2442
|
-
type: z.literal("rich-text", {
|
|
2443
|
-
invalid_type_error: typeTypeError,
|
|
2444
|
-
required_error: typeRequiredError
|
|
2445
|
-
}),
|
|
2446
|
-
templates: z.array(TemplateTemp).optional().superRefine((val, ctx) => {
|
|
2447
|
-
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2448
|
-
if (dups) {
|
|
2449
|
-
ctx.addIssue({
|
|
2450
|
-
code: z.ZodIssueCode.custom,
|
|
2451
|
-
message: duplicateTemplateErrorMessage(dups)
|
|
2452
|
-
});
|
|
2453
|
-
}
|
|
2454
|
-
})
|
|
2455
|
-
});
|
|
2456
|
-
return z.discriminatedUnion(
|
|
2457
|
-
"type",
|
|
2458
|
-
[
|
|
2459
|
-
StringField,
|
|
2460
|
-
BooleanField,
|
|
2461
|
-
NumberField,
|
|
2462
|
-
ImageField,
|
|
2463
|
-
DateTimeField,
|
|
2464
|
-
ReferenceField,
|
|
2465
|
-
ObjectField,
|
|
2466
|
-
RichTextField,
|
|
2467
|
-
PasswordField
|
|
2468
|
-
],
|
|
2469
|
-
{
|
|
2470
|
-
errorMap: (issue, ctx) => {
|
|
2471
|
-
var _a, _b;
|
|
2472
|
-
if (issue.code === "invalid_union_discriminator") {
|
|
2473
|
-
if (!((_a = ctx.data) == null ? void 0 : _a.type)) {
|
|
2474
|
-
return {
|
|
2475
|
-
message: `Missing \`type\` property in field \`${ctx.data.name}\`. Please add a \`type\` property with one of the following:
|
|
2476
|
-
${formattedTypes}`
|
|
2477
|
-
};
|
|
2478
|
-
}
|
|
2479
|
-
return {
|
|
2480
|
-
message: `Invalid \`type\` property in field \`${ctx.data.name}\`. In the schema is 'type: ${(_b = ctx.data) == null ? void 0 : _b.type}' but expected one of the following:
|
|
2481
|
-
${formattedTypes}`
|
|
2482
|
-
};
|
|
2483
|
-
}
|
|
2484
|
-
return {
|
|
2485
|
-
message: issue.message || ""
|
|
2486
|
-
};
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
).superRefine((val, ctx) => {
|
|
2490
|
-
if (val.type === "string") {
|
|
2491
|
-
const stringifiedField = JSON.stringify(val, null, 2);
|
|
2492
|
-
if (val.isTitle && val.list) {
|
|
2493
|
-
ctx.addIssue({
|
|
2494
|
-
code: z.ZodIssueCode.custom,
|
|
2495
|
-
message: `\`list: true\` is not allowed when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2496
|
-
${stringifiedField}`
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2499
|
-
if (val.isTitle && !val.required) {
|
|
2500
|
-
ctx.addIssue({
|
|
2501
|
-
code: z.ZodIssueCode.custom,
|
|
2502
|
-
message: `Property \`required: true\` is required when using \`isTitle\` for fields of \`type: string\`. Error found in field:
|
|
2503
|
-
${stringifiedField}`
|
|
2504
|
-
});
|
|
2505
|
-
}
|
|
2506
|
-
if (val.uid && val.list) {
|
|
2507
|
-
if (val.list) {
|
|
2508
|
-
ctx.addIssue({
|
|
2509
|
-
code: z.ZodIssueCode.custom,
|
|
2510
|
-
message: `\`list: true\` is not allowed when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2511
|
-
${stringifiedField}`
|
|
2512
|
-
});
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
if (val.uid && !val.required) {
|
|
2516
|
-
ctx.addIssue({
|
|
2517
|
-
code: z.ZodIssueCode.custom,
|
|
2518
|
-
message: `Property \`required: true\` is required when using \`uid\` for fields of \`type: string\`. Error found in field:
|
|
2519
|
-
${stringifiedField}`
|
|
2520
|
-
});
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
if (val.type === "object") {
|
|
2524
|
-
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2525
|
-
ctx.addIssue({
|
|
2526
|
-
code: z.ZodIssueCode.custom,
|
|
2527
|
-
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2528
|
-
});
|
|
2529
|
-
return false;
|
|
2530
|
-
}
|
|
2531
|
-
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2532
|
-
ctx.addIssue({
|
|
2533
|
-
code: z.ZodIssueCode.custom,
|
|
2534
|
-
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2535
|
-
});
|
|
2536
|
-
return false;
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
return true;
|
|
2540
|
-
});
|
|
2541
|
-
});
|
|
2542
|
-
const tinaConfigKey = z$1.object({
|
|
2543
|
-
publicFolder: z$1.string(),
|
|
2544
|
-
mediaRoot: z$1.string(),
|
|
2545
|
-
static: z$1.boolean().nullish()
|
|
2546
|
-
}).strict().optional();
|
|
2547
|
-
const tinaSearchKey = z$1.object({
|
|
2548
|
-
indexerToken: z$1.string().optional(),
|
|
2549
|
-
stopwordLanguages: z$1.array(z$1.string()).nonempty().optional(),
|
|
2550
|
-
tokenSplitRegex: z$1.string().optional()
|
|
2551
|
-
}).strict().optional();
|
|
2552
|
-
const tinaConfigZod = z$1.object({
|
|
2553
|
-
client: z$1.object({ referenceDepth: z$1.number().optional() }).optional(),
|
|
2554
|
-
media: z$1.object({
|
|
2555
|
-
tina: tinaConfigKey,
|
|
2556
|
-
loadCustomStore: z$1.function().optional()
|
|
2557
|
-
}).optional(),
|
|
2558
|
-
search: z$1.object({
|
|
2559
|
-
tina: tinaSearchKey,
|
|
2560
|
-
searchClient: z$1.any().optional(),
|
|
2561
|
-
indexBatchSize: z$1.number().gte(1).optional(),
|
|
2562
|
-
maxSearchIndexFieldLength: z$1.number().gte(1).optional()
|
|
2563
|
-
}).optional(),
|
|
2564
|
-
ui: z$1.object({
|
|
2565
|
-
previewUrl: z$1.function().optional(),
|
|
2566
|
-
optOutOfUpdateCheck: z$1.boolean().optional(),
|
|
2567
|
-
regexValidation: z$1.object({
|
|
2568
|
-
folderNameRegex: z$1.string().refine(
|
|
2569
|
-
(val) => {
|
|
2570
|
-
try {
|
|
2571
|
-
new RegExp(val);
|
|
2572
|
-
return true;
|
|
2573
|
-
} catch (error) {
|
|
2574
|
-
return false;
|
|
2575
|
-
}
|
|
2576
|
-
},
|
|
2577
|
-
{ message: "folderNameRegex is not a valid regex pattern" }
|
|
2578
|
-
).optional()
|
|
2579
|
-
}).optional()
|
|
2580
|
-
}).optional()
|
|
2581
|
-
});
|
|
2582
|
-
const validateTinaCloudSchemaConfig = (config) => {
|
|
2583
|
-
const newConfig = tinaConfigZod.parse(config);
|
|
2584
|
-
return newConfig;
|
|
2585
|
-
};
|
|
2586
|
-
const Template = z.object({
|
|
2587
|
-
label: z.string({
|
|
2588
|
-
invalid_type_error: "Invalid data type for property `label`. Must be of type `string`",
|
|
2589
|
-
required_error: "Missing `label` property. Property `label` is required."
|
|
2590
|
-
}),
|
|
2591
|
-
name,
|
|
2592
|
-
fields: z.array(TinaFieldZod)
|
|
2593
|
-
}).superRefine((val, ctx) => {
|
|
2594
|
-
var _a;
|
|
2595
|
-
const dups = findDuplicates((_a = val.fields) == null ? void 0 : _a.map((x) => x.name));
|
|
2596
|
-
if (dups) {
|
|
2597
|
-
ctx.addIssue({
|
|
2598
|
-
code: z.ZodIssueCode.custom,
|
|
2599
|
-
message: duplicateFieldErrorMessage(dups)
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
});
|
|
2603
|
-
const CollectionBaseSchema = z.object({
|
|
2604
|
-
label: z.string().optional(),
|
|
2605
|
-
name: name.superRefine((val, ctx) => {
|
|
2606
|
-
if (val === "relativePath") {
|
|
2607
|
-
ctx.addIssue({
|
|
2608
|
-
code: z.ZodIssueCode.custom,
|
|
2609
|
-
message: "Invalid `name` property. `name` cannot be 'relativePath' as it is a reserved field name."
|
|
2610
|
-
});
|
|
2611
|
-
}
|
|
2612
|
-
}),
|
|
2613
|
-
path: z.string().transform((val) => val.replace(/^\/|\/$/g, "")).superRefine((val, ctx) => {
|
|
2614
|
-
if (val === ".") {
|
|
2615
|
-
ctx.addIssue({
|
|
2616
|
-
code: z.ZodIssueCode.custom,
|
|
2617
|
-
message: "Invalid `path` property. `path` cannot be '.'. Please use '/' or '' instead."
|
|
2618
|
-
});
|
|
2619
|
-
}
|
|
2620
|
-
}),
|
|
2621
|
-
format: z.enum(CONTENT_FORMATS).optional(),
|
|
2622
|
-
isAuthCollection: z.boolean().optional(),
|
|
2623
|
-
isDetached: z.boolean().optional()
|
|
2624
|
-
});
|
|
2625
|
-
const TinaCloudCollection = CollectionBaseSchema.extend({
|
|
2626
|
-
fields: z.array(TinaFieldZod).min(1, "Property `fields` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2627
|
-
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2628
|
-
if (dups) {
|
|
2629
|
-
ctx.addIssue({
|
|
2630
|
-
code: z.ZodIssueCode.custom,
|
|
2631
|
-
message: duplicateFieldErrorMessage(dups)
|
|
2632
|
-
});
|
|
2633
|
-
}
|
|
2634
|
-
}).superRefine((val, ctx) => {
|
|
2635
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.type === "string" && x.isTitle)) || [];
|
|
2636
|
-
if (arr.length > 1) {
|
|
2637
|
-
ctx.addIssue({
|
|
2638
|
-
code: z.ZodIssueCode.custom,
|
|
2639
|
-
message: `The following fields have the property \`isTitle\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`isTitle\`.`
|
|
2640
|
-
});
|
|
2641
|
-
}
|
|
2642
|
-
}).superRefine((val, ctx) => {
|
|
2643
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.uid)) || [];
|
|
2644
|
-
if (arr.length > 2) {
|
|
2645
|
-
ctx.addIssue({
|
|
2646
|
-
code: z.ZodIssueCode.custom,
|
|
2647
|
-
message: `The following fields have the property \`uid\`: [${arr.map((field) => field.name).join(", ")}]. Only one can contain the property \`uid\`.`
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
}).superRefine((val, ctx) => {
|
|
2651
|
-
const arr = (val == null ? void 0 : val.filter((x) => x.type === "password")) || [];
|
|
2652
|
-
if (arr.length > 2) {
|
|
2653
|
-
ctx.addIssue({
|
|
2654
|
-
code: z.ZodIssueCode.custom,
|
|
2655
|
-
message: `The following fields have \`type: password\`: [${arr.map((field) => field.name).join(", ")}]. Only one can be of \`type: password\`.`
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
}),
|
|
2659
|
-
templates: z.array(Template).min(1, "Property `templates` cannot be empty.").optional().superRefine((val, ctx) => {
|
|
2660
|
-
const dups = findDuplicates(val == null ? void 0 : val.map((x) => x.name));
|
|
2661
|
-
if (dups) {
|
|
2662
|
-
ctx.addIssue({
|
|
2663
|
-
code: z.ZodIssueCode.custom,
|
|
2664
|
-
message: duplicateFieldErrorMessage(dups)
|
|
2665
|
-
});
|
|
2666
|
-
}
|
|
2667
|
-
})
|
|
2668
|
-
}).superRefine((val, ctx) => {
|
|
2669
|
-
if (!(val == null ? void 0 : val.templates) && !(val == null ? void 0 : val.fields)) {
|
|
2670
|
-
ctx.addIssue({
|
|
2671
|
-
code: z.ZodIssueCode.custom,
|
|
2672
|
-
message: "Fields of `type: object` must have either `templates` or `fields` property."
|
|
2673
|
-
});
|
|
2674
|
-
return false;
|
|
2675
|
-
}
|
|
2676
|
-
if ((val == null ? void 0 : val.templates) && (val == null ? void 0 : val.fields)) {
|
|
2677
|
-
ctx.addIssue({
|
|
2678
|
-
code: z.ZodIssueCode.custom,
|
|
2679
|
-
message: "Fields of `type: object` must have either `templates` or `fields` property, not both."
|
|
2680
|
-
});
|
|
2681
|
-
return false;
|
|
2682
|
-
}
|
|
2683
|
-
});
|
|
2684
|
-
const TinaCloudSchemaZod = z.object({
|
|
2685
|
-
collections: z.array(TinaCloudCollection),
|
|
2686
|
-
config: tinaConfigZod.optional()
|
|
2687
|
-
}).superRefine((val, ctx) => {
|
|
2688
|
-
var _a, _b, _c, _d;
|
|
2689
|
-
const dups = findDuplicates((_a = val.collections) == null ? void 0 : _a.map((x) => x.name));
|
|
2690
|
-
if (dups) {
|
|
2691
|
-
ctx.addIssue({
|
|
2692
|
-
code: z.ZodIssueCode.custom,
|
|
2693
|
-
message: duplicateCollectionErrorMessage(dups),
|
|
2694
|
-
fatal: true
|
|
2695
|
-
});
|
|
2696
|
-
}
|
|
2697
|
-
if (((_b = val.collections) == null ? void 0 : _b.filter((x) => x.isAuthCollection).length) > 1) {
|
|
2698
|
-
ctx.addIssue({
|
|
2699
|
-
code: z.ZodIssueCode.custom,
|
|
2700
|
-
message: "Only one collection can be marked as `isAuthCollection`.",
|
|
2701
|
-
fatal: true
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
const media = (_c = val == null ? void 0 : val.config) == null ? void 0 : _c.media;
|
|
2705
|
-
if (media && media.tina && media.loadCustomStore) {
|
|
2706
|
-
ctx.addIssue({
|
|
2707
|
-
code: z.ZodIssueCode.custom,
|
|
2708
|
-
message: "Cannot have both `loadCustomStore` and `tina`. Must use one or the other.",
|
|
2709
|
-
fatal: true,
|
|
2710
|
-
path: ["config", "media"]
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
const search = (_d = val == null ? void 0 : val.config) == null ? void 0 : _d.search;
|
|
2714
|
-
if (search && search.tina && search.searchClient) {
|
|
2715
|
-
ctx.addIssue({
|
|
2716
|
-
code: z.ZodIssueCode.custom,
|
|
2717
|
-
message: "Cannot have both `searchClient` and `tina`. Must use one or the other.",
|
|
2718
|
-
fatal: true,
|
|
2719
|
-
path: ["config", "search"]
|
|
2720
|
-
});
|
|
2721
|
-
}
|
|
2722
|
-
});
|
|
2723
|
-
class TinaSchemaValidationError extends Error {
|
|
2724
|
-
constructor(message) {
|
|
2725
|
-
super(message);
|
|
2726
|
-
this.name = "TinaSchemaValidationError";
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
const validateSchema = ({ schema }) => {
|
|
2730
|
-
try {
|
|
2731
|
-
TinaCloudSchemaZod.parse(schema);
|
|
2732
|
-
} catch (e) {
|
|
2733
|
-
if (e instanceof ZodError) {
|
|
2734
|
-
const errors = parseZodError({ zodError: e });
|
|
2735
|
-
throw new TinaSchemaValidationError(errors.join("\n"));
|
|
2736
|
-
}
|
|
2737
|
-
throw new Error(e);
|
|
2738
|
-
}
|
|
2739
|
-
};
|
|
2740
|
-
export {
|
|
2741
|
-
CONTENT_FORMATS,
|
|
2742
|
-
NAMER,
|
|
2743
|
-
TINA_HOST,
|
|
2744
|
-
TinaSchema,
|
|
2745
|
-
TinaSchemaValidationError,
|
|
2746
|
-
addNamespaceToSchema,
|
|
2747
|
-
canonicalPath,
|
|
2748
|
-
normalizePath,
|
|
2749
|
-
parseURL,
|
|
2750
|
-
resolveField,
|
|
2751
|
-
resolveForm,
|
|
2752
|
-
validateSchema,
|
|
2753
|
-
validateTinaCloudSchemaConfig
|
|
2754
|
-
};
|