@speclynx/apidom-parser-adapter-asyncapi-yaml-2 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/package.json +7 -8
- package/src/adapter.cjs +53 -0
- package/src/adapter.mjs +45 -0
- package/src/adapter.ts +59 -0
- package/src/media-types.cjs +10 -0
- package/src/media-types.mjs +7 -0
- package/src/media-types.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.3](https://github.com/speclynx/apidom/compare/v4.0.2...v4.0.3) (2026-03-11)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **release:** fix v4.0.2 failed release ([b4dc1c4](https://github.com/speclynx/apidom/commit/b4dc1c48e8d9b2986a70e49b5554eb0a166d7528))
|
|
11
|
+
|
|
12
|
+
## [4.0.2](https://github.com/speclynx/apidom/compare/v4.0.1...v4.0.2) (2026-03-11)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @speclynx/apidom-parser-adapter-asyncapi-yaml-2
|
|
15
|
+
|
|
6
16
|
## [4.0.1](https://github.com/speclynx/apidom/compare/v4.0.0...v4.0.1) (2026-03-11)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @speclynx/apidom-parser-adapter-asyncapi-yaml-2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-parser-adapter-asyncapi-yaml-2",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Parser adapter for parsing YAML documents into AsyncAPI 2.x.y namespace.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apidom",
|
|
@@ -60,16 +60,15 @@
|
|
|
60
60
|
"license": "Apache-2.0",
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
63
|
-
"@speclynx/apidom-core": "4.0.
|
|
64
|
-
"@speclynx/apidom-datamodel": "4.0.
|
|
65
|
-
"@speclynx/apidom-ns-asyncapi-2": "4.0.
|
|
66
|
-
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.0.
|
|
63
|
+
"@speclynx/apidom-core": "4.0.3",
|
|
64
|
+
"@speclynx/apidom-datamodel": "4.0.3",
|
|
65
|
+
"@speclynx/apidom-ns-asyncapi-2": "4.0.3",
|
|
66
|
+
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.0.3",
|
|
67
67
|
"ramda": "~0.32.0",
|
|
68
68
|
"ramda-adjunct": "^6.0.0"
|
|
69
69
|
},
|
|
70
70
|
"files": [
|
|
71
|
-
"src
|
|
72
|
-
"src/**/*.cjs",
|
|
71
|
+
"src/",
|
|
73
72
|
"dist/",
|
|
74
73
|
"types/apidom-parser-adapter-asyncapi-yaml-2.d.ts",
|
|
75
74
|
"LICENSES",
|
|
@@ -77,5 +76,5 @@
|
|
|
77
76
|
"README.md",
|
|
78
77
|
"CHANGELOG.md"
|
|
79
78
|
],
|
|
80
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "6ccfa09c02232516215e7de3ead276641957e626"
|
|
81
80
|
}
|
package/src/adapter.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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.parse = exports.namespace = exports.mediaTypes = exports.detectionRegExp = exports.detect = void 0;
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
9
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
10
|
+
var _apidomParserAdapterYaml = require("@speclynx/apidom-parser-adapter-yaml-1-2");
|
|
11
|
+
var _apidomNsAsyncapi = _interopRequireWildcard(require("@speclynx/apidom-ns-asyncapi-2"));
|
|
12
|
+
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs"));
|
|
13
|
+
exports.mediaTypes = _mediaTypes.default;
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
const detectionRegExp = exports.detectionRegExp = /(?<YAML>^(["']?)asyncapi\2\s*:\s*(["']?)(?<version_yaml>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"asyncapi"\s*:\s*"(?<version_json>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))")/m;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
const detect = async (source, options = {}) => detectionRegExp.test(source) && (await (0, _apidomParserAdapterYaml.detect)(source, options));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
exports.detect = detect;
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
const parse = async (source, options = {}) => {
|
|
32
|
+
const refractorOpts = (0, _ramda.propOr)({}, 'refractorOpts', options);
|
|
33
|
+
const parserOpts = (0, _ramda.omit)(['refractorOpts'], options);
|
|
34
|
+
const parseResultElement = await (0, _apidomParserAdapterYaml.parse)(source, parserOpts);
|
|
35
|
+
const {
|
|
36
|
+
result
|
|
37
|
+
} = parseResultElement;
|
|
38
|
+
if ((0, _ramdaAdjunct.isNotUndefined)(result)) {
|
|
39
|
+
const asyncApiElement = (0, _apidomNsAsyncapi.refractAsyncApi2)(result, {
|
|
40
|
+
consume: true,
|
|
41
|
+
...refractorOpts
|
|
42
|
+
});
|
|
43
|
+
asyncApiElement.classes.push('result');
|
|
44
|
+
parseResultElement.replaceResult(asyncApiElement);
|
|
45
|
+
}
|
|
46
|
+
return parseResultElement;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
exports.parse = parse;
|
|
53
|
+
const namespace = exports.namespace = new _apidomDatamodel.Namespace().use(_apidomNsAsyncapi.default);
|
package/src/adapter.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { omit, propOr } from 'ramda';
|
|
2
|
+
import { isNotUndefined } from 'ramda-adjunct';
|
|
3
|
+
import { Namespace } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import { parse as parseYAML, detect as detectYAML } from '@speclynx/apidom-parser-adapter-yaml-1-2';
|
|
5
|
+
import asyncApiNamespace, { refractAsyncApi2 } from '@speclynx/apidom-ns-asyncapi-2';
|
|
6
|
+
export { default as mediaTypes } from "./media-types.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const detectionRegExp = /(?<YAML>^(["']?)asyncapi\2\s*:\s*(["']?)(?<version_yaml>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"asyncapi"\s*:\s*"(?<version_json>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))")/m;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const detect = async (source, options = {}) => detectionRegExp.test(source) && (await detectYAML(source, options));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const parse = async (source, options = {}) => {
|
|
25
|
+
const refractorOpts = propOr({}, 'refractorOpts', options);
|
|
26
|
+
const parserOpts = omit(['refractorOpts'], options);
|
|
27
|
+
const parseResultElement = await parseYAML(source, parserOpts);
|
|
28
|
+
const {
|
|
29
|
+
result
|
|
30
|
+
} = parseResultElement;
|
|
31
|
+
if (isNotUndefined(result)) {
|
|
32
|
+
const asyncApiElement = refractAsyncApi2(result, {
|
|
33
|
+
consume: true,
|
|
34
|
+
...refractorOpts
|
|
35
|
+
});
|
|
36
|
+
asyncApiElement.classes.push('result');
|
|
37
|
+
parseResultElement.replaceResult(asyncApiElement);
|
|
38
|
+
}
|
|
39
|
+
return parseResultElement;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export const namespace = new Namespace().use(asyncApiNamespace);
|
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { omit, propOr } from 'ramda';
|
|
2
|
+
import { isNotUndefined } from 'ramda-adjunct';
|
|
3
|
+
import { ParseResultElement, Namespace } from '@speclynx/apidom-datamodel';
|
|
4
|
+
import {
|
|
5
|
+
parse as parseYAML,
|
|
6
|
+
detect as detectYAML,
|
|
7
|
+
type ParseDetectOptions,
|
|
8
|
+
type ParseOptions as ParseOptionsYAML,
|
|
9
|
+
} from '@speclynx/apidom-parser-adapter-yaml-1-2';
|
|
10
|
+
import asyncApiNamespace, { refractAsyncApi2 } from '@speclynx/apidom-ns-asyncapi-2';
|
|
11
|
+
|
|
12
|
+
export { default as mediaTypes } from './media-types.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export const detectionRegExp =
|
|
18
|
+
/(?<YAML>^(["']?)asyncapi\2\s*:\s*(["']?)(?<version_yaml>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))\3(?:\s+|$))|(?<JSON>"asyncapi"\s*:\s*"(?<version_json>2\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))")/m;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export const detect: typeof detectYAML = async (
|
|
24
|
+
source: string,
|
|
25
|
+
options: ParseDetectOptions = {},
|
|
26
|
+
): Promise<boolean> => detectionRegExp.test(source) && (await detectYAML(source, options));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface ParseOptions extends ParseOptionsYAML {
|
|
32
|
+
refractorOpts?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export const parse: typeof parseYAML = async (
|
|
39
|
+
source: string,
|
|
40
|
+
options: ParseOptions = {},
|
|
41
|
+
): Promise<ParseResultElement> => {
|
|
42
|
+
const refractorOpts: Record<string, unknown> = propOr({}, 'refractorOpts', options);
|
|
43
|
+
const parserOpts = omit(['refractorOpts'], options);
|
|
44
|
+
const parseResultElement = await parseYAML(source, parserOpts);
|
|
45
|
+
const { result } = parseResultElement;
|
|
46
|
+
|
|
47
|
+
if (isNotUndefined(result)) {
|
|
48
|
+
const asyncApiElement = refractAsyncApi2(result, { consume: true, ...refractorOpts });
|
|
49
|
+
asyncApiElement.classes.push('result');
|
|
50
|
+
parseResultElement.replaceResult(asyncApiElement);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return parseResultElement;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export const namespace = new Namespace().use(asyncApiNamespace);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomNsAsyncapi = require("@speclynx/apidom-ns-asyncapi-2");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const yamlMediaTypes = new _apidomNsAsyncapi.AsyncAPIMediaTypes(..._apidomNsAsyncapi.mediaTypes.filterByFormat('generic'), ..._apidomNsAsyncapi.mediaTypes.filterByFormat('yaml'));
|
|
10
|
+
var _default = exports.default = yamlMediaTypes;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mediaTypes, AsyncAPIMediaTypes } from '@speclynx/apidom-ns-asyncapi-2';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
const yamlMediaTypes = new AsyncAPIMediaTypes(
|
|
7
|
+
...mediaTypes.filterByFormat('generic'),
|
|
8
|
+
...mediaTypes.filterByFormat('yaml'),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export default yamlMediaTypes;
|