projen 0.71.68 → 0.71.69

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 (240) hide show
  1. package/.jsii +2 -2
  2. package/lib/awscdk/auto-discover.js +5 -5
  3. package/lib/awscdk/awscdk-app-java.js +1 -1
  4. package/lib/awscdk/awscdk-app-py.js +1 -1
  5. package/lib/awscdk/awscdk-app-ts.js +1 -1
  6. package/lib/awscdk/awscdk-construct.js +2 -2
  7. package/lib/awscdk/awscdk-deps-java.js +1 -1
  8. package/lib/awscdk/awscdk-deps-js.js +1 -1
  9. package/lib/awscdk/awscdk-deps-py.js +1 -1
  10. package/lib/awscdk/awscdk-deps.js +1 -1
  11. package/lib/awscdk/cdk-config.js +1 -1
  12. package/lib/awscdk/cdk-tasks.js +1 -1
  13. package/lib/awscdk/integration-test.js +1 -1
  14. package/lib/awscdk/lambda-extension.js +1 -1
  15. package/lib/awscdk/lambda-function.js +2 -2
  16. package/lib/build/build-workflow.js +1 -1
  17. package/lib/cdk/auto-discover-base.js +2 -2
  18. package/lib/cdk/construct-lib.js +1 -1
  19. package/lib/cdk/integration-test-base.js +1 -1
  20. package/lib/cdk/jsii-docgen.js +1 -1
  21. package/lib/cdk/jsii-project.js +1 -1
  22. package/lib/cdk8s/auto-discover.js +2 -2
  23. package/lib/cdk8s/cdk8s-app-py.js +1 -1
  24. package/lib/cdk8s/cdk8s-app-ts.js +1 -1
  25. package/lib/cdk8s/cdk8s-construct.js +1 -1
  26. package/lib/cdk8s/cdk8s-deps-py.js +1 -1
  27. package/lib/cdk8s/cdk8s-deps.js +1 -1
  28. package/lib/cdk8s/integration-test.js +1 -1
  29. package/lib/cdktf/cdktf-construct.js +1 -1
  30. package/lib/circleci/circleci.js +1 -1
  31. package/lib/component.js +1 -1
  32. package/lib/dependencies.js +1 -1
  33. package/lib/dev-env.js +1 -1
  34. package/lib/docker-compose/docker-compose-service.js +1 -1
  35. package/lib/docker-compose/docker-compose.js +1 -1
  36. package/lib/file.js +1 -1
  37. package/lib/gitattributes.js +1 -1
  38. package/lib/github/actions-provider.js +1 -1
  39. package/lib/github/auto-approve.js +1 -1
  40. package/lib/github/auto-merge.js +1 -1
  41. package/lib/github/dependabot.js +1 -1
  42. package/lib/github/github-credentials.js +1 -1
  43. package/lib/github/github-project.js +1 -1
  44. package/lib/github/github.js +1 -1
  45. package/lib/github/mergify.js +1 -1
  46. package/lib/github/pr-template.js +1 -1
  47. package/lib/github/pull-request-lint.js +1 -1
  48. package/lib/github/stale.js +1 -1
  49. package/lib/github/task-workflow.js +1 -1
  50. package/lib/github/workflow-actions.js +1 -1
  51. package/lib/github/workflow-jobs.js +1 -1
  52. package/lib/github/workflows.js +1 -1
  53. package/lib/gitlab/configuration.js +1 -1
  54. package/lib/gitlab/gitlab-configuration.js +1 -1
  55. package/lib/gitlab/nested-configuration.js +1 -1
  56. package/lib/gitpod.js +1 -1
  57. package/lib/ignore-file.js +1 -1
  58. package/lib/ini.js +1 -1
  59. package/lib/java/java-project.js +1 -1
  60. package/lib/java/junit.js +1 -1
  61. package/lib/java/maven-compile.js +1 -1
  62. package/lib/java/maven-packaging.js +1 -1
  63. package/lib/java/maven-sample.js +1 -1
  64. package/lib/java/pom.js +1 -1
  65. package/lib/java/projenrc.js +1 -1
  66. package/lib/javascript/bundler.js +1 -1
  67. package/lib/javascript/eslint.js +1 -1
  68. package/lib/javascript/jest.js +4 -4
  69. package/lib/javascript/node-package.js +1 -1
  70. package/lib/javascript/node-project.js +1 -1
  71. package/lib/javascript/npm-config.js +1 -1
  72. package/lib/javascript/prettier.js +1 -1
  73. package/lib/javascript/projenrc.js +1 -1
  74. package/lib/javascript/typescript-config.js +2 -2
  75. package/lib/javascript/upgrade-dependencies.js +2 -2
  76. package/lib/json-patch.js +1 -1
  77. package/lib/json.js +1 -1
  78. package/lib/license.js +1 -1
  79. package/lib/logger.js +1 -1
  80. package/lib/makefile.js +1 -1
  81. package/lib/object-file.js +1 -1
  82. package/lib/project-build.js +1 -1
  83. package/lib/project.js +1 -1
  84. package/lib/projects.js +1 -1
  85. package/lib/projenrc-json.js +2 -2
  86. package/lib/projenrc.js +1 -1
  87. package/lib/python/pip.js +1 -1
  88. package/lib/python/poetry.js +2 -2
  89. package/lib/python/projenrc.js +1 -1
  90. package/lib/python/pytest-sample.js +1 -1
  91. package/lib/python/pytest.js +1 -1
  92. package/lib/python/python-project.js +1 -1
  93. package/lib/python/python-sample.js +1 -1
  94. package/lib/python/requirements-file.js +1 -1
  95. package/lib/python/setuppy.js +1 -1
  96. package/lib/python/setuptools.js +1 -1
  97. package/lib/python/venv.js +1 -1
  98. package/lib/readme.js +1 -1
  99. package/lib/release/publisher.js +1 -1
  100. package/lib/release/release-trigger.js +1 -1
  101. package/lib/release/release.js +1 -1
  102. package/lib/renovatebot.js +1 -1
  103. package/lib/sample-file.js +2 -2
  104. package/lib/semver.js +1 -1
  105. package/lib/source-code.js +1 -1
  106. package/lib/task-runtime.js +1 -1
  107. package/lib/task.js +1 -1
  108. package/lib/tasks.js +1 -1
  109. package/lib/testing.js +1 -1
  110. package/lib/textfile.js +1 -1
  111. package/lib/toml.js +1 -1
  112. package/lib/typescript/projenrc-ts.js +1 -1
  113. package/lib/typescript/projenrc.js +1 -1
  114. package/lib/typescript/typescript-typedoc.js +1 -1
  115. package/lib/typescript/typescript.js +3 -3
  116. package/lib/version.js +1 -1
  117. package/lib/vscode/devcontainer.js +1 -1
  118. package/lib/vscode/extensions.js +1 -1
  119. package/lib/vscode/launch-config.js +1 -1
  120. package/lib/vscode/settings.js +1 -1
  121. package/lib/vscode/vscode.js +1 -1
  122. package/lib/web/next.js +3 -3
  123. package/lib/web/postcss.js +1 -1
  124. package/lib/web/react.js +4 -4
  125. package/lib/web/tailwind.js +1 -1
  126. package/lib/xmlfile.js +1 -1
  127. package/lib/yaml.js +1 -1
  128. package/node_modules/yaml/README.md +4 -0
  129. package/node_modules/yaml/browser/dist/compose/compose-collection.js +46 -29
  130. package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -0
  131. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +1 -1
  132. package/node_modules/yaml/browser/dist/compose/composer.js +1 -1
  133. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +3 -2
  134. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +3 -2
  135. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +4 -5
  136. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +1 -1
  137. package/node_modules/yaml/browser/dist/doc/Document.js +12 -10
  138. package/node_modules/yaml/browser/dist/doc/anchors.js +1 -1
  139. package/node_modules/yaml/browser/dist/doc/createNode.js +6 -2
  140. package/node_modules/yaml/browser/dist/doc/directives.js +1 -1
  141. package/node_modules/yaml/browser/dist/index.js +1 -1
  142. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +6 -149
  143. package/node_modules/yaml/browser/dist/nodes/Alias.js +9 -2
  144. package/node_modules/yaml/browser/dist/nodes/Collection.js +2 -1
  145. package/node_modules/yaml/browser/dist/nodes/Node.js +25 -35
  146. package/node_modules/yaml/browser/dist/nodes/Pair.js +1 -1
  147. package/node_modules/yaml/browser/dist/nodes/Scalar.js +2 -1
  148. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +30 -2
  149. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +17 -1
  150. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +1 -1
  151. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  152. package/node_modules/yaml/browser/dist/nodes/toJS.js +1 -1
  153. package/node_modules/yaml/browser/dist/schema/Schema.js +1 -1
  154. package/node_modules/yaml/browser/dist/schema/common/map.js +3 -28
  155. package/node_modules/yaml/browser/dist/schema/common/seq.js +3 -19
  156. package/node_modules/yaml/browser/dist/schema/tags.js +1 -1
  157. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +9 -8
  158. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  159. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +14 -13
  160. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +1 -1
  161. package/node_modules/yaml/browser/dist/stringify/stringify.js +1 -1
  162. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +1 -1
  163. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +1 -1
  164. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
  165. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +10 -1
  166. package/node_modules/yaml/browser/dist/util.js +2 -0
  167. package/node_modules/yaml/browser/dist/visit.js +1 -1
  168. package/node_modules/yaml/dist/compose/compose-collection.d.ts +1 -1
  169. package/node_modules/yaml/dist/compose/compose-collection.js +47 -30
  170. package/node_modules/yaml/dist/compose/compose-doc.d.ts +2 -1
  171. package/node_modules/yaml/dist/compose/compose-doc.js +1 -0
  172. package/node_modules/yaml/dist/compose/compose-scalar.js +7 -7
  173. package/node_modules/yaml/dist/compose/composer.d.ts +5 -5
  174. package/node_modules/yaml/dist/compose/composer.js +3 -3
  175. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +2 -1
  176. package/node_modules/yaml/dist/compose/resolve-block-map.js +3 -2
  177. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +2 -1
  178. package/node_modules/yaml/dist/compose/resolve-block-seq.js +3 -2
  179. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +2 -1
  180. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +5 -6
  181. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +3 -3
  182. package/node_modules/yaml/dist/compose/util-map-includes.js +3 -3
  183. package/node_modules/yaml/dist/doc/Document.d.ts +11 -9
  184. package/node_modules/yaml/dist/doc/Document.js +22 -20
  185. package/node_modules/yaml/dist/doc/anchors.d.ts +4 -4
  186. package/node_modules/yaml/dist/doc/anchors.js +2 -2
  187. package/node_modules/yaml/dist/doc/createNode.d.ts +1 -1
  188. package/node_modules/yaml/dist/doc/createNode.js +13 -9
  189. package/node_modules/yaml/dist/doc/directives.js +3 -3
  190. package/node_modules/yaml/dist/errors.d.ts +1 -1
  191. package/node_modules/yaml/dist/index.d.ts +2 -1
  192. package/node_modules/yaml/dist/index.js +9 -9
  193. package/node_modules/yaml/dist/nodes/Alias.d.ts +1 -1
  194. package/node_modules/yaml/dist/nodes/Alias.js +12 -5
  195. package/node_modules/yaml/dist/nodes/Collection.d.ts +3 -2
  196. package/node_modules/yaml/dist/nodes/Collection.js +10 -9
  197. package/node_modules/yaml/dist/nodes/Node.d.ts +5 -18
  198. package/node_modules/yaml/dist/nodes/Node.js +25 -51
  199. package/node_modules/yaml/dist/nodes/Pair.d.ts +2 -2
  200. package/node_modules/yaml/dist/nodes/Pair.js +4 -4
  201. package/node_modules/yaml/dist/nodes/Scalar.js +2 -1
  202. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +7 -1
  203. package/node_modules/yaml/dist/nodes/YAMLMap.js +37 -9
  204. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +3 -1
  205. package/node_modules/yaml/dist/nodes/YAMLSeq.js +21 -5
  206. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +7 -7
  207. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  208. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  209. package/node_modules/yaml/dist/nodes/toJS.d.ts +2 -5
  210. package/node_modules/yaml/dist/nodes/toJS.js +2 -2
  211. package/node_modules/yaml/dist/public-api.d.ts +3 -3
  212. package/node_modules/yaml/dist/schema/Schema.d.ts +1 -1
  213. package/node_modules/yaml/dist/schema/Schema.js +4 -4
  214. package/node_modules/yaml/dist/schema/common/map.js +4 -29
  215. package/node_modules/yaml/dist/schema/common/seq.js +4 -20
  216. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -1
  217. package/node_modules/yaml/dist/schema/json/schema.d.ts +1 -1
  218. package/node_modules/yaml/dist/schema/tags.d.ts +1 -1
  219. package/node_modules/yaml/dist/schema/types.d.ts +11 -3
  220. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +4 -1
  221. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +11 -10
  222. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +1 -1
  223. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +5 -5
  224. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -1
  225. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +3 -1
  226. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +17 -16
  227. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +1 -1
  228. package/node_modules/yaml/dist/stringify/stringify.js +8 -8
  229. package/node_modules/yaml/dist/stringify/stringifyCollection.js +8 -8
  230. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -3
  231. package/node_modules/yaml/dist/stringify/stringifyDocument.js +2 -2
  232. package/node_modules/yaml/dist/stringify/stringifyPair.js +9 -9
  233. package/node_modules/yaml/dist/stringify/stringifyString.js +10 -1
  234. package/node_modules/yaml/dist/test-events.js +8 -8
  235. package/node_modules/yaml/dist/util.d.ts +4 -1
  236. package/node_modules/yaml/dist/util.js +4 -0
  237. package/node_modules/yaml/dist/visit.js +18 -18
  238. package/node_modules/yaml/package.json +8 -6
  239. package/package.json +3 -3
  240. package/node_modules/yaml/util.d.ts +0 -3
@@ -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
  */
@@ -2,11 +2,10 @@
2
2
 
3
3
  var Alias = require('../nodes/Alias.js');
4
4
  var Collection = require('../nodes/Collection.js');
5
- var Node = require('../nodes/Node.js');
5
+ var identity = require('../nodes/identity.js');
6
6
  var Pair = require('../nodes/Pair.js');
7
7
  var toJS = require('../nodes/toJS.js');
8
8
  var Schema = require('../schema/Schema.js');
9
- var stringify = require('../stringify/stringify.js');
10
9
  var stringifyDocument = require('../stringify/stringifyDocument.js');
11
10
  var anchors = require('./anchors.js');
12
11
  var applyReviver = require('./applyReviver.js');
@@ -23,7 +22,7 @@ class Document {
23
22
  this.errors = [];
24
23
  /** Warnings encountered during parsing. */
25
24
  this.warnings = [];
26
- Object.defineProperty(this, Node.NODE_TYPE, { value: Node.DOC });
25
+ Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC });
27
26
  let _replacer = null;
28
27
  if (typeof replacer === 'function' || Array.isArray(replacer)) {
29
28
  _replacer = replacer;
@@ -51,11 +50,9 @@ class Document {
51
50
  else
52
51
  this.directives = new directives.Directives({ version });
53
52
  this.setSchema(version, options);
54
- if (value === undefined)
55
- this.contents = null;
56
- else {
57
- this.contents = this.createNode(value, _replacer, options);
58
- }
53
+ // @ts-expect-error We can't really know that this matches Contents.
54
+ this.contents =
55
+ value === undefined ? null : this.createNode(value, _replacer, options);
59
56
  }
60
57
  /**
61
58
  * Create a deep copy of this Document and its contents.
@@ -64,7 +61,7 @@ class Document {
64
61
  */
65
62
  clone() {
66
63
  const copy = Object.create(Document.prototype, {
67
- [Node.NODE_TYPE]: { value: Node.DOC }
64
+ [identity.NODE_TYPE]: { value: identity.DOC }
68
65
  });
69
66
  copy.commentBefore = this.commentBefore;
70
67
  copy.comment = this.comment;
@@ -74,7 +71,8 @@ class Document {
74
71
  if (this.directives)
75
72
  copy.directives = this.directives.clone();
76
73
  copy.schema = this.schema.clone();
77
- copy.contents = Node.isNode(this.contents)
74
+ // @ts-expect-error We can't really know that this matches Contents.
75
+ copy.contents = identity.isNode(this.contents)
78
76
  ? this.contents.clone(copy.schema)
79
77
  : this.contents;
80
78
  if (this.range)
@@ -140,7 +138,7 @@ class Document {
140
138
  sourceObjects
141
139
  };
142
140
  const node = createNode.createNode(value, tag, ctx);
143
- if (flow && Node.isCollection(node))
141
+ if (flow && identity.isCollection(node))
144
142
  node.flow = true;
145
143
  setAnchors();
146
144
  return node;
@@ -169,6 +167,7 @@ class Document {
169
167
  if (Collection.isEmptyPath(path)) {
170
168
  if (this.contents == null)
171
169
  return false;
170
+ // @ts-expect-error Presumed impossible if Strict extends false
172
171
  this.contents = null;
173
172
  return true;
174
173
  }
@@ -182,7 +181,7 @@ class Document {
182
181
  * `true` (collections are always returned intact).
183
182
  */
184
183
  get(key, keepScalar) {
185
- return Node.isCollection(this.contents)
184
+ return identity.isCollection(this.contents)
186
185
  ? this.contents.get(key, keepScalar)
187
186
  : undefined;
188
187
  }
@@ -193,10 +192,10 @@ class Document {
193
192
  */
194
193
  getIn(path, keepScalar) {
195
194
  if (Collection.isEmptyPath(path))
196
- return !keepScalar && Node.isScalar(this.contents)
195
+ return !keepScalar && identity.isScalar(this.contents)
197
196
  ? this.contents.value
198
197
  : this.contents;
199
- return Node.isCollection(this.contents)
198
+ return identity.isCollection(this.contents)
200
199
  ? this.contents.getIn(path, keepScalar)
201
200
  : undefined;
202
201
  }
@@ -204,7 +203,7 @@ class Document {
204
203
  * Checks if the document includes a value with the key `key`.
205
204
  */
206
205
  has(key) {
207
- return Node.isCollection(this.contents) ? this.contents.has(key) : false;
206
+ return identity.isCollection(this.contents) ? this.contents.has(key) : false;
208
207
  }
209
208
  /**
210
209
  * Checks if the document includes a value at `path`.
@@ -212,7 +211,7 @@ class Document {
212
211
  hasIn(path) {
213
212
  if (Collection.isEmptyPath(path))
214
213
  return this.contents !== undefined;
215
- return Node.isCollection(this.contents) ? this.contents.hasIn(path) : false;
214
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false;
216
215
  }
217
216
  /**
218
217
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -220,6 +219,7 @@ class Document {
220
219
  */
221
220
  set(key, value) {
222
221
  if (this.contents == null) {
222
+ // @ts-expect-error We can't really know that this matches Contents.
223
223
  this.contents = Collection.collectionFromPath(this.schema, [key], value);
224
224
  }
225
225
  else if (assertCollection(this.contents)) {
@@ -231,9 +231,12 @@ class Document {
231
231
  * boolean to add/remove the item from the set.
232
232
  */
233
233
  setIn(path, value) {
234
- if (Collection.isEmptyPath(path))
234
+ if (Collection.isEmptyPath(path)) {
235
+ // @ts-expect-error We can't really know that this matches Contents.
235
236
  this.contents = value;
237
+ }
236
238
  else if (this.contents == null) {
239
+ // @ts-expect-error We can't really know that this matches Contents.
237
240
  this.contents = Collection.collectionFromPath(this.schema, Array.from(path), value);
238
241
  }
239
242
  else if (assertCollection(this.contents)) {
@@ -293,8 +296,7 @@ class Document {
293
296
  keep: !json,
294
297
  mapAsMap: mapAsMap === true,
295
298
  mapKeyWarned: false,
296
- maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
297
- stringify: stringify.stringify
299
+ maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
298
300
  };
299
301
  const res = toJS.toJS(this.contents, jsonArg ?? '', ctx);
300
302
  if (typeof onAnchor === 'function')
@@ -326,7 +328,7 @@ class Document {
326
328
  }
327
329
  }
328
330
  function assertCollection(contents) {
329
- if (Node.isCollection(contents))
331
+ if (identity.isCollection(contents))
330
332
  return true;
331
333
  throw new Error('Expected a YAML collection as document contents');
332
334
  }
@@ -1,4 +1,4 @@
1
- import { Node } from '../nodes/Node.js';
1
+ import type { Node } from '../nodes/Node.js';
2
2
  import type { Document } from './Document.js';
3
3
  /**
4
4
  * Verify that the input string is a valid anchor.
@@ -6,10 +6,10 @@ import type { Document } from './Document.js';
6
6
  * Will throw on errors.
7
7
  */
8
8
  export declare function anchorIsValid(anchor: string): true;
9
- export declare function anchorNames(root: Document | Node): Set<string>;
9
+ export declare function anchorNames(root: Document<Node, boolean> | Node): Set<string>;
10
10
  /** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
11
11
  export declare function findNewAnchor(prefix: string, exclude: Set<string>): string;
12
- export declare function createNodeAnchors(doc: Document, prefix: string): {
12
+ export declare function createNodeAnchors(doc: Document<Node, boolean>, prefix: string): {
13
13
  onAnchor: (source: unknown) => string;
14
14
  /**
15
15
  * With circular references, the source node is only resolved after all
@@ -19,6 +19,6 @@ export declare function createNodeAnchors(doc: Document, prefix: string): {
19
19
  setAnchors: () => void;
20
20
  sourceObjects: Map<unknown, {
21
21
  anchor: string | null;
22
- node: Node<unknown> | null;
22
+ node: Node | null;
23
23
  }>;
24
24
  };
@@ -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 visit = require('../visit.js');
5
5
 
6
6
  /**
@@ -57,7 +57,7 @@ function createNodeAnchors(doc, prefix) {
57
57
  const ref = sourceObjects.get(source);
58
58
  if (typeof ref === 'object' &&
59
59
  ref.anchor &&
60
- (Node.isScalar(ref.node) || Node.isCollection(ref.node))) {
60
+ (identity.isScalar(ref.node) || identity.isCollection(ref.node))) {
61
61
  ref.node.anchor = ref.anchor;
62
62
  }
63
63
  else {
@@ -1,4 +1,4 @@
1
- import { Node } from '../nodes/Node.js';
1
+ import type { Node } from '../nodes/Node.js';
2
2
  import type { Schema } from '../schema/Schema.js';
3
3
  import type { CollectionTag, ScalarTag } from '../schema/types.js';
4
4
  import type { Replacer } from './Document.js';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var Alias = require('../nodes/Alias.js');
4
- var Node = require('../nodes/Node.js');
4
+ var identity = require('../nodes/identity.js');
5
5
  var Scalar = require('../nodes/Scalar.js');
6
6
 
7
7
  const defaultTagPrefix = 'tag:yaml.org,2002:';
@@ -16,12 +16,12 @@ function findTagObject(value, tagName, tags) {
16
16
  return tags.find(t => t.identify?.(value) && !t.format);
17
17
  }
18
18
  function createNode(value, tagName, ctx) {
19
- if (Node.isDocument(value))
19
+ if (identity.isDocument(value))
20
20
  value = value.contents;
21
- if (Node.isNode(value))
21
+ if (identity.isNode(value))
22
22
  return value;
23
- if (Node.isPair(value)) {
24
- const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx);
23
+ if (identity.isPair(value)) {
24
+ const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx);
25
25
  map.items.push(value);
26
26
  return map;
27
27
  }
@@ -65,10 +65,10 @@ function createNode(value, tagName, ctx) {
65
65
  }
66
66
  tagObj =
67
67
  value instanceof Map
68
- ? schema[Node.MAP]
68
+ ? schema[identity.MAP]
69
69
  : Symbol.iterator in Object(value)
70
- ? schema[Node.SEQ]
71
- : schema[Node.MAP];
70
+ ? schema[identity.SEQ]
71
+ : schema[identity.MAP];
72
72
  }
73
73
  if (onTagObj) {
74
74
  onTagObj(tagObj);
@@ -76,9 +76,13 @@ function createNode(value, tagName, ctx) {
76
76
  }
77
77
  const node = tagObj?.createNode
78
78
  ? tagObj.createNode(ctx.schema, value, ctx)
79
- : new Scalar.Scalar(value);
79
+ : typeof tagObj?.nodeClass?.from === 'function'
80
+ ? tagObj.nodeClass.from(ctx.schema, value, ctx)
81
+ : new Scalar.Scalar(value);
80
82
  if (tagName)
81
83
  node.tag = tagName;
84
+ else if (!tagObj.default)
85
+ node.tag = tagObj.tag;
82
86
  if (ref)
83
87
  ref.node = node;
84
88
  return node;
@@ -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 visit = require('../visit.js');
5
5
 
6
6
  const escapeChars = {
@@ -146,10 +146,10 @@ class Directives {
146
146
  : [];
147
147
  const tagEntries = Object.entries(this.tags);
148
148
  let tagNames;
149
- if (doc && tagEntries.length > 0 && Node.isNode(doc.contents)) {
149
+ if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) {
150
150
  const tags = {};
151
151
  visit.visit(doc.contents, (_key, node) => {
152
- if (Node.isNode(node) && node.tag)
152
+ if (identity.isNode(node) && node.tag)
153
153
  tags[node.tag] = true;
154
154
  });
155
155
  tagNames = Object.keys(tags);
@@ -1,5 +1,5 @@
1
1
  import type { LineCounter } from './parse/line-counter';
2
- export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN';
2
+ export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
3
3
  export type LinePos = {
4
4
  line: number;
5
5
  col: number;
@@ -3,7 +3,8 @@ export { Document } from './doc/Document.js';
3
3
  export { Schema } from './schema/Schema.js';
4
4
  export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
5
5
  export { Alias } from './nodes/Alias.js';
6
- export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.js';
6
+ export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js';
7
+ export { Node, ParsedNode, Range } from './nodes/Node.js';
7
8
  export { Pair } from './nodes/Pair.js';
8
9
  export { Scalar } from './nodes/Scalar.js';
9
10
  export { YAMLMap } from './nodes/YAMLMap.js';
@@ -5,7 +5,7 @@ var Document = require('./doc/Document.js');
5
5
  var Schema = require('./schema/Schema.js');
6
6
  var errors = require('./errors.js');
7
7
  var Alias = require('./nodes/Alias.js');
8
- var Node = require('./nodes/Node.js');
8
+ var identity = require('./nodes/identity.js');
9
9
  var Pair = require('./nodes/Pair.js');
10
10
  var Scalar = require('./nodes/Scalar.js');
11
11
  var YAMLMap = require('./nodes/YAMLMap.js');
@@ -26,14 +26,14 @@ exports.YAMLError = errors.YAMLError;
26
26
  exports.YAMLParseError = errors.YAMLParseError;
27
27
  exports.YAMLWarning = errors.YAMLWarning;
28
28
  exports.Alias = Alias.Alias;
29
- exports.isAlias = Node.isAlias;
30
- exports.isCollection = Node.isCollection;
31
- exports.isDocument = Node.isDocument;
32
- exports.isMap = Node.isMap;
33
- exports.isNode = Node.isNode;
34
- exports.isPair = Node.isPair;
35
- exports.isScalar = Node.isScalar;
36
- exports.isSeq = Node.isSeq;
29
+ exports.isAlias = identity.isAlias;
30
+ exports.isCollection = identity.isCollection;
31
+ exports.isDocument = identity.isDocument;
32
+ exports.isMap = identity.isMap;
33
+ exports.isNode = identity.isNode;
34
+ exports.isPair = identity.isPair;
35
+ exports.isScalar = identity.isScalar;
36
+ exports.isSeq = identity.isSeq;
37
37
  exports.Pair = Pair.Pair;
38
38
  exports.Scalar = Scalar.Scalar;
39
39
  exports.YAMLMap = YAMLMap.YAMLMap;
@@ -3,7 +3,7 @@ import type { FlowScalar } from '../parse/cst.js';
3
3
  import type { StringifyContext } from '../stringify/stringify.js';
4
4
  import { NodeBase, Range } from './Node.js';
5
5
  import type { Scalar } from './Scalar';
6
- import type { ToJSContext } from './toJS.js';
6
+ import { ToJSContext } from './toJS.js';
7
7
  import type { YAMLMap } from './YAMLMap.js';
8
8
  import type { YAMLSeq } from './YAMLSeq.js';
9
9
  export declare namespace Alias {
@@ -2,11 +2,13 @@
2
2
 
3
3
  var anchors = require('../doc/anchors.js');
4
4
  var visit = require('../visit.js');
5
+ var identity = require('./identity.js');
5
6
  var Node = require('./Node.js');
7
+ var toJS = require('./toJS.js');
6
8
 
7
9
  class Alias extends Node.NodeBase {
8
10
  constructor(source) {
9
- super(Node.ALIAS);
11
+ super(identity.ALIAS);
10
12
  this.source = source;
11
13
  Object.defineProperty(this, 'tag', {
12
14
  set() {
@@ -39,7 +41,12 @@ class Alias extends Node.NodeBase {
39
41
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
40
42
  throw new ReferenceError(msg);
41
43
  }
42
- const data = anchors.get(source);
44
+ let data = anchors.get(source);
45
+ if (!data) {
46
+ // Resolve anchors for Node.prototype.toJS()
47
+ toJS.toJS(source, null, ctx);
48
+ data = anchors.get(source);
49
+ }
43
50
  /* istanbul ignore if */
44
51
  if (!data || data.res === undefined) {
45
52
  const msg = 'This should not happen: Alias anchor was not resolved?';
@@ -71,12 +78,12 @@ class Alias extends Node.NodeBase {
71
78
  }
72
79
  }
73
80
  function getAliasCount(doc, node, anchors) {
74
- if (Node.isAlias(node)) {
81
+ if (identity.isAlias(node)) {
75
82
  const source = node.resolve(doc);
76
83
  const anchor = anchors && source && anchors.get(source);
77
84
  return anchor ? anchor.count * anchor.aliasCount : 0;
78
85
  }
79
- else if (Node.isCollection(node)) {
86
+ else if (identity.isCollection(node)) {
80
87
  let count = 0;
81
88
  for (const item of node.items) {
82
89
  const c = getAliasCount(doc, item, anchors);
@@ -85,7 +92,7 @@ function getAliasCount(doc, node, anchors) {
85
92
  }
86
93
  return count;
87
94
  }
88
- else if (Node.isPair(node)) {
95
+ else if (identity.isPair(node)) {
89
96
  const kc = getAliasCount(doc, node.key, anchors);
90
97
  const vc = getAliasCount(doc, node.value, anchors);
91
98
  return Math.max(kc, vc);
@@ -1,6 +1,7 @@
1
1
  import type { Schema } from '../schema/Schema.js';
2
- import { NodeBase, NODE_TYPE } from './Node.js';
3
- export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node<unknown>;
2
+ import { NODE_TYPE } from './identity.js';
3
+ import { NodeBase } from './Node.js';
4
+ export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node;
4
5
  export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
5
6
  export declare abstract class Collection extends NodeBase {
6
7
  static maxFlowStringSingleLineLength: number;
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var createNode = require('../doc/createNode.js');
4
+ var identity = require('./identity.js');
4
5
  var Node = require('./Node.js');
5
6
 
6
7
  function collectionFromPath(schema, path, value) {
@@ -49,7 +50,7 @@ class Collection extends Node.NodeBase {
49
50
  const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
50
51
  if (schema)
51
52
  copy.schema = schema;
52
- copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it);
53
+ copy.items = copy.items.map(it => identity.isNode(it) || identity.isPair(it) ? it.clone(schema) : it);
53
54
  if (this.range)
54
55
  copy.range = this.range.slice();
55
56
  return copy;
@@ -65,7 +66,7 @@ class Collection extends Node.NodeBase {
65
66
  else {
66
67
  const [key, ...rest] = path;
67
68
  const node = this.get(key, true);
68
- if (Node.isCollection(node))
69
+ if (identity.isCollection(node))
69
70
  node.addIn(rest, value);
70
71
  else if (node === undefined && this.schema)
71
72
  this.set(key, collectionFromPath(this.schema, rest, value));
@@ -82,7 +83,7 @@ class Collection extends Node.NodeBase {
82
83
  if (rest.length === 0)
83
84
  return this.delete(key);
84
85
  const node = this.get(key, true);
85
- if (Node.isCollection(node))
86
+ if (identity.isCollection(node))
86
87
  return node.deleteIn(rest);
87
88
  else
88
89
  throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
@@ -96,18 +97,18 @@ class Collection extends Node.NodeBase {
96
97
  const [key, ...rest] = path;
97
98
  const node = this.get(key, true);
98
99
  if (rest.length === 0)
99
- return !keepScalar && Node.isScalar(node) ? node.value : node;
100
+ return !keepScalar && identity.isScalar(node) ? node.value : node;
100
101
  else
101
- return Node.isCollection(node) ? node.getIn(rest, keepScalar) : undefined;
102
+ return identity.isCollection(node) ? node.getIn(rest, keepScalar) : undefined;
102
103
  }
103
104
  hasAllNullValues(allowScalar) {
104
105
  return this.items.every(node => {
105
- if (!Node.isPair(node))
106
+ if (!identity.isPair(node))
106
107
  return false;
107
108
  const n = node.value;
108
109
  return (n == null ||
109
110
  (allowScalar &&
110
- Node.isScalar(n) &&
111
+ identity.isScalar(n) &&
111
112
  n.value == null &&
112
113
  !n.commentBefore &&
113
114
  !n.comment &&
@@ -122,7 +123,7 @@ class Collection extends Node.NodeBase {
122
123
  if (rest.length === 0)
123
124
  return this.has(key);
124
125
  const node = this.get(key, true);
125
- return Node.isCollection(node) ? node.hasIn(rest) : false;
126
+ return identity.isCollection(node) ? node.hasIn(rest) : false;
126
127
  }
127
128
  /**
128
129
  * Sets a value in this collection. For `!!set`, `value` needs to be a
@@ -135,7 +136,7 @@ class Collection extends Node.NodeBase {
135
136
  }
136
137
  else {
137
138
  const node = this.get(key, true);
138
- if (Node.isCollection(node))
139
+ if (identity.isCollection(node))
139
140
  node.setIn(rest, value);
140
141
  else if (node === undefined && this.schema)
141
142
  this.set(key, collectionFromPath(this.schema, rest, value));
@@ -1,36 +1,21 @@
1
1
  import type { Document } from '../doc/Document.js';
2
+ import type { ToJSOptions } from '../options.js';
2
3
  import { Token } from '../parse/cst.js';
3
4
  import type { StringifyContext } from '../stringify/stringify.js';
4
5
  import type { Alias } from './Alias.js';
5
- import type { Pair } from './Pair.js';
6
+ import { NODE_TYPE } from './identity.js';
6
7
  import type { Scalar } from './Scalar.js';
7
8
  import type { YAMLMap } from './YAMLMap.js';
8
9
  import type { YAMLSeq } from './YAMLSeq.js';
9
10
  export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
10
11
  /** 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
+ export type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
12
13
  [key: string]: any;
13
14
  } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
14
15
  [key: number]: any;
15
16
  } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
16
17
  export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
17
18
  export type Range = [number, number, number];
18
- export declare const ALIAS: unique symbol;
19
- export declare const DOC: unique symbol;
20
- export declare const MAP: unique symbol;
21
- export declare const PAIR: unique symbol;
22
- export declare const SCALAR: unique symbol;
23
- export declare const SEQ: unique symbol;
24
- export declare const NODE_TYPE: unique symbol;
25
- export declare const isAlias: (node: any) => node is Alias;
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>;
34
19
  export declare abstract class NodeBase {
35
20
  readonly [NODE_TYPE]: symbol;
36
21
  /** A comment on or immediately after this */
@@ -56,4 +41,6 @@ export declare abstract class NodeBase {
56
41
  constructor(type: symbol);
57
42
  /** Create a copy of this node. */
58
43
  clone(): NodeBase;
44
+ /** A plain JavaScript representation of this node. */
45
+ toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any;
59
46
  }