@camstack/server 1.2.718 → 1.2.720
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 +13 -0
- package/dist/addon-root-inventory.js +1 -1
- package/dist/agent/addon-scan.js +11 -7
- package/dist/agent/agent-addon-updates.js +1 -1
- package/dist/agent/agent-cap-dispatch-service.js +1 -1
- package/dist/agent/agent-heap-watch.js +1 -1
- package/dist/agent/agent-http.js +1 -1
- package/dist/agent/agent-hub-addon-update.js +1 -1
- package/dist/agent/agent-hub-registration.js +1 -1
- package/dist/agent/agent-infra-capabilities.js +2 -2
- package/dist/agent/agent-mesh-gate.js +1 -1
- package/dist/agent/agent-node-certificates.js +1 -1
- package/dist/agent/agent-pairing-routes.js +1 -1
- package/dist/agent/agent-pairing-store.js +1 -1
- package/dist/agent/agent-service.js +6 -2
- package/dist/agent/agent-update-service.js +3 -1
- package/dist/agent/hub-membership-client.js +1 -1
- package/dist/agent/infra-boot-guard.js +2 -2
- package/dist/agent/main.js +9 -9
- package/dist/api/addon-upload.js +1 -1
- package/dist/api/core/addon-settings.router.js +1 -1
- package/dist/api/core/agent-pairing.router.js +1 -1
- package/dist/api/core/auth-device-cert.procedures.js +1 -1
- package/dist/api/core/cap-providers.js +6 -6
- package/dist/api/core/certificates.router.js +1 -1
- package/dist/api/core/lifecycle-job-runner.js +1 -1
- package/dist/api/core/logging-settings.js +1 -1
- package/dist/api/core/logs.router.js +2 -2
- package/dist/api/core/notifications.router.js +1 -1
- package/dist/api/core/preferences.router.js +1 -1
- package/dist/api/core/repl.router.js +1 -1
- package/dist/api/cors/cors-policy.js +1 -1
- package/dist/api/mesh-membership-routes.js +1 -1
- package/dist/api/model-distributor.js +1 -1
- package/dist/api/trpc/cap-route-error-formatter.js +1 -1
- package/dist/api/trpc/cap-router-runtime.js +2 -2
- package/dist/api/trpc/core-cap-bridge.js +1 -1
- package/dist/api/trpc/device-collection-dispatch.js +1 -1
- package/dist/api/trpc/generated-cap-routers.js +1 -1
- package/dist/api/trpc/principal-authorization.js +1 -1
- package/dist/api/trpc/principal-visibility.js +1 -1
- package/dist/api/trpc/scope-access.js +1 -1
- package/dist/api/trpc/trpc.context.js +1 -1
- package/dist/api/trpc/trpc.middleware.js +1 -1
- package/dist/api/trpc/trpc.router.js +3 -3
- package/dist/auth/auth-network-policy.js +1 -1
- package/dist/auth/client-address.js +1 -1
- package/dist/auth/hub-sessions.js +1 -1
- package/dist/auth/session-lifetimes.js +1 -1
- package/dist/auth/sso-finish-deps.js +1 -1
- package/dist/boot/boot-config.js +53 -133
- package/dist/boot/platform-keychain-key.js +1 -1
- package/dist/boot/post-boot.service.js +1 -1
- package/dist/bootstrap-packages.js +3 -3
- package/dist/core/addon/addon-call-gateway.js +1 -1
- package/dist/core/addon/addon-package.service.js +140 -21
- package/dist/core/addon/addon-registry.service.js +36 -32
- package/dist/core/addon/addon-requirements.js +81 -0
- package/dist/core/addon/hub-addon-api.js +1 -1
- package/dist/core/addon/installed-addon-versions.js +82 -0
- package/dist/core/addon/package-dir-utils.js +11 -1
- package/dist/core/addon/settings-door-wiring.js +1 -1
- package/dist/core/addon-bridge/addon-bridge.service.js +3 -3
- package/dist/core/addon-pages/addon-pages.service.js +1 -1
- package/dist/core/agent/agent-desired-set.js +1 -1
- package/dist/core/agent/agent-pairing-http.js +1 -1
- package/dist/core/agent/agent-registry.service.js +41 -7
- package/dist/core/agent/cluster-node-history-store.js +1 -1
- package/dist/core/agent/delivery-requirements.js +36 -0
- package/dist/core/agent/forgotten-node-revoker.js +1 -1
- package/dist/core/agent/node-removal-hooks.js +6 -2
- package/dist/core/auth/auth.service.js +1 -1
- package/dist/core/config/config.schema.js +2 -2
- package/dist/core/config/config.service.js +1 -1
- package/dist/core/events/event-bus.service.js +1 -1
- package/dist/core/feature/feature.service.js +1 -1
- package/dist/core/lifecycle/lifecycle-state-machine.js +2 -2
- package/dist/core/logging/log-history.js +1 -1
- package/dist/core/logging/log-ring-buffer.js +2 -2
- package/dist/core/logging/logging.service.js +2 -2
- package/dist/core/logging/scoped-logger.js +2 -2
- package/dist/core/moleculer/cap-route-authority.js +2 -2
- package/dist/core/moleculer/hub-mesh-guard.js +1 -1
- package/dist/core/moleculer/moleculer.service.js +1 -1
- package/dist/core/network/network-quality.service.js +1 -1
- package/dist/core/notification/notification-wrapper.service.js +1 -1
- package/dist/core/notification/toast-wrapper.service.js +1 -1
- package/dist/core/repl/repl-engine.service.js +1 -1
- package/dist/core/server-update/server-update.service.js +3 -0
- package/dist/core/server-update/system-ensure-prebuilds.js +3 -3
- package/dist/core/server-update/system-exec-npm.js +2 -2
- package/dist/core/storage/fs-storage-backend.js +2 -2
- package/dist/core/storage/storage-location-manager.js +2 -2
- package/dist/core/storage/storage.service.js +1 -1
- package/dist/framework-nodepath.js +14 -1
- package/dist/launcher.js +23 -23
- package/dist/legacy-package-names.js +15 -0
- package/dist/main.js +2 -2
- package/dist/manual-boot.js +4 -3
- package/dist/package-inventory.js +6 -3
- package/dist/server-root/index.js +182 -30
- package/dist/single-copy-cleanup-runner.js +3 -3
- package/dist/single-copy-cleanup.js +19 -14
- package/package.json +53 -19
- package/scripts/closure-postinstall.mjs +1 -1
- package/system/assets/addon-pages-aggregator/icon.svg +5 -0
- package/system/assets/addon-widgets-aggregator/icon.svg +6 -0
- package/system/assets/alert-center/icon.svg +5 -0
- package/system/assets/autotrack/icon.svg +5 -0
- package/system/assets/backup-orchestrator/icon.svg +5 -0
- package/system/assets/calendars/icon.svg +5 -0
- package/system/assets/camera-grid/icon.svg +10 -0
- package/system/assets/composer/icon.svg +7 -0
- package/system/assets/console-logging/icon.svg +4 -0
- package/system/assets/core-blocks/icon.svg +6 -0
- package/system/assets/device-history/icon.svg +4 -0
- package/system/assets/device-manager/icon.svg +6 -0
- package/system/assets/filesystem-storage/icon.svg +6 -0
- package/system/assets/hub-forwarder/icon.svg +7 -0
- package/system/assets/keychain/icon.svg +6 -0
- package/system/assets/liveness-monitor/icon.svg +4 -0
- package/system/assets/local-auth/icon.svg +5 -0
- package/system/assets/local-network/icon.svg +7 -0
- package/system/assets/loki-logging/icon.svg +7 -0
- package/system/assets/metrics-native/icon.svg +3 -0
- package/system/assets/platform-probe/icon.svg +5 -0
- package/system/assets/record-entries/icon.svg +8 -0
- package/system/assets/remote-access-orchestrator/icon.svg +5 -0
- package/system/assets/snapshot/icon.svg +4 -0
- package/system/assets/sqlite-settings/icon.svg +5 -0
- package/system/assets/storage-orchestrator/icon.svg +8 -0
- package/system/assets/system-config/icon.svg +4 -0
- package/system/assets/winston-logging/icon.svg +6 -0
- package/system/dist/addon/addon-api-factory.d.ts +35 -0
- package/system/dist/addon-routes/addon-route-registry.d.ts +37 -0
- package/system/dist/addon-runner.js +11894 -0
- package/system/dist/addon-runner.mjs +11840 -0
- package/system/dist/addon-utils.d.ts +23 -0
- package/system/dist/addon-utils.js +27 -0
- package/system/dist/addon-utils.mjs +3 -0
- package/system/dist/agent-https-BMbnmX5u.mjs +1042 -0
- package/system/dist/agent-https-DslXCDRW.js +1289 -0
- package/system/dist/amd-accelerators-CEuPFBBK.js +36 -0
- package/system/dist/amd-accelerators-U_RsoEDd.mjs +35 -0
- package/system/dist/auth/auth-audit-log.d.ts +45 -0
- package/system/dist/auth/auth-manager.d.ts +155 -0
- package/system/dist/auth/cidr.d.ts +22 -0
- package/system/dist/auth/device-ca-store.d.ts +57 -0
- package/system/dist/auth/device-ca.d.ts +65 -0
- package/system/dist/auth/device-credential-manager.d.ts +158 -0
- package/system/dist/auth/external-identity-manager.d.ts +42 -0
- package/system/dist/auth/jwt-signing-key.d.ts +42 -0
- package/system/dist/auth/legacy-token-tables.d.ts +16 -0
- package/system/dist/auth/login-session-manager.d.ts +140 -0
- package/system/dist/auth/origin.d.ts +34 -0
- package/system/dist/auth/parse-record.d.ts +18 -0
- package/system/dist/auth/scope-matcher.d.ts +8 -0
- package/system/dist/auth/session-revocation-bus.d.ts +32 -0
- package/system/dist/auth/token-expiry.d.ts +62 -0
- package/system/dist/auth/totp-manager.d.ts +107 -0
- package/system/dist/auth/user-management-internal.d.ts +90 -0
- package/system/dist/auth/user-manager.d.ts +69 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.d.ts +57 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +271 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +263 -0
- package/system/dist/builtins/addon-pages-aggregator/dedupe-pages.d.ts +24 -0
- package/system/dist/builtins/addon-pages-aggregator/index.d.ts +1 -0
- package/system/dist/builtins/addon-pages-aggregator/index.js +8 -0
- package/system/dist/builtins/addon-pages-aggregator/index.mjs +2 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.d.ts +57 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +257 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +249 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.d.ts +1 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.js +8 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.mjs +2 -0
- package/system/dist/builtins/alerts/alert-episode-policy.d.ts +39 -0
- package/system/dist/builtins/alerts/alert-store.d.ts +32 -0
- package/system/dist/builtins/alerts/alerts.addon.d.ts +148 -0
- package/system/dist/builtins/alerts/alerts.addon.js +1566 -0
- package/system/dist/builtins/alerts/alerts.addon.mjs +1559 -0
- package/system/dist/builtins/alerts/device-label.d.ts +8 -0
- package/system/dist/builtins/alerts/emit-alert-policy.d.ts +15 -0
- package/system/dist/builtins/alerts/index.d.ts +1 -0
- package/system/dist/builtins/alerts/index.js +4 -0
- package/system/dist/builtins/alerts/index.mjs +2 -0
- package/system/dist/builtins/alerts/migration-alerts.d.ts +13 -0
- package/system/dist/builtins/alerts/prune-policy.d.ts +44 -0
- package/system/dist/builtins/alerts/record-kinds.d.ts +15 -0
- package/system/dist/builtins/alerts/runner-alert.d.ts +58 -0
- package/system/dist/builtins/autotrack/autotrack-cameras.d.ts +125 -0
- package/system/dist/builtins/autotrack/autotrack-config.d.ts +89 -0
- package/system/dist/builtins/autotrack/autotrack-decision.d.ts +86 -0
- package/system/dist/builtins/autotrack/autotrack-loop.d.ts +95 -0
- package/system/dist/builtins/autotrack/autotrack.addon.d.ts +108 -0
- package/system/dist/builtins/autotrack/frame-error.d.ts +50 -0
- package/system/dist/builtins/autotrack/frame-measurements.d.ts +97 -0
- package/system/dist/builtins/autotrack/index.d.ts +2 -0
- package/system/dist/builtins/autotrack/index.js +1018 -0
- package/system/dist/builtins/autotrack/index.mjs +1012 -0
- package/system/dist/builtins/autotrack/ptz-mirror.d.ts +54 -0
- package/system/dist/builtins/autotrack/target-selection.d.ts +46 -0
- package/system/dist/builtins/backup-orchestrator/backup-databases.d.ts +51 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +291 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +3213 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +3204 -0
- package/system/dist/builtins/backup-orchestrator/cron-helpers.d.ts +23 -0
- package/system/dist/builtins/backup-orchestrator/destination-policy.d.ts +91 -0
- package/system/dist/builtins/backup-orchestrator/download-helpers.d.ts +12 -0
- package/system/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +49 -0
- package/system/dist/builtins/backup-orchestrator/index.d.ts +2 -0
- package/system/dist/builtins/backup-orchestrator/index.js +8 -0
- package/system/dist/builtins/backup-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/backup-orchestrator/manifest-store.d.ts +134 -0
- package/system/dist/builtins/backup-orchestrator/record-kinds.d.ts +56 -0
- package/system/dist/builtins/backup-orchestrator/restore-archive.d.ts +24 -0
- package/system/dist/builtins/backup-orchestrator/run-queue.d.ts +106 -0
- package/system/dist/builtins/backup-orchestrator/schedule-store.d.ts +59 -0
- package/system/dist/builtins/backup-orchestrator/seed-marker-store.d.ts +26 -0
- package/system/dist/builtins/backup-orchestrator/staging-paths.d.ts +36 -0
- package/system/dist/builtins/backup-orchestrator/write-targets.d.ts +63 -0
- package/system/dist/builtins/calendars/calendar-color.d.ts +9 -0
- package/system/dist/builtins/calendars/calendar-prefs-store.d.ts +34 -0
- package/system/dist/builtins/calendars/calendars.addon.d.ts +19 -0
- package/system/dist/builtins/calendars/calendars.addon.js +227 -0
- package/system/dist/builtins/calendars/calendars.addon.mjs +220 -0
- package/system/dist/builtins/calendars/index.d.ts +1 -0
- package/system/dist/builtins/calendars/index.js +8 -0
- package/system/dist/builtins/calendars/index.mjs +2 -0
- package/system/dist/builtins/calendars/record-kinds.d.ts +18 -0
- package/system/dist/builtins/camera-grid/acquire-retry.d.ts +30 -0
- package/system/dist/builtins/camera-grid/addon.d.ts +205 -0
- package/system/dist/builtins/camera-grid/flv-join.d.ts +40 -0
- package/system/dist/builtins/camera-grid/grid-activity-mirror.d.ts +42 -0
- package/system/dist/builtins/camera-grid/grid-activity.d.ts +91 -0
- package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +59 -0
- package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +68 -0
- package/system/dist/builtins/camera-grid/grid-canvas-derivation.d.ts +54 -0
- package/system/dist/builtins/camera-grid/grid-canvas-seed.d.ts +112 -0
- package/system/dist/builtins/camera-grid/grid-canvas.d.ts +85 -0
- package/system/dist/builtins/camera-grid/grid-child.d.ts +32 -0
- package/system/dist/builtins/camera-grid/grid-compositor-child.d.ts +3 -0
- package/system/dist/builtins/camera-grid/grid-compositor-invocation.d.ts +47 -0
- package/system/dist/builtins/camera-grid/grid-compositor.d.ts +54 -0
- package/system/dist/builtins/camera-grid/grid-detection-mapping.d.ts +61 -0
- package/system/dist/builtins/camera-grid/grid-device-settings.d.ts +35 -0
- package/system/dist/builtins/camera-grid/grid-filter-graph.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-frame-sample.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +22 -0
- package/system/dist/builtins/camera-grid/grid-last-frame-store.d.ts +58 -0
- package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +34 -0
- package/system/dist/builtins/camera-grid/grid-plan.d.ts +34 -0
- package/system/dist/builtins/camera-grid/grid-profiles.d.ts +104 -0
- package/system/dist/builtins/camera-grid/grid-row-normalization.d.ts +10 -0
- package/system/dist/builtins/camera-grid/grid-sentry-sources.d.ts +64 -0
- package/system/dist/builtins/camera-grid/grid-snapshot.d.ts +62 -0
- package/system/dist/builtins/camera-grid/grid-stream-descriptor.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-stream-invocation.d.ts +44 -0
- package/system/dist/builtins/camera-grid/grid-stream-relay.d.ts +35 -0
- package/system/dist/builtins/camera-grid/grid-stream-session.d.ts +143 -0
- package/system/dist/builtins/camera-grid/grid-tile-feed.d.ts +50 -0
- package/system/dist/builtins/camera-grid/grid-tile-plan.d.ts +66 -0
- package/system/dist/builtins/camera-grid/grid-wire-format.d.ts +30 -0
- package/system/dist/builtins/camera-grid/index.d.ts +45 -0
- package/system/dist/builtins/camera-grid/index.js +3994 -0
- package/system/dist/builtins/camera-grid/index.mjs +3961 -0
- package/system/dist/builtins/camera-grid/silence-analysis.d.ts +37 -0
- package/system/dist/builtins/cluster-agent/record-kinds.d.ts +49 -0
- package/system/dist/builtins/composer/actuator-dispatch.d.ts +13 -0
- package/system/dist/builtins/composer/actuator-groups.d.ts +68 -0
- package/system/dist/builtins/composer/actuator-invoke.d.ts +32 -0
- package/system/dist/builtins/composer/claim-gate.d.ts +59 -0
- package/system/dist/builtins/composer/composed-device-set.d.ts +52 -0
- package/system/dist/builtins/composer/composed-device.d.ts +57 -0
- package/system/dist/builtins/composer/composer-apply-waits.d.ts +28 -0
- package/system/dist/builtins/composer/composer-grafts.d.ts +73 -0
- package/system/dist/builtins/composer/composer-live-set.d.ts +30 -0
- package/system/dist/builtins/composer/composer-plan.d.ts +112 -0
- package/system/dist/builtins/composer/composer-runtime-factory.d.ts +30 -0
- package/system/dist/builtins/composer/composer-seeds.d.ts +28 -0
- package/system/dist/builtins/composer/composer-verdict.d.ts +33 -0
- package/system/dist/builtins/composer/composer.addon.d.ts +26 -0
- package/system/dist/builtins/composer/composer.addon.js +6229 -0
- package/system/dist/builtins/composer/composer.addon.mjs +6223 -0
- package/system/dist/builtins/composer/composer.d.ts +208 -0
- package/system/dist/builtins/composer/composition-declarations.d.ts +64 -0
- package/system/dist/builtins/composer/composition-evaluation.d.ts +53 -0
- package/system/dist/builtins/composer/composition-runtime.d.ts +203 -0
- package/system/dist/builtins/composer/composition-target.d.ts +60 -0
- package/system/dist/builtins/composer/confirmed-seed.d.ts +44 -0
- package/system/dist/builtins/composer/deadline-timer.d.ts +18 -0
- package/system/dist/builtins/composer/existing-target.d.ts +131 -0
- package/system/dist/builtins/composer/field-record.d.ts +64 -0
- package/system/dist/builtins/composer/forward-commands.d.ts +61 -0
- package/system/dist/builtins/composer/graft-host.d.ts +71 -0
- package/system/dist/builtins/composer/held-claims.d.ts +29 -0
- package/system/dist/builtins/composer/history-helpers.d.ts +67 -0
- package/system/dist/builtins/composer/index.d.ts +1 -0
- package/system/dist/builtins/composer/index.js +8 -0
- package/system/dist/builtins/composer/index.mjs +2 -0
- package/system/dist/builtins/composer/math-quantity.d.ts +20 -0
- package/system/dist/builtins/composer/own-field-reads.d.ts +30 -0
- package/system/dist/builtins/composer/owned-fields-target.d.ts +95 -0
- package/system/dist/builtins/composer/pulse-seed-resolve.d.ts +59 -0
- package/system/dist/builtins/composer/pulse-seed.d.ts +75 -0
- package/system/dist/builtins/composer/slice-assembler.d.ts +26 -0
- package/system/dist/builtins/composer/source-readings.d.ts +128 -0
- package/system/dist/builtins/composer/source-tracker.d.ts +135 -0
- package/system/dist/builtins/console-logging/console-destination.d.ts +19 -0
- package/system/dist/builtins/console-logging/console-logging.addon.d.ts +26 -0
- package/system/dist/builtins/console-logging/index.d.ts +3 -0
- package/system/dist/builtins/console-logging/index.js +108 -0
- package/system/dist/builtins/console-logging/index.mjs +99 -0
- package/system/dist/builtins/core-blocks/actions-service.d.ts +113 -0
- package/system/dist/builtins/core-blocks/actions-store.d.ts +32 -0
- package/system/dist/builtins/core-blocks/actions-wiring.d.ts +32 -0
- package/system/dist/builtins/core-blocks/block-package.d.ts +54 -0
- package/system/dist/builtins/core-blocks/block-settings-store.d.ts +93 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +176 -0
- package/system/dist/builtins/core-blocks/block-type-defs.d.ts +29 -0
- package/system/dist/builtins/core-blocks/blocks-integration.d.ts +89 -0
- package/system/dist/builtins/core-blocks/compile-block.d.ts +52 -0
- package/system/dist/builtins/core-blocks/composition-api.d.ts +50 -0
- package/system/dist/builtins/core-blocks/composition-peers.d.ts +31 -0
- package/system/dist/builtins/core-blocks/composition-sources.d.ts +40 -0
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +120 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +108 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +6374 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +6355 -0
- package/system/dist/builtins/core-blocks/extract-settings-schema.d.ts +6 -0
- package/system/dist/builtins/core-blocks/index.d.ts +8 -0
- package/system/dist/builtins/core-blocks/index.js +21 -0
- package/system/dist/builtins/core-blocks/index.mjs +2 -0
- package/system/dist/builtins/core-blocks/lock-door-gate.d.ts +31 -0
- package/system/dist/builtins/core-blocks/lock-door-sensor.d.ts +35 -0
- package/system/dist/builtins/core-blocks/power-source-service.d.ts +70 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +83 -0
- package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +23 -0
- package/system/dist/builtins/core-blocks/remote-components-service.d.ts +10 -0
- package/system/dist/builtins/core-blocks/remote-service.d.ts +85 -0
- package/system/dist/builtins/core-blocks/remote-wiring.d.ts +49 -0
- package/system/dist/builtins/core-blocks/runs-api.d.ts +30 -0
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +64 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-engine.d.ts +91 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-holds.d.ts +54 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-service.d.ts +76 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +23 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-timeline.d.ts +53 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-trace.d.ts +17 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-types.d.ts +20 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-wiring.d.ts +41 -0
- package/system/dist/builtins/core-blocks/templates-service.d.ts +24 -0
- package/system/dist/builtins/device-history/capture/capture-engine.d.ts +113 -0
- package/system/dist/builtins/device-history/capture/capture-filter.d.ts +37 -0
- package/system/dist/builtins/device-history/capture/device-directory.d.ts +47 -0
- package/system/dist/builtins/device-history/capture/field-path.d.ts +10 -0
- package/system/dist/builtins/device-history/capture/point-writer.d.ts +63 -0
- package/system/dist/builtins/device-history/device-history.addon.d.ts +53 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2885 -0
- package/system/dist/builtins/device-history/device-history.addon.mjs +2878 -0
- package/system/dist/builtins/device-history/index.d.ts +3 -0
- package/system/dist/builtins/device-history/ingest/producer-ingest.d.ts +99 -0
- package/system/dist/builtins/device-history/query/history-query.d.ts +116 -0
- package/system/dist/builtins/device-history/query/point-shape.d.ts +31 -0
- package/system/dist/builtins/device-history/retention/departure-tracker.d.ts +33 -0
- package/system/dist/builtins/device-history/retention/orphans.d.ts +50 -0
- package/system/dist/builtins/device-history/retention/retention.d.ts +74 -0
- package/system/dist/builtins/device-history/rollup/rollup-engine.d.ts +74 -0
- package/system/dist/builtins/device-history/rollup/rollup-math.d.ts +50 -0
- package/system/dist/builtins/device-history/runtime/history-runtime.d.ts +118 -0
- package/system/dist/builtins/device-history/status/counters.d.ts +55 -0
- package/system/dist/builtins/device-history/store/history-door.d.ts +7 -0
- package/system/dist/builtins/device-history/store/history-schema.d.ts +28 -0
- package/system/dist/builtins/device-history/store/history-store.d.ts +109 -0
- package/system/dist/builtins/device-history/store/row-readers.d.ts +11 -0
- package/system/dist/builtins/device-history/store/series-registry.d.ts +64 -0
- package/system/dist/builtins/device-history/store/series-scale.d.ts +37 -0
- package/system/dist/builtins/device-history/time/bucket-time.d.ts +25 -0
- package/system/dist/builtins/device-manager/adoption-job-engine.d.ts +153 -0
- package/system/dist/builtins/device-manager/claimed-status-overlay.d.ts +45 -0
- package/system/dist/builtins/device-manager/contribution-cache.d.ts +85 -0
- package/system/dist/builtins/device-manager/day-night-config-schema.d.ts +30 -0
- package/system/dist/builtins/device-manager/device-aggregation-merge.d.ts +22 -0
- package/system/dist/builtins/device-manager/device-aggregation.d.ts +335 -0
- package/system/dist/builtins/device-manager/device-bindings-store.d.ts +278 -0
- package/system/dist/builtins/device-manager/device-config-contribution.d.ts +45 -0
- package/system/dist/builtins/device-manager/device-config-secrets.d.ts +40 -0
- package/system/dist/builtins/device-manager/device-event-propagator.d.ts +26 -0
- package/system/dist/builtins/device-manager/device-extension-linked-slot.d.ts +27 -0
- package/system/dist/builtins/device-manager/device-form-secrets.d.ts +25 -0
- package/system/dist/builtins/device-manager/device-linked-devices.d.ts +201 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +234 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +11369 -0
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +11358 -0
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +338 -0
- package/system/dist/builtins/device-manager/device-meta-store.d.ts +103 -0
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +277 -0
- package/system/dist/builtins/device-manager/device-online-fallback.d.ts +35 -0
- package/system/dist/builtins/device-manager/device-projection.d.ts +71 -0
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +126 -0
- package/system/dist/builtins/device-manager/device-queries.d.ts +67 -0
- package/system/dist/builtins/device-manager/device-removal-hooks.d.ts +92 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +449 -0
- package/system/dist/builtins/device-manager/device-source-activation.d.ts +103 -0
- package/system/dist/builtins/device-manager/device-state-claim-views.d.ts +92 -0
- package/system/dist/builtins/device-manager/device-state-claims.d.ts +66 -0
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +267 -0
- package/system/dist/builtins/device-manager/device-sync-resolvers.d.ts +30 -0
- package/system/dist/builtins/device-manager/device-tombstone-store.d.ts +29 -0
- package/system/dist/builtins/device-manager/discovery-orchestrator.d.ts +45 -0
- package/system/dist/builtins/device-manager/field-claims-index.d.ts +96 -0
- package/system/dist/builtins/device-manager/field-ownership.d.ts +71 -0
- package/system/dist/builtins/device-manager/fleet-read-census.d.ts +104 -0
- package/system/dist/builtins/device-manager/image-settings-config-schema.d.ts +22 -0
- package/system/dist/builtins/device-manager/index.d.ts +2 -0
- package/system/dist/builtins/device-manager/index.js +8 -0
- package/system/dist/builtins/device-manager/index.mjs +2 -0
- package/system/dist/builtins/device-manager/linked-devices-manual-backfill.d.ts +27 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +61 -0
- package/system/dist/builtins/device-manager/migrate-device.d.ts +192 -0
- package/system/dist/builtins/device-manager/migrate-guard.d.ts +78 -0
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +79 -0
- package/system/dist/builtins/device-manager/migrate-reload.d.ts +46 -0
- package/system/dist/builtins/device-manager/migration-refused.d.ts +23 -0
- package/system/dist/builtins/device-manager/mirror-row-writer.d.ts +222 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +14 -0
- package/system/dist/builtins/device-manager/recording-onboard-config-schema.d.ts +65 -0
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +50 -0
- package/system/dist/builtins/device-manager/removal-fence.d.ts +58 -0
- package/system/dist/builtins/device-manager/running-flip.d.ts +11 -0
- package/system/dist/builtins/device-manager/runtime-state-persist-gate.d.ts +64 -0
- package/system/dist/builtins/device-manager/secret-config-paths.d.ts +24 -0
- package/system/dist/builtins/device-manager/stale-wrapper-activations.d.ts +59 -0
- package/system/dist/builtins/device-manager/write-lock.d.ts +17 -0
- package/system/dist/builtins/hub-forwarder/hub-forwarder-destination.d.ts +43 -0
- package/system/dist/builtins/hub-forwarder/hub-forwarder.addon.d.ts +16 -0
- package/system/dist/builtins/hub-forwarder/index.d.ts +3 -0
- package/system/dist/builtins/hub-forwarder/index.js +151 -0
- package/system/dist/builtins/hub-forwarder/index.mjs +142 -0
- package/system/dist/builtins/keychain/index.d.ts +1 -0
- package/system/dist/builtins/keychain/index.js +2059 -0
- package/system/dist/builtins/keychain/index.mjs +2052 -0
- package/system/dist/builtins/keychain/key-sources.d.ts +37 -0
- package/system/dist/builtins/keychain/keychain-crypto.d.ts +28 -0
- package/system/dist/builtins/keychain/keychain-reset-trigger.d.ts +25 -0
- package/system/dist/builtins/keychain/keychain-service.d.ts +180 -0
- package/system/dist/builtins/keychain/keychain-store.d.ts +125 -0
- package/system/dist/builtins/keychain/keychain-usage.d.ts +17 -0
- package/system/dist/builtins/keychain/keychain.addon.d.ts +36 -0
- package/system/dist/builtins/keychain/platform-key-source.d.ts +24 -0
- package/system/dist/builtins/keychain/record-kinds.d.ts +16 -0
- package/system/dist/builtins/keychain/system-held-secrets.d.ts +25 -0
- package/system/dist/builtins/liveness-monitor/index.d.ts +2 -0
- package/system/dist/builtins/liveness-monitor/index.js +6 -0
- package/system/dist/builtins/liveness-monitor/index.mjs +2 -0
- package/system/dist/builtins/liveness-monitor/liveness-checks.d.ts +85 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.d.ts +46 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +443 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +437 -0
- package/system/dist/builtins/liveness-monitor/liveness-reporter.d.ts +28 -0
- package/system/dist/builtins/liveness-monitor/storage-root-access.d.ts +53 -0
- package/system/dist/builtins/local-auth/admin-account-boot.d.ts +27 -0
- package/system/dist/builtins/local-auth/auth-config-reader.d.ts +39 -0
- package/system/dist/builtins/local-auth/auth-schema.d.ts +93 -0
- package/system/dist/builtins/local-auth/index.d.ts +1 -0
- package/system/dist/builtins/local-auth/index.js +4 -0
- package/system/dist/builtins/local-auth/index.mjs +2 -0
- package/system/dist/builtins/local-auth/jwt-signing-key-keeper.d.ts +30 -0
- package/system/dist/builtins/local-auth/local-auth.addon.d.ts +48 -0
- package/system/dist/builtins/local-auth/local-auth.addon.js +12418 -0
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +12388 -0
- package/system/dist/builtins/local-auth/oauth-grants.d.ts +71 -0
- package/system/dist/builtins/local-auth/oauth-session-manager.d.ts +44 -0
- package/system/dist/builtins/local-auth/person-scopes.d.ts +7 -0
- package/system/dist/builtins/local-auth/preferences-record-kinds.d.ts +27 -0
- package/system/dist/builtins/local-auth/record-kinds.d.ts +137 -0
- package/system/dist/builtins/local-auth/user-preferences-store.d.ts +56 -0
- package/system/dist/builtins/local-network/address-book.d.ts +128 -0
- package/system/dist/builtins/local-network/agent-mdns.d.ts +56 -0
- package/system/dist/builtins/local-network/hub-mdns-ciao.d.ts +7 -0
- package/system/dist/builtins/local-network/hub-mdns.d.ts +58 -0
- package/system/dist/builtins/local-network/index.d.ts +1 -0
- package/system/dist/builtins/local-network/index.js +10 -0
- package/system/dist/builtins/local-network/index.mjs +2 -0
- package/system/dist/builtins/local-network/ipv6-lan.d.ts +21 -0
- package/system/dist/builtins/local-network/local-hostname.d.ts +15 -0
- package/system/dist/builtins/local-network/local-network.addon.d.ts +334 -0
- package/system/dist/builtins/local-network/local-network.addon.js +2487 -0
- package/system/dist/builtins/local-network/local-network.addon.mjs +2466 -0
- package/system/dist/builtins/local-network/scan/dns-wire.d.ts +17 -0
- package/system/dist/builtins/local-network/scan/scan-engine.d.ts +31 -0
- package/system/dist/builtins/local-network/scan/scan-io-node.d.ts +2 -0
- package/system/dist/builtins/local-network/scan/scan-io.d.ts +56 -0
- package/system/dist/builtins/local-network/scan/subnets.d.ts +57 -0
- package/system/dist/builtins/loki-logging/index.d.ts +4 -0
- package/system/dist/builtins/loki-logging/index.js +915 -0
- package/system/dist/builtins/loki-logging/index.mjs +901 -0
- package/system/dist/builtins/loki-logging/loki-destination.d.ts +142 -0
- package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +66 -0
- package/system/dist/builtins/loki-logging/loki-payload.d.ts +100 -0
- package/system/dist/builtins/loki-logging/loki-read.d.ts +51 -0
- package/system/dist/builtins/loki-logging/retire-enabled-flag.d.ts +48 -0
- package/system/dist/builtins/native-metrics/cgroup-memory.d.ts +240 -0
- package/system/dist/builtins/native-metrics/cgroup-pids.d.ts +159 -0
- package/system/dist/builtins/native-metrics/container-memory-ring.d.ts +18 -0
- package/system/dist/builtins/native-metrics/darwin-memory.d.ts +26 -0
- package/system/dist/builtins/native-metrics/gpu-probe.d.ts +18 -0
- package/system/dist/builtins/native-metrics/index.d.ts +2 -0
- package/system/dist/builtins/native-metrics/load-series-config.d.ts +83 -0
- package/system/dist/builtins/native-metrics/load-series-reader.d.ts +63 -0
- package/system/dist/builtins/native-metrics/load-series-types.d.ts +14 -0
- package/system/dist/builtins/native-metrics/native-metrics-provider.d.ts +49 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.d.ts +233 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +3116 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +3106 -0
- package/system/dist/builtins/native-metrics/node-load-ring.d.ts +212 -0
- package/system/dist/builtins/native-metrics/node-metrics-history-recorder.d.ts +155 -0
- package/system/dist/builtins/native-metrics/proc-process-table.d.ts +25 -0
- package/system/dist/builtins/native-metrics/process-classification.d.ts +110 -0
- package/system/dist/builtins/native-metrics/thread-cpu-sampler.d.ts +116 -0
- package/system/dist/builtins/platform-probe/accelerator-facts-probe.d.ts +24 -0
- package/system/dist/builtins/platform-probe/accelerator-reprobe.d.ts +23 -0
- package/system/dist/builtins/platform-probe/amd-accelerators.d.ts +15 -0
- package/system/dist/builtins/platform-probe/amd-npu.d.ts +35 -0
- package/system/dist/builtins/platform-probe/coral-accelerators.d.ts +87 -0
- package/system/dist/builtins/platform-probe/index.d.ts +57 -0
- package/system/dist/builtins/platform-probe/index.js +1151 -0
- package/system/dist/builtins/platform-probe/index.mjs +1140 -0
- package/system/dist/builtins/platform-probe/inference-config-resolver.d.ts +29 -0
- package/system/dist/builtins/platform-probe/intel-accelerators.d.ts +14 -0
- package/system/dist/builtins/platform-probe/intel-npu.d.ts +38 -0
- package/system/dist/builtins/platform-probe/platform-scorer.d.ts +66 -0
- package/system/dist/builtins/platform-probe/runtime-packages.d.ts +6 -0
- package/system/dist/builtins/platform-probe/windows-hardware.d.ts +77 -0
- package/system/dist/builtins/record-entries/entries-service.d.ts +42 -0
- package/system/dist/builtins/record-entries/index.d.ts +1 -0
- package/system/dist/builtins/record-entries/index.js +162 -0
- package/system/dist/builtins/record-entries/index.mjs +156 -0
- package/system/dist/builtins/record-entries/record-entries.addon.d.ts +13 -0
- package/system/dist/builtins/records-isolated.d.ts +10 -0
- package/system/dist/builtins/remote-access-orchestrator/enabled-providers-reconcile.d.ts +96 -0
- package/system/dist/builtins/remote-access-orchestrator/index.d.ts +1 -0
- package/system/dist/builtins/remote-access-orchestrator/index.js +8 -0
- package/system/dist/builtins/remote-access-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.d.ts +71 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +214 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +208 -0
- package/system/dist/builtins/shared/device-state-changed.d.ts +16 -0
- package/system/dist/builtins/shared/settle-sources.d.ts +22 -0
- package/system/dist/builtins/snapshot/index.d.ts +2 -0
- package/system/dist/builtins/snapshot/index.js +2720 -0
- package/system/dist/builtins/snapshot/index.mjs +2713 -0
- package/system/dist/builtins/snapshot/snapshot-cache.d.ts +108 -0
- package/system/dist/builtins/snapshot/snapshot-coalescing.d.ts +135 -0
- package/system/dist/builtins/snapshot/snapshot-courtesy.d.ts +68 -0
- package/system/dist/builtins/snapshot/snapshot-durable-store.d.ts +36 -0
- package/system/dist/builtins/snapshot/snapshot-fatigue.d.ts +41 -0
- package/system/dist/builtins/snapshot/snapshot-grab-pick.d.ts +20 -0
- package/system/dist/builtins/snapshot/snapshot-link-url.d.ts +66 -0
- package/system/dist/builtins/snapshot/snapshot-media-handler.d.ts +121 -0
- package/system/dist/builtins/snapshot/snapshot-resize.d.ts +75 -0
- package/system/dist/builtins/snapshot/snapshot.addon.d.ts +581 -0
- package/system/dist/builtins/sqlite-storage/analyze-stats.d.ts +83 -0
- package/system/dist/builtins/sqlite-storage/config-store.d.ts +8 -0
- package/system/dist/builtins/sqlite-storage/database-snapshot-provider.d.ts +18 -0
- package/system/dist/builtins/sqlite-storage/device-store.d.ts +23 -0
- package/system/dist/builtins/sqlite-storage/file-host-client.d.ts +75 -0
- package/system/dist/builtins/sqlite-storage/file-host-handlers.d.ts +27 -0
- package/system/dist/builtins/sqlite-storage/file-host-protocol.d.ts +167 -0
- package/system/dist/builtins/sqlite-storage/file-host-worker.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/filesystem-browse-provider.d.ts +25 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage-provider.d.ts +83 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +419 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +411 -0
- package/system/dist/builtins/sqlite-storage/filter-compiler.d.ts +126 -0
- package/system/dist/builtins/sqlite-storage/index.d.ts +12 -0
- package/system/dist/builtins/sqlite-storage/index.js +82 -0
- package/system/dist/builtins/sqlite-storage/index.mjs +50 -0
- package/system/dist/builtins/sqlite-storage/integration-record-kinds.d.ts +31 -0
- package/system/dist/builtins/sqlite-storage/integration-registry.d.ts +34 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-actions.d.ts +12 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-edits.d.ts +35 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +125 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-hold.d.ts +23 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-pass.d.ts +48 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-restore-marker.d.ts +3 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-types.d.ts +151 -0
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +61 -0
- package/system/dist/builtins/sqlite-storage/owned-sqlite-file.d.ts +173 -0
- package/system/dist/builtins/sqlite-storage/path-guard.d.ts +11 -0
- package/system/dist/builtins/sqlite-storage/placement-errors.d.ts +60 -0
- package/system/dist/builtins/sqlite-storage/placement-router.d.ts +85 -0
- package/system/dist/builtins/sqlite-storage/prefix-range.d.ts +50 -0
- package/system/dist/builtins/sqlite-storage/query-bounds.d.ts +110 -0
- package/system/dist/builtins/sqlite-storage/query-profiler.d.ts +242 -0
- package/system/dist/builtins/sqlite-storage/records/records-catalog.d.ts +27 -0
- package/system/dist/builtins/sqlite-storage/records/records-engine-types.d.ts +48 -0
- package/system/dist/builtins/sqlite-storage/records/records-engine.d.ts +115 -0
- package/system/dist/builtins/sqlite-storage/records/records-explain.d.ts +18 -0
- package/system/dist/builtins/sqlite-storage/records/records-plan.d.ts +95 -0
- package/system/dist/builtins/sqlite-storage/records/records-probe.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/records/records-provider.d.ts +72 -0
- package/system/dist/builtins/sqlite-storage/records/records-rows.d.ts +46 -0
- package/system/dist/builtins/sqlite-storage/records/records-sql.d.ts +39 -0
- package/system/dist/builtins/sqlite-storage/retired-settings-keys.d.ts +276 -0
- package/system/dist/builtins/sqlite-storage/shm-lock-canary.d.ts +60 -0
- package/system/dist/builtins/sqlite-storage/sqlite-pragmas.d.ts +191 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +583 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.d.ts +52 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2960 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2952 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshot-protocol.d.ts +54 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshot-worker.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshotter.d.ts +118 -0
- package/system/dist/builtins/sqlite-storage/stale-data/stale-data-audit.d.ts +81 -0
- package/system/dist/builtins/sqlite-storage/stale-data/stale-data-ports.d.ts +17 -0
- package/system/dist/builtins/sqlite-storage/statement-shape.d.ts +64 -0
- package/system/dist/builtins/sqlite-storage/storage-admin-provider.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/table-sizes.d.ts +95 -0
- package/system/dist/builtins/sqlite-storage/vector-index-shared.d.ts +81 -0
- package/system/dist/builtins/sqlite-storage/vector-index-vec.d.ts +143 -0
- package/system/dist/builtins/sqlite-storage/vector-provider.d.ts +30 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpoint-policy.d.ts +196 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpoint-worker.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpointer.d.ts +76 -0
- package/system/dist/builtins/sqlite-storage/wal-maintenance.d.ts +130 -0
- package/system/dist/builtins/storage-orchestrator/access-guards.d.ts +43 -0
- package/system/dist/builtins/storage-orchestrator/data-store-dispatch.d.ts +39 -0
- package/system/dist/builtins/storage-orchestrator/drain-ratchet.d.ts +104 -0
- package/system/dist/builtins/storage-orchestrator/drain-state-store.d.ts +26 -0
- package/system/dist/builtins/storage-orchestrator/hub-settings-forward.d.ts +128 -0
- package/system/dist/builtins/storage-orchestrator/index.d.ts +7 -0
- package/system/dist/builtins/storage-orchestrator/index.js +11 -0
- package/system/dist/builtins/storage-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/storage-orchestrator/location-class-paths.d.ts +13 -0
- package/system/dist/builtins/storage-orchestrator/location-history-recorder.d.ts +76 -0
- package/system/dist/builtins/storage-orchestrator/location-occupancy-slice.d.ts +71 -0
- package/system/dist/builtins/storage-orchestrator/location-occupancy.d.ts +19 -0
- package/system/dist/builtins/storage-orchestrator/location-protection.d.ts +20 -0
- package/system/dist/builtins/storage-orchestrator/location-repoint-move.d.ts +57 -0
- package/system/dist/builtins/storage-orchestrator/location-repointer.d.ts +97 -0
- package/system/dist/builtins/storage-orchestrator/location-root-collision.d.ts +80 -0
- package/system/dist/builtins/storage-orchestrator/location-secrets.d.ts +114 -0
- package/system/dist/builtins/storage-orchestrator/location-store.d.ts +82 -0
- package/system/dist/builtins/storage-orchestrator/location-volume-capacity.d.ts +58 -0
- package/system/dist/builtins/storage-orchestrator/provider-discovery.d.ts +24 -0
- package/system/dist/builtins/storage-orchestrator/record-kinds.d.ts +43 -0
- package/system/dist/builtins/storage-orchestrator/storage-cleanup-coordinator.d.ts +68 -0
- package/system/dist/builtins/storage-orchestrator/storage-location-band-monitor.d.ts +77 -0
- package/system/dist/builtins/storage-orchestrator/storage-migration-coordinator.d.ts +241 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +318 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +5280 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +5264 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +475 -0
- package/system/dist/builtins/storage-orchestrator/storage-pressure-manager.d.ts +115 -0
- package/system/dist/builtins/system-backup/backup-encryption.d.ts +94 -0
- package/system/dist/builtins/system-backup/system-backup.service.d.ts +308 -0
- package/system/dist/builtins/system-config/index.d.ts +2 -0
- package/system/dist/builtins/system-config/index.js +10 -0
- package/system/dist/builtins/system-config/index.mjs +2 -0
- package/system/dist/builtins/system-config/mesh-actions.d.ts +3 -0
- package/system/dist/builtins/system-config/record-kinds.d.ts +32 -0
- package/system/dist/builtins/system-config/system-config.addon.d.ts +56 -0
- package/system/dist/builtins/system-config/system-config.addon.js +89334 -0
- package/system/dist/builtins/system-config/system-config.addon.mjs +89233 -0
- package/system/dist/builtins/winston-logging/index.d.ts +3 -0
- package/system/dist/builtins/winston-logging/index.js +324 -0
- package/system/dist/builtins/winston-logging/index.mjs +313 -0
- package/system/dist/builtins/winston-logging/log-file-cursor.d.ts +12 -0
- package/system/dist/builtins/winston-logging/log-file-index-store.d.ts +11 -0
- package/system/dist/builtins/winston-logging/log-file-index.d.ts +77 -0
- package/system/dist/builtins/winston-logging/log-file-read-client.d.ts +44 -0
- package/system/dist/builtins/winston-logging/log-file-read-protocol.d.ts +41 -0
- package/system/dist/builtins/winston-logging/log-file-read-worker.d.ts +1 -0
- package/system/dist/builtins/winston-logging/log-file-reader.d.ts +51 -0
- package/system/dist/builtins/winston-logging/winston-destination.d.ts +39 -0
- package/system/dist/builtins/winston-logging/winston-logging.addon.d.ts +20 -0
- package/system/dist/chunk-CNf5ZN-e.mjs +37 -0
- package/system/dist/chunk-Cek0wNdY.js +64 -0
- package/system/dist/composition-sources-C14epb_m.js +155 -0
- package/system/dist/composition-sources-EXNuxmGQ.mjs +132 -0
- package/system/dist/constants-DIGWBiNC.mjs +20 -0
- package/system/dist/constants-M7NtSiRo.js +66 -0
- package/system/dist/coral-accelerators-BSVsBVzt.js +250 -0
- package/system/dist/coral-accelerators-DBlgWB8k.mjs +231 -0
- package/system/dist/custom-action-registry-JuMHGKEc.js +1638 -0
- package/system/dist/custom-action-registry-oHl1xltx.mjs +1482 -0
- package/system/dist/device-ca-3vmBP1i0.js +474 -0
- package/system/dist/device-ca-DZlvNBWU.mjs +367 -0
- package/system/dist/dist-DcMqHB_N.mjs +108095 -0
- package/system/dist/dist-M9yHiIY7.js +110554 -0
- package/system/dist/download/hosted-model-revisions.d.ts +10 -0
- package/system/dist/download/model-download-service.d.ts +35 -0
- package/system/dist/download/model-downloader.d.ts +156 -0
- package/system/dist/events/event-bus.d.ts +10 -0
- package/system/dist/events/system-event-bus.d.ts +14 -0
- package/system/dist/feature/feature-manager.d.ts +11 -0
- package/system/dist/file-host-worker.js +160 -0
- package/system/dist/file-host-worker.mjs +160 -0
- package/system/dist/formatter-DkYZ4LXp.mjs +162 -0
- package/system/dist/formatter-xbxeV4GD.js +167 -0
- package/system/dist/framework-resolver-hook.mjs +49 -0
- package/system/dist/http/asset-compression.d.ts +55 -0
- package/system/dist/http/authenticated-file-server.d.ts +53 -0
- package/system/dist/http/data-plane-registry.d.ts +58 -0
- package/system/dist/http/file-data-plane.d.ts +18 -0
- package/system/dist/http/lan-http-bind.d.ts +41 -0
- package/system/dist/http/reverse-proxy.d.ts +42 -0
- package/system/dist/hub-mdns-ciao-CpCKuQnK.js +1163 -0
- package/system/dist/hub-mdns-ciao-Czz2ssit.mjs +942 -0
- package/system/dist/i18n/catalog-registry.d.ts +35 -0
- package/system/dist/i18n/index.d.ts +2 -0
- package/system/dist/index.d.ts +156 -0
- package/system/dist/index.js +28736 -0
- package/system/dist/index.mjs +28065 -0
- package/system/dist/intel-accelerators-BvBjZn4j.js +16 -0
- package/system/dist/intel-accelerators-idEumqk1.mjs +15 -0
- package/system/dist/intel-npu-C8HKvRQF.mjs +27 -0
- package/system/dist/intel-npu-DYF5hO5K.js +28 -0
- package/system/dist/kernel/addon-class-resolver.d.ts +4 -0
- package/system/dist/kernel/addon-engine-manager.d.ts +22 -0
- package/system/dist/kernel/addon-health-monitor.d.ts +163 -0
- package/system/dist/kernel/addon-installer.d.ts +651 -0
- package/system/dist/kernel/addon-loader.d.ts +144 -0
- package/system/dist/kernel/addon-manifest.d.ts +128 -0
- package/system/dist/kernel/addon-refused-error.d.ts +30 -0
- package/system/dist/kernel/addon-residue.d.ts +45 -0
- package/system/dist/kernel/addon-settings-store.d.ts +43 -0
- package/system/dist/kernel/addon-version-policy.d.ts +34 -0
- package/system/dist/kernel/anon-rss.d.ts +12 -0
- package/system/dist/kernel/array-buffer-census.d.ts +118 -0
- package/system/dist/kernel/bootstrap-config.d.ts +7 -0
- package/system/dist/kernel/cap-router-builder.d.ts +180 -0
- package/system/dist/kernel/capability-handle.d.ts +46 -0
- package/system/dist/kernel/capability-registry.d.ts +621 -0
- package/system/dist/kernel/config-manager.d.ts +174 -0
- package/system/dist/kernel/config-schema.d.ts +37 -0
- package/system/dist/kernel/custom-action-registry.d.ts +32 -0
- package/system/dist/kernel/deps/addon-deps-manager.d.ts +28 -0
- package/system/dist/kernel/deps/closure-dedupe.d.ts +105 -0
- package/system/dist/kernel/deps/ensure-addon-natives.d.ts +41 -0
- package/system/dist/kernel/deps/ensure-native-prebuilds.d.ts +40 -0
- package/system/dist/kernel/deps/manifest-native-deps.d.ts +42 -0
- package/system/dist/kernel/deps/manifest-python-deps.d.ts +20 -0
- package/system/dist/kernel/deps/manifest-system-deps.d.ts +18 -0
- package/system/dist/kernel/deps/npm-command.d.ts +60 -0
- package/system/dist/kernel/deps/system-package-allowlist.d.ts +12 -0
- package/system/dist/kernel/deps/system-package-broker.d.ts +31 -0
- package/system/dist/kernel/deps/system-package-client.d.ts +9 -0
- package/system/dist/kernel/device-call-redirect.d.ts +18 -0
- package/system/dist/kernel/device-registry.d.ts +29 -0
- package/system/dist/kernel/device-settings-store.d.ts +74 -0
- package/system/dist/kernel/event-loop-stall-monitor.d.ts +41 -0
- package/system/dist/kernel/event-plane-report.d.ts +225 -0
- package/system/dist/kernel/fs-utils.d.ts +88 -0
- package/system/dist/kernel/gc-census.d.ts +161 -0
- package/system/dist/kernel/heap-spaces.d.ts +112 -0
- package/system/dist/kernel/heap-watch.d.ts +816 -0
- package/system/dist/kernel/host-externals.d.ts +12 -0
- package/system/dist/kernel/hwaccel/hwaccel-resolver.d.ts +56 -0
- package/system/dist/kernel/hwaccel/vaapi-init-probe.d.ts +29 -0
- package/system/dist/kernel/index.d.ts +116 -0
- package/system/dist/kernel/inference/inference-resolver.d.ts +22 -0
- package/system/dist/kernel/inference/local-python-runtimes.d.ts +2 -0
- package/system/dist/kernel/infra-capabilities.d.ts +13 -0
- package/system/dist/kernel/isolated-builtin-phase.d.ts +57 -0
- package/system/dist/kernel/lifecycle/job-journal.d.ts +19 -0
- package/system/dist/kernel/lifecycle/lifecycle-job-engine.d.ts +106 -0
- package/system/dist/kernel/lifecycle/staging-area.d.ts +31 -0
- package/system/dist/kernel/moleculer/accessory-prune-gate.d.ts +55 -0
- package/system/dist/kernel/moleculer/addon-context-factory.d.ts +104 -0
- package/system/dist/kernel/moleculer/addon-data-plane-facility.d.ts +19 -0
- package/system/dist/kernel/moleculer/addon-deploy-source.d.ts +16 -0
- package/system/dist/kernel/moleculer/addon-peer-bytes-facility.d.ts +25 -0
- package/system/dist/kernel/moleculer/addon-runner.d.ts +1 -0
- package/system/dist/kernel/moleculer/addon-service-factory.d.ts +50 -0
- package/system/dist/kernel/moleculer/agent-event-scope.d.ts +49 -0
- package/system/dist/kernel/moleculer/agent-ui-unlock.d.ts +67 -0
- package/system/dist/kernel/moleculer/broker-factory.d.ts +95 -0
- package/system/dist/kernel/moleculer/broker-transport-swap.d.ts +60 -0
- package/system/dist/kernel/moleculer/cap-usage-registry.d.ts +126 -0
- package/system/dist/kernel/moleculer/capabilities-access.d.ts +21 -0
- package/system/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +53 -0
- package/system/dist/kernel/moleculer/child-cap-descriptors.d.ts +34 -0
- package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +59 -0
- package/system/dist/kernel/moleculer/children-batch-loader.d.ts +98 -0
- package/system/dist/kernel/moleculer/core-cap-service.d.ts +65 -0
- package/system/dist/kernel/moleculer/crash-supervisor.d.ts +50 -0
- package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +70 -0
- package/system/dist/kernel/moleculer/device-event-ring.d.ts +155 -0
- package/system/dist/kernel/moleculer/event-bus-core.d.ts +198 -0
- package/system/dist/kernel/moleculer/event-bus.d.ts +106 -0
- package/system/dist/kernel/moleculer/hub-log-forwarder.d.ts +36 -0
- package/system/dist/kernel/moleculer/hub-service.d.ts +39 -0
- package/system/dist/kernel/moleculer/init-watchdog.d.ts +60 -0
- package/system/dist/kernel/moleculer/mesh-access-middleware.d.ts +42 -0
- package/system/dist/kernel/moleculer/mesh-identity.d.ts +57 -0
- package/system/dist/kernel/moleculer/mesh-mtls/constants.d.ts +17 -0
- package/system/dist/kernel/moleculer/mesh-mtls/index.d.ts +12 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca-keeper.d.ts +60 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca.d.ts +49 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-certificate-registry.d.ts +105 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-crl.d.ts +16 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-membership.d.ts +64 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-peer-transport.d.ts +47 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-renewal.d.ts +135 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-enabler.d.ts +9 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-gate.d.ts +40 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/agent-pairing.d.ts +214 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/hub-pairing.d.ts +115 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/index.d.ts +3 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/pairing-protocol.d.ts +107 -0
- package/system/dist/kernel/moleculer/mesh-mtls/tls-tcp-transporter.d.ts +242 -0
- package/system/dist/kernel/moleculer/mesh-queue-report.d.ts +51 -0
- package/system/dist/kernel/moleculer/node-registry.d.ts +146 -0
- package/system/dist/kernel/moleculer/process-context.d.ts +4 -0
- package/system/dist/kernel/moleculer/process-service.d.ts +92 -0
- package/system/dist/kernel/moleculer/provider-registry.d.ts +28 -0
- package/system/dist/kernel/moleculer/readiness-context.d.ts +67 -0
- package/system/dist/kernel/moleculer/readiness-service.d.ts +37 -0
- package/system/dist/kernel/moleculer/records-api-transport.d.ts +9 -0
- package/system/dist/kernel/moleculer/register-framework-resolver.d.ts +8 -0
- package/system/dist/kernel/moleculer/register-node-client.d.ts +49 -0
- package/system/dist/kernel/moleculer/remote-logger.d.ts +43 -0
- package/system/dist/kernel/moleculer/resilient-cap-call.d.ts +28 -0
- package/system/dist/kernel/moleculer/runner-addon-settings.d.ts +29 -0
- package/system/dist/kernel/moleculer/runner-device-settings.d.ts +39 -0
- package/system/dist/kernel/moleculer/runner-heap-flags.d.ts +228 -0
- package/system/dist/kernel/moleculer/runner-native-allocator.d.ts +107 -0
- package/system/dist/kernel/moleculer/runner-process-group.d.ts +96 -0
- package/system/dist/kernel/moleculer/runner-refusal.d.ts +27 -0
- package/system/dist/kernel/moleculer/runtime-state-load.d.ts +29 -0
- package/system/dist/kernel/moleculer/settings-read-guard.d.ts +49 -0
- package/system/dist/kernel/moleculer/stream-probe-service.d.ts +28 -0
- package/system/dist/kernel/moleculer/trpc-links.d.ts +244 -0
- package/system/dist/kernel/moleculer/typed-array-serde.d.ts +14 -0
- package/system/dist/kernel/moleculer/worker-device-restore.d.ts +10 -0
- package/system/dist/kernel/outbound-queue-watch.d.ts +94 -0
- package/system/dist/kernel/prefix-walk.d.ts +39 -0
- package/system/dist/kernel/process-cpu-census.d.ts +74 -0
- package/system/dist/kernel/provider-kind-drift.d.ts +21 -0
- package/system/dist/kernel/restart-coordinator.d.ts +90 -0
- package/system/dist/kernel/sections-store.d.ts +20 -0
- package/system/dist/kernel/settings-door-view.d.ts +41 -0
- package/system/dist/kernel/settings-read-error.d.ts +35 -0
- package/system/dist/kernel/settings-view-types.d.ts +80 -0
- package/system/dist/kernel/socket-plane-report.d.ts +268 -0
- package/system/dist/kernel/status-overlay.d.ts +38 -0
- package/system/dist/kernel/storage-location-registry.d.ts +55 -0
- package/system/dist/kernel/store-settings-view.d.ts +14 -0
- package/system/dist/kernel/system-settings-mirror.d.ts +46 -0
- package/system/dist/kernel/system-settings-policy.d.ts +28 -0
- package/system/dist/kernel/transport/cap-action-census.d.ts +218 -0
- package/system/dist/kernel/transport/cap-action-name.d.ts +100 -0
- package/system/dist/kernel/transport/cap-child-index.d.ts +49 -0
- package/system/dist/kernel/transport/cap-route-resolver.d.ts +231 -0
- package/system/dist/kernel/transport/cap-route.d.ts +168 -0
- package/system/dist/kernel/transport/cap-routing-hints.d.ts +42 -0
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +307 -0
- package/system/dist/kernel/transport/claimed-get-status.d.ts +39 -0
- package/system/dist/kernel/transport/create-local-transport.d.ts +7 -0
- package/system/dist/kernel/transport/device-call-redirect.d.ts +39 -0
- package/system/dist/kernel/transport/frame-codec.d.ts +122 -0
- package/system/dist/kernel/transport/hub-cap-forward.d.ts +96 -0
- package/system/dist/kernel/transport/index.d.ts +38 -0
- package/system/dist/kernel/transport/local-child-client.d.ts +199 -0
- package/system/dist/kernel/transport/local-child-registry.d.ts +654 -0
- package/system/dist/kernel/transport/local-endpoint-path.d.ts +6 -0
- package/system/dist/kernel/transport/local-transport.d.ts +122 -0
- package/system/dist/kernel/transport/parent-unowned-call.d.ts +283 -0
- package/system/dist/kernel/transport/peer-answered-error.d.ts +21 -0
- package/system/dist/kernel/transport/socket-channel.d.ts +116 -0
- package/system/dist/kernel/transport/socket-traffic.d.ts +118 -0
- package/system/dist/kernel/transport/uds-event-bridge.d.ts +85 -0
- package/system/dist/kernel/transport/uds-event-bus.d.ts +93 -0
- package/system/dist/kernel/transport/uds-local-transport.d.ts +18 -0
- package/system/dist/kernel/transport/uds-log-ingest.d.ts +43 -0
- package/system/dist/kernel/transport/uds-logger.d.ts +44 -0
- package/system/dist/kernel/utils/ring-buffer.d.ts +15 -0
- package/system/dist/kernel/workspace-detect.d.ts +9 -0
- package/system/dist/lib-5THG9eKz.mjs +15545 -0
- package/system/dist/lib-C3U1yluo.js +7110 -0
- package/system/dist/lib-CZ3g2WTS.js +15549 -0
- package/system/dist/lib-DFZblCIu.mjs +7106 -0
- package/system/dist/lifecycle/lifecycle-state-machine.d.ts +28 -0
- package/system/dist/log-file-read-protocol-B7M3X3bT.mjs +785 -0
- package/system/dist/log-file-read-protocol-D0WcLbIV.js +817 -0
- package/system/dist/log-file-read-worker.js +64 -0
- package/system/dist/log-file-read-worker.mjs +64 -0
- package/system/dist/log-read-filter-Bi066jwU.js +134 -0
- package/system/dist/log-read-filter-D7Ev3zm-.mjs +93 -0
- package/system/dist/logging/formatter.d.ts +57 -0
- package/system/dist/logging/log-manager.d.ts +145 -0
- package/system/dist/logging/log-read-filter.d.ts +43 -0
- package/system/dist/logging/log-redactor.d.ts +30 -0
- package/system/dist/logging/log-ring-buffer.d.ts +62 -0
- package/system/dist/logging/logging-gate.d.ts +76 -0
- package/system/dist/logging/logging-gate.singleton.d.ts +16 -0
- package/system/dist/logging/partitioned-log-buffer.d.ts +169 -0
- package/system/dist/logging/scoped-logger.d.ts +17 -0
- package/system/dist/migrations/hub/index.d.ts +11 -0
- package/system/dist/ms-CgH2OFlD.mjs +120 -0
- package/system/dist/ms-LB3giGoU.js +124 -0
- package/system/dist/network/network-quality.d.ts +11 -0
- package/system/dist/notification/notification-service.d.ts +43 -0
- package/system/dist/notification/toast-service.d.ts +22 -0
- package/system/dist/pipeline/engine-manager-resolver.d.ts +15 -0
- package/system/dist/pipeline/pipeline-runner.d.ts +8 -0
- package/system/dist/pipeline/pipeline-validator.d.ts +13 -0
- package/system/dist/platform-key-source-BWlq0jjn.mjs +23 -0
- package/system/dist/platform-key-source-Di7HrlGR.js +40 -0
- package/system/dist/prefix-range-D_KueXbQ.js +27 -0
- package/system/dist/prefix-range-Dl0znowN.mjs +22 -0
- package/system/dist/prefix-walk-DAOBSyH1.mjs +88 -0
- package/system/dist/prefix-walk-Dv6MLZlM.js +99 -0
- package/system/dist/process/proc-stat.d.ts +75 -0
- package/system/dist/process/resource-monitor.d.ts +28 -0
- package/system/dist/python/python-env-manager.d.ts +12 -0
- package/system/dist/read-all-rows-CVoO1ONM.js +29 -0
- package/system/dist/read-all-rows-TaPqdWNF.mjs +25 -0
- package/system/dist/records/read-all-rows.d.ts +6 -0
- package/system/dist/repl/interfaces.d.ts +31 -0
- package/system/dist/repl/repl-engine.d.ts +8 -0
- package/system/dist/resource-monitor-Di9daRwI.mjs +96 -0
- package/system/dist/resource-monitor-mio9dSCT.js +113 -0
- package/system/dist/restore-archive-Cy7jGqiD.js +4325 -0
- package/system/dist/restore-archive-DS4nvQ43.mjs +4213 -0
- package/system/dist/retention-Dqm_EiVq.mjs +893 -0
- package/system/dist/retention-Ufa2fci-.js +1024 -0
- package/system/dist/retired-settings-keys-C8nOOr5H.js +381 -0
- package/system/dist/retired-settings-keys-u6xQA6r7.mjs +364 -0
- package/system/dist/safe-buffer-B1OjL1I9.mjs +42 -0
- package/system/dist/safe-buffer-D3aoa-7X.js +46 -0
- package/system/dist/settle-sources-Bhsy57y-.js +38 -0
- package/system/dist/settle-sources-CDtNC8ub.mjs +33 -0
- package/system/dist/snapshot-courtesy-CyFs1M3I.mjs +167 -0
- package/system/dist/snapshot-courtesy-D_C5-nC0.js +192 -0
- package/system/dist/sqlite-snapshot-protocol-2QaTouWV.mjs +34 -0
- package/system/dist/sqlite-snapshot-protocol-B9OndqZv.js +51 -0
- package/system/dist/sqlite-snapshot-worker.js +185 -0
- package/system/dist/sqlite-snapshot-worker.mjs +179 -0
- package/system/dist/src-CnAqG6EF.js +714 -0
- package/system/dist/src-hG4grMU4.mjs +709 -0
- package/system/dist/storage/fs-storage-backend.d.ts +40 -0
- package/system/dist/storage/storage-location-manager.d.ts +23 -0
- package/system/dist/storage/storage-manager.d.ts +83 -0
- package/system/dist/tls/agent-https-names.d.ts +25 -0
- package/system/dist/tls/agent-https.d.ts +111 -0
- package/system/dist/tls/boot-tls.d.ts +35 -0
- package/system/dist/tls/cert-backdate.d.ts +10 -0
- package/system/dist/tls/cert-evaluation.d.ts +41 -0
- package/system/dist/tls/cert-identity.d.ts +60 -0
- package/system/dist/tls/cert-issue.d.ts +57 -0
- package/system/dist/tls/cert-manager.d.ts +124 -0
- package/system/dist/tls/cert-name-constraints.d.ts +53 -0
- package/system/dist/tls/cert-utc-time.d.ts +1 -0
- package/system/dist/tls/https-listener.d.ts +30 -0
- package/system/dist/tls/index.d.ts +12 -0
- package/system/dist/tls/tls-actions.d.ts +49 -0
- package/system/dist/tls/tls-status.d.ts +57 -0
- package/system/dist/tls/uploaded-cert.d.ts +46 -0
- package/system/dist/wal-checkpoint-policy-BahrTtyD.mjs +186 -0
- package/system/dist/wal-checkpoint-policy-d2z2qPqx.js +233 -0
- package/system/dist/wal-checkpoint-worker.js +144 -0
- package/system/dist/wal-checkpoint-worker.mjs +143 -0
- package/system/dist/wal-maintenance-BmugbgS7.js +0 -0
- package/system/dist/wal-maintenance-Bnb2QzYG.mjs +0 -0
- package/system/dist/x509.es-BRiJgOvu.mjs +11939 -0
- package/system/dist/x509.es-WtnRNyYS.js +12076 -0
- package/system/package.json +516 -0
|
@@ -0,0 +1,3213 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
6
|
+
const require_dist = require("../../dist-M9yHiIY7.js");
|
|
7
|
+
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
8
|
+
const require_restore_archive = require("../../restore-archive-Cy7jGqiD.js");
|
|
9
|
+
let node_crypto = require("node:crypto");
|
|
10
|
+
let node_fs_promises = require("node:fs/promises");
|
|
11
|
+
node_fs_promises = require_chunk.__toESM(node_fs_promises);
|
|
12
|
+
let node_path = require("node:path");
|
|
13
|
+
node_path = require_chunk.__toESM(node_path);
|
|
14
|
+
let node_fs = require("node:fs");
|
|
15
|
+
node_fs = require_chunk.__toESM(node_fs);
|
|
16
|
+
//#region src/builtins/backup-orchestrator/backup-databases.ts
|
|
17
|
+
/** Stable id of the seeded weekly schedule. */
|
|
18
|
+
var WEEKLY_SCHEDULE_ID = "weekly-events-history";
|
|
19
|
+
var WEEKLY_SCHEDULE_LABEL = "Weekly — events & history";
|
|
20
|
+
/** Sundays 04:00 — an hour after the nightly settings run. */
|
|
21
|
+
var WEEKLY_SCHEDULE_CRON = "0 4 * * 0";
|
|
22
|
+
/**
|
|
23
|
+
* Events and history ONLY: a run that does not select settings carries no
|
|
24
|
+
* data-root walk either, so the weekly archive is just the two snapshots.
|
|
25
|
+
*/
|
|
26
|
+
var WEEKLY_SCHEDULE_DATABASES = ["events", "history"];
|
|
27
|
+
/** What a schedule carries: its own list, else the minimum (D382). */
|
|
28
|
+
function databasesOfSchedule(schedule) {
|
|
29
|
+
return schedule.databases !== void 0 && schedule.databases.length > 0 ? schedule.databases : require_restore_archive.DEFAULT_BACKUP_DATABASES;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* True when a run asks for a database beyond settings and the owner has none
|
|
33
|
+
* of them open: the run would only repeat the nightly archive. A settings-only
|
|
34
|
+
* run is never nothing-to-carry.
|
|
35
|
+
*/
|
|
36
|
+
function hasNothingBeyondSettings(requested, owned) {
|
|
37
|
+
const extra = requested.filter((id) => id !== "settings");
|
|
38
|
+
if (extra.length === 0) return false;
|
|
39
|
+
return !extra.some((id) => owned.includes(id));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The weekly schedule to seed, or null. Created only when NO schedule carries
|
|
43
|
+
* `events` (a seed never overwrites, D728 — an operator's own weekly schedule,
|
|
44
|
+
* or an edited seed, is left alone), and only when there is a nightly schedule
|
|
45
|
+
* to take the destinations from: a hub that backs up nowhere gets no weekly
|
|
46
|
+
* archive either.
|
|
47
|
+
*/
|
|
48
|
+
function planWeeklySeed(existing) {
|
|
49
|
+
if (existing.some((s) => s.id === "weekly-events-history")) return null;
|
|
50
|
+
if (existing.some((s) => databasesOfSchedule(s).includes("events"))) return null;
|
|
51
|
+
const destinations = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const s of existing) {
|
|
53
|
+
if (!s.enabled) continue;
|
|
54
|
+
for (const id of s.locationIds) destinations.add(id);
|
|
55
|
+
}
|
|
56
|
+
if (destinations.size === 0) return null;
|
|
57
|
+
return {
|
|
58
|
+
id: WEEKLY_SCHEDULE_ID,
|
|
59
|
+
label: WEEKLY_SCHEDULE_LABEL,
|
|
60
|
+
cron: WEEKLY_SCHEDULE_CRON,
|
|
61
|
+
enabled: true,
|
|
62
|
+
locationIds: [...destinations].toSorted(),
|
|
63
|
+
retentionCount: 4,
|
|
64
|
+
databases: WEEKLY_SCHEDULE_DATABASES
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Seed the weekly schedule if {@link planWeeklySeed} says so; returns what it
|
|
69
|
+
* wrote. Exactly once ever: the marker is written after the row, and a marker
|
|
70
|
+
* that exists ends the seed for good — an operator who disabled or deleted the
|
|
71
|
+
* weekly is never second-guessed. A weekly row found with no marker (seeded
|
|
72
|
+
* before the marker existed) is marked, not re-created.
|
|
73
|
+
*/
|
|
74
|
+
async function seedWeeklySchedule(store, markers) {
|
|
75
|
+
if (await markers.has("weekly-events-history")) return null;
|
|
76
|
+
const existing = await store.list();
|
|
77
|
+
if (existing.some((s) => s.id === "weekly-events-history")) {
|
|
78
|
+
await markers.mark(WEEKLY_SCHEDULE_ID);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const seed = planWeeklySeed(existing);
|
|
82
|
+
if (seed === null) return null;
|
|
83
|
+
await store.upsert(seed);
|
|
84
|
+
await markers.mark(WEEKLY_SCHEDULE_ID);
|
|
85
|
+
return seed;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/builtins/backup-orchestrator/seed-marker-store.ts
|
|
89
|
+
/**
|
|
90
|
+
* One `seed-markers` row per seed id (D902: no `backup_seed_markers` table).
|
|
91
|
+
* Written once, never updated; deleting one lets that seed run once more.
|
|
92
|
+
*/
|
|
93
|
+
var BackupSeedMarkerStore = class {
|
|
94
|
+
markersKind;
|
|
95
|
+
now;
|
|
96
|
+
constructor(markersKind, now = Date.now) {
|
|
97
|
+
this.markersKind = markersKind;
|
|
98
|
+
this.now = now;
|
|
99
|
+
}
|
|
100
|
+
async has(seedId) {
|
|
101
|
+
return await this.markersKind.get(seedId) !== null;
|
|
102
|
+
}
|
|
103
|
+
async mark(seedId) {
|
|
104
|
+
if (await this.has(seedId)) return;
|
|
105
|
+
const body = { seededAt: this.now() };
|
|
106
|
+
const data = require_restore_archive.backupOrchestratorRecordKinds["seed-markers"].schema.parse(body);
|
|
107
|
+
await this.markersKind.put({
|
|
108
|
+
id: seedId,
|
|
109
|
+
data
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region ../../node_modules/croner/dist/croner.js
|
|
115
|
+
function T(s) {
|
|
116
|
+
return Date.UTC(s.y, s.m - 1, s.d, s.h, s.i, s.s);
|
|
117
|
+
}
|
|
118
|
+
function D(s, e) {
|
|
119
|
+
return s.y === e.y && s.m === e.m && s.d === e.d && s.h === e.h && s.i === e.i && s.s === e.s;
|
|
120
|
+
}
|
|
121
|
+
function A(s, e) {
|
|
122
|
+
let t = new Date(Date.parse(s));
|
|
123
|
+
if (isNaN(t)) throw new Error("Invalid ISO8601 passed to timezone parser.");
|
|
124
|
+
let r = s.substring(9);
|
|
125
|
+
return r.includes("Z") || r.includes("+") || r.includes("-") ? b(t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds(), "Etc/UTC") : b(t.getFullYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), e);
|
|
126
|
+
}
|
|
127
|
+
function v(s, e, t) {
|
|
128
|
+
return k(A(s, e), t);
|
|
129
|
+
}
|
|
130
|
+
function k(s, e) {
|
|
131
|
+
let t = new Date(T(s)), r = g(t, s.tz), a = T(s) - T(r), o = new Date(t.getTime() + a), h = g(o, s.tz);
|
|
132
|
+
if (D(h, s)) {
|
|
133
|
+
let u = /* @__PURE__ */ new Date(o.getTime() - 36e5);
|
|
134
|
+
return D(g(u, s.tz), s) ? u : o;
|
|
135
|
+
}
|
|
136
|
+
let l = new Date(o.getTime() + T(s) - T(h));
|
|
137
|
+
if (D(g(l, s.tz), s)) return l;
|
|
138
|
+
if (e) throw new Error("Invalid date passed to fromTZ()");
|
|
139
|
+
return o.getTime() > l.getTime() ? o : l;
|
|
140
|
+
}
|
|
141
|
+
function g(s, e) {
|
|
142
|
+
let t, r;
|
|
143
|
+
try {
|
|
144
|
+
t = new Intl.DateTimeFormat("en-US", {
|
|
145
|
+
timeZone: e,
|
|
146
|
+
year: "numeric",
|
|
147
|
+
month: "numeric",
|
|
148
|
+
day: "numeric",
|
|
149
|
+
hour: "numeric",
|
|
150
|
+
minute: "numeric",
|
|
151
|
+
second: "numeric",
|
|
152
|
+
hour12: !1
|
|
153
|
+
}), r = t.formatToParts(s);
|
|
154
|
+
} catch (i) {
|
|
155
|
+
let a = i instanceof Error ? i.message : String(i);
|
|
156
|
+
throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`);
|
|
157
|
+
}
|
|
158
|
+
let n = {
|
|
159
|
+
year: 0,
|
|
160
|
+
month: 0,
|
|
161
|
+
day: 0,
|
|
162
|
+
hour: 0,
|
|
163
|
+
minute: 0,
|
|
164
|
+
second: 0
|
|
165
|
+
};
|
|
166
|
+
for (let i of r) (i.type === "year" || i.type === "month" || i.type === "day" || i.type === "hour" || i.type === "minute" || i.type === "second") && (n[i.type] = parseInt(i.value, 10));
|
|
167
|
+
if (isNaN(n.year) || isNaN(n.month) || isNaN(n.day) || isNaN(n.hour) || isNaN(n.minute) || isNaN(n.second)) throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);
|
|
168
|
+
return n.hour === 24 && (n.hour = 0), {
|
|
169
|
+
y: n.year,
|
|
170
|
+
m: n.month,
|
|
171
|
+
d: n.day,
|
|
172
|
+
h: n.hour,
|
|
173
|
+
i: n.minute,
|
|
174
|
+
s: n.second,
|
|
175
|
+
tz: e
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function b(s, e, t, r, n, i, a) {
|
|
179
|
+
return {
|
|
180
|
+
y: s,
|
|
181
|
+
m: e,
|
|
182
|
+
d: t,
|
|
183
|
+
h: r,
|
|
184
|
+
i: n,
|
|
185
|
+
s: i,
|
|
186
|
+
tz: a
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
var O = [
|
|
190
|
+
1,
|
|
191
|
+
2,
|
|
192
|
+
4,
|
|
193
|
+
8,
|
|
194
|
+
16
|
|
195
|
+
], C = class {
|
|
196
|
+
pattern;
|
|
197
|
+
timezone;
|
|
198
|
+
mode;
|
|
199
|
+
alternativeWeekdays;
|
|
200
|
+
sloppyRanges;
|
|
201
|
+
second;
|
|
202
|
+
minute;
|
|
203
|
+
hour;
|
|
204
|
+
day;
|
|
205
|
+
month;
|
|
206
|
+
dayOfWeek;
|
|
207
|
+
year;
|
|
208
|
+
lastDayOfMonth;
|
|
209
|
+
lastWeekday;
|
|
210
|
+
nearestWeekdays;
|
|
211
|
+
starDOM;
|
|
212
|
+
starDOW;
|
|
213
|
+
starYear;
|
|
214
|
+
useAndLogic;
|
|
215
|
+
constructor(e, t, r) {
|
|
216
|
+
this.pattern = e, this.timezone = t, this.mode = r?.mode ?? "auto", this.alternativeWeekdays = r?.alternativeWeekdays ?? !1, this.sloppyRanges = r?.sloppyRanges ?? !1, this.second = Array(60).fill(0), this.minute = Array(60).fill(0), this.hour = Array(24).fill(0), this.day = Array(31).fill(0), this.month = Array(12).fill(0), this.dayOfWeek = Array(7).fill(0), this.year = Array(1e4).fill(0), this.lastDayOfMonth = !1, this.lastWeekday = !1, this.nearestWeekdays = Array(31).fill(0), this.starDOM = !1, this.starDOW = !1, this.starYear = !1, this.useAndLogic = !1, this.parse();
|
|
217
|
+
}
|
|
218
|
+
parse() {
|
|
219
|
+
if (!(typeof this.pattern == "string" || this.pattern instanceof String)) throw new TypeError("CronPattern: Pattern has to be of type string.");
|
|
220
|
+
this.pattern.indexOf("@") >= 0 && (this.pattern = this.handleNicknames(this.pattern).trim());
|
|
221
|
+
let e = this.pattern.match(/\S+/g) || [""], t = e.length;
|
|
222
|
+
if (e.length < 5 || e.length > 7) throw new TypeError("CronPattern: invalid configuration format ('" + this.pattern + "'), exactly five, six, or seven space separated parts are required.");
|
|
223
|
+
if (this.mode !== "auto") {
|
|
224
|
+
let n;
|
|
225
|
+
switch (this.mode) {
|
|
226
|
+
case "5-part":
|
|
227
|
+
n = 5;
|
|
228
|
+
break;
|
|
229
|
+
case "6-part":
|
|
230
|
+
n = 6;
|
|
231
|
+
break;
|
|
232
|
+
case "7-part":
|
|
233
|
+
n = 7;
|
|
234
|
+
break;
|
|
235
|
+
case "5-or-6-parts":
|
|
236
|
+
n = [5, 6];
|
|
237
|
+
break;
|
|
238
|
+
case "6-or-7-parts":
|
|
239
|
+
n = [6, 7];
|
|
240
|
+
break;
|
|
241
|
+
default: n = 0;
|
|
242
|
+
}
|
|
243
|
+
if (!(Array.isArray(n) ? n.includes(t) : t === n)) {
|
|
244
|
+
let a = Array.isArray(n) ? n.join(" or ") : n.toString();
|
|
245
|
+
throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (e.length === 5 && e.unshift("0"), e.length === 6 && e.push("*"), e[3].toUpperCase() === "LW" ? (this.lastWeekday = !0, e[3] = "") : e[3].toUpperCase().indexOf("L") >= 0 && (e[3] = e[3].replace(/L/gi, ""), this.lastDayOfMonth = !0), e[3] == "*" && (this.starDOM = !0), e[6] == "*" && (this.starYear = !0), e[4].length >= 3 && (e[4] = this.replaceAlphaMonths(e[4])), e[5].length >= 3 && (e[5] = this.alternativeWeekdays ? this.replaceAlphaDaysQuartz(e[5]) : this.replaceAlphaDays(e[5])), e[5].startsWith("+") && (this.useAndLogic = !0, e[5] = e[5].substring(1), e[5] === "")) throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");
|
|
249
|
+
switch (e[5] == "*" && (this.starDOW = !0), this.pattern.indexOf("?") >= 0 && (e[0] = e[0].replace(/\?/g, "*"), e[1] = e[1].replace(/\?/g, "*"), e[2] = e[2].replace(/\?/g, "*"), e[3] = e[3].replace(/\?/g, "*"), e[4] = e[4].replace(/\?/g, "*"), e[5] = e[5].replace(/\?/g, "*"), e[6] && (e[6] = e[6].replace(/\?/g, "*"))), this.mode) {
|
|
250
|
+
case "5-part":
|
|
251
|
+
e[0] = "0", e[6] = "*";
|
|
252
|
+
break;
|
|
253
|
+
case "6-part":
|
|
254
|
+
e[6] = "*";
|
|
255
|
+
break;
|
|
256
|
+
case "5-or-6-parts":
|
|
257
|
+
e[6] = "*";
|
|
258
|
+
break;
|
|
259
|
+
case "6-or-7-parts": break;
|
|
260
|
+
case "7-part":
|
|
261
|
+
case "auto": break;
|
|
262
|
+
}
|
|
263
|
+
this.throwAtIllegalCharacters(e), this.partToArray("second", e[0], 0, 1), this.partToArray("minute", e[1], 0, 1), this.partToArray("hour", e[2], 0, 1), this.partToArray("day", e[3], -1, 1), this.partToArray("month", e[4], -1, 1);
|
|
264
|
+
let r = this.alternativeWeekdays ? -1 : 0;
|
|
265
|
+
this.partToArray("dayOfWeek", e[5], r, 63), this.partToArray("year", e[6], 0, 1), !this.alternativeWeekdays && this.dayOfWeek[7] && (this.dayOfWeek[0] = this.dayOfWeek[7]);
|
|
266
|
+
}
|
|
267
|
+
partToArray(e, t, r, n) {
|
|
268
|
+
let i = this[e], a = e === "day" && this.lastDayOfMonth, o = e === "day" && this.lastWeekday;
|
|
269
|
+
if (t === "" && !a && !o) throw new TypeError("CronPattern: configuration entry " + e + " (" + t + ") is empty, check for trailing spaces.");
|
|
270
|
+
if (t === "*") return i.fill(n);
|
|
271
|
+
let h = t.split(",");
|
|
272
|
+
if (h.length > 1) for (let l = 0; l < h.length; l++) this.partToArray(e, h[l], r, n);
|
|
273
|
+
else t.indexOf("-") !== -1 && t.indexOf("/") !== -1 ? this.handleRangeWithStepping(t, e, r, n) : t.indexOf("-") !== -1 ? this.handleRange(t, e, r, n) : t.indexOf("/") !== -1 ? this.handleStepping(t, e, r, n) : t !== "" && this.handleNumber(t, e, r, n);
|
|
274
|
+
}
|
|
275
|
+
throwAtIllegalCharacters(e) {
|
|
276
|
+
for (let t = 0; t < e.length; t++) if ((t === 3 ? /[^/*0-9,\-WwLl]+/ : t === 5 ? /[^/*0-9,\-#Ll]+/ : /[^/*0-9,\-]+/).test(e[t])) throw new TypeError("CronPattern: configuration entry " + t + " (" + e[t] + ") contains illegal characters.");
|
|
277
|
+
}
|
|
278
|
+
handleNumber(e, t, r, n) {
|
|
279
|
+
let i = this.extractNth(e, t), a = e.toUpperCase().includes("W");
|
|
280
|
+
if (t !== "day" && a) throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");
|
|
281
|
+
a && (t = "nearestWeekdays");
|
|
282
|
+
let o = parseInt(i[0], 10) + r;
|
|
283
|
+
if (isNaN(o)) throw new TypeError("CronPattern: " + t + " is not a number: '" + e + "'");
|
|
284
|
+
this.setPart(t, o, i[1] || n);
|
|
285
|
+
}
|
|
286
|
+
setPart(e, t, r) {
|
|
287
|
+
if (!Object.prototype.hasOwnProperty.call(this, e)) throw new TypeError("CronPattern: Invalid part specified: " + e);
|
|
288
|
+
if (e === "dayOfWeek") {
|
|
289
|
+
if (t === 7 && (t = 0), t < 0 || t > 6) throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + t);
|
|
290
|
+
this.setNthWeekdayOfMonth(t, r);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (e === "second" || e === "minute") {
|
|
294
|
+
if (t < 0 || t >= 60) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
295
|
+
} else if (e === "hour") {
|
|
296
|
+
if (t < 0 || t >= 24) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
297
|
+
} else if (e === "day" || e === "nearestWeekdays") {
|
|
298
|
+
if (t < 0 || t >= 31) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
299
|
+
} else if (e === "month") {
|
|
300
|
+
if (t < 0 || t >= 12) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
301
|
+
} else if (e === "year" && (t < 1 || t >= 1e4)) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t + " (supported range: 1-9999)");
|
|
302
|
+
this[e][t] = r;
|
|
303
|
+
}
|
|
304
|
+
validateNotNaN(e, t) {
|
|
305
|
+
if (isNaN(e)) throw new TypeError(t);
|
|
306
|
+
}
|
|
307
|
+
validateRange(e, t, r, n, i) {
|
|
308
|
+
if (e > t) throw new TypeError("CronPattern: From value is larger than to value: '" + i + "'");
|
|
309
|
+
if (r !== void 0) {
|
|
310
|
+
if (r === 0) throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
|
|
311
|
+
if (r > this[n].length) throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[n].length + ")");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
handleRangeWithStepping(e, t, r, n) {
|
|
315
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");
|
|
316
|
+
let i = this.extractNth(e, t), a = i[0].match(/^(\d+)-(\d+)\/(\d+)$/);
|
|
317
|
+
if (a === null) throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + e + "'");
|
|
318
|
+
let [, o, h, l] = a, y = parseInt(o, 10) + r, u = parseInt(h, 10) + r, d = parseInt(l, 10);
|
|
319
|
+
this.validateNotNaN(y, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(u, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateNotNaN(d, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(y, u, d, t, e);
|
|
320
|
+
for (let c = y; c <= u; c += d) this.setPart(t, c, i[1] || n);
|
|
321
|
+
}
|
|
322
|
+
extractNth(e, t) {
|
|
323
|
+
let r = e, n;
|
|
324
|
+
if (r.includes("#")) {
|
|
325
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
|
|
326
|
+
n = r.split("#")[1], r = r.split("#")[0];
|
|
327
|
+
} else if (r.toUpperCase().endsWith("L")) {
|
|
328
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");
|
|
329
|
+
n = "L", r = r.slice(0, -1);
|
|
330
|
+
}
|
|
331
|
+
return [r, n];
|
|
332
|
+
}
|
|
333
|
+
handleRange(e, t, r, n) {
|
|
334
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");
|
|
335
|
+
let i = this.extractNth(e, t), a = i[0].split("-");
|
|
336
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal range: '" + e + "'");
|
|
337
|
+
let o = parseInt(a[0], 10) + r, h = parseInt(a[1], 10) + r;
|
|
338
|
+
this.validateNotNaN(o, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(h, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateRange(o, h, void 0, t, e);
|
|
339
|
+
for (let l = o; l <= h; l++) this.setPart(t, l, i[1] || n);
|
|
340
|
+
}
|
|
341
|
+
handleStepping(e, t, r, n) {
|
|
342
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");
|
|
343
|
+
let i = this.extractNth(e, t), a = i[0].split("/");
|
|
344
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + e + "'");
|
|
345
|
+
if (this.sloppyRanges) a[0] === "" && (a[0] = "*");
|
|
346
|
+
else {
|
|
347
|
+
if (a[0] === "") throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
348
|
+
if (a[0] !== "*") throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
349
|
+
}
|
|
350
|
+
let o = 0;
|
|
351
|
+
a[0] !== "*" && (o = parseInt(a[0], 10) + r);
|
|
352
|
+
let h = parseInt(a[1], 10);
|
|
353
|
+
this.validateNotNaN(h, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(0, this[t].length - 1, h, t, e);
|
|
354
|
+
for (let l = o; l < this[t].length; l += h) this.setPart(t, l, i[1] || n);
|
|
355
|
+
}
|
|
356
|
+
replaceAlphaDays(e) {
|
|
357
|
+
return e.replace(/-sun/gi, "-7").replace(/sun/gi, "0").replace(/mon/gi, "1").replace(/tue/gi, "2").replace(/wed/gi, "3").replace(/thu/gi, "4").replace(/fri/gi, "5").replace(/sat/gi, "6");
|
|
358
|
+
}
|
|
359
|
+
replaceAlphaDaysQuartz(e) {
|
|
360
|
+
return e.replace(/sun/gi, "1").replace(/mon/gi, "2").replace(/tue/gi, "3").replace(/wed/gi, "4").replace(/thu/gi, "5").replace(/fri/gi, "6").replace(/sat/gi, "7");
|
|
361
|
+
}
|
|
362
|
+
replaceAlphaMonths(e) {
|
|
363
|
+
return e.replace(/jan/gi, "1").replace(/feb/gi, "2").replace(/mar/gi, "3").replace(/apr/gi, "4").replace(/may/gi, "5").replace(/jun/gi, "6").replace(/jul/gi, "7").replace(/aug/gi, "8").replace(/sep/gi, "9").replace(/oct/gi, "10").replace(/nov/gi, "11").replace(/dec/gi, "12");
|
|
364
|
+
}
|
|
365
|
+
handleNicknames(e) {
|
|
366
|
+
let t = e.trim().toLowerCase();
|
|
367
|
+
if (t === "@yearly" || t === "@annually") return "0 0 1 1 *";
|
|
368
|
+
if (t === "@monthly") return "0 0 1 * *";
|
|
369
|
+
if (t === "@weekly") return "0 0 * * 0";
|
|
370
|
+
if (t === "@daily" || t === "@midnight") return "0 0 * * *";
|
|
371
|
+
if (t === "@hourly") return "0 * * * *";
|
|
372
|
+
if (t === "@reboot") throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");
|
|
373
|
+
return e;
|
|
374
|
+
}
|
|
375
|
+
setNthWeekdayOfMonth(e, t) {
|
|
376
|
+
if (typeof t != "number" && t.toUpperCase() === "L") this.dayOfWeek[e] = this.dayOfWeek[e] | 32;
|
|
377
|
+
else if (t === 63) this.dayOfWeek[e] = 63;
|
|
378
|
+
else if (t < 6 && t > 0) this.dayOfWeek[e] = this.dayOfWeek[e] | O[t - 1];
|
|
379
|
+
else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var P = [
|
|
383
|
+
31,
|
|
384
|
+
28,
|
|
385
|
+
31,
|
|
386
|
+
30,
|
|
387
|
+
31,
|
|
388
|
+
30,
|
|
389
|
+
31,
|
|
390
|
+
31,
|
|
391
|
+
30,
|
|
392
|
+
31,
|
|
393
|
+
30,
|
|
394
|
+
31
|
|
395
|
+
], f = [
|
|
396
|
+
[
|
|
397
|
+
"month",
|
|
398
|
+
"year",
|
|
399
|
+
0
|
|
400
|
+
],
|
|
401
|
+
[
|
|
402
|
+
"day",
|
|
403
|
+
"month",
|
|
404
|
+
-1
|
|
405
|
+
],
|
|
406
|
+
[
|
|
407
|
+
"hour",
|
|
408
|
+
"day",
|
|
409
|
+
0
|
|
410
|
+
],
|
|
411
|
+
[
|
|
412
|
+
"minute",
|
|
413
|
+
"hour",
|
|
414
|
+
0
|
|
415
|
+
],
|
|
416
|
+
[
|
|
417
|
+
"second",
|
|
418
|
+
"minute",
|
|
419
|
+
0
|
|
420
|
+
]
|
|
421
|
+
], m = class s {
|
|
422
|
+
tz;
|
|
423
|
+
ms;
|
|
424
|
+
second;
|
|
425
|
+
minute;
|
|
426
|
+
hour;
|
|
427
|
+
day;
|
|
428
|
+
month;
|
|
429
|
+
year;
|
|
430
|
+
constructor(e, t) {
|
|
431
|
+
if (this.tz = t, e && e instanceof Date) if (!isNaN(e)) this.fromDate(e);
|
|
432
|
+
else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
|
|
433
|
+
else if (e == null) this.fromDate(/* @__PURE__ */ new Date());
|
|
434
|
+
else if (e && typeof e == "string") this.fromString(e);
|
|
435
|
+
else if (e instanceof s) this.fromCronDate(e);
|
|
436
|
+
else throw new TypeError("CronDate: Invalid type (" + typeof e + ") passed to CronDate constructor");
|
|
437
|
+
}
|
|
438
|
+
getLastDayOfMonth(e, t) {
|
|
439
|
+
return t !== 1 ? P[t] : new Date(Date.UTC(e, t + 1, 0)).getUTCDate();
|
|
440
|
+
}
|
|
441
|
+
getLastWeekday(e, t) {
|
|
442
|
+
let r = this.getLastDayOfMonth(e, t), i = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
443
|
+
return i === 0 ? r - 2 : i === 6 ? r - 1 : r;
|
|
444
|
+
}
|
|
445
|
+
getNearestWeekday(e, t, r) {
|
|
446
|
+
let n = this.getLastDayOfMonth(e, t);
|
|
447
|
+
if (r > n) return -1;
|
|
448
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
449
|
+
return a === 0 ? r === n ? r - 2 : r + 1 : a === 6 ? r === 1 ? r + 2 : r - 1 : r;
|
|
450
|
+
}
|
|
451
|
+
isNthWeekdayOfMonth(e, t, r, n) {
|
|
452
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay(), o = 0;
|
|
453
|
+
for (let h = 1; h <= r; h++) new Date(Date.UTC(e, t, h)).getUTCDay() === a && o++;
|
|
454
|
+
if (n & 63 && O[o - 1] & n) return !0;
|
|
455
|
+
if (n & 32) {
|
|
456
|
+
let h = this.getLastDayOfMonth(e, t);
|
|
457
|
+
for (let l = r + 1; l <= h; l++) if (new Date(Date.UTC(e, t, l)).getUTCDay() === a) return !1;
|
|
458
|
+
return !0;
|
|
459
|
+
}
|
|
460
|
+
return !1;
|
|
461
|
+
}
|
|
462
|
+
fromDate(e) {
|
|
463
|
+
if (this.tz !== void 0) if (typeof this.tz == "number") this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes() + this.tz, this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), this.apply();
|
|
464
|
+
else try {
|
|
465
|
+
let t = g(e, this.tz);
|
|
466
|
+
this.ms = e.getMilliseconds(), this.second = t.s, this.minute = t.i, this.hour = t.h, this.day = t.d, this.month = t.m - 1, this.year = t.y;
|
|
467
|
+
} catch (t) {
|
|
468
|
+
let r = t instanceof Error ? t.message : String(t);
|
|
469
|
+
throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`);
|
|
470
|
+
}
|
|
471
|
+
else this.ms = e.getMilliseconds(), this.second = e.getSeconds(), this.minute = e.getMinutes(), this.hour = e.getHours(), this.day = e.getDate(), this.month = e.getMonth(), this.year = e.getFullYear();
|
|
472
|
+
}
|
|
473
|
+
fromCronDate(e) {
|
|
474
|
+
this.tz = e.tz, this.year = e.year, this.month = e.month, this.day = e.day, this.hour = e.hour, this.minute = e.minute, this.second = e.second, this.ms = e.ms;
|
|
475
|
+
}
|
|
476
|
+
apply() {
|
|
477
|
+
if (this.month > 11 || this.month < 0 || this.day > P[this.month] || this.day < 1 || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
|
|
478
|
+
let e = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
|
|
479
|
+
return this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes(), this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), !0;
|
|
480
|
+
} else return !1;
|
|
481
|
+
}
|
|
482
|
+
fromString(e) {
|
|
483
|
+
if (typeof this.tz == "number") {
|
|
484
|
+
let t = v(e);
|
|
485
|
+
this.ms = t.getUTCMilliseconds(), this.second = t.getUTCSeconds(), this.minute = t.getUTCMinutes(), this.hour = t.getUTCHours(), this.day = t.getUTCDate(), this.month = t.getUTCMonth(), this.year = t.getUTCFullYear(), this.apply();
|
|
486
|
+
} else return this.fromDate(v(e, this.tz));
|
|
487
|
+
}
|
|
488
|
+
findNext(e, t, r, n) {
|
|
489
|
+
return this._findMatch(e, t, r, n, 1);
|
|
490
|
+
}
|
|
491
|
+
_findMatch(e, t, r, n, i) {
|
|
492
|
+
let a = this[t], o;
|
|
493
|
+
r.lastDayOfMonth && (o = this.getLastDayOfMonth(this.year, this.month));
|
|
494
|
+
let h = !r.starDOW && t == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0, l = this[t] + n, y = i === 1 ? (u) => u < r[t].length : (u) => u >= 0;
|
|
495
|
+
for (let u = l; y(u); u += i) {
|
|
496
|
+
let d = r[t][u];
|
|
497
|
+
if (t === "day" && !d) {
|
|
498
|
+
for (let c = 0; c < r.nearestWeekdays.length; c++) if (r.nearestWeekdays[c]) {
|
|
499
|
+
let M = this.getNearestWeekday(this.year, this.month, c - n);
|
|
500
|
+
if (M === -1) continue;
|
|
501
|
+
if (M === u - n) {
|
|
502
|
+
d = 1;
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (t === "day" && r.lastWeekday) {
|
|
508
|
+
let c = this.getLastWeekday(this.year, this.month);
|
|
509
|
+
u - n === c && (d = 1);
|
|
510
|
+
}
|
|
511
|
+
if (t === "day" && r.lastDayOfMonth && u - n == o && (d = 1), t === "day" && !r.starDOW) {
|
|
512
|
+
let c = r.dayOfWeek[(h + (u - n - 1)) % 7];
|
|
513
|
+
if (c && c & 63) c = this.isNthWeekdayOfMonth(this.year, this.month, u - n, c) ? 1 : 0;
|
|
514
|
+
else if (c) throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);
|
|
515
|
+
r.useAndLogic ? d = d && c : !e.domAndDow && !r.starDOM ? d = d || c : d = d && c;
|
|
516
|
+
}
|
|
517
|
+
if (d) return this[t] = u - n, a !== this[t] ? 2 : 1;
|
|
518
|
+
}
|
|
519
|
+
return 3;
|
|
520
|
+
}
|
|
521
|
+
recurse(e, t, r) {
|
|
522
|
+
if (r === 0 && !e.starYear) {
|
|
523
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
524
|
+
let i = -1;
|
|
525
|
+
for (let a = this.year + 1; a < e.year.length && a < 1e4; a++) if (e.year[a] === 1) {
|
|
526
|
+
i = a;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
if (i === -1) return null;
|
|
530
|
+
this.year = i, this.month = 0, this.day = 1, this.hour = 0, this.minute = 0, this.second = 0, this.ms = 0;
|
|
531
|
+
}
|
|
532
|
+
if (this.year >= 1e4) return null;
|
|
533
|
+
}
|
|
534
|
+
let n = this.findNext(t, f[r][0], e, f[r][2]);
|
|
535
|
+
if (n > 1) {
|
|
536
|
+
let i = r + 1;
|
|
537
|
+
for (; i < f.length;) this[f[i][0]] = -f[i][2], i++;
|
|
538
|
+
if (n === 3) {
|
|
539
|
+
if (this[f[r][1]]++, this[f[r][0]] = -f[r][2], this.apply(), r === 0 && !e.starYear) {
|
|
540
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0 && this.year < 1e4;) this.year++;
|
|
541
|
+
if (this.year >= 1e4 || this.year >= e.year.length) return null;
|
|
542
|
+
}
|
|
543
|
+
return this.recurse(e, t, 0);
|
|
544
|
+
} else if (this.apply()) return this.recurse(e, t, r - 1);
|
|
545
|
+
}
|
|
546
|
+
return r += 1, r >= f.length ? this : (e.starYear ? this.year >= 3e3 : this.year >= 1e4) ? null : this.recurse(e, t, r);
|
|
547
|
+
}
|
|
548
|
+
increment(e, t, r) {
|
|
549
|
+
return this.second += t.interval !== void 0 && t.interval > 1 && r ? t.interval : 1, this.ms = 0, this.apply(), this.recurse(e, t, 0);
|
|
550
|
+
}
|
|
551
|
+
decrement(e, t) {
|
|
552
|
+
return this.second -= t.interval !== void 0 && t.interval > 1 ? t.interval : 1, this.ms = 0, this.apply(), this.recurseBackward(e, t, 0, 0);
|
|
553
|
+
}
|
|
554
|
+
recurseBackward(e, t, r, n = 0) {
|
|
555
|
+
if (n > 1e4) return null;
|
|
556
|
+
if (r === 0 && !e.starYear) {
|
|
557
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
558
|
+
let a = -1;
|
|
559
|
+
for (let o = this.year - 1; o >= 0; o--) if (e.year[o] === 1) {
|
|
560
|
+
a = o;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
if (a === -1) return null;
|
|
564
|
+
this.year = a, this.month = 11, this.day = 31, this.hour = 23, this.minute = 59, this.second = 59, this.ms = 0;
|
|
565
|
+
}
|
|
566
|
+
if (this.year < 0) return null;
|
|
567
|
+
}
|
|
568
|
+
let i = this.findPrevious(t, f[r][0], e, f[r][2]);
|
|
569
|
+
if (i > 1) {
|
|
570
|
+
let a = r + 1;
|
|
571
|
+
for (; a < f.length;) {
|
|
572
|
+
let o = f[a][0], h = f[a][2], l = this.getMaxPatternValue(o, e, h);
|
|
573
|
+
this[o] = l, a++;
|
|
574
|
+
}
|
|
575
|
+
if (i === 3) {
|
|
576
|
+
if (this[f[r][1]]--, r === 0) {
|
|
577
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
578
|
+
this.day > y && (this.day = y);
|
|
579
|
+
}
|
|
580
|
+
if (r === 1) if (this.day <= 0) this.day = 1;
|
|
581
|
+
else {
|
|
582
|
+
let y = this.year, u = this.month;
|
|
583
|
+
for (; u < 0;) u += 12, y--;
|
|
584
|
+
for (; u > 11;) u -= 12, y++;
|
|
585
|
+
let d = u !== 1 ? P[u] : new Date(Date.UTC(y, u + 1, 0)).getUTCDate();
|
|
586
|
+
this.day > d && (this.day = d);
|
|
587
|
+
}
|
|
588
|
+
this.apply();
|
|
589
|
+
let o = f[r][0], h = f[r][2], l = this.getMaxPatternValue(o, e, h);
|
|
590
|
+
if (o === "day") {
|
|
591
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
592
|
+
this[o] = Math.min(l, y);
|
|
593
|
+
} else this[o] = l;
|
|
594
|
+
if (this.apply(), r === 0) {
|
|
595
|
+
let y = f[1][2], u = this.getMaxPatternValue("day", e, y), d = this.getLastDayOfMonth(this.year, this.month), c = Math.min(u, d);
|
|
596
|
+
c !== this.day && (this.day = c, this.hour = this.getMaxPatternValue("hour", e, f[2][2]), this.minute = this.getMaxPatternValue("minute", e, f[3][2]), this.second = this.getMaxPatternValue("second", e, f[4][2]));
|
|
597
|
+
}
|
|
598
|
+
if (r === 0 && !e.starYear) {
|
|
599
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0;) this.year--;
|
|
600
|
+
if (this.year < 0) return null;
|
|
601
|
+
}
|
|
602
|
+
return this.recurseBackward(e, t, 0, n + 1);
|
|
603
|
+
} else if (this.apply()) return this.recurseBackward(e, t, r - 1, n + 1);
|
|
604
|
+
}
|
|
605
|
+
return r += 1, r >= f.length ? this : this.year < 0 ? null : this.recurseBackward(e, t, r, n + 1);
|
|
606
|
+
}
|
|
607
|
+
getMaxPatternValue(e, t, r) {
|
|
608
|
+
if (e === "day" && t.lastDayOfMonth) return this.getLastDayOfMonth(this.year, this.month);
|
|
609
|
+
if (e === "day" && !t.starDOW) return this.getLastDayOfMonth(this.year, this.month);
|
|
610
|
+
for (let n = t[e].length - 1; n >= 0; n--) if (t[e][n]) return n - r;
|
|
611
|
+
return t[e].length - 1 - r;
|
|
612
|
+
}
|
|
613
|
+
findPrevious(e, t, r, n) {
|
|
614
|
+
return this._findMatch(e, t, r, n, -1);
|
|
615
|
+
}
|
|
616
|
+
getDate(e) {
|
|
617
|
+
return e || this.tz === void 0 ? new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms) : typeof this.tz == "number" ? new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms)) : k(b(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz), !1);
|
|
618
|
+
}
|
|
619
|
+
getTime() {
|
|
620
|
+
return this.getDate(!1).getTime();
|
|
621
|
+
}
|
|
622
|
+
match(e, t) {
|
|
623
|
+
if (!e.starYear && (this.year < 0 || this.year >= e.year.length || e.year[this.year] === 0)) return !1;
|
|
624
|
+
for (let r = 0; r < f.length; r++) {
|
|
625
|
+
let n = f[r][0], i = f[r][2], a = this[n];
|
|
626
|
+
if (a + i < 0 || a + i >= e[n].length) return !1;
|
|
627
|
+
let o = e[n][a + i];
|
|
628
|
+
if (n === "day") {
|
|
629
|
+
if (!o) {
|
|
630
|
+
for (let h = 0; h < e.nearestWeekdays.length; h++) if (e.nearestWeekdays[h]) {
|
|
631
|
+
let l = this.getNearestWeekday(this.year, this.month, h - i);
|
|
632
|
+
if (l !== -1 && l === a) {
|
|
633
|
+
o = 1;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (e.lastWeekday) a === this.getLastWeekday(this.year, this.month) && (o = 1);
|
|
639
|
+
if (e.lastDayOfMonth) a === this.getLastDayOfMonth(this.year, this.month) && (o = 1);
|
|
640
|
+
if (!e.starDOW) {
|
|
641
|
+
let h = new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay(), l = e.dayOfWeek[(h + (a - 1)) % 7];
|
|
642
|
+
l && l & 63 && (l = this.isNthWeekdayOfMonth(this.year, this.month, a, l) ? 1 : 0), e.useAndLogic ? o = o && l : !t.domAndDow && !e.starDOM ? o = o || l : o = o && l;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (!o) return !1;
|
|
646
|
+
}
|
|
647
|
+
return !0;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
function R(s) {
|
|
651
|
+
if (s === void 0 && (s = {}), delete s.name, s.legacyMode !== void 0 && s.domAndDow === void 0 ? s.domAndDow = !s.legacyMode : s.domAndDow === void 0 && (s.domAndDow = !1), s.legacyMode = !s.domAndDow, s.paused = s.paused === void 0 ? !1 : s.paused, s.maxRuns = s.maxRuns === void 0 ? Infinity : s.maxRuns, s.catch = s.catch === void 0 ? !1 : s.catch, s.interval = s.interval === void 0 ? 0 : parseInt(s.interval.toString(), 10), s.utcOffset = s.utcOffset === void 0 ? void 0 : parseInt(s.utcOffset.toString(), 10), s.dayOffset = s.dayOffset === void 0 ? 0 : parseInt(s.dayOffset.toString(), 10), s.unref = s.unref === void 0 ? !1 : s.unref, s.mode = s.mode === void 0 ? "auto" : s.mode, s.alternativeWeekdays = s.alternativeWeekdays === void 0 ? !1 : s.alternativeWeekdays, s.sloppyRanges = s.sloppyRanges === void 0 ? !1 : s.sloppyRanges, ![
|
|
652
|
+
"auto",
|
|
653
|
+
"5-part",
|
|
654
|
+
"6-part",
|
|
655
|
+
"7-part",
|
|
656
|
+
"5-or-6-parts",
|
|
657
|
+
"6-or-7-parts"
|
|
658
|
+
].includes(s.mode)) throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");
|
|
659
|
+
if (s.startAt && (s.startAt = new m(s.startAt, s.timezone)), s.stopAt && (s.stopAt = new m(s.stopAt, s.timezone)), s.interval !== null) {
|
|
660
|
+
if (isNaN(s.interval)) throw new Error("CronOptions: Supplied value for interval is not a number");
|
|
661
|
+
if (s.interval < 0) throw new Error("CronOptions: Supplied value for interval can not be negative");
|
|
662
|
+
}
|
|
663
|
+
if (s.utcOffset !== void 0) {
|
|
664
|
+
if (isNaN(s.utcOffset)) throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");
|
|
665
|
+
if (s.utcOffset < -870 || s.utcOffset > 870) throw new Error("CronOptions: utcOffset out of bounds.");
|
|
666
|
+
if (s.utcOffset !== void 0 && s.timezone) throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.");
|
|
667
|
+
}
|
|
668
|
+
if (s.unref !== !0 && s.unref !== !1) throw new Error("CronOptions: Unref should be either true, false or undefined(false).");
|
|
669
|
+
if (s.dayOffset !== void 0 && s.dayOffset !== 0 && isNaN(s.dayOffset)) throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");
|
|
670
|
+
return s;
|
|
671
|
+
}
|
|
672
|
+
function p(s) {
|
|
673
|
+
return Object.prototype.toString.call(s) === "[object Function]" || typeof s == "function" || s instanceof Function;
|
|
674
|
+
}
|
|
675
|
+
function _(s) {
|
|
676
|
+
return p(s);
|
|
677
|
+
}
|
|
678
|
+
function x(s) {
|
|
679
|
+
typeof Deno < "u" && typeof Deno.unrefTimer < "u" ? Deno.unrefTimer(s) : s && typeof s.unref < "u" && s.unref();
|
|
680
|
+
}
|
|
681
|
+
var W = 30 * 1e3, w = [], E = class {
|
|
682
|
+
name;
|
|
683
|
+
options;
|
|
684
|
+
_states;
|
|
685
|
+
fn;
|
|
686
|
+
getTz() {
|
|
687
|
+
return this.options.timezone || this.options.utcOffset;
|
|
688
|
+
}
|
|
689
|
+
applyDayOffset(e) {
|
|
690
|
+
if (this.options.dayOffset !== void 0 && this.options.dayOffset !== 0) {
|
|
691
|
+
let t = this.options.dayOffset * 24 * 60 * 60 * 1e3;
|
|
692
|
+
return new Date(e.getTime() + t);
|
|
693
|
+
}
|
|
694
|
+
return e;
|
|
695
|
+
}
|
|
696
|
+
constructor(e, t, r) {
|
|
697
|
+
let n, i;
|
|
698
|
+
if (p(t)) i = t;
|
|
699
|
+
else if (typeof t == "object") n = t;
|
|
700
|
+
else if (t !== void 0) throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
|
|
701
|
+
if (p(r)) i = r;
|
|
702
|
+
else if (typeof r == "object") n = r;
|
|
703
|
+
else if (r !== void 0) throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");
|
|
704
|
+
if (this.name = n?.name, this.options = R(n), this._states = {
|
|
705
|
+
kill: !1,
|
|
706
|
+
blocking: !1,
|
|
707
|
+
previousRun: void 0,
|
|
708
|
+
currentRun: void 0,
|
|
709
|
+
once: void 0,
|
|
710
|
+
currentTimeout: void 0,
|
|
711
|
+
maxRuns: n ? n.maxRuns : void 0,
|
|
712
|
+
paused: n ? n.paused : !1,
|
|
713
|
+
pattern: new C("* * * * *", void 0, { mode: "auto" })
|
|
714
|
+
}, e && (e instanceof Date || typeof e == "string" && e.indexOf(":") > 0) ? this._states.once = new m(e, this.getTz()) : this._states.pattern = new C(e, this.options.timezone, {
|
|
715
|
+
mode: this.options.mode,
|
|
716
|
+
alternativeWeekdays: this.options.alternativeWeekdays,
|
|
717
|
+
sloppyRanges: this.options.sloppyRanges
|
|
718
|
+
}), this.name) {
|
|
719
|
+
if (w.find((o) => o.name === this.name)) throw new Error("Cron: Tried to initialize new named job '" + this.name + "', but name already taken.");
|
|
720
|
+
w.push(this);
|
|
721
|
+
}
|
|
722
|
+
return i !== void 0 && _(i) && (this.fn = i, this.schedule()), this;
|
|
723
|
+
}
|
|
724
|
+
nextRun(e) {
|
|
725
|
+
let t = this._next(e);
|
|
726
|
+
return t ? this.applyDayOffset(t.getDate(!1)) : null;
|
|
727
|
+
}
|
|
728
|
+
nextRuns(e, t) {
|
|
729
|
+
this._states.maxRuns !== void 0 && e > this._states.maxRuns && (e = this._states.maxRuns);
|
|
730
|
+
let r = t || this._states.currentRun || void 0;
|
|
731
|
+
return this._enumerateRuns(e, r, "next");
|
|
732
|
+
}
|
|
733
|
+
previousRuns(e, t) {
|
|
734
|
+
return this._enumerateRuns(e, t || void 0, "previous");
|
|
735
|
+
}
|
|
736
|
+
_enumerateRuns(e, t, r) {
|
|
737
|
+
let n = [], i = t ? new m(t, this.getTz()) : null, a = r === "next" ? this._next : this._previous;
|
|
738
|
+
for (; e--;) {
|
|
739
|
+
let o = a.call(this, i);
|
|
740
|
+
if (!o) break;
|
|
741
|
+
let h = o.getDate(!1);
|
|
742
|
+
n.push(this.applyDayOffset(h)), i = o;
|
|
743
|
+
}
|
|
744
|
+
return n;
|
|
745
|
+
}
|
|
746
|
+
match(e) {
|
|
747
|
+
if (this._states.once) {
|
|
748
|
+
let r = new m(e, this.getTz());
|
|
749
|
+
r.ms = 0;
|
|
750
|
+
let n = new m(this._states.once, this.getTz());
|
|
751
|
+
return n.ms = 0, r.getTime() === n.getTime();
|
|
752
|
+
}
|
|
753
|
+
let t = new m(e, this.getTz());
|
|
754
|
+
return t.ms = 0, t.match(this._states.pattern, this.options);
|
|
755
|
+
}
|
|
756
|
+
getPattern() {
|
|
757
|
+
if (!this._states.once) return this._states.pattern ? this._states.pattern.pattern : void 0;
|
|
758
|
+
}
|
|
759
|
+
getOnce() {
|
|
760
|
+
return this._states.once ? this._states.once.getDate() : null;
|
|
761
|
+
}
|
|
762
|
+
isRunning() {
|
|
763
|
+
let e = this.nextRun(this._states.currentRun), t = !this._states.paused, r = this.fn !== void 0, n = !this._states.kill;
|
|
764
|
+
return t && r && n && e !== null;
|
|
765
|
+
}
|
|
766
|
+
isStopped() {
|
|
767
|
+
return this._states.kill;
|
|
768
|
+
}
|
|
769
|
+
isBusy() {
|
|
770
|
+
return this._states.blocking;
|
|
771
|
+
}
|
|
772
|
+
currentRun() {
|
|
773
|
+
return this._states.currentRun ? this._states.currentRun.getDate() : null;
|
|
774
|
+
}
|
|
775
|
+
previousRun() {
|
|
776
|
+
return this._states.previousRun ? this._states.previousRun.getDate() : null;
|
|
777
|
+
}
|
|
778
|
+
msToNext(e) {
|
|
779
|
+
let t = this._next(e);
|
|
780
|
+
return t ? e instanceof m || e instanceof Date ? t.getTime() - e.getTime() : t.getTime() - new m(e).getTime() : null;
|
|
781
|
+
}
|
|
782
|
+
stop() {
|
|
783
|
+
this._states.kill = !0, this._states.currentTimeout && clearTimeout(this._states.currentTimeout);
|
|
784
|
+
let e = w.indexOf(this);
|
|
785
|
+
e >= 0 && w.splice(e, 1);
|
|
786
|
+
}
|
|
787
|
+
pause() {
|
|
788
|
+
return this._states.paused = !0, !this._states.kill;
|
|
789
|
+
}
|
|
790
|
+
resume() {
|
|
791
|
+
return this._states.paused = !1, !this._states.kill;
|
|
792
|
+
}
|
|
793
|
+
schedule(e) {
|
|
794
|
+
if (e && this.fn) throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
|
|
795
|
+
e && (this.fn = e);
|
|
796
|
+
let t = this.msToNext(), r = this.nextRun(this._states.currentRun);
|
|
797
|
+
return t == null || isNaN(t) || r === null ? this : (t > W && (t = W), this._states.currentTimeout = setTimeout(() => this._checkTrigger(r), t), this._states.currentTimeout && this.options.unref && x(this._states.currentTimeout), this);
|
|
798
|
+
}
|
|
799
|
+
async _trigger(e) {
|
|
800
|
+
this._states.blocking = !0, this._states.currentRun = new m(void 0, this.getTz());
|
|
801
|
+
try {
|
|
802
|
+
if (this.options.catch) try {
|
|
803
|
+
this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
804
|
+
} catch (t) {
|
|
805
|
+
if (p(this.options.catch)) try {
|
|
806
|
+
this.options.catch(t, this);
|
|
807
|
+
} catch {}
|
|
808
|
+
}
|
|
809
|
+
else this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
810
|
+
} finally {
|
|
811
|
+
this._states.previousRun = new m(e, this.getTz()), this._states.blocking = !1;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
async trigger() {
|
|
815
|
+
await this._trigger();
|
|
816
|
+
}
|
|
817
|
+
runsLeft() {
|
|
818
|
+
return this._states.maxRuns;
|
|
819
|
+
}
|
|
820
|
+
_checkTrigger(e) {
|
|
821
|
+
let t = /* @__PURE__ */ new Date(), r = !this._states.paused && t.getTime() >= e.getTime(), n = this._states.blocking && this.options.protect;
|
|
822
|
+
r && !n ? (this._states.maxRuns !== void 0 && this._states.maxRuns--, this._trigger()) : r && n && p(this.options.protect) && setTimeout(() => this.options.protect(this), 0), this.schedule();
|
|
823
|
+
}
|
|
824
|
+
_next(e) {
|
|
825
|
+
let t = !!(e || this._states.currentRun), r = !1;
|
|
826
|
+
!e && this.options.startAt && this.options.interval && ([e, t] = this._calculatePreviousRun(e, t), r = !e), e = new m(e, this.getTz()), this.options.startAt && e && e.getTime() < this.options.startAt.getTime() && (e = this.options.startAt);
|
|
827
|
+
let n = this._states.once || new m(e, this.getTz());
|
|
828
|
+
return !r && n !== this._states.once && (n = n.increment(this._states.pattern, this.options, t)), this._states.once && this._states.once.getTime() <= e.getTime() || n === null || this._states.maxRuns !== void 0 && this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && n.getTime() >= this.options.stopAt.getTime() ? null : n;
|
|
829
|
+
}
|
|
830
|
+
_previous(e) {
|
|
831
|
+
let t = new m(e, this.getTz());
|
|
832
|
+
this.options.stopAt && t.getTime() > this.options.stopAt.getTime() && (t = this.options.stopAt);
|
|
833
|
+
let r = new m(t, this.getTz());
|
|
834
|
+
return this._states.once ? this._states.once.getTime() < t.getTime() ? this._states.once : null : (r = r.decrement(this._states.pattern, this.options), r === null || this.options.startAt && r.getTime() < this.options.startAt.getTime() ? null : r);
|
|
835
|
+
}
|
|
836
|
+
_calculatePreviousRun(e, t) {
|
|
837
|
+
let r = new m(void 0, this.getTz()), n = e;
|
|
838
|
+
if (this.options.startAt.getTime() <= r.getTime()) {
|
|
839
|
+
n = this.options.startAt;
|
|
840
|
+
let i = n.getTime() + this.options.interval * 1e3;
|
|
841
|
+
for (; i <= r.getTime();) n = new m(n, this.getTz()).increment(this._states.pattern, this.options, !0), i = n.getTime() + this.options.interval * 1e3;
|
|
842
|
+
t = !0;
|
|
843
|
+
}
|
|
844
|
+
return n === null && (n = void 0), [n, t];
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region src/builtins/backup-orchestrator/cron-helpers.ts
|
|
849
|
+
/**
|
|
850
|
+
* Cron helpers — wraps `croner` so the orchestrator + the `previewNextRuns`
|
|
851
|
+
* cap method share one validation + next-run-computation surface.
|
|
852
|
+
*
|
|
853
|
+
* `croner` is the opinionated node cron library we standardize on
|
|
854
|
+
* server-side: pure JS, native TypeScript types, supports the full
|
|
855
|
+
* 5-field POSIX cron grammar plus seconds (6-field), DST-aware, and
|
|
856
|
+
* exposes `nextRun()` / `nextRuns(N)` for peeking without scheduling.
|
|
857
|
+
* The orchestrator uses the peeking API (it has its own polling
|
|
858
|
+
* loop); future surfaces (e.g. event-driven retention sweeps) can
|
|
859
|
+
* register an actual scheduled `Cron(pattern, fn)` and let croner
|
|
860
|
+
* own the timer.
|
|
861
|
+
*/
|
|
862
|
+
/**
|
|
863
|
+
* Validate a cron expression and return its next firing time strictly
|
|
864
|
+
* after `after`, expressed as ms-epoch. Returns `null` when the
|
|
865
|
+
* expression has no future runs (croner returns null e.g. for
|
|
866
|
+
* fully-bounded patterns that have already elapsed). Throws when the
|
|
867
|
+
* expression is syntactically invalid — callers are expected to
|
|
868
|
+
* surface that to the operator.
|
|
869
|
+
*/
|
|
870
|
+
function computeNextDue(cron, after) {
|
|
871
|
+
const next = new E(cron, { paused: true }).nextRun(new Date(after));
|
|
872
|
+
return next ? next.getTime() : null;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Validate without computing — returns true when `cron` parses, false
|
|
876
|
+
* otherwise. Used by the cap-router input zod schema's `.refine`
|
|
877
|
+
* callback to reject malformed expressions at the boundary instead
|
|
878
|
+
* of at scheduler-tick time.
|
|
879
|
+
*/
|
|
880
|
+
function isValidCron(cron) {
|
|
881
|
+
try {
|
|
882
|
+
new E(cron, { paused: true });
|
|
883
|
+
return true;
|
|
884
|
+
} catch {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Peek the next N firing times after `after` (default: now). Used by
|
|
890
|
+
* the admin UI's CronEditor preview pane — operators see the next
|
|
891
|
+
* 3–5 runs as they edit the expression so a wrong pattern is
|
|
892
|
+
* obvious before save.
|
|
893
|
+
*/
|
|
894
|
+
function previewNextRuns(cron, count, after) {
|
|
895
|
+
const job = new E(cron, { paused: true });
|
|
896
|
+
const baseline = after !== void 0 ? new Date(after) : /* @__PURE__ */ new Date();
|
|
897
|
+
const out = [];
|
|
898
|
+
let cursor = baseline;
|
|
899
|
+
for (let i = 0; i < count; i++) {
|
|
900
|
+
cursor = job.nextRun(cursor);
|
|
901
|
+
if (!cursor) break;
|
|
902
|
+
out.push(cursor.getTime());
|
|
903
|
+
}
|
|
904
|
+
return out;
|
|
905
|
+
}
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/builtins/backup-orchestrator/destination-policy.ts
|
|
908
|
+
var import_read_all_rows = require_read_all_rows$1.require_read_all_rows();
|
|
909
|
+
var BackupDestinationPolicyService = class {
|
|
910
|
+
policiesKind;
|
|
911
|
+
constructor(policiesKind) {
|
|
912
|
+
this.policiesKind = policiesKind;
|
|
913
|
+
}
|
|
914
|
+
async list() {
|
|
915
|
+
const rows = await (0, import_read_all_rows.readAllRows)(this.policiesKind);
|
|
916
|
+
rows.sort((a, b) => a.id.localeCompare(b.id));
|
|
917
|
+
const out = [];
|
|
918
|
+
for (const row of rows) {
|
|
919
|
+
const mapped = bodyToPolicy(row.id, row.data);
|
|
920
|
+
if (mapped) out.push(mapped);
|
|
921
|
+
}
|
|
922
|
+
return out;
|
|
923
|
+
}
|
|
924
|
+
async get(locationId) {
|
|
925
|
+
const row = await this.policiesKind.get(locationId);
|
|
926
|
+
return row === null ? null : bodyToPolicy(locationId, row.data);
|
|
927
|
+
}
|
|
928
|
+
/** Replace-or-insert: one full `put` of the row. */
|
|
929
|
+
async upsert(p) {
|
|
930
|
+
const data = require_restore_archive.backupOrchestratorRecordKinds["destination-policies"].schema.parse(policyToBody(p));
|
|
931
|
+
await this.policiesKind.put({
|
|
932
|
+
id: p.locationId,
|
|
933
|
+
data
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
async delete(locationId) {
|
|
937
|
+
await this.policiesKind.delete(locationId);
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Auto-create a default policy for a `backups` location seen for the
|
|
941
|
+
* first time (returns the existing policy unchanged when present).
|
|
942
|
+
* The orchestrator calls this lazily on the first `listDestinations`
|
|
943
|
+
* pass so newly-added storage locations are surfaced as enabled
|
|
944
|
+
* destinations without an explicit configuration step.
|
|
945
|
+
*
|
|
946
|
+
* Defaults are passed by the orchestrator (currently `retentionCount=7`).
|
|
947
|
+
* A fresh destination is enabled and keeps 7 archives; it gets NO cadence
|
|
948
|
+
* of its own — a destination runs when a schedule fans out to it, and
|
|
949
|
+
* seeding a cron here would advertise a nightly run nothing performs
|
|
950
|
+
* (D384).
|
|
951
|
+
*/
|
|
952
|
+
async ensureDefault(locationId, defaults) {
|
|
953
|
+
const existing = await this.get(locationId);
|
|
954
|
+
if (existing) return existing;
|
|
955
|
+
const fresh = {
|
|
956
|
+
locationId,
|
|
957
|
+
enabled: true,
|
|
958
|
+
retentionCount: defaults.retentionCount
|
|
959
|
+
};
|
|
960
|
+
await this.upsert(fresh);
|
|
961
|
+
return fresh;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Stamp the outcome of ONE attempted write to this destination.
|
|
965
|
+
*
|
|
966
|
+
* Read-modify-write on the policy row so the operator's `enabled`,
|
|
967
|
+
* `retentionCount` and `label` survive. A destination with no row yet
|
|
968
|
+
* gets one — an attempt on an unseen location must still be recorded, or
|
|
969
|
+
* the failure disappears with the process (which is exactly how a 03:00
|
|
970
|
+
* SMB refusal stayed invisible until the operator went looking).
|
|
971
|
+
*/
|
|
972
|
+
async recordAttempt(locationId, outcome, defaults) {
|
|
973
|
+
const { lastError: _cleared, ...carried } = await this.get(locationId) ?? {
|
|
974
|
+
locationId,
|
|
975
|
+
enabled: true,
|
|
976
|
+
retentionCount: defaults.retentionCount
|
|
977
|
+
};
|
|
978
|
+
await this.upsert({
|
|
979
|
+
...carried,
|
|
980
|
+
lastAttemptAt: outcome.attemptAt,
|
|
981
|
+
...outcome.error !== void 0 ? { lastError: outcome.error } : {}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
function policyToBody(p) {
|
|
986
|
+
return {
|
|
987
|
+
enabled: p.enabled,
|
|
988
|
+
retentionCount: p.retentionCount,
|
|
989
|
+
...p.label !== void 0 ? { label: p.label } : {},
|
|
990
|
+
...p.lastAttemptAt !== void 0 ? { lastAttemptAt: p.lastAttemptAt } : {},
|
|
991
|
+
...p.lastError !== void 0 ? { lastError: p.lastError } : {}
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function bodyToPolicy(locationId, body) {
|
|
995
|
+
if (!locationId) return null;
|
|
996
|
+
return {
|
|
997
|
+
locationId,
|
|
998
|
+
enabled: body.enabled,
|
|
999
|
+
retentionCount: body.retentionCount,
|
|
1000
|
+
...body.label !== void 0 ? { label: body.label } : {},
|
|
1001
|
+
...body.lastAttemptAt !== void 0 ? { lastAttemptAt: body.lastAttemptAt } : {},
|
|
1002
|
+
...body.lastError !== void 0 ? { lastError: body.lastError } : {}
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
//#endregion
|
|
1006
|
+
//#region src/builtins/backup-orchestrator/download-helpers.ts
|
|
1007
|
+
/**
|
|
1008
|
+
* Chunked-download helper for the backup orchestrator (Task 12 of
|
|
1009
|
+
* the storage-unification refactor).
|
|
1010
|
+
*
|
|
1011
|
+
* Streams an archive from a destination `StorageLocation` into a
|
|
1012
|
+
* local filesystem path via the consumer-facing `storage` cap. Pulled
|
|
1013
|
+
* out of `backup-orchestrator.addon.ts` so it can be unit-tested with
|
|
1014
|
+
* an in-memory fake `AddonApi['storage']` slice — the addon is hard
|
|
1015
|
+
* to bootstrap in vitest because of the BaseAddon ceremony.
|
|
1016
|
+
*
|
|
1017
|
+
* Cleanup contract:
|
|
1018
|
+
* - Successful run leaves the cache file in place + calls
|
|
1019
|
+
* `endDownload`.
|
|
1020
|
+
* - Mid-stream failure destroys the writeStream, removes the
|
|
1021
|
+
* partial cache file, and best-effort calls `endDownload` so the
|
|
1022
|
+
* storage provider's session bookkeeping doesn't leak.
|
|
1023
|
+
*/
|
|
1024
|
+
async function downloadArchiveToCache(input) {
|
|
1025
|
+
const { downloadId, sizeBytes } = await input.api.beginDownload.mutate({
|
|
1026
|
+
location: input.locationId,
|
|
1027
|
+
relativePath: input.filename
|
|
1028
|
+
});
|
|
1029
|
+
const writeStream = node_fs.createWriteStream(input.cachePath);
|
|
1030
|
+
let offset = 0;
|
|
1031
|
+
try {
|
|
1032
|
+
while (offset < sizeBytes) {
|
|
1033
|
+
const remaining = sizeBytes - offset;
|
|
1034
|
+
const length = Math.min(input.chunkBytes, remaining);
|
|
1035
|
+
const chunk = await input.api.readChunk.query({
|
|
1036
|
+
downloadId,
|
|
1037
|
+
offset,
|
|
1038
|
+
length
|
|
1039
|
+
});
|
|
1040
|
+
if (chunk.byteLength === 0) throw new Error(`backup restore: empty chunk at offset ${offset}/${sizeBytes} from "${input.locationId}/${input.filename}"`);
|
|
1041
|
+
writeStream.write(chunk);
|
|
1042
|
+
offset += chunk.byteLength;
|
|
1043
|
+
}
|
|
1044
|
+
await new Promise((resolve, reject) => {
|
|
1045
|
+
writeStream.end((err) => {
|
|
1046
|
+
if (err) reject(err);
|
|
1047
|
+
else resolve();
|
|
1048
|
+
});
|
|
1049
|
+
});
|
|
1050
|
+
try {
|
|
1051
|
+
await input.api.endDownload.mutate({ downloadId });
|
|
1052
|
+
} catch (err) {
|
|
1053
|
+
input.logger.warn("backup restore: endDownload failed (ignoring)", { meta: {
|
|
1054
|
+
downloadId,
|
|
1055
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1056
|
+
} });
|
|
1057
|
+
}
|
|
1058
|
+
} catch (err) {
|
|
1059
|
+
await new Promise((resolve) => {
|
|
1060
|
+
writeStream.once("close", () => resolve());
|
|
1061
|
+
writeStream.destroy();
|
|
1062
|
+
});
|
|
1063
|
+
try {
|
|
1064
|
+
await node_fs_promises.rm(input.cachePath, { force: true });
|
|
1065
|
+
} catch {}
|
|
1066
|
+
try {
|
|
1067
|
+
await input.api.endDownload.mutate({ downloadId });
|
|
1068
|
+
} catch {}
|
|
1069
|
+
throw err;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
//#endregion
|
|
1073
|
+
//#region src/builtins/backup-orchestrator/encryption-key-store.ts
|
|
1074
|
+
/**
|
|
1075
|
+
* @durable class=config owner=backup-orchestrator
|
|
1076
|
+
* write="`setupEncryption` inserts one row per generated key and retires the
|
|
1077
|
+
* previous active row; `disableEncryption` retires the active row"
|
|
1078
|
+
* retention="none — one small row per key ever generated; a retired row
|
|
1079
|
+
* names the key older archives need"
|
|
1080
|
+
*/
|
|
1081
|
+
var BACKUP_ENCRYPTION_KEYS_COLLECTION = "backup_encryption_keys";
|
|
1082
|
+
var COLUMNS = [
|
|
1083
|
+
{
|
|
1084
|
+
name: "key_id",
|
|
1085
|
+
type: "TEXT",
|
|
1086
|
+
primaryKey: true
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
name: "public_key",
|
|
1090
|
+
type: "TEXT",
|
|
1091
|
+
notNull: true
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
name: "created_at",
|
|
1095
|
+
type: "INTEGER",
|
|
1096
|
+
notNull: true
|
|
1097
|
+
},
|
|
1098
|
+
{
|
|
1099
|
+
name: "retired_at",
|
|
1100
|
+
type: "INTEGER"
|
|
1101
|
+
}
|
|
1102
|
+
];
|
|
1103
|
+
var BackupEncryptionKeyStore = class {
|
|
1104
|
+
store;
|
|
1105
|
+
now;
|
|
1106
|
+
declared = false;
|
|
1107
|
+
keysKind;
|
|
1108
|
+
constructor(store, now = Date.now, keysKind = null) {
|
|
1109
|
+
this.store = store;
|
|
1110
|
+
this.now = now;
|
|
1111
|
+
this.keysKind = keysKind;
|
|
1112
|
+
}
|
|
1113
|
+
async ensureDeclared() {
|
|
1114
|
+
if (this.keysKind !== null) return;
|
|
1115
|
+
if (this.declared) return;
|
|
1116
|
+
await this.store.declareCollection({
|
|
1117
|
+
collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
|
|
1118
|
+
columns: COLUMNS
|
|
1119
|
+
});
|
|
1120
|
+
this.declared = true;
|
|
1121
|
+
}
|
|
1122
|
+
/** Every key, newest first. */
|
|
1123
|
+
async list() {
|
|
1124
|
+
await this.ensureDeclared();
|
|
1125
|
+
const kind = this.keysKind;
|
|
1126
|
+
if (kind !== null) {
|
|
1127
|
+
const rows = await (0, import_read_all_rows.readAllRows)(kind);
|
|
1128
|
+
rows.sort((a, b) => b.data.createdAt - a.data.createdAt);
|
|
1129
|
+
const out = [];
|
|
1130
|
+
for (const row of rows) {
|
|
1131
|
+
const record = bodyToRecord(row.id, row.data);
|
|
1132
|
+
if (record !== null) out.push(record);
|
|
1133
|
+
}
|
|
1134
|
+
return out;
|
|
1135
|
+
}
|
|
1136
|
+
const rows = await this.store.query({
|
|
1137
|
+
collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
|
|
1138
|
+
filter: { orderBy: {
|
|
1139
|
+
field: "created_at",
|
|
1140
|
+
direction: "desc"
|
|
1141
|
+
} }
|
|
1142
|
+
});
|
|
1143
|
+
const out = [];
|
|
1144
|
+
for (const row of rows) {
|
|
1145
|
+
const record = toRecord(row.data);
|
|
1146
|
+
if (record !== null) out.push(record);
|
|
1147
|
+
}
|
|
1148
|
+
return out;
|
|
1149
|
+
}
|
|
1150
|
+
/** The key new archives are encrypted to; `null` = encryption off. */
|
|
1151
|
+
async active() {
|
|
1152
|
+
return (await this.list()).find((k) => k.retiredAt === null) ?? null;
|
|
1153
|
+
}
|
|
1154
|
+
/** Make `publicKey` the active key; the previous one is retired, kept listed. */
|
|
1155
|
+
async activate(input) {
|
|
1156
|
+
const parsed = require_restore_archive.parseBackupPublicKey(input.publicKey);
|
|
1157
|
+
const t = this.now();
|
|
1158
|
+
await this.retireActive(t);
|
|
1159
|
+
const record = {
|
|
1160
|
+
keyId: parsed.keyId,
|
|
1161
|
+
publicKey: input.publicKey.trim(),
|
|
1162
|
+
createdAt: t,
|
|
1163
|
+
retiredAt: null
|
|
1164
|
+
};
|
|
1165
|
+
await this.write(record);
|
|
1166
|
+
return record;
|
|
1167
|
+
}
|
|
1168
|
+
/** Encryption off: the active key is retired. Archives already made keep needing it. */
|
|
1169
|
+
async disable() {
|
|
1170
|
+
await this.retireActive(this.now());
|
|
1171
|
+
}
|
|
1172
|
+
async retireActive(at) {
|
|
1173
|
+
for (const key of await this.list()) if (key.retiredAt === null) await this.write({
|
|
1174
|
+
...key,
|
|
1175
|
+
retiredAt: at
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
async write(record) {
|
|
1179
|
+
await this.ensureDeclared();
|
|
1180
|
+
const kind = this.keysKind;
|
|
1181
|
+
if (kind !== null) {
|
|
1182
|
+
const body = {
|
|
1183
|
+
keyId: record.keyId,
|
|
1184
|
+
publicKey: record.publicKey,
|
|
1185
|
+
createdAt: record.createdAt,
|
|
1186
|
+
retiredAt: record.retiredAt
|
|
1187
|
+
};
|
|
1188
|
+
const data = require_restore_archive.backupOrchestratorRecordKinds["encryption-keys"].schema.parse(body);
|
|
1189
|
+
await kind.put({
|
|
1190
|
+
id: record.keyId,
|
|
1191
|
+
data
|
|
1192
|
+
});
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
await this.store.deleteWhere({
|
|
1196
|
+
collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
|
|
1197
|
+
filter: { where: { key_id: record.keyId } }
|
|
1198
|
+
});
|
|
1199
|
+
await this.store.insert({
|
|
1200
|
+
collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
|
|
1201
|
+
record: {
|
|
1202
|
+
id: record.keyId,
|
|
1203
|
+
data: {
|
|
1204
|
+
key_id: record.keyId,
|
|
1205
|
+
public_key: record.publicKey,
|
|
1206
|
+
created_at: record.createdAt,
|
|
1207
|
+
retired_at: record.retiredAt
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
function bodyToRecord(keyId, body) {
|
|
1214
|
+
if (!keyId) return null;
|
|
1215
|
+
return {
|
|
1216
|
+
keyId: body.keyId,
|
|
1217
|
+
publicKey: body.publicKey,
|
|
1218
|
+
createdAt: body.createdAt,
|
|
1219
|
+
retiredAt: body.retiredAt
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
function toRecord(row) {
|
|
1223
|
+
const keyId = row["key_id"];
|
|
1224
|
+
const publicKey = row["public_key"];
|
|
1225
|
+
const createdAt = row["created_at"];
|
|
1226
|
+
if (typeof keyId !== "string" || typeof publicKey !== "string") return null;
|
|
1227
|
+
const retired = row["retired_at"];
|
|
1228
|
+
return {
|
|
1229
|
+
keyId,
|
|
1230
|
+
publicKey,
|
|
1231
|
+
createdAt: typeof createdAt === "number" ? createdAt : Number(createdAt ?? 0),
|
|
1232
|
+
retiredAt: typeof retired === "number" ? retired : null
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
//#endregion
|
|
1236
|
+
//#region src/builtins/backup-orchestrator/manifest-store.ts
|
|
1237
|
+
/** File path (relative to the location root) where the index lives. */
|
|
1238
|
+
var MANIFESTS_FILENAME = "manifests.json";
|
|
1239
|
+
/**
|
|
1240
|
+
* Read the per-location manifest. Returns an empty manifest on first
|
|
1241
|
+
* use (when `manifests.json` doesn't exist) or when the file is
|
|
1242
|
+
* unreadable / corrupt — operators see destination state degrade
|
|
1243
|
+
* gracefully rather than the orchestrator crashing.
|
|
1244
|
+
*/
|
|
1245
|
+
async function readLocationManifest(api, locationId) {
|
|
1246
|
+
if (!await api.exists.query({
|
|
1247
|
+
location: locationId,
|
|
1248
|
+
relativePath: "manifests.json"
|
|
1249
|
+
}).catch(() => false)) return EMPTY_MANIFEST;
|
|
1250
|
+
let bytes;
|
|
1251
|
+
try {
|
|
1252
|
+
bytes = await api.read.query({
|
|
1253
|
+
location: locationId,
|
|
1254
|
+
relativePath: MANIFESTS_FILENAME
|
|
1255
|
+
});
|
|
1256
|
+
} catch {
|
|
1257
|
+
return EMPTY_MANIFEST;
|
|
1258
|
+
}
|
|
1259
|
+
return parseManifestBytes(bytes);
|
|
1260
|
+
}
|
|
1261
|
+
async function writeLocationManifest(api, locationId, manifest) {
|
|
1262
|
+
const json = JSON.stringify(manifest, null, 2);
|
|
1263
|
+
const bytes = new TextEncoder().encode(json);
|
|
1264
|
+
await api.write.mutate({
|
|
1265
|
+
location: locationId,
|
|
1266
|
+
relativePath: MANIFESTS_FILENAME,
|
|
1267
|
+
data: bytes
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Decode the raw bytes of `manifests.json`. Falls back to an empty
|
|
1272
|
+
* manifest on JSON-parse / shape-validation failure — same defensive
|
|
1273
|
+
* stance as the legacy `LocalBackupService.ensureManifestsLoaded`.
|
|
1274
|
+
*/
|
|
1275
|
+
function parseManifestBytes(bytes) {
|
|
1276
|
+
try {
|
|
1277
|
+
const text = new TextDecoder().decode(bytes);
|
|
1278
|
+
if (text.trim().length === 0) return EMPTY_MANIFEST;
|
|
1279
|
+
return normalizeManifest(JSON.parse(text));
|
|
1280
|
+
} catch {
|
|
1281
|
+
return EMPTY_MANIFEST;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Coerce an arbitrary parsed JSON shape into the canonical manifest
|
|
1286
|
+
* type. Bogus archive entries are silently dropped (a corrupt row
|
|
1287
|
+
* shouldn't lock the whole location out of operator visibility).
|
|
1288
|
+
*/
|
|
1289
|
+
function normalizeManifest(raw) {
|
|
1290
|
+
if (typeof raw !== "object" || raw == null) return EMPTY_MANIFEST;
|
|
1291
|
+
const obj = raw;
|
|
1292
|
+
const archives = [];
|
|
1293
|
+
if (Array.isArray(obj.archives)) for (const a of obj.archives) {
|
|
1294
|
+
if (typeof a !== "object" || a == null) continue;
|
|
1295
|
+
const cand = a;
|
|
1296
|
+
if (typeof cand["id"] !== "string" || typeof cand["filename"] !== "string") continue;
|
|
1297
|
+
if (typeof cand["createdAt"] !== "number" || typeof cand["sizeBytes"] !== "number") continue;
|
|
1298
|
+
const manifest = cand["manifest"];
|
|
1299
|
+
if (typeof manifest !== "object" || manifest == null) continue;
|
|
1300
|
+
const entry = {
|
|
1301
|
+
id: String(cand["id"]),
|
|
1302
|
+
filename: String(cand["filename"]),
|
|
1303
|
+
createdAt: Number(cand["createdAt"]),
|
|
1304
|
+
sizeBytes: Number(cand["sizeBytes"]),
|
|
1305
|
+
...typeof cand["label"] === "string" ? { label: cand["label"] } : {},
|
|
1306
|
+
manifest,
|
|
1307
|
+
...encryptionOf(cand["encryption"]),
|
|
1308
|
+
...databasesOf(cand["databases"])
|
|
1309
|
+
};
|
|
1310
|
+
archives.push(entry);
|
|
1311
|
+
}
|
|
1312
|
+
return {
|
|
1313
|
+
version: 1,
|
|
1314
|
+
archives
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
var EMPTY_MANIFEST = {
|
|
1318
|
+
version: 1,
|
|
1319
|
+
archives: []
|
|
1320
|
+
};
|
|
1321
|
+
function databasesOf(raw) {
|
|
1322
|
+
if (!Array.isArray(raw)) return {};
|
|
1323
|
+
const known = [];
|
|
1324
|
+
const unknown = [];
|
|
1325
|
+
for (const item of raw) if (item === "settings" || item === "events" || item === "history") known.push(item);
|
|
1326
|
+
else if (typeof item === "string") unknown.push(item);
|
|
1327
|
+
if (known.length > 0) return { databases: known };
|
|
1328
|
+
return unknown.length > 0 ? { unrecognisedDatabases: unknown } : {};
|
|
1329
|
+
}
|
|
1330
|
+
function encryptionOf(raw) {
|
|
1331
|
+
if (typeof raw !== "object" || raw === null) return {};
|
|
1332
|
+
const scheme = Reflect.get(raw, "scheme");
|
|
1333
|
+
const keyId = Reflect.get(raw, "keyId");
|
|
1334
|
+
if (typeof scheme !== "string" || typeof keyId !== "string") return {};
|
|
1335
|
+
return { encryption: {
|
|
1336
|
+
scheme,
|
|
1337
|
+
keyId
|
|
1338
|
+
} };
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* What the destination's clear-text index may say about an encrypted archive:
|
|
1342
|
+
* the outline a restore needs (locations, sizes, the snapshot promise) — not
|
|
1343
|
+
* the list of files, which stays inside the ciphertext.
|
|
1344
|
+
*/
|
|
1345
|
+
function outlineOfManifest(manifest) {
|
|
1346
|
+
return {
|
|
1347
|
+
archiveVersion: manifest.archiveVersion,
|
|
1348
|
+
createdAt: manifest.createdAt,
|
|
1349
|
+
dataDir: manifest.dataDir,
|
|
1350
|
+
locations: [...manifest.locations],
|
|
1351
|
+
entries: [],
|
|
1352
|
+
totalBytes: manifest.totalBytes,
|
|
1353
|
+
totalFiles: manifest.totalFiles,
|
|
1354
|
+
...manifest.omittedDatabases !== void 0 ? { omittedDatabases: [...manifest.omittedDatabases] } : {}
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Build a `ManifestArchiveEntry` from the raw inputs collected during
|
|
1359
|
+
* a successful upload. Pure transform — no I/O — kept here so the
|
|
1360
|
+
* triggerBackup path stays terse.
|
|
1361
|
+
*/
|
|
1362
|
+
function buildArchiveEntry(input) {
|
|
1363
|
+
return {
|
|
1364
|
+
id: input.id,
|
|
1365
|
+
filename: input.filename,
|
|
1366
|
+
createdAt: input.createdAt,
|
|
1367
|
+
sizeBytes: input.sizeBytes,
|
|
1368
|
+
...input.label !== void 0 ? { label: input.label } : {},
|
|
1369
|
+
manifest: input.encryption !== void 0 ? outlineOfManifest(input.manifest) : input.manifest,
|
|
1370
|
+
...input.encryption !== void 0 ? { encryption: input.encryption } : {},
|
|
1371
|
+
...input.databases !== void 0 ? { databases: [...input.databases] } : {}
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
/** The key under which archives of one cadence prune each other. */
|
|
1375
|
+
function retentionClassOf(entry) {
|
|
1376
|
+
if (entry.databases === void 0 && entry.unrecognisedDatabases !== void 0) return `?${[...entry.unrecognisedDatabases].toSorted().join("+")}`;
|
|
1377
|
+
return [...entry.databases ?? require_restore_archive.DEFAULT_BACKUP_DATABASES].toSorted().join("+");
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Pure retention split: given an archive list and the operator's
|
|
1381
|
+
* `retentionCount`, return `{ keep, drop }` where `keep` is the most-
|
|
1382
|
+
* recent N archives (newest first) and `drop` is the older overflow.
|
|
1383
|
+
*
|
|
1384
|
+
* `retentionCount <= 0` is treated as "no pruning" — defensive against
|
|
1385
|
+
* a config value that would otherwise wipe every archive on the next
|
|
1386
|
+
* write.
|
|
1387
|
+
*
|
|
1388
|
+
* `cadence` (see {@link retentionClassOf}) restricts the count to archives of
|
|
1389
|
+
* the run that was just written: nightly archives (settings) and weekly ones
|
|
1390
|
+
* (settings + events + history) are retained separately.
|
|
1391
|
+
*/
|
|
1392
|
+
function applyRetention(archives, retentionCount, cadence) {
|
|
1393
|
+
if (retentionCount <= 0) return {
|
|
1394
|
+
keep: archives,
|
|
1395
|
+
drop: []
|
|
1396
|
+
};
|
|
1397
|
+
const sorted = [...archives].toSorted((a, b) => b.createdAt - a.createdAt);
|
|
1398
|
+
const inCadence = cadence === void 0 ? sorted : sorted.filter((a) => retentionClassOf(a) === cadence);
|
|
1399
|
+
if (inCadence.length <= retentionCount) return {
|
|
1400
|
+
keep: sorted,
|
|
1401
|
+
drop: []
|
|
1402
|
+
};
|
|
1403
|
+
const drop = inCadence.slice(retentionCount);
|
|
1404
|
+
const dropped = new Set(drop);
|
|
1405
|
+
return {
|
|
1406
|
+
keep: sorted.filter((a) => !dropped.has(a)),
|
|
1407
|
+
drop
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Per-location async mutex. The orchestrator owns one instance and
|
|
1412
|
+
* funnels every read-modify-write of `manifests.json` through it so
|
|
1413
|
+
* parallel destination uploads (within the same location) commit in
|
|
1414
|
+
* arrival order. Across locations the operations run in parallel —
|
|
1415
|
+
* each location keys its own promise chain.
|
|
1416
|
+
*/
|
|
1417
|
+
var LocationManifestLock = class {
|
|
1418
|
+
chains = /* @__PURE__ */ new Map();
|
|
1419
|
+
async run(locationId, fn) {
|
|
1420
|
+
const previous = this.chains.get(locationId) ?? Promise.resolve();
|
|
1421
|
+
let resolveNext;
|
|
1422
|
+
const next = new Promise((res) => {
|
|
1423
|
+
resolveNext = res;
|
|
1424
|
+
});
|
|
1425
|
+
this.chains.set(locationId, previous.then(() => next));
|
|
1426
|
+
try {
|
|
1427
|
+
await previous;
|
|
1428
|
+
return await fn();
|
|
1429
|
+
} finally {
|
|
1430
|
+
resolveNext();
|
|
1431
|
+
const tail = this.chains.get(locationId);
|
|
1432
|
+
if (tail) Promise.resolve(tail).then(() => {
|
|
1433
|
+
if (this.chains.get(locationId) === tail) this.chains.delete(locationId);
|
|
1434
|
+
}).catch(() => {});
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
//#endregion
|
|
1439
|
+
//#region src/builtins/backup-orchestrator/run-queue.ts
|
|
1440
|
+
/**
|
|
1441
|
+
* Backup run queue + per-run tracking (D342).
|
|
1442
|
+
*
|
|
1443
|
+
* Why a GLOBAL queue (concurrency 1), not per-destination: every run
|
|
1444
|
+
* walks the same `<nodeDataDir>` source tree and stages its tar.gz on
|
|
1445
|
+
* the same disk. On 2026-09-04 two schedule ticks built two multi-GB
|
|
1446
|
+
* archives concurrently — staging went 5.1 GB → 18 GB in ~12 minutes
|
|
1447
|
+
* with host load 62, and each run archived the other's growing tar
|
|
1448
|
+
* (pre-D338 staging placement). A per-destination lock would still
|
|
1449
|
+
* allow two concurrent walks of the same tree and two staged archives;
|
|
1450
|
+
* the destination write is the CHEAP half. One run at a time bounds
|
|
1451
|
+
* peak staging disk to a single archive and the walk cost to one
|
|
1452
|
+
* traversal.
|
|
1453
|
+
*
|
|
1454
|
+
* This subsumes the earlier single-flight `buildLock`
|
|
1455
|
+
* (`LocationManifestLock.run('archive-build', …)`): that lock
|
|
1456
|
+
* serialised builds but was invisible (nothing reported a waiting
|
|
1457
|
+
* run), unjoinable and uncancellable. The queue is the one
|
|
1458
|
+
* serialisation authority for archive builds — do not reintroduce a
|
|
1459
|
+
* second lock around the executor.
|
|
1460
|
+
*
|
|
1461
|
+
* Every run is OBSERVABLE while it exists: id, state, phase, byte
|
|
1462
|
+
* counters, per-destination outcome. The registry keeps queued +
|
|
1463
|
+
* active + a bounded tail of finished runs so `backup.listRuns` can
|
|
1464
|
+
* answer "what is running, how far along, how big" without `du`.
|
|
1465
|
+
*/
|
|
1466
|
+
/** Finished runs kept for `listRuns` history. Older ones are dropped. */
|
|
1467
|
+
var DEFAULT_MAX_FINISHED = 20;
|
|
1468
|
+
/**
|
|
1469
|
+
* FIFO queue with concurrency 1. `submit` never starts a second
|
|
1470
|
+
* executor while one is in flight; an identical request already
|
|
1471
|
+
* WAITING (same destinations/locations/label/retention) is joined
|
|
1472
|
+
* instead of queued twice — two schedule ticks due on the same minute
|
|
1473
|
+
* produce one run, not two.
|
|
1474
|
+
*/
|
|
1475
|
+
var BackupRunQueue = class {
|
|
1476
|
+
executor;
|
|
1477
|
+
runs = /* @__PURE__ */ new Map();
|
|
1478
|
+
pending = [];
|
|
1479
|
+
finished = [];
|
|
1480
|
+
activeId = null;
|
|
1481
|
+
maxFinished;
|
|
1482
|
+
now;
|
|
1483
|
+
constructor(executor, opts) {
|
|
1484
|
+
this.executor = executor;
|
|
1485
|
+
this.maxFinished = opts?.maxFinished ?? DEFAULT_MAX_FINISHED;
|
|
1486
|
+
this.now = opts?.now ?? Date.now;
|
|
1487
|
+
}
|
|
1488
|
+
submit(request) {
|
|
1489
|
+
const signature = requestSignature(request);
|
|
1490
|
+
const busy = this.activeId !== null || this.pending.length > 0;
|
|
1491
|
+
for (const id of this.pending) {
|
|
1492
|
+
const existing = this.runs.get(id);
|
|
1493
|
+
if (existing && existing.signature === signature) return {
|
|
1494
|
+
runId: id,
|
|
1495
|
+
queued: true,
|
|
1496
|
+
joined: true,
|
|
1497
|
+
result: existing.resultPromise
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
const record = this.createRecord(request, signature);
|
|
1501
|
+
this.runs.set(record.snapshot.id, record);
|
|
1502
|
+
this.pending.push(record.snapshot.id);
|
|
1503
|
+
this.pump();
|
|
1504
|
+
return {
|
|
1505
|
+
runId: record.snapshot.id,
|
|
1506
|
+
queued: busy,
|
|
1507
|
+
joined: false,
|
|
1508
|
+
result: record.resultPromise
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Cancel a run. Queued: removed before it ever starts (its result
|
|
1513
|
+
* rejects `BackupCancelledError`). Running: the abort signal fires —
|
|
1514
|
+
* the executor's tar/upload streams stop and its cleanup runs.
|
|
1515
|
+
* Unknown or already terminal: `false`.
|
|
1516
|
+
*/
|
|
1517
|
+
cancel(runId) {
|
|
1518
|
+
const record = this.runs.get(runId);
|
|
1519
|
+
if (!record) return false;
|
|
1520
|
+
if (record.snapshot.state === "queued") {
|
|
1521
|
+
const idx = this.pending.indexOf(runId);
|
|
1522
|
+
if (idx >= 0) this.pending.splice(idx, 1);
|
|
1523
|
+
this.finish(record, "cancelled");
|
|
1524
|
+
record.rejectResult(new require_restore_archive.BackupCancelledError(`backup run ${runId} cancelled while queued`));
|
|
1525
|
+
return true;
|
|
1526
|
+
}
|
|
1527
|
+
if (record.snapshot.state === "running") {
|
|
1528
|
+
record.controller.abort();
|
|
1529
|
+
return true;
|
|
1530
|
+
}
|
|
1531
|
+
return false;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* EXECUTION order, not timestamp order: the running run first, then
|
|
1535
|
+
* every queued run in the exact order the pump will start them (each
|
|
1536
|
+
* stamped with `queuePosition`, 1 = next), then the bounded finished
|
|
1537
|
+
* history newest-first. The queued section is read straight off
|
|
1538
|
+
* `this.pending` — a consumer sorting by `requestedAt` descending
|
|
1539
|
+
* would put the run that starts NEXT at the BOTTOM, which is
|
|
1540
|
+
* backwards exactly when the queue matters (more than one waiter).
|
|
1541
|
+
*/
|
|
1542
|
+
listRuns() {
|
|
1543
|
+
const running = [];
|
|
1544
|
+
const finished = [];
|
|
1545
|
+
for (const record of this.runs.values()) {
|
|
1546
|
+
const snap = record.snapshot;
|
|
1547
|
+
if (snap.state === "running") running.push(snap);
|
|
1548
|
+
else if (snap.state !== "queued") finished.push(snap);
|
|
1549
|
+
}
|
|
1550
|
+
const queued = [];
|
|
1551
|
+
for (const [index, id] of this.pending.entries()) {
|
|
1552
|
+
const record = this.runs.get(id);
|
|
1553
|
+
if (record) queued.push({
|
|
1554
|
+
...record.snapshot,
|
|
1555
|
+
queuePosition: index + 1
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
finished.sort((a, b) => b.requestedAt - a.requestedAt);
|
|
1559
|
+
return [
|
|
1560
|
+
...running,
|
|
1561
|
+
...queued,
|
|
1562
|
+
...finished
|
|
1563
|
+
];
|
|
1564
|
+
}
|
|
1565
|
+
getRun(runId) {
|
|
1566
|
+
const record = this.runs.get(runId);
|
|
1567
|
+
if (!record) return void 0;
|
|
1568
|
+
const pendingIndex = this.pending.indexOf(runId);
|
|
1569
|
+
return pendingIndex >= 0 ? {
|
|
1570
|
+
...record.snapshot,
|
|
1571
|
+
queuePosition: pendingIndex + 1
|
|
1572
|
+
} : record.snapshot;
|
|
1573
|
+
}
|
|
1574
|
+
createRecord(request, signature) {
|
|
1575
|
+
let resolveResult;
|
|
1576
|
+
let rejectResult;
|
|
1577
|
+
const resultPromise = new Promise((res, rej) => {
|
|
1578
|
+
resolveResult = res;
|
|
1579
|
+
rejectResult = rej;
|
|
1580
|
+
});
|
|
1581
|
+
resultPromise.catch(() => void 0);
|
|
1582
|
+
return {
|
|
1583
|
+
snapshot: {
|
|
1584
|
+
id: (0, node_crypto.randomUUID)(),
|
|
1585
|
+
state: "queued",
|
|
1586
|
+
phase: "queued",
|
|
1587
|
+
destinationIds: request.destinations ?? [],
|
|
1588
|
+
...request.label !== void 0 ? { label: request.label } : {},
|
|
1589
|
+
requestedAt: this.now(),
|
|
1590
|
+
stagedBytes: 0,
|
|
1591
|
+
uploadedBytes: 0,
|
|
1592
|
+
completedDestinationIds: [],
|
|
1593
|
+
failedDestinationIds: []
|
|
1594
|
+
},
|
|
1595
|
+
request,
|
|
1596
|
+
signature,
|
|
1597
|
+
controller: new AbortController(),
|
|
1598
|
+
resultPromise,
|
|
1599
|
+
resolveResult,
|
|
1600
|
+
rejectResult
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
pump() {
|
|
1604
|
+
if (this.activeId !== null) return;
|
|
1605
|
+
const nextId = this.pending.shift();
|
|
1606
|
+
if (nextId === void 0) return;
|
|
1607
|
+
const record = this.runs.get(nextId);
|
|
1608
|
+
if (!record) {
|
|
1609
|
+
this.pump();
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
this.activeId = nextId;
|
|
1613
|
+
this.patch(record, {
|
|
1614
|
+
state: "running",
|
|
1615
|
+
phase: "building",
|
|
1616
|
+
startedAt: this.now()
|
|
1617
|
+
});
|
|
1618
|
+
this.execute(record);
|
|
1619
|
+
}
|
|
1620
|
+
async execute(record) {
|
|
1621
|
+
const progress = this.progressFor(record);
|
|
1622
|
+
try {
|
|
1623
|
+
const value = await this.executor(record.request, record.controller.signal, progress);
|
|
1624
|
+
if (record.controller.signal.aborted) this.finish(record, "cancelled");
|
|
1625
|
+
else {
|
|
1626
|
+
const { destinationIds, completedDestinationIds, failedDestinationIds } = record.snapshot;
|
|
1627
|
+
if (destinationIds.length > 0 && completedDestinationIds.length === 0) this.finish(record, "failed", `no destination accepted the archive (${(failedDestinationIds.length > 0 ? failedDestinationIds : destinationIds).join(", ")})`);
|
|
1628
|
+
else this.finish(record, "succeeded");
|
|
1629
|
+
}
|
|
1630
|
+
record.resolveResult(value);
|
|
1631
|
+
} catch (err) {
|
|
1632
|
+
if (err instanceof require_restore_archive.BackupCancelledError || record.controller.signal.aborted) {
|
|
1633
|
+
this.finish(record, "cancelled");
|
|
1634
|
+
record.rejectResult(err instanceof require_restore_archive.BackupCancelledError ? err : new require_restore_archive.BackupCancelledError());
|
|
1635
|
+
} else {
|
|
1636
|
+
this.finish(record, "failed", err instanceof Error ? err.message : String(err));
|
|
1637
|
+
record.rejectResult(err);
|
|
1638
|
+
}
|
|
1639
|
+
} finally {
|
|
1640
|
+
this.activeId = null;
|
|
1641
|
+
this.pump();
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
progressFor(record) {
|
|
1645
|
+
return {
|
|
1646
|
+
setPhase: (phase) => this.patch(record, { phase }),
|
|
1647
|
+
setDestinations: (ids) => this.patch(record, { destinationIds: [...ids] }),
|
|
1648
|
+
setStagedBytes: (bytes) => this.patch(record, { stagedBytes: bytes }),
|
|
1649
|
+
setArchiveSize: (bytes) => this.patch(record, { archiveSizeBytes: bytes }),
|
|
1650
|
+
setUploadedBytes: (bytes) => this.patch(record, { uploadedBytes: bytes }),
|
|
1651
|
+
destinationCompleted: (id) => this.patch(record, {
|
|
1652
|
+
completedDestinationIds: [...record.snapshot.completedDestinationIds, id],
|
|
1653
|
+
uploadedBytes: 0
|
|
1654
|
+
}),
|
|
1655
|
+
destinationFailed: (id) => this.patch(record, {
|
|
1656
|
+
failedDestinationIds: [...record.snapshot.failedDestinationIds, id],
|
|
1657
|
+
uploadedBytes: 0
|
|
1658
|
+
})
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
patch(record, patch) {
|
|
1662
|
+
record.snapshot = {
|
|
1663
|
+
...record.snapshot,
|
|
1664
|
+
...patch
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
finish(record, state, error) {
|
|
1668
|
+
this.patch(record, {
|
|
1669
|
+
state,
|
|
1670
|
+
phase: "done",
|
|
1671
|
+
finishedAt: this.now(),
|
|
1672
|
+
...error !== void 0 ? { error } : {}
|
|
1673
|
+
});
|
|
1674
|
+
this.finished.push(record.snapshot.id);
|
|
1675
|
+
while (this.finished.length > this.maxFinished) {
|
|
1676
|
+
const evicted = this.finished.shift();
|
|
1677
|
+
if (evicted !== void 0) this.runs.delete(evicted);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
/**
|
|
1682
|
+
* Canonical signature for join-detection. Order-normalised so
|
|
1683
|
+
* `{ destinations: [a, b] }` and `{ destinations: [b, a] }` — the same
|
|
1684
|
+
* fan-out set — coalesce.
|
|
1685
|
+
*/
|
|
1686
|
+
function requestSignature(request) {
|
|
1687
|
+
return JSON.stringify({
|
|
1688
|
+
destinations: [...request.destinations ?? []].toSorted(),
|
|
1689
|
+
locations: [...request.locations ?? []].toSorted(),
|
|
1690
|
+
label: request.label ?? null,
|
|
1691
|
+
retentionCount: request.retentionCount ?? null,
|
|
1692
|
+
databases: [...request.databases ?? []].toSorted()
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/builtins/backup-orchestrator/schedule-store.ts
|
|
1697
|
+
var BackupScheduleService = class {
|
|
1698
|
+
schedulesKind;
|
|
1699
|
+
constructor(schedulesKind) {
|
|
1700
|
+
this.schedulesKind = schedulesKind;
|
|
1701
|
+
}
|
|
1702
|
+
async list() {
|
|
1703
|
+
const rows = await (0, import_read_all_rows.readAllRows)(this.schedulesKind);
|
|
1704
|
+
rows.sort((a, b) => a.id.localeCompare(b.id));
|
|
1705
|
+
const out = [];
|
|
1706
|
+
for (const row of rows) {
|
|
1707
|
+
const mapped = bodyToSchedule(row.id, row.data);
|
|
1708
|
+
if (mapped) out.push(mapped);
|
|
1709
|
+
}
|
|
1710
|
+
return out;
|
|
1711
|
+
}
|
|
1712
|
+
async get(id) {
|
|
1713
|
+
const row = await this.schedulesKind.get(id);
|
|
1714
|
+
return row === null ? null : bodyToSchedule(id, row.data);
|
|
1715
|
+
}
|
|
1716
|
+
/** Replace-or-insert: one full `put` of the row. */
|
|
1717
|
+
async upsert(s) {
|
|
1718
|
+
const data = require_restore_archive.backupOrchestratorRecordKinds.schedules.schema.parse(scheduleToBody(s));
|
|
1719
|
+
await this.schedulesKind.put({
|
|
1720
|
+
id: s.id,
|
|
1721
|
+
data
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
async delete(id) {
|
|
1725
|
+
await this.schedulesKind.delete(id);
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
function scheduleToBody(s) {
|
|
1729
|
+
return {
|
|
1730
|
+
label: s.label,
|
|
1731
|
+
cron: s.cron,
|
|
1732
|
+
enabled: s.enabled,
|
|
1733
|
+
locationIds: [...s.locationIds],
|
|
1734
|
+
retentionCount: s.retentionCount,
|
|
1735
|
+
...s.dataSources !== void 0 ? { dataSources: [...s.dataSources] } : {},
|
|
1736
|
+
...s.databases !== void 0 ? { databases: [...s.databases] } : {},
|
|
1737
|
+
...s.lastAttemptAt !== void 0 ? { lastAttemptAt: s.lastAttemptAt } : {},
|
|
1738
|
+
...s.lastSuccessAt !== void 0 ? { lastSuccessAt: s.lastSuccessAt } : {},
|
|
1739
|
+
...s.lastError !== void 0 ? { lastError: s.lastError } : {}
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
function bodyToSchedule(id, body) {
|
|
1743
|
+
if (!id) return null;
|
|
1744
|
+
return {
|
|
1745
|
+
id,
|
|
1746
|
+
label: body.label,
|
|
1747
|
+
cron: body.cron,
|
|
1748
|
+
enabled: body.enabled,
|
|
1749
|
+
locationIds: [...body.locationIds],
|
|
1750
|
+
retentionCount: body.retentionCount,
|
|
1751
|
+
...body.dataSources !== void 0 ? { dataSources: [...body.dataSources] } : {},
|
|
1752
|
+
...body.databases !== void 0 && body.databases.length > 0 ? { databases: [...body.databases] } : {},
|
|
1753
|
+
...body.lastAttemptAt !== void 0 ? { lastAttemptAt: body.lastAttemptAt } : {},
|
|
1754
|
+
...body.lastSuccessAt !== void 0 ? { lastSuccessAt: body.lastSuccessAt } : {},
|
|
1755
|
+
...body.lastError !== void 0 ? { lastError: body.lastError } : {}
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
//#endregion
|
|
1759
|
+
//#region src/builtins/backup-orchestrator/staging-paths.ts
|
|
1760
|
+
/** Basename of the staging dir under the node data root. */
|
|
1761
|
+
var STAGING_DIR_NAME = "backup-staging";
|
|
1762
|
+
/** Canonical staging dir for a node data root. */
|
|
1763
|
+
function resolveStagingDir(nodeDataDir) {
|
|
1764
|
+
return node_path.join(nodeDataDir, STAGING_DIR_NAME);
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Delete every top-level entry of `stagingDir` except those whose
|
|
1768
|
+
* resolved path appears in `keepPaths`. Per-entry failures are logged
|
|
1769
|
+
* and skipped — a locked file must not abort the sweep. A missing
|
|
1770
|
+
* staging dir is a clean no-op.
|
|
1771
|
+
*/
|
|
1772
|
+
async function sweepStagingDir(input) {
|
|
1773
|
+
const keep = new Set(input.keepPaths.map((p) => node_path.resolve(p)));
|
|
1774
|
+
let entries;
|
|
1775
|
+
try {
|
|
1776
|
+
entries = await node_fs_promises.readdir(input.stagingDir);
|
|
1777
|
+
} catch {
|
|
1778
|
+
return {
|
|
1779
|
+
removedCount: 0,
|
|
1780
|
+
freedBytes: 0,
|
|
1781
|
+
keptCount: 0
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
let removedCount = 0;
|
|
1785
|
+
let freedBytes = 0;
|
|
1786
|
+
let keptCount = 0;
|
|
1787
|
+
for (const name of entries) {
|
|
1788
|
+
const abs = node_path.join(input.stagingDir, name);
|
|
1789
|
+
if (keep.has(node_path.resolve(abs))) {
|
|
1790
|
+
keptCount++;
|
|
1791
|
+
continue;
|
|
1792
|
+
}
|
|
1793
|
+
try {
|
|
1794
|
+
const footprint = await measureDirectoryFootprint(abs);
|
|
1795
|
+
await node_fs_promises.rm(abs, {
|
|
1796
|
+
recursive: true,
|
|
1797
|
+
force: true
|
|
1798
|
+
});
|
|
1799
|
+
removedCount++;
|
|
1800
|
+
freedBytes += footprint.totalBytes;
|
|
1801
|
+
} catch (err) {
|
|
1802
|
+
input.logger.warn("backup staging sweep: entry removal failed — skipping", { meta: {
|
|
1803
|
+
path: abs,
|
|
1804
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1805
|
+
} });
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return {
|
|
1809
|
+
removedCount,
|
|
1810
|
+
freedBytes,
|
|
1811
|
+
keptCount
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Recursive size + file count of a path (file or directory). Absent
|
|
1816
|
+
* path → `present: false` with zeros. Used by the sweep to report
|
|
1817
|
+
* reclaimed bytes and by the orchestrator to surface the legacy
|
|
1818
|
+
* staging dir's footprint without touching it.
|
|
1819
|
+
*/
|
|
1820
|
+
async function measureDirectoryFootprint(dir) {
|
|
1821
|
+
let stat;
|
|
1822
|
+
try {
|
|
1823
|
+
stat = await node_fs_promises.stat(dir);
|
|
1824
|
+
} catch {
|
|
1825
|
+
return {
|
|
1826
|
+
present: false,
|
|
1827
|
+
totalBytes: 0,
|
|
1828
|
+
fileCount: 0
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
if (!stat.isDirectory()) return {
|
|
1832
|
+
present: true,
|
|
1833
|
+
totalBytes: stat.size,
|
|
1834
|
+
fileCount: 1
|
|
1835
|
+
};
|
|
1836
|
+
let totalBytes = 0;
|
|
1837
|
+
let fileCount = 0;
|
|
1838
|
+
let children;
|
|
1839
|
+
try {
|
|
1840
|
+
children = await node_fs_promises.readdir(dir);
|
|
1841
|
+
} catch {
|
|
1842
|
+
return {
|
|
1843
|
+
present: true,
|
|
1844
|
+
totalBytes: 0,
|
|
1845
|
+
fileCount: 0
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
for (const child of children) {
|
|
1849
|
+
const nested = await measureDirectoryFootprint(node_path.join(dir, child));
|
|
1850
|
+
totalBytes += nested.totalBytes;
|
|
1851
|
+
fileCount += nested.fileCount;
|
|
1852
|
+
}
|
|
1853
|
+
return {
|
|
1854
|
+
present: true,
|
|
1855
|
+
totalBytes,
|
|
1856
|
+
fileCount
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
//#endregion
|
|
1860
|
+
//#region src/builtins/backup-orchestrator/write-targets.ts
|
|
1861
|
+
/**
|
|
1862
|
+
* Pick the destinations an archive may be fanned out to.
|
|
1863
|
+
*
|
|
1864
|
+
* An explicit `requested` list selects from the candidates by id and bypasses
|
|
1865
|
+
* the policy flag (that is today's behaviour and it is right: naming a
|
|
1866
|
+
* destination IS the opt-in). A requested id that is not a `backups` location
|
|
1867
|
+
* at all is simply absent from the candidates and drops out here, exactly as
|
|
1868
|
+
* before.
|
|
1869
|
+
*
|
|
1870
|
+
* The location flag is applied LAST and to both paths, so there is one place
|
|
1871
|
+
* where "disabled" is honoured rather than one per caller.
|
|
1872
|
+
*/
|
|
1873
|
+
function selectBackupTargets(input) {
|
|
1874
|
+
const requested = input.requested;
|
|
1875
|
+
const pool = requested && requested.length > 0 ? input.candidates.filter((c) => requested.includes(c.id)) : input.candidates.filter((c) => c.policyEnabled);
|
|
1876
|
+
return {
|
|
1877
|
+
targets: pool.filter((c) => c.locationEnabled),
|
|
1878
|
+
skippedDisabled: pool.filter((c) => !c.locationEnabled).map((c) => c.id)
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region src/builtins/backup-orchestrator/backup-orchestrator.addon.ts
|
|
1883
|
+
/**
|
|
1884
|
+
* `backup-orchestrator` builtin — singleton owner of the `backup` cap.
|
|
1885
|
+
*
|
|
1886
|
+
* Responsibilities:
|
|
1887
|
+
* - Schedule (cron-like timer at top of hour, daily/weekly cadence)
|
|
1888
|
+
* - Per-destination policy (enable/disable, retention count, label)
|
|
1889
|
+
* persisted in the `destination-policies` records kind (this builtin
|
|
1890
|
+
* owns the kind).
|
|
1891
|
+
* - Archive build (one tar.gz with embedded manifest, fanned out to
|
|
1892
|
+
* every selected `backups`-typed `StorageLocation` via the
|
|
1893
|
+
* consumer-facing `storage` cap's chunked upload protocol).
|
|
1894
|
+
* - Aggregate listing/restore/delete across destinations — operates
|
|
1895
|
+
* on the per-location `manifests.json` index file, not the
|
|
1896
|
+
* archives directly.
|
|
1897
|
+
*
|
|
1898
|
+
* Storage routing: destinations are
|
|
1899
|
+
* `api.storage.listLocations({ type: 'backups' })` — every operator-
|
|
1900
|
+
* visible `backups` location IS a destination. The orchestrator joins
|
|
1901
|
+
* that list with the `destination-policies` records to surface
|
|
1902
|
+
* `enabled` / `retentionCount` / `label`. The actual archive bytes
|
|
1903
|
+
* travel through `api.storage.beginUpload` / `writeChunk` /
|
|
1904
|
+
* `finalizeUpload`, with the staging archive built into
|
|
1905
|
+
* `<nodeDataDir>/backup-staging` (outside every backed-up location —
|
|
1906
|
+
* see staging-paths.ts).
|
|
1907
|
+
*/
|
|
1908
|
+
/**
|
|
1909
|
+
* Hardcoded seed for newly-discovered `backups` locations. Operators
|
|
1910
|
+
* tune retention per-destination after creation via the destinations
|
|
1911
|
+
* table. Promoted from a configurable global to a constant when the
|
|
1912
|
+
* orchestrator's settings panel was retired (per-destination cron +
|
|
1913
|
+
* inline retention input on the destinations row replaces every knob
|
|
1914
|
+
* the panel used to expose).
|
|
1915
|
+
*/
|
|
1916
|
+
var DEFAULT_RETENTION_COUNT = 7;
|
|
1917
|
+
var SCHEDULE_TICK_MS = 6e4;
|
|
1918
|
+
/**
|
|
1919
|
+
* Build the human-facing archive label. Every archive always carries
|
|
1920
|
+
* the destination id and the creation date — useful in restore wizards
|
|
1921
|
+
* + cross-destination listings where UUIDs are unreadable.
|
|
1922
|
+
*
|
|
1923
|
+
* Format: `${destinationId} · ${YYYY-MM-DD HH:mm}[${suffix}]`. Suffix is
|
|
1924
|
+
* an optional operator-provided tag (e.g. "before-migration") appended
|
|
1925
|
+
* after another middot. UTC is intentional — labels are also written
|
|
1926
|
+
* into the per-location manifest which travels across timezones with
|
|
1927
|
+
* the backup.
|
|
1928
|
+
*/
|
|
1929
|
+
function formatArchiveLabel(destinationId, createdAt, suffix) {
|
|
1930
|
+
const d = new Date(createdAt);
|
|
1931
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
1932
|
+
const stamp = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())} ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`;
|
|
1933
|
+
const trimmed = suffix?.trim();
|
|
1934
|
+
return trimmed ? `${destinationId} · ${stamp} · ${trimmed}` : `${destinationId} · ${stamp}`;
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Chunk size for the read-stream that feeds the chunked upload pipe.
|
|
1938
|
+
* 8 MiB is well under the WS frame limit (16 MiB on tRPC) with headroom.
|
|
1939
|
+
*/
|
|
1940
|
+
var UPLOAD_CHUNK_BYTES = 8 * 1024 * 1024;
|
|
1941
|
+
/** Manifest id this addon registers under (must match `package.json`). */
|
|
1942
|
+
var ORCHESTRATOR_ADDON_ID = "backup-orchestrator";
|
|
1943
|
+
var BackupOrchestratorAddon = class extends require_dist.BaseAddon {
|
|
1944
|
+
systemBackup = null;
|
|
1945
|
+
backupRecords = null;
|
|
1946
|
+
policies = null;
|
|
1947
|
+
schedules = null;
|
|
1948
|
+
/** Backup encryption keys — PUBLIC keys only (see encryption-key-store.ts). */
|
|
1949
|
+
encryptionKeys = null;
|
|
1950
|
+
warnedNoEncryptionStore = false;
|
|
1951
|
+
dataDir = "";
|
|
1952
|
+
/**
|
|
1953
|
+
* Transient build buffer for archive fan-out. The tar is built here
|
|
1954
|
+
* ONCE, streamed to every destination via the storage cap's chunked
|
|
1955
|
+
* upload, then removed. Lives at `<nodeDataDir>/backup-staging` —
|
|
1956
|
+
* OUTSIDE every backed-up location, so a backup can never contain a
|
|
1957
|
+
* backup (the old `ctx.dataDir/staging` sat inside `addons-data` and
|
|
1958
|
+
* compounded 175M → 4.5G before Jul 28), and distinct from
|
|
1959
|
+
* `<nodeDataDir>/backups` where the default `backups` destination
|
|
1960
|
+
* seeds when `CAMSTACK_BACKUP_ROOT` is unset. See staging-paths.ts.
|
|
1961
|
+
*/
|
|
1962
|
+
stagingDir = "";
|
|
1963
|
+
scheduleTimer = null;
|
|
1964
|
+
/** Guards the disarmed-scheduler complaint to once per process. */
|
|
1965
|
+
warnedSchedulerDisarmed = false;
|
|
1966
|
+
/**
|
|
1967
|
+
* Baseline used as the "after" anchor when a schedule has a cron but
|
|
1968
|
+
* has never fired yet (no `lastAttemptAt`). Set on orchestrator boot so a
|
|
1969
|
+
* pattern that fires every minute doesn't immediately replay every
|
|
1970
|
+
* historical "missed" run from epoch 0.
|
|
1971
|
+
*/
|
|
1972
|
+
scheduleBaselineAt = Date.now();
|
|
1973
|
+
manifestLock = new LocationManifestLock();
|
|
1974
|
+
/**
|
|
1975
|
+
* Global execution queue — at most ONE archive build at a time,
|
|
1976
|
+
* cluster-node-wide (D342). Replaces the earlier invisible
|
|
1977
|
+
* single-flight `buildLock`: same serialisation guarantee (two
|
|
1978
|
+
* schedules due one tick apart built 8.2 GB + 3.7 GB side by side on
|
|
1979
|
+
* the hub, 2026-09-04), but every run is now observable via
|
|
1980
|
+
* `listRuns`, joinable when identical, and cancellable mid-stream.
|
|
1981
|
+
*/
|
|
1982
|
+
runQueue = null;
|
|
1983
|
+
constructor() {
|
|
1984
|
+
super({});
|
|
1985
|
+
}
|
|
1986
|
+
async onInitialize() {
|
|
1987
|
+
const records = this.ctx.records;
|
|
1988
|
+
if (records !== void 0) {
|
|
1989
|
+
await records.declare(require_restore_archive.backupOrchestratorRecordKinds);
|
|
1990
|
+
this.backupRecords = require_restore_archive.backupRecordStoresOf(records);
|
|
1991
|
+
}
|
|
1992
|
+
this.dataDir = this.ctx.nodeDataDir;
|
|
1993
|
+
this.stagingDir = resolveStagingDir(this.ctx.nodeDataDir);
|
|
1994
|
+
this.systemBackup = new require_restore_archive.SystemBackupService(this.dataDir, this.ctx.logger);
|
|
1995
|
+
this.runQueue = new BackupRunQueue((request, signal, progress) => this.runBackupBuild(request, signal, progress));
|
|
1996
|
+
await this.cleanStagingArea();
|
|
1997
|
+
const backupRecords = this.backupRecords;
|
|
1998
|
+
if (backupRecords === null) this.ctx.logger.warn("backup-orchestrator: no ctx.records — schedules and destination policies will not persist");
|
|
1999
|
+
else {
|
|
2000
|
+
this.policies = new BackupDestinationPolicyService(backupRecords.destinationPolicies);
|
|
2001
|
+
this.schedules = new BackupScheduleService(backupRecords.schedules);
|
|
2002
|
+
}
|
|
2003
|
+
await this.seedWeekly();
|
|
2004
|
+
const settingsStore = this.ctx.kernel.capabilityRegistry?.getSingleton("settings-store");
|
|
2005
|
+
this.encryptionKeys = settingsStore ? new BackupEncryptionKeyStore(settingsStore, Date.now, this.backupRecords?.encryptionKeys ?? null) : null;
|
|
2006
|
+
const provider = {
|
|
2007
|
+
listDestinations: () => this.listDestinations(),
|
|
2008
|
+
list: () => this.aggregatedList(),
|
|
2009
|
+
listLocations: () => this.systemBackup.statLocations(),
|
|
2010
|
+
trigger: (input) => this.triggerBackup(input),
|
|
2011
|
+
listRuns: () => this.listRuns(),
|
|
2012
|
+
cancel: (input) => this.cancelRun(input),
|
|
2013
|
+
getEntries: (input) => this.getEntries(input),
|
|
2014
|
+
restore: (input) => this.scheduleRestore(input),
|
|
2015
|
+
getEncryption: () => this.getEncryption(),
|
|
2016
|
+
setupEncryption: () => this.setupEncryption(),
|
|
2017
|
+
disableEncryption: () => this.disableEncryption(),
|
|
2018
|
+
checkBackupKey: (input) => this.checkBackupKey(input),
|
|
2019
|
+
delete: (input) => this.deleteArchive(input),
|
|
2020
|
+
listArchives: (input) => this.listArchives(input),
|
|
2021
|
+
upsertDestinationPolicy: (input) => this.upsertDestinationPolicy(input),
|
|
2022
|
+
previewSchedule: (input) => this.previewSchedule(input),
|
|
2023
|
+
listSchedules: () => this.listSchedules(),
|
|
2024
|
+
listAvailableDatabases: () => this.listAvailableDatabases(),
|
|
2025
|
+
upsertSchedule: (input) => this.upsertSchedule(input),
|
|
2026
|
+
deleteSchedule: (input) => this.deleteSchedule(input)
|
|
2027
|
+
};
|
|
2028
|
+
this.startScheduleTimer();
|
|
2029
|
+
this.ctx.logger.info("Backup orchestrator initialized", { meta: {
|
|
2030
|
+
dataDir: this.dataDir,
|
|
2031
|
+
policies: this.policies !== null
|
|
2032
|
+
} });
|
|
2033
|
+
return [{
|
|
2034
|
+
capability: require_dist.backupCapability,
|
|
2035
|
+
provider
|
|
2036
|
+
}, {
|
|
2037
|
+
capability: require_dist.storageOccupancyCapability,
|
|
2038
|
+
provider: { getOccupancy: async (input) => this.backupOccupancy(input.locationIds) }
|
|
2039
|
+
}];
|
|
2040
|
+
}
|
|
2041
|
+
async onShutdown() {
|
|
2042
|
+
this.stopScheduleTimer();
|
|
2043
|
+
if (this.runQueue) {
|
|
2044
|
+
for (const run of this.runQueue.listRuns()) if (run.state === "queued" || run.state === "running") this.runQueue.cancel(run.id);
|
|
2045
|
+
}
|
|
2046
|
+
this.runQueue = null;
|
|
2047
|
+
this.systemBackup = null;
|
|
2048
|
+
this.policies = null;
|
|
2049
|
+
this.schedules = null;
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Aggregate destinations from `api.storage.listLocations({ type: 'backups' })`
|
|
2053
|
+
* joined with the per-destination policy table. New locations get an
|
|
2054
|
+
* `ensureDefault` policy seeded transparently (enabled=true,
|
|
2055
|
+
* retentionCount=defaultRetentionCount). Pre-existing operator-edited
|
|
2056
|
+
* policies are preserved by the `ensureDefault` idempotency.
|
|
2057
|
+
*/
|
|
2058
|
+
async listDestinations() {
|
|
2059
|
+
const locations = await this.fetchBackupLocations();
|
|
2060
|
+
const policies = await this.loadPoliciesIndexed(locations.map((l) => l.id));
|
|
2061
|
+
const lastSuccess = await Promise.all(locations.map(async (loc) => {
|
|
2062
|
+
try {
|
|
2063
|
+
const manifest = await readLocationManifest(this.storageApi(), loc.id);
|
|
2064
|
+
return [loc.id, latestArchiveOf(manifest)];
|
|
2065
|
+
} catch {
|
|
2066
|
+
return [loc.id, void 0];
|
|
2067
|
+
}
|
|
2068
|
+
}));
|
|
2069
|
+
const lastSuccessByLoc = new Map(lastSuccess);
|
|
2070
|
+
const cadence = await this.cadenceByLocation();
|
|
2071
|
+
return locations.map((loc) => this.toDestinationWire(loc, policies.get(loc.id), lastSuccessByLoc.get(loc.id), cadence.get(loc.id)));
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* Join the enabled schedules by the locations they fan out to.
|
|
2075
|
+
* Comma-joined crons (a location can be targeted by several schedules),
|
|
2076
|
+
* earliest next firing. Computed from `Date.now()` — an operator asking
|
|
2077
|
+
* "when next" means from now, never from a stale run cursor.
|
|
2078
|
+
*/
|
|
2079
|
+
async cadenceByLocation() {
|
|
2080
|
+
const out = /* @__PURE__ */ new Map();
|
|
2081
|
+
if (!this.schedules) return out;
|
|
2082
|
+
const schedules = await this.schedules.list().catch((err) => {
|
|
2083
|
+
this.ctx.logger.warn("backup-orchestrator: schedule list failed — cadence unknown", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
2084
|
+
return [];
|
|
2085
|
+
});
|
|
2086
|
+
const now = Date.now();
|
|
2087
|
+
for (const s of schedules) {
|
|
2088
|
+
if (!s.enabled || s.cron.trim().length === 0) continue;
|
|
2089
|
+
const next = this.safeNextDue(s.cron, now);
|
|
2090
|
+
for (const id of s.locationIds) {
|
|
2091
|
+
const prev = out.get(id);
|
|
2092
|
+
const crons = prev ? [...prev.crons, s.cron] : [s.cron];
|
|
2093
|
+
const nextRunAt = next === void 0 ? prev?.nextRunAt : prev?.nextRunAt === void 0 ? next : Math.min(prev.nextRunAt, next);
|
|
2094
|
+
out.set(id, {
|
|
2095
|
+
crons,
|
|
2096
|
+
...nextRunAt !== void 0 ? { nextRunAt } : {}
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
return out;
|
|
2101
|
+
}
|
|
2102
|
+
async fetchBackupLocations() {
|
|
2103
|
+
try {
|
|
2104
|
+
return await this.ctx.api.storage.listLocations.query({ type: "backups" });
|
|
2105
|
+
} catch (err) {
|
|
2106
|
+
this.ctx.logger.error("backup-orchestrator: listLocations failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
2107
|
+
return [];
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* Load every persisted policy and key it by `locationId`, while
|
|
2112
|
+
* lazily seeding a default for any `locationId` we haven't seen
|
|
2113
|
+
* before. Idempotent — `ensureDefault` no-ops on already-persisted
|
|
2114
|
+
* rows. Falls back to the in-memory default policy when the policy
|
|
2115
|
+
* service isn't wired (no `ctx.records`).
|
|
2116
|
+
*/
|
|
2117
|
+
async loadPoliciesIndexed(locationIds) {
|
|
2118
|
+
const out = /* @__PURE__ */ new Map();
|
|
2119
|
+
if (!this.policies) {
|
|
2120
|
+
for (const id of locationIds) out.set(id, this.fallbackPolicy(id));
|
|
2121
|
+
return out;
|
|
2122
|
+
}
|
|
2123
|
+
const persisted = await this.policies.list().catch((err) => {
|
|
2124
|
+
this.ctx.logger.warn("backup-orchestrator: policy list failed — using defaults", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
2125
|
+
return [];
|
|
2126
|
+
});
|
|
2127
|
+
for (const p of persisted) out.set(p.locationId, p);
|
|
2128
|
+
for (const id of locationIds) {
|
|
2129
|
+
if (out.has(id)) continue;
|
|
2130
|
+
try {
|
|
2131
|
+
const fresh = await this.policies.ensureDefault(id, { retentionCount: DEFAULT_RETENTION_COUNT });
|
|
2132
|
+
out.set(id, fresh);
|
|
2133
|
+
} catch (err) {
|
|
2134
|
+
this.ctx.logger.warn("backup-orchestrator: ensureDefault failed", { meta: {
|
|
2135
|
+
locationId: id,
|
|
2136
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2137
|
+
} });
|
|
2138
|
+
out.set(id, this.fallbackPolicy(id));
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
return out;
|
|
2142
|
+
}
|
|
2143
|
+
fallbackPolicy(locationId) {
|
|
2144
|
+
return {
|
|
2145
|
+
locationId,
|
|
2146
|
+
enabled: true,
|
|
2147
|
+
retentionCount: DEFAULT_RETENTION_COUNT
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
toDestinationWire(loc, policy, latest, cadence) {
|
|
2151
|
+
const effective = policy ?? this.fallbackPolicy(loc.id);
|
|
2152
|
+
const subId = extractSlug(loc.id);
|
|
2153
|
+
const displayName = effective.label && effective.label.length > 0 ? effective.label : loc.displayName;
|
|
2154
|
+
return {
|
|
2155
|
+
id: loc.id,
|
|
2156
|
+
addonId: ORCHESTRATOR_ADDON_ID,
|
|
2157
|
+
subId,
|
|
2158
|
+
displayName,
|
|
2159
|
+
kind: kindFromProviderId(loc.providerId),
|
|
2160
|
+
triggerSupported: effective.enabled && require_dist.mayWriteToLocation(loc),
|
|
2161
|
+
restoreSupported: true,
|
|
2162
|
+
enabled: effective.enabled,
|
|
2163
|
+
retentionCount: effective.retentionCount,
|
|
2164
|
+
...effective.label !== void 0 ? { label: effective.label } : {},
|
|
2165
|
+
...latest !== void 0 ? { lastSuccessAt: latest.createdAt } : {},
|
|
2166
|
+
...latest !== void 0 ? { lastSuccessSizeBytes: latest.sizeBytes } : {},
|
|
2167
|
+
...cadence !== void 0 ? { cron: cadence.crons.join(", ") } : {},
|
|
2168
|
+
...cadence?.nextRunAt !== void 0 ? { nextRunAt: cadence.nextRunAt } : {},
|
|
2169
|
+
...effective.lastAttemptAt !== void 0 ? { lastAttemptAt: effective.lastAttemptAt } : {},
|
|
2170
|
+
...effective.lastError !== void 0 ? { lastError: effective.lastError } : {}
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Compute next-due ms-epoch for a cron, or `undefined` on parse error.
|
|
2175
|
+
* Catches so a single malformed cron doesn't blank out the whole
|
|
2176
|
+
* destinations list at the cap surface.
|
|
2177
|
+
*/
|
|
2178
|
+
safeNextDue(cron, after) {
|
|
2179
|
+
try {
|
|
2180
|
+
return computeNextDue(cron, after ?? this.scheduleBaselineAt) ?? void 0;
|
|
2181
|
+
} catch {
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Aggregate listing — read every `backups` location's `manifests.json`
|
|
2187
|
+
* and return one wire entry per archive, tagged with `destinationId`.
|
|
2188
|
+
* Failures on individual locations are logged and skipped so a single
|
|
2189
|
+
* unreachable destination doesn't blank out the whole UI.
|
|
2190
|
+
*/
|
|
2191
|
+
/**
|
|
2192
|
+
* Bytes the archives occupy on each named location (D388).
|
|
2193
|
+
*
|
|
2194
|
+
* Summed from each location's own manifest — the record the uploader writes
|
|
2195
|
+
* — so this never walks a filesystem and never stats a remote destination.
|
|
2196
|
+
* A manifest that cannot be read contributes NOTHING and is logged: a
|
|
2197
|
+
* destination that is temporarily unreachable must read back as unknown, not
|
|
2198
|
+
* as an empty disk. A location holding no archives is omitted for the same
|
|
2199
|
+
* reason it is omitted everywhere else — only the orchestrator can tell
|
|
2200
|
+
* "nobody reported" from "reported nothing".
|
|
2201
|
+
*/
|
|
2202
|
+
async backupOccupancy(locationIds) {
|
|
2203
|
+
const measuredAtMs = Date.now();
|
|
2204
|
+
const out = [];
|
|
2205
|
+
for (const locationId of locationIds) {
|
|
2206
|
+
let manifest;
|
|
2207
|
+
try {
|
|
2208
|
+
manifest = await readLocationManifest(this.storageApi(), locationId);
|
|
2209
|
+
} catch {
|
|
2210
|
+
continue;
|
|
2211
|
+
}
|
|
2212
|
+
const ownedBytes = manifest.archives.reduce((sum, a) => sum + a.sizeBytes, 0);
|
|
2213
|
+
if (ownedBytes <= 0) continue;
|
|
2214
|
+
out.push({
|
|
2215
|
+
locationId,
|
|
2216
|
+
ownedBytes,
|
|
2217
|
+
measuredAtMs
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
return out;
|
|
2221
|
+
}
|
|
2222
|
+
async aggregatedList() {
|
|
2223
|
+
const locations = await this.fetchBackupLocations();
|
|
2224
|
+
const out = [];
|
|
2225
|
+
for (const loc of locations) {
|
|
2226
|
+
let manifest;
|
|
2227
|
+
try {
|
|
2228
|
+
manifest = await readLocationManifest(this.storageApi(), loc.id);
|
|
2229
|
+
} catch (err) {
|
|
2230
|
+
this.ctx.logger.warn("backup list: manifest read failed", { meta: {
|
|
2231
|
+
locationId: loc.id,
|
|
2232
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2233
|
+
} });
|
|
2234
|
+
continue;
|
|
2235
|
+
}
|
|
2236
|
+
for (const a of manifest.archives) {
|
|
2237
|
+
const entry = {
|
|
2238
|
+
id: a.id,
|
|
2239
|
+
destinationId: loc.id,
|
|
2240
|
+
createdAt: a.createdAt,
|
|
2241
|
+
sizeBytes: a.sizeBytes,
|
|
2242
|
+
...a.label !== void 0 ? { label: a.label } : {},
|
|
2243
|
+
locations: [...a.manifest.locations],
|
|
2244
|
+
...a.encryption !== void 0 ? { encryption: a.encryption } : {}
|
|
2245
|
+
};
|
|
2246
|
+
out.push(entry);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
return out;
|
|
2250
|
+
}
|
|
2251
|
+
async stagingPath(filename) {
|
|
2252
|
+
await node_fs_promises.mkdir(this.stagingDir, { recursive: true });
|
|
2253
|
+
return node_path.join(this.stagingDir, filename);
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Boot-time staging hygiene. Sweeps the staging dir (sparing an
|
|
2257
|
+
* archive a pending-restore marker references — the boot hook has
|
|
2258
|
+
* not consumed it yet), then reports — without touching — the LEGACY
|
|
2259
|
+
* staging dir inside `addons-data`, where pre-move leaks live. The
|
|
2260
|
+
* legacy dir held 5.1 GB on the hub; deleting operator-visible
|
|
2261
|
+
* gigabytes silently is not this addon's call, so it warns with the
|
|
2262
|
+
* footprint instead.
|
|
2263
|
+
*/
|
|
2264
|
+
async cleanStagingArea() {
|
|
2265
|
+
const marker = this.systemBackup?.readPendingMarker() ?? null;
|
|
2266
|
+
const keepPaths = marker ? [marker.archivePath] : [];
|
|
2267
|
+
try {
|
|
2268
|
+
const swept = await sweepStagingDir({
|
|
2269
|
+
stagingDir: this.stagingDir,
|
|
2270
|
+
keepPaths,
|
|
2271
|
+
logger: this.ctx.logger
|
|
2272
|
+
});
|
|
2273
|
+
if (swept.removedCount > 0) this.ctx.logger.info("backup staging swept — leaked transient files removed", { meta: {
|
|
2274
|
+
stagingDir: this.stagingDir,
|
|
2275
|
+
removedCount: swept.removedCount,
|
|
2276
|
+
freedBytes: swept.freedBytes,
|
|
2277
|
+
keptForPendingRestore: swept.keptCount
|
|
2278
|
+
} });
|
|
2279
|
+
} catch (err) {
|
|
2280
|
+
this.ctx.logger.warn("backup staging sweep failed — continuing", { meta: {
|
|
2281
|
+
stagingDir: this.stagingDir,
|
|
2282
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2283
|
+
} });
|
|
2284
|
+
}
|
|
2285
|
+
const legacyDir = node_path.join(this.ctx.dataDir, "staging");
|
|
2286
|
+
try {
|
|
2287
|
+
const legacy = await measureDirectoryFootprint(legacyDir);
|
|
2288
|
+
if (legacy.present && legacy.fileCount > 0) this.ctx.logger.warn("legacy backup staging dir still holds files inside addons-data — excluded from archives, but the disk space is only reclaimed by deleting it", { meta: {
|
|
2289
|
+
legacyDir,
|
|
2290
|
+
fileCount: legacy.fileCount,
|
|
2291
|
+
totalBytes: legacy.totalBytes
|
|
2292
|
+
} });
|
|
2293
|
+
} catch {}
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Trigger a backup run through the global execution queue (D342):
|
|
2297
|
+
* at most one archive build at a time, a trigger that arrives while
|
|
2298
|
+
* one is in flight WAITS (or joins an identical queued run), and the
|
|
2299
|
+
* result says which happened. The call still resolves when the run
|
|
2300
|
+
* terminates; a cancelled run resolves with `cancelled: true` and
|
|
2301
|
+
* whatever entries landed before the stop — a deliberate operator
|
|
2302
|
+
* cancel is an outcome, not an error.
|
|
2303
|
+
*/
|
|
2304
|
+
async triggerBackup(input) {
|
|
2305
|
+
if (!this.runQueue) throw new Error("orchestrator not initialized");
|
|
2306
|
+
const request = {
|
|
2307
|
+
...input?.destinations ? { destinations: input.destinations } : {},
|
|
2308
|
+
...input?.locations ? { locations: input.locations } : {},
|
|
2309
|
+
...input?.label !== void 0 ? { label: input.label } : {},
|
|
2310
|
+
...input?.retentionCount !== void 0 ? { retentionCount: input.retentionCount } : {},
|
|
2311
|
+
...input?.databases ? { databases: input.databases } : {}
|
|
2312
|
+
};
|
|
2313
|
+
const submitted = this.runQueue.submit(request);
|
|
2314
|
+
if (submitted.queued) this.ctx.logger.info(submitted.joined ? "backup trigger: identical run already queued — joined it" : "backup trigger: a run is in flight — enqueued behind it", { meta: { runId: submitted.runId } });
|
|
2315
|
+
let entries;
|
|
2316
|
+
try {
|
|
2317
|
+
entries = await submitted.result;
|
|
2318
|
+
} catch (err) {
|
|
2319
|
+
if (!(err instanceof require_restore_archive.BackupCancelledError)) throw err;
|
|
2320
|
+
entries = [];
|
|
2321
|
+
}
|
|
2322
|
+
const finalState = this.runQueue?.getRun(submitted.runId)?.state;
|
|
2323
|
+
return {
|
|
2324
|
+
runId: submitted.runId,
|
|
2325
|
+
queued: submitted.queued,
|
|
2326
|
+
joined: submitted.joined,
|
|
2327
|
+
cancelled: finalState === "cancelled",
|
|
2328
|
+
entries
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
/** Wire `backup.listRuns` — queued + active + bounded history. */
|
|
2332
|
+
async listRuns() {
|
|
2333
|
+
return this.runQueue?.listRuns() ?? [];
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Wire `backup.cancel`. Delegates to the queue: a queued run is
|
|
2337
|
+
* removed before it starts; the running run's abort signal fires and
|
|
2338
|
+
* `runBackupBuild` stops the tar/upload streams and deletes its
|
|
2339
|
+
* staging archive on the way out.
|
|
2340
|
+
*/
|
|
2341
|
+
async cancelRun(input) {
|
|
2342
|
+
const cancelled = this.runQueue?.cancel(input.runId) ?? false;
|
|
2343
|
+
if (cancelled) this.ctx.logger.info("backup run cancel requested", { meta: { runId: input.runId } });
|
|
2344
|
+
else this.ctx.logger.warn("backup cancel: run unknown or already terminal", { meta: { runId: input.runId } });
|
|
2345
|
+
return { cancelled };
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Execute ONE backup run — only ever called by the queue, never
|
|
2349
|
+
* directly (the queue is the single serialisation authority).
|
|
2350
|
+
* Builds the archive in the private staging dir, then pushes it to
|
|
2351
|
+
* every selected destination via the storage cap's chunked upload
|
|
2352
|
+
* protocol. Per-destination errors are logged and recorded on the
|
|
2353
|
+
* run — one bad sink doesn't kill the run.
|
|
2354
|
+
*
|
|
2355
|
+
* Cleanup contract (D342): the staging file is deleted in `finally`,
|
|
2356
|
+
* which covers success, per-destination failure, build failure AND
|
|
2357
|
+
* cancellation alike. The only leak this cannot cover — the process
|
|
2358
|
+
* dying inside the run — is reclaimed by the boot sweep in
|
|
2359
|
+
* `cleanStagingArea`.
|
|
2360
|
+
*/
|
|
2361
|
+
async runBackupBuild(input, signal, progress) {
|
|
2362
|
+
if (!this.systemBackup) throw new Error("orchestrator not initialized");
|
|
2363
|
+
const targets = await this.resolveTargets(input.destinations !== void 0 ? [...input.destinations] : void 0);
|
|
2364
|
+
if (targets.length === 0) {
|
|
2365
|
+
this.ctx.logger.warn("backup trigger: no destinations selected — this archive is being dropped", { meta: {
|
|
2366
|
+
requestedDestinationIds: input.destinations !== void 0 ? [...input.destinations] : [],
|
|
2367
|
+
label: input.label ?? null
|
|
2368
|
+
} });
|
|
2369
|
+
return [];
|
|
2370
|
+
}
|
|
2371
|
+
progress.setDestinations(targets.map((t) => t.id));
|
|
2372
|
+
const policies = await this.loadPoliciesIndexed(targets.map((t) => t.id));
|
|
2373
|
+
const encryptTo = await this.activeEncryptionKey();
|
|
2374
|
+
const archiveId = (0, node_crypto.randomUUID)();
|
|
2375
|
+
const archiveFilename = encryptTo === null ? `${archiveId}.tar.gz` : `${archiveId}.tar.gz${require_restore_archive.ENCRYPTED_BACKUP_SUFFIX}`;
|
|
2376
|
+
const cachePath = await this.stagingPath(archiveFilename);
|
|
2377
|
+
let result;
|
|
2378
|
+
try {
|
|
2379
|
+
result = await this.systemBackup.createArchive({
|
|
2380
|
+
archivePath: cachePath,
|
|
2381
|
+
...input.locations ? { locations: [...input.locations] } : {},
|
|
2382
|
+
signal,
|
|
2383
|
+
onArchiveBytes: (bytes) => progress.setStagedBytes(bytes),
|
|
2384
|
+
owner: this.databaseOwner(),
|
|
2385
|
+
...input.databases ? { databases: input.databases } : {},
|
|
2386
|
+
...encryptTo !== null ? { encryptTo: encryptTo.publicKey } : {}
|
|
2387
|
+
});
|
|
2388
|
+
} catch (err) {
|
|
2389
|
+
if (err instanceof require_restore_archive.BackupSnapshotRefusedError) for (const dest of targets) {
|
|
2390
|
+
progress.destinationFailed(dest.id);
|
|
2391
|
+
await this.recordDestinationOutcome(dest.id, Date.now(), err.message);
|
|
2392
|
+
}
|
|
2393
|
+
throw err;
|
|
2394
|
+
}
|
|
2395
|
+
progress.setArchiveSize(result.sizeBytes);
|
|
2396
|
+
progress.setPhase("uploading");
|
|
2397
|
+
try {
|
|
2398
|
+
const entries = [];
|
|
2399
|
+
const createdAt = Date.now();
|
|
2400
|
+
for (const dest of targets) {
|
|
2401
|
+
if (signal.aborted) {
|
|
2402
|
+
this.ctx.logger.info("backup run cancelled — skipping remaining destinations", { meta: {
|
|
2403
|
+
runCancelledAfter: entries.length,
|
|
2404
|
+
skippedDestinationIds: targets.slice(targets.indexOf(dest)).map((t) => t.id)
|
|
2405
|
+
} });
|
|
2406
|
+
break;
|
|
2407
|
+
}
|
|
2408
|
+
try {
|
|
2409
|
+
const policy = policies.get(dest.id) ?? this.fallbackPolicy(dest.id);
|
|
2410
|
+
const stored = await this.uploadAndIndex({
|
|
2411
|
+
locationId: dest.id,
|
|
2412
|
+
archiveId,
|
|
2413
|
+
archiveFilename,
|
|
2414
|
+
cachePath,
|
|
2415
|
+
sizeBytes: result.sizeBytes,
|
|
2416
|
+
archiveManifest: result.manifest,
|
|
2417
|
+
retentionCount: input.retentionCount ?? policy.retentionCount,
|
|
2418
|
+
databases: input.databases ?? require_restore_archive.DEFAULT_BACKUP_DATABASES,
|
|
2419
|
+
createdAt,
|
|
2420
|
+
label: formatArchiveLabel(dest.id, createdAt, input.label),
|
|
2421
|
+
...result.encryption !== void 0 ? { encryption: result.encryption } : {},
|
|
2422
|
+
signal,
|
|
2423
|
+
onUploadedBytes: (bytes) => progress.setUploadedBytes(bytes)
|
|
2424
|
+
});
|
|
2425
|
+
entries.push(stored);
|
|
2426
|
+
progress.destinationCompleted(dest.id);
|
|
2427
|
+
await this.recordDestinationOutcome(dest.id, createdAt);
|
|
2428
|
+
this.ctx.eventBus.emit({
|
|
2429
|
+
id: (0, node_crypto.randomUUID)(),
|
|
2430
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2431
|
+
source: {
|
|
2432
|
+
type: "addon",
|
|
2433
|
+
id: "backup-orchestrator"
|
|
2434
|
+
},
|
|
2435
|
+
category: require_dist.EventCategory.BackupCompleted,
|
|
2436
|
+
data: {
|
|
2437
|
+
destinationId: dest.id,
|
|
2438
|
+
backupId: stored.id,
|
|
2439
|
+
sizeMB: Math.round((stored.sizeBytes ?? 0) / (1024 * 1024))
|
|
2440
|
+
}
|
|
2441
|
+
});
|
|
2442
|
+
} catch (err) {
|
|
2443
|
+
if (err instanceof require_restore_archive.BackupCancelledError) continue;
|
|
2444
|
+
progress.destinationFailed(dest.id);
|
|
2445
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2446
|
+
this.ctx.logger.error("backup trigger: destination failed", { meta: {
|
|
2447
|
+
destinationId: dest.id,
|
|
2448
|
+
error: message
|
|
2449
|
+
} });
|
|
2450
|
+
await this.recordDestinationOutcome(dest.id, Date.now(), message);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
this.ctx.eventBus.emit({
|
|
2454
|
+
id: (0, node_crypto.randomUUID)(),
|
|
2455
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2456
|
+
source: {
|
|
2457
|
+
type: "addon",
|
|
2458
|
+
id: "backup-orchestrator"
|
|
2459
|
+
},
|
|
2460
|
+
category: require_dist.EventCategory.BackupRunCompleted,
|
|
2461
|
+
data: {
|
|
2462
|
+
destinationsOk: entries.length,
|
|
2463
|
+
destinationsFailed: Math.max(0, targets.length - entries.length),
|
|
2464
|
+
destinationsTotal: targets.length,
|
|
2465
|
+
sizeMB: Math.round(entries.reduce((acc, e) => acc + (e.sizeBytes ?? 0), 0) / (1024 * 1024)),
|
|
2466
|
+
...entries[0]?.id === void 0 ? {} : { backupId: entries[0].id }
|
|
2467
|
+
}
|
|
2468
|
+
});
|
|
2469
|
+
return entries;
|
|
2470
|
+
} finally {
|
|
2471
|
+
try {
|
|
2472
|
+
await node_fs_promises.rm(cachePath, { force: true });
|
|
2473
|
+
} catch {}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* THIS node's database owner (D693), reached through `database-snapshot`
|
|
2478
|
+
* pinned to the local node: the paths it answers must be on this host,
|
|
2479
|
+
* because this process archives them. No local node id means no pin, and an
|
|
2480
|
+
* unpinned singleton call could be answered by another host — refuse.
|
|
2481
|
+
*/
|
|
2482
|
+
databaseOwner() {
|
|
2483
|
+
const pin = () => {
|
|
2484
|
+
const localNodeId = this.ctx.kernel.localNodeId;
|
|
2485
|
+
if (localNodeId === void 0 || localNodeId.length === 0) throw new Error("no local node id — the database owner cannot be pinned to this host");
|
|
2486
|
+
return require_dist.nodePin(require_dist.toNodeId(localNodeId));
|
|
2487
|
+
};
|
|
2488
|
+
return {
|
|
2489
|
+
listDatabases: async () => {
|
|
2490
|
+
return (await this.ctx.api.databaseSnapshot.listDatabases.query({}, pin())).databases;
|
|
2491
|
+
},
|
|
2492
|
+
writeSnapshot: async (databaseId) => this.ctx.api.databaseSnapshot.writeSnapshot.mutate({ databaseId }, pin())
|
|
2493
|
+
};
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Push the staged archive to a single destination via chunked
|
|
2497
|
+
* upload, then update the per-location manifest. Applies the
|
|
2498
|
+
* destination's retention policy as part of the same lock-protected
|
|
2499
|
+
* manifest mutation so the deletes never race with a concurrent
|
|
2500
|
+
* append.
|
|
2501
|
+
*
|
|
2502
|
+
* Throws on upload / manifest failure — caller logs and continues to
|
|
2503
|
+
* the next destination so a single bad sink doesn't fail the run.
|
|
2504
|
+
*/
|
|
2505
|
+
async uploadAndIndex(input) {
|
|
2506
|
+
const { uploadId } = await this.ctx.api.storage.beginUpload.mutate({
|
|
2507
|
+
location: input.locationId,
|
|
2508
|
+
relativePath: input.archiveFilename,
|
|
2509
|
+
sizeBytes: input.sizeBytes
|
|
2510
|
+
});
|
|
2511
|
+
try {
|
|
2512
|
+
let offset = 0;
|
|
2513
|
+
const stream = node_fs.createReadStream(input.cachePath, { highWaterMark: UPLOAD_CHUNK_BYTES });
|
|
2514
|
+
for await (const rawChunk of stream) {
|
|
2515
|
+
if (input.signal?.aborted) {
|
|
2516
|
+
stream.destroy();
|
|
2517
|
+
throw new require_restore_archive.BackupCancelledError(`backup upload to ${input.locationId} cancelled mid-stream`);
|
|
2518
|
+
}
|
|
2519
|
+
const chunk = toBufferChunk(rawChunk);
|
|
2520
|
+
const data = new Uint8Array(chunk.byteLength);
|
|
2521
|
+
data.set(chunk);
|
|
2522
|
+
await this.ctx.api.storage.writeChunk.mutate({
|
|
2523
|
+
uploadId,
|
|
2524
|
+
offset,
|
|
2525
|
+
data
|
|
2526
|
+
});
|
|
2527
|
+
offset += data.byteLength;
|
|
2528
|
+
input.onUploadedBytes?.(offset);
|
|
2529
|
+
}
|
|
2530
|
+
await this.ctx.api.storage.finalizeUpload.mutate({ uploadId });
|
|
2531
|
+
} catch (err) {
|
|
2532
|
+
try {
|
|
2533
|
+
await this.ctx.api.storage.abortUpload.mutate({ uploadId });
|
|
2534
|
+
} catch {}
|
|
2535
|
+
throw err;
|
|
2536
|
+
}
|
|
2537
|
+
const entry = buildArchiveEntry({
|
|
2538
|
+
id: input.archiveId,
|
|
2539
|
+
filename: input.archiveFilename,
|
|
2540
|
+
createdAt: input.createdAt,
|
|
2541
|
+
sizeBytes: input.sizeBytes,
|
|
2542
|
+
label: input.label,
|
|
2543
|
+
manifest: input.archiveManifest,
|
|
2544
|
+
...input.encryption !== void 0 ? { encryption: input.encryption } : {},
|
|
2545
|
+
databases: input.databases
|
|
2546
|
+
});
|
|
2547
|
+
await this.manifestLock.run(input.locationId, async () => {
|
|
2548
|
+
const { keep, drop } = applyRetention([...(await readLocationManifest(this.storageApi(), input.locationId)).archives, entry], input.retentionCount, retentionClassOf(entry));
|
|
2549
|
+
for (const stale of drop) try {
|
|
2550
|
+
await this.ctx.api.storage.delete.mutate({
|
|
2551
|
+
location: input.locationId,
|
|
2552
|
+
relativePath: stale.filename
|
|
2553
|
+
});
|
|
2554
|
+
} catch (err) {
|
|
2555
|
+
this.ctx.logger.warn("backup retention: storage delete failed (continuing)", { meta: {
|
|
2556
|
+
destinationId: input.locationId,
|
|
2557
|
+
backupId: stale.id,
|
|
2558
|
+
filename: stale.filename,
|
|
2559
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2560
|
+
} });
|
|
2561
|
+
}
|
|
2562
|
+
const next = {
|
|
2563
|
+
version: 1,
|
|
2564
|
+
archives: keep
|
|
2565
|
+
};
|
|
2566
|
+
await writeLocationManifest(this.storageApi(), input.locationId, next);
|
|
2567
|
+
});
|
|
2568
|
+
return {
|
|
2569
|
+
id: input.archiveId,
|
|
2570
|
+
destinationId: input.locationId,
|
|
2571
|
+
createdAt: input.createdAt,
|
|
2572
|
+
sizeBytes: input.sizeBytes,
|
|
2573
|
+
label: input.label,
|
|
2574
|
+
locations: [...input.archiveManifest.locations],
|
|
2575
|
+
...input.encryption !== void 0 ? { encryption: input.encryption } : {}
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* List archives at a single destination — newest-first. Reads only
|
|
2580
|
+
* the per-location `manifests.json` (no per-archive tarball read);
|
|
2581
|
+
* the orchestrator already snapshots each archive's locations into
|
|
2582
|
+
* the manifest at upload time.
|
|
2583
|
+
*/
|
|
2584
|
+
async listArchives(input) {
|
|
2585
|
+
let manifest;
|
|
2586
|
+
try {
|
|
2587
|
+
manifest = await readLocationManifest(this.storageApi(), input.destinationId);
|
|
2588
|
+
} catch (err) {
|
|
2589
|
+
this.ctx.logger.warn("backup listArchives: manifest read failed", { meta: {
|
|
2590
|
+
destinationId: input.destinationId,
|
|
2591
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2592
|
+
} });
|
|
2593
|
+
return [];
|
|
2594
|
+
}
|
|
2595
|
+
return [...manifest.archives].toSorted((a, b) => b.createdAt - a.createdAt).map((a) => ({
|
|
2596
|
+
id: a.id,
|
|
2597
|
+
filename: a.filename,
|
|
2598
|
+
createdAt: a.createdAt,
|
|
2599
|
+
sizeBytes: a.sizeBytes,
|
|
2600
|
+
...a.label !== void 0 ? { label: a.label } : {},
|
|
2601
|
+
locations: [...a.manifest.locations],
|
|
2602
|
+
...a.encryption !== void 0 ? { encryption: a.encryption } : {},
|
|
2603
|
+
...a.databases !== void 0 ? { databases: [...a.databases] } : {}
|
|
2604
|
+
}));
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Upsert the per-destination policy row. Used by the admin-UI
|
|
2608
|
+
* destinations table — toggle enabled / change retention / set
|
|
2609
|
+
* label. No-ops with a logged warning if the
|
|
2610
|
+
* settings backend lacks structured-table support (no persistence
|
|
2611
|
+
* available).
|
|
2612
|
+
*
|
|
2613
|
+
* There is deliberately NO cadence here. A destination does not run on
|
|
2614
|
+
* its own timer — a schedule fans out to it — and the `cron` this method
|
|
2615
|
+
* used to accept had scheduled nothing since 2026-07-28 while still being
|
|
2616
|
+
* rendered as "daily at 03:00" (D384, and D62's "a switch that writes a
|
|
2617
|
+
* store nobody reads").
|
|
2618
|
+
*/
|
|
2619
|
+
async upsertDestinationPolicy(input) {
|
|
2620
|
+
if (!this.policies) {
|
|
2621
|
+
this.ctx.logger.warn("backup upsertDestinationPolicy: no ctx.records — change will not persist", { meta: { locationId: input.locationId } });
|
|
2622
|
+
return;
|
|
2623
|
+
}
|
|
2624
|
+
const existing = await this.policies.get(input.locationId).catch(() => null);
|
|
2625
|
+
await this.policies.upsert({
|
|
2626
|
+
locationId: input.locationId,
|
|
2627
|
+
enabled: input.enabled,
|
|
2628
|
+
retentionCount: input.retentionCount,
|
|
2629
|
+
...input.label !== void 0 ? { label: input.label } : {},
|
|
2630
|
+
...existing?.lastAttemptAt !== void 0 ? { lastAttemptAt: existing.lastAttemptAt } : {},
|
|
2631
|
+
...existing?.lastError !== void 0 ? { lastError: existing.lastError } : {}
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
/**
|
|
2635
|
+
* Validate a cron expression and peek the next N firing times. The
|
|
2636
|
+
* admin UI's CronEditor calls this on every keystroke (debounced)
|
|
2637
|
+
* to render a live "next-run" preview — invalid expressions surface
|
|
2638
|
+
* the parse error inline instead of waiting for save.
|
|
2639
|
+
*/
|
|
2640
|
+
async previewSchedule(input) {
|
|
2641
|
+
const trimmed = input.cron.trim();
|
|
2642
|
+
if (trimmed.length === 0) return {
|
|
2643
|
+
ok: false,
|
|
2644
|
+
error: "Cron expression is empty",
|
|
2645
|
+
nextRuns: []
|
|
2646
|
+
};
|
|
2647
|
+
try {
|
|
2648
|
+
return {
|
|
2649
|
+
ok: true,
|
|
2650
|
+
nextRuns: previewNextRuns(trimmed, input.count ?? 5)
|
|
2651
|
+
};
|
|
2652
|
+
} catch (err) {
|
|
2653
|
+
return {
|
|
2654
|
+
ok: false,
|
|
2655
|
+
error: err instanceof Error ? err.message : "Invalid cron expression",
|
|
2656
|
+
nextRuns: []
|
|
2657
|
+
};
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
async getEntries(input) {
|
|
2661
|
+
try {
|
|
2662
|
+
return (await readLocationManifest(this.storageApi(), input.destinationId)).archives.find((a) => a.id === input.backupId)?.manifest ?? null;
|
|
2663
|
+
} catch (err) {
|
|
2664
|
+
this.ctx.logger.warn("backup getEntries: manifest read failed", { meta: {
|
|
2665
|
+
destinationId: input.destinationId,
|
|
2666
|
+
backupId: input.backupId,
|
|
2667
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2668
|
+
} });
|
|
2669
|
+
return null;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
async deleteArchive(input) {
|
|
2673
|
+
await this.manifestLock.run(input.destinationId, async () => {
|
|
2674
|
+
const manifest = await readLocationManifest(this.storageApi(), input.destinationId);
|
|
2675
|
+
const target = manifest.archives.find((a) => a.id === input.backupId);
|
|
2676
|
+
if (!target) throw new Error(`backup delete: backup "${input.backupId}" not found at "${input.destinationId}"`);
|
|
2677
|
+
try {
|
|
2678
|
+
await this.ctx.api.storage.delete.mutate({
|
|
2679
|
+
location: input.destinationId,
|
|
2680
|
+
relativePath: target.filename
|
|
2681
|
+
});
|
|
2682
|
+
} catch (err) {
|
|
2683
|
+
this.ctx.logger.warn("backup delete: storage delete failed (continuing manifest cleanup)", { meta: {
|
|
2684
|
+
destinationId: input.destinationId,
|
|
2685
|
+
filename: target.filename,
|
|
2686
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2687
|
+
} });
|
|
2688
|
+
}
|
|
2689
|
+
const next = {
|
|
2690
|
+
version: 1,
|
|
2691
|
+
archives: manifest.archives.filter((a) => a.id !== input.backupId)
|
|
2692
|
+
};
|
|
2693
|
+
await writeLocationManifest(this.storageApi(), input.destinationId, next);
|
|
2694
|
+
});
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* Schedule a restore for the next boot. Pulls the archive bytes
|
|
2698
|
+
* down from the destination's storage location via the chunked-
|
|
2699
|
+
* download protocol into the private staging dir, then writes the
|
|
2700
|
+
* usual restore marker against the staged path so the boot-time
|
|
2701
|
+
* apply hook (in server-backend launcher) extracts before any
|
|
2702
|
+
* addon starts.
|
|
2703
|
+
*
|
|
2704
|
+
* `locations` (optional) is propagated into the marker as a
|
|
2705
|
+
* whitelist — only those top-level locations get extracted.
|
|
2706
|
+
*/
|
|
2707
|
+
async scheduleRestore(input) {
|
|
2708
|
+
if (!this.systemBackup) throw new Error("orchestrator not initialized");
|
|
2709
|
+
const entry = (await readLocationManifest(this.storageApi(), input.destinationId)).archives.find((a) => a.id === input.backupId);
|
|
2710
|
+
if (!entry) throw new Error(`backup restore: backup "${input.backupId}" not found at location "${input.destinationId}"`);
|
|
2711
|
+
require_restore_archive.precheckRestoreKey(entry.encryption?.keyId, input.backupSecretKey);
|
|
2712
|
+
const downloaded = await this.stagingPath(`restore-${input.backupId}.download`);
|
|
2713
|
+
const cachePath = await this.stagingPath(`restore-${input.backupId}.tar.gz`);
|
|
2714
|
+
await downloadArchiveToCache({
|
|
2715
|
+
api: this.ctx.api.storage,
|
|
2716
|
+
locationId: input.destinationId,
|
|
2717
|
+
filename: entry.filename,
|
|
2718
|
+
cachePath: downloaded,
|
|
2719
|
+
chunkBytes: UPLOAD_CHUNK_BYTES,
|
|
2720
|
+
logger: this.ctx.logger
|
|
2721
|
+
});
|
|
2722
|
+
const prepared = await require_restore_archive.prepareRestoreArchive({
|
|
2723
|
+
downloaded,
|
|
2724
|
+
target: cachePath,
|
|
2725
|
+
...input.backupSecretKey !== void 0 ? { secretKey: input.backupSecretKey } : {}
|
|
2726
|
+
});
|
|
2727
|
+
if (prepared.encrypted) this.ctx.logger.info("backup restore: encrypted archive decrypted into staging", { meta: {
|
|
2728
|
+
backupId: input.backupId,
|
|
2729
|
+
keyId: prepared.keyId
|
|
2730
|
+
} });
|
|
2731
|
+
this.systemBackup.scheduleRestoreMarker({
|
|
2732
|
+
archivePath: cachePath,
|
|
2733
|
+
source: input.backupId,
|
|
2734
|
+
...input.locations ? { locations: input.locations } : {}
|
|
2735
|
+
});
|
|
2736
|
+
this.ctx.eventBus.emit({
|
|
2737
|
+
id: (0, node_crypto.randomUUID)(),
|
|
2738
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2739
|
+
source: {
|
|
2740
|
+
type: "addon",
|
|
2741
|
+
id: "backup-orchestrator"
|
|
2742
|
+
},
|
|
2743
|
+
category: require_dist.EventCategory.BackupRestored,
|
|
2744
|
+
data: {
|
|
2745
|
+
backupId: input.backupId,
|
|
2746
|
+
destinationId: input.destinationId
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
}
|
|
2750
|
+
requireEncryptionKeys() {
|
|
2751
|
+
if (this.encryptionKeys === null) throw new Error("backup encryption: no settings-store — the setting cannot be read or saved");
|
|
2752
|
+
return this.encryptionKeys;
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* The key a run encrypts to; `null` = encryption off. THROWS when the
|
|
2756
|
+
* setting cannot be read — a run must fail rather than ship a plain archive
|
|
2757
|
+
* an operator asked to be encrypted.
|
|
2758
|
+
*/
|
|
2759
|
+
async activeEncryptionKey() {
|
|
2760
|
+
const store = this.encryptionKeys;
|
|
2761
|
+
if (store === null) {
|
|
2762
|
+
if (!this.warnedNoEncryptionStore) {
|
|
2763
|
+
this.warnedNoEncryptionStore = true;
|
|
2764
|
+
this.ctx.logger.warn("backup encryption unavailable on this node (no settings-store) — archives are plain");
|
|
2765
|
+
}
|
|
2766
|
+
return null;
|
|
2767
|
+
}
|
|
2768
|
+
try {
|
|
2769
|
+
const active = await store.active();
|
|
2770
|
+
return active === null ? null : {
|
|
2771
|
+
keyId: active.keyId,
|
|
2772
|
+
publicKey: active.publicKey
|
|
2773
|
+
};
|
|
2774
|
+
} catch (err) {
|
|
2775
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2776
|
+
throw new Error(`backup encryption setting unreadable — no archive built, so none leaves unencrypted: ${message}`, { cause: err });
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
async getEncryption() {
|
|
2780
|
+
const keys = await this.requireEncryptionKeys().list();
|
|
2781
|
+
const active = keys.find((k) => k.retiredAt === null) ?? null;
|
|
2782
|
+
return {
|
|
2783
|
+
enabled: active !== null,
|
|
2784
|
+
active: active === null ? null : {
|
|
2785
|
+
keyId: active.keyId,
|
|
2786
|
+
publicKey: active.publicKey,
|
|
2787
|
+
createdAt: active.createdAt
|
|
2788
|
+
},
|
|
2789
|
+
keys: keys.map((k) => ({
|
|
2790
|
+
keyId: k.keyId,
|
|
2791
|
+
createdAt: k.createdAt,
|
|
2792
|
+
retiredAt: k.retiredAt
|
|
2793
|
+
}))
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
async setupEncryption() {
|
|
2797
|
+
const store = this.requireEncryptionKeys();
|
|
2798
|
+
const previous = await store.active();
|
|
2799
|
+
const pair = require_restore_archive.generateBackupKeyPair();
|
|
2800
|
+
const record = await store.activate({ publicKey: pair.publicKey });
|
|
2801
|
+
this.ctx.logger.warn("backup encryption key generated — new archives are encrypted to it", { meta: {
|
|
2802
|
+
keyId: record.keyId,
|
|
2803
|
+
replacedKeyId: previous?.keyId ?? null
|
|
2804
|
+
} });
|
|
2805
|
+
return {
|
|
2806
|
+
keyId: record.keyId,
|
|
2807
|
+
secretKey: pair.secretKey,
|
|
2808
|
+
publicKey: record.publicKey,
|
|
2809
|
+
createdAt: record.createdAt,
|
|
2810
|
+
replacedKeyId: previous?.keyId ?? null
|
|
2811
|
+
};
|
|
2812
|
+
}
|
|
2813
|
+
async disableEncryption() {
|
|
2814
|
+
const store = this.requireEncryptionKeys();
|
|
2815
|
+
const previous = await store.active();
|
|
2816
|
+
await store.disable();
|
|
2817
|
+
if (previous !== null) this.ctx.logger.warn("backup encryption turned OFF — new archives are plain", { meta: { disabledKeyId: previous.keyId } });
|
|
2818
|
+
return { disabledKeyId: previous?.keyId ?? null };
|
|
2819
|
+
}
|
|
2820
|
+
async checkBackupKey(input) {
|
|
2821
|
+
let keyId;
|
|
2822
|
+
try {
|
|
2823
|
+
keyId = require_restore_archive.parseBackupSecretKey(input.backupSecretKey).keyId;
|
|
2824
|
+
} catch (err) {
|
|
2825
|
+
if (!(err instanceof require_restore_archive.BackupKeyFormatError)) throw err;
|
|
2826
|
+
return {
|
|
2827
|
+
valid: false,
|
|
2828
|
+
keyId: null,
|
|
2829
|
+
known: false,
|
|
2830
|
+
active: false,
|
|
2831
|
+
error: err.message
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
const match = (await this.requireEncryptionKeys().list()).find((k) => k.keyId === keyId);
|
|
2835
|
+
return {
|
|
2836
|
+
valid: true,
|
|
2837
|
+
keyId,
|
|
2838
|
+
known: match !== void 0,
|
|
2839
|
+
active: match !== void 0 && match.retiredAt === null
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* Resolve a target destination set — see {@link selectBackupTargets} for the
|
|
2844
|
+
* rule. Caller-provided list wins over the per-destination policy flag;
|
|
2845
|
+
* NEITHER wins over `StorageLocation.enabled`, which is the operator's
|
|
2846
|
+
* switch on the storage screen and the only one that means "this disk takes
|
|
2847
|
+
* no writes" (D62).
|
|
2848
|
+
*
|
|
2849
|
+
* Reads locations + policies directly rather than going through
|
|
2850
|
+
* `listDestinations()`: that method also reads every destination's
|
|
2851
|
+
* `manifests.json` to hydrate `lastSuccess`, which target resolution has no
|
|
2852
|
+
* use for and which cost one round-trip per destination on every trigger.
|
|
2853
|
+
*/
|
|
2854
|
+
async resolveTargets(requested) {
|
|
2855
|
+
const locations = await this.fetchBackupLocations();
|
|
2856
|
+
const policies = await this.loadPoliciesIndexed(locations.map((l) => l.id));
|
|
2857
|
+
const selection = selectBackupTargets({
|
|
2858
|
+
candidates: locations.map((l) => ({
|
|
2859
|
+
id: l.id,
|
|
2860
|
+
locationEnabled: require_dist.mayWriteToLocation(l),
|
|
2861
|
+
policyEnabled: (policies.get(l.id) ?? this.fallbackPolicy(l.id)).enabled
|
|
2862
|
+
})),
|
|
2863
|
+
...requested && requested.length > 0 ? { requested: [...requested] } : {}
|
|
2864
|
+
});
|
|
2865
|
+
if (selection.skippedDisabled.length > 0) this.ctx.logger.warn("backup: destination skipped — its storage location is disabled by the operator", { meta: {
|
|
2866
|
+
destinationIds: [...selection.skippedDisabled],
|
|
2867
|
+
requestedExplicitly: requested !== void 0 && requested.length > 0
|
|
2868
|
+
} });
|
|
2869
|
+
if (selection.targets.length === 0 && selection.skippedDisabled.length > 0) throw new Error(`every selected backup destination is disabled (${selection.skippedDisabled.join(", ")}) — enable its storage location on the Storage screen, or choose another destination. Refusing to write an archive to a location the operator turned off.`);
|
|
2870
|
+
return selection.targets.map((t) => ({ id: t.id }));
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* Persist the outcome of one attempted write to one destination.
|
|
2874
|
+
*
|
|
2875
|
+
* Best-effort by design: an unavailable settings backend must not turn a
|
|
2876
|
+
* successful backup into a failed one. But it is LOGGED when it cannot be
|
|
2877
|
+
* written — a status field that silently stops being updated is the whole
|
|
2878
|
+
* defect this method exists to close.
|
|
2879
|
+
*/
|
|
2880
|
+
async recordDestinationOutcome(destinationId, attemptAt, error) {
|
|
2881
|
+
if (!this.policies) return;
|
|
2882
|
+
try {
|
|
2883
|
+
await this.policies.recordAttempt(destinationId, {
|
|
2884
|
+
attemptAt,
|
|
2885
|
+
...error !== void 0 ? { error } : {}
|
|
2886
|
+
}, { retentionCount: DEFAULT_RETENTION_COUNT });
|
|
2887
|
+
} catch (err) {
|
|
2888
|
+
this.ctx.logger.warn("backup: could not persist the destination outcome", { meta: {
|
|
2889
|
+
destinationId,
|
|
2890
|
+
outcome: error === void 0 ? "succeeded" : "failed",
|
|
2891
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2892
|
+
} });
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
startScheduleTimer() {
|
|
2896
|
+
if (this.scheduleTimer) return;
|
|
2897
|
+
this.scheduleTimer = setInterval(() => {
|
|
2898
|
+
this.onScheduleTick();
|
|
2899
|
+
}, SCHEDULE_TICK_MS);
|
|
2900
|
+
}
|
|
2901
|
+
stopScheduleTimer() {
|
|
2902
|
+
if (!this.scheduleTimer) return;
|
|
2903
|
+
clearInterval(this.scheduleTimer);
|
|
2904
|
+
this.scheduleTimer = null;
|
|
2905
|
+
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Schedule-driven backup scheduling. Walks every enabled backup
|
|
2908
|
+
* SCHEDULE (the N:M entry), computes the next due time after
|
|
2909
|
+
* `lastAttemptAt` (or the orchestrator's first-tick baseline if never
|
|
2910
|
+
* run), and fires a SINGLE archive fanned out to ALL of the
|
|
2911
|
+
* schedule's `locationIds` when due — with the schedule's per-entry
|
|
2912
|
+
* retention applied to each. Each schedule keeps its own cadence.
|
|
2913
|
+
*
|
|
2914
|
+
* Errors per schedule are isolated; one misconfigured cron doesn't
|
|
2915
|
+
* block the others. The schedule's `lastAttemptAt` is updated BEFORE the
|
|
2916
|
+
* trigger to dedupe (the tick runs every SCHEDULE_TICK_MS — without
|
|
2917
|
+
* the up-front update a long-running upload could overlap with the
|
|
2918
|
+
* next tick's same-due check).
|
|
2919
|
+
*/
|
|
2920
|
+
async onScheduleTick() {
|
|
2921
|
+
if (!this.schedules) {
|
|
2922
|
+
if (!this.warnedSchedulerDisarmed) {
|
|
2923
|
+
this.warnedSchedulerDisarmed = true;
|
|
2924
|
+
this.ctx.logger.error("backup scheduler is DISARMED — no settings backend, so no schedule can fire");
|
|
2925
|
+
}
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2928
|
+
const schedules = await this.schedules.list();
|
|
2929
|
+
const now = Date.now();
|
|
2930
|
+
for (const s of schedules) {
|
|
2931
|
+
if (!s.enabled || !s.cron || s.cron.trim().length === 0) continue;
|
|
2932
|
+
if (s.locationIds.length === 0) continue;
|
|
2933
|
+
let due;
|
|
2934
|
+
try {
|
|
2935
|
+
due = computeNextDue(s.cron, s.lastAttemptAt ?? this.scheduleBaselineAt);
|
|
2936
|
+
} catch (err) {
|
|
2937
|
+
this.ctx.logger.warn("Invalid cron — skipping schedule", { meta: {
|
|
2938
|
+
scheduleId: s.id,
|
|
2939
|
+
cron: s.cron,
|
|
2940
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2941
|
+
} });
|
|
2942
|
+
continue;
|
|
2943
|
+
}
|
|
2944
|
+
if (due === null || due > now) continue;
|
|
2945
|
+
const stamped = {
|
|
2946
|
+
...s,
|
|
2947
|
+
lastAttemptAt: now
|
|
2948
|
+
};
|
|
2949
|
+
try {
|
|
2950
|
+
await this.schedules.upsert(stamped);
|
|
2951
|
+
} catch (err) {
|
|
2952
|
+
this.ctx.logger.warn("Failed to persist scheduled-run timestamp", { meta: {
|
|
2953
|
+
scheduleId: s.id,
|
|
2954
|
+
scheduleLabel: s.label,
|
|
2955
|
+
destinationIds: [...s.locationIds],
|
|
2956
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2957
|
+
} });
|
|
2958
|
+
}
|
|
2959
|
+
this.ctx.logger.info("Scheduled backup firing", { meta: {
|
|
2960
|
+
scheduleId: s.id,
|
|
2961
|
+
label: s.label,
|
|
2962
|
+
destinationIds: [...s.locationIds],
|
|
2963
|
+
cron: s.cron,
|
|
2964
|
+
dueAt: due
|
|
2965
|
+
} });
|
|
2966
|
+
await this.runScheduledBackup(stamped, now);
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
/**
|
|
2970
|
+
* A schedule that asks for events/history while the owner has neither open
|
|
2971
|
+
* would only repeat the nightly archive (D852: the weekly schedule has
|
|
2972
|
+
* nothing to carry until those files exist). Said on the record, no archive
|
|
2973
|
+
* built, no outcome stamped. An owner that cannot answer never skips: the
|
|
2974
|
+
* run goes ahead and fails — or succeeds — in the open.
|
|
2975
|
+
*/
|
|
2976
|
+
async nothingToCarry(schedule) {
|
|
2977
|
+
const requested = databasesOfSchedule(schedule);
|
|
2978
|
+
if (!requested.some((id) => id !== "settings")) return false;
|
|
2979
|
+
let owned;
|
|
2980
|
+
try {
|
|
2981
|
+
owned = (await this.databaseOwner().listDatabases()).map((d) => d.databaseId);
|
|
2982
|
+
} catch (err) {
|
|
2983
|
+
this.ctx.logger.warn("Scheduled backup: the database owner did not answer — running anyway", { meta: {
|
|
2984
|
+
scheduleId: schedule.id,
|
|
2985
|
+
label: schedule.label,
|
|
2986
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2987
|
+
} });
|
|
2988
|
+
return false;
|
|
2989
|
+
}
|
|
2990
|
+
if (!hasNothingBeyondSettings(requested, owned)) return false;
|
|
2991
|
+
this.ctx.logger.info("Scheduled backup skipped — no database it carries exists yet", { meta: {
|
|
2992
|
+
scheduleId: schedule.id,
|
|
2993
|
+
label: schedule.label,
|
|
2994
|
+
requested: [...requested],
|
|
2995
|
+
owned
|
|
2996
|
+
} });
|
|
2997
|
+
return true;
|
|
2998
|
+
}
|
|
2999
|
+
/**
|
|
3000
|
+
* Seed the weekly "events & history" schedule (D852) — once, and never over
|
|
3001
|
+
* anything the operator has: see `planWeeklySeed`.
|
|
3002
|
+
*/
|
|
3003
|
+
async seedWeekly() {
|
|
3004
|
+
const markers = this.backupRecords?.seedMarkers;
|
|
3005
|
+
if (!this.schedules || markers === void 0) return;
|
|
3006
|
+
try {
|
|
3007
|
+
const seed = await seedWeeklySchedule(this.schedules, new BackupSeedMarkerStore(markers));
|
|
3008
|
+
if (seed === null) return;
|
|
3009
|
+
this.ctx.logger.info("backup: seeded the weekly events & history schedule", { meta: {
|
|
3010
|
+
scheduleId: seed.id,
|
|
3011
|
+
destinationIds: [...seed.locationIds]
|
|
3012
|
+
} });
|
|
3013
|
+
} catch (err) {
|
|
3014
|
+
this.ctx.logger.warn("backup: the weekly schedule could not be seeded", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Fire one schedule and RECORD what happened to it, naming every
|
|
3019
|
+
* destination. Three outcomes, three different persisted states —
|
|
3020
|
+
* because "fired" and "backed up" were the same field until D384:
|
|
3021
|
+
*
|
|
3022
|
+
* - archive landed somewhere → `lastSuccessAt`, `lastError` cleared;
|
|
3023
|
+
* - the run threw, or landed nowhere → `lastError`, no success stamp;
|
|
3024
|
+
* - the stamp could not be written → logged, named, not swallowed.
|
|
3025
|
+
*/
|
|
3026
|
+
async runScheduledBackup(schedule, firedAt) {
|
|
3027
|
+
const destinationIds = [...schedule.locationIds];
|
|
3028
|
+
if (await this.nothingToCarry(schedule)) return;
|
|
3029
|
+
let failure;
|
|
3030
|
+
try {
|
|
3031
|
+
const result = await this.triggerBackup({
|
|
3032
|
+
destinations: destinationIds,
|
|
3033
|
+
...schedule.dataSources && schedule.dataSources.length > 0 ? { locations: [...schedule.dataSources] } : {},
|
|
3034
|
+
label: schedule.label,
|
|
3035
|
+
retentionCount: schedule.retentionCount,
|
|
3036
|
+
...schedule.databases ? { databases: [...schedule.databases] } : {}
|
|
3037
|
+
});
|
|
3038
|
+
if (result.entries.length === 0 && !result.cancelled) failure = `no destination accepted the archive (${destinationIds.join(", ")})`;
|
|
3039
|
+
} catch (err) {
|
|
3040
|
+
failure = err instanceof Error ? err.message : String(err);
|
|
3041
|
+
}
|
|
3042
|
+
if (failure === void 0) this.ctx.logger.info("Scheduled backup completed", { meta: {
|
|
3043
|
+
scheduleId: schedule.id,
|
|
3044
|
+
label: schedule.label,
|
|
3045
|
+
destinationIds
|
|
3046
|
+
} });
|
|
3047
|
+
else this.ctx.logger.error("Scheduled backup failed", { meta: {
|
|
3048
|
+
scheduleId: schedule.id,
|
|
3049
|
+
label: schedule.label,
|
|
3050
|
+
destinationIds,
|
|
3051
|
+
error: failure
|
|
3052
|
+
} });
|
|
3053
|
+
if (!this.schedules) return;
|
|
3054
|
+
const { lastError: _cleared, ...carried } = schedule;
|
|
3055
|
+
try {
|
|
3056
|
+
await this.schedules.upsert({
|
|
3057
|
+
...carried,
|
|
3058
|
+
...failure === void 0 ? { lastSuccessAt: firedAt } : { lastError: failure }
|
|
3059
|
+
});
|
|
3060
|
+
} catch (err) {
|
|
3061
|
+
this.ctx.logger.warn("Failed to persist the scheduled-run outcome", { meta: {
|
|
3062
|
+
scheduleId: schedule.id,
|
|
3063
|
+
label: schedule.label,
|
|
3064
|
+
destinationIds,
|
|
3065
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3066
|
+
} });
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
3070
|
+
* The database files the owner has open right now, for the selection UI. An
|
|
3071
|
+
* owner that cannot answer is `answered: false` — never an empty list, which
|
|
3072
|
+
* the UI would read as "none exists yet".
|
|
3073
|
+
*/
|
|
3074
|
+
async listAvailableDatabases() {
|
|
3075
|
+
try {
|
|
3076
|
+
return {
|
|
3077
|
+
answered: true,
|
|
3078
|
+
databases: (await this.databaseOwner().listDatabases()).map((d) => d.databaseId)
|
|
3079
|
+
};
|
|
3080
|
+
} catch (err) {
|
|
3081
|
+
this.ctx.logger.warn("Backup database list: the database owner did not answer", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
3082
|
+
return {
|
|
3083
|
+
answered: false,
|
|
3084
|
+
databases: []
|
|
3085
|
+
};
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
async listSchedules() {
|
|
3089
|
+
if (!this.schedules) return [];
|
|
3090
|
+
return (await this.schedules.list()).map((s) => {
|
|
3091
|
+
let nextRunAt;
|
|
3092
|
+
if (s.enabled && s.cron.trim().length > 0) try {
|
|
3093
|
+
const next = computeNextDue(s.cron, Date.now());
|
|
3094
|
+
if (next !== null) nextRunAt = next;
|
|
3095
|
+
} catch {}
|
|
3096
|
+
return {
|
|
3097
|
+
id: s.id,
|
|
3098
|
+
label: s.label,
|
|
3099
|
+
cron: s.cron,
|
|
3100
|
+
enabled: s.enabled,
|
|
3101
|
+
locationIds: [...s.locationIds],
|
|
3102
|
+
retentionCount: s.retentionCount,
|
|
3103
|
+
...s.dataSources !== void 0 ? { dataSources: [...s.dataSources] } : {},
|
|
3104
|
+
...s.databases !== void 0 ? { databases: [...s.databases] } : {},
|
|
3105
|
+
...s.lastAttemptAt !== void 0 ? { lastAttemptAt: s.lastAttemptAt } : {},
|
|
3106
|
+
...s.lastSuccessAt !== void 0 ? { lastSuccessAt: s.lastSuccessAt } : {},
|
|
3107
|
+
...s.lastError !== void 0 ? { lastError: s.lastError } : {},
|
|
3108
|
+
...nextRunAt !== void 0 ? { nextRunAt } : {}
|
|
3109
|
+
};
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
async upsertSchedule(input) {
|
|
3113
|
+
if (!this.schedules) throw new Error("backup upsertSchedule: no ctx.records — schedule cannot be persisted");
|
|
3114
|
+
const cron = input.cron.trim();
|
|
3115
|
+
if (cron.length > 0 && !isValidCron(cron)) throw new Error(`Invalid cron expression: "${cron}"`);
|
|
3116
|
+
const id = input.id && input.id.length > 0 ? input.id : (0, node_crypto.randomUUID)();
|
|
3117
|
+
const existing = await this.schedules.get(id).catch(() => null);
|
|
3118
|
+
const next = {
|
|
3119
|
+
id,
|
|
3120
|
+
label: input.label,
|
|
3121
|
+
cron,
|
|
3122
|
+
enabled: input.enabled,
|
|
3123
|
+
locationIds: [...input.locationIds],
|
|
3124
|
+
retentionCount: input.retentionCount,
|
|
3125
|
+
...input.dataSources && input.dataSources.length > 0 ? { dataSources: [...input.dataSources] } : {},
|
|
3126
|
+
...input.databases && input.databases.length > 0 ? { databases: [...input.databases] } : {},
|
|
3127
|
+
...existing?.lastAttemptAt !== void 0 ? { lastAttemptAt: existing.lastAttemptAt } : {},
|
|
3128
|
+
...existing?.lastSuccessAt !== void 0 ? { lastSuccessAt: existing.lastSuccessAt } : {},
|
|
3129
|
+
...existing?.lastError !== void 0 ? { lastError: existing.lastError } : {}
|
|
3130
|
+
};
|
|
3131
|
+
await this.schedules.upsert(next);
|
|
3132
|
+
let nextRunAt;
|
|
3133
|
+
if (next.enabled && cron.length > 0) try {
|
|
3134
|
+
const due = computeNextDue(cron, Date.now());
|
|
3135
|
+
if (due !== null) nextRunAt = due;
|
|
3136
|
+
} catch {}
|
|
3137
|
+
return {
|
|
3138
|
+
id: next.id,
|
|
3139
|
+
label: next.label,
|
|
3140
|
+
cron: next.cron,
|
|
3141
|
+
enabled: next.enabled,
|
|
3142
|
+
locationIds: [...next.locationIds],
|
|
3143
|
+
retentionCount: next.retentionCount,
|
|
3144
|
+
...next.dataSources !== void 0 ? { dataSources: [...next.dataSources] } : {},
|
|
3145
|
+
...next.databases !== void 0 ? { databases: [...next.databases] } : {},
|
|
3146
|
+
...next.lastAttemptAt !== void 0 ? { lastAttemptAt: next.lastAttemptAt } : {},
|
|
3147
|
+
...next.lastSuccessAt !== void 0 ? { lastSuccessAt: next.lastSuccessAt } : {},
|
|
3148
|
+
...next.lastError !== void 0 ? { lastError: next.lastError } : {},
|
|
3149
|
+
...nextRunAt !== void 0 ? { nextRunAt } : {}
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
async deleteSchedule(input) {
|
|
3153
|
+
if (!this.schedules) return;
|
|
3154
|
+
await this.schedules.delete(input.id);
|
|
3155
|
+
}
|
|
3156
|
+
/**
|
|
3157
|
+
* Narrow `ctx.api.storage` to the subset the manifest helpers need.
|
|
3158
|
+
* Lets the helpers be unit-tested with a Map-backed fake without
|
|
3159
|
+
* pulling in the full `AddonApi` shape.
|
|
3160
|
+
*/
|
|
3161
|
+
storageApi() {
|
|
3162
|
+
return this.ctx.api.storage;
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
/**
|
|
3166
|
+
* Map a `storage-provider` providerId to an operator-friendly `kind`
|
|
3167
|
+
* the admin UI uses for destination cards. Falls back to the raw
|
|
3168
|
+
* provider id so unknown providers still surface (operator sees
|
|
3169
|
+
* `webdav-storage` instead of a blank slot).
|
|
3170
|
+
*/
|
|
3171
|
+
function kindFromProviderId(providerId) {
|
|
3172
|
+
switch (providerId) {
|
|
3173
|
+
case "filesystem-storage": return "local";
|
|
3174
|
+
case "s3-storage": return "s3";
|
|
3175
|
+
case "sftp-storage": return "sftp";
|
|
3176
|
+
case "webdav-storage": return "webdav";
|
|
3177
|
+
default: return providerId;
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Extract the slug part of a `<type>:<slug>` storage-location id.
|
|
3182
|
+
* Defensive: if the id doesn't contain a colon (shouldn't happen given
|
|
3183
|
+
* the regex on `StorageLocationSchema.id`) we return the whole string.
|
|
3184
|
+
*/
|
|
3185
|
+
function extractSlug(id) {
|
|
3186
|
+
const colon = id.indexOf(":");
|
|
3187
|
+
return colon < 0 ? id : id.slice(colon + 1);
|
|
3188
|
+
}
|
|
3189
|
+
/**
|
|
3190
|
+
* Narrow a `for await` chunk from `fs.createReadStream` to a
|
|
3191
|
+
* `Buffer`. The stream yields `string | Buffer` per its public type
|
|
3192
|
+
* even though the no-encoding overload always emits `Buffer`. The
|
|
3193
|
+
* runtime check + clear error keeps eslint's no-unsafe-* rules happy
|
|
3194
|
+
* without resorting to `as Buffer`.
|
|
3195
|
+
*/
|
|
3196
|
+
function toBufferChunk(value) {
|
|
3197
|
+
if (Buffer.isBuffer(value)) return value;
|
|
3198
|
+
if (value instanceof Uint8Array) return value;
|
|
3199
|
+
throw new Error("backup upload: unexpected non-binary chunk from read stream");
|
|
3200
|
+
}
|
|
3201
|
+
/**
|
|
3202
|
+
* Return the most-recent archive in a location manifest, or undefined
|
|
3203
|
+
* when the location has no archives yet. Pure transform — no I/O.
|
|
3204
|
+
*/
|
|
3205
|
+
function latestArchiveOf(manifest) {
|
|
3206
|
+
if (manifest.archives.length === 0) return void 0;
|
|
3207
|
+
let newest = manifest.archives[0];
|
|
3208
|
+
for (const a of manifest.archives) if (a.createdAt > newest.createdAt) newest = a;
|
|
3209
|
+
return newest;
|
|
3210
|
+
}
|
|
3211
|
+
//#endregion
|
|
3212
|
+
exports.BackupOrchestratorAddon = BackupOrchestratorAddon;
|
|
3213
|
+
exports.default = BackupOrchestratorAddon;
|