cdk8s 2.7.61 → 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 +4 -4
  158. package/node_modules/yaml/browser/dist/options.js +0 -17
  159. package/node_modules/yaml/dist/options.js +0 -19
@@ -13,25 +13,21 @@ function collectionFromPath(schema, path, value) {
13
13
  v = a;
14
14
  }
15
15
  else {
16
- const o = {};
17
- Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
18
- value: v,
19
- writable: true,
20
- enumerable: true,
21
- configurable: true
22
- });
23
- v = o;
16
+ v = new Map([[k, v]]);
24
17
  }
25
18
  }
26
19
  return createNode.createNode(v, undefined, {
27
- onAnchor() {
28
- throw new Error('Repeated objects are not supported here');
20
+ aliasDuplicateObjects: false,
21
+ keepUndefined: false,
22
+ onAnchor: () => {
23
+ throw new Error('This should not happen, please report a bug.');
29
24
  },
30
25
  schema,
31
26
  sourceObjects: new Map()
32
27
  });
33
28
  }
34
- // null, undefined, or an empty non-string iterable (e.g. [])
29
+ // Type guard is intentionally a little wrong so as to be more useful,
30
+ // as it does not cover untypable empty non-string iterables (e.g. []).
35
31
  const isEmptyPath = (path) => path == null ||
36
32
  (typeof path === 'object' && !!path[Symbol.iterator]().next().done);
37
33
  class Collection extends Node.NodeBase {
@@ -44,6 +40,20 @@ class Collection extends Node.NodeBase {
44
40
  writable: true
45
41
  });
46
42
  }
43
+ /**
44
+ * Create a copy of this collection.
45
+ *
46
+ * @param schema - If defined, overwrites the original's schema
47
+ */
48
+ clone(schema) {
49
+ const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
50
+ if (schema)
51
+ copy.schema = schema;
52
+ copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it);
53
+ if (this.range)
54
+ copy.range = this.range.slice();
55
+ return copy;
56
+ }
47
57
  /**
48
58
  * Adds a value to the collection. For `!!map` and `!!omap` the value must
49
59
  * be a Pair instance or a `{ key, value }` object, which may not have a key
@@ -67,7 +77,8 @@ class Collection extends Node.NodeBase {
67
77
  * Removes a value from the collection.
68
78
  * @returns `true` if the item was found and removed.
69
79
  */
70
- deleteIn([key, ...rest]) {
80
+ deleteIn(path) {
81
+ const [key, ...rest] = path;
71
82
  if (rest.length === 0)
72
83
  return this.delete(key);
73
84
  const node = this.get(key, true);
@@ -81,7 +92,8 @@ class Collection extends Node.NodeBase {
81
92
  * scalar values from their surrounding node; to disable set `keepScalar` to
82
93
  * `true` (collections are always returned intact).
83
94
  */
84
- getIn([key, ...rest], keepScalar) {
95
+ getIn(path, keepScalar) {
96
+ const [key, ...rest] = path;
85
97
  const node = this.get(key, true);
86
98
  if (rest.length === 0)
87
99
  return !keepScalar && Node.isScalar(node) ? node.value : node;
@@ -105,7 +117,8 @@ class Collection extends Node.NodeBase {
105
117
  /**
106
118
  * Checks if the collection includes a value with the key `key`.
107
119
  */
108
- hasIn([key, ...rest]) {
120
+ hasIn(path) {
121
+ const [key, ...rest] = path;
109
122
  if (rest.length === 0)
110
123
  return this.has(key);
111
124
  const node = this.get(key, true);
@@ -115,7 +128,8 @@ class Collection extends Node.NodeBase {
115
128
  * Sets a value in this collection. For `!!set`, `value` needs to be a
116
129
  * boolean to add/remove the item from the set.
117
130
  */
118
- setIn([key, ...rest], value) {
131
+ setIn(path, value) {
132
+ const [key, ...rest] = path;
119
133
  if (rest.length === 0) {
120
134
  this.set(key, value);
121
135
  }
@@ -1,13 +1,20 @@
1
1
  import type { Document } from '../doc/Document.js';
2
+ import { Token } from '../parse/cst.js';
2
3
  import type { StringifyContext } from '../stringify/stringify.js';
3
4
  import type { Alias } from './Alias.js';
4
5
  import type { Pair } from './Pair.js';
5
6
  import type { Scalar } from './Scalar.js';
6
7
  import type { YAMLMap } from './YAMLMap.js';
7
8
  import type { YAMLSeq } from './YAMLSeq.js';
8
- export declare type Node = Alias | Scalar | YAMLMap | YAMLSeq;
9
- export declare type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
10
- export declare type Range = [number, number, number];
9
+ export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
10
+ /** Utility type mapper */
11
+ export type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
12
+ [key: string]: any;
13
+ } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
14
+ [key: number]: any;
15
+ } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
16
+ export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
17
+ export type Range = [number, number, number];
11
18
  export declare const ALIAS: unique symbol;
12
19
  export declare const DOC: unique symbol;
13
20
  export declare const MAP: unique symbol;
@@ -16,14 +23,14 @@ export declare const SCALAR: unique symbol;
16
23
  export declare const SEQ: unique symbol;
17
24
  export declare const NODE_TYPE: unique symbol;
18
25
  export declare const isAlias: (node: any) => node is Alias;
19
- export declare const isDocument: (node: any) => node is Document<unknown>;
20
- export declare const isMap: (node: any) => node is YAMLMap<unknown, unknown>;
21
- export declare const isPair: (node: any) => node is Pair<unknown, unknown>;
22
- export declare const isScalar: (node: any) => node is Scalar<unknown>;
23
- export declare const isSeq: (node: any) => node is YAMLSeq<unknown>;
24
- export declare function isCollection(node: any): node is YAMLMap | YAMLSeq;
25
- export declare function isNode(node: any): node is Node;
26
- export declare const hasAnchor: (node: unknown) => node is YAMLMap<unknown, unknown> | YAMLSeq<unknown> | Scalar<unknown>;
26
+ export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
27
+ export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
28
+ export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
29
+ export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
30
+ export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
31
+ export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
32
+ export declare function isNode<T = unknown>(node: any): node is Node<T>;
33
+ export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
27
34
  export declare abstract class NodeBase {
28
35
  readonly [NODE_TYPE]: symbol;
29
36
  /** A comment on or immediately after this */
@@ -39,10 +46,14 @@ export declare abstract class NodeBase {
39
46
  range?: Range | null;
40
47
  /** A blank line before this node and its commentBefore */
41
48
  spaceBefore?: boolean;
49
+ /** The CST token that was composed into this node. */
50
+ srcToken?: Token;
42
51
  /** A fully qualified tag, if required */
43
52
  tag?: string;
44
53
  /** A plain JS representation of this node */
45
54
  abstract toJSON(): any;
46
55
  abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
47
56
  constructor(type: symbol);
57
+ /** Create a copy of this node. */
58
+ clone(): NodeBase;
48
59
  }
@@ -38,6 +38,13 @@ class NodeBase {
38
38
  constructor(type) {
39
39
  Object.defineProperty(this, NODE_TYPE, { value: type });
40
40
  }
41
+ /** Create a copy of this node. */
42
+ clone() {
43
+ const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
44
+ if (this.range)
45
+ copy.range = this.range.slice();
46
+ return copy;
47
+ }
41
48
  }
42
49
 
43
50
  exports.ALIAS = ALIAS;
@@ -1,16 +1,21 @@
1
1
  import { CreateNodeContext } from '../doc/createNode.js';
2
- import { StringifyContext } from '../stringify/stringify.js';
2
+ import type { CollectionItem } from '../parse/cst.js';
3
+ import type { Schema } from '../schema/Schema.js';
4
+ import type { StringifyContext } from '../stringify/stringify.js';
3
5
  import { addPairToJSMap } from './addPairToJSMap.js';
4
6
  import { NODE_TYPE } from './Node.js';
5
- import { ToJSContext } from './toJS.js';
6
- export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
7
+ import type { ToJSContext } from './toJS.js';
8
+ export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node<unknown>, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
7
9
  export declare class Pair<K = unknown, V = unknown> {
8
10
  readonly [NODE_TYPE]: symbol;
9
11
  /** Always Node or null when parsed, but can be set to anything. */
10
12
  key: K;
11
13
  /** Always Node or null when parsed, but can be set to anything. */
12
14
  value: V | null;
15
+ /** The CST token that was composed into this pair. */
16
+ srcToken?: CollectionItem;
13
17
  constructor(key: K, value?: V | null);
18
+ clone(schema?: Schema): Pair<K, V>;
14
19
  toJSON(_?: unknown, ctx?: ToJSContext): ReturnType<typeof addPairToJSMap>;
15
20
  toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
16
21
  }
@@ -16,12 +16,20 @@ class Pair {
16
16
  this.key = key;
17
17
  this.value = value;
18
18
  }
19
+ clone(schema) {
20
+ let { key, value } = this;
21
+ if (Node.isNode(key))
22
+ key = key.clone(schema);
23
+ if (Node.isNode(value))
24
+ value = value.clone(schema);
25
+ return new Pair(key, value);
26
+ }
19
27
  toJSON(_, ctx) {
20
- const pair = ctx && ctx.mapAsMap ? new Map() : {};
28
+ const pair = ctx?.mapAsMap ? new Map() : {};
21
29
  return addPairToJSMap.addPairToJSMap(ctx, pair, this);
22
30
  }
23
31
  toString(ctx, onComment, onChompKeep) {
24
- return ctx && ctx.doc
32
+ return ctx?.doc
25
33
  ? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
26
34
  : JSON.stringify(this);
27
35
  }
@@ -1,3 +1,4 @@
1
+ import type { BlockScalar, FlowScalar } from '../parse/cst.js';
1
2
  import { NodeBase, Range } from './Node.js';
2
3
  import { ToJSContext } from './toJS.js';
3
4
  export declare const isScalarValue: (value: unknown) => boolean;
@@ -5,6 +6,7 @@ export declare namespace Scalar {
5
6
  interface Parsed extends Scalar {
6
7
  range: Range;
7
8
  source: string;
9
+ srcToken?: FlowScalar | BlockScalar;
8
10
  }
9
11
  type BLOCK_FOLDED = 'BLOCK_FOLDED';
10
12
  type BLOCK_LITERAL = 'BLOCK_LITERAL';
@@ -10,7 +10,7 @@ class Scalar extends Node.NodeBase {
10
10
  this.value = value;
11
11
  }
12
12
  toJSON(arg, ctx) {
13
- return ctx && ctx.keep ? this.value : toJS.toJS(this.value, arg, ctx);
13
+ return ctx?.keep ? this.value : toJS.toJS(this.value, arg, ctx);
14
14
  }
15
15
  toString() {
16
16
  return String(this.value);
@@ -1,14 +1,18 @@
1
+ import type { BlockMap, FlowCollection } from '../parse/cst.js';
1
2
  import type { Schema } from '../schema/Schema.js';
2
3
  import type { StringifyContext } from '../stringify/stringify.js';
3
4
  import { Collection } from './Collection.js';
4
5
  import { ParsedNode, Range } from './Node.js';
5
6
  import { Pair } from './Pair.js';
7
+ import { Scalar } from './Scalar.js';
6
8
  import type { ToJSContext } from './toJS.js';
9
+ export type MapLike = Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
7
10
  export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
8
11
  export declare namespace YAMLMap {
9
12
  interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
10
13
  items: Pair<K, V>[];
11
14
  range: Range;
15
+ srcToken?: BlockMap | FlowCollection;
12
16
  }
13
17
  }
14
18
  export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
@@ -25,15 +29,19 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
25
29
  key: K;
26
30
  value: V;
27
31
  }, overwrite?: boolean): void;
28
- delete(key: K): boolean;
29
- get(key: K, keepScalar?: boolean): unknown;
30
- has(key: K): boolean;
32
+ delete(key: unknown): boolean;
33
+ get(key: unknown, keepScalar: true): Scalar<V> | undefined;
34
+ get(key: unknown, keepScalar?: false): V | undefined;
35
+ get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
36
+ has(key: unknown): boolean;
31
37
  set(key: K, value: V): void;
32
38
  /**
33
39
  * @param ctx - Conversion context, originally set in Document#toJS()
34
40
  * @param {Class} Type - If set, forces the returned collection type
35
41
  * @returns Instance of Type, Map, or Object
36
42
  */
37
- toJSON(_?: unknown, ctx?: ToJSContext, Type?: any): any;
43
+ toJSON<T extends MapLike = Map<unknown, unknown>>(_?: unknown, ctx?: ToJSContext, Type?: {
44
+ new (): T;
45
+ }): any;
38
46
  toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
39
47
  }
@@ -20,13 +20,13 @@ function findPair(items, key) {
20
20
  return undefined;
21
21
  }
22
22
  class YAMLMap extends Collection.Collection {
23
+ static get tagName() {
24
+ return 'tag:yaml.org,2002:map';
25
+ }
23
26
  constructor(schema) {
24
27
  super(Node.MAP, schema);
25
28
  this.items = [];
26
29
  }
27
- static get tagName() {
28
- return 'tag:yaml.org,2002:map';
29
- }
30
30
  /**
31
31
  * Adds a value to the collection.
32
32
  *
@@ -39,12 +39,12 @@ class YAMLMap extends Collection.Collection {
39
39
  _pair = pair;
40
40
  else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
41
41
  // In TypeScript, this never happens.
42
- _pair = new Pair.Pair(pair, pair.value);
42
+ _pair = new Pair.Pair(pair, pair?.value);
43
43
  }
44
44
  else
45
45
  _pair = new Pair.Pair(pair.key, pair.value);
46
46
  const prev = findPair(this.items, _pair.key);
47
- const sortEntries = this.schema && this.schema.sortMapEntries;
47
+ const sortEntries = this.schema?.sortMapEntries;
48
48
  if (prev) {
49
49
  if (!overwrite)
50
50
  throw new Error(`Key ${_pair.key} already set`);
@@ -74,8 +74,8 @@ class YAMLMap extends Collection.Collection {
74
74
  }
75
75
  get(key, keepScalar) {
76
76
  const it = findPair(this.items, key);
77
- const node = it && it.value;
78
- return !keepScalar && Node.isScalar(node) ? node.value : node;
77
+ const node = it?.value;
78
+ return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
79
79
  }
80
80
  has(key) {
81
81
  return !!findPair(this.items, key);
@@ -89,8 +89,8 @@ class YAMLMap extends Collection.Collection {
89
89
  * @returns Instance of Type, Map, or Object
90
90
  */
91
91
  toJSON(_, ctx, Type) {
92
- const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
93
- if (ctx && ctx.onCreate)
92
+ const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
93
+ if (ctx?.onCreate)
94
94
  ctx.onCreate(map);
95
95
  for (const item of this.items)
96
96
  addPairToJSMap.addPairToJSMap(ctx, map, item);
@@ -106,7 +106,7 @@ class YAMLMap extends Collection.Collection {
106
106
  if (!ctx.allNullValues && this.hasAllNullValues(false))
107
107
  ctx = Object.assign({}, ctx, { allNullValues: true });
108
108
  return stringifyCollection.stringifyCollection(this, ctx, {
109
- blockItem: n => n.str,
109
+ blockItemPrefix: '',
110
110
  flowChars: { start: '{', end: '}' },
111
111
  itemIndent: ctx.indent || '',
112
112
  onChompKeep,
@@ -1,13 +1,16 @@
1
+ import type { BlockSequence, FlowCollection } from '../parse/cst.js';
1
2
  import type { Schema } from '../schema/Schema.js';
2
3
  import type { StringifyContext } from '../stringify/stringify.js';
3
4
  import { Collection } from './Collection.js';
4
5
  import { ParsedNode, Range } from './Node.js';
5
6
  import type { Pair } from './Pair.js';
7
+ import { Scalar } from './Scalar.js';
6
8
  import { ToJSContext } from './toJS.js';
7
9
  export declare namespace YAMLSeq {
8
10
  interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
9
11
  items: T[];
10
12
  range: Range;
13
+ srcToken?: BlockSequence | FlowCollection;
11
14
  }
12
15
  }
13
16
  export declare class YAMLSeq<T = unknown> extends Collection {
@@ -32,7 +35,9 @@ export declare class YAMLSeq<T = unknown> extends Collection {
32
35
  * `key` must contain a representation of an integer for this to succeed.
33
36
  * It may be wrapped in a `Scalar`.
34
37
  */
35
- get(key: unknown, keepScalar?: boolean): unknown;
38
+ get(key: unknown, keepScalar: true): Scalar<T> | undefined;
39
+ get(key: unknown, keepScalar?: false): T | undefined;
40
+ get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
36
41
  /**
37
42
  * Checks if the collection includes a value with the key `key`.
38
43
  *
@@ -7,13 +7,13 @@ var Scalar = require('./Scalar.js');
7
7
  var toJS = require('./toJS.js');
8
8
 
9
9
  class YAMLSeq extends Collection.Collection {
10
+ static get tagName() {
11
+ return 'tag:yaml.org,2002:seq';
12
+ }
10
13
  constructor(schema) {
11
14
  super(Node.SEQ, schema);
12
15
  this.items = [];
13
16
  }
14
- static get tagName() {
15
- return 'tag:yaml.org,2002:seq';
16
- }
17
17
  add(value) {
18
18
  this.items.push(value);
19
19
  }
@@ -32,14 +32,6 @@ class YAMLSeq extends Collection.Collection {
32
32
  const del = this.items.splice(idx, 1);
33
33
  return del.length > 0;
34
34
  }
35
- /**
36
- * Returns item at `key`, or `undefined` if not found. By default unwraps
37
- * scalar values from their surrounding node; to disable set `keepScalar` to
38
- * `true` (collections are always returned intact).
39
- *
40
- * `key` must contain a representation of an integer for this to succeed.
41
- * It may be wrapped in a `Scalar`.
42
- */
43
35
  get(key, keepScalar) {
44
36
  const idx = asItemIndex(key);
45
37
  if (typeof idx !== 'number')
@@ -76,7 +68,7 @@ class YAMLSeq extends Collection.Collection {
76
68
  }
77
69
  toJSON(_, ctx) {
78
70
  const seq = [];
79
- if (ctx && ctx.onCreate)
71
+ if (ctx?.onCreate)
80
72
  ctx.onCreate(seq);
81
73
  let i = 0;
82
74
  for (const item of this.items)
@@ -87,7 +79,7 @@ class YAMLSeq extends Collection.Collection {
87
79
  if (!ctx)
88
80
  return JSON.stringify(this);
89
81
  return stringifyCollection.stringifyCollection(this, ctx, {
90
- blockItem: n => (n.comment ? n.str : `- ${n.str}`),
82
+ blockItemPrefix: '- ',
91
83
  flowChars: { start: '[', end: ']' },
92
84
  itemIndent: (ctx.indent || '') + ' ',
93
85
  onChompKeep,
@@ -1,3 +1,4 @@
1
1
  import type { Pair } from './Pair.js';
2
2
  import { ToJSContext } from './toJS.js';
3
- export declare function addPairToJSMap(ctx: ToJSContext | undefined, map: Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>, { key, value }: Pair): Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
3
+ import type { MapLike } from './YAMLMap.js';
4
+ export declare function addPairToJSMap(ctx: ToJSContext | undefined, map: MapLike, { key, value }: Pair): MapLike;
@@ -8,7 +8,8 @@ var toJS = require('./toJS.js');
8
8
 
9
9
  const MERGE_KEY = '<<';
10
10
  function addPairToJSMap(ctx, map, { key, value }) {
11
- if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
11
+ if (ctx?.doc.schema.merge && isMergeKey(key)) {
12
+ value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
12
13
  if (Node.isSeq(value))
13
14
  for (const it of value.items)
14
15
  mergeToJSMap(ctx, map, it);
@@ -13,9 +13,11 @@ var Node = require('./Node.js');
13
13
  * stringification.
14
14
  */
15
15
  function toJS(value, arg, ctx) {
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
16
17
  if (Array.isArray(value))
17
18
  return value.map((v, i) => toJS(v, String(i), ctx));
18
19
  if (value && typeof value.toJSON === 'function') {
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
19
21
  if (!ctx || !Node.hasAnchor(value))
20
22
  return value.toJSON(arg, ctx);
21
23
  const data = { aliasCount: 0, count: 1, res: undefined };
@@ -29,7 +31,7 @@ function toJS(value, arg, ctx) {
29
31
  ctx.onCreate(res);
30
32
  return res;
31
33
  }
32
- if (typeof value === 'bigint' && !(ctx && ctx.keep))
34
+ if (typeof value === 'bigint' && !ctx?.keep)
33
35
  return Number(value);
34
36
  return value;
35
37
  }
@@ -5,10 +5,10 @@ import type { ParsedNode } from './nodes/Node.js';
5
5
  import type { Pair } from './nodes/Pair.js';
6
6
  import type { Scalar } from './nodes/Scalar.js';
7
7
  import type { LineCounter } from './parse/line-counter.js';
8
- import type { SchemaName } from './schema/Schema.js';
8
+ import type { Schema } from './schema/Schema.js';
9
9
  import type { Tags } from './schema/tags.js';
10
10
  import type { CollectionTag, ScalarTag } from './schema/types.js';
11
- export declare type ParseOptions = {
11
+ export type ParseOptions = {
12
12
  /**
13
13
  * Whether integers should be parsed into BigInt rather than number values.
14
14
  *
@@ -17,6 +17,13 @@ export declare type ParseOptions = {
17
17
  * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
18
18
  */
19
19
  intAsBigInt?: boolean;
20
+ /**
21
+ * Include a `srcToken` value on each parsed `Node`, containing the CST token
22
+ * that was composed into this node.
23
+ *
24
+ * Default: `false`
25
+ */
26
+ keepSourceTokens?: boolean;
20
27
  /**
21
28
  * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
22
29
  * to provide the `{ line, col }` positions within the input.
@@ -49,12 +56,13 @@ export declare type ParseOptions = {
49
56
  */
50
57
  uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
51
58
  };
52
- export declare type DocumentOptions = {
59
+ export type DocumentOptions = {
53
60
  /**
61
+ * @internal
54
62
  * Used internally by Composer. If set and includes an explicit version,
55
63
  * that overrides the `version` option.
56
64
  */
57
- directives?: Directives;
65
+ _directives?: Directives;
58
66
  /**
59
67
  * Control the logging level during parsing
60
68
  *
@@ -66,9 +74,17 @@ export declare type DocumentOptions = {
66
74
  *
67
75
  * Default: `"1.2"`
68
76
  */
69
- version?: '1.1' | '1.2';
77
+ version?: '1.1' | '1.2' | 'next';
70
78
  };
71
- export declare type SchemaOptions = {
79
+ export type SchemaOptions = {
80
+ /**
81
+ * When parsing, warn about compatibility issues with the given schema.
82
+ * When stringifying, use scalar styles that are parsed correctly
83
+ * by the `compat` schema as well as the actual schema.
84
+ *
85
+ * Default: `null`
86
+ */
87
+ compat?: string | Tags | null;
72
88
  /**
73
89
  * Array of additional tags to include in the schema, or a function that may
74
90
  * modify the schema's base tag array.
@@ -92,9 +108,18 @@ export declare type SchemaOptions = {
92
108
  /**
93
109
  * The base schema to use.
94
110
  *
95
- * Default: `"core"` for YAML 1.2, `"yaml-1.1"` for earlier versions
111
+ * The core library has built-in support for the following:
112
+ * - `'failsafe'`: A minimal schema that parses all scalars as strings
113
+ * - `'core'`: The YAML 1.2 core schema
114
+ * - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
115
+ * - `'yaml-1.1'`: The YAML 1.1 schema
116
+ *
117
+ * If using another (custom) schema, the `customTags` array needs to
118
+ * fully define the schema's tags.
119
+ *
120
+ * Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
96
121
  */
97
- schema?: SchemaName;
122
+ schema?: string | Schema;
98
123
  /**
99
124
  * When adding to or stringifying a map, sort the entries.
100
125
  * If `true`, sort by comparing key values with `<`.
@@ -103,8 +128,19 @@ export declare type SchemaOptions = {
103
128
  * Default: `false`
104
129
  */
105
130
  sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
131
+ /**
132
+ * Override default values for `toString()` options.
133
+ */
134
+ toStringDefaults?: ToStringOptions;
106
135
  };
107
- export declare type CreateNodeOptions = {
136
+ export type CreateNodeOptions = {
137
+ /**
138
+ * During node construction, use anchors and aliases to keep strictly equal
139
+ * non-null objects as equivalent in YAML.
140
+ *
141
+ * Default: `true`
142
+ */
143
+ aliasDuplicateObjects?: boolean;
108
144
  /**
109
145
  * Default prefix for anchors.
110
146
  *
@@ -127,7 +163,7 @@ export declare type CreateNodeOptions = {
127
163
  */
128
164
  tag?: string;
129
165
  };
130
- export declare type ToJSOptions = {
166
+ export type ToJSOptions = {
131
167
  /**
132
168
  * Use Map rather than Object to represent mappings.
133
169
  *
@@ -153,7 +189,31 @@ export declare type ToJSOptions = {
153
189
  */
154
190
  reviver?: Reviver;
155
191
  };
156
- export declare type ToStringOptions = {
192
+ export type ToStringOptions = {
193
+ /**
194
+ * Use block quote styles for scalar values where applicable.
195
+ * Set to `false` to disable block quotes completely.
196
+ *
197
+ * Default: `true`
198
+ */
199
+ blockQuote?: boolean | 'folded' | 'literal';
200
+ /**
201
+ * Enforce `'block'` or `'flow'` style on maps and sequences.
202
+ * Empty collections will always be stringified as `{}` or `[]`.
203
+ *
204
+ * Default: `'any'`, allowing each node to set its style separately
205
+ * with its `flow: boolean` (default `false`) property.
206
+ */
207
+ collectionStyle?: 'any' | 'block' | 'flow';
208
+ /**
209
+ * Comment stringifier.
210
+ * Output should be valid for the current schema.
211
+ *
212
+ * By default, empty comment lines are left empty,
213
+ * lines consisting of a single space are replaced by `#`,
214
+ * and all other lines are prefixed with a `#`.
215
+ */
216
+ commentString?: (comment: string) => string;
157
217
  /**
158
218
  * The default type of string literal used to stringify implicit key values.
159
219
  * Output may use other types if required to fully represent the value.
@@ -204,6 +264,13 @@ export declare type ToStringOptions = {
204
264
  * Default: `'false'`
205
265
  */
206
266
  falseStr?: string;
267
+ /**
268
+ * When true, a single space of padding will be added inside the delimiters
269
+ * of non-empty single-line flow collections.
270
+ *
271
+ * Default: `true`
272
+ */
273
+ flowCollectionPadding?: boolean;
207
274
  /**
208
275
  * The number of spaces to use when indenting code.
209
276
  *
@@ -247,11 +314,12 @@ export declare type ToStringOptions = {
247
314
  */
248
315
  simpleKeys?: boolean;
249
316
  /**
250
- * Prefer 'single quote' rather than "double quote" where applicable.
317
+ * Use 'single quote' rather than "double quote" where applicable.
318
+ * Set to `false` to disable single quotes completely.
251
319
  *
252
- * Default: `false`
320
+ * Default: `null`
253
321
  */
254
- singleQuote?: boolean;
322
+ singleQuote?: boolean | null;
255
323
  /**
256
324
  * String representation for `true`.
257
325
  * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
@@ -268,11 +336,3 @@ export declare type ToStringOptions = {
268
336
  */
269
337
  verifyAliasOrder?: boolean;
270
338
  };
271
- /**
272
- * `yaml` defines document-specific options in three places: as an argument of
273
- * parse, create and stringify calls, in the values of `YAML.defaultOptions`,
274
- * and in the version-dependent `YAML.Document.defaults` object. Values set in
275
- * `YAML.defaultOptions` override version-dependent defaults, and argument
276
- * options override both.
277
- */
278
- export declare const defaultOptions: Required<Omit<ParseOptions, 'lineCounter'> & Omit<DocumentOptions, 'directives'>>;