@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,1317 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
2
+ import { O as defaultGraph, T as blankNode$1, Y as literal, Z as namedNode, c as NamedNode, d as Quad, it as variable$2, q as isVariable, rt as triple } from "./Term-CFLG1qu4.mjs";
3
+ import { l as resolve$1 } from "./Iri-Cr92gsQV.mjs";
4
+ import { a as digit, g as pnCharsU, i as blankNodeLabel$1, l as hex, n as alpha, r as alphanumeric, u as iriExcluded } from "./Grammar-mQ8CgE1M.mjs";
5
+ import { f as prefixedName, o as exponent, p as skip } from "./Grammar-CPlSxGH6.mjs";
6
+ import { a as setOf, n as empty } from "./stringMap-D5YIpYtR.mjs";
7
+ import { A as pathPattern, B as update, D as oneOrMore, E as negated$1, F as sequence, H as zeroOrMore, I as service, L as subSelect$1, N as quadPattern$1, O as operation, R as triplePattern, T as minus, U as zeroOrOne, V as values, _ as group, a as bgp, b as isBuiltInName, f as exists, g as graph, h as functionCall, k as optional, l as containsAggregate, m as filter, n as aggregate$1, o as bind, p as expressionVariables, r as alternative, s as builtInArity, v as inScopeVariables, w as link, x as isPath, y as inverse, z as union } from "./Ast-CPRZmBvk.mjs";
8
+ import { t as loop } from "./loop-D5-gNx9K.mjs";
9
+ import * as Arr from "effect/Array";
10
+ import * as MutableHashSet from "effect/MutableHashSet";
11
+ import * as Option from "effect/Option";
12
+ import * as Predicate from "effect/Predicate";
13
+ import * as Schema from "effect/Schema";
14
+ import * as Effect from "effect/Effect";
15
+ import * as Match from "effect/Match";
16
+ import * as Record from "effect/Record";
17
+ import * as Result from "effect/Result";
18
+ import * as Compiler from "@thomasfosterau/effect-parse/Compiler";
19
+ import * as Parser from "@thomasfosterau/effect-parse/Parser";
20
+ import * as Token from "@thomasfosterau/effect-parse/Token";
21
+ import "@thomasfosterau/effect-parse/ParseError";
22
+ // src/sparql/internal/lexer.ts
23
+ /**
24
+ * The SPARQL lexer, written with `@thomasfosterau/effect-parse`: a compiled
25
+ * grammar turning a query or update into tokens, built on the Turtle
26
+ * grammar's terminals (`/turtle`'s `Grammar`), which SPARQL shares,
27
+ * plus SPARQL's own (variables, keywords, punctuation). A pass then resolves
28
+ * IRIs in document order, as `BASE` and `PREFIX` declarations are met, so
29
+ * that the parser works on resolved tokens and needs no per-query state for
30
+ * names.
31
+ *
32
+ * Where no token can be read, the tokens end with an `ERROR` token, which the
33
+ * parser reports if it gets that far (as a lazy lexer would).
34
+ *
35
+ * @internal
36
+ */
37
+ const make = (t, start, end) => ({
38
+ type: t.type,
39
+ value: t.value,
40
+ extra: t.extra ?? "",
41
+ kind: t.type === "PUNCT" ? t.value : t.type === "WORD" ? t.value === "a" ? "a" : t.value.toUpperCase() : t.type,
42
+ start: t.at ?? start,
43
+ end,
44
+ error: Option.none()
45
+ });
46
+ /** A token that ends the stream, with the reason. */
47
+ const errorToken = (value, at) => at === void 0 ? {
48
+ type: "ERROR",
49
+ value
50
+ } : {
51
+ type: "ERROR",
52
+ value,
53
+ at
54
+ };
55
+ const hex4 = Token.takeWhile(hex, 4);
56
+ const hex8 = Token.takeWhile(hex, 8);
57
+ /** Decodes a `UCHAR`, rejecting surrogates and code points beyond U+10FFFF. */
58
+ const decodeUchar = (hex) => {
59
+ const code = parseInt(hex, 16);
60
+ return code >= 55296 && code <= 57343 || code > 1114111 ? Option.none() : Option.some(String.fromCodePoint(code));
61
+ };
62
+ const forbiddenInIri = /[<>"{}|^`\\\u0000- ]/;
63
+ /** `IRIREF`, decoding its `UCHAR`s (an escape may not produce a disallowed character). */
64
+ const iri$1 = Parser.delimited(Token.literal("<"), Parser.taken(Parser.repeat(Parser.alt(Token.takeTill([iriExcluded, "\\"], { min: 1 }), Parser.seq(Token.literal("\\u"), hex4), Parser.seq(Token.literal("\\U"), hex8)))), Token.literal(">")).pipe(Parser.map((raw) => {
65
+ if (raw.indexOf("\\") === -1) return {
66
+ type: "IRI",
67
+ value: raw
68
+ };
69
+ let bad = Option.none();
70
+ const value = raw.replace(/\\u([0-9A-Fa-f]{4})|\\U([0-9A-Fa-f]{8})/g, (_, a, b) => {
71
+ const hex = a ?? b;
72
+ const c = decodeUchar(hex);
73
+ if (Option.isNone(c)) {
74
+ if (Option.isNone(bad)) bad = Option.some(`Invalid code point escape \\u${hex}`);
75
+ return "";
76
+ }
77
+ return c.value;
78
+ });
79
+ if (Option.isSome(bad)) return errorToken(bad.value);
80
+ return forbiddenInIri.test(value) ? errorToken("Invalid character in IRI") : {
81
+ type: "IRI",
82
+ value
83
+ };
84
+ }));
85
+ const varChars = [
86
+ pnCharsU,
87
+ digit,
88
+ "·",
89
+ Token.range("̀", "ͯ"),
90
+ Token.range("‿", "⁀")
91
+ ];
92
+ /** `VAR1` / `VAR2` */
93
+ const variable$1 = Parser.preceded(Token.oneOf("?$"), Parser.taken(Parser.seq(Token.oneOf([pnCharsU, digit]), Token.takeWhile(varChars)))).pipe(Parser.map((value) => ({
94
+ type: "VAR",
95
+ value
96
+ })));
97
+ const ECHAR = {
98
+ t: " ",
99
+ b: "\b",
100
+ n: "\n",
101
+ r: "\r",
102
+ f: "\f",
103
+ "\"": "\"",
104
+ "'": "'",
105
+ "\\": "\\"
106
+ };
107
+ const HEX = /^[0-9A-Fa-f]+$/;
108
+ /**
109
+ * The runs of characters a string takes as they are: all but its quote and
110
+ * `\` (and, in a short string, line breaks).
111
+ */
112
+ const SHORT_RUN_DOUBLE = /[^"\\\n\r]*/y;
113
+ const SHORT_RUN_SINGLE = /[^'\\\n\r]*/y;
114
+ const LONG_RUN_DOUBLE = /[^"\\]*/y;
115
+ const LONG_RUN_SINGLE = /[^'\\]*/y;
116
+ /** Up to two quotes before a long string's closing delimiter. */
117
+ const EXTRA_DOUBLE = /"{0,2}/y;
118
+ const EXTRA_SINGLE = /'{0,2}/y;
119
+ /** The end of the run `re` matches at `pos`. */
120
+ const runEnd = (re, input, pos) => {
121
+ re.lastIndex = pos;
122
+ re.test(input);
123
+ return re.lastIndex;
124
+ };
125
+ /**
126
+ * A string literal. Long strings may end with up to two quotes before the
127
+ * closing delimiter (`"""a""""` is `a"`). Written as plain code: it is a
128
+ * leaf, and its error reporting follows the reference lexer.
129
+ */
130
+ const string$1 = Parser.make((state) => {
131
+ const input = state.input;
132
+ const start = state.pos;
133
+ const quote = input.charAt(start);
134
+ const long = input.startsWith(quote.repeat(3), start);
135
+ const double = quote === "\"";
136
+ const run = long ? double ? LONG_RUN_DOUBLE : LONG_RUN_SINGLE : double ? SHORT_RUN_DOUBLE : SHORT_RUN_SINGLE;
137
+ let i = start + (long ? 3 : 1);
138
+ let out = "";
139
+ let token = errorToken("Unterminated string literal");
140
+ const error = (message, at) => {
141
+ state.pos = input.length;
142
+ token = errorToken(message, at);
143
+ return false;
144
+ };
145
+ /** Reads the next run and the character after it; `false` once the literal ends. */
146
+ const step = () => {
147
+ const runTo = runEnd(run, input, i);
148
+ out += input.slice(i, runTo);
149
+ i = runTo;
150
+ if (i >= input.length) return error("Unterminated string literal");
151
+ const c = input.charAt(i);
152
+ if (c === "\\") {
153
+ const e = input.charAt(i + 1);
154
+ if (e === "u" || e === "U") {
155
+ const len = e === "u" ? 4 : 8;
156
+ const hex = input.slice(i + 2, i + 2 + len);
157
+ if (hex.length !== len || !HEX.test(hex)) return error("Invalid \\u escape", i);
158
+ const decoded = decodeUchar(hex);
159
+ if (Option.isNone(decoded)) return error(`Invalid code point escape \\u${hex}`, i);
160
+ out += decoded.value;
161
+ i += 2 + len;
162
+ return true;
163
+ }
164
+ const decoded = e === "" ? void 0 : ECHAR[e];
165
+ if (decoded === void 0) return error("Invalid escape sequence in string", i);
166
+ out += decoded;
167
+ i += 2;
168
+ return true;
169
+ }
170
+ if (long) {
171
+ if (input.startsWith(quote.repeat(3), i)) {
172
+ const j = runEnd(double ? EXTRA_DOUBLE : EXTRA_SINGLE, input, i + 3) - 3;
173
+ out += input.slice(i, j);
174
+ state.pos = j + 3;
175
+ token = {
176
+ type: "STRING",
177
+ value: out,
178
+ extra: "long"
179
+ };
180
+ return false;
181
+ }
182
+ out += c;
183
+ i++;
184
+ return true;
185
+ }
186
+ if (c === quote) {
187
+ state.pos = i + 1;
188
+ token = {
189
+ type: "STRING",
190
+ value: out
191
+ };
192
+ return false;
193
+ }
194
+ return error("Newline in string literal", i);
195
+ };
196
+ loop(step);
197
+ return token;
198
+ });
199
+ const digits0 = Token.takeWhile(digit);
200
+ const digits1 = Token.takeWhile(digit, { min: 1 });
201
+ /** An unsigned number (the sign is a separate token in SPARQL). */
202
+ const number = Parser.alt(Parser.taken(Parser.alt(Parser.seq(digits1, Parser.opt(Parser.seq(Token.literal("."), digits0)), exponent), Parser.seq(Token.literal("."), digits1, exponent))).pipe(Parser.map((value) => ({
203
+ type: "DOUBLE",
204
+ value
205
+ }))), Parser.taken(Parser.seq(digits0, Token.literal("."), digits1)).pipe(Parser.map((value) => ({
206
+ type: "DECIMAL",
207
+ value
208
+ }))), digits1.pipe(Parser.map((value) => ({
209
+ type: "INTEGER",
210
+ value
211
+ }))));
212
+ /** `LANG_DIR`: a language tag with an optional `--direction` (checked by the parser). */
213
+ const langTag = Parser.alt(Parser.preceded(Token.literal("@"), Parser.taken(Parser.seq(Token.takeWhile(alpha, { min: 1 }), Parser.repeat(Parser.preceded(Token.literal("-"), Token.takeWhile(alphanumeric, { min: 1 }))), Parser.opt(Parser.preceded(Token.literal("--"), Token.takeWhile(alpha, { min: 1 })))))).pipe(Parser.map((value) => ({
214
+ type: "LANGTAG",
215
+ value
216
+ }))), Parser.preceded(Token.literal("@"), Parser.succeed(errorToken("Invalid language tag"))));
217
+ const blankNode = Parser.alt(blankNodeLabel$1.pipe(Parser.map((value) => ({
218
+ type: "BNODE",
219
+ value
220
+ }))), Parser.preceded(Token.literal("_:"), Parser.succeed(errorToken("Invalid blank node label"))));
221
+ const pname = prefixedName.pipe(Parser.map(({ prefix, local }) => ({
222
+ type: "PNAME",
223
+ value: local,
224
+ extra: prefix
225
+ })));
226
+ const word = Parser.taken(Parser.seq(Token.oneOf(alpha), Token.takeWhile([alphanumeric, "_"]))).pipe(Parser.map((value) => ({
227
+ type: "WORD",
228
+ value
229
+ })));
230
+ const PUNCTUATION = [
231
+ "<<(",
232
+ ")>>",
233
+ "{|",
234
+ "|}",
235
+ "<<",
236
+ ">>",
237
+ "^^",
238
+ "&&",
239
+ "||",
240
+ "!=",
241
+ "<=",
242
+ ">=",
243
+ ..."{}()[].,;=<>!+-*/^|?~".split("")
244
+ ];
245
+ const punctuation = Parser.alt(...PUNCTUATION.map((p) => Token.literal(p))).pipe(Parser.map((value) => ({
246
+ type: "PUNCT",
247
+ value
248
+ })));
249
+ const unexpected$1 = Token.any.pipe(Parser.map((c) => errorToken(`Unexpected character '${c}'`)));
250
+ /** One token, in the order of preference of the reference lexer. */
251
+ const token = Parser.alt(Parser.preceded(Parser.peek(Token.literal("<")), Parser.backtrack(iri$1)), Parser.preceded(Parser.peek(Token.oneOf("?$")), variable$1), Parser.preceded(Token.literal("$"), Parser.succeed(errorToken("Invalid variable"))), Parser.preceded(Parser.peek(Token.oneOf("\"'")), string$1), Parser.preceded(Parser.peek(Parser.alt(Token.oneOf(digit), Parser.seq(Token.literal("."), Token.oneOf(digit)))), number), Parser.preceded(Parser.peek(Token.literal("@")), langTag), Parser.preceded(Parser.peek(Token.literal("_:")), blankNode), pname, word, punctuation, unexpected$1);
252
+ const lexer = Compiler.jit(Parser.seq(Parser.repeat(Parser.preceded(Parser.seq(skip, Parser.not(Parser.eof)), Parser.withSpan(token).pipe(Parser.map(([t, { start, end }]) => make(t, start, end))))), Parser.preceded(skip, Parser.location)));
253
+ /** Splits a query or update into tokens (ending at the first `ERROR` token, if any). */
254
+ const tokenize = (input) => {
255
+ const tokens = Result.match(Parser.parsePeek(lexer, input), {
256
+ onSuccess: ([, [lexed]]) => lexed,
257
+ onFailure: () => [make(errorToken("No token could be read"), 0, 0)]
258
+ });
259
+ const error = tokens.findIndex((t) => t.type === "ERROR");
260
+ if (error !== -1) tokens.length = error + 1;
261
+ return tokens;
262
+ };
263
+ /**
264
+ * Resolves the IRIs of `tokens` in place, in document order: IRI references
265
+ * against the base and prefixed names against the prefixes, as `BASE` and
266
+ * `PREFIX` declarations set them. The name a `PREFIX` declares is left
267
+ * alone; a prefixed name with an undefined prefix gets an `error`.
268
+ */
269
+ const resolve = (tokens, baseIri, initialPrefixes) => {
270
+ const state = {
271
+ base: baseIri,
272
+ prefixes: { ...initialPrefixes }
273
+ };
274
+ let i = 0;
275
+ loop(() => {
276
+ const t = tokens[i];
277
+ if (t === void 0) return false;
278
+ i += resolveToken(t, tokens, i, state) + 1;
279
+ return true;
280
+ });
281
+ return {
282
+ base: state.base,
283
+ prefixes: state.prefixes
284
+ };
285
+ };
286
+ const resolveIri = (state, ref) => Option.match(state.base, {
287
+ onNone: () => ref,
288
+ onSome: (base) => resolve$1(ref, base)
289
+ });
290
+ /** Resolves a `BASE` or `PREFIX` directive's IRI; how many tokens it consumed. */
291
+ const resolveDirective = (t, tokens, i, state) => {
292
+ const next = tokens[i + 1];
293
+ if (t.kind === "BASE" && next?.type === "IRI") {
294
+ next.value = resolveIri(state, next.value);
295
+ state.base = Option.some(next.value);
296
+ return 1;
297
+ }
298
+ if (t.kind === "PREFIX" && next?.type === "PNAME" && next.value === "") {
299
+ const value = tokens[i + 2];
300
+ if (value?.type === "IRI") {
301
+ value.value = resolveIri(state, value.value);
302
+ state.prefixes[next.extra] = value.value;
303
+ return 2;
304
+ }
305
+ }
306
+ return 0;
307
+ };
308
+ /**
309
+ * Resolves one token in place and returns how many of the following tokens
310
+ * it consumed (a `BASE` or `PREFIX` directive's IRI and name). A plain
311
+ * branch per type: it runs once per token.
312
+ */
313
+ const resolveToken = (t, tokens, i, state) => {
314
+ if (t.type === "IRI") {
315
+ t.value = resolveIri(state, t.value);
316
+ return 0;
317
+ }
318
+ if (t.type === "PNAME") {
319
+ const ns = state.prefixes[t.extra];
320
+ if (ns === void 0) t.error = Option.some(`Undefined prefix '${t.extra}:'`);
321
+ else t.value = ns + t.value;
322
+ return 0;
323
+ }
324
+ return t.type === "WORD" ? resolveDirective(t, tokens, i, state) : 0;
325
+ };
326
+ // src/sparql/internal/parser.ts
327
+ /**
328
+ * The SPARQL 1.1 / 1.2 query and update grammar, written with
329
+ * `@thomasfosterau/effect-parse` as a compiled LL(1) grammar over the tokens
330
+ * of `lexer.ts` (whose names are already resolved). It builds the AST
331
+ * directly, expanding every abbreviation and enforcing the static rules of
332
+ * the specification.
333
+ *
334
+ * Three things depend on the order in which the input is read: the labels of
335
+ * generated blank nodes, the scopes of blank node labels, and where
336
+ * aggregates are allowed. They live in a per-parse context, which small
337
+ * hooks (`Parser.make`) update at the points where the reference parser does,
338
+ * and which is reset at the start of every run of the grammar.
339
+ *
340
+ * @internal
341
+ */
342
+ const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
343
+ const XSD = "http://www.w3.org/2001/XMLSchema#";
344
+ const rdfType = namedNode(`${RDF}type`);
345
+ const rdfFirst = namedNode(`${RDF}first`);
346
+ const rdfRest = namedNode(`${RDF}rest`);
347
+ const rdfNil = namedNode(`${RDF}nil`);
348
+ const rdfReifies = namedNode(`${RDF}reifies`);
349
+ const xsdInteger = namedNode(`${XSD}integer`);
350
+ const xsdDecimal = namedNode(`${XSD}decimal`);
351
+ const xsdDouble = namedNode(`${XSD}double`);
352
+ const xsdBoolean = namedNode(`${XSD}boolean`);
353
+ /** A syntax or static error, at a character offset. */
354
+ var Failure = class {
355
+ message;
356
+ offset;
357
+ constructor(message, offset) {
358
+ this.message = message;
359
+ this.offset = offset;
360
+ }
361
+ };
362
+ const fail = (message, offset) => {
363
+ throw new Failure(message, offset);
364
+ };
365
+ /**
366
+ * What a hook sees past the last token: a token no grammar rule matches (its
367
+ * kind is no keyword or punctuation), at the end of the input.
368
+ */
369
+ const END = {
370
+ type: "END",
371
+ value: "",
372
+ extra: "",
373
+ kind: "",
374
+ start: -1,
375
+ end: -1,
376
+ error: Option.none()
377
+ };
378
+ /** The token at `pos`, or `END` past the last one. */
379
+ const tokenAt = (tokens, pos) => tokens[pos] ?? END;
380
+ /**
381
+ * A set of token kinds, read through its backing `Map` by the token
382
+ * predicates (one lookup per token, without an `Option` per lookup).
383
+ */
384
+ const kindSet = (kinds) => setOf(kinds);
385
+ /** Whether a triple-shaped item is a triple pattern (not a path pattern). */
386
+ const isTriplePattern = (t) => Predicate.isTagged(t, "TriplePattern");
387
+ /** The context outside every pattern (never read: the grammar sets one first). */
388
+ const noContext = {
389
+ variables: true,
390
+ blankNodes: true,
391
+ scope: 0,
392
+ labels: empty()
393
+ };
394
+ var Context = class {
395
+ input;
396
+ usedLabels;
397
+ bnodeCounter = 0;
398
+ scopeCounter = 0;
399
+ opIndex = 0;
400
+ patternLabels = empty();
401
+ templateLabels = empty();
402
+ aggregatesAllowed = false;
403
+ inAggregate = false;
404
+ /** The aggregate flags saved by `withFlags`, in pairs. */
405
+ flags = [];
406
+ /** The triple contexts in force, innermost last. */
407
+ triples = [];
408
+ /** The last `VERSION` declared. */
409
+ version = Option.none();
410
+ /** Whether the verbs being read are simple predicates, innermost last. */
411
+ verbs = [];
412
+ /** The first token of the subject being read. */
413
+ subjectStart = END;
414
+ constructor(input) {
415
+ this.input = input;
416
+ this.usedLabels = setOf(Array.from(input.matchAll(/_:([^\s.;,(){}[\]]+)/g), (m) => m[1] ?? ""));
417
+ }
418
+ get tc() {
419
+ return this.triples[this.triples.length - 1] ?? noContext;
420
+ }
421
+ patternContext() {
422
+ return {
423
+ variables: true,
424
+ blankNodes: true,
425
+ scope: ++this.scopeCounter,
426
+ labels: this.patternLabels
427
+ };
428
+ }
429
+ freshBlankNode() {
430
+ let label = `g${this.bnodeCounter++}`;
431
+ loop(() => {
432
+ if (!this.usedLabels.has(label)) return false;
433
+ label = `g${this.bnodeCounter++}`;
434
+ return true;
435
+ });
436
+ return blankNode$1(label);
437
+ }
438
+ };
439
+ let ctx = new Context("");
440
+ let fresh = () => new Context("");
441
+ /** Starts a run of the grammar with a new context (the compiled run and any re-run). */
442
+ const start = Parser.make(() => {
443
+ ctx = fresh();
444
+ });
445
+ const offsetOf = (t) => t === END ? ctx.input.length : t.start;
446
+ /**
447
+ * Runs `f`, returning a thrown `Failure` (a syntax error found while
448
+ * building) as the failure; any other exception is a defect and propagates.
449
+ */
450
+ const catchFailure = (f) => Result.try({
451
+ try: f,
452
+ catch: (cause) => {
453
+ if (cause instanceof Failure) return cause;
454
+ throw cause;
455
+ }
456
+ });
457
+ /**
458
+ * A hook: runs `f` on the current token (without consuming it). A `Failure`
459
+ * thrown by `f` is an unrecoverable error.
460
+ */
461
+ const hook = (f) => Parser.make((state) => {
462
+ try {
463
+ return f(tokenAt(state.input, state.pos));
464
+ } catch (e) {
465
+ if (e instanceof Failure) return state.failCause("Cut", "Verify", e);
466
+ throw e;
467
+ }
468
+ });
469
+ /**
470
+ * A token parser written as a hook: `f` returns the value for the current
471
+ * token (consumed), or `None` to fail without consuming it.
472
+ */
473
+ const take = (label, f) => {
474
+ const expected = [label];
475
+ return Parser.make((state) => {
476
+ const t = state.input[state.pos];
477
+ if (t === void 0 || t.type === "ERROR") return state.backtrack("Token", expected);
478
+ try {
479
+ const a = f(t, tokenAt(state.input, state.pos + 1));
480
+ if (Option.isNone(a)) return state.backtrack("Token", expected);
481
+ state.pos++;
482
+ return a.value;
483
+ } catch (e) {
484
+ if (e instanceof Failure) return state.failCause("Cut", "Verify", e);
485
+ throw e;
486
+ }
487
+ });
488
+ };
489
+ /** A `take` result: the token is taken. */
490
+ const taken = Option.some(true);
491
+ const notTaken = Option.none();
492
+ /**
493
+ * Runs `p` with the aggregate flags set (`inAggregate` left alone when
494
+ * `None`), restoring them afterwards.
495
+ */
496
+ const withFlags = (aggregatesAllowed, inAggregate, p) => Parser.delimited(hook(() => {
497
+ ctx.flags.push(ctx.aggregatesAllowed, ctx.inAggregate);
498
+ ctx.aggregatesAllowed = aggregatesAllowed;
499
+ if (Option.isSome(inAggregate)) ctx.inAggregate = inAggregate.value;
500
+ }), p, hook(() => {
501
+ ctx.inAggregate = ctx.flags.pop() ?? false;
502
+ ctx.aggregatesAllowed = ctx.flags.pop() ?? false;
503
+ }));
504
+ /** Runs `p` in a triple context, restoring the enclosing one afterwards. */
505
+ const inContext = (make, p) => Parser.delimited(hook(() => {
506
+ ctx.triples.push(make());
507
+ }), p, hook(() => {
508
+ ctx.triples.pop();
509
+ }));
510
+ const describe = (t) => t === END ? "end of input" : t.type === "STRING" ? "string literal" : `'${ctx.input.slice(t.start, t.end)}'`;
511
+ const unexpected = (t, expected) => fail(`Unexpected ${describe(t)}${expected !== void 0 ? `, expected ${expected}` : ""}`, offsetOf(t));
512
+ /** The reference parser's "Unexpected …" error at `t` (or the lexer's, at an error token). */
513
+ const unexpectedAt = (t, expected) => t.type === "ERROR" ? fail(t.value, t.start) : unexpected(t, expected);
514
+ /** Fails with the reference parser's "Unexpected …" message at the current token. */
515
+ const unexpectedHere = (expected) => hook((t) => unexpectedAt(t, expected));
516
+ /**
517
+ * A token of the given kind (see `Tok.kind`). A token set rather than a
518
+ * `Parser.make` hook, so the compiler inlines the match instead of calling
519
+ * back into an interpreted step.
520
+ */
521
+ const tok = (kind) => Token.oneOf((t) => t.kind === kind).pipe(Parser.expected(`'${kind}'`));
522
+ /** `kind`, or the "Unexpected …, expected …" error. */
523
+ const expect = (kind, label = kind === kind.toUpperCase() && /^[A-Z]/.test(kind) ? kind : `'${kind}'`) => Parser.alt(tok(kind), unexpectedHere(label));
524
+ /** Whether the next token is of kind `kind` (consumed if so). */
525
+ const eat = (kind) => Parser.opt(tok(kind)).pipe(Parser.map(Option.isSome));
526
+ /**
527
+ * Whether the next token's kind is one of `kinds` (not consumed). A peeked
528
+ * token set, like `tok`, so the compiler inlines it.
529
+ */
530
+ const peekKind = (kinds) => {
531
+ const set = kindSet(kinds);
532
+ return Parser.peek(Token.oneOf((t) => set.has(t.kind))).pipe(Parser.asVoid, Parser.expected(kinds.map((k) => `'${k}'`).join(" or ")));
533
+ };
534
+ /** Any token but a lexer error token (consumed). A token set, like `tok`. */
535
+ const anyToken = Token.oneOf((t) => t.type !== "ERROR").pipe(Parser.expected("a token"));
536
+ /**
537
+ * Chooses a parser by the kind of the next token; when no case matches,
538
+ * `otherwise` (or a failure that consumes nothing).
539
+ */
540
+ const select = (cases, otherwise) => {
541
+ const seen = MutableHashSet.empty();
542
+ const branches = Arr.filterMap(cases, ([kinds, p]) => {
543
+ const own = Arr.dedupe(kinds.filter((k) => !MutableHashSet.has(seen, k)));
544
+ own.forEach((k) => MutableHashSet.add(seen, k));
545
+ return Arr.isArrayNonEmpty(own) ? Result.succeed(Parser.preceded(peekKind(own), p)) : Result.failVoid;
546
+ });
547
+ if (otherwise !== void 0) branches.push(otherwise);
548
+ return Parser.alt(...branches);
549
+ };
550
+ /** Whether the next tokens are `a` then `b` (not consumed). */
551
+ const peek2 = (a, b) => Parser.peek(Parser.seq(tok(a), tok(b)));
552
+ const nil = peek2("(", ")");
553
+ const anon = peek2("[", "]");
554
+ const iri = take("an IRI", (t) => {
555
+ if (t.type === "IRI") return Option.some(namedNode(t.value));
556
+ if (t.type === "PNAME") return Option.isSome(t.error) ? fail(t.error.value, t.start) : Option.some(namedNode(t.value));
557
+ return notTaken;
558
+ });
559
+ const iriOrError = Parser.alt(iri, unexpectedHere("an IRI"));
560
+ const variable = take("a variable", (t) => t.type === "VAR" ? Option.some(variable$2(t.value)) : notTaken);
561
+ const variableOrError = Parser.alt(variable, unexpectedHere("a variable"));
562
+ /** A variable in a pattern (checked against the triple context). */
563
+ const patternVariable = take("a variable", (t) => {
564
+ if (t.type !== "VAR") return notTaken;
565
+ if (!ctx.tc.variables) fail("Variables are not allowed here", t.start);
566
+ return Option.some(variable$2(t.value));
567
+ });
568
+ const isIri = (t) => t.type === "IRI" || t.type === "PNAME";
569
+ const isNumber = (t) => t.type === "INTEGER" || t.type === "DECIMAL" || t.type === "DOUBLE";
570
+ const blankNodeLabel = take("a blank node", (t) => {
571
+ if (t.type !== "BNODE") return notTaken;
572
+ const tc = ctx.tc;
573
+ if (!tc.blankNodes) fail("Blank nodes are not allowed here", t.start);
574
+ const existing = tc.labels.get(t.value);
575
+ if (existing !== void 0 && existing !== tc.scope) fail(`Blank node label _:${t.value} is used in more than one scope`, t.start);
576
+ tc.labels.set(t.value, tc.scope);
577
+ return Option.some(blankNode$1(t.value));
578
+ });
579
+ /** A generated blank node in a pattern (checked against the triple context). */
580
+ const freshPatternBlankNode = hook((t) => {
581
+ if (!ctx.tc.blankNodes) fail("Blank nodes are not allowed here", offsetOf(t));
582
+ return ctx.freshBlankNode();
583
+ });
584
+ const string = take("a string", (t) => t.type === "STRING" ? Option.some(t) : notTaken);
585
+ const isDirection = (direction) => direction === "ltr" || direction === "rtl";
586
+ const rdfLiteral = Parser.seq(string, Parser.alt(take("a language tag", (t, next) => {
587
+ if (t.type !== "LANGTAG") return notTaken;
588
+ const tag = t.value;
589
+ const i = tag.indexOf("--");
590
+ if (i === -1) return Option.some({
591
+ tag,
592
+ direction: Option.none()
593
+ });
594
+ const direction = tag.slice(i + 2).toLowerCase();
595
+ return isDirection(direction) ? Option.some({
596
+ tag: tag.slice(0, i),
597
+ direction: Option.some(direction)
598
+ }) : fail(`Invalid base direction '${direction}'`, offsetOf(next));
599
+ }), Parser.preceded(tok("^^"), iriOrError), Parser.succeed(void 0))).pipe(Parser.map(([s, suffix]) => {
600
+ if (suffix === void 0) return literal(s.value);
601
+ if (suffix instanceof NamedNode) return literal(s.value, suffix);
602
+ return Option.isSome(suffix.direction) ? literal(s.value, {
603
+ language: suffix.tag,
604
+ direction: suffix.direction.value
605
+ }) : literal(s.value, suffix.tag);
606
+ }));
607
+ const numberLiteral = (t, sign) => literal(sign + t.value, t.type === "INTEGER" ? xsdInteger : t.type === "DECIMAL" ? xsdDecimal : xsdDouble);
608
+ const numericLiteral = take("a number", (t) => isNumber(t) ? Option.some(numberLiteral(t, "")) : notTaken);
609
+ /** `+` or `-` immediately followed by a number. */
610
+ const signedNumber = Parser.make((state) => {
611
+ const t = state.input[state.pos];
612
+ const n = state.input[state.pos + 1];
613
+ if (t !== void 0 && (t.kind === "+" || t.kind === "-") && n !== void 0 && n.start === t.end && isNumber(n)) {
614
+ state.pos += 2;
615
+ return numberLiteral(n, t.value);
616
+ }
617
+ return state.backtrack("Token", ["a number"]);
618
+ });
619
+ const booleanLiteral = take("a boolean", (t) => t.kind === "TRUE" || t.kind === "FALSE" ? Option.some(literal(t.value.toLowerCase(), xsdBoolean)) : notTaken);
620
+ /** `a`, or an IRI. */
621
+ const aOrIri = Parser.alt(tok("a").pipe(Parser.as(rdfType)), iriOrError);
622
+ /** iri | RDFLiteral | NumericLiteral | BooleanLiteral */
623
+ const dataTerm = Parser.alt(iri, rdfLiteral, numericLiteral, signedNumber, booleanLiteral, unexpectedHere("an RDF term"));
624
+ const tripleTermData = Parser.preceded(tok("<<("), Parser.seq(iriOrError, aOrIri, Parser.alt(Parser.suspend(() => tripleTermData), dataTerm), expect(")>>"))).pipe(Parser.map(([s, p, o]) => triple(s, p, o)));
625
+ /** A data block value; `None` for `UNDEF`. */
626
+ const dataBlockValue = Parser.alt(tok("UNDEF").pipe(Parser.as(Option.none())), Parser.alt(tripleTermData, dataTerm).pipe(Parser.map(Option.some)));
627
+ const dataBlock = Parser.alt(Parser.seq(variable, Parser.preceded(expect("{"), Parser.terminated(Parser.repeat(Parser.preceded(Parser.not(tok("}")), dataBlockValue)), tok("}")))).pipe(Parser.map(([v, values$1]) => values([v], values$1.map((x) => [Option.getOrUndefined(x)])))), Parser.seq(Parser.preceded(expect("("), Parser.repeat(Parser.seq(variable, hook((t) => t))).pipe(Parser.tryMap((vars) => Option.match(Arr.findFirst(vars, ([v], i) => vars.findIndex(([x]) => x.value === v.value) < i), {
628
+ onNone: () => Result.succeed(vars.map(([v]) => v)),
629
+ onSome: ([v, next]) => Result.fail(new Failure(`Duplicate variable ?${v.value} in VALUES`, offsetOf(next)))
630
+ })), Parser.cut)), Parser.preceded(Parser.seq(expect(")"), expect("{")), Parser.terminated(Parser.repeat(Parser.preceded(Parser.not(tok("}")), Parser.seq(hook((t) => offsetOf(t)), Parser.preceded(expect("("), Parser.terminated(Parser.repeat(Parser.preceded(Parser.not(tok(")")), dataBlockValue)), anyToken))))), expect("}")))).pipe(Parser.tryMap(([variables, rows]) => Option.match(Arr.findFirst(rows, ([, row]) => row.length !== variables.length), {
631
+ onNone: () => Result.succeed(values(variables, rows.map(([, row]) => row.map(Option.getOrUndefined)))),
632
+ onSome: ([at, row]) => Result.fail(new Failure(`VALUES row has ${row.length} values but ${variables.length} variables`, at))
633
+ })), Parser.cut));
634
+ const node = (term, triples = []) => ({
635
+ term,
636
+ triples
637
+ });
638
+ /** The triples of a property list, in the order the reference parser emits them. */
639
+ const build = (subject, pl, out = []) => {
640
+ pl.forEach(([v, objects]) => {
641
+ const predicate = v.predicate;
642
+ objects.forEach(({ node: o, annotation }) => {
643
+ o.triples.forEach((t) => out.push(t));
644
+ if (isPath(predicate)) {
645
+ out.push(pathPattern(subject, predicate, o.term));
646
+ return;
647
+ }
648
+ out.push(triplePattern(subject, predicate, o.term));
649
+ if (Arr.isReadonlyArrayEmpty(annotation)) return;
650
+ const triple$1 = triple(subject, predicate, o.term);
651
+ annotation.forEach((a) => {
652
+ out.push(triplePattern(a.reifier, rdfReifies, triple$1));
653
+ if (Option.isSome(a.block)) build(a.reifier, a.block.value, out);
654
+ });
655
+ });
656
+ });
657
+ return out;
658
+ };
659
+ /** The token types that start a triples block on their own. */
660
+ const TRIPLES_START = kindSet([
661
+ "VAR",
662
+ "IRI",
663
+ "PNAME",
664
+ "BNODE",
665
+ "STRING",
666
+ "INTEGER",
667
+ "DECIMAL",
668
+ "DOUBLE"
669
+ ]);
670
+ /** Whether a token can start a triples block. A plain branch per type: it runs once per peek. */
671
+ const startsTriplesToken = (t, next) => {
672
+ if (TRIPLES_START.has(t.type)) return true;
673
+ if (t.type === "WORD") return t.kind === "TRUE" || t.kind === "FALSE";
674
+ if (t.type !== "PUNCT") return false;
675
+ const v = t.value;
676
+ return v === "(" || v === "[" || v === "<<" || v === "<<(" || (v === "+" || v === "-") && isNumber(next);
677
+ };
678
+ const startsTriples = Parser.peek(take("triples", (t, next) => startsTriplesToken(t, next) ? taken : notTaken));
679
+ const path = Parser.suspend(() => pathDef);
680
+ const triplesGrammar = (paths) => {
681
+ const graphNode = Parser.suspend(() => graphNodeDef);
682
+ const propertyList = Parser.suspend(() => propertyListDef);
683
+ const varOrTerm = (allowNil) => Parser.alt(patternVariable, iri, blankNodeLabel, rdfLiteral, numericLiteral, booleanLiteral, signedNumber, ...allowNil ? [Parser.preceded(Parser.seq(nil, anyToken, anyToken), Parser.succeed(rdfNil))] : [], Parser.preceded(Parser.seq(anon, anyToken, anyToken), freshPatternBlankNode), Parser.suspend(() => tripleTerm), unexpectedHere("an RDF term or variable"));
684
+ const patternPredicate = Parser.alt(patternVariable, aOrIri);
685
+ const tripleTermComponent = Parser.alt(Parser.suspend(() => tripleTerm), Parser.preceded(Parser.peek(Parser.alt(tok("("), tok("<<"), Parser.preceded(Parser.not(anon), tok("[")))), unexpectedHere()), varOrTerm(false));
686
+ const tripleTerm = Parser.preceded(tok("<<("), Parser.seq(tripleTermComponent, patternPredicate, tripleTermComponent, expect(")>>"))).pipe(Parser.map(([s, p, o]) => triple(s, p, o)));
687
+ const reifier = Parser.preceded(tok("~"), Parser.alt(patternVariable, iri, blankNodeLabel, Parser.preceded(Parser.seq(anon, anyToken, anyToken), freshPatternBlankNode), freshPatternBlankNode));
688
+ const reifiedTriple = Parser.suspend(() => reifiedTripleDef);
689
+ const reifiedTripleComponent = Parser.alt(reifiedTriple, Parser.suspend(() => tripleTerm).pipe(Parser.map((t) => node(t))), Parser.preceded(Parser.peek(Parser.alt(tok("("), Parser.preceded(Parser.not(anon), tok("[")))), unexpectedHere()), varOrTerm(false).pipe(Parser.map((t) => node(t))));
690
+ const reifiedTripleDef = Parser.preceded(tok("<<"), Parser.seq(reifiedTripleComponent, patternPredicate, reifiedTripleComponent, Parser.alt(reifier, freshPatternBlankNode), expect(">>"))).pipe(Parser.map(([s, p, o, r]) => node(r, [
691
+ ...s.triples,
692
+ ...o.triples,
693
+ triplePattern(r, rdfReifies, triple(s.term, p, o.term))
694
+ ])));
695
+ const triplesNode = Parser.alt(Parser.preceded(tok("["), Parser.seq(freshPatternBlankNode, Parser.terminated(propertyList, expect("]")))).pipe(Parser.map(([b, pl]) => node(b, build(b, pl)))), Parser.preceded(tok("("), Parser.seq(Parser.terminated(Parser.repeat(Parser.preceded(Parser.not(tok(")")), graphNode)), anyToken), hook((t) => t))).pipe(Parser.map(([items, t]) => {
696
+ if (!Arr.isArrayNonEmpty(items)) return node(rdfNil);
697
+ if (!ctx.tc.blankNodes) fail("Blank nodes are not allowed here", offsetOf(t));
698
+ const cells = Arr.map(items, (item) => [ctx.freshBlankNode(), item]);
699
+ const triples = [];
700
+ items.forEach((item) => item.triples.forEach((x) => triples.push(x)));
701
+ cells.forEach(([cell, item], i) => {
702
+ triples.push(triplePattern(cell, rdfFirst, item.term));
703
+ triples.push(triplePattern(cell, rdfRest, cells[i + 1]?.[0] ?? rdfNil));
704
+ });
705
+ return node(cells[0][0], triples);
706
+ })));
707
+ /** GraphNode / GraphNodePath */
708
+ const graphNodeDef = Parser.alt(reifiedTriple, Parser.preceded(Parser.alt(Parser.seq(Parser.not(nil), Parser.peek(tok("("))), Parser.seq(Parser.not(anon), Parser.peek(tok("[")))), triplesNode), varOrTerm(true).pipe(Parser.map((t) => node(t))));
709
+ const startsVerb = Parser.peek(take("a verb", (t) => t.type === "VAR" || isIri(t) || t.kind === "a" || paths && (t.kind === "^" || t.kind === "!" || t.kind === "(") ? taken : notTaken));
710
+ /** A verb; whether it is simple is pushed on `ctx.verbs` until its objects are read. */
711
+ const verb = Parser.alt(Parser.seq(patternVariable, paths ? Parser.preceded(Parser.peek(Parser.alt(tok("/"), tok("|"))), unexpectedHere()).pipe(Parser.opt) : Parser.succeed(void 0)).pipe(Parser.map(([v]) => ({
712
+ predicate: v,
713
+ simple: true
714
+ }))), paths ? path.pipe(Parser.map((p) => Predicate.isTagged(p, "PathLink") ? {
715
+ predicate: p.iri,
716
+ simple: true
717
+ } : {
718
+ predicate: p,
719
+ simple: false
720
+ })) : aOrIri.pipe(Parser.map((predicate) => ({
721
+ predicate,
722
+ simple: true
723
+ })))).pipe(Parser.map((v) => {
724
+ ctx.verbs.push(v.simple);
725
+ return v;
726
+ }));
727
+ const annotationBlock = Parser.terminated(propertyList, expect("|}"));
728
+ const annotationItem = Parser.alt(Parser.seq(reifier, Parser.opt(Parser.preceded(tok("{|"), annotationBlock))).pipe(Parser.map(([r, block]) => ({
729
+ reifier: r,
730
+ block
731
+ }))), Parser.preceded(tok("{|"), Parser.seq(freshPatternBlankNode, annotationBlock)).pipe(Parser.map(([r, block]) => ({
732
+ reifier: r,
733
+ block: Option.some(block)
734
+ }))));
735
+ const annotation = Parser.alt(Parser.preceded(Parser.seq(Parser.peek(Parser.alt(tok("~"), tok("{|"))), hook((t) => {
736
+ if (!ctx.verbs[ctx.verbs.length - 1]) fail("Reifiers and annotations require a simple predicate", offsetOf(t));
737
+ })), Parser.repeat(annotationItem, { min: 1 })), Parser.succeed([]));
738
+ const objectList = Parser.separated(Parser.seq(graphNode, annotation).pipe(Parser.map(([n, a]) => ({
739
+ node: n,
740
+ annotation: a
741
+ }))), tok(","), { min: 1 });
742
+ const verbObjects = Parser.seq(verb, Parser.terminated(objectList, hook(() => {
743
+ ctx.verbs.pop();
744
+ })));
745
+ const propertyListDef = Parser.seq(verbObjects, Parser.repeat(Parser.preceded(Parser.repeat(tok(";"), { min: 1 }), Parser.preceded(startsVerb, verbObjects))), Parser.opt(Parser.repeat(tok(";"), { min: 1 }))).pipe(Parser.map(([first, rest]) => [first, ...rest]));
746
+ const withProperties = (subject) => Parser.seq(subject, Parser.opt(Parser.preceded(startsVerb, propertyList))).pipe(Parser.map(([s, pl]) => Option.isSome(pl) ? build(s.term, pl.value, [...s.triples]) : s.triples));
747
+ const triplesSameSubject = Parser.alt(withProperties(reifiedTriple), Parser.preceded(Parser.alt(Parser.seq(Parser.not(nil), Parser.peek(tok("("))), Parser.seq(Parser.not(anon), Parser.peek(tok("[")))), withProperties(triplesNode)), Parser.seq(hook((t) => {
748
+ ctx.subjectStart = t;
749
+ }), varOrTerm(true), Parser.alt(Parser.preceded(startsVerb, propertyList), hook((t) => unexpectedAt(t, `a predicate after ${describe(ctx.subjectStart)}`)))).pipe(Parser.map(([, subject, pl]) => build(subject, pl))));
750
+ return {
751
+ triplesSameSubject,
752
+ triplesBlock: Parser.seq(triplesSameSubject, Parser.repeat(Parser.preceded(Parser.seq(tok("."), startsTriples), triplesSameSubject)), eat(".")).pipe(Parser.map(([first, rest, dot]) => [[...first, ...rest.flat()], dot])),
753
+ triplesTemplate: Parser.opt(Parser.preceded(Parser.seq(Parser.not(tok("}")), startsTriples), Parser.seq(triplesSameSubject, Parser.repeat(Parser.preceded(Parser.seq(tok("."), Parser.not(tok("}")), startsTriples), triplesSameSubject)), eat(".")))).pipe(Parser.map((o) => Option.isNone(o) ? [] : [...o.value[0], ...o.value[1].flat()]))
754
+ };
755
+ };
756
+ const negatedOne = Parser.seq(eat("^"), aOrIri);
757
+ const negated = Parser.alt(Parser.preceded(tok("("), Parser.terminated(Parser.opt(Parser.separated(negatedOne, tok("|"), { min: 1 })), expect(")"))).pipe(Parser.map((o) => Option.getOrElse(o, () => []))), negatedOne.pipe(Parser.map((one) => [one]))).pipe(Parser.map((ones) => negated$1(ones.filter(([inv]) => !inv).map(([, i]) => i), ones.filter(([inv]) => inv).map(([, i]) => i))));
758
+ const pathPrimary = Parser.alt(tok("a").pipe(Parser.as(link(rdfType))), iri.pipe(Parser.map((i) => link(i))), Parser.preceded(tok("!"), negated), Parser.delimited(tok("("), path, expect(")")), unexpectedHere("a property path"));
759
+ const pathElt = Parser.seq(pathPrimary, Parser.opt(Parser.alt(tok("?"), tok("*"), tok("+")))).pipe(Parser.map(([primary, mod]) => Option.isNone(mod) ? primary : mod.value.kind === "?" ? zeroOrOne(primary) : mod.value.kind === "*" ? zeroOrMore(primary) : oneOrMore(primary)));
760
+ const pathEltOrInverse = Parser.alt(Parser.preceded(tok("^"), pathElt).pipe(Parser.map((p) => inverse(p))), pathElt);
761
+ const pathSequence = Parser.separated(pathEltOrInverse, tok("/"), { min: 1 }).pipe(Parser.map((ps) => ps.length === 1 ? ps[0] : sequence(...ps)));
762
+ const pathDef = Parser.separated(pathSequence, tok("|"), { min: 1 }).pipe(Parser.map((ps) => ps.length === 1 ? ps[0] : alternative(...ps)));
763
+ const expression = Parser.suspend(() => expressionDef);
764
+ const groupGraphPattern = Parser.suspend(() => groupGraphPatternDef);
765
+ const AGGREGATES = [
766
+ "COUNT",
767
+ "SUM",
768
+ "MIN",
769
+ "MAX",
770
+ "AVG",
771
+ "SAMPLE",
772
+ "GROUP_CONCAT"
773
+ ];
774
+ const AGGREGATE_KINDS = kindSet(AGGREGATES);
775
+ const isBuiltInStart = (t) => t.type === "WORD" && (isBuiltInName(t.kind) || AGGREGATE_KINDS.has(t.kind) || t.kind === "EXISTS" || t.kind === "NOT");
776
+ const startsBuiltIn = Parser.peek(take("a function", (t) => isBuiltInStart(t) ? taken : notTaken));
777
+ const brackettedExpression = Parser.delimited(expect("("), expression, expect(")"));
778
+ const expressionList = Parser.preceded(expect("("), Parser.alt(tok(")").pipe(Parser.as([])), Parser.terminated(Parser.separated(expression, tok(","), { min: 1 }), expect(")"))));
779
+ /** The arguments of a function call, and whether they are DISTINCT. */
780
+ const functionArgs = Parser.alt(Parser.preceded(Parser.seq(nil, anyToken, anyToken), Parser.succeed([[], false])), Parser.preceded(expect("("), Parser.seq(Parser.opt(take("DISTINCT", (t) => {
781
+ if (t.kind !== "DISTINCT") return notTaken;
782
+ if (!ctx.aggregatesAllowed || ctx.inAggregate) fail("DISTINCT is only allowed in aggregate function calls", t.start);
783
+ return taken;
784
+ })), Parser.separated(expression, tok(","), { min: 1 }), expect(")"))).pipe(Parser.map(([distinct, args]) => [args, Option.isSome(distinct)])));
785
+ const groupGraphPatternInExpression = withFlags(false, Option.some(false), groupGraphPattern);
786
+ /** An aggregate, from its name. */
787
+ const aggregate = (name) => Parser.preceded(hook((t) => {
788
+ if (!ctx.aggregatesAllowed) fail(`Aggregate ${name} is not allowed here`, offsetOf(t));
789
+ if (ctx.inAggregate) fail("Aggregates cannot be nested", offsetOf(t));
790
+ }), Parser.seq(Parser.preceded(Parser.seq(anyToken, expect("(")), eat("DISTINCT")), Parser.preceded(hook(() => {
791
+ ctx.inAggregate = true;
792
+ }), Parser.alt(...name === "COUNT" ? [Parser.preceded(tok("*"), expect(")")).pipe(Parser.as("*"))] : [], Parser.seq(expression, name === "GROUP_CONCAT" ? Parser.opt(Parser.preceded(Parser.seq(tok(";"), expect("SEPARATOR"), expect("=")), Parser.alt(string, unexpectedHere("a string")))) : Parser.succeed(Option.none()), expect(")")))), hook(() => {
793
+ ctx.inAggregate = false;
794
+ }))).pipe(Parser.map(([distinct, body]) => {
795
+ if (body === "*") return aggregate$1("COUNT", "*", { distinct });
796
+ const [e, sep] = body;
797
+ return Option.isSome(sep) ? aggregate$1(name, e, {
798
+ distinct,
799
+ separator: sep.value.value
800
+ }) : aggregate$1(name, e, { distinct });
801
+ }));
802
+ const BUILT_INS = Record.keys(builtInArity);
803
+ /** The built-in a token names (`peekKind(BUILT_INS)` lets only those through). */
804
+ const builtInName = (t) => isBuiltInName(t.kind) ? t.kind : unexpected(t, "a function");
805
+ const builtInCall = Parser.alt(Parser.preceded(peekKind(BUILT_INS.filter((n) => n !== "BOUND" && builtInArity[n][1] > 0)), Parser.seq(anyToken, expressionList)).pipe(Parser.map(([t, args]) => {
806
+ const name = builtInName(t);
807
+ const [min, max] = builtInArity[name];
808
+ return args.length < min || args.length > max ? fail(`${name} expects ${min === max ? min : `${min} to ${max}`} arguments`, t.start) : operation(name, ...args);
809
+ })), Parser.preceded(peekKind(BUILT_INS.filter((n) => builtInArity[n][1] === 0)), Parser.seq(anyToken, Parser.alt(Parser.seq(nil, anyToken, anyToken), unexpectedHere("'()'")))).pipe(Parser.map(([t]) => operation(builtInName(t)))), Parser.preceded(Parser.seq(tok("BOUND"), expect("(")), Parser.terminated(variableOrError, expect(")"))).pipe(Parser.map((v) => operation("BOUND", v))), Parser.preceded(tok("EXISTS"), groupGraphPatternInExpression).pipe(Parser.map((g) => exists(g, false))), Parser.preceded(Parser.seq(tok("NOT"), expect("EXISTS")), groupGraphPatternInExpression).pipe(Parser.map((g) => exists(g, true))), ...AGGREGATES.map((name) => Parser.preceded(peekKind([name]), aggregate(name))));
810
+ const exprTripleTerm = Parser.preceded(tok("<<("), Parser.seq(Parser.alt(variable, iriOrError), Parser.alt(tok("a").pipe(Parser.as(rdfType)), variable, iriOrError), Parser.alt(Parser.suspend(() => exprTripleTerm), variable, dataTerm), expect(")>>"))).pipe(Parser.map(([s, p, o]) => triple(s, p, o)));
811
+ const primary = Parser.alt(variable, Parser.seq(iri, Parser.opt(Parser.preceded(Parser.peek(tok("(")), functionArgs))).pipe(Parser.map(([i, args]) => Option.isSome(args) ? functionCall(i, args.value[0], args.value[1]) : i)), rdfLiteral, numericLiteral, booleanLiteral, Parser.preceded(startsBuiltIn, builtInCall), Parser.preceded(Parser.peek(tok("(")), brackettedExpression), exprTripleTerm, unexpectedHere("an expression"));
812
+ const unary = Parser.alt(Parser.preceded(tok("!"), Parser.suspend(() => unary)).pipe(Parser.map((e) => operation("!", e))), signedNumber, Parser.seq(Parser.alt(tok("+"), tok("-")), primary).pipe(Parser.map(([op, e]) => operation(op.kind === "+" ? "UPLUS" : "UMINUS", e))), primary);
813
+ /** Matches the token of an operator, typed as that operator. */
814
+ const operator = (o) => tok(o).pipe(Parser.map(() => o));
815
+ const leftAssoc = (operand, ops) => Parser.seq(operand, Parser.repeat(Parser.seq(Parser.alt(...ops.map(operator)), operand))).pipe(Parser.map(([first, rest]) => rest.reduce((left, [op, right]) => operation(op, left, right), first)));
816
+ const additive = leftAssoc(leftAssoc(unary, ["*", "/"]), ["+", "-"]);
817
+ const expressionDef = leftAssoc(leftAssoc(Parser.seq(additive, Parser.opt(Parser.alt(Parser.seq(Parser.alt(...[
818
+ "=",
819
+ "!=",
820
+ "<",
821
+ ">",
822
+ "<=",
823
+ ">="
824
+ ].map(operator)), additive).pipe(Parser.map(([op, right]) => (left) => operation(op, left, right))), Parser.preceded(tok("IN"), expressionList).pipe(Parser.map((list) => (left) => operation("IN", left, ...list))), Parser.preceded(Parser.seq(tok("NOT"), tok("IN")), expressionList).pipe(Parser.map((list) => (left) => operation("NOT IN", left, ...list)))))).pipe(Parser.map(([left, rest]) => Option.isSome(rest) ? rest.value(left) : left)), ["&&"]), ["||"]);
825
+ const constraint = Parser.alt(Parser.preceded(Parser.peek(tok("(")), brackettedExpression), Parser.preceded(startsBuiltIn, builtInCall), Parser.seq(iri, Parser.alt(Parser.preceded(Parser.peek(tok("(")), functionArgs), unexpectedHere("'('"))).pipe(Parser.map(([i, [args, distinct]]) => functionCall(i, args, distinct))), unexpectedHere("a constraint"));
826
+ /** Whether a constraint (`(`, a built-in, an IRI) starts here. */
827
+ const startsConstraint = Parser.peek(take("a constraint", (t) => t.kind === "(" || isBuiltInStart(t) || isIri(t) ? taken : notTaken));
828
+ const patternTriples = triplesGrammar(true);
829
+ const templateTriples = triplesGrammar(false);
830
+ const varOrIri = Parser.alt(variable, iriOrError);
831
+ const GPNT = kindSet([
832
+ "OPTIONAL",
833
+ "MINUS",
834
+ "GRAPH",
835
+ "SERVICE",
836
+ "FILTER",
837
+ "BIND",
838
+ "VALUES"
839
+ ]);
840
+ const graphPatternNotTriples = select([
841
+ [["{"], Parser.seq(groupGraphPattern, Parser.repeat(Parser.preceded(tok("UNION"), groupGraphPattern))).pipe(Parser.map(([first, rest]) => Arr.isReadonlyArrayEmpty(rest) ? first : union([first, ...rest])))],
842
+ [["OPTIONAL"], Parser.preceded(anyToken, groupGraphPattern).pipe(Parser.map((g) => optional(g)))],
843
+ [["MINUS"], Parser.preceded(anyToken, groupGraphPattern).pipe(Parser.map((g) => minus(g)))],
844
+ [["GRAPH"], Parser.preceded(anyToken, Parser.seq(varOrIri, groupGraphPattern)).pipe(Parser.map(([name, g]) => graph(name, g)))],
845
+ [["SERVICE"], Parser.preceded(anyToken, Parser.seq(eat("SILENT"), varOrIri, groupGraphPattern)).pipe(Parser.map(([silent, name, g]) => service(name, g, silent)))],
846
+ [["FILTER"], Parser.preceded(anyToken, constraint).pipe(Parser.map((e) => filter(e)))],
847
+ [["BIND"], Parser.preceded(Parser.seq(anyToken, expect("(")), Parser.seq(expression, Parser.preceded(expect("AS"), variableOrError), expect(")"))).pipe(Parser.map(([e, v]) => bind(e, v)))],
848
+ [["VALUES"], Parser.preceded(anyToken, dataBlock)]
849
+ ]);
850
+ const startsGPNT = Parser.peek(take("a graph pattern", (t) => t.kind === "{" || t.type === "WORD" && GPNT.has(t.kind) ? taken : notTaken));
851
+ const gpntItem = Parser.preceded(startsGPNT, Parser.seq(hook((t) => offsetOf(t)), graphPatternNotTriples, eat("."))).pipe(Parser.map(([at, pattern]) => {
852
+ if (!Predicate.isTagged(pattern, "Filter")) ctx.triples[ctx.triples.length - 1] = ctx.patternContext();
853
+ return {
854
+ _tag: "Pattern",
855
+ pattern,
856
+ at
857
+ };
858
+ }));
859
+ const isGPNTStart = (t) => t.type !== "ERROR" && (t.kind === "{" || t.type === "WORD" && GPNT.has(t.kind));
860
+ /** A triples block; one not ended by `.` must be followed by a pattern or `}`. */
861
+ const triplesItem = Parser.preceded(startsTriples, Parser.seq(patternTriples.triplesBlock, hook((t) => t))).pipe(Parser.map(([[triples, dot], t]) => {
862
+ if (!dot && t.kind !== "}" && !isGPNTStart(t)) unexpectedAt(t, "'.' or '}'");
863
+ return {
864
+ _tag: "Triples",
865
+ triples
866
+ };
867
+ }));
868
+ /** The elements of a group, up to its `}` (not consumed). */
869
+ const groupItems = Parser.repeat(Parser.preceded(Parser.not(tok("}")), Parser.alt(gpntItem, triplesItem, unexpectedHere())));
870
+ /**
871
+ * Adds a group item to the patterns read so far; the failure if it is a
872
+ * `BIND` of a variable already in scope.
873
+ */
874
+ const addGroupItem = (patterns, item) => {
875
+ if (Predicate.isTagged(item, "Triples")) {
876
+ const last = patterns[patterns.length - 1];
877
+ if (Predicate.isTagged(last, "Bgp")) patterns[patterns.length - 1] = bgp([...last.triples, ...item.triples]);
878
+ else patterns.push(bgp(item.triples));
879
+ return Option.none();
880
+ }
881
+ const p = item.pattern;
882
+ if (Predicate.isTagged(p, "Bind")) {
883
+ const name = p.variable.value;
884
+ if (patterns.some((q) => inScopeVariables(q).includes(name))) return Option.some(new Failure(`BIND variable ?${name} is already in scope`, item.at));
885
+ }
886
+ patterns.push(p);
887
+ return Option.none();
888
+ };
889
+ const assembleGroup = (items) => {
890
+ const patterns = [];
891
+ return Option.match(Arr.findFirst(items, (item) => addGroupItem(patterns, item)), {
892
+ onNone: () => Result.succeed(group(patterns)),
893
+ onSome: Result.fail
894
+ });
895
+ };
896
+ const subSelect = Parser.suspend(() => subSelectDef);
897
+ const groupGraphPatternDef = Parser.preceded(expect("{"), Parser.alt(Parser.preceded(Parser.peek(tok("SELECT")), subSelect), inContext(() => ctx.patternContext(), Parser.terminated(groupItems, expect("}"))).pipe(Parser.tryMap(assembleGroup), Parser.cut)));
898
+ let prologue = { value: () => ({ prefixes: {} }) };
899
+ /** Skips the prologue (names are resolved by the lexer), recording `VERSION`. */
900
+ const prologueDecls = Parser.asVoid(Parser.repeat(select([
901
+ [["BASE"], Parser.preceded(anyToken, Parser.alt(take("an IRI", (t) => t.type === "IRI" ? Option.some(t) : notTaken), unexpectedHere("an IRI")))],
902
+ [["PREFIX"], Parser.preceded(anyToken, Parser.seq(Parser.alt(take("a prefix name", (t) => t.type === "PNAME" && t.value === "" ? Option.some(t) : notTaken), unexpectedHere("a prefix name")), Parser.alt(take("an IRI", (t) => t.type === "IRI" ? Option.some(t) : notTaken), unexpectedHere("an IRI"))))],
903
+ [["VERSION"], Parser.preceded(anyToken, Parser.alt(take("a version string", (t) => {
904
+ if (t.type !== "STRING" || t.extra === "long") return notTaken;
905
+ ctx.version = Option.some(t.value);
906
+ return Option.some(t);
907
+ }), unexpectedHere("a version string")))]
908
+ ])));
909
+ /** `query` with its dataset clause; an absent clause leaves the member absent. */
910
+ const withDataset = (query, dataset) => Option.isNone(dataset) ? query : {
911
+ ...query,
912
+ dataset: dataset.value
913
+ };
914
+ const withAggregates = (p) => withFlags(true, Option.none(), p);
915
+ const groupCondition = Parser.alt(variable.pipe(Parser.map((v) => ({ expression: v }))), Parser.preceded(tok("("), Parser.seq(expression, Parser.opt(Parser.preceded(tok("AS"), variableOrError)), expect(")"))).pipe(Parser.map(([e, v]) => Option.isSome(v) ? {
916
+ expression: e,
917
+ variable: v.value
918
+ } : { expression: e })), Parser.preceded(Parser.peek(take("a constraint", (t) => isBuiltInStart(t) || isIri(t) ? taken : notTaken)), constraint).pipe(Parser.map((e) => ({ expression: e }))));
919
+ const orderCondition = Parser.alt(Parser.seq(Parser.alt(tok("ASC"), tok("DESC")), Parser.alt(Parser.preceded(Parser.peek(tok("(")), brackettedExpression), unexpectedHere("'('"))).pipe(Parser.map(([d, e]) => ({
920
+ expression: e,
921
+ descending: d.kind === "DESC"
922
+ }))), variable.pipe(Parser.map((v) => ({
923
+ expression: v,
924
+ descending: false
925
+ }))), Parser.preceded(startsConstraint, constraint).pipe(Parser.map((e) => ({
926
+ expression: e,
927
+ descending: false
928
+ }))));
929
+ const atLeastOne = (p, label) => Parser.seq(Parser.repeat(p), hook((t) => t)).pipe(Parser.tryMap(([items, t]) => Arr.isReadonlyArrayEmpty(items) ? Result.fail(new Failure(t.type === "ERROR" ? t.value : `Unexpected ${describe(t)}, expected ${label}`, offsetOf(t))) : Result.succeed(items)), Parser.cut);
930
+ const integer = Parser.alt(take("an integer", (t) => t.type === "INTEGER" ? Option.some(Number(t.value)) : notTaken), unexpectedHere("an integer"));
931
+ const solutionModifiers = Parser.seq(Parser.opt(Parser.preceded(Parser.seq(tok("GROUP"), expect("BY")), atLeastOne(groupCondition, "a grouping condition"))), Parser.opt(Parser.preceded(tok("HAVING"), Parser.seq(withAggregates(Parser.repeat(Parser.preceded(startsConstraint, constraint))), hook((t) => t))).pipe(Parser.map(([having, t]) => Arr.isReadonlyArrayNonEmpty(having) ? having : unexpectedAt(t, "a HAVING condition")))), Parser.opt(Parser.preceded(Parser.seq(tok("ORDER"), expect("BY")), Parser.seq(withAggregates(Parser.repeat(orderCondition)), hook((t) => t))).pipe(Parser.map(([orderBy, t]) => Arr.isReadonlyArrayNonEmpty(orderBy) ? orderBy : unexpectedAt(t, "an ORDER BY condition")))), Parser.alt(Parser.seq(Parser.preceded(tok("LIMIT"), integer).pipe(Parser.map(Option.some)), Parser.opt(Parser.preceded(tok("OFFSET"), integer))), Parser.seq(Parser.preceded(tok("OFFSET"), integer).pipe(Parser.map(Option.some)), Parser.opt(Parser.preceded(tok("LIMIT"), integer))).pipe(Parser.map(([offset, limit]) => [limit, offset])), Parser.succeed([Option.none(), Option.none()]))).pipe(Parser.map(([groupBy, having, orderBy, [limit, offset]]) => {
932
+ const modifiers = {
933
+ groupBy: Option.getOrElse(groupBy, () => []),
934
+ having: Option.getOrElse(having, () => []),
935
+ orderBy: Option.getOrElse(orderBy, () => [])
936
+ };
937
+ const limited = Option.isNone(limit) ? modifiers : {
938
+ ...modifiers,
939
+ limit: limit.value
940
+ };
941
+ return Option.isNone(offset) ? limited : {
942
+ ...limited,
943
+ offset: offset.value
944
+ };
945
+ }));
946
+ const datasetClauses = Parser.repeat(Parser.preceded(tok("FROM"), Parser.seq(eat("NAMED"), iriOrError))).pipe(Parser.map((clauses) => Arr.isReadonlyArrayEmpty(clauses) ? Option.none() : Option.some({
947
+ default: clauses.filter(([named]) => !named).map(([, i]) => i),
948
+ named: clauses.filter(([named]) => named).map(([, i]) => i)
949
+ })));
950
+ const valuesClause = Parser.opt(Parser.preceded(tok("VALUES"), dataBlock));
951
+ const projectionItem = Parser.alt(variable, Parser.preceded(tok("("), Parser.seq(withAggregates(expression), Parser.preceded(expect("AS"), variableOrError), expect(")"))).pipe(Parser.map(([e, v]) => ({
952
+ _tag: "Projection",
953
+ expression: e,
954
+ variable: v
955
+ }))));
956
+ const selectQuery = (sub) => Parser.preceded(expect("SELECT"), Parser.seq(Parser.alt(tok("DISTINCT").pipe(Parser.as([true, false])), tok("REDUCED").pipe(Parser.as([false, true])), Parser.succeed([false, false])), Parser.alt(tok("*").pipe(Parser.as("*")), atLeastOne(projectionItem, "a variable, expression or *")), sub ? Parser.succeed(Option.none()) : datasetClauses, Parser.preceded(eat("WHERE"), groupGraphPattern), solutionModifiers)).pipe(Parser.map(([[distinct, reduced], projection, dataset, where, modifiers]) => withDataset({
957
+ _tag: "Select",
958
+ prologue: prologue.value(),
959
+ distinct,
960
+ reduced,
961
+ projection,
962
+ where,
963
+ ...modifiers
964
+ }, dataset)));
965
+ const constructTemplate = Parser.delimited(tok("{"), Parser.cut(inContext(() => ({
966
+ variables: true,
967
+ blankNodes: true,
968
+ scope: ++ctx.scopeCounter,
969
+ labels: ctx.templateLabels
970
+ }), templateTriples.triplesTemplate)), expect("}")).pipe(Parser.map((t) => t.filter(isTriplePattern)));
971
+ const constructQuery = Parser.preceded(tok("CONSTRUCT"), Parser.alt(Parser.seq(constructTemplate, datasetClauses, Parser.preceded(eat("WHERE"), groupGraphPattern), solutionModifiers).pipe(Parser.map(([template, dataset, where, modifiers]) => withDataset({
972
+ _tag: "Construct",
973
+ prologue: prologue.value(),
974
+ template,
975
+ where,
976
+ ...modifiers
977
+ }, dataset))), Parser.seq(datasetClauses, Parser.delimited(Parser.seq(expect("WHERE"), expect("{")), inContext(() => ctx.patternContext(), templateTriples.triplesTemplate), expect("}")), solutionModifiers).pipe(Parser.map(([dataset, triples, modifiers]) => {
978
+ const template = triples.filter(isTriplePattern);
979
+ return withDataset({
980
+ _tag: "Construct",
981
+ prologue: prologue.value(),
982
+ template,
983
+ where: group(Arr.isReadonlyArrayNonEmpty(template) ? [bgp(template)] : []),
984
+ short: true,
985
+ ...modifiers
986
+ }, dataset);
987
+ }))));
988
+ const describeQuery = Parser.preceded(tok("DESCRIBE"), Parser.seq(Parser.alt(tok("*").pipe(Parser.as("*")), atLeastOne(Parser.alt(variable, iri), "a variable, IRI or *")), datasetClauses, Parser.alt(Parser.preceded(Parser.peek(Parser.alt(tok("WHERE"), tok("{"))), Parser.preceded(eat("WHERE"), groupGraphPattern)), Parser.succeed(group([]))), solutionModifiers)).pipe(Parser.map(([terms, dataset, where, modifiers]) => withDataset({
989
+ _tag: "Describe",
990
+ prologue: prologue.value(),
991
+ terms,
992
+ where,
993
+ ...modifiers
994
+ }, dataset)));
995
+ const askQuery = Parser.preceded(tok("ASK"), Parser.seq(datasetClauses, Parser.preceded(eat("WHERE"), groupGraphPattern), solutionModifiers)).pipe(Parser.map(([dataset, where, modifiers]) => withDataset({
996
+ _tag: "Ask",
997
+ prologue: prologue.value(),
998
+ where,
999
+ ...modifiers
1000
+ }, dataset)));
1001
+ const subSelectDef = Parser.seq(withFlags(false, Option.none(), Parser.seq(selectQuery(true), valuesClause)), Parser.preceded(expect("}"), hook((t) => offsetOf(t)))).pipe(Parser.map(([[query, values], at]) => {
1002
+ const sub = Option.isSome(values) ? {
1003
+ ...query,
1004
+ values: values.value
1005
+ } : query;
1006
+ validateSelect(sub, at);
1007
+ return group([subSelect$1(sub)]);
1008
+ }));
1009
+ /** The variable a `GROUP BY` condition binds: its `AS` variable, or the variable it is. */
1010
+ const groupKey = (g) => g.variable !== void 0 ? Option.some(g.variable.value) : isVariable(g.expression) ? Option.some(g.expression.value) : Option.none();
1011
+ const validateSelect = (query, offset) => {
1012
+ const projection = query.projection;
1013
+ if (projection !== "*") {
1014
+ const grouped = Arr.isReadonlyArrayNonEmpty(query.groupBy) || projection.some((p) => !isVariable(p) && containsAggregate(p.expression));
1015
+ const inScope = MutableHashSet.fromIterable(grouped ? [] : inScopeVariables(query.where));
1016
+ Arr.forEach(Arr.getSomes(query.groupBy.map(groupKey)), (v) => MutableHashSet.add(inScope, v));
1017
+ (query.values?.variables ?? []).forEach((v) => MutableHashSet.add(inScope, v.value));
1018
+ const seen = MutableHashSet.empty();
1019
+ projection.forEach((item) => {
1020
+ if (isVariable(item)) {
1021
+ MutableHashSet.add(seen, item.value);
1022
+ return;
1023
+ }
1024
+ const name = item.variable.value;
1025
+ if (MutableHashSet.has(inScope, name) || MutableHashSet.has(seen, name)) fail(`Variable ?${name} is already in scope`, offset);
1026
+ MutableHashSet.add(seen, name);
1027
+ });
1028
+ }
1029
+ validateGrouping(query, offset);
1030
+ };
1031
+ const validateGrouping = (query, offset) => {
1032
+ const projectionExprs = Predicate.isTagged(query, "Select") && query.projection !== "*" ? query.projection.flatMap((p) => isVariable(p) ? [] : [p.expression]) : [];
1033
+ const grouped = Arr.isReadonlyArrayNonEmpty(query.groupBy) || projectionExprs.some(containsAggregate) || query.having.some(containsAggregate) || query.orderBy.some((o) => containsAggregate(o.expression));
1034
+ query.groupBy.forEach((g) => {
1035
+ if (containsAggregate(g.expression)) fail("Aggregates are not allowed in GROUP BY", offset);
1036
+ });
1037
+ if (!grouped || !Predicate.isTagged(query, "Select")) return;
1038
+ const projection = query.projection;
1039
+ if (projection === "*") return fail("SELECT * is not allowed with GROUP BY or aggregates", offset);
1040
+ const allowed = MutableHashSet.fromIterable(query.values?.variables.map((v) => v.value) ?? []);
1041
+ Arr.forEach(Arr.getSomes(query.groupBy.map(groupKey)), (v) => MutableHashSet.add(allowed, v));
1042
+ const checkVariable = (v) => {
1043
+ if (!MutableHashSet.has(allowed, v)) fail(`Variable ?${v} is not grouped`, offset);
1044
+ };
1045
+ const checkExpr = (e) => {
1046
+ Match.value(e).pipe(Match.tag("Variable", (v) => checkVariable(v.value)), Match.tag("Operation", "FunctionCall", (call) => call.args.forEach(checkExpr)), Match.tag("Triple", (x) => expressionVariables(x).forEach(checkVariable)), Match.orElse(() => void 0));
1047
+ };
1048
+ projection.forEach((item) => {
1049
+ if (isVariable(item)) checkVariable(item.value);
1050
+ else {
1051
+ checkExpr(item.expression);
1052
+ MutableHashSet.add(allowed, item.variable.value);
1053
+ }
1054
+ });
1055
+ };
1056
+ const checked = (f) => (a) => catchFailure(() => {
1057
+ f(a);
1058
+ return a;
1059
+ });
1060
+ const queryUnit = Compiler.jit(Parser.preceded(Parser.seq(start, prologueDecls), Parser.seq(select([
1061
+ [["SELECT"], selectQuery(false)],
1062
+ [["CONSTRUCT"], constructQuery],
1063
+ [["DESCRIBE"], describeQuery],
1064
+ [["ASK"], askQuery]
1065
+ ], unexpectedHere("SELECT, CONSTRUCT, DESCRIBE or ASK")), valuesClause, Parser.alt(Parser.eof, unexpectedHere())).pipe(Parser.map(([query, values]) => Option.isSome(values) ? {
1066
+ ...query,
1067
+ values: values.value
1068
+ } : query), Parser.tryMap(checked((query) => {
1069
+ if (Predicate.isTagged(query, "Select")) validateSelect(query, 0);
1070
+ else validateGrouping(query, 0);
1071
+ })), Parser.cut)));
1072
+ const quadPattern = Parser.delimited(expect("{"), Parser.repeat(Parser.preceded(Parser.not(tok("}")), Parser.alt(Parser.preceded(tok("GRAPH"), Parser.seq(Parser.preceded(hook((t) => {
1073
+ if (t.type === "VAR" && !ctx.tc.variables) fail("Variables are not allowed here", t.start);
1074
+ }), varOrIri), Parser.delimited(expect("{"), templateTriples.triplesTemplate, expect("}")), eat("."))).pipe(Parser.map(([g, triples]) => triples.filter(isTriplePattern).map((tp) => quadPattern$1(tp.subject, tp.predicate, tp.object, g)))), Parser.terminated(Parser.preceded(Parser.alt(startsTriples, unexpectedHere()), templateTriples.triplesTemplate), Parser.alt(Parser.peek(Parser.alt(tok("}"), tok("GRAPH"))), unexpectedHere("'.' or '}'"))).pipe(Parser.map((triples) => triples.filter(isTriplePattern).map((tp) => quadPattern$1(tp.subject, tp.predicate, tp.object, defaultGraph))))))), expect("}")).pipe(Parser.map((lists) => lists.flat()));
1075
+ const templateContext = (blankNodes) => () => ({
1076
+ variables: true,
1077
+ blankNodes,
1078
+ scope: ctx.opIndex,
1079
+ labels: empty()
1080
+ });
1081
+ const quadData = (blankNodes) => inContext(() => ({
1082
+ variables: false,
1083
+ blankNodes,
1084
+ scope: ctx.opIndex,
1085
+ labels: ctx.templateLabels
1086
+ }), quadPattern).pipe(Parser.map((quads) => quads.map((q) => new Quad(q.subject, q.predicate, q.object, q.graph))));
1087
+ const usingClauses = Parser.repeat(Parser.preceded(tok("USING"), Parser.seq(eat("NAMED"), iriOrError)));
1088
+ const modify = (deleteFirst) => Parser.seq(deleteFirst ? Parser.seq(inContext(templateContext(false), quadPattern), Parser.opt(Parser.preceded(tok("INSERT"), inContext(templateContext(true), quadPattern)))).pipe(Parser.map(([del, ins]) => [del, Option.getOrElse(ins, () => [])])) : inContext(templateContext(true), quadPattern).pipe(Parser.map((ins) => [[], ins])), usingClauses, Parser.preceded(expect("WHERE"), groupGraphPattern)).pipe(Parser.map(([[del, ins], using, where]) => {
1089
+ const op = {
1090
+ _tag: "Modify",
1091
+ delete: del,
1092
+ insert: ins,
1093
+ where
1094
+ };
1095
+ return Arr.isReadonlyArrayEmpty(using) ? op : {
1096
+ ...op,
1097
+ using: {
1098
+ default: using.filter(([named]) => !named).map(([, i]) => i),
1099
+ named: using.filter(([named]) => named).map(([, i]) => i)
1100
+ }
1101
+ };
1102
+ }));
1103
+ const graphRefAll = Parser.alt(tok("DEFAULT").pipe(Parser.as({ _tag: "Default" })), tok("NAMED").pipe(Parser.as({ _tag: "Named" })), tok("ALL").pipe(Parser.as({ _tag: "All" })), Parser.preceded(expect("GRAPH"), iriOrError));
1104
+ const graphOrDefault = Parser.alt(tok("DEFAULT").pipe(Parser.as(defaultGraph)), Parser.preceded(eat("GRAPH"), iriOrError));
1105
+ const update1 = select([
1106
+ [["LOAD"], Parser.preceded(anyToken, Parser.seq(eat("SILENT"), iriOrError, Parser.opt(Parser.preceded(Parser.seq(tok("INTO"), expect("GRAPH")), iriOrError)))).pipe(Parser.map(([silent, source, dest]) => Option.isSome(dest) ? {
1107
+ _tag: "Load",
1108
+ silent,
1109
+ source,
1110
+ destination: dest.value
1111
+ } : {
1112
+ _tag: "Load",
1113
+ silent,
1114
+ source
1115
+ }))],
1116
+ [["CLEAR", "DROP"], Parser.seq(anyToken, eat("SILENT"), graphRefAll).pipe(Parser.map(([t, silent, target]) => ({
1117
+ _tag: t.kind === "CLEAR" ? "Clear" : "Drop",
1118
+ silent,
1119
+ target
1120
+ })))],
1121
+ [["CREATE"], Parser.preceded(anyToken, Parser.seq(eat("SILENT"), Parser.preceded(expect("GRAPH"), iriOrError))).pipe(Parser.map(([silent, graph]) => ({
1122
+ _tag: "Create",
1123
+ silent,
1124
+ graph
1125
+ })))],
1126
+ [[
1127
+ "ADD",
1128
+ "MOVE",
1129
+ "COPY"
1130
+ ], Parser.seq(anyToken, eat("SILENT"), graphOrDefault, Parser.preceded(expect("TO"), graphOrDefault)).pipe(Parser.map(([t, silent, source, destination]) => ({
1131
+ _tag: t.kind === "ADD" ? "Add" : t.kind === "MOVE" ? "Move" : "Copy",
1132
+ silent,
1133
+ source,
1134
+ destination
1135
+ })))],
1136
+ [["INSERT"], Parser.preceded(anyToken, Parser.alt(Parser.preceded(tok("DATA"), quadData(true)).pipe(Parser.map((quads) => ({
1137
+ _tag: "InsertData",
1138
+ quads
1139
+ }))), modify(false)))],
1140
+ [["DELETE"], Parser.preceded(anyToken, Parser.alt(Parser.preceded(tok("DATA"), quadData(false)).pipe(Parser.map((quads) => ({
1141
+ _tag: "DeleteData",
1142
+ quads
1143
+ }))), Parser.preceded(tok("WHERE"), inContext(() => ({
1144
+ variables: true,
1145
+ blankNodes: false,
1146
+ scope: ++ctx.scopeCounter,
1147
+ labels: ctx.patternLabels
1148
+ }), quadPattern)).pipe(Parser.map((patterns) => ({
1149
+ _tag: "DeleteWhere",
1150
+ patterns
1151
+ }))), modify(true)))],
1152
+ [["WITH"], Parser.seq(Parser.preceded(anyToken, iriOrError), Parser.alt(Parser.preceded(tok("DELETE"), modify(true)), Parser.preceded(expect("INSERT"), modify(false)))).pipe(Parser.map(([i, { _tag, ...rest }]) => ({
1153
+ _tag,
1154
+ with: i,
1155
+ ...rest
1156
+ })))]
1157
+ ], unexpectedHere("an update operation"));
1158
+ const update1Indexed = Parser.terminated(update1, hook(() => {
1159
+ ctx.opIndex++;
1160
+ }));
1161
+ const updateUnit = Compiler.jit(Parser.preceded(Parser.seq(start, prologueDecls), Parser.terminated(Parser.opt(Parser.preceded(Parser.not(Parser.eof), Parser.separated(update1Indexed, Parser.seq(tok(";"), prologueDecls, Parser.not(Parser.eof)), { min: 1 }))), Parser.seq(Parser.opt(Parser.seq(tok(";"), prologueDecls)), Parser.alt(Parser.eof, unexpectedHere("';'"))))).pipe(Parser.map((ops) => update(Option.getOrElse(ops, () => []), prologue.value()))));
1162
+ const run = (grammar, input, baseIri, prefixes) => {
1163
+ const tokens = tokenize(input);
1164
+ const resolved = resolve(tokens, baseIri, prefixes);
1165
+ fresh = () => new Context(input);
1166
+ ctx = fresh();
1167
+ prologue = { value: () => {
1168
+ const declared = { prefixes: { ...resolved.prefixes } };
1169
+ const based = Option.isNone(resolved.base) ? declared : {
1170
+ ...declared,
1171
+ base: resolved.base.value
1172
+ };
1173
+ return Option.isNone(ctx.version) ? based : {
1174
+ ...based,
1175
+ version: ctx.version.value
1176
+ };
1177
+ } };
1178
+ const parsed = catchFailure(() => Parser.parse(grammar, tokens));
1179
+ if (Result.isFailure(parsed)) return Result.fail(parsed.failure);
1180
+ const result = parsed.success;
1181
+ if (Result.isSuccess(result)) return Result.succeed(result.success);
1182
+ const error = result.failure;
1183
+ if (error.cause !== void 0) return Result.fail(error.cause);
1184
+ const t = tokenAt(tokens, error.offset);
1185
+ if (t.type === "ERROR") return Result.fail(new Failure(t.value, t.start));
1186
+ return Result.fail(new Failure(`Unexpected ${describe(t)}`, offsetOf(t)));
1187
+ };
1188
+ /** Parses a query against a base IRI (if any) and initial prefixes. */
1189
+ const parseQuery$1 = (input, baseIri, prefixes) => run(queryUnit, input, baseIri, prefixes);
1190
+ /** Parses an update request against a base IRI (if any) and initial prefixes. */
1191
+ const parseUpdate$1 = (input, baseIri, prefixes) => run(updateUnit, input, baseIri, prefixes);
1192
+ // src/sparql/Parser.ts
1193
+ /**
1194
+ * A complete parser for SPARQL 1.1 Query and Update, written with
1195
+ * `@thomasfosterau/effect-parse` (see `internal/parser.ts`), including the SPARQL 1.2 additions (triple terms, reified triples,
1196
+ * annotations, `VERSION`, directional language tags and the new built-in
1197
+ * functions).
1198
+ *
1199
+ * The parser expands all abbreviations (prefixed names, relative IRIs,
1200
+ * `a`, blank node property lists, collections, reifiers and annotations)
1201
+ * and enforces the static constraints of the specification (blank node
1202
+ * label scoping, grouping rules, `BIND`/`AS` scoping, `VALUES` arity,
1203
+ * variable-free `INSERT DATA`, blank-node-free `DELETE` templates, …).
1204
+ *
1205
+ * @since 0.1.0
1206
+ */
1207
+ var Parser_exports = /* @__PURE__ */ __exportAll({
1208
+ SparqlParseError: () => SparqlParseError,
1209
+ parse: () => parse,
1210
+ parseQuery: () => parseQuery,
1211
+ parseQueryResult: () => parseQueryResult,
1212
+ parseQueryUnsafe: () => parseQueryUnsafe,
1213
+ parseUpdate: () => parseUpdate,
1214
+ parseUpdateResult: () => parseUpdateResult,
1215
+ parseUpdateUnsafe: () => parseUpdateUnsafe
1216
+ });
1217
+ /**
1218
+ * A syntax (or static semantic) error in a SPARQL query or update.
1219
+ *
1220
+ * @since 0.1.0
1221
+ * @category errors
1222
+ */
1223
+ var SparqlParseError = class extends Schema.TaggedError()("SparqlParseError", {
1224
+ message: Schema.String,
1225
+ /** 1-based line of the error. */
1226
+ line: Schema.Number,
1227
+ /** 1-based column of the error. */
1228
+ column: Schema.Number,
1229
+ /** 0-based character offset of the error. */
1230
+ offset: Schema.Number
1231
+ }) {};
1232
+ const position = (input, offset) => {
1233
+ const before = input.slice(0, Math.max(0, Math.min(offset, input.length)));
1234
+ const lineStart = before.lastIndexOf("\n") + 1;
1235
+ return {
1236
+ line: before.split("\n").length,
1237
+ column: offset - lineStart + 1
1238
+ };
1239
+ };
1240
+ /** The base IRI and prefixes of `options`, as the internal parser takes them. */
1241
+ const internalOptions = (options) => [Option.fromUndefinedOr(options?.baseIri), options?.prefixes ?? {}];
1242
+ const toError = (input) => (e) => {
1243
+ const { line, column } = position(input, e.offset);
1244
+ return new SparqlParseError({
1245
+ message: `${e.message} (line ${line}, column ${column})`,
1246
+ line,
1247
+ column,
1248
+ offset: e.offset
1249
+ });
1250
+ };
1251
+ /**
1252
+ * Parses a SPARQL query, returning a `Result`.
1253
+ *
1254
+ * @since 0.1.0
1255
+ * @category parsing
1256
+ */
1257
+ const parseQueryResult = (input, options) => Result.mapError(parseQuery$1(input, ...internalOptions(options)), toError(input));
1258
+ /**
1259
+ * Parses a SPARQL update request, returning a `Result`.
1260
+ *
1261
+ * @since 0.1.0
1262
+ * @category parsing
1263
+ */
1264
+ const parseUpdateResult = (input, options) => Result.mapError(parseUpdate$1(input, ...internalOptions(options)), toError(input));
1265
+ /**
1266
+ * Parses a SPARQL query.
1267
+ *
1268
+ * @since 0.1.0
1269
+ * @category parsing
1270
+ */
1271
+ const parseQuery = (input, options) => Effect.suspend(() => Effect.fromResult(parseQueryResult(input, options)));
1272
+ /**
1273
+ * Parses a SPARQL update request.
1274
+ *
1275
+ * @since 0.1.0
1276
+ * @category parsing
1277
+ */
1278
+ const parseUpdate = (input, options) => Effect.suspend(() => Effect.fromResult(parseUpdateResult(input, options)));
1279
+ /**
1280
+ * Parses either a query or an update request: the text is parsed as a query
1281
+ * first and, if that fails, as an update.
1282
+ *
1283
+ * @since 0.1.0
1284
+ * @category parsing
1285
+ */
1286
+ const parse = (input, options) => Effect.suspend(() => {
1287
+ const q = parseQueryResult(input, options);
1288
+ if (Result.isSuccess(q)) return Effect.succeed(q.success);
1289
+ const u = parseUpdateResult(input, options);
1290
+ if (Result.isSuccess(u)) return Effect.succeed(u.success);
1291
+ return Effect.fail(q.failure.offset >= u.failure.offset ? q.failure : u.failure);
1292
+ });
1293
+ /**
1294
+ * Parses a SPARQL query, throwing a `SparqlParseError` on failure.
1295
+ *
1296
+ * @since 0.1.0
1297
+ * @category parsing
1298
+ */
1299
+ const parseQueryUnsafe = (input, options) => {
1300
+ const r = parseQueryResult(input, options);
1301
+ if (Result.isFailure(r)) throw r.failure;
1302
+ return r.success;
1303
+ };
1304
+ /**
1305
+ * Parses a SPARQL update request, throwing a `SparqlParseError` on failure.
1306
+ *
1307
+ * @since 0.1.0
1308
+ * @category parsing
1309
+ */
1310
+ const parseUpdateUnsafe = (input, options) => {
1311
+ const r = parseUpdateResult(input, options);
1312
+ if (Result.isFailure(r)) throw r.failure;
1313
+ return r.success;
1314
+ };
1315
+ export { parseQueryResult as a, parseUpdateResult as c, parseQuery as i, parseUpdateUnsafe as l, SparqlParseError as n, parseQueryUnsafe as o, parse as r, parseUpdate as s, Parser_exports as t };
1316
+
1317
+ //# sourceMappingURL=Parser-xARsOWXk.mjs.map