@speclynx/apidom-parser 3.2.1 → 4.0.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 CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.0.1](https://github.com/speclynx/apidom/compare/v4.0.0...v4.0.1) (2026-03-11)
7
+
8
+ **Note:** Version bump only for package @speclynx/apidom-parser
9
+
10
+ # [4.0.0](https://github.com/speclynx/apidom/compare/v3.2.1...v4.0.0) (2026-03-11)
11
+
12
+ **Note:** Version bump only for package @speclynx/apidom-parser
13
+
6
14
  ## [3.2.1](https://github.com/speclynx/apidom/compare/v3.2.0...v3.2.1) (2026-03-09)
7
15
 
8
16
  **Note:** Version bump only for package @speclynx/apidom-parser
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-parser",
3
- "version": "3.2.1",
3
+ "version": "4.0.1",
4
4
  "description": "Parser consumes parser adapters and provides unified API for parsing.",
5
5
  "keywords": [
6
6
  "apidom",
@@ -59,9 +59,9 @@
59
59
  "license": "Apache-2.0",
60
60
  "dependencies": {
61
61
  "@babel/runtime-corejs3": "^7.28.4",
62
- "@speclynx/apidom-core": "3.2.1",
63
- "@speclynx/apidom-datamodel": "3.2.1",
64
- "@speclynx/apidom-error": "3.2.1",
62
+ "@speclynx/apidom-core": "4.0.1",
63
+ "@speclynx/apidom-datamodel": "4.0.1",
64
+ "@speclynx/apidom-error": "4.0.1",
65
65
  "ramda": "~0.32.0",
66
66
  "ramda-adjunct": "^6.0.0"
67
67
  },
@@ -75,5 +75,5 @@
75
75
  "README.md",
76
76
  "CHANGELOG.md"
77
77
  ],
78
- "gitHead": "83a1e97089ef29134e41ff7cacd351973114ea5b"
78
+ "gitHead": "223132a9b00081ca04842efc2736a491f7876f44"
79
79
  }
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = void 0;
5
- var _apidomError = require("@speclynx/apidom-error");
6
- /**
7
- * @public
8
- */
9
-
10
- /**
11
- * @public
12
- */
13
- class ParserError extends _apidomError.ApiDOMStructuredError {
14
- source;
15
- parserOptions;
16
- constructor(message, structuredOptions) {
17
- super(message, structuredOptions);
18
- if (typeof structuredOptions !== 'undefined') {
19
- this.source = structuredOptions.source;
20
- this.parserOptions = structuredOptions.parserOptions;
21
- }
22
- }
23
- }
24
- var _default = exports.default = ParserError;
@@ -1,21 +0,0 @@
1
- import { ApiDOMStructuredError } from '@speclynx/apidom-error';
2
-
3
- /**
4
- * @public
5
- */
6
-
7
- /**
8
- * @public
9
- */
10
- class ParserError extends ApiDOMStructuredError {
11
- source;
12
- parserOptions;
13
- constructor(message, structuredOptions) {
14
- super(message, structuredOptions);
15
- if (typeof structuredOptions !== 'undefined') {
16
- this.source = structuredOptions.source;
17
- this.parserOptions = structuredOptions.parserOptions;
18
- }
19
- }
20
- }
21
- export default ParserError;
package/src/parser.cjs DELETED
@@ -1,117 +0,0 @@
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 _ramda = require("ramda");
7
- var _ramdaAdjunct = require("ramda-adjunct");
8
- var _apidomCore = require("@speclynx/apidom-core");
9
- var _ParserError = _interopRequireDefault(require("./errors/ParserError.cjs"));
10
- exports.ParserError = _ParserError.default;
11
- /**
12
- * @public
13
- */
14
-
15
- /**
16
- * @public
17
- */
18
-
19
- /**
20
- * @public
21
- */
22
-
23
- /**
24
- * @public
25
- */
26
-
27
- /**
28
- * @public
29
- */
30
- class ApiDOMParser {
31
- adapters = [];
32
- async detectAdapterCandidates(source, options = {}) {
33
- const candidates = [];
34
- for (const adapter of this.adapters) {
35
- if ((0, _ramdaAdjunct.isFunction)(adapter.detect) && (await adapter.detect(source, options))) {
36
- candidates.push(adapter);
37
- }
38
- }
39
- return candidates;
40
- }
41
- async findAdapter(source, options = {}) {
42
- if ((0, _ramdaAdjunct.isString)(options.mediaType)) {
43
- return this.adapters.find(adapter => {
44
- if (!(0, _ramdaAdjunct.isArray)(adapter.mediaTypes)) return false;
45
- return adapter.mediaTypes.includes(options.mediaType);
46
- });
47
- }
48
- const candidates = await this.detectAdapterCandidates(source, options);
49
- return (0, _ramda.head)(candidates);
50
- }
51
- use(adapter) {
52
- this.adapters.push(adapter);
53
- return this;
54
- }
55
- async findNamespace(source, options = {}) {
56
- const adapter = await this.findAdapter(source, options);
57
- return adapter?.namespace;
58
- }
59
- async findMediaType(source) {
60
- const adapter = await this.findAdapter(source, {});
61
- if (typeof adapter === 'undefined') {
62
- return new _apidomCore.MediaTypes().unknownMediaType;
63
- }
64
- if (typeof adapter.mediaTypes === 'undefined') {
65
- return new _apidomCore.MediaTypes().unknownMediaType;
66
- }
67
- if (typeof adapter.detectionRegExp === 'undefined') {
68
- return adapter.mediaTypes.latest();
69
- }
70
- const {
71
- detectionRegExp
72
- } = adapter;
73
- const matches = source.match(detectionRegExp);
74
- if (matches === null) {
75
- return new _apidomCore.MediaTypes().unknownMediaType;
76
- }
77
- const {
78
- groups
79
- } = matches;
80
- const version = groups?.version || groups?.version_json || groups?.version_yaml;
81
- const format = groups?.version_json ? 'json' : groups?.version_yaml ? 'yaml' : 'generic';
82
- if (typeof version === 'undefined') {
83
- return adapter.mediaTypes.latest();
84
- }
85
-
86
- // @ts-ignore
87
- return adapter.mediaTypes.findBy(version, format);
88
- }
89
- async parse(source, options = {}) {
90
- let adapter;
91
- try {
92
- adapter = await this.findAdapter(source, options);
93
- } catch (error) {
94
- throw new _ParserError.default('Encountered an unexpected error while matching parser adapters against the source.', {
95
- source,
96
- parserOptions: options,
97
- cause: error
98
- });
99
- }
100
- if ((0, _ramdaAdjunct.isUndefined)(adapter)) {
101
- throw new _ParserError.default('Source did not match any registered parsers', {
102
- source,
103
- parserOptions: options
104
- });
105
- }
106
- try {
107
- return adapter.parse(source, options);
108
- } catch (error) {
109
- throw new _ParserError.default('Parsing encountered an unexpected error.', {
110
- source,
111
- parserOptions: options,
112
- cause: error
113
- });
114
- }
115
- }
116
- }
117
- var _default = exports.default = ApiDOMParser;
package/src/parser.mjs DELETED
@@ -1,113 +0,0 @@
1
- import { head } from 'ramda';
2
- import { isArray, isFunction, isString, isUndefined } from 'ramda-adjunct';
3
- import { MediaTypes } from '@speclynx/apidom-core';
4
- import ParserError from "./errors/ParserError.mjs";
5
- export { ParserError };
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
- class ApiDOMParser {
27
- adapters = [];
28
- async detectAdapterCandidates(source, options = {}) {
29
- const candidates = [];
30
- for (const adapter of this.adapters) {
31
- if (isFunction(adapter.detect) && (await adapter.detect(source, options))) {
32
- candidates.push(adapter);
33
- }
34
- }
35
- return candidates;
36
- }
37
- async findAdapter(source, options = {}) {
38
- if (isString(options.mediaType)) {
39
- return this.adapters.find(adapter => {
40
- if (!isArray(adapter.mediaTypes)) return false;
41
- return adapter.mediaTypes.includes(options.mediaType);
42
- });
43
- }
44
- const candidates = await this.detectAdapterCandidates(source, options);
45
- return head(candidates);
46
- }
47
- use(adapter) {
48
- this.adapters.push(adapter);
49
- return this;
50
- }
51
- async findNamespace(source, options = {}) {
52
- const adapter = await this.findAdapter(source, options);
53
- return adapter?.namespace;
54
- }
55
- async findMediaType(source) {
56
- const adapter = await this.findAdapter(source, {});
57
- if (typeof adapter === 'undefined') {
58
- return new MediaTypes().unknownMediaType;
59
- }
60
- if (typeof adapter.mediaTypes === 'undefined') {
61
- return new MediaTypes().unknownMediaType;
62
- }
63
- if (typeof adapter.detectionRegExp === 'undefined') {
64
- return adapter.mediaTypes.latest();
65
- }
66
- const {
67
- detectionRegExp
68
- } = adapter;
69
- const matches = source.match(detectionRegExp);
70
- if (matches === null) {
71
- return new MediaTypes().unknownMediaType;
72
- }
73
- const {
74
- groups
75
- } = matches;
76
- const version = groups?.version || groups?.version_json || groups?.version_yaml;
77
- const format = groups?.version_json ? 'json' : groups?.version_yaml ? 'yaml' : 'generic';
78
- if (typeof version === 'undefined') {
79
- return adapter.mediaTypes.latest();
80
- }
81
-
82
- // @ts-ignore
83
- return adapter.mediaTypes.findBy(version, format);
84
- }
85
- async parse(source, options = {}) {
86
- let adapter;
87
- try {
88
- adapter = await this.findAdapter(source, options);
89
- } catch (error) {
90
- throw new ParserError('Encountered an unexpected error while matching parser adapters against the source.', {
91
- source,
92
- parserOptions: options,
93
- cause: error
94
- });
95
- }
96
- if (isUndefined(adapter)) {
97
- throw new ParserError('Source did not match any registered parsers', {
98
- source,
99
- parserOptions: options
100
- });
101
- }
102
- try {
103
- return adapter.parse(source, options);
104
- } catch (error) {
105
- throw new ParserError('Parsing encountered an unexpected error.', {
106
- source,
107
- parserOptions: options,
108
- cause: error
109
- });
110
- }
111
- }
112
- }
113
- export default ApiDOMParser;