@speclynx/apidom-reference 4.0.2 → 4.0.4
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 +12 -0
- package/dist/apidom-reference.browser.js +15 -15
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +25 -25
- package/src/File.cjs +50 -0
- package/src/File.mjs +44 -0
- package/src/Reference.cjs +31 -0
- package/src/Reference.mjs +27 -0
- package/src/ReferenceSet.cjs +60 -0
- package/src/ReferenceSet.mjs +57 -0
- package/src/bundle/index.cjs +61 -0
- package/src/bundle/index.mjs +55 -0
- package/src/bundle/strategies/BundleStrategy.cjs +20 -0
- package/src/bundle/strategies/BundleStrategy.mjs +16 -0
- package/src/bundle/strategies/openapi-3-1/index.cjs +35 -0
- package/src/bundle/strategies/openapi-3-1/index.mjs +29 -0
- package/src/configuration/empty.cjs +9 -0
- package/src/configuration/empty.mjs +1 -0
- package/src/configuration/saturated.cjs +88 -0
- package/src/configuration/saturated.mjs +80 -0
- package/src/dereference/index.cjs +90 -0
- package/src/dereference/index.mjs +83 -0
- package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
- package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
- package/src/dereference/strategies/apidom/index.cjs +89 -0
- package/src/dereference/strategies/apidom/index.mjs +83 -0
- package/src/dereference/strategies/apidom/selectors/element-id.cjs +47 -0
- package/src/dereference/strategies/apidom/selectors/element-id.mjs +41 -0
- package/src/dereference/strategies/apidom/visitor.cjs +266 -0
- package/src/dereference/strategies/apidom/visitor.mjs +259 -0
- package/src/dereference/strategies/arazzo-1/index.cjs +109 -0
- package/src/dereference/strategies/arazzo-1/index.mjs +100 -0
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.cjs +12 -0
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.mjs +1 -0
- package/src/dereference/strategies/arazzo-1/selectors/uri.cjs +8 -0
- package/src/dereference/strategies/arazzo-1/selectors/uri.mjs +1 -0
- package/src/dereference/strategies/arazzo-1/source-descriptions.cjs +248 -0
- package/src/dereference/strategies/arazzo-1/source-descriptions.mjs +243 -0
- package/src/dereference/strategies/arazzo-1/util.cjs +37 -0
- package/src/dereference/strategies/arazzo-1/util.mjs +29 -0
- package/src/dereference/strategies/arazzo-1/visitor.cjs +507 -0
- package/src/dereference/strategies/arazzo-1/visitor.mjs +500 -0
- package/src/dereference/strategies/asyncapi-2/index.cjs +94 -0
- package/src/dereference/strategies/asyncapi-2/index.mjs +88 -0
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +501 -0
- package/src/dereference/strategies/asyncapi-2/visitor.mjs +494 -0
- package/src/dereference/strategies/openapi-2/index.cjs +96 -0
- package/src/dereference/strategies/openapi-2/index.mjs +90 -0
- package/src/dereference/strategies/openapi-2/visitor.cjs +629 -0
- package/src/dereference/strategies/openapi-2/visitor.mjs +622 -0
- package/src/dereference/strategies/openapi-3-0/index.cjs +96 -0
- package/src/dereference/strategies/openapi-3-0/index.mjs +90 -0
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +622 -0
- package/src/dereference/strategies/openapi-3-0/visitor.mjs +615 -0
- package/src/dereference/strategies/openapi-3-1/index.cjs +99 -0
- package/src/dereference/strategies/openapi-3-1/index.mjs +90 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +65 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +54 -0
- package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +50 -0
- package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +42 -0
- package/src/dereference/strategies/openapi-3-1/util.cjs +68 -0
- package/src/dereference/strategies/openapi-3-1/util.mjs +59 -0
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +874 -0
- package/src/dereference/strategies/openapi-3-1/visitor.mjs +867 -0
- package/src/dereference/util.cjs +31 -0
- package/src/dereference/util.mjs +27 -0
- package/src/errors/BundleError.cjs +10 -0
- package/src/errors/BundleError.mjs +7 -0
- package/src/errors/DereferenceError.cjs +10 -0
- package/src/errors/DereferenceError.mjs +7 -0
- package/src/errors/EvaluationElementIdError.cjs +10 -0
- package/src/errors/EvaluationElementIdError.mjs +7 -0
- package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
- package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
- package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
- package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
- package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
- package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
- package/src/errors/JsonSchema$anchorError.cjs +10 -0
- package/src/errors/JsonSchema$anchorError.mjs +7 -0
- package/src/errors/JsonSchemaUriError.cjs +10 -0
- package/src/errors/JsonSchemaUriError.mjs +7 -0
- package/src/errors/MaximumBundleDepthError.cjs +11 -0
- package/src/errors/MaximumBundleDepthError.mjs +6 -0
- package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
- package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
- package/src/errors/MaximumResolveDepthError.cjs +11 -0
- package/src/errors/MaximumResolveDepthError.mjs +6 -0
- package/src/errors/ParseError.cjs +10 -0
- package/src/errors/ParseError.mjs +7 -0
- package/src/errors/ParserError.cjs +11 -0
- package/src/errors/ParserError.mjs +6 -0
- package/src/errors/PluginError.cjs +18 -0
- package/src/errors/PluginError.mjs +15 -0
- package/src/errors/ResolveError.cjs +10 -0
- package/src/errors/ResolveError.mjs +7 -0
- package/src/errors/ResolverError.cjs +11 -0
- package/src/errors/ResolverError.mjs +6 -0
- package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
- package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
- package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
- package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
- package/src/errors/UnmatchedParserError.cjs +11 -0
- package/src/errors/UnmatchedParserError.mjs +6 -0
- package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
- package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
- package/src/errors/UnmatchedResolverError.cjs +11 -0
- package/src/errors/UnmatchedResolverError.mjs +6 -0
- package/src/errors/UnresolvableReferenceError.cjs +11 -0
- package/src/errors/UnresolvableReferenceError.mjs +6 -0
- package/src/index.cjs +146 -0
- package/src/index.mjs +103 -0
- package/src/options/index.cjs +194 -0
- package/src/options/index.mjs +191 -0
- package/src/options/util.cjs +24 -0
- package/src/options/util.mjs +19 -0
- package/src/parse/index.cjs +69 -0
- package/src/parse/index.mjs +63 -0
- package/src/parse/parsers/Parser.cjs +62 -0
- package/src/parse/parsers/Parser.mjs +58 -0
- package/src/parse/parsers/apidom-json/index.cjs +70 -0
- package/src/parse/parsers/apidom-json/index.mjs +64 -0
- package/src/parse/parsers/arazzo-json-1/index.cjs +62 -0
- package/src/parse/parsers/arazzo-json-1/index.mjs +56 -0
- package/src/parse/parsers/arazzo-json-1/source-descriptions.cjs +221 -0
- package/src/parse/parsers/arazzo-json-1/source-descriptions.mjs +214 -0
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +62 -0
- package/src/parse/parsers/arazzo-yaml-1/index.mjs +56 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.cjs +12 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.mjs +7 -0
- package/src/parse/parsers/asyncapi-json-2/index.cjs +54 -0
- package/src/parse/parsers/asyncapi-json-2/index.mjs +48 -0
- package/src/parse/parsers/asyncapi-yaml-2/index.cjs +54 -0
- package/src/parse/parsers/asyncapi-yaml-2/index.mjs +48 -0
- package/src/parse/parsers/binary/index-browser.cjs +56 -0
- package/src/parse/parsers/binary/index-browser.mjs +50 -0
- package/src/parse/parsers/binary/index-node.cjs +51 -0
- package/src/parse/parsers/binary/index-node.mjs +45 -0
- package/src/parse/parsers/json/index.cjs +53 -0
- package/src/parse/parsers/json/index.mjs +47 -0
- package/src/parse/parsers/openapi-json-2/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-2/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-3-0/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-3-0/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-3-1/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-3-1/index.mjs +48 -0
- package/src/parse/parsers/openapi-yaml-2/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-2/index.mjs +48 -0
- package/src/parse/parsers/openapi-yaml-3-0/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-3-0/index.mjs +48 -0
- package/src/parse/parsers/openapi-yaml-3-1/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-3-1/index.mjs +48 -0
- package/src/parse/parsers/yaml-1-2/index.cjs +56 -0
- package/src/parse/parsers/yaml-1-2/index.mjs +50 -0
- package/src/resolve/index.cjs +67 -0
- package/src/resolve/index.mjs +60 -0
- package/src/resolve/resolvers/HTTPResolver.cjs +45 -0
- package/src/resolve/resolvers/HTTPResolver.mjs +37 -0
- package/src/resolve/resolvers/Resolver.cjs +20 -0
- package/src/resolve/resolvers/Resolver.mjs +16 -0
- package/src/resolve/resolvers/file/index-browser.cjs +24 -0
- package/src/resolve/resolvers/file/index-browser.mjs +19 -0
- package/src/resolve/resolvers/file/index-node.cjs +49 -0
- package/src/resolve/resolvers/file/index-node.mjs +42 -0
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.cjs +41 -0
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.mjs +37 -0
- package/src/resolve/resolvers/http-axios/index.cjs +113 -0
- package/src/resolve/resolvers/http-axios/index.mjs +105 -0
- package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
- package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
- package/src/resolve/strategies/apidom/index.cjs +49 -0
- package/src/resolve/strategies/apidom/index.mjs +43 -0
- package/src/resolve/strategies/asyncapi-2/index.cjs +49 -0
- package/src/resolve/strategies/asyncapi-2/index.mjs +43 -0
- package/src/resolve/strategies/openapi-2/index.cjs +49 -0
- package/src/resolve/strategies/openapi-2/index.mjs +43 -0
- package/src/resolve/strategies/openapi-3-0/index.cjs +49 -0
- package/src/resolve/strategies/openapi-3-0/index.mjs +43 -0
- package/src/resolve/strategies/openapi-3-1/index.cjs +49 -0
- package/src/resolve/strategies/openapi-3-1/index.mjs +43 -0
- package/src/resolve/util.cjs +37 -0
- package/src/resolve/util.mjs +30 -0
- package/src/util/plugins.cjs +39 -0
- package/src/util/plugins.mjs +34 -0
- package/src/util/url.cjs +288 -0
- package/src/util/url.mjs +274 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class Resolver {
|
|
13
|
+
name;
|
|
14
|
+
constructor({
|
|
15
|
+
name
|
|
16
|
+
}) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var _default = exports.default = Resolver;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 _Resolver = _interopRequireDefault(require("../Resolver.cjs"));
|
|
7
|
+
var _ResolverError = _interopRequireDefault(require("../../../errors/ResolverError.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class FileResolver extends _Resolver.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super({
|
|
14
|
+
name: 'file'
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
canRead() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
read() {
|
|
21
|
+
throw new _ResolverError.default('FileResolver is not intended to be used in browser context');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var _default = exports.default = FileResolver;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Resolver from "../Resolver.mjs";
|
|
2
|
+
import ResolverError from "../../../errors/ResolverError.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
class FileResolver extends Resolver {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({
|
|
9
|
+
name: 'file'
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
canRead() {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
read() {
|
|
16
|
+
throw new ResolverError('FileResolver is not intended to be used in browser context');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export default FileResolver;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _nodeFs = require("node:fs");
|
|
8
|
+
var _nodeUtil = require("node:util");
|
|
9
|
+
var _picomatch = _interopRequireDefault(require("picomatch"));
|
|
10
|
+
var _Resolver = _interopRequireDefault(require("../Resolver.cjs"));
|
|
11
|
+
var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
|
12
|
+
var _ResolverError = _interopRequireDefault(require("../../../errors/ResolverError.cjs"));
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
class FileResolver extends _Resolver.default {
|
|
21
|
+
fileAllowList;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
const {
|
|
24
|
+
fileAllowList = []
|
|
25
|
+
} = options ?? {};
|
|
26
|
+
super({
|
|
27
|
+
name: 'file'
|
|
28
|
+
});
|
|
29
|
+
this.fileAllowList = fileAllowList;
|
|
30
|
+
}
|
|
31
|
+
canRead(file) {
|
|
32
|
+
return url.isFileSystemPath(file.uri) && this.fileAllowList.some(pattern => {
|
|
33
|
+
return typeof pattern === 'string' ? _picomatch.default.isMatch(file.uri, pattern, {
|
|
34
|
+
matchBase: true
|
|
35
|
+
}) : pattern.test(file.uri);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async read(file) {
|
|
39
|
+
const fileSystemPath = url.toFileSystemPath(file.uri);
|
|
40
|
+
try {
|
|
41
|
+
return await (0, _nodeUtil.promisify)(_nodeFs.readFile)(fileSystemPath);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new _ResolverError.default(`Error opening file "${file.uri}"`, {
|
|
44
|
+
cause: error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var _default = exports.default = FileResolver;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from 'node:fs';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import picomatch from 'picomatch';
|
|
4
|
+
import Resolver from "../Resolver.mjs";
|
|
5
|
+
import * as url from "../../../util/url.mjs";
|
|
6
|
+
import ResolverError from "../../../errors/ResolverError.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
class FileResolver extends Resolver {
|
|
14
|
+
fileAllowList;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
const {
|
|
17
|
+
fileAllowList = []
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
name: 'file'
|
|
21
|
+
});
|
|
22
|
+
this.fileAllowList = fileAllowList;
|
|
23
|
+
}
|
|
24
|
+
canRead(file) {
|
|
25
|
+
return url.isFileSystemPath(file.uri) && this.fileAllowList.some(pattern => {
|
|
26
|
+
return typeof pattern === 'string' ? picomatch.isMatch(file.uri, pattern, {
|
|
27
|
+
matchBase: true
|
|
28
|
+
}) : pattern.test(file.uri);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async read(file) {
|
|
32
|
+
const fileSystemPath = url.toFileSystemPath(file.uri);
|
|
33
|
+
try {
|
|
34
|
+
return await promisify(readFile)(fileSystemPath);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new ResolverError(`Error opening file "${file.uri}"`, {
|
|
37
|
+
cause: error
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default FileResolver;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
class MemoryCache {
|
|
6
|
+
maxEntries;
|
|
7
|
+
maxStaleAge;
|
|
8
|
+
store = new Map();
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
const {
|
|
11
|
+
maxEntries = 1024,
|
|
12
|
+
maxStaleAge = 3_600_000
|
|
13
|
+
} = options;
|
|
14
|
+
this.maxEntries = maxEntries;
|
|
15
|
+
this.maxStaleAge = maxStaleAge;
|
|
16
|
+
}
|
|
17
|
+
get(key) {
|
|
18
|
+
const entry = this.store.get(key);
|
|
19
|
+
if (entry === undefined) return undefined;
|
|
20
|
+
|
|
21
|
+
// evict if entry has exceeded maxStaleAge
|
|
22
|
+
if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
|
|
23
|
+
this.store.delete(key);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return entry.value;
|
|
27
|
+
}
|
|
28
|
+
set(key, value) {
|
|
29
|
+
this.store.set(key, {
|
|
30
|
+
value,
|
|
31
|
+
createdAt: Date.now()
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// evict oldest entries if maxEntries exceeded
|
|
35
|
+
if (this.maxEntries !== false && this.store.size > this.maxEntries) {
|
|
36
|
+
const firstKey = this.store.keys().next().value;
|
|
37
|
+
this.store.delete(firstKey);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var _default = exports.default = MemoryCache;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class MemoryCache {
|
|
2
|
+
maxEntries;
|
|
3
|
+
maxStaleAge;
|
|
4
|
+
store = new Map();
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
const {
|
|
7
|
+
maxEntries = 1024,
|
|
8
|
+
maxStaleAge = 3_600_000
|
|
9
|
+
} = options;
|
|
10
|
+
this.maxEntries = maxEntries;
|
|
11
|
+
this.maxStaleAge = maxStaleAge;
|
|
12
|
+
}
|
|
13
|
+
get(key) {
|
|
14
|
+
const entry = this.store.get(key);
|
|
15
|
+
if (entry === undefined) return undefined;
|
|
16
|
+
|
|
17
|
+
// evict if entry has exceeded maxStaleAge
|
|
18
|
+
if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
|
|
19
|
+
this.store.delete(key);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return entry.value;
|
|
23
|
+
}
|
|
24
|
+
set(key, value) {
|
|
25
|
+
this.store.set(key, {
|
|
26
|
+
value,
|
|
27
|
+
createdAt: Date.now()
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// evict oldest entries if maxEntries exceeded
|
|
31
|
+
if (this.maxEntries !== false && this.store.size > this.maxEntries) {
|
|
32
|
+
const firstKey = this.store.keys().next().value;
|
|
33
|
+
this.store.delete(firstKey);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default MemoryCache;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
9
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
10
|
+
var _HTTPResolver = _interopRequireDefault(require("../HTTPResolver.cjs"));
|
|
11
|
+
var _MemoryCache = _interopRequireDefault(require("./cache/MemoryCache.cjs"));
|
|
12
|
+
var _ResolverError = _interopRequireDefault(require("../../../errors/ResolverError.cjs"));
|
|
13
|
+
var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class HTTPResolverAxios extends _HTTPResolver.default {
|
|
26
|
+
axiosConfig = {};
|
|
27
|
+
axiosInstance;
|
|
28
|
+
previousAxiosConfig;
|
|
29
|
+
cacheStore;
|
|
30
|
+
previousCache;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
const {
|
|
33
|
+
axiosConfig = {},
|
|
34
|
+
...rest
|
|
35
|
+
} = options ?? {};
|
|
36
|
+
super({
|
|
37
|
+
...rest,
|
|
38
|
+
name: 'http-axios'
|
|
39
|
+
});
|
|
40
|
+
this.axiosConfig = axiosConfig;
|
|
41
|
+
this.cacheStore = new _MemoryCache.default((0, _ramdaAdjunct.isPlainObject)(this.cache) ? this.cache : {});
|
|
42
|
+
}
|
|
43
|
+
getHttpClient() {
|
|
44
|
+
if (this.axiosInstance === undefined || this.previousAxiosConfig !== this.axiosConfig) {
|
|
45
|
+
const config = (0, _ramda.omit)(['interceptors'], this.axiosConfig);
|
|
46
|
+
const {
|
|
47
|
+
interceptors
|
|
48
|
+
} = this.axiosConfig;
|
|
49
|
+
this.axiosInstance = _axios.default.create({
|
|
50
|
+
timeout: this.timeout,
|
|
51
|
+
maxRedirects: this.redirects,
|
|
52
|
+
withCredentials: this.withCredentials,
|
|
53
|
+
responseType: 'arraybuffer',
|
|
54
|
+
...config
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// settings up request interceptors
|
|
58
|
+
if (Array.isArray(interceptors?.request)) {
|
|
59
|
+
interceptors.request.forEach(requestInterceptor => {
|
|
60
|
+
this.axiosInstance.interceptors.request.use(...(0, _ramdaAdjunct.ensureArray)(requestInterceptor));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// settings up response interceptors
|
|
65
|
+
if (Array.isArray(interceptors?.response)) {
|
|
66
|
+
interceptors.response.forEach(responseInterceptor => {
|
|
67
|
+
this.axiosInstance.interceptors.response.use(...(0, _ramdaAdjunct.ensureArray)(responseInterceptor));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
this.previousAxiosConfig = this.axiosConfig;
|
|
71
|
+
}
|
|
72
|
+
return this.axiosInstance;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Ensures cacheStore is config-isolated for cloned resolvers.
|
|
77
|
+
* When a resolver is cloned via Object.create (in readFile), the clone inherits
|
|
78
|
+
* cacheStore from the prototype. Object.create(cacheStore) creates a view that
|
|
79
|
+
* shares the underlying store Map but allows isolated config (maxEntries, maxStaleAge)
|
|
80
|
+
* via own properties set by Object.assign.
|
|
81
|
+
*/
|
|
82
|
+
getCacheStore() {
|
|
83
|
+
if (this.previousCache !== this.cache) {
|
|
84
|
+
if (!Object.hasOwn(this, 'cacheStore')) {
|
|
85
|
+
this.cacheStore = Object.create(this.cacheStore);
|
|
86
|
+
}
|
|
87
|
+
if ((0, _ramdaAdjunct.isPlainObject)(this.cache)) {
|
|
88
|
+
Object.assign(this.cacheStore, this.cache);
|
|
89
|
+
}
|
|
90
|
+
this.previousCache = this.cache;
|
|
91
|
+
}
|
|
92
|
+
return this.cacheStore;
|
|
93
|
+
}
|
|
94
|
+
async read(file) {
|
|
95
|
+
const uri = url.stripHash(file.uri);
|
|
96
|
+
const cacheStore = this.cache ? this.getCacheStore() : undefined;
|
|
97
|
+
|
|
98
|
+
// return cached content if available
|
|
99
|
+
const cached = cacheStore?.get(uri);
|
|
100
|
+
if (cached !== undefined) return cached;
|
|
101
|
+
const client = this.getHttpClient();
|
|
102
|
+
try {
|
|
103
|
+
const response = await client.get(uri);
|
|
104
|
+
cacheStore?.set(uri, response.data);
|
|
105
|
+
return response.data;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw new _ResolverError.default(`Error downloading "${file.uri}"`, {
|
|
108
|
+
cause: error
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var _default = exports.default = HTTPResolverAxios;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { omit } from 'ramda';
|
|
2
|
+
import { ensureArray, isPlainObject } from 'ramda-adjunct';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import HTTPResolver from "../HTTPResolver.mjs";
|
|
5
|
+
import MemoryCache from "./cache/MemoryCache.mjs";
|
|
6
|
+
import ResolverError from "../../../errors/ResolverError.mjs";
|
|
7
|
+
import * as url from "../../../util/url.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class HTTPResolverAxios extends HTTPResolver {
|
|
18
|
+
axiosConfig = {};
|
|
19
|
+
axiosInstance;
|
|
20
|
+
previousAxiosConfig;
|
|
21
|
+
cacheStore;
|
|
22
|
+
previousCache;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
const {
|
|
25
|
+
axiosConfig = {},
|
|
26
|
+
...rest
|
|
27
|
+
} = options ?? {};
|
|
28
|
+
super({
|
|
29
|
+
...rest,
|
|
30
|
+
name: 'http-axios'
|
|
31
|
+
});
|
|
32
|
+
this.axiosConfig = axiosConfig;
|
|
33
|
+
this.cacheStore = new MemoryCache(isPlainObject(this.cache) ? this.cache : {});
|
|
34
|
+
}
|
|
35
|
+
getHttpClient() {
|
|
36
|
+
if (this.axiosInstance === undefined || this.previousAxiosConfig !== this.axiosConfig) {
|
|
37
|
+
const config = omit(['interceptors'], this.axiosConfig);
|
|
38
|
+
const {
|
|
39
|
+
interceptors
|
|
40
|
+
} = this.axiosConfig;
|
|
41
|
+
this.axiosInstance = axios.create({
|
|
42
|
+
timeout: this.timeout,
|
|
43
|
+
maxRedirects: this.redirects,
|
|
44
|
+
withCredentials: this.withCredentials,
|
|
45
|
+
responseType: 'arraybuffer',
|
|
46
|
+
...config
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// settings up request interceptors
|
|
50
|
+
if (Array.isArray(interceptors?.request)) {
|
|
51
|
+
interceptors.request.forEach(requestInterceptor => {
|
|
52
|
+
this.axiosInstance.interceptors.request.use(...ensureArray(requestInterceptor));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// settings up response interceptors
|
|
57
|
+
if (Array.isArray(interceptors?.response)) {
|
|
58
|
+
interceptors.response.forEach(responseInterceptor => {
|
|
59
|
+
this.axiosInstance.interceptors.response.use(...ensureArray(responseInterceptor));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
this.previousAxiosConfig = this.axiosConfig;
|
|
63
|
+
}
|
|
64
|
+
return this.axiosInstance;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Ensures cacheStore is config-isolated for cloned resolvers.
|
|
69
|
+
* When a resolver is cloned via Object.create (in readFile), the clone inherits
|
|
70
|
+
* cacheStore from the prototype. Object.create(cacheStore) creates a view that
|
|
71
|
+
* shares the underlying store Map but allows isolated config (maxEntries, maxStaleAge)
|
|
72
|
+
* via own properties set by Object.assign.
|
|
73
|
+
*/
|
|
74
|
+
getCacheStore() {
|
|
75
|
+
if (this.previousCache !== this.cache) {
|
|
76
|
+
if (!Object.hasOwn(this, 'cacheStore')) {
|
|
77
|
+
this.cacheStore = Object.create(this.cacheStore);
|
|
78
|
+
}
|
|
79
|
+
if (isPlainObject(this.cache)) {
|
|
80
|
+
Object.assign(this.cacheStore, this.cache);
|
|
81
|
+
}
|
|
82
|
+
this.previousCache = this.cache;
|
|
83
|
+
}
|
|
84
|
+
return this.cacheStore;
|
|
85
|
+
}
|
|
86
|
+
async read(file) {
|
|
87
|
+
const uri = url.stripHash(file.uri);
|
|
88
|
+
const cacheStore = this.cache ? this.getCacheStore() : undefined;
|
|
89
|
+
|
|
90
|
+
// return cached content if available
|
|
91
|
+
const cached = cacheStore?.get(uri);
|
|
92
|
+
if (cached !== undefined) return cached;
|
|
93
|
+
const client = this.getHttpClient();
|
|
94
|
+
try {
|
|
95
|
+
const response = await client.get(uri);
|
|
96
|
+
cacheStore?.set(uri, response.data);
|
|
97
|
+
return response.data;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
throw new ResolverError(`Error downloading "${file.uri}"`, {
|
|
100
|
+
cause: error
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export default HTTPResolverAxios;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class ResolveStrategy {
|
|
13
|
+
name;
|
|
14
|
+
constructor({
|
|
15
|
+
name
|
|
16
|
+
}) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var _default = exports.default = ResolveStrategy;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
|
+
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
8
|
+
var _util = require("../../../options/util.cjs");
|
|
9
|
+
var _UnmatchedDereferenceStrategyError = _interopRequireDefault(require("../../../errors/UnmatchedDereferenceStrategyError.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class ApiDOMResolveStrategy extends _ResolveStrategy.default {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super({
|
|
20
|
+
...(options ?? {}),
|
|
21
|
+
name: 'apidom'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
canResolve(file, options) {
|
|
25
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'apidom');
|
|
26
|
+
if (dereferenceStrategy === undefined) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return dereferenceStrategy.canDereference(file, options);
|
|
30
|
+
}
|
|
31
|
+
async resolve(file, options) {
|
|
32
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'apidom');
|
|
33
|
+
if (dereferenceStrategy === undefined) {
|
|
34
|
+
throw new _UnmatchedDereferenceStrategyError.default(`"apidom" resolve strategy requires "apidom" dereference strategy to be configured for file "${file.uri}"`);
|
|
35
|
+
}
|
|
36
|
+
const refSet = new _ReferenceSet.default();
|
|
37
|
+
const mergedOptions = (0, _util.merge)(options, {
|
|
38
|
+
resolve: {
|
|
39
|
+
internal: false
|
|
40
|
+
},
|
|
41
|
+
dereference: {
|
|
42
|
+
refSet
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
await dereferenceStrategy.dereference(file, mergedOptions);
|
|
46
|
+
return refSet;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var _default = exports.default = ApiDOMResolveStrategy;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ResolveStrategy from "../ResolveStrategy.mjs";
|
|
2
|
+
import ReferenceSet from "../../../ReferenceSet.mjs";
|
|
3
|
+
import { merge as mergeOptions } from "../../../options/util.mjs";
|
|
4
|
+
import UnmatchedDereferenceStrategyError from "../../../errors/UnmatchedDereferenceStrategyError.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class ApiDOMResolveStrategy extends ResolveStrategy {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super({
|
|
14
|
+
...(options ?? {}),
|
|
15
|
+
name: 'apidom'
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
canResolve(file, options) {
|
|
19
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'apidom');
|
|
20
|
+
if (dereferenceStrategy === undefined) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return dereferenceStrategy.canDereference(file, options);
|
|
24
|
+
}
|
|
25
|
+
async resolve(file, options) {
|
|
26
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'apidom');
|
|
27
|
+
if (dereferenceStrategy === undefined) {
|
|
28
|
+
throw new UnmatchedDereferenceStrategyError(`"apidom" resolve strategy requires "apidom" dereference strategy to be configured for file "${file.uri}"`);
|
|
29
|
+
}
|
|
30
|
+
const refSet = new ReferenceSet();
|
|
31
|
+
const mergedOptions = mergeOptions(options, {
|
|
32
|
+
resolve: {
|
|
33
|
+
internal: false
|
|
34
|
+
},
|
|
35
|
+
dereference: {
|
|
36
|
+
refSet
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
await dereferenceStrategy.dereference(file, mergedOptions);
|
|
40
|
+
return refSet;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export default ApiDOMResolveStrategy;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
|
+
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
8
|
+
var _util = require("../../../options/util.cjs");
|
|
9
|
+
var _UnmatchedDereferenceStrategyError = _interopRequireDefault(require("../../../errors/UnmatchedDereferenceStrategyError.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class AsyncAPI2ResolveStrategy extends _ResolveStrategy.default {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super({
|
|
20
|
+
...(options ?? {}),
|
|
21
|
+
name: 'asyncapi-2'
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
canResolve(file, options) {
|
|
25
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'asyncapi-2');
|
|
26
|
+
if (dereferenceStrategy === undefined) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return dereferenceStrategy.canDereference(file, options);
|
|
30
|
+
}
|
|
31
|
+
async resolve(file, options) {
|
|
32
|
+
const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'asyncapi-2');
|
|
33
|
+
if (dereferenceStrategy === undefined) {
|
|
34
|
+
throw new _UnmatchedDereferenceStrategyError.default(`"asyncapi-2" resolve strategy requires "asyncapi-2" dereference strategy to be configured for file "${file.uri}"`);
|
|
35
|
+
}
|
|
36
|
+
const refSet = new _ReferenceSet.default();
|
|
37
|
+
const mergedOptions = (0, _util.merge)(options, {
|
|
38
|
+
resolve: {
|
|
39
|
+
internal: false
|
|
40
|
+
},
|
|
41
|
+
dereference: {
|
|
42
|
+
refSet
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
await dereferenceStrategy.dereference(file, mergedOptions);
|
|
46
|
+
return refSet;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var _default = exports.default = AsyncAPI2ResolveStrategy;
|