@soda-gql/codegen 0.11.26 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3166 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +55 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3162 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/generator-BJX_PNQq.cjs +0 -2789
- package/dist/generator-BJX_PNQq.cjs.map +0 -1
- package/dist/generator-C2g1EDwR.cjs +0 -4
- package/dist/generator-CsQAp9Xj.mjs +0 -2773
- package/dist/generator-CsQAp9Xj.mjs.map +0 -1
- package/dist/generator-DSYhdRB2.mjs +0 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
2
29
|
let neverthrow = require("neverthrow");
|
|
3
30
|
let graphql = require("graphql");
|
|
4
31
|
let node_fs = require("node:fs");
|
|
@@ -6,6 +33,2852 @@ let node_path = require("node:path");
|
|
|
6
33
|
let esbuild = require("esbuild");
|
|
7
34
|
let node_crypto = require("node:crypto");
|
|
8
35
|
|
|
36
|
+
//#region node_modules/picomatch/lib/constants.js
|
|
37
|
+
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
38
|
+
const WIN_SLASH = "\\\\/";
|
|
39
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
40
|
+
/**
|
|
41
|
+
* Posix glob regex
|
|
42
|
+
*/
|
|
43
|
+
const DOT_LITERAL = "\\.";
|
|
44
|
+
const PLUS_LITERAL = "\\+";
|
|
45
|
+
const QMARK_LITERAL = "\\?";
|
|
46
|
+
const SLASH_LITERAL = "\\/";
|
|
47
|
+
const ONE_CHAR = "(?=.)";
|
|
48
|
+
const QMARK = "[^/]";
|
|
49
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
50
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
51
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
52
|
+
const NO_DOT = `(?!${DOT_LITERAL})`;
|
|
53
|
+
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
54
|
+
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
55
|
+
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
56
|
+
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
57
|
+
const STAR = `${QMARK}*?`;
|
|
58
|
+
const SEP = "/";
|
|
59
|
+
const POSIX_CHARS = {
|
|
60
|
+
DOT_LITERAL,
|
|
61
|
+
PLUS_LITERAL,
|
|
62
|
+
QMARK_LITERAL,
|
|
63
|
+
SLASH_LITERAL,
|
|
64
|
+
ONE_CHAR,
|
|
65
|
+
QMARK,
|
|
66
|
+
END_ANCHOR,
|
|
67
|
+
DOTS_SLASH,
|
|
68
|
+
NO_DOT,
|
|
69
|
+
NO_DOTS,
|
|
70
|
+
NO_DOT_SLASH,
|
|
71
|
+
NO_DOTS_SLASH,
|
|
72
|
+
QMARK_NO_DOT,
|
|
73
|
+
STAR,
|
|
74
|
+
START_ANCHOR,
|
|
75
|
+
SEP
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Windows glob regex
|
|
79
|
+
*/
|
|
80
|
+
const WINDOWS_CHARS = {
|
|
81
|
+
...POSIX_CHARS,
|
|
82
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
83
|
+
QMARK: WIN_NO_SLASH,
|
|
84
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
85
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
86
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
87
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
88
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
89
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
90
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
91
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
92
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
93
|
+
SEP: "\\"
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* POSIX Bracket Regex
|
|
97
|
+
*/
|
|
98
|
+
const POSIX_REGEX_SOURCE$1 = {
|
|
99
|
+
alnum: "a-zA-Z0-9",
|
|
100
|
+
alpha: "a-zA-Z",
|
|
101
|
+
ascii: "\\x00-\\x7F",
|
|
102
|
+
blank: " \\t",
|
|
103
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
104
|
+
digit: "0-9",
|
|
105
|
+
graph: "\\x21-\\x7E",
|
|
106
|
+
lower: "a-z",
|
|
107
|
+
print: "\\x20-\\x7E ",
|
|
108
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
109
|
+
space: " \\t\\r\\n\\v\\f",
|
|
110
|
+
upper: "A-Z",
|
|
111
|
+
word: "A-Za-z0-9_",
|
|
112
|
+
xdigit: "A-Fa-f0-9"
|
|
113
|
+
};
|
|
114
|
+
module.exports = {
|
|
115
|
+
MAX_LENGTH: 1024 * 64,
|
|
116
|
+
POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
|
|
117
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
118
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
119
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
120
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
121
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
122
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
123
|
+
REPLACEMENTS: {
|
|
124
|
+
__proto__: null,
|
|
125
|
+
"***": "*",
|
|
126
|
+
"**/**": "**",
|
|
127
|
+
"**/**/**": "**"
|
|
128
|
+
},
|
|
129
|
+
CHAR_0: 48,
|
|
130
|
+
CHAR_9: 57,
|
|
131
|
+
CHAR_UPPERCASE_A: 65,
|
|
132
|
+
CHAR_LOWERCASE_A: 97,
|
|
133
|
+
CHAR_UPPERCASE_Z: 90,
|
|
134
|
+
CHAR_LOWERCASE_Z: 122,
|
|
135
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
136
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
137
|
+
CHAR_ASTERISK: 42,
|
|
138
|
+
CHAR_AMPERSAND: 38,
|
|
139
|
+
CHAR_AT: 64,
|
|
140
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
141
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
142
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
143
|
+
CHAR_COLON: 58,
|
|
144
|
+
CHAR_COMMA: 44,
|
|
145
|
+
CHAR_DOT: 46,
|
|
146
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
147
|
+
CHAR_EQUAL: 61,
|
|
148
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
149
|
+
CHAR_FORM_FEED: 12,
|
|
150
|
+
CHAR_FORWARD_SLASH: 47,
|
|
151
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
152
|
+
CHAR_HASH: 35,
|
|
153
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
154
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
155
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
156
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
157
|
+
CHAR_LINE_FEED: 10,
|
|
158
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
159
|
+
CHAR_PERCENT: 37,
|
|
160
|
+
CHAR_PLUS: 43,
|
|
161
|
+
CHAR_QUESTION_MARK: 63,
|
|
162
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
163
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
164
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
165
|
+
CHAR_SEMICOLON: 59,
|
|
166
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
167
|
+
CHAR_SPACE: 32,
|
|
168
|
+
CHAR_TAB: 9,
|
|
169
|
+
CHAR_UNDERSCORE: 95,
|
|
170
|
+
CHAR_VERTICAL_LINE: 124,
|
|
171
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
172
|
+
extglobChars(chars) {
|
|
173
|
+
return {
|
|
174
|
+
"!": {
|
|
175
|
+
type: "negate",
|
|
176
|
+
open: "(?:(?!(?:",
|
|
177
|
+
close: `))${chars.STAR})`
|
|
178
|
+
},
|
|
179
|
+
"?": {
|
|
180
|
+
type: "qmark",
|
|
181
|
+
open: "(?:",
|
|
182
|
+
close: ")?"
|
|
183
|
+
},
|
|
184
|
+
"+": {
|
|
185
|
+
type: "plus",
|
|
186
|
+
open: "(?:",
|
|
187
|
+
close: ")+"
|
|
188
|
+
},
|
|
189
|
+
"*": {
|
|
190
|
+
type: "star",
|
|
191
|
+
open: "(?:",
|
|
192
|
+
close: ")*"
|
|
193
|
+
},
|
|
194
|
+
"@": {
|
|
195
|
+
type: "at",
|
|
196
|
+
open: "(?:",
|
|
197
|
+
close: ")"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
globChars(win32) {
|
|
202
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}));
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region node_modules/picomatch/lib/utils.js
|
|
209
|
+
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
210
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
211
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
212
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
213
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
214
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
215
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
216
|
+
exports.isWindows = () => {
|
|
217
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
218
|
+
const platform = navigator.platform.toLowerCase();
|
|
219
|
+
return platform === "win32" || platform === "windows";
|
|
220
|
+
}
|
|
221
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
222
|
+
return process.platform === "win32";
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
};
|
|
226
|
+
exports.removeBackslashes = (str) => {
|
|
227
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
228
|
+
return match === "\\" ? "" : match;
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
232
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
233
|
+
if (idx === -1) return input;
|
|
234
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
235
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
236
|
+
};
|
|
237
|
+
exports.removePrefix = (input, state = {}) => {
|
|
238
|
+
let output = input;
|
|
239
|
+
if (output.startsWith("./")) {
|
|
240
|
+
output = output.slice(2);
|
|
241
|
+
state.prefix = "./";
|
|
242
|
+
}
|
|
243
|
+
return output;
|
|
244
|
+
};
|
|
245
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
246
|
+
const prepend = options.contains ? "" : "^";
|
|
247
|
+
const append = options.contains ? "" : "$";
|
|
248
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
249
|
+
if (state.negated === true) {
|
|
250
|
+
output = `(?:^(?!${output}).*$)`;
|
|
251
|
+
}
|
|
252
|
+
return output;
|
|
253
|
+
};
|
|
254
|
+
exports.basename = (path, { windows } = {}) => {
|
|
255
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
256
|
+
const last = segs[segs.length - 1];
|
|
257
|
+
if (last === "") {
|
|
258
|
+
return segs[segs.length - 2];
|
|
259
|
+
}
|
|
260
|
+
return last;
|
|
261
|
+
};
|
|
262
|
+
}));
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region node_modules/picomatch/lib/scan.js
|
|
266
|
+
var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
267
|
+
const utils$3 = require_utils();
|
|
268
|
+
const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = require_constants();
|
|
269
|
+
const isPathSeparator = (code) => {
|
|
270
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
271
|
+
};
|
|
272
|
+
const depth = (token) => {
|
|
273
|
+
if (token.isPrefix !== true) {
|
|
274
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
279
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
280
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
281
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
282
|
+
*
|
|
283
|
+
* ```js
|
|
284
|
+
* const pm = require('picomatch');
|
|
285
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
286
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
287
|
+
* ```
|
|
288
|
+
* @param {String} `str`
|
|
289
|
+
* @param {Object} `options`
|
|
290
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
291
|
+
* @api public
|
|
292
|
+
*/
|
|
293
|
+
const scan$1 = (input, options) => {
|
|
294
|
+
const opts = options || {};
|
|
295
|
+
const length = input.length - 1;
|
|
296
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
297
|
+
const slashes = [];
|
|
298
|
+
const tokens = [];
|
|
299
|
+
const parts = [];
|
|
300
|
+
let str = input;
|
|
301
|
+
let index = -1;
|
|
302
|
+
let start = 0;
|
|
303
|
+
let lastIndex = 0;
|
|
304
|
+
let isBrace = false;
|
|
305
|
+
let isBracket = false;
|
|
306
|
+
let isGlob = false;
|
|
307
|
+
let isExtglob = false;
|
|
308
|
+
let isGlobstar = false;
|
|
309
|
+
let braceEscaped = false;
|
|
310
|
+
let backslashes = false;
|
|
311
|
+
let negated = false;
|
|
312
|
+
let negatedExtglob = false;
|
|
313
|
+
let finished = false;
|
|
314
|
+
let braces = 0;
|
|
315
|
+
let prev;
|
|
316
|
+
let code;
|
|
317
|
+
let token = {
|
|
318
|
+
value: "",
|
|
319
|
+
depth: 0,
|
|
320
|
+
isGlob: false
|
|
321
|
+
};
|
|
322
|
+
const eos = () => index >= length;
|
|
323
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
324
|
+
const advance = () => {
|
|
325
|
+
prev = code;
|
|
326
|
+
return str.charCodeAt(++index);
|
|
327
|
+
};
|
|
328
|
+
while (index < length) {
|
|
329
|
+
code = advance();
|
|
330
|
+
let next;
|
|
331
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
332
|
+
backslashes = token.backslashes = true;
|
|
333
|
+
code = advance();
|
|
334
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
335
|
+
braceEscaped = true;
|
|
336
|
+
}
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
340
|
+
braces++;
|
|
341
|
+
while (eos() !== true && (code = advance())) {
|
|
342
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
343
|
+
backslashes = token.backslashes = true;
|
|
344
|
+
advance();
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
348
|
+
braces++;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
352
|
+
isBrace = token.isBrace = true;
|
|
353
|
+
isGlob = token.isGlob = true;
|
|
354
|
+
finished = true;
|
|
355
|
+
if (scanToEnd === true) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
361
|
+
isBrace = token.isBrace = true;
|
|
362
|
+
isGlob = token.isGlob = true;
|
|
363
|
+
finished = true;
|
|
364
|
+
if (scanToEnd === true) {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
370
|
+
braces--;
|
|
371
|
+
if (braces === 0) {
|
|
372
|
+
braceEscaped = false;
|
|
373
|
+
isBrace = token.isBrace = true;
|
|
374
|
+
finished = true;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (scanToEnd === true) {
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
385
|
+
slashes.push(index);
|
|
386
|
+
tokens.push(token);
|
|
387
|
+
token = {
|
|
388
|
+
value: "",
|
|
389
|
+
depth: 0,
|
|
390
|
+
isGlob: false
|
|
391
|
+
};
|
|
392
|
+
if (finished === true) continue;
|
|
393
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
394
|
+
start += 2;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
lastIndex = index + 1;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (opts.noext !== true) {
|
|
401
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
402
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
403
|
+
isGlob = token.isGlob = true;
|
|
404
|
+
isExtglob = token.isExtglob = true;
|
|
405
|
+
finished = true;
|
|
406
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
407
|
+
negatedExtglob = true;
|
|
408
|
+
}
|
|
409
|
+
if (scanToEnd === true) {
|
|
410
|
+
while (eos() !== true && (code = advance())) {
|
|
411
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
412
|
+
backslashes = token.backslashes = true;
|
|
413
|
+
code = advance();
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
417
|
+
isGlob = token.isGlob = true;
|
|
418
|
+
finished = true;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (code === CHAR_ASTERISK) {
|
|
428
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
429
|
+
isGlob = token.isGlob = true;
|
|
430
|
+
finished = true;
|
|
431
|
+
if (scanToEnd === true) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
437
|
+
isGlob = token.isGlob = true;
|
|
438
|
+
finished = true;
|
|
439
|
+
if (scanToEnd === true) {
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
445
|
+
while (eos() !== true && (next = advance())) {
|
|
446
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
447
|
+
backslashes = token.backslashes = true;
|
|
448
|
+
advance();
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
452
|
+
isBracket = token.isBracket = true;
|
|
453
|
+
isGlob = token.isGlob = true;
|
|
454
|
+
finished = true;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (scanToEnd === true) {
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
464
|
+
negated = token.negated = true;
|
|
465
|
+
start++;
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
469
|
+
isGlob = token.isGlob = true;
|
|
470
|
+
if (scanToEnd === true) {
|
|
471
|
+
while (eos() !== true && (code = advance())) {
|
|
472
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
473
|
+
backslashes = token.backslashes = true;
|
|
474
|
+
code = advance();
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
478
|
+
finished = true;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
if (isGlob === true) {
|
|
487
|
+
finished = true;
|
|
488
|
+
if (scanToEnd === true) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (opts.noext === true) {
|
|
495
|
+
isExtglob = false;
|
|
496
|
+
isGlob = false;
|
|
497
|
+
}
|
|
498
|
+
let base = str;
|
|
499
|
+
let prefix = "";
|
|
500
|
+
let glob = "";
|
|
501
|
+
if (start > 0) {
|
|
502
|
+
prefix = str.slice(0, start);
|
|
503
|
+
str = str.slice(start);
|
|
504
|
+
lastIndex -= start;
|
|
505
|
+
}
|
|
506
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
507
|
+
base = str.slice(0, lastIndex);
|
|
508
|
+
glob = str.slice(lastIndex);
|
|
509
|
+
} else if (isGlob === true) {
|
|
510
|
+
base = "";
|
|
511
|
+
glob = str;
|
|
512
|
+
} else {
|
|
513
|
+
base = str;
|
|
514
|
+
}
|
|
515
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
516
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
517
|
+
base = base.slice(0, -1);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (opts.unescape === true) {
|
|
521
|
+
if (glob) glob = utils$3.removeBackslashes(glob);
|
|
522
|
+
if (base && backslashes === true) {
|
|
523
|
+
base = utils$3.removeBackslashes(base);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const state = {
|
|
527
|
+
prefix,
|
|
528
|
+
input,
|
|
529
|
+
start,
|
|
530
|
+
base,
|
|
531
|
+
glob,
|
|
532
|
+
isBrace,
|
|
533
|
+
isBracket,
|
|
534
|
+
isGlob,
|
|
535
|
+
isExtglob,
|
|
536
|
+
isGlobstar,
|
|
537
|
+
negated,
|
|
538
|
+
negatedExtglob
|
|
539
|
+
};
|
|
540
|
+
if (opts.tokens === true) {
|
|
541
|
+
state.maxDepth = 0;
|
|
542
|
+
if (!isPathSeparator(code)) {
|
|
543
|
+
tokens.push(token);
|
|
544
|
+
}
|
|
545
|
+
state.tokens = tokens;
|
|
546
|
+
}
|
|
547
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
548
|
+
let prevIndex;
|
|
549
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
550
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
551
|
+
const i = slashes[idx];
|
|
552
|
+
const value = input.slice(n, i);
|
|
553
|
+
if (opts.tokens) {
|
|
554
|
+
if (idx === 0 && start !== 0) {
|
|
555
|
+
tokens[idx].isPrefix = true;
|
|
556
|
+
tokens[idx].value = prefix;
|
|
557
|
+
} else {
|
|
558
|
+
tokens[idx].value = value;
|
|
559
|
+
}
|
|
560
|
+
depth(tokens[idx]);
|
|
561
|
+
state.maxDepth += tokens[idx].depth;
|
|
562
|
+
}
|
|
563
|
+
if (idx !== 0 || value !== "") {
|
|
564
|
+
parts.push(value);
|
|
565
|
+
}
|
|
566
|
+
prevIndex = i;
|
|
567
|
+
}
|
|
568
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
569
|
+
const value = input.slice(prevIndex + 1);
|
|
570
|
+
parts.push(value);
|
|
571
|
+
if (opts.tokens) {
|
|
572
|
+
tokens[tokens.length - 1].value = value;
|
|
573
|
+
depth(tokens[tokens.length - 1]);
|
|
574
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
state.slashes = slashes;
|
|
578
|
+
state.parts = parts;
|
|
579
|
+
}
|
|
580
|
+
return state;
|
|
581
|
+
};
|
|
582
|
+
module.exports = scan$1;
|
|
583
|
+
}));
|
|
584
|
+
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region node_modules/picomatch/lib/parse.js
|
|
587
|
+
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
588
|
+
const constants$1 = require_constants();
|
|
589
|
+
const utils$2 = require_utils();
|
|
590
|
+
/**
|
|
591
|
+
* Constants
|
|
592
|
+
*/
|
|
593
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants$1;
|
|
594
|
+
/**
|
|
595
|
+
* Helpers
|
|
596
|
+
*/
|
|
597
|
+
const expandRange = (args, options) => {
|
|
598
|
+
if (typeof options.expandRange === "function") {
|
|
599
|
+
return options.expandRange(...args, options);
|
|
600
|
+
}
|
|
601
|
+
args.sort();
|
|
602
|
+
const value = `[${args.join("-")}]`;
|
|
603
|
+
try {
|
|
604
|
+
new RegExp(value);
|
|
605
|
+
} catch (ex) {
|
|
606
|
+
return args.map((v) => utils$2.escapeRegex(v)).join("..");
|
|
607
|
+
}
|
|
608
|
+
return value;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Create the message for a syntax error
|
|
612
|
+
*/
|
|
613
|
+
const syntaxError = (type, char) => {
|
|
614
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Parse the given input string.
|
|
618
|
+
* @param {String} input
|
|
619
|
+
* @param {Object} options
|
|
620
|
+
* @return {Object}
|
|
621
|
+
*/
|
|
622
|
+
const parse$3 = (input, options) => {
|
|
623
|
+
if (typeof input !== "string") {
|
|
624
|
+
throw new TypeError("Expected a string");
|
|
625
|
+
}
|
|
626
|
+
input = REPLACEMENTS[input] || input;
|
|
627
|
+
const opts = { ...options };
|
|
628
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
629
|
+
let len = input.length;
|
|
630
|
+
if (len > max) {
|
|
631
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
632
|
+
}
|
|
633
|
+
const bos = {
|
|
634
|
+
type: "bos",
|
|
635
|
+
value: "",
|
|
636
|
+
output: opts.prepend || ""
|
|
637
|
+
};
|
|
638
|
+
const tokens = [bos];
|
|
639
|
+
const capture = opts.capture ? "" : "?:";
|
|
640
|
+
const PLATFORM_CHARS = constants$1.globChars(opts.windows);
|
|
641
|
+
const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
|
|
642
|
+
const { DOT_LITERAL: DOT_LITERAL$1, PLUS_LITERAL: PLUS_LITERAL$1, SLASH_LITERAL: SLASH_LITERAL$1, ONE_CHAR: ONE_CHAR$1, DOTS_SLASH: DOTS_SLASH$1, NO_DOT: NO_DOT$1, NO_DOT_SLASH: NO_DOT_SLASH$1, NO_DOTS_SLASH: NO_DOTS_SLASH$1, QMARK: QMARK$1, QMARK_NO_DOT: QMARK_NO_DOT$1, STAR: STAR$1, START_ANCHOR: START_ANCHOR$1 } = PLATFORM_CHARS;
|
|
643
|
+
const globstar = (opts$1) => {
|
|
644
|
+
return `(${capture}(?:(?!${START_ANCHOR$1}${opts$1.dot ? DOTS_SLASH$1 : DOT_LITERAL$1}).)*?)`;
|
|
645
|
+
};
|
|
646
|
+
const nodot = opts.dot ? "" : NO_DOT$1;
|
|
647
|
+
const qmarkNoDot = opts.dot ? QMARK$1 : QMARK_NO_DOT$1;
|
|
648
|
+
let star = opts.bash === true ? globstar(opts) : STAR$1;
|
|
649
|
+
if (opts.capture) {
|
|
650
|
+
star = `(${star})`;
|
|
651
|
+
}
|
|
652
|
+
if (typeof opts.noext === "boolean") {
|
|
653
|
+
opts.noextglob = opts.noext;
|
|
654
|
+
}
|
|
655
|
+
const state = {
|
|
656
|
+
input,
|
|
657
|
+
index: -1,
|
|
658
|
+
start: 0,
|
|
659
|
+
dot: opts.dot === true,
|
|
660
|
+
consumed: "",
|
|
661
|
+
output: "",
|
|
662
|
+
prefix: "",
|
|
663
|
+
backtrack: false,
|
|
664
|
+
negated: false,
|
|
665
|
+
brackets: 0,
|
|
666
|
+
braces: 0,
|
|
667
|
+
parens: 0,
|
|
668
|
+
quotes: 0,
|
|
669
|
+
globstar: false,
|
|
670
|
+
tokens
|
|
671
|
+
};
|
|
672
|
+
input = utils$2.removePrefix(input, state);
|
|
673
|
+
len = input.length;
|
|
674
|
+
const extglobs = [];
|
|
675
|
+
const braces = [];
|
|
676
|
+
const stack = [];
|
|
677
|
+
let prev = bos;
|
|
678
|
+
let value;
|
|
679
|
+
/**
|
|
680
|
+
* Tokenizing helpers
|
|
681
|
+
*/
|
|
682
|
+
const eos = () => state.index === len - 1;
|
|
683
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
684
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
685
|
+
const remaining = () => input.slice(state.index + 1);
|
|
686
|
+
const consume = (value$1 = "", num = 0) => {
|
|
687
|
+
state.consumed += value$1;
|
|
688
|
+
state.index += num;
|
|
689
|
+
};
|
|
690
|
+
const append = (token) => {
|
|
691
|
+
state.output += token.output != null ? token.output : token.value;
|
|
692
|
+
consume(token.value);
|
|
693
|
+
};
|
|
694
|
+
const negate = () => {
|
|
695
|
+
let count = 1;
|
|
696
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
697
|
+
advance();
|
|
698
|
+
state.start++;
|
|
699
|
+
count++;
|
|
700
|
+
}
|
|
701
|
+
if (count % 2 === 0) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
state.negated = true;
|
|
705
|
+
state.start++;
|
|
706
|
+
return true;
|
|
707
|
+
};
|
|
708
|
+
const increment = (type) => {
|
|
709
|
+
state[type]++;
|
|
710
|
+
stack.push(type);
|
|
711
|
+
};
|
|
712
|
+
const decrement = (type) => {
|
|
713
|
+
state[type]--;
|
|
714
|
+
stack.pop();
|
|
715
|
+
};
|
|
716
|
+
/**
|
|
717
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
718
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
719
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
720
|
+
* characters are plain text. This improves performance and simplifies
|
|
721
|
+
* lookbehinds.
|
|
722
|
+
*/
|
|
723
|
+
const push = (tok) => {
|
|
724
|
+
if (prev.type === "globstar") {
|
|
725
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
726
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
727
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
728
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
729
|
+
prev.type = "star";
|
|
730
|
+
prev.value = "*";
|
|
731
|
+
prev.output = star;
|
|
732
|
+
state.output += prev.output;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
736
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
737
|
+
}
|
|
738
|
+
if (tok.value || tok.output) append(tok);
|
|
739
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
740
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
741
|
+
prev.value += tok.value;
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
tok.prev = prev;
|
|
745
|
+
tokens.push(tok);
|
|
746
|
+
prev = tok;
|
|
747
|
+
};
|
|
748
|
+
const extglobOpen = (type, value$1) => {
|
|
749
|
+
const token = {
|
|
750
|
+
...EXTGLOB_CHARS[value$1],
|
|
751
|
+
conditions: 1,
|
|
752
|
+
inner: ""
|
|
753
|
+
};
|
|
754
|
+
token.prev = prev;
|
|
755
|
+
token.parens = state.parens;
|
|
756
|
+
token.output = state.output;
|
|
757
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
758
|
+
increment("parens");
|
|
759
|
+
push({
|
|
760
|
+
type,
|
|
761
|
+
value: value$1,
|
|
762
|
+
output: state.output ? "" : ONE_CHAR$1
|
|
763
|
+
});
|
|
764
|
+
push({
|
|
765
|
+
type: "paren",
|
|
766
|
+
extglob: true,
|
|
767
|
+
value: advance(),
|
|
768
|
+
output
|
|
769
|
+
});
|
|
770
|
+
extglobs.push(token);
|
|
771
|
+
};
|
|
772
|
+
const extglobClose = (token) => {
|
|
773
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
774
|
+
let rest;
|
|
775
|
+
if (token.type === "negate") {
|
|
776
|
+
let extglobStar = star;
|
|
777
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
778
|
+
extglobStar = globstar(opts);
|
|
779
|
+
}
|
|
780
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
781
|
+
output = token.close = `)$))${extglobStar}`;
|
|
782
|
+
}
|
|
783
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
784
|
+
const expression = parse$3(rest, {
|
|
785
|
+
...options,
|
|
786
|
+
fastpaths: false
|
|
787
|
+
}).output;
|
|
788
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
789
|
+
}
|
|
790
|
+
if (token.prev.type === "bos") {
|
|
791
|
+
state.negatedExtglob = true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
push({
|
|
795
|
+
type: "paren",
|
|
796
|
+
extglob: true,
|
|
797
|
+
value,
|
|
798
|
+
output
|
|
799
|
+
});
|
|
800
|
+
decrement("parens");
|
|
801
|
+
};
|
|
802
|
+
/**
|
|
803
|
+
* Fast paths
|
|
804
|
+
*/
|
|
805
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
806
|
+
let backslashes = false;
|
|
807
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
808
|
+
if (first === "\\") {
|
|
809
|
+
backslashes = true;
|
|
810
|
+
return m;
|
|
811
|
+
}
|
|
812
|
+
if (first === "?") {
|
|
813
|
+
if (esc) {
|
|
814
|
+
return esc + first + (rest ? QMARK$1.repeat(rest.length) : "");
|
|
815
|
+
}
|
|
816
|
+
if (index === 0) {
|
|
817
|
+
return qmarkNoDot + (rest ? QMARK$1.repeat(rest.length) : "");
|
|
818
|
+
}
|
|
819
|
+
return QMARK$1.repeat(chars.length);
|
|
820
|
+
}
|
|
821
|
+
if (first === ".") {
|
|
822
|
+
return DOT_LITERAL$1.repeat(chars.length);
|
|
823
|
+
}
|
|
824
|
+
if (first === "*") {
|
|
825
|
+
if (esc) {
|
|
826
|
+
return esc + first + (rest ? star : "");
|
|
827
|
+
}
|
|
828
|
+
return star;
|
|
829
|
+
}
|
|
830
|
+
return esc ? m : `\\${m}`;
|
|
831
|
+
});
|
|
832
|
+
if (backslashes === true) {
|
|
833
|
+
if (opts.unescape === true) {
|
|
834
|
+
output = output.replace(/\\/g, "");
|
|
835
|
+
} else {
|
|
836
|
+
output = output.replace(/\\+/g, (m) => {
|
|
837
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (output === input && opts.contains === true) {
|
|
842
|
+
state.output = input;
|
|
843
|
+
return state;
|
|
844
|
+
}
|
|
845
|
+
state.output = utils$2.wrapOutput(output, state, options);
|
|
846
|
+
return state;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Tokenize input until we reach end-of-string
|
|
850
|
+
*/
|
|
851
|
+
while (!eos()) {
|
|
852
|
+
value = advance();
|
|
853
|
+
if (value === "\0") {
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Escaped characters
|
|
858
|
+
*/
|
|
859
|
+
if (value === "\\") {
|
|
860
|
+
const next = peek();
|
|
861
|
+
if (next === "/" && opts.bash !== true) {
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
if (next === "." || next === ";") {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
if (!next) {
|
|
868
|
+
value += "\\";
|
|
869
|
+
push({
|
|
870
|
+
type: "text",
|
|
871
|
+
value
|
|
872
|
+
});
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
const match = /^\\+/.exec(remaining());
|
|
876
|
+
let slashes = 0;
|
|
877
|
+
if (match && match[0].length > 2) {
|
|
878
|
+
slashes = match[0].length;
|
|
879
|
+
state.index += slashes;
|
|
880
|
+
if (slashes % 2 !== 0) {
|
|
881
|
+
value += "\\";
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (opts.unescape === true) {
|
|
885
|
+
value = advance();
|
|
886
|
+
} else {
|
|
887
|
+
value += advance();
|
|
888
|
+
}
|
|
889
|
+
if (state.brackets === 0) {
|
|
890
|
+
push({
|
|
891
|
+
type: "text",
|
|
892
|
+
value
|
|
893
|
+
});
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* If we're inside a regex character class, continue
|
|
899
|
+
* until we reach the closing bracket.
|
|
900
|
+
*/
|
|
901
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
902
|
+
if (opts.posix !== false && value === ":") {
|
|
903
|
+
const inner = prev.value.slice(1);
|
|
904
|
+
if (inner.includes("[")) {
|
|
905
|
+
prev.posix = true;
|
|
906
|
+
if (inner.includes(":")) {
|
|
907
|
+
const idx = prev.value.lastIndexOf("[");
|
|
908
|
+
const pre = prev.value.slice(0, idx);
|
|
909
|
+
const rest$1 = prev.value.slice(idx + 2);
|
|
910
|
+
const posix = POSIX_REGEX_SOURCE[rest$1];
|
|
911
|
+
if (posix) {
|
|
912
|
+
prev.value = pre + posix;
|
|
913
|
+
state.backtrack = true;
|
|
914
|
+
advance();
|
|
915
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
916
|
+
bos.output = ONE_CHAR$1;
|
|
917
|
+
}
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
924
|
+
value = `\\${value}`;
|
|
925
|
+
}
|
|
926
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
927
|
+
value = `\\${value}`;
|
|
928
|
+
}
|
|
929
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
930
|
+
value = "^";
|
|
931
|
+
}
|
|
932
|
+
prev.value += value;
|
|
933
|
+
append({ value });
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* If we're inside a quoted string, continue
|
|
938
|
+
* until we reach the closing double quote.
|
|
939
|
+
*/
|
|
940
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
941
|
+
value = utils$2.escapeRegex(value);
|
|
942
|
+
prev.value += value;
|
|
943
|
+
append({ value });
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Double quotes
|
|
948
|
+
*/
|
|
949
|
+
if (value === "\"") {
|
|
950
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
951
|
+
if (opts.keepQuotes === true) {
|
|
952
|
+
push({
|
|
953
|
+
type: "text",
|
|
954
|
+
value
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Parentheses
|
|
961
|
+
*/
|
|
962
|
+
if (value === "(") {
|
|
963
|
+
increment("parens");
|
|
964
|
+
push({
|
|
965
|
+
type: "paren",
|
|
966
|
+
value
|
|
967
|
+
});
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
if (value === ")") {
|
|
971
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
972
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
973
|
+
}
|
|
974
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
975
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
976
|
+
extglobClose(extglobs.pop());
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
push({
|
|
980
|
+
type: "paren",
|
|
981
|
+
value,
|
|
982
|
+
output: state.parens ? ")" : "\\)"
|
|
983
|
+
});
|
|
984
|
+
decrement("parens");
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Square brackets
|
|
989
|
+
*/
|
|
990
|
+
if (value === "[") {
|
|
991
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
992
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
993
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
994
|
+
}
|
|
995
|
+
value = `\\${value}`;
|
|
996
|
+
} else {
|
|
997
|
+
increment("brackets");
|
|
998
|
+
}
|
|
999
|
+
push({
|
|
1000
|
+
type: "bracket",
|
|
1001
|
+
value
|
|
1002
|
+
});
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
if (value === "]") {
|
|
1006
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
1007
|
+
push({
|
|
1008
|
+
type: "text",
|
|
1009
|
+
value,
|
|
1010
|
+
output: `\\${value}`
|
|
1011
|
+
});
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
if (state.brackets === 0) {
|
|
1015
|
+
if (opts.strictBrackets === true) {
|
|
1016
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
1017
|
+
}
|
|
1018
|
+
push({
|
|
1019
|
+
type: "text",
|
|
1020
|
+
value,
|
|
1021
|
+
output: `\\${value}`
|
|
1022
|
+
});
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
decrement("brackets");
|
|
1026
|
+
const prevValue = prev.value.slice(1);
|
|
1027
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
1028
|
+
value = `/${value}`;
|
|
1029
|
+
}
|
|
1030
|
+
prev.value += value;
|
|
1031
|
+
append({ value });
|
|
1032
|
+
if (opts.literalBrackets === false || utils$2.hasRegexChars(prevValue)) {
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
const escaped = utils$2.escapeRegex(prev.value);
|
|
1036
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1037
|
+
if (opts.literalBrackets === true) {
|
|
1038
|
+
state.output += escaped;
|
|
1039
|
+
prev.value = escaped;
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1043
|
+
state.output += prev.value;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Braces
|
|
1048
|
+
*/
|
|
1049
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1050
|
+
increment("braces");
|
|
1051
|
+
const open = {
|
|
1052
|
+
type: "brace",
|
|
1053
|
+
value,
|
|
1054
|
+
output: "(",
|
|
1055
|
+
outputIndex: state.output.length,
|
|
1056
|
+
tokensIndex: state.tokens.length
|
|
1057
|
+
};
|
|
1058
|
+
braces.push(open);
|
|
1059
|
+
push(open);
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (value === "}") {
|
|
1063
|
+
const brace = braces[braces.length - 1];
|
|
1064
|
+
if (opts.nobrace === true || !brace) {
|
|
1065
|
+
push({
|
|
1066
|
+
type: "text",
|
|
1067
|
+
value,
|
|
1068
|
+
output: value
|
|
1069
|
+
});
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
let output = ")";
|
|
1073
|
+
if (brace.dots === true) {
|
|
1074
|
+
const arr = tokens.slice();
|
|
1075
|
+
const range = [];
|
|
1076
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1077
|
+
tokens.pop();
|
|
1078
|
+
if (arr[i].type === "brace") {
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
if (arr[i].type !== "dots") {
|
|
1082
|
+
range.unshift(arr[i].value);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
output = expandRange(range, opts);
|
|
1086
|
+
state.backtrack = true;
|
|
1087
|
+
}
|
|
1088
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1089
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1090
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1091
|
+
brace.value = brace.output = "\\{";
|
|
1092
|
+
value = output = "\\}";
|
|
1093
|
+
state.output = out;
|
|
1094
|
+
for (const t of toks) {
|
|
1095
|
+
state.output += t.output || t.value;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
push({
|
|
1099
|
+
type: "brace",
|
|
1100
|
+
value,
|
|
1101
|
+
output
|
|
1102
|
+
});
|
|
1103
|
+
decrement("braces");
|
|
1104
|
+
braces.pop();
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Pipes
|
|
1109
|
+
*/
|
|
1110
|
+
if (value === "|") {
|
|
1111
|
+
if (extglobs.length > 0) {
|
|
1112
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1113
|
+
}
|
|
1114
|
+
push({
|
|
1115
|
+
type: "text",
|
|
1116
|
+
value
|
|
1117
|
+
});
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Commas
|
|
1122
|
+
*/
|
|
1123
|
+
if (value === ",") {
|
|
1124
|
+
let output = value;
|
|
1125
|
+
const brace = braces[braces.length - 1];
|
|
1126
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1127
|
+
brace.comma = true;
|
|
1128
|
+
output = "|";
|
|
1129
|
+
}
|
|
1130
|
+
push({
|
|
1131
|
+
type: "comma",
|
|
1132
|
+
value,
|
|
1133
|
+
output
|
|
1134
|
+
});
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Slashes
|
|
1139
|
+
*/
|
|
1140
|
+
if (value === "/") {
|
|
1141
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1142
|
+
state.start = state.index + 1;
|
|
1143
|
+
state.consumed = "";
|
|
1144
|
+
state.output = "";
|
|
1145
|
+
tokens.pop();
|
|
1146
|
+
prev = bos;
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
push({
|
|
1150
|
+
type: "slash",
|
|
1151
|
+
value,
|
|
1152
|
+
output: SLASH_LITERAL$1
|
|
1153
|
+
});
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Dots
|
|
1158
|
+
*/
|
|
1159
|
+
if (value === ".") {
|
|
1160
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1161
|
+
if (prev.value === ".") prev.output = DOT_LITERAL$1;
|
|
1162
|
+
const brace = braces[braces.length - 1];
|
|
1163
|
+
prev.type = "dots";
|
|
1164
|
+
prev.output += value;
|
|
1165
|
+
prev.value += value;
|
|
1166
|
+
brace.dots = true;
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1170
|
+
push({
|
|
1171
|
+
type: "text",
|
|
1172
|
+
value,
|
|
1173
|
+
output: DOT_LITERAL$1
|
|
1174
|
+
});
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
push({
|
|
1178
|
+
type: "dot",
|
|
1179
|
+
value,
|
|
1180
|
+
output: DOT_LITERAL$1
|
|
1181
|
+
});
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Question marks
|
|
1186
|
+
*/
|
|
1187
|
+
if (value === "?") {
|
|
1188
|
+
const isGroup = prev && prev.value === "(";
|
|
1189
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1190
|
+
extglobOpen("qmark", value);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (prev && prev.type === "paren") {
|
|
1194
|
+
const next = peek();
|
|
1195
|
+
let output = value;
|
|
1196
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1197
|
+
output = `\\${value}`;
|
|
1198
|
+
}
|
|
1199
|
+
push({
|
|
1200
|
+
type: "text",
|
|
1201
|
+
value,
|
|
1202
|
+
output
|
|
1203
|
+
});
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1207
|
+
push({
|
|
1208
|
+
type: "qmark",
|
|
1209
|
+
value,
|
|
1210
|
+
output: QMARK_NO_DOT$1
|
|
1211
|
+
});
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1214
|
+
push({
|
|
1215
|
+
type: "qmark",
|
|
1216
|
+
value,
|
|
1217
|
+
output: QMARK$1
|
|
1218
|
+
});
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Exclamation
|
|
1223
|
+
*/
|
|
1224
|
+
if (value === "!") {
|
|
1225
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1226
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1227
|
+
extglobOpen("negate", value);
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1232
|
+
negate();
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Plus
|
|
1238
|
+
*/
|
|
1239
|
+
if (value === "+") {
|
|
1240
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1241
|
+
extglobOpen("plus", value);
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1245
|
+
push({
|
|
1246
|
+
type: "plus",
|
|
1247
|
+
value,
|
|
1248
|
+
output: PLUS_LITERAL$1
|
|
1249
|
+
});
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1253
|
+
push({
|
|
1254
|
+
type: "plus",
|
|
1255
|
+
value
|
|
1256
|
+
});
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
push({
|
|
1260
|
+
type: "plus",
|
|
1261
|
+
value: PLUS_LITERAL$1
|
|
1262
|
+
});
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Plain text
|
|
1267
|
+
*/
|
|
1268
|
+
if (value === "@") {
|
|
1269
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1270
|
+
push({
|
|
1271
|
+
type: "at",
|
|
1272
|
+
extglob: true,
|
|
1273
|
+
value,
|
|
1274
|
+
output: ""
|
|
1275
|
+
});
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
push({
|
|
1279
|
+
type: "text",
|
|
1280
|
+
value
|
|
1281
|
+
});
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Plain text
|
|
1286
|
+
*/
|
|
1287
|
+
if (value !== "*") {
|
|
1288
|
+
if (value === "$" || value === "^") {
|
|
1289
|
+
value = `\\${value}`;
|
|
1290
|
+
}
|
|
1291
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1292
|
+
if (match) {
|
|
1293
|
+
value += match[0];
|
|
1294
|
+
state.index += match[0].length;
|
|
1295
|
+
}
|
|
1296
|
+
push({
|
|
1297
|
+
type: "text",
|
|
1298
|
+
value
|
|
1299
|
+
});
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Stars
|
|
1304
|
+
*/
|
|
1305
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1306
|
+
prev.type = "star";
|
|
1307
|
+
prev.star = true;
|
|
1308
|
+
prev.value += value;
|
|
1309
|
+
prev.output = star;
|
|
1310
|
+
state.backtrack = true;
|
|
1311
|
+
state.globstar = true;
|
|
1312
|
+
consume(value);
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
let rest = remaining();
|
|
1316
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1317
|
+
extglobOpen("star", value);
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (prev.type === "star") {
|
|
1321
|
+
if (opts.noglobstar === true) {
|
|
1322
|
+
consume(value);
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
const prior = prev.prev;
|
|
1326
|
+
const before = prior.prev;
|
|
1327
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1328
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1329
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1330
|
+
push({
|
|
1331
|
+
type: "star",
|
|
1332
|
+
value,
|
|
1333
|
+
output: ""
|
|
1334
|
+
});
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1338
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1339
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1340
|
+
push({
|
|
1341
|
+
type: "star",
|
|
1342
|
+
value,
|
|
1343
|
+
output: ""
|
|
1344
|
+
});
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1348
|
+
const after = input[state.index + 4];
|
|
1349
|
+
if (after && after !== "/") {
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1352
|
+
rest = rest.slice(3);
|
|
1353
|
+
consume("/**", 3);
|
|
1354
|
+
}
|
|
1355
|
+
if (prior.type === "bos" && eos()) {
|
|
1356
|
+
prev.type = "globstar";
|
|
1357
|
+
prev.value += value;
|
|
1358
|
+
prev.output = globstar(opts);
|
|
1359
|
+
state.output = prev.output;
|
|
1360
|
+
state.globstar = true;
|
|
1361
|
+
consume(value);
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1365
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1366
|
+
prior.output = `(?:${prior.output}`;
|
|
1367
|
+
prev.type = "globstar";
|
|
1368
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1369
|
+
prev.value += value;
|
|
1370
|
+
state.globstar = true;
|
|
1371
|
+
state.output += prior.output + prev.output;
|
|
1372
|
+
consume(value);
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1376
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1377
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1378
|
+
prior.output = `(?:${prior.output}`;
|
|
1379
|
+
prev.type = "globstar";
|
|
1380
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL$1}|${SLASH_LITERAL$1}${end})`;
|
|
1381
|
+
prev.value += value;
|
|
1382
|
+
state.output += prior.output + prev.output;
|
|
1383
|
+
state.globstar = true;
|
|
1384
|
+
consume(value + advance());
|
|
1385
|
+
push({
|
|
1386
|
+
type: "slash",
|
|
1387
|
+
value: "/",
|
|
1388
|
+
output: ""
|
|
1389
|
+
});
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1393
|
+
prev.type = "globstar";
|
|
1394
|
+
prev.value += value;
|
|
1395
|
+
prev.output = `(?:^|${SLASH_LITERAL$1}|${globstar(opts)}${SLASH_LITERAL$1})`;
|
|
1396
|
+
state.output = prev.output;
|
|
1397
|
+
state.globstar = true;
|
|
1398
|
+
consume(value + advance());
|
|
1399
|
+
push({
|
|
1400
|
+
type: "slash",
|
|
1401
|
+
value: "/",
|
|
1402
|
+
output: ""
|
|
1403
|
+
});
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1407
|
+
prev.type = "globstar";
|
|
1408
|
+
prev.output = globstar(opts);
|
|
1409
|
+
prev.value += value;
|
|
1410
|
+
state.output += prev.output;
|
|
1411
|
+
state.globstar = true;
|
|
1412
|
+
consume(value);
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
const token = {
|
|
1416
|
+
type: "star",
|
|
1417
|
+
value,
|
|
1418
|
+
output: star
|
|
1419
|
+
};
|
|
1420
|
+
if (opts.bash === true) {
|
|
1421
|
+
token.output = ".*?";
|
|
1422
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1423
|
+
token.output = nodot + token.output;
|
|
1424
|
+
}
|
|
1425
|
+
push(token);
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1429
|
+
token.output = value;
|
|
1430
|
+
push(token);
|
|
1431
|
+
continue;
|
|
1432
|
+
}
|
|
1433
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1434
|
+
if (prev.type === "dot") {
|
|
1435
|
+
state.output += NO_DOT_SLASH$1;
|
|
1436
|
+
prev.output += NO_DOT_SLASH$1;
|
|
1437
|
+
} else if (opts.dot === true) {
|
|
1438
|
+
state.output += NO_DOTS_SLASH$1;
|
|
1439
|
+
prev.output += NO_DOTS_SLASH$1;
|
|
1440
|
+
} else {
|
|
1441
|
+
state.output += nodot;
|
|
1442
|
+
prev.output += nodot;
|
|
1443
|
+
}
|
|
1444
|
+
if (peek() !== "*") {
|
|
1445
|
+
state.output += ONE_CHAR$1;
|
|
1446
|
+
prev.output += ONE_CHAR$1;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
push(token);
|
|
1450
|
+
}
|
|
1451
|
+
while (state.brackets > 0) {
|
|
1452
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1453
|
+
state.output = utils$2.escapeLast(state.output, "[");
|
|
1454
|
+
decrement("brackets");
|
|
1455
|
+
}
|
|
1456
|
+
while (state.parens > 0) {
|
|
1457
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1458
|
+
state.output = utils$2.escapeLast(state.output, "(");
|
|
1459
|
+
decrement("parens");
|
|
1460
|
+
}
|
|
1461
|
+
while (state.braces > 0) {
|
|
1462
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1463
|
+
state.output = utils$2.escapeLast(state.output, "{");
|
|
1464
|
+
decrement("braces");
|
|
1465
|
+
}
|
|
1466
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1467
|
+
push({
|
|
1468
|
+
type: "maybe_slash",
|
|
1469
|
+
value: "",
|
|
1470
|
+
output: `${SLASH_LITERAL$1}?`
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
if (state.backtrack === true) {
|
|
1474
|
+
state.output = "";
|
|
1475
|
+
for (const token of state.tokens) {
|
|
1476
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1477
|
+
if (token.suffix) {
|
|
1478
|
+
state.output += token.suffix;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return state;
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
1486
|
+
* This can significantly speed up processing and has very little downside
|
|
1487
|
+
* impact when none of the fast paths match.
|
|
1488
|
+
*/
|
|
1489
|
+
parse$3.fastpaths = (input, options) => {
|
|
1490
|
+
const opts = { ...options };
|
|
1491
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1492
|
+
const len = input.length;
|
|
1493
|
+
if (len > max) {
|
|
1494
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1495
|
+
}
|
|
1496
|
+
input = REPLACEMENTS[input] || input;
|
|
1497
|
+
const { DOT_LITERAL: DOT_LITERAL$1, SLASH_LITERAL: SLASH_LITERAL$1, ONE_CHAR: ONE_CHAR$1, DOTS_SLASH: DOTS_SLASH$1, NO_DOT: NO_DOT$1, NO_DOTS: NO_DOTS$1, NO_DOTS_SLASH: NO_DOTS_SLASH$1, STAR: STAR$1, START_ANCHOR: START_ANCHOR$1 } = constants$1.globChars(opts.windows);
|
|
1498
|
+
const nodot = opts.dot ? NO_DOTS$1 : NO_DOT$1;
|
|
1499
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH$1 : NO_DOT$1;
|
|
1500
|
+
const capture = opts.capture ? "" : "?:";
|
|
1501
|
+
const state = {
|
|
1502
|
+
negated: false,
|
|
1503
|
+
prefix: ""
|
|
1504
|
+
};
|
|
1505
|
+
let star = opts.bash === true ? ".*?" : STAR$1;
|
|
1506
|
+
if (opts.capture) {
|
|
1507
|
+
star = `(${star})`;
|
|
1508
|
+
}
|
|
1509
|
+
const globstar = (opts$1) => {
|
|
1510
|
+
if (opts$1.noglobstar === true) return star;
|
|
1511
|
+
return `(${capture}(?:(?!${START_ANCHOR$1}${opts$1.dot ? DOTS_SLASH$1 : DOT_LITERAL$1}).)*?)`;
|
|
1512
|
+
};
|
|
1513
|
+
const create = (str) => {
|
|
1514
|
+
switch (str) {
|
|
1515
|
+
case "*": return `${nodot}${ONE_CHAR$1}${star}`;
|
|
1516
|
+
case ".*": return `${DOT_LITERAL$1}${ONE_CHAR$1}${star}`;
|
|
1517
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL$1}${ONE_CHAR$1}${star}`;
|
|
1518
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL$1}${ONE_CHAR$1}${slashDot}${star}`;
|
|
1519
|
+
case "**": return nodot + globstar(opts);
|
|
1520
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL$1})?${slashDot}${ONE_CHAR$1}${star}`;
|
|
1521
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL$1})?${slashDot}${star}${DOT_LITERAL$1}${ONE_CHAR$1}${star}`;
|
|
1522
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL$1})?${DOT_LITERAL$1}${ONE_CHAR$1}${star}`;
|
|
1523
|
+
default: {
|
|
1524
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1525
|
+
if (!match) return;
|
|
1526
|
+
const source$1 = create(match[1]);
|
|
1527
|
+
if (!source$1) return;
|
|
1528
|
+
return source$1 + DOT_LITERAL$1 + match[2];
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
const output = utils$2.removePrefix(input, state);
|
|
1533
|
+
let source = create(output);
|
|
1534
|
+
if (source && opts.strictSlashes !== true) {
|
|
1535
|
+
source += `${SLASH_LITERAL$1}?`;
|
|
1536
|
+
}
|
|
1537
|
+
return source;
|
|
1538
|
+
};
|
|
1539
|
+
module.exports = parse$3;
|
|
1540
|
+
}));
|
|
1541
|
+
|
|
1542
|
+
//#endregion
|
|
1543
|
+
//#region node_modules/picomatch/lib/picomatch.js
|
|
1544
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1545
|
+
const scan = require_scan();
|
|
1546
|
+
const parse$2 = require_parse();
|
|
1547
|
+
const utils$1 = require_utils();
|
|
1548
|
+
const constants = require_constants();
|
|
1549
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1550
|
+
/**
|
|
1551
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
1552
|
+
* returned function takes a string to match as its first argument,
|
|
1553
|
+
* and returns true if the string is a match. The returned matcher
|
|
1554
|
+
* function also takes a boolean as the second argument that, when true,
|
|
1555
|
+
* returns an object with additional information.
|
|
1556
|
+
*
|
|
1557
|
+
* ```js
|
|
1558
|
+
* const picomatch = require('picomatch');
|
|
1559
|
+
* // picomatch(glob[, options]);
|
|
1560
|
+
*
|
|
1561
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
1562
|
+
* console.log(isMatch('a.a')); //=> false
|
|
1563
|
+
* console.log(isMatch('a.b')); //=> true
|
|
1564
|
+
* ```
|
|
1565
|
+
* @name picomatch
|
|
1566
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
1567
|
+
* @param {Object=} `options`
|
|
1568
|
+
* @return {Function=} Returns a matcher function.
|
|
1569
|
+
* @api public
|
|
1570
|
+
*/
|
|
1571
|
+
const picomatch$2 = (glob, options, returnState = false) => {
|
|
1572
|
+
if (Array.isArray(glob)) {
|
|
1573
|
+
const fns = glob.map((input) => picomatch$2(input, options, returnState));
|
|
1574
|
+
const arrayMatcher = (str) => {
|
|
1575
|
+
for (const isMatch of fns) {
|
|
1576
|
+
const state$1 = isMatch(str);
|
|
1577
|
+
if (state$1) return state$1;
|
|
1578
|
+
}
|
|
1579
|
+
return false;
|
|
1580
|
+
};
|
|
1581
|
+
return arrayMatcher;
|
|
1582
|
+
}
|
|
1583
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1584
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1585
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1586
|
+
}
|
|
1587
|
+
const opts = options || {};
|
|
1588
|
+
const posix = opts.windows;
|
|
1589
|
+
const regex = isState ? picomatch$2.compileRe(glob, options) : picomatch$2.makeRe(glob, options, false, true);
|
|
1590
|
+
const state = regex.state;
|
|
1591
|
+
delete regex.state;
|
|
1592
|
+
let isIgnored = () => false;
|
|
1593
|
+
if (opts.ignore) {
|
|
1594
|
+
const ignoreOpts = {
|
|
1595
|
+
...options,
|
|
1596
|
+
ignore: null,
|
|
1597
|
+
onMatch: null,
|
|
1598
|
+
onResult: null
|
|
1599
|
+
};
|
|
1600
|
+
isIgnored = picomatch$2(opts.ignore, ignoreOpts, returnState);
|
|
1601
|
+
}
|
|
1602
|
+
const matcher = (input, returnObject = false) => {
|
|
1603
|
+
const { isMatch, match, output } = picomatch$2.test(input, regex, options, {
|
|
1604
|
+
glob,
|
|
1605
|
+
posix
|
|
1606
|
+
});
|
|
1607
|
+
const result = {
|
|
1608
|
+
glob,
|
|
1609
|
+
state,
|
|
1610
|
+
regex,
|
|
1611
|
+
posix,
|
|
1612
|
+
input,
|
|
1613
|
+
output,
|
|
1614
|
+
match,
|
|
1615
|
+
isMatch
|
|
1616
|
+
};
|
|
1617
|
+
if (typeof opts.onResult === "function") {
|
|
1618
|
+
opts.onResult(result);
|
|
1619
|
+
}
|
|
1620
|
+
if (isMatch === false) {
|
|
1621
|
+
result.isMatch = false;
|
|
1622
|
+
return returnObject ? result : false;
|
|
1623
|
+
}
|
|
1624
|
+
if (isIgnored(input)) {
|
|
1625
|
+
if (typeof opts.onIgnore === "function") {
|
|
1626
|
+
opts.onIgnore(result);
|
|
1627
|
+
}
|
|
1628
|
+
result.isMatch = false;
|
|
1629
|
+
return returnObject ? result : false;
|
|
1630
|
+
}
|
|
1631
|
+
if (typeof opts.onMatch === "function") {
|
|
1632
|
+
opts.onMatch(result);
|
|
1633
|
+
}
|
|
1634
|
+
return returnObject ? result : true;
|
|
1635
|
+
};
|
|
1636
|
+
if (returnState) {
|
|
1637
|
+
matcher.state = state;
|
|
1638
|
+
}
|
|
1639
|
+
return matcher;
|
|
1640
|
+
};
|
|
1641
|
+
/**
|
|
1642
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
1643
|
+
* `picomatch()` function to test the input string.
|
|
1644
|
+
*
|
|
1645
|
+
* ```js
|
|
1646
|
+
* const picomatch = require('picomatch');
|
|
1647
|
+
* // picomatch.test(input, regex[, options]);
|
|
1648
|
+
*
|
|
1649
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
1650
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
1651
|
+
* ```
|
|
1652
|
+
* @param {String} `input` String to test.
|
|
1653
|
+
* @param {RegExp} `regex`
|
|
1654
|
+
* @return {Object} Returns an object with matching info.
|
|
1655
|
+
* @api public
|
|
1656
|
+
*/
|
|
1657
|
+
picomatch$2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1658
|
+
if (typeof input !== "string") {
|
|
1659
|
+
throw new TypeError("Expected input to be a string");
|
|
1660
|
+
}
|
|
1661
|
+
if (input === "") {
|
|
1662
|
+
return {
|
|
1663
|
+
isMatch: false,
|
|
1664
|
+
output: ""
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
const opts = options || {};
|
|
1668
|
+
const format = opts.format || (posix ? utils$1.toPosixSlashes : null);
|
|
1669
|
+
let match = input === glob;
|
|
1670
|
+
let output = match && format ? format(input) : input;
|
|
1671
|
+
if (match === false) {
|
|
1672
|
+
output = format ? format(input) : input;
|
|
1673
|
+
match = output === glob;
|
|
1674
|
+
}
|
|
1675
|
+
if (match === false || opts.capture === true) {
|
|
1676
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1677
|
+
match = picomatch$2.matchBase(input, regex, options, posix);
|
|
1678
|
+
} else {
|
|
1679
|
+
match = regex.exec(output);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
return {
|
|
1683
|
+
isMatch: Boolean(match),
|
|
1684
|
+
match,
|
|
1685
|
+
output
|
|
1686
|
+
};
|
|
1687
|
+
};
|
|
1688
|
+
/**
|
|
1689
|
+
* Match the basename of a filepath.
|
|
1690
|
+
*
|
|
1691
|
+
* ```js
|
|
1692
|
+
* const picomatch = require('picomatch');
|
|
1693
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
1694
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
1695
|
+
* ```
|
|
1696
|
+
* @param {String} `input` String to test.
|
|
1697
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
1698
|
+
* @return {Boolean}
|
|
1699
|
+
* @api public
|
|
1700
|
+
*/
|
|
1701
|
+
picomatch$2.matchBase = (input, glob, options) => {
|
|
1702
|
+
const regex = glob instanceof RegExp ? glob : picomatch$2.makeRe(glob, options);
|
|
1703
|
+
return regex.test(utils$1.basename(input));
|
|
1704
|
+
};
|
|
1705
|
+
/**
|
|
1706
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
1707
|
+
*
|
|
1708
|
+
* ```js
|
|
1709
|
+
* const picomatch = require('picomatch');
|
|
1710
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
1711
|
+
*
|
|
1712
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
1713
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
1714
|
+
* ```
|
|
1715
|
+
* @param {String|Array} str The string to test.
|
|
1716
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
1717
|
+
* @param {Object} [options] See available [options](#options).
|
|
1718
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
1719
|
+
* @api public
|
|
1720
|
+
*/
|
|
1721
|
+
picomatch$2.isMatch = (str, patterns, options) => picomatch$2(patterns, options)(str);
|
|
1722
|
+
/**
|
|
1723
|
+
* Parse a glob pattern to create the source string for a regular
|
|
1724
|
+
* expression.
|
|
1725
|
+
*
|
|
1726
|
+
* ```js
|
|
1727
|
+
* const picomatch = require('picomatch');
|
|
1728
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
1729
|
+
* ```
|
|
1730
|
+
* @param {String} `pattern`
|
|
1731
|
+
* @param {Object} `options`
|
|
1732
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
1733
|
+
* @api public
|
|
1734
|
+
*/
|
|
1735
|
+
picomatch$2.parse = (pattern, options) => {
|
|
1736
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch$2.parse(p, options));
|
|
1737
|
+
return parse$2(pattern, {
|
|
1738
|
+
...options,
|
|
1739
|
+
fastpaths: false
|
|
1740
|
+
});
|
|
1741
|
+
};
|
|
1742
|
+
/**
|
|
1743
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
1744
|
+
*
|
|
1745
|
+
* ```js
|
|
1746
|
+
* const picomatch = require('picomatch');
|
|
1747
|
+
* // picomatch.scan(input[, options]);
|
|
1748
|
+
*
|
|
1749
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
1750
|
+
* console.log(result);
|
|
1751
|
+
* { prefix: '!./',
|
|
1752
|
+
* input: '!./foo/*.js',
|
|
1753
|
+
* start: 3,
|
|
1754
|
+
* base: 'foo',
|
|
1755
|
+
* glob: '*.js',
|
|
1756
|
+
* isBrace: false,
|
|
1757
|
+
* isBracket: false,
|
|
1758
|
+
* isGlob: true,
|
|
1759
|
+
* isExtglob: false,
|
|
1760
|
+
* isGlobstar: false,
|
|
1761
|
+
* negated: true }
|
|
1762
|
+
* ```
|
|
1763
|
+
* @param {String} `input` Glob pattern to scan.
|
|
1764
|
+
* @param {Object} `options`
|
|
1765
|
+
* @return {Object} Returns an object with
|
|
1766
|
+
* @api public
|
|
1767
|
+
*/
|
|
1768
|
+
picomatch$2.scan = (input, options) => scan(input, options);
|
|
1769
|
+
/**
|
|
1770
|
+
* Compile a regular expression from the `state` object returned by the
|
|
1771
|
+
* [parse()](#parse) method.
|
|
1772
|
+
*
|
|
1773
|
+
* @param {Object} `state`
|
|
1774
|
+
* @param {Object} `options`
|
|
1775
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
1776
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
1777
|
+
* @return {RegExp}
|
|
1778
|
+
* @api public
|
|
1779
|
+
*/
|
|
1780
|
+
picomatch$2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1781
|
+
if (returnOutput === true) {
|
|
1782
|
+
return state.output;
|
|
1783
|
+
}
|
|
1784
|
+
const opts = options || {};
|
|
1785
|
+
const prepend = opts.contains ? "" : "^";
|
|
1786
|
+
const append = opts.contains ? "" : "$";
|
|
1787
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1788
|
+
if (state && state.negated === true) {
|
|
1789
|
+
source = `^(?!${source}).*$`;
|
|
1790
|
+
}
|
|
1791
|
+
const regex = picomatch$2.toRegex(source, options);
|
|
1792
|
+
if (returnState === true) {
|
|
1793
|
+
regex.state = state;
|
|
1794
|
+
}
|
|
1795
|
+
return regex;
|
|
1796
|
+
};
|
|
1797
|
+
/**
|
|
1798
|
+
* Create a regular expression from a parsed glob pattern.
|
|
1799
|
+
*
|
|
1800
|
+
* ```js
|
|
1801
|
+
* const picomatch = require('picomatch');
|
|
1802
|
+
* const state = picomatch.parse('*.js');
|
|
1803
|
+
* // picomatch.compileRe(state[, options]);
|
|
1804
|
+
*
|
|
1805
|
+
* console.log(picomatch.compileRe(state));
|
|
1806
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
1807
|
+
* ```
|
|
1808
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
1809
|
+
* @param {Object} `options`
|
|
1810
|
+
* @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
|
1811
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
1812
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
1813
|
+
* @api public
|
|
1814
|
+
*/
|
|
1815
|
+
picomatch$2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1816
|
+
if (!input || typeof input !== "string") {
|
|
1817
|
+
throw new TypeError("Expected a non-empty string");
|
|
1818
|
+
}
|
|
1819
|
+
let parsed = {
|
|
1820
|
+
negated: false,
|
|
1821
|
+
fastpaths: true
|
|
1822
|
+
};
|
|
1823
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1824
|
+
parsed.output = parse$2.fastpaths(input, options);
|
|
1825
|
+
}
|
|
1826
|
+
if (!parsed.output) {
|
|
1827
|
+
parsed = parse$2(input, options);
|
|
1828
|
+
}
|
|
1829
|
+
return picomatch$2.compileRe(parsed, options, returnOutput, returnState);
|
|
1830
|
+
};
|
|
1831
|
+
/**
|
|
1832
|
+
* Create a regular expression from the given regex source string.
|
|
1833
|
+
*
|
|
1834
|
+
* ```js
|
|
1835
|
+
* const picomatch = require('picomatch');
|
|
1836
|
+
* // picomatch.toRegex(source[, options]);
|
|
1837
|
+
*
|
|
1838
|
+
* const { output } = picomatch.parse('*.js');
|
|
1839
|
+
* console.log(picomatch.toRegex(output));
|
|
1840
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
1841
|
+
* ```
|
|
1842
|
+
* @param {String} `source` Regular expression source string.
|
|
1843
|
+
* @param {Object} `options`
|
|
1844
|
+
* @return {RegExp}
|
|
1845
|
+
* @api public
|
|
1846
|
+
*/
|
|
1847
|
+
picomatch$2.toRegex = (source, options) => {
|
|
1848
|
+
try {
|
|
1849
|
+
const opts = options || {};
|
|
1850
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1851
|
+
} catch (err$8) {
|
|
1852
|
+
if (options && options.debug === true) throw err$8;
|
|
1853
|
+
return /$^/;
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
/**
|
|
1857
|
+
* Picomatch constants.
|
|
1858
|
+
* @return {Object}
|
|
1859
|
+
*/
|
|
1860
|
+
picomatch$2.constants = constants;
|
|
1861
|
+
/**
|
|
1862
|
+
* Expose "picomatch"
|
|
1863
|
+
*/
|
|
1864
|
+
module.exports = picomatch$2;
|
|
1865
|
+
}));
|
|
1866
|
+
|
|
1867
|
+
//#endregion
|
|
1868
|
+
//#region node_modules/picomatch/index.js
|
|
1869
|
+
var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1870
|
+
const pico = require_picomatch$1();
|
|
1871
|
+
const utils = require_utils();
|
|
1872
|
+
function picomatch$1(glob, options, returnState = false) {
|
|
1873
|
+
if (options && (options.windows === null || options.windows === undefined)) {
|
|
1874
|
+
options = {
|
|
1875
|
+
...options,
|
|
1876
|
+
windows: utils.isWindows()
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
return pico(glob, options, returnState);
|
|
1880
|
+
}
|
|
1881
|
+
Object.assign(picomatch$1, pico);
|
|
1882
|
+
module.exports = picomatch$1;
|
|
1883
|
+
}));
|
|
1884
|
+
|
|
1885
|
+
//#endregion
|
|
1886
|
+
//#region packages/codegen/src/type-filter.ts
|
|
1887
|
+
var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
|
|
1888
|
+
const compileRule = (rule) => {
|
|
1889
|
+
const matcher = (0, import_picomatch.default)(rule.pattern);
|
|
1890
|
+
const categories = rule.category ? Array.isArray(rule.category) ? rule.category : [rule.category] : null;
|
|
1891
|
+
return (context) => {
|
|
1892
|
+
if (categories && !categories.includes(context.category)) {
|
|
1893
|
+
return true;
|
|
1894
|
+
}
|
|
1895
|
+
return !matcher(context.name);
|
|
1896
|
+
};
|
|
1897
|
+
};
|
|
1898
|
+
const compileTypeFilter = (config) => {
|
|
1899
|
+
if (!config) {
|
|
1900
|
+
return () => true;
|
|
1901
|
+
}
|
|
1902
|
+
if (typeof config === "function") {
|
|
1903
|
+
return config;
|
|
1904
|
+
}
|
|
1905
|
+
const rules = config.exclude.map(compileRule);
|
|
1906
|
+
return (context) => rules.every((rule) => rule(context));
|
|
1907
|
+
};
|
|
1908
|
+
const buildExclusionSet = (filter, typeNames) => {
|
|
1909
|
+
const excluded = new Set();
|
|
1910
|
+
for (const [category, names] of typeNames) {
|
|
1911
|
+
for (const name of names) {
|
|
1912
|
+
if (!filter({
|
|
1913
|
+
name,
|
|
1914
|
+
category
|
|
1915
|
+
})) {
|
|
1916
|
+
excluded.add(name);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
return excluded;
|
|
1921
|
+
};
|
|
1922
|
+
|
|
1923
|
+
//#endregion
|
|
1924
|
+
//#region packages/codegen/src/generator.ts
|
|
1925
|
+
const builtinScalarTypes$1 = new Map([
|
|
1926
|
+
["ID", {
|
|
1927
|
+
input: "string",
|
|
1928
|
+
output: "string"
|
|
1929
|
+
}],
|
|
1930
|
+
["String", {
|
|
1931
|
+
input: "string",
|
|
1932
|
+
output: "string"
|
|
1933
|
+
}],
|
|
1934
|
+
["Int", {
|
|
1935
|
+
input: "number",
|
|
1936
|
+
output: "number"
|
|
1937
|
+
}],
|
|
1938
|
+
["Float", {
|
|
1939
|
+
input: "number",
|
|
1940
|
+
output: "number"
|
|
1941
|
+
}],
|
|
1942
|
+
["Boolean", {
|
|
1943
|
+
input: "boolean",
|
|
1944
|
+
output: "boolean"
|
|
1945
|
+
}]
|
|
1946
|
+
]);
|
|
1947
|
+
const ensureRecord = (collection, key, factory) => {
|
|
1948
|
+
const existing = collection.get(key);
|
|
1949
|
+
if (existing) {
|
|
1950
|
+
return existing;
|
|
1951
|
+
}
|
|
1952
|
+
const created = factory(key);
|
|
1953
|
+
collection.set(key, created);
|
|
1954
|
+
return created;
|
|
1955
|
+
};
|
|
1956
|
+
const addObjectFields = (target, fields) => {
|
|
1957
|
+
if (!fields) {
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
for (const field of fields) {
|
|
1961
|
+
target.set(field.name.value, field);
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
const addInputFields = (target, fields) => {
|
|
1965
|
+
if (!fields) {
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
for (const field of fields) {
|
|
1969
|
+
target.set(field.name.value, field);
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
const addEnumValues = (target, values) => {
|
|
1973
|
+
if (!values) {
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1976
|
+
for (const value of values) {
|
|
1977
|
+
target.set(value.name.value, value);
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
const addUnionMembers = (target, members) => {
|
|
1981
|
+
if (!members) {
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
for (const member of members) {
|
|
1985
|
+
target.set(member.name.value, member);
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
const mergeDirectives = (existing, incoming, precedence) => {
|
|
1989
|
+
const current = existing ?? [];
|
|
1990
|
+
const next = incoming ? Array.from(incoming) : [];
|
|
1991
|
+
return precedence === "definition" ? [...next, ...current] : [...current, ...next];
|
|
1992
|
+
};
|
|
1993
|
+
const updateOperationTypes = (operationTypes, definition) => {
|
|
1994
|
+
for (const operation of definition.operationTypes ?? []) {
|
|
1995
|
+
const typeName = operation.type.name.value;
|
|
1996
|
+
switch (operation.operation) {
|
|
1997
|
+
case "query":
|
|
1998
|
+
operationTypes.query = typeName;
|
|
1999
|
+
break;
|
|
2000
|
+
case "mutation":
|
|
2001
|
+
operationTypes.mutation = typeName;
|
|
2002
|
+
break;
|
|
2003
|
+
case "subscription":
|
|
2004
|
+
operationTypes.subscription = typeName;
|
|
2005
|
+
break;
|
|
2006
|
+
default: break;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
const addDirectiveArgs = (target, args) => {
|
|
2011
|
+
if (!args) {
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
for (const arg of args) {
|
|
2015
|
+
target.set(arg.name.value, arg);
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
const createSchemaIndex = (document) => {
|
|
2019
|
+
const objects = new Map();
|
|
2020
|
+
const inputs = new Map();
|
|
2021
|
+
const enums = new Map();
|
|
2022
|
+
const unions = new Map();
|
|
2023
|
+
const scalars = new Map();
|
|
2024
|
+
const directives = new Map();
|
|
2025
|
+
const operationTypes = {};
|
|
2026
|
+
for (const definition of document.definitions) {
|
|
2027
|
+
switch (definition.kind) {
|
|
2028
|
+
case graphql.Kind.OBJECT_TYPE_DEFINITION:
|
|
2029
|
+
case graphql.Kind.OBJECT_TYPE_EXTENSION: {
|
|
2030
|
+
const precedence = definition.kind === graphql.Kind.OBJECT_TYPE_DEFINITION ? "definition" : "extension";
|
|
2031
|
+
const record = ensureRecord(objects, definition.name.value, (name) => ({
|
|
2032
|
+
name,
|
|
2033
|
+
fields: new Map(),
|
|
2034
|
+
directives: []
|
|
2035
|
+
}));
|
|
2036
|
+
addObjectFields(record.fields, definition.fields);
|
|
2037
|
+
record.directives = mergeDirectives(record.directives, definition.directives, precedence);
|
|
2038
|
+
break;
|
|
2039
|
+
}
|
|
2040
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
2041
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION: {
|
|
2042
|
+
const precedence = definition.kind === graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION ? "definition" : "extension";
|
|
2043
|
+
const record = ensureRecord(inputs, definition.name.value, (name) => ({
|
|
2044
|
+
name,
|
|
2045
|
+
fields: new Map(),
|
|
2046
|
+
directives: []
|
|
2047
|
+
}));
|
|
2048
|
+
addInputFields(record.fields, definition.fields);
|
|
2049
|
+
record.directives = mergeDirectives(record.directives, definition.directives, precedence);
|
|
2050
|
+
break;
|
|
2051
|
+
}
|
|
2052
|
+
case graphql.Kind.ENUM_TYPE_DEFINITION:
|
|
2053
|
+
case graphql.Kind.ENUM_TYPE_EXTENSION: {
|
|
2054
|
+
const precedence = definition.kind === graphql.Kind.ENUM_TYPE_DEFINITION ? "definition" : "extension";
|
|
2055
|
+
const record = ensureRecord(enums, definition.name.value, (name) => ({
|
|
2056
|
+
name,
|
|
2057
|
+
values: new Map(),
|
|
2058
|
+
directives: []
|
|
2059
|
+
}));
|
|
2060
|
+
addEnumValues(record.values, definition.values);
|
|
2061
|
+
record.directives = mergeDirectives(record.directives, definition.directives, precedence);
|
|
2062
|
+
break;
|
|
2063
|
+
}
|
|
2064
|
+
case graphql.Kind.UNION_TYPE_DEFINITION:
|
|
2065
|
+
case graphql.Kind.UNION_TYPE_EXTENSION: {
|
|
2066
|
+
const precedence = definition.kind === graphql.Kind.UNION_TYPE_DEFINITION ? "definition" : "extension";
|
|
2067
|
+
const record = ensureRecord(unions, definition.name.value, (name) => ({
|
|
2068
|
+
name,
|
|
2069
|
+
members: new Map(),
|
|
2070
|
+
directives: []
|
|
2071
|
+
}));
|
|
2072
|
+
addUnionMembers(record.members, definition.types);
|
|
2073
|
+
record.directives = mergeDirectives(record.directives, definition.directives, precedence);
|
|
2074
|
+
break;
|
|
2075
|
+
}
|
|
2076
|
+
case graphql.Kind.SCALAR_TYPE_DEFINITION:
|
|
2077
|
+
case graphql.Kind.SCALAR_TYPE_EXTENSION: {
|
|
2078
|
+
const precedence = definition.kind === graphql.Kind.SCALAR_TYPE_DEFINITION ? "definition" : "extension";
|
|
2079
|
+
const record = ensureRecord(scalars, definition.name.value, (name) => ({
|
|
2080
|
+
name,
|
|
2081
|
+
directives: []
|
|
2082
|
+
}));
|
|
2083
|
+
record.directives = mergeDirectives(record.directives, definition.directives, precedence);
|
|
2084
|
+
break;
|
|
2085
|
+
}
|
|
2086
|
+
case graphql.Kind.DIRECTIVE_DEFINITION: {
|
|
2087
|
+
const name = definition.name.value;
|
|
2088
|
+
if (name === "skip" || name === "include" || name === "deprecated" || name === "specifiedBy") {
|
|
2089
|
+
break;
|
|
2090
|
+
}
|
|
2091
|
+
const args = new Map();
|
|
2092
|
+
addDirectiveArgs(args, definition.arguments);
|
|
2093
|
+
directives.set(name, {
|
|
2094
|
+
name,
|
|
2095
|
+
locations: definition.locations.map((loc) => loc.value),
|
|
2096
|
+
args,
|
|
2097
|
+
isRepeatable: definition.repeatable
|
|
2098
|
+
});
|
|
2099
|
+
break;
|
|
2100
|
+
}
|
|
2101
|
+
case graphql.Kind.SCHEMA_DEFINITION:
|
|
2102
|
+
case graphql.Kind.SCHEMA_EXTENSION:
|
|
2103
|
+
updateOperationTypes(operationTypes, definition);
|
|
2104
|
+
break;
|
|
2105
|
+
default: break;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (!operationTypes.query && objects.has("Query")) {
|
|
2109
|
+
operationTypes.query = "Query";
|
|
2110
|
+
}
|
|
2111
|
+
if (!operationTypes.mutation && objects.has("Mutation")) {
|
|
2112
|
+
operationTypes.mutation = "Mutation";
|
|
2113
|
+
}
|
|
2114
|
+
if (!operationTypes.subscription && objects.has("Subscription")) {
|
|
2115
|
+
operationTypes.subscription = "Subscription";
|
|
2116
|
+
}
|
|
2117
|
+
return {
|
|
2118
|
+
objects,
|
|
2119
|
+
inputs,
|
|
2120
|
+
enums,
|
|
2121
|
+
unions,
|
|
2122
|
+
scalars,
|
|
2123
|
+
directives,
|
|
2124
|
+
operationTypes
|
|
2125
|
+
};
|
|
2126
|
+
};
|
|
2127
|
+
const collectTypeLevels = (type, nonNull = false, levels = []) => {
|
|
2128
|
+
if (type.kind === graphql.Kind.NON_NULL_TYPE) {
|
|
2129
|
+
return collectTypeLevels(type.type, true, levels);
|
|
2130
|
+
}
|
|
2131
|
+
if (type.kind === graphql.Kind.LIST_TYPE) {
|
|
2132
|
+
levels.push({
|
|
2133
|
+
kind: "list",
|
|
2134
|
+
nonNull
|
|
2135
|
+
});
|
|
2136
|
+
return collectTypeLevels(type.type, false, levels);
|
|
2137
|
+
}
|
|
2138
|
+
levels.push({
|
|
2139
|
+
kind: "named",
|
|
2140
|
+
nonNull
|
|
2141
|
+
});
|
|
2142
|
+
return {
|
|
2143
|
+
name: type.name.value,
|
|
2144
|
+
levels
|
|
2145
|
+
};
|
|
2146
|
+
};
|
|
2147
|
+
const buildTypeModifier = (levels) => {
|
|
2148
|
+
let modifier = "?";
|
|
2149
|
+
for (const level of levels.slice().reverse()) {
|
|
2150
|
+
if (level.kind === "named") {
|
|
2151
|
+
modifier = level.nonNull ? "!" : "?";
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2154
|
+
const listSuffix = level.nonNull ? "[]!" : "[]?";
|
|
2155
|
+
modifier = `${modifier}${listSuffix}`;
|
|
2156
|
+
}
|
|
2157
|
+
return modifier;
|
|
2158
|
+
};
|
|
2159
|
+
const parseTypeReference = (type) => {
|
|
2160
|
+
const { name, levels } = collectTypeLevels(type);
|
|
2161
|
+
return {
|
|
2162
|
+
name,
|
|
2163
|
+
modifier: buildTypeModifier(levels)
|
|
2164
|
+
};
|
|
2165
|
+
};
|
|
2166
|
+
const isScalarName$1 = (schema, name) => builtinScalarTypes$1.has(name) || schema.scalars.has(name);
|
|
2167
|
+
const isEnumName$1 = (schema, name) => schema.enums.has(name);
|
|
2168
|
+
const _isInputName = (schema, name) => schema.inputs.has(name);
|
|
2169
|
+
const isUnionName = (schema, name) => schema.unions.has(name);
|
|
2170
|
+
const isObjectName = (schema, name) => schema.objects.has(name);
|
|
2171
|
+
/**
|
|
2172
|
+
* Maps type kind to deferred specifier prefix character.
|
|
2173
|
+
*/
|
|
2174
|
+
const inputKindToChar = (kind) => {
|
|
2175
|
+
switch (kind) {
|
|
2176
|
+
case "scalar": return "s";
|
|
2177
|
+
case "enum": return "e";
|
|
2178
|
+
case "input": return "i";
|
|
2179
|
+
case "excluded": return "x";
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
const renderInputRef = (schema, definition, excluded) => {
|
|
2183
|
+
const { name, modifier } = parseTypeReference(definition.type);
|
|
2184
|
+
const defaultValue = definition.defaultValue;
|
|
2185
|
+
if (excluded.has(name)) {
|
|
2186
|
+
const defaultSuffix$1 = defaultValue ? "|D" : "";
|
|
2187
|
+
return `"x|${name}|${modifier}${defaultSuffix$1}"`;
|
|
2188
|
+
}
|
|
2189
|
+
let kind;
|
|
2190
|
+
if (isScalarName$1(schema, name)) {
|
|
2191
|
+
kind = "scalar";
|
|
2192
|
+
} else if (isEnumName$1(schema, name)) {
|
|
2193
|
+
kind = "enum";
|
|
2194
|
+
} else {
|
|
2195
|
+
kind = "input";
|
|
2196
|
+
}
|
|
2197
|
+
const kindChar = inputKindToChar(kind);
|
|
2198
|
+
const defaultSuffix = defaultValue ? "|D" : "";
|
|
2199
|
+
return `"${kindChar}|${name}|${modifier}${defaultSuffix}"`;
|
|
2200
|
+
};
|
|
2201
|
+
/**
|
|
2202
|
+
* Maps output type kind to deferred specifier prefix character.
|
|
2203
|
+
*/
|
|
2204
|
+
const outputKindToChar = (kind) => {
|
|
2205
|
+
switch (kind) {
|
|
2206
|
+
case "scalar": return "s";
|
|
2207
|
+
case "enum": return "e";
|
|
2208
|
+
case "object": return "o";
|
|
2209
|
+
case "union": return "u";
|
|
2210
|
+
case "excluded": return "x";
|
|
2211
|
+
}
|
|
2212
|
+
};
|
|
2213
|
+
/**
|
|
2214
|
+
* Render arguments as object format for DeferredOutputFieldWithArgs.
|
|
2215
|
+
* Returns array of "argName: \"spec\"" entries.
|
|
2216
|
+
*/
|
|
2217
|
+
const renderArgumentsObjectEntries = (schema, args, excluded) => {
|
|
2218
|
+
return [...args].sort((left, right) => left.name.value.localeCompare(right.name.value)).map((arg) => {
|
|
2219
|
+
const { name, modifier } = parseTypeReference(arg.type);
|
|
2220
|
+
if (excluded.has(name)) {
|
|
2221
|
+
return null;
|
|
2222
|
+
}
|
|
2223
|
+
let kind;
|
|
2224
|
+
if (isScalarName$1(schema, name)) {
|
|
2225
|
+
kind = "scalar";
|
|
2226
|
+
} else if (isEnumName$1(schema, name)) {
|
|
2227
|
+
kind = "enum";
|
|
2228
|
+
} else {
|
|
2229
|
+
kind = "input";
|
|
2230
|
+
}
|
|
2231
|
+
const kindChar = inputKindToChar(kind);
|
|
2232
|
+
const defaultSuffix = arg.defaultValue ? "|D" : "";
|
|
2233
|
+
return `${arg.name.value}: "${kindChar}|${name}|${modifier}${defaultSuffix}"`;
|
|
2234
|
+
}).filter((spec) => spec !== null);
|
|
2235
|
+
};
|
|
2236
|
+
const renderArgumentMap = (schema, args, excluded) => {
|
|
2237
|
+
const entries = [...args ?? []].sort((left, right) => left.name.value.localeCompare(right.name.value)).map((arg) => `${arg.name.value}: ${renderInputRef(schema, arg, excluded)}`);
|
|
2238
|
+
return renderPropertyLines({
|
|
2239
|
+
entries,
|
|
2240
|
+
indentSize: 8
|
|
2241
|
+
});
|
|
2242
|
+
};
|
|
2243
|
+
const renderOutputRef = (schema, type, args, excluded) => {
|
|
2244
|
+
const { name, modifier } = parseTypeReference(type);
|
|
2245
|
+
if (excluded.has(name)) {
|
|
2246
|
+
const argumentMap = renderArgumentMap(schema, args, excluded);
|
|
2247
|
+
return `{ spec: "x|${name}|${modifier}", arguments: ${argumentMap} }`;
|
|
2248
|
+
}
|
|
2249
|
+
let kind;
|
|
2250
|
+
if (isScalarName$1(schema, name)) {
|
|
2251
|
+
kind = "scalar";
|
|
2252
|
+
} else if (isEnumName$1(schema, name)) {
|
|
2253
|
+
kind = "enum";
|
|
2254
|
+
} else if (isUnionName(schema, name)) {
|
|
2255
|
+
kind = "union";
|
|
2256
|
+
} else if (isObjectName(schema, name)) {
|
|
2257
|
+
kind = "object";
|
|
2258
|
+
} else {
|
|
2259
|
+
kind = "scalar";
|
|
2260
|
+
}
|
|
2261
|
+
const kindChar = outputKindToChar(kind);
|
|
2262
|
+
const spec = `${kindChar}|${name}|${modifier}`;
|
|
2263
|
+
if (args && args.length > 0) {
|
|
2264
|
+
const argEntries = renderArgumentsObjectEntries(schema, args, excluded);
|
|
2265
|
+
if (argEntries.length > 0) {
|
|
2266
|
+
return `{ spec: "${spec}", arguments: { ${argEntries.join(", ")} } }`;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return `{ spec: "${spec}", arguments: {} }`;
|
|
2270
|
+
};
|
|
2271
|
+
const renderPropertyLines = ({ entries, indentSize }) => {
|
|
2272
|
+
if (entries.length === 0) {
|
|
2273
|
+
return "{}";
|
|
2274
|
+
}
|
|
2275
|
+
const indent = " ".repeat(indentSize);
|
|
2276
|
+
const lastIndent = " ".repeat(indentSize - 2);
|
|
2277
|
+
return [
|
|
2278
|
+
"{",
|
|
2279
|
+
`${indent}${entries.join(`,\n${indent}`)},`,
|
|
2280
|
+
`${lastIndent}}`
|
|
2281
|
+
].join(`\n`);
|
|
2282
|
+
};
|
|
2283
|
+
const renderObjectFields = (schema, fields, excluded) => {
|
|
2284
|
+
const entries = Array.from(fields.values()).sort((left, right) => left.name.value.localeCompare(right.name.value)).map((field) => `${field.name.value}: ${renderOutputRef(schema, field.type, field.arguments, excluded)}`);
|
|
2285
|
+
return renderPropertyLines({
|
|
2286
|
+
entries,
|
|
2287
|
+
indentSize: 6
|
|
2288
|
+
});
|
|
2289
|
+
};
|
|
2290
|
+
const renderInputFields = (schema, fields, excluded) => {
|
|
2291
|
+
const entries = Array.from(fields.values()).sort((left, right) => left.name.value.localeCompare(right.name.value)).map((field) => `${field.name.value}: ${renderInputRef(schema, field, excluded)}`);
|
|
2292
|
+
return renderPropertyLines({
|
|
2293
|
+
entries,
|
|
2294
|
+
indentSize: 6
|
|
2295
|
+
});
|
|
2296
|
+
};
|
|
2297
|
+
const renderScalarVar = (schemaName, record) => {
|
|
2298
|
+
const typeInfo = builtinScalarTypes$1.get(record.name) ?? {
|
|
2299
|
+
input: "string",
|
|
2300
|
+
output: "string"
|
|
2301
|
+
};
|
|
2302
|
+
return `const scalar_${schemaName}_${record.name} = { name: "${record.name}", $type: {} as { input: ${typeInfo.input}; output: ${typeInfo.output}; inputProfile: { kind: "scalar"; name: "${record.name}"; value: ${typeInfo.input} }; outputProfile: { kind: "scalar"; name: "${record.name}"; value: ${typeInfo.output} } } } as const;`;
|
|
2303
|
+
};
|
|
2304
|
+
const renderEnumVar = (schemaName, record) => {
|
|
2305
|
+
const valueNames = Array.from(record.values.values()).sort((left, right) => left.name.value.localeCompare(right.name.value)).map((value) => value.name.value);
|
|
2306
|
+
const valuesObj = valueNames.length === 0 ? "{}" : `{ ${valueNames.map((v) => `${v}: true`).join(", ")} }`;
|
|
2307
|
+
const valueUnion = valueNames.length === 0 ? "never" : valueNames.map((v) => `"${v}"`).join(" | ");
|
|
2308
|
+
return `const enum_${schemaName}_${record.name} = defineEnum<"${record.name}", ${valueUnion}>("${record.name}", ${valuesObj});`;
|
|
2309
|
+
};
|
|
2310
|
+
const renderInputVar = (schemaName, schema, record, excluded) => {
|
|
2311
|
+
const fields = renderInputFields(schema, record.fields, excluded);
|
|
2312
|
+
return `const input_${schemaName}_${record.name} = { name: "${record.name}", fields: ${fields} } as const;`;
|
|
2313
|
+
};
|
|
2314
|
+
const renderObjectVar = (schemaName, schema, record, excluded) => {
|
|
2315
|
+
const fields = renderObjectFields(schema, record.fields, excluded);
|
|
2316
|
+
return `const object_${schemaName}_${record.name} = { name: "${record.name}", fields: ${fields} } as const;`;
|
|
2317
|
+
};
|
|
2318
|
+
const renderUnionVar = (schemaName, record, excluded) => {
|
|
2319
|
+
const memberNames = Array.from(record.members.values()).filter((member) => !excluded.has(member.name.value)).sort((left, right) => left.name.value.localeCompare(right.name.value)).map((member) => member.name.value);
|
|
2320
|
+
const typesObj = memberNames.length === 0 ? "{}" : `{ ${memberNames.map((m) => `${m}: true`).join(", ")} }`;
|
|
2321
|
+
return `const union_${schemaName}_${record.name} = { name: "${record.name}", types: ${typesObj} } as const;`;
|
|
2322
|
+
};
|
|
2323
|
+
const collectObjectTypeNames = (schema) => Array.from(schema.objects.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2324
|
+
const collectInputTypeNames = (schema) => Array.from(schema.inputs.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2325
|
+
const collectEnumTypeNames = (schema) => Array.from(schema.enums.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2326
|
+
const collectUnionTypeNames = (schema) => Array.from(schema.unions.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2327
|
+
const collectScalarNames = (schema) => Array.from(schema.scalars.keys()).filter((name) => !name.startsWith("__")).sort((left, right) => left.localeCompare(right));
|
|
2328
|
+
const collectDirectiveNames = (schema) => Array.from(schema.directives.keys()).sort((left, right) => left.localeCompare(right));
|
|
2329
|
+
const renderInputTypeMethod = (factoryVar, kind, typeName) => `${typeName}: ${factoryVar}("${kind}", "${typeName}")`;
|
|
2330
|
+
const renderInputTypeMethods = (schema, factoryVar, excluded) => {
|
|
2331
|
+
const scalarMethods = Array.from(builtinScalarTypes$1.keys()).concat(collectScalarNames(schema).filter((name) => !builtinScalarTypes$1.has(name))).filter((name) => !excluded.has(name)).map((name) => renderInputTypeMethod(factoryVar, "scalar", name));
|
|
2332
|
+
const enumMethods = collectEnumTypeNames(schema).filter((name) => !excluded.has(name)).map((name) => renderInputTypeMethod(factoryVar, "enum", name));
|
|
2333
|
+
const inputMethods = collectInputTypeNames(schema).filter((name) => !excluded.has(name)).map((name) => renderInputTypeMethod(factoryVar, "input", name));
|
|
2334
|
+
const allMethods = [
|
|
2335
|
+
...scalarMethods,
|
|
2336
|
+
...enumMethods,
|
|
2337
|
+
...inputMethods
|
|
2338
|
+
].sort((left, right) => {
|
|
2339
|
+
const leftName = left.split(":")[0] ?? "";
|
|
2340
|
+
const rightName = right.split(":")[0] ?? "";
|
|
2341
|
+
return leftName.localeCompare(rightName);
|
|
2342
|
+
});
|
|
2343
|
+
return renderPropertyLines({
|
|
2344
|
+
entries: allMethods,
|
|
2345
|
+
indentSize: 2
|
|
2346
|
+
});
|
|
2347
|
+
};
|
|
2348
|
+
/**
|
|
2349
|
+
* Renders an input reference as a deferred string for directive arguments.
|
|
2350
|
+
* Format: "{kindChar}|{name}|{modifier}"
|
|
2351
|
+
*/
|
|
2352
|
+
const renderDeferredDirectiveArgRef = (schema, definition, excluded) => {
|
|
2353
|
+
const { name, modifier } = parseTypeReference(definition.type);
|
|
2354
|
+
if (excluded.has(name)) {
|
|
2355
|
+
return null;
|
|
2356
|
+
}
|
|
2357
|
+
let kind;
|
|
2358
|
+
if (isScalarName$1(schema, name)) {
|
|
2359
|
+
kind = "scalar";
|
|
2360
|
+
} else if (isEnumName$1(schema, name)) {
|
|
2361
|
+
kind = "enum";
|
|
2362
|
+
} else {
|
|
2363
|
+
kind = "input";
|
|
2364
|
+
}
|
|
2365
|
+
const kindChar = inputKindToChar(kind);
|
|
2366
|
+
return `"${kindChar}|${name}|${modifier}"`;
|
|
2367
|
+
};
|
|
2368
|
+
/**
|
|
2369
|
+
* Renders argument specifiers for a directive.
|
|
2370
|
+
* Returns null if the directive has no arguments.
|
|
2371
|
+
* Uses deferred string format for consistency with other type specifiers.
|
|
2372
|
+
*/
|
|
2373
|
+
const renderDirectiveArgsSpec = (schema, args, excluded) => {
|
|
2374
|
+
if (args.size === 0) return null;
|
|
2375
|
+
const entries = Array.from(args.values()).sort((left, right) => left.name.value.localeCompare(right.name.value)).map((arg) => {
|
|
2376
|
+
const ref = renderDeferredDirectiveArgRef(schema, arg, excluded);
|
|
2377
|
+
return ref ? `${arg.name.value}: ${ref}` : null;
|
|
2378
|
+
}).filter((entry) => entry !== null);
|
|
2379
|
+
if (entries.length === 0) return null;
|
|
2380
|
+
return renderPropertyLines({
|
|
2381
|
+
entries,
|
|
2382
|
+
indentSize: 4
|
|
2383
|
+
});
|
|
2384
|
+
};
|
|
2385
|
+
const renderDirectiveMethod = (schema, record, excluded) => {
|
|
2386
|
+
const locationsJson = JSON.stringify(record.locations);
|
|
2387
|
+
const argsSpec = renderDirectiveArgsSpec(schema, record.args, excluded);
|
|
2388
|
+
if (argsSpec === null) {
|
|
2389
|
+
return `${record.name}: createDirectiveMethod("${record.name}", ${locationsJson} as const)`;
|
|
2390
|
+
}
|
|
2391
|
+
return `${record.name}: createTypedDirectiveMethod("${record.name}", ${locationsJson} as const, ${argsSpec})`;
|
|
2392
|
+
};
|
|
2393
|
+
const renderDirectiveMethods = (schema, excluded) => {
|
|
2394
|
+
const directiveNames = collectDirectiveNames(schema);
|
|
2395
|
+
if (directiveNames.length === 0) {
|
|
2396
|
+
return "{}";
|
|
2397
|
+
}
|
|
2398
|
+
const methods = directiveNames.map((name) => {
|
|
2399
|
+
const record = schema.directives.get(name);
|
|
2400
|
+
return record ? renderDirectiveMethod(schema, record, excluded) : null;
|
|
2401
|
+
}).filter((method) => method !== null);
|
|
2402
|
+
return renderPropertyLines({
|
|
2403
|
+
entries: methods,
|
|
2404
|
+
indentSize: 2
|
|
2405
|
+
});
|
|
2406
|
+
};
|
|
2407
|
+
/**
|
|
2408
|
+
* Generates the _internal-injects.ts module code.
|
|
2409
|
+
* This file contains only adapter imports (scalar, adapter) to keep it lightweight.
|
|
2410
|
+
* The heavy schema types remain in _internal.ts.
|
|
2411
|
+
*/
|
|
2412
|
+
const generateInjectsCode = (injection) => {
|
|
2413
|
+
const imports = [];
|
|
2414
|
+
const exports$1 = [];
|
|
2415
|
+
const typeExports = [];
|
|
2416
|
+
const importsByPath = new Map();
|
|
2417
|
+
for (const [schemaName, config] of injection) {
|
|
2418
|
+
const scalarAlias = `scalar_${schemaName}`;
|
|
2419
|
+
const scalarSpecifiers = importsByPath.get(config.scalarImportPath) ?? [];
|
|
2420
|
+
if (!importsByPath.has(config.scalarImportPath)) {
|
|
2421
|
+
importsByPath.set(config.scalarImportPath, scalarSpecifiers);
|
|
2422
|
+
}
|
|
2423
|
+
scalarSpecifiers.push(`scalar as ${scalarAlias}`);
|
|
2424
|
+
exports$1.push(`export { ${scalarAlias} };`);
|
|
2425
|
+
typeExports.push(`export type Scalar_${schemaName} = typeof ${scalarAlias};`);
|
|
2426
|
+
if (config.adapterImportPath) {
|
|
2427
|
+
const adapterAlias = `adapter_${schemaName}`;
|
|
2428
|
+
const adapterSpecifiers = importsByPath.get(config.adapterImportPath) ?? [];
|
|
2429
|
+
if (!importsByPath.has(config.adapterImportPath)) {
|
|
2430
|
+
importsByPath.set(config.adapterImportPath, adapterSpecifiers);
|
|
2431
|
+
}
|
|
2432
|
+
adapterSpecifiers.push(`adapter as ${adapterAlias}`);
|
|
2433
|
+
exports$1.push(`export { ${adapterAlias} };`);
|
|
2434
|
+
typeExports.push(`export type Adapter_${schemaName} = typeof ${adapterAlias} & { _?: never };`);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
for (const [path, specifiers] of importsByPath) {
|
|
2438
|
+
if (specifiers.length === 1) {
|
|
2439
|
+
imports.push(`import { ${specifiers[0]} } from "${path}";`);
|
|
2440
|
+
} else {
|
|
2441
|
+
imports.push(`import {\n ${specifiers.join(",\n ")},\n} from "${path}";`);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
return `\
|
|
2445
|
+
/**
|
|
2446
|
+
* Adapter injections for schema.
|
|
2447
|
+
* Separated to allow lightweight imports for prebuilt module.
|
|
2448
|
+
* @generated by @soda-gql/codegen
|
|
2449
|
+
*/
|
|
2450
|
+
|
|
2451
|
+
${imports.join("\n")}
|
|
2452
|
+
|
|
2453
|
+
// Value exports
|
|
2454
|
+
${exports$1.join("\n")}
|
|
2455
|
+
|
|
2456
|
+
// Type exports
|
|
2457
|
+
${typeExports.join("\n")}
|
|
2458
|
+
`;
|
|
2459
|
+
};
|
|
2460
|
+
const multiRuntimeTemplate = ($$) => {
|
|
2461
|
+
const imports = [];
|
|
2462
|
+
const scalarAliases = new Map();
|
|
2463
|
+
const adapterAliases = new Map();
|
|
2464
|
+
if ($$.injection.mode === "inject") {
|
|
2465
|
+
const injectsImports = [];
|
|
2466
|
+
for (const [schemaName, injection] of $$.injection.perSchema) {
|
|
2467
|
+
const scalarAlias = `scalar_${schemaName}`;
|
|
2468
|
+
scalarAliases.set(schemaName, scalarAlias);
|
|
2469
|
+
injectsImports.push(scalarAlias);
|
|
2470
|
+
if (injection.adapterImportPath) {
|
|
2471
|
+
const adapterAlias = `adapter_${schemaName}`;
|
|
2472
|
+
adapterAliases.set(schemaName, adapterAlias);
|
|
2473
|
+
injectsImports.push(adapterAlias);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
imports.push(`import { ${injectsImports.join(", ")} } from "${$$.injection.injectsModulePath}";`);
|
|
2477
|
+
}
|
|
2478
|
+
{
|
|
2479
|
+
const { importPaths } = $$.splitting;
|
|
2480
|
+
for (const [name, config] of Object.entries($$.schemas)) {
|
|
2481
|
+
if (config.enumNames.length > 0) {
|
|
2482
|
+
const enumImports = config.enumNames.map((n) => `enum_${name}_${n}`).join(", ");
|
|
2483
|
+
imports.push(`import { ${enumImports} } from "${importPaths.enums}";`);
|
|
2484
|
+
}
|
|
2485
|
+
if (config.inputNames.length > 0) {
|
|
2486
|
+
const inputImports = config.inputNames.map((n) => `input_${name}_${n}`).join(", ");
|
|
2487
|
+
imports.push(`import { ${inputImports} } from "${importPaths.inputs}";`);
|
|
2488
|
+
}
|
|
2489
|
+
if (config.objectNames.length > 0) {
|
|
2490
|
+
const objectImports = config.objectNames.map((n) => `object_${name}_${n}`).join(", ");
|
|
2491
|
+
imports.push(`import { ${objectImports} } from "${importPaths.objects}";`);
|
|
2492
|
+
}
|
|
2493
|
+
if (config.unionNames.length > 0) {
|
|
2494
|
+
const unionImports = config.unionNames.map((n) => `union_${name}_${n}`).join(", ");
|
|
2495
|
+
imports.push(`import { ${unionImports} } from "${importPaths.unions}";`);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
const extraImports = imports.length > 0 ? `${imports.join("\n")}\n` : "";
|
|
2500
|
+
const schemaBlocks = [];
|
|
2501
|
+
const gqlExports = [];
|
|
2502
|
+
for (const [name, config] of Object.entries($$.schemas)) {
|
|
2503
|
+
const schemaVar = `${name}Schema`;
|
|
2504
|
+
const adapterVar = adapterAliases.get(name);
|
|
2505
|
+
const typeExports = [`export type Schema_${name} = typeof ${schemaVar} & { _?: never };`];
|
|
2506
|
+
if (adapterVar) {
|
|
2507
|
+
typeExports.push(`export type Adapter_${name} = typeof ${adapterVar} & { _?: never };`);
|
|
2508
|
+
}
|
|
2509
|
+
const inputTypeMethodsVar = `inputTypeMethods_${name}`;
|
|
2510
|
+
const factoryVar = `createMethod_${name}`;
|
|
2511
|
+
const customDirectivesVar = `customDirectives_${name}`;
|
|
2512
|
+
const defaultDepthBlock = config.defaultInputDepth !== undefined && config.defaultInputDepth !== 3 ? `\n __defaultInputDepth: ${config.defaultInputDepth},` : "";
|
|
2513
|
+
const depthOverridesBlock = config.inputDepthOverrides && Object.keys(config.inputDepthOverrides).length > 0 ? `\n __inputDepthOverrides: ${JSON.stringify(config.inputDepthOverrides)},` : "";
|
|
2514
|
+
const isSplitMode = true;
|
|
2515
|
+
const scalarVarsBlock = config.scalarVars.join("\n");
|
|
2516
|
+
const enumVarsBlock = isSplitMode ? "// (enums imported)" : config.enumVars.length > 0 ? config.enumVars.join("\n") : "// (no enums)";
|
|
2517
|
+
const inputVarsBlock = isSplitMode ? "// (inputs imported)" : config.inputVars.length > 0 ? config.inputVars.join("\n") : "// (no inputs)";
|
|
2518
|
+
const objectVarsBlock = isSplitMode ? "// (objects imported)" : config.objectVars.length > 0 ? config.objectVars.join("\n") : "// (no objects)";
|
|
2519
|
+
const unionVarsBlock = isSplitMode ? "// (unions imported)" : config.unionVars.length > 0 ? config.unionVars.join("\n") : "// (no unions)";
|
|
2520
|
+
const scalarAssembly = $$.injection.mode === "inject" ? scalarAliases.get(name) ?? "{}" : config.scalarNames.length > 0 ? `{ ${config.scalarNames.map((n) => `${n}: scalar_${name}_${n}`).join(", ")} }` : "{}";
|
|
2521
|
+
const enumAssembly = config.enumNames.length > 0 ? `{ ${config.enumNames.map((n) => `${n}: enum_${name}_${n}`).join(", ")} }` : "{}";
|
|
2522
|
+
const inputAssembly = config.inputNames.length > 0 ? `{ ${config.inputNames.map((n) => `${n}: input_${name}_${n}`).join(", ")} }` : "{}";
|
|
2523
|
+
const objectAssembly = config.objectNames.length > 0 ? `{ ${config.objectNames.map((n) => `${n}: object_${name}_${n}`).join(", ")} }` : "{}";
|
|
2524
|
+
const unionAssembly = config.unionNames.length > 0 ? `{ ${config.unionNames.map((n) => `${n}: union_${name}_${n}`).join(", ")} }` : "{}";
|
|
2525
|
+
const scalarVarsSection = $$.injection.mode === "inject" ? "// (scalars imported)" : scalarVarsBlock;
|
|
2526
|
+
const scalarAssemblyLine = $$.injection.mode === "inject" ? `// scalar_${name} is imported directly` : `const scalar_${name} = ${scalarAssembly} as const;`;
|
|
2527
|
+
const scalarRef = $$.injection.mode === "inject" ? scalarAliases.get(name) ?? `scalar_${name}` : `scalar_${name}`;
|
|
2528
|
+
schemaBlocks.push(`
|
|
2529
|
+
// Individual scalar definitions
|
|
2530
|
+
${scalarVarsSection}
|
|
2531
|
+
|
|
2532
|
+
// Individual enum definitions
|
|
2533
|
+
${enumVarsBlock}
|
|
2534
|
+
|
|
2535
|
+
// Individual input definitions
|
|
2536
|
+
${inputVarsBlock}
|
|
2537
|
+
|
|
2538
|
+
// Individual object definitions
|
|
2539
|
+
${objectVarsBlock}
|
|
2540
|
+
|
|
2541
|
+
// Individual union definitions
|
|
2542
|
+
${unionVarsBlock}
|
|
2543
|
+
|
|
2544
|
+
// Category assembly
|
|
2545
|
+
${scalarAssemblyLine}
|
|
2546
|
+
const enum_${name} = ${enumAssembly} as const;
|
|
2547
|
+
const input_${name} = ${inputAssembly} as const;
|
|
2548
|
+
const object_${name} = ${objectAssembly} as const;
|
|
2549
|
+
const union_${name} = ${unionAssembly} as const;
|
|
2550
|
+
|
|
2551
|
+
// Schema assembly
|
|
2552
|
+
const ${schemaVar} = {
|
|
2553
|
+
label: "${name}" as const,
|
|
2554
|
+
operations: { query: "${config.queryType}", mutation: "${config.mutationType}", subscription: "${config.subscriptionType}" } as const,
|
|
2555
|
+
scalar: ${scalarRef},
|
|
2556
|
+
enum: enum_${name},
|
|
2557
|
+
input: input_${name},
|
|
2558
|
+
object: object_${name},
|
|
2559
|
+
union: union_${name},${defaultDepthBlock}${depthOverridesBlock}
|
|
2560
|
+
} as const satisfies AnyGraphqlSchema;
|
|
2561
|
+
|
|
2562
|
+
const ${factoryVar} = createVarMethodFactory<typeof ${schemaVar}>();
|
|
2563
|
+
const ${inputTypeMethodsVar} = ${config.inputTypeMethodsBlock};
|
|
2564
|
+
const ${customDirectivesVar} = { ...createStandardDirectives(), ...${config.directiveMethodsBlock} };
|
|
2565
|
+
|
|
2566
|
+
${typeExports.join("\n")}`);
|
|
2567
|
+
const gqlVarName = `gql_${name}`;
|
|
2568
|
+
if (adapterVar) {
|
|
2569
|
+
const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}, Adapter_${name}>`;
|
|
2570
|
+
schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { adapter: ${adapterVar}, inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
|
|
2571
|
+
} else {
|
|
2572
|
+
const typeParams = `<Schema_${name}, typeof ${customDirectivesVar}>`;
|
|
2573
|
+
schemaBlocks.push(`const ${gqlVarName} = createGqlElementComposer${typeParams}(${schemaVar}, { inputTypeMethods: ${inputTypeMethodsVar}, directiveMethods: ${customDirectivesVar} });`);
|
|
2574
|
+
}
|
|
2575
|
+
schemaBlocks.push(`export type Context_${name} = Parameters<typeof ${gqlVarName}>[0] extends (ctx: infer C) => unknown ? C : never;`);
|
|
2576
|
+
const prebuiltExports = [
|
|
2577
|
+
`export { ${schemaVar} as __schema_${name} }`,
|
|
2578
|
+
`export { ${inputTypeMethodsVar} as __inputTypeMethods_${name} }`,
|
|
2579
|
+
`export { ${customDirectivesVar} as __directiveMethods_${name} }`
|
|
2580
|
+
];
|
|
2581
|
+
if (adapterVar) {
|
|
2582
|
+
prebuiltExports.push(`export { ${adapterVar} as __adapter_${name} }`);
|
|
2583
|
+
}
|
|
2584
|
+
schemaBlocks.push(`${prebuiltExports.join(";\n")};`);
|
|
2585
|
+
gqlExports.push(`export { ${gqlVarName} as __gql_${name} }`);
|
|
2586
|
+
}
|
|
2587
|
+
const needsDefineEnum = false;
|
|
2588
|
+
return `\
|
|
2589
|
+
import {${needsDefineEnum ? "\n defineEnum," : ""}
|
|
2590
|
+
type AnyGraphqlSchema,
|
|
2591
|
+
createDirectiveMethod,
|
|
2592
|
+
createTypedDirectiveMethod,
|
|
2593
|
+
createGqlElementComposer,
|
|
2594
|
+
createStandardDirectives,
|
|
2595
|
+
createVarMethodFactory,
|
|
2596
|
+
} from "@soda-gql/core";
|
|
2597
|
+
${extraImports}
|
|
2598
|
+
${schemaBlocks.join("\n")}
|
|
2599
|
+
|
|
2600
|
+
${gqlExports.join(";\n")};
|
|
2601
|
+
`;
|
|
2602
|
+
};
|
|
2603
|
+
const generateMultiSchemaModule = (schemas, options) => {
|
|
2604
|
+
const schemaConfigs = {};
|
|
2605
|
+
const allStats = {
|
|
2606
|
+
objects: 0,
|
|
2607
|
+
enums: 0,
|
|
2608
|
+
inputs: 0,
|
|
2609
|
+
unions: 0
|
|
2610
|
+
};
|
|
2611
|
+
for (const [name, document] of schemas.entries()) {
|
|
2612
|
+
const schema = createSchemaIndex(document);
|
|
2613
|
+
const typeFilterConfig = options?.typeFilters?.get(name);
|
|
2614
|
+
const typeFilter = compileTypeFilter(typeFilterConfig);
|
|
2615
|
+
const allTypeNames = new Map([
|
|
2616
|
+
["object", Array.from(schema.objects.keys()).filter((n) => !n.startsWith("__"))],
|
|
2617
|
+
["input", Array.from(schema.inputs.keys()).filter((n) => !n.startsWith("__"))],
|
|
2618
|
+
["enum", Array.from(schema.enums.keys()).filter((n) => !n.startsWith("__"))],
|
|
2619
|
+
["union", Array.from(schema.unions.keys()).filter((n) => !n.startsWith("__"))],
|
|
2620
|
+
["scalar", Array.from(schema.scalars.keys()).filter((n) => !n.startsWith("__"))]
|
|
2621
|
+
]);
|
|
2622
|
+
const excluded = buildExclusionSet(typeFilter, allTypeNames);
|
|
2623
|
+
const objectTypeNames = collectObjectTypeNames(schema).filter((n) => !excluded.has(n));
|
|
2624
|
+
const enumTypeNames = collectEnumTypeNames(schema).filter((n) => !excluded.has(n));
|
|
2625
|
+
const inputTypeNames = collectInputTypeNames(schema).filter((n) => !excluded.has(n));
|
|
2626
|
+
const unionTypeNames = collectUnionTypeNames(schema).filter((n) => !excluded.has(n));
|
|
2627
|
+
const customScalarNames = collectScalarNames(schema).filter((n) => !builtinScalarTypes$1.has(n) && !excluded.has(n));
|
|
2628
|
+
const scalarVars = [];
|
|
2629
|
+
const enumVars = [];
|
|
2630
|
+
const inputVars = [];
|
|
2631
|
+
const objectVars = [];
|
|
2632
|
+
const unionVars = [];
|
|
2633
|
+
for (const scalarName of builtinScalarTypes$1.keys()) {
|
|
2634
|
+
const record = schema.scalars.get(scalarName) ?? {
|
|
2635
|
+
name: scalarName,
|
|
2636
|
+
directives: []
|
|
2637
|
+
};
|
|
2638
|
+
scalarVars.push(renderScalarVar(name, record));
|
|
2639
|
+
}
|
|
2640
|
+
for (const scalarName of customScalarNames) {
|
|
2641
|
+
const record = schema.scalars.get(scalarName);
|
|
2642
|
+
if (record) {
|
|
2643
|
+
scalarVars.push(renderScalarVar(name, record));
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
for (const enumName of enumTypeNames) {
|
|
2647
|
+
const record = schema.enums.get(enumName);
|
|
2648
|
+
if (record) {
|
|
2649
|
+
enumVars.push(renderEnumVar(name, record));
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
for (const inputName of inputTypeNames) {
|
|
2653
|
+
const record = schema.inputs.get(inputName);
|
|
2654
|
+
if (record) {
|
|
2655
|
+
inputVars.push(renderInputVar(name, schema, record, excluded));
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
for (const objectName of objectTypeNames) {
|
|
2659
|
+
const record = schema.objects.get(objectName);
|
|
2660
|
+
if (record) {
|
|
2661
|
+
objectVars.push(renderObjectVar(name, schema, record, excluded));
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
for (const unionName of unionTypeNames) {
|
|
2665
|
+
const record = schema.unions.get(unionName);
|
|
2666
|
+
if (record) {
|
|
2667
|
+
unionVars.push(renderUnionVar(name, record, excluded));
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
const allScalarNames = [...builtinScalarTypes$1.keys(), ...customScalarNames];
|
|
2671
|
+
const factoryVar = `createMethod_${name}`;
|
|
2672
|
+
const inputTypeMethodsBlock = renderInputTypeMethods(schema, factoryVar, excluded);
|
|
2673
|
+
const directiveMethodsBlock = renderDirectiveMethods(schema, excluded);
|
|
2674
|
+
const queryType = schema.operationTypes.query ?? "Query";
|
|
2675
|
+
const mutationType = schema.operationTypes.mutation ?? "Mutation";
|
|
2676
|
+
const subscriptionType = schema.operationTypes.subscription ?? "Subscription";
|
|
2677
|
+
schemaConfigs[name] = {
|
|
2678
|
+
queryType,
|
|
2679
|
+
mutationType,
|
|
2680
|
+
subscriptionType,
|
|
2681
|
+
scalarVars,
|
|
2682
|
+
enumVars,
|
|
2683
|
+
inputVars,
|
|
2684
|
+
objectVars,
|
|
2685
|
+
unionVars,
|
|
2686
|
+
scalarNames: allScalarNames,
|
|
2687
|
+
enumNames: enumTypeNames,
|
|
2688
|
+
inputNames: inputTypeNames,
|
|
2689
|
+
objectNames: objectTypeNames,
|
|
2690
|
+
unionNames: unionTypeNames,
|
|
2691
|
+
inputTypeMethodsBlock,
|
|
2692
|
+
directiveMethodsBlock,
|
|
2693
|
+
defaultInputDepth: options?.defaultInputDepth?.get(name),
|
|
2694
|
+
inputDepthOverrides: options?.inputDepthOverrides?.get(name)
|
|
2695
|
+
};
|
|
2696
|
+
allStats.objects += objectVars.length;
|
|
2697
|
+
allStats.enums += enumVars.length;
|
|
2698
|
+
allStats.inputs += inputVars.length;
|
|
2699
|
+
allStats.unions += unionVars.length;
|
|
2700
|
+
}
|
|
2701
|
+
const injection = options?.injection ? {
|
|
2702
|
+
mode: "inject",
|
|
2703
|
+
perSchema: options.injection,
|
|
2704
|
+
injectsModulePath: "./_internal-injects"
|
|
2705
|
+
} : { mode: "inline" };
|
|
2706
|
+
const splitting = { importPaths: {
|
|
2707
|
+
enums: "./_defs/enums",
|
|
2708
|
+
inputs: "./_defs/inputs",
|
|
2709
|
+
objects: "./_defs/objects",
|
|
2710
|
+
unions: "./_defs/unions"
|
|
2711
|
+
} };
|
|
2712
|
+
const code = multiRuntimeTemplate({
|
|
2713
|
+
schemas: schemaConfigs,
|
|
2714
|
+
injection,
|
|
2715
|
+
splitting
|
|
2716
|
+
});
|
|
2717
|
+
const injectsCode = options?.injection ? generateInjectsCode(options.injection) : undefined;
|
|
2718
|
+
const categoryVarsResult = Object.fromEntries(Object.entries(schemaConfigs).map(([schemaName, config]) => {
|
|
2719
|
+
const toDefVar = (code$1, prefix) => {
|
|
2720
|
+
const match = code$1.match(new RegExp(`const (${prefix}_${schemaName}_(\\w+))`));
|
|
2721
|
+
return {
|
|
2722
|
+
name: match?.[1] ?? "",
|
|
2723
|
+
code: code$1
|
|
2724
|
+
};
|
|
2725
|
+
};
|
|
2726
|
+
return [schemaName, {
|
|
2727
|
+
enums: config.enumVars.map((c) => toDefVar(c, "enum")),
|
|
2728
|
+
inputs: config.inputVars.map((c) => toDefVar(c, "input")),
|
|
2729
|
+
objects: config.objectVars.map((c) => toDefVar(c, "object")),
|
|
2730
|
+
unions: config.unionVars.map((c) => toDefVar(c, "union"))
|
|
2731
|
+
}];
|
|
2732
|
+
}));
|
|
2733
|
+
return {
|
|
2734
|
+
code,
|
|
2735
|
+
injectsCode,
|
|
2736
|
+
categoryVars: categoryVarsResult,
|
|
2737
|
+
stats: allStats
|
|
2738
|
+
};
|
|
2739
|
+
};
|
|
2740
|
+
/**
|
|
2741
|
+
* Generate a stub `types.prebuilt.ts` file with empty PrebuiltTypes registries.
|
|
2742
|
+
* This stub is only written when `types.prebuilt.ts` does not already exist.
|
|
2743
|
+
* Typegen will later overwrite it with the real type registry.
|
|
2744
|
+
*/
|
|
2745
|
+
const generatePrebuiltStub = (schemaNames) => {
|
|
2746
|
+
const typeDeclarations = schemaNames.map((name) => `export type PrebuiltTypes_${name} = {
|
|
2747
|
+
readonly fragments: {};
|
|
2748
|
+
readonly operations: {};
|
|
2749
|
+
};`).join("\n\n");
|
|
2750
|
+
return `\
|
|
2751
|
+
/**
|
|
2752
|
+
* Prebuilt type registry stub.
|
|
2753
|
+
*
|
|
2754
|
+
* This file was generated by @soda-gql/codegen as an empty stub.
|
|
2755
|
+
* Run 'soda-gql typegen' to populate with real prebuilt types.
|
|
2756
|
+
*
|
|
2757
|
+
* @module
|
|
2758
|
+
* @generated
|
|
2759
|
+
*/
|
|
2760
|
+
|
|
2761
|
+
${typeDeclarations}
|
|
2762
|
+
`;
|
|
2763
|
+
};
|
|
2764
|
+
/**
|
|
2765
|
+
* Generate the `index.ts` module that re-exports from `_internal`
|
|
2766
|
+
* and constructs the `gql` object from individual `__gql_*` exports.
|
|
2767
|
+
*
|
|
2768
|
+
* The `gql` object preserves the original inferred types from schema inference.
|
|
2769
|
+
* PrebuiltContext types will be integrated once the type resolution strategy
|
|
2770
|
+
* is redesigned to match the tagged template runtime API.
|
|
2771
|
+
*/
|
|
2772
|
+
const generateIndexModule = (schemaNames, allFieldNames) => {
|
|
2773
|
+
const gqlImports = schemaNames.map((name) => `__gql_${name}`).join(", ");
|
|
2774
|
+
const prebuiltImports = schemaNames.map((name) => `PrebuiltTypes_${name}`).join(", ");
|
|
2775
|
+
const schemaTypeImports = schemaNames.map((name) => `Schema_${name}`).join(", ");
|
|
2776
|
+
const directiveImports = schemaNames.map((name) => `__directiveMethods_${name}`).join(", ");
|
|
2777
|
+
const perSchemaTypes = schemaNames.map((name) => `
|
|
2778
|
+
type ResolveFragmentAtBuilder_${name}<TKey extends string> =
|
|
2779
|
+
TKey extends keyof PrebuiltTypes_${name}["fragments"]
|
|
2780
|
+
? Fragment<
|
|
2781
|
+
PrebuiltTypes_${name}["fragments"][TKey]["typename"],
|
|
2782
|
+
PrebuiltTypes_${name}["fragments"][TKey]["input"] extends void
|
|
2783
|
+
? void
|
|
2784
|
+
: Partial<PrebuiltTypes_${name}["fragments"][TKey]["input"] & AnyConstAssignableInput>,
|
|
2785
|
+
Partial<AnyFields>,
|
|
2786
|
+
PrebuiltTypes_${name}["fragments"][TKey]["output"] & object
|
|
2787
|
+
>
|
|
2788
|
+
: Fragment<"(unknown)", PrebuiltEntryNotFound<TKey, "fragment">, Partial<AnyFields>, PrebuiltEntryNotFound<TKey, "fragment">>;
|
|
2789
|
+
|
|
2790
|
+
type ResolveOperationAtBuilder_${name}<TOperationType extends OperationType, TName extends string> =
|
|
2791
|
+
TName extends keyof PrebuiltTypes_${name}["operations"]
|
|
2792
|
+
? Operation<
|
|
2793
|
+
TOperationType,
|
|
2794
|
+
TName,
|
|
2795
|
+
string[],
|
|
2796
|
+
PrebuiltTypes_${name}["operations"][TName]["input"] & AnyConstAssignableInput,
|
|
2797
|
+
Partial<AnyFields>,
|
|
2798
|
+
PrebuiltTypes_${name}["operations"][TName]["output"] & object
|
|
2799
|
+
>
|
|
2800
|
+
: Operation<
|
|
2801
|
+
TOperationType,
|
|
2802
|
+
TName,
|
|
2803
|
+
string[],
|
|
2804
|
+
PrebuiltEntryNotFound<TName, "operation">,
|
|
2805
|
+
Partial<AnyFields>,
|
|
2806
|
+
PrebuiltEntryNotFound<TName, "operation">
|
|
2807
|
+
>;
|
|
2808
|
+
|
|
2809
|
+
type PrebuiltCurriedFragment_${name} = <TKey extends string>(
|
|
2810
|
+
name: TKey,
|
|
2811
|
+
typeName: string,
|
|
2812
|
+
) => (...args: unknown[]) => (...args: unknown[]) => ResolveFragmentAtBuilder_${name}<TKey>;
|
|
2813
|
+
|
|
2814
|
+
type PrebuiltCurriedOperation_${name}<TOperationType extends OperationType> = <TName extends string>(
|
|
2815
|
+
operationName: TName,
|
|
2816
|
+
) => (...args: unknown[]) => (...args: unknown[]) => ResolveOperationAtBuilder_${name}<TOperationType, TName>;
|
|
2817
|
+
|
|
2818
|
+
type FieldFactoryFn_${name} = (...args: unknown[]) => Record<string, unknown> & ((callback: (tools: GenericFieldsBuilderTools_${name}) => Record<string, unknown>) => Record<string, unknown>);
|
|
2819
|
+
${(() => {
|
|
2820
|
+
const fieldNames = allFieldNames?.get(name);
|
|
2821
|
+
if (fieldNames && fieldNames.length > 0) {
|
|
2822
|
+
const union = fieldNames.map((n) => JSON.stringify(n)).join(" | ");
|
|
2823
|
+
return `type AllObjectFieldNames_${name} = ${union};
|
|
2824
|
+
type GenericFieldFactory_${name} = { readonly [K in AllObjectFieldNames_${name}]: FieldFactoryFn_${name} } & Record<string, FieldFactoryFn_${name}>;`;
|
|
2825
|
+
}
|
|
2826
|
+
return `type GenericFieldFactory_${name} = Record<string, FieldFactoryFn_${name}>;`;
|
|
2827
|
+
})()}
|
|
2828
|
+
type GenericFieldsBuilderTools_${name} = { readonly f: GenericFieldFactory_${name}; readonly $: Readonly<Record<string, never>> };
|
|
2829
|
+
|
|
2830
|
+
type PrebuiltCallbackOperation_${name}<TOperationType extends OperationType> = <TName extends string>(
|
|
2831
|
+
options: { name: TName; fields: (tools: GenericFieldsBuilderTools_${name}) => Record<string, unknown>; variables?: Record<string, unknown>; metadata?: (tools: { readonly $: Readonly<Record<string, never>>; readonly fragmentMetadata: unknown[] | undefined }) => Record<string, unknown> },
|
|
2832
|
+
) => ResolveOperationAtBuilder_${name}<TOperationType, TName>;
|
|
2833
|
+
|
|
2834
|
+
export type PrebuiltContext_${name} = {
|
|
2835
|
+
readonly fragment: PrebuiltCurriedFragment_${name};
|
|
2836
|
+
readonly query: PrebuiltCurriedOperation_${name}<"query"> & {
|
|
2837
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"query">;
|
|
2838
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2839
|
+
};
|
|
2840
|
+
readonly mutation: PrebuiltCurriedOperation_${name}<"mutation"> & {
|
|
2841
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"mutation">;
|
|
2842
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2843
|
+
};
|
|
2844
|
+
readonly subscription: PrebuiltCurriedOperation_${name}<"subscription"> & {
|
|
2845
|
+
readonly operation: PrebuiltCallbackOperation_${name}<"subscription">;
|
|
2846
|
+
readonly compat: (operationName: string) => (strings: TemplateStringsArray, ...values: never[]) => GqlDefine<unknown>;
|
|
2847
|
+
};
|
|
2848
|
+
readonly define: <TValue>(factory: () => TValue | Promise<TValue>) => GqlDefine<TValue>;
|
|
2849
|
+
readonly extend: (...args: unknown[]) => AnyOperation;
|
|
2850
|
+
readonly $var: VarBuilder<Schema_${name}>;
|
|
2851
|
+
readonly $dir: typeof __directiveMethods_${name};
|
|
2852
|
+
readonly $colocate: <T extends Record<string, unknown>>(projections: T) => T;
|
|
2853
|
+
};
|
|
2854
|
+
|
|
2855
|
+
type GqlComposer_${name} = {
|
|
2856
|
+
<TResult>(composeElement: (context: PrebuiltContext_${name}) => TResult): TResult;
|
|
2857
|
+
readonly $schema: AnyGraphqlSchema;
|
|
2858
|
+
};`).join("\n");
|
|
2859
|
+
const gqlEntries = schemaNames.map((name) => ` ${name}: __gql_${name} as unknown as GqlComposer_${name}`).join(",\n");
|
|
2860
|
+
return `\
|
|
2861
|
+
/**
|
|
2862
|
+
* Generated by @soda-gql/codegen
|
|
2863
|
+
* @module
|
|
2864
|
+
* @generated
|
|
2865
|
+
*/
|
|
2866
|
+
|
|
2867
|
+
export * from "./_internal";
|
|
2868
|
+
import { ${gqlImports} } from "./_internal";
|
|
2869
|
+
import type { ${schemaTypeImports} } from "./_internal";
|
|
2870
|
+
import type { ${directiveImports} } from "./_internal";
|
|
2871
|
+
import type { ${prebuiltImports} } from "./types.prebuilt";
|
|
2872
|
+
import type { Fragment, Operation, OperationType, PrebuiltEntryNotFound, AnyConstAssignableInput, AnyFields, AnyGraphqlSchema, AnyOperation, VarBuilder, GqlDefine } from "@soda-gql/core";
|
|
2873
|
+
${perSchemaTypes}
|
|
2874
|
+
|
|
2875
|
+
export const gql = {
|
|
2876
|
+
${gqlEntries}
|
|
2877
|
+
};
|
|
2878
|
+
`;
|
|
2879
|
+
};
|
|
2880
|
+
|
|
2881
|
+
//#endregion
|
|
9
2882
|
//#region packages/codegen/src/graphql-compat/parser.ts
|
|
10
2883
|
/**
|
|
11
2884
|
* Parser for .graphql operation files.
|
|
@@ -328,6 +3201,7 @@ const isModifierAssignable = (source, target) => {
|
|
|
328
3201
|
for (let i = 0; i < srcStruct.lists.length; i++) {
|
|
329
3202
|
const srcList = srcStruct.lists[i];
|
|
330
3203
|
const tgtList = tgtListsToCompare[i];
|
|
3204
|
+
if (srcList === undefined || tgtList === undefined) break;
|
|
331
3205
|
if (srcList === "[]?" && tgtList === "[]!") return false;
|
|
332
3206
|
}
|
|
333
3207
|
return true;
|
|
@@ -372,6 +3246,7 @@ const mergeModifiers = (a, b) => {
|
|
|
372
3246
|
for (let i = 0; i < structA.lists.length; i++) {
|
|
373
3247
|
const listA = structA.lists[i];
|
|
374
3248
|
const listB = structB.lists[i];
|
|
3249
|
+
if (listA === undefined || listB === undefined) break;
|
|
375
3250
|
mergedLists.push(listA === "[]!" || listB === "[]!" ? "[]!" : "[]?");
|
|
376
3251
|
}
|
|
377
3252
|
return {
|
|
@@ -550,14 +3425,14 @@ const getFieldReturnType = (schema, parentTypeName, fieldName) => {
|
|
|
550
3425
|
* 3. Verify the candidate can satisfy ALL expected modifiers via isModifierAssignable
|
|
551
3426
|
*/
|
|
552
3427
|
const mergeVariableUsages = (variableName, usages) => {
|
|
553
|
-
|
|
3428
|
+
const first = usages[0];
|
|
3429
|
+
if (!first) {
|
|
554
3430
|
return (0, neverthrow.err)({
|
|
555
3431
|
code: "GRAPHQL_UNDECLARED_VARIABLE",
|
|
556
3432
|
message: `No usages found for variable "${variableName}"`,
|
|
557
3433
|
variableName
|
|
558
3434
|
});
|
|
559
3435
|
}
|
|
560
|
-
const first = usages[0];
|
|
561
3436
|
for (const usage of usages) {
|
|
562
3437
|
if (usage.typeName !== first.typeName) {
|
|
563
3438
|
return (0, neverthrow.err)({
|
|
@@ -569,7 +3444,9 @@ const mergeVariableUsages = (variableName, usages) => {
|
|
|
569
3444
|
}
|
|
570
3445
|
let candidateModifier = first.minimumModifier;
|
|
571
3446
|
for (let i = 1; i < usages.length; i++) {
|
|
572
|
-
const
|
|
3447
|
+
const usage = usages[i];
|
|
3448
|
+
if (!usage) break;
|
|
3449
|
+
const result = mergeModifiers(candidateModifier, usage.minimumModifier);
|
|
573
3450
|
if (!result.ok) {
|
|
574
3451
|
return (0, neverthrow.err)({
|
|
575
3452
|
code: "GRAPHQL_VARIABLE_MODIFIER_INCOMPATIBLE",
|
|
@@ -711,7 +3588,7 @@ const isEnumName = (schema, name) => schema.enums.has(name);
|
|
|
711
3588
|
* fragment dependencies, and infers variables for fragments.
|
|
712
3589
|
*/
|
|
713
3590
|
const transformParsedGraphql = (parsed, options) => {
|
|
714
|
-
const schema =
|
|
3591
|
+
const schema = createSchemaIndex(options.schemaDocument);
|
|
715
3592
|
const sortResult = sortFragmentsByDependency(parsed.fragments);
|
|
716
3593
|
if (sortResult.isErr()) {
|
|
717
3594
|
return (0, neverthrow.err)(sortResult.error);
|
|
@@ -867,7 +3744,7 @@ const getRootTypeName = (schema, kind) => {
|
|
|
867
3744
|
*/
|
|
868
3745
|
const emitOperation = (operation, options) => {
|
|
869
3746
|
const lines = [];
|
|
870
|
-
const schema = options.schemaDocument ?
|
|
3747
|
+
const schema = options.schemaDocument ? createSchemaIndex(options.schemaDocument) : null;
|
|
871
3748
|
const exportName = `${operation.name}Compat`;
|
|
872
3749
|
const operationType = operation.kind;
|
|
873
3750
|
lines.push(`export const ${exportName} = gql.${options.schemaName}(({ ${operationType}, $var }) =>`);
|
|
@@ -893,7 +3770,7 @@ const emitOperation = (operation, options) => {
|
|
|
893
3770
|
*/
|
|
894
3771
|
const emitFragment = (fragment, options) => {
|
|
895
3772
|
const lines = [];
|
|
896
|
-
const schema = options.schemaDocument ?
|
|
3773
|
+
const schema = options.schemaDocument ? createSchemaIndex(options.schemaDocument) : null;
|
|
897
3774
|
const hasVariables = fragment.variables.length > 0;
|
|
898
3775
|
const exportName = `${fragment.name}Fragment`;
|
|
899
3776
|
const destructure = hasVariables ? "fragment, $var" : "fragment";
|
|
@@ -1271,6 +4148,221 @@ const writeInjectTemplate = (outPath) => {
|
|
|
1271
4148
|
};
|
|
1272
4149
|
const getInjectTemplate = () => `${templateContents}\n`;
|
|
1273
4150
|
|
|
4151
|
+
//#endregion
|
|
4152
|
+
//#region packages/codegen/src/reachability.ts
|
|
4153
|
+
/**
|
|
4154
|
+
* Schema type reachability analysis.
|
|
4155
|
+
*
|
|
4156
|
+
* Determines which types are reachable from root types (Query/Mutation/Subscription)
|
|
4157
|
+
* to specified target types (e.g., fragment onType values from .graphql files).
|
|
4158
|
+
* Produces a CompiledFilter for use with existing buildExclusionSet.
|
|
4159
|
+
*
|
|
4160
|
+
* @module
|
|
4161
|
+
*/
|
|
4162
|
+
const extractNamedType = (typeNode) => {
|
|
4163
|
+
switch (typeNode.kind) {
|
|
4164
|
+
case graphql.Kind.NAMED_TYPE: return typeNode.name.value;
|
|
4165
|
+
case graphql.Kind.LIST_TYPE: return extractNamedType(typeNode.type);
|
|
4166
|
+
case graphql.Kind.NON_NULL_TYPE: return extractNamedType(typeNode.type);
|
|
4167
|
+
}
|
|
4168
|
+
};
|
|
4169
|
+
const addEdge = (graph, from, to) => {
|
|
4170
|
+
let edges = graph.get(from);
|
|
4171
|
+
if (!edges) {
|
|
4172
|
+
edges = new Set();
|
|
4173
|
+
graph.set(from, edges);
|
|
4174
|
+
}
|
|
4175
|
+
edges.add(to);
|
|
4176
|
+
};
|
|
4177
|
+
const buildTypeGraph = (document) => {
|
|
4178
|
+
const schema = createSchemaIndex(document);
|
|
4179
|
+
const forward = new Map();
|
|
4180
|
+
const reverse = new Map();
|
|
4181
|
+
const addBidirectional = (from, to) => {
|
|
4182
|
+
addEdge(forward, from, to);
|
|
4183
|
+
addEdge(reverse, to, from);
|
|
4184
|
+
};
|
|
4185
|
+
for (const [typeName, record] of schema.objects) {
|
|
4186
|
+
for (const field of record.fields.values()) {
|
|
4187
|
+
const returnType = extractNamedType(field.type);
|
|
4188
|
+
addBidirectional(typeName, returnType);
|
|
4189
|
+
if (field.arguments) {
|
|
4190
|
+
for (const arg of field.arguments) {
|
|
4191
|
+
const argType = extractNamedType(arg.type);
|
|
4192
|
+
addBidirectional(typeName, argType);
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
for (const [typeName, record] of schema.inputs) {
|
|
4198
|
+
for (const field of record.fields.values()) {
|
|
4199
|
+
const fieldType = extractNamedType(field.type);
|
|
4200
|
+
addBidirectional(typeName, fieldType);
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
for (const [typeName, record] of schema.unions) {
|
|
4204
|
+
for (const memberName of record.members.keys()) {
|
|
4205
|
+
addBidirectional(typeName, memberName);
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
return {
|
|
4209
|
+
graph: {
|
|
4210
|
+
forward,
|
|
4211
|
+
reverse
|
|
4212
|
+
},
|
|
4213
|
+
schema
|
|
4214
|
+
};
|
|
4215
|
+
};
|
|
4216
|
+
/**
|
|
4217
|
+
* BFS traversal collecting all reachable nodes from seeds.
|
|
4218
|
+
*/
|
|
4219
|
+
const bfs = (adjacency, seeds, constraint) => {
|
|
4220
|
+
const visited = new Set();
|
|
4221
|
+
const queue = [];
|
|
4222
|
+
for (const seed of seeds) {
|
|
4223
|
+
if (!visited.has(seed)) {
|
|
4224
|
+
visited.add(seed);
|
|
4225
|
+
queue.push(seed);
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
let head = 0;
|
|
4229
|
+
while (head < queue.length) {
|
|
4230
|
+
const current = queue[head++];
|
|
4231
|
+
if (current === undefined) break;
|
|
4232
|
+
const neighbors = adjacency.get(current);
|
|
4233
|
+
if (!neighbors) continue;
|
|
4234
|
+
for (const neighbor of neighbors) {
|
|
4235
|
+
if (visited.has(neighbor)) continue;
|
|
4236
|
+
if (constraint && !constraint.has(neighbor)) continue;
|
|
4237
|
+
visited.add(neighbor);
|
|
4238
|
+
queue.push(neighbor);
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
return visited;
|
|
4242
|
+
};
|
|
4243
|
+
/**
|
|
4244
|
+
* Compute the set of type names reachable on paths from root types to target types.
|
|
4245
|
+
*
|
|
4246
|
+
* Algorithm:
|
|
4247
|
+
* 1. Backward BFS from target types to find all upstream types
|
|
4248
|
+
* 2. Forward BFS from root types, constrained to upstream set, to find actual paths
|
|
4249
|
+
* 3. Collect input/enum/scalar types used as field arguments on reachable object types
|
|
4250
|
+
*/
|
|
4251
|
+
const computeReachableTypes = (graph, schema, targetTypes, usedArgumentTypes) => {
|
|
4252
|
+
const upstream = bfs(graph.reverse, targetTypes);
|
|
4253
|
+
const rootTypes = [];
|
|
4254
|
+
if (schema.operationTypes.query) rootTypes.push(schema.operationTypes.query);
|
|
4255
|
+
if (schema.operationTypes.mutation) rootTypes.push(schema.operationTypes.mutation);
|
|
4256
|
+
if (schema.operationTypes.subscription) rootTypes.push(schema.operationTypes.subscription);
|
|
4257
|
+
const validRoots = rootTypes.filter((r) => upstream.has(r));
|
|
4258
|
+
const pathTypes = bfs(graph.forward, validRoots, upstream);
|
|
4259
|
+
const reachable = new Set(pathTypes);
|
|
4260
|
+
const inputQueue = [];
|
|
4261
|
+
for (const typeName of pathTypes) {
|
|
4262
|
+
const objectRecord = schema.objects.get(typeName);
|
|
4263
|
+
if (!objectRecord) continue;
|
|
4264
|
+
for (const field of objectRecord.fields.values()) {
|
|
4265
|
+
const returnType = extractNamedType(field.type);
|
|
4266
|
+
if (!reachable.has(returnType)) {
|
|
4267
|
+
const isKnownComposite = schema.objects.has(returnType) || schema.inputs.has(returnType) || schema.unions.has(returnType);
|
|
4268
|
+
if (!isKnownComposite) {
|
|
4269
|
+
reachable.add(returnType);
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
if (!usedArgumentTypes && field.arguments) {
|
|
4273
|
+
for (const arg of field.arguments) {
|
|
4274
|
+
const argType = extractNamedType(arg.type);
|
|
4275
|
+
if (!reachable.has(argType)) {
|
|
4276
|
+
reachable.add(argType);
|
|
4277
|
+
if (schema.inputs.has(argType)) {
|
|
4278
|
+
inputQueue.push(argType);
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
if (usedArgumentTypes) {
|
|
4286
|
+
for (const inputName of usedArgumentTypes) {
|
|
4287
|
+
if (!reachable.has(inputName)) {
|
|
4288
|
+
reachable.add(inputName);
|
|
4289
|
+
inputQueue.push(inputName);
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
let inputHead = 0;
|
|
4294
|
+
while (inputHead < inputQueue.length) {
|
|
4295
|
+
const inputName = inputQueue[inputHead++];
|
|
4296
|
+
if (inputName === undefined) break;
|
|
4297
|
+
const inputRecord = schema.inputs.get(inputName);
|
|
4298
|
+
if (!inputRecord) continue;
|
|
4299
|
+
for (const field of inputRecord.fields.values()) {
|
|
4300
|
+
const fieldType = extractNamedType(field.type);
|
|
4301
|
+
if (!reachable.has(fieldType)) {
|
|
4302
|
+
reachable.add(fieldType);
|
|
4303
|
+
if (schema.inputs.has(fieldType)) {
|
|
4304
|
+
inputQueue.push(fieldType);
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
return reachable;
|
|
4310
|
+
};
|
|
4311
|
+
/**
|
|
4312
|
+
* Compute a filter function that includes only types reachable from root types
|
|
4313
|
+
* to the specified target types.
|
|
4314
|
+
*
|
|
4315
|
+
* When targetTypes is empty, returns a pass-all filter (no filtering).
|
|
4316
|
+
* Warns when target types are not found in the schema.
|
|
4317
|
+
*
|
|
4318
|
+
* @param document - The parsed GraphQL schema document
|
|
4319
|
+
* @param targetTypes - Set of type names that fragments target (e.g., from ParsedFragment.onType)
|
|
4320
|
+
* @returns Filter function and any warnings
|
|
4321
|
+
*/
|
|
4322
|
+
const computeReachabilityFilter = (document, targetTypes, usedArgumentTypes) => {
|
|
4323
|
+
if (targetTypes.size === 0) {
|
|
4324
|
+
return {
|
|
4325
|
+
filter: () => true,
|
|
4326
|
+
warnings: []
|
|
4327
|
+
};
|
|
4328
|
+
}
|
|
4329
|
+
const { graph, schema } = buildTypeGraph(document);
|
|
4330
|
+
const allTypeNames = new Set([
|
|
4331
|
+
...schema.objects.keys(),
|
|
4332
|
+
...schema.inputs.keys(),
|
|
4333
|
+
...schema.enums.keys(),
|
|
4334
|
+
...schema.unions.keys(),
|
|
4335
|
+
...schema.scalars.keys()
|
|
4336
|
+
]);
|
|
4337
|
+
const warnings = [];
|
|
4338
|
+
const validTargets = new Set();
|
|
4339
|
+
for (const target of targetTypes) {
|
|
4340
|
+
if (allTypeNames.has(target)) {
|
|
4341
|
+
validTargets.add(target);
|
|
4342
|
+
} else {
|
|
4343
|
+
warnings.push(`Target type "${target}" not found in schema`);
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
if (validTargets.size === 0) {
|
|
4347
|
+
return {
|
|
4348
|
+
filter: () => true,
|
|
4349
|
+
warnings
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
const reachable = computeReachableTypes(graph, schema, validTargets, usedArgumentTypes);
|
|
4353
|
+
if (reachable.size === 0) {
|
|
4354
|
+
warnings.push(`No types reachable from root operations to target types: ${[...validTargets].join(", ")}; skipping reachability filter`);
|
|
4355
|
+
return {
|
|
4356
|
+
filter: () => true,
|
|
4357
|
+
warnings
|
|
4358
|
+
};
|
|
4359
|
+
}
|
|
4360
|
+
return {
|
|
4361
|
+
filter: (context) => reachable.has(context.name),
|
|
4362
|
+
warnings
|
|
4363
|
+
};
|
|
4364
|
+
};
|
|
4365
|
+
|
|
1274
4366
|
//#endregion
|
|
1275
4367
|
//#region packages/codegen/src/bundler/esbuild.ts
|
|
1276
4368
|
const esbuildBundler = {
|
|
@@ -1485,6 +4577,20 @@ const removeDirectory = (dirPath) => {
|
|
|
1485
4577
|
});
|
|
1486
4578
|
}
|
|
1487
4579
|
};
|
|
4580
|
+
const readModule = (filePath) => {
|
|
4581
|
+
const targetPath = (0, node_path.resolve)(filePath);
|
|
4582
|
+
try {
|
|
4583
|
+
const content = (0, node_fs.readFileSync)(targetPath, "utf-8");
|
|
4584
|
+
return (0, neverthrow.ok)(content);
|
|
4585
|
+
} catch (error) {
|
|
4586
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4587
|
+
return (0, neverthrow.err)({
|
|
4588
|
+
code: "READ_FAILED",
|
|
4589
|
+
message,
|
|
4590
|
+
outPath: targetPath
|
|
4591
|
+
});
|
|
4592
|
+
}
|
|
4593
|
+
};
|
|
1488
4594
|
const writeModule = (outPath, contents) => {
|
|
1489
4595
|
const targetPath = (0, node_path.resolve)(outPath);
|
|
1490
4596
|
try {
|
|
@@ -1612,11 +4718,16 @@ const runCodegen = async (options) => {
|
|
|
1612
4718
|
const schemas = new Map();
|
|
1613
4719
|
const schemaHashes = {};
|
|
1614
4720
|
for (const [name, schemaConfig] of Object.entries(options.schemas)) {
|
|
1615
|
-
const
|
|
1616
|
-
if (
|
|
1617
|
-
|
|
4721
|
+
const preloaded = options.preloadedSchemas?.get(name);
|
|
4722
|
+
if (preloaded) {
|
|
4723
|
+
schemas.set(name, preloaded);
|
|
4724
|
+
} else {
|
|
4725
|
+
const result = await loadSchema(schemaConfig.schema).match((doc) => Promise.resolve((0, neverthrow.ok)(doc)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
4726
|
+
if (result.isErr()) {
|
|
4727
|
+
return (0, neverthrow.err)(result.error);
|
|
4728
|
+
}
|
|
4729
|
+
schemas.set(name, result.value);
|
|
1618
4730
|
}
|
|
1619
|
-
schemas.set(name, result.value);
|
|
1620
4731
|
}
|
|
1621
4732
|
const injectionConfig = new Map();
|
|
1622
4733
|
for (const [schemaName, schemaConfig] of Object.entries(options.schemas)) {
|
|
@@ -1643,22 +4754,25 @@ const runCodegen = async (options) => {
|
|
|
1643
4754
|
typeFiltersConfig.set(schemaName, schemaConfig.typeFilter);
|
|
1644
4755
|
}
|
|
1645
4756
|
}
|
|
1646
|
-
const { code: internalCode, injectsCode, categoryVars } =
|
|
4757
|
+
const { code: internalCode, injectsCode, categoryVars } = generateMultiSchemaModule(schemas, {
|
|
1647
4758
|
injection: injectionConfig,
|
|
1648
4759
|
defaultInputDepth: defaultInputDepthConfig.size > 0 ? defaultInputDepthConfig : undefined,
|
|
1649
4760
|
inputDepthOverrides: inputDepthOverridesConfig.size > 0 ? inputDepthOverridesConfig : undefined,
|
|
1650
4761
|
chunkSize,
|
|
1651
4762
|
typeFilters: typeFiltersConfig.size > 0 ? typeFiltersConfig : undefined
|
|
1652
4763
|
});
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1655
|
-
* @module
|
|
1656
|
-
* @generated
|
|
1657
|
-
*/
|
|
1658
|
-
export * from "./_internal";
|
|
1659
|
-
`;
|
|
4764
|
+
const schemaNames = Object.keys(options.schemas);
|
|
4765
|
+
const allFieldNames = new Map();
|
|
1660
4766
|
for (const [name, document] of schemas.entries()) {
|
|
1661
|
-
const schemaIndex =
|
|
4767
|
+
const schemaIndex = createSchemaIndex(document);
|
|
4768
|
+
const fieldNameSet = new Set();
|
|
4769
|
+
for (const [objectName, record] of schemaIndex.objects.entries()) {
|
|
4770
|
+
if (objectName.startsWith("__")) continue;
|
|
4771
|
+
for (const fieldName of record.fields.keys()) {
|
|
4772
|
+
fieldNameSet.add(fieldName);
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
allFieldNames.set(name, Array.from(fieldNameSet).sort());
|
|
1662
4776
|
const objects = Array.from(schemaIndex.objects.keys()).filter((n) => !n.startsWith("__")).length;
|
|
1663
4777
|
const enums = Array.from(schemaIndex.enums.keys()).filter((n) => !n.startsWith("__")).length;
|
|
1664
4778
|
const inputs = Array.from(schemaIndex.inputs.keys()).filter((n) => !n.startsWith("__")).length;
|
|
@@ -1671,6 +4785,7 @@ export * from "./_internal";
|
|
|
1671
4785
|
unions
|
|
1672
4786
|
};
|
|
1673
4787
|
}
|
|
4788
|
+
const indexCode = generateIndexModule(schemaNames, allFieldNames);
|
|
1674
4789
|
const injectsPath = (0, node_path.join)((0, node_path.dirname)(outPath), "_internal-injects.ts");
|
|
1675
4790
|
if (injectsCode) {
|
|
1676
4791
|
const injectsWriteResult = await writeModule(injectsPath, injectsCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
@@ -1719,6 +4834,35 @@ export * from "./_internal";
|
|
|
1719
4834
|
if (indexWriteResult.isErr()) {
|
|
1720
4835
|
return (0, neverthrow.err)(indexWriteResult.error);
|
|
1721
4836
|
}
|
|
4837
|
+
const prebuiltStubPath = (0, node_path.join)((0, node_path.dirname)(outPath), "types.prebuilt.ts");
|
|
4838
|
+
if (!(0, node_fs.existsSync)(prebuiltStubPath)) {
|
|
4839
|
+
const prebuiltStubCode = generatePrebuiltStub(schemaNames);
|
|
4840
|
+
const prebuiltWriteResult = await writeModule(prebuiltStubPath, prebuiltStubCode).match(() => Promise.resolve((0, neverthrow.ok)(undefined)), (error) => Promise.resolve((0, neverthrow.err)(error)));
|
|
4841
|
+
if (prebuiltWriteResult.isErr()) {
|
|
4842
|
+
return (0, neverthrow.err)(prebuiltWriteResult.error);
|
|
4843
|
+
}
|
|
4844
|
+
} else {
|
|
4845
|
+
const readResult = readModule(prebuiltStubPath);
|
|
4846
|
+
if (readResult.isErr()) {
|
|
4847
|
+
return (0, neverthrow.err)(readResult.error);
|
|
4848
|
+
}
|
|
4849
|
+
const existingContent = readResult.value;
|
|
4850
|
+
const existingNames = new Set();
|
|
4851
|
+
for (const match of existingContent.matchAll(/export type PrebuiltTypes_(\w+)/g)) {
|
|
4852
|
+
const name = match[1];
|
|
4853
|
+
if (name) existingNames.add(name);
|
|
4854
|
+
}
|
|
4855
|
+
const missingNames = schemaNames.filter((name) => !existingNames.has(name));
|
|
4856
|
+
if (missingNames.length > 0) {
|
|
4857
|
+
const missingStubs = generatePrebuiltStub(missingNames);
|
|
4858
|
+
const stubDeclarations = missingStubs.replace(/^\/\*\*[\s\S]*?\*\/\n\n/, "");
|
|
4859
|
+
const updatedContent = `${existingContent.trimEnd()}\n\n${stubDeclarations}`;
|
|
4860
|
+
const patchResult = writeModule(prebuiltStubPath, updatedContent);
|
|
4861
|
+
if (patchResult.isErr()) {
|
|
4862
|
+
return (0, neverthrow.err)(patchResult.error);
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
1722
4866
|
const bundleOutcome = await esbuildBundler.bundle({
|
|
1723
4867
|
sourcePath: outPath,
|
|
1724
4868
|
external: ["@soda-gql/core", "@soda-gql/runtime"]
|
|
@@ -1739,6 +4883,8 @@ export * from "./_internal";
|
|
|
1739
4883
|
|
|
1740
4884
|
//#endregion
|
|
1741
4885
|
exports.collectVariableUsages = collectVariableUsages;
|
|
4886
|
+
exports.compileTypeFilter = compileTypeFilter;
|
|
4887
|
+
exports.computeReachabilityFilter = computeReachabilityFilter;
|
|
1742
4888
|
exports.emitFragment = emitFragment;
|
|
1743
4889
|
exports.emitOperation = emitOperation;
|
|
1744
4890
|
exports.getArgumentType = getArgumentType;
|