cdk8s 2.7.103 → 2.7.105

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 (133) hide show
  1. package/.jsii +41 -41
  2. package/lib/_child_process.d.ts +0 -1
  3. package/lib/api-object.d.ts +2 -0
  4. package/lib/api-object.js +31 -31
  5. package/lib/app.js +14 -14
  6. package/lib/chart.js +9 -9
  7. package/lib/cron.js +10 -10
  8. package/lib/dependency.js +2 -2
  9. package/lib/duration.js +9 -9
  10. package/lib/helm.js +1 -1
  11. package/lib/include.js +1 -1
  12. package/lib/index.js +7 -3
  13. package/lib/json-patch.js +6 -6
  14. package/lib/lazy.js +5 -5
  15. package/lib/metadata.d.ts +2 -0
  16. package/lib/metadata.js +4 -4
  17. package/lib/names.js +6 -6
  18. package/lib/size.js +10 -10
  19. package/lib/testing.js +6 -6
  20. package/lib/yaml.js +9 -9
  21. package/node_modules/yaml/README.md +4 -0
  22. package/node_modules/yaml/browser/dist/compose/compose-collection.js +46 -29
  23. package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -0
  24. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +1 -1
  25. package/node_modules/yaml/browser/dist/compose/composer.js +1 -1
  26. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +3 -2
  27. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +3 -2
  28. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +4 -5
  29. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +1 -1
  30. package/node_modules/yaml/browser/dist/doc/Document.js +12 -10
  31. package/node_modules/yaml/browser/dist/doc/anchors.js +1 -1
  32. package/node_modules/yaml/browser/dist/doc/createNode.js +6 -2
  33. package/node_modules/yaml/browser/dist/doc/directives.js +1 -1
  34. package/node_modules/yaml/browser/dist/index.js +1 -1
  35. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +6 -149
  36. package/node_modules/yaml/browser/dist/nodes/Alias.js +9 -2
  37. package/node_modules/yaml/browser/dist/nodes/Collection.js +2 -1
  38. package/node_modules/yaml/browser/dist/nodes/Node.js +25 -35
  39. package/node_modules/yaml/browser/dist/nodes/Pair.js +1 -1
  40. package/node_modules/yaml/browser/dist/nodes/Scalar.js +2 -1
  41. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +30 -2
  42. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +17 -1
  43. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +1 -1
  44. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  45. package/node_modules/yaml/browser/dist/nodes/toJS.js +1 -1
  46. package/node_modules/yaml/browser/dist/schema/Schema.js +1 -1
  47. package/node_modules/yaml/browser/dist/schema/common/map.js +3 -28
  48. package/node_modules/yaml/browser/dist/schema/common/seq.js +3 -19
  49. package/node_modules/yaml/browser/dist/schema/tags.js +1 -1
  50. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +9 -8
  51. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  52. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +14 -13
  53. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +1 -1
  54. package/node_modules/yaml/browser/dist/stringify/stringify.js +1 -1
  55. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +1 -1
  56. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +1 -1
  57. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
  58. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +10 -1
  59. package/node_modules/yaml/browser/dist/util.js +2 -0
  60. package/node_modules/yaml/browser/dist/visit.js +1 -1
  61. package/node_modules/yaml/dist/compose/compose-collection.d.ts +1 -1
  62. package/node_modules/yaml/dist/compose/compose-collection.js +47 -30
  63. package/node_modules/yaml/dist/compose/compose-doc.d.ts +2 -1
  64. package/node_modules/yaml/dist/compose/compose-doc.js +1 -0
  65. package/node_modules/yaml/dist/compose/compose-scalar.js +7 -7
  66. package/node_modules/yaml/dist/compose/composer.d.ts +5 -5
  67. package/node_modules/yaml/dist/compose/composer.js +3 -3
  68. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +2 -1
  69. package/node_modules/yaml/dist/compose/resolve-block-map.js +3 -2
  70. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +2 -1
  71. package/node_modules/yaml/dist/compose/resolve-block-seq.js +3 -2
  72. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +2 -1
  73. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +5 -6
  74. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +3 -3
  75. package/node_modules/yaml/dist/compose/util-map-includes.js +3 -3
  76. package/node_modules/yaml/dist/doc/Document.d.ts +11 -9
  77. package/node_modules/yaml/dist/doc/Document.js +22 -20
  78. package/node_modules/yaml/dist/doc/anchors.d.ts +4 -4
  79. package/node_modules/yaml/dist/doc/anchors.js +2 -2
  80. package/node_modules/yaml/dist/doc/createNode.d.ts +1 -1
  81. package/node_modules/yaml/dist/doc/createNode.js +13 -9
  82. package/node_modules/yaml/dist/doc/directives.js +3 -3
  83. package/node_modules/yaml/dist/errors.d.ts +1 -1
  84. package/node_modules/yaml/dist/index.d.ts +2 -1
  85. package/node_modules/yaml/dist/index.js +9 -9
  86. package/node_modules/yaml/dist/nodes/Alias.d.ts +1 -1
  87. package/node_modules/yaml/dist/nodes/Alias.js +12 -5
  88. package/node_modules/yaml/dist/nodes/Collection.d.ts +3 -2
  89. package/node_modules/yaml/dist/nodes/Collection.js +10 -9
  90. package/node_modules/yaml/dist/nodes/Node.d.ts +5 -18
  91. package/node_modules/yaml/dist/nodes/Node.js +25 -51
  92. package/node_modules/yaml/dist/nodes/Pair.d.ts +2 -2
  93. package/node_modules/yaml/dist/nodes/Pair.js +4 -4
  94. package/node_modules/yaml/dist/nodes/Scalar.js +2 -1
  95. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +7 -1
  96. package/node_modules/yaml/dist/nodes/YAMLMap.js +37 -9
  97. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +3 -1
  98. package/node_modules/yaml/dist/nodes/YAMLSeq.js +21 -5
  99. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +7 -7
  100. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  101. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  102. package/node_modules/yaml/dist/nodes/toJS.d.ts +2 -5
  103. package/node_modules/yaml/dist/nodes/toJS.js +2 -2
  104. package/node_modules/yaml/dist/public-api.d.ts +3 -3
  105. package/node_modules/yaml/dist/schema/Schema.d.ts +1 -1
  106. package/node_modules/yaml/dist/schema/Schema.js +4 -4
  107. package/node_modules/yaml/dist/schema/common/map.js +4 -29
  108. package/node_modules/yaml/dist/schema/common/seq.js +4 -20
  109. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -1
  110. package/node_modules/yaml/dist/schema/json/schema.d.ts +1 -1
  111. package/node_modules/yaml/dist/schema/tags.d.ts +1 -1
  112. package/node_modules/yaml/dist/schema/types.d.ts +11 -3
  113. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +4 -1
  114. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +11 -10
  115. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +1 -1
  116. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +5 -5
  117. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -1
  118. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +3 -1
  119. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +17 -16
  120. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +1 -1
  121. package/node_modules/yaml/dist/stringify/stringify.js +8 -8
  122. package/node_modules/yaml/dist/stringify/stringifyCollection.js +8 -8
  123. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -3
  124. package/node_modules/yaml/dist/stringify/stringifyDocument.js +2 -2
  125. package/node_modules/yaml/dist/stringify/stringifyPair.js +9 -9
  126. package/node_modules/yaml/dist/stringify/stringifyString.js +10 -1
  127. package/node_modules/yaml/dist/test-events.js +8 -8
  128. package/node_modules/yaml/dist/util.d.ts +4 -1
  129. package/node_modules/yaml/dist/util.js +4 -0
  130. package/node_modules/yaml/dist/visit.js +18 -18
  131. package/node_modules/yaml/package.json +6 -5
  132. package/package.json +10 -12
  133. package/node_modules/yaml/util.d.ts +0 -3
@@ -1,7 +1,7 @@
1
- import { YAMLSeq } from '../../nodes/YAMLSeq.js';
1
+ import { isScalar, isPair } from '../../nodes/identity.js';
2
2
  import { toJS } from '../../nodes/toJS.js';
3
- import { isScalar, isPair } from '../../nodes/Node.js';
4
3
  import { YAMLMap } from '../../nodes/YAMLMap.js';
4
+ import { YAMLSeq } from '../../nodes/YAMLSeq.js';
5
5
  import { resolvePairs, createPairs } from './pairs.js';
6
6
 
7
7
  class YAMLOMap extends YAMLSeq {
@@ -39,6 +39,12 @@ class YAMLOMap extends YAMLSeq {
39
39
  }
40
40
  return map;
41
41
  }
42
+ static from(schema, iterable, ctx) {
43
+ const pairs = createPairs(schema, iterable, ctx);
44
+ const omap = new this();
45
+ omap.items = pairs.items;
46
+ return omap;
47
+ }
42
48
  }
43
49
  YAMLOMap.tag = 'tag:yaml.org,2002:omap';
44
50
  const omap = {
@@ -62,12 +68,7 @@ const omap = {
62
68
  }
63
69
  return Object.assign(new YAMLOMap(), pairs);
64
70
  },
65
- createNode(schema, iterable, ctx) {
66
- const pairs = createPairs(schema, iterable, ctx);
67
- const omap = new YAMLOMap();
68
- omap.items = pairs.items;
69
- return omap;
70
- }
71
+ createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
71
72
  };
72
73
 
73
74
  export { YAMLOMap, omap };
@@ -1,4 +1,4 @@
1
- import { isSeq, isPair, isMap } from '../../nodes/Node.js';
1
+ import { isSeq, isPair, isMap } from '../../nodes/identity.js';
2
2
  import { Pair, createPair } from '../../nodes/Pair.js';
3
3
  import { Scalar } from '../../nodes/Scalar.js';
4
4
  import { YAMLSeq } from '../../nodes/YAMLSeq.js';
@@ -1,5 +1,5 @@
1
- import { isMap, isPair, isScalar } from '../../nodes/Node.js';
2
- import { createPair, Pair } from '../../nodes/Pair.js';
1
+ import { isMap, isPair, isScalar } from '../../nodes/identity.js';
2
+ import { Pair, createPair } from '../../nodes/Pair.js';
3
3
  import { YAMLMap, findPair } from '../../nodes/YAMLMap.js';
4
4
 
5
5
  class YAMLSet extends YAMLMap {
@@ -57,6 +57,17 @@ class YAMLSet extends YAMLMap {
57
57
  else
58
58
  throw new Error('Set items must all have null values');
59
59
  }
60
+ static from(schema, iterable, ctx) {
61
+ const { replacer } = ctx;
62
+ const set = new this(schema);
63
+ if (iterable && Symbol.iterator in Object(iterable))
64
+ for (let value of iterable) {
65
+ if (typeof replacer === 'function')
66
+ value = replacer.call(iterable, value, value);
67
+ set.items.push(createPair(value, null, ctx));
68
+ }
69
+ return set;
70
+ }
60
71
  }
61
72
  YAMLSet.tag = 'tag:yaml.org,2002:set';
62
73
  const set = {
@@ -65,6 +76,7 @@ const set = {
65
76
  nodeClass: YAMLSet,
66
77
  default: false,
67
78
  tag: 'tag:yaml.org,2002:set',
79
+ createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
68
80
  resolve(map, onError) {
69
81
  if (isMap(map)) {
70
82
  if (map.hasAllNullValues(true))
@@ -75,17 +87,6 @@ const set = {
75
87
  else
76
88
  onError('Expected a mapping for this tag');
77
89
  return map;
78
- },
79
- createNode(schema, iterable, ctx) {
80
- const { replacer } = ctx;
81
- const set = new YAMLSet(schema);
82
- if (iterable && Symbol.iterator in Object(iterable))
83
- for (let value of iterable) {
84
- if (typeof replacer === 'function')
85
- value = replacer.call(iterable, value, value);
86
- set.items.push(createPair(value, null, ctx));
87
- }
88
- return set;
89
90
  }
90
91
  };
91
92
 
@@ -43,7 +43,7 @@ function stringifySexagesimal(node) {
43
43
  }
44
44
  return (sign +
45
45
  parts
46
- .map(n => (n < 10 ? '0' + String(n) : String(n)))
46
+ .map(n => String(n).padStart(2, '0'))
47
47
  .join(':')
48
48
  .replace(/000000\d*$/, '') // % 60 may introduce error
49
49
  );
@@ -1,5 +1,5 @@
1
1
  import { anchorIsValid } from '../doc/anchors.js';
2
- import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/Node.js';
2
+ import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';
3
3
  import { stringifyComment } from './stringifyComment.js';
4
4
  import { stringifyString } from './stringifyString.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { Collection } from '../nodes/Collection.js';
2
- import { isNode, isPair } from '../nodes/Node.js';
2
+ import { isNode, isPair } from '../nodes/identity.js';
3
3
  import { stringify } from './stringify.js';
4
4
  import { lineComment, indentComment } from './stringifyComment.js';
5
5
 
@@ -1,4 +1,4 @@
1
- import { isNode } from '../nodes/Node.js';
1
+ import { isNode } from '../nodes/identity.js';
2
2
  import { createStringifyContext, stringify } from './stringify.js';
3
3
  import { indentComment, lineComment } from './stringifyComment.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { isCollection, isNode, isScalar, isSeq } from '../nodes/Node.js';
1
+ import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';
2
2
  import { Scalar } from '../nodes/Scalar.js';
3
3
  import { stringify } from './stringify.js';
4
4
  import { lineComment, indentComment } from './stringifyComment.js';
@@ -146,6 +146,15 @@ function quotedString(value, ctx) {
146
146
  }
147
147
  return qs(value, ctx);
148
148
  }
149
+ // The negative lookbehind avoids a polynomial search,
150
+ // but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind
151
+ let blockEndNewlines;
152
+ try {
153
+ blockEndNewlines = new RegExp('(^|(?<!\n))\n+(?!\n|$)', 'g');
154
+ }
155
+ catch {
156
+ blockEndNewlines = /\n+(?!\n|$)/g;
157
+ }
149
158
  function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
150
159
  const { blockQuote, commentString, lineWidth } = ctx.options;
151
160
  // 1. Block can't end in whitespace unless the last line is non-empty.
@@ -189,7 +198,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
189
198
  value = value.slice(0, -end.length);
190
199
  if (end[end.length - 1] === '\n')
191
200
  end = end.slice(0, -1);
192
- end = end.replace(/\n+(?!\n|$)/g, `$&${indent}`);
201
+ end = end.replace(blockEndNewlines, `$&${indent}`);
193
202
  }
194
203
  // determine indent indicator from whitespace at value start
195
204
  let startWithSpace = false;
@@ -1,4 +1,6 @@
1
+ export { createNode } from './doc/createNode.js';
1
2
  export { debug, warn } from './log.js';
3
+ export { createPair } from './nodes/Pair.js';
2
4
  export { findPair } from './nodes/YAMLMap.js';
3
5
  export { toJS } from './nodes/toJS.js';
4
6
  export { map as mapTag } from './schema/common/map.js';
@@ -1,4 +1,4 @@
1
- import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js';
1
+ import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';
2
2
 
3
3
  const BREAK = Symbol('break visit');
4
4
  const SKIP = Symbol('skip children');
@@ -1,4 +1,4 @@
1
- import { ParsedNode } from '../nodes/Node.js';
1
+ import type { ParsedNode } from '../nodes/Node.js';
2
2
  import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js';
3
3
  import type { ComposeContext, ComposeNode } from './compose-node.js';
4
4
  import type { ComposeErrorHandler } from './composer.js';
@@ -1,40 +1,52 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Scalar = require('../nodes/Scalar.js');
5
+ var YAMLMap = require('../nodes/YAMLMap.js');
6
+ var YAMLSeq = require('../nodes/YAMLSeq.js');
5
7
  var resolveBlockMap = require('./resolve-block-map.js');
6
8
  var resolveBlockSeq = require('./resolve-block-seq.js');
7
9
  var resolveFlowCollection = require('./resolve-flow-collection.js');
8
10
 
9
- function composeCollection(CN, ctx, token, tagToken, onError) {
10
- let coll;
11
- switch (token.type) {
12
- case 'block-map': {
13
- coll = resolveBlockMap.resolveBlockMap(CN, ctx, token, onError);
14
- break;
15
- }
16
- case 'block-seq': {
17
- coll = resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError);
18
- break;
19
- }
20
- case 'flow-collection': {
21
- coll = resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError);
22
- break;
23
- }
24
- }
25
- if (!tagToken)
26
- return coll;
27
- const tagName = ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
28
- if (!tagName)
29
- return coll;
30
- // Cast needed due to: https://github.com/Microsoft/TypeScript/issues/3841
11
+ function resolveCollection(CN, ctx, token, onError, tagName, tag) {
12
+ const coll = token.type === 'block-map'
13
+ ? resolveBlockMap.resolveBlockMap(CN, ctx, token, onError, tag)
14
+ : token.type === 'block-seq'
15
+ ? resolveBlockSeq.resolveBlockSeq(CN, ctx, token, onError, tag)
16
+ : resolveFlowCollection.resolveFlowCollection(CN, ctx, token, onError, tag);
31
17
  const Coll = coll.constructor;
18
+ // If we got a tagName matching the class, or the tag name is '!',
19
+ // then use the tagName from the node class used to create it.
32
20
  if (tagName === '!' || tagName === Coll.tagName) {
33
21
  coll.tag = Coll.tagName;
34
22
  return coll;
35
23
  }
36
- const expType = Node.isMap(coll) ? 'map' : 'seq';
37
- let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName);
24
+ if (tagName)
25
+ coll.tag = tagName;
26
+ return coll;
27
+ }
28
+ function composeCollection(CN, ctx, token, tagToken, onError) {
29
+ const tagName = !tagToken
30
+ ? null
31
+ : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
32
+ const expType = token.type === 'block-map'
33
+ ? 'map'
34
+ : token.type === 'block-seq'
35
+ ? 'seq'
36
+ : token.start.source === '{'
37
+ ? 'map'
38
+ : 'seq';
39
+ // shortcut: check if it's a generic YAMLMap or YAMLSeq
40
+ // before jumping into the custom tag logic.
41
+ if (!tagToken ||
42
+ !tagName ||
43
+ tagName === '!' ||
44
+ (tagName === YAMLMap.YAMLMap.tagName && expType === 'map') ||
45
+ (tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq') ||
46
+ !expType) {
47
+ return resolveCollection(CN, ctx, token, onError, tagName);
48
+ }
49
+ let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
38
50
  if (!tag) {
39
51
  const kt = ctx.schema.knownTags[tagName];
40
52
  if (kt && kt.collection === expType) {
@@ -42,13 +54,18 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
42
54
  tag = kt;
43
55
  }
44
56
  else {
45
- onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
46
- coll.tag = tagName;
47
- return coll;
57
+ if (kt?.collection) {
58
+ onError(tagToken, 'BAD_COLLECTION_TYPE', `${kt.tag} used for ${expType} collection, but expects ${kt.collection}`, true);
59
+ }
60
+ else {
61
+ onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, true);
62
+ }
63
+ return resolveCollection(CN, ctx, token, onError, tagName);
48
64
  }
49
65
  }
50
- const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options);
51
- const node = Node.isNode(res)
66
+ const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
67
+ const res = tag.resolve?.(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options) ?? coll;
68
+ const node = identity.isNode(res)
52
69
  ? res
53
70
  : new Scalar.Scalar(res);
54
71
  node.range = coll.range;
@@ -1,6 +1,7 @@
1
1
  import type { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
+ import type { ParsedNode } from '../nodes/Node.js';
3
4
  import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
4
5
  import type * as CST from '../parse/cst.js';
5
6
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function composeDoc(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<import("../index.js").ParsedNode>;
7
+ export declare function composeDoc<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true>(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<Contents, Strict>;
@@ -28,6 +28,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
28
28
  !props.hasNewline)
29
29
  onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
30
30
  }
31
+ // @ts-expect-error If Contents is set, let's trust the user
31
32
  doc.contents = value
32
33
  ? composeNode.composeNode(ctx, value, props, onError)
33
34
  : composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Scalar = require('../nodes/Scalar.js');
5
5
  var resolveBlockScalar = require('./resolve-block-scalar.js');
6
6
  var resolveFlowScalar = require('./resolve-flow-scalar.js');
@@ -16,11 +16,11 @@ function composeScalar(ctx, token, tagToken, onError) {
16
16
  ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
17
17
  : token.type === 'scalar'
18
18
  ? findScalarTagByTest(ctx, value, token, onError)
19
- : ctx.schema[Node.SCALAR];
19
+ : ctx.schema[identity.SCALAR];
20
20
  let scalar;
21
21
  try {
22
22
  const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
23
- scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
23
+ scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
24
24
  }
25
25
  catch (error) {
26
26
  const msg = error instanceof Error ? error.message : String(error);
@@ -41,7 +41,7 @@ function composeScalar(ctx, token, tagToken, onError) {
41
41
  }
42
42
  function findScalarTagByName(schema, value, tagName, tagToken, onError) {
43
43
  if (tagName === '!')
44
- return schema[Node.SCALAR]; // non-specific tag
44
+ return schema[identity.SCALAR]; // non-specific tag
45
45
  const matchWithTest = [];
46
46
  for (const tag of schema.tags) {
47
47
  if (!tag.collection && tag.tag === tagName) {
@@ -62,13 +62,13 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
62
62
  return kt;
63
63
  }
64
64
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
65
- return schema[Node.SCALAR];
65
+ return schema[identity.SCALAR];
66
66
  }
67
67
  function findScalarTagByTest({ directives, schema }, value, token, onError) {
68
- const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
68
+ const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR];
69
69
  if (schema.compat) {
70
70
  const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
71
- schema[Node.SCALAR];
71
+ schema[identity.SCALAR];
72
72
  if (tag.tag !== compat.tag) {
73
73
  const ts = directives.tagString(tag.tag);
74
74
  const cs = directives.tagString(compat.tag);
@@ -1,7 +1,7 @@
1
1
  import { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
3
  import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
4
- import { Range } from '../nodes/Node.js';
4
+ import type { ParsedNode, Range } from '../nodes/Node.js';
5
5
  import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
6
6
  import type { Token } from '../parse/cst.js';
7
7
  type ErrorSource = number | [number, number] | Range | {
@@ -20,7 +20,7 @@ export type ComposeErrorHandler = (source: ErrorSource, code: ErrorCode, message
20
20
  * const docs = new Composer().compose(tokens)
21
21
  * ```
22
22
  */
23
- export declare class Composer {
23
+ export declare class Composer<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> {
24
24
  private directives;
25
25
  private doc;
26
26
  private options;
@@ -48,15 +48,15 @@ export declare class Composer {
48
48
  * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
49
49
  * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
50
50
  */
51
- compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
51
+ compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
52
52
  /** Advance the composer by one CST token. */
53
- next(token: Token): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
53
+ next(token: Token): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
54
54
  /**
55
55
  * Call at end of input to yield any remaining document.
56
56
  *
57
57
  * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
58
58
  * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
59
59
  */
60
- end(forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
60
+ end(forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
61
61
  }
62
62
  export {};
@@ -3,7 +3,7 @@
3
3
  var directives = require('../doc/directives.js');
4
4
  var Document = require('../doc/Document.js');
5
5
  var errors = require('../errors.js');
6
- var Node = require('../nodes/Node.js');
6
+ var identity = require('../nodes/identity.js');
7
7
  var composeDoc = require('./compose-doc.js');
8
8
  var resolveEnd = require('./resolve-end.js');
9
9
 
@@ -83,9 +83,9 @@ class Composer {
83
83
  else if (afterEmptyLine || doc.directives.docStart || !dc) {
84
84
  doc.commentBefore = comment;
85
85
  }
86
- else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
86
+ else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
87
87
  let it = dc.items[0];
88
- if (Node.isPair(it))
88
+ if (identity.isPair(it))
89
89
  it = it.key;
90
90
  const cb = it.commentBefore;
91
91
  it.commentBefore = cb ? `${comment}\n${cb}` : comment;
@@ -1,6 +1,7 @@
1
1
  import type { ParsedNode } from '../nodes/Node.js';
2
2
  import { YAMLMap } from '../nodes/YAMLMap.js';
3
3
  import type { BlockMap } from '../parse/cst.js';
4
+ import { CollectionTag } from '../schema/types.js';
4
5
  import type { ComposeContext, ComposeNode } from './compose-node.js';
5
6
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
7
+ export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
@@ -8,8 +8,9 @@ var utilFlowIndentCheck = require('./util-flow-indent-check.js');
8
8
  var utilMapIncludes = require('./util-map-includes.js');
9
9
 
10
10
  const startColMsg = 'All mapping items must start at the same column';
11
- function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
12
- const map = new YAMLMap.YAMLMap(ctx.schema);
11
+ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, tag) {
12
+ const NodeClass = tag?.nodeClass ?? YAMLMap.YAMLMap;
13
+ const map = new NodeClass(ctx.schema);
13
14
  if (ctx.atRoot)
14
15
  ctx.atRoot = false;
15
16
  let offset = bm.offset;
@@ -1,5 +1,6 @@
1
1
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
2
2
  import type { BlockSequence } from '../parse/cst.js';
3
+ import { CollectionTag } from '../schema/types.js';
3
4
  import type { ComposeContext, ComposeNode } from './compose-node.js';
4
5
  import type { ComposeErrorHandler } from './composer.js';
5
- export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
6
+ export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
@@ -4,8 +4,9 @@ var YAMLSeq = require('../nodes/YAMLSeq.js');
4
4
  var resolveProps = require('./resolve-props.js');
5
5
  var utilFlowIndentCheck = require('./util-flow-indent-check.js');
6
6
 
7
- function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
8
- const seq = new YAMLSeq.YAMLSeq(ctx.schema);
7
+ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, tag) {
8
+ const NodeClass = tag?.nodeClass ?? YAMLSeq.YAMLSeq;
9
+ const seq = new NodeClass(ctx.schema);
9
10
  if (ctx.atRoot)
10
11
  ctx.atRoot = false;
11
12
  let offset = bs.offset;
@@ -1,6 +1,7 @@
1
1
  import { YAMLMap } from '../nodes/YAMLMap.js';
2
2
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
3
3
  import type { FlowCollection } from '../parse/cst.js';
4
+ import { CollectionTag } from '../schema/types.js';
4
5
  import type { ComposeContext, ComposeNode } from './compose-node.js';
5
6
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>;
7
+ export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null> | YAMLSeq.Parsed<import("../index.js").ParsedNode>;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Pair = require('../nodes/Pair.js');
5
5
  var YAMLMap = require('../nodes/YAMLMap.js');
6
6
  var YAMLSeq = require('../nodes/YAMLSeq.js');
@@ -11,12 +11,11 @@ var utilMapIncludes = require('./util-map-includes.js');
11
11
 
12
12
  const blockMsg = 'Block collections are not allowed within flow collections';
13
13
  const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
14
- function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
14
+ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError, tag) {
15
15
  const isMap = fc.start.source === '{';
16
16
  const fcName = isMap ? 'flow map' : 'flow sequence';
17
- const coll = isMap
18
- ? new YAMLMap.YAMLMap(ctx.schema)
19
- : new YAMLSeq.YAMLSeq(ctx.schema);
17
+ const NodeClass = (tag?.nodeClass ?? (isMap ? YAMLMap.YAMLMap : YAMLSeq.YAMLSeq));
18
+ const coll = new NodeClass(ctx.schema);
20
19
  coll.flow = true;
21
20
  const atRoot = ctx.atRoot;
22
21
  if (atRoot)
@@ -75,7 +74,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
75
74
  }
76
75
  if (prevItemComment) {
77
76
  let prev = coll.items[coll.items.length - 1];
78
- if (Node.isPair(prev))
77
+ if (identity.isPair(prev))
79
78
  prev = prev.value ?? prev.key;
80
79
  if (prev.comment)
81
80
  prev.comment += '\n' + prevItemComment;
@@ -1,4 +1,4 @@
1
- import { ParsedNode } from '../nodes/Node';
2
- import { Pair } from '../nodes/Pair';
3
- import { ComposeContext } from './compose-node';
1
+ import type { ParsedNode } from '../nodes/Node.js';
2
+ import type { Pair } from '../nodes/Pair.js';
3
+ import type { ComposeContext } from './compose-node.js';
4
4
  export declare function mapIncludes(ctx: ComposeContext, items: Pair<ParsedNode>[], search: ParsedNode): boolean;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
 
5
5
  function mapIncludes(ctx, items, search) {
6
6
  const { uniqueKeys } = ctx.options;
@@ -9,8 +9,8 @@ function mapIncludes(ctx, items, search) {
9
9
  const isEqual = typeof uniqueKeys === 'function'
10
10
  ? uniqueKeys
11
11
  : (a, b) => a === b ||
12
- (Node.isScalar(a) &&
13
- Node.isScalar(b) &&
12
+ (identity.isScalar(a) &&
13
+ identity.isScalar(b) &&
14
14
  a.value === b.value &&
15
15
  !(a.value === '<<' && ctx.schema.merge));
16
16
  return items.some(pair => isEqual(pair.key, search));
@@ -1,6 +1,7 @@
1
1
  import type { YAMLError, YAMLWarning } from '../errors.js';
2
2
  import { Alias } from '../nodes/Alias.js';
3
- import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
3
+ import { NODE_TYPE } from '../nodes/identity.js';
4
+ import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js';
4
5
  import { Pair } from '../nodes/Pair.js';
5
6
  import type { Scalar } from '../nodes/Scalar.js';
6
7
  import type { YAMLMap } from '../nodes/YAMLMap.js';
@@ -10,20 +11,21 @@ import { Schema } from '../schema/Schema.js';
10
11
  import { Directives } from './directives.js';
11
12
  export type Replacer = any[] | ((key: any, value: any) => unknown);
12
13
  export declare namespace Document {
13
- interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
14
+ /** @ts-ignore The typing of directives fails in TS <= 4.2 */
15
+ interface Parsed<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> extends Document<Contents, Strict> {
14
16
  directives: Directives;
15
17
  range: Range;
16
18
  }
17
19
  }
18
- export declare class Document<T extends Node = Node> {
20
+ export declare class Document<Contents extends Node = Node, Strict extends boolean = true> {
19
21
  readonly [NODE_TYPE]: symbol;
20
22
  /** A comment before this Document */
21
23
  commentBefore: string | null;
22
24
  /** A comment immediately after this Document */
23
25
  comment: string | null;
24
26
  /** The document contents. */
25
- contents: T | null;
26
- directives?: Directives;
27
+ contents: Strict extends true ? Contents | null : Contents;
28
+ directives: Strict extends true ? Directives | undefined : Directives;
27
29
  /** Errors encountered during parsing. */
28
30
  errors: YAMLError[];
29
31
  options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
@@ -49,7 +51,7 @@ export declare class Document<T extends Node = Node> {
49
51
  *
50
52
  * Custom Node values that inherit from `Object` still refer to their original instances.
51
53
  */
52
- clone(): Document<T>;
54
+ clone(): Document<Contents, Strict>;
53
55
  /** Adds a value to the document. */
54
56
  add(value: any): void;
55
57
  /** Adds a value to the document. */
@@ -63,7 +65,7 @@ export declare class Document<T extends Node = Node> {
63
65
  * `name` will be used as a prefix for a new unique anchor.
64
66
  * If `name` is undefined, the generated anchor will use 'a' as a prefix.
65
67
  */
66
- createAlias(node: Scalar | YAMLMap | YAMLSeq, name?: string): Alias;
68
+ createAlias(node: Strict extends true ? Scalar | YAMLMap | YAMLSeq : Node, name?: string): Alias;
67
69
  /**
68
70
  * Convert any value into a `Node` using the current schema, recursively
69
71
  * turning objects into collections.
@@ -90,13 +92,13 @@ export declare class Document<T extends Node = Node> {
90
92
  * scalar values from their surrounding node; to disable set `keepScalar` to
91
93
  * `true` (collections are always returned intact).
92
94
  */
93
- get(key: unknown, keepScalar?: boolean): unknown;
95
+ get(key: unknown, keepScalar?: boolean): Strict extends true ? unknown : any;
94
96
  /**
95
97
  * Returns item at `path`, or `undefined` if not found. By default unwraps
96
98
  * scalar values from their surrounding node; to disable set `keepScalar` to
97
99
  * `true` (collections are always returned intact).
98
100
  */
99
- getIn(path: Iterable<unknown> | null, keepScalar?: boolean): unknown;
101
+ getIn(path: Iterable<unknown> | null, keepScalar?: boolean): Strict extends true ? unknown : any;
100
102
  /**
101
103
  * Checks if the document includes a value with the key `key`.
102
104
  */