@thomasfosterau/effect-rdf 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2250 -1
- package/dist/Algebra-CGG4oae3.mjs +433 -0
- package/dist/Algebra-CGG4oae3.mjs.map +1 -0
- package/dist/Algebra-uGsIEOUA.d.mts +446 -0
- package/dist/Ast-CPRZmBvk.mjs +552 -0
- package/dist/Ast-CPRZmBvk.mjs.map +1 -0
- package/dist/Ast-vcw2W-lf.d.mts +827 -0
- package/dist/Bindings-Ck3m7JRC.mjs +249 -0
- package/dist/Bindings-Ck3m7JRC.mjs.map +1 -0
- package/dist/Bindings-DiKpBd7f.d.mts +153 -0
- package/dist/ClientErrors-CpXdFX5u.mjs +128 -0
- package/dist/ClientErrors-CpXdFX5u.mjs.map +1 -0
- package/dist/ClientErrors-D4IZHUM-.d.mts +101 -0
- package/dist/ClientFormats-CXomkXLV.mjs +73 -0
- package/dist/ClientFormats-CXomkXLV.mjs.map +1 -0
- package/dist/ClientFormats-Dm57ZPwR.d.mts +36 -0
- package/dist/Csv2Json-DynEcwCh.mjs +194 -0
- package/dist/Csv2Json-DynEcwCh.mjs.map +1 -0
- package/dist/Csv2Json-aXNVDoXQ.d.mts +40 -0
- package/dist/Csv2Rdf-8maXP6mt.d.mts +41 -0
- package/dist/Csv2Rdf-DuSEkaKE.mjs +161 -0
- package/dist/Csv2Rdf-DuSEkaKE.mjs.map +1 -0
- package/dist/Dataset-BlmlcI7J.mjs +782 -0
- package/dist/Dataset-BlmlcI7J.mjs.map +1 -0
- package/dist/Dataset-DS3ESOcO.d.mts +426 -0
- package/dist/Dataset.d.mts +2 -0
- package/dist/Dataset.mjs +1 -0
- package/dist/Datatype-CxMpamHC.d.mts +212 -0
- package/dist/Datatype-DQvkNkiH.mjs +1001 -0
- package/dist/Datatype-DQvkNkiH.mjs.map +1 -0
- package/dist/Dialect-8ChFj5EX.d.mts +113 -0
- package/dist/Dialect-CzVH38uo.mjs +165 -0
- package/dist/Dialect-CzVH38uo.mjs.map +1 -0
- package/dist/DocumentLoader-D3lZREnB.mjs +346 -0
- package/dist/DocumentLoader-D3lZREnB.mjs.map +1 -0
- package/dist/DocumentLoader-ZUCEVrW5.d.mts +178 -0
- package/dist/DublinCore-AnwqxRx6.mjs +137 -0
- package/dist/DublinCore-AnwqxRx6.mjs.map +1 -0
- package/dist/DublinCore-Dq-tVA5d.d.mts +119 -0
- package/dist/Engine-CYPB3g4h.d.mts +144 -0
- package/dist/Engine-DF8PN7g-.mjs +872 -0
- package/dist/Engine-DF8PN7g-.mjs.map +1 -0
- package/dist/Errors-CMdV1RhU.mjs +37 -0
- package/dist/Errors-CMdV1RhU.mjs.map +1 -0
- package/dist/Errors-u2bDjUeM.d.mts +30 -0
- package/dist/Evaluator-DEsU4d1o.d.mts +50 -0
- package/dist/Evaluator-DOY2-guC.mjs +281 -0
- package/dist/Evaluator-DOY2-guC.mjs.map +1 -0
- package/dist/Exif-CpqniYQd.d.mts +78 -0
- package/dist/Exif-DjkCfEB-.mjs +89 -0
- package/dist/Exif-DjkCfEB-.mjs.map +1 -0
- package/dist/Expression-BIMMvduQ.mjs +230 -0
- package/dist/Expression-BIMMvduQ.mjs.map +1 -0
- package/dist/Expression-W8A9cyX7.d.mts +89 -0
- package/dist/Extract-Bop85jES.mjs +220 -0
- package/dist/Extract-Bop85jES.mjs.map +1 -0
- package/dist/Extract-C_pCvuTC.d.mts +88 -0
- package/dist/Federation-BcNrozc1.d.mts +52 -0
- package/dist/Federation-CHScBkaK.mjs +130 -0
- package/dist/Federation-CHScBkaK.mjs.map +1 -0
- package/dist/Functions-AvjNcId_.mjs +1346 -0
- package/dist/Functions-AvjNcId_.mjs.map +1 -0
- package/dist/Functions-OQJZP-F6.d.mts +111 -0
- package/dist/Generator-C52mmq01.d.mts +50 -0
- package/dist/Generator-D3utCJC7.mjs +205 -0
- package/dist/Generator-D3utCJC7.mjs.map +1 -0
- package/dist/Grammar-CPlSxGH6.mjs +200 -0
- package/dist/Grammar-CPlSxGH6.mjs.map +1 -0
- package/dist/Grammar-CRhnRoCu.d.mts +148 -0
- package/dist/Grammar-D6jZdJQ3.d.mts +169 -0
- package/dist/Grammar-mQ8CgE1M.mjs +258 -0
- package/dist/Grammar-mQ8CgE1M.mjs.map +1 -0
- package/dist/GraphStore-DhUa4nFO.d.mts +45 -0
- package/dist/GraphStore-DvbqwKy1.mjs +212 -0
- package/dist/GraphStore-DvbqwKy1.mjs.map +1 -0
- package/dist/Iri-BB8Ks-BF.d.mts +84 -0
- package/dist/Iri-Cr92gsQV.mjs +232 -0
- package/dist/Iri-Cr92gsQV.mjs.map +1 -0
- package/dist/Iri.d.mts +2 -0
- package/dist/Iri.mjs +1 -0
- package/dist/Isomorphism-B6qTY-xy.d.mts +28 -0
- package/dist/Isomorphism-BmqxhKyJ.mjs +232 -0
- package/dist/Isomorphism-BmqxhKyJ.mjs.map +1 -0
- package/dist/Isomorphism-DInKnWIy.mjs +390 -0
- package/dist/Isomorphism-DInKnWIy.mjs.map +1 -0
- package/dist/Isomorphism-DvSfZXLR.d.mts +37 -0
- package/dist/Isomorphism.d.mts +2 -0
- package/dist/Isomorphism.mjs +1 -0
- package/dist/JsonLd-DOwS2FHg.mjs +2836 -0
- package/dist/JsonLd-DOwS2FHg.mjs.map +1 -0
- package/dist/JsonLd-DobFrQNa.d.mts +242 -0
- package/dist/JsonLdError-C9J-BxfG.mjs +106 -0
- package/dist/JsonLdError-C9J-BxfG.mjs.map +1 -0
- package/dist/JsonLdError-DSOfHkOy.d.mts +43 -0
- package/dist/LanguageTag-BCu8rcmX.d.mts +38 -0
- package/dist/LanguageTag-BcOpMGZ4.mjs +89 -0
- package/dist/LanguageTag-BcOpMGZ4.mjs.map +1 -0
- package/dist/LanguageTag.d.mts +2 -0
- package/dist/LanguageTag.mjs +1 -0
- package/dist/Lexical-Cg0JHrf6.mjs +243 -0
- package/dist/Lexical-Cg0JHrf6.mjs.map +1 -0
- package/dist/Lexical-D3zySYVS.d.mts +163 -0
- package/dist/Manifest-B6xf6mUc.mjs +148 -0
- package/dist/Manifest-B6xf6mUc.mjs.map +1 -0
- package/dist/Manifest-DQUMRBFr.d.mts +98 -0
- package/dist/Mapping-BgG74x3U.d.mts +63 -0
- package/dist/Mapping-Dc1ZGirk.mjs +259 -0
- package/dist/Mapping-Dc1ZGirk.mjs.map +1 -0
- package/dist/Mcp-1DwTTKOK.mjs +48 -0
- package/dist/Mcp-1DwTTKOK.mjs.map +1 -0
- package/dist/Mcp-d-pX9erx.d.mts +25 -0
- package/dist/Message-CK_DGQuu.mjs +95 -0
- package/dist/Message-CK_DGQuu.mjs.map +1 -0
- package/dist/Message-fIvTJSXM.d.mts +49 -0
- package/dist/Metadata-BbffwGDZ.mjs +445 -0
- package/dist/Metadata-BbffwGDZ.mjs.map +1 -0
- package/dist/Metadata-CEt3yc1-.d.mts +901 -0
- package/dist/Metadata-D4HsQNXr.mjs +1273 -0
- package/dist/Metadata-D4HsQNXr.mjs.map +1 -0
- package/dist/Metadata-nzS7QKRj.d.mts +350 -0
- package/dist/Model-DaMmxurZ.d.mts +293 -0
- package/dist/Model-DlPzRYhF.mjs +528 -0
- package/dist/Model-DlPzRYhF.mjs.map +1 -0
- package/dist/N3-BzyV-KIH.mjs +974 -0
- package/dist/N3-BzyV-KIH.mjs.map +1 -0
- package/dist/N3-DSLnonDn.d.mts +100 -0
- package/dist/NQuads-C1VBOJ3-.mjs +117 -0
- package/dist/NQuads-C1VBOJ3-.mjs.map +1 -0
- package/dist/NQuads-FjFZikFg.d.mts +76 -0
- package/dist/NTriples-D-kLSEAf.mjs +120 -0
- package/dist/NTriples-D-kLSEAf.mjs.map +1 -0
- package/dist/NTriples-D34OspfW.d.mts +76 -0
- package/dist/Namespace-ClTUO_ya.d.mts +42 -0
- package/dist/Namespace-DHFIsORd.mjs +75 -0
- package/dist/Namespace-DHFIsORd.mjs.map +1 -0
- package/dist/Namespace.d.mts +2 -0
- package/dist/Namespace.mjs +1 -0
- package/dist/Namespaces-Bz85vpjW.mjs +235 -0
- package/dist/Namespaces-Bz85vpjW.mjs.map +1 -0
- package/dist/Namespaces-C1jW6EDo.d.mts +178 -0
- package/dist/Optimizer-BWWQRQPY.mjs +168 -0
- package/dist/Optimizer-BWWQRQPY.mjs.map +1 -0
- package/dist/Optimizer-DUpUow6k.d.mts +26 -0
- package/dist/Options-BLBGL4HE.mjs +72 -0
- package/dist/Options-BLBGL4HE.mjs.map +1 -0
- package/dist/Options-BommQwP9.d.mts +127 -0
- package/dist/Packet-CA76wVX3.mjs +197 -0
- package/dist/Packet-CA76wVX3.mjs.map +1 -0
- package/dist/Packet-Cy5g6XuW.d.mts +130 -0
- package/dist/Parser-p1Gyr0QN.d.mts +85 -0
- package/dist/Parser-xARsOWXk.mjs +1317 -0
- package/dist/Parser-xARsOWXk.mjs.map +1 -0
- package/dist/Path-B20Yp8KE.mjs +284 -0
- package/dist/Path-B20Yp8KE.mjs.map +1 -0
- package/dist/Path-DRB8e-Zn.d.mts +181 -0
- package/dist/Pdf-B9RZn--8.d.mts +77 -0
- package/dist/Pdf-CKK6dkZn.mjs +89 -0
- package/dist/Pdf-CKK6dkZn.mjs.map +1 -0
- package/dist/PdfA-CUjSuntT.d.mts +109 -0
- package/dist/PdfA-CleOhuL6.mjs +124 -0
- package/dist/PdfA-CleOhuL6.mjs.map +1 -0
- package/dist/Photoshop-CiHo80qV.mjs +233 -0
- package/dist/Photoshop-CiHo80qV.mjs.map +1 -0
- package/dist/Photoshop-udKZ0I3N.d.mts +204 -0
- package/dist/PrefixMap-BHFPDLO-.mjs +103 -0
- package/dist/PrefixMap-BHFPDLO-.mjs.map +1 -0
- package/dist/PrefixMap-BMlXrWNd.d.mts +64 -0
- package/dist/PrefixMap.d.mts +2 -0
- package/dist/PrefixMap.mjs +1 -0
- package/dist/Processor-CMmecFsb.mjs +198 -0
- package/dist/Processor-CMmecFsb.mjs.map +1 -0
- package/dist/Processor-FJPvO0CB.d.mts +435 -0
- package/dist/Protocol-BA7OkNgp.mjs +202 -0
- package/dist/Protocol-BA7OkNgp.mjs.map +1 -0
- package/dist/Protocol-DlSoiIKB.d.mts +108 -0
- package/dist/ProtocolErrors-Ckfejnl6.d.mts +84 -0
- package/dist/ProtocolErrors-czDPVcX5.mjs +129 -0
- package/dist/ProtocolErrors-czDPVcX5.mjs.map +1 -0
- package/dist/Query-D9A6LOpP.mjs +364 -0
- package/dist/Query-D9A6LOpP.mjs.map +1 -0
- package/dist/Query-KqSkTYyG.d.mts +96 -0
- package/dist/QueryBuilder-BLK9Vfbz.mjs +674 -0
- package/dist/QueryBuilder-BLK9Vfbz.mjs.map +1 -0
- package/dist/QueryBuilder-DUqh4ECe.d.mts +529 -0
- package/dist/RdfJs-D6-49XB5.mjs +86 -0
- package/dist/RdfJs-D6-49XB5.mjs.map +1 -0
- package/dist/RdfJs-DXFqdWrd.d.mts +76 -0
- package/dist/RdfJs.d.mts +2 -0
- package/dist/RdfJs.mjs +1 -0
- package/dist/RdfJson-5aKPDlPS.d.mts +297 -0
- package/dist/RdfJson-BNocgW4f.mjs +548 -0
- package/dist/RdfJson-BNocgW4f.mjs.map +1 -0
- package/dist/RdfXml-DJ9G4gOq.mjs +1014 -0
- package/dist/RdfXml-DJ9G4gOq.mjs.map +1 -0
- package/dist/RdfXml-_N7yxWEp.d.mts +149 -0
- package/dist/Rdfs-BRVPsAjc.d.mts +84 -0
- package/dist/Rdfs-CyY2wVHI.mjs +167 -0
- package/dist/Rdfs-CyY2wVHI.mjs.map +1 -0
- package/dist/Rdfs.d.mts +2 -0
- package/dist/Rdfs.mjs +1 -0
- package/dist/Reasoner-BxYhx9s7.d.mts +94 -0
- package/dist/Reasoner-Cw90zrjv.mjs +798 -0
- package/dist/Reasoner-Cw90zrjv.mjs.map +1 -0
- package/dist/Reification-BmN4EfnM.d.mts +40 -0
- package/dist/Reification-dpqQvjDE.mjs +82 -0
- package/dist/Reification-dpqQvjDE.mjs.map +1 -0
- package/dist/Reification.d.mts +2 -0
- package/dist/Reification.mjs +1 -0
- package/dist/Report-XHs8htzK.mjs +121 -0
- package/dist/Report-XHs8htzK.mjs.map +1 -0
- package/dist/Report-hcXsc_19.d.mts +115 -0
- package/dist/Resource-B1cI8FyJ.d.mts +218 -0
- package/dist/Resource-sIEeNh15.mjs +374 -0
- package/dist/Resource-sIEeNh15.mjs.map +1 -0
- package/dist/Resource.d.mts +2 -0
- package/dist/Resource.mjs +1 -0
- package/dist/Results-BVNEC-Wt.d.mts +277 -0
- package/dist/Results-peJjGA2V.mjs +621 -0
- package/dist/Results-peJjGA2V.mjs.map +1 -0
- package/dist/ResultsStream-BhF0OcNn.mjs +639 -0
- package/dist/ResultsStream-BhF0OcNn.mjs.map +1 -0
- package/dist/ResultsStream-toYMXrOe.d.mts +100 -0
- package/dist/SemAct-CDchtk49.d.mts +96 -0
- package/dist/SemAct-CmyT4yI8.mjs +118 -0
- package/dist/SemAct-CmyT4yI8.mjs.map +1 -0
- package/dist/Serialization-DP9H5bYQ.mjs +514 -0
- package/dist/Serialization-DP9H5bYQ.mjs.map +1 -0
- package/dist/Serialization-Df8iVauT.d.mts +392 -0
- package/dist/Serialization.d.mts +2 -0
- package/dist/Serialization.mjs +1 -0
- package/dist/ServerFormats-CrRnjjf6.mjs +64 -0
- package/dist/ServerFormats-CrRnjjf6.mjs.map +1 -0
- package/dist/ServerFormats-DjC9NsO_.d.mts +36 -0
- package/dist/ServiceDescription-BERsvg-k.d.mts +54 -0
- package/dist/ServiceDescription-Dq5hxeGy.mjs +97 -0
- package/dist/ServiceDescription-Dq5hxeGy.mjs.map +1 -0
- package/dist/ShExC-Ctf-06CL.d.mts +67 -0
- package/dist/ShExC-DJbB19i3.mjs +1181 -0
- package/dist/ShExC-DJbB19i3.mjs.map +1 -0
- package/dist/ShExError-BeYFD9rv.d.mts +61 -0
- package/dist/ShExError-CVtq2NnM.mjs +64 -0
- package/dist/ShExError-CVtq2NnM.mjs.map +1 -0
- package/dist/ShExJ-C1u_wgyD.d.mts +531 -0
- package/dist/ShExJ-COiPd9Xw.mjs +532 -0
- package/dist/ShExJ-COiPd9Xw.mjs.map +1 -0
- package/dist/ShExR-ByR4mCh-.mjs +480 -0
- package/dist/ShExR-ByR4mCh-.mjs.map +1 -0
- package/dist/ShExR-CqONNNBz.d.mts +40 -0
- package/dist/ShapeMap-C422pxKl.d.mts +140 -0
- package/dist/ShapeMap-CsgKxB2G.mjs +181 -0
- package/dist/ShapeMap-CsgKxB2G.mjs.map +1 -0
- package/dist/Shapes-18GjfyBV.mjs +597 -0
- package/dist/Shapes-18GjfyBV.mjs.map +1 -0
- package/dist/Shapes-BQFDFc4Q.d.mts +306 -0
- package/dist/Sparql-BiYFMSpl.mjs +29 -0
- package/dist/Sparql-BiYFMSpl.mjs.map +1 -0
- package/dist/Sparql-DecpWTPh.d.mts +97 -0
- package/dist/SparqlClient-C_CjXbwj.mjs +333 -0
- package/dist/SparqlClient-C_CjXbwj.mjs.map +1 -0
- package/dist/SparqlClient-UPc88SHy.d.mts +290 -0
- package/dist/SparqlServer-CbUW-pVj.d.mts +71 -0
- package/dist/SparqlServer-Db7w7Cll.mjs +308 -0
- package/dist/SparqlServer-Db7w7Cll.mjs.map +1 -0
- package/dist/SqlStore-BBqFx-Wl.mjs +684 -0
- package/dist/SqlStore-BBqFx-Wl.mjs.map +1 -0
- package/dist/SqlStore-CCJo5I-e.d.mts +117 -0
- package/dist/Store-D0jmVfb3.d.mts +166 -0
- package/dist/Store-DH3Ow1GO.mjs +162 -0
- package/dist/Store-DH3Ow1GO.mjs.map +1 -0
- package/dist/Structure-BjMo4Bkc.mjs +334 -0
- package/dist/Structure-BjMo4Bkc.mjs.map +1 -0
- package/dist/Structure-n4CmDiab.d.mts +63 -0
- package/dist/Table-BGgm9nbM.mjs +538 -0
- package/dist/Table-BGgm9nbM.mjs.map +1 -0
- package/dist/Table-C3reiVrb.d.mts +261 -0
- package/dist/Term-B_4ezyXq.d.mts +619 -0
- package/dist/Term-CFLG1qu4.mjs +991 -0
- package/dist/Term-CFLG1qu4.mjs.map +1 -0
- package/dist/Term.d.mts +2 -0
- package/dist/Term.mjs +1 -0
- package/dist/TermCodec-CDZiEztW.mjs +397 -0
- package/dist/TermCodec-CDZiEztW.mjs.map +1 -0
- package/dist/TermCodec-_03bDXr0.d.mts +209 -0
- package/dist/TermCodec.d.mts +2 -0
- package/dist/TermCodec.mjs +1 -0
- package/dist/TermJson-BOPe0yve.d.mts +232 -0
- package/dist/TermJson-FAg3lvjl.mjs +142 -0
- package/dist/TermJson-FAg3lvjl.mjs.map +1 -0
- package/dist/TermJson.d.mts +2 -0
- package/dist/TermJson.mjs +1 -0
- package/dist/TermSchema-Bn9CoaYA.mjs +30 -0
- package/dist/TermSchema-Bn9CoaYA.mjs.map +1 -0
- package/dist/TermSchema-DBO6MroX.d.mts +6 -0
- package/dist/Testing-B-aPCpmu.mjs +63 -0
- package/dist/Testing-B-aPCpmu.mjs.map +1 -0
- package/dist/Testing-CF6s8P3O.d.mts +53 -0
- package/dist/Tiff-CR-2QeSI.d.mts +148 -0
- package/dist/Tiff-DlsOlZPM.mjs +169 -0
- package/dist/Tiff-DlsOlZPM.mjs.map +1 -0
- package/dist/Tools-7MdRKccr.d.mts +583 -0
- package/dist/Tools-ryxphZbI.mjs +329 -0
- package/dist/Tools-ryxphZbI.mjs.map +1 -0
- package/dist/Translate-B0YKKANS.d.mts +37 -0
- package/dist/Translate-gzWPq0Ia.mjs +308 -0
- package/dist/Translate-gzWPq0Ia.mjs.map +1 -0
- package/dist/Translation-DC9rLm2y.mjs +1535 -0
- package/dist/Translation-DC9rLm2y.mjs.map +1 -0
- package/dist/Translation-K4L9XBqX.d.mts +103 -0
- package/dist/TriG-BkqtqZ6Y.mjs +125 -0
- package/dist/TriG-BkqtqZ6Y.mjs.map +1 -0
- package/dist/TriG-xDjdDatp.d.mts +86 -0
- package/dist/Turtle-Bv1_bisW.d.mts +85 -0
- package/dist/Turtle-CZVUOtwl.mjs +133 -0
- package/dist/Turtle-CZVUOtwl.mjs.map +1 -0
- package/dist/ValidationReport-DBdJshW5.mjs +285 -0
- package/dist/ValidationReport-DBdJshW5.mjs.map +1 -0
- package/dist/ValidationReport-Dx3WxY0h.d.mts +192 -0
- package/dist/Validator-227ff9Rn.d.mts +179 -0
- package/dist/Validator-BzXMKDeJ.mjs +1162 -0
- package/dist/Validator-BzXMKDeJ.mjs.map +1 -0
- package/dist/Validator-Dl8cih5V.d.mts +207 -0
- package/dist/Validator-DmUfMbpL.mjs +568 -0
- package/dist/Validator-DmUfMbpL.mjs.map +1 -0
- package/dist/Vocab-DceKywpq.mjs +168 -0
- package/dist/Vocab-DceKywpq.mjs.map +1 -0
- package/dist/Vocab-Df-L-IwZ.d.mts +46 -0
- package/dist/Vocab-Do56UgBX.d.mts +81 -0
- package/dist/Vocab-TfpWG1Ne.mjs +118 -0
- package/dist/Vocab-TfpWG1Ne.mjs.map +1 -0
- package/dist/Vocab.d.mts +2 -0
- package/dist/Vocab.mjs +1 -0
- package/dist/Vocabulary-C6-GPOy4.d.mts +22 -0
- package/dist/Vocabulary-CnQl-_Z4.mjs +179 -0
- package/dist/Vocabulary-CnQl-_Z4.mjs.map +1 -0
- package/dist/Xml-B7iihYCS.mjs +976 -0
- package/dist/Xml-B7iihYCS.mjs.map +1 -0
- package/dist/Xml-CmfHS7SW.d.mts +267 -0
- package/dist/Xmp-D7CKA7MZ.d.mts +111 -0
- package/dist/Xmp-DCGN9pOD.mjs +307 -0
- package/dist/Xmp-DCGN9pOD.mjs.map +1 -0
- package/dist/XmpBasic-CP38jpR_.mjs +73 -0
- package/dist/XmpBasic-CP38jpR_.mjs.map +1 -0
- package/dist/XmpBasic-Cmbe53rQ.d.mts +64 -0
- package/dist/XmpMM-BfL_TgJF.mjs +73 -0
- package/dist/XmpMM-BfL_TgJF.mjs.map +1 -0
- package/dist/XmpMM-Dqm3IX8p.d.mts +63 -0
- package/dist/XmpRights-BKPtoI5L.mjs +73 -0
- package/dist/XmpRights-BKPtoI5L.mjs.map +1 -0
- package/dist/XmpRights-CaALZQz2.d.mts +63 -0
- package/dist/Xsd-Cdgx5zRB.mjs +405 -0
- package/dist/Xsd-Cdgx5zRB.mjs.map +1 -0
- package/dist/Xsd-D2elNhSm.d.mts +187 -0
- package/dist/Xsd.d.mts +2 -0
- package/dist/Xsd.mjs +1 -0
- package/dist/accessors-CEjaojuQ.mjs +28 -0
- package/dist/accessors-CEjaojuQ.mjs.map +1 -0
- package/dist/codec-Lb2T96rv.d.mts +20 -0
- package/dist/codec-QNo7IdJF.mjs +389 -0
- package/dist/codec-QNo7IdJF.mjs.map +1 -0
- package/dist/csvw/Csv2Json.d.mts +2 -0
- package/dist/csvw/Csv2Json.mjs +1 -0
- package/dist/csvw/Csv2Rdf.d.mts +2 -0
- package/dist/csvw/Csv2Rdf.mjs +1 -0
- package/dist/csvw/Datatype.d.mts +2 -0
- package/dist/csvw/Datatype.mjs +1 -0
- package/dist/csvw/Metadata.d.mts +2 -0
- package/dist/csvw/Metadata.mjs +1 -0
- package/dist/csvw/Processor.d.mts +2 -0
- package/dist/csvw/Processor.mjs +1 -0
- package/dist/csvw/Report.d.mts +2 -0
- package/dist/csvw/Report.mjs +1 -0
- package/dist/csvw/Table.d.mts +2 -0
- package/dist/csvw/Table.mjs +1 -0
- package/dist/csvw/index.d.mts +8 -0
- package/dist/csvw/index.mjs +8 -0
- package/dist/index-Cms2TYfC.d.mts +16 -0
- package/dist/index-Ct8xFmRs.d.mts +7 -0
- package/dist/index-D4QFwOjm.d.mts +28 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +17 -0
- package/dist/jsonld/DocumentLoader.d.mts +2 -0
- package/dist/jsonld/DocumentLoader.mjs +1 -0
- package/dist/jsonld/JsonLd.d.mts +2 -0
- package/dist/jsonld/JsonLd.mjs +1 -0
- package/dist/jsonld/JsonLdError.d.mts +2 -0
- package/dist/jsonld/JsonLdError.mjs +1 -0
- package/dist/jsonld/index.d.mts +4 -0
- package/dist/jsonld/index.mjs +4 -0
- package/dist/lists-D-OpQ0Ir.mjs +77 -0
- package/dist/lists-D-OpQ0Ir.mjs.map +1 -0
- package/dist/loop-D5-gNx9K.mjs +21 -0
- package/dist/loop-D5-gNx9K.mjs.map +1 -0
- package/dist/loop-DZ2hXlr_.mjs +21 -0
- package/dist/loop-DZ2hXlr_.mjs.map +1 -0
- package/dist/n3/Isomorphism.d.mts +2 -0
- package/dist/n3/Isomorphism.mjs +1 -0
- package/dist/n3/Mapping.d.mts +2 -0
- package/dist/n3/Mapping.mjs +1 -0
- package/dist/n3/Model.d.mts +2 -0
- package/dist/n3/Model.mjs +1 -0
- package/dist/n3/N3.d.mts +2 -0
- package/dist/n3/N3.mjs +1 -0
- package/dist/n3/Reasoner.d.mts +2 -0
- package/dist/n3/Reasoner.mjs +2 -0
- package/dist/n3/Vocab.d.mts +2 -0
- package/dist/n3/Vocab.mjs +1 -0
- package/dist/n3/index.d.mts +7 -0
- package/dist/n3/index.mjs +7 -0
- package/dist/ntriples/Grammar.d.mts +2 -0
- package/dist/ntriples/Grammar.mjs +1 -0
- package/dist/ntriples/Lexical.d.mts +2 -0
- package/dist/ntriples/Lexical.mjs +1 -0
- package/dist/ntriples/NQuads.d.mts +2 -0
- package/dist/ntriples/NQuads.mjs +1 -0
- package/dist/ntriples/NTriples.d.mts +2 -0
- package/dist/ntriples/NTriples.mjs +1 -0
- package/dist/ntriples/index.d.mts +5 -0
- package/dist/ntriples/index.mjs +5 -0
- package/dist/rdfjson/RdfJson.d.mts +2 -0
- package/dist/rdfjson/RdfJson.mjs +1 -0
- package/dist/rdfjson/index.d.mts +2 -0
- package/dist/rdfjson/index.mjs +1 -0
- package/dist/rdfxml/RdfXml.d.mts +2 -0
- package/dist/rdfxml/RdfXml.mjs +1 -0
- package/dist/rdfxml/Xml.d.mts +2 -0
- package/dist/rdfxml/Xml.mjs +1 -0
- package/dist/rdfxml/index.d.mts +3 -0
- package/dist/rdfxml/index.mjs +3 -0
- package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
- package/dist/serialize-96KBvKaf.mjs +1463 -0
- package/dist/serialize-96KBvKaf.mjs.map +1 -0
- package/dist/serialize-DsoXdM6n.d.mts +37 -0
- package/dist/shacl/Message.d.mts +2 -0
- package/dist/shacl/Message.mjs +1 -0
- package/dist/shacl/Path.d.mts +2 -0
- package/dist/shacl/Path.mjs +1 -0
- package/dist/shacl/Shapes.d.mts +2 -0
- package/dist/shacl/Shapes.mjs +1 -0
- package/dist/shacl/Sparql.d.mts +2 -0
- package/dist/shacl/Sparql.mjs +1 -0
- package/dist/shacl/ValidationReport.d.mts +2 -0
- package/dist/shacl/ValidationReport.mjs +1 -0
- package/dist/shacl/Validator.d.mts +2 -0
- package/dist/shacl/Validator.mjs +1 -0
- package/dist/shacl/Vocabulary.d.mts +2 -0
- package/dist/shacl/Vocabulary.mjs +1 -0
- package/dist/shacl/index.d.mts +9 -0
- package/dist/shacl/index.mjs +8 -0
- package/dist/shex/SemAct.d.mts +2 -0
- package/dist/shex/SemAct.mjs +1 -0
- package/dist/shex/ShExC.d.mts +2 -0
- package/dist/shex/ShExC.mjs +1 -0
- package/dist/shex/ShExError.d.mts +2 -0
- package/dist/shex/ShExError.mjs +1 -0
- package/dist/shex/ShExJ.d.mts +2 -0
- package/dist/shex/ShExJ.mjs +2 -0
- package/dist/shex/ShExR.d.mts +2 -0
- package/dist/shex/ShExR.mjs +1 -0
- package/dist/shex/ShapeMap.d.mts +2 -0
- package/dist/shex/ShapeMap.mjs +1 -0
- package/dist/shex/Structure.d.mts +2 -0
- package/dist/shex/Structure.mjs +2 -0
- package/dist/shex/Validator.d.mts +2 -0
- package/dist/shex/Validator.mjs +4 -0
- package/dist/shex/index.d.mts +9 -0
- package/dist/shex/index.mjs +9 -0
- package/dist/sparql/Algebra.d.mts +2 -0
- package/dist/sparql/Algebra.mjs +1 -0
- package/dist/sparql/Ast.d.mts +2 -0
- package/dist/sparql/Ast.mjs +1 -0
- package/dist/sparql/Bindings.d.mts +2 -0
- package/dist/sparql/Bindings.mjs +1 -0
- package/dist/sparql/ClientErrors.d.mts +2 -0
- package/dist/sparql/ClientErrors.mjs +1 -0
- package/dist/sparql/ClientFormats.d.mts +2 -0
- package/dist/sparql/ClientFormats.mjs +1 -0
- package/dist/sparql/Engine.d.mts +2 -0
- package/dist/sparql/Engine.mjs +1 -0
- package/dist/sparql/Errors.d.mts +2 -0
- package/dist/sparql/Errors.mjs +1 -0
- package/dist/sparql/Expression.d.mts +2 -0
- package/dist/sparql/Expression.mjs +1 -0
- package/dist/sparql/Federation.d.mts +2 -0
- package/dist/sparql/Federation.mjs +1 -0
- package/dist/sparql/Functions.d.mts +2 -0
- package/dist/sparql/Functions.mjs +1 -0
- package/dist/sparql/Generator.d.mts +2 -0
- package/dist/sparql/Generator.mjs +1 -0
- package/dist/sparql/GraphStore.d.mts +2 -0
- package/dist/sparql/GraphStore.mjs +1 -0
- package/dist/sparql/Optimizer.d.mts +2 -0
- package/dist/sparql/Optimizer.mjs +1 -0
- package/dist/sparql/Options.d.mts +2 -0
- package/dist/sparql/Options.mjs +1 -0
- package/dist/sparql/Parser.d.mts +2 -0
- package/dist/sparql/Parser.mjs +1 -0
- package/dist/sparql/Protocol.d.mts +2 -0
- package/dist/sparql/Protocol.mjs +1 -0
- package/dist/sparql/ProtocolErrors.d.mts +2 -0
- package/dist/sparql/ProtocolErrors.mjs +1 -0
- package/dist/sparql/QueryBuilder.d.mts +2 -0
- package/dist/sparql/QueryBuilder.mjs +1 -0
- package/dist/sparql/Results.d.mts +2 -0
- package/dist/sparql/Results.mjs +1 -0
- package/dist/sparql/ResultsStream.d.mts +2 -0
- package/dist/sparql/ResultsStream.mjs +1 -0
- package/dist/sparql/ServerFormats.d.mts +2 -0
- package/dist/sparql/ServerFormats.mjs +1 -0
- package/dist/sparql/ServiceDescription.d.mts +2 -0
- package/dist/sparql/ServiceDescription.mjs +1 -0
- package/dist/sparql/SparqlClient.d.mts +2 -0
- package/dist/sparql/SparqlClient.mjs +1 -0
- package/dist/sparql/SparqlServer.d.mts +2 -0
- package/dist/sparql/SparqlServer.mjs +1 -0
- package/dist/sparql/Store.d.mts +2 -0
- package/dist/sparql/Store.mjs +1 -0
- package/dist/sparql/TermSchema.d.mts +3 -0
- package/dist/sparql/TermSchema.mjs +2 -0
- package/dist/sparql/Testing.d.mts +2 -0
- package/dist/sparql/Testing.mjs +1 -0
- package/dist/sparql/Translate.d.mts +2 -0
- package/dist/sparql/Translate.mjs +1 -0
- package/dist/sparql/ai/Mcp.d.mts +2 -0
- package/dist/sparql/ai/Mcp.mjs +1 -0
- package/dist/sparql/ai/Tools.d.mts +2 -0
- package/dist/sparql/ai/Tools.mjs +1 -0
- package/dist/sparql/ai/index.d.mts +3 -0
- package/dist/sparql/ai/index.mjs +3 -0
- package/dist/sparql/index.d.mts +30 -0
- package/dist/sparql/index.mjs +29 -0
- package/dist/sparql/shacl/Evaluator.d.mts +2 -0
- package/dist/sparql/shacl/Evaluator.mjs +1 -0
- package/dist/sparql/shacl/Query.d.mts +2 -0
- package/dist/sparql/shacl/Query.mjs +1 -0
- package/dist/sparql/shacl/index.d.mts +3 -0
- package/dist/sparql/shacl/index.mjs +3 -0
- package/dist/sparql/sql/Dialect.d.mts +2 -0
- package/dist/sparql/sql/Dialect.mjs +1 -0
- package/dist/sparql/sql/SqlStore.d.mts +2 -0
- package/dist/sparql/sql/SqlStore.mjs +1 -0
- package/dist/sparql/sql/Translation.d.mts +2 -0
- package/dist/sparql/sql/Translation.mjs +1 -0
- package/dist/sparql/sql/index.d.mts +4 -0
- package/dist/sparql/sql/index.mjs +4 -0
- package/dist/stringMap-D5YIpYtR.mjs +38 -0
- package/dist/stringMap-D5YIpYtR.mjs.map +1 -0
- package/dist/tokens-C6BzeodQ.mjs +24 -0
- package/dist/tokens-C6BzeodQ.mjs.map +1 -0
- package/dist/turtle/Grammar.d.mts +3 -0
- package/dist/turtle/Grammar.mjs +3 -0
- package/dist/turtle/Manifest.d.mts +2 -0
- package/dist/turtle/Manifest.mjs +1 -0
- package/dist/turtle/TriG.d.mts +2 -0
- package/dist/turtle/TriG.mjs +1 -0
- package/dist/turtle/Turtle.d.mts +2 -0
- package/dist/turtle/Turtle.mjs +1 -0
- package/dist/turtle/index.d.mts +5 -0
- package/dist/turtle/index.mjs +5 -0
- package/dist/xmp/DublinCore.d.mts +2 -0
- package/dist/xmp/DublinCore.mjs +1 -0
- package/dist/xmp/Exif.d.mts +2 -0
- package/dist/xmp/Exif.mjs +1 -0
- package/dist/xmp/Extract.d.mts +2 -0
- package/dist/xmp/Extract.mjs +1 -0
- package/dist/xmp/Metadata.d.mts +2 -0
- package/dist/xmp/Metadata.mjs +1 -0
- package/dist/xmp/Namespaces.d.mts +2 -0
- package/dist/xmp/Namespaces.mjs +1 -0
- package/dist/xmp/Packet.d.mts +2 -0
- package/dist/xmp/Packet.mjs +1 -0
- package/dist/xmp/Pdf.d.mts +2 -0
- package/dist/xmp/Pdf.mjs +1 -0
- package/dist/xmp/PdfA.d.mts +2 -0
- package/dist/xmp/PdfA.mjs +1 -0
- package/dist/xmp/Photoshop.d.mts +2 -0
- package/dist/xmp/Photoshop.mjs +1 -0
- package/dist/xmp/Tiff.d.mts +2 -0
- package/dist/xmp/Tiff.mjs +1 -0
- package/dist/xmp/Xmp.d.mts +2 -0
- package/dist/xmp/Xmp.mjs +3 -0
- package/dist/xmp/XmpBasic.d.mts +2 -0
- package/dist/xmp/XmpBasic.mjs +1 -0
- package/dist/xmp/XmpMM.d.mts +2 -0
- package/dist/xmp/XmpMM.mjs +1 -0
- package/dist/xmp/XmpRights.d.mts +2 -0
- package/dist/xmp/XmpRights.mjs +1 -0
- package/dist/xmp/index.d.mts +15 -0
- package/dist/xmp/index.mjs +15 -0
- package/package.json +187 -3
- package/src/Dataset.ts +1085 -0
- package/src/Iri.ts +322 -0
- package/src/Isomorphism.ts +319 -0
- package/src/LanguageTag.ts +98 -0
- package/src/Namespace.ts +100 -0
- package/src/PrefixMap.ts +117 -0
- package/src/RdfJs.ts +146 -0
- package/src/Rdfs.ts +241 -0
- package/src/Reification.ts +103 -0
- package/src/Resource.ts +873 -0
- package/src/Serialization.ts +775 -0
- package/src/Term.ts +1300 -0
- package/src/TermCodec.ts +505 -0
- package/src/TermJson.ts +313 -0
- package/src/Vocab.ts +161 -0
- package/src/Xsd.ts +573 -0
- package/src/csvw/Csv2Json.ts +265 -0
- package/src/csvw/Csv2Rdf.ts +268 -0
- package/src/csvw/Datatype.ts +589 -0
- package/src/csvw/Metadata.ts +1523 -0
- package/src/csvw/Processor.ts +276 -0
- package/src/csvw/Report.ts +135 -0
- package/src/csvw/Table.ts +759 -0
- package/src/csvw/index.ts +22 -0
- package/src/csvw/internal/dateFormat.ts +202 -0
- package/src/csvw/internal/json.ts +104 -0
- package/src/csvw/internal/numberFormat.ts +369 -0
- package/src/csvw/internal/object.ts +23 -0
- package/src/csvw/internal/uriTemplate.ts +130 -0
- package/src/csvw/internal/url.ts +93 -0
- package/src/csvw/internal/vocab.ts +282 -0
- package/src/index.ts +40 -0
- package/src/internal/arbitrary.ts +148 -0
- package/src/internal/loop.ts +24 -0
- package/src/internal/pending.ts +20 -0
- package/src/internal/textDecoder.ts +183 -0
- package/src/jsonld/DocumentLoader.ts +512 -0
- package/src/jsonld/JsonLd.ts +847 -0
- package/src/jsonld/JsonLdError.ts +105 -0
- package/src/jsonld/index.ts +13 -0
- package/src/jsonld/internal/compact.ts +852 -0
- package/src/jsonld/internal/context.ts +781 -0
- package/src/jsonld/internal/expand.ts +614 -0
- package/src/jsonld/internal/flatten.ts +243 -0
- package/src/jsonld/internal/frame.ts +559 -0
- package/src/jsonld/internal/iri.ts +52 -0
- package/src/jsonld/internal/json.ts +19 -0
- package/src/jsonld/internal/linkHeader.ts +60 -0
- package/src/jsonld/internal/rdf.ts +481 -0
- package/src/jsonld/internal/util.ts +367 -0
- package/src/n3/Isomorphism.ts +476 -0
- package/src/n3/Mapping.ts +332 -0
- package/src/n3/Model.ts +696 -0
- package/src/n3/N3.ts +237 -0
- package/src/n3/Reasoner.ts +568 -0
- package/src/n3/Vocab.ts +111 -0
- package/src/n3/index.ts +21 -0
- package/src/n3/internal/builtins.ts +668 -0
- package/src/n3/internal/guards.ts +23 -0
- package/src/n3/internal/lists.ts +106 -0
- package/src/n3/internal/loop.ts +28 -0
- package/src/n3/internal/parser.ts +1032 -0
- package/src/n3/internal/writer.ts +344 -0
- package/src/ntriples/Grammar.ts +317 -0
- package/src/ntriples/Lexical.ts +321 -0
- package/src/ntriples/NQuads.ts +140 -0
- package/src/ntriples/NTriples.ts +143 -0
- package/src/ntriples/index.ts +14 -0
- package/src/ntriples/internal/codec.ts +229 -0
- package/src/ntriples/internal/lineParser.ts +326 -0
- package/src/ntriples/internal/loop.ts +14 -0
- package/src/rdfjson/RdfJson.ts +806 -0
- package/src/rdfjson/index.ts +9 -0
- package/src/rdfjson/internal/json.ts +19 -0
- package/src/rdfxml/RdfXml.ts +1408 -0
- package/src/rdfxml/Xml.ts +419 -0
- package/src/rdfxml/index.ts +11 -0
- package/src/rdfxml/internal/chars.ts +73 -0
- package/src/rdfxml/internal/loop.ts +24 -0
- package/src/rdfxml/internal/parser.ts +1265 -0
- package/src/shacl/Message.ts +102 -0
- package/src/shacl/Path.ts +483 -0
- package/src/shacl/Shapes.ts +913 -0
- package/src/shacl/Sparql.ts +128 -0
- package/src/shacl/ValidationReport.ts +438 -0
- package/src/shacl/Validator.ts +1156 -0
- package/src/shacl/Vocabulary.ts +180 -0
- package/src/shacl/index.ts +22 -0
- package/src/shacl/internal/compare.ts +128 -0
- package/src/shacl/internal/regex.ts +56 -0
- package/src/shex/SemAct.ts +197 -0
- package/src/shex/ShExC.ts +415 -0
- package/src/shex/ShExError.ts +71 -0
- package/src/shex/ShExJ.ts +893 -0
- package/src/shex/ShExR.ts +640 -0
- package/src/shex/ShapeMap.ts +385 -0
- package/src/shex/Structure.ts +467 -0
- package/src/shex/Validator.ts +395 -0
- package/src/shex/index.ts +24 -0
- package/src/shex/internal/engine.ts +682 -0
- package/src/shex/internal/iterate.ts +14 -0
- package/src/shex/internal/json.ts +12 -0
- package/src/shex/internal/lexer.ts +56 -0
- package/src/shex/internal/nodeConstraint.ts +368 -0
- package/src/shex/internal/shexcLexer.ts +387 -0
- package/src/shex/internal/shexcParser.ts +1312 -0
- package/src/shex/internal/tokens.ts +41 -0
- package/src/shex/internal/xpathRegex.ts +290 -0
- package/src/sparql/Algebra.ts +914 -0
- package/src/sparql/Ast.ts +1344 -0
- package/src/sparql/Bindings.ts +272 -0
- package/src/sparql/ClientErrors.ts +156 -0
- package/src/sparql/ClientFormats.ts +70 -0
- package/src/sparql/Engine.ts +699 -0
- package/src/sparql/Errors.ts +30 -0
- package/src/sparql/Expression.ts +360 -0
- package/src/sparql/Federation.ts +187 -0
- package/src/sparql/Functions.ts +689 -0
- package/src/sparql/Generator.ts +426 -0
- package/src/sparql/GraphStore.ts +341 -0
- package/src/sparql/Optimizer.ts +230 -0
- package/src/sparql/Options.ts +191 -0
- package/src/sparql/Parser.ts +173 -0
- package/src/sparql/Protocol.ts +342 -0
- package/src/sparql/ProtocolErrors.ts +113 -0
- package/src/sparql/QueryBuilder.ts +953 -0
- package/src/sparql/Results.ts +844 -0
- package/src/sparql/ResultsStream.ts +771 -0
- package/src/sparql/ServerFormats.ts +75 -0
- package/src/sparql/ServiceDescription.ts +130 -0
- package/src/sparql/SparqlClient.ts +947 -0
- package/src/sparql/SparqlServer.ts +528 -0
- package/src/sparql/Store.ts +311 -0
- package/src/sparql/TermSchema.ts +20 -0
- package/src/sparql/Testing.ts +114 -0
- package/src/sparql/Translate.ts +407 -0
- package/src/sparql/ai/Mcp.ts +43 -0
- package/src/sparql/ai/Tools.ts +481 -0
- package/src/sparql/ai/index.ts +11 -0
- package/src/sparql/index.ts +64 -0
- package/src/sparql/internal/evaluator.ts +947 -0
- package/src/sparql/internal/hash.ts +418 -0
- package/src/sparql/internal/json.ts +12 -0
- package/src/sparql/internal/lexer.ts +488 -0
- package/src/sparql/internal/loop.ts +24 -0
- package/src/sparql/internal/parser.ts +2215 -0
- package/src/sparql/internal/prefetch.ts +46 -0
- package/src/sparql/internal/stringMap.ts +39 -0
- package/src/sparql/internal/textResults.ts +226 -0
- package/src/sparql/internal/values.ts +550 -0
- package/src/sparql/shacl/Evaluator.ts +478 -0
- package/src/sparql/shacl/Query.ts +574 -0
- package/src/sparql/shacl/index.ts +12 -0
- package/src/sparql/sql/Dialect.ts +246 -0
- package/src/sparql/sql/SqlStore.ts +1080 -0
- package/src/sparql/sql/Translation.ts +1898 -0
- package/src/sparql/sql/index.ts +17 -0
- package/src/sparql/sql/internal/encoding.ts +313 -0
- package/src/turtle/Grammar.ts +286 -0
- package/src/turtle/Manifest.ts +215 -0
- package/src/turtle/TriG.ts +158 -0
- package/src/turtle/Turtle.ts +166 -0
- package/src/turtle/index.ts +14 -0
- package/src/turtle/internal/loop.ts +23 -0
- package/src/turtle/internal/parse.ts +112 -0
- package/src/turtle/internal/parser.ts +1303 -0
- package/src/turtle/internal/serialize.ts +79 -0
- package/src/turtle/internal/streamWriter.ts +128 -0
- package/src/turtle/internal/writer.ts +898 -0
- package/src/xmp/DublinCore.ts +147 -0
- package/src/xmp/Exif.ts +109 -0
- package/src/xmp/Extract.ts +351 -0
- package/src/xmp/Metadata.ts +703 -0
- package/src/xmp/Namespaces.ts +228 -0
- package/src/xmp/Packet.ts +297 -0
- package/src/xmp/Pdf.ts +99 -0
- package/src/xmp/PdfA.ts +280 -0
- package/src/xmp/Photoshop.ts +275 -0
- package/src/xmp/Tiff.ts +196 -0
- package/src/xmp/Xmp.ts +430 -0
- package/src/xmp/XmpBasic.ts +90 -0
- package/src/xmp/XmpMM.ts +82 -0
- package/src/xmp/XmpRights.ts +83 -0
- package/src/xmp/index.ts +36 -0
- package/src/xmp/internal/accessors.ts +72 -0
- package/src/xmp/internal/xml.ts +63 -0
|
@@ -0,0 +1,1535 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
|
|
2
|
+
import { B as isNamedNode, I as isGround, K as isTriple, P as isDefaultGraph, T as blankNode, Y as literal, Z as namedNode, o as Literal, q as isVariable, w as XSD_STRING, z as isLiteral } from "./Term-CFLG1qu4.mjs";
|
|
3
|
+
import { S as toValue, _ as isValidLexical, g as isNumericDatatype, h as isKnownDatatype } from "./Xsd-Cdgx5zRB.mjs";
|
|
4
|
+
import { i as equals, r as effectiveBooleanValue } from "./Expression-BIMMvduQ.mjs";
|
|
5
|
+
import { n as StoreError } from "./Store-DH3Ow1GO.mjs";
|
|
6
|
+
import * as Arr from "effect/Array";
|
|
7
|
+
import * as Equal from "effect/Equal";
|
|
8
|
+
import * as MutableHashMap from "effect/MutableHashMap";
|
|
9
|
+
import * as MutableHashSet from "effect/MutableHashSet";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import * as Predicate from "effect/Predicate";
|
|
12
|
+
import * as Match from "effect/Match";
|
|
13
|
+
import * as Result from "effect/Result";
|
|
14
|
+
import * as BigDecimal from "effect/BigDecimal";
|
|
15
|
+
// src/sparql/sql/internal/encoding.ts
|
|
16
|
+
/**
|
|
17
|
+
* The encoding of RDF terms as rows of the term dictionary.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
/** Term kinds stored in the `kind` column. */
|
|
22
|
+
const Kind = {
|
|
23
|
+
NamedNode: 1,
|
|
24
|
+
BlankNode: 2,
|
|
25
|
+
Literal: 3,
|
|
26
|
+
Triple: 4
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Comparison classes stored in the `cls` column. They let the SQL
|
|
30
|
+
* translation of SPARQL comparisons decide, per row, which comparison rule
|
|
31
|
+
* applies (numeric, string, boolean, …) — and tell the store which rules the
|
|
32
|
+
* data could need that SQL cannot evaluate exactly.
|
|
33
|
+
*/
|
|
34
|
+
const Cls = {
|
|
35
|
+
/** IRIs and blank nodes. */
|
|
36
|
+
Resource: 0,
|
|
37
|
+
/** Integers and decimals whose double value is exact and order preserving. */
|
|
38
|
+
SafeNumber: 1,
|
|
39
|
+
/** Finite `xsd:double`. */
|
|
40
|
+
Double: 2,
|
|
41
|
+
/** Finite `xsd:float` (`num` holds the float value). */
|
|
42
|
+
Float: 3,
|
|
43
|
+
/** `xsd:string`. */
|
|
44
|
+
String: 4,
|
|
45
|
+
/** Language-tagged strings (with or without a base direction). */
|
|
46
|
+
LangString: 5,
|
|
47
|
+
/** Valid `xsd:boolean` (`num` is 0 or 1). */
|
|
48
|
+
Boolean: 6,
|
|
49
|
+
/** Valid date/time and duration literals. */
|
|
50
|
+
Temporal: 7,
|
|
51
|
+
/** Integers and decimals that do not fit a double exactly. */
|
|
52
|
+
UnsafeNumber: 8,
|
|
53
|
+
/** Literals of datatypes unknown to the engine. */
|
|
54
|
+
Unknown: 9,
|
|
55
|
+
/** Triple terms. */
|
|
56
|
+
Triple: 10,
|
|
57
|
+
/** `NaN` and infinite doubles and floats. */
|
|
58
|
+
SpecialFloat: 11,
|
|
59
|
+
/** Ill-formed literals of numeric datatypes. */
|
|
60
|
+
IllFormedNumeric: 12,
|
|
61
|
+
/** Other well-formed literals of known datatypes (e.g. `xsd:anyURI`). */
|
|
62
|
+
OtherKnown: 13,
|
|
63
|
+
/** Other ill-formed literals of known datatypes. */
|
|
64
|
+
IllFormed: 14
|
|
65
|
+
};
|
|
66
|
+
Array.from({ length: 15 }, (_, i) => i);
|
|
67
|
+
/** Classes of literals that are well-formed and of a known datatype. */
|
|
68
|
+
const WELL_FORMED_KNOWN = [
|
|
69
|
+
1,
|
|
70
|
+
2,
|
|
71
|
+
3,
|
|
72
|
+
4,
|
|
73
|
+
6,
|
|
74
|
+
7,
|
|
75
|
+
8,
|
|
76
|
+
11,
|
|
77
|
+
13
|
|
78
|
+
];
|
|
79
|
+
const XSD$1 = "http://www.w3.org/2001/XMLSchema#";
|
|
80
|
+
const TEMPORAL = MutableHashSet.fromIterable([
|
|
81
|
+
"dateTime",
|
|
82
|
+
"dateTimeStamp",
|
|
83
|
+
"date",
|
|
84
|
+
"time",
|
|
85
|
+
"gYear",
|
|
86
|
+
"gYearMonth",
|
|
87
|
+
"gMonth",
|
|
88
|
+
"gMonthDay",
|
|
89
|
+
"gDay",
|
|
90
|
+
"duration",
|
|
91
|
+
"dayTimeDuration",
|
|
92
|
+
"yearMonthDuration"
|
|
93
|
+
].map((l) => XSD$1 + l));
|
|
94
|
+
const MAX_SAFE = 2n ** 53n;
|
|
95
|
+
const decimalDigits = (d) => {
|
|
96
|
+
const n = BigDecimal.normalize(d);
|
|
97
|
+
return (n.value < 0n ? -n.value : n.value).toString().length;
|
|
98
|
+
};
|
|
99
|
+
const noNumber = (cls) => ({
|
|
100
|
+
cls,
|
|
101
|
+
num: Option.none()
|
|
102
|
+
});
|
|
103
|
+
const withNumber = (cls, num) => ({
|
|
104
|
+
cls,
|
|
105
|
+
num: Option.some(num)
|
|
106
|
+
});
|
|
107
|
+
const numericClass = Match.type().pipe(Match.withReturnType(), Match.tag("Integer", (v) => v.value <= MAX_SAFE && v.value >= -MAX_SAFE ? withNumber(Cls.SafeNumber, Number(v.value)) : withNumber(Cls.UnsafeNumber, Number(v.value))), Match.tag("Decimal", (v) => decimalDigits(v.value) <= 15 ? withNumber(Cls.SafeNumber, Number(BigDecimal.format(v.value))) : withNumber(Cls.UnsafeNumber, BigDecimal.toNumberUnsafe(v.value))), Match.tag("Float", (v) => Number.isFinite(v.value) ? withNumber(Cls.Float, v.value) : noNumber(Cls.SpecialFloat)), Match.tag("Double", (v) => Number.isFinite(v.value) ? withNumber(Cls.Double, v.value) : noNumber(Cls.SpecialFloat)), Match.orElse(() => noNumber(Cls.IllFormedNumeric)));
|
|
108
|
+
const RESOURCE = noNumber(Cls.Resource);
|
|
109
|
+
const TRIPLE = noNumber(Cls.Triple);
|
|
110
|
+
const LANG_STRING = noNumber(Cls.LangString);
|
|
111
|
+
const STRING = noNumber(Cls.String);
|
|
112
|
+
const UNKNOWN = noNumber(Cls.Unknown);
|
|
113
|
+
const ILL_FORMED_NUMERIC = noNumber(Cls.IllFormedNumeric);
|
|
114
|
+
const ILL_FORMED = noNumber(Cls.IllFormed);
|
|
115
|
+
const TEMPORAL_CLASS = noNumber(Cls.Temporal);
|
|
116
|
+
const OTHER_KNOWN = noNumber(Cls.OtherKnown);
|
|
117
|
+
const classifyTerm = Match.type().pipe(Match.withReturnType(), Match.tag("NamedNode", "BlankNode", () => RESOURCE), Match.tag("Triple", () => TRIPLE), Match.tag("Literal", (term) => {
|
|
118
|
+
if (term.language !== "") return LANG_STRING;
|
|
119
|
+
const dt = term.datatype.value;
|
|
120
|
+
if (dt === "http://www.w3.org/2001/XMLSchema#string") return STRING;
|
|
121
|
+
if (!isKnownDatatype(dt)) return UNKNOWN;
|
|
122
|
+
const valid = isValidLexical(dt, term.value);
|
|
123
|
+
if (isNumericDatatype(dt)) {
|
|
124
|
+
if (!valid) return ILL_FORMED_NUMERIC;
|
|
125
|
+
const v = toValue(term);
|
|
126
|
+
return numericClass(v);
|
|
127
|
+
}
|
|
128
|
+
if (!valid) return ILL_FORMED;
|
|
129
|
+
if (dt === `${XSD$1}boolean`) return withNumber(Cls.Boolean, term.value === "true" || term.value === "1" ? 1 : 0);
|
|
130
|
+
if (MutableHashSet.has(TEMPORAL, dt)) return TEMPORAL_CLASS;
|
|
131
|
+
return OTHER_KNOWN;
|
|
132
|
+
}), Match.exhaustive);
|
|
133
|
+
/** The comparison class and numeric value of a term. */
|
|
134
|
+
const classify = (term) => classifyTerm(term);
|
|
135
|
+
const encodeRow = Match.fn((term, _class, _componentIds) => term).pipe(Match.withReturnType(), Match.tag("NamedNode", (term, _term, { cls, num }) => ({
|
|
136
|
+
kind: Kind.NamedNode,
|
|
137
|
+
value: term.value,
|
|
138
|
+
datatype: "",
|
|
139
|
+
lang: "",
|
|
140
|
+
dir: "",
|
|
141
|
+
sub: Option.none(),
|
|
142
|
+
pre: Option.none(),
|
|
143
|
+
obj: Option.none(),
|
|
144
|
+
cls,
|
|
145
|
+
num
|
|
146
|
+
})), Match.tag("BlankNode", (term, _term, { cls, num }) => ({
|
|
147
|
+
kind: Kind.BlankNode,
|
|
148
|
+
value: term.value,
|
|
149
|
+
datatype: "",
|
|
150
|
+
lang: "",
|
|
151
|
+
dir: "",
|
|
152
|
+
sub: Option.none(),
|
|
153
|
+
pre: Option.none(),
|
|
154
|
+
obj: Option.none(),
|
|
155
|
+
cls,
|
|
156
|
+
num
|
|
157
|
+
})), Match.tag("Literal", (term, _term, { cls, num }) => ({
|
|
158
|
+
kind: Kind.Literal,
|
|
159
|
+
value: term.value,
|
|
160
|
+
datatype: term.datatype.value,
|
|
161
|
+
lang: term.language,
|
|
162
|
+
dir: term.direction ?? "",
|
|
163
|
+
sub: Option.none(),
|
|
164
|
+
pre: Option.none(),
|
|
165
|
+
obj: Option.none(),
|
|
166
|
+
cls,
|
|
167
|
+
num
|
|
168
|
+
})), Match.tag("Triple", (_triple, _term, { cls, num }, componentIds) => {
|
|
169
|
+
if (componentIds === void 0) throw new StoreError({ message: "Triple terms need component ids" });
|
|
170
|
+
return {
|
|
171
|
+
kind: Kind.Triple,
|
|
172
|
+
value: componentIds.join(" "),
|
|
173
|
+
datatype: "",
|
|
174
|
+
lang: "",
|
|
175
|
+
dir: "",
|
|
176
|
+
sub: Option.some(componentIds[0]),
|
|
177
|
+
pre: Option.some(componentIds[1]),
|
|
178
|
+
obj: Option.some(componentIds[2]),
|
|
179
|
+
cls,
|
|
180
|
+
num
|
|
181
|
+
};
|
|
182
|
+
}), Match.exhaustive);
|
|
183
|
+
/**
|
|
184
|
+
* The dictionary row of a term. Triple terms store the ids of their
|
|
185
|
+
* components in `value` (`"s p o"`), so that `(value, kind, datatype, lang,
|
|
186
|
+
* dir)` is a unique key for every term.
|
|
187
|
+
*/
|
|
188
|
+
const encode = (term, componentIds) => encodeRow(term, classify(term), componentIds);
|
|
189
|
+
/** The unique key of a dictionary row. */
|
|
190
|
+
const rowKey = (row) => `${row.kind}\u0000${row.value}\u0000${row.datatype}\u0000${row.lang}\u0000${row.dir}`;
|
|
191
|
+
const datatypes = MutableHashMap.empty();
|
|
192
|
+
const datatype = (iri) => Option.getOrElse(MutableHashMap.get(datatypes, iri), () => {
|
|
193
|
+
const n = namedNode(iri);
|
|
194
|
+
if (MutableHashMap.size(datatypes) < 1e4) MutableHashMap.set(datatypes, iri, n);
|
|
195
|
+
return n;
|
|
196
|
+
});
|
|
197
|
+
const decodeRow = Match.fn((kind, _value, _dt, _lang, _dir) => kind).pipe(Match.withReturnType(), Match.when(Kind.NamedNode, (_kind, _k, value) => namedNode(value)), Match.when(Kind.BlankNode, (_kind, _k, value) => blankNode(value)), Match.when(Kind.Literal, (_kind, _k, value, dt, lang, dir) => new Literal(value, datatype(dt), lang, dir === "ltr" || dir === "rtl" ? dir : void 0)), Match.orElse((_kind, _k, value) => {
|
|
198
|
+
const [s = NaN, p = NaN, o = NaN] = value.split(" ").map(Number);
|
|
199
|
+
return [
|
|
200
|
+
s,
|
|
201
|
+
p,
|
|
202
|
+
o
|
|
203
|
+
];
|
|
204
|
+
}));
|
|
205
|
+
/** Whether a decoded row is the component ids of a triple term. */
|
|
206
|
+
const isComponentIds = (decoded) => Array.isArray(decoded);
|
|
207
|
+
/**
|
|
208
|
+
* Decodes a non-triple dictionary row; returns the component ids for triple
|
|
209
|
+
* terms.
|
|
210
|
+
*/
|
|
211
|
+
const decode = (kind, value, dt, lang, dir) => decodeRow(kind, value, dt, lang, dir);
|
|
212
|
+
// src/sparql/sql/Translation.ts
|
|
213
|
+
/**
|
|
214
|
+
* SPARQL algebra to SQL translation.
|
|
215
|
+
*
|
|
216
|
+
* `compile` translates an algebra tree into a single SQL `SELECT` over the
|
|
217
|
+
* store's tables (term dictionary + quads of term ids), or reports that the
|
|
218
|
+
* tree is not (exactly) translatable — the store then lets the generic engine
|
|
219
|
+
* evaluate that node and offers its children again.
|
|
220
|
+
*
|
|
221
|
+
* Solutions are rows whose columns hold term ids (`NULL` = unbound). Terms
|
|
222
|
+
* that are not in the dictionary but are needed by the query (constants of
|
|
223
|
+
* `VALUES`, `BIND`, …) get negative, query-local ids. Integer results of
|
|
224
|
+
* `COUNT` are carried as plain integers. The final `SELECT` joins the
|
|
225
|
+
* dictionary to decode the ids.
|
|
226
|
+
*
|
|
227
|
+
* Translated: BGPs (self-joins of the quads table, triple term patterns
|
|
228
|
+
* through the dictionary), `Join`, `LeftJoin` (with the filter in the `ON`
|
|
229
|
+
* clause), `Union` (`UNION ALL` with `NULL` padding), `Minus` and
|
|
230
|
+
* `[NOT] EXISTS` (correlated `NOT EXISTS` / `EXISTS`), `Filter`, `Graph`
|
|
231
|
+
* (constant and variable), `Extend` with term-valued expressions, `Values`,
|
|
232
|
+
* `Project`, `Distinct`, `Reduced`, `Slice` and `Group` with `COUNT` /
|
|
233
|
+
* `SAMPLE`. Expressions: `&&`, `||`, `!`, `=`, `!=`, `<`, `>`, `<=`, `>=`,
|
|
234
|
+
* `IN`, `NOT IN`, `BOUND`, `sameTerm`, `isIRI`, `isBlank`, `isLiteral`,
|
|
235
|
+
* `isNumeric`, `isTriple`, `hasLang`, `hasLangDir`, `STR`, `LANG`,
|
|
236
|
+
* `DATATYPE`, `STRLEN`, `STRSTARTS`, `STRENDS`, `CONTAINS`, `LANGMATCHES`,
|
|
237
|
+
* `IF`, `COALESCE` and `EXISTS`, with SPARQL's error semantics (an error is
|
|
238
|
+
* SQL `NULL`; SPARQL's `&&`/`||`/`!` coincide with SQL's three-valued logic).
|
|
239
|
+
*
|
|
240
|
+
* Comparisons are evaluated per row by the comparison class of the terms
|
|
241
|
+
* (stored in the dictionary). Combinations of classes that SQL cannot compare
|
|
242
|
+
* exactly (e.g. dates, arbitrary-precision decimals, float/double promotion)
|
|
243
|
+
* are reported as `risks`: before running the query the store checks which
|
|
244
|
+
* classes exist and falls back to the engine if a risk can occur.
|
|
245
|
+
*
|
|
246
|
+
* @since 0.1.0
|
|
247
|
+
*/
|
|
248
|
+
var Translation_exports = /* @__PURE__ */ __exportAll({
|
|
249
|
+
compile: () => compile,
|
|
250
|
+
constants: () => constants,
|
|
251
|
+
isRisky: () => isRisky,
|
|
252
|
+
supports: () => supports
|
|
253
|
+
});
|
|
254
|
+
/**
|
|
255
|
+
* Whether the risks of a compiled query can occur, given the comparison
|
|
256
|
+
* classes present in the store.
|
|
257
|
+
*
|
|
258
|
+
* @since 0.1.0
|
|
259
|
+
* @category utils
|
|
260
|
+
*/
|
|
261
|
+
const isRisky = (compiled, storeClasses) => {
|
|
262
|
+
const present = (c) => storeClasses.has(c) || compiled.localClasses.has(c);
|
|
263
|
+
return compiled.risks.some((r) => (r.aStatic || present(r.a)) && (r.bStatic || present(r.b)));
|
|
264
|
+
};
|
|
265
|
+
var Unsupported = class {
|
|
266
|
+
reason;
|
|
267
|
+
constructor(reason) {
|
|
268
|
+
this.reason = reason;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const unsupported = (reason) => {
|
|
272
|
+
throw new Unsupported(reason);
|
|
273
|
+
};
|
|
274
|
+
/** Whether a term (pattern) is a triple term with no variables. */
|
|
275
|
+
const isGroundTriple = (t) => isTriple(t) && isGround(t);
|
|
276
|
+
const collectTerm = (term, out) => {
|
|
277
|
+
return Match.value(term).pipe(Match.tag("NamedNode", "Literal", (t) => {
|
|
278
|
+
MutableHashMap.set(out, t.key, t);
|
|
279
|
+
}), Match.tag("Triple", (t) => {
|
|
280
|
+
if (isGroundTriple(t)) MutableHashMap.set(out, t.key, t);
|
|
281
|
+
else {
|
|
282
|
+
collectTerm(t.subject, out);
|
|
283
|
+
collectTerm(t.predicate, out);
|
|
284
|
+
collectTerm(t.object, out);
|
|
285
|
+
}
|
|
286
|
+
}), Match.orElse(() => void 0));
|
|
287
|
+
};
|
|
288
|
+
const collectExpression = (e, out) => {
|
|
289
|
+
Match.value(e).pipe(Match.tag("Operation", "FunctionCall", (call) => call.args.forEach((a) => collectExpression(a, out))), Match.tag("Exists", (x) => collectOperation(x.input, out)), Match.orElse((t) => collectTerm(t, out)));
|
|
290
|
+
};
|
|
291
|
+
const collectOperation = (operation, out) => {
|
|
292
|
+
return Match.value(operation).pipe(Match.tag("Bgp", (op) => op.patterns.forEach((p) => {
|
|
293
|
+
collectTerm(p.subject, out);
|
|
294
|
+
collectTerm(p.predicate, out);
|
|
295
|
+
collectTerm(p.object, out);
|
|
296
|
+
})), Match.tag("Path", () => void 0), Match.tag("Join", "Union", "Minus", (op) => {
|
|
297
|
+
collectOperation(op.left, out);
|
|
298
|
+
collectOperation(op.right, out);
|
|
299
|
+
}), Match.tag("LeftJoin", (op) => {
|
|
300
|
+
collectOperation(op.left, out);
|
|
301
|
+
collectOperation(op.right, out);
|
|
302
|
+
if (op.expression !== void 0) collectExpression(op.expression, out);
|
|
303
|
+
}), Match.tag("Filter", (op) => {
|
|
304
|
+
collectExpression(op.expression, out);
|
|
305
|
+
collectOperation(op.input, out);
|
|
306
|
+
}), Match.tag("Extend", (op) => {
|
|
307
|
+
collectExpression(op.expression, out);
|
|
308
|
+
collectOperation(op.input, out);
|
|
309
|
+
}), Match.tag("Graph", (op) => {
|
|
310
|
+
collectTerm(op.name, out);
|
|
311
|
+
collectOperation(op.input, out);
|
|
312
|
+
}), Match.tag("Values", (op) => op.bindings.forEach((b) => Arr.forEach(b, ([, t]) => collectTerm(t, out)))), Match.tag("Group", "OrderBy", "Project", "Distinct", "Reduced", "Slice", "Service", (op) => {
|
|
313
|
+
collectOperation(op.input, out);
|
|
314
|
+
}), Match.exhaustive);
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* The constant terms of an algebra tree (and of the dataset) whose
|
|
318
|
+
* dictionary ids the translation needs.
|
|
319
|
+
*
|
|
320
|
+
* @since 0.1.0
|
|
321
|
+
* @category utils
|
|
322
|
+
*/
|
|
323
|
+
const constants = (op, context) => {
|
|
324
|
+
const out = MutableHashMap.empty();
|
|
325
|
+
collectOperation(op, out);
|
|
326
|
+
const { defaultGraph, namedGraphs } = context.dataset;
|
|
327
|
+
if (!Predicate.isString(defaultGraph)) defaultGraph.forEach((g) => {
|
|
328
|
+
if (!isDefaultGraph(g)) MutableHashMap.set(out, g.key, g);
|
|
329
|
+
});
|
|
330
|
+
if (!Predicate.isString(namedGraphs)) namedGraphs.forEach((g) => MutableHashMap.set(out, g.key, g));
|
|
331
|
+
if (Predicate.isTagged(context.activeGraph, "NamedGraph")) MutableHashMap.set(out, context.activeGraph.graph.key, context.activeGraph.graph);
|
|
332
|
+
MutableHashMap.set(out, TRUE.key, TRUE);
|
|
333
|
+
MutableHashMap.set(out, FALSE.key, FALSE);
|
|
334
|
+
return Arr.fromIterable(MutableHashMap.values(out));
|
|
335
|
+
};
|
|
336
|
+
/** A FROM item joined unconditionally. */
|
|
337
|
+
const inner = (source, alias) => ({
|
|
338
|
+
source,
|
|
339
|
+
alias,
|
|
340
|
+
left: Option.none()
|
|
341
|
+
});
|
|
342
|
+
const EMPTY = {
|
|
343
|
+
items: [],
|
|
344
|
+
where: [],
|
|
345
|
+
cols: MutableHashMap.empty()
|
|
346
|
+
};
|
|
347
|
+
/** Whether a block is the unit (no items, conditions or columns). */
|
|
348
|
+
const isUnit = (block) => Arr.isReadonlyArrayEmpty(block.items) && Arr.isReadonlyArrayEmpty(block.where) && MutableHashMap.isEmpty(block.cols);
|
|
349
|
+
const isHidden = (name) => name.startsWith("#");
|
|
350
|
+
/** The distinct values of `items`, in order of first occurrence. */
|
|
351
|
+
const distinct = (items) => Arr.fromIterable(MutableHashSet.fromIterable(items));
|
|
352
|
+
const XSD = "http://www.w3.org/2001/XMLSchema#";
|
|
353
|
+
const TRUE = new Literal("true", namedNode(`${XSD}boolean`));
|
|
354
|
+
const FALSE = new Literal("false", namedNode(`${XSD}boolean`));
|
|
355
|
+
/** The term id of a term-valued operand. */
|
|
356
|
+
const operandId = (o) => o.tag === "term" || o.tag === "const" ? Option.some(o.id) : Option.none();
|
|
357
|
+
const S = (s) => ({ s: Option.some(s) });
|
|
358
|
+
const SO = (s) => ({ s });
|
|
359
|
+
const SNULL = { s: Option.none() };
|
|
360
|
+
const Q = (q) => ({ q });
|
|
361
|
+
const isStatic = (f) => "s" in f;
|
|
362
|
+
/** The statically known number of a field. */
|
|
363
|
+
const staticNumber = (f) => isStatic(f) ? Option.filter(f.s, Predicate.isNumber) : Option.none();
|
|
364
|
+
/** Whether a field is statically the value `v`. */
|
|
365
|
+
const isStaticValue = (f, v) => isStatic(f) && Option.exists(f.s, (s) => s === v);
|
|
366
|
+
const RISK_ORDER = [
|
|
367
|
+
[1, 3],
|
|
368
|
+
[2, 3],
|
|
369
|
+
[8, 1],
|
|
370
|
+
[8, 2],
|
|
371
|
+
[8, 3],
|
|
372
|
+
[8, 8],
|
|
373
|
+
[11, 1],
|
|
374
|
+
[11, 2],
|
|
375
|
+
[11, 3],
|
|
376
|
+
[11, 8],
|
|
377
|
+
[11, 11],
|
|
378
|
+
[7, 7]
|
|
379
|
+
];
|
|
380
|
+
const RISK_EQUAL = [...RISK_ORDER, [10, 10]];
|
|
381
|
+
/** The SQL conditions of `cs` (dropping the statically known ones). */
|
|
382
|
+
const conditions = (cs) => cs.filter(Predicate.isString);
|
|
383
|
+
const and = (...cs) => {
|
|
384
|
+
if (cs.includes(false)) return false;
|
|
385
|
+
const parts = conditions(cs);
|
|
386
|
+
return Arr.match(parts, {
|
|
387
|
+
onEmpty: () => true,
|
|
388
|
+
onNonEmpty: ([first, ...rest]) => Arr.isReadonlyArrayEmpty(rest) ? first : `(${parts.join(" AND ")})`
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
const or = (...cs) => {
|
|
392
|
+
if (cs.includes(true)) return true;
|
|
393
|
+
const parts = conditions(cs);
|
|
394
|
+
return Arr.match(parts, {
|
|
395
|
+
onEmpty: () => false,
|
|
396
|
+
onNonEmpty: ([first, ...rest]) => Arr.isReadonlyArrayEmpty(rest) ? first : `(${parts.join(" OR ")})`
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
const condSql = (c) => c === true ? "TRUE" : c === false ? "FALSE" : c;
|
|
400
|
+
const isLive = (branch) => Predicate.isString(branch[0]);
|
|
401
|
+
/**
|
|
402
|
+
* A `CASE` of the branches up to the first that always holds (whose value is
|
|
403
|
+
* then the `ELSE`), dropping the branches that never hold.
|
|
404
|
+
*/
|
|
405
|
+
const caseOf = (branches, otherwise) => {
|
|
406
|
+
const fallback = Option.match(Arr.findFirst(branches, ([c]) => c === true), {
|
|
407
|
+
onNone: () => otherwise,
|
|
408
|
+
onSome: ([, v]) => v
|
|
409
|
+
});
|
|
410
|
+
const live = Arr.takeWhile(branches, ([c]) => c !== true).filter(isLive);
|
|
411
|
+
if (Arr.isReadonlyArrayEmpty(live)) return fallback;
|
|
412
|
+
return `(CASE ${live.map(([w, r]) => `WHEN ${w} THEN ${r}`).join(" ")} ELSE ${fallback} END)`;
|
|
413
|
+
};
|
|
414
|
+
var Compiler = class {
|
|
415
|
+
dialect;
|
|
416
|
+
T;
|
|
417
|
+
Q;
|
|
418
|
+
G;
|
|
419
|
+
counter = 0;
|
|
420
|
+
colNames = MutableHashMap.empty();
|
|
421
|
+
params = [];
|
|
422
|
+
paramIndex = MutableHashMap.empty();
|
|
423
|
+
risks = [];
|
|
424
|
+
localClasses = /* @__PURE__ */ new Set();
|
|
425
|
+
context;
|
|
426
|
+
resolve;
|
|
427
|
+
/** Query-local terms, by key (stable across the two compilation passes). */
|
|
428
|
+
locals;
|
|
429
|
+
/** Whether the query-local terms are complete (second pass). */
|
|
430
|
+
localsKnown;
|
|
431
|
+
constructor(context, resolve, locals, localsKnown) {
|
|
432
|
+
this.context = context;
|
|
433
|
+
this.resolve = resolve;
|
|
434
|
+
this.locals = locals;
|
|
435
|
+
this.localsKnown = localsKnown;
|
|
436
|
+
this.dialect = context.dialect;
|
|
437
|
+
this.T = context.tables.terms;
|
|
438
|
+
this.Q = context.tables.quads;
|
|
439
|
+
this.G = context.tables.graphs;
|
|
440
|
+
}
|
|
441
|
+
alias(prefix) {
|
|
442
|
+
return `${prefix}${this.counter++}`;
|
|
443
|
+
}
|
|
444
|
+
col(name) {
|
|
445
|
+
return Option.getOrElse(MutableHashMap.get(this.colNames, name), () => {
|
|
446
|
+
const c = `c${MutableHashMap.size(this.colNames)}`;
|
|
447
|
+
MutableHashMap.set(this.colNames, name, c);
|
|
448
|
+
return c;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
param(value) {
|
|
452
|
+
const i = Option.getOrElse(MutableHashMap.get(this.paramIndex, value), () => {
|
|
453
|
+
this.params.push(value);
|
|
454
|
+
const n = this.params.length;
|
|
455
|
+
MutableHashMap.set(this.paramIndex, value, n);
|
|
456
|
+
return n;
|
|
457
|
+
});
|
|
458
|
+
return this.dialect.castText(`\ue000${i}\ue000`);
|
|
459
|
+
}
|
|
460
|
+
lit(v) {
|
|
461
|
+
if (Predicate.isBoolean(v)) return v ? "TRUE" : "FALSE";
|
|
462
|
+
if (Predicate.isNumber(v)) {
|
|
463
|
+
if (!Number.isFinite(v)) return "NULL";
|
|
464
|
+
return Number.isInteger(v) && Math.abs(v) < 0x38d7ea4c68000 ? String(v) : this.dialect.castDouble(String(v));
|
|
465
|
+
}
|
|
466
|
+
return this.param(v);
|
|
467
|
+
}
|
|
468
|
+
/** A statically known value as SQL (none is `NULL`). */
|
|
469
|
+
litOf(v) {
|
|
470
|
+
return Option.match(v, {
|
|
471
|
+
onNone: () => "NULL",
|
|
472
|
+
onSome: (s) => this.lit(s)
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
f(field) {
|
|
476
|
+
return isStatic(field) ? this.litOf(field.s) : field.q;
|
|
477
|
+
}
|
|
478
|
+
/** The id of a constant term (a query-local negative id if it is not in the dictionary). */
|
|
479
|
+
idOf(term) {
|
|
480
|
+
if (isDefaultGraph(term)) return 0;
|
|
481
|
+
return Option.getOrElse(this.resolve(term), () => this.localId(term));
|
|
482
|
+
}
|
|
483
|
+
/** The query-local id of a term that is not in the dictionary. */
|
|
484
|
+
localId(term) {
|
|
485
|
+
const local = Option.getOrElse(MutableHashMap.get(this.locals, term.key), () => {
|
|
486
|
+
const created = {
|
|
487
|
+
id: -(MutableHashMap.size(this.locals) + 1),
|
|
488
|
+
term
|
|
489
|
+
};
|
|
490
|
+
MutableHashMap.set(this.locals, term.key, created);
|
|
491
|
+
return created;
|
|
492
|
+
});
|
|
493
|
+
this.localClasses.add(classify(term).cls);
|
|
494
|
+
return local.id;
|
|
495
|
+
}
|
|
496
|
+
from(items) {
|
|
497
|
+
if (!Arr.isReadonlyArrayNonEmpty(items)) return "";
|
|
498
|
+
const [first, ...rest] = items;
|
|
499
|
+
const joins = rest.map((it) => Option.match(it.left, {
|
|
500
|
+
onNone: () => ` JOIN ${it.source} ${it.alias} ON TRUE`,
|
|
501
|
+
onSome: (on) => ` LEFT JOIN ${it.source} ${it.alias} ON ${on}`
|
|
502
|
+
}));
|
|
503
|
+
return ` FROM ${first.source} ${first.alias}${joins.join("")}`;
|
|
504
|
+
}
|
|
505
|
+
whereClause(where) {
|
|
506
|
+
return Arr.isReadonlyArrayEmpty(where) ? "" : ` WHERE ${where.join(" AND ")}`;
|
|
507
|
+
}
|
|
508
|
+
nullCol(type) {
|
|
509
|
+
return type === "id" ? this.dialect.nullId : this.dialect.castId("NULL");
|
|
510
|
+
}
|
|
511
|
+
render(block, names = Arr.fromIterable(MutableHashMap.keys(block.cols)), options = {}) {
|
|
512
|
+
const { types } = options;
|
|
513
|
+
const select = names.map((n) => {
|
|
514
|
+
return `${Option.match(MutableHashMap.get(block.cols, n), {
|
|
515
|
+
onNone: () => this.nullCol(types === void 0 ? "id" : Option.getOrElse(MutableHashMap.get(types, n), () => "id")),
|
|
516
|
+
onSome: (c) => c.sql
|
|
517
|
+
})} AS ${this.col(n)}`;
|
|
518
|
+
});
|
|
519
|
+
return `SELECT ${options.distinct === true ? "DISTINCT " : ""}${Arr.isReadonlyArrayEmpty(select) ? "1 AS one" : select.join(", ")}${this.from(block.items)}${this.whereClause(block.where)}`;
|
|
520
|
+
}
|
|
521
|
+
/** Wraps SQL as a subquery item. */
|
|
522
|
+
wrapSql(sql, cols) {
|
|
523
|
+
const alias = this.alias("s");
|
|
524
|
+
const out = MutableHashMap.empty();
|
|
525
|
+
MutableHashMap.forEach(cols, (c, n) => {
|
|
526
|
+
MutableHashMap.set(out, n, {
|
|
527
|
+
...c,
|
|
528
|
+
sql: `${alias}.${this.col(n)}`
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
return {
|
|
532
|
+
items: [inner(`(${sql})`, alias)],
|
|
533
|
+
where: [],
|
|
534
|
+
cols: out
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
wrap(block, options = {}) {
|
|
538
|
+
return this.wrapSql(this.render(block, void 0, options), block.cols);
|
|
539
|
+
}
|
|
540
|
+
compat(a, b) {
|
|
541
|
+
if (a.type !== b.type) return unsupported("Joining integer and term columns");
|
|
542
|
+
if (!a.nullable && !b.nullable) return {
|
|
543
|
+
cond: `${a.sql} = ${b.sql}`,
|
|
544
|
+
merged: a
|
|
545
|
+
};
|
|
546
|
+
if (!a.nullable) return {
|
|
547
|
+
cond: `(${b.sql} IS NULL OR ${b.sql} = ${a.sql})`,
|
|
548
|
+
merged: a
|
|
549
|
+
};
|
|
550
|
+
if (!b.nullable) return {
|
|
551
|
+
cond: `(${a.sql} IS NULL OR ${a.sql} = ${b.sql})`,
|
|
552
|
+
merged: b
|
|
553
|
+
};
|
|
554
|
+
return {
|
|
555
|
+
cond: `(${a.sql} IS NULL OR ${b.sql} IS NULL OR ${a.sql} = ${b.sql})`,
|
|
556
|
+
merged: {
|
|
557
|
+
sql: `COALESCE(${a.sql}, ${b.sql})`,
|
|
558
|
+
nullable: true,
|
|
559
|
+
type: a.type
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
join(a, b) {
|
|
564
|
+
if (isUnit(b)) return a;
|
|
565
|
+
if (isUnit(a)) return b;
|
|
566
|
+
const cols = MutableHashMap.fromIterable(a.cols);
|
|
567
|
+
const where = [...a.where, ...b.where];
|
|
568
|
+
MutableHashMap.forEach(b.cols, (cb, n) => Option.match(MutableHashMap.get(cols, n), {
|
|
569
|
+
onNone: () => {
|
|
570
|
+
MutableHashMap.set(cols, n, cb);
|
|
571
|
+
},
|
|
572
|
+
onSome: (ca) => {
|
|
573
|
+
const { cond, merged } = this.compat(ca, cb);
|
|
574
|
+
where.push(cond);
|
|
575
|
+
MutableHashMap.set(cols, n, merged);
|
|
576
|
+
}
|
|
577
|
+
}));
|
|
578
|
+
return {
|
|
579
|
+
items: [...a.items, ...b.items],
|
|
580
|
+
where,
|
|
581
|
+
cols
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
/** Ensures a block has a FROM item (so that a LEFT JOIN can be appended). */
|
|
585
|
+
anchored(block) {
|
|
586
|
+
if (Arr.isReadonlyArrayNonEmpty(block.items)) return block;
|
|
587
|
+
return {
|
|
588
|
+
...block,
|
|
589
|
+
items: [inner("(SELECT 1 AS one)", this.alias("u"))]
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
op(operation, g, unit) {
|
|
593
|
+
return Match.value(operation).pipe(Match.tag("Bgp", (op) => Arr.isReadonlyArrayEmpty(op.patterns) ? unit : this.bgp(op.patterns, g)), Match.tag("Join", (op) => this.join(this.op(op.left, g, unit), this.op(op.right, g, unit))), Match.tag("LeftJoin", (op) => this.leftJoin(op, g, unit)), Match.tag("Filter", (op) => {
|
|
594
|
+
const input = this.op(op.input, g, unit);
|
|
595
|
+
const cond = this.ebv(this.operand(op.expression, {
|
|
596
|
+
cols: input.cols,
|
|
597
|
+
graph: g
|
|
598
|
+
}));
|
|
599
|
+
if (cond === "TRUE") return input;
|
|
600
|
+
return {
|
|
601
|
+
...input,
|
|
602
|
+
where: [...input.where, cond]
|
|
603
|
+
};
|
|
604
|
+
}), Match.tag("Union", (op) => this.union(this.op(op.left, g, unit), this.op(op.right, g, unit))), Match.tag("Graph", (op) => this.graph(op, g, unit)), Match.tag("Extend", (op) => {
|
|
605
|
+
const input = this.op(op.input, g, unit);
|
|
606
|
+
if (MutableHashMap.has(input.cols, op.variable.value)) return unsupported("BIND to a bound variable");
|
|
607
|
+
const col = this.termValued(this.operand(op.expression, {
|
|
608
|
+
cols: input.cols,
|
|
609
|
+
graph: g
|
|
610
|
+
}));
|
|
611
|
+
const cols = MutableHashMap.fromIterable(input.cols);
|
|
612
|
+
MutableHashMap.set(cols, op.variable.value, col);
|
|
613
|
+
return {
|
|
614
|
+
...input,
|
|
615
|
+
cols
|
|
616
|
+
};
|
|
617
|
+
}), Match.tag("Minus", (op) => this.minus(this.op(op.left, g, unit), this.op(op.right, g, unit))), Match.tag("Group", (op) => this.group(op, g, unit)), Match.tag("Project", (op) => {
|
|
618
|
+
const input = this.op(op.input, g, unit);
|
|
619
|
+
const keep = MutableHashSet.fromIterable(op.variables.map((v) => v.value));
|
|
620
|
+
const cols = MutableHashMap.empty();
|
|
621
|
+
MutableHashMap.forEach(input.cols, (c, n) => {
|
|
622
|
+
if (MutableHashSet.has(keep, n) || isHidden(n)) MutableHashMap.set(cols, n, c);
|
|
623
|
+
});
|
|
624
|
+
return {
|
|
625
|
+
...input,
|
|
626
|
+
cols
|
|
627
|
+
};
|
|
628
|
+
}), Match.tag("Distinct", (op) => this.wrap(this.op(op.input, g, unit), { distinct: true })), Match.tag("Reduced", (op) => this.op(op.input, g, unit)), Match.tag("Slice", (op) => {
|
|
629
|
+
if (g.kind === "var") return unsupported("Slice inside GRAPH ?var");
|
|
630
|
+
const input = this.op(op.input, g, unit);
|
|
631
|
+
return this.wrapSql(`${this.render(input)}${this.dialect.limitOffset(op.limit, op.offset)}`, input.cols);
|
|
632
|
+
}), Match.tag("Values", (op) => {
|
|
633
|
+
return this.values(op);
|
|
634
|
+
}), Match.tag("OrderBy", () => unsupported("ORDER BY is evaluated by the engine")), Match.tag("Path", () => unsupported("Property paths are evaluated by the engine")), Match.tag("Service", () => unsupported("SERVICE is evaluated by the engine")), Match.exhaustive);
|
|
635
|
+
}
|
|
636
|
+
bgp(patterns, ctx) {
|
|
637
|
+
const items = [];
|
|
638
|
+
const where = [];
|
|
639
|
+
const cols = MutableHashMap.empty();
|
|
640
|
+
const bind = (name, sql) => Option.match(MutableHashMap.get(cols, name), {
|
|
641
|
+
onNone: () => {
|
|
642
|
+
MutableHashMap.set(cols, name, {
|
|
643
|
+
sql,
|
|
644
|
+
nullable: false,
|
|
645
|
+
type: "id"
|
|
646
|
+
});
|
|
647
|
+
},
|
|
648
|
+
onSome: (c) => {
|
|
649
|
+
where.push(`${c.sql} = ${sql}`);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
const position = (t, sql, bound) => {
|
|
653
|
+
return Match.value(t).pipe(Match.tag("Variable", (pattern) => {
|
|
654
|
+
bind(pattern.value, sql);
|
|
655
|
+
}), Match.tag("BlankNode", () => unsupported("Blank node in a pattern")), Match.tag("NamedNode", "Literal", (pattern) => {
|
|
656
|
+
bound.push(`${sql} = ${this.idOf(pattern)}`);
|
|
657
|
+
}), Match.tag("Triple", (pattern) => {
|
|
658
|
+
if (isGroundTriple(pattern)) {
|
|
659
|
+
bound.push(`${sql} = ${this.idOf(pattern)}`);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const ta = this.alias("t");
|
|
663
|
+
items.push(inner(this.T, ta));
|
|
664
|
+
where.push(`${ta}.id = ${sql}`, `${ta}.kind = ${Kind.Triple}`);
|
|
665
|
+
position(pattern.subject, `${ta}.sub`, where);
|
|
666
|
+
position(pattern.predicate, `${ta}.pre`, where);
|
|
667
|
+
position(pattern.object, `${ta}.obj`, where);
|
|
668
|
+
}), Match.exhaustive);
|
|
669
|
+
};
|
|
670
|
+
const { defaultGraph } = this.context.dataset;
|
|
671
|
+
patterns.forEach((p) => {
|
|
672
|
+
const a = this.alias("q");
|
|
673
|
+
if (ctx.kind === "default" && (defaultGraph === "union" || Array.isArray(defaultGraph) && defaultGraph.length > 1)) {
|
|
674
|
+
const conds = [];
|
|
675
|
+
if (!Predicate.isString(defaultGraph)) conds.push(`g IN (${defaultGraph.map((x) => this.idOf(x)).join(", ")})`);
|
|
676
|
+
const deferred = [];
|
|
677
|
+
const positionIn = (t, column) => {
|
|
678
|
+
if (isVariable(t) || isTriple(t) && !isGround(t)) deferred.push(() => position(t, `${a}.${column}`, where));
|
|
679
|
+
else position(t, column, conds);
|
|
680
|
+
};
|
|
681
|
+
positionIn(p.subject, "s");
|
|
682
|
+
positionIn(p.predicate, "p");
|
|
683
|
+
positionIn(p.object, "o");
|
|
684
|
+
items.push(inner(`(SELECT DISTINCT s, p, o FROM ${this.Q}${Arr.isReadonlyArrayNonEmpty(conds) ? ` WHERE ${conds.join(" AND ")}` : ""})`, a));
|
|
685
|
+
deferred.forEach((f) => f());
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
items.push(inner(this.Q, a));
|
|
689
|
+
Match.value(ctx).pipe(Match.when({ kind: "default" }, () => {
|
|
690
|
+
if (defaultGraph === "default") where.push(`${a}.g = 0`);
|
|
691
|
+
else if (!Predicate.isString(defaultGraph) && Predicate.isTupleOf(defaultGraph, 1)) where.push(`${a}.g = ${this.idOf(defaultGraph[0])}`);
|
|
692
|
+
else where.push("1 = 0");
|
|
693
|
+
}), Match.when({ kind: "const" }, (graph) => {
|
|
694
|
+
where.push(`${a}.g = ${graph.id}`);
|
|
695
|
+
}), Match.when({ kind: "var" }, (graph) => {
|
|
696
|
+
bind(graph.hidden, `${a}.g`);
|
|
697
|
+
where.push(this.namedGraphCond(`${a}.g`));
|
|
698
|
+
}), Match.exhaustive);
|
|
699
|
+
position(p.subject, `${a}.s`, where);
|
|
700
|
+
position(p.predicate, `${a}.p`, where);
|
|
701
|
+
position(p.object, `${a}.o`, where);
|
|
702
|
+
});
|
|
703
|
+
return {
|
|
704
|
+
items,
|
|
705
|
+
where,
|
|
706
|
+
cols
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
/** The condition that the graph id column `g` of a quad is a named graph of the dataset. */
|
|
710
|
+
namedGraphCond(g) {
|
|
711
|
+
const named = this.context.dataset.namedGraphs;
|
|
712
|
+
if (named === "all") return `${g} <> 0`;
|
|
713
|
+
if (Arr.isReadonlyArrayEmpty(named)) return "1 = 0";
|
|
714
|
+
return `${g} IN (${named.map((n) => this.idOf(n)).join(", ")})`;
|
|
715
|
+
}
|
|
716
|
+
/** A subquery listing the named graphs of the dataset (column `g`). */
|
|
717
|
+
namedGraphsSource() {
|
|
718
|
+
const named = this.context.dataset.namedGraphs;
|
|
719
|
+
if (named === "all") return `(SELECT id AS g FROM ${this.G} UNION SELECT DISTINCT g FROM ${this.Q} WHERE g <> 0)`;
|
|
720
|
+
if (Arr.isReadonlyArrayEmpty(named)) return `(SELECT ${this.dialect.nullId} AS g WHERE 1 = 0)`;
|
|
721
|
+
const alias = this.alias("n");
|
|
722
|
+
return `(SELECT column1 AS g FROM (VALUES ${named.map((n) => `(${this.idOf(n)})`).join(", ")}) AS ${alias})`;
|
|
723
|
+
}
|
|
724
|
+
values(op) {
|
|
725
|
+
const vars = op.variables.map((v) => v.value);
|
|
726
|
+
if (Arr.isReadonlyArrayEmpty(op.bindings)) return {
|
|
727
|
+
items: [],
|
|
728
|
+
where: ["1 = 0"],
|
|
729
|
+
cols: MutableHashMap.fromIterable(vars.map((v) => [v, {
|
|
730
|
+
sql: this.dialect.nullId,
|
|
731
|
+
nullable: true,
|
|
732
|
+
type: "id"
|
|
733
|
+
}]))
|
|
734
|
+
};
|
|
735
|
+
const rows = op.bindings.map((b) => Arr.isReadonlyArrayEmpty(vars) ? "(1)" : `(${vars.map((v) => {
|
|
736
|
+
const t = b.map.get(v);
|
|
737
|
+
return t === void 0 ? this.dialect.nullId : String(this.idOf(t));
|
|
738
|
+
}).join(", ")})`);
|
|
739
|
+
const a = this.alias("v");
|
|
740
|
+
const select = Arr.isReadonlyArrayEmpty(vars) ? "column1 AS one" : vars.map((v, i) => `column${i + 1} AS ${this.col(v)}`);
|
|
741
|
+
const cols = MutableHashMap.fromIterable(vars.map((v) => [v, {
|
|
742
|
+
sql: `${a}.${this.col(v)}`,
|
|
743
|
+
nullable: !op.bindings.every((b) => b.map.has(v)),
|
|
744
|
+
type: "id"
|
|
745
|
+
}]));
|
|
746
|
+
return {
|
|
747
|
+
items: [inner(`(SELECT ${Predicate.isString(select) ? select : select.join(", ")} FROM (VALUES ${rows.join(", ")}) AS ${a}_rows)`, a)],
|
|
748
|
+
where: [],
|
|
749
|
+
cols
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
leftJoin(op, g, unit) {
|
|
753
|
+
const left = this.op(op.left, g, unit);
|
|
754
|
+
const right = this.op(op.right, g, unit);
|
|
755
|
+
MutableHashMap.forEach(right.cols, (c, n) => {
|
|
756
|
+
const leftNullable = Option.match(MutableHashMap.get(left.cols, n), {
|
|
757
|
+
onNone: () => true,
|
|
758
|
+
onSome: (l) => l.nullable
|
|
759
|
+
});
|
|
760
|
+
if (isHidden(n) && leftNullable && !c.nullable) unsupported("OPTIONAL graph-dependent pattern under GRAPH ?var");
|
|
761
|
+
});
|
|
762
|
+
if (op.expression === void 0 && isUnit(right)) return left;
|
|
763
|
+
const a = this.anchored(left);
|
|
764
|
+
const r = this.wrap(right);
|
|
765
|
+
const conds = [];
|
|
766
|
+
const merged = MutableHashMap.fromIterable(a.cols);
|
|
767
|
+
const out = MutableHashMap.fromIterable(a.cols);
|
|
768
|
+
MutableHashMap.forEach(r.cols, (cr, n) => Option.match(MutableHashMap.get(a.cols, n), {
|
|
769
|
+
onNone: () => {
|
|
770
|
+
MutableHashMap.set(merged, n, cr);
|
|
771
|
+
MutableHashMap.set(out, n, {
|
|
772
|
+
...cr,
|
|
773
|
+
nullable: true
|
|
774
|
+
});
|
|
775
|
+
},
|
|
776
|
+
onSome: (ca) => {
|
|
777
|
+
const { cond, merged: m } = this.compat(ca, cr);
|
|
778
|
+
conds.push(cond);
|
|
779
|
+
MutableHashMap.set(merged, n, m);
|
|
780
|
+
MutableHashMap.set(out, n, ca.nullable ? {
|
|
781
|
+
sql: `COALESCE(${ca.sql}, ${cr.sql})`,
|
|
782
|
+
nullable: true,
|
|
783
|
+
type: ca.type
|
|
784
|
+
} : ca);
|
|
785
|
+
}
|
|
786
|
+
}));
|
|
787
|
+
if (op.expression !== void 0) {
|
|
788
|
+
const e = this.ebv(this.operand(op.expression, {
|
|
789
|
+
cols: merged,
|
|
790
|
+
graph: g
|
|
791
|
+
}));
|
|
792
|
+
if (e !== "TRUE") conds.push(e);
|
|
793
|
+
}
|
|
794
|
+
const on = Arr.isReadonlyArrayEmpty(conds) ? "TRUE" : conds.join(" AND ");
|
|
795
|
+
const [item] = r.items;
|
|
796
|
+
return {
|
|
797
|
+
items: [...a.items, {
|
|
798
|
+
source: item.source,
|
|
799
|
+
alias: item.alias,
|
|
800
|
+
left: Option.some(on)
|
|
801
|
+
}],
|
|
802
|
+
where: a.where,
|
|
803
|
+
cols: out
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
union(a, b) {
|
|
807
|
+
const names = distinct([...MutableHashMap.keys(a.cols), ...MutableHashMap.keys(b.cols)]);
|
|
808
|
+
const cols = MutableHashMap.empty();
|
|
809
|
+
const types = MutableHashMap.empty();
|
|
810
|
+
names.forEach((n) => {
|
|
811
|
+
const ca = MutableHashMap.get(a.cols, n);
|
|
812
|
+
const cb = MutableHashMap.get(b.cols, n);
|
|
813
|
+
if (Option.isSome(ca) && Option.isSome(cb) && ca.value.type !== cb.value.type) unsupported("UNION of integer and term columns");
|
|
814
|
+
const nullable = Option.isNone(ca) || Option.isNone(cb) || ca.value.nullable || cb.value.nullable;
|
|
815
|
+
if (isHidden(n) && nullable) unsupported("UNION of graph-dependent and independent patterns under GRAPH ?var");
|
|
816
|
+
const type = Option.isSome(ca) ? ca.value.type : Option.isSome(cb) ? cb.value.type : "id";
|
|
817
|
+
MutableHashMap.set(types, n, type);
|
|
818
|
+
MutableHashMap.set(cols, n, {
|
|
819
|
+
nullable,
|
|
820
|
+
type
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
const sql = `${this.render(a, names, { types })} UNION ALL ${this.render(b, names, { types })}`;
|
|
824
|
+
return this.wrapSql(sql, cols);
|
|
825
|
+
}
|
|
826
|
+
minus(a, b) {
|
|
827
|
+
const bNames = Arr.fromIterable(MutableHashMap.keys(b.cols));
|
|
828
|
+
const shared = bNames.filter((n) => MutableHashMap.has(a.cols, n));
|
|
829
|
+
if (bNames.some((n) => isHidden(n) && !MutableHashMap.has(a.cols, n))) return unsupported("MINUS of a graph-dependent pattern under GRAPH ?var");
|
|
830
|
+
const overlap = shared.filter((n) => !isHidden(n));
|
|
831
|
+
if (Arr.isReadonlyArrayEmpty(overlap)) return a;
|
|
832
|
+
const m = this.wrap(b);
|
|
833
|
+
const pairs = Arr.filterMap(shared, (name) => {
|
|
834
|
+
const left = MutableHashMap.get(a.cols, name);
|
|
835
|
+
const right = MutableHashMap.get(m.cols, name);
|
|
836
|
+
return Option.isSome(left) && Option.isSome(right) ? Result.succeed({
|
|
837
|
+
name,
|
|
838
|
+
left: left.value,
|
|
839
|
+
right: right.value
|
|
840
|
+
}) : Result.failVoid;
|
|
841
|
+
});
|
|
842
|
+
const conds = pairs.map(({ left, right }) => this.compat(left, right).cond);
|
|
843
|
+
const overlapCond = or(...pairs.filter(({ name }) => !isHidden(name)).map(({ left, right }) => and(left.nullable ? `${left.sql} IS NOT NULL` : true, right.nullable ? `${right.sql} IS NOT NULL` : true)));
|
|
844
|
+
if (overlapCond === false) return a;
|
|
845
|
+
if (overlapCond !== true) conds.push(overlapCond);
|
|
846
|
+
const [item] = m.items;
|
|
847
|
+
return {
|
|
848
|
+
...a,
|
|
849
|
+
where: [...a.where, `NOT EXISTS (SELECT 1 FROM ${item.source} ${item.alias} WHERE ${conds.join(" AND ")})`]
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
graph(op, g, unit) {
|
|
853
|
+
const name = op.name;
|
|
854
|
+
if (isNamedNode(name)) {
|
|
855
|
+
const id = this.idOf(name);
|
|
856
|
+
const input = this.op(op.input, {
|
|
857
|
+
kind: "const",
|
|
858
|
+
id
|
|
859
|
+
}, unit);
|
|
860
|
+
const named = this.context.dataset.namedGraphs;
|
|
861
|
+
const cond = named === "all" ? `(EXISTS (SELECT 1 FROM ${this.G} WHERE id = ${id}) OR EXISTS (SELECT 1 FROM ${this.Q} WHERE g = ${id}))` : named.some((n) => n.key === name.key) ? "TRUE" : "1 = 0";
|
|
862
|
+
return cond === "TRUE" ? input : {
|
|
863
|
+
...input,
|
|
864
|
+
where: [...input.where, cond]
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
const hidden = `#${this.alias("g")}`;
|
|
868
|
+
const body = this.op(op.input, {
|
|
869
|
+
kind: "var",
|
|
870
|
+
hidden
|
|
871
|
+
}, unit);
|
|
872
|
+
const bound = MutableHashMap.get(body.cols, hidden);
|
|
873
|
+
if (Option.isSome(bound) && bound.value.nullable) return unsupported("Graph-independent solutions under GRAPH ?var");
|
|
874
|
+
const { input, gcol } = Option.match(bound, {
|
|
875
|
+
onSome: (c) => ({
|
|
876
|
+
input: body,
|
|
877
|
+
gcol: c
|
|
878
|
+
}),
|
|
879
|
+
onNone: () => {
|
|
880
|
+
const alias = this.alias("n");
|
|
881
|
+
return {
|
|
882
|
+
input: {
|
|
883
|
+
...body,
|
|
884
|
+
items: [...body.items, inner(this.namedGraphsSource(), alias)]
|
|
885
|
+
},
|
|
886
|
+
gcol: {
|
|
887
|
+
sql: `${alias}.g`,
|
|
888
|
+
nullable: false,
|
|
889
|
+
type: "id"
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
const cols = MutableHashMap.fromIterable(input.cols);
|
|
895
|
+
MutableHashMap.remove(cols, hidden);
|
|
896
|
+
const where = [...input.where];
|
|
897
|
+
Option.match(MutableHashMap.get(cols, name.value), {
|
|
898
|
+
onNone: () => void 0,
|
|
899
|
+
onSome: (existing) => {
|
|
900
|
+
where.push(this.compat(existing, gcol).cond);
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
MutableHashMap.set(cols, name.value, gcol);
|
|
904
|
+
return {
|
|
905
|
+
items: input.items,
|
|
906
|
+
where,
|
|
907
|
+
cols
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
group(op, g, unit) {
|
|
911
|
+
if (g.kind === "var") return unsupported("GROUP inside GRAPH ?var");
|
|
912
|
+
const input = this.op(op.input, g, unit);
|
|
913
|
+
const needed = MutableHashSet.empty();
|
|
914
|
+
const keyVars = op.keys.map((k) => {
|
|
915
|
+
const e = k.expression;
|
|
916
|
+
if (!isVariable(e)) return unsupported("Non-variable group key");
|
|
917
|
+
const col = Option.getOrElse(MutableHashMap.get(input.cols, e.value), () => unsupported("Group key is never bound"));
|
|
918
|
+
MutableHashSet.add(needed, e.value);
|
|
919
|
+
return {
|
|
920
|
+
source: e.value,
|
|
921
|
+
target: k.variable.value,
|
|
922
|
+
col
|
|
923
|
+
};
|
|
924
|
+
});
|
|
925
|
+
const aggs = op.aggregates.map(({ variable, aggregate }) => {
|
|
926
|
+
const e = aggregate.expression;
|
|
927
|
+
if (aggregate.name === "COUNT") {
|
|
928
|
+
if (e === "*") {
|
|
929
|
+
if (aggregate.distinct) return unsupported("COUNT(DISTINCT *)");
|
|
930
|
+
return {
|
|
931
|
+
target: variable.value,
|
|
932
|
+
sql: () => "COUNT(*)",
|
|
933
|
+
col: {
|
|
934
|
+
nullable: false,
|
|
935
|
+
type: "int"
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
if (!isVariable(e)) return unsupported("COUNT of an expression");
|
|
940
|
+
const name = e.value;
|
|
941
|
+
if (!MutableHashMap.has(input.cols, name)) return {
|
|
942
|
+
target: variable.value,
|
|
943
|
+
sql: () => "0",
|
|
944
|
+
col: {
|
|
945
|
+
nullable: false,
|
|
946
|
+
type: "int"
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
MutableHashSet.add(needed, name);
|
|
950
|
+
return {
|
|
951
|
+
target: variable.value,
|
|
952
|
+
sql: (s) => `COUNT(${aggregate.distinct ? "DISTINCT " : ""}${s}.${this.col(name)})`,
|
|
953
|
+
col: {
|
|
954
|
+
nullable: false,
|
|
955
|
+
type: "int"
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
if (aggregate.name === "SAMPLE" && isVariable(e)) {
|
|
960
|
+
const name = e.value;
|
|
961
|
+
return Option.match(MutableHashMap.get(input.cols, name), {
|
|
962
|
+
onNone: () => ({
|
|
963
|
+
target: variable.value,
|
|
964
|
+
sql: () => this.dialect.nullId,
|
|
965
|
+
col: {
|
|
966
|
+
nullable: true,
|
|
967
|
+
type: "id"
|
|
968
|
+
}
|
|
969
|
+
}),
|
|
970
|
+
onSome: (c) => {
|
|
971
|
+
MutableHashSet.add(needed, name);
|
|
972
|
+
return {
|
|
973
|
+
target: variable.value,
|
|
974
|
+
sql: (s) => `MIN(${s}.${this.col(name)})`,
|
|
975
|
+
col: {
|
|
976
|
+
nullable: true,
|
|
977
|
+
type: c.type
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
return unsupported(`Aggregate ${aggregate.name}`);
|
|
984
|
+
});
|
|
985
|
+
const s = this.alias("a");
|
|
986
|
+
const cols = MutableHashMap.empty();
|
|
987
|
+
const select = [...keyVars.map((k) => {
|
|
988
|
+
const sql = `${s}.${this.col(k.source)} AS ${this.col(k.target)}`;
|
|
989
|
+
MutableHashMap.set(cols, k.target, {
|
|
990
|
+
nullable: k.col.nullable,
|
|
991
|
+
type: k.col.type
|
|
992
|
+
});
|
|
993
|
+
return sql;
|
|
994
|
+
}), ...aggs.map((agg) => {
|
|
995
|
+
const sql = `${agg.sql(s)} AS ${this.col(agg.target)}`;
|
|
996
|
+
MutableHashMap.set(cols, agg.target, agg.col);
|
|
997
|
+
return sql;
|
|
998
|
+
})];
|
|
999
|
+
const innerSql = this.render(input, Arr.fromIterable(needed));
|
|
1000
|
+
const groupBy = Arr.isReadonlyArrayEmpty(keyVars) ? "" : ` GROUP BY ${distinct(keyVars.map((k) => `${s}.${this.col(k.source)}`)).join(", ")}`;
|
|
1001
|
+
const sql = `SELECT ${Arr.isReadonlyArrayEmpty(select) ? "1 AS one" : select.join(", ")} FROM (${innerSql}) ${s}${groupBy}`;
|
|
1002
|
+
return this.wrapSql(sql, cols);
|
|
1003
|
+
}
|
|
1004
|
+
/** A dictionary attribute of a term id expression. */
|
|
1005
|
+
attr(id, field) {
|
|
1006
|
+
const lookup = `(SELECT ${field} FROM ${this.T} WHERE id = ${id})`;
|
|
1007
|
+
if (MutableHashMap.isEmpty(this.locals)) return lookup;
|
|
1008
|
+
if (!this.localsKnown) return lookup;
|
|
1009
|
+
return `(CASE WHEN ${id} < 0 THEN (CASE ${id} ${Arr.fromIterable(MutableHashMap.values(this.locals)).map(({ id: localId, term }) => {
|
|
1010
|
+
const row = encode(term, [
|
|
1011
|
+
0,
|
|
1012
|
+
0,
|
|
1013
|
+
0
|
|
1014
|
+
]);
|
|
1015
|
+
const v = field === "num" ? this.litOf(row.num) : this.lit(row[field]);
|
|
1016
|
+
return `WHEN ${localId} THEN ${field === "num" ? this.dialect.castDouble(v) : field === "kind" || field === "cls" ? this.dialect.castInt(v) : this.dialect.castText(v)}`;
|
|
1017
|
+
}).join(" ")} END) ELSE ${lookup} END)`;
|
|
1018
|
+
}
|
|
1019
|
+
termOperand(id, nullable) {
|
|
1020
|
+
return {
|
|
1021
|
+
tag: "term",
|
|
1022
|
+
classes: Option.none(),
|
|
1023
|
+
isNull: nullable ? Q(`${id} IS NULL`) : S(false),
|
|
1024
|
+
cls: Q(this.attr(id, "cls")),
|
|
1025
|
+
kind: Q(this.attr(id, "kind")),
|
|
1026
|
+
value: Q(this.attr(id, "value")),
|
|
1027
|
+
datatype: Q(this.attr(id, "datatype")),
|
|
1028
|
+
lang: Q(this.attr(id, "lang")),
|
|
1029
|
+
dir: Q(this.attr(id, "dir")),
|
|
1030
|
+
num: Q(this.attr(id, "num")),
|
|
1031
|
+
id: Q(id)
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
constOperand(constant) {
|
|
1035
|
+
const { cls, num } = classify(constant);
|
|
1036
|
+
const base = {
|
|
1037
|
+
tag: "const",
|
|
1038
|
+
classes: Option.some([cls]),
|
|
1039
|
+
isNull: S(false),
|
|
1040
|
+
cls: S(cls),
|
|
1041
|
+
num: SO(num),
|
|
1042
|
+
id: S(this.idOf(constant)),
|
|
1043
|
+
term: constant
|
|
1044
|
+
};
|
|
1045
|
+
return Match.value(constant).pipe(Match.withReturnType(), Match.tag("NamedNode", "BlankNode", (term) => ({
|
|
1046
|
+
...base,
|
|
1047
|
+
kind: S(isNamedNode(term) ? Kind.NamedNode : Kind.BlankNode),
|
|
1048
|
+
value: S(term.value),
|
|
1049
|
+
datatype: S(""),
|
|
1050
|
+
lang: S(""),
|
|
1051
|
+
dir: S("")
|
|
1052
|
+
})), Match.tag("Literal", (term) => ({
|
|
1053
|
+
...base,
|
|
1054
|
+
kind: S(Kind.Literal),
|
|
1055
|
+
value: S(term.value),
|
|
1056
|
+
datatype: S(term.datatype.value),
|
|
1057
|
+
lang: S(term.language),
|
|
1058
|
+
dir: S(term.direction ?? "")
|
|
1059
|
+
})), Match.tag("Triple", () => ({
|
|
1060
|
+
...base,
|
|
1061
|
+
kind: S(Kind.Triple),
|
|
1062
|
+
value: SNULL,
|
|
1063
|
+
datatype: S(""),
|
|
1064
|
+
lang: S(""),
|
|
1065
|
+
dir: S("")
|
|
1066
|
+
})), Match.exhaustive);
|
|
1067
|
+
}
|
|
1068
|
+
intOperand(sql, nullable) {
|
|
1069
|
+
return {
|
|
1070
|
+
tag: "int",
|
|
1071
|
+
classes: Option.some([Cls.SafeNumber]),
|
|
1072
|
+
isNull: nullable ? Q(`${sql} IS NULL`) : S(false),
|
|
1073
|
+
cls: S(Cls.SafeNumber),
|
|
1074
|
+
kind: S(Kind.Literal),
|
|
1075
|
+
value: Q(this.dialect.castText(sql)),
|
|
1076
|
+
datatype: S(`${XSD}integer`),
|
|
1077
|
+
lang: S(""),
|
|
1078
|
+
dir: S(""),
|
|
1079
|
+
num: Q(sql)
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
strOperand(sql) {
|
|
1083
|
+
return {
|
|
1084
|
+
tag: "str",
|
|
1085
|
+
classes: Option.some([Cls.String]),
|
|
1086
|
+
isNull: Q(`${sql} IS NULL`),
|
|
1087
|
+
cls: S(Cls.String),
|
|
1088
|
+
kind: S(Kind.Literal),
|
|
1089
|
+
value: Q(sql),
|
|
1090
|
+
datatype: S(XSD_STRING),
|
|
1091
|
+
lang: S(""),
|
|
1092
|
+
dir: S(""),
|
|
1093
|
+
num: SNULL
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
boolOperand(sql) {
|
|
1097
|
+
if (sql === "TRUE" || sql === "FALSE") return this.constOperand(sql === "TRUE" ? TRUE : FALSE);
|
|
1098
|
+
return {
|
|
1099
|
+
tag: "bool",
|
|
1100
|
+
classes: Option.some([Cls.Boolean]),
|
|
1101
|
+
isNull: Q(`${sql} IS NULL`),
|
|
1102
|
+
cls: S(Cls.Boolean),
|
|
1103
|
+
kind: S(Kind.Literal),
|
|
1104
|
+
value: Q(`(CASE WHEN ${sql} THEN 'true' WHEN NOT ${sql} THEN 'false' END)`),
|
|
1105
|
+
datatype: S(`${XSD}boolean`),
|
|
1106
|
+
lang: S(""),
|
|
1107
|
+
dir: S(""),
|
|
1108
|
+
num: Q(`(CASE WHEN ${sql} THEN 1 WHEN NOT ${sql} THEN 0 END)`),
|
|
1109
|
+
bool: sql
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
iriOperand(sql) {
|
|
1113
|
+
return {
|
|
1114
|
+
tag: "iri",
|
|
1115
|
+
classes: Option.some([Cls.Resource]),
|
|
1116
|
+
isNull: Q(`${sql} IS NULL`),
|
|
1117
|
+
cls: S(Cls.Resource),
|
|
1118
|
+
kind: S(Kind.NamedNode),
|
|
1119
|
+
value: Q(sql),
|
|
1120
|
+
datatype: S(""),
|
|
1121
|
+
lang: S(""),
|
|
1122
|
+
dir: S(""),
|
|
1123
|
+
num: SNULL
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
NULL = {
|
|
1127
|
+
tag: "null",
|
|
1128
|
+
classes: Option.some([]),
|
|
1129
|
+
isNull: S(true),
|
|
1130
|
+
cls: SNULL,
|
|
1131
|
+
kind: SNULL,
|
|
1132
|
+
value: SNULL,
|
|
1133
|
+
datatype: SNULL,
|
|
1134
|
+
lang: SNULL,
|
|
1135
|
+
dir: SNULL,
|
|
1136
|
+
num: SNULL
|
|
1137
|
+
};
|
|
1138
|
+
/** A term-valued expression as a column (for `BIND`). */
|
|
1139
|
+
termValued(operand) {
|
|
1140
|
+
return Match.value(operand).pipe(Match.withReturnType(), Match.when({ tag: "term" }, (o) => ({
|
|
1141
|
+
sql: this.f(o.id),
|
|
1142
|
+
nullable: !isStaticValue(o.isNull, false),
|
|
1143
|
+
type: "id"
|
|
1144
|
+
})), Match.when({ tag: "const" }, (o) => ({
|
|
1145
|
+
sql: String(this.idOf(o.term)),
|
|
1146
|
+
nullable: false,
|
|
1147
|
+
type: "id"
|
|
1148
|
+
})), Match.when({ tag: "int" }, (o) => ({
|
|
1149
|
+
sql: this.f(o.num),
|
|
1150
|
+
nullable: !isStaticValue(o.isNull, false),
|
|
1151
|
+
type: "int"
|
|
1152
|
+
})), Match.when({ tag: "bool" }, (o) => ({
|
|
1153
|
+
sql: `(CASE WHEN ${o.bool} THEN ${this.idOf(TRUE)} WHEN NOT ${o.bool} THEN ${this.idOf(FALSE)} END)`,
|
|
1154
|
+
nullable: true,
|
|
1155
|
+
type: "id"
|
|
1156
|
+
})), Match.when({ tag: "null" }, () => ({
|
|
1157
|
+
sql: this.dialect.nullId,
|
|
1158
|
+
nullable: true,
|
|
1159
|
+
type: "id"
|
|
1160
|
+
})), Match.orElse(() => unsupported("Expression value is not a stored term")));
|
|
1161
|
+
}
|
|
1162
|
+
/** Compiles an expression to an operand. */
|
|
1163
|
+
operand(expr, env) {
|
|
1164
|
+
return Match.value(expr).pipe(Match.tag("Variable", (e) => Option.match(MutableHashMap.get(env.cols, e.value), {
|
|
1165
|
+
onNone: () => this.NULL,
|
|
1166
|
+
onSome: (c) => c.type === "int" ? this.intOperand(c.sql, c.nullable) : this.termOperand(c.sql, c.nullable)
|
|
1167
|
+
})), Match.tag("NamedNode", "Literal", (e) => this.constOperand(e)), Match.tag("BlankNode", () => unsupported("Blank node in an expression")), Match.tag("Triple", (e) => isGroundTriple(e) ? this.constOperand(e) : unsupported("Triple term pattern in an expression")), Match.tag("FunctionCall", (e) => unsupported(`Function <${e.function.value}>`)), Match.tag("Exists", (e) => this.boolOperand(this.exists(e, env))), Match.tag("Operation", (e) => this.operation(e, env)), Match.exhaustive);
|
|
1168
|
+
}
|
|
1169
|
+
operation(expr, env) {
|
|
1170
|
+
const args = expr.args;
|
|
1171
|
+
const arg = (i) => Option.match(Arr.get(args, i), {
|
|
1172
|
+
onNone: () => unsupported(`Operator ${expr.operator} without argument ${i + 1}`),
|
|
1173
|
+
onSome: (a) => this.operand(a, env)
|
|
1174
|
+
});
|
|
1175
|
+
const bool = (sql) => this.boolOperand(sql);
|
|
1176
|
+
return Match.value(expr).pipe(Match.when({ operator: "&&" }, () => bool(`(${this.ebv(arg(0))} AND ${this.ebv(arg(1))})`)), Match.when({ operator: "||" }, () => bool(`(${this.ebv(arg(0))} OR ${this.ebv(arg(1))})`)), Match.when({ operator: "!" }, () => bool(`(NOT ${this.ebv(arg(0))})`)), Match.when({ operator: "=" }, () => bool(this.equals(arg(0), arg(1)))), Match.when({ operator: "!=" }, () => bool(`(NOT ${this.equals(arg(0), arg(1))})`)), Match.when({ operator: Match.is("<", ">", "<=", ">=") }, (e) => bool(this.compare(arg(0), arg(1), e.operator))), Match.when({ operator: Match.is("IN", "NOT IN") }, (e) => {
|
|
1177
|
+
const value = arg(0);
|
|
1178
|
+
const tests = args.slice(1).map((_, i) => this.equals(value, arg(i + 1)));
|
|
1179
|
+
const any = Arr.isReadonlyArrayEmpty(tests) ? "FALSE" : `(${tests.join(" OR ")})`;
|
|
1180
|
+
return bool(e.operator === "IN" ? any : `(NOT ${any})`);
|
|
1181
|
+
}), Match.when({ operator: "BOUND" }, () => {
|
|
1182
|
+
const v = args[0];
|
|
1183
|
+
if (!isVariable(v)) return unsupported("BOUND of a non-variable");
|
|
1184
|
+
return bool(Option.match(MutableHashMap.get(env.cols, v.value), {
|
|
1185
|
+
onNone: () => "FALSE",
|
|
1186
|
+
onSome: (c) => c.nullable ? `(${c.sql} IS NOT NULL)` : "TRUE"
|
|
1187
|
+
}));
|
|
1188
|
+
}), Match.when({ operator: "SAMETERM" }, () => {
|
|
1189
|
+
const a = arg(0);
|
|
1190
|
+
const b = arg(1);
|
|
1191
|
+
if (a.tag === "null" || b.tag === "null") return bool("NULL");
|
|
1192
|
+
const ia = operandId(a);
|
|
1193
|
+
const ib = operandId(b);
|
|
1194
|
+
if (Option.isNone(ia) || Option.isNone(ib)) return unsupported("sameTerm of computed values");
|
|
1195
|
+
return bool(`(${this.f(ia.value)} = ${this.f(ib.value)})`);
|
|
1196
|
+
}), Match.when({ operator: Match.is("ISIRI", "ISURI") }, () => bool(this.kindTest(arg(0), Kind.NamedNode))), Match.when({ operator: "ISBLANK" }, () => bool(this.kindTest(arg(0), Kind.BlankNode))), Match.when({ operator: "ISLITERAL" }, () => bool(this.kindTest(arg(0), Kind.Literal))), Match.when({ operator: "ISTRIPLE" }, () => bool(this.kindTest(arg(0), Kind.Triple))), Match.when({ operator: "ISNUMERIC" }, () => {
|
|
1197
|
+
const a = arg(0);
|
|
1198
|
+
return bool(this.guard(a, condSql(this.clsIn(a, [
|
|
1199
|
+
1,
|
|
1200
|
+
2,
|
|
1201
|
+
3,
|
|
1202
|
+
8,
|
|
1203
|
+
11
|
|
1204
|
+
]))));
|
|
1205
|
+
}), Match.when({ operator: "HASLANG" }, () => {
|
|
1206
|
+
const a = arg(0);
|
|
1207
|
+
return bool(this.guard(a, condSql(this.clsIn(a, [Cls.LangString]))));
|
|
1208
|
+
}), Match.when({ operator: "HASLANGDIR" }, () => {
|
|
1209
|
+
const a = arg(0);
|
|
1210
|
+
return bool(this.guard(a, condSql(and(this.clsIn(a, [Cls.LangString]), this.ne(a.dir, S(""))))));
|
|
1211
|
+
}), Match.when({ operator: "STR" }, () => {
|
|
1212
|
+
const a = arg(0);
|
|
1213
|
+
if (a.tag === "const") {
|
|
1214
|
+
const t = a.term;
|
|
1215
|
+
if (isNamedNode(t) || isLiteral(t)) return this.constOperand(literal(t.value));
|
|
1216
|
+
return this.NULL;
|
|
1217
|
+
}
|
|
1218
|
+
if (a.tag === "str" || a.tag === "null") return a;
|
|
1219
|
+
return this.strOperand(caseOf([[this.isNullC(a), "NULL"], [or(this.eqC(a.kind, Kind.NamedNode), this.eqC(a.kind, Kind.Literal)), this.f(a.value)]], "NULL"));
|
|
1220
|
+
}), Match.when({ operator: "LANG" }, () => {
|
|
1221
|
+
const a = arg(0);
|
|
1222
|
+
if (a.tag === "const") {
|
|
1223
|
+
const t = a.term;
|
|
1224
|
+
return isLiteral(t) ? this.constOperand(literal(t.language)) : this.NULL;
|
|
1225
|
+
}
|
|
1226
|
+
if (a.tag === "null") return a;
|
|
1227
|
+
return this.strOperand(caseOf([[this.isNullC(a), "NULL"], [this.eqC(a.kind, Kind.Literal), this.f(a.lang)]], "NULL"));
|
|
1228
|
+
})).pipe(Match.when({ operator: "DATATYPE" }, () => {
|
|
1229
|
+
const a = arg(0);
|
|
1230
|
+
if (a.tag === "const") {
|
|
1231
|
+
const t = a.term;
|
|
1232
|
+
return isLiteral(t) ? this.constOperand(t.datatype) : this.NULL;
|
|
1233
|
+
}
|
|
1234
|
+
if (a.tag === "null") return a;
|
|
1235
|
+
return this.iriOperand(caseOf([[this.isNullC(a), "NULL"], [this.eqC(a.kind, Kind.Literal), this.f(a.datatype)]], "NULL"));
|
|
1236
|
+
}), Match.when({ operator: "STRLEN" }, () => {
|
|
1237
|
+
const a = arg(0);
|
|
1238
|
+
if (a.tag === "null") return a;
|
|
1239
|
+
return this.intOperand(caseOf([[this.clsIn(a, [Cls.String, Cls.LangString]), this.dialect.length(this.f(a.value))]], "NULL"), true);
|
|
1240
|
+
}), Match.when({ operator: Match.is("STRSTARTS", "STRENDS", "CONTAINS") }, (e) => {
|
|
1241
|
+
const a = arg(0);
|
|
1242
|
+
const b = arg(1);
|
|
1243
|
+
const fn = e.operator === "STRSTARTS" ? this.dialect.startsWith : e.operator === "STRENDS" ? this.dialect.endsWith : this.dialect.contains;
|
|
1244
|
+
const strings = [Cls.String, Cls.LangString];
|
|
1245
|
+
const ok = and(this.clsIn(a, strings), this.clsIn(b, strings), or(this.clsIn(b, [Cls.String]), and(this.eqFF(a.lang, b.lang), this.eqFF(a.dir, b.dir))));
|
|
1246
|
+
return bool(caseOf([[ok, fn(this.f(a.value), this.f(b.value))]], "NULL"));
|
|
1247
|
+
}), Match.when({ operator: "LANGMATCHES" }, () => {
|
|
1248
|
+
const a = arg(0);
|
|
1249
|
+
const b = arg(1);
|
|
1250
|
+
if (b.tag !== "const") return unsupported("LANGMATCHES with a non-constant range");
|
|
1251
|
+
const range = b.term;
|
|
1252
|
+
if (!isLiteral(range) || classify(range).cls !== Cls.String) return bool("NULL");
|
|
1253
|
+
if (!/^[\x00-\x7f]*$/.test(range.value)) return unsupported("Non-ASCII language range");
|
|
1254
|
+
const r = range.value.toLowerCase();
|
|
1255
|
+
const tag = `lower(${this.f(a.value)})`;
|
|
1256
|
+
const test = r === "*" ? `(${this.f(a.value)} <> '')` : `(${tag} = ${this.lit(r)} OR ${this.dialect.startsWith(tag, this.lit(`${r}-`))})`;
|
|
1257
|
+
return bool(caseOf([[this.clsIn(a, [Cls.String]), test]], "NULL"));
|
|
1258
|
+
}), Match.when({ operator: "IF" }, () => {
|
|
1259
|
+
const c = this.ebv(arg(0));
|
|
1260
|
+
const a = arg(1);
|
|
1261
|
+
const b = arg(2);
|
|
1262
|
+
const ca = this.termValued(a);
|
|
1263
|
+
const cb = this.termValued(b);
|
|
1264
|
+
if (ca.type !== cb.type) return unsupported("IF of integer and term values");
|
|
1265
|
+
const sql = `(CASE WHEN ${c} THEN ${ca.sql} WHEN NOT ${c} THEN ${cb.sql} END)`;
|
|
1266
|
+
return ca.type === "int" ? this.intOperand(sql, true) : this.termOperand(sql, true);
|
|
1267
|
+
}), Match.when({ operator: "COALESCE" }, () => {
|
|
1268
|
+
const parts = args.map((_, i) => arg(i)).filter((o) => o.tag !== "null");
|
|
1269
|
+
if (!Arr.isReadonlyArrayNonEmpty(parts)) return this.NULL;
|
|
1270
|
+
const cols = Arr.map(parts, (o) => this.termValued(o));
|
|
1271
|
+
const [first, ...rest] = cols;
|
|
1272
|
+
const type = first.type;
|
|
1273
|
+
if (rest.some((c) => c.type !== type)) return unsupported("COALESCE of integer and term values");
|
|
1274
|
+
const sql = Arr.isReadonlyArrayEmpty(rest) ? first.sql : `COALESCE(${cols.map((c) => c.sql).join(", ")})`;
|
|
1275
|
+
const nullable = cols.every((c) => c.nullable);
|
|
1276
|
+
return type === "int" ? this.intOperand(sql, nullable) : this.termOperand(sql, nullable);
|
|
1277
|
+
}), Match.orElse((e) => unsupported(`Operator ${e.operator}`)));
|
|
1278
|
+
}
|
|
1279
|
+
isNullC(o) {
|
|
1280
|
+
return isStatic(o.isNull) ? Option.exists(o.isNull.s, (s) => s === true) : o.isNull.q;
|
|
1281
|
+
}
|
|
1282
|
+
eqC(f, v) {
|
|
1283
|
+
if (isStatic(f)) return Option.exists(f.s, (s) => s === v);
|
|
1284
|
+
return `${f.q} = ${this.lit(v)}`;
|
|
1285
|
+
}
|
|
1286
|
+
clsIn(o, classes) {
|
|
1287
|
+
const f = o.cls;
|
|
1288
|
+
if (isStatic(f)) return Option.exists(f.s, (s) => Predicate.isNumber(s) && classes.includes(s));
|
|
1289
|
+
return classes.length === 1 ? `${f.q} = ${classes[0]}` : `${f.q} IN (${classes.join(", ")})`;
|
|
1290
|
+
}
|
|
1291
|
+
eqFF(a, b) {
|
|
1292
|
+
if (isStatic(a) && isStatic(b)) return Equal.equals(a.s, b.s);
|
|
1293
|
+
return `${this.f(a)} = ${this.f(b)}`;
|
|
1294
|
+
}
|
|
1295
|
+
ne(a, b) {
|
|
1296
|
+
if (isStatic(a) && isStatic(b)) return !Equal.equals(a.s, b.s);
|
|
1297
|
+
return `${this.f(a)} <> ${this.f(b)}`;
|
|
1298
|
+
}
|
|
1299
|
+
/** `NULL` if the operand is unbound, otherwise the test. */
|
|
1300
|
+
guard(o, test) {
|
|
1301
|
+
return caseOf([[this.isNullC(o), "NULL"]], test);
|
|
1302
|
+
}
|
|
1303
|
+
kindTest(o, kind) {
|
|
1304
|
+
return this.guard(o, condSql(this.eqC(o.kind, kind)));
|
|
1305
|
+
}
|
|
1306
|
+
/** Records the class combinations of a comparison that SQL cannot evaluate exactly. */
|
|
1307
|
+
risk(pairs, a, b, handled = MutableHashSet.empty()) {
|
|
1308
|
+
const possible = (o, c) => Option.match(o.classes, {
|
|
1309
|
+
onNone: () => true,
|
|
1310
|
+
onSome: (classes) => classes.includes(c)
|
|
1311
|
+
});
|
|
1312
|
+
pairs.forEach(([x, y]) => {
|
|
1313
|
+
(x === y ? [[x, y]] : [[x, y], [y, x]]).forEach(([p, q]) => {
|
|
1314
|
+
if (!possible(a, p) || !possible(b, q) || MutableHashSet.has(handled, `${p},${q}`)) return;
|
|
1315
|
+
const r = {
|
|
1316
|
+
a: p,
|
|
1317
|
+
aStatic: Option.isSome(a.classes),
|
|
1318
|
+
b: q,
|
|
1319
|
+
bStatic: Option.isSome(b.classes)
|
|
1320
|
+
};
|
|
1321
|
+
if (r.aStatic && r.bStatic) unsupported("Comparison that SQL cannot evaluate exactly");
|
|
1322
|
+
this.risks.push(r);
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Exact comparisons of a float-or-double term with a numeric constant,
|
|
1328
|
+
* following SPARQL's type promotion (integers and decimals are promoted to
|
|
1329
|
+
* float, floats to double). Returns the branches and the class pairs they
|
|
1330
|
+
* handle.
|
|
1331
|
+
*/
|
|
1332
|
+
promoted(a, b, op) {
|
|
1333
|
+
const branches = [];
|
|
1334
|
+
const handled = MutableHashSet.empty();
|
|
1335
|
+
const one = (t, c, flip) => {
|
|
1336
|
+
if (c.tag !== "const" || t.tag === "const") return;
|
|
1337
|
+
const value = staticNumber(c.num);
|
|
1338
|
+
const constClass = staticNumber(c.cls);
|
|
1339
|
+
if (Option.isNone(value) || Option.isNone(constClass)) return;
|
|
1340
|
+
const v = value.value;
|
|
1341
|
+
const cc = constClass.value;
|
|
1342
|
+
const add = (cls, n) => {
|
|
1343
|
+
if (!Number.isFinite(n)) return;
|
|
1344
|
+
const cmp = flip ? `${this.lit(n)} ${op} ${this.f(t.num)}` : `${this.f(t.num)} ${op} ${this.lit(n)}`;
|
|
1345
|
+
branches.push([this.clsIn(t, [cls]), cmp]);
|
|
1346
|
+
MutableHashSet.add(handled, flip ? `${cc},${cls}` : `${cls},${cc}`);
|
|
1347
|
+
};
|
|
1348
|
+
if (cc === Cls.SafeNumber) add(Cls.Float, Math.fround(v));
|
|
1349
|
+
else if (cc === Cls.Double) add(Cls.Float, v);
|
|
1350
|
+
else if (cc === Cls.Float) add(Cls.Double, v);
|
|
1351
|
+
};
|
|
1352
|
+
one(a, b, false);
|
|
1353
|
+
one(b, a, true);
|
|
1354
|
+
return {
|
|
1355
|
+
branches,
|
|
1356
|
+
handled
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* The branches comparing two numbers of the same SQL-comparable kind
|
|
1361
|
+
* (integers, decimals and doubles together; floats with floats) by `num`.
|
|
1362
|
+
*/
|
|
1363
|
+
numericBranches(a, b, num) {
|
|
1364
|
+
return [[and(this.clsIn(a, [1, 2]), this.clsIn(b, [1, 2])), num], [and(this.clsIn(a, [3]), this.clsIn(b, [3])), num]];
|
|
1365
|
+
}
|
|
1366
|
+
/** SPARQL `=` (value equality, with errors as `NULL`). */
|
|
1367
|
+
equals(a, b) {
|
|
1368
|
+
if (a.tag === "null" || b.tag === "null") return "NULL";
|
|
1369
|
+
if (a.tag === "const" && b.tag === "const") {
|
|
1370
|
+
const r = equals(a.term, b.term);
|
|
1371
|
+
return Result.isSuccess(r) ? r.success ? "TRUE" : "FALSE" : "NULL";
|
|
1372
|
+
}
|
|
1373
|
+
const promoted = this.promoted(a, b, "=");
|
|
1374
|
+
this.risk(RISK_EQUAL, a, b, promoted.handled);
|
|
1375
|
+
const ia = operandId(a);
|
|
1376
|
+
const ib = operandId(b);
|
|
1377
|
+
const bothIds = Option.isSome(ia) && Option.isSome(ib);
|
|
1378
|
+
const sameId = Option.isSome(ia) && Option.isSome(ib) ? this.eqFF(ia.value, ib.value) : false;
|
|
1379
|
+
const num = `${this.f(a.num)} = ${this.f(b.num)}`;
|
|
1380
|
+
return caseOf([
|
|
1381
|
+
[or(this.isNullC(a), this.isNullC(b)), "NULL"],
|
|
1382
|
+
[sameId, "TRUE"],
|
|
1383
|
+
...promoted.branches,
|
|
1384
|
+
...this.numericBranches(a, b, num),
|
|
1385
|
+
[and(this.clsIn(a, [6]), this.clsIn(b, [6])), num],
|
|
1386
|
+
[and(this.clsIn(a, [4]), this.clsIn(b, [4])), `${this.f(a.value)} = ${this.f(b.value)}`],
|
|
1387
|
+
[and(this.clsIn(a, [0]), this.clsIn(b, [0])), bothIds ? "FALSE" : condSql(and(this.eqFF(a.kind, b.kind), this.eqFF(a.value, b.value)))],
|
|
1388
|
+
[or(this.clsIn(a, [0, 10]), this.clsIn(b, [0, 10])), "FALSE"],
|
|
1389
|
+
[or(this.clsIn(a, [5]), this.clsIn(b, [5])), "FALSE"],
|
|
1390
|
+
[and(this.clsIn(a, WELL_FORMED_KNOWN), this.clsIn(b, WELL_FORMED_KNOWN), this.ne(a.datatype, b.datatype)), "FALSE"]
|
|
1391
|
+
], "NULL");
|
|
1392
|
+
}
|
|
1393
|
+
/** SPARQL `<`, `>`, `<=`, `>=`. */
|
|
1394
|
+
compare(a, b, op) {
|
|
1395
|
+
if (a.tag === "null" || b.tag === "null") return "NULL";
|
|
1396
|
+
const promoted = this.promoted(a, b, op);
|
|
1397
|
+
this.risk(RISK_ORDER, a, b, promoted.handled);
|
|
1398
|
+
const num = `${this.f(a.num)} ${op} ${this.f(b.num)}`;
|
|
1399
|
+
const str = `${this.dialect.binary(this.f(a.value))} ${op} ${this.dialect.binary(this.f(b.value))}`;
|
|
1400
|
+
return caseOf([
|
|
1401
|
+
[or(this.isNullC(a), this.isNullC(b)), "NULL"],
|
|
1402
|
+
...promoted.branches,
|
|
1403
|
+
...this.numericBranches(a, b, num),
|
|
1404
|
+
[and(this.clsIn(a, [4]), this.clsIn(b, [4])), str],
|
|
1405
|
+
[and(this.clsIn(a, [5]), this.clsIn(b, [5]), this.eqFF(a.lang, b.lang), this.eqFF(a.dir, b.dir)), str],
|
|
1406
|
+
[and(this.clsIn(a, [6]), this.clsIn(b, [6])), num]
|
|
1407
|
+
], "NULL");
|
|
1408
|
+
}
|
|
1409
|
+
/** The effective boolean value (SQL boolean, `NULL` = error). */
|
|
1410
|
+
ebv(operand) {
|
|
1411
|
+
return Match.value(operand).pipe(Match.when({ tag: "bool" }, (o) => o.bool), Match.when({ tag: Match.is("null", "iri") }, () => "NULL"), Match.when({ tag: "const" }, (o) => {
|
|
1412
|
+
const r = effectiveBooleanValue(o.term);
|
|
1413
|
+
return Result.isSuccess(r) ? r.success ? "TRUE" : "FALSE" : "NULL";
|
|
1414
|
+
}), Match.when({ tag: "int" }, (o) => `(${this.f(o.num)} <> 0)`), Match.when({ tag: "str" }, (o) => `(${this.f(o.value)} <> '')`), Match.when({ tag: "term" }, (o) => {
|
|
1415
|
+
const num = `${this.f(o.num)} <> 0`;
|
|
1416
|
+
const value = this.f(o.value);
|
|
1417
|
+
return caseOf([
|
|
1418
|
+
[this.clsIn(o, [
|
|
1419
|
+
6,
|
|
1420
|
+
1,
|
|
1421
|
+
2,
|
|
1422
|
+
3
|
|
1423
|
+
]), num],
|
|
1424
|
+
[this.clsIn(o, [4]), `${value} <> ''`],
|
|
1425
|
+
[this.clsIn(o, [8]), this.dialect.hasNonZeroDigit(value)],
|
|
1426
|
+
[this.clsIn(o, [11]), `${value} <> 'NaN'`],
|
|
1427
|
+
[this.clsIn(o, [12]), "FALSE"]
|
|
1428
|
+
], "NULL");
|
|
1429
|
+
}), Match.exhaustive);
|
|
1430
|
+
}
|
|
1431
|
+
/** `EXISTS` / `NOT EXISTS` as a correlated subquery. */
|
|
1432
|
+
exists(e, env) {
|
|
1433
|
+
const context = {
|
|
1434
|
+
items: [],
|
|
1435
|
+
where: [],
|
|
1436
|
+
cols: env.cols
|
|
1437
|
+
};
|
|
1438
|
+
const body = this.op(e.input, env.graph, context);
|
|
1439
|
+
const where = [...body.where];
|
|
1440
|
+
if (env.graph.kind === "var") {
|
|
1441
|
+
const hidden = env.graph.hidden;
|
|
1442
|
+
const ic = MutableHashMap.get(body.cols, hidden);
|
|
1443
|
+
const oc = MutableHashMap.get(env.cols, hidden);
|
|
1444
|
+
if (Option.isSome(ic)) {
|
|
1445
|
+
if (Option.isNone(oc) || oc.value.nullable) return unsupported("EXISTS in a graph-independent pattern");
|
|
1446
|
+
if (ic.value.sql !== oc.value.sql) where.push(`${ic.value.sql} = ${oc.value.sql}`);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
const sql = `EXISTS (SELECT 1${this.from(body.items)}${this.whereClause(where)})`;
|
|
1450
|
+
return e.negated ? `(NOT ${sql})` : sql;
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
const compileOnce = (op, context, resolve, locals, localsKnown) => {
|
|
1454
|
+
const c = new Compiler(context, resolve, locals, localsKnown);
|
|
1455
|
+
const g = Predicate.isTagged(context.activeGraph, "NamedGraph") ? {
|
|
1456
|
+
kind: "const",
|
|
1457
|
+
id: c.idOf(context.activeGraph.graph)
|
|
1458
|
+
} : { kind: "default" };
|
|
1459
|
+
const block = c.op(op, g, EMPTY);
|
|
1460
|
+
const visible = Arr.fromIterable(block.cols).filter(([n]) => !isHidden(n));
|
|
1461
|
+
const names = visible.map(([n]) => n);
|
|
1462
|
+
const innerSql = c.render(block, names);
|
|
1463
|
+
const select = [];
|
|
1464
|
+
const joins = [];
|
|
1465
|
+
const columns = [];
|
|
1466
|
+
visible.forEach(([n, col], i) => {
|
|
1467
|
+
const name = `r.${c.col(n)}`;
|
|
1468
|
+
columns.push({
|
|
1469
|
+
variable: n,
|
|
1470
|
+
type: col.type
|
|
1471
|
+
});
|
|
1472
|
+
if (col.type === "int") {
|
|
1473
|
+
select.push(name);
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
const t = `d${i}`;
|
|
1477
|
+
select.push(name, `${t}.kind`, `${t}.value`, `${t}.datatype`, `${t}.lang`, `${t}.dir`);
|
|
1478
|
+
joins.push(` LEFT JOIN ${c.T} ${t} ON ${t}.id = ${name}`);
|
|
1479
|
+
});
|
|
1480
|
+
const marked = `SELECT ${Arr.isReadonlyArrayEmpty(select) ? "1 AS one" : select.join(", ")} FROM (${innerSql}) r${joins.join("")}`;
|
|
1481
|
+
const params = [];
|
|
1482
|
+
const numbering = MutableHashMap.empty();
|
|
1483
|
+
return {
|
|
1484
|
+
sql: marked.replace(/\ue000(\d+)\ue000/g, (_, i) => {
|
|
1485
|
+
if (context.dialect.anonymousParameters) {
|
|
1486
|
+
params.push(c.params[Number(i) - 1]);
|
|
1487
|
+
return context.dialect.placeholder(params.length);
|
|
1488
|
+
}
|
|
1489
|
+
const n = Option.getOrElse(MutableHashMap.get(numbering, i), () => {
|
|
1490
|
+
params.push(c.params[Number(i) - 1]);
|
|
1491
|
+
MutableHashMap.set(numbering, i, params.length);
|
|
1492
|
+
return params.length;
|
|
1493
|
+
});
|
|
1494
|
+
return context.dialect.placeholder(n);
|
|
1495
|
+
}),
|
|
1496
|
+
params,
|
|
1497
|
+
columns,
|
|
1498
|
+
locals: new Map(Arr.fromIterable(MutableHashMap.values(locals)).map(({ id, term }) => [id, term])),
|
|
1499
|
+
localClasses: c.localClasses,
|
|
1500
|
+
risks: c.risks
|
|
1501
|
+
};
|
|
1502
|
+
};
|
|
1503
|
+
/**
|
|
1504
|
+
* Translates an algebra tree to SQL. `resolve` gives the dictionary ids of
|
|
1505
|
+
* constant terms (see `constants`); terms it does not know get query-local
|
|
1506
|
+
* ids. Fails with a reason if the tree is not translatable.
|
|
1507
|
+
*
|
|
1508
|
+
* @since 0.1.0
|
|
1509
|
+
* @category compilation
|
|
1510
|
+
*/
|
|
1511
|
+
const compile = (op, context, resolve) => {
|
|
1512
|
+
const resolveId = (term) => Option.fromNullishOr(resolve(term));
|
|
1513
|
+
return Result.try({
|
|
1514
|
+
try: () => {
|
|
1515
|
+
const locals = MutableHashMap.empty();
|
|
1516
|
+
const first = compileOnce(op, context, resolveId, locals, false);
|
|
1517
|
+
if (MutableHashMap.isEmpty(locals)) return first;
|
|
1518
|
+
return compileOnce(op, context, resolveId, locals, true);
|
|
1519
|
+
},
|
|
1520
|
+
catch: (err) => {
|
|
1521
|
+
if (err instanceof Unsupported) return err.reason;
|
|
1522
|
+
throw err;
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
};
|
|
1526
|
+
/**
|
|
1527
|
+
* Whether an algebra tree is translatable to SQL (independent of the data).
|
|
1528
|
+
*
|
|
1529
|
+
* @since 0.1.0
|
|
1530
|
+
* @category compilation
|
|
1531
|
+
*/
|
|
1532
|
+
const supports = (op, context) => Result.isSuccess(compile(op, context, () => void 0));
|
|
1533
|
+
export { supports as a, isComponentIds as c, isRisky as i, rowKey as l, compile as n, decode as o, constants as r, encode as s, Translation_exports as t };
|
|
1534
|
+
|
|
1535
|
+
//# sourceMappingURL=Translation-DC9rLm2y.mjs.map
|