orval 7.11.2 → 7.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/bin/orval.js CHANGED
@@ -1,4557 +1,63 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // src/bin/orval.ts
27
- var import_core13 = require("@orval/core");
28
- var import_cac = require("cac");
29
-
30
- // src/generate.ts
31
- var import_core12 = require("@orval/core");
32
-
33
- // src/import-specs.ts
34
- var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"));
35
- var import_core4 = require("@orval/core");
36
- var import_chalk = __toESM(require("chalk"));
37
-
38
- // ../../node_modules/js-yaml/dist/js-yaml.mjs
39
- function isNothing(subject) {
40
- return typeof subject === "undefined" || subject === null;
41
- }
42
- function isObject(subject) {
43
- return typeof subject === "object" && subject !== null;
44
- }
45
- function toArray(sequence) {
46
- if (Array.isArray(sequence)) return sequence;
47
- else if (isNothing(sequence)) return [];
48
- return [sequence];
49
- }
50
- function extend(target, source) {
51
- var index, length, key, sourceKeys;
52
- if (source) {
53
- sourceKeys = Object.keys(source);
54
- for (index = 0, length = sourceKeys.length; index < length; index += 1) {
55
- key = sourceKeys[index];
56
- target[key] = source[key];
57
- }
58
- }
59
- return target;
60
- }
61
- function repeat(string, count) {
62
- var result = "", cycle;
63
- for (cycle = 0; cycle < count; cycle += 1) {
64
- result += string;
65
- }
66
- return result;
67
- }
68
- function isNegativeZero(number) {
69
- return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
70
- }
71
- var isNothing_1 = isNothing;
72
- var isObject_1 = isObject;
73
- var toArray_1 = toArray;
74
- var repeat_1 = repeat;
75
- var isNegativeZero_1 = isNegativeZero;
76
- var extend_1 = extend;
77
- var common = {
78
- isNothing: isNothing_1,
79
- isObject: isObject_1,
80
- toArray: toArray_1,
81
- repeat: repeat_1,
82
- isNegativeZero: isNegativeZero_1,
83
- extend: extend_1
84
- };
85
- function formatError(exception2, compact) {
86
- var where = "", message = exception2.reason || "(unknown reason)";
87
- if (!exception2.mark) return message;
88
- if (exception2.mark.name) {
89
- where += 'in "' + exception2.mark.name + '" ';
90
- }
91
- where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
92
- if (!compact && exception2.mark.snippet) {
93
- where += "\n\n" + exception2.mark.snippet;
94
- }
95
- return message + " " + where;
96
- }
97
- function YAMLException$1(reason, mark) {
98
- Error.call(this);
99
- this.name = "YAMLException";
100
- this.reason = reason;
101
- this.mark = mark;
102
- this.message = formatError(this, false);
103
- if (Error.captureStackTrace) {
104
- Error.captureStackTrace(this, this.constructor);
105
- } else {
106
- this.stack = new Error().stack || "";
107
- }
108
- }
109
- YAMLException$1.prototype = Object.create(Error.prototype);
110
- YAMLException$1.prototype.constructor = YAMLException$1;
111
- YAMLException$1.prototype.toString = function toString(compact) {
112
- return this.name + ": " + formatError(this, compact);
113
- };
114
- var exception = YAMLException$1;
115
- function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
116
- var head = "";
117
- var tail = "";
118
- var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
119
- if (position - lineStart > maxHalfLength) {
120
- head = " ... ";
121
- lineStart = position - maxHalfLength + head.length;
122
- }
123
- if (lineEnd - position > maxHalfLength) {
124
- tail = " ...";
125
- lineEnd = position + maxHalfLength - tail.length;
126
- }
127
- return {
128
- str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
129
- pos: position - lineStart + head.length
130
- // relative position
131
- };
132
- }
133
- function padStart(string, max) {
134
- return common.repeat(" ", max - string.length) + string;
135
- }
136
- function makeSnippet(mark, options) {
137
- options = Object.create(options || null);
138
- if (!mark.buffer) return null;
139
- if (!options.maxLength) options.maxLength = 79;
140
- if (typeof options.indent !== "number") options.indent = 1;
141
- if (typeof options.linesBefore !== "number") options.linesBefore = 3;
142
- if (typeof options.linesAfter !== "number") options.linesAfter = 2;
143
- var re = /\r?\n|\r|\0/g;
144
- var lineStarts = [0];
145
- var lineEnds = [];
146
- var match;
147
- var foundLineNo = -1;
148
- while (match = re.exec(mark.buffer)) {
149
- lineEnds.push(match.index);
150
- lineStarts.push(match.index + match[0].length);
151
- if (mark.position <= match.index && foundLineNo < 0) {
152
- foundLineNo = lineStarts.length - 2;
153
- }
154
- }
155
- if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
156
- var result = "", i, line;
157
- var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
158
- var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
159
- for (i = 1; i <= options.linesBefore; i++) {
160
- if (foundLineNo - i < 0) break;
161
- line = getLine(
162
- mark.buffer,
163
- lineStarts[foundLineNo - i],
164
- lineEnds[foundLineNo - i],
165
- mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
166
- maxLineLength
167
- );
168
- result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
169
- }
170
- line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
171
- result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
172
- result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
173
- for (i = 1; i <= options.linesAfter; i++) {
174
- if (foundLineNo + i >= lineEnds.length) break;
175
- line = getLine(
176
- mark.buffer,
177
- lineStarts[foundLineNo + i],
178
- lineEnds[foundLineNo + i],
179
- mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
180
- maxLineLength
181
- );
182
- result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
183
- }
184
- return result.replace(/\n$/, "");
185
- }
186
- var snippet = makeSnippet;
187
- var TYPE_CONSTRUCTOR_OPTIONS = [
188
- "kind",
189
- "multi",
190
- "resolve",
191
- "construct",
192
- "instanceOf",
193
- "predicate",
194
- "represent",
195
- "representName",
196
- "defaultStyle",
197
- "styleAliases"
198
- ];
199
- var YAML_NODE_KINDS = [
200
- "scalar",
201
- "sequence",
202
- "mapping"
203
- ];
204
- function compileStyleAliases(map2) {
205
- var result = {};
206
- if (map2 !== null) {
207
- Object.keys(map2).forEach(function(style) {
208
- map2[style].forEach(function(alias) {
209
- result[String(alias)] = style;
210
- });
211
- });
212
- }
213
- return result;
214
- }
215
- function Type$1(tag, options) {
216
- options = options || {};
217
- Object.keys(options).forEach(function(name) {
218
- if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
219
- throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
220
- }
221
- });
222
- this.options = options;
223
- this.tag = tag;
224
- this.kind = options["kind"] || null;
225
- this.resolve = options["resolve"] || function() {
226
- return true;
227
- };
228
- this.construct = options["construct"] || function(data) {
229
- return data;
230
- };
231
- this.instanceOf = options["instanceOf"] || null;
232
- this.predicate = options["predicate"] || null;
233
- this.represent = options["represent"] || null;
234
- this.representName = options["representName"] || null;
235
- this.defaultStyle = options["defaultStyle"] || null;
236
- this.multi = options["multi"] || false;
237
- this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
238
- if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
239
- throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
240
- }
241
- }
242
- var type = Type$1;
243
- function compileList(schema2, name) {
244
- var result = [];
245
- schema2[name].forEach(function(currentType) {
246
- var newIndex = result.length;
247
- result.forEach(function(previousType, previousIndex) {
248
- if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
249
- newIndex = previousIndex;
250
- }
251
- });
252
- result[newIndex] = currentType;
253
- });
254
- return result;
255
- }
256
- function compileMap() {
257
- var result = {
258
- scalar: {},
259
- sequence: {},
260
- mapping: {},
261
- fallback: {},
262
- multi: {
263
- scalar: [],
264
- sequence: [],
265
- mapping: [],
266
- fallback: []
267
- }
268
- }, index, length;
269
- function collectType(type2) {
270
- if (type2.multi) {
271
- result.multi[type2.kind].push(type2);
272
- result.multi["fallback"].push(type2);
273
- } else {
274
- result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
275
- }
276
- }
277
- for (index = 0, length = arguments.length; index < length; index += 1) {
278
- arguments[index].forEach(collectType);
279
- }
280
- return result;
281
- }
282
- function Schema$1(definition) {
283
- return this.extend(definition);
284
- }
285
- Schema$1.prototype.extend = function extend2(definition) {
286
- var implicit = [];
287
- var explicit = [];
288
- if (definition instanceof type) {
289
- explicit.push(definition);
290
- } else if (Array.isArray(definition)) {
291
- explicit = explicit.concat(definition);
292
- } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
293
- if (definition.implicit) implicit = implicit.concat(definition.implicit);
294
- if (definition.explicit) explicit = explicit.concat(definition.explicit);
295
- } else {
296
- throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
297
- }
298
- implicit.forEach(function(type$1) {
299
- if (!(type$1 instanceof type)) {
300
- throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
301
- }
302
- if (type$1.loadKind && type$1.loadKind !== "scalar") {
303
- throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
304
- }
305
- if (type$1.multi) {
306
- throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
307
- }
308
- });
309
- explicit.forEach(function(type$1) {
310
- if (!(type$1 instanceof type)) {
311
- throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
312
- }
313
- });
314
- var result = Object.create(Schema$1.prototype);
315
- result.implicit = (this.implicit || []).concat(implicit);
316
- result.explicit = (this.explicit || []).concat(explicit);
317
- result.compiledImplicit = compileList(result, "implicit");
318
- result.compiledExplicit = compileList(result, "explicit");
319
- result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
320
- return result;
321
- };
322
- var schema = Schema$1;
323
- var str = new type("tag:yaml.org,2002:str", {
324
- kind: "scalar",
325
- construct: function(data) {
326
- return data !== null ? data : "";
327
- }
328
- });
329
- var seq = new type("tag:yaml.org,2002:seq", {
330
- kind: "sequence",
331
- construct: function(data) {
332
- return data !== null ? data : [];
333
- }
334
- });
335
- var map = new type("tag:yaml.org,2002:map", {
336
- kind: "mapping",
337
- construct: function(data) {
338
- return data !== null ? data : {};
339
- }
340
- });
341
- var failsafe = new schema({
342
- explicit: [
343
- str,
344
- seq,
345
- map
346
- ]
347
- });
348
- function resolveYamlNull(data) {
349
- if (data === null) return true;
350
- var max = data.length;
351
- return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
352
- }
353
- function constructYamlNull() {
354
- return null;
355
- }
356
- function isNull(object) {
357
- return object === null;
358
- }
359
- var _null = new type("tag:yaml.org,2002:null", {
360
- kind: "scalar",
361
- resolve: resolveYamlNull,
362
- construct: constructYamlNull,
363
- predicate: isNull,
364
- represent: {
365
- canonical: function() {
366
- return "~";
367
- },
368
- lowercase: function() {
369
- return "null";
370
- },
371
- uppercase: function() {
372
- return "NULL";
373
- },
374
- camelcase: function() {
375
- return "Null";
376
- },
377
- empty: function() {
378
- return "";
379
- }
380
- },
381
- defaultStyle: "lowercase"
382
- });
383
- function resolveYamlBoolean(data) {
384
- if (data === null) return false;
385
- var max = data.length;
386
- return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
387
- }
388
- function constructYamlBoolean(data) {
389
- return data === "true" || data === "True" || data === "TRUE";
390
- }
391
- function isBoolean(object) {
392
- return Object.prototype.toString.call(object) === "[object Boolean]";
393
- }
394
- var bool = new type("tag:yaml.org,2002:bool", {
395
- kind: "scalar",
396
- resolve: resolveYamlBoolean,
397
- construct: constructYamlBoolean,
398
- predicate: isBoolean,
399
- represent: {
400
- lowercase: function(object) {
401
- return object ? "true" : "false";
402
- },
403
- uppercase: function(object) {
404
- return object ? "TRUE" : "FALSE";
405
- },
406
- camelcase: function(object) {
407
- return object ? "True" : "False";
408
- }
409
- },
410
- defaultStyle: "lowercase"
411
- });
412
- function isHexCode(c) {
413
- return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
414
- }
415
- function isOctCode(c) {
416
- return 48 <= c && c <= 55;
417
- }
418
- function isDecCode(c) {
419
- return 48 <= c && c <= 57;
420
- }
421
- function resolveYamlInteger(data) {
422
- if (data === null) return false;
423
- var max = data.length, index = 0, hasDigits = false, ch;
424
- if (!max) return false;
425
- ch = data[index];
426
- if (ch === "-" || ch === "+") {
427
- ch = data[++index];
428
- }
429
- if (ch === "0") {
430
- if (index + 1 === max) return true;
431
- ch = data[++index];
432
- if (ch === "b") {
433
- index++;
434
- for (; index < max; index++) {
435
- ch = data[index];
436
- if (ch === "_") continue;
437
- if (ch !== "0" && ch !== "1") return false;
438
- hasDigits = true;
439
- }
440
- return hasDigits && ch !== "_";
441
- }
442
- if (ch === "x") {
443
- index++;
444
- for (; index < max; index++) {
445
- ch = data[index];
446
- if (ch === "_") continue;
447
- if (!isHexCode(data.charCodeAt(index))) return false;
448
- hasDigits = true;
449
- }
450
- return hasDigits && ch !== "_";
451
- }
452
- if (ch === "o") {
453
- index++;
454
- for (; index < max; index++) {
455
- ch = data[index];
456
- if (ch === "_") continue;
457
- if (!isOctCode(data.charCodeAt(index))) return false;
458
- hasDigits = true;
459
- }
460
- return hasDigits && ch !== "_";
461
- }
462
- }
463
- if (ch === "_") return false;
464
- for (; index < max; index++) {
465
- ch = data[index];
466
- if (ch === "_") continue;
467
- if (!isDecCode(data.charCodeAt(index))) {
468
- return false;
469
- }
470
- hasDigits = true;
471
- }
472
- if (!hasDigits || ch === "_") return false;
473
- return true;
474
- }
475
- function constructYamlInteger(data) {
476
- var value = data, sign = 1, ch;
477
- if (value.indexOf("_") !== -1) {
478
- value = value.replace(/_/g, "");
479
- }
480
- ch = value[0];
481
- if (ch === "-" || ch === "+") {
482
- if (ch === "-") sign = -1;
483
- value = value.slice(1);
484
- ch = value[0];
485
- }
486
- if (value === "0") return 0;
487
- if (ch === "0") {
488
- if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
489
- if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
490
- if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
491
- }
492
- return sign * parseInt(value, 10);
493
- }
494
- function isInteger(object) {
495
- return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
496
- }
497
- var int = new type("tag:yaml.org,2002:int", {
498
- kind: "scalar",
499
- resolve: resolveYamlInteger,
500
- construct: constructYamlInteger,
501
- predicate: isInteger,
502
- represent: {
503
- binary: function(obj) {
504
- return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
505
- },
506
- octal: function(obj) {
507
- return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
508
- },
509
- decimal: function(obj) {
510
- return obj.toString(10);
511
- },
512
- /* eslint-disable max-len */
513
- hexadecimal: function(obj) {
514
- return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
515
- }
516
- },
517
- defaultStyle: "decimal",
518
- styleAliases: {
519
- binary: [2, "bin"],
520
- octal: [8, "oct"],
521
- decimal: [10, "dec"],
522
- hexadecimal: [16, "hex"]
523
- }
524
- });
525
- var YAML_FLOAT_PATTERN = new RegExp(
526
- // 2.5e4, 2.5 and integers
527
- "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
528
- );
529
- function resolveYamlFloat(data) {
530
- if (data === null) return false;
531
- if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
532
- // Probably should update regexp & check speed
533
- data[data.length - 1] === "_") {
534
- return false;
535
- }
536
- return true;
537
- }
538
- function constructYamlFloat(data) {
539
- var value, sign;
540
- value = data.replace(/_/g, "").toLowerCase();
541
- sign = value[0] === "-" ? -1 : 1;
542
- if ("+-".indexOf(value[0]) >= 0) {
543
- value = value.slice(1);
544
- }
545
- if (value === ".inf") {
546
- return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
547
- } else if (value === ".nan") {
548
- return NaN;
549
- }
550
- return sign * parseFloat(value, 10);
551
- }
552
- var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
553
- function representYamlFloat(object, style) {
554
- var res;
555
- if (isNaN(object)) {
556
- switch (style) {
557
- case "lowercase":
558
- return ".nan";
559
- case "uppercase":
560
- return ".NAN";
561
- case "camelcase":
562
- return ".NaN";
563
- }
564
- } else if (Number.POSITIVE_INFINITY === object) {
565
- switch (style) {
566
- case "lowercase":
567
- return ".inf";
568
- case "uppercase":
569
- return ".INF";
570
- case "camelcase":
571
- return ".Inf";
572
- }
573
- } else if (Number.NEGATIVE_INFINITY === object) {
574
- switch (style) {
575
- case "lowercase":
576
- return "-.inf";
577
- case "uppercase":
578
- return "-.INF";
579
- case "camelcase":
580
- return "-.Inf";
581
- }
582
- } else if (common.isNegativeZero(object)) {
583
- return "-0.0";
584
- }
585
- res = object.toString(10);
586
- return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
587
- }
588
- function isFloat(object) {
589
- return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
590
- }
591
- var float = new type("tag:yaml.org,2002:float", {
592
- kind: "scalar",
593
- resolve: resolveYamlFloat,
594
- construct: constructYamlFloat,
595
- predicate: isFloat,
596
- represent: representYamlFloat,
597
- defaultStyle: "lowercase"
598
- });
599
- var json = failsafe.extend({
600
- implicit: [
601
- _null,
602
- bool,
603
- int,
604
- float
605
- ]
606
- });
607
- var core = json;
608
- var YAML_DATE_REGEXP = new RegExp(
609
- "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
610
- );
611
- var YAML_TIMESTAMP_REGEXP = new RegExp(
612
- "^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
613
- );
614
- function resolveYamlTimestamp(data) {
615
- if (data === null) return false;
616
- if (YAML_DATE_REGEXP.exec(data) !== null) return true;
617
- if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
618
- return false;
619
- }
620
- function constructYamlTimestamp(data) {
621
- var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
622
- match = YAML_DATE_REGEXP.exec(data);
623
- if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
624
- if (match === null) throw new Error("Date resolve error");
625
- year = +match[1];
626
- month = +match[2] - 1;
627
- day = +match[3];
628
- if (!match[4]) {
629
- return new Date(Date.UTC(year, month, day));
630
- }
631
- hour = +match[4];
632
- minute = +match[5];
633
- second = +match[6];
634
- if (match[7]) {
635
- fraction = match[7].slice(0, 3);
636
- while (fraction.length < 3) {
637
- fraction += "0";
638
- }
639
- fraction = +fraction;
640
- }
641
- if (match[9]) {
642
- tz_hour = +match[10];
643
- tz_minute = +(match[11] || 0);
644
- delta = (tz_hour * 60 + tz_minute) * 6e4;
645
- if (match[9] === "-") delta = -delta;
646
- }
647
- date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
648
- if (delta) date.setTime(date.getTime() - delta);
649
- return date;
650
- }
651
- function representYamlTimestamp(object) {
652
- return object.toISOString();
653
- }
654
- var timestamp = new type("tag:yaml.org,2002:timestamp", {
655
- kind: "scalar",
656
- resolve: resolveYamlTimestamp,
657
- construct: constructYamlTimestamp,
658
- instanceOf: Date,
659
- represent: representYamlTimestamp
660
- });
661
- function resolveYamlMerge(data) {
662
- return data === "<<" || data === null;
663
- }
664
- var merge = new type("tag:yaml.org,2002:merge", {
665
- kind: "scalar",
666
- resolve: resolveYamlMerge
667
- });
668
- var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
669
- function resolveYamlBinary(data) {
670
- if (data === null) return false;
671
- var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
672
- for (idx = 0; idx < max; idx++) {
673
- code = map2.indexOf(data.charAt(idx));
674
- if (code > 64) continue;
675
- if (code < 0) return false;
676
- bitlen += 6;
677
- }
678
- return bitlen % 8 === 0;
679
- }
680
- function constructYamlBinary(data) {
681
- var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
682
- for (idx = 0; idx < max; idx++) {
683
- if (idx % 4 === 0 && idx) {
684
- result.push(bits >> 16 & 255);
685
- result.push(bits >> 8 & 255);
686
- result.push(bits & 255);
687
- }
688
- bits = bits << 6 | map2.indexOf(input.charAt(idx));
689
- }
690
- tailbits = max % 4 * 6;
691
- if (tailbits === 0) {
692
- result.push(bits >> 16 & 255);
693
- result.push(bits >> 8 & 255);
694
- result.push(bits & 255);
695
- } else if (tailbits === 18) {
696
- result.push(bits >> 10 & 255);
697
- result.push(bits >> 2 & 255);
698
- } else if (tailbits === 12) {
699
- result.push(bits >> 4 & 255);
700
- }
701
- return new Uint8Array(result);
702
- }
703
- function representYamlBinary(object) {
704
- var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
705
- for (idx = 0; idx < max; idx++) {
706
- if (idx % 3 === 0 && idx) {
707
- result += map2[bits >> 18 & 63];
708
- result += map2[bits >> 12 & 63];
709
- result += map2[bits >> 6 & 63];
710
- result += map2[bits & 63];
711
- }
712
- bits = (bits << 8) + object[idx];
713
- }
714
- tail = max % 3;
715
- if (tail === 0) {
716
- result += map2[bits >> 18 & 63];
717
- result += map2[bits >> 12 & 63];
718
- result += map2[bits >> 6 & 63];
719
- result += map2[bits & 63];
720
- } else if (tail === 2) {
721
- result += map2[bits >> 10 & 63];
722
- result += map2[bits >> 4 & 63];
723
- result += map2[bits << 2 & 63];
724
- result += map2[64];
725
- } else if (tail === 1) {
726
- result += map2[bits >> 2 & 63];
727
- result += map2[bits << 4 & 63];
728
- result += map2[64];
729
- result += map2[64];
730
- }
731
- return result;
732
- }
733
- function isBinary(obj) {
734
- return Object.prototype.toString.call(obj) === "[object Uint8Array]";
735
- }
736
- var binary = new type("tag:yaml.org,2002:binary", {
737
- kind: "scalar",
738
- resolve: resolveYamlBinary,
739
- construct: constructYamlBinary,
740
- predicate: isBinary,
741
- represent: representYamlBinary
742
- });
743
- var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
744
- var _toString$2 = Object.prototype.toString;
745
- function resolveYamlOmap(data) {
746
- if (data === null) return true;
747
- var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
748
- for (index = 0, length = object.length; index < length; index += 1) {
749
- pair = object[index];
750
- pairHasKey = false;
751
- if (_toString$2.call(pair) !== "[object Object]") return false;
752
- for (pairKey in pair) {
753
- if (_hasOwnProperty$3.call(pair, pairKey)) {
754
- if (!pairHasKey) pairHasKey = true;
755
- else return false;
756
- }
757
- }
758
- if (!pairHasKey) return false;
759
- if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
760
- else return false;
761
- }
762
- return true;
763
- }
764
- function constructYamlOmap(data) {
765
- return data !== null ? data : [];
766
- }
767
- var omap = new type("tag:yaml.org,2002:omap", {
768
- kind: "sequence",
769
- resolve: resolveYamlOmap,
770
- construct: constructYamlOmap
771
- });
772
- var _toString$1 = Object.prototype.toString;
773
- function resolveYamlPairs(data) {
774
- if (data === null) return true;
775
- var index, length, pair, keys, result, object = data;
776
- result = new Array(object.length);
777
- for (index = 0, length = object.length; index < length; index += 1) {
778
- pair = object[index];
779
- if (_toString$1.call(pair) !== "[object Object]") return false;
780
- keys = Object.keys(pair);
781
- if (keys.length !== 1) return false;
782
- result[index] = [keys[0], pair[keys[0]]];
783
- }
784
- return true;
785
- }
786
- function constructYamlPairs(data) {
787
- if (data === null) return [];
788
- var index, length, pair, keys, result, object = data;
789
- result = new Array(object.length);
790
- for (index = 0, length = object.length; index < length; index += 1) {
791
- pair = object[index];
792
- keys = Object.keys(pair);
793
- result[index] = [keys[0], pair[keys[0]]];
794
- }
795
- return result;
796
- }
797
- var pairs = new type("tag:yaml.org,2002:pairs", {
798
- kind: "sequence",
799
- resolve: resolveYamlPairs,
800
- construct: constructYamlPairs
801
- });
802
- var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
803
- function resolveYamlSet(data) {
804
- if (data === null) return true;
805
- var key, object = data;
806
- for (key in object) {
807
- if (_hasOwnProperty$2.call(object, key)) {
808
- if (object[key] !== null) return false;
809
- }
810
- }
811
- return true;
812
- }
813
- function constructYamlSet(data) {
814
- return data !== null ? data : {};
815
- }
816
- var set = new type("tag:yaml.org,2002:set", {
817
- kind: "mapping",
818
- resolve: resolveYamlSet,
819
- construct: constructYamlSet
820
- });
821
- var _default = core.extend({
822
- implicit: [
823
- timestamp,
824
- merge
825
- ],
826
- explicit: [
827
- binary,
828
- omap,
829
- pairs,
830
- set
831
- ]
832
- });
833
- var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
834
- var CONTEXT_FLOW_IN = 1;
835
- var CONTEXT_FLOW_OUT = 2;
836
- var CONTEXT_BLOCK_IN = 3;
837
- var CONTEXT_BLOCK_OUT = 4;
838
- var CHOMPING_CLIP = 1;
839
- var CHOMPING_STRIP = 2;
840
- var CHOMPING_KEEP = 3;
841
- var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
842
- var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
843
- var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
844
- var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
845
- var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
846
- function _class(obj) {
847
- return Object.prototype.toString.call(obj);
848
- }
849
- function is_EOL(c) {
850
- return c === 10 || c === 13;
851
- }
852
- function is_WHITE_SPACE(c) {
853
- return c === 9 || c === 32;
854
- }
855
- function is_WS_OR_EOL(c) {
856
- return c === 9 || c === 32 || c === 10 || c === 13;
857
- }
858
- function is_FLOW_INDICATOR(c) {
859
- return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
860
- }
861
- function fromHexCode(c) {
862
- var lc;
863
- if (48 <= c && c <= 57) {
864
- return c - 48;
865
- }
866
- lc = c | 32;
867
- if (97 <= lc && lc <= 102) {
868
- return lc - 97 + 10;
869
- }
870
- return -1;
871
- }
872
- function escapedHexLen(c) {
873
- if (c === 120) {
874
- return 2;
875
- }
876
- if (c === 117) {
877
- return 4;
878
- }
879
- if (c === 85) {
880
- return 8;
881
- }
882
- return 0;
883
- }
884
- function fromDecimalCode(c) {
885
- if (48 <= c && c <= 57) {
886
- return c - 48;
887
- }
888
- return -1;
889
- }
890
- function simpleEscapeSequence(c) {
891
- return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
892
- }
893
- function charFromCodepoint(c) {
894
- if (c <= 65535) {
895
- return String.fromCharCode(c);
896
- }
897
- return String.fromCharCode(
898
- (c - 65536 >> 10) + 55296,
899
- (c - 65536 & 1023) + 56320
900
- );
901
- }
902
- var simpleEscapeCheck = new Array(256);
903
- var simpleEscapeMap = new Array(256);
904
- for (i = 0; i < 256; i++) {
905
- simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
906
- simpleEscapeMap[i] = simpleEscapeSequence(i);
907
- }
908
- var i;
909
- function State$1(input, options) {
910
- this.input = input;
911
- this.filename = options["filename"] || null;
912
- this.schema = options["schema"] || _default;
913
- this.onWarning = options["onWarning"] || null;
914
- this.legacy = options["legacy"] || false;
915
- this.json = options["json"] || false;
916
- this.listener = options["listener"] || null;
917
- this.implicitTypes = this.schema.compiledImplicit;
918
- this.typeMap = this.schema.compiledTypeMap;
919
- this.length = input.length;
920
- this.position = 0;
921
- this.line = 0;
922
- this.lineStart = 0;
923
- this.lineIndent = 0;
924
- this.firstTabInLine = -1;
925
- this.documents = [];
926
- }
927
- function generateError(state, message) {
928
- var mark = {
929
- name: state.filename,
930
- buffer: state.input.slice(0, -1),
931
- // omit trailing \0
932
- position: state.position,
933
- line: state.line,
934
- column: state.position - state.lineStart
935
- };
936
- mark.snippet = snippet(mark);
937
- return new exception(message, mark);
938
- }
939
- function throwError(state, message) {
940
- throw generateError(state, message);
941
- }
942
- function throwWarning(state, message) {
943
- if (state.onWarning) {
944
- state.onWarning.call(null, generateError(state, message));
945
- }
946
- }
947
- var directiveHandlers = {
948
- YAML: function handleYamlDirective(state, name, args) {
949
- var match, major, minor;
950
- if (state.version !== null) {
951
- throwError(state, "duplication of %YAML directive");
952
- }
953
- if (args.length !== 1) {
954
- throwError(state, "YAML directive accepts exactly one argument");
955
- }
956
- match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
957
- if (match === null) {
958
- throwError(state, "ill-formed argument of the YAML directive");
959
- }
960
- major = parseInt(match[1], 10);
961
- minor = parseInt(match[2], 10);
962
- if (major !== 1) {
963
- throwError(state, "unacceptable YAML version of the document");
964
- }
965
- state.version = args[0];
966
- state.checkLineBreaks = minor < 2;
967
- if (minor !== 1 && minor !== 2) {
968
- throwWarning(state, "unsupported YAML version of the document");
969
- }
970
- },
971
- TAG: function handleTagDirective(state, name, args) {
972
- var handle, prefix;
973
- if (args.length !== 2) {
974
- throwError(state, "TAG directive accepts exactly two arguments");
975
- }
976
- handle = args[0];
977
- prefix = args[1];
978
- if (!PATTERN_TAG_HANDLE.test(handle)) {
979
- throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
980
- }
981
- if (_hasOwnProperty$1.call(state.tagMap, handle)) {
982
- throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
983
- }
984
- if (!PATTERN_TAG_URI.test(prefix)) {
985
- throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
986
- }
987
- try {
988
- prefix = decodeURIComponent(prefix);
989
- } catch (err) {
990
- throwError(state, "tag prefix is malformed: " + prefix);
991
- }
992
- state.tagMap[handle] = prefix;
993
- }
994
- };
995
- function captureSegment(state, start, end, checkJson) {
996
- var _position, _length, _character, _result;
997
- if (start < end) {
998
- _result = state.input.slice(start, end);
999
- if (checkJson) {
1000
- for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
1001
- _character = _result.charCodeAt(_position);
1002
- if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
1003
- throwError(state, "expected valid JSON character");
1004
- }
1005
- }
1006
- } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1007
- throwError(state, "the stream contains non-printable characters");
1008
- }
1009
- state.result += _result;
1010
- }
1011
- }
1012
- function mergeMappings(state, destination, source, overridableKeys) {
1013
- var sourceKeys, key, index, quantity;
1014
- if (!common.isObject(source)) {
1015
- throwError(state, "cannot merge mappings; the provided source object is unacceptable");
1016
- }
1017
- sourceKeys = Object.keys(source);
1018
- for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1019
- key = sourceKeys[index];
1020
- if (!_hasOwnProperty$1.call(destination, key)) {
1021
- destination[key] = source[key];
1022
- overridableKeys[key] = true;
1023
- }
1024
- }
1025
- }
1026
- function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
1027
- var index, quantity;
1028
- if (Array.isArray(keyNode)) {
1029
- keyNode = Array.prototype.slice.call(keyNode);
1030
- for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
1031
- if (Array.isArray(keyNode[index])) {
1032
- throwError(state, "nested arrays are not supported inside keys");
1033
- }
1034
- if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
1035
- keyNode[index] = "[object Object]";
1036
- }
1037
- }
1038
- }
1039
- if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
1040
- keyNode = "[object Object]";
1041
- }
1042
- keyNode = String(keyNode);
1043
- if (_result === null) {
1044
- _result = {};
1045
- }
1046
- if (keyTag === "tag:yaml.org,2002:merge") {
1047
- if (Array.isArray(valueNode)) {
1048
- for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1049
- mergeMappings(state, _result, valueNode[index], overridableKeys);
1050
- }
1051
- } else {
1052
- mergeMappings(state, _result, valueNode, overridableKeys);
1053
- }
1054
- } else {
1055
- if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
1056
- state.line = startLine || state.line;
1057
- state.lineStart = startLineStart || state.lineStart;
1058
- state.position = startPos || state.position;
1059
- throwError(state, "duplicated mapping key");
1060
- }
1061
- if (keyNode === "__proto__") {
1062
- Object.defineProperty(_result, keyNode, {
1063
- configurable: true,
1064
- enumerable: true,
1065
- writable: true,
1066
- value: valueNode
1067
- });
1068
- } else {
1069
- _result[keyNode] = valueNode;
1070
- }
1071
- delete overridableKeys[keyNode];
1072
- }
1073
- return _result;
1074
- }
1075
- function readLineBreak(state) {
1076
- var ch;
1077
- ch = state.input.charCodeAt(state.position);
1078
- if (ch === 10) {
1079
- state.position++;
1080
- } else if (ch === 13) {
1081
- state.position++;
1082
- if (state.input.charCodeAt(state.position) === 10) {
1083
- state.position++;
1084
- }
1085
- } else {
1086
- throwError(state, "a line break is expected");
1087
- }
1088
- state.line += 1;
1089
- state.lineStart = state.position;
1090
- state.firstTabInLine = -1;
1091
- }
1092
- function skipSeparationSpace(state, allowComments, checkIndent) {
1093
- var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
1094
- while (ch !== 0) {
1095
- while (is_WHITE_SPACE(ch)) {
1096
- if (ch === 9 && state.firstTabInLine === -1) {
1097
- state.firstTabInLine = state.position;
1098
- }
1099
- ch = state.input.charCodeAt(++state.position);
1100
- }
1101
- if (allowComments && ch === 35) {
1102
- do {
1103
- ch = state.input.charCodeAt(++state.position);
1104
- } while (ch !== 10 && ch !== 13 && ch !== 0);
1105
- }
1106
- if (is_EOL(ch)) {
1107
- readLineBreak(state);
1108
- ch = state.input.charCodeAt(state.position);
1109
- lineBreaks++;
1110
- state.lineIndent = 0;
1111
- while (ch === 32) {
1112
- state.lineIndent++;
1113
- ch = state.input.charCodeAt(++state.position);
1114
- }
1115
- } else {
1116
- break;
1117
- }
1118
- }
1119
- if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1120
- throwWarning(state, "deficient indentation");
1121
- }
1122
- return lineBreaks;
1123
- }
1124
- function testDocumentSeparator(state) {
1125
- var _position = state.position, ch;
1126
- ch = state.input.charCodeAt(_position);
1127
- if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
1128
- _position += 3;
1129
- ch = state.input.charCodeAt(_position);
1130
- if (ch === 0 || is_WS_OR_EOL(ch)) {
1131
- return true;
1132
- }
1133
- }
1134
- return false;
1135
- }
1136
- function writeFoldedLines(state, count) {
1137
- if (count === 1) {
1138
- state.result += " ";
1139
- } else if (count > 1) {
1140
- state.result += common.repeat("\n", count - 1);
1141
- }
1142
- }
1143
- function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1144
- var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
1145
- ch = state.input.charCodeAt(state.position);
1146
- if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
1147
- return false;
1148
- }
1149
- if (ch === 63 || ch === 45) {
1150
- following = state.input.charCodeAt(state.position + 1);
1151
- if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1152
- return false;
1153
- }
1154
- }
1155
- state.kind = "scalar";
1156
- state.result = "";
1157
- captureStart = captureEnd = state.position;
1158
- hasPendingContent = false;
1159
- while (ch !== 0) {
1160
- if (ch === 58) {
1161
- following = state.input.charCodeAt(state.position + 1);
1162
- if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1163
- break;
1164
- }
1165
- } else if (ch === 35) {
1166
- preceding = state.input.charCodeAt(state.position - 1);
1167
- if (is_WS_OR_EOL(preceding)) {
1168
- break;
1169
- }
1170
- } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1171
- break;
1172
- } else if (is_EOL(ch)) {
1173
- _line = state.line;
1174
- _lineStart = state.lineStart;
1175
- _lineIndent = state.lineIndent;
1176
- skipSeparationSpace(state, false, -1);
1177
- if (state.lineIndent >= nodeIndent) {
1178
- hasPendingContent = true;
1179
- ch = state.input.charCodeAt(state.position);
1180
- continue;
1181
- } else {
1182
- state.position = captureEnd;
1183
- state.line = _line;
1184
- state.lineStart = _lineStart;
1185
- state.lineIndent = _lineIndent;
1186
- break;
1187
- }
1188
- }
1189
- if (hasPendingContent) {
1190
- captureSegment(state, captureStart, captureEnd, false);
1191
- writeFoldedLines(state, state.line - _line);
1192
- captureStart = captureEnd = state.position;
1193
- hasPendingContent = false;
1194
- }
1195
- if (!is_WHITE_SPACE(ch)) {
1196
- captureEnd = state.position + 1;
1197
- }
1198
- ch = state.input.charCodeAt(++state.position);
1199
- }
1200
- captureSegment(state, captureStart, captureEnd, false);
1201
- if (state.result) {
1202
- return true;
1203
- }
1204
- state.kind = _kind;
1205
- state.result = _result;
1206
- return false;
1207
- }
1208
- function readSingleQuotedScalar(state, nodeIndent) {
1209
- var ch, captureStart, captureEnd;
1210
- ch = state.input.charCodeAt(state.position);
1211
- if (ch !== 39) {
1212
- return false;
1213
- }
1214
- state.kind = "scalar";
1215
- state.result = "";
1216
- state.position++;
1217
- captureStart = captureEnd = state.position;
1218
- while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1219
- if (ch === 39) {
1220
- captureSegment(state, captureStart, state.position, true);
1221
- ch = state.input.charCodeAt(++state.position);
1222
- if (ch === 39) {
1223
- captureStart = state.position;
1224
- state.position++;
1225
- captureEnd = state.position;
1226
- } else {
1227
- return true;
1228
- }
1229
- } else if (is_EOL(ch)) {
1230
- captureSegment(state, captureStart, captureEnd, true);
1231
- writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1232
- captureStart = captureEnd = state.position;
1233
- } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1234
- throwError(state, "unexpected end of the document within a single quoted scalar");
1235
- } else {
1236
- state.position++;
1237
- captureEnd = state.position;
1238
- }
1239
- }
1240
- throwError(state, "unexpected end of the stream within a single quoted scalar");
1241
- }
1242
- function readDoubleQuotedScalar(state, nodeIndent) {
1243
- var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
1244
- ch = state.input.charCodeAt(state.position);
1245
- if (ch !== 34) {
1246
- return false;
1247
- }
1248
- state.kind = "scalar";
1249
- state.result = "";
1250
- state.position++;
1251
- captureStart = captureEnd = state.position;
1252
- while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1253
- if (ch === 34) {
1254
- captureSegment(state, captureStart, state.position, true);
1255
- state.position++;
1256
- return true;
1257
- } else if (ch === 92) {
1258
- captureSegment(state, captureStart, state.position, true);
1259
- ch = state.input.charCodeAt(++state.position);
1260
- if (is_EOL(ch)) {
1261
- skipSeparationSpace(state, false, nodeIndent);
1262
- } else if (ch < 256 && simpleEscapeCheck[ch]) {
1263
- state.result += simpleEscapeMap[ch];
1264
- state.position++;
1265
- } else if ((tmp = escapedHexLen(ch)) > 0) {
1266
- hexLength = tmp;
1267
- hexResult = 0;
1268
- for (; hexLength > 0; hexLength--) {
1269
- ch = state.input.charCodeAt(++state.position);
1270
- if ((tmp = fromHexCode(ch)) >= 0) {
1271
- hexResult = (hexResult << 4) + tmp;
1272
- } else {
1273
- throwError(state, "expected hexadecimal character");
1274
- }
1275
- }
1276
- state.result += charFromCodepoint(hexResult);
1277
- state.position++;
1278
- } else {
1279
- throwError(state, "unknown escape sequence");
1280
- }
1281
- captureStart = captureEnd = state.position;
1282
- } else if (is_EOL(ch)) {
1283
- captureSegment(state, captureStart, captureEnd, true);
1284
- writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1285
- captureStart = captureEnd = state.position;
1286
- } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1287
- throwError(state, "unexpected end of the document within a double quoted scalar");
1288
- } else {
1289
- state.position++;
1290
- captureEnd = state.position;
1291
- }
1292
- }
1293
- throwError(state, "unexpected end of the stream within a double quoted scalar");
1294
- }
1295
- function readFlowCollection(state, nodeIndent) {
1296
- var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
1297
- ch = state.input.charCodeAt(state.position);
1298
- if (ch === 91) {
1299
- terminator = 93;
1300
- isMapping = false;
1301
- _result = [];
1302
- } else if (ch === 123) {
1303
- terminator = 125;
1304
- isMapping = true;
1305
- _result = {};
1306
- } else {
1307
- return false;
1308
- }
1309
- if (state.anchor !== null) {
1310
- state.anchorMap[state.anchor] = _result;
1311
- }
1312
- ch = state.input.charCodeAt(++state.position);
1313
- while (ch !== 0) {
1314
- skipSeparationSpace(state, true, nodeIndent);
1315
- ch = state.input.charCodeAt(state.position);
1316
- if (ch === terminator) {
1317
- state.position++;
1318
- state.tag = _tag;
1319
- state.anchor = _anchor;
1320
- state.kind = isMapping ? "mapping" : "sequence";
1321
- state.result = _result;
1322
- return true;
1323
- } else if (!readNext) {
1324
- throwError(state, "missed comma between flow collection entries");
1325
- } else if (ch === 44) {
1326
- throwError(state, "expected the node content, but found ','");
1327
- }
1328
- keyTag = keyNode = valueNode = null;
1329
- isPair = isExplicitPair = false;
1330
- if (ch === 63) {
1331
- following = state.input.charCodeAt(state.position + 1);
1332
- if (is_WS_OR_EOL(following)) {
1333
- isPair = isExplicitPair = true;
1334
- state.position++;
1335
- skipSeparationSpace(state, true, nodeIndent);
1336
- }
1337
- }
1338
- _line = state.line;
1339
- _lineStart = state.lineStart;
1340
- _pos = state.position;
1341
- composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1342
- keyTag = state.tag;
1343
- keyNode = state.result;
1344
- skipSeparationSpace(state, true, nodeIndent);
1345
- ch = state.input.charCodeAt(state.position);
1346
- if ((isExplicitPair || state.line === _line) && ch === 58) {
1347
- isPair = true;
1348
- ch = state.input.charCodeAt(++state.position);
1349
- skipSeparationSpace(state, true, nodeIndent);
1350
- composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1351
- valueNode = state.result;
1352
- }
1353
- if (isMapping) {
1354
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
1355
- } else if (isPair) {
1356
- _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
1357
- } else {
1358
- _result.push(keyNode);
1359
- }
1360
- skipSeparationSpace(state, true, nodeIndent);
1361
- ch = state.input.charCodeAt(state.position);
1362
- if (ch === 44) {
1363
- readNext = true;
1364
- ch = state.input.charCodeAt(++state.position);
1365
- } else {
1366
- readNext = false;
1367
- }
1368
- }
1369
- throwError(state, "unexpected end of the stream within a flow collection");
1370
- }
1371
- function readBlockScalar(state, nodeIndent) {
1372
- var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
1373
- ch = state.input.charCodeAt(state.position);
1374
- if (ch === 124) {
1375
- folding = false;
1376
- } else if (ch === 62) {
1377
- folding = true;
1378
- } else {
1379
- return false;
1380
- }
1381
- state.kind = "scalar";
1382
- state.result = "";
1383
- while (ch !== 0) {
1384
- ch = state.input.charCodeAt(++state.position);
1385
- if (ch === 43 || ch === 45) {
1386
- if (CHOMPING_CLIP === chomping) {
1387
- chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
1388
- } else {
1389
- throwError(state, "repeat of a chomping mode identifier");
1390
- }
1391
- } else if ((tmp = fromDecimalCode(ch)) >= 0) {
1392
- if (tmp === 0) {
1393
- throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1394
- } else if (!detectedIndent) {
1395
- textIndent = nodeIndent + tmp - 1;
1396
- detectedIndent = true;
1397
- } else {
1398
- throwError(state, "repeat of an indentation width identifier");
1399
- }
1400
- } else {
1401
- break;
1402
- }
1403
- }
1404
- if (is_WHITE_SPACE(ch)) {
1405
- do {
1406
- ch = state.input.charCodeAt(++state.position);
1407
- } while (is_WHITE_SPACE(ch));
1408
- if (ch === 35) {
1409
- do {
1410
- ch = state.input.charCodeAt(++state.position);
1411
- } while (!is_EOL(ch) && ch !== 0);
1412
- }
1413
- }
1414
- while (ch !== 0) {
1415
- readLineBreak(state);
1416
- state.lineIndent = 0;
1417
- ch = state.input.charCodeAt(state.position);
1418
- while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
1419
- state.lineIndent++;
1420
- ch = state.input.charCodeAt(++state.position);
1421
- }
1422
- if (!detectedIndent && state.lineIndent > textIndent) {
1423
- textIndent = state.lineIndent;
1424
- }
1425
- if (is_EOL(ch)) {
1426
- emptyLines++;
1427
- continue;
1428
- }
1429
- if (state.lineIndent < textIndent) {
1430
- if (chomping === CHOMPING_KEEP) {
1431
- state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1432
- } else if (chomping === CHOMPING_CLIP) {
1433
- if (didReadContent) {
1434
- state.result += "\n";
1435
- }
1436
- }
1437
- break;
1438
- }
1439
- if (folding) {
1440
- if (is_WHITE_SPACE(ch)) {
1441
- atMoreIndented = true;
1442
- state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1443
- } else if (atMoreIndented) {
1444
- atMoreIndented = false;
1445
- state.result += common.repeat("\n", emptyLines + 1);
1446
- } else if (emptyLines === 0) {
1447
- if (didReadContent) {
1448
- state.result += " ";
1449
- }
1450
- } else {
1451
- state.result += common.repeat("\n", emptyLines);
1452
- }
1453
- } else {
1454
- state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1455
- }
1456
- didReadContent = true;
1457
- detectedIndent = true;
1458
- emptyLines = 0;
1459
- captureStart = state.position;
1460
- while (!is_EOL(ch) && ch !== 0) {
1461
- ch = state.input.charCodeAt(++state.position);
1462
- }
1463
- captureSegment(state, captureStart, state.position, false);
1464
- }
1465
- return true;
1466
- }
1467
- function readBlockSequence(state, nodeIndent) {
1468
- var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
1469
- if (state.firstTabInLine !== -1) return false;
1470
- if (state.anchor !== null) {
1471
- state.anchorMap[state.anchor] = _result;
1472
- }
1473
- ch = state.input.charCodeAt(state.position);
1474
- while (ch !== 0) {
1475
- if (state.firstTabInLine !== -1) {
1476
- state.position = state.firstTabInLine;
1477
- throwError(state, "tab characters must not be used in indentation");
1478
- }
1479
- if (ch !== 45) {
1480
- break;
1481
- }
1482
- following = state.input.charCodeAt(state.position + 1);
1483
- if (!is_WS_OR_EOL(following)) {
1484
- break;
1485
- }
1486
- detected = true;
1487
- state.position++;
1488
- if (skipSeparationSpace(state, true, -1)) {
1489
- if (state.lineIndent <= nodeIndent) {
1490
- _result.push(null);
1491
- ch = state.input.charCodeAt(state.position);
1492
- continue;
1493
- }
1494
- }
1495
- _line = state.line;
1496
- composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
1497
- _result.push(state.result);
1498
- skipSeparationSpace(state, true, -1);
1499
- ch = state.input.charCodeAt(state.position);
1500
- if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
1501
- throwError(state, "bad indentation of a sequence entry");
1502
- } else if (state.lineIndent < nodeIndent) {
1503
- break;
1504
- }
1505
- }
1506
- if (detected) {
1507
- state.tag = _tag;
1508
- state.anchor = _anchor;
1509
- state.kind = "sequence";
1510
- state.result = _result;
1511
- return true;
1512
- }
1513
- return false;
1514
- }
1515
- function readBlockMapping(state, nodeIndent, flowIndent) {
1516
- var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
1517
- if (state.firstTabInLine !== -1) return false;
1518
- if (state.anchor !== null) {
1519
- state.anchorMap[state.anchor] = _result;
1520
- }
1521
- ch = state.input.charCodeAt(state.position);
1522
- while (ch !== 0) {
1523
- if (!atExplicitKey && state.firstTabInLine !== -1) {
1524
- state.position = state.firstTabInLine;
1525
- throwError(state, "tab characters must not be used in indentation");
1526
- }
1527
- following = state.input.charCodeAt(state.position + 1);
1528
- _line = state.line;
1529
- if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
1530
- if (ch === 63) {
1531
- if (atExplicitKey) {
1532
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1533
- keyTag = keyNode = valueNode = null;
1534
- }
1535
- detected = true;
1536
- atExplicitKey = true;
1537
- allowCompact = true;
1538
- } else if (atExplicitKey) {
1539
- atExplicitKey = false;
1540
- allowCompact = true;
1541
- } else {
1542
- throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
1543
- }
1544
- state.position += 1;
1545
- ch = following;
1546
- } else {
1547
- _keyLine = state.line;
1548
- _keyLineStart = state.lineStart;
1549
- _keyPos = state.position;
1550
- if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
1551
- break;
1552
- }
1553
- if (state.line === _line) {
1554
- ch = state.input.charCodeAt(state.position);
1555
- while (is_WHITE_SPACE(ch)) {
1556
- ch = state.input.charCodeAt(++state.position);
1557
- }
1558
- if (ch === 58) {
1559
- ch = state.input.charCodeAt(++state.position);
1560
- if (!is_WS_OR_EOL(ch)) {
1561
- throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
1562
- }
1563
- if (atExplicitKey) {
1564
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1565
- keyTag = keyNode = valueNode = null;
1566
- }
1567
- detected = true;
1568
- atExplicitKey = false;
1569
- allowCompact = false;
1570
- keyTag = state.tag;
1571
- keyNode = state.result;
1572
- } else if (detected) {
1573
- throwError(state, "can not read an implicit mapping pair; a colon is missed");
1574
- } else {
1575
- state.tag = _tag;
1576
- state.anchor = _anchor;
1577
- return true;
1578
- }
1579
- } else if (detected) {
1580
- throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
1581
- } else {
1582
- state.tag = _tag;
1583
- state.anchor = _anchor;
1584
- return true;
1585
- }
1586
- }
1587
- if (state.line === _line || state.lineIndent > nodeIndent) {
1588
- if (atExplicitKey) {
1589
- _keyLine = state.line;
1590
- _keyLineStart = state.lineStart;
1591
- _keyPos = state.position;
1592
- }
1593
- if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
1594
- if (atExplicitKey) {
1595
- keyNode = state.result;
1596
- } else {
1597
- valueNode = state.result;
1598
- }
1599
- }
1600
- if (!atExplicitKey) {
1601
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
1602
- keyTag = keyNode = valueNode = null;
1603
- }
1604
- skipSeparationSpace(state, true, -1);
1605
- ch = state.input.charCodeAt(state.position);
1606
- }
1607
- if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
1608
- throwError(state, "bad indentation of a mapping entry");
1609
- } else if (state.lineIndent < nodeIndent) {
1610
- break;
1611
- }
1612
- }
1613
- if (atExplicitKey) {
1614
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
1615
- }
1616
- if (detected) {
1617
- state.tag = _tag;
1618
- state.anchor = _anchor;
1619
- state.kind = "mapping";
1620
- state.result = _result;
1621
- }
1622
- return detected;
1623
- }
1624
- function readTagProperty(state) {
1625
- var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
1626
- ch = state.input.charCodeAt(state.position);
1627
- if (ch !== 33) return false;
1628
- if (state.tag !== null) {
1629
- throwError(state, "duplication of a tag property");
1630
- }
1631
- ch = state.input.charCodeAt(++state.position);
1632
- if (ch === 60) {
1633
- isVerbatim = true;
1634
- ch = state.input.charCodeAt(++state.position);
1635
- } else if (ch === 33) {
1636
- isNamed = true;
1637
- tagHandle = "!!";
1638
- ch = state.input.charCodeAt(++state.position);
1639
- } else {
1640
- tagHandle = "!";
1641
- }
1642
- _position = state.position;
1643
- if (isVerbatim) {
1644
- do {
1645
- ch = state.input.charCodeAt(++state.position);
1646
- } while (ch !== 0 && ch !== 62);
1647
- if (state.position < state.length) {
1648
- tagName = state.input.slice(_position, state.position);
1649
- ch = state.input.charCodeAt(++state.position);
1650
- } else {
1651
- throwError(state, "unexpected end of the stream within a verbatim tag");
1652
- }
1653
- } else {
1654
- while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1655
- if (ch === 33) {
1656
- if (!isNamed) {
1657
- tagHandle = state.input.slice(_position - 1, state.position + 1);
1658
- if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
1659
- throwError(state, "named tag handle cannot contain such characters");
1660
- }
1661
- isNamed = true;
1662
- _position = state.position + 1;
1663
- } else {
1664
- throwError(state, "tag suffix cannot contain exclamation marks");
1665
- }
1666
- }
1667
- ch = state.input.charCodeAt(++state.position);
1668
- }
1669
- tagName = state.input.slice(_position, state.position);
1670
- if (PATTERN_FLOW_INDICATORS.test(tagName)) {
1671
- throwError(state, "tag suffix cannot contain flow indicator characters");
1672
- }
1673
- }
1674
- if (tagName && !PATTERN_TAG_URI.test(tagName)) {
1675
- throwError(state, "tag name cannot contain such characters: " + tagName);
1676
- }
1677
- try {
1678
- tagName = decodeURIComponent(tagName);
1679
- } catch (err) {
1680
- throwError(state, "tag name is malformed: " + tagName);
1681
- }
1682
- if (isVerbatim) {
1683
- state.tag = tagName;
1684
- } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
1685
- state.tag = state.tagMap[tagHandle] + tagName;
1686
- } else if (tagHandle === "!") {
1687
- state.tag = "!" + tagName;
1688
- } else if (tagHandle === "!!") {
1689
- state.tag = "tag:yaml.org,2002:" + tagName;
1690
- } else {
1691
- throwError(state, 'undeclared tag handle "' + tagHandle + '"');
1692
- }
1693
- return true;
1694
- }
1695
- function readAnchorProperty(state) {
1696
- var _position, ch;
1697
- ch = state.input.charCodeAt(state.position);
1698
- if (ch !== 38) return false;
1699
- if (state.anchor !== null) {
1700
- throwError(state, "duplication of an anchor property");
1701
- }
1702
- ch = state.input.charCodeAt(++state.position);
1703
- _position = state.position;
1704
- while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
1705
- ch = state.input.charCodeAt(++state.position);
1706
- }
1707
- if (state.position === _position) {
1708
- throwError(state, "name of an anchor node must contain at least one character");
1709
- }
1710
- state.anchor = state.input.slice(_position, state.position);
1711
- return true;
1712
- }
1713
- function readAlias(state) {
1714
- var _position, alias, ch;
1715
- ch = state.input.charCodeAt(state.position);
1716
- if (ch !== 42) return false;
1717
- ch = state.input.charCodeAt(++state.position);
1718
- _position = state.position;
1719
- while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
1720
- ch = state.input.charCodeAt(++state.position);
1721
- }
1722
- if (state.position === _position) {
1723
- throwError(state, "name of an alias node must contain at least one character");
1724
- }
1725
- alias = state.input.slice(_position, state.position);
1726
- if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
1727
- throwError(state, 'unidentified alias "' + alias + '"');
1728
- }
1729
- state.result = state.anchorMap[alias];
1730
- skipSeparationSpace(state, true, -1);
1731
- return true;
1732
- }
1733
- function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
1734
- var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
1735
- if (state.listener !== null) {
1736
- state.listener("open", state);
1737
- }
1738
- state.tag = null;
1739
- state.anchor = null;
1740
- state.kind = null;
1741
- state.result = null;
1742
- allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
1743
- if (allowToSeek) {
1744
- if (skipSeparationSpace(state, true, -1)) {
1745
- atNewLine = true;
1746
- if (state.lineIndent > parentIndent) {
1747
- indentStatus = 1;
1748
- } else if (state.lineIndent === parentIndent) {
1749
- indentStatus = 0;
1750
- } else if (state.lineIndent < parentIndent) {
1751
- indentStatus = -1;
1752
- }
1753
- }
1754
- }
1755
- if (indentStatus === 1) {
1756
- while (readTagProperty(state) || readAnchorProperty(state)) {
1757
- if (skipSeparationSpace(state, true, -1)) {
1758
- atNewLine = true;
1759
- allowBlockCollections = allowBlockStyles;
1760
- if (state.lineIndent > parentIndent) {
1761
- indentStatus = 1;
1762
- } else if (state.lineIndent === parentIndent) {
1763
- indentStatus = 0;
1764
- } else if (state.lineIndent < parentIndent) {
1765
- indentStatus = -1;
1766
- }
1767
- } else {
1768
- allowBlockCollections = false;
1769
- }
1770
- }
1771
- }
1772
- if (allowBlockCollections) {
1773
- allowBlockCollections = atNewLine || allowCompact;
1774
- }
1775
- if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
1776
- if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
1777
- flowIndent = parentIndent;
1778
- } else {
1779
- flowIndent = parentIndent + 1;
1780
- }
1781
- blockIndent = state.position - state.lineStart;
1782
- if (indentStatus === 1) {
1783
- if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
1784
- hasContent = true;
1785
- } else {
1786
- if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
1787
- hasContent = true;
1788
- } else if (readAlias(state)) {
1789
- hasContent = true;
1790
- if (state.tag !== null || state.anchor !== null) {
1791
- throwError(state, "alias node should not have any properties");
1792
- }
1793
- } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
1794
- hasContent = true;
1795
- if (state.tag === null) {
1796
- state.tag = "?";
1797
- }
1798
- }
1799
- if (state.anchor !== null) {
1800
- state.anchorMap[state.anchor] = state.result;
1801
- }
1802
- }
1803
- } else if (indentStatus === 0) {
1804
- hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
1805
- }
1806
- }
1807
- if (state.tag === null) {
1808
- if (state.anchor !== null) {
1809
- state.anchorMap[state.anchor] = state.result;
1810
- }
1811
- } else if (state.tag === "?") {
1812
- if (state.result !== null && state.kind !== "scalar") {
1813
- throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
1814
- }
1815
- for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
1816
- type2 = state.implicitTypes[typeIndex];
1817
- if (type2.resolve(state.result)) {
1818
- state.result = type2.construct(state.result);
1819
- state.tag = type2.tag;
1820
- if (state.anchor !== null) {
1821
- state.anchorMap[state.anchor] = state.result;
1822
- }
1823
- break;
1824
- }
1825
- }
1826
- } else if (state.tag !== "!") {
1827
- if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
1828
- type2 = state.typeMap[state.kind || "fallback"][state.tag];
1829
- } else {
1830
- type2 = null;
1831
- typeList = state.typeMap.multi[state.kind || "fallback"];
1832
- for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
1833
- if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
1834
- type2 = typeList[typeIndex];
1835
- break;
1836
- }
1837
- }
1838
- }
1839
- if (!type2) {
1840
- throwError(state, "unknown tag !<" + state.tag + ">");
1841
- }
1842
- if (state.result !== null && type2.kind !== state.kind) {
1843
- throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
1844
- }
1845
- if (!type2.resolve(state.result, state.tag)) {
1846
- throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
1847
- } else {
1848
- state.result = type2.construct(state.result, state.tag);
1849
- if (state.anchor !== null) {
1850
- state.anchorMap[state.anchor] = state.result;
1851
- }
1852
- }
1853
- }
1854
- if (state.listener !== null) {
1855
- state.listener("close", state);
1856
- }
1857
- return state.tag !== null || state.anchor !== null || hasContent;
1858
- }
1859
- function readDocument(state) {
1860
- var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
1861
- state.version = null;
1862
- state.checkLineBreaks = state.legacy;
1863
- state.tagMap = /* @__PURE__ */ Object.create(null);
1864
- state.anchorMap = /* @__PURE__ */ Object.create(null);
1865
- while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1866
- skipSeparationSpace(state, true, -1);
1867
- ch = state.input.charCodeAt(state.position);
1868
- if (state.lineIndent > 0 || ch !== 37) {
1869
- break;
1870
- }
1871
- hasDirectives = true;
1872
- ch = state.input.charCodeAt(++state.position);
1873
- _position = state.position;
1874
- while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1875
- ch = state.input.charCodeAt(++state.position);
1876
- }
1877
- directiveName = state.input.slice(_position, state.position);
1878
- directiveArgs = [];
1879
- if (directiveName.length < 1) {
1880
- throwError(state, "directive name must not be less than one character in length");
1881
- }
1882
- while (ch !== 0) {
1883
- while (is_WHITE_SPACE(ch)) {
1884
- ch = state.input.charCodeAt(++state.position);
1885
- }
1886
- if (ch === 35) {
1887
- do {
1888
- ch = state.input.charCodeAt(++state.position);
1889
- } while (ch !== 0 && !is_EOL(ch));
1890
- break;
1891
- }
1892
- if (is_EOL(ch)) break;
1893
- _position = state.position;
1894
- while (ch !== 0 && !is_WS_OR_EOL(ch)) {
1895
- ch = state.input.charCodeAt(++state.position);
1896
- }
1897
- directiveArgs.push(state.input.slice(_position, state.position));
1898
- }
1899
- if (ch !== 0) readLineBreak(state);
1900
- if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
1901
- directiveHandlers[directiveName](state, directiveName, directiveArgs);
1902
- } else {
1903
- throwWarning(state, 'unknown document directive "' + directiveName + '"');
1904
- }
1905
- }
1906
- skipSeparationSpace(state, true, -1);
1907
- if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
1908
- state.position += 3;
1909
- skipSeparationSpace(state, true, -1);
1910
- } else if (hasDirectives) {
1911
- throwError(state, "directives end mark is expected");
1912
- }
1913
- composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
1914
- skipSeparationSpace(state, true, -1);
1915
- if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
1916
- throwWarning(state, "non-ASCII line breaks are interpreted as content");
1917
- }
1918
- state.documents.push(state.result);
1919
- if (state.position === state.lineStart && testDocumentSeparator(state)) {
1920
- if (state.input.charCodeAt(state.position) === 46) {
1921
- state.position += 3;
1922
- skipSeparationSpace(state, true, -1);
1923
- }
1924
- return;
1925
- }
1926
- if (state.position < state.length - 1) {
1927
- throwError(state, "end of the stream or a document separator is expected");
1928
- } else {
1929
- return;
1930
- }
1931
- }
1932
- function loadDocuments(input, options) {
1933
- input = String(input);
1934
- options = options || {};
1935
- if (input.length !== 0) {
1936
- if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
1937
- input += "\n";
1938
- }
1939
- if (input.charCodeAt(0) === 65279) {
1940
- input = input.slice(1);
1941
- }
1942
- }
1943
- var state = new State$1(input, options);
1944
- var nullpos = input.indexOf("\0");
1945
- if (nullpos !== -1) {
1946
- state.position = nullpos;
1947
- throwError(state, "null byte is not allowed in input");
1948
- }
1949
- state.input += "\0";
1950
- while (state.input.charCodeAt(state.position) === 32) {
1951
- state.lineIndent += 1;
1952
- state.position += 1;
1953
- }
1954
- while (state.position < state.length - 1) {
1955
- readDocument(state);
1956
- }
1957
- return state.documents;
1958
- }
1959
- function loadAll$1(input, iterator, options) {
1960
- if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
1961
- options = iterator;
1962
- iterator = null;
1963
- }
1964
- var documents = loadDocuments(input, options);
1965
- if (typeof iterator !== "function") {
1966
- return documents;
1967
- }
1968
- for (var index = 0, length = documents.length; index < length; index += 1) {
1969
- iterator(documents[index]);
1970
- }
1971
- }
1972
- function load$1(input, options) {
1973
- var documents = loadDocuments(input, options);
1974
- if (documents.length === 0) {
1975
- return void 0;
1976
- } else if (documents.length === 1) {
1977
- return documents[0];
1978
- }
1979
- throw new exception("expected a single document in the stream, but found more");
1980
- }
1981
- var loadAll_1 = loadAll$1;
1982
- var load_1 = load$1;
1983
- var loader = {
1984
- loadAll: loadAll_1,
1985
- load: load_1
1986
- };
1987
- var _toString = Object.prototype.toString;
1988
- var _hasOwnProperty = Object.prototype.hasOwnProperty;
1989
- var CHAR_BOM = 65279;
1990
- var CHAR_TAB = 9;
1991
- var CHAR_LINE_FEED = 10;
1992
- var CHAR_CARRIAGE_RETURN = 13;
1993
- var CHAR_SPACE = 32;
1994
- var CHAR_EXCLAMATION = 33;
1995
- var CHAR_DOUBLE_QUOTE = 34;
1996
- var CHAR_SHARP = 35;
1997
- var CHAR_PERCENT = 37;
1998
- var CHAR_AMPERSAND = 38;
1999
- var CHAR_SINGLE_QUOTE = 39;
2000
- var CHAR_ASTERISK = 42;
2001
- var CHAR_COMMA = 44;
2002
- var CHAR_MINUS = 45;
2003
- var CHAR_COLON = 58;
2004
- var CHAR_EQUALS = 61;
2005
- var CHAR_GREATER_THAN = 62;
2006
- var CHAR_QUESTION = 63;
2007
- var CHAR_COMMERCIAL_AT = 64;
2008
- var CHAR_LEFT_SQUARE_BRACKET = 91;
2009
- var CHAR_RIGHT_SQUARE_BRACKET = 93;
2010
- var CHAR_GRAVE_ACCENT = 96;
2011
- var CHAR_LEFT_CURLY_BRACKET = 123;
2012
- var CHAR_VERTICAL_LINE = 124;
2013
- var CHAR_RIGHT_CURLY_BRACKET = 125;
2014
- var ESCAPE_SEQUENCES = {};
2015
- ESCAPE_SEQUENCES[0] = "\\0";
2016
- ESCAPE_SEQUENCES[7] = "\\a";
2017
- ESCAPE_SEQUENCES[8] = "\\b";
2018
- ESCAPE_SEQUENCES[9] = "\\t";
2019
- ESCAPE_SEQUENCES[10] = "\\n";
2020
- ESCAPE_SEQUENCES[11] = "\\v";
2021
- ESCAPE_SEQUENCES[12] = "\\f";
2022
- ESCAPE_SEQUENCES[13] = "\\r";
2023
- ESCAPE_SEQUENCES[27] = "\\e";
2024
- ESCAPE_SEQUENCES[34] = '\\"';
2025
- ESCAPE_SEQUENCES[92] = "\\\\";
2026
- ESCAPE_SEQUENCES[133] = "\\N";
2027
- ESCAPE_SEQUENCES[160] = "\\_";
2028
- ESCAPE_SEQUENCES[8232] = "\\L";
2029
- ESCAPE_SEQUENCES[8233] = "\\P";
2030
- var DEPRECATED_BOOLEANS_SYNTAX = [
2031
- "y",
2032
- "Y",
2033
- "yes",
2034
- "Yes",
2035
- "YES",
2036
- "on",
2037
- "On",
2038
- "ON",
2039
- "n",
2040
- "N",
2041
- "no",
2042
- "No",
2043
- "NO",
2044
- "off",
2045
- "Off",
2046
- "OFF"
2047
- ];
2048
- var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
2049
- function compileStyleMap(schema2, map2) {
2050
- var result, keys, index, length, tag, style, type2;
2051
- if (map2 === null) return {};
2052
- result = {};
2053
- keys = Object.keys(map2);
2054
- for (index = 0, length = keys.length; index < length; index += 1) {
2055
- tag = keys[index];
2056
- style = String(map2[tag]);
2057
- if (tag.slice(0, 2) === "!!") {
2058
- tag = "tag:yaml.org,2002:" + tag.slice(2);
2059
- }
2060
- type2 = schema2.compiledTypeMap["fallback"][tag];
2061
- if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
2062
- style = type2.styleAliases[style];
2063
- }
2064
- result[tag] = style;
2065
- }
2066
- return result;
2067
- }
2068
- function encodeHex(character) {
2069
- var string, handle, length;
2070
- string = character.toString(16).toUpperCase();
2071
- if (character <= 255) {
2072
- handle = "x";
2073
- length = 2;
2074
- } else if (character <= 65535) {
2075
- handle = "u";
2076
- length = 4;
2077
- } else if (character <= 4294967295) {
2078
- handle = "U";
2079
- length = 8;
2080
- } else {
2081
- throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
2082
- }
2083
- return "\\" + handle + common.repeat("0", length - string.length) + string;
2084
- }
2085
- var QUOTING_TYPE_SINGLE = 1;
2086
- var QUOTING_TYPE_DOUBLE = 2;
2087
- function State(options) {
2088
- this.schema = options["schema"] || _default;
2089
- this.indent = Math.max(1, options["indent"] || 2);
2090
- this.noArrayIndent = options["noArrayIndent"] || false;
2091
- this.skipInvalid = options["skipInvalid"] || false;
2092
- this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
2093
- this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
2094
- this.sortKeys = options["sortKeys"] || false;
2095
- this.lineWidth = options["lineWidth"] || 80;
2096
- this.noRefs = options["noRefs"] || false;
2097
- this.noCompatMode = options["noCompatMode"] || false;
2098
- this.condenseFlow = options["condenseFlow"] || false;
2099
- this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
2100
- this.forceQuotes = options["forceQuotes"] || false;
2101
- this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
2102
- this.implicitTypes = this.schema.compiledImplicit;
2103
- this.explicitTypes = this.schema.compiledExplicit;
2104
- this.tag = null;
2105
- this.result = "";
2106
- this.duplicates = [];
2107
- this.usedDuplicates = null;
2108
- }
2109
- function indentString(string, spaces) {
2110
- var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
2111
- while (position < length) {
2112
- next = string.indexOf("\n", position);
2113
- if (next === -1) {
2114
- line = string.slice(position);
2115
- position = length;
2116
- } else {
2117
- line = string.slice(position, next + 1);
2118
- position = next + 1;
2119
- }
2120
- if (line.length && line !== "\n") result += ind;
2121
- result += line;
2122
- }
2123
- return result;
2124
- }
2125
- function generateNextLine(state, level) {
2126
- return "\n" + common.repeat(" ", state.indent * level);
2127
- }
2128
- function testImplicitResolving(state, str2) {
2129
- var index, length, type2;
2130
- for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
2131
- type2 = state.implicitTypes[index];
2132
- if (type2.resolve(str2)) {
2133
- return true;
2134
- }
2135
- }
2136
- return false;
2137
- }
2138
- function isWhitespace(c) {
2139
- return c === CHAR_SPACE || c === CHAR_TAB;
2140
- }
2141
- function isPrintable(c) {
2142
- return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
2143
- }
2144
- function isNsCharOrWhitespace(c) {
2145
- return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
2146
- }
2147
- function isPlainSafe(c, prev, inblock) {
2148
- var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
2149
- var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
2150
- return (
2151
- // ns-plain-safe
2152
- (inblock ? (
2153
- // c = flow-in
2154
- cIsNsCharOrWhitespace
2155
- ) : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar
2156
- );
2157
- }
2158
- function isPlainSafeFirst(c) {
2159
- return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
2160
- }
2161
- function isPlainSafeLast(c) {
2162
- return !isWhitespace(c) && c !== CHAR_COLON;
2163
- }
2164
- function codePointAt(string, pos) {
2165
- var first = string.charCodeAt(pos), second;
2166
- if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
2167
- second = string.charCodeAt(pos + 1);
2168
- if (second >= 56320 && second <= 57343) {
2169
- return (first - 55296) * 1024 + second - 56320 + 65536;
2170
- }
2171
- }
2172
- return first;
2173
- }
2174
- function needIndentIndicator(string) {
2175
- var leadingSpaceRe = /^\n* /;
2176
- return leadingSpaceRe.test(string);
2177
- }
2178
- var STYLE_PLAIN = 1;
2179
- var STYLE_SINGLE = 2;
2180
- var STYLE_LITERAL = 3;
2181
- var STYLE_FOLDED = 4;
2182
- var STYLE_DOUBLE = 5;
2183
- function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
2184
- var i;
2185
- var char = 0;
2186
- var prevChar = null;
2187
- var hasLineBreak = false;
2188
- var hasFoldableLine = false;
2189
- var shouldTrackWidth = lineWidth !== -1;
2190
- var previousLineBreak = -1;
2191
- var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
2192
- if (singleLineOnly || forceQuotes) {
2193
- for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2194
- char = codePointAt(string, i);
2195
- if (!isPrintable(char)) {
2196
- return STYLE_DOUBLE;
2197
- }
2198
- plain = plain && isPlainSafe(char, prevChar, inblock);
2199
- prevChar = char;
2200
- }
2201
- } else {
2202
- for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2203
- char = codePointAt(string, i);
2204
- if (char === CHAR_LINE_FEED) {
2205
- hasLineBreak = true;
2206
- if (shouldTrackWidth) {
2207
- hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
2208
- i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2209
- previousLineBreak = i;
2210
- }
2211
- } else if (!isPrintable(char)) {
2212
- return STYLE_DOUBLE;
2213
- }
2214
- plain = plain && isPlainSafe(char, prevChar, inblock);
2215
- prevChar = char;
2216
- }
2217
- hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
2218
- }
2219
- if (!hasLineBreak && !hasFoldableLine) {
2220
- if (plain && !forceQuotes && !testAmbiguousType(string)) {
2221
- return STYLE_PLAIN;
2222
- }
2223
- return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2224
- }
2225
- if (indentPerLevel > 9 && needIndentIndicator(string)) {
2226
- return STYLE_DOUBLE;
2227
- }
2228
- if (!forceQuotes) {
2229
- return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
2230
- }
2231
- return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2232
- }
2233
- function writeScalar(state, string, level, iskey, inblock) {
2234
- state.dump = function() {
2235
- if (string.length === 0) {
2236
- return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
2237
- }
2238
- if (!state.noCompatMode) {
2239
- if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
2240
- return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
2241
- }
2242
- }
2243
- var indent = state.indent * Math.max(1, level);
2244
- var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
2245
- var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
2246
- function testAmbiguity(string2) {
2247
- return testImplicitResolving(state, string2);
2248
- }
2249
- switch (chooseScalarStyle(
2250
- string,
2251
- singleLineOnly,
2252
- state.indent,
2253
- lineWidth,
2254
- testAmbiguity,
2255
- state.quotingType,
2256
- state.forceQuotes && !iskey,
2257
- inblock
2258
- )) {
2259
- case STYLE_PLAIN:
2260
- return string;
2261
- case STYLE_SINGLE:
2262
- return "'" + string.replace(/'/g, "''") + "'";
2263
- case STYLE_LITERAL:
2264
- return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
2265
- case STYLE_FOLDED:
2266
- return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
2267
- case STYLE_DOUBLE:
2268
- return '"' + escapeString(string) + '"';
2269
- default:
2270
- throw new exception("impossible error: invalid scalar style");
2271
- }
2272
- }();
2273
- }
2274
- function blockHeader(string, indentPerLevel) {
2275
- var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
2276
- var clip = string[string.length - 1] === "\n";
2277
- var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
2278
- var chomp = keep ? "+" : clip ? "" : "-";
2279
- return indentIndicator + chomp + "\n";
2280
- }
2281
- function dropEndingNewline(string) {
2282
- return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2283
- }
2284
- function foldString(string, width) {
2285
- var lineRe = /(\n+)([^\n]*)/g;
2286
- var result = function() {
2287
- var nextLF = string.indexOf("\n");
2288
- nextLF = nextLF !== -1 ? nextLF : string.length;
2289
- lineRe.lastIndex = nextLF;
2290
- return foldLine(string.slice(0, nextLF), width);
2291
- }();
2292
- var prevMoreIndented = string[0] === "\n" || string[0] === " ";
2293
- var moreIndented;
2294
- var match;
2295
- while (match = lineRe.exec(string)) {
2296
- var prefix = match[1], line = match[2];
2297
- moreIndented = line[0] === " ";
2298
- result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2299
- prevMoreIndented = moreIndented;
2300
- }
2301
- return result;
2302
- }
2303
- function foldLine(line, width) {
2304
- if (line === "" || line[0] === " ") return line;
2305
- var breakRe = / [^ ]/g;
2306
- var match;
2307
- var start = 0, end, curr = 0, next = 0;
2308
- var result = "";
2309
- while (match = breakRe.exec(line)) {
2310
- next = match.index;
2311
- if (next - start > width) {
2312
- end = curr > start ? curr : next;
2313
- result += "\n" + line.slice(start, end);
2314
- start = end + 1;
2315
- }
2316
- curr = next;
2317
- }
2318
- result += "\n";
2319
- if (line.length - start > width && curr > start) {
2320
- result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
2321
- } else {
2322
- result += line.slice(start);
2323
- }
2324
- return result.slice(1);
2325
- }
2326
- function escapeString(string) {
2327
- var result = "";
2328
- var char = 0;
2329
- var escapeSeq;
2330
- for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2331
- char = codePointAt(string, i);
2332
- escapeSeq = ESCAPE_SEQUENCES[char];
2333
- if (!escapeSeq && isPrintable(char)) {
2334
- result += string[i];
2335
- if (char >= 65536) result += string[i + 1];
2336
- } else {
2337
- result += escapeSeq || encodeHex(char);
2338
- }
2339
- }
2340
- return result;
2341
- }
2342
- function writeFlowSequence(state, level, object) {
2343
- var _result = "", _tag = state.tag, index, length, value;
2344
- for (index = 0, length = object.length; index < length; index += 1) {
2345
- value = object[index];
2346
- if (state.replacer) {
2347
- value = state.replacer.call(object, String(index), value);
2348
- }
2349
- if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
2350
- if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
2351
- _result += state.dump;
2352
- }
2353
- }
2354
- state.tag = _tag;
2355
- state.dump = "[" + _result + "]";
2356
- }
2357
- function writeBlockSequence(state, level, object, compact) {
2358
- var _result = "", _tag = state.tag, index, length, value;
2359
- for (index = 0, length = object.length; index < length; index += 1) {
2360
- value = object[index];
2361
- if (state.replacer) {
2362
- value = state.replacer.call(object, String(index), value);
2363
- }
2364
- if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
2365
- if (!compact || _result !== "") {
2366
- _result += generateNextLine(state, level);
2367
- }
2368
- if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2369
- _result += "-";
2370
- } else {
2371
- _result += "- ";
2372
- }
2373
- _result += state.dump;
2374
- }
2375
- }
2376
- state.tag = _tag;
2377
- state.dump = _result || "[]";
2378
- }
2379
- function writeFlowMapping(state, level, object) {
2380
- var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
2381
- for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2382
- pairBuffer = "";
2383
- if (_result !== "") pairBuffer += ", ";
2384
- if (state.condenseFlow) pairBuffer += '"';
2385
- objectKey = objectKeyList[index];
2386
- objectValue = object[objectKey];
2387
- if (state.replacer) {
2388
- objectValue = state.replacer.call(object, objectKey, objectValue);
2389
- }
2390
- if (!writeNode(state, level, objectKey, false, false)) {
2391
- continue;
2392
- }
2393
- if (state.dump.length > 1024) pairBuffer += "? ";
2394
- pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
2395
- if (!writeNode(state, level, objectValue, false, false)) {
2396
- continue;
2397
- }
2398
- pairBuffer += state.dump;
2399
- _result += pairBuffer;
2400
- }
2401
- state.tag = _tag;
2402
- state.dump = "{" + _result + "}";
2403
- }
2404
- function writeBlockMapping(state, level, object, compact) {
2405
- var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
2406
- if (state.sortKeys === true) {
2407
- objectKeyList.sort();
2408
- } else if (typeof state.sortKeys === "function") {
2409
- objectKeyList.sort(state.sortKeys);
2410
- } else if (state.sortKeys) {
2411
- throw new exception("sortKeys must be a boolean or a function");
2412
- }
2413
- for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2414
- pairBuffer = "";
2415
- if (!compact || _result !== "") {
2416
- pairBuffer += generateNextLine(state, level);
2417
- }
2418
- objectKey = objectKeyList[index];
2419
- objectValue = object[objectKey];
2420
- if (state.replacer) {
2421
- objectValue = state.replacer.call(object, objectKey, objectValue);
2422
- }
2423
- if (!writeNode(state, level + 1, objectKey, true, true, true)) {
2424
- continue;
2425
- }
2426
- explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
2427
- if (explicitPair) {
2428
- if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2429
- pairBuffer += "?";
2430
- } else {
2431
- pairBuffer += "? ";
2432
- }
2433
- }
2434
- pairBuffer += state.dump;
2435
- if (explicitPair) {
2436
- pairBuffer += generateNextLine(state, level);
2437
- }
2438
- if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
2439
- continue;
2440
- }
2441
- if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2442
- pairBuffer += ":";
2443
- } else {
2444
- pairBuffer += ": ";
2445
- }
2446
- pairBuffer += state.dump;
2447
- _result += pairBuffer;
2448
- }
2449
- state.tag = _tag;
2450
- state.dump = _result || "{}";
2451
- }
2452
- function detectType(state, object, explicit) {
2453
- var _result, typeList, index, length, type2, style;
2454
- typeList = explicit ? state.explicitTypes : state.implicitTypes;
2455
- for (index = 0, length = typeList.length; index < length; index += 1) {
2456
- type2 = typeList[index];
2457
- if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
2458
- if (explicit) {
2459
- if (type2.multi && type2.representName) {
2460
- state.tag = type2.representName(object);
2461
- } else {
2462
- state.tag = type2.tag;
2463
- }
2464
- } else {
2465
- state.tag = "?";
2466
- }
2467
- if (type2.represent) {
2468
- style = state.styleMap[type2.tag] || type2.defaultStyle;
2469
- if (_toString.call(type2.represent) === "[object Function]") {
2470
- _result = type2.represent(object, style);
2471
- } else if (_hasOwnProperty.call(type2.represent, style)) {
2472
- _result = type2.represent[style](object, style);
2473
- } else {
2474
- throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
2475
- }
2476
- state.dump = _result;
2477
- }
2478
- return true;
2479
- }
2480
- }
2481
- return false;
2482
- }
2483
- function writeNode(state, level, object, block, compact, iskey, isblockseq) {
2484
- state.tag = null;
2485
- state.dump = object;
2486
- if (!detectType(state, object, false)) {
2487
- detectType(state, object, true);
2488
- }
2489
- var type2 = _toString.call(state.dump);
2490
- var inblock = block;
2491
- var tagStr;
2492
- if (block) {
2493
- block = state.flowLevel < 0 || state.flowLevel > level;
2494
- }
2495
- var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
2496
- if (objectOrArray) {
2497
- duplicateIndex = state.duplicates.indexOf(object);
2498
- duplicate = duplicateIndex !== -1;
2499
- }
2500
- if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
2501
- compact = false;
2502
- }
2503
- if (duplicate && state.usedDuplicates[duplicateIndex]) {
2504
- state.dump = "*ref_" + duplicateIndex;
2505
- } else {
2506
- if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
2507
- state.usedDuplicates[duplicateIndex] = true;
2508
- }
2509
- if (type2 === "[object Object]") {
2510
- if (block && Object.keys(state.dump).length !== 0) {
2511
- writeBlockMapping(state, level, state.dump, compact);
2512
- if (duplicate) {
2513
- state.dump = "&ref_" + duplicateIndex + state.dump;
2514
- }
2515
- } else {
2516
- writeFlowMapping(state, level, state.dump);
2517
- if (duplicate) {
2518
- state.dump = "&ref_" + duplicateIndex + " " + state.dump;
2519
- }
2520
- }
2521
- } else if (type2 === "[object Array]") {
2522
- if (block && state.dump.length !== 0) {
2523
- if (state.noArrayIndent && !isblockseq && level > 0) {
2524
- writeBlockSequence(state, level - 1, state.dump, compact);
2525
- } else {
2526
- writeBlockSequence(state, level, state.dump, compact);
2527
- }
2528
- if (duplicate) {
2529
- state.dump = "&ref_" + duplicateIndex + state.dump;
2530
- }
2531
- } else {
2532
- writeFlowSequence(state, level, state.dump);
2533
- if (duplicate) {
2534
- state.dump = "&ref_" + duplicateIndex + " " + state.dump;
2535
- }
2536
- }
2537
- } else if (type2 === "[object String]") {
2538
- if (state.tag !== "?") {
2539
- writeScalar(state, state.dump, level, iskey, inblock);
2540
- }
2541
- } else if (type2 === "[object Undefined]") {
2542
- return false;
2543
- } else {
2544
- if (state.skipInvalid) return false;
2545
- throw new exception("unacceptable kind of an object to dump " + type2);
2546
- }
2547
- if (state.tag !== null && state.tag !== "?") {
2548
- tagStr = encodeURI(
2549
- state.tag[0] === "!" ? state.tag.slice(1) : state.tag
2550
- ).replace(/!/g, "%21");
2551
- if (state.tag[0] === "!") {
2552
- tagStr = "!" + tagStr;
2553
- } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
2554
- tagStr = "!!" + tagStr.slice(18);
2555
- } else {
2556
- tagStr = "!<" + tagStr + ">";
2557
- }
2558
- state.dump = tagStr + " " + state.dump;
2559
- }
2560
- }
2561
- return true;
2562
- }
2563
- function getDuplicateReferences(object, state) {
2564
- var objects = [], duplicatesIndexes = [], index, length;
2565
- inspectNode(object, objects, duplicatesIndexes);
2566
- for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
2567
- state.duplicates.push(objects[duplicatesIndexes[index]]);
2568
- }
2569
- state.usedDuplicates = new Array(length);
2570
- }
2571
- function inspectNode(object, objects, duplicatesIndexes) {
2572
- var objectKeyList, index, length;
2573
- if (object !== null && typeof object === "object") {
2574
- index = objects.indexOf(object);
2575
- if (index !== -1) {
2576
- if (duplicatesIndexes.indexOf(index) === -1) {
2577
- duplicatesIndexes.push(index);
2578
- }
2579
- } else {
2580
- objects.push(object);
2581
- if (Array.isArray(object)) {
2582
- for (index = 0, length = object.length; index < length; index += 1) {
2583
- inspectNode(object[index], objects, duplicatesIndexes);
2584
- }
2585
- } else {
2586
- objectKeyList = Object.keys(object);
2587
- for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2588
- inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
2589
- }
2590
- }
2591
- }
2592
- }
2593
- }
2594
- function dump$1(input, options) {
2595
- options = options || {};
2596
- var state = new State(options);
2597
- if (!state.noRefs) getDuplicateReferences(input, state);
2598
- var value = input;
2599
- if (state.replacer) {
2600
- value = state.replacer.call({ "": value }, "", value);
2601
- }
2602
- if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
2603
- return "";
2604
- }
2605
- var dump_1 = dump$1;
2606
- var dumper = {
2607
- dump: dump_1
2608
- };
2609
- function renamed(from, to) {
2610
- return function() {
2611
- throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
2612
- };
2613
- }
2614
- var Type = type;
2615
- var Schema = schema;
2616
- var FAILSAFE_SCHEMA = failsafe;
2617
- var JSON_SCHEMA = json;
2618
- var CORE_SCHEMA = core;
2619
- var DEFAULT_SCHEMA = _default;
2620
- var load = loader.load;
2621
- var loadAll = loader.loadAll;
2622
- var dump = dumper.dump;
2623
- var YAMLException = exception;
2624
- var types = {
2625
- binary,
2626
- float,
2627
- map,
2628
- null: _null,
2629
- pairs,
2630
- set,
2631
- timestamp,
2632
- bool,
2633
- int,
2634
- merge,
2635
- omap,
2636
- seq,
2637
- str
2638
- };
2639
- var safeLoad = renamed("safeLoad", "load");
2640
- var safeLoadAll = renamed("safeLoadAll", "loadAll");
2641
- var safeDump = renamed("safeDump", "dump");
2642
- var jsYaml = {
2643
- Type,
2644
- Schema,
2645
- FAILSAFE_SCHEMA,
2646
- JSON_SCHEMA,
2647
- CORE_SCHEMA,
2648
- DEFAULT_SCHEMA,
2649
- load,
2650
- loadAll,
2651
- dump,
2652
- YAMLException,
2653
- types,
2654
- safeLoad,
2655
- safeLoadAll,
2656
- safeDump
2657
- };
2658
- var js_yaml_default = jsYaml;
2659
-
2660
- // src/import-specs.ts
2661
- var import_fs_extra = __toESM(require("fs-extra"));
2662
-
2663
- // src/import-open-api.ts
2664
- var import_core3 = require("@orval/core");
2665
-
2666
- // src/api.ts
2667
- var import_core2 = require("@orval/core");
2668
- var import_mock = require("@orval/mock");
2669
-
2670
- // src/client.ts
2671
- var import_angular = __toESM(require("@orval/angular"));
2672
- var import_axios = __toESM(require("@orval/axios"));
2673
- var import_core = require("@orval/core");
2674
- var import_fetch = __toESM(require("@orval/fetch"));
2675
- var import_hono = __toESM(require("@orval/hono"));
2676
- var mock = __toESM(require("@orval/mock"));
2677
- var import_query = __toESM(require("@orval/query"));
2678
- var import_swr = __toESM(require("@orval/swr"));
2679
- var import_zod = __toESM(require("@orval/zod"));
2680
- var import_mcp = __toESM(require("@orval/mcp"));
2681
- var DEFAULT_CLIENT = import_core.OutputClient.AXIOS;
2682
- var getGeneratorClient = (outputClient, output) => {
2683
- const GENERATOR_CLIENT = {
2684
- axios: (0, import_axios.default)({ type: "axios" })(),
2685
- "axios-functions": (0, import_axios.default)({ type: "axios-functions" })(),
2686
- angular: (0, import_angular.default)()(),
2687
- "react-query": (0, import_query.default)({ output, type: "react-query" })(),
2688
- "svelte-query": (0, import_query.default)({ output, type: "svelte-query" })(),
2689
- "vue-query": (0, import_query.default)({ output, type: "vue-query" })(),
2690
- swr: (0, import_swr.default)()(),
2691
- zod: (0, import_zod.default)()(),
2692
- hono: (0, import_hono.default)()(),
2693
- fetch: (0, import_fetch.default)()(),
2694
- mcp: (0, import_mcp.default)()()
2695
- };
2696
- const generator = (0, import_core.isFunction)(outputClient) ? outputClient(GENERATOR_CLIENT) : GENERATOR_CLIENT[outputClient];
2697
- if (!generator) {
2698
- throw `Oups... \u{1F37B}. Client not found: ${outputClient}`;
2699
- }
2700
- return generator;
2701
- };
2702
- var generateClientImports = ({
2703
- client = DEFAULT_CLIENT,
2704
- implementation,
2705
- imports,
2706
- specsName,
2707
- hasSchemaDir,
2708
- isAllowSyntheticDefaultImports,
2709
- hasGlobalMutator,
2710
- hasTagsMutator,
2711
- hasParamsSerializerOptions,
2712
- packageJson,
2713
- output
2714
- }) => {
2715
- const { dependencies } = getGeneratorClient(client, output);
2716
- return (0, import_core.generateDependencyImports)(
2717
- implementation,
2718
- dependencies ? [
2719
- ...dependencies(
2720
- hasGlobalMutator,
2721
- hasParamsSerializerOptions,
2722
- packageJson,
2723
- output.httpClient,
2724
- hasTagsMutator,
2725
- output.override
2726
- ),
2727
- ...imports
2728
- ] : imports,
2729
- specsName,
2730
- hasSchemaDir,
2731
- isAllowSyntheticDefaultImports
2732
- );
2733
- };
2734
- var generateClientHeader = ({
2735
- outputClient = DEFAULT_CLIENT,
2736
- isRequestOptions,
2737
- isGlobalMutator,
2738
- isMutator,
2739
- provideIn,
2740
- hasAwaitedType,
2741
- titles,
2742
- output,
2743
- verbOptions,
2744
- tag,
2745
- clientImplementation
2746
- }) => {
2747
- const { header } = getGeneratorClient(outputClient, output);
2748
- return {
2749
- implementation: header ? header({
2750
- title: titles.implementation,
2751
- isRequestOptions,
2752
- isGlobalMutator,
2753
- isMutator,
2754
- provideIn,
2755
- hasAwaitedType,
2756
- output,
2757
- verbOptions,
2758
- tag,
2759
- clientImplementation
2760
- }) : "",
2761
- implementationMock: `export const ${titles.implementationMock} = () => [
2762
- `
2763
- };
2764
- };
2765
- var generateClientFooter = ({
2766
- outputClient = DEFAULT_CLIENT,
2767
- operationNames,
2768
- hasMutator,
2769
- hasAwaitedType,
2770
- titles,
2771
- output
2772
- }) => {
2773
- const { footer } = getGeneratorClient(outputClient, output);
2774
- if (!footer) {
2775
- return {
2776
- implementation: "",
2777
- implementationMock: `
2778
- ]
2779
- `
2780
- };
2781
- }
2782
- let implementation;
2783
- try {
2784
- if ((0, import_core.isFunction)(outputClient)) {
2785
- implementation = footer(
2786
- operationNames
2787
- );
2788
- console.warn(
2789
- "[WARN] Passing an array of strings for operations names to the footer function is deprecated and will be removed in a future major release. Please pass them in an object instead: { operationNames: string[] }."
2790
- );
2791
- } else {
2792
- implementation = footer({
2793
- operationNames,
2794
- title: titles.implementation,
2795
- hasMutator,
2796
- hasAwaitedType
2797
- });
2798
- }
2799
- } catch {
2800
- implementation = footer({
2801
- operationNames,
2802
- title: titles.implementation,
2803
- hasMutator,
2804
- hasAwaitedType
2805
- });
2806
- }
2807
- return {
2808
- implementation,
2809
- implementationMock: `]
2810
- `
2811
- };
2812
- };
2813
- var generateClientTitle = ({
2814
- outputClient = DEFAULT_CLIENT,
2815
- title,
2816
- customTitleFunc,
2817
- output
2818
- }) => {
2819
- const { title: generatorTitle } = getGeneratorClient(outputClient, output);
2820
- if (!generatorTitle) {
2821
- return {
2822
- implementation: "",
2823
- implementationMock: `get${(0, import_core.pascal)(title)}Mock`
2824
- };
2825
- }
2826
- if (customTitleFunc) {
2827
- const customTitle = customTitleFunc(title);
2828
- return {
2829
- implementation: generatorTitle(customTitle),
2830
- implementationMock: `get${(0, import_core.pascal)(customTitle)}Mock`
2831
- };
2832
- }
2833
- return {
2834
- implementation: generatorTitle(title),
2835
- implementationMock: `get${(0, import_core.pascal)(title)}Mock`
2836
- };
2837
- };
2838
- var generateMock2 = (verbOption, options) => {
2839
- if (!options.mock) {
2840
- return {
2841
- implementation: {
2842
- function: "",
2843
- handler: "",
2844
- handlerName: ""
2845
- },
2846
- imports: []
2847
- };
2848
- }
2849
- if ((0, import_core.isFunction)(options.mock)) {
2850
- return options.mock(verbOption, options);
2851
- }
2852
- return mock.generateMock(
2853
- verbOption,
2854
- options
2855
- );
2856
- };
2857
- var generateOperations = (outputClient = DEFAULT_CLIENT, verbsOptions, options, output) => {
2858
- return (0, import_core.asyncReduce)(
2859
- verbsOptions,
2860
- async (acc, verbOption) => {
2861
- const { client: generatorClient } = getGeneratorClient(
2862
- outputClient,
2863
- output
2864
- );
2865
- const client = await generatorClient(verbOption, options, outputClient);
2866
- if (!client.implementation) {
2867
- return acc;
2868
- }
2869
- const generatedMock = generateMock2(verbOption, options);
2870
- acc[verbOption.operationId] = {
2871
- implementation: verbOption.doc + client.implementation,
2872
- imports: client.imports,
2873
- implementationMock: generatedMock.implementation,
2874
- importsMock: generatedMock.imports,
2875
- tags: verbOption.tags,
2876
- mutator: verbOption.mutator,
2877
- clientMutators: client.mutators,
2878
- formData: verbOption.formData,
2879
- formUrlEncoded: verbOption.formUrlEncoded,
2880
- paramsSerializer: verbOption.paramsSerializer,
2881
- operationName: verbOption.operationName,
2882
- fetchReviver: verbOption.fetchReviver
2883
- };
2884
- return acc;
2885
- },
2886
- {}
2887
- );
2888
- };
2889
- var generateExtraFiles = (outputClient = DEFAULT_CLIENT, verbsOptions, output, context) => {
2890
- const { extraFiles: generateExtraFiles2 } = getGeneratorClient(
2891
- outputClient,
2892
- output
2893
- );
2894
- if (!generateExtraFiles2) {
2895
- return Promise.resolve([]);
2896
- }
2897
- return generateExtraFiles2(verbsOptions, output, context);
2898
- };
2899
-
2900
- // src/api.ts
2901
- var getApiBuilder = async ({
2902
- input,
2903
- output,
2904
- context
2905
- }) => {
2906
- var _a;
2907
- const api = await (0, import_core2.asyncReduce)(
2908
- Object.entries((_a = context.specs[context.specKey].paths) != null ? _a : {}),
2909
- async (acc, [pathRoute, verbs]) => {
2910
- var _a2;
2911
- const route = (0, import_core2.getRoute)(pathRoute);
2912
- let resolvedVerbs = verbs;
2913
- let resolvedContext = context;
2914
- if ((0, import_core2.isReference)(verbs)) {
2915
- const { schema: schema2, imports } = (0, import_core2.resolveRef)(verbs, context);
2916
- resolvedVerbs = schema2;
2917
- resolvedContext = {
2918
- ...context,
2919
- ...imports.length ? {
2920
- specKey: imports[0].specKey
2921
- } : {}
2922
- };
2923
- }
2924
- let verbsOptions = await (0, import_core2.generateVerbsOptions)({
2925
- verbs: resolvedVerbs,
2926
- input,
2927
- output,
2928
- route,
2929
- pathRoute,
2930
- context: resolvedContext
2931
- });
2932
- if (output.override.useDeprecatedOperations === false) {
2933
- verbsOptions = verbsOptions.filter((verb) => {
2934
- return !verb.deprecated;
2935
- });
2936
- }
2937
- const schemas = verbsOptions.reduce(
2938
- (acc2, { queryParams, headers, body, response, props }) => {
2939
- if (props) {
2940
- acc2.push(
2941
- ...props.flatMap(
2942
- (param) => param.type === import_core2.GetterPropType.NAMED_PATH_PARAMS ? param.schema : []
2943
- )
2944
- );
2945
- }
2946
- if (queryParams) {
2947
- acc2.push(queryParams.schema, ...queryParams.deps);
2948
- }
2949
- if (headers) {
2950
- acc2.push(headers.schema, ...headers.deps);
2951
- }
2952
- acc2.push(...body.schemas);
2953
- acc2.push(...response.schemas);
2954
- return acc2;
2955
- },
2956
- []
2957
- );
2958
- const fullRoute = (0, import_core2.getFullRoute)(
2959
- route,
2960
- (_a2 = verbs.servers) != null ? _a2 : context.specs[context.specKey].servers,
2961
- output.baseUrl
2962
- );
2963
- if (!output.target) {
2964
- (0, import_core2.logError)("Output does not have a target");
2965
- process.exit(1);
2966
- }
2967
- const pathOperations = await generateOperations(
2968
- output.client,
2969
- verbsOptions,
2970
- {
2971
- route: fullRoute,
2972
- pathRoute,
2973
- override: output.override,
2974
- context: resolvedContext,
2975
- mock: output.mock,
2976
- output: output.target
2977
- },
2978
- output
2979
- );
2980
- verbsOptions.forEach((verbOption) => {
2981
- acc.verbOptions[verbOption.operationId] = verbOption;
2982
- });
2983
- acc.schemas.push(...schemas);
2984
- acc.operations = { ...acc.operations, ...pathOperations };
2985
- return acc;
2986
- },
2987
- {
2988
- operations: {},
2989
- verbOptions: {},
2990
- schemas: []
2991
- }
2992
- );
2993
- const extraFiles = await generateExtraFiles(
2994
- output.client,
2995
- api.verbOptions,
2996
- output,
2997
- context
2998
- );
2999
- return {
3000
- operations: api.operations,
3001
- schemas: api.schemas,
3002
- verbOptions: api.verbOptions,
3003
- title: generateClientTitle,
3004
- header: generateClientHeader,
3005
- footer: generateClientFooter,
3006
- imports: generateClientImports,
3007
- importsMock: import_mock.generateMockImports,
3008
- extraFiles
3009
- };
3010
- };
3011
-
3012
- // src/import-open-api.ts
3013
- var importOpenApi = async ({
3014
- data,
3015
- input,
3016
- output,
3017
- target,
3018
- workspace
3019
- }) => {
3020
- var _a;
3021
- const specs = await generateInputSpecs({ specs: data, input, workspace });
3022
- const schemas = getApiSchemas({ input, output, target, workspace, specs });
3023
- const api = await getApiBuilder({
3024
- input,
3025
- output,
3026
- context: {
3027
- specKey: target,
3028
- target,
3029
- workspace,
3030
- specs,
3031
- output
3032
- }
3033
- });
3034
- return {
3035
- ...api,
3036
- schemas: {
3037
- ...schemas,
3038
- [target]: [...(_a = schemas[target]) != null ? _a : [], ...api.schemas]
3039
- },
3040
- target,
3041
- info: specs[target].info
3042
- };
3043
- };
3044
- var generateInputSpecs = async ({
3045
- specs,
3046
- input,
3047
- workspace
3048
- }) => {
3049
- var _a;
3050
- const transformerFn = ((_a = input.override) == null ? void 0 : _a.transformer) ? await (0, import_core3.dynamicImport)(input.override.transformer, workspace) : void 0;
3051
- return (0, import_core3.asyncReduce)(
3052
- Object.entries(specs),
3053
- async (acc, [specKey, value]) => {
3054
- const schema2 = await (0, import_core3.openApiConverter)(
3055
- value,
3056
- input.converterOptions,
3057
- specKey
3058
- );
3059
- const transfomedSchema = transformerFn ? transformerFn(schema2) : schema2;
3060
- if (input.validation) {
3061
- await (0, import_core3.ibmOpenapiValidator)(transfomedSchema, input.validation);
3062
- }
3063
- acc[specKey] = transfomedSchema;
3064
- return acc;
3065
- },
3066
- {}
3067
- );
3068
- };
3069
- var getApiSchemas = ({
3070
- input,
3071
- output,
3072
- target,
3073
- workspace,
3074
- specs
3075
- }) => {
3076
- return Object.entries(specs).reduce(
3077
- (acc, [specKey, spec]) => {
3078
- var _a, _b, _c, _d;
3079
- const context = {
3080
- specKey,
3081
- target,
3082
- workspace,
3083
- specs,
3084
- output
3085
- };
3086
- const parsedSchemas = spec.openapi ? (_a = spec.components) == null ? void 0 : _a.schemas : getAllSchemas(spec, specKey);
3087
- const schemaDefinition = (0, import_core3.generateSchemasDefinition)(
3088
- parsedSchemas,
3089
- context,
3090
- output.override.components.schemas.suffix,
3091
- input.filters
3092
- );
3093
- const responseDefinition = (0, import_core3.generateComponentDefinition)(
3094
- (_b = spec.components) == null ? void 0 : _b.responses,
3095
- context,
3096
- output.override.components.responses.suffix
3097
- );
3098
- const bodyDefinition = (0, import_core3.generateComponentDefinition)(
3099
- (_c = spec.components) == null ? void 0 : _c.requestBodies,
3100
- context,
3101
- output.override.components.requestBodies.suffix
3102
- );
3103
- const parameters = (0, import_core3.generateParameterDefinition)(
3104
- (_d = spec.components) == null ? void 0 : _d.parameters,
3105
- context,
3106
- output.override.components.parameters.suffix
3107
- );
3108
- const schemas = [
3109
- ...schemaDefinition,
3110
- ...responseDefinition,
3111
- ...bodyDefinition,
3112
- ...parameters
3113
- ];
3114
- if (!schemas.length) {
3115
- return acc;
3116
- }
3117
- acc[specKey] = schemas;
3118
- return acc;
3119
- },
3120
- {}
3121
- );
3122
- };
3123
- var getAllSchemas = (spec, specKey) => {
3124
- var _a;
3125
- const keysToOmit = [
3126
- "openapi",
3127
- "info",
3128
- "servers",
3129
- "paths",
3130
- "components",
3131
- "security",
3132
- "tags",
3133
- "externalDocs"
3134
- ];
3135
- const cleanedSpec = Object.fromEntries(
3136
- Object.entries(spec).filter(([key]) => !keysToOmit.includes(key))
3137
- );
3138
- if (specKey && (0, import_core3.isSchema)(cleanedSpec)) {
3139
- const name = import_core3.upath.getSchemaFileName(specKey);
3140
- const additionalKeysToOmit = [
3141
- "type",
3142
- "properties",
3143
- "allOf",
3144
- "oneOf",
3145
- "anyOf",
3146
- "items"
3147
- ];
3148
- return {
3149
- [name]: cleanedSpec,
3150
- ...getAllSchemas(
3151
- Object.fromEntries(
3152
- Object.entries(cleanedSpec).filter(
3153
- ([key]) => !additionalKeysToOmit.includes(key)
3154
- )
3155
- )
3156
- )
3157
- };
3158
- }
3159
- const schemas = Object.entries(cleanedSpec).reduce(
3160
- (acc, [key, value]) => {
3161
- if (!(0, import_core3.isObject)(value)) {
3162
- return acc;
3163
- }
3164
- if (!(0, import_core3.isSchema)(value) && !(0, import_core3.isReference)(value)) {
3165
- return { ...acc, ...getAllSchemas(value) };
3166
- }
3167
- acc[key] = value;
3168
- return acc;
3169
- },
3170
- {}
3171
- );
3172
- return {
3173
- ...schemas,
3174
- ...(_a = spec == null ? void 0 : spec.components) == null ? void 0 : _a.schemas
3175
- };
3176
- };
3177
-
3178
- // src/import-specs.ts
3179
- var resolveSpecs = async (path, { validate, ...options }, isUrl3, isOnlySchema) => {
3180
- try {
3181
- if (validate) {
3182
- try {
3183
- await import_swagger_parser.default.validate(path, options);
3184
- } catch (e) {
3185
- if ((e == null ? void 0 : e.name) === "ParserError") {
3186
- throw e;
3187
- }
3188
- if (!isOnlySchema) {
3189
- (0, import_core4.log)(`\u26A0\uFE0F ${import_chalk.default.yellow(e)}`);
3190
- }
3191
- }
3192
- }
3193
- const data = (await import_swagger_parser.default.resolve(path, options)).values();
3194
- if (isUrl3) {
3195
- return data;
3196
- }
3197
- return Object.fromEntries(
3198
- Object.entries(data).sort().map(([key, value]) => [import_core4.upath.resolve(key), value])
3199
- );
3200
- } catch {
3201
- const file = await import_fs_extra.default.readFile(path, "utf8");
3202
- return {
3203
- [path]: js_yaml_default.load(file)
3204
- };
3205
- }
3206
- };
3207
- var importSpecs = async (workspace, options) => {
3208
- const { input, output } = options;
3209
- if (!(0, import_core4.isString)(input.target)) {
3210
- return importOpenApi({
3211
- data: { [workspace]: input.target },
3212
- input,
3213
- output,
3214
- target: workspace,
3215
- workspace
3216
- });
3217
- }
3218
- const isPathUrl = (0, import_core4.isUrl)(input.target);
3219
- const data = await resolveSpecs(
3220
- input.target,
3221
- input.parserOptions,
3222
- isPathUrl,
3223
- !output.target
3224
- );
3225
- return importOpenApi({
3226
- data,
3227
- input,
3228
- output,
3229
- target: input.target,
3230
- workspace
3231
- });
3232
- };
3233
-
3234
- // src/utils/options.ts
3235
- var import_core8 = require("@orval/core");
3236
- var import_mock2 = require("@orval/mock");
3237
- var import_chalk3 = __toESM(require("chalk"));
3238
-
3239
- // package.json
3240
- var package_default = {
3241
- name: "orval",
3242
- description: "A swagger client generator for typescript",
3243
- version: "7.11.2",
3244
- license: "MIT",
3245
- files: [
3246
- "dist"
3247
- ],
3248
- bin: "dist/bin/orval.js",
3249
- type: "commonjs",
3250
- main: "dist/index.js",
3251
- keywords: [
3252
- "rest",
3253
- "client",
3254
- "swagger",
3255
- "open-api",
3256
- "fetch",
3257
- "data fetching",
3258
- "code-generation",
3259
- "angular",
3260
- "react",
3261
- "react-query",
3262
- "svelte",
3263
- "svelte-query",
3264
- "vue",
3265
- "vue-query",
3266
- "msw",
3267
- "mock",
3268
- "axios",
3269
- "vue-query",
3270
- "vue",
3271
- "swr",
3272
- "zod",
3273
- "hono"
3274
- ],
3275
- author: {
3276
- name: "Victor Bury",
3277
- email: "victor@anymaniax.com"
3278
- },
3279
- repository: {
3280
- type: "git",
3281
- url: "git+https://github.com/orval-labs/orval.git"
3282
- },
3283
- scripts: {
3284
- build: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --dts",
3285
- dev: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --watch ./src --onSuccess 'yarn generate-api'",
3286
- lint: "eslint src/**/*.ts",
3287
- "generate-api": "node ./dist/bin/orval.js --config ../../samples/react-query/basic/orval.config.ts",
3288
- test: "tsc --noEmit && vitest --passWithNoTests"
3289
- },
3290
- devDependencies: {
3291
- "@types/inquirer": "^9.0.6",
3292
- "@types/js-yaml": "^4.0.8",
3293
- "@types/lodash.uniq": "^4.5.8",
3294
- "typedoc-plugin-coverage": "^3.4.1"
3295
- },
3296
- dependencies: {
3297
- "@apidevtools/swagger-parser": "^10.1.1",
3298
- "@orval/angular": "7.11.2",
3299
- "@orval/axios": "7.11.2",
3300
- "@orval/core": "7.11.2",
3301
- "@orval/fetch": "7.11.2",
3302
- "@orval/hono": "7.11.2",
3303
- "@orval/mcp": "7.11.2",
3304
- "@orval/mock": "7.11.2",
3305
- "@orval/query": "7.11.2",
3306
- "@orval/swr": "7.11.2",
3307
- "@orval/zod": "7.11.2",
3308
- ajv: "^8.17.1",
3309
- cac: "^6.7.14",
3310
- chalk: "^4.1.2",
3311
- chokidar: "^4.0.3",
3312
- enquirer: "^2.4.1",
3313
- execa: "^5.1.1",
3314
- "find-up": "5.0.0",
3315
- "fs-extra": "^11.3.0",
3316
- "lodash.uniq": "^4.5.0",
3317
- "openapi3-ts": "4.2.2",
3318
- "string-argv": "^0.3.2",
3319
- tsconfck: "^2.0.1",
3320
- typedoc: "^0.28.7",
3321
- "typedoc-plugin-markdown": "^4.8.0",
3322
- typescript: "^5.6.3"
3323
- }
3324
- };
3325
-
3326
- // src/utils/github.ts
3327
- var import_core5 = require("@orval/core");
3328
- var import_enquirer = require("enquirer");
3329
- var import_fs_extra2 = __toESM(require("fs-extra"));
3330
-
3331
- // src/utils/request.ts
3332
- var import_https = __toESM(require("https"));
3333
- var request = (urlOptions, data) => {
3334
- return new Promise((resolve, reject) => {
3335
- const req = import_https.default.request(urlOptions, (res) => {
3336
- let body = "";
3337
- res.on("data", (chunk) => body += chunk.toString());
3338
- res.on("error", reject);
3339
- res.on("end", () => {
3340
- const response = {
3341
- status: res.statusCode,
3342
- headers: res.headers,
3343
- body: JSON.parse(body)
3344
- };
3345
- if (res.statusCode && res.statusCode >= 200 && res.statusCode <= 299) {
3346
- resolve(response);
3347
- } else {
3348
- reject(response);
3349
- }
3350
- });
3351
- });
3352
- req.on("error", reject);
3353
- if (data) {
3354
- req.write(data, "binary");
3355
- }
3356
- req.end();
3357
- });
3358
- };
3359
-
3360
- // src/utils/github.ts
3361
- var getGithubSpecReq = ({
3362
- accessToken,
3363
- repo,
3364
- owner,
3365
- branch,
3366
- path
3367
- }) => {
3368
- const payload = JSON.stringify({
3369
- query: `query {
3370
- repository(name: "${repo}", owner: "${owner}") {
3371
- object(expression: "${branch}:${path}") {
3372
- ... on Blob {
3373
- text
3374
- }
3375
- }
3376
- }
3377
- }`
3378
- });
3379
- return [
3380
- {
3381
- method: "POST",
3382
- hostname: "api.github.com",
3383
- path: "/graphql",
3384
- headers: {
3385
- "content-type": "application/json",
3386
- "user-agent": "orval-importer",
3387
- authorization: `bearer ${accessToken}`,
3388
- "Content-Length": payload.length
3389
- }
3390
- },
3391
- payload
3392
- ];
3393
- };
3394
- var githubToken = null;
3395
- var getGithubAcessToken = async (githubTokenPath) => {
3396
- if (githubToken) {
3397
- return githubToken;
3398
- }
3399
- if (await import_fs_extra2.default.pathExists(githubTokenPath)) {
3400
- return import_fs_extra2.default.readFile(githubTokenPath, "utf-8");
3401
- } else {
3402
- const answers = await (0, import_enquirer.prompt)([
3403
- {
3404
- type: "input",
3405
- name: "githubToken",
3406
- message: "Please provide a GitHub token with `repo` rules checked (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)"
3407
- },
3408
- {
3409
- type: "confirm",
3410
- name: "saveToken",
3411
- message: "Would you like to store your token for the next time? (stored in your node_modules)"
3412
- }
3413
- ]);
3414
- githubToken = answers.githubToken;
3415
- if (answers.saveToken) {
3416
- await import_fs_extra2.default.outputFile(githubTokenPath, answers.githubToken);
3417
- }
3418
- return answers.githubToken;
3419
- }
3420
- };
3421
- var getGithubOpenApi = async (url) => {
3422
- var _a, _b, _c, _d;
3423
- const githubTokenPath = import_core5.upath.join(__dirname, ".githubToken");
3424
- const accessToken = await getGithubAcessToken(githubTokenPath);
3425
- const [info] = url.split("github.com/").slice(-1);
3426
- const [owner, repo, , branch, ...paths] = info.split("/");
3427
- const path = paths.join("/");
3428
- try {
3429
- const { body } = await request(...getGithubSpecReq({ accessToken, repo, owner, branch, path }));
3430
- if ((_a = body.errors) == null ? void 0 : _a.length) {
3431
- const isErrorRemoveLink = (_b = body.errors) == null ? void 0 : _b.some(
3432
- (error) => (error == null ? void 0 : error.type) === "NOT_FOUND"
3433
- );
3434
- if (isErrorRemoveLink) {
3435
- const answers = await (0, import_enquirer.prompt)([
3436
- {
3437
- type: "confirm",
3438
- name: "removeToken",
3439
- message: "Your token doesn't have the correct permissions, should we remove it?"
3440
- }
3441
- ]);
3442
- if (answers.removeToken) {
3443
- await import_fs_extra2.default.unlink(githubTokenPath);
3444
- }
3445
- }
3446
- }
3447
- return (_d = (_c = body.data) == null ? void 0 : _c.repository) == null ? void 0 : _d.object.text;
3448
- } catch (e) {
3449
- if (!e.body) {
3450
- throw `Oups... \u{1F37B}. ${e}`;
3451
- }
3452
- if (e.body.message === "Bad credentials") {
3453
- const answers = await (0, import_enquirer.prompt)([
3454
- {
3455
- type: "confirm",
3456
- name: "removeToken",
3457
- message: "Your token doesn't have the correct permissions, should we remove it?"
3458
- }
3459
- ]);
3460
- if (answers.removeToken) {
3461
- await import_fs_extra2.default.unlink(githubTokenPath);
3462
- }
3463
- }
3464
- throw e.body.message || `Oups... \u{1F37B}. ${e}`;
3465
- }
3466
- };
3467
- var githubResolver = {
3468
- order: 199,
3469
- canRead(file) {
3470
- return file.url.includes("github.com");
3471
- },
3472
- read(file) {
3473
- return getGithubOpenApi(file.url);
3474
- }
3475
- };
3476
-
3477
- // src/utils/package-json.ts
3478
- var import_core6 = require("@orval/core");
3479
- var import_chalk2 = __toESM(require("chalk"));
3480
- var import_find_up = __toESM(require("find-up"));
3481
- var import_fs_extra3 = __toESM(require("fs-extra"));
3482
- var loadPackageJson = async (packageJson, workspace = process.cwd()) => {
3483
- if (!packageJson) {
3484
- const pkgPath = await (0, import_find_up.default)(["package.json"], {
3485
- cwd: workspace
3486
- });
3487
- if (pkgPath) {
3488
- const pkg = await Promise.resolve().then(() => __toESM(require(pkgPath)));
3489
- return await maybeReplaceCatalog(pkg, workspace);
3490
- }
3491
- return;
3492
- }
3493
- const normalizedPath = normalizePath(packageJson, workspace);
3494
- if (import_fs_extra3.default.existsSync(normalizedPath)) {
3495
- const pkg = await Promise.resolve().then(() => __toESM(require(normalizedPath)));
3496
- return await maybeReplaceCatalog(pkg, workspace);
3497
- }
3498
- return;
3499
- };
3500
- var maybeReplaceCatalog = async (pkg, workspace) => {
3501
- var _a, _b, _c;
3502
- if (![
3503
- ...Object.entries((_a = pkg.dependencies) != null ? _a : {}),
3504
- ...Object.entries((_b = pkg.devDependencies) != null ? _b : {}),
3505
- ...Object.entries((_c = pkg.peerDependencies) != null ? _c : {})
3506
- ].some(([, value]) => (0, import_core6.isString)(value) && value.startsWith("catalog:"))) {
3507
- return pkg;
3508
- }
3509
- const filePath = await (0, import_find_up.default)("pnpm-workspace.yaml", { cwd: workspace });
3510
- if (!filePath) {
3511
- (0, import_core6.log)(
3512
- `\u26A0\uFE0F ${import_chalk2.default.yellow("package.json contains pnpm catalog: in dependencies, but no pnpm-workspace.yaml was found.")}`
3513
- );
3514
- return pkg;
3515
- }
3516
- const file = await import_fs_extra3.default.readFile(filePath, "utf8");
3517
- const pnpmWorkspaceFile = js_yaml_default.load(file);
3518
- performSubstitution(pkg.dependencies, pnpmWorkspaceFile);
3519
- performSubstitution(pkg.devDependencies, pnpmWorkspaceFile);
3520
- performSubstitution(pkg.peerDependencies, pnpmWorkspaceFile);
3521
- return pkg;
3522
- };
3523
- var performSubstitution = (dependencies, pnpmWorkspaceFile) => {
3524
- var _a, _b;
3525
- if (!dependencies) return;
3526
- for (const [packageName, version] of Object.entries(dependencies)) {
3527
- if (version === "catalog:" || version === "catalog:default") {
3528
- if (!pnpmWorkspaceFile.catalog) {
3529
- (0, import_core6.log)(
3530
- `\u26A0\uFE0F ${import_chalk2.default.yellow(`when reading from pnpm-workspace.yaml, catalog: substitution for the package '${packageName}' failed as there were no default catalog.`)}`
3531
- );
3532
- continue;
3533
- }
3534
- const sub = pnpmWorkspaceFile.catalog[packageName];
3535
- if (!sub) {
3536
- (0, import_core6.log)(
3537
- `\u26A0\uFE0F ${import_chalk2.default.yellow(`when reading from pnpm-workspace.yaml, catalog: substitution for the package '${packageName}' failed as there were no matching package in the default catalog.`)}`
3538
- );
3539
- continue;
3540
- }
3541
- dependencies[packageName] = sub;
3542
- } else if (version.startsWith("catalog:")) {
3543
- const catalogName = version.substring("catalog:".length);
3544
- const catalog = (_a = pnpmWorkspaceFile.catalogs) == null ? void 0 : _a[catalogName];
3545
- if (!catalog) {
3546
- (0, import_core6.log)(
3547
- `\u26A0\uFE0F ${import_chalk2.default.yellow(`when reading from pnpm-workspace.yaml, '${version}' substitution for the package '${packageName}' failed as there were no matching catalog named '${catalogName}'. (available named catalogs are: ${Object.keys((_b = pnpmWorkspaceFile.catalogs) != null ? _b : {}).join(", ")})`)}`
3548
- );
3549
- continue;
3550
- }
3551
- const sub = catalog[packageName];
3552
- if (!sub) {
3553
- (0, import_core6.log)(
3554
- `\u26A0\uFE0F ${import_chalk2.default.yellow(`when reading from pnpm-workspace.yaml, '${version}' substitution for the package '${packageName}' failed as there were no package in the catalog named '${catalogName}'. (packages in the catalog are: ${Object.keys(catalog).join(", ")})`)}`
3555
- );
3556
- continue;
3557
- }
3558
- dependencies[packageName] = sub;
3559
- }
3560
- }
3561
- };
3562
-
3563
- // src/utils/tsconfig.ts
3564
- var import_core7 = require("@orval/core");
3565
- var import_find_up2 = __toESM(require("find-up"));
3566
- var import_fs_extra4 = __toESM(require("fs-extra"));
3567
- var import_tsconfck = require("tsconfck");
3568
- var loadTsconfig = async (tsconfig, workspace = process.cwd()) => {
3569
- var _a, _b;
3570
- if ((0, import_core7.isUndefined)(tsconfig)) {
3571
- const configPath = await (0, import_find_up2.default)(["tsconfig.json", "jsconfig.json"], {
3572
- cwd: workspace
3573
- });
3574
- if (configPath) {
3575
- const config = await (0, import_tsconfck.parse)(configPath);
3576
- return config.tsconfig;
3577
- }
3578
- return;
3579
- }
3580
- if ((0, import_core7.isString)(tsconfig)) {
3581
- const normalizedPath = normalizePath(tsconfig, workspace);
3582
- if (import_fs_extra4.default.existsSync(normalizedPath)) {
3583
- const config = await (0, import_tsconfck.parse)(normalizedPath);
3584
- const tsconfig2 = ((_b = (_a = config.referenced) == null ? void 0 : _a.find(
3585
- ({ tsconfigFile }) => tsconfigFile === normalizedPath
3586
- )) == null ? void 0 : _b.tsconfig) || config.tsconfig;
3587
- return tsconfig2;
3588
- }
3589
- return;
3590
- }
3591
- if ((0, import_core7.isObject)(tsconfig)) {
3592
- return tsconfig;
3593
- }
3594
- return;
3595
- };
3596
-
3597
- // src/utils/options.ts
3598
- var createFormData = (workspace, formData) => {
3599
- var _a;
3600
- const defaultArrayHandling = import_core8.FormDataArrayHandling.SERIALIZE;
3601
- if (formData === void 0)
3602
- return { disabled: false, arrayHandling: defaultArrayHandling };
3603
- if ((0, import_core8.isBoolean)(formData))
3604
- return { disabled: !formData, arrayHandling: defaultArrayHandling };
3605
- if ((0, import_core8.isString)(formData))
3606
- return {
3607
- disabled: false,
3608
- mutator: normalizeMutator(workspace, formData),
3609
- arrayHandling: defaultArrayHandling
3610
- };
3611
- if ("mutator" in formData || "arrayHandling" in formData)
3612
- return {
3613
- disabled: false,
3614
- mutator: normalizeMutator(workspace, formData.mutator),
3615
- arrayHandling: (_a = formData.arrayHandling) != null ? _a : defaultArrayHandling
3616
- };
3617
- return {
3618
- disabled: false,
3619
- mutator: normalizeMutator(workspace, formData),
3620
- arrayHandling: defaultArrayHandling
3621
- };
3622
- };
3623
- var normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOptions = {}) => {
3624
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib, _Jb, _Kb, _Lb, _Mb, _Nb, _Ob, _Pb, _Qb, _Rb, _Sb, _Tb, _Ub, _Vb, _Wb, _Xb, _Yb, _Zb, __b, _$b, _ac, _bc, _cc, _dc, _ec, _fc, _gc, _hc, _ic, _jc, _kc, _lc, _mc, _nc, _oc, _pc, _qc, _rc, _sc, _tc, _uc;
3625
- const options = await ((0, import_core8.isFunction)(optionsExport) ? optionsExport() : optionsExport);
3626
- if (!options.input) {
3627
- (0, import_core8.createLogger)().error(import_chalk3.default.red(`Config require an input`));
3628
- process.exit(1);
3629
- }
3630
- if (!options.output) {
3631
- (0, import_core8.createLogger)().error(import_chalk3.default.red(`Config require an output`));
3632
- process.exit(1);
3633
- }
3634
- const inputOptions = (0, import_core8.isString)(options.input) ? { target: options.input } : options.input;
3635
- const outputOptions = (0, import_core8.isString)(options.output) ? { target: options.output } : options.output;
3636
- const outputWorkspace = normalizePath(
3637
- outputOptions.workspace || "",
3638
- workspace
3639
- );
3640
- const { clean, prettier, client, httpClient, mode, tslint, biome } = globalOptions;
3641
- const tsconfig = await loadTsconfig(
3642
- outputOptions.tsconfig || globalOptions.tsconfig,
3643
- workspace
3644
- );
3645
- const packageJson = await loadPackageJson(
3646
- outputOptions.packageJson || globalOptions.packageJson,
3647
- workspace
3648
- );
3649
- const mockOption = (_a = outputOptions.mock) != null ? _a : globalOptions.mock;
3650
- let mock2;
3651
- if (typeof mockOption === "boolean" && mockOption) {
3652
- mock2 = import_mock2.DEFAULT_MOCK_OPTIONS;
3653
- } else if ((0, import_core8.isFunction)(mockOption)) {
3654
- mock2 = mockOption;
3655
- } else if (!mockOption) {
3656
- mock2 = void 0;
3657
- } else {
3658
- mock2 = {
3659
- ...import_mock2.DEFAULT_MOCK_OPTIONS,
3660
- ...mockOption
3661
- };
3662
- }
3663
- const defaultFileExtension = ".ts";
3664
- const globalQueryOptions = {
3665
- useQuery: true,
3666
- useMutation: true,
3667
- signal: true,
3668
- shouldExportMutatorHooks: true,
3669
- shouldExportHttpClient: true,
3670
- shouldExportQueryKey: true,
3671
- shouldSplitQueryKey: false,
3672
- ...normalizeQueryOptions((_b = outputOptions.override) == null ? void 0 : _b.query, workspace)
3673
- };
3674
- const normalizedOptions = {
3675
- input: {
3676
- target: globalOptions.input ? normalizePathOrUrl(globalOptions.input, process.cwd()) : normalizePathOrUrl(inputOptions.target, workspace),
3677
- validation: inputOptions.validation || false,
3678
- override: {
3679
- transformer: normalizePath(
3680
- (_c = inputOptions.override) == null ? void 0 : _c.transformer,
3681
- workspace
3682
- )
3683
- },
3684
- converterOptions: (_d = inputOptions.converterOptions) != null ? _d : {},
3685
- parserOptions: (0, import_core8.mergeDeep)(
3686
- parserDefaultOptions,
3687
- (_e = inputOptions.parserOptions) != null ? _e : {}
3688
- ),
3689
- filters: inputOptions.filters
3690
- },
3691
- output: {
3692
- target: globalOptions.output ? normalizePath(globalOptions.output, process.cwd()) : normalizePath(outputOptions.target, outputWorkspace),
3693
- schemas: normalizePath(outputOptions.schemas, outputWorkspace),
3694
- namingConvention: outputOptions.namingConvention || import_core8.NamingConvention.CAMEL_CASE,
3695
- fileExtension: outputOptions.fileExtension || defaultFileExtension,
3696
- workspace: outputOptions.workspace ? outputWorkspace : void 0,
3697
- client: (_g = (_f = outputOptions.client) != null ? _f : client) != null ? _g : import_core8.OutputClient.AXIOS_FUNCTIONS,
3698
- httpClient: (_i = (_h = outputOptions.httpClient) != null ? _h : httpClient) != null ? _i : import_core8.OutputHttpClient.AXIOS,
3699
- mode: normalizeOutputMode((_j = outputOptions.mode) != null ? _j : mode),
3700
- mock: mock2,
3701
- clean: (_l = (_k = outputOptions.clean) != null ? _k : clean) != null ? _l : false,
3702
- docs: (_m = outputOptions.docs) != null ? _m : false,
3703
- prettier: (_o = (_n = outputOptions.prettier) != null ? _n : prettier) != null ? _o : false,
3704
- tslint: (_q = (_p = outputOptions.tslint) != null ? _p : tslint) != null ? _q : false,
3705
- biome: (_s = (_r = outputOptions.biome) != null ? _r : biome) != null ? _s : false,
3706
- tsconfig,
3707
- packageJson,
3708
- headers: (_t = outputOptions.headers) != null ? _t : false,
3709
- indexFiles: (_u = outputOptions.indexFiles) != null ? _u : true,
3710
- baseUrl: outputOptions.baseUrl,
3711
- unionAddMissingProperties: (_v = outputOptions.unionAddMissingProperties) != null ? _v : false,
3712
- override: {
3713
- ...outputOptions.override,
3714
- mock: {
3715
- arrayMin: (_y = (_x = (_w = outputOptions.override) == null ? void 0 : _w.mock) == null ? void 0 : _x.arrayMin) != null ? _y : 1,
3716
- arrayMax: (_B = (_A = (_z = outputOptions.override) == null ? void 0 : _z.mock) == null ? void 0 : _A.arrayMax) != null ? _B : 10,
3717
- stringMin: (_E = (_D = (_C = outputOptions.override) == null ? void 0 : _C.mock) == null ? void 0 : _D.stringMin) != null ? _E : 10,
3718
- stringMax: (_H = (_G = (_F = outputOptions.override) == null ? void 0 : _F.mock) == null ? void 0 : _G.stringMax) != null ? _H : 20,
3719
- fractionDigits: (_K = (_J = (_I = outputOptions.override) == null ? void 0 : _I.mock) == null ? void 0 : _J.fractionDigits) != null ? _K : 2,
3720
- ...(_L = outputOptions.override) == null ? void 0 : _L.mock
3721
- },
3722
- operations: normalizeOperationsAndTags(
3723
- (_N = (_M = outputOptions.override) == null ? void 0 : _M.operations) != null ? _N : {},
3724
- outputWorkspace,
3725
- {
3726
- query: globalQueryOptions
3727
- }
3728
- ),
3729
- tags: normalizeOperationsAndTags(
3730
- (_P = (_O = outputOptions.override) == null ? void 0 : _O.tags) != null ? _P : {},
3731
- outputWorkspace,
3732
- {
3733
- query: globalQueryOptions
3734
- }
3735
- ),
3736
- mutator: normalizeMutator(
3737
- outputWorkspace,
3738
- (_Q = outputOptions.override) == null ? void 0 : _Q.mutator
3739
- ),
3740
- formData: createFormData(
3741
- outputWorkspace,
3742
- (_R = outputOptions.override) == null ? void 0 : _R.formData
3743
- ),
3744
- formUrlEncoded: (_V = !(0, import_core8.isBoolean)((_S = outputOptions.override) == null ? void 0 : _S.formUrlEncoded) ? normalizeMutator(
3745
- outputWorkspace,
3746
- (_T = outputOptions.override) == null ? void 0 : _T.formUrlEncoded
3747
- ) : (_U = outputOptions.override) == null ? void 0 : _U.formUrlEncoded) != null ? _V : true,
3748
- paramsSerializer: normalizeMutator(
3749
- outputWorkspace,
3750
- (_W = outputOptions.override) == null ? void 0 : _W.paramsSerializer
3751
- ),
3752
- header: ((_X = outputOptions.override) == null ? void 0 : _X.header) === false ? false : (0, import_core8.isFunction)((_Y = outputOptions.override) == null ? void 0 : _Y.header) ? (_Z = outputOptions.override) == null ? void 0 : _Z.header : getDefaultFilesHeader,
3753
- requestOptions: (_$ = (__ = outputOptions.override) == null ? void 0 : __.requestOptions) != null ? _$ : true,
3754
- namingConvention: (_ba = (_aa = outputOptions.override) == null ? void 0 : _aa.namingConvention) != null ? _ba : {},
3755
- components: {
3756
- schemas: {
3757
- suffix: import_core8.RefComponentSuffix.schemas,
3758
- itemSuffix: (_fa = (_ea = (_da = (_ca = outputOptions.override) == null ? void 0 : _ca.components) == null ? void 0 : _da.schemas) == null ? void 0 : _ea.itemSuffix) != null ? _fa : "Item",
3759
- ...(_ia = (_ha = (_ga = outputOptions.override) == null ? void 0 : _ga.components) == null ? void 0 : _ha.schemas) != null ? _ia : {}
3760
- },
3761
- responses: {
3762
- suffix: import_core8.RefComponentSuffix.responses,
3763
- ...(_la = (_ka = (_ja = outputOptions.override) == null ? void 0 : _ja.components) == null ? void 0 : _ka.responses) != null ? _la : {}
3764
- },
3765
- parameters: {
3766
- suffix: import_core8.RefComponentSuffix.parameters,
3767
- ...(_oa = (_na = (_ma = outputOptions.override) == null ? void 0 : _ma.components) == null ? void 0 : _na.parameters) != null ? _oa : {}
3768
- },
3769
- requestBodies: {
3770
- suffix: import_core8.RefComponentSuffix.requestBodies,
3771
- ...(_ra = (_qa = (_pa = outputOptions.override) == null ? void 0 : _pa.components) == null ? void 0 : _qa.requestBodies) != null ? _ra : {}
3772
- }
3773
- },
3774
- hono: normalizeHonoOptions((_sa = outputOptions.override) == null ? void 0 : _sa.hono, workspace),
3775
- jsDoc: normalizeJSDocOptions((_ta = outputOptions.override) == null ? void 0 : _ta.jsDoc),
3776
- query: globalQueryOptions,
3777
- zod: {
3778
- strict: {
3779
- param: (_xa = (_wa = (_va = (_ua = outputOptions.override) == null ? void 0 : _ua.zod) == null ? void 0 : _va.strict) == null ? void 0 : _wa.param) != null ? _xa : false,
3780
- query: (_Ba = (_Aa = (_za = (_ya = outputOptions.override) == null ? void 0 : _ya.zod) == null ? void 0 : _za.strict) == null ? void 0 : _Aa.query) != null ? _Ba : false,
3781
- header: (_Fa = (_Ea = (_Da = (_Ca = outputOptions.override) == null ? void 0 : _Ca.zod) == null ? void 0 : _Da.strict) == null ? void 0 : _Ea.header) != null ? _Fa : false,
3782
- body: (_Ja = (_Ia = (_Ha = (_Ga = outputOptions.override) == null ? void 0 : _Ga.zod) == null ? void 0 : _Ha.strict) == null ? void 0 : _Ia.body) != null ? _Ja : false,
3783
- response: (_Na = (_Ma = (_La = (_Ka = outputOptions.override) == null ? void 0 : _Ka.zod) == null ? void 0 : _La.strict) == null ? void 0 : _Ma.response) != null ? _Na : false
3784
- },
3785
- generate: {
3786
- param: (_Ra = (_Qa = (_Pa = (_Oa = outputOptions.override) == null ? void 0 : _Oa.zod) == null ? void 0 : _Pa.generate) == null ? void 0 : _Qa.param) != null ? _Ra : true,
3787
- query: (_Va = (_Ua = (_Ta = (_Sa = outputOptions.override) == null ? void 0 : _Sa.zod) == null ? void 0 : _Ta.generate) == null ? void 0 : _Ua.query) != null ? _Va : true,
3788
- header: (_Za = (_Ya = (_Xa = (_Wa = outputOptions.override) == null ? void 0 : _Wa.zod) == null ? void 0 : _Xa.generate) == null ? void 0 : _Ya.header) != null ? _Za : true,
3789
- body: (_bb = (_ab = (_$a = (__a = outputOptions.override) == null ? void 0 : __a.zod) == null ? void 0 : _$a.generate) == null ? void 0 : _ab.body) != null ? _bb : true,
3790
- response: (_fb = (_eb = (_db = (_cb = outputOptions.override) == null ? void 0 : _cb.zod) == null ? void 0 : _db.generate) == null ? void 0 : _eb.response) != null ? _fb : true
3791
- },
3792
- coerce: {
3793
- param: (_jb = (_ib = (_hb = (_gb = outputOptions.override) == null ? void 0 : _gb.zod) == null ? void 0 : _hb.coerce) == null ? void 0 : _ib.param) != null ? _jb : false,
3794
- query: (_nb = (_mb = (_lb = (_kb = outputOptions.override) == null ? void 0 : _kb.zod) == null ? void 0 : _lb.coerce) == null ? void 0 : _mb.query) != null ? _nb : false,
3795
- header: (_rb = (_qb = (_pb = (_ob = outputOptions.override) == null ? void 0 : _ob.zod) == null ? void 0 : _pb.coerce) == null ? void 0 : _qb.header) != null ? _rb : false,
3796
- body: (_vb = (_ub = (_tb = (_sb = outputOptions.override) == null ? void 0 : _sb.zod) == null ? void 0 : _tb.coerce) == null ? void 0 : _ub.body) != null ? _vb : false,
3797
- response: (_zb = (_yb = (_xb = (_wb = outputOptions.override) == null ? void 0 : _wb.zod) == null ? void 0 : _xb.coerce) == null ? void 0 : _yb.response) != null ? _zb : false
3798
- },
3799
- preprocess: {
3800
- ...((_Cb = (_Bb = (_Ab = outputOptions.override) == null ? void 0 : _Ab.zod) == null ? void 0 : _Bb.preprocess) == null ? void 0 : _Cb.param) ? {
3801
- param: normalizeMutator(
3802
- workspace,
3803
- outputOptions.override.zod.preprocess.param
3804
- )
3805
- } : {},
3806
- ...((_Fb = (_Eb = (_Db = outputOptions.override) == null ? void 0 : _Db.zod) == null ? void 0 : _Eb.preprocess) == null ? void 0 : _Fb.query) ? {
3807
- query: normalizeMutator(
3808
- workspace,
3809
- outputOptions.override.zod.preprocess.query
3810
- )
3811
- } : {},
3812
- ...((_Ib = (_Hb = (_Gb = outputOptions.override) == null ? void 0 : _Gb.zod) == null ? void 0 : _Hb.preprocess) == null ? void 0 : _Ib.header) ? {
3813
- header: normalizeMutator(
3814
- workspace,
3815
- outputOptions.override.zod.preprocess.header
3816
- )
3817
- } : {},
3818
- ...((_Lb = (_Kb = (_Jb = outputOptions.override) == null ? void 0 : _Jb.zod) == null ? void 0 : _Kb.preprocess) == null ? void 0 : _Lb.body) ? {
3819
- body: normalizeMutator(
3820
- workspace,
3821
- outputOptions.override.zod.preprocess.body
3822
- )
3823
- } : {},
3824
- ...((_Ob = (_Nb = (_Mb = outputOptions.override) == null ? void 0 : _Mb.zod) == null ? void 0 : _Nb.preprocess) == null ? void 0 : _Ob.response) ? {
3825
- response: normalizeMutator(
3826
- workspace,
3827
- outputOptions.override.zod.preprocess.response
3828
- )
3829
- } : {}
3830
- },
3831
- generateEachHttpStatus: (_Rb = (_Qb = (_Pb = outputOptions.override) == null ? void 0 : _Pb.zod) == null ? void 0 : _Qb.generateEachHttpStatus) != null ? _Rb : false,
3832
- dateTimeOptions: (_Ub = (_Tb = (_Sb = outputOptions.override) == null ? void 0 : _Sb.zod) == null ? void 0 : _Tb.dateTimeOptions) != null ? _Ub : {},
3833
- timeOptions: (_Xb = (_Wb = (_Vb = outputOptions.override) == null ? void 0 : _Vb.zod) == null ? void 0 : _Wb.timeOptions) != null ? _Xb : {}
3834
- },
3835
- swr: {
3836
- ...(_Zb = (_Yb = outputOptions.override) == null ? void 0 : _Yb.swr) != null ? _Zb : {}
3837
- },
3838
- angular: {
3839
- provideIn: (_ac = (_$b = (__b = outputOptions.override) == null ? void 0 : __b.angular) == null ? void 0 : _$b.provideIn) != null ? _ac : "root"
3840
- },
3841
- fetch: {
3842
- includeHttpResponseReturnType: (_dc = (_cc = (_bc = outputOptions.override) == null ? void 0 : _bc.fetch) == null ? void 0 : _cc.includeHttpResponseReturnType) != null ? _dc : true,
3843
- explode: (_gc = (_fc = (_ec = outputOptions.override) == null ? void 0 : _ec.fetch) == null ? void 0 : _fc.explode) != null ? _gc : true,
3844
- ...(_ic = (_hc = outputOptions.override) == null ? void 0 : _hc.fetch) != null ? _ic : {}
3845
- },
3846
- useDates: ((_jc = outputOptions.override) == null ? void 0 : _jc.useDates) || false,
3847
- useDeprecatedOperations: (_lc = (_kc = outputOptions.override) == null ? void 0 : _kc.useDeprecatedOperations) != null ? _lc : true,
3848
- enumGenerationType: ((_nc = (_mc = outputOptions.override) == null ? void 0 : _mc.useNativeEnums) != null ? _nc : false) ? "enum" : (_pc = (_oc = outputOptions.override) == null ? void 0 : _oc.enumGenerationType) != null ? _pc : "const",
3849
- suppressReadonlyModifier: ((_qc = outputOptions.override) == null ? void 0 : _qc.suppressReadonlyModifier) || false
3850
- },
3851
- allParamsOptional: (_rc = outputOptions.allParamsOptional) != null ? _rc : false,
3852
- urlEncodeParameters: (_sc = outputOptions.urlEncodeParameters) != null ? _sc : false,
3853
- optionsParamRequired: (_tc = outputOptions.optionsParamRequired) != null ? _tc : false,
3854
- propertySortOrder: (_uc = outputOptions.propertySortOrder) != null ? _uc : import_core8.PropertySortOrder.SPECIFICATION
3855
- },
3856
- hooks: options.hooks ? normalizeHooks(options.hooks) : {}
3857
- };
3858
- if (!normalizedOptions.input.target) {
3859
- (0, import_core8.createLogger)().error(import_chalk3.default.red(`Config require an input target`));
3860
- process.exit(1);
3861
- }
3862
- if (!normalizedOptions.output.target && !normalizedOptions.output.schemas) {
3863
- (0, import_core8.createLogger)().error(
3864
- import_chalk3.default.red(`Config require an output target or schemas`)
3865
- );
3866
- process.exit(1);
3867
- }
3868
- return normalizedOptions;
3869
- };
3870
- var parserDefaultOptions = {
3871
- validate: true,
3872
- resolve: { github: githubResolver }
3873
- };
3874
- var normalizeMutator = (workspace, mutator) => {
3875
- var _a;
3876
- if ((0, import_core8.isObject)(mutator)) {
3877
- if (!mutator.path) {
3878
- (0, import_core8.createLogger)().error(import_chalk3.default.red(`Mutator need a path`));
3879
- process.exit(1);
3880
- }
3881
- return {
3882
- ...mutator,
3883
- path: import_core8.upath.resolve(workspace, mutator.path),
3884
- default: (_a = mutator.default || !mutator.name) != null ? _a : false
3885
- };
3886
- }
3887
- if ((0, import_core8.isString)(mutator)) {
3888
- return {
3889
- path: import_core8.upath.resolve(workspace, mutator),
3890
- default: true
3891
- };
3892
- }
3893
- return mutator;
3894
- };
3895
- var normalizePathOrUrl = (path, workspace) => {
3896
- if ((0, import_core8.isString)(path) && !(0, import_core8.isUrl)(path)) {
3897
- return normalizePath(path, workspace);
3898
- }
3899
- return path;
3900
- };
3901
- var normalizePath = (path, workspace) => {
3902
- if (!(0, import_core8.isString)(path)) {
3903
- return path;
3904
- }
3905
- return import_core8.upath.resolve(workspace, path);
3906
- };
3907
- var normalizeOperationsAndTags = (operationsOrTags, workspace, global) => {
3908
- return Object.fromEntries(
3909
- Object.entries(operationsOrTags).map(
3910
- ([
3911
- key,
3912
- {
3913
- transformer,
3914
- mutator,
3915
- formData,
3916
- formUrlEncoded,
3917
- paramsSerializer,
3918
- query: query2,
3919
- zod: zod2,
3920
- ...rest
3921
- }
3922
- ]) => {
3923
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
3924
- return [
3925
- key,
3926
- {
3927
- ...rest,
3928
- ...query2 ? {
3929
- query: normalizeQueryOptions(query2, workspace, global.query)
3930
- } : {},
3931
- ...zod2 ? {
3932
- zod: {
3933
- strict: {
3934
- param: (_b = (_a = zod2.strict) == null ? void 0 : _a.param) != null ? _b : false,
3935
- query: (_d = (_c = zod2.strict) == null ? void 0 : _c.query) != null ? _d : false,
3936
- header: (_f = (_e = zod2.strict) == null ? void 0 : _e.header) != null ? _f : false,
3937
- body: (_h = (_g = zod2.strict) == null ? void 0 : _g.body) != null ? _h : false,
3938
- response: (_j = (_i = zod2.strict) == null ? void 0 : _i.response) != null ? _j : false
3939
- },
3940
- generate: {
3941
- param: (_l = (_k = zod2.generate) == null ? void 0 : _k.param) != null ? _l : true,
3942
- query: (_n = (_m = zod2.generate) == null ? void 0 : _m.query) != null ? _n : true,
3943
- header: (_p = (_o = zod2.generate) == null ? void 0 : _o.header) != null ? _p : true,
3944
- body: (_r = (_q = zod2.generate) == null ? void 0 : _q.body) != null ? _r : true,
3945
- response: (_t = (_s = zod2.generate) == null ? void 0 : _s.response) != null ? _t : true
3946
- },
3947
- coerce: {
3948
- param: (_v = (_u = zod2.coerce) == null ? void 0 : _u.param) != null ? _v : false,
3949
- query: (_x = (_w = zod2.coerce) == null ? void 0 : _w.query) != null ? _x : false,
3950
- header: (_z = (_y = zod2.coerce) == null ? void 0 : _y.header) != null ? _z : false,
3951
- body: (_B = (_A = zod2.coerce) == null ? void 0 : _A.body) != null ? _B : false,
3952
- response: (_D = (_C = zod2.coerce) == null ? void 0 : _C.response) != null ? _D : false
3953
- },
3954
- preprocess: {
3955
- ...((_E = zod2.preprocess) == null ? void 0 : _E.param) ? {
3956
- param: normalizeMutator(
3957
- workspace,
3958
- zod2.preprocess.param
3959
- )
3960
- } : {},
3961
- ...((_F = zod2.preprocess) == null ? void 0 : _F.query) ? {
3962
- query: normalizeMutator(
3963
- workspace,
3964
- zod2.preprocess.query
3965
- )
3966
- } : {},
3967
- ...((_G = zod2.preprocess) == null ? void 0 : _G.header) ? {
3968
- header: normalizeMutator(
3969
- workspace,
3970
- zod2.preprocess.header
3971
- )
3972
- } : {},
3973
- ...((_H = zod2.preprocess) == null ? void 0 : _H.body) ? {
3974
- body: normalizeMutator(
3975
- workspace,
3976
- zod2.preprocess.body
3977
- )
3978
- } : {},
3979
- ...((_I = zod2.preprocess) == null ? void 0 : _I.response) ? {
3980
- response: normalizeMutator(
3981
- workspace,
3982
- zod2.preprocess.response
3983
- )
3984
- } : {}
3985
- },
3986
- generateEachHttpStatus: (_J = zod2 == null ? void 0 : zod2.generateEachHttpStatus) != null ? _J : false,
3987
- dateTimeOptions: (_K = zod2 == null ? void 0 : zod2.dateTimeOptions) != null ? _K : {},
3988
- timeOptions: (_L = zod2 == null ? void 0 : zod2.timeOptions) != null ? _L : {}
3989
- }
3990
- } : {},
3991
- ...transformer ? { transformer: normalizePath(transformer, workspace) } : {},
3992
- ...mutator ? { mutator: normalizeMutator(workspace, mutator) } : {},
3993
- ...createFormData(workspace, formData),
3994
- ...formUrlEncoded ? {
3995
- formUrlEncoded: !(0, import_core8.isBoolean)(formUrlEncoded) ? normalizeMutator(workspace, formUrlEncoded) : formUrlEncoded
3996
- } : {},
3997
- ...paramsSerializer ? {
3998
- paramsSerializer: normalizeMutator(
3999
- workspace,
4000
- paramsSerializer
4001
- )
4002
- } : {}
4003
- }
4004
- ];
4005
- }
4006
- )
4007
- );
4008
- };
4009
- var normalizeOutputMode = (mode) => {
4010
- if (!mode) {
4011
- return import_core8.OutputMode.SINGLE;
4012
- }
4013
- if (!Object.values(import_core8.OutputMode).includes(mode)) {
4014
- (0, import_core8.createLogger)().warn(import_chalk3.default.yellow(`Unknown the provided mode => ${mode}`));
4015
- return import_core8.OutputMode.SINGLE;
4016
- }
4017
- return mode;
4018
- };
4019
- var normalizeHooks = (hooks) => {
4020
- const keys = Object.keys(hooks);
4021
- return keys.reduce((acc, key) => {
4022
- if ((0, import_core8.isString)(hooks[key])) {
4023
- return {
4024
- ...acc,
4025
- [key]: [hooks[key]]
4026
- };
4027
- } else if (Array.isArray(hooks[key])) {
4028
- return {
4029
- ...acc,
4030
- [key]: hooks[key]
4031
- };
4032
- } else if ((0, import_core8.isFunction)(hooks[key])) {
4033
- return {
4034
- ...acc,
4035
- [key]: [hooks[key]]
4036
- };
4037
- } else if ((0, import_core8.isObject)(hooks[key])) {
4038
- return {
4039
- ...acc,
4040
- [key]: [hooks[key]]
4041
- };
4042
- }
4043
- return acc;
4044
- }, {});
4045
- };
4046
- var normalizeHonoOptions = (hono2 = {}, workspace) => {
4047
- var _a, _b;
4048
- return {
4049
- ...hono2.handlers ? { handlers: import_core8.upath.resolve(workspace, hono2.handlers) } : {},
4050
- compositeRoute: (_a = hono2.compositeRoute) != null ? _a : "",
4051
- validator: (_b = hono2.validator) != null ? _b : true,
4052
- validatorOutputPath: hono2.validatorOutputPath ? import_core8.upath.resolve(workspace, hono2.validatorOutputPath) : ""
4053
- };
4054
- };
4055
- var normalizeJSDocOptions = (jsdoc = {}) => {
4056
- return {
4057
- ...jsdoc
4058
- };
4059
- };
4060
- var normalizeQueryOptions = (queryOptions = {}, outputWorkspace, globalOptions = {}) => {
4061
- if (queryOptions.options) {
4062
- console.warn(
4063
- "[WARN] Using query options is deprecated and will be removed in a future major release. Please use queryOptions or mutationOptions instead."
4064
- );
4065
- }
4066
- return {
4067
- ...!(0, import_core8.isUndefined)(queryOptions.usePrefetch) ? { usePrefetch: queryOptions.usePrefetch } : {},
4068
- ...!(0, import_core8.isUndefined)(queryOptions.useQuery) ? { useQuery: queryOptions.useQuery } : {},
4069
- ...!(0, import_core8.isUndefined)(queryOptions.useSuspenseQuery) ? { useSuspenseQuery: queryOptions.useSuspenseQuery } : {},
4070
- ...!(0, import_core8.isUndefined)(queryOptions.useMutation) ? { useMutation: queryOptions.useMutation } : {},
4071
- ...!(0, import_core8.isUndefined)(queryOptions.useInfinite) ? { useInfinite: queryOptions.useInfinite } : {},
4072
- ...!(0, import_core8.isUndefined)(queryOptions.useSuspenseInfiniteQuery) ? { useSuspenseInfiniteQuery: queryOptions.useSuspenseInfiniteQuery } : {},
4073
- ...queryOptions.useInfiniteQueryParam ? { useInfiniteQueryParam: queryOptions.useInfiniteQueryParam } : {},
4074
- ...queryOptions.options ? { options: queryOptions.options } : {},
4075
- ...globalOptions.queryKey ? {
4076
- queryKey: globalOptions.queryKey
4077
- } : {},
4078
- ...(queryOptions == null ? void 0 : queryOptions.queryKey) ? {
4079
- queryKey: normalizeMutator(outputWorkspace, queryOptions == null ? void 0 : queryOptions.queryKey)
4080
- } : {},
4081
- ...globalOptions.queryOptions ? {
4082
- queryOptions: globalOptions.queryOptions
4083
- } : {},
4084
- ...(queryOptions == null ? void 0 : queryOptions.queryOptions) ? {
4085
- queryOptions: normalizeMutator(
4086
- outputWorkspace,
4087
- queryOptions == null ? void 0 : queryOptions.queryOptions
4088
- )
4089
- } : {},
4090
- ...globalOptions.mutationOptions ? {
4091
- mutationOptions: globalOptions.mutationOptions
4092
- } : {},
4093
- ...(queryOptions == null ? void 0 : queryOptions.mutationOptions) ? {
4094
- mutationOptions: normalizeMutator(
4095
- outputWorkspace,
4096
- queryOptions == null ? void 0 : queryOptions.mutationOptions
4097
- )
4098
- } : {},
4099
- ...!(0, import_core8.isUndefined)(globalOptions.shouldExportQueryKey) ? {
4100
- shouldExportQueryKey: globalOptions.shouldExportQueryKey
4101
- } : {},
4102
- ...!(0, import_core8.isUndefined)(queryOptions.shouldExportQueryKey) ? { shouldExportQueryKey: queryOptions.shouldExportQueryKey } : {},
4103
- ...!(0, import_core8.isUndefined)(globalOptions.shouldExportHttpClient) ? {
4104
- shouldExportHttpClient: globalOptions.shouldExportHttpClient
4105
- } : {},
4106
- ...!(0, import_core8.isUndefined)(queryOptions.shouldExportHttpClient) ? { shouldExportHttpClient: queryOptions.shouldExportHttpClient } : {},
4107
- ...!(0, import_core8.isUndefined)(globalOptions.shouldExportMutatorHooks) ? {
4108
- shouldExportMutatorHooks: globalOptions.shouldExportMutatorHooks
4109
- } : {},
4110
- ...!(0, import_core8.isUndefined)(queryOptions.shouldExportMutatorHooks) ? { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks } : {},
4111
- ...!(0, import_core8.isUndefined)(globalOptions.shouldSplitQueryKey) ? {
4112
- shouldSplitQueryKey: globalOptions.shouldSplitQueryKey
4113
- } : {},
4114
- ...!(0, import_core8.isUndefined)(queryOptions.shouldSplitQueryKey) ? { shouldSplitQueryKey: queryOptions.shouldSplitQueryKey } : {},
4115
- ...!(0, import_core8.isUndefined)(globalOptions.signal) ? {
4116
- signal: globalOptions.signal
4117
- } : {},
4118
- ...!(0, import_core8.isUndefined)(queryOptions.signal) ? { signal: queryOptions.signal } : {},
4119
- ...!(0, import_core8.isUndefined)(globalOptions.version) ? {
4120
- version: globalOptions.version
4121
- } : {},
4122
- ...!(0, import_core8.isUndefined)(queryOptions.version) ? { version: queryOptions.version } : {}
4123
- };
4124
- };
4125
- var getDefaultFilesHeader = ({
4126
- title,
4127
- description,
4128
- version
4129
- } = {}) => [
4130
- `Generated by ${package_default.name} v${package_default.version} \u{1F37A}`,
4131
- `Do not edit manually.`,
4132
- ...title ? [title] : [],
4133
- ...description ? [description] : [],
4134
- ...version ? [`OpenAPI spec version: ${version}`] : []
4135
- ];
4136
-
4137
- // src/utils/watcher.ts
4138
- var import_core9 = require("@orval/core");
4139
- var startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
4140
- if (!watchOptions) return;
4141
- const { watch } = await Promise.resolve().then(() => __toESM(require("chokidar")));
4142
- const ignored = ["**/{.git,node_modules}/**"];
4143
- const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter(
4144
- (path) => typeof path === "string"
4145
- ) : watchOptions;
4146
- (0, import_core9.log)(
4147
- `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`
4148
- );
4149
- const watcher = watch(watchPaths, {
4150
- ignorePermissionErrors: true,
4151
- ignored
4152
- });
4153
- watcher.on("all", async (type2, file) => {
4154
- (0, import_core9.log)(`Change detected: ${type2} ${file}`);
4155
- try {
4156
- await watchFn();
4157
- } catch (e) {
4158
- (0, import_core9.logError)(e);
4159
- }
4160
- });
4161
- };
4162
-
4163
- // src/write-specs.ts
4164
- var import_core11 = require("@orval/core");
4165
- var import_chalk5 = __toESM(require("chalk"));
4166
- var import_execa2 = __toESM(require("execa"));
4167
- var import_fs_extra5 = __toESM(require("fs-extra"));
4168
- var import_lodash = __toESM(require("lodash.uniq"));
4169
-
4170
- // src/utils/executeHook.ts
4171
- var import_core10 = require("@orval/core");
4172
- var import_chalk4 = __toESM(require("chalk"));
4173
- var import_execa = __toESM(require("execa"));
4174
- var import_string_argv = require("string-argv");
4175
- var executeHook = async (name, commands = [], args = []) => {
4176
- (0, import_core10.log)(import_chalk4.default.white(`Running ${name} hook...`));
4177
- for (const command of commands) {
4178
- try {
4179
- if ((0, import_core10.isString)(command)) {
4180
- await executeCommand(command, args);
4181
- } else if ((0, import_core10.isFunction)(command)) {
4182
- await command(args);
4183
- } else if ((0, import_core10.isObject)(command)) {
4184
- await executeObjectCommand(command, args);
4185
- }
4186
- } catch (e) {
4187
- (0, import_core10.logError)(e, `Failed to run ${name} hook`);
4188
- }
4189
- }
4190
- };
4191
- async function executeCommand(command, args) {
4192
- const [cmd, ..._args] = [...(0, import_string_argv.parseArgsStringToArgv)(command), ...args];
4193
- await (0, import_execa.default)(cmd, _args);
4194
- }
4195
- async function executeObjectCommand(command, args) {
4196
- if (command.injectGeneratedDirsAndFiles === false) {
4197
- args = [];
4198
- }
4199
- if ((0, import_core10.isString)(command.command)) {
4200
- await executeCommand(command.command, args);
4201
- } else if ((0, import_core10.isFunction)(command.command)) {
4202
- await command.command();
4203
- }
4204
- }
4205
-
4206
- // src/write-specs.ts
4207
- var getHeader = (option, info) => {
4208
- if (!option) {
4209
- return "";
4210
- }
4211
- const header = option(info);
4212
- return Array.isArray(header) ? (0, import_core11.jsDoc)({ description: header }) : header;
4213
- };
4214
- var writeSpecs = async (builder, workspace, options, projectName) => {
4215
- var _a, _b;
4216
- const { info = { title: "", version: 0 }, schemas, target } = builder;
4217
- const { output } = options;
4218
- const projectTitle = projectName || info.title;
4219
- const specsName = Object.keys(schemas).reduce(
4220
- (acc, specKey) => {
4221
- const basePath = import_core11.upath.getSpecName(specKey, target);
4222
- const name = basePath.slice(1).split("/").join("-");
4223
- acc[specKey] = name;
4224
- return acc;
4225
- },
4226
- {}
4227
- );
4228
- const header = getHeader(output.override.header, info);
4229
- if (output.schemas) {
4230
- const rootSchemaPath = output.schemas;
4231
- const fileExtension = ["tags", "tags-split", "split"].includes(output.mode) ? ".ts" : (_a = output.fileExtension) != null ? _a : ".ts";
4232
- await Promise.all(
4233
- Object.entries(schemas).map(([specKey, schemas2]) => {
4234
- const schemaPath = !(0, import_core11.isRootKey)(specKey, target) ? import_core11.upath.join(rootSchemaPath, specsName[specKey]) : rootSchemaPath;
4235
- return (0, import_core11.writeSchemas)({
4236
- schemaPath,
4237
- schemas: schemas2,
4238
- target,
4239
- namingConvention: output.namingConvention,
4240
- fileExtension,
4241
- specsName,
4242
- specKey,
4243
- isRootKey: (0, import_core11.isRootKey)(specKey, target),
4244
- header,
4245
- indexFiles: output.indexFiles
4246
- });
4247
- })
4248
- );
4249
- }
4250
- let implementationPaths = [];
4251
- if (output.target) {
4252
- const writeMode = getWriteMode(output.mode);
4253
- implementationPaths = await writeMode({
4254
- builder,
4255
- workspace,
4256
- output,
4257
- specsName,
4258
- header,
4259
- needSchema: !output.schemas && output.client !== "zod"
4260
- });
4261
- }
4262
- if (output.workspace) {
4263
- const workspacePath = output.workspace;
4264
- const imports = implementationPaths.filter(
4265
- (path) => !output.mock || !path.endsWith(`.${(0, import_core11.getMockFileExtensionByTypeName)(output.mock)}.ts`)
4266
- ).map(
4267
- (path) => import_core11.upath.relativeSafe(
4268
- workspacePath,
4269
- (0, import_core11.getFileInfo)(path).pathWithoutExtension
4270
- )
4271
- );
4272
- if (output.schemas) {
4273
- imports.push(
4274
- import_core11.upath.relativeSafe(workspacePath, (0, import_core11.getFileInfo)(output.schemas).dirname)
4275
- );
4276
- }
4277
- if (output.indexFiles) {
4278
- const indexFile = import_core11.upath.join(workspacePath, "/index.ts");
4279
- if (await import_fs_extra5.default.pathExists(indexFile)) {
4280
- const data = await import_fs_extra5.default.readFile(indexFile, "utf8");
4281
- const importsNotDeclared = imports.filter((imp) => !data.includes(imp));
4282
- await import_fs_extra5.default.appendFile(
4283
- indexFile,
4284
- (0, import_lodash.default)(importsNotDeclared).map((imp) => `export * from '${imp}';
4285
- `).join("")
4286
- );
4287
- } else {
4288
- await import_fs_extra5.default.outputFile(
4289
- indexFile,
4290
- (0, import_lodash.default)(imports).map((imp) => `export * from '${imp}';`).join("\n") + "\n"
4291
- );
4292
- }
4293
- implementationPaths = [indexFile, ...implementationPaths];
4294
- }
4295
- }
4296
- if (builder.extraFiles.length) {
4297
- await Promise.all(
4298
- builder.extraFiles.map(
4299
- async (file) => import_fs_extra5.default.outputFile(file.path, file.content)
4300
- )
4301
- );
4302
- implementationPaths = [
4303
- ...implementationPaths,
4304
- ...builder.extraFiles.map((file) => file.path)
4305
- ];
4306
- }
4307
- const paths = [
4308
- ...output.schemas ? [(0, import_core11.getFileInfo)(output.schemas).dirname] : [],
4309
- ...implementationPaths
4310
- ];
4311
- if (options.hooks.afterAllFilesWrite) {
4312
- await executeHook(
4313
- "afterAllFilesWrite",
4314
- options.hooks.afterAllFilesWrite,
4315
- paths
4316
- );
4317
- }
4318
- if (output.prettier) {
4319
- try {
4320
- await (0, import_execa2.default)("prettier", ["--write", ...paths]);
4321
- } catch {
4322
- (0, import_core11.log)(
4323
- import_chalk5.default.yellow(
4324
- `\u26A0\uFE0F ${projectTitle ? `${projectTitle} - ` : ""}Prettier not found`
4325
- )
4326
- );
4327
- }
4328
- }
4329
- if (output.biome) {
4330
- try {
4331
- await (0, import_execa2.default)("biome", ["check", "--write", ...paths]);
4332
- } catch (e) {
4333
- const message = e.exitCode === 1 ? e.stdout + e.stderr : `\u26A0\uFE0F ${projectTitle ? `${projectTitle} - ` : ""}biome not found`;
4334
- (0, import_core11.log)(import_chalk5.default.yellow(message));
4335
- }
4336
- }
4337
- if (output.docs) {
4338
- try {
4339
- let config = {};
4340
- let configPath = null;
4341
- if (typeof output.docs === "object") {
4342
- ({ configPath = null, ...config } = output.docs);
4343
- if (configPath) {
4344
- config.options = configPath;
4345
- }
4346
- }
4347
- const getTypedocApplication = async () => {
4348
- const { Application: Application2 } = await Promise.resolve().then(() => __toESM(require("typedoc")));
4349
- return Application2;
4350
- };
4351
- const Application = await getTypedocApplication();
4352
- const app = await Application.bootstrapWithPlugins({
4353
- entryPoints: paths,
4354
- theme: "markdown",
4355
- // Set the custom config location if it has been provided.
4356
- ...config,
4357
- plugin: ["typedoc-plugin-markdown", ...(_b = config.plugin) != null ? _b : []]
4358
- });
4359
- if (!app.options.isSet("readme")) {
4360
- app.options.setValue("readme", "none");
4361
- }
4362
- if (!app.options.isSet("logLevel")) {
4363
- app.options.setValue("logLevel", "None");
4364
- }
4365
- const project = await app.convert();
4366
- if (project) {
4367
- await app.generateDocs(project, app.options.getValue("out"));
4368
- } else {
4369
- throw new Error("TypeDoc not initialised");
4370
- }
4371
- } catch (e) {
4372
- const message = e.exitCode === 1 ? e.stdout + e.stderr : `\u26A0\uFE0F ${projectTitle ? `${projectTitle} - ` : ""}Unable to generate docs`;
4373
- (0, import_core11.log)(import_chalk5.default.yellow(message));
4374
- }
4375
- }
4376
- (0, import_core11.createSuccessMessage)(projectTitle);
4377
- };
4378
- var getWriteMode = (mode) => {
4379
- switch (mode) {
4380
- case import_core11.OutputMode.SPLIT:
4381
- return import_core11.writeSplitMode;
4382
- case import_core11.OutputMode.TAGS:
4383
- return import_core11.writeTagsMode;
4384
- case import_core11.OutputMode.TAGS_SPLIT:
4385
- return import_core11.writeSplitTagsMode;
4386
- case import_core11.OutputMode.SINGLE:
4387
- default:
4388
- return import_core11.writeSingleMode;
4389
- }
4390
- };
4391
-
4392
- // src/generate.ts
4393
- var generateSpec = async (workspace, options, projectName) => {
4394
- if (options.output.clean) {
4395
- const extraPatterns = Array.isArray(options.output.clean) ? options.output.clean : [];
4396
- if (options.output.target) {
4397
- await (0, import_core12.removeFiles)(
4398
- ["**/*", "!**/*.d.ts", ...extraPatterns],
4399
- (0, import_core12.getFileInfo)(options.output.target).dirname
4400
- );
4401
- }
4402
- if (options.output.schemas) {
4403
- await (0, import_core12.removeFiles)(
4404
- ["**/*", "!**/*.d.ts", ...extraPatterns],
4405
- (0, import_core12.getFileInfo)(options.output.schemas).dirname
4406
- );
4407
- }
4408
- (0, import_core12.log)(`${projectName ? `${projectName}: ` : ""}Cleaning output folder`);
4409
- }
4410
- const writeSpecBuilder = await importSpecs(workspace, options);
4411
- await writeSpecs(writeSpecBuilder, workspace, options, projectName);
4412
- };
4413
- var generateSpecs = async (config, workspace, projectName) => {
4414
- if (projectName) {
4415
- const options = config[projectName];
4416
- if (options) {
4417
- try {
4418
- await generateSpec(workspace, options, projectName);
4419
- } catch (e) {
4420
- (0, import_core12.logError)(e, projectName);
4421
- process.exit(1);
4422
- }
4423
- } else {
4424
- (0, import_core12.logError)("Project not found");
4425
- process.exit(1);
4426
- }
4427
- return;
4428
- }
4429
- let hasErrors;
4430
- const accumulate = await (0, import_core12.asyncReduce)(
4431
- Object.entries(config),
4432
- async (acc, [projectName2, options]) => {
4433
- try {
4434
- acc.push(await generateSpec(workspace, options, projectName2));
4435
- } catch (e) {
4436
- hasErrors = true;
4437
- (0, import_core12.logError)(e, projectName2);
4438
- }
4439
- return acc;
4440
- },
4441
- []
4442
- );
4443
- if (hasErrors) process.exit(1);
4444
- return accumulate;
4445
- };
4446
- var generateConfig = async (configFile, options) => {
4447
- const {
4448
- path,
4449
- file: configExternal,
4450
- error
4451
- } = await (0, import_core12.loadFile)(configFile, {
4452
- defaultFileName: "orval.config"
4453
- });
4454
- if (!configExternal) {
4455
- throw `failed to load from ${path} => ${error}`;
4456
- }
4457
- const workspace = import_core12.upath.dirname(path);
4458
- const config = await ((0, import_core12.isFunction)(configExternal) ? configExternal() : configExternal);
4459
- const normalizedConfig = await (0, import_core12.asyncReduce)(
4460
- Object.entries(config),
4461
- async (acc, [key, value]) => {
4462
- acc[key] = await normalizeOptions(value, workspace, options);
4463
- return acc;
4464
- },
4465
- {}
4466
- );
4467
- const fileToWatch = Object.entries(normalizedConfig).filter(
4468
- ([project]) => (options == null ? void 0 : options.projectName) === void 0 || project === (options == null ? void 0 : options.projectName)
4469
- ).map(([, { input }]) => input.target).filter((target) => (0, import_core12.isString)(target));
4470
- if ((options == null ? void 0 : options.watch) && fileToWatch.length) {
4471
- startWatcher(
4472
- options == null ? void 0 : options.watch,
4473
- () => generateSpecs(normalizedConfig, workspace, options == null ? void 0 : options.projectName),
4474
- fileToWatch
4475
- );
4476
- } else {
4477
- await generateSpecs(normalizedConfig, workspace, options == null ? void 0 : options.projectName);
4478
- }
4479
- };
4480
-
4481
- // src/bin/orval.ts
4482
- var cli = (0, import_cac.cac)("orval");
4483
- (0, import_core13.startMessage)({
4484
- name: package_default.name,
4485
- version: package_default.version,
4486
- description: package_default.description
4487
- });
4488
- cli.version(package_default.version);
4489
- cli.command(
4490
- "[config]",
4491
- "generate client with appropriate type-signatures from OpenAPI specs",
4492
- {
4493
- ignoreOptionDefaultValue: true
4494
- }
4495
- ).option("-o, --output <path>", "output file destination").option("-i, --input <path>", "input file (yaml or json openapi specs)").option("-c, --config <path>", "override flags by a config file").option("-p, --project <name>", "focus a project of the config").option("-m, --mode <name>", "default mode that will be used").option("-c, --client <name>", "default client that will be used").option("--mock", "activate the mock").option(
4496
- "-w, --watch [path]",
4497
- "Watch mode, if path is not specified, it watches the input target"
4498
- ).option("--clean [path]", "Clean output directory").option("--prettier [path]", "Prettier generated files").option("--tslint [path]", "tslint generated files").option("--biome [path]", "biome generated files").option("--tsconfig [path]", "path to your tsconfig file").action(async (paths, cmd) => {
4499
- if (!cmd.config && (0, import_core13.isString)(cmd.input) && (0, import_core13.isString)(cmd.output)) {
4500
- const normalizedOptions = await normalizeOptions({
4501
- input: cmd.input,
4502
- output: {
4503
- target: cmd.output,
4504
- clean: cmd.clean,
4505
- prettier: cmd.prettier,
4506
- tslint: cmd.tslint,
4507
- biome: cmd.biome,
4508
- mock: cmd.mock,
4509
- client: cmd.client,
4510
- mode: cmd.mode,
4511
- tsconfig: cmd.tsconfig
4512
- }
4513
- });
4514
- if (cmd.watch) {
4515
- startWatcher(
4516
- cmd.watch,
4517
- async () => {
4518
- try {
4519
- await generateSpec(process.cwd(), normalizedOptions);
4520
- } catch (e) {
4521
- (0, import_core13.logError)(e);
4522
- }
4523
- },
4524
- normalizedOptions.input.target
4525
- );
4526
- } else {
4527
- try {
4528
- await generateSpec(process.cwd(), normalizedOptions);
4529
- } catch (e) {
4530
- (0, import_core13.logError)(e);
4531
- }
4532
- }
4533
- } else {
4534
- await generateConfig(cmd.config, {
4535
- projectName: cmd.project,
4536
- watch: cmd.watch,
4537
- clean: cmd.clean,
4538
- prettier: cmd.prettier,
4539
- tslint: cmd.tslint,
4540
- biome: cmd.biome,
4541
- mock: cmd.mock,
4542
- client: cmd.client,
4543
- mode: cmd.mode,
4544
- tsconfig: cmd.tsconfig,
4545
- input: cmd.input,
4546
- output: cmd.output
4547
- });
4548
- }
4549
- });
4550
- cli.help();
4551
- cli.parse(process.argv);
4552
- /*! Bundled license information:
4553
-
4554
- js-yaml/dist/js-yaml.mjs:
4555
- (*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
4556
- */
2
+ const require_generate = require('../generate-C5kRAcZ2.js');
3
+ let __orval_core = require("@orval/core");
4
+ __orval_core = require_generate.__toESM(__orval_core);
5
+ let __commander_js_extra_typings = require("@commander-js/extra-typings");
6
+ __commander_js_extra_typings = require_generate.__toESM(__commander_js_extra_typings);
7
+
8
+ //#region src/bin/orval.ts
9
+ const orvalMessage = (0, __orval_core.startMessage)({
10
+ name: require_generate.package_default.name,
11
+ version: require_generate.package_default.version,
12
+ description: require_generate.package_default.description
13
+ });
14
+ const cli = __commander_js_extra_typings.program.name("orval").description(orvalMessage).version(require_generate.package_default.version);
15
+ cli.option("-o, --output <path>", "output file destination").option("-i, --input <path>", "input file (yaml or json openapi specs)").option("-c, --config <path>", "override flags by a config file").option("-p, --project <name>", "focus a project of the config").addOption(new __commander_js_extra_typings.Option("-m, --mode <name>", "default mode that will be used").choices(Object.values(__orval_core.OutputMode))).option("-w, --watch [path]", "Watch mode, if path is not specified, it watches the input target").addOption(new __commander_js_extra_typings.Option("--client <name>", "default client that will be used").choices(Object.values(__orval_core.OutputClient))).option("--mock", "activate the mock").option("--clean [path...]", "Clean output directory").option("--prettier", "Prettier generated files").option("--biome", "biome generated files").option("--tsconfig <path>", "path to your tsconfig file").action(async (options) => {
16
+ (0, __orval_core.log)(orvalMessage);
17
+ if (!options.config && (0, __orval_core.isString)(options.input) && (0, __orval_core.isString)(options.output)) {
18
+ const normalizedOptions = await require_generate.normalizeOptions({
19
+ input: options.input,
20
+ output: {
21
+ target: options.output,
22
+ clean: options.clean,
23
+ prettier: options.prettier,
24
+ biome: options.biome,
25
+ mock: options.mock,
26
+ client: options.client,
27
+ mode: options.mode,
28
+ tsconfig: options.tsconfig
29
+ }
30
+ });
31
+ if (options.watch) await require_generate.startWatcher(options.watch, async () => {
32
+ try {
33
+ await require_generate.generateSpec(process.cwd(), normalizedOptions);
34
+ } catch (error) {
35
+ (0, __orval_core.logError)(error);
36
+ process.exit(1);
37
+ }
38
+ }, normalizedOptions.input.target);
39
+ else try {
40
+ await require_generate.generateSpec(process.cwd(), normalizedOptions);
41
+ } catch (error) {
42
+ if (error instanceof __orval_core.ErrorWithTag) (0, __orval_core.logError)(error.cause, error.tag);
43
+ else (0, __orval_core.logError)(error);
44
+ process.exit(1);
45
+ }
46
+ } else await require_generate.generateConfig(options.config, {
47
+ projectName: options.project,
48
+ watch: options.watch,
49
+ clean: options.clean,
50
+ prettier: options.prettier,
51
+ biome: options.biome,
52
+ mock: options.mock,
53
+ client: options.client,
54
+ mode: options.mode,
55
+ tsconfig: options.tsconfig,
56
+ input: options.input,
57
+ output: options.output
58
+ });
59
+ });
60
+ cli.parseAsync(process.argv);
61
+
62
+ //#endregion
4557
63
  //# sourceMappingURL=orval.js.map