yaml 1.7.2 → 1.8.3
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/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +86 -110
- package/browser/dist/addComment.js +2 -11
- package/browser/dist/constants.js +3 -11
- package/browser/dist/cst/Alias.js +19 -36
- package/browser/dist/cst/BlankLine.js +25 -38
- package/browser/dist/cst/BlockValue.js +29 -51
- package/browser/dist/cst/Collection.js +42 -65
- package/browser/dist/cst/CollectionItem.js +33 -55
- package/browser/dist/cst/Comment.js +19 -35
- package/browser/dist/cst/Directive.js +20 -56
- package/browser/dist/cst/Document.js +47 -71
- package/browser/dist/cst/FlowCollection.js +38 -61
- package/browser/dist/cst/Node.js +26 -46
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +21 -38
- package/browser/dist/cst/QuoteDouble.js +26 -42
- package/browser/dist/cst/QuoteSingle.js +25 -41
- package/browser/dist/cst/Range.js +9 -19
- package/browser/dist/cst/parse.js +5 -16
- package/browser/dist/cst/source-utils.js +3 -14
- package/browser/dist/errors.js +42 -78
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +24 -44
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +32 -49
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +32 -52
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +40 -58
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +66 -81
- package/browser/dist/schema/parseMap.js +52 -72
- package/browser/dist/schema/parseSeq.js +30 -45
- package/browser/dist/schema/parseUtils.js +12 -25
- package/browser/dist/stringify.js +39 -45
- package/browser/dist/tags/core.js +34 -40
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +15 -24
- package/browser/dist/tags/failsafe/seq.js +7 -18
- package/browser/dist/tags/failsafe/string.js +7 -19
- package/browser/dist/tags/index.js +35 -49
- package/browser/dist/tags/json.js +11 -38
- package/browser/dist/tags/options.js +8 -20
- package/browser/dist/tags/yaml-1.1/binary.js +22 -33
- package/browser/dist/tags/yaml-1.1/index.js +34 -54
- package/browser/dist/tags/yaml-1.1/omap.js +39 -58
- package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
- package/browser/dist/tags/yaml-1.1/set.js +35 -61
- package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
- package/browser/dist/test-events.js +7 -19
- package/browser/dist/toJSON.js +1 -8
- package/browser/dist/warnings.js +3 -15
- package/dist/Document.js +1 -1
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +0 -5
- package/dist/cst/ParseContext.js +41 -55
- package/dist/schema/Alias.js +1 -0
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Pair.js +1 -0
- package/dist/schema/index.js +10 -5
- package/dist/schema/parseMap.js +1 -1
- package/dist/stringify.js +15 -8
- package/dist/tags/core.js +31 -13
- package/dist/tags/failsafe/map.js +5 -1
- package/dist/tags/failsafe/seq.js +1 -1
- package/dist/tags/index.js +13 -1
- package/dist/tags/json.js +2 -9
- package/dist/tags/yaml-1.1/binary.js +8 -5
- package/dist/tags/yaml-1.1/index.js +6 -6
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +1 -1
- package/package.json +43 -17
- package/types.mjs +20 -0
- package/util.mjs +24 -0
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
|
-
var _constants = require("../constants");
|
|
23
|
-
|
|
24
|
-
var _errors = require("../errors");
|
|
25
|
-
|
|
26
|
-
var _toJSON2 = _interopRequireDefault(require("../toJSON"));
|
|
27
|
-
|
|
28
|
-
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
29
|
-
|
|
30
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
31
|
-
|
|
32
|
-
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
3
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
7
|
+
import { Type } from '../constants';
|
|
8
|
+
import { YAMLReferenceError } from '../errors';
|
|
9
|
+
import _toJSON from '../toJSON';
|
|
10
|
+
import Collection from './Collection';
|
|
11
|
+
import Node from './Node';
|
|
12
|
+
import Pair from './Pair';
|
|
33
13
|
|
|
34
14
|
var getAliasCount = function getAliasCount(node, anchors) {
|
|
35
15
|
if (node instanceof Alias) {
|
|
@@ -37,7 +17,7 @@ var getAliasCount = function getAliasCount(node, anchors) {
|
|
|
37
17
|
return a.node === node.source;
|
|
38
18
|
});
|
|
39
19
|
return anchor.count * anchor.aliasCount;
|
|
40
|
-
} else if (node instanceof
|
|
20
|
+
} else if (node instanceof Collection) {
|
|
41
21
|
var count = 0;
|
|
42
22
|
var _iteratorNormalCompletion = true;
|
|
43
23
|
var _didIteratorError = false;
|
|
@@ -65,7 +45,7 @@ var getAliasCount = function getAliasCount(node, anchors) {
|
|
|
65
45
|
}
|
|
66
46
|
|
|
67
47
|
return count;
|
|
68
|
-
} else if (node instanceof
|
|
48
|
+
} else if (node instanceof Pair) {
|
|
69
49
|
var kc = getAliasCount(node.key, anchors);
|
|
70
50
|
var vc = getAliasCount(node.value, anchors);
|
|
71
51
|
return Math.max(kc, vc);
|
|
@@ -74,11 +54,10 @@ var getAliasCount = function getAliasCount(node, anchors) {
|
|
|
74
54
|
return 1;
|
|
75
55
|
};
|
|
76
56
|
|
|
77
|
-
var Alias =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
(
|
|
81
|
-
(0, _createClass2.default)(Alias, null, [{
|
|
57
|
+
var Alias = /*#__PURE__*/function (_Node) {
|
|
58
|
+
_inherits(Alias, _Node);
|
|
59
|
+
|
|
60
|
+
_createClass(Alias, null, [{
|
|
82
61
|
key: "stringify",
|
|
83
62
|
value: function stringify(_ref, _ref2) {
|
|
84
63
|
var range = _ref.range,
|
|
@@ -100,28 +79,30 @@ function (_Node) {
|
|
|
100
79
|
function Alias(source) {
|
|
101
80
|
var _this;
|
|
102
81
|
|
|
103
|
-
(
|
|
104
|
-
|
|
82
|
+
_classCallCheck(this, Alias);
|
|
83
|
+
|
|
84
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Alias).call(this));
|
|
105
85
|
_this.source = source;
|
|
106
|
-
_this.type =
|
|
86
|
+
_this.type = Type.ALIAS;
|
|
107
87
|
return _this;
|
|
108
88
|
}
|
|
109
89
|
|
|
110
|
-
(
|
|
90
|
+
_createClass(Alias, [{
|
|
111
91
|
key: "toJSON",
|
|
112
92
|
value: function toJSON(arg, ctx) {
|
|
113
93
|
var _this2 = this;
|
|
114
94
|
|
|
115
|
-
if (!ctx) return (
|
|
95
|
+
if (!ctx) return _toJSON(this.source, arg, ctx);
|
|
116
96
|
var anchors = ctx.anchors,
|
|
117
97
|
maxAliasCount = ctx.maxAliasCount;
|
|
118
98
|
var anchor = anchors.find(function (a) {
|
|
119
99
|
return a.node === _this2.source;
|
|
120
100
|
});
|
|
101
|
+
/* istanbul ignore if */
|
|
121
102
|
|
|
122
103
|
if (!anchor || anchor.res === undefined) {
|
|
123
104
|
var msg = 'This should not happen: Alias anchor was not resolved?';
|
|
124
|
-
if (this.cstNode) throw new
|
|
105
|
+
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
125
106
|
}
|
|
126
107
|
|
|
127
108
|
if (maxAliasCount >= 0) {
|
|
@@ -130,7 +111,7 @@ function (_Node) {
|
|
|
130
111
|
|
|
131
112
|
if (anchor.count * anchor.aliasCount > maxAliasCount) {
|
|
132
113
|
var _msg = 'Excessive alias count indicates a resource exhaustion attack';
|
|
133
|
-
if (this.cstNode) throw new
|
|
114
|
+
if (this.cstNode) throw new YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg);
|
|
134
115
|
}
|
|
135
116
|
}
|
|
136
117
|
|
|
@@ -149,8 +130,10 @@ function (_Node) {
|
|
|
149
130
|
throw new Error('Alias nodes cannot have tags');
|
|
150
131
|
}
|
|
151
132
|
}]);
|
|
133
|
+
|
|
152
134
|
return Alias;
|
|
153
|
-
}(
|
|
135
|
+
}(Node);
|
|
136
|
+
|
|
137
|
+
_defineProperty(Alias, "default", true);
|
|
154
138
|
|
|
155
|
-
|
|
156
|
-
(0, _defineProperty2.default)(Alias, "default", true);
|
|
139
|
+
export { Alias as default };
|
|
@@ -1,82 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
-
|
|
26
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
27
|
-
|
|
28
|
-
var _addComment = _interopRequireDefault(require("../addComment"));
|
|
29
|
-
|
|
30
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
1
|
+
import _toArray from "@babel/runtime/helpers/toArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
10
|
+
import addComment from '../addComment';
|
|
11
|
+
import Node from './Node';
|
|
12
|
+
import Pair from './Pair';
|
|
13
|
+
import Scalar from './Scalar';
|
|
14
|
+
|
|
15
|
+
function collectionFromPath(schema, path, value) {
|
|
16
|
+
var v = value;
|
|
17
|
+
|
|
18
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
19
|
+
var k = path[i];
|
|
20
|
+
var o = Number.isInteger(k) && k >= 0 ? [] : {};
|
|
21
|
+
o[k] = v;
|
|
22
|
+
v = o;
|
|
23
|
+
}
|
|
31
24
|
|
|
32
|
-
|
|
25
|
+
return schema.createNode(v, false);
|
|
26
|
+
} // null, undefined, or an empty non-string iterable (e.g. [])
|
|
33
27
|
|
|
34
|
-
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return path == null || (0, _typeof2.default)(path) === 'object' && path[Symbol.iterator]().next().done;
|
|
29
|
+
export var isEmptyPath = function isEmptyPath(path) {
|
|
30
|
+
return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done;
|
|
39
31
|
};
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var Collection =
|
|
44
|
-
/*#__PURE__*/
|
|
45
|
-
function (_Node) {
|
|
46
|
-
(0, _inherits2.default)(Collection, _Node);
|
|
47
|
-
|
|
48
|
-
function Collection() {
|
|
49
|
-
var _getPrototypeOf2;
|
|
33
|
+
var Collection = /*#__PURE__*/function (_Node) {
|
|
34
|
+
_inherits(Collection, _Node);
|
|
50
35
|
|
|
36
|
+
function Collection(schema) {
|
|
51
37
|
var _this;
|
|
52
38
|
|
|
53
|
-
(
|
|
39
|
+
_classCallCheck(this, Collection);
|
|
54
40
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this));
|
|
42
|
+
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "items", []);
|
|
58
44
|
|
|
59
|
-
_this
|
|
60
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "items", []);
|
|
45
|
+
_this.schema = schema;
|
|
61
46
|
return _this;
|
|
62
47
|
}
|
|
63
48
|
|
|
64
|
-
(
|
|
49
|
+
_createClass(Collection, [{
|
|
65
50
|
key: "addIn",
|
|
66
51
|
value: function addIn(path, value) {
|
|
67
52
|
if (isEmptyPath(path)) this.add(value);else {
|
|
68
|
-
var _path = (
|
|
53
|
+
var _path = _toArray(path),
|
|
69
54
|
key = _path[0],
|
|
70
55
|
rest = _path.slice(1);
|
|
71
56
|
|
|
72
57
|
var node = this.get(key, true);
|
|
73
|
-
if (node instanceof Collection) node.addIn(rest, value);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
|
|
58
|
+
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
|
|
74
59
|
}
|
|
75
60
|
}
|
|
76
61
|
}, {
|
|
77
62
|
key: "deleteIn",
|
|
78
63
|
value: function deleteIn(_ref) {
|
|
79
|
-
var _ref2 = (
|
|
64
|
+
var _ref2 = _toArray(_ref),
|
|
80
65
|
key = _ref2[0],
|
|
81
66
|
rest = _ref2.slice(1);
|
|
82
67
|
|
|
@@ -87,26 +72,26 @@ function (_Node) {
|
|
|
87
72
|
}, {
|
|
88
73
|
key: "getIn",
|
|
89
74
|
value: function getIn(_ref3, keepScalar) {
|
|
90
|
-
var _ref4 = (
|
|
75
|
+
var _ref4 = _toArray(_ref3),
|
|
91
76
|
key = _ref4[0],
|
|
92
77
|
rest = _ref4.slice(1);
|
|
93
78
|
|
|
94
79
|
var node = this.get(key, true);
|
|
95
|
-
if (rest.length === 0) return !keepScalar && node instanceof
|
|
80
|
+
if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
|
|
96
81
|
}
|
|
97
82
|
}, {
|
|
98
83
|
key: "hasAllNullValues",
|
|
99
84
|
value: function hasAllNullValues() {
|
|
100
85
|
return this.items.every(function (node) {
|
|
101
|
-
if (!(node instanceof
|
|
86
|
+
if (!(node instanceof Pair)) return false;
|
|
102
87
|
var n = node.value;
|
|
103
|
-
return n == null || n instanceof
|
|
88
|
+
return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
104
89
|
});
|
|
105
90
|
}
|
|
106
91
|
}, {
|
|
107
92
|
key: "hasIn",
|
|
108
93
|
value: function hasIn(_ref5) {
|
|
109
|
-
var _ref6 = (
|
|
94
|
+
var _ref6 = _toArray(_ref5),
|
|
110
95
|
key = _ref6[0],
|
|
111
96
|
rest = _ref6.slice(1);
|
|
112
97
|
|
|
@@ -117,7 +102,7 @@ function (_Node) {
|
|
|
117
102
|
}, {
|
|
118
103
|
key: "setIn",
|
|
119
104
|
value: function setIn(_ref7, value) {
|
|
120
|
-
var _ref8 = (
|
|
105
|
+
var _ref8 = _toArray(_ref7),
|
|
121
106
|
key = _ref8[0],
|
|
122
107
|
rest = _ref8.slice(1);
|
|
123
108
|
|
|
@@ -125,10 +110,12 @@ function (_Node) {
|
|
|
125
110
|
this.set(key, value);
|
|
126
111
|
} else {
|
|
127
112
|
var node = this.get(key, true);
|
|
128
|
-
if (node instanceof Collection) node.setIn(rest, value);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
|
|
113
|
+
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
|
|
129
114
|
}
|
|
130
115
|
} // overridden in implementations
|
|
131
116
|
|
|
117
|
+
/* istanbul ignore next */
|
|
118
|
+
|
|
132
119
|
}, {
|
|
133
120
|
key: "toJSON",
|
|
134
121
|
value: function toJSON() {
|
|
@@ -183,7 +170,7 @@ function (_Node) {
|
|
|
183
170
|
});
|
|
184
171
|
if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
|
|
185
172
|
if (inFlow && i < _this2.items.length - 1) str += ',';
|
|
186
|
-
str = (
|
|
173
|
+
str = addComment(str, itemIndent, comment);
|
|
187
174
|
if (chompKeep && (comment || inFlow)) chompKeep = false;
|
|
188
175
|
nodes.push({
|
|
189
176
|
type: 'item',
|
|
@@ -271,8 +258,10 @@ function (_Node) {
|
|
|
271
258
|
return str;
|
|
272
259
|
}
|
|
273
260
|
}]);
|
|
261
|
+
|
|
274
262
|
return Collection;
|
|
275
|
-
}(
|
|
263
|
+
}(Node);
|
|
264
|
+
|
|
265
|
+
_defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
|
|
276
266
|
|
|
277
|
-
|
|
278
|
-
(0, _defineProperty2.default)(Collection, "maxFlowStringSingleLineLength", 60);
|
|
267
|
+
export { Collection as default };
|
|
@@ -1,33 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
-
|
|
15
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
16
|
-
|
|
17
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
18
|
-
|
|
19
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
20
|
-
|
|
21
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
22
|
-
|
|
23
|
-
var _Collection2 = _interopRequireDefault(require("./Collection"));
|
|
24
|
-
|
|
25
|
-
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
26
|
-
|
|
27
|
-
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
28
|
-
|
|
29
|
-
function findPair(items, key) {
|
|
30
|
-
var k = key instanceof _Scalar.default ? key.value : key;
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _get from "@babel/runtime/helpers/get";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import Collection from './Collection';
|
|
8
|
+
import Pair from './Pair';
|
|
9
|
+
import Scalar from './Scalar';
|
|
10
|
+
export function findPair(items, key) {
|
|
11
|
+
var k = key instanceof Scalar ? key.value : key;
|
|
31
12
|
var _iteratorNormalCompletion = true;
|
|
32
13
|
var _didIteratorError = false;
|
|
33
14
|
var _iteratorError = undefined;
|
|
@@ -36,7 +17,7 @@ function findPair(items, key) {
|
|
|
36
17
|
for (var _iterator = items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
37
18
|
var it = _step.value;
|
|
38
19
|
|
|
39
|
-
if (it instanceof
|
|
20
|
+
if (it instanceof Pair) {
|
|
40
21
|
if (it.key === key || it.key === k) return it;
|
|
41
22
|
if (it.key && it.key.value === k) return it;
|
|
42
23
|
}
|
|
@@ -59,23 +40,32 @@ function findPair(items, key) {
|
|
|
59
40
|
return undefined;
|
|
60
41
|
}
|
|
61
42
|
|
|
62
|
-
var YAMLMap =
|
|
63
|
-
|
|
64
|
-
function (_Collection) {
|
|
65
|
-
(0, _inherits2.default)(YAMLMap, _Collection);
|
|
43
|
+
var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
44
|
+
_inherits(YAMLMap, _Collection);
|
|
66
45
|
|
|
67
46
|
function YAMLMap() {
|
|
68
|
-
(
|
|
69
|
-
|
|
47
|
+
_classCallCheck(this, YAMLMap);
|
|
48
|
+
|
|
49
|
+
return _possibleConstructorReturn(this, _getPrototypeOf(YAMLMap).apply(this, arguments));
|
|
70
50
|
}
|
|
71
51
|
|
|
72
|
-
(
|
|
52
|
+
_createClass(YAMLMap, [{
|
|
73
53
|
key: "add",
|
|
74
|
-
value: function add(pair) {
|
|
75
|
-
if (!pair) pair = new
|
|
54
|
+
value: function add(pair, overwrite) {
|
|
55
|
+
if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
|
|
76
56
|
var prev = findPair(this.items, pair.key);
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
var sortEntries = this.schema && this.schema.sortMapEntries;
|
|
58
|
+
|
|
59
|
+
if (prev) {
|
|
60
|
+
if (overwrite) prev.value = pair.value;else throw new Error("Key ".concat(pair.key, " already set"));
|
|
61
|
+
} else if (sortEntries) {
|
|
62
|
+
var i = this.items.findIndex(function (item) {
|
|
63
|
+
return sortEntries(pair, item) < 0;
|
|
64
|
+
});
|
|
65
|
+
if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
|
|
66
|
+
} else {
|
|
67
|
+
this.items.push(pair);
|
|
68
|
+
}
|
|
79
69
|
}
|
|
80
70
|
}, {
|
|
81
71
|
key: "delete",
|
|
@@ -90,7 +80,7 @@ function (_Collection) {
|
|
|
90
80
|
value: function get(key, keepScalar) {
|
|
91
81
|
var it = findPair(this.items, key);
|
|
92
82
|
var node = it && it.value;
|
|
93
|
-
return !keepScalar && node instanceof
|
|
83
|
+
return !keepScalar && node instanceof Scalar ? node.value : node;
|
|
94
84
|
}
|
|
95
85
|
}, {
|
|
96
86
|
key: "has",
|
|
@@ -100,8 +90,7 @@ function (_Collection) {
|
|
|
100
90
|
}, {
|
|
101
91
|
key: "set",
|
|
102
92
|
value: function set(key, value) {
|
|
103
|
-
|
|
104
|
-
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
|
|
93
|
+
this.add(new Pair(key, value), true);
|
|
105
94
|
}
|
|
106
95
|
/**
|
|
107
96
|
* @param {*} arg ignored
|
|
@@ -152,7 +141,7 @@ function (_Collection) {
|
|
|
152
141
|
try {
|
|
153
142
|
for (var _iterator3 = this.items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
154
143
|
var item = _step3.value;
|
|
155
|
-
if (!(item instanceof
|
|
144
|
+
if (!(item instanceof Pair)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
|
|
156
145
|
}
|
|
157
146
|
} catch (err) {
|
|
158
147
|
_didIteratorError3 = true;
|
|
@@ -169,7 +158,7 @@ function (_Collection) {
|
|
|
169
158
|
}
|
|
170
159
|
}
|
|
171
160
|
|
|
172
|
-
return (
|
|
161
|
+
return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, {
|
|
173
162
|
blockItem: function blockItem(n) {
|
|
174
163
|
return n.str;
|
|
175
164
|
},
|
|
@@ -182,7 +171,8 @@ function (_Collection) {
|
|
|
182
171
|
}, onComment, onChompKeep);
|
|
183
172
|
}
|
|
184
173
|
}]);
|
|
174
|
+
|
|
185
175
|
return YAMLMap;
|
|
186
|
-
}(
|
|
176
|
+
}(Collection);
|
|
187
177
|
|
|
188
|
-
|
|
178
|
+
export { YAMLMap as default };
|
|
@@ -1,64 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
21
|
-
|
|
22
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
|
-
|
|
24
|
-
var _Map = _interopRequireDefault(require("./Map"));
|
|
25
|
-
|
|
26
|
-
var _Pair2 = _interopRequireDefault(require("./Pair"));
|
|
27
|
-
|
|
28
|
-
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
29
|
-
|
|
30
|
-
var _Seq = _interopRequireDefault(require("./Seq"));
|
|
31
|
-
|
|
32
|
-
var MERGE_KEY = '<<';
|
|
33
|
-
exports.MERGE_KEY = MERGE_KEY;
|
|
34
|
-
|
|
35
|
-
var Merge =
|
|
36
|
-
/*#__PURE__*/
|
|
37
|
-
function (_Pair) {
|
|
38
|
-
(0, _inherits2.default)(Merge, _Pair);
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _get from "@babel/runtime/helpers/get";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
+
import YAMLMap from './Map';
|
|
9
|
+
import Pair from './Pair';
|
|
10
|
+
import Scalar from './Scalar';
|
|
11
|
+
import Seq from './Seq';
|
|
12
|
+
export var MERGE_KEY = '<<';
|
|
13
|
+
|
|
14
|
+
var Merge = /*#__PURE__*/function (_Pair) {
|
|
15
|
+
_inherits(Merge, _Pair);
|
|
39
16
|
|
|
40
17
|
function Merge(pair) {
|
|
41
18
|
var _this;
|
|
42
19
|
|
|
43
|
-
(
|
|
20
|
+
_classCallCheck(this, Merge);
|
|
44
21
|
|
|
45
|
-
if (pair instanceof
|
|
22
|
+
if (pair instanceof Pair) {
|
|
46
23
|
var seq = pair.value;
|
|
47
24
|
|
|
48
|
-
if (!(seq instanceof
|
|
49
|
-
seq = new
|
|
25
|
+
if (!(seq instanceof Seq)) {
|
|
26
|
+
seq = new Seq();
|
|
50
27
|
seq.items.push(pair.value);
|
|
51
28
|
seq.range = pair.value.range;
|
|
52
29
|
}
|
|
53
30
|
|
|
54
|
-
_this = (
|
|
31
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, pair.key, seq));
|
|
55
32
|
_this.range = pair.range;
|
|
56
33
|
} else {
|
|
57
|
-
_this = (
|
|
34
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Merge).call(this, new Scalar(MERGE_KEY), new Seq()));
|
|
58
35
|
}
|
|
59
36
|
|
|
60
37
|
_this.type = 'MERGE_PAIR';
|
|
61
|
-
return (
|
|
38
|
+
return _possibleConstructorReturn(_this);
|
|
62
39
|
} // If the value associated with a merge key is a single mapping node, each of
|
|
63
40
|
// its key/value pairs is inserted into the current mapping, unless the key
|
|
64
41
|
// already exists in it. If the value associated with the merge key is a
|
|
@@ -68,7 +45,7 @@ function (_Pair) {
|
|
|
68
45
|
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
69
46
|
|
|
70
47
|
|
|
71
|
-
(
|
|
48
|
+
_createClass(Merge, [{
|
|
72
49
|
key: "addToJSMap",
|
|
73
50
|
value: function addToJSMap(ctx, map) {
|
|
74
51
|
var _iteratorNormalCompletion = true;
|
|
@@ -78,7 +55,7 @@ function (_Pair) {
|
|
|
78
55
|
try {
|
|
79
56
|
for (var _iterator = this.value.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
80
57
|
var source = _step.value.source;
|
|
81
|
-
if (!(source instanceof
|
|
58
|
+
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
|
|
82
59
|
var srcMap = source.toJSON(null, ctx, Map);
|
|
83
60
|
var _iteratorNormalCompletion2 = true;
|
|
84
61
|
var _didIteratorError2 = false;
|
|
@@ -86,7 +63,7 @@ function (_Pair) {
|
|
|
86
63
|
|
|
87
64
|
try {
|
|
88
65
|
for (var _iterator2 = srcMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
89
|
-
var _step2$value = (
|
|
66
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
90
67
|
key = _step2$value[0],
|
|
91
68
|
value = _step2$value[1];
|
|
92
69
|
|
|
@@ -134,14 +111,17 @@ function (_Pair) {
|
|
|
134
111
|
key: "toString",
|
|
135
112
|
value: function toString(ctx, onComment) {
|
|
136
113
|
var seq = this.value;
|
|
137
|
-
if (seq.items.length > 1) return (
|
|
114
|
+
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
138
115
|
this.value = seq.items[0];
|
|
139
|
-
|
|
116
|
+
|
|
117
|
+
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
118
|
+
|
|
140
119
|
this.value = seq;
|
|
141
120
|
return str;
|
|
142
121
|
}
|
|
143
122
|
}]);
|
|
123
|
+
|
|
144
124
|
return Merge;
|
|
145
|
-
}(
|
|
125
|
+
}(Pair);
|
|
146
126
|
|
|
147
|
-
|
|
127
|
+
export { Merge as default };
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
11
2
|
|
|
12
3
|
var Node = function Node() {
|
|
13
|
-
(
|
|
4
|
+
_classCallCheck(this, Node);
|
|
14
5
|
};
|
|
15
6
|
|
|
16
|
-
|
|
7
|
+
export { Node as default };
|