superfactory 0.0.0-stage → 0.4.30
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 +34 -2
- package/THIRD-PARTY-NOTICES.md +27604 -0
- package/bin/superfactory.js +57 -0
- package/cli/agent-rf446fr1.js +2 -0
- package/cli/agent-state-wv62c1td.js +2 -0
- package/cli/bin-0cvfmkhh.js +33 -0
- package/cli/bin-0t68hf99.js +3 -0
- package/cli/bin-19vpzq7g.js +4 -0
- package/cli/bin-37w316c6.js +3 -0
- package/cli/bin-3dsqxzbz.js +3 -0
- package/cli/bin-4j0jjd8g.js +3 -0
- package/cli/bin-4tdqjbbd.js +229 -0
- package/cli/bin-4zvje4sn.js +502 -0
- package/cli/bin-674kd343.js +7 -0
- package/cli/bin-8jdkg4ke.js +3 -0
- package/cli/bin-d99yte0j.js +5 -0
- package/cli/bin-fgvkq9cq.js +867 -0
- package/cli/bin-fkp3j5f3.js +3 -0
- package/cli/bin-fypan1f6.js +951 -0
- package/cli/bin-gg19acwr.js +4 -0
- package/cli/bin-ghp5x0x5.js +139 -0
- package/cli/bin-gk00mnmn.js +5 -0
- package/cli/bin-gne2w036.js +29 -0
- package/cli/bin-grxzwpe8.js +3 -0
- package/cli/bin-h57gajkz.js +8 -0
- package/cli/bin-mbpvzx2b.js +8 -0
- package/cli/bin-nnq8kd9z.js +4 -0
- package/cli/bin-ven2efjq.js +3 -0
- package/cli/bin-yqb1d1mw.js +22 -0
- package/cli/bin-z5b3tt05.js +20 -0
- package/cli/bin-za1by1n5.js +3 -0
- package/cli/bin-zpfe0pxz.js +1 -0
- package/cli/bin.js +3 -0
- package/cli/child-agent-qgeqvs03.js +4 -0
- package/cli/connect-chn8pxyf.js +2 -0
- package/cli/container-j6zr9gww.js +4 -0
- package/cli/dev-gsaehf19.js +7 -0
- package/cli/health-nqzge5kh.js +2 -0
- package/cli/home-lock-5seng0k3.js +2 -0
- package/cli/host-7dfjhf0z.js +1507 -0
- package/cli/index-1wseh1tm.js +2 -0
- package/cli/index-axfe8zef.js +2 -0
- package/cli/index-s9pw90xe.js +2 -0
- package/cli/install-17r8t45e.js +2 -0
- package/cli/join-551zg7yr.js +31 -0
- package/cli/local-server-2smsafvg.js +2 -0
- package/cli/machine-zfjmpw7h.js +2 -0
- package/cli/main-0mxhd968.js +33 -0
- package/cli/main-53qmhxmd.js +303 -0
- package/cli/move-to-xrr2b135.js +2 -0
- package/cli/npm-package.json +1 -0
- package/cli/pair-phone-070c9ztt.js +5 -0
- package/cli/prompt-psc4drtd.js +2 -0
- package/cli/reached-vwzx2cdg.js +2 -0
- package/cli/sessions-bm4mk37y.js +3 -0
- package/cli/sf-cli-s42gkp0b.js +2 -0
- package/cli/sf-db-r8f1a20b.js +23 -0
- package/cli/sf-deploy-wqaa4fdm.js +21 -0
- package/cli/sf-pr-rg3q3tn6.js +13 -0
- package/cli/sf-test-pff158qc.js +10 -0
- package/cli/tart-isolation-wr3xwfmw.js +3 -0
- package/cli/tray-4rr0y1dv.png +0 -0
- package/cli/tray-mac-offline-89dva0gs.png +0 -0
- package/cli/tray-mac-paused-hq3a1cxv.png +0 -0
- package/cli/tray-mac-tvtavf0g.png +0 -0
- package/cli/tray-offline-xj6b5ta4.png +0 -0
- package/cli/tray-paused-6pzdv5ze.png +0 -0
- package/cli/vm-keeper-p0ggcw3z.js +3 -0
- package/package.json +50 -4
- package/plugins/sf-video-review/.claude-plugin/plugin.json +17 -0
- package/plugins/sf-video-review/.mcp.json +9 -0
- package/plugins/sf-video-review/dist/video-review.mjs +135 -0
- package/plugins/sf-video-review/skills/video-review/SKILL.md +65 -0
- package/plugins/sf-video-studio/.claude-plugin/plugin.json +17 -0
- package/plugins/sf-video-studio/.mcp.json +19 -0
- package/plugins/sf-video-studio/dist/demo-video.mjs +139 -0
- package/plugins/sf-video-studio/dist/narration-voice.mjs +134 -0
- package/plugins/sf-video-studio/dist/video-generation.mjs +131 -0
- package/plugins/sf-video-studio/fonts/DejaVuSansMono-Bold.ttf +0 -0
- package/plugins/sf-video-studio/fonts/DejaVuSansMono.ttf +0 -0
- package/plugins/sf-video-studio/fonts/LICENSE-DejaVu +187 -0
- package/plugins/sf-video-studio/hooks/hooks.json +17 -0
- package/plugins/sf-video-studio/hooks/no-robot-voice.sh +77 -0
- package/plugins/sf-video-studio/kokoro/package-lock.json +1137 -0
- package/plugins/sf-video-studio/kokoro/package.json +11 -0
- package/plugins/sf-video-studio/skills/demo-video/SKILL.md +101 -0
- package/plugins/sf-video-studio/skills/narration-voice/SKILL.md +49 -0
- package/plugins/sf-video-studio/skills/video-generation/SKILL.md +30 -0
- package/server/dist/account.js +3 -0
- package/server/dist/backup-process.js +2 -0
- package/server/dist/backup.js +3 -0
- package/server/dist/chunk-0tbq288f.js +3055 -0
- package/server/dist/chunk-18n7tr66.js +3 -0
- package/server/dist/chunk-1kgfrgmv.js +3 -0
- package/server/dist/chunk-1rnmxaav.js +209 -0
- package/server/dist/chunk-26zhqbyn.js +25 -0
- package/server/dist/chunk-34mn2zj2.js +2 -0
- package/server/dist/chunk-3psgsw9t.js +2 -0
- package/server/dist/chunk-8zbwppny.js +391 -0
- package/server/dist/chunk-9pn7q001.js +3 -0
- package/server/dist/chunk-9y7a9gkf.js +2 -0
- package/server/dist/chunk-bhm6jzch.js +8 -0
- package/server/dist/chunk-dbzjsqvb.js +17 -0
- package/server/dist/chunk-fxn504n0.js +2 -0
- package/server/dist/chunk-g6pwaap3.js +2 -0
- package/server/dist/chunk-gefgv8rg.js +7 -0
- package/server/dist/chunk-jg8b833v.js +2 -0
- package/server/dist/chunk-jy148bhn.js +3 -0
- package/server/dist/chunk-ky4nz39j.js +7 -0
- package/server/dist/chunk-mbd1y9qk.js +2 -0
- package/server/dist/chunk-neyhk32g.js +13 -0
- package/server/dist/chunk-nrz953bx.js +2 -0
- package/server/dist/chunk-padvv31s.js +2 -0
- package/server/dist/chunk-q1s2ez77.js +3 -0
- package/server/dist/chunk-q403h2bh.js +10 -0
- package/server/dist/chunk-t64r6enn.js +4 -0
- package/server/dist/chunk-vccappg7.js +59 -0
- package/server/dist/chunk-vj60fbhw.js +2 -0
- package/server/dist/chunk-xj26rwda.js +3 -0
- package/server/dist/chunk-xyw98jst.js +5 -0
- package/server/dist/main.js +43 -0
- package/server/dist/move.js +3 -0
- package/server/drizzle/pg/0000_baseline.sql +632 -0
- package/server/drizzle/pg/0001_transcripts_packed.sql +2 -0
- package/server/drizzle/pg/0002_vm_server_origin.sql +1 -0
- package/server/drizzle/pg/0003_reached_machines.sql +1 -0
- package/server/drizzle/pg/0004_link_records.sql +2 -0
- package/server/drizzle/pg/0005_task_columns.sql +7 -0
- package/server/drizzle/pg/0006_task_bundle.sql +3 -0
- package/server/drizzle/pg/0007_server_log.sql +9 -0
- package/server/drizzle/pg/0008_notification_pauses.sql +6 -0
- package/server/drizzle/pg/0009_vm_replaces.sql +1 -0
- package/server/drizzle/pg/0010_question_told_once.sql +10 -0
- package/server/drizzle/pg/0011_node_next_key.sql +3 -0
- package/server/drizzle/pg/0012_task_work.sql +8 -0
- package/server/drizzle/pg/0013_task_secret_grants.sql +9 -0
- package/server/drizzle/pg/0014_node_paused.sql +2 -0
- package/server/drizzle/pg/0015_ssh_machines.sql +19 -0
- package/server/drizzle/pg/0016_node_wake.sql +1 -0
- package/server/drizzle/pg/0017_node_uninstall_key.sql +1 -0
- package/server/drizzle/pg/0018_release_starts.sql +6 -0
- package/server/drizzle/pg/0019_session_memory.sql +7 -0
- package/server/drizzle/pg/meta/_journal.json +146 -0
- package/server/drizzle/sqlite/0000_pre_drizzle_schema.sql +351 -0
- package/server/drizzle/sqlite/0001_cluster.sql +36 -0
- package/server/drizzle/sqlite/0002_task_records.sql +22 -0
- package/server/drizzle/sqlite/0003_indexes.sql +12 -0
- package/server/drizzle/sqlite/0004_project_machines.sql +19 -0
- package/server/drizzle/sqlite/0005_session_events.sql +7 -0
- package/server/drizzle/sqlite/0006_task_platforms.sql +8 -0
- package/server/drizzle/sqlite/0007_session_event_tags.sql +7 -0
- package/server/drizzle/sqlite/0008_sprints.sql +7 -0
- package/server/drizzle/sqlite/0009_project_vms.sql +19 -0
- package/server/drizzle/sqlite/0010_server_repairs.sql +4 -0
- package/server/drizzle/sqlite/0011_drop_todos.sql +2 -0
- package/server/drizzle/sqlite/0012_hypervisors.sql +14 -0
- package/server/drizzle/sqlite/0013_manager_leads.sql +2 -0
- package/server/drizzle/sqlite/0014_session_text.sql +35 -0
- package/server/drizzle/sqlite/0015_vm_resize_machine_instructions_access.sql +22 -0
- package/server/drizzle/sqlite/0016_tunnel.sql +23 -0
- package/server/drizzle/sqlite/0017_session_secret_grants.sql +7 -0
- package/server/drizzle/sqlite/0018_https.sql +18 -0
- package/server/drizzle/sqlite/0019_secret_grant_runs.sql +1 -0
- package/server/drizzle/sqlite/0020_session_transcripts.sql +16 -0
- package/server/drizzle/sqlite/0021_claude_signed_out.sql +2 -0
- package/server/drizzle/sqlite/0022_machine_disabled.sql +1 -0
- package/server/drizzle/sqlite/0023_machine_access_granted_by.sql +1 -0
- package/server/drizzle/sqlite/0024_machine_vms.sql +27 -0
- package/server/drizzle/sqlite/0025_machine_tunnel_fallback.sql +1 -0
- package/server/drizzle/sqlite/0026_tunnel_peer_linked.sql +3 -0
- package/server/drizzle/sqlite/0027_tunnel_upgrade_grace.sql +2 -0
- package/server/drizzle/sqlite/0028_dialed_machines.sql +2 -0
- package/server/drizzle/sqlite/0029_node_link.sql +3 -0
- package/server/drizzle/sqlite/0030_sprint_calendar.sql +1 -0
- package/server/drizzle/sqlite/0031_transcripts_packed.sql +2 -0
- package/server/drizzle/sqlite/0032_vm_server_origin.sql +1 -0
- package/server/drizzle/sqlite/meta/_journal.json +237 -0
- package/server/src/account.ts +2 -0
- package/server/src/backup.ts +2 -0
- package/server/src/features/backups/backup-process.ts +2 -0
- package/server/src/main.ts +2 -0
- package/server/src/move.ts +2 -0
- package/ui/dist/_expo/static/css/global-d378e211074d97e633bc15418ccf57d4.css +2 -0
- package/ui/dist/_expo/static/css/xterm-8a7c4e0dca731c11dbe6bdff98fb667c.css +1 -0
- package/ui/dist/_expo/static/js/web/Network-f300a5960620f5029c91c06cae29dba5.js +3 -0
- package/ui/dist/_expo/static/js/web/[...rest]-9e454d985f211f5c983f42bec15b6ad9.js +1 -0
- package/ui/dist/_expo/static/js/web/[managerId]-2580b90e8d862ad66197eecb1dc04a12.js +1 -0
- package/ui/dist/_expo/static/js/web/[managerId]-39308153b42eed025c0abb9242ae6c71.js +1 -0
- package/ui/dist/_expo/static/js/web/[managerId]-8b7a94ec818e50a371b6b2750b73df6a.js +1 -0
- package/ui/dist/_expo/static/js/web/[managerId]-ac3a14c7607e4576d7e6c39c1014bcaf.js +1 -0
- package/ui/dist/_expo/static/js/web/[managerId]-e8549b2313a119437c373e30207518c0.js +1 -0
- package/ui/dist/_expo/static/js/web/[ref]-9b46f1ec4348f980e9838b68d47c34bf.js +2 -0
- package/ui/dist/_expo/static/js/web/[sessionId]-09e376674fb8b3edc4ae8aa9b3a189d7.js +1 -0
- package/ui/dist/_expo/static/js/web/[sessionId]-0e5fdba25c9f78220cea4cb66227743d.js +1 -0
- package/ui/dist/_expo/static/js/web/[sessionId]-104af3c3885009e6a8d204b6fd6e2c3a.js +1 -0
- package/ui/dist/_expo/static/js/web/[sessionId]-863a34ca3835b469134ddbc4ebc6fafc.js +1 -0
- package/ui/dist/_expo/static/js/web/[taskId]-1218e1dd3ecf175ffb7701fc886d62c9.js +1 -0
- package/ui/dist/_expo/static/js/web/[taskId]-31a48c7017dbd096f8ece9dc102a9762.js +1 -0
- package/ui/dist/_expo/static/js/web/[taskId]-a56cf85bcfd14f2d6b5d4180ea17e8d7.js +1 -0
- package/ui/dist/_expo/static/js/web/[taskId]-f2a157b3cb676b3c5d04c8eadfe90cdd.js +1 -0
- package/ui/dist/_expo/static/js/web/__common-1ad58e53e08528a67b99f53a1690b669.js +2078 -0
- package/ui/dist/_expo/static/js/web/__expo-metro-runtime-1f8f5d3ca6b7f58204d51e14506d73fb.js +5 -0
- package/ui/dist/_expo/static/js/web/_layout-057457e97e0af20433ed41b39cb5e809.js +1 -0
- package/ui/dist/_expo/static/js/web/_layout-2a7d73d5356823e1f7d2dab23e440d09.js +7 -0
- package/ui/dist/_expo/static/js/web/_layout-42e6a6b7855655d456015ce41aefdd39.js +1 -0
- package/ui/dist/_expo/static/js/web/_layout-a5e5a5b2fb3bfbfcc2914131976679e7.js +1 -0
- package/ui/dist/_expo/static/js/web/_layout-b2cbba92506f66815a5d744fd7cd5d8c.js +1 -0
- package/ui/dist/_expo/static/js/web/_layout-b4d13dc52bbcb65b18b4e52813d53883.js +198 -0
- package/ui/dist/_expo/static/js/web/_layout-fb0f75b354800de2e1582dc963f5c148.js +1 -0
- package/ui/dist/_expo/static/js/web/index-41299a961569cc8e5410ec53ba2b87c4.js +4 -0
- package/ui/dist/_expo/static/js/web/index-6c2bb0d3b6d00c5c007a663e9f4ce108.js +1 -0
- package/ui/dist/_expo/static/js/web/index-70484f7d2769d9ae01dac1fdb22aef1d.js +14 -0
- package/ui/dist/_expo/static/js/web/index-7d764cb7cefe0a217728c24d44990057.js +14 -0
- package/ui/dist/_expo/static/js/web/index-a5eb3d0c6aa4c483674beb5de428634c.js +12 -0
- package/ui/dist/_expo/static/js/web/index-b1c2543003cba86eeb3abfa4d21fd8da.js +14 -0
- package/ui/dist/_expo/static/js/web/index-d200aded5448966e5e05d9ccb77b56a4.js +5 -0
- package/ui/dist/_expo/static/js/web/index-ea43f51ceec4a981c942fc6dce9cedc4.js +2378 -0
- package/ui/dist/_expo/static/js/web/index-efa68d817a7febbf8c0163303bf4cd49.js +29 -0
- package/ui/dist/_expo/static/js/web/licenses-30f8c0555f7f4d434a68ee4706fa433d.js +1 -0
- package/ui/dist/_expo/static/js/web/pair-3f6f72208023894f43f4f07db5116cca.js +1 -0
- package/ui/dist/_expo/static/js/web/rich-markdown-editor-dea9c0f7c0306da4146e54ee44cce173.js +228 -0
- package/ui/dist/_expo/static/js/web/sign-in-67d2a0c00232e0e6f40efade1a83dc4b.js +4 -0
- package/ui/dist/_expo/static/js/web/terminal-view-32db8e6f8a21dd073f6a310862d36db8.js +90 -0
- package/ui/dist/apple-touch-icon.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/100Thin/GeistMono_100Thin.95eed4519d8c395e41b3b837ca97edea.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/100Thin_Italic/GeistMono_100Thin_Italic.2e50fb9a43d70ceb4925a2c54502097c.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/200ExtraLight/GeistMono_200ExtraLight.0714ea94ac265d76bc16698dd1808599.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/200ExtraLight_Italic/GeistMono_200ExtraLight_Italic.107f2670e94507223548f1d38eb14087.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/300Light/GeistMono_300Light.d6a3533adfd5834dd9f68ee37faa1e2d.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/300Light_Italic/GeistMono_300Light_Italic.09420cdceda8d1f1612daceae1e4890e.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/400Regular/GeistMono_400Regular.3656dcb247d3a6cd141f7601c2101125.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/400Regular_Italic/GeistMono_400Regular_Italic.88343c321b266476ad3bc56735cc6ac7.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/500Medium/GeistMono_500Medium.a298cd61aebdb709299e2a7deb73ed93.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/500Medium_Italic/GeistMono_500Medium_Italic.e149441dd9360bd7dbffeb1de9aa1685.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/600SemiBold/GeistMono_600SemiBold.cae945cb3b6156e396a1008b6252af21.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/600SemiBold_Italic/GeistMono_600SemiBold_Italic.e939ba436795ee2f0a379e7271bb957d.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/700Bold/GeistMono_700Bold.7fcc8478bc1dcadc865d97626ba3206b.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/700Bold_Italic/GeistMono_700Bold_Italic.8cc57ff1f3c45e7ed84e74853c141e06.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/800ExtraBold/GeistMono_800ExtraBold.b09b5457204e06ea7bacff03f0880065.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/800ExtraBold_Italic/GeistMono_800ExtraBold_Italic.0b4dd8c1b0e6d8791ea34c8f1417edfd.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/900Black/GeistMono_900Black.9ec025adf049c8a476588eeac81a36e4.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+geist-mono@0.4.3-2a25012349fb7712/node_modules/@expo-google-fonts/geist-mono/900Black_Italic/GeistMono_900Black_Italic.8dfe24b2fef43fb3d535316e2412be7d.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/100Thin/HankenGrotesk_100Thin.2d9c9415d97b66fb3bbca06b538f11d8.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/100Thin_Italic/HankenGrotesk_100Thin_Italic.5ad53da9f1ff702f55cf870763a159ff.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/200ExtraLight/HankenGrotesk_200ExtraLight.2cae1a1078b5af081aff084011b07522.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/200ExtraLight_Italic/HankenGrotesk_200ExtraLight_Italic.5d4eff887cdb33164b4fba2066c687e3.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/300Light/HankenGrotesk_300Light.2be9fd730ff95b91631e3f99bc449709.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/300Light_Italic/HankenGrotesk_300Light_Italic.4ae6910889ffdf69093da607b369b0a8.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/400Regular/HankenGrotesk_400Regular.2e544d6119b4e635f6cc5a47800523bb.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/400Regular_Italic/HankenGrotesk_400Regular_Italic.ed9d322cffe9e614205ce9512f144834.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/500Medium/HankenGrotesk_500Medium.a822d33614b51eb05478e0e29cf757f3.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/500Medium_Italic/HankenGrotesk_500Medium_Italic.bc71c45237e12974e52335b615fab7da.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/600SemiBold/HankenGrotesk_600SemiBold.b016ff502f15ce9b59c453304c74fb48.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/600SemiBold_Italic/HankenGrotesk_600SemiBold_Italic.94428d43b74e372dc47910fd4fc6b552.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/700Bold/HankenGrotesk_700Bold.14d2af6df606492d846389d2108dae50.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/700Bold_Italic/HankenGrotesk_700Bold_Italic.d075966aaf26126d8aaac0802735e310.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/800ExtraBold/HankenGrotesk_800ExtraBold.b419489745bc870b4e4288e969945f31.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/800ExtraBold_Italic/HankenGrotesk_800ExtraBold_Italic.ea7ac4778026e067a5d637f4a494b2d2.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/900Black/HankenGrotesk_900Black.55e860e6549b53fa530d9eda7c7518a2.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+hanken-grotesk@0.4.3-9a0105bf7cbf8f8b/node_modules/@expo-google-fonts/hanken-grotesk/900Black_Italic/HankenGrotesk_900Black_Italic.dcad6f722a66aae93f70a72604112754.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/200ExtraLight/Newsreader_200ExtraLight.1ee07dc260606863f8bf8101308d85f2.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/200ExtraLight_Italic/Newsreader_200ExtraLight_Italic.52c51abab458715d1205b8732b55735f.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/300Light/Newsreader_300Light.bf0dfa126654b01f65e1c53a4507ec12.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/300Light_Italic/Newsreader_300Light_Italic.03190fe46aa9b7083610981ac13b10f3.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/400Regular/Newsreader_400Regular.b1d919187d5645f84124ef065868ba9e.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/400Regular_Italic/Newsreader_400Regular_Italic.f7b81d92eb42d85de96b6dc1c72d2c36.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/500Medium/Newsreader_500Medium.df89e83cfd4e37176dda53076a01b3b7.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/500Medium_Italic/Newsreader_500Medium_Italic.fb45099c4fb3c395e8f12e181475230c.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/600SemiBold/Newsreader_600SemiBold.20bce29dc5180892ce1fbf4a563737a0.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/600SemiBold_Italic/Newsreader_600SemiBold_Italic.93e2816e201fa363d3289e741f757ff0.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/700Bold/Newsreader_700Bold.bf7c54edbd2afe9b289d5da777f489e9.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/700Bold_Italic/Newsreader_700Bold_Italic.e2f5e5260513d7d4f9f3edbdcbc9f43f.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/800ExtraBold/Newsreader_800ExtraBold.702211ca77927e4c276b28169dc3694c.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/@expo-google-fonts+newsreader@0.4.1-869d74885c3fd9d6/node_modules/@expo-google-fonts/newsreader/800ExtraBold_Italic/Newsreader_800ExtraBold_Italic.9b9eacc7d72e5152e692cb144ef7a9fd.ttf +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/arrow_down.017bc6ba3fc25503e5eb5e53826d48a8.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/error.d1ea1496f9057eb392d5bbf3732a61b7.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/file.19eeb73b9593a38f8e9f418337fc7d10.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/forward.d8b800c443b8972542883e0b9de2bdc6.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/pkg.ab19f4cbc543357183a20571f68380a3.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/drawer/toggle-drawer-icon.ae74bb20586a731af545e6b00fe14a09.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/back-icon-mask.0a328cd9c1afd0afe8e3b1ec5165b1b4.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/back-icon.35ba0eaec5a4f5ed12ca16fabeae451d.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@2x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@3x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/clear-icon.c94f6478e7ae0cdd9f15de1fcb9e5e55@4x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/close-icon.808e1b1b9b53114ec2838071a7e6daa7.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/close-icon.808e1b1b9b53114ec2838071a7e6daa7@2x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/close-icon.808e1b1b9b53114ec2838071a7e6daa7@3x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/close-icon.808e1b1b9b53114ec2838071a7e6daa7@4x.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/react-navigation/elements/search-icon.286d67d3f74808a60a78d3ebf1a5fb57.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/sitemap.412dd9275b6b48ad28f5e3d81bb1f626.png +0 -0
- package/ui/dist/assets/_____.bun/install/cache/links/expo-router@57.0.24+dc951f634b001cec-a06b318b98b13101/node_modules/expo-router/assets/unmatched.20e71bdf79e3a97bf55fd9e164041578.png +0 -0
- package/ui/dist/favicon.ico +0 -0
- package/ui/dist/favicon.svg +10 -0
- package/ui/dist/icon-192.png +0 -0
- package/ui/dist/icon-512.png +0 -0
- package/ui/dist/index.html +45 -0
- package/ui/dist/legal/privacy-policy.md +174 -0
- package/ui/dist/legal/terms-of-use.md +76 -0
- package/ui/dist/load-again.js +42 -0
- package/ui/dist/manifest.webmanifest +12 -0
- package/ui/dist/metadata.json +1 -0
- package/ui/dist/sounds/bell.wav +0 -0
- package/ui/dist/sounds/chime.wav +0 -0
- package/ui/dist/sounds/knock.wav +0 -0
- package/ui/dist/sounds/pop.wav +0 -0
- package/ui/dist/sw.js +121 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function Ut(e){return typeof e>"u"||e===void 0}function Y(e){return typeof e==="string"}function Hr(e){return typeof e==="number"}function qn(e){return typeof e==="boolean"}function Ts(e){return e===null}function xd(e){return e instanceof Date}function ks(e){return typeof e==="bigint"}function yy(e){return typeof Buffer<"u"&&Buffer.isBuffer(e)}function Se(e){return typeof e==="function"}function Me(e){return typeof e==="object"&&e!==null}function r(e){return Object.freeze(e)}function Fe(e){if(v(e))return e;else return[e]}function v(e){return Array.isArray(e)}function mt(e){return e}function er(e){return e instanceof Error?e.message:String(e)}var H=r({is(e){return e.kind==="IdentifierNode"},create(e){return r({kind:"IdentifierNode",name:e})}});var wy=["preserve rows","delete rows","drop"],ht=r({is(e){return e.kind==="CreateTableNode"},create(e){return r({kind:"CreateTableNode",table:e,columns:r([])})},cloneWithColumn(e,t){return r({...e,columns:r([...e.columns,t])})},cloneWithConstraint(e,t){return r({...e,constraints:e.constraints?r([...e.constraints,t]):r([t])})},cloneWithIndex(e,t){return r({...e,indexes:e.indexes?r([...e.indexes,t]):r([t])})},cloneWithFrontModifier(e,t){return r({...e,frontModifiers:e.frontModifiers?r([...e.frontModifiers,t]):r([t])})},cloneWithEndModifier(e,t){return r({...e,endModifiers:e.endModifiers?r([...e.endModifiers,t]):r([t])})},cloneWith(e,t){return r({...e,...t})}});var Rt=r({is(e){return e.kind==="SchemableIdentifierNode"},create(e){return r({kind:"SchemableIdentifierNode",identifier:H.create(e)})},createWithSchema(e,t){return r({kind:"SchemableIdentifierNode",schema:H.create(e),identifier:H.create(t)})}});var w=r({is(e){return e.kind==="AliasNode"},create(e,t){return r({kind:"AliasNode",node:e,alias:t})}});var Nt=r({is(e){return e.kind==="TableNode"},create(e){return r({kind:"TableNode",table:Rt.create(e)})},createWithSchema(e,t){return r({kind:"TableNode",table:Rt.createWithSchema(e,t)})}});function be(e){return Me(e)&&Se(e.toOperationNode)}function et(e){return Me(e)&&"expressionType"in e&&be(e)}function tr(e){return Me(e)&&"expression"in e&&Y(e.alias)&&be(e)}var _=r({is(e){return e.kind==="SelectModifierNode"},create(e,t){return r({kind:"SelectModifierNode",modifier:e,of:t})},createWithExpression(e){return r({kind:"SelectModifierNode",rawModifier:e})}});var S=r({is(e){return e.kind==="AndNode"},create(e,t){return r({kind:"AndNode",left:e,right:t})}});var P=r({is(e){return e.kind==="OrNode"},create(e,t){return r({kind:"OrNode",left:e,right:t})}});var tt=r({is(e){return e.kind==="OnNode"},create(e){return r({kind:"OnNode",on:e})},cloneWithOperation(e,t,i){return r({...e,on:t==="And"?S.create(e.on,i):P.create(e.on,i)})}});var I=r({is(e){return e.kind==="JoinNode"},create(e,t){return r({kind:"JoinNode",joinType:e,table:t,on:void 0})},createWithOn(e,t,i){return r({kind:"JoinNode",joinType:e,table:t,on:tt.create(i)})},cloneWithOn(e,t){return r({...e,on:e.on?tt.cloneWithOperation(e.on,"And",t):tt.create(t)})}});var ue=r({is(e){return e.kind==="BinaryOperationNode"},create(e,t,i){return r({kind:"BinaryOperationNode",leftOperand:e,operator:t,rightOperand:i})}});var rr=r({"=":!0,"==":!0,"!=":!0,"<>":!0,">":!0,">=":!0,"<":!0,"<=":!0,in:!0,"not in":!0,is:!0,"is not":!0,like:!0,"not like":!0,match:!0,ilike:!0,"not ilike":!0,"@>":!0,"<@":!0,"^@":!0,"&&":!0,"?":!0,"?&":!0,"?|":!0,"!<":!0,"!>":!0,"<=>":!0,"!~":!0,"~":!0,"~*":!0,"!~*":!0,"@@":!0,"@@@":!0,"!!":!0,"<->":!0,regexp:!0,"is distinct from":!0,"is not distinct from":!0}),Eo=Object.keys(rr),ir=r({"+":!0,"-":!0,"*":!0,"/":!0,"%":!0,"^":!0,"&":!0,"|":!0,"#":!0,"<<":!0,">>":!0}),ko=Object.keys(ir),or=r({"->":!0,"->>":!0}),fi=Object.keys(or),nr=r({...rr,...ir,"||":!0}),ci=Object.keys(nr),sr=r({exists:!0,"not exists":!0}),Lo=Object.keys(sr),dr=r({...sr,"-":!0,not:!0}),li=Object.keys(dr),Do=[...ci,...fi,...li,"between","between symmetric"],T=r({is(e){return e.kind==="OperatorNode"},create(e){return r({kind:"OperatorNode",operator:e})}});function ur(e){return Y(e)&&nr[e]}function hr(e){return Y(e)&&or[e]}function pr(e){return Y(e)&&dr[e]}var se=r({is(e){return e.kind==="ColumnNode"},create(e){return r({kind:"ColumnNode",column:H.create(e)})}});var yo=r({is(e){return e.kind==="SelectAllNode"},create(){return r({kind:"SelectAllNode"})}});var xs=r({is(e){return e.kind==="ReferenceNode"},create(e,t){return r({kind:"ReferenceNode",table:t,column:e})},createSelectAll(e){return r({kind:"ReferenceNode",table:e,column:yo.create()})}});class Ip{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return wt(this.#e)}}function rt(e){return Me(e)&&be(e)&&Y(e.dynamicReference)}var V=r({is(e){return e.kind==="OrderByItemNode"},create(e,t){return r({kind:"OrderByItemNode",orderBy:e,direction:t})},cloneWith(e,t){return r({...e,...t})}});var ce=r({is(e){return e.kind==="RawNode"},create(e,t){return r({kind:"RawNode",sqlFragments:r(e),parameters:r(t)})},createWithSql(e){return ce.create([e],[])},createWithChild(e){return ce.create(["",""],[e])},createWithChildren(e){return ce.create(Array(e.length+1).fill(""),e)}});var mr=r({is(e){return e.kind==="CollateNode"},create(e){return r({kind:"CollateNode",collation:H.create(e)})}});class he{#e;constructor(e){this.#e=r(e)}desc(){return new he({node:V.cloneWith(this.#e.node,{direction:ce.createWithSql("desc")})})}asc(){return new he({node:V.cloneWith(this.#e.node,{direction:ce.createWithSql("asc")})})}nullsLast(){return new he({node:V.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new he({node:V.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new he({node:V.cloneWith(this.#e.node,{collation:mr.create(e)})})}toOperationNode(){return this.#e.node}}var fr=new Set;function wo(e){if(fr.has(e))return;fr.add(e),console.log(e)}function vt(e){return e==="asc"||e==="desc"}function E(e){if(e.length===2)return[xt(e[0],e[1])];if(e.length===1){let[t]=e;if(Array.isArray(t))return wo("orderBy(array) is deprecated, use multiple orderBy calls instead."),t.map((i)=>xt(i));return[xt(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function xt(e,t){let i=Ni(e);if(V.is(i)){if(t)throw Error("Cannot specify direction twice!");return i}return cr(i,t)}function Ni(e){if(te(e))return gt(e);if(rt(e))return e.toOperationNode();let[t,i]=e.split(" ");if(i)return wo("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),cr(Jt(t),i);return Jt(e)}function cr(e,t){if(typeof t==="string"){if(!vt(t))throw Error(`Invalid order by direction: ${t}`);return V.create(e,ce.createWithSql(t))}if(et(t))return wo("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),V.create(e,t.toOperationNode());let i=V.create(e);if(!t)return i;return t(new he({node:i})).toOperationNode()}var Te=r({is(e){return e.kind==="JSONReferenceNode"},create(e,t){return r({kind:"JSONReferenceNode",reference:e,traversal:t})},cloneWithTraversal(e,t){return r({...e,traversal:t})}});var it=r({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return r({kind:"JSONOperatorChainNode",operator:e,values:r([])})},cloneWithValue(e,t){return r({...e,values:r([...e.values,t])})}});var me=r({is(e){return e.kind==="JSONPathNode"},create(e){return r({kind:"JSONPathNode",inOperator:e,pathLegs:r([])})},cloneWithLeg(e,t){return r({...e,pathLegs:r([...e.pathLegs,t])})}});function wt(e){if(Y(e))return Jt(e);return e.toOperationNode()}function re(e){if(v(e))return e.map((t)=>l(t));else return[l(e)]}function l(e){if(te(e))return gt(e);return wt(e)}function lr(e,t){if(hr(t))return Te.create(Jt(e),it.create(T.create(t)));if(t==="->$"||t==="->>$")return Te.create(Jt(e),me.create(T.create(t.slice(0,-1))));throw Error(`Invalid JSON operator: ${t}`)}function Jt(e){if(!e.includes("."))return xs.create(se.create(e));let i=e.split(".").map(Wt);if(i.length===3)return yi(i);if(i.length===2)return wi(i);throw Error(`invalid column reference ${e}`)}function Nr(e){if(e.includes(" as ")){let[i,o]=e.split(" as ").map(Wt);return w.create(Jt(i),H.create(o))}else return Jt(e)}function Pp(e){return se.create(e)}function So(e){if(e.includes(" ")){let[i,o]=e.split(" ").map(Wt);if(!vt(o))throw Error(`invalid order direction "${o}" next to "${i}"`);return E([i,o])[0]}else return Pp(e)}function yi(e){let[t,i,o]=e;return xs.create(se.create(o),Nt.createWithSchema(t,i))}function wi(e){let[t,i]=e;return xs.create(se.create(i),Nt.create(t))}function Wt(e){return e.trim()}var ot=r({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return r({kind:"PrimitiveValueListNode",values:r([...e])})}});var Is=r({is(e){return e.kind==="ValueListNode"},create(e){return r({kind:"ValueListNode",values:r(e)})}});var Ne=r({is(e){return e.kind==="ValueNode"},create(e){return r({kind:"ValueNode",value:e})},createImmediate(e){return r({kind:"ValueNode",value:e,immediate:!0})}});function yr(e){if(v(e))return xi(e);return u(e)}function u(e){if(te(e))return gt(e);return Ne.create(e)}function nt(e){return Hr(e)||qn(e)||Ts(e)}function Ue(e){if(!nt(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return Ne.createImmediate(e)}function xi(e){if(e.some(te))return Is.create(e.map((t)=>u(t)));return ot.create(e)}var k=r({is(e){return e.kind==="ParensNode"},create(e){return r({kind:"ParensNode",node:e})}});function _e(e){if(e.length===3)return st(e[0],e[1],e[2]);else if(e.length===1)return u(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function st(e,t,i){if(Oi(t)&&xr(i))return ue.create(l(e),St(t),Ne.createImmediate(i));return ue.create(l(e),St(t),yr(i))}function c(e,t,i){return ue.create(l(e),St(t),l(i))}function Ct(e,t){return Ee(Object.entries(e).filter(([,i])=>!Ut(i)).map(([i,o])=>st(i,xr(o)?"is":"=",o)),t)}function Ee(e,t,i=!0){let o=t==="and"?S.create:P.create;if(e.length===0)return ue.create(Ne.createImmediate(1),T.create("="),Ne.createImmediate(t==="and"?1:0));let n=wr(e[0]);for(let s=1;s<e.length;++s)n=o(n,wr(e[s]));if(e.length>1&&i)return k.create(n);return n}function Oi(e){return e==="is"||e==="is not"}function xr(e){return Ts(e)||qn(e)}function St(e){if(ur(e))return T.create(e);if(be(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function wr(e){return be(e)?e.toOperationNode():e}var ie=r({is(e){return e.kind==="OrderByNode"},create(e){return r({kind:"OrderByNode",items:r([...e])})},cloneWithItems(e,t){return r({...e,items:r([...e.items,...t])})}});var At=r({is(e){return e.kind==="PartitionByNode"},create(e){return r({kind:"PartitionByNode",items:r(e)})},cloneWithItems(e,t){return r({...e,items:r([...e.items,...t])})}});var Je=r({is(e){return e.kind==="OverNode"},create(){return r({kind:"OverNode"})},cloneWithOrderByItems(e,t){return r({...e,orderBy:e.orderBy?ie.cloneWithItems(e.orderBy,t):ie.create(t)})},cloneWithPartitionByItems(e,t){return r({...e,partitionBy:e.partitionBy?At.cloneWithItems(e.partitionBy,t):At.create(t)})}});var ve=r({is(e){return e.kind==="FromNode"},create(e){return r({kind:"FromNode",froms:r(e)})},cloneWithFroms(e,t){return r({...e,froms:r([...e.froms,...t])})}});var Tt=r({is(e){return e.kind==="GroupByNode"},create(e){return r({kind:"GroupByNode",items:r(e)})},cloneWithItems(e,t){return r({...e,items:r([...e.items,...t])})}});var Et=r({is(e){return e.kind==="HavingNode"},create(e){return r({kind:"HavingNode",having:e})},cloneWithOperation(e,t,i){return r({...e,having:t==="And"?S.create(e.having,i):P.create(e.having,i)})}});var p=r({is(e){return e.kind==="InsertQueryNode"},create(e,t,i){return r({kind:"InsertQueryNode",into:e,...t&&{with:t},replace:i})},createWithoutInto(){return r({kind:"InsertQueryNode"})},cloneWith(e,t){return r({...e,...t})}});var at=r({is(e){return e.kind==="ListNode"},create(e){return r({kind:"ListNode",items:r(e)})}});var Q=r({is(e){return e.kind==="UpdateQueryNode"},create(e,t){return r({kind:"UpdateQueryNode",table:e.length===1?e[0]:at.create(e),...t&&{with:t}})},createWithoutTable(){return r({kind:"UpdateQueryNode"})},cloneWithFromItems(e,t){return r({...e,from:e.from?ve.cloneWithFroms(e.from,t):ve.create(t)})},cloneWithUpdates(e,t){return r({...e,updates:e.updates?r([...e.updates,...t]):t})},cloneWithLimit(e,t){return r({...e,limit:t})}});var ze=r({is(e){return e.kind==="UsingNode"},create(e){return r({kind:"UsingNode",tables:r(e)})},cloneWithTables(e,t){return r({...e,tables:r([...e.tables,...t])})}});var le=r({is(e){return e.kind==="DeleteQueryNode"},create(e,t){return r({kind:"DeleteQueryNode",from:ve.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>M.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:(e)=>M.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return r({...e,limit:t})},cloneWithoutLimit(e){return r({...e,limit:void 0})},cloneWithUsing(e,t){return r({...e,using:e.using!==void 0?ze.cloneWithTables(e.using,t):ze.create(t)})}});var O=r({is(e){return e.kind==="WhereNode"},create(e){return r({kind:"WhereNode",where:e})},cloneWithOperation(e,t,i){return r({...e,where:t==="And"?S.create(e.where,i):P.create(e.where,i)})}});var kt=r({is(e){return e.kind==="ReturningNode"},create(e){return r({kind:"ReturningNode",selections:r(e)})},cloneWithSelections(e,t){return r({...e,selections:e.selections?r([...e.selections,...t]):r(t)})}});var Or=r({is(e){return e.kind==="ExplainNode"},create(e,t){return r({kind:"ExplainNode",format:e,options:t})}});var C=r({is(e){return e.kind==="WhenNode"},create(e){return r({kind:"WhenNode",condition:e})},cloneWithResult(e,t){return r({...e,result:t})}});var L=r({is(e){return e.kind==="MergeQueryNode"},create(e,t){return r({kind:"MergeQueryNode",into:e,...t&&{with:t}})},cloneWithUsing(e,t){return r({...e,using:t})},cloneWithWhen(e,t){return r({...e,whens:e.whens?r([...e.whens,t]):r([t])})},cloneWithThen(e,t){return r({...e,whens:e.whens?r([...e.whens.slice(0,-1),C.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}});var Lt=r({is(e){return e.kind==="OutputNode"},create(e){return r({kind:"OutputNode",selections:r(e)})},cloneWithSelections(e,t){return r({...e,selections:e.selections?r([...e.selections,...t]):r(t)})}});var M=r({is(e){return pe.is(e)||p.is(e)||Q.is(e)||le.is(e)||L.is(e)},cloneWithEndModifier(e,t){return r({...e,endModifiers:e.endModifiers?r([...e.endModifiers,t]):r([t])})},cloneWithWhere(e,t){return r({...e,where:e.where?O.cloneWithOperation(e.where,"And",t):O.create(t)})},cloneWithJoin(e,t){return r({...e,joins:e.joins?r([...e.joins,t]):r([t])})},cloneWithReturning(e,t){return r({...e,returning:e.returning?kt.cloneWithSelections(e.returning,t):kt.create(t)})},cloneWithoutReturning(e){return r({...e,returning:void 0})},cloneWithoutWhere(e){return r({...e,where:void 0})},cloneWithExplain(e,t,i){return r({...e,explain:Or.create(t,i?.toOperationNode())})},cloneWithTop(e,t){return r({...e,top:t})},cloneWithOutput(e,t){return r({...e,output:e.output?Lt.cloneWithSelections(e.output,t):Lt.create(t)})},cloneWithOrderByItems(e,t){return r({...e,orderBy:e.orderBy?ie.cloneWithItems(e.orderBy,t):ie.create(t)})},cloneWithoutOrderBy(e){return r({...e,orderBy:void 0})}});var pe=r({is(e){return e.kind==="SelectQueryNode"},create(e){return r({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,t){return r({kind:"SelectQueryNode",from:ve.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return r({...e,selections:e.selections?r([...e.selections,...t]):r(t)})},cloneWithDistinctOn(e,t){return r({...e,distinctOn:e.distinctOn?r([...e.distinctOn,...t]):r(t)})},cloneWithFrontModifier(e,t){return r({...e,frontModifiers:e.frontModifiers?r([...e.frontModifiers,t]):r([t])})},cloneWithOrderByItems:(e,t)=>M.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return r({...e,groupBy:e.groupBy?Tt.cloneWithItems(e.groupBy,t):Tt.create(t)})},cloneWithLimit(e,t){return r({...e,limit:t})},cloneWithOffset(e,t){return r({...e,offset:t})},cloneWithFetch(e,t){return r({...e,fetch:t})},cloneWithHaving(e,t){return r({...e,having:e.having?Et.cloneWithOperation(e.having,"And",t):Et.create(t)})},cloneWithSetOperations(e,t){return r({...e,setOperations:e.setOperations?r([...e.setOperations,...t]):r([...t])})},cloneWithoutSelections(e){return r({...e,selections:[]})},cloneWithoutLimit(e){return r({...e,limit:void 0})},cloneWithoutOffset(e){return r({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>M.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return r({...e,groupBy:void 0})}});class ke{#e;constructor(e){this.#e=r(e)}on(...e){return new ke({...this.#e,joinNode:I.cloneWithOn(this.#e.joinNode,_e(e))})}onRef(e,t,i){return new ke({...this.#e,joinNode:I.cloneWithOn(this.#e.joinNode,c(e,t,i))})}onTrue(){return new ke({...this.#e,joinNode:I.cloneWithOn(this.#e.joinNode,ce.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}}var gr=r({is(e){return e.kind==="PartitionByItemNode"},create(e){return r({kind:"PartitionByItemNode",partitionBy:e})}});function vr(e){return re(e).map(gr.create)}class Le{#e;constructor(e){this.#e=r(e)}orderBy(...e){return new Le({overNode:Je.cloneWithOrderByItems(this.#e.overNode,E(e))})}clearOrderBy(){return new Le({overNode:M.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new Le({overNode:Je.cloneWithPartitionByItems(this.#e.overNode,vr(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var De=r({is(e){return e.kind==="SelectionNode"},create(e){return r({kind:"SelectionNode",selection:e})},createSelectAll(){return r({kind:"SelectionNode",selection:yo.create()})},createSelectAllFromTable(e){return r({kind:"SelectionNode",selection:xs.createSelectAll(e)})}});function N(e){if(Se(e))return N(e(F()));else if(v(e))return e.map((t)=>br(t));else return[br(e)]}function br(e){if(Y(e))return De.create(Nr(e));else if(rt(e))return De.create(e.toOperationNode());else return De.create(dt(e))}function x(e){if(!e)return[De.createSelectAll()];else if(Array.isArray(e))return e.map(Wr);else return[Wr(e)]}function Wr(e){if(Y(e))return De.createSelectAllFromTable(fe(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Sr=r({is(e){return e.kind==="ValuesNode"},create(e){return r({kind:"ValuesNode",values:r(e)})}});var Cr=r({is(e){return e.kind==="DefaultInsertValueNode"},create(){return r({kind:"DefaultInsertValueNode"})}});function ut(e){let t=Se(e)?e(F()):e,i=v(t)?t:r([t]);return gi(i)}function gi(e){let t=vi(e);return[r([...t.keys()].map(se.create)),Sr.create(e.map((i)=>bi(i,t)))]}function vi(e){let t=new Map;for(let i of e){let o=Object.keys(i);for(let n of o)if(!t.has(n)&&i[n]!==void 0)t.set(n,t.size)}return t}function bi(e,t){let i=Object.keys(e),o=Array.from({length:t.size}),n=!1,s=i.length;for(let y of i){let W=t.get(y);if(Ut(W)){s--;continue}let q=e[y];if(Ut(q)||te(q))n=!0;o[W]=q}if(s<t.size||n){let y=Cr.create();return Is.create(o.map((W)=>Ut(W)?y:u(W)))}return ot.create(o)}var Dt=r({is(e){return e.kind==="ColumnUpdateNode"},create(e,t){return r({kind:"ColumnUpdateNode",column:e,value:t})}});function Rr(...e){if(e.length===2)return[Dt.create(l(e[0]),u(e[1]))];return Qe(e[0])}function Qe(e){let t=Se(e)?e(F()):e;return Object.entries(t).filter(([i,o])=>o!==void 0).map(([i,o])=>Dt.create(se.create(i),u(o)))}var Ar=r({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return r({kind:"OnDuplicateKeyNode",updates:e})}});class Bt{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}}class U extends Error{node;constructor(e){super("no result");this.node=e}}function j(e){return Object.prototype.hasOwnProperty.call(e,"prototype")}var b=r({is(e){return e.kind==="OnConflictNode"},create(){return r({kind:"OnConflictNode"})},cloneWith(e,t){return r({...e,...t})},cloneWithIndexWhere(e,t){return r({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",t):O.create(t)})},cloneWithIndexOrWhere(e,t){return r({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",t):O.create(t)})},cloneWithUpdateWhere(e,t){return r({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",t):O.create(t)})},cloneWithUpdateOrWhere(e,t){return r({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",t):O.create(t)})},cloneWithoutIndexWhere(e){return r({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return r({...e,updateWhere:void 0})}});class K{#e;constructor(e){this.#e=r(e)}column(e){let t=se.create(e);return new K({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,t]):r([t])})})}columns(e){let t=e.map(se.create);return new K({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?r([...this.#e.onConflictNode.columns,...t]):r(t)})})}constraint(e){return new K({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{constraint:H.create(e)})})}expression(e){return new K({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new K({...this.#e,onConflictNode:b.cloneWithIndexWhere(this.#e.onConflictNode,_e(e))})}whereRef(e,t,i){return new K({...this.#e,onConflictNode:b.cloneWithIndexWhere(this.#e.onConflictNode,c(e,t,i))})}clearWhere(){return new K({...this.#e,onConflictNode:b.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Tr({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new $e({...this.#e,onConflictNode:b.cloneWith(this.#e.onConflictNode,{updates:Qe(e)})})}$call(e){return e(this)}}class Tr{#e;constructor(e){this.#e=r(e)}toOperationNode(){return this.#e.onConflictNode}}class $e{#e;constructor(e){this.#e=r(e)}where(...e){return new $e({...this.#e,onConflictNode:b.cloneWithUpdateWhere(this.#e.onConflictNode,_e(e))})}whereRef(e,t,i){return new $e({...this.#e,onConflictNode:b.cloneWithUpdateWhere(this.#e.onConflictNode,c(e,t,i))})}clearWhere(){return new $e({...this.#e,onConflictNode:b.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var Er=r({is(e){return e.kind==="TopNode"},create(e,t){return r({kind:"TopNode",expression:e,modifiers:t})}});function J(e,t){if(!Hr(e)&&!ks(e))throw Error(`Invalid top expression: ${e}`);if(!Ut(t)&&!Wi(t))throw Error(`Invalid top modifiers: ${t}`);return Er.create(e,t)}function Wi(e){return e==="percent"||e==="with ties"||e==="percent with ties"}var We=r({is(e){return e.kind==="OrActionNode"},create(e){return r({kind:"OrActionNode",action:e})}});class h{#e;constructor(e){this.#e=r(e)}values(e){let[t,i]=ut(e);return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{columns:t,values:i})})}columns(e){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{columns:r(e.map(se.create))})})}expression(e){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{values:gt(e)})})}defaultValues(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new h({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("ignore")})})}orIgnore(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("ignore")})})}orAbort(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("abort")})})}orFail(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("fail")})})}orReplace(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("replace")})})}orRollback(){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{orAction:We.create("rollback")})})}top(e,t){return new h({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}onConflict(e){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{onConflict:e(new K({onConflictNode:b.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new h({...this.#e,queryNode:p.cloneWith(this.#e.queryNode,{onDuplicateKey:Ar.create(Qe(e))})})}returning(e){return new h({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,N(e))})}returningAll(){return new h({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,x())})}output(e){return new h({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,N(e))})}outputAll(e){return new h({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,x(e))})}clearReturning(){return new h({...this.#e,queryNode:M.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new h({...this.#e})}$castTo(){return new h(this.#e)}$narrowType(){return new h(this.#e)}$assertType(){return new h(this.#e)}withPlugin(e){return new h({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){let t=this.compile(),i=await this.#e.executor.executeQuery(t,e),{adapter:o}=this.#e.executor,n=t.query;if(n.returning&&o.supportsReturning||n.output&&o.supportsOutput)return i.rows;return[new Bt(i.insertId,i.numAffectedRows??BigInt(0))]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){if(typeof e==="function")e={errorConstructor:e};let t=await this.executeTakeFirst(e);if(t===void 0){let i=e?.errorConstructor??U;throw j(i)?new i(this.toOperationNode()):i(this.toOperationNode())}return t}async*stream(e){if(typeof e!=="object")e={chunkSize:e};let t=this.compile(),i=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let o of i)yield*o.rows}async explain(e,t){return await new h({...this.#e,queryNode:M.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}class qt{numDeletedRows;constructor(e){this.numDeletedRows=e}}var Be=r({is(e){return e.kind==="LimitNode"},create(e){return r({kind:"LimitNode",limit:e})}});var m;class pt{#e;constructor(e){this.#e=r(e)}where(...e){return new m({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,_e(e))})}whereRef(e,t,i){return new m({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,c(e,t,i))})}clearWhere(){return new m({...this.#e,queryNode:M.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new m({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}using(e){return new m({...this.#e,queryNode:le.cloneWithUsing(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new m({...this.#e,queryNode:M.cloneWithJoin(this.#e.queryNode,ye(e,t))})}returning(e){return new m({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,N(e))})}returningAll(e){return new m({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,x(e))})}output(e){return new m({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,N(e))})}outputAll(e){return new m({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,x(e))})}clearReturning(){return new m({...this.#e,queryNode:M.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new m({...this.#e,queryNode:le.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new m({...this.#e,queryNode:M.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new m({...this.#e,queryNode:M.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new m({...this.#e,queryNode:le.cloneWithLimit(this.#e.queryNode,Be.create(u(e)))})}modifyEnd(e){return new m({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new m({...this.#e})}$castTo(){return new m(this.#e)}$narrowType(){return new m(this.#e)}$assertType(){return new m(this.#e)}withPlugin(e){return new m({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){let t=this.compile(),i=await this.#e.executor.executeQuery(t,e),{adapter:o}=this.#e.executor,n=t.query;if(n.returning&&o.supportsReturning||n.output&&o.supportsOutput)return i.rows;return[new qt(i.numAffectedRows??BigInt(0))]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){if(typeof e==="function")e={errorConstructor:e};let t=await this.executeTakeFirst(e);if(t===void 0){let i=e?.errorConstructor??U;throw j(i)?new i(this.toOperationNode()):i(this.toOperationNode())}return t}async*stream(e){if(typeof e!=="object")e={chunkSize:e};let t=this.compile(),i=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let o of i)yield*o.rows}async explain(e,t){return await new m({...this.#e,queryNode:M.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}m=pt;class Pt{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}}var f;class qe{#e;constructor(e){this.#e=r(e)}where(...e){return new f({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,_e(e))})}whereRef(e,t,i){return new f({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,c(e,t,i))})}clearWhere(){return new f({...this.#e,queryNode:M.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new f({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}from(e){return new f({...this.#e,queryNode:Q.cloneWithFromItems(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}#t(e,t){return new f({...this.#e,queryNode:M.cloneWithJoin(this.#e.queryNode,ye(e,t))})}orderBy(...e){return new f({...this.#e,queryNode:M.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new f({...this.#e,queryNode:M.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new f({...this.#e,queryNode:Q.cloneWithLimit(this.#e.queryNode,Be.create(u(e)))})}set(...e){return new f({...this.#e,queryNode:Q.cloneWithUpdates(this.#e.queryNode,Rr(...e))})}returning(e){return new f({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,N(e))})}returningAll(e){return new f({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,x(e))})}output(e){return new f({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,N(e))})}outputAll(e){return new f({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,x(e))})}modifyEnd(e){return new f({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new f({...this.#e,queryNode:M.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new f({...this.#e})}$castTo(){return new f(this.#e)}$narrowType(){return new f(this.#e)}$assertType(){return new f(this.#e)}withPlugin(e){return new f({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){let t=this.compile(),i=await this.#e.executor.executeQuery(t,e),{adapter:o}=this.#e.executor,n=t.query;if(n.returning&&o.supportsReturning||n.output&&o.supportsOutput)return i.rows;return[new Pt(i.numAffectedRows??BigInt(0),i.numChangedRows)]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){if(typeof e==="function")e={errorConstructor:e};let t=await this.executeTakeFirst(e);if(t===void 0){let i=e?.errorConstructor??U;throw j(i)?new i(this.toOperationNode()):i(this.toOperationNode())}return t}async*stream(e){if(typeof e!=="object")e={chunkSize:e};let t=this.compile(),i=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let o of i)yield*o.rows}async explain(e,t){return await new f({...this.#e,queryNode:M.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}f=qe;var It=r({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,t){return r({kind:"CommonTableExpressionNameNode",table:Nt.create(e),columns:t?r(t.map(se.create)):void 0})}});var Pe=r({is(e){return e.kind==="CommonTableExpressionNode"},create(e,t){return r({kind:"CommonTableExpressionNode",name:e,expression:t})},cloneWith(e,t){return r({...e,...t})}});class je{#e;constructor(e){this.#e=r(e)}materialized(){return new je({...this.#e,node:Pe.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new je({...this.#e,node:Pe.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function Vt(e,t){let i=be(t)?t.toOperationNode():t(Lr()).toOperationNode();if(Se(e))return e(Si(i)).toOperationNode();return Pe.create(kr(e),i)}function Si(e){return(t)=>new je({node:Pe.create(kr(t),e)})}function kr(e){if(e.includes("(")){let t=e.split(/[\(\)]/),i=t[0],o=t[1].split(",").map((n)=>n.trim());return It.create(i,o)}else return It.create(e)}var Ge=r({is(e){return e.kind==="WithNode"},create(e,t){return r({kind:"WithNode",expressions:r([e]),...t})},cloneWithExpression(e,t){return r({...e,expressions:r([...e.expressions,t])})}});var Dr=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Id(e){let t="";for(let i=0;i<e;++i)t+=Ci();return t}function Ci(){return Dr[~~(Math.random()*Dr.length)]}function G(){return new Br}class Br{#e;get queryId(){if(this.#e===void 0)this.#e=Id(8);return this.#e}}class Qa{nodeStack=[];#e=r({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this),AlterTypeNode:this.transformAlterType.bind(this),AddValueNode:this.transformAddValue.bind(this),RenameValueNode:this.transformRenameValue.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let i=this.transformNodeImpl(e,t);return this.nodeStack.pop(),r(i)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){if(!e)return e;return r(e.map((i)=>this.transformNode(i,t)))}transformSelectQuery(e,t){return{kind:"SelectQueryNode",from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)}}transformSelection(e,t){return{kind:"SelectionNode",selection:this.transformNode(e.selection,t)}}transformColumn(e,t){return{kind:"ColumnNode",column:this.transformNode(e.column,t)}}transformAlias(e,t){return{kind:"AliasNode",node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)}}transformTable(e,t){return{kind:"TableNode",table:this.transformNode(e.table,t)}}transformFrom(e,t){return{kind:"FromNode",froms:this.transformNodeList(e.froms,t)}}transformReference(e,t){return{kind:"ReferenceNode",column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)}}transformAnd(e,t){return{kind:"AndNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformOr(e,t){return{kind:"OrNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformValueList(e,t){return{kind:"ValueListNode",values:this.transformNodeList(e.values,t)}}transformParens(e,t){return{kind:"ParensNode",node:this.transformNode(e.node,t)}}transformJoin(e,t){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)}}transformRaw(e,t){return{kind:"RawNode",sqlFragments:r([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)}}transformWhere(e,t){return{kind:"WhereNode",where:this.transformNode(e.where,t)}}transformInsertQuery(e,t){return{kind:"InsertQueryNode",into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformValues(e,t){return{kind:"ValuesNode",values:this.transformNodeList(e.values,t)}}transformDeleteQuery(e,t){return{kind:"DeleteQueryNode",from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformReturning(e,t){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections,t)}}transformCreateTable(e,t){return{kind:"CreateTableNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),indexes:this.transformNodeList(e.indexes,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)}}transformColumnDefinition(e,t){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e,t){return{kind:"AddColumnNode",column:this.transformNode(e.column,t)}}transformDropTable(e,t){return{kind:"DropTableNode",table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade,temporary:e.temporary}}transformOrderBy(e,t){return{kind:"OrderByNode",items:this.transformNodeList(e.items,t)}}transformOrderByItem(e,t){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls}}transformGroupBy(e,t){return{kind:"GroupByNode",items:this.transformNodeList(e.items,t)}}transformGroupByItem(e,t){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,t)}}transformUpdateQuery(e,t){return{kind:"UpdateQueryNode",table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)}}transformColumnUpdate(e,t){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)}}transformLimit(e,t){return{kind:"LimitNode",limit:this.transformNode(e.limit,t)}}transformOffset(e,t){return{kind:"OffsetNode",offset:this.transformNode(e.offset,t)}}transformOnConflict(e,t){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing}}transformOnDuplicateKey(e,t){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,t)}}transformCreateIndex(e,t){return{kind:"CreateIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct}}transformList(e,t){return{kind:"ListNode",items:this.transformNodeList(e.items,t)}}transformDropIndex(e,t){return{kind:"DropIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e,t){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformUniqueConstraint(e,t){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformForeignKeyConstraint(e,t){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformSetOperation(e,t){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all}}transformReferences(e,t){return{kind:"ReferencesNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e,t){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)}}transformWith(e,t){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive}}transformCommonTableExpression(e,t){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)}}transformCommonTableExpressionName(e,t){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)}}transformHaving(e,t){return{kind:"HavingNode",having:this.transformNode(e.having,t)}}transformCreateSchema(e,t){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists}}transformDropSchema(e,t){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e,t){return{kind:"AlterTableNode",table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)}}transformDropColumn(e,t){return{kind:"DropColumnNode",column:this.transformNode(e.column,t),ifExists:e.ifExists}}transformRenameColumn(e,t){return{kind:"RenameColumnNode",column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)}}transformAlterColumn(e,t){return{kind:"AlterColumnNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e,t){return{kind:"ModifyColumnNode",column:this.transformNode(e.column,t)}}transformAddConstraint(e,t){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,t)}}transformDropConstraint(e,t){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier}}transformRenameConstraint(e,t){return{kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)}}transformCreateView(e,t){return{kind:"CreateViewNode",name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)}}transformRefreshMaterializedView(e,t){return{kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData}}transformDropView(e,t){return{kind:"DropViewNode",name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e,t){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)}}transformDefaultValue(e,t){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,t)}}transformOn(e,t){return{kind:"OnNode",on:this.transformNode(e.on,t)}}transformSelectModifier(e,t){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)}}transformCreateType(e,t){return{kind:"CreateTypeNode",name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)}}transformDropType(e,t){return{kind:"DropTypeNode",name:this.transformNode(e.name,t),additionalNames:this.transformNodeList(e.additionalNames,t),cascade:e.cascade,ifExists:e.ifExists}}transformExplain(e,t){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,t)}}transformSchemableIdentifier(e,t){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)}}transformAggregateFunction(e,t){return{kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)}}transformOver(e,t){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)}}transformPartitionBy(e,t){return{kind:"PartitionByNode",items:this.transformNodeList(e.items,t)}}transformPartitionByItem(e,t){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,t)}}transformBinaryOperation(e,t){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)}}transformUnaryOperation(e,t){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)}}transformUsing(e,t){return{kind:"UsingNode",tables:this.transformNodeList(e.tables,t)}}transformFunction(e,t){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,t)}}transformCase(e,t){return{kind:"CaseNode",value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement}}transformWhen(e,t){return{kind:"WhenNode",condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)}}transformJSONReference(e,t){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)}}transformJSONPath(e,t){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)}}transformJSONPathLeg(e,t){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e,t){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)}}transformTuple(e,t){return{kind:"TupleNode",values:this.transformNodeList(e.values,t)}}transformMergeQuery(e,t){return{kind:"MergeQueryNode",into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)}}transformMatched(e,t){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e,t){return{kind:"AddIndexNode",name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists}}transformCast(e,t){return{kind:"CastNode",expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)}}transformFetch(e,t){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier}}transformTop(e,t){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e,t){return{kind:"OutputNode",selections:this.transformNodeList(e.selections,t)}}transformAlterType(e,t){return{kind:"AlterTypeNode",name:this.transformNode(e.name,t),addValue:this.transformNode(e.addValue,t),renameTo:this.transformNode(e.renameTo,t),renameValue:this.transformNode(e.renameValue,t),setSchema:this.transformNode(e.setSchema,t)}}transformAddValue(e,t){return{kind:"AddValueNode",value:this.transformNode(e.value,t),ifNotExists:e.ifNotExists,isBefore:e.isBefore,neighborValue:this.transformNode(e.neighborValue,t)}}transformRenameValue(e,t){return{kind:"RenameValueNode",oldValue:this.transformNode(e.oldValue,t),newValue:this.transformNode(e.newValue,t)}}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}}function qr(e){return Me(e)&&Y(e.kind)}var Ri={AlterTableNode:!0,AlterTypeNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,RefreshMaterializedViewNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0};function Pr(e){return qr(e)&&Ri[e.kind]===!0}var Ai=r({json_agg:!0,to_json:!0});class Mt extends Qa{#e;#t=new Set;#r=new Set;constructor(e){super();this.#e=e}transformNodeImpl(e,t){if(!Pr(e))return super.transformNodeImpl(e,t);let i=this.#a(e);for(let s of i)this.#r.add(s);let o=this.#s(e);for(let s of o)this.#t.add(s);let n=super.transformNodeImpl(e,t);for(let s of o)this.#t.delete(s);for(let s of i)this.#r.delete(s);return n}transformSchemableIdentifier(e,t){let i=super.transformSchemableIdentifier(e,t);if(i.schema||!this.#t.has(e.identifier.name))return i;return{...i,schema:H.create(this.#e)}}transformReferences(e,t){let i=super.transformReferences(e,t);if(i.table.table.schema)return i;return{...i,table:Nt.createWithSchema(this.#e,i.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#o(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#o(e,t,"arguments")}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map((i)=>Nt.is(i)&&!i.table.schema?{...i,table:this.transformIdentifier(i.table.identifier,t)}:this.transformNode(i,t))}}#o(e,t,i){return Ai[e.func]?e[i].map((o)=>!Nt.is(o)||o.table.schema?this.transformNode(o,t):{...o,table:this.transformIdentifier(o.table.identifier,t)}):this.transformNodeList(e[i],t)}#s(e){let t=new Set;if("name"in e&&e.name&&Rt.is(e.name))this.#n(e.name,t);if("from"in e&&e.from)for(let i of e.from.froms)this.#i(i,t);if("into"in e&&e.into)this.#i(e.into,t);if("table"in e&&e.table)this.#i(e.table,t);if("joins"in e&&e.joins)for(let i of e.joins)this.#i(i.table,t);if("using"in e&&e.using)if(I.is(e.using))this.#i(e.using.table,t);else this.#i(e.using,t);return t}#a(e){let t=new Set;if("with"in e&&e.with)this.#d(e.with,t);return t}#i(e,t){if(Nt.is(e))return this.#n(e.table,t);if(w.is(e)&&Nt.is(e.node))return this.#n(e.node.table,t);if(at.is(e)){for(let i of e.items)this.#i(i,t);return}if(ze.is(e)){for(let i of e.tables)this.#i(i,t);return}}#n(e,t){let i=e.identifier.name;if(!this.#t.has(i)&&!this.#r.has(i))t.add(i)}#d(e,t){for(let i of e.expressions){let o=i.name.table.table.identifier.name;if(!this.#r.has(o))t.add(o)}}}class Hn{#e;constructor(e){this.#e=new Mt(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}}var Ir=r({is(e){return e.kind==="MatchedNode"},create(e,t=!1){return r({kind:"MatchedNode",not:e,bySource:t})}});function Ft(e,t,i){return C.create(Ee([Ir.create(!e.isMatched,e.bySource),...t&&t.length>0?[t.length===3&&i?c(t[0],t[1],t[2]):_e(t)]:[]],"and",!1))}function Ie(e){if(Y(e))return ce.create([e],[]);if(be(e))return e.toOperationNode();return e}class ar{#e;#t;#r;constructor(){this.#e=new Promise((e,t)=>{this.#r=t,this.#t=e})}get promise(){return this.#e}resolve=(e)=>{this.#t?.(e),this.#t=this.#r=void 0};reject=(e)=>{this.#r?.(e),this.#r=this.#t=void 0}}async function bo(e,t){let i=new ar,o=new ar;return e.provideConnection(async(n)=>(i.resolve(n),await o.promise),t).catch((n)=>i.reject(n)),r({connection:await i.promise,release:o.resolve})}function Fr(e="ignore query",t,i){if(e==="ignore query")return;if(e==="cancel query"){let o=t.cancelQuery;if(!o)i(),Mr(e,t.killSession?"kill session":void 0);return o.bind(t)}if(e==="kill session"){let o=t.killSession;if(!o)i(),Mr(e,t.cancelQuery?"cancel query":void 0);return o.bind(t)}throw i(),Error(`Unexpected \`inflightQueryAbortStrategy\`: "${e}"`)}function Mr(e,t){throw Error(`This dialect doesn't support \`inflightQueryAbortStrategy\` "${e}". Use "ignore query"${t?` or "${t}"`:""} instead.`)}function oe(e,t,i){if(e?.aborted)i?.(),we(e.reason,t)}function we(e,t){throw Ti(e,t),e}var B={};async function vo(e,t,i,o){if(!t)return e;oe(t,`before ${i}`,o);let{promise:n,resolve:s}=new ar,g=()=>s(B);t.addEventListener("abort",g);try{oe(t,`before ${i}`,o);let y=await Promise.race([e,n]);if(y!==B)return y;o?.(),we(t.reason,`during ${i}`)}finally{t.removeEventListener("abort",g),s(B)}}function hn(e){return(t)=>console.error(`\`${e}\` failed in the background after abortion: ${er(t)}`)}function Ti(e,t){if(e!==null&&typeof e==="object"&&!Object.isFrozen(e))Object.defineProperty(e,"__kysely_timing__",{configurable:!0,enumerable:!1,value:t,writable:!1})}var Ei=r([]);class Za{#e;constructor(e=Ei){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let i of this.#e){let o=i.transformQuery({node:e,queryId:t});if(o.kind===e.kind)e=o;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${o.kind}`].join(" "))}return e}async executeQuery(e,t){let{inflightQueryAbortStrategy:i="ignore query",signal:o}=t||{};if(!o){let Z=await this.provideConnection(async(Ae)=>await Ae.executeQuery(e),t);return await this.#t(Z,e.queryId)}oe(o,"before query execution"),t=r({signal:o});let{connection:n,release:s}=await bo(this,t),g=this.provideConnection.bind(this),{promise:y,resolve:W}=new ar,q=()=>W(B);o.addEventListener("abort",q,{once:!0});try{oe(o,"before query execution",s);let Z=Fr(i,n,s);if(Z&&n.collectSessionInfo){oe(o,"before query execution",s);let ge=n.collectSessionInfo();if(await Promise.race([y,ge]).catch((mi)=>{throw s(),mi})===B)ge.catch(hn("collectSessionInfo")).finally(s),we(o.reason,"before query execution")}let Ae=n.executeQuery(e,t),ee=await Promise.race([y,Ae]).catch((ge)=>{throw s(),ge});if(ee===B)Promise.allSettled([Ae.catch(hn("query")),Z?.(g).catch(hn("inflightQueryAbortHandler"))]).finally(s),we(o.reason,"during query execution");else s();let de=this.#t(ee,e.queryId,t),Oe=await Promise.race([y,de]);if(Oe===B)de.catch(hn("plugins.transformResult")),we(o.reason,"during result transformation");return Oe}finally{W(B),o.removeEventListener("abort",q)}}async*stream(e,t,i){let{signal:o}=i||{};if(!o){let{connection:ee,release:de}=await bo(this);try{for await(let Oe of ee.streamQuery(e,t))yield await this.#t(Oe,e.queryId,i)}finally{de()}return}i=r({signal:o}),oe(o,"before connection acquisition");let{connection:n,release:s}=await bo(this,i),{promise:g,resolve:y}=new ar,W=()=>y(B);o.addEventListener("abort",W,{once:!0});let q,Z;oe(o,"before query streaming",s);let{queryId:Ae}=e;try{q=n.streamQuery(e,t,i);while(!0){oe(o,"during query streaming");let ee=q.next(),de=await Promise.race([g,ee]);if(de===B)Z=ee.catch(hn("iterator.next")),we(o.reason,"during query streaming");if(de.done)break;let Oe=this.#t(de.value,Ae,i),ge=await Promise.race([g,Oe]);if(ge===B)Z=Oe.catch(hn("plugins.transformResult")),we(o.reason,"during result transformation");yield ge}}finally{y(B),o.removeEventListener("abort",W);let ee=(q?.return?.()||Promise.resolve()).finally(()=>Z).finally(s);if(!Z)await ee}}async#t(e,t,i){let{signal:o}=i||{};for(let n of this.#e)e=await n.transformResult(r({queryId:t,result:e,signal:o}));return e}}class Ve extends Za{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(e){return new Ve([...this.plugins,e])}withPlugins(e){return new Ve([...this.plugins,...e])}withPluginAtFront(e){return new Ve([e,...this.plugins])}withoutPlugins(){return new Ve([])}}var xe=new Ve;class zt{numChangedRows;constructor(e){this.numChangedRows=e}}class ne{#e;constructor(e){this.#e=r(e)}modifyEnd(e){return new ne({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new ne({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}using(...e){return new R({...this.#e,queryNode:L.cloneWithUsing(this.#e.queryNode,ye("Using",e))})}returning(e){return new ne({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,N(e))})}returningAll(e){return new ne({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,x(e))})}output(e){return new ne({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,N(e))})}outputAll(e){return new ne({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,x(e))})}}class R{#e;constructor(e){this.#e=r(e)}modifyEnd(e){return new R({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new R({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,t,i){return this.#t([e,t,i],!0)}#t(e,t){return new _t({...this.#e,queryNode:L.cloneWithWhen(this.#e.queryNode,Ft({isMatched:!0},e,t))})}whenNotMatched(){return this.#r([])}whenNotMatchedAnd(...e){return this.#r(e)}whenNotMatchedAndRef(e,t,i){return this.#r([e,t,i],!0)}whenNotMatchedBySource(){return this.#r([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#r(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,i){return this.#r([e,t,i],!0,!0)}returning(e){return new R({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,N(e))})}returningAll(e){return new R({...this.#e,queryNode:M.cloneWithReturning(this.#e.queryNode,x(e))})}output(e){return new R({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,N(e))})}outputAll(e){return new R({...this.#e,queryNode:M.cloneWithOutput(this.#e.queryNode,x(e))})}#r(e,t=!1,i=!1){let o={...this.#e,queryNode:L.cloneWithWhen(this.#e.queryNode,Ft({isMatched:!1,bySource:i},e,t))};return new(i?_t:Ur)(o)}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new R({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){let t=this.compile(),i=await this.#e.executor.executeQuery(t,e),{adapter:o}=this.#e.executor,n=t.query;if(n.returning&&o.supportsReturning||n.output&&o.supportsOutput)return i.rows;return[new zt(i.numAffectedRows)]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){if(typeof e==="function")e={errorConstructor:e};let t=await this.executeTakeFirst(e);if(t===void 0){let i=e?.errorConstructor??U;throw j(i)?new i(this.toOperationNode()):i(this.toOperationNode())}return t}}class _t{#e;constructor(e){this.#e=r(e)}thenDelete(){return new R({...this.#e,queryNode:L.cloneWithThen(this.#e.queryNode,Ie("delete"))})}thenDoNothing(){return new R({...this.#e,queryNode:L.cloneWithThen(this.#e.queryNode,Ie("do nothing"))})}thenUpdate(e){return new R({...this.#e,queryNode:L.cloneWithThen(this.#e.queryNode,Ie(e(new qe({queryId:this.#e.queryId,executor:xe,queryNode:Q.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate((t)=>t.set(...e))}}class Ur{#e;constructor(e){this.#e=r(e)}thenDoNothing(){return new R({...this.#e,queryNode:L.cloneWithThen(this.#e.queryNode,Ie("do nothing"))})}thenInsertValues(e){let[t,i]=ut(e);return new R({...this.#e,queryNode:L.cloneWithThen(this.#e.queryNode,Ie(p.cloneWith(p.createWithoutInto(),{columns:t,values:i})))})}}class gn{#e;constructor(e){this.#e=r(e)}selectFrom(e){return Ke({queryId:G(),executor:this.#e.executor,queryNode:pe.createFrom(z(e),this.#e.withNode)})}selectNoFrom(e){return Ke({queryId:G(),executor:this.#e.executor,queryNode:pe.cloneWithSelections(pe.create(this.#e.withNode),N(e))})}insertInto(e){return new h({queryId:G(),executor:this.#e.executor,queryNode:p.create(fe(e),this.#e.withNode)})}replaceInto(e){return new h({queryId:G(),executor:this.#e.executor,queryNode:p.create(fe(e),this.#e.withNode,!0)})}deleteFrom(e){return new pt({queryId:G(),executor:this.#e.executor,queryNode:le.create(z(e),this.#e.withNode)})}updateTable(e){return new qe({queryId:G(),executor:this.#e.executor,queryNode:Q.create(z(e),this.#e.withNode)})}mergeInto(e){return new ne({queryId:G(),executor:this.#e.executor,queryNode:L.create(Qt(e),this.#e.withNode)})}with(e,t){let i=Vt(e,t);return new gn({...this.#e,withNode:this.#e.withNode?Ge.cloneWithExpression(this.#e.withNode,i):Ge.create(i)})}withRecursive(e,t){let i=Vt(e,t);return new gn({...this.#e,withNode:this.#e.withNode?Ge.cloneWithExpression(this.#e.withNode,i):Ge.create(i,{recursive:!0})})}withPlugin(e){return new gn({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new gn({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new gn({...this.#e,executor:this.#e.executor.withPluginAtFront(new Hn(e))})}}function Lr(){return new gn({executor:xe})}function Jr(e,t){return new ke({joinNode:I.create(e,Ce(t))})}function _r(){return new Le({overNode:Je.create()})}function ye(e,t){if(t.length===3)return Li(e,t[0],t[1],t[2]);else if(t.length===2)return ki(e,t[0],t[1]);else if(t.length===1)return Di(e,t[0]);else throw Error("not implemented")}function ki(e,t,i){return i(Jr(e,t)).toOperationNode()}function Li(e,t,i,o){return I.createWithOn(e,Ce(t),c(i,"=",o))}function Di(e,t){return I.create(e,Ce(t))}var Qr=r({is(e){return e.kind==="OffsetNode"},create(e){return r({kind:"OffsetNode",offset:e})}});var $r=r({is(e){return e.kind==="GroupByItemNode"},create(e){return r({kind:"GroupByItemNode",groupBy:e})}});function jr(e){return e=Se(e)?e(F()):e,re(e).map($r.create)}var ft=r({is(e){return e.kind==="SetOperationNode"},create(e,t,i){return r({kind:"SetOperationNode",operator:e,expression:t,all:i})}});function Re(e,t,i){if(Se(t))t=t($t());if(!v(t))t=[t];return t.map((o)=>ft.create(e,gt(o),i))}class d{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new yt(this,e)}or(...e){return new ct(P.create(this.#e,_e(e)))}and(...e){return new lt(S.create(this.#e,_e(e)))}$castTo(){return new d(this.#e)}$notNull(){return new d(this.#e)}toOperationNode(){return this.#e}}class yt{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return w.create(this.#e.toOperationNode(),be(this.#t)?this.#t.toOperationNode():H.create(this.#t))}}class ct{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new yt(this,e)}or(...e){return new ct(P.create(this.#e,_e(e)))}$castTo(){return new ct(this.#e)}toOperationNode(){return k.create(this.#e)}}class lt{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new yt(this,e)}and(...e){return new lt(S.create(this.#e,_e(e)))}$castTo(){return new lt(this.#e)}toOperationNode(){return k.create(this.#e)}}var Gr=r({is(e){return e.kind==="FetchNode"},create(e,t){return{kind:"FetchNode",rowCount:Ne.create(e),modifier:t}}});function Kr(e,t){if(!Hr(e)&&!ks(e))throw Error(`Invalid fetch row count: ${e}`);if(!Bi(t))throw Error(`Invalid fetch modifier: ${t}`);return Gr.create(e,t)}function Bi(e){return e==="only"||e==="with ties"}var a;class jt{#e;constructor(e){this.#e=r(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new a({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,_e(e))})}whereRef(e,t,i){return new a({...this.#e,queryNode:M.cloneWithWhere(this.#e.queryNode,c(e,t,i))})}having(...e){return new a({...this.#e,queryNode:pe.cloneWithHaving(this.#e.queryNode,_e(e))})}havingRef(e,t,i){return new a({...this.#e,queryNode:pe.cloneWithHaving(this.#e.queryNode,c(e,t,i))})}select(e){return new a({...this.#e,queryNode:pe.cloneWithSelections(this.#e.queryNode,N(e))})}distinctOn(e){return new a({...this.#e,queryNode:pe.cloneWithDistinctOn(this.#e.queryNode,re(e))})}modifyFront(e){return new a({...this.#e,queryNode:pe.cloneWithFrontModifier(this.#e.queryNode,_.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.createWithExpression(e.toOperationNode()))})}distinct(){return new a({...this.#e,queryNode:pe.cloneWithFrontModifier(this.#e.queryNode,_.create("Distinct"))})}forUpdate(e){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("ForUpdate",e?Fe(e).map(fe):void 0))})}forShare(e){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("ForShare",e?Fe(e).map(fe):void 0))})}forKeyShare(e){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("ForKeyShare",e?Fe(e).map(fe):void 0))})}forNoKeyUpdate(e){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("ForNoKeyUpdate",e?Fe(e).map(fe):void 0))})}skipLocked(){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("SkipLocked"))})}noWait(){return new a({...this.#e,queryNode:M.cloneWithEndModifier(this.#e.queryNode,_.create("NoWait"))})}selectAll(e){return new a({...this.#e,queryNode:pe.cloneWithSelections(this.#e.queryNode,x(e))})}innerJoin(...e){return this.#t("InnerJoin",e)}leftJoin(...e){return this.#t("LeftJoin",e)}rightJoin(...e){return this.#t("RightJoin",e)}fullJoin(...e){return this.#t("FullJoin",e)}crossJoin(...e){return this.#t("CrossJoin",e)}innerJoinLateral(...e){return this.#t("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#t("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#t("LateralCrossJoin",e)}crossApply(...e){return this.#t("CrossApply",e)}outerApply(...e){return this.#t("OuterApply",e)}#t(e,t){return new a({...this.#e,queryNode:M.cloneWithJoin(this.#e.queryNode,ye(e,t))})}orderBy(...e){return new a({...this.#e,queryNode:M.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new a({...this.#e,queryNode:pe.cloneWithGroupByItems(this.#e.queryNode,jr(e))})}limit(e){return new a({...this.#e,queryNode:pe.cloneWithLimit(this.#e.queryNode,Be.create(u(e)))})}offset(e){return new a({...this.#e,queryNode:pe.cloneWithOffset(this.#e.queryNode,Qr.create(u(e)))})}fetch(e,t="only"){return new a({...this.#e,queryNode:pe.cloneWithFetch(this.#e.queryNode,Kr(e,t))})}top(e,t){return new a({...this.#e,queryNode:M.cloneWithTop(this.#e.queryNode,J(e,t))})}union(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("union",e,!1))})}unionAll(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("union",e,!0))})}intersect(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("intersect",e,!1))})}intersectAll(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("intersect",e,!0))})}except(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("except",e,!1))})}exceptAll(e){return new a({...this.#e,queryNode:pe.cloneWithSetOperations(this.#e.queryNode,Re("except",e,!0))})}as(e){return new Yr(this,e)}clearSelect(){return new a({...this.#e,queryNode:pe.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new a({...this.#e,queryNode:M.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new a({...this.#e,queryNode:pe.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new a({...this.#e,queryNode:pe.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new a({...this.#e,queryNode:M.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new a({...this.#e,queryNode:pe.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){if(e)return t(this);return new a({...this.#e})}$castTo(){return new a(this.#e)}$narrowType(){return new a(this.#e)}$assertType(){return new a(this.#e)}$asTuple(){return new d(this.toOperationNode())}$asScalar(){return new d(this.toOperationNode())}withPlugin(e){return new a({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){let t=this.compile();return(await this.#e.executor.executeQuery(t,e)).rows}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){if(typeof e==="function")e={errorConstructor:e};let t=await this.executeTakeFirst(e);if(t===void 0){let i=e?.errorConstructor??U;throw j(i)?new i(this.toOperationNode()):i(this.toOperationNode())}return t}async*stream(e){if(typeof e!=="object")e={chunkSize:e};let t=this.compile(),i=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let o of i)yield*o.rows}async explain(e,t){return await new a({...this.#e,queryNode:M.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}}a=jt;function Ke(e){return new jt(e)}class Yr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return w.create(this.#e.toOperationNode(),H.create(this.#t))}}var X=r({is(e){return e.kind==="AggregateFunctionNode"},create(e,t=[]){return r({kind:"AggregateFunctionNode",func:e,aggregated:t})},cloneWithDistinct(e){return r({...e,distinct:!0})},cloneWithOrderBy(e,t,i=!1){let o=i?"withinGroup":"orderBy";return r({...e,[o]:e[o]?ie.cloneWithItems(e[o],t):ie.create(t)})},cloneWithFilter(e,t){return r({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",t):O.create(t)})},cloneWithOrFilter(e,t){return r({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",t):O.create(t)})},cloneWithOver(e,t){return r({...e,over:t})}});var Gt=r({is(e){return e.kind==="FunctionNode"},create(e,t){return r({kind:"FunctionNode",func:e,arguments:t})}});class A{#e;constructor(e){this.#e=r(e)}get expressionType(){return}as(e){return new Xr(this,e)}distinct(){return new A({...this.#e,aggregateFunctionNode:X.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new A({...this.#e,aggregateFunctionNode:M.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(e))})}clearOrderBy(){return new A({...this.#e,aggregateFunctionNode:M.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new A({...this.#e,aggregateFunctionNode:X.cloneWithOrderBy(this.#e.aggregateFunctionNode,E(e),!0)})}filterWhere(...e){return new A({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,_e(e))})}filterWhereRef(e,t,i){return new A({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,c(e,t,i))})}over(e){let t=_r();return new A({...this.#e,aggregateFunctionNode:X.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new A(this.#e)}$notNull(){return new A(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}}class Xr{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return w.create(this.#e.toOperationNode(),H.create(this.#t))}}function Pd(){let e=(i,o)=>new d(Gt.create(i,re(o??[]))),t=(i,o)=>new A({aggregateFunctionNode:X.create(i,o?re(o):void 0)});return Object.assign(e,{agg:t,avg(i){return t("avg",[i])},coalesce(...i){return e("coalesce",i)},count(i){return t("count",[i])},countAll(i){return new A({aggregateFunctionNode:X.create("count",x(i))})},max(i){return t("max",[i])},min(i){return t("min",[i])},sum(i){return t("sum",[i])},any(i){return e("any",[i])},jsonAgg(i){return new A({aggregateFunctionNode:X.create("json_agg",[Y(i)?fe(i):i.toOperationNode()])})},toJson(i){return new d(Gt.create("to_json",[Y(i)?fe(i):i.toOperationNode()]))}})}var Zr=r({is(e){return e.kind==="UnaryOperationNode"},create(e,t){return r({kind:"UnaryOperationNode",operator:e,operand:t})}});function ei(e,t){if(pr(e))return Zr.create(T.create(e),l(t));throw Error(`invalid unary operator ${JSON.stringify(e)}`)}var bt=r({is(e){return e.kind==="CaseNode"},create(e){return r({kind:"CaseNode",value:e})},cloneWithWhen(e,t){return r({...e,when:r(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return r({...e,when:e.when?r([...e.when.slice(0,-1),C.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return r({...e,...t})}});class Xa{#e;constructor(e){this.#e=r(e)}when(...e){return new He({...this.#e,node:bt.cloneWithWhen(this.#e.node,C.create(_e(e)))})}whenRef(e,t,i){return new He({...this.#e,node:bt.cloneWithWhen(this.#e.node,C.create(c(e,t,i)))})}}class He{#e;constructor(e){this.#e=r(e)}then(e){return new Kt({...this.#e,node:bt.cloneWithThen(this.#e.node,nt(e)?Ue(e):u(e))})}thenRef(e){return new Kt({...this.#e,node:bt.cloneWithThen(this.#e.node,l(e))})}}class Kt{#e;constructor(e){this.#e=r(e)}when(...e){return new He({...this.#e,node:bt.cloneWithWhen(this.#e.node,C.create(_e(e)))})}whenRef(e,t,i){return new He({...this.#e,node:bt.cloneWithWhen(this.#e.node,C.create(c(e,t,i)))})}else(e){return new Ht({...this.#e,node:bt.cloneWith(this.#e.node,{else:nt(e)?Ue(e):u(e)})})}elseRef(e){return new Ht({...this.#e,node:bt.cloneWith(this.#e.node,{else:l(e)})})}end(){return new d(bt.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new d(bt.cloneWith(this.#e.node,{isStatement:!0}))}}class Ht{#e;constructor(e){this.#e=r(e)}end(){return new d(bt.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new d(bt.cloneWith(this.#e.node,{isStatement:!0}))}}var Yt=r({is(e){return e.kind==="JSONPathLegNode"},create(e,t){return r({kind:"JSONPathLegNode",type:e,value:t})}});var qi=/^#-\d+$/;class Xe{#e;constructor(e){this.#e=e}at(e){if(typeof e!=="number"&&typeof e!=="string"||typeof e==="number"&&!Number.isInteger(e)||typeof e==="string"&&e!=="last"&&!qi.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#t("ArrayLocation",e)}key(e){return this.#t("Member",e)}#t(e,t){if(Te.is(this.#e))return new Ye(Te.cloneWithTraversal(this.#e,me.is(this.#e.traversal)?me.cloneWithLeg(this.#e.traversal,Yt.create(e,t)):it.cloneWithValue(this.#e.traversal,Ne.createImmediate(t))));return new Ye(me.cloneWithLeg(this.#e,Yt.create(e,t)))}}class Ye extends Xe{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new ti(this,e)}$castTo(){return new Ye(this.#e)}$notNull(){return new Ye(this.#e)}toOperationNode(){return this.#e}}class ti{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return w.create(this.#e.toOperationNode(),be(this.#t)?this.#t.toOperationNode():H.create(this.#t))}}var Xt=r({is(e){return e.kind==="TupleNode"},create(e){return r({kind:"TupleNode",values:r(e)})}});var Pi=r({bigint:!0,bigserial:!0,binary:!0,blob:!0,boolean:!0,bytea:!0,char:!0,date:!0,datemultirange:!0,daterange:!0,datetime:!0,datetime2:!0,decimal:!0,"double precision":!0,float4:!0,float8:!0,int2:!0,int4:!0,int4multirange:!0,int4range:!0,int8:!0,int8multirange:!0,int8range:!0,integer:!0,json:!0,jsonb:!0,numeric:!0,nummultirange:!0,numrange:!0,real:!0,serial:!0,smallint:!0,text:!0,time:!0,timestamp:!0,timestamptz:!0,timetz:!0,tsmultirange:!0,tsrange:!0,tstzmultirange:!0,tstzrange:!0,uuid:!0,varbinary:!0,varchar:!0}),Ii=r([/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^datetime2\(\d+\)$/,/^varbinary\(\d+\)$/]),ri=r({is(e){return e.kind==="DataTypeNode"},create(e){return r({kind:"DataTypeNode",dataType:e})}});function ii(e){return Pi[e]||Ii.some((t)=>t.test(e))}function Vr(e){if(be(e))return e.toOperationNode();if(ii(e))return ri.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var oi=r({is(e){return e.kind==="CastNode"},create(e,t){return r({kind:"CastNode",expression:e,dataType:t})}});function $t(e=xe){function t(n,s,g){return new d(st(n,s,g))}function i(n,s){return new d(ei(n,s))}let o=Object.assign(t,{fn:void 0,eb:void 0,selectFrom(n){return Ke({queryId:G(),executor:e,queryNode:pe.createFrom(z(n))})},case(n){return new Xa({node:bt.create(Ut(n)?void 0:l(n))})},ref(n,s){if(Ut(s))return new d(Jt(n));return new Xe(lr(n,s))},jsonPath(){return new Xe(me.create())},table(n){return new d(fe(n))},val(n){return new d(u(n))},refTuple(...n){return new d(Xt.create(n.map(l)))},tuple(...n){return new d(Xt.create(n.map(u)))},lit(n){return new d(Ue(n))},unary:i,not(n){return i("not",n)},exists(n){return i("exists",n)},neg(n){return i("-",n)},between(n,s,g){return new d(ue.create(l(n),T.create("between"),S.create(u(s),u(g))))},betweenSymmetric(n,s,g){return new d(ue.create(l(n),T.create("between symmetric"),S.create(u(s),u(g))))},and(n){if(v(n))return new d(Ee(n,"and"));return new d(Ct(n,"and"))},or(n){if(v(n))return new d(Ee(n,"or"));return new d(Ct(n,"or"))},parens(...n){let s=_e(n);if(k.is(s))return new d(s);else return new d(k.create(s))},cast(n,s){return new d(oi.create(l(n),Vr(s)))}});return o.fn=Pd(),o.eb=o,o}function F(e){return $t()}function gt(e){if(be(e))return e.toOperationNode();else if(Se(e))return e(F()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function dt(e){if(be(e))return e.toOperationNode();else if(Se(e))return e(F()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function te(e){return et(e)||tr(e)||Se(e)}class Rp{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new ni(this.#e,e)}}class ni{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return w.create(fe(this.#e),H.create(this.#t))}}function si(e){return Me(e)&&be(e)&&Y(e.table)&&Y(e.alias)}function z(e){if(v(e))return e.map((t)=>Ce(t));else return[Ce(e)]}function Ce(e){if(Y(e))return Qt(e);else if(si(e))return e.toOperationNode();else return dt(e)}function Qt(e){if(e.includes(" as ")){let[i,o]=e.split(" as ").map(ai);return w.create(fe(i),H.create(o))}else return fe(e)}function fe(e){if(e.includes(".")){let[i,o]=e.split(".").map(ai);return Nt.createWithSchema(i,o)}else return Nt.create(e)}function ai(e){return e.trim()}var zr=r({is(e){return e.kind==="CreateViewNode"},create(e){return r({kind:"CreateViewNode",name:Rt.create(e)})},cloneWith(e,t){return r({...e,...t})}});class Ze{#e;constructor(e){this.#e=r(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new di(this,e)}$castTo(){return new Ze({...this.#e})}$notNull(){return new Ze(this.#e)}withPlugin(e){return new Ze({...this.#e,plugins:this.#e.plugins!==void 0?r([...this.#e.plugins,e]):r([e])})}toOperationNode(){return this.#r(this.#t())}compile(e){return this.#o(this.#t(e))}async execute(e,t){let i=this.#t(e);return i.executeQuery(this.#o(i),t)}#t(e){let t=e!==void 0?e.getExecutor():xe;return this.#e.plugins!==void 0?t.withPlugins(this.#e.plugins):t}#r(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#o(e){return e.compileQuery(this.#r(e),this.#e.queryId)}}function ae(e){return new Ze(e)}class di{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return w.create(this.#e.toOperationNode(),be(this.#t)?this.#t.toOperationNode():H.create(this.#t))}}var D=Object.assign((e,...t)=>ae({queryId:G(),rawNode:ce.create(e,t?.map(ui)??[])}),{ref(e){return ae({queryId:G(),rawNode:ce.createWithChild(Jt(e))})},val(e){return ae({queryId:G(),rawNode:ce.createWithChild(u(e))})},table(e){return ae({queryId:G(),rawNode:ce.createWithChild(fe(e))})},id(...e){let t=Array(e.length+1).fill(".");return t[0]="",t[t.length-1]="",ae({queryId:G(),rawNode:ce.create(t,e.map(H.create))})},lit(e){return ae({queryId:G(),rawNode:ce.createWithChild(Ne.createImmediate(e))})},raw(e){return ae({queryId:G(),rawNode:ce.createWithSql(e)})},join(e,t=D`, `){let i=Array(Math.max(2*e.length-1,0)),o=t.toOperationNode();for(let n=0;n<e.length;++n)if(i[2*n]=ui(e[n]),n!==e.length-1)i[2*n+1]=o;return ae({queryId:G(),rawNode:ce.createWithChildren(i)})}});function ui(e){if(be(e))return e.toOperationNode();return u(e)}class Zt{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=r({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this),AlterTypeNode:this.visitAlterType.bind(this),AddValueNode:this.visitAddValue.bind(this),RenameValueNode:this.visitRenameValue.bind(this)});visitNode=(e)=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}}var Vi=/'/g,Mi=/['"]/g;class Ot extends Zt{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e,t){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),r({query:e,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let t=this.parentNode!==void 0&&!k.is(this.parentNode)&&!p.is(this.parentNode)&&!ht.is(this.parentNode)&&!zr.is(this.parentNode)&&!ft.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("select"),e.distinctOn)this.append(" "),this.compileDistinctOn(e.distinctOn);if(e.frontModifiers?.length)this.append(" "),this.compileList(e.frontModifiers," ");if(e.top)this.append(" "),this.visitNode(e.top);if(e.selections)this.append(" "),this.compileList(e.selections);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.groupBy)this.append(" "),this.visitNode(e.groupBy);if(e.having)this.append(" "),this.visitNode(e.having);if(e.setOperations)this.append(" "),this.compileList(e.setOperations," ");if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(e.offset)this.append(" "),this.visitNode(e.offset);if(e.fetch)this.append(" "),this.visitNode(e.fetch);if(e.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers(e.endModifiers)," ");if(t)this.append(")")}visitFrom(e){this.append("from "),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append("distinct on ("),this.compileList(e),this.append(")")}compileList(e,t=", "){let i=e.length-1;for(let o=0;o<=i;o++)if(this.visitNode(e[o]),o<i)this.append(t)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let t=this.parentNode!==void 0&&!k.is(this.parentNode)&&!ce.is(this.parentNode)&&!C.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append(e.replace?"replace":"insert"),e.orAction)this.append(" "),this.visitNode(e.orAction);if(e.top)this.append(" "),this.visitNode(e.top);if(e.into)this.append(" into "),this.visitNode(e.into);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.output)this.append(" "),this.visitNode(e.output);if(e.values)this.append(" "),this.visitNode(e.values);if(e.defaultValues)this.append(" "),this.append("default values");if(e.onConflict)this.append(" "),this.visitNode(e.onConflict);if(e.onDuplicateKey)this.append(" "),this.visitNode(e.onDuplicateKey);if(e.returning)this.append(" "),this.visitNode(e.returning);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let t=this.parentNode!==void 0&&!k.is(this.parentNode)&&!ce.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("delete "),e.top)this.visitNode(e.top),this.append(" ");if(this.visitNode(e.from),e.output)this.append(" "),this.visitNode(e.output);if(e.using)this.append(" "),this.visitNode(e.using);if(e.joins)this.append(" "),this.compileList(e.joins," ");if(e.where)this.append(" "),this.visitNode(e.where);if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitReturning(e){this.append("returning "),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(" as "),this.visitNode(e.alias)}visitReference(e){if(e.table)this.visitNode(e.table),this.append(".");this.visitNode(e.column)}visitSelectAll(e){this.append("*")}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!Y(e.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(" and "),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(" or "),this.visitNode(e.right)}visitValue(e){if(e.immediate)this.appendImmediateValue(e.value);else this.appendValue(e.value)}visitValueList(e){this.append("("),this.compileList(e.values),this.append(")")}visitTuple(e){this.append("("),this.compileList(e.values),this.append(")")}visitPrimitiveValueList(e){this.append("(");let{values:t}=e;for(let i=0;i<t.length;++i)if(this.appendValue(t[i]),i!==t.length-1)this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){if(this.append(Ui[e.joinType]),this.append(" "),this.visitNode(e.table),e.on)this.append(" "),this.visitNode(e.on)}visitOn(e){this.append("on "),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:t,parameters:i}=e;for(let o=0;o<t.length;++o)if(this.append(t[o]),i.length>o)this.visitNode(i[o])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){if(e.schema)this.visitNode(e.schema),this.append(".");this.visitNode(e.identifier)}visitCreateTable(e){if(this.append("create "),e.frontModifiers?.length)this.compileList(e.frontModifiers," "),this.append(" ");if(e.temporary)this.append("temporary ");if(this.append("table "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.table),!e.selectQuery)this.append(" ("),this.compileList([...e.columns,...e.constraints??[],...e.indexes??[]]),this.append(")");if(e.onCommit)this.append(" on commit "),this.append(e.onCommit);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ");if(e.selectQuery)this.append(" as "),this.visitNode(e.selectQuery)}visitColumnDefinition(e){if(e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned)this.append(" unsigned");if(e.frontModifiers&&e.frontModifiers.length>0)this.append(" "),this.compileList(e.frontModifiers," ");if(e.generated)this.append(" "),this.visitNode(e.generated);if(e.identity)this.append(" identity");if(e.defaultTo)this.append(" "),this.visitNode(e.defaultTo);if(e.notNull)this.append(" not null");if(e.unique)this.append(" unique");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.primaryKey)this.append(" primary key");if(e.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(e.references)this.append(" "),this.visitNode(e.references);if(e.check)this.append(" "),this.visitNode(e.check);if(e.endModifiers&&e.endModifiers.length>0)this.append(" "),this.compileList(e.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(e){if(this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate)}visitDropTable(e){if(this.append("drop "),e.temporary)this.append("temporary ");if(this.append("table "),e.ifExists)this.append("if exists ");if(this.visitNode(e.table),e.cascade)this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){if(this.visitNode(e.orderBy),e.collation)this.append(" "),this.visitNode(e.collation);if(e.direction)this.append(" "),this.visitNode(e.direction);if(e.nulls)this.append(" nulls "),this.append(e.nulls)}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let t=this.parentNode!==void 0&&!k.is(this.parentNode)&&!ce.is(this.parentNode)&&!C.is(this.parentNode);if(this.parentNode===void 0&&e.explain)this.visitNode(e.explain),this.append(" ");if(t)this.append("(");if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("update "),e.top)this.visitNode(e.top),this.append(" ");if(e.table)this.visitNode(e.table),this.append(" ");if(this.append("set "),e.updates)this.compileList(e.updates);if(e.output)this.append(" "),this.visitNode(e.output);if(e.from)this.append(" "),this.visitNode(e.from);if(e.joins){if(!e.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(e.joins," ")}if(e.where)this.append(" "),this.visitNode(e.where);if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(e.limit)this.append(" "),this.visitNode(e.limit);if(t)this.append(")");if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitColumnUpdate(e){this.visitNode(e.column),this.append(" = "),this.visitNode(e.value)}visitLimit(e){this.append("limit "),this.visitNode(e.limit)}visitOffset(e){this.append("offset "),this.visitNode(e.offset)}visitOnConflict(e){if(this.append("on conflict"),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");else if(e.constraint)this.append(" on constraint "),this.visitNode(e.constraint);else if(e.indexExpression)this.append(" ("),this.visitNode(e.indexExpression),this.append(")");if(e.indexWhere)this.append(" "),this.visitNode(e.indexWhere);if(e.doNothing===!0)this.append(" do nothing");else if(e.updates){if(this.append(" do update set "),this.compileList(e.updates),e.updateWhere)this.append(" "),this.visitNode(e.updateWhere)}}visitOnDuplicateKey(e){this.append("on duplicate key update "),this.compileList(e.updates)}visitCreateIndex(e){if(this.append("create "),e.unique)this.append("unique ");if(this.append("index "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.using)this.append(" using "),this.visitNode(e.using);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.nullsNotDistinct)this.append(" nulls not distinct");if(e.where)this.append(" "),this.visitNode(e.where)}visitDropIndex(e){if(this.append("drop index "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.table)this.append(" on "),this.visitNode(e.table);if(e.cascade)this.append(" cascade")}visitCreateSchema(e){if(this.append("create schema "),e.ifNotExists)this.append("if not exists ");this.visitNode(e.schema)}visitDropSchema(e){if(this.append("drop schema "),e.ifExists)this.append("if exists ");if(this.visitNode(e.schema),e.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("primary key ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}buildDeferrable(e){if(e.deferrable!==void 0)if(e.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(e.initiallyDeferred!==void 0)if(e.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("unique"),e.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(e.columns),this.append(")"),this.buildDeferrable(e)}visitCheckConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");this.append("check ("),this.visitNode(e.expression),this.append(")")}visitForeignKeyConstraint(e){if(e.name)this.append("constraint "),this.visitNode(e.name),this.append(" ");if(this.append("foreign key ("),this.compileList(e.columns),this.append(") "),this.visitNode(e.references),e.onDelete)this.append(" on delete "),this.append(e.onDelete);if(e.onUpdate)this.append(" on update "),this.append(e.onUpdate);this.buildDeferrable(e)}visitList(e){this.compileList(e.items)}visitWith(e){if(this.append("with "),e.recursive)this.append("recursive ");this.compileList(e.expressions)}visitCommonTableExpression(e){if(this.visitNode(e.name),this.append(" as "),qn(e.materialized)){if(!e.materialized)this.append("not ");this.append("materialized ")}this.visitNode(e.expression)}visitCommonTableExpressionName(e){if(this.visitNode(e.table),e.columns)this.append("("),this.compileList(e.columns),this.append(")")}visitAlterTable(e){if(this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo)this.append("rename to "),this.visitNode(e.renameTo);if(e.setSchema)this.append("set schema "),this.visitNode(e.setSchema);if(e.addConstraint)this.visitNode(e.addConstraint);if(e.dropConstraint)this.visitNode(e.dropConstraint);if(e.renameConstraint)this.visitNode(e.renameConstraint);if(e.columnAlterations)this.compileColumnAlterations(e.columnAlterations);if(e.addIndex)this.visitNode(e.addIndex);if(e.dropIndex)this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){if(this.append("drop column "),e.ifExists)this.append("if exists ");this.visitNode(e.column)}visitAlterColumn(e){if(this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(e.dataType),e.dataTypeExpression)this.append("using "),this.visitNode(e.dataTypeExpression)}if(e.setDefault)this.append("set default "),this.visitNode(e.setDefault);if(e.dropDefault)this.append("drop default");if(e.setNotNull)this.append("set not null");if(e.dropNotNull)this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){if(this.append("drop constraint "),e.ifExists)this.append("if exists ");if(this.visitNode(e.constraintName),e.modifier==="cascade")this.append(" cascade");else if(e.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(e){this.append("rename constraint "),this.visitNode(e.oldName),this.append(" to "),this.visitNode(e.newName)}visitSetOperation(e){if(this.append(e.operator),this.append(" "),e.all)this.append("all ");this.visitNode(e.expression)}visitCreateView(e){if(this.append("create "),e.orReplace)this.append("or replace ");if(e.materialized)this.append("materialized ");if(e.temporary)this.append("temporary ");if(this.append("view "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),this.append(" "),e.columns)this.append("("),this.compileList(e.columns),this.append(") ");if(e.as)this.append("as "),this.visitNode(e.as)}visitRefreshMaterializedView(e){if(this.append("refresh materialized view "),e.concurrently)this.append("concurrently ");if(this.visitNode(e.name),e.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(e){if(this.append("drop "),e.materialized)this.append("materialized ");if(this.append("view "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.cascade)this.append(" cascade")}visitGenerated(e){if(this.append("generated "),e.always)this.append("always ");if(e.byDefault)this.append("by default ");if(this.append("as "),e.identity)this.append("identity");if(e.expression)this.append("("),this.visitNode(e.expression),this.append(")");if(e.stored)this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){if(e.rawModifier)this.visitNode(e.rawModifier);else this.append(Fi[e.modifier]);if(e.of)this.append(" of "),this.compileList(e.of,", ")}visitCreateType(e){if(this.append("create type "),this.visitNode(e.name),e.enum)this.append(" as enum "),this.visitNode(e.enum)}visitDropType(e){if(this.append("drop type "),e.ifExists)this.append("if exists ");if(this.visitNode(e.name),e.additionalNames?.length)this.append(", "),this.compileList(e.additionalNames);if(e.cascade)this.append(" cascade")}visitAlterType(e){if(this.append("alter type "),this.visitNode(e.name),this.append(" "),e.addValue)this.visitNode(e.addValue);else if(e.renameTo)this.append("rename to "),this.visitNode(e.renameTo);else if(e.renameValue)this.visitNode(e.renameValue);else if(e.setSchema)this.append("set schema "),this.visitNode(e.setSchema)}visitAddValue(e){if(this.append("add value "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.value),e.neighborValue)this.append(e.isBefore?" before ":" after "),this.visitNode(e.neighborValue)}visitRenameValue(e){this.append("rename value "),this.visitNode(e.oldValue),this.append(" to "),this.visitNode(e.newValue)}visitExplain(e){if(this.append("explain"),e.options||e.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options){if(this.visitNode(e.options),e.format)this.append(this.getExplainOptionsDelimiter())}if(e.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){if(this.append(e.func),this.append("("),e.distinct)this.append("distinct ");if(this.compileList(e.aggregated),e.orderBy)this.append(" "),this.visitNode(e.orderBy);if(this.append(")"),e.withinGroup)this.append(" within group ("),this.visitNode(e.withinGroup),this.append(")");if(e.filter)this.append(" filter("),this.visitNode(e.filter),this.append(")");if(e.over)this.append(" "),this.visitNode(e.over)}visitOver(e){if(this.append("over("),e.partitionBy){if(this.visitNode(e.partitionBy),e.orderBy)this.append(" ")}if(e.orderBy)this.visitNode(e.orderBy);this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){if(this.visitNode(e.operator),!this.isMinusOperator(e.operator))this.append(" ");this.visitNode(e.operand)}isMinusOperator(e){return T.is(e)&&e.operator==="-"}visitUsing(e){this.append("using "),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append("("),this.compileList(e.arguments),this.append(")")}visitCase(e){if(this.append("case"),e.value)this.append(" "),this.visitNode(e.value);if(e.when)this.append(" "),this.compileList(e.when," ");if(e.else)this.append(" else "),this.visitNode(e.else);if(this.append(" end"),e.isStatement)this.append(" case")}visitWhen(e){if(this.append("when "),this.visitNode(e.condition),e.result)this.append(" then "),this.visitNode(e.result)}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){if(e.inOperator)this.visitNode(e.inOperator);this.append("'$");for(let t of e.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(e){let t=e.type==="ArrayLocation",i=String(e.value);if(t)this.append("["),this.append(this.sanitizeStringLiteral(i)),this.append("]");else this.append('."'),this.append(this.sanitizeJSONPathMemberValue(i)),this.append('"')}visitJSONOperatorChain(e){for(let t=0,i=e.values.length;t<i;t++){if(t===i-1)this.visitNode(e.operator);else this.append("->");this.visitNode(e.values[t])}}visitMergeQuery(e){if(e.with)this.visitNode(e.with),this.append(" ");if(this.append("merge "),e.top)this.visitNode(e.top),this.append(" ");if(this.append("into "),this.visitNode(e.into),e.using)this.append(" "),this.visitNode(e.using);if(e.whens)this.append(" "),this.compileList(e.whens," ");if(e.returning)this.append(" "),this.visitNode(e.returning);if(e.output)this.append(" "),this.visitNode(e.output);if(e.endModifiers?.length)this.append(" "),this.compileList(e.endModifiers," ")}visitMatched(e){if(e.not)this.append("not ");if(this.append("matched"),e.bySource)this.append(" by source")}visitAddIndex(e){if(!this.parentNode||!ht.is(this.parentNode))this.append("add ");if(e.unique)this.append("unique ");if(this.append("index "),this.visitNode(e.name),e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.using)this.append(" using "),this.visitNode(e.using)}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){if(this.append(`top(${e.expression})`),e.modifiers)this.append(` ${e.modifiers}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append("collate "),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let t=this.getLeftIdentifierWrapper(),i=this.getRightIdentifierWrapper(),o="";for(let n of e)if(o+=n,n===t)o+=t;else if(n===i)o+=i;return o}sanitizeStringLiteral(e){return e.replace(Vi,"''")}sanitizeJSONPathMemberValue(e){return e.replace(Mi,(t)=>t==="'"?"''":"\\\"")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(Y(e))this.appendStringLiteral(e);else if(Hr(e)||qn(e)||ks(e))this.append(e.toString());else if(Ts(e))this.append("null");else if(xd(e))this.appendImmediateValue(e.toISOString());else throw Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append("'"),this.append(this.sanitizeStringLiteral(e)),this.append("'")}sortSelectModifiers(e){return r(e.toSorted((t,i)=>t.modifier&&i.modifier?hi[t.modifier]-hi[i.modifier]:1))}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}}var Fi=r({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),hi=r({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Ui=r({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var Np="kysely_migration",Op="kysely_migration_lock";function Cp(e){let t=e.filter((o)=>o.pk>0),i=t.length===1?t[0]:void 0;return i?.type.toLowerCase()==="integer"?i.name:void 0}async function pi(e,t,i){let o=Cp(i);if(!o)return;let{rows:n}=await D`
|
|
3
|
+
PRAGMA index_list(${D.id(t)})
|
|
4
|
+
`.execute(e.withoutPlugins());return n.some((s)=>s.origin==="pk")?void 0:o}function Rd(e,t,i){return{name:e.name,isView:e.type==="view",columns:t.map((o)=>({name:o.name,dataType:o.type,isNullable:o.notnull===0,isAutoIncrementing:o.name===i,hasDefaultValue:o.dflt_value!=null}))}}async function Ji(e,t){let{rows:i}=await D`
|
|
5
|
+
PRAGMA table_info(${D.id(t)})
|
|
6
|
+
`.execute(e.withoutPlugins());if(i.length===0)return;let o=await pi(e,t,i);return Rd({name:t},i,o)}async function Sy(e,t){if(t.length===0)return[];try{return await e.introspection.getTables()}catch{return(await Promise.all(t.map((i)=>Ji(e,i)))).filter((i)=>i!==void 0)}}function ec(e){let t=e;async function i(){return[]}async function o(n={withInternalKyselyTables:!1}){let s=t.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name");if(!n.withInternalKyselyTables)s=s.where("name","!=",Np).where("name","!=",Op);let g=await s.execute();return Promise.all(g.map(async({name:y})=>{let W=await e.selectFrom(D`pragma_table_info(${y})`.as("table_info")).select(["cid","name","type","notnull","dflt_value","pk"]).execute(),q=await pi(e,y,W);return Rd({name:y},W,q)}))}return{getSchemas:i,getTables:o,getMetadata:async(n)=>({tables:await o(n)})}}
|
|
7
|
+
export{Ut,Y,Hr,qn,Ts,xd,ks,yy,Se,Me,r,mt,H,wy,ht,Rt,Nt,be,se,yo,xs,Ip,ce,wo,Jt,Pp,So,Is,Ne,_e,M,pe,Id,G,Qa,Hn,ar,bo,vo,hn,Za,gn,Pd,bt,Xa,Vr,gt,Rp,fe,zr,D,Ot,Np,Op,Cp,Rd,Sy,ec};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{l}from"./chunk-gefgv8rg.js";import{zf}from"./chunk-8zbwppny.js";import"./chunk-neyhk32g.js";import{e,a,j}from"./chunk-vccappg7.js";var w={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},d=zf(w),h=d.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),A=d.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),P=d.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]}),R={admin:h,owner:A,member:P};var u=(o,s)=>{if(!o.permissions)return!1;let r=o.role.split(","),i=o.options.creatorRole||"owner",t=r.includes(i),c=o.allowCreatorAllPermissions||!1;if(t&&c)return!0;for(let n of r)if(s[n]?.authorize(o.permissions)?.success)return!0;return!1},f=new Map;var I=j(e(),a(e())),b=async(o,s)=>{let r={...o.options.roles||R};if(s&&o.organizationId&&o.options.dynamicAccessControl?.enabled&&o.options.ac&&!o.useMemoryCache){let i=await s.context.adapter.findMany({model:"organizationRole",where:[{field:"organizationId",value:o.organizationId}]});for(let{role:t,permission:c}of i){let n=JSON.parse(c),p=I.safeParse(n);if(!p.success)throw s.context.logger.error("[hasPermission] Invalid permissions for role "+t,{permissions:n}),new l("INTERNAL_SERVER_ERROR",{message:"Invalid permissions for role "+t});let m={...r[t]?.statements};for(let[g,z]of Object.entries(p.data))m[g]=[...new Set([...m[g]??[],...z])];r[t]=o.options.ac.newRole(m)}}if(o.useMemoryCache)r=f.get(o.organizationId)||r;return f.set(o.organizationId,r),u(o,r)};export{b as hasPermission};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{S,It}from"./chunk-gefgv8rg.js";function Li(e,{usePlural:t=!1}={}){let n={};for(let a of Object.values(It(e))){let s=t?`${a.modelName}s`:a.modelName,o=n[s]??={fields:{},disableMigrations:!0};for(let[c,i]of Object.entries(a.fields))o.fields[i.fieldName||c]=i;o.disableMigrations=o.disableMigrations&&!!a.disableMigrations}return n}function _n(e,t){let n=[];for(let[a,s]of Object.entries(e)){if(s.disableMigrations)continue;let o=t.find((i)=>i.name===a&&(s.schema===void 0||i.schema===s.schema));if(!o){n.push({kind:"missing-table",table:a});continue}let c=new Set([s.idColumn??"id",...Object.keys(s.fields)]);for(let i of c)if(!o.columns.some((l)=>l.name===i))n.push({kind:"missing-column",table:a,column:i});for(let i of o.columns){if(c.has(i.name)||i.nullable||i.hasDefault)continue;n.push({kind:"unexpected-required-column",table:a,column:i.name})}}return n}var h={database:"Run `npx auth migrate` to add it.",drizzle:"Run `npx auth generate` to refresh the Drizzle schema, then apply it with your migration tool.",prisma:"Run `npx auth generate` to refresh the Prisma schema, then run `prisma migrate`."},f={database:"Drop the column, make it nullable, or give it a database default.",drizzle:"Remove it from the Drizzle schema, make it nullable, or give it a default, then apply the change with your migration tool.",prisma:"Remove it from the Prisma schema, make it optional, or give it a default, then run `prisma migrate`."},g={database:"Database",drizzle:"Drizzle",prisma:"Prisma"};function su(e,t){switch(e.kind){case"missing-table":return`Table "${e.table}" is missing. ${h[t]}`;case"missing-column":return`Column "${e.column}" is missing from table "${e.table}". ${h[t]}`;case"unexpected-required-column":{let n=e.column==="issuer"?" If this column came from Better Auth 1.7.0 through 1.7.2, follow the upgrade guide before removing it: https://www.better-auth.com/docs/guides/1-7-upgrade-guide":"";return`Column "${e.column}" on table "${e.table}" is required but Better Auth never writes it, so every insert into "${e.table}" fails. ${f[t]}${n}`}}}var b={database:"Make the listed columns nullable, give them defaults, or remove them.",drizzle:"Make the listed columns nullable in your Drizzle schema, give them defaults, or remove them.",prisma:"Make the listed fields optional in your Prisma schema, give them defaults, or remove them."},p={...h,database:"Run `npx auth migrate` to add the missing tables and columns."};function v(e,t){let n=[],a=[],s=[],o=new Set,c=!1;for(let r of e)switch(r.kind){case"missing-table":n.push(r.table);break;case"missing-column":a.push(`${r.table}.${r.column}`);break;case"unexpected-required-column":s.push(`${r.table}.${r.column}`),o.add(r.table),c||=r.column==="issuer";break}let i=[`${g[t]} schema mismatch`];if(n.length)i.push(` Missing tables
|
|
3
|
+
${n.join(", ")}`);if(a.length)i.push(` Missing columns
|
|
4
|
+
${a.join(`
|
|
5
|
+
`)}`);if(s.length)i.push(` Required columns Better Auth never writes
|
|
6
|
+
${s.join(`
|
|
7
|
+
`)}`),i.push(` Inserts into ${[...o].join(", ")} will fail.`);let l=[];if(s.length)l.push(b[t]);if(n.length||a.length||s.length&&t!=="database")l.push(p[t]);if(l.length)i.push(` help: ${l.join(`
|
|
8
|
+
`)}`);if(c)i.push(` note: If this column came from Better Auth 1.7.0 through 1.7.2,
|
|
9
|
+
follow the upgrade guide before removing it:
|
|
10
|
+
https://www.better-auth.com/docs/guides/1-7-upgrade-guide`);return i.join(`
|
|
11
|
+
|
|
12
|
+
`)}var Zo=class extends S{code="SCHEMA_MISMATCH";constructor(e,t){super(v(e,t));this.findings=e,this.source=t}};function Ui(e){return e.advanced?.database?.validateSchema!==!1}var d=new WeakMap,u=new WeakMap;function iu(e){let t=u.get(e);if(t)t.value++}function Bi(e,t,n={}){let a=n.runtimeEnabled??!0;d.set(e,{check:t,runtimeEnabled:a})}function ou(e){return d.get(e)?.check}function Fi(e){let t=d.get(e);return t?.runtimeEnabled?t.check:void 0}function qi(e,t,n){let a=n?u.get(n):void 0;if(n&&!a)a={value:0},u.set(n,a);let s=a?.value,o=!1,c,i=function l(){let r=a?.value;if(s!==r)s=r,o=!1,c=void 0;if(o)return;return c??=Promise.resolve().then(e).then((m)=>{if(a?.value!==r)return l();if(m.length)throw new Zo(m,t);if(s===r)o=!0},(m)=>{if(a?.value!==r)return l();if(s===r)c=void 0;throw m})};return i.source=t,i}
|
|
13
|
+
export{Li,_n,su,Zo,Ui,iu,Bi,ou,Fi,qi};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Pi,Ri}from"./chunk-xj26rwda.js";import{Np,Op,Cp,Rd}from"./chunk-ky4nz39j.js";function p(e){return`'${e.replaceAll("'","''")}'`}function f(e){return async(t)=>{if(t.length===0)return[];let n=(await e.batch(t.map((r)=>e.prepare(`PRAGMA index_list(${p(r)})`)))).flatMap((r,o)=>{let i=t[o];if(!i)return[];return r.results.map((u)=>({...u,tableName:i}))});if(n.length===0)return[];let l=await e.batch(n.map((r)=>e.prepare(`PRAGMA index_info(${p(r.name)})`)));return n.map((r,o)=>({columns:(l[o]?.results??[]).map((i)=>({fullLength:i.name!==null,name:i.name,position:i.seqno})),name:r.name,partial:r.partial!==0,table:r.tableName,unique:r.unique!==0,valid:!0}))}}var h=class extends Ri{get supportsMultipleConnections(){return!0}},m=class{#e;#t;constructor(e){this.#e={...e}}async init(){if(this.#t=new w(this.#e.database),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#t)}async acquireConnection(){return this.#t}async beginTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async commitTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async rollbackTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async releaseConnection(){}async destroy(){}},w=class{#e;constructor(e){this.#e=e}async executeQuery(e){let t=await this.#e.prepare(e.sql).bind(...e.parameters).all(),n=t.meta.changes!=null?BigInt(t.meta.changes):void 0;return{insertId:t.meta.last_row_id===void 0||t.meta.last_row_id===null?void 0:BigInt(t.meta.last_row_id),rows:t?.results||[],numAffectedRows:n}}async*streamQuery(){throw Error("D1 does not support streaming queries.")}},d=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").where("name","not like","_cf_%").select(["name","type"]).$castTo();if(!e.withInternalKyselyTables)t=t.where("name","!=",Np).where("name","!=",Op);let n=await t.execute();if(n.length===0)return[];let l=n.map((a)=>this.#t.prepare("SELECT * FROM pragma_table_info(?)").bind(a.name)),r=await this.#t.batch(l),o=n.flatMap((a,s)=>{let c=Cp(r[s]?.results??[]);return c?[{index:s,tableName:a.name,column:c}]:[]}),i=o.length?await this.#t.batch(o.map(({tableName:a})=>this.#t.prepare(`PRAGMA index_list(${p(a)})`))):[],u=new Map(o.filter((a,s)=>!i[s]?.results?.some((c)=>c.origin==="pk")).map(({index:a,column:s})=>[a,s]));return n.map((a,s)=>Rd(a,r[s]?.results??[],u.get(s)))}async getMetadata(e){return{tables:await this.getTables(e)}}},y=class extends Pi{},q=class{#e;constructor(e){this.#e={...e}}createDriver(){return new m(this.#e)}createQueryCompiler(){return new y}createAdapter(){return new h}createIntrospector(e){return new d(e,this.#e.database)}};export{q as D1SqliteDialect,f as createD1IndexIntrospector};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{O}from"./chunk-gefgv8rg.js";import{Ur}from"./chunk-bhm6jzch.js";function N(u,f){if(typeof u==="string"&&typeof f==="string")return u.toLowerCase()===f.toLowerCase();return u===f}function k(u,f){if(typeof u!=="string")return f.includes(u);return f.some((w)=>typeof w==="string"&&u.toLowerCase()===w.toLowerCase())}function J(u,f){return!k(u,f)}function v(u,f){if(typeof u!=="string"||typeof f!=="string")return!1;return u.toLowerCase().includes(f.toLowerCase())}function _(u,f){if(typeof u!=="string"||typeof f!=="string")return!1;return u.toLowerCase().startsWith(f.toLowerCase())}function x(u,f){if(typeof u!=="string"||typeof f!=="string")return!1;return u.toLowerCase().endsWith(f.toLowerCase())}function T(u){let f=new Map;for(let w of u)f.set(w.id,w);return f}function F(u,f,w){let S=new Set([...Object.keys(f),...Object.keys(w)]);for(let M of S){if(!(M in w)){delete u[M];continue}let d=T(f[M]??[]),m=w[M]??[],L=T(m),I=u[M]??[],b=[],C=new Set;for(let n of I){let r=n.id,l=d.get(r),c=L.get(r);if(l!==void 0&&c===void 0)continue;if(c!==void 0&&z(l,c))b.push(c);else b.push(n);C.add(r)}for(let n of m)if(!d.has(n.id)&&!C.has(n.id))b.push(n);u[M]=b}}function z(u,f){if(u===void 0)return!0;return JSON.stringify(u)!==JSON.stringify(f)}var G=(u,f)=>{let w=null,S=(d)=>Ur({config:{adapterId:"memory",adapterName:"Memory Adapter",usePlural:!1,debugLogs:f?.debugLogs||!1,supportsArrays:!0,customTransformInput(m){if(m.options.advanced?.database?.generateId==="serial"&&m.field==="id"&&m.action==="create")return d[m.model].length+1;return m.data},transaction:async(m)=>{let L=structuredClone(d),I=structuredClone(d),b=await m(S(I)(w));return F(d,L,I),b}},adapter:({getFieldName:m,getDefaultFieldName:L,options:I})=>{let b=(n,r,l)=>{if(!r)return n;return n.sort((c,o)=>{let a=m({model:l,field:r.field}),s=c[a],g=o[a],y=0;if(s==null&&g==null)y=0;else if(s==null)y=-1;else if(g==null)y=1;else if(typeof s==="string"&&typeof g==="string")y=s.localeCompare(g);else if(s instanceof Date&&g instanceof Date)y=s.getTime()-g.getTime();else if(typeof s==="number"&&typeof g==="number")y=s-g;else if(typeof s==="boolean"&&typeof g==="boolean")y=s===g?0:s?1:-1;else y=String(s).localeCompare(String(g));return r.direction==="asc"?y:-y})};function C(n,r,l,c,o){let a=(()=>{let y=d[r];if(!y)throw O.error(`[MemoryAdapter] Model ${r} not found in the DB`,Object.keys(d)),Error(`Model ${r} not found`);let h=(e,p)=>{let{field:i,value:t,operator:E,mode:R="sensitive"}=p,j=R==="insensitive"&&(typeof t==="string"||Array.isArray(t)&&t.every((W)=>typeof W==="string"));switch(E){case"in":if(!Array.isArray(t))throw Error("Value must be an array");if(j)return k(e[i],t);return t.includes(e[i]);case"not_in":if(!Array.isArray(t))throw Error("Value must be an array");if(j)return J(e[i],t);return!t.includes(e[i]);case"contains":if(j)return v(e[i],t);return e[i]?.includes(t);case"starts_with":if(j)return _(e[i],t);return e[i].startsWith(t);case"ends_with":if(j)return x(e[i],t);return e[i].endsWith(t);case"ne":return j?!N(e[i],t):e[i]!==t;case"gt":return t!=null&&Boolean(e[i]>t);case"gte":return t!=null&&Boolean(e[i]>=t);case"lt":return t!=null&&Boolean(e[i]<t);case"lte":return t!=null&&Boolean(e[i]<=t);default:if(j)return N(e[i],t);if(t===null)return e[i]==null;return e[i]===t}},A=y.filter((e)=>{if(!n.length||n.length===0)return!0;let p=h(e,n[0]);for(let i of n){let t=h(e,i);if(i.connector==="OR")p=p||t;else p=p&&t}return p});if(o?.length&&o.length>0)A=A.map((e)=>Object.fromEntries(Object.entries(e).filter(([p])=>o.includes(L({model:l,field:p})))));return A})();if(!c)return a;let s=new Map,g=new Map;for(let y of a){let h=String(y.id);if(!s.has(h)){let e={...y};for(let[p,i]of Object.entries(c)){let t=p;if(i.relation==="one-to-one")e[t]=null;else e[t]=[],g.set(`${h}-${p}`,new Set)}s.set(h,e)}let A=s.get(h);for(let[e,p]of Object.entries(c)){let i=e,t=d[i];if(!t)throw O.error(`[MemoryAdapter] JoinOption model ${i} not found in the DB`,Object.keys(d)),Error(`JoinOption model ${i} not found`);let E=t.filter((R)=>R[p.on.to]===y[p.on.from]);if(p.relation==="one-to-one")A[i]=E[0]||null;else{let R=g.get(`${h}-${e}`),j=p.limit??100,W=0;for(let B of E){if(W>=j)break;if(!R.has(B.id))A[i].push(B),R.add(B.id),W++}}}}return Array.from(s.values())}return{create:async({model:n,data:r})=>{if(I.advanced?.database?.generateId==="serial")r.id=d[n].length+1;if(!d[n])d[n]=[];return d[n].push(r),r},findOne:async({model:n,modelKey:r=n,where:l,select:c,join:o})=>{let a=C(l,n,r,o,c);if(o){let s=a;if(!s.length)return null;return s[0]}return a[0]||null},findMany:async({model:n,modelKey:r=n,where:l,sortBy:c,limit:o,select:a,offset:s,join:g})=>{let y=C(l||[],n,r,g,a);if(g){let A=y;if(!A.length)return[];b(A,c,r);let e=A;if(s!==void 0)e=e.slice(s);if(o!==void 0)e=e.slice(0,o);return e}let h=b(y,c,r);if(s!==void 0)h=h.slice(s);if(o!==void 0)h=h.slice(0,o);return h||[]},count:async({model:n,modelKey:r=n,where:l})=>{if(l)return C(l,n,r).length;return d[n].length},update:async({model:n,modelKey:r=n,where:l,update:c})=>{if(l.length===0)return null;let o=C(l,n,r);return o.forEach((a)=>{Object.assign(a,c)}),o[0]||null},delete:async({model:n,modelKey:r=n,where:l})=>{if(l.length===0)return;let c=d[n],o=C(l,n,r);d[n]=c.filter((a)=>!o.includes(a))},deleteMany:async({model:n,modelKey:r=n,where:l})=>{let c=d[n],o=C(l,n,r),a=0;return d[n]=c.filter((s)=>{if(o.includes(s))return a++,!1;return!o.includes(s)}),a},consumeOne:async({model:n,modelKey:r=n,where:l})=>{let c=d[n],o=C(l,n,r)[0];if(!o)return null;return d[n]=c.filter((a)=>a!==o),o},incrementOne:async({model:n,modelKey:r=n,where:l,increment:c,set:o})=>{let a=C(l,n,r)[0];if(!a)return null;for(let[s,g]of Object.entries(c))a[s]=(typeof a[s]==="number"?a[s]:0)+g;if(o)Object.assign(a,o);return a},updateMany:async({model:n,modelKey:r=n,where:l,update:c})=>{let o=C(l,n,r);return o.forEach((a)=>{Object.assign(a,c)}),o.length}}}}),M=S(u);return(d)=>(w=d,M(d))};export{G as memoryAdapter};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{q}from"./chunk-1kgfrgmv.js";import{ud,ii,yr}from"./chunk-1rnmxaav.js";var{SQL:D}=globalThis.Bun;var z=/^cluster_/,O=1000,A=8388608,j=16,F=q.backupSizeScale,B=(t)=>`"${t.replaceAll('"','""')}"`,R=["text","character varying","bytea"],M=["smallint","integer","bigint","boolean","real","double precision","date","timestamp with time zone","timestamp without time zone","uuid"];function N({c:t,type:r}){let e=B(t);if(R.includes(r))return`coalesce(octet_length(${e}), 0)`;if(M.includes(r))return`coalesce(pg_column_size(${e}), 0)`;return`coalesce(octet_length(${e}::text), 0)`}var k=`'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;function G({c:t,type:r}){let e=B(t);if(r==="jsonb"||r==="json")return`${e}::text`;if(r==="boolean")return`${e}::int`;if(r==="bytea")return`case when ${e} is null then null
|
|
3
|
+
else json_build_object('base64', translate(encode(${e}, 'base64'), E'\\n', '')) end`;if(r==="timestamp with time zone")return`to_char(${e} at time zone 'UTC', ${k})`;if(r==="timestamp without time zone")return`to_char(${e}, ${k})`;return e}async function L(t){let[r]=await t`select to_regclass('drizzle.__drizzle_migrations') is not null as present`;if(!r?.present)return 0;let[e]=await t`select max(created_at)::bigint as at from drizzle.__drizzle_migrations`,n=Number(e?.at??0);return(await ud()).entries.filter((s)=>s.when<=n).length}async function na(t){let r=new D({url:t,max:1,...yr()}),e=await r.reserve(),n=async()=>{e.release(),await r.close()},s,l;try{await e`begin isolation level repeatable read read only`,s=await L(e),l=await e`
|
|
4
|
+
select table_name as t, column_name as c, data_type as type from information_schema.columns
|
|
5
|
+
where table_schema = 'public' and is_generated = 'NEVER' order by table_name, ordinal_position`}catch(a){throw await n(),a}async function f(a,o,i,y,m){let b=await e.unsafe(`select ctid::text as "$ctid", (${o.map(N).join(" + ")})::bigint as bytes from ${B(a)}
|
|
6
|
+
where ctid > $1::tid order by ctid limit ${y}`,[i]),d;for(let u of b){let p=(d?.bytes??0)+Number(u.bytes)*F;if(d&&p>m)break;d={end:u.$ctid,bytes:p}}return d}async function*c(){try{let a=[...new Set(l.map((i)=>i.t))].filter((i)=>!z.test(i)),o=0;for(let i of a){let y=l.filter((u)=>u.t===i);yield Buffer.from(`${JSON.stringify({table:i,columns:y.map((u)=>u.c)})}
|
|
7
|
+
`);let m="(0,0)",b=j,d=A;for(;;){let u=await f(i,y,m,b,d);if(!u)break;let[p]=await e.unsafe(`select convert_to(string_agg(json_build_array(${y.map(G).join(", ")})::text, E'\\n'
|
|
8
|
+
order by ctid) || E'\\n', 'UTF8') as lines
|
|
9
|
+
from ${B(i)} where ctid > $1::tid and ctid <= $2::tid`,[m,u.end]),E=p?.lines?.byteLength??0;if(p?.lines)yield p.lines;if(m=u.end,d=A*Math.min(1,u.bytes/Math.max(E,1)),b=O,o+=E,o>=A)Bun.gc(!0),o=0}}await e`commit`}finally{await n()}}return{migrations:s,lines:c()}}async function Zf({url:t,replace:r=!1}){let e=await ii(t);if(e>0&&!r)throw Error(`the database has ${e} accounts already: pass --replace to replace them`)}var Xf=(t)=>`${Object.values(t).reduce((r,e)=>r+e,0)} rows in ${Object.keys(t).length} tables, into Postgres`;import{mkdir as W,rm as X,stat as J}from"fs/promises";import{join as Q}from"path";import{createCipheriv as Y,createDecipheriv as C,hkdfSync as H}from"crypto";var g=Buffer.from("SFBACKUP"),T=1,x=16,I=16,_=g.length+1+x,S=1048576,V="superfactory database backup v1";function U(t,r){let e=Buffer.from(t,"base64");if(e.length!==32)throw Error("the master key must be 32 bytes, base64-encoded");return Buffer.from(H("sha256",e,r,V,32))}function v(t,r){let e=Buffer.alloc(12);return e.writeBigUInt64BE(BigInt(t),0),e[11]=r?1:0,e}async function*ns(t,r,e){let n=crypto.getRandomValues(new Uint8Array(x)),s=Buffer.concat([g,Buffer.from([T]),n]),l=U(t,n);yield s;let f=0,c=(y,m)=>{let b=Y("aes-256-gcm",l,v(f++,m));b.setAAD(s);let d=Buffer.concat([b.update(y),b.final(),b.getAuthTag()]),u=Buffer.alloc(4);return u.writeUInt32BE(d.length),Buffer.concat([u,d])},a=Buffer.from(JSON.stringify(r)),o=[],i=0;for await(let y of e){o.push(Buffer.from(y)),i+=y.byteLength;while(i>=S){let m=Buffer.concat(o);yield c(a,!1),a=m.subarray(0,S),o=[m.subarray(S)],i=m.length-S}}if(i>0)yield c(a,!1),a=Buffer.concat(o);yield c(a,!0)}async function ss(t,r){let e=K(t,r),n=await e.next();if(n.done)throw Error("the backup is empty");return{facts:JSON.parse(Buffer.from(n.value).toString("utf8")),body:e}}async function*K(t,r){let e=Buffer.alloc(0),n,s,l=0,f,c=(a,o)=>{let i=C("aes-256-gcm",s,v(l++,o));i.setAAD(n),i.setAuthTag(a.subarray(a.length-I));try{return Buffer.concat([i.update(a.subarray(0,a.length-I)),i.final()])}catch{throw Error("the backup doesn't open: another master key made it, or it was changed or cut short")}};for await(let a of r){if(e=Buffer.concat([e,Buffer.from(a)]),!n){if(e.length<_)continue;if(n=e.subarray(0,_),!n.subarray(0,g.length).equals(g))throw Error("not a Superfactory backup");if(n[g.length]!==T)throw Error(`a backup of format ${n[g.length]}: restore it with a newer server`);s=U(t,n.subarray(g.length+1)),e=e.subarray(_)}while(e.length>=4&&e.length>=4+e.readUInt32BE(0)){let o=e.readUInt32BE(0),i=e.subarray(4,4+o);if(e=e.subarray(4+o),f)yield c(f,!1);f=Buffer.from(i)}}if(!f||e.length>0)throw Error("the backup is cut short");yield c(f,!0)}var Z=["media/","avatars/","platforms/","repos/"],w="files/",h="deleted/",ee=(t)=>t.toISOString().replaceAll(":","-"),P=(t)=>new Date(t.replace(/T(\d{2})-(\d{2})-(\d{2})/,"T$1:$2:$3"));async function te(t){return(await Promise.all(Z.map((r)=>t.list(r)))).flat()}async function sa(t,r,e,n){let s=await te(t),l=new Map((await r.list(w)).map((a)=>[a.key.slice(w.length),a])),f=0;for(let a of s){let o=l.get(a.key);if(o&&o.modifiedAt>=a.modifiedAt)continue;await re(r,`${w}${a.key}`,e,a.key,t),f++}let c=new Set(s.map((a)=>a.key));for(let a of l.keys())if(!c.has(a))await ne(r,`${w}${a}`,`${h}${ee(n)}/${a}`);return{count:s.length,bytes:s.reduce((a,o)=>a+o.size,0),copied:f}}async function em(t,r){for(let e of await t.list(h))if(P(e.key.slice(h.length).split("/")[0]??"")<r)await t.delete(e.key)}async function tm(t,r,e,n){let s=new Map;for(let c of await t.list(h)){let[a,...o]=c.key.slice(h.length).split("/");if(P(a??"")>=e)s.set(o.join("/"),c.key)}for(let c of await t.list(w))s.set(c.key.slice(w.length),c.key);let l=0,f=0;for(let[c,a]of s){if(await n.stat(c)){f++;continue}let o=await t.localFile(a);try{let{body:i}=await ss(r,Bun.file(o.path).stream());await xn(n,c,i),l++}finally{await o.release()}}return{restored:l,present:f}}async function re(t,r,e,n,s){let l=await s.localFile(n);try{await xn(t,r,ns(e,{kind:"file",key:n},Bun.file(l.path).stream()))}finally{await l.release()}}async function ne(t,r,e){let n=await t.localFile(r);try{await xn(t,e,Bun.file(n.path).stream())}finally{await n.release()}await t.delete(r)}async function xn(t,r,e){return uu(t,r,(n)=>zi(n,e))}async function uu(t,r,e){await W(t.scratchDir,{recursive:!0,mode:448});let n=Q(t.scratchDir,`backup-${crypto.randomUUID()}`);try{await e(n);let{size:s}=await J(n);return await t.moveIn(r,n),s}finally{await X(n,{force:!0})}}async function zi(t,r){let e=Bun.file(t).writer();for await(let n of r)e.write(n);await e.end()}
|
|
10
|
+
export{na,Zf,Xf,ns,ss,sa,em,tm,xn,uu,zi};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{ap,X,Fe,pn,pd,Ba,co,ct,lo,Qg}from"./chunk-1rnmxaav.js";import{ir}from"./chunk-1kgfrgmv.js";import{kn,rn,Us}from"./chunk-18n7tr66.js";import{na,Zf,Xf,ns,ss,tm,xn,uu}from"./chunk-q403h2bh.js";import{mkdir as U,mkdtemp as D,readdir as K,rm as T,writeFile as O}from"fs/promises";import{tmpdir as R}from"os";import{dirname as v,join as p}from"path";function Vi(e){let t=Buffer.from(JSON.stringify(e)),r=Buffer.alloc(4);return r.writeUInt32BE(t.length),Buffer.concat([r,t])}async function*nl(e){let t=new b(e);for(;;){if(await t.atEnd())return;let r=await t.exactly(4),s=JSON.parse((await t.exactly(r.readUInt32BE(0))).toString()),n=s.size===void 0?t.rest():t.next(s.size);yield{header:s,bytes:n};for await(let a of n);if(s.size===void 0)return}}class b{held=Buffer.alloc(0);chunks;ended=!1;constructor(e){this.chunks=e[Symbol.asyncIterator]()}async fill(){if(this.ended)return!1;let e=await this.chunks.next();if(e.done)return this.ended=!0,!1;return this.held=Buffer.concat([this.held,e.value]),!0}async atEnd(){return this.held.length===0&&!await this.fill()}async exactly(e){while(this.held.length<e)if(!await this.fill())throw Error("the backup is cut short");let t=this.held.subarray(0,e);return this.held=this.held.subarray(e),t}async*next(e){let t=e;while(t>0){if(this.held.length===0&&!await this.fill())throw Error("the backup is cut short");let r=this.held.subarray(0,Math.min(t,this.held.length));this.held=this.held.subarray(r.length),t-=r.length,yield r}}async*rest(){if(this.held.length)yield this.held;this.held=Buffer.alloc(0);while(await this.fill())yield this.held,this.held=Buffer.alloc(0)}}function rs(e){let t=e[Symbol.asyncIterator]();return new ReadableStream({async pull(r){let s=await t.next();if(s.done)r.close();else r.enqueue(s.value)},async cancel(r){await t.return?.(r)}})}import{join as x}from"path";function Tr(e){let t=e.SF_BACKUP_S3_BUCKET,r=t??e.SF_S3_BUCKET;if(!r){let a=x(e.SF_DATA_DIR,"backups");return{store:new rn(a),destination:a}}let s=[t?"":e.SF_S3_PREFIX,e.SF_BACKUP_S3_PREFIX].map((a)=>a.replace(/^\/+|\/+$/g,"")).filter(Boolean).join("/");return{store:new Us({bucket:r,endpoint:e.SF_BACKUP_S3_ENDPOINT??e.SF_S3_ENDPOINT,region:e.SF_BACKUP_S3_REGION??e.SF_S3_REGION,accessKeyId:e.SF_BACKUP_S3_ACCESS_KEY_ID??e.SF_S3_ACCESS_KEY_ID,secretAccessKey:e.SF_BACKUP_S3_SECRET_ACCESS_KEY??e.SF_S3_SECRET_ACCESS_KEY,prefix:s}),destination:`s3://${r}/${s?`${s}/`:""}`}}var F=/^(\d{4}-\d{2}-\d{2})T(\d{2})-(\d{2})-(\d{2})\.(\d{3})Z\.(sqlite|pg)\.sfbackup$/;function h(e,t){return`${e.toISOString().replaceAll(":","-")}.${t}.sfbackup`}function P(e){let t=F.exec(e);if(!t)return;let[,r,s,n,a,c,o]=t;return{name:e,at:new Date(`${r}T${s}:${n}:${a}.${c}Z`),dialect:o}}async function Ls(e){return(await e.list("")).flatMap((t)=>{let r=P(t.key);return r?[{...r,size:t.size}]:[]}).sort((t,r)=>r.at.getTime()-t.at.getTime())}function lu(e,t){if(!e.SF_S3_BUCKET)return new rn(t);return new Us({bucket:e.SF_S3_BUCKET,endpoint:e.SF_S3_ENDPOINT,region:e.SF_S3_REGION,accessKeyId:e.SF_S3_ACCESS_KEY_ID,secretAccessKey:e.SF_S3_SECRET_ACCESS_KEY,prefix:e.SF_S3_PREFIX})}var g=(e)=>e.toISOString().slice(0,10),C=(e)=>e.toISOString().slice(0,7);function I(e){let t=new Date(e);return t.setUTCDate(e.getUTCDate()-(e.getUTCDay()+6)%7),g(t)}function ra(e,t){let r=[...e].sort((a,c)=>c.at.getTime()-a.at.getTime()),s=new Set(r.slice(0,1).map((a)=>a.name)),n=(a,c)=>{let o=new Set;for(let i of r){if(o.size>=c)break;let u=a(i.at);if(o.has(u))continue;o.add(u),s.add(i.name)}};return n(g,t.daily),n(I,t.weekly),n(C,t.monthly),s}var N=["auth-secret","avatar-key","vapid.json"],z=["tls"],G=["avatar-key","vapid.json"];async function M(e){let t=[...N];for(let s of z)for(let n of await K(p(e,s)).catch(()=>[]))t.push(`${s}/${n}`);let r=[];for(let s of t){let n=Bun.file(p(e,s));if(await n.exists())r.push({name:s,bytes:await n.bytes()})}return r}async function Yf(e,t,r,s,n=new Date){let a=h(n,"pg");return{name:a,size:await xn(e,a,du(t,r,s,n))}}async function Jf(e,t,r,s,n=new Date){let a=h(n,"pg"),c={masterKey:t,url:r,dataDir:s,createdAt:n.toISOString()};return{name:a,size:await uu(e,a,(o)=>q({...c,file:o}))}}var _=18000000,Y=ir("src/features/backups/backup-process.ts");async function q(e){let t=await Fe(X(ap).programPath(process.execPath).flag("--smol").arg(Y).timeoutMs(_).build(),{input:JSON.stringify(e)});if(t.exitCode===0)return;let r=t.stdout.trim().split(`
|
|
3
|
+
`).at(-1)??"",s=r.startsWith("{")?JSON.parse(r).error:void 0;if(s)throw Error(s);if(t.timedOut)throw Error(`the backup took more than ${_/3600000} hours`);if(t.signal)throw Error(`the backup's process was stopped (${t.signal}): the server ran out of memory?`);throw Error(`the backup's process failed (exit ${t.exitCode}): ${t.stderr.trim().slice(-500)}`)}async function*du(e,t,r,s){let n=await M(r),a=await na(t),c={format:3,dialect:"pg",createdAt:s.toISOString(),migrations:a.migrations,keys:n.map((i)=>i.name)},o=rs(J(n,"rows",a.lines)).pipeThrough(new CompressionStream("gzip"));yield*ns(e,c,o)}async function*J(e,t,r){for(let s of e)yield Vi({part:"key",name:s.name,size:s.bytes.length}),yield s.bytes;yield Vi({part:"database",form:t}),yield*r}async function Qf(e,t,r,s){let n=await e.localFile(r),a=await D(p(R(),"superfactory-restore-"));try{let{facts:c,body:o}=await ss(t,Bun.file(n.path).stream()),i=c;if(i.format!==2&&i.format!==3)throw Error(`a backup of format ${i.format}: this server reads formats 2 and 3`);let u=await s.database();await Zf({url:u,replace:s.replace});let f=new Map,m=p(a,ct),y,k=rs(o).pipeThrough(new DecompressionStream("gzip"));for await(let{header:l,bytes:d}of nl(k))if(l.part==="key")f.set(String(l.name),Buffer.concat(await L(d)));else if(l.part==="database"&&l.form==="rows"&&i.format===3)y=await Ba(u,i.migrations??0,co(d));else if(l.part==="database"&&l.form==="rows")await Qg(m,i.migrations??0,co(d));else if(l.part==="database")await Bun.write(m,new Response(rs(d)));y??=await lo(m,u);let A=Xf(y),S=s.replicas?await j(u,t,f):[],B=[...f].filter(([l])=>!S.includes(l)&&!(s.replicas&&l.startsWith("tls/"))),w=await H(s.dataDir,new Map(B)),E=s.files?await tm(e,t,new Date(i.createdAt),s.files):void 0;return{facts:i,database:A,keys:{written:w,sealed:S,kept:[...f.keys()].filter((l)=>!w.includes(l)&&!S.includes(l))},files:E}}finally{await T(a,{recursive:!0,force:!0}),await n.release()}}async function j(e,t,r){let{db:s,close:n}=await pd(e);try{let a=new kn(s,await pn.fromBase64(t)),c=[];for(let o of G){let i=r.get(o);if(!i)continue;await a.set(o,new TextDecoder().decode(i).trim()),c.push(o)}return c}finally{await n()}}async function H(e,t){let r=[];for(let[s,n]of t){let a=p(e,s);if(await Bun.file(a).exists())continue;await U(v(a),{recursive:!0,mode:448}),await O(a,n,{mode:384}),r.push(s)}return r}async function L(e){let t=[];for await(let r of e)t.push(r);return t}
|
|
4
|
+
export{Vi,nl,rs,Tr,Ls,lu,ra,Yf,Jf,du,Qf};
|