@nicia-ai/typegraph 0.49.0 → 0.51.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/README.md +12 -0
- package/dist/backend/drizzle/indexes.cjs +11 -9
- package/dist/backend/drizzle/indexes.d.cts +1 -1
- package/dist/backend/drizzle/indexes.d.ts +1 -1
- package/dist/backend/drizzle/indexes.js +7 -5
- package/dist/backend/index.cjs +190 -53
- package/dist/backend/index.d.cts +90 -4
- package/dist/backend/index.d.ts +90 -4
- package/dist/backend/index.js +9 -12
- package/dist/backend/postgres/index.cjs +36 -28
- package/dist/backend/postgres/index.d.cts +7 -7
- package/dist/backend/postgres/index.d.ts +7 -7
- package/dist/backend/postgres/index.js +19 -15
- package/dist/backend/postgres/pglite-store.cjs +7 -62
- package/dist/backend/postgres/pglite-store.cjs.map +1 -1
- package/dist/backend/postgres/pglite-store.d.cts +8 -8
- package/dist/backend/postgres/pglite-store.d.ts +8 -8
- package/dist/backend/postgres/pglite-store.js +7 -62
- package/dist/backend/postgres/pglite-store.js.map +1 -1
- package/dist/backend/postgres/pglite.cjs +21 -17
- package/dist/backend/postgres/pglite.d.cts +3 -3
- package/dist/backend/postgres/pglite.d.ts +3 -3
- package/dist/backend/postgres/pglite.js +20 -16
- package/dist/backend/sqlite/index.cjs +33 -25
- package/dist/backend/sqlite/index.d.cts +7 -7
- package/dist/backend/sqlite/index.d.ts +7 -7
- package/dist/backend/sqlite/index.js +17 -13
- package/dist/backend/sqlite/libsql.cjs +24 -20
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +3 -3
- package/dist/backend/sqlite/libsql.d.ts +3 -3
- package/dist/backend/sqlite/libsql.js +19 -15
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local-store.cjs +9 -64
- package/dist/backend/sqlite/local-store.cjs.map +1 -1
- package/dist/backend/sqlite/local-store.d.cts +8 -8
- package/dist/backend/sqlite/local-store.d.ts +8 -8
- package/dist/backend/sqlite/local-store.js +8 -64
- package/dist/backend/sqlite/local-store.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +25 -20
- package/dist/backend/sqlite/local.d.cts +3 -3
- package/dist/backend/sqlite/local.d.ts +3 -3
- package/dist/backend/sqlite/local.js +21 -16
- package/dist/chunk-2CVDZCXH.cjs +1278 -0
- package/dist/chunk-2CVDZCXH.cjs.map +1 -0
- package/dist/{chunk-MYKHJI2J.js → chunk-2DWTBNSH.js} +3 -3
- package/dist/{chunk-MYKHJI2J.js.map → chunk-2DWTBNSH.js.map} +1 -1
- package/dist/{chunk-JB6T4GLL.cjs → chunk-2KCTP3U2.cjs} +870 -528
- package/dist/chunk-2KCTP3U2.cjs.map +1 -0
- package/dist/{chunk-OORXGFL5.cjs → chunk-322TBTOQ.cjs} +48 -48
- package/dist/{chunk-OORXGFL5.cjs.map → chunk-322TBTOQ.cjs.map} +1 -1
- package/dist/{chunk-FA2AFWLP.cjs → chunk-36SX6QXP.cjs} +31 -12
- package/dist/chunk-36SX6QXP.cjs.map +1 -0
- package/dist/{chunk-SDBBMD4N.js → chunk-36VYWVQU.js} +3 -3
- package/dist/{chunk-SDBBMD4N.js.map → chunk-36VYWVQU.js.map} +1 -1
- package/dist/chunk-4DKY6RIU.js +1253 -0
- package/dist/chunk-4DKY6RIU.js.map +1 -0
- package/dist/chunk-4QKOZYMV.js +9 -0
- package/dist/chunk-4QKOZYMV.js.map +1 -0
- package/dist/{chunk-WIC7DRXW.js → chunk-57JM6NW3.js} +9 -19
- package/dist/chunk-57JM6NW3.js.map +1 -0
- package/dist/chunk-5WWEYV4H.cjs +5113 -0
- package/dist/chunk-5WWEYV4H.cjs.map +1 -0
- package/dist/chunk-6KQEICJ6.cjs +12 -0
- package/dist/{chunk-MKJ4KXL5.cjs.map → chunk-6KQEICJ6.cjs.map} +1 -1
- package/dist/{chunk-DZAICA5J.js → chunk-6NKSE5AU.js} +4 -4
- package/dist/{chunk-DZAICA5J.js.map → chunk-6NKSE5AU.js.map} +1 -1
- package/dist/{chunk-KKBDXCLQ.js → chunk-6NLYIMJO.js} +4 -4
- package/dist/{chunk-KKBDXCLQ.js.map → chunk-6NLYIMJO.js.map} +1 -1
- package/dist/{chunk-BFUOME67.cjs → chunk-7B7I7YAW.cjs} +20 -11
- package/dist/chunk-7B7I7YAW.cjs.map +1 -0
- package/dist/{chunk-ZDKTPBGV.js → chunk-7G5IYROL.js} +6 -548
- package/dist/chunk-7G5IYROL.js.map +1 -0
- package/dist/{chunk-3DMMGT6S.js → chunk-7QFRK6PU.js} +4 -8
- package/dist/chunk-7QFRK6PU.js.map +1 -0
- package/dist/chunk-A4C4NJ5U.cjs +12 -0
- package/dist/chunk-A4C4NJ5U.cjs.map +1 -0
- package/dist/{chunk-CHAOFCHV.js → chunk-AH2A74OZ.js} +3 -3
- package/dist/{chunk-CHAOFCHV.js.map → chunk-AH2A74OZ.js.map} +1 -1
- package/dist/{chunk-UGHQV7MP.cjs → chunk-B3MN7EJR.cjs} +228 -162
- package/dist/chunk-B3MN7EJR.cjs.map +1 -0
- package/dist/{chunk-TZEGUG6D.cjs → chunk-BZ5MVITP.cjs} +4 -4
- package/dist/{chunk-TZEGUG6D.cjs.map → chunk-BZ5MVITP.cjs.map} +1 -1
- package/dist/{chunk-YVF2EM7B.js → chunk-CAI6SMP6.js} +3 -3
- package/dist/{chunk-YVF2EM7B.js.map → chunk-CAI6SMP6.js.map} +1 -1
- package/dist/{chunk-JONXFAPO.js → chunk-CBOD7TXH.js} +5 -5
- package/dist/{chunk-JONXFAPO.js.map → chunk-CBOD7TXH.js.map} +1 -1
- package/dist/{chunk-FQPEMEWX.cjs → chunk-CRZ56SZU.cjs} +81 -32
- package/dist/chunk-CRZ56SZU.cjs.map +1 -0
- package/dist/{chunk-DO7SAMEK.cjs → chunk-D3GWARN7.cjs} +47 -47
- package/dist/{chunk-DO7SAMEK.cjs.map → chunk-D3GWARN7.cjs.map} +1 -1
- package/dist/{chunk-QTD6HX4O.js → chunk-D3OUDFU7.js} +5 -5
- package/dist/{chunk-QTD6HX4O.js.map → chunk-D3OUDFU7.js.map} +1 -1
- package/dist/{chunk-2QGYQBS2.cjs → chunk-DWUDZ66O.cjs} +10 -10
- package/dist/{chunk-2QGYQBS2.cjs.map → chunk-DWUDZ66O.cjs.map} +1 -1
- package/dist/chunk-EKG2UXNX.cjs +23 -0
- package/dist/chunk-EKG2UXNX.cjs.map +1 -0
- package/dist/chunk-FMMW3KX7.cjs +148 -0
- package/dist/chunk-FMMW3KX7.cjs.map +1 -0
- package/dist/{chunk-XVWOYKIK.js → chunk-FZHF5UWR.js} +3 -3
- package/dist/{chunk-XVWOYKIK.js.map → chunk-FZHF5UWR.js.map} +1 -1
- package/dist/chunk-H2VWDQWC.cjs +571 -0
- package/dist/chunk-H2VWDQWC.cjs.map +1 -0
- package/dist/chunk-H4FY6OZK.js +13 -0
- package/dist/chunk-H4FY6OZK.js.map +1 -0
- package/dist/{chunk-EDN4Y4ZG.cjs → chunk-H5IJSROF.cjs} +9 -15
- package/dist/chunk-H5IJSROF.cjs.map +1 -0
- package/dist/chunk-HZUB5CON.js +27 -0
- package/dist/chunk-HZUB5CON.js.map +1 -0
- package/dist/{chunk-NACVVDWB.js → chunk-I5IOSA27.js} +103 -105
- package/dist/chunk-I5IOSA27.js.map +1 -0
- package/dist/{chunk-OI2GQ25X.cjs → chunk-I7YAY2VQ.cjs} +7 -7
- package/dist/{chunk-OI2GQ25X.cjs.map → chunk-I7YAY2VQ.cjs.map} +1 -1
- package/dist/chunk-IRCWIA3R.js +20 -0
- package/dist/chunk-IRCWIA3R.js.map +1 -0
- package/dist/chunk-IVQBLXBK.cjs +55 -0
- package/dist/chunk-IVQBLXBK.cjs.map +1 -0
- package/dist/{chunk-7SQSZN2J.js → chunk-IZD4HTCP.js} +5 -5
- package/dist/{chunk-7SQSZN2J.js.map → chunk-IZD4HTCP.js.map} +1 -1
- package/dist/{chunk-3FPR224C.cjs → chunk-JHRUZ73O.cjs} +116 -107
- package/dist/chunk-JHRUZ73O.cjs.map +1 -0
- package/dist/{chunk-EZEEWCFJ.cjs → chunk-JQKMEKKW.cjs} +525 -298
- package/dist/chunk-JQKMEKKW.cjs.map +1 -0
- package/dist/chunk-JVA3KDEA.cjs +691 -0
- package/dist/chunk-JVA3KDEA.cjs.map +1 -0
- package/dist/{chunk-5K2BKEBD.js → chunk-K46SDNQD.js} +10 -4
- package/dist/chunk-K46SDNQD.js.map +1 -0
- package/dist/{chunk-7LZJNLA5.js → chunk-K67P5DLL.js} +108 -42
- package/dist/chunk-K67P5DLL.js.map +1 -0
- package/dist/{chunk-3G5W2U2L.cjs → chunk-KACEYDYV.cjs} +335 -258
- package/dist/chunk-KACEYDYV.cjs.map +1 -0
- package/dist/{chunk-JFRT7S3B.cjs → chunk-L6EVYIID.cjs} +318 -478
- package/dist/chunk-L6EVYIID.cjs.map +1 -0
- package/dist/{chunk-SHFBB23Q.js → chunk-LI4K2KEJ.js} +6 -4
- package/dist/chunk-LI4K2KEJ.js.map +1 -0
- package/dist/chunk-LKZDQ2B4.js +1581 -0
- package/dist/chunk-LKZDQ2B4.js.map +1 -0
- package/dist/{chunk-WODMN3Q2.cjs → chunk-LLFPQOBA.cjs} +27 -27
- package/dist/{chunk-WODMN3Q2.cjs.map → chunk-LLFPQOBA.cjs.map} +1 -1
- package/dist/{chunk-P6YLZTRE.js → chunk-LZMQ3SFK.js} +3 -3
- package/dist/{chunk-P6YLZTRE.js.map → chunk-LZMQ3SFK.js.map} +1 -1
- package/dist/{chunk-HEV35TGT.js → chunk-M3VTS3F6.js} +13 -4
- package/dist/chunk-M3VTS3F6.js.map +1 -0
- package/dist/{chunk-TQHGE7UC.cjs → chunk-M5MSP3BI.cjs} +18 -10
- package/dist/chunk-M5MSP3BI.cjs.map +1 -0
- package/dist/{chunk-D4QLTJSM.js → chunk-NBOS7BY3.js} +63 -23
- package/dist/chunk-NBOS7BY3.js.map +1 -0
- package/dist/chunk-NGQDGL5X.js +140 -0
- package/dist/chunk-NGQDGL5X.js.map +1 -0
- package/dist/{chunk-SIT26LAZ.cjs → chunk-NLX5OWK7.cjs} +33 -5
- package/dist/chunk-NLX5OWK7.cjs.map +1 -0
- package/dist/chunk-NUQ2YFFH.cjs +1637 -0
- package/dist/chunk-NUQ2YFFH.cjs.map +1 -0
- package/dist/{chunk-UMGZDVOA.cjs → chunk-OGL4X4PH.cjs} +206 -208
- package/dist/chunk-OGL4X4PH.cjs.map +1 -0
- package/dist/{chunk-LRQKXRXO.cjs → chunk-OTNTGEXR.cjs} +4 -4
- package/dist/{chunk-LRQKXRXO.cjs.map → chunk-OTNTGEXR.cjs.map} +1 -1
- package/dist/chunk-OTWE63BW.js +53 -0
- package/dist/chunk-OTWE63BW.js.map +1 -0
- package/dist/chunk-PC5NGH5A.js +549 -0
- package/dist/chunk-PC5NGH5A.js.map +1 -0
- package/dist/{chunk-26YKDNUD.cjs → chunk-PS3TUWJM.cjs} +12 -10
- package/dist/chunk-PS3TUWJM.cjs.map +1 -0
- package/dist/{chunk-OMZ37BM2.js → chunk-PVFFH7TL.js} +5 -5
- package/dist/{chunk-OMZ37BM2.js.map → chunk-PVFFH7TL.js.map} +1 -1
- package/dist/chunk-QCD5JKU4.cjs +15 -0
- package/dist/chunk-QCD5JKU4.cjs.map +1 -0
- package/dist/{chunk-UGHG7PGX.js → chunk-QG5VEOKX.js} +30 -4
- package/dist/chunk-QG5VEOKX.js.map +1 -0
- package/dist/{chunk-TUNPBZY3.cjs → chunk-QLLZM5I3.cjs} +4 -4
- package/dist/{chunk-TUNPBZY3.cjs.map → chunk-QLLZM5I3.cjs.map} +1 -1
- package/dist/{chunk-BRRP76WO.js → chunk-RCBG6YMT.js} +781 -375
- package/dist/chunk-RCBG6YMT.js.map +1 -0
- package/dist/{chunk-LTXQOEIC.js → chunk-RI7RJH4G.js} +281 -204
- package/dist/chunk-RI7RJH4G.js.map +1 -0
- package/dist/{chunk-GYEG3ZLZ.cjs → chunk-RJMHU2MG.cjs} +121 -18
- package/dist/chunk-RJMHU2MG.cjs.map +1 -0
- package/dist/{chunk-GLHXM7C4.js → chunk-RVUL2HXY.js} +61 -23
- package/dist/chunk-RVUL2HXY.js.map +1 -0
- package/dist/chunk-RWUWTJQY.cjs +30 -0
- package/dist/chunk-RWUWTJQY.cjs.map +1 -0
- package/dist/{chunk-2O4PCIZ6.cjs → chunk-S5GU4LUN.cjs} +13 -13
- package/dist/{chunk-2O4PCIZ6.cjs.map → chunk-S5GU4LUN.cjs.map} +1 -1
- package/dist/{chunk-JPD2CTC3.js → chunk-SDPWO2Z5.js} +7 -7
- package/dist/{chunk-JPD2CTC3.js.map → chunk-SDPWO2Z5.js.map} +1 -1
- package/dist/{chunk-OVI7IXYX.js → chunk-SLGGT2XD.js} +3 -3
- package/dist/{chunk-OVI7IXYX.js.map → chunk-SLGGT2XD.js.map} +1 -1
- package/dist/{chunk-ROR5ZR6A.cjs → chunk-TIJUA4I6.cjs} +45 -45
- package/dist/{chunk-ROR5ZR6A.cjs.map → chunk-TIJUA4I6.cjs.map} +1 -1
- package/dist/{chunk-AOSSQDVO.cjs → chunk-TM54OBHX.cjs} +13 -13
- package/dist/{chunk-AOSSQDVO.cjs.map → chunk-TM54OBHX.cjs.map} +1 -1
- package/dist/{chunk-KF6K7TGH.js → chunk-TYEYRCXL.js} +766 -433
- package/dist/chunk-TYEYRCXL.js.map +1 -0
- package/dist/{chunk-Z2JCLZFJ.js → chunk-UKOVGCRN.js} +2151 -570
- package/dist/chunk-UKOVGCRN.js.map +1 -0
- package/dist/chunk-UYKDYE5D.cjs +12 -0
- package/dist/{chunk-CICO5GXD.cjs.map → chunk-UYKDYE5D.cjs.map} +1 -1
- package/dist/{chunk-S5TERQVW.js → chunk-VAAC7L57.js} +284 -66
- package/dist/chunk-VAAC7L57.js.map +1 -0
- package/dist/{chunk-7UOLHNWC.cjs → chunk-VKHXYVN7.cjs} +22 -33
- package/dist/chunk-VKHXYVN7.cjs.map +1 -0
- package/dist/{chunk-6NGW27EO.cjs → chunk-VLBTRXA2.cjs} +10 -10
- package/dist/{chunk-6NGW27EO.cjs.map → chunk-VLBTRXA2.cjs.map} +1 -1
- package/dist/{chunk-YIURNGXI.js → chunk-VUQZNUHU.js} +22 -6
- package/dist/chunk-VUQZNUHU.js.map +1 -0
- package/dist/{chunk-YYUHLYM2.cjs → chunk-WDM5WQK4.cjs} +183 -143
- package/dist/chunk-WDM5WQK4.cjs.map +1 -0
- package/dist/{chunk-ZFMCDJGB.js → chunk-WFSYYU4W.js} +70 -220
- package/dist/chunk-WFSYYU4W.js.map +1 -0
- package/dist/{chunk-SR725PWF.cjs → chunk-WRBV2FNH.cjs} +2065 -1659
- package/dist/chunk-WRBV2FNH.cjs.map +1 -0
- package/dist/{chunk-MRDBBHIZ.cjs → chunk-X4GDXBOP.cjs} +2 -2
- package/dist/chunk-X4GDXBOP.cjs.map +1 -0
- package/dist/chunk-XORONCV3.js +202 -0
- package/dist/chunk-XORONCV3.js.map +1 -0
- package/dist/{chunk-D5R42W5D.js → chunk-XZW2CTNO.js} +115 -12
- package/dist/chunk-XZW2CTNO.js.map +1 -0
- package/dist/{chunk-ZLONH2UD.js → chunk-YDEJQWOL.js} +2 -2
- package/dist/chunk-YDEJQWOL.js.map +1 -0
- package/dist/{chunk-2TYSSBU5.js → chunk-YT2IVFAI.js} +30 -21
- package/dist/chunk-YT2IVFAI.js.map +1 -0
- package/dist/chunk-ZGVTNKTX.cjs +217 -0
- package/dist/chunk-ZGVTNKTX.cjs.map +1 -0
- package/dist/core/index.cjs +29 -28
- package/dist/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +9 -8
- package/dist/{ddl-D_oW-EVO.d.ts → ddl-BvcbgzHo.d.ts} +3 -3
- package/dist/{ddl-BL1NZLMY.d.cts → ddl-Ufebz5q5.d.cts} +3 -3
- package/dist/graph-extension/index.cjs +21 -20
- package/dist/graph-extension/index.d.cts +2 -4
- package/dist/graph-extension/index.d.ts +2 -4
- package/dist/graph-extension/index.js +5 -4
- package/dist/graph-merge/index.cjs +324 -307
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +8 -9
- package/dist/graph-merge/index.d.ts +8 -9
- package/dist/graph-merge/index.js +51 -34
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/index.cjs +224 -222
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +38 -36
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +15 -13
- package/dist/indexes/index.d.cts +4 -4
- package/dist/indexes/index.d.ts +4 -4
- package/dist/indexes/index.js +8 -6
- package/dist/{ingestion-import-target-dNeL7iAv.d.ts → ingestion-import-target-CAs1OX-l.d.cts} +1 -1
- package/dist/{ingestion-import-target-XPxZYw89.d.cts → ingestion-import-target-DCQSPfNx.d.ts} +1 -1
- package/dist/interchange/index.cjs +57 -54
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +19 -8
- package/dist/interchange/index.d.ts +19 -8
- package/dist/interchange/index.js +21 -18
- package/dist/interchange/index.js.map +1 -1
- package/dist/local-store-impl-6DDTFM32.cjs +77 -0
- package/dist/local-store-impl-6DDTFM32.cjs.map +1 -0
- package/dist/local-store-impl-OXTOVU2J.js +75 -0
- package/dist/local-store-impl-OXTOVU2J.js.map +1 -0
- package/dist/{manager-CYaff3n3.d.cts → manager-B68OrPR2.d.ts} +29 -2
- package/dist/{manager-D9eRT_ns.d.ts → manager-D_t7oK69.d.cts} +29 -2
- package/dist/pglite-store-impl-6EMZGL7K.js +73 -0
- package/dist/pglite-store-impl-6EMZGL7K.js.map +1 -0
- package/dist/pglite-store-impl-GJG3Y7RP.cjs +75 -0
- package/dist/pglite-store-impl-GJG3Y7RP.cjs.map +1 -0
- package/dist/{postgres-CcL4bAHS.d.ts → postgres-BPLSVyHM.d.ts} +279 -2
- package/dist/{postgres-DMj39MEu.d.cts → postgres-CqvtFC2y.d.cts} +279 -2
- package/dist/profiler/index.d.cts +9 -9
- package/dist/profiler/index.d.ts +9 -9
- package/dist/provenance/index.cjs +59 -44
- package/dist/provenance/index.cjs.map +1 -1
- package/dist/provenance/index.d.cts +7 -7
- package/dist/provenance/index.d.ts +7 -7
- package/dist/provenance/index.js +28 -13
- package/dist/provenance/index.js.map +1 -1
- package/dist/{repair-validity-windows-BFNZvd_H.d.cts → repair-validity-windows-DEzCKAdy.d.cts} +7 -3
- package/dist/{repair-validity-windows-DlUSqwCg.d.ts → repair-validity-windows-GMdaS2AH.d.ts} +7 -3
- package/dist/resolve-D_H8MHtq.d.ts +1805 -0
- package/dist/resolve-WEW8gWws.d.cts +1805 -0
- package/dist/schema/index.cjs +48 -46
- package/dist/schema/index.d.cts +4 -6
- package/dist/schema/index.d.ts +4 -6
- package/dist/schema/index.js +21 -19
- package/dist/{searchable-bpE1bBfc.d.ts → searchable-C_UREI9K.d.ts} +1 -1
- package/dist/{searchable-DHJMh_nj.d.cts → searchable-ClgET_i7.d.cts} +1 -1
- package/dist/{sqlite-YppHrNFb.d.cts → sqlite-D1mXO9Kp.d.cts} +310 -2
- package/dist/{sqlite-D7Oz0SQh.d.ts → sqlite-MZA3oZNB.d.ts} +310 -2
- package/dist/{store-bphCSo7z.d.cts → store-CuFX7fCx.d.cts} +117 -31
- package/dist/{store-DRrFCx5x.d.ts → store-D-ZjXQpW.d.ts} +117 -31
- package/dist/{temporal-CbnLzTmM.d.ts → temporal-CpyEiRY8.d.cts} +1 -1
- package/dist/{temporal-5GqpYCk2.d.cts → temporal-y0Aep9Su.d.ts} +1 -1
- package/dist/{types-BqFZTQmV.d.cts → types-6yf0Vv-_.d.cts} +2016 -94
- package/dist/{types-BqFZTQmV.d.ts → types-6yf0Vv-_.d.ts} +2016 -94
- package/dist/{types-Bx74kaTt.d.ts → types-DzJ4dlzk.d.cts} +1 -1
- package/dist/{types-CXAhpW-c.d.cts → types-_vVSB9k-.d.ts} +1 -1
- package/dist/{where-O-k2wgYm.d.ts → where-DuG2LCLe.d.ts} +1 -1
- package/dist/{where-DI_Fqz-X.d.cts → where-Mhf_yyKX.d.cts} +1 -1
- package/package.json +7 -2
- package/dist/chunk-26YKDNUD.cjs.map +0 -1
- package/dist/chunk-2TYSSBU5.js.map +0 -1
- package/dist/chunk-3DMMGT6S.js.map +0 -1
- package/dist/chunk-3FPR224C.cjs.map +0 -1
- package/dist/chunk-3G5W2U2L.cjs.map +0 -1
- package/dist/chunk-3KOY4FH3.cjs +0 -934
- package/dist/chunk-3KOY4FH3.cjs.map +0 -1
- package/dist/chunk-3QNZ5SAJ.cjs +0 -3502
- package/dist/chunk-3QNZ5SAJ.cjs.map +0 -1
- package/dist/chunk-3U5ABFDW.cjs +0 -259
- package/dist/chunk-3U5ABFDW.cjs.map +0 -1
- package/dist/chunk-5K2BKEBD.js.map +0 -1
- package/dist/chunk-5PRKMB24.cjs +0 -124
- package/dist/chunk-5PRKMB24.cjs.map +0 -1
- package/dist/chunk-6LN7FIVU.js +0 -107
- package/dist/chunk-6LN7FIVU.js.map +0 -1
- package/dist/chunk-6SWPJEYN.js +0 -1126
- package/dist/chunk-6SWPJEYN.js.map +0 -1
- package/dist/chunk-7LZJNLA5.js.map +0 -1
- package/dist/chunk-7UOLHNWC.cjs.map +0 -1
- package/dist/chunk-BFUOME67.cjs.map +0 -1
- package/dist/chunk-BRRP76WO.js.map +0 -1
- package/dist/chunk-CICO5GXD.cjs +0 -12
- package/dist/chunk-D4QLTJSM.js.map +0 -1
- package/dist/chunk-D5R42W5D.js.map +0 -1
- package/dist/chunk-EDN4Y4ZG.cjs.map +0 -1
- package/dist/chunk-EZEEWCFJ.cjs.map +0 -1
- package/dist/chunk-FA2AFWLP.cjs.map +0 -1
- package/dist/chunk-FQPEMEWX.cjs.map +0 -1
- package/dist/chunk-GLHXM7C4.js.map +0 -1
- package/dist/chunk-GYEG3ZLZ.cjs.map +0 -1
- package/dist/chunk-HDL2ARHX.cjs +0 -1156
- package/dist/chunk-HDL2ARHX.cjs.map +0 -1
- package/dist/chunk-HEV35TGT.js.map +0 -1
- package/dist/chunk-I4GAZH5Z.js +0 -913
- package/dist/chunk-I4GAZH5Z.js.map +0 -1
- package/dist/chunk-JB6T4GLL.cjs.map +0 -1
- package/dist/chunk-JBQQ7THH.js +0 -20
- package/dist/chunk-JBQQ7THH.js.map +0 -1
- package/dist/chunk-JFRT7S3B.cjs.map +0 -1
- package/dist/chunk-KF6K7TGH.js.map +0 -1
- package/dist/chunk-L3LQNR34.cjs +0 -1254
- package/dist/chunk-L3LQNR34.cjs.map +0 -1
- package/dist/chunk-LTXQOEIC.js.map +0 -1
- package/dist/chunk-MKJ4KXL5.cjs +0 -12
- package/dist/chunk-MRDBBHIZ.cjs.map +0 -1
- package/dist/chunk-NACVVDWB.js.map +0 -1
- package/dist/chunk-NVY5CJFP.js +0 -244
- package/dist/chunk-NVY5CJFP.js.map +0 -1
- package/dist/chunk-PWLJ77UV.cjs +0 -23
- package/dist/chunk-PWLJ77UV.cjs.map +0 -1
- package/dist/chunk-S5TERQVW.js.map +0 -1
- package/dist/chunk-SHFBB23Q.js.map +0 -1
- package/dist/chunk-SIT26LAZ.cjs.map +0 -1
- package/dist/chunk-SR725PWF.cjs.map +0 -1
- package/dist/chunk-TQHGE7UC.cjs.map +0 -1
- package/dist/chunk-UGHG7PGX.js.map +0 -1
- package/dist/chunk-UGHQV7MP.cjs.map +0 -1
- package/dist/chunk-UMGZDVOA.cjs.map +0 -1
- package/dist/chunk-WIC7DRXW.js.map +0 -1
- package/dist/chunk-YIURNGXI.js.map +0 -1
- package/dist/chunk-YYUHLYM2.cjs.map +0 -1
- package/dist/chunk-Z2JCLZFJ.js.map +0 -1
- package/dist/chunk-ZDKTPBGV.js.map +0 -1
- package/dist/chunk-ZFMCDJGB.js.map +0 -1
- package/dist/chunk-ZLONH2UD.js.map +0 -1
- package/dist/index-COs_z6nV.d.cts +0 -1132
- package/dist/index-D7d1u2gr.d.ts +0 -1132
- package/dist/materialize-indexes-DJ3ykH59.d.ts +0 -266
- package/dist/materialize-indexes-DTtAnvfY.d.cts +0 -266
package/dist/chunk-3QNZ5SAJ.cjs
DELETED
|
@@ -1,3502 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkFA2AFWLP_cjs = require('./chunk-FA2AFWLP.cjs');
|
|
4
|
-
var chunkHDL2ARHX_cjs = require('./chunk-HDL2ARHX.cjs');
|
|
5
|
-
var chunkWODMN3Q2_cjs = require('./chunk-WODMN3Q2.cjs');
|
|
6
|
-
var chunkPWLJ77UV_cjs = require('./chunk-PWLJ77UV.cjs');
|
|
7
|
-
var chunkSIT26LAZ_cjs = require('./chunk-SIT26LAZ.cjs');
|
|
8
|
-
var chunkTQHGE7UC_cjs = require('./chunk-TQHGE7UC.cjs');
|
|
9
|
-
var chunkZY4GXIVN_cjs = require('./chunk-ZY4GXIVN.cjs');
|
|
10
|
-
var chunkL3LQNR34_cjs = require('./chunk-L3LQNR34.cjs');
|
|
11
|
-
var chunkEDN4Y4ZG_cjs = require('./chunk-EDN4Y4ZG.cjs');
|
|
12
|
-
var chunkMRDBBHIZ_cjs = require('./chunk-MRDBBHIZ.cjs');
|
|
13
|
-
var chunkN66HCGCY_cjs = require('./chunk-N66HCGCY.cjs');
|
|
14
|
-
var drizzleOrm = require('drizzle-orm');
|
|
15
|
-
|
|
16
|
-
// src/backend/edge-endpoint-sets.ts
|
|
17
|
-
var FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT = 6;
|
|
18
|
-
var FIND_EDGES_HETEROGENEOUS_FIXED_PARAM_COUNT = 4;
|
|
19
|
-
function assertLimitPerEndpoint(operation, graphId, limitPerEndpoint, kind) {
|
|
20
|
-
if (limitPerEndpoint === void 0 || Number.isInteger(limitPerEndpoint) && limitPerEndpoint > 0) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
24
|
-
`${operation} \`limitPerEndpoint\` must be a positive integer, received ${String(limitPerEndpoint)}.`,
|
|
25
|
-
{
|
|
26
|
-
code: "EDGE_ENDPOINT_SET_INVALID",
|
|
27
|
-
graphId,
|
|
28
|
-
...kind === void 0 ? {} : { kind }
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
suggestion: "Pass a positive integer to cap each endpoint's rows, or omit it for an unbounded read."
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
function resolveEdgeEndpointIds(params) {
|
|
36
|
-
assertLimitPerEndpoint(
|
|
37
|
-
"findEdgesByEndpointSet",
|
|
38
|
-
params.graphId,
|
|
39
|
-
params.limitPerEndpoint,
|
|
40
|
-
params.kind
|
|
41
|
-
);
|
|
42
|
-
return [...new Set(params.endpointIds)];
|
|
43
|
-
}
|
|
44
|
-
function endpointKey(endpoint) {
|
|
45
|
-
return `${endpoint.kind}\0${endpoint.id}`;
|
|
46
|
-
}
|
|
47
|
-
function resolveHeterogeneousEdgeRead(params, maxBindParameters) {
|
|
48
|
-
assertLimitPerEndpoint(
|
|
49
|
-
"findEdgesByHeterogeneousEndpointSet",
|
|
50
|
-
params.graphId,
|
|
51
|
-
params.limitPerEndpoint
|
|
52
|
-
);
|
|
53
|
-
const edgeKinds = [...new Set(params.edgeKinds)];
|
|
54
|
-
const endpoints = [
|
|
55
|
-
...new Map(
|
|
56
|
-
params.endpoints.map((endpoint) => [endpointKey(endpoint), endpoint])
|
|
57
|
-
).values()
|
|
58
|
-
];
|
|
59
|
-
if (edgeKinds.length === 0 || endpoints.length === 0) {
|
|
60
|
-
return { edgeKinds, endpoints, endpointChunkSize: 1 };
|
|
61
|
-
}
|
|
62
|
-
const endpointBindBudget = maxBindParameters - FIND_EDGES_HETEROGENEOUS_FIXED_PARAM_COUNT - edgeKinds.length;
|
|
63
|
-
const endpointChunkSize = Math.floor(endpointBindBudget / 2);
|
|
64
|
-
if (endpointChunkSize >= 1) {
|
|
65
|
-
return { edgeKinds, endpoints, endpointChunkSize };
|
|
66
|
-
}
|
|
67
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
68
|
-
"findEdgesByHeterogeneousEndpointSet cannot fit one endpoint and the selected edge kinds within the backend bind-parameter budget.",
|
|
69
|
-
{
|
|
70
|
-
code: "EDGE_HETEROGENEOUS_READ_BIND_BUDGET_EXCEEDED",
|
|
71
|
-
graphId: params.graphId,
|
|
72
|
-
edgeKindCount: edgeKinds.length,
|
|
73
|
-
maxBindParameters
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
suggestion: "Select fewer edge kinds in one call or use a backend with a larger bind-parameter budget."
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/backend/live-node-candidates.ts
|
|
82
|
-
function buildLiveNodeCandidates(nodesTableName, graphId, nodeKind, now) {
|
|
83
|
-
const nodes = chunkEDN4Y4ZG_cjs.sql.identifier(nodesTableName);
|
|
84
|
-
return chunkEDN4Y4ZG_cjs.sql`
|
|
85
|
-
SELECT "id" AS node_id
|
|
86
|
-
FROM ${nodes}
|
|
87
|
-
WHERE "graph_id" = ${graphId}
|
|
88
|
-
AND "kind" = ${nodeKind}
|
|
89
|
-
AND "deleted_at" IS NULL
|
|
90
|
-
AND ("valid_from" IS NULL OR "valid_from" <= ${now})
|
|
91
|
-
AND ("valid_to" IS NULL OR "valid_to" > ${now})
|
|
92
|
-
`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// src/backend/drizzle/vector-runtime.ts
|
|
96
|
-
var VECTOR_SLOT_PLACEHOLDER_DIMENSIONS = 1;
|
|
97
|
-
var EMBEDDING_UPSERT_PARAM_COUNT = 5;
|
|
98
|
-
function vectorSlotFromParams(params) {
|
|
99
|
-
return {
|
|
100
|
-
graphId: params.graphId,
|
|
101
|
-
nodeKind: params.nodeKind,
|
|
102
|
-
fieldPath: params.fieldPath,
|
|
103
|
-
dimensions: params.dimensions,
|
|
104
|
-
metric: params.metric,
|
|
105
|
-
indexType: params.indexType
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function vectorSlotFromCreateIndexParams(params) {
|
|
109
|
-
return {
|
|
110
|
-
...vectorSlotFromParams(params),
|
|
111
|
-
...params.indexParams === void 0 ? {} : { indexParams: params.indexParams }
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function vectorSlotFromDropIndexParams(params) {
|
|
115
|
-
return {
|
|
116
|
-
graphId: params.graphId,
|
|
117
|
-
nodeKind: params.nodeKind,
|
|
118
|
-
fieldPath: params.fieldPath,
|
|
119
|
-
dimensions: VECTOR_SLOT_PLACEHOLDER_DIMENSIONS,
|
|
120
|
-
metric: "cosine",
|
|
121
|
-
indexType: "hnsw"
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function mapVectorWriteError(error, params) {
|
|
125
|
-
const mismatch = chunkSIT26LAZ_cjs.parseDimensionMismatch(error);
|
|
126
|
-
if (mismatch === void 0) return error;
|
|
127
|
-
const attempted = mismatch.actual ?? "a different number of";
|
|
128
|
-
return new chunkMRDBBHIZ_cjs.EmbeddingDimensionChangedError(
|
|
129
|
-
`Embedding "${params.nodeKind}.${params.fieldPath}" was written with ${attempted} dimensions, but its per-field storage expects ${mismatch.expected}. The field's embedding dimension changed; existing vectors must be recreated and re-embedded.`,
|
|
130
|
-
{
|
|
131
|
-
kind: params.nodeKind,
|
|
132
|
-
fieldPath: params.fieldPath,
|
|
133
|
-
storedDimensions: mismatch.expected,
|
|
134
|
-
...mismatch.actual === void 0 ? {} : { declaredDimensions: mismatch.actual }
|
|
135
|
-
},
|
|
136
|
-
{ cause: error }
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
var SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = {
|
|
140
|
-
decode: (value) => typeof value === "string" ? value : void 0,
|
|
141
|
-
encode: (value) => value
|
|
142
|
-
};
|
|
143
|
-
var POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS = {
|
|
144
|
-
decode: chunkFA2AFWLP_cjs.formatPostgresTimestamp,
|
|
145
|
-
encode: (value) => new Date(value)
|
|
146
|
-
};
|
|
147
|
-
function mapContributionMaterializationRow(row, decode) {
|
|
148
|
-
const lastAttemptedAt = decode(row.lastAttemptedAt);
|
|
149
|
-
if (lastAttemptedAt === void 0) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
`contribution materialization row missing required last_attempted_at: ${row.graphId}/${row.logicalName}`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
graphId: row.graphId,
|
|
156
|
-
logicalName: row.logicalName,
|
|
157
|
-
owner: row.owner,
|
|
158
|
-
tableName: row.tableName,
|
|
159
|
-
signature: row.signature,
|
|
160
|
-
materializedAt: decode(row.materializedAt),
|
|
161
|
-
lastAttemptedAt,
|
|
162
|
-
lastError: row.lastError ?? void 0
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function buildContributionInsertValues(params, encode) {
|
|
166
|
-
return {
|
|
167
|
-
graphId: params.graphId,
|
|
168
|
-
logicalName: params.logicalName,
|
|
169
|
-
owner: params.owner,
|
|
170
|
-
tableName: params.tableName,
|
|
171
|
-
signature: params.signature,
|
|
172
|
-
materializedAt: params.materializedAt === void 0 ? void 0 : encode(params.materializedAt),
|
|
173
|
-
lastAttemptedAt: encode(params.attemptedAt),
|
|
174
|
-
lastError: params.error
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
function buildContributionOnConflictSet(materializedAtColumn, paramsMaterializedAt) {
|
|
178
|
-
const materializedAtSet = paramsMaterializedAt === void 0 ? drizzleOrm.sql`COALESCE(excluded.${drizzleOrm.sql.identifier("materialized_at")}, ${materializedAtColumn})` : drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("materialized_at")}`;
|
|
179
|
-
return {
|
|
180
|
-
signature: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("signature")}`,
|
|
181
|
-
materializedAt: materializedAtSet,
|
|
182
|
-
lastAttemptedAt: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_attempted_at")}`,
|
|
183
|
-
lastError: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_error")}`
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function contributionSignatureInput(dialect, identity, createDdl) {
|
|
187
|
-
const hashable = {
|
|
188
|
-
dialect,
|
|
189
|
-
owner: identity.owner,
|
|
190
|
-
logicalName: identity.logicalName,
|
|
191
|
-
tableName: identity.tableName,
|
|
192
|
-
createDdl
|
|
193
|
-
};
|
|
194
|
-
return JSON.stringify(hashable, chunkPWLJ77UV_cjs.sortedReplacer);
|
|
195
|
-
}
|
|
196
|
-
function evaluateContributionState(row, signature) {
|
|
197
|
-
if (row === void 0) return "missing";
|
|
198
|
-
if (row.lastError !== void 0) return "failed";
|
|
199
|
-
if (row.signature !== signature) return "stale";
|
|
200
|
-
if (row.materializedAt === void 0) return "missing";
|
|
201
|
-
return "initialized";
|
|
202
|
-
}
|
|
203
|
-
function diagnoseContribution(row, signature, tableExists) {
|
|
204
|
-
if (!tableExists) {
|
|
205
|
-
if (row === void 0) return void 0;
|
|
206
|
-
if (row.materializedAt !== void 0) return "orphaned-marker";
|
|
207
|
-
return row.lastError === void 0 ? void 0 : "failed-materialization";
|
|
208
|
-
}
|
|
209
|
-
if (row?.materializedAt !== void 0 && row.signature !== signature) {
|
|
210
|
-
return "stale";
|
|
211
|
-
}
|
|
212
|
-
const state = evaluateContributionState(row, signature);
|
|
213
|
-
switch (state) {
|
|
214
|
-
case "initialized": {
|
|
215
|
-
return void 0;
|
|
216
|
-
}
|
|
217
|
-
case "stale": {
|
|
218
|
-
return "stale";
|
|
219
|
-
}
|
|
220
|
-
case "missing":
|
|
221
|
-
case "failed": {
|
|
222
|
-
return "missing-marker";
|
|
223
|
-
}
|
|
224
|
-
default: {
|
|
225
|
-
return state;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
var PROBE_PROJECTION_ORDER = [
|
|
230
|
-
"fulltext",
|
|
231
|
-
"vector"
|
|
232
|
-
];
|
|
233
|
-
var PROBE_DETAIL_PHRASE = {
|
|
234
|
-
"orphaned-marker": "storage is missing",
|
|
235
|
-
"missing-marker": "storage is not attested by a durable marker",
|
|
236
|
-
"failed-materialization": "provisioning failed and produced no storage",
|
|
237
|
-
stale: "storage exists at a different shape than the current declaration"
|
|
238
|
-
};
|
|
239
|
-
function describeProbeDiagnostic(diagnostic) {
|
|
240
|
-
const subject = diagnostic.kind === void 0 || diagnostic.fieldPath === void 0 ? `table "${diagnostic.physicalName}"` : `${diagnostic.kind}.${diagnostic.fieldPath}`;
|
|
241
|
-
return `${subject}: ${PROBE_DETAIL_PHRASE[diagnostic.state]} (${diagnostic.state})`;
|
|
242
|
-
}
|
|
243
|
-
function identityOf(graphId, contribution) {
|
|
244
|
-
return {
|
|
245
|
-
graphId,
|
|
246
|
-
logicalName: contribution.logicalName,
|
|
247
|
-
owner: contribution.owner,
|
|
248
|
-
tableName: contribution.tableName
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function missingTableErrorNames(error, tableName) {
|
|
252
|
-
const quotedTableName2 = `"${tableName.replaceAll('"', '""')}"`;
|
|
253
|
-
for (const link of chunkSIT26LAZ_cjs.errorChain(error)) {
|
|
254
|
-
const message = errorMessage(link);
|
|
255
|
-
if (typeof message !== "string") continue;
|
|
256
|
-
const sqliteMatch = /\bno such table:\s*([^\s;:]+)/i.exec(message);
|
|
257
|
-
const sqliteName = unquoteSqliteIdentifier(sqliteMatch?.[1]);
|
|
258
|
-
if (sqliteName === tableName) return true;
|
|
259
|
-
const namesPostgresTable = message.includes(`relation ${quotedTableName2} does not exist`) || message.includes(`table ${quotedTableName2} does not exist`);
|
|
260
|
-
if (namesPostgresTable) return true;
|
|
261
|
-
}
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
function errorMessage(error) {
|
|
265
|
-
if (typeof error === "string") return error;
|
|
266
|
-
if (error instanceof Error) return error.message;
|
|
267
|
-
if (typeof error !== "object" || error === null || !("message" in error)) {
|
|
268
|
-
return void 0;
|
|
269
|
-
}
|
|
270
|
-
return typeof error.message === "string" ? error.message : void 0;
|
|
271
|
-
}
|
|
272
|
-
function unquoteSqliteIdentifier(identifier) {
|
|
273
|
-
if (identifier === void 0) return void 0;
|
|
274
|
-
const first = identifier.at(0);
|
|
275
|
-
const last = identifier.at(-1);
|
|
276
|
-
const isQuoted = first === '"' && last === '"' || first === "'" && last === "'" || first === "`" && last === "`" || first === "[" && last === "]";
|
|
277
|
-
return isQuoted ? identifier.slice(1, -1) : identifier;
|
|
278
|
-
}
|
|
279
|
-
async function executeGatedFulltext(graphId, assert, refuseUnavailable, execute) {
|
|
280
|
-
await assert(graphId);
|
|
281
|
-
try {
|
|
282
|
-
return await execute();
|
|
283
|
-
} catch (error) {
|
|
284
|
-
return refuseUnavailable(graphId, error);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
function gateFulltextMethods(source, assert, refuseUnavailable) {
|
|
288
|
-
const gated = {};
|
|
289
|
-
if (source.upsertFulltext) {
|
|
290
|
-
const raw = source.upsertFulltext;
|
|
291
|
-
gated.upsertFulltext = async (params) => {
|
|
292
|
-
await executeGatedFulltext(
|
|
293
|
-
params.graphId,
|
|
294
|
-
assert,
|
|
295
|
-
refuseUnavailable,
|
|
296
|
-
() => raw(params)
|
|
297
|
-
);
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
if (source.deleteFulltext) {
|
|
301
|
-
const raw = source.deleteFulltext;
|
|
302
|
-
gated.deleteFulltext = async (params) => {
|
|
303
|
-
await executeGatedFulltext(
|
|
304
|
-
params.graphId,
|
|
305
|
-
assert,
|
|
306
|
-
refuseUnavailable,
|
|
307
|
-
() => raw(params)
|
|
308
|
-
);
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (source.upsertFulltextBatch) {
|
|
312
|
-
const raw = source.upsertFulltextBatch;
|
|
313
|
-
gated.upsertFulltextBatch = async (params) => {
|
|
314
|
-
if (params.rows.length === 0) return;
|
|
315
|
-
await executeGatedFulltext(
|
|
316
|
-
params.graphId,
|
|
317
|
-
assert,
|
|
318
|
-
refuseUnavailable,
|
|
319
|
-
() => raw(params)
|
|
320
|
-
);
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
if (source.deleteFulltextBatch) {
|
|
324
|
-
const raw = source.deleteFulltextBatch;
|
|
325
|
-
gated.deleteFulltextBatch = async (params) => {
|
|
326
|
-
if (params.nodeIds.length === 0) return;
|
|
327
|
-
await executeGatedFulltext(
|
|
328
|
-
params.graphId,
|
|
329
|
-
assert,
|
|
330
|
-
refuseUnavailable,
|
|
331
|
-
() => raw(params)
|
|
332
|
-
);
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
if (source.fulltextSearch) {
|
|
336
|
-
const raw = source.fulltextSearch;
|
|
337
|
-
gated.fulltextSearch = async (params) => {
|
|
338
|
-
return executeGatedFulltext(
|
|
339
|
-
params.graphId,
|
|
340
|
-
assert,
|
|
341
|
-
refuseUnavailable,
|
|
342
|
-
() => raw(params)
|
|
343
|
-
);
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
const rawHardDelete = source.hardDeleteNode;
|
|
347
|
-
gated.hardDeleteNode = async (params) => {
|
|
348
|
-
await executeGatedFulltext(
|
|
349
|
-
params.graphId,
|
|
350
|
-
assert,
|
|
351
|
-
refuseUnavailable,
|
|
352
|
-
() => rawHardDelete(params)
|
|
353
|
-
);
|
|
354
|
-
};
|
|
355
|
-
return gated;
|
|
356
|
-
}
|
|
357
|
-
function gateFulltext(tx, assert, refuseUnavailable) {
|
|
358
|
-
return chunkSIT26LAZ_cjs.deriveBackend(
|
|
359
|
-
tx,
|
|
360
|
-
gateFulltextMethods(tx, assert, refuseUnavailable)
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
function contributionRebuildSupported(fulltextStrategy, fulltextTableName, transactional) {
|
|
364
|
-
return transactional && chunkHDL2ARHX_cjs.runtimeStrategyContributions(fulltextStrategy, fulltextTableName).every(
|
|
365
|
-
(contribution) => contribution.dropDdl !== void 0
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
var CONTRIBUTION_DDL_LOCK_KEY = "typegraph:contribution-ddl";
|
|
369
|
-
var FOREIGN_GRAPH_REPORT_LIMIT = 5;
|
|
370
|
-
var CONTRIBUTION_KEY_SEPARATOR = String.fromCodePoint(0);
|
|
371
|
-
function contributionKey(graphId, contribution) {
|
|
372
|
-
return [
|
|
373
|
-
graphId,
|
|
374
|
-
contribution.owner,
|
|
375
|
-
contribution.logicalName,
|
|
376
|
-
contribution.tableName
|
|
377
|
-
].join(CONTRIBUTION_KEY_SEPARATOR);
|
|
378
|
-
}
|
|
379
|
-
function createContributionMaterializer(deps) {
|
|
380
|
-
const { dialect, fulltextStrategy, fulltextTableName } = deps;
|
|
381
|
-
const initializedSignatures = /* @__PURE__ */ new Map();
|
|
382
|
-
const uncacheableKeys = /* @__PURE__ */ new Set();
|
|
383
|
-
const computedSignatures = /* @__PURE__ */ new Map();
|
|
384
|
-
async function resolveContributionSignature(key, contribution) {
|
|
385
|
-
const cached = computedSignatures.get(key);
|
|
386
|
-
const cachedCreateDdl = cached?.createDdl;
|
|
387
|
-
const cachedSignature = cached?.signature;
|
|
388
|
-
if (cachedCreateDdl?.length === contribution.createDdl.length && cachedSignature !== void 0 && contribution.createDdl.every(
|
|
389
|
-
(statement, index) => cachedCreateDdl[index] === statement
|
|
390
|
-
)) {
|
|
391
|
-
return cachedSignature;
|
|
392
|
-
}
|
|
393
|
-
const input = contributionSignatureInput(
|
|
394
|
-
dialect,
|
|
395
|
-
contribution,
|
|
396
|
-
contribution.createDdl
|
|
397
|
-
);
|
|
398
|
-
const entry = {
|
|
399
|
-
createDdl: [...contribution.createDdl],
|
|
400
|
-
signature: chunkZY4GXIVN_cjs.sha256Hex(input, 16)
|
|
401
|
-
};
|
|
402
|
-
computedSignatures.set(key, entry);
|
|
403
|
-
try {
|
|
404
|
-
return await entry.signature;
|
|
405
|
-
} catch (error) {
|
|
406
|
-
if (computedSignatures.get(key) === entry) {
|
|
407
|
-
computedSignatures.delete(key);
|
|
408
|
-
}
|
|
409
|
-
throw error;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
function runtimeContributions() {
|
|
413
|
-
return chunkHDL2ARHX_cjs.runtimeStrategyContributions(fulltextStrategy, fulltextTableName);
|
|
414
|
-
}
|
|
415
|
-
function cacheInitializedSignature(key, signature) {
|
|
416
|
-
if (!uncacheableKeys.has(key)) {
|
|
417
|
-
initializedSignatures.set(key, signature);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
async function materializeOne(graphId, contribution, signature, existing, options) {
|
|
421
|
-
const force = options?.force === true;
|
|
422
|
-
const identity = identityOf(graphId, contribution);
|
|
423
|
-
if (!force && evaluateContributionState(existing, signature) === "initialized") {
|
|
424
|
-
return "materialized";
|
|
425
|
-
}
|
|
426
|
-
const priorSuccess = existing?.materializedAt !== void 0;
|
|
427
|
-
if (!force && priorSuccess && existing.signature !== signature) {
|
|
428
|
-
if (options?.onDrift === "skip") {
|
|
429
|
-
console.warn(
|
|
430
|
-
`[typegraph] contribution "${contribution.logicalName}" (table "${contribution.tableName}") is provisioned at a different shape than the current declaration \u2014 left untouched. Writes to it will fail until store.reembedVectorField(kind, fieldPath) recreates the storage at the new shape.`
|
|
431
|
-
);
|
|
432
|
-
return "drift-skipped";
|
|
433
|
-
}
|
|
434
|
-
const error = new Error(
|
|
435
|
-
`Contribution "${contribution.logicalName}" (owner "${contribution.owner}", table "${contribution.tableName}") was already materialized with a different signature. The recorded physical shape is stale relative to the current strategy/DDL \u2014 migrate or drop the table and retry, or restore the original strategy.`
|
|
436
|
-
);
|
|
437
|
-
await deps.recordMarker({
|
|
438
|
-
...identity,
|
|
439
|
-
signature: existing.signature,
|
|
440
|
-
attemptedAt: chunkFA2AFWLP_cjs.nowIso(),
|
|
441
|
-
materializedAt: void 0,
|
|
442
|
-
error: error.message
|
|
443
|
-
});
|
|
444
|
-
throw error;
|
|
445
|
-
}
|
|
446
|
-
const attemptedAt = chunkFA2AFWLP_cjs.nowIso();
|
|
447
|
-
try {
|
|
448
|
-
for (const statement of contribution.createDdl) {
|
|
449
|
-
await deps.execDdl(statement);
|
|
450
|
-
}
|
|
451
|
-
} catch (error) {
|
|
452
|
-
await deps.recordMarker({
|
|
453
|
-
...identity,
|
|
454
|
-
signature,
|
|
455
|
-
attemptedAt,
|
|
456
|
-
materializedAt: void 0,
|
|
457
|
-
error: error instanceof Error ? error.message : String(error)
|
|
458
|
-
});
|
|
459
|
-
throw error;
|
|
460
|
-
}
|
|
461
|
-
await deps.recordMarker({
|
|
462
|
-
...identity,
|
|
463
|
-
signature,
|
|
464
|
-
attemptedAt,
|
|
465
|
-
materializedAt: attemptedAt,
|
|
466
|
-
error: void 0
|
|
467
|
-
});
|
|
468
|
-
return "materialized";
|
|
469
|
-
}
|
|
470
|
-
function indexMarkerRows(graphId, rows) {
|
|
471
|
-
return new Map(
|
|
472
|
-
rows.map((row) => [contributionKey(graphId, row), row])
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
async function readMarkerRows(graphId) {
|
|
476
|
-
try {
|
|
477
|
-
return {
|
|
478
|
-
kind: "rows",
|
|
479
|
-
rows: indexMarkerRows(graphId, await deps.getMarkers(graphId))
|
|
480
|
-
};
|
|
481
|
-
} catch (error) {
|
|
482
|
-
if (!chunkSIT26LAZ_cjs.isMissingTableError(error)) throw error;
|
|
483
|
-
return { kind: "missing-table", error };
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
async function ensureContributions(graphId, contributions, options) {
|
|
487
|
-
const force = options?.force === true;
|
|
488
|
-
const bypassCache = options?.bypassCache === true;
|
|
489
|
-
const entries = await Promise.all(
|
|
490
|
-
contributions.map(async (contribution) => {
|
|
491
|
-
const key = contributionKey(graphId, contribution);
|
|
492
|
-
return {
|
|
493
|
-
contribution,
|
|
494
|
-
key,
|
|
495
|
-
signature: await resolveContributionSignature(key, contribution)
|
|
496
|
-
};
|
|
497
|
-
})
|
|
498
|
-
);
|
|
499
|
-
if (bypassCache) {
|
|
500
|
-
for (const entry of entries) {
|
|
501
|
-
uncacheableKeys.add(entry.key);
|
|
502
|
-
initializedSignatures.delete(entry.key);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const pending = force || bypassCache ? entries : entries.filter(
|
|
506
|
-
(entry) => uncacheableKeys.has(entry.key) || initializedSignatures.get(entry.key) !== entry.signature
|
|
507
|
-
);
|
|
508
|
-
if (pending.length === 0) return;
|
|
509
|
-
const initialRead = force ? void 0 : await readMarkerRows(graphId);
|
|
510
|
-
if (!force && initialRead?.kind === "rows" && pending.every(
|
|
511
|
-
(entry) => evaluateContributionState(
|
|
512
|
-
initialRead.rows.get(entry.key),
|
|
513
|
-
entry.signature
|
|
514
|
-
) === "initialized"
|
|
515
|
-
)) {
|
|
516
|
-
for (const entry of pending) {
|
|
517
|
-
cacheInitializedSignature(entry.key, entry.signature);
|
|
518
|
-
}
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
await deps.ensureMarkerTable();
|
|
522
|
-
const existingRows = indexMarkerRows(
|
|
523
|
-
graphId,
|
|
524
|
-
await deps.getMarkers(graphId)
|
|
525
|
-
);
|
|
526
|
-
for (const entry of pending) {
|
|
527
|
-
const outcome = await materializeOne(
|
|
528
|
-
graphId,
|
|
529
|
-
entry.contribution,
|
|
530
|
-
entry.signature,
|
|
531
|
-
existingRows.get(entry.key),
|
|
532
|
-
{
|
|
533
|
-
force,
|
|
534
|
-
...options?.onDrift === void 0 ? {} : { onDrift: options.onDrift }
|
|
535
|
-
}
|
|
536
|
-
);
|
|
537
|
-
if (outcome === "materialized") {
|
|
538
|
-
cacheInitializedSignature(entry.key, entry.signature);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
async function assertContributions(graphId, contributions) {
|
|
543
|
-
const entries = await Promise.all(
|
|
544
|
-
contributions.map(async (contribution) => {
|
|
545
|
-
const key = contributionKey(graphId, contribution);
|
|
546
|
-
return {
|
|
547
|
-
contribution,
|
|
548
|
-
key,
|
|
549
|
-
signature: await resolveContributionSignature(key, contribution)
|
|
550
|
-
};
|
|
551
|
-
})
|
|
552
|
-
);
|
|
553
|
-
const pending = entries.filter(
|
|
554
|
-
(entry) => uncacheableKeys.has(entry.key) || initializedSignatures.get(entry.key) !== entry.signature
|
|
555
|
-
);
|
|
556
|
-
if (pending.length === 0) return;
|
|
557
|
-
const read = await readMarkerRows(graphId);
|
|
558
|
-
if (read.kind === "missing-table") {
|
|
559
|
-
const first = pending[0];
|
|
560
|
-
if (first === void 0) return;
|
|
561
|
-
throw new chunkMRDBBHIZ_cjs.StoreNotInitializedError(graphId, "missing", {
|
|
562
|
-
cause: read.error,
|
|
563
|
-
details: { logicalName: first.contribution.logicalName }
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
for (const entry of pending) {
|
|
567
|
-
const { contribution, key, signature } = entry;
|
|
568
|
-
const state = evaluateContributionState(read.rows.get(key), signature);
|
|
569
|
-
if (state !== "initialized") {
|
|
570
|
-
throw new chunkMRDBBHIZ_cjs.StoreNotInitializedError(graphId, state, {
|
|
571
|
-
details: { logicalName: contribution.logicalName }
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
cacheInitializedSignature(key, signature);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
async function ensureRuntimeContributions(graphId) {
|
|
578
|
-
await ensureContributions(graphId, runtimeContributions());
|
|
579
|
-
}
|
|
580
|
-
async function assertInitialized(graphId) {
|
|
581
|
-
await assertContributions(graphId, runtimeContributions());
|
|
582
|
-
}
|
|
583
|
-
async function refuseUnavailableFulltext(graphId, error) {
|
|
584
|
-
await Promise.resolve();
|
|
585
|
-
if (!chunkSIT26LAZ_cjs.isMissingTableError(error)) throw error;
|
|
586
|
-
const missingContribution = runtimeContributions().find(
|
|
587
|
-
(contribution) => contribution.logicalName === "fulltext" && missingTableErrorNames(error, contribution.tableName)
|
|
588
|
-
);
|
|
589
|
-
if (missingContribution !== void 0) {
|
|
590
|
-
throw new chunkMRDBBHIZ_cjs.ContributionUnavailableError(
|
|
591
|
-
graphId,
|
|
592
|
-
missingContribution.tableName,
|
|
593
|
-
{ cause: error }
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
throw error;
|
|
597
|
-
}
|
|
598
|
-
async function ensureVectorSlot(slot, options) {
|
|
599
|
-
await ensureVectorSlots([slot], options);
|
|
600
|
-
}
|
|
601
|
-
async function assertVectorSlot(slot) {
|
|
602
|
-
await assertVectorSlots([slot]);
|
|
603
|
-
}
|
|
604
|
-
function groupVectorContributions(slots) {
|
|
605
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
606
|
-
if (deps.vectorStrategy === void 0) return grouped;
|
|
607
|
-
for (const slot of slots) {
|
|
608
|
-
grouped.set(slot.graphId, [
|
|
609
|
-
...grouped.get(slot.graphId) ?? [],
|
|
610
|
-
...deps.vectorStrategy.ownedTables(slot)
|
|
611
|
-
]);
|
|
612
|
-
}
|
|
613
|
-
return grouped;
|
|
614
|
-
}
|
|
615
|
-
async function ensureVectorSlots(slots, options) {
|
|
616
|
-
for (const [graphId, contributions] of groupVectorContributions(slots)) {
|
|
617
|
-
await ensureContributions(graphId, contributions, options);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
async function assertVectorSlots(slots) {
|
|
621
|
-
for (const [graphId, contributions] of groupVectorContributions(slots)) {
|
|
622
|
-
await assertContributions(graphId, contributions);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
function verificationTargetsByGraph(graphId, vectorSlots) {
|
|
626
|
-
const targets = /* @__PURE__ */ new Map();
|
|
627
|
-
function addTarget(id, target) {
|
|
628
|
-
const existing = targets.get(id);
|
|
629
|
-
if (existing === void 0) targets.set(id, [target]);
|
|
630
|
-
else existing.push(target);
|
|
631
|
-
}
|
|
632
|
-
for (const contribution of runtimeContributions()) {
|
|
633
|
-
addTarget(graphId, { contribution, projection: "fulltext" });
|
|
634
|
-
}
|
|
635
|
-
const { vectorStrategy } = deps;
|
|
636
|
-
if (vectorStrategy !== void 0) {
|
|
637
|
-
for (const slot of vectorSlots) {
|
|
638
|
-
for (const contribution of vectorStrategy.ownedTables(slot)) {
|
|
639
|
-
addTarget(slot.graphId, {
|
|
640
|
-
contribution,
|
|
641
|
-
projection: "vector",
|
|
642
|
-
kind: slot.nodeKind,
|
|
643
|
-
fieldPath: slot.fieldPath
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
return targets;
|
|
649
|
-
}
|
|
650
|
-
async function diagnoseTargets(targetsByGraph) {
|
|
651
|
-
const probes = /* @__PURE__ */ new Map();
|
|
652
|
-
function tableExists(tableName) {
|
|
653
|
-
const pending = probes.get(tableName);
|
|
654
|
-
if (pending !== void 0) return pending;
|
|
655
|
-
const probe = deps.tableExists(tableName);
|
|
656
|
-
probes.set(tableName, probe);
|
|
657
|
-
return probe;
|
|
658
|
-
}
|
|
659
|
-
const diagnosed = [];
|
|
660
|
-
for (const [id, targets] of targetsByGraph) {
|
|
661
|
-
const read = await readMarkerRows(id);
|
|
662
|
-
const rows = read.kind === "rows" ? read.rows : /* @__PURE__ */ new Map();
|
|
663
|
-
for (const { contribution, projection, kind, fieldPath } of targets) {
|
|
664
|
-
const key = contributionKey(id, contribution);
|
|
665
|
-
const row = rows.get(key);
|
|
666
|
-
const state = diagnoseContribution(
|
|
667
|
-
row,
|
|
668
|
-
await resolveContributionSignature(key, contribution),
|
|
669
|
-
await tableExists(contribution.tableName)
|
|
670
|
-
);
|
|
671
|
-
if (state === void 0) continue;
|
|
672
|
-
diagnosed.push({
|
|
673
|
-
graphId: id,
|
|
674
|
-
contribution,
|
|
675
|
-
projection,
|
|
676
|
-
diagnostic: {
|
|
677
|
-
owner: contribution.owner,
|
|
678
|
-
logicalName: contribution.logicalName,
|
|
679
|
-
physicalName: contribution.tableName,
|
|
680
|
-
...kind === void 0 ? {} : { kind },
|
|
681
|
-
...fieldPath === void 0 ? {} : { fieldPath },
|
|
682
|
-
state,
|
|
683
|
-
// The recorded reason, carried through verbatim. `state` folds
|
|
684
|
-
// several marker verdicts together because they share a repair;
|
|
685
|
-
// this is what keeps the fold from also discarding the one thing
|
|
686
|
-
// the catalog can never tell the operator.
|
|
687
|
-
...row?.lastError === void 0 ? {} : { lastError: row.lastError }
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
return diagnosed;
|
|
693
|
-
}
|
|
694
|
-
async function diagnoseContributions(graphId, vectorSlots) {
|
|
695
|
-
return diagnoseTargets(verificationTargetsByGraph(graphId, vectorSlots));
|
|
696
|
-
}
|
|
697
|
-
async function verifyContributions(graphId, vectorSlots) {
|
|
698
|
-
const diagnosed = await diagnoseContributions(graphId, vectorSlots);
|
|
699
|
-
return diagnosed.map((entry) => entry.diagnostic);
|
|
700
|
-
}
|
|
701
|
-
async function probeContributions(graphId, vectorSlots) {
|
|
702
|
-
const targetsByGraph = verificationTargetsByGraph(graphId, vectorSlots);
|
|
703
|
-
const declared = /* @__PURE__ */ new Set();
|
|
704
|
-
for (const targets of targetsByGraph.values()) {
|
|
705
|
-
for (const target of targets) declared.add(target.projection);
|
|
706
|
-
}
|
|
707
|
-
const diagnosed = await diagnoseTargets(targetsByGraph);
|
|
708
|
-
const entries = [];
|
|
709
|
-
for (const projection of PROBE_PROJECTION_ORDER) {
|
|
710
|
-
if (!declared.has(projection)) continue;
|
|
711
|
-
const problems = diagnosed.filter(
|
|
712
|
-
(entry) => entry.projection === projection
|
|
713
|
-
);
|
|
714
|
-
if (problems.length === 0) {
|
|
715
|
-
entries.push({ contribution: projection, state: "ready" });
|
|
716
|
-
continue;
|
|
717
|
-
}
|
|
718
|
-
entries.push({
|
|
719
|
-
contribution: projection,
|
|
720
|
-
state: "degraded",
|
|
721
|
-
detail: problems.map((entry) => describeProbeDiagnostic(entry.diagnostic)).join("; ")
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
return entries;
|
|
725
|
-
}
|
|
726
|
-
async function repairContributions(graphId, vectorSlots) {
|
|
727
|
-
const diagnosed = await diagnoseContributions(graphId, vectorSlots);
|
|
728
|
-
const results = [];
|
|
729
|
-
for (const {
|
|
730
|
-
graphId: targetGraphId,
|
|
731
|
-
contribution,
|
|
732
|
-
diagnostic
|
|
733
|
-
} of diagnosed) {
|
|
734
|
-
if (diagnostic.state === "stale" || diagnostic.state === "orphaned-marker") {
|
|
735
|
-
results.push({ diagnostic, status: "requires-rebuild" });
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
try {
|
|
739
|
-
await ensureContributions(targetGraphId, [contribution], {
|
|
740
|
-
bypassCache: true
|
|
741
|
-
});
|
|
742
|
-
results.push({ diagnostic, status: "repaired" });
|
|
743
|
-
} catch (error) {
|
|
744
|
-
results.push({
|
|
745
|
-
diagnostic,
|
|
746
|
-
status: "failed",
|
|
747
|
-
error: error instanceof Error ? error.message : String(error)
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
return {
|
|
752
|
-
results,
|
|
753
|
-
remaining: await verifyContributions(graphId, vectorSlots)
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
async function lockContributionDdl(tx) {
|
|
757
|
-
if (dialect !== "postgres") return;
|
|
758
|
-
await tx.execute(
|
|
759
|
-
chunkEDN4Y4ZG_cjs.asCompiledRowsSql(
|
|
760
|
-
chunkEDN4Y4ZG_cjs.sql`SELECT pg_advisory_xact_lock(hashtext(${CONTRIBUTION_DDL_LOCK_KEY}), 0)`
|
|
761
|
-
)
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
async function lockSharedFulltextTable(tx, tableName) {
|
|
765
|
-
if (dialect !== "postgres") return;
|
|
766
|
-
await tx.executeStatement(
|
|
767
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
768
|
-
chunkEDN4Y4ZG_cjs.sql`LOCK TABLE ${chunkEDN4Y4ZG_cjs.sql.identifier(tableName)} IN ACCESS EXCLUSIVE MODE`
|
|
769
|
-
)
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
async function readForeignGraphIds(tx, tableName, graphId) {
|
|
773
|
-
const rows = await tx.execute(
|
|
774
|
-
chunkEDN4Y4ZG_cjs.asCompiledRowsSql(
|
|
775
|
-
chunkL3LQNR34_cjs.buildForeignFulltextGraphProbe(
|
|
776
|
-
tableName,
|
|
777
|
-
graphId,
|
|
778
|
-
FOREIGN_GRAPH_REPORT_LIMIT
|
|
779
|
-
)
|
|
780
|
-
)
|
|
781
|
-
);
|
|
782
|
-
return rows.map((row) => String(row.graph_id));
|
|
783
|
-
}
|
|
784
|
-
async function rebuildContribution(graphId, scope, repopulate) {
|
|
785
|
-
if (scope === "vector") {
|
|
786
|
-
throw new chunkMRDBBHIZ_cjs.ContributionRebuildUnsupportedError(
|
|
787
|
-
"vector-source-unavailable",
|
|
788
|
-
{ graphId, contribution: scope }
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
const contributions = runtimeContributions();
|
|
792
|
-
const withoutTeardown = contributions.find(
|
|
793
|
-
(contribution) => contribution.dropDdl === void 0
|
|
794
|
-
);
|
|
795
|
-
if (withoutTeardown !== void 0) {
|
|
796
|
-
throw new chunkMRDBBHIZ_cjs.ContributionRebuildUnsupportedError("no-drop-ddl", {
|
|
797
|
-
graphId,
|
|
798
|
-
contribution: scope,
|
|
799
|
-
owner: withoutTeardown.owner,
|
|
800
|
-
logicalName: withoutTeardown.logicalName,
|
|
801
|
-
physicalName: withoutTeardown.tableName
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
const fence = deps.schemaWriteTransaction;
|
|
805
|
-
if (fence === void 0) {
|
|
806
|
-
throw new chunkMRDBBHIZ_cjs.ContributionRebuildUnsupportedError("no-schema-fence", {
|
|
807
|
-
graphId,
|
|
808
|
-
contribution: scope,
|
|
809
|
-
backend: dialect
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
const stamps = await Promise.all(
|
|
813
|
-
contributions.map(async (contribution) => {
|
|
814
|
-
const key = contributionKey(graphId, contribution);
|
|
815
|
-
return {
|
|
816
|
-
contribution,
|
|
817
|
-
key,
|
|
818
|
-
signature: await resolveContributionSignature(key, contribution)
|
|
819
|
-
};
|
|
820
|
-
})
|
|
821
|
-
);
|
|
822
|
-
await deps.ensureMarkerTable();
|
|
823
|
-
const markers = indexMarkerRows(graphId, await deps.getMarkers(graphId));
|
|
824
|
-
const sharedTable = deps.fulltextTableName;
|
|
825
|
-
const sharedTableExisted = await deps.tableExists(sharedTable);
|
|
826
|
-
const rebuilt = await fence(graphId, async (tx) => {
|
|
827
|
-
const record = tx.recordContributionMaterialization;
|
|
828
|
-
if (record === void 0) {
|
|
829
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
830
|
-
"rebuildContribution requires a transaction-scoped backend that can write contribution markers; without it the drop, recreate, and stamp could not commit together.",
|
|
831
|
-
{
|
|
832
|
-
backend: dialect,
|
|
833
|
-
capability: "contributions",
|
|
834
|
-
operation: "rebuild"
|
|
835
|
-
}
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
await lockContributionDdl(tx);
|
|
839
|
-
const unlockedForeignGraphIds = sharedTableExisted ? await readForeignGraphIds(tx, sharedTable, graphId) : [];
|
|
840
|
-
const mayRecreate = sharedTableExisted && unlockedForeignGraphIds.length === 0;
|
|
841
|
-
if (mayRecreate) await lockSharedFulltextTable(tx, sharedTable);
|
|
842
|
-
const foreignGraphIds = mayRecreate ? await readForeignGraphIds(tx, sharedTable, graphId) : unlockedForeignGraphIds;
|
|
843
|
-
const recreateStorage = mayRecreate && foreignGraphIds.length === 0;
|
|
844
|
-
if (!recreateStorage) {
|
|
845
|
-
const staleStamp = stamps.find(
|
|
846
|
-
({ key, signature }) => diagnoseContribution(
|
|
847
|
-
markers.get(key),
|
|
848
|
-
signature,
|
|
849
|
-
sharedTableExisted
|
|
850
|
-
) === "stale"
|
|
851
|
-
);
|
|
852
|
-
if (staleStamp !== void 0) {
|
|
853
|
-
throw new chunkMRDBBHIZ_cjs.ContributionRebuildUnsupportedError(
|
|
854
|
-
"shared-storage-in-use",
|
|
855
|
-
{
|
|
856
|
-
graphId,
|
|
857
|
-
contribution: scope,
|
|
858
|
-
owner: staleStamp.contribution.owner,
|
|
859
|
-
logicalName: staleStamp.contribution.logicalName,
|
|
860
|
-
physicalName: staleStamp.contribution.tableName,
|
|
861
|
-
otherGraphIds: foreignGraphIds
|
|
862
|
-
}
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
for (const { contribution } of stamps) {
|
|
867
|
-
if (recreateStorage) {
|
|
868
|
-
for (const statement of contribution.dropDdl ?? []) {
|
|
869
|
-
await tx.executeSchemaDdl(statement);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
for (const statement of contribution.createDdl) {
|
|
873
|
-
await tx.executeSchemaDdl(statement);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
if (!recreateStorage) {
|
|
877
|
-
await tx.executeStatement(
|
|
878
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
879
|
-
chunkL3LQNR34_cjs.buildFulltextGraphDelete(sharedTable, graphId)
|
|
880
|
-
)
|
|
881
|
-
);
|
|
882
|
-
}
|
|
883
|
-
const stats = await repopulate(tx);
|
|
884
|
-
const now = chunkFA2AFWLP_cjs.nowIso();
|
|
885
|
-
for (const { contribution, signature } of stamps) {
|
|
886
|
-
await record({
|
|
887
|
-
...identityOf(graphId, contribution),
|
|
888
|
-
signature,
|
|
889
|
-
attemptedAt: now,
|
|
890
|
-
materializedAt: now,
|
|
891
|
-
error: void 0
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
return {
|
|
895
|
-
rebuilt: stamps.map(({ contribution }) => contribution.tableName),
|
|
896
|
-
processed: stats.processed,
|
|
897
|
-
repopulated: stats.repopulated,
|
|
898
|
-
skipped: stats.skipped
|
|
899
|
-
};
|
|
900
|
-
});
|
|
901
|
-
for (const { key, signature } of stamps) {
|
|
902
|
-
cacheInitializedSignature(key, signature);
|
|
903
|
-
}
|
|
904
|
-
return rebuilt;
|
|
905
|
-
}
|
|
906
|
-
function evictVectorSlot(slot) {
|
|
907
|
-
if (deps.vectorStrategy === void 0) return;
|
|
908
|
-
for (const contribution of deps.vectorStrategy.ownedTables(slot)) {
|
|
909
|
-
const key = contributionKey(slot.graphId, contribution);
|
|
910
|
-
uncacheableKeys.add(key);
|
|
911
|
-
initializedSignatures.delete(key);
|
|
912
|
-
computedSignatures.delete(key);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
async function dropVectorSlot(slot) {
|
|
916
|
-
if (deps.vectorStrategy === void 0) return;
|
|
917
|
-
try {
|
|
918
|
-
for (const contribution of deps.vectorStrategy.ownedTables(slot)) {
|
|
919
|
-
await deps.deleteMarker(identityOf(slot.graphId, contribution));
|
|
920
|
-
}
|
|
921
|
-
} finally {
|
|
922
|
-
evictVectorSlot(slot);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return {
|
|
926
|
-
ensureRuntimeContributions,
|
|
927
|
-
assertInitialized,
|
|
928
|
-
refuseUnavailableFulltext,
|
|
929
|
-
ensureVectorSlot,
|
|
930
|
-
ensureVectorSlots,
|
|
931
|
-
assertVectorSlot,
|
|
932
|
-
assertVectorSlots,
|
|
933
|
-
dropVectorSlot,
|
|
934
|
-
evictVectorSlot,
|
|
935
|
-
verifyContributions,
|
|
936
|
-
repairContributions,
|
|
937
|
-
probeContributions,
|
|
938
|
-
rebuildContribution
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
var SQLITE_INDEX_MAT_TIMESTAMPS = {
|
|
942
|
-
decode: (value) => typeof value === "string" ? value : void 0,
|
|
943
|
-
encode: (value) => value
|
|
944
|
-
};
|
|
945
|
-
var POSTGRES_INDEX_MAT_TIMESTAMPS = {
|
|
946
|
-
decode: chunkFA2AFWLP_cjs.formatPostgresTimestamp,
|
|
947
|
-
encode: (value) => new Date(value)
|
|
948
|
-
};
|
|
949
|
-
function mapMaterializationRow(row, decode) {
|
|
950
|
-
const lastAttemptedAt = decode(row.lastAttemptedAt);
|
|
951
|
-
if (lastAttemptedAt === void 0) {
|
|
952
|
-
throw new Error(
|
|
953
|
-
`materialization row missing required last_attempted_at: ${row.indexName}`
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
return {
|
|
957
|
-
indexName: row.indexName,
|
|
958
|
-
graphId: row.graphId,
|
|
959
|
-
entity: row.entity,
|
|
960
|
-
kind: row.kind,
|
|
961
|
-
signature: row.signature,
|
|
962
|
-
schemaVersion: row.schemaVersion,
|
|
963
|
-
materializedAt: decode(row.materializedAt),
|
|
964
|
-
lastAttemptedAt,
|
|
965
|
-
lastError: row.lastError ?? void 0
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
function buildMaterializationInsertValues(params, encode) {
|
|
969
|
-
return {
|
|
970
|
-
indexName: params.indexName,
|
|
971
|
-
graphId: params.graphId,
|
|
972
|
-
entity: params.entity,
|
|
973
|
-
kind: params.kind,
|
|
974
|
-
signature: params.signature,
|
|
975
|
-
schemaVersion: params.schemaVersion,
|
|
976
|
-
materializedAt: params.materializedAt === void 0 ? void 0 : encode(params.materializedAt),
|
|
977
|
-
lastAttemptedAt: encode(params.attemptedAt),
|
|
978
|
-
lastError: params.error
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
function buildMaterializationOnConflictSet(paramsMaterializedAt) {
|
|
982
|
-
if (paramsMaterializedAt === void 0) {
|
|
983
|
-
return {
|
|
984
|
-
lastAttemptedAt: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_attempted_at")}`,
|
|
985
|
-
lastError: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_error")}`
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
return {
|
|
989
|
-
graphId: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("graph_id")}`,
|
|
990
|
-
entity: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("entity")}`,
|
|
991
|
-
kind: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("kind")}`,
|
|
992
|
-
signature: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("signature")}`,
|
|
993
|
-
schemaVersion: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("schema_version")}`,
|
|
994
|
-
materializedAt: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("materialized_at")}`,
|
|
995
|
-
lastAttemptedAt: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_attempted_at")}`,
|
|
996
|
-
lastError: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_error")}`
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
var SQLITE_KIND_REMOVAL_TIMESTAMPS = {
|
|
1000
|
-
decode: (value) => typeof value === "string" ? value : void 0,
|
|
1001
|
-
encode: (value) => value
|
|
1002
|
-
};
|
|
1003
|
-
var POSTGRES_KIND_REMOVAL_TIMESTAMPS = {
|
|
1004
|
-
decode: chunkFA2AFWLP_cjs.formatPostgresTimestamp,
|
|
1005
|
-
encode: (value) => new Date(value)
|
|
1006
|
-
};
|
|
1007
|
-
function mapKindRemovalRow(row, decode) {
|
|
1008
|
-
const lastAttemptedAt = decode(row.lastAttemptedAt);
|
|
1009
|
-
if (lastAttemptedAt === void 0) {
|
|
1010
|
-
throw new Error(
|
|
1011
|
-
`kind removal row missing required last_attempted_at: ${row.kindName}`
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
return {
|
|
1015
|
-
graphId: row.graphId,
|
|
1016
|
-
kindName: row.kindName,
|
|
1017
|
-
entity: row.entity,
|
|
1018
|
-
schemaVersion: row.schemaVersion,
|
|
1019
|
-
removedAt: decode(row.removedAt),
|
|
1020
|
-
lastAttemptedAt,
|
|
1021
|
-
lastError: row.lastError ?? void 0
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
function buildKindRemovalInsertValues(params, encode) {
|
|
1025
|
-
return {
|
|
1026
|
-
graphId: params.graphId,
|
|
1027
|
-
kindName: params.kindName,
|
|
1028
|
-
entity: params.entity,
|
|
1029
|
-
schemaVersion: params.schemaVersion,
|
|
1030
|
-
removedAt: params.removedAt === void 0 ? void 0 : encode(params.removedAt),
|
|
1031
|
-
lastAttemptedAt: encode(params.attemptedAt),
|
|
1032
|
-
lastError: params.error
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
function buildKindRemovalOnConflictSet(removedAtColumn, paramsRemovedAt) {
|
|
1036
|
-
const removedAtSet = paramsRemovedAt === void 0 ? drizzleOrm.sql`COALESCE(excluded.${drizzleOrm.sql.identifier("removed_at")}, ${removedAtColumn})` : drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("removed_at")}`;
|
|
1037
|
-
return {
|
|
1038
|
-
entity: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("entity")}`,
|
|
1039
|
-
schemaVersion: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("schema_version")}`,
|
|
1040
|
-
removedAt: removedAtSet,
|
|
1041
|
-
lastAttemptedAt: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_attempted_at")}`,
|
|
1042
|
-
lastError: drizzleOrm.sql`excluded.${drizzleOrm.sql.identifier("last_error")}`
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
function primaryKeyConstraintNames(relation, keyColumns) {
|
|
1046
|
-
return [`${relation}_pkey`, `${relation}_${keyColumns.join("_")}_pk`];
|
|
1047
|
-
}
|
|
1048
|
-
function nodePrimaryKeyConstraint(nodes) {
|
|
1049
|
-
const relation = drizzleOrm.getTableName(nodes);
|
|
1050
|
-
return {
|
|
1051
|
-
table: relation,
|
|
1052
|
-
constraintNames: primaryKeyConstraintNames(relation, [
|
|
1053
|
-
nodes.graphId.name,
|
|
1054
|
-
nodes.kind.name,
|
|
1055
|
-
nodes.id.name
|
|
1056
|
-
])
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
function edgePrimaryKeyConstraint(edges) {
|
|
1060
|
-
const relation = drizzleOrm.getTableName(edges);
|
|
1061
|
-
return {
|
|
1062
|
-
table: relation,
|
|
1063
|
-
constraintNames: primaryKeyConstraintNames(relation, [
|
|
1064
|
-
edges.graphId.name,
|
|
1065
|
-
edges.id.name
|
|
1066
|
-
])
|
|
1067
|
-
};
|
|
1068
|
-
}
|
|
1069
|
-
function sqlNull(value) {
|
|
1070
|
-
return value ?? drizzleOrm.sql.raw("NULL");
|
|
1071
|
-
}
|
|
1072
|
-
function expectedValidFromPredicate(column, expected) {
|
|
1073
|
-
if (expected === void 0) return drizzleOrm.sql.empty();
|
|
1074
|
-
if (expected === null) return drizzleOrm.sql` AND ${column} IS NULL`;
|
|
1075
|
-
return drizzleOrm.sql` AND ${column} = ${expected}`;
|
|
1076
|
-
}
|
|
1077
|
-
function quotedColumn(column) {
|
|
1078
|
-
return drizzleOrm.sql.raw(`"${column.name.replaceAll('"', '""')}"`);
|
|
1079
|
-
}
|
|
1080
|
-
function quotedTableName(tableName) {
|
|
1081
|
-
return drizzleOrm.sql.raw(`"${tableName.replaceAll('"', '""')}"`);
|
|
1082
|
-
}
|
|
1083
|
-
var CODE_POINT_ORDER_BUILDERS = {
|
|
1084
|
-
postgres: (value) => drizzleOrm.sql`${value} COLLATE "C"`,
|
|
1085
|
-
sqlite: (value) => value
|
|
1086
|
-
};
|
|
1087
|
-
function codePointOrderKey(column, dialect) {
|
|
1088
|
-
return CODE_POINT_ORDER_BUILDERS[dialect](column);
|
|
1089
|
-
}
|
|
1090
|
-
function liveNodeIdsSubquery(nodes, graphId, nodeKind, nowIso2) {
|
|
1091
|
-
return drizzleOrm.sql`SELECT ${nodes.id} AS node_id FROM ${nodes} WHERE ${nodes.graphId} = ${graphId} AND ${nodes.kind} = ${nodeKind} AND ${nodes.deletedAt} IS NULL AND (${nodes.validFrom} IS NULL OR ${nodes.validFrom} <= ${nowIso2}) AND (${nodes.validTo} IS NULL OR ${nodes.validTo} > ${nowIso2})`;
|
|
1092
|
-
}
|
|
1093
|
-
function nodeColumnList(nodes) {
|
|
1094
|
-
return drizzleOrm.sql.raw(
|
|
1095
|
-
`"${nodes.graphId.name}", "${nodes.kind.name}", "${nodes.id.name}", "${nodes.props.name}", "${nodes.version.name}", "${nodes.validFrom.name}", "${nodes.validTo.name}", "${nodes.createdAt.name}", "${nodes.updatedAt.name}"`
|
|
1096
|
-
);
|
|
1097
|
-
}
|
|
1098
|
-
function edgeColumnList(edges) {
|
|
1099
|
-
return drizzleOrm.sql.raw(
|
|
1100
|
-
`"${edges.graphId.name}", "${edges.id.name}", "${edges.kind.name}", "${edges.fromKind.name}", "${edges.fromId.name}", "${edges.toKind.name}", "${edges.toId.name}", "${edges.props.name}", "${edges.validFrom.name}", "${edges.validTo.name}", "${edges.createdAt.name}", "${edges.updatedAt.name}"`
|
|
1101
|
-
);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
// src/backend/drizzle/operations/hybrid.ts
|
|
1105
|
-
function nodeIdOrderKey(dialect) {
|
|
1106
|
-
return codePointOrderKey(drizzleOrm.sql.raw("node_id"), dialect);
|
|
1107
|
-
}
|
|
1108
|
-
function hybridCandidatesRef() {
|
|
1109
|
-
return drizzleOrm.sql`SELECT node_id FROM tg_hybrid_cand`;
|
|
1110
|
-
}
|
|
1111
|
-
function buildHybridSearchStatement(input) {
|
|
1112
|
-
const { nodes } = input;
|
|
1113
|
-
const nodeIdOrder = nodeIdOrderKey(input.dialect);
|
|
1114
|
-
const vectorOrder = input.vectorScoreDescending ? drizzleOrm.sql`score DESC, ${nodeIdOrder} ASC` : drizzleOrm.sql`score ASC, ${nodeIdOrder} ASC`;
|
|
1115
|
-
const columnPairs = [
|
|
1116
|
-
[nodes.graphId, "graph_id"],
|
|
1117
|
-
[nodes.kind, "kind"],
|
|
1118
|
-
[nodes.id, "id"],
|
|
1119
|
-
[nodes.props, "props"],
|
|
1120
|
-
[nodes.version, "version"],
|
|
1121
|
-
[nodes.validFrom, "valid_from"],
|
|
1122
|
-
[nodes.validTo, "valid_to"],
|
|
1123
|
-
[nodes.createdAt, "created_at"],
|
|
1124
|
-
[nodes.updatedAt, "updated_at"],
|
|
1125
|
-
[nodes.deletedAt, "deleted_at"]
|
|
1126
|
-
];
|
|
1127
|
-
const nodeColumns = drizzleOrm.sql.raw(
|
|
1128
|
-
columnPairs.map(
|
|
1129
|
-
([column, alias]) => `tg_hybrid_node."${column.name.replaceAll('"', '""')}" AS ${alias}`
|
|
1130
|
-
).join(", ")
|
|
1131
|
-
);
|
|
1132
|
-
return drizzleOrm.sql`
|
|
1133
|
-
WITH tg_hybrid_cand AS (
|
|
1134
|
-
SELECT node_id FROM (${input.candidatesSql}) AS tg_hybrid_cand_src
|
|
1135
|
-
),
|
|
1136
|
-
tg_hybrid_vec AS (
|
|
1137
|
-
SELECT node_id, score,
|
|
1138
|
-
ROW_NUMBER() OVER (ORDER BY ${vectorOrder}) AS ord
|
|
1139
|
-
FROM (${input.vectorSql}) AS tg_hybrid_vec_src
|
|
1140
|
-
),
|
|
1141
|
-
tg_hybrid_fts AS (
|
|
1142
|
-
SELECT node_id, score, snippet,
|
|
1143
|
-
ROW_NUMBER() OVER (ORDER BY score DESC, ${nodeIdOrder} ASC) AS ord
|
|
1144
|
-
FROM (${input.fulltextSql}) AS tg_hybrid_fts_src
|
|
1145
|
-
),
|
|
1146
|
-
tg_hybrid_pairs AS (
|
|
1147
|
-
SELECT node_id, ord AS vector_rank, score AS vector_score,
|
|
1148
|
-
NULL AS fulltext_rank, NULL AS fulltext_score, NULL AS snippet
|
|
1149
|
-
FROM tg_hybrid_vec
|
|
1150
|
-
UNION ALL
|
|
1151
|
-
SELECT node_id, NULL, NULL, ord, score, snippet
|
|
1152
|
-
FROM tg_hybrid_fts
|
|
1153
|
-
),
|
|
1154
|
-
tg_hybrid_fused AS MATERIALIZED (
|
|
1155
|
-
SELECT node_id,
|
|
1156
|
-
SUM(
|
|
1157
|
-
COALESCE((${input.vectorWeight} * 1.0) / (${input.fusionK} + vector_rank), 0)
|
|
1158
|
-
+ COALESCE((${input.fulltextWeight} * 1.0) / (${input.fusionK} + fulltext_rank), 0)
|
|
1159
|
-
) AS fused_score,
|
|
1160
|
-
MAX(vector_rank) AS vector_rank,
|
|
1161
|
-
MAX(vector_score) AS vector_score,
|
|
1162
|
-
MAX(fulltext_rank) AS fulltext_rank,
|
|
1163
|
-
MAX(fulltext_score) AS fulltext_score,
|
|
1164
|
-
MAX(snippet) AS snippet
|
|
1165
|
-
FROM tg_hybrid_pairs
|
|
1166
|
-
GROUP BY node_id
|
|
1167
|
-
)
|
|
1168
|
-
SELECT
|
|
1169
|
-
tg_hybrid_fused.node_id AS node_id,
|
|
1170
|
-
tg_hybrid_fused.fused_score AS fused_score,
|
|
1171
|
-
tg_hybrid_fused.vector_rank AS vector_rank,
|
|
1172
|
-
tg_hybrid_fused.vector_score AS vector_score,
|
|
1173
|
-
tg_hybrid_fused.fulltext_rank AS fulltext_rank,
|
|
1174
|
-
tg_hybrid_fused.fulltext_score AS fulltext_score,
|
|
1175
|
-
tg_hybrid_fused.snippet AS snippet,
|
|
1176
|
-
${nodeColumns}
|
|
1177
|
-
FROM tg_hybrid_fused
|
|
1178
|
-
JOIN ${nodes} AS tg_hybrid_node
|
|
1179
|
-
ON ${qualified(nodes, "graphId")} = ${input.graphId}
|
|
1180
|
-
AND ${qualified(nodes, "kind")} = ${input.nodeKind}
|
|
1181
|
-
AND ${qualified(nodes, "id")} = tg_hybrid_fused.node_id
|
|
1182
|
-
AND ${qualified(nodes, "deletedAt")} IS NULL
|
|
1183
|
-
ORDER BY fused_score DESC, ${nodeIdOrder} ASC
|
|
1184
|
-
LIMIT ${input.limit} OFFSET ${input.offset}
|
|
1185
|
-
`;
|
|
1186
|
-
}
|
|
1187
|
-
function qualified(nodes, member) {
|
|
1188
|
-
return drizzleOrm.sql`tg_hybrid_node.${quotedColumn(nodes[member])}`;
|
|
1189
|
-
}
|
|
1190
|
-
function present(value) {
|
|
1191
|
-
return value !== null && value !== void 0;
|
|
1192
|
-
}
|
|
1193
|
-
function mapHybridSearchRow(row, toNodeRow) {
|
|
1194
|
-
return {
|
|
1195
|
-
node: toNodeRow(row),
|
|
1196
|
-
fusedScore: chunkFA2AFWLP_cjs.coerceNumericScore(row["fused_score"]),
|
|
1197
|
-
...present(row["vector_rank"]) ? { vectorRank: Number(row["vector_rank"]) } : {},
|
|
1198
|
-
...present(row["vector_score"]) ? { vectorScore: chunkFA2AFWLP_cjs.coerceNumericScore(row["vector_score"]) } : {},
|
|
1199
|
-
...present(row["fulltext_rank"]) ? { fulltextRank: Number(row["fulltext_rank"]) } : {},
|
|
1200
|
-
...present(row["fulltext_score"]) ? {
|
|
1201
|
-
fulltextScore: chunkFA2AFWLP_cjs.coerceNumericScore(
|
|
1202
|
-
row["fulltext_score"]
|
|
1203
|
-
)
|
|
1204
|
-
} : {},
|
|
1205
|
-
...present(row["snippet"]) ? { snippet: String(row["snippet"]) } : {}
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
function buildClearGraph(tables, graphId) {
|
|
1209
|
-
return [
|
|
1210
|
-
// The fulltext table is shared by every graph in the database, so its
|
|
1211
|
-
// graph-scoped delete is owned by one builder the destructive
|
|
1212
|
-
// contribution rebuild calls too — see `buildFulltextGraphDelete`.
|
|
1213
|
-
{ query: chunkL3LQNR34_cjs.buildFulltextGraphDelete(tables.fulltextTableName, graphId) },
|
|
1214
|
-
{
|
|
1215
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.recordedIdentityAssertions} WHERE ${tables.recordedIdentityAssertions.graphId} = ${graphId}`,
|
|
1216
|
-
ignoreMissingTable: true,
|
|
1217
|
-
requiredTableName: drizzleOrm.getTableName(tables.recordedIdentityAssertions)
|
|
1218
|
-
},
|
|
1219
|
-
{
|
|
1220
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.recordedEdges} WHERE ${tables.recordedEdges.graphId} = ${graphId}`,
|
|
1221
|
-
ignoreMissingTable: true,
|
|
1222
|
-
requiredTableName: drizzleOrm.getTableName(tables.recordedEdges)
|
|
1223
|
-
},
|
|
1224
|
-
{
|
|
1225
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.recordedNodes} WHERE ${tables.recordedNodes.graphId} = ${graphId}`,
|
|
1226
|
-
ignoreMissingTable: true,
|
|
1227
|
-
requiredTableName: drizzleOrm.getTableName(tables.recordedNodes)
|
|
1228
|
-
},
|
|
1229
|
-
{
|
|
1230
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.recordedClock} WHERE ${tables.recordedClock.graphId} = ${graphId}`,
|
|
1231
|
-
ignoreMissingTable: true,
|
|
1232
|
-
requiredTableName: drizzleOrm.getTableName(tables.recordedClock)
|
|
1233
|
-
},
|
|
1234
|
-
{
|
|
1235
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.identitySeparation} WHERE ${tables.identitySeparation.graphId} = ${graphId}`,
|
|
1236
|
-
ignoreMissingTable: true,
|
|
1237
|
-
requiredTableName: drizzleOrm.getTableName(tables.identitySeparation)
|
|
1238
|
-
},
|
|
1239
|
-
{
|
|
1240
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.identityClosure} WHERE ${tables.identityClosure.graphId} = ${graphId}`,
|
|
1241
|
-
ignoreMissingTable: true,
|
|
1242
|
-
requiredTableName: drizzleOrm.getTableName(tables.identityClosure)
|
|
1243
|
-
},
|
|
1244
|
-
{
|
|
1245
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.identityAssertions} WHERE ${tables.identityAssertions.graphId} = ${graphId}`,
|
|
1246
|
-
ignoreMissingTable: true,
|
|
1247
|
-
requiredTableName: drizzleOrm.getTableName(tables.identityAssertions)
|
|
1248
|
-
},
|
|
1249
|
-
{
|
|
1250
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.uniques} WHERE ${tables.uniques.graphId} = ${graphId}`
|
|
1251
|
-
},
|
|
1252
|
-
{
|
|
1253
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.edges} WHERE ${tables.edges.graphId} = ${graphId}`
|
|
1254
|
-
},
|
|
1255
|
-
{
|
|
1256
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.nodes} WHERE ${tables.nodes.graphId} = ${graphId}`
|
|
1257
|
-
},
|
|
1258
|
-
{
|
|
1259
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.indexMaterializations} WHERE ${tables.indexMaterializations.graphId} = ${graphId}`
|
|
1260
|
-
},
|
|
1261
|
-
{
|
|
1262
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.kindRemovals} WHERE ${tables.kindRemovals.graphId} = ${graphId}`
|
|
1263
|
-
},
|
|
1264
|
-
{
|
|
1265
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.reconciliationMarkers} WHERE ${tables.reconciliationMarkers.graphId} = ${graphId}`
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
query: drizzleOrm.sql`DELETE FROM ${tables.schemaVersions} WHERE ${tables.schemaVersions.graphId} = ${graphId}`
|
|
1269
|
-
}
|
|
1270
|
-
];
|
|
1271
|
-
}
|
|
1272
|
-
function buildTemporalConditions(table, params) {
|
|
1273
|
-
const conditions = [];
|
|
1274
|
-
const mode = params.temporalMode;
|
|
1275
|
-
if (mode === "includeTombstones") return conditions;
|
|
1276
|
-
if (params.excludeDeleted !== false) {
|
|
1277
|
-
conditions.push(drizzleOrm.sql`${table.deletedAt} IS NULL`);
|
|
1278
|
-
}
|
|
1279
|
-
if (mode === "current" || mode === "asOf") {
|
|
1280
|
-
if (params.asOf === void 0) {
|
|
1281
|
-
throw new Error(`asOf timestamp is required for temporal mode "${mode}"`);
|
|
1282
|
-
}
|
|
1283
|
-
conditions.push(
|
|
1284
|
-
drizzleOrm.sql`(${table.validFrom} IS NULL OR ${table.validFrom} <= ${params.asOf})`,
|
|
1285
|
-
drizzleOrm.sql`(${table.validTo} IS NULL OR ${table.validTo} > ${params.asOf})`
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
return conditions;
|
|
1289
|
-
}
|
|
1290
|
-
function buildFindNodesByKind(tables, params) {
|
|
1291
|
-
const { nodes } = tables;
|
|
1292
|
-
const conditions = [
|
|
1293
|
-
drizzleOrm.sql`${nodes.graphId} = ${params.graphId}`,
|
|
1294
|
-
drizzleOrm.sql`${nodes.kind} = ${params.kind}`,
|
|
1295
|
-
...buildTemporalConditions(nodes, params)
|
|
1296
|
-
];
|
|
1297
|
-
if (params.orderBy === "id" && params.after !== void 0) {
|
|
1298
|
-
conditions.push(drizzleOrm.sql`${nodes.id} > ${params.after}`);
|
|
1299
|
-
}
|
|
1300
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1301
|
-
const orderByClause = params.orderBy === "id" ? drizzleOrm.sql`${nodes.id} ASC` : drizzleOrm.sql`${nodes.createdAt} DESC, ${nodes.id} DESC`;
|
|
1302
|
-
if (params.limit !== void 0 && params.offset !== void 0) {
|
|
1303
|
-
return drizzleOrm.sql`
|
|
1304
|
-
SELECT * FROM ${nodes}
|
|
1305
|
-
WHERE ${whereClause}
|
|
1306
|
-
ORDER BY ${orderByClause}
|
|
1307
|
-
LIMIT ${params.limit} OFFSET ${params.offset}
|
|
1308
|
-
`;
|
|
1309
|
-
}
|
|
1310
|
-
if (params.limit !== void 0) {
|
|
1311
|
-
return drizzleOrm.sql`
|
|
1312
|
-
SELECT * FROM ${nodes}
|
|
1313
|
-
WHERE ${whereClause}
|
|
1314
|
-
ORDER BY ${orderByClause}
|
|
1315
|
-
LIMIT ${params.limit}
|
|
1316
|
-
`;
|
|
1317
|
-
}
|
|
1318
|
-
return drizzleOrm.sql`
|
|
1319
|
-
SELECT * FROM ${nodes}
|
|
1320
|
-
WHERE ${whereClause}
|
|
1321
|
-
ORDER BY ${orderByClause}
|
|
1322
|
-
`;
|
|
1323
|
-
}
|
|
1324
|
-
function buildCountNodesByKind(tables, params) {
|
|
1325
|
-
const { nodes } = tables;
|
|
1326
|
-
const conditions = [
|
|
1327
|
-
drizzleOrm.sql`${nodes.graphId} = ${params.graphId}`,
|
|
1328
|
-
drizzleOrm.sql`${nodes.kind} = ${params.kind}`,
|
|
1329
|
-
...buildTemporalConditions(nodes, params)
|
|
1330
|
-
];
|
|
1331
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1332
|
-
return drizzleOrm.sql`
|
|
1333
|
-
SELECT COUNT(*) as count FROM ${nodes}
|
|
1334
|
-
WHERE ${whereClause}
|
|
1335
|
-
`;
|
|
1336
|
-
}
|
|
1337
|
-
function buildIdSetCondition(column, ids) {
|
|
1338
|
-
return drizzleOrm.sql`${column} IN (${drizzleOrm.sql.join(
|
|
1339
|
-
ids.map((id) => drizzleOrm.sql`${id}`),
|
|
1340
|
-
drizzleOrm.sql`, `
|
|
1341
|
-
)})`;
|
|
1342
|
-
}
|
|
1343
|
-
function buildEdgeOrdering(tables, orderBy) {
|
|
1344
|
-
const { edges } = tables;
|
|
1345
|
-
return orderBy === "id" ? { qualified: drizzleOrm.sql`${edges.id} ASC`, bare: drizzleOrm.sql.raw(`"id" ASC`) } : {
|
|
1346
|
-
qualified: drizzleOrm.sql`${edges.createdAt} DESC, ${edges.id} DESC`,
|
|
1347
|
-
bare: drizzleOrm.sql.raw(`"created_at" DESC, "id" DESC`)
|
|
1348
|
-
};
|
|
1349
|
-
}
|
|
1350
|
-
function buildFindEdgesByKind(tables, params) {
|
|
1351
|
-
const { edges } = tables;
|
|
1352
|
-
const conditions = [
|
|
1353
|
-
drizzleOrm.sql`${edges.graphId} = ${params.graphId}`,
|
|
1354
|
-
drizzleOrm.sql`${edges.kind} = ${params.kind}`,
|
|
1355
|
-
...buildTemporalConditions(edges, params)
|
|
1356
|
-
];
|
|
1357
|
-
if (params.fromKind !== void 0) {
|
|
1358
|
-
conditions.push(drizzleOrm.sql`${edges.fromKind} = ${params.fromKind}`);
|
|
1359
|
-
}
|
|
1360
|
-
if (params.fromId !== void 0) {
|
|
1361
|
-
conditions.push(drizzleOrm.sql`${edges.fromId} = ${params.fromId}`);
|
|
1362
|
-
}
|
|
1363
|
-
if (params.toKind !== void 0) {
|
|
1364
|
-
conditions.push(drizzleOrm.sql`${edges.toKind} = ${params.toKind}`);
|
|
1365
|
-
}
|
|
1366
|
-
if (params.toId !== void 0) {
|
|
1367
|
-
conditions.push(drizzleOrm.sql`${edges.toId} = ${params.toId}`);
|
|
1368
|
-
}
|
|
1369
|
-
if (params.orderBy === "id" && params.after !== void 0) {
|
|
1370
|
-
conditions.push(drizzleOrm.sql`${edges.id} > ${params.after}`);
|
|
1371
|
-
}
|
|
1372
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1373
|
-
const { qualified: orderByClause } = buildEdgeOrdering(
|
|
1374
|
-
tables,
|
|
1375
|
-
params.orderBy
|
|
1376
|
-
);
|
|
1377
|
-
if (params.limit !== void 0 && params.offset !== void 0) {
|
|
1378
|
-
return drizzleOrm.sql`
|
|
1379
|
-
SELECT * FROM ${edges}
|
|
1380
|
-
WHERE ${whereClause}
|
|
1381
|
-
ORDER BY ${orderByClause}
|
|
1382
|
-
LIMIT ${params.limit} OFFSET ${params.offset}
|
|
1383
|
-
`;
|
|
1384
|
-
}
|
|
1385
|
-
if (params.limit !== void 0) {
|
|
1386
|
-
return drizzleOrm.sql`
|
|
1387
|
-
SELECT * FROM ${edges}
|
|
1388
|
-
WHERE ${whereClause}
|
|
1389
|
-
ORDER BY ${orderByClause}
|
|
1390
|
-
LIMIT ${params.limit}
|
|
1391
|
-
`;
|
|
1392
|
-
}
|
|
1393
|
-
return drizzleOrm.sql`
|
|
1394
|
-
SELECT * FROM ${edges}
|
|
1395
|
-
WHERE ${whereClause}
|
|
1396
|
-
ORDER BY ${orderByClause}
|
|
1397
|
-
`;
|
|
1398
|
-
}
|
|
1399
|
-
function buildFindEdgesByEndpointSet(tables, params, endpointIds) {
|
|
1400
|
-
const { edges } = tables;
|
|
1401
|
-
const fromSide = params.side === "from";
|
|
1402
|
-
const kindColumn = fromSide ? edges.fromKind : edges.toKind;
|
|
1403
|
-
const idColumn = fromSide ? edges.fromId : edges.toId;
|
|
1404
|
-
const whereClause = drizzleOrm.sql.join(
|
|
1405
|
-
[
|
|
1406
|
-
drizzleOrm.sql`${edges.graphId} = ${params.graphId}`,
|
|
1407
|
-
drizzleOrm.sql`${edges.kind} = ${params.kind}`,
|
|
1408
|
-
...buildTemporalConditions(edges, params),
|
|
1409
|
-
drizzleOrm.sql`${kindColumn} = ${params.endpointKind}`,
|
|
1410
|
-
buildIdSetCondition(idColumn, endpointIds)
|
|
1411
|
-
],
|
|
1412
|
-
drizzleOrm.sql` AND `
|
|
1413
|
-
);
|
|
1414
|
-
const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
|
|
1415
|
-
if (params.limitPerEndpoint === void 0) {
|
|
1416
|
-
return drizzleOrm.sql`
|
|
1417
|
-
SELECT * FROM ${edges}
|
|
1418
|
-
WHERE ${whereClause}
|
|
1419
|
-
ORDER BY ${orderByClause}
|
|
1420
|
-
`;
|
|
1421
|
-
}
|
|
1422
|
-
const ranked = drizzleOrm.sql`
|
|
1423
|
-
SELECT *, ROW_NUMBER() OVER (
|
|
1424
|
-
PARTITION BY ${idColumn} ORDER BY ${orderByClause}
|
|
1425
|
-
) AS endpoint_rank
|
|
1426
|
-
FROM ${edges}
|
|
1427
|
-
WHERE ${whereClause}
|
|
1428
|
-
`;
|
|
1429
|
-
return drizzleOrm.sql`
|
|
1430
|
-
SELECT * FROM (${ranked}) AS ranked_edges
|
|
1431
|
-
WHERE endpoint_rank <= ${params.limitPerEndpoint}
|
|
1432
|
-
ORDER BY ${derivedOrderByClause}
|
|
1433
|
-
`;
|
|
1434
|
-
}
|
|
1435
|
-
function buildFindEdgesByHeterogeneousEndpointSet(tables, params, endpoints, edgeKinds) {
|
|
1436
|
-
const { edges } = tables;
|
|
1437
|
-
const fromSide = params.side === "from";
|
|
1438
|
-
const kindColumn = fromSide ? edges.fromKind : edges.toKind;
|
|
1439
|
-
const idColumn = fromSide ? edges.fromId : edges.toId;
|
|
1440
|
-
const requestedKind = drizzleOrm.sql.raw(`requested_endpoints."endpoint_kind"`);
|
|
1441
|
-
const requestedId = drizzleOrm.sql.raw(`requested_endpoints."endpoint_id"`);
|
|
1442
|
-
const requestedRows = drizzleOrm.sql.join(
|
|
1443
|
-
endpoints.map((endpoint) => drizzleOrm.sql`(${endpoint.kind}, ${endpoint.id})`),
|
|
1444
|
-
drizzleOrm.sql`, `
|
|
1445
|
-
);
|
|
1446
|
-
const whereClause = drizzleOrm.sql.join(
|
|
1447
|
-
[
|
|
1448
|
-
drizzleOrm.sql`${edges.graphId} = ${params.graphId}`,
|
|
1449
|
-
buildIdSetCondition(edges.kind, edgeKinds),
|
|
1450
|
-
...buildTemporalConditions(edges, params)
|
|
1451
|
-
],
|
|
1452
|
-
drizzleOrm.sql` AND `
|
|
1453
|
-
);
|
|
1454
|
-
const joinClause = drizzleOrm.sql`
|
|
1455
|
-
FROM ${edges}
|
|
1456
|
-
INNER JOIN requested_endpoints
|
|
1457
|
-
ON ${kindColumn} = ${requestedKind}
|
|
1458
|
-
AND ${idColumn} = ${requestedId}
|
|
1459
|
-
WHERE ${whereClause}
|
|
1460
|
-
`;
|
|
1461
|
-
const { qualified: orderByClause, bare: derivedOrderByClause } = buildEdgeOrdering(tables, void 0);
|
|
1462
|
-
if (params.limitPerEndpoint === void 0) {
|
|
1463
|
-
return drizzleOrm.sql`
|
|
1464
|
-
WITH requested_endpoints(endpoint_kind, endpoint_id) AS (
|
|
1465
|
-
VALUES ${requestedRows}
|
|
1466
|
-
)
|
|
1467
|
-
SELECT ${edges}.*
|
|
1468
|
-
${joinClause}
|
|
1469
|
-
ORDER BY ${orderByClause}
|
|
1470
|
-
`;
|
|
1471
|
-
}
|
|
1472
|
-
const ranked = drizzleOrm.sql`
|
|
1473
|
-
SELECT ${edges}.*, ROW_NUMBER() OVER (
|
|
1474
|
-
PARTITION BY ${kindColumn}, ${idColumn} ORDER BY ${orderByClause}
|
|
1475
|
-
) AS endpoint_rank
|
|
1476
|
-
${joinClause}
|
|
1477
|
-
`;
|
|
1478
|
-
return drizzleOrm.sql`
|
|
1479
|
-
WITH requested_endpoints(endpoint_kind, endpoint_id) AS (
|
|
1480
|
-
VALUES ${requestedRows}
|
|
1481
|
-
)
|
|
1482
|
-
SELECT * FROM (${ranked}) AS ranked_edges
|
|
1483
|
-
WHERE endpoint_rank <= ${params.limitPerEndpoint}
|
|
1484
|
-
ORDER BY ${derivedOrderByClause}
|
|
1485
|
-
`;
|
|
1486
|
-
}
|
|
1487
|
-
function buildCountEdgesByKind(tables, params) {
|
|
1488
|
-
const { edges } = tables;
|
|
1489
|
-
const conditions = [
|
|
1490
|
-
drizzleOrm.sql`${edges.graphId} = ${params.graphId}`,
|
|
1491
|
-
drizzleOrm.sql`${edges.kind} = ${params.kind}`,
|
|
1492
|
-
...buildTemporalConditions(edges, params)
|
|
1493
|
-
];
|
|
1494
|
-
if (params.fromKind !== void 0) {
|
|
1495
|
-
conditions.push(drizzleOrm.sql`${edges.fromKind} = ${params.fromKind}`);
|
|
1496
|
-
}
|
|
1497
|
-
if (params.fromId !== void 0) {
|
|
1498
|
-
conditions.push(drizzleOrm.sql`${edges.fromId} = ${params.fromId}`);
|
|
1499
|
-
}
|
|
1500
|
-
if (params.toKind !== void 0) {
|
|
1501
|
-
conditions.push(drizzleOrm.sql`${edges.toKind} = ${params.toKind}`);
|
|
1502
|
-
}
|
|
1503
|
-
if (params.toId !== void 0) {
|
|
1504
|
-
conditions.push(drizzleOrm.sql`${edges.toId} = ${params.toId}`);
|
|
1505
|
-
}
|
|
1506
|
-
const whereClause = drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `);
|
|
1507
|
-
return drizzleOrm.sql`
|
|
1508
|
-
SELECT COUNT(*) as count FROM ${edges}
|
|
1509
|
-
WHERE ${whereClause}
|
|
1510
|
-
`;
|
|
1511
|
-
}
|
|
1512
|
-
function buildInsertEdge(tables, params, timestamp) {
|
|
1513
|
-
const { edges } = tables;
|
|
1514
|
-
const propsJson = JSON.stringify(params.props);
|
|
1515
|
-
const columns = edgeColumnList(edges);
|
|
1516
|
-
return drizzleOrm.sql`
|
|
1517
|
-
INSERT INTO ${edges} (${columns})
|
|
1518
|
-
VALUES (
|
|
1519
|
-
${params.graphId}, ${params.id}, ${params.kind},
|
|
1520
|
-
${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
|
|
1521
|
-
${propsJson}, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
|
|
1522
|
-
${timestamp}, ${timestamp}
|
|
1523
|
-
)
|
|
1524
|
-
RETURNING *
|
|
1525
|
-
`;
|
|
1526
|
-
}
|
|
1527
|
-
function buildInsertEdgeNoReturn(tables, params, timestamp) {
|
|
1528
|
-
const { edges } = tables;
|
|
1529
|
-
const propsJson = JSON.stringify(params.props);
|
|
1530
|
-
const columns = edgeColumnList(edges);
|
|
1531
|
-
return drizzleOrm.sql`
|
|
1532
|
-
INSERT INTO ${edges} (${columns})
|
|
1533
|
-
VALUES (
|
|
1534
|
-
${params.graphId}, ${params.id}, ${params.kind},
|
|
1535
|
-
${params.fromKind}, ${params.fromId}, ${params.toKind}, ${params.toId},
|
|
1536
|
-
${propsJson}, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
|
|
1537
|
-
${timestamp}, ${timestamp}
|
|
1538
|
-
)
|
|
1539
|
-
`;
|
|
1540
|
-
}
|
|
1541
|
-
function buildInsertEdgesBatch(tables, params, timestamp) {
|
|
1542
|
-
const { edges } = tables;
|
|
1543
|
-
const columns = edgeColumnList(edges);
|
|
1544
|
-
const values = params.map((edgeParams) => {
|
|
1545
|
-
const propsJson = JSON.stringify(edgeParams.props);
|
|
1546
|
-
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp))}, ${sqlNull(edgeParams.validTo)}, ${timestamp}, ${timestamp})`;
|
|
1547
|
-
});
|
|
1548
|
-
return drizzleOrm.sql`
|
|
1549
|
-
INSERT INTO ${edges} (${columns})
|
|
1550
|
-
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1551
|
-
`;
|
|
1552
|
-
}
|
|
1553
|
-
function buildInsertEdgesBatchReturning(tables, params, timestamp) {
|
|
1554
|
-
const { edges } = tables;
|
|
1555
|
-
const columns = edgeColumnList(edges);
|
|
1556
|
-
const values = params.map((edgeParams) => {
|
|
1557
|
-
const propsJson = JSON.stringify(edgeParams.props);
|
|
1558
|
-
return drizzleOrm.sql`(${edgeParams.graphId}, ${edgeParams.id}, ${edgeParams.kind}, ${edgeParams.fromKind}, ${edgeParams.fromId}, ${edgeParams.toKind}, ${edgeParams.toId}, ${propsJson}, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(edgeParams.validFrom, edgeParams.validTo, timestamp))}, ${sqlNull(edgeParams.validTo)}, ${timestamp}, ${timestamp})`;
|
|
1559
|
-
});
|
|
1560
|
-
return drizzleOrm.sql`
|
|
1561
|
-
INSERT INTO ${edges} (${columns})
|
|
1562
|
-
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1563
|
-
RETURNING *
|
|
1564
|
-
`;
|
|
1565
|
-
}
|
|
1566
|
-
function buildGetEdge(tables, graphId, id) {
|
|
1567
|
-
const { edges } = tables;
|
|
1568
|
-
return drizzleOrm.sql`
|
|
1569
|
-
SELECT * FROM ${edges}
|
|
1570
|
-
WHERE ${edges.graphId} = ${graphId}
|
|
1571
|
-
AND ${edges.id} = ${id}
|
|
1572
|
-
`;
|
|
1573
|
-
}
|
|
1574
|
-
function buildGetEdges(tables, graphId, ids) {
|
|
1575
|
-
const { edges } = tables;
|
|
1576
|
-
return drizzleOrm.sql`
|
|
1577
|
-
SELECT * FROM ${edges}
|
|
1578
|
-
WHERE ${edges.graphId} = ${graphId}
|
|
1579
|
-
AND ${edges.id} IN (${drizzleOrm.sql.join(
|
|
1580
|
-
ids.map((id) => drizzleOrm.sql`${id}`),
|
|
1581
|
-
drizzleOrm.sql`, `
|
|
1582
|
-
)})
|
|
1583
|
-
`;
|
|
1584
|
-
}
|
|
1585
|
-
function expectedIdentityPredicate(tables, expected) {
|
|
1586
|
-
const { edges } = tables;
|
|
1587
|
-
const parts = [
|
|
1588
|
-
expected.kind === void 0 ? void 0 : drizzleOrm.sql` AND ${edges.kind} = ${expected.kind}`,
|
|
1589
|
-
expected.fromKind === void 0 ? void 0 : drizzleOrm.sql` AND ${edges.fromKind} = ${expected.fromKind}`,
|
|
1590
|
-
expected.fromId === void 0 ? void 0 : drizzleOrm.sql` AND ${edges.fromId} = ${expected.fromId}`,
|
|
1591
|
-
expected.toKind === void 0 ? void 0 : drizzleOrm.sql` AND ${edges.toKind} = ${expected.toKind}`,
|
|
1592
|
-
expected.toId === void 0 ? void 0 : drizzleOrm.sql` AND ${edges.toId} = ${expected.toId}`
|
|
1593
|
-
].filter((part) => part !== void 0);
|
|
1594
|
-
return parts.length === 0 ? drizzleOrm.sql.empty() : drizzleOrm.sql.join(parts, drizzleOrm.sql``);
|
|
1595
|
-
}
|
|
1596
|
-
function buildUpdateEdge(tables, params, timestamp) {
|
|
1597
|
-
const { edges } = tables;
|
|
1598
|
-
const propsJson = JSON.stringify(params.props);
|
|
1599
|
-
const setParts = [
|
|
1600
|
-
drizzleOrm.sql`${quotedColumn(edges.props)} = ${propsJson}`,
|
|
1601
|
-
drizzleOrm.sql`${quotedColumn(edges.updatedAt)} = ${timestamp}`
|
|
1602
|
-
];
|
|
1603
|
-
if (params.clearDeleted && params.validFrom !== void 0) {
|
|
1604
|
-
setParts.push(
|
|
1605
|
-
drizzleOrm.sql`${quotedColumn(edges.validFrom)} = ${sqlNull(chunkTQHGE7UC_cjs.resolveStatedValidityLowerBound(params.validFrom))}`,
|
|
1606
|
-
drizzleOrm.sql`${quotedColumn(edges.validTo)} = ${sqlNull(params.validTo)}`
|
|
1607
|
-
);
|
|
1608
|
-
} else if (params.clearValidTo === true) {
|
|
1609
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(edges.validTo)} = NULL`);
|
|
1610
|
-
} else if (params.validTo !== void 0) {
|
|
1611
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(edges.validTo)} = ${params.validTo}`);
|
|
1612
|
-
}
|
|
1613
|
-
if (params.clearDeleted) {
|
|
1614
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(edges.deletedAt)} = NULL`);
|
|
1615
|
-
}
|
|
1616
|
-
const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
|
|
1617
|
-
const expectedIdentity = expectedIdentityPredicate(tables, params);
|
|
1618
|
-
const expectedValidFrom = expectedValidFromPredicate(
|
|
1619
|
-
edges.validFrom,
|
|
1620
|
-
params.expectedValidFrom
|
|
1621
|
-
);
|
|
1622
|
-
const expectedValidTo = expectedValidFromPredicate(
|
|
1623
|
-
edges.validTo,
|
|
1624
|
-
params.expectedValidTo
|
|
1625
|
-
);
|
|
1626
|
-
if (params.clearDeleted) {
|
|
1627
|
-
return drizzleOrm.sql`
|
|
1628
|
-
UPDATE ${edges}
|
|
1629
|
-
SET ${setClause}
|
|
1630
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1631
|
-
AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
|
|
1632
|
-
RETURNING *
|
|
1633
|
-
`;
|
|
1634
|
-
}
|
|
1635
|
-
return drizzleOrm.sql`
|
|
1636
|
-
UPDATE ${edges}
|
|
1637
|
-
SET ${setClause}
|
|
1638
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1639
|
-
AND ${edges.id} = ${params.id}${expectedIdentity}${expectedValidFrom}${expectedValidTo}
|
|
1640
|
-
AND ${edges.deletedAt} IS NULL
|
|
1641
|
-
RETURNING *
|
|
1642
|
-
`;
|
|
1643
|
-
}
|
|
1644
|
-
function buildDeleteEdge(tables, params, timestamp) {
|
|
1645
|
-
const { edges } = tables;
|
|
1646
|
-
return drizzleOrm.sql`
|
|
1647
|
-
UPDATE ${edges}
|
|
1648
|
-
SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
|
|
1649
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1650
|
-
AND ${edges.id} = ${params.id}${expectedIdentityPredicate(tables, params.kind === void 0 ? {} : { kind: params.kind })}
|
|
1651
|
-
AND ${edges.deletedAt} IS NULL
|
|
1652
|
-
`;
|
|
1653
|
-
}
|
|
1654
|
-
function buildDeleteEdgesBatch(tables, params, timestamp) {
|
|
1655
|
-
const { edges } = tables;
|
|
1656
|
-
return drizzleOrm.sql`
|
|
1657
|
-
UPDATE ${edges}
|
|
1658
|
-
SET ${quotedColumn(edges.deletedAt)} = ${timestamp}
|
|
1659
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1660
|
-
AND ${edges.id} IN (${drizzleOrm.sql.join(
|
|
1661
|
-
params.ids.map((id) => drizzleOrm.sql`${id}`),
|
|
1662
|
-
drizzleOrm.sql`, `
|
|
1663
|
-
)})
|
|
1664
|
-
AND ${edges.deletedAt} IS NULL
|
|
1665
|
-
`;
|
|
1666
|
-
}
|
|
1667
|
-
function buildHardDeleteEdgesBatch(tables, params) {
|
|
1668
|
-
const { edges } = tables;
|
|
1669
|
-
return drizzleOrm.sql`
|
|
1670
|
-
DELETE FROM ${edges}
|
|
1671
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1672
|
-
AND ${edges.id} IN (${drizzleOrm.sql.join(
|
|
1673
|
-
params.ids.map((id) => drizzleOrm.sql`${id}`),
|
|
1674
|
-
drizzleOrm.sql`, `
|
|
1675
|
-
)})
|
|
1676
|
-
`;
|
|
1677
|
-
}
|
|
1678
|
-
function buildHardDeleteEdge(tables, params) {
|
|
1679
|
-
const { edges } = tables;
|
|
1680
|
-
return drizzleOrm.sql`
|
|
1681
|
-
DELETE FROM ${edges}
|
|
1682
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1683
|
-
AND ${edges.id} = ${params.id}${expectedIdentityPredicate(tables, params.kind === void 0 ? {} : { kind: params.kind })}
|
|
1684
|
-
`;
|
|
1685
|
-
}
|
|
1686
|
-
function buildHardDeleteEdgesByNode(tables, graphId, nodeKind, nodeId) {
|
|
1687
|
-
const { edges } = tables;
|
|
1688
|
-
return drizzleOrm.sql`
|
|
1689
|
-
DELETE FROM ${edges}
|
|
1690
|
-
WHERE ${edges.graphId} = ${graphId}
|
|
1691
|
-
AND (
|
|
1692
|
-
(${edges.fromKind} = ${nodeKind} AND ${edges.fromId} = ${nodeId})
|
|
1693
|
-
OR (${edges.toKind} = ${nodeKind} AND ${edges.toId} = ${nodeId})
|
|
1694
|
-
)
|
|
1695
|
-
`;
|
|
1696
|
-
}
|
|
1697
|
-
function buildCountEdgesFrom(tables, params) {
|
|
1698
|
-
const { edges } = tables;
|
|
1699
|
-
if (params.activeOnly) {
|
|
1700
|
-
return drizzleOrm.sql`
|
|
1701
|
-
SELECT COUNT(*) as count FROM ${edges}
|
|
1702
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1703
|
-
AND ${edges.kind} = ${params.edgeKind}
|
|
1704
|
-
AND ${edges.fromKind} = ${params.fromKind}
|
|
1705
|
-
AND ${edges.fromId} = ${params.fromId}
|
|
1706
|
-
AND ${edges.deletedAt} IS NULL
|
|
1707
|
-
AND ${edges.validTo} IS NULL
|
|
1708
|
-
`;
|
|
1709
|
-
}
|
|
1710
|
-
return drizzleOrm.sql`
|
|
1711
|
-
SELECT COUNT(*) as count FROM ${edges}
|
|
1712
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1713
|
-
AND ${edges.kind} = ${params.edgeKind}
|
|
1714
|
-
AND ${edges.fromKind} = ${params.fromKind}
|
|
1715
|
-
AND ${edges.fromId} = ${params.fromId}
|
|
1716
|
-
AND ${edges.deletedAt} IS NULL
|
|
1717
|
-
`;
|
|
1718
|
-
}
|
|
1719
|
-
function buildEdgeExistsBetween(tables, params) {
|
|
1720
|
-
const { edges } = tables;
|
|
1721
|
-
return drizzleOrm.sql`
|
|
1722
|
-
SELECT 1 FROM ${edges}
|
|
1723
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1724
|
-
AND ${edges.kind} = ${params.edgeKind}
|
|
1725
|
-
AND ${edges.fromKind} = ${params.fromKind}
|
|
1726
|
-
AND ${edges.fromId} = ${params.fromId}
|
|
1727
|
-
AND ${edges.toKind} = ${params.toKind}
|
|
1728
|
-
AND ${edges.toId} = ${params.toId}
|
|
1729
|
-
AND ${edges.deletedAt} IS NULL
|
|
1730
|
-
LIMIT 1
|
|
1731
|
-
`;
|
|
1732
|
-
}
|
|
1733
|
-
function buildFindEdgesConnectedTo(tables, params) {
|
|
1734
|
-
const { edges } = tables;
|
|
1735
|
-
return drizzleOrm.sql`
|
|
1736
|
-
SELECT * FROM ${edges}
|
|
1737
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1738
|
-
AND ${edges.deletedAt} IS NULL
|
|
1739
|
-
AND ${edges.fromKind} = ${params.nodeKind}
|
|
1740
|
-
AND ${edges.fromId} = ${params.nodeId}
|
|
1741
|
-
UNION ALL
|
|
1742
|
-
SELECT * FROM ${edges}
|
|
1743
|
-
WHERE ${edges.graphId} = ${params.graphId}
|
|
1744
|
-
AND ${edges.deletedAt} IS NULL
|
|
1745
|
-
AND ${edges.toKind} = ${params.nodeKind}
|
|
1746
|
-
AND ${edges.toId} = ${params.nodeId}
|
|
1747
|
-
AND NOT (
|
|
1748
|
-
${edges.fromKind} = ${params.nodeKind}
|
|
1749
|
-
AND ${edges.fromId} = ${params.nodeId}
|
|
1750
|
-
)
|
|
1751
|
-
`;
|
|
1752
|
-
}
|
|
1753
|
-
function resolveMode(mode) {
|
|
1754
|
-
return mode ?? "websearch";
|
|
1755
|
-
}
|
|
1756
|
-
function buildFulltextSearch(tableName, params, strategy, dialect, candidates) {
|
|
1757
|
-
assertValidSearchParams(params);
|
|
1758
|
-
const mode = resolveMode(params.mode);
|
|
1759
|
-
const table = quotedTableName(tableName);
|
|
1760
|
-
const matchCondition = chunkWODMN3Q2_cjs.toDrizzleSql(
|
|
1761
|
-
strategy.matchCondition(tableName, params.query, mode, params.language),
|
|
1762
|
-
dialect
|
|
1763
|
-
);
|
|
1764
|
-
const rankExpression = chunkWODMN3Q2_cjs.toDrizzleSql(
|
|
1765
|
-
strategy.rankExpression(tableName, params.query, mode, params.language),
|
|
1766
|
-
dialect
|
|
1767
|
-
);
|
|
1768
|
-
const conditions = [
|
|
1769
|
-
matchCondition,
|
|
1770
|
-
drizzleOrm.sql`"graph_id" = ${params.graphId}`,
|
|
1771
|
-
drizzleOrm.sql`"node_kind" = ${params.nodeKind}`
|
|
1772
|
-
];
|
|
1773
|
-
if (params.minScore !== void 0) {
|
|
1774
|
-
conditions.push(drizzleOrm.sql`${rankExpression} >= ${params.minScore}`);
|
|
1775
|
-
}
|
|
1776
|
-
if (candidates !== void 0) {
|
|
1777
|
-
const candidateSql = chunkEDN4Y4ZG_cjs.isSqlFragment(candidates) ? chunkWODMN3Q2_cjs.toDrizzleSql(candidates, dialect) : candidates;
|
|
1778
|
-
conditions.push(drizzleOrm.sql`"node_id" IN (${candidateSql})`);
|
|
1779
|
-
}
|
|
1780
|
-
const snippetExpr = params.includeSnippets === true && strategy.supportsSnippets ? chunkWODMN3Q2_cjs.toDrizzleSql(
|
|
1781
|
-
strategy.snippetExpression(
|
|
1782
|
-
tableName,
|
|
1783
|
-
params.query,
|
|
1784
|
-
mode,
|
|
1785
|
-
params.language
|
|
1786
|
-
),
|
|
1787
|
-
dialect
|
|
1788
|
-
) : drizzleOrm.sql`NULL`;
|
|
1789
|
-
const pageClause = params.offset === void 0 || params.offset === 0 ? drizzleOrm.sql`LIMIT ${params.limit}` : drizzleOrm.sql`LIMIT ${params.limit} OFFSET ${params.offset}`;
|
|
1790
|
-
return drizzleOrm.sql`
|
|
1791
|
-
SELECT
|
|
1792
|
-
"node_id" AS node_id,
|
|
1793
|
-
${rankExpression} AS score,
|
|
1794
|
-
${snippetExpr} AS snippet
|
|
1795
|
-
FROM ${table}
|
|
1796
|
-
WHERE ${drizzleOrm.sql.join(conditions, drizzleOrm.sql` AND `)}
|
|
1797
|
-
ORDER BY ${rankExpression} DESC, ${codePointOrderKey(drizzleOrm.sql.raw('"node_id"'), dialect)} ASC
|
|
1798
|
-
${pageClause}
|
|
1799
|
-
`;
|
|
1800
|
-
}
|
|
1801
|
-
function assertValidSearchParams(params) {
|
|
1802
|
-
if (!Number.isInteger(params.limit) || params.limit <= 0) {
|
|
1803
|
-
throw new Error(`limit must be a positive integer, got: ${params.limit}`);
|
|
1804
|
-
}
|
|
1805
|
-
if (params.minScore !== void 0 && !Number.isFinite(params.minScore)) {
|
|
1806
|
-
throw new TypeError(
|
|
1807
|
-
`minScore must be a finite number, got: ${params.minScore}`
|
|
1808
|
-
);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
function buildInsertNode(tables, params, timestamp) {
|
|
1812
|
-
const { nodes } = tables;
|
|
1813
|
-
const propsJson = JSON.stringify(params.props);
|
|
1814
|
-
const columns = nodeColumnList(nodes);
|
|
1815
|
-
return drizzleOrm.sql`
|
|
1816
|
-
INSERT INTO ${nodes} (${columns})
|
|
1817
|
-
VALUES (
|
|
1818
|
-
${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
|
|
1819
|
-
1, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
|
|
1820
|
-
${timestamp}, ${timestamp}
|
|
1821
|
-
)
|
|
1822
|
-
RETURNING *
|
|
1823
|
-
`;
|
|
1824
|
-
}
|
|
1825
|
-
function buildInsertNodeNoReturn(tables, params, timestamp) {
|
|
1826
|
-
const { nodes } = tables;
|
|
1827
|
-
const propsJson = JSON.stringify(params.props);
|
|
1828
|
-
const columns = nodeColumnList(nodes);
|
|
1829
|
-
return drizzleOrm.sql`
|
|
1830
|
-
INSERT INTO ${nodes} (${columns})
|
|
1831
|
-
VALUES (
|
|
1832
|
-
${params.graphId}, ${params.kind}, ${params.id}, ${propsJson},
|
|
1833
|
-
1, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}, ${sqlNull(params.validTo)},
|
|
1834
|
-
${timestamp}, ${timestamp}
|
|
1835
|
-
)
|
|
1836
|
-
`;
|
|
1837
|
-
}
|
|
1838
|
-
function buildInsertNodesBatch(tables, params, timestamp) {
|
|
1839
|
-
const { nodes } = tables;
|
|
1840
|
-
const columns = nodeColumnList(nodes);
|
|
1841
|
-
const values = params.map((nodeParams) => {
|
|
1842
|
-
const propsJson = JSON.stringify(nodeParams.props);
|
|
1843
|
-
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp))}, ${sqlNull(nodeParams.validTo)}, ${timestamp}, ${timestamp})`;
|
|
1844
|
-
});
|
|
1845
|
-
return drizzleOrm.sql`
|
|
1846
|
-
INSERT INTO ${nodes} (${columns})
|
|
1847
|
-
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1848
|
-
`;
|
|
1849
|
-
}
|
|
1850
|
-
function buildInsertNodesBatchReturning(tables, params, timestamp) {
|
|
1851
|
-
const { nodes } = tables;
|
|
1852
|
-
const columns = nodeColumnList(nodes);
|
|
1853
|
-
const values = params.map((nodeParams) => {
|
|
1854
|
-
const propsJson = JSON.stringify(nodeParams.props);
|
|
1855
|
-
return drizzleOrm.sql`(${nodeParams.graphId}, ${nodeParams.kind}, ${nodeParams.id}, ${propsJson}, 1, ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(nodeParams.validFrom, nodeParams.validTo, timestamp))}, ${sqlNull(nodeParams.validTo)}, ${timestamp}, ${timestamp})`;
|
|
1856
|
-
});
|
|
1857
|
-
return drizzleOrm.sql`
|
|
1858
|
-
INSERT INTO ${nodes} (${columns})
|
|
1859
|
-
VALUES ${drizzleOrm.sql.join(values, drizzleOrm.sql`, `)}
|
|
1860
|
-
RETURNING *
|
|
1861
|
-
`;
|
|
1862
|
-
}
|
|
1863
|
-
function buildGetNode(tables, graphId, kind, id) {
|
|
1864
|
-
const { nodes } = tables;
|
|
1865
|
-
return drizzleOrm.sql`
|
|
1866
|
-
SELECT * FROM ${nodes}
|
|
1867
|
-
WHERE ${nodes.graphId} = ${graphId}
|
|
1868
|
-
AND ${nodes.kind} = ${kind}
|
|
1869
|
-
AND ${nodes.id} = ${id}
|
|
1870
|
-
`;
|
|
1871
|
-
}
|
|
1872
|
-
function buildGetNodes(tables, graphId, kind, ids) {
|
|
1873
|
-
const { nodes } = tables;
|
|
1874
|
-
return drizzleOrm.sql`
|
|
1875
|
-
SELECT * FROM ${nodes}
|
|
1876
|
-
WHERE ${nodes.graphId} = ${graphId}
|
|
1877
|
-
AND ${nodes.kind} = ${kind}
|
|
1878
|
-
AND ${nodes.id} IN (${drizzleOrm.sql.join(
|
|
1879
|
-
ids.map((id) => drizzleOrm.sql`${id}`),
|
|
1880
|
-
drizzleOrm.sql`, `
|
|
1881
|
-
)})
|
|
1882
|
-
`;
|
|
1883
|
-
}
|
|
1884
|
-
function buildUpdateNode(tables, params, timestamp) {
|
|
1885
|
-
const { nodes } = tables;
|
|
1886
|
-
const propsJson = JSON.stringify(params.props);
|
|
1887
|
-
const setParts = [
|
|
1888
|
-
drizzleOrm.sql`${quotedColumn(nodes.props)} = ${propsJson}`,
|
|
1889
|
-
drizzleOrm.sql`${quotedColumn(nodes.updatedAt)} = ${timestamp}`
|
|
1890
|
-
];
|
|
1891
|
-
if (params.incrementVersion) {
|
|
1892
|
-
setParts.push(
|
|
1893
|
-
drizzleOrm.sql`${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1`
|
|
1894
|
-
);
|
|
1895
|
-
}
|
|
1896
|
-
if (params.clearDeleted) {
|
|
1897
|
-
setParts.push(
|
|
1898
|
-
drizzleOrm.sql`${quotedColumn(nodes.validFrom)} = ${sqlNull(chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(params.validFrom, params.validTo, timestamp))}`,
|
|
1899
|
-
drizzleOrm.sql`${quotedColumn(nodes.validTo)} = ${sqlNull(params.validTo)}`
|
|
1900
|
-
);
|
|
1901
|
-
} else if (params.clearValidTo === true) {
|
|
1902
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(nodes.validTo)} = NULL`);
|
|
1903
|
-
} else if (params.validTo !== void 0) {
|
|
1904
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(nodes.validTo)} = ${params.validTo}`);
|
|
1905
|
-
}
|
|
1906
|
-
if (params.clearDeleted) {
|
|
1907
|
-
setParts.push(drizzleOrm.sql`${quotedColumn(nodes.deletedAt)} = NULL`);
|
|
1908
|
-
}
|
|
1909
|
-
const setClause = drizzleOrm.sql.join(setParts, drizzleOrm.sql`, `);
|
|
1910
|
-
const expectedValidFrom = expectedValidFromPredicate(
|
|
1911
|
-
nodes.validFrom,
|
|
1912
|
-
params.expectedValidFrom
|
|
1913
|
-
);
|
|
1914
|
-
if (params.clearDeleted) {
|
|
1915
|
-
return drizzleOrm.sql`
|
|
1916
|
-
UPDATE ${nodes}
|
|
1917
|
-
SET ${setClause}
|
|
1918
|
-
WHERE ${nodes.graphId} = ${params.graphId}
|
|
1919
|
-
AND ${nodes.kind} = ${params.kind}
|
|
1920
|
-
AND ${nodes.id} = ${params.id}${expectedValidFrom}
|
|
1921
|
-
AND ${nodes.deletedAt} IS NOT NULL
|
|
1922
|
-
RETURNING *
|
|
1923
|
-
`;
|
|
1924
|
-
}
|
|
1925
|
-
return drizzleOrm.sql`
|
|
1926
|
-
UPDATE ${nodes}
|
|
1927
|
-
SET ${setClause}
|
|
1928
|
-
WHERE ${nodes.graphId} = ${params.graphId}
|
|
1929
|
-
AND ${nodes.kind} = ${params.kind}
|
|
1930
|
-
AND ${nodes.id} = ${params.id}${expectedValidFrom}
|
|
1931
|
-
AND ${nodes.deletedAt} IS NULL
|
|
1932
|
-
RETURNING *
|
|
1933
|
-
`;
|
|
1934
|
-
}
|
|
1935
|
-
function buildUpdateNodeSet(tables, dialect, params, timestamp) {
|
|
1936
|
-
const { nodes } = tables;
|
|
1937
|
-
const adapter = chunkL3LQNR34_cjs.getDialect(dialect);
|
|
1938
|
-
const patchedProps = chunkWODMN3Q2_cjs.toDrizzleSql(
|
|
1939
|
-
adapter.jsonSetProperties(
|
|
1940
|
-
chunkEDN4Y4ZG_cjs.sql.identifier(nodes.props.name),
|
|
1941
|
-
params.patch,
|
|
1942
|
-
params.unsetProperties ?? []
|
|
1943
|
-
),
|
|
1944
|
-
dialect
|
|
1945
|
-
);
|
|
1946
|
-
const candidateIds = chunkWODMN3Q2_cjs.toDrizzleSql(params.candidateIds, dialect);
|
|
1947
|
-
const candidateIdColumn = chunkWODMN3Q2_cjs.toDrizzleSql(
|
|
1948
|
-
chunkEDN4Y4ZG_cjs.sql.identifier(params.candidateIdColumn),
|
|
1949
|
-
dialect
|
|
1950
|
-
);
|
|
1951
|
-
return drizzleOrm.sql`
|
|
1952
|
-
UPDATE ${nodes}
|
|
1953
|
-
SET ${quotedColumn(nodes.props)} = ${patchedProps},
|
|
1954
|
-
${quotedColumn(nodes.updatedAt)} = ${timestamp},
|
|
1955
|
-
${quotedColumn(nodes.version)} = ${quotedColumn(nodes.version)} + 1
|
|
1956
|
-
WHERE ${nodes.graphId} = ${params.graphId}
|
|
1957
|
-
AND ${nodes.kind} = ${params.kind}
|
|
1958
|
-
AND ${nodes.deletedAt} IS NULL
|
|
1959
|
-
AND ${nodes.id} IN (
|
|
1960
|
-
SELECT ${candidateIdColumn}
|
|
1961
|
-
FROM (${candidateIds}) AS tg_set_candidates
|
|
1962
|
-
)
|
|
1963
|
-
RETURNING *
|
|
1964
|
-
`;
|
|
1965
|
-
}
|
|
1966
|
-
function buildDeleteNode(tables, params, timestamp) {
|
|
1967
|
-
const { nodes } = tables;
|
|
1968
|
-
return drizzleOrm.sql`
|
|
1969
|
-
UPDATE ${nodes}
|
|
1970
|
-
SET ${quotedColumn(nodes.deletedAt)} = ${timestamp}
|
|
1971
|
-
WHERE ${nodes.graphId} = ${params.graphId}
|
|
1972
|
-
AND ${nodes.kind} = ${params.kind}
|
|
1973
|
-
AND ${nodes.id} = ${params.id}
|
|
1974
|
-
AND ${nodes.deletedAt} IS NULL
|
|
1975
|
-
`;
|
|
1976
|
-
}
|
|
1977
|
-
function buildHardDeleteNode(tables, params) {
|
|
1978
|
-
const { nodes } = tables;
|
|
1979
|
-
return drizzleOrm.sql`
|
|
1980
|
-
DELETE FROM ${nodes}
|
|
1981
|
-
WHERE ${nodes.graphId} = ${params.graphId}
|
|
1982
|
-
AND ${nodes.kind} = ${params.kind}
|
|
1983
|
-
AND ${nodes.id} = ${params.id}
|
|
1984
|
-
`;
|
|
1985
|
-
}
|
|
1986
|
-
function createSchemaDialectStrategy(dialect) {
|
|
1987
|
-
const literals = {
|
|
1988
|
-
postgres: { false: "FALSE", true: "TRUE" },
|
|
1989
|
-
sqlite: { false: "0", true: "1" }
|
|
1990
|
-
};
|
|
1991
|
-
const dialectLiterals = literals[dialect];
|
|
1992
|
-
const trueLiteral = drizzleOrm.sql.raw(dialectLiterals.true);
|
|
1993
|
-
const falseLiteral = drizzleOrm.sql.raw(dialectLiterals.false);
|
|
1994
|
-
return {
|
|
1995
|
-
booleanLiteral(value) {
|
|
1996
|
-
return value ? trueLiteral : falseLiteral;
|
|
1997
|
-
}
|
|
1998
|
-
};
|
|
1999
|
-
}
|
|
2000
|
-
var SCHEMA_DIALECT_STRATEGIES = {
|
|
2001
|
-
postgres: createSchemaDialectStrategy("postgres"),
|
|
2002
|
-
sqlite: createSchemaDialectStrategy("sqlite")
|
|
2003
|
-
};
|
|
2004
|
-
function buildInsertSchema(tables, params, timestamp, dialect = "sqlite") {
|
|
2005
|
-
const { schemaVersions } = tables;
|
|
2006
|
-
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2007
|
-
const schemaDocumentJson = JSON.stringify(params.schemaDoc);
|
|
2008
|
-
const isActiveValue = strategy.booleanLiteral(params.isActive);
|
|
2009
|
-
const columns = drizzleOrm.sql.raw(
|
|
2010
|
-
`"${schemaVersions.graphId.name}", "${schemaVersions.version.name}", "${schemaVersions.schemaHash.name}", "${schemaVersions.schemaDoc.name}", "${schemaVersions.createdAt.name}", "${schemaVersions.isActive.name}"`
|
|
2011
|
-
);
|
|
2012
|
-
return drizzleOrm.sql`
|
|
2013
|
-
INSERT INTO ${schemaVersions} (${columns})
|
|
2014
|
-
VALUES (
|
|
2015
|
-
${params.graphId}, ${params.version},
|
|
2016
|
-
${params.schemaHash}, ${schemaDocumentJson},
|
|
2017
|
-
${timestamp}, ${isActiveValue}
|
|
2018
|
-
)
|
|
2019
|
-
RETURNING *
|
|
2020
|
-
`;
|
|
2021
|
-
}
|
|
2022
|
-
function buildGetActiveSchema(tables, graphId, dialect = "sqlite") {
|
|
2023
|
-
const { schemaVersions } = tables;
|
|
2024
|
-
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2025
|
-
return drizzleOrm.sql`
|
|
2026
|
-
SELECT * FROM ${schemaVersions}
|
|
2027
|
-
WHERE ${schemaVersions.graphId} = ${graphId}
|
|
2028
|
-
AND ${schemaVersions.isActive} = ${strategy.booleanLiteral(true)}
|
|
2029
|
-
`;
|
|
2030
|
-
}
|
|
2031
|
-
function buildGetSchemaVersion(tables, graphId, version) {
|
|
2032
|
-
const { schemaVersions } = tables;
|
|
2033
|
-
return drizzleOrm.sql`
|
|
2034
|
-
SELECT * FROM ${schemaVersions}
|
|
2035
|
-
WHERE ${schemaVersions.graphId} = ${graphId}
|
|
2036
|
-
AND ${schemaVersions.version} = ${version}
|
|
2037
|
-
`;
|
|
2038
|
-
}
|
|
2039
|
-
function buildSetActiveSchema(tables, graphId, version, dialect = "sqlite") {
|
|
2040
|
-
const { schemaVersions } = tables;
|
|
2041
|
-
const strategy = SCHEMA_DIALECT_STRATEGIES[dialect];
|
|
2042
|
-
const deactivateAll = drizzleOrm.sql`
|
|
2043
|
-
UPDATE ${schemaVersions}
|
|
2044
|
-
SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(false)}
|
|
2045
|
-
WHERE ${schemaVersions.graphId} = ${graphId}
|
|
2046
|
-
`;
|
|
2047
|
-
const activateVersion = drizzleOrm.sql`
|
|
2048
|
-
UPDATE ${schemaVersions}
|
|
2049
|
-
SET ${quotedColumn(schemaVersions.isActive)} = ${strategy.booleanLiteral(true)}
|
|
2050
|
-
WHERE ${schemaVersions.graphId} = ${graphId}
|
|
2051
|
-
AND ${schemaVersions.version} = ${version}
|
|
2052
|
-
`;
|
|
2053
|
-
return { deactivateAll, activateVersion };
|
|
2054
|
-
}
|
|
2055
|
-
function buildInsertUniqueSqlite(tables, params) {
|
|
2056
|
-
const { uniques } = tables;
|
|
2057
|
-
const columns = drizzleOrm.sql.raw(
|
|
2058
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
|
|
2059
|
-
);
|
|
2060
|
-
const conflictColumns = drizzleOrm.sql.raw(
|
|
2061
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
|
|
2062
|
-
);
|
|
2063
|
-
return drizzleOrm.sql`
|
|
2064
|
-
INSERT INTO ${uniques} (${columns})
|
|
2065
|
-
VALUES (
|
|
2066
|
-
${params.graphId}, ${params.nodeKind}, ${params.constraintName},
|
|
2067
|
-
${params.key}, ${params.nodeId}, ${params.concreteKind}, ${drizzleOrm.sql.raw("NULL")}
|
|
2068
|
-
)
|
|
2069
|
-
ON CONFLICT (${conflictColumns})
|
|
2070
|
-
DO UPDATE SET
|
|
2071
|
-
${quotedColumn(uniques.nodeId)} = CASE
|
|
2072
|
-
WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
|
|
2073
|
-
WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.nodeId}
|
|
2074
|
-
ELSE ${quotedColumn(uniques.nodeId)}
|
|
2075
|
-
END,
|
|
2076
|
-
${quotedColumn(uniques.concreteKind)} = CASE
|
|
2077
|
-
WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
|
|
2078
|
-
WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
|
|
2079
|
-
ELSE ${quotedColumn(uniques.concreteKind)}
|
|
2080
|
-
END,
|
|
2081
|
-
${quotedColumn(uniques.deletedAt)} = CASE
|
|
2082
|
-
WHEN ${quotedColumn(uniques.nodeId)} = ${params.nodeId} THEN NULL
|
|
2083
|
-
WHEN ${quotedColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
|
|
2084
|
-
ELSE ${quotedColumn(uniques.deletedAt)}
|
|
2085
|
-
END
|
|
2086
|
-
RETURNING ${quotedColumn(uniques.nodeId)} as node_id
|
|
2087
|
-
`;
|
|
2088
|
-
}
|
|
2089
|
-
function buildInsertUniquePostgres(tables, params) {
|
|
2090
|
-
const { uniques } = tables;
|
|
2091
|
-
const columns = drizzleOrm.sql.raw(
|
|
2092
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
|
|
2093
|
-
);
|
|
2094
|
-
const conflictColumns = drizzleOrm.sql.raw(
|
|
2095
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
|
|
2096
|
-
);
|
|
2097
|
-
const tableName = drizzleOrm.getTableName(uniques);
|
|
2098
|
-
const existingColumn = (column) => drizzleOrm.sql.raw(`"${tableName}"."${column.name}"`);
|
|
2099
|
-
return drizzleOrm.sql`
|
|
2100
|
-
INSERT INTO ${uniques} (${columns})
|
|
2101
|
-
VALUES (
|
|
2102
|
-
${params.graphId}, ${params.nodeKind}, ${params.constraintName},
|
|
2103
|
-
${params.key}, ${params.nodeId}, ${params.concreteKind}, ${drizzleOrm.sql.raw("NULL")}
|
|
2104
|
-
)
|
|
2105
|
-
ON CONFLICT (${conflictColumns})
|
|
2106
|
-
DO UPDATE SET
|
|
2107
|
-
${quotedColumn(uniques.nodeId)} = CASE
|
|
2108
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.nodeId}
|
|
2109
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.nodeId}
|
|
2110
|
-
ELSE ${existingColumn(uniques.nodeId)}
|
|
2111
|
-
END,
|
|
2112
|
-
${quotedColumn(uniques.concreteKind)} = CASE
|
|
2113
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN ${params.concreteKind}
|
|
2114
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${params.concreteKind}
|
|
2115
|
-
ELSE ${existingColumn(uniques.concreteKind)}
|
|
2116
|
-
END,
|
|
2117
|
-
${quotedColumn(uniques.deletedAt)} = CASE
|
|
2118
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${params.nodeId} THEN NULL
|
|
2119
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
|
|
2120
|
-
ELSE ${existingColumn(uniques.deletedAt)}
|
|
2121
|
-
END
|
|
2122
|
-
RETURNING ${quotedColumn(uniques.nodeId)} as node_id
|
|
2123
|
-
`;
|
|
2124
|
-
}
|
|
2125
|
-
var UNIQUE_INSERT_BUILDERS = {
|
|
2126
|
-
postgres: buildInsertUniquePostgres,
|
|
2127
|
-
sqlite: buildInsertUniqueSqlite
|
|
2128
|
-
};
|
|
2129
|
-
function buildInsertUnique(tables, dialect, params) {
|
|
2130
|
-
const builder = UNIQUE_INSERT_BUILDERS[dialect];
|
|
2131
|
-
return builder(tables, params);
|
|
2132
|
-
}
|
|
2133
|
-
function buildInsertUniqueBatch(tables, dialect, entries) {
|
|
2134
|
-
const { uniques } = tables;
|
|
2135
|
-
const columns = drizzleOrm.sql.raw(
|
|
2136
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}", "${uniques.nodeId.name}", "${uniques.concreteKind.name}", "${uniques.deletedAt.name}"`
|
|
2137
|
-
);
|
|
2138
|
-
const conflictColumns = drizzleOrm.sql.raw(
|
|
2139
|
-
`"${uniques.graphId.name}", "${uniques.nodeKind.name}", "${uniques.constraintName.name}", "${uniques.key.name}"`
|
|
2140
|
-
);
|
|
2141
|
-
const tableName = drizzleOrm.getTableName(uniques);
|
|
2142
|
-
const existingColumn = (column) => {
|
|
2143
|
-
switch (dialect) {
|
|
2144
|
-
case "postgres": {
|
|
2145
|
-
return drizzleOrm.sql.raw(`"${tableName}"."${column.name}"`);
|
|
2146
|
-
}
|
|
2147
|
-
case "sqlite": {
|
|
2148
|
-
return drizzleOrm.sql.raw(`"${column.name}"`);
|
|
2149
|
-
}
|
|
2150
|
-
default: {
|
|
2151
|
-
return dialect;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
};
|
|
2155
|
-
const excludedColumn = (column) => drizzleOrm.sql.raw(`excluded."${column.name}"`);
|
|
2156
|
-
const valueRows = drizzleOrm.sql.join(
|
|
2157
|
-
entries.map(
|
|
2158
|
-
(params) => drizzleOrm.sql`(${params.graphId}, ${params.nodeKind}, ${params.constraintName}, ${params.key}, ${params.nodeId}, ${params.concreteKind}, ${drizzleOrm.sql.raw("NULL")})`
|
|
2159
|
-
),
|
|
2160
|
-
drizzleOrm.sql`, `
|
|
2161
|
-
);
|
|
2162
|
-
return drizzleOrm.sql`
|
|
2163
|
-
INSERT INTO ${uniques} (${columns})
|
|
2164
|
-
VALUES ${valueRows}
|
|
2165
|
-
ON CONFLICT (${conflictColumns})
|
|
2166
|
-
DO UPDATE SET
|
|
2167
|
-
${quotedColumn(uniques.nodeId)} = CASE
|
|
2168
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN ${excludedColumn(uniques.nodeId)}
|
|
2169
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques.nodeId)}
|
|
2170
|
-
ELSE ${existingColumn(uniques.nodeId)}
|
|
2171
|
-
END,
|
|
2172
|
-
${quotedColumn(uniques.concreteKind)} = CASE
|
|
2173
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN ${excludedColumn(uniques.concreteKind)}
|
|
2174
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN ${excludedColumn(uniques.concreteKind)}
|
|
2175
|
-
ELSE ${existingColumn(uniques.concreteKind)}
|
|
2176
|
-
END,
|
|
2177
|
-
${quotedColumn(uniques.deletedAt)} = CASE
|
|
2178
|
-
WHEN ${existingColumn(uniques.nodeId)} = ${excludedColumn(uniques.nodeId)} THEN NULL
|
|
2179
|
-
WHEN ${existingColumn(uniques.deletedAt)} IS NOT NULL THEN NULL
|
|
2180
|
-
ELSE ${existingColumn(uniques.deletedAt)}
|
|
2181
|
-
END
|
|
2182
|
-
RETURNING
|
|
2183
|
-
${quotedColumn(uniques.nodeKind)} as node_kind,
|
|
2184
|
-
${quotedColumn(uniques.constraintName)} as constraint_name,
|
|
2185
|
-
${quotedColumn(uniques.key)} as key,
|
|
2186
|
-
${quotedColumn(uniques.nodeId)} as node_id
|
|
2187
|
-
`;
|
|
2188
|
-
}
|
|
2189
|
-
function buildDeleteUnique(tables, params, timestamp) {
|
|
2190
|
-
const { uniques } = tables;
|
|
2191
|
-
return drizzleOrm.sql`
|
|
2192
|
-
UPDATE ${uniques}
|
|
2193
|
-
SET ${quotedColumn(uniques.deletedAt)} = ${timestamp}
|
|
2194
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2195
|
-
AND ${uniques.nodeKind} = ${params.nodeKind}
|
|
2196
|
-
AND ${uniques.constraintName} = ${params.constraintName}
|
|
2197
|
-
AND ${uniques.key} = ${params.key}
|
|
2198
|
-
AND ${uniques.deletedAt} IS NULL
|
|
2199
|
-
`;
|
|
2200
|
-
}
|
|
2201
|
-
function buildHardDeleteUniquesByNode(tables, graphId, concreteKind, nodeId) {
|
|
2202
|
-
return buildHardDeleteUniquesByNodeIds(tables, {
|
|
2203
|
-
graphId,
|
|
2204
|
-
concreteKind,
|
|
2205
|
-
nodeIds: [nodeId]
|
|
2206
|
-
});
|
|
2207
|
-
}
|
|
2208
|
-
function buildHardDeleteUniquesByNodeIds(tables, params) {
|
|
2209
|
-
const { uniques } = tables;
|
|
2210
|
-
return drizzleOrm.sql`
|
|
2211
|
-
DELETE FROM ${uniques}
|
|
2212
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2213
|
-
AND ${uniques.concreteKind} = ${params.concreteKind}
|
|
2214
|
-
AND ${uniques.nodeId} IN (${drizzleOrm.sql.join(
|
|
2215
|
-
params.nodeIds.map((nodeId) => drizzleOrm.sql`${nodeId}`),
|
|
2216
|
-
drizzleOrm.sql`, `
|
|
2217
|
-
)})
|
|
2218
|
-
`;
|
|
2219
|
-
}
|
|
2220
|
-
function buildCheckUnique(tables, params) {
|
|
2221
|
-
const { uniques } = tables;
|
|
2222
|
-
if (params.includeDeleted) {
|
|
2223
|
-
return drizzleOrm.sql`
|
|
2224
|
-
SELECT * FROM ${uniques}
|
|
2225
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2226
|
-
AND ${uniques.nodeKind} = ${params.nodeKind}
|
|
2227
|
-
AND ${uniques.constraintName} = ${params.constraintName}
|
|
2228
|
-
AND ${uniques.key} = ${params.key}
|
|
2229
|
-
`;
|
|
2230
|
-
}
|
|
2231
|
-
return drizzleOrm.sql`
|
|
2232
|
-
SELECT * FROM ${uniques}
|
|
2233
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2234
|
-
AND ${uniques.nodeKind} = ${params.nodeKind}
|
|
2235
|
-
AND ${uniques.constraintName} = ${params.constraintName}
|
|
2236
|
-
AND ${uniques.key} = ${params.key}
|
|
2237
|
-
AND ${uniques.deletedAt} IS NULL
|
|
2238
|
-
`;
|
|
2239
|
-
}
|
|
2240
|
-
function buildCheckUniqueBatch(tables, params) {
|
|
2241
|
-
const { uniques } = tables;
|
|
2242
|
-
const keyPlaceholders = drizzleOrm.sql.join(
|
|
2243
|
-
params.keys.map((key) => drizzleOrm.sql`${key}`),
|
|
2244
|
-
drizzleOrm.sql`, `
|
|
2245
|
-
);
|
|
2246
|
-
if (params.includeDeleted) {
|
|
2247
|
-
return drizzleOrm.sql`
|
|
2248
|
-
SELECT * FROM ${uniques}
|
|
2249
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2250
|
-
AND ${uniques.nodeKind} = ${params.nodeKind}
|
|
2251
|
-
AND ${uniques.constraintName} = ${params.constraintName}
|
|
2252
|
-
AND ${uniques.key} IN (${keyPlaceholders})
|
|
2253
|
-
`;
|
|
2254
|
-
}
|
|
2255
|
-
return drizzleOrm.sql`
|
|
2256
|
-
SELECT * FROM ${uniques}
|
|
2257
|
-
WHERE ${uniques.graphId} = ${params.graphId}
|
|
2258
|
-
AND ${uniques.nodeKind} = ${params.nodeKind}
|
|
2259
|
-
AND ${uniques.constraintName} = ${params.constraintName}
|
|
2260
|
-
AND ${uniques.key} IN (${keyPlaceholders})
|
|
2261
|
-
AND ${uniques.deletedAt} IS NULL
|
|
2262
|
-
`;
|
|
2263
|
-
}
|
|
2264
|
-
|
|
2265
|
-
// src/backend/drizzle/operations/strategy.ts
|
|
2266
|
-
function nullableText(value) {
|
|
2267
|
-
return value === void 0 ? drizzleOrm.sql`NULL` : drizzleOrm.sql`${value}`;
|
|
2268
|
-
}
|
|
2269
|
-
function bindTableOperationBuilders(tables, builders) {
|
|
2270
|
-
const boundEntries = Object.entries(builders).map(([name, builder]) => {
|
|
2271
|
-
function boundBuilder(...args) {
|
|
2272
|
-
return builder(tables, ...args);
|
|
2273
|
-
}
|
|
2274
|
-
return [name, boundBuilder];
|
|
2275
|
-
});
|
|
2276
|
-
return Object.fromEntries(
|
|
2277
|
-
boundEntries
|
|
2278
|
-
);
|
|
2279
|
-
}
|
|
2280
|
-
var COMMON_TABLE_OPERATION_BUILDERS = {
|
|
2281
|
-
buildInsertNode,
|
|
2282
|
-
buildInsertNodeNoReturn,
|
|
2283
|
-
buildInsertNodesBatch,
|
|
2284
|
-
buildInsertNodesBatchReturning,
|
|
2285
|
-
buildGetNode,
|
|
2286
|
-
buildGetNodes,
|
|
2287
|
-
buildUpdateNode,
|
|
2288
|
-
buildDeleteNode,
|
|
2289
|
-
buildHardDeleteNode,
|
|
2290
|
-
buildInsertEdge,
|
|
2291
|
-
buildInsertEdgeNoReturn,
|
|
2292
|
-
buildInsertEdgesBatch,
|
|
2293
|
-
buildInsertEdgesBatchReturning,
|
|
2294
|
-
buildGetEdge,
|
|
2295
|
-
buildGetEdges,
|
|
2296
|
-
buildUpdateEdge,
|
|
2297
|
-
buildDeleteEdge,
|
|
2298
|
-
buildDeleteEdgesBatch,
|
|
2299
|
-
buildHardDeleteEdge,
|
|
2300
|
-
buildHardDeleteEdgesBatch,
|
|
2301
|
-
buildHardDeleteEdgesByNode,
|
|
2302
|
-
buildCountEdgesFrom,
|
|
2303
|
-
buildEdgeExistsBetween,
|
|
2304
|
-
buildFindEdgesConnectedTo,
|
|
2305
|
-
buildFindNodesByKind,
|
|
2306
|
-
buildCountNodesByKind,
|
|
2307
|
-
buildFindEdgesByKind,
|
|
2308
|
-
buildFindEdgesByEndpointSet,
|
|
2309
|
-
buildFindEdgesByHeterogeneousEndpointSet,
|
|
2310
|
-
buildCountEdgesByKind,
|
|
2311
|
-
buildDeleteUnique,
|
|
2312
|
-
buildHardDeleteUniquesByNode,
|
|
2313
|
-
buildHardDeleteUniquesByNodeIds,
|
|
2314
|
-
buildCheckUnique,
|
|
2315
|
-
buildCheckUniqueBatch,
|
|
2316
|
-
buildGetSchemaVersion
|
|
2317
|
-
};
|
|
2318
|
-
function createCommonOperationStrategy(tables, dialect, fulltextStrategy) {
|
|
2319
|
-
const tableOperations = bindTableOperationBuilders(
|
|
2320
|
-
tables,
|
|
2321
|
-
COMMON_TABLE_OPERATION_BUILDERS
|
|
2322
|
-
);
|
|
2323
|
-
const fulltextTable = tables.fulltextTableName;
|
|
2324
|
-
const contributionMaterializations = tables.contributionMaterializations;
|
|
2325
|
-
const fulltextBuilders = {
|
|
2326
|
-
buildUpsertFulltext: (params, timestamp) => fulltextStrategy.buildUpsert(fulltextTable, params, timestamp).map((statement) => chunkWODMN3Q2_cjs.toDrizzleSql(statement, dialect)),
|
|
2327
|
-
buildDeleteFulltext: (params) => fulltextStrategy.buildDelete(fulltextTable, params).map((statement) => chunkWODMN3Q2_cjs.toDrizzleSql(statement, dialect)),
|
|
2328
|
-
buildDeleteFulltextByNode: (graphId, nodeKind, nodeId) => fulltextStrategy.buildDelete(fulltextTable, {
|
|
2329
|
-
graphId,
|
|
2330
|
-
nodeKind,
|
|
2331
|
-
nodeId
|
|
2332
|
-
}).map((statement) => chunkWODMN3Q2_cjs.toDrizzleSql(statement, dialect)),
|
|
2333
|
-
buildUpsertFulltextBatch: (params, timestamp) => fulltextStrategy.buildBatchUpsert(fulltextTable, params, timestamp).map((statement) => chunkWODMN3Q2_cjs.toDrizzleSql(statement, dialect)),
|
|
2334
|
-
buildDeleteFulltextBatch: (params) => fulltextStrategy.buildBatchDelete(fulltextTable, params).map((statement) => chunkWODMN3Q2_cjs.toDrizzleSql(statement, dialect)),
|
|
2335
|
-
buildFulltextSearch: (params) => buildFulltextSearch(
|
|
2336
|
-
fulltextTable,
|
|
2337
|
-
params,
|
|
2338
|
-
fulltextStrategy,
|
|
2339
|
-
dialect,
|
|
2340
|
-
// Store-compiled candidates (predicates + subclass + currency)
|
|
2341
|
-
// take precedence; the live-node default covers direct backend use.
|
|
2342
|
-
params.candidates ?? liveNodeIdsSubquery(
|
|
2343
|
-
tables.nodes,
|
|
2344
|
-
params.graphId,
|
|
2345
|
-
params.nodeKind,
|
|
2346
|
-
chunkFA2AFWLP_cjs.nowIso()
|
|
2347
|
-
)
|
|
2348
|
-
),
|
|
2349
|
-
buildHybridSearch: (params, vectorSql, vectorScoreDescending) => {
|
|
2350
|
-
const candidates = params.candidates ?? liveNodeIdsSubquery(
|
|
2351
|
-
tables.nodes,
|
|
2352
|
-
params.graphId,
|
|
2353
|
-
params.nodeKind,
|
|
2354
|
-
chunkFA2AFWLP_cjs.nowIso()
|
|
2355
|
-
);
|
|
2356
|
-
const fulltextSql = buildFulltextSearch(
|
|
2357
|
-
fulltextTable,
|
|
2358
|
-
{
|
|
2359
|
-
graphId: params.graphId,
|
|
2360
|
-
nodeKind: params.nodeKind,
|
|
2361
|
-
query: params.fulltext.query,
|
|
2362
|
-
limit: params.fulltext.k,
|
|
2363
|
-
...params.fulltext.mode === void 0 ? {} : { mode: params.fulltext.mode },
|
|
2364
|
-
...params.fulltext.language === void 0 ? {} : { language: params.fulltext.language },
|
|
2365
|
-
...params.fulltext.minScore === void 0 ? {} : { minScore: params.fulltext.minScore },
|
|
2366
|
-
...params.fulltext.includeSnippets === void 0 ? {} : { includeSnippets: params.fulltext.includeSnippets }
|
|
2367
|
-
},
|
|
2368
|
-
fulltextStrategy,
|
|
2369
|
-
dialect,
|
|
2370
|
-
// Reference, not copy: the statement evaluates the shared
|
|
2371
|
-
// tg_hybrid_cand CTE once for both legs.
|
|
2372
|
-
hybridCandidatesRef()
|
|
2373
|
-
);
|
|
2374
|
-
return buildHybridSearchStatement({
|
|
2375
|
-
candidatesSql: chunkEDN4Y4ZG_cjs.isSqlFragment(candidates) ? chunkWODMN3Q2_cjs.toDrizzleSql(candidates, dialect) : candidates,
|
|
2376
|
-
vectorSql,
|
|
2377
|
-
vectorScoreDescending,
|
|
2378
|
-
fulltextSql,
|
|
2379
|
-
nodes: tables.nodes,
|
|
2380
|
-
dialect,
|
|
2381
|
-
graphId: params.graphId,
|
|
2382
|
-
nodeKind: params.nodeKind,
|
|
2383
|
-
fusionK: params.fusion.k,
|
|
2384
|
-
vectorWeight: params.fusion.vectorWeight,
|
|
2385
|
-
fulltextWeight: params.fusion.fulltextWeight,
|
|
2386
|
-
limit: params.limit,
|
|
2387
|
-
offset: params.offset ?? 0
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
};
|
|
2391
|
-
function buildInsertContributionMaterialization(params) {
|
|
2392
|
-
return drizzleOrm.sql`
|
|
2393
|
-
INSERT INTO ${contributionMaterializations}
|
|
2394
|
-
(graph_id, logical_name, owner, table_name, signature,
|
|
2395
|
-
materialized_at, last_attempted_at, last_error)
|
|
2396
|
-
VALUES (
|
|
2397
|
-
${params.graphId}, ${params.logicalName}, ${params.owner},
|
|
2398
|
-
${params.tableName}, ${params.signature},
|
|
2399
|
-
${nullableText(params.materializedAt)}, ${params.attemptedAt},
|
|
2400
|
-
${nullableText(params.error)}
|
|
2401
|
-
)
|
|
2402
|
-
ON CONFLICT (graph_id, logical_name, owner, table_name) DO UPDATE SET
|
|
2403
|
-
signature = excluded.signature,
|
|
2404
|
-
materialized_at = excluded.materialized_at,
|
|
2405
|
-
last_attempted_at = excluded.last_attempted_at,
|
|
2406
|
-
last_error = excluded.last_error
|
|
2407
|
-
`;
|
|
2408
|
-
}
|
|
2409
|
-
function buildDeleteContributionMaterialization(identity) {
|
|
2410
|
-
return drizzleOrm.sql`
|
|
2411
|
-
DELETE FROM ${contributionMaterializations}
|
|
2412
|
-
WHERE graph_id = ${identity.graphId}
|
|
2413
|
-
AND logical_name = ${identity.logicalName}
|
|
2414
|
-
AND owner = ${identity.owner}
|
|
2415
|
-
AND table_name = ${identity.tableName}
|
|
2416
|
-
`;
|
|
2417
|
-
}
|
|
2418
|
-
return {
|
|
2419
|
-
...tableOperations,
|
|
2420
|
-
...fulltextBuilders,
|
|
2421
|
-
primaryKeyConstraints: {
|
|
2422
|
-
nodes: nodePrimaryKeyConstraint(tables.nodes),
|
|
2423
|
-
edges: edgePrimaryKeyConstraint(tables.edges)
|
|
2424
|
-
},
|
|
2425
|
-
buildUpdateNodeSet(params, timestamp) {
|
|
2426
|
-
return buildUpdateNodeSet(tables, dialect, params, timestamp);
|
|
2427
|
-
},
|
|
2428
|
-
buildDeleteContributionMaterialization,
|
|
2429
|
-
buildInsertContributionMaterialization,
|
|
2430
|
-
buildInsertUnique(params) {
|
|
2431
|
-
return buildInsertUnique(tables, dialect, params);
|
|
2432
|
-
},
|
|
2433
|
-
buildInsertUniqueBatch(entries) {
|
|
2434
|
-
return buildInsertUniqueBatch(tables, dialect, entries);
|
|
2435
|
-
},
|
|
2436
|
-
buildGetActiveSchema(graphId) {
|
|
2437
|
-
return buildGetActiveSchema(tables, graphId, dialect);
|
|
2438
|
-
},
|
|
2439
|
-
buildInsertSchema(params, timestamp) {
|
|
2440
|
-
return buildInsertSchema(tables, params, timestamp, dialect);
|
|
2441
|
-
},
|
|
2442
|
-
buildSetActiveSchema(graphId, version) {
|
|
2443
|
-
return buildSetActiveSchema(tables, graphId, version, dialect);
|
|
2444
|
-
},
|
|
2445
|
-
buildTableExists(tableName) {
|
|
2446
|
-
switch (dialect) {
|
|
2447
|
-
case "postgres": {
|
|
2448
|
-
return drizzleOrm.sql`
|
|
2449
|
-
SELECT c.relname AS table_name
|
|
2450
|
-
FROM pg_catalog.pg_class AS c
|
|
2451
|
-
WHERE c.relname = ${tableName}
|
|
2452
|
-
AND c.relkind IN ('r', 'p', 'v', 'm', 'f')
|
|
2453
|
-
AND pg_catalog.pg_table_is_visible(c.oid)
|
|
2454
|
-
LIMIT 1
|
|
2455
|
-
`;
|
|
2456
|
-
}
|
|
2457
|
-
case "sqlite": {
|
|
2458
|
-
return drizzleOrm.sql`SELECT name AS table_name FROM sqlite_master WHERE type IN ('table', 'view') AND name = ${tableName}`;
|
|
2459
|
-
}
|
|
2460
|
-
default: {
|
|
2461
|
-
return dialect;
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
},
|
|
2465
|
-
buildClearGraph(graphId) {
|
|
2466
|
-
return buildClearGraph(tables, graphId);
|
|
2467
|
-
}
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
function tableExistsFromRow(row) {
|
|
2471
|
-
if (row === void 0) return false;
|
|
2472
|
-
return Object.values(row).some((value) => chunkN66HCGCY_cjs.isPresent(value));
|
|
2473
|
-
}
|
|
2474
|
-
function createCachedTableExistence(probe, options) {
|
|
2475
|
-
const cacheExisting = options?.cacheExisting !== false;
|
|
2476
|
-
const cacheMissing = options?.cacheMissing === true;
|
|
2477
|
-
const confirmedExisting = /* @__PURE__ */ new Set();
|
|
2478
|
-
const confirmedMissing = /* @__PURE__ */ new Set();
|
|
2479
|
-
return async function tableExists(tableName) {
|
|
2480
|
-
if (confirmedExisting.has(tableName)) return true;
|
|
2481
|
-
if (confirmedMissing.has(tableName)) return false;
|
|
2482
|
-
const exists = tableExistsFromRow(await probe(tableName));
|
|
2483
|
-
if (exists && cacheExisting) {
|
|
2484
|
-
confirmedExisting.add(tableName);
|
|
2485
|
-
}
|
|
2486
|
-
if (!exists && cacheMissing) {
|
|
2487
|
-
confirmedMissing.add(tableName);
|
|
2488
|
-
}
|
|
2489
|
-
return exists;
|
|
2490
|
-
};
|
|
2491
|
-
}
|
|
2492
|
-
function createSqliteOperationStrategy(tables, fulltextStrategy) {
|
|
2493
|
-
return createCommonOperationStrategy(tables, "sqlite", fulltextStrategy);
|
|
2494
|
-
}
|
|
2495
|
-
function createPostgresOperationStrategy(tables, fulltextStrategy) {
|
|
2496
|
-
return createCommonOperationStrategy(tables, "postgres", fulltextStrategy);
|
|
2497
|
-
}
|
|
2498
|
-
var DRIZZLE_DIALECT_LABELS = {
|
|
2499
|
-
postgres: "Postgres",
|
|
2500
|
-
sqlite: "SQLite"
|
|
2501
|
-
};
|
|
2502
|
-
function assertAdoptedDialect(externalTx, brand, backend) {
|
|
2503
|
-
if (drizzleOrm.is(externalTx, brand)) return;
|
|
2504
|
-
const label = DRIZZLE_DIALECT_LABELS[backend];
|
|
2505
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
2506
|
-
`adoptTransaction received a handle that is not a ${label} Drizzle transaction. Pass the \`tx\` from a ${label} \`db.transaction(...)\` opened on this backend's connection.`,
|
|
2507
|
-
{ backend, capability: "adoptTransaction" }
|
|
2508
|
-
);
|
|
2509
|
-
}
|
|
2510
|
-
async function withDuplicateKeyClassification(run, context) {
|
|
2511
|
-
try {
|
|
2512
|
-
return await run();
|
|
2513
|
-
} catch (error) {
|
|
2514
|
-
if (!chunkSIT26LAZ_cjs.isDuplicatePrimaryKeyError(error, context.relation)) throw error;
|
|
2515
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
2516
|
-
`Insert ${context.entity} failed: a row with this identity already exists`,
|
|
2517
|
-
{
|
|
2518
|
-
operation: "insert",
|
|
2519
|
-
entity: context.entity,
|
|
2520
|
-
reason: "duplicate_key",
|
|
2521
|
-
attempted: context.attempted
|
|
2522
|
-
},
|
|
2523
|
-
{ cause: error }
|
|
2524
|
-
);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
function attemptedInserts(params) {
|
|
2528
|
-
return params.map((item) => ({ kind: item.kind, id: item.id }));
|
|
2529
|
-
}
|
|
2530
|
-
function verifyExpectedActiveVersion(graphId, expected, actualActiveVersion) {
|
|
2531
|
-
const expectedVersion = expected.kind === "active" ? expected.version : 0;
|
|
2532
|
-
assertActiveSchemaVersion(graphId, expectedVersion, actualActiveVersion);
|
|
2533
|
-
}
|
|
2534
|
-
function assertActiveSchemaVersion(graphId, expectedVersion, actualActiveVersion) {
|
|
2535
|
-
if (actualActiveVersion !== expectedVersion) {
|
|
2536
|
-
throw new chunkMRDBBHIZ_cjs.StaleVersionError({
|
|
2537
|
-
graphId,
|
|
2538
|
-
expected: expectedVersion,
|
|
2539
|
-
actual: actualActiveVersion
|
|
2540
|
-
});
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
async function commitSchemaVersionIfKindsEmpty(backend, params, probes) {
|
|
2544
|
-
const [existing, active] = await Promise.all([
|
|
2545
|
-
backend.getSchemaVersion(params.graphId, params.version),
|
|
2546
|
-
backend.getActiveSchema(params.graphId)
|
|
2547
|
-
]);
|
|
2548
|
-
if (existing !== void 0 && (existing.is_active || existing.schema_hash !== params.schemaHash)) {
|
|
2549
|
-
return {
|
|
2550
|
-
status: "committed",
|
|
2551
|
-
row: await backend.commitSchemaVersion(params)
|
|
2552
|
-
};
|
|
2553
|
-
}
|
|
2554
|
-
verifyExpectedActiveVersion(
|
|
2555
|
-
params.graphId,
|
|
2556
|
-
params.expected,
|
|
2557
|
-
active?.version ?? 0
|
|
2558
|
-
);
|
|
2559
|
-
const populated = [];
|
|
2560
|
-
for (const probe of probes) {
|
|
2561
|
-
const count = probe.entity === "node" ? await backend.countNodesByKind({
|
|
2562
|
-
graphId: params.graphId,
|
|
2563
|
-
kind: probe.kind
|
|
2564
|
-
}) : await backend.countEdgesByKind({
|
|
2565
|
-
graphId: params.graphId,
|
|
2566
|
-
kind: probe.kind
|
|
2567
|
-
});
|
|
2568
|
-
if (count > 0) populated.push({ ...probe, count });
|
|
2569
|
-
}
|
|
2570
|
-
if (populated.length > 0) {
|
|
2571
|
-
return { status: "populated", kinds: populated };
|
|
2572
|
-
}
|
|
2573
|
-
return {
|
|
2574
|
-
status: "committed",
|
|
2575
|
-
row: await backend.commitSchemaVersion(params)
|
|
2576
|
-
};
|
|
2577
|
-
}
|
|
2578
|
-
function createCommonOperationBackend(options) {
|
|
2579
|
-
const {
|
|
2580
|
-
batchConfig,
|
|
2581
|
-
execution,
|
|
2582
|
-
maxBindParameters,
|
|
2583
|
-
operationStrategy,
|
|
2584
|
-
rowMappers
|
|
2585
|
-
} = options;
|
|
2586
|
-
const nowIso2 = options.nowIso ?? chunkFA2AFWLP_cjs.nowIso;
|
|
2587
|
-
const tableExists = createCachedTableExistence(
|
|
2588
|
-
(tableName) => execution.execGet(
|
|
2589
|
-
operationStrategy.buildTableExists(tableName)
|
|
2590
|
-
),
|
|
2591
|
-
options.tableExistenceCache
|
|
2592
|
-
);
|
|
2593
|
-
async function runIgnorableClearStatement(statement) {
|
|
2594
|
-
if (statement.ignoreMissingTable === true && statement.requiredTableName !== void 0 && !await tableExists(statement.requiredTableName)) {
|
|
2595
|
-
return;
|
|
2596
|
-
}
|
|
2597
|
-
await execution.execRun(statement.query);
|
|
2598
|
-
}
|
|
2599
|
-
async function readActiveVersion(graphId) {
|
|
2600
|
-
const row = await execution.execGet(
|
|
2601
|
-
operationStrategy.buildGetActiveSchema(graphId)
|
|
2602
|
-
);
|
|
2603
|
-
return row === void 0 ? 0 : rowMappers.toSchemaVersionRow(row).version;
|
|
2604
|
-
}
|
|
2605
|
-
return {
|
|
2606
|
-
tableExists,
|
|
2607
|
-
async executeSchemaDdl(ddl) {
|
|
2608
|
-
await execution.execRun(chunkEDN4Y4ZG_cjs.asCompiledStatementSql(chunkEDN4Y4ZG_cjs.sql.raw(ddl)));
|
|
2609
|
-
},
|
|
2610
|
-
async executeStatement(query) {
|
|
2611
|
-
await execution.execRun(query);
|
|
2612
|
-
},
|
|
2613
|
-
async executeTemporaryStatement(query) {
|
|
2614
|
-
await execution.execRun(query);
|
|
2615
|
-
},
|
|
2616
|
-
async insertNode(params) {
|
|
2617
|
-
const timestamp = nowIso2();
|
|
2618
|
-
const query = operationStrategy.buildInsertNode(params, timestamp);
|
|
2619
|
-
const row = await withDuplicateKeyClassification(
|
|
2620
|
-
() => execution.execGet(query),
|
|
2621
|
-
{
|
|
2622
|
-
entity: "node",
|
|
2623
|
-
relation: operationStrategy.primaryKeyConstraints.nodes,
|
|
2624
|
-
attempted: attemptedInserts([params])
|
|
2625
|
-
}
|
|
2626
|
-
);
|
|
2627
|
-
if (!row)
|
|
2628
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
2629
|
-
"Insert node failed: no row returned",
|
|
2630
|
-
{
|
|
2631
|
-
operation: "insert",
|
|
2632
|
-
entity: "node",
|
|
2633
|
-
reason: "no_row_returned"
|
|
2634
|
-
}
|
|
2635
|
-
);
|
|
2636
|
-
return rowMappers.toNodeRow(row);
|
|
2637
|
-
},
|
|
2638
|
-
async insertNodeNoReturn(params) {
|
|
2639
|
-
const timestamp = nowIso2();
|
|
2640
|
-
const query = operationStrategy.buildInsertNodeNoReturn(
|
|
2641
|
-
params,
|
|
2642
|
-
timestamp
|
|
2643
|
-
);
|
|
2644
|
-
await withDuplicateKeyClassification(() => execution.execRun(query), {
|
|
2645
|
-
entity: "node",
|
|
2646
|
-
relation: operationStrategy.primaryKeyConstraints.nodes,
|
|
2647
|
-
attempted: attemptedInserts([params])
|
|
2648
|
-
});
|
|
2649
|
-
},
|
|
2650
|
-
async insertNodesBatch(params) {
|
|
2651
|
-
if (params.length === 0) {
|
|
2652
|
-
return;
|
|
2653
|
-
}
|
|
2654
|
-
const timestamp = nowIso2();
|
|
2655
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
2656
|
-
const query = operationStrategy.buildInsertNodesBatch(chunk2, timestamp);
|
|
2657
|
-
await withDuplicateKeyClassification(() => execution.execRun(query), {
|
|
2658
|
-
entity: "node",
|
|
2659
|
-
relation: operationStrategy.primaryKeyConstraints.nodes,
|
|
2660
|
-
attempted: attemptedInserts(chunk2)
|
|
2661
|
-
});
|
|
2662
|
-
}
|
|
2663
|
-
},
|
|
2664
|
-
async insertNodesBatchReturning(params) {
|
|
2665
|
-
if (params.length === 0) {
|
|
2666
|
-
return [];
|
|
2667
|
-
}
|
|
2668
|
-
const timestamp = nowIso2();
|
|
2669
|
-
const allRows = [];
|
|
2670
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(params, batchConfig.nodeInsertBatchSize)) {
|
|
2671
|
-
const query = operationStrategy.buildInsertNodesBatchReturning(
|
|
2672
|
-
chunk2,
|
|
2673
|
-
timestamp
|
|
2674
|
-
);
|
|
2675
|
-
const rows = await withDuplicateKeyClassification(
|
|
2676
|
-
() => execution.execAll(query),
|
|
2677
|
-
{
|
|
2678
|
-
entity: "node",
|
|
2679
|
-
relation: operationStrategy.primaryKeyConstraints.nodes,
|
|
2680
|
-
attempted: attemptedInserts(chunk2)
|
|
2681
|
-
}
|
|
2682
|
-
);
|
|
2683
|
-
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2684
|
-
}
|
|
2685
|
-
return allRows;
|
|
2686
|
-
},
|
|
2687
|
-
async getNode(graphId, kind, id) {
|
|
2688
|
-
const query = operationStrategy.buildGetNode(graphId, kind, id);
|
|
2689
|
-
const row = await execution.execGet(query);
|
|
2690
|
-
return row ? rowMappers.toNodeRow(row) : void 0;
|
|
2691
|
-
},
|
|
2692
|
-
async getNodes(graphId, kind, ids) {
|
|
2693
|
-
if (ids.length === 0) return [];
|
|
2694
|
-
const allRows = [];
|
|
2695
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(ids, batchConfig.getNodesChunkSize)) {
|
|
2696
|
-
const query = operationStrategy.buildGetNodes(graphId, kind, chunk2);
|
|
2697
|
-
const rows = await execution.execAll(query);
|
|
2698
|
-
allRows.push(...rows.map((row) => rowMappers.toNodeRow(row)));
|
|
2699
|
-
}
|
|
2700
|
-
return allRows;
|
|
2701
|
-
},
|
|
2702
|
-
async updateNode(params) {
|
|
2703
|
-
const timestamp = nowIso2();
|
|
2704
|
-
const query = operationStrategy.buildUpdateNode(params, timestamp);
|
|
2705
|
-
const row = await execution.execGet(query);
|
|
2706
|
-
if (!row)
|
|
2707
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
2708
|
-
"Update node failed: no row returned",
|
|
2709
|
-
{
|
|
2710
|
-
operation: "update",
|
|
2711
|
-
entity: "node",
|
|
2712
|
-
reason: "no_row_returned"
|
|
2713
|
-
}
|
|
2714
|
-
);
|
|
2715
|
-
return rowMappers.toNodeRow(row);
|
|
2716
|
-
},
|
|
2717
|
-
async updateNodeSet(params) {
|
|
2718
|
-
if (Object.keys(params.patch).length === 0 && (params.unsetProperties?.length ?? 0) === 0) {
|
|
2719
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
2720
|
-
"Set-based node update requires at least one property",
|
|
2721
|
-
{ operation: "updateNodeSet", kind: params.kind }
|
|
2722
|
-
);
|
|
2723
|
-
}
|
|
2724
|
-
if (params.candidateIdColumn.length === 0) {
|
|
2725
|
-
throw new chunkMRDBBHIZ_cjs.ConfigurationError(
|
|
2726
|
-
"Set-based node update requires a candidate id column",
|
|
2727
|
-
{ operation: "updateNodeSet", kind: params.kind }
|
|
2728
|
-
);
|
|
2729
|
-
}
|
|
2730
|
-
const timestamp = nowIso2();
|
|
2731
|
-
const query = operationStrategy.buildUpdateNodeSet(params, timestamp);
|
|
2732
|
-
const rows = await execution.execAll(query);
|
|
2733
|
-
const updatedRows = rows.map((row) => rowMappers.toNodeRow(row));
|
|
2734
|
-
return { affectedCount: updatedRows.length, rows: updatedRows };
|
|
2735
|
-
},
|
|
2736
|
-
async deleteNode(params) {
|
|
2737
|
-
const timestamp = nowIso2();
|
|
2738
|
-
const query = operationStrategy.buildDeleteNode(params, timestamp);
|
|
2739
|
-
await execution.execRun(query);
|
|
2740
|
-
},
|
|
2741
|
-
// IMPORTANT: This cascade is not atomic. Callers must ensure this runs
|
|
2742
|
-
// within a transaction to prevent partial deletion on intermediate failure.
|
|
2743
|
-
//
|
|
2744
|
-
// Embeddings are NOT cleaned up here: they live in per-`(nodeKind,
|
|
2745
|
-
// fieldPath)` strategy-owned tables addressable only with the slot
|
|
2746
|
-
// context the graph-agnostic backend lacks. The store's hard-delete
|
|
2747
|
-
// path (`executeNodeHardDelete`) drives `deleteNodeEmbeddings`, which
|
|
2748
|
-
// resolves each embedding field and routes a per-field
|
|
2749
|
-
// `backend.deleteEmbedding` through the active vector strategy.
|
|
2750
|
-
async hardDeleteNode(params) {
|
|
2751
|
-
const deleteUniquesQuery = operationStrategy.buildHardDeleteUniquesByNode(
|
|
2752
|
-
params.graphId,
|
|
2753
|
-
params.kind,
|
|
2754
|
-
params.id
|
|
2755
|
-
);
|
|
2756
|
-
await execution.execRun(deleteUniquesQuery);
|
|
2757
|
-
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
2758
|
-
params.graphId,
|
|
2759
|
-
params.kind,
|
|
2760
|
-
params.id
|
|
2761
|
-
);
|
|
2762
|
-
for (const stmt of deleteFulltextStatements) {
|
|
2763
|
-
await execution.execRun(stmt);
|
|
2764
|
-
}
|
|
2765
|
-
const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
|
|
2766
|
-
params.graphId,
|
|
2767
|
-
params.kind,
|
|
2768
|
-
params.id
|
|
2769
|
-
);
|
|
2770
|
-
await execution.execRun(deleteEdgesQuery);
|
|
2771
|
-
const query = operationStrategy.buildHardDeleteNode(params);
|
|
2772
|
-
await execution.execRun(query);
|
|
2773
|
-
},
|
|
2774
|
-
async insertEdge(params) {
|
|
2775
|
-
const timestamp = nowIso2();
|
|
2776
|
-
const query = operationStrategy.buildInsertEdge(params, timestamp);
|
|
2777
|
-
const row = await withDuplicateKeyClassification(
|
|
2778
|
-
() => execution.execGet(query),
|
|
2779
|
-
{
|
|
2780
|
-
entity: "edge",
|
|
2781
|
-
relation: operationStrategy.primaryKeyConstraints.edges,
|
|
2782
|
-
attempted: attemptedInserts([params])
|
|
2783
|
-
}
|
|
2784
|
-
);
|
|
2785
|
-
if (!row)
|
|
2786
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
2787
|
-
"Insert edge failed: no row returned",
|
|
2788
|
-
{
|
|
2789
|
-
operation: "insert",
|
|
2790
|
-
entity: "edge",
|
|
2791
|
-
reason: "no_row_returned"
|
|
2792
|
-
}
|
|
2793
|
-
);
|
|
2794
|
-
return rowMappers.toEdgeRow(row);
|
|
2795
|
-
},
|
|
2796
|
-
async insertEdgeNoReturn(params) {
|
|
2797
|
-
const timestamp = nowIso2();
|
|
2798
|
-
const query = operationStrategy.buildInsertEdgeNoReturn(
|
|
2799
|
-
params,
|
|
2800
|
-
timestamp
|
|
2801
|
-
);
|
|
2802
|
-
await withDuplicateKeyClassification(() => execution.execRun(query), {
|
|
2803
|
-
entity: "edge",
|
|
2804
|
-
relation: operationStrategy.primaryKeyConstraints.edges,
|
|
2805
|
-
attempted: attemptedInserts([params])
|
|
2806
|
-
});
|
|
2807
|
-
},
|
|
2808
|
-
async insertEdgesBatch(params) {
|
|
2809
|
-
if (params.length === 0) {
|
|
2810
|
-
return;
|
|
2811
|
-
}
|
|
2812
|
-
const timestamp = nowIso2();
|
|
2813
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2814
|
-
const query = operationStrategy.buildInsertEdgesBatch(chunk2, timestamp);
|
|
2815
|
-
await withDuplicateKeyClassification(() => execution.execRun(query), {
|
|
2816
|
-
entity: "edge",
|
|
2817
|
-
relation: operationStrategy.primaryKeyConstraints.edges,
|
|
2818
|
-
attempted: attemptedInserts(chunk2)
|
|
2819
|
-
});
|
|
2820
|
-
}
|
|
2821
|
-
},
|
|
2822
|
-
async insertEdgesBatchReturning(params) {
|
|
2823
|
-
if (params.length === 0) {
|
|
2824
|
-
return [];
|
|
2825
|
-
}
|
|
2826
|
-
const timestamp = nowIso2();
|
|
2827
|
-
const allRows = [];
|
|
2828
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(params, batchConfig.edgeInsertBatchSize)) {
|
|
2829
|
-
const query = operationStrategy.buildInsertEdgesBatchReturning(
|
|
2830
|
-
chunk2,
|
|
2831
|
-
timestamp
|
|
2832
|
-
);
|
|
2833
|
-
const rows = await withDuplicateKeyClassification(
|
|
2834
|
-
() => execution.execAll(query),
|
|
2835
|
-
{
|
|
2836
|
-
entity: "edge",
|
|
2837
|
-
relation: operationStrategy.primaryKeyConstraints.edges,
|
|
2838
|
-
attempted: attemptedInserts(chunk2)
|
|
2839
|
-
}
|
|
2840
|
-
);
|
|
2841
|
-
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2842
|
-
}
|
|
2843
|
-
return allRows;
|
|
2844
|
-
},
|
|
2845
|
-
async getEdge(graphId, id) {
|
|
2846
|
-
const query = operationStrategy.buildGetEdge(graphId, id);
|
|
2847
|
-
const row = await execution.execGet(query);
|
|
2848
|
-
return row ? rowMappers.toEdgeRow(row) : void 0;
|
|
2849
|
-
},
|
|
2850
|
-
async getEdges(graphId, ids) {
|
|
2851
|
-
if (ids.length === 0) return [];
|
|
2852
|
-
const allRows = [];
|
|
2853
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(ids, batchConfig.getEdgesChunkSize)) {
|
|
2854
|
-
const query = operationStrategy.buildGetEdges(graphId, chunk2);
|
|
2855
|
-
const rows = await execution.execAll(query);
|
|
2856
|
-
allRows.push(...rows.map((row) => rowMappers.toEdgeRow(row)));
|
|
2857
|
-
}
|
|
2858
|
-
return allRows;
|
|
2859
|
-
},
|
|
2860
|
-
async updateEdge(params) {
|
|
2861
|
-
const timestamp = nowIso2();
|
|
2862
|
-
const query = operationStrategy.buildUpdateEdge(params, timestamp);
|
|
2863
|
-
const row = await execution.execGet(query);
|
|
2864
|
-
if (!row)
|
|
2865
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
2866
|
-
"Update edge failed: no row returned",
|
|
2867
|
-
{
|
|
2868
|
-
operation: "update",
|
|
2869
|
-
entity: "edge",
|
|
2870
|
-
reason: "no_row_returned"
|
|
2871
|
-
}
|
|
2872
|
-
);
|
|
2873
|
-
return rowMappers.toEdgeRow(row);
|
|
2874
|
-
},
|
|
2875
|
-
async deleteEdge(params) {
|
|
2876
|
-
const timestamp = nowIso2();
|
|
2877
|
-
const query = operationStrategy.buildDeleteEdge(params, timestamp);
|
|
2878
|
-
await execution.execRun(query);
|
|
2879
|
-
},
|
|
2880
|
-
async hardDeleteEdge(params) {
|
|
2881
|
-
const query = operationStrategy.buildHardDeleteEdge(params);
|
|
2882
|
-
await execution.execRun(query);
|
|
2883
|
-
},
|
|
2884
|
-
async deleteEdgesBatch(params) {
|
|
2885
|
-
if (params.ids.length === 0) return;
|
|
2886
|
-
const timestamp = nowIso2();
|
|
2887
|
-
const softDeleteChunkSize = Math.max(
|
|
2888
|
-
1,
|
|
2889
|
-
batchConfig.getEdgesChunkSize - 1
|
|
2890
|
-
);
|
|
2891
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(params.ids, softDeleteChunkSize)) {
|
|
2892
|
-
const query = operationStrategy.buildDeleteEdgesBatch(
|
|
2893
|
-
{ graphId: params.graphId, ids: chunk2 },
|
|
2894
|
-
timestamp
|
|
2895
|
-
);
|
|
2896
|
-
await execution.execRun(query);
|
|
2897
|
-
}
|
|
2898
|
-
},
|
|
2899
|
-
async hardDeleteEdgesBatch(params) {
|
|
2900
|
-
if (params.ids.length === 0) return;
|
|
2901
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(
|
|
2902
|
-
params.ids,
|
|
2903
|
-
batchConfig.getEdgesChunkSize
|
|
2904
|
-
)) {
|
|
2905
|
-
const query = operationStrategy.buildHardDeleteEdgesBatch({
|
|
2906
|
-
graphId: params.graphId,
|
|
2907
|
-
ids: chunk2
|
|
2908
|
-
});
|
|
2909
|
-
await execution.execRun(query);
|
|
2910
|
-
}
|
|
2911
|
-
},
|
|
2912
|
-
async countEdgesFrom(params) {
|
|
2913
|
-
const query = operationStrategy.buildCountEdgesFrom(params);
|
|
2914
|
-
const row = await execution.execGet(query);
|
|
2915
|
-
return Number(row?.count ?? 0);
|
|
2916
|
-
},
|
|
2917
|
-
async edgeExistsBetween(params) {
|
|
2918
|
-
const query = operationStrategy.buildEdgeExistsBetween(params);
|
|
2919
|
-
const row = await execution.execGet(query);
|
|
2920
|
-
return row !== void 0;
|
|
2921
|
-
},
|
|
2922
|
-
async findEdgesConnectedTo(params) {
|
|
2923
|
-
const query = operationStrategy.buildFindEdgesConnectedTo(params);
|
|
2924
|
-
const rows = await execution.execAll(query);
|
|
2925
|
-
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2926
|
-
},
|
|
2927
|
-
async findNodesByKind(params) {
|
|
2928
|
-
const query = operationStrategy.buildFindNodesByKind(params);
|
|
2929
|
-
const rows = await execution.execAll(query);
|
|
2930
|
-
return rows.map((row) => rowMappers.toNodeRow(row));
|
|
2931
|
-
},
|
|
2932
|
-
async countNodesByKind(params) {
|
|
2933
|
-
const query = operationStrategy.buildCountNodesByKind(params);
|
|
2934
|
-
const row = await execution.execGet(query);
|
|
2935
|
-
return Number(row?.count ?? 0);
|
|
2936
|
-
},
|
|
2937
|
-
async findEdgesByKind(params) {
|
|
2938
|
-
const query = operationStrategy.buildFindEdgesByKind(params);
|
|
2939
|
-
const rows = await execution.execAll(query);
|
|
2940
|
-
return rows.map((row) => rowMappers.toEdgeRow(row));
|
|
2941
|
-
},
|
|
2942
|
-
async findEdgesByEndpointSet(params) {
|
|
2943
|
-
const ids = resolveEdgeEndpointIds(params);
|
|
2944
|
-
const edgeRows = [];
|
|
2945
|
-
for (const idChunk of chunkSIT26LAZ_cjs.chunk(
|
|
2946
|
-
ids,
|
|
2947
|
-
batchConfig.findEdgesEndpointChunkSize
|
|
2948
|
-
)) {
|
|
2949
|
-
const query = operationStrategy.buildFindEdgesByEndpointSet(
|
|
2950
|
-
params,
|
|
2951
|
-
idChunk
|
|
2952
|
-
);
|
|
2953
|
-
const rows = await execution.execAll(query);
|
|
2954
|
-
for (const row of rows) edgeRows.push(rowMappers.toEdgeRow(row));
|
|
2955
|
-
}
|
|
2956
|
-
return edgeRows;
|
|
2957
|
-
},
|
|
2958
|
-
async findEdgesByHeterogeneousEndpointSet(params) {
|
|
2959
|
-
const { edgeKinds, endpoints, endpointChunkSize } = resolveHeterogeneousEdgeRead(params, maxBindParameters);
|
|
2960
|
-
if (edgeKinds.length === 0 || endpoints.length === 0) return [];
|
|
2961
|
-
const edgeRows = [];
|
|
2962
|
-
for (const endpointChunk of chunkSIT26LAZ_cjs.chunk(endpoints, endpointChunkSize)) {
|
|
2963
|
-
const query = operationStrategy.buildFindEdgesByHeterogeneousEndpointSet(
|
|
2964
|
-
params,
|
|
2965
|
-
endpointChunk,
|
|
2966
|
-
edgeKinds
|
|
2967
|
-
);
|
|
2968
|
-
const rows = await execution.execAll(query);
|
|
2969
|
-
for (const row of rows) edgeRows.push(rowMappers.toEdgeRow(row));
|
|
2970
|
-
}
|
|
2971
|
-
return edgeRows;
|
|
2972
|
-
},
|
|
2973
|
-
async countEdgesByKind(params) {
|
|
2974
|
-
const query = operationStrategy.buildCountEdgesByKind(params);
|
|
2975
|
-
const row = await execution.execGet(query);
|
|
2976
|
-
return Number(row?.count ?? 0);
|
|
2977
|
-
},
|
|
2978
|
-
async insertUnique(params) {
|
|
2979
|
-
const query = operationStrategy.buildInsertUnique(params);
|
|
2980
|
-
const result = await execution.execGet(query);
|
|
2981
|
-
if (result && result.node_id !== params.nodeId) {
|
|
2982
|
-
throw new chunkMRDBBHIZ_cjs.UniquenessError({
|
|
2983
|
-
constraintName: params.constraintName,
|
|
2984
|
-
kind: params.nodeKind,
|
|
2985
|
-
existingId: result.node_id,
|
|
2986
|
-
newId: params.nodeId,
|
|
2987
|
-
fields: []
|
|
2988
|
-
});
|
|
2989
|
-
}
|
|
2990
|
-
},
|
|
2991
|
-
async insertUniqueBatch(entries) {
|
|
2992
|
-
if (entries.length === 0) return;
|
|
2993
|
-
const targetKey = (entry) => `${entry.nodeKind}\0${entry.constraintName}\0${entry.key}`;
|
|
2994
|
-
const byTarget = /* @__PURE__ */ new Map();
|
|
2995
|
-
for (const entry of entries) {
|
|
2996
|
-
const existing = byTarget.get(targetKey(entry));
|
|
2997
|
-
if (existing === void 0) {
|
|
2998
|
-
byTarget.set(targetKey(entry), entry);
|
|
2999
|
-
continue;
|
|
3000
|
-
}
|
|
3001
|
-
if (existing.nodeId !== entry.nodeId) {
|
|
3002
|
-
throw new chunkMRDBBHIZ_cjs.UniquenessError({
|
|
3003
|
-
constraintName: entry.constraintName,
|
|
3004
|
-
kind: entry.nodeKind,
|
|
3005
|
-
existingId: existing.nodeId,
|
|
3006
|
-
newId: entry.nodeId,
|
|
3007
|
-
fields: []
|
|
3008
|
-
});
|
|
3009
|
-
}
|
|
3010
|
-
}
|
|
3011
|
-
const deduped = [...byTarget.values()];
|
|
3012
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(
|
|
3013
|
-
deduped,
|
|
3014
|
-
batchConfig.uniqueInsertBatchSize
|
|
3015
|
-
)) {
|
|
3016
|
-
const query = operationStrategy.buildInsertUniqueBatch(chunk2);
|
|
3017
|
-
const rows = await execution.execAll(query);
|
|
3018
|
-
const ownerByTarget = new Map(
|
|
3019
|
-
rows.map((row) => [
|
|
3020
|
-
`${row.node_kind}\0${row.constraint_name}\0${row.key}`,
|
|
3021
|
-
row.node_id
|
|
3022
|
-
])
|
|
3023
|
-
);
|
|
3024
|
-
for (const entry of chunk2) {
|
|
3025
|
-
const owner = ownerByTarget.get(targetKey(entry));
|
|
3026
|
-
if (owner !== void 0 && owner !== entry.nodeId) {
|
|
3027
|
-
throw new chunkMRDBBHIZ_cjs.UniquenessError({
|
|
3028
|
-
constraintName: entry.constraintName,
|
|
3029
|
-
kind: entry.nodeKind,
|
|
3030
|
-
existingId: owner,
|
|
3031
|
-
newId: entry.nodeId,
|
|
3032
|
-
fields: []
|
|
3033
|
-
});
|
|
3034
|
-
}
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
},
|
|
3038
|
-
async deleteUnique(params) {
|
|
3039
|
-
const timestamp = nowIso2();
|
|
3040
|
-
const query = operationStrategy.buildDeleteUnique(params, timestamp);
|
|
3041
|
-
await execution.execRun(query);
|
|
3042
|
-
},
|
|
3043
|
-
async hardDeleteUniquesByNodeIds(params) {
|
|
3044
|
-
const nodeIds = [...new Set(params.nodeIds)];
|
|
3045
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(
|
|
3046
|
-
nodeIds,
|
|
3047
|
-
batchConfig.uniqueDeleteChunkSize
|
|
3048
|
-
)) {
|
|
3049
|
-
const query = operationStrategy.buildHardDeleteUniquesByNodeIds({
|
|
3050
|
-
...params,
|
|
3051
|
-
nodeIds: chunk2
|
|
3052
|
-
});
|
|
3053
|
-
await execution.execRun(query);
|
|
3054
|
-
}
|
|
3055
|
-
},
|
|
3056
|
-
async checkUnique(params) {
|
|
3057
|
-
const query = operationStrategy.buildCheckUnique(params);
|
|
3058
|
-
const row = await execution.execGet(query);
|
|
3059
|
-
return row ? rowMappers.toUniqueRow(row) : void 0;
|
|
3060
|
-
},
|
|
3061
|
-
async checkUniqueBatch(params) {
|
|
3062
|
-
if (params.keys.length === 0) return [];
|
|
3063
|
-
const allRows = [];
|
|
3064
|
-
for (const chunk2 of chunkSIT26LAZ_cjs.chunk(
|
|
3065
|
-
params.keys,
|
|
3066
|
-
batchConfig.checkUniqueBatchChunkSize
|
|
3067
|
-
)) {
|
|
3068
|
-
const query = operationStrategy.buildCheckUniqueBatch({
|
|
3069
|
-
...params,
|
|
3070
|
-
keys: chunk2
|
|
3071
|
-
});
|
|
3072
|
-
const rows = await execution.execAll(query);
|
|
3073
|
-
allRows.push(...rows.map((row) => rowMappers.toUniqueRow(row)));
|
|
3074
|
-
}
|
|
3075
|
-
return allRows;
|
|
3076
|
-
},
|
|
3077
|
-
async getActiveSchema(graphId) {
|
|
3078
|
-
const query = operationStrategy.buildGetActiveSchema(graphId);
|
|
3079
|
-
const row = await execution.execGet(query);
|
|
3080
|
-
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
3081
|
-
},
|
|
3082
|
-
async getSchemaVersion(graphId, version) {
|
|
3083
|
-
const query = operationStrategy.buildGetSchemaVersion(graphId, version);
|
|
3084
|
-
const row = await execution.execGet(query);
|
|
3085
|
-
return row ? rowMappers.toSchemaVersionRow(row) : void 0;
|
|
3086
|
-
},
|
|
3087
|
-
async commitSchemaVersion(params) {
|
|
3088
|
-
const existingRaw = await execution.execGet(
|
|
3089
|
-
operationStrategy.buildGetSchemaVersion(params.graphId, params.version)
|
|
3090
|
-
);
|
|
3091
|
-
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
3092
|
-
if (existingRaw !== void 0) {
|
|
3093
|
-
const existing = rowMappers.toSchemaVersionRow(existingRaw);
|
|
3094
|
-
if (existing.schema_hash !== params.schemaHash) {
|
|
3095
|
-
throw new chunkMRDBBHIZ_cjs.SchemaContentConflictError({
|
|
3096
|
-
graphId: params.graphId,
|
|
3097
|
-
version: params.version,
|
|
3098
|
-
existingHash: existing.schema_hash,
|
|
3099
|
-
incomingHash: params.schemaHash
|
|
3100
|
-
});
|
|
3101
|
-
}
|
|
3102
|
-
if (existing.is_active) {
|
|
3103
|
-
return existing;
|
|
3104
|
-
}
|
|
3105
|
-
verifyExpectedActiveVersion(
|
|
3106
|
-
params.graphId,
|
|
3107
|
-
params.expected,
|
|
3108
|
-
actualActiveVersion
|
|
3109
|
-
);
|
|
3110
|
-
const reactivate = operationStrategy.buildSetActiveSchema(
|
|
3111
|
-
params.graphId,
|
|
3112
|
-
params.version
|
|
3113
|
-
);
|
|
3114
|
-
await execution.execRun(reactivate.deactivateAll);
|
|
3115
|
-
await execution.execRun(reactivate.activateVersion);
|
|
3116
|
-
return { ...existing, is_active: true };
|
|
3117
|
-
}
|
|
3118
|
-
verifyExpectedActiveVersion(
|
|
3119
|
-
params.graphId,
|
|
3120
|
-
params.expected,
|
|
3121
|
-
actualActiveVersion
|
|
3122
|
-
);
|
|
3123
|
-
if (params.expected.kind === "active") {
|
|
3124
|
-
const flip = operationStrategy.buildSetActiveSchema(
|
|
3125
|
-
params.graphId,
|
|
3126
|
-
params.version
|
|
3127
|
-
);
|
|
3128
|
-
await execution.execRun(flip.deactivateAll);
|
|
3129
|
-
}
|
|
3130
|
-
const timestamp = nowIso2();
|
|
3131
|
-
const insertQuery = operationStrategy.buildInsertSchema(
|
|
3132
|
-
{
|
|
3133
|
-
graphId: params.graphId,
|
|
3134
|
-
version: params.version,
|
|
3135
|
-
schemaHash: params.schemaHash,
|
|
3136
|
-
schemaDoc: params.schemaDoc,
|
|
3137
|
-
isActive: true
|
|
3138
|
-
},
|
|
3139
|
-
timestamp
|
|
3140
|
-
);
|
|
3141
|
-
const insertedRaw = await execution.execGet(insertQuery);
|
|
3142
|
-
if (!insertedRaw) {
|
|
3143
|
-
throw new chunkMRDBBHIZ_cjs.DatabaseOperationError(
|
|
3144
|
-
"Insert schema failed: no row returned",
|
|
3145
|
-
{ operation: "insert", entity: "schema" }
|
|
3146
|
-
);
|
|
3147
|
-
}
|
|
3148
|
-
return rowMappers.toSchemaVersionRow(insertedRaw);
|
|
3149
|
-
},
|
|
3150
|
-
async setActiveVersion(params) {
|
|
3151
|
-
const actualActiveVersion = await readActiveVersion(params.graphId);
|
|
3152
|
-
verifyExpectedActiveVersion(
|
|
3153
|
-
params.graphId,
|
|
3154
|
-
params.expected,
|
|
3155
|
-
actualActiveVersion
|
|
3156
|
-
);
|
|
3157
|
-
const targetRaw = await execution.execGet(
|
|
3158
|
-
operationStrategy.buildGetSchemaVersion(params.graphId, params.version)
|
|
3159
|
-
);
|
|
3160
|
-
if (!targetRaw) {
|
|
3161
|
-
throw new chunkMRDBBHIZ_cjs.MigrationError(
|
|
3162
|
-
`Cannot activate version ${params.version}: version does not exist for graph "${params.graphId}".`,
|
|
3163
|
-
{
|
|
3164
|
-
graphId: params.graphId,
|
|
3165
|
-
fromVersion: actualActiveVersion,
|
|
3166
|
-
toVersion: params.version,
|
|
3167
|
-
reason: "version-not-found"
|
|
3168
|
-
}
|
|
3169
|
-
);
|
|
3170
|
-
}
|
|
3171
|
-
const queries = operationStrategy.buildSetActiveSchema(
|
|
3172
|
-
params.graphId,
|
|
3173
|
-
params.version
|
|
3174
|
-
);
|
|
3175
|
-
await execution.execRun(queries.deactivateAll);
|
|
3176
|
-
await execution.execRun(queries.activateVersion);
|
|
3177
|
-
},
|
|
3178
|
-
async clearGraph(graphId) {
|
|
3179
|
-
const statements = operationStrategy.buildClearGraph(graphId);
|
|
3180
|
-
for (const statement of statements) {
|
|
3181
|
-
await runIgnorableClearStatement(statement);
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
};
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
|
-
// src/backend/drizzle/trusted-import.ts
|
|
3188
|
-
var DATABASE_NULL = null;
|
|
3189
|
-
function quoteSqlIdentifier(identifier) {
|
|
3190
|
-
return `"${identifier.replaceAll('"', '""')}"`;
|
|
3191
|
-
}
|
|
3192
|
-
function requireRawExecution(backend) {
|
|
3193
|
-
if (backend.executeRaw === void 0) {
|
|
3194
|
-
throw new chunkMRDBBHIZ_cjs.TrustedImportError(
|
|
3195
|
-
"This backend cannot execute the raw statements required by trusted import.",
|
|
3196
|
-
"backend_unsupported"
|
|
3197
|
-
);
|
|
3198
|
-
}
|
|
3199
|
-
return backend.executeRaw;
|
|
3200
|
-
}
|
|
3201
|
-
function requireStatementExecution(backend) {
|
|
3202
|
-
if (backend.executeStatement === void 0) {
|
|
3203
|
-
throw new chunkMRDBBHIZ_cjs.TrustedImportError(
|
|
3204
|
-
"This backend cannot execute the index lifecycle required by trusted import.",
|
|
3205
|
-
"backend_unsupported"
|
|
3206
|
-
);
|
|
3207
|
-
}
|
|
3208
|
-
return backend.executeStatement;
|
|
3209
|
-
}
|
|
3210
|
-
function rowIndicatesExistingData(row) {
|
|
3211
|
-
if (typeof row !== "object" || row === null) return false;
|
|
3212
|
-
const value = row["has_rows"];
|
|
3213
|
-
return value === true || value === 1 || value === "1";
|
|
3214
|
-
}
|
|
3215
|
-
async function assertTrustedImportDatabaseEmpty(backend, tableNames) {
|
|
3216
|
-
const executeRaw = requireRawExecution(backend);
|
|
3217
|
-
const rows = await executeRaw(
|
|
3218
|
-
`SELECT (
|
|
3219
|
-
EXISTS (SELECT 1 FROM ${quoteSqlIdentifier(tableNames.nodes)} LIMIT 1)
|
|
3220
|
-
OR EXISTS (SELECT 1 FROM ${quoteSqlIdentifier(tableNames.edges)} LIMIT 1)
|
|
3221
|
-
) AS has_rows`,
|
|
3222
|
-
[]
|
|
3223
|
-
);
|
|
3224
|
-
if (!rowIndicatesExistingData(rows[0])) return;
|
|
3225
|
-
throw new chunkMRDBBHIZ_cjs.TrustedImportError(
|
|
3226
|
-
"Trusted import requires globally empty TypeGraph node and edge tables.",
|
|
3227
|
-
"database_not_empty",
|
|
3228
|
-
{ tables: [tableNames.nodes, tableNames.edges] },
|
|
3229
|
-
{
|
|
3230
|
-
suggestion: "Run trusted import only against a fresh, dedicated database. Use importGraph or the collection bulk APIs to add data to an existing database."
|
|
3231
|
-
}
|
|
3232
|
-
);
|
|
3233
|
-
}
|
|
3234
|
-
async function lockPostgresTrustedImportTables(backend, tableNames) {
|
|
3235
|
-
const executeStatement = requireStatementExecution(backend);
|
|
3236
|
-
await executeStatement(
|
|
3237
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
3238
|
-
chunkEDN4Y4ZG_cjs.sql.raw(
|
|
3239
|
-
`LOCK TABLE ${quoteSqlIdentifier(tableNames.nodes)}, ${quoteSqlIdentifier(tableNames.edges)} IN ACCESS EXCLUSIVE MODE`
|
|
3240
|
-
)
|
|
3241
|
-
)
|
|
3242
|
-
);
|
|
3243
|
-
}
|
|
3244
|
-
async function suspendSqliteSecondaryIndexes(backend, tableNames) {
|
|
3245
|
-
const executeRaw = requireRawExecution(backend);
|
|
3246
|
-
const executeStatement = requireStatementExecution(backend);
|
|
3247
|
-
const definitions = await executeRaw(
|
|
3248
|
-
`SELECT name AS index_name, sql AS index_definition
|
|
3249
|
-
FROM sqlite_schema
|
|
3250
|
-
WHERE type = 'index'
|
|
3251
|
-
AND tbl_name IN (?, ?)
|
|
3252
|
-
AND sql IS NOT NULL
|
|
3253
|
-
ORDER BY name`,
|
|
3254
|
-
[tableNames.nodes, tableNames.edges]
|
|
3255
|
-
);
|
|
3256
|
-
for (const definition of definitions) {
|
|
3257
|
-
await executeStatement(
|
|
3258
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
3259
|
-
chunkEDN4Y4ZG_cjs.sql.raw(`DROP INDEX ${quoteSqlIdentifier(definition.index_name)}`)
|
|
3260
|
-
)
|
|
3261
|
-
);
|
|
3262
|
-
}
|
|
3263
|
-
return definitions;
|
|
3264
|
-
}
|
|
3265
|
-
async function suspendPostgresSecondaryIndexes(backend, tableNames) {
|
|
3266
|
-
const executeRaw = requireRawExecution(backend);
|
|
3267
|
-
const executeStatement = requireStatementExecution(backend);
|
|
3268
|
-
const definitions = await executeRaw(
|
|
3269
|
-
`SELECT index_class.relname AS index_name,
|
|
3270
|
-
pg_get_indexdef(index_class.oid) AS index_definition
|
|
3271
|
-
FROM pg_class AS table_class
|
|
3272
|
-
JOIN pg_namespace AS namespace
|
|
3273
|
-
ON namespace.oid = table_class.relnamespace
|
|
3274
|
-
JOIN pg_index AS index_metadata
|
|
3275
|
-
ON index_metadata.indrelid = table_class.oid
|
|
3276
|
-
JOIN pg_class AS index_class
|
|
3277
|
-
ON index_class.oid = index_metadata.indexrelid
|
|
3278
|
-
LEFT JOIN pg_constraint AS table_constraint
|
|
3279
|
-
ON table_constraint.conindid = index_class.oid
|
|
3280
|
-
WHERE namespace.nspname = current_schema()
|
|
3281
|
-
AND table_class.relname IN ($1, $2)
|
|
3282
|
-
AND table_constraint.oid IS NULL
|
|
3283
|
-
AND NOT index_metadata.indisprimary
|
|
3284
|
-
ORDER BY index_class.relname`,
|
|
3285
|
-
[tableNames.nodes, tableNames.edges]
|
|
3286
|
-
);
|
|
3287
|
-
for (const definition of definitions) {
|
|
3288
|
-
await executeStatement(
|
|
3289
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
3290
|
-
chunkEDN4Y4ZG_cjs.sql.raw(`DROP INDEX ${quoteSqlIdentifier(definition.index_name)}`)
|
|
3291
|
-
)
|
|
3292
|
-
);
|
|
3293
|
-
}
|
|
3294
|
-
return definitions;
|
|
3295
|
-
}
|
|
3296
|
-
async function restoreSecondaryIndexes(backend, definitions) {
|
|
3297
|
-
const executeStatement = requireStatementExecution(backend);
|
|
3298
|
-
for (const definition of definitions) {
|
|
3299
|
-
await executeStatement(
|
|
3300
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(chunkEDN4Y4ZG_cjs.sql.raw(definition.index_definition))
|
|
3301
|
-
);
|
|
3302
|
-
}
|
|
3303
|
-
}
|
|
3304
|
-
async function analyzeImportedTables(backend, tableNames) {
|
|
3305
|
-
const executeStatement = requireStatementExecution(backend);
|
|
3306
|
-
await executeStatement(
|
|
3307
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
3308
|
-
chunkEDN4Y4ZG_cjs.sql.raw(`ANALYZE ${quoteSqlIdentifier(tableNames.nodes)}`)
|
|
3309
|
-
)
|
|
3310
|
-
);
|
|
3311
|
-
await executeStatement(
|
|
3312
|
-
chunkEDN4Y4ZG_cjs.asCompiledStatementSql(
|
|
3313
|
-
chunkEDN4Y4ZG_cjs.sql.raw(`ANALYZE ${quoteSqlIdentifier(tableNames.edges)}`)
|
|
3314
|
-
)
|
|
3315
|
-
);
|
|
3316
|
-
}
|
|
3317
|
-
function postgresArray(values) {
|
|
3318
|
-
return `{${values.map(
|
|
3319
|
-
(value) => value === DATABASE_NULL ? "NULL" : `"${value.replaceAll("\\", "\\\\").replaceAll('"', String.raw`\"`)}"`
|
|
3320
|
-
).join(",")}}`;
|
|
3321
|
-
}
|
|
3322
|
-
function createSqliteTrustedImportSession(executionAdapter, tableNames) {
|
|
3323
|
-
const executePreparedRunBatch = executionAdapter.executePreparedRunBatch;
|
|
3324
|
-
if (executePreparedRunBatch === void 0) {
|
|
3325
|
-
throw new chunkMRDBBHIZ_cjs.TrustedImportError(
|
|
3326
|
-
"Trusted import requires a synchronous SQLite driver with prepared statement support.",
|
|
3327
|
-
"backend_unsupported"
|
|
3328
|
-
);
|
|
3329
|
-
}
|
|
3330
|
-
const nodeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.nodes)}
|
|
3331
|
-
(graph_id, kind, id, props, version, valid_from, valid_to, created_at, updated_at)
|
|
3332
|
-
VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?)`;
|
|
3333
|
-
const edgeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.edges)}
|
|
3334
|
-
(graph_id, id, kind, from_kind, from_id, to_kind, to_id, props, valid_from, valid_to, created_at, updated_at)
|
|
3335
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
|
3336
|
-
return {
|
|
3337
|
-
async insertNodes(params) {
|
|
3338
|
-
if (params.length === 0) return;
|
|
3339
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3340
|
-
await executePreparedRunBatch(
|
|
3341
|
-
nodeSql,
|
|
3342
|
-
params.map((item) => [
|
|
3343
|
-
item.graphId,
|
|
3344
|
-
item.kind,
|
|
3345
|
-
item.id,
|
|
3346
|
-
JSON.stringify(item.props),
|
|
3347
|
-
chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
|
|
3348
|
-
item.validTo ?? DATABASE_NULL,
|
|
3349
|
-
timestamp,
|
|
3350
|
-
timestamp
|
|
3351
|
-
])
|
|
3352
|
-
);
|
|
3353
|
-
},
|
|
3354
|
-
async insertEdges(params) {
|
|
3355
|
-
if (params.length === 0) return;
|
|
3356
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3357
|
-
await executePreparedRunBatch(
|
|
3358
|
-
edgeSql,
|
|
3359
|
-
params.map((item) => [
|
|
3360
|
-
item.graphId,
|
|
3361
|
-
item.id,
|
|
3362
|
-
item.kind,
|
|
3363
|
-
item.fromKind,
|
|
3364
|
-
item.fromId,
|
|
3365
|
-
item.toKind,
|
|
3366
|
-
item.toId,
|
|
3367
|
-
JSON.stringify(item.props),
|
|
3368
|
-
chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL,
|
|
3369
|
-
item.validTo ?? DATABASE_NULL,
|
|
3370
|
-
timestamp,
|
|
3371
|
-
timestamp
|
|
3372
|
-
])
|
|
3373
|
-
);
|
|
3374
|
-
}
|
|
3375
|
-
};
|
|
3376
|
-
}
|
|
3377
|
-
function createPostgresTrustedImportSession(backend, tableNames) {
|
|
3378
|
-
const executeRaw = requireRawExecution(backend);
|
|
3379
|
-
const nodeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.nodes)}
|
|
3380
|
-
(graph_id, kind, id, props, version, valid_from, valid_to, created_at, updated_at)
|
|
3381
|
-
SELECT graph_id, kind, id, props::jsonb, 1, valid_from, valid_to, created_at, created_at
|
|
3382
|
-
FROM UNNEST(
|
|
3383
|
-
$1::text[], $2::text[], $3::text[], $4::text[],
|
|
3384
|
-
$5::timestamptz[], $6::timestamptz[], $7::timestamptz[]
|
|
3385
|
-
) AS imported(graph_id, kind, id, props, valid_from, valid_to, created_at)`;
|
|
3386
|
-
const edgeSql = `INSERT INTO ${quoteSqlIdentifier(tableNames.edges)}
|
|
3387
|
-
(graph_id, id, kind, from_kind, from_id, to_kind, to_id, props, valid_from, valid_to, created_at, updated_at)
|
|
3388
|
-
SELECT graph_id, id, kind, from_kind, from_id, to_kind, to_id, props::jsonb,
|
|
3389
|
-
valid_from, valid_to, created_at, created_at
|
|
3390
|
-
FROM UNNEST(
|
|
3391
|
-
$1::text[], $2::text[], $3::text[], $4::text[], $5::text[],
|
|
3392
|
-
$6::text[], $7::text[], $8::text[], $9::timestamptz[],
|
|
3393
|
-
$10::timestamptz[], $11::timestamptz[]
|
|
3394
|
-
) AS imported(
|
|
3395
|
-
graph_id, id, kind, from_kind, from_id, to_kind, to_id, props,
|
|
3396
|
-
valid_from, valid_to, created_at
|
|
3397
|
-
)`;
|
|
3398
|
-
return {
|
|
3399
|
-
async insertNodes(params) {
|
|
3400
|
-
if (params.length === 0) return;
|
|
3401
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3402
|
-
await executeRaw(nodeSql, [
|
|
3403
|
-
postgresArray(params.map((item) => item.graphId)),
|
|
3404
|
-
postgresArray(params.map((item) => item.kind)),
|
|
3405
|
-
postgresArray(params.map((item) => item.id)),
|
|
3406
|
-
postgresArray(params.map((item) => JSON.stringify(item.props))),
|
|
3407
|
-
postgresArray(
|
|
3408
|
-
params.map(
|
|
3409
|
-
(item) => chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
|
|
3410
|
-
)
|
|
3411
|
-
),
|
|
3412
|
-
postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
|
|
3413
|
-
postgresArray(params.map(() => timestamp))
|
|
3414
|
-
]);
|
|
3415
|
-
},
|
|
3416
|
-
async insertEdges(params) {
|
|
3417
|
-
if (params.length === 0) return;
|
|
3418
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3419
|
-
await executeRaw(edgeSql, [
|
|
3420
|
-
postgresArray(params.map((item) => item.graphId)),
|
|
3421
|
-
postgresArray(params.map((item) => item.id)),
|
|
3422
|
-
postgresArray(params.map((item) => item.kind)),
|
|
3423
|
-
postgresArray(params.map((item) => item.fromKind)),
|
|
3424
|
-
postgresArray(params.map((item) => item.fromId)),
|
|
3425
|
-
postgresArray(params.map((item) => item.toKind)),
|
|
3426
|
-
postgresArray(params.map((item) => item.toId)),
|
|
3427
|
-
postgresArray(params.map((item) => JSON.stringify(item.props))),
|
|
3428
|
-
postgresArray(
|
|
3429
|
-
params.map(
|
|
3430
|
-
(item) => chunkTQHGE7UC_cjs.resolveStampedValidityLowerBound(item.validFrom, item.validTo, timestamp) ?? DATABASE_NULL
|
|
3431
|
-
)
|
|
3432
|
-
),
|
|
3433
|
-
postgresArray(params.map((item) => item.validTo ?? DATABASE_NULL)),
|
|
3434
|
-
postgresArray(params.map(() => timestamp))
|
|
3435
|
-
]);
|
|
3436
|
-
}
|
|
3437
|
-
};
|
|
3438
|
-
}
|
|
3439
|
-
|
|
3440
|
-
// src/backend/drizzle/execution/lru.ts
|
|
3441
|
-
function getOrCreateLru(cache, key, cacheMax, create) {
|
|
3442
|
-
const cached = cache.get(key);
|
|
3443
|
-
if (cached !== void 0) {
|
|
3444
|
-
cache.delete(key);
|
|
3445
|
-
cache.set(key, cached);
|
|
3446
|
-
return cached;
|
|
3447
|
-
}
|
|
3448
|
-
const value = create();
|
|
3449
|
-
cache.set(key, value);
|
|
3450
|
-
if (cache.size > cacheMax) {
|
|
3451
|
-
const oldest = cache.keys().next().value;
|
|
3452
|
-
if (oldest !== void 0) cache.delete(oldest);
|
|
3453
|
-
}
|
|
3454
|
-
return value;
|
|
3455
|
-
}
|
|
3456
|
-
|
|
3457
|
-
exports.EMBEDDING_UPSERT_PARAM_COUNT = EMBEDDING_UPSERT_PARAM_COUNT;
|
|
3458
|
-
exports.FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT = FIND_EDGES_ENDPOINT_FIXED_PARAM_COUNT;
|
|
3459
|
-
exports.POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS = POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS;
|
|
3460
|
-
exports.POSTGRES_INDEX_MAT_TIMESTAMPS = POSTGRES_INDEX_MAT_TIMESTAMPS;
|
|
3461
|
-
exports.POSTGRES_KIND_REMOVAL_TIMESTAMPS = POSTGRES_KIND_REMOVAL_TIMESTAMPS;
|
|
3462
|
-
exports.SQLITE_CONTRIBUTION_MAT_TIMESTAMPS = SQLITE_CONTRIBUTION_MAT_TIMESTAMPS;
|
|
3463
|
-
exports.SQLITE_INDEX_MAT_TIMESTAMPS = SQLITE_INDEX_MAT_TIMESTAMPS;
|
|
3464
|
-
exports.SQLITE_KIND_REMOVAL_TIMESTAMPS = SQLITE_KIND_REMOVAL_TIMESTAMPS;
|
|
3465
|
-
exports.analyzeImportedTables = analyzeImportedTables;
|
|
3466
|
-
exports.assertActiveSchemaVersion = assertActiveSchemaVersion;
|
|
3467
|
-
exports.assertAdoptedDialect = assertAdoptedDialect;
|
|
3468
|
-
exports.assertTrustedImportDatabaseEmpty = assertTrustedImportDatabaseEmpty;
|
|
3469
|
-
exports.buildContributionInsertValues = buildContributionInsertValues;
|
|
3470
|
-
exports.buildContributionOnConflictSet = buildContributionOnConflictSet;
|
|
3471
|
-
exports.buildKindRemovalInsertValues = buildKindRemovalInsertValues;
|
|
3472
|
-
exports.buildKindRemovalOnConflictSet = buildKindRemovalOnConflictSet;
|
|
3473
|
-
exports.buildLiveNodeCandidates = buildLiveNodeCandidates;
|
|
3474
|
-
exports.buildMaterializationInsertValues = buildMaterializationInsertValues;
|
|
3475
|
-
exports.buildMaterializationOnConflictSet = buildMaterializationOnConflictSet;
|
|
3476
|
-
exports.commitSchemaVersionIfKindsEmpty = commitSchemaVersionIfKindsEmpty;
|
|
3477
|
-
exports.contributionRebuildSupported = contributionRebuildSupported;
|
|
3478
|
-
exports.createCachedTableExistence = createCachedTableExistence;
|
|
3479
|
-
exports.createCommonOperationBackend = createCommonOperationBackend;
|
|
3480
|
-
exports.createContributionMaterializer = createContributionMaterializer;
|
|
3481
|
-
exports.createPostgresOperationStrategy = createPostgresOperationStrategy;
|
|
3482
|
-
exports.createPostgresTrustedImportSession = createPostgresTrustedImportSession;
|
|
3483
|
-
exports.createSqliteOperationStrategy = createSqliteOperationStrategy;
|
|
3484
|
-
exports.createSqliteTrustedImportSession = createSqliteTrustedImportSession;
|
|
3485
|
-
exports.gateFulltext = gateFulltext;
|
|
3486
|
-
exports.gateFulltextMethods = gateFulltextMethods;
|
|
3487
|
-
exports.getOrCreateLru = getOrCreateLru;
|
|
3488
|
-
exports.lockPostgresTrustedImportTables = lockPostgresTrustedImportTables;
|
|
3489
|
-
exports.mapContributionMaterializationRow = mapContributionMaterializationRow;
|
|
3490
|
-
exports.mapHybridSearchRow = mapHybridSearchRow;
|
|
3491
|
-
exports.mapKindRemovalRow = mapKindRemovalRow;
|
|
3492
|
-
exports.mapMaterializationRow = mapMaterializationRow;
|
|
3493
|
-
exports.mapVectorWriteError = mapVectorWriteError;
|
|
3494
|
-
exports.restoreSecondaryIndexes = restoreSecondaryIndexes;
|
|
3495
|
-
exports.suspendPostgresSecondaryIndexes = suspendPostgresSecondaryIndexes;
|
|
3496
|
-
exports.suspendSqliteSecondaryIndexes = suspendSqliteSecondaryIndexes;
|
|
3497
|
-
exports.tableExistsFromRow = tableExistsFromRow;
|
|
3498
|
-
exports.vectorSlotFromCreateIndexParams = vectorSlotFromCreateIndexParams;
|
|
3499
|
-
exports.vectorSlotFromDropIndexParams = vectorSlotFromDropIndexParams;
|
|
3500
|
-
exports.vectorSlotFromParams = vectorSlotFromParams;
|
|
3501
|
-
//# sourceMappingURL=chunk-3QNZ5SAJ.cjs.map
|
|
3502
|
-
//# sourceMappingURL=chunk-3QNZ5SAJ.cjs.map
|