projen 0.71.67 → 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 (243) hide show
  1. package/.jsii +24 -6
  2. package/docs/api/API.md +2 -0
  3. package/lib/awscdk/auto-discover.js +5 -5
  4. package/lib/awscdk/awscdk-app-java.js +1 -1
  5. package/lib/awscdk/awscdk-app-py.js +1 -1
  6. package/lib/awscdk/awscdk-app-ts.js +1 -1
  7. package/lib/awscdk/awscdk-construct.js +2 -2
  8. package/lib/awscdk/awscdk-deps-java.js +1 -1
  9. package/lib/awscdk/awscdk-deps-js.js +1 -1
  10. package/lib/awscdk/awscdk-deps-py.js +1 -1
  11. package/lib/awscdk/awscdk-deps.js +1 -1
  12. package/lib/awscdk/cdk-config.js +1 -1
  13. package/lib/awscdk/cdk-tasks.js +1 -1
  14. package/lib/awscdk/integration-test.js +1 -1
  15. package/lib/awscdk/lambda-extension.js +1 -1
  16. package/lib/awscdk/lambda-function.js +2 -2
  17. package/lib/build/build-workflow.js +1 -1
  18. package/lib/cdk/auto-discover-base.js +2 -2
  19. package/lib/cdk/construct-lib.js +1 -1
  20. package/lib/cdk/integration-test-base.js +1 -1
  21. package/lib/cdk/jsii-docgen.js +1 -1
  22. package/lib/cdk/jsii-project.js +1 -1
  23. package/lib/cdk8s/auto-discover.js +2 -2
  24. package/lib/cdk8s/cdk8s-app-py.js +1 -1
  25. package/lib/cdk8s/cdk8s-app-ts.js +1 -1
  26. package/lib/cdk8s/cdk8s-construct.js +1 -1
  27. package/lib/cdk8s/cdk8s-deps-py.js +1 -1
  28. package/lib/cdk8s/cdk8s-deps.js +1 -1
  29. package/lib/cdk8s/integration-test.js +1 -1
  30. package/lib/cdktf/cdktf-construct.js +1 -1
  31. package/lib/circleci/circleci.js +1 -1
  32. package/lib/component.js +1 -1
  33. package/lib/dependencies.js +1 -1
  34. package/lib/dev-env.js +1 -1
  35. package/lib/docker-compose/docker-compose-service.js +1 -1
  36. package/lib/docker-compose/docker-compose.js +1 -1
  37. package/lib/file.js +1 -1
  38. package/lib/gitattributes.js +1 -1
  39. package/lib/github/actions-provider.js +1 -1
  40. package/lib/github/auto-approve.js +1 -1
  41. package/lib/github/auto-merge.js +1 -1
  42. package/lib/github/dependabot.js +1 -1
  43. package/lib/github/github-credentials.js +1 -1
  44. package/lib/github/github-project.js +1 -1
  45. package/lib/github/github.js +1 -1
  46. package/lib/github/mergify.js +1 -1
  47. package/lib/github/pr-template.js +1 -1
  48. package/lib/github/pull-request-lint.js +1 -1
  49. package/lib/github/stale.js +1 -1
  50. package/lib/github/task-workflow.js +1 -1
  51. package/lib/github/workflow-actions.js +1 -1
  52. package/lib/github/workflow-jobs.js +1 -1
  53. package/lib/github/workflows.js +1 -1
  54. package/lib/gitlab/configuration.js +1 -1
  55. package/lib/gitlab/gitlab-configuration.js +1 -1
  56. package/lib/gitlab/nested-configuration.js +1 -1
  57. package/lib/gitpod.js +1 -1
  58. package/lib/ignore-file.js +1 -1
  59. package/lib/ini.js +1 -1
  60. package/lib/java/java-project.js +1 -1
  61. package/lib/java/junit.js +1 -1
  62. package/lib/java/maven-compile.js +1 -1
  63. package/lib/java/maven-packaging.js +1 -1
  64. package/lib/java/maven-sample.js +1 -1
  65. package/lib/java/pom.js +1 -1
  66. package/lib/java/projenrc.js +1 -1
  67. package/lib/javascript/bundler.js +1 -1
  68. package/lib/javascript/eslint.js +1 -1
  69. package/lib/javascript/jest.js +4 -4
  70. package/lib/javascript/node-package.js +1 -1
  71. package/lib/javascript/node-project.js +1 -1
  72. package/lib/javascript/npm-config.js +1 -1
  73. package/lib/javascript/prettier.js +1 -1
  74. package/lib/javascript/projenrc.js +1 -1
  75. package/lib/javascript/typescript-config.js +2 -2
  76. package/lib/javascript/upgrade-dependencies.js +2 -2
  77. package/lib/json-patch.js +1 -1
  78. package/lib/json.js +1 -1
  79. package/lib/license.js +1 -1
  80. package/lib/logger.js +1 -1
  81. package/lib/makefile.js +1 -1
  82. package/lib/object-file.js +1 -1
  83. package/lib/project-build.js +1 -1
  84. package/lib/project.js +1 -1
  85. package/lib/projects.js +1 -1
  86. package/lib/projenrc-json.js +2 -2
  87. package/lib/projenrc.js +1 -1
  88. package/lib/python/pip.js +1 -1
  89. package/lib/python/poetry.js +2 -2
  90. package/lib/python/projenrc.js +1 -1
  91. package/lib/python/pytest-sample.js +1 -1
  92. package/lib/python/pytest.js +1 -1
  93. package/lib/python/python-project.js +1 -1
  94. package/lib/python/python-sample.js +1 -1
  95. package/lib/python/requirements-file.js +1 -1
  96. package/lib/python/setuppy.js +1 -1
  97. package/lib/python/setuptools.js +1 -1
  98. package/lib/python/venv.js +1 -1
  99. package/lib/readme.js +1 -1
  100. package/lib/release/publisher.js +1 -1
  101. package/lib/release/release-trigger.js +1 -1
  102. package/lib/release/release.js +1 -1
  103. package/lib/renovatebot.js +1 -1
  104. package/lib/run-task.js +1889 -0
  105. package/lib/sample-file.js +2 -2
  106. package/lib/semver.js +1 -1
  107. package/lib/source-code.js +1 -1
  108. package/lib/task-runtime.js +1 -1
  109. package/lib/task.js +1 -1
  110. package/lib/tasks.js +1 -1
  111. package/lib/testing.js +1 -1
  112. package/lib/textfile.js +1 -1
  113. package/lib/toml.js +1 -1
  114. package/lib/typescript/projenrc-ts.js +1 -1
  115. package/lib/typescript/projenrc.d.ts +8 -0
  116. package/lib/typescript/projenrc.js +14 -5
  117. package/lib/typescript/typescript-typedoc.js +1 -1
  118. package/lib/typescript/typescript.js +3 -3
  119. package/lib/version.js +1 -1
  120. package/lib/vscode/devcontainer.js +1 -1
  121. package/lib/vscode/extensions.js +1 -1
  122. package/lib/vscode/launch-config.js +1 -1
  123. package/lib/vscode/settings.js +1 -1
  124. package/lib/vscode/vscode.js +1 -1
  125. package/lib/web/next.js +3 -3
  126. package/lib/web/postcss.js +1 -1
  127. package/lib/web/react.js +4 -4
  128. package/lib/web/tailwind.js +1 -1
  129. package/lib/xmlfile.js +1 -1
  130. package/lib/yaml.js +1 -1
  131. package/node_modules/yaml/README.md +4 -0
  132. package/node_modules/yaml/browser/dist/compose/compose-collection.js +46 -29
  133. package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -0
  134. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +1 -1
  135. package/node_modules/yaml/browser/dist/compose/composer.js +1 -1
  136. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +3 -2
  137. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +3 -2
  138. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +4 -5
  139. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +1 -1
  140. package/node_modules/yaml/browser/dist/doc/Document.js +12 -10
  141. package/node_modules/yaml/browser/dist/doc/anchors.js +1 -1
  142. package/node_modules/yaml/browser/dist/doc/createNode.js +6 -2
  143. package/node_modules/yaml/browser/dist/doc/directives.js +1 -1
  144. package/node_modules/yaml/browser/dist/index.js +1 -1
  145. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +6 -149
  146. package/node_modules/yaml/browser/dist/nodes/Alias.js +9 -2
  147. package/node_modules/yaml/browser/dist/nodes/Collection.js +2 -1
  148. package/node_modules/yaml/browser/dist/nodes/Node.js +25 -35
  149. package/node_modules/yaml/browser/dist/nodes/Pair.js +1 -1
  150. package/node_modules/yaml/browser/dist/nodes/Scalar.js +2 -1
  151. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +30 -2
  152. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +17 -1
  153. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +1 -1
  154. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  155. package/node_modules/yaml/browser/dist/nodes/toJS.js +1 -1
  156. package/node_modules/yaml/browser/dist/schema/Schema.js +1 -1
  157. package/node_modules/yaml/browser/dist/schema/common/map.js +3 -28
  158. package/node_modules/yaml/browser/dist/schema/common/seq.js +3 -19
  159. package/node_modules/yaml/browser/dist/schema/tags.js +1 -1
  160. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +9 -8
  161. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  162. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +14 -13
  163. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +1 -1
  164. package/node_modules/yaml/browser/dist/stringify/stringify.js +1 -1
  165. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +1 -1
  166. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +1 -1
  167. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
  168. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +10 -1
  169. package/node_modules/yaml/browser/dist/util.js +2 -0
  170. package/node_modules/yaml/browser/dist/visit.js +1 -1
  171. package/node_modules/yaml/dist/compose/compose-collection.d.ts +1 -1
  172. package/node_modules/yaml/dist/compose/compose-collection.js +47 -30
  173. package/node_modules/yaml/dist/compose/compose-doc.d.ts +2 -1
  174. package/node_modules/yaml/dist/compose/compose-doc.js +1 -0
  175. package/node_modules/yaml/dist/compose/compose-scalar.js +7 -7
  176. package/node_modules/yaml/dist/compose/composer.d.ts +5 -5
  177. package/node_modules/yaml/dist/compose/composer.js +3 -3
  178. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +2 -1
  179. package/node_modules/yaml/dist/compose/resolve-block-map.js +3 -2
  180. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +2 -1
  181. package/node_modules/yaml/dist/compose/resolve-block-seq.js +3 -2
  182. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +2 -1
  183. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +5 -6
  184. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +3 -3
  185. package/node_modules/yaml/dist/compose/util-map-includes.js +3 -3
  186. package/node_modules/yaml/dist/doc/Document.d.ts +11 -9
  187. package/node_modules/yaml/dist/doc/Document.js +22 -20
  188. package/node_modules/yaml/dist/doc/anchors.d.ts +4 -4
  189. package/node_modules/yaml/dist/doc/anchors.js +2 -2
  190. package/node_modules/yaml/dist/doc/createNode.d.ts +1 -1
  191. package/node_modules/yaml/dist/doc/createNode.js +13 -9
  192. package/node_modules/yaml/dist/doc/directives.js +3 -3
  193. package/node_modules/yaml/dist/errors.d.ts +1 -1
  194. package/node_modules/yaml/dist/index.d.ts +2 -1
  195. package/node_modules/yaml/dist/index.js +9 -9
  196. package/node_modules/yaml/dist/nodes/Alias.d.ts +1 -1
  197. package/node_modules/yaml/dist/nodes/Alias.js +12 -5
  198. package/node_modules/yaml/dist/nodes/Collection.d.ts +3 -2
  199. package/node_modules/yaml/dist/nodes/Collection.js +10 -9
  200. package/node_modules/yaml/dist/nodes/Node.d.ts +5 -18
  201. package/node_modules/yaml/dist/nodes/Node.js +25 -51
  202. package/node_modules/yaml/dist/nodes/Pair.d.ts +2 -2
  203. package/node_modules/yaml/dist/nodes/Pair.js +4 -4
  204. package/node_modules/yaml/dist/nodes/Scalar.js +2 -1
  205. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +7 -1
  206. package/node_modules/yaml/dist/nodes/YAMLMap.js +37 -9
  207. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +3 -1
  208. package/node_modules/yaml/dist/nodes/YAMLSeq.js +21 -5
  209. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +7 -7
  210. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  211. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  212. package/node_modules/yaml/dist/nodes/toJS.d.ts +2 -5
  213. package/node_modules/yaml/dist/nodes/toJS.js +2 -2
  214. package/node_modules/yaml/dist/public-api.d.ts +3 -3
  215. package/node_modules/yaml/dist/schema/Schema.d.ts +1 -1
  216. package/node_modules/yaml/dist/schema/Schema.js +4 -4
  217. package/node_modules/yaml/dist/schema/common/map.js +4 -29
  218. package/node_modules/yaml/dist/schema/common/seq.js +4 -20
  219. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -1
  220. package/node_modules/yaml/dist/schema/json/schema.d.ts +1 -1
  221. package/node_modules/yaml/dist/schema/tags.d.ts +1 -1
  222. package/node_modules/yaml/dist/schema/types.d.ts +11 -3
  223. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +4 -1
  224. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +11 -10
  225. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +1 -1
  226. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +5 -5
  227. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -1
  228. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +3 -1
  229. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +17 -16
  230. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +1 -1
  231. package/node_modules/yaml/dist/stringify/stringify.js +8 -8
  232. package/node_modules/yaml/dist/stringify/stringifyCollection.js +8 -8
  233. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -3
  234. package/node_modules/yaml/dist/stringify/stringifyDocument.js +2 -2
  235. package/node_modules/yaml/dist/stringify/stringifyPair.js +9 -9
  236. package/node_modules/yaml/dist/stringify/stringifyString.js +10 -1
  237. package/node_modules/yaml/dist/test-events.js +8 -8
  238. package/node_modules/yaml/dist/util.d.ts +4 -1
  239. package/node_modules/yaml/dist/util.js +4 -0
  240. package/node_modules/yaml/dist/visit.js +18 -18
  241. package/node_modules/yaml/package.json +8 -6
  242. package/package.json +3 -3
  243. package/node_modules/yaml/util.d.ts +0 -3
@@ -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
  }
@@ -1,42 +1,12 @@
1
1
  'use strict';
2
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;
3
+ var applyReviver = require('../doc/applyReviver.js');
4
+ var identity = require('./identity.js');
5
+ var toJS = require('./toJS.js');
6
+
37
7
  class NodeBase {
38
8
  constructor(type) {
39
- Object.defineProperty(this, NODE_TYPE, { value: type });
9
+ Object.defineProperty(this, identity.NODE_TYPE, { value: type });
40
10
  }
41
11
  /** Create a copy of this node. */
42
12
  clone() {
@@ -45,22 +15,26 @@ class NodeBase {
45
15
  copy.range = this.range.slice();
46
16
  return copy;
47
17
  }
18
+ /** A plain JavaScript representation of this node. */
19
+ toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
20
+ if (!identity.isDocument(doc))
21
+ throw new TypeError('A document argument is required');
22
+ const ctx = {
23
+ anchors: new Map(),
24
+ doc,
25
+ keep: true,
26
+ mapAsMap: mapAsMap === true,
27
+ mapKeyWarned: false,
28
+ maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
29
+ };
30
+ const res = toJS.toJS(this, '', ctx);
31
+ if (typeof onAnchor === 'function')
32
+ for (const { count, res } of ctx.anchors.values())
33
+ onAnchor(res, count);
34
+ return typeof reviver === 'function'
35
+ ? applyReviver.applyReviver(reviver, { '': res }, '', res)
36
+ : res;
37
+ }
48
38
  }
49
39
 
50
- exports.ALIAS = ALIAS;
51
- exports.DOC = DOC;
52
- exports.MAP = MAP;
53
- exports.NODE_TYPE = NODE_TYPE;
54
40
  exports.NodeBase = NodeBase;
55
- exports.PAIR = PAIR;
56
- exports.SCALAR = SCALAR;
57
- exports.SEQ = SEQ;
58
- exports.hasAnchor = hasAnchor;
59
- exports.isAlias = isAlias;
60
- exports.isCollection = isCollection;
61
- exports.isDocument = isDocument;
62
- exports.isMap = isMap;
63
- exports.isNode = isNode;
64
- exports.isPair = isPair;
65
- exports.isScalar = isScalar;
66
- exports.isSeq = isSeq;
@@ -3,9 +3,9 @@ import type { CollectionItem } from '../parse/cst.js';
3
3
  import type { Schema } from '../schema/Schema.js';
4
4
  import type { StringifyContext } from '../stringify/stringify.js';
5
5
  import { addPairToJSMap } from './addPairToJSMap.js';
6
- import { NODE_TYPE } from './Node.js';
6
+ import { NODE_TYPE } from './identity.js';
7
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>>;
8
+ export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./Scalar.js").Scalar<unknown> | import("./Alias.js").Alias | import("./YAMLSeq.js").YAMLSeq<unknown>>;
9
9
  export declare class Pair<K = unknown, V = unknown> {
10
10
  readonly [NODE_TYPE]: symbol;
11
11
  /** Always Node or null when parsed, but can be set to anything. */
@@ -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>;