freelens-cert-manager 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/renderer.js +3730 -17
- package/dist/renderer.js.map +1 -1
- package/package.json +5 -1
package/dist/renderer.js
CHANGED
|
@@ -184,8 +184,8 @@ var Issuer = class extends Renderer.K8sApi.LensExtensionKubeObject {
|
|
|
184
184
|
Renderer.K8sApi.KubeApi;
|
|
185
185
|
Renderer.K8sApi.KubeObjectStore;
|
|
186
186
|
// \0freelens-host:mobx
|
|
187
|
-
var hostModule$
|
|
188
|
-
var observable = /* @__PURE__ */ Reflect.get(hostModule$
|
|
187
|
+
var hostModule$3 = globalThis.FreelensExtensionApi.Mobx;
|
|
188
|
+
var observable = /* @__PURE__ */ Reflect.get(hostModule$3, "observable");
|
|
189
189
|
// src/common/store/preferences-store.ts
|
|
190
190
|
var __create = Object.create;
|
|
191
191
|
var __defProp = Object.defineProperty;
|
|
@@ -363,9 +363,10 @@ function isCertReqApproved(obj) {
|
|
|
363
363
|
return (getCertReqStatus(obj).conditions ?? []).some((c) => c.type === "Approved" && c.status === "True");
|
|
364
364
|
}
|
|
365
365
|
// \0freelens-host:react/jsx-runtime
|
|
366
|
-
var hostModule$
|
|
367
|
-
var
|
|
368
|
-
var
|
|
366
|
+
var hostModule$2 = globalThis.FreelensExtensionApi.ReactJsxRuntime;
|
|
367
|
+
var Fragment = /* @__PURE__ */ Reflect.get(hostModule$2, "Fragment");
|
|
368
|
+
var jsx = /* @__PURE__ */ Reflect.get(hostModule$2, "jsx");
|
|
369
|
+
var jsxs = /* @__PURE__ */ Reflect.get(hostModule$2, "jsxs");
|
|
369
370
|
// src/renderer/details/certificate-details.tsx
|
|
370
371
|
/**
|
|
371
372
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
@@ -578,6 +579,3538 @@ function CertificateDeleteCascadeMenuItem({ object: cert }) {
|
|
|
578
579
|
children: "Delete (cascade)"
|
|
579
580
|
});
|
|
580
581
|
}
|
|
582
|
+
// node_modules/.pnpm/js-yaml@5.5.0/node_modules/js-yaml/dist/js-yaml.mjs
|
|
583
|
+
/*! js-yaml 5.5.0 https://github.com/nodeca/js-yaml @license MIT */
|
|
584
|
+
/**
|
|
585
|
+
* Returned by a scalar resolver when the source does not match its tag.
|
|
586
|
+
*
|
|
587
|
+
* @category Tags
|
|
588
|
+
*/
|
|
589
|
+
var NOT_RESOLVED = Symbol("NOT_RESOLVED");
|
|
590
|
+
/**
|
|
591
|
+
* Create a normalized scalar tag definition.
|
|
592
|
+
*
|
|
593
|
+
* @category Tags
|
|
594
|
+
*/
|
|
595
|
+
function defineScalarTag(tagName, options) {
|
|
596
|
+
return {
|
|
597
|
+
tagName,
|
|
598
|
+
nodeKind: "scalar",
|
|
599
|
+
implicit: options.implicit ?? false,
|
|
600
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
601
|
+
implicitFirstChars: options.implicitFirstChars ?? null,
|
|
602
|
+
resolve: options.resolve,
|
|
603
|
+
identify: options.identify,
|
|
604
|
+
represent: options.represent ?? ((data) => String(data)),
|
|
605
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Create a normalized sequence tag definition.
|
|
610
|
+
*
|
|
611
|
+
* @category Tags
|
|
612
|
+
*/
|
|
613
|
+
function defineSequenceTag(tagName, options) {
|
|
614
|
+
const carrierIsResult = options.finalize === void 0;
|
|
615
|
+
return {
|
|
616
|
+
tagName,
|
|
617
|
+
nodeKind: "sequence",
|
|
618
|
+
implicit: false,
|
|
619
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
620
|
+
create: options.create,
|
|
621
|
+
addItem: options.addItem,
|
|
622
|
+
finalize: options.finalize ?? ((carrier) => carrier),
|
|
623
|
+
carrierIsResult,
|
|
624
|
+
identify: options.identify,
|
|
625
|
+
represent: options.represent ?? ((data) => data),
|
|
626
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Create a normalized mapping tag definition.
|
|
631
|
+
*
|
|
632
|
+
* @category Tags
|
|
633
|
+
*/
|
|
634
|
+
function defineMappingTag(tagName, options) {
|
|
635
|
+
const carrierIsResult = options.finalize === void 0;
|
|
636
|
+
return {
|
|
637
|
+
tagName,
|
|
638
|
+
nodeKind: "mapping",
|
|
639
|
+
implicit: false,
|
|
640
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
641
|
+
create: options.create,
|
|
642
|
+
addPair: options.addPair,
|
|
643
|
+
has: options.has,
|
|
644
|
+
keys: options.keys,
|
|
645
|
+
get: options.get,
|
|
646
|
+
finalize: options.finalize ?? ((carrier) => carrier),
|
|
647
|
+
carrierIsResult,
|
|
648
|
+
identify: options.identify,
|
|
649
|
+
represent: options.represent ?? ((data) => data),
|
|
650
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
/** @category Tags */
|
|
654
|
+
var strTag = defineScalarTag("tag:yaml.org,2002:str", {
|
|
655
|
+
resolve: (source) => source,
|
|
656
|
+
identify: (data) => typeof data === "string"
|
|
657
|
+
});
|
|
658
|
+
var NULL_VALUES$1 = [
|
|
659
|
+
"",
|
|
660
|
+
"~",
|
|
661
|
+
"null",
|
|
662
|
+
"Null",
|
|
663
|
+
"NULL"
|
|
664
|
+
];
|
|
665
|
+
/** @category Tags */
|
|
666
|
+
var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
667
|
+
implicit: true,
|
|
668
|
+
implicitFirstChars: [
|
|
669
|
+
"",
|
|
670
|
+
"~",
|
|
671
|
+
"n",
|
|
672
|
+
"N"
|
|
673
|
+
],
|
|
674
|
+
resolve: (source) => {
|
|
675
|
+
if (NULL_VALUES$1.indexOf(source) !== -1) return null;
|
|
676
|
+
return NOT_RESOLVED;
|
|
677
|
+
},
|
|
678
|
+
identify: (object) => object === null,
|
|
679
|
+
represent: () => "null"
|
|
680
|
+
});
|
|
681
|
+
/** @category Tags */
|
|
682
|
+
var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
683
|
+
implicit: true,
|
|
684
|
+
implicitFirstChars: ["n"],
|
|
685
|
+
resolve: (source, isExplicit) => {
|
|
686
|
+
if (source === "null" || isExplicit && source === "") return null;
|
|
687
|
+
return NOT_RESOLVED;
|
|
688
|
+
},
|
|
689
|
+
identify: (object) => object === null,
|
|
690
|
+
represent: () => "null"
|
|
691
|
+
});
|
|
692
|
+
var NULL_VALUES = [
|
|
693
|
+
"",
|
|
694
|
+
"~",
|
|
695
|
+
"null",
|
|
696
|
+
"Null",
|
|
697
|
+
"NULL"
|
|
698
|
+
];
|
|
699
|
+
/** @category Tags */
|
|
700
|
+
var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
701
|
+
implicit: true,
|
|
702
|
+
implicitFirstChars: [
|
|
703
|
+
"",
|
|
704
|
+
"~",
|
|
705
|
+
"n",
|
|
706
|
+
"N"
|
|
707
|
+
],
|
|
708
|
+
resolve: (source) => {
|
|
709
|
+
if (NULL_VALUES.indexOf(source) !== -1) return null;
|
|
710
|
+
return NOT_RESOLVED;
|
|
711
|
+
},
|
|
712
|
+
identify: (object) => object === null,
|
|
713
|
+
represent: () => "null"
|
|
714
|
+
});
|
|
715
|
+
var TRUE_VALUES$2 = [
|
|
716
|
+
"true",
|
|
717
|
+
"True",
|
|
718
|
+
"TRUE"
|
|
719
|
+
];
|
|
720
|
+
var FALSE_VALUES$2 = [
|
|
721
|
+
"false",
|
|
722
|
+
"False",
|
|
723
|
+
"FALSE"
|
|
724
|
+
];
|
|
725
|
+
/** @category Tags */
|
|
726
|
+
var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
727
|
+
implicit: true,
|
|
728
|
+
implicitFirstChars: [
|
|
729
|
+
"t",
|
|
730
|
+
"T",
|
|
731
|
+
"f",
|
|
732
|
+
"F"
|
|
733
|
+
],
|
|
734
|
+
resolve: (source) => {
|
|
735
|
+
if (TRUE_VALUES$2.indexOf(source) !== -1) return true;
|
|
736
|
+
if (FALSE_VALUES$2.indexOf(source) !== -1) return false;
|
|
737
|
+
return NOT_RESOLVED;
|
|
738
|
+
},
|
|
739
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
740
|
+
represent: (object) => object ? "true" : "false"
|
|
741
|
+
});
|
|
742
|
+
var TRUE_VALUES$1 = ["true"];
|
|
743
|
+
var FALSE_VALUES$1 = ["false"];
|
|
744
|
+
/** @category Tags */
|
|
745
|
+
var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
746
|
+
implicit: true,
|
|
747
|
+
implicitFirstChars: ["t", "f"],
|
|
748
|
+
resolve: (source) => {
|
|
749
|
+
if (TRUE_VALUES$1.indexOf(source) !== -1) return true;
|
|
750
|
+
if (FALSE_VALUES$1.indexOf(source) !== -1) return false;
|
|
751
|
+
return NOT_RESOLVED;
|
|
752
|
+
},
|
|
753
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
754
|
+
represent: (object) => object ? "true" : "false"
|
|
755
|
+
});
|
|
756
|
+
var TRUE_VALUES = [
|
|
757
|
+
"true",
|
|
758
|
+
"True",
|
|
759
|
+
"TRUE",
|
|
760
|
+
"y",
|
|
761
|
+
"Y",
|
|
762
|
+
"yes",
|
|
763
|
+
"Yes",
|
|
764
|
+
"YES",
|
|
765
|
+
"on",
|
|
766
|
+
"On",
|
|
767
|
+
"ON"
|
|
768
|
+
];
|
|
769
|
+
var FALSE_VALUES = [
|
|
770
|
+
"false",
|
|
771
|
+
"False",
|
|
772
|
+
"FALSE",
|
|
773
|
+
"n",
|
|
774
|
+
"N",
|
|
775
|
+
"no",
|
|
776
|
+
"No",
|
|
777
|
+
"NO",
|
|
778
|
+
"off",
|
|
779
|
+
"Off",
|
|
780
|
+
"OFF"
|
|
781
|
+
];
|
|
782
|
+
/** @category Tags */
|
|
783
|
+
var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
784
|
+
implicit: true,
|
|
785
|
+
implicitFirstChars: [
|
|
786
|
+
"y",
|
|
787
|
+
"Y",
|
|
788
|
+
"n",
|
|
789
|
+
"N",
|
|
790
|
+
"t",
|
|
791
|
+
"T",
|
|
792
|
+
"f",
|
|
793
|
+
"F",
|
|
794
|
+
"o",
|
|
795
|
+
"O"
|
|
796
|
+
],
|
|
797
|
+
resolve: (source) => {
|
|
798
|
+
if (TRUE_VALUES.indexOf(source) !== -1) return true;
|
|
799
|
+
if (FALSE_VALUES.indexOf(source) !== -1) return false;
|
|
800
|
+
return NOT_RESOLVED;
|
|
801
|
+
},
|
|
802
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
803
|
+
represent: (object) => object ? "true" : "false"
|
|
804
|
+
});
|
|
805
|
+
var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
806
|
+
var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
807
|
+
function parseYamlInteger$2(source) {
|
|
808
|
+
let value = source;
|
|
809
|
+
let sign = 1;
|
|
810
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
811
|
+
if (value[0] === "-") sign = -1;
|
|
812
|
+
value = value.slice(1);
|
|
813
|
+
}
|
|
814
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
815
|
+
if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
|
|
816
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
817
|
+
return sign * parseInt(value, 10);
|
|
818
|
+
}
|
|
819
|
+
function resolveYamlInteger$2(source, isExplicit) {
|
|
820
|
+
if (isExplicit) {
|
|
821
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
822
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
823
|
+
const result = parseYamlInteger$2(source);
|
|
824
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
825
|
+
}
|
|
826
|
+
/** @category Tags */
|
|
827
|
+
var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
828
|
+
implicit: true,
|
|
829
|
+
implicitFirstChars: [
|
|
830
|
+
"-",
|
|
831
|
+
"+",
|
|
832
|
+
..."0123456789"
|
|
833
|
+
],
|
|
834
|
+
resolve: resolveYamlInteger$2,
|
|
835
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
836
|
+
represent: (object) => object.toString(10)
|
|
837
|
+
});
|
|
838
|
+
var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
|
|
839
|
+
var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
840
|
+
function parseYamlInteger$1(source) {
|
|
841
|
+
let value = source;
|
|
842
|
+
let sign = 1;
|
|
843
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
844
|
+
if (value[0] === "-") sign = -1;
|
|
845
|
+
value = value.slice(1);
|
|
846
|
+
}
|
|
847
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
848
|
+
if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
|
|
849
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
850
|
+
return sign * parseInt(value, 10);
|
|
851
|
+
}
|
|
852
|
+
function resolveYamlInteger$1(source, isExplicit) {
|
|
853
|
+
if (isExplicit) {
|
|
854
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
855
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
856
|
+
const result = parseYamlInteger$1(source);
|
|
857
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
858
|
+
}
|
|
859
|
+
/** @category Tags */
|
|
860
|
+
var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
861
|
+
implicit: true,
|
|
862
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
863
|
+
resolve: resolveYamlInteger$1,
|
|
864
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
865
|
+
represent: (object) => object.toString(10)
|
|
866
|
+
});
|
|
867
|
+
var YAML_INTEGER_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?0x[0-9a-fA-F_]+|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+|[-+]?(?:0|[1-9][0-9_]*))$");
|
|
868
|
+
function parseYamlInteger(source) {
|
|
869
|
+
let value = source.replace(/_/g, "");
|
|
870
|
+
let sign = 1;
|
|
871
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
872
|
+
if (value[0] === "-") sign = -1;
|
|
873
|
+
value = value.slice(1);
|
|
874
|
+
}
|
|
875
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
876
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
877
|
+
if (value.includes(":")) {
|
|
878
|
+
let result = 0;
|
|
879
|
+
for (const part of value.split(":")) result = result * 60 + Number(part);
|
|
880
|
+
return sign * result;
|
|
881
|
+
}
|
|
882
|
+
if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8);
|
|
883
|
+
return sign * parseInt(value, 10);
|
|
884
|
+
}
|
|
885
|
+
function resolveYamlInteger(source) {
|
|
886
|
+
if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED;
|
|
887
|
+
const result = parseYamlInteger(source);
|
|
888
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
889
|
+
}
|
|
890
|
+
/** @category Tags */
|
|
891
|
+
var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
892
|
+
implicit: true,
|
|
893
|
+
implicitFirstChars: [
|
|
894
|
+
"-",
|
|
895
|
+
"+",
|
|
896
|
+
..."0123456789"
|
|
897
|
+
],
|
|
898
|
+
resolve: resolveYamlInteger,
|
|
899
|
+
identify: (object) => Number.isInteger(object) && !Object.is(object, -0) && object.toString(10).indexOf("e") < 0,
|
|
900
|
+
represent: (object) => object.toString(10)
|
|
901
|
+
});
|
|
902
|
+
var YAML_FLOAT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
903
|
+
var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
904
|
+
function resolveYamlFloat$2(source) {
|
|
905
|
+
if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
906
|
+
let value = source.toLowerCase();
|
|
907
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
908
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
909
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
910
|
+
if (value === ".nan") return NaN;
|
|
911
|
+
const result = sign * parseFloat(value);
|
|
912
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result;
|
|
913
|
+
return NOT_RESOLVED;
|
|
914
|
+
}
|
|
915
|
+
function representYamlFloat$2(object) {
|
|
916
|
+
if (isNaN(object)) return ".nan";
|
|
917
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
918
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
919
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
920
|
+
const result = object.toString(10);
|
|
921
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
922
|
+
}
|
|
923
|
+
/** @category Tags */
|
|
924
|
+
var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
925
|
+
implicit: true,
|
|
926
|
+
implicitFirstChars: [
|
|
927
|
+
"-",
|
|
928
|
+
"+",
|
|
929
|
+
".",
|
|
930
|
+
..."0123456789"
|
|
931
|
+
],
|
|
932
|
+
resolve: resolveYamlFloat$2,
|
|
933
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
934
|
+
represent: representYamlFloat$2
|
|
935
|
+
});
|
|
936
|
+
var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
|
|
937
|
+
var YAML_FLOAT_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
938
|
+
function resolveYamlFloat$1(source, isExplicit) {
|
|
939
|
+
if (isExplicit) {
|
|
940
|
+
if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
941
|
+
let value = source.toLowerCase();
|
|
942
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
943
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
944
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
945
|
+
if (value === ".nan") return NaN;
|
|
946
|
+
const result = sign * parseFloat(value);
|
|
947
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
948
|
+
}
|
|
949
|
+
if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
950
|
+
const result = Number(source);
|
|
951
|
+
if (Number.isFinite(result)) return result;
|
|
952
|
+
return NOT_RESOLVED;
|
|
953
|
+
}
|
|
954
|
+
function representYamlFloat$1(object) {
|
|
955
|
+
if (isNaN(object)) return ".nan";
|
|
956
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
957
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
958
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
959
|
+
const result = object.toString(10);
|
|
960
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
961
|
+
}
|
|
962
|
+
/** @category Tags */
|
|
963
|
+
var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
964
|
+
implicit: true,
|
|
965
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
966
|
+
resolve: resolveYamlFloat$1,
|
|
967
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
968
|
+
represent: representYamlFloat$1
|
|
969
|
+
});
|
|
970
|
+
var YAML_FLOAT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:(?:[0-9][0-9_]*)?\\.[0-9_]*)(?:[eE][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
971
|
+
var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
972
|
+
function resolveYamlFloat(source) {
|
|
973
|
+
if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
974
|
+
let value = source.toLowerCase().replace(/_/g, "");
|
|
975
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
976
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
977
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
978
|
+
if (value === ".nan") return NaN;
|
|
979
|
+
let result = 0;
|
|
980
|
+
if (value.includes(":")) {
|
|
981
|
+
for (const part of value.split(":")) result = result * 60 + Number(part);
|
|
982
|
+
result *= sign;
|
|
983
|
+
} else result = sign * parseFloat(value);
|
|
984
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result;
|
|
985
|
+
return NOT_RESOLVED;
|
|
986
|
+
}
|
|
987
|
+
function representYamlFloat(object) {
|
|
988
|
+
if (isNaN(object)) return ".nan";
|
|
989
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
990
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
991
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
992
|
+
const result = object.toString(10);
|
|
993
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
994
|
+
}
|
|
995
|
+
/** @category Tags */
|
|
996
|
+
var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
997
|
+
implicit: true,
|
|
998
|
+
implicitFirstChars: [
|
|
999
|
+
"-",
|
|
1000
|
+
"+",
|
|
1001
|
+
".",
|
|
1002
|
+
..."0123456789"
|
|
1003
|
+
],
|
|
1004
|
+
resolve: resolveYamlFloat,
|
|
1005
|
+
identify: (object) => typeof object === "number" && (!Number.isInteger(object) || Object.is(object, -0) || object.toString(10).indexOf("e") >= 0),
|
|
1006
|
+
represent: representYamlFloat
|
|
1007
|
+
});
|
|
1008
|
+
/**
|
|
1009
|
+
* Enables merge keys in {@link CORE_SCHEMA} when added with
|
|
1010
|
+
* {@link Schema.withTags}.
|
|
1011
|
+
*
|
|
1012
|
+
* @category Tags
|
|
1013
|
+
*/
|
|
1014
|
+
var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
|
|
1015
|
+
implicit: true,
|
|
1016
|
+
implicitFirstChars: ["<"],
|
|
1017
|
+
resolve: (source, isExplicit) => {
|
|
1018
|
+
if (source === "<<" || isExplicit && source === "") return "<<";
|
|
1019
|
+
return NOT_RESOLVED;
|
|
1020
|
+
},
|
|
1021
|
+
identify: () => false
|
|
1022
|
+
});
|
|
1023
|
+
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
1024
|
+
function resolveYamlBinary(source) {
|
|
1025
|
+
const input = source.replace(/\s/g, "");
|
|
1026
|
+
if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED;
|
|
1027
|
+
const binary = atob(input);
|
|
1028
|
+
const result = new Uint8Array(binary.length);
|
|
1029
|
+
for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index);
|
|
1030
|
+
return result;
|
|
1031
|
+
}
|
|
1032
|
+
function representYamlBinary(object) {
|
|
1033
|
+
let binary = "";
|
|
1034
|
+
for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
|
|
1035
|
+
return btoa(binary);
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* The `!!binary` tag, represented as a `Uint8Array`.
|
|
1039
|
+
*
|
|
1040
|
+
* @category Tags
|
|
1041
|
+
*/
|
|
1042
|
+
var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
|
|
1043
|
+
resolve: resolveYamlBinary,
|
|
1044
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
|
|
1045
|
+
represent: representYamlBinary
|
|
1046
|
+
});
|
|
1047
|
+
var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
|
|
1048
|
+
var YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([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]))?))?$");
|
|
1049
|
+
function makeUtcDate(year, month, day, hour = 0, minute = 0, second = 0, fraction = 0) {
|
|
1050
|
+
const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
1051
|
+
date.setUTCFullYear(year, month, day);
|
|
1052
|
+
return date;
|
|
1053
|
+
}
|
|
1054
|
+
function resolveYamlTimestamp(source) {
|
|
1055
|
+
let match = YAML_DATE_REGEXP.exec(source);
|
|
1056
|
+
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
|
|
1057
|
+
if (match === null) return NOT_RESOLVED;
|
|
1058
|
+
const year = +match[1];
|
|
1059
|
+
const month = +match[2] - 1;
|
|
1060
|
+
const day = +match[3];
|
|
1061
|
+
if (!match[4]) {
|
|
1062
|
+
const date = makeUtcDate(year, month, day);
|
|
1063
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
|
|
1064
|
+
return date;
|
|
1065
|
+
}
|
|
1066
|
+
const hour = +match[4];
|
|
1067
|
+
const minute = +match[5];
|
|
1068
|
+
const second = +match[6];
|
|
1069
|
+
let fraction = 0;
|
|
1070
|
+
if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED;
|
|
1071
|
+
if (match[7]) {
|
|
1072
|
+
let value = match[7].slice(0, 3);
|
|
1073
|
+
while (value.length < 3) value += "0";
|
|
1074
|
+
fraction = +value;
|
|
1075
|
+
}
|
|
1076
|
+
const date = makeUtcDate(year, month, day, hour, minute, second, fraction);
|
|
1077
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
|
|
1078
|
+
if (match[9]) {
|
|
1079
|
+
const offsetHour = +match[10];
|
|
1080
|
+
const offsetMinute = +(match[11] || 0);
|
|
1081
|
+
if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED;
|
|
1082
|
+
const offset = (offsetHour * 60 + offsetMinute) * 6e4;
|
|
1083
|
+
date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
|
|
1084
|
+
}
|
|
1085
|
+
return date;
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* The YAML 1.1 `!!timestamp` tag, represented as a JavaScript `Date`.
|
|
1089
|
+
*
|
|
1090
|
+
* @category Tags
|
|
1091
|
+
*/
|
|
1092
|
+
var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
1093
|
+
implicit: true,
|
|
1094
|
+
implicitFirstChars: [..."0123456789"],
|
|
1095
|
+
resolve: resolveYamlTimestamp,
|
|
1096
|
+
identify: (object) => object instanceof Date,
|
|
1097
|
+
represent: (object) => object.toISOString()
|
|
1098
|
+
});
|
|
1099
|
+
/** @category Tags */
|
|
1100
|
+
var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
|
|
1101
|
+
create: () => [],
|
|
1102
|
+
addItem: (container, item) => {
|
|
1103
|
+
container.push(item);
|
|
1104
|
+
},
|
|
1105
|
+
identify: Array.isArray
|
|
1106
|
+
});
|
|
1107
|
+
function isPlainObject(data) {
|
|
1108
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
|
|
1109
|
+
const prototype = Object.getPrototypeOf(data);
|
|
1110
|
+
return prototype === null || prototype === Object.prototype;
|
|
1111
|
+
}
|
|
1112
|
+
function pick(object, keys) {
|
|
1113
|
+
const result = {};
|
|
1114
|
+
for (const key of keys) if (object[key] !== void 0) result[key] = object[key];
|
|
1115
|
+
return result;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
1119
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
1120
|
+
* identified and dumped.
|
|
1121
|
+
*
|
|
1122
|
+
* ```yaml
|
|
1123
|
+
* !!omap
|
|
1124
|
+
* - one: 1
|
|
1125
|
+
* - two: 2
|
|
1126
|
+
* ```
|
|
1127
|
+
*
|
|
1128
|
+
* is loaded as
|
|
1129
|
+
*
|
|
1130
|
+
* ```javascript
|
|
1131
|
+
* [
|
|
1132
|
+
* { one: 1 },
|
|
1133
|
+
* { two: 2 }
|
|
1134
|
+
* ]
|
|
1135
|
+
* ```
|
|
1136
|
+
*
|
|
1137
|
+
* @category Tags
|
|
1138
|
+
*/
|
|
1139
|
+
var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
1140
|
+
create: () => ({
|
|
1141
|
+
list: [],
|
|
1142
|
+
seen: /* @__PURE__ */ new Set()
|
|
1143
|
+
}),
|
|
1144
|
+
addItem: (carrier, item) => {
|
|
1145
|
+
let key;
|
|
1146
|
+
if (item instanceof Map) {
|
|
1147
|
+
if (item.size !== 1) return "cannot resolve an ordered map item";
|
|
1148
|
+
key = item.keys().next().value;
|
|
1149
|
+
} else if (isPlainObject(item)) {
|
|
1150
|
+
const itemKeys = Object.keys(item);
|
|
1151
|
+
if (itemKeys.length !== 1) return "cannot resolve an ordered map item";
|
|
1152
|
+
key = itemKeys[0];
|
|
1153
|
+
} else return "cannot resolve an ordered map item";
|
|
1154
|
+
if (carrier.seen.has(key)) return "duplicate key in ordered map";
|
|
1155
|
+
carrier.seen.add(key);
|
|
1156
|
+
carrier.list.push(item);
|
|
1157
|
+
return "";
|
|
1158
|
+
},
|
|
1159
|
+
finalize: (carrier) => carrier.list,
|
|
1160
|
+
identify: () => false
|
|
1161
|
+
});
|
|
1162
|
+
/**
|
|
1163
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
1164
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
1165
|
+
* identified and dumped.
|
|
1166
|
+
*
|
|
1167
|
+
* ```yaml
|
|
1168
|
+
* !!pairs
|
|
1169
|
+
* - one: 1
|
|
1170
|
+
* - two: 2
|
|
1171
|
+
* ```
|
|
1172
|
+
*
|
|
1173
|
+
* is loaded as
|
|
1174
|
+
*
|
|
1175
|
+
* ```javascript
|
|
1176
|
+
* [
|
|
1177
|
+
* ['one', 1],
|
|
1178
|
+
* ['two', 2]
|
|
1179
|
+
* ]
|
|
1180
|
+
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* @category Tags
|
|
1183
|
+
*/
|
|
1184
|
+
var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
1185
|
+
create: () => [],
|
|
1186
|
+
addItem: (container, item) => {
|
|
1187
|
+
if (item instanceof Map) {
|
|
1188
|
+
if (item.size !== 1) return "cannot resolve a pairs item";
|
|
1189
|
+
container.push(item.entries().next().value);
|
|
1190
|
+
return "";
|
|
1191
|
+
}
|
|
1192
|
+
if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item";
|
|
1193
|
+
const object = item;
|
|
1194
|
+
const keys = Object.keys(object);
|
|
1195
|
+
if (keys.length !== 1) return "cannot resolve a pairs item";
|
|
1196
|
+
container.push([keys[0], object[keys[0]]]);
|
|
1197
|
+
return "";
|
|
1198
|
+
},
|
|
1199
|
+
identify: () => false
|
|
1200
|
+
});
|
|
1201
|
+
/**
|
|
1202
|
+
* This is the default mapping implementation. It uses `{}` objects and has only
|
|
1203
|
+
* partial functionality due to language limitations. This choice was made
|
|
1204
|
+
* because users expect to get JavaScript objects, and it was left unchanged to
|
|
1205
|
+
* avoid too many breaking changes in the v5 release.
|
|
1206
|
+
*
|
|
1207
|
+
* Side effects:
|
|
1208
|
+
*
|
|
1209
|
+
* - `Object.hasOwn()` checks or `for...of` loops are required for safe use (to
|
|
1210
|
+
* avoid falling through to prototypes).
|
|
1211
|
+
* - Only scalar string keys are supported properly.
|
|
1212
|
+
* - Other scalar keys, such as `null` and numbers, are converted to strings.
|
|
1213
|
+
* This is historical behaviour, and it can cause side effects such as
|
|
1214
|
+
* problems with `!!merge`.
|
|
1215
|
+
*
|
|
1216
|
+
* Note that non-string scalar keys may be deprecated in future versions.
|
|
1217
|
+
*
|
|
1218
|
+
* Ideally, use {@link realMapTag} instead.
|
|
1219
|
+
*
|
|
1220
|
+
* @category Tags
|
|
1221
|
+
*/
|
|
1222
|
+
var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
1223
|
+
create: () => ({}),
|
|
1224
|
+
identify: isPlainObject,
|
|
1225
|
+
represent: (o) => {
|
|
1226
|
+
const map = /* @__PURE__ */ new Map();
|
|
1227
|
+
for (const key of Object.keys(o)) map.set(key, o[key]);
|
|
1228
|
+
return map;
|
|
1229
|
+
},
|
|
1230
|
+
addPair: (container, key, value) => {
|
|
1231
|
+
if (key !== null && typeof key === "object") return "object-based map does not support complex keys";
|
|
1232
|
+
const normalizedKey = String(key);
|
|
1233
|
+
if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
|
|
1234
|
+
value,
|
|
1235
|
+
enumerable: true,
|
|
1236
|
+
configurable: true,
|
|
1237
|
+
writable: true
|
|
1238
|
+
});
|
|
1239
|
+
else container[normalizedKey] = value;
|
|
1240
|
+
return "";
|
|
1241
|
+
},
|
|
1242
|
+
has: (container, key) => {
|
|
1243
|
+
if (key !== null && typeof key === "object") return false;
|
|
1244
|
+
return Object.prototype.hasOwnProperty.call(container, String(key));
|
|
1245
|
+
},
|
|
1246
|
+
keys: (container) => Object.keys(container),
|
|
1247
|
+
get: (container, key) => {
|
|
1248
|
+
const normalizedKey = String(key);
|
|
1249
|
+
if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
|
|
1250
|
+
return container[normalizedKey];
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
/**
|
|
1254
|
+
* The YAML 1.1 `!!set` tag, represented as a JavaScript `Set`.
|
|
1255
|
+
*
|
|
1256
|
+
* @category Tags
|
|
1257
|
+
*/
|
|
1258
|
+
var setTag = defineMappingTag("tag:yaml.org,2002:set", {
|
|
1259
|
+
create: () => /* @__PURE__ */ new Set(),
|
|
1260
|
+
identify: (data) => data instanceof Set,
|
|
1261
|
+
represent: (data) => {
|
|
1262
|
+
const map = /* @__PURE__ */ new Map();
|
|
1263
|
+
for (const key of data) map.set(key, null);
|
|
1264
|
+
return map;
|
|
1265
|
+
},
|
|
1266
|
+
addPair: (container, key, value) => {
|
|
1267
|
+
if (value !== null) return "cannot resolve a set item";
|
|
1268
|
+
container.add(key);
|
|
1269
|
+
return "";
|
|
1270
|
+
},
|
|
1271
|
+
has: (container, key) => container.has(key),
|
|
1272
|
+
keys: (container) => container.keys(),
|
|
1273
|
+
get: () => null
|
|
1274
|
+
});
|
|
1275
|
+
function createTagDefinitionMap() {
|
|
1276
|
+
return {
|
|
1277
|
+
scalar: Object.create(null),
|
|
1278
|
+
sequence: Object.create(null),
|
|
1279
|
+
mapping: Object.create(null)
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
function createTagDefinitionListMap() {
|
|
1283
|
+
return {
|
|
1284
|
+
scalar: [],
|
|
1285
|
+
sequence: [],
|
|
1286
|
+
mapping: []
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
function compileTags(tags) {
|
|
1290
|
+
const result = [];
|
|
1291
|
+
for (const tag of tags) {
|
|
1292
|
+
let index = result.length;
|
|
1293
|
+
for (let previousIndex = 0; previousIndex < result.length; previousIndex++) {
|
|
1294
|
+
const previous = result[previousIndex];
|
|
1295
|
+
if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
|
|
1296
|
+
index = previousIndex;
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
result[index] = tag;
|
|
1301
|
+
}
|
|
1302
|
+
return result;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Controls tag resolution when loading and type selection when dumping.
|
|
1306
|
+
*
|
|
1307
|
+
* @category Schemas
|
|
1308
|
+
*/
|
|
1309
|
+
var Schema = class Schema {
|
|
1310
|
+
tags;
|
|
1311
|
+
/** @internal */
|
|
1312
|
+
implicitScalarTags;
|
|
1313
|
+
/**
|
|
1314
|
+
* Dispatch implicit scalar resolvers by `source.charAt(0)`. Each bucket holds
|
|
1315
|
+
* the resolvers that may match that key, in schema order; a key absent from
|
|
1316
|
+
* the map uses
|
|
1317
|
+
* {@link Schema.implicitScalarAnyFirstChar}
|
|
1318
|
+
* (resolvers that declared no first-char constraint, so they apply to any
|
|
1319
|
+
* first character).
|
|
1320
|
+
*/
|
|
1321
|
+
implicitScalarByFirstChar;
|
|
1322
|
+
implicitScalarAnyFirstChar;
|
|
1323
|
+
/**
|
|
1324
|
+
* The default scalar tag (`!!str`), resolved once so the composer's fallback
|
|
1325
|
+
* for unresolved plain scalars avoids a keyed lookup per scalar.
|
|
1326
|
+
*
|
|
1327
|
+
* @internal
|
|
1328
|
+
*/
|
|
1329
|
+
defaultScalarTag;
|
|
1330
|
+
/**
|
|
1331
|
+
* The default container tags (`!!seq` / `!!map`), used by the dumper: when a
|
|
1332
|
+
* value is identified by its default tag, the tag is implicit and not
|
|
1333
|
+
* printed. Undefined if the schema does not define them (then such values
|
|
1334
|
+
* can't be dumped).
|
|
1335
|
+
*
|
|
1336
|
+
* @internal
|
|
1337
|
+
*/
|
|
1338
|
+
defaultSequenceTag;
|
|
1339
|
+
/** @internal */
|
|
1340
|
+
defaultMappingTag;
|
|
1341
|
+
exact;
|
|
1342
|
+
prefix;
|
|
1343
|
+
constructor(tags) {
|
|
1344
|
+
const compiledTags = compileTags(tags);
|
|
1345
|
+
const implicitScalarTags = [];
|
|
1346
|
+
const exact = createTagDefinitionMap();
|
|
1347
|
+
const prefix = createTagDefinitionListMap();
|
|
1348
|
+
for (const tag of compiledTags) {
|
|
1349
|
+
if (tag.nodeKind === "scalar" && tag.implicit) {
|
|
1350
|
+
if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix");
|
|
1351
|
+
implicitScalarTags.push(tag);
|
|
1352
|
+
}
|
|
1353
|
+
switch (tag.nodeKind) {
|
|
1354
|
+
case "scalar":
|
|
1355
|
+
if (tag.matchByTagPrefix) prefix.scalar.push(tag);
|
|
1356
|
+
else exact.scalar[tag.tagName] = tag;
|
|
1357
|
+
break;
|
|
1358
|
+
case "sequence":
|
|
1359
|
+
if (tag.matchByTagPrefix) prefix.sequence.push(tag);
|
|
1360
|
+
else exact.sequence[tag.tagName] = tag;
|
|
1361
|
+
break;
|
|
1362
|
+
case "mapping": if (tag.matchByTagPrefix) prefix.mapping.push(tag);
|
|
1363
|
+
else exact.mapping[tag.tagName] = tag;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
|
|
1367
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1368
|
+
for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key);
|
|
1369
|
+
const implicitScalarByFirstChar = /* @__PURE__ */ new Map();
|
|
1370
|
+
for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
|
|
1371
|
+
const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
|
|
1372
|
+
if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
|
|
1373
|
+
this.tags = compiledTags;
|
|
1374
|
+
this.implicitScalarTags = implicitScalarTags;
|
|
1375
|
+
this.implicitScalarByFirstChar = implicitScalarByFirstChar;
|
|
1376
|
+
this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
|
|
1377
|
+
this.defaultScalarTag = defaultScalarTag;
|
|
1378
|
+
this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
|
|
1379
|
+
this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
|
|
1380
|
+
this.exact = exact;
|
|
1381
|
+
this.prefix = prefix;
|
|
1382
|
+
}
|
|
1383
|
+
/** @internal */
|
|
1384
|
+
lookupScalarTag(tagName) {
|
|
1385
|
+
const exactTag = this.exact.scalar[tagName];
|
|
1386
|
+
if (exactTag) return exactTag;
|
|
1387
|
+
for (const tag of this.prefix.scalar) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1388
|
+
}
|
|
1389
|
+
/** @internal */
|
|
1390
|
+
lookupSequenceTag(tagName) {
|
|
1391
|
+
const exactTag = this.exact.sequence[tagName];
|
|
1392
|
+
if (exactTag) return exactTag;
|
|
1393
|
+
for (const tag of this.prefix.sequence) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1394
|
+
}
|
|
1395
|
+
/** @internal */
|
|
1396
|
+
lookupMappingTag(tagName) {
|
|
1397
|
+
const exactTag = this.exact.mapping[tagName];
|
|
1398
|
+
if (exactTag) return exactTag;
|
|
1399
|
+
for (const tag of this.prefix.mapping) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1400
|
+
}
|
|
1401
|
+
/** @internal */
|
|
1402
|
+
resolveImplicitScalarTag(source) {
|
|
1403
|
+
const candidates = this.implicitScalarByFirstChar.get(source.charAt(0)) ?? this.implicitScalarAnyFirstChar;
|
|
1404
|
+
for (const tag of candidates) {
|
|
1405
|
+
const value = tag.resolve(source, false, tag.tagName);
|
|
1406
|
+
if (value !== NOT_RESOLVED) return {
|
|
1407
|
+
value,
|
|
1408
|
+
tag
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
const tag = this.defaultScalarTag;
|
|
1412
|
+
return {
|
|
1413
|
+
value: tag.resolve(source, false, tag.tagName),
|
|
1414
|
+
tag
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Creates a new schema with the specified tags added. If a tag already
|
|
1419
|
+
* exists, it is replaced by the specified tag.
|
|
1420
|
+
*
|
|
1421
|
+
* @example
|
|
1422
|
+
*
|
|
1423
|
+
* ```javascript
|
|
1424
|
+
* import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
1425
|
+
*
|
|
1426
|
+
* const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
withTags(...tags) {
|
|
1430
|
+
let flatTags = [];
|
|
1431
|
+
for (const tag of tags) flatTags = flatTags.concat(tag);
|
|
1432
|
+
return new Schema([...this.tags, ...flatTags]);
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
/**
|
|
1436
|
+
* The YAML 1.2 Failsafe Schema: strings, sequences, and mappings.
|
|
1437
|
+
*
|
|
1438
|
+
* @category Schemas
|
|
1439
|
+
*/
|
|
1440
|
+
var FAILSAFE_SCHEMA = new Schema([
|
|
1441
|
+
strTag,
|
|
1442
|
+
seqTag,
|
|
1443
|
+
mapTag
|
|
1444
|
+
]);
|
|
1445
|
+
new Schema([
|
|
1446
|
+
...FAILSAFE_SCHEMA.tags,
|
|
1447
|
+
nullJsonTag,
|
|
1448
|
+
boolJsonTag,
|
|
1449
|
+
intJsonTag,
|
|
1450
|
+
floatJsonTag
|
|
1451
|
+
]);
|
|
1452
|
+
/**
|
|
1453
|
+
* The default schema for the loaders. Note, {@link CORE_SCHEMA} comes
|
|
1454
|
+
* without the `!!merge` tag. You can easily enable it if needed.
|
|
1455
|
+
*
|
|
1456
|
+
* @example
|
|
1457
|
+
* Enable {@link mergeTag}:
|
|
1458
|
+
*
|
|
1459
|
+
* ```javascript
|
|
1460
|
+
* import { load, CORE_SCHEMA, mergeTag } from 'js-yaml'
|
|
1461
|
+
*
|
|
1462
|
+
* try {
|
|
1463
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag) })
|
|
1464
|
+
* } catch (e) {
|
|
1465
|
+
* console.error(e)
|
|
1466
|
+
* }
|
|
1467
|
+
* ```
|
|
1468
|
+
*
|
|
1469
|
+
* @category Schemas
|
|
1470
|
+
*/
|
|
1471
|
+
var CORE_SCHEMA = new Schema([
|
|
1472
|
+
...FAILSAFE_SCHEMA.tags,
|
|
1473
|
+
nullCoreTag,
|
|
1474
|
+
boolCoreTag,
|
|
1475
|
+
intCoreTag,
|
|
1476
|
+
floatCoreTag
|
|
1477
|
+
]);
|
|
1478
|
+
/**
|
|
1479
|
+
* The dumper schema for maximum compatibility. It combines all supported type
|
|
1480
|
+
* variants from YAML 1.1 and YAML 1.2 so strings matching any of them are
|
|
1481
|
+
* quoted. This makes the generated YAML more compatible with other parsers.
|
|
1482
|
+
*
|
|
1483
|
+
* The schema is based on YAML 1.1, but extends `!!int` and `!!float` to accept
|
|
1484
|
+
* both YAML 1.1 and Core Schema forms, since Core Schema supports some forms
|
|
1485
|
+
* that YAML 1.1 does not.
|
|
1486
|
+
*
|
|
1487
|
+
* @category Schemas
|
|
1488
|
+
*/
|
|
1489
|
+
var DUMP_SCHEMA = new Schema([
|
|
1490
|
+
...FAILSAFE_SCHEMA.tags,
|
|
1491
|
+
nullYaml11Tag,
|
|
1492
|
+
boolYaml11Tag,
|
|
1493
|
+
intYaml11Tag,
|
|
1494
|
+
floatYaml11Tag,
|
|
1495
|
+
timestampTag,
|
|
1496
|
+
mergeTag,
|
|
1497
|
+
binaryTag,
|
|
1498
|
+
omapTag,
|
|
1499
|
+
pairsTag,
|
|
1500
|
+
setTag
|
|
1501
|
+
]).withTags({
|
|
1502
|
+
...intYaml11Tag,
|
|
1503
|
+
resolve: (source, isExplicit, tagName) => {
|
|
1504
|
+
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
1505
|
+
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
1506
|
+
}
|
|
1507
|
+
}, {
|
|
1508
|
+
...floatYaml11Tag,
|
|
1509
|
+
resolve: (source, isExplicit, tagName) => {
|
|
1510
|
+
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
1511
|
+
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
defineMappingTag("tag:yaml.org,2002:map", {
|
|
1515
|
+
create: () => /* @__PURE__ */ new Map(),
|
|
1516
|
+
addPair: (container, key, value) => {
|
|
1517
|
+
container.set(key, value);
|
|
1518
|
+
return "";
|
|
1519
|
+
},
|
|
1520
|
+
has: (container, key) => container.has(key),
|
|
1521
|
+
keys: (container) => container.keys(),
|
|
1522
|
+
get: (container, key) => container.get(key),
|
|
1523
|
+
identify: (data) => data instanceof Map || isPlainObject(data),
|
|
1524
|
+
represent: (data) => {
|
|
1525
|
+
if (data instanceof Map) return data;
|
|
1526
|
+
const map = /* @__PURE__ */ new Map();
|
|
1527
|
+
const obj = data;
|
|
1528
|
+
for (const key of Object.keys(obj)) map.set(key, obj[key]);
|
|
1529
|
+
return map;
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
function normalizeKey(key) {
|
|
1533
|
+
if (Array.isArray(key)) {
|
|
1534
|
+
const array = Array.prototype.slice.call(key);
|
|
1535
|
+
for (let index = 0; index < array.length; index++) {
|
|
1536
|
+
if (Array.isArray(array[index])) return null;
|
|
1537
|
+
if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]";
|
|
1538
|
+
}
|
|
1539
|
+
return String(array);
|
|
1540
|
+
}
|
|
1541
|
+
if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
|
|
1542
|
+
return String(key);
|
|
1543
|
+
}
|
|
1544
|
+
defineMappingTag("tag:yaml.org,2002:map", {
|
|
1545
|
+
create: () => ({}),
|
|
1546
|
+
identify: isPlainObject,
|
|
1547
|
+
represent: (o) => {
|
|
1548
|
+
const map = /* @__PURE__ */ new Map();
|
|
1549
|
+
for (const key of Object.keys(o)) map.set(key, o[key]);
|
|
1550
|
+
return map;
|
|
1551
|
+
},
|
|
1552
|
+
addPair: (container, key, value) => {
|
|
1553
|
+
const normalizedKey = normalizeKey(key);
|
|
1554
|
+
if (normalizedKey === null) return "nested arrays are not supported inside keys";
|
|
1555
|
+
if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
|
|
1556
|
+
value,
|
|
1557
|
+
enumerable: true,
|
|
1558
|
+
configurable: true,
|
|
1559
|
+
writable: true
|
|
1560
|
+
});
|
|
1561
|
+
else container[normalizedKey] = value;
|
|
1562
|
+
return "";
|
|
1563
|
+
},
|
|
1564
|
+
has: (container, key) => {
|
|
1565
|
+
const normalizedKey = normalizeKey(key);
|
|
1566
|
+
return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
|
|
1567
|
+
},
|
|
1568
|
+
keys: (container) => Object.keys(container),
|
|
1569
|
+
get: (container, key) => {
|
|
1570
|
+
const normalizedKey = String(key);
|
|
1571
|
+
if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
|
|
1572
|
+
return container[normalizedKey];
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
var DEFAULT_SNIPPET_OPTIONS = {
|
|
1576
|
+
maxLength: 79,
|
|
1577
|
+
indent: 1,
|
|
1578
|
+
linesBefore: 3,
|
|
1579
|
+
linesAfter: 2
|
|
1580
|
+
};
|
|
1581
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
1582
|
+
let head = "";
|
|
1583
|
+
let tail = "";
|
|
1584
|
+
const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
1585
|
+
if (position - lineStart > maxHalfLength) {
|
|
1586
|
+
head = " ... ";
|
|
1587
|
+
lineStart = position - maxHalfLength + head.length;
|
|
1588
|
+
}
|
|
1589
|
+
if (lineEnd - position > maxHalfLength) {
|
|
1590
|
+
tail = " ...";
|
|
1591
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
1592
|
+
}
|
|
1593
|
+
return {
|
|
1594
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
|
|
1595
|
+
pos: position - lineStart + head.length
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function padStart(string, max) {
|
|
1599
|
+
return " ".repeat(Math.max(max - string.length, 0)) + string;
|
|
1600
|
+
}
|
|
1601
|
+
function makeSnippet(mark, options) {
|
|
1602
|
+
if (!mark.buffer) return null;
|
|
1603
|
+
const opts = {
|
|
1604
|
+
...DEFAULT_SNIPPET_OPTIONS,
|
|
1605
|
+
...options
|
|
1606
|
+
};
|
|
1607
|
+
const re = /\r?\n|\r|\0/g;
|
|
1608
|
+
const lineStarts = [0];
|
|
1609
|
+
const lineEnds = [];
|
|
1610
|
+
let match;
|
|
1611
|
+
let foundLineNo = -1;
|
|
1612
|
+
while (match = re.exec(mark.buffer)) {
|
|
1613
|
+
lineEnds.push(match.index);
|
|
1614
|
+
lineStarts.push(match.index + match[0].length);
|
|
1615
|
+
if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2;
|
|
1616
|
+
}
|
|
1617
|
+
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
1618
|
+
let result = "";
|
|
1619
|
+
const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
|
|
1620
|
+
const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
|
|
1621
|
+
for (let i = 1; i <= opts.linesBefore; i++) {
|
|
1622
|
+
if (foundLineNo - i < 0) break;
|
|
1623
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
1624
|
+
result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line.str}\n${result}`;
|
|
1625
|
+
}
|
|
1626
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
1627
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}\n`;
|
|
1628
|
+
result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^\n`;
|
|
1629
|
+
for (let i = 1; i <= opts.linesAfter; i++) {
|
|
1630
|
+
if (foundLineNo + i >= lineEnds.length) break;
|
|
1631
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
1632
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line.str}\n`;
|
|
1633
|
+
}
|
|
1634
|
+
return result.replace(/\n$/, "");
|
|
1635
|
+
}
|
|
1636
|
+
function formatError(exception, compact) {
|
|
1637
|
+
let where = "";
|
|
1638
|
+
if (!exception.mark) return exception.reason;
|
|
1639
|
+
if (exception.mark.name) where += `in "${exception.mark.name}" `;
|
|
1640
|
+
where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
|
|
1641
|
+
if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
|
|
1642
|
+
return `${exception.reason} ${where}`;
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* A YAML error. Unlike an ordinary `Error`, it adds a source snippet showing
|
|
1646
|
+
* the location of the problem to the error message, when available.
|
|
1647
|
+
*
|
|
1648
|
+
* @category Main
|
|
1649
|
+
*/
|
|
1650
|
+
var YAMLException = class YAMLException extends Error {
|
|
1651
|
+
reason;
|
|
1652
|
+
mark;
|
|
1653
|
+
/**
|
|
1654
|
+
* Optional `mark` contains source snippet data. Usually, use
|
|
1655
|
+
* {@link YAMLException.throwAt} instead of passing it directly.
|
|
1656
|
+
*/
|
|
1657
|
+
constructor(reason, mark) {
|
|
1658
|
+
super();
|
|
1659
|
+
this.name = "YAMLException";
|
|
1660
|
+
this.reason = reason;
|
|
1661
|
+
this.mark = mark;
|
|
1662
|
+
this.message = formatError(this, false);
|
|
1663
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Returns the formatted error, omitting the source snippet in compact mode.
|
|
1667
|
+
*/
|
|
1668
|
+
toString(compact) {
|
|
1669
|
+
return `${this.name}: ${formatError(this, compact)}`;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Builds a YAMLException with a source snippet and throws it. `source` is
|
|
1673
|
+
* the raw input text; `position` is an offset into it.
|
|
1674
|
+
*/
|
|
1675
|
+
static throwAt(source, position, message, filename = "") {
|
|
1676
|
+
let line = 0;
|
|
1677
|
+
let lineStart = 0;
|
|
1678
|
+
for (let index = 0; index < position; index++) {
|
|
1679
|
+
const ch = source.charCodeAt(index);
|
|
1680
|
+
if (ch === 10) {
|
|
1681
|
+
line++;
|
|
1682
|
+
lineStart = index + 1;
|
|
1683
|
+
} else if (ch === 13) {
|
|
1684
|
+
line++;
|
|
1685
|
+
if (source.charCodeAt(index + 1) === 10) index++;
|
|
1686
|
+
lineStart = index + 1;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const mark = {
|
|
1690
|
+
name: filename,
|
|
1691
|
+
buffer: source,
|
|
1692
|
+
position,
|
|
1693
|
+
line,
|
|
1694
|
+
column: position - lineStart
|
|
1695
|
+
};
|
|
1696
|
+
mark.snippet = makeSnippet(mark);
|
|
1697
|
+
throw new YAMLException(message, mark);
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
/** @category Events */
|
|
1701
|
+
var EVENT_ID = {
|
|
1702
|
+
DOCUMENT: 1,
|
|
1703
|
+
SEQUENCE: 2,
|
|
1704
|
+
MAPPING: 3,
|
|
1705
|
+
SCALAR: 4,
|
|
1706
|
+
ALIAS: 5,
|
|
1707
|
+
POP: 6
|
|
1708
|
+
};
|
|
1709
|
+
/** @category Nodes */
|
|
1710
|
+
var SCALAR_STYLE = {
|
|
1711
|
+
PLAIN: 1,
|
|
1712
|
+
SINGLE_QUOTED: 2,
|
|
1713
|
+
DOUBLE_QUOTED: 3,
|
|
1714
|
+
LITERAL_BLOCK: 4,
|
|
1715
|
+
FOLDED_BLOCK: 5
|
|
1716
|
+
};
|
|
1717
|
+
/** @category Nodes */
|
|
1718
|
+
var COLLECTION_STYLE = {
|
|
1719
|
+
BLOCK: 1,
|
|
1720
|
+
FLOW: 2
|
|
1721
|
+
};
|
|
1722
|
+
/** @category Nodes */
|
|
1723
|
+
var CHOMPING_MODE = {
|
|
1724
|
+
CLIP: 1,
|
|
1725
|
+
STRIP: 2,
|
|
1726
|
+
KEEP: 3
|
|
1727
|
+
};
|
|
1728
|
+
var NO_RANGE$3 = -1;
|
|
1729
|
+
function simpleEscapeSequence(c) {
|
|
1730
|
+
switch (c) {
|
|
1731
|
+
case 48: return "\0";
|
|
1732
|
+
case 97: return "\x07";
|
|
1733
|
+
case 98: return "\b";
|
|
1734
|
+
case 116: return " ";
|
|
1735
|
+
case 9: return " ";
|
|
1736
|
+
case 110: return "\n";
|
|
1737
|
+
case 118: return "\v";
|
|
1738
|
+
case 102: return "\f";
|
|
1739
|
+
case 114: return "\r";
|
|
1740
|
+
case 101: return "\x1B";
|
|
1741
|
+
case 32: return " ";
|
|
1742
|
+
case 34: return "\"";
|
|
1743
|
+
case 47: return "/";
|
|
1744
|
+
case 92: return "\\";
|
|
1745
|
+
case 78: return "
";
|
|
1746
|
+
case 95: return "\xA0";
|
|
1747
|
+
case 76: return "\u2028";
|
|
1748
|
+
case 80: return "\u2029";
|
|
1749
|
+
default: return "";
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
var simpleEscapeCheck = new Array(256);
|
|
1753
|
+
var simpleEscapeMap = new Array(256);
|
|
1754
|
+
for (let i = 0; i < 256; i++) {
|
|
1755
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1756
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1757
|
+
}
|
|
1758
|
+
function charFromCodepoint(c) {
|
|
1759
|
+
if (c <= 65535) return String.fromCharCode(c);
|
|
1760
|
+
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1761
|
+
}
|
|
1762
|
+
function fromHexCode$1(c) {
|
|
1763
|
+
if (c >= 48 && c <= 57) return c - 48;
|
|
1764
|
+
return (c | 32) - 97 + 10;
|
|
1765
|
+
}
|
|
1766
|
+
function escapedHexLen$1(c) {
|
|
1767
|
+
if (c === 120) return 2;
|
|
1768
|
+
if (c === 117) return 4;
|
|
1769
|
+
return 8;
|
|
1770
|
+
}
|
|
1771
|
+
function skipFoldedBreaks(input, position, end) {
|
|
1772
|
+
let breaks = 0;
|
|
1773
|
+
while (position < end) {
|
|
1774
|
+
const ch = input.charCodeAt(position);
|
|
1775
|
+
if (ch === 10) {
|
|
1776
|
+
breaks++;
|
|
1777
|
+
position++;
|
|
1778
|
+
} else if (ch === 13) {
|
|
1779
|
+
breaks++;
|
|
1780
|
+
position++;
|
|
1781
|
+
if (input.charCodeAt(position) === 10) position++;
|
|
1782
|
+
} else if (ch === 32 || ch === 9) position++;
|
|
1783
|
+
else break;
|
|
1784
|
+
}
|
|
1785
|
+
return {
|
|
1786
|
+
position,
|
|
1787
|
+
breaks
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
function foldedBreaks(count) {
|
|
1791
|
+
if (count === 1) return " ";
|
|
1792
|
+
return "\n".repeat(count - 1);
|
|
1793
|
+
}
|
|
1794
|
+
function getPlainValue(input, start, end) {
|
|
1795
|
+
let result = "";
|
|
1796
|
+
let position = start;
|
|
1797
|
+
let captureStart = start;
|
|
1798
|
+
let captureEnd = start;
|
|
1799
|
+
while (position < end) {
|
|
1800
|
+
const ch = input.charCodeAt(position);
|
|
1801
|
+
if (ch === 10 || ch === 13) {
|
|
1802
|
+
result += input.slice(captureStart, captureEnd);
|
|
1803
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1804
|
+
result += foldedBreaks(fold.breaks);
|
|
1805
|
+
position = captureStart = captureEnd = fold.position;
|
|
1806
|
+
} else {
|
|
1807
|
+
position++;
|
|
1808
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return result + input.slice(captureStart, captureEnd);
|
|
1812
|
+
}
|
|
1813
|
+
function getSingleQuotedValue(input, start, end) {
|
|
1814
|
+
let result = "";
|
|
1815
|
+
let position = start;
|
|
1816
|
+
let captureStart = start;
|
|
1817
|
+
let captureEnd = start;
|
|
1818
|
+
while (position < end) {
|
|
1819
|
+
const ch = input.charCodeAt(position);
|
|
1820
|
+
if (ch === 39) {
|
|
1821
|
+
result += input.slice(captureStart, position) + "'";
|
|
1822
|
+
position += 2;
|
|
1823
|
+
captureStart = captureEnd = position;
|
|
1824
|
+
} else if (ch === 10 || ch === 13) {
|
|
1825
|
+
result += input.slice(captureStart, captureEnd);
|
|
1826
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1827
|
+
result += foldedBreaks(fold.breaks);
|
|
1828
|
+
position = captureStart = captureEnd = fold.position;
|
|
1829
|
+
} else {
|
|
1830
|
+
position++;
|
|
1831
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
return result + input.slice(captureStart, end);
|
|
1835
|
+
}
|
|
1836
|
+
function getDoubleQuotedValue(input, start, end) {
|
|
1837
|
+
let result = "";
|
|
1838
|
+
let position = start;
|
|
1839
|
+
let captureStart = start;
|
|
1840
|
+
let captureEnd = start;
|
|
1841
|
+
while (position < end) {
|
|
1842
|
+
const ch = input.charCodeAt(position);
|
|
1843
|
+
if (ch === 92) {
|
|
1844
|
+
result += input.slice(captureStart, position);
|
|
1845
|
+
position++;
|
|
1846
|
+
const escaped = input.charCodeAt(position);
|
|
1847
|
+
if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position;
|
|
1848
|
+
else if (escaped < 256 && simpleEscapeCheck[escaped]) {
|
|
1849
|
+
result += simpleEscapeMap[escaped];
|
|
1850
|
+
position++;
|
|
1851
|
+
} else {
|
|
1852
|
+
let hexLength = escapedHexLen$1(escaped);
|
|
1853
|
+
let hexResult = 0;
|
|
1854
|
+
for (; hexLength > 0; hexLength--) {
|
|
1855
|
+
position++;
|
|
1856
|
+
const digit = fromHexCode$1(input.charCodeAt(position));
|
|
1857
|
+
hexResult = (hexResult << 4) + digit;
|
|
1858
|
+
}
|
|
1859
|
+
result += charFromCodepoint(hexResult);
|
|
1860
|
+
position++;
|
|
1861
|
+
}
|
|
1862
|
+
captureStart = captureEnd = position;
|
|
1863
|
+
} else if (ch === 10 || ch === 13) {
|
|
1864
|
+
result += input.slice(captureStart, captureEnd);
|
|
1865
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1866
|
+
result += foldedBreaks(fold.breaks);
|
|
1867
|
+
position = captureStart = captureEnd = fold.position;
|
|
1868
|
+
} else {
|
|
1869
|
+
position++;
|
|
1870
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
return result + input.slice(captureStart, end);
|
|
1874
|
+
}
|
|
1875
|
+
function getBlockValue(input, start, end, indent, chomping, folded) {
|
|
1876
|
+
const textIndent = indent < 0 ? 0 : indent;
|
|
1877
|
+
const region = input.slice(start, end).replace(/\r\n?/g, "\n");
|
|
1878
|
+
const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n");
|
|
1879
|
+
let result = "";
|
|
1880
|
+
let didReadContent = false;
|
|
1881
|
+
let emptyLines = 0;
|
|
1882
|
+
let atMoreIndented = false;
|
|
1883
|
+
for (const line of lines) {
|
|
1884
|
+
let column = 0;
|
|
1885
|
+
while (column < textIndent && line.charCodeAt(column) === 32) column++;
|
|
1886
|
+
if (indent < 0 || column >= line.length) {
|
|
1887
|
+
emptyLines++;
|
|
1888
|
+
continue;
|
|
1889
|
+
}
|
|
1890
|
+
const content = line.slice(textIndent);
|
|
1891
|
+
const first = content.charCodeAt(0);
|
|
1892
|
+
if (folded) {
|
|
1893
|
+
if (first === 32 || first === 9) {
|
|
1894
|
+
atMoreIndented = true;
|
|
1895
|
+
result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1896
|
+
} else if (atMoreIndented) {
|
|
1897
|
+
atMoreIndented = false;
|
|
1898
|
+
result += "\n".repeat(emptyLines + 1);
|
|
1899
|
+
} else if (emptyLines === 0) {
|
|
1900
|
+
if (didReadContent) result += " ";
|
|
1901
|
+
} else result += "\n".repeat(emptyLines);
|
|
1902
|
+
} else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1903
|
+
result += content;
|
|
1904
|
+
didReadContent = true;
|
|
1905
|
+
emptyLines = 0;
|
|
1906
|
+
}
|
|
1907
|
+
if (chomping === CHOMPING_MODE.KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1908
|
+
else if (chomping !== CHOMPING_MODE.STRIP) {
|
|
1909
|
+
if (didReadContent) result += "\n";
|
|
1910
|
+
}
|
|
1911
|
+
return result;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Decodes the scalar referenced by event offsets in `input`.
|
|
1915
|
+
*
|
|
1916
|
+
* @category Events
|
|
1917
|
+
*/
|
|
1918
|
+
function getScalarValue(input, scalar) {
|
|
1919
|
+
if (scalar.valueStart === NO_RANGE$3) return "";
|
|
1920
|
+
const { valueStart, valueEnd } = scalar;
|
|
1921
|
+
if (scalar.fast) return input.slice(valueStart, valueEnd);
|
|
1922
|
+
switch (scalar.style) {
|
|
1923
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return getSingleQuotedValue(input, valueStart, valueEnd);
|
|
1924
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return getDoubleQuotedValue(input, valueStart, valueEnd);
|
|
1925
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
|
|
1926
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
|
|
1927
|
+
default: return getPlainValue(input, valueStart, valueEnd);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
var DEFAULT_TAG_HANDLERS = Object.assign(Object.create(null), {
|
|
1931
|
+
"!": "!",
|
|
1932
|
+
"!!": "tag:yaml.org,2002:"
|
|
1933
|
+
});
|
|
1934
|
+
var TAG_SUFFIX_CHARS = "-#;/?:@&=+$_.~*'()";
|
|
1935
|
+
var TAG_URI_CHARS = TAG_SUFFIX_CHARS + "!,[]";
|
|
1936
|
+
var HEX = "0123456789ABCDEF";
|
|
1937
|
+
function percentByte(byte) {
|
|
1938
|
+
return "%" + HEX[byte >> 4] + HEX[byte & 15];
|
|
1939
|
+
}
|
|
1940
|
+
function tagPercentEncode(source, isSuffix) {
|
|
1941
|
+
const allowed = isSuffix ? TAG_SUFFIX_CHARS : TAG_URI_CHARS;
|
|
1942
|
+
let result = "";
|
|
1943
|
+
for (let index = 0; index < source.length; index++) {
|
|
1944
|
+
let ch = source.charCodeAt(index);
|
|
1945
|
+
if (ch >= 48 && ch <= 57 || ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || allowed.includes(source[index])) {
|
|
1946
|
+
result += source[index];
|
|
1947
|
+
continue;
|
|
1948
|
+
}
|
|
1949
|
+
if (ch >= 55296 && ch <= 56319) ch = 65536 + ((ch & 1023) << 10) + (source.charCodeAt(++index) & 1023);
|
|
1950
|
+
if (ch < 128) result += percentByte(ch);
|
|
1951
|
+
else if (ch < 2048) result += percentByte(192 | ch >> 6) + percentByte(128 | ch & 63);
|
|
1952
|
+
else if (ch < 65536) result += percentByte(224 | ch >> 12) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
|
|
1953
|
+
else result += percentByte(240 | ch >> 18) + percentByte(128 | ch >> 12 & 63) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
|
|
1954
|
+
}
|
|
1955
|
+
return result;
|
|
1956
|
+
}
|
|
1957
|
+
function tagPercentDecode(source) {
|
|
1958
|
+
let result = "";
|
|
1959
|
+
let index = 0;
|
|
1960
|
+
while (index < source.length) {
|
|
1961
|
+
if (source.charCodeAt(index) !== 37) {
|
|
1962
|
+
result += source[index++];
|
|
1963
|
+
continue;
|
|
1964
|
+
}
|
|
1965
|
+
let ch = parseInt(source.slice(index + 1, index + 3), 16);
|
|
1966
|
+
index += 3;
|
|
1967
|
+
if (ch >= 192) {
|
|
1968
|
+
let remaining = ch < 224 ? 1 : ch < 240 ? 2 : 3;
|
|
1969
|
+
ch &= (1 << 6 - remaining) - 1;
|
|
1970
|
+
while (remaining-- > 0) {
|
|
1971
|
+
ch = ch << 6 | parseInt(source.slice(index + 1, index + 3), 16) & 63;
|
|
1972
|
+
index += 3;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (ch < 65536) result += String.fromCharCode(ch);
|
|
1976
|
+
else {
|
|
1977
|
+
ch -= 65536;
|
|
1978
|
+
result += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
return result;
|
|
1982
|
+
}
|
|
1983
|
+
function tagNameFull(rawTag, tagHandlers) {
|
|
1984
|
+
if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return tagPercentDecode(rawTag.slice(2, -1));
|
|
1985
|
+
const handleEnd = rawTag.indexOf("!", 1);
|
|
1986
|
+
const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
|
|
1987
|
+
return tagPercentDecode(tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle) + tagPercentDecode(rawTag.slice(handle.length));
|
|
1988
|
+
}
|
|
1989
|
+
function tagNameShort(fullTag) {
|
|
1990
|
+
let tag = fullTag;
|
|
1991
|
+
if (tag.charCodeAt(0) === 33) {
|
|
1992
|
+
tag = tag.slice(1);
|
|
1993
|
+
return `!${tagPercentEncode(tag, true)}`;
|
|
1994
|
+
}
|
|
1995
|
+
if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18), true)}`;
|
|
1996
|
+
return `!<${tagPercentEncode(tag, false)}>`;
|
|
1997
|
+
}
|
|
1998
|
+
var NO_RANGE$2 = -1;
|
|
1999
|
+
var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
|
|
2000
|
+
var DEFAULT_CONSTRUCTOR_OPTIONS = {
|
|
2001
|
+
filename: "",
|
|
2002
|
+
schema: CORE_SCHEMA,
|
|
2003
|
+
json: false,
|
|
2004
|
+
maxTotalMergeKeys: 1e4,
|
|
2005
|
+
maxAliases: -1
|
|
2006
|
+
};
|
|
2007
|
+
function eventPosition$1(event) {
|
|
2008
|
+
if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart;
|
|
2009
|
+
if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart;
|
|
2010
|
+
if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart;
|
|
2011
|
+
if ("start" in event) return event.start;
|
|
2012
|
+
return 0;
|
|
2013
|
+
}
|
|
2014
|
+
function throwError$1(state, message) {
|
|
2015
|
+
YAMLException.throwAt(state.source, state.position, message, state.filename);
|
|
2016
|
+
}
|
|
2017
|
+
function finalizeCollection(state, position, tag, carrier) {
|
|
2018
|
+
try {
|
|
2019
|
+
return tag.finalize(carrier);
|
|
2020
|
+
} catch (error) {
|
|
2021
|
+
if (error instanceof YAMLException) throw error;
|
|
2022
|
+
YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
function constructScalar(state, event) {
|
|
2026
|
+
const source = getScalarValue(state.source, event);
|
|
2027
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
2028
|
+
const strTag = state.schema.defaultScalarTag;
|
|
2029
|
+
if (rawTag !== "") {
|
|
2030
|
+
if (rawTag === "!") return {
|
|
2031
|
+
value: source,
|
|
2032
|
+
tag: strTag
|
|
2033
|
+
};
|
|
2034
|
+
const tagName = tagNameFull(rawTag, state.tagHandlers);
|
|
2035
|
+
const scalarTag = state.schema.lookupScalarTag(tagName);
|
|
2036
|
+
if (scalarTag) {
|
|
2037
|
+
const result = scalarTag.resolve(source, true, tagName);
|
|
2038
|
+
if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
2039
|
+
return {
|
|
2040
|
+
value: result,
|
|
2041
|
+
tag: scalarTag
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
const collectionTagDef = state.schema.lookupMappingTag(tagName) ?? state.schema.lookupSequenceTag(tagName);
|
|
2045
|
+
if (collectionTagDef) {
|
|
2046
|
+
if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
2047
|
+
const carrier = collectionTagDef.create(tagName);
|
|
2048
|
+
return {
|
|
2049
|
+
value: collectionTagDef.carrierIsResult ? carrier : finalizeCollection(state, state.position, collectionTagDef, carrier),
|
|
2050
|
+
tag: collectionTagDef
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
throwError$1(state, `unknown scalar tag !<${tagName}>`);
|
|
2054
|
+
}
|
|
2055
|
+
if (event.style === SCALAR_STYLE.PLAIN) return state.schema.resolveImplicitScalarTag(source);
|
|
2056
|
+
return {
|
|
2057
|
+
value: strTag.resolve(source, false, strTag.tagName),
|
|
2058
|
+
tag: strTag
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
function collectionTagName(state, event, defaultTagName) {
|
|
2062
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
2063
|
+
return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
|
|
2064
|
+
}
|
|
2065
|
+
function isMappingTag(tag) {
|
|
2066
|
+
return tag.nodeKind === "mapping";
|
|
2067
|
+
}
|
|
2068
|
+
function chargeMergeWork(state) {
|
|
2069
|
+
state.totalMergeKeys++;
|
|
2070
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
|
|
2071
|
+
}
|
|
2072
|
+
function mergeKeys(state, frame, source, sourceTag) {
|
|
2073
|
+
chargeMergeWork(state);
|
|
2074
|
+
for (const sourceKey of sourceTag.keys(source)) {
|
|
2075
|
+
chargeMergeWork(state);
|
|
2076
|
+
if (frame.tag.has(frame.value, sourceKey)) continue;
|
|
2077
|
+
const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
|
|
2078
|
+
if (err) throwError$1(state, err);
|
|
2079
|
+
frame.overridable ??= /* @__PURE__ */ new Set();
|
|
2080
|
+
frame.overridable.add(sourceKey);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
function mergeSource(state, frame, source, sourceTag) {
|
|
2084
|
+
state.position = frame.keyPosition;
|
|
2085
|
+
if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
|
|
2086
|
+
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
|
|
2087
|
+
if (source.length > 100) throwError$1(state, "abnormal merge sequence size");
|
|
2088
|
+
for (const element of source) {
|
|
2089
|
+
const elementTag = state.nodeTags.get(element);
|
|
2090
|
+
if (!elementTag) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
2091
|
+
mergeKeys(state, frame, element, elementTag);
|
|
2092
|
+
}
|
|
2093
|
+
} else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
2094
|
+
}
|
|
2095
|
+
function addMappingValue(state, frame, key, value, tag) {
|
|
2096
|
+
state.position = frame.keyPosition;
|
|
2097
|
+
if (frame.keyIsMerge) {
|
|
2098
|
+
mergeSource(state, frame, value, tag);
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key)) throwError$1(state, "duplicated mapping key");
|
|
2102
|
+
const err = frame.tag.addPair(frame.value, key, value);
|
|
2103
|
+
if (err) throwError$1(state, err);
|
|
2104
|
+
frame.overridable?.delete(key);
|
|
2105
|
+
}
|
|
2106
|
+
function addValue(state, value, tag) {
|
|
2107
|
+
const frame = state.frames[state.frames.length - 1];
|
|
2108
|
+
if (frame.kind === "document") {
|
|
2109
|
+
frame.value = value;
|
|
2110
|
+
frame.hasValue = true;
|
|
2111
|
+
} else if (frame.kind === "sequence") {
|
|
2112
|
+
if (isMappingTag(tag)) state.nodeTags.set(value, tag);
|
|
2113
|
+
const err = frame.tag.addItem(frame.value, value, frame.index++);
|
|
2114
|
+
if (err) throwError$1(state, err);
|
|
2115
|
+
} else if (frame.hasKey) {
|
|
2116
|
+
const key = frame.key;
|
|
2117
|
+
frame.key = void 0;
|
|
2118
|
+
frame.hasKey = false;
|
|
2119
|
+
addMappingValue(state, frame, key, value, tag);
|
|
2120
|
+
} else {
|
|
2121
|
+
frame.key = value;
|
|
2122
|
+
frame.keyPosition = state.position;
|
|
2123
|
+
frame.hasKey = true;
|
|
2124
|
+
frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
2128
|
+
if (event.anchorStart !== NO_RANGE$2) {
|
|
2129
|
+
const anchor = {
|
|
2130
|
+
value,
|
|
2131
|
+
tag,
|
|
2132
|
+
isValueFinal
|
|
2133
|
+
};
|
|
2134
|
+
state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), anchor);
|
|
2135
|
+
return anchor;
|
|
2136
|
+
}
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* Constructs JavaScript documents directly from parser events, without an
|
|
2141
|
+
* intermediate AST.
|
|
2142
|
+
*
|
|
2143
|
+
* @category Events
|
|
2144
|
+
*/
|
|
2145
|
+
function constructFromEvents(events, options) {
|
|
2146
|
+
const state = {
|
|
2147
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS,
|
|
2148
|
+
...options,
|
|
2149
|
+
events,
|
|
2150
|
+
documents: [],
|
|
2151
|
+
eventIndex: 0,
|
|
2152
|
+
position: 0,
|
|
2153
|
+
frames: [],
|
|
2154
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
2155
|
+
nodeTags: /* @__PURE__ */ new Map(),
|
|
2156
|
+
tagHandlers: Object.create(null),
|
|
2157
|
+
totalMergeKeys: 0,
|
|
2158
|
+
aliasCount: 0
|
|
2159
|
+
};
|
|
2160
|
+
while (state.eventIndex < state.events.length) {
|
|
2161
|
+
const event = state.events[state.eventIndex++];
|
|
2162
|
+
state.position = eventPosition$1(event);
|
|
2163
|
+
switch (event.type) {
|
|
2164
|
+
case EVENT_ID.DOCUMENT:
|
|
2165
|
+
state.anchors = /* @__PURE__ */ new Map();
|
|
2166
|
+
state.nodeTags = /* @__PURE__ */ new Map();
|
|
2167
|
+
state.aliasCount = 0;
|
|
2168
|
+
state.tagHandlers = Object.create(null);
|
|
2169
|
+
for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
|
|
2170
|
+
state.frames.push({
|
|
2171
|
+
kind: "document",
|
|
2172
|
+
position: state.position,
|
|
2173
|
+
value: void 0,
|
|
2174
|
+
hasValue: false
|
|
2175
|
+
});
|
|
2176
|
+
break;
|
|
2177
|
+
case EVENT_ID.SCALAR: {
|
|
2178
|
+
const { value, tag } = constructScalar(state, event);
|
|
2179
|
+
storeAnchor(state, event, value, tag, true);
|
|
2180
|
+
addValue(state, value, tag);
|
|
2181
|
+
break;
|
|
2182
|
+
}
|
|
2183
|
+
case EVENT_ID.SEQUENCE: {
|
|
2184
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
|
|
2185
|
+
const tag = state.schema.lookupSequenceTag(tagName);
|
|
2186
|
+
if (!tag) throwError$1(state, `unknown sequence tag !<${tagName}>`);
|
|
2187
|
+
const value = tag.create(tagName);
|
|
2188
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
2189
|
+
state.frames.push({
|
|
2190
|
+
kind: "sequence",
|
|
2191
|
+
position: state.position,
|
|
2192
|
+
value,
|
|
2193
|
+
tag,
|
|
2194
|
+
anchor,
|
|
2195
|
+
index: 0
|
|
2196
|
+
});
|
|
2197
|
+
break;
|
|
2198
|
+
}
|
|
2199
|
+
case EVENT_ID.MAPPING: {
|
|
2200
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
|
|
2201
|
+
const tag = state.schema.lookupMappingTag(tagName);
|
|
2202
|
+
if (!tag) throwError$1(state, `unknown mapping tag !<${tagName}>`);
|
|
2203
|
+
const value = tag.create(tagName);
|
|
2204
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
2205
|
+
state.frames.push({
|
|
2206
|
+
kind: "mapping",
|
|
2207
|
+
position: state.position,
|
|
2208
|
+
value,
|
|
2209
|
+
tag,
|
|
2210
|
+
anchor,
|
|
2211
|
+
key: void 0,
|
|
2212
|
+
keyPosition: state.position,
|
|
2213
|
+
hasKey: false,
|
|
2214
|
+
keyIsMerge: false,
|
|
2215
|
+
overridable: null
|
|
2216
|
+
});
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
case EVENT_ID.ALIAS: {
|
|
2220
|
+
if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
|
|
2221
|
+
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
2222
|
+
const anchor = state.anchors.get(name);
|
|
2223
|
+
if (!anchor) throwError$1(state, `unidentified alias "${name}"`);
|
|
2224
|
+
if (!anchor.isValueFinal) throwError$1(state, `recursive alias "${name}" is not supported for tag ${anchor.tag.tagName} because it uses finalize()`);
|
|
2225
|
+
addValue(state, anchor.value, anchor.tag);
|
|
2226
|
+
break;
|
|
2227
|
+
}
|
|
2228
|
+
case EVENT_ID.POP: {
|
|
2229
|
+
const frame = state.frames.pop();
|
|
2230
|
+
if (frame.kind === "mapping" && frame.hasKey) {
|
|
2231
|
+
state.position = frame.keyPosition;
|
|
2232
|
+
throwError$1(state, "incomplete mapping pair in event stream");
|
|
2233
|
+
}
|
|
2234
|
+
if (frame.kind === "document") state.documents.push(frame.value);
|
|
2235
|
+
else {
|
|
2236
|
+
const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
|
|
2237
|
+
if (frame.anchor) {
|
|
2238
|
+
frame.anchor.value = value;
|
|
2239
|
+
frame.anchor.isValueFinal = true;
|
|
2240
|
+
}
|
|
2241
|
+
addValue(state, value, frame.tag);
|
|
2242
|
+
}
|
|
2243
|
+
break;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
return state.documents;
|
|
2248
|
+
}
|
|
2249
|
+
var NO_RANGE$1 = -1;
|
|
2250
|
+
var HAS_OWN = Object.prototype.hasOwnProperty;
|
|
2251
|
+
var CONTEXT_FLOW_IN = 1;
|
|
2252
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
2253
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
2254
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
2255
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
2256
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
|
|
2257
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
|
|
2258
|
+
var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
|
|
2259
|
+
var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
|
|
2260
|
+
var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
|
|
2261
|
+
var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
|
|
2262
|
+
var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
|
|
2263
|
+
var DEFAULT_PARSER_OPTIONS = {
|
|
2264
|
+
filename: "",
|
|
2265
|
+
maxDepth: 100
|
|
2266
|
+
};
|
|
2267
|
+
function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
2268
|
+
state.events.push({
|
|
2269
|
+
type: EVENT_ID.DOCUMENT,
|
|
2270
|
+
explicitStart,
|
|
2271
|
+
explicitEnd,
|
|
2272
|
+
directives: state.directives
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
2276
|
+
state.events.push({
|
|
2277
|
+
type: EVENT_ID.SEQUENCE,
|
|
2278
|
+
start,
|
|
2279
|
+
anchorStart,
|
|
2280
|
+
anchorEnd,
|
|
2281
|
+
tagStart,
|
|
2282
|
+
tagEnd,
|
|
2283
|
+
style
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
2287
|
+
state.events.push({
|
|
2288
|
+
type: EVENT_ID.MAPPING,
|
|
2289
|
+
start,
|
|
2290
|
+
anchorStart,
|
|
2291
|
+
anchorEnd,
|
|
2292
|
+
tagStart,
|
|
2293
|
+
tagEnd,
|
|
2294
|
+
style
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
function insertFlowPairMappingEvent(state, snapshot) {
|
|
2298
|
+
state.events.splice(snapshot.eventsLength, 0, {
|
|
2299
|
+
type: EVENT_ID.MAPPING,
|
|
2300
|
+
start: snapshot.position,
|
|
2301
|
+
anchorStart: NO_RANGE$1,
|
|
2302
|
+
anchorEnd: NO_RANGE$1,
|
|
2303
|
+
tagStart: NO_RANGE$1,
|
|
2304
|
+
tagEnd: NO_RANGE$1,
|
|
2305
|
+
style: COLLECTION_STYLE.FLOW
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
|
|
2309
|
+
state.events.push({
|
|
2310
|
+
type: EVENT_ID.SCALAR,
|
|
2311
|
+
valueStart,
|
|
2312
|
+
valueEnd,
|
|
2313
|
+
anchorStart,
|
|
2314
|
+
anchorEnd,
|
|
2315
|
+
tagStart,
|
|
2316
|
+
tagEnd,
|
|
2317
|
+
style,
|
|
2318
|
+
chomping,
|
|
2319
|
+
indent,
|
|
2320
|
+
fast
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
function addAliasEvent(state, anchorStart, anchorEnd) {
|
|
2324
|
+
state.events.push({
|
|
2325
|
+
type: EVENT_ID.ALIAS,
|
|
2326
|
+
anchorStart,
|
|
2327
|
+
anchorEnd
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
function addPopEvent(state) {
|
|
2331
|
+
state.events.push({ type: EVENT_ID.POP });
|
|
2332
|
+
}
|
|
2333
|
+
function addEmptyScalarEvent(state) {
|
|
2334
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
|
|
2335
|
+
}
|
|
2336
|
+
function emptyProperties() {
|
|
2337
|
+
return {
|
|
2338
|
+
anchorStart: NO_RANGE$1,
|
|
2339
|
+
anchorEnd: NO_RANGE$1,
|
|
2340
|
+
tagStart: NO_RANGE$1,
|
|
2341
|
+
tagEnd: NO_RANGE$1
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
function snapshotState(state) {
|
|
2345
|
+
return {
|
|
2346
|
+
position: state.position,
|
|
2347
|
+
line: state.line,
|
|
2348
|
+
lineStart: state.lineStart,
|
|
2349
|
+
lineIndent: state.lineIndent,
|
|
2350
|
+
firstTabInLine: state.firstTabInLine,
|
|
2351
|
+
eventsLength: state.events.length
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
function restoreState(state, snapshot) {
|
|
2355
|
+
state.position = snapshot.position;
|
|
2356
|
+
state.line = snapshot.line;
|
|
2357
|
+
state.lineStart = snapshot.lineStart;
|
|
2358
|
+
state.lineIndent = snapshot.lineIndent;
|
|
2359
|
+
state.firstTabInLine = snapshot.firstTabInLine;
|
|
2360
|
+
state.events.length = snapshot.eventsLength;
|
|
2361
|
+
}
|
|
2362
|
+
function throwError(state, message) {
|
|
2363
|
+
YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
|
|
2364
|
+
}
|
|
2365
|
+
function isEol(c) {
|
|
2366
|
+
return c === 10 || c === 13;
|
|
2367
|
+
}
|
|
2368
|
+
function isWhiteSpace(c) {
|
|
2369
|
+
return c === 9 || c === 32;
|
|
2370
|
+
}
|
|
2371
|
+
function isWsOrEol(c) {
|
|
2372
|
+
return isWhiteSpace(c) || isEol(c);
|
|
2373
|
+
}
|
|
2374
|
+
function isWsOrEolOrEnd(c) {
|
|
2375
|
+
return c === 0 || isWsOrEol(c);
|
|
2376
|
+
}
|
|
2377
|
+
function isFlowIndicator(c) {
|
|
2378
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
2379
|
+
}
|
|
2380
|
+
function fromDecimalCode(c) {
|
|
2381
|
+
return c >= 48 && c <= 57 ? c - 48 : -1;
|
|
2382
|
+
}
|
|
2383
|
+
function fromHexCode(c) {
|
|
2384
|
+
if (c >= 48 && c <= 57) return c - 48;
|
|
2385
|
+
const lc = c | 32;
|
|
2386
|
+
if (lc >= 97 && lc <= 102) return lc - 97 + 10;
|
|
2387
|
+
return -1;
|
|
2388
|
+
}
|
|
2389
|
+
function escapedHexLen(c) {
|
|
2390
|
+
if (c === 120) return 2;
|
|
2391
|
+
if (c === 117) return 4;
|
|
2392
|
+
if (c === 85) return 8;
|
|
2393
|
+
return 0;
|
|
2394
|
+
}
|
|
2395
|
+
function isSimpleEscape(c) {
|
|
2396
|
+
return c === 48 || c === 97 || c === 98 || c === 116 || c === 9 || c === 110 || c === 118 || c === 102 || c === 114 || c === 101 || c === 32 || c === 34 || c === 47 || c === 92 || c === 78 || c === 95 || c === 76 || c === 80;
|
|
2397
|
+
}
|
|
2398
|
+
function consumeLineBreak(state) {
|
|
2399
|
+
if (state.input.charCodeAt(state.position) === 10) state.position++;
|
|
2400
|
+
else {
|
|
2401
|
+
state.position++;
|
|
2402
|
+
if (state.input.charCodeAt(state.position) === 10) state.position++;
|
|
2403
|
+
}
|
|
2404
|
+
state.line++;
|
|
2405
|
+
state.lineStart = state.position;
|
|
2406
|
+
state.lineIndent = 0;
|
|
2407
|
+
state.firstTabInLine = -1;
|
|
2408
|
+
}
|
|
2409
|
+
function skipSeparationSpace(state, allowComments) {
|
|
2410
|
+
let lineBreaks = 0;
|
|
2411
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2412
|
+
let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
|
|
2413
|
+
while (ch !== 0) {
|
|
2414
|
+
while (isWhiteSpace(ch)) {
|
|
2415
|
+
hasSeparation = true;
|
|
2416
|
+
if (ch === 9 && state.firstTabInLine === -1) state.firstTabInLine = state.position;
|
|
2417
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2418
|
+
}
|
|
2419
|
+
if (allowComments && hasSeparation && ch === 35) do
|
|
2420
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2421
|
+
while (!isEol(ch) && ch !== 0);
|
|
2422
|
+
if (!isEol(ch)) break;
|
|
2423
|
+
consumeLineBreak(state);
|
|
2424
|
+
lineBreaks++;
|
|
2425
|
+
hasSeparation = true;
|
|
2426
|
+
ch = state.input.charCodeAt(state.position);
|
|
2427
|
+
while (ch === 32) {
|
|
2428
|
+
state.lineIndent++;
|
|
2429
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
return lineBreaks;
|
|
2433
|
+
}
|
|
2434
|
+
function testDocumentSeparator(state, position = state.position) {
|
|
2435
|
+
const ch = state.input.charCodeAt(position);
|
|
2436
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
|
|
2437
|
+
const following = state.input.charCodeAt(position + 3);
|
|
2438
|
+
return following === 0 || isWsOrEol(following);
|
|
2439
|
+
}
|
|
2440
|
+
return false;
|
|
2441
|
+
}
|
|
2442
|
+
function skipByteOrderMark(state) {
|
|
2443
|
+
if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
|
|
2444
|
+
state.position++;
|
|
2445
|
+
state.lineStart = state.position;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
function testDocumentBoundary(state) {
|
|
2449
|
+
if (state.position !== state.lineStart) return false;
|
|
2450
|
+
if (testDocumentSeparator(state)) return true;
|
|
2451
|
+
if (state.input.charCodeAt(state.position) !== 65279) return false;
|
|
2452
|
+
const snapshot = snapshotState(state);
|
|
2453
|
+
skipByteOrderMark(state);
|
|
2454
|
+
skipSeparationSpace(state, true);
|
|
2455
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2456
|
+
const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
|
|
2457
|
+
restoreState(state, snapshot);
|
|
2458
|
+
return result;
|
|
2459
|
+
}
|
|
2460
|
+
function skipUntilLineEnd(state) {
|
|
2461
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2462
|
+
while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
|
|
2463
|
+
}
|
|
2464
|
+
function checkPrintable(state, start, end) {
|
|
2465
|
+
const match = PATTERN_NON_PRINTABLE.exec(state.input.slice(start, end));
|
|
2466
|
+
if (match !== null) {
|
|
2467
|
+
state.position = start + match.index + match[0].length - 1;
|
|
2468
|
+
throwError(state, "the stream contains non-printable characters");
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
function readTagProperty(state, props, inFlow) {
|
|
2472
|
+
if (state.input.charCodeAt(state.position) !== 33) return false;
|
|
2473
|
+
if (props.tagStart !== NO_RANGE$1) throwError(state, "duplication of a tag property");
|
|
2474
|
+
const start = state.position;
|
|
2475
|
+
let isVerbatim = false;
|
|
2476
|
+
let isNamed = false;
|
|
2477
|
+
let tagHandle = "!";
|
|
2478
|
+
let ch = state.input.charCodeAt(++state.position);
|
|
2479
|
+
if (ch === 60) {
|
|
2480
|
+
isVerbatim = true;
|
|
2481
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2482
|
+
} else if (ch === 33) {
|
|
2483
|
+
isNamed = true;
|
|
2484
|
+
tagHandle = "!!";
|
|
2485
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2486
|
+
}
|
|
2487
|
+
let suffixStart = state.position;
|
|
2488
|
+
let tagName;
|
|
2489
|
+
if (isVerbatim) {
|
|
2490
|
+
while (ch !== 0 && ch !== 62) ch = state.input.charCodeAt(++state.position);
|
|
2491
|
+
if (ch !== 62) throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2492
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
2493
|
+
state.position++;
|
|
2494
|
+
} else {
|
|
2495
|
+
while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
|
|
2496
|
+
if (ch === 33) {
|
|
2497
|
+
if (!isNamed) {
|
|
2498
|
+
tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
|
|
2499
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
|
|
2500
|
+
isNamed = true;
|
|
2501
|
+
suffixStart = state.position + 1;
|
|
2502
|
+
} else throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2503
|
+
}
|
|
2504
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2505
|
+
}
|
|
2506
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
2507
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2508
|
+
}
|
|
2509
|
+
if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName))) throwError(state, `tag name cannot contain such characters: ${tagName}`);
|
|
2510
|
+
if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle)) throwError(state, `undeclared tag handle "${tagHandle}"`);
|
|
2511
|
+
props.tagStart = start;
|
|
2512
|
+
props.tagEnd = state.position;
|
|
2513
|
+
return true;
|
|
2514
|
+
}
|
|
2515
|
+
function readAnchorProperty(state, props) {
|
|
2516
|
+
if (state.input.charCodeAt(state.position) !== 38) return false;
|
|
2517
|
+
if (props.anchorStart !== NO_RANGE$1) throwError(state, "duplication of an anchor property");
|
|
2518
|
+
state.position++;
|
|
2519
|
+
const start = state.position;
|
|
2520
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
|
|
2521
|
+
if (state.position === start) throwError(state, "name of an anchor node must contain at least one character");
|
|
2522
|
+
props.anchorStart = start;
|
|
2523
|
+
props.anchorEnd = state.position;
|
|
2524
|
+
return true;
|
|
2525
|
+
}
|
|
2526
|
+
function readAlias(state, props) {
|
|
2527
|
+
if (state.input.charCodeAt(state.position) !== 42) return false;
|
|
2528
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) throwError(state, "alias node should not have any properties");
|
|
2529
|
+
state.position++;
|
|
2530
|
+
const start = state.position;
|
|
2531
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
|
|
2532
|
+
if (state.position === start) throwError(state, "name of an alias node must contain at least one character");
|
|
2533
|
+
addAliasEvent(state, start, state.position);
|
|
2534
|
+
return true;
|
|
2535
|
+
}
|
|
2536
|
+
function readFlowScalarBreak(state, nodeIndent) {
|
|
2537
|
+
skipSeparationSpace(state, false);
|
|
2538
|
+
if (state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
|
|
2539
|
+
}
|
|
2540
|
+
function readSingleQuotedScalar(state, nodeIndent, props) {
|
|
2541
|
+
if (state.input.charCodeAt(state.position) !== 39) return false;
|
|
2542
|
+
state.position++;
|
|
2543
|
+
const start = state.position;
|
|
2544
|
+
let simple = true;
|
|
2545
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2546
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2547
|
+
if (ch === 39) {
|
|
2548
|
+
if (state.input.charCodeAt(state.position + 1) === 39) {
|
|
2549
|
+
simple = false;
|
|
2550
|
+
state.position += 2;
|
|
2551
|
+
continue;
|
|
2552
|
+
}
|
|
2553
|
+
const end = state.position;
|
|
2554
|
+
state.position++;
|
|
2555
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
2556
|
+
return true;
|
|
2557
|
+
}
|
|
2558
|
+
if (isEol(ch)) {
|
|
2559
|
+
simple = false;
|
|
2560
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
2561
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
2562
|
+
else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
|
|
2563
|
+
else state.position++;
|
|
2564
|
+
}
|
|
2565
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
2566
|
+
}
|
|
2567
|
+
function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
2568
|
+
if (state.input.charCodeAt(state.position) !== 34) return false;
|
|
2569
|
+
state.position++;
|
|
2570
|
+
const start = state.position;
|
|
2571
|
+
let simple = true;
|
|
2572
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2573
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2574
|
+
if (ch === 34) {
|
|
2575
|
+
const end = state.position;
|
|
2576
|
+
state.position++;
|
|
2577
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
2578
|
+
return true;
|
|
2579
|
+
}
|
|
2580
|
+
if (ch === 92) {
|
|
2581
|
+
simple = false;
|
|
2582
|
+
const escaped = state.input.charCodeAt(++state.position);
|
|
2583
|
+
if (isEol(escaped)) readFlowScalarBreak(state, nodeIndent);
|
|
2584
|
+
else if (isSimpleEscape(escaped)) state.position++;
|
|
2585
|
+
else {
|
|
2586
|
+
let hexLength = escapedHexLen(escaped);
|
|
2587
|
+
if (hexLength === 0) throwError(state, "unknown escape sequence");
|
|
2588
|
+
while (hexLength-- > 0) {
|
|
2589
|
+
state.position++;
|
|
2590
|
+
if (fromHexCode(state.input.charCodeAt(state.position)) < 0) throwError(state, "expected hexadecimal character");
|
|
2591
|
+
}
|
|
2592
|
+
state.position++;
|
|
2593
|
+
}
|
|
2594
|
+
} else if (isEol(ch)) {
|
|
2595
|
+
simple = false;
|
|
2596
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
2597
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
2598
|
+
else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
|
|
2599
|
+
else state.position++;
|
|
2600
|
+
}
|
|
2601
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
2602
|
+
}
|
|
2603
|
+
function readBlockScalar(state, parentIndent, props) {
|
|
2604
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2605
|
+
let chomping = CHOMPING_MODE.CLIP;
|
|
2606
|
+
let indent = -1;
|
|
2607
|
+
let detectedIndent = false;
|
|
2608
|
+
if (ch !== 124 && ch !== 62) return false;
|
|
2609
|
+
const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
|
|
2610
|
+
state.position++;
|
|
2611
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2612
|
+
const current = state.input.charCodeAt(state.position);
|
|
2613
|
+
const digit = fromDecimalCode(current);
|
|
2614
|
+
if (current === 43 || current === 45) {
|
|
2615
|
+
if (chomping !== CHOMPING_MODE.CLIP) throwError(state, "repeat of a chomping mode identifier");
|
|
2616
|
+
chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
|
|
2617
|
+
state.position++;
|
|
2618
|
+
} else if (digit >= 0) {
|
|
2619
|
+
if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
2620
|
+
if (detectedIndent) throwError(state, "repeat of an indentation width identifier");
|
|
2621
|
+
indent = parentIndent + digit - 1;
|
|
2622
|
+
detectedIndent = true;
|
|
2623
|
+
state.position++;
|
|
2624
|
+
} else break;
|
|
2625
|
+
}
|
|
2626
|
+
let hadWhitespace = false;
|
|
2627
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position))) {
|
|
2628
|
+
hadWhitespace = true;
|
|
2629
|
+
state.position++;
|
|
2630
|
+
}
|
|
2631
|
+
if (hadWhitespace && state.input.charCodeAt(state.position) === 35) skipUntilLineEnd(state);
|
|
2632
|
+
if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
|
|
2633
|
+
else if (state.input.charCodeAt(state.position) !== 0) throwError(state, "a line break is expected");
|
|
2634
|
+
let contentIndent = detectedIndent ? indent : -1;
|
|
2635
|
+
let maxLeadingIndent = 0;
|
|
2636
|
+
const valueStart = state.position;
|
|
2637
|
+
let valueEnd = state.position;
|
|
2638
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2639
|
+
const linePosition = state.position;
|
|
2640
|
+
let column = 0;
|
|
2641
|
+
while (state.input.charCodeAt(linePosition + column) === 32) column++;
|
|
2642
|
+
const first = state.input.charCodeAt(linePosition + column);
|
|
2643
|
+
if (first === 0) {
|
|
2644
|
+
if (contentIndent >= 0) {
|
|
2645
|
+
if (column > contentIndent) valueEnd = linePosition + column;
|
|
2646
|
+
} else if (column > 0) valueEnd = linePosition + column;
|
|
2647
|
+
break;
|
|
2648
|
+
}
|
|
2649
|
+
if (testDocumentBoundary(state)) break;
|
|
2650
|
+
if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
|
|
2651
|
+
if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
|
|
2652
|
+
if (first === 9 && column < parentIndent) {
|
|
2653
|
+
state.position = linePosition + column;
|
|
2654
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2655
|
+
}
|
|
2656
|
+
if (column >= parentIndent && column < maxLeadingIndent) {
|
|
2657
|
+
state.position = linePosition + column;
|
|
2658
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
|
|
2662
|
+
state.lineIndent = column;
|
|
2663
|
+
state.position = linePosition + column;
|
|
2664
|
+
break;
|
|
2665
|
+
}
|
|
2666
|
+
if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1) contentIndent = column;
|
|
2667
|
+
const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
|
|
2668
|
+
if (first !== 0 && !isEol(first) && column < requiredIndent) {
|
|
2669
|
+
state.lineIndent = column;
|
|
2670
|
+
state.position = linePosition + column;
|
|
2671
|
+
break;
|
|
2672
|
+
}
|
|
2673
|
+
skipUntilLineEnd(state);
|
|
2674
|
+
valueEnd = state.position;
|
|
2675
|
+
if (isEol(state.input.charCodeAt(state.position))) {
|
|
2676
|
+
consumeLineBreak(state);
|
|
2677
|
+
valueEnd = state.position;
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
checkPrintable(state, valueStart, valueEnd);
|
|
2681
|
+
addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
|
|
2682
|
+
return true;
|
|
2683
|
+
}
|
|
2684
|
+
function canStartPlainScalar(state, nodeContext) {
|
|
2685
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2686
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2687
|
+
if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || isFlowIndicator(ch)) return false;
|
|
2688
|
+
if (ch === 63 || ch === 45) {
|
|
2689
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2690
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
|
|
2691
|
+
}
|
|
2692
|
+
return true;
|
|
2693
|
+
}
|
|
2694
|
+
function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
2695
|
+
if (!canStartPlainScalar(state, nodeContext)) return false;
|
|
2696
|
+
const start = state.position;
|
|
2697
|
+
let end = state.position;
|
|
2698
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2699
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2700
|
+
let multiline = false;
|
|
2701
|
+
while (ch !== 0) {
|
|
2702
|
+
if (testDocumentBoundary(state)) break;
|
|
2703
|
+
if (ch === 58) {
|
|
2704
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2705
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
|
|
2706
|
+
} else if (ch === 35) {
|
|
2707
|
+
if (isWsOrEol(state.input.charCodeAt(state.position - 1))) break;
|
|
2708
|
+
} else if (inFlow && isFlowIndicator(ch)) break;
|
|
2709
|
+
else if (isEol(ch)) {
|
|
2710
|
+
const savedPosition = state.position;
|
|
2711
|
+
const savedLine = state.line;
|
|
2712
|
+
const savedLineStart = state.lineStart;
|
|
2713
|
+
const savedLineIndent = state.lineIndent;
|
|
2714
|
+
skipSeparationSpace(state, false);
|
|
2715
|
+
if (state.lineIndent >= nodeIndent) {
|
|
2716
|
+
multiline = true;
|
|
2717
|
+
ch = state.input.charCodeAt(state.position);
|
|
2718
|
+
continue;
|
|
2719
|
+
}
|
|
2720
|
+
state.position = savedPosition;
|
|
2721
|
+
state.line = savedLine;
|
|
2722
|
+
state.lineStart = savedLineStart;
|
|
2723
|
+
state.lineIndent = savedLineIndent;
|
|
2724
|
+
break;
|
|
2725
|
+
}
|
|
2726
|
+
if (!isWhiteSpace(ch)) end = state.position + 1;
|
|
2727
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2728
|
+
}
|
|
2729
|
+
if (end === start) return false;
|
|
2730
|
+
checkPrintable(state, start, end);
|
|
2731
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
|
|
2732
|
+
return true;
|
|
2733
|
+
}
|
|
2734
|
+
function skipFlowSeparationSpace(state, nodeIndent) {
|
|
2735
|
+
const startLine = state.line;
|
|
2736
|
+
skipSeparationSpace(state, true);
|
|
2737
|
+
if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
|
|
2738
|
+
}
|
|
2739
|
+
function readFlowCollection(state, nodeIndent, props) {
|
|
2740
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2741
|
+
const isMapping = ch === 123;
|
|
2742
|
+
const start = state.position;
|
|
2743
|
+
let readNext = true;
|
|
2744
|
+
if (ch !== 91 && ch !== 123) return false;
|
|
2745
|
+
const terminator = isMapping ? 125 : 93;
|
|
2746
|
+
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2747
|
+
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2748
|
+
state.position++;
|
|
2749
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2750
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2751
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2752
|
+
if (ch === terminator) {
|
|
2753
|
+
state.position++;
|
|
2754
|
+
addPopEvent(state);
|
|
2755
|
+
return true;
|
|
2756
|
+
} else if (!readNext) throwError(state, "missed comma between flow collection entries");
|
|
2757
|
+
else if (ch === 44) throwError(state, "expected the node content, but found ','");
|
|
2758
|
+
let isPair = false;
|
|
2759
|
+
let isExplicitPair = false;
|
|
2760
|
+
if (ch === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
|
|
2761
|
+
isPair = isExplicitPair = true;
|
|
2762
|
+
state.position += 1;
|
|
2763
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2764
|
+
}
|
|
2765
|
+
const entryLine = state.line;
|
|
2766
|
+
const entryStart = snapshotState(state);
|
|
2767
|
+
const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2768
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2769
|
+
ch = state.input.charCodeAt(state.position);
|
|
2770
|
+
if ((isMapping || isExplicitPair || state.line === entryLine) && ch === 58) {
|
|
2771
|
+
isPair = true;
|
|
2772
|
+
state.position++;
|
|
2773
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2774
|
+
if (!isMapping) {
|
|
2775
|
+
insertFlowPairMappingEvent(state, entryStart);
|
|
2776
|
+
if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2777
|
+
} else if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2778
|
+
if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
|
|
2779
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2780
|
+
if (!isMapping) addPopEvent(state);
|
|
2781
|
+
} else if (isMapping && isPair) {
|
|
2782
|
+
if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2783
|
+
addEmptyScalarEvent(state);
|
|
2784
|
+
} else if (isMapping) addEmptyScalarEvent(state);
|
|
2785
|
+
else if (isPair) {
|
|
2786
|
+
insertFlowPairMappingEvent(state, entryStart);
|
|
2787
|
+
if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2788
|
+
addEmptyScalarEvent(state);
|
|
2789
|
+
addPopEvent(state);
|
|
2790
|
+
}
|
|
2791
|
+
ch = state.input.charCodeAt(state.position);
|
|
2792
|
+
if (ch === 44) {
|
|
2793
|
+
readNext = true;
|
|
2794
|
+
state.position++;
|
|
2795
|
+
} else readNext = false;
|
|
2796
|
+
}
|
|
2797
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
2798
|
+
}
|
|
2799
|
+
function readBlockSequence(state, nodeIndent, props) {
|
|
2800
|
+
if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
|
|
2801
|
+
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2802
|
+
while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
|
|
2803
|
+
if (state.firstTabInLine !== -1) {
|
|
2804
|
+
state.position = state.firstTabInLine;
|
|
2805
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2806
|
+
}
|
|
2807
|
+
const entryLine = state.line;
|
|
2808
|
+
state.position++;
|
|
2809
|
+
const hadBreak = skipSeparationSpace(state, true) > 0;
|
|
2810
|
+
if (state.firstTabInLine !== -1 && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
|
|
2811
|
+
if (hadBreak && state.lineIndent <= nodeIndent) addEmptyScalarEvent(state);
|
|
2812
|
+
else parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2813
|
+
skipSeparationSpace(state, true);
|
|
2814
|
+
if (state.lineIndent < nodeIndent || state.position >= state.length) break;
|
|
2815
|
+
if (state.lineIndent > nodeIndent) throwError(state, "bad indentation of a sequence entry");
|
|
2816
|
+
if (state.line === entryLine && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
|
|
2817
|
+
}
|
|
2818
|
+
addPopEvent(state);
|
|
2819
|
+
return true;
|
|
2820
|
+
}
|
|
2821
|
+
function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
2822
|
+
let atExplicitKey = false;
|
|
2823
|
+
let detected = false;
|
|
2824
|
+
let mappingOpened = false;
|
|
2825
|
+
let pendingExplicitKey = false;
|
|
2826
|
+
if (state.firstTabInLine !== -1) return false;
|
|
2827
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2828
|
+
while (ch !== 0) {
|
|
2829
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
2830
|
+
state.position = state.firstTabInLine;
|
|
2831
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2832
|
+
}
|
|
2833
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2834
|
+
const entryLine = state.line;
|
|
2835
|
+
if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
|
|
2836
|
+
if (!mappingOpened) {
|
|
2837
|
+
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2838
|
+
mappingOpened = true;
|
|
2839
|
+
}
|
|
2840
|
+
if (ch === 63) {
|
|
2841
|
+
if (atExplicitKey) addEmptyScalarEvent(state);
|
|
2842
|
+
detected = true;
|
|
2843
|
+
atExplicitKey = true;
|
|
2844
|
+
} else if (atExplicitKey) atExplicitKey = false;
|
|
2845
|
+
else {
|
|
2846
|
+
addEmptyScalarEvent(state);
|
|
2847
|
+
detected = true;
|
|
2848
|
+
atExplicitKey = false;
|
|
2849
|
+
}
|
|
2850
|
+
state.position += 1;
|
|
2851
|
+
pendingExplicitKey = true;
|
|
2852
|
+
} else {
|
|
2853
|
+
if (atExplicitKey) {
|
|
2854
|
+
addEmptyScalarEvent(state);
|
|
2855
|
+
atExplicitKey = false;
|
|
2856
|
+
}
|
|
2857
|
+
const beforeKey = snapshotState(state);
|
|
2858
|
+
if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) break;
|
|
2859
|
+
if (state.line === entryLine) {
|
|
2860
|
+
ch = state.input.charCodeAt(state.position);
|
|
2861
|
+
while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
|
|
2862
|
+
if (ch === 58) {
|
|
2863
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2864
|
+
if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2865
|
+
if (!mappingOpened) {
|
|
2866
|
+
state.events.splice(beforeKey.eventsLength, 0, {
|
|
2867
|
+
type: EVENT_ID.MAPPING,
|
|
2868
|
+
start: beforeKey.position,
|
|
2869
|
+
anchorStart: props.anchorStart,
|
|
2870
|
+
anchorEnd: props.anchorEnd,
|
|
2871
|
+
tagStart: props.tagStart,
|
|
2872
|
+
tagEnd: props.tagEnd,
|
|
2873
|
+
style: COLLECTION_STYLE.BLOCK
|
|
2874
|
+
});
|
|
2875
|
+
mappingOpened = true;
|
|
2876
|
+
}
|
|
2877
|
+
detected = true;
|
|
2878
|
+
atExplicitKey = false;
|
|
2879
|
+
pendingExplicitKey = false;
|
|
2880
|
+
} else if (detected) throwError(state, "expected ':' after a mapping key");
|
|
2881
|
+
else {
|
|
2882
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2883
|
+
restoreState(state, beforeKey);
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
return true;
|
|
2887
|
+
}
|
|
2888
|
+
} else if (detected) throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2889
|
+
else {
|
|
2890
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2891
|
+
restoreState(state, beforeKey);
|
|
2892
|
+
return false;
|
|
2893
|
+
}
|
|
2894
|
+
return true;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey)) pendingExplicitKey = false;
|
|
2898
|
+
if (!atExplicitKey) {
|
|
2899
|
+
if (pendingExplicitKey) {
|
|
2900
|
+
addEmptyScalarEvent(state);
|
|
2901
|
+
pendingExplicitKey = false;
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
skipSeparationSpace(state, true);
|
|
2905
|
+
ch = state.input.charCodeAt(state.position);
|
|
2906
|
+
if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0) throwError(state, "bad indentation of a mapping entry");
|
|
2907
|
+
else if (state.lineIndent < nodeIndent) break;
|
|
2908
|
+
}
|
|
2909
|
+
if (!detected) return false;
|
|
2910
|
+
if (atExplicitKey) addEmptyScalarEvent(state);
|
|
2911
|
+
if (mappingOpened) addPopEvent(state);
|
|
2912
|
+
return true;
|
|
2913
|
+
}
|
|
2914
|
+
function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
|
|
2915
|
+
if (state.depth >= state.maxDepth) throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
|
|
2916
|
+
state.depth++;
|
|
2917
|
+
let indentStatus = 1;
|
|
2918
|
+
let atNewLine = false;
|
|
2919
|
+
let hasContent = false;
|
|
2920
|
+
let propertyStart = null;
|
|
2921
|
+
const props = emptyProperties();
|
|
2922
|
+
let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
|
|
2923
|
+
let allowBlockCollections = allowBlockScalars;
|
|
2924
|
+
const allowBlockStyles = allowBlockScalars;
|
|
2925
|
+
if (allowToSeek && skipSeparationSpace(state, true)) {
|
|
2926
|
+
atNewLine = true;
|
|
2927
|
+
if (state.lineIndent > parentIndent) indentStatus = 1;
|
|
2928
|
+
else if (state.lineIndent === parentIndent) indentStatus = 0;
|
|
2929
|
+
else indentStatus = -1;
|
|
2930
|
+
}
|
|
2931
|
+
if (indentStatus === 1) while (true) {
|
|
2932
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2933
|
+
const propertyState = snapshotState(state);
|
|
2934
|
+
if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38)) break;
|
|
2935
|
+
if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
|
|
2936
|
+
const fallbackState = snapshotState(state);
|
|
2937
|
+
const flowIndent = parentIndent + 1;
|
|
2938
|
+
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) {
|
|
2939
|
+
state.depth--;
|
|
2940
|
+
return true;
|
|
2941
|
+
}
|
|
2942
|
+
restoreState(state, fallbackState);
|
|
2943
|
+
}
|
|
2944
|
+
if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1)) break;
|
|
2945
|
+
if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props)) break;
|
|
2946
|
+
if (propertyStart === null) propertyStart = propertyState;
|
|
2947
|
+
if (skipSeparationSpace(state, true)) {
|
|
2948
|
+
atNewLine = true;
|
|
2949
|
+
allowBlockCollections = allowBlockStyles;
|
|
2950
|
+
if (state.lineIndent > parentIndent) indentStatus = 1;
|
|
2951
|
+
else if (state.lineIndent === parentIndent) indentStatus = 0;
|
|
2952
|
+
else indentStatus = -1;
|
|
2953
|
+
} else allowBlockCollections = false;
|
|
2954
|
+
}
|
|
2955
|
+
if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
|
|
2956
|
+
if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
|
|
2957
|
+
const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
|
|
2958
|
+
const blockIndent = state.position - state.lineStart;
|
|
2959
|
+
if (indentStatus === 1) {
|
|
2960
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
|
|
2961
|
+
else {
|
|
2962
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2963
|
+
if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
|
|
2964
|
+
const fallbackState = snapshotState(state);
|
|
2965
|
+
const propertyIndent = propertyStart.position - propertyStart.lineStart;
|
|
2966
|
+
restoreState(state, propertyStart);
|
|
2967
|
+
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
|
|
2968
|
+
else restoreState(state, fallbackState);
|
|
2969
|
+
}
|
|
2970
|
+
if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
|
|
2971
|
+
}
|
|
2972
|
+
} else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
|
|
2973
|
+
}
|
|
2974
|
+
allowBlockScalars = allowBlockScalars && !hasContent;
|
|
2975
|
+
if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
|
|
2976
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
|
|
2977
|
+
hasContent = true;
|
|
2978
|
+
}
|
|
2979
|
+
state.depth--;
|
|
2980
|
+
return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
|
|
2981
|
+
}
|
|
2982
|
+
function readDirective(state) {
|
|
2983
|
+
if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37) return false;
|
|
2984
|
+
state.position++;
|
|
2985
|
+
const nameStart = state.position;
|
|
2986
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
|
|
2987
|
+
const name = state.input.slice(nameStart, state.position);
|
|
2988
|
+
const args = [];
|
|
2989
|
+
if (name.length === 0) throwError(state, "directive name must not be less than one character in length");
|
|
2990
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
|
|
2991
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position))) state.position++;
|
|
2992
|
+
if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0) break;
|
|
2993
|
+
const start = state.position;
|
|
2994
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
|
|
2995
|
+
args.push(state.input.slice(start, state.position));
|
|
2996
|
+
}
|
|
2997
|
+
if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
|
|
2998
|
+
if (name === "YAML") {
|
|
2999
|
+
if (state.directives.some((directive) => directive.kind === "yaml")) throwError(state, "duplication of %YAML directive");
|
|
3000
|
+
if (args.length !== 1) throwError(state, "YAML directive accepts exactly one argument");
|
|
3001
|
+
const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
3002
|
+
if (match === null) throwError(state, "ill-formed argument of the YAML directive");
|
|
3003
|
+
if (parseInt(match[1], 10) !== 1) throwError(state, "unacceptable YAML version of the document");
|
|
3004
|
+
state.directives.push({
|
|
3005
|
+
kind: "yaml",
|
|
3006
|
+
version: args[0]
|
|
3007
|
+
});
|
|
3008
|
+
} else if (name === "TAG") {
|
|
3009
|
+
if (args.length !== 2) throwError(state, "TAG directive accepts exactly two arguments");
|
|
3010
|
+
const [handle, prefix] = args;
|
|
3011
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
3012
|
+
if (HAS_OWN.call(state.tagHandlers, handle)) throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
|
|
3013
|
+
if (!PATTERN_TAG_PREFIX.test(prefix)) throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
3014
|
+
state.tagHandlers[handle] = prefix;
|
|
3015
|
+
state.directives.push({
|
|
3016
|
+
kind: "tag",
|
|
3017
|
+
handle,
|
|
3018
|
+
prefix
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
return true;
|
|
3022
|
+
}
|
|
3023
|
+
function readDocument(state) {
|
|
3024
|
+
state.directives = [];
|
|
3025
|
+
state.tagHandlers = Object.create(null);
|
|
3026
|
+
let hasDirectives = false;
|
|
3027
|
+
skipSeparationSpace(state, true);
|
|
3028
|
+
while (readDirective(state)) {
|
|
3029
|
+
hasDirectives = true;
|
|
3030
|
+
skipSeparationSpace(state, true);
|
|
3031
|
+
}
|
|
3032
|
+
let explicitStart = false;
|
|
3033
|
+
let explicitEnd = false;
|
|
3034
|
+
let allowCompact = true;
|
|
3035
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 3))) {
|
|
3036
|
+
explicitStart = true;
|
|
3037
|
+
const markerLine = state.line;
|
|
3038
|
+
state.position += 3;
|
|
3039
|
+
skipSeparationSpace(state, true);
|
|
3040
|
+
allowCompact = state.line > markerLine;
|
|
3041
|
+
} else if (hasDirectives) throwError(state, "directives end mark is expected");
|
|
3042
|
+
const documentEventIndex = state.events.length;
|
|
3043
|
+
if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
|
|
3044
|
+
state.position += 3;
|
|
3045
|
+
skipSeparationSpace(state, true);
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
addDocumentEvent(state, explicitStart, false);
|
|
3049
|
+
if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact)) addEmptyScalarEvent(state);
|
|
3050
|
+
skipSeparationSpace(state, true);
|
|
3051
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
3052
|
+
explicitEnd = state.input.charCodeAt(state.position) === 46;
|
|
3053
|
+
if (explicitEnd) {
|
|
3054
|
+
const markerLine = state.line;
|
|
3055
|
+
state.position += 3;
|
|
3056
|
+
skipSeparationSpace(state, true);
|
|
3057
|
+
if (state.line === markerLine && state.position < state.length) throwError(state, "end of the stream or a document separator is expected");
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
const documentEvent = state.events[documentEventIndex];
|
|
3061
|
+
if (documentEvent?.type === EVENT_ID.DOCUMENT) documentEvent.explicitEnd = explicitEnd;
|
|
3062
|
+
addPopEvent(state);
|
|
3063
|
+
if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state)) throwError(state, "end of the stream or a document separator is expected");
|
|
3064
|
+
}
|
|
3065
|
+
/**
|
|
3066
|
+
* Parses YAML into a flat event stream referencing source text by offsets.
|
|
3067
|
+
*
|
|
3068
|
+
* @category Events
|
|
3069
|
+
*/
|
|
3070
|
+
function parseEvents(input, options) {
|
|
3071
|
+
const length = input.length;
|
|
3072
|
+
const state = {
|
|
3073
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
3074
|
+
...options,
|
|
3075
|
+
input: `${input}\0`,
|
|
3076
|
+
length,
|
|
3077
|
+
position: 0,
|
|
3078
|
+
line: 0,
|
|
3079
|
+
lineStart: 0,
|
|
3080
|
+
lineIndent: 0,
|
|
3081
|
+
firstTabInLine: -1,
|
|
3082
|
+
depth: 0,
|
|
3083
|
+
directives: [],
|
|
3084
|
+
tagHandlers: Object.create(null),
|
|
3085
|
+
events: []
|
|
3086
|
+
};
|
|
3087
|
+
const nullpos = input.indexOf("\0");
|
|
3088
|
+
if (nullpos !== -1) YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
|
|
3089
|
+
while (state.position < state.length) {
|
|
3090
|
+
skipByteOrderMark(state);
|
|
3091
|
+
skipSeparationSpace(state, true);
|
|
3092
|
+
if (state.position >= state.length) break;
|
|
3093
|
+
const documentStart = state.position;
|
|
3094
|
+
readDocument(state);
|
|
3095
|
+
if (state.position === documentStart)
|
|
3096
|
+
/* c8 ignore next */
|
|
3097
|
+
throwError(state, "can not read a document");
|
|
3098
|
+
}
|
|
3099
|
+
return state.events;
|
|
3100
|
+
}
|
|
3101
|
+
var DEFAULT_LOAD_OPTIONS = {
|
|
3102
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
3103
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS
|
|
3104
|
+
};
|
|
3105
|
+
function loadDocuments(input, options = {}) {
|
|
3106
|
+
const opts = {
|
|
3107
|
+
...DEFAULT_LOAD_OPTIONS,
|
|
3108
|
+
...options
|
|
3109
|
+
};
|
|
3110
|
+
const source = String(input);
|
|
3111
|
+
const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
|
|
3112
|
+
const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
|
|
3113
|
+
return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
|
|
3114
|
+
...pick(opts, CONSTRUCTOR_OPT_KEYS),
|
|
3115
|
+
source
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* Parses `string` as a single YAML document. Throws {@link YAMLException} on
|
|
3120
|
+
* error. This function does not understand multi-document or empty sources; it
|
|
3121
|
+
* throws an exception on those.
|
|
3122
|
+
*
|
|
3123
|
+
* > [!NOTE]
|
|
3124
|
+
* > 1. When processing untrusted input, see the
|
|
3125
|
+
* > [security considerations](../docs/safety.md).
|
|
3126
|
+
* > 2. All exceptions MUST be caught, not just {@link YAMLException}.
|
|
3127
|
+
* > 3. The default {@link CORE_SCHEMA} comes without the `!!merge` tag. You can
|
|
3128
|
+
* > easily enable it if needed.
|
|
3129
|
+
* > 4. The default {@link mapTag} is `{}`-object based, with known limitations
|
|
3130
|
+
* > (see description). For full compatibility use {@link realMapTag}
|
|
3131
|
+
* > instead (it uses native JS `Map`).
|
|
3132
|
+
*
|
|
3133
|
+
* @example
|
|
3134
|
+
* Enable {@link mergeTag} and {@link realMapTag}:
|
|
3135
|
+
*
|
|
3136
|
+
* ```javascript
|
|
3137
|
+
* import { load, CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
3138
|
+
*
|
|
3139
|
+
* try {
|
|
3140
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag, realMapTag) })
|
|
3141
|
+
* } catch (e) {
|
|
3142
|
+
* console.error(e)
|
|
3143
|
+
* }
|
|
3144
|
+
* ```
|
|
3145
|
+
*
|
|
3146
|
+
* @category Main
|
|
3147
|
+
*/
|
|
3148
|
+
function load(input, options) {
|
|
3149
|
+
const documents = loadDocuments(input, options);
|
|
3150
|
+
if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
|
|
3151
|
+
if (documents.length === 1) return documents[0];
|
|
3152
|
+
throw new YAMLException("expected a single document in the stream, but found more");
|
|
3153
|
+
}
|
|
3154
|
+
var INVALID = Symbol("INVALID");
|
|
3155
|
+
function buildRepresentTypes(schema) {
|
|
3156
|
+
const defaultTags = new Set([
|
|
3157
|
+
schema.defaultScalarTag,
|
|
3158
|
+
schema.defaultSequenceTag,
|
|
3159
|
+
schema.defaultMappingTag
|
|
3160
|
+
].filter((t) => t !== void 0));
|
|
3161
|
+
const implicitScalars = schema.implicitScalarTags;
|
|
3162
|
+
const explicitTags = schema.tags.filter((t) => !(t.nodeKind === "scalar" && t.implicit) && !defaultTags.has(t));
|
|
3163
|
+
const defaultTagsLast = schema.tags.filter((t) => defaultTags.has(t));
|
|
3164
|
+
return [
|
|
3165
|
+
...implicitScalars.map((tag) => ({
|
|
3166
|
+
tag,
|
|
3167
|
+
implicitTag: true
|
|
3168
|
+
})),
|
|
3169
|
+
...explicitTags.map((tag) => ({
|
|
3170
|
+
tag,
|
|
3171
|
+
implicitTag: false
|
|
3172
|
+
})),
|
|
3173
|
+
...defaultTagsLast.map((tag) => ({
|
|
3174
|
+
tag,
|
|
3175
|
+
implicitTag: true
|
|
3176
|
+
}))
|
|
3177
|
+
];
|
|
3178
|
+
}
|
|
3179
|
+
function matchTag(state, object) {
|
|
3180
|
+
for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
|
|
3181
|
+
const { tag, implicitTag } = state.representTypes[index];
|
|
3182
|
+
if (tag.identify(object)) {
|
|
3183
|
+
let tagName;
|
|
3184
|
+
if (tag.matchByTagPrefix) tagName = tag.representTagName(object);
|
|
3185
|
+
else tagName = tag.tagName;
|
|
3186
|
+
return {
|
|
3187
|
+
tag,
|
|
3188
|
+
tagName,
|
|
3189
|
+
implicitTag
|
|
3190
|
+
};
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
return null;
|
|
3194
|
+
}
|
|
3195
|
+
function build(state, object) {
|
|
3196
|
+
if (!state.noRefs && object !== null && typeof object === "object") {
|
|
3197
|
+
const existing = state.refs.get(object);
|
|
3198
|
+
if (existing) {
|
|
3199
|
+
if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
|
|
3200
|
+
return {
|
|
3201
|
+
kind: "alias",
|
|
3202
|
+
anchor: existing.anchor
|
|
3203
|
+
};
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
const matched = matchTag(state, object);
|
|
3207
|
+
if (!matched) {
|
|
3208
|
+
if (object === void 0) return INVALID;
|
|
3209
|
+
if (state.skipInvalid) return INVALID;
|
|
3210
|
+
throw new YAMLException(`unacceptable kind of an object to dump ${Object.prototype.toString.call(object)}`);
|
|
3211
|
+
}
|
|
3212
|
+
const { tag, tagName, implicitTag } = matched;
|
|
3213
|
+
const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
|
|
3214
|
+
if (tag.nodeKind === "scalar") return {
|
|
3215
|
+
kind: "scalar",
|
|
3216
|
+
tag: nodeTagName,
|
|
3217
|
+
tagged: !implicitTag,
|
|
3218
|
+
style: SCALAR_STYLE.PLAIN,
|
|
3219
|
+
value: tag.represent(object)
|
|
3220
|
+
};
|
|
3221
|
+
if (tag.nodeKind === "sequence") {
|
|
3222
|
+
const container = tag.represent(object);
|
|
3223
|
+
const node = {
|
|
3224
|
+
kind: "sequence",
|
|
3225
|
+
tag: nodeTagName,
|
|
3226
|
+
tagged: !implicitTag,
|
|
3227
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
3228
|
+
items: []
|
|
3229
|
+
};
|
|
3230
|
+
if (!state.noRefs) state.refs.set(object, node);
|
|
3231
|
+
for (let index = 0, length = container.length; index < length; index += 1) {
|
|
3232
|
+
let item = build(state, container[index]);
|
|
3233
|
+
if (item === INVALID && container[index] === void 0) item = build(state, null);
|
|
3234
|
+
if (item === INVALID) continue;
|
|
3235
|
+
node.items.push(item);
|
|
3236
|
+
}
|
|
3237
|
+
return node;
|
|
3238
|
+
}
|
|
3239
|
+
const map = tag.represent(object);
|
|
3240
|
+
const node = {
|
|
3241
|
+
kind: "mapping",
|
|
3242
|
+
tag: nodeTagName,
|
|
3243
|
+
tagged: !implicitTag,
|
|
3244
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
3245
|
+
items: []
|
|
3246
|
+
};
|
|
3247
|
+
if (!state.noRefs) state.refs.set(object, node);
|
|
3248
|
+
for (const [objectKey, objectValue] of map) {
|
|
3249
|
+
const key = build(state, objectKey);
|
|
3250
|
+
if (key === INVALID) continue;
|
|
3251
|
+
const value = build(state, objectValue);
|
|
3252
|
+
if (value === INVALID) continue;
|
|
3253
|
+
node.items.push({
|
|
3254
|
+
key,
|
|
3255
|
+
value
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
return node;
|
|
3259
|
+
}
|
|
3260
|
+
/**
|
|
3261
|
+
* Convert JS object to AST. A JS value is one YAML document. An unrepresentable
|
|
3262
|
+
* root becomes an empty document, which the presenter renders as an empty
|
|
3263
|
+
* string.
|
|
3264
|
+
*
|
|
3265
|
+
* @category AST
|
|
3266
|
+
*/
|
|
3267
|
+
function jsToAst(input, schema, options = {}) {
|
|
3268
|
+
const root = build({
|
|
3269
|
+
representTypes: buildRepresentTypes(schema),
|
|
3270
|
+
noRefs: options.noRefs ?? false,
|
|
3271
|
+
skipInvalid: options.skipInvalid ?? false,
|
|
3272
|
+
refs: /* @__PURE__ */ new Map(),
|
|
3273
|
+
refCounter: 0
|
|
3274
|
+
}, input);
|
|
3275
|
+
return [{
|
|
3276
|
+
contents: root === INVALID ? null : root,
|
|
3277
|
+
directives: []
|
|
3278
|
+
}];
|
|
3279
|
+
}
|
|
3280
|
+
/**
|
|
3281
|
+
* Return from a visitor to stop the whole traversal.
|
|
3282
|
+
*
|
|
3283
|
+
* @category AST
|
|
3284
|
+
*/
|
|
3285
|
+
var VISIT_BREAK = Symbol("visit:break");
|
|
3286
|
+
/**
|
|
3287
|
+
* Return from a visitor to skip the current node's children.
|
|
3288
|
+
*
|
|
3289
|
+
* @category AST
|
|
3290
|
+
*/
|
|
3291
|
+
var VISIT_SKIP = Symbol("visit:skip");
|
|
3292
|
+
function visitNode(node, visitor, ctx) {
|
|
3293
|
+
const control = visitor(node, ctx);
|
|
3294
|
+
if (control === VISIT_BREAK) return true;
|
|
3295
|
+
if (control === VISIT_SKIP) return false;
|
|
3296
|
+
const depth = ctx.depth + 1;
|
|
3297
|
+
switch (node.kind) {
|
|
3298
|
+
case "sequence":
|
|
3299
|
+
for (const item of node.items) if (visitNode(item, visitor, {
|
|
3300
|
+
depth,
|
|
3301
|
+
parent: node,
|
|
3302
|
+
isKey: false
|
|
3303
|
+
})) return true;
|
|
3304
|
+
break;
|
|
3305
|
+
case "mapping": for (const { key, value } of node.items) {
|
|
3306
|
+
if (visitNode(key, visitor, {
|
|
3307
|
+
depth,
|
|
3308
|
+
parent: node,
|
|
3309
|
+
isKey: true
|
|
3310
|
+
})) return true;
|
|
3311
|
+
if (visitNode(value, visitor, {
|
|
3312
|
+
depth,
|
|
3313
|
+
parent: node,
|
|
3314
|
+
isKey: false
|
|
3315
|
+
})) return true;
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
return false;
|
|
3319
|
+
}
|
|
3320
|
+
/**
|
|
3321
|
+
* Walk every node in the documents, calling {@link Visitor} once per
|
|
3322
|
+
* node (pre-order).
|
|
3323
|
+
*
|
|
3324
|
+
* @category AST
|
|
3325
|
+
*/
|
|
3326
|
+
function visit(documents, visitor) {
|
|
3327
|
+
for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
|
|
3328
|
+
depth: 0,
|
|
3329
|
+
parent: null,
|
|
3330
|
+
isKey: false
|
|
3331
|
+
})) return;
|
|
3332
|
+
}
|
|
3333
|
+
function hasBit(mask, bit) {
|
|
3334
|
+
return (mask & 1 << bit) !== 0;
|
|
3335
|
+
}
|
|
3336
|
+
/**
|
|
3337
|
+
* Default scalar styling rules in application order.
|
|
3338
|
+
* See [Scalar styling](../../docs/scalar_styling.md) for usage details.
|
|
3339
|
+
*
|
|
3340
|
+
* @category AST
|
|
3341
|
+
*/
|
|
3342
|
+
var DEFAULT_SCALAR_STYLE_RULES = {
|
|
3343
|
+
applyQuoteFlowKeysOption,
|
|
3344
|
+
doubleQuoteForInvisibles,
|
|
3345
|
+
doubleQuoteWhitespaceOnly,
|
|
3346
|
+
applyForceQuotesOption,
|
|
3347
|
+
tryLongOrMultilineAsBlock,
|
|
3348
|
+
quoteInvalidPlain,
|
|
3349
|
+
fallbackToDoubleQuoted
|
|
3350
|
+
};
|
|
3351
|
+
function _preferredQuotedStyle(layout) {
|
|
3352
|
+
if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED)) return SCALAR_STYLE.SINGLE_QUOTED;
|
|
3353
|
+
return SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3354
|
+
}
|
|
3355
|
+
function applyQuoteFlowKeysOption(layout) {
|
|
3356
|
+
if (!layout.presenterOptions.quoteFlowKeys) return;
|
|
3357
|
+
if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
3358
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3359
|
+
}
|
|
3360
|
+
function doubleQuoteForInvisibles(layout) {
|
|
3361
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3362
|
+
}
|
|
3363
|
+
function doubleQuoteWhitespaceOnly(layout) {
|
|
3364
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3365
|
+
}
|
|
3366
|
+
function applyForceQuotesOption(layout) {
|
|
3367
|
+
if (!layout.presenterOptions.forceQuotes) return;
|
|
3368
|
+
if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
3369
|
+
if (layout.node.tag !== layout.presenterOptions.schema.defaultScalarTag.tagName) return;
|
|
3370
|
+
layout.style = layout.node.value.includes("\n") ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
|
|
3371
|
+
}
|
|
3372
|
+
function tryLongOrMultilineAsBlock(layout) {
|
|
3373
|
+
if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey) return;
|
|
3374
|
+
const value = layout.node.value;
|
|
3375
|
+
const multiline = value.indexOf("\n") !== -1;
|
|
3376
|
+
if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
|
|
3377
|
+
if (multiline) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3378
|
+
return;
|
|
3379
|
+
}
|
|
3380
|
+
const w = layout.presenterOptions.lineWidth;
|
|
3381
|
+
if (w === -1) {
|
|
3382
|
+
if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
3386
|
+
let position = 0;
|
|
3387
|
+
let shouldFold = false;
|
|
3388
|
+
while (position <= value.length) {
|
|
3389
|
+
let lineEnd = value.length;
|
|
3390
|
+
const nextLineBreak = value.indexOf("\n", position);
|
|
3391
|
+
if (nextLineBreak !== -1) lineEnd = nextLineBreak;
|
|
3392
|
+
const line = value.slice(position, lineEnd);
|
|
3393
|
+
if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line)) shouldFold = true;
|
|
3394
|
+
if (nextLineBreak === -1) break;
|
|
3395
|
+
position = nextLineBreak + 1;
|
|
3396
|
+
}
|
|
3397
|
+
if (shouldFold) layout.style = SCALAR_STYLE.FOLDED_BLOCK;
|
|
3398
|
+
else if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
3399
|
+
}
|
|
3400
|
+
function quoteInvalidPlain(layout) {
|
|
3401
|
+
if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN)) layout.style = _preferredQuotedStyle(layout);
|
|
3402
|
+
}
|
|
3403
|
+
function fallbackToDoubleQuoted(layout) {
|
|
3404
|
+
if (!hasBit(layout.allowedStylesMask, layout.style)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3405
|
+
}
|
|
3406
|
+
function setBit(mask, bit) {
|
|
3407
|
+
return mask | 1 << bit;
|
|
3408
|
+
}
|
|
3409
|
+
var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
|
|
3410
|
+
var SRC_B_CHAR = "[\\n\\r]";
|
|
3411
|
+
var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
|
|
3412
|
+
var SRC_S_WHITE = "[ \\t]";
|
|
3413
|
+
var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
|
|
3414
|
+
var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
|
|
3415
|
+
var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
|
|
3416
|
+
var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
|
|
3417
|
+
var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
|
|
3418
|
+
var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
|
|
3419
|
+
var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
|
|
3420
|
+
var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
|
|
3421
|
+
var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
|
|
3422
|
+
var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
|
|
3423
|
+
var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
|
|
3424
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
|
|
3425
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
|
|
3426
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
3427
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
3428
|
+
var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
|
|
3429
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
|
|
3430
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
3431
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
3432
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
|
|
3433
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
|
|
3434
|
+
var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
|
|
3435
|
+
var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
|
|
3436
|
+
var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
|
|
3437
|
+
var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
|
|
3438
|
+
var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
|
|
3439
|
+
var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
|
|
3440
|
+
var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
|
|
3441
|
+
var C_FORBIDDEN_FIRST_LINE = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/;
|
|
3442
|
+
var C_FORBIDDEN_CONTENT = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/m;
|
|
3443
|
+
function canUsePlain(layout) {
|
|
3444
|
+
const str = layout.node.value;
|
|
3445
|
+
if (str !== "") {
|
|
3446
|
+
if (!(layout.isKey ? layout.flowOnly ? NS_PLAIN_FLOW_KEY : NS_PLAIN_BLOCK_KEY : layout.flowOnly ? NS_PLAIN_FLOW_IN : NS_PLAIN_FLOW_OUT).test(str)) return false;
|
|
3447
|
+
if (layout.shiftOfFirstLine === 0 && C_FORBIDDEN_FIRST_LINE.test(str)) return false;
|
|
3448
|
+
if (layout.shiftOfContent === 0) {
|
|
3449
|
+
const firstLineBreak = str.indexOf("\n");
|
|
3450
|
+
if (firstLineBreak !== -1) {
|
|
3451
|
+
const content = str.slice(firstLineBreak + 1);
|
|
3452
|
+
if (C_FORBIDDEN_CONTENT.test(content)) return false;
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
const resolvedTag = layout.presenterOptions.schema.resolveImplicitScalarTag(str).tag.tagName;
|
|
3457
|
+
if (!layout.node.tagged && resolvedTag !== layout.node.tag) return false;
|
|
3458
|
+
if (!layout.node.tagged && str === "=" && resolvedTag === layout.presenterOptions.schema.defaultScalarTag.tagName) return false;
|
|
3459
|
+
return true;
|
|
3460
|
+
}
|
|
3461
|
+
function canUseSingleQuoted(layout) {
|
|
3462
|
+
const str = layout.node.value;
|
|
3463
|
+
if (!(layout.isKey ? NB_SINGLE_ONE_LINE : NB_SINGLE_MULTI_LINE).test(str)) return false;
|
|
3464
|
+
if (/[ \t]\n|\n[ \t]/.test(str)) return false;
|
|
3465
|
+
if (!layout.isKey && layout.shiftOfContent === 0) {
|
|
3466
|
+
const firstLineBreak = str.indexOf("\n");
|
|
3467
|
+
if (firstLineBreak !== -1 && C_FORBIDDEN_CONTENT.test(str.slice(firstLineBreak + 1))) return false;
|
|
3468
|
+
}
|
|
3469
|
+
return true;
|
|
3470
|
+
}
|
|
3471
|
+
function canUseBlock(layout) {
|
|
3472
|
+
if (layout.flowOnly || !BLOCK_SCALAR_CONTENT.test(layout.node.value)) return false;
|
|
3473
|
+
const contentIndent = layout.shiftOfContent - layout.shiftOfParent;
|
|
3474
|
+
if (contentIndent < 1) return false;
|
|
3475
|
+
if (contentIndent > 9 && /^\n* /.test(layout.node.value)) return false;
|
|
3476
|
+
if (layout.shiftOfContent === 0 && C_FORBIDDEN_CONTENT.test(layout.node.value)) return false;
|
|
3477
|
+
return true;
|
|
3478
|
+
}
|
|
3479
|
+
function detectAllowedStyles(layout) {
|
|
3480
|
+
let mask = setBit(0, SCALAR_STYLE.DOUBLE_QUOTED);
|
|
3481
|
+
if (canUsePlain(layout)) mask = setBit(mask, SCALAR_STYLE.PLAIN);
|
|
3482
|
+
if (canUseSingleQuoted(layout)) mask = setBit(mask, SCALAR_STYLE.SINGLE_QUOTED);
|
|
3483
|
+
if (canUseBlock(layout)) mask = setBit(setBit(mask, SCALAR_STYLE.LITERAL_BLOCK), SCALAR_STYLE.FOLDED_BLOCK);
|
|
3484
|
+
layout.allowedStylesMask = mask;
|
|
3485
|
+
}
|
|
3486
|
+
function renderScalar(layout) {
|
|
3487
|
+
switch (layout.style) {
|
|
3488
|
+
case SCALAR_STYLE.PLAIN: return renderPlain(layout);
|
|
3489
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return renderSingleQuoted(layout);
|
|
3490
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return renderLiteralBlock(layout);
|
|
3491
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return renderFoldedBlock(layout);
|
|
3492
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return renderDoubleQuoted(layout);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
function renderPlain(layout) {
|
|
3496
|
+
return encodeFlowBreaks(layout.node.value, layout.shiftOfContent);
|
|
3497
|
+
}
|
|
3498
|
+
function renderSingleQuoted(layout) {
|
|
3499
|
+
return `'${encodeFlowBreaks(layout.node.value, layout.shiftOfContent).replace(/'/g, "''")}'`;
|
|
3500
|
+
}
|
|
3501
|
+
function renderLiteralBlock(layout) {
|
|
3502
|
+
const value = layout.node.value;
|
|
3503
|
+
return "|" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(value, layout.shiftOfContent));
|
|
3504
|
+
}
|
|
3505
|
+
function renderFoldedBlock(layout) {
|
|
3506
|
+
const value = layout.node.value;
|
|
3507
|
+
const w = layout.presenterOptions.lineWidth;
|
|
3508
|
+
let availableWidth = Infinity;
|
|
3509
|
+
if (w !== -1) availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
3510
|
+
return ">" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(foldBlockScalar(value, availableWidth), layout.shiftOfContent));
|
|
3511
|
+
}
|
|
3512
|
+
function renderDoubleQuoted(layout) {
|
|
3513
|
+
return `"${escapeString(layout.node.value)}"`;
|
|
3514
|
+
}
|
|
3515
|
+
function encodeFlowBreaks(string, shiftOfContent) {
|
|
3516
|
+
let nextLF = string.indexOf("\n");
|
|
3517
|
+
if (nextLF === -1) return string;
|
|
3518
|
+
const pad = " ".repeat(shiftOfContent);
|
|
3519
|
+
let result = string.slice(0, nextLF);
|
|
3520
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3521
|
+
lineRe.lastIndex = nextLF;
|
|
3522
|
+
let match;
|
|
3523
|
+
while (match = lineRe.exec(string)) {
|
|
3524
|
+
const breaks = match[1].length;
|
|
3525
|
+
const line = match[2];
|
|
3526
|
+
result += "\n".repeat(breaks + 1) + pad + line;
|
|
3527
|
+
}
|
|
3528
|
+
return result;
|
|
3529
|
+
}
|
|
3530
|
+
function indentString(string, spaces) {
|
|
3531
|
+
const indent = " ".repeat(spaces);
|
|
3532
|
+
let position = 0;
|
|
3533
|
+
let result = "";
|
|
3534
|
+
const length = string.length;
|
|
3535
|
+
while (position < length) {
|
|
3536
|
+
let line;
|
|
3537
|
+
const next = string.indexOf("\n", position);
|
|
3538
|
+
if (next === -1) {
|
|
3539
|
+
line = string.slice(position);
|
|
3540
|
+
position = length;
|
|
3541
|
+
} else {
|
|
3542
|
+
line = string.slice(position, next + 1);
|
|
3543
|
+
position = next + 1;
|
|
3544
|
+
}
|
|
3545
|
+
if (line.length && line !== "\n") result += indent;
|
|
3546
|
+
result += line;
|
|
3547
|
+
}
|
|
3548
|
+
return result;
|
|
3549
|
+
}
|
|
3550
|
+
function needIndentIndicator(string) {
|
|
3551
|
+
return /^\n* /.test(string);
|
|
3552
|
+
}
|
|
3553
|
+
function blockHeader(string, shiftOfParent, shiftOfContent) {
|
|
3554
|
+
const indentIndicator = needIndentIndicator(string) ? String(shiftOfContent - shiftOfParent) : "";
|
|
3555
|
+
const clip = string[string.length - 1] === "\n";
|
|
3556
|
+
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
3557
|
+
}
|
|
3558
|
+
function dropEndingNewline(string) {
|
|
3559
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
3560
|
+
}
|
|
3561
|
+
function isMoreIndented(char) {
|
|
3562
|
+
return char === " " || char === " ";
|
|
3563
|
+
}
|
|
3564
|
+
function foldLine(line, width) {
|
|
3565
|
+
if (line === "" || isMoreIndented(line[0])) return line;
|
|
3566
|
+
const breakRe = / [^ \t]/g;
|
|
3567
|
+
let match;
|
|
3568
|
+
let start = 0;
|
|
3569
|
+
let end;
|
|
3570
|
+
let curr = 0;
|
|
3571
|
+
let next = 0;
|
|
3572
|
+
let result = "";
|
|
3573
|
+
while (match = breakRe.exec(line)) {
|
|
3574
|
+
next = match.index;
|
|
3575
|
+
if (next - start > width) {
|
|
3576
|
+
end = curr > start ? curr : next;
|
|
3577
|
+
result += `\n${line.slice(start, end)}`;
|
|
3578
|
+
start = end + 1;
|
|
3579
|
+
}
|
|
3580
|
+
curr = next;
|
|
3581
|
+
}
|
|
3582
|
+
result += "\n";
|
|
3583
|
+
if (line.length - start > width && curr > start) result += `${line.slice(start, curr)}\n${line.slice(curr + 1)}`;
|
|
3584
|
+
else result += line.slice(start);
|
|
3585
|
+
return result.slice(1);
|
|
3586
|
+
}
|
|
3587
|
+
function foldBlockScalar(string, width) {
|
|
3588
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3589
|
+
let nextLF = string.indexOf("\n");
|
|
3590
|
+
if (nextLF === -1) nextLF = string.length;
|
|
3591
|
+
lineRe.lastIndex = nextLF;
|
|
3592
|
+
let result = foldLine(string.slice(0, nextLF), width);
|
|
3593
|
+
let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
|
|
3594
|
+
let moreIndented;
|
|
3595
|
+
let match;
|
|
3596
|
+
while (match = lineRe.exec(string)) {
|
|
3597
|
+
const prefix = match[1];
|
|
3598
|
+
const line = match[2];
|
|
3599
|
+
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
3600
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
3601
|
+
prevMoreIndented = moreIndented;
|
|
3602
|
+
}
|
|
3603
|
+
return result;
|
|
3604
|
+
}
|
|
3605
|
+
var CHARACTERS_TO_ESCAPE = /["\\\x00-\x1F\x7F-\xA0\u2028\u2029\uD800-\uDFFF\uFEFF\uFFFE\uFFFF]/gu;
|
|
3606
|
+
function escapeCharacter(character) {
|
|
3607
|
+
switch (character) {
|
|
3608
|
+
case "\0": return "\\0";
|
|
3609
|
+
case "\x07": return "\\a";
|
|
3610
|
+
case "\b": return "\\b";
|
|
3611
|
+
case " ": return "\\t";
|
|
3612
|
+
case "\n": return "\\n";
|
|
3613
|
+
case "\v": return "\\v";
|
|
3614
|
+
case "\f": return "\\f";
|
|
3615
|
+
case "\r": return "\\r";
|
|
3616
|
+
case "\x1B": return "\\e";
|
|
3617
|
+
case "\"": return "\\\"";
|
|
3618
|
+
case "\\": return "\\\\";
|
|
3619
|
+
case "
": return "\\N";
|
|
3620
|
+
case "\xA0": return "\\_";
|
|
3621
|
+
case "\u2028": return "\\L";
|
|
3622
|
+
case "\u2029": return "\\P";
|
|
3623
|
+
}
|
|
3624
|
+
const code = character.charCodeAt(0);
|
|
3625
|
+
const hex = code.toString(16).toUpperCase();
|
|
3626
|
+
if (code <= 255) return `\\x${"0".repeat(2 - hex.length)}${hex}`;
|
|
3627
|
+
return `\\u${"0".repeat(4 - hex.length)}${hex}`;
|
|
3628
|
+
}
|
|
3629
|
+
function escapeString(string) {
|
|
3630
|
+
return string.replace(CHARACTERS_TO_ESCAPE, escapeCharacter);
|
|
3631
|
+
}
|
|
3632
|
+
var CHAR_LINE_FEED = 10;
|
|
3633
|
+
var DEFAULT_PRESENTER_OPTIONS = {
|
|
3634
|
+
indent: 2,
|
|
3635
|
+
seqNoIndent: false,
|
|
3636
|
+
seqInlineFirst: true,
|
|
3637
|
+
lineWidth: 80,
|
|
3638
|
+
flowBracketPadding: false,
|
|
3639
|
+
flowSkipCommaSpace: false,
|
|
3640
|
+
flowSkipColonSpace: false,
|
|
3641
|
+
quoteFlowKeys: false,
|
|
3642
|
+
quoteStyle: "single",
|
|
3643
|
+
forceQuotes: false,
|
|
3644
|
+
scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
|
|
3645
|
+
tagBeforeAnchor: false
|
|
3646
|
+
};
|
|
3647
|
+
function nodeTagShort(node) {
|
|
3648
|
+
return node.tagged ? node.tag : tagNameShort(node.tag);
|
|
3649
|
+
}
|
|
3650
|
+
function createPresenterState(options) {
|
|
3651
|
+
const opts = {
|
|
3652
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3653
|
+
...options
|
|
3654
|
+
};
|
|
3655
|
+
if (opts.flowSkipColonSpace) opts.quoteFlowKeys = true;
|
|
3656
|
+
return {
|
|
3657
|
+
...opts,
|
|
3658
|
+
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
|
|
3659
|
+
openEnded: false
|
|
3660
|
+
};
|
|
3661
|
+
}
|
|
3662
|
+
function generateNextLine(state, level) {
|
|
3663
|
+
return `\n${" ".repeat(state.indent * level)}`;
|
|
3664
|
+
}
|
|
3665
|
+
function scalarLayout(state, node, parent, level, isKey, flowOnly) {
|
|
3666
|
+
return {
|
|
3667
|
+
node,
|
|
3668
|
+
parent,
|
|
3669
|
+
level,
|
|
3670
|
+
isKey,
|
|
3671
|
+
flowOnly,
|
|
3672
|
+
shiftOfParent: level === 0 ? -1 : state.indent * (level - 1),
|
|
3673
|
+
shiftOfContent: state.indent * Math.max(1, level),
|
|
3674
|
+
shiftOfFirstLine: level === 0 ? 0 : state.indent * level,
|
|
3675
|
+
presenterOptions: state,
|
|
3676
|
+
allowedStylesMask: 0,
|
|
3677
|
+
style: node.style
|
|
3678
|
+
};
|
|
3679
|
+
}
|
|
3680
|
+
function writeFlowSequence(state, level, node) {
|
|
3681
|
+
let result = "";
|
|
3682
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
3683
|
+
const item = writeNode(state, level, node.items[index], node, {}).text;
|
|
3684
|
+
if (index > 0) result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
3685
|
+
result += item;
|
|
3686
|
+
}
|
|
3687
|
+
const pad = state.flowBracketPadding && node.items.length > 0 ? " " : "";
|
|
3688
|
+
return `[${pad}${result}${pad}]`;
|
|
3689
|
+
}
|
|
3690
|
+
function writeBlockSequence(state, level, node, compact) {
|
|
3691
|
+
let result = "";
|
|
3692
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
3693
|
+
const item = writeNode(state, level + 1, node.items[index], node, {
|
|
3694
|
+
block: true,
|
|
3695
|
+
compact: state.seqInlineFirst,
|
|
3696
|
+
isblockseq: true
|
|
3697
|
+
}).text;
|
|
3698
|
+
if (!compact || result !== "") result += generateNextLine(state, level);
|
|
3699
|
+
if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
|
|
3700
|
+
else result += "- ";
|
|
3701
|
+
result += item;
|
|
3702
|
+
}
|
|
3703
|
+
return result;
|
|
3704
|
+
}
|
|
3705
|
+
function writeFlowMapping(state, level, node) {
|
|
3706
|
+
let result = "";
|
|
3707
|
+
for (const { key, value } of node.items) {
|
|
3708
|
+
let pairBuffer = "";
|
|
3709
|
+
if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
3710
|
+
const keyRender = writeNode(state, level, key, node, { iskey: true });
|
|
3711
|
+
const keyText = keyRender.text;
|
|
3712
|
+
const valueText = writeNode(state, level, value, node, {}).text;
|
|
3713
|
+
const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
|
|
3714
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
3715
|
+
const keyColonSep = key.kind === "alias" || keyIsBareProps ? " " : "";
|
|
3716
|
+
pairBuffer += `${keyText}${keyColonSep}:${sep}${valueText}`;
|
|
3717
|
+
result += pairBuffer;
|
|
3718
|
+
}
|
|
3719
|
+
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
3720
|
+
return `{${pad}${result}${pad}}`;
|
|
3721
|
+
}
|
|
3722
|
+
function writeBlockMapping(state, level, node, compact) {
|
|
3723
|
+
let result = "";
|
|
3724
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
3725
|
+
let pairBuffer = "";
|
|
3726
|
+
if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
|
|
3727
|
+
const { key, value } = node.items[index];
|
|
3728
|
+
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && key.style === COLLECTION_STYLE.BLOCK && key.items.length !== 0 || key.kind === "scalar" && (key.style === SCALAR_STYLE.LITERAL_BLOCK || key.style === SCALAR_STYLE.FOLDED_BLOCK);
|
|
3729
|
+
const keyRender = keyIsBlock ? writeNode(state, level + 1, key, node, {
|
|
3730
|
+
block: true,
|
|
3731
|
+
compact: true,
|
|
3732
|
+
isblockseq: !cannotBeCompact(state, key, level + 1)
|
|
3733
|
+
}) : writeNode(state, level + 1, key, node, {
|
|
3734
|
+
block: true,
|
|
3735
|
+
compact: true,
|
|
3736
|
+
iskey: true
|
|
3737
|
+
});
|
|
3738
|
+
const keyText = keyRender.text;
|
|
3739
|
+
const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
|
|
3740
|
+
const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
|
|
3741
|
+
const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
|
|
3742
|
+
if (explicitPair) {
|
|
3743
|
+
if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
|
|
3744
|
+
else pairBuffer += "? ";
|
|
3745
|
+
}
|
|
3746
|
+
pairBuffer += keyText;
|
|
3747
|
+
if (explicitPair) pairBuffer += generateNextLine(state, level);
|
|
3748
|
+
const valueText = writeNode(state, level + 1, value, node, {
|
|
3749
|
+
block: true,
|
|
3750
|
+
compact: explicitPair,
|
|
3751
|
+
isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
|
|
3752
|
+
}).text;
|
|
3753
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
3754
|
+
const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
|
|
3755
|
+
if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
|
|
3756
|
+
else pairBuffer += `${keyColonSep}: `;
|
|
3757
|
+
pairBuffer += valueText;
|
|
3758
|
+
result += pairBuffer;
|
|
3759
|
+
}
|
|
3760
|
+
return result;
|
|
3761
|
+
}
|
|
3762
|
+
function cannotBeCompact(state, node, level) {
|
|
3763
|
+
if (node.kind === "alias") return true;
|
|
3764
|
+
return node.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
|
|
3765
|
+
}
|
|
3766
|
+
function writeNode(state, level, node, parent, ctx) {
|
|
3767
|
+
if (node.kind === "alias") {
|
|
3768
|
+
state.openEnded = false;
|
|
3769
|
+
return {
|
|
3770
|
+
text: `*${node.anchor}`,
|
|
3771
|
+
noBody: false
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
const { block = false, iskey = false, isblockseq = false } = ctx;
|
|
3775
|
+
let compact = ctx.compact ?? false;
|
|
3776
|
+
const hasAnchor = node.anchor !== void 0;
|
|
3777
|
+
if (cannotBeCompact(state, node, level)) compact = false;
|
|
3778
|
+
let body;
|
|
3779
|
+
let shouldPrintTag = node.tagged;
|
|
3780
|
+
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
|
|
3781
|
+
if (node.kind === "mapping") {
|
|
3782
|
+
if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
|
|
3783
|
+
else body = writeFlowMapping(state, level, node);
|
|
3784
|
+
} else if (node.kind === "sequence") {
|
|
3785
|
+
if (useBlockCollection) {
|
|
3786
|
+
if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
|
|
3787
|
+
else body = writeBlockSequence(state, level, node, compact);
|
|
3788
|
+
} else body = writeFlowSequence(state, level, node);
|
|
3789
|
+
} else {
|
|
3790
|
+
const layout = scalarLayout(state, node, parent, level, iskey, !block);
|
|
3791
|
+
detectAllowedStyles(layout);
|
|
3792
|
+
for (const rule of state.scalarStyleRules) rule(layout);
|
|
3793
|
+
body = renderScalar(layout);
|
|
3794
|
+
state.openEnded = (layout.style === SCALAR_STYLE.LITERAL_BLOCK || layout.style === SCALAR_STYLE.FOLDED_BLOCK) && (node.value === "\n" || node.value.endsWith("\n\n"));
|
|
3795
|
+
shouldPrintTag = node.tagged || body === "" && layout.flowOnly && parent?.kind === "sequence" && !hasAnchor || layout.style !== SCALAR_STYLE.PLAIN && node.tag !== state.defaultScalarTagName;
|
|
3796
|
+
}
|
|
3797
|
+
if ((node.kind === "mapping" || node.kind === "sequence") && !useBlockCollection) state.openEnded = false;
|
|
3798
|
+
if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
|
|
3799
|
+
const noBody = body === "";
|
|
3800
|
+
let text = body;
|
|
3801
|
+
if (shouldPrintTag || hasAnchor) {
|
|
3802
|
+
const props = [];
|
|
3803
|
+
const tag = shouldPrintTag ? nodeTagShort(node) : null;
|
|
3804
|
+
const anchor = hasAnchor ? `&${node.anchor}` : null;
|
|
3805
|
+
if (state.tagBeforeAnchor) {
|
|
3806
|
+
if (tag !== null) props.push(tag);
|
|
3807
|
+
if (anchor !== null) props.push(anchor);
|
|
3808
|
+
} else {
|
|
3809
|
+
if (anchor !== null) props.push(anchor);
|
|
3810
|
+
if (tag !== null) props.push(tag);
|
|
3811
|
+
}
|
|
3812
|
+
const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
|
|
3813
|
+
text = `${props.join(" ")}${sep}${body}`;
|
|
3814
|
+
}
|
|
3815
|
+
return {
|
|
3816
|
+
text,
|
|
3817
|
+
noBody
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
function rootStartsOwnLine(node) {
|
|
3821
|
+
return (node.kind === "sequence" || node.kind === "mapping") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0 && !node.tagged && node.anchor === void 0;
|
|
3822
|
+
}
|
|
3823
|
+
function writeDocumentDirectives(doc) {
|
|
3824
|
+
let result = "";
|
|
3825
|
+
for (const directive of doc.directives) {
|
|
3826
|
+
if (directive.kind === "yaml") {
|
|
3827
|
+
result += `%YAML ${directive.version}\n`;
|
|
3828
|
+
continue;
|
|
3829
|
+
}
|
|
3830
|
+
const { handle, prefix } = directive;
|
|
3831
|
+
result += `%TAG ${handle} ${prefix}\n`;
|
|
3832
|
+
}
|
|
3833
|
+
return result;
|
|
3834
|
+
}
|
|
3835
|
+
/**
|
|
3836
|
+
* Build YAML from AST.
|
|
3837
|
+
*
|
|
3838
|
+
* @category AST
|
|
3839
|
+
*/
|
|
3840
|
+
function present(documents, options) {
|
|
3841
|
+
const state = createPresenterState(options);
|
|
3842
|
+
let result = "";
|
|
3843
|
+
let previousEnded = false;
|
|
3844
|
+
for (let index = 0; index < documents.length; index += 1) {
|
|
3845
|
+
const doc = documents[index];
|
|
3846
|
+
state.openEnded = false;
|
|
3847
|
+
const directives = writeDocumentDirectives(doc);
|
|
3848
|
+
const hasDirectives = directives !== "";
|
|
3849
|
+
const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
|
|
3850
|
+
result += directives;
|
|
3851
|
+
if (doc.contents === null) {
|
|
3852
|
+
if (marker) result += "---\n";
|
|
3853
|
+
} else if (marker) {
|
|
3854
|
+
const body = writeNode(state, 0, doc.contents, null, {
|
|
3855
|
+
block: true,
|
|
3856
|
+
compact: true
|
|
3857
|
+
}).text;
|
|
3858
|
+
const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
|
|
3859
|
+
result += `---${sep}${body}\n`;
|
|
3860
|
+
} else result += writeNode(state, 0, doc.contents, null, {
|
|
3861
|
+
block: true,
|
|
3862
|
+
compact: true
|
|
3863
|
+
}).text + "\n";
|
|
3864
|
+
previousEnded = doc.explicitEnd || state.openEnded;
|
|
3865
|
+
if (previousEnded) result += "...\n";
|
|
3866
|
+
}
|
|
3867
|
+
return result;
|
|
3868
|
+
}
|
|
3869
|
+
var DEFAULT_DUMP_OPTIONS = {
|
|
3870
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3871
|
+
schema: DUMP_SCHEMA,
|
|
3872
|
+
skipInvalid: false,
|
|
3873
|
+
noRefs: false,
|
|
3874
|
+
flowLevel: -1,
|
|
3875
|
+
sortKeys: false,
|
|
3876
|
+
transform: () => {}
|
|
3877
|
+
};
|
|
3878
|
+
function defaultCompareFn(a, b) {
|
|
3879
|
+
const x = String(a);
|
|
3880
|
+
const y = String(b);
|
|
3881
|
+
if (x < y) return -1;
|
|
3882
|
+
if (x > y) return 1;
|
|
3883
|
+
return 0;
|
|
3884
|
+
}
|
|
3885
|
+
/**
|
|
3886
|
+
* Serializes JS object as a YAML document. By default it can dump every
|
|
3887
|
+
* supported YAML type, so it throws an exception if you try to dump regexps or
|
|
3888
|
+
* functions. However, you can disable exceptions by setting the
|
|
3889
|
+
* {@link DumpOptions.skipInvalid} option to `true`.
|
|
3890
|
+
*
|
|
3891
|
+
* @category Main
|
|
3892
|
+
*/
|
|
3893
|
+
function dump(input, options = {}) {
|
|
3894
|
+
const opts = {
|
|
3895
|
+
...DEFAULT_DUMP_OPTIONS,
|
|
3896
|
+
...options
|
|
3897
|
+
};
|
|
3898
|
+
const documents = jsToAst(input, opts.schema, {
|
|
3899
|
+
noRefs: opts.noRefs,
|
|
3900
|
+
skipInvalid: opts.skipInvalid
|
|
3901
|
+
});
|
|
3902
|
+
if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
|
|
3903
|
+
if (ctx.depth < opts.flowLevel) return;
|
|
3904
|
+
if (node.kind === "sequence" || node.kind === "mapping") node.style = COLLECTION_STYLE.FLOW;
|
|
3905
|
+
return VISIT_SKIP;
|
|
3906
|
+
});
|
|
3907
|
+
if (opts.sortKeys) {
|
|
3908
|
+
const compareFn = opts.sortKeys === true ? defaultCompareFn : opts.sortKeys;
|
|
3909
|
+
visit(documents, (node) => {
|
|
3910
|
+
if (node.kind !== "mapping") return;
|
|
3911
|
+
node.items.sort((a, b) => compareFn(a.key.kind === "scalar" ? a.key.value : "", b.key.kind === "scalar" ? b.key.value : ""));
|
|
3912
|
+
});
|
|
3913
|
+
}
|
|
3914
|
+
opts.transform(documents);
|
|
3915
|
+
return present(documents, {
|
|
3916
|
+
...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
|
|
3917
|
+
schema: opts.schema
|
|
3918
|
+
});
|
|
3919
|
+
}
|
|
3920
|
+
EVENT_ID.DOCUMENT;
|
|
3921
|
+
EVENT_ID.SEQUENCE;
|
|
3922
|
+
EVENT_ID.MAPPING;
|
|
3923
|
+
EVENT_ID.SCALAR;
|
|
3924
|
+
EVENT_ID.ALIAS;
|
|
3925
|
+
EVENT_ID.POP;
|
|
3926
|
+
SCALAR_STYLE.PLAIN;
|
|
3927
|
+
SCALAR_STYLE.SINGLE_QUOTED;
|
|
3928
|
+
SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3929
|
+
SCALAR_STYLE.LITERAL_BLOCK;
|
|
3930
|
+
SCALAR_STYLE.FOLDED_BLOCK;
|
|
3931
|
+
COLLECTION_STYLE.BLOCK;
|
|
3932
|
+
COLLECTION_STYLE.FLOW;
|
|
3933
|
+
CHOMPING_MODE.CLIP;
|
|
3934
|
+
CHOMPING_MODE.STRIP;
|
|
3935
|
+
CHOMPING_MODE.KEEP;
|
|
3936
|
+
// \0freelens-host:react
|
|
3937
|
+
var hostModule$1 = globalThis.FreelensExtensionApi.React;
|
|
3938
|
+
var useState = /* @__PURE__ */ Reflect.get(hostModule$1, "useState");
|
|
3939
|
+
// src/renderer/components/yaml-editor-dialog.tsx
|
|
3940
|
+
/**
|
|
3941
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
3942
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
3943
|
+
*/
|
|
3944
|
+
function YamlEditorDialog({ isOpen, title, value, onChange, onClose, onSave }) {
|
|
3945
|
+
const [saving, setSaving] = useState(false);
|
|
3946
|
+
const [error, setError] = useState(null);
|
|
3947
|
+
async function handleSave() {
|
|
3948
|
+
setSaving(true);
|
|
3949
|
+
setError(null);
|
|
3950
|
+
try {
|
|
3951
|
+
await onSave(value);
|
|
3952
|
+
} catch (e) {
|
|
3953
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
3954
|
+
} finally {
|
|
3955
|
+
setSaving(false);
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
return /* @__PURE__ */ jsx(Renderer.Component.Dialog, {
|
|
3959
|
+
isOpen,
|
|
3960
|
+
onClose,
|
|
3961
|
+
modal: true,
|
|
3962
|
+
pinned: true,
|
|
3963
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
3964
|
+
style: {
|
|
3965
|
+
display: "flex",
|
|
3966
|
+
flexDirection: "column",
|
|
3967
|
+
width: "700px",
|
|
3968
|
+
maxWidth: "90vw",
|
|
3969
|
+
gap: "12px",
|
|
3970
|
+
padding: "16px"
|
|
3971
|
+
},
|
|
3972
|
+
children: [
|
|
3973
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3974
|
+
style: {
|
|
3975
|
+
display: "flex",
|
|
3976
|
+
justifyContent: "space-between",
|
|
3977
|
+
alignItems: "center"
|
|
3978
|
+
},
|
|
3979
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
3980
|
+
style: {
|
|
3981
|
+
margin: 0,
|
|
3982
|
+
fontSize: "1.1rem"
|
|
3983
|
+
},
|
|
3984
|
+
children: title
|
|
3985
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
3986
|
+
type: "button",
|
|
3987
|
+
onClick: onClose,
|
|
3988
|
+
style: {
|
|
3989
|
+
background: "none",
|
|
3990
|
+
border: "none",
|
|
3991
|
+
cursor: "pointer",
|
|
3992
|
+
fontSize: "1.2rem",
|
|
3993
|
+
opacity: .7
|
|
3994
|
+
},
|
|
3995
|
+
children: "✕"
|
|
3996
|
+
})]
|
|
3997
|
+
}),
|
|
3998
|
+
/* @__PURE__ */ jsx("div", {
|
|
3999
|
+
style: {
|
|
4000
|
+
height: "450px",
|
|
4001
|
+
border: "1px solid rgba(255,255,255,0.1)",
|
|
4002
|
+
borderRadius: "4px"
|
|
4003
|
+
},
|
|
4004
|
+
children: /* @__PURE__ */ jsx(Renderer.Component.MonacoEditor, {
|
|
4005
|
+
language: "yaml",
|
|
4006
|
+
value,
|
|
4007
|
+
onChange: (v) => onChange(v),
|
|
4008
|
+
style: {
|
|
4009
|
+
height: "100%",
|
|
4010
|
+
width: "100%"
|
|
4011
|
+
}
|
|
4012
|
+
})
|
|
4013
|
+
}),
|
|
4014
|
+
error && /* @__PURE__ */ jsx("div", {
|
|
4015
|
+
style: {
|
|
4016
|
+
color: "#f55",
|
|
4017
|
+
fontSize: "0.85rem",
|
|
4018
|
+
padding: "4px 8px"
|
|
4019
|
+
},
|
|
4020
|
+
children: error
|
|
4021
|
+
}),
|
|
4022
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4023
|
+
style: {
|
|
4024
|
+
display: "flex",
|
|
4025
|
+
justifyContent: "flex-end",
|
|
4026
|
+
gap: "8px"
|
|
4027
|
+
},
|
|
4028
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
4029
|
+
type: "button",
|
|
4030
|
+
onClick: onClose,
|
|
4031
|
+
style: {
|
|
4032
|
+
padding: "6px 14px",
|
|
4033
|
+
cursor: "pointer",
|
|
4034
|
+
borderRadius: "4px",
|
|
4035
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
4036
|
+
background: "transparent"
|
|
4037
|
+
},
|
|
4038
|
+
children: "Cancel"
|
|
4039
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
4040
|
+
type: "button",
|
|
4041
|
+
onClick: handleSave,
|
|
4042
|
+
disabled: saving,
|
|
4043
|
+
style: {
|
|
4044
|
+
padding: "6px 14px",
|
|
4045
|
+
cursor: saving ? "not-allowed" : "pointer",
|
|
4046
|
+
borderRadius: "4px",
|
|
4047
|
+
border: "none",
|
|
4048
|
+
background: "#0084d1",
|
|
4049
|
+
color: "#fff",
|
|
4050
|
+
opacity: saving ? .6 : 1
|
|
4051
|
+
},
|
|
4052
|
+
children: saving ? "Saving…" : "Save"
|
|
4053
|
+
})]
|
|
4054
|
+
})
|
|
4055
|
+
]
|
|
4056
|
+
})
|
|
4057
|
+
});
|
|
4058
|
+
}
|
|
4059
|
+
// src/renderer/menus/resource-edit-yaml-menu-item.tsx
|
|
4060
|
+
/**
|
|
4061
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
4062
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
4063
|
+
*/
|
|
4064
|
+
function toEditYaml(obj) {
|
|
4065
|
+
const raw = obj;
|
|
4066
|
+
const metadata = { ...raw.metadata };
|
|
4067
|
+
delete metadata.managedFields;
|
|
4068
|
+
return dump({
|
|
4069
|
+
apiVersion: raw.apiVersion,
|
|
4070
|
+
kind: raw.kind,
|
|
4071
|
+
metadata,
|
|
4072
|
+
spec: raw.spec
|
|
4073
|
+
}, { lineWidth: -1 });
|
|
4074
|
+
}
|
|
4075
|
+
function ResourceEditYamlMenuItem({ object, api }) {
|
|
4076
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
4077
|
+
const [yaml, setYaml] = useState("");
|
|
4078
|
+
function open() {
|
|
4079
|
+
setYaml(toEditYaml(object));
|
|
4080
|
+
setIsOpen(true);
|
|
4081
|
+
}
|
|
4082
|
+
async function onSave(yamlStr) {
|
|
4083
|
+
const data = load(yamlStr);
|
|
4084
|
+
await api.update({
|
|
4085
|
+
name: object.getName(),
|
|
4086
|
+
namespace: object.getNs() ?? ""
|
|
4087
|
+
}, data);
|
|
4088
|
+
setIsOpen(false);
|
|
4089
|
+
}
|
|
4090
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renderer.Component.MenuItem, {
|
|
4091
|
+
onClick: open,
|
|
4092
|
+
children: "Edit YAML"
|
|
4093
|
+
}), /* @__PURE__ */ jsx(YamlEditorDialog, {
|
|
4094
|
+
isOpen,
|
|
4095
|
+
title: `Edit ${object.getName()}`,
|
|
4096
|
+
value: yaml,
|
|
4097
|
+
onChange: setYaml,
|
|
4098
|
+
onClose: () => setIsOpen(false),
|
|
4099
|
+
onSave
|
|
4100
|
+
})] });
|
|
4101
|
+
}
|
|
4102
|
+
// src/renderer/menus/certificate-edit-menu-item.tsx
|
|
4103
|
+
/**
|
|
4104
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
4105
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
4106
|
+
*/
|
|
4107
|
+
function CertificateEditMenuItem({ object }) {
|
|
4108
|
+
const api = Certificate.getStore().api;
|
|
4109
|
+
return /* @__PURE__ */ jsx(ResourceEditYamlMenuItem, {
|
|
4110
|
+
object,
|
|
4111
|
+
api
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
581
4114
|
// src/renderer/menus/certificate-force-renew-menu-item.tsx
|
|
582
4115
|
/**
|
|
583
4116
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
@@ -613,6 +4146,42 @@ function CertificateForceRenewMenuItem({ object: cert }) {
|
|
|
613
4146
|
children: "Force Renew"
|
|
614
4147
|
});
|
|
615
4148
|
}
|
|
4149
|
+
// src/renderer/menus/certificate-request-edit-menu-item.tsx
|
|
4150
|
+
/**
|
|
4151
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
4152
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
4153
|
+
*/
|
|
4154
|
+
function CertificateRequestEditMenuItem({ object }) {
|
|
4155
|
+
const api = CertificateRequest.getStore().api;
|
|
4156
|
+
return /* @__PURE__ */ jsx(ResourceEditYamlMenuItem, {
|
|
4157
|
+
object,
|
|
4158
|
+
api
|
|
4159
|
+
});
|
|
4160
|
+
}
|
|
4161
|
+
// src/renderer/menus/cluster-issuer-edit-menu-item.tsx
|
|
4162
|
+
/**
|
|
4163
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
4164
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
4165
|
+
*/
|
|
4166
|
+
function ClusterIssuerEditMenuItem({ object }) {
|
|
4167
|
+
const api = ClusterIssuer.getStore().api;
|
|
4168
|
+
return /* @__PURE__ */ jsx(ResourceEditYamlMenuItem, {
|
|
4169
|
+
object,
|
|
4170
|
+
api
|
|
4171
|
+
});
|
|
4172
|
+
}
|
|
4173
|
+
// src/renderer/menus/issuer-edit-menu-item.tsx
|
|
4174
|
+
/**
|
|
4175
|
+
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
4176
|
+
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
4177
|
+
*/
|
|
4178
|
+
function IssuerEditMenuItem({ object }) {
|
|
4179
|
+
const api = Issuer.getStore().api;
|
|
4180
|
+
return /* @__PURE__ */ jsx(ResourceEditYamlMenuItem, {
|
|
4181
|
+
object,
|
|
4182
|
+
api
|
|
4183
|
+
});
|
|
4184
|
+
}
|
|
616
4185
|
// src/renderer/pages/not-installed.tsx
|
|
617
4186
|
/**
|
|
618
4187
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
@@ -647,14 +4216,37 @@ function NotInstalled({ resource }) {
|
|
|
647
4216
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
648
4217
|
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
649
4218
|
*/
|
|
4219
|
+
var CERT_REQUEST_TEMPLATE = `apiVersion: cert-manager.io/v1
|
|
4220
|
+
kind: CertificateRequest
|
|
4221
|
+
metadata:
|
|
4222
|
+
name: my-certificate-request
|
|
4223
|
+
namespace: default
|
|
4224
|
+
spec:
|
|
4225
|
+
issuerRef:
|
|
4226
|
+
name: my-issuer
|
|
4227
|
+
kind: Issuer
|
|
4228
|
+
# request: <base64-encoded PEM CSR>
|
|
4229
|
+
duration: 2160h
|
|
4230
|
+
`;
|
|
650
4231
|
function CertificateRequestsPage() {
|
|
4232
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
4233
|
+
const [createYaml, setCreateYaml] = useState(CERT_REQUEST_TEMPLATE);
|
|
651
4234
|
let store;
|
|
652
4235
|
try {
|
|
653
4236
|
store = CertificateRequest.getStore();
|
|
654
4237
|
} catch {
|
|
655
4238
|
return /* @__PURE__ */ jsx(NotInstalled, { resource: "CertificateRequest" });
|
|
656
4239
|
}
|
|
657
|
-
|
|
4240
|
+
async function handleCreate(yamlStr) {
|
|
4241
|
+
const data = load(yamlStr);
|
|
4242
|
+
const meta = data.metadata;
|
|
4243
|
+
await store.api.create({
|
|
4244
|
+
name: String(meta?.name ?? ""),
|
|
4245
|
+
namespace: String(meta?.namespace ?? "default")
|
|
4246
|
+
}, data);
|
|
4247
|
+
setCreateOpen(false);
|
|
4248
|
+
}
|
|
4249
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renderer.Component.KubeObjectListLayout, {
|
|
658
4250
|
store,
|
|
659
4251
|
isConfigurable: true,
|
|
660
4252
|
tableId: "cert-manager-certificate-requests",
|
|
@@ -690,8 +4282,22 @@ function CertificateRequestsPage() {
|
|
|
690
4282
|
isCertReqApproved(cr) ? "✓" : isCertReqDenied(cr) ? "Denied" : "-",
|
|
691
4283
|
issuerRef ? `${issuerRef.kind}/${issuerRef.name}` : "-"
|
|
692
4284
|
];
|
|
4285
|
+
},
|
|
4286
|
+
addRemoveButtons: {
|
|
4287
|
+
onAdd: () => {
|
|
4288
|
+
setCreateYaml(CERT_REQUEST_TEMPLATE);
|
|
4289
|
+
setCreateOpen(true);
|
|
4290
|
+
},
|
|
4291
|
+
addTooltip: "Create CertificateRequest"
|
|
693
4292
|
}
|
|
694
|
-
})
|
|
4293
|
+
}), /* @__PURE__ */ jsx(YamlEditorDialog, {
|
|
4294
|
+
isOpen: createOpen,
|
|
4295
|
+
title: "Create CertificateRequest",
|
|
4296
|
+
value: createYaml,
|
|
4297
|
+
onChange: setCreateYaml,
|
|
4298
|
+
onClose: () => setCreateOpen(false),
|
|
4299
|
+
onSave: handleCreate
|
|
4300
|
+
})] });
|
|
695
4301
|
}
|
|
696
4302
|
// src/renderer/pages/certificates-page.tsx
|
|
697
4303
|
/**
|
|
@@ -707,14 +4313,38 @@ function certStatus(obj) {
|
|
|
707
4313
|
function certIsReady(obj) {
|
|
708
4314
|
return (certStatus(obj).conditions ?? []).some((c) => c.type === "Ready" && c.status === "True");
|
|
709
4315
|
}
|
|
4316
|
+
var CERT_TEMPLATE = `apiVersion: cert-manager.io/v1
|
|
4317
|
+
kind: Certificate
|
|
4318
|
+
metadata:
|
|
4319
|
+
name: my-certificate
|
|
4320
|
+
namespace: default
|
|
4321
|
+
spec:
|
|
4322
|
+
secretName: my-certificate-tls
|
|
4323
|
+
issuerRef:
|
|
4324
|
+
name: selfsigned-issuer
|
|
4325
|
+
kind: Issuer
|
|
4326
|
+
dnsNames:
|
|
4327
|
+
- example.com
|
|
4328
|
+
`;
|
|
710
4329
|
function CertificatesPage() {
|
|
4330
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
4331
|
+
const [createYaml, setCreateYaml] = useState(CERT_TEMPLATE);
|
|
711
4332
|
let store;
|
|
712
4333
|
try {
|
|
713
4334
|
store = Certificate.getStore();
|
|
714
4335
|
} catch {
|
|
715
4336
|
return /* @__PURE__ */ jsx(NotInstalled, { resource: "Certificate" });
|
|
716
4337
|
}
|
|
717
|
-
|
|
4338
|
+
async function handleCreate(yamlStr) {
|
|
4339
|
+
const data = load(yamlStr);
|
|
4340
|
+
const meta = data.metadata;
|
|
4341
|
+
await store.api.create({
|
|
4342
|
+
name: String(meta?.name ?? ""),
|
|
4343
|
+
namespace: String(meta?.namespace ?? "default")
|
|
4344
|
+
}, data);
|
|
4345
|
+
setCreateOpen(false);
|
|
4346
|
+
}
|
|
4347
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renderer.Component.KubeObjectListLayout, {
|
|
718
4348
|
store,
|
|
719
4349
|
isConfigurable: true,
|
|
720
4350
|
tableId: "cert-manager-certificates",
|
|
@@ -747,22 +4377,51 @@ function CertificatesPage() {
|
|
|
747
4377
|
certIsReady(cert) ? "✓" : "✗",
|
|
748
4378
|
certSpec(cert).secretName ?? "-",
|
|
749
4379
|
certStatus(cert).notAfter ?? "-"
|
|
750
|
-
]
|
|
751
|
-
|
|
4380
|
+
],
|
|
4381
|
+
addRemoveButtons: {
|
|
4382
|
+
onAdd: () => {
|
|
4383
|
+
setCreateYaml(CERT_TEMPLATE);
|
|
4384
|
+
setCreateOpen(true);
|
|
4385
|
+
},
|
|
4386
|
+
addTooltip: "Create Certificate"
|
|
4387
|
+
}
|
|
4388
|
+
}), /* @__PURE__ */ jsx(YamlEditorDialog, {
|
|
4389
|
+
isOpen: createOpen,
|
|
4390
|
+
title: "Create Certificate",
|
|
4391
|
+
value: createYaml,
|
|
4392
|
+
onChange: setCreateYaml,
|
|
4393
|
+
onClose: () => setCreateOpen(false),
|
|
4394
|
+
onSave: handleCreate
|
|
4395
|
+
})] });
|
|
752
4396
|
}
|
|
753
4397
|
// src/renderer/pages/cluster-issuers-page.tsx
|
|
754
4398
|
/**
|
|
755
4399
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
756
4400
|
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
757
4401
|
*/
|
|
4402
|
+
var CLUSTER_ISSUER_TEMPLATE = `apiVersion: cert-manager.io/v1
|
|
4403
|
+
kind: ClusterIssuer
|
|
4404
|
+
metadata:
|
|
4405
|
+
name: my-cluster-issuer
|
|
4406
|
+
spec:
|
|
4407
|
+
selfSigned: {}
|
|
4408
|
+
`;
|
|
758
4409
|
function ClusterIssuersPage() {
|
|
4410
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
4411
|
+
const [createYaml, setCreateYaml] = useState(CLUSTER_ISSUER_TEMPLATE);
|
|
759
4412
|
let store;
|
|
760
4413
|
try {
|
|
761
4414
|
store = ClusterIssuer.getStore();
|
|
762
4415
|
} catch {
|
|
763
4416
|
return /* @__PURE__ */ jsx(NotInstalled, { resource: "ClusterIssuer" });
|
|
764
4417
|
}
|
|
765
|
-
|
|
4418
|
+
async function handleCreate(yamlStr) {
|
|
4419
|
+
const data = load(yamlStr);
|
|
4420
|
+
const meta = data.metadata;
|
|
4421
|
+
await store.api.create({ name: String(meta?.name ?? "") }, data);
|
|
4422
|
+
setCreateOpen(false);
|
|
4423
|
+
}
|
|
4424
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renderer.Component.KubeObjectListLayout, {
|
|
766
4425
|
store,
|
|
767
4426
|
isConfigurable: true,
|
|
768
4427
|
tableId: "cert-manager-cluster-issuers",
|
|
@@ -785,22 +4444,55 @@ function ClusterIssuersPage() {
|
|
|
785
4444
|
issuer.getName(),
|
|
786
4445
|
isClusterIssuerReady(issuer) ? "✓" : "✗",
|
|
787
4446
|
getClusterIssuerType(issuer)
|
|
788
|
-
]
|
|
789
|
-
|
|
4447
|
+
],
|
|
4448
|
+
addRemoveButtons: {
|
|
4449
|
+
onAdd: () => {
|
|
4450
|
+
setCreateYaml(CLUSTER_ISSUER_TEMPLATE);
|
|
4451
|
+
setCreateOpen(true);
|
|
4452
|
+
},
|
|
4453
|
+
addTooltip: "Create ClusterIssuer"
|
|
4454
|
+
}
|
|
4455
|
+
}), /* @__PURE__ */ jsx(YamlEditorDialog, {
|
|
4456
|
+
isOpen: createOpen,
|
|
4457
|
+
title: "Create ClusterIssuer",
|
|
4458
|
+
value: createYaml,
|
|
4459
|
+
onChange: setCreateYaml,
|
|
4460
|
+
onClose: () => setCreateOpen(false),
|
|
4461
|
+
onSave: handleCreate
|
|
4462
|
+
})] });
|
|
790
4463
|
}
|
|
791
4464
|
// src/renderer/pages/issuers-page.tsx
|
|
792
4465
|
/**
|
|
793
4466
|
* Author: Maifee Ul Asad <maifeeulasad@gmail.com>
|
|
794
4467
|
* Co-Author: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
795
4468
|
*/
|
|
4469
|
+
var ISSUER_TEMPLATE = `apiVersion: cert-manager.io/v1
|
|
4470
|
+
kind: Issuer
|
|
4471
|
+
metadata:
|
|
4472
|
+
name: my-issuer
|
|
4473
|
+
namespace: default
|
|
4474
|
+
spec:
|
|
4475
|
+
selfSigned: {}
|
|
4476
|
+
`;
|
|
796
4477
|
function IssuersPage() {
|
|
4478
|
+
const [createOpen, setCreateOpen] = useState(false);
|
|
4479
|
+
const [createYaml, setCreateYaml] = useState(ISSUER_TEMPLATE);
|
|
797
4480
|
let store;
|
|
798
4481
|
try {
|
|
799
4482
|
store = Issuer.getStore();
|
|
800
4483
|
} catch {
|
|
801
4484
|
return /* @__PURE__ */ jsx(NotInstalled, { resource: "Issuer" });
|
|
802
4485
|
}
|
|
803
|
-
|
|
4486
|
+
async function handleCreate(yamlStr) {
|
|
4487
|
+
const data = load(yamlStr);
|
|
4488
|
+
const meta = data.metadata;
|
|
4489
|
+
await store.api.create({
|
|
4490
|
+
name: String(meta?.name ?? ""),
|
|
4491
|
+
namespace: String(meta?.namespace ?? "default")
|
|
4492
|
+
}, data);
|
|
4493
|
+
setCreateOpen(false);
|
|
4494
|
+
}
|
|
4495
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renderer.Component.KubeObjectListLayout, {
|
|
804
4496
|
store,
|
|
805
4497
|
isConfigurable: true,
|
|
806
4498
|
tableId: "cert-manager-issuers",
|
|
@@ -828,8 +4520,22 @@ function IssuersPage() {
|
|
|
828
4520
|
issuer.getNs(),
|
|
829
4521
|
isIssuerReady(issuer) ? "✓" : "✗",
|
|
830
4522
|
getIssuerType(issuer)
|
|
831
|
-
]
|
|
832
|
-
|
|
4523
|
+
],
|
|
4524
|
+
addRemoveButtons: {
|
|
4525
|
+
onAdd: () => {
|
|
4526
|
+
setCreateYaml(ISSUER_TEMPLATE);
|
|
4527
|
+
setCreateOpen(true);
|
|
4528
|
+
},
|
|
4529
|
+
addTooltip: "Create Issuer"
|
|
4530
|
+
}
|
|
4531
|
+
}), /* @__PURE__ */ jsx(YamlEditorDialog, {
|
|
4532
|
+
isOpen: createOpen,
|
|
4533
|
+
title: "Create Issuer",
|
|
4534
|
+
value: createYaml,
|
|
4535
|
+
onChange: setCreateYaml,
|
|
4536
|
+
onClose: () => setCreateOpen(false),
|
|
4537
|
+
onSave: handleCreate
|
|
4538
|
+
})] });
|
|
833
4539
|
}
|
|
834
4540
|
// \0freelens-host:mobx-react
|
|
835
4541
|
var hostModule = globalThis.FreelensExtensionApi.MobxReact;
|
|
@@ -917,7 +4623,14 @@ var CertManagerRenderer = class extends Renderer.LensExtension {
|
|
|
917
4623
|
Hint: () => /* @__PURE__ */ jsx(CertManagerPreferenceHint, {})
|
|
918
4624
|
}
|
|
919
4625
|
}];
|
|
920
|
-
kubeObjectMenuItems = [
|
|
4626
|
+
kubeObjectMenuItems = [
|
|
4627
|
+
Renderer.K8sApi.menuItemFor(Certificate, { MenuItem: CertificateForceRenewMenuItem }),
|
|
4628
|
+
Renderer.K8sApi.menuItemFor(Certificate, { MenuItem: CertificateDeleteCascadeMenuItem }),
|
|
4629
|
+
Renderer.K8sApi.menuItemFor(Certificate, { MenuItem: CertificateEditMenuItem }),
|
|
4630
|
+
Renderer.K8sApi.menuItemFor(Issuer, { MenuItem: IssuerEditMenuItem }),
|
|
4631
|
+
Renderer.K8sApi.menuItemFor(ClusterIssuer, { MenuItem: ClusterIssuerEditMenuItem }),
|
|
4632
|
+
Renderer.K8sApi.menuItemFor(CertificateRequest, { MenuItem: CertificateRequestEditMenuItem })
|
|
4633
|
+
];
|
|
921
4634
|
clusterPageMenus = [
|
|
922
4635
|
{
|
|
923
4636
|
id: "cert-manager",
|