@narumitw/pi-sync 0.59.0 → 0.60.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/CHANGELOG.md +15 -0
- package/README.md +19 -10
- package/dist/chunks/{chunk-AMJRUXFT.ts → chunk-2JNFEZ3V.ts} +2 -6
- package/dist/chunks/{chunk-AMJRUXFT.ts.map → chunk-2JNFEZ3V.ts.map} +1 -1
- package/dist/chunks/{chunk-NGW4JMBF.ts → chunk-4RNCZZY7.ts} +33 -27
- package/dist/chunks/{chunk-NGW4JMBF.ts.map → chunk-4RNCZZY7.ts.map} +3 -3
- package/dist/chunks/{config-J5VZUY4J.ts → chunk-7AC2RX4M.ts} +6 -13
- package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
- package/dist/chunks/{chunk-76HID27T.ts → chunk-BGGKHHO4.ts} +18 -14
- package/dist/chunks/{chunk-76HID27T.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
- package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
- package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
- package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
- package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
- package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
- package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
- package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
- package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
- package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
- package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
- package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
- package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
- package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
- package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
- package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
- package/dist/chunks/chunk-JZKCOM62.ts +26 -0
- package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
- package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
- package/dist/chunks/chunk-M7RHV3H6.ts.map +7 -0
- package/dist/chunks/{chunk-2ZZJXITS.ts → chunk-MIXZVHFR.ts} +24 -10
- package/dist/chunks/chunk-MIXZVHFR.ts.map +7 -0
- package/dist/chunks/chunk-NPT2G4FU.ts +15 -0
- package/dist/chunks/chunk-NPT2G4FU.ts.map +7 -0
- package/dist/chunks/chunk-PDBTD2K6.ts +11 -0
- package/dist/chunks/chunk-PDBTD2K6.ts.map +7 -0
- package/dist/chunks/chunk-UBE6XWOM.ts +29 -0
- package/dist/chunks/chunk-UBE6XWOM.ts.map +7 -0
- package/dist/chunks/{chunk-PQ75RPUP.ts → chunk-UZUUUY7C.ts} +8 -8
- package/dist/chunks/chunk-VZCWYXRS.ts +23 -0
- package/dist/chunks/chunk-VZCWYXRS.ts.map +7 -0
- package/dist/chunks/{chunk-DTPELCPW.ts → chunk-YWEYRRQI.ts} +45 -37
- package/dist/chunks/chunk-YWEYRRQI.ts.map +7 -0
- package/dist/chunks/{chunk-ECYCNZOE.ts → chunk-ZMNVNECV.ts} +5 -1
- package/dist/chunks/chunk-ZMNVNECV.ts.map +7 -0
- package/dist/chunks/{command-handler-SDGKIQH2.ts → command-handler-3O76V7Q5.ts} +80 -86
- package/dist/chunks/command-handler-3O76V7Q5.ts.map +7 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts +18 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts.map +7 -0
- package/dist/chunks/{continuous-record-OM64J27R.ts → continuous-record-ZHUXVO4E.ts} +5 -13
- package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
- package/dist/chunks/{file-selection-7HEVPO4T.ts → file-selection-S6CNNNQI.ts} +11 -14
- package/dist/chunks/{file-selection-7HEVPO4T.ts.map → file-selection-S6CNNNQI.ts.map} +1 -1
- package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
- package/dist/chunks/{manager-ui-65ZETN6F.ts → manager-ui-SJOBTJLY.ts} +80 -123
- package/dist/chunks/manager-ui-SJOBTJLY.ts.map +7 -0
- package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
- package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
- package/dist/chunks/{setup-switch-AB27ADDI.ts → setup-switch-M3BAFGJM.ts} +9 -13
- package/dist/chunks/{setup-wizard-5FILKFLQ.ts → setup-wizard-NFAWP4KF.ts} +18 -21
- package/dist/chunks/{setup-wizard-5FILKFLQ.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
- package/dist/chunks/{snapshot-G3W2GOGB.ts → snapshot-D4SFDP5J.ts} +8 -13
- package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
- package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
- package/dist/chunks/{sync-state-H4TFZZ7S.ts → sync-state-FVCJJ7MY.ts} +5 -11
- package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
- package/dist/index.ts +269 -313
- package/dist/index.ts.map +4 -4
- package/docs/daemon-migration.md +93 -0
- package/package.json +3 -6
- package/skills/configure-pi-sync/SKILL.md +1 -1
- package/skills/configure-pi-sync/references/configuration.md +19 -6
- package/src/backends/backend-factory.ts +2 -23
- package/src/backends/backend-identity.ts +5 -40
- package/src/backends/backend-types.ts +1 -81
- package/src/backends/git/git-backend.ts +6 -784
- package/src/backends/git/git-config.ts +8 -130
- package/src/backends/git/git-runner.ts +7 -255
- package/src/backends/git/git-storage.ts +14 -293
- package/src/backends/s3/s3-backend.ts +11 -523
- package/src/backends/s3/s3-client.ts +2 -399
- package/src/backends/s3/s3-conditions.ts +2 -67
- package/src/backends/snapshot-pointer.ts +2 -27
- package/src/backends/sync-backend.ts +6 -101
- package/src/backends/webdav/webdav-backend.ts +10 -622
- package/src/backends/webdav/webdav-client.ts +6 -370
- package/src/backends/webdav/webdav-config.ts +8 -82
- package/src/commands/command-execution.ts +40 -36
- package/src/commands/command.ts +23 -1
- package/src/daemon/apply-gate.ts +146 -0
- package/src/daemon/pi-client.ts +591 -0
- package/src/daemon/recovery.ts +103 -0
- package/src/paths.ts +12 -83
- package/src/settings/config-errors.ts +2 -6
- package/src/settings/config-file.ts +19 -693
- package/src/settings/config.ts +16 -263
- package/src/settings/settings-management.ts +11 -254
- package/src/settings/settings-store.ts +10 -48
- package/src/settings/settings-types.ts +1 -157
- package/src/settings/settings-validation.ts +17 -435
- package/src/snapshot/session-paths.ts +11 -111
- package/src/snapshot/snapshot-apply.ts +9 -322
- package/src/snapshot/snapshot-case-replacement.ts +6 -80
- package/src/snapshot/snapshot-codec.ts +2 -59
- package/src/snapshot/snapshot-exclude-safety.ts +2 -44
- package/src/snapshot/snapshot-mutation-queues.ts +6 -142
- package/src/snapshot/snapshot-paths.ts +2 -11
- package/src/snapshot/snapshot-root-transition.ts +6 -154
- package/src/snapshot/snapshot-transaction-directory.ts +5 -16
- package/src/snapshot/snapshot-transaction-plan.ts +2 -72
- package/src/snapshot/snapshot-transaction.ts +6 -946
- package/src/snapshot/snapshot-types.ts +1 -43
- package/src/snapshot/snapshot.ts +19 -447
- package/src/state/json-file.ts +2 -47
- package/src/state/lock-policy.ts +2 -2
- package/src/state/lock.ts +10 -292
- package/src/state/lockfile-fs.ts +2 -25
- package/src/state/merge-baseline-store.ts +8 -208
- package/src/state/mutation-directory-sync.ts +2 -34
- package/src/state/operation-availability.ts +7 -59
- package/src/state/state-directory.ts +8 -243
- package/src/state/state-types.ts +1 -25
- package/src/state/sync-state-store.ts +11 -75
- package/src/sync/agent-candidate.ts +7 -256
- package/src/sync/agent-plan.ts +2 -107
- package/src/sync/agent-policy.ts +10 -13
- package/src/sync/agent-refusal-retry.ts +2 -54
- package/src/sync/agent-request.ts +2 -19
- package/src/sync/agent-runner.ts +2 -191
- package/src/sync/agent-store.ts +7 -182
- package/src/sync/agent-sync.ts +2 -141
- package/src/sync/apply-review.ts +2 -63
- package/src/sync/automatic-sync.ts +55 -111
- package/src/sync/conflict-artifact-ownership.ts +2 -63
- package/src/sync/conflict-artifacts.ts +8 -195
- package/src/sync/conflict-groups.ts +2 -68
- package/src/sync/conflict-preview.ts +2 -56
- package/src/sync/conflict-resolution.ts +2 -93
- package/src/sync/conflict-retention.ts +2 -72
- package/src/sync/conflict-review.ts +3 -92
- package/src/sync/content-conflicts.ts +2 -73
- package/src/sync/continuous-errors.ts +7 -85
- package/src/sync/continuous-lease.ts +2 -216
- package/src/sync/continuous-record.ts +10 -261
- package/src/sync/continuous-storage.ts +12 -64
- package/src/sync/continuous-sync.ts +2 -563
- package/src/sync/continuous-watch.ts +2 -61
- package/src/sync/exclude-policy.ts +6 -84
- package/src/sync/field-migration.ts +2 -39
- package/src/sync/file-merge-planner.ts +2 -143
- package/src/sync/json-document.ts +7 -184
- package/src/sync/local-field-policy.ts +2 -29
- package/src/sync/local-fields.ts +9 -119
- package/src/sync/merge-apply.ts +2 -439
- package/src/sync/merge-journal.ts +10 -228
- package/src/sync/merge-transfer-error.ts +2 -72
- package/src/sync/merged-sync.ts +2 -919
- package/src/sync/mutation-owner.ts +2 -22
- package/src/sync/package-merge.ts +2 -87
- package/src/sync/partial-progress.ts +2 -55
- package/src/sync/remote-snapshot.ts +7 -79
- package/src/sync/session-merge.ts +2 -194
- package/src/sync/settings-conflicts.ts +2 -64
- package/src/sync/settings-merge.ts +6 -121
- package/src/sync/signals.ts +2 -8
- package/src/sync/startup-check.ts +15 -31
- package/src/sync/startup-timings.ts +2 -94
- package/src/sync/sync-decision.ts +3 -111
- package/src/sync/sync-error-guidance.ts +2 -46
- package/src/sync/sync-errors.ts +7 -23
- package/src/sync/sync-inspection.ts +10 -59
- package/src/sync/sync-local.ts +2 -44
- package/src/sync/sync-mutations.ts +10 -788
- package/src/sync/sync-operations.ts +32 -11
- package/src/sync/sync-policy.ts +34 -474
- package/src/sync/sync-queries.ts +2 -247
- package/src/sync/sync-state.ts +18 -157
- package/src/sync/text-merge.ts +10 -133
- package/src/sync-extension.ts +192 -142
- package/dist/chunks/agent-candidate-ZHN7FTZT.ts +0 -30
- package/dist/chunks/agent-plan-ILFEUJ2E.ts +0 -124
- package/dist/chunks/agent-plan-ILFEUJ2E.ts.map +0 -7
- package/dist/chunks/agent-refusal-retry-HRMHCX2A.ts +0 -73
- package/dist/chunks/agent-refusal-retry-HRMHCX2A.ts.map +0 -7
- package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
- package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
- package/dist/chunks/agent-store-CCKN4DPR.ts +0 -175
- package/dist/chunks/agent-store-CCKN4DPR.ts.map +0 -7
- package/dist/chunks/agent-sync-EGA2I5W7.ts +0 -22
- package/dist/chunks/chunk-25QCU3LY.ts +0 -220
- package/dist/chunks/chunk-25QCU3LY.ts.map +0 -7
- package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
- package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
- package/dist/chunks/chunk-2UKUKIBI.ts +0 -25
- package/dist/chunks/chunk-2UKUKIBI.ts.map +0 -7
- package/dist/chunks/chunk-2ZZJXITS.ts.map +0 -7
- package/dist/chunks/chunk-3JTZF7Z5.ts +0 -77
- package/dist/chunks/chunk-3JTZF7Z5.ts.map +0 -7
- package/dist/chunks/chunk-3ST7RSYN.ts +0 -21
- package/dist/chunks/chunk-3ST7RSYN.ts.map +0 -7
- package/dist/chunks/chunk-4NVHHDN2.ts +0 -61
- package/dist/chunks/chunk-4NVHHDN2.ts.map +0 -7
- package/dist/chunks/chunk-5SFMBY5P.ts +0 -26
- package/dist/chunks/chunk-5SFMBY5P.ts.map +0 -7
- package/dist/chunks/chunk-6OFMB6KK.ts +0 -215
- package/dist/chunks/chunk-6OFMB6KK.ts.map +0 -7
- package/dist/chunks/chunk-6XU5HZAN.ts +0 -205
- package/dist/chunks/chunk-6XU5HZAN.ts.map +0 -7
- package/dist/chunks/chunk-6YGRZSCN.ts +0 -128
- package/dist/chunks/chunk-6YGRZSCN.ts.map +0 -7
- package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
- package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
- package/dist/chunks/chunk-7WYF2KUO.ts +0 -1161
- package/dist/chunks/chunk-7WYF2KUO.ts.map +0 -7
- package/dist/chunks/chunk-APDNHB2T.ts +0 -2037
- package/dist/chunks/chunk-APDNHB2T.ts.map +0 -7
- package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
- package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
- package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
- package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
- package/dist/chunks/chunk-DTPELCPW.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
- package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
- package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
- package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
- package/dist/chunks/chunk-ILXMZ2HU.ts +0 -58
- package/dist/chunks/chunk-ILXMZ2HU.ts.map +0 -7
- package/dist/chunks/chunk-LA3HQMFG.ts +0 -115
- package/dist/chunks/chunk-LA3HQMFG.ts.map +0 -7
- package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
- package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
- package/dist/chunks/chunk-MKC3PXCN.ts +0 -369
- package/dist/chunks/chunk-MKC3PXCN.ts.map +0 -7
- package/dist/chunks/chunk-OQBE2OMB.ts +0 -88
- package/dist/chunks/chunk-OQBE2OMB.ts.map +0 -7
- package/dist/chunks/chunk-P3YD4ONV.ts +0 -123
- package/dist/chunks/chunk-P3YD4ONV.ts.map +0 -7
- package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
- package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
- package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
- package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
- package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
- package/dist/chunks/chunk-QQVK2XFC.ts +0 -64
- package/dist/chunks/chunk-QQVK2XFC.ts.map +0 -7
- package/dist/chunks/chunk-RDOX3VH5.ts +0 -140
- package/dist/chunks/chunk-RDOX3VH5.ts.map +0 -7
- package/dist/chunks/chunk-S7D6XWHI.ts +0 -258
- package/dist/chunks/chunk-S7D6XWHI.ts.map +0 -7
- package/dist/chunks/chunk-SHPNS7FM.ts +0 -64
- package/dist/chunks/chunk-SHPNS7FM.ts.map +0 -7
- package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
- package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
- package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
- package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
- package/dist/chunks/chunk-T2TYBLXK.ts +0 -27
- package/dist/chunks/chunk-T2TYBLXK.ts.map +0 -7
- package/dist/chunks/chunk-UZSDS4HF.ts +0 -403
- package/dist/chunks/chunk-UZSDS4HF.ts.map +0 -7
- package/dist/chunks/chunk-VPODHKOX.ts +0 -229
- package/dist/chunks/chunk-VPODHKOX.ts.map +0 -7
- package/dist/chunks/chunk-WEKGW7HV.ts +0 -162
- package/dist/chunks/chunk-WEKGW7HV.ts.map +0 -7
- package/dist/chunks/chunk-WUHRVSWI.ts +0 -369
- package/dist/chunks/chunk-WUHRVSWI.ts.map +0 -7
- package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
- package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
- package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
- package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
- package/dist/chunks/chunk-XZ3ZTHKR.ts +0 -1184
- package/dist/chunks/chunk-XZ3ZTHKR.ts.map +0 -7
- package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
- package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
- package/dist/chunks/chunk-YEULK7MK.ts +0 -415
- package/dist/chunks/chunk-YEULK7MK.ts.map +0 -7
- package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
- package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
- package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
- package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
- package/dist/chunks/command-handler-SDGKIQH2.ts.map +0 -7
- package/dist/chunks/conflict-artifacts-MYSH3L2J.ts +0 -33
- package/dist/chunks/conflict-review-J6ZSPNWL.ts +0 -190
- package/dist/chunks/conflict-review-J6ZSPNWL.ts.map +0 -7
- package/dist/chunks/continuous-sync-BH5SWIRV.ts +0 -590
- package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +0 -7
- package/dist/chunks/git-backend-6CKI6CUG.ts +0 -1074
- package/dist/chunks/git-backend-6CKI6CUG.ts.map +0 -7
- package/dist/chunks/local-fields-SR7PH66U.ts +0 -27
- package/dist/chunks/local-fields-SR7PH66U.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts +0 -33
- package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts.map +0 -7
- package/dist/chunks/manager-ui-65ZETN6F.ts.map +0 -7
- package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts +0 -26
- package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-W55BQDJQ.ts +0 -32
- package/dist/chunks/remote-selection-ui-W55BQDJQ.ts.map +0 -7
- package/dist/chunks/s3-backend-FDK7JSDQ.ts +0 -845
- package/dist/chunks/s3-backend-FDK7JSDQ.ts.map +0 -7
- package/dist/chunks/setup-switch-AB27ADDI.ts.map +0 -7
- package/dist/chunks/snapshot-G3W2GOGB.ts.map +0 -7
- package/dist/chunks/snapshot-transaction-SGRUWT73.ts +0 -25
- package/dist/chunks/snapshot-transaction-SGRUWT73.ts.map +0 -7
- package/dist/chunks/sync-inspection-MDYHZHT7.ts +0 -26
- package/dist/chunks/sync-inspection-MDYHZHT7.ts.map +0 -7
- package/dist/chunks/sync-operations-ZAUP65FH.ts +0 -1032
- package/dist/chunks/sync-operations-ZAUP65FH.ts.map +0 -7
- package/dist/chunks/sync-state-H4TFZZ7S.ts.map +0 -7
- package/dist/chunks/webdav-backend-UNMIAXM5.ts +0 -852
- package/dist/chunks/webdav-backend-UNMIAXM5.ts.map +0 -7
- /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
- /package/dist/chunks/{chunk-PQ75RPUP.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
- /package/dist/chunks/{agent-candidate-ZHN7FTZT.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-EGA2I5W7.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
- /package/dist/chunks/{config-J5VZUY4J.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-MYSH3L2J.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-OM64J27R.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
package/src/settings/config.ts
CHANGED
|
@@ -1,263 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "./settings-types.js";
|
|
18
|
-
import {
|
|
19
|
-
DEFAULT_ON_SWITCH,
|
|
20
|
-
isCloudflareR2Endpoint,
|
|
21
|
-
normalizeS3Bucket,
|
|
22
|
-
normalizeS3Endpoint,
|
|
23
|
-
normalizeStoragePath,
|
|
24
|
-
optionalString,
|
|
25
|
-
ownObject,
|
|
26
|
-
requiredString,
|
|
27
|
-
validateConfigName,
|
|
28
|
-
validateSettingsDocument,
|
|
29
|
-
} from "./settings-validation.js";
|
|
30
|
-
|
|
31
|
-
export async function loadConfig(setupName?: string): Promise<AnySyncConfig> {
|
|
32
|
-
return configFromSettings(await requireSettings(), setupName);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** A background freshness read must never trigger legacy-file publication. */
|
|
36
|
-
export async function loadConfigForCheck(): Promise<AnySyncConfig> {
|
|
37
|
-
const document = await readActiveLocalConfigDocumentForRepair();
|
|
38
|
-
if (!document) throw new Error(`Missing pi-sync settings: ${localConfigPath()}`);
|
|
39
|
-
validateSettingsDocument(document.parsed);
|
|
40
|
-
return configFromSettings(document.parsed as PiSyncSettingsV3);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function configFromSettings(settings: PiSyncSettingsV3, setupName?: string): AnySyncConfig {
|
|
44
|
-
const selectedName = setupName ?? settings.activeSyncSetup;
|
|
45
|
-
if (!selectedName) throw new Error("No sync setups are configured.");
|
|
46
|
-
validateConfigName(selectedName, "sync setup");
|
|
47
|
-
const setup = ownObject<SyncSetupSettings>(settings.syncSetups, selectedName);
|
|
48
|
-
if (!setup) throw new Error(`Invalid pi-sync settings: sync setup “${selectedName}” was not found.`);
|
|
49
|
-
const connectionName = setup.storage.connection;
|
|
50
|
-
const connection = ownObject<StorageConnectionSettings>(settings.storageConnections, connectionName);
|
|
51
|
-
if (!connection) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Invalid pi-sync settings: sync setup “${selectedName}” references missing storage connection “${connectionName}”.`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
...resolveSyncConfig(
|
|
58
|
-
selectedName,
|
|
59
|
-
setup,
|
|
60
|
-
connectionName,
|
|
61
|
-
connection,
|
|
62
|
-
settings.onSwitch,
|
|
63
|
-
settings.skipSecretScan ?? false,
|
|
64
|
-
settings.showStatus ?? true,
|
|
65
|
-
),
|
|
66
|
-
debug: settings.debug ?? false,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type SyncSetupStorageReview = Pick<
|
|
71
|
-
PartialConfig,
|
|
72
|
-
"connectionName" | "storageKind" | "storagePath" | "bucket" | "branch"
|
|
73
|
-
>;
|
|
74
|
-
|
|
75
|
-
/** A validated setup-facing projection used by manager and settings UI. */
|
|
76
|
-
export async function loadPartialConfig(setupName?: string): Promise<PartialConfig> {
|
|
77
|
-
const config = await loadConfig(setupName);
|
|
78
|
-
return {
|
|
79
|
-
setupName: config.setupName,
|
|
80
|
-
...storageReviewFromConfig(config),
|
|
81
|
-
include: [...config.include],
|
|
82
|
-
...(config.exclude === undefined ? {} : { exclude: [...config.exclude] }),
|
|
83
|
-
automatic: config.automatic,
|
|
84
|
-
automaticTransfer: config.automaticTransfer ?? false,
|
|
85
|
-
agentMode: config.agentMode ?? false,
|
|
86
|
-
continuous: config.continuous ?? false,
|
|
87
|
-
onSwitch: config.onSwitch,
|
|
88
|
-
showStatus: config.showStatus,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function syncSetupStorageReview(
|
|
93
|
-
setupName: string,
|
|
94
|
-
setup: SyncSetupSettings,
|
|
95
|
-
connectionName: string,
|
|
96
|
-
connection: StorageConnectionSettings,
|
|
97
|
-
): SyncSetupStorageReview {
|
|
98
|
-
return storageReviewFromConfig(
|
|
99
|
-
resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true),
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function syncSetupReviewIdentity(
|
|
104
|
-
setupName: string,
|
|
105
|
-
setup: SyncSetupSettings,
|
|
106
|
-
connectionName: string,
|
|
107
|
-
connection: StorageConnectionSettings,
|
|
108
|
-
) {
|
|
109
|
-
return syncConfigReviewIdentity(
|
|
110
|
-
resolveSyncConfig(setupName, setup, connectionName, connection, DEFAULT_ON_SWITCH, false, true),
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function syncConfigReviewIdentity(config: AnySyncConfig) {
|
|
115
|
-
return JSON.stringify([
|
|
116
|
-
config.setupName,
|
|
117
|
-
config.connectionName,
|
|
118
|
-
backendIdentityCoordinates(config),
|
|
119
|
-
config.include,
|
|
120
|
-
config.automatic,
|
|
121
|
-
config.automaticTransfer ?? false,
|
|
122
|
-
config.agentMode ?? false,
|
|
123
|
-
config.localFields,
|
|
124
|
-
config.mergeSettings ?? false,
|
|
125
|
-
config.mergeContent ?? false,
|
|
126
|
-
config.partialSync ?? false,
|
|
127
|
-
// Preserve existing Off identities and cached candidates across the upgrade.
|
|
128
|
-
...(config.continuous ? ["continuous"] : []),
|
|
129
|
-
...(config.exclude === undefined
|
|
130
|
-
? []
|
|
131
|
-
: ["exclude", normalizeSyncExclude(config.exclude).map((rule) => rule.toLowerCase())]),
|
|
132
|
-
]);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function syncConfigReviewFingerprint(config: AnySyncConfig) {
|
|
136
|
-
return createHash("sha256").update(syncConfigReviewIdentity(config)).digest("hex");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Internal freshness token, including credentials; never display or persist it. */
|
|
140
|
-
export function syncCheckConfigFingerprint(config: AnySyncConfig) {
|
|
141
|
-
return createHash("sha256")
|
|
142
|
-
.update(JSON.stringify({ ...config, showStatus: undefined, debug: undefined }))
|
|
143
|
-
.digest("hex");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function storageReviewFromConfig(config: AnySyncConfig): SyncSetupStorageReview {
|
|
147
|
-
return {
|
|
148
|
-
connectionName: config.connectionName,
|
|
149
|
-
storageKind: config.backend.type,
|
|
150
|
-
storagePath: config.storagePath,
|
|
151
|
-
...(config.backend.type === "s3"
|
|
152
|
-
? { bucket: config.backend.destination.bucket }
|
|
153
|
-
: config.backend.type === "git"
|
|
154
|
-
? { branch: config.backend.destination.branch }
|
|
155
|
-
: {}),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function resolveSyncConfig(
|
|
160
|
-
setupName: string,
|
|
161
|
-
setup: SyncSetupSettings,
|
|
162
|
-
connectionName: string,
|
|
163
|
-
connection: StorageConnectionSettings,
|
|
164
|
-
onSwitch: OnSwitchAction,
|
|
165
|
-
skipSecretScan: boolean,
|
|
166
|
-
showStatus: boolean,
|
|
167
|
-
): AnySyncConfig {
|
|
168
|
-
const storagePath = normalizeStoragePath(setup.storage.path);
|
|
169
|
-
const namespace = storagePath === "./" ? "root" : storagePath.slice(storagePath.lastIndexOf("/") + 1);
|
|
170
|
-
const include = normalizeSyncInclude(setup.sync.include);
|
|
171
|
-
const common = {
|
|
172
|
-
setupName,
|
|
173
|
-
connectionName,
|
|
174
|
-
storagePath,
|
|
175
|
-
snapshotIdentity: namespace,
|
|
176
|
-
include,
|
|
177
|
-
...(setup.sync.exclude === undefined ? {} : { exclude: normalizeSyncExclude(setup.sync.exclude) }),
|
|
178
|
-
automatic: setup.sync.automatic,
|
|
179
|
-
automaticTransfer: setup.sync.automaticTransfer ?? false,
|
|
180
|
-
agentMode: setup.sync.agentMode ?? false,
|
|
181
|
-
continuous: setup.sync.continuous ?? false,
|
|
182
|
-
localFields: setup.sync.localFields === undefined ? undefined : normalizeLocalFields(setup.sync.localFields),
|
|
183
|
-
mergeSettings: setup.sync.mergeSettings ?? false,
|
|
184
|
-
mergeContent: setup.sync.mergeContent ?? false,
|
|
185
|
-
partialSync: setup.sync.partialSync ?? false,
|
|
186
|
-
onSwitch,
|
|
187
|
-
skipSecretScan,
|
|
188
|
-
showStatus,
|
|
189
|
-
};
|
|
190
|
-
if (connection.type === "git") {
|
|
191
|
-
return {
|
|
192
|
-
...common,
|
|
193
|
-
backend: {
|
|
194
|
-
type: "git",
|
|
195
|
-
profile: { kind: "git", remote: normalizeGitRemote(connection.remote) as string },
|
|
196
|
-
destination: {
|
|
197
|
-
branch: normalizeGitBranch(setup.storage.branch),
|
|
198
|
-
directory: normalizeGitDirectory(storagePath),
|
|
199
|
-
namespace,
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
if (connection.type === "webdav") {
|
|
205
|
-
return {
|
|
206
|
-
...common,
|
|
207
|
-
backend: {
|
|
208
|
-
type: "webdav",
|
|
209
|
-
profile: {
|
|
210
|
-
kind: "webdav",
|
|
211
|
-
url: normalizeWebDavUrl(connection.url) as string,
|
|
212
|
-
username: connection.credentials.username,
|
|
213
|
-
password: connection.credentials.password,
|
|
214
|
-
},
|
|
215
|
-
destination: { path: normalizeWebDavPath(storagePath), namespace },
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
...common,
|
|
221
|
-
backend: {
|
|
222
|
-
type: "s3",
|
|
223
|
-
profile: {
|
|
224
|
-
kind: isCloudflareR2Endpoint(connection.endpoint) ? "r2" : "s3-compatible",
|
|
225
|
-
endpoint: normalizeS3Endpoint(connection.endpoint),
|
|
226
|
-
region: requiredString(connection.region, "S3 region"),
|
|
227
|
-
accessKeyId: connection.credentials.accessKeyId,
|
|
228
|
-
secretAccessKey: connection.credentials.secretAccessKey,
|
|
229
|
-
sessionToken: optionalString(connection.credentials.sessionToken, "S3 session token"),
|
|
230
|
-
},
|
|
231
|
-
destination: {
|
|
232
|
-
bucket: normalizeS3Bucket(setup.storage.bucket),
|
|
233
|
-
prefix: storagePath,
|
|
234
|
-
namespace,
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export function sessionTokenWarnings(config: { endpoint?: string; sessionToken?: string }) {
|
|
241
|
-
if (!isCloudflareR2Endpoint(config.endpoint) || !config.sessionToken) return [];
|
|
242
|
-
return [
|
|
243
|
-
"session token: configured for Cloudflare R2; if R2 rejects X-Amz-Security-Token, pi-sync retries once without it. R2 static access keys usually do not need a session token.",
|
|
244
|
-
];
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function syncSessionsWarnings(config: { include: readonly string[]; exclude?: readonly string[] }) {
|
|
248
|
-
if (!syncSessionsSelected(config)) return [];
|
|
249
|
-
return [
|
|
250
|
-
"sessions: included; Pi session JSONL can contain prompts, tool output, file paths, images, and secrets. Sync sessions only to storage you trust.",
|
|
251
|
-
];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export function isEnabled(value: boolean | string | undefined, defaultValue: boolean) {
|
|
255
|
-
if (value === undefined) return defaultValue;
|
|
256
|
-
if (typeof value === "boolean") return value;
|
|
257
|
-
return !["0", "false", "no", "off"].includes(value.trim().toLowerCase());
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function isExplicitlyEnabled(value: boolean | string | undefined) {
|
|
261
|
-
if (typeof value === "boolean") return value;
|
|
262
|
-
return ["1", "true", "yes", "on"].includes(value?.trim().toLowerCase() ?? "");
|
|
263
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/settings/config";
|
|
2
|
+
export {
|
|
3
|
+
configFromSettings,
|
|
4
|
+
isEnabled,
|
|
5
|
+
isExplicitlyEnabled,
|
|
6
|
+
loadConfig,
|
|
7
|
+
loadConfigForCheck,
|
|
8
|
+
loadPartialConfig,
|
|
9
|
+
sessionTokenWarnings,
|
|
10
|
+
syncCheckConfigFingerprint,
|
|
11
|
+
syncConfigReviewFingerprint,
|
|
12
|
+
syncConfigReviewIdentity,
|
|
13
|
+
syncSessionsWarnings,
|
|
14
|
+
syncSetupReviewIdentity,
|
|
15
|
+
syncSetupStorageReview,
|
|
16
|
+
} from "@narumitw/sync-daemon/engine/settings/config";
|
|
@@ -1,254 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { effectiveSyncSetupRemoteIdentity, validateConfigName } from "./settings-validation.js";
|
|
13
|
-
|
|
14
|
-
export class SyncSetupReviewChangedError extends Error {
|
|
15
|
-
constructor(message: string) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = "SyncSetupReviewChangedError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function saveNewV3Settings(
|
|
22
|
-
input: {
|
|
23
|
-
setupName: string;
|
|
24
|
-
connectionName: string;
|
|
25
|
-
connection: StorageConnectionSettings;
|
|
26
|
-
setup: SyncSetupSettings;
|
|
27
|
-
},
|
|
28
|
-
signal?: AbortSignal,
|
|
29
|
-
) {
|
|
30
|
-
validateConfigName(input.setupName, "sync setup");
|
|
31
|
-
validateConfigName(input.connectionName, "storage connection");
|
|
32
|
-
const settings: PiSyncSettingsV3 = {
|
|
33
|
-
version: 3,
|
|
34
|
-
activeSyncSetup: input.setupName,
|
|
35
|
-
onSwitch: "ask-before-pull",
|
|
36
|
-
skipSecretScan: false,
|
|
37
|
-
storageConnections: { [input.connectionName]: structuredClone(input.connection) },
|
|
38
|
-
syncSetups: {
|
|
39
|
-
[input.setupName]: {
|
|
40
|
-
...structuredClone(input.setup),
|
|
41
|
-
storage: { ...input.setup.storage, connection: input.connectionName },
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
return updateLocalConfig((current) => {
|
|
46
|
-
if (Object.keys(current.storageConnections).length || Object.keys(current.syncSetups).length) {
|
|
47
|
-
throw new Error(`Settings already exist: ${localConfigPath()}`);
|
|
48
|
-
}
|
|
49
|
-
return { ...current, ...settings };
|
|
50
|
-
}, signal);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function addStorageConnection(name: string, connection: StorageConnectionSettings, signal?: AbortSignal) {
|
|
54
|
-
validateConfigName(name, "storage connection");
|
|
55
|
-
await updateSettings((settings) => {
|
|
56
|
-
if (Object.hasOwn(settings.storageConnections, name)) {
|
|
57
|
-
throw new Error(`Storage connection already exists: ${name}`);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
...settings,
|
|
61
|
-
storageConnections: {
|
|
62
|
-
...settings.storageConnections,
|
|
63
|
-
[name]: structuredClone(connection),
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}, signal);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function updateStorageConnection(
|
|
70
|
-
name: string,
|
|
71
|
-
update: (connection: StorageConnectionSettings) => StorageConnectionSettings,
|
|
72
|
-
expectedSetups?: readonly string[],
|
|
73
|
-
signal?: AbortSignal,
|
|
74
|
-
) {
|
|
75
|
-
validateConfigName(name, "storage connection");
|
|
76
|
-
await updateSettings((settings) => {
|
|
77
|
-
const connection = settings.storageConnections[name];
|
|
78
|
-
if (!connection) throw new Error(`Storage connection not found: ${name}`);
|
|
79
|
-
const currentSetups = referencingSetupNames(settings.syncSetups, name);
|
|
80
|
-
if (expectedSetups && !sameNames(currentSetups, expectedSetups)) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Storage connection “${name}” usage changed while it was open; reopen it and review the affected sync setups.`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
const nextConnection = update(structuredClone(connection));
|
|
86
|
-
const nextConnections = { ...settings.storageConnections, [name]: nextConnection };
|
|
87
|
-
assertUniqueLocations(settings.syncSetups, nextConnections);
|
|
88
|
-
return { ...settings, storageConnections: nextConnections };
|
|
89
|
-
}, signal);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function addSyncSetup(
|
|
93
|
-
name: string,
|
|
94
|
-
setup: SyncSetupSettings,
|
|
95
|
-
signal?: AbortSignal,
|
|
96
|
-
expectedConnection?: StorageConnectionSettings,
|
|
97
|
-
) {
|
|
98
|
-
validateConfigName(name, "sync setup");
|
|
99
|
-
await updateSettings((settings) => {
|
|
100
|
-
if (Object.hasOwn(settings.syncSetups, name)) throw new Error(`Sync setup already exists: ${name}`);
|
|
101
|
-
if (!Object.hasOwn(settings.storageConnections, setup.storage.connection)) {
|
|
102
|
-
throw new Error(`Storage connection not found: ${setup.storage.connection}`);
|
|
103
|
-
}
|
|
104
|
-
if (
|
|
105
|
-
expectedConnection &&
|
|
106
|
-
!isDeepStrictEqual(settings.storageConnections[setup.storage.connection], expectedConnection)
|
|
107
|
-
) {
|
|
108
|
-
throw new SyncSetupReviewChangedError("Storage connection changed while the setup review was open; reopen it.");
|
|
109
|
-
}
|
|
110
|
-
const nextSetups = { ...settings.syncSetups, [name]: structuredClone(setup) };
|
|
111
|
-
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
112
|
-
return {
|
|
113
|
-
...settings,
|
|
114
|
-
syncSetups: nextSetups,
|
|
115
|
-
...(settings.activeSyncSetup ? {} : { activeSyncSetup: name }),
|
|
116
|
-
};
|
|
117
|
-
}, signal);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export async function updateSyncSetup(
|
|
121
|
-
name: string,
|
|
122
|
-
update: (setup: SyncSetupSettings) => SyncSetupSettings,
|
|
123
|
-
options: {
|
|
124
|
-
expectedStorage?: SyncSetupStorageReview;
|
|
125
|
-
expectedInclude?: readonly string[];
|
|
126
|
-
expectedConnection?: StorageConnectionSettings;
|
|
127
|
-
expectedConfigFingerprint?: string;
|
|
128
|
-
upgradeExclude?: boolean;
|
|
129
|
-
signal?: AbortSignal;
|
|
130
|
-
} = {},
|
|
131
|
-
) {
|
|
132
|
-
validateConfigName(name, "sync setup");
|
|
133
|
-
await updateSettings((settings) => {
|
|
134
|
-
const setup = settings.syncSetups[name];
|
|
135
|
-
if (!setup) throw new Error(`Sync setup not found: ${name}`);
|
|
136
|
-
if (
|
|
137
|
-
options.expectedConfigFingerprint !== undefined &&
|
|
138
|
-
syncCheckConfigFingerprint(configFromSettings(settings, name)) !== options.expectedConfigFingerprint
|
|
139
|
-
) {
|
|
140
|
-
throw new SyncSetupReviewChangedError(
|
|
141
|
-
`Sync setup “${name}” changed while it was open; reopen it and review the current configuration.`,
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
if (options.expectedInclude && !sameNames(normalizeSyncInclude(setup.sync.include), options.expectedInclude)) {
|
|
145
|
-
throw new SyncSetupReviewChangedError(
|
|
146
|
-
`Sync setup “${name}” included content changed while it was open; reopen it and review the current selection.`,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
if (options.expectedStorage) {
|
|
150
|
-
const connectionName = setup.storage.connection;
|
|
151
|
-
const connection = settings.storageConnections[connectionName];
|
|
152
|
-
if (
|
|
153
|
-
!connection ||
|
|
154
|
-
!sameStorageReview(syncSetupStorageReview(name, setup, connectionName, connection), options.expectedStorage)
|
|
155
|
-
) {
|
|
156
|
-
throw new SyncSetupReviewChangedError(
|
|
157
|
-
`Sync setup “${name}” storage changed while it was open; reopen it and review the current storage location.`,
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (
|
|
162
|
-
options.expectedConnection &&
|
|
163
|
-
!isDeepStrictEqual(settings.storageConnections[setup.storage.connection], options.expectedConnection)
|
|
164
|
-
) {
|
|
165
|
-
throw new SyncSetupReviewChangedError("Storage connection changed while the setup review was open; reopen it.");
|
|
166
|
-
}
|
|
167
|
-
const nextSetup = update(structuredClone(setup));
|
|
168
|
-
if (!Object.hasOwn(settings.storageConnections, nextSetup.storage.connection)) {
|
|
169
|
-
throw new Error(`Storage connection not found: ${nextSetup.storage.connection}`);
|
|
170
|
-
}
|
|
171
|
-
const nextSetups = { ...settings.syncSetups, [name]: nextSetup };
|
|
172
|
-
assertUniqueLocations(nextSetups, settings.storageConnections);
|
|
173
|
-
return { ...settings, ...(options.upgradeExclude ? { version: 6 as const } : {}), syncSetups: nextSetups };
|
|
174
|
-
}, options.signal);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export async function removeSyncSetup(name: string, signal?: AbortSignal) {
|
|
178
|
-
validateConfigName(name, "sync setup");
|
|
179
|
-
await updateSettings((settings) => {
|
|
180
|
-
if (!Object.hasOwn(settings.syncSetups, name)) throw new Error(`Sync setup not found: ${name}`);
|
|
181
|
-
const isCurrent = settings.activeSyncSetup === name;
|
|
182
|
-
if (isCurrent && Object.keys(settings.syncSetups).length > 1) {
|
|
183
|
-
throw new Error("Switch to another sync setup before removing the current setup.");
|
|
184
|
-
}
|
|
185
|
-
const syncSetups = { ...settings.syncSetups };
|
|
186
|
-
delete syncSetups[name];
|
|
187
|
-
const next = { ...settings, syncSetups };
|
|
188
|
-
if (isCurrent) delete next.activeSyncSetup;
|
|
189
|
-
return next;
|
|
190
|
-
}, signal);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export async function removeStorageConnection(name: string, signal?: AbortSignal) {
|
|
194
|
-
validateConfigName(name, "storage connection");
|
|
195
|
-
await updateSettings((settings) => {
|
|
196
|
-
const referenced = referencingSetupNames(settings.syncSetups, name)[0];
|
|
197
|
-
if (referenced) {
|
|
198
|
-
throw new Error(`Storage connection “${name}” is used by sync setup “${referenced}”.`);
|
|
199
|
-
}
|
|
200
|
-
if (!Object.hasOwn(settings.storageConnections, name)) {
|
|
201
|
-
throw new Error(`Storage connection not found: ${name}`);
|
|
202
|
-
}
|
|
203
|
-
const storageConnections = { ...settings.storageConnections };
|
|
204
|
-
delete storageConnections[name];
|
|
205
|
-
return { ...settings, storageConnections };
|
|
206
|
-
}, signal);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async function updateSettings(update: (settings: PiSyncSettingsV3) => PiSyncSettingsV3, signal?: AbortSignal) {
|
|
210
|
-
return updateLocalConfig((settings) => {
|
|
211
|
-
if (settings.version !== 3 && settings.version !== 4 && settings.version !== 5 && settings.version !== 6) {
|
|
212
|
-
throw new Error("Storage connections and sync setups require version 3, 4, 5 or 6 pi-sync settings.");
|
|
213
|
-
}
|
|
214
|
-
return update(settings);
|
|
215
|
-
}, signal);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function referencingSetupNames(setups: Record<string, SyncSetupSettings>, connection: string) {
|
|
219
|
-
return Object.entries(setups)
|
|
220
|
-
.filter(([, setup]) => setup.storage.connection === connection)
|
|
221
|
-
.map(([name]) => name)
|
|
222
|
-
.sort((left, right) => left.localeCompare(right));
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function assertUniqueLocations(
|
|
226
|
-
setups: Record<string, SyncSetupSettings>,
|
|
227
|
-
connections: Record<string, StorageConnectionSettings>,
|
|
228
|
-
) {
|
|
229
|
-
const identities = new Map<string, string>();
|
|
230
|
-
for (const [name, setup] of Object.entries(setups)) {
|
|
231
|
-
const connection = connections[setup.storage.connection];
|
|
232
|
-
if (!connection) throw new Error(`Storage connection not found: ${setup.storage.connection}`);
|
|
233
|
-
const identity = effectiveSyncSetupRemoteIdentity(setup, connection);
|
|
234
|
-
const previous = identities.get(identity);
|
|
235
|
-
if (previous) {
|
|
236
|
-
throw new Error(`Sync setup “${name}” duplicates the storage location of “${previous}”.`);
|
|
237
|
-
}
|
|
238
|
-
identities.set(identity, name);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function sameNames(left: readonly string[], right: readonly string[]) {
|
|
243
|
-
return left.length === right.length && left.every((name, index) => name === right[index]);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function sameStorageReview(left: SyncSetupStorageReview, right: SyncSetupStorageReview) {
|
|
247
|
-
return (
|
|
248
|
-
left.connectionName === right.connectionName &&
|
|
249
|
-
left.storageKind === right.storageKind &&
|
|
250
|
-
left.storagePath === right.storagePath &&
|
|
251
|
-
left.bucket === right.bucket &&
|
|
252
|
-
left.branch === right.branch
|
|
253
|
-
);
|
|
254
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/settings/settings-management";
|
|
2
|
+
export {
|
|
3
|
+
addStorageConnection,
|
|
4
|
+
addSyncSetup,
|
|
5
|
+
removeStorageConnection,
|
|
6
|
+
removeSyncSetup,
|
|
7
|
+
SyncSetupReviewChangedError,
|
|
8
|
+
saveNewV3Settings,
|
|
9
|
+
updateStorageConnection,
|
|
10
|
+
updateSyncSetup,
|
|
11
|
+
} from "@narumitw/sync-daemon/engine/settings/settings-management";
|
|
@@ -1,48 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function configuredSyncSetupNames() {
|
|
14
|
-
const settings = await readLocalConfigObject();
|
|
15
|
-
return settings ? Object.keys(settings.syncSetups).sort((left, right) => left.localeCompare(right)) : [];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function loadOnSwitch(): Promise<OnSwitchAction> {
|
|
19
|
-
return (await requireSettings()).onSwitch;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function localConfigTemplate(): PiSyncSettingsV3 {
|
|
23
|
-
return {
|
|
24
|
-
version: 3,
|
|
25
|
-
onSwitch: DEFAULT_ON_SWITCH,
|
|
26
|
-
skipSecretScan: false,
|
|
27
|
-
showStatus: true,
|
|
28
|
-
debug: false,
|
|
29
|
-
storageConnections: {},
|
|
30
|
-
syncSetups: {},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function readLocalConfigDocument() {
|
|
35
|
-
const document = await readMigratingLocalConfigDocument((settings) => {
|
|
36
|
-
validateSettingsDocument(settings);
|
|
37
|
-
});
|
|
38
|
-
if (document) validateSettingsDocument(document.parsed);
|
|
39
|
-
return document;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function readLocalConfigObject(): Promise<PiSyncSettingsV3 | undefined> {
|
|
43
|
-
return (await readLocalConfigDocument())?.parsed as PiSyncSettingsV3 | undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function updateLocalConfig(update: (current: PiSyncSettingsV3) => PiSyncSettingsV3, signal?: AbortSignal) {
|
|
47
|
-
return updateLocalConfigDocument(localConfigTemplate(), update, validateSettingsDocument, signal);
|
|
48
|
-
}
|
|
1
|
+
export type * from "@narumitw/sync-daemon/engine/settings/settings-store";
|
|
2
|
+
export {
|
|
3
|
+
configuredSyncSetupNames,
|
|
4
|
+
loadOnSwitch,
|
|
5
|
+
localConfigTemplate,
|
|
6
|
+
readLocalConfigDocument,
|
|
7
|
+
readLocalConfigObject,
|
|
8
|
+
requireSettings,
|
|
9
|
+
updateLocalConfig,
|
|
10
|
+
} from "@narumitw/sync-daemon/engine/settings/settings-store";
|