orqevio 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/assets/AccessKeyReveal-B8-53IsG.js +2 -0
- package/dist/web/assets/{AccessRows-GJ7NGNg8.js → AccessRows-BvqV7IBl.js} +1 -1
- package/dist/web/assets/ActivityList-CMeaCWkv.js +1 -0
- package/dist/web/assets/AgentsPage-BFV4Irgu.js +1 -0
- package/dist/web/assets/Attachments-Ehl3SEHq.js +221 -0
- package/dist/web/assets/{Avatar-BOAvUuAe.js → Avatar-XLUId3O5.js} +1 -1
- package/dist/web/assets/BoardPage-yeO36gca.js +1 -0
- package/dist/web/assets/{Button-BEyJ-GlB.js → Button-DFtiJeUa.js} +1 -1
- package/dist/web/assets/{CardItem-lb5OjqhD.js → CardItem-BJSe5Yys.js} +2 -2
- package/dist/web/assets/Checkbox-D2glB_5Z.js +1 -0
- package/dist/web/assets/ColorPicker-DXWll90z.js +1 -0
- package/dist/web/assets/{ConsentPage-BOW8RRYV.js → ConsentPage-LsyaMLAu.js} +1 -1
- package/dist/web/assets/CopyButton-DPGirLsh.js +1 -0
- package/dist/web/assets/DocPage-LDbLYm22.js +1 -0
- package/dist/web/assets/{EmptyState-hluhiKgi.js → EmptyState-NLNYFMbg.js} +1 -1
- package/dist/web/assets/{Field-q3KZ7chQ.js → Field-CJ08Txzu.js} +1 -1
- package/dist/web/assets/HomePage-C5tasScn.js +1 -0
- package/dist/web/assets/Menu-D1dtpXQc.js +41 -0
- package/dist/web/assets/PageHeader-6CKm6Nmk.js +1 -0
- package/dist/web/assets/Popover-rUw84XS3.js +1 -0
- package/dist/web/assets/ProjectPage-sRIqleNm.js +1 -0
- package/dist/web/assets/ProjectSettingsDialog-Bu9Nh_f1.js +1 -0
- package/dist/web/assets/Segmented-CkRO6dAI.js +1 -0
- package/dist/web/assets/SettingsPage--HzCtlxW.js +1 -0
- package/dist/web/assets/States-YdzeahGB.js +1 -0
- package/dist/web/assets/TokenCard-Cxa4noi9.js +1 -0
- package/dist/web/assets/{Trans-Dad4wAn9.js → Trans-BeLoTtlV.js} +1 -1
- package/dist/web/assets/TrashPage-eI708eSb.js +1 -0
- package/dist/web/assets/VaultPage-DZ8whuhV.js +9 -0
- package/dist/web/assets/actions-BHpEdIG-.js +1 -0
- package/dist/web/assets/{activity-CdqdeoxV.js → activity-B9yvTGRK.js} +1 -1
- package/dist/web/assets/{activity-_4kW2ZJ_.js → activity-BhJh5gr8.js} +1 -1
- package/dist/web/assets/{activity-ZNUvkr3p.js → activity-C6uHBG-k.js} +1 -1
- package/dist/web/assets/activity-C_Gj6kNm.js +1 -0
- package/dist/web/assets/{activity-6zHhcitv.js → activity-DE5W3_Zl.js} +1 -1
- package/dist/web/assets/{activity-mAare-yB.js → activity-Da3DZwfO.js} +1 -1
- package/dist/web/assets/{activity-DGUXp5QL.js → activity-DklyxS1p.js} +1 -1
- package/dist/web/assets/{activity-CWpwjlzR.js → activity-DqxJDBNZ.js} +1 -1
- package/dist/web/assets/agents-BT7hhkmJ.js +1 -0
- package/dist/web/assets/agents-CH9hiW4n.js +1 -0
- package/dist/web/assets/agents-D2HbGZdI.js +1 -0
- package/dist/web/assets/agents-dOyd7e_g.js +1 -0
- package/dist/web/assets/agents-hwFgCutb.js +1 -0
- package/dist/web/assets/agents-mGUE0KF4.js +1 -0
- package/dist/web/assets/agents-rpBGYkV5.js +1 -0
- package/dist/web/assets/{arrow-up-right-jy54oepv.js → arrow-up-right-CZaZGd2b.js} +1 -1
- package/dist/web/assets/boards-B55T0dLc.js +1 -0
- package/dist/web/assets/boards-BJtzDCZ4.js +1 -0
- package/dist/web/assets/boards-BK-HIes0.js +1 -0
- package/dist/web/assets/boards-BRGCpMCs.js +1 -0
- package/dist/web/assets/boards-D9ITCVkH.js +1 -0
- package/dist/web/assets/{boards-Bd-B4hhr.js → boards-DAtCVLZ8.js} +1 -1
- package/dist/web/assets/boards-DkGEJNsi.js +1 -0
- package/dist/web/assets/check-zaEYRgm_.js +1 -0
- package/dist/web/assets/chevron-right-CKppr8-s.js +1 -0
- package/dist/web/assets/{clock-C5M8Fsgx.js → clock-Or1e2dj9.js} +1 -1
- package/dist/web/assets/common-BEzNU6dg.js +1 -0
- package/dist/web/assets/common-BQxUpELz.js +1 -0
- package/dist/web/assets/common-BVdHyWon.js +1 -0
- package/dist/web/assets/common-DB87cQ0w.js +1 -0
- package/dist/web/assets/common-DIIWFfP1.js +1 -0
- package/dist/web/assets/common-DL87-WQe.js +1 -0
- package/dist/web/assets/common-pmlLlsX2.js +1 -0
- package/dist/web/assets/dist-BXudX2C8.js +1 -0
- package/dist/web/assets/{docs-_S4ttW8g.js → docs-CdU1zlr_.js} +1 -1
- package/dist/web/assets/{docs-Bx1kznfx.js → docs-CozS3xm2.js} +1 -1
- package/dist/web/assets/{docs-BPnASlp4.js → docs-DL4bSiKv.js} +1 -1
- package/dist/web/assets/{docs-BwYy_eWc.js → docs-DdRzy2fY.js} +1 -1
- package/dist/web/assets/{docs-B6tXalZZ.js → docs-DjihmilZ.js} +1 -1
- package/dist/web/assets/{docs-DEnWVVdL.js → docs-DkxJ3bH2.js} +1 -1
- package/dist/web/assets/{docs-BlYmrIPJ.js → docs-Duf_UKKw.js} +1 -1
- package/dist/web/assets/{download-BBMY4_F_.js → download-DeNtxt4D.js} +1 -1
- package/dist/web/assets/{errors-Ci_yKm08.js → errors-CWljhQp1.js} +1 -1
- package/dist/web/assets/{errors-CLj0b-7k.js → errors-Cgnb5wfv.js} +1 -1
- package/dist/web/assets/{errors-nYX9_uNL.js → errors-D2gpUA7_.js} +1 -1
- package/dist/web/assets/{errors-BBSpXkde.js → errors-D3pMnz0U.js} +1 -1
- package/dist/web/assets/{errors-H0RFbE9j.js → errors-DAwX8-Fy.js} +1 -1
- package/dist/web/assets/{errors-COWA3coq.js → errors-DlcuhMif.js} +1 -1
- package/dist/web/assets/{errors-DV9hY964.js → errors-gJfsmgEB.js} +1 -1
- package/dist/web/assets/{eye-B6U-U9I2.js → eye-DqmmpIUP.js} +1 -1
- package/dist/web/assets/{file-plus-sBsw-mHU.js → file-plus-B9RcccJq.js} +1 -1
- package/dist/web/assets/{folder-open-C8XbXqby.js → folder-open-B5eZ7cqb.js} +1 -1
- package/dist/web/assets/{format-Bk7x-Tvj.js → format-DEwJtk6a.js} +3 -3
- package/dist/web/assets/history-BTSLGRUd.js +1 -0
- package/dist/web/assets/history-BYQKniZP.js +1 -0
- package/dist/web/assets/history-CCBPyinv.js +1 -0
- package/dist/web/assets/history-DJRWWqQM.js +1 -0
- package/dist/web/assets/history-DKzmm79r.js +1 -0
- package/dist/web/assets/history-DTKtuTix.js +1 -0
- package/dist/web/assets/history-DiKunONf.js +1 -0
- package/dist/web/assets/index-DXZdSAQ6.js +9 -0
- package/dist/web/assets/index-JKAKpcGm.css +2 -0
- package/dist/web/assets/{lock-keyhole-C4Z7hIsy.js → lock-keyhole-BSIBvxdl.js} +1 -1
- package/dist/web/assets/{paperclip-BYdtXq93.js → paperclip-45hm0LEK.js} +1 -1
- package/dist/web/assets/{pencil-CIP9wOAh.js → pencil-BgKjfUw7.js} +1 -1
- package/dist/web/assets/plus-DkN0_LKK.js +1 -0
- package/dist/web/assets/{projects-BsY2PmjV.js → projects-B2JAODbF.js} +1 -1
- package/dist/web/assets/{projects--t9VhdYF.js → projects-BUM_86ov.js} +1 -1
- package/dist/web/assets/{projects-D3eU-Jew.js → projects-Bc_qRQF1.js} +1 -1
- package/dist/web/assets/{projects-aUO3NoCx.js → projects-C_ZQ0ABW.js} +1 -1
- package/dist/web/assets/{projects-BVQGJc7P.js → projects-DTgjzEHE.js} +1 -1
- package/dist/web/assets/{projects-CNfl9kuI.js → projects-NfKe5Y_d.js} +1 -1
- package/dist/web/assets/{projects-CrDJIGi7.js → projects-pq_l0OIa.js} +1 -1
- package/dist/web/assets/{realtime-CKklHnjh.js → realtime-D4IlZ7la.js} +1 -1
- package/dist/web/assets/restore-2dQEOQsU.js +1 -0
- package/dist/web/assets/router-Dq52n_dF.js +1 -0
- package/dist/web/assets/router-i53kBtjJ.js +6 -0
- package/dist/web/assets/{search-qd7k-kLC.js → search-THqOJIwW.js} +1 -1
- package/dist/web/assets/{session-Dcwvbu5M.js → session-BuK7KqOl.js} +1 -1
- package/dist/web/assets/settings-B2K0CC6S.js +1 -0
- package/dist/web/assets/settings-C6mEKUST.js +1 -0
- package/dist/web/assets/settings-CHHy3vrT.js +1 -0
- package/dist/web/assets/settings-CcG0OlNC.js +1 -0
- package/dist/web/assets/settings-Clq39MFV.js +1 -0
- package/dist/web/assets/{settings-CNp5nmcK.js → settings-D5LDNHZs.js} +1 -1
- package/dist/web/assets/settings-DOUFAQf_.js +1 -0
- package/dist/web/assets/shell-BWsPUku5.js +1 -0
- package/dist/web/assets/shell-ChgP5xyE.js +1 -0
- package/dist/web/assets/shell-DNBUBxNa.js +1 -0
- package/dist/web/assets/{shell-CkzevnPH.js → shell-DND6HJAN.js} +1 -1
- package/dist/web/assets/shell-DQ0M6Blt.js +1 -0
- package/dist/web/assets/shell-DvS2WNEV.js +1 -0
- package/dist/web/assets/shell-jyyol4c1.js +1 -0
- package/dist/web/assets/{shield-exclamation-point-C2zfs7xR.js → shield-exclamation-point-XUMrMBnT.js} +1 -1
- package/dist/web/assets/{square-kanban-D8NGcaz9.js → square-kanban-CMvSaNex.js} +1 -1
- package/dist/web/assets/{sticky-note-BDU0a5o7.js → sticky-note-DQns5zF8.js} +1 -1
- package/dist/web/assets/sync-7NhCAmaJ.js +1 -0
- package/dist/web/assets/tag-5EiSR0t7.js +1 -0
- package/dist/web/assets/trash-BS2DxHiH.js +1 -0
- package/dist/web/assets/trash-Blx5xyGN.js +1 -0
- package/dist/web/assets/trash-C8iQ5jx0.js +1 -0
- package/dist/web/assets/{trash-DXD8fhoH.js → trash-CBo3hCgY.js} +1 -1
- package/dist/web/assets/trash-D4IUwUwV.js +1 -0
- package/dist/web/assets/trash-D6VCYSPP.js +1 -0
- package/dist/web/assets/trash-DHTLFm0L.js +1 -0
- package/dist/web/assets/trash-DlhKL2Eo.js +2 -0
- package/dist/web/assets/trash-Duy-tBWH.js +1 -0
- package/dist/web/assets/{triangle-exclamation-point-DF10_hIt.js → triangle-exclamation-point-fRu34PHx.js} +1 -1
- package/dist/web/assets/vault-CNRRr8jE.js +7 -0
- package/dist/web/assets/vault-D0qB-XRT.js +7 -0
- package/dist/web/assets/vault-DJFOCIz1.js +7 -0
- package/dist/web/assets/vault-DbyTbZAp.js +7 -0
- package/dist/web/assets/vault-DfGgsIOH.js +7 -0
- package/dist/web/assets/vault-Dw09SaES.js +7 -0
- package/dist/web/assets/vault-DyvlvJIG.js +7 -0
- package/dist/web/index.html +34 -34
- package/dist/worker/index.js +2074 -654
- package/package.json +1 -1
- package/dist/web/assets/AccessKeyReveal-pXOyawHZ.js +0 -2
- package/dist/web/assets/ActivityList-CW5ca7uM.js +0 -1
- package/dist/web/assets/AgentsPage-cSDKX5Eu.js +0 -1
- package/dist/web/assets/Attachments-8VpIt4nK.js +0 -221
- package/dist/web/assets/BoardPage-DduYPKOl.js +0 -1
- package/dist/web/assets/Checkbox-DMMOD-1_.js +0 -1
- package/dist/web/assets/ColorPicker-C1Syzpon.js +0 -1
- package/dist/web/assets/CopyButton-CT-XER6M.js +0 -1
- package/dist/web/assets/DocPage-CKD3LhsV.js +0 -1
- package/dist/web/assets/HomePage-Cpo7TSvS.js +0 -1
- package/dist/web/assets/Menu-DSQtu5tc.js +0 -1
- package/dist/web/assets/PageHeader-QiDVhGPg.js +0 -1
- package/dist/web/assets/Popover-DakV3SHV.js +0 -1
- package/dist/web/assets/ProjectPage-BtP0zjMz.js +0 -1
- package/dist/web/assets/ProjectSettingsDialog-D8rX_65I.js +0 -1
- package/dist/web/assets/Segmented-BY3-D_fh.js +0 -1
- package/dist/web/assets/SettingsPage-YDB-n3AM.js +0 -1
- package/dist/web/assets/States-C2yXthAS.js +0 -1
- package/dist/web/assets/TokenCard-Duq8y0nr.js +0 -1
- package/dist/web/assets/TrashPage-DYntIFir.js +0 -1
- package/dist/web/assets/VaultPage-CiH1OYiv.js +0 -9
- package/dist/web/assets/actions-BO2lajTK.js +0 -1
- package/dist/web/assets/activity-DncNY2jQ.js +0 -1
- package/dist/web/assets/agents-BGMKVi6i.js +0 -1
- package/dist/web/assets/agents-BXU0uzTH.js +0 -1
- package/dist/web/assets/agents-Cibz_z-h.js +0 -1
- package/dist/web/assets/agents-DOYJyzdo.js +0 -1
- package/dist/web/assets/agents-DrakTRAt.js +0 -1
- package/dist/web/assets/agents-de0xSyjY.js +0 -1
- package/dist/web/assets/agents-kJYxGRsw.js +0 -1
- package/dist/web/assets/boards-BExvvK2C.js +0 -1
- package/dist/web/assets/boards-CttGasCM.js +0 -1
- package/dist/web/assets/boards-DF_wEJNs.js +0 -1
- package/dist/web/assets/boards-DM5MZ8MK.js +0 -1
- package/dist/web/assets/boards-DRXX82kC.js +0 -1
- package/dist/web/assets/boards-DTnFEV0A.js +0 -1
- package/dist/web/assets/check-DuMyfuQh.js +0 -1
- package/dist/web/assets/chevron-right-IV_EWEd2.js +0 -1
- package/dist/web/assets/common-COjNB9BR.js +0 -1
- package/dist/web/assets/common-CxTPkV7X.js +0 -1
- package/dist/web/assets/common-D-VyKjDv.js +0 -1
- package/dist/web/assets/common-D3b_OJUw.js +0 -1
- package/dist/web/assets/common-DJe5JA5c.js +0 -1
- package/dist/web/assets/common-Dr48NU46.js +0 -1
- package/dist/web/assets/common-Vls4DuMQ.js +0 -1
- package/dist/web/assets/confirm-B_a86qfl.js +0 -41
- package/dist/web/assets/history-BR28CO2x.js +0 -1
- package/dist/web/assets/history-BuXL4ZO8.js +0 -1
- package/dist/web/assets/history-CBSq8sT_.js +0 -1
- package/dist/web/assets/history-CUFddWVE.js +0 -1
- package/dist/web/assets/history-Cpw0AAmb.js +0 -1
- package/dist/web/assets/history-DXLLakuK.js +0 -1
- package/dist/web/assets/history-DpSejrKr.js +0 -1
- package/dist/web/assets/index-C5_JoNeq.css +0 -2
- package/dist/web/assets/index-CwpgaQ7Y.js +0 -14
- package/dist/web/assets/plus-DaFIeRQ5.js +0 -1
- package/dist/web/assets/rotate-ccw-DN73NT0I.js +0 -1
- package/dist/web/assets/settings-BEQRzNKB.js +0 -1
- package/dist/web/assets/settings-BF7RMx4g.js +0 -1
- package/dist/web/assets/settings-BTl-RmtN.js +0 -1
- package/dist/web/assets/settings-CDsJtPq7.js +0 -1
- package/dist/web/assets/settings-Chkz6CC0.js +0 -1
- package/dist/web/assets/settings-DeEGVtMK.js +0 -1
- package/dist/web/assets/shell--RN8OuYs.js +0 -1
- package/dist/web/assets/shell-Bhcgh15N.js +0 -1
- package/dist/web/assets/shell-BlFKTzFJ.js +0 -1
- package/dist/web/assets/shell-CVGGeBa9.js +0 -1
- package/dist/web/assets/shell-DOWo5KgD.js +0 -1
- package/dist/web/assets/shell-dLPGAa5r.js +0 -1
- package/dist/web/assets/sync-DaIWZIoO.js +0 -1
- package/dist/web/assets/tag-CgkfTxMT.js +0 -1
- package/dist/web/assets/trash-BJO-DupK.js +0 -1
- package/dist/web/assets/trash-BQQD171k.js +0 -1
- package/dist/web/assets/trash-Bxu4b7lw.js +0 -1
- package/dist/web/assets/trash-CZ2Sbb1v.js +0 -1
- package/dist/web/assets/trash-DFqgqLEp.js +0 -1
- package/dist/web/assets/trash-lAGOyPXd.js +0 -1
- package/dist/web/assets/trash-mj787YHq.js +0 -1
- package/dist/web/assets/trash-pWFmQnYh.js +0 -1
- package/dist/web/assets/vault-B-faqbCu.js +0 -7
- package/dist/web/assets/vault-BDbmJ4gY.js +0 -7
- package/dist/web/assets/vault-BtBepzOV.js +0 -7
- package/dist/web/assets/vault-C3Z6tIv1.js +0 -7
- package/dist/web/assets/vault-CiXNbJPq.js +0 -7
- package/dist/web/assets/vault-D8BaBWEB.js +0 -7
- package/dist/web/assets/vault-DRsraquz.js +0 -7
- package/dist/web/assets/workspace-DzXvw2Jk.js +0 -1
package/dist/worker/index.js
CHANGED
|
@@ -8632,8 +8632,8 @@ function nullish(input2) {
|
|
|
8632
8632
|
__name(nullish, "nullish");
|
|
8633
8633
|
function cleanRegex(source) {
|
|
8634
8634
|
const start = source.startsWith("^") ? 1 : 0;
|
|
8635
|
-
const
|
|
8636
|
-
return source.slice(start,
|
|
8635
|
+
const end2 = source.endsWith("$") ? source.length - 1 : source.length;
|
|
8636
|
+
return source.slice(start, end2);
|
|
8637
8637
|
}
|
|
8638
8638
|
__name(cleanRegex, "cleanRegex");
|
|
8639
8639
|
function floatSafeRemainder(val, step) {
|
|
@@ -11139,17 +11139,17 @@ var $ZodCreditCard = /* @__PURE__ */ $constructor("$ZodCreditCard", (inst, def)
|
|
|
11139
11139
|
};
|
|
11140
11140
|
});
|
|
11141
11141
|
function isIso7064Mod97(iban3) {
|
|
11142
|
-
let
|
|
11142
|
+
let remainder2 = 0;
|
|
11143
11143
|
const len = iban3.length;
|
|
11144
11144
|
for (let i2 = 4; i2 < len; i2++) {
|
|
11145
11145
|
const code = iban3.charCodeAt(i2);
|
|
11146
|
-
|
|
11146
|
+
remainder2 = (code >= 65 ? remainder2 * 100 + (code - 55) : remainder2 * 10 + (code - 48)) % 97;
|
|
11147
11147
|
}
|
|
11148
11148
|
for (let i2 = 0; i2 < 4; i2++) {
|
|
11149
11149
|
const code = iban3.charCodeAt(i2);
|
|
11150
|
-
|
|
11150
|
+
remainder2 = (code >= 65 ? remainder2 * 100 + (code - 55) : remainder2 * 10 + (code - 48)) % 97;
|
|
11151
11151
|
}
|
|
11152
|
-
return
|
|
11152
|
+
return remainder2 === 1;
|
|
11153
11153
|
}
|
|
11154
11154
|
__name(isIso7064Mod97, "isIso7064Mod97");
|
|
11155
11155
|
function isValidIBAN(input2) {
|
|
@@ -21497,8 +21497,8 @@ function generateMultipleOfCheck(doc, ctx, def, accessor) {
|
|
|
21497
21497
|
throw new ZodCompileUnsupportedError("multiple_of check with a zero divisor");
|
|
21498
21498
|
doc.write(`if (${accessor} % ${def.value}n !== 0n) return INVALID;`);
|
|
21499
21499
|
} else {
|
|
21500
|
-
const
|
|
21501
|
-
doc.write(`if (${
|
|
21500
|
+
const remainder2 = addConstant(ctx, floatSafeRemainder);
|
|
21501
|
+
doc.write(`if (${remainder2}(${accessor}, ${numericOperand(def.value, "multiple_of")}) !== 0) return INVALID;`);
|
|
21502
21502
|
}
|
|
21503
21503
|
}
|
|
21504
21504
|
__name(generateMultipleOfCheck, "generateMultipleOfCheck");
|
|
@@ -23871,13 +23871,13 @@ function _promise(Class2, innerType) {
|
|
|
23871
23871
|
__name(_promise, "_promise");
|
|
23872
23872
|
// @__NO_SIDE_EFFECTS__
|
|
23873
23873
|
function _custom(Class2, fn, _params) {
|
|
23874
|
-
const
|
|
23875
|
-
|
|
23874
|
+
const norm2 = normalizeParams(_params);
|
|
23875
|
+
norm2.abort ?? (norm2.abort = true);
|
|
23876
23876
|
const schema = new Class2({
|
|
23877
23877
|
type: "custom",
|
|
23878
23878
|
check: "custom",
|
|
23879
23879
|
fn,
|
|
23880
|
-
...
|
|
23880
|
+
...norm2
|
|
23881
23881
|
});
|
|
23882
23882
|
return schema;
|
|
23883
23883
|
}
|
|
@@ -28290,8 +28290,9 @@ var SCOPES = ["tasks:read", "tasks:write", "docs:read", "docs:write", "organize"
|
|
|
28290
28290
|
|
|
28291
28291
|
// ../../packages/shared/src/schemas.ts
|
|
28292
28292
|
var id = external_exports.uuid();
|
|
28293
|
-
var VISIBLE = /[^\s\p{Cc}\p{Cf}\p{Z}\u115F\u1160\u3164\uFFA0\u2800]/u;
|
|
28293
|
+
var VISIBLE = /[^\s\p{Cc}\p{Cf}\p{Z}\p{M}\u115F\u1160\u3164\uFFA0\u2800]/u;
|
|
28294
28294
|
var name = /* @__PURE__ */ __name((max2 = 120) => external_exports.string().overwrite((value) => value.replace(/\p{Cc}+/gu, " ")).trim().min(1, { message: "Required", abort: true }).max(max2).refine((value) => VISIBLE.test(value), "Required"), "name");
|
|
28295
|
+
var optionalName = /* @__PURE__ */ __name((max2) => external_exports.string().overwrite((value) => value.replace(/\p{Cc}+/gu, " ")).trim().overwrite((value) => VISIBLE.test(value) ? value : "").max(max2), "optionalName");
|
|
28295
28296
|
var color = external_exports.enum(PALETTE);
|
|
28296
28297
|
var index = external_exports.number().int().min(0).max(1e5);
|
|
28297
28298
|
var DUE_YEARS = { min: 1900, max: 2199 };
|
|
@@ -28314,6 +28315,17 @@ var dueAt = external_exports.string().transform((value, ctx) => {
|
|
|
28314
28315
|
return external_exports.NEVER;
|
|
28315
28316
|
});
|
|
28316
28317
|
var MAX_MARKDOWN = 2e5;
|
|
28318
|
+
function characters(text2) {
|
|
28319
|
+
let count2 = text2.length;
|
|
28320
|
+
for (let i2 = 0; i2 < text2.length - 1; i2++) {
|
|
28321
|
+
if ((text2.charCodeAt(i2) & 64512) === 55296 && (text2.charCodeAt(i2 + 1) & 64512) === 56320) {
|
|
28322
|
+
count2--;
|
|
28323
|
+
i2++;
|
|
28324
|
+
}
|
|
28325
|
+
}
|
|
28326
|
+
return count2;
|
|
28327
|
+
}
|
|
28328
|
+
__name(characters, "characters");
|
|
28317
28329
|
var secret = external_exports.string().trim().min(1, "Required").max(256);
|
|
28318
28330
|
var claimInput = external_exports.object({ setupCode: secret, name: name(80), locale: external_exports.enum(LOCALES).optional() });
|
|
28319
28331
|
var unlockInput = external_exports.object({ accessKey: secret });
|
|
@@ -28323,7 +28335,7 @@ var rotateAccessKeyInput = external_exports.object({ currentAccessKey: secret })
|
|
|
28323
28335
|
var confirmAccessKeyInput = external_exports.object({ accessKey: secret });
|
|
28324
28336
|
var uninstallInput = external_exports.object({ accessKey: secret, deleteBackups: external_exports.boolean() });
|
|
28325
28337
|
var installerUninstallInput = external_exports.object({ token: external_exports.string().min(40).max(200), deleteBackups: external_exports.boolean().default(false) });
|
|
28326
|
-
var restoreBackupInput = external_exports.object({ accessKey: secret });
|
|
28338
|
+
var restoreBackupInput = external_exports.object({ accessKey: secret, leaveOut: external_exports.array(external_exports.string().max(200)).max(1e5).default([]) });
|
|
28327
28339
|
var updateAccountInput = external_exports.object({
|
|
28328
28340
|
name: name(80).optional(),
|
|
28329
28341
|
theme: external_exports.enum(["system", "light", "dark"]).optional(),
|
|
@@ -28348,8 +28360,8 @@ var boardCreateInput = external_exports.object({
|
|
|
28348
28360
|
var boardUpdateInput = external_exports.object({ name: name(80) });
|
|
28349
28361
|
var columnCreateInput = external_exports.object({ name: name(60), index: index.optional() });
|
|
28350
28362
|
var columnUpdateInput = external_exports.object({ name: name(60).optional(), index: index.optional() });
|
|
28351
|
-
var labelCreateInput = external_exports.object({ name:
|
|
28352
|
-
var labelUpdateInput = external_exports.object({ name:
|
|
28363
|
+
var labelCreateInput = external_exports.object({ name: optionalName(40).default(""), color });
|
|
28364
|
+
var labelUpdateInput = external_exports.object({ name: optionalName(40).optional(), color: color.optional() });
|
|
28353
28365
|
var cardCreateInput = external_exports.object({
|
|
28354
28366
|
title: name(300),
|
|
28355
28367
|
description: external_exports.string().max(MAX_MARKDOWN).optional(),
|
|
@@ -28376,13 +28388,13 @@ var checklistItemUpdateInput = external_exports.object({
|
|
|
28376
28388
|
});
|
|
28377
28389
|
var linkPageInput = external_exports.object({ pageId: id });
|
|
28378
28390
|
var pageCreateInput = external_exports.object({
|
|
28379
|
-
title:
|
|
28391
|
+
title: optionalName(200).default(""),
|
|
28380
28392
|
icon: external_exports.string().max(16).nullable().optional(),
|
|
28381
28393
|
parentId: id.nullable().optional(),
|
|
28382
28394
|
content: external_exports.string().max(MAX_MARKDOWN).default("")
|
|
28383
28395
|
});
|
|
28384
28396
|
var pageUpdateInput = external_exports.object({
|
|
28385
|
-
title:
|
|
28397
|
+
title: optionalName(200).optional(),
|
|
28386
28398
|
icon: external_exports.string().max(16).nullable().optional(),
|
|
28387
28399
|
content: external_exports.string().max(MAX_MARKDOWN).optional(),
|
|
28388
28400
|
/** Required when `content` is sent: optimistic concurrency guard. */
|
|
@@ -28428,10 +28440,35 @@ var oauthDecisionInput = oauthRequestInput.extend({
|
|
|
28428
28440
|
var undoInput = external_exports.object({
|
|
28429
28441
|
ids: external_exports.array(id).min(1).max(500).optional(),
|
|
28430
28442
|
since: id.optional(),
|
|
28443
|
+
/** With `since`: only the changes older than this one, to go on after a batch that ended there. */
|
|
28444
|
+
until: id.optional(),
|
|
28431
28445
|
conflicts: external_exports.enum(["ask", "skip", "force"]).default("ask"),
|
|
28432
28446
|
/** Only say what would happen: nothing is undone. */
|
|
28433
28447
|
dryRun: external_exports.boolean().default(false)
|
|
28434
|
-
}).refine((v) => v.ids === void 0 !== (v.since === void 0), { message: "Send either ids or since" });
|
|
28448
|
+
}).refine((v) => v.ids === void 0 !== (v.since === void 0), { message: "Send either ids or since" }).refine((v) => v.until === void 0 || v.since !== void 0, { message: "until goes with since" });
|
|
28449
|
+
var UUID2 = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
28450
|
+
var TRASH_KEY = new RegExp(`^(?:(?:project|board|column|card|page|attachment|label|checklist|checklist_item):${UUID2}|link:${UUID2}:${UUID2})$`, "i");
|
|
28451
|
+
var trashKey = external_exports.string().regex(TRASH_KEY, "Not a trash key");
|
|
28452
|
+
var trashRestoreInput = external_exports.object({
|
|
28453
|
+
key: trashKey,
|
|
28454
|
+
exclude: external_exports.array(trashKey).max(1e4).default([]),
|
|
28455
|
+
to: external_exports.discriminatedUnion("kind", [
|
|
28456
|
+
external_exports.object({ kind: external_exports.literal("original") }),
|
|
28457
|
+
external_exports.object({ kind: external_exports.literal("recreate") }),
|
|
28458
|
+
external_exports.object({ kind: external_exports.literal("other"), parent: external_exports.object({ kind: external_exports.enum(["project", "board", "column", "card", "page", "checklist"]), id }) })
|
|
28459
|
+
]).optional(),
|
|
28460
|
+
names: external_exports.record(trashKey, name(300)).default({}),
|
|
28461
|
+
keepNames: external_exports.array(trashKey).max(1e4).default([]),
|
|
28462
|
+
include: external_exports.array(trashKey).max(1e3).default([]),
|
|
28463
|
+
dryRun: external_exports.boolean().default(false)
|
|
28464
|
+
});
|
|
28465
|
+
var trashPurgeInput = external_exports.object({ key: trashKey, dryRun: external_exports.boolean().default(false) });
|
|
28466
|
+
var MAX_TRASH_BATCH = 100;
|
|
28467
|
+
var trashRestoreManyInput = external_exports.object({
|
|
28468
|
+
items: external_exports.array(trashRestoreInput.omit({ dryRun: true })).min(1).max(MAX_TRASH_BATCH),
|
|
28469
|
+
dryRun: external_exports.boolean().default(false)
|
|
28470
|
+
});
|
|
28471
|
+
var trashPurgeManyInput = external_exports.object({ keys: external_exports.array(trashKey).min(1).max(MAX_TRASH_BATCH), dryRun: external_exports.boolean().default(false) });
|
|
28435
28472
|
|
|
28436
28473
|
// ../../packages/shared/src/types.ts
|
|
28437
28474
|
var INSTALL_KINDS = ["cli", "button", "docker", "source", "cloudflare"];
|
|
@@ -28509,9 +28546,45 @@ function workerMaxUploadBytes(value) {
|
|
|
28509
28546
|
}
|
|
28510
28547
|
__name(workerMaxUploadBytes, "workerMaxUploadBytes");
|
|
28511
28548
|
|
|
28549
|
+
// src/lib/app-urls.ts
|
|
28550
|
+
var ConfigError = class extends Error {
|
|
28551
|
+
static {
|
|
28552
|
+
__name(this, "ConfigError");
|
|
28553
|
+
}
|
|
28554
|
+
};
|
|
28555
|
+
function parseAppUrls(value) {
|
|
28556
|
+
const urls = value.split(",").map((u) => u.trim()).filter(Boolean);
|
|
28557
|
+
if (urls.length === 0) throw new ConfigError("APP_URL is empty. Set it to the address people open Orqevio at, such as https://orqevio.example.com");
|
|
28558
|
+
return urls.map((u) => {
|
|
28559
|
+
const url2 = URL.canParse(u) ? new URL(u) : null;
|
|
28560
|
+
if (!url2 || url2.protocol !== "http:" && url2.protocol !== "https:") {
|
|
28561
|
+
throw new ConfigError(`APP_URL must be full addresses starting with https:// or http://, such as https://orqevio.example.com (got "${u}")`);
|
|
28562
|
+
}
|
|
28563
|
+
return url2.origin;
|
|
28564
|
+
});
|
|
28565
|
+
}
|
|
28566
|
+
__name(parseAppUrls, "parseAppUrls");
|
|
28567
|
+
|
|
28568
|
+
// src/worker/settings.ts
|
|
28569
|
+
function workerAppUrls(value) {
|
|
28570
|
+
return value?.split(",").some((url2) => url2.trim()) ? parseAppUrls(value) : [];
|
|
28571
|
+
}
|
|
28572
|
+
__name(workerAppUrls, "workerAppUrls");
|
|
28573
|
+
function appUrlProblem(value) {
|
|
28574
|
+
try {
|
|
28575
|
+
workerAppUrls(value);
|
|
28576
|
+
return null;
|
|
28577
|
+
} catch (error62) {
|
|
28578
|
+
if (error62 instanceof ConfigError) return error62.message;
|
|
28579
|
+
throw error62;
|
|
28580
|
+
}
|
|
28581
|
+
}
|
|
28582
|
+
__name(appUrlProblem, "appUrlProblem");
|
|
28583
|
+
|
|
28512
28584
|
// src/worker/env.ts
|
|
28585
|
+
var workerConfigProblem = /* @__PURE__ */ __name((bindings) => appUrlProblem(bindings.APP_URL), "workerConfigProblem");
|
|
28513
28586
|
function workerEnv(bindings) {
|
|
28514
|
-
const appUrls = (bindings.APP_URL
|
|
28587
|
+
const appUrls = workerAppUrls(bindings.APP_URL);
|
|
28515
28588
|
return {
|
|
28516
28589
|
nodeEnv: "production",
|
|
28517
28590
|
port: 0,
|
|
@@ -28536,6 +28609,28 @@ function workerEnv(bindings) {
|
|
|
28536
28609
|
}
|
|
28537
28610
|
__name(workerEnv, "workerEnv");
|
|
28538
28611
|
|
|
28612
|
+
// src/worker/misconfigured.ts
|
|
28613
|
+
function misconfigured(request, problem) {
|
|
28614
|
+
const fix = "On Cloudflare APP_URL is optional: remove it to use the address each visit comes from, or set it to full addresses separated by commas.";
|
|
28615
|
+
const { pathname } = new URL(request.url);
|
|
28616
|
+
const headers = { "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };
|
|
28617
|
+
if (/^\/(?:api\/|mcp$|oauth\/|\.well-known\/)/.test(pathname)) {
|
|
28618
|
+
return Response.json({ error: { code: "misconfigured", message: `${problem} ${fix}` } }, { status: 503, headers });
|
|
28619
|
+
}
|
|
28620
|
+
if (pathname === "/healthz") return new Response(`misconfigured: ${problem}
|
|
28621
|
+
`, { status: 503, headers: { ...headers, "Content-Type": "text/plain; charset=utf-8" } });
|
|
28622
|
+
const escape2 = /* @__PURE__ */ __name((text2) => text2.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`), "escape");
|
|
28623
|
+
const page = `<!doctype html>
|
|
28624
|
+
<html lang="en">
|
|
28625
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Orqevio can't start</title>
|
|
28626
|
+
<style>body{font:16px/1.5 system-ui,sans-serif;max-width:40rem;margin:4rem auto;padding:0 1rem;color:#1f1d1a;background:#faf9f6}h1{font-size:1.5rem}code{background:#efede8;padding:.1em .3em;border-radius:4px}</style></head>
|
|
28627
|
+
<body><h1>Orqevio can't start</h1><p>${escape2(problem)}</p><p>${escape2(fix)}</p></body>
|
|
28628
|
+
</html>
|
|
28629
|
+
`;
|
|
28630
|
+
return new Response(page, { status: 503, headers: { ...headers, "Content-Type": "text/html; charset=utf-8", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'" } });
|
|
28631
|
+
}
|
|
28632
|
+
__name(misconfigured, "misconfigured");
|
|
28633
|
+
|
|
28539
28634
|
// src/worker/copy.ts
|
|
28540
28635
|
import { DurableObject } from "cloudflare:workers";
|
|
28541
28636
|
|
|
@@ -34723,8 +34818,8 @@ var getPath = /* @__PURE__ */ __name((request) => {
|
|
|
34723
34818
|
if (charCode === 37) {
|
|
34724
34819
|
const queryIndex = url2.indexOf("?", i2);
|
|
34725
34820
|
const hashIndex = url2.indexOf("#", i2);
|
|
34726
|
-
const
|
|
34727
|
-
const path2 = url2.slice(start,
|
|
34821
|
+
const end2 = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
34822
|
+
const path2 = url2.slice(start, end2);
|
|
34728
34823
|
return tryDecodeURI(path2.includes("%25") ? path2.replace(/%25/g, "%2525") : path2);
|
|
34729
34824
|
} else if (charCode === 63 || charCode === 35) break;
|
|
34730
34825
|
}
|
|
@@ -35580,8 +35675,8 @@ var getPathPrefixLength = /* @__PURE__ */ __name((c, pathPrefix, routePath) => {
|
|
|
35580
35675
|
const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
|
|
35581
35676
|
length += value.length + 1;
|
|
35582
35677
|
} else if (pattern || part.endsWith("*")) {
|
|
35583
|
-
const
|
|
35584
|
-
length =
|
|
35678
|
+
const end2 = path2.indexOf("/", length + 1);
|
|
35679
|
+
length = end2 === -1 ? path2.length : end2;
|
|
35585
35680
|
} else length += part.length + 1;
|
|
35586
35681
|
}
|
|
35587
35682
|
return length;
|
|
@@ -37038,6 +37133,7 @@ var TokenService = class {
|
|
|
37038
37133
|
await this.access.workspace(actor, data.workspaceId);
|
|
37039
37134
|
const token = `${TOKEN_PREFIX}${randomToken(32)}`;
|
|
37040
37135
|
const scopes = consistentScopes(data.scopes);
|
|
37136
|
+
if (scopes.length === 0) throw badRequest('Allow at least read access to tasks or docs: "organize" alone gives none');
|
|
37041
37137
|
const [row] = await this.deps.db.insert(apiTokens).values({
|
|
37042
37138
|
userId: actor.userId,
|
|
37043
37139
|
workspaceId: data.workspaceId,
|
|
@@ -37230,7 +37326,9 @@ var registrationInput = external_exports.object({
|
|
|
37230
37326
|
grant_types: external_exports.array(external_exports.string()).optional(),
|
|
37231
37327
|
response_types: external_exports.array(external_exports.string()).optional()
|
|
37232
37328
|
});
|
|
37233
|
-
function registrationProblem(
|
|
37329
|
+
function registrationProblem(path2 = []) {
|
|
37330
|
+
const [field] = path2;
|
|
37331
|
+
if (field === "redirect_uris" && path2.length > 1) return "Each address in redirect_uris must be text of at most 500 characters";
|
|
37234
37332
|
switch (field) {
|
|
37235
37333
|
case "client_name":
|
|
37236
37334
|
return "client_name must be text of at most 200 characters";
|
|
@@ -37268,7 +37366,7 @@ var OAuthService = class {
|
|
|
37268
37366
|
/** Dynamic Client Registration (RFC 7591). Nothing is stored: the client_id is signed. */
|
|
37269
37367
|
async register(input2) {
|
|
37270
37368
|
const result = registrationInput.safeParse(input2);
|
|
37271
|
-
if (!result.success) throw new OAuthError("invalid_client_metadata", registrationProblem(result.error.issues[0]?.path
|
|
37369
|
+
if (!result.success) throw new OAuthError("invalid_client_metadata", registrationProblem(result.error.issues[0]?.path));
|
|
37272
37370
|
const data = result.data;
|
|
37273
37371
|
const bad = data.redirect_uris.find((uri) => !validRedirectUri(uri));
|
|
37274
37372
|
if (bad) throw new OAuthError("invalid_redirect_uri", `Not an allowed redirect URI: ${bad.slice(0, 100)}`);
|
|
@@ -37555,18 +37653,18 @@ var relaxedCookieNameRegEx = /^[!#-:<>-[\]-~]+$/;
|
|
|
37555
37653
|
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
37556
37654
|
var trimCookieWhitespace = /* @__PURE__ */ __name((value) => {
|
|
37557
37655
|
let start = 0;
|
|
37558
|
-
let
|
|
37559
|
-
while (start <
|
|
37656
|
+
let end2 = value.length;
|
|
37657
|
+
while (start < end2) {
|
|
37560
37658
|
const charCode = value.charCodeAt(start);
|
|
37561
37659
|
if (charCode !== 32 && charCode !== 9) break;
|
|
37562
37660
|
start++;
|
|
37563
37661
|
}
|
|
37564
|
-
while (
|
|
37565
|
-
const charCode = value.charCodeAt(
|
|
37662
|
+
while (end2 > start) {
|
|
37663
|
+
const charCode = value.charCodeAt(end2 - 1);
|
|
37566
37664
|
if (charCode !== 32 && charCode !== 9) break;
|
|
37567
|
-
|
|
37665
|
+
end2--;
|
|
37568
37666
|
}
|
|
37569
|
-
return start === 0 &&
|
|
37667
|
+
return start === 0 && end2 === value.length ? value : value.slice(start, end2);
|
|
37570
37668
|
}, "trimCookieWhitespace");
|
|
37571
37669
|
var parse4 = /* @__PURE__ */ __name((cookie, name2) => {
|
|
37572
37670
|
if (name2 && cookie.indexOf(name2) === -1) return {};
|
|
@@ -37768,7 +37866,7 @@ function safeFilename(name2) {
|
|
|
37768
37866
|
const cleaned = withoutBidiControls(name2).replace(/[\\/\u0000-\u001f\u007f"]/g, "_").trim();
|
|
37769
37867
|
if (cleaned.length <= MAX_FILENAME) return cleaned || "file";
|
|
37770
37868
|
const ext = /\.[^.\s]{1,16}$/.exec(cleaned)?.[0] ?? "";
|
|
37771
|
-
return cleaned
|
|
37869
|
+
return clip(cleaned, MAX_FILENAME - ext.length).trimEnd() + ext;
|
|
37772
37870
|
}
|
|
37773
37871
|
__name(safeFilename, "safeFilename");
|
|
37774
37872
|
function sniff(bytes, declared) {
|
|
@@ -37811,8 +37909,10 @@ var AttachmentService = class {
|
|
|
37811
37909
|
*/
|
|
37812
37910
|
/** Uploads still running, which uninstalling waits for (see close). */
|
|
37813
37911
|
inFlight = /* @__PURE__ */ new Set();
|
|
37814
|
-
|
|
37912
|
+
/** Why uploads are refused for now: the copy being uninstalled, or a backup being put back. */
|
|
37913
|
+
closed = null;
|
|
37815
37914
|
async upload(actor, target, file2) {
|
|
37915
|
+
if (this.closed === "restoring") throw new AppError(409, "restoring", "A backup is being restored: upload the file again in a moment");
|
|
37816
37916
|
if (this.closed) throw uninstalled();
|
|
37817
37917
|
const work = this.store(actor, target, file2);
|
|
37818
37918
|
this.inFlight.add(work);
|
|
@@ -37826,12 +37926,12 @@ var AttachmentService = class {
|
|
|
37826
37926
|
* Refuses new uploads and waits for the running ones, so that deleting every stored
|
|
37827
37927
|
* file afterwards cannot miss one still being written. reopen() undoes it.
|
|
37828
37928
|
*/
|
|
37829
|
-
async close() {
|
|
37830
|
-
this.closed =
|
|
37929
|
+
async close(reason = "uninstalling") {
|
|
37930
|
+
this.closed = reason;
|
|
37831
37931
|
await Promise.allSettled([...this.inFlight]);
|
|
37832
37932
|
}
|
|
37833
37933
|
reopen() {
|
|
37834
|
-
this.closed =
|
|
37934
|
+
this.closed = null;
|
|
37835
37935
|
}
|
|
37836
37936
|
async store(actor, target, file2) {
|
|
37837
37937
|
this.access.requireScope(actor, target.pageId ? "docs:write" : "tasks:write");
|
|
@@ -37839,7 +37939,7 @@ var AttachmentService = class {
|
|
|
37839
37939
|
throw new AppError(415, "raw_upload_required", "Send the file itself as the request body, with its name in the X-File-Name header");
|
|
37840
37940
|
}
|
|
37841
37941
|
if (!Number.isSafeInteger(file2.size) || file2.size < 0) throw new AppError(411, "length_required", "Content-Length is required");
|
|
37842
|
-
if (file2.size === 0 || !file2.body) throw
|
|
37942
|
+
if (file2.size === 0 || !file2.body) throw new AppError(400, "file_empty", "The file is empty");
|
|
37843
37943
|
if (file2.size > this.deps.env.maxUploadBytes) {
|
|
37844
37944
|
throw new AppError(413, "file_too_large", `Files are limited to ${Math.round(this.deps.env.maxUploadBytes / 1048576)} MB`);
|
|
37845
37945
|
}
|
|
@@ -38494,13 +38594,14 @@ var PageService = class {
|
|
|
38494
38594
|
}
|
|
38495
38595
|
return null;
|
|
38496
38596
|
}
|
|
38597
|
+
/** Every page above it, the top one first, however deep it is. */
|
|
38497
38598
|
async breadcrumbs(page) {
|
|
38498
38599
|
if (!page.parentId) return [];
|
|
38499
38600
|
const rows = this.deps.db.all(sql`
|
|
38500
38601
|
WITH RECURSIVE chain AS (
|
|
38501
38602
|
SELECT id, parent_id, title, icon, 1 AS depth FROM pages WHERE id = ${page.parentId}
|
|
38502
38603
|
UNION ALL
|
|
38503
|
-
SELECT p.id, p.parent_id, p.title, p.icon, c.depth + 1 FROM pages p JOIN chain c ON p.id = c.parent_id WHERE c.depth <
|
|
38604
|
+
SELECT p.id, p.parent_id, p.title, p.icon, c.depth + 1 FROM pages p JOIN chain c ON p.id = c.parent_id WHERE c.depth < ${MAX_TREE_DEPTH}
|
|
38504
38605
|
)
|
|
38505
38606
|
SELECT id, title, icon, depth FROM chain ORDER BY depth DESC`);
|
|
38506
38607
|
return rows.map((r) => ({ id: r.id, title: r.title, icon: r.icon }));
|
|
@@ -38527,8 +38628,8 @@ var PageService = class {
|
|
|
38527
38628
|
if (data.title !== void 0) patch.title = data.title;
|
|
38528
38629
|
if (data.icon !== void 0) patch.icon = data.icon;
|
|
38529
38630
|
if (data.content !== void 0) {
|
|
38530
|
-
const length = opts.append && prev.content !== "" ? prev.content
|
|
38531
|
-
if (length > MAX_MARKDOWN) throw pageTooLong(prev.content
|
|
38631
|
+
const length = opts.append && prev.content !== "" ? characters(prev.content) + 2 + characters(data.content) : 0;
|
|
38632
|
+
if (length > MAX_MARKDOWN) throw pageTooLong(characters(prev.content), length);
|
|
38532
38633
|
patch.content = opts.append ? sql`CASE WHEN ${pages.content} = '' THEN ${data.content} ELSE ${pages.content} || ${"\n\n"} || ${data.content} END` : data.content;
|
|
38533
38634
|
}
|
|
38534
38635
|
const guard = data.baseVersion !== void 0 ? and(eq(pages.id, pageId), eq(pages.version, data.baseVersion)) : eq(pages.id, pageId);
|
|
@@ -39174,6 +39275,11 @@ function limit(limiter2, key) {
|
|
|
39174
39275
|
if (wait > 0) throw new AppError(429, "rate_limited", `Too many attempts. Try again in ${Math.ceil(wait / 60)} min.`, void 0, { "Retry-After": String(wait) });
|
|
39175
39276
|
}
|
|
39176
39277
|
__name(limit, "limit");
|
|
39278
|
+
function trashItemKey(value) {
|
|
39279
|
+
if (!TRASH_KEY.test(value)) throw badRequest("Not a trash key");
|
|
39280
|
+
return value;
|
|
39281
|
+
}
|
|
39282
|
+
__name(trashItemKey, "trashItemKey");
|
|
39177
39283
|
async function json2(c) {
|
|
39178
39284
|
try {
|
|
39179
39285
|
return await c.req.json();
|
|
@@ -39279,9 +39385,9 @@ function createApi(env) {
|
|
|
39279
39385
|
api.get("/backups", async (c) => c.json(await c.get("services").backups.status(requireActor(c))));
|
|
39280
39386
|
api.post("/backups", async (c) => c.json(await c.get("services").backups.createNow(requireActor(c)), 201));
|
|
39281
39387
|
api.post("/backups/:id/restore", async (c) => {
|
|
39282
|
-
const { session, restored } = await c.get("services").backups.restore(requireActor(c), c.req.param("id"), await json2(c), c.req.header("user-agent") ?? null);
|
|
39388
|
+
const { session, restored, leftOut } = await c.get("services").backups.restore(requireActor(c), c.req.param("id"), await json2(c), c.req.header("user-agent") ?? null);
|
|
39283
39389
|
setSessionCookie(c, session.token, session.expiresAt);
|
|
39284
|
-
return c.json({ restored });
|
|
39390
|
+
return c.json({ restored, ...leftOut && { leftOut } });
|
|
39285
39391
|
});
|
|
39286
39392
|
api.get("/export", async (c) => {
|
|
39287
39393
|
const { body, filename } = await c.get("services").export.export(requireActor(c));
|
|
@@ -39305,6 +39411,17 @@ function createApi(env) {
|
|
|
39305
39411
|
return c.body(null, 204);
|
|
39306
39412
|
});
|
|
39307
39413
|
api.get("/workspaces/:id/trash", async (c) => c.json(await c.get("services").trash.list(requireActor(c), c.req.param("id"))));
|
|
39414
|
+
api.post(
|
|
39415
|
+
"/workspaces/:id/trash/restore",
|
|
39416
|
+
async (c) => c.json(await c.get("services").trash.restoreItem(requireActor(c), c.req.param("id"), await json2(c)))
|
|
39417
|
+
);
|
|
39418
|
+
api.post("/workspaces/:id/trash/restore-many", async (c) => c.json(await c.get("services").trash.restoreMany(requireActor(c), c.req.param("id"), await json2(c))));
|
|
39419
|
+
api.post("/workspaces/:id/trash/purge", async (c) => c.json(await c.get("services").trash.purgeMany(requireActor(c), c.req.param("id"), await json2(c))));
|
|
39420
|
+
api.get("/workspaces/:id/trash/:key", async (c) => c.json(await c.get("services").trash.tree(requireActor(c), c.req.param("id"), trashItemKey(c.req.param("key")))));
|
|
39421
|
+
api.delete("/workspaces/:id/trash/:key", async (c) => {
|
|
39422
|
+
await c.get("services").trash.purgeItem(requireActor(c), c.req.param("id"), trashItemKey(c.req.param("key")));
|
|
39423
|
+
return c.body(null, 204);
|
|
39424
|
+
});
|
|
39308
39425
|
api.post("/trash/:id/restore", async (c) => c.json(await c.get("services").trash.restore(requireActor(c), c.req.param("id"))));
|
|
39309
39426
|
api.delete("/trash/:id", async (c) => {
|
|
39310
39427
|
await c.get("services").trash.purge(requireActor(c), c.req.param("id"));
|
|
@@ -39328,6 +39445,7 @@ function createApi(env) {
|
|
|
39328
39445
|
await services.activity.list(c.req.param("id"), {
|
|
39329
39446
|
limit: limitParam(c),
|
|
39330
39447
|
before: beforeParam(c),
|
|
39448
|
+
beforeId: c.req.query("beforeId") || void 0,
|
|
39331
39449
|
tokenId: c.req.query("tokenId") || void 0,
|
|
39332
39450
|
agentsOnly: c.req.query("agents") === "1"
|
|
39333
39451
|
})
|
|
@@ -50163,7 +50281,7 @@ var EMPTY_COMPLETION_RESULT = {
|
|
|
50163
50281
|
};
|
|
50164
50282
|
|
|
50165
50283
|
// src/version.ts
|
|
50166
|
-
var VERSION = "1.
|
|
50284
|
+
var VERSION = "1.3.0";
|
|
50167
50285
|
|
|
50168
50286
|
// src/mcp/server.ts
|
|
50169
50287
|
var MCP_SERVER_NAME = "orqevio";
|
|
@@ -50381,11 +50499,11 @@ function createMcpServer(services, actor) {
|
|
|
50381
50499
|
"create_card",
|
|
50382
50500
|
{
|
|
50383
50501
|
title: "Create card",
|
|
50384
|
-
description:
|
|
50502
|
+
description: `Creates a card in a column. description is Markdown, up to ${MAX_MARKDOWN} characters.`,
|
|
50385
50503
|
inputSchema: {
|
|
50386
50504
|
column_id: uuid3,
|
|
50387
50505
|
title: external_exports.string().min(1).max(300),
|
|
50388
|
-
description: external_exports.string().max(
|
|
50506
|
+
description: external_exports.string().max(MAX_MARKDOWN).optional(),
|
|
50389
50507
|
due_date: dueDate.optional(),
|
|
50390
50508
|
label_ids: external_exports.array(uuid3).max(20).optional(),
|
|
50391
50509
|
position: external_exports.enum(["top", "bottom"]).default("bottom")
|
|
@@ -50407,11 +50525,11 @@ function createMcpServer(services, actor) {
|
|
|
50407
50525
|
"update_card",
|
|
50408
50526
|
{
|
|
50409
50527
|
title: "Update card",
|
|
50410
|
-
description:
|
|
50528
|
+
description: `Updates a card. Only the fields you send change. label_ids replaces the full label set. description is Markdown, up to ${MAX_MARKDOWN} characters; with it, send base_version (the version from get_card) to avoid overwriting newer edits.`,
|
|
50411
50529
|
inputSchema: {
|
|
50412
50530
|
card_id: uuid3,
|
|
50413
50531
|
title: external_exports.string().min(1).max(300).optional(),
|
|
50414
|
-
description: external_exports.string().max(
|
|
50532
|
+
description: external_exports.string().max(MAX_MARKDOWN).optional(),
|
|
50415
50533
|
base_version: external_exports.number().int().min(1).optional(),
|
|
50416
50534
|
due_date: dueDate.nullable().optional(),
|
|
50417
50535
|
label_ids: external_exports.array(uuid3).max(20).optional()
|
|
@@ -50508,11 +50626,24 @@ function createMcpServer(services, actor) {
|
|
|
50508
50626
|
return { created: true, label_id: label.id };
|
|
50509
50627
|
})
|
|
50510
50628
|
);
|
|
50629
|
+
server.registerTool(
|
|
50630
|
+
"create_checklist",
|
|
50631
|
+
{
|
|
50632
|
+
title: "Create checklist",
|
|
50633
|
+
description: "Creates an empty checklist on a card. To create one with items, use add_checklist_items with checklist_title instead.",
|
|
50634
|
+
inputSchema: { card_id: uuid3, title: external_exports.string().min(1).max(120) },
|
|
50635
|
+
annotations: WRITE
|
|
50636
|
+
},
|
|
50637
|
+
({ card_id, title }) => run(async () => {
|
|
50638
|
+
const checklist = await services.cards.createChecklist(actor, card_id, { title });
|
|
50639
|
+
return { created: true, checklist_id: checklist.id, title: checklist.title };
|
|
50640
|
+
})
|
|
50641
|
+
);
|
|
50511
50642
|
server.registerTool(
|
|
50512
50643
|
"add_checklist_items",
|
|
50513
50644
|
{
|
|
50514
50645
|
title: "Add checklist items",
|
|
50515
|
-
description: "Adds items to a checklist of a card. Pass checklist_id to use an existing checklist; otherwise a new checklist is created with checklist_title.",
|
|
50646
|
+
description: "Adds items to a checklist of a card. Pass checklist_id to use an existing checklist; otherwise a new checklist is created with checklist_title. For an empty checklist, use create_checklist.",
|
|
50516
50647
|
inputSchema: {
|
|
50517
50648
|
card_id: uuid3,
|
|
50518
50649
|
items: external_exports.array(external_exports.string().min(1).max(500)).min(1).max(50),
|
|
@@ -50670,7 +50801,7 @@ function createMcpServer(services, actor) {
|
|
|
50670
50801
|
},
|
|
50671
50802
|
(args) => run(async () => {
|
|
50672
50803
|
if (args.card_id === void 0 === (args.page_id === void 0)) throw new AppError(400, "bad_request", "Send either card_id or page_id");
|
|
50673
|
-
const bytes = args.encoding === "base64" ?
|
|
50804
|
+
const bytes = args.encoding === "base64" ? fromBase64(args.content) : new TextEncoder().encode(args.content);
|
|
50674
50805
|
if (bytes.byteLength > MCP_UPLOAD_MB * 1024 * 1024) throw new AppError(413, "file_too_large", `Files uploaded by agents are limited to ${MCP_UPLOAD_MB} MB`);
|
|
50675
50806
|
const type = args.mime_type ?? (args.encoding === "text" ? "text/plain; charset=utf-8" : "application/octet-stream");
|
|
50676
50807
|
const body = new Blob([bytes]).stream();
|
|
@@ -50773,6 +50904,15 @@ function createMcpServer(services, actor) {
|
|
|
50773
50904
|
return server;
|
|
50774
50905
|
}
|
|
50775
50906
|
__name(createMcpServer, "createMcpServer");
|
|
50907
|
+
function fromBase64(content) {
|
|
50908
|
+
if (/^data:[^,]*,/i.test(content)) throw new AppError(400, "bad_request", "content is a data: URL: send only the base64 after the comma");
|
|
50909
|
+
const compact = content.replace(/\s+/g, "");
|
|
50910
|
+
const unpadded = compact.replace(/={1,2}$/, "");
|
|
50911
|
+
if (!/^[A-Za-z0-9+/]*$/.test(unpadded) && !/^[A-Za-z0-9_-]*$/.test(unpadded)) throw new AppError(400, "bad_request", "content is not valid base64");
|
|
50912
|
+
if (unpadded.length % 4 === 1 || compact.length !== unpadded.length && compact.length % 4 !== 0) throw new AppError(400, "bad_request", "content is not valid base64: its length is not that of encoded bytes");
|
|
50913
|
+
return Uint8Array.from(Buffer.from(unpadded, /[-_]/.test(unpadded) ? "base64url" : "base64"));
|
|
50914
|
+
}
|
|
50915
|
+
__name(fromBase64, "fromBase64");
|
|
50776
50916
|
function invalidParamsForMalformedRequests(server) {
|
|
50777
50917
|
const handlers = server.server._requestHandlers;
|
|
50778
50918
|
if (!(handlers instanceof Map)) return;
|
|
@@ -50796,6 +50936,13 @@ var rpcError = /* @__PURE__ */ __name((status, code, message, headers = {}) => n
|
|
|
50796
50936
|
status,
|
|
50797
50937
|
headers: { "Content-Type": "application/json", ...headers }
|
|
50798
50938
|
}), "rpcError");
|
|
50939
|
+
async function invalidRequestForNonRpc(response) {
|
|
50940
|
+
if (response.status !== 400 || !response.headers.get("content-type")?.includes("application/json")) return response;
|
|
50941
|
+
const body = await response.clone().json().catch(() => null);
|
|
50942
|
+
if (body?.error?.code !== -32700 || body.error.message !== "Parse error: Invalid JSON-RPC message") return response;
|
|
50943
|
+
return rpcError(400, -32600, 'Invalid Request: the body is JSON, but not a JSON-RPC 2.0 request (jsonrpc "2.0", method, and an id for a call)');
|
|
50944
|
+
}
|
|
50945
|
+
__name(invalidRequestForNonRpc, "invalidRequestForNonRpc");
|
|
50799
50946
|
async function handleMcp(c) {
|
|
50800
50947
|
if (c.req.method !== "POST") {
|
|
50801
50948
|
return rpcError(405, -32e3, "Method not allowed. This server is stateless: use POST.", { Allow: "POST" });
|
|
@@ -50816,7 +50963,7 @@ async function handleMcp(c) {
|
|
|
50816
50963
|
const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: void 0, enableJsonResponse: true, maxRequestBodySize: MCP_MAX_REQUEST_BYTES });
|
|
50817
50964
|
await server.connect(transport);
|
|
50818
50965
|
try {
|
|
50819
|
-
return await transport.handleRequest(c.req.raw);
|
|
50966
|
+
return invalidRequestForNonRpc(await transport.handleRequest(c.req.raw));
|
|
50820
50967
|
} finally {
|
|
50821
50968
|
void server.close();
|
|
50822
50969
|
}
|
|
@@ -51007,16 +51154,52 @@ var ActivityService = class {
|
|
|
51007
51154
|
console.error("[realtime] publish failed", error62);
|
|
51008
51155
|
}
|
|
51009
51156
|
}
|
|
51157
|
+
/**
|
|
51158
|
+
* The workspace's activity, newest first. A page after the first starts after the last entry
|
|
51159
|
+
* of the previous one: `before`, its time, and `beforeId`, the entry itself, as several can
|
|
51160
|
+
* share a millisecond.
|
|
51161
|
+
*/
|
|
51010
51162
|
async list(workspaceId, opts = {}) {
|
|
51011
51163
|
const filters = [eq(activity.workspaceId, workspaceId)];
|
|
51012
|
-
|
|
51164
|
+
const after = this.after(opts.before, opts.beforeId);
|
|
51165
|
+
if (after) filters.push(after);
|
|
51013
51166
|
if (opts.entityId) filters.push(eq(activity.entityId, opts.entityId));
|
|
51014
51167
|
if (opts.tokenId) filters.push(eq(activity.actorTokenId, opts.tokenId));
|
|
51015
51168
|
if (opts.agentsOnly) filters.push(eq(activity.actorKind, "agent"));
|
|
51016
51169
|
const rows = await this.deps.db.select().from(activity).where(and(...filters)).orderBy(desc(activity.createdAt), desc(sql`rowid`)).limit(Math.min(opts.limit ?? 30, 100));
|
|
51017
|
-
return rows.map(toActivityDTO);
|
|
51170
|
+
return this.markTrashed(workspaceId, rows.map(toActivityDTO));
|
|
51171
|
+
}
|
|
51172
|
+
/**
|
|
51173
|
+
* Where the next page starts, in the list's order: after the time the previous page ended at
|
|
51174
|
+
* and, within that millisecond, after its last entry. The entry keeps its rowid when a later
|
|
51175
|
+
* one merges into it and takes it to the top, so it still marks where the page ended; only if
|
|
51176
|
+
* it is gone is the time alone the best there is.
|
|
51177
|
+
*/
|
|
51178
|
+
after(before, beforeId) {
|
|
51179
|
+
if (!before) return void 0;
|
|
51180
|
+
const anchor2 = beforeId ? this.deps.db.get(sql`SELECT rowid AS seq FROM activity WHERE id = ${beforeId}`) : void 0;
|
|
51181
|
+
if (!anchor2) return lt(activity.createdAt, before);
|
|
51182
|
+
return or(lt(activity.createdAt, before), and(eq(activity.createdAt, before), sql`rowid < ${anchor2.seq}`));
|
|
51183
|
+
}
|
|
51184
|
+
/**
|
|
51185
|
+
* Entries about something that is in the trash now say so, with its key there: a link to it
|
|
51186
|
+
* would find nothing. What was deleted for good is in neither, and is told as text.
|
|
51187
|
+
*/
|
|
51188
|
+
markTrashed(workspaceId, entries) {
|
|
51189
|
+
const ids = [...new Set(entries.filter((e) => e.action !== "trash.purged" && TRASH_TABLE[e.entityType]).map((e) => e.entityId))];
|
|
51190
|
+
if (ids.length === 0) return entries;
|
|
51191
|
+
const found = this.deps.db.all(
|
|
51192
|
+
sql`SELECT r.table_name AS tableName, json_extract(r.data, '$.id') AS id FROM trash_rows r JOIN trash t ON t.id = r.trash_id
|
|
51193
|
+
WHERE t.workspace_id = ${workspaceId} AND json_extract(r.data, '$.id') IN (SELECT value FROM json_each(${JSON.stringify(ids)}))`
|
|
51194
|
+
);
|
|
51195
|
+
const trashed = new Set(found.map((r) => `${r.tableName}|${r.id}`));
|
|
51196
|
+
return entries.map((e) => {
|
|
51197
|
+
const table = e.action === "trash.purged" ? void 0 : TRASH_TABLE[e.entityType];
|
|
51198
|
+
return table && trashed.has(`${table}|${e.entityId}`) ? { ...e, inTrash: `${e.entityType}:${e.entityId}` } : e;
|
|
51199
|
+
});
|
|
51018
51200
|
}
|
|
51019
51201
|
};
|
|
51202
|
+
var TRASH_TABLE = { project: "projects", board: "boards", column: "board_columns", card: "cards", label: "labels", page: "pages" };
|
|
51020
51203
|
|
|
51021
51204
|
// ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
|
|
51022
51205
|
var u8 = Uint8Array;
|
|
@@ -51356,15 +51539,15 @@ var inflt = /* @__PURE__ */ __name(function(dat, st, buf, dict) {
|
|
|
51356
51539
|
}
|
|
51357
51540
|
if (resize)
|
|
51358
51541
|
cbuf(bt + 131072);
|
|
51359
|
-
var
|
|
51542
|
+
var end2 = bt + add;
|
|
51360
51543
|
if (bt < dt) {
|
|
51361
|
-
var shift = dl - dt, dend = Math.min(dt,
|
|
51544
|
+
var shift = dl - dt, dend = Math.min(dt, end2);
|
|
51362
51545
|
if (shift + bt < 0)
|
|
51363
51546
|
err(3);
|
|
51364
51547
|
for (; bt < dend; ++bt)
|
|
51365
51548
|
buf[bt] = dict[shift + bt];
|
|
51366
51549
|
}
|
|
51367
|
-
for (; bt <
|
|
51550
|
+
for (; bt < end2; ++bt)
|
|
51368
51551
|
buf[bt] = buf[bt - dt];
|
|
51369
51552
|
}
|
|
51370
51553
|
}
|
|
@@ -51713,14 +51896,6 @@ var dopt = /* @__PURE__ */ __name(function(dat, opt, pre, post, st) {
|
|
|
51713
51896
|
}
|
|
51714
51897
|
return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
|
|
51715
51898
|
}, "dopt");
|
|
51716
|
-
var mrg = /* @__PURE__ */ __name(function(a, b) {
|
|
51717
|
-
var o = {};
|
|
51718
|
-
for (var k in a)
|
|
51719
|
-
o[k] = a[k];
|
|
51720
|
-
for (var k in b)
|
|
51721
|
-
o[k] = b[k];
|
|
51722
|
-
return o;
|
|
51723
|
-
}, "mrg");
|
|
51724
51899
|
var wbytes = /* @__PURE__ */ __name(function(d, b, v) {
|
|
51725
51900
|
for (; v; ++b)
|
|
51726
51901
|
d[b] = v, v >>>= 8;
|
|
@@ -51819,6 +51994,10 @@ var Deflate = /* @__PURE__ */ (function() {
|
|
|
51819
51994
|
};
|
|
51820
51995
|
return Deflate2;
|
|
51821
51996
|
})();
|
|
51997
|
+
function deflateSync(data, opts) {
|
|
51998
|
+
return dopt(data, opts || {}, 0, 0);
|
|
51999
|
+
}
|
|
52000
|
+
__name(deflateSync, "deflateSync");
|
|
51822
52001
|
var Inflate = /* @__PURE__ */ (function() {
|
|
51823
52002
|
function Inflate2(opts, cb) {
|
|
51824
52003
|
if (typeof opts == "function")
|
|
@@ -51958,239 +52137,6 @@ function strToU8(str, latin1) {
|
|
|
51958
52137
|
return slc(ar, 0, ai);
|
|
51959
52138
|
}
|
|
51960
52139
|
__name(strToU8, "strToU8");
|
|
51961
|
-
var dbf = /* @__PURE__ */ __name(function(l) {
|
|
51962
|
-
return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0;
|
|
51963
|
-
}, "dbf");
|
|
51964
|
-
var exfl = /* @__PURE__ */ __name(function(ex) {
|
|
51965
|
-
var le = 0;
|
|
51966
|
-
if (ex) {
|
|
51967
|
-
for (var k in ex) {
|
|
51968
|
-
var l = ex[k].length;
|
|
51969
|
-
if (l > 65535)
|
|
51970
|
-
err(9);
|
|
51971
|
-
le += l + 4;
|
|
51972
|
-
}
|
|
51973
|
-
}
|
|
51974
|
-
return le;
|
|
51975
|
-
}, "exfl");
|
|
51976
|
-
var wzh = /* @__PURE__ */ __name(function(d, b, f, fn, u, c, ce, co) {
|
|
51977
|
-
var fl2 = fn.length, ex = f.extra, col = co && co.length;
|
|
51978
|
-
var exl = exfl(ex);
|
|
51979
|
-
wbytes(d, b, ce != null ? 33639248 : 67324752), b += 4;
|
|
51980
|
-
if (ce != null)
|
|
51981
|
-
d[b++] = 20, d[b++] = f.os;
|
|
51982
|
-
d[b] = 20, b += 2;
|
|
51983
|
-
d[b++] = f.flag << 1 | (c < 0 && 8), d[b++] = u && 8;
|
|
51984
|
-
d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
|
|
51985
|
-
var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
|
|
51986
|
-
if (y < 0 || y > 119)
|
|
51987
|
-
err(10);
|
|
51988
|
-
wbytes(d, b, y << 25 | dt.getMonth() + 1 << 21 | dt.getDate() << 16 | dt.getHours() << 11 | dt.getMinutes() << 5 | dt.getSeconds() >> 1), b += 4;
|
|
51989
|
-
if (c != -1) {
|
|
51990
|
-
wbytes(d, b, f.crc);
|
|
51991
|
-
wbytes(d, b + 4, c < 0 ? -c - 2 : c);
|
|
51992
|
-
wbytes(d, b + 8, f.size);
|
|
51993
|
-
}
|
|
51994
|
-
wbytes(d, b + 12, fl2);
|
|
51995
|
-
wbytes(d, b + 14, exl), b += 16;
|
|
51996
|
-
if (ce != null) {
|
|
51997
|
-
wbytes(d, b, col);
|
|
51998
|
-
wbytes(d, b + 6, f.attrs);
|
|
51999
|
-
wbytes(d, b + 10, ce), b += 14;
|
|
52000
|
-
}
|
|
52001
|
-
d.set(fn, b);
|
|
52002
|
-
b += fl2;
|
|
52003
|
-
if (exl) {
|
|
52004
|
-
for (var k in ex) {
|
|
52005
|
-
var exf = ex[k], l = exf.length;
|
|
52006
|
-
wbytes(d, b, +k);
|
|
52007
|
-
wbytes(d, b + 2, l);
|
|
52008
|
-
d.set(exf, b + 4), b += 4 + l;
|
|
52009
|
-
}
|
|
52010
|
-
}
|
|
52011
|
-
if (col)
|
|
52012
|
-
d.set(co, b), b += col;
|
|
52013
|
-
return b;
|
|
52014
|
-
}, "wzh");
|
|
52015
|
-
var wzf = /* @__PURE__ */ __name(function(o, b, c, d, e) {
|
|
52016
|
-
wbytes(o, b, 101010256);
|
|
52017
|
-
wbytes(o, b + 8, c);
|
|
52018
|
-
wbytes(o, b + 10, c);
|
|
52019
|
-
wbytes(o, b + 12, d);
|
|
52020
|
-
wbytes(o, b + 16, e);
|
|
52021
|
-
}, "wzf");
|
|
52022
|
-
var ZipPassThrough = /* @__PURE__ */ (function() {
|
|
52023
|
-
function ZipPassThrough2(filename) {
|
|
52024
|
-
this.filename = filename;
|
|
52025
|
-
this.c = crc();
|
|
52026
|
-
this.size = 0;
|
|
52027
|
-
this.compression = 0;
|
|
52028
|
-
}
|
|
52029
|
-
__name(ZipPassThrough2, "ZipPassThrough");
|
|
52030
|
-
ZipPassThrough2.prototype.process = function(chunk, final) {
|
|
52031
|
-
this.ondata(null, chunk, final);
|
|
52032
|
-
};
|
|
52033
|
-
ZipPassThrough2.prototype.push = function(chunk, final) {
|
|
52034
|
-
if (!this.ondata)
|
|
52035
|
-
err(5);
|
|
52036
|
-
this.c.p(chunk);
|
|
52037
|
-
this.size += chunk.length;
|
|
52038
|
-
if (final)
|
|
52039
|
-
this.crc = this.c.d();
|
|
52040
|
-
this.process(chunk, final || false);
|
|
52041
|
-
};
|
|
52042
|
-
return ZipPassThrough2;
|
|
52043
|
-
})();
|
|
52044
|
-
var ZipDeflate = /* @__PURE__ */ (function() {
|
|
52045
|
-
function ZipDeflate2(filename, opts) {
|
|
52046
|
-
var _this = this;
|
|
52047
|
-
if (!opts)
|
|
52048
|
-
opts = {};
|
|
52049
|
-
ZipPassThrough.call(this, filename);
|
|
52050
|
-
this.d = new Deflate(opts, function(dat, final) {
|
|
52051
|
-
_this.ondata(null, dat, final);
|
|
52052
|
-
});
|
|
52053
|
-
this.compression = 8;
|
|
52054
|
-
this.flag = dbf(opts.level);
|
|
52055
|
-
}
|
|
52056
|
-
__name(ZipDeflate2, "ZipDeflate");
|
|
52057
|
-
ZipDeflate2.prototype.process = function(chunk, final) {
|
|
52058
|
-
try {
|
|
52059
|
-
this.d.push(chunk, final);
|
|
52060
|
-
} catch (e) {
|
|
52061
|
-
this.ondata(e, null, final);
|
|
52062
|
-
}
|
|
52063
|
-
};
|
|
52064
|
-
ZipDeflate2.prototype.push = function(chunk, final) {
|
|
52065
|
-
ZipPassThrough.prototype.push.call(this, chunk, final);
|
|
52066
|
-
};
|
|
52067
|
-
return ZipDeflate2;
|
|
52068
|
-
})();
|
|
52069
|
-
var Zip = /* @__PURE__ */ (function() {
|
|
52070
|
-
function Zip2(cb) {
|
|
52071
|
-
this.ondata = cb;
|
|
52072
|
-
this.u = [];
|
|
52073
|
-
this.d = 1;
|
|
52074
|
-
}
|
|
52075
|
-
__name(Zip2, "Zip");
|
|
52076
|
-
Zip2.prototype.add = function(file2) {
|
|
52077
|
-
var _this = this;
|
|
52078
|
-
if (!this.ondata)
|
|
52079
|
-
err(5);
|
|
52080
|
-
if (this.d & 2)
|
|
52081
|
-
this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);
|
|
52082
|
-
else {
|
|
52083
|
-
var f = strToU8(file2.filename), fl_1 = f.length;
|
|
52084
|
-
var com = file2.comment, o = com && strToU8(com);
|
|
52085
|
-
var u = fl_1 != file2.filename.length || o && com.length != o.length;
|
|
52086
|
-
var hl_1 = fl_1 + exfl(file2.extra) + 30;
|
|
52087
|
-
if (fl_1 > 65535)
|
|
52088
|
-
this.ondata(err(11, 0, 1), null, false);
|
|
52089
|
-
var header = new u8(hl_1);
|
|
52090
|
-
wzh(header, 0, file2, f, u, -1);
|
|
52091
|
-
var chks_1 = [header];
|
|
52092
|
-
var pAll_1 = /* @__PURE__ */ __name(function() {
|
|
52093
|
-
for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {
|
|
52094
|
-
var chk = chks_2[_i];
|
|
52095
|
-
_this.ondata(null, chk, false);
|
|
52096
|
-
}
|
|
52097
|
-
chks_1 = [];
|
|
52098
|
-
}, "pAll_1");
|
|
52099
|
-
var tr_1 = this.d;
|
|
52100
|
-
this.d = 0;
|
|
52101
|
-
var ind_1 = this.u.length;
|
|
52102
|
-
var uf_1 = mrg(file2, {
|
|
52103
|
-
f,
|
|
52104
|
-
u,
|
|
52105
|
-
o,
|
|
52106
|
-
t: /* @__PURE__ */ __name(function() {
|
|
52107
|
-
if (file2.terminate)
|
|
52108
|
-
file2.terminate();
|
|
52109
|
-
}, "t"),
|
|
52110
|
-
r: /* @__PURE__ */ __name(function() {
|
|
52111
|
-
pAll_1();
|
|
52112
|
-
if (tr_1) {
|
|
52113
|
-
var nxt = _this.u[ind_1 + 1];
|
|
52114
|
-
if (nxt)
|
|
52115
|
-
nxt.r();
|
|
52116
|
-
else
|
|
52117
|
-
_this.d = 1;
|
|
52118
|
-
}
|
|
52119
|
-
tr_1 = 1;
|
|
52120
|
-
}, "r")
|
|
52121
|
-
});
|
|
52122
|
-
var cl_1 = 0;
|
|
52123
|
-
file2.ondata = function(err2, dat, final) {
|
|
52124
|
-
if (err2) {
|
|
52125
|
-
_this.ondata(err2, dat, final);
|
|
52126
|
-
_this.terminate();
|
|
52127
|
-
} else {
|
|
52128
|
-
cl_1 += dat.length;
|
|
52129
|
-
chks_1.push(dat);
|
|
52130
|
-
if (final) {
|
|
52131
|
-
var dd = new u8(16);
|
|
52132
|
-
wbytes(dd, 0, 134695760);
|
|
52133
|
-
wbytes(dd, 4, file2.crc);
|
|
52134
|
-
wbytes(dd, 8, cl_1);
|
|
52135
|
-
wbytes(dd, 12, file2.size);
|
|
52136
|
-
chks_1.push(dd);
|
|
52137
|
-
uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file2.crc, uf_1.size = file2.size;
|
|
52138
|
-
if (tr_1)
|
|
52139
|
-
uf_1.r();
|
|
52140
|
-
tr_1 = 1;
|
|
52141
|
-
} else if (tr_1)
|
|
52142
|
-
pAll_1();
|
|
52143
|
-
}
|
|
52144
|
-
};
|
|
52145
|
-
this.u.push(uf_1);
|
|
52146
|
-
}
|
|
52147
|
-
};
|
|
52148
|
-
Zip2.prototype.end = function() {
|
|
52149
|
-
var _this = this;
|
|
52150
|
-
if (this.d & 2) {
|
|
52151
|
-
this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);
|
|
52152
|
-
return;
|
|
52153
|
-
}
|
|
52154
|
-
if (this.d)
|
|
52155
|
-
this.e();
|
|
52156
|
-
else
|
|
52157
|
-
this.u.push({
|
|
52158
|
-
r: /* @__PURE__ */ __name(function() {
|
|
52159
|
-
if (!(_this.d & 1))
|
|
52160
|
-
return;
|
|
52161
|
-
_this.u.splice(-1, 1);
|
|
52162
|
-
_this.e();
|
|
52163
|
-
}, "r"),
|
|
52164
|
-
t: /* @__PURE__ */ __name(function() {
|
|
52165
|
-
}, "t")
|
|
52166
|
-
});
|
|
52167
|
-
this.d = 3;
|
|
52168
|
-
};
|
|
52169
|
-
Zip2.prototype.e = function() {
|
|
52170
|
-
var bt = 0, l = 0, tl = 0;
|
|
52171
|
-
for (var _i = 0, _a4 = this.u; _i < _a4.length; _i++) {
|
|
52172
|
-
var f = _a4[_i];
|
|
52173
|
-
tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);
|
|
52174
|
-
}
|
|
52175
|
-
var out = new u8(tl + 22);
|
|
52176
|
-
for (var _b2 = 0, _c = this.u; _b2 < _c.length; _b2++) {
|
|
52177
|
-
var f = _c[_b2];
|
|
52178
|
-
wzh(out, bt, f, f.f, f.u, -f.c - 2, l, f.o);
|
|
52179
|
-
bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;
|
|
52180
|
-
}
|
|
52181
|
-
wzf(out, bt, this.u.length, tl, l);
|
|
52182
|
-
this.ondata(null, out, true);
|
|
52183
|
-
this.d = 2;
|
|
52184
|
-
};
|
|
52185
|
-
Zip2.prototype.terminate = function() {
|
|
52186
|
-
for (var _i = 0, _a4 = this.u; _i < _a4.length; _i++) {
|
|
52187
|
-
var f = _a4[_i];
|
|
52188
|
-
f.t();
|
|
52189
|
-
}
|
|
52190
|
-
this.d = 2;
|
|
52191
|
-
};
|
|
52192
|
-
return Zip2;
|
|
52193
|
-
})();
|
|
52194
52140
|
|
|
52195
52141
|
// src/backups/dump.ts
|
|
52196
52142
|
var DUMP_FORMAT = "orqevio-backup";
|
|
@@ -52355,6 +52301,31 @@ function readHeader(data) {
|
|
|
52355
52301
|
return header;
|
|
52356
52302
|
}
|
|
52357
52303
|
__name(readHeader, "readHeader");
|
|
52304
|
+
function fileNames(data) {
|
|
52305
|
+
const names = /* @__PURE__ */ new Map();
|
|
52306
|
+
let reading = null;
|
|
52307
|
+
for (const line of readLines(data)) {
|
|
52308
|
+
if (Array.isArray(line)) {
|
|
52309
|
+
const key = reading ? line[reading.key] : void 0;
|
|
52310
|
+
if (!reading || typeof key !== "string") continue;
|
|
52311
|
+
if (reading.table === "attachments") {
|
|
52312
|
+
const name2 = line[reading.name];
|
|
52313
|
+
if (typeof name2 === "string") names.set(key, name2);
|
|
52314
|
+
} else {
|
|
52315
|
+
try {
|
|
52316
|
+
const row = JSON.parse(String(line[reading.data]));
|
|
52317
|
+
if (typeof row.filename === "string") names.set(key, row.filename);
|
|
52318
|
+
} catch {
|
|
52319
|
+
}
|
|
52320
|
+
}
|
|
52321
|
+
} else if (line && typeof line === "object" && "table" in line) {
|
|
52322
|
+
const { table, columns: columns2 } = line;
|
|
52323
|
+
reading = (table === "attachments" || table === "trash_rows") && columns2.includes("storage_key") ? { table, key: columns2.indexOf("storage_key"), name: columns2.indexOf("filename"), data: columns2.indexOf("data") } : null;
|
|
52324
|
+
} else if (line && typeof line === "object" && "end" in line) break;
|
|
52325
|
+
}
|
|
52326
|
+
return names;
|
|
52327
|
+
}
|
|
52328
|
+
__name(fileNames, "fileNames");
|
|
52358
52329
|
var DumpError = class extends Error {
|
|
52359
52330
|
constructor(code) {
|
|
52360
52331
|
super(`This backup can't be restored: ${code}`);
|
|
@@ -52465,7 +52436,33 @@ import { createReadStream, createWriteStream } from "node:fs";
|
|
|
52465
52436
|
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
52466
52437
|
import path from "node:path";
|
|
52467
52438
|
import { Readable, Writable } from "node:stream";
|
|
52439
|
+
function problemOf(error62, at) {
|
|
52440
|
+
const code = error62?.code;
|
|
52441
|
+
const uid = typeof process !== "undefined" ? process.getuid?.() : void 0;
|
|
52442
|
+
const gid = typeof process !== "undefined" ? process.getgid?.() : void 0;
|
|
52443
|
+
return {
|
|
52444
|
+
code: code === "EACCES" || code === "EPERM" ? "access" : code === "EROFS" ? "readonly" : code === "ENOSPC" || code === "EDQUOT" ? "full" : "other",
|
|
52445
|
+
path: at,
|
|
52446
|
+
user: uid === void 0 ? null : `${uid}:${gid ?? uid}`,
|
|
52447
|
+
detail: error62 instanceof Error ? error62.message : String(error62)
|
|
52448
|
+
};
|
|
52449
|
+
}
|
|
52450
|
+
__name(problemOf, "problemOf");
|
|
52451
|
+
function describeBackupProblem(problem, root = problem.path) {
|
|
52452
|
+
switch (problem.code) {
|
|
52453
|
+
case "access":
|
|
52454
|
+
return `Backups can't be made: this server's user (${problem.user ?? "unknown"}) can't read or write ${problem.path}. Give the backups folder back to that user: mounted from the host, with sudo chown -R ${problem.user ?? "100:101"} on it; inside the volume (backups copied in with docker compose cp are left to root), with docker compose run --rm --user root app chown -R orqevio:orqevio ${root}.`;
|
|
52455
|
+
case "readonly":
|
|
52456
|
+
return `Backups can't be made: ${problem.path} is read-only.`;
|
|
52457
|
+
case "full":
|
|
52458
|
+
return `Backups can't be made: the disk of ${problem.path} is full.`;
|
|
52459
|
+
default:
|
|
52460
|
+
return `Backups can't be made in ${problem.path}: ${problem.detail}`;
|
|
52461
|
+
}
|
|
52462
|
+
}
|
|
52463
|
+
__name(describeBackupProblem, "describeBackupProblem");
|
|
52468
52464
|
var BACKUP_KEY = /^(?:snapshots\/[0-9A-Za-z-]+\/(?:data\.ndjson\.gz|manifest\.json)|files\/[0-9a-f-]{36}\/[0-9a-f-]{36})$/;
|
|
52465
|
+
var PROBE_BYTES = new Uint8Array(64 * 1024);
|
|
52469
52466
|
async function emptyBackupStore(store) {
|
|
52470
52467
|
const snapshots = (await store.list("snapshots/")).map((k) => k.key);
|
|
52471
52468
|
const manifests = snapshots.filter((key) => key.endsWith("/manifest.json"));
|
|
@@ -52475,6 +52472,35 @@ async function emptyBackupStore(store) {
|
|
|
52475
52472
|
}
|
|
52476
52473
|
__name(emptyBackupStore, "emptyBackupStore");
|
|
52477
52474
|
|
|
52475
|
+
// src/lib/measure.ts
|
|
52476
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
52477
|
+
function measure() {
|
|
52478
|
+
const hash2 = createHash3("sha256");
|
|
52479
|
+
let bytes = 0;
|
|
52480
|
+
let digest = null;
|
|
52481
|
+
const stream = new TransformStream({
|
|
52482
|
+
transform(chunk, controller) {
|
|
52483
|
+
hash2.update(chunk);
|
|
52484
|
+
bytes += chunk.length;
|
|
52485
|
+
controller.enqueue(chunk);
|
|
52486
|
+
},
|
|
52487
|
+
flush() {
|
|
52488
|
+
digest = hash2.digest("hex");
|
|
52489
|
+
}
|
|
52490
|
+
});
|
|
52491
|
+
return {
|
|
52492
|
+
stream,
|
|
52493
|
+
/** What went through, once all of it has. */
|
|
52494
|
+
result: /* @__PURE__ */ __name(() => {
|
|
52495
|
+
if (digest === null) throw new Error("Not measured yet");
|
|
52496
|
+
return { bytes, sha256: digest };
|
|
52497
|
+
}, "result"),
|
|
52498
|
+
/** How much has gone through so far, and whether that was all (the stream ended). */
|
|
52499
|
+
sofar: /* @__PURE__ */ __name(() => ({ bytes, ended: digest !== null }), "sofar")
|
|
52500
|
+
};
|
|
52501
|
+
}
|
|
52502
|
+
__name(measure, "measure");
|
|
52503
|
+
|
|
52478
52504
|
// src/services/backups.ts
|
|
52479
52505
|
var KEEP_BACKUPS = 7;
|
|
52480
52506
|
var DUE_AFTER_MS = 23.5 * 60 * 60 * 1e3;
|
|
@@ -52514,15 +52540,34 @@ var BackupService = class {
|
|
|
52514
52540
|
await this.accounts.requireOwner(actor);
|
|
52515
52541
|
if (!this.enabled) return { where: null, keep: KEEP_BACKUPS, backups: [] };
|
|
52516
52542
|
const migration = currentMigration(this.deps.sql);
|
|
52517
|
-
|
|
52518
|
-
|
|
52543
|
+
let problem = await this.deps.backups.check?.() ?? null;
|
|
52544
|
+
let manifests = [];
|
|
52545
|
+
try {
|
|
52546
|
+
manifests = await this.manifests();
|
|
52547
|
+
} catch (error62) {
|
|
52548
|
+
const failed = this.folderError(error62);
|
|
52549
|
+
if (!(failed instanceof AppError) || failed.code !== "backup_folder") throw error62;
|
|
52550
|
+
problem ??= failed.details;
|
|
52551
|
+
}
|
|
52552
|
+
return { where: this.deps.backups.where, keep: KEEP_BACKUPS, backups: manifests.map((m) => this.toDTO(m, migration)), problem };
|
|
52519
52553
|
}
|
|
52520
52554
|
/** "Back up now", from Settings. */
|
|
52521
52555
|
async createNow(actor) {
|
|
52522
52556
|
await this.accounts.requireOwner(actor);
|
|
52523
52557
|
if (!this.enabled) throw backupsOff();
|
|
52524
|
-
|
|
52525
|
-
|
|
52558
|
+
try {
|
|
52559
|
+
const manifest = await this.exclusive(() => this.create("manual"));
|
|
52560
|
+
return this.toDTO(manifest, currentMigration(this.deps.sql));
|
|
52561
|
+
} catch (error62) {
|
|
52562
|
+
throw this.folderError(error62);
|
|
52563
|
+
}
|
|
52564
|
+
}
|
|
52565
|
+
/** A backup that failed because of where it goes (not the app's, read-only, full, not a folder): said as such. */
|
|
52566
|
+
folderError(error62) {
|
|
52567
|
+
if (error62 instanceof AppError || !this.deps.backups.failedHere?.(error62)) return error62;
|
|
52568
|
+
const where = this.deps.backups.where.name;
|
|
52569
|
+
const problem = problemOf(error62, error62.path ?? where);
|
|
52570
|
+
return new AppError(409, "backup_folder", describeBackupProblem(problem, where), problem);
|
|
52526
52571
|
}
|
|
52527
52572
|
/** Hourly: makes the daily backup once the last one is a day old, for a copy that is claimed and in use. */
|
|
52528
52573
|
async runIfDue(now = Date.now()) {
|
|
@@ -52589,33 +52634,37 @@ var BackupService = class {
|
|
|
52589
52634
|
const id3 = now.toISOString().replace(/[:.]/g, "-");
|
|
52590
52635
|
const dump = writeDump(sql2, VERSION, now);
|
|
52591
52636
|
const listed = /* @__PURE__ */ new Map();
|
|
52592
|
-
for (const [key, size] of sql2.rows(
|
|
52593
|
-
"SELECT storage_key, size FROM attachments UNION ALL SELECT storage_key, json_extract(data, '$.size') FROM trash_rows WHERE storage_key IS NOT NULL"
|
|
52637
|
+
for (const [key, size, name2] of sql2.rows(
|
|
52638
|
+
"SELECT storage_key, size, filename FROM attachments UNION ALL SELECT storage_key, json_extract(data, '$.size'), json_extract(data, '$.filename') FROM trash_rows WHERE storage_key IS NOT NULL"
|
|
52594
52639
|
)) {
|
|
52595
|
-
if (typeof key === "string") listed.set(key, Number(size ?? 0));
|
|
52640
|
+
if (typeof key === "string") listed.set(key, { size: Number(size ?? 0), name: typeof name2 === "string" ? name2 : key });
|
|
52596
52641
|
}
|
|
52597
52642
|
const migration = currentMigration(sql2);
|
|
52598
52643
|
const count2 = /* @__PURE__ */ __name((table) => dump.counts[table] ?? 0, "count");
|
|
52599
52644
|
await store.write(dataKey(id3), dump.data);
|
|
52600
|
-
const stored = new
|
|
52645
|
+
const stored = new Map((await store.list("files/")).map((f) => [f.key, f.size]));
|
|
52646
|
+
const known = await this.knownHashes();
|
|
52601
52647
|
const files = [];
|
|
52602
52648
|
const missingFiles = [];
|
|
52603
|
-
for (const [key, size] of listed) {
|
|
52604
|
-
if (
|
|
52605
|
-
|
|
52606
|
-
|
|
52607
|
-
|
|
52608
|
-
|
|
52609
|
-
|
|
52610
|
-
|
|
52611
|
-
await store.writeStream(fileKey(key), body, size);
|
|
52612
|
-
} catch (error62) {
|
|
52613
|
-
console.error(`[backups] could not copy ${key}`, error62);
|
|
52649
|
+
for (const [key, { size, name: name2 }] of listed) {
|
|
52650
|
+
if (stored.get(fileKey(key)) === size) {
|
|
52651
|
+
files.push({ key, size, sha256: known.get(key), name: name2 });
|
|
52652
|
+
continue;
|
|
52653
|
+
}
|
|
52654
|
+
try {
|
|
52655
|
+
const body = await this.deps.storage.stream(key);
|
|
52656
|
+
if (!body) {
|
|
52614
52657
|
missingFiles.push(key);
|
|
52615
52658
|
continue;
|
|
52616
52659
|
}
|
|
52660
|
+
const measured = measure();
|
|
52661
|
+
await store.writeStream(fileKey(key), body.pipeThrough(measured.stream), size);
|
|
52662
|
+
files.push({ key, size, sha256: measured.result().sha256, name: name2 });
|
|
52663
|
+
} catch (error62) {
|
|
52664
|
+
if (store.failedHere?.(error62)) throw error62;
|
|
52665
|
+
console.error(`[backups] could not copy ${key}`, error62);
|
|
52666
|
+
missingFiles.push(key);
|
|
52617
52667
|
}
|
|
52618
|
-
files.push({ key, size });
|
|
52619
52668
|
}
|
|
52620
52669
|
const manifest = {
|
|
52621
52670
|
format: DUMP_FORMAT,
|
|
@@ -52640,18 +52689,25 @@ var BackupService = class {
|
|
|
52640
52689
|
missingFiles
|
|
52641
52690
|
};
|
|
52642
52691
|
await store.write(manifestKey(id3), new TextEncoder().encode(JSON.stringify(manifest)));
|
|
52643
|
-
if (prune) await this.prune(now.getTime());
|
|
52692
|
+
if (prune) await this.prune(now.getTime()).catch((error62) => console.error("[backups] prune failed", error62));
|
|
52644
52693
|
return manifest;
|
|
52645
52694
|
}
|
|
52695
|
+
/** What each kept attachment was, as the backups that say it do: a kept file never changes. */
|
|
52696
|
+
async knownHashes(manifests) {
|
|
52697
|
+
const known = /* @__PURE__ */ new Map();
|
|
52698
|
+
for (const m of manifests ?? await this.manifests()) for (const f of m.files) if (f.sha256 && !known.has(f.key)) known.set(f.key, f.sha256);
|
|
52699
|
+
return known;
|
|
52700
|
+
}
|
|
52646
52701
|
/**
|
|
52647
|
-
* Keeps the KEEP_BACKUPS newest daily
|
|
52648
|
-
*
|
|
52702
|
+
* Keeps the KEEP_BACKUPS newest daily backups, as many of those made by hand (which never push
|
|
52703
|
+
* out a daily one) and the newest one made before a restore; removes the rest, the unfinished
|
|
52704
|
+
* ones and what interrupted writes left, then the attachments none of those kept lists.
|
|
52649
52705
|
*/
|
|
52650
52706
|
async prune(now) {
|
|
52651
52707
|
const store = this.deps.backups;
|
|
52652
52708
|
const manifests = await this.manifests();
|
|
52653
|
-
const
|
|
52654
|
-
const kept = [...
|
|
52709
|
+
const newest = /* @__PURE__ */ __name((kind, count2) => manifests.filter((m) => m.kind === kind).slice(0, count2), "newest");
|
|
52710
|
+
const kept = [...newest("daily", KEEP_BACKUPS), ...newest("manual", KEEP_BACKUPS), ...newest("before-restore", 1)];
|
|
52655
52711
|
const keptIds = new Set(kept.map((m) => m.id));
|
|
52656
52712
|
const listed = await store.list("snapshots/");
|
|
52657
52713
|
const withManifest = new Set(manifests.map((m) => m.id));
|
|
@@ -52668,25 +52724,32 @@ var BackupService = class {
|
|
|
52668
52724
|
const needed = new Set(kept.flatMap((m) => m.files.map((f) => fileKey(f.key))));
|
|
52669
52725
|
const unused = (await store.list("files/")).map((f) => f.key).filter((key) => !needed.has(key));
|
|
52670
52726
|
if (unused.length) await store.delete(unused);
|
|
52727
|
+
await store.removeLeftovers?.(now - UNFINISHED_AFTER_MS);
|
|
52671
52728
|
}
|
|
52672
52729
|
/**
|
|
52673
|
-
* Puts a backup back in place of everything. First
|
|
52674
|
-
*
|
|
52675
|
-
* the database, in one transaction. The access key in use now
|
|
52676
|
-
* session ends, and the person who restored it gets a new one.
|
|
52677
|
-
* revoked, and the vault key version only goes up (see
|
|
52730
|
+
* Puts a backup back in place of everything. First the attachments it lists that the copy no
|
|
52731
|
+
* longer has, each checked as it is put back; then a backup of the copy as it is now, kept
|
|
52732
|
+
* apart from the daily ones; then the database, in one transaction. The access key in use now
|
|
52733
|
+
* still opens the copy, every session ends, and the person who restored it gets a new one.
|
|
52734
|
+
* Agents' accesses revoked since stay revoked, and the vault key version only goes up (see
|
|
52735
|
+
* backups/kept.ts).
|
|
52678
52736
|
*/
|
|
52679
52737
|
async restore(actor, id3, input2, userAgent) {
|
|
52680
52738
|
await this.accounts.requireOwner(actor);
|
|
52681
|
-
const { accessKey } = parse3(restoreBackupInput, input2);
|
|
52739
|
+
const { accessKey, leaveOut } = parse3(restoreBackupInput, input2);
|
|
52682
52740
|
if (!this.enabled) throw backupsOff();
|
|
52683
52741
|
if (!/^[0-9A-Za-z-]+$/.test(id3)) throw notFound("Backup");
|
|
52684
52742
|
const owner = await this.accounts.verifyAccessKey(actor.userId, accessKey);
|
|
52685
52743
|
return this.exclusive(async () => {
|
|
52686
52744
|
const store = this.deps.backups;
|
|
52687
52745
|
const sql2 = this.deps.sql;
|
|
52688
|
-
const
|
|
52689
|
-
|
|
52746
|
+
const manifests = await this.manifests().catch((error62) => {
|
|
52747
|
+
throw this.folderError(error62);
|
|
52748
|
+
});
|
|
52749
|
+
const manifest = manifests.find((m) => m.id === id3);
|
|
52750
|
+
const data = manifest && await store.read(dataKey(id3)).catch((error62) => {
|
|
52751
|
+
throw this.folderError(error62);
|
|
52752
|
+
});
|
|
52690
52753
|
if (!manifest || !data) throw notFound("Backup");
|
|
52691
52754
|
if (data.length !== manifest.data.bytes || await sha2563(data) !== manifest.data.sha256) {
|
|
52692
52755
|
throw new AppError(422, "backup_damaged", "This backup is damaged: its data is not what it was when it was made");
|
|
@@ -52698,15 +52761,76 @@ var BackupService = class {
|
|
|
52698
52761
|
} catch (error62) {
|
|
52699
52762
|
throw this.dumpError(error62);
|
|
52700
52763
|
}
|
|
52701
|
-
|
|
52764
|
+
const names = manifest.files.some((f) => !f.name) ? fileNames(data) : /* @__PURE__ */ new Map();
|
|
52765
|
+
const named = /* @__PURE__ */ __name((file2, reason) => ({ key: file2.key, name: file2.name ?? names.get(file2.key) ?? file2.key, reason }), "named");
|
|
52766
|
+
const agreed = new Set(leaveOut);
|
|
52767
|
+
const damaged = [];
|
|
52768
|
+
const refuseUnlessAgreed = /* @__PURE__ */ __name(() => {
|
|
52769
|
+
if (damaged.some((f) => !agreed.has(f.key))) {
|
|
52770
|
+
throw new AppError(422, "backup_files_damaged", "Some attachments of this backup are damaged or gone: restore it without them, or keep this copy as it is", { files: damaged });
|
|
52771
|
+
}
|
|
52772
|
+
}, "refuseUnlessAgreed");
|
|
52773
|
+
const stored = new Map(
|
|
52774
|
+
(await store.list("files/").catch((error62) => {
|
|
52775
|
+
throw this.folderError(error62);
|
|
52776
|
+
})).map((f) => [f.key, f.size])
|
|
52777
|
+
);
|
|
52778
|
+
const wanted = [];
|
|
52779
|
+
for (const file2 of manifest.files) {
|
|
52780
|
+
if (await this.deps.storage.exists(file2.key)) continue;
|
|
52781
|
+
const size = stored.get(fileKey(file2.key));
|
|
52782
|
+
if (size === void 0) damaged.push(named(file2, "missing"));
|
|
52783
|
+
else if (size !== file2.size) damaged.push(named(file2, "size"));
|
|
52784
|
+
else wanted.push(file2);
|
|
52785
|
+
}
|
|
52786
|
+
refuseUnlessAgreed();
|
|
52787
|
+
const known = await this.knownHashes(manifests);
|
|
52788
|
+
const copied = [];
|
|
52789
|
+
const spoilt = [];
|
|
52790
|
+
const undo = /* @__PURE__ */ __name(() => Promise.all(copied.map((key) => this.deps.storage.delete(key).catch(() => {
|
|
52791
|
+
}))), "undo");
|
|
52702
52792
|
let ownerId = "";
|
|
52703
|
-
|
|
52793
|
+
let before = null;
|
|
52794
|
+
await this.attachments.close("restoring");
|
|
52704
52795
|
try {
|
|
52705
|
-
for (const file2 of
|
|
52706
|
-
|
|
52707
|
-
|
|
52708
|
-
|
|
52796
|
+
for (const file2 of wanted) {
|
|
52797
|
+
const body = await store.stream(fileKey(file2.key)).catch((error62) => {
|
|
52798
|
+
throw this.folderError(error62);
|
|
52799
|
+
});
|
|
52800
|
+
if (!body) {
|
|
52801
|
+
damaged.push(named(file2, "missing"));
|
|
52802
|
+
continue;
|
|
52803
|
+
}
|
|
52804
|
+
const measured = measure();
|
|
52805
|
+
try {
|
|
52806
|
+
await this.deps.storage.put(file2.key, body.pipeThrough(measured.stream), file2.size, "application/octet-stream");
|
|
52807
|
+
} catch (error62) {
|
|
52808
|
+
const read = measured.sofar();
|
|
52809
|
+
if (!(error62 instanceof LengthMismatchError) && !(read.ended ? read.bytes !== file2.size : read.bytes > file2.size)) throw this.folderError(error62);
|
|
52810
|
+
damaged.push(named(file2, "size"));
|
|
52811
|
+
continue;
|
|
52812
|
+
}
|
|
52813
|
+
const expected = file2.sha256 ?? known.get(file2.key);
|
|
52814
|
+
if (expected && measured.result().sha256 !== expected) {
|
|
52815
|
+
await this.deps.storage.delete(file2.key);
|
|
52816
|
+
damaged.push(named(file2, "changed"));
|
|
52817
|
+
spoilt.push(fileKey(file2.key));
|
|
52818
|
+
continue;
|
|
52819
|
+
}
|
|
52820
|
+
copied.push(file2.key);
|
|
52709
52821
|
}
|
|
52822
|
+
if (spoilt.length) await store.delete(spoilt).catch((error62) => console.error("[backups] could not remove damaged kept attachments", error62));
|
|
52823
|
+
refuseUnlessAgreed();
|
|
52824
|
+
before = await this.create("before-restore", { prune: false }).catch((error62) => {
|
|
52825
|
+
throw this.folderError(error62);
|
|
52826
|
+
});
|
|
52827
|
+
} catch (error62) {
|
|
52828
|
+
await undo();
|
|
52829
|
+
this.attachments.reopen();
|
|
52830
|
+
throw error62;
|
|
52831
|
+
}
|
|
52832
|
+
let restored = false;
|
|
52833
|
+
try {
|
|
52710
52834
|
const kept = readKept(sql2);
|
|
52711
52835
|
try {
|
|
52712
52836
|
restoreDump(sql2, data, {
|
|
@@ -52720,10 +52844,17 @@ var BackupService = class {
|
|
|
52720
52844
|
applyKept(sql2, kept, ownerId);
|
|
52721
52845
|
}, "before")
|
|
52722
52846
|
});
|
|
52847
|
+
restored = true;
|
|
52723
52848
|
} catch (error62) {
|
|
52724
52849
|
throw this.dumpError(error62);
|
|
52725
52850
|
}
|
|
52726
52851
|
await this.deps.migrate?.();
|
|
52852
|
+
} catch (error62) {
|
|
52853
|
+
if (!restored) {
|
|
52854
|
+
await undo();
|
|
52855
|
+
if (before) await store.delete([manifestKey(before.id), dataKey(before.id)]).catch((e) => console.error("[backups] could not remove the backup made before a failed restore", e));
|
|
52856
|
+
}
|
|
52857
|
+
throw error62;
|
|
52727
52858
|
} finally {
|
|
52728
52859
|
this.attachments.reopen();
|
|
52729
52860
|
await this.prune(Date.now()).catch((error62) => console.error("[backups] prune failed", error62));
|
|
@@ -52731,7 +52862,7 @@ var BackupService = class {
|
|
|
52731
52862
|
this.accounts.forget();
|
|
52732
52863
|
this.oauth.forget();
|
|
52733
52864
|
const session = await this.accounts.startSession(ownerId, userAgent);
|
|
52734
|
-
return { session, restored: this.toDTO(manifest, currentMigration(sql2)) };
|
|
52865
|
+
return { session, restored: this.toDTO(manifest, currentMigration(sql2)), ...damaged.length && { leftOut: damaged } };
|
|
52735
52866
|
});
|
|
52736
52867
|
}
|
|
52737
52868
|
/**
|
|
@@ -52947,62 +53078,68 @@ var CardService = class {
|
|
|
52947
53078
|
async update(actor, cardId, input2) {
|
|
52948
53079
|
const data = parse3(cardUpdateInput, input2);
|
|
52949
53080
|
const card = await this.load(actor, cardId, "tasks:write");
|
|
52950
|
-
const changed =
|
|
52951
|
-
if (changed.length === 0) {
|
|
52952
|
-
const [summary2] = await this.summarize([card]);
|
|
52953
|
-
return summary2;
|
|
52954
|
-
}
|
|
52955
|
-
const updated = this.deps.db.transaction((tx) => {
|
|
53081
|
+
const { row: updated, changed } = this.deps.db.transaction((tx) => {
|
|
52956
53082
|
const prev = tx.select().from(cards).where(eq(cards.id, cardId)).get();
|
|
52957
53083
|
if (!prev) throw notFound("Card");
|
|
53084
|
+
const title = data.title !== void 0 && data.title !== prev.title ? data.title : void 0;
|
|
53085
|
+
const description = data.description !== void 0 && data.description !== prev.description ? data.description : void 0;
|
|
53086
|
+
const due = data.dueAt === void 0 ? void 0 : data.dueAt ? new Date(data.dueAt) : null;
|
|
53087
|
+
const dueChanged = due !== void 0 && (due?.getTime() ?? null) !== (prev.dueAt?.getTime() ?? null);
|
|
53088
|
+
let labels2;
|
|
53089
|
+
if (data.labelIds) {
|
|
53090
|
+
const ids = this.validLabelIds(tx, card.boardId, data.labelIds);
|
|
53091
|
+
const was = tx.select({ id: cardLabels.labelId }).from(cardLabels).where(eq(cardLabels.cardId, cardId)).all().map((l) => l.id);
|
|
53092
|
+
if ([...new Set(ids)].sort().join() !== [...was].sort().join()) labels2 = { ids, was };
|
|
53093
|
+
}
|
|
53094
|
+
const changed2 = [title !== void 0 && "title", description !== void 0 && "description", dueChanged && "dueAt", labels2 && "labelIds"].filter((f) => Boolean(f));
|
|
53095
|
+
if (changed2.length === 0) return { row: prev, changed: changed2 };
|
|
52958
53096
|
const patch = { updatedAt: /* @__PURE__ */ new Date() };
|
|
52959
|
-
if (
|
|
52960
|
-
if (
|
|
52961
|
-
patch.description =
|
|
53097
|
+
if (title !== void 0) patch.title = title;
|
|
53098
|
+
if (description !== void 0) {
|
|
53099
|
+
patch.description = description;
|
|
52962
53100
|
patch.version = sql`${cards.version} + 1`;
|
|
52963
53101
|
}
|
|
52964
|
-
if (
|
|
52965
|
-
const guard =
|
|
53102
|
+
if (dueChanged) patch.dueAt = due;
|
|
53103
|
+
const guard = description !== void 0 && data.baseVersion !== void 0 ? and(eq(cards.id, cardId), eq(cards.version, data.baseVersion)) : eq(cards.id, cardId);
|
|
52966
53104
|
const row = tx.update(cards).set(patch).where(guard).returning().get();
|
|
52967
53105
|
if (!row) {
|
|
52968
53106
|
const latest = tx.select({ version: cards.version }).from(cards).where(eq(cards.id, cardId)).get();
|
|
52969
53107
|
throw conflict("This card was modified since you loaded it", { currentVersion: latest?.version ?? null });
|
|
52970
53108
|
}
|
|
52971
|
-
if (
|
|
52972
|
-
if (
|
|
52973
|
-
if (
|
|
52974
|
-
if (
|
|
52975
|
-
const
|
|
52976
|
-
const was = tx.select({ id: cardLabels.labelId }).from(cardLabels).where(eq(cardLabels.cardId, cardId)).all().map((l) => l.id);
|
|
53109
|
+
if (title !== void 0) this.change(tx, actor, row, { kind: "card.title", before: prev.title, after: row.title });
|
|
53110
|
+
if (description !== void 0) this.change(tx, actor, row, { kind: "card.description", before: prev.description, after: row.description });
|
|
53111
|
+
if (dueChanged) this.change(tx, actor, row, { kind: "card.due", before: prev.dueAt?.toISOString() ?? null, after: row.dueAt?.toISOString() ?? null });
|
|
53112
|
+
if (labels2) {
|
|
53113
|
+
const { ids, was } = labels2;
|
|
52977
53114
|
tx.delete(cardLabels).where(eq(cardLabels.cardId, cardId)).run();
|
|
52978
|
-
if (
|
|
52979
|
-
const added =
|
|
52980
|
-
const removed = was.filter((id3) => !
|
|
52981
|
-
|
|
52982
|
-
|
|
52983
|
-
|
|
52984
|
-
|
|
52985
|
-
|
|
52986
|
-
|
|
52987
|
-
});
|
|
52988
|
-
}
|
|
53115
|
+
if (ids.length) tx.insert(cardLabels).values(ids.map((labelId) => ({ cardId, labelId }))).run();
|
|
53116
|
+
const added = ids.filter((id3) => !was.includes(id3));
|
|
53117
|
+
const removed = was.filter((id3) => !ids.includes(id3));
|
|
53118
|
+
this.change(tx, actor, row, {
|
|
53119
|
+
kind: "card.labels",
|
|
53120
|
+
before: [...was].sort(),
|
|
53121
|
+
after: [...ids].sort(),
|
|
53122
|
+
meta: { added: this.labelNames(tx, added), removed: this.labelNames(tx, removed) }
|
|
53123
|
+
});
|
|
52989
53124
|
}
|
|
52990
|
-
return row;
|
|
53125
|
+
return { row, changed: changed2 };
|
|
52991
53126
|
});
|
|
52992
|
-
|
|
52993
|
-
|
|
52994
|
-
|
|
52995
|
-
|
|
52996
|
-
|
|
52997
|
-
|
|
52998
|
-
|
|
52999
|
-
|
|
53000
|
-
|
|
53001
|
-
|
|
53002
|
-
|
|
53003
|
-
|
|
53004
|
-
|
|
53005
|
-
|
|
53127
|
+
if (changed.length > 0) {
|
|
53128
|
+
await this.activity.record(
|
|
53129
|
+
actor,
|
|
53130
|
+
card.workspaceId,
|
|
53131
|
+
{
|
|
53132
|
+
action: "card.updated",
|
|
53133
|
+
entityType: "card",
|
|
53134
|
+
entityId: cardId,
|
|
53135
|
+
summary: updated.title,
|
|
53136
|
+
meta: { fields: changed.join(",") },
|
|
53137
|
+
coalesce: true
|
|
53138
|
+
},
|
|
53139
|
+
// Only changes to the description carry a version, so an open card refreshes its text only for those.
|
|
53140
|
+
{ boardId: card.boardId, cardId, ...changed.includes("description") ? { version: updated.version } : {} }
|
|
53141
|
+
);
|
|
53142
|
+
}
|
|
53006
53143
|
const [summary] = await this.summarize([updated]);
|
|
53007
53144
|
return summary;
|
|
53008
53145
|
}
|
|
@@ -53457,8 +53594,12 @@ var BoardService = class {
|
|
|
53457
53594
|
async updateLabel(actor, labelId, input2) {
|
|
53458
53595
|
const data = parse3(labelUpdateInput, input2);
|
|
53459
53596
|
const label = await this.loadLabel(actor, labelId);
|
|
53460
|
-
|
|
53461
|
-
|
|
53597
|
+
const patch = {
|
|
53598
|
+
...data.name !== void 0 && data.name !== label.name ? { name: data.name } : {},
|
|
53599
|
+
...data.color !== void 0 && data.color !== label.color ? { color: data.color } : {}
|
|
53600
|
+
};
|
|
53601
|
+
if (Object.keys(patch).length === 0) return toLabelDTO(label);
|
|
53602
|
+
const [row] = await this.deps.db.update(labels).set(patch).where(eq(labels.id, labelId)).returning();
|
|
53462
53603
|
await this.activity.record(
|
|
53463
53604
|
actor,
|
|
53464
53605
|
label.workspaceId,
|
|
@@ -53482,14 +53623,233 @@ var BoardService = class {
|
|
|
53482
53623
|
}
|
|
53483
53624
|
};
|
|
53484
53625
|
|
|
53626
|
+
// src/lib/zip.ts
|
|
53627
|
+
var MAX32 = 4294967295;
|
|
53628
|
+
var MAX16 = 65535;
|
|
53629
|
+
var UTF8 = 2048;
|
|
53630
|
+
var DESCRIPTOR = 8;
|
|
53631
|
+
var ZIP64_EXTRA_MAX = 4 + 3 * 8;
|
|
53632
|
+
var STORED = 0;
|
|
53633
|
+
var DEFLATED = 8;
|
|
53634
|
+
var V20 = 20;
|
|
53635
|
+
var V45 = 45;
|
|
53636
|
+
var ZipWriter = class {
|
|
53637
|
+
/** `write` takes each piece in order; the ZIP waits for it, which is how a slow reader slows it down. */
|
|
53638
|
+
constructor(write, options = {}) {
|
|
53639
|
+
this.write = write;
|
|
53640
|
+
this.options = options;
|
|
53641
|
+
}
|
|
53642
|
+
write;
|
|
53643
|
+
options;
|
|
53644
|
+
static {
|
|
53645
|
+
__name(this, "ZipWriter");
|
|
53646
|
+
}
|
|
53647
|
+
offset = 0;
|
|
53648
|
+
entries = [];
|
|
53649
|
+
encoder = new TextEncoder();
|
|
53650
|
+
/** A text (or any data held in memory), compressed. */
|
|
53651
|
+
async add(name2, data, date5 = /* @__PURE__ */ new Date()) {
|
|
53652
|
+
const compressed = deflateSync(data, { level: 6 });
|
|
53653
|
+
const entry = this.entry(name2, date5, DEFLATED, 0);
|
|
53654
|
+
entry.crc = crc32(data);
|
|
53655
|
+
entry.compressed = compressed.length;
|
|
53656
|
+
entry.size = data.length;
|
|
53657
|
+
entry.zip64 = Boolean(this.options.alwaysZip64) || entry.size >= MAX32 || entry.compressed >= MAX32;
|
|
53658
|
+
await this.put(localHeader(entry));
|
|
53659
|
+
await this.put(compressed);
|
|
53660
|
+
}
|
|
53661
|
+
/**
|
|
53662
|
+
* A file of `size` bytes, read from `body` as it is written: stored as it is (attachments are
|
|
53663
|
+
* mostly compressed already). It must be `size` bytes long, or the ZIP stops there with an error.
|
|
53664
|
+
*/
|
|
53665
|
+
async addStream(name2, size, body, date5 = /* @__PURE__ */ new Date()) {
|
|
53666
|
+
const entry = this.entry(name2, date5, STORED, DESCRIPTOR);
|
|
53667
|
+
entry.zip64 = Boolean(this.options.alwaysZip64) || size >= MAX32;
|
|
53668
|
+
await this.put(localHeader(entry));
|
|
53669
|
+
let crc2 = ~0;
|
|
53670
|
+
let length = 0;
|
|
53671
|
+
const reader = body.getReader();
|
|
53672
|
+
try {
|
|
53673
|
+
for (; ; ) {
|
|
53674
|
+
const { value, done } = await reader.read();
|
|
53675
|
+
if (done) break;
|
|
53676
|
+
length += value.length;
|
|
53677
|
+
if (length > size) throw new Error(`${name2} is longer than its ${size} bytes`);
|
|
53678
|
+
crc2 = crc32Update(crc2, value);
|
|
53679
|
+
await this.put(value);
|
|
53680
|
+
}
|
|
53681
|
+
} catch (error62) {
|
|
53682
|
+
await reader.cancel(error62).catch(() => {
|
|
53683
|
+
});
|
|
53684
|
+
throw error62;
|
|
53685
|
+
} finally {
|
|
53686
|
+
reader.releaseLock();
|
|
53687
|
+
}
|
|
53688
|
+
if (length !== size) throw new Error(`${name2} has ${length} bytes, not ${size}`);
|
|
53689
|
+
entry.crc = ~crc2 >>> 0;
|
|
53690
|
+
entry.compressed = entry.size = length;
|
|
53691
|
+
await this.put(dataDescriptor(entry));
|
|
53692
|
+
}
|
|
53693
|
+
/** The central directory, and the records at the end that say where it is. */
|
|
53694
|
+
async end() {
|
|
53695
|
+
const start = this.offset;
|
|
53696
|
+
for (const entry of this.entries) await this.put(centralHeader(entry, Boolean(this.options.alwaysZip64)));
|
|
53697
|
+
const size = this.offset - start;
|
|
53698
|
+
const count2 = this.entries.length;
|
|
53699
|
+
const zip64 = Boolean(this.options.alwaysZip64) || count2 >= MAX16 || size >= MAX32 || start >= MAX32;
|
|
53700
|
+
if (zip64) {
|
|
53701
|
+
const record2 = this.offset;
|
|
53702
|
+
await this.put(zip64End(count2, size, start));
|
|
53703
|
+
await this.put(zip64Locator(record2));
|
|
53704
|
+
}
|
|
53705
|
+
await this.put(end(zip64 ? MAX16 : count2, zip64 ? MAX32 : size, zip64 ? MAX32 : start));
|
|
53706
|
+
}
|
|
53707
|
+
entry(name2, date5, method, flags) {
|
|
53708
|
+
const bytes = this.encoder.encode(name2);
|
|
53709
|
+
if (bytes.length > MAX16) throw new Error(`The name ${name2.slice(0, 80)}\u2026 is longer than a ZIP holds (65,535 bytes)`);
|
|
53710
|
+
const fits = 9 + bytes.length + ZIP64_EXTRA_MAX <= MAX16;
|
|
53711
|
+
const unicode = bytes.length === name2.length || !fits ? new Uint8Array(0) : new Record(9 + bytes.length).u16(28789).u16(5 + bytes.length).raw(new Uint8Array([1])).u32(crc32(bytes)).raw(bytes).bytes;
|
|
53712
|
+
const entry = { name: bytes, flags: UTF8 | flags, method, ...dos(date5), crc: 0, compressed: 0, size: 0, offset: this.offset, zip64: false, unicode };
|
|
53713
|
+
this.entries.push(entry);
|
|
53714
|
+
return entry;
|
|
53715
|
+
}
|
|
53716
|
+
async put(chunk) {
|
|
53717
|
+
if (!chunk.length) return;
|
|
53718
|
+
this.offset += chunk.length;
|
|
53719
|
+
await this.write(chunk);
|
|
53720
|
+
}
|
|
53721
|
+
};
|
|
53722
|
+
function dos(date5) {
|
|
53723
|
+
const year = Math.max(1980, date5.getFullYear());
|
|
53724
|
+
return {
|
|
53725
|
+
time: date5.getHours() << 11 | date5.getMinutes() << 5 | date5.getSeconds() >> 1,
|
|
53726
|
+
date: year - 1980 << 9 | date5.getMonth() + 1 << 5 | date5.getDate()
|
|
53727
|
+
};
|
|
53728
|
+
}
|
|
53729
|
+
__name(dos, "dos");
|
|
53730
|
+
var Record = class {
|
|
53731
|
+
static {
|
|
53732
|
+
__name(this, "Record");
|
|
53733
|
+
}
|
|
53734
|
+
bytes;
|
|
53735
|
+
view;
|
|
53736
|
+
at = 0;
|
|
53737
|
+
constructor(size) {
|
|
53738
|
+
this.bytes = new Uint8Array(size);
|
|
53739
|
+
this.view = new DataView(this.bytes.buffer);
|
|
53740
|
+
}
|
|
53741
|
+
u16(value) {
|
|
53742
|
+
if (value > MAX16) throw new Error(`${value} does not fit in a ZIP field of 2 bytes`);
|
|
53743
|
+
this.view.setUint16(this.at, value, true);
|
|
53744
|
+
this.at += 2;
|
|
53745
|
+
return this;
|
|
53746
|
+
}
|
|
53747
|
+
u32(value) {
|
|
53748
|
+
this.view.setUint32(this.at, value >>> 0, true);
|
|
53749
|
+
this.at += 4;
|
|
53750
|
+
return this;
|
|
53751
|
+
}
|
|
53752
|
+
u64(value) {
|
|
53753
|
+
this.view.setBigUint64(this.at, BigInt(value), true);
|
|
53754
|
+
this.at += 8;
|
|
53755
|
+
return this;
|
|
53756
|
+
}
|
|
53757
|
+
raw(bytes) {
|
|
53758
|
+
this.bytes.set(bytes, this.at);
|
|
53759
|
+
this.at += bytes.length;
|
|
53760
|
+
return this;
|
|
53761
|
+
}
|
|
53762
|
+
};
|
|
53763
|
+
var concat = /* @__PURE__ */ __name((a, b) => {
|
|
53764
|
+
const out = new Uint8Array(a.length + b.length);
|
|
53765
|
+
out.set(a);
|
|
53766
|
+
out.set(b, a.length);
|
|
53767
|
+
return out;
|
|
53768
|
+
}, "concat");
|
|
53769
|
+
function zip64Extra(values) {
|
|
53770
|
+
const record2 = new Record(4 + values.length * 8).u16(1).u16(values.length * 8);
|
|
53771
|
+
for (const value of values) record2.u64(value);
|
|
53772
|
+
return record2.bytes;
|
|
53773
|
+
}
|
|
53774
|
+
__name(zip64Extra, "zip64Extra");
|
|
53775
|
+
function localHeader(entry) {
|
|
53776
|
+
const streamed = (entry.flags & DESCRIPTOR) !== 0;
|
|
53777
|
+
const extra = concat(entry.zip64 ? zip64Extra(streamed ? [0, 0] : [entry.size, entry.compressed]) : new Uint8Array(0), entry.unicode);
|
|
53778
|
+
const record2 = new Record(30 + entry.name.length + extra.length).u32(67324752).u16(entry.zip64 ? V45 : V20).u16(entry.flags).u16(entry.method).u16(entry.time).u16(entry.date).u32(streamed ? 0 : entry.crc);
|
|
53779
|
+
if (entry.zip64) record2.u32(MAX32).u32(MAX32);
|
|
53780
|
+
else record2.u32(streamed ? 0 : entry.compressed).u32(streamed ? 0 : entry.size);
|
|
53781
|
+
return record2.u16(entry.name.length).u16(extra.length).raw(entry.name).raw(extra).bytes;
|
|
53782
|
+
}
|
|
53783
|
+
__name(localHeader, "localHeader");
|
|
53784
|
+
function dataDescriptor(entry) {
|
|
53785
|
+
const record2 = new Record(entry.zip64 ? 24 : 16).u32(134695760).u32(entry.crc);
|
|
53786
|
+
if (entry.zip64) return record2.u64(entry.compressed).u64(entry.size).bytes;
|
|
53787
|
+
return record2.u32(entry.compressed).u32(entry.size).bytes;
|
|
53788
|
+
}
|
|
53789
|
+
__name(dataDescriptor, "dataDescriptor");
|
|
53790
|
+
function centralHeader(entry, always) {
|
|
53791
|
+
const big = /* @__PURE__ */ __name((value) => always || value >= MAX32, "big");
|
|
53792
|
+
const values = [entry.size, entry.compressed, entry.offset].filter(big);
|
|
53793
|
+
const extra = concat(values.length ? zip64Extra(values) : new Uint8Array(0), entry.unicode);
|
|
53794
|
+
const version3 = values.length || entry.zip64 ? V45 : V20;
|
|
53795
|
+
return new Record(46 + entry.name.length + extra.length).u32(33639248).u16(version3).u16(version3).u16(entry.flags).u16(entry.method).u16(entry.time).u16(entry.date).u32(entry.crc).u32(big(entry.compressed) ? MAX32 : entry.compressed).u32(big(entry.size) ? MAX32 : entry.size).u16(entry.name.length).u16(extra.length).u16(0).u16(0).u16(0).u32(0).u32(big(entry.offset) ? MAX32 : entry.offset).raw(entry.name).raw(extra).bytes;
|
|
53796
|
+
}
|
|
53797
|
+
__name(centralHeader, "centralHeader");
|
|
53798
|
+
function zip64End(count2, size, offset) {
|
|
53799
|
+
return new Record(56).u32(101075792).u64(44).u16(V45).u16(V45).u32(0).u32(0).u64(count2).u64(count2).u64(size).u64(offset).bytes;
|
|
53800
|
+
}
|
|
53801
|
+
__name(zip64End, "zip64End");
|
|
53802
|
+
function zip64Locator(record2) {
|
|
53803
|
+
return new Record(20).u32(117853008).u32(0).u64(record2).u32(1).bytes;
|
|
53804
|
+
}
|
|
53805
|
+
__name(zip64Locator, "zip64Locator");
|
|
53806
|
+
function end(count2, size, offset) {
|
|
53807
|
+
return new Record(22).u32(101010256).u16(0).u16(0).u16(count2).u16(count2).u32(size).u32(offset).u16(0).bytes;
|
|
53808
|
+
}
|
|
53809
|
+
__name(end, "end");
|
|
53810
|
+
var TABLES = (() => {
|
|
53811
|
+
const tables = new Int32Array(256 * 8);
|
|
53812
|
+
for (let n = 0; n < 256; n++) {
|
|
53813
|
+
let c = n;
|
|
53814
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
53815
|
+
tables[n] = c;
|
|
53816
|
+
}
|
|
53817
|
+
for (let n = 0; n < 256; n++) {
|
|
53818
|
+
let c = tables[n];
|
|
53819
|
+
for (let t = 1; t < 8; t++) {
|
|
53820
|
+
c = tables[c & 255] ^ c >>> 8;
|
|
53821
|
+
tables[t * 256 + n] = c;
|
|
53822
|
+
}
|
|
53823
|
+
}
|
|
53824
|
+
return tables;
|
|
53825
|
+
})();
|
|
53826
|
+
function crc32Update(crc2, data) {
|
|
53827
|
+
const t = TABLES;
|
|
53828
|
+
let c = crc2;
|
|
53829
|
+
let i2 = 0;
|
|
53830
|
+
const end8 = data.length - data.length % 8;
|
|
53831
|
+
for (; i2 < end8; i2 += 8) {
|
|
53832
|
+
const a = c ^ (data[i2] | data[i2 + 1] << 8 | data[i2 + 2] << 16 | data[i2 + 3] << 24);
|
|
53833
|
+
c = t[1792 + (a & 255)] ^ t[1536 + (a >>> 8 & 255)] ^ t[1280 + (a >>> 16 & 255)] ^ t[1024 + (a >>> 24)] ^ t[768 + data[i2 + 4]] ^ t[512 + data[i2 + 5]] ^ t[256 + data[i2 + 6]] ^ t[data[i2 + 7]];
|
|
53834
|
+
}
|
|
53835
|
+
for (; i2 < data.length; i2++) c = t[(c ^ data[i2]) & 255] ^ c >>> 8;
|
|
53836
|
+
return c;
|
|
53837
|
+
}
|
|
53838
|
+
__name(crc32Update, "crc32Update");
|
|
53839
|
+
function crc32(data) {
|
|
53840
|
+
return ~crc32Update(~0, data) >>> 0;
|
|
53841
|
+
}
|
|
53842
|
+
__name(crc32, "crc32");
|
|
53843
|
+
|
|
53485
53844
|
// src/services/export.ts
|
|
53486
53845
|
var EXPORT_FORMAT = "orqevio-export";
|
|
53487
53846
|
var UNSAFE2 = /[\u0000-\u001f\u007f<>:"/\\|?*]/g;
|
|
53488
53847
|
var NAME_BYTES = 150;
|
|
53489
53848
|
var utf8 = new TextEncoder();
|
|
53490
53849
|
var DEVICE = /^(?:con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³]|conin\$|conout\$)(?=\.|$)/i;
|
|
53850
|
+
var INVISIBLE = /(?!\u200D)[\p{Cf}\u115F\u1160\u3164\uFFA0]/gu;
|
|
53491
53851
|
function cleanName2(name2, maxBytes) {
|
|
53492
|
-
const clean = name2.replace(UNSAFE2, "-").replace(/\s+/g, " ").trim().replace(/^\.+/, "").replace(/[. ]+$/, "");
|
|
53852
|
+
const clean = name2.normalize("NFC").replace(INVISIBLE, "").replace(UNSAFE2, "-").replace(/\s+/g, " ").trim().replace(/^\.+/, "").replace(/[. ]+$/, "");
|
|
53493
53853
|
let cut = "";
|
|
53494
53854
|
let bytes = 0;
|
|
53495
53855
|
for (const char of clean) {
|
|
@@ -53505,12 +53865,13 @@ function safeName(name2, fallback = "Untitled", maxBytes = NAME_BYTES) {
|
|
|
53505
53865
|
}
|
|
53506
53866
|
__name(safeName, "safeName");
|
|
53507
53867
|
function namer(reserved = []) {
|
|
53508
|
-
const
|
|
53509
|
-
const
|
|
53868
|
+
const same = /* @__PURE__ */ __name((name2) => name2.normalize("NFC").toLowerCase(), "same");
|
|
53869
|
+
const taken = new Set(reserved.map(same));
|
|
53870
|
+
const free = /* @__PURE__ */ __name((stem, endings) => endings.every((ending) => !taken.has(same(`${stem}${ending}`))), "free");
|
|
53510
53871
|
return (name2, endings = [""]) => {
|
|
53511
53872
|
let stem = name2;
|
|
53512
53873
|
for (let n = 2; !free(stem, endings); n++) stem = `${name2} (${n})`;
|
|
53513
|
-
for (const ending of endings) taken.add(`${stem}${ending}
|
|
53874
|
+
for (const ending of endings) taken.add(same(`${stem}${ending}`));
|
|
53514
53875
|
return stem;
|
|
53515
53876
|
};
|
|
53516
53877
|
}
|
|
@@ -53525,10 +53886,12 @@ function linkTo(fromDir, target) {
|
|
|
53525
53886
|
}
|
|
53526
53887
|
__name(linkTo, "linkTo");
|
|
53527
53888
|
var DESTINATION = String.raw`(\]\(\s*<?|^[ \t]{0,3}\[[^\]\n]+\]:[ \t]*<?|\b(?:src|href)=["']?)`;
|
|
53528
|
-
var
|
|
53529
|
-
var ATTACHMENT_LINK = new RegExp(String.raw`${DESTINATION}(?:https?:\/\/[^\s()<>"']+)?\/api\/attachments\/(${
|
|
53530
|
-
var REFERENCE = new RegExp(String.raw`${DESTINATION}\/(doc|card)\/(${
|
|
53889
|
+
var UUID3 = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
53890
|
+
var ATTACHMENT_LINK = new RegExp(String.raw`${DESTINATION}(?:https?:\/\/[^\s()<>"']+)?\/api\/attachments\/(${UUID3})(?=[\s)>"'])`, "gim");
|
|
53891
|
+
var REFERENCE = new RegExp(String.raw`${DESTINATION}\/(doc|card)\/(${UUID3})(?=[\s)>"'])`, "gim");
|
|
53531
53892
|
var FENCE = /^[ \t]*(?:>[ \t]?)*[ \t]*(?:(?:[-*+]|\d{1,9}[.)])[ \t]+)?(`{3,}|~{3,})(.*)$/;
|
|
53893
|
+
var INDENTED = /^(?: {4}|\t)/;
|
|
53894
|
+
var LIST_ITEM = /^[ \t]{0,3}(?:>[ \t]?)*(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
|
|
53532
53895
|
function outsideCode(markdown, change) {
|
|
53533
53896
|
const out = [];
|
|
53534
53897
|
let text2 = "";
|
|
@@ -53537,18 +53900,39 @@ function outsideCode(markdown, change) {
|
|
|
53537
53900
|
text2 = "";
|
|
53538
53901
|
}, "flush");
|
|
53539
53902
|
let fence = null;
|
|
53903
|
+
let indented = false;
|
|
53904
|
+
let blank = true;
|
|
53905
|
+
let inList2 = false;
|
|
53540
53906
|
for (const line of markdown.split(/(?<=\n)/)) {
|
|
53541
|
-
const
|
|
53907
|
+
const bare = line.replace(/\r?\n$/, "");
|
|
53908
|
+
const match2 = FENCE.exec(bare);
|
|
53542
53909
|
if (fence) {
|
|
53543
53910
|
out.push(line);
|
|
53544
53911
|
if (match2 && match2[1][0] === fence.char && match2[1].length >= fence.size && !match2[2].trim()) fence = null;
|
|
53545
|
-
|
|
53912
|
+
continue;
|
|
53913
|
+
}
|
|
53914
|
+
if (indented) {
|
|
53915
|
+
if (!bare.trim() || INDENTED.test(bare)) {
|
|
53916
|
+
out.push(line);
|
|
53917
|
+
blank = !bare.trim();
|
|
53918
|
+
continue;
|
|
53919
|
+
}
|
|
53920
|
+
indented = false;
|
|
53921
|
+
}
|
|
53922
|
+
if (match2 && !(match2[1][0] === "`" && match2[2].includes("`"))) {
|
|
53546
53923
|
flush();
|
|
53547
53924
|
out.push(line);
|
|
53548
53925
|
fence = { char: match2[1][0], size: match2[1].length };
|
|
53926
|
+
} else if (blank && !inList2 && INDENTED.test(bare) && bare.trim()) {
|
|
53927
|
+
flush();
|
|
53928
|
+
out.push(line);
|
|
53929
|
+
indented = true;
|
|
53549
53930
|
} else {
|
|
53550
53931
|
text2 += line;
|
|
53932
|
+
if (LIST_ITEM.test(bare)) inList2 = true;
|
|
53933
|
+
else if (bare.trim() && !/^[ \t]/.test(bare) && blank) inList2 = false;
|
|
53551
53934
|
}
|
|
53935
|
+
blank = !bare.trim();
|
|
53552
53936
|
}
|
|
53553
53937
|
flush();
|
|
53554
53938
|
return out.join("");
|
|
@@ -53593,47 +53977,22 @@ var ExportService = class {
|
|
|
53593
53977
|
const { texts, files, summary } = this.snapshot(actor.userId, root);
|
|
53594
53978
|
const { readable, writable } = new TransformStream();
|
|
53595
53979
|
const writer = writable.getWriter();
|
|
53596
|
-
|
|
53597
|
-
const
|
|
53598
|
-
if (error62) {
|
|
53599
|
-
failed = error62;
|
|
53600
|
-
void writer.abort(error62).catch(() => {
|
|
53601
|
-
});
|
|
53602
|
-
return;
|
|
53603
|
-
}
|
|
53604
|
-
void writer.write(chunk).catch(() => {
|
|
53605
|
-
});
|
|
53606
|
-
if (final) void writer.close().catch(() => {
|
|
53607
|
-
});
|
|
53608
|
-
});
|
|
53609
|
-
const add = /* @__PURE__ */ __name((entry, data) => {
|
|
53610
|
-
zip.add(entry);
|
|
53611
|
-
entry.push(data, true);
|
|
53612
|
-
}, "add");
|
|
53980
|
+
const zip = new ZipWriter((chunk) => writer.write(chunk));
|
|
53981
|
+
const text2 = /* @__PURE__ */ __name((value) => new TextEncoder().encode(value), "text");
|
|
53613
53982
|
void (async () => {
|
|
53614
53983
|
try {
|
|
53615
53984
|
const missing = /* @__PURE__ */ new Set();
|
|
53616
53985
|
for (const file2 of files) if (!await this.deps.storage.exists(file2.storageKey)) missing.add(file2.path);
|
|
53617
53986
|
const about = { format: EXPORT_FORMAT, version: 1, app: VERSION, exportedAt: now.toISOString(), workspaces: summary, missingAttachments: [...missing].map((path2) => path2.slice(root.length + 1)) };
|
|
53618
|
-
add(
|
|
53619
|
-
`));
|
|
53620
|
-
for (const [path2,
|
|
53987
|
+
await zip.add(`${root}/export.json`, text2(`${JSON.stringify(about, null, 2)}
|
|
53988
|
+
`), now);
|
|
53989
|
+
for (const [path2, content] of texts) await zip.add(path2, text2(content), now);
|
|
53621
53990
|
for (const file2 of files) {
|
|
53622
53991
|
const body = missing.has(file2.path) ? null : await this.deps.storage.stream(file2.storageKey);
|
|
53623
|
-
if (
|
|
53624
|
-
const entry = new ZipPassThrough(file2.path);
|
|
53625
|
-
zip.add(entry);
|
|
53626
|
-
const reader = body.getReader();
|
|
53627
|
-
for (; ; ) {
|
|
53628
|
-
await writer.ready;
|
|
53629
|
-
const { value, done } = await reader.read();
|
|
53630
|
-
if (done) break;
|
|
53631
|
-
if (failed) throw failed;
|
|
53632
|
-
entry.push(value);
|
|
53633
|
-
}
|
|
53634
|
-
entry.push(new Uint8Array(0), true);
|
|
53992
|
+
if (body) await zip.addStream(file2.path, file2.size, body, now);
|
|
53635
53993
|
}
|
|
53636
|
-
zip.end();
|
|
53994
|
+
await zip.end();
|
|
53995
|
+
await writer.close();
|
|
53637
53996
|
} catch (error62) {
|
|
53638
53997
|
console.error("[export] failed", error62);
|
|
53639
53998
|
await writer.abort(error62).catch(() => {
|
|
@@ -53770,7 +54129,8 @@ var ExportService = class {
|
|
|
53770
54129
|
due: day(card.dueAt),
|
|
53771
54130
|
archived: card.archivedAt !== null,
|
|
53772
54131
|
checklists: checklistsOf(card.id).map((list) => ({ title: list.title, items: itemsOf(list.id).map((i2) => ({ text: i2.text, done: i2.done })) })),
|
|
53773
|
-
|
|
54132
|
+
// A document linked by hand and mentioned too is one document.
|
|
54133
|
+
documents: [...new Set(linksOf(card.id).map((link) => pagePath.get(link.pageId)))].filter(Boolean),
|
|
53774
54134
|
attachments: filesOf(card.id).map((f) => filePath.get(f.id)),
|
|
53775
54135
|
createdAt: iso(card.createdAt),
|
|
53776
54136
|
updatedAt: iso(card.updatedAt)
|
|
@@ -53934,6 +54294,13 @@ var HistoryService = class {
|
|
|
53934
54294
|
* Forgets the history of what a trash entry holds, as it is deleted for good: the pages and
|
|
53935
54295
|
* cards in it, and the checklists, items and files it took from a card or a page.
|
|
53936
54296
|
*/
|
|
54297
|
+
/** Forgets the history of things deleted for good, by their ids: as the page or card, or what a change is about. */
|
|
54298
|
+
forgetIds(db, ids) {
|
|
54299
|
+
for (let i2 = 0; i2 < ids.length; i2 += 500) {
|
|
54300
|
+
const chunk = ids.slice(i2, i2 + 500);
|
|
54301
|
+
db.delete(history).where(or(inList(history.entityId, chunk), inList(history.subjectId, chunk))).run();
|
|
54302
|
+
}
|
|
54303
|
+
}
|
|
53937
54304
|
forget(db, trashId) {
|
|
53938
54305
|
const ids = sql`SELECT json_extract(data, '$.id') FROM trash_rows WHERE trash_id = ${trashId}`;
|
|
53939
54306
|
db.delete(history).where(or(sql`${history.entityId} IN (${ids})`, sql`${history.subjectId} IN (${ids})`)).run();
|
|
@@ -54044,8 +54411,763 @@ var SearchService = class {
|
|
|
54044
54411
|
}
|
|
54045
54412
|
};
|
|
54046
54413
|
|
|
54414
|
+
// src/services/trash-tree.ts
|
|
54415
|
+
var SEPARATOR = " \u203A ";
|
|
54416
|
+
var NODE_KIND = {
|
|
54417
|
+
projects: "project",
|
|
54418
|
+
boards: "board",
|
|
54419
|
+
board_columns: "column",
|
|
54420
|
+
labels: "label",
|
|
54421
|
+
cards: "card",
|
|
54422
|
+
checklists: "checklist",
|
|
54423
|
+
checklist_items: "checklist_item",
|
|
54424
|
+
pages: "page",
|
|
54425
|
+
attachments: "attachment"
|
|
54426
|
+
};
|
|
54427
|
+
var LIVE_TABLE = {
|
|
54428
|
+
project: "projects",
|
|
54429
|
+
board: "boards",
|
|
54430
|
+
column: "board_columns",
|
|
54431
|
+
label: "labels",
|
|
54432
|
+
card: "cards",
|
|
54433
|
+
checklist: "checklists",
|
|
54434
|
+
checklist_item: "checklist_items",
|
|
54435
|
+
page: "pages",
|
|
54436
|
+
attachment: "attachments"
|
|
54437
|
+
};
|
|
54438
|
+
var LIVE_COLUMNS = {
|
|
54439
|
+
project: sql`id, name`,
|
|
54440
|
+
board: sql`id, name, project_id`,
|
|
54441
|
+
column: sql`id, name, board_id`,
|
|
54442
|
+
label: sql`id, name, board_id`,
|
|
54443
|
+
card: sql`id, title AS name, column_id, board_id`,
|
|
54444
|
+
checklist: sql`id, title AS name, card_id`,
|
|
54445
|
+
checklist_item: sql`id, text AS name, checklist_id`,
|
|
54446
|
+
page: sql`id, title AS name, project_id, parent_id`,
|
|
54447
|
+
attachment: sql`id, filename AS name, card_id, page_id`
|
|
54448
|
+
};
|
|
54449
|
+
var RANK = { project: 0, board: 1, column: 2, label: 3, card: 4, checklist: 5, checklist_item: 6, page: 7, attachment: 8, link: 9 };
|
|
54450
|
+
var COUNTED = {
|
|
54451
|
+
project: "projects",
|
|
54452
|
+
board: "boards",
|
|
54453
|
+
column: "columns",
|
|
54454
|
+
card: "cards",
|
|
54455
|
+
page: "pages",
|
|
54456
|
+
attachment: "attachments",
|
|
54457
|
+
checklist: "checklists",
|
|
54458
|
+
checklist_item: "items",
|
|
54459
|
+
label: "labels",
|
|
54460
|
+
link: "links"
|
|
54461
|
+
};
|
|
54462
|
+
var CHOOSE = {
|
|
54463
|
+
project: [],
|
|
54464
|
+
board: ["project"],
|
|
54465
|
+
column: ["board"],
|
|
54466
|
+
label: ["board"],
|
|
54467
|
+
card: ["column"],
|
|
54468
|
+
checklist: ["card"],
|
|
54469
|
+
checklist_item: ["checklist"],
|
|
54470
|
+
page: ["project", "page"],
|
|
54471
|
+
attachment: ["card", "page"],
|
|
54472
|
+
link: []
|
|
54473
|
+
};
|
|
54474
|
+
var NAMED = /* @__PURE__ */ new Set(["project", "board", "column", "label", "card", "page", "attachment"]);
|
|
54475
|
+
var NAME_MAX = { project: 80, board: 80, column: 60, label: 40, card: 300, page: 200, attachment: 180 };
|
|
54476
|
+
var NAME_COLUMN = { project: "name", board: "name", column: "name", label: "name", card: "title", page: "title", attachment: "filename" };
|
|
54477
|
+
var keyOf = /* @__PURE__ */ __name((kind, id3) => `${kind}:${id3}`, "keyOf");
|
|
54478
|
+
var refKey = /* @__PURE__ */ __name((ref) => keyOf(ref.kind, ref.id), "refKey");
|
|
54479
|
+
var norm = /* @__PURE__ */ __name((name2) => name2.normalize("NFC").trim().toLowerCase(), "norm");
|
|
54480
|
+
var Live = class {
|
|
54481
|
+
constructor(db, workspaceId) {
|
|
54482
|
+
this.db = db;
|
|
54483
|
+
this.workspaceId = workspaceId;
|
|
54484
|
+
}
|
|
54485
|
+
db;
|
|
54486
|
+
workspaceId;
|
|
54487
|
+
static {
|
|
54488
|
+
__name(this, "Live");
|
|
54489
|
+
}
|
|
54490
|
+
rows = /* @__PURE__ */ new Map();
|
|
54491
|
+
/** Looks up many at once: SQLite in a Durable Object takes at most 100 parameters a query. */
|
|
54492
|
+
prefetch(kind, ids) {
|
|
54493
|
+
const unknown2 = [...new Set(ids)].filter((id3) => !this.rows.has(keyOf(kind, id3)));
|
|
54494
|
+
for (let i2 = 0; i2 < unknown2.length; i2 += 500) {
|
|
54495
|
+
const chunk = unknown2.slice(i2, i2 + 500);
|
|
54496
|
+
const found = this.db.all(
|
|
54497
|
+
sql`SELECT ${LIVE_COLUMNS[kind]} FROM ${sql.identifier(LIVE_TABLE[kind])} WHERE workspace_id = ${this.workspaceId} AND ${inList(sql`id`, chunk)}`
|
|
54498
|
+
);
|
|
54499
|
+
const byId = new Map(found.map((row) => [row.id, row]));
|
|
54500
|
+
for (const id3 of chunk) this.rows.set(keyOf(kind, id3), byId.get(id3) ?? null);
|
|
54501
|
+
}
|
|
54502
|
+
}
|
|
54503
|
+
get(kind, id3) {
|
|
54504
|
+
if (!id3) return null;
|
|
54505
|
+
const key = keyOf(kind, id3);
|
|
54506
|
+
if (!this.rows.has(key)) this.prefetch(kind, [id3]);
|
|
54507
|
+
return this.rows.get(key) ?? null;
|
|
54508
|
+
}
|
|
54509
|
+
exists(kind, id3) {
|
|
54510
|
+
return this.get(kind, id3) !== null;
|
|
54511
|
+
}
|
|
54512
|
+
/** The names from the top down to it, its own included: "Project › Board › Column". */
|
|
54513
|
+
path(ref, depth = 0) {
|
|
54514
|
+
if (!ref || depth > 64) return [];
|
|
54515
|
+
const row = this.get(ref.kind, ref.id);
|
|
54516
|
+
if (!row) return [];
|
|
54517
|
+
const name2 = row.name ?? "";
|
|
54518
|
+
const up = /* @__PURE__ */ __name((kind, id3) => id3 ? this.path({ kind, id: id3 }, depth + 1) : [], "up");
|
|
54519
|
+
switch (ref.kind) {
|
|
54520
|
+
case "project":
|
|
54521
|
+
return [name2];
|
|
54522
|
+
case "board":
|
|
54523
|
+
return [...up("project", row.project_id), name2];
|
|
54524
|
+
case "column":
|
|
54525
|
+
case "label":
|
|
54526
|
+
case "card":
|
|
54527
|
+
return [...up("board", row.board_id), name2];
|
|
54528
|
+
case "checklist":
|
|
54529
|
+
return [...up("card", row.card_id), name2];
|
|
54530
|
+
case "checklist_item":
|
|
54531
|
+
return [...up("checklist", row.checklist_id), name2];
|
|
54532
|
+
case "page":
|
|
54533
|
+
return [...row.parent_id ? up("page", row.parent_id) : up("project", row.project_id), name2];
|
|
54534
|
+
case "attachment":
|
|
54535
|
+
return [...row.card_id ? up("card", row.card_id) : up("page", row.page_id), name2];
|
|
54536
|
+
}
|
|
54537
|
+
}
|
|
54538
|
+
/** How many columns a board has now. */
|
|
54539
|
+
columnCount(boardId) {
|
|
54540
|
+
return this.db.get(sql`SELECT count(*) AS total FROM board_columns WHERE board_id = ${boardId}`)?.total ?? 0;
|
|
54541
|
+
}
|
|
54542
|
+
/** The names of what is next to where something of `kind` goes, in `container`. */
|
|
54543
|
+
siblingNames(kind, container) {
|
|
54544
|
+
const names = /* @__PURE__ */ __name((query) => this.db.all(query).map((r) => r.name), "names");
|
|
54545
|
+
const ws = this.workspaceId;
|
|
54546
|
+
switch (kind) {
|
|
54547
|
+
case "project":
|
|
54548
|
+
return names(sql`SELECT name FROM projects WHERE workspace_id = ${ws}`);
|
|
54549
|
+
case "board":
|
|
54550
|
+
return container ? names(sql`SELECT name FROM boards WHERE project_id = ${container.id}`) : [];
|
|
54551
|
+
case "column":
|
|
54552
|
+
return container ? names(sql`SELECT name FROM board_columns WHERE board_id = ${container.id}`) : [];
|
|
54553
|
+
case "label":
|
|
54554
|
+
return container ? names(sql`SELECT name FROM labels WHERE board_id = ${container.id}`) : [];
|
|
54555
|
+
case "card":
|
|
54556
|
+
return container ? names(sql`SELECT title AS name FROM cards WHERE column_id = ${container.id} AND archived_at IS NULL`) : [];
|
|
54557
|
+
case "page":
|
|
54558
|
+
if (!container) return [];
|
|
54559
|
+
return container.kind === "page" ? names(sql`SELECT title AS name FROM pages WHERE parent_id = ${container.id}`) : names(sql`SELECT title AS name FROM pages WHERE project_id = ${container.id} AND parent_id IS NULL`);
|
|
54560
|
+
case "attachment":
|
|
54561
|
+
if (!container) return [];
|
|
54562
|
+
return container.kind === "card" ? names(sql`SELECT filename AS name FROM attachments WHERE card_id = ${container.id}`) : names(sql`SELECT filename AS name FROM attachments WHERE page_id = ${container.id}`);
|
|
54563
|
+
default:
|
|
54564
|
+
return [];
|
|
54565
|
+
}
|
|
54566
|
+
}
|
|
54567
|
+
};
|
|
54568
|
+
function parentRef(kind, row) {
|
|
54569
|
+
const ref = /* @__PURE__ */ __name((k, id3) => id3 ? { kind: k, id: id3 } : null, "ref");
|
|
54570
|
+
switch (kind) {
|
|
54571
|
+
case "project":
|
|
54572
|
+
return null;
|
|
54573
|
+
case "board":
|
|
54574
|
+
return ref("project", row.projectId);
|
|
54575
|
+
case "column":
|
|
54576
|
+
case "label":
|
|
54577
|
+
return ref("board", row.boardId);
|
|
54578
|
+
case "card":
|
|
54579
|
+
return ref("column", row.columnId);
|
|
54580
|
+
case "checklist":
|
|
54581
|
+
return ref("card", row.cardId);
|
|
54582
|
+
case "checklist_item":
|
|
54583
|
+
return ref("checklist", row.checklistId);
|
|
54584
|
+
case "page":
|
|
54585
|
+
return row.parentId ? ref("page", row.parentId) : ref("project", row.projectId);
|
|
54586
|
+
case "attachment":
|
|
54587
|
+
return row.cardId ? ref("card", row.cardId) : ref("page", row.pageId);
|
|
54588
|
+
case "link":
|
|
54589
|
+
return ref("card", row.cardId);
|
|
54590
|
+
}
|
|
54591
|
+
}
|
|
54592
|
+
__name(parentRef, "parentRef");
|
|
54593
|
+
var byPosition = /* @__PURE__ */ __name((a, b) => a === b ? 0 : a === null ? 1 : b === null ? -1 : a < b ? -1 : 1, "byPosition");
|
|
54594
|
+
var byOrder = /* @__PURE__ */ __name((a, b) => RANK[a.kind] - RANK[b.kind] || byPosition(a.row.position, b.row.position) || a.title.localeCompare(b.title) || a.entry.deletedAt.getTime() - b.entry.deletedAt.getTime() || a.row.rowId - b.row.rowId, "byOrder");
|
|
54595
|
+
var TrashIndex = class _TrashIndex {
|
|
54596
|
+
static {
|
|
54597
|
+
__name(this, "TrashIndex");
|
|
54598
|
+
}
|
|
54599
|
+
nodes = /* @__PURE__ */ new Map();
|
|
54600
|
+
/** Rows joining two things (a card's label, a card and a page) that are not things of their own. */
|
|
54601
|
+
relations = [];
|
|
54602
|
+
/** Links made by a page mentioning a card: never put back, they are rebuilt from what pages say. */
|
|
54603
|
+
mentions = [];
|
|
54604
|
+
entries = /* @__PURE__ */ new Map();
|
|
54605
|
+
live;
|
|
54606
|
+
constructor(db, workspaceId) {
|
|
54607
|
+
this.live = new Live(db, workspaceId);
|
|
54608
|
+
}
|
|
54609
|
+
static load(db, workspaceId) {
|
|
54610
|
+
const index3 = new _TrashIndex(db, workspaceId);
|
|
54611
|
+
for (const entry of db.select().from(trash).where(eq(trash.workspaceId, workspaceId)).all()) index3.entries.set(entry.id, entry);
|
|
54612
|
+
const rows = db.all(sql`
|
|
54613
|
+
SELECT r.id AS rowId, r.trash_id AS trashId, r.table_name AS tableName,
|
|
54614
|
+
json_extract(r.data, '$.id') AS id,
|
|
54615
|
+
coalesce(json_extract(r.data, '$.name'), json_extract(r.data, '$.title'), json_extract(r.data, '$.filename'), json_extract(r.data, '$.text')) AS name,
|
|
54616
|
+
json_extract(r.data, '$.project_id') AS projectId,
|
|
54617
|
+
json_extract(r.data, '$.board_id') AS boardId,
|
|
54618
|
+
json_extract(r.data, '$.column_id') AS columnId,
|
|
54619
|
+
json_extract(r.data, '$.card_id') AS cardId,
|
|
54620
|
+
json_extract(r.data, '$.checklist_id') AS checklistId,
|
|
54621
|
+
json_extract(r.data, '$.parent_id') AS parentId,
|
|
54622
|
+
json_extract(r.data, '$.page_id') AS pageId,
|
|
54623
|
+
json_extract(r.data, '$.label_id') AS labelId,
|
|
54624
|
+
json_extract(r.data, '$.size') AS size,
|
|
54625
|
+
json_extract(r.data, '$.source') AS source,
|
|
54626
|
+
json_extract(r.data, '$.position') AS position,
|
|
54627
|
+
r.storage_key AS storageKey
|
|
54628
|
+
FROM trash_rows r JOIN trash t ON t.id = r.trash_id
|
|
54629
|
+
WHERE t.workspace_id = ${workspaceId}
|
|
54630
|
+
ORDER BY r.id`);
|
|
54631
|
+
for (const { tableName, ...rest } of rows) {
|
|
54632
|
+
const row = { ...rest, table: tableName };
|
|
54633
|
+
const entry = index3.entries.get(row.trashId);
|
|
54634
|
+
if (!entry) continue;
|
|
54635
|
+
const kind = NODE_KIND[row.table];
|
|
54636
|
+
if (kind && row.id) {
|
|
54637
|
+
index3.add(kind, row.id, row, entry);
|
|
54638
|
+
} else if (row.table === "card_page_links") {
|
|
54639
|
+
if (row.source === "mention") index3.mentions.push(row);
|
|
54640
|
+
else if (entry.kind === "link" && entry.entityId === `${row.cardId}:${row.pageId}`) index3.add("link", `${row.cardId}:${row.pageId}`, row, entry);
|
|
54641
|
+
else index3.relations.push(row);
|
|
54642
|
+
} else if (row.table === "card_labels") {
|
|
54643
|
+
index3.relations.push(row);
|
|
54644
|
+
}
|
|
54645
|
+
}
|
|
54646
|
+
index3.resolve();
|
|
54647
|
+
return index3;
|
|
54648
|
+
}
|
|
54649
|
+
add(kind, id3, row, entry) {
|
|
54650
|
+
const key = kind === "link" ? `link:${id3}` : keyOf(kind, id3);
|
|
54651
|
+
this.nodes.set(key, {
|
|
54652
|
+
key,
|
|
54653
|
+
kind,
|
|
54654
|
+
id: id3,
|
|
54655
|
+
row,
|
|
54656
|
+
entry,
|
|
54657
|
+
title: row.name ?? "",
|
|
54658
|
+
ref: parentRef(kind, row),
|
|
54659
|
+
parent: null,
|
|
54660
|
+
children: [],
|
|
54661
|
+
place: "original",
|
|
54662
|
+
entryRoot: entry.kind === kind && entry.entityId === id3
|
|
54663
|
+
});
|
|
54664
|
+
}
|
|
54665
|
+
/** Hangs each node from what held it, and says where the rest goes back. */
|
|
54666
|
+
resolve() {
|
|
54667
|
+
const missing = /* @__PURE__ */ new Map();
|
|
54668
|
+
for (const node2 of this.nodes.values()) {
|
|
54669
|
+
if (!node2.ref) continue;
|
|
54670
|
+
const parent = this.nodes.get(refKey(node2.ref));
|
|
54671
|
+
if (parent && parent !== node2) {
|
|
54672
|
+
node2.parent = parent;
|
|
54673
|
+
parent.children.push(node2);
|
|
54674
|
+
node2.place = "trash";
|
|
54675
|
+
} else {
|
|
54676
|
+
const ids = missing.get(node2.ref.kind) ?? /* @__PURE__ */ new Set();
|
|
54677
|
+
ids.add(node2.ref.id);
|
|
54678
|
+
missing.set(node2.ref.kind, ids);
|
|
54679
|
+
}
|
|
54680
|
+
}
|
|
54681
|
+
for (const [kind, ids] of missing) this.live.prefetch(kind, ids);
|
|
54682
|
+
this.live.prefetch("page", [...this.nodes.values()].filter((n) => n.kind === "link" && !this.nodes.has(keyOf("page", n.row.pageId ?? ""))).map((n) => n.row.pageId ?? ""));
|
|
54683
|
+
for (const node2 of this.nodes.values()) {
|
|
54684
|
+
if (node2.ref && !node2.parent) node2.place = this.live.exists(node2.ref.kind, node2.ref.id) ? "original" : "gone";
|
|
54685
|
+
if (node2.kind === "link") node2.title = this.nodes.get(keyOf("page", node2.row.pageId ?? ""))?.title ?? this.live.get("page", node2.row.pageId)?.name ?? "";
|
|
54686
|
+
node2.children.sort(byOrder);
|
|
54687
|
+
}
|
|
54688
|
+
for (const node2 of this.nodes.values()) {
|
|
54689
|
+
const seen = /* @__PURE__ */ new Set();
|
|
54690
|
+
for (let up = node2.parent; up; up = up.parent) {
|
|
54691
|
+
if (seen.has(up) || up === node2) {
|
|
54692
|
+
node2.parent?.children.splice(node2.parent.children.indexOf(node2), 1);
|
|
54693
|
+
node2.parent = null;
|
|
54694
|
+
node2.place = "gone";
|
|
54695
|
+
break;
|
|
54696
|
+
}
|
|
54697
|
+
seen.add(up);
|
|
54698
|
+
}
|
|
54699
|
+
}
|
|
54700
|
+
}
|
|
54701
|
+
node(key) {
|
|
54702
|
+
return this.nodes.get(key);
|
|
54703
|
+
}
|
|
54704
|
+
/** What is at the top: what is not held by anything else in the trash. Newest first. */
|
|
54705
|
+
top() {
|
|
54706
|
+
return [...this.nodes.values()].filter((n) => !n.parent).sort((a, b) => b.entry.deletedAt.getTime() - a.entry.deletedAt.getTime() || b.row.rowId - a.row.rowId);
|
|
54707
|
+
}
|
|
54708
|
+
/** The node and everything below it, each before what it holds. */
|
|
54709
|
+
subtree(node2) {
|
|
54710
|
+
const out = [];
|
|
54711
|
+
const walk = /* @__PURE__ */ __name((n) => {
|
|
54712
|
+
out.push(n);
|
|
54713
|
+
for (const child of n.children) walk(child);
|
|
54714
|
+
}, "walk");
|
|
54715
|
+
walk(node2);
|
|
54716
|
+
return out;
|
|
54717
|
+
}
|
|
54718
|
+
/** What holds it in the trash, top first. */
|
|
54719
|
+
ancestors(node2) {
|
|
54720
|
+
const out = [];
|
|
54721
|
+
for (let up = node2.parent; up; up = up.parent) out.unshift(up);
|
|
54722
|
+
return out;
|
|
54723
|
+
}
|
|
54724
|
+
/** Of `nodes`, those not below another one of them: what is below one comes with it. */
|
|
54725
|
+
outermost(nodes) {
|
|
54726
|
+
const picked = new Set(nodes);
|
|
54727
|
+
return [...picked].filter((node2) => !this.ancestors(node2).some((up) => picked.has(up)));
|
|
54728
|
+
}
|
|
54729
|
+
/**
|
|
54730
|
+
* What deleting `nodes` for good takes: everything below them, and the links to a page that goes
|
|
54731
|
+
* (with what is below them), wherever those wait in the trash.
|
|
54732
|
+
*/
|
|
54733
|
+
goneWith(nodes) {
|
|
54734
|
+
const gone = /* @__PURE__ */ new Map();
|
|
54735
|
+
for (const node2 of nodes) for (const n of this.subtree(node2)) gone.set(n.key, n);
|
|
54736
|
+
for (const n of this.nodes.values()) if (n.kind === "link" && gone.has(`page:${n.row.pageId}`)) for (const m of this.subtree(n)) gone.set(m.key, m);
|
|
54737
|
+
return gone;
|
|
54738
|
+
}
|
|
54739
|
+
/** Everything deleting `nodes` for good takes (see goneWith), by kind, and the size of its files. */
|
|
54740
|
+
totals(nodes) {
|
|
54741
|
+
const all = this.goneWith(nodes);
|
|
54742
|
+
const contents = {};
|
|
54743
|
+
let bytes = 0;
|
|
54744
|
+
for (const n of all.values()) {
|
|
54745
|
+
if (n.kind === "attachment") bytes += Number(n.row.size ?? 0);
|
|
54746
|
+
const counted = COUNTED[n.kind];
|
|
54747
|
+
if (counted) contents[counted] = (contents[counted] ?? 0) + 1;
|
|
54748
|
+
}
|
|
54749
|
+
return { contents, bytes };
|
|
54750
|
+
}
|
|
54751
|
+
/** Whether `node` is `top` or below it. */
|
|
54752
|
+
within(node2, top) {
|
|
54753
|
+
for (let n = node2; n; n = n.parent) if (n === top) return true;
|
|
54754
|
+
return false;
|
|
54755
|
+
}
|
|
54756
|
+
/** Where it goes back, for people: "Project › Board" when that is there; where it was when that is gone. */
|
|
54757
|
+
location(node2) {
|
|
54758
|
+
if (node2.parent) return "";
|
|
54759
|
+
if (node2.place === "gone") return node2.entryRoot ? node2.entry.location : "";
|
|
54760
|
+
return this.live.path(node2.ref).join(SEPARATOR);
|
|
54761
|
+
}
|
|
54762
|
+
dto(node2) {
|
|
54763
|
+
const contents = {};
|
|
54764
|
+
const earlierContents = {};
|
|
54765
|
+
let bytes = 0;
|
|
54766
|
+
for (const n of this.subtree(node2)) {
|
|
54767
|
+
if (n.kind === "attachment") bytes += Number(n.row.size ?? 0);
|
|
54768
|
+
if (n === node2) continue;
|
|
54769
|
+
const counted = COUNTED[n.kind];
|
|
54770
|
+
if (!counted) continue;
|
|
54771
|
+
contents[counted] = (contents[counted] ?? 0) + 1;
|
|
54772
|
+
if (isEarlier(n)) earlierContents[counted] = (earlierContents[counted] ?? 0) + 1;
|
|
54773
|
+
}
|
|
54774
|
+
const entry = node2.entry;
|
|
54775
|
+
return {
|
|
54776
|
+
key: node2.key,
|
|
54777
|
+
kind: node2.kind,
|
|
54778
|
+
entityId: node2.id,
|
|
54779
|
+
title: node2.title,
|
|
54780
|
+
parentKey: node2.parent?.key ?? null,
|
|
54781
|
+
trashId: entry.id,
|
|
54782
|
+
place: node2.place,
|
|
54783
|
+
location: this.location(node2),
|
|
54784
|
+
earlier: isEarlier(node2),
|
|
54785
|
+
contents,
|
|
54786
|
+
earlierContents,
|
|
54787
|
+
bytes,
|
|
54788
|
+
deletedBy: actorOf(entry),
|
|
54789
|
+
deletedAt: entry.deletedAt.toISOString(),
|
|
54790
|
+
expiresAt: entry.expiresAt.toISOString()
|
|
54791
|
+
};
|
|
54792
|
+
}
|
|
54793
|
+
tree(node2) {
|
|
54794
|
+
return { node: this.dto(node2), below: this.subtree(node2).slice(1).map((n) => this.dto(n)), ancestors: this.ancestors(node2).map((n) => ({ key: n.key, kind: n.kind, title: n.title, trashId: n.entry.id })) };
|
|
54795
|
+
}
|
|
54796
|
+
};
|
|
54797
|
+
var isEarlier = /* @__PURE__ */ __name((node2) => node2.parent !== null && node2.parent.entry.id !== node2.entry.id, "isEarlier");
|
|
54798
|
+
var actorOf = /* @__PURE__ */ __name((entry) => ({
|
|
54799
|
+
kind: entry.actorKind,
|
|
54800
|
+
id: (entry.actorKind === "agent" ? entry.actorTokenId : entry.actorUserId) ?? "",
|
|
54801
|
+
name: entry.actorName
|
|
54802
|
+
}), "actorOf");
|
|
54803
|
+
var restoreError = /* @__PURE__ */ __name((code, message, details) => new AppError(409, code, message, details), "restoreError");
|
|
54804
|
+
function remainder(location, prefix) {
|
|
54805
|
+
const start = prefix.join(SEPARATOR);
|
|
54806
|
+
if (start && location.startsWith(start + SEPARATOR)) return location.slice(start.length + SEPARATOR.length);
|
|
54807
|
+
return location.split(SEPARATOR).at(-1) ?? location;
|
|
54808
|
+
}
|
|
54809
|
+
__name(remainder, "remainder");
|
|
54810
|
+
function creatable(index3, node2) {
|
|
54811
|
+
if (!node2.entryRoot) return null;
|
|
54812
|
+
const live = index3.live;
|
|
54813
|
+
const location = node2.entry.location;
|
|
54814
|
+
const made = /* @__PURE__ */ __name((kind, title, where) => [{ kind, id: crypto.randomUUID(), title: title.trim() || "Restored", in: where }], "made");
|
|
54815
|
+
switch (node2.kind) {
|
|
54816
|
+
case "board":
|
|
54817
|
+
return made("project", location, null);
|
|
54818
|
+
case "page":
|
|
54819
|
+
if (!node2.row.parentId) return made("project", location, null);
|
|
54820
|
+
if (!live.exists("project", node2.row.projectId)) return null;
|
|
54821
|
+
return made("page", remainder(location, live.path({ kind: "project", id: node2.row.projectId })), { kind: "project", id: node2.row.projectId });
|
|
54822
|
+
case "card":
|
|
54823
|
+
if (!live.exists("board", node2.row.boardId)) return null;
|
|
54824
|
+
return made("column", remainder(location, live.path({ kind: "board", id: node2.row.boardId })), { kind: "board", id: node2.row.boardId });
|
|
54825
|
+
default:
|
|
54826
|
+
return null;
|
|
54827
|
+
}
|
|
54828
|
+
}
|
|
54829
|
+
__name(creatable, "creatable");
|
|
54830
|
+
function planRestore(index3, input2) {
|
|
54831
|
+
const root = index3.node(input2.key);
|
|
54832
|
+
if (!root) throw notFound("Trash item");
|
|
54833
|
+
const live = index3.live;
|
|
54834
|
+
const subtree = index3.subtree(root);
|
|
54835
|
+
const asked = new Set(input2.exclude);
|
|
54836
|
+
asked.delete(root.key);
|
|
54837
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
54838
|
+
for (const n of subtree) if (asked.has(n.key) || n.parent && excluded.has(n.parent.key)) excluded.add(n.key);
|
|
54839
|
+
const included = subtree.filter((n) => !excluded.has(n.key));
|
|
54840
|
+
let choose = CHOOSE[root.kind];
|
|
54841
|
+
let path2 = [];
|
|
54842
|
+
let create = [];
|
|
54843
|
+
let canRecreate = false;
|
|
54844
|
+
if (root.place === "trash") {
|
|
54845
|
+
path2 = index3.ancestors(root);
|
|
54846
|
+
const top = path2[0];
|
|
54847
|
+
const made = top.place === "gone" ? creatable(index3, top) : [];
|
|
54848
|
+
if (made) {
|
|
54849
|
+
create = made;
|
|
54850
|
+
canRecreate = true;
|
|
54851
|
+
}
|
|
54852
|
+
} else if (root.place === "gone") {
|
|
54853
|
+
const made = creatable(index3, root);
|
|
54854
|
+
if (made) {
|
|
54855
|
+
create = made;
|
|
54856
|
+
canRecreate = true;
|
|
54857
|
+
}
|
|
54858
|
+
}
|
|
54859
|
+
const linkPageGone = root.kind === "link" && !index3.node(keyOf("page", root.row.pageId ?? "")) && !live.exists("page", root.row.pageId);
|
|
54860
|
+
if (linkPageGone) {
|
|
54861
|
+
choose = [];
|
|
54862
|
+
canRecreate = false;
|
|
54863
|
+
}
|
|
54864
|
+
let to = input2.to?.kind ?? (root.place === "original" ? "original" : canRecreate ? "recreate" : null);
|
|
54865
|
+
if (linkPageGone || to === "original" && root.place !== "original") to = null;
|
|
54866
|
+
if (to === "recreate" && root.place === "original") to = "original";
|
|
54867
|
+
if (to === "recreate" && !canRecreate) to = null;
|
|
54868
|
+
let other = null;
|
|
54869
|
+
if (to === "other" && input2.to?.kind === "other") {
|
|
54870
|
+
const chosen = input2.to.parent;
|
|
54871
|
+
if (!choose.includes(chosen.kind) || !live.exists(chosen.kind, chosen.id)) throw restoreError("restore_place_gone", "The place chosen to put it in is not there.");
|
|
54872
|
+
other = chosen;
|
|
54873
|
+
}
|
|
54874
|
+
const recreatePath = path2;
|
|
54875
|
+
const recreateCreate = create;
|
|
54876
|
+
if (to !== "recreate") {
|
|
54877
|
+
path2 = [];
|
|
54878
|
+
create = [];
|
|
54879
|
+
}
|
|
54880
|
+
const comingKeys = /* @__PURE__ */ new Set();
|
|
54881
|
+
const coming = [];
|
|
54882
|
+
const add = /* @__PURE__ */ __name((n) => {
|
|
54883
|
+
if (comingKeys.has(n.key)) return;
|
|
54884
|
+
comingKeys.add(n.key);
|
|
54885
|
+
coming.push(n);
|
|
54886
|
+
}, "add");
|
|
54887
|
+
for (const n of path2) add(n);
|
|
54888
|
+
for (const n of included) add(n);
|
|
54889
|
+
const canInclude = /* @__PURE__ */ __name((n) => !comingKeys.has(n.key) && !index3.within(n, root) && (n.place === "original" || n.parent !== null && comingKeys.has(n.parent.key)), "canInclude");
|
|
54890
|
+
const relationRows = /* @__PURE__ */ __name((keys) => {
|
|
54891
|
+
const linkNodes = [...keys].map((k) => index3.node(k)).filter((n) => n.kind === "link");
|
|
54892
|
+
return [
|
|
54893
|
+
...index3.relations.filter((r) => keys.has(keyOf("card", r.cardId ?? "")) || keys.has(r.table === "card_labels" ? keyOf("label", r.labelId ?? "") : keyOf("page", r.pageId ?? ""))),
|
|
54894
|
+
...linkNodes.map((n) => n.row)
|
|
54895
|
+
];
|
|
54896
|
+
}, "relationRows");
|
|
54897
|
+
const otherEnds = /* @__PURE__ */ new Map();
|
|
54898
|
+
for (const r of relationRows(comingKeys)) {
|
|
54899
|
+
for (const key of [keyOf("card", r.cardId ?? ""), r.table === "card_labels" ? keyOf("label", r.labelId ?? "") : keyOf("page", r.pageId ?? "")]) {
|
|
54900
|
+
const n = index3.node(key);
|
|
54901
|
+
if (n && canInclude(n)) otherEnds.set(key, n);
|
|
54902
|
+
}
|
|
54903
|
+
}
|
|
54904
|
+
const extraRoots = [];
|
|
54905
|
+
for (const key of new Set(input2.include)) {
|
|
54906
|
+
const n = otherEnds.get(key);
|
|
54907
|
+
if (n) extraRoots.push(n);
|
|
54908
|
+
else if (!input2.dryRun) throw restoreError("restore_changed", "Something in the trash changed meanwhile: look again before restoring.");
|
|
54909
|
+
}
|
|
54910
|
+
const own2 = new Set(comingKeys);
|
|
54911
|
+
const extras = [];
|
|
54912
|
+
for (const n of extraRoots) for (const below of index3.subtree(n)) if (!comingKeys.has(below.key)) extras.push(below);
|
|
54913
|
+
for (const n of extras) add(n);
|
|
54914
|
+
const createdById = new Map(create.map((c) => [c.id, c]));
|
|
54915
|
+
const lastMade = create.at(-1);
|
|
54916
|
+
const madeRef = /* @__PURE__ */ __name((c) => ({ kind: c.kind, id: c.id }), "madeRef");
|
|
54917
|
+
const finalBoard = /* @__PURE__ */ new Map();
|
|
54918
|
+
const finalProject = /* @__PURE__ */ new Map();
|
|
54919
|
+
const boardOfColumn = /* @__PURE__ */ __name((id3) => {
|
|
54920
|
+
const made = createdById.get(id3);
|
|
54921
|
+
if (made) return made.in?.id ?? null;
|
|
54922
|
+
return finalBoard.has(keyOf("column", id3)) ? finalBoard.get(keyOf("column", id3)) : live.get("column", id3)?.board_id ?? null;
|
|
54923
|
+
}, "boardOfColumn");
|
|
54924
|
+
const projectOfPage = /* @__PURE__ */ __name((id3) => {
|
|
54925
|
+
const made = createdById.get(id3);
|
|
54926
|
+
if (made) return made.in?.id ?? null;
|
|
54927
|
+
return finalProject.has(keyOf("page", id3)) ? finalProject.get(keyOf("page", id3)) : live.get("page", id3)?.project_id ?? null;
|
|
54928
|
+
}, "projectOfPage");
|
|
54929
|
+
const placement = /* @__PURE__ */ new Map();
|
|
54930
|
+
for (const n of coming) {
|
|
54931
|
+
if (!n.ref) continue;
|
|
54932
|
+
let container = n.ref;
|
|
54933
|
+
let moved = false;
|
|
54934
|
+
if (lastMade && (n === path2[0] || n === root && root.place === "gone")) {
|
|
54935
|
+
container = madeRef(lastMade);
|
|
54936
|
+
moved = true;
|
|
54937
|
+
}
|
|
54938
|
+
if (n === root && other) {
|
|
54939
|
+
container = other;
|
|
54940
|
+
moved = true;
|
|
54941
|
+
}
|
|
54942
|
+
const sets = {};
|
|
54943
|
+
switch (n.kind) {
|
|
54944
|
+
case "board":
|
|
54945
|
+
sets.project_id = container.id;
|
|
54946
|
+
finalProject.set(n.key, container.id);
|
|
54947
|
+
break;
|
|
54948
|
+
case "column":
|
|
54949
|
+
case "label":
|
|
54950
|
+
sets.board_id = container.id;
|
|
54951
|
+
finalBoard.set(n.key, container.id);
|
|
54952
|
+
break;
|
|
54953
|
+
case "card": {
|
|
54954
|
+
const board = boardOfColumn(container.id);
|
|
54955
|
+
sets.column_id = container.id;
|
|
54956
|
+
sets.board_id = board;
|
|
54957
|
+
finalBoard.set(n.key, board);
|
|
54958
|
+
break;
|
|
54959
|
+
}
|
|
54960
|
+
case "checklist":
|
|
54961
|
+
sets.card_id = container.id;
|
|
54962
|
+
break;
|
|
54963
|
+
case "checklist_item":
|
|
54964
|
+
sets.checklist_id = container.id;
|
|
54965
|
+
break;
|
|
54966
|
+
case "page": {
|
|
54967
|
+
const project = container.kind === "page" ? projectOfPage(container.id) : container.id;
|
|
54968
|
+
sets.parent_id = container.kind === "page" ? container.id : null;
|
|
54969
|
+
sets.project_id = project;
|
|
54970
|
+
finalProject.set(n.key, project);
|
|
54971
|
+
break;
|
|
54972
|
+
}
|
|
54973
|
+
case "attachment":
|
|
54974
|
+
sets.card_id = container.kind === "card" ? container.id : null;
|
|
54975
|
+
sets.page_id = container.kind === "page" ? container.id : null;
|
|
54976
|
+
break;
|
|
54977
|
+
}
|
|
54978
|
+
placement.set(n.key, { container, moved, sets });
|
|
54979
|
+
}
|
|
54980
|
+
const state = /* @__PURE__ */ __name((kind, id3) => {
|
|
54981
|
+
if (!id3) return "gone";
|
|
54982
|
+
const key = keyOf(kind, id3);
|
|
54983
|
+
if (comingKeys.has(key)) return "coming";
|
|
54984
|
+
if (index3.node(key)) return "trash";
|
|
54985
|
+
return live.exists(kind, id3) ? "live" : "gone";
|
|
54986
|
+
}, "state");
|
|
54987
|
+
const rows = relationRows(comingKeys);
|
|
54988
|
+
live.prefetch("card", rows.map((r) => r.cardId ?? ""));
|
|
54989
|
+
live.prefetch("label", rows.filter((r) => r.table === "card_labels").map((r) => r.labelId ?? ""));
|
|
54990
|
+
live.prefetch("page", rows.filter((r) => r.table === "card_page_links").map((r) => r.pageId ?? ""));
|
|
54991
|
+
const boardOfCard = /* @__PURE__ */ __name((id3) => finalBoard.has(keyOf("card", id3)) ? finalBoard.get(keyOf("card", id3)) : live.get("card", id3)?.board_id ?? null, "boardOfCard");
|
|
54992
|
+
const boardOfLabel = /* @__PURE__ */ __name((id3) => finalBoard.has(keyOf("label", id3)) ? finalBoard.get(keyOf("label", id3)) : live.get("label", id3)?.board_id ?? null, "boardOfLabel");
|
|
54993
|
+
const titleOf = /* @__PURE__ */ __name((kind, id3) => index3.node(keyOf(kind, id3))?.title ?? live.get(kind, id3)?.name ?? "", "titleOf");
|
|
54994
|
+
const extraKeys = new Set(extraRoots.map((n) => n.key));
|
|
54995
|
+
const reinsert = [];
|
|
54996
|
+
const wait = [];
|
|
54997
|
+
const drop = [];
|
|
54998
|
+
const groups = /* @__PURE__ */ new Map();
|
|
54999
|
+
const note = /* @__PURE__ */ __name((group, first) => {
|
|
55000
|
+
const id3 = `${group.state}|${group.kind}|${group.key ?? group.title}`;
|
|
55001
|
+
const found = groups.get(id3);
|
|
55002
|
+
if (found) found.count++;
|
|
55003
|
+
else groups.set(id3, { ...group, count: 1, first });
|
|
55004
|
+
}, "note");
|
|
55005
|
+
for (const r of rows) {
|
|
55006
|
+
const cardId = r.cardId ?? "";
|
|
55007
|
+
const isLabel = r.table === "card_labels";
|
|
55008
|
+
const otherKind = isLabel ? "label" : "page";
|
|
55009
|
+
const otherId = (isLabel ? r.labelId : r.pageId) ?? "";
|
|
55010
|
+
const ends = [
|
|
55011
|
+
{ kind: "card", id: cardId, state: state("card", cardId) },
|
|
55012
|
+
{ kind: otherKind, id: otherId, state: state(otherKind, otherId) }
|
|
55013
|
+
];
|
|
55014
|
+
const isLinkNode = r.table === "card_page_links" && index3.node(`link:${cardId}:${otherId}`)?.row === r;
|
|
55015
|
+
const near = isLinkNode ? ends[0] : ends.find((e) => own2.has(keyOf(e.kind, e.id))) ?? ends.find((e) => e.state === "coming");
|
|
55016
|
+
if (!near) continue;
|
|
55017
|
+
const far = ends.find((e) => e !== near);
|
|
55018
|
+
const shown = extraKeys.has(keyOf(far.kind, far.id));
|
|
55019
|
+
if (shown) note({ kind: far.kind, title: titleOf(far.kind, far.id), key: keyOf(far.kind, far.id), state: "trash", included: true, canInclude: true }, titleOf(near.kind, near.id));
|
|
55020
|
+
if (far.state === "coming" || far.state === "live") {
|
|
55021
|
+
if (isLabel && boardOfCard(cardId) !== boardOfLabel(otherId)) {
|
|
55022
|
+
drop.push(r);
|
|
55023
|
+
note({ kind: "label", title: titleOf("label", otherId), key: index3.node(keyOf("label", otherId)) ? keyOf("label", otherId) : null, state: "other_board", included: false, canInclude: false }, titleOf("card", cardId));
|
|
55024
|
+
} else if (!isLinkNode) {
|
|
55025
|
+
reinsert.push(r);
|
|
55026
|
+
}
|
|
55027
|
+
} else if (far.state === "trash") {
|
|
55028
|
+
const holder = index3.node(keyOf(far.kind, far.id));
|
|
55029
|
+
if (r.trashId !== holder.entry.id) wait.push({ row: r, trashId: holder.entry.id });
|
|
55030
|
+
note({ kind: far.kind, title: holder.title, key: holder.key, state: "trash", included: false, canInclude: canInclude(holder) }, titleOf(near.kind, near.id));
|
|
55031
|
+
} else {
|
|
55032
|
+
drop.push(r);
|
|
55033
|
+
note({ kind: far.kind, title: "", key: null, state: "gone", included: false, canInclude: false }, titleOf(near.kind, near.id));
|
|
55034
|
+
}
|
|
55035
|
+
}
|
|
55036
|
+
const waitingLinks = new Set([...wait.map((w) => w.row), ...drop].filter((r) => r.table === "card_page_links").map((r) => `link:${r.cardId}:${r.pageId}`));
|
|
55037
|
+
const names = /* @__PURE__ */ new Map();
|
|
55038
|
+
for (const [key, value] of Object.entries(input2.names)) {
|
|
55039
|
+
const n = index3.node(key);
|
|
55040
|
+
if (!n || !comingKeys.has(key) || !NAMED.has(n.kind)) continue;
|
|
55041
|
+
const max2 = NAME_MAX[n.kind] ?? 300;
|
|
55042
|
+
if (value.length > max2) throw badRequest(`A ${n.kind} name has at most ${max2} characters`);
|
|
55043
|
+
const stored = n.kind === "attachment" ? safeFilename(value) : value;
|
|
55044
|
+
if (stored !== n.title) names.set(key, stored);
|
|
55045
|
+
}
|
|
55046
|
+
const keep = new Set(input2.keepNames);
|
|
55047
|
+
const conflicts = [];
|
|
55048
|
+
const madeIds = new Set(create.map((c) => c.id));
|
|
55049
|
+
const containerName = /* @__PURE__ */ __name((ref) => {
|
|
55050
|
+
if (!ref) return "";
|
|
55051
|
+
const made = createdById.get(ref.id);
|
|
55052
|
+
if (made) return made.title;
|
|
55053
|
+
const node2 = comingKeys.has(refKey(ref)) ? index3.node(refKey(ref)) : void 0;
|
|
55054
|
+
if (node2) return names.get(node2.key) ?? node2.title;
|
|
55055
|
+
return live.get(ref.kind, ref.id)?.name ?? "";
|
|
55056
|
+
}, "containerName");
|
|
55057
|
+
const byContainer = /* @__PURE__ */ new Map();
|
|
55058
|
+
for (const n of coming) {
|
|
55059
|
+
if (!NAMED.has(n.kind)) continue;
|
|
55060
|
+
const container = n.kind === "project" ? null : placement.get(n.key)?.container ?? null;
|
|
55061
|
+
const id3 = `${n.kind}@${container ? refKey(container) : "workspace"}`;
|
|
55062
|
+
const group = byContainer.get(id3) ?? { kind: n.kind, container, nodes: [] };
|
|
55063
|
+
group.nodes.push(n);
|
|
55064
|
+
byContainer.set(id3, group);
|
|
55065
|
+
}
|
|
55066
|
+
for (const { kind, container, nodes } of byContainer.values()) {
|
|
55067
|
+
const isLive = container === null || !comingKeys.has(refKey(container)) && !madeIds.has(container.id);
|
|
55068
|
+
const taken = new Set((isLive ? live.siblingNames(kind, container) : []).map(norm).filter(Boolean));
|
|
55069
|
+
const batches = /* @__PURE__ */ new Map();
|
|
55070
|
+
for (const n of nodes) batches.set(n.entry.id, [...batches.get(n.entry.id) ?? [], n]);
|
|
55071
|
+
const order2 = [...batches.values()].sort((a, b) => b[0].entry.deletedAt.getTime() - a[0].entry.deletedAt.getTime() || (a[0].entry.id < b[0].entry.id ? -1 : 1));
|
|
55072
|
+
for (const batch of order2) {
|
|
55073
|
+
for (const n of batch) {
|
|
55074
|
+
const renamed = names.get(n.key);
|
|
55075
|
+
const originalTaken = Boolean(norm(n.title)) && taken.has(norm(n.title));
|
|
55076
|
+
if (!originalTaken && renamed === void 0) continue;
|
|
55077
|
+
const name2 = renamed ?? n.title;
|
|
55078
|
+
conflicts.push({ key: n.key, kind: n.kind, original: n.title, name: name2, where: containerName(container), taken: Boolean(norm(name2)) && taken.has(norm(name2)), kept: keep.has(n.key) });
|
|
55079
|
+
}
|
|
55080
|
+
for (const n of batch) {
|
|
55081
|
+
const name2 = norm(names.get(n.key) ?? n.title);
|
|
55082
|
+
if (name2) taken.add(name2);
|
|
55083
|
+
}
|
|
55084
|
+
}
|
|
55085
|
+
}
|
|
55086
|
+
let location = "";
|
|
55087
|
+
if (to === "original") location = live.path(root.ref).join(SEPARATOR);
|
|
55088
|
+
else if (to === "other") location = live.path(other).join(SEPARATOR);
|
|
55089
|
+
else if (to === "recreate") {
|
|
55090
|
+
const base = create.length ? [...live.path(create[0].in), ...create.map((c) => c.title)] : live.path(path2[0]?.ref ?? null);
|
|
55091
|
+
location = [...base, ...path2.map((n) => names.get(n.key) ?? n.title)].join(SEPARATOR);
|
|
55092
|
+
}
|
|
55093
|
+
const columnsInto = /* @__PURE__ */ new Map();
|
|
55094
|
+
const into = /* @__PURE__ */ __name((boardId) => {
|
|
55095
|
+
if (boardId) columnsInto.set(boardId, (columnsInto.get(boardId) ?? 0) + 1);
|
|
55096
|
+
}, "into");
|
|
55097
|
+
for (const n of coming) if (n.kind === "column") into(placement.get(n.key)?.sets.board_id);
|
|
55098
|
+
for (const c of create) if (c.kind === "column") into(c.in?.id);
|
|
55099
|
+
const limits = [];
|
|
55100
|
+
for (const [boardId, incoming] of columnsInto) {
|
|
55101
|
+
const key = keyOf("board", boardId);
|
|
55102
|
+
const there = comingKeys.has(key) ? 0 : live.columnCount(boardId);
|
|
55103
|
+
if (there + incoming <= MAX_COLUMNS) continue;
|
|
55104
|
+
const board = comingKeys.has(key) ? names.get(key) ?? index3.node(key)?.title ?? "" : live.get("board", boardId)?.name ?? "";
|
|
55105
|
+
limits.push({ board, count: there + incoming, max: MAX_COLUMNS });
|
|
55106
|
+
}
|
|
55107
|
+
const missing = [];
|
|
55108
|
+
if (to === null) missing.push("place");
|
|
55109
|
+
if (limits.length) missing.push("columns");
|
|
55110
|
+
if (conflicts.some((c) => c.taken && !c.kept)) missing.push("names");
|
|
55111
|
+
return {
|
|
55112
|
+
root,
|
|
55113
|
+
to,
|
|
55114
|
+
subtree,
|
|
55115
|
+
excluded,
|
|
55116
|
+
path: path2,
|
|
55117
|
+
create,
|
|
55118
|
+
recreatePath,
|
|
55119
|
+
recreateCreate,
|
|
55120
|
+
extras,
|
|
55121
|
+
coming: coming.filter((n) => !waitingLinks.has(n.key)),
|
|
55122
|
+
comingKeys,
|
|
55123
|
+
placement,
|
|
55124
|
+
names,
|
|
55125
|
+
conflicts,
|
|
55126
|
+
reinsert,
|
|
55127
|
+
wait,
|
|
55128
|
+
drop,
|
|
55129
|
+
mentions: index3.mentions.filter((r) => comingKeys.has(keyOf("card", r.cardId ?? "")) || comingKeys.has(keyOf("page", r.pageId ?? ""))),
|
|
55130
|
+
relations: [...groups.values()],
|
|
55131
|
+
canRecreate,
|
|
55132
|
+
choose,
|
|
55133
|
+
location,
|
|
55134
|
+
limits,
|
|
55135
|
+
missing
|
|
55136
|
+
};
|
|
55137
|
+
}
|
|
55138
|
+
__name(planRestore, "planRestore");
|
|
55139
|
+
function planDTO(index3, plan) {
|
|
55140
|
+
const { root } = plan;
|
|
55141
|
+
return {
|
|
55142
|
+
node: index3.dto(root),
|
|
55143
|
+
nodes: plan.subtree.map((n) => ({
|
|
55144
|
+
key: n.key,
|
|
55145
|
+
parentKey: n === root ? null : n.parent?.key ?? null,
|
|
55146
|
+
kind: n.kind,
|
|
55147
|
+
title: n.title,
|
|
55148
|
+
earlier: n !== root && isEarlier(n),
|
|
55149
|
+
included: !plan.excluded.has(n.key)
|
|
55150
|
+
})),
|
|
55151
|
+
where: {
|
|
55152
|
+
place: root.place,
|
|
55153
|
+
to: plan.to,
|
|
55154
|
+
path: plan.recreatePath.map((n) => ({ key: n.key, kind: n.kind, title: plan.names.get(n.key) ?? n.title })),
|
|
55155
|
+
create: plan.recreateCreate.map((c) => ({ kind: c.kind, title: c.title })),
|
|
55156
|
+
canRecreate: plan.canRecreate,
|
|
55157
|
+
choose: plan.choose,
|
|
55158
|
+
location: plan.location
|
|
55159
|
+
},
|
|
55160
|
+
conflicts: plan.conflicts,
|
|
55161
|
+
relations: plan.relations,
|
|
55162
|
+
limits: plan.limits,
|
|
55163
|
+
ready: plan.missing.length === 0,
|
|
55164
|
+
missing: plan.missing
|
|
55165
|
+
};
|
|
55166
|
+
}
|
|
55167
|
+
__name(planDTO, "planDTO");
|
|
55168
|
+
|
|
54047
55169
|
// src/services/trash.ts
|
|
54048
|
-
var
|
|
55170
|
+
var TABLES2 = {
|
|
54049
55171
|
projects,
|
|
54050
55172
|
boards,
|
|
54051
55173
|
board_columns: columns,
|
|
@@ -54058,7 +55180,7 @@ var TABLES = {
|
|
|
54058
55180
|
card_page_links: cardPageLinks,
|
|
54059
55181
|
attachments
|
|
54060
55182
|
};
|
|
54061
|
-
var ORDER = Object.keys(
|
|
55183
|
+
var ORDER = Object.keys(TABLES2);
|
|
54062
55184
|
var ROOT_TABLE = {
|
|
54063
55185
|
project: "projects",
|
|
54064
55186
|
board: "boards",
|
|
@@ -54071,7 +55193,7 @@ var ROOT_TABLE = {
|
|
|
54071
55193
|
checklist_item: "checklist_items",
|
|
54072
55194
|
link: "card_page_links"
|
|
54073
55195
|
};
|
|
54074
|
-
var
|
|
55196
|
+
var COUNTED2 = {
|
|
54075
55197
|
boards: "boards",
|
|
54076
55198
|
board_columns: "columns",
|
|
54077
55199
|
cards: "cards",
|
|
@@ -54082,7 +55204,7 @@ var COUNTED = {
|
|
|
54082
55204
|
labels: "labels"
|
|
54083
55205
|
};
|
|
54084
55206
|
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
54085
|
-
var
|
|
55207
|
+
var SEPARATOR2 = " \u203A ";
|
|
54086
55208
|
var Snapshot = class {
|
|
54087
55209
|
constructor(db) {
|
|
54088
55210
|
this.db = db;
|
|
@@ -54125,7 +55247,6 @@ var Snapshot = class {
|
|
|
54125
55247
|
return this.rows.map((row, i2) => ({ row, i: i2 })).sort((a, b) => ORDER.indexOf(a.row.table) - ORDER.indexOf(b.row.table) || a.i - b.i).map((x2) => x2.row);
|
|
54126
55248
|
}
|
|
54127
55249
|
};
|
|
54128
|
-
var restoreError = /* @__PURE__ */ __name((code, message, details) => new AppError(409, code, message, details), "restoreError");
|
|
54129
55250
|
var TrashService = class {
|
|
54130
55251
|
constructor(deps, access, activity2, history2) {
|
|
54131
55252
|
this.deps = deps;
|
|
@@ -54185,7 +55306,7 @@ var TrashService = class {
|
|
|
54185
55306
|
for (const { table, data } of rows) {
|
|
54186
55307
|
if (table === "attachments") bytes += Number(data.size ?? 0);
|
|
54187
55308
|
if (data === root.data) continue;
|
|
54188
|
-
const counted =
|
|
55309
|
+
const counted = COUNTED2[table];
|
|
54189
55310
|
if (counted) contents[counted] = (contents[counted] ?? 0) + 1;
|
|
54190
55311
|
}
|
|
54191
55312
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -54214,7 +55335,7 @@ var TrashService = class {
|
|
|
54214
55335
|
capture(db, snapshot, target) {
|
|
54215
55336
|
const one = /* @__PURE__ */ __name((table, id3) => db.get(sql`SELECT * FROM ${sql.identifier(table)} WHERE id = ${id3}`), "one");
|
|
54216
55337
|
const name2 = /* @__PURE__ */ __name((query) => db.get(query)?.name ?? "", "name");
|
|
54217
|
-
const path2 = /* @__PURE__ */ __name((...parts) => parts.filter(Boolean).join(
|
|
55338
|
+
const path2 = /* @__PURE__ */ __name((...parts) => parts.filter(Boolean).join(SEPARATOR2), "path");
|
|
54218
55339
|
const boardPath = /* @__PURE__ */ __name((boardId) => path2(name2(sql`SELECT p.name FROM boards b JOIN projects p ON p.id = b.project_id WHERE b.id = ${boardId}`), name2(sql`SELECT name FROM boards WHERE id = ${boardId}`)), "boardPath");
|
|
54219
55340
|
const cardPath = /* @__PURE__ */ __name((cardId) => {
|
|
54220
55341
|
const card = db.get(sql`SELECT board_id, column_id, title FROM cards WHERE id = ${cardId}`);
|
|
@@ -54316,17 +55437,29 @@ var TrashService = class {
|
|
|
54316
55437
|
db.delete(cardPageLinks).where(and(eq(cardPageLinks.cardId, target.cardId), eq(cardPageLinks.pageId, target.pageId), eq(cardPageLinks.source, "manual"))).run();
|
|
54317
55438
|
return;
|
|
54318
55439
|
default: {
|
|
54319
|
-
const table =
|
|
55440
|
+
const table = TABLES2[ROOT_TABLE[target.kind]];
|
|
54320
55441
|
db.delete(table).where(eq(table.id, target.id)).run();
|
|
54321
55442
|
}
|
|
54322
55443
|
}
|
|
54323
55444
|
}
|
|
54324
55445
|
// ── People's side: listing, restoring, deleting for good ─────
|
|
55446
|
+
/** What is at the top of the trash: what isn't held by anything else in it. Newest first. */
|
|
54325
55447
|
async list(actor, workspaceId) {
|
|
54326
55448
|
this.access.requireUser(actor);
|
|
54327
55449
|
await this.access.workspace(actor, workspaceId);
|
|
54328
|
-
const
|
|
54329
|
-
return
|
|
55450
|
+
const index3 = TrashIndex.load(this.deps.db, workspaceId);
|
|
55451
|
+
return index3.top().map((node2) => index3.dto(node2));
|
|
55452
|
+
}
|
|
55453
|
+
/**
|
|
55454
|
+
* One thing in the trash, with everything below it and what holds it there; null when it is
|
|
55455
|
+
* not in the trash (any more): asking is how the app finds out.
|
|
55456
|
+
*/
|
|
55457
|
+
async tree(actor, workspaceId, key) {
|
|
55458
|
+
this.access.requireUser(actor);
|
|
55459
|
+
await this.access.workspace(actor, workspaceId);
|
|
55460
|
+
const index3 = TrashIndex.load(this.deps.db, workspaceId);
|
|
55461
|
+
const node2 = index3.node(key);
|
|
55462
|
+
return node2 ? index3.tree(node2) : null;
|
|
54330
55463
|
}
|
|
54331
55464
|
async load(actor, trashId) {
|
|
54332
55465
|
this.access.requireUser(actor);
|
|
@@ -54335,159 +55468,329 @@ var TrashService = class {
|
|
|
54335
55468
|
await this.access.workspace(actor, entry.workspaceId);
|
|
54336
55469
|
return entry;
|
|
54337
55470
|
}
|
|
54338
|
-
/**
|
|
55471
|
+
/**
|
|
55472
|
+
* Restores something with everything below it but what is left out, where the person says.
|
|
55473
|
+
* With `dryRun`, only says what that would do. Without it, it does exactly that, worked out
|
|
55474
|
+
* again in the same transaction: if anything is still to decide (where, or names already
|
|
55475
|
+
* used there), nothing is done and the plan says what.
|
|
55476
|
+
*/
|
|
55477
|
+
async restoreItem(actor, workspaceId, body) {
|
|
55478
|
+
this.access.requireUser(actor);
|
|
55479
|
+
await this.access.workspace(actor, workspaceId);
|
|
55480
|
+
const input2 = parse3(trashRestoreInput, body);
|
|
55481
|
+
if (input2.dryRun) {
|
|
55482
|
+
const index3 = TrashIndex.load(this.deps.db, workspaceId);
|
|
55483
|
+
return planDTO(index3, planRestore(index3, input2));
|
|
55484
|
+
}
|
|
55485
|
+
const done = this.deps.db.transaction((tx) => {
|
|
55486
|
+
const index3 = TrashIndex.load(tx, workspaceId);
|
|
55487
|
+
const plan = planRestore(index3, input2);
|
|
55488
|
+
if (plan.missing.length) throw new AppError(409, "restore_incomplete", "Say where it goes back, and what to do with names already used there, first.", planDTO(index3, plan));
|
|
55489
|
+
return this.apply(tx, actor, workspaceId, plan);
|
|
55490
|
+
});
|
|
55491
|
+
await this.announce(actor, workspaceId, done);
|
|
55492
|
+
return done.result;
|
|
55493
|
+
}
|
|
55494
|
+
/**
|
|
55495
|
+
* Restores several things at once, each as `restoreItem` does, in one transaction: what holds
|
|
55496
|
+
* others first, each planned with what the ones before it brought back already there, so the
|
|
55497
|
+
* plans say what restoring them together does. One that came back with another (below it, or
|
|
55498
|
+
* as the other end of one of its relations) is not asked for twice: `cameWith` says with
|
|
55499
|
+
* which. One no longer in the trash is in `missing`. With `dryRun`, or when anything is still to
|
|
55500
|
+
* decide for any of them, or one went missing, nothing is done and the plans say what.
|
|
55501
|
+
*/
|
|
55502
|
+
async restoreMany(actor, workspaceId, body) {
|
|
55503
|
+
this.access.requireUser(actor);
|
|
55504
|
+
await this.access.workspace(actor, workspaceId);
|
|
55505
|
+
const input2 = parse3(trashRestoreManyInput, body);
|
|
55506
|
+
let answer = { plans: [], ready: false };
|
|
55507
|
+
const asked = new Error("only planned");
|
|
55508
|
+
let done;
|
|
55509
|
+
try {
|
|
55510
|
+
done = this.deps.db.transaction((tx) => {
|
|
55511
|
+
const plans = [];
|
|
55512
|
+
const cameWith = {};
|
|
55513
|
+
const applied = [];
|
|
55514
|
+
const first = TrashIndex.load(tx, workspaceId);
|
|
55515
|
+
const missing = input2.items.filter((item) => !first.node(item.key)).map((item) => item.key);
|
|
55516
|
+
const depth = /* @__PURE__ */ __name((key) => first.ancestors(first.node(key)).length, "depth");
|
|
55517
|
+
const items = input2.items.filter((item) => first.node(item.key)).sort((a, b) => depth(a.key) - depth(b.key));
|
|
55518
|
+
for (const item of items) {
|
|
55519
|
+
const index3 = TrashIndex.load(tx, workspaceId);
|
|
55520
|
+
const back = /* @__PURE__ */ __name((key) => first.node(key) !== void 0 && !index3.node(key), "back");
|
|
55521
|
+
if (back(item.key)) continue;
|
|
55522
|
+
const plan = planRestore(index3, { ...item, include: item.include.filter((key) => !back(key)), dryRun: input2.dryRun });
|
|
55523
|
+
plans.push(planDTO(index3, plan));
|
|
55524
|
+
if (plan.missing.length) continue;
|
|
55525
|
+
applied.push(this.apply(tx, actor, workspaceId, plan));
|
|
55526
|
+
const after = TrashIndex.load(tx, workspaceId);
|
|
55527
|
+
for (const other of items) if (other !== item && index3.node(other.key) && !after.node(other.key)) cameWith[other.key] ??= item.key;
|
|
55528
|
+
}
|
|
55529
|
+
answer = { plans, ready: missing.length === 0 && plans.every((p) => p.ready), ...Object.keys(cameWith).length && { cameWith }, ...missing.length && { missing } };
|
|
55530
|
+
if (input2.dryRun || !answer.ready) throw asked;
|
|
55531
|
+
return applied;
|
|
55532
|
+
});
|
|
55533
|
+
} catch (error62) {
|
|
55534
|
+
if (error62 !== asked) throw error62;
|
|
55535
|
+
if (input2.dryRun) return answer;
|
|
55536
|
+
throw new AppError(409, "restore_incomplete", "Say where each goes back, and what to do with names already used there, first.", answer);
|
|
55537
|
+
}
|
|
55538
|
+
for (const applied of done) await this.announce(actor, workspaceId, applied);
|
|
55539
|
+
return { restored: done.map((a) => a.result) };
|
|
55540
|
+
}
|
|
55541
|
+
/**
|
|
55542
|
+
* Puts back exactly what one deletion took away, where it was: what was deleted before on its
|
|
55543
|
+
* own stays in the trash. It is what undoing a deletion does, so it never goes anywhere else:
|
|
55544
|
+
* when its place is not there, it says so. Names stay as they were.
|
|
55545
|
+
*/
|
|
54339
55546
|
async restore(actor, trashId) {
|
|
54340
55547
|
const entry = await this.load(actor, trashId);
|
|
54341
|
-
const
|
|
54342
|
-
const
|
|
54343
|
-
const
|
|
54344
|
-
|
|
54345
|
-
|
|
54346
|
-
|
|
54347
|
-
|
|
54348
|
-
if (
|
|
54349
|
-
if (
|
|
54350
|
-
|
|
54351
|
-
|
|
54352
|
-
|
|
54353
|
-
|
|
54354
|
-
|
|
54355
|
-
|
|
54356
|
-
|
|
54357
|
-
|
|
54358
|
-
|
|
54359
|
-
|
|
54360
|
-
|
|
54361
|
-
|
|
54362
|
-
|
|
54363
|
-
|
|
54364
|
-
|
|
54365
|
-
|
|
54366
|
-
|
|
54367
|
-
|
|
54368
|
-
|
|
54369
|
-
|
|
54370
|
-
|
|
54371
|
-
|
|
54372
|
-
|
|
54373
|
-
|
|
54374
|
-
|
|
54375
|
-
|
|
54376
|
-
|
|
54377
|
-
|
|
54378
|
-
|
|
55548
|
+
const done = this.deps.db.transaction((tx) => {
|
|
55549
|
+
const results = [];
|
|
55550
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55551
|
+
for (; ; ) {
|
|
55552
|
+
const index3 = TrashIndex.load(tx, entry.workspaceId);
|
|
55553
|
+
const tops = [...index3.nodes.values()].filter((n) => n.entry.id === trashId && (!n.parent || n.parent.entry.id !== trashId)).sort((a, b) => Number(b.entryRoot) - Number(a.entryRoot) || a.row.rowId - b.row.rowId);
|
|
55554
|
+
const top = tops[0];
|
|
55555
|
+
if (!top) break;
|
|
55556
|
+
if (seen.has(top.key)) throw restoreError("restore_changed", "It could not be put back.");
|
|
55557
|
+
seen.add(top.key);
|
|
55558
|
+
if (top.place === "trash") {
|
|
55559
|
+
const holder = top.parent;
|
|
55560
|
+
throw restoreError("restore_place_in_trash", `Restore \u201C${holder.title}\u201D first: what it belongs to is in the trash too.`, { title: holder.title, key: holder.key });
|
|
55561
|
+
}
|
|
55562
|
+
if (top.place === "gone") throw restoreError("restore_place_gone", "What it belonged to no longer exists.");
|
|
55563
|
+
const subtree = index3.subtree(top);
|
|
55564
|
+
const plan = planRestore(index3, {
|
|
55565
|
+
key: top.key,
|
|
55566
|
+
exclude: subtree.filter((n) => n.entry.id !== trashId).map((n) => n.key),
|
|
55567
|
+
to: { kind: "original" },
|
|
55568
|
+
names: {},
|
|
55569
|
+
keepNames: subtree.map((n) => n.key),
|
|
55570
|
+
include: [],
|
|
55571
|
+
dryRun: false
|
|
55572
|
+
});
|
|
55573
|
+
if (plan.missing.includes("columns")) throw new AppError(409, "too_many_columns", `A board holds up to ${MAX_COLUMNS} columns: there is no room to put it back.`);
|
|
55574
|
+
if (plan.missing.length) throw restoreError("restore_place_gone", "What it belonged to no longer exists.");
|
|
55575
|
+
const waiting = top.kind === "link" ? plan.wait.find((w) => w.row === top.row) : void 0;
|
|
55576
|
+
if (waiting) {
|
|
55577
|
+
const page = index3.node(`page:${top.row.pageId}`);
|
|
55578
|
+
throw restoreError("restore_place_in_trash", `Restore \u201C${page?.title ?? ""}\u201D first: the page is in the trash too.`, { title: page?.title ?? "", key: page?.key });
|
|
55579
|
+
}
|
|
55580
|
+
results.push(this.apply(tx, actor, entry.workspaceId, plan));
|
|
55581
|
+
}
|
|
55582
|
+
if (!results.length) throw notFound("Trash entry");
|
|
55583
|
+
return results;
|
|
55584
|
+
});
|
|
55585
|
+
for (const applied of done) await this.announce(actor, entry.workspaceId, applied);
|
|
55586
|
+
const first = done[0].result;
|
|
55587
|
+
return { ...first, kind: entry.kind, entityId: entry.entityId, movedTo: null };
|
|
55588
|
+
}
|
|
55589
|
+
/** The end of the list of `table`'s rows in `scope`, for something put there now. */
|
|
55590
|
+
atEnd(tx, table, scope) {
|
|
55591
|
+
const keys = tx.all(sql`SELECT position FROM ${sql.identifier(table)} WHERE ${scope} ORDER BY position`).map((r) => r.position);
|
|
55592
|
+
return keyAtEnd(keys);
|
|
55593
|
+
}
|
|
55594
|
+
/** Applies a plan inside the transaction it was worked out in. */
|
|
55595
|
+
apply(tx, actor, workspaceId, plan) {
|
|
55596
|
+
const { root } = plan;
|
|
55597
|
+
for (const made of plan.create) {
|
|
55598
|
+
if (made.kind === "project") {
|
|
55599
|
+
tx.insert(projects).values({ id: made.id, workspaceId, name: made.title.slice(0, NAME_MAX.project), color: "slate", position: this.atEnd(tx, "projects", sql`workspace_id = ${workspaceId}`) }).run();
|
|
55600
|
+
} else if (made.kind === "page") {
|
|
55601
|
+
const projectId = made.in.id;
|
|
55602
|
+
tx.insert(pages).values({
|
|
55603
|
+
id: made.id,
|
|
55604
|
+
workspaceId,
|
|
55605
|
+
projectId,
|
|
55606
|
+
parentId: null,
|
|
55607
|
+
title: made.title.slice(0, NAME_MAX.page),
|
|
55608
|
+
position: this.atEnd(tx, "pages", sql`project_id = ${projectId} AND parent_id IS NULL`),
|
|
55609
|
+
createdByUserId: actor.kind === "user" ? actor.userId : null
|
|
55610
|
+
}).run();
|
|
55611
|
+
} else {
|
|
55612
|
+
const boardId = made.in.id;
|
|
55613
|
+
tx.insert(columns).values({ id: made.id, workspaceId, boardId, name: made.title.slice(0, NAME_MAX.column), position: this.atEnd(tx, "board_columns", sql`board_id = ${boardId}`) }).run();
|
|
55614
|
+
}
|
|
55615
|
+
}
|
|
55616
|
+
const wanted = [...plan.coming.map((n) => n.row.rowId), ...plan.reinsert.map((r) => r.rowId)];
|
|
55617
|
+
const kept = /* @__PURE__ */ new Map();
|
|
55618
|
+
for (let i2 = 0; i2 < wanted.length; i2 += 500) {
|
|
55619
|
+
const chunk = wanted.slice(i2, i2 + 500);
|
|
55620
|
+
for (const row of tx.select({ id: trashRows.id, table: trashRows.tableName, data: trashRows.data }).from(trashRows).where(sql`${trashRows.id} IN (SELECT value FROM json_each(${JSON.stringify(chunk)}))`).all()) {
|
|
55621
|
+
kept.set(row.id, { table: row.table, data: row.data });
|
|
55622
|
+
}
|
|
55623
|
+
}
|
|
55624
|
+
const order2 = new Map(plan.coming.map((n, i2) => [n.row.rowId, i2]));
|
|
55625
|
+
const byRow = new Map(plan.coming.map((n) => [n.row.rowId, n]));
|
|
55626
|
+
const rows = wanted.map((rowId) => ({ rowId, captured: kept.get(rowId), node: byRow.get(rowId) })).filter((r) => r.captured !== void 0).sort((a, b) => ORDER.indexOf(a.captured.table) - ORDER.indexOf(b.captured.table) || (order2.get(a.rowId) ?? Infinity) - (order2.get(b.rowId) ?? Infinity) || a.rowId - b.rowId);
|
|
55627
|
+
if (rows.filter((r) => r.node).length !== plan.coming.length) throw restoreError("restore_changed", "Something in the trash changed meanwhile: look again before restoring.");
|
|
55628
|
+
const reinsert = new Reinsert(tx);
|
|
55629
|
+
const data = /* @__PURE__ */ new Map();
|
|
55630
|
+
for (const { captured, node: node2 } of rows) {
|
|
55631
|
+
if (node2) {
|
|
55632
|
+
const place = plan.placement.get(node2.key);
|
|
55633
|
+
if (place) {
|
|
55634
|
+
Object.assign(captured.data, place.sets);
|
|
55635
|
+
const scope = place.moved ? positionScope(node2.kind, place.container) : null;
|
|
55636
|
+
if (scope) captured.data.position = this.atEnd(tx, scope.table, scope.where);
|
|
55637
|
+
}
|
|
55638
|
+
const name2 = plan.names.get(node2.key);
|
|
55639
|
+
const column2 = NAME_COLUMN[node2.kind];
|
|
55640
|
+
if (name2 !== void 0 && column2) captured.data[column2] = node2.kind === "attachment" ? safeFilename(name2) : name2;
|
|
55641
|
+
data.set(node2.key, captured.data);
|
|
55642
|
+
if (!reinsert.insert(captured)) throw restoreError("restore_place_gone", "It no longer fits where it goes back.");
|
|
55643
|
+
} else {
|
|
55644
|
+
reinsert.insert(captured);
|
|
55645
|
+
}
|
|
55646
|
+
}
|
|
55647
|
+
const removed = [...plan.coming.map((n) => n.row), ...plan.reinsert, ...plan.drop, ...plan.mentions].map((r) => r.rowId);
|
|
55648
|
+
for (let i2 = 0; i2 < removed.length; i2 += 500) {
|
|
55649
|
+
tx.delete(trashRows).where(sql`${trashRows.id} IN (SELECT value FROM json_each(${JSON.stringify(removed.slice(i2, i2 + 500))}))`).run();
|
|
55650
|
+
}
|
|
55651
|
+
for (const { row, trashId } of plan.wait) tx.update(trashRows).set({ trashId }).where(eq(trashRows.id, row.rowId)).run();
|
|
55652
|
+
const touched = /* @__PURE__ */ new Set([...plan.coming.map((n) => n.entry.id), ...[...plan.reinsert, ...plan.drop, ...plan.mentions, ...plan.wait.map((w) => w.row)].map((r) => r.trashId)]);
|
|
55653
|
+
this.dropEmpty(tx, touched);
|
|
55654
|
+
rebuildMentions(tx, workspaceId, reinsert.cards, reinsert.pages);
|
|
55655
|
+
const movedTo = plan.to === "other" || plan.create.length > 0 ? plan.location : null;
|
|
55656
|
+
for (const node2 of plan.coming) {
|
|
55657
|
+
if (!node2.entryRoot) continue;
|
|
55658
|
+
const change = this.restoredChange(tx, node2.kind, data.get(node2.key) ?? {}, { trashId: node2.entry.id, ...node2 === root && movedTo ? { movedTo } : {} });
|
|
55659
|
+
if (change) this.history.record(tx, actor, workspaceId, change);
|
|
55660
|
+
}
|
|
55661
|
+
const extras = plan.extras.filter((n) => !n.parent || !plan.comingKeys.has(n.parent.key));
|
|
55662
|
+
const targets = [root, ...extras].map((node2) => ({ node: node2, ...this.target(tx, node2, data.get(node2.key)) }));
|
|
55663
|
+
const main = targets[0];
|
|
55664
|
+
const result = {
|
|
55665
|
+
kind: root.kind,
|
|
55666
|
+
entityId: root.id,
|
|
55667
|
+
movedTo,
|
|
55668
|
+
path: main.path,
|
|
55669
|
+
location: plan.location,
|
|
55670
|
+
restored: Math.max(0, plan.coming.length - (data.has(root.key) ? 1 : 0)),
|
|
55671
|
+
left: plan.subtree.filter((n) => plan.excluded.has(n.key) && !(n.parent && plan.excluded.has(n.parent.key))).length
|
|
55672
|
+
};
|
|
55673
|
+
const waiting = root.kind === "link" && !data.has(root.key);
|
|
55674
|
+
if (waiting) result.waitsFor = root.title;
|
|
55675
|
+
const structure = plan.path.length > 0 || plan.create.length > 0;
|
|
55676
|
+
return {
|
|
55677
|
+
result,
|
|
55678
|
+
targets: targets.map((t) => ({ ...t, event: structure ? { ...t.event, structure: true } : t.event })),
|
|
55679
|
+
movedTo,
|
|
55680
|
+
waiting
|
|
55681
|
+
};
|
|
55682
|
+
}
|
|
55683
|
+
/** Deletes the entries left with nothing of their own; what else they kept goes with them. */
|
|
55684
|
+
dropEmpty(tx, trashIds) {
|
|
55685
|
+
for (const trashId of trashIds) {
|
|
55686
|
+
const left = tx.get(
|
|
55687
|
+
sql`SELECT 1 AS found FROM trash_rows WHERE trash_id = ${trashId} AND (table_name NOT IN ('card_labels', 'card_page_links') OR (table_name = 'card_page_links' AND trash_id IN (SELECT id FROM trash WHERE id = ${trashId} AND kind = 'link'))) LIMIT 1`
|
|
54379
55688
|
);
|
|
54380
|
-
if (
|
|
54381
|
-
|
|
54382
|
-
|
|
54383
|
-
|
|
54384
|
-
|
|
54385
|
-
|
|
54386
|
-
const
|
|
54387
|
-
const
|
|
54388
|
-
|
|
54389
|
-
|
|
54390
|
-
|
|
54391
|
-
|
|
54392
|
-
|
|
54393
|
-
|
|
54394
|
-
switch (kind) {
|
|
55689
|
+
if (!left) tx.delete(trash).where(eq(trash.id, trashId)).run();
|
|
55690
|
+
}
|
|
55691
|
+
}
|
|
55692
|
+
/** What restoring `node` is about, where to open it, and who hears of it. */
|
|
55693
|
+
target(tx, node2, data) {
|
|
55694
|
+
const text2 = /* @__PURE__ */ __name((value) => typeof value === "string" ? value : "", "text");
|
|
55695
|
+
const row = data ?? { id: node2.id, card_id: node2.row.cardId, page_id: node2.row.pageId, board_id: node2.row.boardId, project_id: node2.row.projectId, checklist_id: node2.row.checklistId };
|
|
55696
|
+
const id3 = text2(row.id) || node2.id;
|
|
55697
|
+
const boardOfCard = /* @__PURE__ */ __name((cardId) => tx.get(sql`SELECT board_id FROM cards WHERE id = ${cardId}`)?.board_id ?? "", "boardOfCard");
|
|
55698
|
+
const onCard = /* @__PURE__ */ __name((cardId, extra = {}) => {
|
|
55699
|
+
const boardId = boardOfCard(cardId);
|
|
55700
|
+
return { entityType: "card", entityId: cardId, path: boardId ? `b/${boardId}` : null, event: { boardId, cardId, ...extra } };
|
|
55701
|
+
}, "onCard");
|
|
55702
|
+
switch (node2.kind) {
|
|
54395
55703
|
case "project":
|
|
54396
|
-
return { entityType: "project", entityId:
|
|
54397
|
-
case "board":
|
|
54398
|
-
|
|
54399
|
-
|
|
54400
|
-
|
|
54401
|
-
|
|
54402
|
-
|
|
54403
|
-
|
|
54404
|
-
}
|
|
54405
|
-
return { entityType: "board", entityId: String(root.id), movedTo, path: `b/${root.id}`, event: event({ boardId: String(root.id), projectId: String(root.project_id), structure: true }) };
|
|
54406
|
-
}
|
|
54407
|
-
case "column": {
|
|
54408
|
-
if (!exists2("boards", root.board_id)) {
|
|
54409
|
-
const target = firstBoard();
|
|
54410
|
-
if (!target) throw missing("boards", root.board_id, "board");
|
|
54411
|
-
root.board_id = target.id;
|
|
54412
|
-
root.position = atEnd("board_columns", sql`board_id = ${target.id}`);
|
|
54413
|
-
for (const card of ofTable("cards")) card.board_id = target.id;
|
|
54414
|
-
movedTo = [target.project, target.name].join(SEPARATOR);
|
|
54415
|
-
}
|
|
54416
|
-
return { entityType: "column", entityId: String(root.id), movedTo, path: `b/${root.board_id}`, event: event({ boardId: String(root.board_id), structure: true }) };
|
|
54417
|
-
}
|
|
54418
|
-
case "card": {
|
|
54419
|
-
const column2 = tx.get(sql`SELECT board_id, name FROM board_columns WHERE id = ${root.column_id}`);
|
|
54420
|
-
if (column2 && column2.board_id !== root.board_id) {
|
|
54421
|
-
const board = boardName(column2.board_id);
|
|
54422
|
-
root.board_id = column2.board_id;
|
|
54423
|
-
root.position = atEnd("cards", sql`column_id = ${root.column_id}`);
|
|
54424
|
-
movedTo = [board.project, board.name, column2.name].join(SEPARATOR);
|
|
54425
|
-
} else if (!column2) {
|
|
54426
|
-
const first = /* @__PURE__ */ __name((scope) => tx.get(
|
|
54427
|
-
sql`SELECT c.id, c.name, b.id AS board_id, b.name AS board, p.name AS project FROM board_columns c JOIN boards b ON b.id = c.board_id JOIN projects p ON p.id = b.project_id WHERE ${scope} ORDER BY p.position, p.id, b.position, b.id, c.position, c.id LIMIT 1`
|
|
54428
|
-
), "first");
|
|
54429
|
-
const target = first(sql`c.board_id = ${root.board_id}`) ?? first(sql`c.workspace_id = ${workspaceId}`);
|
|
54430
|
-
if (!target) throw missing("board_columns", root.column_id, "column");
|
|
54431
|
-
root.board_id = target.board_id;
|
|
54432
|
-
root.column_id = target.id;
|
|
54433
|
-
root.position = atEnd("cards", sql`column_id = ${target.id}`);
|
|
54434
|
-
movedTo = [target.project, target.board, target.name].join(SEPARATOR);
|
|
54435
|
-
}
|
|
54436
|
-
return { entityType: "card", entityId: String(root.id), movedTo, path: `b/${root.board_id}`, event: event({ boardId: String(root.board_id), cardId: String(root.id), structure: true }) };
|
|
54437
|
-
}
|
|
54438
|
-
case "page": {
|
|
54439
|
-
const parent = root.parent_id != null ? tx.get(sql`SELECT project_id FROM pages WHERE id = ${root.parent_id}`) : void 0;
|
|
54440
|
-
const projectName = /* @__PURE__ */ __name((id3) => tx.get(sql`SELECT name FROM projects WHERE id = ${id3}`)?.name ?? null, "projectName");
|
|
54441
|
-
if (parent) {
|
|
54442
|
-
if (parent.project_id !== root.project_id) {
|
|
54443
|
-
for (const page of ofTable("pages")) page.project_id = parent.project_id;
|
|
54444
|
-
root.position = atEnd("pages", sql`parent_id = ${root.parent_id}`);
|
|
54445
|
-
movedTo = projectName(parent.project_id);
|
|
54446
|
-
}
|
|
54447
|
-
} else if (!exists2("projects", root.project_id)) {
|
|
54448
|
-
const target = firstProject();
|
|
54449
|
-
if (!target) throw missing("projects", root.project_id, "project");
|
|
54450
|
-
for (const page of ofTable("pages")) page.project_id = target.id;
|
|
54451
|
-
root.parent_id = null;
|
|
54452
|
-
root.position = atEnd("pages", sql`project_id = ${target.id} AND parent_id IS NULL`);
|
|
54453
|
-
movedTo = target.name;
|
|
54454
|
-
} else if (root.parent_id != null) {
|
|
54455
|
-
root.parent_id = null;
|
|
54456
|
-
root.position = atEnd("pages", sql`project_id = ${root.project_id} AND parent_id IS NULL`);
|
|
54457
|
-
movedTo = projectName(root.project_id);
|
|
54458
|
-
}
|
|
54459
|
-
return { entityType: "page", entityId: String(root.id), movedTo, path: `d/${root.id}`, event: event({ pageId: String(root.id), projectId: String(root.project_id), structure: true }) };
|
|
54460
|
-
}
|
|
54461
|
-
case "attachment": {
|
|
54462
|
-
if (root.card_id != null) {
|
|
54463
|
-
needs("cards", root.card_id, "card");
|
|
54464
|
-
const boardId = tx.get(sql`SELECT board_id FROM cards WHERE id = ${root.card_id}`).board_id;
|
|
54465
|
-
return { entityType: "card", entityId: String(root.card_id), movedTo, path: `b/${boardId}`, event: event({ boardId, cardId: String(root.card_id) }) };
|
|
54466
|
-
}
|
|
54467
|
-
needs("pages", root.page_id, "page");
|
|
54468
|
-
return { entityType: "page", entityId: String(root.page_id), movedTo, path: `d/${root.page_id}`, event: event({ pageId: String(root.page_id) }) };
|
|
54469
|
-
}
|
|
55704
|
+
return { entityType: "project", entityId: id3, path: `p/${id3}`, event: { projectId: id3, structure: true } };
|
|
55705
|
+
case "board":
|
|
55706
|
+
return { entityType: "board", entityId: id3, path: `b/${id3}`, event: { boardId: id3, projectId: text2(row.project_id), structure: true } };
|
|
55707
|
+
case "column":
|
|
55708
|
+
return { entityType: "column", entityId: id3, path: `b/${text2(row.board_id)}`, event: { boardId: text2(row.board_id), structure: true } };
|
|
55709
|
+
case "card":
|
|
55710
|
+
return { entityType: "card", entityId: id3, path: `b/${text2(row.board_id)}`, event: { boardId: text2(row.board_id), cardId: id3, structure: true } };
|
|
55711
|
+
case "page":
|
|
55712
|
+
return { entityType: "page", entityId: id3, path: `d/${id3}`, event: { pageId: id3, projectId: text2(row.project_id), structure: true } };
|
|
54470
55713
|
case "label":
|
|
54471
|
-
|
|
54472
|
-
|
|
55714
|
+
return { entityType: "label", entityId: id3, path: `b/${text2(row.board_id)}`, event: { boardId: text2(row.board_id) } };
|
|
55715
|
+
case "attachment":
|
|
55716
|
+
if (row.card_id) return onCard(text2(row.card_id));
|
|
55717
|
+
return { entityType: "page", entityId: text2(row.page_id), path: `d/${text2(row.page_id)}`, event: { pageId: text2(row.page_id) } };
|
|
54473
55718
|
case "checklist":
|
|
55719
|
+
return onCard(text2(row.card_id));
|
|
54474
55720
|
case "checklist_item": {
|
|
54475
|
-
const
|
|
54476
|
-
|
|
54477
|
-
return { entityType: "card", entityId: String(cardId), movedTo, path: `b/${boardId}`, event: event({ boardId, cardId: String(cardId) }) };
|
|
54478
|
-
}
|
|
54479
|
-
case "link": {
|
|
54480
|
-
needs("cards", root.card_id, "card");
|
|
54481
|
-
needs("pages", root.page_id, "page");
|
|
54482
|
-
const boardId = tx.get(sql`SELECT board_id FROM cards WHERE id = ${root.card_id}`).board_id;
|
|
54483
|
-
return { entityType: "card", entityId: String(root.card_id), movedTo, path: `b/${boardId}`, event: event({ boardId, cardId: String(root.card_id), pageId: String(root.page_id) }) };
|
|
55721
|
+
const list = tx.get(sql`SELECT card_id FROM checklists WHERE id = ${text2(row.checklist_id)}`);
|
|
55722
|
+
return onCard(list?.card_id ?? "");
|
|
54484
55723
|
}
|
|
55724
|
+
case "link":
|
|
55725
|
+
return onCard(text2(row.card_id), { pageId: text2(row.page_id) });
|
|
55726
|
+
}
|
|
55727
|
+
}
|
|
55728
|
+
/** Records and announces what came back. */
|
|
55729
|
+
async announce(actor, workspaceId, applied) {
|
|
55730
|
+
if (applied.waiting && applied.targets.length === 1) {
|
|
55731
|
+
await this.activity.emit(workspaceId, { action: "trash.changed", actor: actorRef(actor), ...applied.targets[0].event });
|
|
55732
|
+
return;
|
|
54485
55733
|
}
|
|
55734
|
+
for (const [i2, target] of applied.targets.entries()) {
|
|
55735
|
+
if (i2 === 0 && applied.waiting) continue;
|
|
55736
|
+
await this.activity.record(
|
|
55737
|
+
actor,
|
|
55738
|
+
workspaceId,
|
|
55739
|
+
{
|
|
55740
|
+
action: "trash.restored",
|
|
55741
|
+
entityType: target.entityType,
|
|
55742
|
+
entityId: target.entityId,
|
|
55743
|
+
summary: target.node.title,
|
|
55744
|
+
meta: { kind: target.node.kind, ...i2 === 0 && applied.movedTo ? { movedTo: applied.movedTo } : {} }
|
|
55745
|
+
},
|
|
55746
|
+
target.event
|
|
55747
|
+
);
|
|
55748
|
+
}
|
|
55749
|
+
}
|
|
55750
|
+
/** Deletes something for good with everything below it, and the files of its attachments. */
|
|
55751
|
+
async purgeItem(actor, workspaceId, key) {
|
|
55752
|
+
this.access.requireUser(actor);
|
|
55753
|
+
await this.access.workspace(actor, workspaceId);
|
|
55754
|
+
const erased = await this.erase(workspaceId, (index3) => {
|
|
55755
|
+
const node3 = index3.node(key);
|
|
55756
|
+
return node3 ? [node3] : [];
|
|
55757
|
+
});
|
|
55758
|
+
if (!erased) throw notFound("Trash item");
|
|
55759
|
+
const [node2] = erased;
|
|
55760
|
+
await this.activity.record(actor, workspaceId, { action: "trash.purged", entityType: purgedEntityType(node2.kind), entityId: node2.id, summary: node2.title, meta: { kind: node2.kind } });
|
|
54486
55761
|
}
|
|
54487
|
-
/**
|
|
55762
|
+
/**
|
|
55763
|
+
* Deletes several things for good, with everything below them; what is below another one of
|
|
55764
|
+
* them goes with it. With `dryRun`, only says how much that takes. What is no longer in the
|
|
55765
|
+
* trash is skipped; the answer counts what went.
|
|
55766
|
+
*/
|
|
55767
|
+
async purgeMany(actor, workspaceId, body) {
|
|
55768
|
+
this.access.requireUser(actor);
|
|
55769
|
+
await this.access.workspace(actor, workspaceId);
|
|
55770
|
+
const input2 = parse3(trashPurgeManyInput, body);
|
|
55771
|
+
const pick2 = /* @__PURE__ */ __name((index3) => index3.outermost(input2.keys.flatMap((key) => index3.node(key) ?? [])), "pick");
|
|
55772
|
+
const summary = /* @__PURE__ */ __name((index3, nodes) => ({ count: nodes.length, ...index3.totals(nodes) }), "summary");
|
|
55773
|
+
if (input2.dryRun) {
|
|
55774
|
+
const index3 = TrashIndex.load(this.deps.db, workspaceId);
|
|
55775
|
+
return summary(index3, pick2(index3));
|
|
55776
|
+
}
|
|
55777
|
+
let went = null;
|
|
55778
|
+
const erased = await this.erase(workspaceId, (index3) => {
|
|
55779
|
+
const picked = pick2(index3);
|
|
55780
|
+
went = summary(index3, picked);
|
|
55781
|
+
return picked;
|
|
55782
|
+
});
|
|
55783
|
+
if (!erased?.length || !went) throw notFound("Trash item");
|
|
55784
|
+
for (const node2 of erased) {
|
|
55785
|
+
await this.activity.record(actor, workspaceId, { action: "trash.purged", entityType: purgedEntityType(node2.kind), entityId: node2.id, summary: node2.title, meta: { kind: node2.kind } });
|
|
55786
|
+
}
|
|
55787
|
+
return went;
|
|
55788
|
+
}
|
|
55789
|
+
/** Deletes for good what one deletion took away, with everything below it. */
|
|
54488
55790
|
async purge(actor, trashId) {
|
|
54489
55791
|
const entry = await this.load(actor, trashId);
|
|
54490
|
-
|
|
55792
|
+
const erased = await this.erase(entry.workspaceId, (index3) => [...index3.nodes.values()].filter((n) => n.entry.id === trashId), [trashId]);
|
|
55793
|
+
if (!erased) throw notFound("Trash entry");
|
|
54491
55794
|
await this.activity.record(actor, entry.workspaceId, {
|
|
54492
55795
|
action: "trash.purged",
|
|
54493
55796
|
entityType: purgedEntityType(entry.kind),
|
|
@@ -54498,30 +55801,71 @@ var TrashService = class {
|
|
|
54498
55801
|
}
|
|
54499
55802
|
/** Deletes for good what has been in the trash for TRASH_DAYS. Runs hourly. */
|
|
54500
55803
|
async purgeExpired(now = /* @__PURE__ */ new Date()) {
|
|
54501
|
-
const expired = await this.deps.db.select({ id: trash.id }).from(trash).where(lte(trash.expiresAt, now));
|
|
55804
|
+
const expired = await this.deps.db.select({ id: trash.id, workspaceId: trash.workspaceId }).from(trash).where(lte(trash.expiresAt, now));
|
|
55805
|
+
const byWorkspace = /* @__PURE__ */ new Map();
|
|
55806
|
+
for (const { id: id3, workspaceId } of expired) byWorkspace.set(workspaceId, [...byWorkspace.get(workspaceId) ?? [], id3]);
|
|
54502
55807
|
let erased = 0;
|
|
54503
|
-
for (const
|
|
55808
|
+
for (const [workspaceId, ids] of byWorkspace) {
|
|
55809
|
+
const set2 = new Set(ids);
|
|
55810
|
+
if (await this.erase(workspaceId, (index3) => [...index3.nodes.values()].filter((n) => set2.has(n.entry.id)), ids)) erased += ids.length;
|
|
55811
|
+
}
|
|
54504
55812
|
return erased;
|
|
54505
55813
|
}
|
|
54506
55814
|
/**
|
|
54507
|
-
* Deletes
|
|
54508
|
-
* the
|
|
54509
|
-
* comes first (and nothing is erased) or finds
|
|
54510
|
-
*
|
|
54511
|
-
|
|
54512
|
-
|
|
54513
|
-
|
|
54514
|
-
|
|
54515
|
-
|
|
54516
|
-
const
|
|
54517
|
-
|
|
55815
|
+
* Deletes for good what `pick` chooses, with everything below it, and then the files of its
|
|
55816
|
+
* attachments. Choosing, reading the files and deleting happen in one transaction, so a
|
|
55817
|
+
* restore running at the same time either comes first (and nothing of it is erased) or finds
|
|
55818
|
+
* nothing to restore. Relations of what goes can never come back: they go too, as do links
|
|
55819
|
+
* to a page that goes. Entries left with nothing of their own go, and so do `entries`.
|
|
55820
|
+
* Returns what was picked, or null when there was nothing.
|
|
55821
|
+
*/
|
|
55822
|
+
async erase(workspaceId, pick2, entries = []) {
|
|
55823
|
+
const done = this.deps.db.transaction((tx) => {
|
|
55824
|
+
const index3 = TrashIndex.load(tx, workspaceId);
|
|
55825
|
+
const picked = pick2(index3);
|
|
55826
|
+
const gone = index3.goneWith(picked);
|
|
55827
|
+
const has = /* @__PURE__ */ __name((kind, id3) => gone.has(`${kind}:${id3}`), "has");
|
|
55828
|
+
const touches = /* @__PURE__ */ __name((r) => has("card", r.cardId) || (r.table === "card_labels" ? has("label", r.labelId) : has("page", r.pageId)), "touches");
|
|
55829
|
+
const rows = [...[...gone.values()].map((n) => n.row), ...index3.relations.filter(touches), ...index3.mentions.filter(touches)];
|
|
55830
|
+
const existing = entries.filter((id3) => index3.entries.has(id3));
|
|
55831
|
+
if (rows.length === 0 && existing.length === 0) return null;
|
|
55832
|
+
this.history.forgetIds(
|
|
55833
|
+
tx,
|
|
55834
|
+
[...gone.values()].filter((n) => n.kind !== "link").map((n) => n.id)
|
|
55835
|
+
);
|
|
55836
|
+
const ids = rows.map((r) => r.rowId);
|
|
55837
|
+
for (let i2 = 0; i2 < ids.length; i2 += 500) {
|
|
55838
|
+
tx.delete(trashRows).where(sql`${trashRows.id} IN (SELECT value FROM json_each(${JSON.stringify(ids.slice(i2, i2 + 500))}))`).run();
|
|
55839
|
+
}
|
|
55840
|
+
for (const id3 of existing) tx.delete(trash).where(eq(trash.id, id3)).run();
|
|
55841
|
+
this.dropEmpty(tx, new Set(rows.map((r) => r.trashId)));
|
|
55842
|
+
return { picked, files: rows.flatMap((r) => r.table === "attachments" && r.storageKey ? [r.storageKey] : []) };
|
|
54518
55843
|
});
|
|
54519
|
-
if (!
|
|
54520
|
-
for (const
|
|
55844
|
+
if (!done) return null;
|
|
55845
|
+
for (const key of done.files) await this.deps.storage.delete(key).catch(() => {
|
|
54521
55846
|
});
|
|
54522
|
-
return
|
|
55847
|
+
return done.picked.length ? done.picked : entries.length ? [] : null;
|
|
54523
55848
|
}
|
|
54524
55849
|
};
|
|
55850
|
+
function positionScope(kind, container) {
|
|
55851
|
+
switch (kind) {
|
|
55852
|
+
case "board":
|
|
55853
|
+
return { table: "boards", where: sql`project_id = ${container.id}` };
|
|
55854
|
+
case "column":
|
|
55855
|
+
return { table: "board_columns", where: sql`board_id = ${container.id}` };
|
|
55856
|
+
case "card":
|
|
55857
|
+
return { table: "cards", where: sql`column_id = ${container.id}` };
|
|
55858
|
+
case "checklist":
|
|
55859
|
+
return { table: "checklists", where: sql`card_id = ${container.id}` };
|
|
55860
|
+
case "checklist_item":
|
|
55861
|
+
return { table: "checklist_items", where: sql`checklist_id = ${container.id}` };
|
|
55862
|
+
case "page":
|
|
55863
|
+
return { table: "pages", where: container.kind === "page" ? sql`parent_id = ${container.id}` : sql`project_id = ${container.id} AND parent_id IS NULL` };
|
|
55864
|
+
default:
|
|
55865
|
+
return null;
|
|
55866
|
+
}
|
|
55867
|
+
}
|
|
55868
|
+
__name(positionScope, "positionScope");
|
|
54525
55869
|
function rebuildMentions(tx, workspaceId, cards2, pages2) {
|
|
54526
55870
|
if (cards2.size === 0 && pages2.size === 0) return;
|
|
54527
55871
|
const exists2 = /* @__PURE__ */ new Map();
|
|
@@ -54547,7 +55891,7 @@ __name(rebuildMentions, "rebuildMentions");
|
|
|
54547
55891
|
var AUTHORS = /* @__PURE__ */ new Set(["users", "api_tokens"]);
|
|
54548
55892
|
var SHAPES = new Map(
|
|
54549
55893
|
ORDER.map((table) => {
|
|
54550
|
-
const definition =
|
|
55894
|
+
const definition = TABLES2[table];
|
|
54551
55895
|
const references = getTableConfig(definition).foreignKeys.map((fk) => {
|
|
54552
55896
|
const reference = fk.reference();
|
|
54553
55897
|
return { column: reference.columns[0].name, table: getTableConfig(reference.foreignTable).name, target: reference.foreignColumns[0].name };
|
|
@@ -54605,29 +55949,14 @@ var Reinsert = class {
|
|
|
54605
55949
|
}
|
|
54606
55950
|
};
|
|
54607
55951
|
var purgedEntityType = /* @__PURE__ */ __name((kind) => ["project", "board", "column", "card", "label", "page"].find((k) => k === kind) ?? "card", "purgedEntityType");
|
|
54608
|
-
function toTrashEntryDTO(row) {
|
|
54609
|
-
return {
|
|
54610
|
-
id: row.id,
|
|
54611
|
-
kind: row.kind,
|
|
54612
|
-
entityId: row.entityId,
|
|
54613
|
-
title: row.title,
|
|
54614
|
-
location: row.location,
|
|
54615
|
-
contents: row.contents,
|
|
54616
|
-
bytes: row.bytes,
|
|
54617
|
-
deletedBy: {
|
|
54618
|
-
kind: row.actorKind,
|
|
54619
|
-
id: (row.actorKind === "agent" ? row.actorTokenId : row.actorUserId) ?? "",
|
|
54620
|
-
name: row.actorName
|
|
54621
|
-
},
|
|
54622
|
-
deletedAt: row.deletedAt.toISOString(),
|
|
54623
|
-
expiresAt: row.expiresAt.toISOString()
|
|
54624
|
-
};
|
|
54625
|
-
}
|
|
54626
|
-
__name(toTrashEntryDTO, "toTrashEntryDTO");
|
|
54627
55952
|
|
|
54628
55953
|
// src/services/undo.ts
|
|
54629
55954
|
var AT_END = 1e5;
|
|
54630
55955
|
var MAX_CHANGES = 500;
|
|
55956
|
+
var MAX_LEFT = 50;
|
|
55957
|
+
var LEFT_TYPES = ["project", "board", "column", "label"];
|
|
55958
|
+
var LEFT_ACTIONS = ["created", "updated", "moved", "deleted"];
|
|
55959
|
+
var TRASH_TABLES = { project: "projects", board: "boards", column: "board_columns", label: "labels", page: "pages", card: "cards" };
|
|
54631
55960
|
var CHUNK = 90;
|
|
54632
55961
|
var LIGHT_COLUMNS = (() => {
|
|
54633
55962
|
const body = inArray(history.kind, [...HISTORY_BODY_KINDS]);
|
|
@@ -54673,11 +56002,12 @@ var UndoService = class {
|
|
|
54673
56002
|
async undo(actor, input2) {
|
|
54674
56003
|
this.access.requireUser(actor);
|
|
54675
56004
|
const data = parse3(undoInput, input2);
|
|
54676
|
-
const rows = await this.entries(actor, data.ids, data.since);
|
|
56005
|
+
const { rows, anchor: anchor2, remaining } = await this.entries(actor, data.ids, data.since, data.until);
|
|
54677
56006
|
const undoing = new Set(rows.map((r) => r.id));
|
|
56007
|
+
const told = anchor2 ? { remaining: remaining ?? 0, ...this.left(anchor2) } : {};
|
|
54678
56008
|
const state = new State();
|
|
54679
56009
|
const plan = rows.map((row) => this.planItem(row, this.check(row, undoing, state), undoing, state));
|
|
54680
|
-
if (data.dryRun || data.conflicts === "ask" && plan.some((p) => p.status === "conflict")) return { applied: false, plan, undone: 0, skipped: 0, failed: 0 };
|
|
56010
|
+
if (data.dryRun || data.conflicts === "ask" && plan.some((p) => p.status === "conflict")) return { applied: false, plan, undone: 0, skipped: 0, failed: 0, ...told };
|
|
54681
56011
|
let undone = 0;
|
|
54682
56012
|
let skipped = 0;
|
|
54683
56013
|
let failed = 0;
|
|
@@ -54703,7 +56033,7 @@ var UndoService = class {
|
|
|
54703
56033
|
failed++;
|
|
54704
56034
|
}
|
|
54705
56035
|
}
|
|
54706
|
-
return { applied: true, plan, undone, skipped, failed };
|
|
56036
|
+
return { applied: true, plan, undone, skipped, failed, ...told };
|
|
54707
56037
|
}
|
|
54708
56038
|
/** Puts a page's content or a card's description back as it was after a change, as a new change. */
|
|
54709
56039
|
async restoreVersion(actor, entryId) {
|
|
@@ -54727,22 +56057,67 @@ var UndoService = class {
|
|
|
54727
56057
|
rows(where) {
|
|
54728
56058
|
return this.deps.db.select(LIGHT_COLUMNS).from(history).where(where).orderBy(desc(history.updatedAt), desc(sql`rowid`));
|
|
54729
56059
|
}
|
|
54730
|
-
/**
|
|
54731
|
-
|
|
54732
|
-
|
|
56060
|
+
/**
|
|
56061
|
+
* The changes to undo, newest first: those asked for, or all their author did from one on (the
|
|
56062
|
+
* anchor), up to MAX_CHANGES at a time. Those older than `until` are the next batch, after the
|
|
56063
|
+
* one that ended there; `remaining` says how many are left beyond this one.
|
|
56064
|
+
*/
|
|
56065
|
+
async entries(actor, ids, since, until) {
|
|
54733
56066
|
if (ids) {
|
|
54734
|
-
|
|
54735
|
-
|
|
54736
|
-
|
|
54737
|
-
|
|
54738
|
-
const
|
|
54739
|
-
|
|
54740
|
-
|
|
54741
|
-
|
|
54742
|
-
|
|
54743
|
-
|
|
54744
|
-
|
|
54745
|
-
|
|
56067
|
+
const rows2 = [];
|
|
56068
|
+
for (let i2 = 0; i2 < ids.length; i2 += CHUNK) rows2.push(...await this.rows(inArray(history.id, ids.slice(i2, i2 + CHUNK))));
|
|
56069
|
+
if (rows2.length !== new Set(ids).size) throw notFound("History entry");
|
|
56070
|
+
rows2.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime() || b.seq - a.seq);
|
|
56071
|
+
for (const workspaceId of new Set(rows2.map((r) => r.workspaceId))) await this.access.workspace(actor, workspaceId);
|
|
56072
|
+
return { rows: rows2 };
|
|
56073
|
+
}
|
|
56074
|
+
const [anchor2] = await this.rows(eq(history.id, since));
|
|
56075
|
+
if (!anchor2) throw notFound("History entry");
|
|
56076
|
+
await this.access.workspace(actor, anchor2.workspaceId);
|
|
56077
|
+
const author = anchor2.actorKind === "agent" ? eq(history.actorTokenId, anchor2.actorTokenId ?? "") : and(eq(history.actorKind, "user"), eq(history.actorUserId, anchor2.actorUserId ?? ""));
|
|
56078
|
+
const from = or(gt(history.updatedAt, anchor2.updatedAt), and(eq(history.updatedAt, anchor2.updatedAt), sql`rowid >= ${anchor2.seq}`));
|
|
56079
|
+
const before = /* @__PURE__ */ __name((row) => or(lt(history.updatedAt, row.updatedAt), and(eq(history.updatedAt, row.updatedAt), sql`rowid < ${row.seq}`)), "before");
|
|
56080
|
+
let end2;
|
|
56081
|
+
if (until) {
|
|
56082
|
+
;
|
|
56083
|
+
[end2] = await this.rows(eq(history.id, until));
|
|
56084
|
+
if (!end2 || end2.workspaceId !== anchor2.workspaceId) throw notFound("History entry");
|
|
56085
|
+
}
|
|
56086
|
+
const scope = and(eq(history.workspaceId, anchor2.workspaceId), author, from, end2 ? before(end2) : void 0);
|
|
56087
|
+
const rows = await this.rows(scope).limit(MAX_CHANGES);
|
|
56088
|
+
const last = rows.at(-1);
|
|
56089
|
+
const remaining = rows.length < MAX_CHANGES || !last ? 0 : this.deps.db.select({ n: sql`count(*)` }).from(history).where(and(scope, before(last))).get()?.n ?? 0;
|
|
56090
|
+
return { rows, anchor: anchor2, remaining };
|
|
56091
|
+
}
|
|
56092
|
+
/**
|
|
56093
|
+
* What the anchor's author changed from it on in projects, boards, columns and labels: these
|
|
56094
|
+
* have no history, so undoing from it leaves them as they are, and says so. By what activity
|
|
56095
|
+
* tells, each thing once, with its name as the latest change left it and its key in the trash.
|
|
56096
|
+
*/
|
|
56097
|
+
left(anchor2) {
|
|
56098
|
+
const author = anchor2.actorKind === "agent" ? sql`actor_kind = 'agent' AND actor_token_id = ${anchor2.actorTokenId ?? ""}` : sql`actor_kind = 'user' AND actor_user_id = ${anchor2.actorUserId ?? ""}`;
|
|
56099
|
+
const types = JSON.stringify(LEFT_TYPES);
|
|
56100
|
+
const scope = sql`workspace_id = ${anchor2.workspaceId} AND ${author} AND created_at >= ${anchor2.updatedAt.getTime()} AND entity_type IN (SELECT value FROM json_each(${types}))`;
|
|
56101
|
+
const found = this.deps.db.all(
|
|
56102
|
+
sql`SELECT g.entityType, g.entityId, g.actions,
|
|
56103
|
+
(SELECT summary FROM activity n WHERE n.workspace_id = ${anchor2.workspaceId} AND n.entity_id = g.entityId ORDER BY n.created_at DESC, n.rowid DESC LIMIT 1) AS title
|
|
56104
|
+
FROM (SELECT entity_type AS entityType, entity_id AS entityId, json_group_array(DISTINCT action) AS actions, min(rowid) AS first
|
|
56105
|
+
FROM activity WHERE ${scope} GROUP BY entity_type, entity_id) g
|
|
56106
|
+
ORDER BY g.first LIMIT ${MAX_LEFT + 1}`
|
|
56107
|
+
);
|
|
56108
|
+
const total = found.length > MAX_LEFT ? this.deps.db.get(sql`SELECT count(*) AS n FROM (SELECT 1 FROM activity WHERE ${scope} GROUP BY entity_type, entity_id)`)?.n ?? found.length : found.length;
|
|
56109
|
+
const left = found.slice(0, MAX_LEFT).map((r) => {
|
|
56110
|
+
const done = new Set(JSON.parse(r.actions).map((a) => a.slice(a.indexOf(".") + 1)));
|
|
56111
|
+
const trashKey2 = this.inTrash(anchor2.workspaceId, r.entityType, r.entityId);
|
|
56112
|
+
return {
|
|
56113
|
+
entityType: r.entityType,
|
|
56114
|
+
entityId: r.entityId,
|
|
56115
|
+
title: r.title ?? "",
|
|
56116
|
+
actions: LEFT_ACTIONS.filter((a) => done.has(a)),
|
|
56117
|
+
...trashKey2 ? { trashKey: trashKey2 } : {}
|
|
56118
|
+
};
|
|
56119
|
+
});
|
|
56120
|
+
return { left, leftMore: total - left.length };
|
|
54746
56121
|
}
|
|
54747
56122
|
planItem(row, check3, undoing, state) {
|
|
54748
56123
|
const table = row.entityType === "page" ? pages : cards;
|
|
@@ -54756,6 +56131,7 @@ var UndoService = class {
|
|
|
54756
56131
|
entityTitle: title ?? (typeof row.meta.title === "string" ? row.meta.title : ""),
|
|
54757
56132
|
status: check3.status,
|
|
54758
56133
|
...check3.reason ? { reason: check3.reason } : {},
|
|
56134
|
+
...check3.trashKey ? { trashKey: check3.trashKey } : {},
|
|
54759
56135
|
...check3.status === "conflict" ? { changedBy: check3.by !== void 0 ? check3.by : this.changedSince(row, check3.exists === void 0, undoing, state), current: check3.current ?? null } : {}
|
|
54760
56136
|
};
|
|
54761
56137
|
}
|
|
@@ -54807,7 +56183,15 @@ var UndoService = class {
|
|
|
54807
56183
|
laterChanges(row, isValue, undoing, state) {
|
|
54808
56184
|
const author = /* @__PURE__ */ __name((r) => r.kind === "agent" ? `agent:${r.tokenId}` : `user:${r.userId}`, "author");
|
|
54809
56185
|
const own2 = author({ kind: row.actorKind, userId: row.actorUserId, tokenId: row.actorTokenId });
|
|
54810
|
-
|
|
56186
|
+
const after = /* @__PURE__ */ __name(() => or(gt(history.updatedAt, row.updatedAt), and(eq(history.updatedAt, row.updatedAt), sql`rowid > ${row.seq}`)), "after");
|
|
56187
|
+
const later = this.deps.db.select({ id: history.id, kind: history.actorKind, userId: history.actorUserId, tokenId: history.actorTokenId, name: history.actorName, meta: history.meta }).from(history).where(and(this.sameThing(row, isValue, state), after())).orderBy(desc(history.updatedAt), desc(sql`rowid`)).all().filter((r) => !undoing.has(r.id) && !undoing.has(String(r.meta.undoOf)));
|
|
56188
|
+
const undoneIds = [...new Set(later.map((r) => r.meta.undoOf).filter((v) => typeof v === "string"))];
|
|
56189
|
+
const theirs = /* @__PURE__ */ new Set();
|
|
56190
|
+
for (let i2 = 0; i2 < undoneIds.length; i2 += CHUNK) {
|
|
56191
|
+
const undone = this.deps.db.select({ id: history.id, kind: history.actorKind, userId: history.actorUserId, tokenId: history.actorTokenId }).from(history).where(and(inArray(history.id, undoneIds.slice(i2, i2 + CHUNK)), after())).all();
|
|
56192
|
+
for (const r of undone) if (author(r) === own2) theirs.add(r.id);
|
|
56193
|
+
}
|
|
56194
|
+
return later.filter((r) => !theirs.has(String(r.meta.undoOf)) && (isValue || author(r) !== own2));
|
|
54811
56195
|
}
|
|
54812
56196
|
/** Who changed it after this change, besides the changes being undone with it. */
|
|
54813
56197
|
changedSince(row, isValue, undoing, state) {
|
|
@@ -54836,11 +56220,20 @@ var UndoService = class {
|
|
|
54836
56220
|
const id3 = typeof row.meta.trashId === "string" ? row.meta.trashId : null;
|
|
54837
56221
|
return id3 !== null && Boolean(this.deps.db.select({ id: trash.id }).from(trash).where(eq(trash.id, id3)).get());
|
|
54838
56222
|
}
|
|
56223
|
+
/** The key of `kind:id` in this workspace's trash, when it is there. */
|
|
56224
|
+
inTrash(workspaceId, kind, id3) {
|
|
56225
|
+
if (!id3) return null;
|
|
56226
|
+
const table = TRASH_TABLES[kind];
|
|
56227
|
+
const found = this.deps.db.get(
|
|
56228
|
+
sql`SELECT 1 AS found FROM trash_rows r JOIN trash t ON t.id = r.trash_id WHERE t.workspace_id = ${workspaceId} AND r.table_name = ${table} AND json_extract(r.data, '$.id') = ${id3} LIMIT 1`
|
|
56229
|
+
);
|
|
56230
|
+
return found ? `${kind}:${id3}` : null;
|
|
56231
|
+
}
|
|
54839
56232
|
/**
|
|
54840
|
-
*
|
|
54841
|
-
*
|
|
54842
|
-
*
|
|
54843
|
-
*
|
|
56233
|
+
* Whether the page or card a deletion took away can go back where it was: undoing never puts
|
|
56234
|
+
* it anywhere else. Its place is there, or comes back with the newer changes being undone
|
|
56235
|
+
* (`state.restoring`); a card follows its column if that went to another board. Otherwise:
|
|
56236
|
+
* that place is in the trash (with its key there) or gone for good.
|
|
54844
56237
|
*/
|
|
54845
56238
|
returnPlace(row, state) {
|
|
54846
56239
|
const db = this.deps.db;
|
|
@@ -54848,21 +56241,23 @@ var UndoService = class {
|
|
|
54848
56241
|
const [kept] = this.keptRows(/* @__PURE__ */ new Set([trashId]), row.entityType === "page" ? "pages" : "cards", "id", row.entityId);
|
|
54849
56242
|
if (!kept) return void 0;
|
|
54850
56243
|
const data = kept.data;
|
|
56244
|
+
const missing = /* @__PURE__ */ __name((kind, id3) => {
|
|
56245
|
+
const trashKey2 = this.inTrash(row.workspaceId, kind, id3);
|
|
56246
|
+
return trashKey2 ? { reason: "place_in_trash", trashKey: trashKey2 } : { reason: "place_gone" };
|
|
56247
|
+
}, "missing");
|
|
54851
56248
|
if (row.entityType === "page") {
|
|
54852
56249
|
const parentId = data.parent_id == null ? null : String(data.parent_id);
|
|
54853
|
-
|
|
54854
|
-
|
|
54855
|
-
|
|
54856
|
-
|
|
54857
|
-
|
|
54858
|
-
|
|
54859
|
-
|
|
54860
|
-
|
|
54861
|
-
const
|
|
54862
|
-
|
|
54863
|
-
|
|
54864
|
-
const target = first(sql`c.board_id = ${data.board_id}`) ?? first(sql`c.workspace_id = ${row.workspaceId}`);
|
|
54865
|
-
return target ? { boardId: target.board_id, columnId: target.id } : null;
|
|
56250
|
+
if (parentId !== null) {
|
|
56251
|
+
const there = Boolean(db.get(sql`SELECT 1 AS found FROM pages WHERE id = ${parentId}`)) || this.keptRows(state.restoring, "pages", "id", parentId).length > 0;
|
|
56252
|
+
return there ? void 0 : missing("page", parentId);
|
|
56253
|
+
}
|
|
56254
|
+
const projectId = String(data.project_id);
|
|
56255
|
+
return db.get(sql`SELECT 1 AS found FROM projects WHERE id = ${projectId}`) ? void 0 : missing("project", projectId);
|
|
56256
|
+
}
|
|
56257
|
+
const columnId = String(data.column_id);
|
|
56258
|
+
const column2 = db.get(sql`SELECT board_id FROM board_columns WHERE id = ${columnId}`);
|
|
56259
|
+
if (!column2) return missing("column", columnId);
|
|
56260
|
+
return column2.board_id === data.board_id ? void 0 : { boardId: column2.board_id, columnId };
|
|
54866
56261
|
}
|
|
54867
56262
|
/** How undoing this change stands, against `state`: now, and after the newer changes being undone. */
|
|
54868
56263
|
check(row, undoing, state) {
|
|
@@ -54895,10 +56290,13 @@ var UndoService = class {
|
|
|
54895
56290
|
if (status === "ready") state.exists.set(key, false);
|
|
54896
56291
|
return { status, exists: false };
|
|
54897
56292
|
}, "takeAway");
|
|
54898
|
-
const value = /* @__PURE__ */ __name((current, same = (a, b) => a === b, place, key = fieldKey(row), back = before) => {
|
|
56293
|
+
const value = /* @__PURE__ */ __name((current, same = (a, b) => a === b, place, key = fieldKey(row), back = before, inTrash) => {
|
|
54899
56294
|
const now = state.values.has(key) ? state.values.get(key) : current;
|
|
54900
56295
|
if (same(now, back)) return { status: "unchanged" };
|
|
54901
|
-
if (place && !place())
|
|
56296
|
+
if (place && !place()) {
|
|
56297
|
+
const trashKey2 = inTrash?.();
|
|
56298
|
+
return trashKey2 ? { status: "impossible", reason: "place_in_trash", trashKey: trashKey2 } : { status: "impossible", reason: "place_gone" };
|
|
56299
|
+
}
|
|
54902
56300
|
const status = same(now, after) ? "ready" : "conflict";
|
|
54903
56301
|
if (status === "ready") state.values.set(key, back);
|
|
54904
56302
|
return { status, current: now };
|
|
@@ -54921,7 +56319,7 @@ var UndoService = class {
|
|
|
54921
56319
|
case "card.deleted": {
|
|
54922
56320
|
if (has(entityKey, () => entityExists)) return { status: "unchanged" };
|
|
54923
56321
|
const place = this.returnPlace(row, state);
|
|
54924
|
-
if (place
|
|
56322
|
+
if (place && "reason" in place) return { status: "impossible", ...place };
|
|
54925
56323
|
const check3 = bringBack(entityKey, () => entityExists);
|
|
54926
56324
|
if (check3.status === "ready" && place) state.values.set(`${row.entityId}|${row.entityType}.moved|`, place);
|
|
54927
56325
|
return check3;
|
|
@@ -54949,7 +56347,14 @@ var UndoService = class {
|
|
|
54949
56347
|
const id3 = back?.pageId ?? back?.cardId ?? "";
|
|
54950
56348
|
return Boolean(one(db.select({ id: table.id }).from(table).where(and(eq(table.id, id3), eq(table.workspaceId, at.workspaceId))))) || kept(back?.pageId ? "pages" : "cards", id3).some(({ data }) => data.workspace_id === at.workspaceId);
|
|
54951
56349
|
}, "there");
|
|
54952
|
-
return value(
|
|
56350
|
+
return value(
|
|
56351
|
+
{ cardId: at.cardId, pageId: at.pageId },
|
|
56352
|
+
(a, b) => fileAt(a) === fileAt(b),
|
|
56353
|
+
there,
|
|
56354
|
+
key,
|
|
56355
|
+
before,
|
|
56356
|
+
() => this.inTrash(row.workspaceId, back?.pageId ? "page" : "card", back?.pageId ?? back?.cardId ?? null)
|
|
56357
|
+
);
|
|
54953
56358
|
}
|
|
54954
56359
|
}
|
|
54955
56360
|
if (row.entityType === "page") {
|
|
@@ -54970,7 +56375,10 @@ var UndoService = class {
|
|
|
54970
56375
|
{ projectId: page.projectId, parentId: page.parentId },
|
|
54971
56376
|
(a, b) => parentOf(a) === parentOf(b),
|
|
54972
56377
|
// Its old parent: there, or coming back from the trash first.
|
|
54973
|
-
() => target === null || Boolean(one(db.select({ id: pages.id }).from(pages).where(and(eq(pages.id, target ?? ""), eq(pages.projectId, page.projectId))))) || kept("pages", target ?? "").some(({ data }) => data.project_id === page.projectId)
|
|
56378
|
+
() => target === null || Boolean(one(db.select({ id: pages.id }).from(pages).where(and(eq(pages.id, target ?? ""), eq(pages.projectId, page.projectId))))) || kept("pages", target ?? "").some(({ data }) => data.project_id === page.projectId),
|
|
56379
|
+
fieldKey(row),
|
|
56380
|
+
before,
|
|
56381
|
+
() => this.inTrash(row.workspaceId, "page", target ?? null)
|
|
54974
56382
|
);
|
|
54975
56383
|
}
|
|
54976
56384
|
}
|
|
@@ -55021,7 +56429,10 @@ var UndoService = class {
|
|
|
55021
56429
|
{ boardId: card.boardId, columnId: card.columnId },
|
|
55022
56430
|
(a, b) => columnOf(a) === columnOf(b),
|
|
55023
56431
|
// Its old column, on its board or another one of the same workspace.
|
|
55024
|
-
() => Boolean(one(db.select({ id: columns.id }).from(columns).where(and(eq(columns.id, target ?? ""), eq(columns.workspaceId, card.workspaceId)))))
|
|
56432
|
+
() => Boolean(one(db.select({ id: columns.id }).from(columns).where(and(eq(columns.id, target ?? ""), eq(columns.workspaceId, card.workspaceId))))),
|
|
56433
|
+
key,
|
|
56434
|
+
before,
|
|
56435
|
+
() => this.inTrash(row.workspaceId, "column", target ?? null)
|
|
55025
56436
|
);
|
|
55026
56437
|
const toOtherBoard = before?.boardId !== void 0 && before.boardId !== place.boardId;
|
|
55027
56438
|
if (check3.status !== "ready" || !toOtherBoard) return check3;
|
|
@@ -55810,7 +57221,9 @@ var OrqevioCopy = class extends DurableObject {
|
|
|
55810
57221
|
app;
|
|
55811
57222
|
constructor(ctx, env) {
|
|
55812
57223
|
super(ctx, env);
|
|
55813
|
-
|
|
57224
|
+
const problem = workerConfigProblem(env);
|
|
57225
|
+
if (problem) console.error(`Orqevio can't serve requests: ${problem}`);
|
|
57226
|
+
this.config = workerEnv(problem ? { ...env, APP_URL: void 0 } : env);
|
|
55814
57227
|
const db = drizzle(ctx.storage, { schema: schema_exports });
|
|
55815
57228
|
this.services = createServices({
|
|
55816
57229
|
db,
|
|
@@ -55898,10 +57311,17 @@ var OrqevioCopy = class extends DurableObject {
|
|
|
55898
57311
|
};
|
|
55899
57312
|
|
|
55900
57313
|
// src/worker/index.ts
|
|
57314
|
+
var logged = null;
|
|
55901
57315
|
var TO_COPY = /^\/(?:api\/|mcp$|healthz$|oauth\/(?:register|token|revoke)$|\.well-known\/)/;
|
|
55902
57316
|
var index_default = {
|
|
55903
57317
|
async fetch(request, env) {
|
|
55904
57318
|
const url2 = new URL(request.url);
|
|
57319
|
+
const problem = workerConfigProblem(env);
|
|
57320
|
+
if (problem) {
|
|
57321
|
+
if (logged !== problem) console.error(`Orqevio can't start: ${problem}`);
|
|
57322
|
+
logged = problem;
|
|
57323
|
+
return misconfigured(request, problem);
|
|
57324
|
+
}
|
|
55905
57325
|
if (TO_COPY.test(url2.pathname)) return env.COPY.getByName("copy").fetch(request);
|
|
55906
57326
|
const response = await env.ASSETS.fetch(request);
|
|
55907
57327
|
const headers = new Headers(response.headers);
|