@speclynx/apidom-datamodel 4.0.1 → 4.0.3
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 +10 -0
- package/package.json +4 -5
- package/src/KeyValuePair.cjs +31 -0
- package/src/KeyValuePair.mjs +27 -0
- package/src/KeyValuePair.ts +31 -0
- package/src/Metadata.cjs +91 -0
- package/src/Metadata.mjs +87 -0
- package/src/Metadata.ts +100 -0
- package/src/Namespace.cjs +212 -0
- package/src/Namespace.mjs +206 -0
- package/src/Namespace.ts +260 -0
- package/src/ObjectSlice.cjs +199 -0
- package/src/ObjectSlice.mjs +195 -0
- package/src/ObjectSlice.ts +228 -0
- package/src/clone/errors/CloneError.cjs +22 -0
- package/src/clone/errors/CloneError.mjs +19 -0
- package/src/clone/errors/CloneError.ts +26 -0
- package/src/clone/errors/DeepCloneError.cjs +11 -0
- package/src/clone/errors/DeepCloneError.mjs +6 -0
- package/src/clone/errors/DeepCloneError.ts +8 -0
- package/src/clone/errors/ShallowCloneError.cjs +11 -0
- package/src/clone/errors/ShallowCloneError.mjs +6 -0
- package/src/clone/errors/ShallowCloneError.ts +8 -0
- package/src/clone/index.cjs +188 -0
- package/src/clone/index.mjs +178 -0
- package/src/clone/index.ts +195 -0
- package/src/elements/Annotation.cjs +35 -0
- package/src/elements/Annotation.mjs +30 -0
- package/src/elements/Annotation.ts +35 -0
- package/src/elements/Comment.cjs +18 -0
- package/src/elements/Comment.mjs +13 -0
- package/src/elements/Comment.ts +16 -0
- package/src/elements/LinkElement.cjs +50 -0
- package/src/elements/LinkElement.mjs +45 -0
- package/src/elements/LinkElement.ts +49 -0
- package/src/elements/ParseResult.cjs +91 -0
- package/src/elements/ParseResult.mjs +86 -0
- package/src/elements/ParseResult.ts +94 -0
- package/src/elements/RefElement.cjs +34 -0
- package/src/elements/RefElement.mjs +29 -0
- package/src/elements/RefElement.ts +33 -0
- package/src/elements/SourceMap.cjs +140 -0
- package/src/elements/SourceMap.mjs +134 -0
- package/src/elements/SourceMap.ts +170 -0
- package/src/elements/Style.cjs +54 -0
- package/src/elements/Style.mjs +48 -0
- package/src/elements/Style.ts +56 -0
- package/src/index.cjs +58 -0
- package/src/index.mjs +11 -0
- package/src/index.ts +79 -0
- package/src/predicates/elements.cjs +46 -0
- package/src/predicates/elements.mjs +35 -0
- package/src/predicates/elements.ts +42 -0
- package/src/predicates/index.cjs +77 -0
- package/src/predicates/index.mjs +56 -0
- package/src/predicates/index.ts +89 -0
- package/src/predicates/primitives.cjs +69 -0
- package/src/predicates/primitives.mjs +56 -0
- package/src/predicates/primitives.ts +79 -0
- package/src/primitives/ArrayElement.cjs +155 -0
- package/src/primitives/ArrayElement.mjs +148 -0
- package/src/primitives/ArrayElement.ts +161 -0
- package/src/primitives/BooleanElement.cjs +20 -0
- package/src/primitives/BooleanElement.mjs +15 -0
- package/src/primitives/BooleanElement.ts +18 -0
- package/src/primitives/CollectionElement.cjs +180 -0
- package/src/primitives/CollectionElement.mjs +173 -0
- package/src/primitives/CollectionElement.ts +191 -0
- package/src/primitives/Element.cjs +510 -0
- package/src/primitives/Element.mjs +505 -0
- package/src/primitives/Element.ts +556 -0
- package/src/primitives/MemberElement.cjs +58 -0
- package/src/primitives/MemberElement.mjs +53 -0
- package/src/primitives/MemberElement.ts +61 -0
- package/src/primitives/NullElement.cjs +28 -0
- package/src/primitives/NullElement.mjs +23 -0
- package/src/primitives/NullElement.ts +26 -0
- package/src/primitives/NumberElement.cjs +20 -0
- package/src/primitives/NumberElement.mjs +15 -0
- package/src/primitives/NumberElement.ts +18 -0
- package/src/primitives/ObjectElement.cjs +220 -0
- package/src/primitives/ObjectElement.mjs +214 -0
- package/src/primitives/ObjectElement.ts +263 -0
- package/src/primitives/StringElement.cjs +27 -0
- package/src/primitives/StringElement.mjs +22 -0
- package/src/primitives/StringElement.ts +25 -0
- package/src/registration.cjs +101 -0
- package/src/registration.mjs +79 -0
- package/src/registration.ts +111 -0
- package/src/serialisers/JSONSerialiser.cjs +230 -0
- package/src/serialisers/JSONSerialiser.mjs +221 -0
- package/src/serialisers/JSONSerialiser.ts +295 -0
- package/src/types.cjs +3 -0
- package/src/types.mjs +1 -0
- package/src/types.ts +72 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import StringElement from '../primitives/StringElement.ts';
|
|
2
|
+
import type { Meta, Attributes } from '../types.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CommentElement represents a comment in the source document.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
class CommentElement extends StringElement {
|
|
10
|
+
constructor(content?: string, meta?: Meta, attributes?: Attributes) {
|
|
11
|
+
super(content, meta, attributes);
|
|
12
|
+
this.element = 'comment';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default CommentElement;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _Element = _interopRequireDefault(require("../primitives/Element.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* LinkElement represents a hyperlink in ApiDOM.
|
|
9
|
+
*
|
|
10
|
+
* Hyperlinking MAY be used to link to other resources, provide links to
|
|
11
|
+
* instructions on how to process a given element (by way of a profile or
|
|
12
|
+
* other means), and may be used to provide meta data about the element in
|
|
13
|
+
* which it's found. The meaning and purpose of the hyperlink is defined by
|
|
14
|
+
* the link relation according to RFC 5988.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
class LinkElement extends _Element.default {
|
|
19
|
+
constructor(content, meta, attributes) {
|
|
20
|
+
super(content || [], meta, attributes);
|
|
21
|
+
this.element = 'link';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The relation identifier for the link, as defined in RFC 5988.
|
|
26
|
+
*/
|
|
27
|
+
get relation() {
|
|
28
|
+
if (this.hasAttributesProperty('relation')) {
|
|
29
|
+
return this.attributes.get('relation');
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
set relation(relation) {
|
|
34
|
+
this.attributes.set('relation', relation);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The URI for the given link.
|
|
39
|
+
*/
|
|
40
|
+
get href() {
|
|
41
|
+
if (this.hasAttributesProperty('href')) {
|
|
42
|
+
return this.attributes.get('href');
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
set href(href) {
|
|
47
|
+
this.attributes.set('href', href);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var _default = exports.default = LinkElement;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Element from "../primitives/Element.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* LinkElement represents a hyperlink in ApiDOM.
|
|
4
|
+
*
|
|
5
|
+
* Hyperlinking MAY be used to link to other resources, provide links to
|
|
6
|
+
* instructions on how to process a given element (by way of a profile or
|
|
7
|
+
* other means), and may be used to provide meta data about the element in
|
|
8
|
+
* which it's found. The meaning and purpose of the hyperlink is defined by
|
|
9
|
+
* the link relation according to RFC 5988.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
class LinkElement extends Element {
|
|
14
|
+
constructor(content, meta, attributes) {
|
|
15
|
+
super(content || [], meta, attributes);
|
|
16
|
+
this.element = 'link';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The relation identifier for the link, as defined in RFC 5988.
|
|
21
|
+
*/
|
|
22
|
+
get relation() {
|
|
23
|
+
if (this.hasAttributesProperty('relation')) {
|
|
24
|
+
return this.attributes.get('relation');
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
set relation(relation) {
|
|
29
|
+
this.attributes.set('relation', relation);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The URI for the given link.
|
|
34
|
+
*/
|
|
35
|
+
get href() {
|
|
36
|
+
if (this.hasAttributesProperty('href')) {
|
|
37
|
+
return this.attributes.get('href');
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
set href(href) {
|
|
42
|
+
this.attributes.set('href', href);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export default LinkElement;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Element, { type Meta, type Attributes } from '../primitives/Element.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LinkElement represents a hyperlink in ApiDOM.
|
|
5
|
+
*
|
|
6
|
+
* Hyperlinking MAY be used to link to other resources, provide links to
|
|
7
|
+
* instructions on how to process a given element (by way of a profile or
|
|
8
|
+
* other means), and may be used to provide meta data about the element in
|
|
9
|
+
* which it's found. The meaning and purpose of the hyperlink is defined by
|
|
10
|
+
* the link relation according to RFC 5988.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class LinkElement extends Element {
|
|
15
|
+
constructor(content?: unknown, meta?: Meta, attributes?: Attributes) {
|
|
16
|
+
super(content || [], meta, attributes);
|
|
17
|
+
this.element = 'link';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The relation identifier for the link, as defined in RFC 5988.
|
|
22
|
+
*/
|
|
23
|
+
get relation(): Element | undefined {
|
|
24
|
+
if (this.hasAttributesProperty('relation')) {
|
|
25
|
+
return this.attributes.get('relation');
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set relation(relation: string | Element | undefined) {
|
|
31
|
+
this.attributes.set('relation', relation);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The URI for the given link.
|
|
36
|
+
*/
|
|
37
|
+
get href(): Element | undefined {
|
|
38
|
+
if (this.hasAttributesProperty('href')) {
|
|
39
|
+
return this.attributes.get('href');
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set href(href: string | Element | undefined) {
|
|
45
|
+
this.attributes.set('href', href);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default LinkElement;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ArrayElement = _interopRequireDefault(require("../primitives/ArrayElement.cjs"));
|
|
7
|
+
var _index = require("../predicates/index.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* ParseResultElement represents the result of parsing a document.
|
|
10
|
+
*
|
|
11
|
+
* Contains the parsed API element, any result elements, and annotations
|
|
12
|
+
* (warnings and errors) from the parsing process.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class ParseResultElement extends _ArrayElement.default {
|
|
17
|
+
constructor(content, meta, attributes) {
|
|
18
|
+
super(content, meta, attributes);
|
|
19
|
+
this.element = 'parseResult';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The main API element from the parse result.
|
|
24
|
+
*/
|
|
25
|
+
get api() {
|
|
26
|
+
return this.filter(item => (0, _index.includesClasses)(item, ['api'])).first;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* All result elements from the parse result.
|
|
31
|
+
*/
|
|
32
|
+
get results() {
|
|
33
|
+
return this.filter(item => (0, _index.includesClasses)(item, ['result']));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The first result element.
|
|
38
|
+
*/
|
|
39
|
+
get result() {
|
|
40
|
+
return this.results.first;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* All annotation elements (warnings and errors).
|
|
45
|
+
*/
|
|
46
|
+
get annotations() {
|
|
47
|
+
return this.filter(item => item.element === 'annotation');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* All warning annotations.
|
|
52
|
+
*/
|
|
53
|
+
get warnings() {
|
|
54
|
+
return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['warning']));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* All error annotations.
|
|
59
|
+
*/
|
|
60
|
+
get errors() {
|
|
61
|
+
return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['error']));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether the parse result is empty (contains only annotations).
|
|
66
|
+
*/
|
|
67
|
+
get isEmpty() {
|
|
68
|
+
return this.reject(item => item.element === 'annotation').length === 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Replaces the first result element with the given replacement.
|
|
73
|
+
* @returns true if replacement was successful, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
replaceResult(replacement) {
|
|
76
|
+
const {
|
|
77
|
+
result
|
|
78
|
+
} = this;
|
|
79
|
+
if (result === undefined) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const content = this._content;
|
|
83
|
+
const searchIndex = content.findIndex(e => e === result);
|
|
84
|
+
if (searchIndex === -1) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
content[searchIndex] = replacement;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var _default = exports.default = ParseResultElement;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import ArrayElement from "../primitives/ArrayElement.mjs";
|
|
2
|
+
import { includesClasses } from "../predicates/index.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* ParseResultElement represents the result of parsing a document.
|
|
5
|
+
*
|
|
6
|
+
* Contains the parsed API element, any result elements, and annotations
|
|
7
|
+
* (warnings and errors) from the parsing process.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class ParseResultElement extends ArrayElement {
|
|
12
|
+
constructor(content, meta, attributes) {
|
|
13
|
+
super(content, meta, attributes);
|
|
14
|
+
this.element = 'parseResult';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The main API element from the parse result.
|
|
19
|
+
*/
|
|
20
|
+
get api() {
|
|
21
|
+
return this.filter(item => includesClasses(item, ['api'])).first;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* All result elements from the parse result.
|
|
26
|
+
*/
|
|
27
|
+
get results() {
|
|
28
|
+
return this.filter(item => includesClasses(item, ['result']));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The first result element.
|
|
33
|
+
*/
|
|
34
|
+
get result() {
|
|
35
|
+
return this.results.first;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* All annotation elements (warnings and errors).
|
|
40
|
+
*/
|
|
41
|
+
get annotations() {
|
|
42
|
+
return this.filter(item => item.element === 'annotation');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* All warning annotations.
|
|
47
|
+
*/
|
|
48
|
+
get warnings() {
|
|
49
|
+
return this.filter(item => item.element === 'annotation' && includesClasses(item, ['warning']));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* All error annotations.
|
|
54
|
+
*/
|
|
55
|
+
get errors() {
|
|
56
|
+
return this.filter(item => item.element === 'annotation' && includesClasses(item, ['error']));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether the parse result is empty (contains only annotations).
|
|
61
|
+
*/
|
|
62
|
+
get isEmpty() {
|
|
63
|
+
return this.reject(item => item.element === 'annotation').length === 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Replaces the first result element with the given replacement.
|
|
68
|
+
* @returns true if replacement was successful, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
replaceResult(replacement) {
|
|
71
|
+
const {
|
|
72
|
+
result
|
|
73
|
+
} = this;
|
|
74
|
+
if (result === undefined) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const content = this._content;
|
|
78
|
+
const searchIndex = content.findIndex(e => e === result);
|
|
79
|
+
if (searchIndex === -1) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
content[searchIndex] = replacement;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export default ParseResultElement;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import ArrayElement from '../primitives/ArrayElement.ts';
|
|
2
|
+
import type Element from '../primitives/Element.ts';
|
|
3
|
+
import { includesClasses } from '../predicates/index.ts';
|
|
4
|
+
import type { Meta, Attributes } from '../primitives/Element.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ParseResultElement represents the result of parsing a document.
|
|
8
|
+
*
|
|
9
|
+
* Contains the parsed API element, any result elements, and annotations
|
|
10
|
+
* (warnings and errors) from the parsing process.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class ParseResultElement extends ArrayElement {
|
|
15
|
+
constructor(content?: unknown[], meta?: Meta, attributes?: Attributes) {
|
|
16
|
+
super(content, meta, attributes);
|
|
17
|
+
this.element = 'parseResult';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The main API element from the parse result.
|
|
22
|
+
*/
|
|
23
|
+
get api(): Element | undefined {
|
|
24
|
+
return this.filter((item) => includesClasses(item, ['api'])).first;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* All result elements from the parse result.
|
|
29
|
+
*/
|
|
30
|
+
get results(): ArrayElement {
|
|
31
|
+
return this.filter((item) => includesClasses(item, ['result']));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The first result element.
|
|
36
|
+
*/
|
|
37
|
+
get result(): Element | undefined {
|
|
38
|
+
return this.results.first;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* All annotation elements (warnings and errors).
|
|
43
|
+
*/
|
|
44
|
+
get annotations(): ArrayElement {
|
|
45
|
+
return this.filter((item) => item.element === 'annotation');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* All warning annotations.
|
|
50
|
+
*/
|
|
51
|
+
get warnings(): ArrayElement {
|
|
52
|
+
return this.filter(
|
|
53
|
+
(item) => item.element === 'annotation' && includesClasses(item, ['warning']),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* All error annotations.
|
|
59
|
+
*/
|
|
60
|
+
get errors(): ArrayElement {
|
|
61
|
+
return this.filter((item) => item.element === 'annotation' && includesClasses(item, ['error']));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether the parse result is empty (contains only annotations).
|
|
66
|
+
*/
|
|
67
|
+
override get isEmpty(): boolean {
|
|
68
|
+
return this.reject((item) => item.element === 'annotation').length === 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Replaces the first result element with the given replacement.
|
|
73
|
+
* @returns true if replacement was successful, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
replaceResult(replacement: Element): boolean {
|
|
76
|
+
const { result } = this;
|
|
77
|
+
|
|
78
|
+
if (result === undefined) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const content = this._content as Element[];
|
|
83
|
+
const searchIndex = content.findIndex((e) => e === result);
|
|
84
|
+
if (searchIndex === -1) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
content[searchIndex] = replacement;
|
|
89
|
+
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default ParseResultElement;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _Element = _interopRequireDefault(require("../primitives/Element.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* RefElement represents a reference to another element in ApiDOM.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class RefElement extends _Element.default {
|
|
12
|
+
constructor(content, meta, attributes) {
|
|
13
|
+
super(content || [], meta, attributes);
|
|
14
|
+
this.element = 'ref';
|
|
15
|
+
if (!this.path) {
|
|
16
|
+
this.path = 'element';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Path of referenced element to transclude instead of element itself.
|
|
22
|
+
* @defaultValue 'element'
|
|
23
|
+
*/
|
|
24
|
+
get path() {
|
|
25
|
+
if (this.hasAttributesProperty('path')) {
|
|
26
|
+
return this.attributes.get('path');
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
set path(newValue) {
|
|
31
|
+
this.attributes.set('path', newValue);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var _default = exports.default = RefElement;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Element from "../primitives/Element.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* RefElement represents a reference to another element in ApiDOM.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
class RefElement extends Element {
|
|
7
|
+
constructor(content, meta, attributes) {
|
|
8
|
+
super(content || [], meta, attributes);
|
|
9
|
+
this.element = 'ref';
|
|
10
|
+
if (!this.path) {
|
|
11
|
+
this.path = 'element';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Path of referenced element to transclude instead of element itself.
|
|
17
|
+
* @defaultValue 'element'
|
|
18
|
+
*/
|
|
19
|
+
get path() {
|
|
20
|
+
if (this.hasAttributesProperty('path')) {
|
|
21
|
+
return this.attributes.get('path');
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
set path(newValue) {
|
|
26
|
+
this.attributes.set('path', newValue);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default RefElement;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Element, { type Meta, type Attributes } from '../primitives/Element.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RefElement represents a reference to another element in ApiDOM.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
class RefElement extends Element {
|
|
8
|
+
constructor(content?: unknown, meta?: Meta, attributes?: Attributes) {
|
|
9
|
+
super(content || [], meta, attributes);
|
|
10
|
+
this.element = 'ref';
|
|
11
|
+
|
|
12
|
+
if (!this.path) {
|
|
13
|
+
this.path = 'element';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Path of referenced element to transclude instead of element itself.
|
|
19
|
+
* @defaultValue 'element'
|
|
20
|
+
*/
|
|
21
|
+
get path(): Element | undefined {
|
|
22
|
+
if (this.hasAttributesProperty('path')) {
|
|
23
|
+
return this.attributes.get('path');
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
set path(newValue: string | Element | undefined) {
|
|
29
|
+
this.attributes.set('path', newValue);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default RefElement;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* Shape with optional source position properties.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SourceMapElement stores source position as a compact VLQ-encoded string.
|
|
14
|
+
*
|
|
15
|
+
* The encoded string contains 6 values: startLine, startCharacter, startOffset,
|
|
16
|
+
* endLine, endCharacter, endOffset. All values use UTF-16 code units,
|
|
17
|
+
* compatible with LSP, TextDocument, and JavaScript string indexing.
|
|
18
|
+
*
|
|
19
|
+
* web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
class SourceMapElement extends _StringElement.default {
|
|
24
|
+
constructor(content, meta, attributes) {
|
|
25
|
+
super(content, meta, attributes);
|
|
26
|
+
this.element = 'sourceMap';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Transfers source position properties from one object to another.
|
|
31
|
+
*/
|
|
32
|
+
static transfer(from, to) {
|
|
33
|
+
to.startLine = from.startLine;
|
|
34
|
+
to.startCharacter = from.startCharacter;
|
|
35
|
+
to.startOffset = from.startOffset;
|
|
36
|
+
to.endLine = from.endLine;
|
|
37
|
+
to.endCharacter = from.endCharacter;
|
|
38
|
+
to.endOffset = from.endOffset;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a SourceMapElement from source position properties.
|
|
43
|
+
* Returns undefined if any position property is not a number.
|
|
44
|
+
* Also assigns position properties to the instance for inspection.
|
|
45
|
+
*/
|
|
46
|
+
static from(source) {
|
|
47
|
+
const {
|
|
48
|
+
startLine,
|
|
49
|
+
startCharacter,
|
|
50
|
+
startOffset,
|
|
51
|
+
endLine,
|
|
52
|
+
endCharacter,
|
|
53
|
+
endOffset
|
|
54
|
+
} = source;
|
|
55
|
+
if (typeof startLine !== 'number' || typeof startCharacter !== 'number' || typeof startOffset !== 'number' || typeof endLine !== 'number' || typeof endCharacter !== 'number' || typeof endOffset !== 'number') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const packed = packSourceMap([startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]);
|
|
59
|
+
const sourceMap = new SourceMapElement(packed);
|
|
60
|
+
sourceMap.startLine = startLine;
|
|
61
|
+
sourceMap.startCharacter = startCharacter;
|
|
62
|
+
sourceMap.startOffset = startOffset;
|
|
63
|
+
sourceMap.endLine = endLine;
|
|
64
|
+
sourceMap.endCharacter = endCharacter;
|
|
65
|
+
sourceMap.endOffset = endOffset;
|
|
66
|
+
return sourceMap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Decodes the VLQ string and applies source position properties to the target.
|
|
71
|
+
*/
|
|
72
|
+
applyTo(target) {
|
|
73
|
+
if (!this.content) return;
|
|
74
|
+
[target.startLine, target.startCharacter, target.startOffset, target.endLine, target.endCharacter, target.endOffset] = unpackSourceMap(this.content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
78
|
+
|
|
79
|
+
// Encode one unsigned integer to Base64-VLQ
|
|
80
|
+
function vlqEncodeInt(value) {
|
|
81
|
+
let vlq = value >>> 0; // ensure unsigned 32-bit
|
|
82
|
+
let out = '';
|
|
83
|
+
do {
|
|
84
|
+
let digit = vlq & 31; // 5 bits
|
|
85
|
+
vlq >>>= 5;
|
|
86
|
+
if (vlq !== 0) digit |= 32; // continuation bit
|
|
87
|
+
out += BASE64[digit];
|
|
88
|
+
} while (vlq !== 0);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Decode one unsigned integer from Base64-VLQ, starting at `index`
|
|
93
|
+
function vlqDecodeInt(str, index = 0) {
|
|
94
|
+
let result = 0;
|
|
95
|
+
let shift = 0;
|
|
96
|
+
let i = index;
|
|
97
|
+
while (true) {
|
|
98
|
+
const ch = str[i++];
|
|
99
|
+
const digit = BASE64.indexOf(ch);
|
|
100
|
+
if (digit === -1) throw new Error(`Invalid Base64 VLQ char: ${ch}`);
|
|
101
|
+
const cont = (digit & 32) !== 0;
|
|
102
|
+
result |= (digit & 31) << shift;
|
|
103
|
+
shift += 5;
|
|
104
|
+
if (!cont) break;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
value: result >>> 0,
|
|
108
|
+
next: i
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Span of 6 position values: [startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Encodes 6 position values into a compact VLQ string.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
function packSourceMap(v) {
|
|
122
|
+
return 'sm1:' + v.map(vlqEncodeInt).join('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a VLQ string into 6 position values.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
function unpackSourceMap(packed) {
|
|
130
|
+
const s = packed.startsWith('sm1:') ? packed.slice(4) : packed;
|
|
131
|
+
const out = [];
|
|
132
|
+
let i = 0;
|
|
133
|
+
for (let k = 0; k < 6; k++) {
|
|
134
|
+
const r = vlqDecodeInt(s, i);
|
|
135
|
+
out.push(r.value);
|
|
136
|
+
i = r.next;
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
var _default = exports.default = SourceMapElement;
|