@thomasfosterau/effect-rdf 0.0.0 → 0.1.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 (776) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2250 -1
  3. package/dist/Algebra-CGG4oae3.mjs +433 -0
  4. package/dist/Algebra-CGG4oae3.mjs.map +1 -0
  5. package/dist/Algebra-uGsIEOUA.d.mts +446 -0
  6. package/dist/Ast-CPRZmBvk.mjs +552 -0
  7. package/dist/Ast-CPRZmBvk.mjs.map +1 -0
  8. package/dist/Ast-vcw2W-lf.d.mts +827 -0
  9. package/dist/Bindings-Ck3m7JRC.mjs +249 -0
  10. package/dist/Bindings-Ck3m7JRC.mjs.map +1 -0
  11. package/dist/Bindings-DiKpBd7f.d.mts +153 -0
  12. package/dist/ClientErrors-CpXdFX5u.mjs +128 -0
  13. package/dist/ClientErrors-CpXdFX5u.mjs.map +1 -0
  14. package/dist/ClientErrors-D4IZHUM-.d.mts +101 -0
  15. package/dist/ClientFormats-CXomkXLV.mjs +73 -0
  16. package/dist/ClientFormats-CXomkXLV.mjs.map +1 -0
  17. package/dist/ClientFormats-Dm57ZPwR.d.mts +36 -0
  18. package/dist/Csv2Json-DynEcwCh.mjs +194 -0
  19. package/dist/Csv2Json-DynEcwCh.mjs.map +1 -0
  20. package/dist/Csv2Json-aXNVDoXQ.d.mts +40 -0
  21. package/dist/Csv2Rdf-8maXP6mt.d.mts +41 -0
  22. package/dist/Csv2Rdf-DuSEkaKE.mjs +161 -0
  23. package/dist/Csv2Rdf-DuSEkaKE.mjs.map +1 -0
  24. package/dist/Dataset-BlmlcI7J.mjs +782 -0
  25. package/dist/Dataset-BlmlcI7J.mjs.map +1 -0
  26. package/dist/Dataset-DS3ESOcO.d.mts +426 -0
  27. package/dist/Dataset.d.mts +2 -0
  28. package/dist/Dataset.mjs +1 -0
  29. package/dist/Datatype-CxMpamHC.d.mts +212 -0
  30. package/dist/Datatype-DQvkNkiH.mjs +1001 -0
  31. package/dist/Datatype-DQvkNkiH.mjs.map +1 -0
  32. package/dist/Dialect-8ChFj5EX.d.mts +113 -0
  33. package/dist/Dialect-CzVH38uo.mjs +165 -0
  34. package/dist/Dialect-CzVH38uo.mjs.map +1 -0
  35. package/dist/DocumentLoader-D3lZREnB.mjs +346 -0
  36. package/dist/DocumentLoader-D3lZREnB.mjs.map +1 -0
  37. package/dist/DocumentLoader-ZUCEVrW5.d.mts +178 -0
  38. package/dist/DublinCore-AnwqxRx6.mjs +137 -0
  39. package/dist/DublinCore-AnwqxRx6.mjs.map +1 -0
  40. package/dist/DublinCore-Dq-tVA5d.d.mts +119 -0
  41. package/dist/Engine-CYPB3g4h.d.mts +144 -0
  42. package/dist/Engine-DF8PN7g-.mjs +872 -0
  43. package/dist/Engine-DF8PN7g-.mjs.map +1 -0
  44. package/dist/Errors-CMdV1RhU.mjs +37 -0
  45. package/dist/Errors-CMdV1RhU.mjs.map +1 -0
  46. package/dist/Errors-u2bDjUeM.d.mts +30 -0
  47. package/dist/Evaluator-DEsU4d1o.d.mts +50 -0
  48. package/dist/Evaluator-DOY2-guC.mjs +281 -0
  49. package/dist/Evaluator-DOY2-guC.mjs.map +1 -0
  50. package/dist/Exif-CpqniYQd.d.mts +78 -0
  51. package/dist/Exif-DjkCfEB-.mjs +89 -0
  52. package/dist/Exif-DjkCfEB-.mjs.map +1 -0
  53. package/dist/Expression-BIMMvduQ.mjs +230 -0
  54. package/dist/Expression-BIMMvduQ.mjs.map +1 -0
  55. package/dist/Expression-W8A9cyX7.d.mts +89 -0
  56. package/dist/Extract-Bop85jES.mjs +220 -0
  57. package/dist/Extract-Bop85jES.mjs.map +1 -0
  58. package/dist/Extract-C_pCvuTC.d.mts +88 -0
  59. package/dist/Federation-BcNrozc1.d.mts +52 -0
  60. package/dist/Federation-CHScBkaK.mjs +130 -0
  61. package/dist/Federation-CHScBkaK.mjs.map +1 -0
  62. package/dist/Functions-AvjNcId_.mjs +1346 -0
  63. package/dist/Functions-AvjNcId_.mjs.map +1 -0
  64. package/dist/Functions-OQJZP-F6.d.mts +111 -0
  65. package/dist/Generator-C52mmq01.d.mts +50 -0
  66. package/dist/Generator-D3utCJC7.mjs +205 -0
  67. package/dist/Generator-D3utCJC7.mjs.map +1 -0
  68. package/dist/Grammar-CPlSxGH6.mjs +200 -0
  69. package/dist/Grammar-CPlSxGH6.mjs.map +1 -0
  70. package/dist/Grammar-CRhnRoCu.d.mts +148 -0
  71. package/dist/Grammar-D6jZdJQ3.d.mts +169 -0
  72. package/dist/Grammar-mQ8CgE1M.mjs +258 -0
  73. package/dist/Grammar-mQ8CgE1M.mjs.map +1 -0
  74. package/dist/GraphStore-DhUa4nFO.d.mts +45 -0
  75. package/dist/GraphStore-DvbqwKy1.mjs +212 -0
  76. package/dist/GraphStore-DvbqwKy1.mjs.map +1 -0
  77. package/dist/Iri-BB8Ks-BF.d.mts +84 -0
  78. package/dist/Iri-Cr92gsQV.mjs +232 -0
  79. package/dist/Iri-Cr92gsQV.mjs.map +1 -0
  80. package/dist/Iri.d.mts +2 -0
  81. package/dist/Iri.mjs +1 -0
  82. package/dist/Isomorphism-B6qTY-xy.d.mts +28 -0
  83. package/dist/Isomorphism-BmqxhKyJ.mjs +232 -0
  84. package/dist/Isomorphism-BmqxhKyJ.mjs.map +1 -0
  85. package/dist/Isomorphism-DInKnWIy.mjs +390 -0
  86. package/dist/Isomorphism-DInKnWIy.mjs.map +1 -0
  87. package/dist/Isomorphism-DvSfZXLR.d.mts +37 -0
  88. package/dist/Isomorphism.d.mts +2 -0
  89. package/dist/Isomorphism.mjs +1 -0
  90. package/dist/JsonLd-DOwS2FHg.mjs +2836 -0
  91. package/dist/JsonLd-DOwS2FHg.mjs.map +1 -0
  92. package/dist/JsonLd-DobFrQNa.d.mts +242 -0
  93. package/dist/JsonLdError-C9J-BxfG.mjs +106 -0
  94. package/dist/JsonLdError-C9J-BxfG.mjs.map +1 -0
  95. package/dist/JsonLdError-DSOfHkOy.d.mts +43 -0
  96. package/dist/LanguageTag-BCu8rcmX.d.mts +38 -0
  97. package/dist/LanguageTag-BcOpMGZ4.mjs +89 -0
  98. package/dist/LanguageTag-BcOpMGZ4.mjs.map +1 -0
  99. package/dist/LanguageTag.d.mts +2 -0
  100. package/dist/LanguageTag.mjs +1 -0
  101. package/dist/Lexical-Cg0JHrf6.mjs +243 -0
  102. package/dist/Lexical-Cg0JHrf6.mjs.map +1 -0
  103. package/dist/Lexical-D3zySYVS.d.mts +163 -0
  104. package/dist/Manifest-B6xf6mUc.mjs +148 -0
  105. package/dist/Manifest-B6xf6mUc.mjs.map +1 -0
  106. package/dist/Manifest-DQUMRBFr.d.mts +98 -0
  107. package/dist/Mapping-BgG74x3U.d.mts +63 -0
  108. package/dist/Mapping-Dc1ZGirk.mjs +259 -0
  109. package/dist/Mapping-Dc1ZGirk.mjs.map +1 -0
  110. package/dist/Mcp-1DwTTKOK.mjs +48 -0
  111. package/dist/Mcp-1DwTTKOK.mjs.map +1 -0
  112. package/dist/Mcp-d-pX9erx.d.mts +25 -0
  113. package/dist/Message-CK_DGQuu.mjs +95 -0
  114. package/dist/Message-CK_DGQuu.mjs.map +1 -0
  115. package/dist/Message-fIvTJSXM.d.mts +49 -0
  116. package/dist/Metadata-BbffwGDZ.mjs +445 -0
  117. package/dist/Metadata-BbffwGDZ.mjs.map +1 -0
  118. package/dist/Metadata-CEt3yc1-.d.mts +901 -0
  119. package/dist/Metadata-D4HsQNXr.mjs +1273 -0
  120. package/dist/Metadata-D4HsQNXr.mjs.map +1 -0
  121. package/dist/Metadata-nzS7QKRj.d.mts +350 -0
  122. package/dist/Model-DaMmxurZ.d.mts +293 -0
  123. package/dist/Model-DlPzRYhF.mjs +528 -0
  124. package/dist/Model-DlPzRYhF.mjs.map +1 -0
  125. package/dist/N3-BzyV-KIH.mjs +974 -0
  126. package/dist/N3-BzyV-KIH.mjs.map +1 -0
  127. package/dist/N3-DSLnonDn.d.mts +100 -0
  128. package/dist/NQuads-C1VBOJ3-.mjs +117 -0
  129. package/dist/NQuads-C1VBOJ3-.mjs.map +1 -0
  130. package/dist/NQuads-FjFZikFg.d.mts +76 -0
  131. package/dist/NTriples-D-kLSEAf.mjs +120 -0
  132. package/dist/NTriples-D-kLSEAf.mjs.map +1 -0
  133. package/dist/NTriples-D34OspfW.d.mts +76 -0
  134. package/dist/Namespace-ClTUO_ya.d.mts +42 -0
  135. package/dist/Namespace-DHFIsORd.mjs +75 -0
  136. package/dist/Namespace-DHFIsORd.mjs.map +1 -0
  137. package/dist/Namespace.d.mts +2 -0
  138. package/dist/Namespace.mjs +1 -0
  139. package/dist/Namespaces-Bz85vpjW.mjs +235 -0
  140. package/dist/Namespaces-Bz85vpjW.mjs.map +1 -0
  141. package/dist/Namespaces-C1jW6EDo.d.mts +178 -0
  142. package/dist/Optimizer-BWWQRQPY.mjs +168 -0
  143. package/dist/Optimizer-BWWQRQPY.mjs.map +1 -0
  144. package/dist/Optimizer-DUpUow6k.d.mts +26 -0
  145. package/dist/Options-BLBGL4HE.mjs +72 -0
  146. package/dist/Options-BLBGL4HE.mjs.map +1 -0
  147. package/dist/Options-BommQwP9.d.mts +127 -0
  148. package/dist/Packet-CA76wVX3.mjs +197 -0
  149. package/dist/Packet-CA76wVX3.mjs.map +1 -0
  150. package/dist/Packet-Cy5g6XuW.d.mts +130 -0
  151. package/dist/Parser-p1Gyr0QN.d.mts +85 -0
  152. package/dist/Parser-xARsOWXk.mjs +1317 -0
  153. package/dist/Parser-xARsOWXk.mjs.map +1 -0
  154. package/dist/Path-B20Yp8KE.mjs +284 -0
  155. package/dist/Path-B20Yp8KE.mjs.map +1 -0
  156. package/dist/Path-DRB8e-Zn.d.mts +181 -0
  157. package/dist/Pdf-B9RZn--8.d.mts +77 -0
  158. package/dist/Pdf-CKK6dkZn.mjs +89 -0
  159. package/dist/Pdf-CKK6dkZn.mjs.map +1 -0
  160. package/dist/PdfA-CUjSuntT.d.mts +109 -0
  161. package/dist/PdfA-CleOhuL6.mjs +124 -0
  162. package/dist/PdfA-CleOhuL6.mjs.map +1 -0
  163. package/dist/Photoshop-CiHo80qV.mjs +233 -0
  164. package/dist/Photoshop-CiHo80qV.mjs.map +1 -0
  165. package/dist/Photoshop-udKZ0I3N.d.mts +204 -0
  166. package/dist/PrefixMap-BHFPDLO-.mjs +103 -0
  167. package/dist/PrefixMap-BHFPDLO-.mjs.map +1 -0
  168. package/dist/PrefixMap-BMlXrWNd.d.mts +64 -0
  169. package/dist/PrefixMap.d.mts +2 -0
  170. package/dist/PrefixMap.mjs +1 -0
  171. package/dist/Processor-CMmecFsb.mjs +198 -0
  172. package/dist/Processor-CMmecFsb.mjs.map +1 -0
  173. package/dist/Processor-FJPvO0CB.d.mts +435 -0
  174. package/dist/Protocol-BA7OkNgp.mjs +202 -0
  175. package/dist/Protocol-BA7OkNgp.mjs.map +1 -0
  176. package/dist/Protocol-DlSoiIKB.d.mts +108 -0
  177. package/dist/ProtocolErrors-Ckfejnl6.d.mts +84 -0
  178. package/dist/ProtocolErrors-czDPVcX5.mjs +129 -0
  179. package/dist/ProtocolErrors-czDPVcX5.mjs.map +1 -0
  180. package/dist/Query-D9A6LOpP.mjs +364 -0
  181. package/dist/Query-D9A6LOpP.mjs.map +1 -0
  182. package/dist/Query-KqSkTYyG.d.mts +96 -0
  183. package/dist/QueryBuilder-BLK9Vfbz.mjs +674 -0
  184. package/dist/QueryBuilder-BLK9Vfbz.mjs.map +1 -0
  185. package/dist/QueryBuilder-DUqh4ECe.d.mts +529 -0
  186. package/dist/RdfJs-D6-49XB5.mjs +86 -0
  187. package/dist/RdfJs-D6-49XB5.mjs.map +1 -0
  188. package/dist/RdfJs-DXFqdWrd.d.mts +76 -0
  189. package/dist/RdfJs.d.mts +2 -0
  190. package/dist/RdfJs.mjs +1 -0
  191. package/dist/RdfJson-5aKPDlPS.d.mts +297 -0
  192. package/dist/RdfJson-BNocgW4f.mjs +548 -0
  193. package/dist/RdfJson-BNocgW4f.mjs.map +1 -0
  194. package/dist/RdfXml-DJ9G4gOq.mjs +1014 -0
  195. package/dist/RdfXml-DJ9G4gOq.mjs.map +1 -0
  196. package/dist/RdfXml-_N7yxWEp.d.mts +149 -0
  197. package/dist/Rdfs-BRVPsAjc.d.mts +84 -0
  198. package/dist/Rdfs-CyY2wVHI.mjs +167 -0
  199. package/dist/Rdfs-CyY2wVHI.mjs.map +1 -0
  200. package/dist/Rdfs.d.mts +2 -0
  201. package/dist/Rdfs.mjs +1 -0
  202. package/dist/Reasoner-BxYhx9s7.d.mts +94 -0
  203. package/dist/Reasoner-Cw90zrjv.mjs +798 -0
  204. package/dist/Reasoner-Cw90zrjv.mjs.map +1 -0
  205. package/dist/Reification-BmN4EfnM.d.mts +40 -0
  206. package/dist/Reification-dpqQvjDE.mjs +82 -0
  207. package/dist/Reification-dpqQvjDE.mjs.map +1 -0
  208. package/dist/Reification.d.mts +2 -0
  209. package/dist/Reification.mjs +1 -0
  210. package/dist/Report-XHs8htzK.mjs +121 -0
  211. package/dist/Report-XHs8htzK.mjs.map +1 -0
  212. package/dist/Report-hcXsc_19.d.mts +115 -0
  213. package/dist/Resource-B1cI8FyJ.d.mts +218 -0
  214. package/dist/Resource-sIEeNh15.mjs +374 -0
  215. package/dist/Resource-sIEeNh15.mjs.map +1 -0
  216. package/dist/Resource.d.mts +2 -0
  217. package/dist/Resource.mjs +1 -0
  218. package/dist/Results-BVNEC-Wt.d.mts +277 -0
  219. package/dist/Results-peJjGA2V.mjs +621 -0
  220. package/dist/Results-peJjGA2V.mjs.map +1 -0
  221. package/dist/ResultsStream-BhF0OcNn.mjs +639 -0
  222. package/dist/ResultsStream-BhF0OcNn.mjs.map +1 -0
  223. package/dist/ResultsStream-toYMXrOe.d.mts +100 -0
  224. package/dist/SemAct-CDchtk49.d.mts +96 -0
  225. package/dist/SemAct-CmyT4yI8.mjs +118 -0
  226. package/dist/SemAct-CmyT4yI8.mjs.map +1 -0
  227. package/dist/Serialization-DP9H5bYQ.mjs +514 -0
  228. package/dist/Serialization-DP9H5bYQ.mjs.map +1 -0
  229. package/dist/Serialization-Df8iVauT.d.mts +392 -0
  230. package/dist/Serialization.d.mts +2 -0
  231. package/dist/Serialization.mjs +1 -0
  232. package/dist/ServerFormats-CrRnjjf6.mjs +64 -0
  233. package/dist/ServerFormats-CrRnjjf6.mjs.map +1 -0
  234. package/dist/ServerFormats-DjC9NsO_.d.mts +36 -0
  235. package/dist/ServiceDescription-BERsvg-k.d.mts +54 -0
  236. package/dist/ServiceDescription-Dq5hxeGy.mjs +97 -0
  237. package/dist/ServiceDescription-Dq5hxeGy.mjs.map +1 -0
  238. package/dist/ShExC-Ctf-06CL.d.mts +67 -0
  239. package/dist/ShExC-DJbB19i3.mjs +1181 -0
  240. package/dist/ShExC-DJbB19i3.mjs.map +1 -0
  241. package/dist/ShExError-BeYFD9rv.d.mts +61 -0
  242. package/dist/ShExError-CVtq2NnM.mjs +64 -0
  243. package/dist/ShExError-CVtq2NnM.mjs.map +1 -0
  244. package/dist/ShExJ-C1u_wgyD.d.mts +531 -0
  245. package/dist/ShExJ-COiPd9Xw.mjs +532 -0
  246. package/dist/ShExJ-COiPd9Xw.mjs.map +1 -0
  247. package/dist/ShExR-ByR4mCh-.mjs +480 -0
  248. package/dist/ShExR-ByR4mCh-.mjs.map +1 -0
  249. package/dist/ShExR-CqONNNBz.d.mts +40 -0
  250. package/dist/ShapeMap-C422pxKl.d.mts +140 -0
  251. package/dist/ShapeMap-CsgKxB2G.mjs +181 -0
  252. package/dist/ShapeMap-CsgKxB2G.mjs.map +1 -0
  253. package/dist/Shapes-18GjfyBV.mjs +597 -0
  254. package/dist/Shapes-18GjfyBV.mjs.map +1 -0
  255. package/dist/Shapes-BQFDFc4Q.d.mts +306 -0
  256. package/dist/Sparql-BiYFMSpl.mjs +29 -0
  257. package/dist/Sparql-BiYFMSpl.mjs.map +1 -0
  258. package/dist/Sparql-DecpWTPh.d.mts +97 -0
  259. package/dist/SparqlClient-C_CjXbwj.mjs +333 -0
  260. package/dist/SparqlClient-C_CjXbwj.mjs.map +1 -0
  261. package/dist/SparqlClient-UPc88SHy.d.mts +290 -0
  262. package/dist/SparqlServer-CbUW-pVj.d.mts +71 -0
  263. package/dist/SparqlServer-Db7w7Cll.mjs +308 -0
  264. package/dist/SparqlServer-Db7w7Cll.mjs.map +1 -0
  265. package/dist/SqlStore-BBqFx-Wl.mjs +684 -0
  266. package/dist/SqlStore-BBqFx-Wl.mjs.map +1 -0
  267. package/dist/SqlStore-CCJo5I-e.d.mts +117 -0
  268. package/dist/Store-D0jmVfb3.d.mts +166 -0
  269. package/dist/Store-DH3Ow1GO.mjs +162 -0
  270. package/dist/Store-DH3Ow1GO.mjs.map +1 -0
  271. package/dist/Structure-BjMo4Bkc.mjs +334 -0
  272. package/dist/Structure-BjMo4Bkc.mjs.map +1 -0
  273. package/dist/Structure-n4CmDiab.d.mts +63 -0
  274. package/dist/Table-BGgm9nbM.mjs +538 -0
  275. package/dist/Table-BGgm9nbM.mjs.map +1 -0
  276. package/dist/Table-C3reiVrb.d.mts +261 -0
  277. package/dist/Term-B_4ezyXq.d.mts +619 -0
  278. package/dist/Term-CFLG1qu4.mjs +991 -0
  279. package/dist/Term-CFLG1qu4.mjs.map +1 -0
  280. package/dist/Term.d.mts +2 -0
  281. package/dist/Term.mjs +1 -0
  282. package/dist/TermCodec-CDZiEztW.mjs +397 -0
  283. package/dist/TermCodec-CDZiEztW.mjs.map +1 -0
  284. package/dist/TermCodec-_03bDXr0.d.mts +209 -0
  285. package/dist/TermCodec.d.mts +2 -0
  286. package/dist/TermCodec.mjs +1 -0
  287. package/dist/TermJson-BOPe0yve.d.mts +232 -0
  288. package/dist/TermJson-FAg3lvjl.mjs +142 -0
  289. package/dist/TermJson-FAg3lvjl.mjs.map +1 -0
  290. package/dist/TermJson.d.mts +2 -0
  291. package/dist/TermJson.mjs +1 -0
  292. package/dist/TermSchema-Bn9CoaYA.mjs +30 -0
  293. package/dist/TermSchema-Bn9CoaYA.mjs.map +1 -0
  294. package/dist/TermSchema-DBO6MroX.d.mts +6 -0
  295. package/dist/Testing-B-aPCpmu.mjs +63 -0
  296. package/dist/Testing-B-aPCpmu.mjs.map +1 -0
  297. package/dist/Testing-CF6s8P3O.d.mts +53 -0
  298. package/dist/Tiff-CR-2QeSI.d.mts +148 -0
  299. package/dist/Tiff-DlsOlZPM.mjs +169 -0
  300. package/dist/Tiff-DlsOlZPM.mjs.map +1 -0
  301. package/dist/Tools-7MdRKccr.d.mts +583 -0
  302. package/dist/Tools-ryxphZbI.mjs +329 -0
  303. package/dist/Tools-ryxphZbI.mjs.map +1 -0
  304. package/dist/Translate-B0YKKANS.d.mts +37 -0
  305. package/dist/Translate-gzWPq0Ia.mjs +308 -0
  306. package/dist/Translate-gzWPq0Ia.mjs.map +1 -0
  307. package/dist/Translation-DC9rLm2y.mjs +1535 -0
  308. package/dist/Translation-DC9rLm2y.mjs.map +1 -0
  309. package/dist/Translation-K4L9XBqX.d.mts +103 -0
  310. package/dist/TriG-BkqtqZ6Y.mjs +125 -0
  311. package/dist/TriG-BkqtqZ6Y.mjs.map +1 -0
  312. package/dist/TriG-xDjdDatp.d.mts +86 -0
  313. package/dist/Turtle-Bv1_bisW.d.mts +85 -0
  314. package/dist/Turtle-CZVUOtwl.mjs +133 -0
  315. package/dist/Turtle-CZVUOtwl.mjs.map +1 -0
  316. package/dist/ValidationReport-DBdJshW5.mjs +285 -0
  317. package/dist/ValidationReport-DBdJshW5.mjs.map +1 -0
  318. package/dist/ValidationReport-Dx3WxY0h.d.mts +192 -0
  319. package/dist/Validator-227ff9Rn.d.mts +179 -0
  320. package/dist/Validator-BzXMKDeJ.mjs +1162 -0
  321. package/dist/Validator-BzXMKDeJ.mjs.map +1 -0
  322. package/dist/Validator-Dl8cih5V.d.mts +207 -0
  323. package/dist/Validator-DmUfMbpL.mjs +568 -0
  324. package/dist/Validator-DmUfMbpL.mjs.map +1 -0
  325. package/dist/Vocab-DceKywpq.mjs +168 -0
  326. package/dist/Vocab-DceKywpq.mjs.map +1 -0
  327. package/dist/Vocab-Df-L-IwZ.d.mts +46 -0
  328. package/dist/Vocab-Do56UgBX.d.mts +81 -0
  329. package/dist/Vocab-TfpWG1Ne.mjs +118 -0
  330. package/dist/Vocab-TfpWG1Ne.mjs.map +1 -0
  331. package/dist/Vocab.d.mts +2 -0
  332. package/dist/Vocab.mjs +1 -0
  333. package/dist/Vocabulary-C6-GPOy4.d.mts +22 -0
  334. package/dist/Vocabulary-CnQl-_Z4.mjs +179 -0
  335. package/dist/Vocabulary-CnQl-_Z4.mjs.map +1 -0
  336. package/dist/Xml-B7iihYCS.mjs +976 -0
  337. package/dist/Xml-B7iihYCS.mjs.map +1 -0
  338. package/dist/Xml-CmfHS7SW.d.mts +267 -0
  339. package/dist/Xmp-D7CKA7MZ.d.mts +111 -0
  340. package/dist/Xmp-DCGN9pOD.mjs +307 -0
  341. package/dist/Xmp-DCGN9pOD.mjs.map +1 -0
  342. package/dist/XmpBasic-CP38jpR_.mjs +73 -0
  343. package/dist/XmpBasic-CP38jpR_.mjs.map +1 -0
  344. package/dist/XmpBasic-Cmbe53rQ.d.mts +64 -0
  345. package/dist/XmpMM-BfL_TgJF.mjs +73 -0
  346. package/dist/XmpMM-BfL_TgJF.mjs.map +1 -0
  347. package/dist/XmpMM-Dqm3IX8p.d.mts +63 -0
  348. package/dist/XmpRights-BKPtoI5L.mjs +73 -0
  349. package/dist/XmpRights-BKPtoI5L.mjs.map +1 -0
  350. package/dist/XmpRights-CaALZQz2.d.mts +63 -0
  351. package/dist/Xsd-Cdgx5zRB.mjs +405 -0
  352. package/dist/Xsd-Cdgx5zRB.mjs.map +1 -0
  353. package/dist/Xsd-D2elNhSm.d.mts +187 -0
  354. package/dist/Xsd.d.mts +2 -0
  355. package/dist/Xsd.mjs +1 -0
  356. package/dist/accessors-CEjaojuQ.mjs +28 -0
  357. package/dist/accessors-CEjaojuQ.mjs.map +1 -0
  358. package/dist/codec-Lb2T96rv.d.mts +20 -0
  359. package/dist/codec-QNo7IdJF.mjs +389 -0
  360. package/dist/codec-QNo7IdJF.mjs.map +1 -0
  361. package/dist/csvw/Csv2Json.d.mts +2 -0
  362. package/dist/csvw/Csv2Json.mjs +1 -0
  363. package/dist/csvw/Csv2Rdf.d.mts +2 -0
  364. package/dist/csvw/Csv2Rdf.mjs +1 -0
  365. package/dist/csvw/Datatype.d.mts +2 -0
  366. package/dist/csvw/Datatype.mjs +1 -0
  367. package/dist/csvw/Metadata.d.mts +2 -0
  368. package/dist/csvw/Metadata.mjs +1 -0
  369. package/dist/csvw/Processor.d.mts +2 -0
  370. package/dist/csvw/Processor.mjs +1 -0
  371. package/dist/csvw/Report.d.mts +2 -0
  372. package/dist/csvw/Report.mjs +1 -0
  373. package/dist/csvw/Table.d.mts +2 -0
  374. package/dist/csvw/Table.mjs +1 -0
  375. package/dist/csvw/index.d.mts +8 -0
  376. package/dist/csvw/index.mjs +8 -0
  377. package/dist/index-Cms2TYfC.d.mts +16 -0
  378. package/dist/index-Ct8xFmRs.d.mts +7 -0
  379. package/dist/index-D4QFwOjm.d.mts +28 -0
  380. package/dist/index.d.mts +18 -0
  381. package/dist/index.mjs +17 -0
  382. package/dist/jsonld/DocumentLoader.d.mts +2 -0
  383. package/dist/jsonld/DocumentLoader.mjs +1 -0
  384. package/dist/jsonld/JsonLd.d.mts +2 -0
  385. package/dist/jsonld/JsonLd.mjs +1 -0
  386. package/dist/jsonld/JsonLdError.d.mts +2 -0
  387. package/dist/jsonld/JsonLdError.mjs +1 -0
  388. package/dist/jsonld/index.d.mts +4 -0
  389. package/dist/jsonld/index.mjs +4 -0
  390. package/dist/lists-D-OpQ0Ir.mjs +77 -0
  391. package/dist/lists-D-OpQ0Ir.mjs.map +1 -0
  392. package/dist/loop-D5-gNx9K.mjs +21 -0
  393. package/dist/loop-D5-gNx9K.mjs.map +1 -0
  394. package/dist/loop-DZ2hXlr_.mjs +21 -0
  395. package/dist/loop-DZ2hXlr_.mjs.map +1 -0
  396. package/dist/n3/Isomorphism.d.mts +2 -0
  397. package/dist/n3/Isomorphism.mjs +1 -0
  398. package/dist/n3/Mapping.d.mts +2 -0
  399. package/dist/n3/Mapping.mjs +1 -0
  400. package/dist/n3/Model.d.mts +2 -0
  401. package/dist/n3/Model.mjs +1 -0
  402. package/dist/n3/N3.d.mts +2 -0
  403. package/dist/n3/N3.mjs +1 -0
  404. package/dist/n3/Reasoner.d.mts +2 -0
  405. package/dist/n3/Reasoner.mjs +2 -0
  406. package/dist/n3/Vocab.d.mts +2 -0
  407. package/dist/n3/Vocab.mjs +1 -0
  408. package/dist/n3/index.d.mts +7 -0
  409. package/dist/n3/index.mjs +7 -0
  410. package/dist/ntriples/Grammar.d.mts +2 -0
  411. package/dist/ntriples/Grammar.mjs +1 -0
  412. package/dist/ntriples/Lexical.d.mts +2 -0
  413. package/dist/ntriples/Lexical.mjs +1 -0
  414. package/dist/ntriples/NQuads.d.mts +2 -0
  415. package/dist/ntriples/NQuads.mjs +1 -0
  416. package/dist/ntriples/NTriples.d.mts +2 -0
  417. package/dist/ntriples/NTriples.mjs +1 -0
  418. package/dist/ntriples/index.d.mts +5 -0
  419. package/dist/ntriples/index.mjs +5 -0
  420. package/dist/rdfjson/RdfJson.d.mts +2 -0
  421. package/dist/rdfjson/RdfJson.mjs +1 -0
  422. package/dist/rdfjson/index.d.mts +2 -0
  423. package/dist/rdfjson/index.mjs +1 -0
  424. package/dist/rdfxml/RdfXml.d.mts +2 -0
  425. package/dist/rdfxml/RdfXml.mjs +1 -0
  426. package/dist/rdfxml/Xml.d.mts +2 -0
  427. package/dist/rdfxml/Xml.mjs +1 -0
  428. package/dist/rdfxml/index.d.mts +3 -0
  429. package/dist/rdfxml/index.mjs +3 -0
  430. package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
  431. package/dist/serialize-96KBvKaf.mjs +1463 -0
  432. package/dist/serialize-96KBvKaf.mjs.map +1 -0
  433. package/dist/serialize-DsoXdM6n.d.mts +37 -0
  434. package/dist/shacl/Message.d.mts +2 -0
  435. package/dist/shacl/Message.mjs +1 -0
  436. package/dist/shacl/Path.d.mts +2 -0
  437. package/dist/shacl/Path.mjs +1 -0
  438. package/dist/shacl/Shapes.d.mts +2 -0
  439. package/dist/shacl/Shapes.mjs +1 -0
  440. package/dist/shacl/Sparql.d.mts +2 -0
  441. package/dist/shacl/Sparql.mjs +1 -0
  442. package/dist/shacl/ValidationReport.d.mts +2 -0
  443. package/dist/shacl/ValidationReport.mjs +1 -0
  444. package/dist/shacl/Validator.d.mts +2 -0
  445. package/dist/shacl/Validator.mjs +1 -0
  446. package/dist/shacl/Vocabulary.d.mts +2 -0
  447. package/dist/shacl/Vocabulary.mjs +1 -0
  448. package/dist/shacl/index.d.mts +9 -0
  449. package/dist/shacl/index.mjs +8 -0
  450. package/dist/shex/SemAct.d.mts +2 -0
  451. package/dist/shex/SemAct.mjs +1 -0
  452. package/dist/shex/ShExC.d.mts +2 -0
  453. package/dist/shex/ShExC.mjs +1 -0
  454. package/dist/shex/ShExError.d.mts +2 -0
  455. package/dist/shex/ShExError.mjs +1 -0
  456. package/dist/shex/ShExJ.d.mts +2 -0
  457. package/dist/shex/ShExJ.mjs +2 -0
  458. package/dist/shex/ShExR.d.mts +2 -0
  459. package/dist/shex/ShExR.mjs +1 -0
  460. package/dist/shex/ShapeMap.d.mts +2 -0
  461. package/dist/shex/ShapeMap.mjs +1 -0
  462. package/dist/shex/Structure.d.mts +2 -0
  463. package/dist/shex/Structure.mjs +2 -0
  464. package/dist/shex/Validator.d.mts +2 -0
  465. package/dist/shex/Validator.mjs +4 -0
  466. package/dist/shex/index.d.mts +9 -0
  467. package/dist/shex/index.mjs +9 -0
  468. package/dist/sparql/Algebra.d.mts +2 -0
  469. package/dist/sparql/Algebra.mjs +1 -0
  470. package/dist/sparql/Ast.d.mts +2 -0
  471. package/dist/sparql/Ast.mjs +1 -0
  472. package/dist/sparql/Bindings.d.mts +2 -0
  473. package/dist/sparql/Bindings.mjs +1 -0
  474. package/dist/sparql/ClientErrors.d.mts +2 -0
  475. package/dist/sparql/ClientErrors.mjs +1 -0
  476. package/dist/sparql/ClientFormats.d.mts +2 -0
  477. package/dist/sparql/ClientFormats.mjs +1 -0
  478. package/dist/sparql/Engine.d.mts +2 -0
  479. package/dist/sparql/Engine.mjs +1 -0
  480. package/dist/sparql/Errors.d.mts +2 -0
  481. package/dist/sparql/Errors.mjs +1 -0
  482. package/dist/sparql/Expression.d.mts +2 -0
  483. package/dist/sparql/Expression.mjs +1 -0
  484. package/dist/sparql/Federation.d.mts +2 -0
  485. package/dist/sparql/Federation.mjs +1 -0
  486. package/dist/sparql/Functions.d.mts +2 -0
  487. package/dist/sparql/Functions.mjs +1 -0
  488. package/dist/sparql/Generator.d.mts +2 -0
  489. package/dist/sparql/Generator.mjs +1 -0
  490. package/dist/sparql/GraphStore.d.mts +2 -0
  491. package/dist/sparql/GraphStore.mjs +1 -0
  492. package/dist/sparql/Optimizer.d.mts +2 -0
  493. package/dist/sparql/Optimizer.mjs +1 -0
  494. package/dist/sparql/Options.d.mts +2 -0
  495. package/dist/sparql/Options.mjs +1 -0
  496. package/dist/sparql/Parser.d.mts +2 -0
  497. package/dist/sparql/Parser.mjs +1 -0
  498. package/dist/sparql/Protocol.d.mts +2 -0
  499. package/dist/sparql/Protocol.mjs +1 -0
  500. package/dist/sparql/ProtocolErrors.d.mts +2 -0
  501. package/dist/sparql/ProtocolErrors.mjs +1 -0
  502. package/dist/sparql/QueryBuilder.d.mts +2 -0
  503. package/dist/sparql/QueryBuilder.mjs +1 -0
  504. package/dist/sparql/Results.d.mts +2 -0
  505. package/dist/sparql/Results.mjs +1 -0
  506. package/dist/sparql/ResultsStream.d.mts +2 -0
  507. package/dist/sparql/ResultsStream.mjs +1 -0
  508. package/dist/sparql/ServerFormats.d.mts +2 -0
  509. package/dist/sparql/ServerFormats.mjs +1 -0
  510. package/dist/sparql/ServiceDescription.d.mts +2 -0
  511. package/dist/sparql/ServiceDescription.mjs +1 -0
  512. package/dist/sparql/SparqlClient.d.mts +2 -0
  513. package/dist/sparql/SparqlClient.mjs +1 -0
  514. package/dist/sparql/SparqlServer.d.mts +2 -0
  515. package/dist/sparql/SparqlServer.mjs +1 -0
  516. package/dist/sparql/Store.d.mts +2 -0
  517. package/dist/sparql/Store.mjs +1 -0
  518. package/dist/sparql/TermSchema.d.mts +3 -0
  519. package/dist/sparql/TermSchema.mjs +2 -0
  520. package/dist/sparql/Testing.d.mts +2 -0
  521. package/dist/sparql/Testing.mjs +1 -0
  522. package/dist/sparql/Translate.d.mts +2 -0
  523. package/dist/sparql/Translate.mjs +1 -0
  524. package/dist/sparql/ai/Mcp.d.mts +2 -0
  525. package/dist/sparql/ai/Mcp.mjs +1 -0
  526. package/dist/sparql/ai/Tools.d.mts +2 -0
  527. package/dist/sparql/ai/Tools.mjs +1 -0
  528. package/dist/sparql/ai/index.d.mts +3 -0
  529. package/dist/sparql/ai/index.mjs +3 -0
  530. package/dist/sparql/index.d.mts +30 -0
  531. package/dist/sparql/index.mjs +29 -0
  532. package/dist/sparql/shacl/Evaluator.d.mts +2 -0
  533. package/dist/sparql/shacl/Evaluator.mjs +1 -0
  534. package/dist/sparql/shacl/Query.d.mts +2 -0
  535. package/dist/sparql/shacl/Query.mjs +1 -0
  536. package/dist/sparql/shacl/index.d.mts +3 -0
  537. package/dist/sparql/shacl/index.mjs +3 -0
  538. package/dist/sparql/sql/Dialect.d.mts +2 -0
  539. package/dist/sparql/sql/Dialect.mjs +1 -0
  540. package/dist/sparql/sql/SqlStore.d.mts +2 -0
  541. package/dist/sparql/sql/SqlStore.mjs +1 -0
  542. package/dist/sparql/sql/Translation.d.mts +2 -0
  543. package/dist/sparql/sql/Translation.mjs +1 -0
  544. package/dist/sparql/sql/index.d.mts +4 -0
  545. package/dist/sparql/sql/index.mjs +4 -0
  546. package/dist/stringMap-D5YIpYtR.mjs +38 -0
  547. package/dist/stringMap-D5YIpYtR.mjs.map +1 -0
  548. package/dist/tokens-C6BzeodQ.mjs +24 -0
  549. package/dist/tokens-C6BzeodQ.mjs.map +1 -0
  550. package/dist/turtle/Grammar.d.mts +3 -0
  551. package/dist/turtle/Grammar.mjs +3 -0
  552. package/dist/turtle/Manifest.d.mts +2 -0
  553. package/dist/turtle/Manifest.mjs +1 -0
  554. package/dist/turtle/TriG.d.mts +2 -0
  555. package/dist/turtle/TriG.mjs +1 -0
  556. package/dist/turtle/Turtle.d.mts +2 -0
  557. package/dist/turtle/Turtle.mjs +1 -0
  558. package/dist/turtle/index.d.mts +5 -0
  559. package/dist/turtle/index.mjs +5 -0
  560. package/dist/xmp/DublinCore.d.mts +2 -0
  561. package/dist/xmp/DublinCore.mjs +1 -0
  562. package/dist/xmp/Exif.d.mts +2 -0
  563. package/dist/xmp/Exif.mjs +1 -0
  564. package/dist/xmp/Extract.d.mts +2 -0
  565. package/dist/xmp/Extract.mjs +1 -0
  566. package/dist/xmp/Metadata.d.mts +2 -0
  567. package/dist/xmp/Metadata.mjs +1 -0
  568. package/dist/xmp/Namespaces.d.mts +2 -0
  569. package/dist/xmp/Namespaces.mjs +1 -0
  570. package/dist/xmp/Packet.d.mts +2 -0
  571. package/dist/xmp/Packet.mjs +1 -0
  572. package/dist/xmp/Pdf.d.mts +2 -0
  573. package/dist/xmp/Pdf.mjs +1 -0
  574. package/dist/xmp/PdfA.d.mts +2 -0
  575. package/dist/xmp/PdfA.mjs +1 -0
  576. package/dist/xmp/Photoshop.d.mts +2 -0
  577. package/dist/xmp/Photoshop.mjs +1 -0
  578. package/dist/xmp/Tiff.d.mts +2 -0
  579. package/dist/xmp/Tiff.mjs +1 -0
  580. package/dist/xmp/Xmp.d.mts +2 -0
  581. package/dist/xmp/Xmp.mjs +3 -0
  582. package/dist/xmp/XmpBasic.d.mts +2 -0
  583. package/dist/xmp/XmpBasic.mjs +1 -0
  584. package/dist/xmp/XmpMM.d.mts +2 -0
  585. package/dist/xmp/XmpMM.mjs +1 -0
  586. package/dist/xmp/XmpRights.d.mts +2 -0
  587. package/dist/xmp/XmpRights.mjs +1 -0
  588. package/dist/xmp/index.d.mts +15 -0
  589. package/dist/xmp/index.mjs +15 -0
  590. package/package.json +187 -3
  591. package/src/Dataset.ts +1085 -0
  592. package/src/Iri.ts +322 -0
  593. package/src/Isomorphism.ts +319 -0
  594. package/src/LanguageTag.ts +98 -0
  595. package/src/Namespace.ts +100 -0
  596. package/src/PrefixMap.ts +117 -0
  597. package/src/RdfJs.ts +146 -0
  598. package/src/Rdfs.ts +241 -0
  599. package/src/Reification.ts +103 -0
  600. package/src/Resource.ts +873 -0
  601. package/src/Serialization.ts +775 -0
  602. package/src/Term.ts +1300 -0
  603. package/src/TermCodec.ts +505 -0
  604. package/src/TermJson.ts +313 -0
  605. package/src/Vocab.ts +161 -0
  606. package/src/Xsd.ts +573 -0
  607. package/src/csvw/Csv2Json.ts +265 -0
  608. package/src/csvw/Csv2Rdf.ts +268 -0
  609. package/src/csvw/Datatype.ts +589 -0
  610. package/src/csvw/Metadata.ts +1523 -0
  611. package/src/csvw/Processor.ts +276 -0
  612. package/src/csvw/Report.ts +135 -0
  613. package/src/csvw/Table.ts +759 -0
  614. package/src/csvw/index.ts +22 -0
  615. package/src/csvw/internal/dateFormat.ts +202 -0
  616. package/src/csvw/internal/json.ts +104 -0
  617. package/src/csvw/internal/numberFormat.ts +369 -0
  618. package/src/csvw/internal/object.ts +23 -0
  619. package/src/csvw/internal/uriTemplate.ts +130 -0
  620. package/src/csvw/internal/url.ts +93 -0
  621. package/src/csvw/internal/vocab.ts +282 -0
  622. package/src/index.ts +40 -0
  623. package/src/internal/arbitrary.ts +148 -0
  624. package/src/internal/loop.ts +24 -0
  625. package/src/internal/pending.ts +20 -0
  626. package/src/internal/textDecoder.ts +183 -0
  627. package/src/jsonld/DocumentLoader.ts +512 -0
  628. package/src/jsonld/JsonLd.ts +847 -0
  629. package/src/jsonld/JsonLdError.ts +105 -0
  630. package/src/jsonld/index.ts +13 -0
  631. package/src/jsonld/internal/compact.ts +852 -0
  632. package/src/jsonld/internal/context.ts +781 -0
  633. package/src/jsonld/internal/expand.ts +614 -0
  634. package/src/jsonld/internal/flatten.ts +243 -0
  635. package/src/jsonld/internal/frame.ts +559 -0
  636. package/src/jsonld/internal/iri.ts +52 -0
  637. package/src/jsonld/internal/json.ts +19 -0
  638. package/src/jsonld/internal/linkHeader.ts +60 -0
  639. package/src/jsonld/internal/rdf.ts +481 -0
  640. package/src/jsonld/internal/util.ts +367 -0
  641. package/src/n3/Isomorphism.ts +476 -0
  642. package/src/n3/Mapping.ts +332 -0
  643. package/src/n3/Model.ts +696 -0
  644. package/src/n3/N3.ts +237 -0
  645. package/src/n3/Reasoner.ts +568 -0
  646. package/src/n3/Vocab.ts +111 -0
  647. package/src/n3/index.ts +21 -0
  648. package/src/n3/internal/builtins.ts +668 -0
  649. package/src/n3/internal/guards.ts +23 -0
  650. package/src/n3/internal/lists.ts +106 -0
  651. package/src/n3/internal/loop.ts +28 -0
  652. package/src/n3/internal/parser.ts +1032 -0
  653. package/src/n3/internal/writer.ts +344 -0
  654. package/src/ntriples/Grammar.ts +317 -0
  655. package/src/ntriples/Lexical.ts +321 -0
  656. package/src/ntriples/NQuads.ts +140 -0
  657. package/src/ntriples/NTriples.ts +143 -0
  658. package/src/ntriples/index.ts +14 -0
  659. package/src/ntriples/internal/codec.ts +229 -0
  660. package/src/ntriples/internal/lineParser.ts +326 -0
  661. package/src/ntriples/internal/loop.ts +14 -0
  662. package/src/rdfjson/RdfJson.ts +806 -0
  663. package/src/rdfjson/index.ts +9 -0
  664. package/src/rdfjson/internal/json.ts +19 -0
  665. package/src/rdfxml/RdfXml.ts +1408 -0
  666. package/src/rdfxml/Xml.ts +419 -0
  667. package/src/rdfxml/index.ts +11 -0
  668. package/src/rdfxml/internal/chars.ts +73 -0
  669. package/src/rdfxml/internal/loop.ts +24 -0
  670. package/src/rdfxml/internal/parser.ts +1265 -0
  671. package/src/shacl/Message.ts +102 -0
  672. package/src/shacl/Path.ts +483 -0
  673. package/src/shacl/Shapes.ts +913 -0
  674. package/src/shacl/Sparql.ts +128 -0
  675. package/src/shacl/ValidationReport.ts +438 -0
  676. package/src/shacl/Validator.ts +1156 -0
  677. package/src/shacl/Vocabulary.ts +180 -0
  678. package/src/shacl/index.ts +22 -0
  679. package/src/shacl/internal/compare.ts +128 -0
  680. package/src/shacl/internal/regex.ts +56 -0
  681. package/src/shex/SemAct.ts +197 -0
  682. package/src/shex/ShExC.ts +415 -0
  683. package/src/shex/ShExError.ts +71 -0
  684. package/src/shex/ShExJ.ts +893 -0
  685. package/src/shex/ShExR.ts +640 -0
  686. package/src/shex/ShapeMap.ts +385 -0
  687. package/src/shex/Structure.ts +467 -0
  688. package/src/shex/Validator.ts +395 -0
  689. package/src/shex/index.ts +24 -0
  690. package/src/shex/internal/engine.ts +682 -0
  691. package/src/shex/internal/iterate.ts +14 -0
  692. package/src/shex/internal/json.ts +12 -0
  693. package/src/shex/internal/lexer.ts +56 -0
  694. package/src/shex/internal/nodeConstraint.ts +368 -0
  695. package/src/shex/internal/shexcLexer.ts +387 -0
  696. package/src/shex/internal/shexcParser.ts +1312 -0
  697. package/src/shex/internal/tokens.ts +41 -0
  698. package/src/shex/internal/xpathRegex.ts +290 -0
  699. package/src/sparql/Algebra.ts +914 -0
  700. package/src/sparql/Ast.ts +1344 -0
  701. package/src/sparql/Bindings.ts +272 -0
  702. package/src/sparql/ClientErrors.ts +156 -0
  703. package/src/sparql/ClientFormats.ts +70 -0
  704. package/src/sparql/Engine.ts +699 -0
  705. package/src/sparql/Errors.ts +30 -0
  706. package/src/sparql/Expression.ts +360 -0
  707. package/src/sparql/Federation.ts +187 -0
  708. package/src/sparql/Functions.ts +689 -0
  709. package/src/sparql/Generator.ts +426 -0
  710. package/src/sparql/GraphStore.ts +341 -0
  711. package/src/sparql/Optimizer.ts +230 -0
  712. package/src/sparql/Options.ts +191 -0
  713. package/src/sparql/Parser.ts +173 -0
  714. package/src/sparql/Protocol.ts +342 -0
  715. package/src/sparql/ProtocolErrors.ts +113 -0
  716. package/src/sparql/QueryBuilder.ts +953 -0
  717. package/src/sparql/Results.ts +844 -0
  718. package/src/sparql/ResultsStream.ts +771 -0
  719. package/src/sparql/ServerFormats.ts +75 -0
  720. package/src/sparql/ServiceDescription.ts +130 -0
  721. package/src/sparql/SparqlClient.ts +947 -0
  722. package/src/sparql/SparqlServer.ts +528 -0
  723. package/src/sparql/Store.ts +311 -0
  724. package/src/sparql/TermSchema.ts +20 -0
  725. package/src/sparql/Testing.ts +114 -0
  726. package/src/sparql/Translate.ts +407 -0
  727. package/src/sparql/ai/Mcp.ts +43 -0
  728. package/src/sparql/ai/Tools.ts +481 -0
  729. package/src/sparql/ai/index.ts +11 -0
  730. package/src/sparql/index.ts +64 -0
  731. package/src/sparql/internal/evaluator.ts +947 -0
  732. package/src/sparql/internal/hash.ts +418 -0
  733. package/src/sparql/internal/json.ts +12 -0
  734. package/src/sparql/internal/lexer.ts +488 -0
  735. package/src/sparql/internal/loop.ts +24 -0
  736. package/src/sparql/internal/parser.ts +2215 -0
  737. package/src/sparql/internal/prefetch.ts +46 -0
  738. package/src/sparql/internal/stringMap.ts +39 -0
  739. package/src/sparql/internal/textResults.ts +226 -0
  740. package/src/sparql/internal/values.ts +550 -0
  741. package/src/sparql/shacl/Evaluator.ts +478 -0
  742. package/src/sparql/shacl/Query.ts +574 -0
  743. package/src/sparql/shacl/index.ts +12 -0
  744. package/src/sparql/sql/Dialect.ts +246 -0
  745. package/src/sparql/sql/SqlStore.ts +1080 -0
  746. package/src/sparql/sql/Translation.ts +1898 -0
  747. package/src/sparql/sql/index.ts +17 -0
  748. package/src/sparql/sql/internal/encoding.ts +313 -0
  749. package/src/turtle/Grammar.ts +286 -0
  750. package/src/turtle/Manifest.ts +215 -0
  751. package/src/turtle/TriG.ts +158 -0
  752. package/src/turtle/Turtle.ts +166 -0
  753. package/src/turtle/index.ts +14 -0
  754. package/src/turtle/internal/loop.ts +23 -0
  755. package/src/turtle/internal/parse.ts +112 -0
  756. package/src/turtle/internal/parser.ts +1303 -0
  757. package/src/turtle/internal/serialize.ts +79 -0
  758. package/src/turtle/internal/streamWriter.ts +128 -0
  759. package/src/turtle/internal/writer.ts +898 -0
  760. package/src/xmp/DublinCore.ts +147 -0
  761. package/src/xmp/Exif.ts +109 -0
  762. package/src/xmp/Extract.ts +351 -0
  763. package/src/xmp/Metadata.ts +703 -0
  764. package/src/xmp/Namespaces.ts +228 -0
  765. package/src/xmp/Packet.ts +297 -0
  766. package/src/xmp/Pdf.ts +99 -0
  767. package/src/xmp/PdfA.ts +280 -0
  768. package/src/xmp/Photoshop.ts +275 -0
  769. package/src/xmp/Tiff.ts +196 -0
  770. package/src/xmp/Xmp.ts +430 -0
  771. package/src/xmp/XmpBasic.ts +90 -0
  772. package/src/xmp/XmpMM.ts +82 -0
  773. package/src/xmp/XmpRights.ts +83 -0
  774. package/src/xmp/index.ts +36 -0
  775. package/src/xmp/internal/accessors.ts +72 -0
  776. package/src/xmp/internal/xml.ts +63 -0
@@ -0,0 +1,1408 @@
1
+ /**
2
+ * RDF 1.2 XML Syntax (RDF/XML): parser and serializer.
3
+ *
4
+ * The parser implements the RDF/XML grammar of
5
+ * https://www.w3.org/TR/rdf-syntax-grammar/ together with the RDF 1.2
6
+ * additions: `rdf:version`, base direction via `its:dir`, triple terms via
7
+ * `rdf:parseType="Triple"`, and annotations via `rdf:annotation` /
8
+ * `rdf:annotationNodeID`. `rdf:parseType="Literal"` content is turned into
9
+ * an `rdf:XMLLiteral` using Exclusive XML Canonicalization.
10
+ *
11
+ * The serializer writes readable RDF/XML: typed node elements, nested blank
12
+ * nodes where a blank node is referenced exactly once, namespace
13
+ * declarations taken from `options.prefixes` and generated namespaces for the
14
+ * rest.
15
+ *
16
+ * @since 0.1.0
17
+ */
18
+ import * as Arr from 'effect/Array';
19
+ import * as Effect from 'effect/Effect';
20
+ import * as Match from 'effect/Match';
21
+ import * as MutableHashMap from 'effect/MutableHashMap';
22
+ import * as MutableHashSet from 'effect/MutableHashSet';
23
+ import * as Option from 'effect/Option';
24
+ import * as Predicate from 'effect/Predicate';
25
+ import * as Result from 'effect/Result';
26
+ import * as Order from 'effect/Order';
27
+ import * as Dataset from '../Dataset.ts';
28
+ import * as Iri from '../Iri.ts';
29
+ import * as PrefixMap from '../PrefixMap.ts';
30
+ import * as Serialization from '../Serialization.ts';
31
+ import * as Term from '../Term.ts';
32
+ import * as Xml from './Xml.ts';
33
+ import * as XmlParser from './internal/parser.ts';
34
+
35
+ const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
36
+ const ITS = 'http://www.w3.org/2005/11/its';
37
+ const XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string';
38
+ const FORMAT_NAME = 'RDF/XML';
39
+
40
+ /**
41
+ * The RDF/XML format description (`application/rdf+xml`).
42
+ *
43
+ * @since 0.1.0
44
+ * @category formats
45
+ */
46
+ export const format: Serialization.Format = Serialization.makeFormat({
47
+ name: FORMAT_NAME,
48
+ mediaType: 'application/rdf+xml',
49
+ extensions: ['rdf', 'owl'],
50
+ datasets: false,
51
+ });
52
+
53
+ // Spans are named `RdfXml.parse`, `RdfXml.serialize`.
54
+ const trace: Serialization.SpanTarget = { module: 'RdfXml', format };
55
+
56
+ // -----------------------------------------------------------------------------
57
+ // Parsing
58
+ // -----------------------------------------------------------------------------
59
+
60
+ /**
61
+ * Options for parsing RDF/XML.
62
+ *
63
+ * @since 0.1.0
64
+ * @category models
65
+ */
66
+ export interface ParseOptions extends Serialization.ParseOptions {
67
+ /**
68
+ * The RDF version assumed when the document does not announce one with
69
+ * `rdf:version`. RDF 1.2 features that require a version announcement
70
+ * (base direction and triple terms) are only enabled when a version other
71
+ * than `"1.0"`/`"1.1"` is in scope. Defaults to none.
72
+ */
73
+ readonly version?: string | undefined;
74
+ }
75
+
76
+ const rdf = (local: string) => RDF + local;
77
+
78
+ /** The core syntax terms and the old terms, which are never node, property or attribute names. */
79
+ const RESERVED_TERMS = MutableHashSet.fromIterable(
80
+ [
81
+ 'RDF',
82
+ 'ID',
83
+ 'about',
84
+ 'annotation',
85
+ 'annotationNodeID',
86
+ 'parseType',
87
+ 'resource',
88
+ 'nodeID',
89
+ 'datatype',
90
+ 'version',
91
+ 'aboutEach',
92
+ 'aboutEachPrefix',
93
+ 'bagID',
94
+ ].map(rdf),
95
+ );
96
+ const UNQUALIFIED_RDF_ATTRIBUTES = MutableHashSet.make(
97
+ 'ID',
98
+ 'about',
99
+ 'resource',
100
+ 'parseType',
101
+ 'type',
102
+ 'version',
103
+ );
104
+
105
+ const RDF_DESCRIPTION = rdf('Description');
106
+ const RDF_LI = rdf('li');
107
+ const RDF_TYPE = rdf('type');
108
+ const RDF_ID = rdf('ID');
109
+ const RDF_NODE_ID = rdf('nodeID');
110
+ const RDF_ABOUT = rdf('about');
111
+ const RDF_VERSION = rdf('version');
112
+ const RDF_ANNOTATION = rdf('annotation');
113
+ const RDF_ANNOTATION_NODE_ID = rdf('annotationNodeID');
114
+ const RDF_PARSE_TYPE = rdf('parseType');
115
+ const RDF_RESOURCE = rdf('resource');
116
+ const RDF_DATATYPE = rdf('datatype');
117
+
118
+ const isReserved = (iri: string): boolean => MutableHashSet.has(RESERVED_TERMS, iri);
119
+ const isForbiddenNodeElement = (iri: string) => isReserved(iri) || iri === RDF_LI;
120
+ const isForbiddenPropertyElement = (iri: string) => isReserved(iri) || iri === RDF_DESCRIPTION;
121
+ const isForbiddenPropertyAttribute = (iri: string) =>
122
+ isReserved(iri) || iri === RDF_DESCRIPTION || iri === RDF_LI;
123
+
124
+ const isElement = Predicate.isTagged('Element');
125
+ const isText = Predicate.isTagged('Text');
126
+
127
+ class ParseFailure {
128
+ readonly message: string;
129
+ readonly position: Xml.Position;
130
+ constructor(message: string, position: Xml.Position) {
131
+ this.message = message;
132
+ this.position = position;
133
+ }
134
+ }
135
+
136
+ interface Context {
137
+ readonly base: Option.Option<string>;
138
+ readonly language: string;
139
+ readonly direction: '' | Term.Direction;
140
+ readonly version: Option.Option<string>;
141
+ }
142
+
143
+ /** Resolves `reference` against the base IRI of `ctx`, if it has one. */
144
+ const resolveIn = (reference: string, base: Option.Option<string>): string =>
145
+ Iri.resolve(reference, Option.getOrUndefined(base));
146
+
147
+ interface Attr {
148
+ readonly iri: string;
149
+ readonly value: string;
150
+ readonly attribute: Xml.Attribute;
151
+ }
152
+
153
+ const isRdf12 = (version: Option.Option<string>): boolean =>
154
+ Option.isSome(version) && version.value !== '1.0' && version.value !== '1.1';
155
+
156
+ const rdfType = new Term.NamedNode(rdf('type'));
157
+ const rdfFirst = new Term.NamedNode(rdf('first'));
158
+ const rdfRest = new Term.NamedNode(rdf('rest'));
159
+ const rdfNil = new Term.NamedNode(rdf('nil'));
160
+ const rdfStatement = new Term.NamedNode(rdf('Statement'));
161
+ const rdfSubject = new Term.NamedNode(rdf('subject'));
162
+ const rdfPredicate = new Term.NamedNode(rdf('predicate'));
163
+ const rdfObject = new Term.NamedNode(rdf('object'));
164
+ const rdfReifies = new Term.NamedNode(rdf('reifies'));
165
+ const rdfXmlLiteral = new Term.NamedNode(rdf('XMLLiteral'));
166
+
167
+ /** The syntax attributes of a node element, gathered by `nodeAttribute`. */
168
+ interface NodeAttributes {
169
+ idAttr: Option.Option<Attr>;
170
+ readonly props: Array<Attr>;
171
+ }
172
+
173
+ /**
174
+ * Adds an attribute that is not a syntax attribute of its element to `props`
175
+ * (`rdf:version` aside, which `context` reads).
176
+ */
177
+ const propertyAttr = (a: Attr, parser: RdfXmlParser, props: Array<Attr>): void => {
178
+ if (a.iri === RDF_VERSION) return;
179
+ if (isForbiddenPropertyAttribute(a.iri)) {
180
+ parser.fail(`${a.attribute.name} is not allowed as a property attribute`, a.attribute);
181
+ }
182
+ props.push(a);
183
+ };
184
+
185
+ /** Gathers an attribute of a node element (run for every one, so a chain of comparisons). */
186
+ const nodeAttribute = (a: Attr, parser: RdfXmlParser, attrs: NodeAttributes): void => {
187
+ const iri = a.iri;
188
+ if (iri !== RDF_ID && iri !== RDF_NODE_ID && iri !== RDF_ABOUT) {
189
+ propertyAttr(a, parser, attrs.props);
190
+ return;
191
+ }
192
+ if (Option.isSome(attrs.idAttr)) {
193
+ parser.fail(
194
+ `rdf:${attrs.idAttr.value.attribute.localName} and rdf:${a.attribute.localName} cannot be used together`,
195
+ a.attribute,
196
+ );
197
+ }
198
+ attrs.idAttr = Option.some(a);
199
+ };
200
+
201
+ /** The syntax attributes of a property element, gathered by `propertyAttribute`. */
202
+ interface PropertyAttributes {
203
+ id: Option.Option<Attr>;
204
+ annotation: Option.Option<Attr>;
205
+ parseType: Option.Option<Attr>;
206
+ resource: Option.Option<Attr>;
207
+ nodeId: Option.Option<Attr>;
208
+ datatype: Option.Option<Attr>;
209
+ readonly props: Array<Attr>;
210
+ }
211
+
212
+ /** Gathers an attribute of a property element (run for every one, so a chain of comparisons). */
213
+ const propertyAttribute = (a: Attr, parser: RdfXmlParser, attrs: PropertyAttributes): void => {
214
+ const iri = a.iri;
215
+ if (iri === RDF_ID) attrs.id = Option.some(a);
216
+ else if (iri === RDF_ANNOTATION || iri === RDF_ANNOTATION_NODE_ID) {
217
+ if (Option.isSome(attrs.annotation)) {
218
+ parser.fail('rdf:annotation and rdf:annotationNodeID cannot be used together', a.attribute);
219
+ }
220
+ attrs.annotation = Option.some(a);
221
+ } else if (iri === RDF_PARSE_TYPE) attrs.parseType = Option.some(a);
222
+ else if (iri === RDF_RESOURCE) attrs.resource = Option.some(a);
223
+ else if (iri === RDF_NODE_ID) attrs.nodeId = Option.some(a);
224
+ else if (iri === RDF_DATATYPE) attrs.datatype = Option.some(a);
225
+ else propertyAttr(a, parser, attrs.props);
226
+ };
227
+
228
+ const isRdfRoot = (root: Xml.Element): boolean =>
229
+ root.namespace === RDF && root.localName === 'RDF';
230
+
231
+ class RdfXmlParser {
232
+ sink: Array<Term.Triple> = [];
233
+ readonly ids = MutableHashSet.empty<string>();
234
+ counter = 0;
235
+
236
+ readonly blankNodePrefix: string;
237
+ readonly defaultVersion: Option.Option<string>;
238
+ constructor(blankNodePrefix: string, defaultVersion: Option.Option<string>) {
239
+ this.blankNodePrefix = blankNodePrefix;
240
+ this.defaultVersion = defaultVersion;
241
+ }
242
+
243
+ fail(message: string, node: { readonly position: Xml.Position }): never {
244
+ throw new ParseFailure(message, node.position);
245
+ }
246
+
247
+ /** Fails if any of `attrs` is present: the first `<name> <why>`. */
248
+ reject(attrs: Iterable<Option.Option<Attr>>, why: string): void {
249
+ const other = Option.firstSomeOf(attrs);
250
+ if (Option.isSome(other)) {
251
+ const { attribute } = other.value;
252
+ this.fail(`${attribute.name} ${why}`, attribute);
253
+ }
254
+ }
255
+
256
+ emit(s: Term.Subject, p: Term.NamedNode, o: Term.Object): Term.Triple {
257
+ const t = new Term.Triple(s, p, o);
258
+ this.sink.push(t);
259
+ return t;
260
+ }
261
+
262
+ fresh(): Term.BlankNode {
263
+ return new Term.BlankNode(`${this.blankNodePrefix}${this.counter++}`);
264
+ }
265
+
266
+ blank(id: string, node: { readonly position: Xml.Position }): Term.BlankNode {
267
+ if (!Xml.isNCName(id)) this.fail(`Invalid blank node identifier "${id}"`, node);
268
+ return new Term.BlankNode(`${this.blankNodePrefix}${id}`);
269
+ }
270
+
271
+ /** The IRIs of names and datatypes seen so far, which repeat throughout a document. */
272
+ private readonly names = MutableHashMap.empty<string, Term.NamedNode>();
273
+
274
+ /**
275
+ * The IRIs of the names read so far, by local name, then namespace (a
276
+ * local name rarely has more than one).
277
+ */
278
+ private readonly qualifiedNames = MutableHashMap.empty<
279
+ string,
280
+ Array<readonly [namespace: string, iri: string]>
281
+ >();
282
+
283
+ /**
284
+ * The IRI of a name (`namespace` + `localName`), the same string each time
285
+ * it is read: names repeat throughout a document, and each later lookup of
286
+ * the IRI (in the reserved-term set, the node cache) then hashes nothing.
287
+ */
288
+ qualified(namespace: string, localName: string): string {
289
+ const byLocalName = MutableHashMap.get(this.qualifiedNames, localName);
290
+ if (Option.isNone(byLocalName)) {
291
+ const iri = namespace + localName;
292
+ MutableHashMap.set(this.qualifiedNames, localName, [[namespace, iri]]);
293
+ return iri;
294
+ }
295
+ const byNamespace = byLocalName.value;
296
+ const known = byNamespace.find(([ns]) => ns === namespace);
297
+ if (known !== undefined) return known[1];
298
+ const iri = namespace + localName;
299
+ byNamespace.push([namespace, iri]);
300
+ return iri;
301
+ }
302
+
303
+ /** The node for the IRI of an element or attribute name, or of a datatype. */
304
+ named(iri: string): Term.NamedNode {
305
+ const known = MutableHashMap.get(this.names, iri);
306
+ if (Option.isSome(known)) return known.value;
307
+ const node = new Term.NamedNode(iri);
308
+ MutableHashMap.set(this.names, iri, node);
309
+ return node;
310
+ }
311
+
312
+ iri(value: string, ctx: Context): Term.NamedNode {
313
+ return new Term.NamedNode(resolveIn(value, ctx.base));
314
+ }
315
+
316
+ idIri(id: string, ctx: Context, node: { readonly position: Xml.Position }): Term.NamedNode {
317
+ if (!Xml.isNCName(id)) this.fail(`Invalid rdf:ID "${id}"`, node);
318
+ const iri = resolveIn(`#${id}`, ctx.base);
319
+ if (MutableHashSet.has(this.ids, iri)) this.fail(`Duplicate rdf:ID "${id}"`, node);
320
+ MutableHashSet.add(this.ids, iri);
321
+ return new Term.NamedNode(iri);
322
+ }
323
+
324
+ literal(value: string, ctx: Context): Term.Literal {
325
+ if (ctx.language === '') return Term.literal(value);
326
+ return ctx.direction === ''
327
+ ? Term.literal(value, ctx.language)
328
+ : Term.literal(value, { language: ctx.language, direction: ctx.direction });
329
+ }
330
+
331
+ /** Computes the evaluation context of an element. */
332
+ context(el: Xml.Element, parent: Context): Context {
333
+ if (Arr.isReadonlyArrayEmpty(el.attributes)) return parent;
334
+ let base = parent.base;
335
+ let language = parent.language;
336
+ let direction = parent.direction;
337
+ let version = parent.version;
338
+ let dir = Option.none<Xml.Attribute>();
339
+ el.attributes.forEach((a) => {
340
+ if (a.namespace === Xml.XML_NAMESPACE) {
341
+ if (a.localName === 'base') base = Option.some(resolveIn(a.value, base));
342
+ else if (a.localName === 'lang') language = a.value;
343
+ } else if (a.namespace === ITS && a.localName === 'dir') {
344
+ dir = Option.some(a);
345
+ } else if ((a.namespace === RDF || a.namespace === undefined) && a.localName === 'version') {
346
+ version = Option.some(a.value);
347
+ }
348
+ });
349
+ if (Option.isSome(dir) && isRdf12(version)) {
350
+ const value = dir.value.value;
351
+ if (value !== 'ltr' && value !== 'rtl' && value !== '') {
352
+ this.fail(`Invalid its:dir value "${value}"`, dir.value);
353
+ }
354
+ // SAFETY: the value was checked to be `ltr` or `rtl` above.
355
+ direction = value;
356
+ }
357
+ return { base, language, direction, version };
358
+ }
359
+
360
+ /** The RDF-relevant attributes of an element, with their IRIs. */
361
+ attributes(el: Xml.Element): Array<Attr> {
362
+ const out: Array<Attr> = [];
363
+ el.attributes.forEach((a) => {
364
+ if (a.namespace === Xml.XML_NAMESPACE) return;
365
+ if (a.prefix.toLowerCase().startsWith('xml')) return;
366
+ if (a.namespace === undefined) {
367
+ if (a.localName.toLowerCase().startsWith('xml')) return;
368
+ if (!MutableHashSet.has(UNQUALIFIED_RDF_ATTRIBUTES, a.localName)) {
369
+ this.fail(`Unqualified attribute "${a.localName}" is not allowed`, a);
370
+ }
371
+ out.push({ iri: this.qualified(RDF, a.localName), value: a.value, attribute: a });
372
+ return;
373
+ }
374
+ if (a.namespace === ITS && (a.localName === 'dir' || a.localName === 'version')) return;
375
+ out.push({ iri: this.qualified(a.namespace, a.localName), value: a.value, attribute: a });
376
+ });
377
+ return out;
378
+ }
379
+
380
+ elementIri(el: Xml.Element): string {
381
+ if (el.namespace === undefined) {
382
+ this.fail(`Element "${el.name}" is not in a namespace`, el);
383
+ }
384
+ return this.qualified(el.namespace, el.localName);
385
+ }
386
+
387
+ document(doc: Xml.Document, base: Option.Option<string>): void {
388
+ const root = doc.root;
389
+ const ctx: Context = { base, language: '', direction: '', version: this.defaultVersion };
390
+ if (isRdfRoot(root)) this.nodeElementList(root.children, this.rdfRoot(root, ctx));
391
+ else this.nodeElement(root, ctx);
392
+ }
393
+
394
+ /** The context of the node elements in an `rdf:RDF` root, after checking its attributes. */
395
+ rdfRoot(root: Xml.Element, ctx: Context): Context {
396
+ const rootCtx = this.context(root, ctx);
397
+ this.attributes(root).forEach((a) => {
398
+ if (a.iri !== RDF_VERSION) this.fail(`Unexpected attribute on rdf:RDF`, a.attribute);
399
+ });
400
+ return rootCtx;
401
+ }
402
+
403
+ nodeElementList(children: ReadonlyArray<Xml.Node>, ctx: Context): Array<Term.Subject> {
404
+ const subjects: Array<Term.Subject> = [];
405
+ children.forEach((c) => {
406
+ if (isElement(c)) subjects.push(this.nodeElement(c, ctx));
407
+ else if (isText(c) && !Xml.isWhitespace(c.value)) {
408
+ this.fail('Unexpected text where node elements are expected', c);
409
+ }
410
+ });
411
+ return subjects;
412
+ }
413
+
414
+ nodeElement(el: Xml.Element, parentCtx: Context): Term.Subject {
415
+ const ctx = this.context(el, parentCtx);
416
+ const iri = this.elementIri(el);
417
+ if (isForbiddenNodeElement(iri)) this.fail(`<${el.name}> is not allowed as a node element`, el);
418
+ const attrs: NodeAttributes = { idAttr: Option.none(), props: [] };
419
+ this.attributes(el).forEach((a) => nodeAttribute(a, this, attrs));
420
+ const s: Term.Subject = Option.match(attrs.idAttr, {
421
+ onNone: () => this.fresh(),
422
+ onSome: (idAttr) => {
423
+ const local = idAttr.iri.slice(RDF.length);
424
+ return local === 'ID'
425
+ ? this.idIri(idAttr.value, ctx, idAttr.attribute)
426
+ : local === 'nodeID'
427
+ ? this.blank(idAttr.value, idAttr.attribute)
428
+ : this.iri(idAttr.value, ctx);
429
+ },
430
+ });
431
+ if (iri !== RDF_DESCRIPTION) this.emit(s, rdfType, this.named(iri));
432
+ attrs.props.forEach((a) => {
433
+ this.emit(
434
+ s,
435
+ this.named(a.iri),
436
+ a.iri === RDF_TYPE ? this.iri(a.value, ctx) : this.literal(a.value, ctx),
437
+ );
438
+ });
439
+ this.propertyEltList(el, s, ctx);
440
+ return s;
441
+ }
442
+
443
+ propertyEltList(el: Xml.Element, subject: Term.Subject, ctx: Context): void {
444
+ let li = 1;
445
+ el.children.forEach((c) => {
446
+ if (isElement(c)) {
447
+ const name = this.elementIri(c);
448
+ this.propertyElt(c, name === RDF_LI ? rdf(`_${li++}`) : name, subject, ctx);
449
+ } else if (isText(c) && !Xml.isWhitespace(c.value)) {
450
+ this.fail('Unexpected text where property elements are expected', c);
451
+ }
452
+ });
453
+ }
454
+
455
+ propertyElt(el: Xml.Element, iri: string, subject: Term.Subject, parentCtx: Context): void {
456
+ if (isForbiddenPropertyElement(iri)) {
457
+ this.fail(`<${el.name}> is not allowed as a property element`, el);
458
+ }
459
+ const ctx = this.context(el, parentCtx);
460
+ const predicate = this.named(iri);
461
+ const attrs: PropertyAttributes = {
462
+ id: Option.none(),
463
+ annotation: Option.none(),
464
+ parseType: Option.none(),
465
+ resource: Option.none(),
466
+ nodeId: Option.none(),
467
+ datatype: Option.none(),
468
+ props: [],
469
+ };
470
+ this.attributes(el).forEach((a) => propertyAttribute(a, this, attrs));
471
+ const { id, annotation, parseType, resource, nodeId, datatype, props } = attrs;
472
+ const elements: Array<Xml.Element> = [];
473
+ let text = '';
474
+ let hasText = false;
475
+ el.children.forEach((c) => {
476
+ if (isElement(c)) elements.push(c);
477
+ else if (isText(c)) {
478
+ text += c.value;
479
+ hasText = true;
480
+ }
481
+ });
482
+
483
+ const finish = (object: Term.Object) => {
484
+ const statement = this.emit(subject, predicate, object);
485
+ this.reify(statement, id, annotation, ctx);
486
+ };
487
+ const firstProp = Arr.head(props);
488
+
489
+ if (Option.isSome(parseType)) {
490
+ this.reject([resource, nodeId, datatype, firstProp], 'cannot be used with rdf:parseType');
491
+ Match.value(parseType.value.value).pipe(
492
+ Match.when('Resource', () => {
493
+ const n = this.fresh();
494
+ finish(n);
495
+ this.propertyEltList(el, n, ctx);
496
+ }),
497
+ Match.when('Collection', () => {
498
+ const items = this.nodeElementList(el.children, ctx);
499
+ if (!Arr.isArrayNonEmpty(items)) {
500
+ finish(rdfNil);
501
+ return;
502
+ }
503
+ const cells = Arr.map(items, () => this.fresh());
504
+ finish(Arr.headNonEmpty(cells));
505
+ Arr.zip(cells, items).forEach(([cell, item], i) => {
506
+ this.emit(cell, rdfFirst, item);
507
+ this.emit(cell, rdfRest, cells[i + 1] ?? rdfNil);
508
+ });
509
+ }),
510
+ Match.when('Triple', () => {
511
+ const saved = this.sink;
512
+ this.sink = [];
513
+ if (
514
+ !Arr.isArrayNonEmpty(elements) ||
515
+ elements.length !== 1 ||
516
+ (hasText && !Xml.isWhitespace(text))
517
+ ) {
518
+ this.fail('rdf:parseType="Triple" must contain exactly one node element', el);
519
+ }
520
+ this.nodeElement(Arr.headNonEmpty(elements), ctx);
521
+ const triples = this.sink;
522
+ this.sink = saved;
523
+ if (!isRdf12(ctx.version)) {
524
+ // Triple terms require an RDF 1.2 version announcement; without
525
+ // one the property element is ignored.
526
+ return;
527
+ }
528
+ if (!Arr.isArrayNonEmpty(triples) || triples.length !== 1) {
529
+ this.fail(
530
+ `rdf:parseType="Triple" content must describe exactly one triple, found ${triples.length}`,
531
+ el,
532
+ );
533
+ }
534
+ finish(Arr.headNonEmpty(triples));
535
+ }),
536
+ Match.orElse(() => {
537
+ finish(new Term.Literal(Xml.canonicalize(el.children), rdfXmlLiteral));
538
+ }),
539
+ );
540
+ return;
541
+ }
542
+
543
+ if (Arr.isArrayNonEmpty(elements)) {
544
+ if (elements.length > 1)
545
+ this.fail('A property element can contain only one node element', el);
546
+ if (!Xml.isWhitespace(text))
547
+ this.fail('Mixed content is not allowed in a property element', el);
548
+ this.reject(
549
+ [resource, nodeId, datatype, firstProp],
550
+ 'is not allowed on a property element with content',
551
+ );
552
+ finish(this.nodeElement(Arr.headNonEmpty(elements), ctx));
553
+ return;
554
+ }
555
+
556
+ if (hasText && text !== '') {
557
+ this.reject([resource, nodeId, firstProp], 'is not allowed on a literal property element');
558
+ finish(
559
+ Option.isSome(datatype)
560
+ ? Term.literal(text, this.named(resolveIn(datatype.value.value, ctx.base)))
561
+ : this.literal(text, ctx),
562
+ );
563
+ return;
564
+ }
565
+
566
+ // empty property element
567
+ if (Option.isSome(resource) && Option.isSome(nodeId)) {
568
+ this.fail('rdf:resource and rdf:nodeID cannot be used together', nodeId.value.attribute);
569
+ }
570
+ if (Option.isSome(datatype)) {
571
+ this.reject([resource, nodeId, firstProp], 'cannot be used with rdf:datatype');
572
+ finish(Term.literal('', this.named(resolveIn(datatype.value.value, ctx.base))));
573
+ return;
574
+ }
575
+ if (Option.isNone(resource) && Option.isNone(nodeId) && Arr.isReadonlyArrayEmpty(props)) {
576
+ finish(this.literal('', ctx));
577
+ return;
578
+ }
579
+ const r: Term.NamedNode | Term.BlankNode = Option.isSome(resource)
580
+ ? this.iri(resource.value.value, ctx)
581
+ : Option.isSome(nodeId)
582
+ ? this.blank(nodeId.value.value, nodeId.value.attribute)
583
+ : this.fresh();
584
+ props.forEach((a) => {
585
+ this.emit(
586
+ r,
587
+ this.named(a.iri),
588
+ a.iri === RDF_TYPE ? this.iri(a.value, ctx) : this.literal(a.value, ctx),
589
+ );
590
+ });
591
+ finish(r);
592
+ }
593
+
594
+ reify(
595
+ statement: Term.Triple,
596
+ id: Option.Option<Attr>,
597
+ annotation: Option.Option<Attr>,
598
+ ctx: Context,
599
+ ) {
600
+ if (Option.isSome(id)) {
601
+ const i = this.idIri(id.value.value, ctx, id.value.attribute);
602
+ this.emit(i, rdfType, rdfStatement);
603
+ this.emit(i, rdfSubject, statement.subject);
604
+ this.emit(i, rdfPredicate, statement.predicate);
605
+ this.emit(i, rdfObject, statement.object);
606
+ }
607
+ if (Option.isSome(annotation)) {
608
+ const { iri, value, attribute } = annotation.value;
609
+ const reifier = iri === RDF_ANNOTATION ? this.iri(value, ctx) : this.blank(value, attribute);
610
+ this.emit(reifier, rdfReifies, statement);
611
+ }
612
+ }
613
+ }
614
+
615
+ const toParseError = (message: string, position: Xml.Position) =>
616
+ new Serialization.RdfParseError({
617
+ format: FORMAT_NAME,
618
+ message,
619
+ line: position.line,
620
+ column: position.column,
621
+ });
622
+
623
+ const parseTriples = (
624
+ doc: Xml.Document,
625
+ options?: ParseOptions,
626
+ ): Effect.Effect<ReadonlyArray<Term.Triple>, Serialization.RdfParseError> =>
627
+ Effect.try({
628
+ try: () => {
629
+ const parser = new RdfXmlParser(
630
+ options?.blankNodePrefix ?? Serialization.freshBlankNodePrefix(),
631
+ Option.fromUndefinedOr(options?.version),
632
+ );
633
+ parser.document(doc, Option.fromUndefinedOr(options?.baseIri));
634
+ return parser.sink;
635
+ },
636
+ catch: (e) => {
637
+ if (e instanceof ParseFailure) return toParseError(e.message, e.position);
638
+ throw e;
639
+ },
640
+ });
641
+
642
+ /** Prefixes in the order first declared, each with its first namespace. */
643
+ type Prefixes = Array<readonly [prefix: string, namespace: string]>;
644
+
645
+ /**
646
+ * Adds the namespace declarations of the elements among `nodes` (at
647
+ * `depth`, the root's being 0) and of their descendants down to `maxDepth`
648
+ * to `prefixes`, keeping the first declaration of each prefix.
649
+ */
650
+ const declarePrefixes = (
651
+ prefixes: Prefixes,
652
+ nodes: ReadonlyArray<Xml.Node>,
653
+ depth: number,
654
+ maxDepth: number,
655
+ ): void => {
656
+ nodes.forEach((node) => {
657
+ if (!isElement(node)) return;
658
+ node.namespaceDeclarations.forEach((d) => {
659
+ if (d.prefix !== '' && d.namespace !== '' && !prefixes.some(([p]) => p === d.prefix)) {
660
+ prefixes.push([d.prefix, d.namespace]);
661
+ }
662
+ });
663
+ if (depth < maxDepth) declarePrefixes(prefixes, node.children, depth + 1, maxDepth);
664
+ });
665
+ };
666
+
667
+ /** The prefixes declared on the root, its children and their children. */
668
+ const collectPrefixes = (doc: Xml.Document): PrefixMap.PrefixMap => {
669
+ const prefixes: Prefixes = [];
670
+ declarePrefixes(prefixes, [doc.root], 0, 2);
671
+ return PrefixMap.make(prefixes);
672
+ };
673
+
674
+ /**
675
+ * Converts the node elements of an `rdf:RDF` root while the XML is read, as
676
+ * each one is closed, so that no more than one of them is held at a time.
677
+ * The order of conversion (and so of triples, blank nodes and prefixes) and
678
+ * which error is reported are as for a whole document: an XML error anywhere
679
+ * comes first, so the first RDF/XML error is kept until the XML has been
680
+ * read.
681
+ */
682
+ class RootStream {
683
+ readonly parser: RdfXmlParser;
684
+ /** The context outside the root, and then that of its node elements. */
685
+ private ctx: Context;
686
+ readonly prefixes: Prefixes = [];
687
+ readonly failures: Array<ParseFailure> = [];
688
+ /** Whether the root has been seen, and whether it is `rdf:RDF`. */
689
+ private started = false;
690
+ private streaming = false;
691
+ /** How many of the children the root kept have been converted. */
692
+ private converted = 0;
693
+
694
+ constructor(parser: RdfXmlParser, ctx: Context) {
695
+ this.parser = parser;
696
+ this.ctx = ctx;
697
+ }
698
+
699
+ /** The `RootChildHook`: takes the child if the root is `rdf:RDF`. */
700
+ readonly take = (child: Xml.Element, root: Xml.Element): boolean => {
701
+ if (!this.begin(root)) return false;
702
+ this.guard(() => {
703
+ this.drain(root);
704
+ declarePrefixes(this.prefixes, [child], 1, 2);
705
+ this.parser.nodeElement(child, this.ctx);
706
+ });
707
+ return true;
708
+ };
709
+
710
+ /** Converts what is left once the document has been read. */
711
+ finish(doc: Xml.Document): void {
712
+ if (this.begin(doc.root)) {
713
+ this.guard(() => this.drain(doc.root));
714
+ } else {
715
+ this.parser.document(doc, this.ctx.base);
716
+ declarePrefixes(this.prefixes, [doc.root], 0, 2);
717
+ }
718
+ const failure = this.failures.at(0);
719
+ if (failure !== undefined) throw failure;
720
+ }
721
+
722
+ private begin(root: Xml.Element): boolean {
723
+ if (!this.started) {
724
+ this.started = true;
725
+ this.streaming = isRdfRoot(root);
726
+ if (this.streaming) {
727
+ declarePrefixes(this.prefixes, [root], 0, 0);
728
+ this.guard(() => {
729
+ this.ctx = this.parser.rdfRoot(root, this.ctx);
730
+ });
731
+ }
732
+ }
733
+ return this.streaming;
734
+ }
735
+
736
+ /** Converts the children the root kept (text, and elements from entities) since the last time. */
737
+ private drain(root: Xml.Element): void {
738
+ const pending = root.children.slice(this.converted);
739
+ this.converted = root.children.length;
740
+ declarePrefixes(this.prefixes, pending, 1, 2);
741
+ this.parser.nodeElementList(pending, this.ctx);
742
+ }
743
+
744
+ /** Runs a conversion step unless one has failed, keeping its failure. */
745
+ private guard(step: () => void): void {
746
+ if (Arr.isReadonlyArrayNonEmpty(this.failures)) return;
747
+ const outcome = Result.try({ try: step, catch: (e) => e });
748
+ if (Result.isSuccess(outcome)) return;
749
+ if (!(outcome.failure instanceof ParseFailure)) throw outcome.failure;
750
+ this.failures.push(outcome.failure);
751
+ }
752
+ }
753
+
754
+ /**
755
+ * Parses an already-parsed XML document as RDF/XML. The root element is
756
+ * `rdf:RDF` or a single node element; `xml:base` on it is returned as the
757
+ * base IRI and namespace declarations on it (and its children) as prefixes.
758
+ * Formats that embed RDF/XML in a larger XML document (XMP, SVG metadata)
759
+ * pass a document whose root is the embedded `rdf:RDF` element.
760
+ *
761
+ * @since 0.1.0
762
+ * @category parsing
763
+ */
764
+ export const parseDocument = (
765
+ doc: Xml.Document,
766
+ options?: ParseOptions,
767
+ ): Effect.Effect<Serialization.ParseResult, Serialization.RdfParseError> =>
768
+ Effect.map(parseTriples(doc, options), (triples) =>
769
+ toResult(toQuadsResult(triples, doc, collectPrefixes(doc), options)),
770
+ );
771
+
772
+ /** The result of a parse: the triples in their graph, with the document's prefixes and base. */
773
+ /** The quads of a parse, in their graph, with the document's prefixes and base. */
774
+ const toQuadsResult = (
775
+ triples: ReadonlyArray<Term.Triple>,
776
+ doc: Xml.Document,
777
+ prefixes: PrefixMap.PrefixMap,
778
+ options?: ParseOptions,
779
+ ): QuadsResult => {
780
+ const graph = options?.graph ?? Term.defaultGraph;
781
+ let baseIri = options?.baseIri;
782
+ const xmlBase = doc.root.attributes.find(
783
+ (a) => a.namespace === Xml.XML_NAMESPACE && a.localName === 'base',
784
+ );
785
+ if (xmlBase !== undefined) baseIri = Iri.resolve(xmlBase.value, baseIri);
786
+ return {
787
+ quads: triples.map((t) => new Term.Quad(t.subject, t.predicate, t.object, graph)),
788
+ prefixes,
789
+ baseIri,
790
+ };
791
+ };
792
+
793
+ const toResult = (quads: QuadsResult): Serialization.ParseResult => ({
794
+ dataset: Dataset.fromIterable(quads.quads),
795
+ prefixes: quads.prefixes,
796
+ baseIri: quads.baseIri,
797
+ });
798
+
799
+ /**
800
+ * The statements of an RDF/XML document in document order (duplicates
801
+ * kept), with the namespace declarations on the root element (and its
802
+ * children) as prefixes and the document's base IRI.
803
+ *
804
+ * @since 0.1.0
805
+ * @category models
806
+ */
807
+ export interface QuadsResult extends Omit<Serialization.ParseResult, 'dataset'> {
808
+ readonly quads: ReadonlyArray<Term.Quad>;
809
+ }
810
+
811
+ /**
812
+ * Parses a complete RDF/XML document into its statements in document order,
813
+ * without building a dataset. Node elements are converted as they are read,
814
+ * so the XML tree is never held whole.
815
+ *
816
+ * @since 0.1.0
817
+ * @category parsing
818
+ * @example
819
+ * ```ts
820
+ * import * as Effect from 'effect/Effect';
821
+ * import { RdfXml } from '@thomasfosterau/effect-rdf/rdfxml';
822
+ *
823
+ * const { quads } = Effect.runSync(
824
+ * RdfXml.parseQuads(
825
+ * `<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
826
+ * xmlns:ex="http://example.org/">
827
+ * <rdf:Description rdf:about="http://example.org/a" ex:p="1"/>
828
+ * </rdf:RDF>`,
829
+ * ),
830
+ * );
831
+ * // quads.length === 1
832
+ * ```
833
+ */
834
+ export const parseQuads = (
835
+ input: string,
836
+ options?: ParseOptions,
837
+ ): Effect.Effect<QuadsResult, Serialization.RdfParseError> =>
838
+ Effect.try({
839
+ try: () => {
840
+ const version = Option.fromUndefinedOr(options?.version);
841
+ const parser = new RdfXmlParser(
842
+ options?.blankNodePrefix ?? Serialization.freshBlankNodePrefix(),
843
+ version,
844
+ );
845
+ const stream = new RootStream(parser, {
846
+ base: Option.fromUndefinedOr(options?.baseIri),
847
+ language: '',
848
+ direction: '',
849
+ version,
850
+ });
851
+ const doc = XmlParser.parseText(input, stream.take);
852
+ stream.finish(doc);
853
+ return toQuadsResult(parser.sink, doc, PrefixMap.make(stream.prefixes), options);
854
+ },
855
+ catch: (e) => {
856
+ if (e instanceof XmlParser.Failure) return toParseError(e.message, e.position);
857
+ if (e instanceof ParseFailure) return toParseError(e.message, e.position);
858
+ throw e;
859
+ },
860
+ });
861
+
862
+ /**
863
+ * Parses a complete RDF/XML document. Namespace declarations on the root
864
+ * element (and its children) are returned as prefixes.
865
+ *
866
+ * @since 0.1.0
867
+ * @category parsing
868
+ */
869
+ export const parse = (
870
+ input: string,
871
+ options?: ParseOptions,
872
+ ): Effect.Effect<Serialization.ParseResult, Serialization.RdfParseError> =>
873
+ Effect.map(parseQuads(input, options), toResult).pipe(Serialization.withParseSpan(trace, input));
874
+
875
+ /**
876
+ * The RDF/XML parser.
877
+ *
878
+ * @since 0.1.0
879
+ * @category parsing
880
+ */
881
+ export const parser: Serialization.Parser<ParseOptions> = Serialization.makeParser({
882
+ format,
883
+ parse,
884
+ });
885
+
886
+ // -----------------------------------------------------------------------------
887
+ // Serializing
888
+ // -----------------------------------------------------------------------------
889
+
890
+ /**
891
+ * Options for serialising RDF/XML.
892
+ *
893
+ * @since 0.1.0
894
+ * @category models
895
+ */
896
+ export interface SerializeOptions extends Serialization.SerializeOptions {
897
+ /** The indentation unit. Defaults to two spaces. */
898
+ readonly indent?: string | undefined;
899
+ /**
900
+ * Whether to nest blank nodes that are the object of exactly one triple
901
+ * inside the referencing property element. Defaults to `true`.
902
+ */
903
+ readonly nestBlankNodes?: boolean | undefined;
904
+ /**
905
+ * Whether to use typed node elements (`<ex:Person>`) for an `rdf:type`
906
+ * of each node. Defaults to `true`.
907
+ */
908
+ readonly typedNodes?: boolean | undefined;
909
+ /** Whether to write the `<?xml …?>` declaration. Defaults to `true`. */
910
+ readonly xmlDeclaration?: boolean | undefined;
911
+ }
912
+
913
+ class SerializeFailure {
914
+ readonly message: string;
915
+ constructor(message: string) {
916
+ this.message = message;
917
+ }
918
+ }
919
+
920
+ const LOCAL_SUFFIX_RE = new RegExp(`[${Xml.NAME_START}][${Xml.NAME_CHAR}]*$`, 'u');
921
+
922
+ /**
923
+ * Splits an IRI into a namespace and a local name that is an XML `NCName`,
924
+ * choosing the longest possible local name. Returns `None` when the IRI does
925
+ * not end with an `NCName` (such IRIs cannot be used as element or
926
+ * attribute names).
927
+ *
928
+ * @since 0.1.0
929
+ * @category serializing
930
+ */
931
+ export const splitIri = (iri: string): Option.Option<readonly [string, string]> => {
932
+ // The leftmost match is the longest NCName suffix.
933
+ const m = LOCAL_SUFFIX_RE.exec(iri);
934
+ if (m === null || m.index === 0) return Option.none();
935
+ return Option.some([iri.slice(0, m.index), m[0]] as const);
936
+ };
937
+
938
+ const escapeAttr = Xml.escapeAttribute;
939
+
940
+ interface Namespaces {
941
+ /** namespace → prefix, for configured and generated prefixes. */
942
+ readonly byNamespace: MutableHashMap.MutableHashMap<string, string>;
943
+ /** Prefixes taken (configured, generated or reserved). */
944
+ readonly used: MutableHashSet.MutableHashSet<string>;
945
+ /** Namespaces actually referenced by the output. */
946
+ readonly declared: MutableHashSet.MutableHashSet<string>;
947
+ counter: number;
948
+ }
949
+
950
+ /** Whether `prefix` may be declared for `ns` as configured in `options.prefixes`. */
951
+ const isConfigurable = (prefix: string, ns: string): boolean =>
952
+ Xml.isNCName(prefix) &&
953
+ !prefix.toLowerCase().startsWith('xml') &&
954
+ ns !== ITS &&
955
+ Xml.isValidText(ns) &&
956
+ (ns === RDF) === (prefix === 'rdf') &&
957
+ prefix !== 'its';
958
+
959
+ /** The first of `name(1)`, `name(2)`, … (counting on from `from`) that `taken` does not hold. */
960
+ const freshName = (
961
+ taken: MutableHashSet.MutableHashSet<string>,
962
+ from: number,
963
+ name: (n: number) => string,
964
+ ): readonly [name: string, n: number] => {
965
+ const candidate = name(from + 1);
966
+ return MutableHashSet.has(taken, candidate)
967
+ ? freshName(taken, from + 1, name)
968
+ : [candidate, from + 1];
969
+ };
970
+
971
+ class Writer {
972
+ readonly namespaces: Namespaces;
973
+ readonly blankLabels = MutableHashMap.empty<string, string>();
974
+ /** The QName of each IRI written so far, while no namespace has been added since. */
975
+ private readonly qnames = MutableHashMap.empty<string, string>();
976
+ needsVersion = false;
977
+ needsIts = false;
978
+
979
+ readonly options: SerializeOptions;
980
+ constructor(options: SerializeOptions, prefixes: PrefixMap.PrefixMap) {
981
+ this.options = options;
982
+ const byNamespace = MutableHashMap.empty<string, string>();
983
+ const used = MutableHashSet.empty<string>();
984
+ prefixes.prefixes.forEach((ns, prefix) => {
985
+ if (
986
+ isConfigurable(prefix, ns) &&
987
+ !MutableHashMap.has(byNamespace, ns) &&
988
+ !MutableHashSet.has(used, prefix)
989
+ ) {
990
+ MutableHashMap.set(byNamespace, ns, prefix);
991
+ MutableHashSet.add(used, prefix);
992
+ }
993
+ });
994
+ if (!MutableHashMap.has(byNamespace, RDF)) {
995
+ MutableHashMap.set(byNamespace, RDF, 'rdf');
996
+ MutableHashSet.add(used, 'rdf');
997
+ }
998
+ MutableHashSet.add(used, 'its');
999
+ this.namespaces = { byNamespace, used, declared: MutableHashSet.make(RDF), counter: 0 };
1000
+ }
1001
+
1002
+ fail(message: string): never {
1003
+ throw new SerializeFailure(message);
1004
+ }
1005
+
1006
+ qname(iri: string, what: string): string {
1007
+ const known = MutableHashMap.get(this.qnames, iri);
1008
+ if (Option.isSome(known)) return known.value;
1009
+ const name = this.newQname(iri, what);
1010
+ MutableHashMap.set(this.qnames, iri, name);
1011
+ return name;
1012
+ }
1013
+
1014
+ private newQname(iri: string, what: string): string {
1015
+ if (!Xml.isValidText(iri)) this.fail(`The ${what} <${iri}> contains invalid XML characters`);
1016
+ const { byNamespace, used, declared } = this.namespaces;
1017
+ // Prefer the longest configured namespace that leaves an NCName.
1018
+ const configured = Arr.reduce(
1019
+ Arr.fromIterable(MutableHashMap.keys(byNamespace)),
1020
+ Option.none<readonly [string, string]>(),
1021
+ (best, ns) =>
1022
+ iri.startsWith(ns) &&
1023
+ (Option.isNone(best) || ns.length > best.value[0].length) &&
1024
+ Xml.isNCName(iri.slice(ns.length))
1025
+ ? Option.some([ns, iri.slice(ns.length)] as const)
1026
+ : best,
1027
+ );
1028
+ const [ns, local] = Option.getOrElse(
1029
+ Option.orElse(configured, () => splitIri(iri)),
1030
+ () => this.fail(`The ${what} <${iri}> cannot be written as an XML QName`),
1031
+ );
1032
+ MutableHashSet.add(declared, ns);
1033
+ const prefix = Option.getOrElse(MutableHashMap.get(byNamespace, ns), () => {
1034
+ const [generated, n] = freshName(used, this.namespaces.counter, (i) => `ns${i}`);
1035
+ this.namespaces.counter = n;
1036
+ MutableHashSet.add(used, generated);
1037
+ MutableHashMap.set(byNamespace, ns, generated);
1038
+ // A new namespace may be a better choice for the IRIs already named
1039
+ MutableHashMap.clear(this.qnames);
1040
+ return generated;
1041
+ });
1042
+ return `${prefix}:${local}`;
1043
+ }
1044
+
1045
+ iriRef(iri: string): string {
1046
+ if (!Xml.isValidText(iri)) this.fail(`The IRI <${iri}> contains characters not allowed in XML`);
1047
+ const base = this.options.baseIri;
1048
+ if (base !== undefined) {
1049
+ const rel = Iri.relativize(iri, base);
1050
+ if (Option.isSome(rel)) return escapeAttr(rel.value);
1051
+ }
1052
+ return escapeAttr(iri);
1053
+ }
1054
+
1055
+ blankLabel(node: Term.BlankNode): string {
1056
+ const known = MutableHashMap.get(this.blankLabels, node.value);
1057
+ if (Option.isSome(known)) return known.value;
1058
+ const label =
1059
+ Xml.isNCName(node.value) && !MutableHashSet.has(this.usedLabels, node.value)
1060
+ ? node.value
1061
+ : this.freshLabel();
1062
+ MutableHashSet.add(this.usedLabels, label);
1063
+ MutableHashMap.set(this.blankLabels, node.value, label);
1064
+ return label;
1065
+ }
1066
+
1067
+ private freshLabel(): string {
1068
+ // `b0`, `b1`, …: `freshName` counts on from the one before the next
1069
+ const [label, n] = freshName(this.usedLabels, this.labelCounter - 1, (i) => `b${i}`);
1070
+ this.labelCounter = n + 1;
1071
+ return label;
1072
+ }
1073
+
1074
+ readonly usedLabels = MutableHashSet.empty<string>();
1075
+ labelCounter = 0;
1076
+ }
1077
+
1078
+ /** A subject with the triples it is the subject of. */
1079
+ interface Description {
1080
+ readonly subject: Term.Subject;
1081
+ readonly triples: Array<Term.Triple>;
1082
+ }
1083
+
1084
+ interface Graph {
1085
+ readonly bySubject: MutableHashMap.MutableHashMap<string, Description>;
1086
+ readonly references: MutableHashMap.MutableHashMap<string, number>;
1087
+ }
1088
+
1089
+ const text = (value: string, writer: Writer): string => {
1090
+ if (!Xml.isValidText(value)) writer.fail('A literal contains characters not allowed in XML 1.0');
1091
+ return Xml.escapeText(value);
1092
+ };
1093
+
1094
+ const sortByPredicateObject = (ts: ReadonlyArray<Term.Triple>) =>
1095
+ Arr.sort(
1096
+ ts,
1097
+ Order.combine(
1098
+ Order.mapInput(Term.Order, (t: Term.Triple) => t.predicate),
1099
+ Order.mapInput(Term.Order, (t: Term.Triple) => t.object),
1100
+ ),
1101
+ );
1102
+
1103
+ /** Whether `t` gives its subject an `rdf:type` that can be the name of a typed node element. */
1104
+ const isTypeTriple = (t: Term.Triple): t is Term.Triple & { readonly object: Term.NamedNode } =>
1105
+ t.predicate.value === RDF_TYPE &&
1106
+ Term.isNamedNode(t.object) &&
1107
+ !isForbiddenNodeElement(t.object.value) &&
1108
+ Option.isSome(splitIri(t.object.value));
1109
+
1110
+ const serializeGraph = (triples: ReadonlyArray<Term.Triple>, options: SerializeOptions): string => {
1111
+ const writer = new Writer(options, options.prefixes ?? PrefixMap.empty);
1112
+ const indentUnit = options.indent ?? ' ';
1113
+ const nest = options.nestBlankNodes ?? true;
1114
+ const typed = options.typedNodes ?? true;
1115
+
1116
+ const graph: Graph = { bySubject: MutableHashMap.empty(), references: MutableHashMap.empty() };
1117
+ const referenceCount = (label: string): number => {
1118
+ const count = MutableHashMap.get(graph.references, label);
1119
+ return Option.isSome(count) ? count.value : 0;
1120
+ };
1121
+ const inTripleTerm = MutableHashSet.empty<string>();
1122
+ const markTripleTerm = (t: Term.Term): void => {
1123
+ if (Term.isBlankNode(t)) MutableHashSet.add(inTripleTerm, t.value);
1124
+ else if (Term.isTriple(t)) {
1125
+ markTripleTerm(t.subject);
1126
+ markTripleTerm(t.object);
1127
+ }
1128
+ };
1129
+ triples.forEach((t) => {
1130
+ if (Term.isTriple(t.subject)) {
1131
+ writer.fail('RDF/XML cannot represent triple terms in the subject position');
1132
+ }
1133
+ const subject = t.subject;
1134
+ const key = subject.key;
1135
+ const entry = MutableHashMap.get(graph.bySubject, key);
1136
+ if (Option.isSome(entry)) entry.value.triples.push(t);
1137
+ else MutableHashMap.set(graph.bySubject, key, { subject, triples: [t] });
1138
+ const o = t.object;
1139
+ if (Term.isBlankNode(o)) {
1140
+ MutableHashMap.set(graph.references, o.value, referenceCount(o.value) + 1);
1141
+ } else if (Term.isTriple(o)) {
1142
+ markTripleTerm(o);
1143
+ }
1144
+ });
1145
+
1146
+ // Blank nodes that can be written inline, inside their only reference.
1147
+ const nested = MutableHashSet.empty<string>();
1148
+ if (nest) {
1149
+ MutableHashMap.forEach(graph.references, (count, label) => {
1150
+ if (count === 1 && !MutableHashSet.has(inTripleTerm, label)) {
1151
+ MutableHashSet.add(nested, label);
1152
+ }
1153
+ });
1154
+ // Break cycles: every nested node must be reachable from a top-level node.
1155
+ const reachable = MutableHashSet.empty<string>();
1156
+ const visit = (subjectKey: string): void => {
1157
+ const entry = MutableHashMap.get(graph.bySubject, subjectKey);
1158
+ if (Option.isNone(entry)) return;
1159
+ entry.value.triples.forEach((t) => {
1160
+ const o = t.object;
1161
+ if (
1162
+ Term.isBlankNode(o) &&
1163
+ MutableHashSet.has(nested, o.value) &&
1164
+ !MutableHashSet.has(reachable, o.value)
1165
+ ) {
1166
+ MutableHashSet.add(reachable, o.value);
1167
+ visit(o.key);
1168
+ }
1169
+ });
1170
+ };
1171
+ MutableHashMap.forEach(graph.bySubject, (entry, key) => {
1172
+ const s = entry.subject;
1173
+ if (!Term.isBlankNode(s) || !MutableHashSet.has(nested, s.value)) visit(key);
1174
+ });
1175
+ MutableHashMap.forEach(graph.bySubject, (entry) => {
1176
+ const s = entry.subject;
1177
+ if (
1178
+ Term.isBlankNode(s) &&
1179
+ MutableHashSet.has(nested, s.value) &&
1180
+ !MutableHashSet.has(reachable, s.value)
1181
+ ) {
1182
+ MutableHashSet.remove(nested, s.value);
1183
+ visit(s.key);
1184
+ }
1185
+ });
1186
+ }
1187
+
1188
+ const body: Array<string> = [];
1189
+
1190
+ /** Writes a node element for `subject` at `depth`. */
1191
+ const node = (subject: Term.Subject, depth: number, inline: boolean, lines: Array<string>) => {
1192
+ const pad = indentUnit.repeat(depth);
1193
+ const sorted = Option.match(MutableHashMap.get(graph.bySubject, subject.key), {
1194
+ onNone: (): ReadonlyArray<Term.Triple> => [],
1195
+ onSome: (entry) => sortByPredicateObject(entry.triples),
1196
+ });
1197
+ const typeTriple = typed
1198
+ ? Arr.findFirst(sorted, (t) =>
1199
+ isTypeTriple(t) && Xml.isValidText(t.object.value)
1200
+ ? Option.some([t, t.object.value] as const)
1201
+ : Option.none(),
1202
+ )
1203
+ : Option.none();
1204
+ const element = Option.match(typeTriple, {
1205
+ onNone: () => 'rdf:Description',
1206
+ onSome: ([, type]) => writer.qname(type, 'type'),
1207
+ });
1208
+ const ts = Option.match(typeTriple, {
1209
+ onNone: () => sorted,
1210
+ onSome: ([typeT]) => sorted.filter((t) => t !== typeT),
1211
+ });
1212
+ const attrs = Term.isNamedNode(subject)
1213
+ ? ` rdf:about="${writer.iriRef(subject.value)}"`
1214
+ : Term.isBlankNode(subject) &&
1215
+ !inline &&
1216
+ (referenceCount(subject.value) > 0 || MutableHashSet.has(inTripleTerm, subject.value))
1217
+ ? ` rdf:nodeID="${writer.blankLabel(subject)}"`
1218
+ : '';
1219
+ if (Arr.isReadonlyArrayEmpty(ts)) {
1220
+ lines.push(`${pad}<${element}${attrs}/>`);
1221
+ return;
1222
+ }
1223
+ lines.push(`${pad}<${element}${attrs}>`);
1224
+ ts.forEach((t) => property(t, depth + 1, lines));
1225
+ lines.push(`${pad}</${element}>`);
1226
+ };
1227
+ const property = (t: Term.Triple, depth: number, lines: Array<string>) => {
1228
+ const pad = indentUnit.repeat(depth);
1229
+ const p = t.predicate.value;
1230
+ if (isForbiddenPropertyElement(p) || p === RDF_LI) {
1231
+ writer.fail(`The predicate <${p}> cannot be used as an RDF/XML property element`);
1232
+ }
1233
+ const name = writer.qname(p, 'predicate');
1234
+ propertyObject(t.object, pad, name, depth, lines);
1235
+ };
1236
+
1237
+ // Built once per serialisation, not per triple.
1238
+ const propertyObject = Match.fn(
1239
+ (o: Term.Object, _pad: string, _name: string, _depth: number, _lines: Array<string>) => o,
1240
+ ).pipe(
1241
+ Match.withReturnType<void>(),
1242
+ Match.tag('NamedNode', (o, _o, pad, name, _depth, lines) => {
1243
+ lines.push(`${pad}<${name} rdf:resource="${writer.iriRef(o.value)}"/>`);
1244
+ }),
1245
+ Match.tag('BlankNode', (o, _o, pad, name, depth, lines) => {
1246
+ if (MutableHashSet.has(nested, o.value) && !MutableHashSet.has(inTripleTerm, o.value)) {
1247
+ const described = Option.match(MutableHashMap.get(graph.bySubject, o.key), {
1248
+ onNone: (): ReadonlyArray<Term.Triple> => [],
1249
+ onSome: (entry) => entry.triples,
1250
+ });
1251
+ if (Arr.isReadonlyArrayEmpty(described)) {
1252
+ lines.push(`${pad}<${name} rdf:parseType="Resource"/>`);
1253
+ return;
1254
+ }
1255
+ if (!(typed && described.some(isTypeTriple))) {
1256
+ lines.push(`${pad}<${name} rdf:parseType="Resource">`);
1257
+ sortByPredicateObject(described).forEach((x) => property(x, depth + 1, lines));
1258
+ lines.push(`${pad}</${name}>`);
1259
+ return;
1260
+ }
1261
+ lines.push(`${pad}<${name}>`);
1262
+ node(o, depth + 1, true, lines);
1263
+ lines.push(`${pad}</${name}>`);
1264
+ return;
1265
+ }
1266
+ lines.push(`${pad}<${name} rdf:nodeID="${writer.blankLabel(o)}"/>`);
1267
+ }),
1268
+ Match.tag('Literal', (o, _o, pad, name, _depth, lines) => {
1269
+ let attrs = '';
1270
+ if (o.language !== '') {
1271
+ attrs += ` xml:lang="${escapeAttr(o.language)}"`;
1272
+ if (o.direction !== undefined) {
1273
+ writer.needsVersion = true;
1274
+ writer.needsIts = true;
1275
+ attrs += ` its:dir="${o.direction}"`;
1276
+ }
1277
+ } else if (o.datatype.value !== XSD_STRING) {
1278
+ attrs += ` rdf:datatype="${writer.iriRef(o.datatype.value)}"`;
1279
+ }
1280
+ if (o.value === '') lines.push(`${pad}<${name}${attrs}/>`);
1281
+ else lines.push(`${pad}<${name}${attrs}>${text(o.value, writer)}</${name}>`);
1282
+ }),
1283
+ Match.tag('Triple', (o, _o, pad, name, depth, lines) => {
1284
+ writer.needsVersion = true;
1285
+ lines.push(`${pad}<${name} rdf:parseType="Triple">`);
1286
+ tripleTerm(o, depth + 1, lines);
1287
+ lines.push(`${pad}</${name}>`);
1288
+ }),
1289
+ Match.exhaustive,
1290
+ );
1291
+
1292
+ const tripleTerm = (t: Term.Triple, depth: number, lines: Array<string>) => {
1293
+ const pad = indentUnit.repeat(depth);
1294
+ const s = t.subject;
1295
+ const attrs = Term.isNamedNode(s)
1296
+ ? ` rdf:about="${writer.iriRef(s.value)}"`
1297
+ : Term.isBlankNode(s)
1298
+ ? ` rdf:nodeID="${writer.blankLabel(s)}"`
1299
+ : writer.fail('RDF/XML cannot represent triple terms in the subject position');
1300
+ lines.push(`${pad}<rdf:Description${attrs}>`);
1301
+ const o = t.object;
1302
+ if (Term.isBlankNode(o)) {
1303
+ const name = writer.qname(t.predicate.value, 'predicate');
1304
+ if (isForbiddenPropertyElement(t.predicate.value) || t.predicate.value === RDF_LI) {
1305
+ writer.fail(
1306
+ `The predicate <${t.predicate.value}> cannot be used as an RDF/XML property element`,
1307
+ );
1308
+ }
1309
+ lines.push(`${pad}${indentUnit}<${name} rdf:nodeID="${writer.blankLabel(o)}"/>`);
1310
+ } else {
1311
+ property(t, depth + 1, lines);
1312
+ }
1313
+ lines.push(`${pad}</rdf:Description>`);
1314
+ };
1315
+
1316
+ const subjects = Arr.sort(
1317
+ Arr.map(Arr.fromIterable(MutableHashMap.values(graph.bySubject)), (e) => e.subject),
1318
+ // Not `Term.Order`, which puts blank nodes first: IRI subjects come first here, so named
1319
+ // descriptions lead the document and unnested blank nodes follow.
1320
+ Order.make<Term.Term>((a, b) =>
1321
+ a._tag === b._tag ? Term.compare(a, b) : Term.isNamedNode(a) ? -1 : 1,
1322
+ ),
1323
+ );
1324
+ subjects.forEach((s) => {
1325
+ if (!Term.isBlankNode(s) || !MutableHashSet.has(nested, s.value)) node(s, 1, false, body);
1326
+ });
1327
+
1328
+ const nsEntries = Arr.sort(
1329
+ Arr.filter(Arr.fromIterable(writer.namespaces.byNamespace), ([ns]) =>
1330
+ MutableHashSet.has(writer.namespaces.declared, ns),
1331
+ ),
1332
+ Order.make<readonly [string, string]>((a, b) =>
1333
+ a[1] === 'rdf' ? -1 : b[1] === 'rdf' ? 1 : a[1] < b[1] ? -1 : 1,
1334
+ ),
1335
+ );
1336
+ const decls: Array<string> = [
1337
+ ...nsEntries.map(([ns, prefix]) => `xmlns:${prefix}="${escapeAttr(ns)}"`),
1338
+ ...(writer.needsIts ? [`xmlns:its="${ITS}"`, 'its:version="2.0"'] : []),
1339
+ ...(options.baseIri === undefined ? [] : [`xml:base="${escapeAttr(options.baseIri)}"`]),
1340
+ ...(writer.needsVersion ? ['rdf:version="1.2"'] : []),
1341
+ ];
1342
+ const sep = `\n${' '.repeat('<rdf:RDF '.length)}`;
1343
+ const declaration =
1344
+ (options.xmlDeclaration ?? true) ? ['<?xml version="1.0" encoding="utf-8"?>'] : [];
1345
+ // Not `push(...body)`, which passes every line as an argument and overflows the stack
1346
+ const out = Arr.isReadonlyArrayEmpty(body)
1347
+ ? [...declaration, `<rdf:RDF ${decls.join(sep)}/>`]
1348
+ : [...declaration, `<rdf:RDF ${decls.join(sep)}>`, ...body, '</rdf:RDF>'];
1349
+ return `${out.join('\n')}\n`;
1350
+ };
1351
+
1352
+ /**
1353
+ * Serialises quads as an RDF/XML document. Fails with `RdfSerializeError`
1354
+ * for quads in named graphs, triple terms in the subject position, and
1355
+ * predicates that cannot be written as XML QNames.
1356
+ *
1357
+ * @since 0.1.0
1358
+ * @category serializing
1359
+ */
1360
+ export const serialize = (
1361
+ quads: Iterable<Term.Quad>,
1362
+ options?: SerializeOptions,
1363
+ ): Effect.Effect<string, Serialization.RdfSerializeError> =>
1364
+ Effect.suspend(() => {
1365
+ const all = Arr.fromIterable(quads);
1366
+ const named = Arr.findFirst(all, (q) => !Term.isDefaultGraph(q.graph));
1367
+ if (Option.isSome(named)) {
1368
+ return Effect.fail(
1369
+ new Serialization.RdfSerializeError({
1370
+ format: FORMAT_NAME,
1371
+ message: `RDF/XML cannot represent named graphs (found graph ${named.value.graph.key})`,
1372
+ }),
1373
+ );
1374
+ }
1375
+ const triples = all.map((q) => q.triple);
1376
+ return Effect.try({
1377
+ try: () => serializeGraph(triples, options ?? {}),
1378
+ catch: (e) => {
1379
+ if (e instanceof SerializeFailure) {
1380
+ return new Serialization.RdfSerializeError({ format: FORMAT_NAME, message: e.message });
1381
+ }
1382
+ throw e;
1383
+ },
1384
+ });
1385
+ }).pipe(Serialization.withSerializeSpan(trace));
1386
+
1387
+ /**
1388
+ * The RDF/XML serializer.
1389
+ *
1390
+ * @since 0.1.0
1391
+ * @category serializing
1392
+ */
1393
+ export const serializer: Serialization.Serializer<SerializeOptions> = Serialization.makeSerializer({
1394
+ format,
1395
+ serialize,
1396
+ });
1397
+
1398
+ /**
1399
+ * The RDF/XML codec, including a `Schema` transforming RDF/XML documents to
1400
+ * datasets and back.
1401
+ *
1402
+ * @since 0.1.0
1403
+ * @category codecs
1404
+ */
1405
+ export const codec: Serialization.Codec<ParseOptions, SerializeOptions> = Serialization.makeCodec(
1406
+ parser,
1407
+ serializer,
1408
+ );