@intentius/chant 0.104.0 → 0.104.1
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/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/vendor/js-yaml-load.test.ts +115 -0
- package/src/vendor/js-yaml-load.ts +1939 -0
- package/src/yaml.ts +31 -21
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare class YAMLException extends Error {
|
|
2
|
+
reason: string;
|
|
3
|
+
mark: {
|
|
4
|
+
line: number;
|
|
5
|
+
column: number;
|
|
6
|
+
position: number;
|
|
7
|
+
name: string | null;
|
|
8
|
+
buffer: string;
|
|
9
|
+
};
|
|
10
|
+
constructor(reason: any, mark: any);
|
|
11
|
+
}
|
|
12
|
+
export declare const NULL_TYPE: {
|
|
13
|
+
tag: string;
|
|
14
|
+
kind: string;
|
|
15
|
+
resolve: (data: any) => boolean;
|
|
16
|
+
construct: () => null;
|
|
17
|
+
};
|
|
18
|
+
declare function resolveYamlInteger(data: any): boolean;
|
|
19
|
+
declare function parseYamlInteger(data: any): number;
|
|
20
|
+
export declare const INT_TYPE: {
|
|
21
|
+
tag: string;
|
|
22
|
+
kind: string;
|
|
23
|
+
resolve: typeof resolveYamlInteger;
|
|
24
|
+
construct: typeof parseYamlInteger;
|
|
25
|
+
};
|
|
26
|
+
declare function resolveYamlFloat(data: any): boolean;
|
|
27
|
+
export declare const FLOAT_TYPE: {
|
|
28
|
+
tag: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
resolve: typeof resolveYamlFloat;
|
|
31
|
+
construct: (data: any) => number;
|
|
32
|
+
};
|
|
33
|
+
export declare const STR_TYPE: {
|
|
34
|
+
tag: string;
|
|
35
|
+
kind: string;
|
|
36
|
+
construct: (data: any) => any;
|
|
37
|
+
};
|
|
38
|
+
export declare const SEQ_TYPE: {
|
|
39
|
+
tag: string;
|
|
40
|
+
kind: string;
|
|
41
|
+
construct: (data: any) => any;
|
|
42
|
+
};
|
|
43
|
+
export declare const MAP_TYPE: {
|
|
44
|
+
tag: string;
|
|
45
|
+
kind: string;
|
|
46
|
+
construct: (data: any) => any;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Read one YAML document. `types.implicit` lists the scalar types tried in
|
|
50
|
+
* order on untagged scalars; `types.explicit` lists those reachable by tag.
|
|
51
|
+
* Returns `undefined` for an empty stream and throws {@link YAMLException}
|
|
52
|
+
* on malformed input or more than one document.
|
|
53
|
+
*/
|
|
54
|
+
export declare function load(input: any, types: any): any;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=js-yaml-load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-yaml-load.d.ts","sourceRoot":"","sources":["../../src/vendor/js-yaml-load.ts"],"names":[],"mappings":"AAoCA,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9F,YAAY,MAAM,KAAA,EAAE,IAAI,KAAA,EAKvB;CACF;AAeD,eAAO,MAAM,SAAS;;;;;CAKrB,CAAC;AAMF,iBAAS,kBAAkB,CAAE,IAAI,KAAA,WAyChC;AAED,iBAAS,gBAAgB,CAAE,IAAI,KAAA,UAqB9B;AAED,eAAO,MAAM,QAAQ;IACnB,GAAG;IACH,IAAI;IACJ,OAAO;IACP,SAAS;CACV,CAAA;AAWD,iBAAS,gBAAgB,CAAE,IAAI,KAAA,WAK9B;AAED,eAAO,MAAM,UAAU;;;;;CAYtB,CAAA;AAED,eAAO,MAAM,QAAQ;;;;CAAqG,CAAC;AAC3H,eAAO,MAAM,QAAQ;;;;CAAuG,CAAC;AAC7H,eAAO,MAAM,QAAQ;;;;CAAsG,CAAC;AAqsD5H;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,KAAK,KAAA,EAAE,KAAK,KAAA,OAuBhC"}
|
package/dist/yaml.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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.
|
package/dist/yaml.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAqCH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAsH/D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAI,GAAG,MAAM,CAG7E;AAMD;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAIxC;CACF;AAmID;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQlE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO1D;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAc5D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAwBlD"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import * as upstream from "js-yaml";
|
|
3
|
+
import { FLOAT_TYPE, INT_TYPE, load, MAP_TYPE, NULL_TYPE, SEQ_TYPE, STR_TYPE, YAMLException } from "./js-yaml-load";
|
|
4
|
+
|
|
5
|
+
const BOOL_TYPE = {
|
|
6
|
+
tag: "tag:yaml.org,2002:bool",
|
|
7
|
+
kind: "scalar",
|
|
8
|
+
resolve: (d: string | null) => d !== null && /^(?:true|True|TRUE|false|False|FALSE)$/.test(d),
|
|
9
|
+
construct: (d: string) => /^(?:true|True|TRUE)$/.test(d),
|
|
10
|
+
};
|
|
11
|
+
const MERGE_TYPE = { tag: "tag:yaml.org,2002:merge", kind: "scalar", resolve: (d: string | null) => d === "<<" || d === null };
|
|
12
|
+
|
|
13
|
+
const TYPES = {
|
|
14
|
+
implicit: [NULL_TYPE, BOOL_TYPE, INT_TYPE, FLOAT_TYPE, MERGE_TYPE],
|
|
15
|
+
explicit: [STR_TYPE, SEQ_TYPE, MAP_TYPE],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Documents spanning the loader's paths: block and flow collections, every scalar style, anchors, tags, merge keys. */
|
|
19
|
+
const OPTIONS = { schema: upstream.CORE_SCHEMA.extend({ implicit: [new upstream.Type("tag:yaml.org,2002:merge", { kind: "scalar", resolve: (d: string | null) => d === "<<" || d === null })] }), json: true };
|
|
20
|
+
|
|
21
|
+
const VALID = [
|
|
22
|
+
"",
|
|
23
|
+
"a: 1\nb: [1, 2, {c: d}]\n",
|
|
24
|
+
"- a\n- b: 1\n c: 2\n-\n - x\n - y\n",
|
|
25
|
+
"s: 'it''s'\nd: \"tab\\t \\u00e9 \\x41 \\\n folded\"\n",
|
|
26
|
+
"lit: |\n one\n two\n\nfold: >-\n a\n b\n\n c\nkeep: |+\n x\n\n",
|
|
27
|
+
"base: &b {x: 1}\nuse: *b\nm:\n <<: *b\n y: 2\n",
|
|
28
|
+
"n: ~\nm: null\nt: true\nT: True\nf: FALSE\nyes_: yes\n",
|
|
29
|
+
"big: 1e999\nz: 0x\ny: -0\n",
|
|
30
|
+
"i: 12\nh: 0x1F\no: 0o17\nbin: 0b101\nu: 1_000\nneg: -5\nfl: 1.5e3\ninf: .inf\nnan: .NaN\nd: .5\n",
|
|
31
|
+
"? complex\n: value\n? [a, b]\n: seq key\n",
|
|
32
|
+
"!!str 123: !!int '7'\nq: !!map {a: 1}\nz: !!seq [1]\n",
|
|
33
|
+
"key with spaces: value # comment\n# full comment\nother: 'x' # trailing\n",
|
|
34
|
+
"multi: first line\n second line\n third\n",
|
|
35
|
+
"a:\n b:\n c:\n - 1\n - 2\n",
|
|
36
|
+
"dup: 1\ndup: 2\n",
|
|
37
|
+
"{a: 1, b: [x, y], c: {d: e}}",
|
|
38
|
+
"[1, 2, 3]",
|
|
39
|
+
"\ufeffa: bom\n",
|
|
40
|
+
"a: 1\r\nb: 2\r\n",
|
|
41
|
+
"%YAML 1.2\n---\na: 1\n",
|
|
42
|
+
"__proto__: 1\nconstructor: 2\n",
|
|
43
|
+
"emoji: \"\\U0001F600\"\nunicode: héllo ✓\n",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const INVALID = [
|
|
47
|
+
"[".repeat(200),
|
|
48
|
+
"a: 99999999999999999999999999\n" + "b: " + "[".repeat(150) + "]".repeat(150) + "\n",
|
|
49
|
+
"a: 1\njust text\nb: 2\n",
|
|
50
|
+
"a: [1, 2\n",
|
|
51
|
+
"a: 'unterminated\n",
|
|
52
|
+
"a: &x 1\nb: *y\n",
|
|
53
|
+
"- a\nb: 1\n",
|
|
54
|
+
"a:\n\t- b\n",
|
|
55
|
+
"a: !!binary x\n",
|
|
56
|
+
"a: 1\n---\nb: 2\n",
|
|
57
|
+
"a: \"bad \\q escape\"\n",
|
|
58
|
+
"a: b: c\n",
|
|
59
|
+
"a\u0000b: 1\n",
|
|
60
|
+
"{a: 1, a",
|
|
61
|
+
"%YAML 1.2\n%YAML 1.2\n---\na: 1\n",
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
function outcome(fn: () => unknown): { ok: true; value: unknown } | { ok: false; reason: string; line: number | undefined } {
|
|
65
|
+
try {
|
|
66
|
+
return { ok: true, value: fn() };
|
|
67
|
+
} catch (err) {
|
|
68
|
+
const e = err as { reason: string; mark?: { line: number; column: number; position: number } };
|
|
69
|
+
return { ok: false, reason: e.reason, line: e.mark?.line };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe("vendored js-yaml loader", () => {
|
|
74
|
+
for (const text of VALID) {
|
|
75
|
+
test(`reads ${JSON.stringify(text.slice(0, 40))} as js-yaml does`, () => {
|
|
76
|
+
const mine = outcome(() => load(text, TYPES));
|
|
77
|
+
const theirs = outcome(() => upstream.load(text, OPTIONS));
|
|
78
|
+
expect(mine.ok).toBe(true);
|
|
79
|
+
expect(mine).toEqual(theirs);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const text of INVALID) {
|
|
84
|
+
test(`rejects ${JSON.stringify(text.slice(0, 40))} with js-yaml's reason and line`, () => {
|
|
85
|
+
const mine = outcome(() => load(text, TYPES));
|
|
86
|
+
const theirs = outcome(() => upstream.load(text, OPTIONS));
|
|
87
|
+
expect(mine.ok).toBe(false);
|
|
88
|
+
expect(mine).toEqual(theirs);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
test("throws YAMLException carrying a reason and a position", () => {
|
|
93
|
+
try {
|
|
94
|
+
load("a: [1\n", TYPES);
|
|
95
|
+
expect.unreachable();
|
|
96
|
+
} catch (err) {
|
|
97
|
+
expect(err).toBeInstanceOf(YAMLException);
|
|
98
|
+
expect((err as YAMLException).reason).toBeTruthy();
|
|
99
|
+
expect((err as { mark: { line: number } }).mark.line).toBe(1);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("an empty stream is undefined", () => {
|
|
104
|
+
expect(load("", TYPES)).toBeUndefined();
|
|
105
|
+
expect(load("# only a comment\n", TYPES)).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a custom multi tag type is consulted by prefix", () => {
|
|
109
|
+
const types = {
|
|
110
|
+
implicit: TYPES.implicit,
|
|
111
|
+
explicit: [...TYPES.explicit, { tag: "!", kind: "scalar", multi: true, construct: (d: string, tag: string) => `${tag}:${d}` }],
|
|
112
|
+
};
|
|
113
|
+
expect(load("a: !Ref x\n", types)).toEqual({ a: "!Ref:x" });
|
|
114
|
+
});
|
|
115
|
+
});
|