@intentius/chant 0.104.0 → 0.104.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.
- package/dist/op/activities/factory.d.ts.map +1 -1
- package/dist/vendor/js-yaml-load.d.ts +56 -0
- package/dist/vendor/js-yaml-load.d.ts.map +1 -0
- package/dist/yaml.d.ts +1 -1
- package/dist/yaml.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/op/activities/factory.ts +13 -4
- package/src/op/factory.e2e.test.ts +14 -0
- package/src/vendor/js-yaml-load.test.ts +115 -0
- package/src/vendor/js-yaml-load.ts +1939 -0
- package/src/yaml.ts +31 -21
package/src/yaml.ts
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
* YAML emitter and parser.
|
|
3
3
|
*
|
|
4
4
|
* The emitter writes the block-style YAML chant's serializers produce. The
|
|
5
|
-
* parser is js-yaml with chant's schema (#3006): YAML 1.2 core types,
|
|
5
|
+
* parser is a vendored js-yaml loader with chant's schema (#3006): YAML 1.2 core types,
|
|
6
6
|
* merge keys, `yes`/`no` booleans, and local tags such as `!reference` read
|
|
7
7
|
* as strings. `splitYAMLDocuments` splits a multi-document stream. Input the
|
|
8
8
|
* parser cannot read throws a `YAMLParseError` naming the line.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
FLOAT_TYPE,
|
|
13
|
+
INT_TYPE,
|
|
14
|
+
load,
|
|
15
|
+
MAP_TYPE,
|
|
16
|
+
NULL_TYPE,
|
|
17
|
+
SEQ_TYPE,
|
|
18
|
+
STR_TYPE,
|
|
19
|
+
YAMLException,
|
|
20
|
+
} from "./vendor/js-yaml-load";
|
|
12
21
|
|
|
13
22
|
// ---------------------------------------------------------------------------
|
|
14
23
|
// Emitter
|
|
@@ -191,14 +200,12 @@ const DOCUMENT_MARKER = /^(?:---|\.\.\.)(?:[ \t]+#.*)?[ \t]*$/;
|
|
|
191
200
|
* Booleans as YAML 1.2's core schema reads them, plus `yes` and `no`, which
|
|
192
201
|
* this parser has always read as booleans and its callers expect.
|
|
193
202
|
*/
|
|
194
|
-
const BOOL =
|
|
203
|
+
const BOOL = {
|
|
204
|
+
tag: "tag:yaml.org,2002:bool",
|
|
195
205
|
kind: "scalar",
|
|
196
206
|
resolve: (data: string | null) => data !== null && /^(?:true|True|TRUE|false|False|FALSE|yes|no)$/.test(data),
|
|
197
207
|
construct: (data: string) => /^(?:true|True|TRUE|yes)$/.test(data),
|
|
198
|
-
|
|
199
|
-
represent: { lowercase: (value: object) => (value ? "true" : "false") },
|
|
200
|
-
defaultStyle: "lowercase",
|
|
201
|
-
});
|
|
208
|
+
};
|
|
202
209
|
|
|
203
210
|
/** A tagged value written back as text, the way it appeared: `!reference [.base, script]`. */
|
|
204
211
|
function flowText(value: unknown): string {
|
|
@@ -215,31 +222,34 @@ function flowText(value: unknown): string {
|
|
|
215
222
|
* `!reference [.base, script]` is the string `"!reference [.base, script]"`.
|
|
216
223
|
* A tag on a mapping has no such form and is an error.
|
|
217
224
|
*/
|
|
218
|
-
const TAGGED_SCALAR =
|
|
225
|
+
const TAGGED_SCALAR = {
|
|
226
|
+
tag: "!",
|
|
219
227
|
kind: "scalar",
|
|
220
228
|
multi: true,
|
|
221
229
|
construct: (data: string | null, tag?: string) => (data === null || data === "" ? tag : `${tag} ${data}`),
|
|
222
|
-
}
|
|
223
|
-
const TAGGED_SEQUENCE =
|
|
230
|
+
};
|
|
231
|
+
const TAGGED_SEQUENCE = {
|
|
232
|
+
tag: "!",
|
|
224
233
|
kind: "sequence",
|
|
225
234
|
multi: true,
|
|
226
235
|
construct: (data: unknown[] | null, tag?: string) => `${tag} ${flowText(data ?? [])}`,
|
|
227
|
-
}
|
|
236
|
+
};
|
|
228
237
|
|
|
229
|
-
/** The merge key `<<`, as js-yaml's own merge type reads it
|
|
230
|
-
const MERGE =
|
|
238
|
+
/** The merge key `<<`, as js-yaml's own merge type reads it. */
|
|
239
|
+
const MERGE = {
|
|
240
|
+
tag: "tag:yaml.org,2002:merge",
|
|
231
241
|
kind: "scalar",
|
|
232
242
|
resolve: (data: string | null) => data === "<<" || data === null,
|
|
233
|
-
}
|
|
243
|
+
};
|
|
234
244
|
|
|
235
245
|
/**
|
|
236
246
|
* YAML 1.2's core schema (no timestamps, so a date stays a string) with merge
|
|
237
247
|
* keys, `yes`/`no` booleans and local tags read as strings.
|
|
238
248
|
*/
|
|
239
|
-
const SCHEMA =
|
|
240
|
-
implicit: [BOOL, MERGE],
|
|
241
|
-
explicit: [TAGGED_SCALAR, TAGGED_SEQUENCE],
|
|
242
|
-
}
|
|
249
|
+
const SCHEMA = {
|
|
250
|
+
implicit: [NULL_TYPE, BOOL, INT_TYPE, FLOAT_TYPE, MERGE],
|
|
251
|
+
explicit: [STR_TYPE, SEQ_TYPE, MAP_TYPE, TAGGED_SCALAR, TAGGED_SEQUENCE],
|
|
252
|
+
};
|
|
243
253
|
|
|
244
254
|
/**
|
|
245
255
|
* Give every alias its own copy of the anchored value. js-yaml shares one
|
|
@@ -266,7 +276,7 @@ function unshareAliases(value: unknown, seen = new Set<object>()): unknown {
|
|
|
266
276
|
* multiline key. Report the line where that key starts instead, the text
|
|
267
277
|
* that is not a key.
|
|
268
278
|
*/
|
|
269
|
-
function errorLine(lines: string[], err:
|
|
279
|
+
function errorLine(lines: string[], err: YAMLException): number {
|
|
270
280
|
let line = err.mark?.line ?? 0;
|
|
271
281
|
if (/multiline key may not be an implicit key/.test(err.reason)) {
|
|
272
282
|
const indent = lines[line]?.search(/\S/) ?? -1;
|
|
@@ -297,9 +307,9 @@ function loadDocument(content: string): unknown {
|
|
|
297
307
|
.join("\n");
|
|
298
308
|
let value: unknown;
|
|
299
309
|
try {
|
|
300
|
-
value =
|
|
310
|
+
value = load(text, SCHEMA);
|
|
301
311
|
} catch (err) {
|
|
302
|
-
if (!(err instanceof
|
|
312
|
+
if (!(err instanceof YAMLException)) throw err;
|
|
303
313
|
const line = errorLine(text.split("\n"), err);
|
|
304
314
|
const tag = err.reason.match(/^unknown tag !<(![^>]*)>/)?.[1];
|
|
305
315
|
throw new YAMLParseError(line, tag ? `the tag ${JSON.stringify(tag)} on a mapping is not supported` : err.reason);
|