@speclynx/apidom-parser 2.2.3 → 2.4.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.
- package/CHANGELOG.md +10 -0
- package/README.md +3 -3
- package/dist/apidom-parser.browser.js +9 -9
- package/dist/apidom-parser.browser.min.js +1 -1
- package/package.json +5 -5
- package/src/parser.cjs +9 -9
- package/src/parser.mjs +9 -9
- package/types/apidom-parser.d.ts +3 -3
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
|
+
# [2.4.0](https://github.com/speclynx/apidom/compare/v2.3.0...v2.4.0) (2026-01-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @speclynx/apidom-parser
|
|
9
|
+
|
|
10
|
+
# [2.3.0](https://github.com/speclynx/apidom/compare/v2.2.3...v2.3.0) (2026-01-27)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- support strict parsing mode through out the packages ([#46](https://github.com/speclynx/apidom/issues/46)) ([e6b47d9](https://github.com/speclynx/apidom/commit/e6b47d9cfdede7103cada67362b316fd8e5b787f)), closes [#23](https://github.com/speclynx/apidom/issues/23)
|
|
15
|
+
|
|
6
16
|
## [2.2.3](https://github.com/speclynx/apidom/compare/v2.2.2...v2.2.3) (2026-01-26)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @speclynx/apidom-parser
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ const parser = new ApiDOMParser();
|
|
|
51
51
|
parser.use(jsonParserAdapter);
|
|
52
52
|
parser.use(yamlParserAdapter);
|
|
53
53
|
|
|
54
|
-
const namespace = await parser.findNamespace('{"prop"
|
|
54
|
+
const namespace = await parser.findNamespace('{"prop": "value"}', { mediaType: 'application/json' });
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## Finding an appropriate media type
|
|
@@ -87,7 +87,7 @@ const parser = new ApiDOMParser();
|
|
|
87
87
|
parser.use(jsonParserAdapter);
|
|
88
88
|
parser.use(yamlParserAdapter);
|
|
89
89
|
|
|
90
|
-
const parseResult = await parser.parse('{"prop"
|
|
90
|
+
const parseResult = await parser.parse('{"prop": "value"}', { mediaType: 'application/json' });
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
`parse` method consumes various options as a second argument. Here is a list of options recognized by all parser adapters:
|
|
@@ -107,7 +107,7 @@ If no parser adapter was mounted before the parsing, calling `parse` method will
|
|
|
107
107
|
import ApiDOMParser from '@speclynx/apidom-parser';
|
|
108
108
|
|
|
109
109
|
const parser = new ApiDOMParser();
|
|
110
|
-
const parseResult = await parser.parse('{"prop"
|
|
110
|
+
const parseResult = await parser.parse('{"prop": "value"}', { mediaType: 'application/json' });
|
|
111
111
|
// => ParserError('Source did not match any registered parsers')
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -2907,23 +2907,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2907
2907
|
*/
|
|
2908
2908
|
class ApiDOMParser {
|
|
2909
2909
|
adapters = [];
|
|
2910
|
-
async detectAdapterCandidates(source) {
|
|
2910
|
+
async detectAdapterCandidates(source, options = {}) {
|
|
2911
2911
|
const candidates = [];
|
|
2912
2912
|
for (const adapter of this.adapters) {
|
|
2913
|
-
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_4__["default"])(adapter.detect) && (await adapter.detect(source))) {
|
|
2913
|
+
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_4__["default"])(adapter.detect) && (await adapter.detect(source, options))) {
|
|
2914
2914
|
candidates.push(adapter);
|
|
2915
2915
|
}
|
|
2916
2916
|
}
|
|
2917
2917
|
return candidates;
|
|
2918
2918
|
}
|
|
2919
|
-
async findAdapter(source,
|
|
2920
|
-
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_3__["default"])(mediaType)) {
|
|
2919
|
+
async findAdapter(source, options = {}) {
|
|
2920
|
+
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_3__["default"])(options.mediaType)) {
|
|
2921
2921
|
return this.adapters.find(adapter => {
|
|
2922
2922
|
if (!(0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_2__["default"])(adapter.mediaTypes)) return false;
|
|
2923
|
-
return adapter.mediaTypes.includes(mediaType);
|
|
2923
|
+
return adapter.mediaTypes.includes(options.mediaType);
|
|
2924
2924
|
});
|
|
2925
2925
|
}
|
|
2926
|
-
const candidates = await this.detectAdapterCandidates(source);
|
|
2926
|
+
const candidates = await this.detectAdapterCandidates(source, options);
|
|
2927
2927
|
return (0,ramda__WEBPACK_IMPORTED_MODULE_0__["default"])(candidates);
|
|
2928
2928
|
}
|
|
2929
2929
|
use(adapter) {
|
|
@@ -2931,11 +2931,11 @@ class ApiDOMParser {
|
|
|
2931
2931
|
return this;
|
|
2932
2932
|
}
|
|
2933
2933
|
async findNamespace(source, options = {}) {
|
|
2934
|
-
const adapter = await this.findAdapter(source, options
|
|
2934
|
+
const adapter = await this.findAdapter(source, options);
|
|
2935
2935
|
return adapter?.namespace;
|
|
2936
2936
|
}
|
|
2937
2937
|
async findMediaType(source) {
|
|
2938
|
-
const adapter = await this.findAdapter(source,
|
|
2938
|
+
const adapter = await this.findAdapter(source, {});
|
|
2939
2939
|
if (typeof adapter === 'undefined') {
|
|
2940
2940
|
return new _speclynx_apidom_core__WEBPACK_IMPORTED_MODULE_5__["default"]().unknownMediaType;
|
|
2941
2941
|
}
|
|
@@ -2967,7 +2967,7 @@ class ApiDOMParser {
|
|
|
2967
2967
|
async parse(source, options = {}) {
|
|
2968
2968
|
let adapter;
|
|
2969
2969
|
try {
|
|
2970
|
-
adapter = await this.findAdapter(source, options
|
|
2970
|
+
adapter = await this.findAdapter(source, options);
|
|
2971
2971
|
} catch (error) {
|
|
2972
2972
|
throw new _errors_ParserError_ts__WEBPACK_IMPORTED_MODULE_6__["default"]('Encountered an unexpected error while matching parser adapters against the source.', {
|
|
2973
2973
|
source,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.apidomParser=e():t.apidomParser=e()}(self,()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function r(t){return function e(r){return 0===arguments.length||n(r)?e:t.apply(this,arguments)}}function o(t,e){return e[t<0?e.length+t:t]}t.r(e),t.d(e,{ParserError:()=>Mt,default:()=>kt});const u=r(function(t){return o(0,t)});function c(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,n){return e.apply(this,arguments)};case 3:return function(t,n,r){return e.apply(this,arguments)};case 4:return function(t,n,r,o){return e.apply(this,arguments)};case 5:return function(t,n,r,o,u){return e.apply(this,arguments)};case 6:return function(t,n,r,o,u,c){return e.apply(this,arguments)};case 7:return function(t,n,r,o,u,c,a){return e.apply(this,arguments)};case 8:return function(t,n,r,o,u,c,a,i){return e.apply(this,arguments)};case 9:return function(t,n,r,o,u,c,a,i,s){return e.apply(this,arguments)};case 10:return function(t,n,r,o,u,c,a,i,s,f){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function a(t){return function e(o,u){switch(arguments.length){case 0:return e;case 1:return n(o)?e:r(function(e){return t(o,e)});default:return n(o)&&n(u)?e:n(o)?r(function(e){return t(e,u)}):n(u)?r(function(e){return t(o,e)}):t(o,u)}}}function i(t,e,r){return function(){for(var o=[],u=0,a=t,s=0,f=!1;s<e.length||u<arguments.length;){var l;s<e.length&&(!n(e[s])||u>=arguments.length)?l=e[s]:(l=arguments[u],u+=1),o[s]=l,n(l)?f=!0:a-=1,s+=1}return!f&&a<=0?r.apply(this,o):c(Math.max(0,a),i(t,o,r))}}const s=a(function(t,e){return 1===t?r(e):c(t,i(t,[],e))});function f(t){for(var e,n=[];!(e=t.next()).done;)n.push(e.value);return n}function l(t,e,n){for(var r=0,o=n.length;r<o;){if(t(e,n[r]))return!0;r+=1}return!1}function p(t,e){return Object.prototype.hasOwnProperty.call(e,t)}const y="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};var d=Object.prototype.toString;const h=function(){return"[object Arguments]"===d.call(arguments)?function(t){return"[object Arguments]"===d.call(t)}:function(t){return p("callee",t)}}();var g=!{toString:null}.propertyIsEnumerable("toString"),b=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],v=function(){return arguments.propertyIsEnumerable("length")}(),m=function(t,e){for(var n=0;n<t.length;){if(t[n]===e)return!0;n+=1}return!1},j="function"!=typeof Object.keys||v?r(function(t){if(Object(t)!==t)return[];var e,n,r=[],o=v&&h(t);for(e in t)!p(e,t)||o&&"length"===e||(r[r.length]=e);if(g)for(n=b.length-1;n>=0;)p(e=b[n],t)&&!m(r,e)&&(r[r.length]=e),n-=1;return r}):r(function(t){return Object(t)!==t?[]:Object.keys(t)});const w=j;const O=r(function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)});function S(t,e,n,r){var o=f(t);function u(t,e){return A(t,e,n.slice(),r.slice())}return!l(function(t,e){return!l(u,e,t)},f(e),o)}function A(t,e,n,r){if(y(t,e))return!0;var o,u,c=O(t);if(c!==O(e))return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(c){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(o=t.constructor,null==(u=String(o).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!y(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!y(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var a=n.length-1;a>=0;){if(n[a]===t)return r[a]===e;a-=1}switch(c){case"Map":return t.size===e.size&&S(t.entries(),e.entries(),n.concat([t]),r.concat([e]));case"Set":return t.size===e.size&&S(t.values(),e.values(),n.concat([t]),r.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var i=w(t);if(i.length!==w(e).length)return!1;var s=n.concat([t]),f=r.concat([e]);for(a=i.length-1;a>=0;){var l=i[a];if(!p(l,e)||!A(e[l],t[l],s,f))return!1;a-=1}return!0}const x=a(function(t,e){return A(t,e,[],[])});function T(t,e){return function(t,e,n){var r,o;if("function"==typeof t.indexOf)switch(typeof e){case"number":if(0===e){for(r=1/e;n<t.length;){if(0===(o=t[n])&&1/o===r)return n;n+=1}return-1}if(e!=e){for(;n<t.length;){if("number"==typeof(o=t[n])&&o!=o)return n;n+=1}return-1}return t.indexOf(e,n);case"string":case"boolean":case"function":case"undefined":return t.indexOf(e,n);case"object":if(null===e)return t.indexOf(e,n)}for(;n<t.length;){if(x(t[n],e))return n;n+=1}return-1}(e,t,0)>=0}function E(t,e){for(var n=0,r=e.length,o=Array(r);n<r;)o[n]=t(e[n]),n+=1;return o}function M(t){return'"'+t.replace(/\\/g,"\\\\").replace(/[\b]/g,"\\b").replace(/\f/g,"\\f").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v").replace(/\0/g,"\\0").replace(/"/g,'\\"')+'"'}var k=function(t){return(t<10?"0":"")+t};const P="function"==typeof Date.prototype.toISOString?function(t){return t.toISOString()}:function(t){return t.getUTCFullYear()+"-"+k(t.getUTCMonth()+1)+"-"+k(t.getUTCDate())+"T"+k(t.getUTCHours())+":"+k(t.getUTCMinutes())+":"+k(t.getUTCSeconds())+"."+(t.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"Z"};function q(t,e,n){for(var r=0,o=n.length;r<o;)e=t(e,n[r]),r+=1;return e}const C=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function U(t,e,n){return function(){if(0===arguments.length)return n();var r=arguments[arguments.length-1];if(!C(r)){for(var o=0;o<t.length;){if("function"==typeof r[t[o]])return r[t[o]].apply(r,Array.prototype.slice.call(arguments,0,-1));o+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(r))return e.apply(null,Array.prototype.slice.call(arguments,0,-1))(r)}return n.apply(this,arguments)}}const F=function(){return this.xf["@@transducer/init"]()},I=function(t){return this.xf["@@transducer/result"](t)};var N=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=F,t.prototype["@@transducer/result"]=I,t.prototype["@@transducer/step"]=function(t,e){return this.f(e)?this.xf["@@transducer/step"](t,e):t},t}();function B(t){return function(e){return new N(t,e)}}var _=a(U(["fantasy-land/filter","filter"],B,function(t,e){return n=e,"[object Object]"===Object.prototype.toString.call(n)?q(function(n,r){return t(e[r])&&(n[r]=e[r]),n},{},w(e)):function(t){return"[object Map]"===Object.prototype.toString.call(t)}(e)?function(t,e){for(var n=new Map,r=e.entries(),o=r.next();!o.done;)t(o.value[1])&&n.set(o.value[0],o.value[1]),o=r.next();return n}(t,e):function(t,e){for(var n=0,r=e.length,o=[];n<r;)t(e[n])&&(o[o.length]=e[n]),n+=1;return o}(t,e);var n}));const D=_;const z=a(function(t,e){return D((n=t,function(){return!n.apply(this,arguments)}),e);var n});function R(t,e){var n=function(n){var r=e.concat([t]);return T(n,r)?"<Circular>":R(n,r)},r=function(t,e){return E(function(e){return M(e)+": "+n(t[e])},e.slice().sort())};switch(Object.prototype.toString.call(t)){case"[object Arguments]":return"(function() { return arguments; }("+E(n,t).join(", ")+"))";case"[object Array]":return"["+E(n,t).concat(r(t,z(function(t){return/^\d+$/.test(t)},w(t)))).join(", ")+"]";case"[object Boolean]":return"object"==typeof t?"new Boolean("+n(t.valueOf())+")":t.toString();case"[object Date]":return"new Date("+(isNaN(t.valueOf())?n(NaN):M(P(t)))+")";case"[object Map]":return"new Map("+n(Array.from(t))+")";case"[object Null]":return"null";case"[object Number]":return"object"==typeof t?"new Number("+n(t.valueOf())+")":1/t==-1/0?"-0":t.toString(10);case"[object Set]":return"new Set("+n(Array.from(t).sort())+")";case"[object String]":return"object"==typeof t?"new String("+n(t.valueOf())+")":M(t);case"[object Undefined]":return"undefined";default:if("function"==typeof t.toString){var o=t.toString();if("[object Object]"!==o)return o}return"{"+r(t,w(t)).join(", ")+"}"}}const G=r(function(t){return R(t,[])});const H=a(function(t,e){if(t===e)return e;function n(t,e){if(t>e!=e>t)return e>t?e:t}var r=n(t,e);if(void 0!==r)return r;var o=n(typeof t,typeof e);if(void 0!==o)return o===typeof t?t:e;var u=G(t),c=n(u,G(e));return void 0!==c&&c===u?t:e});var L=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=F,t.prototype["@@transducer/result"]=I,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}();const W=a(U(["fantasy-land/map","map"],function(t){return function(e){return new L(t,e)}},function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return s(e.length,function(){return t.call(this,e.apply(this,arguments))});case"[object Object]":return q(function(n,r){return n[r]=t(e[r]),n},{},w(e));default:return E(t,e)}})),X=Number.isInteger||function(t){return(t|0)===t};const Y=a(function(t,e){if(null!=e)return X(t)?o(t,e):e[t]});const Z=a(function(t,e){return W(Y(t),e)});function $(t){return function e(o,u,c){switch(arguments.length){case 0:return e;case 1:return n(o)?e:a(function(e,n){return t(o,e,n)});case 2:return n(o)&&n(u)?e:n(o)?a(function(e,n){return t(e,u,n)}):n(u)?a(function(e,n){return t(o,e,n)}):r(function(e){return t(o,u,e)});default:return n(o)&&n(u)&&n(c)?e:n(o)&&n(u)?a(function(e,n){return t(e,n,c)}):n(o)&&n(c)?a(function(e,n){return t(e,u,n)}):n(u)&&n(c)?a(function(e,n){return t(o,e,n)}):n(o)?r(function(e){return t(e,u,c)}):n(u)?r(function(e){return t(o,e,c)}):n(c)?r(function(e){return t(o,u,e)}):t(o,u,c)}}}const J=r(function(t){return!!C(t)||!!t&&("object"==typeof t&&(!function(t){return"[object String]"===Object.prototype.toString.call(t)}(t)&&(0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))});var K="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function Q(t,e,n){return function(r,o,u){if(J(u))return t(r,o,u);if(null==u)return o;if("function"==typeof u["fantasy-land/reduce"])return e(r,o,u,"fantasy-land/reduce");if(null!=u[K])return n(r,o,u[K]());if("function"==typeof u.next)return n(r,o,u);if("function"==typeof u.reduce)return e(r,o,u,"reduce");throw new TypeError("reduce: list must be array or iterable")}}function V(t,e,n){for(var r=0,o=n.length;r<o;){if((e=t["@@transducer/step"](e,n[r]))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}r+=1}return t["@@transducer/result"](e)}const tt=a(function(t,e){return c(t.length,function(){return t.apply(e,arguments)})});function et(t,e,n){for(var r=n.next();!r.done;){if((e=t["@@transducer/step"](e,r.value))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}r=n.next()}return t["@@transducer/result"](e)}function nt(t,e,n,r){return t["@@transducer/result"](n[r](tt(t["@@transducer/step"],t),e))}const rt=Q(V,nt,et);var ot=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,e){return this.f(t,e)},t}();const ut=$(function(t,e,n){return rt("function"==typeof t?new ot(t):t,e,n)});const ct=r(function(t){return s(ut(H,0,Z("length",t)),function(){for(var e=0,n=t.length;e<n;){if(t[e].apply(this,arguments))return!0;e+=1}return!1})});function at(t,e){return function(){return e.call(this,t.apply(this,arguments))}}function it(t,e){return function(){var n=arguments.length;if(0===n)return e();var r=arguments[n-1];return C(r)||"function"!=typeof r[t]?e.apply(this,arguments):r[t].apply(r,Array.prototype.slice.call(arguments,0,n-1))}}const st=r(it("tail",$(it("slice",function(t,e,n){return Array.prototype.slice.call(n,t,e)}))(1,1/0)));function ft(){if(0===arguments.length)throw new Error("pipe requires at least one argument");return c(arguments[0].length,ut(at,arguments[0],st(arguments)))}var lt=function(t,e){switch(arguments.length){case 0:return lt;case 1:return function e(n){return 0===arguments.length?e:y(t,n)};default:return y(t,e)}};const pt=lt;const yt=s(1,ft(O,pt("GeneratorFunction")));const dt=s(1,ft(O,pt("AsyncFunction")));const ht=ct([ft(O,pt("Function")),yt,dt]);const gt=s(1,ft(O,pt("String")));const bt=s(1,ht(Array.isArray)?Array.isArray:ft(O,pt("Array")));var vt=r(function(t){return function(){return t}})(void 0);const mt=x(vt());class jt extends AggregateError{constructor(t,e,n){super(t,e,n),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const wt=jt;class Ot extends Error{static[Symbol.hasInstance](t){return super[Symbol.hasInstance](t)||Function.prototype[Symbol.hasInstance].call(wt,t)}constructor(t,e){super(t,e),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const St=Ot;const At=class extends St{};const xt=class extends At{};const Tt=class extends Array{unknownMediaType="application/octet-stream";filterByFormat(){throw new xt("filterByFormat method in MediaTypes class is not yet implemented.")}findBy(){throw new xt("findBy method in MediaTypes class is not yet implemented.")}latest(){throw new xt("latest method in MediaTypes class is not yet implemented.")}};const Et=class extends St{constructor(t,e){if(super(t,e),null!=e&&"object"==typeof e){const{cause:t,...n}=e;Object.assign(this,n)}}};const Mt=class extends Et{source;parserOptions;constructor(t,e){super(t,e),void 0!==e&&(this.source=e.source,this.parserOptions=e.parserOptions)}};const kt=class{adapters=[];async detectAdapterCandidates(t){const e=[];for(const n of this.adapters)ht(n.detect)&&await n.detect(t)&&e.push(n);return e}async findAdapter(t,e){if(gt(e))return this.adapters.find(t=>!!bt(t.mediaTypes)&&t.mediaTypes.includes(e));const n=await this.detectAdapterCandidates(t);return u(n)}use(t){return this.adapters.push(t),this}async findNamespace(t,e={}){const n=await this.findAdapter(t,e.mediaType);return n?.namespace}async findMediaType(t){const e=await this.findAdapter(t,void 0);if(void 0===e)return(new Tt).unknownMediaType;if(void 0===e.mediaTypes)return(new Tt).unknownMediaType;if(void 0===e.detectionRegExp)return e.mediaTypes.latest();const{detectionRegExp:n}=e,r=t.match(n);if(null===r)return(new Tt).unknownMediaType;const{groups:o}=r,u=o?.version||o?.version_json||o?.version_yaml,c=o?.version_json?"json":o?.version_yaml?"yaml":"generic";return void 0===u?e.mediaTypes.latest():e.mediaTypes.findBy(u,c)}async parse(t,e={}){let n;try{n=await this.findAdapter(t,e.mediaType)}catch(n){throw new Mt("Encountered an unexpected error while matching parser adapters against the source.",{source:t,parserOptions:e,cause:n})}if(mt(n))throw new Mt("Source did not match any registered parsers",{source:t,parserOptions:e});try{return n.parse(t,e)}catch(n){throw new Mt("Parsing encountered an unexpected error.",{source:t,parserOptions:e,cause:n})}}};return e})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.apidomParser=e():t.apidomParser=e()}(self,()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function r(t){return function e(r){return 0===arguments.length||n(r)?e:t.apply(this,arguments)}}function o(t,e){return e[t<0?e.length+t:t]}t.r(e),t.d(e,{ParserError:()=>Mt,default:()=>kt});const u=r(function(t){return o(0,t)});function c(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,n){return e.apply(this,arguments)};case 3:return function(t,n,r){return e.apply(this,arguments)};case 4:return function(t,n,r,o){return e.apply(this,arguments)};case 5:return function(t,n,r,o,u){return e.apply(this,arguments)};case 6:return function(t,n,r,o,u,c){return e.apply(this,arguments)};case 7:return function(t,n,r,o,u,c,a){return e.apply(this,arguments)};case 8:return function(t,n,r,o,u,c,a,i){return e.apply(this,arguments)};case 9:return function(t,n,r,o,u,c,a,i,s){return e.apply(this,arguments)};case 10:return function(t,n,r,o,u,c,a,i,s,f){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function a(t){return function e(o,u){switch(arguments.length){case 0:return e;case 1:return n(o)?e:r(function(e){return t(o,e)});default:return n(o)&&n(u)?e:n(o)?r(function(e){return t(e,u)}):n(u)?r(function(e){return t(o,e)}):t(o,u)}}}function i(t,e,r){return function(){for(var o=[],u=0,a=t,s=0,f=!1;s<e.length||u<arguments.length;){var l;s<e.length&&(!n(e[s])||u>=arguments.length)?l=e[s]:(l=arguments[u],u+=1),o[s]=l,n(l)?f=!0:a-=1,s+=1}return!f&&a<=0?r.apply(this,o):c(Math.max(0,a),i(t,o,r))}}const s=a(function(t,e){return 1===t?r(e):c(t,i(t,[],e))});function f(t){for(var e,n=[];!(e=t.next()).done;)n.push(e.value);return n}function l(t,e,n){for(var r=0,o=n.length;r<o;){if(t(e,n[r]))return!0;r+=1}return!1}function p(t,e){return Object.prototype.hasOwnProperty.call(e,t)}const y="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};var d=Object.prototype.toString;const h=function(){return"[object Arguments]"===d.call(arguments)?function(t){return"[object Arguments]"===d.call(t)}:function(t){return p("callee",t)}}();var g=!{toString:null}.propertyIsEnumerable("toString"),b=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],m=function(){return arguments.propertyIsEnumerable("length")}(),v=function(t,e){for(var n=0;n<t.length;){if(t[n]===e)return!0;n+=1}return!1},j="function"!=typeof Object.keys||m?r(function(t){if(Object(t)!==t)return[];var e,n,r=[],o=m&&h(t);for(e in t)!p(e,t)||o&&"length"===e||(r[r.length]=e);if(g)for(n=b.length-1;n>=0;)p(e=b[n],t)&&!v(r,e)&&(r[r.length]=e),n-=1;return r}):r(function(t){return Object(t)!==t?[]:Object.keys(t)});const w=j;const O=r(function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)});function S(t,e,n,r){var o=f(t);function u(t,e){return A(t,e,n.slice(),r.slice())}return!l(function(t,e){return!l(u,e,t)},f(e),o)}function A(t,e,n,r){if(y(t,e))return!0;var o,u,c=O(t);if(c!==O(e))return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(c){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(o=t.constructor,null==(u=String(o).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!y(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!y(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var a=n.length-1;a>=0;){if(n[a]===t)return r[a]===e;a-=1}switch(c){case"Map":return t.size===e.size&&S(t.entries(),e.entries(),n.concat([t]),r.concat([e]));case"Set":return t.size===e.size&&S(t.values(),e.values(),n.concat([t]),r.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var i=w(t);if(i.length!==w(e).length)return!1;var s=n.concat([t]),f=r.concat([e]);for(a=i.length-1;a>=0;){var l=i[a];if(!p(l,e)||!A(e[l],t[l],s,f))return!1;a-=1}return!0}const x=a(function(t,e){return A(t,e,[],[])});function T(t,e){return function(t,e,n){var r,o;if("function"==typeof t.indexOf)switch(typeof e){case"number":if(0===e){for(r=1/e;n<t.length;){if(0===(o=t[n])&&1/o===r)return n;n+=1}return-1}if(e!=e){for(;n<t.length;){if("number"==typeof(o=t[n])&&o!=o)return n;n+=1}return-1}return t.indexOf(e,n);case"string":case"boolean":case"function":case"undefined":return t.indexOf(e,n);case"object":if(null===e)return t.indexOf(e,n)}for(;n<t.length;){if(x(t[n],e))return n;n+=1}return-1}(e,t,0)>=0}function E(t,e){for(var n=0,r=e.length,o=Array(r);n<r;)o[n]=t(e[n]),n+=1;return o}function M(t){return'"'+t.replace(/\\/g,"\\\\").replace(/[\b]/g,"\\b").replace(/\f/g,"\\f").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v").replace(/\0/g,"\\0").replace(/"/g,'\\"')+'"'}var k=function(t){return(t<10?"0":"")+t};const P="function"==typeof Date.prototype.toISOString?function(t){return t.toISOString()}:function(t){return t.getUTCFullYear()+"-"+k(t.getUTCMonth()+1)+"-"+k(t.getUTCDate())+"T"+k(t.getUTCHours())+":"+k(t.getUTCMinutes())+":"+k(t.getUTCSeconds())+"."+(t.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"Z"};function q(t,e,n){for(var r=0,o=n.length;r<o;)e=t(e,n[r]),r+=1;return e}const C=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function U(t,e,n){return function(){if(0===arguments.length)return n();var r=arguments[arguments.length-1];if(!C(r)){for(var o=0;o<t.length;){if("function"==typeof r[t[o]])return r[t[o]].apply(r,Array.prototype.slice.call(arguments,0,-1));o+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(r))return e.apply(null,Array.prototype.slice.call(arguments,0,-1))(r)}return n.apply(this,arguments)}}const F=function(){return this.xf["@@transducer/init"]()},I=function(t){return this.xf["@@transducer/result"](t)};var N=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=F,t.prototype["@@transducer/result"]=I,t.prototype["@@transducer/step"]=function(t,e){return this.f(e)?this.xf["@@transducer/step"](t,e):t},t}();function B(t){return function(e){return new N(t,e)}}var _=a(U(["fantasy-land/filter","filter"],B,function(t,e){return n=e,"[object Object]"===Object.prototype.toString.call(n)?q(function(n,r){return t(e[r])&&(n[r]=e[r]),n},{},w(e)):function(t){return"[object Map]"===Object.prototype.toString.call(t)}(e)?function(t,e){for(var n=new Map,r=e.entries(),o=r.next();!o.done;)t(o.value[1])&&n.set(o.value[0],o.value[1]),o=r.next();return n}(t,e):function(t,e){for(var n=0,r=e.length,o=[];n<r;)t(e[n])&&(o[o.length]=e[n]),n+=1;return o}(t,e);var n}));const D=_;const z=a(function(t,e){return D((n=t,function(){return!n.apply(this,arguments)}),e);var n});function R(t,e){var n=function(n){var r=e.concat([t]);return T(n,r)?"<Circular>":R(n,r)},r=function(t,e){return E(function(e){return M(e)+": "+n(t[e])},e.slice().sort())};switch(Object.prototype.toString.call(t)){case"[object Arguments]":return"(function() { return arguments; }("+E(n,t).join(", ")+"))";case"[object Array]":return"["+E(n,t).concat(r(t,z(function(t){return/^\d+$/.test(t)},w(t)))).join(", ")+"]";case"[object Boolean]":return"object"==typeof t?"new Boolean("+n(t.valueOf())+")":t.toString();case"[object Date]":return"new Date("+(isNaN(t.valueOf())?n(NaN):M(P(t)))+")";case"[object Map]":return"new Map("+n(Array.from(t))+")";case"[object Null]":return"null";case"[object Number]":return"object"==typeof t?"new Number("+n(t.valueOf())+")":1/t==-1/0?"-0":t.toString(10);case"[object Set]":return"new Set("+n(Array.from(t).sort())+")";case"[object String]":return"object"==typeof t?"new String("+n(t.valueOf())+")":M(t);case"[object Undefined]":return"undefined";default:if("function"==typeof t.toString){var o=t.toString();if("[object Object]"!==o)return o}return"{"+r(t,w(t)).join(", ")+"}"}}const G=r(function(t){return R(t,[])});const H=a(function(t,e){if(t===e)return e;function n(t,e){if(t>e!=e>t)return e>t?e:t}var r=n(t,e);if(void 0!==r)return r;var o=n(typeof t,typeof e);if(void 0!==o)return o===typeof t?t:e;var u=G(t),c=n(u,G(e));return void 0!==c&&c===u?t:e});var L=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=F,t.prototype["@@transducer/result"]=I,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}();const W=a(U(["fantasy-land/map","map"],function(t){return function(e){return new L(t,e)}},function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return s(e.length,function(){return t.call(this,e.apply(this,arguments))});case"[object Object]":return q(function(n,r){return n[r]=t(e[r]),n},{},w(e));default:return E(t,e)}})),X=Number.isInteger||function(t){return(t|0)===t};const Y=a(function(t,e){if(null!=e)return X(t)?o(t,e):e[t]});const Z=a(function(t,e){return W(Y(t),e)});function $(t){return function e(o,u,c){switch(arguments.length){case 0:return e;case 1:return n(o)?e:a(function(e,n){return t(o,e,n)});case 2:return n(o)&&n(u)?e:n(o)?a(function(e,n){return t(e,u,n)}):n(u)?a(function(e,n){return t(o,e,n)}):r(function(e){return t(o,u,e)});default:return n(o)&&n(u)&&n(c)?e:n(o)&&n(u)?a(function(e,n){return t(e,n,c)}):n(o)&&n(c)?a(function(e,n){return t(e,u,n)}):n(u)&&n(c)?a(function(e,n){return t(o,e,n)}):n(o)?r(function(e){return t(e,u,c)}):n(u)?r(function(e){return t(o,e,c)}):n(c)?r(function(e){return t(o,u,e)}):t(o,u,c)}}}const J=r(function(t){return!!C(t)||!!t&&("object"==typeof t&&(!function(t){return"[object String]"===Object.prototype.toString.call(t)}(t)&&(0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))});var K="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function Q(t,e,n){return function(r,o,u){if(J(u))return t(r,o,u);if(null==u)return o;if("function"==typeof u["fantasy-land/reduce"])return e(r,o,u,"fantasy-land/reduce");if(null!=u[K])return n(r,o,u[K]());if("function"==typeof u.next)return n(r,o,u);if("function"==typeof u.reduce)return e(r,o,u,"reduce");throw new TypeError("reduce: list must be array or iterable")}}function V(t,e,n){for(var r=0,o=n.length;r<o;){if((e=t["@@transducer/step"](e,n[r]))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}r+=1}return t["@@transducer/result"](e)}const tt=a(function(t,e){return c(t.length,function(){return t.apply(e,arguments)})});function et(t,e,n){for(var r=n.next();!r.done;){if((e=t["@@transducer/step"](e,r.value))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}r=n.next()}return t["@@transducer/result"](e)}function nt(t,e,n,r){return t["@@transducer/result"](n[r](tt(t["@@transducer/step"],t),e))}const rt=Q(V,nt,et);var ot=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,e){return this.f(t,e)},t}();const ut=$(function(t,e,n){return rt("function"==typeof t?new ot(t):t,e,n)});const ct=r(function(t){return s(ut(H,0,Z("length",t)),function(){for(var e=0,n=t.length;e<n;){if(t[e].apply(this,arguments))return!0;e+=1}return!1})});function at(t,e){return function(){return e.call(this,t.apply(this,arguments))}}function it(t,e){return function(){var n=arguments.length;if(0===n)return e();var r=arguments[n-1];return C(r)||"function"!=typeof r[t]?e.apply(this,arguments):r[t].apply(r,Array.prototype.slice.call(arguments,0,n-1))}}const st=r(it("tail",$(it("slice",function(t,e,n){return Array.prototype.slice.call(n,t,e)}))(1,1/0)));function ft(){if(0===arguments.length)throw new Error("pipe requires at least one argument");return c(arguments[0].length,ut(at,arguments[0],st(arguments)))}var lt=function(t,e){switch(arguments.length){case 0:return lt;case 1:return function e(n){return 0===arguments.length?e:y(t,n)};default:return y(t,e)}};const pt=lt;const yt=s(1,ft(O,pt("GeneratorFunction")));const dt=s(1,ft(O,pt("AsyncFunction")));const ht=ct([ft(O,pt("Function")),yt,dt]);const gt=s(1,ft(O,pt("String")));const bt=s(1,ht(Array.isArray)?Array.isArray:ft(O,pt("Array")));var mt=r(function(t){return function(){return t}})(void 0);const vt=x(mt());class jt extends AggregateError{constructor(t,e,n){super(t,e,n),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const wt=jt;class Ot extends Error{static[Symbol.hasInstance](t){return super[Symbol.hasInstance](t)||Function.prototype[Symbol.hasInstance].call(wt,t)}constructor(t,e){super(t,e),this.name=this.constructor.name,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const St=Ot;const At=class extends St{};const xt=class extends At{};const Tt=class extends Array{unknownMediaType="application/octet-stream";filterByFormat(){throw new xt("filterByFormat method in MediaTypes class is not yet implemented.")}findBy(){throw new xt("findBy method in MediaTypes class is not yet implemented.")}latest(){throw new xt("latest method in MediaTypes class is not yet implemented.")}};const Et=class extends St{constructor(t,e){if(super(t,e),null!=e&&"object"==typeof e){const{cause:t,...n}=e;Object.assign(this,n)}}};const Mt=class extends Et{source;parserOptions;constructor(t,e){super(t,e),void 0!==e&&(this.source=e.source,this.parserOptions=e.parserOptions)}};const kt=class{adapters=[];async detectAdapterCandidates(t,e={}){const n=[];for(const r of this.adapters)ht(r.detect)&&await r.detect(t,e)&&n.push(r);return n}async findAdapter(t,e={}){if(gt(e.mediaType))return this.adapters.find(t=>!!bt(t.mediaTypes)&&t.mediaTypes.includes(e.mediaType));const n=await this.detectAdapterCandidates(t,e);return u(n)}use(t){return this.adapters.push(t),this}async findNamespace(t,e={}){const n=await this.findAdapter(t,e);return n?.namespace}async findMediaType(t){const e=await this.findAdapter(t,{});if(void 0===e)return(new Tt).unknownMediaType;if(void 0===e.mediaTypes)return(new Tt).unknownMediaType;if(void 0===e.detectionRegExp)return e.mediaTypes.latest();const{detectionRegExp:n}=e,r=t.match(n);if(null===r)return(new Tt).unknownMediaType;const{groups:o}=r,u=o?.version||o?.version_json||o?.version_yaml,c=o?.version_json?"json":o?.version_yaml?"yaml":"generic";return void 0===u?e.mediaTypes.latest():e.mediaTypes.findBy(u,c)}async parse(t,e={}){let n;try{n=await this.findAdapter(t,e)}catch(n){throw new Mt("Encountered an unexpected error while matching parser adapters against the source.",{source:t,parserOptions:e,cause:n})}if(vt(n))throw new Mt("Source did not match any registered parsers",{source:t,parserOptions:e});try{return n.parse(t,e)}catch(n){throw new Mt("Parsing encountered an unexpected error.",{source:t,parserOptions:e,cause:n})}}};return e})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-parser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Parser consumes parser adapters and provides unified API for parsing.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
42
|
-
"@speclynx/apidom-core": "^2.
|
|
43
|
-
"@speclynx/apidom-datamodel": "^2.
|
|
44
|
-
"@speclynx/apidom-error": "^2.
|
|
42
|
+
"@speclynx/apidom-core": "^2.4.0",
|
|
43
|
+
"@speclynx/apidom-datamodel": "^2.4.0",
|
|
44
|
+
"@speclynx/apidom-error": "^2.4.0",
|
|
45
45
|
"ramda": "~0.32.0",
|
|
46
46
|
"ramda-adjunct": "^6.0.0"
|
|
47
47
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"README.md",
|
|
56
56
|
"CHANGELOG.md"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "f127ee0b98cc108b83a690bf317895e17a32b4d4"
|
|
59
59
|
}
|
package/src/parser.cjs
CHANGED
|
@@ -29,23 +29,23 @@ exports.ParserError = _ParserError.default;
|
|
|
29
29
|
*/
|
|
30
30
|
class ApiDOMParser {
|
|
31
31
|
adapters = [];
|
|
32
|
-
async detectAdapterCandidates(source) {
|
|
32
|
+
async detectAdapterCandidates(source, options = {}) {
|
|
33
33
|
const candidates = [];
|
|
34
34
|
for (const adapter of this.adapters) {
|
|
35
|
-
if ((0, _ramdaAdjunct.isFunction)(adapter.detect) && (await adapter.detect(source))) {
|
|
35
|
+
if ((0, _ramdaAdjunct.isFunction)(adapter.detect) && (await adapter.detect(source, options))) {
|
|
36
36
|
candidates.push(adapter);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
return candidates;
|
|
40
40
|
}
|
|
41
|
-
async findAdapter(source,
|
|
42
|
-
if ((0, _ramdaAdjunct.isString)(mediaType)) {
|
|
41
|
+
async findAdapter(source, options = {}) {
|
|
42
|
+
if ((0, _ramdaAdjunct.isString)(options.mediaType)) {
|
|
43
43
|
return this.adapters.find(adapter => {
|
|
44
44
|
if (!(0, _ramdaAdjunct.isArray)(adapter.mediaTypes)) return false;
|
|
45
|
-
return adapter.mediaTypes.includes(mediaType);
|
|
45
|
+
return adapter.mediaTypes.includes(options.mediaType);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
const candidates = await this.detectAdapterCandidates(source);
|
|
48
|
+
const candidates = await this.detectAdapterCandidates(source, options);
|
|
49
49
|
return (0, _ramda.head)(candidates);
|
|
50
50
|
}
|
|
51
51
|
use(adapter) {
|
|
@@ -53,11 +53,11 @@ class ApiDOMParser {
|
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
55
|
async findNamespace(source, options = {}) {
|
|
56
|
-
const adapter = await this.findAdapter(source, options
|
|
56
|
+
const adapter = await this.findAdapter(source, options);
|
|
57
57
|
return adapter?.namespace;
|
|
58
58
|
}
|
|
59
59
|
async findMediaType(source) {
|
|
60
|
-
const adapter = await this.findAdapter(source,
|
|
60
|
+
const adapter = await this.findAdapter(source, {});
|
|
61
61
|
if (typeof adapter === 'undefined') {
|
|
62
62
|
return new _apidomCore.MediaTypes().unknownMediaType;
|
|
63
63
|
}
|
|
@@ -89,7 +89,7 @@ class ApiDOMParser {
|
|
|
89
89
|
async parse(source, options = {}) {
|
|
90
90
|
let adapter;
|
|
91
91
|
try {
|
|
92
|
-
adapter = await this.findAdapter(source, options
|
|
92
|
+
adapter = await this.findAdapter(source, options);
|
|
93
93
|
} catch (error) {
|
|
94
94
|
throw new _ParserError.default('Encountered an unexpected error while matching parser adapters against the source.', {
|
|
95
95
|
source,
|
package/src/parser.mjs
CHANGED
|
@@ -25,23 +25,23 @@ export { ParserError };
|
|
|
25
25
|
*/
|
|
26
26
|
class ApiDOMParser {
|
|
27
27
|
adapters = [];
|
|
28
|
-
async detectAdapterCandidates(source) {
|
|
28
|
+
async detectAdapterCandidates(source, options = {}) {
|
|
29
29
|
const candidates = [];
|
|
30
30
|
for (const adapter of this.adapters) {
|
|
31
|
-
if (isFunction(adapter.detect) && (await adapter.detect(source))) {
|
|
31
|
+
if (isFunction(adapter.detect) && (await adapter.detect(source, options))) {
|
|
32
32
|
candidates.push(adapter);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
return candidates;
|
|
36
36
|
}
|
|
37
|
-
async findAdapter(source,
|
|
38
|
-
if (isString(mediaType)) {
|
|
37
|
+
async findAdapter(source, options = {}) {
|
|
38
|
+
if (isString(options.mediaType)) {
|
|
39
39
|
return this.adapters.find(adapter => {
|
|
40
40
|
if (!isArray(adapter.mediaTypes)) return false;
|
|
41
|
-
return adapter.mediaTypes.includes(mediaType);
|
|
41
|
+
return adapter.mediaTypes.includes(options.mediaType);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
const candidates = await this.detectAdapterCandidates(source);
|
|
44
|
+
const candidates = await this.detectAdapterCandidates(source, options);
|
|
45
45
|
return head(candidates);
|
|
46
46
|
}
|
|
47
47
|
use(adapter) {
|
|
@@ -49,11 +49,11 @@ class ApiDOMParser {
|
|
|
49
49
|
return this;
|
|
50
50
|
}
|
|
51
51
|
async findNamespace(source, options = {}) {
|
|
52
|
-
const adapter = await this.findAdapter(source, options
|
|
52
|
+
const adapter = await this.findAdapter(source, options);
|
|
53
53
|
return adapter?.namespace;
|
|
54
54
|
}
|
|
55
55
|
async findMediaType(source) {
|
|
56
|
-
const adapter = await this.findAdapter(source,
|
|
56
|
+
const adapter = await this.findAdapter(source, {});
|
|
57
57
|
if (typeof adapter === 'undefined') {
|
|
58
58
|
return new MediaTypes().unknownMediaType;
|
|
59
59
|
}
|
|
@@ -85,7 +85,7 @@ class ApiDOMParser {
|
|
|
85
85
|
async parse(source, options = {}) {
|
|
86
86
|
let adapter;
|
|
87
87
|
try {
|
|
88
|
-
adapter = await this.findAdapter(source, options
|
|
88
|
+
adapter = await this.findAdapter(source, options);
|
|
89
89
|
} catch (error) {
|
|
90
90
|
throw new ParserError('Encountered an unexpected error while matching parser adapters against the source.', {
|
|
91
91
|
source,
|
package/types/apidom-parser.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
|
9
9
|
*/
|
|
10
10
|
declare class ApiDOMParser {
|
|
11
11
|
private adapters;
|
|
12
|
-
protected detectAdapterCandidates(source: string): Promise<ApiDOMParserAdapter[]>;
|
|
13
|
-
protected findAdapter(source: string,
|
|
12
|
+
protected detectAdapterCandidates(source: string, options?: ApiDOMParserOptions): Promise<ApiDOMParserAdapter[]>;
|
|
13
|
+
protected findAdapter(source: string, options?: ApiDOMParserOptions): Promise<ApiDOMParserAdapter | undefined>;
|
|
14
14
|
use(adapter: ApiDOMParserAdapter): this;
|
|
15
15
|
findNamespace(source: string, options?: ApiDOMParserOptions): Promise<Namespace | undefined>;
|
|
16
16
|
findMediaType(source: string): Promise<string | void>;
|
|
@@ -42,7 +42,7 @@ export declare interface ApiDOMParserOptions {
|
|
|
42
42
|
/**
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
|
-
export declare type Detect = (source: string) => boolean | Promise<boolean>;
|
|
45
|
+
export declare type Detect = (source: string, options?: ApiDOMParserOptions) => boolean | Promise<boolean>;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* @public
|