@hiai-gg/docsmint 2.0.4 → 2.1.1
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 +74 -5
- package/dist/backend/index.js +94475 -92073
- package/dist/backend-account-runtime-cleanup.js +293 -292
- package/dist/backend-api-key-facade.js +6 -5
- package/dist/backend-pipeline-cancellation.js +287 -286
- package/dist/client.d.ts +33 -7
- package/dist/client.js +55 -1
- package/dist/frontend/CategoryDialog-CVJi5PJu.js +602 -0
- package/dist/frontend/{ConfirmDialog-B1MjKlVQ.js → ConfirmDialog-0JwB8mKN.js} +5 -8
- package/dist/frontend/{CreateSnapshotDialog-BTMoPFdj.js → CreateSnapshotDialog-BLrtuYs5.js} +63 -68
- package/dist/frontend/{DatePicker-Bmjko3X7.js → DatePicker-BwSb8TRv.js} +17 -29
- package/dist/frontend/{DeleteDialog-BkfIeKXO.js → DeleteDialog-s7Dr6bXg.js} +51 -56
- package/dist/frontend/{FolderNode-Do8pIfyA.js → FolderNode-Y7cV9xeX.js} +105 -106
- package/dist/frontend/{FolderTreeSelector-FyxhcHjr.js → FolderTreeSelector-BR3lYmPU.js} +18 -20
- package/dist/frontend/HiAiEditor-BQERr-cd.js +3077 -0
- package/dist/frontend/{HiaiDocsExtensionProvider-Cc3yzW5I.js → HiaiDocsExtensionProvider-A2nGddUR.js} +2 -3
- package/dist/frontend/{Icon-3EYzvNyk.js → Icon-CiHcxcpv.js} +1 -2
- package/dist/frontend/SettingsDialog-BvS74JZu.js +978 -0
- package/dist/frontend/{ShareDialog-Ddvl7xvb.js → ShareDialog-Bo50h_Oe.js} +23 -25
- package/dist/frontend/Sidebar-i0kbanpg.js +2123 -0
- package/dist/frontend/{TagCreateDialog-DQmMJe_E.js → TagCreateDialog-DhKfsfv3.js} +78 -86
- package/dist/frontend/action_cancel-BdsWzQKU.js +4 -0
- package/dist/frontend/action_close-CVhfLPRQ.js +4 -0
- package/dist/frontend/action_create-ByaroO1_.js +4 -0
- package/dist/frontend/action_delete-SRloglWY.js +4 -0
- package/dist/frontend/action_go_to-DO1bicF-.js +4 -0
- package/dist/frontend/action_loading-iQ0KsN6i.js +4 -0
- package/dist/frontend/action_save-DeqrZQwV.js +4 -0
- package/dist/frontend/api/attachments.js +1 -2
- package/dist/frontend/api/categories.js +1 -2
- package/dist/frontend/api/documents.js +1 -2
- package/dist/frontend/api/folders.js +1 -2
- package/dist/frontend/api/settings.js +1 -2
- package/dist/frontend/api/share.js +1 -2
- package/dist/frontend/api/tags.js +1 -2
- package/dist/frontend/{api-keys-DIwAdYkg.js → api-keys-B63imiLr.js} +2 -3
- package/dist/frontend/app-shell.js +55 -79
- package/dist/frontend/{attachments-C225gTA7.js → attachments-Bfly-sam.js} +2 -3
- package/dist/frontend/{auth-client-CXR-7mIO.js → auth-client-Dx7d9Tzo.js} +409 -343
- package/dist/frontend/{bundle-mjs-CZ3g1Uzr.js → bundle-mjs-clTO1WW-.js} +5 -23
- package/dist/frontend/{camera-DtgHzfVI.js → camera-DsdOPOcD.js} +2 -3
- package/dist/frontend/{categories-C8AAkhCR.js → categories-CusvHb5Y.js} +3 -4
- package/dist/frontend/{categories_update_error-4aSI8PTr.js → categories_update_error-Cn8DBBHv.js} +2 -3
- package/dist/frontend/{check-DVx65aSv.js → check-DiMZRkKS.js} +2 -3
- package/dist/frontend/{chevron-down-C2tbZ8Ol.js → chevron-down-CxFrMFDJ.js} +2 -3
- package/dist/frontend/{circle-check-BAN-D7yg.js → circle-check-B4F_qgPx.js} +2 -3
- package/dist/frontend/{client-GbtOH90i.js → client-BDdDd84W.js} +1 -2
- package/dist/frontend/{clipboard-Cgzxc0_R.js → clipboard-Dt1oW6nm.js} +1 -2
- package/dist/frontend/{clock-ByiB0SwQ.js → clock-dcpueRk-.js} +2 -3
- package/dist/frontend/collaboration.js +6 -12
- package/dist/frontend/components/category-dialog.js +1 -2
- package/dist/frontend/components/create-snapshot-dialog.js +1 -2
- package/dist/frontend/components/delete-dialog.js +1 -2
- package/dist/frontend/components/editor/compact-editor.js +2 -3
- package/dist/frontend/components/editor/document-editor.js +1 -2
- package/dist/frontend/components/editor/document-title.js +3 -4
- package/dist/frontend/components/editor/docx-serializer.js +123 -167
- package/dist/frontend/components/editor/extensions.js +1 -2
- package/dist/frontend/components/editor/markdown-toggle.js +5 -6
- package/dist/frontend/components/editor/markdown.js +1 -2
- package/dist/frontend/components/folder-node.js +1 -2
- package/dist/frontend/components/folder-tree-selector.js +1 -2
- package/dist/frontend/components/save-as-dialog.js +86 -90
- package/dist/frontend/components/settings.js +1 -2
- package/dist/frontend/components/share-dialog.js +1 -2
- package/dist/frontend/components/sidebar.js +1 -2
- package/dist/frontend/components/tag-create-dialog.js +1 -2
- package/dist/frontend/components/version-history.js +177 -180
- package/dist/frontend/{context-D0zPFXZ4.js → context-BguSRnCt.js} +1 -2
- package/dist/frontend/{copy-CRzvfZGb.js → copy-Bag46YaR.js} +2 -3
- package/dist/frontend/dashboard.js +666 -690
- package/dist/frontend/{db-Dya0HRhS.js → db-B1ZV452J.js} +22 -39
- package/dist/frontend/{dialog-a_ZcpEC5.js → dialog-C0Bpok1d.js} +10 -18
- package/dist/frontend/{dist-CcHOStsA.js → dist-BlcV_BOY.js} +2 -3
- package/dist/frontend/{dist-qd_OnyUC.js → dist-DjId3RKL.js} +8 -21
- package/dist/frontend/dist-Dl9qg10h.js +301 -0
- package/dist/frontend/{dndzone-CDhrbpTg.js → dndzone-C62yjeG3.js} +38 -53
- package/dist/frontend/doc-tabs.js +1 -2
- package/dist/frontend/doc_title_label-BOuZzvqv.js +4 -0
- package/dist/frontend/doc_title_placeholder-ZxpdWWEn.js +4 -0
- package/dist/frontend/{document-drop-coordinator-Da7HcXgv.js → document-drop-coordinator-C_o93kKW.js} +3 -4
- package/dist/frontend/document-drop-coordinator.js +1 -2
- package/dist/frontend/{documents-CwCs1rA7.js → documents-CDJb8dv-.js} +4 -8
- package/dist/frontend/{dropdown-menu-DrHYReIC.js → dropdown-menu-B3nk2aM-.js} +13 -24
- package/dist/frontend/{editor-content-sanitizer-CWjqiz0T.js → editor-content-sanitizer-5MjSVPVn.js} +1 -2
- package/dist/frontend/editor-preferences.js +1 -2
- package/dist/frontend/{editor-preferences.svelte-Bt_A9k7n.js → editor-preferences.svelte-BpTE4mbz.js} +3 -5
- package/dist/frontend/{editorExtensions-DPR-CjMu.js → editorExtensions-DbiFj4tn.js} +3 -4
- package/dist/frontend/{editor_markdown_placeholder-BIWDUF1E.js → editor_markdown_placeholder-BztIY9Ci.js} +2 -3
- package/dist/frontend/{ellipsis-vertical-qxNgoXu-.js → ellipsis-vertical-Oymsv1R4.js} +2 -3
- package/dist/frontend/{error_dismiss-Dx_JbRjs.js → error_dismiss-C651ZdWI.js} +2 -3
- package/dist/frontend/error_generic-BlWqOE-a.js +4 -0
- package/dist/frontend/extension.js +1 -2
- package/dist/frontend/{folder-D74E-Kdp.js → folder-BpmB_sAy.js} +3 -5
- package/dist/frontend/folder-refresh.js +1 -2
- package/dist/frontend/{folders-CC0UWkZH.js → folders-DgKSovXa.js} +2 -3
- package/dist/frontend/{folders_rename-BJo4Gipq.js → folders_rename-Cxbg5GIw.js} +2 -3
- package/dist/frontend/frontend.css +1 -1
- package/dist/frontend/i18n.js +144 -145
- package/dist/frontend/{identity-BOA7Jejv.js → identity-B7HeOzDJ.js} +4 -5
- package/dist/frontend/{input-Q_7qCfnU.js → input-CbeB9220.js} +2 -3
- package/dist/frontend/keyboard.js +1 -2
- package/dist/frontend/{keyboard.svelte-CApmX0vl.js → keyboard.svelte-BBUdhTsM.js} +2 -3
- package/dist/frontend/{label-Dj8FDEhf.js → label-CfBWf3gI.js} +2 -3
- package/dist/frontend/{lib-aUbBbIW2.js → lib-CITdCbKa.js} +176 -365
- package/dist/frontend/{loader-circle-D3t5NkvC.js → loader-circle-skKwfRCB.js} +2 -3
- package/dist/frontend/markdown-6E9TWC6V.js +11 -0
- package/dist/frontend/offline/identity.js +1 -2
- package/dist/frontend/{popper-layer-force-mount-CNtiLgbV.js → popper-layer-force-mount-BG0eyrCk.js} +112 -284
- package/dist/frontend/{resolve-BG4HgzpN.js → resolve-DbT-KhGZ.js} +2 -3
- package/dist/frontend/{rolldown-runtime-DArdT4gl.js → rolldown-runtime-CwxnZyOB.js} +2 -3
- package/dist/frontend/{rotate-ccw-B1ybQ8oQ.js → rotate-ccw-DAUX7np7.js} +2 -3
- package/dist/frontend/{route-context-DYQlUfzL.js → route-context-6OHiGtfb.js} +2 -4
- package/dist/frontend/{runtime-CwWSo6c9.js → runtime-CGUiMzK6.js} +1 -2
- package/dist/frontend/{schemas-1Na35n71.js → schemas-YXxhj5o8.js} +850 -880
- package/dist/frontend/scroll_to_top_aria-lJc2RSx_.js +4 -0
- package/dist/frontend/{search-preferences-B1GdbdUc.js → search-preferences-DuLDczRu.js} +1 -2
- package/dist/frontend/search.js +277 -292
- package/dist/frontend/{search_title-DOC0cPlQ.js → search_title-BETwQYJq.js} +2 -3
- package/dist/frontend/{select-value-BkI1W1bn.js → select-value-BY5Hw6Rl.js} +28 -65
- package/dist/frontend/{settings-BRcYFQa_.js → settings-DyePuqjp.js} +3 -4
- package/dist/frontend/{share-D5yo0JOh.js → share-3gWTTYvH.js} +2 -3
- package/dist/frontend/{share-context-BJ4GF4yT.js → share-context-C2xyVP9M.js} +29 -37
- package/dist/frontend/{share_copied-DPxVzfWh.js → share_copied-BuAnmpbz.js} +2 -3
- package/dist/frontend/{share_toggle_password-DdxfIjj1.js → share_toggle_password-LEYUeHWr.js} +2 -3
- package/dist/frontend/shared-document.js +27 -36
- package/dist/frontend/{sidebar_uncategorized-qJ2_Aonf.js → sidebar_uncategorized-C5PGOflV.js} +2 -3
- package/dist/frontend/{sort_relevance-DwYX5MO9.js → sort_relevance-DpCVLby_.js} +2 -3
- package/dist/frontend/{subfolders-refresh-store.svelte-DxP21a1c.js → subfolders-refresh-store.svelte-CeyqvNpu.js} +1 -2
- package/dist/frontend/{tag-qbTBLj-g.js → tag-Wdfe0rKU.js} +3 -5
- package/dist/frontend/{tag-store.svelte-ogVCMCbv.js → tag-store.svelte-C9VYWqLQ.js} +2 -3
- package/dist/frontend/{tags-CF_cqzSV.js → tags-DlDVothf.js} +3 -4
- package/dist/frontend/{tags_load_error-BKjA1pI0.js → tags_load_error-BINNpPPV.js} +2 -3
- package/dist/frontend/{tags_new-BiNAJ9Bx.js → tags_new-Dw0Uy43-.js} +2 -3
- package/dist/frontend/{textarea-BNK0LFUK.js → textarea-D6emvAwM.js} +2 -3
- package/dist/frontend/theme.js +2 -3
- package/dist/frontend/{theme.svelte-BRdxXd-B.js → theme.svelte-BiXvrqwh.js} +7 -23
- package/dist/frontend/{theme_system-BBNUhYKh.js → theme_system-YIfa_2Xt.js} +2 -3
- package/dist/frontend/utils/clipboard.js +1 -2
- package/dist/frontend/utils/dndzone.js +1 -2
- package/dist/frontend/{utils-BovMJHdA.js → utils-CnAmIMwr.js} +2 -3
- package/dist/frontend/utils-DH0uqK40.js +6 -0
- package/dist/frontend/utils.js +1 -2
- package/dist/frontend/version_create_snapshot-D8xjbuCq.js +4 -0
- package/dist/frontend/{version_restored_from-dVRN3Zdk.js → version_restored_from-DYFFSuQj.js} +2 -3
- package/dist/frontend/{version_snapshot_label_placeholder-DrMikux0.js → version_snapshot_label_placeholder-BhKq1NQ7.js} +2 -3
- package/dist/frontend/{weekday_we-C5H_M-df.js → weekday_we-BxbzNVWR.js} +2 -3
- package/dist/frontend/{x-CvSSnrjl.js → x-CBUgPygC.js} +2 -3
- package/dist/frontend/{yjs-VUcKqaKW.js → yjs-BbwnvxgY.js} +9 -23
- package/dist/frontend-ssr/api/attachments.js +2 -3
- package/dist/frontend-ssr/api/categories.js +1 -2
- package/dist/frontend-ssr/api/documents.js +1 -2
- package/dist/frontend-ssr/api/folders.js +1 -2
- package/dist/frontend-ssr/api/settings.js +1 -2
- package/dist/frontend-ssr/api/share.js +2 -3
- package/dist/frontend-ssr/api/tags.js +1 -2
- package/dist/frontend-ssr/app-shell.js +19 -28
- package/dist/frontend-ssr/assets/{CategoryDialog-DuZLLlt7.js → CategoryDialog-2CCX508O.js} +17 -20
- package/dist/frontend-ssr/assets/{ConfirmDialog-0WVu9BCE.js → ConfirmDialog-Cc6lcY1N.js} +8 -14
- package/dist/frontend-ssr/assets/{CreateSnapshotDialog-3vhDTFNu.js → CreateSnapshotDialog-BB8fXF9W.js} +9 -10
- package/dist/frontend-ssr/assets/{DatePicker-t12leL2Y.js → DatePicker-CfzKzipR.js} +9 -15
- package/dist/frontend-ssr/assets/{DeleteDialog-B0AU1fJR.js → DeleteDialog-DRU4UgOW.js} +4 -5
- package/dist/frontend-ssr/assets/{FolderNode-C-B-s8x1.js → FolderNode-Dg_5-orQ.js} +11 -12
- package/dist/frontend-ssr/assets/{FolderTreeSelector-DdQuEcj0.js → FolderTreeSelector-D0reTdFS.js} +5 -7
- package/dist/frontend-ssr/assets/{HiAiEditor-Bj6tiE97.js → HiAiEditor-DeHWAIj-.js} +44 -69
- package/dist/frontend-ssr/assets/{HiaiDocsExtensionProvider-BRKWmcDd.js → HiaiDocsExtensionProvider-D6cGL-9s.js} +2 -3
- package/dist/frontend-ssr/assets/{Icon-DE_3EnuF.js → Icon-CrIRbT5O.js} +4 -8
- package/dist/frontend-ssr/assets/{SettingsDialog-h4SFwpUa.js → SettingsDialog-BpHY3IMb.js} +29 -40
- package/dist/frontend-ssr/assets/{ShareDialog-CpE9zd_f.js → ShareDialog-CY40nWZJ.js} +7 -9
- package/dist/frontend-ssr/assets/{Sidebar-BFBpsd3L.js → Sidebar-fpYk5MGO.js} +55 -63
- package/dist/frontend-ssr/assets/{TagCreateDialog-DBHO1DPU.js → TagCreateDialog-C2tpdEuj.js} +13 -14
- package/dist/frontend-ssr/assets/{action_cancel-OVgQDP5Q.js → action_cancel-CsBbxW0m.js} +2 -3
- package/dist/frontend-ssr/assets/{action_close-DagDyMXk.js → action_close-lFKBqBwg.js} +2 -3
- package/dist/frontend-ssr/assets/{action_create-hqJWjyqh.js → action_create-BV4ZOcQW.js} +2 -3
- package/dist/frontend-ssr/assets/{action_delete-B1-16jSo.js → action_delete-CNmRhKQP.js} +2 -3
- package/dist/frontend-ssr/assets/{action_go_to-DQScgw7P.js → action_go_to-tN5I26xM.js} +2 -3
- package/dist/frontend-ssr/assets/{action_save-Bx7vlLZI.js → action_save-YCfMiKb4.js} +2 -3
- package/dist/frontend-ssr/assets/{api-keys-CHOrbU-Q.js → api-keys-G6oimJIv.js} +2 -3
- package/dist/frontend-ssr/assets/{auth-client-BC4hSFKF.js → auth-client-BnnnJDAb.js} +368 -256
- package/dist/frontend-ssr/assets/{camera-B6ldo_Js.js → camera-OYNSMvMd.js} +2 -3
- package/dist/frontend-ssr/assets/{categories-C_dxFoHi.js → categories-bBPviKjl.js} +2 -3
- package/dist/frontend-ssr/assets/{categories_update_error-DkKgsqdD.js → categories_update_error-Bfx5vtvt.js} +11 -21
- package/dist/frontend-ssr/assets/{chevron-down-DQcr6JUc.js → chevron-down-DB6YsSbQ.js} +2 -3
- package/dist/frontend-ssr/assets/{chevron-right-9szrliZx.js → chevron-right-DOt2uY6b.js} +2 -3
- package/dist/frontend-ssr/assets/{circle-check-BgP9MRRv.js → circle-check-DQhTm9YR.js} +2 -3
- package/dist/frontend-ssr/assets/{client-rfwQYYHY.js → client-B2AniXwV.js} +1 -2
- package/dist/frontend-ssr/assets/{clipboard-CXOaoz2W.js → clipboard-CXKnyYba.js} +1 -2
- package/dist/frontend-ssr/assets/{clock-roNtGlT6.js → clock-B08dVWtf.js} +2 -3
- package/dist/frontend-ssr/assets/{context-Bi_mO-NS.js → context-C_xxvxnR.js} +1 -2
- package/dist/frontend-ssr/assets/{copy-BYqYnBIQ.js → copy-2jsznHar.js} +2 -3
- package/dist/frontend-ssr/assets/{db-C3rFdTZa.js → db-BEKLU5Fc.js} +2 -3
- package/dist/frontend-ssr/assets/{dialog-SqCnTT43.js → dialog-C6U-DqLr.js} +9 -17
- package/dist/frontend-ssr/assets/{dist-CaZQ1FhA.js → dist-DqXTz_zE.js} +9 -12
- package/dist/frontend-ssr/assets/{dist-CqxHwOlp.js → dist-ip9bPdma.js} +3 -6
- package/dist/frontend-ssr/assets/{dndzone-CnTCMhPd.js → dndzone-Dx3jt_e4.js} +4 -6
- package/dist/frontend-ssr/assets/{doc_title_label-Ev_ltlh3.js → doc_title_label-CE_l-Gum.js} +2 -3
- package/dist/frontend-ssr/assets/{doc_title_placeholder-DSHpUb7w.js → doc_title_placeholder-7_i7PtG6.js} +2 -3
- package/dist/frontend-ssr/assets/{document-drop-coordinator-CEaYACsC.js → document-drop-coordinator-BVytYy2K.js} +1 -2
- package/dist/frontend-ssr/assets/{documents-CEuA1V6N.js → documents-B_wpQFTh.js} +2 -3
- package/dist/frontend-ssr/assets/{dropdown-menu-CE6U0f1b.js → dropdown-menu-BS5fcN9l.js} +12 -23
- package/dist/frontend-ssr/assets/{editor-content-sanitizer-Gjm93iR-.js → editor-content-sanitizer-CIdFjBSC.js} +1 -2
- package/dist/frontend-ssr/assets/{editor-preferences.svelte-iI5jJM1x.js → editor-preferences.svelte-CdAXTd-I.js} +2 -4
- package/dist/frontend-ssr/assets/{editorExtensions-rhletNji.js → editorExtensions-2O7O2Nhv.js} +2 -3
- package/dist/frontend-ssr/assets/{editor_markdown_placeholder-BpezdkOr.js → editor_markdown_placeholder-CAeLJjFT.js} +3 -5
- package/dist/frontend-ssr/assets/{editor_toolbar_undo-CKJAOqv2.js → editor_toolbar_undo-CVCfQIS1.js} +29 -57
- package/dist/frontend-ssr/assets/{ellipsis-vertical-Cg1MrZsl.js → ellipsis-vertical-IFHt2NM1.js} +2 -3
- package/dist/frontend-ssr/assets/{error_generic-DTK0kwxT.js → error_generic-BB80i0Vk.js} +3 -5
- package/dist/frontend-ssr/assets/{folder-DHB-CEcQ.js → folder-CXa1_bm5.js} +2 -3
- package/dist/frontend-ssr/assets/{folders-BOXeb9hz.js → folders-CTLqWbMm.js} +2 -3
- package/dist/frontend-ssr/assets/{folders_rename-DvciOb6K.js → folders_rename-ydbfwQlj.js} +7 -13
- package/dist/frontend-ssr/assets/{identity-DNIo1bgc.js → identity-DTz1SQwC.js} +2 -3
- package/dist/frontend-ssr/assets/{input-DVrBVPgs.js → input-Bxw9sFF0.js} +2 -3
- package/dist/frontend-ssr/assets/{keyboard.svelte-BgF47N3L.js → keyboard.svelte-njehUCm3.js} +1 -2
- package/dist/frontend-ssr/assets/{label-vtCK3pTp.js → label-CMWedjs6.js} +2 -3
- package/dist/frontend-ssr/assets/{loader-circle-D3NWhCif.js → loader-circle-zbKj9Qb-.js} +2 -3
- package/dist/frontend-ssr/assets/{markdown-Co31-Tl2.js → markdown-BmIhDQp7.js} +2 -3
- package/dist/frontend-ssr/assets/{popper-layer-force-mount-C4dMMt-f.js → popper-layer-force-mount-CSHZsG2E.js} +78 -156
- package/dist/frontend-ssr/assets/{resolve-BqHozBXl.js → resolve-Wqdff4CL.js} +1 -2
- package/dist/frontend-ssr/assets/{rotate-ccw-DNf3nwMD.js → rotate-ccw-B7SaTFWf.js} +2 -3
- package/dist/frontend-ssr/assets/{route-context-BPRerEtZ.js → route-context-BsqLFt5Y.js} +2 -4
- package/dist/frontend-ssr/assets/{runtime-O78RzRqx.js → runtime-BX6-jTn_.js} +1 -2
- package/dist/frontend-ssr/assets/{scroll_to_top_aria-BN4ZfOnM.js → scroll_to_top_aria-CAYSiGHO.js} +2 -3
- package/dist/frontend-ssr/assets/{search_title-CKUsQDT0.js → search_title-C7NVXXq3.js} +2 -3
- package/dist/frontend-ssr/assets/{search_toggle_filters-hS9rvQhC.js → search_toggle_filters-Bq_YVD8s.js} +15 -29
- package/dist/frontend-ssr/assets/{select-value-Ce5c_fuA.js → select-value-TgslfiUB.js} +18 -34
- package/dist/frontend-ssr/assets/{settings-DWCpfCPj.js → settings-B1MA_FjO.js} +3 -4
- package/dist/frontend-ssr/assets/{share-context-B4UpvTSw.js → share-context-RVh8AExX.js} +17 -22
- package/dist/frontend-ssr/assets/{share_copied-BxU9rjXG.js → share_copied-CrwEwkb3.js} +31 -61
- package/dist/frontend-ssr/assets/{share_toggle_password-C6OmroqR.js → share_toggle_password-Co56z0Ha.js} +11 -21
- package/dist/frontend-ssr/assets/{sidebar_uncategorized-Dx-LTd5w.js → sidebar_uncategorized-COWdmZ3d.js} +6 -11
- package/dist/frontend-ssr/assets/{subfolders-refresh-store.svelte-CXHxQWKh.js → subfolders-refresh-store.svelte-LxG18U0n.js} +1 -2
- package/dist/frontend-ssr/assets/{tag-Cqv0fWVG.js → tag-BGhtDKpP.js} +3 -5
- package/dist/frontend-ssr/assets/{tag-store.svelte-QRysvGKe.js → tag-store.svelte-CUUgAaDD.js} +2 -3
- package/dist/frontend-ssr/assets/{tags-BBCoFYro.js → tags-C7u-LBsl.js} +2 -3
- package/dist/frontend-ssr/assets/{tags_load_error-CPrc6Gzs.js → tags_load_error-DW4FbHvr.js} +19 -37
- package/dist/frontend-ssr/assets/{tags_new-VmMr9v2V.js → tags_new-Dr3ByMPZ.js} +4 -7
- package/dist/frontend-ssr/assets/{textarea-BdjOJJVb.js → textarea-Bz5Tz4rw.js} +2 -3
- package/dist/frontend-ssr/assets/{theme.svelte-D6bbaJ9m.js → theme.svelte-CdHah46l.js} +3 -5
- package/dist/frontend-ssr/assets/{theme_system-BucaNntV.js → theme_system-E97FASeq.js} +19 -37
- package/dist/frontend-ssr/assets/{utils-DvZnctjz.js → utils-085zSPe5.js} +1 -2
- package/dist/frontend-ssr/assets/{utils-D3X7I8nz.js → utils-DF6CmRDX.js} +1 -2
- package/dist/frontend-ssr/assets/{version_create_snapshot-COHzwjle.js → version_create_snapshot-DeeYB7bb.js} +2 -3
- package/dist/frontend-ssr/assets/{version_restored_from-CertjFDl.js → version_restored_from-CTt2LM4A.js} +13 -25
- package/dist/frontend-ssr/assets/{version_snapshot_label_placeholder-Cy_rMCij.js → version_snapshot_label_placeholder-BbGD9YuN.js} +12 -23
- package/dist/frontend-ssr/assets/{weekday_we-DrI3U230.js → weekday_we-BzGQ-iFc.js} +22 -43
- package/dist/frontend-ssr/collaboration.js +2 -4
- package/dist/frontend-ssr/components/category-dialog.js +1 -2
- package/dist/frontend-ssr/components/create-snapshot-dialog.js +1 -2
- package/dist/frontend-ssr/components/delete-dialog.js +1 -2
- package/dist/frontend-ssr/components/editor/compact-editor.js +2 -3
- package/dist/frontend-ssr/components/editor/document-editor.js +1 -2
- package/dist/frontend-ssr/components/editor/document-title.js +3 -4
- package/dist/frontend-ssr/components/editor/docx-serializer.js +1 -2
- package/dist/frontend-ssr/components/editor/extensions.js +1 -2
- package/dist/frontend-ssr/components/editor/markdown-toggle.js +4 -5
- package/dist/frontend-ssr/components/editor/markdown.js +1 -2
- package/dist/frontend-ssr/components/folder-node.js +1 -2
- package/dist/frontend-ssr/components/folder-tree-selector.js +1 -2
- package/dist/frontend-ssr/components/save-as-dialog.js +12 -13
- package/dist/frontend-ssr/components/settings.js +1 -2
- package/dist/frontend-ssr/components/share-dialog.js +1 -2
- package/dist/frontend-ssr/components/sidebar.js +1 -2
- package/dist/frontend-ssr/components/tag-create-dialog.js +1 -2
- package/dist/frontend-ssr/components/version-history.js +18 -21
- package/dist/frontend-ssr/dashboard.js +64 -88
- package/dist/frontend-ssr/doc-tabs.js +1 -2
- package/dist/frontend-ssr/document-drop-coordinator.js +1 -2
- package/dist/frontend-ssr/editor-preferences.js +1 -2
- package/dist/frontend-ssr/extension.js +1 -2
- package/dist/frontend-ssr/folder-refresh.js +1 -2
- package/dist/frontend-ssr/i18n.js +315 -603
- package/dist/frontend-ssr/keyboard.js +1 -2
- package/dist/frontend-ssr/offline/identity.js +1 -2
- package/dist/frontend-ssr/search.js +17 -20
- package/dist/frontend-ssr/shared-document.js +5 -8
- package/dist/frontend-ssr/theme.js +2 -3
- package/dist/frontend-ssr/utils/clipboard.js +1 -2
- package/dist/frontend-ssr/utils/dndzone.js +1 -2
- package/dist/frontend-ssr/utils.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lifecycle-runtime.js +3998 -17872
- package/dist/mcp-cli.js +357 -78
- package/dist/mcp-server.d.ts +92 -23
- package/dist/mcp-server.js +525 -78
- package/dist/types.d.ts +68 -1
- package/package.json +5 -5
- package/packages/cli/src/index.ts +1 -1
- package/packages/db/src/schema.ts +3 -1
- package/server.json +2 -2
- package/dist/frontend/CategoryDialog-CJeAYxcd.js +0 -630
- package/dist/frontend/HiAiEditor-DDpfdQEg.js +0 -3129
- package/dist/frontend/SettingsDialog-DzlYW50I.js +0 -991
- package/dist/frontend/Sidebar-rFiVen96.js +0 -2149
- package/dist/frontend/action_cancel-Cuxsznzz.js +0 -5
- package/dist/frontend/action_close-BJm_52wm.js +0 -5
- package/dist/frontend/action_create-CtBQrRuj.js +0 -5
- package/dist/frontend/action_delete-BXBIzvn0.js +0 -5
- package/dist/frontend/action_go_to-VmK5jmEk.js +0 -5
- package/dist/frontend/action_loading-BLCGJVA9.js +0 -5
- package/dist/frontend/action_save-BRN2Z_GP.js +0 -5
- package/dist/frontend/dist-DcHl92QO.js +0 -316
- package/dist/frontend/doc_title_label-DS9jSIh2.js +0 -5
- package/dist/frontend/doc_title_placeholder-DBQpM1aH.js +0 -5
- package/dist/frontend/error_generic-CzNtmBT4.js +0 -5
- package/dist/frontend/markdown-O9YJA70S.js +0 -12
- package/dist/frontend/scroll_to_top_aria-CvkNF_Hu.js +0 -5
- package/dist/frontend/utils-BlHvR6OL.js +0 -7
- package/dist/frontend/version_create_snapshot-3bu-0qzH.js +0 -5
|
@@ -149,10 +149,11 @@ var accounts = pgTable("accounts", {
|
|
|
149
149
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
150
150
|
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
151
151
|
accountId: text("account_id").notNull(),
|
|
152
|
-
issuer: text("issuer")
|
|
152
|
+
issuer: text("issuer"),
|
|
153
153
|
providerId: text("provider_id").notNull(),
|
|
154
154
|
accessToken: text("access_token"),
|
|
155
155
|
refreshToken: text("refresh_token"),
|
|
156
|
+
idToken: text("id_token"),
|
|
156
157
|
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
157
158
|
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
158
159
|
scope: text("scope"),
|
|
@@ -959,44 +960,44 @@ class Builder extends NotTagged {
|
|
|
959
960
|
this.first = first;
|
|
960
961
|
this.rest = rest;
|
|
961
962
|
}
|
|
962
|
-
build(before, parameters,
|
|
963
|
+
build(before, parameters, types, options) {
|
|
963
964
|
const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b) => a.i - b.i).pop();
|
|
964
|
-
return keyword.i === -1 ? escapeIdentifiers(this.first, options) : keyword.fn(this.first, this.rest, parameters,
|
|
965
|
+
return keyword.i === -1 ? escapeIdentifiers(this.first, options) : keyword.fn(this.first, this.rest, parameters, types, options);
|
|
965
966
|
}
|
|
966
967
|
}
|
|
967
|
-
function handleValue(x, parameters,
|
|
968
|
+
function handleValue(x, parameters, types, options) {
|
|
968
969
|
let value = x instanceof Parameter ? x.value : x;
|
|
969
970
|
if (value === undefined) {
|
|
970
971
|
x instanceof Parameter ? x.value = options.transform.undefined : value = x = options.transform.undefined;
|
|
971
972
|
if (value === undefined)
|
|
972
973
|
throw Errors.generic("UNDEFINED_VALUE", "Undefined values are not allowed");
|
|
973
974
|
}
|
|
974
|
-
return "$" +
|
|
975
|
+
return "$" + types.push(x instanceof Parameter ? (parameters.push(x.value), x.array ? x.array[x.type || inferType(x.value)] || x.type || firstIsString(x.value) : x.type) : (parameters.push(x), inferType(x)));
|
|
975
976
|
}
|
|
976
977
|
var defaultHandlers = typeHandlers(types);
|
|
977
|
-
function stringify(q, string, value, parameters,
|
|
978
|
+
function stringify(q, string, value, parameters, types, options) {
|
|
978
979
|
for (let i = 1;i < q.strings.length; i++) {
|
|
979
|
-
string += stringifyValue(string, value, parameters,
|
|
980
|
+
string += stringifyValue(string, value, parameters, types, options) + q.strings[i];
|
|
980
981
|
value = q.args[i];
|
|
981
982
|
}
|
|
982
983
|
return string;
|
|
983
984
|
}
|
|
984
|
-
function stringifyValue(string, value, parameters,
|
|
985
|
-
return value instanceof Builder ? value.build(string, parameters,
|
|
985
|
+
function stringifyValue(string, value, parameters, types, o) {
|
|
986
|
+
return value instanceof Builder ? value.build(string, parameters, types, o) : value instanceof Query ? fragment(value, parameters, types, o) : value instanceof Identifier ? value.value : value && value[0] instanceof Query ? value.reduce((acc, x) => acc + " " + fragment(x, parameters, types, o), "") : handleValue(value, parameters, types, o);
|
|
986
987
|
}
|
|
987
|
-
function fragment(q, parameters,
|
|
988
|
+
function fragment(q, parameters, types, options) {
|
|
988
989
|
q.fragment = true;
|
|
989
|
-
return stringify(q, q.strings[0], q.args[0], parameters,
|
|
990
|
+
return stringify(q, q.strings[0], q.args[0], parameters, types, options);
|
|
990
991
|
}
|
|
991
|
-
function valuesBuilder(first, parameters,
|
|
992
|
-
return first.map((row) => "(" + columns.map((column) => stringifyValue("values", row[column], parameters,
|
|
992
|
+
function valuesBuilder(first, parameters, types, columns, options) {
|
|
993
|
+
return first.map((row) => "(" + columns.map((column) => stringifyValue("values", row[column], parameters, types, options)).join(",") + ")").join(",");
|
|
993
994
|
}
|
|
994
|
-
function values(first, rest, parameters,
|
|
995
|
+
function values(first, rest, parameters, types, options) {
|
|
995
996
|
const multi = Array.isArray(first[0]);
|
|
996
997
|
const columns = rest.length ? rest.flat() : Object.keys(multi ? first[0] : first);
|
|
997
|
-
return valuesBuilder(multi ? first : [first], parameters,
|
|
998
|
+
return valuesBuilder(multi ? first : [first], parameters, types, columns, options);
|
|
998
999
|
}
|
|
999
|
-
function select(first, rest, parameters,
|
|
1000
|
+
function select(first, rest, parameters, types, options) {
|
|
1000
1001
|
typeof first === "string" && (first = [first].concat(rest));
|
|
1001
1002
|
if (Array.isArray(first))
|
|
1002
1003
|
return escapeIdentifiers(first, options);
|
|
@@ -1004,7 +1005,7 @@ function select(first, rest, parameters, types2, options) {
|
|
|
1004
1005
|
const columns = rest.length ? rest.flat() : Object.keys(first);
|
|
1005
1006
|
return columns.map((x) => {
|
|
1006
1007
|
value = first[x];
|
|
1007
|
-
return (value instanceof Query ? fragment(value, parameters,
|
|
1008
|
+
return (value instanceof Query ? fragment(value, parameters, types, options) : value instanceof Identifier ? value.value : handleValue(value, parameters, types, options)) + " as " + escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x);
|
|
1008
1009
|
}).join(",");
|
|
1009
1010
|
}
|
|
1010
1011
|
var builders = Object.entries({
|
|
@@ -1017,12 +1018,12 @@ var builders = Object.entries({
|
|
|
1017
1018
|
as: select,
|
|
1018
1019
|
returning: select,
|
|
1019
1020
|
"\\(": select,
|
|
1020
|
-
update(first, rest, parameters,
|
|
1021
|
-
return (rest.length ? rest.flat() : Object.keys(first)).map((x) => escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) + "=" + stringifyValue("values", first[x], parameters,
|
|
1021
|
+
update(first, rest, parameters, types, options) {
|
|
1022
|
+
return (rest.length ? rest.flat() : Object.keys(first)).map((x) => escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) + "=" + stringifyValue("values", first[x], parameters, types, options));
|
|
1022
1023
|
},
|
|
1023
|
-
insert(first, rest, parameters,
|
|
1024
|
+
insert(first, rest, parameters, types, options) {
|
|
1024
1025
|
const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first);
|
|
1025
|
-
return "(" + escapeIdentifiers(columns, options) + ")values" + valuesBuilder(Array.isArray(first) ? first : [first], parameters,
|
|
1026
|
+
return "(" + escapeIdentifiers(columns, options) + ")values" + valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options);
|
|
1026
1027
|
}
|
|
1027
1028
|
}).map(([x, fn]) => [new RegExp("((?:^|[\\s(])" + x + "(?:$|[\\s(]))(?![\\s\\S]*\\1)", "i"), fn]);
|
|
1028
1029
|
function notTagged() {
|
|
@@ -1035,19 +1036,19 @@ function firstIsString(x) {
|
|
|
1035
1036
|
return firstIsString(x[0]);
|
|
1036
1037
|
return typeof x === "string" ? 1009 : 0;
|
|
1037
1038
|
}
|
|
1038
|
-
var mergeUserTypes = function(
|
|
1039
|
-
const user = typeHandlers(
|
|
1039
|
+
var mergeUserTypes = function(types) {
|
|
1040
|
+
const user = typeHandlers(types || {});
|
|
1040
1041
|
return {
|
|
1041
1042
|
serializers: Object.assign({}, serializers, user.serializers),
|
|
1042
1043
|
parsers: Object.assign({}, parsers, user.parsers)
|
|
1043
1044
|
};
|
|
1044
1045
|
};
|
|
1045
|
-
function typeHandlers(
|
|
1046
|
-
return Object.keys(
|
|
1047
|
-
|
|
1048
|
-
if (
|
|
1049
|
-
acc.serializers[
|
|
1050
|
-
|
|
1046
|
+
function typeHandlers(types) {
|
|
1047
|
+
return Object.keys(types).reduce((acc, k) => {
|
|
1048
|
+
types[k].from && [].concat(types[k].from).forEach((x) => acc.parsers[x] = types[k].parse);
|
|
1049
|
+
if (types[k].serialize) {
|
|
1050
|
+
acc.serializers[types[k].to] = types[k].serialize;
|
|
1051
|
+
types[k].from && [].concat(types[k].from).forEach((x) => acc.serializers[x] = types[k].serialize);
|
|
1051
1052
|
}
|
|
1052
1053
|
return acc;
|
|
1053
1054
|
}, { parsers: {}, serializers: {} });
|
|
@@ -1058,15 +1059,15 @@ function escapeIdentifiers(xs, { transform: { column } }) {
|
|
|
1058
1059
|
var escapeIdentifier = function escape(str) {
|
|
1059
1060
|
return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"';
|
|
1060
1061
|
};
|
|
1061
|
-
var inferType = function
|
|
1062
|
-
return x instanceof Parameter ? x.type : x instanceof Date ? 1184 : x instanceof Uint8Array ? 17 : x === true || x === false ? 16 : typeof x === "bigint" ? 20 : Array.isArray(x) ?
|
|
1062
|
+
var inferType = function inferType(x) {
|
|
1063
|
+
return x instanceof Parameter ? x.type : x instanceof Date ? 1184 : x instanceof Uint8Array ? 17 : x === true || x === false ? 16 : typeof x === "bigint" ? 20 : Array.isArray(x) ? inferType(x[0]) : 0;
|
|
1063
1064
|
};
|
|
1064
1065
|
var escapeBackslash = /\\/g;
|
|
1065
1066
|
var escapeQuote = /"/g;
|
|
1066
1067
|
function arrayEscape(x) {
|
|
1067
1068
|
return x.replace(escapeBackslash, "\\\\").replace(escapeQuote, "\\\"");
|
|
1068
1069
|
}
|
|
1069
|
-
var arraySerializer = function
|
|
1070
|
+
var arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
|
|
1070
1071
|
if (Array.isArray(xs) === false)
|
|
1071
1072
|
return xs;
|
|
1072
1073
|
if (!xs.length)
|
|
@@ -1074,7 +1075,7 @@ var arraySerializer = function arraySerializer2(xs, serializer, options, typarra
|
|
|
1074
1075
|
const first = xs[0];
|
|
1075
1076
|
const delimiter = typarray === 1020 ? ";" : ",";
|
|
1076
1077
|
if (Array.isArray(first) && !first.type)
|
|
1077
|
-
return "{" + xs.map((x) =>
|
|
1078
|
+
return "{" + xs.map((x) => arraySerializer(x, serializer, options, typarray)).join(delimiter) + "}";
|
|
1078
1079
|
return "{" + xs.map((x) => {
|
|
1079
1080
|
if (x === undefined) {
|
|
1080
1081
|
x = options.transform.undefined;
|
|
@@ -1091,7 +1092,7 @@ var arrayParserState = {
|
|
|
1091
1092
|
quoted: false,
|
|
1092
1093
|
last: 0
|
|
1093
1094
|
};
|
|
1094
|
-
var arrayParser = function
|
|
1095
|
+
var arrayParser = function arrayParser(x, parser, typarray) {
|
|
1095
1096
|
arrayParserState.i = arrayParserState.last = 0;
|
|
1096
1097
|
return arrayParserLoop(arrayParserState, x, parser, typarray);
|
|
1097
1098
|
};
|
|
@@ -1148,7 +1149,7 @@ var fromPascal = (x) => (x.slice(0, 1) + x.slice(1).replace(/([A-Z])/g, "_$1")).
|
|
|
1148
1149
|
var fromKebab = (x) => x.replace(/-/g, "_");
|
|
1149
1150
|
function createJsonTransform(fn) {
|
|
1150
1151
|
return function jsonTransform(x, column) {
|
|
1151
|
-
return typeof x === "object" && x !== null && (column.type === 114 || column.type === 3802) ? Array.isArray(x) ? x.map((
|
|
1152
|
+
return typeof x === "object" && x !== null && (column.type === 114 || column.type === 3802) ? Array.isArray(x) ? x.map((x) => jsonTransform(x, column)) : Object.entries(x).reduce((acc, [k, v]) => Object.assign(acc, { [fn(k)]: jsonTransform(v, column) }), {}) : x;
|
|
1152
1153
|
};
|
|
1153
1154
|
}
|
|
1154
1155
|
toCamel.column = { from: toCamel };
|
|
@@ -1195,23 +1196,23 @@ class Result extends Array {
|
|
|
1195
1196
|
var queue_default = Queue;
|
|
1196
1197
|
function Queue(initial = []) {
|
|
1197
1198
|
let xs = initial.slice();
|
|
1198
|
-
let
|
|
1199
|
+
let index = 0;
|
|
1199
1200
|
return {
|
|
1200
1201
|
get length() {
|
|
1201
|
-
return xs.length -
|
|
1202
|
+
return xs.length - index;
|
|
1202
1203
|
},
|
|
1203
1204
|
remove: (x) => {
|
|
1204
|
-
const
|
|
1205
|
-
return
|
|
1205
|
+
const index = xs.indexOf(x);
|
|
1206
|
+
return index === -1 ? null : (xs.splice(index, 1), x);
|
|
1206
1207
|
},
|
|
1207
1208
|
push: (x) => (xs.push(x), x),
|
|
1208
1209
|
shift: () => {
|
|
1209
|
-
const out = xs[
|
|
1210
|
-
if (
|
|
1211
|
-
|
|
1210
|
+
const out = xs[index++];
|
|
1211
|
+
if (index === xs.length) {
|
|
1212
|
+
index = 0;
|
|
1212
1213
|
xs = [];
|
|
1213
1214
|
} else {
|
|
1214
|
-
xs[
|
|
1215
|
+
xs[index - 1] = undefined;
|
|
1215
1216
|
}
|
|
1216
1217
|
return out;
|
|
1217
1218
|
}
|
|
@@ -1334,7 +1335,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1334
1335
|
host,
|
|
1335
1336
|
port,
|
|
1336
1337
|
database,
|
|
1337
|
-
parsers
|
|
1338
|
+
parsers,
|
|
1338
1339
|
transform,
|
|
1339
1340
|
onnotice,
|
|
1340
1341
|
onnotify,
|
|
@@ -1346,11 +1347,11 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1346
1347
|
} = options;
|
|
1347
1348
|
const sent = queue_default(), id = uid++, backend = { pid: null, secret: null }, idleTimer = timer(end, options.idle_timeout), lifeTimer = timer(end, options.max_lifetime), connectTimer = timer(connectTimedOut, options.connect_timeout);
|
|
1348
1349
|
let socket = null, cancelMessage, errorResponse = null, result = new Result, incoming = Buffer.alloc(0), needsTypes = options.fetch_types, backendParameters = {}, statements = {}, statementId = Math.random().toString(36).slice(2), statementCount = 1, closedTime = 0, remaining = 0, hostIndex = 0, retries = 0, length = 0, delay = 0, rows = 0, serverSignature = null, nextWriteTimer = null, terminated = false, incomings = null, results = null, initial = null, ending = null, stream = null, chunk = null, ended = null, nonce = null, query = null, final = null;
|
|
1349
|
-
const
|
|
1350
|
+
const connection = {
|
|
1350
1351
|
queue: queues.closed,
|
|
1351
1352
|
idleTimer,
|
|
1352
|
-
connect(
|
|
1353
|
-
initial =
|
|
1353
|
+
connect(query) {
|
|
1354
|
+
initial = query;
|
|
1354
1355
|
reconnect();
|
|
1355
1356
|
},
|
|
1356
1357
|
terminate,
|
|
@@ -1360,8 +1361,8 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1360
1361
|
count: 0,
|
|
1361
1362
|
id
|
|
1362
1363
|
};
|
|
1363
|
-
queues.closed && queues.closed.push(
|
|
1364
|
-
return
|
|
1364
|
+
queues.closed && queues.closed.push(connection);
|
|
1365
|
+
return connection;
|
|
1365
1366
|
async function createSocket() {
|
|
1366
1367
|
let x;
|
|
1367
1368
|
try {
|
|
@@ -1381,8 +1382,8 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1381
1382
|
await connect();
|
|
1382
1383
|
socket.once("error", reject);
|
|
1383
1384
|
socket.once("close", resolve);
|
|
1384
|
-
} catch (
|
|
1385
|
-
reject(
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
reject(error);
|
|
1386
1387
|
}
|
|
1387
1388
|
}
|
|
1388
1389
|
function execute(q) {
|
|
@@ -1396,10 +1397,10 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1396
1397
|
q.state = backend;
|
|
1397
1398
|
query ? sent.push(q) : (query = q, query.active = true);
|
|
1398
1399
|
build(q);
|
|
1399
|
-
return write(toBuffer(q)) && !q.describeFirst && !q.cursorFn && sent.length < max_pipeline && (!q.options.onexecute || q.options.onexecute(
|
|
1400
|
-
} catch (
|
|
1400
|
+
return write(toBuffer(q)) && !q.describeFirst && !q.cursorFn && sent.length < max_pipeline && (!q.options.onexecute || q.options.onexecute(connection));
|
|
1401
|
+
} catch (error) {
|
|
1401
1402
|
sent.length === 0 && write(Sync);
|
|
1402
|
-
errored(
|
|
1403
|
+
errored(error);
|
|
1403
1404
|
return true;
|
|
1404
1405
|
}
|
|
1405
1406
|
}
|
|
@@ -1428,18 +1429,18 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1428
1429
|
]);
|
|
1429
1430
|
}
|
|
1430
1431
|
function build(q) {
|
|
1431
|
-
const parameters = [],
|
|
1432
|
-
const string = stringify(q, q.strings[0], q.args[0], parameters,
|
|
1433
|
-
!q.tagged && q.args.forEach((x) => handleValue(x, parameters,
|
|
1432
|
+
const parameters = [], types = [];
|
|
1433
|
+
const string = stringify(q, q.strings[0], q.args[0], parameters, types, options);
|
|
1434
|
+
!q.tagged && q.args.forEach((x) => handleValue(x, parameters, types, options));
|
|
1434
1435
|
q.prepare = options.prepare && ("prepare" in q.options ? q.options.prepare : true);
|
|
1435
1436
|
q.string = string;
|
|
1436
|
-
q.signature = q.prepare &&
|
|
1437
|
+
q.signature = q.prepare && types + string;
|
|
1437
1438
|
q.onlyDescribe && delete statements[q.signature];
|
|
1438
1439
|
q.parameters = q.parameters || parameters;
|
|
1439
1440
|
q.prepared = q.prepare && q.signature in statements;
|
|
1440
1441
|
q.describeFirst = q.onlyDescribe || parameters.length && !q.prepared;
|
|
1441
|
-
q.statement = q.prepared ? statements[q.signature] : { string, types
|
|
1442
|
-
typeof options.debug === "function" && options.debug(id, string, parameters,
|
|
1442
|
+
q.statement = q.prepared ? statements[q.signature] : { string, types, name: q.prepare ? statementId + statementCount++ : "" };
|
|
1443
|
+
typeof options.debug === "function" && options.debug(id, string, parameters, types);
|
|
1443
1444
|
}
|
|
1444
1445
|
function write(x, fn) {
|
|
1445
1446
|
chunk = chunk ? Buffer.concat([chunk, x]) : Buffer.from(x);
|
|
@@ -1465,25 +1466,25 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1465
1466
|
if (!canSSL && ssl === "prefer")
|
|
1466
1467
|
return connected();
|
|
1467
1468
|
}
|
|
1468
|
-
const
|
|
1469
|
+
const options = {
|
|
1469
1470
|
socket,
|
|
1470
1471
|
servername: net.isIP(socket.host) ? undefined : socket.host
|
|
1471
1472
|
};
|
|
1472
1473
|
if (sslnegotiation === "direct")
|
|
1473
|
-
|
|
1474
|
+
options.ALPNProtocols = ["postgresql"];
|
|
1474
1475
|
if (ssl === "require" || ssl === "allow" || ssl === "prefer")
|
|
1475
|
-
|
|
1476
|
+
options.rejectUnauthorized = false;
|
|
1476
1477
|
else if (typeof ssl === "object")
|
|
1477
|
-
Object.assign(
|
|
1478
|
+
Object.assign(options, ssl);
|
|
1478
1479
|
socket.removeAllListeners();
|
|
1479
|
-
socket = tls.connect(
|
|
1480
|
+
socket = tls.connect(options);
|
|
1480
1481
|
socket.on("secureConnect", connected);
|
|
1481
1482
|
socket.on("error", error);
|
|
1482
1483
|
socket.on("close", closed);
|
|
1483
1484
|
socket.on("drain", drain);
|
|
1484
1485
|
}
|
|
1485
1486
|
function drain() {
|
|
1486
|
-
!query && onopen(
|
|
1487
|
+
!query && onopen(connection);
|
|
1487
1488
|
}
|
|
1488
1489
|
function data(x) {
|
|
1489
1490
|
if (incomings) {
|
|
@@ -1548,7 +1549,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1548
1549
|
}
|
|
1549
1550
|
}
|
|
1550
1551
|
function error(err) {
|
|
1551
|
-
if (
|
|
1552
|
+
if (connection.queue === queues.connecting && options.host[retries + 1])
|
|
1552
1553
|
return;
|
|
1553
1554
|
errored(err);
|
|
1554
1555
|
while (sent.length)
|
|
@@ -1559,23 +1560,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1559
1560
|
query && queryError(query, err);
|
|
1560
1561
|
initial && (queryError(initial, err), initial = null);
|
|
1561
1562
|
}
|
|
1562
|
-
function queryError(
|
|
1563
|
-
if (
|
|
1564
|
-
return
|
|
1563
|
+
function queryError(query, err) {
|
|
1564
|
+
if (query.reserve)
|
|
1565
|
+
return query.reject(err);
|
|
1565
1566
|
if (!err || typeof err !== "object")
|
|
1566
1567
|
err = new Error(err);
|
|
1567
1568
|
"query" in err || "parameters" in err || Object.defineProperties(err, {
|
|
1568
|
-
stack: { value: err.stack +
|
|
1569
|
+
stack: { value: err.stack + query.origin.replace(/.*\n/, `
|
|
1569
1570
|
`), enumerable: options.debug },
|
|
1570
|
-
query: { value:
|
|
1571
|
-
parameters: { value:
|
|
1572
|
-
args: { value:
|
|
1573
|
-
types: { value:
|
|
1571
|
+
query: { value: query.string, enumerable: options.debug },
|
|
1572
|
+
parameters: { value: query.parameters, enumerable: options.debug },
|
|
1573
|
+
args: { value: query.args, enumerable: options.debug },
|
|
1574
|
+
types: { value: query.statement && query.statement.types, enumerable: options.debug }
|
|
1574
1575
|
});
|
|
1575
|
-
|
|
1576
|
+
query.reject(err);
|
|
1576
1577
|
}
|
|
1577
1578
|
function end() {
|
|
1578
|
-
return ending || (!
|
|
1579
|
+
return ending || (!connection.reserved && onend(connection), !connection.reserved && !initial && !query && sent.length === 0 ? (terminate(), new Promise((r) => socket && socket.readyState !== "closed" ? socket.once("close", r) : r())) : ending = new Promise((r) => ended = r));
|
|
1579
1580
|
}
|
|
1580
1581
|
function terminate() {
|
|
1581
1582
|
terminated = true;
|
|
@@ -1607,22 +1608,22 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1607
1608
|
closedTime = performance.now();
|
|
1608
1609
|
hadError && options.shared.retries++;
|
|
1609
1610
|
delay = (typeof backoff === "function" ? backoff(options.shared.retries) : backoff) * 1000;
|
|
1610
|
-
onclose(
|
|
1611
|
+
onclose(connection, Errors.connection("CONNECTION_CLOSED", options, socket));
|
|
1611
1612
|
}
|
|
1612
1613
|
function handle(xs, x = xs[0]) {
|
|
1613
1614
|
(x === 68 ? DataRow : x === 100 ? CopyData : x === 65 ? NotificationResponse : x === 83 ? ParameterStatus : x === 90 ? ReadyForQuery : x === 67 ? CommandComplete : x === 50 ? BindComplete : x === 49 ? ParseComplete : x === 116 ? ParameterDescription : x === 84 ? RowDescription : x === 82 ? Authentication : x === 110 ? NoData : x === 75 ? BackendKeyData : x === 69 ? ErrorResponse : x === 115 ? PortalSuspended : x === 51 ? CloseComplete : x === 71 ? CopyInResponse : x === 78 ? NoticeResponse : x === 72 ? CopyOutResponse : x === 99 ? CopyDone : x === 73 ? EmptyQueryResponse : x === 86 ? FunctionCallResponse : x === 118 ? NegotiateProtocolVersion : x === 87 ? CopyBothResponse : UnknownMessage)(xs);
|
|
1614
1615
|
}
|
|
1615
1616
|
function DataRow(x) {
|
|
1616
|
-
let
|
|
1617
|
-
let
|
|
1617
|
+
let index = 7;
|
|
1618
|
+
let length;
|
|
1618
1619
|
let column;
|
|
1619
1620
|
let value;
|
|
1620
1621
|
const row = query.isRaw ? new Array(query.statement.columns.length) : {};
|
|
1621
1622
|
for (let i = 0;i < query.statement.columns.length; i++) {
|
|
1622
1623
|
column = query.statement.columns[i];
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
value =
|
|
1624
|
+
length = x.readInt32BE(index);
|
|
1625
|
+
index += 4;
|
|
1626
|
+
value = length === -1 ? null : query.isRaw === true ? x.subarray(index, index += length) : column.parser === undefined ? x.toString("utf8", index, index += length) : column.parser.array === true ? column.parser(x.toString("utf8", index + 1, index += length)) : column.parser(x.toString("utf8", index, index += length));
|
|
1626
1627
|
query.isRaw ? row[i] = query.isRaw === true ? value : transform.value.from ? transform.value.from(value, column) : value : row[column.name] = transform.value.from ? transform.value.from(value, column) : value;
|
|
1627
1628
|
}
|
|
1628
1629
|
query.forEachFn ? query.forEachFn(transform.row.from ? transform.row.from(row) : row, result) : result[rows++] = transform.row.from ? transform.row.from(row) : row;
|
|
@@ -1668,7 +1669,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1668
1669
|
Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject);
|
|
1669
1670
|
if (query)
|
|
1670
1671
|
return;
|
|
1671
|
-
|
|
1672
|
+
connection.reserved ? !connection.reserved.release && x[5] === 73 ? ending ? terminate() : (connection.reserved = null, onopen(connection)) : connection.reserved() : ending ? terminate() : onopen(connection);
|
|
1672
1673
|
}
|
|
1673
1674
|
function CommandComplete(x) {
|
|
1674
1675
|
rows = 0;
|
|
@@ -1682,7 +1683,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1682
1683
|
}
|
|
1683
1684
|
}
|
|
1684
1685
|
final && (final(), final = null);
|
|
1685
|
-
if (result.command === "BEGIN" && max !== 1 && !
|
|
1686
|
+
if (result.command === "BEGIN" && max !== 1 && !connection.reserved)
|
|
1686
1687
|
return errored(Errors.generic("UNSAFE_TRANSACTION", "Only use sql.begin, sql.reserved or max: 1"));
|
|
1687
1688
|
if (query.options.simple)
|
|
1688
1689
|
return BindComplete();
|
|
@@ -1699,8 +1700,8 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1699
1700
|
result.columns = query.statement.columns;
|
|
1700
1701
|
}
|
|
1701
1702
|
function ParameterDescription(x) {
|
|
1702
|
-
const
|
|
1703
|
-
for (let i = 0;i <
|
|
1703
|
+
const length = x.readUInt16BE(5);
|
|
1704
|
+
for (let i = 0;i < length; ++i)
|
|
1704
1705
|
!query.statement.types[i] && (query.statement.types[i] = x.readUInt32BE(7 + i * 4));
|
|
1705
1706
|
query.prepare && (statements[query.signature] = query.statement);
|
|
1706
1707
|
query.describeFirst && !query.onlyDescribe && (write(prepared(query)), query.describeFirst = false);
|
|
@@ -1712,25 +1713,25 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1712
1713
|
result.count = null;
|
|
1713
1714
|
query.statement.columns = null;
|
|
1714
1715
|
}
|
|
1715
|
-
const
|
|
1716
|
-
let
|
|
1716
|
+
const length = x.readUInt16BE(5);
|
|
1717
|
+
let index = 7;
|
|
1717
1718
|
let start;
|
|
1718
|
-
query.statement.columns = Array(
|
|
1719
|
-
for (let i = 0;i <
|
|
1720
|
-
start =
|
|
1721
|
-
while (x[
|
|
1719
|
+
query.statement.columns = Array(length);
|
|
1720
|
+
for (let i = 0;i < length; ++i) {
|
|
1721
|
+
start = index;
|
|
1722
|
+
while (x[index++] !== 0)
|
|
1722
1723
|
;
|
|
1723
|
-
const table = x.readUInt32BE(
|
|
1724
|
-
const number = x.readUInt16BE(
|
|
1725
|
-
const type = x.readUInt32BE(
|
|
1724
|
+
const table = x.readUInt32BE(index);
|
|
1725
|
+
const number = x.readUInt16BE(index + 4);
|
|
1726
|
+
const type = x.readUInt32BE(index + 6);
|
|
1726
1727
|
query.statement.columns[i] = {
|
|
1727
|
-
name: transform.column.from ? transform.column.from(x.toString("utf8", start,
|
|
1728
|
-
parser:
|
|
1728
|
+
name: transform.column.from ? transform.column.from(x.toString("utf8", start, index - 1)) : x.toString("utf8", start, index - 1),
|
|
1729
|
+
parser: parsers[type],
|
|
1729
1730
|
table,
|
|
1730
1731
|
number,
|
|
1731
1732
|
type
|
|
1732
1733
|
};
|
|
1733
|
-
|
|
1734
|
+
index += 18;
|
|
1734
1735
|
}
|
|
1735
1736
|
result.statement = query.statement;
|
|
1736
1737
|
if (query.onlyDescribe)
|
|
@@ -1757,7 +1758,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1757
1758
|
write(bytes_default.inc(4).str("n,,n=*,r=" + nonce).i32(bytes_default.i - i - 4, i).end());
|
|
1758
1759
|
}
|
|
1759
1760
|
async function SASLContinue(x) {
|
|
1760
|
-
const res = x.toString("utf8", 9).split(",").reduce((acc,
|
|
1761
|
+
const res = x.toString("utf8", 9).split(",").reduce((acc, x) => (acc[x[0]] = x.slice(2), acc), {});
|
|
1761
1762
|
const saltedPassword = await crypto.pbkdf2Sync(await Pass(), Buffer.from(res.s, "base64"), parseInt(res.i), 32, "sha256");
|
|
1762
1763
|
const clientKey = await hmac(saltedPassword, "Client Key");
|
|
1763
1764
|
const auth = "n=*,r=" + nonce + "," + "r=" + res.r + ",s=" + res.s + ",i=" + res.i + ",c=biws,r=" + res.r;
|
|
@@ -1786,7 +1787,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1786
1787
|
}
|
|
1787
1788
|
async function fetchArrayTypes() {
|
|
1788
1789
|
needsTypes = false;
|
|
1789
|
-
const
|
|
1790
|
+
const types = await new Query([`
|
|
1790
1791
|
select b.oid, b.typarray
|
|
1791
1792
|
from pg_catalog.pg_type a
|
|
1792
1793
|
left join pg_catalog.pg_type b on b.oid = a.typelem
|
|
@@ -1794,7 +1795,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1794
1795
|
group by b.oid, b.typarray
|
|
1795
1796
|
order by b.oid
|
|
1796
1797
|
`], [], execute);
|
|
1797
|
-
|
|
1798
|
+
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray));
|
|
1798
1799
|
}
|
|
1799
1800
|
function addArrayType(oid, typarray) {
|
|
1800
1801
|
if (!!options.parsers[typarray] && !!options.serializers[typarray])
|
|
@@ -1809,15 +1810,15 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1809
1810
|
return x === "read-write" && xs.default_transaction_read_only === "on" || x === "read-only" && xs.default_transaction_read_only === "off" || x === "primary" && xs.in_hot_standby === "on" || x === "standby" && xs.in_hot_standby === "off" || x === "prefer-standby" && xs.in_hot_standby === "off" && options.host[retries];
|
|
1810
1811
|
}
|
|
1811
1812
|
function fetchState() {
|
|
1812
|
-
const
|
|
1813
|
+
const query = new Query([`
|
|
1813
1814
|
show transaction_read_only;
|
|
1814
1815
|
select pg_catalog.pg_is_in_recovery()
|
|
1815
1816
|
`], [], execute, null, { simple: true });
|
|
1816
|
-
|
|
1817
|
+
query.resolve = ([[a], [b]]) => {
|
|
1817
1818
|
backendParameters.default_transaction_read_only = a.transaction_read_only;
|
|
1818
|
-
backendParameters.in_hot_standby =
|
|
1819
|
+
backendParameters.in_hot_standby = b.pg_is_in_recovery ? "on" : "off";
|
|
1819
1820
|
};
|
|
1820
|
-
|
|
1821
|
+
query.execute();
|
|
1821
1822
|
}
|
|
1822
1823
|
function ErrorResponse(x) {
|
|
1823
1824
|
if (query) {
|
|
@@ -1827,18 +1828,18 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1827
1828
|
errored(Errors.postgres(parseError(x)));
|
|
1828
1829
|
}
|
|
1829
1830
|
}
|
|
1830
|
-
function retry(q,
|
|
1831
|
+
function retry(q, error) {
|
|
1831
1832
|
delete statements[q.signature];
|
|
1832
|
-
q.retried =
|
|
1833
|
+
q.retried = error;
|
|
1833
1834
|
execute(q);
|
|
1834
1835
|
}
|
|
1835
1836
|
function NotificationResponse(x) {
|
|
1836
1837
|
if (!onnotify)
|
|
1837
1838
|
return;
|
|
1838
|
-
let
|
|
1839
|
-
while (x[
|
|
1839
|
+
let index = 9;
|
|
1840
|
+
while (x[index++] !== 0)
|
|
1840
1841
|
;
|
|
1841
|
-
onnotify(x.toString("utf8", 9,
|
|
1842
|
+
onnotify(x.toString("utf8", 9, index - 1), x.toString("utf8", index, x.length - 1));
|
|
1842
1843
|
}
|
|
1843
1844
|
async function PortalSuspended() {
|
|
1844
1845
|
try {
|
|
@@ -1857,12 +1858,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1857
1858
|
function CopyInResponse() {
|
|
1858
1859
|
stream = new Stream.Writable({
|
|
1859
1860
|
autoDestroy: true,
|
|
1860
|
-
write(
|
|
1861
|
-
socket.write(bytes_default().d().raw(
|
|
1861
|
+
write(chunk, encoding, callback) {
|
|
1862
|
+
socket.write(bytes_default().d().raw(chunk).end(), callback);
|
|
1862
1863
|
},
|
|
1863
|
-
destroy(
|
|
1864
|
-
callback(
|
|
1865
|
-
socket.write(bytes_default().f().str(
|
|
1864
|
+
destroy(error, callback) {
|
|
1865
|
+
callback(error);
|
|
1866
|
+
socket.write(bytes_default().f().str(error + bytes_default.N).end());
|
|
1866
1867
|
stream = null;
|
|
1867
1868
|
},
|
|
1868
1869
|
final(callback) {
|
|
@@ -1887,12 +1888,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1887
1888
|
read() {
|
|
1888
1889
|
socket.resume();
|
|
1889
1890
|
},
|
|
1890
|
-
write(
|
|
1891
|
-
socket.write(bytes_default().d().raw(
|
|
1891
|
+
write(chunk, encoding, callback) {
|
|
1892
|
+
socket.write(bytes_default().d().raw(chunk).end(), callback);
|
|
1892
1893
|
},
|
|
1893
|
-
destroy(
|
|
1894
|
-
callback(
|
|
1895
|
-
socket.write(bytes_default().f().str(
|
|
1894
|
+
destroy(error, callback) {
|
|
1895
|
+
callback(error);
|
|
1896
|
+
socket.write(bytes_default().f().str(error + bytes_default.N).end());
|
|
1896
1897
|
stream = null;
|
|
1897
1898
|
},
|
|
1898
1899
|
final(callback) {
|
|
@@ -1925,13 +1926,13 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1925
1926
|
function UnknownAuth(x, type) {
|
|
1926
1927
|
console.error("Postgres.js : Unknown Auth:", type);
|
|
1927
1928
|
}
|
|
1928
|
-
function Bind(parameters,
|
|
1929
|
+
function Bind(parameters, types, statement = "", portal = "") {
|
|
1929
1930
|
let prev, type;
|
|
1930
1931
|
bytes_default().B().str(portal + bytes_default.N).str(statement + bytes_default.N).i16(0).i16(parameters.length);
|
|
1931
1932
|
parameters.forEach((x, i) => {
|
|
1932
1933
|
if (x === null)
|
|
1933
1934
|
return bytes_default.i32(4294967295);
|
|
1934
|
-
type =
|
|
1935
|
+
type = types[i];
|
|
1935
1936
|
parameters[i] = x = type in options.serializers ? options.serializers[type](x) : "" + x;
|
|
1936
1937
|
prev = bytes_default.i;
|
|
1937
1938
|
bytes_default.inc(4).str(x).i32(bytes_default.i - prev - 4, prev);
|
|
@@ -1939,17 +1940,17 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1939
1940
|
bytes_default.i16(0);
|
|
1940
1941
|
return bytes_default.end();
|
|
1941
1942
|
}
|
|
1942
|
-
function Parse(str, parameters,
|
|
1943
|
+
function Parse(str, parameters, types, name = "") {
|
|
1943
1944
|
bytes_default().P().str(name + bytes_default.N).str(str + bytes_default.N).i16(parameters.length);
|
|
1944
|
-
parameters.forEach((x, i) => bytes_default.i32(
|
|
1945
|
+
parameters.forEach((x, i) => bytes_default.i32(types[i] || 0));
|
|
1945
1946
|
return bytes_default.end();
|
|
1946
1947
|
}
|
|
1947
1948
|
function Describe(x, name = "") {
|
|
1948
1949
|
return bytes_default().D().str(x).str(name + bytes_default.N).end();
|
|
1949
1950
|
}
|
|
1950
|
-
function Execute(portal = "",
|
|
1951
|
+
function Execute(portal = "", rows = 0) {
|
|
1951
1952
|
return Buffer.concat([
|
|
1952
|
-
bytes_default().E().str(portal + bytes_default.N).i32(
|
|
1953
|
+
bytes_default().E().str(portal + bytes_default.N).i32(rows).end(),
|
|
1953
1954
|
Flush
|
|
1954
1955
|
]);
|
|
1955
1956
|
}
|
|
@@ -1987,39 +1988,39 @@ function hmac(key, x) {
|
|
|
1987
1988
|
function sha256(x) {
|
|
1988
1989
|
return crypto.createHash("sha256").update(x).digest();
|
|
1989
1990
|
}
|
|
1990
|
-
function xor(a,
|
|
1991
|
-
const length = Math.max(a.length,
|
|
1992
|
-
const
|
|
1991
|
+
function xor(a, b) {
|
|
1992
|
+
const length = Math.max(a.length, b.length);
|
|
1993
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
1993
1994
|
for (let i = 0;i < length; i++)
|
|
1994
|
-
|
|
1995
|
-
return
|
|
1995
|
+
buffer[i] = a[i] ^ b[i];
|
|
1996
|
+
return buffer;
|
|
1996
1997
|
}
|
|
1997
1998
|
function timer(fn, seconds) {
|
|
1998
1999
|
seconds = typeof seconds === "function" ? seconds() : seconds;
|
|
1999
2000
|
if (!seconds)
|
|
2000
2001
|
return { cancel: noop, start: noop };
|
|
2001
|
-
let
|
|
2002
|
+
let timer;
|
|
2002
2003
|
return {
|
|
2003
2004
|
cancel() {
|
|
2004
|
-
|
|
2005
|
+
timer && (clearTimeout(timer), timer = null);
|
|
2005
2006
|
},
|
|
2006
2007
|
start() {
|
|
2007
|
-
|
|
2008
|
-
|
|
2008
|
+
timer && clearTimeout(timer);
|
|
2009
|
+
timer = setTimeout(done, seconds * 1000, arguments);
|
|
2009
2010
|
}
|
|
2010
2011
|
};
|
|
2011
2012
|
function done(args) {
|
|
2012
2013
|
fn.apply(null, args);
|
|
2013
|
-
|
|
2014
|
+
timer = null;
|
|
2014
2015
|
}
|
|
2015
2016
|
}
|
|
2016
2017
|
|
|
2017
2018
|
// ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/subscribe.js
|
|
2018
2019
|
var noop2 = () => {};
|
|
2019
|
-
function Subscribe(
|
|
2020
|
+
function Subscribe(postgres, options) {
|
|
2020
2021
|
const subscribers = new Map, slot = "postgresjs_" + Math.random().toString(36).slice(2), state = {};
|
|
2021
|
-
let
|
|
2022
|
-
const
|
|
2022
|
+
let connection, stream, ended = false;
|
|
2023
|
+
const sql = subscribe.sql = postgres({
|
|
2023
2024
|
...options,
|
|
2024
2025
|
transform: { column: {}, value: {}, row: {} },
|
|
2025
2026
|
max: 1,
|
|
@@ -2035,37 +2036,37 @@ function Subscribe(postgres2, options) {
|
|
|
2035
2036
|
return;
|
|
2036
2037
|
stream = null;
|
|
2037
2038
|
state.pid = state.secret = undefined;
|
|
2038
|
-
connected(await init(
|
|
2039
|
+
connected(await init(sql, slot, options.publications));
|
|
2039
2040
|
subscribers.forEach((event) => event.forEach(({ onsubscribe }) => onsubscribe()));
|
|
2040
2041
|
},
|
|
2041
2042
|
no_subscribe: true
|
|
2042
2043
|
});
|
|
2043
|
-
const { end, close } =
|
|
2044
|
-
|
|
2044
|
+
const { end, close } = sql;
|
|
2045
|
+
sql.end = async () => {
|
|
2045
2046
|
ended = true;
|
|
2046
2047
|
stream && await new Promise((r) => (stream.once("close", r), stream.end()));
|
|
2047
2048
|
return end();
|
|
2048
2049
|
};
|
|
2049
|
-
|
|
2050
|
+
sql.close = async () => {
|
|
2050
2051
|
stream && await new Promise((r) => (stream.once("close", r), stream.end()));
|
|
2051
2052
|
return close();
|
|
2052
2053
|
};
|
|
2053
2054
|
return subscribe;
|
|
2054
2055
|
async function subscribe(event, fn, onsubscribe = noop2, onerror = noop2) {
|
|
2055
2056
|
event = parseEvent(event);
|
|
2056
|
-
if (!
|
|
2057
|
-
|
|
2057
|
+
if (!connection)
|
|
2058
|
+
connection = init(sql, slot, options.publications);
|
|
2058
2059
|
const subscriber = { fn, onsubscribe };
|
|
2059
2060
|
const fns = subscribers.has(event) ? subscribers.get(event).add(subscriber) : subscribers.set(event, new Set([subscriber])).get(event);
|
|
2060
2061
|
const unsubscribe = () => {
|
|
2061
2062
|
fns.delete(subscriber);
|
|
2062
2063
|
fns.size === 0 && subscribers.delete(event);
|
|
2063
2064
|
};
|
|
2064
|
-
return
|
|
2065
|
+
return connection.then((x) => {
|
|
2065
2066
|
connected(x);
|
|
2066
2067
|
onsubscribe();
|
|
2067
2068
|
stream && stream.on("error", onerror);
|
|
2068
|
-
return { unsubscribe, state, sql
|
|
2069
|
+
return { unsubscribe, state, sql };
|
|
2069
2070
|
});
|
|
2070
2071
|
}
|
|
2071
2072
|
function connected(x) {
|
|
@@ -2073,74 +2074,74 @@ function Subscribe(postgres2, options) {
|
|
|
2073
2074
|
state.pid = x.state.pid;
|
|
2074
2075
|
state.secret = x.state.secret;
|
|
2075
2076
|
}
|
|
2076
|
-
async function init(
|
|
2077
|
+
async function init(sql, slot, publications) {
|
|
2077
2078
|
if (!publications)
|
|
2078
2079
|
throw new Error("Missing publication names");
|
|
2079
|
-
const xs = await
|
|
2080
|
+
const xs = await sql.unsafe(`CREATE_REPLICATION_SLOT ${slot} TEMPORARY LOGICAL pgoutput NOEXPORT_SNAPSHOT`);
|
|
2080
2081
|
const [x] = xs;
|
|
2081
|
-
const
|
|
2082
|
-
const
|
|
2083
|
-
lsn: Buffer.concat(x.consistent_point.split("/").map((
|
|
2082
|
+
const stream = await sql.unsafe(`START_REPLICATION SLOT ${slot} LOGICAL ${x.consistent_point} (proto_version '1', publication_names '${publications}')`).writable();
|
|
2083
|
+
const state = {
|
|
2084
|
+
lsn: Buffer.concat(x.consistent_point.split("/").map((x) => Buffer.from(("00000000" + x).slice(-8), "hex")))
|
|
2084
2085
|
};
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
return { stream
|
|
2086
|
+
stream.on("data", data);
|
|
2087
|
+
stream.on("error", error);
|
|
2088
|
+
stream.on("close", sql.close);
|
|
2089
|
+
return { stream, state: xs.state };
|
|
2089
2090
|
function error(e) {
|
|
2090
2091
|
console.error("Unexpected error during logical streaming - reconnecting", e);
|
|
2091
2092
|
}
|
|
2092
|
-
function data(
|
|
2093
|
-
if (
|
|
2094
|
-
parse(
|
|
2095
|
-
} else if (
|
|
2096
|
-
|
|
2093
|
+
function data(x) {
|
|
2094
|
+
if (x[0] === 119) {
|
|
2095
|
+
parse(x.subarray(25), state, sql.options.parsers, handle, options.transform);
|
|
2096
|
+
} else if (x[0] === 107 && x[17]) {
|
|
2097
|
+
state.lsn = x.subarray(1, 9);
|
|
2097
2098
|
pong();
|
|
2098
2099
|
}
|
|
2099
2100
|
}
|
|
2100
|
-
function handle(a,
|
|
2101
|
-
const path =
|
|
2102
|
-
call("*", a,
|
|
2103
|
-
call("*:" + path, a,
|
|
2104
|
-
|
|
2105
|
-
call(
|
|
2106
|
-
call(
|
|
2107
|
-
|
|
2101
|
+
function handle(a, b) {
|
|
2102
|
+
const path = b.relation.schema + "." + b.relation.table;
|
|
2103
|
+
call("*", a, b);
|
|
2104
|
+
call("*:" + path, a, b);
|
|
2105
|
+
b.relation.keys.length && call("*:" + path + "=" + b.relation.keys.map((x) => a[x.name]), a, b);
|
|
2106
|
+
call(b.command, a, b);
|
|
2107
|
+
call(b.command + ":" + path, a, b);
|
|
2108
|
+
b.relation.keys.length && call(b.command + ":" + path + "=" + b.relation.keys.map((x) => a[x.name]), a, b);
|
|
2108
2109
|
}
|
|
2109
2110
|
function pong() {
|
|
2110
|
-
const
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2111
|
+
const x = Buffer.alloc(34);
|
|
2112
|
+
x[0] = 114;
|
|
2113
|
+
x.fill(state.lsn, 1);
|
|
2114
|
+
x.writeBigInt64BE(BigInt(Date.now() - Date.UTC(2000, 0, 1)) * BigInt(1000), 25);
|
|
2115
|
+
stream.write(x);
|
|
2115
2116
|
}
|
|
2116
2117
|
}
|
|
2117
|
-
function call(x, a,
|
|
2118
|
-
subscribers.has(x) && subscribers.get(x).forEach(({ fn }) => fn(a,
|
|
2118
|
+
function call(x, a, b) {
|
|
2119
|
+
subscribers.has(x) && subscribers.get(x).forEach(({ fn }) => fn(a, b, x));
|
|
2119
2120
|
}
|
|
2120
2121
|
}
|
|
2121
2122
|
function Time(x) {
|
|
2122
2123
|
return new Date(Date.UTC(2000, 0, 1) + Number(x / BigInt(1000)));
|
|
2123
2124
|
}
|
|
2124
|
-
function parse(x, state,
|
|
2125
|
+
function parse(x, state, parsers, handle, transform) {
|
|
2125
2126
|
const char = (acc, [k, v]) => (acc[k.charCodeAt(0)] = v, acc);
|
|
2126
2127
|
Object.entries({
|
|
2127
|
-
R: (
|
|
2128
|
+
R: (x) => {
|
|
2128
2129
|
let i = 1;
|
|
2129
|
-
const r = state[
|
|
2130
|
-
schema:
|
|
2131
|
-
table:
|
|
2132
|
-
columns: Array(
|
|
2130
|
+
const r = state[x.readUInt32BE(i)] = {
|
|
2131
|
+
schema: x.toString("utf8", i += 4, i = x.indexOf(0, i)) || "pg_catalog",
|
|
2132
|
+
table: x.toString("utf8", i + 1, i = x.indexOf(0, i + 1)),
|
|
2133
|
+
columns: Array(x.readUInt16BE(i += 2)),
|
|
2133
2134
|
keys: []
|
|
2134
2135
|
};
|
|
2135
2136
|
i += 2;
|
|
2136
2137
|
let columnIndex = 0, column;
|
|
2137
|
-
while (i <
|
|
2138
|
+
while (i < x.length) {
|
|
2138
2139
|
column = r.columns[columnIndex++] = {
|
|
2139
|
-
key:
|
|
2140
|
-
name: transform.column.from ? transform.column.from(
|
|
2141
|
-
type:
|
|
2142
|
-
parser:
|
|
2143
|
-
atttypmod:
|
|
2140
|
+
key: x[i++],
|
|
2141
|
+
name: transform.column.from ? transform.column.from(x.toString("utf8", i, i = x.indexOf(0, i))) : x.toString("utf8", i, i = x.indexOf(0, i)),
|
|
2142
|
+
type: x.readUInt32BE(i += 1),
|
|
2143
|
+
parser: parsers[x.readUInt32BE(i)],
|
|
2144
|
+
atttypmod: x.readUInt32BE(i += 4)
|
|
2144
2145
|
};
|
|
2145
2146
|
column.key && r.keys.push(column);
|
|
2146
2147
|
i += 4;
|
|
@@ -2148,38 +2149,38 @@ function parse(x, state, parsers2, handle, transform) {
|
|
|
2148
2149
|
},
|
|
2149
2150
|
Y: () => {},
|
|
2150
2151
|
O: () => {},
|
|
2151
|
-
B: (
|
|
2152
|
-
state.date = Time(
|
|
2153
|
-
state.lsn =
|
|
2152
|
+
B: (x) => {
|
|
2153
|
+
state.date = Time(x.readBigInt64BE(9));
|
|
2154
|
+
state.lsn = x.subarray(1, 9);
|
|
2154
2155
|
},
|
|
2155
|
-
I: (
|
|
2156
|
+
I: (x) => {
|
|
2156
2157
|
let i = 1;
|
|
2157
|
-
const relation = state[
|
|
2158
|
-
const { row } = tuples(
|
|
2158
|
+
const relation = state[x.readUInt32BE(i)];
|
|
2159
|
+
const { row } = tuples(x, relation.columns, i += 7, transform);
|
|
2159
2160
|
handle(row, {
|
|
2160
2161
|
command: "insert",
|
|
2161
2162
|
relation
|
|
2162
2163
|
});
|
|
2163
2164
|
},
|
|
2164
|
-
D: (
|
|
2165
|
+
D: (x) => {
|
|
2165
2166
|
let i = 1;
|
|
2166
|
-
const relation = state[
|
|
2167
|
+
const relation = state[x.readUInt32BE(i)];
|
|
2167
2168
|
i += 4;
|
|
2168
|
-
const key =
|
|
2169
|
-
handle(key ||
|
|
2169
|
+
const key = x[i] === 75;
|
|
2170
|
+
handle(key || x[i] === 79 ? tuples(x, relation.columns, i += 3, transform).row : null, {
|
|
2170
2171
|
command: "delete",
|
|
2171
2172
|
relation,
|
|
2172
2173
|
key
|
|
2173
2174
|
});
|
|
2174
2175
|
},
|
|
2175
|
-
U: (
|
|
2176
|
+
U: (x) => {
|
|
2176
2177
|
let i = 1;
|
|
2177
|
-
const relation = state[
|
|
2178
|
+
const relation = state[x.readUInt32BE(i)];
|
|
2178
2179
|
i += 4;
|
|
2179
|
-
const key =
|
|
2180
|
-
const xs = key ||
|
|
2180
|
+
const key = x[i] === 75;
|
|
2181
|
+
const xs = key || x[i] === 79 ? tuples(x, relation.columns, i += 3, transform) : null;
|
|
2181
2182
|
xs && (i = xs.i);
|
|
2182
|
-
const { row } = tuples(
|
|
2183
|
+
const { row } = tuples(x, relation.columns, i + 3, transform);
|
|
2183
2184
|
handle(row, {
|
|
2184
2185
|
command: "update",
|
|
2185
2186
|
relation,
|
|
@@ -2212,22 +2213,22 @@ function parseEvent(x) {
|
|
|
2212
2213
|
|
|
2213
2214
|
// ../../node_modules/.bun/postgres@3.4.9/node_modules/postgres/src/large.js
|
|
2214
2215
|
import Stream2 from "stream";
|
|
2215
|
-
function largeObject(
|
|
2216
|
+
function largeObject(sql, oid, mode = 131072 | 262144) {
|
|
2216
2217
|
return new Promise(async (resolve, reject) => {
|
|
2217
|
-
await
|
|
2218
|
+
await sql.begin(async (sql) => {
|
|
2218
2219
|
let finish;
|
|
2219
|
-
!oid && ([{ oid }] = await
|
|
2220
|
-
const [{ fd }] = await
|
|
2220
|
+
!oid && ([{ oid }] = await sql`select lo_creat(-1) as oid`);
|
|
2221
|
+
const [{ fd }] = await sql`select lo_open(${oid}, ${mode}) as fd`;
|
|
2221
2222
|
const lo = {
|
|
2222
2223
|
writable,
|
|
2223
2224
|
readable,
|
|
2224
|
-
close: () =>
|
|
2225
|
-
tell: () =>
|
|
2226
|
-
read: (x) =>
|
|
2227
|
-
write: (x) =>
|
|
2228
|
-
truncate: (x) =>
|
|
2229
|
-
seek: (x, whence = 0) =>
|
|
2230
|
-
size: () =>
|
|
2225
|
+
close: () => sql`select lo_close(${fd})`.then(finish),
|
|
2226
|
+
tell: () => sql`select lo_tell64(${fd})`,
|
|
2227
|
+
read: (x) => sql`select loread(${fd}, ${x}) as data`,
|
|
2228
|
+
write: (x) => sql`select lowrite(${fd}, ${x})`,
|
|
2229
|
+
truncate: (x) => sql`select lo_truncate64(${fd}, ${x})`,
|
|
2230
|
+
seek: (x, whence = 0) => sql`select lo_lseek64(${fd}, ${x}, ${whence})`,
|
|
2231
|
+
size: () => sql`
|
|
2231
2232
|
select
|
|
2232
2233
|
lo_lseek64(${fd}, location, 0) as position,
|
|
2233
2234
|
seek.size
|
|
@@ -2250,12 +2251,12 @@ function largeObject(sql2, oid, mode = 131072 | 262144) {
|
|
|
2250
2251
|
start && await lo.seek(start);
|
|
2251
2252
|
return new Stream2.Readable({
|
|
2252
2253
|
highWaterMark,
|
|
2253
|
-
async read(
|
|
2254
|
-
const l =
|
|
2255
|
-
max -=
|
|
2254
|
+
async read(size) {
|
|
2255
|
+
const l = size > max ? size - max : size;
|
|
2256
|
+
max -= size;
|
|
2256
2257
|
const [{ data }] = await lo.read(l);
|
|
2257
2258
|
this.push(data);
|
|
2258
|
-
if (data.length <
|
|
2259
|
+
if (data.length < size)
|
|
2259
2260
|
this.push(null);
|
|
2260
2261
|
}
|
|
2261
2262
|
});
|
|
@@ -2296,17 +2297,17 @@ Object.assign(Postgres, {
|
|
|
2296
2297
|
}
|
|
2297
2298
|
});
|
|
2298
2299
|
var src_default = Postgres;
|
|
2299
|
-
function Postgres(a,
|
|
2300
|
-
const options = parseOptions(a,
|
|
2300
|
+
function Postgres(a, b) {
|
|
2301
|
+
const options = parseOptions(a, b), subscribe = options.no_subscribe || Subscribe(Postgres, { ...options });
|
|
2301
2302
|
let ending = false;
|
|
2302
2303
|
const queries = queue_default(), connecting = queue_default(), reserved = queue_default(), closed = queue_default(), ended = queue_default(), open = queue_default(), busy = queue_default(), full = queue_default(), queues = { connecting, reserved, closed, ended, open, busy, full };
|
|
2303
2304
|
const connections = [...Array(options.max)].map(() => connection_default(options, queues, { onopen, onend, onclose }));
|
|
2304
|
-
const
|
|
2305
|
-
Object.assign(
|
|
2305
|
+
const sql = Sql(handler);
|
|
2306
|
+
Object.assign(sql, {
|
|
2306
2307
|
get parameters() {
|
|
2307
2308
|
return options.parameters;
|
|
2308
2309
|
},
|
|
2309
|
-
largeObject: largeObject.bind(null,
|
|
2310
|
+
largeObject: largeObject.bind(null, sql),
|
|
2310
2311
|
subscribe,
|
|
2311
2312
|
CLOSE,
|
|
2312
2313
|
END: CLOSE,
|
|
@@ -2318,14 +2319,14 @@ function Postgres(a, b2) {
|
|
|
2318
2319
|
close,
|
|
2319
2320
|
end
|
|
2320
2321
|
});
|
|
2321
|
-
return
|
|
2322
|
-
function Sql(
|
|
2323
|
-
|
|
2322
|
+
return sql;
|
|
2323
|
+
function Sql(handler) {
|
|
2324
|
+
handler.debug = options.debug;
|
|
2324
2325
|
Object.entries(options.types).reduce((acc, [name, type]) => {
|
|
2325
2326
|
acc[name] = (x) => new Parameter(x, type.to);
|
|
2326
2327
|
return acc;
|
|
2327
2328
|
}, typed);
|
|
2328
|
-
Object.assign(
|
|
2329
|
+
Object.assign(sql, {
|
|
2329
2330
|
types: typed,
|
|
2330
2331
|
typed,
|
|
2331
2332
|
unsafe,
|
|
@@ -2334,51 +2335,51 @@ function Postgres(a, b2) {
|
|
|
2334
2335
|
json,
|
|
2335
2336
|
file
|
|
2336
2337
|
});
|
|
2337
|
-
return
|
|
2338
|
+
return sql;
|
|
2338
2339
|
function typed(value, type) {
|
|
2339
2340
|
return new Parameter(value, type);
|
|
2340
2341
|
}
|
|
2341
|
-
function
|
|
2342
|
-
const query = strings && Array.isArray(strings.raw) ? new Query(strings, args,
|
|
2342
|
+
function sql(strings, ...args) {
|
|
2343
|
+
const query = strings && Array.isArray(strings.raw) ? new Query(strings, args, handler, cancel) : typeof strings === "string" && !args.length ? new Identifier(options.transform.column.to ? options.transform.column.to(strings) : strings) : new Builder(strings, args);
|
|
2343
2344
|
return query;
|
|
2344
2345
|
}
|
|
2345
|
-
function unsafe(string, args = [],
|
|
2346
|
-
arguments.length === 2 && !Array.isArray(args) && (
|
|
2347
|
-
const query = new Query([string], args,
|
|
2346
|
+
function unsafe(string, args = [], options = {}) {
|
|
2347
|
+
arguments.length === 2 && !Array.isArray(args) && (options = args, args = []);
|
|
2348
|
+
const query = new Query([string], args, handler, cancel, {
|
|
2348
2349
|
prepare: false,
|
|
2349
|
-
...
|
|
2350
|
-
simple: "simple" in
|
|
2350
|
+
...options,
|
|
2351
|
+
simple: "simple" in options ? options.simple : args.length === 0
|
|
2351
2352
|
});
|
|
2352
2353
|
return query;
|
|
2353
2354
|
}
|
|
2354
|
-
function file(path, args = [],
|
|
2355
|
-
arguments.length === 2 && !Array.isArray(args) && (
|
|
2356
|
-
const query = new Query([], args, (
|
|
2355
|
+
function file(path, args = [], options = {}) {
|
|
2356
|
+
arguments.length === 2 && !Array.isArray(args) && (options = args, args = []);
|
|
2357
|
+
const query = new Query([], args, (query) => {
|
|
2357
2358
|
fs.readFile(path, "utf8", (err, string) => {
|
|
2358
2359
|
if (err)
|
|
2359
|
-
return
|
|
2360
|
-
|
|
2361
|
-
|
|
2360
|
+
return query.reject(err);
|
|
2361
|
+
query.strings = [string];
|
|
2362
|
+
handler(query);
|
|
2362
2363
|
});
|
|
2363
2364
|
}, cancel, {
|
|
2364
|
-
...
|
|
2365
|
-
simple: "simple" in
|
|
2365
|
+
...options,
|
|
2366
|
+
simple: "simple" in options ? options.simple : args.length === 0
|
|
2366
2367
|
});
|
|
2367
2368
|
return query;
|
|
2368
2369
|
}
|
|
2369
2370
|
}
|
|
2370
2371
|
async function listen(name, fn, onlisten) {
|
|
2371
2372
|
const listener = { fn, onlisten };
|
|
2372
|
-
const
|
|
2373
|
+
const sql = listen.sql || (listen.sql = Postgres({
|
|
2373
2374
|
...options,
|
|
2374
2375
|
max: 1,
|
|
2375
2376
|
idle_timeout: null,
|
|
2376
2377
|
max_lifetime: null,
|
|
2377
2378
|
fetch_types: false,
|
|
2378
2379
|
onclose() {
|
|
2379
|
-
Object.entries(listen.channels).forEach(([
|
|
2380
|
-
delete listen.channels[
|
|
2381
|
-
Promise.all(listeners.map((l) => listen(
|
|
2380
|
+
Object.entries(listen.channels).forEach(([name, { listeners }]) => {
|
|
2381
|
+
delete listen.channels[name];
|
|
2382
|
+
Promise.all(listeners.map((l) => listen(name, l.fn, l.onlisten).catch(() => {})));
|
|
2382
2383
|
});
|
|
2383
2384
|
},
|
|
2384
2385
|
onnotify(c, x) {
|
|
@@ -2388,11 +2389,11 @@ function Postgres(a, b2) {
|
|
|
2388
2389
|
const channels = listen.channels || (listen.channels = {}), exists = name in channels;
|
|
2389
2390
|
if (exists) {
|
|
2390
2391
|
channels[name].listeners.push(listener);
|
|
2391
|
-
const
|
|
2392
|
+
const result = await channels[name].result;
|
|
2392
2393
|
listener.onlisten && listener.onlisten();
|
|
2393
|
-
return { state:
|
|
2394
|
+
return { state: result.state, unlisten };
|
|
2394
2395
|
}
|
|
2395
|
-
channels[name] = { result:
|
|
2396
|
+
channels[name] = { result: sql`listen ${sql.unsafe('"' + name.replace(/"/g, '""') + '"')}`, listeners: [listener] };
|
|
2396
2397
|
const result = await channels[name].result;
|
|
2397
2398
|
listener.onlisten && listener.onlisten();
|
|
2398
2399
|
return { state: result.state, unlisten };
|
|
@@ -2403,11 +2404,11 @@ function Postgres(a, b2) {
|
|
|
2403
2404
|
if (channels[name].listeners.length)
|
|
2404
2405
|
return;
|
|
2405
2406
|
delete channels[name];
|
|
2406
|
-
return
|
|
2407
|
+
return sql`unlisten ${sql.unsafe('"' + name.replace(/"/g, '""') + '"')}`;
|
|
2407
2408
|
}
|
|
2408
2409
|
}
|
|
2409
2410
|
async function notify(channel, payload) {
|
|
2410
|
-
return await
|
|
2411
|
+
return await sql`select pg_notify(${channel}, ${"" + payload})`;
|
|
2411
2412
|
}
|
|
2412
2413
|
async function reserve() {
|
|
2413
2414
|
const queue = queue_default();
|
|
@@ -2419,65 +2420,65 @@ function Postgres(a, b2) {
|
|
|
2419
2420
|
move(c, reserved);
|
|
2420
2421
|
c.reserved = () => queue.length ? c.execute(queue.shift()) : move(c, reserved);
|
|
2421
2422
|
c.reserved.release = true;
|
|
2422
|
-
const
|
|
2423
|
-
|
|
2423
|
+
const sql = Sql(handler);
|
|
2424
|
+
sql.release = () => {
|
|
2424
2425
|
c.reserved = null;
|
|
2425
2426
|
onopen(c);
|
|
2426
2427
|
};
|
|
2427
|
-
return
|
|
2428
|
-
function
|
|
2428
|
+
return sql;
|
|
2429
|
+
function handler(q) {
|
|
2429
2430
|
c.queue === full ? queue.push(q) : c.execute(q) || move(c, full);
|
|
2430
2431
|
}
|
|
2431
2432
|
}
|
|
2432
|
-
async function begin(
|
|
2433
|
-
!fn && (fn =
|
|
2434
|
-
const
|
|
2435
|
-
let savepoints = 0,
|
|
2433
|
+
async function begin(options, fn) {
|
|
2434
|
+
!fn && (fn = options, options = "");
|
|
2435
|
+
const queries = queue_default();
|
|
2436
|
+
let savepoints = 0, connection, prepare = null;
|
|
2436
2437
|
try {
|
|
2437
|
-
await
|
|
2438
|
+
await sql.unsafe("begin " + options.replace(/[^a-z ]/ig, ""), [], { onexecute }).execute();
|
|
2438
2439
|
return await Promise.race([
|
|
2439
|
-
scope(
|
|
2440
|
-
new Promise((_, reject) =>
|
|
2440
|
+
scope(connection, fn),
|
|
2441
|
+
new Promise((_, reject) => connection.onclose = reject)
|
|
2441
2442
|
]);
|
|
2442
2443
|
} catch (error) {
|
|
2443
2444
|
throw error;
|
|
2444
2445
|
}
|
|
2445
|
-
async function scope(c,
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
|
|
2446
|
+
async function scope(c, fn, name) {
|
|
2447
|
+
const sql = Sql(handler);
|
|
2448
|
+
sql.savepoint = savepoint;
|
|
2449
|
+
sql.prepare = (x) => prepare = x.replace(/[^a-z0-9$-_. ]/gi);
|
|
2449
2450
|
let uncaughtError, result;
|
|
2450
|
-
name && await
|
|
2451
|
+
name && await sql`savepoint ${sql(name)}`;
|
|
2451
2452
|
try {
|
|
2452
2453
|
result = await new Promise((resolve, reject) => {
|
|
2453
|
-
const x =
|
|
2454
|
+
const x = fn(sql);
|
|
2454
2455
|
Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject);
|
|
2455
2456
|
});
|
|
2456
2457
|
if (uncaughtError)
|
|
2457
2458
|
throw uncaughtError;
|
|
2458
2459
|
} catch (e) {
|
|
2459
|
-
await (name ?
|
|
2460
|
+
await (name ? sql`rollback to ${sql(name)}` : sql`rollback`);
|
|
2460
2461
|
throw e instanceof PostgresError && e.code === "25P02" && uncaughtError || e;
|
|
2461
2462
|
}
|
|
2462
2463
|
if (!name) {
|
|
2463
|
-
prepare ? await
|
|
2464
|
+
prepare ? await sql`prepare transaction '${sql.unsafe(prepare)}'` : await sql`commit`;
|
|
2464
2465
|
}
|
|
2465
2466
|
return result;
|
|
2466
|
-
function savepoint(
|
|
2467
|
-
if (
|
|
2468
|
-
return savepoint((
|
|
2469
|
-
arguments.length === 1 && (
|
|
2470
|
-
return scope(c,
|
|
2467
|
+
function savepoint(name, fn) {
|
|
2468
|
+
if (name && Array.isArray(name.raw))
|
|
2469
|
+
return savepoint((sql) => sql.apply(sql, arguments));
|
|
2470
|
+
arguments.length === 1 && (fn = name, name = null);
|
|
2471
|
+
return scope(c, fn, "s" + savepoints++ + (name ? "_" + name : ""));
|
|
2471
2472
|
}
|
|
2472
|
-
function
|
|
2473
|
+
function handler(q) {
|
|
2473
2474
|
q.catch((e) => uncaughtError || (uncaughtError = e));
|
|
2474
|
-
c.queue === full ?
|
|
2475
|
+
c.queue === full ? queries.push(q) : c.execute(q) || move(c, full);
|
|
2475
2476
|
}
|
|
2476
2477
|
}
|
|
2477
2478
|
function onexecute(c) {
|
|
2478
|
-
|
|
2479
|
+
connection = c;
|
|
2479
2480
|
move(c, reserved);
|
|
2480
|
-
c.reserved = () =>
|
|
2481
|
+
c.reserved = () => queries.length ? c.execute(queries.shift()) : move(c, reserved);
|
|
2481
2482
|
}
|
|
2482
2483
|
}
|
|
2483
2484
|
function move(c, queue) {
|
|
@@ -2516,11 +2517,11 @@ function Postgres(a, b2) {
|
|
|
2516
2517
|
if (ending)
|
|
2517
2518
|
return ending;
|
|
2518
2519
|
await 1;
|
|
2519
|
-
let
|
|
2520
|
+
let timer;
|
|
2520
2521
|
return ending = Promise.race([
|
|
2521
|
-
new Promise((r) => timeout !== null && (
|
|
2522
|
+
new Promise((r) => timeout !== null && (timer = setTimeout(destroy, timeout * 1000, r))),
|
|
2522
2523
|
Promise.all(connections.map((c) => c.end()).concat(listen.sql ? listen.sql.end({ timeout: 0 }) : [], subscribe.sql ? subscribe.sql.end({ timeout: 0 }) : []))
|
|
2523
|
-
]).then(() => clearTimeout(
|
|
2524
|
+
]).then(() => clearTimeout(timer));
|
|
2524
2525
|
}
|
|
2525
2526
|
async function close() {
|
|
2526
2527
|
await Promise.all(connections.map((c) => c.end()));
|
|
@@ -2559,10 +2560,10 @@ function Postgres(a, b2) {
|
|
|
2559
2560
|
queries.length && connect(c, queries.shift());
|
|
2560
2561
|
}
|
|
2561
2562
|
}
|
|
2562
|
-
function parseOptions(a,
|
|
2563
|
+
function parseOptions(a, b) {
|
|
2563
2564
|
if (a && a.shared)
|
|
2564
2565
|
return a;
|
|
2565
|
-
const env = process.env, o = (!a || typeof a === "string" ?
|
|
2566
|
+
const env = process.env, o = (!a || typeof a === "string" ? b : a) || {}, { url, multihost } = parseUrl(a), query = [...url.searchParams].reduce((a, [b, c]) => (a[b] = c, a), {}), host = o.hostname || o.host || multihost || url.hostname || env.PGHOST || "localhost", port = o.port || url.port || env.PGPORT || 5432, user = o.user || o.username || url.username || env.PGUSERNAME || env.PGUSER || osUsername();
|
|
2566
2567
|
o.no_prepare && (o.prepare = false);
|
|
2567
2568
|
query.sslmode && (query.ssl = query.sslmode, delete query.sslmode);
|
|
2568
2569
|
"timeout" in o && (console.log("The timeout option is deprecated, use idle_timeout instead"), o.idle_timeout = o.timeout);
|
|
@@ -2718,7 +2719,7 @@ function parseSnapshot(value, actorUserId) {
|
|
|
2718
2719
|
if (typeof parsed !== "object" || parsed === null || !("version" in parsed) || parsed.version !== 1 || !("actorUserId" in parsed) || parsed.actorUserId !== actorUserId || !("documents" in parsed) || !Array.isArray(parsed.documents)) {
|
|
2719
2720
|
throw new Error("account_runtime_cleanup_snapshot_invalid");
|
|
2720
2721
|
}
|
|
2721
|
-
const
|
|
2722
|
+
const documents = parsed.documents.map((document) => {
|
|
2722
2723
|
if (typeof document !== "object" || document === null || !("documentId" in document) || typeof document.documentId !== "string" || document.documentId.length === 0 || !("workspaceId" in document) || document.workspaceId !== null && typeof document.workspaceId !== "string") {
|
|
2723
2724
|
throw new Error("account_runtime_cleanup_snapshot_invalid");
|
|
2724
2725
|
}
|
|
@@ -2727,7 +2728,7 @@ function parseSnapshot(value, actorUserId) {
|
|
|
2727
2728
|
workspaceId: document.workspaceId
|
|
2728
2729
|
};
|
|
2729
2730
|
});
|
|
2730
|
-
return { version: 1, actorUserId, documents
|
|
2731
|
+
return { version: 1, actorUserId, documents };
|
|
2731
2732
|
}
|
|
2732
2733
|
function createAccountRuntimeCleanupWithDependencies(dependencies) {
|
|
2733
2734
|
const snapshots = new Map;
|
|
@@ -2738,9 +2739,9 @@ function createAccountRuntimeCleanupWithDependencies(dependencies) {
|
|
|
2738
2739
|
if (closed)
|
|
2739
2740
|
throw new Error("account_runtime_cleanup_closed");
|
|
2740
2741
|
}
|
|
2741
|
-
function cacheSnapshot(actorUserId,
|
|
2742
|
+
function cacheSnapshot(actorUserId, documents) {
|
|
2742
2743
|
snapshots.delete(actorUserId);
|
|
2743
|
-
snapshots.set(actorUserId,
|
|
2744
|
+
snapshots.set(actorUserId, documents);
|
|
2744
2745
|
while (snapshots.size > MAX_IN_MEMORY_SNAPSHOTS) {
|
|
2745
2746
|
const oldest = snapshots.keys().next().value;
|
|
2746
2747
|
if (typeof oldest !== "string")
|
|
@@ -2772,12 +2773,12 @@ function createAccountRuntimeCleanupWithDependencies(dependencies) {
|
|
|
2772
2773
|
try {
|
|
2773
2774
|
let snapshot = await loadDurableSnapshot(actorUserId, signal);
|
|
2774
2775
|
if (!snapshot) {
|
|
2775
|
-
const
|
|
2776
|
+
const documents = await dependencies.snapshotActorDocuments(actorUserId, signal);
|
|
2776
2777
|
throwIfAborted(signal);
|
|
2777
2778
|
const candidate = {
|
|
2778
2779
|
version: 1,
|
|
2779
2780
|
actorUserId,
|
|
2780
|
-
documents:
|
|
2781
|
+
documents: documents.map((document) => ({
|
|
2781
2782
|
documentId: document.documentId,
|
|
2782
2783
|
workspaceId: document.workspaceId
|
|
2783
2784
|
}))
|