@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,142 @@
1
+ /**
2
+ * The GEXF subpath entry (`@graphty/graph-io/gexf`, design section 8.2): the importer and exporter
3
+ * objects with their format-specific option types, the exporter's loss-note codes and the
4
+ * importer's issue codes grouped in one table.
5
+ */
6
+
7
+ import {
8
+ BAD_DEFAULT_CODE,
9
+ BAD_OPTIONS_CODE,
10
+ COLUMN_RENAMED_CODE,
11
+ COUNT_HINT_CODE,
12
+ DIRECTION_FORCED_CODE,
13
+ DIRECTION_REFUSED_CODE,
14
+ DUPLICATE_EDGE_ID_CODE,
15
+ DUPLICATE_NODE_CODE,
16
+ ID_MERGED_CODE,
17
+ INVALID_UTF8_CODE,
18
+ MISSING_ENDPOINT_CODE,
19
+ MISSING_ID_CODE,
20
+ MIXED_DIRECTION_CODE,
21
+ NO_GRAPH_CODE,
22
+ OPTION_IGNORED_CODE,
23
+ PRECISION_CODE,
24
+ ROLE_TAKEN_CODE,
25
+ SINK_OPTION_CODE,
26
+ STRAY_TEXT_CODE,
27
+ UNKNOWN_ATTR_TYPE_CODE,
28
+ UNKNOWN_ELEMENT_CODE,
29
+ UNKNOWN_PARENT_CODE,
30
+ XML_SYNTAX_CODE,
31
+ } from "../../common/codes.js";
32
+ import {
33
+ ATTRIBUTE_ID_CODE,
34
+ ATTRIBUTE_TYPE_CODE,
35
+ ATTRIBUTES_CLASS_CODE,
36
+ ATTVALUE_SHAPE_CODE,
37
+ DUPLICATE_ATTRIBUTE_CODE,
38
+ EDGE_TYPE_CODE,
39
+ HEADER_VALUE_CODE,
40
+ MISSING_NODES_CODE,
41
+ NOT_GEXF_CODE,
42
+ OPEN_BOUND_CONFLICT_CODE,
43
+ SPELL_OPEN_CODE,
44
+ TIMED_STATIC_CODE,
45
+ UNKNOWN_ATTRIBUTE_CODE,
46
+ VIZ_DYNAMIC_CODE,
47
+ VIZ_SKIPPED_CODE,
48
+ VIZ_VALUE_CODE,
49
+ WEIGHT_IGNORED_CODE,
50
+ } from "./importer.js";
51
+
52
+ export { GEXF_1_2_CAPABILITIES, GEXF_LOSS, gexfExporter, type GexfExportOptions } from "./exporter.js";
53
+ export { gexfImporter, type GexfImportOptions } from "./importer.js";
54
+ export { type GexfVersion } from "./schema.js";
55
+
56
+ /**
57
+ * The issue codes the GEXF importer records (design section 8.6), by name: the codes shared with
58
+ * the other importers (src/common/codes.ts) and the GEXF-specific ones. A key is the code without
59
+ * its severity and format prefixes.
60
+ */
61
+ export const GEXF_ISSUE = Object.freeze({
62
+ /** The XML is not well-formed (fatal). */
63
+ XML_SYNTAX: XML_SYNTAX_CODE,
64
+ /** The input holds invalid UTF-8 (fatal). */
65
+ INVALID_UTF8: INVALID_UTF8_CODE,
66
+ /** The root element is not `<gexf>` (fatal). */
67
+ NOT_GEXF: NOT_GEXF_CODE,
68
+ /** The document has no `<graph>` (fatal). */
69
+ NO_GRAPH: NO_GRAPH_CODE,
70
+ /** `<edges>` without `<nodes>`. */
71
+ MISSING_NODES: MISSING_NODES_CODE,
72
+ /** A node without an id. */
73
+ MISSING_ID: MISSING_ID_CODE,
74
+ /** An edge without a source or target. */
75
+ MISSING_ENDPOINT: MISSING_ENDPOINT_CODE,
76
+ /** An edge `type` outside directed / undirected / mutual. */
77
+ EDGE_TYPE: EDGE_TYPE_CODE,
78
+ /** A `pid` / `<parent for>` naming an unknown node. */
79
+ UNKNOWN_PARENT: UNKNOWN_PARENT_CODE,
80
+ /** An `<attributes class>` outside node / edge. */
81
+ ATTRIBUTES_CLASS: ATTRIBUTES_CLASS_CODE,
82
+ /** An `<attribute>` without an id. */
83
+ ATTRIBUTE_ID: ATTRIBUTE_ID_CODE,
84
+ /** A `<graph>` header attribute with an unknown value. */
85
+ HEADER_VALUE: HEADER_VALUE_CODE,
86
+ /** A `count` hint the sink cannot reserve (ignored). */
87
+ COUNT_HINT: COUNT_HINT_CODE,
88
+ /** A node id declared twice. */
89
+ DUPLICATE_NODE: DUPLICATE_NODE_CODE,
90
+ /** An edge id declared twice (the second edge is skipped). */
91
+ DUPLICATE_EDGE_ID: DUPLICATE_EDGE_ID_CODE,
92
+ /** An attribute id declared twice in one class. */
93
+ DUPLICATE_ATTRIBUTE: DUPLICATE_ATTRIBUTE_CODE,
94
+ /** An attribute type the importer maps to string. */
95
+ ATTRIBUTE_TYPE: ATTRIBUTE_TYPE_CODE,
96
+ /** A declared type the format does not define (kept as string). */
97
+ UNKNOWN_ATTR_TYPE: UNKNOWN_ATTR_TYPE_CODE,
98
+ /** A default that does not parse as the declared type. */
99
+ BAD_DEFAULT: BAD_DEFAULT_CODE,
100
+ /** Options that do not parse as the declared type. */
101
+ BAD_OPTIONS: BAD_OPTIONS_CODE,
102
+ /** A column renamed `<name>#<id>` because the name was taken (design section 5.6). */
103
+ COLUMN_RENAMED: COLUMN_RENAMED_CODE,
104
+ /** A column declared without its role because the table already holds it. */
105
+ ROLE_TAKEN: ROLE_TAKEN_CODE,
106
+ /** An `<attvalue for>` naming an undeclared attribute. */
107
+ UNKNOWN_ATTRIBUTE: UNKNOWN_ATTRIBUTE_CODE,
108
+ /** An `<attvalue>` without a value. */
109
+ ATTVALUE_SHAPE: ATTVALUE_SHAPE_CODE,
110
+ /** A timed value on an attribute of a static group. */
111
+ TIMED_VALUE_ON_STATIC: TIMED_STATIC_CODE,
112
+ /** A long value beyond 2^53 rounded. */
113
+ PRECISION: PRECISION_CODE,
114
+ /** Two id texts merged into one number under ids "number". */
115
+ ID_MERGED: ID_MERGED_CODE,
116
+ /** The XML weight attribute ignored under weightFrom null. */
117
+ WEIGHT_IGNORED: WEIGHT_IGNORED_CODE,
118
+ /** viz elements skipped under viz: false. */
119
+ VIZ_SKIPPED: VIZ_SKIPPED_CODE,
120
+ /** A 1.2 dynamic viz element whose bounds were dropped. */
121
+ VIZ_DYNAMIC_DROPPED: VIZ_DYNAMIC_CODE,
122
+ /** A 1.2 startopen / endopen spell stored closed. */
123
+ SPELL_OPEN_DROPPED: SPELL_OPEN_CODE,
124
+ /** A viz value that could not be read. */
125
+ VIZ_VALUE: VIZ_VALUE_CODE,
126
+ /** Both `start` and `startopen` (or `end` and `endopen`) on one element. */
127
+ OPEN_BOUND_CONFLICT: OPEN_BOUND_CONFLICT_CODE,
128
+ /** An element or attribute GEXF does not define was skipped. */
129
+ UNKNOWN_ELEMENT: UNKNOWN_ELEMENT_CODE,
130
+ /** Text where GEXF allows only elements was ignored. */
131
+ STRAY_TEXT: STRAY_TEXT_CODE,
132
+ /** A common option the importer has no use for was given. */
133
+ OPTION_IGNORED: OPTION_IGNORED_CODE,
134
+ /** A builder-policy option the sink does not honour. */
135
+ SINK_OPTION: SINK_OPTION_CODE,
136
+ /** The sink refused the file's direction. */
137
+ DIRECTION_REFUSED: DIRECTION_REFUSED_CODE,
138
+ /** Edges forced to the policy's direction. */
139
+ DIRECTION_FORCED: DIRECTION_FORCED_CODE,
140
+ /** A mixed file under onMixedDirection "error" (fatal). */
141
+ MIXED_DIRECTION: MIXED_DIRECTION_CODE,
142
+ });
@@ -0,0 +1,361 @@
1
+ /**
2
+ * What the GEXF importer and exporter share (research note 07 section 2.1, design sections 5.1,
3
+ * 5.5, 5.6 and 5.10): the namespaces of the two supported versions, the fixed names and
4
+ * declarations of the columns derived from XML attributes and viz elements (design section 5.6:
5
+ * XML-attribute-derived columns have fixed names and roles, and a declared attribute that would
6
+ * take one of them is renamed `<name>#<id>`), the shape of a temporal extension table, and the
7
+ * declared-type table of each version for the exporter.
8
+ */
9
+
10
+ import { type ColumnDecl, type Dtype } from "@graphty/graph-format";
11
+
12
+ import { TIME_TEXT_ROLE, TIME_TEXT_SUFFIX } from "../../common/temporal.js";
13
+
14
+ /** The GEXF versions the exporter writes. */
15
+ export type GexfVersion = "1.2" | "1.3";
16
+
17
+ /** The format name. */
18
+ export const GEXF_FORMAT = "gexf";
19
+
20
+ /** The namespace URIs of each version. */
21
+ export const GEXF_NAMESPACES: Readonly<Record<GexfVersion, { readonly gexf: string; readonly viz: string }>> = {
22
+ "1.2": { gexf: "http://www.gexf.net/1.2draft", viz: "http://www.gexf.net/1.2draft/viz" },
23
+ "1.3": { gexf: "http://gexf.net/1.3", viz: "http://gexf.net/1.3/viz" },
24
+ };
25
+
26
+ /** The default edge type values of `<graph defaultedgetype>` and `<edge type>`. */
27
+ export type GexfEdgeType = "directed" | "undirected" | "mutual";
28
+
29
+ /** The GEXF `timeformat` values. */
30
+ export const TIME_FORMATS: ReadonlySet<string> = new Set(["integer", "double", "date", "dateTime"]);
31
+
32
+ /** The GEXF graph `mode` values. */
33
+ export const GRAPH_MODES: ReadonlySet<string> = new Set(["static", "dynamic", "slice"]);
34
+
35
+ /** The GEXF 1.3 `timerepresentation` values. */
36
+ export const TIME_REPRESENTATIONS: ReadonlySet<string> = new Set(["interval", "timestamp"]);
37
+
38
+ /** The `origin.namespace` of viz-derived columns. */
39
+ export const VIZ_NAMESPACE = "viz";
40
+
41
+ /** The origin every XML-derived column declares. */
42
+ const XML_ORIGIN = { format: GEXF_FORMAT };
43
+
44
+ /** The origin of every viz-derived column. */
45
+ const VIZ_ORIGIN = { format: GEXF_FORMAT, namespace: VIZ_NAMESPACE };
46
+
47
+ /**
48
+ * The fixed node column names the importer owns (design section 5.6): a declared attribute with
49
+ * one of these titles is renamed `<title>#<id>` so the XML-derived column keeps its name and role.
50
+ */
51
+ export const NODE_COLUMNS = Object.freeze({
52
+ label: "label",
53
+ parent: "parent",
54
+ parents: "parents",
55
+ start: "start",
56
+ end: "end",
57
+ timestamp: "timestamp",
58
+ spells: "spells",
59
+ timestamps: "timestamps",
60
+ open: "open",
61
+ position: "position",
62
+ color: "color",
63
+ size: "size",
64
+ shape: "shape",
65
+ shapeUri: "shape.uri",
66
+ });
67
+
68
+ /** The fixed edge column names the importer owns. */
69
+ const EDGE_COLUMNS = Object.freeze({
70
+ id: "id",
71
+ label: "label",
72
+ kind: "kind",
73
+ start: "start",
74
+ end: "end",
75
+ timestamp: "timestamp",
76
+ spells: "spells",
77
+ timestamps: "timestamps",
78
+ open: "open",
79
+ color: "color",
80
+ thickness: "thickness",
81
+ shape: "shape",
82
+ });
83
+
84
+ /** Every reserved node column name, including the temporal companions. */
85
+ export const RESERVED_NODE_NAMES: ReadonlySet<string> = new Set([
86
+ ...Object.values(NODE_COLUMNS),
87
+ NODE_COLUMNS.start + TIME_TEXT_SUFFIX,
88
+ NODE_COLUMNS.end + TIME_TEXT_SUFFIX,
89
+ NODE_COLUMNS.timestamp + TIME_TEXT_SUFFIX,
90
+ ]);
91
+
92
+ /** Every reserved edge column name, including the temporal companions. */
93
+ export const RESERVED_EDGE_NAMES: ReadonlySet<string> = new Set([
94
+ ...Object.values(EDGE_COLUMNS),
95
+ EDGE_COLUMNS.start + TIME_TEXT_SUFFIX,
96
+ EDGE_COLUMNS.end + TIME_TEXT_SUFFIX,
97
+ EDGE_COLUMNS.timestamp + TIME_TEXT_SUFFIX,
98
+ ]);
99
+
100
+ /** The declarations of the XML-derived node columns, keyed as NODE_COLUMNS. */
101
+ export const NODE_DECLS: Readonly<Record<keyof typeof NODE_COLUMNS, ColumnDecl>> = {
102
+ label: { name: NODE_COLUMNS.label, dtype: "string", role: "label", nullable: true, origin: XML_ORIGIN },
103
+ parent: {
104
+ name: NODE_COLUMNS.parent,
105
+ dtype: "u32",
106
+ role: "parent",
107
+ refersTo: "node",
108
+ nullable: true,
109
+ origin: XML_ORIGIN,
110
+ },
111
+ parents: {
112
+ name: NODE_COLUMNS.parents,
113
+ dtype: "list",
114
+ itemDtype: "u32",
115
+ role: "parents",
116
+ refersTo: "node",
117
+ nullable: true,
118
+ origin: XML_ORIGIN,
119
+ },
120
+ start: { name: NODE_COLUMNS.start, dtype: "f64", role: "start", nullable: true, origin: XML_ORIGIN },
121
+ end: { name: NODE_COLUMNS.end, dtype: "f64", role: "end", nullable: true, origin: XML_ORIGIN },
122
+ timestamp: { name: NODE_COLUMNS.timestamp, dtype: "f64", role: "timestamp", nullable: true, origin: XML_ORIGIN },
123
+ spells: {
124
+ name: NODE_COLUMNS.spells,
125
+ dtype: "list",
126
+ itemDtype: "f64",
127
+ itemComponents: 2,
128
+ role: "spells",
129
+ nullable: true,
130
+ origin: XML_ORIGIN,
131
+ },
132
+ timestamps: {
133
+ name: NODE_COLUMNS.timestamps,
134
+ dtype: "list",
135
+ itemDtype: "f64",
136
+ role: "timestamps",
137
+ nullable: true,
138
+ origin: XML_ORIGIN,
139
+ },
140
+ open: { name: NODE_COLUMNS.open, dtype: "u8", role: "open", nullable: true, origin: XML_ORIGIN },
141
+ position: {
142
+ name: NODE_COLUMNS.position,
143
+ dtype: "f32",
144
+ components: 3,
145
+ role: "position",
146
+ mutable: true,
147
+ nullable: true,
148
+ origin: VIZ_ORIGIN,
149
+ extra: { units: "file" },
150
+ },
151
+ color: {
152
+ name: NODE_COLUMNS.color,
153
+ dtype: "f32",
154
+ components: 4,
155
+ role: "color",
156
+ nullable: true,
157
+ origin: VIZ_ORIGIN,
158
+ },
159
+ size: { name: NODE_COLUMNS.size, dtype: "f32", role: "size", nullable: true, origin: VIZ_ORIGIN },
160
+ shape: { name: NODE_COLUMNS.shape, dtype: "dict", role: "shape", nullable: true, origin: VIZ_ORIGIN },
161
+ shapeUri: { name: NODE_COLUMNS.shapeUri, dtype: "string", nullable: true, origin: VIZ_ORIGIN },
162
+ };
163
+
164
+ /** The declarations of the XML-derived edge columns, keyed as EDGE_COLUMNS. */
165
+ export const EDGE_DECLS: Readonly<Record<keyof typeof EDGE_COLUMNS, ColumnDecl>> = {
166
+ id: { name: EDGE_COLUMNS.id, dtype: "string", role: "id", unique: true, nullable: true, origin: XML_ORIGIN },
167
+ label: { name: EDGE_COLUMNS.label, dtype: "string", role: "label", nullable: true, origin: XML_ORIGIN },
168
+ kind: { name: EDGE_COLUMNS.kind, dtype: "dict", role: "kind", nullable: true, origin: XML_ORIGIN },
169
+ start: { name: EDGE_COLUMNS.start, dtype: "f64", role: "start", nullable: true, origin: XML_ORIGIN },
170
+ end: { name: EDGE_COLUMNS.end, dtype: "f64", role: "end", nullable: true, origin: XML_ORIGIN },
171
+ timestamp: { name: EDGE_COLUMNS.timestamp, dtype: "f64", role: "timestamp", nullable: true, origin: XML_ORIGIN },
172
+ spells: {
173
+ name: EDGE_COLUMNS.spells,
174
+ dtype: "list",
175
+ itemDtype: "f64",
176
+ itemComponents: 2,
177
+ role: "spells",
178
+ nullable: true,
179
+ origin: XML_ORIGIN,
180
+ },
181
+ timestamps: {
182
+ name: EDGE_COLUMNS.timestamps,
183
+ dtype: "list",
184
+ itemDtype: "f64",
185
+ role: "timestamps",
186
+ nullable: true,
187
+ origin: XML_ORIGIN,
188
+ },
189
+ open: { name: EDGE_COLUMNS.open, dtype: "u8", role: "open", nullable: true, origin: XML_ORIGIN },
190
+ color: {
191
+ name: EDGE_COLUMNS.color,
192
+ dtype: "f32",
193
+ components: 4,
194
+ role: "color",
195
+ nullable: true,
196
+ origin: VIZ_ORIGIN,
197
+ },
198
+ thickness: { name: EDGE_COLUMNS.thickness, dtype: "f32", role: "thickness", nullable: true, origin: VIZ_ORIGIN },
199
+ shape: { name: EDGE_COLUMNS.shape, dtype: "dict", role: "shape", nullable: true, origin: VIZ_ORIGIN },
200
+ };
201
+
202
+ /** The bit of the `open` column marking an open start (design section 5.1). */
203
+ export const OPEN_START = 1;
204
+
205
+ /** The bit of the `open` column marking an open end. */
206
+ export const OPEN_END = 2;
207
+
208
+ /** The prefix of a temporal extension table's name (design section 5.10). */
209
+ const TEMPORAL_TABLE_PREFIX = "temporal:";
210
+
211
+ /** The column names of a temporal extension table (design section 5.10). */
212
+ export const TEMPORAL_COLUMNS = Object.freeze({
213
+ element: "element",
214
+ start: "start",
215
+ end: "end",
216
+ value: "value",
217
+ open: "open",
218
+ startText: `start${TIME_TEXT_SUFFIX}`,
219
+ endText: `end${TIME_TEXT_SUFFIX}`,
220
+ valueText: `value${TIME_TEXT_SUFFIX}`,
221
+ });
222
+
223
+ /**
224
+ * The name of the temporal extension table of a dynamic attribute.
225
+ * @param domain - node or edge
226
+ * @param column - the static column's name
227
+ * @returns `temporal:<domain>:<column>`
228
+ */
229
+ export function temporalTableName(domain: "node" | "edge", column: string): string {
230
+ return `${TEMPORAL_TABLE_PREFIX}${domain}:${column}`;
231
+ }
232
+
233
+ /**
234
+ * Split a temporal table name into its domain and column.
235
+ * @param name - the table name
236
+ * @returns the parts, or null when the name is not a temporal table's
237
+ */
238
+ export function parseTemporalTableName(name: string): { domain: "node" | "edge"; column: string } | null {
239
+ if (!name.startsWith(TEMPORAL_TABLE_PREFIX)) {
240
+ return null;
241
+ }
242
+ const rest = name.slice(TEMPORAL_TABLE_PREFIX.length);
243
+ const colon = rest.indexOf(":");
244
+ if (colon < 0) {
245
+ return null;
246
+ }
247
+ const domain = rest.slice(0, colon);
248
+ if (domain !== "node" && domain !== "edge") {
249
+ return null;
250
+ }
251
+ return { domain, column: rest.slice(colon + 1) };
252
+ }
253
+
254
+ /**
255
+ * The column declarations of a temporal extension table (design section 5.10): the element index,
256
+ * the interval, the value in the attribute's dtype, the interval's text companions, an open-bounds
257
+ * byte and, for a temporal-typed attribute, the value's text companion.
258
+ * @param domain - the domain the element column refers to
259
+ * @param value - the value column's declaration fields (dtype, itemDtype, options...)
260
+ * @param temporalValue - whether the value is itself a temporal type needing a text companion
261
+ * @returns the declarations in table order
262
+ */
263
+ export function temporalTableDecls(
264
+ domain: "node" | "edge",
265
+ value: Pick<ColumnDecl, "dtype" | "itemDtype" | "options" | "origin">,
266
+ temporalValue: boolean,
267
+ ): ColumnDecl[] {
268
+ const decls: ColumnDecl[] = [
269
+ { name: TEMPORAL_COLUMNS.element, dtype: "u32", refersTo: domain, nullable: false },
270
+ { name: TEMPORAL_COLUMNS.start, dtype: "f64", role: "start", nullable: true },
271
+ { name: TEMPORAL_COLUMNS.end, dtype: "f64", role: "end", nullable: true },
272
+ { name: TEMPORAL_COLUMNS.value, ...value, nullable: true },
273
+ {
274
+ name: TEMPORAL_COLUMNS.startText,
275
+ dtype: "string",
276
+ role: TIME_TEXT_ROLE,
277
+ nullable: true,
278
+ extra: { for: TEMPORAL_COLUMNS.start },
279
+ },
280
+ { name: TEMPORAL_COLUMNS.endText, dtype: "string", nullable: true, extra: { for: TEMPORAL_COLUMNS.end } },
281
+ { name: TEMPORAL_COLUMNS.open, dtype: "u8", role: "open", nullable: true },
282
+ ];
283
+ if (temporalValue) {
284
+ decls.push({
285
+ name: TEMPORAL_COLUMNS.valueText,
286
+ dtype: "string",
287
+ nullable: true,
288
+ extra: { for: TEMPORAL_COLUMNS.value },
289
+ });
290
+ }
291
+ return decls;
292
+ }
293
+
294
+ /** The scalar type names GEXF 1.2 declares. */
295
+ const TYPES_1_2: ReadonlySet<string> = new Set(["integer", "long", "double", "float", "boolean", "string", "anyURI"]);
296
+
297
+ /** The scalar type names GEXF 1.3 declares (the list variants are derived). */
298
+ const TYPES_1_3: ReadonlySet<string> = new Set([
299
+ ...TYPES_1_2,
300
+ "bigdecimal",
301
+ "biginteger",
302
+ "byte",
303
+ "char",
304
+ "short",
305
+ "date",
306
+ "dateTime",
307
+ ]);
308
+
309
+ /**
310
+ * Whether a declared type text is a scalar type of a version (case-sensitive, as the schema spells
311
+ * them).
312
+ * @param type - the type text
313
+ * @param version - the target version
314
+ * @returns true when the version declares it
315
+ */
316
+ export function isScalarType(type: string, version: GexfVersion): boolean {
317
+ return (version === "1.2" ? TYPES_1_2 : TYPES_1_3).has(type);
318
+ }
319
+
320
+ /**
321
+ * Whether a declared type text is a list type of a version: `liststring` in 1.2, `list<scalar>` in 1.3.
322
+ * @param type - the type text
323
+ * @param version - the target version
324
+ * @returns true when the version declares it
325
+ */
326
+ export function isListType(type: string, version: GexfVersion): boolean {
327
+ if (version === "1.2") {
328
+ return type === "liststring";
329
+ }
330
+ return type.startsWith("list") && type.length > 4 && isScalarType(type.slice(4), "1.3");
331
+ }
332
+
333
+ /**
334
+ * The canonical GEXF scalar type of a column dtype (design section 5.1 reversed).
335
+ * @param dtype - a scalar dtype
336
+ * @returns the type text; u32 becomes `long` (its range exceeds `integer`), u8 `integer`, json `string`
337
+ */
338
+ export function canonicalScalarType(dtype: Dtype): string {
339
+ switch (dtype) {
340
+ case "bool":
341
+ return "boolean";
342
+ case "i32":
343
+ case "u8":
344
+ return "integer";
345
+ case "u32":
346
+ return "long";
347
+ case "f32":
348
+ return "float";
349
+ case "f64":
350
+ return "double";
351
+ case "dict":
352
+ case "string":
353
+ case "json":
354
+ case "list":
355
+ return "string";
356
+ default: {
357
+ const name: string = dtype;
358
+ return name;
359
+ }
360
+ }
361
+ }