@ng-openapi/http-resource 0.0.2-pr-9-feature-http-resource-e6134bb.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/index.cjs +3788 -0
  4. package/index.d.ts +221 -0
  5. package/index.js +3749 -0
  6. package/package.json +88 -0
package/index.cjs ADDED
@@ -0,0 +1,3788 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ HttpResourceGenerator: () => HttpResourceGenerator,
35
+ HttpResourceIndexGenerator: () => HttpResourceIndexGenerator,
36
+ HttpResourceMethodBodyGenerator: () => HttpResourceMethodBodyGenerator,
37
+ HttpResourceMethodGenerator: () => HttpResourceMethodGenerator,
38
+ HttpResourceMethodParamsGenerator: () => HttpResourceMethodParamsGenerator
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/lib/http-resource.generator.ts
43
+ var import_ts_morph = require("ts-morph");
44
+
45
+ // ../../shared/src/utils/string.utils.ts
46
+ function camelCase(str2) {
47
+ const cleaned = str2.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
48
+ return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
49
+ }
50
+ __name(camelCase, "camelCase");
51
+ function pascalCase(str2) {
52
+ return str2.replace(/(?:^|[-_])([a-z])/g, (_, char) => char.toUpperCase());
53
+ }
54
+ __name(pascalCase, "pascalCase");
55
+
56
+ // ../../shared/src/utils/type.utils.ts
57
+ function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, context = "type") {
58
+ let schema2;
59
+ let nullable;
60
+ if (typeof schemaOrType === "string" || schemaOrType === void 0) {
61
+ schema2 = {
62
+ type: schemaOrType,
63
+ format: typeof formatOrNullable === "string" ? formatOrNullable : void 0
64
+ };
65
+ nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : isNullable;
66
+ } else {
67
+ schema2 = schemaOrType;
68
+ nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : schema2.nullable;
69
+ }
70
+ if (!schema2) {
71
+ return "any";
72
+ }
73
+ if (schema2.$ref) {
74
+ const refName = schema2.$ref.split("/").pop();
75
+ return nullableType(pascalCase(refName), nullable);
76
+ }
77
+ if (schema2.type === "array") {
78
+ const itemType = schema2.items ? getTypeScriptType(schema2.items, config, void 0, void 0, context) : "unknown";
79
+ return nullable ? `(${itemType}[] | null)` : `${itemType}[]`;
80
+ }
81
+ switch (schema2.type) {
82
+ case "string":
83
+ if (schema2.enum) {
84
+ return schema2.enum.map((value) => typeof value === "string" ? `'${escapeString(value)}'` : String(value)).join(" | ");
85
+ }
86
+ if (schema2.format === "date" || schema2.format === "date-time") {
87
+ const dateType = config.options.dateType === "Date" ? "Date" : "string";
88
+ return nullableType(dateType, nullable);
89
+ }
90
+ if (schema2.format === "binary") {
91
+ const binaryType = context === "type" ? "Blob" : "File";
92
+ return nullableType(binaryType, nullable);
93
+ }
94
+ if (schema2.format === "uuid" || schema2.format === "email" || schema2.format === "uri" || schema2.format === "hostname" || schema2.format === "ipv4" || schema2.format === "ipv6") {
95
+ return nullableType("string", nullable);
96
+ }
97
+ return nullableType("string", nullable);
98
+ case "number":
99
+ case "integer":
100
+ return nullableType("number", nullable);
101
+ case "boolean":
102
+ return nullableType("boolean", nullable);
103
+ case "object":
104
+ return nullableType(context === "type" ? "Record<string, unknown>" : "any", nullable);
105
+ case "null":
106
+ return "null";
107
+ default:
108
+ console.warn(`Unknown swagger type: ${schema2.type}`);
109
+ return nullableType("any", nullable);
110
+ }
111
+ }
112
+ __name(getTypeScriptType, "getTypeScriptType");
113
+ function nullableType(type2, isNullable) {
114
+ return type2 + (isNullable ? " | null" : "");
115
+ }
116
+ __name(nullableType, "nullableType");
117
+ function escapeString(str2) {
118
+ return str2.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
119
+ }
120
+ __name(escapeString, "escapeString");
121
+
122
+ // ../../shared/src/utils/functions/collect-used-types.ts
123
+ function collectUsedTypes(operations) {
124
+ const usedTypes = /* @__PURE__ */ new Set();
125
+ operations.forEach((operation) => {
126
+ operation.parameters?.forEach((param) => {
127
+ collectTypesFromSchema(param.schema || param, usedTypes);
128
+ });
129
+ if (operation.requestBody) {
130
+ collectTypesFromRequestBody(operation.requestBody, usedTypes);
131
+ }
132
+ if (operation.responses) {
133
+ Object.values(operation.responses).forEach((response) => {
134
+ collectTypesFromResponse(response, usedTypes);
135
+ });
136
+ }
137
+ });
138
+ return usedTypes;
139
+ }
140
+ __name(collectUsedTypes, "collectUsedTypes");
141
+ function collectTypesFromSchema(schema2, usedTypes) {
142
+ if (!schema2) return;
143
+ if (schema2.$ref) {
144
+ const refName = schema2.$ref.split("/").pop();
145
+ if (refName) {
146
+ usedTypes.add(pascalCase(refName));
147
+ }
148
+ }
149
+ if (schema2.type === "array" && schema2.items) {
150
+ collectTypesFromSchema(schema2.items, usedTypes);
151
+ }
152
+ if (schema2.type === "object" && schema2.properties) {
153
+ Object.values(schema2.properties).forEach((prop) => {
154
+ collectTypesFromSchema(prop, usedTypes);
155
+ });
156
+ }
157
+ if (schema2.allOf) {
158
+ schema2.allOf.forEach((subSchema) => {
159
+ collectTypesFromSchema(subSchema, usedTypes);
160
+ });
161
+ }
162
+ if (schema2.oneOf) {
163
+ schema2.oneOf.forEach((subSchema) => {
164
+ collectTypesFromSchema(subSchema, usedTypes);
165
+ });
166
+ }
167
+ if (schema2.anyOf) {
168
+ schema2.anyOf.forEach((subSchema) => {
169
+ collectTypesFromSchema(subSchema, usedTypes);
170
+ });
171
+ }
172
+ }
173
+ __name(collectTypesFromSchema, "collectTypesFromSchema");
174
+ function collectTypesFromRequestBody(requestBody, usedTypes) {
175
+ const content = requestBody.content || {};
176
+ Object.values(content).forEach((mediaType) => {
177
+ if (mediaType.schema) {
178
+ collectTypesFromSchema(mediaType.schema, usedTypes);
179
+ }
180
+ });
181
+ }
182
+ __name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
183
+ function collectTypesFromResponse(response, usedTypes) {
184
+ const content = response.content || {};
185
+ Object.values(content).forEach((mediaType) => {
186
+ if (mediaType.schema) {
187
+ collectTypesFromSchema(mediaType.schema, usedTypes);
188
+ }
189
+ });
190
+ }
191
+ __name(collectTypesFromResponse, "collectTypesFromResponse");
192
+
193
+ // ../../shared/src/utils/functions/token-names.ts
194
+ function getClientContextTokenName(clientName = "default") {
195
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
196
+ return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
197
+ }
198
+ __name(getClientContextTokenName, "getClientContextTokenName");
199
+ function getBasePathTokenName(clientName = "default") {
200
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
201
+ return `BASE_PATH_${clientSuffix}`;
202
+ }
203
+ __name(getBasePathTokenName, "getBasePathTokenName");
204
+
205
+ // ../../shared/src/utils/functions/duplicate-function-name.ts
206
+ function hasDuplicateFunctionNames(arr) {
207
+ return new Set(arr.map((fn) => fn.getName())).size !== arr.length;
208
+ }
209
+ __name(hasDuplicateFunctionNames, "hasDuplicateFunctionNames");
210
+
211
+ // ../../shared/src/utils/functions/extract-paths.ts
212
+ function extractPaths(swaggerPaths = {}, methods = [
213
+ "get",
214
+ "post",
215
+ "put",
216
+ "patch",
217
+ "delete",
218
+ "options",
219
+ "head"
220
+ ]) {
221
+ const paths = [];
222
+ Object.entries(swaggerPaths).forEach(([path4, pathItem]) => {
223
+ methods.forEach((method) => {
224
+ if (pathItem[method]) {
225
+ const operation = pathItem[method];
226
+ paths.push({
227
+ path: path4,
228
+ method: method.toUpperCase(),
229
+ operationId: operation.operationId,
230
+ summary: operation.summary,
231
+ description: operation.description,
232
+ tags: operation.tags || [],
233
+ parameters: parseParameters(operation.parameters || [], pathItem.parameters || []),
234
+ requestBody: operation.requestBody,
235
+ responses: operation.responses || {}
236
+ });
237
+ }
238
+ });
239
+ });
240
+ return paths;
241
+ }
242
+ __name(extractPaths, "extractPaths");
243
+ function parseParameters(operationParams, pathParams) {
244
+ const allParams = [
245
+ ...pathParams,
246
+ ...operationParams
247
+ ];
248
+ return allParams.map((param) => ({
249
+ name: param.name,
250
+ in: param.in,
251
+ required: param.required || param.in === "path",
252
+ schema: param.schema,
253
+ type: param.type,
254
+ format: param.format,
255
+ description: param.description
256
+ }));
257
+ }
258
+ __name(parseParameters, "parseParameters");
259
+
260
+ // ../../shared/src/utils/functions/extract-swagger-response-type.ts
261
+ function getResponseTypeFromResponse(response, responseTypeMapping) {
262
+ const content = response.content || {};
263
+ if (Object.keys(content).length === 0) {
264
+ return "json";
265
+ }
266
+ const responseTypes = [];
267
+ for (const [contentType, mediaType] of Object.entries(content)) {
268
+ const schema2 = mediaType?.schema;
269
+ const mapping = responseTypeMapping || {};
270
+ if (mapping[contentType]) {
271
+ responseTypes.push({
272
+ type: mapping[contentType],
273
+ priority: 1,
274
+ contentType
275
+ });
276
+ continue;
277
+ }
278
+ if (schema2?.format === "binary" || schema2?.format === "byte") {
279
+ responseTypes.push({
280
+ type: "blob",
281
+ priority: 2,
282
+ contentType
283
+ });
284
+ continue;
285
+ }
286
+ if (schema2?.type === "string" && (schema2?.format === "binary" || schema2?.format === "byte")) {
287
+ responseTypes.push({
288
+ type: "blob",
289
+ priority: 2,
290
+ contentType
291
+ });
292
+ continue;
293
+ }
294
+ const isPrimitive = isPrimitiveType(schema2);
295
+ const inferredType = inferResponseTypeFromContentType(contentType);
296
+ let priority = 3;
297
+ let finalType = inferredType;
298
+ if (inferredType === "json" && isPrimitive) {
299
+ finalType = "text";
300
+ priority = 2;
301
+ } else if (inferredType === "json") {
302
+ priority = 2;
303
+ }
304
+ responseTypes.push({
305
+ type: finalType,
306
+ priority,
307
+ contentType,
308
+ isPrimitive
309
+ });
310
+ }
311
+ responseTypes.sort((a, b) => a.priority - b.priority);
312
+ return responseTypes[0]?.type || "json";
313
+ }
314
+ __name(getResponseTypeFromResponse, "getResponseTypeFromResponse");
315
+ function isPrimitiveType(schema2) {
316
+ if (!schema2) return false;
317
+ const primitiveTypes = [
318
+ "string",
319
+ "number",
320
+ "integer",
321
+ "boolean"
322
+ ];
323
+ if (primitiveTypes.includes(schema2.type)) {
324
+ return true;
325
+ }
326
+ if (schema2.type === "array") {
327
+ return false;
328
+ }
329
+ if (schema2.type === "object" || schema2.properties) {
330
+ return false;
331
+ }
332
+ if (schema2.$ref) {
333
+ return false;
334
+ }
335
+ if (schema2.allOf || schema2.oneOf || schema2.anyOf) {
336
+ return false;
337
+ }
338
+ return false;
339
+ }
340
+ __name(isPrimitiveType, "isPrimitiveType");
341
+ function inferResponseTypeFromContentType(contentType) {
342
+ const normalizedType = contentType.split(";")[0].trim().toLowerCase();
343
+ if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
344
+ return "json";
345
+ }
346
+ if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
347
+ return "text";
348
+ }
349
+ if (normalizedType.startsWith("text/")) {
350
+ const binaryTextTypes = [
351
+ "text/rtf",
352
+ "text/cache-manifest",
353
+ "text/vcard",
354
+ "text/calendar"
355
+ ];
356
+ if (binaryTextTypes.includes(normalizedType)) {
357
+ return "blob";
358
+ }
359
+ return "text";
360
+ }
361
+ if (normalizedType === "application/x-www-form-urlencoded" || normalizedType === "multipart/form-data") {
362
+ return "text";
363
+ }
364
+ if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
365
+ return "text";
366
+ }
367
+ if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
368
+ return "arraybuffer";
369
+ }
370
+ return "blob";
371
+ }
372
+ __name(inferResponseTypeFromContentType, "inferResponseTypeFromContentType");
373
+ function getResponseType(response, config) {
374
+ const responseType = getResponseTypeFromResponse(response);
375
+ switch (responseType) {
376
+ case "blob":
377
+ return "Blob";
378
+ case "arraybuffer":
379
+ return "ArrayBuffer";
380
+ case "text":
381
+ return "string";
382
+ case "json": {
383
+ const content = response.content || {};
384
+ for (const [contentType, mediaType] of Object.entries(content)) {
385
+ if (inferResponseTypeFromContentType(contentType) === "json" && mediaType?.schema) {
386
+ return getTypeScriptType(mediaType.schema, config, mediaType.schema.nullable);
387
+ }
388
+ }
389
+ return "any";
390
+ }
391
+ default:
392
+ return "any";
393
+ }
394
+ }
395
+ __name(getResponseType, "getResponseType");
396
+
397
+ // ../../shared/src/config/constants.ts
398
+ var disableLinting = `/* @ts-nocheck */
399
+ /* eslint-disable */
400
+ /* @noformat */
401
+ /* @formatter:off */
402
+ `;
403
+ var authorComment = `/**
404
+ * Generated by ng-openapi
405
+ `;
406
+ var defaultHeaderComment = disableLinting + authorComment;
407
+ var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
408
+ * Do not edit this file manually
409
+ */
410
+ `;
411
+ var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
412
+ * Do not edit this file manually
413
+ */
414
+ `;
415
+ var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
416
+ * Do not edit this file manually
417
+ */
418
+ `;
419
+ var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
420
+ * Do not edit this file manually
421
+ */
422
+ `;
423
+ var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceName) => defaultHeaderComment + `* \`httpResource\` is still an experimental feature - NOT PRODUCTION READY
424
+ * Generated Angular service for ${resourceName}
425
+ * Do not edit this file manually
426
+ */
427
+ `, "HTTP_RESOURCE_GENERATOR_HEADER_COMMENT");
428
+
429
+ // ../../shared/src/core/swagger-parser.ts
430
+ var fs = __toESM(require("fs"));
431
+ var path = __toESM(require("path"));
432
+
433
+ // ../../../node_modules/js-yaml/dist/js-yaml.mjs
434
+ function isNothing(subject) {
435
+ return typeof subject === "undefined" || subject === null;
436
+ }
437
+ __name(isNothing, "isNothing");
438
+ function isObject(subject) {
439
+ return typeof subject === "object" && subject !== null;
440
+ }
441
+ __name(isObject, "isObject");
442
+ function toArray(sequence) {
443
+ if (Array.isArray(sequence)) return sequence;
444
+ else if (isNothing(sequence)) return [];
445
+ return [sequence];
446
+ }
447
+ __name(toArray, "toArray");
448
+ function extend(target, source) {
449
+ var index, length, key, sourceKeys;
450
+ if (source) {
451
+ sourceKeys = Object.keys(source);
452
+ for (index = 0, length = sourceKeys.length; index < length; index += 1) {
453
+ key = sourceKeys[index];
454
+ target[key] = source[key];
455
+ }
456
+ }
457
+ return target;
458
+ }
459
+ __name(extend, "extend");
460
+ function repeat(string, count) {
461
+ var result = "", cycle;
462
+ for (cycle = 0; cycle < count; cycle += 1) {
463
+ result += string;
464
+ }
465
+ return result;
466
+ }
467
+ __name(repeat, "repeat");
468
+ function isNegativeZero(number) {
469
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
470
+ }
471
+ __name(isNegativeZero, "isNegativeZero");
472
+ var isNothing_1 = isNothing;
473
+ var isObject_1 = isObject;
474
+ var toArray_1 = toArray;
475
+ var repeat_1 = repeat;
476
+ var isNegativeZero_1 = isNegativeZero;
477
+ var extend_1 = extend;
478
+ var common = {
479
+ isNothing: isNothing_1,
480
+ isObject: isObject_1,
481
+ toArray: toArray_1,
482
+ repeat: repeat_1,
483
+ isNegativeZero: isNegativeZero_1,
484
+ extend: extend_1
485
+ };
486
+ function formatError(exception2, compact) {
487
+ var where = "", message = exception2.reason || "(unknown reason)";
488
+ if (!exception2.mark) return message;
489
+ if (exception2.mark.name) {
490
+ where += 'in "' + exception2.mark.name + '" ';
491
+ }
492
+ where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
493
+ if (!compact && exception2.mark.snippet) {
494
+ where += "\n\n" + exception2.mark.snippet;
495
+ }
496
+ return message + " " + where;
497
+ }
498
+ __name(formatError, "formatError");
499
+ function YAMLException$1(reason, mark) {
500
+ Error.call(this);
501
+ this.name = "YAMLException";
502
+ this.reason = reason;
503
+ this.mark = mark;
504
+ this.message = formatError(this, false);
505
+ if (Error.captureStackTrace) {
506
+ Error.captureStackTrace(this, this.constructor);
507
+ } else {
508
+ this.stack = new Error().stack || "";
509
+ }
510
+ }
511
+ __name(YAMLException$1, "YAMLException$1");
512
+ YAMLException$1.prototype = Object.create(Error.prototype);
513
+ YAMLException$1.prototype.constructor = YAMLException$1;
514
+ YAMLException$1.prototype.toString = /* @__PURE__ */ __name(function toString(compact) {
515
+ return this.name + ": " + formatError(this, compact);
516
+ }, "toString");
517
+ var exception = YAMLException$1;
518
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
519
+ var head = "";
520
+ var tail = "";
521
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
522
+ if (position - lineStart > maxHalfLength) {
523
+ head = " ... ";
524
+ lineStart = position - maxHalfLength + head.length;
525
+ }
526
+ if (lineEnd - position > maxHalfLength) {
527
+ tail = " ...";
528
+ lineEnd = position + maxHalfLength - tail.length;
529
+ }
530
+ return {
531
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
532
+ pos: position - lineStart + head.length
533
+ // relative position
534
+ };
535
+ }
536
+ __name(getLine, "getLine");
537
+ function padStart(string, max) {
538
+ return common.repeat(" ", max - string.length) + string;
539
+ }
540
+ __name(padStart, "padStart");
541
+ function makeSnippet(mark, options) {
542
+ options = Object.create(options || null);
543
+ if (!mark.buffer) return null;
544
+ if (!options.maxLength) options.maxLength = 79;
545
+ if (typeof options.indent !== "number") options.indent = 1;
546
+ if (typeof options.linesBefore !== "number") options.linesBefore = 3;
547
+ if (typeof options.linesAfter !== "number") options.linesAfter = 2;
548
+ var re = /\r?\n|\r|\0/g;
549
+ var lineStarts = [0];
550
+ var lineEnds = [];
551
+ var match;
552
+ var foundLineNo = -1;
553
+ while (match = re.exec(mark.buffer)) {
554
+ lineEnds.push(match.index);
555
+ lineStarts.push(match.index + match[0].length);
556
+ if (mark.position <= match.index && foundLineNo < 0) {
557
+ foundLineNo = lineStarts.length - 2;
558
+ }
559
+ }
560
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
561
+ var result = "", i, line;
562
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
563
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
564
+ for (i = 1; i <= options.linesBefore; i++) {
565
+ if (foundLineNo - i < 0) break;
566
+ line = getLine(
567
+ mark.buffer,
568
+ lineStarts[foundLineNo - i],
569
+ lineEnds[foundLineNo - i],
570
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
571
+ maxLineLength
572
+ );
573
+ result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
574
+ }
575
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
576
+ result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
577
+ result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
578
+ for (i = 1; i <= options.linesAfter; i++) {
579
+ if (foundLineNo + i >= lineEnds.length) break;
580
+ line = getLine(
581
+ mark.buffer,
582
+ lineStarts[foundLineNo + i],
583
+ lineEnds[foundLineNo + i],
584
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
585
+ maxLineLength
586
+ );
587
+ result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
588
+ }
589
+ return result.replace(/\n$/, "");
590
+ }
591
+ __name(makeSnippet, "makeSnippet");
592
+ var snippet = makeSnippet;
593
+ var TYPE_CONSTRUCTOR_OPTIONS = [
594
+ "kind",
595
+ "multi",
596
+ "resolve",
597
+ "construct",
598
+ "instanceOf",
599
+ "predicate",
600
+ "represent",
601
+ "representName",
602
+ "defaultStyle",
603
+ "styleAliases"
604
+ ];
605
+ var YAML_NODE_KINDS = [
606
+ "scalar",
607
+ "sequence",
608
+ "mapping"
609
+ ];
610
+ function compileStyleAliases(map2) {
611
+ var result = {};
612
+ if (map2 !== null) {
613
+ Object.keys(map2).forEach(function(style) {
614
+ map2[style].forEach(function(alias) {
615
+ result[String(alias)] = style;
616
+ });
617
+ });
618
+ }
619
+ return result;
620
+ }
621
+ __name(compileStyleAliases, "compileStyleAliases");
622
+ function Type$1(tag, options) {
623
+ options = options || {};
624
+ Object.keys(options).forEach(function(name) {
625
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
626
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
627
+ }
628
+ });
629
+ this.options = options;
630
+ this.tag = tag;
631
+ this.kind = options["kind"] || null;
632
+ this.resolve = options["resolve"] || function() {
633
+ return true;
634
+ };
635
+ this.construct = options["construct"] || function(data) {
636
+ return data;
637
+ };
638
+ this.instanceOf = options["instanceOf"] || null;
639
+ this.predicate = options["predicate"] || null;
640
+ this.represent = options["represent"] || null;
641
+ this.representName = options["representName"] || null;
642
+ this.defaultStyle = options["defaultStyle"] || null;
643
+ this.multi = options["multi"] || false;
644
+ this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
645
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
646
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
647
+ }
648
+ }
649
+ __name(Type$1, "Type$1");
650
+ var type = Type$1;
651
+ function compileList(schema2, name) {
652
+ var result = [];
653
+ schema2[name].forEach(function(currentType) {
654
+ var newIndex = result.length;
655
+ result.forEach(function(previousType, previousIndex) {
656
+ if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
657
+ newIndex = previousIndex;
658
+ }
659
+ });
660
+ result[newIndex] = currentType;
661
+ });
662
+ return result;
663
+ }
664
+ __name(compileList, "compileList");
665
+ function compileMap() {
666
+ var result = {
667
+ scalar: {},
668
+ sequence: {},
669
+ mapping: {},
670
+ fallback: {},
671
+ multi: {
672
+ scalar: [],
673
+ sequence: [],
674
+ mapping: [],
675
+ fallback: []
676
+ }
677
+ }, index, length;
678
+ function collectType(type2) {
679
+ if (type2.multi) {
680
+ result.multi[type2.kind].push(type2);
681
+ result.multi["fallback"].push(type2);
682
+ } else {
683
+ result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
684
+ }
685
+ }
686
+ __name(collectType, "collectType");
687
+ for (index = 0, length = arguments.length; index < length; index += 1) {
688
+ arguments[index].forEach(collectType);
689
+ }
690
+ return result;
691
+ }
692
+ __name(compileMap, "compileMap");
693
+ function Schema$1(definition) {
694
+ return this.extend(definition);
695
+ }
696
+ __name(Schema$1, "Schema$1");
697
+ Schema$1.prototype.extend = /* @__PURE__ */ __name(function extend2(definition) {
698
+ var implicit = [];
699
+ var explicit = [];
700
+ if (definition instanceof type) {
701
+ explicit.push(definition);
702
+ } else if (Array.isArray(definition)) {
703
+ explicit = explicit.concat(definition);
704
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
705
+ if (definition.implicit) implicit = implicit.concat(definition.implicit);
706
+ if (definition.explicit) explicit = explicit.concat(definition.explicit);
707
+ } else {
708
+ throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
709
+ }
710
+ implicit.forEach(function(type$1) {
711
+ if (!(type$1 instanceof type)) {
712
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
713
+ }
714
+ if (type$1.loadKind && type$1.loadKind !== "scalar") {
715
+ throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
716
+ }
717
+ if (type$1.multi) {
718
+ throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
719
+ }
720
+ });
721
+ explicit.forEach(function(type$1) {
722
+ if (!(type$1 instanceof type)) {
723
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
724
+ }
725
+ });
726
+ var result = Object.create(Schema$1.prototype);
727
+ result.implicit = (this.implicit || []).concat(implicit);
728
+ result.explicit = (this.explicit || []).concat(explicit);
729
+ result.compiledImplicit = compileList(result, "implicit");
730
+ result.compiledExplicit = compileList(result, "explicit");
731
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
732
+ return result;
733
+ }, "extend");
734
+ var schema = Schema$1;
735
+ var str = new type("tag:yaml.org,2002:str", {
736
+ kind: "scalar",
737
+ construct: /* @__PURE__ */ __name(function(data) {
738
+ return data !== null ? data : "";
739
+ }, "construct")
740
+ });
741
+ var seq = new type("tag:yaml.org,2002:seq", {
742
+ kind: "sequence",
743
+ construct: /* @__PURE__ */ __name(function(data) {
744
+ return data !== null ? data : [];
745
+ }, "construct")
746
+ });
747
+ var map = new type("tag:yaml.org,2002:map", {
748
+ kind: "mapping",
749
+ construct: /* @__PURE__ */ __name(function(data) {
750
+ return data !== null ? data : {};
751
+ }, "construct")
752
+ });
753
+ var failsafe = new schema({
754
+ explicit: [
755
+ str,
756
+ seq,
757
+ map
758
+ ]
759
+ });
760
+ function resolveYamlNull(data) {
761
+ if (data === null) return true;
762
+ var max = data.length;
763
+ return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
764
+ }
765
+ __name(resolveYamlNull, "resolveYamlNull");
766
+ function constructYamlNull() {
767
+ return null;
768
+ }
769
+ __name(constructYamlNull, "constructYamlNull");
770
+ function isNull(object) {
771
+ return object === null;
772
+ }
773
+ __name(isNull, "isNull");
774
+ var _null = new type("tag:yaml.org,2002:null", {
775
+ kind: "scalar",
776
+ resolve: resolveYamlNull,
777
+ construct: constructYamlNull,
778
+ predicate: isNull,
779
+ represent: {
780
+ canonical: /* @__PURE__ */ __name(function() {
781
+ return "~";
782
+ }, "canonical"),
783
+ lowercase: /* @__PURE__ */ __name(function() {
784
+ return "null";
785
+ }, "lowercase"),
786
+ uppercase: /* @__PURE__ */ __name(function() {
787
+ return "NULL";
788
+ }, "uppercase"),
789
+ camelcase: /* @__PURE__ */ __name(function() {
790
+ return "Null";
791
+ }, "camelcase"),
792
+ empty: /* @__PURE__ */ __name(function() {
793
+ return "";
794
+ }, "empty")
795
+ },
796
+ defaultStyle: "lowercase"
797
+ });
798
+ function resolveYamlBoolean(data) {
799
+ if (data === null) return false;
800
+ var max = data.length;
801
+ return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
802
+ }
803
+ __name(resolveYamlBoolean, "resolveYamlBoolean");
804
+ function constructYamlBoolean(data) {
805
+ return data === "true" || data === "True" || data === "TRUE";
806
+ }
807
+ __name(constructYamlBoolean, "constructYamlBoolean");
808
+ function isBoolean(object) {
809
+ return Object.prototype.toString.call(object) === "[object Boolean]";
810
+ }
811
+ __name(isBoolean, "isBoolean");
812
+ var bool = new type("tag:yaml.org,2002:bool", {
813
+ kind: "scalar",
814
+ resolve: resolveYamlBoolean,
815
+ construct: constructYamlBoolean,
816
+ predicate: isBoolean,
817
+ represent: {
818
+ lowercase: /* @__PURE__ */ __name(function(object) {
819
+ return object ? "true" : "false";
820
+ }, "lowercase"),
821
+ uppercase: /* @__PURE__ */ __name(function(object) {
822
+ return object ? "TRUE" : "FALSE";
823
+ }, "uppercase"),
824
+ camelcase: /* @__PURE__ */ __name(function(object) {
825
+ return object ? "True" : "False";
826
+ }, "camelcase")
827
+ },
828
+ defaultStyle: "lowercase"
829
+ });
830
+ function isHexCode(c) {
831
+ return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
832
+ }
833
+ __name(isHexCode, "isHexCode");
834
+ function isOctCode(c) {
835
+ return 48 <= c && c <= 55;
836
+ }
837
+ __name(isOctCode, "isOctCode");
838
+ function isDecCode(c) {
839
+ return 48 <= c && c <= 57;
840
+ }
841
+ __name(isDecCode, "isDecCode");
842
+ function resolveYamlInteger(data) {
843
+ if (data === null) return false;
844
+ var max = data.length, index = 0, hasDigits = false, ch;
845
+ if (!max) return false;
846
+ ch = data[index];
847
+ if (ch === "-" || ch === "+") {
848
+ ch = data[++index];
849
+ }
850
+ if (ch === "0") {
851
+ if (index + 1 === max) return true;
852
+ ch = data[++index];
853
+ if (ch === "b") {
854
+ index++;
855
+ for (; index < max; index++) {
856
+ ch = data[index];
857
+ if (ch === "_") continue;
858
+ if (ch !== "0" && ch !== "1") return false;
859
+ hasDigits = true;
860
+ }
861
+ return hasDigits && ch !== "_";
862
+ }
863
+ if (ch === "x") {
864
+ index++;
865
+ for (; index < max; index++) {
866
+ ch = data[index];
867
+ if (ch === "_") continue;
868
+ if (!isHexCode(data.charCodeAt(index))) return false;
869
+ hasDigits = true;
870
+ }
871
+ return hasDigits && ch !== "_";
872
+ }
873
+ if (ch === "o") {
874
+ index++;
875
+ for (; index < max; index++) {
876
+ ch = data[index];
877
+ if (ch === "_") continue;
878
+ if (!isOctCode(data.charCodeAt(index))) return false;
879
+ hasDigits = true;
880
+ }
881
+ return hasDigits && ch !== "_";
882
+ }
883
+ }
884
+ if (ch === "_") return false;
885
+ for (; index < max; index++) {
886
+ ch = data[index];
887
+ if (ch === "_") continue;
888
+ if (!isDecCode(data.charCodeAt(index))) {
889
+ return false;
890
+ }
891
+ hasDigits = true;
892
+ }
893
+ if (!hasDigits || ch === "_") return false;
894
+ return true;
895
+ }
896
+ __name(resolveYamlInteger, "resolveYamlInteger");
897
+ function constructYamlInteger(data) {
898
+ var value = data, sign = 1, ch;
899
+ if (value.indexOf("_") !== -1) {
900
+ value = value.replace(/_/g, "");
901
+ }
902
+ ch = value[0];
903
+ if (ch === "-" || ch === "+") {
904
+ if (ch === "-") sign = -1;
905
+ value = value.slice(1);
906
+ ch = value[0];
907
+ }
908
+ if (value === "0") return 0;
909
+ if (ch === "0") {
910
+ if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
911
+ if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
912
+ if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
913
+ }
914
+ return sign * parseInt(value, 10);
915
+ }
916
+ __name(constructYamlInteger, "constructYamlInteger");
917
+ function isInteger(object) {
918
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
919
+ }
920
+ __name(isInteger, "isInteger");
921
+ var int = new type("tag:yaml.org,2002:int", {
922
+ kind: "scalar",
923
+ resolve: resolveYamlInteger,
924
+ construct: constructYamlInteger,
925
+ predicate: isInteger,
926
+ represent: {
927
+ binary: /* @__PURE__ */ __name(function(obj) {
928
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
929
+ }, "binary"),
930
+ octal: /* @__PURE__ */ __name(function(obj) {
931
+ return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
932
+ }, "octal"),
933
+ decimal: /* @__PURE__ */ __name(function(obj) {
934
+ return obj.toString(10);
935
+ }, "decimal"),
936
+ /* eslint-disable max-len */
937
+ hexadecimal: /* @__PURE__ */ __name(function(obj) {
938
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
939
+ }, "hexadecimal")
940
+ },
941
+ defaultStyle: "decimal",
942
+ styleAliases: {
943
+ binary: [2, "bin"],
944
+ octal: [8, "oct"],
945
+ decimal: [10, "dec"],
946
+ hexadecimal: [16, "hex"]
947
+ }
948
+ });
949
+ var YAML_FLOAT_PATTERN = new RegExp(
950
+ // 2.5e4, 2.5 and integers
951
+ "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
952
+ );
953
+ function resolveYamlFloat(data) {
954
+ if (data === null) return false;
955
+ if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
956
+ // Probably should update regexp & check speed
957
+ data[data.length - 1] === "_") {
958
+ return false;
959
+ }
960
+ return true;
961
+ }
962
+ __name(resolveYamlFloat, "resolveYamlFloat");
963
+ function constructYamlFloat(data) {
964
+ var value, sign;
965
+ value = data.replace(/_/g, "").toLowerCase();
966
+ sign = value[0] === "-" ? -1 : 1;
967
+ if ("+-".indexOf(value[0]) >= 0) {
968
+ value = value.slice(1);
969
+ }
970
+ if (value === ".inf") {
971
+ return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
972
+ } else if (value === ".nan") {
973
+ return NaN;
974
+ }
975
+ return sign * parseFloat(value, 10);
976
+ }
977
+ __name(constructYamlFloat, "constructYamlFloat");
978
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
979
+ function representYamlFloat(object, style) {
980
+ var res;
981
+ if (isNaN(object)) {
982
+ switch (style) {
983
+ case "lowercase":
984
+ return ".nan";
985
+ case "uppercase":
986
+ return ".NAN";
987
+ case "camelcase":
988
+ return ".NaN";
989
+ }
990
+ } else if (Number.POSITIVE_INFINITY === object) {
991
+ switch (style) {
992
+ case "lowercase":
993
+ return ".inf";
994
+ case "uppercase":
995
+ return ".INF";
996
+ case "camelcase":
997
+ return ".Inf";
998
+ }
999
+ } else if (Number.NEGATIVE_INFINITY === object) {
1000
+ switch (style) {
1001
+ case "lowercase":
1002
+ return "-.inf";
1003
+ case "uppercase":
1004
+ return "-.INF";
1005
+ case "camelcase":
1006
+ return "-.Inf";
1007
+ }
1008
+ } else if (common.isNegativeZero(object)) {
1009
+ return "-0.0";
1010
+ }
1011
+ res = object.toString(10);
1012
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
1013
+ }
1014
+ __name(representYamlFloat, "representYamlFloat");
1015
+ function isFloat(object) {
1016
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
1017
+ }
1018
+ __name(isFloat, "isFloat");
1019
+ var float = new type("tag:yaml.org,2002:float", {
1020
+ kind: "scalar",
1021
+ resolve: resolveYamlFloat,
1022
+ construct: constructYamlFloat,
1023
+ predicate: isFloat,
1024
+ represent: representYamlFloat,
1025
+ defaultStyle: "lowercase"
1026
+ });
1027
+ var json = failsafe.extend({
1028
+ implicit: [
1029
+ _null,
1030
+ bool,
1031
+ int,
1032
+ float
1033
+ ]
1034
+ });
1035
+ var core = json;
1036
+ var YAML_DATE_REGEXP = new RegExp(
1037
+ "^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
1038
+ );
1039
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
1040
+ "^([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]))?))?$"
1041
+ );
1042
+ function resolveYamlTimestamp(data) {
1043
+ if (data === null) return false;
1044
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
1045
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
1046
+ return false;
1047
+ }
1048
+ __name(resolveYamlTimestamp, "resolveYamlTimestamp");
1049
+ function constructYamlTimestamp(data) {
1050
+ var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
1051
+ match = YAML_DATE_REGEXP.exec(data);
1052
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
1053
+ if (match === null) throw new Error("Date resolve error");
1054
+ year = +match[1];
1055
+ month = +match[2] - 1;
1056
+ day = +match[3];
1057
+ if (!match[4]) {
1058
+ return new Date(Date.UTC(year, month, day));
1059
+ }
1060
+ hour = +match[4];
1061
+ minute = +match[5];
1062
+ second = +match[6];
1063
+ if (match[7]) {
1064
+ fraction = match[7].slice(0, 3);
1065
+ while (fraction.length < 3) {
1066
+ fraction += "0";
1067
+ }
1068
+ fraction = +fraction;
1069
+ }
1070
+ if (match[9]) {
1071
+ tz_hour = +match[10];
1072
+ tz_minute = +(match[11] || 0);
1073
+ delta = (tz_hour * 60 + tz_minute) * 6e4;
1074
+ if (match[9] === "-") delta = -delta;
1075
+ }
1076
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1077
+ if (delta) date.setTime(date.getTime() - delta);
1078
+ return date;
1079
+ }
1080
+ __name(constructYamlTimestamp, "constructYamlTimestamp");
1081
+ function representYamlTimestamp(object) {
1082
+ return object.toISOString();
1083
+ }
1084
+ __name(representYamlTimestamp, "representYamlTimestamp");
1085
+ var timestamp = new type("tag:yaml.org,2002:timestamp", {
1086
+ kind: "scalar",
1087
+ resolve: resolveYamlTimestamp,
1088
+ construct: constructYamlTimestamp,
1089
+ instanceOf: Date,
1090
+ represent: representYamlTimestamp
1091
+ });
1092
+ function resolveYamlMerge(data) {
1093
+ return data === "<<" || data === null;
1094
+ }
1095
+ __name(resolveYamlMerge, "resolveYamlMerge");
1096
+ var merge = new type("tag:yaml.org,2002:merge", {
1097
+ kind: "scalar",
1098
+ resolve: resolveYamlMerge
1099
+ });
1100
+ var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
1101
+ function resolveYamlBinary(data) {
1102
+ if (data === null) return false;
1103
+ var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
1104
+ for (idx = 0; idx < max; idx++) {
1105
+ code = map2.indexOf(data.charAt(idx));
1106
+ if (code > 64) continue;
1107
+ if (code < 0) return false;
1108
+ bitlen += 6;
1109
+ }
1110
+ return bitlen % 8 === 0;
1111
+ }
1112
+ __name(resolveYamlBinary, "resolveYamlBinary");
1113
+ function constructYamlBinary(data) {
1114
+ var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
1115
+ for (idx = 0; idx < max; idx++) {
1116
+ if (idx % 4 === 0 && idx) {
1117
+ result.push(bits >> 16 & 255);
1118
+ result.push(bits >> 8 & 255);
1119
+ result.push(bits & 255);
1120
+ }
1121
+ bits = bits << 6 | map2.indexOf(input.charAt(idx));
1122
+ }
1123
+ tailbits = max % 4 * 6;
1124
+ if (tailbits === 0) {
1125
+ result.push(bits >> 16 & 255);
1126
+ result.push(bits >> 8 & 255);
1127
+ result.push(bits & 255);
1128
+ } else if (tailbits === 18) {
1129
+ result.push(bits >> 10 & 255);
1130
+ result.push(bits >> 2 & 255);
1131
+ } else if (tailbits === 12) {
1132
+ result.push(bits >> 4 & 255);
1133
+ }
1134
+ return new Uint8Array(result);
1135
+ }
1136
+ __name(constructYamlBinary, "constructYamlBinary");
1137
+ function representYamlBinary(object) {
1138
+ var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
1139
+ for (idx = 0; idx < max; idx++) {
1140
+ if (idx % 3 === 0 && idx) {
1141
+ result += map2[bits >> 18 & 63];
1142
+ result += map2[bits >> 12 & 63];
1143
+ result += map2[bits >> 6 & 63];
1144
+ result += map2[bits & 63];
1145
+ }
1146
+ bits = (bits << 8) + object[idx];
1147
+ }
1148
+ tail = max % 3;
1149
+ if (tail === 0) {
1150
+ result += map2[bits >> 18 & 63];
1151
+ result += map2[bits >> 12 & 63];
1152
+ result += map2[bits >> 6 & 63];
1153
+ result += map2[bits & 63];
1154
+ } else if (tail === 2) {
1155
+ result += map2[bits >> 10 & 63];
1156
+ result += map2[bits >> 4 & 63];
1157
+ result += map2[bits << 2 & 63];
1158
+ result += map2[64];
1159
+ } else if (tail === 1) {
1160
+ result += map2[bits >> 2 & 63];
1161
+ result += map2[bits << 4 & 63];
1162
+ result += map2[64];
1163
+ result += map2[64];
1164
+ }
1165
+ return result;
1166
+ }
1167
+ __name(representYamlBinary, "representYamlBinary");
1168
+ function isBinary(obj) {
1169
+ return Object.prototype.toString.call(obj) === "[object Uint8Array]";
1170
+ }
1171
+ __name(isBinary, "isBinary");
1172
+ var binary = new type("tag:yaml.org,2002:binary", {
1173
+ kind: "scalar",
1174
+ resolve: resolveYamlBinary,
1175
+ construct: constructYamlBinary,
1176
+ predicate: isBinary,
1177
+ represent: representYamlBinary
1178
+ });
1179
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1180
+ var _toString$2 = Object.prototype.toString;
1181
+ function resolveYamlOmap(data) {
1182
+ if (data === null) return true;
1183
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
1184
+ for (index = 0, length = object.length; index < length; index += 1) {
1185
+ pair = object[index];
1186
+ pairHasKey = false;
1187
+ if (_toString$2.call(pair) !== "[object Object]") return false;
1188
+ for (pairKey in pair) {
1189
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
1190
+ if (!pairHasKey) pairHasKey = true;
1191
+ else return false;
1192
+ }
1193
+ }
1194
+ if (!pairHasKey) return false;
1195
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
1196
+ else return false;
1197
+ }
1198
+ return true;
1199
+ }
1200
+ __name(resolveYamlOmap, "resolveYamlOmap");
1201
+ function constructYamlOmap(data) {
1202
+ return data !== null ? data : [];
1203
+ }
1204
+ __name(constructYamlOmap, "constructYamlOmap");
1205
+ var omap = new type("tag:yaml.org,2002:omap", {
1206
+ kind: "sequence",
1207
+ resolve: resolveYamlOmap,
1208
+ construct: constructYamlOmap
1209
+ });
1210
+ var _toString$1 = Object.prototype.toString;
1211
+ function resolveYamlPairs(data) {
1212
+ if (data === null) return true;
1213
+ var index, length, pair, keys, result, object = data;
1214
+ result = new Array(object.length);
1215
+ for (index = 0, length = object.length; index < length; index += 1) {
1216
+ pair = object[index];
1217
+ if (_toString$1.call(pair) !== "[object Object]") return false;
1218
+ keys = Object.keys(pair);
1219
+ if (keys.length !== 1) return false;
1220
+ result[index] = [keys[0], pair[keys[0]]];
1221
+ }
1222
+ return true;
1223
+ }
1224
+ __name(resolveYamlPairs, "resolveYamlPairs");
1225
+ function constructYamlPairs(data) {
1226
+ if (data === null) return [];
1227
+ var index, length, pair, keys, result, object = data;
1228
+ result = new Array(object.length);
1229
+ for (index = 0, length = object.length; index < length; index += 1) {
1230
+ pair = object[index];
1231
+ keys = Object.keys(pair);
1232
+ result[index] = [keys[0], pair[keys[0]]];
1233
+ }
1234
+ return result;
1235
+ }
1236
+ __name(constructYamlPairs, "constructYamlPairs");
1237
+ var pairs = new type("tag:yaml.org,2002:pairs", {
1238
+ kind: "sequence",
1239
+ resolve: resolveYamlPairs,
1240
+ construct: constructYamlPairs
1241
+ });
1242
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1243
+ function resolveYamlSet(data) {
1244
+ if (data === null) return true;
1245
+ var key, object = data;
1246
+ for (key in object) {
1247
+ if (_hasOwnProperty$2.call(object, key)) {
1248
+ if (object[key] !== null) return false;
1249
+ }
1250
+ }
1251
+ return true;
1252
+ }
1253
+ __name(resolveYamlSet, "resolveYamlSet");
1254
+ function constructYamlSet(data) {
1255
+ return data !== null ? data : {};
1256
+ }
1257
+ __name(constructYamlSet, "constructYamlSet");
1258
+ var set = new type("tag:yaml.org,2002:set", {
1259
+ kind: "mapping",
1260
+ resolve: resolveYamlSet,
1261
+ construct: constructYamlSet
1262
+ });
1263
+ var _default = core.extend({
1264
+ implicit: [
1265
+ timestamp,
1266
+ merge
1267
+ ],
1268
+ explicit: [
1269
+ binary,
1270
+ omap,
1271
+ pairs,
1272
+ set
1273
+ ]
1274
+ });
1275
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1276
+ var CONTEXT_FLOW_IN = 1;
1277
+ var CONTEXT_FLOW_OUT = 2;
1278
+ var CONTEXT_BLOCK_IN = 3;
1279
+ var CONTEXT_BLOCK_OUT = 4;
1280
+ var CHOMPING_CLIP = 1;
1281
+ var CHOMPING_STRIP = 2;
1282
+ var CHOMPING_KEEP = 3;
1283
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1284
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
1285
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1286
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1287
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1288
+ function _class(obj) {
1289
+ return Object.prototype.toString.call(obj);
1290
+ }
1291
+ __name(_class, "_class");
1292
+ function is_EOL(c) {
1293
+ return c === 10 || c === 13;
1294
+ }
1295
+ __name(is_EOL, "is_EOL");
1296
+ function is_WHITE_SPACE(c) {
1297
+ return c === 9 || c === 32;
1298
+ }
1299
+ __name(is_WHITE_SPACE, "is_WHITE_SPACE");
1300
+ function is_WS_OR_EOL(c) {
1301
+ return c === 9 || c === 32 || c === 10 || c === 13;
1302
+ }
1303
+ __name(is_WS_OR_EOL, "is_WS_OR_EOL");
1304
+ function is_FLOW_INDICATOR(c) {
1305
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
1306
+ }
1307
+ __name(is_FLOW_INDICATOR, "is_FLOW_INDICATOR");
1308
+ function fromHexCode(c) {
1309
+ var lc;
1310
+ if (48 <= c && c <= 57) {
1311
+ return c - 48;
1312
+ }
1313
+ lc = c | 32;
1314
+ if (97 <= lc && lc <= 102) {
1315
+ return lc - 97 + 10;
1316
+ }
1317
+ return -1;
1318
+ }
1319
+ __name(fromHexCode, "fromHexCode");
1320
+ function escapedHexLen(c) {
1321
+ if (c === 120) {
1322
+ return 2;
1323
+ }
1324
+ if (c === 117) {
1325
+ return 4;
1326
+ }
1327
+ if (c === 85) {
1328
+ return 8;
1329
+ }
1330
+ return 0;
1331
+ }
1332
+ __name(escapedHexLen, "escapedHexLen");
1333
+ function fromDecimalCode(c) {
1334
+ if (48 <= c && c <= 57) {
1335
+ return c - 48;
1336
+ }
1337
+ return -1;
1338
+ }
1339
+ __name(fromDecimalCode, "fromDecimalCode");
1340
+ function simpleEscapeSequence(c) {
1341
+ 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" : "";
1342
+ }
1343
+ __name(simpleEscapeSequence, "simpleEscapeSequence");
1344
+ function charFromCodepoint(c) {
1345
+ if (c <= 65535) {
1346
+ return String.fromCharCode(c);
1347
+ }
1348
+ return String.fromCharCode(
1349
+ (c - 65536 >> 10) + 55296,
1350
+ (c - 65536 & 1023) + 56320
1351
+ );
1352
+ }
1353
+ __name(charFromCodepoint, "charFromCodepoint");
1354
+ var simpleEscapeCheck = new Array(256);
1355
+ var simpleEscapeMap = new Array(256);
1356
+ for (i = 0; i < 256; i++) {
1357
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1358
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
1359
+ }
1360
+ var i;
1361
+ function State$1(input, options) {
1362
+ this.input = input;
1363
+ this.filename = options["filename"] || null;
1364
+ this.schema = options["schema"] || _default;
1365
+ this.onWarning = options["onWarning"] || null;
1366
+ this.legacy = options["legacy"] || false;
1367
+ this.json = options["json"] || false;
1368
+ this.listener = options["listener"] || null;
1369
+ this.implicitTypes = this.schema.compiledImplicit;
1370
+ this.typeMap = this.schema.compiledTypeMap;
1371
+ this.length = input.length;
1372
+ this.position = 0;
1373
+ this.line = 0;
1374
+ this.lineStart = 0;
1375
+ this.lineIndent = 0;
1376
+ this.firstTabInLine = -1;
1377
+ this.documents = [];
1378
+ }
1379
+ __name(State$1, "State$1");
1380
+ function generateError(state, message) {
1381
+ var mark = {
1382
+ name: state.filename,
1383
+ buffer: state.input.slice(0, -1),
1384
+ // omit trailing \0
1385
+ position: state.position,
1386
+ line: state.line,
1387
+ column: state.position - state.lineStart
1388
+ };
1389
+ mark.snippet = snippet(mark);
1390
+ return new exception(message, mark);
1391
+ }
1392
+ __name(generateError, "generateError");
1393
+ function throwError(state, message) {
1394
+ throw generateError(state, message);
1395
+ }
1396
+ __name(throwError, "throwError");
1397
+ function throwWarning(state, message) {
1398
+ if (state.onWarning) {
1399
+ state.onWarning.call(null, generateError(state, message));
1400
+ }
1401
+ }
1402
+ __name(throwWarning, "throwWarning");
1403
+ var directiveHandlers = {
1404
+ YAML: /* @__PURE__ */ __name(function handleYamlDirective(state, name, args) {
1405
+ var match, major, minor;
1406
+ if (state.version !== null) {
1407
+ throwError(state, "duplication of %YAML directive");
1408
+ }
1409
+ if (args.length !== 1) {
1410
+ throwError(state, "YAML directive accepts exactly one argument");
1411
+ }
1412
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
1413
+ if (match === null) {
1414
+ throwError(state, "ill-formed argument of the YAML directive");
1415
+ }
1416
+ major = parseInt(match[1], 10);
1417
+ minor = parseInt(match[2], 10);
1418
+ if (major !== 1) {
1419
+ throwError(state, "unacceptable YAML version of the document");
1420
+ }
1421
+ state.version = args[0];
1422
+ state.checkLineBreaks = minor < 2;
1423
+ if (minor !== 1 && minor !== 2) {
1424
+ throwWarning(state, "unsupported YAML version of the document");
1425
+ }
1426
+ }, "handleYamlDirective"),
1427
+ TAG: /* @__PURE__ */ __name(function handleTagDirective(state, name, args) {
1428
+ var handle, prefix;
1429
+ if (args.length !== 2) {
1430
+ throwError(state, "TAG directive accepts exactly two arguments");
1431
+ }
1432
+ handle = args[0];
1433
+ prefix = args[1];
1434
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
1435
+ throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
1436
+ }
1437
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
1438
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
1439
+ }
1440
+ if (!PATTERN_TAG_URI.test(prefix)) {
1441
+ throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
1442
+ }
1443
+ try {
1444
+ prefix = decodeURIComponent(prefix);
1445
+ } catch (err) {
1446
+ throwError(state, "tag prefix is malformed: " + prefix);
1447
+ }
1448
+ state.tagMap[handle] = prefix;
1449
+ }, "handleTagDirective")
1450
+ };
1451
+ function captureSegment(state, start, end, checkJson) {
1452
+ var _position, _length, _character, _result;
1453
+ if (start < end) {
1454
+ _result = state.input.slice(start, end);
1455
+ if (checkJson) {
1456
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
1457
+ _character = _result.charCodeAt(_position);
1458
+ if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
1459
+ throwError(state, "expected valid JSON character");
1460
+ }
1461
+ }
1462
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1463
+ throwError(state, "the stream contains non-printable characters");
1464
+ }
1465
+ state.result += _result;
1466
+ }
1467
+ }
1468
+ __name(captureSegment, "captureSegment");
1469
+ function mergeMappings(state, destination, source, overridableKeys) {
1470
+ var sourceKeys, key, index, quantity;
1471
+ if (!common.isObject(source)) {
1472
+ throwError(state, "cannot merge mappings; the provided source object is unacceptable");
1473
+ }
1474
+ sourceKeys = Object.keys(source);
1475
+ for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1476
+ key = sourceKeys[index];
1477
+ if (!_hasOwnProperty$1.call(destination, key)) {
1478
+ destination[key] = source[key];
1479
+ overridableKeys[key] = true;
1480
+ }
1481
+ }
1482
+ }
1483
+ __name(mergeMappings, "mergeMappings");
1484
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
1485
+ var index, quantity;
1486
+ if (Array.isArray(keyNode)) {
1487
+ keyNode = Array.prototype.slice.call(keyNode);
1488
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
1489
+ if (Array.isArray(keyNode[index])) {
1490
+ throwError(state, "nested arrays are not supported inside keys");
1491
+ }
1492
+ if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
1493
+ keyNode[index] = "[object Object]";
1494
+ }
1495
+ }
1496
+ }
1497
+ if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
1498
+ keyNode = "[object Object]";
1499
+ }
1500
+ keyNode = String(keyNode);
1501
+ if (_result === null) {
1502
+ _result = {};
1503
+ }
1504
+ if (keyTag === "tag:yaml.org,2002:merge") {
1505
+ if (Array.isArray(valueNode)) {
1506
+ for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1507
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
1508
+ }
1509
+ } else {
1510
+ mergeMappings(state, _result, valueNode, overridableKeys);
1511
+ }
1512
+ } else {
1513
+ if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
1514
+ state.line = startLine || state.line;
1515
+ state.lineStart = startLineStart || state.lineStart;
1516
+ state.position = startPos || state.position;
1517
+ throwError(state, "duplicated mapping key");
1518
+ }
1519
+ if (keyNode === "__proto__") {
1520
+ Object.defineProperty(_result, keyNode, {
1521
+ configurable: true,
1522
+ enumerable: true,
1523
+ writable: true,
1524
+ value: valueNode
1525
+ });
1526
+ } else {
1527
+ _result[keyNode] = valueNode;
1528
+ }
1529
+ delete overridableKeys[keyNode];
1530
+ }
1531
+ return _result;
1532
+ }
1533
+ __name(storeMappingPair, "storeMappingPair");
1534
+ function readLineBreak(state) {
1535
+ var ch;
1536
+ ch = state.input.charCodeAt(state.position);
1537
+ if (ch === 10) {
1538
+ state.position++;
1539
+ } else if (ch === 13) {
1540
+ state.position++;
1541
+ if (state.input.charCodeAt(state.position) === 10) {
1542
+ state.position++;
1543
+ }
1544
+ } else {
1545
+ throwError(state, "a line break is expected");
1546
+ }
1547
+ state.line += 1;
1548
+ state.lineStart = state.position;
1549
+ state.firstTabInLine = -1;
1550
+ }
1551
+ __name(readLineBreak, "readLineBreak");
1552
+ function skipSeparationSpace(state, allowComments, checkIndent) {
1553
+ var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
1554
+ while (ch !== 0) {
1555
+ while (is_WHITE_SPACE(ch)) {
1556
+ if (ch === 9 && state.firstTabInLine === -1) {
1557
+ state.firstTabInLine = state.position;
1558
+ }
1559
+ ch = state.input.charCodeAt(++state.position);
1560
+ }
1561
+ if (allowComments && ch === 35) {
1562
+ do {
1563
+ ch = state.input.charCodeAt(++state.position);
1564
+ } while (ch !== 10 && ch !== 13 && ch !== 0);
1565
+ }
1566
+ if (is_EOL(ch)) {
1567
+ readLineBreak(state);
1568
+ ch = state.input.charCodeAt(state.position);
1569
+ lineBreaks++;
1570
+ state.lineIndent = 0;
1571
+ while (ch === 32) {
1572
+ state.lineIndent++;
1573
+ ch = state.input.charCodeAt(++state.position);
1574
+ }
1575
+ } else {
1576
+ break;
1577
+ }
1578
+ }
1579
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1580
+ throwWarning(state, "deficient indentation");
1581
+ }
1582
+ return lineBreaks;
1583
+ }
1584
+ __name(skipSeparationSpace, "skipSeparationSpace");
1585
+ function testDocumentSeparator(state) {
1586
+ var _position = state.position, ch;
1587
+ ch = state.input.charCodeAt(_position);
1588
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
1589
+ _position += 3;
1590
+ ch = state.input.charCodeAt(_position);
1591
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
1592
+ return true;
1593
+ }
1594
+ }
1595
+ return false;
1596
+ }
1597
+ __name(testDocumentSeparator, "testDocumentSeparator");
1598
+ function writeFoldedLines(state, count) {
1599
+ if (count === 1) {
1600
+ state.result += " ";
1601
+ } else if (count > 1) {
1602
+ state.result += common.repeat("\n", count - 1);
1603
+ }
1604
+ }
1605
+ __name(writeFoldedLines, "writeFoldedLines");
1606
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1607
+ var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
1608
+ ch = state.input.charCodeAt(state.position);
1609
+ 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) {
1610
+ return false;
1611
+ }
1612
+ if (ch === 63 || ch === 45) {
1613
+ following = state.input.charCodeAt(state.position + 1);
1614
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1615
+ return false;
1616
+ }
1617
+ }
1618
+ state.kind = "scalar";
1619
+ state.result = "";
1620
+ captureStart = captureEnd = state.position;
1621
+ hasPendingContent = false;
1622
+ while (ch !== 0) {
1623
+ if (ch === 58) {
1624
+ following = state.input.charCodeAt(state.position + 1);
1625
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
1626
+ break;
1627
+ }
1628
+ } else if (ch === 35) {
1629
+ preceding = state.input.charCodeAt(state.position - 1);
1630
+ if (is_WS_OR_EOL(preceding)) {
1631
+ break;
1632
+ }
1633
+ } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1634
+ break;
1635
+ } else if (is_EOL(ch)) {
1636
+ _line = state.line;
1637
+ _lineStart = state.lineStart;
1638
+ _lineIndent = state.lineIndent;
1639
+ skipSeparationSpace(state, false, -1);
1640
+ if (state.lineIndent >= nodeIndent) {
1641
+ hasPendingContent = true;
1642
+ ch = state.input.charCodeAt(state.position);
1643
+ continue;
1644
+ } else {
1645
+ state.position = captureEnd;
1646
+ state.line = _line;
1647
+ state.lineStart = _lineStart;
1648
+ state.lineIndent = _lineIndent;
1649
+ break;
1650
+ }
1651
+ }
1652
+ if (hasPendingContent) {
1653
+ captureSegment(state, captureStart, captureEnd, false);
1654
+ writeFoldedLines(state, state.line - _line);
1655
+ captureStart = captureEnd = state.position;
1656
+ hasPendingContent = false;
1657
+ }
1658
+ if (!is_WHITE_SPACE(ch)) {
1659
+ captureEnd = state.position + 1;
1660
+ }
1661
+ ch = state.input.charCodeAt(++state.position);
1662
+ }
1663
+ captureSegment(state, captureStart, captureEnd, false);
1664
+ if (state.result) {
1665
+ return true;
1666
+ }
1667
+ state.kind = _kind;
1668
+ state.result = _result;
1669
+ return false;
1670
+ }
1671
+ __name(readPlainScalar, "readPlainScalar");
1672
+ function readSingleQuotedScalar(state, nodeIndent) {
1673
+ var ch, captureStart, captureEnd;
1674
+ ch = state.input.charCodeAt(state.position);
1675
+ if (ch !== 39) {
1676
+ return false;
1677
+ }
1678
+ state.kind = "scalar";
1679
+ state.result = "";
1680
+ state.position++;
1681
+ captureStart = captureEnd = state.position;
1682
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1683
+ if (ch === 39) {
1684
+ captureSegment(state, captureStart, state.position, true);
1685
+ ch = state.input.charCodeAt(++state.position);
1686
+ if (ch === 39) {
1687
+ captureStart = state.position;
1688
+ state.position++;
1689
+ captureEnd = state.position;
1690
+ } else {
1691
+ return true;
1692
+ }
1693
+ } else if (is_EOL(ch)) {
1694
+ captureSegment(state, captureStart, captureEnd, true);
1695
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1696
+ captureStart = captureEnd = state.position;
1697
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1698
+ throwError(state, "unexpected end of the document within a single quoted scalar");
1699
+ } else {
1700
+ state.position++;
1701
+ captureEnd = state.position;
1702
+ }
1703
+ }
1704
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
1705
+ }
1706
+ __name(readSingleQuotedScalar, "readSingleQuotedScalar");
1707
+ function readDoubleQuotedScalar(state, nodeIndent) {
1708
+ var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
1709
+ ch = state.input.charCodeAt(state.position);
1710
+ if (ch !== 34) {
1711
+ return false;
1712
+ }
1713
+ state.kind = "scalar";
1714
+ state.result = "";
1715
+ state.position++;
1716
+ captureStart = captureEnd = state.position;
1717
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1718
+ if (ch === 34) {
1719
+ captureSegment(state, captureStart, state.position, true);
1720
+ state.position++;
1721
+ return true;
1722
+ } else if (ch === 92) {
1723
+ captureSegment(state, captureStart, state.position, true);
1724
+ ch = state.input.charCodeAt(++state.position);
1725
+ if (is_EOL(ch)) {
1726
+ skipSeparationSpace(state, false, nodeIndent);
1727
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
1728
+ state.result += simpleEscapeMap[ch];
1729
+ state.position++;
1730
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
1731
+ hexLength = tmp;
1732
+ hexResult = 0;
1733
+ for (; hexLength > 0; hexLength--) {
1734
+ ch = state.input.charCodeAt(++state.position);
1735
+ if ((tmp = fromHexCode(ch)) >= 0) {
1736
+ hexResult = (hexResult << 4) + tmp;
1737
+ } else {
1738
+ throwError(state, "expected hexadecimal character");
1739
+ }
1740
+ }
1741
+ state.result += charFromCodepoint(hexResult);
1742
+ state.position++;
1743
+ } else {
1744
+ throwError(state, "unknown escape sequence");
1745
+ }
1746
+ captureStart = captureEnd = state.position;
1747
+ } else if (is_EOL(ch)) {
1748
+ captureSegment(state, captureStart, captureEnd, true);
1749
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1750
+ captureStart = captureEnd = state.position;
1751
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1752
+ throwError(state, "unexpected end of the document within a double quoted scalar");
1753
+ } else {
1754
+ state.position++;
1755
+ captureEnd = state.position;
1756
+ }
1757
+ }
1758
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
1759
+ }
1760
+ __name(readDoubleQuotedScalar, "readDoubleQuotedScalar");
1761
+ function readFlowCollection(state, nodeIndent) {
1762
+ 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;
1763
+ ch = state.input.charCodeAt(state.position);
1764
+ if (ch === 91) {
1765
+ terminator = 93;
1766
+ isMapping = false;
1767
+ _result = [];
1768
+ } else if (ch === 123) {
1769
+ terminator = 125;
1770
+ isMapping = true;
1771
+ _result = {};
1772
+ } else {
1773
+ return false;
1774
+ }
1775
+ if (state.anchor !== null) {
1776
+ state.anchorMap[state.anchor] = _result;
1777
+ }
1778
+ ch = state.input.charCodeAt(++state.position);
1779
+ while (ch !== 0) {
1780
+ skipSeparationSpace(state, true, nodeIndent);
1781
+ ch = state.input.charCodeAt(state.position);
1782
+ if (ch === terminator) {
1783
+ state.position++;
1784
+ state.tag = _tag;
1785
+ state.anchor = _anchor;
1786
+ state.kind = isMapping ? "mapping" : "sequence";
1787
+ state.result = _result;
1788
+ return true;
1789
+ } else if (!readNext) {
1790
+ throwError(state, "missed comma between flow collection entries");
1791
+ } else if (ch === 44) {
1792
+ throwError(state, "expected the node content, but found ','");
1793
+ }
1794
+ keyTag = keyNode = valueNode = null;
1795
+ isPair = isExplicitPair = false;
1796
+ if (ch === 63) {
1797
+ following = state.input.charCodeAt(state.position + 1);
1798
+ if (is_WS_OR_EOL(following)) {
1799
+ isPair = isExplicitPair = true;
1800
+ state.position++;
1801
+ skipSeparationSpace(state, true, nodeIndent);
1802
+ }
1803
+ }
1804
+ _line = state.line;
1805
+ _lineStart = state.lineStart;
1806
+ _pos = state.position;
1807
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1808
+ keyTag = state.tag;
1809
+ keyNode = state.result;
1810
+ skipSeparationSpace(state, true, nodeIndent);
1811
+ ch = state.input.charCodeAt(state.position);
1812
+ if ((isExplicitPair || state.line === _line) && ch === 58) {
1813
+ isPair = true;
1814
+ ch = state.input.charCodeAt(++state.position);
1815
+ skipSeparationSpace(state, true, nodeIndent);
1816
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1817
+ valueNode = state.result;
1818
+ }
1819
+ if (isMapping) {
1820
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
1821
+ } else if (isPair) {
1822
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
1823
+ } else {
1824
+ _result.push(keyNode);
1825
+ }
1826
+ skipSeparationSpace(state, true, nodeIndent);
1827
+ ch = state.input.charCodeAt(state.position);
1828
+ if (ch === 44) {
1829
+ readNext = true;
1830
+ ch = state.input.charCodeAt(++state.position);
1831
+ } else {
1832
+ readNext = false;
1833
+ }
1834
+ }
1835
+ throwError(state, "unexpected end of the stream within a flow collection");
1836
+ }
1837
+ __name(readFlowCollection, "readFlowCollection");
1838
+ function readBlockScalar(state, nodeIndent) {
1839
+ var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
1840
+ ch = state.input.charCodeAt(state.position);
1841
+ if (ch === 124) {
1842
+ folding = false;
1843
+ } else if (ch === 62) {
1844
+ folding = true;
1845
+ } else {
1846
+ return false;
1847
+ }
1848
+ state.kind = "scalar";
1849
+ state.result = "";
1850
+ while (ch !== 0) {
1851
+ ch = state.input.charCodeAt(++state.position);
1852
+ if (ch === 43 || ch === 45) {
1853
+ if (CHOMPING_CLIP === chomping) {
1854
+ chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
1855
+ } else {
1856
+ throwError(state, "repeat of a chomping mode identifier");
1857
+ }
1858
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
1859
+ if (tmp === 0) {
1860
+ throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
1861
+ } else if (!detectedIndent) {
1862
+ textIndent = nodeIndent + tmp - 1;
1863
+ detectedIndent = true;
1864
+ } else {
1865
+ throwError(state, "repeat of an indentation width identifier");
1866
+ }
1867
+ } else {
1868
+ break;
1869
+ }
1870
+ }
1871
+ if (is_WHITE_SPACE(ch)) {
1872
+ do {
1873
+ ch = state.input.charCodeAt(++state.position);
1874
+ } while (is_WHITE_SPACE(ch));
1875
+ if (ch === 35) {
1876
+ do {
1877
+ ch = state.input.charCodeAt(++state.position);
1878
+ } while (!is_EOL(ch) && ch !== 0);
1879
+ }
1880
+ }
1881
+ while (ch !== 0) {
1882
+ readLineBreak(state);
1883
+ state.lineIndent = 0;
1884
+ ch = state.input.charCodeAt(state.position);
1885
+ while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
1886
+ state.lineIndent++;
1887
+ ch = state.input.charCodeAt(++state.position);
1888
+ }
1889
+ if (!detectedIndent && state.lineIndent > textIndent) {
1890
+ textIndent = state.lineIndent;
1891
+ }
1892
+ if (is_EOL(ch)) {
1893
+ emptyLines++;
1894
+ continue;
1895
+ }
1896
+ if (state.lineIndent < textIndent) {
1897
+ if (chomping === CHOMPING_KEEP) {
1898
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1899
+ } else if (chomping === CHOMPING_CLIP) {
1900
+ if (didReadContent) {
1901
+ state.result += "\n";
1902
+ }
1903
+ }
1904
+ break;
1905
+ }
1906
+ if (folding) {
1907
+ if (is_WHITE_SPACE(ch)) {
1908
+ atMoreIndented = true;
1909
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1910
+ } else if (atMoreIndented) {
1911
+ atMoreIndented = false;
1912
+ state.result += common.repeat("\n", emptyLines + 1);
1913
+ } else if (emptyLines === 0) {
1914
+ if (didReadContent) {
1915
+ state.result += " ";
1916
+ }
1917
+ } else {
1918
+ state.result += common.repeat("\n", emptyLines);
1919
+ }
1920
+ } else {
1921
+ state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
1922
+ }
1923
+ didReadContent = true;
1924
+ detectedIndent = true;
1925
+ emptyLines = 0;
1926
+ captureStart = state.position;
1927
+ while (!is_EOL(ch) && ch !== 0) {
1928
+ ch = state.input.charCodeAt(++state.position);
1929
+ }
1930
+ captureSegment(state, captureStart, state.position, false);
1931
+ }
1932
+ return true;
1933
+ }
1934
+ __name(readBlockScalar, "readBlockScalar");
1935
+ function readBlockSequence(state, nodeIndent) {
1936
+ var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
1937
+ if (state.firstTabInLine !== -1) return false;
1938
+ if (state.anchor !== null) {
1939
+ state.anchorMap[state.anchor] = _result;
1940
+ }
1941
+ ch = state.input.charCodeAt(state.position);
1942
+ while (ch !== 0) {
1943
+ if (state.firstTabInLine !== -1) {
1944
+ state.position = state.firstTabInLine;
1945
+ throwError(state, "tab characters must not be used in indentation");
1946
+ }
1947
+ if (ch !== 45) {
1948
+ break;
1949
+ }
1950
+ following = state.input.charCodeAt(state.position + 1);
1951
+ if (!is_WS_OR_EOL(following)) {
1952
+ break;
1953
+ }
1954
+ detected = true;
1955
+ state.position++;
1956
+ if (skipSeparationSpace(state, true, -1)) {
1957
+ if (state.lineIndent <= nodeIndent) {
1958
+ _result.push(null);
1959
+ ch = state.input.charCodeAt(state.position);
1960
+ continue;
1961
+ }
1962
+ }
1963
+ _line = state.line;
1964
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
1965
+ _result.push(state.result);
1966
+ skipSeparationSpace(state, true, -1);
1967
+ ch = state.input.charCodeAt(state.position);
1968
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
1969
+ throwError(state, "bad indentation of a sequence entry");
1970
+ } else if (state.lineIndent < nodeIndent) {
1971
+ break;
1972
+ }
1973
+ }
1974
+ if (detected) {
1975
+ state.tag = _tag;
1976
+ state.anchor = _anchor;
1977
+ state.kind = "sequence";
1978
+ state.result = _result;
1979
+ return true;
1980
+ }
1981
+ return false;
1982
+ }
1983
+ __name(readBlockSequence, "readBlockSequence");
1984
+ function readBlockMapping(state, nodeIndent, flowIndent) {
1985
+ 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;
1986
+ if (state.firstTabInLine !== -1) return false;
1987
+ if (state.anchor !== null) {
1988
+ state.anchorMap[state.anchor] = _result;
1989
+ }
1990
+ ch = state.input.charCodeAt(state.position);
1991
+ while (ch !== 0) {
1992
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
1993
+ state.position = state.firstTabInLine;
1994
+ throwError(state, "tab characters must not be used in indentation");
1995
+ }
1996
+ following = state.input.charCodeAt(state.position + 1);
1997
+ _line = state.line;
1998
+ if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
1999
+ if (ch === 63) {
2000
+ if (atExplicitKey) {
2001
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2002
+ keyTag = keyNode = valueNode = null;
2003
+ }
2004
+ detected = true;
2005
+ atExplicitKey = true;
2006
+ allowCompact = true;
2007
+ } else if (atExplicitKey) {
2008
+ atExplicitKey = false;
2009
+ allowCompact = true;
2010
+ } else {
2011
+ throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
2012
+ }
2013
+ state.position += 1;
2014
+ ch = following;
2015
+ } else {
2016
+ _keyLine = state.line;
2017
+ _keyLineStart = state.lineStart;
2018
+ _keyPos = state.position;
2019
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2020
+ break;
2021
+ }
2022
+ if (state.line === _line) {
2023
+ ch = state.input.charCodeAt(state.position);
2024
+ while (is_WHITE_SPACE(ch)) {
2025
+ ch = state.input.charCodeAt(++state.position);
2026
+ }
2027
+ if (ch === 58) {
2028
+ ch = state.input.charCodeAt(++state.position);
2029
+ if (!is_WS_OR_EOL(ch)) {
2030
+ throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
2031
+ }
2032
+ if (atExplicitKey) {
2033
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2034
+ keyTag = keyNode = valueNode = null;
2035
+ }
2036
+ detected = true;
2037
+ atExplicitKey = false;
2038
+ allowCompact = false;
2039
+ keyTag = state.tag;
2040
+ keyNode = state.result;
2041
+ } else if (detected) {
2042
+ throwError(state, "can not read an implicit mapping pair; a colon is missed");
2043
+ } else {
2044
+ state.tag = _tag;
2045
+ state.anchor = _anchor;
2046
+ return true;
2047
+ }
2048
+ } else if (detected) {
2049
+ throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
2050
+ } else {
2051
+ state.tag = _tag;
2052
+ state.anchor = _anchor;
2053
+ return true;
2054
+ }
2055
+ }
2056
+ if (state.line === _line || state.lineIndent > nodeIndent) {
2057
+ if (atExplicitKey) {
2058
+ _keyLine = state.line;
2059
+ _keyLineStart = state.lineStart;
2060
+ _keyPos = state.position;
2061
+ }
2062
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2063
+ if (atExplicitKey) {
2064
+ keyNode = state.result;
2065
+ } else {
2066
+ valueNode = state.result;
2067
+ }
2068
+ }
2069
+ if (!atExplicitKey) {
2070
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
2071
+ keyTag = keyNode = valueNode = null;
2072
+ }
2073
+ skipSeparationSpace(state, true, -1);
2074
+ ch = state.input.charCodeAt(state.position);
2075
+ }
2076
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
2077
+ throwError(state, "bad indentation of a mapping entry");
2078
+ } else if (state.lineIndent < nodeIndent) {
2079
+ break;
2080
+ }
2081
+ }
2082
+ if (atExplicitKey) {
2083
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2084
+ }
2085
+ if (detected) {
2086
+ state.tag = _tag;
2087
+ state.anchor = _anchor;
2088
+ state.kind = "mapping";
2089
+ state.result = _result;
2090
+ }
2091
+ return detected;
2092
+ }
2093
+ __name(readBlockMapping, "readBlockMapping");
2094
+ function readTagProperty(state) {
2095
+ var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
2096
+ ch = state.input.charCodeAt(state.position);
2097
+ if (ch !== 33) return false;
2098
+ if (state.tag !== null) {
2099
+ throwError(state, "duplication of a tag property");
2100
+ }
2101
+ ch = state.input.charCodeAt(++state.position);
2102
+ if (ch === 60) {
2103
+ isVerbatim = true;
2104
+ ch = state.input.charCodeAt(++state.position);
2105
+ } else if (ch === 33) {
2106
+ isNamed = true;
2107
+ tagHandle = "!!";
2108
+ ch = state.input.charCodeAt(++state.position);
2109
+ } else {
2110
+ tagHandle = "!";
2111
+ }
2112
+ _position = state.position;
2113
+ if (isVerbatim) {
2114
+ do {
2115
+ ch = state.input.charCodeAt(++state.position);
2116
+ } while (ch !== 0 && ch !== 62);
2117
+ if (state.position < state.length) {
2118
+ tagName = state.input.slice(_position, state.position);
2119
+ ch = state.input.charCodeAt(++state.position);
2120
+ } else {
2121
+ throwError(state, "unexpected end of the stream within a verbatim tag");
2122
+ }
2123
+ } else {
2124
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2125
+ if (ch === 33) {
2126
+ if (!isNamed) {
2127
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
2128
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
2129
+ throwError(state, "named tag handle cannot contain such characters");
2130
+ }
2131
+ isNamed = true;
2132
+ _position = state.position + 1;
2133
+ } else {
2134
+ throwError(state, "tag suffix cannot contain exclamation marks");
2135
+ }
2136
+ }
2137
+ ch = state.input.charCodeAt(++state.position);
2138
+ }
2139
+ tagName = state.input.slice(_position, state.position);
2140
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
2141
+ throwError(state, "tag suffix cannot contain flow indicator characters");
2142
+ }
2143
+ }
2144
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
2145
+ throwError(state, "tag name cannot contain such characters: " + tagName);
2146
+ }
2147
+ try {
2148
+ tagName = decodeURIComponent(tagName);
2149
+ } catch (err) {
2150
+ throwError(state, "tag name is malformed: " + tagName);
2151
+ }
2152
+ if (isVerbatim) {
2153
+ state.tag = tagName;
2154
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
2155
+ state.tag = state.tagMap[tagHandle] + tagName;
2156
+ } else if (tagHandle === "!") {
2157
+ state.tag = "!" + tagName;
2158
+ } else if (tagHandle === "!!") {
2159
+ state.tag = "tag:yaml.org,2002:" + tagName;
2160
+ } else {
2161
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
2162
+ }
2163
+ return true;
2164
+ }
2165
+ __name(readTagProperty, "readTagProperty");
2166
+ function readAnchorProperty(state) {
2167
+ var _position, ch;
2168
+ ch = state.input.charCodeAt(state.position);
2169
+ if (ch !== 38) return false;
2170
+ if (state.anchor !== null) {
2171
+ throwError(state, "duplication of an anchor property");
2172
+ }
2173
+ ch = state.input.charCodeAt(++state.position);
2174
+ _position = state.position;
2175
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2176
+ ch = state.input.charCodeAt(++state.position);
2177
+ }
2178
+ if (state.position === _position) {
2179
+ throwError(state, "name of an anchor node must contain at least one character");
2180
+ }
2181
+ state.anchor = state.input.slice(_position, state.position);
2182
+ return true;
2183
+ }
2184
+ __name(readAnchorProperty, "readAnchorProperty");
2185
+ function readAlias(state) {
2186
+ var _position, alias, ch;
2187
+ ch = state.input.charCodeAt(state.position);
2188
+ if (ch !== 42) return false;
2189
+ ch = state.input.charCodeAt(++state.position);
2190
+ _position = state.position;
2191
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2192
+ ch = state.input.charCodeAt(++state.position);
2193
+ }
2194
+ if (state.position === _position) {
2195
+ throwError(state, "name of an alias node must contain at least one character");
2196
+ }
2197
+ alias = state.input.slice(_position, state.position);
2198
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
2199
+ throwError(state, 'unidentified alias "' + alias + '"');
2200
+ }
2201
+ state.result = state.anchorMap[alias];
2202
+ skipSeparationSpace(state, true, -1);
2203
+ return true;
2204
+ }
2205
+ __name(readAlias, "readAlias");
2206
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
2207
+ var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
2208
+ if (state.listener !== null) {
2209
+ state.listener("open", state);
2210
+ }
2211
+ state.tag = null;
2212
+ state.anchor = null;
2213
+ state.kind = null;
2214
+ state.result = null;
2215
+ allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
2216
+ if (allowToSeek) {
2217
+ if (skipSeparationSpace(state, true, -1)) {
2218
+ atNewLine = true;
2219
+ if (state.lineIndent > parentIndent) {
2220
+ indentStatus = 1;
2221
+ } else if (state.lineIndent === parentIndent) {
2222
+ indentStatus = 0;
2223
+ } else if (state.lineIndent < parentIndent) {
2224
+ indentStatus = -1;
2225
+ }
2226
+ }
2227
+ }
2228
+ if (indentStatus === 1) {
2229
+ while (readTagProperty(state) || readAnchorProperty(state)) {
2230
+ if (skipSeparationSpace(state, true, -1)) {
2231
+ atNewLine = true;
2232
+ allowBlockCollections = allowBlockStyles;
2233
+ if (state.lineIndent > parentIndent) {
2234
+ indentStatus = 1;
2235
+ } else if (state.lineIndent === parentIndent) {
2236
+ indentStatus = 0;
2237
+ } else if (state.lineIndent < parentIndent) {
2238
+ indentStatus = -1;
2239
+ }
2240
+ } else {
2241
+ allowBlockCollections = false;
2242
+ }
2243
+ }
2244
+ }
2245
+ if (allowBlockCollections) {
2246
+ allowBlockCollections = atNewLine || allowCompact;
2247
+ }
2248
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
2249
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
2250
+ flowIndent = parentIndent;
2251
+ } else {
2252
+ flowIndent = parentIndent + 1;
2253
+ }
2254
+ blockIndent = state.position - state.lineStart;
2255
+ if (indentStatus === 1) {
2256
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
2257
+ hasContent = true;
2258
+ } else {
2259
+ if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
2260
+ hasContent = true;
2261
+ } else if (readAlias(state)) {
2262
+ hasContent = true;
2263
+ if (state.tag !== null || state.anchor !== null) {
2264
+ throwError(state, "alias node should not have any properties");
2265
+ }
2266
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
2267
+ hasContent = true;
2268
+ if (state.tag === null) {
2269
+ state.tag = "?";
2270
+ }
2271
+ }
2272
+ if (state.anchor !== null) {
2273
+ state.anchorMap[state.anchor] = state.result;
2274
+ }
2275
+ }
2276
+ } else if (indentStatus === 0) {
2277
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
2278
+ }
2279
+ }
2280
+ if (state.tag === null) {
2281
+ if (state.anchor !== null) {
2282
+ state.anchorMap[state.anchor] = state.result;
2283
+ }
2284
+ } else if (state.tag === "?") {
2285
+ if (state.result !== null && state.kind !== "scalar") {
2286
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
2287
+ }
2288
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
2289
+ type2 = state.implicitTypes[typeIndex];
2290
+ if (type2.resolve(state.result)) {
2291
+ state.result = type2.construct(state.result);
2292
+ state.tag = type2.tag;
2293
+ if (state.anchor !== null) {
2294
+ state.anchorMap[state.anchor] = state.result;
2295
+ }
2296
+ break;
2297
+ }
2298
+ }
2299
+ } else if (state.tag !== "!") {
2300
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
2301
+ type2 = state.typeMap[state.kind || "fallback"][state.tag];
2302
+ } else {
2303
+ type2 = null;
2304
+ typeList = state.typeMap.multi[state.kind || "fallback"];
2305
+ for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
2306
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
2307
+ type2 = typeList[typeIndex];
2308
+ break;
2309
+ }
2310
+ }
2311
+ }
2312
+ if (!type2) {
2313
+ throwError(state, "unknown tag !<" + state.tag + ">");
2314
+ }
2315
+ if (state.result !== null && type2.kind !== state.kind) {
2316
+ throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
2317
+ }
2318
+ if (!type2.resolve(state.result, state.tag)) {
2319
+ throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
2320
+ } else {
2321
+ state.result = type2.construct(state.result, state.tag);
2322
+ if (state.anchor !== null) {
2323
+ state.anchorMap[state.anchor] = state.result;
2324
+ }
2325
+ }
2326
+ }
2327
+ if (state.listener !== null) {
2328
+ state.listener("close", state);
2329
+ }
2330
+ return state.tag !== null || state.anchor !== null || hasContent;
2331
+ }
2332
+ __name(composeNode, "composeNode");
2333
+ function readDocument(state) {
2334
+ var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
2335
+ state.version = null;
2336
+ state.checkLineBreaks = state.legacy;
2337
+ state.tagMap = /* @__PURE__ */ Object.create(null);
2338
+ state.anchorMap = /* @__PURE__ */ Object.create(null);
2339
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2340
+ skipSeparationSpace(state, true, -1);
2341
+ ch = state.input.charCodeAt(state.position);
2342
+ if (state.lineIndent > 0 || ch !== 37) {
2343
+ break;
2344
+ }
2345
+ hasDirectives = true;
2346
+ ch = state.input.charCodeAt(++state.position);
2347
+ _position = state.position;
2348
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2349
+ ch = state.input.charCodeAt(++state.position);
2350
+ }
2351
+ directiveName = state.input.slice(_position, state.position);
2352
+ directiveArgs = [];
2353
+ if (directiveName.length < 1) {
2354
+ throwError(state, "directive name must not be less than one character in length");
2355
+ }
2356
+ while (ch !== 0) {
2357
+ while (is_WHITE_SPACE(ch)) {
2358
+ ch = state.input.charCodeAt(++state.position);
2359
+ }
2360
+ if (ch === 35) {
2361
+ do {
2362
+ ch = state.input.charCodeAt(++state.position);
2363
+ } while (ch !== 0 && !is_EOL(ch));
2364
+ break;
2365
+ }
2366
+ if (is_EOL(ch)) break;
2367
+ _position = state.position;
2368
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2369
+ ch = state.input.charCodeAt(++state.position);
2370
+ }
2371
+ directiveArgs.push(state.input.slice(_position, state.position));
2372
+ }
2373
+ if (ch !== 0) readLineBreak(state);
2374
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
2375
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
2376
+ } else {
2377
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
2378
+ }
2379
+ }
2380
+ skipSeparationSpace(state, true, -1);
2381
+ if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
2382
+ state.position += 3;
2383
+ skipSeparationSpace(state, true, -1);
2384
+ } else if (hasDirectives) {
2385
+ throwError(state, "directives end mark is expected");
2386
+ }
2387
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
2388
+ skipSeparationSpace(state, true, -1);
2389
+ if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
2390
+ throwWarning(state, "non-ASCII line breaks are interpreted as content");
2391
+ }
2392
+ state.documents.push(state.result);
2393
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
2394
+ if (state.input.charCodeAt(state.position) === 46) {
2395
+ state.position += 3;
2396
+ skipSeparationSpace(state, true, -1);
2397
+ }
2398
+ return;
2399
+ }
2400
+ if (state.position < state.length - 1) {
2401
+ throwError(state, "end of the stream or a document separator is expected");
2402
+ } else {
2403
+ return;
2404
+ }
2405
+ }
2406
+ __name(readDocument, "readDocument");
2407
+ function loadDocuments(input, options) {
2408
+ input = String(input);
2409
+ options = options || {};
2410
+ if (input.length !== 0) {
2411
+ if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
2412
+ input += "\n";
2413
+ }
2414
+ if (input.charCodeAt(0) === 65279) {
2415
+ input = input.slice(1);
2416
+ }
2417
+ }
2418
+ var state = new State$1(input, options);
2419
+ var nullpos = input.indexOf("\0");
2420
+ if (nullpos !== -1) {
2421
+ state.position = nullpos;
2422
+ throwError(state, "null byte is not allowed in input");
2423
+ }
2424
+ state.input += "\0";
2425
+ while (state.input.charCodeAt(state.position) === 32) {
2426
+ state.lineIndent += 1;
2427
+ state.position += 1;
2428
+ }
2429
+ while (state.position < state.length - 1) {
2430
+ readDocument(state);
2431
+ }
2432
+ return state.documents;
2433
+ }
2434
+ __name(loadDocuments, "loadDocuments");
2435
+ function loadAll$1(input, iterator, options) {
2436
+ if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
2437
+ options = iterator;
2438
+ iterator = null;
2439
+ }
2440
+ var documents = loadDocuments(input, options);
2441
+ if (typeof iterator !== "function") {
2442
+ return documents;
2443
+ }
2444
+ for (var index = 0, length = documents.length; index < length; index += 1) {
2445
+ iterator(documents[index]);
2446
+ }
2447
+ }
2448
+ __name(loadAll$1, "loadAll$1");
2449
+ function load$1(input, options) {
2450
+ var documents = loadDocuments(input, options);
2451
+ if (documents.length === 0) {
2452
+ return void 0;
2453
+ } else if (documents.length === 1) {
2454
+ return documents[0];
2455
+ }
2456
+ throw new exception("expected a single document in the stream, but found more");
2457
+ }
2458
+ __name(load$1, "load$1");
2459
+ var loadAll_1 = loadAll$1;
2460
+ var load_1 = load$1;
2461
+ var loader = {
2462
+ loadAll: loadAll_1,
2463
+ load: load_1
2464
+ };
2465
+ var _toString = Object.prototype.toString;
2466
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
2467
+ var CHAR_BOM = 65279;
2468
+ var CHAR_TAB = 9;
2469
+ var CHAR_LINE_FEED = 10;
2470
+ var CHAR_CARRIAGE_RETURN = 13;
2471
+ var CHAR_SPACE = 32;
2472
+ var CHAR_EXCLAMATION = 33;
2473
+ var CHAR_DOUBLE_QUOTE = 34;
2474
+ var CHAR_SHARP = 35;
2475
+ var CHAR_PERCENT = 37;
2476
+ var CHAR_AMPERSAND = 38;
2477
+ var CHAR_SINGLE_QUOTE = 39;
2478
+ var CHAR_ASTERISK = 42;
2479
+ var CHAR_COMMA = 44;
2480
+ var CHAR_MINUS = 45;
2481
+ var CHAR_COLON = 58;
2482
+ var CHAR_EQUALS = 61;
2483
+ var CHAR_GREATER_THAN = 62;
2484
+ var CHAR_QUESTION = 63;
2485
+ var CHAR_COMMERCIAL_AT = 64;
2486
+ var CHAR_LEFT_SQUARE_BRACKET = 91;
2487
+ var CHAR_RIGHT_SQUARE_BRACKET = 93;
2488
+ var CHAR_GRAVE_ACCENT = 96;
2489
+ var CHAR_LEFT_CURLY_BRACKET = 123;
2490
+ var CHAR_VERTICAL_LINE = 124;
2491
+ var CHAR_RIGHT_CURLY_BRACKET = 125;
2492
+ var ESCAPE_SEQUENCES = {};
2493
+ ESCAPE_SEQUENCES[0] = "\\0";
2494
+ ESCAPE_SEQUENCES[7] = "\\a";
2495
+ ESCAPE_SEQUENCES[8] = "\\b";
2496
+ ESCAPE_SEQUENCES[9] = "\\t";
2497
+ ESCAPE_SEQUENCES[10] = "\\n";
2498
+ ESCAPE_SEQUENCES[11] = "\\v";
2499
+ ESCAPE_SEQUENCES[12] = "\\f";
2500
+ ESCAPE_SEQUENCES[13] = "\\r";
2501
+ ESCAPE_SEQUENCES[27] = "\\e";
2502
+ ESCAPE_SEQUENCES[34] = '\\"';
2503
+ ESCAPE_SEQUENCES[92] = "\\\\";
2504
+ ESCAPE_SEQUENCES[133] = "\\N";
2505
+ ESCAPE_SEQUENCES[160] = "\\_";
2506
+ ESCAPE_SEQUENCES[8232] = "\\L";
2507
+ ESCAPE_SEQUENCES[8233] = "\\P";
2508
+ var DEPRECATED_BOOLEANS_SYNTAX = [
2509
+ "y",
2510
+ "Y",
2511
+ "yes",
2512
+ "Yes",
2513
+ "YES",
2514
+ "on",
2515
+ "On",
2516
+ "ON",
2517
+ "n",
2518
+ "N",
2519
+ "no",
2520
+ "No",
2521
+ "NO",
2522
+ "off",
2523
+ "Off",
2524
+ "OFF"
2525
+ ];
2526
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
2527
+ function compileStyleMap(schema2, map2) {
2528
+ var result, keys, index, length, tag, style, type2;
2529
+ if (map2 === null) return {};
2530
+ result = {};
2531
+ keys = Object.keys(map2);
2532
+ for (index = 0, length = keys.length; index < length; index += 1) {
2533
+ tag = keys[index];
2534
+ style = String(map2[tag]);
2535
+ if (tag.slice(0, 2) === "!!") {
2536
+ tag = "tag:yaml.org,2002:" + tag.slice(2);
2537
+ }
2538
+ type2 = schema2.compiledTypeMap["fallback"][tag];
2539
+ if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
2540
+ style = type2.styleAliases[style];
2541
+ }
2542
+ result[tag] = style;
2543
+ }
2544
+ return result;
2545
+ }
2546
+ __name(compileStyleMap, "compileStyleMap");
2547
+ function encodeHex(character) {
2548
+ var string, handle, length;
2549
+ string = character.toString(16).toUpperCase();
2550
+ if (character <= 255) {
2551
+ handle = "x";
2552
+ length = 2;
2553
+ } else if (character <= 65535) {
2554
+ handle = "u";
2555
+ length = 4;
2556
+ } else if (character <= 4294967295) {
2557
+ handle = "U";
2558
+ length = 8;
2559
+ } else {
2560
+ throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
2561
+ }
2562
+ return "\\" + handle + common.repeat("0", length - string.length) + string;
2563
+ }
2564
+ __name(encodeHex, "encodeHex");
2565
+ var QUOTING_TYPE_SINGLE = 1;
2566
+ var QUOTING_TYPE_DOUBLE = 2;
2567
+ function State(options) {
2568
+ this.schema = options["schema"] || _default;
2569
+ this.indent = Math.max(1, options["indent"] || 2);
2570
+ this.noArrayIndent = options["noArrayIndent"] || false;
2571
+ this.skipInvalid = options["skipInvalid"] || false;
2572
+ this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
2573
+ this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
2574
+ this.sortKeys = options["sortKeys"] || false;
2575
+ this.lineWidth = options["lineWidth"] || 80;
2576
+ this.noRefs = options["noRefs"] || false;
2577
+ this.noCompatMode = options["noCompatMode"] || false;
2578
+ this.condenseFlow = options["condenseFlow"] || false;
2579
+ this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
2580
+ this.forceQuotes = options["forceQuotes"] || false;
2581
+ this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
2582
+ this.implicitTypes = this.schema.compiledImplicit;
2583
+ this.explicitTypes = this.schema.compiledExplicit;
2584
+ this.tag = null;
2585
+ this.result = "";
2586
+ this.duplicates = [];
2587
+ this.usedDuplicates = null;
2588
+ }
2589
+ __name(State, "State");
2590
+ function indentString(string, spaces) {
2591
+ var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
2592
+ while (position < length) {
2593
+ next = string.indexOf("\n", position);
2594
+ if (next === -1) {
2595
+ line = string.slice(position);
2596
+ position = length;
2597
+ } else {
2598
+ line = string.slice(position, next + 1);
2599
+ position = next + 1;
2600
+ }
2601
+ if (line.length && line !== "\n") result += ind;
2602
+ result += line;
2603
+ }
2604
+ return result;
2605
+ }
2606
+ __name(indentString, "indentString");
2607
+ function generateNextLine(state, level) {
2608
+ return "\n" + common.repeat(" ", state.indent * level);
2609
+ }
2610
+ __name(generateNextLine, "generateNextLine");
2611
+ function testImplicitResolving(state, str2) {
2612
+ var index, length, type2;
2613
+ for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
2614
+ type2 = state.implicitTypes[index];
2615
+ if (type2.resolve(str2)) {
2616
+ return true;
2617
+ }
2618
+ }
2619
+ return false;
2620
+ }
2621
+ __name(testImplicitResolving, "testImplicitResolving");
2622
+ function isWhitespace(c) {
2623
+ return c === CHAR_SPACE || c === CHAR_TAB;
2624
+ }
2625
+ __name(isWhitespace, "isWhitespace");
2626
+ function isPrintable(c) {
2627
+ return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
2628
+ }
2629
+ __name(isPrintable, "isPrintable");
2630
+ function isNsCharOrWhitespace(c) {
2631
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
2632
+ }
2633
+ __name(isNsCharOrWhitespace, "isNsCharOrWhitespace");
2634
+ function isPlainSafe(c, prev, inblock) {
2635
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
2636
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
2637
+ return (
2638
+ // ns-plain-safe
2639
+ (inblock ? (
2640
+ // c = flow-in
2641
+ cIsNsCharOrWhitespace
2642
+ ) : 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
2643
+ );
2644
+ }
2645
+ __name(isPlainSafe, "isPlainSafe");
2646
+ function isPlainSafeFirst(c) {
2647
+ 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;
2648
+ }
2649
+ __name(isPlainSafeFirst, "isPlainSafeFirst");
2650
+ function isPlainSafeLast(c) {
2651
+ return !isWhitespace(c) && c !== CHAR_COLON;
2652
+ }
2653
+ __name(isPlainSafeLast, "isPlainSafeLast");
2654
+ function codePointAt(string, pos) {
2655
+ var first = string.charCodeAt(pos), second;
2656
+ if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
2657
+ second = string.charCodeAt(pos + 1);
2658
+ if (second >= 56320 && second <= 57343) {
2659
+ return (first - 55296) * 1024 + second - 56320 + 65536;
2660
+ }
2661
+ }
2662
+ return first;
2663
+ }
2664
+ __name(codePointAt, "codePointAt");
2665
+ function needIndentIndicator(string) {
2666
+ var leadingSpaceRe = /^\n* /;
2667
+ return leadingSpaceRe.test(string);
2668
+ }
2669
+ __name(needIndentIndicator, "needIndentIndicator");
2670
+ var STYLE_PLAIN = 1;
2671
+ var STYLE_SINGLE = 2;
2672
+ var STYLE_LITERAL = 3;
2673
+ var STYLE_FOLDED = 4;
2674
+ var STYLE_DOUBLE = 5;
2675
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
2676
+ var i;
2677
+ var char = 0;
2678
+ var prevChar = null;
2679
+ var hasLineBreak = false;
2680
+ var hasFoldableLine = false;
2681
+ var shouldTrackWidth = lineWidth !== -1;
2682
+ var previousLineBreak = -1;
2683
+ var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
2684
+ if (singleLineOnly || forceQuotes) {
2685
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2686
+ char = codePointAt(string, i);
2687
+ if (!isPrintable(char)) {
2688
+ return STYLE_DOUBLE;
2689
+ }
2690
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2691
+ prevChar = char;
2692
+ }
2693
+ } else {
2694
+ for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2695
+ char = codePointAt(string, i);
2696
+ if (char === CHAR_LINE_FEED) {
2697
+ hasLineBreak = true;
2698
+ if (shouldTrackWidth) {
2699
+ hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
2700
+ i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2701
+ previousLineBreak = i;
2702
+ }
2703
+ } else if (!isPrintable(char)) {
2704
+ return STYLE_DOUBLE;
2705
+ }
2706
+ plain = plain && isPlainSafe(char, prevChar, inblock);
2707
+ prevChar = char;
2708
+ }
2709
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
2710
+ }
2711
+ if (!hasLineBreak && !hasFoldableLine) {
2712
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
2713
+ return STYLE_PLAIN;
2714
+ }
2715
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2716
+ }
2717
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
2718
+ return STYLE_DOUBLE;
2719
+ }
2720
+ if (!forceQuotes) {
2721
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
2722
+ }
2723
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
2724
+ }
2725
+ __name(chooseScalarStyle, "chooseScalarStyle");
2726
+ function writeScalar(state, string, level, iskey, inblock) {
2727
+ state.dump = (function() {
2728
+ if (string.length === 0) {
2729
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
2730
+ }
2731
+ if (!state.noCompatMode) {
2732
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
2733
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
2734
+ }
2735
+ }
2736
+ var indent = state.indent * Math.max(1, level);
2737
+ var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
2738
+ var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
2739
+ function testAmbiguity(string2) {
2740
+ return testImplicitResolving(state, string2);
2741
+ }
2742
+ __name(testAmbiguity, "testAmbiguity");
2743
+ switch (chooseScalarStyle(
2744
+ string,
2745
+ singleLineOnly,
2746
+ state.indent,
2747
+ lineWidth,
2748
+ testAmbiguity,
2749
+ state.quotingType,
2750
+ state.forceQuotes && !iskey,
2751
+ inblock
2752
+ )) {
2753
+ case STYLE_PLAIN:
2754
+ return string;
2755
+ case STYLE_SINGLE:
2756
+ return "'" + string.replace(/'/g, "''") + "'";
2757
+ case STYLE_LITERAL:
2758
+ return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
2759
+ case STYLE_FOLDED:
2760
+ return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
2761
+ case STYLE_DOUBLE:
2762
+ return '"' + escapeString2(string) + '"';
2763
+ default:
2764
+ throw new exception("impossible error: invalid scalar style");
2765
+ }
2766
+ })();
2767
+ }
2768
+ __name(writeScalar, "writeScalar");
2769
+ function blockHeader(string, indentPerLevel) {
2770
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
2771
+ var clip = string[string.length - 1] === "\n";
2772
+ var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
2773
+ var chomp = keep ? "+" : clip ? "" : "-";
2774
+ return indentIndicator + chomp + "\n";
2775
+ }
2776
+ __name(blockHeader, "blockHeader");
2777
+ function dropEndingNewline(string) {
2778
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2779
+ }
2780
+ __name(dropEndingNewline, "dropEndingNewline");
2781
+ function foldString(string, width) {
2782
+ var lineRe = /(\n+)([^\n]*)/g;
2783
+ var result = (function() {
2784
+ var nextLF = string.indexOf("\n");
2785
+ nextLF = nextLF !== -1 ? nextLF : string.length;
2786
+ lineRe.lastIndex = nextLF;
2787
+ return foldLine(string.slice(0, nextLF), width);
2788
+ })();
2789
+ var prevMoreIndented = string[0] === "\n" || string[0] === " ";
2790
+ var moreIndented;
2791
+ var match;
2792
+ while (match = lineRe.exec(string)) {
2793
+ var prefix = match[1], line = match[2];
2794
+ moreIndented = line[0] === " ";
2795
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2796
+ prevMoreIndented = moreIndented;
2797
+ }
2798
+ return result;
2799
+ }
2800
+ __name(foldString, "foldString");
2801
+ function foldLine(line, width) {
2802
+ if (line === "" || line[0] === " ") return line;
2803
+ var breakRe = / [^ ]/g;
2804
+ var match;
2805
+ var start = 0, end, curr = 0, next = 0;
2806
+ var result = "";
2807
+ while (match = breakRe.exec(line)) {
2808
+ next = match.index;
2809
+ if (next - start > width) {
2810
+ end = curr > start ? curr : next;
2811
+ result += "\n" + line.slice(start, end);
2812
+ start = end + 1;
2813
+ }
2814
+ curr = next;
2815
+ }
2816
+ result += "\n";
2817
+ if (line.length - start > width && curr > start) {
2818
+ result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
2819
+ } else {
2820
+ result += line.slice(start);
2821
+ }
2822
+ return result.slice(1);
2823
+ }
2824
+ __name(foldLine, "foldLine");
2825
+ function escapeString2(string) {
2826
+ var result = "";
2827
+ var char = 0;
2828
+ var escapeSeq;
2829
+ for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
2830
+ char = codePointAt(string, i);
2831
+ escapeSeq = ESCAPE_SEQUENCES[char];
2832
+ if (!escapeSeq && isPrintable(char)) {
2833
+ result += string[i];
2834
+ if (char >= 65536) result += string[i + 1];
2835
+ } else {
2836
+ result += escapeSeq || encodeHex(char);
2837
+ }
2838
+ }
2839
+ return result;
2840
+ }
2841
+ __name(escapeString2, "escapeString");
2842
+ function writeFlowSequence(state, level, object) {
2843
+ var _result = "", _tag = state.tag, index, length, value;
2844
+ for (index = 0, length = object.length; index < length; index += 1) {
2845
+ value = object[index];
2846
+ if (state.replacer) {
2847
+ value = state.replacer.call(object, String(index), value);
2848
+ }
2849
+ if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
2850
+ if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
2851
+ _result += state.dump;
2852
+ }
2853
+ }
2854
+ state.tag = _tag;
2855
+ state.dump = "[" + _result + "]";
2856
+ }
2857
+ __name(writeFlowSequence, "writeFlowSequence");
2858
+ function writeBlockSequence(state, level, object, compact) {
2859
+ var _result = "", _tag = state.tag, index, length, value;
2860
+ for (index = 0, length = object.length; index < length; index += 1) {
2861
+ value = object[index];
2862
+ if (state.replacer) {
2863
+ value = state.replacer.call(object, String(index), value);
2864
+ }
2865
+ if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
2866
+ if (!compact || _result !== "") {
2867
+ _result += generateNextLine(state, level);
2868
+ }
2869
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2870
+ _result += "-";
2871
+ } else {
2872
+ _result += "- ";
2873
+ }
2874
+ _result += state.dump;
2875
+ }
2876
+ }
2877
+ state.tag = _tag;
2878
+ state.dump = _result || "[]";
2879
+ }
2880
+ __name(writeBlockSequence, "writeBlockSequence");
2881
+ function writeFlowMapping(state, level, object) {
2882
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
2883
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2884
+ pairBuffer = "";
2885
+ if (_result !== "") pairBuffer += ", ";
2886
+ if (state.condenseFlow) pairBuffer += '"';
2887
+ objectKey = objectKeyList[index];
2888
+ objectValue = object[objectKey];
2889
+ if (state.replacer) {
2890
+ objectValue = state.replacer.call(object, objectKey, objectValue);
2891
+ }
2892
+ if (!writeNode(state, level, objectKey, false, false)) {
2893
+ continue;
2894
+ }
2895
+ if (state.dump.length > 1024) pairBuffer += "? ";
2896
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
2897
+ if (!writeNode(state, level, objectValue, false, false)) {
2898
+ continue;
2899
+ }
2900
+ pairBuffer += state.dump;
2901
+ _result += pairBuffer;
2902
+ }
2903
+ state.tag = _tag;
2904
+ state.dump = "{" + _result + "}";
2905
+ }
2906
+ __name(writeFlowMapping, "writeFlowMapping");
2907
+ function writeBlockMapping(state, level, object, compact) {
2908
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
2909
+ if (state.sortKeys === true) {
2910
+ objectKeyList.sort();
2911
+ } else if (typeof state.sortKeys === "function") {
2912
+ objectKeyList.sort(state.sortKeys);
2913
+ } else if (state.sortKeys) {
2914
+ throw new exception("sortKeys must be a boolean or a function");
2915
+ }
2916
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
2917
+ pairBuffer = "";
2918
+ if (!compact || _result !== "") {
2919
+ pairBuffer += generateNextLine(state, level);
2920
+ }
2921
+ objectKey = objectKeyList[index];
2922
+ objectValue = object[objectKey];
2923
+ if (state.replacer) {
2924
+ objectValue = state.replacer.call(object, objectKey, objectValue);
2925
+ }
2926
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
2927
+ continue;
2928
+ }
2929
+ explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
2930
+ if (explicitPair) {
2931
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2932
+ pairBuffer += "?";
2933
+ } else {
2934
+ pairBuffer += "? ";
2935
+ }
2936
+ }
2937
+ pairBuffer += state.dump;
2938
+ if (explicitPair) {
2939
+ pairBuffer += generateNextLine(state, level);
2940
+ }
2941
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
2942
+ continue;
2943
+ }
2944
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
2945
+ pairBuffer += ":";
2946
+ } else {
2947
+ pairBuffer += ": ";
2948
+ }
2949
+ pairBuffer += state.dump;
2950
+ _result += pairBuffer;
2951
+ }
2952
+ state.tag = _tag;
2953
+ state.dump = _result || "{}";
2954
+ }
2955
+ __name(writeBlockMapping, "writeBlockMapping");
2956
+ function detectType(state, object, explicit) {
2957
+ var _result, typeList, index, length, type2, style;
2958
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
2959
+ for (index = 0, length = typeList.length; index < length; index += 1) {
2960
+ type2 = typeList[index];
2961
+ if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
2962
+ if (explicit) {
2963
+ if (type2.multi && type2.representName) {
2964
+ state.tag = type2.representName(object);
2965
+ } else {
2966
+ state.tag = type2.tag;
2967
+ }
2968
+ } else {
2969
+ state.tag = "?";
2970
+ }
2971
+ if (type2.represent) {
2972
+ style = state.styleMap[type2.tag] || type2.defaultStyle;
2973
+ if (_toString.call(type2.represent) === "[object Function]") {
2974
+ _result = type2.represent(object, style);
2975
+ } else if (_hasOwnProperty.call(type2.represent, style)) {
2976
+ _result = type2.represent[style](object, style);
2977
+ } else {
2978
+ throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
2979
+ }
2980
+ state.dump = _result;
2981
+ }
2982
+ return true;
2983
+ }
2984
+ }
2985
+ return false;
2986
+ }
2987
+ __name(detectType, "detectType");
2988
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
2989
+ state.tag = null;
2990
+ state.dump = object;
2991
+ if (!detectType(state, object, false)) {
2992
+ detectType(state, object, true);
2993
+ }
2994
+ var type2 = _toString.call(state.dump);
2995
+ var inblock = block;
2996
+ var tagStr;
2997
+ if (block) {
2998
+ block = state.flowLevel < 0 || state.flowLevel > level;
2999
+ }
3000
+ var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
3001
+ if (objectOrArray) {
3002
+ duplicateIndex = state.duplicates.indexOf(object);
3003
+ duplicate = duplicateIndex !== -1;
3004
+ }
3005
+ if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
3006
+ compact = false;
3007
+ }
3008
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
3009
+ state.dump = "*ref_" + duplicateIndex;
3010
+ } else {
3011
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
3012
+ state.usedDuplicates[duplicateIndex] = true;
3013
+ }
3014
+ if (type2 === "[object Object]") {
3015
+ if (block && Object.keys(state.dump).length !== 0) {
3016
+ writeBlockMapping(state, level, state.dump, compact);
3017
+ if (duplicate) {
3018
+ state.dump = "&ref_" + duplicateIndex + state.dump;
3019
+ }
3020
+ } else {
3021
+ writeFlowMapping(state, level, state.dump);
3022
+ if (duplicate) {
3023
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
3024
+ }
3025
+ }
3026
+ } else if (type2 === "[object Array]") {
3027
+ if (block && state.dump.length !== 0) {
3028
+ if (state.noArrayIndent && !isblockseq && level > 0) {
3029
+ writeBlockSequence(state, level - 1, state.dump, compact);
3030
+ } else {
3031
+ writeBlockSequence(state, level, state.dump, compact);
3032
+ }
3033
+ if (duplicate) {
3034
+ state.dump = "&ref_" + duplicateIndex + state.dump;
3035
+ }
3036
+ } else {
3037
+ writeFlowSequence(state, level, state.dump);
3038
+ if (duplicate) {
3039
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
3040
+ }
3041
+ }
3042
+ } else if (type2 === "[object String]") {
3043
+ if (state.tag !== "?") {
3044
+ writeScalar(state, state.dump, level, iskey, inblock);
3045
+ }
3046
+ } else if (type2 === "[object Undefined]") {
3047
+ return false;
3048
+ } else {
3049
+ if (state.skipInvalid) return false;
3050
+ throw new exception("unacceptable kind of an object to dump " + type2);
3051
+ }
3052
+ if (state.tag !== null && state.tag !== "?") {
3053
+ tagStr = encodeURI(
3054
+ state.tag[0] === "!" ? state.tag.slice(1) : state.tag
3055
+ ).replace(/!/g, "%21");
3056
+ if (state.tag[0] === "!") {
3057
+ tagStr = "!" + tagStr;
3058
+ } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
3059
+ tagStr = "!!" + tagStr.slice(18);
3060
+ } else {
3061
+ tagStr = "!<" + tagStr + ">";
3062
+ }
3063
+ state.dump = tagStr + " " + state.dump;
3064
+ }
3065
+ }
3066
+ return true;
3067
+ }
3068
+ __name(writeNode, "writeNode");
3069
+ function getDuplicateReferences(object, state) {
3070
+ var objects = [], duplicatesIndexes = [], index, length;
3071
+ inspectNode(object, objects, duplicatesIndexes);
3072
+ for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
3073
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
3074
+ }
3075
+ state.usedDuplicates = new Array(length);
3076
+ }
3077
+ __name(getDuplicateReferences, "getDuplicateReferences");
3078
+ function inspectNode(object, objects, duplicatesIndexes) {
3079
+ var objectKeyList, index, length;
3080
+ if (object !== null && typeof object === "object") {
3081
+ index = objects.indexOf(object);
3082
+ if (index !== -1) {
3083
+ if (duplicatesIndexes.indexOf(index) === -1) {
3084
+ duplicatesIndexes.push(index);
3085
+ }
3086
+ } else {
3087
+ objects.push(object);
3088
+ if (Array.isArray(object)) {
3089
+ for (index = 0, length = object.length; index < length; index += 1) {
3090
+ inspectNode(object[index], objects, duplicatesIndexes);
3091
+ }
3092
+ } else {
3093
+ objectKeyList = Object.keys(object);
3094
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
3095
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
3096
+ }
3097
+ }
3098
+ }
3099
+ }
3100
+ }
3101
+ __name(inspectNode, "inspectNode");
3102
+ function dump$1(input, options) {
3103
+ options = options || {};
3104
+ var state = new State(options);
3105
+ if (!state.noRefs) getDuplicateReferences(input, state);
3106
+ var value = input;
3107
+ if (state.replacer) {
3108
+ value = state.replacer.call({ "": value }, "", value);
3109
+ }
3110
+ if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
3111
+ return "";
3112
+ }
3113
+ __name(dump$1, "dump$1");
3114
+ var dump_1 = dump$1;
3115
+ var dumper = {
3116
+ dump: dump_1
3117
+ };
3118
+ function renamed(from, to) {
3119
+ return function() {
3120
+ throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
3121
+ };
3122
+ }
3123
+ __name(renamed, "renamed");
3124
+ var load = loader.load;
3125
+ var loadAll = loader.loadAll;
3126
+ var dump = dumper.dump;
3127
+ var safeLoad = renamed("safeLoad", "load");
3128
+ var safeLoadAll = renamed("safeLoadAll", "loadAll");
3129
+ var safeDump = renamed("safeDump", "dump");
3130
+
3131
+ // ../../shared/src/core/swagger-parser.ts
3132
+ var SwaggerParser = class _SwaggerParser {
3133
+ static {
3134
+ __name(this, "SwaggerParser");
3135
+ }
3136
+ spec;
3137
+ constructor(spec, config) {
3138
+ const isInputValid = config.validateInput?.(spec) ?? true;
3139
+ if (!isInputValid) {
3140
+ throw new Error("Swagger spec is not valid. Check your `validateInput` condition.");
3141
+ }
3142
+ this.spec = spec;
3143
+ }
3144
+ static async create(swaggerPathOrUrl, config) {
3145
+ const swaggerContent = await _SwaggerParser.loadContent(swaggerPathOrUrl);
3146
+ const spec = _SwaggerParser.parseSpecContent(swaggerContent, swaggerPathOrUrl);
3147
+ return new _SwaggerParser(spec, config);
3148
+ }
3149
+ static async loadContent(pathOrUrl) {
3150
+ if (_SwaggerParser.isUrl(pathOrUrl)) {
3151
+ return await _SwaggerParser.fetchUrlContent(pathOrUrl);
3152
+ } else {
3153
+ return fs.readFileSync(pathOrUrl, "utf8");
3154
+ }
3155
+ }
3156
+ static isUrl(input) {
3157
+ try {
3158
+ new URL(input);
3159
+ return true;
3160
+ } catch {
3161
+ return false;
3162
+ }
3163
+ }
3164
+ static async fetchUrlContent(url) {
3165
+ try {
3166
+ const response = await fetch(url, {
3167
+ method: "GET",
3168
+ headers: {
3169
+ Accept: "application/json, application/yaml, text/yaml, text/plain, */*",
3170
+ "User-Agent": "ng-openapi"
3171
+ },
3172
+ // 30 second timeout
3173
+ signal: AbortSignal.timeout(3e4)
3174
+ });
3175
+ if (!response.ok) {
3176
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
3177
+ }
3178
+ const content = await response.text();
3179
+ if (!content || content.trim() === "") {
3180
+ throw new Error(`Empty response from URL: ${url}`);
3181
+ }
3182
+ return content;
3183
+ } catch (error) {
3184
+ let errorMessage = `Failed to fetch content from URL: ${url}`;
3185
+ if (error.name === "AbortError") {
3186
+ errorMessage += " - Request timeout (30s)";
3187
+ } else if (error.message) {
3188
+ errorMessage += ` - ${error.message}`;
3189
+ }
3190
+ throw new Error(errorMessage);
3191
+ }
3192
+ }
3193
+ static parseSpecContent(content, pathOrUrl) {
3194
+ let format;
3195
+ if (_SwaggerParser.isUrl(pathOrUrl)) {
3196
+ const urlPath = new URL(pathOrUrl).pathname.toLowerCase();
3197
+ if (urlPath.endsWith(".json")) {
3198
+ format = "json";
3199
+ } else if (urlPath.endsWith(".yaml") || urlPath.endsWith(".yml")) {
3200
+ format = "yaml";
3201
+ } else {
3202
+ format = _SwaggerParser.detectFormat(content);
3203
+ }
3204
+ } else {
3205
+ const extension = path.extname(pathOrUrl).toLowerCase();
3206
+ switch (extension) {
3207
+ case ".json":
3208
+ format = "json";
3209
+ break;
3210
+ case ".yaml":
3211
+ format = "yaml";
3212
+ break;
3213
+ case ".yml":
3214
+ format = "yml";
3215
+ break;
3216
+ default:
3217
+ format = _SwaggerParser.detectFormat(content);
3218
+ }
3219
+ }
3220
+ try {
3221
+ switch (format) {
3222
+ case "json":
3223
+ return JSON.parse(content);
3224
+ case "yaml":
3225
+ case "yml":
3226
+ return load(content);
3227
+ default:
3228
+ throw new Error(`Unable to determine format for: ${pathOrUrl}`);
3229
+ }
3230
+ } catch (error) {
3231
+ throw new Error(`Failed to parse ${format.toUpperCase()} content from: ${pathOrUrl}. Error: ${error instanceof Error ? error.message : error}`);
3232
+ }
3233
+ }
3234
+ static detectFormat(content) {
3235
+ const trimmed = content.trim();
3236
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
3237
+ return "json";
3238
+ }
3239
+ if (trimmed.includes("openapi:") || trimmed.includes("swagger:") || trimmed.includes("---") || /^[a-zA-Z][a-zA-Z0-9_]*\s*:/.test(trimmed)) {
3240
+ return "yaml";
3241
+ }
3242
+ return "json";
3243
+ }
3244
+ getDefinitions() {
3245
+ return this.spec.definitions || this.spec.components?.schemas || {};
3246
+ }
3247
+ getDefinition(name) {
3248
+ const definitions = this.getDefinitions();
3249
+ return definitions[name];
3250
+ }
3251
+ resolveReference(ref) {
3252
+ const parts = ref.split("/");
3253
+ const definitionName = parts[parts.length - 1];
3254
+ return this.getDefinition(definitionName);
3255
+ }
3256
+ getAllDefinitionNames() {
3257
+ return Object.keys(this.getDefinitions());
3258
+ }
3259
+ getSpec() {
3260
+ return this.spec;
3261
+ }
3262
+ getPaths() {
3263
+ return this.spec.paths || {};
3264
+ }
3265
+ isValidSpec() {
3266
+ return !!(this.spec.swagger && this.spec.swagger.startsWith("2.") || this.spec.openapi && this.spec.openapi.startsWith("3."));
3267
+ }
3268
+ getSpecVersion() {
3269
+ if (this.spec.swagger) {
3270
+ return {
3271
+ type: "swagger",
3272
+ version: this.spec.swagger
3273
+ };
3274
+ }
3275
+ if (this.spec.openapi) {
3276
+ return {
3277
+ type: "openapi",
3278
+ version: this.spec.openapi
3279
+ };
3280
+ }
3281
+ return null;
3282
+ }
3283
+ };
3284
+
3285
+ // src/lib/http-resource.generator.ts
3286
+ var path3 = __toESM(require("path"), 1);
3287
+
3288
+ // src/lib/http-resource-method/http-resource-method-body.generator.ts
3289
+ var HttpResourceMethodBodyGenerator = class {
3290
+ static {
3291
+ __name(this, "HttpResourceMethodBodyGenerator");
3292
+ }
3293
+ config;
3294
+ constructor(config) {
3295
+ this.config = config;
3296
+ }
3297
+ generateMethodBody(operation) {
3298
+ const context = this.createGenerationContext(operation);
3299
+ const bodyParts = [
3300
+ this.generateHeaders(context),
3301
+ this.generateHttpResource(operation, context)
3302
+ ];
3303
+ return bodyParts.filter(Boolean).join("\n");
3304
+ }
3305
+ createGenerationContext(operation) {
3306
+ return {
3307
+ pathParams: operation.parameters?.filter((p) => p.in === "path") || [],
3308
+ queryParams: operation.parameters?.filter((p) => p.in === "query") || [],
3309
+ responseType: this.determineResponseType(operation)
3310
+ };
3311
+ }
3312
+ generateUrl(operation, context) {
3313
+ let urlExpression = `\`\${this.basePath}${operation.path}\``;
3314
+ if (context.pathParams.length > 0) {
3315
+ context.pathParams.forEach((param) => {
3316
+ urlExpression = urlExpression.replace(`{${param.name}}`, `\${typeof ${param.name} === 'function' ? ${param.name}() : ${param.name}}`);
3317
+ });
3318
+ }
3319
+ return urlExpression;
3320
+ }
3321
+ generateQueryParams(context) {
3322
+ if (context.queryParams.length === 0) {
3323
+ return "";
3324
+ }
3325
+ const paramMappings = context.queryParams.map((param) => `const ${param.name}Value = typeof ${param.name} === 'function' ? ${param.name}() : ${param.name};
3326
+ if (${param.name}Value !== undefined) {
3327
+ params = params.set('${param.name}', String(${param.name}Value));
3328
+ }`).join("\n");
3329
+ return `
3330
+ let params = new HttpParams();
3331
+ ${paramMappings}`;
3332
+ }
3333
+ generateHeaders(context) {
3334
+ const hasCustomHeaders = this.config.options.customHeaders;
3335
+ if (!hasCustomHeaders) {
3336
+ return "";
3337
+ }
3338
+ let headerCode = `
3339
+ let headers: HttpHeaders;
3340
+ if (requestOptions?.headers instanceof HttpHeaders) {
3341
+ headers = requestOptions.headers;
3342
+ } else {
3343
+ headers = new HttpHeaders(requestOptions?.headers as Record<string, string>);
3344
+ }`;
3345
+ if (hasCustomHeaders) {
3346
+ headerCode += `
3347
+ // Add default headers if not already present
3348
+ ${Object.entries(this.config.options.customHeaders || {}).map(([key, value]) => `if (!headers.has('${key}')) {
3349
+ headers = headers.set('${key}', '${value}');
3350
+ }`).join("\n")}`;
3351
+ }
3352
+ return headerCode;
3353
+ }
3354
+ generateRequestOptions(operation, context) {
3355
+ const options = [];
3356
+ const url = this.generateUrl(operation, context);
3357
+ options.push(`url: ${url}`);
3358
+ options.push(`method: "GET"`);
3359
+ if (context.queryParams.length > 0) {
3360
+ options.push("params");
3361
+ }
3362
+ const hasHeaders = this.config.options.customHeaders;
3363
+ if (hasHeaders) {
3364
+ options.push("headers");
3365
+ }
3366
+ if (context.responseType !== "json") {
3367
+ options.push(`responseType: '${context.responseType}' as '${context.responseType}'`);
3368
+ }
3369
+ options.push("context: this.createContextWithClientId(requestOptions?.context)");
3370
+ const formattedOptions = options.filter((opt) => opt && !opt.includes("undefined")).join(",\n ");
3371
+ return `return {
3372
+ ${formattedOptions},
3373
+ ...requestOptions
3374
+ }`;
3375
+ }
3376
+ generateHttpResource(operation, context) {
3377
+ const resourceOptions = this.generateRequestOptions(operation, context);
3378
+ const queryParams = this.generateQueryParams(context);
3379
+ let httpResource = "httpResource";
3380
+ switch (context.responseType) {
3381
+ case "blob":
3382
+ httpResource += ".blob";
3383
+ break;
3384
+ case "arraybuffer":
3385
+ httpResource += ".arrayBuffer";
3386
+ break;
3387
+ case "text":
3388
+ httpResource += ".text";
3389
+ break;
3390
+ }
3391
+ return ` return ${httpResource}(() => {${queryParams}
3392
+ ${resourceOptions}
3393
+ }, resourceOptions);`;
3394
+ }
3395
+ determineResponseType(operation) {
3396
+ const successResponses = [
3397
+ "200",
3398
+ "201",
3399
+ "202",
3400
+ "204",
3401
+ "206"
3402
+ ];
3403
+ for (const statusCode of successResponses) {
3404
+ const response = operation.responses?.[statusCode];
3405
+ if (!response) continue;
3406
+ return getResponseTypeFromResponse(response);
3407
+ }
3408
+ return "json";
3409
+ }
3410
+ };
3411
+
3412
+ // src/lib/http-resource-method/http-resource-method-params.generator.ts
3413
+ var HttpResourceMethodParamsGenerator = class {
3414
+ static {
3415
+ __name(this, "HttpResourceMethodParamsGenerator");
3416
+ }
3417
+ config;
3418
+ constructor(config) {
3419
+ this.config = config;
3420
+ }
3421
+ generateMethodParameters(operation) {
3422
+ const params = this.generateApiParameters(operation);
3423
+ const responseType = this.getApiReturnType(operation);
3424
+ const optionsParam = this.addOptionsParameter(responseType);
3425
+ const combined = [
3426
+ ...params,
3427
+ ...optionsParam
3428
+ ];
3429
+ const seen = /* @__PURE__ */ new Set();
3430
+ const uniqueParams = [];
3431
+ for (const param of combined) {
3432
+ if (!seen.has(param.name)) {
3433
+ seen.add(param.name);
3434
+ uniqueParams.push(param);
3435
+ }
3436
+ }
3437
+ return uniqueParams;
3438
+ }
3439
+ generateApiParameters(operation) {
3440
+ const params = [];
3441
+ const pathParams = operation.parameters?.filter((p) => p.in === "path") || [];
3442
+ pathParams.forEach((param) => {
3443
+ const paramType = getTypeScriptType(param.schema || param, this.config);
3444
+ const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
3445
+ params.push({
3446
+ name: param.name,
3447
+ type: `${signalParamType} | ${paramType}`,
3448
+ hasQuestionToken: !param.required
3449
+ });
3450
+ });
3451
+ const queryParams = operation.parameters?.filter((p) => p.in === "query") || [];
3452
+ queryParams.forEach((param) => {
3453
+ const paramType = getTypeScriptType(param.schema || param, this.config);
3454
+ const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
3455
+ params.push({
3456
+ name: param.name,
3457
+ type: `${signalParamType} | ${paramType}`,
3458
+ hasQuestionToken: !param.required
3459
+ });
3460
+ });
3461
+ return params.sort((a, b) => Number(a.hasQuestionToken) - Number(b.hasQuestionToken));
3462
+ }
3463
+ addOptionsParameter(responseType) {
3464
+ const rawDataType = this.getResourceRawDataType(responseType);
3465
+ return [
3466
+ {
3467
+ name: "resourceOptions",
3468
+ type: `HttpResourceOptions<${responseType}, ${rawDataType}>`,
3469
+ hasQuestionToken: true
3470
+ },
3471
+ {
3472
+ name: "requestOptions",
3473
+ type: `Omit<HttpResourceRequest, "method" | "url" | "params">`,
3474
+ hasQuestionToken: true
3475
+ }
3476
+ ];
3477
+ }
3478
+ getApiReturnType(operation) {
3479
+ const successResponses = [
3480
+ "200",
3481
+ "201",
3482
+ "202",
3483
+ "204",
3484
+ "206"
3485
+ ];
3486
+ for (const statusCode of successResponses) {
3487
+ const response = operation.responses?.[statusCode];
3488
+ if (!response) continue;
3489
+ return getResponseType(response, this.config);
3490
+ }
3491
+ return "unknown";
3492
+ }
3493
+ getResourceRawDataType(responseType) {
3494
+ if (responseType !== "Blob" && responseType !== "ArrayBuffer" && responseType !== "string") {
3495
+ return "unknown";
3496
+ }
3497
+ return responseType;
3498
+ }
3499
+ };
3500
+
3501
+ // src/lib/http-resource-method.generator.ts
3502
+ var HttpResourceMethodGenerator = class {
3503
+ static {
3504
+ __name(this, "HttpResourceMethodGenerator");
3505
+ }
3506
+ config;
3507
+ bodyGenerator;
3508
+ paramsGenerator;
3509
+ #responseType = "unknown";
3510
+ constructor(config) {
3511
+ this.config = config;
3512
+ this.bodyGenerator = new HttpResourceMethodBodyGenerator(config);
3513
+ this.paramsGenerator = new HttpResourceMethodParamsGenerator(config);
3514
+ }
3515
+ addResourceMethod(serviceClass, operation) {
3516
+ const methodName = this.generateMethodName(operation);
3517
+ const parameters = this.paramsGenerator.generateMethodParameters(operation);
3518
+ const returnType = this.generateReturnType(operation);
3519
+ const overloads = this.generateMethodOverload(parameters);
3520
+ const methodBody = this.bodyGenerator.generateMethodBody(operation);
3521
+ serviceClass.addMethod({
3522
+ name: methodName,
3523
+ parameters,
3524
+ returnType,
3525
+ statements: methodBody,
3526
+ overloads
3527
+ });
3528
+ }
3529
+ generateMethodName(operation) {
3530
+ if (operation.operationId) {
3531
+ return camelCase(operation.operationId);
3532
+ }
3533
+ const method = operation.method.toLowerCase();
3534
+ const pathParts = operation.path.split("/").filter((p) => p && !p.startsWith("{"));
3535
+ const resource = pathParts[pathParts.length - 1] || "resource";
3536
+ return `${method}${pascalCase(resource)}`;
3537
+ }
3538
+ generateReturnType(operation) {
3539
+ const response = operation.responses?.["200"] || operation.responses?.["201"] || operation.responses?.["204"];
3540
+ if (!response) {
3541
+ return "any";
3542
+ }
3543
+ this.#responseType = getResponseType(response, this.config);
3544
+ return `HttpResourceRef<${this.#responseType} | undefined>`;
3545
+ }
3546
+ generateMethodOverload(methodParams) {
3547
+ const _methodParams = structuredClone(methodParams);
3548
+ const params = _methodParams.slice(0, -2).map((p) => {
3549
+ if (p.hasQuestionToken) {
3550
+ p.hasQuestionToken = false;
3551
+ p.type += " | undefined";
3552
+ }
3553
+ return p;
3554
+ });
3555
+ const optionParams = _methodParams.slice(-2).map((p) => {
3556
+ if (p.name === "resourceOptions") {
3557
+ p.hasQuestionToken = false;
3558
+ p.type += ` & { defaultValue: NoInfer<${this.#responseType}> }`;
3559
+ }
3560
+ return p;
3561
+ });
3562
+ return [
3563
+ {
3564
+ parameters: [
3565
+ ...params,
3566
+ ...optionParams
3567
+ ],
3568
+ returnType: `HttpResourceRef<${this.#responseType}>`
3569
+ }
3570
+ ];
3571
+ }
3572
+ };
3573
+
3574
+ // src/lib/http-resource-index.generator.ts
3575
+ var fs2 = __toESM(require("fs"), 1);
3576
+ var path2 = __toESM(require("path"), 1);
3577
+ var HttpResourceIndexGenerator = class {
3578
+ static {
3579
+ __name(this, "HttpResourceIndexGenerator");
3580
+ }
3581
+ project;
3582
+ constructor(project) {
3583
+ this.project = project;
3584
+ }
3585
+ generateIndex(outputRoot) {
3586
+ const servicesDir = path2.join(outputRoot, "resources");
3587
+ const indexPath = path2.join(servicesDir, "index.ts");
3588
+ const sourceFile = this.project.createSourceFile(indexPath, "", {
3589
+ overwrite: true
3590
+ });
3591
+ sourceFile.insertText(0, SERVICE_INDEX_GENERATOR_HEADER_COMMENT);
3592
+ const serviceFiles = fs2.readdirSync(servicesDir).filter((file) => file.endsWith(".resource.ts")).map((file) => file.replace(".resource.ts", ""));
3593
+ serviceFiles.forEach((serviceName) => {
3594
+ const className = pascalCase(serviceName) + "Resource";
3595
+ sourceFile.addExportDeclaration({
3596
+ namedExports: [
3597
+ className
3598
+ ],
3599
+ moduleSpecifier: `./${serviceName}.resource`
3600
+ });
3601
+ });
3602
+ sourceFile.formatText();
3603
+ sourceFile.saveSync();
3604
+ }
3605
+ };
3606
+
3607
+ // src/lib/http-resource.generator.ts
3608
+ var HttpResourceGenerator = class _HttpResourceGenerator {
3609
+ static {
3610
+ __name(this, "HttpResourceGenerator");
3611
+ }
3612
+ project;
3613
+ parser;
3614
+ spec;
3615
+ config;
3616
+ methodGenerator;
3617
+ indexGenerator;
3618
+ constructor(parser, project, config) {
3619
+ this.config = config;
3620
+ this.project = project;
3621
+ this.parser = parser;
3622
+ this.spec = this.parser.getSpec();
3623
+ this.indexGenerator = new HttpResourceIndexGenerator(project);
3624
+ if (!this.parser.isValidSpec()) {
3625
+ const versionInfo = this.parser.getSpecVersion();
3626
+ throw new Error(`Invalid or unsupported specification format. Expected OpenAPI 3.x or Swagger 2.x. ${versionInfo ? `Found: ${versionInfo.type} ${versionInfo.version}` : "No version info found"}`);
3627
+ }
3628
+ this.methodGenerator = new HttpResourceMethodGenerator(config);
3629
+ }
3630
+ static async create(swaggerPathOrUrl, project, config) {
3631
+ const parser = await SwaggerParser.create(swaggerPathOrUrl, config);
3632
+ return new _HttpResourceGenerator(parser, project, config);
3633
+ }
3634
+ generate(outputRoot) {
3635
+ const outputDir = path3.join(outputRoot, "resources");
3636
+ const paths = extractPaths(this.spec.paths, [
3637
+ "get"
3638
+ ]);
3639
+ if (paths.length === 0) {
3640
+ console.warn("No API paths found in the specification");
3641
+ return;
3642
+ }
3643
+ const controllerGroups = this.groupPathsByController(paths);
3644
+ Object.entries(controllerGroups).forEach(([resourceName, operations]) => {
3645
+ this.generateServiceFile(resourceName, operations, outputDir);
3646
+ });
3647
+ this.indexGenerator.generateIndex(outputRoot);
3648
+ }
3649
+ groupPathsByController(paths) {
3650
+ const groups = {};
3651
+ paths.forEach((path4) => {
3652
+ let controllerName = "Default";
3653
+ if (path4.tags && path4.tags.length > 0) {
3654
+ controllerName = path4.tags[0];
3655
+ } else {
3656
+ const pathParts = path4.path.split("/").filter((p) => p && !p.startsWith("{"));
3657
+ if (pathParts.length > 1) {
3658
+ controllerName = pascalCase(pathParts[1]);
3659
+ }
3660
+ }
3661
+ controllerName += "Resource";
3662
+ controllerName = pascalCase(controllerName);
3663
+ if (!groups[controllerName]) {
3664
+ groups[controllerName] = [];
3665
+ }
3666
+ groups[controllerName].push(path4);
3667
+ });
3668
+ return groups;
3669
+ }
3670
+ generateServiceFile(resourceName, operations, outputDir) {
3671
+ const fileName = `${camelCase(resourceName).replace(/Resource/, "")}.resource.ts`;
3672
+ const filePath = path3.join(outputDir, fileName);
3673
+ const sourceFile = this.project.createSourceFile(filePath, "", {
3674
+ overwrite: true
3675
+ });
3676
+ const usedTypes = collectUsedTypes(operations);
3677
+ this.addImports(sourceFile, usedTypes);
3678
+ this.addServiceClass(sourceFile, resourceName, operations);
3679
+ sourceFile.formatText();
3680
+ sourceFile.saveSync();
3681
+ }
3682
+ addImports(sourceFile, usedTypes) {
3683
+ const basePathTokenName = getBasePathTokenName(this.config.clientName);
3684
+ const clientContextTokenName = getClientContextTokenName(this.config.clientName);
3685
+ sourceFile.addImportDeclarations([
3686
+ {
3687
+ namedImports: [
3688
+ "Injectable",
3689
+ "inject",
3690
+ "Signal"
3691
+ ],
3692
+ moduleSpecifier: "@angular/core"
3693
+ },
3694
+ {
3695
+ namedImports: [
3696
+ "HttpResourceRef",
3697
+ "HttpContext",
3698
+ "httpResource",
3699
+ "HttpResourceRequest",
3700
+ "HttpResourceOptions",
3701
+ "HttpParams",
3702
+ "HttpContextToken",
3703
+ "HttpHeaders"
3704
+ ],
3705
+ moduleSpecifier: "@angular/common/http"
3706
+ },
3707
+ {
3708
+ namedImports: [
3709
+ basePathTokenName,
3710
+ clientContextTokenName
3711
+ ],
3712
+ moduleSpecifier: "../tokens"
3713
+ }
3714
+ ]);
3715
+ if (usedTypes.size > 0) {
3716
+ sourceFile.addImportDeclaration({
3717
+ namedImports: Array.from(usedTypes).sort(),
3718
+ moduleSpecifier: "../models"
3719
+ });
3720
+ }
3721
+ }
3722
+ addServiceClass(sourceFile, resourceName, operations) {
3723
+ const className = `${resourceName}`;
3724
+ const basePathTokenName = getBasePathTokenName(this.config.clientName);
3725
+ const clientContextTokenName = getClientContextTokenName(this.config.clientName);
3726
+ sourceFile.insertText(0, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT(resourceName));
3727
+ const serviceClass = sourceFile.addClass({
3728
+ name: className,
3729
+ isExported: true,
3730
+ decorators: [
3731
+ {
3732
+ name: "Injectable",
3733
+ arguments: [
3734
+ '{ providedIn: "root" }'
3735
+ ]
3736
+ }
3737
+ ]
3738
+ });
3739
+ serviceClass.addProperty({
3740
+ name: "basePath",
3741
+ type: "string",
3742
+ scope: import_ts_morph.Scope.Private,
3743
+ isReadonly: true,
3744
+ initializer: `inject(${basePathTokenName})`
3745
+ });
3746
+ serviceClass.addProperty({
3747
+ name: "clientContextToken",
3748
+ type: "HttpContextToken<string>",
3749
+ scope: import_ts_morph.Scope.Private,
3750
+ isReadonly: true,
3751
+ initializer: clientContextTokenName
3752
+ });
3753
+ serviceClass.addMethod({
3754
+ name: "createContextWithClientId",
3755
+ scope: import_ts_morph.Scope.Private,
3756
+ parameters: [
3757
+ {
3758
+ name: "existingContext",
3759
+ type: "HttpContext",
3760
+ hasQuestionToken: true
3761
+ }
3762
+ ],
3763
+ returnType: "HttpContext",
3764
+ statements: `const context = existingContext || new HttpContext();
3765
+ return context.set(this.clientContextToken, '${this.config.clientName || "default"}');`
3766
+ });
3767
+ operations.forEach((operation) => {
3768
+ this.methodGenerator.addResourceMethod(serviceClass, operation);
3769
+ });
3770
+ if (hasDuplicateFunctionNames(serviceClass.getMethods())) {
3771
+ throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
3772
+ }
3773
+ }
3774
+ };
3775
+ // Annotate the CommonJS export names for ESM import in node:
3776
+ 0 && (module.exports = {
3777
+ HttpResourceGenerator,
3778
+ HttpResourceIndexGenerator,
3779
+ HttpResourceMethodBodyGenerator,
3780
+ HttpResourceMethodGenerator,
3781
+ HttpResourceMethodParamsGenerator
3782
+ });
3783
+ /*! Bundled license information:
3784
+
3785
+ js-yaml/dist/js-yaml.mjs:
3786
+ (*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
3787
+ */
3788
+ //# sourceMappingURL=index.cjs.map