cdklabs-projen-project-types 0.0.2

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/.gitattributes +22 -0
  2. package/.jsii +421 -0
  3. package/API.md +14712 -0
  4. package/LICENSE +202 -0
  5. package/README.md +1 -0
  6. package/lib/cdk.d.ts +40 -0
  7. package/lib/cdk.js +68 -0
  8. package/lib/cdklabs.d.ts +45 -0
  9. package/lib/cdklabs.js +101 -0
  10. package/lib/index.d.ts +2 -0
  11. package/lib/index.js +15 -0
  12. package/lib/private.d.ts +13 -0
  13. package/lib/private.js +25 -0
  14. package/node_modules/yaml/LICENSE +13 -0
  15. package/node_modules/yaml/README.md +143 -0
  16. package/node_modules/yaml/browser/dist/compose/compose-collection.js +59 -0
  17. package/node_modules/yaml/browser/dist/compose/compose-doc.js +40 -0
  18. package/node_modules/yaml/browser/dist/compose/compose-node.js +92 -0
  19. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +80 -0
  20. package/node_modules/yaml/browser/dist/compose/composer.js +217 -0
  21. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +110 -0
  22. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +194 -0
  23. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +45 -0
  24. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  25. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +200 -0
  26. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +223 -0
  27. package/node_modules/yaml/browser/dist/compose/resolve-props.js +134 -0
  28. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  29. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +27 -0
  30. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  31. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +17 -0
  32. package/node_modules/yaml/browser/dist/doc/Document.js +332 -0
  33. package/node_modules/yaml/browser/dist/doc/anchors.js +72 -0
  34. package/node_modules/yaml/browser/dist/doc/applyReviver.js +54 -0
  35. package/node_modules/yaml/browser/dist/doc/createNode.js +85 -0
  36. package/node_modules/yaml/browser/dist/doc/directives.js +169 -0
  37. package/node_modules/yaml/browser/dist/errors.js +57 -0
  38. package/node_modules/yaml/browser/dist/index.js +17 -0
  39. package/node_modules/yaml/browser/dist/log.js +14 -0
  40. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
  41. package/node_modules/yaml/browser/dist/nodes/Alias.js +94 -0
  42. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  43. package/node_modules/yaml/browser/dist/nodes/Node.js +48 -0
  44. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  45. package/node_modules/yaml/browser/dist/nodes/Scalar.js +23 -0
  46. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +116 -0
  47. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +97 -0
  48. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +104 -0
  49. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  50. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  51. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  52. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  53. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  54. package/node_modules/yaml/browser/dist/parse/lexer.js +701 -0
  55. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  56. package/node_modules/yaml/browser/dist/parse/parser.js +950 -0
  57. package/node_modules/yaml/browser/dist/public-api.js +99 -0
  58. package/node_modules/yaml/browser/dist/schema/Schema.js +38 -0
  59. package/node_modules/yaml/browser/dist/schema/common/map.js +42 -0
  60. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  61. package/node_modules/yaml/browser/dist/schema/common/seq.js +33 -0
  62. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  63. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  64. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  65. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  66. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  67. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  68. package/node_modules/yaml/browser/dist/schema/tags.js +83 -0
  69. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +66 -0
  70. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  71. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  72. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  73. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +73 -0
  74. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  75. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +37 -0
  76. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +92 -0
  77. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  78. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +135 -0
  79. package/node_modules/yaml/browser/dist/stringify/stringify.js +124 -0
  80. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +151 -0
  81. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  82. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  83. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +24 -0
  84. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  85. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +319 -0
  86. package/node_modules/yaml/browser/dist/util.js +9 -0
  87. package/node_modules/yaml/browser/dist/visit.js +233 -0
  88. package/node_modules/yaml/browser/index.js +5 -0
  89. package/node_modules/yaml/browser/package.json +3 -0
  90. package/node_modules/yaml/dist/compose/compose-collection.d.ts +5 -0
  91. package/node_modules/yaml/dist/compose/compose-collection.js +61 -0
  92. package/node_modules/yaml/dist/compose/compose-doc.d.ts +6 -0
  93. package/node_modules/yaml/dist/compose/compose-doc.js +42 -0
  94. package/node_modules/yaml/dist/compose/compose-node.d.ts +27 -0
  95. package/node_modules/yaml/dist/compose/compose-node.js +95 -0
  96. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  97. package/node_modules/yaml/dist/compose/compose-scalar.js +82 -0
  98. package/node_modules/yaml/dist/compose/composer.d.ts +62 -0
  99. package/node_modules/yaml/dist/compose/composer.js +221 -0
  100. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  101. package/node_modules/yaml/dist/compose/resolve-block-map.js +112 -0
  102. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +10 -0
  103. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +196 -0
  104. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +5 -0
  105. package/node_modules/yaml/dist/compose/resolve-block-seq.js +47 -0
  106. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  107. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  108. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +6 -0
  109. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +202 -0
  110. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  111. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +225 -0
  112. package/node_modules/yaml/dist/compose/resolve-props.d.ts +22 -0
  113. package/node_modules/yaml/dist/compose/resolve-props.js +136 -0
  114. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  115. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  116. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  117. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +29 -0
  118. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  119. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  120. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  121. package/node_modules/yaml/dist/compose/util-map-includes.js +19 -0
  122. package/node_modules/yaml/dist/doc/Document.d.ts +139 -0
  123. package/node_modules/yaml/dist/doc/Document.js +334 -0
  124. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  125. package/node_modules/yaml/dist/doc/anchors.js +77 -0
  126. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  127. package/node_modules/yaml/dist/doc/applyReviver.js +56 -0
  128. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  129. package/node_modules/yaml/dist/doc/createNode.js +87 -0
  130. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  131. package/node_modules/yaml/dist/doc/directives.js +171 -0
  132. package/node_modules/yaml/dist/errors.d.ts +21 -0
  133. package/node_modules/yaml/dist/errors.js +62 -0
  134. package/node_modules/yaml/dist/index.d.ts +21 -0
  135. package/node_modules/yaml/dist/index.js +50 -0
  136. package/node_modules/yaml/dist/log.d.ts +3 -0
  137. package/node_modules/yaml/dist/log.js +17 -0
  138. package/node_modules/yaml/dist/nodes/Alias.d.ts +28 -0
  139. package/node_modules/yaml/dist/nodes/Alias.js +96 -0
  140. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  141. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  142. package/node_modules/yaml/dist/nodes/Node.d.ts +59 -0
  143. package/node_modules/yaml/dist/nodes/Node.js +66 -0
  144. package/node_modules/yaml/dist/nodes/Pair.d.ts +21 -0
  145. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  146. package/node_modules/yaml/dist/nodes/Scalar.d.ts +42 -0
  147. package/node_modules/yaml/dist/nodes/Scalar.js +26 -0
  148. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +47 -0
  149. package/node_modules/yaml/dist/nodes/YAMLMap.js +119 -0
  150. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +58 -0
  151. package/node_modules/yaml/dist/nodes/YAMLSeq.js +99 -0
  152. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  153. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +106 -0
  154. package/node_modules/yaml/dist/nodes/toJS.d.ts +30 -0
  155. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  156. package/node_modules/yaml/dist/options.d.ts +338 -0
  157. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  158. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  159. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  160. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  161. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  162. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  163. package/node_modules/yaml/dist/parse/cst.d.ts +106 -0
  164. package/node_modules/yaml/dist/parse/cst.js +112 -0
  165. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  166. package/node_modules/yaml/dist/parse/lexer.js +703 -0
  167. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  168. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  169. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  170. package/node_modules/yaml/dist/parse/parser.js +954 -0
  171. package/node_modules/yaml/dist/public-api.d.ts +43 -0
  172. package/node_modules/yaml/dist/public-api.js +104 -0
  173. package/node_modules/yaml/dist/schema/Schema.d.ts +18 -0
  174. package/node_modules/yaml/dist/schema/Schema.js +40 -0
  175. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  176. package/node_modules/yaml/dist/schema/common/map.js +44 -0
  177. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  178. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  179. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  180. package/node_modules/yaml/dist/schema/common/seq.js +35 -0
  181. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  182. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  183. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  184. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  185. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  186. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  187. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  188. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  189. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  190. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  191. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  192. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  193. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  194. package/node_modules/yaml/dist/schema/tags.d.ts +40 -0
  195. package/node_modules/yaml/dist/schema/tags.js +86 -0
  196. package/node_modules/yaml/dist/schema/types.d.ts +82 -0
  197. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  198. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +68 -0
  199. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  200. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  201. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  202. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  203. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  204. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  205. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +25 -0
  206. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +76 -0
  207. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  208. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +81 -0
  209. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  210. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +39 -0
  211. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +26 -0
  212. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +95 -0
  213. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  214. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  215. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  216. package/node_modules/yaml/dist/stringify/foldFlowLines.js +140 -0
  217. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  218. package/node_modules/yaml/dist/stringify/stringify.js +127 -0
  219. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  220. package/node_modules/yaml/dist/stringify/stringifyCollection.js +153 -0
  221. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  222. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  223. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +3 -0
  224. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  225. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  226. package/node_modules/yaml/dist/stringify/stringifyNumber.js +26 -0
  227. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  228. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  229. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  230. package/node_modules/yaml/dist/stringify/stringifyString.js +321 -0
  231. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  232. package/node_modules/yaml/dist/test-events.js +134 -0
  233. package/node_modules/yaml/dist/util.d.ts +9 -0
  234. package/node_modules/yaml/dist/util.js +24 -0
  235. package/node_modules/yaml/dist/visit.d.ts +102 -0
  236. package/node_modules/yaml/dist/visit.js +236 -0
  237. package/node_modules/yaml/package.json +94 -0
  238. package/node_modules/yaml/util.d.ts +3 -0
  239. package/node_modules/yaml/util.js +2 -0
  240. package/package.json +126 -0
@@ -0,0 +1,218 @@
1
+ 'use strict';
2
+
3
+ var resolveBlockScalar = require('../compose/resolve-block-scalar.js');
4
+ var resolveFlowScalar = require('../compose/resolve-flow-scalar.js');
5
+ var errors = require('../errors.js');
6
+ var stringifyString = require('../stringify/stringifyString.js');
7
+
8
+ function resolveAsScalar(token, strict = true, onError) {
9
+ if (token) {
10
+ const _onError = (pos, code, message) => {
11
+ const offset = typeof pos === 'number' ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
12
+ if (onError)
13
+ onError(offset, code, message);
14
+ else
15
+ throw new errors.YAMLParseError([offset, offset + 1], code, message);
16
+ };
17
+ switch (token.type) {
18
+ case 'scalar':
19
+ case 'single-quoted-scalar':
20
+ case 'double-quoted-scalar':
21
+ return resolveFlowScalar.resolveFlowScalar(token, strict, _onError);
22
+ case 'block-scalar':
23
+ return resolveBlockScalar.resolveBlockScalar(token, strict, _onError);
24
+ }
25
+ }
26
+ return null;
27
+ }
28
+ /**
29
+ * Create a new scalar token with `value`
30
+ *
31
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
32
+ * as this function does not support any schema operations and won't check for such conflicts.
33
+ *
34
+ * @param value The string representation of the value, which will have its content properly indented.
35
+ * @param context.end Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.
36
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
37
+ * @param context.indent The indent level of the token.
38
+ * @param context.inFlow Is this scalar within a flow collection? This may affect the resolved type of the token's value.
39
+ * @param context.offset The offset position of the token.
40
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
41
+ */
42
+ function createScalarToken(value, context) {
43
+ const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
44
+ const source = stringifyString.stringifyString({ type, value }, {
45
+ implicitKey,
46
+ indent: indent > 0 ? ' '.repeat(indent) : '',
47
+ inFlow,
48
+ options: { blockQuote: true, lineWidth: -1 }
49
+ });
50
+ const end = context.end ?? [
51
+ { type: 'newline', offset: -1, indent, source: '\n' }
52
+ ];
53
+ switch (source[0]) {
54
+ case '|':
55
+ case '>': {
56
+ const he = source.indexOf('\n');
57
+ const head = source.substring(0, he);
58
+ const body = source.substring(he + 1) + '\n';
59
+ const props = [
60
+ { type: 'block-scalar-header', offset, indent, source: head }
61
+ ];
62
+ if (!addEndtoBlockProps(props, end))
63
+ props.push({ type: 'newline', offset: -1, indent, source: '\n' });
64
+ return { type: 'block-scalar', offset, indent, props, source: body };
65
+ }
66
+ case '"':
67
+ return { type: 'double-quoted-scalar', offset, indent, source, end };
68
+ case "'":
69
+ return { type: 'single-quoted-scalar', offset, indent, source, end };
70
+ default:
71
+ return { type: 'scalar', offset, indent, source, end };
72
+ }
73
+ }
74
+ /**
75
+ * Set the value of `token` to the given string `value`, overwriting any previous contents and type that it may have.
76
+ *
77
+ * Best efforts are made to retain any comments previously associated with the `token`,
78
+ * though all contents within a collection's `items` will be overwritten.
79
+ *
80
+ * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
81
+ * as this function does not support any schema operations and won't check for such conflicts.
82
+ *
83
+ * @param token Any token. If it does not include an `indent` value, the value will be stringified as if it were an implicit key.
84
+ * @param value The string representation of the value, which will have its content properly indented.
85
+ * @param context.afterKey In most cases, values after a key should have an additional level of indentation.
86
+ * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
87
+ * @param context.inFlow Being within a flow collection may affect the resolved type of the token's value.
88
+ * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
89
+ */
90
+ function setScalarValue(token, value, context = {}) {
91
+ let { afterKey = false, implicitKey = false, inFlow = false, type } = context;
92
+ let indent = 'indent' in token ? token.indent : null;
93
+ if (afterKey && typeof indent === 'number')
94
+ indent += 2;
95
+ if (!type)
96
+ switch (token.type) {
97
+ case 'single-quoted-scalar':
98
+ type = 'QUOTE_SINGLE';
99
+ break;
100
+ case 'double-quoted-scalar':
101
+ type = 'QUOTE_DOUBLE';
102
+ break;
103
+ case 'block-scalar': {
104
+ const header = token.props[0];
105
+ if (header.type !== 'block-scalar-header')
106
+ throw new Error('Invalid block scalar header');
107
+ type = header.source[0] === '>' ? 'BLOCK_FOLDED' : 'BLOCK_LITERAL';
108
+ break;
109
+ }
110
+ default:
111
+ type = 'PLAIN';
112
+ }
113
+ const source = stringifyString.stringifyString({ type, value }, {
114
+ implicitKey: implicitKey || indent === null,
115
+ indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
116
+ inFlow,
117
+ options: { blockQuote: true, lineWidth: -1 }
118
+ });
119
+ switch (source[0]) {
120
+ case '|':
121
+ case '>':
122
+ setBlockScalarValue(token, source);
123
+ break;
124
+ case '"':
125
+ setFlowScalarValue(token, source, 'double-quoted-scalar');
126
+ break;
127
+ case "'":
128
+ setFlowScalarValue(token, source, 'single-quoted-scalar');
129
+ break;
130
+ default:
131
+ setFlowScalarValue(token, source, 'scalar');
132
+ }
133
+ }
134
+ function setBlockScalarValue(token, source) {
135
+ const he = source.indexOf('\n');
136
+ const head = source.substring(0, he);
137
+ const body = source.substring(he + 1) + '\n';
138
+ if (token.type === 'block-scalar') {
139
+ const header = token.props[0];
140
+ if (header.type !== 'block-scalar-header')
141
+ throw new Error('Invalid block scalar header');
142
+ header.source = head;
143
+ token.source = body;
144
+ }
145
+ else {
146
+ const { offset } = token;
147
+ const indent = 'indent' in token ? token.indent : -1;
148
+ const props = [
149
+ { type: 'block-scalar-header', offset, indent, source: head }
150
+ ];
151
+ if (!addEndtoBlockProps(props, 'end' in token ? token.end : undefined))
152
+ props.push({ type: 'newline', offset: -1, indent, source: '\n' });
153
+ for (const key of Object.keys(token))
154
+ if (key !== 'type' && key !== 'offset')
155
+ delete token[key];
156
+ Object.assign(token, { type: 'block-scalar', indent, props, source: body });
157
+ }
158
+ }
159
+ /** @returns `true` if last token is a newline */
160
+ function addEndtoBlockProps(props, end) {
161
+ if (end)
162
+ for (const st of end)
163
+ switch (st.type) {
164
+ case 'space':
165
+ case 'comment':
166
+ props.push(st);
167
+ break;
168
+ case 'newline':
169
+ props.push(st);
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+ function setFlowScalarValue(token, source, type) {
175
+ switch (token.type) {
176
+ case 'scalar':
177
+ case 'double-quoted-scalar':
178
+ case 'single-quoted-scalar':
179
+ token.type = type;
180
+ token.source = source;
181
+ break;
182
+ case 'block-scalar': {
183
+ const end = token.props.slice(1);
184
+ let oa = source.length;
185
+ if (token.props[0].type === 'block-scalar-header')
186
+ oa -= token.props[0].source.length;
187
+ for (const tok of end)
188
+ tok.offset += oa;
189
+ delete token.props;
190
+ Object.assign(token, { type, source, end });
191
+ break;
192
+ }
193
+ case 'block-map':
194
+ case 'block-seq': {
195
+ const offset = token.offset + source.length;
196
+ const nl = { type: 'newline', offset, indent: token.indent, source: '\n' };
197
+ delete token.items;
198
+ Object.assign(token, { type, source, end: [nl] });
199
+ break;
200
+ }
201
+ default: {
202
+ const indent = 'indent' in token ? token.indent : -1;
203
+ const end = 'end' in token && Array.isArray(token.end)
204
+ ? token.end.filter(st => st.type === 'space' ||
205
+ st.type === 'comment' ||
206
+ st.type === 'newline')
207
+ : [];
208
+ for (const key of Object.keys(token))
209
+ if (key !== 'type' && key !== 'offset')
210
+ delete token[key];
211
+ Object.assign(token, { type, indent, source, end });
212
+ }
213
+ }
214
+ }
215
+
216
+ exports.createScalarToken = createScalarToken;
217
+ exports.resolveAsScalar = resolveAsScalar;
218
+ exports.setScalarValue = setScalarValue;
@@ -0,0 +1,8 @@
1
+ import type { CollectionItem, Token } from './cst.js';
2
+ /**
3
+ * Stringify a CST document, token, or collection item
4
+ *
5
+ * Fair warning: This applies no validation whatsoever, and
6
+ * simply concatenates the sources in their logical order.
7
+ */
8
+ export declare const stringify: (cst: Token | CollectionItem) => string;
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Stringify a CST document, token, or collection item
5
+ *
6
+ * Fair warning: This applies no validation whatsoever, and
7
+ * simply concatenates the sources in their logical order.
8
+ */
9
+ const stringify = (cst) => 'type' in cst ? stringifyToken(cst) : stringifyItem(cst);
10
+ function stringifyToken(token) {
11
+ switch (token.type) {
12
+ case 'block-scalar': {
13
+ let res = '';
14
+ for (const tok of token.props)
15
+ res += stringifyToken(tok);
16
+ return res + token.source;
17
+ }
18
+ case 'block-map':
19
+ case 'block-seq': {
20
+ let res = '';
21
+ for (const item of token.items)
22
+ res += stringifyItem(item);
23
+ return res;
24
+ }
25
+ case 'flow-collection': {
26
+ let res = token.start.source;
27
+ for (const item of token.items)
28
+ res += stringifyItem(item);
29
+ for (const st of token.end)
30
+ res += st.source;
31
+ return res;
32
+ }
33
+ case 'document': {
34
+ let res = stringifyItem(token);
35
+ if (token.end)
36
+ for (const st of token.end)
37
+ res += st.source;
38
+ return res;
39
+ }
40
+ default: {
41
+ let res = token.source;
42
+ if ('end' in token && token.end)
43
+ for (const st of token.end)
44
+ res += st.source;
45
+ return res;
46
+ }
47
+ }
48
+ }
49
+ function stringifyItem({ start, key, sep, value }) {
50
+ let res = '';
51
+ for (const st of start)
52
+ res += st.source;
53
+ if (key)
54
+ res += stringifyToken(key);
55
+ if (sep)
56
+ for (const st of sep)
57
+ res += st.source;
58
+ if (value)
59
+ res += stringifyToken(value);
60
+ return res;
61
+ }
62
+
63
+ exports.stringify = stringify;
@@ -0,0 +1,39 @@
1
+ import type { CollectionItem, Document } from './cst.js';
2
+ export type VisitPath = readonly ['key' | 'value', number][];
3
+ export type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
4
+ /**
5
+ * Apply a visitor to a CST document or item.
6
+ *
7
+ * Walks through the tree (depth-first) starting from the root, calling a
8
+ * `visitor` function with two arguments when entering each item:
9
+ * - `item`: The current item, which included the following members:
10
+ * - `start: SourceToken[]` – Source tokens before the key or value,
11
+ * possibly including its anchor or tag.
12
+ * - `key?: Token | null` – Set for pair values. May then be `null`, if
13
+ * the key before the `:` separator is empty.
14
+ * - `sep?: SourceToken[]` – Source tokens between the key and the value,
15
+ * which should include the `:` map value indicator if `value` is set.
16
+ * - `value?: Token` – The value of a sequence item, or of a map pair.
17
+ * - `path`: The steps from the root to the current node, as an array of
18
+ * `['key' | 'value', number]` tuples.
19
+ *
20
+ * The return value of the visitor may be used to control the traversal:
21
+ * - `undefined` (default): Do nothing and continue
22
+ * - `visit.SKIP`: Do not visit the children of this token, continue with
23
+ * next sibling
24
+ * - `visit.BREAK`: Terminate traversal completely
25
+ * - `visit.REMOVE`: Remove the current item, then continue with the next one
26
+ * - `number`: Set the index of the next step. This is useful especially if
27
+ * the index of the current token has changed.
28
+ * - `function`: Define the next visitor for this item. After the original
29
+ * visitor is called on item entry, next visitors are called after handling
30
+ * a non-empty `key` and when exiting the item.
31
+ */
32
+ export declare function visit(cst: Document | CollectionItem, visitor: Visitor): void;
33
+ export declare namespace visit {
34
+ var BREAK: symbol;
35
+ var SKIP: symbol;
36
+ var REMOVE: symbol;
37
+ var itemAtPath: (cst: Document | CollectionItem, path: VisitPath) => CollectionItem | undefined;
38
+ var parentCollection: (cst: Document | CollectionItem, path: VisitPath) => import("./cst.js").BlockMap | import("./cst.js").BlockSequence | import("./cst.js").FlowCollection;
39
+ }
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ const BREAK = Symbol('break visit');
4
+ const SKIP = Symbol('skip children');
5
+ const REMOVE = Symbol('remove item');
6
+ /**
7
+ * Apply a visitor to a CST document or item.
8
+ *
9
+ * Walks through the tree (depth-first) starting from the root, calling a
10
+ * `visitor` function with two arguments when entering each item:
11
+ * - `item`: The current item, which included the following members:
12
+ * - `start: SourceToken[]` – Source tokens before the key or value,
13
+ * possibly including its anchor or tag.
14
+ * - `key?: Token | null` – Set for pair values. May then be `null`, if
15
+ * the key before the `:` separator is empty.
16
+ * - `sep?: SourceToken[]` – Source tokens between the key and the value,
17
+ * which should include the `:` map value indicator if `value` is set.
18
+ * - `value?: Token` – The value of a sequence item, or of a map pair.
19
+ * - `path`: The steps from the root to the current node, as an array of
20
+ * `['key' | 'value', number]` tuples.
21
+ *
22
+ * The return value of the visitor may be used to control the traversal:
23
+ * - `undefined` (default): Do nothing and continue
24
+ * - `visit.SKIP`: Do not visit the children of this token, continue with
25
+ * next sibling
26
+ * - `visit.BREAK`: Terminate traversal completely
27
+ * - `visit.REMOVE`: Remove the current item, then continue with the next one
28
+ * - `number`: Set the index of the next step. This is useful especially if
29
+ * the index of the current token has changed.
30
+ * - `function`: Define the next visitor for this item. After the original
31
+ * visitor is called on item entry, next visitors are called after handling
32
+ * a non-empty `key` and when exiting the item.
33
+ */
34
+ function visit(cst, visitor) {
35
+ if ('type' in cst && cst.type === 'document')
36
+ cst = { start: cst.start, value: cst.value };
37
+ _visit(Object.freeze([]), cst, visitor);
38
+ }
39
+ // Without the `as symbol` casts, TS declares these in the `visit`
40
+ // namespace using `var`, but then complains about that because
41
+ // `unique symbol` must be `const`.
42
+ /** Terminate visit traversal completely */
43
+ visit.BREAK = BREAK;
44
+ /** Do not visit the children of the current item */
45
+ visit.SKIP = SKIP;
46
+ /** Remove the current item */
47
+ visit.REMOVE = REMOVE;
48
+ /** Find the item at `path` from `cst` as the root */
49
+ visit.itemAtPath = (cst, path) => {
50
+ let item = cst;
51
+ for (const [field, index] of path) {
52
+ const tok = item?.[field];
53
+ if (tok && 'items' in tok) {
54
+ item = tok.items[index];
55
+ }
56
+ else
57
+ return undefined;
58
+ }
59
+ return item;
60
+ };
61
+ /**
62
+ * Get the immediate parent collection of the item at `path` from `cst` as the root.
63
+ *
64
+ * Throws an error if the collection is not found, which should never happen if the item itself exists.
65
+ */
66
+ visit.parentCollection = (cst, path) => {
67
+ const parent = visit.itemAtPath(cst, path.slice(0, -1));
68
+ const field = path[path.length - 1][0];
69
+ const coll = parent?.[field];
70
+ if (coll && 'items' in coll)
71
+ return coll;
72
+ throw new Error('Parent collection not found');
73
+ };
74
+ function _visit(path, item, visitor) {
75
+ let ctrl = visitor(item, path);
76
+ if (typeof ctrl === 'symbol')
77
+ return ctrl;
78
+ for (const field of ['key', 'value']) {
79
+ const token = item[field];
80
+ if (token && 'items' in token) {
81
+ for (let i = 0; i < token.items.length; ++i) {
82
+ const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
83
+ if (typeof ci === 'number')
84
+ i = ci - 1;
85
+ else if (ci === BREAK)
86
+ return BREAK;
87
+ else if (ci === REMOVE) {
88
+ token.items.splice(i, 1);
89
+ i -= 1;
90
+ }
91
+ }
92
+ if (typeof ctrl === 'function' && field === 'key')
93
+ ctrl = ctrl(item, path);
94
+ }
95
+ }
96
+ return typeof ctrl === 'function' ? ctrl(item, path) : ctrl;
97
+ }
98
+
99
+ exports.visit = visit;
@@ -0,0 +1,106 @@
1
+ export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar.js';
2
+ export { stringify } from './cst-stringify.js';
3
+ export { visit, Visitor, VisitPath } from './cst-visit.js';
4
+ export interface SourceToken {
5
+ type: 'byte-order-mark' | 'doc-mode' | 'doc-start' | 'space' | 'comment' | 'newline' | 'directive-line' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'block-scalar-header';
6
+ offset: number;
7
+ indent: number;
8
+ source: string;
9
+ }
10
+ export interface ErrorToken {
11
+ type: 'error';
12
+ offset: number;
13
+ source: string;
14
+ message: string;
15
+ }
16
+ export interface Directive {
17
+ type: 'directive';
18
+ offset: number;
19
+ source: string;
20
+ }
21
+ export interface Document {
22
+ type: 'document';
23
+ offset: number;
24
+ start: SourceToken[];
25
+ value?: Token;
26
+ end?: SourceToken[];
27
+ }
28
+ export interface DocumentEnd {
29
+ type: 'doc-end';
30
+ offset: number;
31
+ source: string;
32
+ end?: SourceToken[];
33
+ }
34
+ export interface FlowScalar {
35
+ type: 'alias' | 'scalar' | 'single-quoted-scalar' | 'double-quoted-scalar';
36
+ offset: number;
37
+ indent: number;
38
+ source: string;
39
+ end?: SourceToken[];
40
+ }
41
+ export interface BlockScalar {
42
+ type: 'block-scalar';
43
+ offset: number;
44
+ indent: number;
45
+ props: Token[];
46
+ source: string;
47
+ }
48
+ export interface BlockMap {
49
+ type: 'block-map';
50
+ offset: number;
51
+ indent: number;
52
+ items: Array<{
53
+ start: SourceToken[];
54
+ key?: never;
55
+ sep?: never;
56
+ value?: never;
57
+ } | {
58
+ start: SourceToken[];
59
+ key: Token | null;
60
+ sep: SourceToken[];
61
+ value?: Token;
62
+ }>;
63
+ }
64
+ export interface BlockSequence {
65
+ type: 'block-seq';
66
+ offset: number;
67
+ indent: number;
68
+ items: Array<{
69
+ start: SourceToken[];
70
+ key?: never;
71
+ sep?: never;
72
+ value?: Token;
73
+ }>;
74
+ }
75
+ export type CollectionItem = {
76
+ start: SourceToken[];
77
+ key?: Token | null;
78
+ sep?: SourceToken[];
79
+ value?: Token;
80
+ };
81
+ export interface FlowCollection {
82
+ type: 'flow-collection';
83
+ offset: number;
84
+ indent: number;
85
+ start: SourceToken;
86
+ items: CollectionItem[];
87
+ end: SourceToken[];
88
+ }
89
+ export type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
90
+ export type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
91
+ /** The byte order mark */
92
+ export declare const BOM = "\uFEFF";
93
+ /** Start of doc-mode */
94
+ export declare const DOCUMENT = "\u0002";
95
+ /** Unexpected end of flow-mode */
96
+ export declare const FLOW_END = "\u0018";
97
+ /** Next token is a scalar value */
98
+ export declare const SCALAR = "\u001F";
99
+ /** @returns `true` if `token` is a flow or block collection */
100
+ export declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
101
+ /** @returns `true` if `token` is a flow or block scalar; not an alias */
102
+ export declare const isScalar: (token: Token | null | undefined) => token is BlockScalar | FlowScalar;
103
+ /** Get a printable representation of a lexer token */
104
+ export declare function prettyToken(token: string): string;
105
+ /** Identify the type of a lexer token. May return `null` for unknown tokens. */
106
+ export declare function tokenType(source: string): TokenType | null;
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ var cstScalar = require('./cst-scalar.js');
4
+ var cstStringify = require('./cst-stringify.js');
5
+ var cstVisit = require('./cst-visit.js');
6
+
7
+ /** The byte order mark */
8
+ const BOM = '\u{FEFF}';
9
+ /** Start of doc-mode */
10
+ const DOCUMENT = '\x02'; // C0: Start of Text
11
+ /** Unexpected end of flow-mode */
12
+ const FLOW_END = '\x18'; // C0: Cancel
13
+ /** Next token is a scalar value */
14
+ const SCALAR = '\x1f'; // C0: Unit Separator
15
+ /** @returns `true` if `token` is a flow or block collection */
16
+ const isCollection = (token) => !!token && 'items' in token;
17
+ /** @returns `true` if `token` is a flow or block scalar; not an alias */
18
+ const isScalar = (token) => !!token &&
19
+ (token.type === 'scalar' ||
20
+ token.type === 'single-quoted-scalar' ||
21
+ token.type === 'double-quoted-scalar' ||
22
+ token.type === 'block-scalar');
23
+ /* istanbul ignore next */
24
+ /** Get a printable representation of a lexer token */
25
+ function prettyToken(token) {
26
+ switch (token) {
27
+ case BOM:
28
+ return '<BOM>';
29
+ case DOCUMENT:
30
+ return '<DOC>';
31
+ case FLOW_END:
32
+ return '<FLOW_END>';
33
+ case SCALAR:
34
+ return '<SCALAR>';
35
+ default:
36
+ return JSON.stringify(token);
37
+ }
38
+ }
39
+ /** Identify the type of a lexer token. May return `null` for unknown tokens. */
40
+ function tokenType(source) {
41
+ switch (source) {
42
+ case BOM:
43
+ return 'byte-order-mark';
44
+ case DOCUMENT:
45
+ return 'doc-mode';
46
+ case FLOW_END:
47
+ return 'flow-error-end';
48
+ case SCALAR:
49
+ return 'scalar';
50
+ case '---':
51
+ return 'doc-start';
52
+ case '...':
53
+ return 'doc-end';
54
+ case '':
55
+ case '\n':
56
+ case '\r\n':
57
+ return 'newline';
58
+ case '-':
59
+ return 'seq-item-ind';
60
+ case '?':
61
+ return 'explicit-key-ind';
62
+ case ':':
63
+ return 'map-value-ind';
64
+ case '{':
65
+ return 'flow-map-start';
66
+ case '}':
67
+ return 'flow-map-end';
68
+ case '[':
69
+ return 'flow-seq-start';
70
+ case ']':
71
+ return 'flow-seq-end';
72
+ case ',':
73
+ return 'comma';
74
+ }
75
+ switch (source[0]) {
76
+ case ' ':
77
+ case '\t':
78
+ return 'space';
79
+ case '#':
80
+ return 'comment';
81
+ case '%':
82
+ return 'directive-line';
83
+ case '*':
84
+ return 'alias';
85
+ case '&':
86
+ return 'anchor';
87
+ case '!':
88
+ return 'tag';
89
+ case "'":
90
+ return 'single-quoted-scalar';
91
+ case '"':
92
+ return 'double-quoted-scalar';
93
+ case '|':
94
+ case '>':
95
+ return 'block-scalar-header';
96
+ }
97
+ return null;
98
+ }
99
+
100
+ exports.createScalarToken = cstScalar.createScalarToken;
101
+ exports.resolveAsScalar = cstScalar.resolveAsScalar;
102
+ exports.setScalarValue = cstScalar.setScalarValue;
103
+ exports.stringify = cstStringify.stringify;
104
+ exports.visit = cstVisit.visit;
105
+ exports.BOM = BOM;
106
+ exports.DOCUMENT = DOCUMENT;
107
+ exports.FLOW_END = FLOW_END;
108
+ exports.SCALAR = SCALAR;
109
+ exports.isCollection = isCollection;
110
+ exports.isScalar = isScalar;
111
+ exports.prettyToken = prettyToken;
112
+ exports.tokenType = tokenType;