@speclynx/apidom-reference 1.12.1
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 +86 -0
- package/LICENSE +202 -0
- package/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +65 -0
- package/README.md +2107 -0
- package/dist/167.apidom-reference.browser.js +10 -0
- package/dist/167.apidom-reference.browser.min.js +1 -0
- package/dist/451.apidom-reference.browser.js +10 -0
- package/dist/451.apidom-reference.browser.min.js +1 -0
- package/dist/9786785aaddf11f37840fad896531940.wasm +0 -0
- package/dist/apidom-reference.browser.js +85376 -0
- package/dist/apidom-reference.browser.min.js +1 -0
- package/package.json +304 -0
- 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 +95 -0
- package/src/configuration/saturated.mjs +87 -0
- package/src/dereference/index.cjs +86 -0
- package/src/dereference/index.mjs +79 -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 +84 -0
- package/src/dereference/strategies/apidom/selectors/element-id.cjs +36 -0
- package/src/dereference/strategies/apidom/selectors/element-id.mjs +30 -0
- package/src/dereference/strategies/apidom/visitor.cjs +165 -0
- package/src/dereference/strategies/apidom/visitor.mjs +159 -0
- package/src/dereference/strategies/asyncapi-2/index.cjs +100 -0
- package/src/dereference/strategies/asyncapi-2/index.mjs +94 -0
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +412 -0
- package/src/dereference/strategies/asyncapi-2/visitor.mjs +406 -0
- package/src/dereference/strategies/openapi-2/index.cjs +102 -0
- package/src/dereference/strategies/openapi-2/index.mjs +96 -0
- package/src/dereference/strategies/openapi-2/visitor.cjs +530 -0
- package/src/dereference/strategies/openapi-2/visitor.mjs +524 -0
- package/src/dereference/strategies/openapi-3-0/index.cjs +102 -0
- package/src/dereference/strategies/openapi-3-0/index.mjs +96 -0
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +519 -0
- package/src/dereference/strategies/openapi-3-0/visitor.mjs +513 -0
- package/src/dereference/strategies/openapi-3-1/index.cjs +105 -0
- package/src/dereference/strategies/openapi-3-1/index.mjs +96 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +66 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +55 -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 +67 -0
- package/src/dereference/strategies/openapi-3-1/util.mjs +58 -0
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +776 -0
- package/src/dereference/strategies/openapi-3-1/visitor.mjs +770 -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/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/index.cjs +142 -0
- package/src/index.mjs +101 -0
- package/src/options/index.cjs +185 -0
- package/src/options/index.mjs +182 -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 +48 -0
- package/src/parse/parsers/Parser.mjs +44 -0
- package/src/parse/parsers/api-design-systems-json/index.cjs +55 -0
- package/src/parse/parsers/api-design-systems-json/index.mjs +49 -0
- package/src/parse/parsers/api-design-systems-yaml/index.cjs +54 -0
- package/src/parse/parsers/api-design-systems-yaml/index.mjs +48 -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 +55 -0
- package/src/parse/parsers/arazzo-json-1/index.mjs +49 -0
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +54 -0
- package/src/parse/parsers/arazzo-yaml-1/index.mjs +48 -0
- package/src/parse/parsers/asyncapi-json-2/index.cjs +55 -0
- package/src/parse/parsers/asyncapi-json-2/index.mjs +49 -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 +54 -0
- package/src/parse/parsers/json/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-2/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-2/index.mjs +49 -0
- package/src/parse/parsers/openapi-json-3-0/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-3-0/index.mjs +49 -0
- package/src/parse/parsers/openapi-json-3-1/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-3-1/index.mjs +49 -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 +54 -0
- package/src/parse/parsers/yaml-1-2/index.mjs +48 -0
- package/src/resolve/index.cjs +67 -0
- package/src/resolve/index.mjs +60 -0
- package/src/resolve/resolvers/HTTPResolver.cjs +38 -0
- package/src/resolve/resolvers/HTTPResolver.mjs +31 -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/index.cjs +80 -0
- package/src/resolve/resolvers/http-axios/index.mjs +73 -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 +44 -0
- package/src/util/plugins.mjs +37 -0
- package/src/util/url.cjs +288 -0
- package/src/util/url.mjs +274 -0
- package/types/File.d.ts +24 -0
- package/types/Reference.d.ts +23 -0
- package/types/ReferenceSet.d.ts +25 -0
- package/types/apidom-reference.d.ts +584 -0
- package/types/bundle/index.d.ts +7 -0
- package/types/bundle/strategies/BundleStrategy.d.ts +19 -0
- package/types/bundle/strategies/openapi-3-1/index.d.ts +26 -0
- package/types/configuration/empty.d.ts +1 -0
- package/types/configuration/saturated.d.ts +1 -0
- package/types/dereference/index.d.ts +11 -0
- package/types/dereference/strategies/DereferenceStrategy.d.ts +19 -0
- package/types/dereference/strategies/apidom/index.d.ts +30 -0
- package/types/dereference/strategies/apidom/selectors/element-id.d.ts +11 -0
- package/types/dereference/strategies/apidom/visitor.d.ts +32 -0
- package/types/dereference/strategies/asyncapi-2/index.d.ts +31 -0
- package/types/dereference/strategies/asyncapi-2/visitor.d.ts +43 -0
- package/types/dereference/strategies/openapi-2/index.d.ts +32 -0
- package/types/dereference/strategies/openapi-2/visitor.d.ts +47 -0
- package/types/dereference/strategies/openapi-3-0/index.d.ts +31 -0
- package/types/dereference/strategies/openapi-3-0/visitor.d.ts +49 -0
- package/types/dereference/strategies/openapi-3-1/index.d.ts +32 -0
- package/types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts +22 -0
- package/types/dereference/strategies/openapi-3-1/selectors/uri.d.ts +12 -0
- package/types/dereference/strategies/openapi-3-1/util.d.ts +21 -0
- package/types/dereference/strategies/openapi-3-1/visitor.d.ts +52 -0
- package/types/dereference/util.d.ts +9 -0
- package/types/errors/BundleError.d.ts +7 -0
- package/types/errors/DereferenceError.d.ts +7 -0
- package/types/errors/EvaluationElementIdError.d.ts +7 -0
- package/types/errors/EvaluationJsonSchema$anchorError.d.ts +7 -0
- package/types/errors/EvaluationJsonSchemaUriError.d.ts +7 -0
- package/types/errors/InvalidJsonSchema$anchorError.d.ts +8 -0
- package/types/errors/JsonSchema$anchorError.d.ts +7 -0
- package/types/errors/JsonSchemaUriError.d.ts +7 -0
- package/types/errors/MaximumBundleDepthError.d.ts +7 -0
- package/types/errors/MaximumDereferenceDepthError.d.ts +7 -0
- package/types/errors/MaximumResolveDepthError.d.ts +7 -0
- package/types/errors/ParseError.d.ts +7 -0
- package/types/errors/ParserError.d.ts +7 -0
- package/types/errors/PluginError.d.ts +12 -0
- package/types/errors/ResolveError.d.ts +7 -0
- package/types/errors/ResolverError.d.ts +7 -0
- package/types/errors/UnmatchedBundleStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedDereferenceStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedResolveStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedResolverError.d.ts +7 -0
- package/types/index.d.ts +75 -0
- package/types/options/index.d.ts +62 -0
- package/types/options/util.d.ts +5 -0
- package/types/parse/index.d.ts +7 -0
- package/types/parse/parsers/Parser.d.ts +38 -0
- package/types/parse/parsers/api-design-systems-json/index.d.ts +21 -0
- package/types/parse/parsers/api-design-systems-yaml/index.d.ts +20 -0
- package/types/parse/parsers/apidom-json/index.d.ts +24 -0
- package/types/parse/parsers/arazzo-json-1/index.d.ts +21 -0
- package/types/parse/parsers/arazzo-yaml-1/index.d.ts +20 -0
- package/types/parse/parsers/asyncapi-json-2/index.d.ts +21 -0
- package/types/parse/parsers/asyncapi-yaml-2/index.d.ts +20 -0
- package/types/parse/parsers/binary/index-browser.d.ts +21 -0
- package/types/parse/parsers/binary/index-node.d.ts +21 -0
- package/types/parse/parsers/json/index.d.ts +20 -0
- package/types/parse/parsers/openapi-json-2/index.d.ts +21 -0
- package/types/parse/parsers/openapi-json-3-0/index.d.ts +21 -0
- package/types/parse/parsers/openapi-json-3-1/index.d.ts +21 -0
- package/types/parse/parsers/openapi-yaml-2/index.d.ts +20 -0
- package/types/parse/parsers/openapi-yaml-3-0/index.d.ts +20 -0
- package/types/parse/parsers/openapi-yaml-3-1/index.d.ts +20 -0
- package/types/parse/parsers/yaml-1-2/index.d.ts +20 -0
- package/types/resolve/index.d.ts +12 -0
- package/types/resolve/resolvers/HTTPResolver.d.ts +22 -0
- package/types/resolve/resolvers/Resolver.d.ts +17 -0
- package/types/resolve/resolvers/file/index-browser.d.ts +12 -0
- package/types/resolve/resolvers/file/index-node.d.ts +20 -0
- package/types/resolve/resolvers/http-axios/index.d.ts +30 -0
- package/types/resolve/strategies/ResolveStrategy.d.ts +19 -0
- package/types/resolve/strategies/apidom/index.d.ts +27 -0
- package/types/resolve/strategies/asyncapi-2/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-2/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-3-0/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-3-1/index.d.ts +27 -0
- package/types/resolve/util.d.ts +6 -0
- package/types/util/plugins.d.ts +14 -0
- package/types/util/url.d.ts +106 -0
package/src/index.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import File from "./File.mjs";
|
|
2
|
+
import ReferenceSet from "./ReferenceSet.mjs";
|
|
3
|
+
import * as url from "./util/url.mjs";
|
|
4
|
+
import defaultOptions from "./options/index.mjs";
|
|
5
|
+
import { merge as mergeOptions } from "./options/util.mjs";
|
|
6
|
+
import parseFn from "./parse/index.mjs";
|
|
7
|
+
import resolveFn, { resolveApiDOM as resolveApiDOMFn } from "./resolve/index.mjs";
|
|
8
|
+
import { readFile as readFileFn } from "./resolve/util.mjs";
|
|
9
|
+
import dereferenceFn, { dereferenceApiDOM as dereferenceApiDOMFn } from "./dereference/index.mjs";
|
|
10
|
+
import bundleFn from "./bundle/index.mjs";
|
|
11
|
+
export { url };
|
|
12
|
+
export { default as Parser } from "./parse/parsers/Parser.mjs";
|
|
13
|
+
export { default as Resolver } from "./resolve/resolvers/Resolver.mjs";
|
|
14
|
+
export { default as HTTPResolver } from "./resolve/resolvers/HTTPResolver.mjs";
|
|
15
|
+
export { default as ResolveStrategy } from "./resolve/strategies/ResolveStrategy.mjs";
|
|
16
|
+
export { default as DereferenceStrategy } from "./dereference/strategies/DereferenceStrategy.mjs";
|
|
17
|
+
export { AncestorLineage as DereferenceAncestorLineage } from "./dereference/util.mjs";
|
|
18
|
+
export { default as BundleStrategy } from "./bundle/strategies/BundleStrategy.mjs";
|
|
19
|
+
export { default as options } from "./options/index.mjs";
|
|
20
|
+
export { merge as mergeOptions } from "./options/util.mjs";
|
|
21
|
+
export { File };
|
|
22
|
+
export { default as Reference } from "./Reference.mjs";
|
|
23
|
+
export { ReferenceSet };
|
|
24
|
+
export { default as BundleError } from "./errors/BundleError.mjs";
|
|
25
|
+
export { default as MaximumBundleDepthError } from "./errors/MaximumBundleDepthError.mjs";
|
|
26
|
+
export { default as UnmatchedBundleStrategyError } from "./errors/UnmatchedBundleStrategyError.mjs";
|
|
27
|
+
export { default as DereferenceError } from "./errors/DereferenceError.mjs";
|
|
28
|
+
export { default as EvaluationElementIdError } from "./errors/EvaluationElementIdError.mjs";
|
|
29
|
+
export { default as EvaluationJsonSchema$anchorError } from "./errors/EvaluationJsonSchema$anchorError.mjs";
|
|
30
|
+
export { default as EvaluationJsonSchemaUriError } from "./errors/EvaluationJsonSchemaUriError.mjs";
|
|
31
|
+
export { default as InvalidJsonSchema$anchorError } from "./errors/InvalidJsonSchema$anchorError.mjs";
|
|
32
|
+
export { default as JsonSchema$anchorError } from "./errors/JsonSchema$anchorError.mjs";
|
|
33
|
+
export { default as JsonSchemaURIError } from "./errors/JsonSchemaUriError.mjs";
|
|
34
|
+
export { default as MaximumDereferenceDepthError } from "./errors/MaximumDereferenceDepthError.mjs";
|
|
35
|
+
export { default as MaximumResolveDepthError } from "./errors/MaximumResolveDepthError.mjs";
|
|
36
|
+
export { default as ParseError } from "./errors/ParseError.mjs";
|
|
37
|
+
export { default as ParserError } from "./errors/ParserError.mjs";
|
|
38
|
+
export { default as PluginError } from "./errors/PluginError.mjs";
|
|
39
|
+
export { default as ResolveError } from "./errors/ResolveError.mjs";
|
|
40
|
+
export { default as ResolverError } from "./errors/ResolverError.mjs";
|
|
41
|
+
export { default as UnmatchedDereferenceStrategyError } from "./errors/UnmatchedDereferenceStrategyError.mjs";
|
|
42
|
+
export { default as UnmatchedResolveStrategyError } from "./errors/UnmatchedResolveStrategyError.mjs";
|
|
43
|
+
export { default as UnmatchedResolverError } from "./errors/UnmatchedResolverError.mjs";
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export const readFile = async (uri, options = {}) => {
|
|
48
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
49
|
+
const file = new File({
|
|
50
|
+
uri: url.sanitize(uri)
|
|
51
|
+
});
|
|
52
|
+
return readFileFn(file, mergedOptions);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export const parse = async (uri, options = {}) => {
|
|
59
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
60
|
+
return parseFn(uri, mergedOptions);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export const resolve = async (uri, options = {}) => {
|
|
67
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
68
|
+
return resolveFn(uri, mergedOptions);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export const resolveApiDOM = async (element, options = {}) => {
|
|
75
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
76
|
+
return resolveApiDOMFn(element, mergedOptions);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export const dereference = async (uri, options = {}) => {
|
|
83
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
84
|
+
return dereferenceFn(uri, mergedOptions);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export const dereferenceApiDOM = async (element, options = {}) => {
|
|
91
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
92
|
+
return dereferenceApiDOMFn(element, mergedOptions);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export const bundle = async (uri, options = {}) => {
|
|
99
|
+
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
100
|
+
return bundleFn(uri, mergedOptions);
|
|
101
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _ramda = require("ramda");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
const defaultOptions = {
|
|
30
|
+
parse: {
|
|
31
|
+
/**
|
|
32
|
+
* This is media type that will be used to parse the input.
|
|
33
|
+
*/
|
|
34
|
+
mediaType: 'text/plain',
|
|
35
|
+
/**
|
|
36
|
+
* Determines how different types of files will be parsed.
|
|
37
|
+
*
|
|
38
|
+
* You can add additional parsers of your own, replace an existing one with
|
|
39
|
+
* your own implementation, or remove any resolver by removing it from the list.
|
|
40
|
+
* It's recommended to keep the order of parser from most specific ones to most generic ones.
|
|
41
|
+
*/
|
|
42
|
+
parsers: [],
|
|
43
|
+
/**
|
|
44
|
+
* These options are merged with parser plugin instance before the plugin is run.
|
|
45
|
+
*/
|
|
46
|
+
parserOpts: {}
|
|
47
|
+
},
|
|
48
|
+
resolve: {
|
|
49
|
+
/**
|
|
50
|
+
* baseURI serves as a base for all relative URL found in ApiDOM references.
|
|
51
|
+
*/
|
|
52
|
+
baseURI: '',
|
|
53
|
+
/**
|
|
54
|
+
* Determines how References will be resolved.
|
|
55
|
+
*
|
|
56
|
+
* You can add additional resolvers of your own, replace an existing one with
|
|
57
|
+
* your own implementation, or remove any resolver by removing it from the list.
|
|
58
|
+
*/
|
|
59
|
+
resolvers: [],
|
|
60
|
+
/**
|
|
61
|
+
* These options are merged with resolver plugin instance before the plugin is run.
|
|
62
|
+
*/
|
|
63
|
+
resolverOpts: {},
|
|
64
|
+
/**
|
|
65
|
+
* Determines strategies how References are identified and processed by resolvers.
|
|
66
|
+
* Strategy is determined by media type.
|
|
67
|
+
*
|
|
68
|
+
* You can add additional resolver strategies of your own, replace an existing one with
|
|
69
|
+
* your own implementation, or remove any resolve strategy by removing it from the list.
|
|
70
|
+
*/
|
|
71
|
+
strategies: [],
|
|
72
|
+
/**
|
|
73
|
+
* These options are available in resolver strategy `canResolve` and `resolve` methods.
|
|
74
|
+
*/
|
|
75
|
+
strategyOpts: {},
|
|
76
|
+
/**
|
|
77
|
+
* Determines whether internal references will be resolved.
|
|
78
|
+
* Internal references will simply be ignored.
|
|
79
|
+
*/
|
|
80
|
+
internal: true,
|
|
81
|
+
/**
|
|
82
|
+
* Determines whether external references will be resolved.
|
|
83
|
+
* If this option is disabled, then none of above resolvers will be called.
|
|
84
|
+
* Instead, external references will simply be ignored.
|
|
85
|
+
*/
|
|
86
|
+
external: true,
|
|
87
|
+
/**
|
|
88
|
+
* Determines the maximum depth of resolve algorithms.
|
|
89
|
+
* By default, there is no limit.
|
|
90
|
+
*
|
|
91
|
+
* This option tracks the depth of the file tree not the depth of the dereference path.
|
|
92
|
+
*
|
|
93
|
+
* It can be set to any positive integer number or zero (0).
|
|
94
|
+
*
|
|
95
|
+
* The resolver should throw MaximumResolverDepthError if resolution depth
|
|
96
|
+
* is exceeded by this option.
|
|
97
|
+
*/
|
|
98
|
+
maxDepth: +Infinity
|
|
99
|
+
},
|
|
100
|
+
dereference: {
|
|
101
|
+
/**
|
|
102
|
+
* Determines strategies how ApiDOM is dereferenced.
|
|
103
|
+
* Strategy is determined by media type or by inspecting ApiDOM to be dereferenced.
|
|
104
|
+
*
|
|
105
|
+
* You can add additional dereference strategies of your own, replace an existing one with
|
|
106
|
+
* your own implementation, or remove any dereference strategy by removing it from the list.
|
|
107
|
+
*/
|
|
108
|
+
strategies: [],
|
|
109
|
+
/**
|
|
110
|
+
* These options are available in dereference strategy `canDereference` and `dereference` methods.
|
|
111
|
+
*/
|
|
112
|
+
strategyOpts: {},
|
|
113
|
+
/**
|
|
114
|
+
* This option accepts an instance of pre-computed ReferenceSet.
|
|
115
|
+
* If provided it will speed up the dereferencing significantly as the external
|
|
116
|
+
* resolution doesn't need to happen anymore.
|
|
117
|
+
*/
|
|
118
|
+
refSet: null,
|
|
119
|
+
/**
|
|
120
|
+
* Determines the maximum depth of dereferencing.
|
|
121
|
+
* By default, there is no limit.
|
|
122
|
+
*
|
|
123
|
+
* The maxDepth represents a number of references that needed to be followed
|
|
124
|
+
* before the eventual value was reached.
|
|
125
|
+
*
|
|
126
|
+
* It can be set to any positive integer number or zero (0).
|
|
127
|
+
*
|
|
128
|
+
* The dereferencing should throw MaximumDereferenceDepthError if dereferencing depth
|
|
129
|
+
* is exceeded by this option.
|
|
130
|
+
*/
|
|
131
|
+
maxDepth: +Infinity,
|
|
132
|
+
/**
|
|
133
|
+
* Determines how circular references are handled.
|
|
134
|
+
*
|
|
135
|
+
* "ignore" - circular reference are allowed
|
|
136
|
+
* "replace" - circular references are not allowed and are translated to RefElement
|
|
137
|
+
* "error" - circular references are not allowed and will throw an error
|
|
138
|
+
*/
|
|
139
|
+
circular: 'ignore',
|
|
140
|
+
/**
|
|
141
|
+
* This function is used to replace circular references when `circular` option is set to "replace".
|
|
142
|
+
* By default, it's an identity function. It means that circular references are replaced with RefElement.
|
|
143
|
+
*/
|
|
144
|
+
circularReplacer: _ramda.identity,
|
|
145
|
+
/**
|
|
146
|
+
* Determines whether the dereferencing process will be immutable.
|
|
147
|
+
* By default, the dereferencing process is immutable, which means that the original
|
|
148
|
+
* ApiDOM passed to the dereference process is NOT modified.
|
|
149
|
+
*
|
|
150
|
+
* true - the dereferencing process will be immutable (deep cloning of ApiDOM is involved)
|
|
151
|
+
* false - the dereferencing process will be mutable
|
|
152
|
+
*/
|
|
153
|
+
immutable: true
|
|
154
|
+
},
|
|
155
|
+
bundle: {
|
|
156
|
+
/**
|
|
157
|
+
* Determines strategies how ApiDOM is bundled.
|
|
158
|
+
* Strategy is determined by media type or by inspecting ApiDOM to be bundled.
|
|
159
|
+
*
|
|
160
|
+
* You can add additional bundle strategies of your own, replace an existing one with
|
|
161
|
+
* your own implementation, or remove any bundle strategy by removing it from the list.
|
|
162
|
+
*/
|
|
163
|
+
strategies: [],
|
|
164
|
+
/**
|
|
165
|
+
* This option accepts an instance of pre-computed ReferenceSet.
|
|
166
|
+
* If provided it will speed up the bundling significantly as the external
|
|
167
|
+
* resolution doesn't need to happen anymore.
|
|
168
|
+
*/
|
|
169
|
+
refSet: null,
|
|
170
|
+
/**
|
|
171
|
+
* Determines the maximum depth of bundling.
|
|
172
|
+
* By default, there is no limit.
|
|
173
|
+
*
|
|
174
|
+
* The maxDepth represents a number of references that needed to be followed
|
|
175
|
+
* before the eventual value was reached.
|
|
176
|
+
*
|
|
177
|
+
* It can be set to any positive integer number or zero (0).
|
|
178
|
+
*
|
|
179
|
+
* The bundling should throw MaximumBundleDepthError if bundling depth
|
|
180
|
+
* is exceeded by this option.
|
|
181
|
+
*/
|
|
182
|
+
maxDepth: +Infinity
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var _default = exports.default = defaultOptions;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { identity } from 'ramda';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const defaultOptions = {
|
|
27
|
+
parse: {
|
|
28
|
+
/**
|
|
29
|
+
* This is media type that will be used to parse the input.
|
|
30
|
+
*/
|
|
31
|
+
mediaType: 'text/plain',
|
|
32
|
+
/**
|
|
33
|
+
* Determines how different types of files will be parsed.
|
|
34
|
+
*
|
|
35
|
+
* You can add additional parsers of your own, replace an existing one with
|
|
36
|
+
* your own implementation, or remove any resolver by removing it from the list.
|
|
37
|
+
* It's recommended to keep the order of parser from most specific ones to most generic ones.
|
|
38
|
+
*/
|
|
39
|
+
parsers: [],
|
|
40
|
+
/**
|
|
41
|
+
* These options are merged with parser plugin instance before the plugin is run.
|
|
42
|
+
*/
|
|
43
|
+
parserOpts: {}
|
|
44
|
+
},
|
|
45
|
+
resolve: {
|
|
46
|
+
/**
|
|
47
|
+
* baseURI serves as a base for all relative URL found in ApiDOM references.
|
|
48
|
+
*/
|
|
49
|
+
baseURI: '',
|
|
50
|
+
/**
|
|
51
|
+
* Determines how References will be resolved.
|
|
52
|
+
*
|
|
53
|
+
* You can add additional resolvers of your own, replace an existing one with
|
|
54
|
+
* your own implementation, or remove any resolver by removing it from the list.
|
|
55
|
+
*/
|
|
56
|
+
resolvers: [],
|
|
57
|
+
/**
|
|
58
|
+
* These options are merged with resolver plugin instance before the plugin is run.
|
|
59
|
+
*/
|
|
60
|
+
resolverOpts: {},
|
|
61
|
+
/**
|
|
62
|
+
* Determines strategies how References are identified and processed by resolvers.
|
|
63
|
+
* Strategy is determined by media type.
|
|
64
|
+
*
|
|
65
|
+
* You can add additional resolver strategies of your own, replace an existing one with
|
|
66
|
+
* your own implementation, or remove any resolve strategy by removing it from the list.
|
|
67
|
+
*/
|
|
68
|
+
strategies: [],
|
|
69
|
+
/**
|
|
70
|
+
* These options are available in resolver strategy `canResolve` and `resolve` methods.
|
|
71
|
+
*/
|
|
72
|
+
strategyOpts: {},
|
|
73
|
+
/**
|
|
74
|
+
* Determines whether internal references will be resolved.
|
|
75
|
+
* Internal references will simply be ignored.
|
|
76
|
+
*/
|
|
77
|
+
internal: true,
|
|
78
|
+
/**
|
|
79
|
+
* Determines whether external references will be resolved.
|
|
80
|
+
* If this option is disabled, then none of above resolvers will be called.
|
|
81
|
+
* Instead, external references will simply be ignored.
|
|
82
|
+
*/
|
|
83
|
+
external: true,
|
|
84
|
+
/**
|
|
85
|
+
* Determines the maximum depth of resolve algorithms.
|
|
86
|
+
* By default, there is no limit.
|
|
87
|
+
*
|
|
88
|
+
* This option tracks the depth of the file tree not the depth of the dereference path.
|
|
89
|
+
*
|
|
90
|
+
* It can be set to any positive integer number or zero (0).
|
|
91
|
+
*
|
|
92
|
+
* The resolver should throw MaximumResolverDepthError if resolution depth
|
|
93
|
+
* is exceeded by this option.
|
|
94
|
+
*/
|
|
95
|
+
maxDepth: +Infinity
|
|
96
|
+
},
|
|
97
|
+
dereference: {
|
|
98
|
+
/**
|
|
99
|
+
* Determines strategies how ApiDOM is dereferenced.
|
|
100
|
+
* Strategy is determined by media type or by inspecting ApiDOM to be dereferenced.
|
|
101
|
+
*
|
|
102
|
+
* You can add additional dereference strategies of your own, replace an existing one with
|
|
103
|
+
* your own implementation, or remove any dereference strategy by removing it from the list.
|
|
104
|
+
*/
|
|
105
|
+
strategies: [],
|
|
106
|
+
/**
|
|
107
|
+
* These options are available in dereference strategy `canDereference` and `dereference` methods.
|
|
108
|
+
*/
|
|
109
|
+
strategyOpts: {},
|
|
110
|
+
/**
|
|
111
|
+
* This option accepts an instance of pre-computed ReferenceSet.
|
|
112
|
+
* If provided it will speed up the dereferencing significantly as the external
|
|
113
|
+
* resolution doesn't need to happen anymore.
|
|
114
|
+
*/
|
|
115
|
+
refSet: null,
|
|
116
|
+
/**
|
|
117
|
+
* Determines the maximum depth of dereferencing.
|
|
118
|
+
* By default, there is no limit.
|
|
119
|
+
*
|
|
120
|
+
* The maxDepth represents a number of references that needed to be followed
|
|
121
|
+
* before the eventual value was reached.
|
|
122
|
+
*
|
|
123
|
+
* It can be set to any positive integer number or zero (0).
|
|
124
|
+
*
|
|
125
|
+
* The dereferencing should throw MaximumDereferenceDepthError if dereferencing depth
|
|
126
|
+
* is exceeded by this option.
|
|
127
|
+
*/
|
|
128
|
+
maxDepth: +Infinity,
|
|
129
|
+
/**
|
|
130
|
+
* Determines how circular references are handled.
|
|
131
|
+
*
|
|
132
|
+
* "ignore" - circular reference are allowed
|
|
133
|
+
* "replace" - circular references are not allowed and are translated to RefElement
|
|
134
|
+
* "error" - circular references are not allowed and will throw an error
|
|
135
|
+
*/
|
|
136
|
+
circular: 'ignore',
|
|
137
|
+
/**
|
|
138
|
+
* This function is used to replace circular references when `circular` option is set to "replace".
|
|
139
|
+
* By default, it's an identity function. It means that circular references are replaced with RefElement.
|
|
140
|
+
*/
|
|
141
|
+
circularReplacer: identity,
|
|
142
|
+
/**
|
|
143
|
+
* Determines whether the dereferencing process will be immutable.
|
|
144
|
+
* By default, the dereferencing process is immutable, which means that the original
|
|
145
|
+
* ApiDOM passed to the dereference process is NOT modified.
|
|
146
|
+
*
|
|
147
|
+
* true - the dereferencing process will be immutable (deep cloning of ApiDOM is involved)
|
|
148
|
+
* false - the dereferencing process will be mutable
|
|
149
|
+
*/
|
|
150
|
+
immutable: true
|
|
151
|
+
},
|
|
152
|
+
bundle: {
|
|
153
|
+
/**
|
|
154
|
+
* Determines strategies how ApiDOM is bundled.
|
|
155
|
+
* Strategy is determined by media type or by inspecting ApiDOM to be bundled.
|
|
156
|
+
*
|
|
157
|
+
* You can add additional bundle strategies of your own, replace an existing one with
|
|
158
|
+
* your own implementation, or remove any bundle strategy by removing it from the list.
|
|
159
|
+
*/
|
|
160
|
+
strategies: [],
|
|
161
|
+
/**
|
|
162
|
+
* This option accepts an instance of pre-computed ReferenceSet.
|
|
163
|
+
* If provided it will speed up the bundling significantly as the external
|
|
164
|
+
* resolution doesn't need to happen anymore.
|
|
165
|
+
*/
|
|
166
|
+
refSet: null,
|
|
167
|
+
/**
|
|
168
|
+
* Determines the maximum depth of bundling.
|
|
169
|
+
* By default, there is no limit.
|
|
170
|
+
*
|
|
171
|
+
* The maxDepth represents a number of references that needed to be followed
|
|
172
|
+
* before the eventual value was reached.
|
|
173
|
+
*
|
|
174
|
+
* It can be set to any positive integer number or zero (0).
|
|
175
|
+
*
|
|
176
|
+
* The bundling should throw MaximumBundleDepthError if bundling depth
|
|
177
|
+
* is exceeded by this option.
|
|
178
|
+
*/
|
|
179
|
+
maxDepth: +Infinity
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
export default defaultOptions;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.merge = void 0;
|
|
5
|
+
var _ramda = require("ramda");
|
|
6
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
+
var _url = require("../util/url.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* Algorithm for deep merging options.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const baseURILens = (0, _ramda.lens)((0, _ramda.path)(['resolve', 'baseURI']), (0, _ramda.assocPath)(['resolve', 'baseURI']));
|
|
13
|
+
const baseURIDefault = baseURI => (0, _ramdaAdjunct.isEmptyString)(baseURI) ? (0, _url.cwd)() : baseURI;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const merge = (lObj, rObj) => {
|
|
20
|
+
const withoutDefaults = (0, _ramda.mergeDeepRight)(lObj, rObj);
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
return (0, _ramda.over)(baseURILens, baseURIDefault, withoutDefaults);
|
|
23
|
+
};
|
|
24
|
+
exports.merge = merge;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { mergeDeepRight, lens, path, assocPath, over } from 'ramda';
|
|
2
|
+
import { isEmptyString } from 'ramda-adjunct';
|
|
3
|
+
import { cwd } from "../util/url.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Algorithm for deep merging options.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const baseURILens = lens(path(['resolve', 'baseURI']), assocPath(['resolve', 'baseURI']));
|
|
9
|
+
const baseURIDefault = baseURI => isEmptyString(baseURI) ? cwd() : baseURI;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const merge = (lObj, rObj) => {
|
|
16
|
+
const withoutDefaults = mergeDeepRight(lObj, rObj);
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
return over(baseURILens, baseURIDefault, withoutDefaults);
|
|
19
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var url = _interopRequireWildcard(require("../util/url.cjs"));
|
|
9
|
+
var _File = _interopRequireDefault(require("../File.cjs"));
|
|
10
|
+
var plugins = _interopRequireWildcard(require("../util/plugins.cjs"));
|
|
11
|
+
var _ParseError = _interopRequireDefault(require("../errors/ParseError.cjs"));
|
|
12
|
+
var _UnmatchedResolverError = _interopRequireDefault(require("../errors/UnmatchedResolverError.cjs"));
|
|
13
|
+
var _util = require("../resolve/util.cjs");
|
|
14
|
+
/**
|
|
15
|
+
* Parses the given file's contents, using the configured parser plugins.
|
|
16
|
+
*/
|
|
17
|
+
const parseFile = async (file, options) => {
|
|
18
|
+
const optsBoundParsers = options.parse.parsers.map(parser => {
|
|
19
|
+
const clonedParser = Object.create(parser);
|
|
20
|
+
return Object.assign(clonedParser, options.parse.parserOpts);
|
|
21
|
+
});
|
|
22
|
+
const parsers = await plugins.filter('canParse', [file, options], optsBoundParsers);
|
|
23
|
+
|
|
24
|
+
// we couldn't find any parser for this File
|
|
25
|
+
if ((0, _ramda.isEmpty)(parsers)) {
|
|
26
|
+
throw new _UnmatchedResolverError.default(file.uri);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const {
|
|
30
|
+
plugin,
|
|
31
|
+
result
|
|
32
|
+
} = await plugins.run('parse', [file, options], parsers);
|
|
33
|
+
|
|
34
|
+
// empty files handling
|
|
35
|
+
if (!plugin.allowEmpty && result.isEmpty) {
|
|
36
|
+
return Promise.reject(new _ParseError.default(`Error while parsing file "${file.uri}". File is empty.`));
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw new _ParseError.default(`Error while parsing file "${file.uri}"`, {
|
|
41
|
+
cause: error
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parses a file into ApiDOM.
|
|
48
|
+
*/
|
|
49
|
+
const parse = async (uri, options) => {
|
|
50
|
+
/**
|
|
51
|
+
* If the path is a filesystem path, then convert it to a URL.
|
|
52
|
+
*
|
|
53
|
+
* NOTE: According to the JSON Reference spec, these should already be URLs,
|
|
54
|
+
* but, in practice, many people use local filesystem paths instead.
|
|
55
|
+
* So we're being generous here and doing the conversion automatically.
|
|
56
|
+
* This is not intended to be a 100% bulletproof solution.
|
|
57
|
+
* If it doesn't work for your use-case, then use a URL instead.
|
|
58
|
+
*/
|
|
59
|
+
const file = new _File.default({
|
|
60
|
+
uri: url.sanitize(url.stripHash(uri)),
|
|
61
|
+
mediaType: options.parse.mediaType
|
|
62
|
+
});
|
|
63
|
+
const data = await (0, _util.readFile)(file, options);
|
|
64
|
+
return parseFile(new _File.default({
|
|
65
|
+
...file,
|
|
66
|
+
data
|
|
67
|
+
}), options);
|
|
68
|
+
};
|
|
69
|
+
var _default = exports.default = parse;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isEmpty } from 'ramda';
|
|
2
|
+
import * as url from "../util/url.mjs";
|
|
3
|
+
import File from "../File.mjs";
|
|
4
|
+
import * as plugins from "../util/plugins.mjs";
|
|
5
|
+
import ParseError from "../errors/ParseError.mjs";
|
|
6
|
+
import UnmatchedResolverError from "../errors/UnmatchedResolverError.mjs";
|
|
7
|
+
import { readFile } from "../resolve/util.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* Parses the given file's contents, using the configured parser plugins.
|
|
10
|
+
*/
|
|
11
|
+
const parseFile = async (file, options) => {
|
|
12
|
+
const optsBoundParsers = options.parse.parsers.map(parser => {
|
|
13
|
+
const clonedParser = Object.create(parser);
|
|
14
|
+
return Object.assign(clonedParser, options.parse.parserOpts);
|
|
15
|
+
});
|
|
16
|
+
const parsers = await plugins.filter('canParse', [file, options], optsBoundParsers);
|
|
17
|
+
|
|
18
|
+
// we couldn't find any parser for this File
|
|
19
|
+
if (isEmpty(parsers)) {
|
|
20
|
+
throw new UnmatchedResolverError(file.uri);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const {
|
|
24
|
+
plugin,
|
|
25
|
+
result
|
|
26
|
+
} = await plugins.run('parse', [file, options], parsers);
|
|
27
|
+
|
|
28
|
+
// empty files handling
|
|
29
|
+
if (!plugin.allowEmpty && result.isEmpty) {
|
|
30
|
+
return Promise.reject(new ParseError(`Error while parsing file "${file.uri}". File is empty.`));
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new ParseError(`Error while parsing file "${file.uri}"`, {
|
|
35
|
+
cause: error
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Parses a file into ApiDOM.
|
|
42
|
+
*/
|
|
43
|
+
const parse = async (uri, options) => {
|
|
44
|
+
/**
|
|
45
|
+
* If the path is a filesystem path, then convert it to a URL.
|
|
46
|
+
*
|
|
47
|
+
* NOTE: According to the JSON Reference spec, these should already be URLs,
|
|
48
|
+
* but, in practice, many people use local filesystem paths instead.
|
|
49
|
+
* So we're being generous here and doing the conversion automatically.
|
|
50
|
+
* This is not intended to be a 100% bulletproof solution.
|
|
51
|
+
* If it doesn't work for your use-case, then use a URL instead.
|
|
52
|
+
*/
|
|
53
|
+
const file = new File({
|
|
54
|
+
uri: url.sanitize(url.stripHash(uri)),
|
|
55
|
+
mediaType: options.parse.mediaType
|
|
56
|
+
});
|
|
57
|
+
const data = await readFile(file, options);
|
|
58
|
+
return parseFile(new File({
|
|
59
|
+
...file,
|
|
60
|
+
data
|
|
61
|
+
}), options);
|
|
62
|
+
};
|
|
63
|
+
export default parse;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class Parser {
|
|
13
|
+
name;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether to allow "empty" files. This includes zero-byte files.
|
|
17
|
+
*/
|
|
18
|
+
allowEmpty;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether to generate source map during parsing.
|
|
22
|
+
*/
|
|
23
|
+
sourceMap;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* List of supported file extensions.
|
|
27
|
+
*/
|
|
28
|
+
fileExtensions;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* List of supported media types.
|
|
32
|
+
*/
|
|
33
|
+
mediaTypes;
|
|
34
|
+
constructor({
|
|
35
|
+
name,
|
|
36
|
+
allowEmpty = true,
|
|
37
|
+
sourceMap = false,
|
|
38
|
+
fileExtensions = [],
|
|
39
|
+
mediaTypes = []
|
|
40
|
+
}) {
|
|
41
|
+
this.name = name;
|
|
42
|
+
this.allowEmpty = allowEmpty;
|
|
43
|
+
this.sourceMap = sourceMap;
|
|
44
|
+
this.fileExtensions = fileExtensions;
|
|
45
|
+
this.mediaTypes = mediaTypes;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var _default = exports.default = Parser;
|