@speclynx/apidom-reference 4.0.3 → 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.
Files changed (95) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/apidom-reference.browser.js +15 -15
  3. package/dist/apidom-reference.browser.min.js +1 -1
  4. package/package.json +27 -26
  5. package/src/File.ts +0 -63
  6. package/src/Reference.ts +0 -38
  7. package/src/ReferenceSet.ts +0 -73
  8. package/src/bundle/index.ts +0 -57
  9. package/src/bundle/strategies/BundleStrategy.ts +0 -27
  10. package/src/bundle/strategies/openapi-3-1/index.ts +0 -57
  11. package/src/configuration/empty.ts +0 -1
  12. package/src/configuration/saturated.ts +0 -72
  13. package/src/dereference/index.ts +0 -96
  14. package/src/dereference/strategies/DereferenceStrategy.ts +0 -27
  15. package/src/dereference/strategies/apidom/index.ts +0 -128
  16. package/src/dereference/strategies/apidom/selectors/element-id.ts +0 -48
  17. package/src/dereference/strategies/apidom/visitor.ts +0 -316
  18. package/src/dereference/strategies/arazzo-1/index.ts +0 -158
  19. package/src/dereference/strategies/arazzo-1/selectors/$anchor.ts +0 -9
  20. package/src/dereference/strategies/arazzo-1/selectors/uri.ts +0 -5
  21. package/src/dereference/strategies/arazzo-1/source-descriptions.ts +0 -317
  22. package/src/dereference/strategies/arazzo-1/util.ts +0 -33
  23. package/src/dereference/strategies/arazzo-1/visitor.ts +0 -574
  24. package/src/dereference/strategies/asyncapi-2/index.ts +0 -133
  25. package/src/dereference/strategies/asyncapi-2/visitor.ts +0 -589
  26. package/src/dereference/strategies/openapi-2/index.ts +0 -136
  27. package/src/dereference/strategies/openapi-2/visitor.ts +0 -745
  28. package/src/dereference/strategies/openapi-3-0/index.ts +0 -134
  29. package/src/dereference/strategies/openapi-3-0/visitor.ts +0 -760
  30. package/src/dereference/strategies/openapi-3-1/index.ts +0 -141
  31. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts +0 -64
  32. package/src/dereference/strategies/openapi-3-1/selectors/uri.ts +0 -54
  33. package/src/dereference/strategies/openapi-3-1/util.ts +0 -83
  34. package/src/dereference/strategies/openapi-3-1/visitor.ts +0 -1053
  35. package/src/dereference/util.ts +0 -29
  36. package/src/errors/BundleError.ts +0 -8
  37. package/src/errors/DereferenceError.ts +0 -8
  38. package/src/errors/EvaluationElementIdError.ts +0 -8
  39. package/src/errors/EvaluationJsonSchema$anchorError.ts +0 -8
  40. package/src/errors/EvaluationJsonSchemaUriError.ts +0 -8
  41. package/src/errors/InvalidJsonSchema$anchorError.ts +0 -12
  42. package/src/errors/JsonSchema$anchorError.ts +0 -8
  43. package/src/errors/JsonSchemaUriError.ts +0 -8
  44. package/src/errors/MaximumBundleDepthError.ts +0 -8
  45. package/src/errors/MaximumDereferenceDepthError.ts +0 -8
  46. package/src/errors/MaximumResolveDepthError.ts +0 -8
  47. package/src/errors/ParseError.ts +0 -8
  48. package/src/errors/ParserError.ts +0 -8
  49. package/src/errors/PluginError.ts +0 -15
  50. package/src/errors/ResolveError.ts +0 -8
  51. package/src/errors/ResolverError.ts +0 -8
  52. package/src/errors/UnmatchedBundleStrategyError.ts +0 -8
  53. package/src/errors/UnmatchedDereferenceStrategyError.ts +0 -8
  54. package/src/errors/UnmatchedParserError.ts +0 -8
  55. package/src/errors/UnmatchedResolveStrategyError.ts +0 -8
  56. package/src/errors/UnmatchedResolverError.ts +0 -8
  57. package/src/errors/UnresolvableReferenceError.ts +0 -8
  58. package/src/index.ts +0 -135
  59. package/src/options/index.ts +0 -239
  60. package/src/options/util.ts +0 -22
  61. package/src/parse/index.ts +0 -67
  62. package/src/parse/parsers/Parser.ts +0 -80
  63. package/src/parse/parsers/apidom-json/index.ts +0 -78
  64. package/src/parse/parsers/arazzo-json-1/index.ts +0 -76
  65. package/src/parse/parsers/arazzo-json-1/source-descriptions.ts +0 -280
  66. package/src/parse/parsers/arazzo-yaml-1/index.ts +0 -77
  67. package/src/parse/parsers/arazzo-yaml-1/source-descriptions.ts +0 -16
  68. package/src/parse/parsers/asyncapi-json-2/index.ts +0 -58
  69. package/src/parse/parsers/asyncapi-yaml-2/index.ts +0 -58
  70. package/src/parse/parsers/binary/index-browser.ts +0 -60
  71. package/src/parse/parsers/binary/index-node.ts +0 -57
  72. package/src/parse/parsers/json/index.ts +0 -52
  73. package/src/parse/parsers/openapi-json-2/index.ts +0 -58
  74. package/src/parse/parsers/openapi-json-3-0/index.ts +0 -59
  75. package/src/parse/parsers/openapi-json-3-1/index.ts +0 -59
  76. package/src/parse/parsers/openapi-yaml-2/index.ts +0 -58
  77. package/src/parse/parsers/openapi-yaml-3-0/index.ts +0 -59
  78. package/src/parse/parsers/openapi-yaml-3-1/index.ts +0 -59
  79. package/src/parse/parsers/yaml-1-2/index.ts +0 -60
  80. package/src/resolve/index.ts +0 -75
  81. package/src/resolve/resolvers/HTTPResolver.ts +0 -58
  82. package/src/resolve/resolvers/Resolver.ts +0 -25
  83. package/src/resolve/resolvers/file/index-browser.ts +0 -24
  84. package/src/resolve/resolvers/file/index-node.ts +0 -55
  85. package/src/resolve/resolvers/http-axios/cache/MemoryCache.ts +0 -46
  86. package/src/resolve/resolvers/http-axios/index.ts +0 -130
  87. package/src/resolve/strategies/ResolveStrategy.ts +0 -26
  88. package/src/resolve/strategies/apidom/index.ts +0 -78
  89. package/src/resolve/strategies/asyncapi-2/index.ts +0 -78
  90. package/src/resolve/strategies/openapi-2/index.ts +0 -78
  91. package/src/resolve/strategies/openapi-3-0/index.ts +0 -78
  92. package/src/resolve/strategies/openapi-3-1/index.ts +0 -78
  93. package/src/resolve/util.ts +0 -39
  94. package/src/util/plugins.ts +0 -37
  95. package/src/util/url.ts +0 -285
@@ -1,60 +0,0 @@
1
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
- import {
3
- parse,
4
- mediaTypes as YAMLMediaTypes,
5
- detect,
6
- } from '@speclynx/apidom-parser-adapter-yaml-1-2';
7
-
8
- import ParserError from '../../../errors/ParserError.ts';
9
- import Parser, { ParserOptions } from '../Parser.ts';
10
- import File from '../../../File.ts';
11
-
12
- export type { default as Parser, ParserOptions } from '../Parser.ts';
13
- export type { default as File, FileOptions } from '../../../File.ts';
14
-
15
- /**
16
- * @public
17
- */
18
- export interface YAMLParserOptions extends Omit<ParserOptions, 'name'> {}
19
-
20
- /**
21
- * @public
22
- */
23
- class YAML1Parser extends Parser {
24
- public refractorOpts!: object;
25
-
26
- constructor(options?: YAMLParserOptions) {
27
- const { fileExtensions = [], mediaTypes = YAMLMediaTypes, ...rest } = options ?? {};
28
-
29
- super({ ...rest, name: 'yaml-1-2', fileExtensions, mediaTypes });
30
- }
31
-
32
- async canParse(file: File): Promise<boolean> {
33
- const hasSupportedFileExtension =
34
- this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
35
- const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
36
-
37
- if (!hasSupportedFileExtension) return false;
38
- if (hasSupportedMediaType) return true;
39
- if (!hasSupportedMediaType) {
40
- return detect(file.toString());
41
- }
42
- return false;
43
- }
44
-
45
- async parse(file: File): Promise<ParseResultElement> {
46
- const source = file.toString();
47
-
48
- try {
49
- return await parse(source, {
50
- sourceMap: this.sourceMap,
51
- style: this.style,
52
- strict: this.strict,
53
- });
54
- } catch (error: unknown) {
55
- throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
56
- }
57
- }
58
- }
59
-
60
- export default YAML1Parser;
@@ -1,75 +0,0 @@
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;
@@ -1,58 +0,0 @@
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;
@@ -1,25 +0,0 @@
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;
@@ -1,24 +0,0 @@
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;
@@ -1,55 +0,0 @@
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;
@@ -1,46 +0,0 @@
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;
@@ -1,130 +0,0 @@
1
- import { omit } from 'ramda';
2
- import { ensureArray, isPlainObject } from 'ramda-adjunct';
3
- import axios, { Axios, AxiosInstance, CreateAxiosDefaults } from 'axios';
4
-
5
- import HTTPResolver, { HTTPResolverOptions } from '../HTTPResolver.ts';
6
- import MemoryCache from './cache/MemoryCache.ts';
7
- import File from '../../../File.ts';
8
- import ResolverError from '../../../errors/ResolverError.ts';
9
- import * as url from '../../../util/url.ts';
10
-
11
- export type {
12
- default as HTTPResolver,
13
- HTTPResolverOptions,
14
- CacheOptions,
15
- } from '../HTTPResolver.ts';
16
- export type { default as Resolver, ResolverOptions } from '../Resolver.ts';
17
- export type { default as File, FileOptions } from '../../../File.ts';
18
-
19
- /**
20
- * @public
21
- */
22
- export interface HTTPResolverAxiosConfig extends CreateAxiosDefaults {
23
- interceptors?: Axios['interceptors'];
24
- }
25
-
26
- /**
27
- * @public
28
- */
29
- export interface HTTPResolverAxiosOptions extends Omit<HTTPResolverOptions, 'name'> {
30
- readonly axiosConfig?: HTTPResolverAxiosConfig;
31
- }
32
-
33
- /**
34
- * @public
35
- */
36
- class HTTPResolverAxios extends HTTPResolver {
37
- public axiosConfig: HTTPResolverAxiosConfig = {};
38
-
39
- protected axiosInstance!: AxiosInstance;
40
-
41
- protected previousAxiosConfig!: HTTPResolverAxiosConfig;
42
-
43
- protected cacheStore: MemoryCache<Buffer>;
44
-
45
- protected previousCache!: typeof this.cache;
46
-
47
- constructor(options?: HTTPResolverAxiosOptions) {
48
- const { axiosConfig = {}, ...rest } = options ?? {};
49
-
50
- super({ ...rest, name: 'http-axios' });
51
- this.axiosConfig = axiosConfig;
52
- this.cacheStore = new MemoryCache(isPlainObject(this.cache) ? this.cache : {});
53
- }
54
-
55
- getHttpClient(): AxiosInstance {
56
- if (this.axiosInstance === undefined || this.previousAxiosConfig !== this.axiosConfig) {
57
- const config = omit(['interceptors'], this.axiosConfig);
58
- const { interceptors } = this.axiosConfig;
59
-
60
- this.axiosInstance = axios.create({
61
- timeout: this.timeout,
62
- maxRedirects: this.redirects,
63
- withCredentials: this.withCredentials,
64
- responseType: 'arraybuffer',
65
- ...config,
66
- });
67
-
68
- // settings up request interceptors
69
- if (Array.isArray(interceptors?.request)) {
70
- interceptors.request.forEach((requestInterceptor) => {
71
- this.axiosInstance.interceptors.request.use(...ensureArray(requestInterceptor));
72
- });
73
- }
74
-
75
- // settings up response interceptors
76
- if (Array.isArray(interceptors?.response)) {
77
- interceptors.response.forEach((responseInterceptor: any) => {
78
- this.axiosInstance.interceptors.response.use(...ensureArray(responseInterceptor));
79
- });
80
- }
81
-
82
- this.previousAxiosConfig = this.axiosConfig;
83
- }
84
-
85
- return this.axiosInstance;
86
- }
87
-
88
- /**
89
- * Ensures cacheStore is config-isolated for cloned resolvers.
90
- * When a resolver is cloned via Object.create (in readFile), the clone inherits
91
- * cacheStore from the prototype. Object.create(cacheStore) creates a view that
92
- * shares the underlying store Map but allows isolated config (maxEntries, maxStaleAge)
93
- * via own properties set by Object.assign.
94
- */
95
- protected getCacheStore(): MemoryCache<Buffer> {
96
- if (this.previousCache !== this.cache) {
97
- if (!Object.hasOwn(this, 'cacheStore')) {
98
- this.cacheStore = Object.create(this.cacheStore) as MemoryCache<Buffer>;
99
- }
100
- if (isPlainObject(this.cache)) {
101
- Object.assign(this.cacheStore, this.cache);
102
- }
103
-
104
- this.previousCache = this.cache;
105
- }
106
-
107
- return this.cacheStore;
108
- }
109
-
110
- async read(file: File): Promise<Buffer> {
111
- const uri = url.stripHash(file.uri);
112
- const cacheStore = this.cache ? this.getCacheStore() : undefined;
113
-
114
- // return cached content if available
115
- const cached = cacheStore?.get(uri);
116
- if (cached !== undefined) return cached;
117
-
118
- const client: AxiosInstance = this.getHttpClient();
119
-
120
- try {
121
- const response = await client.get<Buffer>(uri);
122
- cacheStore?.set(uri, response.data);
123
- return response.data;
124
- } catch (error: unknown) {
125
- throw new ResolverError(`Error downloading "${file.uri}"`, { cause: error });
126
- }
127
- }
128
- }
129
-
130
- export default HTTPResolverAxios;
@@ -1,26 +0,0 @@
1
- import File from '../../File.ts';
2
- import ReferenceSet from '../../ReferenceSet.ts';
3
- import type { ReferenceOptions } from '../../options/index.ts';
4
-
5
- /**
6
- * @public
7
- */
8
- export interface ResolveStrategyOptions {
9
- readonly name: string;
10
- }
11
-
12
- /**
13
- * @public
14
- */
15
- abstract class ResolveStrategy {
16
- public readonly name: string;
17
-
18
- constructor({ name }: ResolveStrategyOptions) {
19
- this.name = name;
20
- }
21
-
22
- abstract canResolve(file: File, options: ReferenceOptions): boolean;
23
- abstract resolve(file: File, options: ReferenceOptions): Promise<ReferenceSet>;
24
- }
25
-
26
- export default ResolveStrategy;
@@ -1,78 +0,0 @@
1
- import ResolveStrategy, { ResolveStrategyOptions } from '../ResolveStrategy.ts';
2
- import ReferenceSet from '../../../ReferenceSet.ts';
3
- import File from '../../../File.ts';
4
- import { merge as mergeOptions } from '../../../options/util.ts';
5
- import UnmatchedDereferenceStrategyError from '../../../errors/UnmatchedDereferenceStrategyError.ts';
6
- import type { ReferenceOptions } from '../../../options/index.ts';
7
-
8
- export type { default as ResolveStrategy, ResolveStrategyOptions } from '../ResolveStrategy.ts';
9
- export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
10
- export type { default as File, FileOptions } from '../../../File.ts';
11
- export type {
12
- ReferenceOptions as ApiDOMReferenceOptions,
13
- ReferenceBundleOptions as ApiDOMReferenceBundleOptions,
14
- ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions,
15
- ReferenceParseOptions as ApiDOMReferenceParseOptions,
16
- ReferenceResolveOptions as ApiDOMReferenceResolveOptions,
17
- } from '../../../options/index.ts';
18
- export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
19
- export type { default as Resolver, ResolverOptions } from '../../resolvers/Resolver.ts';
20
- export type {
21
- default as DereferenceStrategy,
22
- DereferenceStrategyOptions,
23
- } from '../../../dereference/strategies/DereferenceStrategy.ts';
24
- export type {
25
- default as BundleStrategy,
26
- BundleStrategyOptions,
27
- } from '../../../bundle/strategies/BundleStrategy.ts';
28
- export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
29
-
30
- /**
31
- * @public
32
- */
33
- export interface ApiDOMResolveStrategyOptions extends Omit<ResolveStrategyOptions, 'name'> {}
34
-
35
- /**
36
- * @public
37
- */
38
- class ApiDOMResolveStrategy extends ResolveStrategy {
39
- constructor(options?: ApiDOMResolveStrategyOptions) {
40
- super({ ...(options ?? {}), name: 'apidom' });
41
- }
42
-
43
- canResolve(file: File, options: ReferenceOptions): boolean {
44
- const dereferenceStrategy = options.dereference.strategies.find(
45
- (strategy) => strategy.name === 'apidom',
46
- );
47
-
48
- if (dereferenceStrategy === undefined) {
49
- return false;
50
- }
51
-
52
- return dereferenceStrategy.canDereference(file, options);
53
- }
54
-
55
- async resolve(file: File, options: ReferenceOptions) {
56
- const dereferenceStrategy = options.dereference.strategies.find(
57
- (strategy) => strategy.name === 'apidom',
58
- );
59
-
60
- if (dereferenceStrategy === undefined) {
61
- throw new UnmatchedDereferenceStrategyError(
62
- `"apidom" resolve strategy requires "apidom" dereference strategy to be configured for file "${file.uri}"`,
63
- );
64
- }
65
-
66
- const refSet = new ReferenceSet();
67
- const mergedOptions = mergeOptions(options, {
68
- resolve: { internal: false },
69
- dereference: { refSet },
70
- });
71
-
72
- await dereferenceStrategy.dereference(file, mergedOptions);
73
-
74
- return refSet;
75
- }
76
- }
77
-
78
- export default ApiDOMResolveStrategy;
@@ -1,78 +0,0 @@
1
- import ResolveStrategy, { ResolveStrategyOptions } from '../ResolveStrategy.ts';
2
- import ReferenceSet from '../../../ReferenceSet.ts';
3
- import File from '../../../File.ts';
4
- import { merge as mergeOptions } from '../../../options/util.ts';
5
- import UnmatchedDereferenceStrategyError from '../../../errors/UnmatchedDereferenceStrategyError.ts';
6
- import type { ReferenceOptions } from '../../../options/index.ts';
7
-
8
- export type { default as ResolveStrategy, ResolveStrategyOptions } from '../ResolveStrategy.ts';
9
- export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
10
- export type { default as File, FileOptions } from '../../../File.ts';
11
- export type {
12
- ReferenceOptions as ApiDOMReferenceOptions,
13
- ReferenceBundleOptions as ApiDOMReferenceBundleOptions,
14
- ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions,
15
- ReferenceParseOptions as ApiDOMReferenceParseOptions,
16
- ReferenceResolveOptions as ApiDOMReferenceResolveOptions,
17
- } from '../../../options/index.ts';
18
- export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
19
- export type { default as Resolver, ResolverOptions } from '../../resolvers/Resolver.ts';
20
- export type {
21
- default as DereferenceStrategy,
22
- DereferenceStrategyOptions,
23
- } from '../../../dereference/strategies/DereferenceStrategy.ts';
24
- export type {
25
- default as BundleStrategy,
26
- BundleStrategyOptions,
27
- } from '../../../bundle/strategies/BundleStrategy.ts';
28
- export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
29
-
30
- /**
31
- * @public
32
- */
33
- export interface AsyncAPI2ResolveStrategyOptions extends Omit<ResolveStrategyOptions, 'name'> {}
34
-
35
- /**
36
- * @public
37
- */
38
- class AsyncAPI2ResolveStrategy extends ResolveStrategy {
39
- constructor(options?: AsyncAPI2ResolveStrategyOptions) {
40
- super({ ...(options ?? {}), name: 'asyncapi-2' });
41
- }
42
-
43
- canResolve(file: File, options: ReferenceOptions) {
44
- const dereferenceStrategy = options.dereference.strategies.find(
45
- (strategy) => strategy.name === 'asyncapi-2',
46
- );
47
-
48
- if (dereferenceStrategy === undefined) {
49
- return false;
50
- }
51
-
52
- return dereferenceStrategy.canDereference(file, options);
53
- }
54
-
55
- async resolve(file: File, options: ReferenceOptions) {
56
- const dereferenceStrategy = options.dereference.strategies.find(
57
- (strategy) => strategy.name === 'asyncapi-2',
58
- );
59
-
60
- if (dereferenceStrategy === undefined) {
61
- throw new UnmatchedDereferenceStrategyError(
62
- `"asyncapi-2" resolve strategy requires "asyncapi-2" dereference strategy to be configured for file "${file.uri}"`,
63
- );
64
- }
65
-
66
- const refSet = new ReferenceSet();
67
- const mergedOptions = mergeOptions(options, {
68
- resolve: { internal: false },
69
- dereference: { refSet },
70
- });
71
-
72
- await dereferenceStrategy.dereference(file, mergedOptions);
73
-
74
- return refSet;
75
- }
76
- }
77
-
78
- export default AsyncAPI2ResolveStrategy;