yaml 2.0.1 → 2.1.0
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/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-doc.js +2 -2
- package/browser/dist/compose/compose-scalar.js +6 -7
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +5 -6
- package/browser/dist/compose/resolve-block-scalar.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +3 -4
- package/browser/dist/compose/resolve-flow-scalar.js +1 -2
- package/browser/dist/compose/resolve-props.js +2 -2
- package/browser/dist/compose/util-empty-scalar-position.js +1 -1
- package/browser/dist/compose/util-flow-indent-check.js +1 -1
- package/browser/dist/doc/Document.js +6 -6
- package/browser/dist/doc/createNode.js +5 -7
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -7
- package/browser/dist/nodes/YAMLSeq.js +1 -9
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/parse/cst-scalar.js +1 -2
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +1 -2
- package/browser/dist/parse/parser.js +10 -14
- package/browser/dist/public-api.js +3 -4
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -2
- package/browser/dist/schema/yaml-1.1/set.js +4 -0
- package/browser/dist/stringify/stringify.js +6 -8
- package/browser/dist/stringify/stringifyCollection.js +1 -2
- package/browser/dist/stringify/stringifyDocument.js +1 -2
- package/browser/dist/stringify/stringifyString.js +2 -2
- package/browser/dist/visit.js +5 -6
- package/dist/compose/compose-collection.js +1 -1
- package/dist/compose/compose-doc.js +2 -2
- package/dist/compose/compose-scalar.js +6 -7
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.js +5 -6
- package/dist/compose/resolve-block-scalar.js +1 -1
- package/dist/compose/resolve-flow-collection.js +3 -4
- package/dist/compose/resolve-flow-scalar.js +1 -2
- package/dist/compose/resolve-props.js +2 -2
- package/dist/compose/util-empty-scalar-position.js +1 -1
- package/dist/compose/util-flow-indent-check.js +1 -1
- package/dist/doc/Document.d.ts +10 -10
- package/dist/doc/Document.js +6 -6
- package/dist/doc/anchors.d.ts +1 -1
- package/dist/doc/createNode.js +5 -7
- package/dist/index.d.ts +2 -0
- package/dist/nodes/Collection.d.ts +2 -2
- package/dist/nodes/Collection.js +2 -1
- package/dist/nodes/Node.d.ts +14 -10
- package/dist/nodes/Pair.d.ts +1 -1
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +6 -3
- package/dist/nodes/YAMLMap.js +6 -7
- package/dist/nodes/YAMLSeq.d.ts +4 -1
- package/dist/nodes/YAMLSeq.js +1 -9
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +1 -1
- package/dist/options.d.ts +2 -1
- package/dist/parse/cst-scalar.js +1 -2
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +1 -2
- package/dist/parse/parser.js +10 -14
- package/dist/public-api.js +3 -4
- package/dist/schema/Schema.js +1 -1
- package/dist/schema/json-schema.d.ts +69 -0
- package/dist/schema/yaml-1.1/omap.d.ts +7 -3
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +1 -2
- package/dist/schema/yaml-1.1/set.d.ts +6 -2
- package/dist/schema/yaml-1.1/set.js +4 -0
- package/dist/stringify/stringify.js +6 -8
- package/dist/stringify/stringifyCollection.js +1 -2
- package/dist/stringify/stringifyDocument.js +1 -2
- package/dist/stringify/stringifyString.js +2 -2
- package/dist/test-events.js +2 -3
- package/dist/visit.js +5 -6
- package/package.json +3 -3
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
package/dist/nodes/Node.d.ts
CHANGED
|
@@ -6,9 +6,13 @@ import type { Pair } from './Pair.js';
|
|
|
6
6
|
import type { Scalar } from './Scalar.js';
|
|
7
7
|
import type { YAMLMap } from './YAMLMap.js';
|
|
8
8
|
import type { YAMLSeq } from './YAMLSeq.js';
|
|
9
|
-
export declare type Node = Alias | Scalar | YAMLMap | YAMLSeq
|
|
9
|
+
export declare type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
|
|
10
|
+
/** Utility type mapper */
|
|
11
|
+
export declare type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
|
|
12
|
+
[key: string | number]: any;
|
|
13
|
+
} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
|
|
10
14
|
export declare type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
|
|
11
|
-
export declare type Range = [number, number, number];
|
|
15
|
+
export declare type Range = [start: number, valueEnd: number, nodeEnd: number];
|
|
12
16
|
export declare const ALIAS: unique symbol;
|
|
13
17
|
export declare const DOC: unique symbol;
|
|
14
18
|
export declare const MAP: unique symbol;
|
|
@@ -17,14 +21,14 @@ export declare const SCALAR: unique symbol;
|
|
|
17
21
|
export declare const SEQ: unique symbol;
|
|
18
22
|
export declare const NODE_TYPE: unique symbol;
|
|
19
23
|
export declare const isAlias: (node: any) => node is Alias;
|
|
20
|
-
export declare const isDocument: (node: any) => node is Document<
|
|
21
|
-
export declare const isMap: (node: any) => node is YAMLMap<
|
|
22
|
-
export declare const isPair: (node: any) => node is Pair<
|
|
23
|
-
export declare const isScalar: (node: any) => node is Scalar<
|
|
24
|
-
export declare const isSeq: (node: any) => node is YAMLSeq<
|
|
25
|
-
export declare function isCollection(node: any): node is YAMLMap | YAMLSeq
|
|
26
|
-
export declare function isNode(node: any): node is Node
|
|
27
|
-
export declare const hasAnchor: (node: unknown) => node is Scalar<
|
|
24
|
+
export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
|
|
25
|
+
export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
|
|
26
|
+
export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
|
|
27
|
+
export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
|
|
28
|
+
export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
|
|
29
|
+
export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
|
|
30
|
+
export declare function isNode<T = unknown>(node: any): node is Node<T>;
|
|
31
|
+
export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
|
|
28
32
|
export declare abstract class NodeBase {
|
|
29
33
|
readonly [NODE_TYPE]: symbol;
|
|
30
34
|
/** A comment on or immediately after this */
|
package/dist/nodes/Pair.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
5
5
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
6
6
|
import { NODE_TYPE } from './Node.js';
|
|
7
7
|
import type { ToJSContext } from './toJS.js';
|
|
8
|
-
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node
|
|
8
|
+
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node<unknown>, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
|
|
9
9
|
export declare class Pair<K = unknown, V = unknown> {
|
|
10
10
|
readonly [NODE_TYPE]: symbol;
|
|
11
11
|
/** Always Node or null when parsed, but can be set to anything. */
|
package/dist/nodes/Pair.js
CHANGED
|
@@ -25,11 +25,11 @@ class Pair {
|
|
|
25
25
|
return new Pair(key, value);
|
|
26
26
|
}
|
|
27
27
|
toJSON(_, ctx) {
|
|
28
|
-
const pair =
|
|
28
|
+
const pair = ctx?.mapAsMap ? new Map() : {};
|
|
29
29
|
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
|
30
30
|
}
|
|
31
31
|
toString(ctx, onComment, onChompKeep) {
|
|
32
|
-
return
|
|
32
|
+
return ctx?.doc
|
|
33
33
|
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
|
|
34
34
|
: JSON.stringify(this);
|
|
35
35
|
}
|
package/dist/nodes/Scalar.js
CHANGED
|
@@ -10,7 +10,7 @@ class Scalar extends Node.NodeBase {
|
|
|
10
10
|
this.value = value;
|
|
11
11
|
}
|
|
12
12
|
toJSON(arg, ctx) {
|
|
13
|
-
return
|
|
13
|
+
return ctx?.keep ? this.value : toJS.toJS(this.value, arg, ctx);
|
|
14
14
|
}
|
|
15
15
|
toString() {
|
|
16
16
|
return String(this.value);
|
package/dist/nodes/YAMLMap.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
4
4
|
import { Collection } from './Collection.js';
|
|
5
5
|
import { ParsedNode, Range } from './Node.js';
|
|
6
6
|
import { Pair } from './Pair.js';
|
|
7
|
+
import { Scalar } from './Scalar.js';
|
|
7
8
|
import type { ToJSContext } from './toJS.js';
|
|
8
9
|
export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
|
|
9
10
|
export declare namespace YAMLMap {
|
|
@@ -27,9 +28,11 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
|
|
27
28
|
key: K;
|
|
28
29
|
value: V;
|
|
29
30
|
}, overwrite?: boolean): void;
|
|
30
|
-
delete(key:
|
|
31
|
-
get(key:
|
|
32
|
-
|
|
31
|
+
delete(key: unknown): boolean;
|
|
32
|
+
get(key: unknown, keepScalar: true): Scalar<V> | undefined;
|
|
33
|
+
get(key: unknown, keepScalar?: false): V | undefined;
|
|
34
|
+
get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
|
|
35
|
+
has(key: unknown): boolean;
|
|
33
36
|
set(key: K, value: V): void;
|
|
34
37
|
/**
|
|
35
38
|
* @param ctx - Conversion context, originally set in Document#toJS()
|
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -34,18 +34,17 @@ class YAMLMap extends Collection.Collection {
|
|
|
34
34
|
* collection will throw. Otherwise, overwrites the previous value.
|
|
35
35
|
*/
|
|
36
36
|
add(pair, overwrite) {
|
|
37
|
-
var _a;
|
|
38
37
|
let _pair;
|
|
39
38
|
if (Node.isPair(pair))
|
|
40
39
|
_pair = pair;
|
|
41
40
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
42
41
|
// In TypeScript, this never happens.
|
|
43
|
-
_pair = new Pair.Pair(pair, pair
|
|
42
|
+
_pair = new Pair.Pair(pair, pair?.value);
|
|
44
43
|
}
|
|
45
44
|
else
|
|
46
45
|
_pair = new Pair.Pair(pair.key, pair.value);
|
|
47
46
|
const prev = findPair(this.items, _pair.key);
|
|
48
|
-
const sortEntries =
|
|
47
|
+
const sortEntries = this.schema?.sortMapEntries;
|
|
49
48
|
if (prev) {
|
|
50
49
|
if (!overwrite)
|
|
51
50
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -75,8 +74,8 @@ class YAMLMap extends Collection.Collection {
|
|
|
75
74
|
}
|
|
76
75
|
get(key, keepScalar) {
|
|
77
76
|
const it = findPair(this.items, key);
|
|
78
|
-
const node = it
|
|
79
|
-
return !keepScalar && Node.isScalar(node) ? node.value : node;
|
|
77
|
+
const node = it?.value;
|
|
78
|
+
return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
|
|
80
79
|
}
|
|
81
80
|
has(key) {
|
|
82
81
|
return !!findPair(this.items, key);
|
|
@@ -90,8 +89,8 @@ class YAMLMap extends Collection.Collection {
|
|
|
90
89
|
* @returns Instance of Type, Map, or Object
|
|
91
90
|
*/
|
|
92
91
|
toJSON(_, ctx, Type) {
|
|
93
|
-
const map = Type ? new Type() :
|
|
94
|
-
if (ctx
|
|
92
|
+
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
|
|
93
|
+
if (ctx?.onCreate)
|
|
95
94
|
ctx.onCreate(map);
|
|
96
95
|
for (const item of this.items)
|
|
97
96
|
addPairToJSMap.addPairToJSMap(ctx, map, item);
|
package/dist/nodes/YAMLSeq.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
|
|
|
4
4
|
import { Collection } from './Collection.js';
|
|
5
5
|
import { ParsedNode, Range } from './Node.js';
|
|
6
6
|
import type { Pair } from './Pair.js';
|
|
7
|
+
import { Scalar } from './Scalar.js';
|
|
7
8
|
import { ToJSContext } from './toJS.js';
|
|
8
9
|
export declare namespace YAMLSeq {
|
|
9
10
|
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
|
|
@@ -34,7 +35,9 @@ export declare class YAMLSeq<T = unknown> extends Collection {
|
|
|
34
35
|
* `key` must contain a representation of an integer for this to succeed.
|
|
35
36
|
* It may be wrapped in a `Scalar`.
|
|
36
37
|
*/
|
|
37
|
-
get(key: unknown, keepScalar
|
|
38
|
+
get(key: unknown, keepScalar: true): Scalar<T> | undefined;
|
|
39
|
+
get(key: unknown, keepScalar?: false): T | undefined;
|
|
40
|
+
get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
|
|
38
41
|
/**
|
|
39
42
|
* Checks if the collection includes a value with the key `key`.
|
|
40
43
|
*
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -32,14 +32,6 @@ class YAMLSeq extends Collection.Collection {
|
|
|
32
32
|
const del = this.items.splice(idx, 1);
|
|
33
33
|
return del.length > 0;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
37
|
-
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
38
|
-
* `true` (collections are always returned intact).
|
|
39
|
-
*
|
|
40
|
-
* `key` must contain a representation of an integer for this to succeed.
|
|
41
|
-
* It may be wrapped in a `Scalar`.
|
|
42
|
-
*/
|
|
43
35
|
get(key, keepScalar) {
|
|
44
36
|
const idx = asItemIndex(key);
|
|
45
37
|
if (typeof idx !== 'number')
|
|
@@ -76,7 +68,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
76
68
|
}
|
|
77
69
|
toJSON(_, ctx) {
|
|
78
70
|
const seq = [];
|
|
79
|
-
if (ctx
|
|
71
|
+
if (ctx?.onCreate)
|
|
80
72
|
ctx.onCreate(seq);
|
|
81
73
|
let i = 0;
|
|
82
74
|
for (const item of this.items)
|
|
@@ -8,7 +8,7 @@ var toJS = require('./toJS.js');
|
|
|
8
8
|
|
|
9
9
|
const MERGE_KEY = '<<';
|
|
10
10
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
11
|
-
if (
|
|
11
|
+
if (ctx?.doc.schema.merge && isMergeKey(key)) {
|
|
12
12
|
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
13
13
|
if (Node.isSeq(value))
|
|
14
14
|
for (const it of value.items)
|
package/dist/nodes/toJS.js
CHANGED
|
@@ -31,7 +31,7 @@ function toJS(value, arg, ctx) {
|
|
|
31
31
|
ctx.onCreate(res);
|
|
32
32
|
return res;
|
|
33
33
|
}
|
|
34
|
-
if (typeof value === 'bigint' && !
|
|
34
|
+
if (typeof value === 'bigint' && !ctx?.keep)
|
|
35
35
|
return Number(value);
|
|
36
36
|
return value;
|
|
37
37
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -58,10 +58,11 @@ export declare type ParseOptions = {
|
|
|
58
58
|
};
|
|
59
59
|
export declare type DocumentOptions = {
|
|
60
60
|
/**
|
|
61
|
+
* @internal
|
|
61
62
|
* Used internally by Composer. If set and includes an explicit version,
|
|
62
63
|
* that overrides the `version` option.
|
|
63
64
|
*/
|
|
64
|
-
|
|
65
|
+
_directives?: Directives;
|
|
65
66
|
/**
|
|
66
67
|
* Control the logging level during parsing
|
|
67
68
|
*
|
package/dist/parse/cst-scalar.js
CHANGED
|
@@ -40,7 +40,6 @@ function resolveAsScalar(token, strict = true, onError) {
|
|
|
40
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
41
|
*/
|
|
42
42
|
function createScalarToken(value, context) {
|
|
43
|
-
var _a;
|
|
44
43
|
const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
|
|
45
44
|
const source = stringifyString.stringifyString({ type, value }, {
|
|
46
45
|
implicitKey,
|
|
@@ -48,7 +47,7 @@ function createScalarToken(value, context) {
|
|
|
48
47
|
inFlow,
|
|
49
48
|
options: { blockQuote: true, lineWidth: -1 }
|
|
50
49
|
});
|
|
51
|
-
const end =
|
|
50
|
+
const end = context.end ?? [
|
|
52
51
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
53
52
|
];
|
|
54
53
|
switch (source[0]) {
|
package/dist/parse/cst-visit.js
CHANGED
|
@@ -49,7 +49,7 @@ visit.REMOVE = REMOVE;
|
|
|
49
49
|
visit.itemAtPath = (cst, path) => {
|
|
50
50
|
let item = cst;
|
|
51
51
|
for (const [field, index] of path) {
|
|
52
|
-
const tok = item
|
|
52
|
+
const tok = item?.[field];
|
|
53
53
|
if (tok && 'items' in tok) {
|
|
54
54
|
item = tok.items[index];
|
|
55
55
|
}
|
|
@@ -66,7 +66,7 @@ visit.itemAtPath = (cst, path) => {
|
|
|
66
66
|
visit.parentCollection = (cst, path) => {
|
|
67
67
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
68
68
|
const field = path[path.length - 1][0];
|
|
69
|
-
const coll = parent
|
|
69
|
+
const coll = parent?.[field];
|
|
70
70
|
if (coll && 'items' in coll)
|
|
71
71
|
return coll;
|
|
72
72
|
throw new Error('Parent collection not found');
|
package/dist/parse/lexer.js
CHANGED
|
@@ -150,13 +150,12 @@ class Lexer {
|
|
|
150
150
|
* @returns A generator of lexical tokens
|
|
151
151
|
*/
|
|
152
152
|
*lex(source, incomplete = false) {
|
|
153
|
-
var _a;
|
|
154
153
|
if (source) {
|
|
155
154
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
156
155
|
this.lineEndPos = null;
|
|
157
156
|
}
|
|
158
157
|
this.atEnd = !incomplete;
|
|
159
|
-
let next =
|
|
158
|
+
let next = this.next ?? 'stream';
|
|
160
159
|
while (next && (incomplete || this.hasChars(1)))
|
|
161
160
|
next = yield* this.parseNext(next);
|
|
162
161
|
}
|
package/dist/parse/parser.js
CHANGED
|
@@ -23,7 +23,7 @@ function findNonEmptyIndex(list) {
|
|
|
23
23
|
return -1;
|
|
24
24
|
}
|
|
25
25
|
function isFlowToken(token) {
|
|
26
|
-
switch (token
|
|
26
|
+
switch (token?.type) {
|
|
27
27
|
case 'alias':
|
|
28
28
|
case 'scalar':
|
|
29
29
|
case 'single-quoted-scalar':
|
|
@@ -35,13 +35,12 @@ function isFlowToken(token) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function getPrevProps(parent) {
|
|
38
|
-
var _a;
|
|
39
38
|
switch (parent.type) {
|
|
40
39
|
case 'document':
|
|
41
40
|
return parent.start;
|
|
42
41
|
case 'block-map': {
|
|
43
42
|
const it = parent.items[parent.items.length - 1];
|
|
44
|
-
return
|
|
43
|
+
return it.sep ?? it.start;
|
|
45
44
|
}
|
|
46
45
|
case 'block-seq':
|
|
47
46
|
return parent.items[parent.items.length - 1].start;
|
|
@@ -52,7 +51,6 @@ function getPrevProps(parent) {
|
|
|
52
51
|
}
|
|
53
52
|
/** Note: May modify input array */
|
|
54
53
|
function getFirstKeyStartProps(prev) {
|
|
55
|
-
var _a;
|
|
56
54
|
if (prev.length === 0)
|
|
57
55
|
return [];
|
|
58
56
|
let i = prev.length;
|
|
@@ -66,7 +64,7 @@ function getFirstKeyStartProps(prev) {
|
|
|
66
64
|
break loop;
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
|
-
while (
|
|
67
|
+
while (prev[++i]?.type === 'space') {
|
|
70
68
|
/* loop */
|
|
71
69
|
}
|
|
72
70
|
return prev.splice(i, prev.length);
|
|
@@ -270,7 +268,7 @@ class Parser {
|
|
|
270
268
|
return this.stack[this.stack.length - n];
|
|
271
269
|
}
|
|
272
270
|
*pop(error) {
|
|
273
|
-
const token = error
|
|
271
|
+
const token = error ?? this.stack.pop();
|
|
274
272
|
/* istanbul ignore if should not happen */
|
|
275
273
|
if (!token) {
|
|
276
274
|
const message = 'Tried to pop an empty stack';
|
|
@@ -475,7 +473,6 @@ class Parser {
|
|
|
475
473
|
}
|
|
476
474
|
}
|
|
477
475
|
*blockMap(map) {
|
|
478
|
-
var _a;
|
|
479
476
|
const it = map.items[map.items.length - 1];
|
|
480
477
|
// it.sep is true-ish if pair already has key or : separator
|
|
481
478
|
switch (this.type) {
|
|
@@ -484,8 +481,8 @@ class Parser {
|
|
|
484
481
|
if (it.value) {
|
|
485
482
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
486
483
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
487
|
-
if (
|
|
488
|
-
end
|
|
484
|
+
if (last?.type === 'comment')
|
|
485
|
+
end?.push(this.sourceToken);
|
|
489
486
|
else
|
|
490
487
|
map.items.push({ start: [this.sourceToken] });
|
|
491
488
|
}
|
|
@@ -507,7 +504,7 @@ class Parser {
|
|
|
507
504
|
else {
|
|
508
505
|
if (this.atIndentedComment(it.start, map.indent)) {
|
|
509
506
|
const prev = map.items[map.items.length - 2];
|
|
510
|
-
const end =
|
|
507
|
+
const end = prev?.value?.end;
|
|
511
508
|
if (Array.isArray(end)) {
|
|
512
509
|
Array.prototype.push.apply(end, it.start);
|
|
513
510
|
end.push(this.sourceToken);
|
|
@@ -684,15 +681,14 @@ class Parser {
|
|
|
684
681
|
yield* this.step();
|
|
685
682
|
}
|
|
686
683
|
*blockSequence(seq) {
|
|
687
|
-
var _a;
|
|
688
684
|
const it = seq.items[seq.items.length - 1];
|
|
689
685
|
switch (this.type) {
|
|
690
686
|
case 'newline':
|
|
691
687
|
if (it.value) {
|
|
692
688
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
693
689
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
694
|
-
if (
|
|
695
|
-
end
|
|
690
|
+
if (last?.type === 'comment')
|
|
691
|
+
end?.push(this.sourceToken);
|
|
696
692
|
else
|
|
697
693
|
seq.items.push({ start: [this.sourceToken] });
|
|
698
694
|
}
|
|
@@ -706,7 +702,7 @@ class Parser {
|
|
|
706
702
|
else {
|
|
707
703
|
if (this.atIndentedComment(it.start, seq.indent)) {
|
|
708
704
|
const prev = seq.items[seq.items.length - 2];
|
|
709
|
-
const end =
|
|
705
|
+
const end = prev?.value?.end;
|
|
710
706
|
if (Array.isArray(end)) {
|
|
711
707
|
Array.prototype.push.apply(end, it.start);
|
|
712
708
|
end.push(this.sourceToken);
|
package/dist/public-api.js
CHANGED
|
@@ -23,7 +23,7 @@ function parseOptions(options) {
|
|
|
23
23
|
*/
|
|
24
24
|
function parseAllDocuments(source, options = {}) {
|
|
25
25
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
26
|
-
const parser$1 = new parser.Parser(lineCounter
|
|
26
|
+
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
|
|
27
27
|
const composer$1 = new composer.Composer(options);
|
|
28
28
|
const docs = Array.from(composer$1.compose(parser$1.parse(source)));
|
|
29
29
|
if (prettyErrors && lineCounter)
|
|
@@ -38,7 +38,7 @@ function parseAllDocuments(source, options = {}) {
|
|
|
38
38
|
/** Parse an input string into a single YAML.Document */
|
|
39
39
|
function parseDocument(source, options = {}) {
|
|
40
40
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
41
|
-
const parser$1 = new parser.Parser(lineCounter
|
|
41
|
+
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
|
|
42
42
|
const composer$1 = new composer.Composer(options);
|
|
43
43
|
// `doc` is always set by compose.end(true) at the very latest
|
|
44
44
|
let doc = null;
|
|
@@ -77,7 +77,6 @@ function parse(src, reviver, options) {
|
|
|
77
77
|
return doc.toJS(Object.assign({ reviver: _reviver }, options));
|
|
78
78
|
}
|
|
79
79
|
function stringify(value, replacer, options) {
|
|
80
|
-
var _a;
|
|
81
80
|
let _replacer = null;
|
|
82
81
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
83
82
|
_replacer = replacer;
|
|
@@ -92,7 +91,7 @@ function stringify(value, replacer, options) {
|
|
|
92
91
|
options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
|
|
93
92
|
}
|
|
94
93
|
if (value === undefined) {
|
|
95
|
-
const { keepUndefined } =
|
|
94
|
+
const { keepUndefined } = options ?? replacer ?? {};
|
|
96
95
|
if (!keepUndefined)
|
|
97
96
|
return undefined;
|
|
98
97
|
}
|
package/dist/schema/Schema.js
CHANGED
|
@@ -18,7 +18,7 @@ class Schema {
|
|
|
18
18
|
this.name = (typeof schema === 'string' && schema) || 'core';
|
|
19
19
|
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
|
|
20
20
|
this.tags = tags.getTags(customTags, this.name);
|
|
21
|
-
this.toStringOptions = toStringDefaults
|
|
21
|
+
this.toStringOptions = toStringDefaults ?? null;
|
|
22
22
|
Object.defineProperty(this, Node.MAP, { value: map.map });
|
|
23
23
|
Object.defineProperty(this, Node.SCALAR, { value: string.string });
|
|
24
24
|
Object.defineProperty(this, Node.SEQ, { value: seq.seq });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare type JsonSchema = boolean | ArraySchema | ObjectSchema | NumberSchema | StringSchema;
|
|
2
|
+
declare type JsonType = 'array' | 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
3
|
+
interface CommonSchema {
|
|
4
|
+
type?: JsonType | JsonType[];
|
|
5
|
+
const?: unknown;
|
|
6
|
+
enum?: unknown[];
|
|
7
|
+
format?: string;
|
|
8
|
+
allOf?: JsonSchema[];
|
|
9
|
+
anyOf?: JsonSchema[];
|
|
10
|
+
oneOf?: JsonSchema[];
|
|
11
|
+
not?: JsonSchema;
|
|
12
|
+
if?: JsonSchema;
|
|
13
|
+
then?: JsonSchema;
|
|
14
|
+
else?: JsonSchema;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$defs?: Record<string, JsonSchema>;
|
|
17
|
+
$anchor?: string;
|
|
18
|
+
$dynamicAnchor?: string;
|
|
19
|
+
$ref?: string;
|
|
20
|
+
$dynamicRef?: string;
|
|
21
|
+
$schema?: string;
|
|
22
|
+
$vocabulary?: Record<string, boolean>;
|
|
23
|
+
$comment?: string;
|
|
24
|
+
default?: unknown;
|
|
25
|
+
deprecated?: boolean;
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
writeOnly?: boolean;
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
examples?: unknown[];
|
|
31
|
+
}
|
|
32
|
+
interface ArraySchema extends CommonSchema {
|
|
33
|
+
prefixItems?: JsonSchema[];
|
|
34
|
+
items?: JsonSchema;
|
|
35
|
+
contains?: JsonSchema;
|
|
36
|
+
unevaluatedItems?: JsonSchema;
|
|
37
|
+
maxItems?: number;
|
|
38
|
+
minItems?: number;
|
|
39
|
+
uniqueItems?: boolean;
|
|
40
|
+
maxContains?: number;
|
|
41
|
+
minContains?: number;
|
|
42
|
+
}
|
|
43
|
+
interface ObjectSchema extends CommonSchema {
|
|
44
|
+
properties?: Record<string, JsonSchema>;
|
|
45
|
+
patternProperties?: Record<string, JsonSchema>;
|
|
46
|
+
additionalProperties?: JsonSchema;
|
|
47
|
+
propertyNames?: JsonSchema;
|
|
48
|
+
unevaluatedProperties?: JsonSchema;
|
|
49
|
+
maxProperties?: number;
|
|
50
|
+
minProperties?: number;
|
|
51
|
+
required?: string[];
|
|
52
|
+
dependentRequired?: Record<string, string[]>;
|
|
53
|
+
dependentSchemas?: Record<string, JsonSchema>;
|
|
54
|
+
}
|
|
55
|
+
interface StringSchema extends CommonSchema {
|
|
56
|
+
maxLength?: number;
|
|
57
|
+
minLength?: number;
|
|
58
|
+
patter?: string;
|
|
59
|
+
contentEncoding?: string;
|
|
60
|
+
contentMediaType?: string;
|
|
61
|
+
contentSchema?: JsonSchema;
|
|
62
|
+
}
|
|
63
|
+
interface NumberSchema extends CommonSchema {
|
|
64
|
+
multipleOf?: number;
|
|
65
|
+
maximum?: number;
|
|
66
|
+
exclusiveMaximum?: number;
|
|
67
|
+
minimum?: number;
|
|
68
|
+
exclusiveMinimum?: number;
|
|
69
|
+
}
|
|
@@ -8,9 +8,13 @@ export declare class YAMLOMap extends YAMLSeq {
|
|
|
8
8
|
key: any;
|
|
9
9
|
value: any;
|
|
10
10
|
}, overwrite?: boolean | undefined) => void;
|
|
11
|
-
delete: (key:
|
|
12
|
-
get:
|
|
13
|
-
|
|
11
|
+
delete: (key: unknown) => boolean;
|
|
12
|
+
get: {
|
|
13
|
+
(key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
|
|
14
|
+
(key: unknown, keepScalar?: false | undefined): any;
|
|
15
|
+
(key: unknown, keepScalar?: boolean | undefined): any;
|
|
16
|
+
};
|
|
17
|
+
has: (key: unknown) => boolean;
|
|
14
18
|
set: (key: any, value: any) => void;
|
|
15
19
|
/**
|
|
16
20
|
* If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
|
|
@@ -24,7 +24,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
|
|
|
24
24
|
if (!ctx)
|
|
25
25
|
return super.toJSON(_);
|
|
26
26
|
const map = new Map();
|
|
27
|
-
if (ctx
|
|
27
|
+
if (ctx?.onCreate)
|
|
28
28
|
ctx.onCreate(map);
|
|
29
29
|
for (const pair of this.items) {
|
|
30
30
|
let key, value;
|
|
@@ -6,7 +6,6 @@ var Scalar = require('../../nodes/Scalar.js');
|
|
|
6
6
|
var YAMLSeq = require('../../nodes/YAMLSeq.js');
|
|
7
7
|
|
|
8
8
|
function resolvePairs(seq, onError) {
|
|
9
|
-
var _a;
|
|
10
9
|
if (Node.isSeq(seq)) {
|
|
11
10
|
for (let i = 0; i < seq.items.length; ++i) {
|
|
12
11
|
let item = seq.items[i];
|
|
@@ -21,7 +20,7 @@ function resolvePairs(seq, onError) {
|
|
|
21
20
|
? `${item.commentBefore}\n${pair.key.commentBefore}`
|
|
22
21
|
: item.commentBefore;
|
|
23
22
|
if (item.comment) {
|
|
24
|
-
const cn =
|
|
23
|
+
const cn = pair.value ?? pair.key;
|
|
25
24
|
cn.comment = cn.comment
|
|
26
25
|
? `${item.comment}\n${cn.comment}`
|
|
27
26
|
: item.comment;
|
|
@@ -12,9 +12,13 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
|
|
|
12
12
|
key: T;
|
|
13
13
|
value: Scalar<null> | null;
|
|
14
14
|
}): void;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
17
|
+
* Otherwise, returns the value of that Pair's key.
|
|
18
|
+
*/
|
|
19
|
+
get(key: unknown, keepPair?: boolean): any;
|
|
16
20
|
set(key: T, value: boolean): void;
|
|
17
|
-
/** Will throw; `value` must be boolean */
|
|
21
|
+
/** @deprecated Will throw; `value` must be boolean */
|
|
18
22
|
set(key: T, value: null): void;
|
|
19
23
|
toJSON(_?: unknown, ctx?: ToJSContext): any;
|
|
20
24
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
@@ -24,6 +24,10 @@ class YAMLSet extends YAMLMap.YAMLMap {
|
|
|
24
24
|
if (!prev)
|
|
25
25
|
this.items.push(pair);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
29
|
+
* Otherwise, returns the value of that Pair's key.
|
|
30
|
+
*/
|
|
27
31
|
get(key, keepPair) {
|
|
28
32
|
const pair = YAMLMap.findPair(this.items, key);
|
|
29
33
|
return !keepPair && Node.isPair(pair)
|
|
@@ -45,26 +45,25 @@ function createStringifyContext(doc, options) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function getTagObject(tags, item) {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
49
48
|
if (item.tag) {
|
|
50
49
|
const match = tags.filter(t => t.tag === item.tag);
|
|
51
50
|
if (match.length > 0)
|
|
52
|
-
return
|
|
51
|
+
return match.find(t => t.format === item.format) ?? match[0];
|
|
53
52
|
}
|
|
54
53
|
let tagObj = undefined;
|
|
55
54
|
let obj;
|
|
56
55
|
if (Node.isScalar(item)) {
|
|
57
56
|
obj = item.value;
|
|
58
|
-
const match = tags.filter(t =>
|
|
57
|
+
const match = tags.filter(t => t.identify?.(obj));
|
|
59
58
|
tagObj =
|
|
60
|
-
|
|
59
|
+
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
|
|
61
60
|
}
|
|
62
61
|
else {
|
|
63
62
|
obj = item;
|
|
64
63
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
65
64
|
}
|
|
66
65
|
if (!tagObj) {
|
|
67
|
-
const name =
|
|
66
|
+
const name = obj?.constructor?.name ?? typeof obj;
|
|
68
67
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
69
68
|
}
|
|
70
69
|
return tagObj;
|
|
@@ -85,13 +84,12 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
|
|
|
85
84
|
return props.join(' ');
|
|
86
85
|
}
|
|
87
86
|
function stringify(item, ctx, onComment, onChompKeep) {
|
|
88
|
-
var _a, _b;
|
|
89
87
|
if (Node.isPair(item))
|
|
90
88
|
return item.toString(ctx, onComment, onChompKeep);
|
|
91
89
|
if (Node.isAlias(item)) {
|
|
92
90
|
if (ctx.doc.directives)
|
|
93
91
|
return item.toString(ctx);
|
|
94
|
-
if (
|
|
92
|
+
if (ctx.resolvedAliases?.has(item)) {
|
|
95
93
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
96
94
|
}
|
|
97
95
|
else {
|
|
@@ -110,7 +108,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
110
108
|
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
111
109
|
const props = stringifyProps(node, tagObj, ctx);
|
|
112
110
|
if (props.length > 0)
|
|
113
|
-
ctx.indentAtStart = (
|
|
111
|
+
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
114
112
|
const str = typeof tagObj.stringify === 'function'
|
|
115
113
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
116
114
|
: Node.isScalar(node)
|
|
@@ -6,8 +6,7 @@ var stringify = require('./stringify.js');
|
|
|
6
6
|
var stringifyComment = require('./stringifyComment.js');
|
|
7
7
|
|
|
8
8
|
function stringifyCollection(collection, ctx, options) {
|
|
9
|
-
|
|
10
|
-
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
|
|
9
|
+
const flow = ctx.inFlow ?? collection.flow;
|
|
11
10
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
12
11
|
return stringify(collection, ctx, options);
|
|
13
12
|
}
|
|
@@ -5,7 +5,6 @@ var stringify = require('./stringify.js');
|
|
|
5
5
|
var stringifyComment = require('./stringifyComment.js');
|
|
6
6
|
|
|
7
7
|
function stringifyDocument(doc, options) {
|
|
8
|
-
var _a;
|
|
9
8
|
const lines = [];
|
|
10
9
|
let hasDirectives = options.directives === true;
|
|
11
10
|
if (options.directives !== false && doc.directives) {
|
|
@@ -57,7 +56,7 @@ function stringifyDocument(doc, options) {
|
|
|
57
56
|
else {
|
|
58
57
|
lines.push(stringify.stringify(doc.contents, ctx));
|
|
59
58
|
}
|
|
60
|
-
if (
|
|
59
|
+
if (doc.directives?.docEnd) {
|
|
61
60
|
if (doc.comment) {
|
|
62
61
|
const cs = commentString(doc.comment);
|
|
63
62
|
if (cs.includes('\n')) {
|