@graphty/graph-io 0.0.0 → 0.2.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 (339) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +250 -28
  3. package/dist/chunks/children-CL3Cy0ez.js +238 -0
  4. package/dist/chunks/children-CL3Cy0ez.js.map +1 -0
  5. package/dist/chunks/escape-DyI8JofU.js +938 -0
  6. package/dist/chunks/escape-DyI8JofU.js.map +1 -0
  7. package/dist/chunks/importer-CQnJuWJw.js +2987 -0
  8. package/dist/chunks/importer-CQnJuWJw.js.map +1 -0
  9. package/dist/chunks/importer-CpCpfbxr.js +2015 -0
  10. package/dist/chunks/importer-CpCpfbxr.js.map +1 -0
  11. package/dist/chunks/importer-DbnGYr3_.js +2342 -0
  12. package/dist/chunks/importer-DbnGYr3_.js.map +1 -0
  13. package/dist/chunks/importer-GozH8DkN.js +3050 -0
  14. package/dist/chunks/importer-GozH8DkN.js.map +1 -0
  15. package/dist/chunks/records-CGpxszm1.js +605 -0
  16. package/dist/chunks/records-CGpxszm1.js.map +1 -0
  17. package/dist/chunks/text-CajMdVFy.js +189 -0
  18. package/dist/chunks/text-CajMdVFy.js.map +1 -0
  19. package/dist/chunks/writer-DxSKC7TL.js +2842 -0
  20. package/dist/chunks/writer-DxSKC7TL.js.map +1 -0
  21. package/dist/csv.d.ts +1 -0
  22. package/dist/csv.js +1702 -0
  23. package/dist/csv.js.map +1 -0
  24. package/dist/dot.d.ts +1 -0
  25. package/dist/dot.js +8 -0
  26. package/dist/dot.js.map +1 -0
  27. package/dist/gexf.d.ts +1 -0
  28. package/dist/gexf.js +3466 -0
  29. package/dist/gexf.js.map +1 -0
  30. package/dist/gml.d.ts +1 -0
  31. package/dist/gml.js +2647 -0
  32. package/dist/gml.js.map +1 -0
  33. package/dist/graph-io.d.ts +1 -0
  34. package/dist/graph-io.js +790 -0
  35. package/dist/graph-io.js.map +1 -0
  36. package/dist/graphml.d.ts +1 -0
  37. package/dist/graphml.js +8 -0
  38. package/dist/graphml.js.map +1 -0
  39. package/dist/json.d.ts +1 -0
  40. package/dist/json.js +11 -0
  41. package/dist/json.js.map +1 -0
  42. package/dist/neo4j.d.ts +1 -0
  43. package/dist/neo4j.js +2046 -0
  44. package/dist/neo4j.js.map +1 -0
  45. package/dist/pajek.d.ts +1 -0
  46. package/dist/pajek.js +8 -0
  47. package/dist/pajek.js.map +1 -0
  48. package/dist/src/children.d.ts +134 -0
  49. package/dist/src/children.d.ts.map +1 -0
  50. package/dist/src/children.js +274 -0
  51. package/dist/src/children.js.map +1 -0
  52. package/dist/src/common/attributes.d.ts +229 -0
  53. package/dist/src/common/attributes.d.ts.map +1 -0
  54. package/dist/src/common/attributes.js +368 -0
  55. package/dist/src/common/attributes.js.map +1 -0
  56. package/dist/src/common/codes.d.ts +105 -0
  57. package/dist/src/common/codes.d.ts.map +1 -0
  58. package/dist/src/common/codes.js +107 -0
  59. package/dist/src/common/codes.js.map +1 -0
  60. package/dist/src/common/declared-types.d.ts +84 -0
  61. package/dist/src/common/declared-types.d.ts.map +1 -0
  62. package/dist/src/common/declared-types.js +326 -0
  63. package/dist/src/common/declared-types.js.map +1 -0
  64. package/dist/src/common/direction.d.ts +206 -0
  65. package/dist/src/common/direction.d.ts.map +1 -0
  66. package/dist/src/common/direction.js +370 -0
  67. package/dist/src/common/direction.js.map +1 -0
  68. package/dist/src/common/escape.d.ts +92 -0
  69. package/dist/src/common/escape.d.ts.map +1 -0
  70. package/dist/src/common/escape.js +212 -0
  71. package/dist/src/common/escape.js.map +1 -0
  72. package/dist/src/common/export.d.ts +249 -0
  73. package/dist/src/common/export.d.ts.map +1 -0
  74. package/dist/src/common/export.js +594 -0
  75. package/dist/src/common/export.js.map +1 -0
  76. package/dist/src/common/format.d.ts +59 -0
  77. package/dist/src/common/format.d.ts.map +1 -0
  78. package/dist/src/common/format.js +106 -0
  79. package/dist/src/common/format.js.map +1 -0
  80. package/dist/src/common/ids.d.ts +83 -0
  81. package/dist/src/common/ids.d.ts.map +1 -0
  82. package/dist/src/common/ids.js +158 -0
  83. package/dist/src/common/ids.js.map +1 -0
  84. package/dist/src/common/input.d.ts +100 -0
  85. package/dist/src/common/input.d.ts.map +1 -0
  86. package/dist/src/common/input.js +335 -0
  87. package/dist/src/common/input.js.map +1 -0
  88. package/dist/src/common/lists.d.ts +34 -0
  89. package/dist/src/common/lists.d.ts.map +1 -0
  90. package/dist/src/common/lists.js +185 -0
  91. package/dist/src/common/lists.js.map +1 -0
  92. package/dist/src/common/options.d.ts +108 -0
  93. package/dist/src/common/options.d.ts.map +1 -0
  94. package/dist/src/common/options.js +265 -0
  95. package/dist/src/common/options.js.map +1 -0
  96. package/dist/src/common/report.d.ts +187 -0
  97. package/dist/src/common/report.d.ts.map +1 -0
  98. package/dist/src/common/report.js +274 -0
  99. package/dist/src/common/report.js.map +1 -0
  100. package/dist/src/common/temporal.d.ts +71 -0
  101. package/dist/src/common/temporal.d.ts.map +1 -0
  102. package/dist/src/common/temporal.js +266 -0
  103. package/dist/src/common/temporal.js.map +1 -0
  104. package/dist/src/common/text.d.ts +104 -0
  105. package/dist/src/common/text.d.ts.map +1 -0
  106. package/dist/src/common/text.js +255 -0
  107. package/dist/src/common/text.js.map +1 -0
  108. package/dist/src/common/weights.d.ts +77 -0
  109. package/dist/src/common/weights.d.ts.map +1 -0
  110. package/dist/src/common/weights.js +156 -0
  111. package/dist/src/common/weights.js.map +1 -0
  112. package/dist/src/common/writer.d.ts +51 -0
  113. package/dist/src/common/writer.d.ts.map +1 -0
  114. package/dist/src/common/writer.js +108 -0
  115. package/dist/src/common/writer.js.map +1 -0
  116. package/dist/src/common/xml.d.ts +245 -0
  117. package/dist/src/common/xml.d.ts.map +1 -0
  118. package/dist/src/common/xml.js +942 -0
  119. package/dist/src/common/xml.js.map +1 -0
  120. package/dist/src/formats/csv/exporter.d.ts +70 -0
  121. package/dist/src/formats/csv/exporter.d.ts.map +1 -0
  122. package/dist/src/formats/csv/exporter.js +682 -0
  123. package/dist/src/formats/csv/exporter.js.map +1 -0
  124. package/dist/src/formats/csv/header.d.ts +66 -0
  125. package/dist/src/formats/csv/header.d.ts.map +1 -0
  126. package/dist/src/formats/csv/header.js +152 -0
  127. package/dist/src/formats/csv/header.js.map +1 -0
  128. package/dist/src/formats/csv/importer.d.ts +82 -0
  129. package/dist/src/formats/csv/importer.d.ts.map +1 -0
  130. package/dist/src/formats/csv/importer.js +849 -0
  131. package/dist/src/formats/csv/importer.js.map +1 -0
  132. package/dist/src/formats/csv/index.d.ts +60 -0
  133. package/dist/src/formats/csv/index.d.ts.map +1 -0
  134. package/dist/src/formats/csv/index.js +63 -0
  135. package/dist/src/formats/csv/index.js.map +1 -0
  136. package/dist/src/formats/csv/records.d.ts +188 -0
  137. package/dist/src/formats/csv/records.d.ts.map +1 -0
  138. package/dist/src/formats/csv/records.js +702 -0
  139. package/dist/src/formats/csv/records.js.map +1 -0
  140. package/dist/src/formats/csv/values.d.ts +105 -0
  141. package/dist/src/formats/csv/values.d.ts.map +1 -0
  142. package/dist/src/formats/csv/values.js +192 -0
  143. package/dist/src/formats/csv/values.js.map +1 -0
  144. package/dist/src/formats/dot/exporter.d.ts +52 -0
  145. package/dist/src/formats/dot/exporter.d.ts.map +1 -0
  146. package/dist/src/formats/dot/exporter.js +836 -0
  147. package/dist/src/formats/dot/exporter.js.map +1 -0
  148. package/dist/src/formats/dot/importer.d.ts +102 -0
  149. package/dist/src/formats/dot/importer.d.ts.map +1 -0
  150. package/dist/src/formats/dot/importer.js +1291 -0
  151. package/dist/src/formats/dot/importer.js.map +1 -0
  152. package/dist/src/formats/dot/index.d.ts +7 -0
  153. package/dist/src/formats/dot/index.d.ts.map +1 -0
  154. package/dist/src/formats/dot/index.js +7 -0
  155. package/dist/src/formats/dot/index.js.map +1 -0
  156. package/dist/src/formats/dot/names.d.ts +29 -0
  157. package/dist/src/formats/dot/names.d.ts.map +1 -0
  158. package/dist/src/formats/dot/names.js +28 -0
  159. package/dist/src/formats/dot/names.js.map +1 -0
  160. package/dist/src/formats/dot/tokenizer.d.ts +114 -0
  161. package/dist/src/formats/dot/tokenizer.d.ts.map +1 -0
  162. package/dist/src/formats/dot/tokenizer.js +341 -0
  163. package/dist/src/formats/dot/tokenizer.js.map +1 -0
  164. package/dist/src/formats/gexf/exporter.d.ts +56 -0
  165. package/dist/src/formats/gexf/exporter.d.ts.map +1 -0
  166. package/dist/src/formats/gexf/exporter.js +1395 -0
  167. package/dist/src/formats/gexf/exporter.js.map +1 -0
  168. package/dist/src/formats/gexf/importer.d.ts +73 -0
  169. package/dist/src/formats/gexf/importer.d.ts.map +1 -0
  170. package/dist/src/formats/gexf/importer.js +1880 -0
  171. package/dist/src/formats/gexf/importer.js.map +1 -0
  172. package/dist/src/formats/gexf/index.d.ts +96 -0
  173. package/dist/src/formats/gexf/index.d.ts.map +1 -0
  174. package/dist/src/formats/gexf/index.js +97 -0
  175. package/dist/src/formats/gexf/index.js.map +1 -0
  176. package/dist/src/formats/gexf/schema.d.ts +135 -0
  177. package/dist/src/formats/gexf/schema.d.ts.map +1 -0
  178. package/dist/src/formats/gexf/schema.js +323 -0
  179. package/dist/src/formats/gexf/schema.js.map +1 -0
  180. package/dist/src/formats/gml/exporter.d.ts +69 -0
  181. package/dist/src/formats/gml/exporter.d.ts.map +1 -0
  182. package/dist/src/formats/gml/exporter.js +1093 -0
  183. package/dist/src/formats/gml/exporter.js.map +1 -0
  184. package/dist/src/formats/gml/importer.d.ts +66 -0
  185. package/dist/src/formats/gml/importer.d.ts.map +1 -0
  186. package/dist/src/formats/gml/importer.js +1331 -0
  187. package/dist/src/formats/gml/importer.js.map +1 -0
  188. package/dist/src/formats/gml/index.d.ts +85 -0
  189. package/dist/src/formats/gml/index.d.ts.map +1 -0
  190. package/dist/src/formats/gml/index.js +88 -0
  191. package/dist/src/formats/gml/index.js.map +1 -0
  192. package/dist/src/formats/gml/syntax.d.ts +186 -0
  193. package/dist/src/formats/gml/syntax.d.ts.map +1 -0
  194. package/dist/src/formats/gml/syntax.js +467 -0
  195. package/dist/src/formats/gml/syntax.js.map +1 -0
  196. package/dist/src/formats/graphml/constants.d.ts +169 -0
  197. package/dist/src/formats/graphml/constants.d.ts.map +1 -0
  198. package/dist/src/formats/graphml/constants.js +165 -0
  199. package/dist/src/formats/graphml/constants.js.map +1 -0
  200. package/dist/src/formats/graphml/exporter.d.ts +34 -0
  201. package/dist/src/formats/graphml/exporter.d.ts.map +1 -0
  202. package/dist/src/formats/graphml/exporter.js +1176 -0
  203. package/dist/src/formats/graphml/exporter.js.map +1 -0
  204. package/dist/src/formats/graphml/importer.d.ts +31 -0
  205. package/dist/src/formats/graphml/importer.d.ts.map +1 -0
  206. package/dist/src/formats/graphml/importer.js +1607 -0
  207. package/dist/src/formats/graphml/importer.js.map +1 -0
  208. package/dist/src/formats/graphml/index.d.ts +8 -0
  209. package/dist/src/formats/graphml/index.d.ts.map +1 -0
  210. package/dist/src/formats/graphml/index.js +8 -0
  211. package/dist/src/formats/graphml/index.js.map +1 -0
  212. package/dist/src/formats/graphml/tree.d.ts +72 -0
  213. package/dist/src/formats/graphml/tree.d.ts.map +1 -0
  214. package/dist/src/formats/graphml/tree.js +290 -0
  215. package/dist/src/formats/graphml/tree.js.map +1 -0
  216. package/dist/src/formats/json/dialect.d.ts +125 -0
  217. package/dist/src/formats/json/dialect.d.ts.map +1 -0
  218. package/dist/src/formats/json/dialect.js +262 -0
  219. package/dist/src/formats/json/dialect.js.map +1 -0
  220. package/dist/src/formats/json/exporter.d.ts +89 -0
  221. package/dist/src/formats/json/exporter.d.ts.map +1 -0
  222. package/dist/src/formats/json/exporter.js +1358 -0
  223. package/dist/src/formats/json/exporter.js.map +1 -0
  224. package/dist/src/formats/json/importer.d.ts +108 -0
  225. package/dist/src/formats/json/importer.d.ts.map +1 -0
  226. package/dist/src/formats/json/importer.js +1838 -0
  227. package/dist/src/formats/json/importer.js.map +1 -0
  228. package/dist/src/formats/json/index.d.ts +8 -0
  229. package/dist/src/formats/json/index.d.ts.map +1 -0
  230. package/dist/src/formats/json/index.js +8 -0
  231. package/dist/src/formats/json/index.js.map +1 -0
  232. package/dist/src/formats/neo4j/exporter.d.ts +68 -0
  233. package/dist/src/formats/neo4j/exporter.d.ts.map +1 -0
  234. package/dist/src/formats/neo4j/exporter.js +1055 -0
  235. package/dist/src/formats/neo4j/exporter.js.map +1 -0
  236. package/dist/src/formats/neo4j/header.d.ts +52 -0
  237. package/dist/src/formats/neo4j/header.d.ts.map +1 -0
  238. package/dist/src/formats/neo4j/header.js +131 -0
  239. package/dist/src/formats/neo4j/header.js.map +1 -0
  240. package/dist/src/formats/neo4j/importer.d.ts +73 -0
  241. package/dist/src/formats/neo4j/importer.d.ts.map +1 -0
  242. package/dist/src/formats/neo4j/importer.js +932 -0
  243. package/dist/src/formats/neo4j/importer.js.map +1 -0
  244. package/dist/src/formats/neo4j/index.d.ts +79 -0
  245. package/dist/src/formats/neo4j/index.d.ts.map +1 -0
  246. package/dist/src/formats/neo4j/index.js +83 -0
  247. package/dist/src/formats/neo4j/index.js.map +1 -0
  248. package/dist/src/formats/pajek/exporter.d.ts +58 -0
  249. package/dist/src/formats/pajek/exporter.d.ts.map +1 -0
  250. package/dist/src/formats/pajek/exporter.js +825 -0
  251. package/dist/src/formats/pajek/exporter.js.map +1 -0
  252. package/dist/src/formats/pajek/importer.d.ts +88 -0
  253. package/dist/src/formats/pajek/importer.d.ts.map +1 -0
  254. package/dist/src/formats/pajek/importer.js +1047 -0
  255. package/dist/src/formats/pajek/importer.js.map +1 -0
  256. package/dist/src/formats/pajek/index.d.ts +7 -0
  257. package/dist/src/formats/pajek/index.d.ts.map +1 -0
  258. package/dist/src/formats/pajek/index.js +7 -0
  259. package/dist/src/formats/pajek/index.js.map +1 -0
  260. package/dist/src/formats/pajek/syntax.d.ts +112 -0
  261. package/dist/src/formats/pajek/syntax.d.ts.map +1 -0
  262. package/dist/src/formats/pajek/syntax.js +269 -0
  263. package/dist/src/formats/pajek/syntax.js.map +1 -0
  264. package/dist/src/index.d.ts +35 -0
  265. package/dist/src/index.d.ts.map +1 -0
  266. package/dist/src/index.js +39 -0
  267. package/dist/src/index.js.map +1 -0
  268. package/dist/src/registry.d.ts +207 -0
  269. package/dist/src/registry.d.ts.map +1 -0
  270. package/dist/src/registry.js +481 -0
  271. package/dist/src/registry.js.map +1 -0
  272. package/dist/src/sniff.d.ts +104 -0
  273. package/dist/src/sniff.d.ts.map +1 -0
  274. package/dist/src/sniff.js +357 -0
  275. package/dist/src/sniff.js.map +1 -0
  276. package/dist/src/types.d.ts +238 -0
  277. package/dist/src/types.d.ts.map +1 -0
  278. package/dist/src/types.js +29 -0
  279. package/dist/src/types.js.map +1 -0
  280. package/dist/tsconfig.build.tsbuildinfo +1 -0
  281. package/package.json +122 -7
  282. package/src/children.ts +335 -0
  283. package/src/common/attributes.ts +520 -0
  284. package/src/common/codes.ts +153 -0
  285. package/src/common/declared-types.ts +374 -0
  286. package/src/common/direction.ts +518 -0
  287. package/src/common/escape.ts +231 -0
  288. package/src/common/export.ts +817 -0
  289. package/src/common/format.ts +111 -0
  290. package/src/common/ids.ts +176 -0
  291. package/src/common/input.ts +378 -0
  292. package/src/common/lists.ts +196 -0
  293. package/src/common/options.ts +377 -0
  294. package/src/common/report.ts +352 -0
  295. package/src/common/temporal.ts +302 -0
  296. package/src/common/text.ts +294 -0
  297. package/src/common/weights.ts +202 -0
  298. package/src/common/writer.ts +123 -0
  299. package/src/common/xml.ts +1053 -0
  300. package/src/formats/csv/exporter.ts +894 -0
  301. package/src/formats/csv/header.ts +172 -0
  302. package/src/formats/csv/importer.ts +1104 -0
  303. package/src/formats/csv/index.ts +88 -0
  304. package/src/formats/csv/records.ts +813 -0
  305. package/src/formats/csv/values.ts +224 -0
  306. package/src/formats/dot/exporter.ts +1014 -0
  307. package/src/formats/dot/importer.ts +1549 -0
  308. package/src/formats/dot/index.ts +7 -0
  309. package/src/formats/dot/names.ts +40 -0
  310. package/src/formats/dot/tokenizer.ts +384 -0
  311. package/src/formats/gexf/exporter.ts +1696 -0
  312. package/src/formats/gexf/importer.ts +2333 -0
  313. package/src/formats/gexf/index.ts +142 -0
  314. package/src/formats/gexf/schema.ts +361 -0
  315. package/src/formats/gml/exporter.ts +1404 -0
  316. package/src/formats/gml/importer.ts +1591 -0
  317. package/src/formats/gml/index.ts +128 -0
  318. package/src/formats/gml/syntax.ts +545 -0
  319. package/src/formats/graphml/constants.ts +225 -0
  320. package/src/formats/graphml/exporter.ts +1458 -0
  321. package/src/formats/graphml/importer.ts +2027 -0
  322. package/src/formats/graphml/index.ts +8 -0
  323. package/src/formats/graphml/tree.ts +318 -0
  324. package/src/formats/json/dialect.ts +317 -0
  325. package/src/formats/json/exporter.ts +1616 -0
  326. package/src/formats/json/importer.ts +2271 -0
  327. package/src/formats/json/index.ts +8 -0
  328. package/src/formats/neo4j/exporter.ts +1287 -0
  329. package/src/formats/neo4j/header.ts +156 -0
  330. package/src/formats/neo4j/importer.ts +1220 -0
  331. package/src/formats/neo4j/index.ts +116 -0
  332. package/src/formats/pajek/exporter.ts +1000 -0
  333. package/src/formats/pajek/importer.ts +1311 -0
  334. package/src/formats/pajek/index.ts +7 -0
  335. package/src/formats/pajek/syntax.ts +307 -0
  336. package/src/index.ts +244 -0
  337. package/src/registry.ts +617 -0
  338. package/src/sniff.ts +397 -0
  339. package/src/types.ts +262 -0
@@ -0,0 +1,481 @@
1
+ /**
2
+ * The importer / exporter registry (design sections 8.2 and 8.4): the eight built-in formats
3
+ * registered by name, `sniff()` over them, and the two conveniences for callers who do not own a
4
+ * sink: `importGraph()` sniffs the format, creates a builder seeded from the common options
5
+ * (`directed: true` as a placeholder; the importer sets the real value), imports and freezes;
6
+ * `exportGraph()` looks the exporter up by name. A caller who owns a builder uses the importer
7
+ * objects directly (the subpath exports) and this module never touches their sink.
8
+ */
9
+ import { GraphBuilder, GraphFormatError, } from "@graphty/graph-format";
10
+ import { throwIfAborted } from "./common/input.js";
11
+ import { ImportReportBuilder } from "./common/report.js";
12
+ import { csvExporter, csvImporter } from "./formats/csv/index.js";
13
+ import { dotExporter, dotImporter } from "./formats/dot/index.js";
14
+ import { gexfExporter, gexfImporter } from "./formats/gexf/index.js";
15
+ import { gmlExporter, gmlImporter } from "./formats/gml/index.js";
16
+ import { graphmlExporter, graphmlImporter } from "./formats/graphml/index.js";
17
+ import { jsonExporter, jsonImporter } from "./formats/json/index.js";
18
+ import { neo4jExporter, neo4jImporter } from "./formats/neo4j/index.js";
19
+ import { pajekExporter, pajekImporter } from "./formats/pajek/index.js";
20
+ import { rankFormats, SNIFF_HEAD_BYTES } from "./sniff.js";
21
+ /** The issue code of an input whose format no registered importer recognises. */
22
+ export const UNKNOWN_FORMAT_CODE = "E_UNKNOWN_FORMAT";
23
+ /** The keys of ImportGraphOptions that belong to the registry, never to an importer. */
24
+ const REGISTRY_KEYS = new Set(["format", "filename", "mimeType", "builder", "freeze"]);
25
+ /**
26
+ * A registry of importers and exporters by format name. Registration order is the tie-break
27
+ * order of sniffing (design section 8.2); the default registry lists the built-in formats in the
28
+ * order of GRAPH_FORMATS.
29
+ */
30
+ export class FormatRegistry {
31
+ constructor() {
32
+ this.importerMap = new Map();
33
+ this.exporterMap = new Map();
34
+ }
35
+ /**
36
+ * Register an importer under its format name, replacing one of the same name in place (the
37
+ * original registration order is kept).
38
+ * @param importer - the importer
39
+ * @returns this registry, for chaining
40
+ */
41
+ registerImporter(importer) {
42
+ this.importerMap.set(importer.format, importer);
43
+ return this;
44
+ }
45
+ /**
46
+ * Register an exporter under its format name, replacing one of the same name.
47
+ * @param exporter - the exporter
48
+ * @returns this registry, for chaining
49
+ */
50
+ registerExporter(exporter) {
51
+ this.exporterMap.set(exporter.format, exporter);
52
+ return this;
53
+ }
54
+ /**
55
+ * The importer of a format.
56
+ * @param format - the format name
57
+ * @returns the importer; E_UNSUPPORTED when none is registered
58
+ */
59
+ importer(format) {
60
+ const importer = this.importerMap.get(format);
61
+ if (importer === undefined) {
62
+ throw unknownFormat("importer", format, this.importerMap.keys());
63
+ }
64
+ return importer;
65
+ }
66
+ /**
67
+ * The exporter of a format.
68
+ * @param format - the format name
69
+ * @returns the exporter; E_UNSUPPORTED when none is registered
70
+ */
71
+ exporter(format) {
72
+ const exporter = this.exporterMap.get(format);
73
+ if (exporter === undefined) {
74
+ throw unknownFormat("exporter", format, this.exporterMap.keys());
75
+ }
76
+ return exporter;
77
+ }
78
+ /**
79
+ * Whether an importer is registered for a format.
80
+ * @param format - the format name
81
+ * @returns true when importer(format) would succeed
82
+ */
83
+ hasImporter(format) {
84
+ return this.importerMap.has(format);
85
+ }
86
+ /**
87
+ * Whether an exporter is registered for a format.
88
+ * @param format - the format name
89
+ * @returns true when exporter(format) would succeed
90
+ */
91
+ hasExporter(format) {
92
+ return this.exporterMap.has(format);
93
+ }
94
+ /**
95
+ * Every registered importer, in registration order.
96
+ * @returns the importers
97
+ */
98
+ importers() {
99
+ return [...this.importerMap.values()];
100
+ }
101
+ /**
102
+ * Every registered exporter, in registration order.
103
+ * @returns the exporters
104
+ */
105
+ exporters() {
106
+ return [...this.exporterMap.values()];
107
+ }
108
+ /**
109
+ * The names of every format with an importer or an exporter, importers' order first.
110
+ * @returns the format names, each once
111
+ */
112
+ formats() {
113
+ return [...new Set([...this.importerMap.keys(), ...this.exporterMap.keys()])];
114
+ }
115
+ /**
116
+ * Rank the registered importers for an input (design section 8.2; the successor of
117
+ * graphty-element's detectFormat()).
118
+ * @param hints - the filename, MIME type and / or head of the input
119
+ * @returns the candidates, best first; empty when nothing matches
120
+ */
121
+ sniffAll(hints) {
122
+ return rankFormats(hints, this.importerMap.values());
123
+ }
124
+ /**
125
+ * The best importer for an input, or null when no registered importer claims it.
126
+ * @param hints - the filename, MIME type and / or head of the input
127
+ * @returns the best candidate, or null
128
+ */
129
+ sniff(hints) {
130
+ const ranked = this.sniffAll(hints);
131
+ return ranked.length > 0 ? ranked[0] : null;
132
+ }
133
+ /**
134
+ * Read an input into a fresh builder and freeze it (design section 8.4: for callers who do not
135
+ * own a sink). The format is the one named in the options, else sniffed from the filename,
136
+ * the MIME type and the first bytes of the content; the builder is seeded from the common
137
+ * options with `directed: true` as a placeholder that the importer overrides from the file.
138
+ * @param input - the text, bytes, stream or chunks to read
139
+ * @param options - the format, hints, common and format-specific import options
140
+ * @returns the snapshot, the import report and the freeze report
141
+ */
142
+ async importGraph(input, options = {}) {
143
+ const requested = options.format ?? "auto";
144
+ let importer;
145
+ let sniff = null;
146
+ let source = input;
147
+ let peeked = null;
148
+ if (requested === "auto") {
149
+ peeked = await peekHead(input, SNIFF_HEAD_BYTES, options.signal ?? null);
150
+ source = peeked.input;
151
+ sniff = this.sniff({ filename: options.filename, mimeType: options.mimeType, head: peeked.head });
152
+ if (sniff === null) {
153
+ const report = new ImportReportBuilder("unknown", 0);
154
+ return report.fail(UNKNOWN_FORMAT_CODE, `no registered importer recognises the input${describeHints(options)}; pass the format explicitly`, undefined, { formats: this.formats() });
155
+ }
156
+ importer = this.importer(sniff.format);
157
+ }
158
+ else {
159
+ importer = this.importer(requested);
160
+ }
161
+ const builder = new GraphBuilder({
162
+ weightDtype: options.weightDtype ?? "f64",
163
+ ...options.builder,
164
+ directed: true,
165
+ addMissingNodes: options.addMissingNodes ?? true,
166
+ duplicateEdges: options.duplicateEdges ?? "keep",
167
+ selfLoops: options.selfLoops ?? "keep",
168
+ });
169
+ let report;
170
+ try {
171
+ report = await importer.import(source, builder, importerOptions(options));
172
+ }
173
+ catch (err) {
174
+ await peeked?.close();
175
+ throw err;
176
+ }
177
+ const frozen = builder.freezeWithReport(options.freeze);
178
+ return Object.freeze({
179
+ format: importer.format,
180
+ sniff,
181
+ snapshot: frozen.snapshot,
182
+ report,
183
+ freeze: frozen.report,
184
+ });
185
+ }
186
+ /**
187
+ * Write a snapshot in a format, as UTF-8 chunks (design section 8.5).
188
+ * @param snapshot - the snapshot
189
+ * @param format - the format name
190
+ * @param options - the exporter's common and format-specific options
191
+ * @returns the encoded chunks
192
+ */
193
+ exportGraph(snapshot, format, options) {
194
+ return this.exporter(format).export(snapshot, options);
195
+ }
196
+ /**
197
+ * Write a snapshot in a format, as one string.
198
+ * @param snapshot - the snapshot
199
+ * @param format - the format name
200
+ * @param options - the exporter's common and format-specific options
201
+ * @returns the whole document
202
+ */
203
+ async exportGraphToString(snapshot, format, options) {
204
+ return this.exporter(format).exportToString(snapshot, options);
205
+ }
206
+ /**
207
+ * What exporting a snapshot in a format would lose, without writing anything.
208
+ * @param snapshot - the snapshot
209
+ * @param format - the format name
210
+ * @param options - the exporter's common and format-specific options
211
+ * @returns the loss notes, empty when the export is exact
212
+ */
213
+ checkExport(snapshot, format, options) {
214
+ return this.exporter(format).check(snapshot, options);
215
+ }
216
+ }
217
+ /**
218
+ * A registry holding the eight built-in importers and exporters in the order of GRAPH_FORMATS.
219
+ * @returns a new registry
220
+ */
221
+ export function createRegistry() {
222
+ return new FormatRegistry()
223
+ .registerImporter(jsonImporter)
224
+ .registerExporter(jsonExporter)
225
+ .registerImporter(graphmlImporter)
226
+ .registerExporter(graphmlExporter)
227
+ .registerImporter(gexfImporter)
228
+ .registerExporter(gexfExporter)
229
+ .registerImporter(csvImporter)
230
+ .registerExporter(csvExporter)
231
+ .registerImporter(gmlImporter)
232
+ .registerExporter(gmlExporter)
233
+ .registerImporter(dotImporter)
234
+ .registerExporter(dotExporter)
235
+ .registerImporter(pajekImporter)
236
+ .registerExporter(pajekExporter)
237
+ .registerImporter(neo4jImporter)
238
+ .registerExporter(neo4jExporter);
239
+ }
240
+ /** The default registry: every built-in format. */
241
+ export const registry = createRegistry();
242
+ /**
243
+ * Read an input into a fresh builder and freeze it, through the default registry (design section
244
+ * 8.4: `importGraph(input, { format?, ...options })`).
245
+ * @param input - the text, bytes, stream or chunks to read
246
+ * @param options - the format, hints, common and format-specific import options
247
+ * @returns the snapshot, the import report and the freeze report
248
+ */
249
+ export function importGraph(input, options) {
250
+ return registry.importGraph(input, options);
251
+ }
252
+ /**
253
+ * Write a snapshot in a format through the default registry, as UTF-8 chunks.
254
+ * @param snapshot - the snapshot
255
+ * @param format - the format name
256
+ * @param options - the exporter's common and format-specific options
257
+ * @returns the encoded chunks
258
+ */
259
+ export function exportGraph(snapshot, format, options) {
260
+ return registry.exportGraph(snapshot, format, options);
261
+ }
262
+ /**
263
+ * Write a snapshot in a format through the default registry, as one string.
264
+ * @param snapshot - the snapshot
265
+ * @param format - the format name
266
+ * @param options - the exporter's common and format-specific options
267
+ * @returns the whole document
268
+ */
269
+ export async function exportGraphToString(snapshot, format, options) {
270
+ return registry.exportGraphToString(snapshot, format, options);
271
+ }
272
+ /**
273
+ * What exporting a snapshot in a format would lose, through the default registry.
274
+ * @param snapshot - the snapshot
275
+ * @param format - the format name
276
+ * @param options - the exporter's common and format-specific options
277
+ * @returns the loss notes, empty when the export is exact
278
+ */
279
+ export function checkExport(snapshot, format, options) {
280
+ return registry.checkExport(snapshot, format, options);
281
+ }
282
+ /**
283
+ * Sniff an input's format through the default registry.
284
+ * @param hints - the filename, MIME type and / or head of the input
285
+ * @returns the best candidate, or null when no built-in importer claims it
286
+ */
287
+ export function sniff(hints) {
288
+ return registry.sniff(hints);
289
+ }
290
+ /**
291
+ * The options handed to the importer: everything but the registry's own keys.
292
+ * @param options - the importGraph options
293
+ * @returns the importer's options
294
+ */
295
+ function importerOptions(options) {
296
+ const out = {};
297
+ for (const [key, value] of Object.entries(options)) {
298
+ if (!REGISTRY_KEYS.has(key)) {
299
+ out[key] = value;
300
+ }
301
+ }
302
+ return out;
303
+ }
304
+ /**
305
+ * The E_UNSUPPORTED error of a format name nothing is registered under.
306
+ * @param kind - importer or exporter
307
+ * @param format - the requested name
308
+ * @param known - the registered names
309
+ * @returns the error
310
+ */
311
+ function unknownFormat(kind, format, known) {
312
+ const supported = [...known];
313
+ return new GraphFormatError("E_UNSUPPORTED", `no ${kind} is registered for format ${JSON.stringify(format)}; known: ${supported.join(", ")}`, { option: "format", found: format, supported });
314
+ }
315
+ /**
316
+ * The hints of an import, for the unknown-format message.
317
+ * @param options - the importGraph options
318
+ * @returns " (filename ..., MIME type ...)" or an empty string
319
+ */
320
+ function describeHints(options) {
321
+ const parts = [];
322
+ if (typeof options.filename === "string" && options.filename.length > 0) {
323
+ parts.push(`filename ${JSON.stringify(options.filename)}`);
324
+ }
325
+ if (typeof options.mimeType === "string" && options.mimeType.length > 0) {
326
+ parts.push(`MIME type ${JSON.stringify(options.mimeType)}`);
327
+ }
328
+ return parts.length === 0 ? "" : ` (${parts.join(", ")})`;
329
+ }
330
+ /**
331
+ * The first `bytes` of an input without consuming it: in-memory input is sliced; a stream or an
332
+ * async iterable is read until enough is buffered and then replayed (the buffered chunks first,
333
+ * the rest as it arrives) through a new async iterable that cancels the source when the importer
334
+ * stops early.
335
+ * @param input - the input
336
+ * @param bytes - how much to peek
337
+ * @param signal - the cancellation signal, or null
338
+ * @returns the head and the input to read
339
+ */
340
+ async function peekHead(input, bytes, signal) {
341
+ if (typeof input === "string") {
342
+ return { head: input.slice(0, bytes), input, close: () => Promise.resolve() };
343
+ }
344
+ if (input instanceof Uint8Array) {
345
+ return { head: input.subarray(0, bytes), input, close: () => Promise.resolve() };
346
+ }
347
+ throwIfAborted(signal);
348
+ const source = typeof input.getReader === "function"
349
+ ? readerIterator(input)
350
+ : input[Symbol.asyncIterator]();
351
+ const buffered = [];
352
+ let size = 0;
353
+ let finished = false;
354
+ while (size < bytes) {
355
+ if (signal !== null && signal.aborted) {
356
+ await source.return?.();
357
+ throwIfAborted(signal);
358
+ }
359
+ const next = await source.next();
360
+ if (next.done === true) {
361
+ finished = true;
362
+ break;
363
+ }
364
+ buffered.push(next.value);
365
+ size += typeof next.value === "string" ? next.value.length : next.value.byteLength;
366
+ }
367
+ if (!finished && signal !== null && signal.aborted) {
368
+ // an abort that landed on the read completing the head: close the source before rethrowing
369
+ await source.return?.();
370
+ throwIfAborted(signal);
371
+ }
372
+ const replayed = replay(buffered, source, finished);
373
+ return { head: joinHead(buffered, bytes), input: replayed, close: () => replayed.close() };
374
+ }
375
+ /**
376
+ * The head text or bytes of the buffered chunks: bytes when every chunk is bytes, text otherwise
377
+ * (byte chunks decoded leniently; the importer decodes the real input strictly).
378
+ * @param chunks - the buffered chunks
379
+ * @param bytes - the head size
380
+ * @returns the head
381
+ */
382
+ function joinHead(chunks, bytes) {
383
+ if (chunks.every((c) => c instanceof Uint8Array)) {
384
+ const total = Math.min(bytes, chunks.reduce((sum, c) => sum + c.byteLength, 0));
385
+ const head = new Uint8Array(total);
386
+ let offset = 0;
387
+ for (const chunk of chunks) {
388
+ if (offset >= total) {
389
+ break;
390
+ }
391
+ const part = chunk.subarray(0, Math.min(chunk.byteLength, total - offset));
392
+ head.set(part, offset);
393
+ offset += part.byteLength;
394
+ }
395
+ return head;
396
+ }
397
+ const decoder = new TextDecoder("utf-8", { fatal: false });
398
+ let text = "";
399
+ for (const chunk of chunks) {
400
+ text += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
401
+ if (text.length >= bytes) {
402
+ break;
403
+ }
404
+ }
405
+ return text.slice(0, bytes);
406
+ }
407
+ /**
408
+ * An async iterable that yields the buffered chunks, then the rest of the source; the source is
409
+ * closed when the consumer stops early.
410
+ * @param buffered - the chunks already read
411
+ * @param source - the iterator positioned after them
412
+ * @param finished - whether the source is already exhausted
413
+ * @returns the replaying iterable
414
+ */
415
+ function replay(buffered, source, finished) {
416
+ let exhausted = finished;
417
+ const close = async () => {
418
+ if (!exhausted) {
419
+ exhausted = true;
420
+ await source.return?.();
421
+ }
422
+ };
423
+ return {
424
+ close,
425
+ [Symbol.asyncIterator]() {
426
+ let position = 0;
427
+ return {
428
+ async next() {
429
+ if (position < buffered.length) {
430
+ return { done: false, value: buffered[position++] };
431
+ }
432
+ if (exhausted) {
433
+ return { done: true, value: undefined };
434
+ }
435
+ const next = await source.next();
436
+ if (next.done === true) {
437
+ exhausted = true;
438
+ return { done: true, value: undefined };
439
+ }
440
+ return next;
441
+ },
442
+ async return() {
443
+ await close();
444
+ return { done: true, value: undefined };
445
+ },
446
+ };
447
+ },
448
+ };
449
+ }
450
+ /**
451
+ * An async iterator over a ReadableStream's chunks that cancels the stream when closed early.
452
+ * @param stream - the stream
453
+ * @returns the iterator
454
+ */
455
+ function readerIterator(stream) {
456
+ const reader = stream.getReader();
457
+ let done = false;
458
+ return {
459
+ async next() {
460
+ if (done) {
461
+ return { done: true, value: undefined };
462
+ }
463
+ const result = await reader.read();
464
+ if (result.done) {
465
+ done = true;
466
+ reader.releaseLock();
467
+ return { done: true, value: undefined };
468
+ }
469
+ return { done: false, value: result.value };
470
+ },
471
+ async return() {
472
+ if (!done) {
473
+ done = true;
474
+ await reader.cancel().catch(() => undefined);
475
+ reader.releaseLock();
476
+ }
477
+ return { done: true, value: undefined };
478
+ },
479
+ };
480
+ }
481
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAGH,YAAY,EAEZ,gBAAgB,GAEnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC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AC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,MAAkC;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,OAAO;QACH,KAAK,CAAC,IAAI;YACN,IAAI,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAC5C,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACnC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACd,IAAI,GAAG,IAAI,CAAC;gBACZ,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAC5C,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QAChD,CAAC;QACD,KAAK,CAAC,MAAM;YACR,IAAI,CAAC,IAAI,EAAE,CAAC;gBACR,IAAI,GAAG,IAAI,CAAC;gBACZ,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAC7C,MAAM,CAAC,WAAW,EAAE,CAAC;YACzB,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC5C,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Format detection (design sections 8.2 and 13.1: the registry's `sniff()`, the successor of
3
+ * graphty-element's `format-detection.ts`): which of the registered importers a file is for, from
4
+ * any combination of a filename (its extension), a MIME type and the first bytes of the content.
5
+ *
6
+ * Every importer declares `extensions`, `mimeTypes` and a `sniff(head)` content confidence in
7
+ * 0..1 (design section 8.4); this module combines them into one ranked answer so that content
8
+ * always beats a hint: a `.csv` whose first line is a neo4j-admin header is Neo4j, a `.xml` is
9
+ * GEXF or GraphML by its root element, a `.txt` holding `graph [` is GML. The confidence of a
10
+ * candidate is
11
+ *
12
+ * - `0.5 + 0.35 * content + 0.1 * [extension matches] + 0.05 * [MIME type matches]` when the
13
+ * importer recognises the content (`content > 0`), so a content match always scores at least
14
+ * 0.5 and at most 1;
15
+ * - `0.3 * [extension matches] + 0.1 * [MIME type matches]` when the content is absent or the
16
+ * importer rejects it, so a hint alone never reaches 0.5;
17
+ * - nothing (the format is not a candidate) otherwise.
18
+ *
19
+ * Ties are broken by the order the importers were registered in, which is why the default
20
+ * registry lists the common formats first. The JSON dialect is sniffed from the head as a hint
21
+ * (the importer's detection on the parsed document is authoritative, design section 8.2).
22
+ */
23
+ import { type JsonDialect } from "./formats/json/dialect.js";
24
+ import { type GraphImporter } from "./types.js";
25
+ /** The format names of the eight built-in importers and exporters. */
26
+ export type GraphFormatName = "gexf" | "graphml" | "gml" | "dot" | "pajek" | "csv" | "json" | "neo4j";
27
+ /**
28
+ * The built-in format names in the default registry's order, which is also the tie-break order of
29
+ * sniffing: the more common format wins an extension two formats claim (`.xml` GraphML before GEXF,
30
+ * `.csv` CSV before Neo4j) when the content does not decide.
31
+ */
32
+ export declare const GRAPH_FORMATS: readonly GraphFormatName[];
33
+ /** How many bytes of the input the sniffers look at; the registry reads no more than this before deciding. */
34
+ export declare const SNIFF_HEAD_BYTES = 8192;
35
+ /** What is known about an input before it is read. */
36
+ export interface SniffHints {
37
+ /** A file name or path; only its extension is used. */
38
+ readonly filename?: string | null | undefined;
39
+ /** A MIME type, with or without parameters (`text/csv; charset=utf-8`). */
40
+ readonly mimeType?: string | null | undefined;
41
+ /** The first bytes (or characters) of the content. */
42
+ readonly head?: Uint8Array | string | null | undefined;
43
+ }
44
+ /** One ranked candidate of a sniff. */
45
+ export interface SniffResult {
46
+ /** The importer's format name. */
47
+ readonly format: string;
48
+ /** The combined confidence in 0..1 (at least 0.5 when the content was recognised). */
49
+ readonly confidence: number;
50
+ /** The importer's own content confidence, 0 when no head was given or it rejected the head. */
51
+ readonly content: number;
52
+ /** Whether the filename's extension is one the importer claims. */
53
+ readonly extension: boolean;
54
+ /** Whether the MIME type is one the importer claims. */
55
+ readonly mimeType: boolean;
56
+ /** For the JSON format: the dialect the head suggests, or null when unknown; always null for other formats. */
57
+ readonly dialect: JsonDialect | null;
58
+ }
59
+ /**
60
+ * The lower-cased extension of a file name or path, with its dot.
61
+ * @param filename - the name or path
62
+ * @returns the extension (`.gexf`), or null when the name has none
63
+ */
64
+ export declare function extensionOf(filename: string): string | null;
65
+ /**
66
+ * A MIME type without parameters, lower-cased, for comparison with an importer's list.
67
+ * @param mimeType - the type as received (`Text/CSV; charset=utf-8`)
68
+ * @returns the bare type (`text/csv`)
69
+ */
70
+ export declare function normalizeMimeType(mimeType: string): string;
71
+ /**
72
+ * The head as bytes for the importers' sniff functions: at most SNIFF_HEAD_BYTES, a string
73
+ * encoded as UTF-8.
74
+ * @param head - the head as given
75
+ * @returns the bytes
76
+ */
77
+ export declare function headBytes(head: Uint8Array | string): Uint8Array;
78
+ /**
79
+ * Rank the registered importers for an input by the rule of the module comment: every importer
80
+ * whose content confidence is positive or whose extension / MIME type matches is a candidate,
81
+ * ordered by confidence (ties in registration order).
82
+ * @param hints - what is known about the input
83
+ * @param importers - the registered importers, in registration order
84
+ * @returns the candidates, best first; empty when nothing matches
85
+ */
86
+ export declare function rankFormats(hints: SniffHints, importers: Iterable<GraphImporter>): readonly SniffResult[];
87
+ /**
88
+ * The best candidate of rankFormats(), or null when no importer matches.
89
+ * @param hints - what is known about the input
90
+ * @param importers - the registered importers, in registration order
91
+ * @returns the best candidate, or null
92
+ */
93
+ export declare function sniffFormat(hints: SniffHints, importers: Iterable<GraphImporter>): SniffResult | null;
94
+ /**
95
+ * The JSON dialect a head suggests. A head that parses as a whole document is classified exactly
96
+ * (sniffJsonDialect); a truncated head is scanned for its top-level keys, the keys of `graph` and
97
+ * `options`, and the keys of the first object under `nodes` / `edges` / `links`, and the same
98
+ * rule is applied to that skeleton. The result is a hint: the importer decides on the parsed
99
+ * document.
100
+ * @param head - the first bytes or characters of the document
101
+ * @returns the dialect, or null when the head is not a JSON graph document
102
+ */
103
+ export declare function sniffJsonDialectHead(head: Uint8Array | string): JsonDialect | null;
104
+ //# sourceMappingURL=sniff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sniff.d.ts","sourceRoot":"","sources":["../../src/sniff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAEtG;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,eAAe,EASlD,CAAC;AAEH,8GAA8G;AAC9G,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,sDAAsD;AACtD,MAAM,WAAW,UAAU;IACvB,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1D;AAED,uCAAuC;AACvC,MAAM,WAAW,WAAW;IACxB,kCAAkC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sFAAsF;IACtF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IA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