cdk8s 2.7.102 → 2.7.104

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
@@ -3,7 +3,7 @@
3
3
  var createNode = require('../doc/createNode.js');
4
4
  var stringifyPair = require('../stringify/stringifyPair.js');
5
5
  var addPairToJSMap = require('./addPairToJSMap.js');
6
- var Node = require('./Node.js');
6
+ var identity = require('./identity.js');
7
7
 
8
8
  function createPair(key, value, ctx) {
9
9
  const k = createNode.createNode(key, undefined, ctx);
@@ -12,15 +12,15 @@ function createPair(key, value, ctx) {
12
12
  }
13
13
  class Pair {
14
14
  constructor(key, value = null) {
15
- Object.defineProperty(this, Node.NODE_TYPE, { value: Node.PAIR });
15
+ Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR });
16
16
  this.key = key;
17
17
  this.value = value;
18
18
  }
19
19
  clone(schema) {
20
20
  let { key, value } = this;
21
- if (Node.isNode(key))
21
+ if (identity.isNode(key))
22
22
  key = key.clone(schema);
23
- if (Node.isNode(value))
23
+ if (identity.isNode(value))
24
24
  value = value.clone(schema);
25
25
  return new Pair(key, value);
26
26
  }
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ var identity = require('./identity.js');
3
4
  var Node = require('./Node.js');
4
5
  var toJS = require('./toJS.js');
5
6
 
6
7
  const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
7
8
  class Scalar extends Node.NodeBase {
8
9
  constructor(value) {
9
- super(Node.SCALAR);
10
+ super(identity.SCALAR);
10
11
  this.value = value;
11
12
  }
12
13
  toJSON(arg, ctx) {
@@ -1,8 +1,9 @@
1
1
  import type { BlockMap, FlowCollection } from '../parse/cst.js';
2
2
  import type { Schema } from '../schema/Schema.js';
3
3
  import type { StringifyContext } from '../stringify/stringify.js';
4
+ import { CreateNodeContext } from '../util.js';
4
5
  import { Collection } from './Collection.js';
5
- import { ParsedNode, Range } from './Node.js';
6
+ import type { ParsedNode, Range } from './Node.js';
6
7
  import { Pair } from './Pair.js';
7
8
  import { Scalar } from './Scalar.js';
8
9
  import type { ToJSContext } from './toJS.js';
@@ -19,6 +20,11 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
19
20
  static get tagName(): 'tag:yaml.org,2002:map';
20
21
  items: Pair<K, V>[];
21
22
  constructor(schema?: Schema);
23
+ /**
24
+ * A generic collection parsing method that can be extended
25
+ * to other node classes that inherit from YAMLMap
26
+ */
27
+ static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLMap<unknown, unknown>;
22
28
  /**
23
29
  * Adds a value to the collection.
24
30
  *
@@ -3,17 +3,17 @@
3
3
  var stringifyCollection = require('../stringify/stringifyCollection.js');
4
4
  var addPairToJSMap = require('./addPairToJSMap.js');
5
5
  var Collection = require('./Collection.js');
6
- var Node = require('./Node.js');
6
+ var identity = require('./identity.js');
7
7
  var Pair = require('./Pair.js');
8
8
  var Scalar = require('./Scalar.js');
9
9
 
10
10
  function findPair(items, key) {
11
- const k = Node.isScalar(key) ? key.value : key;
11
+ const k = identity.isScalar(key) ? key.value : key;
12
12
  for (const it of items) {
13
- if (Node.isPair(it)) {
13
+ if (identity.isPair(it)) {
14
14
  if (it.key === key || it.key === k)
15
15
  return it;
16
- if (Node.isScalar(it.key) && it.key.value === k)
16
+ if (identity.isScalar(it.key) && it.key.value === k)
17
17
  return it;
18
18
  }
19
19
  }
@@ -24,9 +24,37 @@ class YAMLMap extends Collection.Collection {
24
24
  return 'tag:yaml.org,2002:map';
25
25
  }
26
26
  constructor(schema) {
27
- super(Node.MAP, schema);
27
+ super(identity.MAP, schema);
28
28
  this.items = [];
29
29
  }
30
+ /**
31
+ * A generic collection parsing method that can be extended
32
+ * to other node classes that inherit from YAMLMap
33
+ */
34
+ static from(schema, obj, ctx) {
35
+ const { keepUndefined, replacer } = ctx;
36
+ const map = new this(schema);
37
+ const add = (key, value) => {
38
+ if (typeof replacer === 'function')
39
+ value = replacer.call(obj, key, value);
40
+ else if (Array.isArray(replacer) && !replacer.includes(key))
41
+ return;
42
+ if (value !== undefined || keepUndefined)
43
+ map.items.push(Pair.createPair(key, value, ctx));
44
+ };
45
+ if (obj instanceof Map) {
46
+ for (const [key, value] of obj)
47
+ add(key, value);
48
+ }
49
+ else if (obj && typeof obj === 'object') {
50
+ for (const key of Object.keys(obj))
51
+ add(key, obj[key]);
52
+ }
53
+ if (typeof schema.sortMapEntries === 'function') {
54
+ map.items.sort(schema.sortMapEntries);
55
+ }
56
+ return map;
57
+ }
30
58
  /**
31
59
  * Adds a value to the collection.
32
60
  *
@@ -35,7 +63,7 @@ class YAMLMap extends Collection.Collection {
35
63
  */
36
64
  add(pair, overwrite) {
37
65
  let _pair;
38
- if (Node.isPair(pair))
66
+ if (identity.isPair(pair))
39
67
  _pair = pair;
40
68
  else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
41
69
  // In TypeScript, this never happens.
@@ -49,7 +77,7 @@ class YAMLMap extends Collection.Collection {
49
77
  if (!overwrite)
50
78
  throw new Error(`Key ${_pair.key} already set`);
51
79
  // For scalars, keep the old node & its comments and anchors
52
- if (Node.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
80
+ if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
53
81
  prev.value.value = _pair.value;
54
82
  else
55
83
  prev.value = _pair.value;
@@ -75,7 +103,7 @@ class YAMLMap extends Collection.Collection {
75
103
  get(key, keepScalar) {
76
104
  const it = findPair(this.items, key);
77
105
  const node = it?.value;
78
- return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
106
+ return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? undefined;
79
107
  }
80
108
  has(key) {
81
109
  return !!findPair(this.items, key);
@@ -100,7 +128,7 @@ class YAMLMap extends Collection.Collection {
100
128
  if (!ctx)
101
129
  return JSON.stringify(this);
102
130
  for (const item of this.items) {
103
- if (!Node.isPair(item))
131
+ if (!identity.isPair(item))
104
132
  throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
105
133
  }
106
134
  if (!ctx.allNullValues && this.hasAllNullValues(false))
@@ -1,8 +1,9 @@
1
+ import { CreateNodeContext } from '../doc/createNode.js';
1
2
  import type { BlockSequence, FlowCollection } from '../parse/cst.js';
2
3
  import type { Schema } from '../schema/Schema.js';
3
4
  import type { StringifyContext } from '../stringify/stringify.js';
4
5
  import { Collection } from './Collection.js';
5
- import { ParsedNode, Range } from './Node.js';
6
+ import type { ParsedNode, Range } from './Node.js';
6
7
  import type { Pair } from './Pair.js';
7
8
  import { Scalar } from './Scalar.js';
8
9
  import { ToJSContext } from './toJS.js';
@@ -55,4 +56,5 @@ export declare class YAMLSeq<T = unknown> extends Collection {
55
56
  set(key: unknown, value: T): void;
56
57
  toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
57
58
  toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
59
+ static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLSeq<unknown>;
58
60
  }
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var createNode = require('../doc/createNode.js');
3
4
  var stringifyCollection = require('../stringify/stringifyCollection.js');
4
5
  var Collection = require('./Collection.js');
5
- var Node = require('./Node.js');
6
+ var identity = require('./identity.js');
6
7
  var Scalar = require('./Scalar.js');
7
8
  var toJS = require('./toJS.js');
8
9
 
@@ -11,7 +12,7 @@ class YAMLSeq extends Collection.Collection {
11
12
  return 'tag:yaml.org,2002:seq';
12
13
  }
13
14
  constructor(schema) {
14
- super(Node.SEQ, schema);
15
+ super(identity.SEQ, schema);
15
16
  this.items = [];
16
17
  }
17
18
  add(value) {
@@ -37,7 +38,7 @@ class YAMLSeq extends Collection.Collection {
37
38
  if (typeof idx !== 'number')
38
39
  return undefined;
39
40
  const it = this.items[idx];
40
- return !keepScalar && Node.isScalar(it) ? it.value : it;
41
+ return !keepScalar && identity.isScalar(it) ? it.value : it;
41
42
  }
42
43
  /**
43
44
  * Checks if the collection includes a value with the key `key`.
@@ -61,7 +62,7 @@ class YAMLSeq extends Collection.Collection {
61
62
  if (typeof idx !== 'number')
62
63
  throw new Error(`Expected a valid index, not ${key}.`);
63
64
  const prev = this.items[idx];
64
- if (Node.isScalar(prev) && Scalar.isScalarValue(value))
65
+ if (identity.isScalar(prev) && Scalar.isScalarValue(value))
65
66
  prev.value = value;
66
67
  else
67
68
  this.items[idx] = value;
@@ -86,9 +87,24 @@ class YAMLSeq extends Collection.Collection {
86
87
  onComment
87
88
  });
88
89
  }
90
+ static from(schema, obj, ctx) {
91
+ const { replacer } = ctx;
92
+ const seq = new this(schema);
93
+ if (obj && Symbol.iterator in Object(obj)) {
94
+ let i = 0;
95
+ for (let it of obj) {
96
+ if (typeof replacer === 'function') {
97
+ const key = obj instanceof Set ? it : String(i++);
98
+ it = replacer.call(obj, key, it);
99
+ }
100
+ seq.items.push(createNode.createNode(it, undefined, ctx));
101
+ }
102
+ }
103
+ return seq;
104
+ }
89
105
  }
90
106
  function asItemIndex(key) {
91
- let idx = Node.isScalar(key) ? key.value : key;
107
+ let idx = identity.isScalar(key) ? key.value : key;
92
108
  if (idx && typeof idx === 'string')
93
109
  idx = Number(idx);
94
110
  return typeof idx === 'number' && Number.isInteger(idx) && idx >= 0
@@ -2,15 +2,15 @@
2
2
 
3
3
  var log = require('../log.js');
4
4
  var stringify = require('../stringify/stringify.js');
5
- var Node = require('./Node.js');
5
+ var identity = require('./identity.js');
6
6
  var Scalar = require('./Scalar.js');
7
7
  var toJS = require('./toJS.js');
8
8
 
9
9
  const MERGE_KEY = '<<';
10
10
  function addPairToJSMap(ctx, map, { key, value }) {
11
11
  if (ctx?.doc.schema.merge && isMergeKey(key)) {
12
- value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
13
- if (Node.isSeq(value))
12
+ value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
13
+ if (identity.isSeq(value))
14
14
  for (const it of value.items)
15
15
  mergeToJSMap(ctx, map, it);
16
16
  else if (Array.isArray(value))
@@ -44,7 +44,7 @@ function addPairToJSMap(ctx, map, { key, value }) {
44
44
  return map;
45
45
  }
46
46
  const isMergeKey = (key) => key === MERGE_KEY ||
47
- (Node.isScalar(key) &&
47
+ (identity.isScalar(key) &&
48
48
  key.value === MERGE_KEY &&
49
49
  (!key.type || key.type === Scalar.Scalar.PLAIN));
50
50
  // If the value associated with a merge key is a single mapping node, each of
@@ -55,8 +55,8 @@ const isMergeKey = (key) => key === MERGE_KEY ||
55
55
  // Keys in mapping nodes earlier in the sequence override keys specified in
56
56
  // later mapping nodes. -- http://yaml.org/type/merge.html
57
57
  function mergeToJSMap(ctx, map, value) {
58
- const source = ctx && Node.isAlias(value) ? value.resolve(ctx.doc) : value;
59
- if (!Node.isMap(source))
58
+ const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
59
+ if (!identity.isMap(source))
60
60
  throw new Error('Merge sources must be maps or map aliases');
61
61
  const srcMap = source.toJSON(null, ctx, Map);
62
62
  for (const [key, value] of srcMap) {
@@ -83,7 +83,7 @@ function stringifyKey(key, jsKey, ctx) {
83
83
  return '';
84
84
  if (typeof jsKey !== 'object')
85
85
  return String(jsKey);
86
- if (Node.isNode(key) && ctx && ctx.doc) {
86
+ if (identity.isNode(key) && ctx && ctx.doc) {
87
87
  const strCtx = stringify.createStringifyContext(ctx.doc, {});
88
88
  strCtx.anchors = new Set();
89
89
  for (const node of ctx.anchors.keys())
@@ -0,0 +1,23 @@
1
+ import type { Document } from '../doc/Document.js';
2
+ import type { Alias } from './Alias.js';
3
+ import type { Node } from './Node.js';
4
+ import type { Pair } from './Pair.js';
5
+ import type { Scalar } from './Scalar.js';
6
+ import type { YAMLMap } from './YAMLMap.js';
7
+ import type { YAMLSeq } from './YAMLSeq.js';
8
+ export declare const ALIAS: unique symbol;
9
+ export declare const DOC: unique symbol;
10
+ export declare const MAP: unique symbol;
11
+ export declare const PAIR: unique symbol;
12
+ export declare const SCALAR: unique symbol;
13
+ export declare const SEQ: unique symbol;
14
+ export declare const NODE_TYPE: unique symbol;
15
+ export declare const isAlias: (node: any) => node is Alias;
16
+ export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T, true>;
17
+ export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
18
+ export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
19
+ export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
20
+ export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
21
+ export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
22
+ export declare function isNode<T = unknown>(node: any): node is Node<T>;
23
+ export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const ALIAS = Symbol.for('yaml.alias');
4
+ const DOC = Symbol.for('yaml.document');
5
+ const MAP = Symbol.for('yaml.map');
6
+ const PAIR = Symbol.for('yaml.pair');
7
+ const SCALAR = Symbol.for('yaml.scalar');
8
+ const SEQ = Symbol.for('yaml.seq');
9
+ const NODE_TYPE = Symbol.for('yaml.node.type');
10
+ const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
11
+ const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
12
+ const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
13
+ const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
14
+ const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
15
+ const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
16
+ function isCollection(node) {
17
+ if (node && typeof node === 'object')
18
+ switch (node[NODE_TYPE]) {
19
+ case MAP:
20
+ case SEQ:
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ function isNode(node) {
26
+ if (node && typeof node === 'object')
27
+ switch (node[NODE_TYPE]) {
28
+ case ALIAS:
29
+ case MAP:
30
+ case SCALAR:
31
+ case SEQ:
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
37
+
38
+ exports.ALIAS = ALIAS;
39
+ exports.DOC = DOC;
40
+ exports.MAP = MAP;
41
+ exports.NODE_TYPE = NODE_TYPE;
42
+ exports.PAIR = PAIR;
43
+ exports.SCALAR = SCALAR;
44
+ exports.SEQ = SEQ;
45
+ exports.hasAnchor = hasAnchor;
46
+ exports.isAlias = isAlias;
47
+ exports.isCollection = isCollection;
48
+ exports.isDocument = isDocument;
49
+ exports.isMap = isMap;
50
+ exports.isNode = isNode;
51
+ exports.isPair = isPair;
52
+ exports.isScalar = isScalar;
53
+ exports.isSeq = isSeq;
@@ -1,6 +1,5 @@
1
1
  import type { Document } from '../doc/Document.js';
2
- import type { stringify } from '../stringify/stringify.js';
3
- import { Node } from './Node.js';
2
+ import type { Node } from './Node.js';
4
3
  export interface AnchorData {
5
4
  aliasCount: number;
6
5
  count: number;
@@ -8,14 +7,12 @@ export interface AnchorData {
8
7
  }
9
8
  export interface ToJSContext {
10
9
  anchors: Map<Node, AnchorData>;
11
- doc: Document;
10
+ doc: Document<Node, boolean>;
12
11
  keep: boolean;
13
12
  mapAsMap: boolean;
14
13
  mapKeyWarned: boolean;
15
14
  maxAliasCount: number;
16
15
  onCreate?: (res: unknown) => void;
17
- /** Requiring this directly in Pair would create circular dependencies */
18
- stringify: typeof stringify;
19
16
  }
20
17
  /**
21
18
  * Recursively convert any node or its contents to native JavaScript
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('./Node.js');
3
+ var identity = require('./identity.js');
4
4
 
5
5
  /**
6
6
  * Recursively convert any node or its contents to native JavaScript
@@ -18,7 +18,7 @@ function toJS(value, arg, ctx) {
18
18
  return value.map((v, i) => toJS(v, String(i), ctx));
19
19
  if (value && typeof value.toJSON === 'function') {
20
20
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
21
- if (!ctx || !Node.hasAnchor(value))
21
+ if (!ctx || !identity.hasAnchor(value))
22
22
  return value.toJSON(arg, ctx);
23
23
  const data = { aliasCount: 0, count: 1, res: undefined };
24
24
  ctx.anchors.set(value, data);
@@ -1,7 +1,7 @@
1
1
  import { Composer } from './compose/composer.js';
2
2
  import type { Reviver } from './doc/applyReviver.js';
3
3
  import { Document, Replacer } from './doc/Document.js';
4
- import type { ParsedNode } from './nodes/Node.js';
4
+ import type { Node, ParsedNode } from './nodes/Node.js';
5
5
  import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
6
6
  export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
7
7
  empty: true;
@@ -15,9 +15,9 @@ export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer
15
15
  * EmptyStream and contain additional stream information. In
16
16
  * TypeScript, you should use `'empty' in docs` as a type guard for it.
17
17
  */
18
- export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
18
+ export declare function parseAllDocuments<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Array<Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>> | EmptyStream;
19
19
  /** Parse an input string into a single YAML.Document */
20
- export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
20
+ export declare function parseDocument<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>;
21
21
  /**
22
22
  * Parse an input string into JavaScript.
23
23
  *
@@ -1,4 +1,4 @@
1
- import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
1
+ import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
2
2
  import type { Pair } from '../nodes/Pair.js';
3
3
  import type { SchemaOptions, ToStringOptions } from '../options.js';
4
4
  import type { CollectionTag, ScalarTag } from './types.js';
@@ -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 map = require('./common/map.js');
5
5
  var seq = require('./common/seq.js');
6
6
  var string = require('./common/string.js');
@@ -19,9 +19,9 @@ class Schema {
19
19
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
20
20
  this.tags = tags.getTags(customTags, this.name);
21
21
  this.toStringOptions = toStringDefaults ?? null;
22
- Object.defineProperty(this, Node.MAP, { value: map.map });
23
- Object.defineProperty(this, Node.SCALAR, { value: string.string });
24
- Object.defineProperty(this, Node.SEQ, { value: seq.seq });
22
+ Object.defineProperty(this, identity.MAP, { value: map.map });
23
+ Object.defineProperty(this, identity.SCALAR, { value: string.string });
24
+ Object.defineProperty(this, identity.SEQ, { value: seq.seq });
25
25
  // Used by createMap()
26
26
  this.sortMapEntries =
27
27
  typeof sortMapEntries === 'function'
@@ -1,44 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../../nodes/Node.js');
4
- var Pair = require('../../nodes/Pair.js');
3
+ var identity = require('../../nodes/identity.js');
5
4
  var YAMLMap = require('../../nodes/YAMLMap.js');
6
5
 
7
- function createMap(schema, obj, ctx) {
8
- const { keepUndefined, replacer } = ctx;
9
- const map = new YAMLMap.YAMLMap(schema);
10
- const add = (key, value) => {
11
- if (typeof replacer === 'function')
12
- value = replacer.call(obj, key, value);
13
- else if (Array.isArray(replacer) && !replacer.includes(key))
14
- return;
15
- if (value !== undefined || keepUndefined)
16
- map.items.push(Pair.createPair(key, value, ctx));
17
- };
18
- if (obj instanceof Map) {
19
- for (const [key, value] of obj)
20
- add(key, value);
21
- }
22
- else if (obj && typeof obj === 'object') {
23
- for (const key of Object.keys(obj))
24
- add(key, obj[key]);
25
- }
26
- if (typeof schema.sortMapEntries === 'function') {
27
- map.items.sort(schema.sortMapEntries);
28
- }
29
- return map;
30
- }
31
6
  const map = {
32
7
  collection: 'map',
33
- createNode: createMap,
34
8
  default: true,
35
9
  nodeClass: YAMLMap.YAMLMap,
36
10
  tag: 'tag:yaml.org,2002:map',
37
11
  resolve(map, onError) {
38
- if (!Node.isMap(map))
12
+ if (!identity.isMap(map))
39
13
  onError('Expected a mapping for this tag');
40
14
  return map;
41
- }
15
+ },
16
+ createNode: (schema, obj, ctx) => YAMLMap.YAMLMap.from(schema, obj, ctx)
42
17
  };
43
18
 
44
19
  exports.map = map;
@@ -1,35 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var createNode = require('../../doc/createNode.js');
4
- var Node = require('../../nodes/Node.js');
3
+ var identity = require('../../nodes/identity.js');
5
4
  var YAMLSeq = require('../../nodes/YAMLSeq.js');
6
5
 
7
- function createSeq(schema, obj, ctx) {
8
- const { replacer } = ctx;
9
- const seq = new YAMLSeq.YAMLSeq(schema);
10
- if (obj && Symbol.iterator in Object(obj)) {
11
- let i = 0;
12
- for (let it of obj) {
13
- if (typeof replacer === 'function') {
14
- const key = obj instanceof Set ? it : String(i++);
15
- it = replacer.call(obj, key, it);
16
- }
17
- seq.items.push(createNode.createNode(it, undefined, ctx));
18
- }
19
- }
20
- return seq;
21
- }
22
6
  const seq = {
23
7
  collection: 'seq',
24
- createNode: createSeq,
25
8
  default: true,
26
9
  nodeClass: YAMLSeq.YAMLSeq,
27
10
  tag: 'tag:yaml.org,2002:seq',
28
11
  resolve(seq, onError) {
29
- if (!Node.isSeq(seq))
12
+ if (!identity.isSeq(seq))
30
13
  onError('Expected a sequence for this tag');
31
14
  return seq;
32
- }
15
+ },
16
+ createNode: (schema, obj, ctx) => YAMLSeq.YAMLSeq.from(schema, obj, ctx)
33
17
  };
34
18
 
35
19
  exports.seq = seq;
@@ -1 +1 @@
1
- export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
1
+ export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
@@ -1,2 +1,2 @@
1
1
  import { CollectionTag, ScalarTag } from '../types.js';
2
- export declare const schema: (ScalarTag | CollectionTag)[];
2
+ export declare const schema: (CollectionTag | ScalarTag)[];
@@ -36,5 +36,5 @@ export declare const coreKnownTags: {
36
36
  test: RegExp;
37
37
  };
38
38
  };
39
- export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (ScalarTag | CollectionTag)[];
39
+ export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
40
40
  export {};
@@ -1,11 +1,11 @@
1
1
  import type { CreateNodeContext } from '../doc/createNode.js';
2
- import type { Schema } from './Schema.js';
3
2
  import type { Node } from '../nodes/Node.js';
4
3
  import type { Scalar } from '../nodes/Scalar.js';
5
4
  import type { YAMLMap } from '../nodes/YAMLMap.js';
6
5
  import type { YAMLSeq } from '../nodes/YAMLSeq.js';
7
6
  import type { ParseOptions } from '../options.js';
8
7
  import type { StringifyContext } from '../stringify/stringify.js';
8
+ import type { Schema } from './Schema.js';
9
9
  interface TagBase {
10
10
  /**
11
11
  * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
@@ -71,12 +71,20 @@ export interface CollectionTag extends TagBase {
71
71
  /**
72
72
  * The `Node` child class that implements this tag.
73
73
  * If set, used to select this tag when stringifying.
74
+ *
75
+ * If the class provides a static `from` method, then that
76
+ * will be used if the tag object doesn't have a `createNode` method.
74
77
  */
75
- nodeClass?: new () => Node;
78
+ nodeClass?: {
79
+ new (schema?: Schema): Node;
80
+ from?: (schema: Schema, obj: unknown, ctx: CreateNodeContext) => Node;
81
+ };
76
82
  /**
77
83
  * Turns a value into an AST node.
78
84
  * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
85
+ *
86
+ * Note: this is required if nodeClass is not provided.
79
87
  */
80
- resolve(value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions): unknown;
88
+ resolve?: (value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions) => unknown;
81
89
  }
82
90
  export {};
@@ -1,5 +1,7 @@
1
- import { YAMLSeq } from '../../nodes/YAMLSeq.js';
2
1
  import { ToJSContext } from '../../nodes/toJS.js';
2
+ import { YAMLSeq } from '../../nodes/YAMLSeq.js';
3
+ import { CreateNodeContext } from '../../util.js';
4
+ import type { Schema } from '../Schema.js';
3
5
  import { CollectionTag } from '../types.js';
4
6
  export declare class YAMLOMap extends YAMLSeq {
5
7
  static tag: string;
@@ -21,5 +23,6 @@ export declare class YAMLOMap extends YAMLSeq {
21
23
  * but TypeScript won't allow widening the signature of a child method.
22
24
  */
23
25
  toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
26
+ static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLOMap;
24
27
  }
25
28
  export declare const omap: CollectionTag;