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
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const ALIAS = Symbol.for('yaml.alias');
4
+ const DOC = Symbol.for('yaml.document');
5
+ const MAP = Symbol.for('yaml.map');
6
+ const PAIR = Symbol.for('yaml.pair');
7
+ const SCALAR = Symbol.for('yaml.scalar');
8
+ const SEQ = Symbol.for('yaml.seq');
9
+ const NODE_TYPE = Symbol.for('yaml.node.type');
10
+ const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
11
+ const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
12
+ const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
13
+ const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
14
+ const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
15
+ const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
16
+ function isCollection(node) {
17
+ if (node && typeof node === 'object')
18
+ switch (node[NODE_TYPE]) {
19
+ case MAP:
20
+ case SEQ:
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ function isNode(node) {
26
+ if (node && typeof node === 'object')
27
+ switch (node[NODE_TYPE]) {
28
+ case ALIAS:
29
+ case MAP:
30
+ case SCALAR:
31
+ case SEQ:
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
37
+
38
+ exports.ALIAS = ALIAS;
39
+ exports.DOC = DOC;
40
+ exports.MAP = MAP;
41
+ exports.NODE_TYPE = NODE_TYPE;
42
+ exports.PAIR = PAIR;
43
+ exports.SCALAR = SCALAR;
44
+ exports.SEQ = SEQ;
45
+ exports.hasAnchor = hasAnchor;
46
+ exports.isAlias = isAlias;
47
+ exports.isCollection = isCollection;
48
+ exports.isDocument = isDocument;
49
+ exports.isMap = isMap;
50
+ exports.isNode = isNode;
51
+ exports.isPair = isPair;
52
+ exports.isScalar = isScalar;
53
+ exports.isSeq = isSeq;
@@ -1,6 +1,5 @@
1
1
  import type { Document } from '../doc/Document.js';
2
- import type { stringify } from '../stringify/stringify.js';
3
- import { Node } from './Node.js';
2
+ import type { Node } from './Node.js';
4
3
  export interface AnchorData {
5
4
  aliasCount: number;
6
5
  count: number;
@@ -8,14 +7,12 @@ export interface AnchorData {
8
7
  }
9
8
  export interface ToJSContext {
10
9
  anchors: Map<Node, AnchorData>;
11
- doc: Document;
10
+ doc: Document<Node, boolean>;
12
11
  keep: boolean;
13
12
  mapAsMap: boolean;
14
13
  mapKeyWarned: boolean;
15
14
  maxAliasCount: number;
16
15
  onCreate?: (res: unknown) => void;
17
- /** Requiring this directly in Pair would create circular dependencies */
18
- stringify: typeof stringify;
19
16
  }
20
17
  /**
21
18
  * Recursively convert any node or its contents to native JavaScript
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('./Node.js');
3
+ var identity = require('./identity.js');
4
4
 
5
5
  /**
6
6
  * Recursively convert any node or its contents to native JavaScript
@@ -18,7 +18,7 @@ function toJS(value, arg, ctx) {
18
18
  return value.map((v, i) => toJS(v, String(i), ctx));
19
19
  if (value && typeof value.toJSON === 'function') {
20
20
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
21
- if (!ctx || !Node.hasAnchor(value))
21
+ if (!ctx || !identity.hasAnchor(value))
22
22
  return value.toJSON(arg, ctx);
23
23
  const data = { aliasCount: 0, count: 1, res: undefined };
24
24
  ctx.anchors.set(value, data);
@@ -1,7 +1,7 @@
1
1
  import { Composer } from './compose/composer.js';
2
2
  import type { Reviver } from './doc/applyReviver.js';
3
3
  import { Document, Replacer } from './doc/Document.js';
4
- import type { ParsedNode } from './nodes/Node.js';
4
+ import type { Node, ParsedNode } from './nodes/Node.js';
5
5
  import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
6
6
  export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
7
7
  empty: true;
@@ -15,9 +15,9 @@ export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer
15
15
  * EmptyStream and contain additional stream information. In
16
16
  * TypeScript, you should use `'empty' in docs` as a type guard for it.
17
17
  */
18
- export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
18
+ export declare function parseAllDocuments<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Array<Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>> | EmptyStream;
19
19
  /** Parse an input string into a single YAML.Document */
20
- export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
20
+ export declare function parseDocument<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>;
21
21
  /**
22
22
  * Parse an input string into JavaScript.
23
23
  *
@@ -1,4 +1,4 @@
1
- import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
1
+ import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
2
2
  import type { Pair } from '../nodes/Pair.js';
3
3
  import type { SchemaOptions, ToStringOptions } from '../options.js';
4
4
  import type { CollectionTag, ScalarTag } from './types.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var map = require('./common/map.js');
5
5
  var seq = require('./common/seq.js');
6
6
  var string = require('./common/string.js');
@@ -19,9 +19,9 @@ class Schema {
19
19
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
20
20
  this.tags = tags.getTags(customTags, this.name);
21
21
  this.toStringOptions = toStringDefaults ?? null;
22
- Object.defineProperty(this, Node.MAP, { value: map.map });
23
- Object.defineProperty(this, Node.SCALAR, { value: string.string });
24
- Object.defineProperty(this, Node.SEQ, { value: seq.seq });
22
+ Object.defineProperty(this, identity.MAP, { value: map.map });
23
+ Object.defineProperty(this, identity.SCALAR, { value: string.string });
24
+ Object.defineProperty(this, identity.SEQ, { value: seq.seq });
25
25
  // Used by createMap()
26
26
  this.sortMapEntries =
27
27
  typeof sortMapEntries === 'function'
@@ -1,44 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../../nodes/Node.js');
4
- var Pair = require('../../nodes/Pair.js');
3
+ var identity = require('../../nodes/identity.js');
5
4
  var YAMLMap = require('../../nodes/YAMLMap.js');
6
5
 
7
- function createMap(schema, obj, ctx) {
8
- const { keepUndefined, replacer } = ctx;
9
- const map = new YAMLMap.YAMLMap(schema);
10
- const add = (key, value) => {
11
- if (typeof replacer === 'function')
12
- value = replacer.call(obj, key, value);
13
- else if (Array.isArray(replacer) && !replacer.includes(key))
14
- return;
15
- if (value !== undefined || keepUndefined)
16
- map.items.push(Pair.createPair(key, value, ctx));
17
- };
18
- if (obj instanceof Map) {
19
- for (const [key, value] of obj)
20
- add(key, value);
21
- }
22
- else if (obj && typeof obj === 'object') {
23
- for (const key of Object.keys(obj))
24
- add(key, obj[key]);
25
- }
26
- if (typeof schema.sortMapEntries === 'function') {
27
- map.items.sort(schema.sortMapEntries);
28
- }
29
- return map;
30
- }
31
6
  const map = {
32
7
  collection: 'map',
33
- createNode: createMap,
34
8
  default: true,
35
9
  nodeClass: YAMLMap.YAMLMap,
36
10
  tag: 'tag:yaml.org,2002:map',
37
11
  resolve(map, onError) {
38
- if (!Node.isMap(map))
12
+ if (!identity.isMap(map))
39
13
  onError('Expected a mapping for this tag');
40
14
  return map;
41
- }
15
+ },
16
+ createNode: (schema, obj, ctx) => YAMLMap.YAMLMap.from(schema, obj, ctx)
42
17
  };
43
18
 
44
19
  exports.map = map;
@@ -1,35 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var createNode = require('../../doc/createNode.js');
4
- var Node = require('../../nodes/Node.js');
3
+ var identity = require('../../nodes/identity.js');
5
4
  var YAMLSeq = require('../../nodes/YAMLSeq.js');
6
5
 
7
- function createSeq(schema, obj, ctx) {
8
- const { replacer } = ctx;
9
- const seq = new YAMLSeq.YAMLSeq(schema);
10
- if (obj && Symbol.iterator in Object(obj)) {
11
- let i = 0;
12
- for (let it of obj) {
13
- if (typeof replacer === 'function') {
14
- const key = obj instanceof Set ? it : String(i++);
15
- it = replacer.call(obj, key, it);
16
- }
17
- seq.items.push(createNode.createNode(it, undefined, ctx));
18
- }
19
- }
20
- return seq;
21
- }
22
6
  const seq = {
23
7
  collection: 'seq',
24
- createNode: createSeq,
25
8
  default: true,
26
9
  nodeClass: YAMLSeq.YAMLSeq,
27
10
  tag: 'tag:yaml.org,2002:seq',
28
11
  resolve(seq, onError) {
29
- if (!Node.isSeq(seq))
12
+ if (!identity.isSeq(seq))
30
13
  onError('Expected a sequence for this tag');
31
14
  return seq;
32
- }
15
+ },
16
+ createNode: (schema, obj, ctx) => YAMLSeq.YAMLSeq.from(schema, obj, ctx)
33
17
  };
34
18
 
35
19
  exports.seq = seq;
@@ -1 +1 @@
1
- export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
1
+ export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
@@ -1,2 +1,2 @@
1
1
  import { CollectionTag, ScalarTag } from '../types.js';
2
- export declare const schema: (ScalarTag | CollectionTag)[];
2
+ export declare const schema: (CollectionTag | ScalarTag)[];
@@ -36,5 +36,5 @@ export declare const coreKnownTags: {
36
36
  test: RegExp;
37
37
  };
38
38
  };
39
- export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (ScalarTag | CollectionTag)[];
39
+ export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
40
40
  export {};
@@ -1,11 +1,11 @@
1
1
  import type { CreateNodeContext } from '../doc/createNode.js';
2
- import type { Schema } from './Schema.js';
3
2
  import type { Node } from '../nodes/Node.js';
4
3
  import type { Scalar } from '../nodes/Scalar.js';
5
4
  import type { YAMLMap } from '../nodes/YAMLMap.js';
6
5
  import type { YAMLSeq } from '../nodes/YAMLSeq.js';
7
6
  import type { ParseOptions } from '../options.js';
8
7
  import type { StringifyContext } from '../stringify/stringify.js';
8
+ import type { Schema } from './Schema.js';
9
9
  interface TagBase {
10
10
  /**
11
11
  * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
@@ -71,12 +71,20 @@ export interface CollectionTag extends TagBase {
71
71
  /**
72
72
  * The `Node` child class that implements this tag.
73
73
  * If set, used to select this tag when stringifying.
74
+ *
75
+ * If the class provides a static `from` method, then that
76
+ * will be used if the tag object doesn't have a `createNode` method.
74
77
  */
75
- nodeClass?: new () => Node;
78
+ nodeClass?: {
79
+ new (schema?: Schema): Node;
80
+ from?: (schema: Schema, obj: unknown, ctx: CreateNodeContext) => Node;
81
+ };
76
82
  /**
77
83
  * Turns a value into an AST node.
78
84
  * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
85
+ *
86
+ * Note: this is required if nodeClass is not provided.
79
87
  */
80
- resolve(value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions): unknown;
88
+ resolve?: (value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions) => unknown;
81
89
  }
82
90
  export {};
@@ -1,5 +1,7 @@
1
- import { YAMLSeq } from '../../nodes/YAMLSeq.js';
2
1
  import { ToJSContext } from '../../nodes/toJS.js';
2
+ import { YAMLSeq } from '../../nodes/YAMLSeq.js';
3
+ import { CreateNodeContext } from '../../util.js';
4
+ import type { Schema } from '../Schema.js';
3
5
  import { CollectionTag } from '../types.js';
4
6
  export declare class YAMLOMap extends YAMLSeq {
5
7
  static tag: string;
@@ -21,5 +23,6 @@ export declare class YAMLOMap extends YAMLSeq {
21
23
  * but TypeScript won't allow widening the signature of a child method.
22
24
  */
23
25
  toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
26
+ static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLOMap;
24
27
  }
25
28
  export declare const omap: CollectionTag;
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var YAMLSeq = require('../../nodes/YAMLSeq.js');
3
+ var identity = require('../../nodes/identity.js');
4
4
  var toJS = require('../../nodes/toJS.js');
5
- var Node = require('../../nodes/Node.js');
6
5
  var YAMLMap = require('../../nodes/YAMLMap.js');
6
+ var YAMLSeq = require('../../nodes/YAMLSeq.js');
7
7
  var pairs = require('./pairs.js');
8
8
 
9
9
  class YAMLOMap extends YAMLSeq.YAMLSeq {
@@ -28,7 +28,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
28
28
  ctx.onCreate(map);
29
29
  for (const pair of this.items) {
30
30
  let key, value;
31
- if (Node.isPair(pair)) {
31
+ if (identity.isPair(pair)) {
32
32
  key = toJS.toJS(pair.key, '', ctx);
33
33
  value = toJS.toJS(pair.value, key, ctx);
34
34
  }
@@ -41,6 +41,12 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
41
41
  }
42
42
  return map;
43
43
  }
44
+ static from(schema, iterable, ctx) {
45
+ const pairs$1 = pairs.createPairs(schema, iterable, ctx);
46
+ const omap = new this();
47
+ omap.items = pairs$1.items;
48
+ return omap;
49
+ }
44
50
  }
45
51
  YAMLOMap.tag = 'tag:yaml.org,2002:omap';
46
52
  const omap = {
@@ -53,7 +59,7 @@ const omap = {
53
59
  const pairs$1 = pairs.resolvePairs(seq, onError);
54
60
  const seenKeys = [];
55
61
  for (const { key } of pairs$1.items) {
56
- if (Node.isScalar(key)) {
62
+ if (identity.isScalar(key)) {
57
63
  if (seenKeys.includes(key.value)) {
58
64
  onError(`Ordered maps must not include duplicate keys: ${key.value}`);
59
65
  }
@@ -64,12 +70,7 @@ const omap = {
64
70
  }
65
71
  return Object.assign(new YAMLOMap(), pairs$1);
66
72
  },
67
- createNode(schema, iterable, ctx) {
68
- const pairs$1 = pairs.createPairs(schema, iterable, ctx);
69
- const omap = new YAMLOMap();
70
- omap.items = pairs$1.items;
71
- return omap;
72
- }
73
+ createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
73
74
  };
74
75
 
75
76
  exports.YAMLOMap = YAMLOMap;
@@ -1,5 +1,5 @@
1
1
  import type { CreateNodeContext } from '../../doc/createNode.js';
2
- import { ParsedNode } from '../../nodes/Node.js';
2
+ import type { ParsedNode } from '../../nodes/Node.js';
3
3
  import { Pair } from '../../nodes/Pair.js';
4
4
  import { YAMLMap } from '../../nodes/YAMLMap.js';
5
5
  import { YAMLSeq } from '../../nodes/YAMLSeq.js';
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../../nodes/Node.js');
3
+ var identity = require('../../nodes/identity.js');
4
4
  var Pair = require('../../nodes/Pair.js');
5
5
  var Scalar = require('../../nodes/Scalar.js');
6
6
  var YAMLSeq = require('../../nodes/YAMLSeq.js');
7
7
 
8
8
  function resolvePairs(seq, onError) {
9
- if (Node.isSeq(seq)) {
9
+ if (identity.isSeq(seq)) {
10
10
  for (let i = 0; i < seq.items.length; ++i) {
11
11
  let item = seq.items[i];
12
- if (Node.isPair(item))
12
+ if (identity.isPair(item))
13
13
  continue;
14
- else if (Node.isMap(item)) {
14
+ else if (identity.isMap(item)) {
15
15
  if (item.items.length > 1)
16
16
  onError('Each pair must have its own sequence indicator');
17
17
  const pair = item.items[0] || new Pair.Pair(new Scalar.Scalar(null));
@@ -27,7 +27,7 @@ function resolvePairs(seq, onError) {
27
27
  }
28
28
  item = pair;
29
29
  }
30
- seq.items[i] = Node.isPair(item) ? item : new Pair.Pair(item);
30
+ seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item);
31
31
  }
32
32
  }
33
33
  else
@@ -1 +1 @@
1
- export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[];
1
+ export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
@@ -1,9 +1,10 @@
1
- import type { Schema } from '../../schema/Schema.js';
2
1
  import { Pair } from '../../nodes/Pair.js';
3
2
  import { Scalar } from '../../nodes/Scalar.js';
4
3
  import { ToJSContext } from '../../nodes/toJS.js';
5
4
  import { YAMLMap } from '../../nodes/YAMLMap.js';
5
+ import type { Schema } from '../../schema/Schema.js';
6
6
  import type { StringifyContext } from '../../stringify/stringify.js';
7
+ import { CreateNodeContext } from '../../util.js';
7
8
  import type { CollectionTag } from '../types.js';
8
9
  export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null> {
9
10
  static tag: string;
@@ -22,5 +23,6 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
22
23
  set(key: T, value: null): void;
23
24
  toJSON(_?: unknown, ctx?: ToJSContext): any;
24
25
  toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
26
+ static from(schema: Schema, iterable: unknown, ctx: CreateNodeContext): YAMLSet<unknown>;
25
27
  }
26
28
  export declare const set: CollectionTag;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../../nodes/Node.js');
3
+ var identity = require('../../nodes/identity.js');
4
4
  var Pair = require('../../nodes/Pair.js');
5
5
  var YAMLMap = require('../../nodes/YAMLMap.js');
6
6
 
@@ -11,7 +11,7 @@ class YAMLSet extends YAMLMap.YAMLMap {
11
11
  }
12
12
  add(key) {
13
13
  let pair;
14
- if (Node.isPair(key))
14
+ if (identity.isPair(key))
15
15
  pair = key;
16
16
  else if (key &&
17
17
  typeof key === 'object' &&
@@ -31,8 +31,8 @@ class YAMLSet extends YAMLMap.YAMLMap {
31
31
  */
32
32
  get(key, keepPair) {
33
33
  const pair = YAMLMap.findPair(this.items, key);
34
- return !keepPair && Node.isPair(pair)
35
- ? Node.isScalar(pair.key)
34
+ return !keepPair && identity.isPair(pair)
35
+ ? identity.isScalar(pair.key)
36
36
  ? pair.key.value
37
37
  : pair.key
38
38
  : pair;
@@ -59,6 +59,17 @@ class YAMLSet extends YAMLMap.YAMLMap {
59
59
  else
60
60
  throw new Error('Set items must all have null values');
61
61
  }
62
+ static from(schema, iterable, ctx) {
63
+ const { replacer } = ctx;
64
+ const set = new this(schema);
65
+ if (iterable && Symbol.iterator in Object(iterable))
66
+ for (let value of iterable) {
67
+ if (typeof replacer === 'function')
68
+ value = replacer.call(iterable, value, value);
69
+ set.items.push(Pair.createPair(value, null, ctx));
70
+ }
71
+ return set;
72
+ }
62
73
  }
63
74
  YAMLSet.tag = 'tag:yaml.org,2002:set';
64
75
  const set = {
@@ -67,8 +78,9 @@ const set = {
67
78
  nodeClass: YAMLSet,
68
79
  default: false,
69
80
  tag: 'tag:yaml.org,2002:set',
81
+ createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
70
82
  resolve(map, onError) {
71
- if (Node.isMap(map)) {
83
+ if (identity.isMap(map)) {
72
84
  if (map.hasAllNullValues(true))
73
85
  return Object.assign(new YAMLSet(), map);
74
86
  else
@@ -77,17 +89,6 @@ const set = {
77
89
  else
78
90
  onError('Expected a mapping for this tag');
79
91
  return map;
80
- },
81
- createNode(schema, iterable, ctx) {
82
- const { replacer } = ctx;
83
- const set = new YAMLSet(schema);
84
- if (iterable && Symbol.iterator in Object(iterable))
85
- for (let value of iterable) {
86
- if (typeof replacer === 'function')
87
- value = replacer.call(iterable, value, value);
88
- set.items.push(Pair.createPair(value, null, ctx));
89
- }
90
- return set;
91
92
  }
92
93
  };
93
94
 
@@ -45,7 +45,7 @@ function stringifySexagesimal(node) {
45
45
  }
46
46
  return (sign +
47
47
  parts
48
- .map(n => (n < 10 ? '0' + String(n) : String(n)))
48
+ .map(n => String(n).padStart(2, '0'))
49
49
  .join(':')
50
50
  .replace(/000000\d*$/, '') // % 60 may introduce error
51
51
  );
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var anchors = require('../doc/anchors.js');
4
- var Node = require('../nodes/Node.js');
4
+ var identity = require('../nodes/identity.js');
5
5
  var stringifyComment = require('./stringifyComment.js');
6
6
  var stringifyString = require('./stringifyString.js');
7
7
 
@@ -54,7 +54,7 @@ function getTagObject(tags, item) {
54
54
  }
55
55
  let tagObj = undefined;
56
56
  let obj;
57
- if (Node.isScalar(item)) {
57
+ if (identity.isScalar(item)) {
58
58
  obj = item.value;
59
59
  const match = tags.filter(t => t.identify?.(obj));
60
60
  tagObj =
@@ -75,7 +75,7 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
75
75
  if (!doc.directives)
76
76
  return '';
77
77
  const props = [];
78
- const anchor = (Node.isScalar(node) || Node.isCollection(node)) && node.anchor;
78
+ const anchor = (identity.isScalar(node) || identity.isCollection(node)) && node.anchor;
79
79
  if (anchor && anchors.anchorIsValid(anchor)) {
80
80
  anchors$1.add(anchor);
81
81
  props.push(`&${anchor}`);
@@ -86,9 +86,9 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
86
86
  return props.join(' ');
87
87
  }
88
88
  function stringify(item, ctx, onComment, onChompKeep) {
89
- if (Node.isPair(item))
89
+ if (identity.isPair(item))
90
90
  return item.toString(ctx, onComment, onChompKeep);
91
- if (Node.isAlias(item)) {
91
+ if (identity.isAlias(item)) {
92
92
  if (ctx.doc.directives)
93
93
  return item.toString(ctx);
94
94
  if (ctx.resolvedAliases?.has(item)) {
@@ -103,7 +103,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
103
103
  }
104
104
  }
105
105
  let tagObj = undefined;
106
- const node = Node.isNode(item)
106
+ const node = identity.isNode(item)
107
107
  ? item
108
108
  : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
109
109
  if (!tagObj)
@@ -113,12 +113,12 @@ function stringify(item, ctx, onComment, onChompKeep) {
113
113
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
114
114
  const str = typeof tagObj.stringify === 'function'
115
115
  ? tagObj.stringify(node, ctx, onComment, onChompKeep)
116
- : Node.isScalar(node)
116
+ : identity.isScalar(node)
117
117
  ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep)
118
118
  : node.toString(ctx, onComment, onChompKeep);
119
119
  if (!props)
120
120
  return str;
121
- return Node.isScalar(node) || str[0] === '{' || str[0] === '['
121
+ return identity.isScalar(node) || str[0] === '{' || str[0] === '['
122
122
  ? `${props} ${str}`
123
123
  : `${props}\n${ctx.indent}${str}`;
124
124
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var Collection = require('../nodes/Collection.js');
4
- var Node = require('../nodes/Node.js');
4
+ var identity = require('../nodes/identity.js');
5
5
  var stringify = require('./stringify.js');
6
6
  var stringifyComment = require('./stringifyComment.js');
7
7
 
@@ -18,15 +18,15 @@ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, fl
18
18
  for (let i = 0; i < items.length; ++i) {
19
19
  const item = items[i];
20
20
  let comment = null;
21
- if (Node.isNode(item)) {
21
+ if (identity.isNode(item)) {
22
22
  if (!chompKeep && item.spaceBefore)
23
23
  lines.push('');
24
24
  addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
25
25
  if (item.comment)
26
26
  comment = item.comment;
27
27
  }
28
- else if (Node.isPair(item)) {
29
- const ik = Node.isNode(item.key) ? item.key : null;
28
+ else if (identity.isPair(item)) {
29
+ const ik = identity.isNode(item.key) ? item.key : null;
30
30
  if (ik) {
31
31
  if (!chompKeep && ik.spaceBefore)
32
32
  lines.push('');
@@ -75,15 +75,15 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
75
75
  for (let i = 0; i < items.length; ++i) {
76
76
  const item = items[i];
77
77
  let comment = null;
78
- if (Node.isNode(item)) {
78
+ if (identity.isNode(item)) {
79
79
  if (item.spaceBefore)
80
80
  lines.push('');
81
81
  addCommentBefore(ctx, lines, item.commentBefore, false);
82
82
  if (item.comment)
83
83
  comment = item.comment;
84
84
  }
85
- else if (Node.isPair(item)) {
86
- const ik = Node.isNode(item.key) ? item.key : null;
85
+ else if (identity.isPair(item)) {
86
+ const ik = identity.isNode(item.key) ? item.key : null;
87
87
  if (ik) {
88
88
  if (ik.spaceBefore)
89
89
  lines.push('');
@@ -91,7 +91,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
91
91
  if (ik.comment)
92
92
  reqNewline = true;
93
93
  }
94
- const iv = Node.isNode(item.value) ? item.value : null;
94
+ const iv = identity.isNode(item.value) ? item.value : null;
95
95
  if (iv) {
96
96
  if (iv.comment)
97
97
  comment = iv.comment;
@@ -1,3 +1,4 @@
1
- import { Document } from '../doc/Document.js';
2
- import { ToStringOptions } from '../options.js';
3
- export declare function stringifyDocument(doc: Readonly<Document>, options: ToStringOptions): string;
1
+ import type { Document } from '../doc/Document.js';
2
+ import type { Node } from '../nodes/Node.js';
3
+ import type { ToStringOptions } from '../options.js';
4
+ export declare function stringifyDocument(doc: Readonly<Document<Node, boolean>>, options: ToStringOptions): string;
@@ -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 stringify = require('./stringify.js');
5
5
  var stringifyComment = require('./stringifyComment.js');
6
6
 
@@ -29,7 +29,7 @@ function stringifyDocument(doc, options) {
29
29
  let chompKeep = false;
30
30
  let contentComment = null;
31
31
  if (doc.contents) {
32
- if (Node.isNode(doc.contents)) {
32
+ if (identity.isNode(doc.contents)) {
33
33
  if (doc.contents.spaceBefore && hasDirectives)
34
34
  lines.push('');
35
35
  if (doc.contents.commentBefore) {