@dotdo/postgres 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +868 -0
- package/dist/cdc/change-stream.d.ts +44 -0
- package/dist/cdc/change-stream.d.ts.map +1 -0
- package/dist/cdc/change-stream.js +95 -0
- package/dist/cdc/change-stream.js.map +1 -0
- package/dist/cdc/filter.d.ts +58 -0
- package/dist/cdc/filter.d.ts.map +1 -0
- package/dist/cdc/filter.js +520 -0
- package/dist/cdc/filter.js.map +1 -0
- package/dist/cdc/index.d.ts +47 -0
- package/dist/cdc/index.d.ts.map +1 -0
- package/dist/cdc/index.js +50 -0
- package/dist/cdc/index.js.map +1 -0
- package/dist/cdc/resume-token.d.ts +60 -0
- package/dist/cdc/resume-token.d.ts.map +1 -0
- package/dist/cdc/resume-token.js +228 -0
- package/dist/cdc/resume-token.js.map +1 -0
- package/dist/cdc/transport/index.d.ts +7 -0
- package/dist/cdc/transport/index.d.ts.map +1 -0
- package/dist/cdc/transport/index.js +7 -0
- package/dist/cdc/transport/index.js.map +1 -0
- package/dist/cdc/transport/sse.d.ts +120 -0
- package/dist/cdc/transport/sse.d.ts.map +1 -0
- package/dist/cdc/transport/sse.js +590 -0
- package/dist/cdc/transport/sse.js.map +1 -0
- package/dist/cdc/transport/websocket.d.ts +130 -0
- package/dist/cdc/transport/websocket.d.ts.map +1 -0
- package/dist/cdc/transport/websocket.js +688 -0
- package/dist/cdc/transport/websocket.js.map +1 -0
- package/dist/cdc/types.d.ts +306 -0
- package/dist/cdc/types.d.ts.map +1 -0
- package/dist/cdc/types.js +8 -0
- package/dist/cdc/types.js.map +1 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +25 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/memory.d.ts +139 -0
- package/dist/config/memory.d.ts.map +1 -0
- package/dist/config/memory.js +157 -0
- package/dist/config/memory.js.map +1 -0
- package/dist/config/storage.d.ts +157 -0
- package/dist/config/storage.d.ts.map +1 -0
- package/dist/config/storage.js +178 -0
- package/dist/config/storage.js.map +1 -0
- package/dist/config/streaming.d.ts +117 -0
- package/dist/config/streaming.d.ts.map +1 -0
- package/dist/config/streaming.js +132 -0
- package/dist/config/streaming.js.map +1 -0
- package/dist/config/timeouts.d.ts +168 -0
- package/dist/config/timeouts.d.ts.map +1 -0
- package/dist/config/timeouts.js +192 -0
- package/dist/config/timeouts.js.map +1 -0
- package/dist/extensions/config.d.ts +89 -0
- package/dist/extensions/config.d.ts.map +1 -0
- package/dist/extensions/config.js +216 -0
- package/dist/extensions/config.js.map +1 -0
- package/dist/extensions/geo.d.ts +452 -0
- package/dist/extensions/geo.d.ts.map +1 -0
- package/dist/extensions/geo.js +583 -0
- package/dist/extensions/geo.js.map +1 -0
- package/dist/extensions/index.d.ts +167 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +99 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/loader.d.ts +226 -0
- package/dist/extensions/loader.d.ts.map +1 -0
- package/dist/extensions/loader.js +456 -0
- package/dist/extensions/loader.js.map +1 -0
- package/dist/extensions/pgmq-lite.d.ts +330 -0
- package/dist/extensions/pgmq-lite.d.ts.map +1 -0
- package/dist/extensions/pgmq-lite.js +648 -0
- package/dist/extensions/pgmq-lite.js.map +1 -0
- package/dist/extensions/plugins.d.ts +260 -0
- package/dist/extensions/plugins.d.ts.map +1 -0
- package/dist/extensions/plugins.js +535 -0
- package/dist/extensions/plugins.js.map +1 -0
- package/dist/extensions/registry.d.ts +93 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/extensions/registry.js +182 -0
- package/dist/extensions/registry.js.map +1 -0
- package/dist/extensions/vector.d.ts +106 -0
- package/dist/extensions/vector.d.ts.map +1 -0
- package/dist/extensions/vector.js +129 -0
- package/dist/extensions/vector.js.map +1 -0
- package/dist/iceberg/analytics.d.ts +279 -0
- package/dist/iceberg/analytics.d.ts.map +1 -0
- package/dist/iceberg/analytics.js +448 -0
- package/dist/iceberg/analytics.js.map +1 -0
- package/dist/iceberg/catalog-api.d.ts +39 -0
- package/dist/iceberg/catalog-api.d.ts.map +1 -0
- package/dist/iceberg/catalog-api.js +388 -0
- package/dist/iceberg/catalog-api.js.map +1 -0
- package/dist/iceberg/catalog.d.ts +401 -0
- package/dist/iceberg/catalog.d.ts.map +1 -0
- package/dist/iceberg/catalog.js +677 -0
- package/dist/iceberg/catalog.js.map +1 -0
- package/dist/iceberg/duckdb-wasm.d.ts +447 -0
- package/dist/iceberg/duckdb-wasm.d.ts.map +1 -0
- package/dist/iceberg/duckdb-wasm.js +600 -0
- package/dist/iceberg/duckdb-wasm.js.map +1 -0
- package/dist/iceberg/index.d.ts +92 -0
- package/dist/iceberg/index.d.ts.map +1 -0
- package/dist/iceberg/index.js +119 -0
- package/dist/iceberg/index.js.map +1 -0
- package/dist/iceberg/metadata.d.ts +214 -0
- package/dist/iceberg/metadata.d.ts.map +1 -0
- package/dist/iceberg/metadata.js +535 -0
- package/dist/iceberg/metadata.js.map +1 -0
- package/dist/iceberg/optimizer.d.ts +296 -0
- package/dist/iceberg/optimizer.d.ts.map +1 -0
- package/dist/iceberg/optimizer.js +889 -0
- package/dist/iceberg/optimizer.js.map +1 -0
- package/dist/iceberg/parquet.d.ts +447 -0
- package/dist/iceberg/parquet.d.ts.map +1 -0
- package/dist/iceberg/parquet.js +1225 -0
- package/dist/iceberg/parquet.js.map +1 -0
- package/dist/iceberg/r2-organization.d.ts +422 -0
- package/dist/iceberg/r2-organization.d.ts.map +1 -0
- package/dist/iceberg/r2-organization.js +672 -0
- package/dist/iceberg/r2-organization.js.map +1 -0
- package/dist/iceberg/scheduler-do-example.d.ts +158 -0
- package/dist/iceberg/scheduler-do-example.d.ts.map +1 -0
- package/dist/iceberg/scheduler-do-example.js +261 -0
- package/dist/iceberg/scheduler-do-example.js.map +1 -0
- package/dist/iceberg/scheduler.d.ts +434 -0
- package/dist/iceberg/scheduler.d.ts.map +1 -0
- package/dist/iceberg/scheduler.js +818 -0
- package/dist/iceberg/scheduler.js.map +1 -0
- package/dist/iceberg/schema.d.ts +149 -0
- package/dist/iceberg/schema.d.ts.map +1 -0
- package/dist/iceberg/schema.js +525 -0
- package/dist/iceberg/schema.js.map +1 -0
- package/dist/iceberg/snapshot-manager.d.ts +406 -0
- package/dist/iceberg/snapshot-manager.d.ts.map +1 -0
- package/dist/iceberg/snapshot-manager.js +934 -0
- package/dist/iceberg/snapshot-manager.js.map +1 -0
- package/dist/iceberg/sql-router.d.ts +194 -0
- package/dist/iceberg/sql-router.d.ts.map +1 -0
- package/dist/iceberg/sql-router.js +180 -0
- package/dist/iceberg/sql-router.js.map +1 -0
- package/dist/iceberg/test-fixtures.d.ts +151 -0
- package/dist/iceberg/test-fixtures.d.ts.map +1 -0
- package/dist/iceberg/test-fixtures.js +446 -0
- package/dist/iceberg/test-fixtures.js.map +1 -0
- package/dist/iceberg/time-travel-api.d.ts +102 -0
- package/dist/iceberg/time-travel-api.d.ts.map +1 -0
- package/dist/iceberg/time-travel-api.js +437 -0
- package/dist/iceberg/time-travel-api.js.map +1 -0
- package/dist/iceberg/time-travel.d.ts +293 -0
- package/dist/iceberg/time-travel.d.ts.map +1 -0
- package/dist/iceberg/time-travel.js +689 -0
- package/dist/iceberg/time-travel.js.map +1 -0
- package/dist/iceberg/transformer.d.ts +356 -0
- package/dist/iceberg/transformer.d.ts.map +1 -0
- package/dist/iceberg/transformer.js +770 -0
- package/dist/iceberg/transformer.js.map +1 -0
- package/dist/iceberg/types.d.ts +318 -0
- package/dist/iceberg/types.d.ts.map +1 -0
- package/dist/iceberg/types.js +9 -0
- package/dist/iceberg/types.js.map +1 -0
- package/dist/iceberg/writer.d.ts +144 -0
- package/dist/iceberg/writer.d.ts.map +1 -0
- package/dist/iceberg/writer.js +452 -0
- package/dist/iceberg/writer.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/lineage/index.d.ts +11 -0
- package/dist/lineage/index.d.ts.map +1 -0
- package/dist/lineage/index.js +11 -0
- package/dist/lineage/index.js.map +1 -0
- package/dist/lineage/integration.d.ts +134 -0
- package/dist/lineage/integration.d.ts.map +1 -0
- package/dist/lineage/integration.js +258 -0
- package/dist/lineage/integration.js.map +1 -0
- package/dist/lineage/tracker.d.ts +189 -0
- package/dist/lineage/tracker.d.ts.map +1 -0
- package/dist/lineage/tracker.js +1352 -0
- package/dist/lineage/tracker.js.map +1 -0
- package/dist/lineage/types.d.ts +318 -0
- package/dist/lineage/types.d.ts.map +1 -0
- package/dist/lineage/types.js +9 -0
- package/dist/lineage/types.js.map +1 -0
- package/dist/middleware/index.d.ts +11 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +16 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +397 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/middleware/rate-limit.js +507 -0
- package/dist/middleware/rate-limit.js.map +1 -0
- package/dist/migration-tooling/external-migration.d.ts +601 -0
- package/dist/migration-tooling/external-migration.d.ts.map +1 -0
- package/dist/migration-tooling/external-migration.js +1612 -0
- package/dist/migration-tooling/external-migration.js.map +1 -0
- package/dist/migration-tooling/index.d.ts +19 -0
- package/dist/migration-tooling/index.d.ts.map +1 -0
- package/dist/migration-tooling/index.js +19 -0
- package/dist/migration-tooling/index.js.map +1 -0
- package/dist/migrations/auto-migrator.d.ts +289 -0
- package/dist/migrations/auto-migrator.d.ts.map +1 -0
- package/dist/migrations/auto-migrator.js +396 -0
- package/dist/migrations/auto-migrator.js.map +1 -0
- package/dist/migrations/bulk-orchestrator.d.ts +403 -0
- package/dist/migrations/bulk-orchestrator.d.ts.map +1 -0
- package/dist/migrations/bulk-orchestrator.js +646 -0
- package/dist/migrations/bulk-orchestrator.js.map +1 -0
- package/dist/migrations/compatibility.d.ts +216 -0
- package/dist/migrations/compatibility.d.ts.map +1 -0
- package/dist/migrations/compatibility.js +651 -0
- package/dist/migrations/compatibility.js.map +1 -0
- package/dist/migrations/do-migrations.d.ts +101 -0
- package/dist/migrations/do-migrations.d.ts.map +1 -0
- package/dist/migrations/do-migrations.js +1060 -0
- package/dist/migrations/do-migrations.js.map +1 -0
- package/dist/migrations/do-migrations.types.d.ts +550 -0
- package/dist/migrations/do-migrations.types.d.ts.map +1 -0
- package/dist/migrations/do-migrations.types.js +15 -0
- package/dist/migrations/do-migrations.types.js.map +1 -0
- package/dist/migrations/drizzle-compat.d.ts +163 -0
- package/dist/migrations/drizzle-compat.d.ts.map +1 -0
- package/dist/migrations/drizzle-compat.js +273 -0
- package/dist/migrations/drizzle-compat.js.map +1 -0
- package/dist/migrations/index.d.ts +109 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +127 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/migration-api.d.ts +161 -0
- package/dist/migrations/migration-api.d.ts.map +1 -0
- package/dist/migrations/migration-api.js +499 -0
- package/dist/migrations/migration-api.js.map +1 -0
- package/dist/migrations/progress-tracker-do.d.ts +195 -0
- package/dist/migrations/progress-tracker-do.d.ts.map +1 -0
- package/dist/migrations/progress-tracker-do.js +339 -0
- package/dist/migrations/progress-tracker-do.js.map +1 -0
- package/dist/migrations/progress-tracker-kv.d.ts +103 -0
- package/dist/migrations/progress-tracker-kv.d.ts.map +1 -0
- package/dist/migrations/progress-tracker-kv.js +231 -0
- package/dist/migrations/progress-tracker-kv.js.map +1 -0
- package/dist/migrations/progress-tracker.d.ts +320 -0
- package/dist/migrations/progress-tracker.d.ts.map +1 -0
- package/dist/migrations/progress-tracker.js +443 -0
- package/dist/migrations/progress-tracker.js.map +1 -0
- package/dist/migrations/registry.d.ts +231 -0
- package/dist/migrations/registry.d.ts.map +1 -0
- package/dist/migrations/registry.js +376 -0
- package/dist/migrations/registry.js.map +1 -0
- package/dist/migrations/runner.d.ts +197 -0
- package/dist/migrations/runner.d.ts.map +1 -0
- package/dist/migrations/runner.js +1167 -0
- package/dist/migrations/runner.js.map +1 -0
- package/dist/migrations/schema-generator.d.ts +111 -0
- package/dist/migrations/schema-generator.d.ts.map +1 -0
- package/dist/migrations/schema-generator.js +335 -0
- package/dist/migrations/schema-generator.js.map +1 -0
- package/dist/migrations/testing.d.ts +321 -0
- package/dist/migrations/testing.d.ts.map +1 -0
- package/dist/migrations/testing.js +645 -0
- package/dist/migrations/testing.js.map +1 -0
- package/dist/migrations/types.d.ts +503 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +11 -0
- package/dist/migrations/types.js.map +1 -0
- package/dist/migrations/validator.d.ts +215 -0
- package/dist/migrations/validator.d.ts.map +1 -0
- package/dist/migrations/validator.js +494 -0
- package/dist/migrations/validator.js.map +1 -0
- package/dist/observability/alerting.d.ts +116 -0
- package/dist/observability/alerting.d.ts.map +1 -0
- package/dist/observability/alerting.js +353 -0
- package/dist/observability/alerting.js.map +1 -0
- package/dist/observability/analytics-engine.d.ts +357 -0
- package/dist/observability/analytics-engine.d.ts.map +1 -0
- package/dist/observability/analytics-engine.js +430 -0
- package/dist/observability/analytics-engine.js.map +1 -0
- package/dist/observability/cost-metrics.d.ts +269 -0
- package/dist/observability/cost-metrics.d.ts.map +1 -0
- package/dist/observability/cost-metrics.js +560 -0
- package/dist/observability/cost-metrics.js.map +1 -0
- package/dist/observability/cross-do-tracing.d.ts +305 -0
- package/dist/observability/cross-do-tracing.d.ts.map +1 -0
- package/dist/observability/cross-do-tracing.js +431 -0
- package/dist/observability/cross-do-tracing.js.map +1 -0
- package/dist/observability/error-rate-collector.d.ts +163 -0
- package/dist/observability/error-rate-collector.d.ts.map +1 -0
- package/dist/observability/error-rate-collector.js +306 -0
- package/dist/observability/error-rate-collector.js.map +1 -0
- package/dist/observability/exporters.d.ts +231 -0
- package/dist/observability/exporters.d.ts.map +1 -0
- package/dist/observability/exporters.js +479 -0
- package/dist/observability/exporters.js.map +1 -0
- package/dist/observability/health-check.d.ts +106 -0
- package/dist/observability/health-check.d.ts.map +1 -0
- package/dist/observability/health-check.js +243 -0
- package/dist/observability/health-check.js.map +1 -0
- package/dist/observability/index.d.ts +297 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +455 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/instrumentation.d.ts +222 -0
- package/dist/observability/instrumentation.d.ts.map +1 -0
- package/dist/observability/instrumentation.js +532 -0
- package/dist/observability/instrumentation.js.map +1 -0
- package/dist/observability/memory-metrics.d.ts +227 -0
- package/dist/observability/memory-metrics.d.ts.map +1 -0
- package/dist/observability/memory-metrics.js +688 -0
- package/dist/observability/memory-metrics.js.map +1 -0
- package/dist/observability/metrics-endpoint.d.ts +91 -0
- package/dist/observability/metrics-endpoint.d.ts.map +1 -0
- package/dist/observability/metrics-endpoint.js +246 -0
- package/dist/observability/metrics-endpoint.js.map +1 -0
- package/dist/observability/metrics.d.ts +88 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +253 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/observability-features.d.ts +488 -0
- package/dist/observability/observability-features.d.ts.map +1 -0
- package/dist/observability/observability-features.js +773 -0
- package/dist/observability/observability-features.js.map +1 -0
- package/dist/observability/prometheus.d.ts +39 -0
- package/dist/observability/prometheus.d.ts.map +1 -0
- package/dist/observability/prometheus.js +120 -0
- package/dist/observability/prometheus.js.map +1 -0
- package/dist/observability/propagation.d.ts +126 -0
- package/dist/observability/propagation.d.ts.map +1 -0
- package/dist/observability/propagation.js +234 -0
- package/dist/observability/propagation.js.map +1 -0
- package/dist/observability/query-latency.d.ts +243 -0
- package/dist/observability/query-latency.d.ts.map +1 -0
- package/dist/observability/query-latency.js +292 -0
- package/dist/observability/query-latency.js.map +1 -0
- package/dist/observability/query-performance.d.ts +169 -0
- package/dist/observability/query-performance.d.ts.map +1 -0
- package/dist/observability/query-performance.js +290 -0
- package/dist/observability/query-performance.js.map +1 -0
- package/dist/observability/storage-tier-metrics.d.ts +174 -0
- package/dist/observability/storage-tier-metrics.d.ts.map +1 -0
- package/dist/observability/storage-tier-metrics.js +306 -0
- package/dist/observability/storage-tier-metrics.js.map +1 -0
- package/dist/observability/tier-cost-optimizer.d.ts +155 -0
- package/dist/observability/tier-cost-optimizer.d.ts.map +1 -0
- package/dist/observability/tier-cost-optimizer.js +536 -0
- package/dist/observability/tier-cost-optimizer.js.map +1 -0
- package/dist/observability/tracer.d.ts +149 -0
- package/dist/observability/tracer.d.ts.map +1 -0
- package/dist/observability/tracer.js +435 -0
- package/dist/observability/tracer.js.map +1 -0
- package/dist/observability/types.d.ts +402 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +103 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/pglite/workers-pglite.d.ts +138 -0
- package/dist/pglite/workers-pglite.d.ts.map +1 -0
- package/dist/pglite/workers-pglite.js +143 -0
- package/dist/pglite/workers-pglite.js.map +1 -0
- package/dist/pglite-assets/pglite.data +0 -0
- package/dist/pglite-assets/pglite.wasm +0 -0
- package/dist/playground/index.d.ts +52 -0
- package/dist/playground/index.d.ts.map +1 -0
- package/dist/playground/index.js +55 -0
- package/dist/playground/index.js.map +1 -0
- package/dist/playground/keyboard-shortcuts.d.ts +116 -0
- package/dist/playground/keyboard-shortcuts.d.ts.map +1 -0
- package/dist/playground/keyboard-shortcuts.js +588 -0
- package/dist/playground/keyboard-shortcuts.js.map +1 -0
- package/dist/playground/playground.d.ts +82 -0
- package/dist/playground/playground.d.ts.map +1 -0
- package/dist/playground/playground.js +271 -0
- package/dist/playground/playground.js.map +1 -0
- package/dist/playground/query-executor.d.ts +115 -0
- package/dist/playground/query-executor.d.ts.map +1 -0
- package/dist/playground/query-executor.js +558 -0
- package/dist/playground/query-executor.js.map +1 -0
- package/dist/playground/query-history.d.ts +92 -0
- package/dist/playground/query-history.d.ts.map +1 -0
- package/dist/playground/query-history.js +259 -0
- package/dist/playground/query-history.js.map +1 -0
- package/dist/playground/result-formatter.d.ts +59 -0
- package/dist/playground/result-formatter.d.ts.map +1 -0
- package/dist/playground/result-formatter.js +341 -0
- package/dist/playground/result-formatter.js.map +1 -0
- package/dist/playground/sample-datasets.d.ts +77 -0
- package/dist/playground/sample-datasets.d.ts.map +1 -0
- package/dist/playground/sample-datasets.js +641 -0
- package/dist/playground/sample-datasets.js.map +1 -0
- package/dist/playground/sample-queries.d.ts +73 -0
- package/dist/playground/sample-queries.d.ts.map +1 -0
- package/dist/playground/sample-queries.js +1095 -0
- package/dist/playground/sample-queries.js.map +1 -0
- package/dist/playground/schema-explorer.d.ts +55 -0
- package/dist/playground/schema-explorer.d.ts.map +1 -0
- package/dist/playground/schema-explorer.js +473 -0
- package/dist/playground/schema-explorer.js.map +1 -0
- package/dist/playground/types.d.ts +430 -0
- package/dist/playground/types.d.ts.map +1 -0
- package/dist/playground/types.js +10 -0
- package/dist/playground/types.js.map +1 -0
- package/dist/readonly/cache-reader.d.ts +145 -0
- package/dist/readonly/cache-reader.d.ts.map +1 -0
- package/dist/readonly/cache-reader.js +198 -0
- package/dist/readonly/cache-reader.js.map +1 -0
- package/dist/readonly/config.d.ts +74 -0
- package/dist/readonly/config.d.ts.map +1 -0
- package/dist/readonly/config.js +67 -0
- package/dist/readonly/config.js.map +1 -0
- package/dist/readonly/index.d.ts +22 -0
- package/dist/readonly/index.d.ts.map +1 -0
- package/dist/readonly/index.js +17 -0
- package/dist/readonly/index.js.map +1 -0
- package/dist/readonly/pglite-wrapper.d.ts +82 -0
- package/dist/readonly/pglite-wrapper.d.ts.map +1 -0
- package/dist/readonly/pglite-wrapper.js +123 -0
- package/dist/readonly/pglite-wrapper.js.map +1 -0
- package/dist/readonly/worker.d.ts +142 -0
- package/dist/readonly/worker.d.ts.map +1 -0
- package/dist/readonly/worker.js +187 -0
- package/dist/readonly/worker.js.map +1 -0
- package/dist/readonly/write-blocker.d.ts +47 -0
- package/dist/readonly/write-blocker.d.ts.map +1 -0
- package/dist/readonly/write-blocker.js +136 -0
- package/dist/readonly/write-blocker.js.map +1 -0
- package/dist/recovery/disaster-recovery.d.ts +326 -0
- package/dist/recovery/disaster-recovery.d.ts.map +1 -0
- package/dist/recovery/disaster-recovery.js +799 -0
- package/dist/recovery/disaster-recovery.js.map +1 -0
- package/dist/recovery/index.d.ts +12 -0
- package/dist/recovery/index.d.ts.map +1 -0
- package/dist/recovery/index.js +12 -0
- package/dist/recovery/index.js.map +1 -0
- package/dist/recovery/parquet-parser.d.ts +321 -0
- package/dist/recovery/parquet-parser.d.ts.map +1 -0
- package/dist/recovery/parquet-parser.js +797 -0
- package/dist/recovery/parquet-parser.js.map +1 -0
- package/dist/retention/index.d.ts +50 -0
- package/dist/retention/index.d.ts.map +1 -0
- package/dist/retention/index.js +50 -0
- package/dist/retention/index.js.map +1 -0
- package/dist/retention/policy.d.ts +344 -0
- package/dist/retention/policy.d.ts.map +1 -0
- package/dist/retention/policy.js +472 -0
- package/dist/retention/policy.js.map +1 -0
- package/dist/retention/purger.d.ts +187 -0
- package/dist/retention/purger.d.ts.map +1 -0
- package/dist/retention/purger.js +411 -0
- package/dist/retention/purger.js.map +1 -0
- package/dist/rls/auth-integration.d.ts +280 -0
- package/dist/rls/auth-integration.d.ts.map +1 -0
- package/dist/rls/auth-integration.js +399 -0
- package/dist/rls/auth-integration.js.map +1 -0
- package/dist/rls/generator.d.ts +249 -0
- package/dist/rls/generator.d.ts.map +1 -0
- package/dist/rls/generator.js +495 -0
- package/dist/rls/generator.js.map +1 -0
- package/dist/rls/index.d.ts +26 -0
- package/dist/rls/index.d.ts.map +1 -0
- package/dist/rls/index.js +58 -0
- package/dist/rls/index.js.map +1 -0
- package/dist/rls/policy.d.ts +116 -0
- package/dist/rls/policy.d.ts.map +1 -0
- package/dist/rls/policy.js +77 -0
- package/dist/rls/policy.js.map +1 -0
- package/dist/rls/validator.d.ts +155 -0
- package/dist/rls/validator.d.ts.map +1 -0
- package/dist/rls/validator.js +792 -0
- package/dist/rls/validator.js.map +1 -0
- package/dist/routing/adaptive-router.d.ts +317 -0
- package/dist/routing/adaptive-router.d.ts.map +1 -0
- package/dist/routing/adaptive-router.js +554 -0
- package/dist/routing/adaptive-router.js.map +1 -0
- package/dist/routing/circuit-breaker.d.ts +339 -0
- package/dist/routing/circuit-breaker.d.ts.map +1 -0
- package/dist/routing/circuit-breaker.js +620 -0
- package/dist/routing/circuit-breaker.js.map +1 -0
- package/dist/routing/cost-metrics.d.ts +133 -0
- package/dist/routing/cost-metrics.d.ts.map +1 -0
- package/dist/routing/cost-metrics.js +259 -0
- package/dist/routing/cost-metrics.js.map +1 -0
- package/dist/routing/do-connection-pool.d.ts +243 -0
- package/dist/routing/do-connection-pool.d.ts.map +1 -0
- package/dist/routing/do-connection-pool.js +572 -0
- package/dist/routing/do-connection-pool.js.map +1 -0
- package/dist/routing/index.d.ts +59 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +59 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/query-complexity-estimator.d.ts +73 -0
- package/dist/routing/query-complexity-estimator.d.ts.map +1 -0
- package/dist/routing/query-complexity-estimator.js +327 -0
- package/dist/routing/query-complexity-estimator.js.map +1 -0
- package/dist/routing/request-coalescing.d.ts +178 -0
- package/dist/routing/request-coalescing.d.ts.map +1 -0
- package/dist/routing/request-coalescing.js +325 -0
- package/dist/routing/request-coalescing.js.map +1 -0
- package/dist/routing/runtime-router.d.ts +107 -0
- package/dist/routing/runtime-router.d.ts.map +1 -0
- package/dist/routing/runtime-router.js +246 -0
- package/dist/routing/runtime-router.js.map +1 -0
- package/dist/routing/tenant-router.d.ts +848 -0
- package/dist/routing/tenant-router.d.ts.map +1 -0
- package/dist/routing/tenant-router.js +1056 -0
- package/dist/routing/tenant-router.js.map +1 -0
- package/dist/routing/websocket-pool.d.ts +119 -0
- package/dist/routing/websocket-pool.d.ts.map +1 -0
- package/dist/routing/websocket-pool.js +436 -0
- package/dist/routing/websocket-pool.js.map +1 -0
- package/dist/storage/cache-layer.d.ts +159 -0
- package/dist/storage/cache-layer.d.ts.map +1 -0
- package/dist/storage/cache-layer.js +245 -0
- package/dist/storage/cache-layer.js.map +1 -0
- package/dist/storage/cost-aware-tiering.d.ts +258 -0
- package/dist/storage/cost-aware-tiering.d.ts.map +1 -0
- package/dist/storage/cost-aware-tiering.js +526 -0
- package/dist/storage/cost-aware-tiering.js.map +1 -0
- package/dist/storage/index.d.ts +87 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +78 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/interfaces.d.ts +856 -0
- package/dist/storage/interfaces.d.ts.map +1 -0
- package/dist/storage/interfaces.js +69 -0
- package/dist/storage/interfaces.js.map +1 -0
- package/dist/storage/r2-layer.d.ts +226 -0
- package/dist/storage/r2-layer.d.ts.map +1 -0
- package/dist/storage/r2-layer.js +307 -0
- package/dist/storage/r2-layer.js.map +1 -0
- package/dist/storage/r2-overflow.d.ts +344 -0
- package/dist/storage/r2-overflow.d.ts.map +1 -0
- package/dist/storage/r2-overflow.js +730 -0
- package/dist/storage/r2-overflow.js.map +1 -0
- package/dist/storage/r2-page-vfs.d.ts +374 -0
- package/dist/storage/r2-page-vfs.d.ts.map +1 -0
- package/dist/storage/r2-page-vfs.js +754 -0
- package/dist/storage/r2-page-vfs.js.map +1 -0
- package/dist/storage/swr-cache.d.ts +181 -0
- package/dist/storage/swr-cache.d.ts.map +1 -0
- package/dist/storage/swr-cache.js +295 -0
- package/dist/storage/swr-cache.js.map +1 -0
- package/dist/storage/tiered-orchestrator.d.ts +951 -0
- package/dist/storage/tiered-orchestrator.d.ts.map +1 -0
- package/dist/storage/tiered-orchestrator.js +1731 -0
- package/dist/storage/tiered-orchestrator.js.map +1 -0
- package/dist/storage/tiered-vfs-swr.d.ts +279 -0
- package/dist/storage/tiered-vfs-swr.d.ts.map +1 -0
- package/dist/storage/tiered-vfs-swr.js +584 -0
- package/dist/storage/tiered-vfs-swr.js.map +1 -0
- package/dist/storage/tiered-vfs.d.ts +405 -0
- package/dist/storage/tiered-vfs.d.ts.map +1 -0
- package/dist/storage/tiered-vfs.js +833 -0
- package/dist/storage/tiered-vfs.js.map +1 -0
- package/dist/streaming/backpressure-controller.d.ts +173 -0
- package/dist/streaming/backpressure-controller.d.ts.map +1 -0
- package/dist/streaming/backpressure-controller.js +344 -0
- package/dist/streaming/backpressure-controller.js.map +1 -0
- package/dist/streaming/buffer-pool.d.ts +241 -0
- package/dist/streaming/buffer-pool.d.ts.map +1 -0
- package/dist/streaming/buffer-pool.js +381 -0
- package/dist/streaming/buffer-pool.js.map +1 -0
- package/dist/streaming/cdc-iceberg-connector.d.ts +272 -0
- package/dist/streaming/cdc-iceberg-connector.d.ts.map +1 -0
- package/dist/streaming/cdc-iceberg-connector.js +408 -0
- package/dist/streaming/cdc-iceberg-connector.js.map +1 -0
- package/dist/streaming/index.d.ts +111 -0
- package/dist/streaming/index.d.ts.map +1 -0
- package/dist/streaming/index.js +128 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/streaming/live-cdc-stream.d.ts +400 -0
- package/dist/streaming/live-cdc-stream.d.ts.map +1 -0
- package/dist/streaming/live-cdc-stream.js +703 -0
- package/dist/streaming/live-cdc-stream.js.map +1 -0
- package/dist/streaming/memory-bounded-stream.d.ts +207 -0
- package/dist/streaming/memory-bounded-stream.d.ts.map +1 -0
- package/dist/streaming/memory-bounded-stream.js +340 -0
- package/dist/streaming/memory-bounded-stream.js.map +1 -0
- package/dist/streaming/query-streamer.d.ts +379 -0
- package/dist/streaming/query-streamer.d.ts.map +1 -0
- package/dist/streaming/query-streamer.js +495 -0
- package/dist/streaming/query-streamer.js.map +1 -0
- package/dist/streaming/response-streaming.d.ts +203 -0
- package/dist/streaming/response-streaming.d.ts.map +1 -0
- package/dist/streaming/response-streaming.js +449 -0
- package/dist/streaming/response-streaming.js.map +1 -0
- package/dist/types/branded.d.ts +859 -0
- package/dist/types/branded.d.ts.map +1 -0
- package/dist/types/branded.js +891 -0
- package/dist/types/branded.js.map +1 -0
- package/dist/types/utilities.d.ts +757 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/types/utilities.js +447 -0
- package/dist/types/utilities.js.map +1 -0
- package/dist/wal/replay-engine.d.ts +344 -0
- package/dist/wal/replay-engine.d.ts.map +1 -0
- package/dist/wal/replay-engine.js +975 -0
- package/dist/wal/replay-engine.js.map +1 -0
- package/dist/worker/__mocks__/capnweb.d.ts +13 -0
- package/dist/worker/__mocks__/capnweb.d.ts.map +1 -0
- package/dist/worker/__mocks__/capnweb.js +15 -0
- package/dist/worker/__mocks__/capnweb.js.map +1 -0
- package/dist/worker/__mocks__/cloudflare-workers.d.ts +31 -0
- package/dist/worker/__mocks__/cloudflare-workers.d.ts.map +1 -0
- package/dist/worker/__mocks__/cloudflare-workers.js +33 -0
- package/dist/worker/__mocks__/cloudflare-workers.js.map +1 -0
- package/dist/worker/__mocks__/pglite.data.d.ts +3 -0
- package/dist/worker/__mocks__/pglite.data.d.ts.map +1 -0
- package/dist/worker/__mocks__/pglite.data.js +20 -0
- package/dist/worker/__mocks__/pglite.data.js.map +1 -0
- package/dist/worker/__mocks__/pglite.wasm.d.ts +3 -0
- package/dist/worker/__mocks__/pglite.wasm.d.ts.map +1 -0
- package/dist/worker/__mocks__/pglite.wasm.js +30 -0
- package/dist/worker/__mocks__/pglite.wasm.js.map +1 -0
- package/dist/worker/auth-rate-limiter.d.ts +270 -0
- package/dist/worker/auth-rate-limiter.d.ts.map +1 -0
- package/dist/worker/auth-rate-limiter.js +332 -0
- package/dist/worker/auth-rate-limiter.js.map +1 -0
- package/dist/worker/auth.d.ts +345 -0
- package/dist/worker/auth.d.ts.map +1 -0
- package/dist/worker/auth.js +837 -0
- package/dist/worker/auth.js.map +1 -0
- package/dist/worker/cdc-backpressure.d.ts +338 -0
- package/dist/worker/cdc-backpressure.d.ts.map +1 -0
- package/dist/worker/cdc-backpressure.js +619 -0
- package/dist/worker/cdc-backpressure.js.map +1 -0
- package/dist/worker/cdc-sse.d.ts +277 -0
- package/dist/worker/cdc-sse.d.ts.map +1 -0
- package/dist/worker/cdc-sse.js +528 -0
- package/dist/worker/cdc-sse.js.map +1 -0
- package/dist/worker/cdc-websocket.d.ts +252 -0
- package/dist/worker/cdc-websocket.d.ts.map +1 -0
- package/dist/worker/cdc-websocket.js +940 -0
- package/dist/worker/cdc-websocket.js.map +1 -0
- package/dist/worker/cdc.d.ts +95 -0
- package/dist/worker/cdc.d.ts.map +1 -0
- package/dist/worker/cdc.js +211 -0
- package/dist/worker/cdc.js.map +1 -0
- package/dist/worker/concerns/auth-concern.d.ts +50 -0
- package/dist/worker/concerns/auth-concern.d.ts.map +1 -0
- package/dist/worker/concerns/auth-concern.js +131 -0
- package/dist/worker/concerns/auth-concern.js.map +1 -0
- package/dist/worker/concerns/cdc-concern.d.ts +99 -0
- package/dist/worker/concerns/cdc-concern.d.ts.map +1 -0
- package/dist/worker/concerns/cdc-concern.js +137 -0
- package/dist/worker/concerns/cdc-concern.js.map +1 -0
- package/dist/worker/concerns/index.d.ts +22 -0
- package/dist/worker/concerns/index.d.ts.map +1 -0
- package/dist/worker/concerns/index.js +13 -0
- package/dist/worker/concerns/index.js.map +1 -0
- package/dist/worker/concerns/query-execution-concern.d.ts +104 -0
- package/dist/worker/concerns/query-execution-concern.d.ts.map +1 -0
- package/dist/worker/concerns/query-execution-concern.js +95 -0
- package/dist/worker/concerns/query-execution-concern.js.map +1 -0
- package/dist/worker/concerns/storage-orchestration-concern.d.ts +78 -0
- package/dist/worker/concerns/storage-orchestration-concern.d.ts.map +1 -0
- package/dist/worker/concerns/storage-orchestration-concern.js +240 -0
- package/dist/worker/concerns/storage-orchestration-concern.js.map +1 -0
- package/dist/worker/do-auth-manager.d.ts +108 -0
- package/dist/worker/do-auth-manager.d.ts.map +1 -0
- package/dist/worker/do-auth-manager.js +212 -0
- package/dist/worker/do-auth-manager.js.map +1 -0
- package/dist/worker/do-pglite-manager.d.ts +137 -0
- package/dist/worker/do-pglite-manager.d.ts.map +1 -0
- package/dist/worker/do-pglite-manager.js +228 -0
- package/dist/worker/do-pglite-manager.js.map +1 -0
- package/dist/worker/do.d.ts +556 -0
- package/dist/worker/do.d.ts.map +1 -0
- package/dist/worker/do.js +1441 -0
- package/dist/worker/do.js.map +1 -0
- package/dist/worker/entry.d.ts +23 -0
- package/dist/worker/entry.d.ts.map +1 -0
- package/dist/worker/entry.js +362 -0
- package/dist/worker/entry.js.map +1 -0
- package/dist/worker/errors.d.ts +106 -0
- package/dist/worker/errors.d.ts.map +1 -0
- package/dist/worker/errors.js +178 -0
- package/dist/worker/errors.js.map +1 -0
- package/dist/worker/health-check-manager.d.ts +141 -0
- package/dist/worker/health-check-manager.d.ts.map +1 -0
- package/dist/worker/health-check-manager.js +145 -0
- package/dist/worker/health-check-manager.js.map +1 -0
- package/dist/worker/index.d.ts +60 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +67 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/memory-pressure.d.ts +892 -0
- package/dist/worker/memory-pressure.d.ts.map +1 -0
- package/dist/worker/memory-pressure.js +1990 -0
- package/dist/worker/memory-pressure.js.map +1 -0
- package/dist/worker/migration-manager.d.ts +153 -0
- package/dist/worker/migration-manager.d.ts.map +1 -0
- package/dist/worker/migration-manager.js +461 -0
- package/dist/worker/migration-manager.js.map +1 -0
- package/dist/worker/plugin-manager.d.ts +147 -0
- package/dist/worker/plugin-manager.d.ts.map +1 -0
- package/dist/worker/plugin-manager.js +408 -0
- package/dist/worker/plugin-manager.js.map +1 -0
- package/dist/worker/proxy.d.ts +330 -0
- package/dist/worker/proxy.d.ts.map +1 -0
- package/dist/worker/proxy.js +504 -0
- package/dist/worker/proxy.js.map +1 -0
- package/dist/worker/query-execution-manager.d.ts +107 -0
- package/dist/worker/query-execution-manager.d.ts.map +1 -0
- package/dist/worker/query-execution-manager.js +155 -0
- package/dist/worker/query-execution-manager.js.map +1 -0
- package/dist/worker/query-executor.d.ts +163 -0
- package/dist/worker/query-executor.d.ts.map +1 -0
- package/dist/worker/query-executor.js +413 -0
- package/dist/worker/query-executor.js.map +1 -0
- package/dist/worker/query-stats-manager.d.ts +117 -0
- package/dist/worker/query-stats-manager.d.ts.map +1 -0
- package/dist/worker/query-stats-manager.js +162 -0
- package/dist/worker/query-stats-manager.js.map +1 -0
- package/dist/worker/result-handler.d.ts +192 -0
- package/dist/worker/result-handler.d.ts.map +1 -0
- package/dist/worker/result-handler.js +346 -0
- package/dist/worker/result-handler.js.map +1 -0
- package/dist/worker/routes.d.ts +135 -0
- package/dist/worker/routes.d.ts.map +1 -0
- package/dist/worker/routes.js +460 -0
- package/dist/worker/routes.js.map +1 -0
- package/dist/worker/rpc-methods-manager.d.ts +142 -0
- package/dist/worker/rpc-methods-manager.d.ts.map +1 -0
- package/dist/worker/rpc-methods-manager.js +195 -0
- package/dist/worker/rpc-methods-manager.js.map +1 -0
- package/dist/worker/rpc.d.ts +259 -0
- package/dist/worker/rpc.d.ts.map +1 -0
- package/dist/worker/rpc.js +398 -0
- package/dist/worker/rpc.js.map +1 -0
- package/dist/worker/schema-version.d.ts +209 -0
- package/dist/worker/schema-version.d.ts.map +1 -0
- package/dist/worker/schema-version.js +450 -0
- package/dist/worker/schema-version.js.map +1 -0
- package/dist/worker/session-manager.d.ts +282 -0
- package/dist/worker/session-manager.d.ts.map +1 -0
- package/dist/worker/session-manager.js +523 -0
- package/dist/worker/session-manager.js.map +1 -0
- package/dist/worker/shutdown-manager.d.ts +188 -0
- package/dist/worker/shutdown-manager.d.ts.map +1 -0
- package/dist/worker/shutdown-manager.js +347 -0
- package/dist/worker/shutdown-manager.js.map +1 -0
- package/dist/worker/sql-transform.d.ts +61 -0
- package/dist/worker/sql-transform.d.ts.map +1 -0
- package/dist/worker/sql-transform.js +312 -0
- package/dist/worker/sql-transform.js.map +1 -0
- package/dist/worker/types.d.ts +738 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +6 -0
- package/dist/worker/types.js.map +1 -0
- package/dist/worker/user-routes.d.ts +76 -0
- package/dist/worker/user-routes.d.ts.map +1 -0
- package/dist/worker/user-routes.js +188 -0
- package/dist/worker/user-routes.js.map +1 -0
- package/dist/worker/wal-facade.d.ts +138 -0
- package/dist/worker/wal-facade.d.ts.map +1 -0
- package/dist/worker/wal-facade.js +184 -0
- package/dist/worker/wal-facade.js.map +1 -0
- package/dist/worker/wal-r2.d.ts +271 -0
- package/dist/worker/wal-r2.d.ts.map +1 -0
- package/dist/worker/wal-r2.js +689 -0
- package/dist/worker/wal-r2.js.map +1 -0
- package/dist/worker/wal-replay.d.ts +361 -0
- package/dist/worker/wal-replay.d.ts.map +1 -0
- package/dist/worker/wal-replay.js +628 -0
- package/dist/worker/wal-replay.js.map +1 -0
- package/dist/worker/wal-retention.d.ts +389 -0
- package/dist/worker/wal-retention.d.ts.map +1 -0
- package/dist/worker/wal-retention.js +763 -0
- package/dist/worker/wal-retention.js.map +1 -0
- package/dist/worker/wal.d.ts +278 -0
- package/dist/worker/wal.d.ts.map +1 -0
- package/dist/worker/wal.js +467 -0
- package/dist/worker/wal.js.map +1 -0
- package/dist/worker/websocket.d.ts +85 -0
- package/dist/worker/websocket.d.ts.map +1 -0
- package/dist/worker/websocket.js +227 -0
- package/dist/worker/websocket.js.map +1 -0
- package/package.json +108 -0
- package/src/cdc/change-stream.ts +137 -0
- package/src/cdc/filter.ts +646 -0
- package/src/cdc/index.ts +112 -0
- package/src/cdc/resume-token.ts +280 -0
- package/src/cdc/transport/index.ts +7 -0
- package/src/cdc/transport/sse.ts +723 -0
- package/src/cdc/transport/websocket.ts +873 -0
- package/src/cdc/types.ts +346 -0
- package/src/config/index.ts +25 -0
- package/src/config/memory.ts +177 -0
- package/src/config/storage.ts +204 -0
- package/src/config/streaming.ts +147 -0
- package/src/config/timeouts.ts +221 -0
- package/src/extensions/config.test.ts +187 -0
- package/src/extensions/config.ts +278 -0
- package/src/extensions/geo.test.ts +455 -0
- package/src/extensions/geo.ts +858 -0
- package/src/extensions/index.test.ts +259 -0
- package/src/extensions/index.ts +227 -0
- package/src/extensions/loader.test.ts +555 -0
- package/src/extensions/loader.ts +588 -0
- package/src/extensions/pgmq-lite.test.ts +727 -0
- package/src/extensions/pgmq-lite.ts +770 -0
- package/src/extensions/plugins.test.ts +528 -0
- package/src/extensions/plugins.ts +718 -0
- package/src/extensions/registry.test.ts +202 -0
- package/src/extensions/registry.ts +267 -0
- package/src/extensions/vector.test.ts +195 -0
- package/src/extensions/vector.ts +217 -0
- package/src/iceberg/SCHEDULER.md +580 -0
- package/src/iceberg/analytics.test.ts +703 -0
- package/src/iceberg/analytics.ts +727 -0
- package/src/iceberg/catalog-api.test.ts +838 -0
- package/src/iceberg/catalog-api.ts +520 -0
- package/src/iceberg/catalog.test.ts +680 -0
- package/src/iceberg/catalog.ts +1007 -0
- package/src/iceberg/iceberg.test.ts +705 -0
- package/src/iceberg/index.ts +406 -0
- package/src/iceberg/metadata.test.ts +632 -0
- package/src/iceberg/metadata.ts +649 -0
- package/src/iceberg/optimizer.test.ts +868 -0
- package/src/iceberg/optimizer.ts +1287 -0
- package/src/iceberg/parquet.test.ts +899 -0
- package/src/iceberg/parquet.ts +1640 -0
- package/src/iceberg/r2-organization.test.ts +615 -0
- package/src/iceberg/r2-organization.ts +951 -0
- package/src/iceberg/scheduler-do-example.ts +364 -0
- package/src/iceberg/scheduler.test.ts +861 -0
- package/src/iceberg/scheduler.ts +1201 -0
- package/src/iceberg/schema.test.ts +547 -0
- package/src/iceberg/schema.ts +616 -0
- package/src/iceberg/snapshot-manager.test.ts +919 -0
- package/src/iceberg/snapshot-manager.ts +1369 -0
- package/src/iceberg/sql-router.test.ts +334 -0
- package/src/iceberg/sql-router.ts +337 -0
- package/src/iceberg/test-fixtures.ts +605 -0
- package/src/iceberg/time-travel-api.test.ts +1029 -0
- package/src/iceberg/time-travel-api.ts +731 -0
- package/src/iceberg/time-travel.test.ts +1218 -0
- package/src/iceberg/time-travel.ts +1052 -0
- package/src/iceberg/transformer.test.ts +689 -0
- package/src/iceberg/transformer.ts +1029 -0
- package/src/iceberg/types.ts +373 -0
- package/src/iceberg/writer.test.ts +716 -0
- package/src/iceberg/writer.ts +590 -0
- package/src/index.ts +212 -0
- package/src/lineage/index.ts +42 -0
- package/src/lineage/integration.ts +334 -0
- package/src/lineage/tracker.ts +1618 -0
- package/src/lineage/types.ts +354 -0
- package/src/middleware/index.ts +36 -0
- package/src/middleware/rate-limit-concurrent.test.ts +794 -0
- package/src/middleware/rate-limit.test.ts +1568 -0
- package/src/middleware/rate-limit.ts +840 -0
- package/src/migration-tooling/external-migration.test.ts +1864 -0
- package/src/migration-tooling/external-migration.ts +2355 -0
- package/src/migration-tooling/index.ts +19 -0
- package/src/migrations/ARCHITECTURE.md +474 -0
- package/src/migrations/PROGRESS_TRACKING.md +485 -0
- package/src/migrations/auto-migrator.test.ts +732 -0
- package/src/migrations/auto-migrator.ts +531 -0
- package/src/migrations/bulk-orchestrator.test.ts +801 -0
- package/src/migrations/bulk-orchestrator.ts +1039 -0
- package/src/migrations/compatibility.test.ts +958 -0
- package/src/migrations/compatibility.ts +902 -0
- package/src/migrations/do-migrations.test.ts +2620 -0
- package/src/migrations/do-migrations.ts +1289 -0
- package/src/migrations/do-migrations.types.ts +715 -0
- package/src/migrations/drizzle-compat.test.ts +210 -0
- package/src/migrations/drizzle-compat.ts +337 -0
- package/src/migrations/index.ts +334 -0
- package/src/migrations/migration-api.test.ts +438 -0
- package/src/migrations/migration-api.ts +704 -0
- package/src/migrations/progress-tracker-do.ts +518 -0
- package/src/migrations/progress-tracker-kv.ts +305 -0
- package/src/migrations/progress-tracker.test.ts +937 -0
- package/src/migrations/progress-tracker.ts +665 -0
- package/src/migrations/registry.test.ts +331 -0
- package/src/migrations/registry.ts +468 -0
- package/src/migrations/rollback.test.ts +644 -0
- package/src/migrations/runner.test.ts +807 -0
- package/src/migrations/runner.test.ts.backup +759 -0
- package/src/migrations/runner.ts +1459 -0
- package/src/migrations/schema-generator.test.ts +649 -0
- package/src/migrations/schema-generator.ts +513 -0
- package/src/migrations/testing.ts +1037 -0
- package/src/migrations/types.ts +573 -0
- package/src/migrations/validator.test.ts +660 -0
- package/src/migrations/validator.ts +741 -0
- package/src/observability/alerting.test.ts +1133 -0
- package/src/observability/alerting.ts +455 -0
- package/src/observability/analytics-engine.ts +733 -0
- package/src/observability/cost-metrics.ts +804 -0
- package/src/observability/cross-do-tracing.test.ts +516 -0
- package/src/observability/cross-do-tracing.ts +588 -0
- package/src/observability/dashboards/postgres-do-overview.json +1656 -0
- package/src/observability/error-rate-collector.test.ts +977 -0
- package/src/observability/error-rate-collector.ts +518 -0
- package/src/observability/exporters.test.ts +365 -0
- package/src/observability/exporters.ts +650 -0
- package/src/observability/health-check.test.ts +353 -0
- package/src/observability/health-check.ts +341 -0
- package/src/observability/index.test.ts +298 -0
- package/src/observability/index.ts +885 -0
- package/src/observability/instrumentation.test.ts +428 -0
- package/src/observability/instrumentation.ts +788 -0
- package/src/observability/memory-metrics.test.ts +355 -0
- package/src/observability/memory-metrics.ts +990 -0
- package/src/observability/metrics-endpoint.test.ts +402 -0
- package/src/observability/metrics-endpoint.ts +374 -0
- package/src/observability/metrics.test.ts +291 -0
- package/src/observability/metrics.ts +315 -0
- package/src/observability/observability-features.ts +1296 -0
- package/src/observability/prometheus.test.ts +292 -0
- package/src/observability/prometheus.ts +170 -0
- package/src/observability/propagation.test.ts +417 -0
- package/src/observability/propagation.ts +294 -0
- package/src/observability/query-latency.ts +586 -0
- package/src/observability/query-performance.test.ts +406 -0
- package/src/observability/query-performance.ts +491 -0
- package/src/observability/storage-tier-metrics.test.ts +633 -0
- package/src/observability/storage-tier-metrics.ts +570 -0
- package/src/observability/tier-cost-optimizer.ts +740 -0
- package/src/observability/tracer.test.ts +346 -0
- package/src/observability/tracer.ts +585 -0
- package/src/observability/types.test.ts +726 -0
- package/src/observability/types.ts +434 -0
- package/src/pglite/auto-demotion.test.ts +477 -0
- package/src/pglite/auto-demotion.ts +385 -0
- package/src/pglite/auto-promotion.test.ts +824 -0
- package/src/pglite/auto-promotion.ts +547 -0
- package/src/pglite/cache-layer.test.ts +469 -0
- package/src/pglite/cache-layer.ts +271 -0
- package/src/pglite/cold-start-manager.ts +1260 -0
- package/src/pglite/cold-start-optimizer.test.ts +937 -0
- package/src/pglite/cold-start-optimizer.ts +1895 -0
- package/src/pglite/dovfs-adapter.ts +1122 -0
- package/src/pglite/dovfs.ts +1258 -0
- package/src/pglite/etag-cache.test.ts +844 -0
- package/src/pglite/etag-cache.ts +526 -0
- package/src/pglite/index.ts +442 -0
- package/src/pglite/init.test.ts +455 -0
- package/src/pglite/init.ts +574 -0
- package/src/pglite/lifecycle.test.ts +599 -0
- package/src/pglite/lifecycle.ts +704 -0
- package/src/pglite/parallel-loader.test.ts +586 -0
- package/src/pglite/parallel-loader.ts +481 -0
- package/src/pglite/production-pglite.test.ts +666 -0
- package/src/pglite/production-pglite.ts +537 -0
- package/src/pglite/query-executor.ts +614 -0
- package/src/pglite/r2-layer.test.ts +501 -0
- package/src/pglite/r2-layer.ts +322 -0
- package/src/pglite/tiered-init.test.ts +725 -0
- package/src/pglite/tiered-init.ts +556 -0
- package/src/pglite/tiered-vfs.test.ts +726 -0
- package/src/pglite/tiered-vfs.ts +33 -0
- package/src/pglite/tiering-stats.test.ts +531 -0
- package/src/pglite/tiering-stats.ts +407 -0
- package/src/pglite/transaction-hooks.ts +343 -0
- package/src/pglite/warm-loader.test.ts +1701 -0
- package/src/pglite/warm-loader.ts +528 -0
- package/src/pglite/workers-pglite.ts +224 -0
- package/src/pglite-assets/pglite.data +0 -0
- package/src/pglite-assets/pglite.wasm +0 -0
- package/src/pglite.d.ts +47 -0
- package/src/playground/index.ts +137 -0
- package/src/playground/keyboard-shortcuts.ts +677 -0
- package/src/playground/playground.ts +323 -0
- package/src/playground/query-executor.ts +669 -0
- package/src/playground/query-history.ts +328 -0
- package/src/playground/result-formatter.ts +420 -0
- package/src/playground/sample-datasets.ts +674 -0
- package/src/playground/sample-queries.ts +1168 -0
- package/src/playground/schema-explorer.ts +558 -0
- package/src/playground/types.ts +518 -0
- package/src/readonly/cache-reader.test.ts +460 -0
- package/src/readonly/cache-reader.ts +313 -0
- package/src/readonly/config.test.ts +187 -0
- package/src/readonly/config.ts +128 -0
- package/src/readonly/index.ts +50 -0
- package/src/readonly/pglite-wrapper.test.ts +278 -0
- package/src/readonly/pglite-wrapper.ts +184 -0
- package/src/readonly/worker.test.ts +533 -0
- package/src/readonly/worker.ts +341 -0
- package/src/readonly/write-blocker.test.ts +459 -0
- package/src/readonly/write-blocker.ts +175 -0
- package/src/recovery/disaster-recovery.test.ts +618 -0
- package/src/recovery/disaster-recovery.ts +1181 -0
- package/src/recovery/index.ts +43 -0
- package/src/recovery/parquet-parser.ts +974 -0
- package/src/retention/index.ts +74 -0
- package/src/retention/policy.test.ts +571 -0
- package/src/retention/policy.ts +774 -0
- package/src/retention/purger.test.ts +465 -0
- package/src/retention/purger.ts +558 -0
- package/src/rls/auth-integration.test.ts +752 -0
- package/src/rls/auth-integration.ts +533 -0
- package/src/rls/generator.test.ts +829 -0
- package/src/rls/generator.ts +573 -0
- package/src/rls/index.ts +128 -0
- package/src/rls/policy.ts +208 -0
- package/src/rls/rls.test.ts +1071 -0
- package/src/rls/validator.test.ts +930 -0
- package/src/rls/validator.ts +895 -0
- package/src/routing/adaptive-router.test.ts +884 -0
- package/src/routing/adaptive-router.ts +845 -0
- package/src/routing/circuit-breaker.test.ts +1505 -0
- package/src/routing/circuit-breaker.ts +852 -0
- package/src/routing/cost-metrics.test.ts +565 -0
- package/src/routing/cost-metrics.ts +408 -0
- package/src/routing/do-connection-pool.test.ts +1109 -0
- package/src/routing/do-connection-pool.ts +828 -0
- package/src/routing/index.ts +158 -0
- package/src/routing/query-complexity-estimator.test.ts +356 -0
- package/src/routing/query-complexity-estimator.ts +444 -0
- package/src/routing/request-coalescing.test.ts +738 -0
- package/src/routing/request-coalescing.ts +475 -0
- package/src/routing/runtime-router.test.ts +436 -0
- package/src/routing/runtime-router.ts +357 -0
- package/src/routing/tenant-router.test.ts +2493 -0
- package/src/routing/tenant-router.ts +1908 -0
- package/src/routing/websocket-pool.test.ts +551 -0
- package/src/routing/websocket-pool.ts +577 -0
- package/src/storage/access-pattern-tracker.test.ts +874 -0
- package/src/storage/cache-layer.test.ts +560 -0
- package/src/storage/cache-layer.ts +328 -0
- package/src/storage/cost-aware-tiering.test.ts +652 -0
- package/src/storage/cost-aware-tiering.ts +794 -0
- package/src/storage/do-sqlite-blobs.test.ts +937 -0
- package/src/storage/index.ts +272 -0
- package/src/storage/interfaces.ts +974 -0
- package/src/storage/r2-layer.test.ts +653 -0
- package/src/storage/r2-layer.ts +434 -0
- package/src/storage/r2-overflow.ts +920 -0
- package/src/storage/r2-page-vfs.test.ts +2348 -0
- package/src/storage/r2-page-vfs.ts +1054 -0
- package/src/storage/swr-cache.test.ts +832 -0
- package/src/storage/swr-cache.ts +398 -0
- package/src/storage/swr-tiered-integration.test.ts +617 -0
- package/src/storage/tiered-orchestrator.test.ts +2441 -0
- package/src/storage/tiered-orchestrator.ts +2081 -0
- package/src/storage/tiered-vfs-swr.test.ts +736 -0
- package/src/storage/tiered-vfs-swr.ts +735 -0
- package/src/storage/tiered-vfs.test.ts +793 -0
- package/src/storage/tiered-vfs.ts +1082 -0
- package/src/streaming/backpressure-controller.ts +452 -0
- package/src/streaming/buffer-pool.ts +484 -0
- package/src/streaming/cdc-iceberg-connector.ts +605 -0
- package/src/streaming/index.ts +225 -0
- package/src/streaming/live-cdc-stream.ts +985 -0
- package/src/streaming/memory-bounded-stream.ts +443 -0
- package/src/streaming/query-streamer.ts +662 -0
- package/src/streaming/response-streaming.ts +557 -0
- package/src/types/branded.ts +1075 -0
- package/src/types/branded.ts.backup +273 -0
- package/src/types/utilities.ts +1023 -0
- package/src/types/wasm.d.ts +30 -0
- package/src/validation/typed-errors.test.ts +420 -0
- package/src/wal/replay-engine.ts +1264 -0
- package/src/worker/__mocks__/capnweb.ts +15 -0
- package/src/worker/__mocks__/pglite.data.ts +22 -0
- package/src/worker/__mocks__/pglite.wasm.ts +33 -0
- package/src/worker/auth-rate-limiter.test.ts +272 -0
- package/src/worker/auth-rate-limiter.ts +448 -0
- package/src/worker/auth.security-red.test.ts +1236 -0
- package/src/worker/auth.security.test.ts +822 -0
- package/src/worker/auth.test.ts +469 -0
- package/src/worker/auth.ts +1104 -0
- package/src/worker/cdc-backpressure.test.ts +726 -0
- package/src/worker/cdc-backpressure.ts +866 -0
- package/src/worker/cdc-sse.test.ts +780 -0
- package/src/worker/cdc-sse.ts +728 -0
- package/src/worker/cdc-websocket.ts +1229 -0
- package/src/worker/cdc-ws.test.ts +1009 -0
- package/src/worker/cdc.test.ts +327 -0
- package/src/worker/cdc.ts +289 -0
- package/src/worker/concerns/auth-concern.ts +179 -0
- package/src/worker/concerns/cdc-concern.ts +247 -0
- package/src/worker/concerns/index.ts +58 -0
- package/src/worker/concerns/query-execution-concern.ts +194 -0
- package/src/worker/concerns/storage-orchestration-concern.ts +373 -0
- package/src/worker/discriminated-types.test.ts +280 -0
- package/src/worker/do-auth-manager.ts +257 -0
- package/src/worker/do-decomposition.test.ts +1236 -0
- package/src/worker/do-pglite-manager.ts +302 -0
- package/src/worker/do.test.ts +2254 -0
- package/src/worker/do.ts +1878 -0
- package/src/worker/entry.ts +417 -0
- package/src/worker/errors.ts +285 -0
- package/src/worker/health-check-manager.test.ts +261 -0
- package/src/worker/health-check-manager.ts +231 -0
- package/src/worker/index.ts +389 -0
- package/src/worker/memory-pressure.test.ts +1460 -0
- package/src/worker/memory-pressure.ts +2650 -0
- package/src/worker/migration-manager.ts +582 -0
- package/src/worker/neon-compat.test.ts +332 -0
- package/src/worker/plugin-manager.ts +485 -0
- package/src/worker/postgres.do-rpc.d.ts +76 -0
- package/src/worker/proxy.ts +694 -0
- package/src/worker/query-execution-manager.test.ts +303 -0
- package/src/worker/query-execution-manager.ts +219 -0
- package/src/worker/query-executor.test.ts +282 -0
- package/src/worker/query-executor.ts +560 -0
- package/src/worker/query-stats-manager.ts +229 -0
- package/src/worker/result-handler.test.ts +364 -0
- package/src/worker/result-handler.ts +510 -0
- package/src/worker/routes.test.ts +795 -0
- package/src/worker/routes.ts +650 -0
- package/src/worker/rpc-methods-manager.test.ts +326 -0
- package/src/worker/rpc-methods-manager.ts +276 -0
- package/src/worker/rpc.ts +524 -0
- package/src/worker/schema-version.ts +605 -0
- package/src/worker/session-manager.test.ts +506 -0
- package/src/worker/session-manager.ts +732 -0
- package/src/worker/shutdown-manager.ts +469 -0
- package/src/worker/sql-transform.test.ts +286 -0
- package/src/worker/sql-transform.ts +368 -0
- package/src/worker/supabase-compat.test.ts +621 -0
- package/src/worker/types.test.ts +292 -0
- package/src/worker/types.ts +873 -0
- package/src/worker/user-routes.test.ts +703 -0
- package/src/worker/user-routes.ts +303 -0
- package/src/worker/wal-facade.ts +235 -0
- package/src/worker/wal-r2.test.ts +570 -0
- package/src/worker/wal-r2.ts +930 -0
- package/src/worker/wal-replay.test.ts +845 -0
- package/src/worker/wal-replay.ts +897 -0
- package/src/worker/wal-retention.test.ts +758 -0
- package/src/worker/wal-retention.ts +1075 -0
- package/src/worker/wal.test.ts +618 -0
- package/src/worker/wal.ts +697 -0
- package/src/worker/websocket.test.ts +296 -0
- package/src/worker/websocket.ts +284 -0
|
@@ -0,0 +1,1201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iceberg Snapshot Scheduling and Automation
|
|
3
|
+
* Task: postgres-uw7 - Snapshot scheduling and automation
|
|
4
|
+
*
|
|
5
|
+
* Provides automatic snapshot creation on schedules and event triggers:
|
|
6
|
+
* - Cron-based scheduling (e.g., hourly, daily snapshots)
|
|
7
|
+
* - Event-triggered snapshots (write count thresholds)
|
|
8
|
+
* - Snapshot retention policy enforcement
|
|
9
|
+
* - Integration with Cloudflare Cron Triggers and Durable Object alarms
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Create scheduler with cron schedule
|
|
14
|
+
* const scheduler = createSnapshotScheduler({
|
|
15
|
+
* bucket: env.ICEBERG_BUCKET,
|
|
16
|
+
* tablePath: 'iceberg/events',
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* await scheduler.initialize()
|
|
20
|
+
*
|
|
21
|
+
* // Schedule hourly snapshots
|
|
22
|
+
* await scheduler.schedule('events', '0 * * * *')
|
|
23
|
+
*
|
|
24
|
+
* // Trigger snapshot after 10,000 writes
|
|
25
|
+
* await scheduler.setThreshold('events', 10000)
|
|
26
|
+
*
|
|
27
|
+
* // Set retention policy
|
|
28
|
+
* await scheduler.enforceRetention('events', {
|
|
29
|
+
* maxAgeDays: 30,
|
|
30
|
+
* minSnapshotsToRetain: 5,
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* // List scheduled snapshots
|
|
34
|
+
* const schedules = scheduler.listScheduled()
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Integration with Durable Object alarms
|
|
40
|
+
* export class IcebergSnapshotDO extends DurableObject {
|
|
41
|
+
* async alarm() {
|
|
42
|
+
* const scheduler = createSnapshotScheduler({
|
|
43
|
+
* bucket: this.env.ICEBERG_BUCKET,
|
|
44
|
+
* tablePath: 'iceberg/events',
|
|
45
|
+
* state: this.state,
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* await scheduler.processDueSnapshots()
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import {
|
|
55
|
+
createSnapshotManager,
|
|
56
|
+
type RetentionConfig,
|
|
57
|
+
type ExpireSnapshotsResult,
|
|
58
|
+
} from './snapshot-manager'
|
|
59
|
+
// Re-export for potential external use
|
|
60
|
+
export type { IcebergWALWriter } from './writer'
|
|
61
|
+
export { createIcebergWALWriter } from './writer'
|
|
62
|
+
|
|
63
|
+
// ========== Types ==========
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Cron expression type
|
|
67
|
+
*
|
|
68
|
+
* Standard cron format: minute hour day month dayOfWeek
|
|
69
|
+
* - minute: 0-59
|
|
70
|
+
* - hour: 0-23
|
|
71
|
+
* - day: 1-31
|
|
72
|
+
* - month: 1-12
|
|
73
|
+
* - dayOfWeek: 0-6 (0 = Sunday)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* - "0 * * * *" - Every hour at minute 0
|
|
77
|
+
* - "0 0 * * *" - Daily at midnight
|
|
78
|
+
* - "0 0 * * 0" - Weekly on Sunday at midnight
|
|
79
|
+
* - "0 0 1 * *" - Monthly on the 1st at midnight
|
|
80
|
+
*/
|
|
81
|
+
export type CronExpression = string
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Snapshot schedule configuration
|
|
85
|
+
*/
|
|
86
|
+
export interface SnapshotSchedule {
|
|
87
|
+
/** Table identifier */
|
|
88
|
+
table: string
|
|
89
|
+
/** Cron expression for schedule */
|
|
90
|
+
cron: CronExpression
|
|
91
|
+
/** Next scheduled snapshot time (ISO timestamp) */
|
|
92
|
+
nextRun: string
|
|
93
|
+
/** Last snapshot time (ISO timestamp) */
|
|
94
|
+
lastRun: string | null
|
|
95
|
+
/** Whether the schedule is enabled */
|
|
96
|
+
enabled: boolean
|
|
97
|
+
/** Retention policy for this table */
|
|
98
|
+
retentionPolicy?: RetentionConfig
|
|
99
|
+
/** Schedule metadata */
|
|
100
|
+
metadata?: Record<string, unknown>
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Write threshold configuration for event-triggered snapshots
|
|
105
|
+
*/
|
|
106
|
+
export interface WriteThreshold {
|
|
107
|
+
/** Table identifier */
|
|
108
|
+
table: string
|
|
109
|
+
/** Number of writes before triggering snapshot */
|
|
110
|
+
writeCount: number
|
|
111
|
+
/** Current write count since last snapshot */
|
|
112
|
+
currentCount: number
|
|
113
|
+
/** Whether threshold is enabled */
|
|
114
|
+
enabled: boolean
|
|
115
|
+
/** Last snapshot time (ISO timestamp) */
|
|
116
|
+
lastSnapshot: string | null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Size-based policy configuration for automatic snapshots
|
|
121
|
+
*/
|
|
122
|
+
export interface SizePolicy {
|
|
123
|
+
/** Table identifier */
|
|
124
|
+
table: string
|
|
125
|
+
/** Size threshold in bytes before triggering snapshot */
|
|
126
|
+
sizeThresholdBytes: number
|
|
127
|
+
/** Current accumulated size since last snapshot */
|
|
128
|
+
currentSizeBytes: number
|
|
129
|
+
/** Whether the policy is enabled */
|
|
130
|
+
enabled: boolean
|
|
131
|
+
/** Last snapshot time (ISO timestamp) */
|
|
132
|
+
lastSnapshot: string | null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Snapshot lifecycle policy configuration
|
|
137
|
+
*/
|
|
138
|
+
export interface LifecyclePolicy {
|
|
139
|
+
/** Table identifier */
|
|
140
|
+
table: string
|
|
141
|
+
/** Whether lifecycle management is enabled */
|
|
142
|
+
enabled: boolean
|
|
143
|
+
/** Retention configuration */
|
|
144
|
+
retention: RetentionConfig
|
|
145
|
+
/** Auto-expiration timestamp (ISO timestamp, snapshots older than this are expired) */
|
|
146
|
+
expirationTimestamp?: string
|
|
147
|
+
/** Archive policy - move to cold storage after this many days */
|
|
148
|
+
archiveAfterDays?: number
|
|
149
|
+
/** Delete policy - delete from cold storage after this many days */
|
|
150
|
+
deleteAfterDays?: number
|
|
151
|
+
/** Last enforcement time (ISO timestamp) */
|
|
152
|
+
lastEnforcementAt: string | null
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Snapshot scheduler statistics
|
|
157
|
+
*/
|
|
158
|
+
export interface SchedulerStats {
|
|
159
|
+
/** Total scheduled snapshots created */
|
|
160
|
+
scheduledSnapshotsCreated: number
|
|
161
|
+
/** Total threshold-triggered snapshots created */
|
|
162
|
+
thresholdSnapshotsCreated: number
|
|
163
|
+
/** Total size-triggered snapshots created */
|
|
164
|
+
sizeSnapshotsCreated: number
|
|
165
|
+
/** Total retention enforcements */
|
|
166
|
+
retentionEnforcements: number
|
|
167
|
+
/** Total lifecycle enforcements */
|
|
168
|
+
lifecycleEnforcements: number
|
|
169
|
+
/** Last scheduler run timestamp */
|
|
170
|
+
lastRunAt: number | null
|
|
171
|
+
/** Last snapshot created timestamp */
|
|
172
|
+
lastSnapshotAt: number | null
|
|
173
|
+
/** Scheduled tables count */
|
|
174
|
+
scheduledTablesCount: number
|
|
175
|
+
/** Threshold-monitored tables count */
|
|
176
|
+
thresholdTablesCount: number
|
|
177
|
+
/** Size policy tables count */
|
|
178
|
+
sizePolicyTablesCount: number
|
|
179
|
+
/** Lifecycle policy tables count */
|
|
180
|
+
lifecyclePolicyTablesCount: number
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Snapshot creation result
|
|
185
|
+
*/
|
|
186
|
+
export interface SnapshotCreationResult {
|
|
187
|
+
/** Whether snapshot was created successfully */
|
|
188
|
+
success: boolean
|
|
189
|
+
/** Table identifier */
|
|
190
|
+
table: string
|
|
191
|
+
/** Created snapshot ID */
|
|
192
|
+
snapshotId: number | null
|
|
193
|
+
/** Trigger type */
|
|
194
|
+
trigger: 'schedule' | 'threshold' | 'size' | 'manual'
|
|
195
|
+
/** Duration in milliseconds */
|
|
196
|
+
durationMs: number
|
|
197
|
+
/** Error message if failed */
|
|
198
|
+
error?: string
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Lifecycle enforcement result
|
|
203
|
+
*/
|
|
204
|
+
export interface LifecycleEnforcementResult {
|
|
205
|
+
/** Table identifier */
|
|
206
|
+
table: string
|
|
207
|
+
/** Whether enforcement was successful */
|
|
208
|
+
success: boolean
|
|
209
|
+
/** Snapshots expired */
|
|
210
|
+
snapshotsExpired: number
|
|
211
|
+
/** Snapshots archived */
|
|
212
|
+
snapshotsArchived: number
|
|
213
|
+
/** Snapshots deleted */
|
|
214
|
+
snapshotsDeleted: number
|
|
215
|
+
/** Duration in milliseconds */
|
|
216
|
+
durationMs: number
|
|
217
|
+
/** Error message if failed */
|
|
218
|
+
error?: string
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Scheduler processing result
|
|
223
|
+
*/
|
|
224
|
+
export interface SchedulerProcessResult {
|
|
225
|
+
/** Snapshots created */
|
|
226
|
+
snapshotsCreated: SnapshotCreationResult[]
|
|
227
|
+
/** Retention enforcements performed */
|
|
228
|
+
retentionResults: ExpireSnapshotsResult[]
|
|
229
|
+
/** Lifecycle enforcement results */
|
|
230
|
+
lifecycleResults: LifecycleEnforcementResult[]
|
|
231
|
+
/** Total processing duration */
|
|
232
|
+
durationMs: number
|
|
233
|
+
/** Next alarm time (ISO timestamp) */
|
|
234
|
+
nextAlarmAt: string | null
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Snapshot scheduler configuration
|
|
239
|
+
*/
|
|
240
|
+
export interface SnapshotSchedulerConfig {
|
|
241
|
+
/** R2 bucket for Iceberg storage */
|
|
242
|
+
bucket: R2Bucket
|
|
243
|
+
/** Base path for tables in R2 */
|
|
244
|
+
tablePath: string
|
|
245
|
+
/** Durable Object state for persistence (optional) */
|
|
246
|
+
state?: DurableObjectState
|
|
247
|
+
/** Check interval for alarm scheduling (milliseconds, default: 60000 = 1 minute) */
|
|
248
|
+
checkIntervalMs?: number
|
|
249
|
+
/** Default retention policy for new schedules */
|
|
250
|
+
defaultRetention?: RetentionConfig
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ========== Storage Keys ==========
|
|
254
|
+
|
|
255
|
+
const SCHEDULES_KEY = '__iceberg_schedules__'
|
|
256
|
+
const THRESHOLDS_KEY = '__iceberg_thresholds__'
|
|
257
|
+
const SIZE_POLICIES_KEY = '__iceberg_size_policies__'
|
|
258
|
+
const LIFECYCLE_POLICIES_KEY = '__iceberg_lifecycle_policies__'
|
|
259
|
+
const STATS_KEY = '__iceberg_scheduler_stats__'
|
|
260
|
+
|
|
261
|
+
// ========== Cron Parsing ==========
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Parse cron expression and calculate next run time
|
|
265
|
+
*/
|
|
266
|
+
export function parseNextRun(cron: CronExpression, after: Date = new Date()): Date {
|
|
267
|
+
const parts = cron.trim().split(/\s+/)
|
|
268
|
+
if (parts.length !== 5) {
|
|
269
|
+
throw new Error(`Invalid cron expression: ${cron}. Expected 5 parts (minute hour day month dayOfWeek)`)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const minutePart = parts[0]
|
|
273
|
+
const hourPart = parts[1]
|
|
274
|
+
const dayPart = parts[2]
|
|
275
|
+
const monthPart = parts[3]
|
|
276
|
+
const dayOfWeekPart = parts[4]
|
|
277
|
+
|
|
278
|
+
if (!minutePart || !hourPart || !dayPart || !monthPart || !dayOfWeekPart) {
|
|
279
|
+
throw new Error(`Invalid cron expression: ${cron}. Expected 5 parts (minute hour day month dayOfWeek)`)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const now = new Date(after)
|
|
283
|
+
let next = new Date(now)
|
|
284
|
+
next.setSeconds(0)
|
|
285
|
+
next.setMilliseconds(0)
|
|
286
|
+
|
|
287
|
+
// Helper to parse cron field
|
|
288
|
+
const parseField = (field: string, min: number, max: number): number[] => {
|
|
289
|
+
if (field === '*') {
|
|
290
|
+
return Array.from({ length: max - min + 1 }, (_, i) => i + min)
|
|
291
|
+
}
|
|
292
|
+
if (field.includes(',')) {
|
|
293
|
+
return field.split(',').map(Number)
|
|
294
|
+
}
|
|
295
|
+
if (field.includes('/')) {
|
|
296
|
+
const splitParts = field.split('/')
|
|
297
|
+
const stepStr = splitParts[1]
|
|
298
|
+
if (!stepStr) return [min]
|
|
299
|
+
const stepNum = parseInt(stepStr, 10)
|
|
300
|
+
return Array.from({ length: Math.ceil((max - min + 1) / stepNum) }, (_, i) => min + i * stepNum).filter(n => n <= max)
|
|
301
|
+
}
|
|
302
|
+
if (field.includes('-')) {
|
|
303
|
+
const rangeParts = field.split('-').map(Number)
|
|
304
|
+
const start = rangeParts[0]
|
|
305
|
+
const end = rangeParts[1]
|
|
306
|
+
if (start === undefined || end === undefined || isNaN(start) || isNaN(end)) return [min]
|
|
307
|
+
return Array.from({ length: end - start + 1 }, (_, i) => start + i)
|
|
308
|
+
}
|
|
309
|
+
return [parseInt(field, 10)]
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const validMinutes = parseField(minutePart, 0, 59)
|
|
313
|
+
const validHours = parseField(hourPart, 0, 23)
|
|
314
|
+
const validDays = dayPart === '*' ? null : parseField(dayPart, 1, 31)
|
|
315
|
+
const validMonths = monthPart === '*' ? null : parseField(monthPart, 1, 12)
|
|
316
|
+
const validDaysOfWeek = dayOfWeekPart === '*' ? null : parseField(dayOfWeekPart, 0, 6)
|
|
317
|
+
|
|
318
|
+
// Start from next minute
|
|
319
|
+
next.setMinutes(next.getMinutes() + 1)
|
|
320
|
+
|
|
321
|
+
// Find next matching time (max 4 years to prevent infinite loops)
|
|
322
|
+
const maxIterations = 4 * 365 * 24 * 60
|
|
323
|
+
let iterations = 0
|
|
324
|
+
|
|
325
|
+
while (iterations < maxIterations) {
|
|
326
|
+
const minute = next.getMinutes()
|
|
327
|
+
const hour = next.getHours()
|
|
328
|
+
const day = next.getDate()
|
|
329
|
+
const month = next.getMonth() + 1
|
|
330
|
+
const dayOfWeek = next.getDay()
|
|
331
|
+
|
|
332
|
+
if (
|
|
333
|
+
validMinutes.includes(minute) &&
|
|
334
|
+
validHours.includes(hour) &&
|
|
335
|
+
(validDays === null || validDays.includes(day)) &&
|
|
336
|
+
(validMonths === null || validMonths.includes(month)) &&
|
|
337
|
+
(validDaysOfWeek === null || validDaysOfWeek.includes(dayOfWeek))
|
|
338
|
+
) {
|
|
339
|
+
return next
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Advance to next minute
|
|
343
|
+
next.setMinutes(next.getMinutes() + 1)
|
|
344
|
+
iterations++
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
throw new Error(`Failed to calculate next run time for cron: ${cron}`)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Check if a cron schedule is due to run
|
|
352
|
+
*/
|
|
353
|
+
export function isDue(schedule: SnapshotSchedule, now: Date = new Date()): boolean {
|
|
354
|
+
if (!schedule.enabled) {
|
|
355
|
+
return false
|
|
356
|
+
}
|
|
357
|
+
const nextRun = new Date(schedule.nextRun)
|
|
358
|
+
return now >= nextRun
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ========== Snapshot Scheduler Class ==========
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Snapshot Scheduler
|
|
365
|
+
*
|
|
366
|
+
* Manages automatic snapshot creation based on schedules and events.
|
|
367
|
+
*/
|
|
368
|
+
export class SnapshotScheduler {
|
|
369
|
+
private bucket: R2Bucket
|
|
370
|
+
private tablePath: string
|
|
371
|
+
private state: DurableObjectState | null
|
|
372
|
+
private defaultRetention: RetentionConfig
|
|
373
|
+
/** @internal Reserved for future alarm scheduling */
|
|
374
|
+
private _checkIntervalMs: number
|
|
375
|
+
|
|
376
|
+
private schedules: Map<string, SnapshotSchedule> = new Map()
|
|
377
|
+
private thresholds: Map<string, WriteThreshold> = new Map()
|
|
378
|
+
private sizePolicies: Map<string, SizePolicy> = new Map()
|
|
379
|
+
private lifecyclePolicies: Map<string, LifecyclePolicy> = new Map()
|
|
380
|
+
private stats: SchedulerStats = {
|
|
381
|
+
scheduledSnapshotsCreated: 0,
|
|
382
|
+
thresholdSnapshotsCreated: 0,
|
|
383
|
+
sizeSnapshotsCreated: 0,
|
|
384
|
+
retentionEnforcements: 0,
|
|
385
|
+
lifecycleEnforcements: 0,
|
|
386
|
+
lastRunAt: null,
|
|
387
|
+
lastSnapshotAt: null,
|
|
388
|
+
scheduledTablesCount: 0,
|
|
389
|
+
thresholdTablesCount: 0,
|
|
390
|
+
sizePolicyTablesCount: 0,
|
|
391
|
+
lifecyclePolicyTablesCount: 0,
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private initialized = false
|
|
395
|
+
|
|
396
|
+
constructor(config: SnapshotSchedulerConfig) {
|
|
397
|
+
this.bucket = config.bucket
|
|
398
|
+
this.tablePath = config.tablePath.replace(/\/$/, '')
|
|
399
|
+
this.state = config.state ?? null
|
|
400
|
+
this._checkIntervalMs = config.checkIntervalMs ?? 60000 // 1 minute
|
|
401
|
+
this.defaultRetention = config.defaultRetention ?? {}
|
|
402
|
+
void this._checkIntervalMs // Reserved for future alarm scheduling
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Initialize the scheduler
|
|
407
|
+
*/
|
|
408
|
+
async initialize(): Promise<void> {
|
|
409
|
+
if (this.initialized) {
|
|
410
|
+
return
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Load state from Durable Object storage if available
|
|
414
|
+
if (this.state) {
|
|
415
|
+
const schedulesData = await this.state.storage.get<SnapshotSchedule[]>(SCHEDULES_KEY)
|
|
416
|
+
if (schedulesData) {
|
|
417
|
+
for (const schedule of schedulesData) {
|
|
418
|
+
this.schedules.set(schedule.table, schedule)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const thresholdsData = await this.state.storage.get<WriteThreshold[]>(THRESHOLDS_KEY)
|
|
423
|
+
if (thresholdsData) {
|
|
424
|
+
for (const threshold of thresholdsData) {
|
|
425
|
+
this.thresholds.set(threshold.table, threshold)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const sizePoliciesData = await this.state.storage.get<SizePolicy[]>(SIZE_POLICIES_KEY)
|
|
430
|
+
if (sizePoliciesData) {
|
|
431
|
+
for (const policy of sizePoliciesData) {
|
|
432
|
+
this.sizePolicies.set(policy.table, policy)
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const lifecyclePoliciesData = await this.state.storage.get<LifecyclePolicy[]>(LIFECYCLE_POLICIES_KEY)
|
|
437
|
+
if (lifecyclePoliciesData) {
|
|
438
|
+
for (const policy of lifecyclePoliciesData) {
|
|
439
|
+
this.lifecyclePolicies.set(policy.table, policy)
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const statsData = await this.state.storage.get<SchedulerStats>(STATS_KEY)
|
|
444
|
+
if (statsData) {
|
|
445
|
+
this.stats = statsData
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
this.initialized = true
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Ensure initialized
|
|
454
|
+
*/
|
|
455
|
+
private ensureInitialized(): void {
|
|
456
|
+
if (!this.initialized) {
|
|
457
|
+
throw new Error('SnapshotScheduler not initialized. Call initialize() first.')
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Save state to Durable Object storage
|
|
463
|
+
*/
|
|
464
|
+
private async saveState(): Promise<void> {
|
|
465
|
+
if (!this.state) {
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
await this.state.storage.put(SCHEDULES_KEY, Array.from(this.schedules.values()))
|
|
470
|
+
await this.state.storage.put(THRESHOLDS_KEY, Array.from(this.thresholds.values()))
|
|
471
|
+
await this.state.storage.put(SIZE_POLICIES_KEY, Array.from(this.sizePolicies.values()))
|
|
472
|
+
await this.state.storage.put(LIFECYCLE_POLICIES_KEY, Array.from(this.lifecyclePolicies.values()))
|
|
473
|
+
await this.state.storage.put(STATS_KEY, this.stats)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// ========== Schedule Management ==========
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Schedule automatic snapshots for a table
|
|
480
|
+
*
|
|
481
|
+
* @param table - Table identifier
|
|
482
|
+
* @param cron - Cron expression (e.g., "0 * * * *" for hourly)
|
|
483
|
+
* @param retentionPolicy - Optional retention policy
|
|
484
|
+
*/
|
|
485
|
+
async schedule(
|
|
486
|
+
table: string,
|
|
487
|
+
cron: CronExpression,
|
|
488
|
+
retentionPolicy?: RetentionConfig
|
|
489
|
+
): Promise<SnapshotSchedule> {
|
|
490
|
+
this.ensureInitialized()
|
|
491
|
+
|
|
492
|
+
// Validate cron expression by calculating next run
|
|
493
|
+
const nextRun = parseNextRun(cron)
|
|
494
|
+
|
|
495
|
+
const schedule: SnapshotSchedule = {
|
|
496
|
+
table,
|
|
497
|
+
cron,
|
|
498
|
+
nextRun: nextRun.toISOString(),
|
|
499
|
+
lastRun: null,
|
|
500
|
+
enabled: true,
|
|
501
|
+
retentionPolicy: retentionPolicy ?? this.defaultRetention,
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
this.schedules.set(table, schedule)
|
|
505
|
+
this.stats.scheduledTablesCount = this.schedules.size
|
|
506
|
+
|
|
507
|
+
await this.saveState()
|
|
508
|
+
await this.updateAlarm()
|
|
509
|
+
|
|
510
|
+
return schedule
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Unschedule snapshots for a table
|
|
515
|
+
*/
|
|
516
|
+
async unschedule(table: string): Promise<boolean> {
|
|
517
|
+
this.ensureInitialized()
|
|
518
|
+
|
|
519
|
+
const deleted = this.schedules.delete(table)
|
|
520
|
+
this.stats.scheduledTablesCount = this.schedules.size
|
|
521
|
+
|
|
522
|
+
if (deleted) {
|
|
523
|
+
await this.saveState()
|
|
524
|
+
await this.updateAlarm()
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return deleted
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Enable or disable a schedule
|
|
532
|
+
*/
|
|
533
|
+
async toggleSchedule(table: string, enabled: boolean): Promise<SnapshotSchedule | null> {
|
|
534
|
+
this.ensureInitialized()
|
|
535
|
+
|
|
536
|
+
const schedule = this.schedules.get(table)
|
|
537
|
+
if (!schedule) {
|
|
538
|
+
return null
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
schedule.enabled = enabled
|
|
542
|
+
this.schedules.set(table, schedule)
|
|
543
|
+
|
|
544
|
+
await this.saveState()
|
|
545
|
+
await this.updateAlarm()
|
|
546
|
+
|
|
547
|
+
return schedule
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Get schedule for a table
|
|
552
|
+
*/
|
|
553
|
+
getSchedule(table: string): SnapshotSchedule | null {
|
|
554
|
+
this.ensureInitialized()
|
|
555
|
+
return this.schedules.get(table) ?? null
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* List all scheduled snapshots
|
|
560
|
+
*/
|
|
561
|
+
listScheduled(): SnapshotSchedule[] {
|
|
562
|
+
this.ensureInitialized()
|
|
563
|
+
return Array.from(this.schedules.values())
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// ========== Write Threshold Management ==========
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Set write count threshold for automatic snapshots
|
|
570
|
+
*
|
|
571
|
+
* @param table - Table identifier
|
|
572
|
+
* @param writeCount - Number of writes before triggering snapshot
|
|
573
|
+
*/
|
|
574
|
+
async setThreshold(table: string, writeCount: number): Promise<WriteThreshold> {
|
|
575
|
+
this.ensureInitialized()
|
|
576
|
+
|
|
577
|
+
if (writeCount <= 0) {
|
|
578
|
+
throw new Error('Write count must be positive')
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const threshold: WriteThreshold = {
|
|
582
|
+
table,
|
|
583
|
+
writeCount,
|
|
584
|
+
currentCount: 0,
|
|
585
|
+
enabled: true,
|
|
586
|
+
lastSnapshot: null,
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
this.thresholds.set(table, threshold)
|
|
590
|
+
this.stats.thresholdTablesCount = this.thresholds.size
|
|
591
|
+
|
|
592
|
+
await this.saveState()
|
|
593
|
+
|
|
594
|
+
return threshold
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Remove write threshold for a table
|
|
599
|
+
*/
|
|
600
|
+
async removeThreshold(table: string): Promise<boolean> {
|
|
601
|
+
this.ensureInitialized()
|
|
602
|
+
|
|
603
|
+
const deleted = this.thresholds.delete(table)
|
|
604
|
+
this.stats.thresholdTablesCount = this.thresholds.size
|
|
605
|
+
|
|
606
|
+
if (deleted) {
|
|
607
|
+
await this.saveState()
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return deleted
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Increment write count for a table
|
|
615
|
+
*
|
|
616
|
+
* Returns true if threshold was reached and snapshot should be created.
|
|
617
|
+
*/
|
|
618
|
+
async incrementWriteCount(table: string, count: number = 1): Promise<boolean> {
|
|
619
|
+
this.ensureInitialized()
|
|
620
|
+
|
|
621
|
+
const threshold = this.thresholds.get(table)
|
|
622
|
+
if (!threshold || !threshold.enabled) {
|
|
623
|
+
return false
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
threshold.currentCount += count
|
|
627
|
+
|
|
628
|
+
const shouldSnapshot = threshold.currentCount >= threshold.writeCount
|
|
629
|
+
|
|
630
|
+
if (shouldSnapshot) {
|
|
631
|
+
// Reset counter
|
|
632
|
+
threshold.currentCount = 0
|
|
633
|
+
threshold.lastSnapshot = new Date().toISOString()
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
this.thresholds.set(table, threshold)
|
|
637
|
+
await this.saveState()
|
|
638
|
+
|
|
639
|
+
return shouldSnapshot
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Get write threshold for a table
|
|
644
|
+
*/
|
|
645
|
+
getThreshold(table: string): WriteThreshold | null {
|
|
646
|
+
this.ensureInitialized()
|
|
647
|
+
return this.thresholds.get(table) ?? null
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* List all write thresholds
|
|
652
|
+
*/
|
|
653
|
+
listThresholds(): WriteThreshold[] {
|
|
654
|
+
this.ensureInitialized()
|
|
655
|
+
return Array.from(this.thresholds.values())
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// ========== Size Policy Management ==========
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Set size-based policy for automatic snapshots
|
|
662
|
+
*
|
|
663
|
+
* @param table - Table identifier
|
|
664
|
+
* @param sizeThresholdBytes - Size threshold in bytes before triggering snapshot
|
|
665
|
+
*/
|
|
666
|
+
async setSizePolicy(table: string, sizeThresholdBytes: number): Promise<SizePolicy> {
|
|
667
|
+
this.ensureInitialized()
|
|
668
|
+
|
|
669
|
+
if (sizeThresholdBytes <= 0) {
|
|
670
|
+
throw new Error('Size threshold must be positive')
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const policy: SizePolicy = {
|
|
674
|
+
table,
|
|
675
|
+
sizeThresholdBytes,
|
|
676
|
+
currentSizeBytes: 0,
|
|
677
|
+
enabled: true,
|
|
678
|
+
lastSnapshot: null,
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
this.sizePolicies.set(table, policy)
|
|
682
|
+
this.stats.sizePolicyTablesCount = this.sizePolicies.size
|
|
683
|
+
|
|
684
|
+
await this.saveState()
|
|
685
|
+
|
|
686
|
+
return policy
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Remove size policy for a table
|
|
691
|
+
*/
|
|
692
|
+
async removeSizePolicy(table: string): Promise<boolean> {
|
|
693
|
+
this.ensureInitialized()
|
|
694
|
+
|
|
695
|
+
const deleted = this.sizePolicies.delete(table)
|
|
696
|
+
this.stats.sizePolicyTablesCount = this.sizePolicies.size
|
|
697
|
+
|
|
698
|
+
if (deleted) {
|
|
699
|
+
await this.saveState()
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return deleted
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Increment size for a table
|
|
707
|
+
*
|
|
708
|
+
* Returns true if threshold was reached and snapshot should be created.
|
|
709
|
+
*/
|
|
710
|
+
async incrementSize(table: string, bytes: number): Promise<boolean> {
|
|
711
|
+
this.ensureInitialized()
|
|
712
|
+
|
|
713
|
+
const policy = this.sizePolicies.get(table)
|
|
714
|
+
if (!policy || !policy.enabled) {
|
|
715
|
+
return false
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
policy.currentSizeBytes += bytes
|
|
719
|
+
|
|
720
|
+
const shouldSnapshot = policy.currentSizeBytes >= policy.sizeThresholdBytes
|
|
721
|
+
|
|
722
|
+
if (shouldSnapshot) {
|
|
723
|
+
// Reset counter
|
|
724
|
+
policy.currentSizeBytes = 0
|
|
725
|
+
policy.lastSnapshot = new Date().toISOString()
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
this.sizePolicies.set(table, policy)
|
|
729
|
+
await this.saveState()
|
|
730
|
+
|
|
731
|
+
return shouldSnapshot
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Get size policy for a table
|
|
736
|
+
*/
|
|
737
|
+
getSizePolicy(table: string): SizePolicy | null {
|
|
738
|
+
this.ensureInitialized()
|
|
739
|
+
return this.sizePolicies.get(table) ?? null
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* List all size policies
|
|
744
|
+
*/
|
|
745
|
+
listSizePolicies(): SizePolicy[] {
|
|
746
|
+
this.ensureInitialized()
|
|
747
|
+
return Array.from(this.sizePolicies.values())
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// ========== Lifecycle Policy Management ==========
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Set lifecycle policy for a table
|
|
754
|
+
*
|
|
755
|
+
* @param table - Table identifier
|
|
756
|
+
* @param retention - Retention configuration
|
|
757
|
+
* @param options - Additional lifecycle options
|
|
758
|
+
*/
|
|
759
|
+
async setLifecyclePolicy(
|
|
760
|
+
table: string,
|
|
761
|
+
retention: RetentionConfig,
|
|
762
|
+
options?: {
|
|
763
|
+
expirationTimestamp?: string
|
|
764
|
+
archiveAfterDays?: number
|
|
765
|
+
deleteAfterDays?: number
|
|
766
|
+
}
|
|
767
|
+
): Promise<LifecyclePolicy> {
|
|
768
|
+
this.ensureInitialized()
|
|
769
|
+
|
|
770
|
+
const policy: LifecyclePolicy = {
|
|
771
|
+
table,
|
|
772
|
+
enabled: true,
|
|
773
|
+
retention,
|
|
774
|
+
lastEnforcementAt: null,
|
|
775
|
+
}
|
|
776
|
+
if (options?.expirationTimestamp !== undefined) {
|
|
777
|
+
policy.expirationTimestamp = options.expirationTimestamp
|
|
778
|
+
}
|
|
779
|
+
if (options?.archiveAfterDays !== undefined) {
|
|
780
|
+
policy.archiveAfterDays = options.archiveAfterDays
|
|
781
|
+
}
|
|
782
|
+
if (options?.deleteAfterDays !== undefined) {
|
|
783
|
+
policy.deleteAfterDays = options.deleteAfterDays
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
this.lifecyclePolicies.set(table, policy)
|
|
787
|
+
this.stats.lifecyclePolicyTablesCount = this.lifecyclePolicies.size
|
|
788
|
+
|
|
789
|
+
await this.saveState()
|
|
790
|
+
|
|
791
|
+
return policy
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Remove lifecycle policy for a table
|
|
796
|
+
*/
|
|
797
|
+
async removeLifecyclePolicy(table: string): Promise<boolean> {
|
|
798
|
+
this.ensureInitialized()
|
|
799
|
+
|
|
800
|
+
const deleted = this.lifecyclePolicies.delete(table)
|
|
801
|
+
this.stats.lifecyclePolicyTablesCount = this.lifecyclePolicies.size
|
|
802
|
+
|
|
803
|
+
if (deleted) {
|
|
804
|
+
await this.saveState()
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
return deleted
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Toggle lifecycle policy enabled state
|
|
812
|
+
*/
|
|
813
|
+
async toggleLifecyclePolicy(table: string, enabled: boolean): Promise<LifecyclePolicy | null> {
|
|
814
|
+
this.ensureInitialized()
|
|
815
|
+
|
|
816
|
+
const policy = this.lifecyclePolicies.get(table)
|
|
817
|
+
if (!policy) {
|
|
818
|
+
return null
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
policy.enabled = enabled
|
|
822
|
+
this.lifecyclePolicies.set(table, policy)
|
|
823
|
+
|
|
824
|
+
await this.saveState()
|
|
825
|
+
|
|
826
|
+
return policy
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Get lifecycle policy for a table
|
|
831
|
+
*/
|
|
832
|
+
getLifecyclePolicy(table: string): LifecyclePolicy | null {
|
|
833
|
+
this.ensureInitialized()
|
|
834
|
+
return this.lifecyclePolicies.get(table) ?? null
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* List all lifecycle policies
|
|
839
|
+
*/
|
|
840
|
+
listLifecyclePolicies(): LifecyclePolicy[] {
|
|
841
|
+
this.ensureInitialized()
|
|
842
|
+
return Array.from(this.lifecyclePolicies.values())
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Enforce lifecycle policy for a table
|
|
847
|
+
*
|
|
848
|
+
* This handles expiration, archival, and deletion based on the policy configuration.
|
|
849
|
+
*/
|
|
850
|
+
async enforceLifecyclePolicy(table: string): Promise<LifecycleEnforcementResult> {
|
|
851
|
+
this.ensureInitialized()
|
|
852
|
+
|
|
853
|
+
const startTime = performance.now()
|
|
854
|
+
const policy = this.lifecyclePolicies.get(table)
|
|
855
|
+
|
|
856
|
+
if (!policy || !policy.enabled) {
|
|
857
|
+
return {
|
|
858
|
+
table,
|
|
859
|
+
success: false,
|
|
860
|
+
snapshotsExpired: 0,
|
|
861
|
+
snapshotsArchived: 0,
|
|
862
|
+
snapshotsDeleted: 0,
|
|
863
|
+
durationMs: performance.now() - startTime,
|
|
864
|
+
error: 'Lifecycle policy not found or disabled',
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
try {
|
|
869
|
+
const manager = createSnapshotManager({
|
|
870
|
+
bucket: this.bucket,
|
|
871
|
+
tablePath: `${this.tablePath}/${table}`,
|
|
872
|
+
})
|
|
873
|
+
|
|
874
|
+
await manager.initialize()
|
|
875
|
+
|
|
876
|
+
let snapshotsExpired = 0
|
|
877
|
+
let snapshotsArchived = 0
|
|
878
|
+
let snapshotsDeleted = 0
|
|
879
|
+
|
|
880
|
+
// Determine effective retention based on expiration timestamp
|
|
881
|
+
const effectiveRetention = { ...policy.retention }
|
|
882
|
+
|
|
883
|
+
if (policy.expirationTimestamp) {
|
|
884
|
+
const expirationDate = new Date(policy.expirationTimestamp)
|
|
885
|
+
const now = new Date()
|
|
886
|
+
const ageInDays = Math.floor((now.getTime() - expirationDate.getTime()) / (24 * 60 * 60 * 1000))
|
|
887
|
+
|
|
888
|
+
// If we're past the expiration timestamp, enforce stricter retention
|
|
889
|
+
if (ageInDays > 0) {
|
|
890
|
+
effectiveRetention.maxAgeDays = Math.min(
|
|
891
|
+
effectiveRetention.maxAgeDays ?? Infinity,
|
|
892
|
+
ageInDays
|
|
893
|
+
)
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// Expire snapshots based on retention
|
|
898
|
+
const expirationResult = await manager.expireSnapshots(effectiveRetention)
|
|
899
|
+
snapshotsExpired = expirationResult.snapshotsExpired
|
|
900
|
+
|
|
901
|
+
// Note: Archive and delete operations would require additional R2 storage class support
|
|
902
|
+
// For now, we track the intent but rely on R2 lifecycle rules for actual archival
|
|
903
|
+
|
|
904
|
+
// Update policy
|
|
905
|
+
policy.lastEnforcementAt = new Date().toISOString()
|
|
906
|
+
this.lifecyclePolicies.set(table, policy)
|
|
907
|
+
|
|
908
|
+
this.stats.lifecycleEnforcements++
|
|
909
|
+
await this.saveState()
|
|
910
|
+
|
|
911
|
+
return {
|
|
912
|
+
table,
|
|
913
|
+
success: true,
|
|
914
|
+
snapshotsExpired,
|
|
915
|
+
snapshotsArchived,
|
|
916
|
+
snapshotsDeleted,
|
|
917
|
+
durationMs: performance.now() - startTime,
|
|
918
|
+
}
|
|
919
|
+
} catch (error) {
|
|
920
|
+
return {
|
|
921
|
+
table,
|
|
922
|
+
success: false,
|
|
923
|
+
snapshotsExpired: 0,
|
|
924
|
+
snapshotsArchived: 0,
|
|
925
|
+
snapshotsDeleted: 0,
|
|
926
|
+
durationMs: performance.now() - startTime,
|
|
927
|
+
error: error instanceof Error ? error.message : String(error),
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// ========== Snapshot Creation ==========
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Create a snapshot for a table
|
|
936
|
+
*/
|
|
937
|
+
private async createSnapshot(
|
|
938
|
+
table: string,
|
|
939
|
+
trigger: 'schedule' | 'threshold' | 'size' | 'manual'
|
|
940
|
+
): Promise<SnapshotCreationResult> {
|
|
941
|
+
const startTime = performance.now()
|
|
942
|
+
|
|
943
|
+
try {
|
|
944
|
+
// Create snapshot manager for the table
|
|
945
|
+
const manager = createSnapshotManager({
|
|
946
|
+
bucket: this.bucket,
|
|
947
|
+
tablePath: `${this.tablePath}/${table}`,
|
|
948
|
+
})
|
|
949
|
+
|
|
950
|
+
await manager.initialize()
|
|
951
|
+
|
|
952
|
+
// Get current snapshot
|
|
953
|
+
const currentSnapshot = manager.getCurrentSnapshot()
|
|
954
|
+
|
|
955
|
+
// If no changes since last snapshot, skip
|
|
956
|
+
if (currentSnapshot && trigger !== 'manual') {
|
|
957
|
+
// For now, we create a new snapshot anyway
|
|
958
|
+
// In a real implementation, we would check if there are new writes
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// Create new snapshot (placeholder - would integrate with WAL writer)
|
|
962
|
+
// For now, we just verify the table exists
|
|
963
|
+
const metadata = manager.getMetadata()
|
|
964
|
+
if (!metadata) {
|
|
965
|
+
throw new Error(`Table not found: ${table}`)
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const snapshotId = currentSnapshot?.snapshotId ?? null
|
|
969
|
+
|
|
970
|
+
this.stats.lastSnapshotAt = Date.now()
|
|
971
|
+
if (trigger === 'schedule') {
|
|
972
|
+
this.stats.scheduledSnapshotsCreated++
|
|
973
|
+
} else if (trigger === 'threshold') {
|
|
974
|
+
this.stats.thresholdSnapshotsCreated++
|
|
975
|
+
} else if (trigger === 'size') {
|
|
976
|
+
this.stats.sizeSnapshotsCreated++
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
await this.saveState()
|
|
980
|
+
|
|
981
|
+
return {
|
|
982
|
+
success: true,
|
|
983
|
+
table,
|
|
984
|
+
snapshotId,
|
|
985
|
+
trigger,
|
|
986
|
+
durationMs: performance.now() - startTime,
|
|
987
|
+
}
|
|
988
|
+
} catch (error) {
|
|
989
|
+
return {
|
|
990
|
+
success: false,
|
|
991
|
+
table,
|
|
992
|
+
snapshotId: null,
|
|
993
|
+
trigger,
|
|
994
|
+
durationMs: performance.now() - startTime,
|
|
995
|
+
error: error instanceof Error ? error.message : String(error),
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// ========== Retention Enforcement ==========
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Enforce retention policy for a table
|
|
1004
|
+
*/
|
|
1005
|
+
async enforceRetention(table: string, policy: RetentionConfig): Promise<ExpireSnapshotsResult> {
|
|
1006
|
+
this.ensureInitialized()
|
|
1007
|
+
|
|
1008
|
+
const manager = createSnapshotManager({
|
|
1009
|
+
bucket: this.bucket,
|
|
1010
|
+
tablePath: `${this.tablePath}/${table}`,
|
|
1011
|
+
})
|
|
1012
|
+
|
|
1013
|
+
await manager.initialize()
|
|
1014
|
+
|
|
1015
|
+
const result = await manager.expireSnapshots(policy)
|
|
1016
|
+
|
|
1017
|
+
this.stats.retentionEnforcements++
|
|
1018
|
+
await this.saveState()
|
|
1019
|
+
|
|
1020
|
+
return result
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// ========== Scheduled Processing ==========
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Process due snapshots (called by cron trigger or alarm)
|
|
1027
|
+
*/
|
|
1028
|
+
async processDueSnapshots(): Promise<SchedulerProcessResult> {
|
|
1029
|
+
this.ensureInitialized()
|
|
1030
|
+
|
|
1031
|
+
const startTime = performance.now()
|
|
1032
|
+
const now = new Date()
|
|
1033
|
+
const snapshotsCreated: SnapshotCreationResult[] = []
|
|
1034
|
+
const retentionResults: ExpireSnapshotsResult[] = []
|
|
1035
|
+
const lifecycleResults: LifecycleEnforcementResult[] = []
|
|
1036
|
+
|
|
1037
|
+
// Process scheduled snapshots
|
|
1038
|
+
for (const schedule of this.schedules.values()) {
|
|
1039
|
+
if (isDue(schedule, now)) {
|
|
1040
|
+
const result = await this.createSnapshot(schedule.table, 'schedule')
|
|
1041
|
+
snapshotsCreated.push(result)
|
|
1042
|
+
|
|
1043
|
+
// Update schedule
|
|
1044
|
+
schedule.lastRun = now.toISOString()
|
|
1045
|
+
schedule.nextRun = parseNextRun(schedule.cron, now).toISOString()
|
|
1046
|
+
this.schedules.set(schedule.table, schedule)
|
|
1047
|
+
|
|
1048
|
+
// Enforce retention if configured
|
|
1049
|
+
if (schedule.retentionPolicy) {
|
|
1050
|
+
const retentionResult = await this.enforceRetention(
|
|
1051
|
+
schedule.table,
|
|
1052
|
+
schedule.retentionPolicy
|
|
1053
|
+
)
|
|
1054
|
+
retentionResults.push(retentionResult)
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// Process lifecycle policies
|
|
1060
|
+
for (const policy of this.lifecyclePolicies.values()) {
|
|
1061
|
+
if (policy.enabled) {
|
|
1062
|
+
const result = await this.enforceLifecyclePolicy(policy.table)
|
|
1063
|
+
lifecycleResults.push(result)
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
this.stats.lastRunAt = Date.now()
|
|
1068
|
+
await this.saveState()
|
|
1069
|
+
|
|
1070
|
+
// Update alarm for next run
|
|
1071
|
+
const nextAlarmAt = await this.updateAlarm()
|
|
1072
|
+
|
|
1073
|
+
return {
|
|
1074
|
+
snapshotsCreated,
|
|
1075
|
+
retentionResults,
|
|
1076
|
+
lifecycleResults,
|
|
1077
|
+
durationMs: performance.now() - startTime,
|
|
1078
|
+
nextAlarmAt: nextAlarmAt ? new Date(nextAlarmAt).toISOString() : null,
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Update Durable Object alarm to next scheduled run
|
|
1084
|
+
*
|
|
1085
|
+
* Returns the next alarm time in milliseconds, or null if no schedules.
|
|
1086
|
+
*/
|
|
1087
|
+
private async updateAlarm(): Promise<number | null> {
|
|
1088
|
+
if (!this.state) {
|
|
1089
|
+
return null
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
let nextRun: Date | null = null
|
|
1093
|
+
|
|
1094
|
+
// Find earliest next run time
|
|
1095
|
+
for (const schedule of this.schedules.values()) {
|
|
1096
|
+
if (!schedule.enabled) {
|
|
1097
|
+
continue
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
const scheduleNextRun = new Date(schedule.nextRun)
|
|
1101
|
+
if (!nextRun || scheduleNextRun < nextRun) {
|
|
1102
|
+
nextRun = scheduleNextRun
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
if (!nextRun) {
|
|
1107
|
+
return null
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Set alarm
|
|
1111
|
+
const alarmTime = nextRun.getTime()
|
|
1112
|
+
await this.state.storage.setAlarm(alarmTime)
|
|
1113
|
+
|
|
1114
|
+
return alarmTime
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// ========== Statistics ==========
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Get scheduler statistics
|
|
1121
|
+
*/
|
|
1122
|
+
getStats(): SchedulerStats {
|
|
1123
|
+
this.ensureInitialized()
|
|
1124
|
+
return { ...this.stats }
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* Reset statistics
|
|
1129
|
+
*/
|
|
1130
|
+
async resetStats(): Promise<void> {
|
|
1131
|
+
this.ensureInitialized()
|
|
1132
|
+
|
|
1133
|
+
this.stats = {
|
|
1134
|
+
scheduledSnapshotsCreated: 0,
|
|
1135
|
+
thresholdSnapshotsCreated: 0,
|
|
1136
|
+
sizeSnapshotsCreated: 0,
|
|
1137
|
+
retentionEnforcements: 0,
|
|
1138
|
+
lifecycleEnforcements: 0,
|
|
1139
|
+
lastRunAt: null,
|
|
1140
|
+
lastSnapshotAt: null,
|
|
1141
|
+
scheduledTablesCount: this.schedules.size,
|
|
1142
|
+
thresholdTablesCount: this.thresholds.size,
|
|
1143
|
+
sizePolicyTablesCount: this.sizePolicies.size,
|
|
1144
|
+
lifecyclePolicyTablesCount: this.lifecyclePolicies.size,
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
await this.saveState()
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// ========== Factory Function ==========
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Create a snapshot scheduler
|
|
1155
|
+
*/
|
|
1156
|
+
export function createSnapshotScheduler(config: SnapshotSchedulerConfig): SnapshotScheduler {
|
|
1157
|
+
return new SnapshotScheduler(config)
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// ========== Cloudflare Cron Integration ==========
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Cron trigger configuration for Cloudflare Workers
|
|
1164
|
+
*
|
|
1165
|
+
* Add to wrangler.toml:
|
|
1166
|
+
* ```toml
|
|
1167
|
+
* [triggers]
|
|
1168
|
+
* crons = ["0 * * * *"] # Hourly
|
|
1169
|
+
* ```
|
|
1170
|
+
*
|
|
1171
|
+
* In your worker:
|
|
1172
|
+
* ```typescript
|
|
1173
|
+
* export default {
|
|
1174
|
+
* async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext) {
|
|
1175
|
+
* await handleScheduledSnapshots(event, env, ctx)
|
|
1176
|
+
* }
|
|
1177
|
+
* }
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
export async function handleScheduledSnapshots(
|
|
1181
|
+
_event: ScheduledEvent,
|
|
1182
|
+
env: { ICEBERG_BUCKET: R2Bucket; ICEBERG_SCHEDULER_DO?: DurableObjectNamespace },
|
|
1183
|
+
ctx: ExecutionContext
|
|
1184
|
+
): Promise<void> {
|
|
1185
|
+
// Use Durable Object for coordination if available
|
|
1186
|
+
if (env.ICEBERG_SCHEDULER_DO) {
|
|
1187
|
+
const id = env.ICEBERG_SCHEDULER_DO.idFromName('global-scheduler')
|
|
1188
|
+
const stub = env.ICEBERG_SCHEDULER_DO.get(id)
|
|
1189
|
+
ctx.waitUntil(stub.fetch('https://scheduler/process'))
|
|
1190
|
+
return
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// Fallback to direct processing
|
|
1194
|
+
const scheduler = createSnapshotScheduler({
|
|
1195
|
+
bucket: env.ICEBERG_BUCKET,
|
|
1196
|
+
tablePath: 'iceberg',
|
|
1197
|
+
})
|
|
1198
|
+
|
|
1199
|
+
await scheduler.initialize()
|
|
1200
|
+
await scheduler.processDueSnapshots()
|
|
1201
|
+
}
|