@speclynx/apidom-parser 1.12.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 +82 -0
- package/LICENSE +202 -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 +65 -0
- package/README.md +139 -0
- package/dist/apidom-parser.browser.js +2983 -0
- package/dist/apidom-parser.browser.min.js +1 -0
- package/package.json +59 -0
- package/src/errors/ParserError.cjs +24 -0
- package/src/errors/ParserError.mjs +21 -0
- package/src/parser.cjs +101 -0
- package/src/parser.mjs +97 -0
- package/types/apidom-parser.d.ts +68 -0
|
@@ -0,0 +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})());
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speclynx/apidom-parser",
|
|
3
|
+
"version": "1.12.1",
|
|
4
|
+
"description": "Parser consumes parser adapters and provides unified API for parsing.",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org",
|
|
8
|
+
"provenance": true
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"unpkg": "./dist/apidom-parser.browser.min.js",
|
|
13
|
+
"main": "./src/parser.cjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
"types": "./types/apidom-parser.d.ts",
|
|
16
|
+
"import": "./src/parser.mjs",
|
|
17
|
+
"require": "./src/parser.cjs"
|
|
18
|
+
},
|
|
19
|
+
"types": "./types/apidom-parser.d.ts",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
|
|
22
|
+
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
|
|
23
|
+
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir src --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
|
|
24
|
+
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
|
|
25
|
+
"lint": "eslint ./",
|
|
26
|
+
"lint:fix": "eslint ./ --fix",
|
|
27
|
+
"clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types",
|
|
28
|
+
"typescript:check-types": "tsc --noEmit",
|
|
29
|
+
"typescript:declaration": "copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
|
|
30
|
+
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
|
|
31
|
+
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
|
|
32
|
+
"postpack": "rimraf NOTICE LICENSES"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/speclynx/apidom.git"
|
|
37
|
+
},
|
|
38
|
+
"author": "Vladimir Gorej",
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@babel/runtime-corejs3": "^7.28.4",
|
|
42
|
+
"@speclynx/apidom-core": "^1.12.1",
|
|
43
|
+
"@speclynx/apidom-error": "^1.12.1",
|
|
44
|
+
"@types/ramda": "~0.30.0",
|
|
45
|
+
"ramda": "~0.32.0",
|
|
46
|
+
"ramda-adjunct": "^6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"src/**/*.mjs",
|
|
50
|
+
"src/**/*.cjs",
|
|
51
|
+
"dist/",
|
|
52
|
+
"types/apidom-parser.d.ts",
|
|
53
|
+
"LICENSES",
|
|
54
|
+
"NOTICE",
|
|
55
|
+
"README.md",
|
|
56
|
+
"CHANGELOG.md"
|
|
57
|
+
],
|
|
58
|
+
"gitHead": "49be88493f922c4ace2e4ebc0f23387ccb62c4fc"
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
class ApiDOMParser {
|
|
15
|
+
adapters = [];
|
|
16
|
+
async detectAdapterCandidates(source) {
|
|
17
|
+
const candidates = [];
|
|
18
|
+
for (const adapter of this.adapters) {
|
|
19
|
+
if ((0, _ramdaAdjunct.isFunction)(adapter.detect) && (await adapter.detect(source))) {
|
|
20
|
+
candidates.push(adapter);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return candidates;
|
|
24
|
+
}
|
|
25
|
+
async findAdapter(source, mediaType) {
|
|
26
|
+
if ((0, _ramdaAdjunct.isString)(mediaType)) {
|
|
27
|
+
return this.adapters.find(adapter => {
|
|
28
|
+
if (!(0, _ramdaAdjunct.isArray)(adapter.mediaTypes)) return false;
|
|
29
|
+
return adapter.mediaTypes.includes(mediaType);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const candidates = await this.detectAdapterCandidates(source);
|
|
33
|
+
return (0, _ramda.head)(candidates);
|
|
34
|
+
}
|
|
35
|
+
use(adapter) {
|
|
36
|
+
this.adapters.push(adapter);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
async findNamespace(source, options = {}) {
|
|
40
|
+
const adapter = await this.findAdapter(source, options.mediaType);
|
|
41
|
+
return adapter?.namespace;
|
|
42
|
+
}
|
|
43
|
+
async findMediaType(source) {
|
|
44
|
+
const adapter = await this.findAdapter(source, undefined);
|
|
45
|
+
if (typeof adapter === 'undefined') {
|
|
46
|
+
return new _apidomCore.MediaTypes().unknownMediaType;
|
|
47
|
+
}
|
|
48
|
+
if (typeof adapter.mediaTypes === 'undefined') {
|
|
49
|
+
return new _apidomCore.MediaTypes().unknownMediaType;
|
|
50
|
+
}
|
|
51
|
+
if (typeof adapter.detectionRegExp === 'undefined') {
|
|
52
|
+
return adapter.mediaTypes.latest();
|
|
53
|
+
}
|
|
54
|
+
const {
|
|
55
|
+
detectionRegExp
|
|
56
|
+
} = adapter;
|
|
57
|
+
const matches = source.match(detectionRegExp);
|
|
58
|
+
if (matches === null) {
|
|
59
|
+
return new _apidomCore.MediaTypes().unknownMediaType;
|
|
60
|
+
}
|
|
61
|
+
const {
|
|
62
|
+
groups
|
|
63
|
+
} = matches;
|
|
64
|
+
const version = groups?.version || groups?.version_json || groups?.version_yaml;
|
|
65
|
+
const format = groups?.version_json ? 'json' : groups?.version_yaml ? 'yaml' : 'generic';
|
|
66
|
+
if (typeof version === 'undefined') {
|
|
67
|
+
return adapter.mediaTypes.latest();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return adapter.mediaTypes.findBy(version, format);
|
|
72
|
+
}
|
|
73
|
+
async parse(source, options = {}) {
|
|
74
|
+
let adapter;
|
|
75
|
+
try {
|
|
76
|
+
adapter = await this.findAdapter(source, options.mediaType);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new _ParserError.default('Encountered an unexpected error while matching parser adapters against the source.', {
|
|
79
|
+
source,
|
|
80
|
+
parserOptions: options,
|
|
81
|
+
cause: error
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if ((0, _ramdaAdjunct.isUndefined)(adapter)) {
|
|
85
|
+
throw new _ParserError.default('Source did not match any registered parsers', {
|
|
86
|
+
source,
|
|
87
|
+
parserOptions: options
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return adapter.parse(source, options);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
throw new _ParserError.default('Parsing encountered an unexpected error.', {
|
|
94
|
+
source,
|
|
95
|
+
parserOptions: options,
|
|
96
|
+
cause: error
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var _default = exports.default = ApiDOMParser;
|
package/src/parser.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
class ApiDOMParser {
|
|
11
|
+
adapters = [];
|
|
12
|
+
async detectAdapterCandidates(source) {
|
|
13
|
+
const candidates = [];
|
|
14
|
+
for (const adapter of this.adapters) {
|
|
15
|
+
if (isFunction(adapter.detect) && (await adapter.detect(source))) {
|
|
16
|
+
candidates.push(adapter);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return candidates;
|
|
20
|
+
}
|
|
21
|
+
async findAdapter(source, mediaType) {
|
|
22
|
+
if (isString(mediaType)) {
|
|
23
|
+
return this.adapters.find(adapter => {
|
|
24
|
+
if (!isArray(adapter.mediaTypes)) return false;
|
|
25
|
+
return adapter.mediaTypes.includes(mediaType);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const candidates = await this.detectAdapterCandidates(source);
|
|
29
|
+
return head(candidates);
|
|
30
|
+
}
|
|
31
|
+
use(adapter) {
|
|
32
|
+
this.adapters.push(adapter);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
async findNamespace(source, options = {}) {
|
|
36
|
+
const adapter = await this.findAdapter(source, options.mediaType);
|
|
37
|
+
return adapter?.namespace;
|
|
38
|
+
}
|
|
39
|
+
async findMediaType(source) {
|
|
40
|
+
const adapter = await this.findAdapter(source, undefined);
|
|
41
|
+
if (typeof adapter === 'undefined') {
|
|
42
|
+
return new MediaTypes().unknownMediaType;
|
|
43
|
+
}
|
|
44
|
+
if (typeof adapter.mediaTypes === 'undefined') {
|
|
45
|
+
return new MediaTypes().unknownMediaType;
|
|
46
|
+
}
|
|
47
|
+
if (typeof adapter.detectionRegExp === 'undefined') {
|
|
48
|
+
return adapter.mediaTypes.latest();
|
|
49
|
+
}
|
|
50
|
+
const {
|
|
51
|
+
detectionRegExp
|
|
52
|
+
} = adapter;
|
|
53
|
+
const matches = source.match(detectionRegExp);
|
|
54
|
+
if (matches === null) {
|
|
55
|
+
return new MediaTypes().unknownMediaType;
|
|
56
|
+
}
|
|
57
|
+
const {
|
|
58
|
+
groups
|
|
59
|
+
} = matches;
|
|
60
|
+
const version = groups?.version || groups?.version_json || groups?.version_yaml;
|
|
61
|
+
const format = groups?.version_json ? 'json' : groups?.version_yaml ? 'yaml' : 'generic';
|
|
62
|
+
if (typeof version === 'undefined') {
|
|
63
|
+
return adapter.mediaTypes.latest();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
return adapter.mediaTypes.findBy(version, format);
|
|
68
|
+
}
|
|
69
|
+
async parse(source, options = {}) {
|
|
70
|
+
let adapter;
|
|
71
|
+
try {
|
|
72
|
+
adapter = await this.findAdapter(source, options.mediaType);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new ParserError('Encountered an unexpected error while matching parser adapters against the source.', {
|
|
75
|
+
source,
|
|
76
|
+
parserOptions: options,
|
|
77
|
+
cause: error
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (isUndefined(adapter)) {
|
|
81
|
+
throw new ParserError('Source did not match any registered parsers', {
|
|
82
|
+
source,
|
|
83
|
+
parserOptions: options
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return adapter.parse(source, options);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new ParserError('Parsing encountered an unexpected error.', {
|
|
90
|
+
source,
|
|
91
|
+
parserOptions: options,
|
|
92
|
+
cause: error
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export default ApiDOMParser;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ApiDOMErrorOptions } from '@speclynx/apidom-error';
|
|
2
|
+
import { ApiDOMStructuredError } from '@speclynx/apidom-error';
|
|
3
|
+
import { MediaTypes } from '@speclynx/apidom-core';
|
|
4
|
+
import { Namespace } from '@speclynx/apidom-core';
|
|
5
|
+
import { ParseResultElement } from '@speclynx/apidom-core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
declare class ApiDOMParser {
|
|
11
|
+
private adapters;
|
|
12
|
+
protected detectAdapterCandidates(source: string): Promise<ApiDOMParserAdapter[]>;
|
|
13
|
+
protected findAdapter(source: string, mediaType: string | undefined): Promise<ApiDOMParserAdapter | undefined>;
|
|
14
|
+
use(adapter: ApiDOMParserAdapter): this;
|
|
15
|
+
findNamespace(source: string, options?: ApiDOMParserOptions): Promise<Namespace | undefined>;
|
|
16
|
+
findMediaType(source: string): Promise<string | void>;
|
|
17
|
+
parse(source: string, options?: ApiDOMParserOptions): Promise<ParseResultElement>;
|
|
18
|
+
}
|
|
19
|
+
export default ApiDOMParser;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare interface ApiDOMParserAdapter {
|
|
25
|
+
detectionRegExp?: RegExp;
|
|
26
|
+
detect?: Detect;
|
|
27
|
+
mediaTypes?: MediaTypes<string>;
|
|
28
|
+
parse: Parse;
|
|
29
|
+
namespace: Namespace;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare interface ApiDOMParserOptions {
|
|
36
|
+
readonly mediaType?: string;
|
|
37
|
+
readonly sourceMap?: boolean;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare type Detect = (source: string) => boolean | Promise<boolean>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare type Parse = (source: string, options?: ApiDOMParserOptions) => Promise<ParseResultElement>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare class ParserError extends ApiDOMStructuredError {
|
|
55
|
+
readonly source: string;
|
|
56
|
+
readonly parserOptions: ApiDOMParserOptions;
|
|
57
|
+
constructor(message?: string, structuredOptions?: ParserErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare interface ParserErrorOptions extends ApiDOMErrorOptions {
|
|
64
|
+
readonly source: string;
|
|
65
|
+
readonly parserOptions: ApiDOMParserOptions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { }
|