@speclynx/apidom-reference 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 +26 -27
- package/src/File.cjs +50 -0
- package/src/File.mjs +44 -0
- package/src/File.ts +63 -0
- package/src/Reference.cjs +31 -0
- package/src/Reference.mjs +27 -0
- package/src/Reference.ts +38 -0
- package/src/ReferenceSet.cjs +60 -0
- package/src/ReferenceSet.mjs +57 -0
- package/src/ReferenceSet.ts +73 -0
- package/src/bundle/index.cjs +61 -0
- package/src/bundle/index.mjs +55 -0
- package/src/bundle/index.ts +57 -0
- package/src/bundle/strategies/BundleStrategy.cjs +20 -0
- package/src/bundle/strategies/BundleStrategy.mjs +16 -0
- package/src/bundle/strategies/BundleStrategy.ts +27 -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/bundle/strategies/openapi-3-1/index.ts +57 -0
- package/src/configuration/empty.cjs +9 -0
- package/src/configuration/empty.mjs +1 -0
- package/src/configuration/empty.ts +1 -0
- package/src/configuration/saturated.cjs +88 -0
- package/src/configuration/saturated.mjs +80 -0
- package/src/configuration/saturated.ts +72 -0
- package/src/dereference/index.cjs +90 -0
- package/src/dereference/index.mjs +83 -0
- package/src/dereference/index.ts +96 -0
- package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
- package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
- package/src/dereference/strategies/DereferenceStrategy.ts +27 -0
- package/src/dereference/strategies/apidom/index.cjs +89 -0
- package/src/dereference/strategies/apidom/index.mjs +83 -0
- package/src/dereference/strategies/apidom/index.ts +128 -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/selectors/element-id.ts +48 -0
- package/src/dereference/strategies/apidom/visitor.cjs +266 -0
- package/src/dereference/strategies/apidom/visitor.mjs +259 -0
- package/src/dereference/strategies/apidom/visitor.ts +316 -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/index.ts +158 -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/$anchor.ts +9 -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/selectors/uri.ts +5 -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/source-descriptions.ts +317 -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/util.ts +33 -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/arazzo-1/visitor.ts +574 -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/index.ts +133 -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/asyncapi-2/visitor.ts +589 -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/index.ts +136 -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-2/visitor.ts +745 -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/index.ts +134 -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-0/visitor.ts +760 -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/index.ts +141 -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/$anchor.ts +64 -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/selectors/uri.ts +54 -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/util.ts +83 -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/strategies/openapi-3-1/visitor.ts +1053 -0
- package/src/dereference/util.cjs +31 -0
- package/src/dereference/util.mjs +27 -0
- package/src/dereference/util.ts +29 -0
- package/src/errors/BundleError.cjs +10 -0
- package/src/errors/BundleError.mjs +7 -0
- package/src/errors/BundleError.ts +8 -0
- package/src/errors/DereferenceError.cjs +10 -0
- package/src/errors/DereferenceError.mjs +7 -0
- package/src/errors/DereferenceError.ts +8 -0
- package/src/errors/EvaluationElementIdError.cjs +10 -0
- package/src/errors/EvaluationElementIdError.mjs +7 -0
- package/src/errors/EvaluationElementIdError.ts +8 -0
- package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
- package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
- package/src/errors/EvaluationJsonSchema$anchorError.ts +8 -0
- package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
- package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
- package/src/errors/EvaluationJsonSchemaUriError.ts +8 -0
- package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
- package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
- package/src/errors/InvalidJsonSchema$anchorError.ts +12 -0
- package/src/errors/JsonSchema$anchorError.cjs +10 -0
- package/src/errors/JsonSchema$anchorError.mjs +7 -0
- package/src/errors/JsonSchema$anchorError.ts +8 -0
- package/src/errors/JsonSchemaUriError.cjs +10 -0
- package/src/errors/JsonSchemaUriError.mjs +7 -0
- package/src/errors/JsonSchemaUriError.ts +8 -0
- package/src/errors/MaximumBundleDepthError.cjs +11 -0
- package/src/errors/MaximumBundleDepthError.mjs +6 -0
- package/src/errors/MaximumBundleDepthError.ts +8 -0
- package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
- package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
- package/src/errors/MaximumDereferenceDepthError.ts +8 -0
- package/src/errors/MaximumResolveDepthError.cjs +11 -0
- package/src/errors/MaximumResolveDepthError.mjs +6 -0
- package/src/errors/MaximumResolveDepthError.ts +8 -0
- package/src/errors/ParseError.cjs +10 -0
- package/src/errors/ParseError.mjs +7 -0
- package/src/errors/ParseError.ts +8 -0
- package/src/errors/ParserError.cjs +11 -0
- package/src/errors/ParserError.mjs +6 -0
- package/src/errors/ParserError.ts +8 -0
- package/src/errors/PluginError.cjs +18 -0
- package/src/errors/PluginError.mjs +15 -0
- package/src/errors/PluginError.ts +15 -0
- package/src/errors/ResolveError.cjs +10 -0
- package/src/errors/ResolveError.mjs +7 -0
- package/src/errors/ResolveError.ts +8 -0
- package/src/errors/ResolverError.cjs +11 -0
- package/src/errors/ResolverError.mjs +6 -0
- package/src/errors/ResolverError.ts +8 -0
- package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
- package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
- package/src/errors/UnmatchedBundleStrategyError.ts +8 -0
- package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
- package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
- package/src/errors/UnmatchedDereferenceStrategyError.ts +8 -0
- package/src/errors/UnmatchedParserError.cjs +11 -0
- package/src/errors/UnmatchedParserError.mjs +6 -0
- package/src/errors/UnmatchedParserError.ts +8 -0
- package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
- package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
- package/src/errors/UnmatchedResolveStrategyError.ts +8 -0
- package/src/errors/UnmatchedResolverError.cjs +11 -0
- package/src/errors/UnmatchedResolverError.mjs +6 -0
- package/src/errors/UnmatchedResolverError.ts +8 -0
- package/src/errors/UnresolvableReferenceError.cjs +11 -0
- package/src/errors/UnresolvableReferenceError.mjs +6 -0
- package/src/errors/UnresolvableReferenceError.ts +8 -0
- package/src/index.cjs +146 -0
- package/src/index.mjs +103 -0
- package/src/index.ts +135 -0
- package/src/options/index.cjs +194 -0
- package/src/options/index.mjs +191 -0
- package/src/options/index.ts +239 -0
- package/src/options/util.cjs +24 -0
- package/src/options/util.mjs +19 -0
- package/src/options/util.ts +22 -0
- package/src/parse/index.cjs +69 -0
- package/src/parse/index.mjs +63 -0
- package/src/parse/index.ts +67 -0
- package/src/parse/parsers/Parser.cjs +62 -0
- package/src/parse/parsers/Parser.mjs +58 -0
- package/src/parse/parsers/Parser.ts +80 -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/apidom-json/index.ts +78 -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/index.ts +76 -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-json-1/source-descriptions.ts +280 -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/index.ts +77 -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/arazzo-yaml-1/source-descriptions.ts +16 -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-json-2/index.ts +58 -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/asyncapi-yaml-2/index.ts +58 -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-browser.ts +60 -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/binary/index-node.ts +57 -0
- package/src/parse/parsers/json/index.cjs +53 -0
- package/src/parse/parsers/json/index.mjs +47 -0
- package/src/parse/parsers/json/index.ts +52 -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-2/index.ts +58 -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-0/index.ts +59 -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-json-3-1/index.ts +59 -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-2/index.ts +58 -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-0/index.ts +59 -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/openapi-yaml-3-1/index.ts +59 -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/parse/parsers/yaml-1-2/index.ts +60 -0
- package/src/resolve/index.cjs +67 -0
- package/src/resolve/index.mjs +60 -0
- package/src/resolve/index.ts +75 -0
- package/src/resolve/resolvers/HTTPResolver.cjs +45 -0
- package/src/resolve/resolvers/HTTPResolver.mjs +37 -0
- package/src/resolve/resolvers/HTTPResolver.ts +58 -0
- package/src/resolve/resolvers/Resolver.cjs +20 -0
- package/src/resolve/resolvers/Resolver.mjs +16 -0
- package/src/resolve/resolvers/Resolver.ts +25 -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-browser.ts +24 -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/file/index-node.ts +55 -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/cache/MemoryCache.ts +46 -0
- package/src/resolve/resolvers/http-axios/index.cjs +113 -0
- package/src/resolve/resolvers/http-axios/index.mjs +105 -0
- package/src/resolve/resolvers/http-axios/index.ts +130 -0
- package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
- package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
- package/src/resolve/strategies/ResolveStrategy.ts +26 -0
- package/src/resolve/strategies/apidom/index.cjs +49 -0
- package/src/resolve/strategies/apidom/index.mjs +43 -0
- package/src/resolve/strategies/apidom/index.ts +78 -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/asyncapi-2/index.ts +78 -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-2/index.ts +78 -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-0/index.ts +78 -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/strategies/openapi-3-1/index.ts +78 -0
- package/src/resolve/util.cjs +37 -0
- package/src/resolve/util.mjs +30 -0
- package/src/resolve/util.ts +39 -0
- package/src/util/plugins.cjs +39 -0
- package/src/util/plugins.mjs +34 -0
- package/src/util/plugins.ts +37 -0
- package/src/util/url.cjs +288 -0
- package/src/util/url.mjs +274 -0
- package/src/util/url.ts +285 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { isEmpty } from 'ramda';
|
|
2
|
+
import {
|
|
3
|
+
Element,
|
|
4
|
+
isParseResultElement,
|
|
5
|
+
ParseResultElement,
|
|
6
|
+
cloneShallow,
|
|
7
|
+
} from '@speclynx/apidom-datamodel';
|
|
8
|
+
|
|
9
|
+
import { merge as mergeOptions } from '../options/util.ts';
|
|
10
|
+
import parse from '../parse/index.ts';
|
|
11
|
+
import * as plugins from '../util/plugins.ts';
|
|
12
|
+
import File from '../File.ts';
|
|
13
|
+
import ReferenceSet from '../ReferenceSet.ts';
|
|
14
|
+
import ResolveError from '../errors/ResolverError.ts';
|
|
15
|
+
import UnmatchedResolveStrategyError from '../errors/UnmatchedResolveStrategyError.ts';
|
|
16
|
+
import * as url from '../util/url.ts';
|
|
17
|
+
import type { ReferenceOptions } from '../options/index.ts';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolves ApiDOM with all its external references.
|
|
21
|
+
*/
|
|
22
|
+
export const resolveApiDOM = async <T extends Element>(
|
|
23
|
+
element: T,
|
|
24
|
+
options: ReferenceOptions,
|
|
25
|
+
): Promise<ReferenceSet> => {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
let parseResult: ParseResultElement = element;
|
|
28
|
+
|
|
29
|
+
// wrap element into parse result
|
|
30
|
+
if (!isParseResultElement(element)) {
|
|
31
|
+
// shallow clone of the element
|
|
32
|
+
const elementClone = cloneShallow(element);
|
|
33
|
+
elementClone.classes.push('result');
|
|
34
|
+
parseResult = new ParseResultElement([elementClone]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sanitizedURI = url.sanitize(url.stripHash(options.resolve.baseURI));
|
|
38
|
+
const file = new File({
|
|
39
|
+
uri: sanitizedURI,
|
|
40
|
+
parseResult,
|
|
41
|
+
mediaType: options.parse.mediaType,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const resolveStrategies = await plugins.filter(
|
|
45
|
+
'canResolve',
|
|
46
|
+
[file, options],
|
|
47
|
+
options.resolve.strategies,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// we couldn't find any resolve strategy for this File
|
|
51
|
+
if (isEmpty(resolveStrategies)) {
|
|
52
|
+
throw new UnmatchedResolveStrategyError(
|
|
53
|
+
`Could not find a resolve strategy that can resolve the file "${file.uri}"`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const { result } = await plugins.run('resolve', [file, options], resolveStrategies);
|
|
59
|
+
return result;
|
|
60
|
+
} catch (error: any) {
|
|
61
|
+
throw new ResolveError(`Error while resolving file "${file.uri}"`, { cause: error });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolves a file with all its external references.
|
|
67
|
+
*/
|
|
68
|
+
const resolve = async (uri: string, options: ReferenceOptions): Promise<ReferenceSet> => {
|
|
69
|
+
const parseResult = await parse(uri, options);
|
|
70
|
+
const mergedOptions = mergeOptions(options, { resolve: { baseURI: url.sanitize(uri) } });
|
|
71
|
+
|
|
72
|
+
return resolveApiDOM(parseResult, mergedOptions);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default resolve;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 _Resolver = _interopRequireDefault(require("./Resolver.cjs"));
|
|
8
|
+
var url = _interopRequireWildcard(require("../../util/url.cjs"));
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
class HTTPResolver extends _Resolver.default {
|
|
21
|
+
timeout;
|
|
22
|
+
redirects;
|
|
23
|
+
withCredentials;
|
|
24
|
+
cache;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
const {
|
|
27
|
+
name = 'http-resolver',
|
|
28
|
+
timeout = 5000,
|
|
29
|
+
redirects = 5,
|
|
30
|
+
withCredentials = false,
|
|
31
|
+
cache = false
|
|
32
|
+
} = options ?? {};
|
|
33
|
+
super({
|
|
34
|
+
name
|
|
35
|
+
});
|
|
36
|
+
this.timeout = timeout;
|
|
37
|
+
this.redirects = redirects;
|
|
38
|
+
this.withCredentials = withCredentials;
|
|
39
|
+
this.cache = cache;
|
|
40
|
+
}
|
|
41
|
+
canRead(file) {
|
|
42
|
+
return url.isHttpUrl(file.uri);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var _default = exports.default = HTTPResolver;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Resolver from "./Resolver.mjs";
|
|
2
|
+
import * as url from "../../util/url.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class HTTPResolver extends Resolver {
|
|
13
|
+
timeout;
|
|
14
|
+
redirects;
|
|
15
|
+
withCredentials;
|
|
16
|
+
cache;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
const {
|
|
19
|
+
name = 'http-resolver',
|
|
20
|
+
timeout = 5000,
|
|
21
|
+
redirects = 5,
|
|
22
|
+
withCredentials = false,
|
|
23
|
+
cache = false
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
name
|
|
27
|
+
});
|
|
28
|
+
this.timeout = timeout;
|
|
29
|
+
this.redirects = redirects;
|
|
30
|
+
this.withCredentials = withCredentials;
|
|
31
|
+
this.cache = cache;
|
|
32
|
+
}
|
|
33
|
+
canRead(file) {
|
|
34
|
+
return url.isHttpUrl(file.uri);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default HTTPResolver;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Resolver, { ResolverOptions } from './Resolver.ts';
|
|
2
|
+
import * as url from '../../util/url.ts';
|
|
3
|
+
import File from '../../File.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface CacheOptions {
|
|
9
|
+
readonly maxEntries?: number | false;
|
|
10
|
+
readonly maxStaleAge?: number | false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export interface HTTPResolverOptions extends ResolverOptions {
|
|
17
|
+
readonly timeout?: number;
|
|
18
|
+
readonly redirects?: number;
|
|
19
|
+
readonly withCredentials?: boolean;
|
|
20
|
+
readonly cache?: boolean | CacheOptions;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
abstract class HTTPResolver extends Resolver {
|
|
27
|
+
protected readonly timeout: number;
|
|
28
|
+
|
|
29
|
+
protected readonly redirects: number;
|
|
30
|
+
|
|
31
|
+
protected readonly withCredentials: boolean;
|
|
32
|
+
|
|
33
|
+
protected readonly cache: boolean | CacheOptions;
|
|
34
|
+
|
|
35
|
+
constructor(options?: HTTPResolverOptions) {
|
|
36
|
+
const {
|
|
37
|
+
name = 'http-resolver',
|
|
38
|
+
timeout = 5000,
|
|
39
|
+
redirects = 5,
|
|
40
|
+
withCredentials = false,
|
|
41
|
+
cache = false,
|
|
42
|
+
} = options ?? {};
|
|
43
|
+
|
|
44
|
+
super({ name });
|
|
45
|
+
this.timeout = timeout;
|
|
46
|
+
this.redirects = redirects;
|
|
47
|
+
this.withCredentials = withCredentials;
|
|
48
|
+
this.cache = cache;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
canRead(file: File): boolean {
|
|
52
|
+
return url.isHttpUrl(file.uri);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
abstract getHttpClient(): unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default HTTPResolver;
|
|
@@ -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,25 @@
|
|
|
1
|
+
import File from '../../File.ts';
|
|
2
|
+
import type { ReferenceOptions } from '../../options/index.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface ResolverOptions {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
abstract class Resolver {
|
|
15
|
+
public readonly name: string;
|
|
16
|
+
|
|
17
|
+
constructor({ name }: ResolverOptions) {
|
|
18
|
+
this.name = name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public abstract canRead(file: File, options?: ReferenceOptions): boolean;
|
|
22
|
+
public abstract read(file: File, options?: ReferenceOptions): Promise<Buffer>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export 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,24 @@
|
|
|
1
|
+
import Resolver from '../Resolver.ts';
|
|
2
|
+
import ResolverError from '../../../errors/ResolverError.ts';
|
|
3
|
+
|
|
4
|
+
export type { default as Resolver, ResolverOptions } from '../Resolver.ts';
|
|
5
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
class FileResolver extends Resolver {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({ name: 'file' });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
canRead(): boolean {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
read(): Promise<Buffer> {
|
|
20
|
+
throw new ResolverError('FileResolver is not intended to be used in browser context');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
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,55 @@
|
|
|
1
|
+
import { readFile } from 'node:fs';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import picomatch from 'picomatch';
|
|
4
|
+
|
|
5
|
+
import File from '../../../File.ts';
|
|
6
|
+
import Resolver, { ResolverOptions } from '../Resolver.ts';
|
|
7
|
+
import * as url from '../../../util/url.ts';
|
|
8
|
+
import ResolverError from '../../../errors/ResolverError.ts';
|
|
9
|
+
|
|
10
|
+
export type { default as Resolver, ResolverOptions } from '../Resolver.ts';
|
|
11
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export interface FileResolverOptions extends Omit<ResolverOptions, 'name'> {
|
|
17
|
+
readonly fileAllowList?: string[] | RegExp[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
class FileResolver extends Resolver {
|
|
24
|
+
public fileAllowList: string[] | RegExp[];
|
|
25
|
+
|
|
26
|
+
constructor(options?: FileResolverOptions) {
|
|
27
|
+
const { fileAllowList = [] } = options ?? {};
|
|
28
|
+
|
|
29
|
+
super({ name: 'file' });
|
|
30
|
+
this.fileAllowList = fileAllowList;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
canRead(file: File): boolean {
|
|
34
|
+
return (
|
|
35
|
+
url.isFileSystemPath(file.uri) &&
|
|
36
|
+
this.fileAllowList.some((pattern) => {
|
|
37
|
+
return typeof pattern === 'string'
|
|
38
|
+
? picomatch.isMatch(file.uri, pattern, { matchBase: true })
|
|
39
|
+
: pattern.test(file.uri);
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async read(file: File): Promise<Buffer> {
|
|
45
|
+
const fileSystemPath = url.toFileSystemPath(file.uri);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
return await promisify(readFile)(fileSystemPath);
|
|
49
|
+
} catch (error: unknown) {
|
|
50
|
+
throw new ResolverError(`Error opening file "${file.uri}"`, { cause: error });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
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,46 @@
|
|
|
1
|
+
import type { CacheOptions } from '../../HTTPResolver.ts';
|
|
2
|
+
|
|
3
|
+
interface CacheEntry<T> {
|
|
4
|
+
value: T;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class MemoryCache<T> {
|
|
9
|
+
protected maxEntries: number | false;
|
|
10
|
+
|
|
11
|
+
protected maxStaleAge: number | false;
|
|
12
|
+
|
|
13
|
+
protected readonly store: Map<string, CacheEntry<T>> = new Map();
|
|
14
|
+
|
|
15
|
+
constructor(options: CacheOptions = {}) {
|
|
16
|
+
const { maxEntries = 1024, maxStaleAge = 3_600_000 } = options;
|
|
17
|
+
|
|
18
|
+
this.maxEntries = maxEntries;
|
|
19
|
+
this.maxStaleAge = maxStaleAge;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get(key: string): T | undefined {
|
|
23
|
+
const entry = this.store.get(key);
|
|
24
|
+
if (entry === undefined) return undefined;
|
|
25
|
+
|
|
26
|
+
// evict if entry has exceeded maxStaleAge
|
|
27
|
+
if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
|
|
28
|
+
this.store.delete(key);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return entry.value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set(key: string, value: T): void {
|
|
36
|
+
this.store.set(key, { value, createdAt: Date.now() });
|
|
37
|
+
|
|
38
|
+
// evict oldest entries if maxEntries exceeded
|
|
39
|
+
if (this.maxEntries !== false && this.store.size > this.maxEntries) {
|
|
40
|
+
const firstKey = this.store.keys().next().value as string;
|
|
41
|
+
this.store.delete(firstKey);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default MemoryCache;
|