cdk8s 2.7.62 → 2.7.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/.jsii +3 -3
  2. package/lib/api-object.js +1 -1
  3. package/lib/app.js +1 -1
  4. package/lib/chart.js +1 -1
  5. package/lib/cron.js +1 -1
  6. package/lib/dependency.js +2 -2
  7. package/lib/duration.js +1 -1
  8. package/lib/helm.js +1 -1
  9. package/lib/include.js +1 -1
  10. package/lib/json-patch.js +1 -1
  11. package/lib/lazy.js +1 -1
  12. package/lib/metadata.js +1 -1
  13. package/lib/names.js +1 -1
  14. package/lib/size.js +1 -1
  15. package/lib/testing.js +1 -1
  16. package/lib/yaml.js +6 -4
  17. package/node_modules/yaml/README.md +2 -2
  18. package/node_modules/yaml/browser/dist/compose/compose-collection.js +1 -1
  19. package/node_modules/yaml/browser/dist/compose/compose-doc.js +4 -3
  20. package/node_modules/yaml/browser/dist/compose/compose-node.js +18 -5
  21. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +19 -13
  22. package/node_modules/yaml/browser/dist/compose/composer.js +8 -10
  23. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +30 -13
  24. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +12 -3
  25. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +10 -5
  26. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +17 -6
  27. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +8 -2
  28. package/node_modules/yaml/browser/dist/compose/resolve-props.js +9 -1
  29. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +1 -1
  30. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  31. package/node_modules/yaml/browser/dist/doc/Document.js +76 -19
  32. package/node_modules/yaml/browser/dist/doc/anchors.js +2 -2
  33. package/node_modules/yaml/browser/dist/doc/createNode.js +14 -11
  34. package/node_modules/yaml/browser/dist/doc/directives.js +11 -3
  35. package/node_modules/yaml/browser/dist/errors.js +1 -1
  36. package/node_modules/yaml/browser/dist/index.js +1 -2
  37. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
  38. package/node_modules/yaml/browser/dist/nodes/Collection.js +30 -16
  39. package/node_modules/yaml/browser/dist/nodes/Node.js +7 -0
  40. package/node_modules/yaml/browser/dist/nodes/Pair.js +11 -3
  41. package/node_modules/yaml/browser/dist/nodes/Scalar.js +1 -1
  42. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +10 -10
  43. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +5 -13
  44. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +3 -2
  45. package/node_modules/yaml/browser/dist/nodes/toJS.js +3 -1
  46. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +3 -8
  47. package/node_modules/yaml/browser/dist/parse/cst-visit.js +2 -2
  48. package/node_modules/yaml/browser/dist/parse/lexer.js +49 -22
  49. package/node_modules/yaml/browser/dist/parse/parser.js +142 -68
  50. package/node_modules/yaml/browser/dist/public-api.js +5 -7
  51. package/node_modules/yaml/browser/dist/schema/Schema.js +19 -4
  52. package/node_modules/yaml/browser/dist/schema/common/null.js +3 -1
  53. package/node_modules/yaml/browser/dist/schema/core/float.js +4 -1
  54. package/node_modules/yaml/browser/dist/schema/tags.js +17 -13
  55. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +4 -1
  56. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +1 -1
  57. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  58. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +6 -1
  59. package/node_modules/yaml/browser/dist/stringify/stringify.js +53 -23
  60. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +114 -85
  61. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +18 -12
  62. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +36 -15
  63. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +71 -32
  64. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +56 -53
  65. package/node_modules/yaml/browser/dist/util.js +3 -0
  66. package/node_modules/yaml/browser/dist/visit.js +149 -62
  67. package/node_modules/yaml/dist/compose/compose-collection.js +1 -1
  68. package/node_modules/yaml/dist/compose/compose-doc.js +4 -3
  69. package/node_modules/yaml/dist/compose/compose-node.d.ts +4 -2
  70. package/node_modules/yaml/dist/compose/compose-node.js +18 -5
  71. package/node_modules/yaml/dist/compose/compose-scalar.js +18 -12
  72. package/node_modules/yaml/dist/compose/composer.d.ts +3 -3
  73. package/node_modules/yaml/dist/compose/composer.js +10 -12
  74. package/node_modules/yaml/dist/compose/resolve-block-map.js +30 -13
  75. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +12 -3
  76. package/node_modules/yaml/dist/compose/resolve-block-seq.js +10 -5
  77. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +17 -6
  78. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +8 -2
  79. package/node_modules/yaml/dist/compose/resolve-props.d.ts +2 -1
  80. package/node_modules/yaml/dist/compose/resolve-props.js +9 -1
  81. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +1 -1
  82. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  83. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  84. package/node_modules/yaml/dist/doc/Document.d.ts +24 -15
  85. package/node_modules/yaml/dist/doc/Document.js +80 -23
  86. package/node_modules/yaml/dist/doc/anchors.d.ts +3 -3
  87. package/node_modules/yaml/dist/doc/anchors.js +2 -2
  88. package/node_modules/yaml/dist/doc/applyReviver.d.ts +1 -1
  89. package/node_modules/yaml/dist/doc/createNode.d.ts +3 -2
  90. package/node_modules/yaml/dist/doc/createNode.js +13 -10
  91. package/node_modules/yaml/dist/doc/directives.d.ts +5 -2
  92. package/node_modules/yaml/dist/doc/directives.js +11 -3
  93. package/node_modules/yaml/dist/errors.d.ts +2 -2
  94. package/node_modules/yaml/dist/errors.js +1 -1
  95. package/node_modules/yaml/dist/index.d.ts +6 -4
  96. package/node_modules/yaml/dist/index.js +1 -2
  97. package/node_modules/yaml/dist/log.d.ts +1 -1
  98. package/node_modules/yaml/dist/nodes/Alias.d.ts +8 -4
  99. package/node_modules/yaml/dist/nodes/Collection.d.ts +12 -6
  100. package/node_modules/yaml/dist/nodes/Collection.js +29 -15
  101. package/node_modules/yaml/dist/nodes/Node.d.ts +22 -11
  102. package/node_modules/yaml/dist/nodes/Node.js +7 -0
  103. package/node_modules/yaml/dist/nodes/Pair.d.ts +8 -3
  104. package/node_modules/yaml/dist/nodes/Pair.js +10 -2
  105. package/node_modules/yaml/dist/nodes/Scalar.d.ts +2 -0
  106. package/node_modules/yaml/dist/nodes/Scalar.js +1 -1
  107. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +12 -4
  108. package/node_modules/yaml/dist/nodes/YAMLMap.js +10 -10
  109. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +6 -1
  110. package/node_modules/yaml/dist/nodes/YAMLSeq.js +5 -13
  111. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +2 -1
  112. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +2 -1
  113. package/node_modules/yaml/dist/nodes/toJS.js +3 -1
  114. package/node_modules/yaml/dist/options.d.ts +82 -22
  115. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +6 -0
  116. package/node_modules/yaml/dist/parse/cst-scalar.js +3 -8
  117. package/node_modules/yaml/dist/parse/cst-visit.d.ts +2 -2
  118. package/node_modules/yaml/dist/parse/cst-visit.js +2 -2
  119. package/node_modules/yaml/dist/parse/cst.d.ts +3 -3
  120. package/node_modules/yaml/dist/parse/lexer.d.ts +2 -0
  121. package/node_modules/yaml/dist/parse/lexer.js +49 -22
  122. package/node_modules/yaml/dist/parse/parser.js +142 -68
  123. package/node_modules/yaml/dist/public-api.js +5 -7
  124. package/node_modules/yaml/dist/schema/Schema.d.ts +9 -7
  125. package/node_modules/yaml/dist/schema/Schema.js +18 -3
  126. package/node_modules/yaml/dist/schema/common/null.js +3 -1
  127. package/node_modules/yaml/dist/schema/core/float.js +4 -1
  128. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  129. package/node_modules/yaml/dist/schema/tags.d.ts +3 -4
  130. package/node_modules/yaml/dist/schema/tags.js +17 -13
  131. package/node_modules/yaml/dist/schema/types.d.ts +1 -1
  132. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +4 -1
  133. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +7 -3
  134. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +1 -1
  135. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +1 -1
  136. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +6 -2
  137. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +6 -1
  138. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +1 -1
  139. package/node_modules/yaml/dist/stringify/stringify.d.ts +7 -4
  140. package/node_modules/yaml/dist/stringify/stringify.js +53 -23
  141. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +2 -6
  142. package/node_modules/yaml/dist/stringify/stringifyCollection.js +113 -84
  143. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -2
  144. package/node_modules/yaml/dist/stringify/stringifyComment.js +19 -12
  145. package/node_modules/yaml/dist/stringify/stringifyDocument.js +35 -14
  146. package/node_modules/yaml/dist/stringify/stringifyPair.js +70 -31
  147. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +7 -1
  148. package/node_modules/yaml/dist/stringify/stringifyString.js +56 -53
  149. package/node_modules/yaml/dist/test-events.d.ts +1 -1
  150. package/node_modules/yaml/dist/test-events.js +14 -14
  151. package/node_modules/yaml/dist/util.d.ts +3 -0
  152. package/node_modules/yaml/dist/util.js +6 -0
  153. package/node_modules/yaml/dist/visit.d.ts +51 -12
  154. package/node_modules/yaml/dist/visit.js +148 -60
  155. package/node_modules/yaml/package.json +19 -17
  156. package/node_modules/yaml/util.d.ts +3 -0
  157. package/package.json +2 -2
  158. package/node_modules/yaml/browser/dist/options.js +0 -17
  159. package/node_modules/yaml/dist/options.js +0 -19
@@ -3,8 +3,8 @@
3
3
  var Scalar = require('../nodes/Scalar.js');
4
4
  var foldFlowLines = require('./foldFlowLines.js');
5
5
 
6
- const getFoldOptions = (ctx) => ({
7
- indentAtStart: ctx.indentAtStart,
6
+ const getFoldOptions = (ctx, isBlock) => ({
7
+ indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
8
8
  lineWidth: ctx.options.lineWidth,
9
9
  minContentWidth: ctx.options.minContentWidth
10
10
  });
@@ -117,37 +117,53 @@ function doubleQuotedString(value, ctx) {
117
117
  str = start ? str + json.slice(start) : json;
118
118
  return implicitKey
119
119
  ? str
120
- : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
120
+ : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
121
121
  }
122
122
  function singleQuotedString(value, ctx) {
123
- if (ctx.implicitKey) {
124
- if (/\n/.test(value))
125
- return doubleQuotedString(value, ctx);
126
- }
127
- else {
128
- // single quoted string can't have leading or trailing whitespace around newline
129
- if (/[ \t]\n|\n[ \t]/.test(value))
130
- return doubleQuotedString(value, ctx);
131
- }
123
+ if (ctx.options.singleQuote === false ||
124
+ (ctx.implicitKey && value.includes('\n')) ||
125
+ /[ \t]\n|\n[ \t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline
126
+ )
127
+ return doubleQuotedString(value, ctx);
132
128
  const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
133
129
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
134
130
  return ctx.implicitKey
135
131
  ? res
136
- : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
132
+ : foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
133
+ }
134
+ function quotedString(value, ctx) {
135
+ const { singleQuote } = ctx.options;
136
+ let qs;
137
+ if (singleQuote === false)
138
+ qs = doubleQuotedString;
139
+ else {
140
+ const hasDouble = value.includes('"');
141
+ const hasSingle = value.includes("'");
142
+ if (hasDouble && !hasSingle)
143
+ qs = singleQuotedString;
144
+ else if (hasSingle && !hasDouble)
145
+ qs = doubleQuotedString;
146
+ else
147
+ qs = singleQuote ? singleQuotedString : doubleQuotedString;
148
+ }
149
+ return qs(value, ctx);
137
150
  }
138
151
  function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
152
+ const { blockQuote, commentString, lineWidth } = ctx.options;
139
153
  // 1. Block can't end in whitespace unless the last line is non-empty.
140
154
  // 2. Strings consisting of only whitespace are best rendered explicitly.
141
- if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
142
- return doubleQuotedString(value, ctx);
155
+ if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
156
+ return quotedString(value, ctx);
143
157
  }
144
158
  const indent = ctx.indent ||
145
159
  (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
146
- const literal = type === Scalar.Scalar.BLOCK_FOLDED
147
- ? false
148
- : type === Scalar.Scalar.BLOCK_LITERAL
149
- ? true
150
- : !lineLengthOverLimit(value, ctx.options.lineWidth, indent.length);
160
+ const literal = blockQuote === 'literal'
161
+ ? true
162
+ : blockQuote === 'folded' || type === Scalar.Scalar.BLOCK_FOLDED
163
+ ? false
164
+ : type === Scalar.Scalar.BLOCK_LITERAL
165
+ ? true
166
+ : !lineLengthOverLimit(value, lineWidth, indent.length);
151
167
  if (!value)
152
168
  return literal ? '|\n' : '>\n';
153
169
  // determine chomping from whitespace at value end
@@ -198,7 +214,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
198
214
  const indentSize = indent ? '2' : '1'; // root is at -1
199
215
  let header = (literal ? '|' : '>') + (startWithSpace ? indentSize : '') + chomp;
200
216
  if (comment) {
201
- header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
217
+ header += ' ' + commentString(comment.replace(/ ?[\r\n]+/g, ' '));
202
218
  if (onComment)
203
219
  onComment();
204
220
  }
@@ -211,70 +227,57 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
211
227
  .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
212
228
  // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
213
229
  .replace(/\n+/g, `$&${indent}`);
214
- const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx));
230
+ const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true));
215
231
  return `${header}\n${indent}${body}`;
216
232
  }
217
233
  function plainString(item, ctx, onComment, onChompKeep) {
218
- var _a;
219
234
  const { type, value } = item;
220
- const { actualString, implicitKey, indent, inFlow } = ctx;
235
+ const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
221
236
  if ((implicitKey && /[\n[\]{},]/.test(value)) ||
222
237
  (inFlow && /[[\]{},]/.test(value))) {
223
- return doubleQuotedString(value, ctx);
238
+ return quotedString(value, ctx);
224
239
  }
225
240
  if (!value ||
226
241
  /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
227
- const hasDouble = value.indexOf('"') !== -1;
228
- const hasSingle = value.indexOf("'") !== -1;
229
- let quotedString;
230
- if (hasDouble && !hasSingle) {
231
- quotedString = singleQuotedString;
232
- }
233
- else if (hasSingle && !hasDouble) {
234
- quotedString = doubleQuotedString;
235
- }
236
- else if (ctx.options.singleQuote) {
237
- quotedString = singleQuotedString;
238
- }
239
- else {
240
- quotedString = doubleQuotedString;
241
- }
242
242
  // not allowed:
243
243
  // - empty string, '-' or '?'
244
244
  // - start with an indicator character (except [?:-]) or /[?-] /
245
245
  // - '\n ', ': ' or ' \n' anywhere
246
246
  // - '#' not preceded by a non-space char
247
247
  // - end with ' ' or ':'
248
- return implicitKey || inFlow || value.indexOf('\n') === -1
248
+ return implicitKey || inFlow || !value.includes('\n')
249
249
  ? quotedString(value, ctx)
250
250
  : blockString(item, ctx, onComment, onChompKeep);
251
251
  }
252
252
  if (!implicitKey &&
253
253
  !inFlow &&
254
254
  type !== Scalar.Scalar.PLAIN &&
255
- value.indexOf('\n') !== -1) {
255
+ value.includes('\n')) {
256
256
  // Where allowed & type not set explicitly, prefer block style for multiline strings
257
257
  return blockString(item, ctx, onComment, onChompKeep);
258
258
  }
259
- if (indent === '' && containsDocumentMarker(value)) {
260
- ctx.forceBlockIndent = true;
261
- return blockString(item, ctx, onComment, onChompKeep);
259
+ if (containsDocumentMarker(value)) {
260
+ if (indent === '') {
261
+ ctx.forceBlockIndent = true;
262
+ return blockString(item, ctx, onComment, onChompKeep);
263
+ }
264
+ else if (implicitKey && indent === indentStep) {
265
+ return quotedString(value, ctx);
266
+ }
262
267
  }
263
268
  const str = value.replace(/\n+/g, `$&\n${indent}`);
264
269
  // Verify that output will be parsed as a string, as e.g. plain numbers and
265
270
  // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
266
271
  // and others in v1.1.
267
272
  if (actualString) {
268
- for (const tag of ctx.doc.schema.tags) {
269
- if (tag.default &&
270
- tag.tag !== 'tag:yaml.org,2002:str' &&
271
- ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)))
272
- return doubleQuotedString(value, ctx);
273
- }
273
+ const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
274
+ const { compat, tags } = ctx.doc.schema;
275
+ if (tags.some(test) || compat?.some(test))
276
+ return quotedString(value, ctx);
274
277
  }
275
278
  return implicitKey
276
279
  ? str
277
- : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
280
+ : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
278
281
  }
279
282
  function stringifyString(item, ctx, onComment, onChompKeep) {
280
283
  const { implicitKey, inFlow } = ctx;
@@ -292,7 +295,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
292
295
  case Scalar.Scalar.BLOCK_FOLDED:
293
296
  case Scalar.Scalar.BLOCK_LITERAL:
294
297
  return implicitKey || inFlow
295
- ? doubleQuotedString(ss.value, ctx) // blocks are not valid inside flow containers
298
+ ? quotedString(ss.value, ctx) // blocks are not valid inside flow containers
296
299
  : blockString(ss, ctx, onComment, onChompKeep);
297
300
  case Scalar.Scalar.QUOTE_DOUBLE:
298
301
  return doubleQuotedString(ss.value, ctx);
@@ -1,4 +1,4 @@
1
1
  export declare function testEvents(src: string): {
2
2
  events: string[];
3
- error: any;
3
+ error: unknown;
4
4
  };
@@ -25,7 +25,6 @@ function anchorExists(doc, anchor) {
25
25
  }
26
26
  // test harness for yaml-test-suite event tests
27
27
  function testEvents(src) {
28
- var _a;
29
28
  const docs = publicApi.parseAllDocuments(src);
30
29
  const errDoc = docs.find(doc => doc.errors.length > 0);
31
30
  const error = errDoc ? errDoc.errors[0].message : null;
@@ -36,29 +35,28 @@ function testEvents(src) {
36
35
  let root = doc.contents;
37
36
  if (Array.isArray(root))
38
37
  root = root[0];
39
- // eslint-disable-next-line no-sparse-arrays
40
- const [rootStart, , rootEnd] = doc.range || [0, , 0];
38
+ const [rootStart] = doc.range || [0];
41
39
  const error = doc.errors[0];
42
40
  if (error && (!error.pos || error.pos[0] < rootStart))
43
41
  throw new Error();
44
42
  let docStart = '+DOC';
45
- if (doc.directives.marker)
43
+ if (doc.directives.docStart)
46
44
  docStart += ' ---';
47
- else if (doc.contents && doc.contents.range[2] === doc.contents.range[0])
45
+ else if (doc.contents &&
46
+ doc.contents.range[2] === doc.contents.range[0] &&
47
+ !doc.contents.anchor &&
48
+ !doc.contents.tag)
48
49
  continue;
49
50
  events.push(docStart);
50
- addEvents(events, doc, (_a = error === null || error === void 0 ? void 0 : error.pos[0]) !== null && _a !== void 0 ? _a : -1, root);
51
+ addEvents(events, doc, error?.pos[0] ?? -1, root);
51
52
  let docEnd = '-DOC';
52
- if (rootEnd) {
53
- const post = src.slice(rootStart, rootEnd);
54
- if (/^\.\.\.($|\s)/m.test(post))
55
- docEnd += ' ...';
56
- }
53
+ if (doc.directives.docEnd)
54
+ docEnd += ' ...';
57
55
  events.push(docEnd);
58
56
  }
59
57
  }
60
58
  catch (e) {
61
- return { events, error: error || e };
59
+ return { events, error: error ?? e };
62
60
  }
63
61
  events.push('-STR');
64
62
  return { events, error };
@@ -83,7 +81,8 @@ function addEvents(events, doc, errPos, node) {
83
81
  if (Node.isNode(node) && node.tag)
84
82
  props += ` <${node.tag}>`;
85
83
  if (Node.isMap(node)) {
86
- events.push(`+MAP${props}`);
84
+ const ev = node.flow ? '+MAP {}' : '+MAP';
85
+ events.push(`${ev}${props}`);
87
86
  node.items.forEach(({ key, value }) => {
88
87
  addEvents(events, doc, errPos, key);
89
88
  addEvents(events, doc, errPos, value);
@@ -91,7 +90,8 @@ function addEvents(events, doc, errPos, node) {
91
90
  events.push('-MAP');
92
91
  }
93
92
  else if (Node.isSeq(node)) {
94
- events.push(`+SEQ${props}`);
93
+ const ev = node.flow ? '+SEQ []' : '+SEQ';
94
+ events.push(`${ev}${props}`);
95
95
  node.items.forEach(item => {
96
96
  addEvents(events, doc, errPos, item);
97
97
  });
@@ -1,6 +1,9 @@
1
1
  export { debug, LogLevelId, warn } from './log.js';
2
2
  export { findPair } from './nodes/YAMLMap.js';
3
3
  export { toJS, ToJSContext } from './nodes/toJS.js';
4
+ export { map as mapTag } from './schema/common/map.js';
5
+ export { seq as seqTag } from './schema/common/seq.js';
6
+ export { string as stringTag } from './schema/common/string.js';
4
7
  export { foldFlowLines } from './stringify/foldFlowLines';
5
8
  export { stringifyNumber } from './stringify/stringifyNumber.js';
6
9
  export { stringifyString } from './stringify/stringifyString.js';
@@ -3,6 +3,9 @@
3
3
  var log = require('./log.js');
4
4
  var YAMLMap = require('./nodes/YAMLMap.js');
5
5
  var toJS = require('./nodes/toJS.js');
6
+ var map = require('./schema/common/map.js');
7
+ var seq = require('./schema/common/seq.js');
8
+ var string = require('./schema/common/string.js');
6
9
  var foldFlowLines = require('./stringify/foldFlowLines.js');
7
10
  var stringifyNumber = require('./stringify/stringifyNumber.js');
8
11
  var stringifyString = require('./stringify/stringifyString.js');
@@ -13,6 +16,9 @@ exports.debug = log.debug;
13
16
  exports.warn = log.warn;
14
17
  exports.findPair = YAMLMap.findPair;
15
18
  exports.toJS = toJS.toJS;
19
+ exports.mapTag = map.map;
20
+ exports.seqTag = seq.seq;
21
+ exports.stringTag = string.string;
16
22
  exports.foldFlowLines = foldFlowLines.foldFlowLines;
17
23
  exports.stringifyNumber = stringifyNumber.stringifyNumber;
18
24
  exports.stringifyString = stringifyString.stringifyString;
@@ -5,8 +5,8 @@ import type { Pair } from './nodes/Pair.js';
5
5
  import type { Scalar } from './nodes/Scalar.js';
6
6
  import type { YAMLMap } from './nodes/YAMLMap.js';
7
7
  import type { YAMLSeq } from './nodes/YAMLSeq.js';
8
- export declare type visitorFn<T> = (key: number | 'key' | 'value' | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair;
9
- export declare type visitor = visitorFn<unknown> | {
8
+ export type visitorFn<T> = (key: number | 'key' | 'value' | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair;
9
+ export type visitor = visitorFn<unknown> | {
10
10
  Alias?: visitorFn<Alias>;
11
11
  Collection?: visitorFn<YAMLMap | YAMLSeq>;
12
12
  Map?: visitorFn<YAMLMap>;
@@ -16,6 +16,17 @@ export declare type visitor = visitorFn<unknown> | {
16
16
  Seq?: visitorFn<YAMLSeq>;
17
17
  Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
18
18
  };
19
+ export type asyncVisitorFn<T> = (key: number | 'key' | 'value' | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair | Promise<void | symbol | number | Node | Pair>;
20
+ export type asyncVisitor = asyncVisitorFn<unknown> | {
21
+ Alias?: asyncVisitorFn<Alias>;
22
+ Collection?: asyncVisitorFn<YAMLMap | YAMLSeq>;
23
+ Map?: asyncVisitorFn<YAMLMap>;
24
+ Node?: asyncVisitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
25
+ Pair?: asyncVisitorFn<Pair>;
26
+ Scalar?: asyncVisitorFn<Scalar>;
27
+ Seq?: asyncVisitorFn<YAMLSeq>;
28
+ Value?: asyncVisitorFn<Scalar | YAMLMap | YAMLSeq>;
29
+ };
19
30
  /**
20
31
  * Apply a visitor to an AST node or document.
21
32
  *
@@ -46,18 +57,46 @@ export declare type visitor = visitorFn<unknown> | {
46
57
  * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
47
58
  * specific defined one will be used for each node.
48
59
  */
49
- export declare function visit(node: Node | Document | null, visitor: visitorFn<unknown> | {
50
- Alias?: visitorFn<Alias>;
51
- Collection?: visitorFn<YAMLMap | YAMLSeq>;
52
- Map?: visitorFn<YAMLMap>;
53
- Node?: visitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
54
- Pair?: visitorFn<Pair>;
55
- Scalar?: visitorFn<Scalar>;
56
- Seq?: visitorFn<YAMLSeq>;
57
- Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
58
- }): void;
60
+ export declare function visit(node: Node | Document | null, visitor: visitor): void;
59
61
  export declare namespace visit {
60
62
  var BREAK: symbol;
61
63
  var SKIP: symbol;
62
64
  var REMOVE: symbol;
63
65
  }
66
+ /**
67
+ * Apply an async visitor to an AST node or document.
68
+ *
69
+ * Walks through the tree (depth-first) starting from `node`, calling a
70
+ * `visitor` function with three arguments:
71
+ * - `key`: For sequence values and map `Pair`, the node's index in the
72
+ * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
73
+ * `null` for the root node.
74
+ * - `node`: The current node.
75
+ * - `path`: The ancestry of the current node.
76
+ *
77
+ * The return value of the visitor may be used to control the traversal:
78
+ * - `Promise`: Must resolve to one of the following values
79
+ * - `undefined` (default): Do nothing and continue
80
+ * - `visit.SKIP`: Do not visit the children of this node, continue with next
81
+ * sibling
82
+ * - `visit.BREAK`: Terminate traversal completely
83
+ * - `visit.REMOVE`: Remove the current node, then continue with the next one
84
+ * - `Node`: Replace the current node, then continue by visiting it
85
+ * - `number`: While iterating the items of a sequence or map, set the index
86
+ * of the next step. This is useful especially if the index of the current
87
+ * node has changed.
88
+ *
89
+ * If `visitor` is a single function, it will be called with all values
90
+ * encountered in the tree, including e.g. `null` values. Alternatively,
91
+ * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
92
+ * `Alias` and `Scalar` node. To define the same visitor function for more than
93
+ * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
94
+ * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
95
+ * specific defined one will be used for each node.
96
+ */
97
+ export declare function visitAsync(node: Node | Document | null, visitor: asyncVisitor): Promise<void>;
98
+ export declare namespace visitAsync {
99
+ var BREAK: symbol;
100
+ var SKIP: symbol;
101
+ var REMOVE: symbol;
102
+ }
@@ -36,29 +36,14 @@ const REMOVE = Symbol('remove node');
36
36
  * specific defined one will be used for each node.
37
37
  */
38
38
  function visit(node, visitor) {
39
- if (typeof visitor === 'object' &&
40
- (visitor.Collection || visitor.Node || visitor.Value)) {
41
- visitor = Object.assign({
42
- Alias: visitor.Node,
43
- Map: visitor.Node,
44
- Scalar: visitor.Node,
45
- Seq: visitor.Node
46
- }, visitor.Value && {
47
- Map: visitor.Value,
48
- Scalar: visitor.Value,
49
- Seq: visitor.Value
50
- }, visitor.Collection && {
51
- Map: visitor.Collection,
52
- Seq: visitor.Collection
53
- }, visitor);
54
- }
39
+ const visitor_ = initVisitor(visitor);
55
40
  if (Node.isDocument(node)) {
56
- const cd = _visit(null, node.contents, visitor, Object.freeze([node]));
41
+ const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
57
42
  if (cd === REMOVE)
58
43
  node.contents = null;
59
44
  }
60
45
  else
61
- _visit(null, node, visitor, Object.freeze([]));
46
+ visit_(null, node, visitor_, Object.freeze([]));
62
47
  }
63
48
  // Without the `as symbol` casts, TS declares these in the `visit`
64
49
  // namespace using `var`, but then complains about that because
@@ -69,55 +54,104 @@ visit.BREAK = BREAK;
69
54
  visit.SKIP = SKIP;
70
55
  /** Remove the current node */
71
56
  visit.REMOVE = REMOVE;
72
- function _visit(key, node, visitor, path) {
73
- let ctrl = undefined;
74
- if (typeof visitor === 'function')
75
- ctrl = visitor(key, node, path);
76
- else if (Node.isMap(node)) {
77
- if (visitor.Map)
78
- ctrl = visitor.Map(key, node, path);
79
- }
80
- else if (Node.isSeq(node)) {
81
- if (visitor.Seq)
82
- ctrl = visitor.Seq(key, node, path);
83
- }
84
- else if (Node.isPair(node)) {
85
- if (visitor.Pair)
86
- ctrl = visitor.Pair(key, node, path);
57
+ function visit_(key, node, visitor, path) {
58
+ const ctrl = callVisitor(key, node, visitor, path);
59
+ if (Node.isNode(ctrl) || Node.isPair(ctrl)) {
60
+ replaceNode(key, path, ctrl);
61
+ return visit_(key, ctrl, visitor, path);
87
62
  }
88
- else if (Node.isScalar(node)) {
89
- if (visitor.Scalar)
90
- ctrl = visitor.Scalar(key, node, path);
63
+ if (typeof ctrl !== 'symbol') {
64
+ if (Node.isCollection(node)) {
65
+ path = Object.freeze(path.concat(node));
66
+ for (let i = 0; i < node.items.length; ++i) {
67
+ const ci = visit_(i, node.items[i], visitor, path);
68
+ if (typeof ci === 'number')
69
+ i = ci - 1;
70
+ else if (ci === BREAK)
71
+ return BREAK;
72
+ else if (ci === REMOVE) {
73
+ node.items.splice(i, 1);
74
+ i -= 1;
75
+ }
76
+ }
77
+ }
78
+ else if (Node.isPair(node)) {
79
+ path = Object.freeze(path.concat(node));
80
+ const ck = visit_('key', node.key, visitor, path);
81
+ if (ck === BREAK)
82
+ return BREAK;
83
+ else if (ck === REMOVE)
84
+ node.key = null;
85
+ const cv = visit_('value', node.value, visitor, path);
86
+ if (cv === BREAK)
87
+ return BREAK;
88
+ else if (cv === REMOVE)
89
+ node.value = null;
90
+ }
91
91
  }
92
- else if (Node.isAlias(node)) {
93
- if (visitor.Alias)
94
- ctrl = visitor.Alias(key, node, path);
92
+ return ctrl;
93
+ }
94
+ /**
95
+ * Apply an async visitor to an AST node or document.
96
+ *
97
+ * Walks through the tree (depth-first) starting from `node`, calling a
98
+ * `visitor` function with three arguments:
99
+ * - `key`: For sequence values and map `Pair`, the node's index in the
100
+ * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
101
+ * `null` for the root node.
102
+ * - `node`: The current node.
103
+ * - `path`: The ancestry of the current node.
104
+ *
105
+ * The return value of the visitor may be used to control the traversal:
106
+ * - `Promise`: Must resolve to one of the following values
107
+ * - `undefined` (default): Do nothing and continue
108
+ * - `visit.SKIP`: Do not visit the children of this node, continue with next
109
+ * sibling
110
+ * - `visit.BREAK`: Terminate traversal completely
111
+ * - `visit.REMOVE`: Remove the current node, then continue with the next one
112
+ * - `Node`: Replace the current node, then continue by visiting it
113
+ * - `number`: While iterating the items of a sequence or map, set the index
114
+ * of the next step. This is useful especially if the index of the current
115
+ * node has changed.
116
+ *
117
+ * If `visitor` is a single function, it will be called with all values
118
+ * encountered in the tree, including e.g. `null` values. Alternatively,
119
+ * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
120
+ * `Alias` and `Scalar` node. To define the same visitor function for more than
121
+ * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
122
+ * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
123
+ * specific defined one will be used for each node.
124
+ */
125
+ async function visitAsync(node, visitor) {
126
+ const visitor_ = initVisitor(visitor);
127
+ if (Node.isDocument(node)) {
128
+ const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
129
+ if (cd === REMOVE)
130
+ node.contents = null;
95
131
  }
132
+ else
133
+ await visitAsync_(null, node, visitor_, Object.freeze([]));
134
+ }
135
+ // Without the `as symbol` casts, TS declares these in the `visit`
136
+ // namespace using `var`, but then complains about that because
137
+ // `unique symbol` must be `const`.
138
+ /** Terminate visit traversal completely */
139
+ visitAsync.BREAK = BREAK;
140
+ /** Do not visit the children of the current node */
141
+ visitAsync.SKIP = SKIP;
142
+ /** Remove the current node */
143
+ visitAsync.REMOVE = REMOVE;
144
+ async function visitAsync_(key, node, visitor, path) {
145
+ const ctrl = await callVisitor(key, node, visitor, path);
96
146
  if (Node.isNode(ctrl) || Node.isPair(ctrl)) {
97
- const parent = path[path.length - 1];
98
- if (Node.isCollection(parent)) {
99
- parent.items[key] = ctrl;
100
- }
101
- else if (Node.isPair(parent)) {
102
- if (key === 'key')
103
- parent.key = ctrl;
104
- else
105
- parent.value = ctrl;
106
- }
107
- else if (Node.isDocument(parent)) {
108
- parent.contents = ctrl;
109
- }
110
- else {
111
- const pt = Node.isAlias(parent) ? 'alias' : 'scalar';
112
- throw new Error(`Cannot replace node with ${pt} parent`);
113
- }
114
- return _visit(key, ctrl, visitor, path);
147
+ replaceNode(key, path, ctrl);
148
+ return visitAsync_(key, ctrl, visitor, path);
115
149
  }
116
150
  if (typeof ctrl !== 'symbol') {
117
151
  if (Node.isCollection(node)) {
118
152
  path = Object.freeze(path.concat(node));
119
153
  for (let i = 0; i < node.items.length; ++i) {
120
- const ci = _visit(i, node.items[i], visitor, path);
154
+ const ci = await visitAsync_(i, node.items[i], visitor, path);
121
155
  if (typeof ci === 'number')
122
156
  i = ci - 1;
123
157
  else if (ci === BREAK)
@@ -130,12 +164,12 @@ function _visit(key, node, visitor, path) {
130
164
  }
131
165
  else if (Node.isPair(node)) {
132
166
  path = Object.freeze(path.concat(node));
133
- const ck = _visit('key', node.key, visitor, path);
167
+ const ck = await visitAsync_('key', node.key, visitor, path);
134
168
  if (ck === BREAK)
135
169
  return BREAK;
136
170
  else if (ck === REMOVE)
137
171
  node.key = null;
138
- const cv = _visit('value', node.value, visitor, path);
172
+ const cv = await visitAsync_('value', node.value, visitor, path);
139
173
  if (cv === BREAK)
140
174
  return BREAK;
141
175
  else if (cv === REMOVE)
@@ -144,5 +178,59 @@ function _visit(key, node, visitor, path) {
144
178
  }
145
179
  return ctrl;
146
180
  }
181
+ function initVisitor(visitor) {
182
+ if (typeof visitor === 'object' &&
183
+ (visitor.Collection || visitor.Node || visitor.Value)) {
184
+ return Object.assign({
185
+ Alias: visitor.Node,
186
+ Map: visitor.Node,
187
+ Scalar: visitor.Node,
188
+ Seq: visitor.Node
189
+ }, visitor.Value && {
190
+ Map: visitor.Value,
191
+ Scalar: visitor.Value,
192
+ Seq: visitor.Value
193
+ }, visitor.Collection && {
194
+ Map: visitor.Collection,
195
+ Seq: visitor.Collection
196
+ }, visitor);
197
+ }
198
+ return visitor;
199
+ }
200
+ function callVisitor(key, node, visitor, path) {
201
+ if (typeof visitor === 'function')
202
+ return visitor(key, node, path);
203
+ if (Node.isMap(node))
204
+ return visitor.Map?.(key, node, path);
205
+ if (Node.isSeq(node))
206
+ return visitor.Seq?.(key, node, path);
207
+ if (Node.isPair(node))
208
+ return visitor.Pair?.(key, node, path);
209
+ if (Node.isScalar(node))
210
+ return visitor.Scalar?.(key, node, path);
211
+ if (Node.isAlias(node))
212
+ return visitor.Alias?.(key, node, path);
213
+ return undefined;
214
+ }
215
+ function replaceNode(key, path, node) {
216
+ const parent = path[path.length - 1];
217
+ if (Node.isCollection(parent)) {
218
+ parent.items[key] = node;
219
+ }
220
+ else if (Node.isPair(parent)) {
221
+ if (key === 'key')
222
+ parent.key = node;
223
+ else
224
+ parent.value = node;
225
+ }
226
+ else if (Node.isDocument(parent)) {
227
+ parent.contents = node;
228
+ }
229
+ else {
230
+ const pt = Node.isAlias(parent) ? 'alias' : 'scalar';
231
+ throw new Error(`Cannot replace node with ${pt} parent`);
232
+ }
233
+ }
147
234
 
148
235
  exports.visit = visit;
236
+ exports.visitAsync = visitAsync;