yaml 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +99 -111
- 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 +57 -58
- 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 +30 -47
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +22 -39
- 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 +168 -0
- package/browser/dist/errors.js +71 -74
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +26 -45
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +33 -50
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +33 -53
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +53 -56
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +67 -81
- package/browser/dist/schema/parseMap.js +63 -70
- package/browser/dist/schema/parseSeq.js +45 -44
- package/browser/dist/schema/parseUtils.js +47 -11
- package/browser/dist/stringify.js +43 -48
- package/browser/dist/tags/core.js +30 -37
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +17 -26
- 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 +16 -29
- 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 +28 -0
- package/browser/map.js +1 -1
- package/browser/pair.js +1 -1
- package/browser/scalar.js +1 -1
- package/browser/schema.js +1 -1
- package/browser/seq.js +1 -1
- package/browser/types/binary.js +1 -1
- package/browser/types/omap.js +1 -1
- package/browser/types/pairs.js +1 -1
- package/browser/types/set.js +1 -1
- package/browser/types/timestamp.js +1 -1
- package/dist/Document.js +21 -9
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/CollectionItem.js +27 -6
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +7 -9
- package/dist/cst/ParseContext.js +41 -55
- package/dist/cst/PlainValue.js +1 -1
- package/dist/cst/source-utils.js +178 -0
- package/dist/errors.js +37 -3
- package/dist/index.js +5 -4
- package/dist/schema/Alias.js +2 -1
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Merge.js +4 -5
- package/dist/schema/Pair.js +20 -2
- package/dist/schema/index.js +14 -8
- package/dist/schema/parseMap.js +20 -5
- package/dist/schema/parseSeq.js +19 -6
- package/dist/schema/parseUtils.js +54 -6
- package/dist/stringify.js +21 -11
- package/dist/tags/core.js +27 -10
- 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/index.js +6 -6
- package/dist/tags/yaml-1.1/omap.js +3 -5
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +3 -1
- package/dist/{deprecation.js → warnings.js} +12 -7
- package/map.js +1 -1
- package/package.json +35 -17
- package/pair.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +1 -1
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/types.mjs +20 -0
- package/util.mjs +24 -0
- package/browser/dist/cst/getLinePos.js +0 -79
- package/browser/dist/deprecation.js +0 -34
- package/dist/cst/getLinePos.js +0 -79
package/browser/dist/index.js
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _parse = _interopRequireDefault(require("./cst/parse"));
|
|
19
|
-
|
|
20
|
-
var _Document = _interopRequireDefault(require("./Document"));
|
|
21
|
-
|
|
22
|
-
var _errors = require("./errors");
|
|
23
|
-
|
|
24
|
-
var _schema = _interopRequireDefault(require("./schema"));
|
|
25
|
-
|
|
26
|
-
/* global console */
|
|
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 _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import parseCST from './cst/parse';
|
|
6
|
+
import YAMLDocument from './Document';
|
|
7
|
+
import { YAMLSemanticError } from './errors';
|
|
8
|
+
import Schema from './schema';
|
|
9
|
+
import { warn } from './warnings';
|
|
27
10
|
var defaultOptions = {
|
|
28
11
|
anchorPrefix: 'a',
|
|
29
12
|
customTags: null,
|
|
@@ -34,6 +17,7 @@ var defaultOptions = {
|
|
|
34
17
|
maxAliasCount: 100,
|
|
35
18
|
prettyErrors: false,
|
|
36
19
|
// TODO Set true in v2
|
|
20
|
+
simpleKeys: false,
|
|
37
21
|
version: '1.2'
|
|
38
22
|
};
|
|
39
23
|
|
|
@@ -46,23 +30,22 @@ function createNode(value) {
|
|
|
46
30
|
wrapScalars = true;
|
|
47
31
|
}
|
|
48
32
|
|
|
49
|
-
var options = Object.assign({},
|
|
50
|
-
var schema = new
|
|
33
|
+
var options = Object.assign({}, YAMLDocument.defaults[defaultOptions.version], defaultOptions);
|
|
34
|
+
var schema = new Schema(options);
|
|
51
35
|
return schema.createNode(value, wrapScalars, tag);
|
|
52
36
|
}
|
|
53
37
|
|
|
54
|
-
var Document =
|
|
55
|
-
|
|
56
|
-
function (_YAMLDocument) {
|
|
57
|
-
(0, _inherits2.default)(Document, _YAMLDocument);
|
|
38
|
+
var Document = /*#__PURE__*/function (_YAMLDocument) {
|
|
39
|
+
_inherits(Document, _YAMLDocument);
|
|
58
40
|
|
|
59
41
|
function Document(options) {
|
|
60
|
-
(
|
|
61
|
-
|
|
42
|
+
_classCallCheck(this, Document);
|
|
43
|
+
|
|
44
|
+
return _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Object.assign({}, defaultOptions, options)));
|
|
62
45
|
}
|
|
63
46
|
|
|
64
47
|
return Document;
|
|
65
|
-
}(
|
|
48
|
+
}(YAMLDocument);
|
|
66
49
|
|
|
67
50
|
function parseAllDocuments(src, options) {
|
|
68
51
|
var stream = [];
|
|
@@ -72,7 +55,7 @@ function parseAllDocuments(src, options) {
|
|
|
72
55
|
var _iteratorError = undefined;
|
|
73
56
|
|
|
74
57
|
try {
|
|
75
|
-
for (var _iterator = (
|
|
58
|
+
for (var _iterator = parseCST(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
76
59
|
var cstDoc = _step.value;
|
|
77
60
|
var doc = new Document(options);
|
|
78
61
|
doc.parse(cstDoc, prev);
|
|
@@ -98,22 +81,21 @@ function parseAllDocuments(src, options) {
|
|
|
98
81
|
}
|
|
99
82
|
|
|
100
83
|
function parseDocument(src, options) {
|
|
101
|
-
var cst = (
|
|
84
|
+
var cst = parseCST(src);
|
|
102
85
|
var doc = new Document(options).parse(cst[0]);
|
|
103
86
|
|
|
104
87
|
if (cst.length > 1) {
|
|
105
88
|
var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
|
|
106
|
-
doc.errors.unshift(new
|
|
89
|
+
doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg));
|
|
107
90
|
}
|
|
108
91
|
|
|
109
92
|
return doc;
|
|
110
93
|
}
|
|
111
94
|
|
|
112
95
|
function parse(src, options) {
|
|
113
|
-
var doc = parseDocument(src, options);
|
|
114
|
-
|
|
96
|
+
var doc = parseDocument(src, options);
|
|
115
97
|
doc.warnings.forEach(function (warning) {
|
|
116
|
-
return
|
|
98
|
+
return warn(warning);
|
|
117
99
|
});
|
|
118
100
|
if (doc.errors.length > 0) throw doc.errors[0];
|
|
119
101
|
return doc.toJSON();
|
|
@@ -125,14 +107,13 @@ function stringify(value, options) {
|
|
|
125
107
|
return String(doc);
|
|
126
108
|
}
|
|
127
109
|
|
|
128
|
-
|
|
110
|
+
export default {
|
|
129
111
|
createNode: createNode,
|
|
130
112
|
defaultOptions: defaultOptions,
|
|
131
113
|
Document: Document,
|
|
132
114
|
parse: parse,
|
|
133
115
|
parseAllDocuments: parseAllDocuments,
|
|
134
|
-
parseCST:
|
|
116
|
+
parseCST: parseCST,
|
|
135
117
|
parseDocument: parseDocument,
|
|
136
118
|
stringify: stringify
|
|
137
|
-
};
|
|
138
|
-
exports.default = _default;
|
|
119
|
+
};
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
|
-
var _Collection = _interopRequireDefault(require("./schema/Collection"));
|
|
13
|
-
|
|
14
|
-
var _Pair = _interopRequireDefault(require("./schema/Pair"));
|
|
15
|
-
|
|
16
|
-
var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import Collection from './schema/Collection';
|
|
3
|
+
import Pair from './schema/Pair';
|
|
4
|
+
import Scalar from './schema/Scalar';
|
|
17
5
|
|
|
18
6
|
var visit = function visit(node, tags) {
|
|
19
|
-
if (node && (
|
|
7
|
+
if (node && _typeof(node) === 'object') {
|
|
20
8
|
var tag = node.tag;
|
|
21
9
|
|
|
22
|
-
if (node instanceof
|
|
10
|
+
if (node instanceof Collection) {
|
|
23
11
|
if (tag) tags[tag] = true;
|
|
24
12
|
node.items.forEach(function (n) {
|
|
25
13
|
return visit(n, tags);
|
|
26
14
|
});
|
|
27
|
-
} else if (node instanceof
|
|
15
|
+
} else if (node instanceof Pair) {
|
|
28
16
|
visit(node.key, tags);
|
|
29
17
|
visit(node.value, tags);
|
|
30
|
-
} else if (node instanceof
|
|
18
|
+
} else if (node instanceof Scalar) {
|
|
31
19
|
if (tag) tags[tag] = true;
|
|
32
20
|
}
|
|
33
21
|
}
|
|
@@ -35,8 +23,6 @@ var visit = function visit(node, tags) {
|
|
|
35
23
|
return tags;
|
|
36
24
|
};
|
|
37
25
|
|
|
38
|
-
|
|
26
|
+
export default (function (node) {
|
|
39
27
|
return Object.keys(visit(node, {}));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
exports.default = _default;
|
|
28
|
+
});
|
|
@@ -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
|
-
if (!anchor ||
|
|
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 };
|