@swagger-api/apidom-parser-adapter-asyncapi-json-3 1.0.0-rc.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.
- package/CHANGELOG.md +10 -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 +83 -0
- package/README.md +93 -0
- package/dist/2f9d346f3bc0cf9ba30b2a61e889fb78.wasm +0 -0
- package/dist/8b9a42208b2f0cb650aa7e5c4e293a15.wasm +0 -0
- package/dist/apidom-parser-adapter-asyncapi-json-3.browser.js +52955 -0
- package/dist/apidom-parser-adapter-asyncapi-json-3.browser.min.js +1 -0
- package/package.json +64 -0
- package/src/adapter.cjs +47 -0
- package/src/adapter.mjs +38 -0
- package/src/media-types.cjs +10 -0
- package/src/media-types.mjs +7 -0
- package/types/apidom-parser-adapter-asyncapi-json-3.d.ts +30 -0
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@swagger-api/apidom-parser-adapter-asyncapi-json-3",
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
|
+
"description": "Parser adapter for parsing JSON documents into AsyncAPI 3.x.y namespace.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"unpkg": "./dist/apidom-parser-apdater-asyncapi-json-3.browser.min.js",
|
|
12
|
+
"main": "./src/adapter.cjs",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./types/apidom-parser-adapter-asyncapi-json-3.d.ts",
|
|
15
|
+
"import": "./src/adapter.mjs",
|
|
16
|
+
"require": "./src/adapter.cjs"
|
|
17
|
+
},
|
|
18
|
+
"types": "./types/apidom-parser-adapter-asyncapi-json-3.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
|
|
21
|
+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
|
|
22
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir src --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
|
|
23
|
+
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
|
|
24
|
+
"lint": "eslint ./",
|
|
25
|
+
"lint:fix": "eslint ./ --fix",
|
|
26
|
+
"clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' ./dist ./types",
|
|
27
|
+
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
|
|
28
|
+
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
|
|
29
|
+
"test": "NODE_ENV=test ts-mocha --exit",
|
|
30
|
+
"perf": "cross-env BABEL_ENV=es babel ./test/perf/index.ts --out-file ./test/perf/index.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/index.mjs",
|
|
31
|
+
"perf:lexical-analysis": "cross-env BABEL_ENV=es babel ./test/perf/lexical-analysis.ts --out-file ./test/perf/lexical-analysis.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/lexical-analysis.mjs",
|
|
32
|
+
"perf:syntactic-analysis": "cross-env BABEL_ENV=es babel ./test/perf/syntactic-analysis.ts --out-file ./test/perf/syntactic-analysis.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/syntactic-analysis.mjs",
|
|
33
|
+
"perf:refract": "cross-env BABEL_ENV=es babel ./test/perf/refract.ts --out-file ./test/perf/refract.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/refract.mjs",
|
|
34
|
+
"perf:parse": "cross-env BABEL_ENV=es babel ./test/perf/parse.ts --out-file ./test/perf/parse.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/parse.mjs",
|
|
35
|
+
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
|
36
|
+
"postpack": "rimraf NOTICE LICENSES"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/swagger-api/apidom.git"
|
|
41
|
+
},
|
|
42
|
+
"author": "Shikha Lakhotia",
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@babel/runtime-corejs3": "^7.26.10",
|
|
46
|
+
"@swagger-api/apidom-core": "^1.0.0-rc.4",
|
|
47
|
+
"@swagger-api/apidom-ns-asyncapi-3": "^1.0.0-rc.4",
|
|
48
|
+
"@swagger-api/apidom-parser-adapter-json": "^1.0.0-rc.4",
|
|
49
|
+
"@types/ramda": "~0.30.0",
|
|
50
|
+
"ramda": "~0.30.0",
|
|
51
|
+
"ramda-adjunct": "^5.0.0"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"src/**/*.mjs",
|
|
55
|
+
"src/**/*.cjs",
|
|
56
|
+
"dist/",
|
|
57
|
+
"types/apidom-parser-adapter-asyncapi-json-3.d.ts",
|
|
58
|
+
"LICENSES",
|
|
59
|
+
"NOTICE",
|
|
60
|
+
"README.md",
|
|
61
|
+
"CHANGELOG.md"
|
|
62
|
+
],
|
|
63
|
+
"gitHead": "ee774281a884eedf1445699d8f2b0092e50db432"
|
|
64
|
+
}
|
package/src/adapter.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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 _apidomCore = require("@swagger-api/apidom-core");
|
|
10
|
+
var _apidomParserAdapterJson = require("@swagger-api/apidom-parser-adapter-json");
|
|
11
|
+
var _apidomNsAsyncapi = _interopRequireWildcard(require("@swagger-api/apidom-ns-asyncapi-3"));
|
|
12
|
+
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs"));
|
|
13
|
+
exports.mediaTypes = _mediaTypes.default;
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
const detectionRegExp = exports.detectionRegExp = /"asyncapi"\s*:\s*"(?<version_json>3\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))"/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
const detect = async source => detectionRegExp.test(source) && (await (0, _apidomParserAdapterJson.detect)(source));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
exports.detect = detect;
|
|
28
|
+
const parse = async (source, options = {}) => {
|
|
29
|
+
const refractorOpts = (0, _ramda.propOr)({}, 'refractorOpts', options);
|
|
30
|
+
const parserOpts = (0, _ramda.omit)(['refractorOpts'], options);
|
|
31
|
+
const parseResultElement = await (0, _apidomParserAdapterJson.parse)(source, parserOpts);
|
|
32
|
+
const {
|
|
33
|
+
result
|
|
34
|
+
} = parseResultElement;
|
|
35
|
+
if ((0, _ramdaAdjunct.isNotUndefined)(result)) {
|
|
36
|
+
const asyncApiElement = _apidomNsAsyncapi.AsyncApi3Element.refract(result, refractorOpts);
|
|
37
|
+
asyncApiElement.classes.push('result');
|
|
38
|
+
parseResultElement.replaceResult(asyncApiElement);
|
|
39
|
+
}
|
|
40
|
+
return parseResultElement;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
exports.parse = parse;
|
|
47
|
+
const namespace = exports.namespace = (0, _apidomCore.createNamespace)(_apidomNsAsyncapi.default);
|
package/src/adapter.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { propOr, omit } from 'ramda';
|
|
2
|
+
import { isNotUndefined } from 'ramda-adjunct';
|
|
3
|
+
import { createNamespace } from '@swagger-api/apidom-core';
|
|
4
|
+
import { parse as parseJSON, detect as detectJSON } from '@swagger-api/apidom-parser-adapter-json';
|
|
5
|
+
import asyncApiNamespace, { AsyncApi3Element } from '@swagger-api/apidom-ns-asyncapi-3';
|
|
6
|
+
export { default as mediaTypes } from "./media-types.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const detectionRegExp = /"asyncapi"\s*:\s*"(?<version_json>3\.(?:[1-9]\d*|0)\.(?:[1-9]\d*|0))"/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const detect = async source => detectionRegExp.test(source) && (await detectJSON(source));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export const parse = async (source, options = {}) => {
|
|
21
|
+
const refractorOpts = propOr({}, 'refractorOpts', options);
|
|
22
|
+
const parserOpts = omit(['refractorOpts'], options);
|
|
23
|
+
const parseResultElement = await parseJSON(source, parserOpts);
|
|
24
|
+
const {
|
|
25
|
+
result
|
|
26
|
+
} = parseResultElement;
|
|
27
|
+
if (isNotUndefined(result)) {
|
|
28
|
+
const asyncApiElement = AsyncApi3Element.refract(result, refractorOpts);
|
|
29
|
+
asyncApiElement.classes.push('result');
|
|
30
|
+
parseResultElement.replaceResult(asyncApiElement);
|
|
31
|
+
}
|
|
32
|
+
return parseResultElement;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export const namespace = createNamespace(asyncApiNamespace);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomNsAsyncapi = require("@swagger-api/apidom-ns-asyncapi-3");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
const jsonMediaTypes = new _apidomNsAsyncapi.AsyncAPIMediaTypes(..._apidomNsAsyncapi.mediaTypes.filterByFormat('generic'), ..._apidomNsAsyncapi.mediaTypes.filterByFormat('json'));
|
|
10
|
+
var _default = exports.default = jsonMediaTypes;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { mediaTypes, AsyncAPIMediaTypes } from '@swagger-api/apidom-ns-asyncapi-3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
const jsonMediaTypes = new AsyncAPIMediaTypes(...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('json'));
|
|
7
|
+
export default jsonMediaTypes;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AsyncAPIMediaTypes } from '@swagger-api/apidom-ns-asyncapi-3';
|
|
2
|
+
import { Namespace } from '@swagger-api/apidom-core';
|
|
3
|
+
import { ParseResultElement } from '@swagger-api/apidom-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const detect: (source: string) => Promise<boolean>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare const detectionRegExp: RegExp;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare const mediaTypes: AsyncAPIMediaTypes;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const namespace: Namespace;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const parse: (source: string, options?: Record<string, unknown>) => Promise<ParseResultElement>;
|
|
29
|
+
|
|
30
|
+
export { }
|