yaml 2.3.0-0 → 2.3.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.
- package/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-scalar.js +1 -1
- package/browser/dist/compose/composer.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +1 -1
- package/browser/dist/compose/util-map-includes.js +1 -1
- package/browser/dist/doc/Document.js +2 -4
- package/browser/dist/doc/anchors.js +1 -1
- package/browser/dist/doc/createNode.js +1 -1
- package/browser/dist/doc/directives.js +1 -1
- package/browser/dist/index.js +1 -1
- package/browser/dist/nodes/Alias.js +9 -2
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Node.js +25 -35
- package/browser/dist/nodes/Pair.js +1 -1
- package/browser/dist/nodes/Scalar.js +2 -1
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/identity.js +36 -0
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/common/map.js +1 -1
- package/browser/dist/schema/common/seq.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +2 -2
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -1
- package/browser/dist/schema/yaml-1.1/set.js +1 -1
- package/browser/dist/stringify/stringify.js +1 -1
- package/browser/dist/stringify/stringifyCollection.js +1 -1
- package/browser/dist/stringify/stringifyDocument.js +1 -1
- package/browser/dist/stringify/stringifyPair.js +1 -1
- package/browser/dist/stringify/stringifyString.js +6 -6
- package/browser/dist/util.js +2 -0
- package/browser/dist/visit.js +1 -1
- package/dist/compose/compose-collection.d.ts +1 -1
- package/dist/compose/compose-collection.js +3 -3
- package/dist/compose/compose-scalar.js +7 -7
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +3 -3
- package/dist/compose/resolve-flow-collection.d.ts +1 -1
- package/dist/compose/resolve-flow-collection.js +2 -2
- package/dist/compose/util-map-includes.d.ts +3 -3
- package/dist/compose/util-map-includes.js +3 -3
- package/dist/doc/Document.d.ts +2 -1
- package/dist/doc/Document.js +12 -14
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +8 -8
- package/dist/doc/directives.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -9
- package/dist/nodes/Alias.d.ts +1 -1
- package/dist/nodes/Alias.js +12 -5
- package/dist/nodes/Collection.d.ts +3 -2
- package/dist/nodes/Collection.js +10 -9
- package/dist/nodes/Node.d.ts +4 -17
- package/dist/nodes/Node.js +25 -51
- package/dist/nodes/Pair.d.ts +2 -2
- package/dist/nodes/Pair.js +4 -4
- package/dist/nodes/Scalar.js +2 -1
- package/dist/nodes/YAMLMap.d.ts +1 -1
- package/dist/nodes/YAMLMap.js +9 -9
- package/dist/nodes/YAMLSeq.d.ts +1 -1
- package/dist/nodes/YAMLSeq.js +5 -5
- package/dist/nodes/addPairToJSMap.js +7 -7
- package/dist/nodes/identity.d.ts +23 -0
- package/dist/nodes/identity.js +53 -0
- package/dist/nodes/toJS.d.ts +1 -4
- package/dist/nodes/toJS.js +2 -2
- package/dist/schema/Schema.d.ts +1 -1
- package/dist/schema/Schema.js +4 -4
- package/dist/schema/common/map.js +2 -2
- package/dist/schema/common/seq.js +2 -2
- package/dist/schema/core/schema.d.ts +1 -1
- package/dist/schema/json/schema.d.ts +1 -1
- package/dist/schema/tags.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.d.ts +1 -1
- package/dist/schema/yaml-1.1/omap.js +4 -4
- package/dist/schema/yaml-1.1/pairs.d.ts +1 -1
- package/dist/schema/yaml-1.1/pairs.js +5 -5
- package/dist/schema/yaml-1.1/schema.d.ts +1 -1
- package/dist/schema/yaml-1.1/set.js +5 -5
- package/dist/stringify/stringify.js +8 -8
- package/dist/stringify/stringifyCollection.js +8 -8
- package/dist/stringify/stringifyDocument.d.ts +3 -3
- package/dist/stringify/stringifyDocument.js +2 -2
- package/dist/stringify/stringifyPair.js +9 -9
- package/dist/stringify/stringifyString.js +6 -6
- package/dist/test-events.js +8 -8
- package/dist/util.d.ts +2 -0
- package/dist/util.js +4 -0
- package/dist/visit.js +18 -18
- package/package.json +7 -4
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
var stringifyCollection = require('../stringify/stringifyCollection.js');
|
|
4
4
|
var addPairToJSMap = require('./addPairToJSMap.js');
|
|
5
5
|
var Collection = require('./Collection.js');
|
|
6
|
-
var
|
|
6
|
+
var identity = require('./identity.js');
|
|
7
7
|
var Pair = require('./Pair.js');
|
|
8
8
|
var Scalar = require('./Scalar.js');
|
|
9
9
|
|
|
10
10
|
function findPair(items, key) {
|
|
11
|
-
const k =
|
|
11
|
+
const k = identity.isScalar(key) ? key.value : key;
|
|
12
12
|
for (const it of items) {
|
|
13
|
-
if (
|
|
13
|
+
if (identity.isPair(it)) {
|
|
14
14
|
if (it.key === key || it.key === k)
|
|
15
15
|
return it;
|
|
16
|
-
if (
|
|
16
|
+
if (identity.isScalar(it.key) && it.key.value === k)
|
|
17
17
|
return it;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -24,7 +24,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
24
24
|
return 'tag:yaml.org,2002:map';
|
|
25
25
|
}
|
|
26
26
|
constructor(schema) {
|
|
27
|
-
super(
|
|
27
|
+
super(identity.MAP, schema);
|
|
28
28
|
this.items = [];
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -35,7 +35,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
35
35
|
*/
|
|
36
36
|
add(pair, overwrite) {
|
|
37
37
|
let _pair;
|
|
38
|
-
if (
|
|
38
|
+
if (identity.isPair(pair))
|
|
39
39
|
_pair = pair;
|
|
40
40
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
41
41
|
// In TypeScript, this never happens.
|
|
@@ -49,7 +49,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
49
49
|
if (!overwrite)
|
|
50
50
|
throw new Error(`Key ${_pair.key} already set`);
|
|
51
51
|
// For scalars, keep the old node & its comments and anchors
|
|
52
|
-
if (
|
|
52
|
+
if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
|
|
53
53
|
prev.value.value = _pair.value;
|
|
54
54
|
else
|
|
55
55
|
prev.value = _pair.value;
|
|
@@ -75,7 +75,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
75
75
|
get(key, keepScalar) {
|
|
76
76
|
const it = findPair(this.items, key);
|
|
77
77
|
const node = it?.value;
|
|
78
|
-
return (!keepScalar &&
|
|
78
|
+
return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? undefined;
|
|
79
79
|
}
|
|
80
80
|
has(key) {
|
|
81
81
|
return !!findPair(this.items, key);
|
|
@@ -100,7 +100,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
100
100
|
if (!ctx)
|
|
101
101
|
return JSON.stringify(this);
|
|
102
102
|
for (const item of this.items) {
|
|
103
|
-
if (!
|
|
103
|
+
if (!identity.isPair(item))
|
|
104
104
|
throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
105
105
|
}
|
|
106
106
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
package/dist/nodes/YAMLSeq.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { BlockSequence, FlowCollection } from '../parse/cst.js';
|
|
|
2
2
|
import type { Schema } from '../schema/Schema.js';
|
|
3
3
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
4
4
|
import { Collection } from './Collection.js';
|
|
5
|
-
import { ParsedNode, Range } from './Node.js';
|
|
5
|
+
import type { ParsedNode, Range } from './Node.js';
|
|
6
6
|
import type { Pair } from './Pair.js';
|
|
7
7
|
import { Scalar } from './Scalar.js';
|
|
8
8
|
import { ToJSContext } from './toJS.js';
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var stringifyCollection = require('../stringify/stringifyCollection.js');
|
|
4
4
|
var Collection = require('./Collection.js');
|
|
5
|
-
var
|
|
5
|
+
var identity = require('./identity.js');
|
|
6
6
|
var Scalar = require('./Scalar.js');
|
|
7
7
|
var toJS = require('./toJS.js');
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
11
11
|
return 'tag:yaml.org,2002:seq';
|
|
12
12
|
}
|
|
13
13
|
constructor(schema) {
|
|
14
|
-
super(
|
|
14
|
+
super(identity.SEQ, schema);
|
|
15
15
|
this.items = [];
|
|
16
16
|
}
|
|
17
17
|
add(value) {
|
|
@@ -37,7 +37,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
37
37
|
if (typeof idx !== 'number')
|
|
38
38
|
return undefined;
|
|
39
39
|
const it = this.items[idx];
|
|
40
|
-
return !keepScalar &&
|
|
40
|
+
return !keepScalar && identity.isScalar(it) ? it.value : it;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Checks if the collection includes a value with the key `key`.
|
|
@@ -61,7 +61,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
61
61
|
if (typeof idx !== 'number')
|
|
62
62
|
throw new Error(`Expected a valid index, not ${key}.`);
|
|
63
63
|
const prev = this.items[idx];
|
|
64
|
-
if (
|
|
64
|
+
if (identity.isScalar(prev) && Scalar.isScalarValue(value))
|
|
65
65
|
prev.value = value;
|
|
66
66
|
else
|
|
67
67
|
this.items[idx] = value;
|
|
@@ -88,7 +88,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
function asItemIndex(key) {
|
|
91
|
-
let idx =
|
|
91
|
+
let idx = identity.isScalar(key) ? key.value : key;
|
|
92
92
|
if (idx && typeof idx === 'string')
|
|
93
93
|
idx = Number(idx);
|
|
94
94
|
return typeof idx === 'number' && Number.isInteger(idx) && idx >= 0
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var log = require('../log.js');
|
|
4
4
|
var stringify = require('../stringify/stringify.js');
|
|
5
|
-
var
|
|
5
|
+
var identity = require('./identity.js');
|
|
6
6
|
var Scalar = require('./Scalar.js');
|
|
7
7
|
var toJS = require('./toJS.js');
|
|
8
8
|
|
|
9
9
|
const MERGE_KEY = '<<';
|
|
10
10
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
11
11
|
if (ctx?.doc.schema.merge && isMergeKey(key)) {
|
|
12
|
-
value =
|
|
13
|
-
if (
|
|
12
|
+
value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
13
|
+
if (identity.isSeq(value))
|
|
14
14
|
for (const it of value.items)
|
|
15
15
|
mergeToJSMap(ctx, map, it);
|
|
16
16
|
else if (Array.isArray(value))
|
|
@@ -44,7 +44,7 @@ function addPairToJSMap(ctx, map, { key, value }) {
|
|
|
44
44
|
return map;
|
|
45
45
|
}
|
|
46
46
|
const isMergeKey = (key) => key === MERGE_KEY ||
|
|
47
|
-
(
|
|
47
|
+
(identity.isScalar(key) &&
|
|
48
48
|
key.value === MERGE_KEY &&
|
|
49
49
|
(!key.type || key.type === Scalar.Scalar.PLAIN));
|
|
50
50
|
// If the value associated with a merge key is a single mapping node, each of
|
|
@@ -55,8 +55,8 @@ const isMergeKey = (key) => key === MERGE_KEY ||
|
|
|
55
55
|
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
56
56
|
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
57
57
|
function mergeToJSMap(ctx, map, value) {
|
|
58
|
-
const source = ctx &&
|
|
59
|
-
if (!
|
|
58
|
+
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
59
|
+
if (!identity.isMap(source))
|
|
60
60
|
throw new Error('Merge sources must be maps or map aliases');
|
|
61
61
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
62
62
|
for (const [key, value] of srcMap) {
|
|
@@ -83,7 +83,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
83
83
|
return '';
|
|
84
84
|
if (typeof jsKey !== 'object')
|
|
85
85
|
return String(jsKey);
|
|
86
|
-
if (
|
|
86
|
+
if (identity.isNode(key) && ctx && ctx.doc) {
|
|
87
87
|
const strCtx = stringify.createStringifyContext(ctx.doc, {});
|
|
88
88
|
strCtx.anchors = new Set();
|
|
89
89
|
for (const node of ctx.anchors.keys())
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Document } from '../doc/Document.js';
|
|
2
|
+
import type { Alias } from './Alias.js';
|
|
3
|
+
import type { Node } from './Node.js';
|
|
4
|
+
import type { Pair } from './Pair.js';
|
|
5
|
+
import type { Scalar } from './Scalar.js';
|
|
6
|
+
import type { YAMLMap } from './YAMLMap.js';
|
|
7
|
+
import type { YAMLSeq } from './YAMLSeq.js';
|
|
8
|
+
export declare const ALIAS: unique symbol;
|
|
9
|
+
export declare const DOC: unique symbol;
|
|
10
|
+
export declare const MAP: unique symbol;
|
|
11
|
+
export declare const PAIR: unique symbol;
|
|
12
|
+
export declare const SCALAR: unique symbol;
|
|
13
|
+
export declare const SEQ: unique symbol;
|
|
14
|
+
export declare const NODE_TYPE: unique symbol;
|
|
15
|
+
export declare const isAlias: (node: any) => node is Alias;
|
|
16
|
+
export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T, true>;
|
|
17
|
+
export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
|
|
18
|
+
export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
|
|
19
|
+
export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
|
|
20
|
+
export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
|
|
21
|
+
export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
|
|
22
|
+
export declare function isNode<T = unknown>(node: any): node is Node<T>;
|
|
23
|
+
export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
|
|
@@ -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;
|
package/dist/nodes/toJS.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Document } from '../doc/Document.js';
|
|
2
|
-
import type {
|
|
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;
|
|
@@ -14,8 +13,6 @@ export interface ToJSContext {
|
|
|
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
|
package/dist/nodes/toJS.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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 || !
|
|
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);
|
package/dist/schema/Schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAP, SCALAR, SEQ } from '../nodes/
|
|
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';
|
package/dist/schema/Schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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,
|
|
23
|
-
Object.defineProperty(this,
|
|
24
|
-
Object.defineProperty(this,
|
|
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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
|
|
@@ -35,7 +35,7 @@ const map = {
|
|
|
35
35
|
nodeClass: YAMLMap.YAMLMap,
|
|
36
36
|
tag: 'tag:yaml.org,2002:map',
|
|
37
37
|
resolve(map, onError) {
|
|
38
|
-
if (!
|
|
38
|
+
if (!identity.isMap(map))
|
|
39
39
|
onError('Expected a mapping for this tag');
|
|
40
40
|
return map;
|
|
41
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createNode = require('../../doc/createNode.js');
|
|
4
|
-
var
|
|
4
|
+
var identity = require('../../nodes/identity.js');
|
|
5
5
|
var YAMLSeq = require('../../nodes/YAMLSeq.js');
|
|
6
6
|
|
|
7
7
|
function createSeq(schema, obj, ctx) {
|
|
@@ -26,7 +26,7 @@ const seq = {
|
|
|
26
26
|
nodeClass: YAMLSeq.YAMLSeq,
|
|
27
27
|
tag: 'tag:yaml.org,2002:seq',
|
|
28
28
|
resolve(seq, onError) {
|
|
29
|
-
if (!
|
|
29
|
+
if (!identity.isSeq(seq))
|
|
30
30
|
onError('Expected a sequence for this tag');
|
|
31
31
|
return seq;
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const schema: (import("../types.js").
|
|
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: (
|
|
2
|
+
export declare const schema: (CollectionTag | ScalarTag)[];
|
package/dist/schema/tags.d.ts
CHANGED
|
@@ -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): (
|
|
39
|
+
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
|
|
40
40
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
2
1
|
import { ToJSContext } from '../../nodes/toJS.js';
|
|
2
|
+
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
3
3
|
import { CollectionTag } from '../types.js';
|
|
4
4
|
export declare class YAMLOMap extends YAMLSeq {
|
|
5
5
|
static tag: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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 (
|
|
31
|
+
if (identity.isPair(pair)) {
|
|
32
32
|
key = toJS.toJS(pair.key, '', ctx);
|
|
33
33
|
value = toJS.toJS(pair.value, key, ctx);
|
|
34
34
|
}
|
|
@@ -53,7 +53,7 @@ const omap = {
|
|
|
53
53
|
const pairs$1 = pairs.resolvePairs(seq, onError);
|
|
54
54
|
const seenKeys = [];
|
|
55
55
|
for (const { key } of pairs$1.items) {
|
|
56
|
-
if (
|
|
56
|
+
if (identity.isScalar(key)) {
|
|
57
57
|
if (seenKeys.includes(key.value)) {
|
|
58
58
|
onError(`Ordered maps must not include duplicate keys: ${key.value}`);
|
|
59
59
|
}
|
|
@@ -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
|
|
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 (
|
|
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 (
|
|
12
|
+
if (identity.isPair(item))
|
|
13
13
|
continue;
|
|
14
|
-
else if (
|
|
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] =
|
|
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").
|
|
1
|
+
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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 (
|
|
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 &&
|
|
35
|
-
?
|
|
34
|
+
return !keepPair && identity.isPair(pair)
|
|
35
|
+
? identity.isScalar(pair.key)
|
|
36
36
|
? pair.key.value
|
|
37
37
|
: pair.key
|
|
38
38
|
: pair;
|
|
@@ -68,7 +68,7 @@ const set = {
|
|
|
68
68
|
default: false,
|
|
69
69
|
tag: 'tag:yaml.org,2002:set',
|
|
70
70
|
resolve(map, onError) {
|
|
71
|
-
if (
|
|
71
|
+
if (identity.isMap(map)) {
|
|
72
72
|
if (map.hasAllNullValues(true))
|
|
73
73
|
return Object.assign(new YAMLSet(), map);
|
|
74
74
|
else
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var anchors = require('../doc/anchors.js');
|
|
4
|
-
var
|
|
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 (
|
|
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 = (
|
|
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 (
|
|
89
|
+
if (identity.isPair(item))
|
|
90
90
|
return item.toString(ctx, onComment, onChompKeep);
|
|
91
|
-
if (
|
|
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 =
|
|
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
|
-
:
|
|
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
|
|
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
|
|
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 (
|
|
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 (
|
|
29
|
-
const ik =
|
|
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 (
|
|
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 (
|
|
86
|
-
const ik =
|
|
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 =
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { Document } from '../doc/Document.js';
|
|
2
|
-
import { Node } from '../nodes/Node.js';
|
|
3
|
-
import { ToStringOptions } from '../options.js';
|
|
1
|
+
import type { Document } from '../doc/Document.js';
|
|
2
|
+
import type { Node } from '../nodes/Node.js';
|
|
3
|
+
import type { ToStringOptions } from '../options.js';
|
|
4
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
|
|
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 (
|
|
32
|
+
if (identity.isNode(doc.contents)) {
|
|
33
33
|
if (doc.contents.spaceBefore && hasDirectives)
|
|
34
34
|
lines.push('');
|
|
35
35
|
if (doc.contents.commentBefore) {
|