@aeye/resources 0.3.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/aeye-resources-converters.md +191 -0
  2. package/aeye-resources-graph.md +61 -7
  3. package/aeye-resources-parsers.md +42 -14
  4. package/aeye-resources-slicers.md +76 -8
  5. package/aeye-resources.md +24 -9
  6. package/dist/converters/data.d.ts +9 -0
  7. package/dist/converters/data.d.ts.map +1 -0
  8. package/dist/converters/data.js +78 -0
  9. package/dist/converters/data.js.map +1 -0
  10. package/dist/converters/folder.d.ts +13 -0
  11. package/dist/converters/folder.d.ts.map +1 -0
  12. package/dist/converters/folder.js +63 -0
  13. package/dist/converters/folder.js.map +1 -0
  14. package/dist/converters/index.d.ts +9 -0
  15. package/dist/converters/index.d.ts.map +1 -0
  16. package/dist/converters/index.js +22 -0
  17. package/dist/converters/index.js.map +1 -0
  18. package/dist/converters/markup.d.ts +6 -0
  19. package/dist/converters/markup.d.ts.map +1 -0
  20. package/dist/converters/markup.js +59 -0
  21. package/dist/converters/markup.js.map +1 -0
  22. package/dist/converters/pdf.d.ts +6 -0
  23. package/dist/converters/pdf.d.ts.map +1 -0
  24. package/dist/converters/pdf.js +70 -0
  25. package/dist/converters/pdf.js.map +1 -0
  26. package/dist/converters/tables.d.ts +12 -0
  27. package/dist/converters/tables.d.ts.map +1 -0
  28. package/dist/converters/tables.js +64 -0
  29. package/dist/converters/tables.js.map +1 -0
  30. package/dist/default.d.ts +9 -5
  31. package/dist/default.d.ts.map +1 -1
  32. package/dist/default.js +23 -8
  33. package/dist/default.js.map +1 -1
  34. package/dist/graph.d.ts +64 -6
  35. package/dist/graph.d.ts.map +1 -1
  36. package/dist/graph.js +127 -32
  37. package/dist/graph.js.map +1 -1
  38. package/dist/html/dom.d.ts +31 -0
  39. package/dist/html/dom.d.ts.map +1 -0
  40. package/dist/html/dom.js +194 -0
  41. package/dist/html/dom.js.map +1 -0
  42. package/dist/html/entities.d.ts +3 -0
  43. package/dist/html/entities.d.ts.map +1 -0
  44. package/dist/html/entities.js +33 -0
  45. package/dist/html/entities.js.map +1 -0
  46. package/dist/html/markdown.d.ts +30 -0
  47. package/dist/html/markdown.d.ts.map +1 -0
  48. package/dist/html/markdown.js +429 -0
  49. package/dist/html/markdown.js.map +1 -0
  50. package/dist/http/index.d.ts +5 -0
  51. package/dist/http/index.d.ts.map +1 -0
  52. package/dist/http/index.js +3 -0
  53. package/dist/http/index.js.map +1 -0
  54. package/dist/http/loader.d.ts +74 -0
  55. package/dist/http/loader.d.ts.map +1 -0
  56. package/dist/http/loader.js +248 -0
  57. package/dist/http/loader.js.map +1 -0
  58. package/dist/http/sniff.d.ts +38 -0
  59. package/dist/http/sniff.d.ts.map +1 -0
  60. package/dist/http/sniff.js +131 -0
  61. package/dist/http/sniff.js.map +1 -0
  62. package/dist/imports.d.ts +29 -0
  63. package/dist/imports.d.ts.map +1 -0
  64. package/dist/imports.js +53 -0
  65. package/dist/imports.js.map +1 -0
  66. package/dist/index.d.ts +28 -7
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +21 -6
  69. package/dist/index.js.map +1 -1
  70. package/dist/optional.d.ts +9 -0
  71. package/dist/optional.d.ts.map +1 -0
  72. package/dist/optional.js +17 -0
  73. package/dist/optional.js.map +1 -0
  74. package/dist/parsers/code.d.ts +1 -1
  75. package/dist/parsers/code.d.ts.map +1 -1
  76. package/dist/parsers/code.js +2 -2
  77. package/dist/parsers/code.js.map +1 -1
  78. package/dist/parsers/convert.d.ts +8 -0
  79. package/dist/parsers/convert.d.ts.map +1 -0
  80. package/dist/parsers/convert.js +40 -0
  81. package/dist/parsers/convert.js.map +1 -0
  82. package/dist/parsers/data.d.ts +8 -0
  83. package/dist/parsers/data.d.ts.map +1 -0
  84. package/dist/parsers/data.js +20 -0
  85. package/dist/parsers/data.js.map +1 -0
  86. package/dist/parsers/docx.d.ts +2 -2
  87. package/dist/parsers/docx.d.ts.map +1 -1
  88. package/dist/parsers/docx.js +9 -68
  89. package/dist/parsers/docx.js.map +1 -1
  90. package/dist/parsers/excel.d.ts +4 -1
  91. package/dist/parsers/excel.d.ts.map +1 -1
  92. package/dist/parsers/excel.js +17 -136
  93. package/dist/parsers/excel.js.map +1 -1
  94. package/dist/parsers/folder.d.ts +3 -0
  95. package/dist/parsers/folder.d.ts.map +1 -0
  96. package/dist/parsers/folder.js +21 -0
  97. package/dist/parsers/folder.js.map +1 -0
  98. package/dist/parsers/html.d.ts +5 -2
  99. package/dist/parsers/html.d.ts.map +1 -1
  100. package/dist/parsers/html.js +11 -33
  101. package/dist/parsers/html.js.map +1 -1
  102. package/dist/parsers/image.d.ts +1 -1
  103. package/dist/parsers/image.d.ts.map +1 -1
  104. package/dist/parsers/image.js +2 -2
  105. package/dist/parsers/image.js.map +1 -1
  106. package/dist/parsers/index.d.ts +13 -9
  107. package/dist/parsers/index.d.ts.map +1 -1
  108. package/dist/parsers/index.js +12 -9
  109. package/dist/parsers/index.js.map +1 -1
  110. package/dist/parsers/markdown.d.ts +1 -1
  111. package/dist/parsers/markdown.d.ts.map +1 -1
  112. package/dist/parsers/markdown.js +2 -2
  113. package/dist/parsers/markdown.js.map +1 -1
  114. package/dist/parsers/pdf.d.ts +2 -2
  115. package/dist/parsers/pdf.d.ts.map +1 -1
  116. package/dist/parsers/pdf.js +99 -119
  117. package/dist/parsers/pdf.js.map +1 -1
  118. package/dist/parsers/text.d.ts +1 -1
  119. package/dist/parsers/text.d.ts.map +1 -1
  120. package/dist/parsers/text.js +2 -2
  121. package/dist/parsers/text.js.map +1 -1
  122. package/dist/parsers/version.d.ts +42 -0
  123. package/dist/parsers/version.d.ts.map +1 -0
  124. package/dist/parsers/version.js +100 -0
  125. package/dist/parsers/version.js.map +1 -0
  126. package/dist/parsers/zip.d.ts +1 -1
  127. package/dist/parsers/zip.d.ts.map +1 -1
  128. package/dist/parsers/zip.js +12 -5
  129. package/dist/parsers/zip.js.map +1 -1
  130. package/dist/registry.d.ts +46 -3
  131. package/dist/registry.d.ts.map +1 -1
  132. package/dist/registry.js +97 -39
  133. package/dist/registry.js.map +1 -1
  134. package/dist/renderers/index.d.ts +2 -2
  135. package/dist/renderers/index.d.ts.map +1 -1
  136. package/dist/renderers/index.js +1 -1
  137. package/dist/renderers/index.js.map +1 -1
  138. package/dist/renderers/poppler.d.ts +1 -1
  139. package/dist/renderers/poppler.d.ts.map +1 -1
  140. package/dist/renderers/poppler.js +1 -1
  141. package/dist/renderers/poppler.js.map +1 -1
  142. package/dist/resolvers/file.d.ts +7 -1
  143. package/dist/resolvers/file.d.ts.map +1 -1
  144. package/dist/resolvers/file.js +26 -6
  145. package/dist/resolvers/file.js.map +1 -1
  146. package/dist/resolvers/folder.d.ts +18 -0
  147. package/dist/resolvers/folder.d.ts.map +1 -0
  148. package/dist/resolvers/folder.js +89 -0
  149. package/dist/resolvers/folder.js.map +1 -0
  150. package/dist/resolvers/index.d.ts +4 -3
  151. package/dist/resolvers/index.d.ts.map +1 -1
  152. package/dist/resolvers/index.js +4 -3
  153. package/dist/resolvers/index.js.map +1 -1
  154. package/dist/resolvers/url.d.ts +5 -1
  155. package/dist/resolvers/url.d.ts.map +1 -1
  156. package/dist/resolvers/url.js +13 -74
  157. package/dist/resolvers/url.js.map +1 -1
  158. package/dist/resolvers/zip.d.ts +1 -1
  159. package/dist/resolvers/zip.d.ts.map +1 -1
  160. package/dist/resolvers/zip.js +2 -2
  161. package/dist/resolvers/zip.js.map +1 -1
  162. package/dist/section-keys.d.ts +16 -0
  163. package/dist/section-keys.d.ts.map +1 -0
  164. package/dist/section-keys.js +24 -0
  165. package/dist/section-keys.js.map +1 -0
  166. package/dist/sections.d.ts +39 -0
  167. package/dist/sections.d.ts.map +1 -0
  168. package/dist/sections.js +118 -0
  169. package/dist/sections.js.map +1 -0
  170. package/dist/segmenters/default.d.ts +1 -1
  171. package/dist/segmenters/default.d.ts.map +1 -1
  172. package/dist/segmenters/default.js +1 -1
  173. package/dist/segmenters/default.js.map +1 -1
  174. package/dist/segmenters/index.d.ts +3 -3
  175. package/dist/segmenters/index.d.ts.map +1 -1
  176. package/dist/segmenters/index.js +2 -2
  177. package/dist/segmenters/index.js.map +1 -1
  178. package/dist/segmenters/langchain.d.ts +1 -1
  179. package/dist/segmenters/langchain.d.ts.map +1 -1
  180. package/dist/segmenters/langchain.js +1 -1
  181. package/dist/segmenters/langchain.js.map +1 -1
  182. package/dist/slicers/code.d.ts +30 -1
  183. package/dist/slicers/code.d.ts.map +1 -1
  184. package/dist/slicers/code.js +118 -32
  185. package/dist/slicers/code.js.map +1 -1
  186. package/dist/slicers/index.d.ts +3 -3
  187. package/dist/slicers/index.d.ts.map +1 -1
  188. package/dist/slicers/index.js +3 -3
  189. package/dist/slicers/index.js.map +1 -1
  190. package/dist/slicers/markdown.d.ts +15 -1
  191. package/dist/slicers/markdown.d.ts.map +1 -1
  192. package/dist/slicers/markdown.js +56 -27
  193. package/dist/slicers/markdown.js.map +1 -1
  194. package/dist/slicers/text.d.ts +1 -1
  195. package/dist/slicers/text.d.ts.map +1 -1
  196. package/dist/slicers/text.js +6 -4
  197. package/dist/slicers/text.js.map +1 -1
  198. package/dist/stack.d.ts +41 -0
  199. package/dist/stack.d.ts.map +1 -0
  200. package/dist/stack.js +56 -0
  201. package/dist/stack.js.map +1 -0
  202. package/dist/summaries.d.ts +11 -0
  203. package/dist/summaries.d.ts.map +1 -0
  204. package/dist/summaries.js +131 -0
  205. package/dist/summaries.js.map +1 -0
  206. package/dist/tables.d.ts +21 -0
  207. package/dist/tables.d.ts.map +1 -0
  208. package/dist/tables.js +113 -0
  209. package/dist/tables.js.map +1 -0
  210. package/dist/types.d.ts +140 -17
  211. package/dist/types.d.ts.map +1 -1
  212. package/dist/utils.d.ts +64 -3
  213. package/dist/utils.d.ts.map +1 -1
  214. package/dist/utils.js +156 -160
  215. package/dist/utils.js.map +1 -1
  216. package/dist/versions.d.ts +207 -0
  217. package/dist/versions.d.ts.map +1 -0
  218. package/dist/versions.js +217 -0
  219. package/dist/versions.js.map +1 -0
  220. package/dist/zip-internal.d.ts +9 -4
  221. package/dist/zip-internal.d.ts.map +1 -1
  222. package/dist/zip-internal.js +45 -19
  223. package/dist/zip-internal.js.map +1 -1
  224. package/package.json +33 -3
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1H,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACrI,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpH,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACtB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Optional peer dependencies, loaded on first use. A missing package is not an error: the loader gives undefined and
3
+ * the converter or parser that needs it declines or reports itself unsupported.
4
+ */
5
+ /** A cached loader for an optional module: the module once it has loaded, or undefined when it is not installed. */
6
+ export declare function optionalModule<T>(load: () => Promise<T>): () => Promise<T | undefined>;
7
+ /** The error thrown when a format's optional dependency is not installed. */
8
+ export declare function missingDependency(packageName: string, format: string): Error;
9
+ //# sourceMappingURL=optional.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oHAAoH;AACpH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAMtF;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAE5E"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Optional peer dependencies, loaded on first use. A missing package is not an error: the loader gives undefined and
3
+ * the converter or parser that needs it declines or reports itself unsupported.
4
+ */
5
+ /** A cached loader for an optional module: the module once it has loaded, or undefined when it is not installed. */
6
+ export function optionalModule(load) {
7
+ let loading;
8
+ return () => {
9
+ loading ??= load().catch(() => undefined);
10
+ return loading;
11
+ };
12
+ }
13
+ /** The error thrown when a format's optional dependency is not installed. */
14
+ export function missingDependency(packageName, format) {
15
+ return new Error(`${packageName} is not installed. Install it to read ${format} resources: npm install ${packageName}`);
16
+ }
17
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oHAAoH;AACpH,MAAM,UAAU,cAAc,CAAI,IAAsB;IACtD,IAAI,OAA2C,CAAC;IAChD,OAAO,GAAG,EAAE;QACV,OAAO,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,iBAAiB,CAAC,WAAmB,EAAE,MAAc;IACnE,OAAO,IAAI,KAAK,CAAC,GAAG,WAAW,yCAAyC,MAAM,2BAA2B,WAAW,EAAE,CAAC,CAAC;AAC1H,CAAC"}
@@ -1,3 +1,3 @@
1
- import type { ResourceParser } from "../types";
1
+ import type { ResourceParser } from "../types.js";
2
2
  export declare const codeParser: ResourceParser;
3
3
  //# sourceMappingURL=code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/parsers/code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,UAAU,CAAC;AAW7D,eAAO,MAAM,UAAU,EAAE,cAuBxB,CAAC"}
1
+ {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/parsers/code.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAWhE,eAAO,MAAM,UAAU,EAAE,cAuBxB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from "node:buffer";
2
- import { createParsedResource } from "../registry";
3
- import { CODE_TYPES, assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromCode, extractLinksFromText, } from "../utils";
2
+ import { createParsedResource } from "../registry.js";
3
+ import { CODE_TYPES, assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromCode, extractLinksFromText, } from "../utils.js";
4
4
  export const codeParser = {
5
5
  id: "code-parser",
6
6
  supportedTypes: [...CODE_TYPES],
@@ -1 +1 @@
1
- {"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/parsers/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,a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E,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ParsedResource, ParserContext, ResourceSource } from "../types.js";
2
+ /**
3
+ * Converts a source to PDF with `convertToPdf` and parses the PDF through the registry's PDF parser
4
+ * stack. Sources that aren't local files (in memory, URLs, zip entries) are written to a temporary
5
+ * file first; the PDF is parsed before that file is removed, in case the converter wrote next to it.
6
+ */
7
+ export declare function parseViaPdf(source: ResourceSource, context: ParserContext): Promise<ParsedResource | undefined>;
8
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/parsers/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAUjF;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAyBrH"}
@@ -0,0 +1,40 @@
1
+ import { createReadStream } from "node:fs";
2
+ import path from "node:path";
3
+ import { withLocalFile } from "../utils.js";
4
+ const DEFAULT_EXTENSIONS = {
5
+ docx: ".docx",
6
+ excel: ".xlsx",
7
+ csv: ".csv",
8
+ tsv: ".tsv",
9
+ };
10
+ /**
11
+ * Converts a source to PDF with `convertToPdf` and parses the PDF through the registry's PDF parser
12
+ * stack. Sources that aren't local files (in memory, URLs, zip entries) are written to a temporary
13
+ * file first; the PDF is parsed before that file is removed, in case the converter wrote next to it.
14
+ */
15
+ export async function parseViaPdf(source, context) {
16
+ const convertToPdf = context.options.convertToPdf;
17
+ if (!convertToPdf) {
18
+ return undefined;
19
+ }
20
+ const extension = path.extname(source.name ?? "") || DEFAULT_EXTENSIONS[source.type ?? ""] || "";
21
+ return withLocalFile(source, extension, async (sourceFilePath) => {
22
+ const pdfPath = await convertToPdf(sourceFilePath, context.options.signal);
23
+ const pdfSource = {
24
+ ...source,
25
+ location: pdfPath,
26
+ type: "pdf",
27
+ mimeType: "application/pdf",
28
+ // A factory, so the file is only opened if a parser actually reads it.
29
+ input: () => createReadStream(pdfPath),
30
+ metadata: { ...source.metadata, convertedFrom: source.location },
31
+ };
32
+ // Delegate through the registry so the full PDF parser stack (render + text) applies.
33
+ const result = await context.registry.parseSource(pdfSource, context.options);
34
+ result.location = source.location;
35
+ result.name = source.name ?? result.name;
36
+ result.metadata = { ...result.metadata, convertedFrom: source.type, pdfPath };
37
+ return result;
38
+ });
39
+ }
40
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/parsers/convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,kBAAkB,GAA2B;IACjD,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAsB,EAAE,OAAsB;IAC9E,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC;IAClD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IACjG,OAAO,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;QAC/D,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3E,MAAM,SAAS,GAAmB;YAChC,GAAG,MAAM;YACT,QAAQ,EAAE,OAAO;YACjB,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,iBAAiB;YAC3B,uEAAuE;YACvE,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAA8B;YACnE,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,QAAQ,EAAE;SACjE,CAAC;QACF,sFAAsF;QACtF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9E,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC;QACzC,MAAM,CAAC,QAAQ,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;QAC9E,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Json through its pretty form (see {@link jsonConverter}). It declines when the json is already pretty or does not
3
+ * parse, leaving it to the text parser.
4
+ */
5
+ export declare const jsonParser: import("../types.js").ResourceParser;
6
+ /** Yaml through its even form (see {@link yamlConverter}); it declines as the converter does, leaving it to the text parser. */
7
+ export declare const yamlParser: import("../types.js").ResourceParser;
8
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/parsers/data.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,UAAU,sCAKrB,CAAC;AAEH,gIAAgI;AAChI,eAAO,MAAM,UAAU,sCAKrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { jsonConverter, yamlConverter } from "../converters/data.js";
2
+ import { createVersionParser } from "./version.js";
3
+ /**
4
+ * Json through its pretty form (see {@link jsonConverter}). It declines when the json is already pretty or does not
5
+ * parse, leaving it to the text parser.
6
+ */
7
+ export const jsonParser = createVersionParser({
8
+ id: "json-parser",
9
+ supportedTypes: ["json"],
10
+ defaultSlicer: "text",
11
+ fallback: jsonConverter,
12
+ });
13
+ /** Yaml through its even form (see {@link yamlConverter}); it declines as the converter does, leaving it to the text parser. */
14
+ export const yamlParser = createVersionParser({
15
+ id: "yaml-parser",
16
+ supportedTypes: ["yaml"],
17
+ defaultSlicer: "text",
18
+ fallback: yamlConverter,
19
+ });
20
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/parsers/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;IAC5C,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,aAAa;CACxB,CAAC,CAAC;AAEH,gIAAgI;AAChI,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;IAC5C,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,aAAa;CACxB,CAAC,CAAC"}
@@ -1,10 +1,10 @@
1
- import type { ResourceParser } from "../types";
1
+ import type { ResourceParser } from "../types.js";
2
2
  /**
3
3
  * Higher-priority DOCX parser that converts the document to PDF and delegates to the PDF parser stack
4
4
  * for richer output (rendered pages, transcription, etc.). Declines (falls back to {@link docxParser})
5
5
  * when no `convertToPdf` function is configured or conversion fails.
6
6
  */
7
7
  export declare const docxPdfParser: ResourceParser;
8
- /** Base DOCX parser that converts the document to markdown via mammoth. Fallback in the DOCX stack. */
8
+ /** Word documents, through their markdown version (see {@link docxConverter}). Fallback in the DOCX stack. */
9
9
  export declare const docxParser: ResourceParser;
10
10
  //# sourceMappingURL=docx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"docx.d.ts","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAgC,MAAM,UAAU,CAAC;AAuB7E;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,cAkC3B,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,UAAU,EAAE,cAmCxB,CAAC"}
1
+ {"version":3,"file":"docx.d.ts","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAKlE;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,cAa3B,CAAC;AAEF,8GAA8G;AAC9G,eAAO,MAAM,UAAU,gBAKrB,CAAC"}
@@ -1,19 +1,7 @@
1
- import { Buffer } from "node:buffer";
2
- import { createReadStream } from "node:fs";
3
- import { createParsedResource } from "../registry";
4
- import { assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromText, htmlToMarkdown, toFilePath, } from "../utils";
5
- let mammothModule;
6
- async function loadMammoth() {
7
- if (mammothModule)
8
- return mammothModule;
9
- try {
10
- mammothModule = await import("mammoth");
11
- return mammothModule;
12
- }
13
- catch {
14
- return undefined;
15
- }
16
- }
1
+ import { docxConverter } from "../converters/markup.js";
2
+ import { assertNotAborted } from "../utils.js";
3
+ import { parseViaPdf } from "./convert.js";
4
+ import { createVersionParser } from "./version.js";
17
5
  /**
18
6
  * Higher-priority DOCX parser that converts the document to PDF and delegates to the PDF parser stack
19
7
  * for richer output (rendered pages, transcription, etc.). Declines (falls back to {@link docxParser})
@@ -29,61 +17,14 @@ export const docxPdfParser = {
29
17
  },
30
18
  async parse(source, context) {
31
19
  assertNotAborted(context.options.signal);
32
- const convertToPdf = context.options.convertToPdf;
33
- if (!convertToPdf) {
34
- return undefined;
35
- }
36
- const sourceFilePath = toFilePath(source.location);
37
- const pdfPath = await convertToPdf(sourceFilePath, context.options.signal);
38
- const pdfSource = {
39
- ...source,
40
- location: pdfPath,
41
- type: "pdf",
42
- mimeType: "application/pdf",
43
- input: (() => createReadStream(pdfPath))(),
44
- metadata: { ...source.metadata, convertedFrom: source.location },
45
- };
46
- // Delegate through the registry so the full PDF parser stack (render + text) applies.
47
- const result = await context.registry.parseSource(pdfSource, context.options);
48
- // Restore original location info
49
- result.location = source.location;
50
- result.name = source.name ?? result.name;
51
- result.metadata = { ...result.metadata, convertedFrom: "docx", pdfPath };
52
- return result;
20
+ return parseViaPdf(source, context);
53
21
  }
54
22
  };
55
- /** Base DOCX parser that converts the document to markdown via mammoth. Fallback in the DOCX stack. */
56
- export const docxParser = {
23
+ /** Word documents, through their markdown version (see {@link docxConverter}). Fallback in the DOCX stack. */
24
+ export const docxParser = createVersionParser({
57
25
  id: "docx-parser",
58
26
  supportedTypes: ["docx"],
59
27
  defaultSlicer: "markdown",
60
- async isSupported(_type, _context) {
61
- return Boolean(await loadMammoth());
62
- },
63
- async parse(source, context) {
64
- assertNotAborted(context.options.signal);
65
- const mammoth = await loadMammoth();
66
- if (!mammoth) {
67
- throw new Error("mammoth is not installed. Install it to parse DOCX resources: npm install mammoth");
68
- }
69
- const data = await collectInput(source.input);
70
- const result = await mammoth.convertToHtml({ buffer: Buffer.from(data) });
71
- const markdown = htmlToMarkdown(result.value);
72
- const resource = createParsedResource(source);
73
- resource.defaultSlicer = "markdown";
74
- const part = {
75
- id: createPartId(resource, 0),
76
- location: `${resource.location}#part/0`,
77
- kind: "text",
78
- text: markdown,
79
- metadata: { originalType: "docx" },
80
- links: dedupeLinks([
81
- ...extractLinksFromText(markdown, `${resource.location}#part/0`)
82
- ])
83
- };
84
- resource.parts.push(part);
85
- resource.links = part.links ?? [];
86
- return resource;
87
- }
88
- };
28
+ fallback: docxConverter,
29
+ });
89
30
  //# sourceMappingURL=docx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"docx.js","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,IAAI,aAAkB,CAAC;AAEvB,KAAK,UAAU,WAAW;IACxB,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IACxC,IAAI,CAAC;QACH,aAAa,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,EAAE,EAAE,iBAAiB;IACrB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,UAAU;IACzB,QAAQ,EAAE,EAAE;IACZ,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,OAAuB;QACtD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC;IACzE,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC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AClB,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"docx.js","sourceRoot":"","sources":["../../src/parsers/docx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,EAAE,EAAE,iBAAiB;IACrB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,UAAU;IACzB,QAAQ,EAAE,EAAE;IACZ,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,OAAuB;QACtD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC;IACzE,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEzC,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF,CAAC;AAEF,8GAA8G;AAC9G,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;IAC5C,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,UAAU;IACzB,QAAQ,EAAE,aAAa;CACxB,CAAC,CAAC"}
@@ -1,9 +1,12 @@
1
- import type { ResourceParser } from "../types";
1
+ import type { ResourceParser } from "../types.js";
2
2
  /**
3
3
  * Higher-priority spreadsheet parser that converts to PDF and delegates to the PDF parser stack when
4
4
  * PDF rendering is enabled. Declines (falls back to {@link excelParser}) when conversion/rendering is
5
5
  * not configured or conversion fails.
6
6
  */
7
7
  export declare const excelPdfParser: ResourceParser;
8
+ /** Workbooks, through their table version (see {@link workbookConverter}): one part per sheet. */
8
9
  export declare const excelParser: ResourceParser;
10
+ /** Csv and tsv files, through their table version (see {@link delimitedConverter}); no dependency needed. */
11
+ export declare const delimitedParser: ResourceParser;
9
12
  //# sourceMappingURL=excel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"excel.d.ts","sourceRoot":"","sources":["../../src/parsers/excel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,cAAc,EAAgC,MAAM,UAAU,CAAC;AAuE7F;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,cAkC5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,cAoEzB,CAAC"}
1
+ {"version":3,"file":"excel.d.ts","sourceRoot":"","sources":["../../src/parsers/excel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAKlE;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,cAmB5B,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,WAAW,gBAKtB,CAAC;AAEH,6GAA6G;AAC7G,eAAO,MAAM,eAAe,gBAK1B,CAAC"}
@@ -1,64 +1,7 @@
1
- import { Buffer } from "node:buffer";
2
- import { createReadStream } from "node:fs";
3
- import { createParsedResource } from "../registry";
4
- import { assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromText, toFilePath, } from "../utils";
5
- let xlsxModule;
6
- async function loadXlsx() {
7
- if (xlsxModule)
8
- return xlsxModule;
9
- try {
10
- xlsxModule = await import("xlsx");
11
- return xlsxModule;
12
- }
13
- catch {
14
- return undefined;
15
- }
16
- }
17
- /**
18
- * Detects separate table regions within a sheet's row data.
19
- * A table region is delimited by one or more fully empty rows.
20
- * The first non-empty row of each region is treated as headers.
21
- */
22
- function extractTablesFromRows(rows, sheetName, sheetIndex) {
23
- const tables = [];
24
- let regionStart = -1;
25
- for (let i = 0; i <= rows.length; i++) {
26
- const isEmpty = i === rows.length || rows[i].every((cell) => cell === "");
27
- if (isEmpty) {
28
- if (regionStart !== -1) {
29
- const regionRows = rows.slice(regionStart, i);
30
- if (regionRows.length >= 1) {
31
- const headers = regionRows[0];
32
- const dataRows = regionRows.slice(1);
33
- tables.push({
34
- name: tables.length === 0 ? sheetName : `${sheetName} - Table ${tables.length + 1}`,
35
- headers,
36
- rows: dataRows,
37
- sheetName,
38
- sheetIndex,
39
- });
40
- }
41
- regionStart = -1;
42
- }
43
- }
44
- else if (regionStart === -1) {
45
- regionStart = i;
46
- }
47
- }
48
- return tables;
49
- }
50
- /** Renders a table into a markdown table string. */
51
- function tableToMarkdown(table) {
52
- const lines = [];
53
- const headers = table.headers.map((h) => h || " ");
54
- lines.push(`| ${headers.join(" | ")} |`);
55
- lines.push(`| ${headers.map(() => "---").join(" | ")} |`);
56
- for (const row of table.rows) {
57
- const cells = headers.map((_, ci) => (row[ci] ?? "").replace(/\|/g, "\\|"));
58
- lines.push(`| ${cells.join(" | ")} |`);
59
- }
60
- return lines.join("\n");
61
- }
1
+ import { delimitedConverter, workbookConverter } from "../converters/tables.js";
2
+ import { assertNotAborted } from "../utils.js";
3
+ import { parseViaPdf } from "./convert.js";
4
+ import { createVersionParser } from "./version.js";
62
5
  /**
63
6
  * Higher-priority spreadsheet parser that converts to PDF and delegates to the PDF parser stack when
64
7
  * PDF rendering is enabled. Declines (falls back to {@link excelParser}) when conversion/rendering is
@@ -79,83 +22,21 @@ export const excelPdfParser = {
79
22
  if (!context.options.convertToPdf || !context.options.pdf?.renderPages) {
80
23
  return undefined;
81
24
  }
82
- const sourceFilePath = toFilePath(source.location);
83
- const pdfPath = await context.options.convertToPdf(sourceFilePath, context.options.signal);
84
- const pdfSource = {
85
- ...source,
86
- location: pdfPath,
87
- type: "pdf",
88
- mimeType: "application/pdf",
89
- input: (() => createReadStream(pdfPath))(),
90
- metadata: { ...source.metadata, convertedFrom: source.location },
91
- };
92
- // Delegate through the registry so the full PDF parser stack (render + text) applies.
93
- const result = await context.registry.parseSource(pdfSource, context.options);
94
- result.location = source.location;
95
- result.name = source.name ?? result.name;
96
- result.metadata = { ...result.metadata, convertedFrom: source.type, pdfPath };
97
- return result;
25
+ return parseViaPdf(source, context);
98
26
  }
99
27
  };
100
- export const excelParser = {
28
+ /** Workbooks, through their table version (see {@link workbookConverter}): one part per sheet. */
29
+ export const excelParser = createVersionParser({
101
30
  id: "excel-parser",
102
- supportedTypes: ["excel", "csv", "tsv"],
31
+ supportedTypes: ["excel"],
103
32
  defaultSlicer: "text",
104
- async isSupported(_type, _context) {
105
- return Boolean(await loadXlsx());
106
- },
107
- async parse(source, context) {
108
- assertNotAborted(context.options.signal);
109
- const XLSX = await loadXlsx();
110
- if (!XLSX) {
111
- throw new Error("xlsx is not installed. Install it to parse Excel/CSV resources: npm install xlsx");
112
- }
113
- const data = await collectInput(source.input);
114
- const workbook = XLSX.read(Buffer.from(data), { type: "buffer" });
115
- const resource = createParsedResource(source);
116
- resource.defaultSlicer = "text";
117
- const allTables = [];
118
- for (let i = 0; i < workbook.SheetNames.length; i++) {
119
- assertNotAborted(context.options.signal);
120
- const sheetName = workbook.SheetNames[i];
121
- const worksheet = workbook.Sheets[sheetName];
122
- const jsonData = XLSX.utils.sheet_to_json(worksheet, {
123
- header: 1,
124
- defval: "",
125
- raw: false
126
- });
127
- const rows = jsonData.filter((row) => row.some((cell) => cell !== ""));
128
- if (rows.length === 0)
129
- continue;
130
- // Extract structured tables from this sheet
131
- const tables = extractTablesFromRows(jsonData, sheetName, i);
132
- allTables.push(...tables);
133
- // Render tables as markdown for the text part
134
- const text = tables.length > 0
135
- ? tables.map((t) => tableToMarkdown(t)).join("\n\n")
136
- : rows.map((row) => row.join("\t")).join("\n");
137
- const part = {
138
- id: createPartId(resource, resource.parts.length),
139
- location: `${resource.location}#sheet/${i}`,
140
- kind: "text",
141
- text,
142
- metadata: {
143
- sheetName,
144
- sheetIndex: i,
145
- tables: tables.map((t) => ({ name: t.name, headers: t.headers, rowCount: t.rows.length })),
146
- },
147
- links: dedupeLinks([
148
- ...extractLinksFromText(text, `${resource.location}#sheet/${i}`)
149
- ])
150
- };
151
- resource.parts.push(part);
152
- }
153
- resource.metadata = {
154
- ...resource.metadata,
155
- structuredTables: allTables,
156
- };
157
- resource.links = dedupeLinks(resource.parts.flatMap((part) => part.links ?? []));
158
- return resource;
159
- }
160
- };
33
+ fallback: workbookConverter,
34
+ });
35
+ /** Csv and tsv files, through their table version (see {@link delimitedConverter}); no dependency needed. */
36
+ export const delimitedParser = createVersionParser({
37
+ id: "delimited-parser",
38
+ supportedTypes: ["csv", "tsv"],
39
+ defaultSlicer: "text",
40
+ fallback: delimitedConverter,
41
+ });
161
42
  //# sourceMappingURL=excel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"excel.js","sourceRoot":"","sources":["../../src/parsers/excel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,IAAI,UAAe,CAAC;AAEpB,KAAK,UAAU,QAAQ;IACrB,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAClC,IAAI,CAAC;QACH,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,IAAgB,EAAE,SAAiB,EAAE,UAAkB;IACpF,MAAM,MAAM,GAAqB,EAAE,CAAC;IACpC,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC;I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C,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEzC,sFAAsF;QACtF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC;YACvE,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACF,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC;IAC7C,EAAE,EAAE,cAAc;IAClB,cAAc,EAAE,CAAC,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC;AAEH,6GAA6G;AAC7G,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;IACjD,EAAE,EAAE,kBAAkB;IACtB,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IAC9B,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,kBAAkB;CAC7B,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Folders, through their markdown listing; every entry is a link, so a resource graph walks the tree. */
2
+ export declare const folderParser: import("../types.js").ResourceParser;
3
+ //# sourceMappingURL=folder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folder.d.ts","sourceRoot":"","sources":["../../src/parsers/folder.ts"],"names":[],"mappings":"AAKA,0GAA0G;AAC1G,eAAO,MAAM,YAAY,sCAevB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { folderConverter, parseFolderListing } from "../converters/folder.js";
2
+ import { createLinkId, dedupeLinks } from "../utils.js";
3
+ import { createVersionParser } from "./version.js";
4
+ /** Folders, through their markdown listing; every entry is a link, so a resource graph walks the tree. */
5
+ export const folderParser = createVersionParser({
6
+ id: "folder-parser",
7
+ supportedTypes: ["folder"],
8
+ defaultSlicer: "markdown",
9
+ fallback: folderConverter,
10
+ links: ({ raw, location }) => {
11
+ return dedupeLinks(parseFolderListing(raw).entries.map((entry, i) => ({
12
+ id: createLinkId(location, entry.location, i),
13
+ value: entry.location,
14
+ location,
15
+ kind: "resource",
16
+ title: entry.name,
17
+ ...(entry.type !== undefined ? { targetType: entry.type } : {}),
18
+ })));
19
+ },
20
+ });
21
+ //# sourceMappingURL=folder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"folder.js","sourceRoot":"","sources":["../../src/parsers/folder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;IAC9C,EAAE,EAAE,eAAe;IACnB,cAAc,EAAE,CAAC,QAAQ,CAAC;IAC1B,aAAa,EAAE,UAAU;IACzB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC3B,OAAO,WAAW,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAgB,EAAE,CAAC,CAAC;YAClF,EAAE,EAAE,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC7C,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,QAAQ;YACR,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;CACF,CAAC,CAAC"}
@@ -1,3 +1,6 @@
1
- import type { ResourceParser } from "../types";
2
- export declare const htmlParser: ResourceParser;
1
+ /**
2
+ * Html pages, through their markdown version (see {@link htmlConverter}). Links come from the raw html (every `href`
3
+ * and `src`, as written), so a crawl sees navigation the markdown leaves out.
4
+ */
5
+ export declare const htmlParser: import("../types.js").ResourceParser;
3
6
  //# sourceMappingURL=html.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/parsers/html.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,UAAU,CAAC;AAW7D,eAAO,MAAM,UAAU,EAAE,cAiCxB,CAAC"}
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/parsers/html.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,UAAU,sCAMrB,CAAC"}
@@ -1,37 +1,15 @@
1
- import { Buffer } from "node:buffer";
2
- import { createParsedResource } from "../registry";
3
- import { assertNotAborted, collectInput, createPartId, dedupeLinks, extractLinksFromHtml, extractLinksFromText, htmlToMarkdown, } from "../utils";
4
- export const htmlParser = {
1
+ import { htmlConverter } from "../converters/markup.js";
2
+ import { extractLinksFromHtml } from "../utils.js";
3
+ import { createVersionParser, rawText } from "./version.js";
4
+ /**
5
+ * Html pages, through their markdown version (see {@link htmlConverter}). Links come from the raw html (every `href`
6
+ * and `src`, as written), so a crawl sees navigation the markdown leaves out.
7
+ */
8
+ export const htmlParser = createVersionParser({
5
9
  id: "html-parser",
6
10
  supportedTypes: ["html"],
7
11
  defaultSlicer: "markdown",
8
- async parse(source, context) {
9
- assertNotAborted(context.options.signal);
10
- let rawHtml;
11
- // If renderUrl is provided and the source has a URL location, render it first
12
- if (context.options.renderUrl && /^https?:\/\//i.test(source.location)) {
13
- rawHtml = await context.options.renderUrl(source.location, context.options.signal);
14
- }
15
- else {
16
- rawHtml = Buffer.from(await collectInput(source.input)).toString("utf8");
17
- }
18
- const resource = createParsedResource(source);
19
- resource.defaultSlicer = "markdown";
20
- const text = htmlToMarkdown(rawHtml);
21
- const part = {
22
- id: createPartId(resource, 0),
23
- location: `${resource.location}#part/0`,
24
- kind: "text",
25
- text,
26
- metadata: { originalType: "html" },
27
- links: dedupeLinks([
28
- ...extractLinksFromHtml(rawHtml, `${resource.location}#part/0`),
29
- ...extractLinksFromText(text, `${resource.location}#part/0`)
30
- ])
31
- };
32
- resource.parts.push(part);
33
- resource.links = part.links ?? [];
34
- return resource;
35
- }
36
- };
12
+ fallback: htmlConverter,
13
+ links: ({ raw, location }) => extractLinksFromHtml(rawText(raw), location),
14
+ });
37
15
  //# sourceMappingURL=html.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/parsers/html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,UAAU;IACzB,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;QACzB,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEzC,IAAI,OAAe,CAAC;QACpB,8EAA8E;QAC9E,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvE,OAAO,GAAG,MAAM,OAA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AO,EAAE,MAAM,cAAc,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAC;IAC5C,EAAE,EAAE,aAAa;IACjB,cAAc,EAAE,CAAC,MAAM,CAAC;IACxB,aAAa,EAAE,UAAU;IACzB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;CAC3E,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
- import type { ResourceParser } from "../types";
1
+ import type { ResourceParser } from "../types.js";
2
2
  export declare const imageParser: ResourceParser;
3
3
  //# sourceMappingURL=image.d.ts.map