@speclynx/apidom-ns-json-schema-draft-6 1.12.2 → 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/CHANGELOG.md +25 -0
- package/NOTICE +16 -7
- package/README.md +24 -24
- package/dist/apidom-ns-json-schema-draft-6.browser.js +1 -1
- package/package.json +11 -9
- package/src/elements/JSONSchema.cjs +14 -6
- package/src/elements/JSONSchema.mjs +14 -6
- package/src/elements/LinkDescription.cjs +4 -0
- package/src/elements/LinkDescription.mjs +4 -0
- package/src/index.cjs +8 -21
- package/src/index.mjs +2 -5
- package/src/predicates.cjs +4 -15
- package/src/predicates.mjs +2 -15
- package/src/refractor/index.cjs +38 -17
- package/src/refractor/index.mjs +33 -15
- package/src/refractor/inspect.cjs +47 -0
- package/src/refractor/inspect.mjs +39 -0
- package/src/refractor/plugins/replace-empty-element.cjs +28 -26
- package/src/refractor/plugins/replace-empty-element.mjs +14 -11
- package/src/refractor/specification.cjs +14 -2
- package/src/refractor/specification.mjs +14 -2
- package/src/refractor/toolbox.cjs +8 -3
- package/src/refractor/toolbox.mjs +6 -2
- package/src/refractor/visitors/json-schema/ExamplesVisitor.cjs +2 -3
- package/src/refractor/visitors/json-schema/ExamplesVisitor.mjs +2 -3
- package/src/refractor/visitors/json-schema/ItemsVisitor.cjs +3 -4
- package/src/refractor/visitors/json-schema/ItemsVisitor.mjs +3 -4
- package/src/refractor/visitors/json-schema/index.cjs +4 -3
- package/src/refractor/visitors/json-schema/index.mjs +4 -3
- package/src/refractor/visitors/json-schema/link-description/index.cjs +2 -0
- package/src/refractor/visitors/json-schema/link-description/index.mjs +2 -0
- package/types/apidom-ns-json-schema-draft-6.d.ts +90 -245
- package/src/refractor/registration.cjs +0 -13
- package/src/refractor/registration.mjs +0 -6
- package/src/traversal/visitor.cjs +0 -17
- package/src/traversal/visitor.mjs +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-ns-json-schema-draft-6",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "JSON Schema Draft 6 namespace for ApiDOM.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"sideEffects": [
|
|
12
|
-
"./src/refractor/
|
|
13
|
-
"./src/refractor/
|
|
12
|
+
"./src/refractor/inspect.mjs",
|
|
13
|
+
"./src/refractor/inspect.cjs"
|
|
14
14
|
],
|
|
15
15
|
"unpkg": "./dist/apidom-ns-json-schema-draft-6.browser.min.js",
|
|
16
16
|
"main": "./src/index.cjs",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
|
|
32
32
|
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 mocha",
|
|
33
33
|
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
|
|
34
|
-
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json
|
|
34
|
+
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
|
|
35
|
+
"posttypescript:declaration": "node scripts/fix-dts-ts-ignore.mjs",
|
|
35
36
|
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
|
36
37
|
"postpack": "rimraf NOTICE LICENSES"
|
|
37
38
|
},
|
|
@@ -43,10 +44,11 @@
|
|
|
43
44
|
"license": "Apache-2.0",
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
46
|
-
"@speclynx/apidom-core": "^1.
|
|
47
|
-
"@speclynx/apidom-
|
|
48
|
-
"@speclynx/apidom-
|
|
49
|
-
"@
|
|
47
|
+
"@speclynx/apidom-core": "^2.1.0",
|
|
48
|
+
"@speclynx/apidom-datamodel": "^2.1.0",
|
|
49
|
+
"@speclynx/apidom-error": "^2.1.0",
|
|
50
|
+
"@speclynx/apidom-ns-json-schema-draft-4": "^2.1.0",
|
|
51
|
+
"@speclynx/apidom-traverse": "^2.1.0",
|
|
50
52
|
"ramda": "~0.32.0",
|
|
51
53
|
"ramda-adjunct": "^6.0.0",
|
|
52
54
|
"ts-mixer": "^6.0.4"
|
|
@@ -61,5 +63,5 @@
|
|
|
61
63
|
"README.md",
|
|
62
64
|
"CHANGELOG.md"
|
|
63
65
|
],
|
|
64
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "dd02cfbbe82b0a31c6e7c444cec140e740e1c6e9"
|
|
65
67
|
}
|
|
@@ -19,10 +19,10 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
|
|
|
19
19
|
* URI: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
get
|
|
22
|
+
get idField() {
|
|
23
23
|
throw new _apidomError.UnsupportedOperationError('id keyword from Core vocabulary has been renamed to $id.');
|
|
24
24
|
}
|
|
25
|
-
set
|
|
25
|
+
set idField(id) {
|
|
26
26
|
throw new _apidomError.UnsupportedOperationError('id keyword from Core vocabulary has been renamed to $id.');
|
|
27
27
|
}
|
|
28
28
|
get $id() {
|
|
@@ -59,16 +59,20 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
|
|
|
59
59
|
* Validation keywords for arrays
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
|
-
get
|
|
62
|
+
get containsField() {
|
|
63
63
|
return this.get('contains');
|
|
64
64
|
}
|
|
65
|
-
set
|
|
65
|
+
set containsField(contains) {
|
|
66
66
|
this.set('contains', contains);
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
70
|
+
get itemsField() {
|
|
69
71
|
return this.get('items');
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
|
|
74
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
75
|
+
set itemsField(items) {
|
|
72
76
|
this.set('items', items);
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -93,9 +97,13 @@ class JSONSchema extends _apidomNsJsonSchemaDraft.JSONSchemaElement {
|
|
|
93
97
|
set const(constValue) {
|
|
94
98
|
this.set('const', constValue);
|
|
95
99
|
}
|
|
100
|
+
|
|
101
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
96
102
|
get not() {
|
|
97
103
|
return this.get('not');
|
|
98
104
|
}
|
|
105
|
+
|
|
106
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
99
107
|
set not(not) {
|
|
100
108
|
this.set('not', not);
|
|
101
109
|
}
|
|
@@ -16,10 +16,10 @@ class JSONSchema extends JSONSchemaElement {
|
|
|
16
16
|
* URI: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
get
|
|
19
|
+
get idField() {
|
|
20
20
|
throw new UnsupportedOperationError('id keyword from Core vocabulary has been renamed to $id.');
|
|
21
21
|
}
|
|
22
|
-
set
|
|
22
|
+
set idField(id) {
|
|
23
23
|
throw new UnsupportedOperationError('id keyword from Core vocabulary has been renamed to $id.');
|
|
24
24
|
}
|
|
25
25
|
get $id() {
|
|
@@ -56,16 +56,20 @@ class JSONSchema extends JSONSchemaElement {
|
|
|
56
56
|
* Validation keywords for arrays
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
|
-
get
|
|
59
|
+
get containsField() {
|
|
60
60
|
return this.get('contains');
|
|
61
61
|
}
|
|
62
|
-
set
|
|
62
|
+
set containsField(contains) {
|
|
63
63
|
this.set('contains', contains);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
|
|
66
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
67
|
+
get itemsField() {
|
|
66
68
|
return this.get('items');
|
|
67
69
|
}
|
|
68
|
-
|
|
70
|
+
|
|
71
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
72
|
+
set itemsField(items) {
|
|
69
73
|
this.set('items', items);
|
|
70
74
|
}
|
|
71
75
|
|
|
@@ -90,9 +94,13 @@ class JSONSchema extends JSONSchemaElement {
|
|
|
90
94
|
set const(constValue) {
|
|
91
95
|
this.set('const', constValue);
|
|
92
96
|
}
|
|
97
|
+
|
|
98
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
93
99
|
get not() {
|
|
94
100
|
return this.get('not');
|
|
95
101
|
}
|
|
102
|
+
|
|
103
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
96
104
|
set not(not) {
|
|
97
105
|
this.set('not', not);
|
|
98
106
|
}
|
|
@@ -16,9 +16,13 @@ class LinkDescription extends _apidomNsJsonSchemaDraft.LinkDescriptionElement {
|
|
|
16
16
|
set hrefSchema(hrefSchema) {
|
|
17
17
|
this.set('hrefSchema', hrefSchema);
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
19
21
|
get targetSchema() {
|
|
20
22
|
return this.get('targetSchema');
|
|
21
23
|
}
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
22
26
|
set targetSchema(targetSchema) {
|
|
23
27
|
this.set('targetSchema', targetSchema);
|
|
24
28
|
}
|
|
@@ -12,9 +12,13 @@ class LinkDescription extends LinkDescriptionElement {
|
|
|
12
12
|
set hrefSchema(hrefSchema) {
|
|
13
13
|
this.set('hrefSchema', hrefSchema);
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
15
17
|
get targetSchema() {
|
|
16
18
|
return this.get('targetSchema');
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
// @ts-expect-error - widening type to include BooleanElement (boolean schemas introduced in draft-6)
|
|
18
22
|
set targetSchema(targetSchema) {
|
|
19
23
|
this.set('targetSchema', targetSchema);
|
|
20
24
|
}
|
package/src/index.cjs
CHANGED
|
@@ -3,18 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.
|
|
7
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
-
exports.isRefElement = _apidomCore.isRefElement;
|
|
9
|
-
exports.isLinkElement = _apidomCore.isLinkElement;
|
|
10
|
-
exports.isMemberElement = _apidomCore.isMemberElement;
|
|
11
|
-
exports.isObjectElement = _apidomCore.isObjectElement;
|
|
12
|
-
exports.isArrayElement = _apidomCore.isArrayElement;
|
|
13
|
-
exports.isBooleanElement = _apidomCore.isBooleanElement;
|
|
14
|
-
exports.isNullElement = _apidomCore.isNullElement;
|
|
15
|
-
exports.isElement = _apidomCore.isElement;
|
|
16
|
-
exports.isNumberElement = _apidomCore.isNumberElement;
|
|
17
|
-
exports.isStringElement = _apidomCore.isStringElement;
|
|
6
|
+
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractLinkDescription = exports.refractJSONSchema = exports.refract = exports.mediaTypes = exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceLikeElement = exports.isJSONReferenceElement = exports.default = exports.Visitor = exports.SpecificationVisitor = exports.PatternedFieldsVisitor = exports.ParentSchemaAwareVisitor = exports.MediaElement = exports.MapVisitor = exports.LinkDescriptionVisitor = exports.LinkDescriptionElement = exports.JSONSchemaVisitor = exports.JSONSchemaElement = exports.JSONSchemaDraft6MediaTypes = exports.JSONReferenceElement = exports.ItemsVisitor = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.AlternatingVisitor = void 0;
|
|
18
7
|
var _mediaTypes = _interopRequireWildcard(require("./media-types.cjs"));
|
|
19
8
|
exports.mediaTypes = _mediaTypes.default;
|
|
20
9
|
exports.JSONSchemaDraft6MediaTypes = _mediaTypes.JSONSchemaDraft6MediaTypes;
|
|
@@ -24,7 +13,8 @@ var _replaceEmptyElement = _interopRequireDefault(require("./refractor/plugins/r
|
|
|
24
13
|
exports.refractorPluginReplaceEmptyElement = _replaceEmptyElement.default;
|
|
25
14
|
var _index = _interopRequireWildcard(require("./refractor/index.cjs"));
|
|
26
15
|
exports.refract = _index.default;
|
|
27
|
-
exports.
|
|
16
|
+
exports.refractJSONSchema = _index.refractJSONSchema;
|
|
17
|
+
exports.refractLinkDescription = _index.refractLinkDescription;
|
|
28
18
|
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
|
29
19
|
exports.specificationObj = _specification.default;
|
|
30
20
|
var _predicates = require("./predicates.cjs");
|
|
@@ -42,17 +32,14 @@ exports.MapVisitor = _apidomNsJsonSchemaDraft.MapVisitor;
|
|
|
42
32
|
exports.AlternatingVisitor = _apidomNsJsonSchemaDraft.AlternatingVisitor;
|
|
43
33
|
exports.ParentSchemaAwareVisitor = _apidomNsJsonSchemaDraft.ParentSchemaAwareVisitor;
|
|
44
34
|
exports.Visitor = _apidomNsJsonSchemaDraft.Visitor;
|
|
45
|
-
exports.JSONReferenceElement = _apidomNsJsonSchemaDraft.JSONReferenceElement;
|
|
46
|
-
exports.MediaElement = _apidomNsJsonSchemaDraft.MediaElement;
|
|
47
35
|
var _index2 = _interopRequireDefault(require("./refractor/visitors/json-schema/link-description/index.cjs"));
|
|
48
36
|
exports.LinkDescriptionVisitor = _index2.default;
|
|
49
37
|
var _index3 = _interopRequireDefault(require("./refractor/visitors/json-schema/index.cjs"));
|
|
50
38
|
exports.JSONSchemaVisitor = _index3.default;
|
|
51
39
|
var _ItemsVisitor = _interopRequireDefault(require("./refractor/visitors/json-schema/ItemsVisitor.cjs"));
|
|
52
40
|
exports.ItemsVisitor = _ItemsVisitor.default;
|
|
53
|
-
var
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
56
|
-
|
|
57
|
-
exports.
|
|
58
|
-
exports.LinkDescriptionElement = _registration.LinkDescriptionElement;
|
|
41
|
+
var _inspect = require("./refractor/inspect.cjs");
|
|
42
|
+
exports.JSONSchemaElement = _inspect.JSONSchemaElement;
|
|
43
|
+
exports.JSONReferenceElement = _inspect.JSONReferenceElement;
|
|
44
|
+
exports.MediaElement = _inspect.MediaElement;
|
|
45
|
+
exports.LinkDescriptionElement = _inspect.LinkDescriptionElement;
|
package/src/index.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
export { isRefElement, isLinkElement, isMemberElement, isObjectElement, isArrayElement, isBooleanElement, isNullElement, isElement, isNumberElement, isStringElement } from '@speclynx/apidom-core';
|
|
2
1
|
export { default as mediaTypes, JSONSchemaDraft6MediaTypes } from "./media-types.mjs";
|
|
3
2
|
export { default } from "./namespace.mjs";
|
|
4
3
|
export { default as refractorPluginReplaceEmptyElement } from "./refractor/plugins/replace-empty-element.mjs";
|
|
5
|
-
export { default as refract,
|
|
4
|
+
export { default as refract, refractJSONSchema, refractLinkDescription } from "./refractor/index.mjs";
|
|
6
5
|
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
7
6
|
export { isJSONReferenceElement, isJSONSchemaElement, isLinkDescriptionElement, isMediaElement } from "./predicates.mjs";
|
|
8
7
|
export { isJSONReferenceLikeElement, SpecificationVisitor, FallbackVisitor, FixedFieldsVisitor, PatternedFieldsVisitor, MapVisitor, AlternatingVisitor, ParentSchemaAwareVisitor, Visitor } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
9
8
|
export { default as LinkDescriptionVisitor } from "./refractor/visitors/json-schema/link-description/index.mjs";
|
|
10
9
|
export { default as JSONSchemaVisitor } from "./refractor/visitors/json-schema/index.mjs";
|
|
11
10
|
export { default as ItemsVisitor } from "./refractor/visitors/json-schema/ItemsVisitor.mjs";
|
|
12
|
-
export { keyMap, getNodeType } from "./traversal/visitor.mjs";
|
|
13
11
|
/**
|
|
14
12
|
* JSON Schema Draft 6 specification elements.
|
|
15
13
|
*/
|
|
16
|
-
export { JSONSchemaElement, LinkDescriptionElement } from "./refractor/
|
|
17
|
-
export { JSONReferenceElement, MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
14
|
+
export { JSONSchemaElement, JSONReferenceElement, MediaElement, LinkDescriptionElement } from "./refractor/inspect.mjs";
|
package/src/predicates.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.isMediaElement = exports.isLinkDescriptionElement = exports.isJSONSchemaElement = exports.isJSONReferenceElement = void 0;
|
|
6
|
-
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
6
|
var _JSONSchema = _interopRequireDefault(require("./elements/JSONSchema.cjs"));
|
|
8
7
|
var _LinkDescription = _interopRequireDefault(require("./elements/LinkDescription.cjs"));
|
|
9
8
|
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
@@ -12,21 +11,11 @@ exports.isMediaElement = _apidomNsJsonSchemaDraft.isMediaElement;
|
|
|
12
11
|
/**
|
|
13
12
|
* @public
|
|
14
13
|
*/
|
|
15
|
-
const isJSONSchemaElement =
|
|
16
|
-
hasBasicElementProps,
|
|
17
|
-
isElementType,
|
|
18
|
-
primitiveEq
|
|
19
|
-
}) => {
|
|
20
|
-
return element => element instanceof _JSONSchema.default || hasBasicElementProps(element) && isElementType('JSONSchemaDraft6', element) && primitiveEq('object', element);
|
|
21
|
-
});
|
|
14
|
+
const isJSONSchemaElement = element => element instanceof _JSONSchema.default;
|
|
22
15
|
|
|
23
16
|
/**
|
|
24
17
|
* @public
|
|
25
18
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
primitiveEq
|
|
30
|
-
}) => {
|
|
31
|
-
return element => element instanceof _LinkDescription.default || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
|
|
32
|
-
});
|
|
19
|
+
exports.isJSONSchemaElement = isJSONSchemaElement;
|
|
20
|
+
const isLinkDescriptionElement = element => element instanceof _LinkDescription.default;
|
|
21
|
+
exports.isLinkDescriptionElement = isLinkDescriptionElement;
|
package/src/predicates.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createPredicate } from '@speclynx/apidom-core';
|
|
2
1
|
import JSONSchemaElement from "./elements/JSONSchema.mjs";
|
|
3
2
|
import LinkDescriptionElement from "./elements/LinkDescription.mjs";
|
|
4
3
|
export { isJSONReferenceElement, isMediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
@@ -6,21 +5,9 @@ export { isJSONReferenceElement, isMediaElement } from '@speclynx/apidom-ns-json
|
|
|
6
5
|
/**
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
9
|
-
export const isJSONSchemaElement =
|
|
10
|
-
hasBasicElementProps,
|
|
11
|
-
isElementType,
|
|
12
|
-
primitiveEq
|
|
13
|
-
}) => {
|
|
14
|
-
return element => element instanceof JSONSchemaElement || hasBasicElementProps(element) && isElementType('JSONSchemaDraft6', element) && primitiveEq('object', element);
|
|
15
|
-
});
|
|
8
|
+
export const isJSONSchemaElement = element => element instanceof JSONSchemaElement;
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* @public
|
|
19
12
|
*/
|
|
20
|
-
export const isLinkDescriptionElement =
|
|
21
|
-
hasBasicElementProps,
|
|
22
|
-
isElementType,
|
|
23
|
-
primitiveEq
|
|
24
|
-
}) => {
|
|
25
|
-
return element => element instanceof LinkDescriptionElement || hasBasicElementProps(element) && isElementType('linkDescription', element) && primitiveEq('object', element);
|
|
26
|
-
});
|
|
13
|
+
export const isLinkDescriptionElement = element => element instanceof LinkDescriptionElement;
|
package/src/refractor/index.cjs
CHANGED
|
@@ -2,52 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
|
-
exports.
|
|
6
|
-
var _ramda = require("ramda");
|
|
5
|
+
exports.refractLinkDescription = exports.refractJSONSchema = exports.default = void 0;
|
|
7
6
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
7
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
8
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
9
|
+
var _ramda = require("ramda");
|
|
8
10
|
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
9
|
-
var _visitor = require("../traversal/visitor.cjs");
|
|
10
11
|
var _toolbox = _interopRequireDefault(require("./toolbox.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* @public
|
|
13
22
|
*/
|
|
14
23
|
const refract = (value, {
|
|
15
|
-
|
|
24
|
+
element = 'jSONSchemaDraft6',
|
|
16
25
|
plugins = [],
|
|
17
26
|
specificationObj = _specification.default
|
|
18
27
|
} = {}) => {
|
|
19
|
-
const
|
|
20
|
-
const resolvedSpec = (0, _apidomCore.
|
|
28
|
+
const genericElement = (0, _apidomDatamodel.refract)(value);
|
|
29
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(specificationObj);
|
|
30
|
+
const elementMap = resolvedSpec.elementMap;
|
|
31
|
+
const specPath = elementMap[element];
|
|
32
|
+
if (!specPath) {
|
|
33
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
34
|
+
}
|
|
21
35
|
|
|
22
36
|
/**
|
|
23
37
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
24
38
|
* We don't allow consumers to hook into this translation.
|
|
25
|
-
* Though we allow consumers to define their
|
|
39
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
26
40
|
*/
|
|
27
41
|
const RootVisitorClass = (0, _ramda.path)(specPath, resolvedSpec);
|
|
28
42
|
const rootVisitor = new RootVisitorClass({
|
|
29
43
|
specObj: resolvedSpec
|
|
30
44
|
});
|
|
31
|
-
(0,
|
|
45
|
+
(0, _apidomTraverse.traverse)(genericElement, rootVisitor);
|
|
32
46
|
|
|
33
47
|
/**
|
|
34
48
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
35
49
|
*/
|
|
36
50
|
return (0, _apidomCore.dispatchRefractorPlugins)(rootVisitor.element, plugins, {
|
|
37
|
-
toolboxCreator: _toolbox.default
|
|
38
|
-
visitorOptions: {
|
|
39
|
-
keyMap: _visitor.keyMap,
|
|
40
|
-
nodeTypeGetter: _visitor.getNodeType
|
|
41
|
-
}
|
|
51
|
+
toolboxCreator: _toolbox.default
|
|
42
52
|
});
|
|
43
53
|
};
|
|
44
54
|
|
|
45
55
|
/**
|
|
56
|
+
* Refracts a value into a JSONSchemaElement.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
60
|
+
...options,
|
|
61
|
+
element: 'jSONSchemaDraft6'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
46
66
|
* @public
|
|
47
67
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...options
|
|
68
|
+
exports.refractJSONSchema = refractJSONSchema;
|
|
69
|
+
const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
70
|
+
...options,
|
|
71
|
+
element: 'linkDescription'
|
|
51
72
|
});
|
|
52
|
-
exports.
|
|
73
|
+
exports.refractLinkDescription = refractLinkDescription;
|
|
53
74
|
var _default = exports.default = refract;
|
package/src/refractor/index.mjs
CHANGED
|
@@ -1,47 +1,65 @@
|
|
|
1
|
+
import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
2
|
+
import { traverse } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { refract as baseRefract } from '@speclynx/apidom-datamodel';
|
|
1
4
|
import { path } from 'ramda';
|
|
2
|
-
import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@speclynx/apidom-core';
|
|
3
5
|
import specification from "./specification.mjs";
|
|
4
|
-
import { keyMap, getNodeType } from "../traversal/visitor.mjs";
|
|
5
6
|
import createToolbox from "./toolbox.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
6
13
|
/**
|
|
7
14
|
* @public
|
|
8
15
|
*/
|
|
9
16
|
const refract = (value, {
|
|
10
|
-
|
|
17
|
+
element = 'jSONSchemaDraft6',
|
|
11
18
|
plugins = [],
|
|
12
19
|
specificationObj = specification
|
|
13
20
|
} = {}) => {
|
|
14
|
-
const
|
|
15
|
-
const resolvedSpec =
|
|
21
|
+
const genericElement = baseRefract(value);
|
|
22
|
+
const resolvedSpec = resolveSpecification(specificationObj);
|
|
23
|
+
const elementMap = resolvedSpec.elementMap;
|
|
24
|
+
const specPath = elementMap[element];
|
|
25
|
+
if (!specPath) {
|
|
26
|
+
throw new Error(`Unknown element type: "${element}"`);
|
|
27
|
+
}
|
|
16
28
|
|
|
17
29
|
/**
|
|
18
30
|
* This is where generic ApiDOM becomes semantic (namespace applied).
|
|
19
31
|
* We don't allow consumers to hook into this translation.
|
|
20
|
-
* Though we allow consumers to define their
|
|
32
|
+
* Though we allow consumers to define their own plugins on already transformed ApiDOM.
|
|
21
33
|
*/
|
|
22
34
|
const RootVisitorClass = path(specPath, resolvedSpec);
|
|
23
35
|
const rootVisitor = new RootVisitorClass({
|
|
24
36
|
specObj: resolvedSpec
|
|
25
37
|
});
|
|
26
|
-
|
|
38
|
+
traverse(genericElement, rootVisitor);
|
|
27
39
|
|
|
28
40
|
/**
|
|
29
41
|
* Running plugins visitors means extra single traversal === performance hit.
|
|
30
42
|
*/
|
|
31
43
|
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
|
|
32
|
-
toolboxCreator: createToolbox
|
|
33
|
-
visitorOptions: {
|
|
34
|
-
keyMap,
|
|
35
|
-
nodeTypeGetter: getNodeType
|
|
36
|
-
}
|
|
44
|
+
toolboxCreator: createToolbox
|
|
37
45
|
});
|
|
38
46
|
};
|
|
39
47
|
|
|
40
48
|
/**
|
|
49
|
+
* Refracts a value into a JSONSchemaElement.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export const refractJSONSchema = (value, options = {}) => refract(value, {
|
|
53
|
+
...options,
|
|
54
|
+
element: 'jSONSchemaDraft6'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Refracts a value into a LinkDescriptionElement.
|
|
41
59
|
* @public
|
|
42
60
|
*/
|
|
43
|
-
export const
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
export const refractLinkDescription = (value, options = {}) => refract(value, {
|
|
62
|
+
...options,
|
|
63
|
+
element: 'linkDescription'
|
|
46
64
|
});
|
|
47
65
|
export default refract;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
6
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
+
var _apidomNsJsonSchemaDraft = require("@speclynx/apidom-ns-json-schema-draft-4");
|
|
8
|
+
exports.JSONReferenceElement = _apidomNsJsonSchemaDraft.JSONReferenceElement;
|
|
9
|
+
exports.MediaElement = _apidomNsJsonSchemaDraft.MediaElement;
|
|
10
|
+
var _JSONSchema = _interopRequireDefault(require("../elements/JSONSchema.cjs"));
|
|
11
|
+
exports.JSONSchemaElement = _JSONSchema.default;
|
|
12
|
+
var _LinkDescription = _interopRequireDefault(require("../elements/LinkDescription.cjs"));
|
|
13
|
+
exports.LinkDescriptionElement = _LinkDescription.default;
|
|
14
|
+
var _specification = _interopRequireDefault(require("./specification.cjs"));
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Resolve specification to dereference $ref pointers
|
|
20
|
+
const resolvedSpec = (0, _apidomCore.resolveSpecification)(_specification.default);
|
|
21
|
+
|
|
22
|
+
// Extract fixed fields as list of { name, alias?, $visitor }
|
|
23
|
+
const getFixedFields = fixedFieldsSpec => {
|
|
24
|
+
return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
|
|
25
|
+
if ((0, _ramdaAdjunct.isPlainObject)(fieldSpec)) {
|
|
26
|
+
return {
|
|
27
|
+
name,
|
|
28
|
+
...fieldSpec
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
name,
|
|
33
|
+
$visitor: fieldSpec
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Define lazy getters for fixedFields on element classes
|
|
39
|
+
// Note: JSONReferenceElement and MediaElement inherit fixedFields from draft-4
|
|
40
|
+
Object.defineProperty(_JSONSchema.default, 'fixedFields', {
|
|
41
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
|
|
42
|
+
enumerable: true
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(_LinkDescription.default, 'fixedFields', {
|
|
45
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
|
|
46
|
+
enumerable: true
|
|
47
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolveSpecification } from '@speclynx/apidom-core';
|
|
2
|
+
import { isPlainObject } from 'ramda-adjunct';
|
|
3
|
+
import { JSONReferenceElement, MediaElement } from '@speclynx/apidom-ns-json-schema-draft-4';
|
|
4
|
+
import JSONSchemaElement from "../elements/JSONSchema.mjs";
|
|
5
|
+
import LinkDescriptionElement from "../elements/LinkDescription.mjs";
|
|
6
|
+
import specification from "./specification.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
// Resolve specification to dereference $ref pointers
|
|
11
|
+
const resolvedSpec = resolveSpecification(specification);
|
|
12
|
+
|
|
13
|
+
// Extract fixed fields as list of { name, alias?, $visitor }
|
|
14
|
+
const getFixedFields = fixedFieldsSpec => {
|
|
15
|
+
return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
|
|
16
|
+
if (isPlainObject(fieldSpec)) {
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
...fieldSpec
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
$visitor: fieldSpec
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Define lazy getters for fixedFields on element classes
|
|
30
|
+
// Note: JSONReferenceElement and MediaElement inherit fixedFields from draft-4
|
|
31
|
+
Object.defineProperty(JSONSchemaElement, 'fixedFields', {
|
|
32
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.JSONSchema.fixedFields),
|
|
33
|
+
enumerable: true
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(LinkDescriptionElement, 'fixedFields', {
|
|
36
|
+
get: () => getFixedFields(resolvedSpec.visitors.document.objects.LinkDescription.fixedFields),
|
|
37
|
+
enumerable: true
|
|
38
|
+
});
|
|
39
|
+
export { JSONSchemaElement, JSONReferenceElement, MediaElement, LinkDescriptionElement };
|