@speclynx/apidom-reference 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/CHANGELOG.md +10 -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,75 @@
1
+ import { isEmpty } from 'ramda';
2
+ import {
3
+ Element,
4
+ isParseResultElement,
5
+ ParseResultElement,
6
+ cloneShallow,
7
+ } from '@speclynx/apidom-datamodel';
8
+
9
+ import { merge as mergeOptions } from '../options/util.ts';
10
+ import parse from '../parse/index.ts';
11
+ import * as plugins from '../util/plugins.ts';
12
+ import File from '../File.ts';
13
+ import ReferenceSet from '../ReferenceSet.ts';
14
+ import ResolveError from '../errors/ResolverError.ts';
15
+ import UnmatchedResolveStrategyError from '../errors/UnmatchedResolveStrategyError.ts';
16
+ import * as url from '../util/url.ts';
17
+ import type { ReferenceOptions } from '../options/index.ts';
18
+
19
+ /**
20
+ * Resolves ApiDOM with all its external references.
21
+ */
22
+ export const resolveApiDOM = async <T extends Element>(
23
+ element: T,
24
+ options: ReferenceOptions,
25
+ ): Promise<ReferenceSet> => {
26
+ // @ts-ignore
27
+ let parseResult: ParseResultElement = element;
28
+
29
+ // wrap element into parse result
30
+ if (!isParseResultElement(element)) {
31
+ // shallow clone of the element
32
+ const elementClone = cloneShallow(element);
33
+ elementClone.classes.push('result');
34
+ parseResult = new ParseResultElement([elementClone]);
35
+ }
36
+
37
+ const sanitizedURI = url.sanitize(url.stripHash(options.resolve.baseURI));
38
+ const file = new File({
39
+ uri: sanitizedURI,
40
+ parseResult,
41
+ mediaType: options.parse.mediaType,
42
+ });
43
+
44
+ const resolveStrategies = await plugins.filter(
45
+ 'canResolve',
46
+ [file, options],
47
+ options.resolve.strategies,
48
+ );
49
+
50
+ // we couldn't find any resolve strategy for this File
51
+ if (isEmpty(resolveStrategies)) {
52
+ throw new UnmatchedResolveStrategyError(
53
+ `Could not find a resolve strategy that can resolve the file "${file.uri}"`,
54
+ );
55
+ }
56
+
57
+ try {
58
+ const { result } = await plugins.run('resolve', [file, options], resolveStrategies);
59
+ return result;
60
+ } catch (error: any) {
61
+ throw new ResolveError(`Error while resolving file "${file.uri}"`, { cause: error });
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Resolves a file with all its external references.
67
+ */
68
+ const resolve = async (uri: string, options: ReferenceOptions): Promise<ReferenceSet> => {
69
+ const parseResult = await parse(uri, options);
70
+ const mergedOptions = mergeOptions(options, { resolve: { baseURI: url.sanitize(uri) } });
71
+
72
+ return resolveApiDOM(parseResult, mergedOptions);
73
+ };
74
+
75
+ export default resolve;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+ var _Resolver = _interopRequireDefault(require("./Resolver.cjs"));
8
+ var url = _interopRequireWildcard(require("../../util/url.cjs"));
9
+ /**
10
+ * @public
11
+ */
12
+
13
+ /**
14
+ * @public
15
+ */
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ class HTTPResolver extends _Resolver.default {
21
+ timeout;
22
+ redirects;
23
+ withCredentials;
24
+ cache;
25
+ constructor(options) {
26
+ const {
27
+ name = 'http-resolver',
28
+ timeout = 5000,
29
+ redirects = 5,
30
+ withCredentials = false,
31
+ cache = false
32
+ } = options ?? {};
33
+ super({
34
+ name
35
+ });
36
+ this.timeout = timeout;
37
+ this.redirects = redirects;
38
+ this.withCredentials = withCredentials;
39
+ this.cache = cache;
40
+ }
41
+ canRead(file) {
42
+ return url.isHttpUrl(file.uri);
43
+ }
44
+ }
45
+ var _default = exports.default = HTTPResolver;
@@ -0,0 +1,37 @@
1
+ import Resolver from "./Resolver.mjs";
2
+ import * as url from "../../util/url.mjs";
3
+ /**
4
+ * @public
5
+ */
6
+ /**
7
+ * @public
8
+ */
9
+ /**
10
+ * @public
11
+ */
12
+ class HTTPResolver extends Resolver {
13
+ timeout;
14
+ redirects;
15
+ withCredentials;
16
+ cache;
17
+ constructor(options) {
18
+ const {
19
+ name = 'http-resolver',
20
+ timeout = 5000,
21
+ redirects = 5,
22
+ withCredentials = false,
23
+ cache = false
24
+ } = options ?? {};
25
+ super({
26
+ name
27
+ });
28
+ this.timeout = timeout;
29
+ this.redirects = redirects;
30
+ this.withCredentials = withCredentials;
31
+ this.cache = cache;
32
+ }
33
+ canRead(file) {
34
+ return url.isHttpUrl(file.uri);
35
+ }
36
+ }
37
+ export default HTTPResolver;
@@ -0,0 +1,58 @@
1
+ import Resolver, { ResolverOptions } from './Resolver.ts';
2
+ import * as url from '../../util/url.ts';
3
+ import File from '../../File.ts';
4
+
5
+ /**
6
+ * @public
7
+ */
8
+ export interface CacheOptions {
9
+ readonly maxEntries?: number | false;
10
+ readonly maxStaleAge?: number | false;
11
+ }
12
+
13
+ /**
14
+ * @public
15
+ */
16
+ export interface HTTPResolverOptions extends ResolverOptions {
17
+ readonly timeout?: number;
18
+ readonly redirects?: number;
19
+ readonly withCredentials?: boolean;
20
+ readonly cache?: boolean | CacheOptions;
21
+ }
22
+
23
+ /**
24
+ * @public
25
+ */
26
+ abstract class HTTPResolver extends Resolver {
27
+ protected readonly timeout: number;
28
+
29
+ protected readonly redirects: number;
30
+
31
+ protected readonly withCredentials: boolean;
32
+
33
+ protected readonly cache: boolean | CacheOptions;
34
+
35
+ constructor(options?: HTTPResolverOptions) {
36
+ const {
37
+ name = 'http-resolver',
38
+ timeout = 5000,
39
+ redirects = 5,
40
+ withCredentials = false,
41
+ cache = false,
42
+ } = options ?? {};
43
+
44
+ super({ name });
45
+ this.timeout = timeout;
46
+ this.redirects = redirects;
47
+ this.withCredentials = withCredentials;
48
+ this.cache = cache;
49
+ }
50
+
51
+ canRead(file: File): boolean {
52
+ return url.isHttpUrl(file.uri);
53
+ }
54
+
55
+ abstract getHttpClient(): unknown;
56
+ }
57
+
58
+ export default HTTPResolver;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ /**
6
+ * @public
7
+ */
8
+
9
+ /**
10
+ * @public
11
+ */
12
+ class Resolver {
13
+ name;
14
+ constructor({
15
+ name
16
+ }) {
17
+ this.name = name;
18
+ }
19
+ }
20
+ var _default = exports.default = Resolver;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @public
3
+ */
4
+
5
+ /**
6
+ * @public
7
+ */
8
+ class Resolver {
9
+ name;
10
+ constructor({
11
+ name
12
+ }) {
13
+ this.name = name;
14
+ }
15
+ }
16
+ export default Resolver;
@@ -0,0 +1,25 @@
1
+ import File from '../../File.ts';
2
+ import type { ReferenceOptions } from '../../options/index.ts';
3
+
4
+ /**
5
+ * @public
6
+ */
7
+ export interface ResolverOptions {
8
+ readonly name: string;
9
+ }
10
+
11
+ /**
12
+ * @public
13
+ */
14
+ abstract class Resolver {
15
+ public readonly name: string;
16
+
17
+ constructor({ name }: ResolverOptions) {
18
+ this.name = name;
19
+ }
20
+
21
+ public abstract canRead(file: File, options?: ReferenceOptions): boolean;
22
+ public abstract read(file: File, options?: ReferenceOptions): Promise<Buffer>;
23
+ }
24
+
25
+ export default Resolver;
@@ -0,0 +1,24 @@
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 _Resolver = _interopRequireDefault(require("../Resolver.cjs"));
7
+ var _ResolverError = _interopRequireDefault(require("../../../errors/ResolverError.cjs"));
8
+ /**
9
+ * @public
10
+ */
11
+ class FileResolver extends _Resolver.default {
12
+ constructor() {
13
+ super({
14
+ name: 'file'
15
+ });
16
+ }
17
+ canRead() {
18
+ return false;
19
+ }
20
+ read() {
21
+ throw new _ResolverError.default('FileResolver is not intended to be used in browser context');
22
+ }
23
+ }
24
+ var _default = exports.default = FileResolver;
@@ -0,0 +1,19 @@
1
+ import Resolver from "../Resolver.mjs";
2
+ import ResolverError from "../../../errors/ResolverError.mjs";
3
+ /**
4
+ * @public
5
+ */
6
+ class FileResolver extends Resolver {
7
+ constructor() {
8
+ super({
9
+ name: 'file'
10
+ });
11
+ }
12
+ canRead() {
13
+ return false;
14
+ }
15
+ read() {
16
+ throw new ResolverError('FileResolver is not intended to be used in browser context');
17
+ }
18
+ }
19
+ export default FileResolver;
@@ -0,0 +1,24 @@
1
+ import Resolver from '../Resolver.ts';
2
+ import ResolverError from '../../../errors/ResolverError.ts';
3
+
4
+ export type { default as Resolver, ResolverOptions } from '../Resolver.ts';
5
+ export type { default as File, FileOptions } from '../../../File.ts';
6
+
7
+ /**
8
+ * @public
9
+ */
10
+ class FileResolver extends Resolver {
11
+ constructor() {
12
+ super({ name: 'file' });
13
+ }
14
+
15
+ canRead(): boolean {
16
+ return false;
17
+ }
18
+
19
+ read(): Promise<Buffer> {
20
+ throw new ResolverError('FileResolver is not intended to be used in browser context');
21
+ }
22
+ }
23
+
24
+ export default FileResolver;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ exports.__esModule = true;
6
+ exports.default = void 0;
7
+ var _nodeFs = require("node:fs");
8
+ var _nodeUtil = require("node:util");
9
+ var _picomatch = _interopRequireDefault(require("picomatch"));
10
+ var _Resolver = _interopRequireDefault(require("../Resolver.cjs"));
11
+ var url = _interopRequireWildcard(require("../../../util/url.cjs"));
12
+ var _ResolverError = _interopRequireDefault(require("../../../errors/ResolverError.cjs"));
13
+ /**
14
+ * @public
15
+ */
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ class FileResolver extends _Resolver.default {
21
+ fileAllowList;
22
+ constructor(options) {
23
+ const {
24
+ fileAllowList = []
25
+ } = options ?? {};
26
+ super({
27
+ name: 'file'
28
+ });
29
+ this.fileAllowList = fileAllowList;
30
+ }
31
+ canRead(file) {
32
+ return url.isFileSystemPath(file.uri) && this.fileAllowList.some(pattern => {
33
+ return typeof pattern === 'string' ? _picomatch.default.isMatch(file.uri, pattern, {
34
+ matchBase: true
35
+ }) : pattern.test(file.uri);
36
+ });
37
+ }
38
+ async read(file) {
39
+ const fileSystemPath = url.toFileSystemPath(file.uri);
40
+ try {
41
+ return await (0, _nodeUtil.promisify)(_nodeFs.readFile)(fileSystemPath);
42
+ } catch (error) {
43
+ throw new _ResolverError.default(`Error opening file "${file.uri}"`, {
44
+ cause: error
45
+ });
46
+ }
47
+ }
48
+ }
49
+ var _default = exports.default = FileResolver;
@@ -0,0 +1,42 @@
1
+ import { readFile } from 'node:fs';
2
+ import { promisify } from 'node:util';
3
+ import picomatch from 'picomatch';
4
+ import Resolver from "../Resolver.mjs";
5
+ import * as url from "../../../util/url.mjs";
6
+ import ResolverError from "../../../errors/ResolverError.mjs";
7
+ /**
8
+ * @public
9
+ */
10
+ /**
11
+ * @public
12
+ */
13
+ class FileResolver extends Resolver {
14
+ fileAllowList;
15
+ constructor(options) {
16
+ const {
17
+ fileAllowList = []
18
+ } = options ?? {};
19
+ super({
20
+ name: 'file'
21
+ });
22
+ this.fileAllowList = fileAllowList;
23
+ }
24
+ canRead(file) {
25
+ return url.isFileSystemPath(file.uri) && this.fileAllowList.some(pattern => {
26
+ return typeof pattern === 'string' ? picomatch.isMatch(file.uri, pattern, {
27
+ matchBase: true
28
+ }) : pattern.test(file.uri);
29
+ });
30
+ }
31
+ async read(file) {
32
+ const fileSystemPath = url.toFileSystemPath(file.uri);
33
+ try {
34
+ return await promisify(readFile)(fileSystemPath);
35
+ } catch (error) {
36
+ throw new ResolverError(`Error opening file "${file.uri}"`, {
37
+ cause: error
38
+ });
39
+ }
40
+ }
41
+ }
42
+ export default FileResolver;
@@ -0,0 +1,55 @@
1
+ import { readFile } from 'node:fs';
2
+ import { promisify } from 'node:util';
3
+ import picomatch from 'picomatch';
4
+
5
+ import File from '../../../File.ts';
6
+ import Resolver, { ResolverOptions } from '../Resolver.ts';
7
+ import * as url from '../../../util/url.ts';
8
+ import ResolverError from '../../../errors/ResolverError.ts';
9
+
10
+ export type { default as Resolver, ResolverOptions } from '../Resolver.ts';
11
+ export type { default as File, FileOptions } from '../../../File.ts';
12
+
13
+ /**
14
+ * @public
15
+ */
16
+ export interface FileResolverOptions extends Omit<ResolverOptions, 'name'> {
17
+ readonly fileAllowList?: string[] | RegExp[];
18
+ }
19
+
20
+ /**
21
+ * @public
22
+ */
23
+ class FileResolver extends Resolver {
24
+ public fileAllowList: string[] | RegExp[];
25
+
26
+ constructor(options?: FileResolverOptions) {
27
+ const { fileAllowList = [] } = options ?? {};
28
+
29
+ super({ name: 'file' });
30
+ this.fileAllowList = fileAllowList;
31
+ }
32
+
33
+ canRead(file: File): boolean {
34
+ return (
35
+ url.isFileSystemPath(file.uri) &&
36
+ this.fileAllowList.some((pattern) => {
37
+ return typeof pattern === 'string'
38
+ ? picomatch.isMatch(file.uri, pattern, { matchBase: true })
39
+ : pattern.test(file.uri);
40
+ })
41
+ );
42
+ }
43
+
44
+ async read(file: File): Promise<Buffer> {
45
+ const fileSystemPath = url.toFileSystemPath(file.uri);
46
+
47
+ try {
48
+ return await promisify(readFile)(fileSystemPath);
49
+ } catch (error: unknown) {
50
+ throw new ResolverError(`Error opening file "${file.uri}"`, { cause: error });
51
+ }
52
+ }
53
+ }
54
+
55
+ export default FileResolver;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ class MemoryCache {
6
+ maxEntries;
7
+ maxStaleAge;
8
+ store = new Map();
9
+ constructor(options = {}) {
10
+ const {
11
+ maxEntries = 1024,
12
+ maxStaleAge = 3_600_000
13
+ } = options;
14
+ this.maxEntries = maxEntries;
15
+ this.maxStaleAge = maxStaleAge;
16
+ }
17
+ get(key) {
18
+ const entry = this.store.get(key);
19
+ if (entry === undefined) return undefined;
20
+
21
+ // evict if entry has exceeded maxStaleAge
22
+ if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
23
+ this.store.delete(key);
24
+ return undefined;
25
+ }
26
+ return entry.value;
27
+ }
28
+ set(key, value) {
29
+ this.store.set(key, {
30
+ value,
31
+ createdAt: Date.now()
32
+ });
33
+
34
+ // evict oldest entries if maxEntries exceeded
35
+ if (this.maxEntries !== false && this.store.size > this.maxEntries) {
36
+ const firstKey = this.store.keys().next().value;
37
+ this.store.delete(firstKey);
38
+ }
39
+ }
40
+ }
41
+ var _default = exports.default = MemoryCache;
@@ -0,0 +1,37 @@
1
+ class MemoryCache {
2
+ maxEntries;
3
+ maxStaleAge;
4
+ store = new Map();
5
+ constructor(options = {}) {
6
+ const {
7
+ maxEntries = 1024,
8
+ maxStaleAge = 3_600_000
9
+ } = options;
10
+ this.maxEntries = maxEntries;
11
+ this.maxStaleAge = maxStaleAge;
12
+ }
13
+ get(key) {
14
+ const entry = this.store.get(key);
15
+ if (entry === undefined) return undefined;
16
+
17
+ // evict if entry has exceeded maxStaleAge
18
+ if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
19
+ this.store.delete(key);
20
+ return undefined;
21
+ }
22
+ return entry.value;
23
+ }
24
+ set(key, value) {
25
+ this.store.set(key, {
26
+ value,
27
+ createdAt: Date.now()
28
+ });
29
+
30
+ // evict oldest entries if maxEntries exceeded
31
+ if (this.maxEntries !== false && this.store.size > this.maxEntries) {
32
+ const firstKey = this.store.keys().next().value;
33
+ this.store.delete(firstKey);
34
+ }
35
+ }
36
+ }
37
+ export default MemoryCache;
@@ -0,0 +1,46 @@
1
+ import type { CacheOptions } from '../../HTTPResolver.ts';
2
+
3
+ interface CacheEntry<T> {
4
+ value: T;
5
+ createdAt: number;
6
+ }
7
+
8
+ class MemoryCache<T> {
9
+ protected maxEntries: number | false;
10
+
11
+ protected maxStaleAge: number | false;
12
+
13
+ protected readonly store: Map<string, CacheEntry<T>> = new Map();
14
+
15
+ constructor(options: CacheOptions = {}) {
16
+ const { maxEntries = 1024, maxStaleAge = 3_600_000 } = options;
17
+
18
+ this.maxEntries = maxEntries;
19
+ this.maxStaleAge = maxStaleAge;
20
+ }
21
+
22
+ get(key: string): T | undefined {
23
+ const entry = this.store.get(key);
24
+ if (entry === undefined) return undefined;
25
+
26
+ // evict if entry has exceeded maxStaleAge
27
+ if (this.maxStaleAge !== false && Date.now() - entry.createdAt > this.maxStaleAge) {
28
+ this.store.delete(key);
29
+ return undefined;
30
+ }
31
+
32
+ return entry.value;
33
+ }
34
+
35
+ set(key: string, value: T): void {
36
+ this.store.set(key, { value, createdAt: Date.now() });
37
+
38
+ // evict oldest entries if maxEntries exceeded
39
+ if (this.maxEntries !== false && this.store.size > this.maxEntries) {
40
+ const firstKey = this.store.keys().next().value as string;
41
+ this.store.delete(firstKey);
42
+ }
43
+ }
44
+ }
45
+
46
+ export default MemoryCache;