@speclynx/apidom-reference 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +109 -6
  3. package/dist/apidom-reference.browser.js +287 -69
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +25 -25
  6. package/src/configuration/saturated.cjs +4 -2
  7. package/src/configuration/saturated.mjs +5 -3
  8. package/src/dereference/strategies/arazzo-1/index.cjs +1 -1
  9. package/src/dereference/strategies/arazzo-1/index.mjs +1 -1
  10. package/src/dereference/strategies/asyncapi-2/index.cjs +1 -1
  11. package/src/dereference/strategies/asyncapi-2/index.mjs +1 -1
  12. package/src/dereference/strategies/openapi-2/index.cjs +1 -1
  13. package/src/dereference/strategies/openapi-2/index.mjs +1 -1
  14. package/src/dereference/strategies/openapi-3-0/index.cjs +1 -1
  15. package/src/dereference/strategies/openapi-3-0/index.mjs +1 -1
  16. package/src/parse/parsers/arazzo-json-1/index.cjs +12 -2
  17. package/src/parse/parsers/arazzo-json-1/index.mjs +14 -4
  18. package/src/parse/parsers/arazzo-json-1/source-description.cjs +177 -0
  19. package/src/parse/parsers/arazzo-json-1/source-description.mjs +171 -0
  20. package/src/parse/parsers/arazzo-yaml-1/index.cjs +12 -2
  21. package/src/parse/parsers/arazzo-yaml-1/index.mjs +12 -2
  22. package/src/resolve/util.cjs +1 -1
  23. package/src/resolve/util.mjs +1 -1
  24. package/types/apidom-reference.d.ts +4 -4
  25. package/types/parse/parsers/Parser.d.ts +3 -2
  26. package/types/parse/parsers/arazzo-json-1/index.d.ts +5 -1
  27. package/types/parse/parsers/arazzo-json-1/source-description.d.ts +13 -0
  28. package/types/parse/parsers/arazzo-yaml-1/index.d.ts +5 -1
  29. package/types/resolve/resolvers/Resolver.d.ts +3 -2
@@ -7,6 +7,7 @@ var _ramda = require("ramda");
7
7
  var _apidomParserAdapterArazzoYaml = require("@speclynx/apidom-parser-adapter-arazzo-yaml-1");
8
8
  var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
9
9
  var _Parser = _interopRequireDefault(require("../Parser.cjs"));
10
+ var _sourceDescription = require("../arazzo-json-1/source-description.cjs");
10
11
  /**
11
12
  * @public
12
13
  */
@@ -16,8 +17,10 @@ var _Parser = _interopRequireDefault(require("../Parser.cjs"));
16
17
  */
17
18
  class ArazzoYAML1Parser extends _Parser.default {
18
19
  refractorOpts;
20
+ parseFn;
19
21
  constructor(options) {
20
22
  const {
23
+ parseFn,
21
24
  fileExtensions = [],
22
25
  mediaTypes = _apidomParserAdapterArazzoYaml.mediaTypes,
23
26
  ...rest
@@ -28,6 +31,7 @@ class ArazzoYAML1Parser extends _Parser.default {
28
31
  fileExtensions,
29
32
  mediaTypes
30
33
  });
34
+ this.parseFn = parseFn;
31
35
  }
32
36
  async canParse(file) {
33
37
  const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
@@ -39,11 +43,17 @@ class ArazzoYAML1Parser extends _Parser.default {
39
43
  }
40
44
  return false;
41
45
  }
42
- async parse(file) {
46
+ async parse(file, options) {
43
47
  const source = file.toString();
44
48
  try {
45
49
  const parserOpts = (0, _ramda.pick)(['sourceMap', 'strict', 'refractorOpts'], this);
46
- return await (0, _apidomParserAdapterArazzoYaml.parse)(source, parserOpts);
50
+ const parseResult = await (0, _apidomParserAdapterArazzoYaml.parse)(source, parserOpts);
51
+ const shouldParseSourceDescriptions = options?.parse?.parserOpts?.[this.name]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
52
+ if (shouldParseSourceDescriptions) {
53
+ const sourceDescriptions = await _sourceDescription.parseSourceDescriptions.call(this, parseResult.api, file, options);
54
+ parseResult.push(...sourceDescriptions);
55
+ }
56
+ return parseResult;
47
57
  } catch (error) {
48
58
  throw new _ParserError.default(`Error parsing "${file.uri}"`, {
49
59
  cause: error
@@ -2,6 +2,7 @@ import { pick } from 'ramda';
2
2
  import { parse, mediaTypes as ArazzoYAML1MediaTypes, detect } from '@speclynx/apidom-parser-adapter-arazzo-yaml-1';
3
3
  import ParserError from "../../../errors/ParserError.mjs";
4
4
  import Parser from "../Parser.mjs";
5
+ import { parseSourceDescriptions } from "../arazzo-json-1/source-description.mjs";
5
6
  /**
6
7
  * @public
7
8
  */
@@ -10,8 +11,10 @@ import Parser from "../Parser.mjs";
10
11
  */
11
12
  class ArazzoYAML1Parser extends Parser {
12
13
  refractorOpts;
14
+ parseFn;
13
15
  constructor(options) {
14
16
  const {
17
+ parseFn,
15
18
  fileExtensions = [],
16
19
  mediaTypes = ArazzoYAML1MediaTypes,
17
20
  ...rest
@@ -22,6 +25,7 @@ class ArazzoYAML1Parser extends Parser {
22
25
  fileExtensions,
23
26
  mediaTypes
24
27
  });
28
+ this.parseFn = parseFn;
25
29
  }
26
30
  async canParse(file) {
27
31
  const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
@@ -33,11 +37,17 @@ class ArazzoYAML1Parser extends Parser {
33
37
  }
34
38
  return false;
35
39
  }
36
- async parse(file) {
40
+ async parse(file, options) {
37
41
  const source = file.toString();
38
42
  try {
39
43
  const parserOpts = pick(['sourceMap', 'strict', 'refractorOpts'], this);
40
- return await parse(source, parserOpts);
44
+ const parseResult = await parse(source, parserOpts);
45
+ const shouldParseSourceDescriptions = options?.parse?.parserOpts?.[this.name]?.sourceDescriptions ?? options?.parse?.parserOpts?.sourceDescriptions;
46
+ if (shouldParseSourceDescriptions) {
47
+ const sourceDescriptions = await parseSourceDescriptions.call(this, parseResult.api, file, options);
48
+ parseResult.push(...sourceDescriptions);
49
+ }
50
+ return parseResult;
41
51
  } catch (error) {
42
52
  throw new ParserError(`Error parsing "${file.uri}"`, {
43
53
  cause: error
@@ -26,7 +26,7 @@ const readFile = async (file, options) => {
26
26
  try {
27
27
  const {
28
28
  result
29
- } = await plugins.run('read', [file], resolvers);
29
+ } = await plugins.run('read', [file, options], resolvers);
30
30
  return result;
31
31
  } catch (error) {
32
32
  throw new _ResolveError.default(`Error while reading file "${file.uri}"`, {
@@ -20,7 +20,7 @@ export const readFile = async (file, options) => {
20
20
  try {
21
21
  const {
22
22
  result
23
- } = await plugins.run('read', [file], resolvers);
23
+ } = await plugins.run('read', [file, options], resolvers);
24
24
  return result;
25
25
  } catch (error) {
26
26
  throw new ResolveError(`Error while reading file "${file.uri}"`, {
@@ -344,8 +344,8 @@ export declare abstract class Parser {
344
344
  */
345
345
  mediaTypes: string[];
346
346
  constructor({ name, allowEmpty, sourceMap, strict, fileExtensions, mediaTypes, }: ParserOptions);
347
- abstract canParse(file: File_2): boolean | Promise<boolean>;
348
- abstract parse(file: File_2): ParseResultElement | Promise<ParseResultElement>;
347
+ abstract canParse(file: File_2, options?: ApiDOMReferenceOptions): boolean | Promise<boolean>;
348
+ abstract parse(file: File_2, options?: ApiDOMReferenceOptions): ParseResultElement | Promise<ParseResultElement>;
349
349
  }
350
350
 
351
351
  /**
@@ -457,8 +457,8 @@ export declare class ResolveError extends ApiDOMError {
457
457
  export declare abstract class Resolver {
458
458
  readonly name: string;
459
459
  constructor({ name }: ResolverOptions);
460
- abstract canRead(file: File_2): boolean;
461
- abstract read(file: File_2): Promise<Buffer>;
460
+ abstract canRead(file: File_2, options?: ApiDOMReferenceOptions): boolean;
461
+ abstract read(file: File_2, options?: ApiDOMReferenceOptions): Promise<Buffer>;
462
462
  }
463
463
 
464
464
  /**
@@ -1,5 +1,6 @@
1
1
  import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
2
  import File from '../../File.ts';
3
+ import type { ReferenceOptions } from '../../options/index.ts';
3
4
  /**
4
5
  * @public
5
6
  */
@@ -37,7 +38,7 @@ declare abstract class Parser {
37
38
  */
38
39
  mediaTypes: string[];
39
40
  constructor({ name, allowEmpty, sourceMap, strict, fileExtensions, mediaTypes, }: ParserOptions);
40
- abstract canParse(file: File): boolean | Promise<boolean>;
41
- abstract parse(file: File): ParseResultElement | Promise<ParseResultElement>;
41
+ abstract canParse(file: File, options?: ReferenceOptions): boolean | Promise<boolean>;
42
+ abstract parse(file: File, options?: ReferenceOptions): ParseResultElement | Promise<ParseResultElement>;
42
43
  }
43
44
  export default Parser;
@@ -1,20 +1,24 @@
1
1
  import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
2
  import Parser, { ParserOptions } from '../Parser.ts';
3
3
  import File from '../../../File.ts';
4
+ import type { ReferenceOptions } from '../../../options/index.ts';
5
+ import type ParseFn from '../../index.ts';
4
6
  export type { default as Parser, ParserOptions } from '../Parser.ts';
5
7
  export type { default as File, FileOptions } from '../../../File.ts';
6
8
  /**
7
9
  * @public
8
10
  */
9
11
  export interface ArazzoJSON1ParserOptions extends Omit<ParserOptions, 'name'> {
12
+ readonly parseFn?: typeof ParseFn;
10
13
  }
11
14
  /**
12
15
  * @public
13
16
  */
14
17
  declare class ArazzoJSON1Parser extends Parser {
15
18
  refractorOpts: object;
19
+ parseFn?: typeof ParseFn;
16
20
  constructor(options?: ArazzoJSON1ParserOptions);
17
21
  canParse(file: File): Promise<boolean>;
18
- parse(file: File): Promise<ParseResultElement>;
22
+ parse(file: File, options?: ReferenceOptions): Promise<ParseResultElement>;
19
23
  }
20
24
  export default ArazzoJSON1Parser;
@@ -0,0 +1,13 @@
1
+ import { Element, ParseResultElement } from '@speclynx/apidom-datamodel';
2
+ import File from '../../../File.ts';
3
+ import type { ReferenceOptions } from '../../../options/index.ts';
4
+ import type ParseFn from '../../index.ts';
5
+ /**
6
+ * Shared function for parsing source descriptions.
7
+ * Call with `.call(this, ...)` where `this` has `name` and `parseFn` properties.
8
+ * @public
9
+ */
10
+ export declare function parseSourceDescriptions(this: {
11
+ name: string;
12
+ parseFn?: typeof ParseFn;
13
+ }, api: Element | undefined, file: File, options: ReferenceOptions): Promise<ParseResultElement[]>;
@@ -1,20 +1,24 @@
1
1
  import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
2
  import Parser, { ParserOptions } from '../Parser.ts';
3
3
  import File from '../../../File.ts';
4
+ import type { ReferenceOptions } from '../../../options/index.ts';
5
+ import type ParseFn from '../../index.ts';
4
6
  export type { default as Parser, ParserOptions } from '../Parser.ts';
5
7
  export type { default as File, FileOptions } from '../../../File.ts';
6
8
  /**
7
9
  * @public
8
10
  */
9
11
  export interface ArazzoYAML1ParserOptions extends Omit<ParserOptions, 'name'> {
12
+ readonly parseFn?: typeof ParseFn;
10
13
  }
11
14
  /**
12
15
  * @public
13
16
  */
14
17
  declare class ArazzoYAML1Parser extends Parser {
15
18
  refractorOpts: object;
19
+ parseFn?: typeof ParseFn;
16
20
  constructor(options?: ArazzoYAML1ParserOptions);
17
21
  canParse(file: File): Promise<boolean>;
18
- parse(file: File): Promise<ParseResultElement>;
22
+ parse(file: File, options?: ReferenceOptions): Promise<ParseResultElement>;
19
23
  }
20
24
  export default ArazzoYAML1Parser;
@@ -1,4 +1,5 @@
1
1
  import File from '../../File.ts';
2
+ import type { ReferenceOptions } from '../../options/index.ts';
2
3
  /**
3
4
  * @public
4
5
  */
@@ -11,7 +12,7 @@ export interface ResolverOptions {
11
12
  declare abstract class Resolver {
12
13
  readonly name: string;
13
14
  constructor({ name }: ResolverOptions);
14
- abstract canRead(file: File): boolean;
15
- abstract read(file: File): Promise<Buffer>;
15
+ abstract canRead(file: File, options?: ReferenceOptions): boolean;
16
+ abstract read(file: File, options?: ReferenceOptions): Promise<Buffer>;
16
17
  }
17
18
  export default Resolver;