@thomasfosterau/effect-rdf 0.0.0-stage → 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 +2251 -2
  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 +195 -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,2836 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
2
+ import { B as isNamedNode, N as isBlankNode, O as defaultGraph, P as isDefaultGraph, Q as quad, T as blankNode$1, X as mapTerms, Y as literal, Z as namedNode, z as isLiteral } from "./Term-CFLG1qu4.mjs";
3
+ import { m as fromIterable } from "./Dataset-BlmlcI7J.mjs";
4
+ import { a as isValid, c as removeDotSegments, l as resolve } from "./Iri-Cr92gsQV.mjs";
5
+ import { s as make } from "./PrefixMap-BHFPDLO-.mjs";
6
+ import { C as withParseSpan, c as makeCodec, d as makeSerializer, l as makeFormat, n as RdfParseError, o as freshBlankNodePrefix, r as RdfSerializeError, u as makeParser, w as withSerializeSpan } from "./Serialization-DP9H5bYQ.mjs";
7
+ import { f as none, m as parseJson, t as DocumentLoader } from "./DocumentLoader-D3lZREnB.mjs";
8
+ import { a as make$1, i as isJsonLdError } from "./JsonLdError-C9J-BxfG.mjs";
9
+ import * as Arr from "effect/Array";
10
+ import * as Iterable from "effect/Iterable";
11
+ import * as MutableHashMap from "effect/MutableHashMap";
12
+ import * as MutableHashSet from "effect/MutableHashSet";
13
+ import * as Option from "effect/Option";
14
+ import * as Predicate from "effect/Predicate";
15
+ import * as Schema from "effect/Schema";
16
+ import * as Effect from "effect/Effect";
17
+ import * as Match from "effect/Match";
18
+ import * as Order from "effect/Order";
19
+ import * as Record from "effect/Record";
20
+ import * as Result from "effect/Result";
21
+ // src/jsonld/internal/iri.ts
22
+ /** @internal */
23
+ /**
24
+ * Resolves `reference` against `base`; a `null` base (`"@base": null`, or no
25
+ * document URL) leaves it unchanged.
26
+ *
27
+ * @internal
28
+ */
29
+ const resolveIri = (reference, base) => base === null ? reference : resolve(reference, base);
30
+ const PARTS = /^(?:([A-Za-z][A-Za-z0-9+.-]*):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/s;
31
+ /**
32
+ * Turns an absolute IRI into a reference relative to `base`, when possible.
33
+ *
34
+ * @internal
35
+ */
36
+ const removeBase = (base, iri) => {
37
+ if (base === null) return iri;
38
+ const b = PARTS.exec(base);
39
+ if (b === null) return iri;
40
+ let root = "";
41
+ if (base !== "") {
42
+ if (b[1] === void 0) return iri;
43
+ root = `${b[1]}:${b[2] !== void 0 ? `//${b[2]}` : ""}`;
44
+ }
45
+ if (!iri.startsWith(root)) return iri;
46
+ const restStart = iri.charAt(root.length);
47
+ if (root !== "" && restStart !== "" && !"/?#".includes(restStart)) return iri;
48
+ const rel = PARTS.exec(iri.slice(root.length));
49
+ if (rel === null) return iri;
50
+ const baseSegments = removeDotSegments(b[3] ?? "").split("/");
51
+ const iriSegments = removeDotSegments(rel[3] ?? "").split("/");
52
+ const last = rel[5] !== void 0 || rel[4] !== void 0 ? 0 : 1;
53
+ const differs = baseSegments.findIndex((segment, i) => iriSegments.length - i <= last || segment !== iriSegments[i]);
54
+ const common = differs === -1 ? baseSegments.length : differs;
55
+ const baseRest = baseSegments.length - common;
56
+ let out = baseRest > 0 ? "../".repeat(baseRest - 1) : "";
57
+ out += iriSegments.slice(common).join("/");
58
+ if (rel[4] !== void 0) out += `?${rel[4]}`;
59
+ if (rel[5] !== void 0) out += `#${rel[5]}`;
60
+ if (out === "") out = "./";
61
+ if (/^[^/?#]*:/.test(out)) out = `./${out}`;
62
+ if (/^@[a-zA-Z]+$/.test(out)) out = `./${out}`;
63
+ return base === "" || resolveIri(out, base) === iri ? out : iri;
64
+ };
65
+ // src/jsonld/internal/util.ts
66
+ /** @internal */
67
+ const JsonText = Schema.fromJsonString(Schema.Unknown);
68
+ const encodeJson = Schema.encodeUnknownResult(JsonText);
69
+ /**
70
+ * Serialises a JSON value (`JSON.stringify` semantics); a value with no JSON
71
+ * form (`undefined`) renders as `String(value)`, as in a template literal.
72
+ *
73
+ * @internal
74
+ */
75
+ const stringifyJson = (value) => Result.getOrElse(encodeJson(value), () => String(value));
76
+ /** @internal */
77
+ const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
78
+ /**
79
+ * A membership test for a fixed set of strings: a lookup in a prototype-less
80
+ * record, so that no `Object.prototype` member is a member.
81
+ *
82
+ * @internal
83
+ */
84
+ const stringSet = (members) => {
85
+ const record = Object.create(null);
86
+ members.forEach((m) => {
87
+ record[m] = true;
88
+ });
89
+ return (s) => record[s] === true;
90
+ };
91
+ const isKeywordString = stringSet([
92
+ "@base",
93
+ "@container",
94
+ "@context",
95
+ "@default",
96
+ "@direction",
97
+ "@embed",
98
+ "@explicit",
99
+ "@graph",
100
+ "@id",
101
+ "@import",
102
+ "@included",
103
+ "@index",
104
+ "@json",
105
+ "@language",
106
+ "@list",
107
+ "@nest",
108
+ "@none",
109
+ "@omitDefault",
110
+ "@prefix",
111
+ "@preserve",
112
+ "@protected",
113
+ "@requireAll",
114
+ "@reverse",
115
+ "@set",
116
+ "@type",
117
+ "@value",
118
+ "@version",
119
+ "@vocab"
120
+ ]);
121
+ /** @internal */
122
+ const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
123
+ /** @internal */
124
+ const XSD = "http://www.w3.org/2001/XMLSchema#";
125
+ /** @internal */
126
+ const RDF_TYPE = `${RDF}type`;
127
+ /** @internal */
128
+ const RDF_FIRST = `${RDF}first`;
129
+ /** @internal */
130
+ const RDF_REST = `${RDF}rest`;
131
+ /** @internal */
132
+ const RDF_NIL = `${RDF}nil`;
133
+ /** @internal */
134
+ const RDF_JSON = `${RDF}JSON`;
135
+ /** @internal */
136
+ const RDF_VALUE = `${RDF}value`;
137
+ /** @internal */
138
+ const RDF_LANGUAGE = `${RDF}language`;
139
+ /** @internal */
140
+ const RDF_DIRECTION = `${RDF}direction`;
141
+ /** @internal */
142
+ const RDF_LANG_STRING = `${RDF}langString`;
143
+ /** @internal */
144
+ const XSD_STRING = `${XSD}string`;
145
+ /** @internal */
146
+ const XSD_BOOLEAN = `${XSD}boolean`;
147
+ /** @internal */
148
+ const XSD_INTEGER = `${XSD}integer`;
149
+ /** @internal */
150
+ const XSD_DOUBLE = `${XSD}double`;
151
+ /** @internal */
152
+ const I18N = "https://www.w3.org/ns/i18n#";
153
+ /**
154
+ * Throws the `JsonLdError` with this code. Its type is declared on the
155
+ * binding, so that a call statement narrows like a `throw`.
156
+ *
157
+ * @internal
158
+ */
159
+ const fail = (code, message) => {
160
+ throw make$1(code, message);
161
+ };
162
+ /**
163
+ * Runs `f`, handing a thrown `JsonLdError` to `onError` (which rethrows a
164
+ * different one); any other thrown value propagates unchanged.
165
+ *
166
+ * @internal
167
+ */
168
+ const mapJsonLdError = (f, onError) => Result.getOrElse(Result.try({
169
+ try: f,
170
+ catch: (e) => {
171
+ if (isJsonLdError(e)) return e;
172
+ throw e;
173
+ }
174
+ }), onError);
175
+ /** @internal */
176
+ const GRAPH_PROPERTY = Option.some("@graph");
177
+ /** @internal */
178
+ const REVERSE_PROPERTY = Option.some("@reverse");
179
+ /**
180
+ * The active property is `keyword` (`@graph`, `@reverse`, …).
181
+ *
182
+ * @internal
183
+ */
184
+ const isProperty = (activeProperty, keyword) => Option.isSome(activeProperty) && activeProperty.value === keyword;
185
+ /**
186
+ * At the top level, or directly under `@graph`: where free-floating values are dropped.
187
+ *
188
+ * @internal
189
+ */
190
+ const isTopLevel = (activeProperty) => Option.isNone(activeProperty) || activeProperty.value === "@graph";
191
+ /** @internal */
192
+ const getOrInit = (o, k, init) => {
193
+ if (!hasOwn(o, k)) o[k] = init();
194
+ return o[k];
195
+ };
196
+ /** @internal */
197
+ const isKeyword = (v) => Predicate.isString(v) && isKeywordString(v);
198
+ const KEYWORD_FORM = /^@[a-zA-Z]+$/;
199
+ const ABSOLUTE_IRI = /^[A-Za-z][A-Za-z0-9+.-]*:[^\s]*$/;
200
+ /** @internal */
201
+ const hasKeywordForm = (v) => KEYWORD_FORM.test(v);
202
+ /** @internal */
203
+ const isObject = (v) => Predicate.isObject(v);
204
+ /** @internal */
205
+ const isEmptyObject = (v) => isObject(v) && Arr.isReadonlyArrayEmpty(Record.keys(v));
206
+ /** @internal */
207
+ const isString$1 = (v) => Predicate.isString(v);
208
+ /** @internal */
209
+ const isScalar = (v) => Predicate.isString(v) || Predicate.isNumber(v) || Predicate.isBoolean(v);
210
+ /** @internal */
211
+ const asArray = (v) => Array.isArray(v) ? v : [v];
212
+ /** @internal */
213
+ const isBlankNodeId = (v) => Predicate.isString(v) && v.startsWith("_:");
214
+ /** @internal */
215
+ const isAbsoluteIri = (v) => ABSOLUTE_IRI.test(v);
216
+ /** @internal */
217
+ const isWellFormedIri = (v) => isValid(v);
218
+ /** @internal */
219
+ const isWellFormedLanguage = (v) => /^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/.test(v);
220
+ /** @internal */
221
+ const isValueObject = (v) => isObject(v) && "@value" in v;
222
+ /** @internal */
223
+ const isListObject = (v) => isObject(v) && "@list" in v;
224
+ /** @internal */
225
+ const isGraphObject = (v) => {
226
+ if (!isObject(v) || !("@graph" in v)) return false;
227
+ return Record.keys(v).every((k) => k === "@graph" || k === "@id" || k === "@index" || k === "@context");
228
+ };
229
+ /** @internal */
230
+ const isSimpleGraphObject = (v) => isGraphObject(v) && !("@id" in v);
231
+ /** @internal */
232
+ const deepEqual = (a, b) => {
233
+ if (a === b) return true;
234
+ if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((x, i) => deepEqual(x, b[i]));
235
+ if (isObject(a)) {
236
+ if (!isObject(b)) return false;
237
+ const ka = Record.keys(a);
238
+ return ka.length === Record.keys(b).length && ka.every((k) => hasOwn(b, k) && deepEqual(a[k], b[k]));
239
+ }
240
+ return false;
241
+ };
242
+ /** @internal */
243
+ const compareStrings = Order.String;
244
+ /**
245
+ * Appends every item to `target` (one `push` per item: spreading a large
246
+ * array into `push` can overflow the stack).
247
+ *
248
+ * @internal
249
+ */
250
+ const pushAll = (target, items) => {
251
+ items.forEach((item) => target.push(item));
252
+ };
253
+ /**
254
+ * Adds a value to an entry of a map. When `forceArray` is true the entry is
255
+ * always an array.
256
+ *
257
+ * @internal
258
+ */
259
+ const addValue = (object, key, value, forceArray) => {
260
+ if (Array.isArray(value)) {
261
+ if (Arr.isReadonlyArrayEmpty(value) && forceArray && !hasOwn(object, key)) object[key] = [];
262
+ value.forEach((v) => addValue(object, key, v, forceArray));
263
+ return;
264
+ }
265
+ if (!hasOwn(object, key)) object[key] = forceArray ? [value] : value;
266
+ else {
267
+ if (!Array.isArray(object[key])) object[key] = [object[key]];
268
+ object[key].push(value);
269
+ }
270
+ };
271
+ /** @internal */
272
+ const addUnique = (array, value) => {
273
+ if (!array.some((v) => deepEqual(v, value))) array.push(value);
274
+ };
275
+ /**
276
+ * Steps a state until `step` returns none, and returns the last state: a
277
+ * loop as a function, for the scans that walk a structure of unknown length.
278
+ *
279
+ * @internal
280
+ */
281
+ const loop = (initial, step) => {
282
+ let state = initial;
283
+ Arr.unfold(void 0, () => Option.map(step(state), (next) => {
284
+ state = next;
285
+ return [void 0, void 0];
286
+ }));
287
+ return state;
288
+ };
289
+ /** @internal */
290
+ const clone = (v) => v === void 0 ? v : structuredClone(v);
291
+ /**
292
+ * The JSON Canonicalization Scheme (RFC 8785).
293
+ *
294
+ * @internal
295
+ */
296
+ const canonicalJson = (v) => {
297
+ if (v === null || Predicate.isBoolean(v) || Predicate.isNumber(v) || Predicate.isString(v)) return stringifyJson(v);
298
+ if (Array.isArray(v)) return `[${v.map(canonicalJson).join(",")}]`;
299
+ return `{${Arr.sort(Record.keys(v), compareStrings).map((k) => `${stringifyJson(k)}:${canonicalJson(v[k])}`).join(",")}}`;
300
+ };
301
+ /**
302
+ * A blank node identifier issuer.
303
+ *
304
+ * @internal
305
+ */
306
+ var IdIssuer = class {
307
+ #counter = 0;
308
+ #map = MutableHashMap.empty();
309
+ prefix;
310
+ constructor(prefix = "_:b") {
311
+ this.prefix = prefix;
312
+ }
313
+ /** A fresh identifier, or the one already issued for `old`. */
314
+ issue(old) {
315
+ if (old === void 0) return this.#next();
316
+ return Option.getOrElse(MutableHashMap.get(this.#map, old), () => {
317
+ const id = this.#next();
318
+ MutableHashMap.set(this.#map, old, id);
319
+ return id;
320
+ });
321
+ }
322
+ has(old) {
323
+ return MutableHashMap.has(this.#map, old);
324
+ }
325
+ #next() {
326
+ return `${this.prefix}${this.#counter++}`;
327
+ }
328
+ };
329
+ // src/jsonld/internal/context.ts
330
+ /**
331
+ * Context processing and IRI expansion (JSON-LD 1.1 API §4.1, §4.2, §5.2).
332
+ *
333
+ * @internal
334
+ */
335
+ /** @internal */
336
+ var NeedDocument = class {
337
+ url;
338
+ constructor(url) {
339
+ this.url = url;
340
+ }
341
+ };
342
+ /** @internal */
343
+ const initialContext = (base) => ({
344
+ base,
345
+ originalBase: base,
346
+ terms: MutableHashMap.empty()
347
+ });
348
+ /**
349
+ * The definition of `term` in the active context.
350
+ *
351
+ * @internal
352
+ */
353
+ const termOf = (active, term) => Option.fromUndefinedOr(active.terms.backing.get(term));
354
+ /**
355
+ * The definition of `term`, when it carries a scoped context.
356
+ *
357
+ * @internal
358
+ */
359
+ const scopedTermOf = (active, term) => Option.filter(termOf(active, term), (def) => def.hasContext);
360
+ const cloneContext = (ctx) => {
361
+ const out = {
362
+ base: ctx.base,
363
+ originalBase: ctx.originalBase,
364
+ terms: MutableHashMap.fromIterable(ctx.terms)
365
+ };
366
+ if (ctx.vocab !== void 0) out.vocab = ctx.vocab;
367
+ if (ctx.language !== void 0) out.language = ctx.language;
368
+ if (ctx.direction !== void 0) out.direction = ctx.direction;
369
+ if (ctx.previous !== void 0) out.previous = ctx.previous;
370
+ return out;
371
+ };
372
+ const MAX_REMOTE_CONTEXTS = 32;
373
+ /** Loads a remote context document, failing with `loading remote context failed`. */
374
+ const loadContextDocument = (env, url) => mapJsonLdError(() => env.load(url, "http://www.w3.org/ns/json-ld#context"), (e) => fail("loading remote context failed", `${url}: ${e.message}`));
375
+ /**
376
+ * Applies the type-scoped context of each term (in the given order) that
377
+ * defines one, as expansion step 11 and compaction step 11 do.
378
+ *
379
+ * @internal
380
+ */
381
+ const applyTypeScopedContexts = (env, active, typeScoped, terms) => terms.reduce((result, term) => Option.match(scopedTermOf(typeScoped, term), {
382
+ onNone: () => result,
383
+ onSome: (def) => processContext(env, result, def.context, def.baseUrl ?? null, [], false, false)
384
+ }), active);
385
+ /** Loads a remote context (once per run), failing with `invalid remote context`. */
386
+ const remoteContext = (env, url) => Option.getOrElse(MutableHashMap.get(env.contextCache, url), () => {
387
+ const doc = loadContextDocument(env, url);
388
+ if (!isObject(doc.document) || !("@context" in doc.document)) fail("invalid remote context", url);
389
+ const loaded = {
390
+ context: doc.document["@context"],
391
+ documentUrl: doc.documentUrl
392
+ };
393
+ MutableHashMap.set(env.contextCache, url, loaded);
394
+ return loaded;
395
+ });
396
+ /**
397
+ * Context Processing Algorithm.
398
+ *
399
+ * @internal
400
+ */
401
+ const processContext = (env, active, localContext, baseUrl, remoteContexts = [], overrideProtected = false, propagate = true, validateScoped = true) => {
402
+ let result = cloneContext(active);
403
+ if (isObject(localContext) && "@propagate" in localContext) {
404
+ if (!Predicate.isBoolean(localContext["@propagate"])) fail("invalid @propagate value");
405
+ propagate = localContext["@propagate"];
406
+ }
407
+ if (!propagate && result.previous === void 0) result.previous = active;
408
+ (Array.isArray(localContext) ? localContext : [localContext]).forEach((context) => {
409
+ if (context === null) {
410
+ result = nullified(active, result, overrideProtected, propagate);
411
+ return;
412
+ }
413
+ if (isString$1(context)) {
414
+ const url = resolveIri(context, baseUrl);
415
+ if (!validateScoped && remoteContexts.includes(url)) return;
416
+ if (remoteContexts.length > MAX_REMOTE_CONTEXTS) fail("context overflow");
417
+ const loaded = remoteContext(env, url);
418
+ result = processContext(env, result, loaded.context, loaded.documentUrl, [...remoteContexts, url], overrideProtected, true, validateScoped);
419
+ return;
420
+ }
421
+ processLocalContext(env, result, context, baseUrl, remoteContexts, overrideProtected, validateScoped);
422
+ });
423
+ return result;
424
+ };
425
+ /** Context processing step 5.1: a `null` context resets the active context. */
426
+ const nullified = (active, result, overrideProtected, propagate) => {
427
+ if (!overrideProtected && Iterable.some(MutableHashMap.values(result.terms), (def) => def.protected)) fail("invalid context nullification");
428
+ const reset = initialContext(active.originalBase);
429
+ if (!propagate) reset.previous = result;
430
+ return reset;
431
+ };
432
+ /** Steps 5.3 - 5.13: a context definition (an object) updates `result` in place. */
433
+ const processLocalContext = (env, result, definition, baseUrl, remoteContexts, overrideProtected, validateScoped) => {
434
+ if (!isObject(definition)) fail("invalid local context");
435
+ checkVersion(env, definition);
436
+ const context = withImport(env, definition, baseUrl);
437
+ if ("@base" in context && Arr.isReadonlyArrayEmpty(remoteContexts)) setBase(result, context["@base"]);
438
+ if ("@vocab" in context) setVocab(env, result, context["@vocab"]);
439
+ setLanguageAndDirection(env, result, context);
440
+ checkFlags(env, context);
441
+ const state = {
442
+ defined: MutableHashMap.empty(),
443
+ baseUrl,
444
+ protected: context["@protected"] === true,
445
+ overrideProtected,
446
+ remoteContexts,
447
+ validateScoped
448
+ };
449
+ Record.keys(context).forEach((key) => {
450
+ if (!isContextKeyword(key)) createTermDefinition(env, result, context, key, state);
451
+ });
452
+ };
453
+ /** Step 5.5: `@version`. */
454
+ const checkVersion = (env, context) => {
455
+ if (!("@version" in context)) return;
456
+ if (context["@version"] !== 1.1) fail("invalid @version value");
457
+ if (env.processingMode === "json-ld-1.0") fail("processing mode conflict");
458
+ };
459
+ /** Step 5.6: the context merged over the one its `@import` names. */
460
+ const withImport = (env, context, baseUrl) => {
461
+ if (!("@import" in context)) return context;
462
+ if (env.processingMode === "json-ld-1.0") fail("invalid context entry");
463
+ const imp = context["@import"];
464
+ if (!isString$1(imp)) fail("invalid @import value");
465
+ const url = resolveIri(imp, baseUrl);
466
+ const doc = loadContextDocument(env, url);
467
+ if (!isObject(doc.document) || !isObject(doc.document["@context"])) fail("invalid remote context", url);
468
+ const importContext = doc.document["@context"];
469
+ if ("@import" in importContext) fail("invalid context entry");
470
+ return {
471
+ ...importContext,
472
+ ...context
473
+ };
474
+ };
475
+ /** Step 5.7: `@base`. */
476
+ const setBase = (result, value) => {
477
+ if (value === null) result.base = null;
478
+ else if (!isString$1(value)) fail("invalid base IRI");
479
+ else if (isAbsoluteIri(value)) result.base = value;
480
+ else if (result.base !== null) result.base = resolveIri(value, result.base);
481
+ else fail("invalid base IRI");
482
+ };
483
+ /** Step 5.8: `@vocab`. */
484
+ const setVocab = (env, result, value) => {
485
+ if (value === null) {
486
+ delete result.vocab;
487
+ return;
488
+ }
489
+ if (!isString$1(value)) fail("invalid vocab mapping");
490
+ if (env.processingMode === "json-ld-1.0" && !isAbsoluteIri(value) && !isBlankNodeId(value)) fail("invalid vocab mapping");
491
+ const expanded = expandIri(env, result, value, true, true);
492
+ if (expanded === null || isKeyword(expanded)) fail("invalid vocab mapping");
493
+ result.vocab = expanded;
494
+ };
495
+ /** Steps 5.9 and 5.10: `@language` and `@direction`. */
496
+ const setLanguageAndDirection = (env, result, context) => {
497
+ if ("@language" in context) {
498
+ const value = context["@language"];
499
+ if (value === null) delete result.language;
500
+ else if (!isString$1(value)) fail("invalid default language");
501
+ else result.language = value;
502
+ }
503
+ if ("@direction" in context) {
504
+ if (env.processingMode === "json-ld-1.0") fail("invalid context entry");
505
+ const value = context["@direction"];
506
+ if (value === null) delete result.direction;
507
+ else if (value !== "ltr" && value !== "rtl") fail("invalid base direction");
508
+ else result.direction = value;
509
+ }
510
+ };
511
+ /** Step 5.11, and the `@protected` flag. */
512
+ const checkFlags = (env, context) => {
513
+ if ("@propagate" in context) {
514
+ if (env.processingMode === "json-ld-1.0") fail("invalid context entry");
515
+ if (!Predicate.isBoolean(context["@propagate"])) fail("invalid @propagate value");
516
+ }
517
+ if ("@protected" in context && !Predicate.isBoolean(context["@protected"])) fail("invalid @protected value");
518
+ };
519
+ const isContextKeyword = stringSet([
520
+ "@base",
521
+ "@direction",
522
+ "@import",
523
+ "@language",
524
+ "@propagate",
525
+ "@protected",
526
+ "@version",
527
+ "@vocab"
528
+ ]);
529
+ const isTermKey = stringSet([
530
+ "@id",
531
+ "@reverse",
532
+ "@container",
533
+ "@context",
534
+ "@direction",
535
+ "@index",
536
+ "@language",
537
+ "@nest",
538
+ "@prefix",
539
+ "@protected",
540
+ "@type"
541
+ ]);
542
+ const GEN_DELIMS = /[:/?#[\]@]$/;
543
+ const isContainerKeyword = stringSet([
544
+ "@graph",
545
+ "@id",
546
+ "@index",
547
+ "@language",
548
+ "@list",
549
+ "@set",
550
+ "@type"
551
+ ]);
552
+ const validContainer = (env, value) => {
553
+ if (env.processingMode === "json-ld-1.0") return isString$1(value) && [
554
+ "@list",
555
+ "@set",
556
+ "@index",
557
+ "@language"
558
+ ].includes(value);
559
+ const c = Array.isArray(value) ? value : [value];
560
+ if (Arr.isReadonlyArrayEmpty(c)) return false;
561
+ if (!c.every((x) => isString$1(x) && isContainerKeyword(x))) return false;
562
+ if (c.some((x, i) => c.indexOf(x) !== i)) return false;
563
+ if (c.includes("@list")) return c.length === 1;
564
+ if (c.includes("@graph")) {
565
+ if (c.includes("@id") && c.includes("@index")) return false;
566
+ return c.every((x) => x === "@graph" || x === "@id" || x === "@index" || x === "@set");
567
+ }
568
+ if (c.length === 1) return true;
569
+ return c.length === 2 && c.includes("@set");
570
+ };
571
+ /**
572
+ * Create Term Definition algorithm.
573
+ *
574
+ * @internal
575
+ */
576
+ const createTermDefinition = (env, active, local, term, state) => {
577
+ const { defined, baseUrl, overrideProtected, remoteContexts } = state;
578
+ const status = MutableHashMap.get(defined, term);
579
+ if (Option.isSome(status)) {
580
+ if (status.value) return;
581
+ fail("cyclic IRI mapping", term);
582
+ }
583
+ if (term === "") fail("invalid term definition", "empty term");
584
+ MutableHashMap.set(defined, term, false);
585
+ let value = local[term];
586
+ if (term === "@type" && env.processingMode !== "json-ld-1.0" && isObject(value)) {
587
+ const keys = Record.keys(value);
588
+ if (Arr.isReadonlyArrayEmpty(keys) || keys.some((k) => k !== "@container" && k !== "@protected") || "@container" in value && value["@container"] !== "@set") fail("keyword redefinition", term);
589
+ } else if (isKeyword(term)) fail("keyword redefinition", term);
590
+ else if (hasKeywordForm(term)) {
591
+ MutableHashMap.set(defined, term, true);
592
+ return;
593
+ }
594
+ const previous = termOf(active, term);
595
+ MutableHashMap.remove(active.terms, term);
596
+ let simpleTerm = false;
597
+ if (value === null) value = { "@id": null };
598
+ else if (isString$1(value)) {
599
+ value = { "@id": value };
600
+ simpleTerm = true;
601
+ } else if (!isObject(value)) fail("invalid term definition", term);
602
+ const def = {
603
+ iri: null,
604
+ reverse: false,
605
+ hasContext: false,
606
+ container: [],
607
+ prefix: false,
608
+ protected: state.protected,
609
+ hasColon: term.indexOf(":", 1) !== -1
610
+ };
611
+ if ("@protected" in value) {
612
+ if (env.processingMode === "json-ld-1.0") fail("invalid term definition");
613
+ if (!Predicate.isBoolean(value["@protected"])) fail("invalid @protected value");
614
+ def.protected = value["@protected"];
615
+ }
616
+ if ("@type" in value) {
617
+ const type = value["@type"];
618
+ if (!isString$1(type)) fail("invalid type mapping");
619
+ const expanded = expandIri(env, active, type, true, false, local, state);
620
+ if (expanded === "@json" || expanded === "@none") {
621
+ if (env.processingMode === "json-ld-1.0") fail("invalid type mapping");
622
+ } else if (expanded === null || expanded !== "@id" && expanded !== "@vocab" && !isAbsoluteIri(expanded) || isBlankNodeId(expanded)) fail("invalid type mapping", type);
623
+ def.type = expanded;
624
+ }
625
+ if ("@reverse" in value) {
626
+ if ("@id" in value || "@nest" in value) fail("invalid reverse property");
627
+ const rev = value["@reverse"];
628
+ if (!isString$1(rev)) fail("invalid IRI mapping");
629
+ if (hasKeywordForm(rev)) {
630
+ MutableHashMap.set(defined, term, true);
631
+ return;
632
+ }
633
+ const iri = expandIri(env, active, rev, true, false, local, state);
634
+ if (iri === null || !isAbsoluteIri(iri) && !isBlankNodeId(iri)) fail("invalid IRI mapping");
635
+ def.iri = iri;
636
+ if ("@container" in value) {
637
+ const c = value["@container"];
638
+ if (c !== null && c !== "@set" && c !== "@index") fail("invalid reverse property");
639
+ if (c !== null) def.container = [c];
640
+ }
641
+ def.reverse = true;
642
+ } else if ("@id" in value && value["@id"] !== term) {
643
+ const id = value["@id"];
644
+ if (id === null) def.iri = null;
645
+ else {
646
+ if (!isString$1(id)) fail("invalid IRI mapping");
647
+ if (!isKeyword(id) && hasKeywordForm(id)) {
648
+ MutableHashMap.set(defined, term, true);
649
+ return;
650
+ }
651
+ const iri = expandIri(env, active, id, true, false, local, state);
652
+ if (iri === null || !isKeyword(iri) && !isAbsoluteIri(iri) && !isBlankNodeId(iri)) fail("invalid IRI mapping", id);
653
+ if (iri === "@context") fail("invalid keyword alias");
654
+ def.iri = iri;
655
+ if (term.slice(1, -1).includes(":") || term.includes("/")) {
656
+ MutableHashMap.set(defined, term, true);
657
+ if (expandIri(env, active, term, true, false, local, state) !== iri) fail("invalid IRI mapping", term);
658
+ }
659
+ if (!term.includes(":") && !term.includes("/") && simpleTerm) {
660
+ if (GEN_DELIMS.test(iri) || isBlankNodeId(iri)) def.prefix = true;
661
+ }
662
+ }
663
+ } else if (term.indexOf(":", 1) !== -1) {
664
+ const i = term.indexOf(":");
665
+ const prefix = term.slice(0, i);
666
+ const suffix = term.slice(i + 1);
667
+ if (prefix !== "_" && !suffix.startsWith("//") && hasOwn(local, prefix)) createTermDefinition(env, active, local, prefix, state);
668
+ const prefixIri = prefix === "_" ? null : Option.getOrNull(Option.map(termOf(active, prefix), (d) => d.iri));
669
+ def.iri = prefixIri === null ? term : prefixIri + suffix;
670
+ } else if (term.includes("/")) {
671
+ const iri = expandIri(env, active, term, true);
672
+ if (iri === null || !isAbsoluteIri(iri)) fail("invalid IRI mapping", term);
673
+ def.iri = iri;
674
+ } else if (term === "@type") def.iri = "@type";
675
+ else if (active.vocab !== void 0) def.iri = active.vocab + term;
676
+ else fail("invalid IRI mapping", term);
677
+ if ("@container" in value && !def.reverse) {
678
+ const c = value["@container"];
679
+ if (!validContainer(env, c)) fail("invalid container mapping");
680
+ def.container = Array.isArray(c) ? [...c] : [c];
681
+ if (def.container.includes("@type")) {
682
+ if (def.type === void 0) def.type = "@id";
683
+ if (def.type !== "@id" && def.type !== "@vocab") fail("invalid type mapping");
684
+ }
685
+ }
686
+ if ("@index" in value) {
687
+ if (env.processingMode === "json-ld-1.0" || !def.container.includes("@index")) fail("invalid term definition");
688
+ const index = value["@index"];
689
+ if (!isString$1(index)) fail("invalid term definition");
690
+ const expanded = expandIri(env, active, index, true, false, local, state);
691
+ if (expanded === null || isKeyword(expanded) || !isAbsoluteIri(expanded)) fail("invalid term definition");
692
+ def.index = index;
693
+ }
694
+ if ("@context" in value) {
695
+ if (env.processingMode === "json-ld-1.0") fail("invalid term definition");
696
+ const ctx = value["@context"];
697
+ mapJsonLdError(() => processContext(env, active, ctx, baseUrl, remoteContexts, true, true, false), (e) => fail("invalid scoped context", e.message));
698
+ def.context = ctx;
699
+ def.hasContext = true;
700
+ def.baseUrl = baseUrl;
701
+ }
702
+ if ("@language" in value && !("@type" in value)) {
703
+ const lang = value["@language"];
704
+ if (lang !== null && !isString$1(lang)) fail("invalid language mapping");
705
+ def.language = lang;
706
+ }
707
+ if ("@direction" in value && !("@type" in value)) {
708
+ const dir = value["@direction"];
709
+ if (dir !== null && dir !== "ltr" && dir !== "rtl") fail("invalid base direction");
710
+ def.direction = dir;
711
+ }
712
+ if ("@nest" in value) {
713
+ if (env.processingMode === "json-ld-1.0") fail("invalid term definition");
714
+ const nest = value["@nest"];
715
+ if (!isString$1(nest) || isKeyword(nest) && nest !== "@nest") fail("invalid @nest value");
716
+ def.nest = nest;
717
+ }
718
+ if ("@prefix" in value) {
719
+ if (env.processingMode === "json-ld-1.0" || term.includes(":") || term.includes("/")) fail("invalid term definition");
720
+ const p = value["@prefix"];
721
+ if (!Predicate.isBoolean(p)) fail("invalid @prefix value");
722
+ def.prefix = p;
723
+ if (p && def.iri !== null && isKeyword(def.iri)) fail("invalid term definition");
724
+ }
725
+ checkTermKeys(value);
726
+ finishDefinition(active, term, def, previous, overrideProtected, defined);
727
+ };
728
+ const checkTermKeys = (value) => {
729
+ Record.keys(value).forEach((k) => {
730
+ if (!isTermKey(k)) fail("invalid term definition", k);
731
+ });
732
+ };
733
+ const finishDefinition = (active, term, def, previous, overrideProtected, defined) => {
734
+ const kept = Option.filter(previous, (p) => !overrideProtected && p.protected);
735
+ if (Option.isSome(kept) && !sameDefinition(def, kept.value)) fail("protected term redefinition", term);
736
+ MutableHashMap.set(active.terms, term, Option.getOrElse(kept, () => def));
737
+ MutableHashMap.set(defined, term, true);
738
+ };
739
+ /** Whether the definition of `term` is still to be created from `local` (§4.2, step 3). */
740
+ const isPending = (local, state, term) => hasOwn(local, term) && !Option.getOrElse(MutableHashMap.get(state.defined, term), () => false);
741
+ const sameDefinition = (a, b) => a.iri === b.iri && a.reverse === b.reverse && a.type === b.type && a.language === b.language && "language" in a === "language" in b && a.direction === b.direction && "direction" in a === "direction" in b && a.hasContext === b.hasContext && deepEqual(a.context, b.context) && a.container.length === b.container.length && a.container.every((c) => b.container.includes(c)) && a.index === b.index && a.nest === b.nest && a.prefix === b.prefix;
742
+ /**
743
+ * IRI Expansion algorithm.
744
+ *
745
+ * @internal
746
+ */
747
+ const expandIri = (env, active, value, vocab = false, documentRelative = false, local, state) => {
748
+ if (value === null || isKeyword(value)) return value;
749
+ if (hasKeywordForm(value)) return null;
750
+ if (local !== void 0 && state !== void 0 && isPending(local, state, value)) createTermDefinition(env, active, local, value, state);
751
+ const def = termOf(active, value);
752
+ if (Option.isSome(def)) {
753
+ const iri = def.value.iri;
754
+ if (iri !== null && isKeyword(iri)) return iri;
755
+ if (vocab) return iri;
756
+ }
757
+ const colon = value.indexOf(":", 1);
758
+ if (colon !== -1) {
759
+ const prefix = value.slice(0, colon);
760
+ const suffix = value.slice(colon + 1);
761
+ if (prefix === "_" || suffix.startsWith("//")) return value;
762
+ if (local !== void 0 && state !== void 0 && isPending(local, state, prefix)) createTermDefinition(env, active, local, prefix, state);
763
+ const prefixDef = termOf(active, prefix);
764
+ if (Option.isSome(prefixDef) && prefixDef.value.iri !== null && prefixDef.value.prefix) return prefixDef.value.iri + suffix;
765
+ if (isAbsoluteIri(value)) return value;
766
+ }
767
+ if (vocab && active.vocab !== void 0) return active.vocab + value;
768
+ if (documentRelative) return resolveIri(value, active.base);
769
+ return value;
770
+ };
771
+ // src/jsonld/internal/compact.ts
772
+ /**
773
+ * Compaction Algorithms (JSON-LD 1.1 API §6).
774
+ *
775
+ * @internal
776
+ */
777
+ /** The definition of `term`, read where a missing definition reads as its defaults. */
778
+ const definitionOf = (active, term) => active.terms.backing.get(term);
779
+ /**
780
+ * Compaction Algorithm.
781
+ *
782
+ * @internal
783
+ */
784
+ const compactElement = (env, active, activeProperty, element, options) => {
785
+ const typeScoped = active;
786
+ if (isScalar(element) || element === null) return element;
787
+ if (Array.isArray(element)) {
788
+ const result = [];
789
+ element.forEach((item) => {
790
+ const compacted = compactElement(env, active, activeProperty, item, options);
791
+ if (compacted !== null) result.push(compacted);
792
+ });
793
+ const container = activeContainer(active, activeProperty);
794
+ if (result.length !== 1 || !options.compactArrays || isProperty(activeProperty, "@graph") || isProperty(activeProperty, "@set") || container.includes("@list") || container.includes("@set")) return result;
795
+ return result[0];
796
+ }
797
+ const propDef = activeDefinition(active, activeProperty);
798
+ if (active.previous !== void 0) {
799
+ const keys = Record.keys(element);
800
+ if (!("@value" in element) && !(keys.length === 1 && keys[0] === "@id")) active = active.previous;
801
+ }
802
+ if (propDef?.hasContext === true) active = processContext(env, active, propDef.context, propDef.baseUrl ?? null, [], true);
803
+ if ("@value" in element || "@id" in element) {
804
+ const compacted = compactValue(env, active, activeProperty, element, options);
805
+ if (isScalar(compacted) || compacted === null || propDef?.type === "@json") {
806
+ if (isScalar(compacted) || propDef?.type === "@json") return compacted;
807
+ }
808
+ }
809
+ if (isListObject(element) && activeContainer(active, activeProperty).includes("@list")) return compactElement(env, active, activeProperty, element["@list"], options);
810
+ const insideReverse = isProperty(activeProperty, "@reverse");
811
+ const result = {};
812
+ if ("@type" in element) {
813
+ const compactedTypes = Arr.sort(asArray(element["@type"]).map((t) => compactIri(env, typeScoped, t, null, true, false, options)), compareStrings);
814
+ active = applyTypeScopedContexts(env, active, typeScoped, compactedTypes);
815
+ }
816
+ const scope = {
817
+ env,
818
+ active,
819
+ typeScoped,
820
+ activeProperty,
821
+ options,
822
+ result,
823
+ insideReverse
824
+ };
825
+ (options.ordered ? Arr.sort(Record.keys(element), compareStrings) : Record.keys(element)).forEach((expandedProperty) => {
826
+ const expandedValue = element[expandedProperty];
827
+ if (!compactKeywordEntry(scope, expandedProperty, expandedValue)) compactPropertyEntry(scope, expandedProperty, expandedValue);
828
+ });
829
+ return result;
830
+ };
831
+ /** The IRI compaction of a keyword (as a vocabulary term) in the active context. */
832
+ const aliasOf = (scope, keyword) => compactIri(scope.env, scope.active, keyword, null, true, false, scope.options);
833
+ /** Steps 12.1 - 12.6: a keyword entry. Returns false for an entry they leave to 12.7. */
834
+ const compactKeywordEntry = (scope, expandedProperty, expandedValue) => {
835
+ const { env, active, activeProperty, options, result } = scope;
836
+ if (expandedProperty === "@id") result[aliasOf(scope, "@id")] = isString$1(expandedValue) ? compactIri(env, active, expandedValue, null, false, false, options) : expandedValue;
837
+ else if (expandedProperty === "@type") compactTypeEntry(scope, expandedValue);
838
+ else if (expandedProperty === "@reverse") compactReverseEntry(scope, expandedValue);
839
+ else if (expandedProperty === "@preserve") {
840
+ const compactedValue = compactElement(env, active, activeProperty, expandedValue, options);
841
+ if (!(Array.isArray(expandedValue) && Arr.isReadonlyArrayEmpty(expandedValue))) result["@preserve"] = compactedValue;
842
+ } else if (expandedProperty === "@index") {
843
+ if (!activeContainer(active, activeProperty).includes("@index")) result[aliasOf(scope, expandedProperty)] = expandedValue;
844
+ } else if (expandedProperty === "@direction" || expandedProperty === "@language" || expandedProperty === "@value") result[aliasOf(scope, expandedProperty)] = expandedValue;
845
+ else return false;
846
+ return true;
847
+ };
848
+ /** Step 12.2: `@type`. */
849
+ const compactTypeEntry = (scope, expandedValue) => {
850
+ const { env, active, typeScoped, options, result } = scope;
851
+ const types = isString$1(expandedValue) ? [] : expandedValue;
852
+ const compactedValue = isString$1(expandedValue) ? compactIri(env, typeScoped, expandedValue, null, true, false, options) : types.map((t) => compactIri(env, typeScoped, t, null, true, false, options));
853
+ const alias = aliasOf(scope, "@type");
854
+ const asArr = env.processingMode !== "json-ld-1.0" && containerOf(active, alias).includes("@set") || !options.compactArrays;
855
+ addValue(result, alias, compactedValue, asArr);
856
+ if (!asArr && Array.isArray(result[alias]) && result[alias].length === 1) result[alias] = result[alias][0];
857
+ };
858
+ /** Step 12.3: `@reverse`. */
859
+ const compactReverseEntry = (scope, expandedValue) => {
860
+ const { env, active, options, result } = scope;
861
+ const compactedValue = compactElement(env, active, REVERSE_PROPERTY, expandedValue, options);
862
+ Record.keys(compactedValue).forEach((property) => {
863
+ const def = definitionOf(active, property);
864
+ if (def?.reverse === true) {
865
+ const asArr = def.container.includes("@set") || !options.compactArrays;
866
+ addValue(result, property, compactedValue[property], asArr);
867
+ delete compactedValue[property];
868
+ }
869
+ });
870
+ if (Arr.isReadonlyArrayNonEmpty(Record.keys(compactedValue))) result[aliasOf(scope, "@reverse")] = compactedValue;
871
+ };
872
+ /** Steps 12.7 and 12.8: a property entry. */
873
+ const compactPropertyEntry = (scope, expandedProperty, expandedValue) => {
874
+ const { env, active, options, result, insideReverse } = scope;
875
+ if (Array.isArray(expandedValue) && Arr.isReadonlyArrayEmpty(expandedValue)) {
876
+ const itemActiveProperty = compactIri(env, active, expandedProperty, expandedValue, true, insideReverse, options);
877
+ const nestResult = nestResultFor(env, active, result, itemActiveProperty, options);
878
+ addValue(nestResult, itemActiveProperty, [], true);
879
+ }
880
+ asArray(expandedValue).forEach((expandedItem) => compactPropertyItem(scope, expandedProperty, expandedItem));
881
+ };
882
+ /** Step 12.8: one item of a property entry. */
883
+ const compactPropertyItem = (scope, expandedProperty, expandedItem) => {
884
+ const { env, active, options, result, insideReverse } = scope;
885
+ const property = compactIri(env, active, expandedProperty, expandedItem, true, insideReverse, options);
886
+ const container = containerOf(active, property);
887
+ const target = {
888
+ property,
889
+ nestResult: nestResultFor(env, active, result, property, options),
890
+ container,
891
+ asArr: container.includes("@set") || property === "@graph" || property === "@list" || !options.compactArrays
892
+ };
893
+ const inner = isListObject(expandedItem) ? expandedItem["@list"] : isGraphObject(expandedItem) ? expandedItem["@graph"] : expandedItem;
894
+ const compactedItem = compactElement(env, active, Option.some(property), inner, options);
895
+ if (isListObject(expandedItem)) compactListItem(scope, target, expandedItem, compactedItem);
896
+ else if (isGraphObject(expandedItem)) compactGraphItem(scope, target, expandedItem, compactedItem);
897
+ else if ((container.includes("@language") || container.includes("@index") || container.includes("@id") || container.includes("@type")) && !container.includes("@graph")) compactMapItem(scope, target, expandedItem, compactedItem);
898
+ else addValue(target.nestResult, property, compactedItem, target.asArr);
899
+ };
900
+ /** Step 12.8.7: a list object. */
901
+ const compactListItem = (scope, target, expandedItem, compacted) => {
902
+ const items = asArray(compacted);
903
+ if (target.container.includes("@list")) {
904
+ target.nestResult[target.property] = items;
905
+ return;
906
+ }
907
+ const compactedItem = { [aliasOf(scope, "@list")]: items };
908
+ if ("@index" in expandedItem) compactedItem[aliasOf(scope, "@index")] = expandedItem["@index"];
909
+ addValue(target.nestResult, target.property, compactedItem, target.asArr);
910
+ };
911
+ /** Step 12.8.8: a graph object. */
912
+ const compactGraphItem = (scope, target, expandedItem, compactedItem) => {
913
+ const { env, active, options } = scope;
914
+ const { container, nestResult, property, asArr } = target;
915
+ if (container.includes("@graph") && container.includes("@id")) {
916
+ const mapObject = getOrInit(nestResult, property, () => ({}));
917
+ const mapKey = "@id" in expandedItem ? compactIri(env, active, expandedItem["@id"], null, false, false, options) : aliasOf(scope, "@none");
918
+ addValue(mapObject, mapKey, compactedItem, asArr);
919
+ } else if (container.includes("@graph") && container.includes("@index") && isSimpleGraphObject(expandedItem)) {
920
+ const mapObject = getOrInit(nestResult, property, () => ({}));
921
+ const mapKey = "@index" in expandedItem ? expandedItem["@index"] : aliasOf(scope, "@none");
922
+ addValue(mapObject, mapKey, compactedItem, asArr);
923
+ } else if (container.includes("@graph") && isSimpleGraphObject(expandedItem)) {
924
+ const value = Array.isArray(compactedItem) && compactedItem.length > 1 ? { [aliasOf(scope, "@included")]: compactedItem } : compactedItem;
925
+ addValue(nestResult, property, value, asArr);
926
+ } else {
927
+ const value = { [aliasOf(scope, "@graph")]: compactedItem };
928
+ if ("@id" in expandedItem) value[aliasOf(scope, "@id")] = compactIri(env, active, expandedItem["@id"], null, false, false, options);
929
+ if ("@index" in expandedItem) value[aliasOf(scope, "@index")] = expandedItem["@index"];
930
+ addValue(nestResult, property, value, asArr);
931
+ }
932
+ };
933
+ /** Step 12.8.9: an item of a language, index, id or type map. */
934
+ const compactMapItem = (scope, target, expandedItem, compactedItem) => {
935
+ const { container, nestResult, property, asArr } = target;
936
+ const mapObject = getOrInit(nestResult, property, () => ({}));
937
+ const indexKey = definitionOf(scope.active, property)?.index ?? "@index";
938
+ let entry;
939
+ if (container.includes("@language") && "@value" in expandedItem) entry = {
940
+ key: expandedItem["@language"],
941
+ value: expandedItem["@value"]
942
+ };
943
+ else if (container.includes("@language")) entry = typeMapEntry(scope, target, expandedItem, compactedItem, "@language");
944
+ else if (container.includes("@index") && indexKey === "@index") entry = {
945
+ key: expandedItem["@index"],
946
+ value: compactedItem
947
+ };
948
+ else if (container.includes("@index")) entry = indexPropertyEntry(scope, indexKey, compactedItem);
949
+ else if (container.includes("@id")) {
950
+ const idKey = aliasOf(scope, "@id");
951
+ entry = {
952
+ key: compactedItem[idKey],
953
+ value: compactedItem
954
+ };
955
+ delete compactedItem[idKey];
956
+ } else entry = typeMapEntry(scope, target, expandedItem, compactedItem, "@type");
957
+ const key = entry.key === void 0 || entry.key === null ? aliasOf(scope, "@none") : entry.key;
958
+ addValue(mapObject, key, entry.value, asArr);
959
+ };
960
+ /** Step 12.8.9.8: an index map on a property (`@index` names a property). */
961
+ const indexPropertyEntry = (scope, indexKey, compactedItem) => {
962
+ const { env, active } = scope;
963
+ const containerKey = isObject(compactedItem) && hasOwn(compactedItem, indexKey) ? indexKey : aliasOf(scope, expandIri(env, active, indexKey, true) ?? indexKey);
964
+ const values = isObject(compactedItem) ? asArray(compactedItem[containerKey] ?? []) : [];
965
+ const key = Arr.isReadonlyArrayNonEmpty(values) && isString$1(values[0]) ? values[0] : void 0;
966
+ if (key !== void 0) {
967
+ const rest = values.slice(1);
968
+ delete compactedItem[containerKey];
969
+ if (Arr.isReadonlyArrayNonEmpty(rest)) addValue(compactedItem, containerKey, rest, false);
970
+ }
971
+ return {
972
+ key,
973
+ value: compactedItem
974
+ };
975
+ };
976
+ /** Step 12.8.9.10: a type map (the map's keys are the values of `keyword`). */
977
+ const typeMapEntry = (scope, target, expandedItem, compactedItem, keyword) => {
978
+ const { env, active, options } = scope;
979
+ const containerKey = aliasOf(scope, keyword);
980
+ const values = asArray(compactedItem[containerKey] ?? []);
981
+ const rest = values.slice(1);
982
+ delete compactedItem[containerKey];
983
+ if (Arr.isReadonlyArrayNonEmpty(rest)) addValue(compactedItem, containerKey, rest, false);
984
+ if (rest.length === 1 && Array.isArray(compactedItem[containerKey])) compactedItem[containerKey] = compactedItem[containerKey][0];
985
+ const remaining = Record.keys(compactedItem);
986
+ const [only] = remaining;
987
+ const onlyId = remaining.length === 1 && only !== void 0 && expandIri(env, active, only, true) === "@id" && "@id" in expandedItem;
988
+ return {
989
+ key: values[0],
990
+ value: onlyId ? compactElement(env, active, Option.some(target.property), { "@id": expandedItem["@id"] }, options) : compactedItem
991
+ };
992
+ };
993
+ const nestResultFor = (env, active, result, itemActiveProperty, options) => {
994
+ const nestTerm = definitionOf(active, itemActiveProperty)?.nest;
995
+ if (nestTerm === void 0) return result;
996
+ if (nestTerm !== "@nest" && expandIri(env, active, nestTerm, true) !== "@nest") fail("invalid @nest value");
997
+ if (!isObject(result[nestTerm])) result[nestTerm] = {};
998
+ return result[nestTerm];
999
+ };
1000
+ /** @internal */
1001
+ const containerOf = (active, term) => definitionOf(active, term)?.container ?? [];
1002
+ /** The definition of the active property (none at the top level). */
1003
+ const activeDefinition = (active, activeProperty) => Option.isNone(activeProperty) ? void 0 : definitionOf(active, activeProperty.value);
1004
+ /** The container mapping of the active property (none at the top level). */
1005
+ const activeContainer = (active, activeProperty) => activeDefinition(active, activeProperty)?.container ?? [];
1006
+ /** Term definitions ordered by their term: shortest first, then lexicographically. */
1007
+ const shortestTermFirst = Order.mapInput(Order.combine(Order.mapInput(Order.Number, (term) => term.length), compareStrings), ([term]) => term);
1008
+ const emptyEntry = (term) => {
1009
+ return {
1010
+ "@language": Object.create(null),
1011
+ "@type": Object.create(null),
1012
+ "@any": { "@none": term }
1013
+ };
1014
+ };
1015
+ /**
1016
+ * Inverse Context Creation algorithm.
1017
+ *
1018
+ * @internal
1019
+ */
1020
+ const inverseContext = (active) => {
1021
+ if (active.inverse !== void 0) return active.inverse;
1022
+ const result = MutableHashMap.empty();
1023
+ const defaultLanguage = active.language !== void 0 ? active.language.toLowerCase() : "@none";
1024
+ Arr.sort(active.terms, shortestTermFirst).forEach(([term, def]) => {
1025
+ const iri = def.iri;
1026
+ if (iri === null) return;
1027
+ const container = Arr.isReadonlyArrayEmpty(def.container) ? "@none" : Arr.sort(def.container, Order.String).join("");
1028
+ const containerMap = Option.getOrElse(MutableHashMap.get(result, iri), () => {
1029
+ const created = Object.create(null);
1030
+ MutableHashMap.set(result, iri, created);
1031
+ return created;
1032
+ });
1033
+ const entry = containerMap[container] ?? emptyEntry(term);
1034
+ containerMap[container] = entry;
1035
+ const typeMap = entry["@type"];
1036
+ const languageMap = entry["@language"];
1037
+ if (def.reverse) typeMap["@reverse"] ??= term;
1038
+ else if (def.type === "@none") {
1039
+ languageMap["@any"] ??= term;
1040
+ typeMap["@any"] ??= term;
1041
+ } else if (def.type !== void 0) typeMap[def.type] ??= term;
1042
+ else if ("language" in def && "direction" in def) {
1043
+ let langDir;
1044
+ if (def.language != null && def.direction != null) langDir = `${def.language}_${def.direction}`.toLowerCase();
1045
+ else if (def.language != null) langDir = def.language.toLowerCase();
1046
+ else if (def.direction != null) langDir = `_${def.direction}`;
1047
+ else langDir = "@null";
1048
+ languageMap[langDir] ??= term;
1049
+ } else if ("language" in def) {
1050
+ const language = def.language == null ? "@null" : def.language.toLowerCase();
1051
+ languageMap[language] ??= term;
1052
+ } else if ("direction" in def) {
1053
+ const direction = def.direction == null ? "@none" : `_${def.direction}`;
1054
+ languageMap[direction] ??= term;
1055
+ } else if (active.direction !== void 0) {
1056
+ const langDir = active.language !== void 0 ? `${active.language}_${active.direction}`.toLowerCase() : `_${active.direction}`;
1057
+ languageMap[langDir] ??= term;
1058
+ languageMap["@none"] ??= term;
1059
+ typeMap["@none"] ??= term;
1060
+ } else {
1061
+ languageMap[defaultLanguage] ??= term;
1062
+ languageMap["@none"] ??= term;
1063
+ typeMap["@none"] ??= term;
1064
+ }
1065
+ });
1066
+ active.inverse = result;
1067
+ return result;
1068
+ };
1069
+ const selectTerm = (containerMap, containers, typeLanguage, preferredValues) => Arr.findFirst(containers, (container) => {
1070
+ const entry = containerMap[container];
1071
+ if (entry === void 0) return Option.none();
1072
+ const valueMap = entry[typeLanguage];
1073
+ return Arr.findFirst(preferredValues, (item) => Option.fromUndefinedOr(valueMap[item]));
1074
+ });
1075
+ /** The `_direction` suffix of a preferred language value (none without one). */
1076
+ const directionSuffix = (pv) => {
1077
+ const i = pv.indexOf("_");
1078
+ return i === -1 ? [] : [pv.slice(i)];
1079
+ };
1080
+ /** A compact IRI candidate is chosen when it is shorter (or as short and earlier) than the best. */
1081
+ const isBetterCompactIri = (candidate, best) => Option.isNone(best) || candidate.length < best.value.length || candidate.length === best.value.length && candidate < best.value;
1082
+ /**
1083
+ * IRI Compaction algorithm.
1084
+ *
1085
+ * @internal
1086
+ */
1087
+ const compactIri = (env, active, iri, value = null, vocab = false, reverse = false, options) => {
1088
+ if (iri === null) return iri;
1089
+ const inverse = inverseContext(active);
1090
+ const containerMap = vocab ? MutableHashMap.get(inverse, iri) : Option.none();
1091
+ if (Option.isSome(containerMap)) {
1092
+ const defaultLanguage = active.direction !== void 0 ? `${active.language ?? ""}_${active.direction}`.toLowerCase() : active.language !== void 0 ? active.language.toLowerCase() : "@none";
1093
+ if (isObject(value) && "@preserve" in value) value = asArray(value["@preserve"])[0];
1094
+ const containers = [];
1095
+ let typeLanguage = "@language";
1096
+ let typeLanguageValue = "@null";
1097
+ if (isObject(value) && "@index" in value && !isGraphObject(value)) containers.push("@index", "@index@set");
1098
+ if (reverse) {
1099
+ typeLanguage = "@type";
1100
+ typeLanguageValue = "@reverse";
1101
+ containers.push("@set");
1102
+ } else if (isListObject(value)) {
1103
+ if (!("@index" in value)) containers.push("@list");
1104
+ const list = value["@list"];
1105
+ let commonType = "@none";
1106
+ let commonLanguage = defaultLanguage;
1107
+ list.every((item, i) => {
1108
+ let itemLanguage = "@none";
1109
+ let itemType = "@none";
1110
+ if (isValueObject(item)) {
1111
+ if ("@direction" in item) itemLanguage = `${item["@language"] ?? ""}_${item["@direction"]}`.toLowerCase();
1112
+ else if ("@language" in item) itemLanguage = String(item["@language"]).toLowerCase();
1113
+ else if ("@type" in item) itemType = item["@type"];
1114
+ else itemLanguage = "@null";
1115
+ } else itemType = "@id";
1116
+ if (i === 0) {
1117
+ commonLanguage = itemLanguage;
1118
+ commonType = itemType;
1119
+ } else {
1120
+ if (itemLanguage !== commonLanguage && isValueObject(item)) commonLanguage = "@none";
1121
+ if (itemType !== commonType) commonType = "@none";
1122
+ }
1123
+ return !(commonLanguage === "@none" && commonType === "@none");
1124
+ });
1125
+ if (commonType !== "@none") {
1126
+ typeLanguage = "@type";
1127
+ typeLanguageValue = commonType;
1128
+ } else typeLanguageValue = commonLanguage;
1129
+ } else if (isGraphObject(value)) {
1130
+ if ("@index" in value) containers.push("@graph@index", "@graph@index@set");
1131
+ if ("@id" in value) containers.push("@graph@id", "@graph@id@set");
1132
+ containers.push("@graph", "@graph@set", "@set");
1133
+ if (!("@index" in value)) containers.push("@graph@index", "@graph@index@set");
1134
+ if (!("@id" in value)) containers.push("@graph@id", "@graph@id@set");
1135
+ containers.push("@index", "@index@set");
1136
+ typeLanguage = "@type";
1137
+ typeLanguageValue = "@id";
1138
+ } else {
1139
+ if (isValueObject(value)) {
1140
+ if ("@direction" in value && !("@index" in value)) {
1141
+ typeLanguageValue = `${value["@language"] ?? ""}_${value["@direction"]}`.toLowerCase();
1142
+ containers.push("@language", "@language@set");
1143
+ } else if ("@language" in value && !("@index" in value)) {
1144
+ typeLanguageValue = String(value["@language"]).toLowerCase();
1145
+ containers.push("@language", "@language@set");
1146
+ } else if ("@type" in value) {
1147
+ typeLanguageValue = value["@type"] ?? "@null";
1148
+ typeLanguage = "@type";
1149
+ }
1150
+ } else {
1151
+ typeLanguage = "@type";
1152
+ typeLanguageValue = "@id";
1153
+ containers.push("@id", "@id@set", "@type", "@set@type");
1154
+ }
1155
+ containers.push("@set");
1156
+ }
1157
+ containers.push("@none");
1158
+ if (env.processingMode !== "json-ld-1.0" && (!isObject(value) || !("@index" in value))) containers.push("@index", "@index@set");
1159
+ if (env.processingMode !== "json-ld-1.0" && isObject(value) && Record.keys(value).length === 1 && "@value" in value) containers.push("@language", "@language@set");
1160
+ const preferredValues = [];
1161
+ if (typeLanguageValue === "@reverse") preferredValues.push("@reverse");
1162
+ if ((typeLanguageValue === "@id" || typeLanguageValue === "@reverse") && isObject(value) && "@id" in value) {
1163
+ const compactedId = compactIri(env, active, value["@id"], null, true, false, options);
1164
+ if (definitionOf(active, compactedId)?.iri === value["@id"]) preferredValues.push("@vocab", "@id", "@none");
1165
+ else preferredValues.push("@id", "@vocab", "@none");
1166
+ } else {
1167
+ preferredValues.push(typeLanguageValue, "@none");
1168
+ if (isListObject(value) && Arr.isReadonlyArrayEmpty(value["@list"])) typeLanguage = "@any";
1169
+ }
1170
+ preferredValues.push("@any");
1171
+ pushAll(preferredValues, preferredValues.flatMap(directionSuffix));
1172
+ const term = selectTerm(containerMap.value, containers, typeLanguage, preferredValues);
1173
+ if (Option.isSome(term)) return term.value;
1174
+ }
1175
+ if (vocab && active.vocab !== void 0) {
1176
+ if (iri.startsWith(active.vocab) && iri.length > active.vocab.length) {
1177
+ const suffix = iri.slice(active.vocab.length);
1178
+ if (!MutableHashMap.has(active.terms, suffix)) return suffix;
1179
+ }
1180
+ }
1181
+ let compactIriResult = Option.none();
1182
+ MutableHashMap.forEach(active.terms, (def, term) => {
1183
+ const prefixIri = def.iri;
1184
+ if (prefixIri === null || prefixIri === iri || !iri.startsWith(prefixIri) || !def.prefix) return;
1185
+ const candidate = `${term}:${iri.slice(prefixIri.length)}`;
1186
+ const candidateDef = definitionOf(active, candidate);
1187
+ if (isBetterCompactIri(candidate, compactIriResult) && (candidateDef === void 0 || candidateDef.iri === iri && value === null)) compactIriResult = Option.some(candidate);
1188
+ });
1189
+ if (Option.isSome(compactIriResult)) return compactIriResult.value;
1190
+ const colon = iri.indexOf(":");
1191
+ if (colon > 0) {
1192
+ const scheme = iri.slice(0, colon);
1193
+ const def = definitionOf(active, scheme);
1194
+ if (def !== void 0 && def.prefix && !iri.slice(colon + 1).startsWith("//")) fail("IRI confused with prefix", iri);
1195
+ }
1196
+ if (!vocab && (options?.compactToRelative ?? true)) return removeBase(active.base, iri);
1197
+ return iri;
1198
+ };
1199
+ /**
1200
+ * Value Compaction algorithm.
1201
+ *
1202
+ * @internal
1203
+ */
1204
+ const compactValue = (env, active, activeProperty, value, options) => {
1205
+ const def = activeDefinition(active, activeProperty);
1206
+ const container = def?.container ?? [];
1207
+ const typeMapping = def?.type;
1208
+ const language = def !== void 0 && "language" in def ? def.language : active.language;
1209
+ const direction = def !== void 0 && "direction" in def ? def.direction : active.direction;
1210
+ const keys = Record.keys(value);
1211
+ if ("@id" in value) {
1212
+ if (keys.every((k) => k === "@id" || k === "@index")) {
1213
+ const indexOk = !("@index" in value) || container.includes("@index");
1214
+ if (indexOk && typeMapping === "@id") return compactIri(env, active, value["@id"], null, false, false, options);
1215
+ if (indexOk && typeMapping === "@vocab") return compactIri(env, active, value["@id"], null, true, false, options);
1216
+ }
1217
+ return value;
1218
+ }
1219
+ const preserveIndex = "@index" in value && !container.includes("@index");
1220
+ if (!preserveIndex) {
1221
+ if ("@type" in value && value["@type"] === typeMapping) return value["@value"];
1222
+ if (typeMapping === "@none" || "@type" in value) {} else if (!isString$1(value["@value"])) {
1223
+ if (!("@language" in value) && !("@direction" in value)) return value["@value"];
1224
+ } else {
1225
+ const langMatch = "@language" in value ? language != null && String(value["@language"]).toLowerCase() === language.toLowerCase() : language == null;
1226
+ const dirMatch = "@direction" in value ? value["@direction"] === direction : direction == null;
1227
+ if (langMatch && dirMatch) return value["@value"];
1228
+ }
1229
+ }
1230
+ const result = {};
1231
+ keys.forEach((key) => {
1232
+ if (key === "@index" && !preserveIndex) return;
1233
+ const alias = compactIri(env, active, key, null, true, false, options);
1234
+ result[alias] = key === "@type" ? compactIri(env, active, value[key], null, true, false, options) : value[key];
1235
+ });
1236
+ return result;
1237
+ };
1238
+ // src/jsonld/internal/expand.ts
1239
+ /**
1240
+ * Expansion Algorithm (JSON-LD 1.1 API §5.1).
1241
+ *
1242
+ * @internal
1243
+ */
1244
+ /** A frame-expansion `@language` / `@direction` value: `{}` or an array of strings. */
1245
+ const isFrameStringValue = (value) => isEmptyObject(value) || Array.isArray(value) && value.every(isString$1);
1246
+ /** @internal */
1247
+ const expandElement = (env, active, activeProperty, element, baseUrl, options, fromMap = false) => {
1248
+ if (element === null || element === void 0) return null;
1249
+ if (isProperty(activeProperty, "@default")) options = {
1250
+ ...options,
1251
+ frameExpansion: false
1252
+ };
1253
+ const propDef = Option.isNone(activeProperty) ? Option.none() : termOf(active, activeProperty.value);
1254
+ const propertyScoped = Option.filter(propDef, (def) => def.hasContext);
1255
+ if (isScalar(element)) {
1256
+ if (Option.isNone(activeProperty) || activeProperty.value === "@graph") return null;
1257
+ if (Option.isSome(propertyScoped)) {
1258
+ const def = propertyScoped.value;
1259
+ active = processContext(env, active, def.context, def.baseUrl ?? null);
1260
+ }
1261
+ return expandValue(env, active, activeProperty.value, element);
1262
+ }
1263
+ if (Array.isArray(element)) {
1264
+ const result = [];
1265
+ const isList = Option.isSome(propDef) && propDef.value.container.includes("@list");
1266
+ element.forEach((item) => {
1267
+ const expanded = expandElement(env, active, activeProperty, item, baseUrl, options, fromMap);
1268
+ if (Array.isArray(expanded)) {
1269
+ if (isList) result.push({ "@list": expanded });
1270
+ else pushAll(result, expanded);
1271
+ } else if (expanded !== null) result.push(expanded);
1272
+ });
1273
+ return result;
1274
+ }
1275
+ if (!isObject(element)) fail("invalid local context");
1276
+ if (active.previous !== void 0 && !fromMap) {
1277
+ const keys = Record.keys(element);
1278
+ if (!keys.some((key) => {
1279
+ const exp = expandIri(env, active, key, true);
1280
+ return exp === "@value" || keys.length === 1 && exp === "@id";
1281
+ })) active = active.previous;
1282
+ }
1283
+ if (Option.isSome(propertyScoped)) {
1284
+ const def = propertyScoped.value;
1285
+ active = processContext(env, active, def.context, def.baseUrl ?? null, [], true);
1286
+ }
1287
+ if ("@context" in element) active = processContext(env, active, element["@context"], baseUrl);
1288
+ const typeScoped = active;
1289
+ const keys = Arr.sort(Record.keys(element), compareStrings);
1290
+ keys.forEach((key) => {
1291
+ if (expandIri(env, active, key, true) !== "@type") return;
1292
+ const values = asArray(element[key]);
1293
+ active = applyTypeScopedContexts(env, active, typeScoped, Arr.sort(Arr.filter(values, isString$1), compareStrings));
1294
+ });
1295
+ const typeKey = keys.find((key) => expandIri(env, active, key, true) === "@type");
1296
+ const lastType = typeKey === void 0 ? void 0 : asArray(element[typeKey]).at(-1);
1297
+ const inputIsJson = isString$1(lastType) && expandIri(env, active, lastType, true) === "@json";
1298
+ const result = {};
1299
+ expandObject(env, active, typeScoped, activeProperty, element, result, inputIsJson, baseUrl, options);
1300
+ if ("@value" in result) {
1301
+ const extra = Record.keys(result).find((k) => k !== "@direction" && k !== "@index" && k !== "@language" && k !== "@type" && k !== "@value");
1302
+ if (extra !== void 0) fail("invalid value object", extra);
1303
+ if ("@type" in result && ("@language" in result || "@direction" in result)) fail("invalid value object");
1304
+ const type = result["@type"];
1305
+ if (type === "@json") {} else {
1306
+ const v = result["@value"];
1307
+ if (v === null || Array.isArray(v) && Arr.isReadonlyArrayEmpty(v)) return null;
1308
+ if (!isString$1(v) && "@language" in result) {
1309
+ if (!options.frameExpansion) fail("invalid language-tagged value");
1310
+ }
1311
+ if ("@type" in result) {
1312
+ if (options.frameExpansion) {} else if (!isString$1(type) || !isAbsoluteIri(type) || isBlankNodeId(type)) fail("invalid typed value");
1313
+ }
1314
+ }
1315
+ } else if ("@type" in result) {
1316
+ if (!Array.isArray(result["@type"])) result["@type"] = [result["@type"]];
1317
+ } else if ("@set" in result || "@list" in result) {
1318
+ const n = Record.keys(result).length;
1319
+ if (n > 2 || n === 2 && !("@index" in result)) fail("invalid set or list object");
1320
+ if ("@set" in result) {
1321
+ const set = result["@set"];
1322
+ return finalize(set, activeProperty, options);
1323
+ }
1324
+ }
1325
+ return finalize(result, activeProperty, options);
1326
+ };
1327
+ const finalize = (result, activeProperty, options) => {
1328
+ if (isObject(result)) {
1329
+ const keys = Record.keys(result);
1330
+ if (keys.length === 1 && keys[0] === "@language") return null;
1331
+ if (!options.frameExpansion && isTopLevel(activeProperty)) {
1332
+ if (Arr.isReadonlyArrayEmpty(keys) || "@value" in result || "@list" in result) return null;
1333
+ if (keys.length === 1 && keys[0] === "@id") return null;
1334
+ }
1335
+ }
1336
+ return result;
1337
+ };
1338
+ const expandKeyword = Match.fn((expandedProperty, _key, _value, _kw) => expandedProperty).pipe(Match.withReturnType(), Match.when("@id", (_p, _ep, _key, value, kw) => {
1339
+ if (isString$1(value)) return expandIri(kw.env, kw.active, value, false, true);
1340
+ if (kw.options.frameExpansion && isEmptyObject(value)) return [value];
1341
+ if (kw.options.frameExpansion && Array.isArray(value) && value.every(isString$1)) return value.map((v) => expandIri(kw.env, kw.active, v, false, true));
1342
+ return fail("invalid @id value", stringifyJson(value));
1343
+ }), Match.when("@type", (_p, _ep, _key, value, kw) => {
1344
+ let expandedValue = void 0;
1345
+ if (kw.options.frameExpansion && isEmptyObject(value)) expandedValue = value;
1346
+ else if (kw.options.frameExpansion && isObject(value) && "@default" in value && Record.keys(value).length === 1) expandedValue = { "@default": expandIri(kw.env, kw.typeScoped, value["@default"], true, true) };
1347
+ else if (isString$1(value)) expandedValue = expandIri(kw.env, kw.typeScoped, value, true, true);
1348
+ else if (Array.isArray(value) && value.every(isString$1)) expandedValue = value.map((v) => expandIri(kw.env, kw.typeScoped, v, true, true));
1349
+ else fail("invalid type value", stringifyJson(value));
1350
+ if ("@type" in kw.result) expandedValue = [...asArray(kw.result["@type"]), ...asArray(expandedValue)];
1351
+ return expandedValue;
1352
+ }), Match.when("@graph", (_p, _ep, _key, value, kw) => asArray(expandElement(kw.env, kw.active, GRAPH_PROPERTY, value, kw.baseUrl, kw.options))), Match.when("@included", (_p, _ep, _key, value, kw) => {
1353
+ if (kw.env.processingMode === "json-ld-1.0") return void 0;
1354
+ const expandedValue = asArray(expandElement(kw.env, kw.active, kw.activeProperty, value, kw.baseUrl, kw.options));
1355
+ if (expandedValue.some((v) => !isObject(v) || "@value" in v || "@list" in v || "@set" in v)) fail("invalid @included value");
1356
+ return "@included" in kw.result ? [...kw.result["@included"], ...expandedValue] : expandedValue;
1357
+ }), Match.when("@value", (_p, _ep, _key, value, kw) => {
1358
+ let expandedValue = void 0;
1359
+ if (kw.inputIsJson) {
1360
+ if (kw.env.processingMode === "json-ld-1.0") fail("invalid value object value");
1361
+ expandedValue = value;
1362
+ } else if (value === null || isScalar(value)) expandedValue = value;
1363
+ else if (kw.options.frameExpansion && (isEmptyObject(value) || Array.isArray(value) && value.every(isScalar))) expandedValue = value;
1364
+ else fail("invalid value object value");
1365
+ if (expandedValue === null) {
1366
+ kw.result["@value"] = null;
1367
+ return;
1368
+ }
1369
+ return expandedValue;
1370
+ }), Match.when("@language", (_p, _ep, _key, value, kw) => {
1371
+ if (isString$1(value)) return value;
1372
+ if (kw.options.frameExpansion && isFrameStringValue(value)) return value;
1373
+ return fail("invalid language-tagged string");
1374
+ }), Match.when("@direction", (_p, _ep, _key, value, kw) => {
1375
+ if (kw.env.processingMode === "json-ld-1.0") return void 0;
1376
+ if (value === "ltr" || value === "rtl") return value;
1377
+ if (kw.options.frameExpansion && isFrameStringValue(value)) return value;
1378
+ return fail("invalid base direction");
1379
+ }), Match.when("@index", (_p, _ep, _key, value) => {
1380
+ if (!isString$1(value)) fail("invalid @index value");
1381
+ return value;
1382
+ }), Match.when("@list", (_p, _ep, _key, value, kw) => {
1383
+ if (isTopLevel(kw.activeProperty)) return void 0;
1384
+ const expandedValue = asArray(expandElement(kw.env, kw.active, kw.activeProperty, value, kw.baseUrl, kw.options));
1385
+ if (kw.env.processingMode === "json-ld-1.0" && expandedValue.some(isListObject)) fail("list of lists");
1386
+ return expandedValue;
1387
+ }), Match.when("@set", (_p, _ep, _key, value, kw) => expandElement(kw.env, kw.active, kw.activeProperty, value, kw.baseUrl, kw.options)), Match.when("@reverse", (_p, _ep, _key, value, kw) => {
1388
+ if (!isObject(value)) fail("invalid @reverse value");
1389
+ const ev = expandElement(kw.env, kw.active, REVERSE_PROPERTY, value, kw.baseUrl, kw.options);
1390
+ if (isObject(ev)) {
1391
+ if ("@reverse" in ev) {
1392
+ const reversed = ev["@reverse"];
1393
+ Record.keys(reversed).forEach((property) => {
1394
+ if (!hasOwn(kw.result, property)) kw.result[property] = [];
1395
+ pushAll(kw.result[property], asArray(reversed[property]));
1396
+ });
1397
+ }
1398
+ const others = Record.keys(ev).filter((k) => k !== "@reverse");
1399
+ if (Arr.isReadonlyArrayNonEmpty(others)) {
1400
+ const reverseMap = getOrInit(kw.result, "@reverse", () => ({}));
1401
+ others.forEach((property) => asArray(ev[property]).forEach((item) => {
1402
+ if (isValueObject(item) || isListObject(item)) fail("invalid reverse property value");
1403
+ getOrInit(reverseMap, property, () => []).push(item);
1404
+ }));
1405
+ }
1406
+ }
1407
+ }), Match.when("@nest", (_p, _ep, key, _value, kw) => {
1408
+ kw.nests.push(key);
1409
+ }), Match.when("@default", (_p, _ep, _key, value, kw) => kw.options.frameExpansion ? expandElement(kw.env, kw.active, kw.activeProperty, value, kw.baseUrl, kw.options) : void 0), Match.when(Match.is("@embed", "@explicit", "@omitDefault", "@requireAll"), (_p, _ep, _key, value, kw) => kw.options.frameExpansion ? asArray(value) : void 0), Match.orElse(() => void 0));
1410
+ const expandObject = (env, active, typeScoped, activeProperty, element, result, inputIsJson, baseUrl, options) => {
1411
+ const nests = [];
1412
+ const scope = {
1413
+ env,
1414
+ active,
1415
+ typeScoped,
1416
+ activeProperty,
1417
+ result,
1418
+ inputIsJson,
1419
+ baseUrl,
1420
+ options,
1421
+ nests
1422
+ };
1423
+ (options.ordered ? Arr.sort(Record.keys(element), compareStrings) : Record.keys(element)).forEach((key) => {
1424
+ const value = element[key];
1425
+ if (key === "@context") return;
1426
+ const expandedProperty = expandIri(env, active, key, true);
1427
+ if (expandedProperty === null || !expandedProperty.includes(":") && !isKeyword(expandedProperty)) return;
1428
+ if (isKeyword(expandedProperty)) {
1429
+ if (isProperty(activeProperty, "@reverse")) fail("invalid reverse property map");
1430
+ if (hasOwn(result, expandedProperty) && expandedProperty !== "@included" && expandedProperty !== "@type") fail("colliding keywords", expandedProperty);
1431
+ if (expandedProperty in result && expandedProperty === "@type" && env.processingMode === "json-ld-1.0") fail("colliding keywords", expandedProperty);
1432
+ const expandedValue = expandKeyword(expandedProperty, key, value, scope);
1433
+ if (expandedValue !== void 0) result[expandedProperty] = expandedValue;
1434
+ return;
1435
+ }
1436
+ const def = termOf(active, key);
1437
+ const container = Option.isSome(def) ? def.value.container : [];
1438
+ let expandedValue;
1439
+ if (Option.isSome(def) && def.value.type === "@json") expandedValue = {
1440
+ "@value": value,
1441
+ "@type": "@json"
1442
+ };
1443
+ else if (container.includes("@language") && isObject(value)) {
1444
+ const values = [];
1445
+ expandedValue = values;
1446
+ const direction = Option.isSome(def) && "direction" in def.value ? def.value.direction : active.direction;
1447
+ (options.ordered ? Arr.sort(Record.keys(value), compareStrings) : Record.keys(value)).forEach((language) => asArray(value[language]).forEach((item) => {
1448
+ if (item === null) return;
1449
+ if (!isString$1(item)) fail("invalid language map value");
1450
+ const v = {
1451
+ "@value": item,
1452
+ "@language": language
1453
+ };
1454
+ if (language === "@none" || expandIri(env, active, language, true) === "@none") delete v["@language"];
1455
+ if (direction !== null && direction !== void 0) v["@direction"] = direction;
1456
+ values.push(v);
1457
+ }));
1458
+ } else if ((container.includes("@index") || container.includes("@type") || container.includes("@id")) && isObject(value)) {
1459
+ const values = [];
1460
+ expandedValue = values;
1461
+ const indexKey = Option.isSome(def) ? def.value.index ?? "@index" : "@index";
1462
+ (options.ordered ? Arr.sort(Record.keys(value), compareStrings) : Record.keys(value)).forEach((index) => {
1463
+ let mapContext = active;
1464
+ if (container.includes("@type")) {
1465
+ mapContext = active.previous ?? active;
1466
+ const indexDef = scopedTermOf(mapContext, index);
1467
+ if (Option.isSome(indexDef)) mapContext = processContext(env, mapContext, indexDef.value.context, indexDef.value.baseUrl ?? null);
1468
+ }
1469
+ const expandedIndex = expandIri(env, active, index, true);
1470
+ asArray(expandElement(env, mapContext, Option.some(key), asArray(value[index]), baseUrl, options, true)).forEach((expandedItem) => {
1471
+ const item = container.includes("@graph") && !isGraphObject(expandedItem) ? { "@graph": asArray(expandedItem) } : expandedItem;
1472
+ if (container.includes("@index") && indexKey !== "@index" && expandedIndex !== "@none") {
1473
+ const reExpanded = expandValue(env, active, indexKey, index);
1474
+ const expandedIndexKey = expandIri(env, active, indexKey, true) ?? indexKey;
1475
+ item[expandedIndexKey] = [reExpanded, ...hasOwn(item, expandedIndexKey) ? asArray(item[expandedIndexKey]) : []];
1476
+ if (isValueObject(item) && Record.keys(item).length > 1) fail("invalid value object");
1477
+ } else if (container.includes("@index") && !("@index" in item) && expandedIndex !== "@none") item["@index"] = index;
1478
+ else if (container.includes("@id") && !("@id" in item) && expandedIndex !== "@none") item["@id"] = expandIri(env, active, index, false, true);
1479
+ else if (container.includes("@type") && expandedIndex !== "@none") item["@type"] = [expandedIndex, ...item["@type"] ? asArray(item["@type"]) : []];
1480
+ values.push(item);
1481
+ });
1482
+ });
1483
+ } else expandedValue = expandElement(env, active, Option.some(key), value, baseUrl, options);
1484
+ if (expandedValue === null) return;
1485
+ if (container.includes("@list") && !isListObject(expandedValue)) expandedValue = { "@list": asArray(expandedValue) };
1486
+ if (container.includes("@graph") && !container.includes("@id") && !container.includes("@index")) expandedValue = asArray(expandedValue).map((ev) => ({ "@graph": asArray(ev) }));
1487
+ if (Option.isSome(def) && def.value.reverse) {
1488
+ const reverseMap = getOrInit(result, "@reverse", () => ({}));
1489
+ asArray(expandedValue).forEach((item) => {
1490
+ if (isValueObject(item) || isListObject(item)) fail("invalid reverse property value");
1491
+ getOrInit(reverseMap, expandedProperty, () => []).push(item);
1492
+ });
1493
+ } else pushAll(getOrInit(result, expandedProperty, () => []), asArray(expandedValue));
1494
+ });
1495
+ (options.ordered ? Arr.sort(nests, compareStrings) : nests).forEach((nestKey) => asArray(element[nestKey]).forEach((nested) => {
1496
+ if (!isObject(nested)) fail("invalid @nest value");
1497
+ if (Record.keys(nested).some((k) => expandIri(env, active, k, true) === "@value")) fail("invalid @nest value");
1498
+ const nestContext = Option.match(scopedTermOf(active, nestKey), {
1499
+ onNone: () => active,
1500
+ onSome: (nestDef) => processContext(env, active, nestDef.context, nestDef.baseUrl ?? null, [], true)
1501
+ });
1502
+ expandObject(env, nestContext, typeScoped, activeProperty, nested, result, inputIsJson, baseUrl, options);
1503
+ }));
1504
+ };
1505
+ /**
1506
+ * Value Expansion algorithm.
1507
+ *
1508
+ * @internal
1509
+ */
1510
+ const expandValue = (env, active, activeProperty, value) => {
1511
+ const def = Option.getOrNull(termOf(active, activeProperty));
1512
+ const type = def === null ? void 0 : def.type;
1513
+ if (type === "@id" && isString$1(value)) return { "@id": expandIri(env, active, value, false, true) };
1514
+ if (type === "@vocab" && isString$1(value)) return { "@id": expandIri(env, active, value, true, true) };
1515
+ const result = { "@value": value };
1516
+ if (type !== void 0 && type !== "@id" && type !== "@vocab" && type !== "@none") result["@type"] = type;
1517
+ else if (isString$1(value)) {
1518
+ const language = def !== null && "language" in def ? def.language : active.language;
1519
+ const direction = def !== null && "direction" in def ? def.direction : active.direction;
1520
+ if (language !== null && language !== void 0) result["@language"] = language;
1521
+ if (direction !== null && direction !== void 0) result["@direction"] = direction;
1522
+ }
1523
+ return result;
1524
+ };
1525
+ // src/jsonld/internal/flatten.ts
1526
+ /**
1527
+ * Node Map Generation and Flattening (JSON-LD 1.1 API §7).
1528
+ *
1529
+ * @internal
1530
+ */
1531
+ /**
1532
+ * Adds `item` to the active list or, outside a list, to the active property
1533
+ * of the active subject (once, when `unique`).
1534
+ */
1535
+ const addToTarget = (graph, activeSubject, activeProperty, list, item, unique) => {
1536
+ if (Option.isSome(list)) {
1537
+ list.value["@list"].push(item);
1538
+ return;
1539
+ }
1540
+ if (Option.isNone(activeSubject) || Option.isNone(activeProperty)) return;
1541
+ const subject = activeSubject.value;
1542
+ if (isObject(subject)) return;
1543
+ const values = getOrInit(graph[subject] ?? {}, activeProperty.value, () => []);
1544
+ if (unique) addUnique(values, item);
1545
+ else values.push(item);
1546
+ };
1547
+ /**
1548
+ * Node Map Generation algorithm.
1549
+ *
1550
+ * @internal
1551
+ */
1552
+ const generateNodeMap = (element, nodeMap, issuer, activeGraph = "@default", activeSubject = Option.none(), activeProperty = Option.none(), list = Option.none()) => {
1553
+ if (Array.isArray(element)) {
1554
+ element.forEach((item) => generateNodeMap(item, nodeMap, issuer, activeGraph, activeSubject, activeProperty, list));
1555
+ return;
1556
+ }
1557
+ const graph = getOrInit(nodeMap, activeGraph, () => ({}));
1558
+ if ("@type" in element) {
1559
+ const type = element["@type"];
1560
+ element["@type"] = Array.isArray(type) ? type.map((t) => isBlankNodeId(t) ? issuer.issue(t) : t) : isBlankNodeId(type) ? issuer.issue(type) : type;
1561
+ }
1562
+ if (isValueObject(element)) {
1563
+ addToTarget(graph, activeSubject, activeProperty, list, element, true);
1564
+ return;
1565
+ }
1566
+ if (isListObject(element)) {
1567
+ const result = { "@list": [] };
1568
+ generateNodeMap(element["@list"], nodeMap, issuer, activeGraph, activeSubject, activeProperty, Option.some(result));
1569
+ addToTarget(graph, activeSubject, activeProperty, list, result, false);
1570
+ return;
1571
+ }
1572
+ let id;
1573
+ if ("@id" in element) {
1574
+ id = element["@id"];
1575
+ if (id === null) return;
1576
+ if (isBlankNodeId(id)) id = issuer.issue(id);
1577
+ } else id = issuer.issue();
1578
+ const node = getOrInit(graph, id, () => ({ "@id": id }));
1579
+ if (Option.isSome(activeSubject) && isObject(activeSubject.value)) {
1580
+ if (Option.isSome(activeProperty)) {
1581
+ const values = getOrInit(node, activeProperty.value, () => []);
1582
+ addUnique(values, activeSubject.value);
1583
+ }
1584
+ } else if (Option.isSome(activeProperty)) addToTarget(graph, activeSubject, activeProperty, list, { "@id": id }, true);
1585
+ if ("@type" in element) {
1586
+ const types = getOrInit(node, "@type", () => []);
1587
+ asArray(element["@type"]).forEach((t) => {
1588
+ if (!types.includes(t)) types.push(t);
1589
+ });
1590
+ }
1591
+ if ("@index" in element) {
1592
+ if ("@index" in node && node["@index"] !== element["@index"]) fail("conflicting indexes");
1593
+ node["@index"] = element["@index"];
1594
+ }
1595
+ if ("@reverse" in element) {
1596
+ const referenced = Option.some({ "@id": id });
1597
+ const reverseMap = element["@reverse"];
1598
+ Record.keys(reverseMap).forEach((property) => {
1599
+ const reverseProperty = Option.some(property);
1600
+ asArray(reverseMap[property]).forEach((value) => generateNodeMap(value, nodeMap, issuer, activeGraph, referenced, reverseProperty));
1601
+ });
1602
+ }
1603
+ if ("@graph" in element) generateNodeMap(element["@graph"], nodeMap, issuer, id);
1604
+ if ("@included" in element) generateNodeMap(element["@included"], nodeMap, issuer, activeGraph);
1605
+ const subject = Option.some(id);
1606
+ Arr.sort(Record.keys(element), compareStrings).forEach((key) => {
1607
+ if (key === "@id" || key === "@type" || key === "@index" || key === "@reverse" || key === "@graph" || key === "@included") return;
1608
+ const property = isBlankNodeId(key) ? issuer.issue(key) : key;
1609
+ if (!hasOwn(node, property)) node[property] = [];
1610
+ generateNodeMap(element[key], nodeMap, issuer, activeGraph, subject, Option.some(property));
1611
+ });
1612
+ };
1613
+ /** The nodes of a graph that say more than their `@id`, in key order (sorted when `ordered`). */
1614
+ const nodesOf = (graph, ordered) => {
1615
+ const ids = ordered ? Arr.sort(Record.keys(graph), compareStrings) : Record.keys(graph);
1616
+ const nodes = [];
1617
+ ids.forEach((id) => {
1618
+ const node = graph[id];
1619
+ if (node !== void 0 && !isOnlyId$1(node)) nodes.push(node);
1620
+ });
1621
+ return nodes;
1622
+ };
1623
+ /**
1624
+ * Flattening algorithm (without the final compaction).
1625
+ *
1626
+ * @internal
1627
+ */
1628
+ const flattenExpanded = (expanded, ordered) => {
1629
+ const defaultGraph = {};
1630
+ const nodeMap = { "@default": defaultGraph };
1631
+ generateNodeMap(expanded, nodeMap, new IdIssuer());
1632
+ const named = Record.keys(nodeMap).filter((g) => g !== "@default");
1633
+ (ordered ? Arr.sort(named, compareStrings) : named).forEach((graphName) => {
1634
+ const entry = getOrInit(defaultGraph, graphName, () => ({ "@id": graphName }));
1635
+ entry["@graph"] = nodesOf(nodeMap[graphName] ?? {}, ordered);
1636
+ });
1637
+ return nodesOf(defaultGraph, ordered);
1638
+ };
1639
+ const isOnlyId$1 = (node) => {
1640
+ const keys = Record.keys(node);
1641
+ return keys.length === 1 && keys[0] === "@id";
1642
+ };
1643
+ /** @internal */
1644
+ const mergeNodeMaps = (graphs) => {
1645
+ const merged = {};
1646
+ Arr.sort(Record.keys(graphs), compareStrings).forEach((graphName) => {
1647
+ const graph = graphs[graphName] ?? {};
1648
+ Arr.sort(Record.keys(graph), compareStrings).forEach((id) => {
1649
+ const node = graph[id] ?? {};
1650
+ const mergedNode = getOrInit(merged, id, () => ({ "@id": id }));
1651
+ Arr.sort(Record.keys(node), compareStrings).forEach((property) => {
1652
+ if (property === "@id") return;
1653
+ if (property === "@type") {
1654
+ const types = getOrInit(mergedNode, "@type", () => []);
1655
+ asArray(node["@type"]).forEach((t) => {
1656
+ if (!types.includes(t)) types.push(t);
1657
+ });
1658
+ return;
1659
+ }
1660
+ if (property.startsWith("@")) {
1661
+ mergedNode[property] = structuredClone(node[property]);
1662
+ return;
1663
+ }
1664
+ const values = getOrInit(mergedNode, property, () => []);
1665
+ asArray(node[property]).forEach((v) => {
1666
+ if (!values.some((x) => deepEqual(x, v))) values.push(structuredClone(v));
1667
+ });
1668
+ });
1669
+ });
1670
+ });
1671
+ return merged;
1672
+ };
1673
+ // src/jsonld/internal/frame.ts
1674
+ /**
1675
+ * Framing Algorithm (JSON-LD 1.1 Framing §4).
1676
+ *
1677
+ * @internal
1678
+ */
1679
+ /**
1680
+ * Frames expanded input with an expanded frame. Returns the framed nodes
1681
+ * (expanded form) and the blank node identifiers that are referenced only
1682
+ * once and can therefore be pruned.
1683
+ *
1684
+ * @internal
1685
+ */
1686
+ const frame$1 = (expanded, expandedFrame, options) => {
1687
+ const graphMap = { "@default": {} };
1688
+ generateNodeMap(expanded, graphMap, new IdIssuer());
1689
+ let graph = "@default";
1690
+ if (options.merged) {
1691
+ graphMap["@merged"] = mergeNodeMaps(graphMap);
1692
+ graph = "@merged";
1693
+ }
1694
+ const state = {
1695
+ options,
1696
+ graphMap,
1697
+ subjects: graphMap[graph] ?? {},
1698
+ graph,
1699
+ embedded: false,
1700
+ subjectStack: [],
1701
+ link: {},
1702
+ bnodeMap: {},
1703
+ uniqueEmbeds: {}
1704
+ };
1705
+ const framed = [];
1706
+ frameSubjects(state, Arr.sort(Record.keys(state.subjects), compareStrings), asArray(expandedFrame), framed, Option.none());
1707
+ const bnodesToClear = MutableHashSet.fromIterable(options.is11 ? Record.keys(state.bnodeMap).filter((id) => state.bnodeMap[id]?.length === 1) : []);
1708
+ return cleanupPreserve(framed, bnodesToClear, /* @__PURE__ */ new WeakSet());
1709
+ };
1710
+ const getFlag = (pattern, options, name) => {
1711
+ const flag = `@${name}`;
1712
+ let value = hasOwn(pattern, flag) ? asArray(pattern[flag])[0] : options[name];
1713
+ if (isValueObject(value)) value = value["@value"];
1714
+ if (name === "embed") {
1715
+ if (value === true) value = "@once";
1716
+ else if (value === false) value = "@never";
1717
+ else if (![
1718
+ "@always",
1719
+ "@never",
1720
+ "@link",
1721
+ "@first",
1722
+ "@last",
1723
+ "@once"
1724
+ ].includes(value)) fail("invalid @embed value", String(value));
1725
+ } else if (Predicate.isString(value)) value = value === "true";
1726
+ return value;
1727
+ };
1728
+ const validateFrame = (frameValue) => {
1729
+ if (!Array.isArray(frameValue) || frameValue.length !== 1 || !isObject(frameValue[0])) fail("invalid frame", "a frame must be a single object");
1730
+ const f = frameValue[0];
1731
+ if (hasOwn(f, "@id")) asArray(f["@id"]).forEach((id) => {
1732
+ if (!(isObject(id) || isString$1(id) && isAbsoluteIri(id)) || isBlankNodeId(id)) fail("invalid frame", `invalid @id ${stringifyJson(id)}`);
1733
+ });
1734
+ if (hasOwn(f, "@type")) asArray(f["@type"]).forEach((type) => {
1735
+ if (!(isObject(type) || isString$1(type) && isAbsoluteIri(type) || type === "@json") || isBlankNodeId(type)) fail("invalid frame", `invalid @type ${stringifyJson(type)}`);
1736
+ });
1737
+ };
1738
+ const createImplicitFrame = (flags) => [{
1739
+ "@embed": [flags.embed],
1740
+ "@explicit": [flags.explicit],
1741
+ "@requireAll": [flags.requireAll]
1742
+ }];
1743
+ const createsCircularReference = (subject, graph, stack) => stack.some((entry) => entry.graph === graph && entry.subject["@id"] === subject["@id"]);
1744
+ const addFrameOutput = (parent, property, output) => {
1745
+ if (isObject(parent)) {
1746
+ if (Option.isSome(property)) addValue(parent, property.value, output, true);
1747
+ } else parent.push(output);
1748
+ };
1749
+ const isSubjectReference = (v) => isObject(v) && Record.keys(v).length === 1 && hasOwn(v, "@id");
1750
+ const frameSubjects = (state, subjects, frameValue, parent, property) => {
1751
+ validateFrame(frameValue);
1752
+ const pattern = frameValue[0];
1753
+ const options = state.options;
1754
+ const flags = {
1755
+ embed: getFlag(pattern, options, "embed"),
1756
+ explicit: getFlag(pattern, options, "explicit"),
1757
+ requireAll: getFlag(pattern, options, "requireAll")
1758
+ };
1759
+ const link = getOrInit(state.link, state.graph, () => ({}));
1760
+ const matches = filterSubjects(state, subjects, pattern, flags);
1761
+ Arr.sort(Record.keys(matches), compareStrings).forEach((id) => {
1762
+ const subject = matches[id];
1763
+ if (subject === void 0) return;
1764
+ if (Option.isNone(property)) state.uniqueEmbeds = { [state.graph]: {} };
1765
+ const uniqueEmbeds = getOrInit(state.uniqueEmbeds, state.graph, () => ({}));
1766
+ const output = { "@id": id };
1767
+ if (isBlankNodeId(id)) addValue(state.bnodeMap, id, output, true);
1768
+ link[id] = output;
1769
+ if ((flags.embed === "@first" || flags.embed === "@last") && options.is11) fail("invalid @embed value", flags.embed);
1770
+ if (!state.embedded && hasOwn(uniqueEmbeds, id)) return;
1771
+ if (state.embedded && (flags.embed === "@never" || createsCircularReference(subject, state.graph, state.subjectStack))) {
1772
+ addFrameOutput(parent, property, output);
1773
+ return;
1774
+ }
1775
+ if (state.embedded && (flags.embed === "@first" || flags.embed === "@once") && hasOwn(uniqueEmbeds, id)) {
1776
+ addFrameOutput(parent, property, output);
1777
+ return;
1778
+ }
1779
+ if (flags.embed === "@last" && hasOwn(uniqueEmbeds, id)) removeEmbed(state, id);
1780
+ uniqueEmbeds[id] = {
1781
+ parent,
1782
+ property
1783
+ };
1784
+ state.subjectStack.push({
1785
+ subject,
1786
+ graph: state.graph
1787
+ });
1788
+ const namedGraph = state.graphMap[id];
1789
+ if (hasOwn(state.graphMap, id) && namedGraph !== void 0) {
1790
+ let recurse;
1791
+ let subframe;
1792
+ if (!hasOwn(pattern, "@graph")) {
1793
+ recurse = state.graph !== "@merged";
1794
+ subframe = {};
1795
+ } else {
1796
+ subframe = asArray(pattern["@graph"])[0];
1797
+ recurse = !(id === "@merged" || id === "@default");
1798
+ if (!isObject(subframe)) subframe = {};
1799
+ }
1800
+ if (recurse) frameSubjects({
1801
+ ...state,
1802
+ graph: id,
1803
+ subjects: namedGraph,
1804
+ embedded: false
1805
+ }, Arr.sort(Record.keys(namedGraph), compareStrings), [subframe], output, Option.some("@graph"));
1806
+ }
1807
+ if (hasOwn(pattern, "@included")) frameSubjects({
1808
+ ...state,
1809
+ embedded: false
1810
+ }, subjects, pattern["@included"], output, Option.some("@included"));
1811
+ Arr.sort(Record.keys(subject), compareStrings).forEach((prop) => {
1812
+ if (isKeyword(prop)) {
1813
+ output[prop] = clone(subject[prop]);
1814
+ if (prop === "@type") asArray(subject["@type"]).forEach((type) => {
1815
+ if (isBlankNodeId(type)) addValue(state.bnodeMap, type, output, true);
1816
+ });
1817
+ return;
1818
+ }
1819
+ if (flags.explicit && !hasOwn(pattern, prop)) return;
1820
+ const underProp = Option.some(prop);
1821
+ subject[prop].forEach((o) => {
1822
+ const subframe = hasOwn(pattern, prop) ? pattern[prop] : createImplicitFrame(flags);
1823
+ if (isListObject(o)) {
1824
+ const first = hasOwn(pattern, prop) ? asArray(pattern[prop])[0] : void 0;
1825
+ const listFrame = isObject(first) && hasOwn(first, "@list") ? first["@list"] : createImplicitFrame(flags);
1826
+ const list = { "@list": [] };
1827
+ addFrameOutput(output, underProp, list);
1828
+ const listProperty = Option.some("@list");
1829
+ asArray(o["@list"]).forEach((oo) => {
1830
+ if (isSubjectReference(oo)) frameSubjects({
1831
+ ...state,
1832
+ embedded: true
1833
+ }, [oo["@id"]], listFrame, list, listProperty);
1834
+ else addFrameOutput(list, listProperty, clone(oo));
1835
+ });
1836
+ } else if (isSubjectReference(o)) frameSubjects({
1837
+ ...state,
1838
+ embedded: true
1839
+ }, [o["@id"]], subframe, output, underProp);
1840
+ else if (valueMatch(asArray(subframe)[0], o)) addFrameOutput(output, underProp, clone(o));
1841
+ });
1842
+ });
1843
+ Arr.sort(Record.keys(pattern), compareStrings).forEach((prop) => {
1844
+ if (prop === "@type") {
1845
+ const first = asArray(pattern[prop])[0];
1846
+ if (!isObject(first) || !hasOwn(first, "@default")) return;
1847
+ } else if (isKeyword(prop)) return;
1848
+ const next = asArray(pattern[prop])[0] ?? {};
1849
+ if (!getFlag(next, options, "omitDefault") && !hasOwn(output, prop)) {
1850
+ let preserve = "@null";
1851
+ if (hasOwn(next, "@default")) preserve = clone(next["@default"]);
1852
+ output[prop] = [{ "@preserve": asArray(preserve) }];
1853
+ }
1854
+ });
1855
+ if (isObject(pattern["@reverse"])) {
1856
+ const reversePattern = pattern["@reverse"];
1857
+ Arr.sort(Record.keys(reversePattern), compareStrings).forEach((reverseProp) => {
1858
+ const subframe = reversePattern[reverseProp];
1859
+ Record.keys(state.subjects).forEach((s) => {
1860
+ if (asArray(state.subjects[s]?.[reverseProp] ?? []).some((v) => isObject(v) && v["@id"] === id)) {
1861
+ const reverse = output["@reverse"] ??= {};
1862
+ addValue(reverse, reverseProp, [], true);
1863
+ frameSubjects({
1864
+ ...state,
1865
+ embedded: true
1866
+ }, [s], subframe, reverse[reverseProp], property);
1867
+ }
1868
+ });
1869
+ });
1870
+ }
1871
+ addFrameOutput(parent, property, output);
1872
+ state.subjectStack.pop();
1873
+ });
1874
+ };
1875
+ const removeEmbed = (state, id) => {
1876
+ const embeds = state.uniqueEmbeds[state.graph];
1877
+ const embed = embeds?.[id];
1878
+ if (embeds === void 0 || embed === void 0) return;
1879
+ const parent = embed.parent;
1880
+ const subject = { "@id": id };
1881
+ if (Array.isArray(parent)) parent.forEach((v, i) => {
1882
+ if (isObject(v) && v["@id"] === id) parent[i] = subject;
1883
+ });
1884
+ else if (isObject(parent) && Option.isSome(embed.property)) {
1885
+ const property = embed.property.value;
1886
+ parent[property] = asArray(parent[property]).map((v) => isObject(v) && v["@id"] === id ? subject : v);
1887
+ }
1888
+ const removeDependents = (parentId) => {
1889
+ Record.keys(embeds).forEach((next) => {
1890
+ const e = embeds[next];
1891
+ if (e !== void 0 && isObject(e.parent) && e.parent["@id"] === parentId) {
1892
+ delete embeds[next];
1893
+ removeDependents(next);
1894
+ }
1895
+ });
1896
+ };
1897
+ removeDependents(id);
1898
+ };
1899
+ const filterSubjects = (state, subjects, pattern, flags) => {
1900
+ const result = {};
1901
+ const graph = state.graphMap[state.graph];
1902
+ subjects.forEach((id) => {
1903
+ const subject = graph?.[id];
1904
+ if (subject !== void 0 && filterSubject(state, subject, pattern, flags)) result[id] = subject;
1905
+ });
1906
+ return result;
1907
+ };
1908
+ const filterSubject = (state, subject, pattern, flags) => {
1909
+ let wildcard = true;
1910
+ let matchesSome = false;
1911
+ let decided = Option.none();
1912
+ const decide = (verdict) => {
1913
+ decided = Option.some(verdict);
1914
+ return true;
1915
+ };
1916
+ Record.keys(pattern).some((key) => {
1917
+ let matchThis = false;
1918
+ const nodeValues = hasOwn(subject, key) ? asArray(subject[key]) : [];
1919
+ const frameValues = asArray(pattern[key]);
1920
+ const isEmpty = Arr.isReadonlyArrayEmpty(frameValues);
1921
+ if (key === "@id") {
1922
+ if (Arr.isReadonlyArrayEmpty(frameValues) || isObject(frameValues[0])) matchThis = true;
1923
+ else matchThis = frameValues.includes(nodeValues[0]);
1924
+ if (!flags.requireAll) return decide(matchThis);
1925
+ } else if (key === "@type") {
1926
+ wildcard = false;
1927
+ if (isEmpty) {
1928
+ if (Arr.isReadonlyArrayNonEmpty(nodeValues)) return decide(false);
1929
+ matchThis = true;
1930
+ } else if (frameValues.length === 1 && isEmptyObject(frameValues[0])) matchThis = Arr.isReadonlyArrayNonEmpty(nodeValues);
1931
+ else {
1932
+ frameValues.forEach((type) => {
1933
+ if (isObject(type) && hasOwn(type, "@default")) matchThis = true;
1934
+ else matchThis = matchThis || nodeValues.some((t) => t === type);
1935
+ });
1936
+ if (!flags.requireAll) return decide(matchThis);
1937
+ }
1938
+ } else if (isKeyword(key)) return false;
1939
+ else {
1940
+ const thisFrame = frameValues[0];
1941
+ let hasDefault = false;
1942
+ if (thisFrame !== void 0) {
1943
+ validateFrame([thisFrame]);
1944
+ hasDefault = hasOwn(thisFrame, "@default");
1945
+ }
1946
+ wildcard = false;
1947
+ if (Arr.isReadonlyArrayEmpty(nodeValues) && hasDefault) return false;
1948
+ if (Arr.isReadonlyArrayNonEmpty(nodeValues) && isEmpty) return decide(false);
1949
+ if (thisFrame === void 0) {
1950
+ if (Arr.isReadonlyArrayNonEmpty(nodeValues)) return decide(false);
1951
+ matchThis = true;
1952
+ } else if (isListObject(thisFrame)) {
1953
+ const listValue = asArray(thisFrame["@list"])[0];
1954
+ if (isListObject(nodeValues[0])) {
1955
+ const nodeListValues = nodeValues[0]["@list"];
1956
+ if (isValueObject(listValue)) matchThis = nodeListValues.some((lv) => valueMatch(listValue, lv));
1957
+ else if (isObject(listValue)) matchThis = nodeListValues.some((lv) => nodeMatch(state, listValue, lv, flags));
1958
+ }
1959
+ } else if (isValueObject(thisFrame)) matchThis = nodeValues.some((nv) => valueMatch(thisFrame, nv));
1960
+ else if (isSubjectReference(thisFrame)) matchThis = nodeValues.some((nv) => nodeMatch(state, thisFrame, nv, flags));
1961
+ else if (isObject(thisFrame)) matchThis = Arr.isReadonlyArrayNonEmpty(nodeValues);
1962
+ }
1963
+ if (!matchThis && flags.requireAll) return decide(false);
1964
+ matchesSome = matchesSome || matchThis;
1965
+ return false;
1966
+ });
1967
+ return Option.getOrElse(decided, () => wildcard || matchesSome);
1968
+ };
1969
+ const nodeMatch = (state, pattern, value, flags) => {
1970
+ if (!isObject(value) || !hasOwn(value, "@id")) return false;
1971
+ const node = state.subjects[value["@id"]];
1972
+ return node !== void 0 && filterSubject(state, node, pattern, flags);
1973
+ };
1974
+ const lowerIfString = (s) => isString$1(s) ? s.toLowerCase() : s;
1975
+ const valueMatch = (pattern, value) => {
1976
+ if (!isObject(pattern)) return true;
1977
+ const v1 = value["@value"];
1978
+ const t1 = value["@type"];
1979
+ const l1 = value["@language"];
1980
+ const v2 = hasOwn(pattern, "@value") ? asArray(pattern["@value"]) : [];
1981
+ const t2 = hasOwn(pattern, "@type") ? asArray(pattern["@type"]) : [];
1982
+ const l2 = hasOwn(pattern, "@language") ? asArray(pattern["@language"]) : [];
1983
+ if (Arr.isReadonlyArrayEmpty(v2) && Arr.isReadonlyArrayEmpty(t2) && Arr.isReadonlyArrayEmpty(l2)) return true;
1984
+ if (!(v2.includes(v1) || isEmptyObject(v2[0]))) return false;
1985
+ if (!(t1 === void 0 && Arr.isReadonlyArrayEmpty(t2) || t2.includes(t1) || t1 !== void 0 && isEmptyObject(t2[0]))) return false;
1986
+ if (!(l1 === void 0 && Arr.isReadonlyArrayEmpty(l2) || l2.map(lowerIfString).includes(lowerIfString(l1)) || l1 !== void 0 && isEmptyObject(l2[0]))) return false;
1987
+ return true;
1988
+ };
1989
+ const cleanupPreserve = (input, bnodesToClear, seen) => {
1990
+ if (Array.isArray(input)) return input.map((v) => cleanupPreserve(v, bnodesToClear, seen));
1991
+ if (isObject(input)) {
1992
+ if (hasOwn(input, "@preserve")) return input["@preserve"][0];
1993
+ if (isValueObject(input)) return input;
1994
+ if (isListObject(input)) {
1995
+ input["@list"] = cleanupPreserve(input["@list"], bnodesToClear, seen);
1996
+ return input;
1997
+ }
1998
+ if (seen.has(input)) return input;
1999
+ seen.add(input);
2000
+ Record.keys(input).forEach((prop) => {
2001
+ if (prop === "@id" && MutableHashSet.has(bnodesToClear, input[prop])) {
2002
+ delete input["@id"];
2003
+ return;
2004
+ }
2005
+ input[prop] = cleanupPreserve(input[prop], bnodesToClear, seen);
2006
+ });
2007
+ }
2008
+ return input;
2009
+ };
2010
+ /**
2011
+ * Replaces `@null` placeholders (from frame defaults) by `null`, dropping
2012
+ * them from arrays.
2013
+ *
2014
+ * @internal
2015
+ */
2016
+ const cleanupNull = (input, seen = /* @__PURE__ */ new WeakSet()) => {
2017
+ if (Array.isArray(input)) return input.map((v) => cleanupNull(v, seen)).filter((v) => v !== null);
2018
+ if (input === "@null") return null;
2019
+ if (isObject(input)) {
2020
+ if (seen.has(input)) return input;
2021
+ seen.add(input);
2022
+ Record.keys(input).forEach((key) => {
2023
+ input[key] = cleanupNull(input[key], seen);
2024
+ });
2025
+ }
2026
+ return input;
2027
+ };
2028
+ // src/jsonld/internal/rdf.ts
2029
+ /**
2030
+ * RDF conversion: Deserialize JSON-LD to RDF and Serialize RDF as JSON-LD
2031
+ * (JSON-LD 1.1 API §8).
2032
+ *
2033
+ * @internal
2034
+ */
2035
+ const blankNode = (id) => blankNode$1(id.slice(2));
2036
+ /**
2037
+ * The nodes of the IRIs seen by the current `toRdf` (none for an IRI that
2038
+ * is not well-formed), so that an IRI that recurs (a property, a type, a
2039
+ * datatype, a node) is validated and made into a node once. `toRdf` runs
2040
+ * synchronously, and empties it before and after.
2041
+ */
2042
+ const iriNodes = MutableHashMap.empty();
2043
+ /** The node of an IRI, if it is well-formed. */
2044
+ const iriNode = (iri) => {
2045
+ const cached = MutableHashMap.get(iriNodes, iri);
2046
+ if (Option.isSome(cached)) return cached.value;
2047
+ const node = isWellFormedIri(iri) ? Option.some(namedNode(iri)) : Option.none();
2048
+ MutableHashMap.set(iriNodes, iri, node);
2049
+ return node;
2050
+ };
2051
+ const toResource = (id) => isBlankNodeId(id) ? Option.some(blankNode(id)) : iriNode(id);
2052
+ /**
2053
+ * Converts expanded JSON-LD to quads.
2054
+ *
2055
+ * @internal
2056
+ */
2057
+ const toRdf$1 = (expanded, options) => {
2058
+ const issuer = new IdIssuer();
2059
+ MutableHashMap.clear(iriNodes);
2060
+ const rdfType = namedNode(RDF_TYPE);
2061
+ const nodeMap = { "@default": {} };
2062
+ generateNodeMap(expanded, nodeMap, issuer);
2063
+ const quads = [];
2064
+ Arr.sort(Record.keys(nodeMap), compareStrings).forEach((graphName) => {
2065
+ const graphTerm = graphName === "@default" ? Option.some(defaultGraph) : toResource(graphName);
2066
+ const graph = nodeMap[graphName];
2067
+ if (Option.isNone(graphTerm) || graph === void 0) return;
2068
+ const g = graphTerm.value;
2069
+ Arr.sort(Record.keys(graph), compareStrings).forEach((subject) => {
2070
+ const s = toResource(subject);
2071
+ const node = graph[subject];
2072
+ if (Option.isNone(s) || node === void 0) return;
2073
+ Arr.sort(Record.keys(node), compareStrings).forEach((property) => {
2074
+ const values = node[property];
2075
+ if (property === "@type") {
2076
+ values.forEach((type) => {
2077
+ const o = toResource(type);
2078
+ if (Option.isSome(o)) quads.push(quad(s.value, rdfType, o.value, g));
2079
+ });
2080
+ return;
2081
+ }
2082
+ if (property.startsWith("@")) return;
2083
+ const p = isBlankNodeId(property) ? Option.none() : iriNode(property);
2084
+ if (Option.isNone(p)) return;
2085
+ values.forEach((item) => {
2086
+ const listTriples = [];
2087
+ const o = objectToRdf(item, listTriples, issuer, options);
2088
+ if (Option.isSome(o)) quads.push(quad(s.value, p.value, o.value, g));
2089
+ listTriples.forEach(([ls, lp, lo]) => quads.push(quad(ls, lp, lo, g)));
2090
+ });
2091
+ });
2092
+ });
2093
+ });
2094
+ MutableHashMap.clear(iriNodes);
2095
+ return quads;
2096
+ };
2097
+ const toDoubleString = (n) => n.toExponential(15).replace(/(\d)0*e\+?/, "$1E");
2098
+ const objectToRdf = (item, triples, issuer, options) => {
2099
+ if (!isValueObject(item) && !isListObject(item)) return toResource(item["@id"]);
2100
+ if (isListObject(item)) return Option.some(listToRdf(item["@list"], triples, issuer, options));
2101
+ let value = item["@value"];
2102
+ const type = item["@type"];
2103
+ const typed = type !== void 0 && type !== null;
2104
+ if (typed && type !== "@json" && Option.isNone(iriNode(type))) return Option.none();
2105
+ if ("@language" in item && !isWellFormedLanguage(item["@language"])) return Option.none();
2106
+ let datatype;
2107
+ if (type === "@json") {
2108
+ value = canonicalJson(value);
2109
+ datatype = RDF_JSON;
2110
+ } else if (Predicate.isBoolean(value)) {
2111
+ value = value ? "true" : "false";
2112
+ datatype = typed ? type : XSD_BOOLEAN;
2113
+ } else if (Predicate.isNumber(value) && (!Number.isInteger(value) || Math.abs(value) >= 1e21 || type === "http://www.w3.org/2001/XMLSchema#double")) {
2114
+ value = toDoubleString(value);
2115
+ datatype = typed ? type : XSD_DOUBLE;
2116
+ } else if (Predicate.isNumber(value)) {
2117
+ value = value.toFixed(0);
2118
+ datatype = typed ? type : XSD_INTEGER;
2119
+ } else datatype = typed ? type : "@language" in item ? RDF_LANG_STRING : XSD_STRING;
2120
+ if ("@direction" in item && Option.isSome(options.rdfDirection)) {
2121
+ const language = "@language" in item ? String(item["@language"]).toLowerCase() : "";
2122
+ if (options.rdfDirection.value === "i18n-datatype") return Option.some(literal(String(value), namedNode(`${I18N}${language}_${item["@direction"]}`)));
2123
+ const literal$1 = blankNode(issuer.issue());
2124
+ triples.push([
2125
+ literal$1,
2126
+ namedNode(RDF_VALUE),
2127
+ literal(String(value))
2128
+ ]);
2129
+ if ("@language" in item) triples.push([
2130
+ literal$1,
2131
+ namedNode(RDF_LANGUAGE),
2132
+ literal(language)
2133
+ ]);
2134
+ triples.push([
2135
+ literal$1,
2136
+ namedNode(RDF_DIRECTION),
2137
+ literal(item["@direction"])
2138
+ ]);
2139
+ return Option.some(literal$1);
2140
+ }
2141
+ if ("@language" in item) return Option.some(literal(String(value), String(item["@language"])));
2142
+ return Option.some(literal(String(value), Option.getOrElse(iriNode(datatype), () => namedNode(datatype))));
2143
+ };
2144
+ const listToRdf = (list, triples, issuer, options) => {
2145
+ const nil = namedNode(RDF_NIL);
2146
+ const bnodes = list.map(() => blankNode(issuer.issue()));
2147
+ const first = namedNode(RDF_FIRST);
2148
+ const rest = namedNode(RDF_REST);
2149
+ bnodes.forEach((subject, i) => {
2150
+ const embedded = [];
2151
+ const o = objectToRdf(list[i], embedded, issuer, options);
2152
+ if (Option.isSome(o)) triples.push([
2153
+ subject,
2154
+ first,
2155
+ o.value
2156
+ ]);
2157
+ triples.push([
2158
+ subject,
2159
+ rest,
2160
+ bnodes[i + 1] ?? nil
2161
+ ]);
2162
+ embedded.forEach((triple) => triples.push(triple));
2163
+ });
2164
+ return bnodes[0] ?? nil;
2165
+ };
2166
+ const termId = (t) => isBlankNode(t) ? `_:${t.value}` : isNamedNode(t) ? t.value : isDefaultGraph(t) ? "@default" : t.key;
2167
+ const DOUBLE_RE = /^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?$|^(\+|-)?INF$|^NaN$/;
2168
+ /**
2169
+ * Serialize RDF as JSON-LD algorithm.
2170
+ *
2171
+ * @internal
2172
+ */
2173
+ const fromRdf$1 = (quads, options) => {
2174
+ const defaultGraph = {};
2175
+ const graphMap = {};
2176
+ graphMap["@default"] = defaultGraph;
2177
+ const referencedOnce = {};
2178
+ const compoundLiteralSubjects = {};
2179
+ const nilUsages = {};
2180
+ const seen = MutableHashSet.empty();
2181
+ const compoundLiterals = Option.isSome(options.rdfDirection) && options.rdfDirection.value === "compound-literal";
2182
+ Iterable.forEach(quads, (q) => {
2183
+ const before = MutableHashSet.size(seen);
2184
+ if (MutableHashSet.size(MutableHashSet.add(seen, q.key)) === before) return;
2185
+ const name = termId(q.graph);
2186
+ const nodeMap = getOrInit(graphMap, name, () => ({}));
2187
+ const compoundMap = getOrInit(compoundLiteralSubjects, name, () => MutableHashSet.empty());
2188
+ const usages = getOrInit(nilUsages, name, () => []);
2189
+ if (name !== "@default" && !hasOwn(defaultGraph, name)) defaultGraph[name] = { "@id": name };
2190
+ const subject = termId(q.subject);
2191
+ const predicate = q.predicate.value;
2192
+ const object = q.object;
2193
+ const node = getOrInit(nodeMap, subject, () => ({ "@id": subject }));
2194
+ if (compoundLiterals && predicate === "http://www.w3.org/1999/02/22-rdf-syntax-ns#direction") MutableHashSet.add(compoundMap, subject);
2195
+ const isBlank = isBlankNode(object);
2196
+ const isResource = isBlank || isNamedNode(object);
2197
+ const objectId = isResource ? termId(object) : "";
2198
+ if (isResource && !hasOwn(nodeMap, objectId)) nodeMap[objectId] = { "@id": objectId };
2199
+ if (predicate === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && isResource && !options.useRdfType) {
2200
+ const types = getOrInit(node, "@type", () => []);
2201
+ if (!types.includes(objectId)) types.push(objectId);
2202
+ return;
2203
+ }
2204
+ const value = rdfToObject(object, options);
2205
+ const values = getOrInit(node, predicate, () => []);
2206
+ let stored = value;
2207
+ const existing = values.find((v) => deepEqual(v, value));
2208
+ if (existing === void 0) values.push(value);
2209
+ else stored = existing;
2210
+ if (isResource && objectId === "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") usages.push({
2211
+ node,
2212
+ property: predicate,
2213
+ value: stored
2214
+ });
2215
+ else if (isResource && hasOwn(referencedOnce, objectId)) referencedOnce[objectId] = false;
2216
+ else if (isBlank) referencedOnce[objectId] = {
2217
+ node,
2218
+ property: predicate,
2219
+ value: stored
2220
+ };
2221
+ });
2222
+ Record.keys(graphMap).forEach((name) => {
2223
+ const graphObject = graphMap[name];
2224
+ if (graphObject === void 0) return;
2225
+ Iterable.forEach(compoundLiteralSubjects[name] ?? [], (cl) => {
2226
+ const clEntry = referencedOnce[cl];
2227
+ if (!clEntry) return;
2228
+ const { node, property } = clEntry;
2229
+ const clNode = graphObject[cl];
2230
+ delete graphObject[cl];
2231
+ if (clNode === void 0) return;
2232
+ node[property].forEach((clReference) => {
2233
+ if (clReference["@id"] !== cl) return;
2234
+ delete clReference["@id"];
2235
+ clReference["@value"] = clNode[RDF_VALUE]?.[0]?.["@value"];
2236
+ if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#language" in clNode) {
2237
+ const lang = clNode[RDF_LANGUAGE][0]["@value"];
2238
+ if (!Predicate.isString(lang) || !isWellFormedLanguage(lang)) fail("invalid language-tagged string");
2239
+ clReference["@language"] = lang;
2240
+ }
2241
+ if ("http://www.w3.org/1999/02/22-rdf-syntax-ns#direction" in clNode) {
2242
+ const dir = clNode[RDF_DIRECTION][0]["@value"];
2243
+ if (dir !== "ltr" && dir !== "rtl") fail("invalid base direction");
2244
+ clReference["@direction"] = dir;
2245
+ }
2246
+ });
2247
+ });
2248
+ if (!("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" in graphObject)) return;
2249
+ (nilUsages[name] ?? []).forEach((usage) => {
2250
+ const list = [];
2251
+ const listNodes = [];
2252
+ const { head } = loop({
2253
+ node: usage.node,
2254
+ property: usage.property,
2255
+ head: usage.value,
2256
+ done: false
2257
+ }, (walk) => {
2258
+ const { node } = walk;
2259
+ if (walk.done || walk.property !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") return Option.none();
2260
+ if (!isWellFormedListNode(node, referencedOnce)) return Option.none();
2261
+ const nodeUsage = referencedOnce[node["@id"]];
2262
+ if (!nodeUsage) return Option.none();
2263
+ list.push(node[RDF_FIRST][0]);
2264
+ listNodes.push(node["@id"]);
2265
+ return Option.some({
2266
+ node: nodeUsage.node,
2267
+ property: nodeUsage.property,
2268
+ head: nodeUsage.value,
2269
+ done: !isBlankNodeId(nodeUsage.node["@id"])
2270
+ });
2271
+ });
2272
+ delete head["@id"];
2273
+ list.reverse();
2274
+ head["@list"] = list;
2275
+ listNodes.forEach((id) => {
2276
+ delete graphObject[id];
2277
+ });
2278
+ });
2279
+ });
2280
+ const result = [];
2281
+ (options.ordered ? Arr.sort(Record.keys(defaultGraph), compareStrings) : Record.keys(defaultGraph)).forEach((subject) => {
2282
+ const node = defaultGraph[subject];
2283
+ if (node === void 0) return;
2284
+ const graph = graphMap[subject];
2285
+ if (hasOwn(graphMap, subject) && subject !== "@default" && graph !== void 0) {
2286
+ const nodes = node["@graph"] = [];
2287
+ (options.ordered ? Arr.sort(Record.keys(graph), compareStrings) : Record.keys(graph)).forEach((k) => {
2288
+ const n = graph[k];
2289
+ if (n !== void 0 && !isOnlyId(n)) nodes.push(n);
2290
+ });
2291
+ }
2292
+ if (!isOnlyId(node)) result.push(node);
2293
+ });
2294
+ return result;
2295
+ };
2296
+ const isOnlyId = (n) => Record.keys(n).length === 1 && "@id" in n;
2297
+ const isWellFormedListNode = (node, referencedOnce) => {
2298
+ const id = node["@id"];
2299
+ if (!isBlankNodeId(id)) return false;
2300
+ if (!isObject(referencedOnce[id])) return false;
2301
+ const first = node[RDF_FIRST];
2302
+ const rest = node[RDF_REST];
2303
+ if (!Array.isArray(first) || first.length !== 1) return false;
2304
+ if (!Array.isArray(rest) || rest.length !== 1) return false;
2305
+ return Record.keys(node).every((k) => {
2306
+ if (k === "@id" || k === "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" || k === "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest") return true;
2307
+ const t = node["@type"];
2308
+ return k === "@type" && Array.isArray(t) && t.length === 1 && t[0] === "http://www.w3.org/1999/02/22-rdf-syntax-ns#List";
2309
+ });
2310
+ };
2311
+ const rdfToObject = (object, options) => {
2312
+ if (!isLiteral(object)) return { "@id": termId(object) };
2313
+ const result = {};
2314
+ let converted = object.value;
2315
+ let type = Option.none();
2316
+ const datatype = object.datatype.value;
2317
+ const isJson = options.processingMode !== "json-ld-1.0" && datatype === "http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON";
2318
+ if (isJson) {
2319
+ converted = Result.getOrElse(parseJson(converted), () => fail("invalid JSON literal"));
2320
+ type = Option.some("@json");
2321
+ } else if (options.useNativeTypes) {
2322
+ if (datatype === "http://www.w3.org/2001/XMLSchema#string") {} else if (datatype === "http://www.w3.org/2001/XMLSchema#boolean") {
2323
+ if (converted === "true" || converted === "1") converted = true;
2324
+ else if (converted === "false" || converted === "0") converted = false;
2325
+ else type = Option.some(datatype);
2326
+ } else if (datatype === "http://www.w3.org/2001/XMLSchema#integer" && /^[+-]?[0-9]+$/.test(converted)) {
2327
+ const n = Number(converted);
2328
+ if (Number.isSafeInteger(n)) converted = n;
2329
+ else type = Option.some(datatype);
2330
+ } else if (datatype === "http://www.w3.org/2001/XMLSchema#double" && DOUBLE_RE.test(converted)) {
2331
+ const n = Number(converted.replace(/INF$/, "Infinity"));
2332
+ if (Number.isFinite(n)) converted = n;
2333
+ else type = Option.some(datatype);
2334
+ } else if (object.language === "") type = Option.some(datatype);
2335
+ }
2336
+ if (isJson) {} else if (datatype.startsWith("https://www.w3.org/ns/i18n#") && Option.isSome(options.rdfDirection) && options.rdfDirection.value === "i18n-datatype") {
2337
+ const fragment = datatype.slice(27);
2338
+ const i = fragment.indexOf("_");
2339
+ const language = i === -1 ? fragment : fragment.slice(0, i);
2340
+ if (language !== "") result["@language"] = language;
2341
+ if (i !== -1) result["@direction"] = fragment.slice(i + 1);
2342
+ type = Option.none();
2343
+ } else if (object.language !== "") {
2344
+ result["@language"] = object.language;
2345
+ if (object.direction !== void 0) result["@direction"] = object.direction;
2346
+ type = Option.none();
2347
+ } else if (!options.useNativeTypes && datatype !== "http://www.w3.org/2001/XMLSchema#string" && Option.isNone(type)) type = Option.some(datatype);
2348
+ result["@value"] = converted;
2349
+ if (Option.isSome(type)) result["@type"] = type.value;
2350
+ return result;
2351
+ };
2352
+ // src/jsonld/JsonLd.ts
2353
+ /**
2354
+ * The JSON-LD 1.1 processor: expansion, compaction, flattening, framing and
2355
+ * conversion to and from RDF, plus a `Serialization.Codec` for the
2356
+ * `application/ld+json` media type.
2357
+ *
2358
+ * Remote documents and contexts are loaded through the `DocumentLoader`
2359
+ * service when it is provided (or through `options.documentLoader`); without
2360
+ * one, any remote reference fails with `loading remote context failed` /
2361
+ * `loading document failed`.
2362
+ *
2363
+ * @since 0.1.0
2364
+ */
2365
+ var JsonLd_exports = /* @__PURE__ */ __exportAll({
2366
+ codec: () => codec,
2367
+ compact: () => compact,
2368
+ expand: () => expand,
2369
+ flatten: () => flatten,
2370
+ format: () => format,
2371
+ frame: () => frame,
2372
+ fromRdf: () => fromRdf,
2373
+ parse: () => parse,
2374
+ parser: () => parser,
2375
+ serialize: () => serialize,
2376
+ serializer: () => serializer,
2377
+ toQuads: () => toQuads,
2378
+ toRdf: () => toRdf
2379
+ });
2380
+ /** An empty context (`{}` or `[]`), which compaction leaves out of the output. */
2381
+ const isEmptyContext = (context) => isEmptyObject(context) || Array.isArray(context) && Arr.isReadonlyArrayEmpty(context);
2382
+ const getLoader = (options) => options?.documentLoader !== void 0 ? Effect.succeed(options.documentLoader) : Effect.map(Effect.serviceOption(DocumentLoader), (o) => Option.getOrElse(o, () => none));
2383
+ /**
2384
+ * The environment of one algorithm run: documents come from `docs`, and a
2385
+ * document not loaded yet aborts the run with `NeedDocument`.
2386
+ */
2387
+ const makeEnv = (docs, options) => ({
2388
+ processingMode: options?.processingMode ?? "json-ld-1.1",
2389
+ contextCache: MutableHashMap.empty(),
2390
+ load: (url) => {
2391
+ const hit = MutableHashMap.get(docs, url);
2392
+ if (Option.isNone(hit)) throw new NeedDocument(url);
2393
+ if (Result.isFailure(hit.value)) throw hit.value.failure;
2394
+ return hit.value.success;
2395
+ }
2396
+ });
2397
+ /**
2398
+ * Runs the algorithm once. A `NeedDocument` or `JsonLdError` it throws is the
2399
+ * failure; anything else is a bug and propagates (a defect in `run`).
2400
+ */
2401
+ const attempt = (f, env) => Result.try({
2402
+ try: () => f(env),
2403
+ catch: (e) => {
2404
+ if (e instanceof NeedDocument || isJsonLdError(e)) return e;
2405
+ throw e;
2406
+ }
2407
+ });
2408
+ /**
2409
+ * Runs a pure algorithm, loading documents on demand: when the algorithm
2410
+ * needs a document that has not been loaded yet it aborts with
2411
+ * `NeedDocument`, the document is loaded, and the algorithm is restarted.
2412
+ */
2413
+ const run = (f, options) => Effect.gen(function* () {
2414
+ const loader = yield* getLoader(options);
2415
+ const docs = MutableHashMap.empty();
2416
+ const env = makeEnv(docs, options);
2417
+ const go = Effect.suspend(() => {
2418
+ const step = attempt(f, env);
2419
+ if (Result.isSuccess(step)) return Effect.succeed(step.success);
2420
+ const failure = step.failure;
2421
+ if (!(failure instanceof NeedDocument)) return Effect.fail(failure);
2422
+ return Effect.flatMap(Effect.result(loader.load(failure.url, { profile: "http://www.w3.org/ns/json-ld#context" })), (r) => {
2423
+ MutableHashMap.set(docs, failure.url, r);
2424
+ return go;
2425
+ });
2426
+ });
2427
+ return yield* go;
2428
+ });
2429
+ const isRemoteDocument = (u) => isObject(u) && Predicate.isString(u["documentUrl"]) && "document" in u;
2430
+ /** Resolves an input (an `Input`, or a frame, which is any JSON-LD input). */
2431
+ const resolveInput = (input, options) => Effect.gen(function* () {
2432
+ if (isString$1(input)) {
2433
+ const doc = yield* (yield* getLoader(options)).load(input, { extractAllScripts: options?.extractAllScripts }).pipe(Effect.mapError((e) => e.code === "loading document failed" || e.code === "multiple context link headers" ? e : make$1("loading document failed", e.message)));
2434
+ return {
2435
+ document: doc.document,
2436
+ documentUrl: doc.documentUrl,
2437
+ contextUrl: Option.fromUndefinedOr(doc.contextUrl)
2438
+ };
2439
+ }
2440
+ if (isRemoteDocument(input)) return {
2441
+ document: input.document,
2442
+ documentUrl: input.documentUrl,
2443
+ contextUrl: Option.fromUndefinedOr(input.contextUrl)
2444
+ };
2445
+ return {
2446
+ document: input,
2447
+ documentUrl: null,
2448
+ contextUrl: Option.none()
2449
+ };
2450
+ });
2451
+ const expandSync = (env, input, frameExpansion, options) => {
2452
+ const base = options?.base !== void 0 ? options.base : input.documentUrl;
2453
+ let active = initialContext(base);
2454
+ if (options?.expandContext !== void 0 && options.expandContext !== null) {
2455
+ let ctx = options.expandContext;
2456
+ if (isObject(ctx) && "@context" in ctx) ctx = ctx["@context"];
2457
+ active = processContext(env, active, ctx, active.originalBase);
2458
+ }
2459
+ if (Option.isSome(input.contextUrl)) {
2460
+ const contextUrl = input.contextUrl.value;
2461
+ active = processContext(env, active, contextUrl, contextUrl);
2462
+ }
2463
+ let expanded = expandElement(env, active, Option.none(), input.document, input.documentUrl ?? base, {
2464
+ frameExpansion,
2465
+ ordered: options?.ordered ?? false
2466
+ });
2467
+ if (isObject(expanded) && Record.keys(expanded).length === 1 && "@graph" in expanded) expanded = expanded["@graph"];
2468
+ if (expanded === null || expanded === void 0) expanded = [];
2469
+ if (!Array.isArray(expanded)) expanded = [expanded];
2470
+ return expanded;
2471
+ };
2472
+ const compactSync = (env, expanded, context, documentUrl, options) => {
2473
+ if (isObject(context) && "@context" in context) context = context["@context"];
2474
+ const compactToRelative = options?.compactToRelative ?? true;
2475
+ const base = options?.base !== void 0 && options.base !== null ? options.base : compactToRelative ? documentUrl : null;
2476
+ const contextBase = isString$1(context) ? context : options?.base ?? documentUrl ?? null;
2477
+ let active = initialContext(base);
2478
+ active = processContext(env, active, context ?? null, contextBase);
2479
+ const compactOptions = {
2480
+ compactArrays: options?.compactArrays ?? true,
2481
+ ordered: options?.ordered ?? false,
2482
+ compactToRelative
2483
+ };
2484
+ let compacted = compactElement(env, active, Option.none(), expanded, compactOptions);
2485
+ if (Array.isArray(compacted)) compacted = Arr.isReadonlyArrayEmpty(compacted) ? {} : { [compactIri(env, active, "@graph", null, true, false, compactOptions)]: compacted };
2486
+ if (compacted === null || compacted === void 0) compacted = {};
2487
+ if (context !== null && context !== void 0 && !isEmptyContext(context)) compacted = {
2488
+ "@context": context,
2489
+ ...compacted
2490
+ };
2491
+ return compacted;
2492
+ };
2493
+ /**
2494
+ * Expands a JSON-LD document (JSON-LD 1.1 API, Expansion Algorithm).
2495
+ *
2496
+ * @since 0.1.0
2497
+ * @category algorithms
2498
+ */
2499
+ const expand = (input, options) => Effect.flatMap(resolveInput(input, options), (resolved) => run((env) => expandSync(env, resolved, false, options), options));
2500
+ /**
2501
+ * Compacts a JSON-LD document against a context (JSON-LD 1.1 API,
2502
+ * Compaction Algorithm). The context may be a context definition, an array
2503
+ * of contexts, an IRI, or a document with an `@context` entry.
2504
+ *
2505
+ * @since 0.1.0
2506
+ * @category algorithms
2507
+ */
2508
+ const compact = (input, context, options) => Effect.flatMap(resolveInput(input, options), (resolved) => run((env) => {
2509
+ const expanded = expandSync(env, resolved, false, {
2510
+ ...options,
2511
+ ordered: false
2512
+ });
2513
+ return compactSync(env, expanded, context, resolved.documentUrl, options);
2514
+ }, options));
2515
+ /**
2516
+ * Flattens a JSON-LD document (JSON-LD 1.1 API, Flattening Algorithm),
2517
+ * optionally compacting the result.
2518
+ *
2519
+ * @since 0.1.0
2520
+ * @category algorithms
2521
+ */
2522
+ const flatten = (input, context, options) => Effect.flatMap(resolveInput(input, options), (resolved) => run((env) => {
2523
+ const expanded = expandSync(env, resolved, false, options);
2524
+ const flattened = flattenExpanded(expanded, options?.ordered ?? false);
2525
+ if (context === void 0 || context === null) return flattened;
2526
+ return compactSync(env, flattened, context, resolved.documentUrl, options);
2527
+ }, options));
2528
+ /**
2529
+ * Frames a JSON-LD document (JSON-LD 1.1 Framing).
2530
+ *
2531
+ * @since 0.1.0
2532
+ * @category algorithms
2533
+ */
2534
+ const frame = (input, frameInput, options) => Effect.gen(function* () {
2535
+ const resolved = yield* resolveInput(input, options);
2536
+ const resolvedFrame = yield* resolveInput(frameInput, options);
2537
+ return yield* run((env) => frameSync(env, resolved, resolvedFrame, options), options);
2538
+ });
2539
+ /** The `@context` entry of a document (`null` when it has none). */
2540
+ const contextOf = (document) => document["@context"] ?? null;
2541
+ const frameSync = (env, resolved, resolvedFrame, options) => {
2542
+ const frameDocument = resolvedFrame.document;
2543
+ if (!isObject(frameDocument) && !Array.isArray(frameDocument)) return fail("invalid frame", "a frame must be a JSON object");
2544
+ const context = isObject(frameDocument) ? contextOf(frameDocument) : null;
2545
+ const base = options?.base !== void 0 ? options.base : resolved.documentUrl;
2546
+ const frameBase = resolvedFrame.documentUrl ?? base;
2547
+ const frameContext = processContext(env, initialContext(frameBase), context, frameBase);
2548
+ const merged = !(isObject(frameDocument) && Record.keys(frameDocument).some((k) => expandIri(env, frameContext, k, true) === "@graph"));
2549
+ const expanded = expandSync(env, resolved, false, {
2550
+ ...options,
2551
+ ordered: false
2552
+ });
2553
+ const expandedFrame = expandSync(env, resolvedFrame, true, {
2554
+ ...options,
2555
+ ordered: false
2556
+ });
2557
+ const is11 = env.processingMode !== "json-ld-1.0";
2558
+ const framed = frame$1(expanded, expandedFrame, {
2559
+ embed: options?.embed ?? "@once",
2560
+ explicit: options?.explicit ?? false,
2561
+ omitDefault: options?.omitDefault ?? false,
2562
+ requireAll: options?.requireAll ?? false,
2563
+ ordered: options?.ordered ?? false,
2564
+ merged,
2565
+ is11
2566
+ });
2567
+ const compactToRelative = options?.compactToRelative ?? true;
2568
+ let active = initialContext(options?.base != null ? options.base : compactToRelative ? resolved.documentUrl : null);
2569
+ active = processContext(env, active, context, frameBase);
2570
+ const compactOptions = {
2571
+ compactArrays: options?.compactArrays ?? true,
2572
+ ordered: options?.ordered ?? false,
2573
+ compactToRelative
2574
+ };
2575
+ const omitGraph = options?.omitGraph ?? is11;
2576
+ let compacted = compactElement(env, active, Option.none(), framed, compactOptions);
2577
+ if (omitGraph && Array.isArray(compacted)) {
2578
+ if (compacted.length === 1 && compactOptions.compactArrays) compacted = compacted[0];
2579
+ } else if (!omitGraph && isObject(compacted)) compacted = [compacted];
2580
+ if (Array.isArray(compacted)) compacted = { [compactIri(env, active, "@graph", null, true, false, compactOptions)]: compacted };
2581
+ if (compacted === null || compacted === void 0) compacted = {};
2582
+ if (context !== null && !isEmptyContext(context)) compacted = {
2583
+ "@context": context,
2584
+ ...compacted
2585
+ };
2586
+ return cleanupNull(compacted);
2587
+ };
2588
+ /**
2589
+ * Converts a JSON-LD document to an RDF dataset (Deserialize JSON-LD to RDF
2590
+ * Algorithm).
2591
+ *
2592
+ * @since 0.1.0
2593
+ * @category algorithms
2594
+ */
2595
+ const toRdf = (input, options) => Effect.map(toQuads(input, options), fromIterable);
2596
+ /**
2597
+ * Like `toRdf`, but returns the quads in document order.
2598
+ *
2599
+ * @since 0.1.0
2600
+ * @category algorithms
2601
+ */
2602
+ const toQuads = (input, options) => quadsOf(input, options);
2603
+ /** `toQuads` over any parsed JSON document. */
2604
+ const quadsOf = (input, options) => Effect.flatMap(resolveInput(input, options), (resolved) => run((env) => {
2605
+ const expanded = expandSync(env, resolved, false, options);
2606
+ return toRdf$1(expanded, {
2607
+ produceGeneralizedRdf: options?.produceGeneralizedRdf ?? false,
2608
+ rdfDirection: Option.fromNullishOr(options?.rdfDirection)
2609
+ });
2610
+ }, options));
2611
+ /**
2612
+ * Converts RDF quads to expanded JSON-LD (Serialize RDF as JSON-LD
2613
+ * Algorithm).
2614
+ *
2615
+ * @since 0.1.0
2616
+ * @category algorithms
2617
+ */
2618
+ const fromRdf = (quads, options) => Effect.try({
2619
+ try: () => fromRdf$1(quads, {
2620
+ rdfDirection: Option.fromNullishOr(options?.rdfDirection),
2621
+ useNativeTypes: options?.useNativeTypes ?? false,
2622
+ useRdfType: options?.useRdfType ?? false,
2623
+ ordered: options?.ordered ?? false,
2624
+ processingMode: options?.processingMode ?? "json-ld-1.1"
2625
+ }),
2626
+ catch: (e) => isJsonLdError(e) ? e : make$1("invalid JSON literal", String(e))
2627
+ });
2628
+ /**
2629
+ * The JSON-LD format.
2630
+ *
2631
+ * @since 0.1.0
2632
+ * @category formats
2633
+ */
2634
+ const format = makeFormat({
2635
+ name: "JSON-LD",
2636
+ mediaType: "application/ld+json",
2637
+ extensions: ["jsonld"],
2638
+ datasets: true
2639
+ });
2640
+ const trace = {
2641
+ module: "JsonLd",
2642
+ format
2643
+ };
2644
+ const JSON_WS = /[ \t\n\r]*/y;
2645
+ /** Finds the offset of the first JSON syntax error in `input`. */
2646
+ const jsonErrorOffset = (input) => {
2647
+ let i = 0;
2648
+ const scan = (re) => {
2649
+ re.lastIndex = i;
2650
+ re.exec(input);
2651
+ i = re.lastIndex;
2652
+ };
2653
+ const ws = () => scan(JSON_WS);
2654
+ const stop = () => {
2655
+ throw i;
2656
+ };
2657
+ const literal = (word) => {
2658
+ if (input.startsWith(word, i)) i += word.length;
2659
+ else stop();
2660
+ };
2661
+ const string = () => {
2662
+ i++;
2663
+ loop(true, () => {
2664
+ if (i >= input.length || input[i] === "\"") return Option.none();
2665
+ if (input[i] === "\\") i++;
2666
+ else if (input.charCodeAt(i) < 32) stop();
2667
+ i++;
2668
+ return Option.some(true);
2669
+ });
2670
+ if (i >= input.length) stop();
2671
+ i++;
2672
+ };
2673
+ const value = () => {
2674
+ ws();
2675
+ const c = input[i];
2676
+ if (c === "{" || c === "[") {
2677
+ const close = c === "{" ? "}" : "]";
2678
+ i++;
2679
+ ws();
2680
+ if (input[i] === close) {
2681
+ i++;
2682
+ return;
2683
+ }
2684
+ loop(true, () => {
2685
+ if (c === "{") {
2686
+ ws();
2687
+ if (input[i] !== "\"") stop();
2688
+ string();
2689
+ ws();
2690
+ if (input[i] !== ":") stop();
2691
+ i++;
2692
+ }
2693
+ value();
2694
+ ws();
2695
+ if (input[i] === ",") {
2696
+ i++;
2697
+ return Option.some(true);
2698
+ }
2699
+ if (input[i] !== close) stop();
2700
+ i++;
2701
+ return Option.none();
2702
+ });
2703
+ } else if (c === "\"") string();
2704
+ else if (c === "t") literal("true");
2705
+ else if (c === "f") literal("false");
2706
+ else if (c === "n") literal("null");
2707
+ else {
2708
+ const m = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/.exec(input.slice(i));
2709
+ if (m === null || m[0] === "") return stop();
2710
+ i += m[0].length;
2711
+ }
2712
+ };
2713
+ return Result.merge(Result.try({
2714
+ try: () => {
2715
+ value();
2716
+ ws();
2717
+ return i;
2718
+ },
2719
+ catch: () => i
2720
+ }));
2721
+ };
2722
+ const positionOf = (input) => {
2723
+ const pos = jsonErrorOffset(input);
2724
+ const before = input.slice(0, pos);
2725
+ return {
2726
+ line: before.split("\n").length,
2727
+ column: pos - before.lastIndexOf("\n")
2728
+ };
2729
+ };
2730
+ /**
2731
+ * Parses a JSON-LD document into RDF.
2732
+ *
2733
+ * @since 0.1.0
2734
+ * @category parsing
2735
+ */
2736
+ const parse = (input, options) => Effect.gen(function* () {
2737
+ const json = yield* Effect.fromResult(parseJson(input)).pipe(Effect.mapError((e) => new RdfParseError({
2738
+ format: format.name,
2739
+ message: `invalid JSON: ${String(e)}`,
2740
+ ...positionOf(input)
2741
+ })));
2742
+ const base = options?.base !== void 0 ? options.base : options?.baseIri ?? null;
2743
+ const quads = yield* quadsOf(json, {
2744
+ ...options,
2745
+ base
2746
+ }).pipe(Effect.mapError((e) => new RdfParseError({
2747
+ format: format.name,
2748
+ message: e.message
2749
+ })));
2750
+ const prefix = options?.blankNodePrefix ?? freshBlankNodePrefix();
2751
+ const graph = options?.graph;
2752
+ const relabel = (t) => isBlankNode(t) ? blankNode$1(`${prefix}${t.value}`) : t;
2753
+ return {
2754
+ dataset: fromIterable(quads.map((q) => {
2755
+ const relabelled = mapTerms(q, relabel);
2756
+ return graph !== void 0 && isDefaultGraph(relabelled.graph) ? quad(relabelled.subject, relabelled.predicate, relabelled.object, graph) : relabelled;
2757
+ })),
2758
+ prefixes: prefixesOf(json),
2759
+ baseIri: base ?? void 0
2760
+ };
2761
+ }).pipe(withParseSpan(trace, input));
2762
+ const prefixesOf = (json) => {
2763
+ const entries = [];
2764
+ const visit = (ctx) => {
2765
+ if (Array.isArray(ctx)) ctx.forEach(visit);
2766
+ else if (isObject(ctx)) Record.keys(ctx).forEach((k) => {
2767
+ if (k.startsWith("@") || k.includes(":")) return;
2768
+ const v = ctx[k];
2769
+ const iri = isString$1(v) ? v : isObject(v) && isString$1(v["@id"]) ? v["@id"] : void 0;
2770
+ if (iri !== void 0 && /[/#:]$/.test(iri) && /^[a-z][a-z0-9+.-]*:/i.test(iri)) entries.push([k, iri]);
2771
+ });
2772
+ };
2773
+ if (isObject(json)) visit(json["@context"]);
2774
+ return make(entries);
2775
+ };
2776
+ /**
2777
+ * Serialises quads as a JSON-LD document. Without a context (and without
2778
+ * prefixes) the output is expanded JSON-LD; otherwise it is compacted with
2779
+ * the given context, extended with one term per prefix.
2780
+ *
2781
+ * @since 0.1.0
2782
+ * @category serializing
2783
+ */
2784
+ const serialize = (quads, options) => Effect.gen(function* () {
2785
+ const expanded = yield* fromRdf(quads, options);
2786
+ let context = options?.context ?? null;
2787
+ if (isObject(context) && "@context" in context) context = context["@context"];
2788
+ if (options?.prefixes !== void 0 && options.prefixes.prefixes.size > 0) {
2789
+ const prefixContext = {};
2790
+ options.prefixes.prefixes.forEach((namespace, prefix) => {
2791
+ prefixContext[prefix] = namespace;
2792
+ });
2793
+ if (options.baseIri !== void 0) prefixContext["@base"] = options.baseIri;
2794
+ context = context === null ? prefixContext : Array.isArray(context) ? [prefixContext, ...context] : [prefixContext, context];
2795
+ }
2796
+ const output = context === null ? expanded : yield* compact(expanded, context, {
2797
+ base: options?.baseIri ?? null,
2798
+ compactArrays: options?.compactArrays,
2799
+ processingMode: options?.processingMode,
2800
+ documentLoader: options?.documentLoader
2801
+ });
2802
+ return yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown, { space: options?.indent ?? 2 }))(output);
2803
+ }).pipe(Effect.mapError((e) => new RdfSerializeError({
2804
+ format: format.name,
2805
+ message: e.message
2806
+ })), withSerializeSpan(trace));
2807
+ /**
2808
+ * The JSON-LD parser.
2809
+ *
2810
+ * @since 0.1.0
2811
+ * @category parsing
2812
+ */
2813
+ const parser = makeParser({
2814
+ format,
2815
+ parse
2816
+ });
2817
+ /**
2818
+ * The JSON-LD serializer.
2819
+ *
2820
+ * @since 0.1.0
2821
+ * @category serializing
2822
+ */
2823
+ const serializer = makeSerializer({
2824
+ format,
2825
+ serialize
2826
+ });
2827
+ /**
2828
+ * The JSON-LD codec.
2829
+ *
2830
+ * @since 0.1.0
2831
+ * @category codecs
2832
+ */
2833
+ const codec = makeCodec(parser, serializer);
2834
+ export { flatten as a, fromRdf as c, serialize as d, serializer as f, expand as i, parse as l, toRdf as m, codec as n, format as o, toQuads as p, compact as r, frame as s, JsonLd_exports as t, parser as u };
2835
+
2836
+ //# sourceMappingURL=JsonLd-DOwS2FHg.mjs.map