@swagger-api/apidom-ast 0.68.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/CHANGELOG.md +352 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +57 -0
- package/README.md +98 -0
- package/cjs/Error.cjs +25 -0
- package/cjs/Literal.cjs +22 -0
- package/cjs/Node.cjs +46 -0
- package/cjs/ParseResult.cjs +22 -0
- package/cjs/Position.cjs +46 -0
- package/cjs/index.cjs +113 -0
- package/cjs/json/nodes/JsonArray.cjs +21 -0
- package/cjs/json/nodes/JsonDocument.cjs +22 -0
- package/cjs/json/nodes/JsonEscapeSequence.cjs +14 -0
- package/cjs/json/nodes/JsonFalse.cjs +14 -0
- package/cjs/json/nodes/JsonKey.cjs +14 -0
- package/cjs/json/nodes/JsonNode.cjs +10 -0
- package/cjs/json/nodes/JsonNull.cjs +14 -0
- package/cjs/json/nodes/JsonNumber.cjs +14 -0
- package/cjs/json/nodes/JsonObject.cjs +21 -0
- package/cjs/json/nodes/JsonProperty.cjs +27 -0
- package/cjs/json/nodes/JsonString.cjs +27 -0
- package/cjs/json/nodes/JsonStringContent.cjs +14 -0
- package/cjs/json/nodes/JsonTrue.cjs +14 -0
- package/cjs/json/nodes/JsonValue.cjs +22 -0
- package/cjs/json/nodes/predicates.cjs +29 -0
- package/cjs/predicates.cjs +14 -0
- package/cjs/traversal/visitor.cjs +493 -0
- package/cjs/yaml/nodes/YamlAlias.cjs +22 -0
- package/cjs/yaml/nodes/YamlAnchor.cjs +22 -0
- package/cjs/yaml/nodes/YamlCollection.cjs +10 -0
- package/cjs/yaml/nodes/YamlComment.cjs +22 -0
- package/cjs/yaml/nodes/YamlDirective.cjs +30 -0
- package/cjs/yaml/nodes/YamlDocument.cjs +14 -0
- package/cjs/yaml/nodes/YamlKeyValuePair.cjs +40 -0
- package/cjs/yaml/nodes/YamlMapping.cjs +24 -0
- package/cjs/yaml/nodes/YamlNode.cjs +28 -0
- package/cjs/yaml/nodes/YamlScalar.cjs +22 -0
- package/cjs/yaml/nodes/YamlSequence.cjs +27 -0
- package/cjs/yaml/nodes/YamlStream.cjs +26 -0
- package/cjs/yaml/nodes/YamlStyle.cjs +33 -0
- package/cjs/yaml/nodes/YamlTag.cjs +32 -0
- package/cjs/yaml/nodes/predicates.cjs +25 -0
- package/cjs/yaml/schemas/ScalarTag.cjs +43 -0
- package/cjs/yaml/schemas/Tag.cjs +14 -0
- package/cjs/yaml/schemas/canonical-format.cjs +129 -0
- package/cjs/yaml/schemas/failsafe/GenericMapping.cjs +29 -0
- package/cjs/yaml/schemas/failsafe/GenericSequence.cjs +29 -0
- package/cjs/yaml/schemas/failsafe/GenericString.cjs +24 -0
- package/cjs/yaml/schemas/failsafe/index.cjs +96 -0
- package/cjs/yaml/schemas/json/Boolean.cjs +30 -0
- package/cjs/yaml/schemas/json/FloatingPoint.cjs +30 -0
- package/cjs/yaml/schemas/json/Integer.cjs +30 -0
- package/cjs/yaml/schemas/json/Null.cjs +29 -0
- package/cjs/yaml/schemas/json/index.cjs +47 -0
- package/dist/apidom-ast.browser.js +21212 -0
- package/dist/apidom-ast.browser.min.js +2 -0
- package/dist/apidom-ast.browser.min.js.LICENSE.txt +6 -0
- package/es/Error.js +19 -0
- package/es/Literal.js +16 -0
- package/es/Node.js +40 -0
- package/es/ParseResult.js +16 -0
- package/es/Position.js +39 -0
- package/es/index.js +39 -0
- package/es/json/nodes/JsonArray.js +15 -0
- package/es/json/nodes/JsonDocument.js +16 -0
- package/es/json/nodes/JsonEscapeSequence.js +8 -0
- package/es/json/nodes/JsonFalse.js +8 -0
- package/es/json/nodes/JsonKey.js +8 -0
- package/es/json/nodes/JsonNode.js +4 -0
- package/es/json/nodes/JsonNull.js +8 -0
- package/es/json/nodes/JsonNumber.js +8 -0
- package/es/json/nodes/JsonObject.js +15 -0
- package/es/json/nodes/JsonProperty.js +21 -0
- package/es/json/nodes/JsonString.js +21 -0
- package/es/json/nodes/JsonStringContent.js +8 -0
- package/es/json/nodes/JsonTrue.js +8 -0
- package/es/json/nodes/JsonValue.js +16 -0
- package/es/json/nodes/predicates.js +13 -0
- package/es/predicates.js +5 -0
- package/es/traversal/visitor.js +483 -0
- package/es/yaml/nodes/YamlAlias.js +16 -0
- package/es/yaml/nodes/YamlAnchor.js +16 -0
- package/es/yaml/nodes/YamlCollection.js +4 -0
- package/es/yaml/nodes/YamlComment.js +16 -0
- package/es/yaml/nodes/YamlDirective.js +24 -0
- package/es/yaml/nodes/YamlDocument.js +8 -0
- package/es/yaml/nodes/YamlKeyValuePair.js +34 -0
- package/es/yaml/nodes/YamlMapping.js +18 -0
- package/es/yaml/nodes/YamlNode.js +22 -0
- package/es/yaml/nodes/YamlScalar.js +16 -0
- package/es/yaml/nodes/YamlSequence.js +21 -0
- package/es/yaml/nodes/YamlStream.js +20 -0
- package/es/yaml/nodes/YamlStyle.js +25 -0
- package/es/yaml/nodes/YamlTag.js +25 -0
- package/es/yaml/nodes/predicates.js +11 -0
- package/es/yaml/schemas/ScalarTag.js +37 -0
- package/es/yaml/schemas/Tag.js +8 -0
- package/es/yaml/schemas/canonical-format.js +122 -0
- package/es/yaml/schemas/failsafe/GenericMapping.js +23 -0
- package/es/yaml/schemas/failsafe/GenericSequence.js +23 -0
- package/es/yaml/schemas/failsafe/GenericString.js +18 -0
- package/es/yaml/schemas/failsafe/index.js +90 -0
- package/es/yaml/schemas/json/Boolean.js +24 -0
- package/es/yaml/schemas/json/FloatingPoint.js +24 -0
- package/es/yaml/schemas/json/Integer.js +24 -0
- package/es/yaml/schemas/json/Null.js +23 -0
- package/es/yaml/schemas/json/index.js +41 -0
- package/package.json +62 -0
- package/types/dist.d.ts +362 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Node from "../../Node.js";
|
3
|
+
import { isComment, isDocument } from "./predicates.js";
|
4
|
+
const YamlStream = stampit(Node, {
|
5
|
+
statics: {
|
6
|
+
type: 'stream'
|
7
|
+
},
|
8
|
+
propertyDescriptors: {
|
9
|
+
content: {
|
10
|
+
get() {
|
11
|
+
// @ts-ignore
|
12
|
+
return Array.isArray(this.children) ?
|
13
|
+
// @ts-ignore
|
14
|
+
this.children.filter(node => isDocument(node) || isComment(node)) : [];
|
15
|
+
},
|
16
|
+
enumerable: true
|
17
|
+
}
|
18
|
+
}
|
19
|
+
});
|
20
|
+
export default YamlStream;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
export let YamlStyle;
|
3
|
+
(function (YamlStyle) {
|
4
|
+
YamlStyle["Plain"] = "Plain";
|
5
|
+
YamlStyle["SingleQuoted"] = "SingleQuoted";
|
6
|
+
YamlStyle["DoubleQuoted"] = "DoubleQuoted";
|
7
|
+
YamlStyle["Literal"] = "Literal";
|
8
|
+
YamlStyle["Folded"] = "Folded";
|
9
|
+
YamlStyle["Explicit"] = "Explicit";
|
10
|
+
YamlStyle["SinglePair"] = "SinglePair";
|
11
|
+
YamlStyle["NextLine"] = "NextLine";
|
12
|
+
YamlStyle["InLine"] = "InLine";
|
13
|
+
})(YamlStyle || (YamlStyle = {}));
|
14
|
+
export let YamlStyleGroup;
|
15
|
+
(function (YamlStyleGroup) {
|
16
|
+
YamlStyleGroup["Flow"] = "Flow";
|
17
|
+
YamlStyleGroup["Block"] = "Block";
|
18
|
+
})(YamlStyleGroup || (YamlStyleGroup = {}));
|
19
|
+
const YamlStyleModel = stampit({
|
20
|
+
props: {
|
21
|
+
styleGroup: null,
|
22
|
+
style: null
|
23
|
+
}
|
24
|
+
});
|
25
|
+
export default YamlStyleModel;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Node from "../../Node.js";
|
3
|
+
export let YamlNodeKind;
|
4
|
+
(function (YamlNodeKind) {
|
5
|
+
YamlNodeKind["Scalar"] = "Scalar";
|
6
|
+
YamlNodeKind["Sequence"] = "Sequence";
|
7
|
+
YamlNodeKind["Mapping"] = "Mapping";
|
8
|
+
})(YamlNodeKind || (YamlNodeKind = {}));
|
9
|
+
const YamlTag = stampit(Node, {
|
10
|
+
statics: {
|
11
|
+
type: 'tag'
|
12
|
+
},
|
13
|
+
props: {
|
14
|
+
explicitName: '',
|
15
|
+
kind: null
|
16
|
+
},
|
17
|
+
init({
|
18
|
+
explicitName,
|
19
|
+
kind
|
20
|
+
} = {}) {
|
21
|
+
this.explicitName = explicitName;
|
22
|
+
this.kind = kind;
|
23
|
+
}
|
24
|
+
});
|
25
|
+
export default YamlTag;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { isNodeType } from "../../predicates.js";
|
2
|
+
export const isStream = isNodeType.bind(undefined, 'stream');
|
3
|
+
export const isDocument = isNodeType.bind(undefined, 'document');
|
4
|
+
export const isMapping = isNodeType.bind(undefined, 'mapping');
|
5
|
+
export const isSequence = isNodeType.bind(undefined, 'sequence');
|
6
|
+
export const isKeyValuePair = isNodeType.bind(undefined, 'keyValuePair');
|
7
|
+
export const isTag = isNodeType.bind(undefined, 'tag');
|
8
|
+
export const isScalar = isNodeType.bind(undefined, 'scalar');
|
9
|
+
export const isAlias = isNodeType.bind(undefined, 'alias');
|
10
|
+
export const isDirective = isNodeType.bind(undefined, 'directive');
|
11
|
+
export const isComment = isNodeType.bind(undefined, 'comment');
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import { formatFlowPlain, formatFlowSingleQuoted, formatFlowDoubleQuoted, formatBlockLiteral, formatBlockFolded } from "./canonical-format.js";
|
3
|
+
import { YamlStyle } from "../nodes/YamlStyle.js";
|
4
|
+
import { YamlNodeKind } from "../nodes/YamlTag.js";
|
5
|
+
const ScalarTag = stampit({
|
6
|
+
methods: {
|
7
|
+
test(node) {
|
8
|
+
return node.tag.kind === YamlNodeKind.Scalar && typeof node.content === 'string';
|
9
|
+
},
|
10
|
+
canonicalFormat(node) {
|
11
|
+
let canonicalForm = node.content;
|
12
|
+
const nodeClone = node.clone();
|
13
|
+
if (node.style === YamlStyle.Plain) {
|
14
|
+
// @ts-ignore
|
15
|
+
canonicalForm = formatFlowPlain(node.content);
|
16
|
+
} else if (node.style === YamlStyle.SingleQuoted) {
|
17
|
+
// @ts-ignore
|
18
|
+
canonicalForm = formatFlowSingleQuoted(node.content);
|
19
|
+
} else if (node.style === YamlStyle.DoubleQuoted) {
|
20
|
+
// @ts-ignore
|
21
|
+
canonicalForm = formatFlowDoubleQuoted(node.content);
|
22
|
+
} else if (node.style === YamlStyle.Literal) {
|
23
|
+
// @ts-ignore
|
24
|
+
canonicalForm = formatBlockLiteral(node.content);
|
25
|
+
} else if (node.style === YamlStyle.Folded) {
|
26
|
+
// @ts-ignore
|
27
|
+
canonicalForm = formatBlockFolded(node.content);
|
28
|
+
}
|
29
|
+
nodeClone.content = canonicalForm;
|
30
|
+
return nodeClone;
|
31
|
+
},
|
32
|
+
resolve(node) {
|
33
|
+
return node;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
});
|
37
|
+
export default ScalarTag;
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import { tail, compose, pathOr, map, concat, transduce, pipe, trim, split, join, curry } from 'ramda';
|
2
|
+
import { isInteger, trimStart, trimEnd, isUndefined, trimCharsStart, isEmptyString, repeatStr, concatRight } from 'ramda-adjunct';
|
3
|
+
import { unraw } from 'unraw';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Helpers.
|
7
|
+
*/
|
8
|
+
|
9
|
+
const blockStyleRegExp = /^(?<style>[|>])(?<chomping>[+-]?)(?<indentation>[0-9]*)\s/;
|
10
|
+
const getIndentationIndicator = content => {
|
11
|
+
const matches = content.match(blockStyleRegExp);
|
12
|
+
const indicator = pathOr('', ['groups', 'indentation'], matches);
|
13
|
+
return isEmptyString(indicator) ? undefined : parseInt(indicator, 10);
|
14
|
+
};
|
15
|
+
const getIndentation = content => {
|
16
|
+
const explicitIndentationIndicator = getIndentationIndicator(content);
|
17
|
+
|
18
|
+
// we have explicit indentation indicator
|
19
|
+
if (isInteger(explicitIndentationIndicator)) {
|
20
|
+
return repeatStr(' ', explicitIndentationIndicator);
|
21
|
+
}
|
22
|
+
|
23
|
+
// we assume indentation indicator from first line
|
24
|
+
const firstLine = pathOr('', [1], content.split('\n'));
|
25
|
+
const implicitIndentationIndicator = pathOr(0, ['groups', 'indentation', 'length'], firstLine.match(/^(?<indentation>[ ]*)/));
|
26
|
+
return repeatStr(' ', implicitIndentationIndicator);
|
27
|
+
};
|
28
|
+
const getChompingIndicator = content => {
|
29
|
+
const matches = content.match(blockStyleRegExp);
|
30
|
+
const indicator = pathOr('', ['groups', 'chomping'], matches);
|
31
|
+
return isEmptyString(indicator) ? undefined : indicator;
|
32
|
+
};
|
33
|
+
const chomp = (indicator, content) => {
|
34
|
+
// clip (single newline at end)
|
35
|
+
if (isUndefined(indicator)) {
|
36
|
+
return `${trimEnd(content)}\n`;
|
37
|
+
}
|
38
|
+
// strip (no newline at end)
|
39
|
+
if (indicator === '-') {
|
40
|
+
return trimEnd(content);
|
41
|
+
}
|
42
|
+
// keep (all newlines from end)
|
43
|
+
if (indicator === '+') {
|
44
|
+
return content;
|
45
|
+
}
|
46
|
+
return content;
|
47
|
+
};
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Normalizes lines breaks.
|
51
|
+
* https://yaml.org/spec/1.2/spec.html#line%20break/normalization/
|
52
|
+
*/
|
53
|
+
// @ts-ignore
|
54
|
+
const normalizeLineBreaks = val => val.replace(/\r\n/g, '\n');
|
55
|
+
|
56
|
+
// prevent escaped line breaks from being converted to a space
|
57
|
+
const preventLineBreakCollapseToSpace = val => val.replace(/\\\n\s*/g, '');
|
58
|
+
|
59
|
+
// collapse line breaks into spaces
|
60
|
+
const collapseLineBreakToSpace = val => {
|
61
|
+
/**
|
62
|
+
* Safari doesn't support negative lookbehind, thus we use mimicking technique:
|
63
|
+
*
|
64
|
+
* - https://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
|
65
|
+
*
|
66
|
+
* Ideally we want to use following replace, but that's not currently possible:
|
67
|
+
*
|
68
|
+
* .replace(/[^\n]\n([^\n]+)/g, (match: string, p1: string) => ` ${p1.trimLeft()}`)
|
69
|
+
*/
|
70
|
+
return val.replace(/(\n)?\n([^\n]+)/g, (match, p1, p2) => p1 ? match : ` ${p2.trimStart()}`).replace(/[\n]{2}/g, '\n');
|
71
|
+
};
|
72
|
+
const removeQuotes = curry((quoteType, val) => val.replace(new RegExp(`^${quoteType}`), '').replace(new RegExp(`${quoteType}$`), ''));
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Formats Flow Scalar Plain style.
|
76
|
+
* https://yaml.org/spec/1.2/spec.html#id2788859
|
77
|
+
*/
|
78
|
+
export const formatFlowPlain = pipe(normalizeLineBreaks, trim, collapseLineBreakToSpace, split('\n'), map(trimStart), join('\n'));
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Formats Flow Scalar Single-Quoted style.
|
82
|
+
* https://yaml.org/spec/1.2/spec.html#id2788097
|
83
|
+
*/
|
84
|
+
|
85
|
+
export const formatFlowSingleQuoted = pipe(normalizeLineBreaks, trim, removeQuotes("'"), collapseLineBreakToSpace, split('\n'), map(trimStart), join('\n'));
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Formats Flow Scalar Double-Quoted style.
|
89
|
+
* https://yaml.org/spec/1.2/spec.html#id2787109
|
90
|
+
*/
|
91
|
+
export const formatFlowDoubleQuoted = pipe(normalizeLineBreaks, trim, removeQuotes('"'), preventLineBreakCollapseToSpace, collapseLineBreakToSpace, unraw, split('\n'), map(trimStart), join('\n'));
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Formats Block Scalar Literal style.
|
95
|
+
* https://yaml.org/spec/1.2/spec.html#id2795688
|
96
|
+
*/
|
97
|
+
export const formatBlockLiteral = content => {
|
98
|
+
const indentation = getIndentation(content);
|
99
|
+
const chompingIndicator = getChompingIndicator(content);
|
100
|
+
const normalized = normalizeLineBreaks(content);
|
101
|
+
const lines = tail(normalized.split('\n')); // first line only contains indicators
|
102
|
+
const transducer = compose(map(trimCharsStart(indentation)), map(concatRight('\n')));
|
103
|
+
// @ts-ignore
|
104
|
+
const deindented = transduce(transducer, concat, '', lines);
|
105
|
+
return chomp(chompingIndicator, deindented);
|
106
|
+
};
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Formats BLock Scalar Folded style.
|
110
|
+
* https://yaml.org/spec/1.2/spec.html#id2796251
|
111
|
+
*/
|
112
|
+
export const formatBlockFolded = content => {
|
113
|
+
const indentation = getIndentation(content);
|
114
|
+
const chompingIndicator = getChompingIndicator(content);
|
115
|
+
const normalized = normalizeLineBreaks(content);
|
116
|
+
const lines = tail(normalized.split('\n')); // first line only contains indicators
|
117
|
+
const transducer = compose(map(trimCharsStart(indentation)), map(concatRight('\n')));
|
118
|
+
// @ts-ignore
|
119
|
+
const deindented = transduce(transducer, concat, '', lines);
|
120
|
+
const collapsed = collapseLineBreakToSpace(deindented);
|
121
|
+
return chomp(chompingIndicator, collapsed);
|
122
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
import { YamlNodeKind } from "../../nodes/YamlTag.js";
|
4
|
+
const GenericMapping = stampit(Tag, {
|
5
|
+
statics: {
|
6
|
+
uri: 'tag:yaml.org,2002:map'
|
7
|
+
},
|
8
|
+
init(args, {
|
9
|
+
stamp
|
10
|
+
}) {
|
11
|
+
this.tag = stamp.uri;
|
12
|
+
},
|
13
|
+
methods: {
|
14
|
+
test(node) {
|
15
|
+
// @ts-ignore
|
16
|
+
return node.tag.kind === YamlNodeKind.Mapping;
|
17
|
+
},
|
18
|
+
resolve(node) {
|
19
|
+
return node;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
});
|
23
|
+
export default GenericMapping;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
import { YamlNodeKind } from "../../nodes/YamlTag.js";
|
4
|
+
const GenericSequence = stampit(Tag, {
|
5
|
+
statics: {
|
6
|
+
uri: 'tag:yaml.org,2002:seq'
|
7
|
+
},
|
8
|
+
init(args, {
|
9
|
+
stamp
|
10
|
+
}) {
|
11
|
+
this.tag = stamp.uri;
|
12
|
+
},
|
13
|
+
methods: {
|
14
|
+
test(node) {
|
15
|
+
// @ts-ignore
|
16
|
+
return node.tag.kind === YamlNodeKind.Sequence;
|
17
|
+
},
|
18
|
+
resolve(node) {
|
19
|
+
return node;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
});
|
23
|
+
export default GenericSequence;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
const GenericString = stampit(Tag, {
|
4
|
+
statics: {
|
5
|
+
uri: 'tag:yaml.org,2002:str'
|
6
|
+
},
|
7
|
+
init(args, {
|
8
|
+
stamp
|
9
|
+
}) {
|
10
|
+
this.tag = stamp.uri;
|
11
|
+
},
|
12
|
+
methods: {
|
13
|
+
resolve(node) {
|
14
|
+
return node;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
});
|
18
|
+
export default GenericString;
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import { YamlNodeKind } from "../../nodes/YamlTag.js";
|
3
|
+
import GenericMapping from "./GenericMapping.js";
|
4
|
+
import GenericSequence from "./GenericSequence.js";
|
5
|
+
import GenericString from "./GenericString.js";
|
6
|
+
import ScalarTag from "../ScalarTag.js";
|
7
|
+
const FailsafeSchema = stampit({
|
8
|
+
props: {
|
9
|
+
tags: [],
|
10
|
+
tagDirectives: []
|
11
|
+
},
|
12
|
+
init() {
|
13
|
+
this.tags = [];
|
14
|
+
this.tagDirectives = [];
|
15
|
+
this.registerTag(GenericMapping());
|
16
|
+
this.registerTag(GenericSequence());
|
17
|
+
this.registerTag(GenericString());
|
18
|
+
},
|
19
|
+
methods: {
|
20
|
+
toSpecificTagName(node) {
|
21
|
+
let specificTagName = node.tag.explicitName;
|
22
|
+
if (node.tag.explicitName === '!') {
|
23
|
+
// non-specific tag; we assume tag by kind
|
24
|
+
if (node.tag.kind === YamlNodeKind.Scalar) {
|
25
|
+
// @ts-ignore
|
26
|
+
specificTagName = GenericString.uri;
|
27
|
+
} else if (node.tag.kind === YamlNodeKind.Sequence) {
|
28
|
+
// @ts-ignore
|
29
|
+
specificTagName = GenericSequence.uri;
|
30
|
+
} else if (node.tag.kind === YamlNodeKind.Mapping) {
|
31
|
+
// @ts-ignore
|
32
|
+
specificTagName = GenericMapping.uri;
|
33
|
+
}
|
34
|
+
} else if (node.tag.explicitName.startsWith('!<')) {
|
35
|
+
// verbatim form
|
36
|
+
specificTagName = node.tag.explicitName.replace(/^!</, '').replace(/>$/, '');
|
37
|
+
} else if (node.tag.explicitName.startsWith('!!')) {
|
38
|
+
// shorthand notation
|
39
|
+
specificTagName = `tag:yaml.org,2002:${node.tag.explicitName.replace(/^!!/, '')}`;
|
40
|
+
}
|
41
|
+
return specificTagName;
|
42
|
+
},
|
43
|
+
registerTagDirective(tagDirective) {
|
44
|
+
this.tagDirectives.push({
|
45
|
+
handle: tagDirective.parameters.handle,
|
46
|
+
prefix: tagDirective.parameters.prefix
|
47
|
+
});
|
48
|
+
},
|
49
|
+
registerTag(tag, beginning = false) {
|
50
|
+
if (beginning) {
|
51
|
+
this.tags.unshift(tag);
|
52
|
+
} else {
|
53
|
+
this.tags.push(tag);
|
54
|
+
}
|
55
|
+
return this;
|
56
|
+
},
|
57
|
+
overrideTag(tag) {
|
58
|
+
this.tags = this.tags.filter(itag => itag.tag === tag.tag);
|
59
|
+
this.tags.push(tag);
|
60
|
+
return this;
|
61
|
+
},
|
62
|
+
resolve(node) {
|
63
|
+
const specificTagName = this.toSpecificTagName(node);
|
64
|
+
|
65
|
+
// leave this node unresolved
|
66
|
+
if (specificTagName === '?') {
|
67
|
+
return node;
|
68
|
+
}
|
69
|
+
|
70
|
+
// turn scalar nodes into canonical format before resolving
|
71
|
+
let canonicalNode = node;
|
72
|
+
if (node.tag.kind === YamlNodeKind.Scalar) {
|
73
|
+
canonicalNode = ScalarTag().canonicalFormat(node);
|
74
|
+
}
|
75
|
+
const tag = this.tags.find(itag => (itag === null || itag === void 0 ? void 0 : itag.tag) === specificTagName);
|
76
|
+
|
77
|
+
// mechanism for resolving node (tag implementation) not found
|
78
|
+
if (typeof tag === 'undefined') {
|
79
|
+
throw new Error(`Tag "${specificTagName}" couldn't be resolved`);
|
80
|
+
}
|
81
|
+
|
82
|
+
// node content is not compatible with resolving mechanism (tag implementation)
|
83
|
+
if (!tag.test(canonicalNode)) {
|
84
|
+
throw new Error(`Node couldn't be resolved against tag "${specificTagName}"`);
|
85
|
+
}
|
86
|
+
return tag.resolve(canonicalNode);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
});
|
90
|
+
export default FailsafeSchema;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
const Boolean = stampit(Tag, {
|
4
|
+
statics: {
|
5
|
+
uri: 'tag:yaml.org,2002:bool'
|
6
|
+
},
|
7
|
+
init(args, {
|
8
|
+
stamp
|
9
|
+
}) {
|
10
|
+
this.tag = stamp.uri;
|
11
|
+
},
|
12
|
+
methods: {
|
13
|
+
test(node) {
|
14
|
+
return /^(true|false)$/.test(node.content);
|
15
|
+
},
|
16
|
+
resolve(node) {
|
17
|
+
const content = node.content === 'true';
|
18
|
+
const nodeClone = node.clone();
|
19
|
+
nodeClone.content = content;
|
20
|
+
return nodeClone;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
export default Boolean;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
const FloatingPoint = stampit(Tag, {
|
4
|
+
statics: {
|
5
|
+
uri: 'tag:yaml.org,2002:float'
|
6
|
+
},
|
7
|
+
init(args, {
|
8
|
+
stamp
|
9
|
+
}) {
|
10
|
+
this.tag = stamp.uri;
|
11
|
+
},
|
12
|
+
methods: {
|
13
|
+
test(node) {
|
14
|
+
return /^-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/.test(node.content);
|
15
|
+
},
|
16
|
+
resolve(node) {
|
17
|
+
const content = parseFloat(node.content);
|
18
|
+
const nodeClone = node.clone();
|
19
|
+
nodeClone.content = content;
|
20
|
+
return nodeClone;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
export default FloatingPoint;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
const Integer = stampit(Tag, {
|
4
|
+
statics: {
|
5
|
+
uri: 'tag:yaml.org,2002:int'
|
6
|
+
},
|
7
|
+
init(args, {
|
8
|
+
stamp
|
9
|
+
}) {
|
10
|
+
this.tag = stamp.uri;
|
11
|
+
},
|
12
|
+
methods: {
|
13
|
+
test(node) {
|
14
|
+
return /^-?(0|[1-9][0-9]*)$/.test(node.content);
|
15
|
+
},
|
16
|
+
resolve(node) {
|
17
|
+
const content = parseInt(node.content, 10);
|
18
|
+
const nodeClone = node.clone();
|
19
|
+
nodeClone.content = content;
|
20
|
+
return nodeClone;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
export default Integer;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import Tag from "../Tag.js";
|
3
|
+
const Null = stampit(Tag, {
|
4
|
+
statics: {
|
5
|
+
uri: 'tag:yaml.org,2002:null'
|
6
|
+
},
|
7
|
+
init(args, {
|
8
|
+
stamp
|
9
|
+
}) {
|
10
|
+
this.tag = stamp.uri;
|
11
|
+
},
|
12
|
+
methods: {
|
13
|
+
test(node) {
|
14
|
+
return /^null$/.test(node.content);
|
15
|
+
},
|
16
|
+
resolve(node) {
|
17
|
+
const nodeClone = node.clone();
|
18
|
+
nodeClone.content = null;
|
19
|
+
return nodeClone;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
});
|
23
|
+
export default Null;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import stampit from 'stampit';
|
2
|
+
import FailsafeSchema from "../failsafe/index.js";
|
3
|
+
import Boolean from "./Boolean.js";
|
4
|
+
import FloatingPoint from "./FloatingPoint.js";
|
5
|
+
import Integer from "./Integer.js";
|
6
|
+
import Null from "./Null.js";
|
7
|
+
import { YamlNodeKind } from "../../nodes/YamlTag.js";
|
8
|
+
import GenericSequence from "../failsafe/GenericSequence.js";
|
9
|
+
import GenericMapping from "../failsafe/GenericMapping.js";
|
10
|
+
const JsonSchema = stampit(FailsafeSchema, {
|
11
|
+
init() {
|
12
|
+
/**
|
13
|
+
* We're registering more specific tags before more generic ones from Failsafe schema.
|
14
|
+
*/
|
15
|
+
this.registerTag(Boolean(), true);
|
16
|
+
this.registerTag(FloatingPoint(), true);
|
17
|
+
this.registerTag(Integer(), true);
|
18
|
+
this.registerTag(Null(), true);
|
19
|
+
},
|
20
|
+
methods: {
|
21
|
+
toSpecificTagName(node) {
|
22
|
+
// @ts-ignore
|
23
|
+
let specificTagName = FailsafeSchema.compose.methods.toSpecificTagName.call(this, node);
|
24
|
+
if (specificTagName === '?') {
|
25
|
+
if (node.tag.vkind === YamlNodeKind.Sequence) {
|
26
|
+
// @ts-ignore
|
27
|
+
specificTagName = GenericSequence.uri;
|
28
|
+
} else if (node.tag.kind === YamlNodeKind.Mapping) {
|
29
|
+
// @ts-ignore
|
30
|
+
specificTagName = GenericMapping.uri;
|
31
|
+
} else if (node.tag.kind === YamlNodeKind.Scalar) {
|
32
|
+
// @ts-ignore
|
33
|
+
const foundTag = this.tags.find(tag => tag.test(node));
|
34
|
+
specificTagName = (foundTag === null || foundTag === void 0 ? void 0 : foundTag.tag) || '?';
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return specificTagName;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
});
|
41
|
+
export default JsonSchema;
|
package/package.json
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
{
|
2
|
+
"name": "@swagger-api/apidom-ast",
|
3
|
+
"version": "0.68.0",
|
4
|
+
"description": "Tools necessary for parsing stage of ApiDOM, specifically for syntactic analysis.",
|
5
|
+
"publishConfig": {
|
6
|
+
"access": "public",
|
7
|
+
"registry": "https://registry.npmjs.org"
|
8
|
+
},
|
9
|
+
"type": "module",
|
10
|
+
"sideEffects": false,
|
11
|
+
"unpkg": "./dist/apidom.ast.min.js",
|
12
|
+
"main": "./cjs/index.cjs",
|
13
|
+
"exports": {
|
14
|
+
"types": "./types/dist.d.ts",
|
15
|
+
"import": "./es/index.js",
|
16
|
+
"require": "./cjs/index.cjs"
|
17
|
+
},
|
18
|
+
"types": "./types/dist.d.ts",
|
19
|
+
"scripts": {
|
20
|
+
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
|
21
|
+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'",
|
22
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
|
23
|
+
"build:umd:browser": "cross-env BABEL_ENV=browser BROWSERSLIST_ENV=production webpack --config config/webpack/browser.config.js --progress",
|
24
|
+
"lint": "eslint ./",
|
25
|
+
"lint:fix": "eslint ./ --fix",
|
26
|
+
"clean": "rimraf ./es ./cjs ./dist ./types",
|
27
|
+
"test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha",
|
28
|
+
"typescript:check-types": "tsc --noEmit",
|
29
|
+
"typescript:declaration": "tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js",
|
30
|
+
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
31
|
+
"postpack": "rimraf NOTICE LICENSES"
|
32
|
+
},
|
33
|
+
"repository": {
|
34
|
+
"type": "git",
|
35
|
+
"url": "git+https://github.com/swagger-api/apidom.git"
|
36
|
+
},
|
37
|
+
"author": "Vladimir Gorej",
|
38
|
+
"license": "Apache-2.0",
|
39
|
+
"bugs": {
|
40
|
+
"url": "https://github.com/swagger-api/apidom/issues"
|
41
|
+
},
|
42
|
+
"homepage": "https://github.com/swagger-api/apidom#readme",
|
43
|
+
"dependencies": {
|
44
|
+
"@babel/runtime-corejs3": "^7.20.7",
|
45
|
+
"@types/ramda": "=0.28.23",
|
46
|
+
"ramda": "=0.28.0",
|
47
|
+
"ramda-adjunct": "=3.4.0",
|
48
|
+
"stampit": "=4.3.2",
|
49
|
+
"unraw": "=2.0.1"
|
50
|
+
},
|
51
|
+
"files": [
|
52
|
+
"cjs/",
|
53
|
+
"dist/",
|
54
|
+
"es/",
|
55
|
+
"types/dist.d.ts",
|
56
|
+
"LICENSES",
|
57
|
+
"NOTICE",
|
58
|
+
"README.md",
|
59
|
+
"CHANGELOG.md"
|
60
|
+
],
|
61
|
+
"gitHead": "d2bc706671f1b9a593b8f0c5bca8c501ad0e4cff"
|
62
|
+
}
|