@speclynx/apidom-reference 4.0.2 → 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.
Files changed (275) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +26 -27
  3. package/src/File.cjs +50 -0
  4. package/src/File.mjs +44 -0
  5. package/src/File.ts +63 -0
  6. package/src/Reference.cjs +31 -0
  7. package/src/Reference.mjs +27 -0
  8. package/src/Reference.ts +38 -0
  9. package/src/ReferenceSet.cjs +60 -0
  10. package/src/ReferenceSet.mjs +57 -0
  11. package/src/ReferenceSet.ts +73 -0
  12. package/src/bundle/index.cjs +61 -0
  13. package/src/bundle/index.mjs +55 -0
  14. package/src/bundle/index.ts +57 -0
  15. package/src/bundle/strategies/BundleStrategy.cjs +20 -0
  16. package/src/bundle/strategies/BundleStrategy.mjs +16 -0
  17. package/src/bundle/strategies/BundleStrategy.ts +27 -0
  18. package/src/bundle/strategies/openapi-3-1/index.cjs +35 -0
  19. package/src/bundle/strategies/openapi-3-1/index.mjs +29 -0
  20. package/src/bundle/strategies/openapi-3-1/index.ts +57 -0
  21. package/src/configuration/empty.cjs +9 -0
  22. package/src/configuration/empty.mjs +1 -0
  23. package/src/configuration/empty.ts +1 -0
  24. package/src/configuration/saturated.cjs +88 -0
  25. package/src/configuration/saturated.mjs +80 -0
  26. package/src/configuration/saturated.ts +72 -0
  27. package/src/dereference/index.cjs +90 -0
  28. package/src/dereference/index.mjs +83 -0
  29. package/src/dereference/index.ts +96 -0
  30. package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
  31. package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
  32. package/src/dereference/strategies/DereferenceStrategy.ts +27 -0
  33. package/src/dereference/strategies/apidom/index.cjs +89 -0
  34. package/src/dereference/strategies/apidom/index.mjs +83 -0
  35. package/src/dereference/strategies/apidom/index.ts +128 -0
  36. package/src/dereference/strategies/apidom/selectors/element-id.cjs +47 -0
  37. package/src/dereference/strategies/apidom/selectors/element-id.mjs +41 -0
  38. package/src/dereference/strategies/apidom/selectors/element-id.ts +48 -0
  39. package/src/dereference/strategies/apidom/visitor.cjs +266 -0
  40. package/src/dereference/strategies/apidom/visitor.mjs +259 -0
  41. package/src/dereference/strategies/apidom/visitor.ts +316 -0
  42. package/src/dereference/strategies/arazzo-1/index.cjs +109 -0
  43. package/src/dereference/strategies/arazzo-1/index.mjs +100 -0
  44. package/src/dereference/strategies/arazzo-1/index.ts +158 -0
  45. package/src/dereference/strategies/arazzo-1/selectors/$anchor.cjs +12 -0
  46. package/src/dereference/strategies/arazzo-1/selectors/$anchor.mjs +1 -0
  47. package/src/dereference/strategies/arazzo-1/selectors/$anchor.ts +9 -0
  48. package/src/dereference/strategies/arazzo-1/selectors/uri.cjs +8 -0
  49. package/src/dereference/strategies/arazzo-1/selectors/uri.mjs +1 -0
  50. package/src/dereference/strategies/arazzo-1/selectors/uri.ts +5 -0
  51. package/src/dereference/strategies/arazzo-1/source-descriptions.cjs +248 -0
  52. package/src/dereference/strategies/arazzo-1/source-descriptions.mjs +243 -0
  53. package/src/dereference/strategies/arazzo-1/source-descriptions.ts +317 -0
  54. package/src/dereference/strategies/arazzo-1/util.cjs +37 -0
  55. package/src/dereference/strategies/arazzo-1/util.mjs +29 -0
  56. package/src/dereference/strategies/arazzo-1/util.ts +33 -0
  57. package/src/dereference/strategies/arazzo-1/visitor.cjs +507 -0
  58. package/src/dereference/strategies/arazzo-1/visitor.mjs +500 -0
  59. package/src/dereference/strategies/arazzo-1/visitor.ts +574 -0
  60. package/src/dereference/strategies/asyncapi-2/index.cjs +94 -0
  61. package/src/dereference/strategies/asyncapi-2/index.mjs +88 -0
  62. package/src/dereference/strategies/asyncapi-2/index.ts +133 -0
  63. package/src/dereference/strategies/asyncapi-2/visitor.cjs +501 -0
  64. package/src/dereference/strategies/asyncapi-2/visitor.mjs +494 -0
  65. package/src/dereference/strategies/asyncapi-2/visitor.ts +589 -0
  66. package/src/dereference/strategies/openapi-2/index.cjs +96 -0
  67. package/src/dereference/strategies/openapi-2/index.mjs +90 -0
  68. package/src/dereference/strategies/openapi-2/index.ts +136 -0
  69. package/src/dereference/strategies/openapi-2/visitor.cjs +629 -0
  70. package/src/dereference/strategies/openapi-2/visitor.mjs +622 -0
  71. package/src/dereference/strategies/openapi-2/visitor.ts +745 -0
  72. package/src/dereference/strategies/openapi-3-0/index.cjs +96 -0
  73. package/src/dereference/strategies/openapi-3-0/index.mjs +90 -0
  74. package/src/dereference/strategies/openapi-3-0/index.ts +134 -0
  75. package/src/dereference/strategies/openapi-3-0/visitor.cjs +622 -0
  76. package/src/dereference/strategies/openapi-3-0/visitor.mjs +615 -0
  77. package/src/dereference/strategies/openapi-3-0/visitor.ts +760 -0
  78. package/src/dereference/strategies/openapi-3-1/index.cjs +99 -0
  79. package/src/dereference/strategies/openapi-3-1/index.mjs +90 -0
  80. package/src/dereference/strategies/openapi-3-1/index.ts +141 -0
  81. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +65 -0
  82. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +54 -0
  83. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts +64 -0
  84. package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +50 -0
  85. package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +42 -0
  86. package/src/dereference/strategies/openapi-3-1/selectors/uri.ts +54 -0
  87. package/src/dereference/strategies/openapi-3-1/util.cjs +68 -0
  88. package/src/dereference/strategies/openapi-3-1/util.mjs +59 -0
  89. package/src/dereference/strategies/openapi-3-1/util.ts +83 -0
  90. package/src/dereference/strategies/openapi-3-1/visitor.cjs +874 -0
  91. package/src/dereference/strategies/openapi-3-1/visitor.mjs +867 -0
  92. package/src/dereference/strategies/openapi-3-1/visitor.ts +1053 -0
  93. package/src/dereference/util.cjs +31 -0
  94. package/src/dereference/util.mjs +27 -0
  95. package/src/dereference/util.ts +29 -0
  96. package/src/errors/BundleError.cjs +10 -0
  97. package/src/errors/BundleError.mjs +7 -0
  98. package/src/errors/BundleError.ts +8 -0
  99. package/src/errors/DereferenceError.cjs +10 -0
  100. package/src/errors/DereferenceError.mjs +7 -0
  101. package/src/errors/DereferenceError.ts +8 -0
  102. package/src/errors/EvaluationElementIdError.cjs +10 -0
  103. package/src/errors/EvaluationElementIdError.mjs +7 -0
  104. package/src/errors/EvaluationElementIdError.ts +8 -0
  105. package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
  106. package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
  107. package/src/errors/EvaluationJsonSchema$anchorError.ts +8 -0
  108. package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
  109. package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
  110. package/src/errors/EvaluationJsonSchemaUriError.ts +8 -0
  111. package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
  112. package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
  113. package/src/errors/InvalidJsonSchema$anchorError.ts +12 -0
  114. package/src/errors/JsonSchema$anchorError.cjs +10 -0
  115. package/src/errors/JsonSchema$anchorError.mjs +7 -0
  116. package/src/errors/JsonSchema$anchorError.ts +8 -0
  117. package/src/errors/JsonSchemaUriError.cjs +10 -0
  118. package/src/errors/JsonSchemaUriError.mjs +7 -0
  119. package/src/errors/JsonSchemaUriError.ts +8 -0
  120. package/src/errors/MaximumBundleDepthError.cjs +11 -0
  121. package/src/errors/MaximumBundleDepthError.mjs +6 -0
  122. package/src/errors/MaximumBundleDepthError.ts +8 -0
  123. package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
  124. package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
  125. package/src/errors/MaximumDereferenceDepthError.ts +8 -0
  126. package/src/errors/MaximumResolveDepthError.cjs +11 -0
  127. package/src/errors/MaximumResolveDepthError.mjs +6 -0
  128. package/src/errors/MaximumResolveDepthError.ts +8 -0
  129. package/src/errors/ParseError.cjs +10 -0
  130. package/src/errors/ParseError.mjs +7 -0
  131. package/src/errors/ParseError.ts +8 -0
  132. package/src/errors/ParserError.cjs +11 -0
  133. package/src/errors/ParserError.mjs +6 -0
  134. package/src/errors/ParserError.ts +8 -0
  135. package/src/errors/PluginError.cjs +18 -0
  136. package/src/errors/PluginError.mjs +15 -0
  137. package/src/errors/PluginError.ts +15 -0
  138. package/src/errors/ResolveError.cjs +10 -0
  139. package/src/errors/ResolveError.mjs +7 -0
  140. package/src/errors/ResolveError.ts +8 -0
  141. package/src/errors/ResolverError.cjs +11 -0
  142. package/src/errors/ResolverError.mjs +6 -0
  143. package/src/errors/ResolverError.ts +8 -0
  144. package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
  145. package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
  146. package/src/errors/UnmatchedBundleStrategyError.ts +8 -0
  147. package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
  148. package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
  149. package/src/errors/UnmatchedDereferenceStrategyError.ts +8 -0
  150. package/src/errors/UnmatchedParserError.cjs +11 -0
  151. package/src/errors/UnmatchedParserError.mjs +6 -0
  152. package/src/errors/UnmatchedParserError.ts +8 -0
  153. package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
  154. package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
  155. package/src/errors/UnmatchedResolveStrategyError.ts +8 -0
  156. package/src/errors/UnmatchedResolverError.cjs +11 -0
  157. package/src/errors/UnmatchedResolverError.mjs +6 -0
  158. package/src/errors/UnmatchedResolverError.ts +8 -0
  159. package/src/errors/UnresolvableReferenceError.cjs +11 -0
  160. package/src/errors/UnresolvableReferenceError.mjs +6 -0
  161. package/src/errors/UnresolvableReferenceError.ts +8 -0
  162. package/src/index.cjs +146 -0
  163. package/src/index.mjs +103 -0
  164. package/src/index.ts +135 -0
  165. package/src/options/index.cjs +194 -0
  166. package/src/options/index.mjs +191 -0
  167. package/src/options/index.ts +239 -0
  168. package/src/options/util.cjs +24 -0
  169. package/src/options/util.mjs +19 -0
  170. package/src/options/util.ts +22 -0
  171. package/src/parse/index.cjs +69 -0
  172. package/src/parse/index.mjs +63 -0
  173. package/src/parse/index.ts +67 -0
  174. package/src/parse/parsers/Parser.cjs +62 -0
  175. package/src/parse/parsers/Parser.mjs +58 -0
  176. package/src/parse/parsers/Parser.ts +80 -0
  177. package/src/parse/parsers/apidom-json/index.cjs +70 -0
  178. package/src/parse/parsers/apidom-json/index.mjs +64 -0
  179. package/src/parse/parsers/apidom-json/index.ts +78 -0
  180. package/src/parse/parsers/arazzo-json-1/index.cjs +62 -0
  181. package/src/parse/parsers/arazzo-json-1/index.mjs +56 -0
  182. package/src/parse/parsers/arazzo-json-1/index.ts +76 -0
  183. package/src/parse/parsers/arazzo-json-1/source-descriptions.cjs +221 -0
  184. package/src/parse/parsers/arazzo-json-1/source-descriptions.mjs +214 -0
  185. package/src/parse/parsers/arazzo-json-1/source-descriptions.ts +280 -0
  186. package/src/parse/parsers/arazzo-yaml-1/index.cjs +62 -0
  187. package/src/parse/parsers/arazzo-yaml-1/index.mjs +56 -0
  188. package/src/parse/parsers/arazzo-yaml-1/index.ts +77 -0
  189. package/src/parse/parsers/arazzo-yaml-1/source-descriptions.cjs +12 -0
  190. package/src/parse/parsers/arazzo-yaml-1/source-descriptions.mjs +7 -0
  191. package/src/parse/parsers/arazzo-yaml-1/source-descriptions.ts +16 -0
  192. package/src/parse/parsers/asyncapi-json-2/index.cjs +54 -0
  193. package/src/parse/parsers/asyncapi-json-2/index.mjs +48 -0
  194. package/src/parse/parsers/asyncapi-json-2/index.ts +58 -0
  195. package/src/parse/parsers/asyncapi-yaml-2/index.cjs +54 -0
  196. package/src/parse/parsers/asyncapi-yaml-2/index.mjs +48 -0
  197. package/src/parse/parsers/asyncapi-yaml-2/index.ts +58 -0
  198. package/src/parse/parsers/binary/index-browser.cjs +56 -0
  199. package/src/parse/parsers/binary/index-browser.mjs +50 -0
  200. package/src/parse/parsers/binary/index-browser.ts +60 -0
  201. package/src/parse/parsers/binary/index-node.cjs +51 -0
  202. package/src/parse/parsers/binary/index-node.mjs +45 -0
  203. package/src/parse/parsers/binary/index-node.ts +57 -0
  204. package/src/parse/parsers/json/index.cjs +53 -0
  205. package/src/parse/parsers/json/index.mjs +47 -0
  206. package/src/parse/parsers/json/index.ts +52 -0
  207. package/src/parse/parsers/openapi-json-2/index.cjs +54 -0
  208. package/src/parse/parsers/openapi-json-2/index.mjs +48 -0
  209. package/src/parse/parsers/openapi-json-2/index.ts +58 -0
  210. package/src/parse/parsers/openapi-json-3-0/index.cjs +54 -0
  211. package/src/parse/parsers/openapi-json-3-0/index.mjs +48 -0
  212. package/src/parse/parsers/openapi-json-3-0/index.ts +59 -0
  213. package/src/parse/parsers/openapi-json-3-1/index.cjs +54 -0
  214. package/src/parse/parsers/openapi-json-3-1/index.mjs +48 -0
  215. package/src/parse/parsers/openapi-json-3-1/index.ts +59 -0
  216. package/src/parse/parsers/openapi-yaml-2/index.cjs +54 -0
  217. package/src/parse/parsers/openapi-yaml-2/index.mjs +48 -0
  218. package/src/parse/parsers/openapi-yaml-2/index.ts +58 -0
  219. package/src/parse/parsers/openapi-yaml-3-0/index.cjs +54 -0
  220. package/src/parse/parsers/openapi-yaml-3-0/index.mjs +48 -0
  221. package/src/parse/parsers/openapi-yaml-3-0/index.ts +59 -0
  222. package/src/parse/parsers/openapi-yaml-3-1/index.cjs +54 -0
  223. package/src/parse/parsers/openapi-yaml-3-1/index.mjs +48 -0
  224. package/src/parse/parsers/openapi-yaml-3-1/index.ts +59 -0
  225. package/src/parse/parsers/yaml-1-2/index.cjs +56 -0
  226. package/src/parse/parsers/yaml-1-2/index.mjs +50 -0
  227. package/src/parse/parsers/yaml-1-2/index.ts +60 -0
  228. package/src/resolve/index.cjs +67 -0
  229. package/src/resolve/index.mjs +60 -0
  230. package/src/resolve/index.ts +75 -0
  231. package/src/resolve/resolvers/HTTPResolver.cjs +45 -0
  232. package/src/resolve/resolvers/HTTPResolver.mjs +37 -0
  233. package/src/resolve/resolvers/HTTPResolver.ts +58 -0
  234. package/src/resolve/resolvers/Resolver.cjs +20 -0
  235. package/src/resolve/resolvers/Resolver.mjs +16 -0
  236. package/src/resolve/resolvers/Resolver.ts +25 -0
  237. package/src/resolve/resolvers/file/index-browser.cjs +24 -0
  238. package/src/resolve/resolvers/file/index-browser.mjs +19 -0
  239. package/src/resolve/resolvers/file/index-browser.ts +24 -0
  240. package/src/resolve/resolvers/file/index-node.cjs +49 -0
  241. package/src/resolve/resolvers/file/index-node.mjs +42 -0
  242. package/src/resolve/resolvers/file/index-node.ts +55 -0
  243. package/src/resolve/resolvers/http-axios/cache/MemoryCache.cjs +41 -0
  244. package/src/resolve/resolvers/http-axios/cache/MemoryCache.mjs +37 -0
  245. package/src/resolve/resolvers/http-axios/cache/MemoryCache.ts +46 -0
  246. package/src/resolve/resolvers/http-axios/index.cjs +113 -0
  247. package/src/resolve/resolvers/http-axios/index.mjs +105 -0
  248. package/src/resolve/resolvers/http-axios/index.ts +130 -0
  249. package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
  250. package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
  251. package/src/resolve/strategies/ResolveStrategy.ts +26 -0
  252. package/src/resolve/strategies/apidom/index.cjs +49 -0
  253. package/src/resolve/strategies/apidom/index.mjs +43 -0
  254. package/src/resolve/strategies/apidom/index.ts +78 -0
  255. package/src/resolve/strategies/asyncapi-2/index.cjs +49 -0
  256. package/src/resolve/strategies/asyncapi-2/index.mjs +43 -0
  257. package/src/resolve/strategies/asyncapi-2/index.ts +78 -0
  258. package/src/resolve/strategies/openapi-2/index.cjs +49 -0
  259. package/src/resolve/strategies/openapi-2/index.mjs +43 -0
  260. package/src/resolve/strategies/openapi-2/index.ts +78 -0
  261. package/src/resolve/strategies/openapi-3-0/index.cjs +49 -0
  262. package/src/resolve/strategies/openapi-3-0/index.mjs +43 -0
  263. package/src/resolve/strategies/openapi-3-0/index.ts +78 -0
  264. package/src/resolve/strategies/openapi-3-1/index.cjs +49 -0
  265. package/src/resolve/strategies/openapi-3-1/index.mjs +43 -0
  266. package/src/resolve/strategies/openapi-3-1/index.ts +78 -0
  267. package/src/resolve/util.cjs +37 -0
  268. package/src/resolve/util.mjs +30 -0
  269. package/src/resolve/util.ts +39 -0
  270. package/src/util/plugins.cjs +39 -0
  271. package/src/util/plugins.mjs +34 -0
  272. package/src/util/plugins.ts +37 -0
  273. package/src/util/url.cjs +288 -0
  274. package/src/util/url.mjs +274 -0
  275. package/src/util/url.ts +285 -0
@@ -0,0 +1,54 @@
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 _apidomParserAdapterAsyncapiYaml = require("@speclynx/apidom-parser-adapter-asyncapi-yaml-2");
8
+ var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
9
+ var _Parser = _interopRequireDefault(require("../Parser.cjs"));
10
+ /**
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ class AsyncAPIYAML2Parser extends _Parser.default {
18
+ refractorOpts;
19
+ constructor(options) {
20
+ const {
21
+ fileExtensions = [],
22
+ mediaTypes = _apidomParserAdapterAsyncapiYaml.mediaTypes,
23
+ ...rest
24
+ } = options ?? {};
25
+ super({
26
+ ...rest,
27
+ name: 'asyncapi-yaml-2',
28
+ fileExtensions,
29
+ mediaTypes
30
+ });
31
+ }
32
+ async canParse(file) {
33
+ const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
34
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
35
+ if (!hasSupportedFileExtension) return false;
36
+ if (hasSupportedMediaType) return true;
37
+ if (!hasSupportedMediaType) {
38
+ return (0, _apidomParserAdapterAsyncapiYaml.detect)(file.toString());
39
+ }
40
+ return false;
41
+ }
42
+ async parse(file) {
43
+ const source = file.toString();
44
+ try {
45
+ const parserOpts = (0, _ramda.pick)(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
46
+ return await (0, _apidomParserAdapterAsyncapiYaml.parse)(source, parserOpts);
47
+ } catch (error) {
48
+ throw new _ParserError.default(`Error parsing "${file.uri}"`, {
49
+ cause: error
50
+ });
51
+ }
52
+ }
53
+ }
54
+ var _default = exports.default = AsyncAPIYAML2Parser;
@@ -0,0 +1,48 @@
1
+ import { pick } from 'ramda';
2
+ import { parse, mediaTypes as AsyncAPI2MediaTypes, detect } from '@speclynx/apidom-parser-adapter-asyncapi-yaml-2';
3
+ import ParserError from "../../../errors/ParserError.mjs";
4
+ import Parser from "../Parser.mjs";
5
+ /**
6
+ * @public
7
+ */
8
+ /**
9
+ * @public
10
+ */
11
+ class AsyncAPIYAML2Parser extends Parser {
12
+ refractorOpts;
13
+ constructor(options) {
14
+ const {
15
+ fileExtensions = [],
16
+ mediaTypes = AsyncAPI2MediaTypes,
17
+ ...rest
18
+ } = options ?? {};
19
+ super({
20
+ ...rest,
21
+ name: 'asyncapi-yaml-2',
22
+ fileExtensions,
23
+ mediaTypes
24
+ });
25
+ }
26
+ async canParse(file) {
27
+ const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
28
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
29
+ if (!hasSupportedFileExtension) return false;
30
+ if (hasSupportedMediaType) return true;
31
+ if (!hasSupportedMediaType) {
32
+ return detect(file.toString());
33
+ }
34
+ return false;
35
+ }
36
+ async parse(file) {
37
+ const source = file.toString();
38
+ try {
39
+ const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
40
+ return await parse(source, parserOpts);
41
+ } catch (error) {
42
+ throw new ParserError(`Error parsing "${file.uri}"`, {
43
+ cause: error
44
+ });
45
+ }
46
+ }
47
+ }
48
+ export default AsyncAPIYAML2Parser;
@@ -0,0 +1,58 @@
1
+ import { pick } from 'ramda';
2
+ import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
+ import {
4
+ parse,
5
+ mediaTypes as AsyncAPI2MediaTypes,
6
+ detect,
7
+ } from '@speclynx/apidom-parser-adapter-asyncapi-yaml-2';
8
+
9
+ import ParserError from '../../../errors/ParserError.ts';
10
+ import Parser, { ParserOptions } from '../Parser.ts';
11
+ import File from '../../../File.ts';
12
+
13
+ export type { default as Parser, ParserOptions } from '../Parser.ts';
14
+ export type { default as File, FileOptions } from '../../../File.ts';
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ export interface AsyncAPIYAML2ParserOptions extends Omit<ParserOptions, 'name'> {}
20
+
21
+ /**
22
+ * @public
23
+ */
24
+ class AsyncAPIYAML2Parser extends Parser {
25
+ public refractorOpts!: object;
26
+
27
+ constructor(options?: AsyncAPIYAML2ParserOptions) {
28
+ const { fileExtensions = [], mediaTypes = AsyncAPI2MediaTypes, ...rest } = options ?? {};
29
+
30
+ super({ ...rest, name: 'asyncapi-yaml-2', fileExtensions, mediaTypes });
31
+ }
32
+
33
+ async canParse(file: File): Promise<boolean> {
34
+ const hasSupportedFileExtension =
35
+ this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
36
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
37
+
38
+ if (!hasSupportedFileExtension) return false;
39
+ if (hasSupportedMediaType) return true;
40
+ if (!hasSupportedMediaType) {
41
+ return detect(file.toString());
42
+ }
43
+ return false;
44
+ }
45
+
46
+ async parse(file: File): Promise<ParseResultElement> {
47
+ const source = file.toString();
48
+
49
+ try {
50
+ const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
51
+ return await parse(source, parserOpts);
52
+ } catch (error: unknown) {
53
+ throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
54
+ }
55
+ }
56
+ }
57
+
58
+ export default AsyncAPIYAML2Parser;
@@ -0,0 +1,56 @@
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 _apidomDatamodel = require("@speclynx/apidom-datamodel");
7
+ var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
8
+ var _Parser = _interopRequireDefault(require("../Parser.cjs"));
9
+ /**
10
+ * Everything that is not recognized by other parsers will be considered by this parser
11
+ * as a binary data and will be encoded to Base64 format.
12
+ * @public
13
+ */
14
+
15
+ /**
16
+ * @public
17
+ */
18
+ class BinaryParser extends _Parser.default {
19
+ constructor(options) {
20
+ super({
21
+ ...(options ?? {}),
22
+ name: 'binary'
23
+ });
24
+ }
25
+ canParse(file) {
26
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
27
+ }
28
+ parse(file) {
29
+ try {
30
+ /**
31
+ * More information about binary strings and btoa function in following link:
32
+ * https://developer.mozilla.org/en-US/docs/Web/API/btoa
33
+ *
34
+ * @example
35
+ * ArrayBuffer to base64 conversion:
36
+ *
37
+ * const binaryString = String.fromCharCode.apply(null, file.data);
38
+ * base64String = btoa(binaryString);
39
+ */
40
+ const binaryString = unescape(encodeURIComponent(file.toString()));
41
+ const base64String = btoa(binaryString);
42
+ const parseResultElement = new _apidomDatamodel.ParseResultElement();
43
+ if (base64String.length !== 0) {
44
+ const base64StringElement = new _apidomDatamodel.StringElement(base64String);
45
+ base64StringElement.classes.push('result');
46
+ parseResultElement.push(base64StringElement);
47
+ }
48
+ return parseResultElement;
49
+ } catch (error) {
50
+ throw new _ParserError.default(`Error parsing "${file.uri}"`, {
51
+ cause: error
52
+ });
53
+ }
54
+ }
55
+ }
56
+ var _default = exports.default = BinaryParser;
@@ -0,0 +1,50 @@
1
+ import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
2
+ import ParserError from "../../../errors/ParserError.mjs";
3
+ import Parser from "../Parser.mjs";
4
+ /**
5
+ * Everything that is not recognized by other parsers will be considered by this parser
6
+ * as a binary data and will be encoded to Base64 format.
7
+ * @public
8
+ */
9
+ /**
10
+ * @public
11
+ */
12
+ class BinaryParser extends Parser {
13
+ constructor(options) {
14
+ super({
15
+ ...(options ?? {}),
16
+ name: 'binary'
17
+ });
18
+ }
19
+ canParse(file) {
20
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
21
+ }
22
+ parse(file) {
23
+ try {
24
+ /**
25
+ * More information about binary strings and btoa function in following link:
26
+ * https://developer.mozilla.org/en-US/docs/Web/API/btoa
27
+ *
28
+ * @example
29
+ * ArrayBuffer to base64 conversion:
30
+ *
31
+ * const binaryString = String.fromCharCode.apply(null, file.data);
32
+ * base64String = btoa(binaryString);
33
+ */
34
+ const binaryString = unescape(encodeURIComponent(file.toString()));
35
+ const base64String = btoa(binaryString);
36
+ const parseResultElement = new ParseResultElement();
37
+ if (base64String.length !== 0) {
38
+ const base64StringElement = new StringElement(base64String);
39
+ base64StringElement.classes.push('result');
40
+ parseResultElement.push(base64StringElement);
41
+ }
42
+ return parseResultElement;
43
+ } catch (error) {
44
+ throw new ParserError(`Error parsing "${file.uri}"`, {
45
+ cause: error
46
+ });
47
+ }
48
+ }
49
+ }
50
+ export default BinaryParser;
@@ -0,0 +1,60 @@
1
+ import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
2
+
3
+ import ParserError from '../../../errors/ParserError.ts';
4
+ import Parser, { ParserOptions } from '../Parser.ts';
5
+ import File from '../../../File.ts';
6
+
7
+ export type { default as Parser, ParserOptions } from '../Parser.ts';
8
+ export type { default as File, FileOptions } from '../../../File.ts';
9
+
10
+ /**
11
+ * Everything that is not recognized by other parsers will be considered by this parser
12
+ * as a binary data and will be encoded to Base64 format.
13
+ * @public
14
+ */
15
+
16
+ export interface BinaryParserOptions extends Omit<ParserOptions, 'name'> {}
17
+
18
+ /**
19
+ * @public
20
+ */
21
+ class BinaryParser extends Parser {
22
+ constructor(options?: BinaryParserOptions) {
23
+ super({ ...(options ?? {}), name: 'binary' });
24
+ }
25
+
26
+ canParse(file: File): boolean {
27
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
28
+ }
29
+
30
+ parse(file: File): ParseResultElement {
31
+ try {
32
+ /**
33
+ * More information about binary strings and btoa function in following link:
34
+ * https://developer.mozilla.org/en-US/docs/Web/API/btoa
35
+ *
36
+ * @example
37
+ * ArrayBuffer to base64 conversion:
38
+ *
39
+ * const binaryString = String.fromCharCode.apply(null, file.data);
40
+ * base64String = btoa(binaryString);
41
+ */
42
+ const binaryString = unescape(encodeURIComponent(file.toString()));
43
+ const base64String = btoa(binaryString);
44
+
45
+ const parseResultElement = new ParseResultElement();
46
+
47
+ if (base64String.length !== 0) {
48
+ const base64StringElement = new StringElement(base64String);
49
+ base64StringElement.classes.push('result');
50
+ parseResultElement.push(base64StringElement);
51
+ }
52
+
53
+ return parseResultElement;
54
+ } catch (error: unknown) {
55
+ throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
56
+ }
57
+ }
58
+ }
59
+
60
+ export default BinaryParser;
@@ -0,0 +1,51 @@
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 _nodeBuffer = require("node:buffer");
7
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
8
+ var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
9
+ var _Parser = _interopRequireDefault(require("../Parser.cjs"));
10
+ /**
11
+ * Everything that is not recognized by other parsers will be considered by this parser
12
+ * as a binary data and will be encoded to Base64 format.
13
+ * @public
14
+ */
15
+
16
+ /**
17
+ * @public
18
+ */
19
+ class BinaryParser extends _Parser.default {
20
+ constructor(options) {
21
+ super({
22
+ ...(options ?? {}),
23
+ name: 'binary'
24
+ });
25
+ }
26
+ canParse(file) {
27
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
28
+ }
29
+ parse(file) {
30
+ let base64String;
31
+ try {
32
+ base64String = _nodeBuffer.Buffer.from(file.data).toString('base64');
33
+ } catch {
34
+ base64String = _nodeBuffer.Buffer.from(file.toString()).toString('base64');
35
+ }
36
+ try {
37
+ const parseResultElement = new _apidomDatamodel.ParseResultElement();
38
+ if (base64String.length !== 0) {
39
+ const base64StringElement = new _apidomDatamodel.StringElement(base64String);
40
+ base64StringElement.classes.push('result');
41
+ parseResultElement.push(base64StringElement);
42
+ }
43
+ return parseResultElement;
44
+ } catch (error) {
45
+ throw new _ParserError.default(`Error parsing "${file.uri}"`, {
46
+ cause: error
47
+ });
48
+ }
49
+ }
50
+ }
51
+ var _default = exports.default = BinaryParser;
@@ -0,0 +1,45 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
3
+ import ParserError from "../../../errors/ParserError.mjs";
4
+ import Parser from "../Parser.mjs";
5
+ /**
6
+ * Everything that is not recognized by other parsers will be considered by this parser
7
+ * as a binary data and will be encoded to Base64 format.
8
+ * @public
9
+ */
10
+ /**
11
+ * @public
12
+ */
13
+ class BinaryParser extends Parser {
14
+ constructor(options) {
15
+ super({
16
+ ...(options ?? {}),
17
+ name: 'binary'
18
+ });
19
+ }
20
+ canParse(file) {
21
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
22
+ }
23
+ parse(file) {
24
+ let base64String;
25
+ try {
26
+ base64String = Buffer.from(file.data).toString('base64');
27
+ } catch {
28
+ base64String = Buffer.from(file.toString()).toString('base64');
29
+ }
30
+ try {
31
+ const parseResultElement = new ParseResultElement();
32
+ if (base64String.length !== 0) {
33
+ const base64StringElement = new StringElement(base64String);
34
+ base64StringElement.classes.push('result');
35
+ parseResultElement.push(base64StringElement);
36
+ }
37
+ return parseResultElement;
38
+ } catch (error) {
39
+ throw new ParserError(`Error parsing "${file.uri}"`, {
40
+ cause: error
41
+ });
42
+ }
43
+ }
44
+ }
45
+ export default BinaryParser;
@@ -0,0 +1,57 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
3
+
4
+ import ParserError from '../../../errors/ParserError.ts';
5
+ import Parser, { ParserOptions } from '../Parser.ts';
6
+ import File from '../../../File.ts';
7
+
8
+ export type { default as Parser, ParserOptions } from '../Parser.ts';
9
+ export type { default as File, FileOptions } from '../../../File.ts';
10
+
11
+ /**
12
+ * Everything that is not recognized by other parsers will be considered by this parser
13
+ * as a binary data and will be encoded to Base64 format.
14
+ * @public
15
+ */
16
+
17
+ export interface BinaryParserOptions extends Omit<ParserOptions, 'name'> {}
18
+
19
+ /**
20
+ * @public
21
+ */
22
+ class BinaryParser extends Parser {
23
+ constructor(options?: BinaryParserOptions) {
24
+ super({ ...(options ?? {}), name: 'binary' });
25
+ }
26
+
27
+ canParse(file: File): boolean {
28
+ return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
29
+ }
30
+
31
+ parse(file: File): ParseResultElement {
32
+ let base64String: string;
33
+
34
+ try {
35
+ type BufferData = Parameters<typeof Buffer.from>[0];
36
+ base64String = Buffer.from(file.data as BufferData).toString('base64');
37
+ } catch {
38
+ base64String = Buffer.from(file.toString()).toString('base64');
39
+ }
40
+
41
+ try {
42
+ const parseResultElement = new ParseResultElement();
43
+
44
+ if (base64String.length !== 0) {
45
+ const base64StringElement = new StringElement(base64String);
46
+ base64StringElement.classes.push('result');
47
+ parseResultElement.push(base64StringElement);
48
+ }
49
+
50
+ return parseResultElement;
51
+ } catch (error: unknown) {
52
+ throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
53
+ }
54
+ }
55
+ }
56
+
57
+ export default BinaryParser;
@@ -0,0 +1,53 @@
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 _apidomParserAdapterJson = require("@speclynx/apidom-parser-adapter-json");
8
+ var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
9
+ var _Parser = _interopRequireDefault(require("../Parser.cjs"));
10
+ /**
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ class JSONParser extends _Parser.default {
18
+ constructor(options) {
19
+ const {
20
+ fileExtensions = [],
21
+ mediaTypes = _apidomParserAdapterJson.mediaTypes,
22
+ ...rest
23
+ } = options ?? {};
24
+ super({
25
+ ...rest,
26
+ name: 'json',
27
+ fileExtensions,
28
+ mediaTypes
29
+ });
30
+ }
31
+ async canParse(file) {
32
+ const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
33
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
34
+ if (!hasSupportedFileExtension) return false;
35
+ if (hasSupportedMediaType) return true;
36
+ if (!hasSupportedMediaType) {
37
+ return (0, _apidomParserAdapterJson.detect)(file.toString());
38
+ }
39
+ return false;
40
+ }
41
+ async parse(file) {
42
+ const source = file.toString();
43
+ try {
44
+ const parserOpts = (0, _ramda.pick)(['sourceMap', 'style', 'strict'], this);
45
+ return await (0, _apidomParserAdapterJson.parse)(source, parserOpts);
46
+ } catch (error) {
47
+ throw new _ParserError.default(`Error parsing "${file.uri}"`, {
48
+ cause: error
49
+ });
50
+ }
51
+ }
52
+ }
53
+ var _default = exports.default = JSONParser;
@@ -0,0 +1,47 @@
1
+ import { pick } from 'ramda';
2
+ import { parse, mediaTypes as JSONMediaTypes, detect } from '@speclynx/apidom-parser-adapter-json';
3
+ import ParserError from "../../../errors/ParserError.mjs";
4
+ import Parser from "../Parser.mjs";
5
+ /**
6
+ * @public
7
+ */
8
+ /**
9
+ * @public
10
+ */
11
+ class JSONParser extends Parser {
12
+ constructor(options) {
13
+ const {
14
+ fileExtensions = [],
15
+ mediaTypes = JSONMediaTypes,
16
+ ...rest
17
+ } = options ?? {};
18
+ super({
19
+ ...rest,
20
+ name: 'json',
21
+ fileExtensions,
22
+ mediaTypes
23
+ });
24
+ }
25
+ async canParse(file) {
26
+ const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
27
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
28
+ if (!hasSupportedFileExtension) return false;
29
+ if (hasSupportedMediaType) return true;
30
+ if (!hasSupportedMediaType) {
31
+ return detect(file.toString());
32
+ }
33
+ return false;
34
+ }
35
+ async parse(file) {
36
+ const source = file.toString();
37
+ try {
38
+ const parserOpts = pick(['sourceMap', 'style', 'strict'], this);
39
+ return await parse(source, parserOpts);
40
+ } catch (error) {
41
+ throw new ParserError(`Error parsing "${file.uri}"`, {
42
+ cause: error
43
+ });
44
+ }
45
+ }
46
+ }
47
+ export default JSONParser;
@@ -0,0 +1,52 @@
1
+ import { pick } from 'ramda';
2
+ import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
+ import { parse, mediaTypes as JSONMediaTypes, detect } from '@speclynx/apidom-parser-adapter-json';
4
+
5
+ import ParserError from '../../../errors/ParserError.ts';
6
+ import Parser, { ParserOptions } from '../Parser.ts';
7
+ import File from '../../../File.ts';
8
+
9
+ export type { default as Parser, ParserOptions } from '../Parser.ts';
10
+ export type { default as File, FileOptions } from '../../../File.ts';
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ export interface JSONParserOptions extends Omit<ParserOptions, 'name'> {}
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ class JSONParser extends Parser {
21
+ constructor(options?: JSONParserOptions) {
22
+ const { fileExtensions = [], mediaTypes = JSONMediaTypes, ...rest } = options ?? {};
23
+
24
+ super({ ...rest, name: 'json', fileExtensions, mediaTypes });
25
+ }
26
+
27
+ async canParse(file: File): Promise<boolean> {
28
+ const hasSupportedFileExtension =
29
+ this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
30
+ const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
31
+
32
+ if (!hasSupportedFileExtension) return false;
33
+ if (hasSupportedMediaType) return true;
34
+ if (!hasSupportedMediaType) {
35
+ return detect(file.toString());
36
+ }
37
+ return false;
38
+ }
39
+
40
+ async parse(file: File): Promise<ParseResultElement> {
41
+ const source = file.toString();
42
+
43
+ try {
44
+ const parserOpts = pick(['sourceMap', 'style', 'strict'], this);
45
+ return await parse(source, parserOpts);
46
+ } catch (error: unknown) {
47
+ throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
48
+ }
49
+ }
50
+ }
51
+
52
+ export default JSONParser;