@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,858 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geospatial Extension Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides helpers for working with PostgreSQL's native geographic types
|
|
5
|
+
* and the earthdistance + cube extensions for location-based queries.
|
|
6
|
+
*
|
|
7
|
+
* Since PostGIS is not available in PGLite, this module provides alternatives:
|
|
8
|
+
* - earthdistance: Calculate great circle distances between lat/long coordinates
|
|
9
|
+
* - cube: Multi-dimensional data type required by earthdistance
|
|
10
|
+
* - Native PostgreSQL geometric types: point, box, polygon, circle, path, line, lseg
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { GeoExtension, GeoPoint, parsePoint, serializePoint } from '@dotdo/postgres/extensions'
|
|
15
|
+
*
|
|
16
|
+
* // Create a table for locations with a point column
|
|
17
|
+
* const sql = GeoExtension.createLocationTableSQL('locations', { idColumn: 'uuid' })
|
|
18
|
+
*
|
|
19
|
+
* // Find locations within 10km of a coordinate
|
|
20
|
+
* const searchSQL = GeoExtension.findWithinRadiusSQL(
|
|
21
|
+
* 'locations',
|
|
22
|
+
* { lat: 37.7749, lng: -122.4194 },
|
|
23
|
+
* 10,
|
|
24
|
+
* 'km'
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Parse PostgreSQL point string
|
|
28
|
+
* const point = parsePoint('(37.7749,-122.4194)')
|
|
29
|
+
* // { lat: 37.7749, lng: -122.4194 }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module extensions/geo
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import type { ExtensionDefinition } from './registry'
|
|
36
|
+
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Types
|
|
39
|
+
// ============================================================================
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Geographic point with latitude and longitude
|
|
43
|
+
*/
|
|
44
|
+
export interface GeoPoint {
|
|
45
|
+
/** Latitude in degrees (-90 to 90) */
|
|
46
|
+
lat: number
|
|
47
|
+
/** Longitude in degrees (-180 to 180) */
|
|
48
|
+
lng: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* PostgreSQL native point type (x, y)
|
|
53
|
+
*
|
|
54
|
+
* Note: PostgreSQL's point type uses (x, y) coordinates.
|
|
55
|
+
* For geographic data, x = longitude, y = latitude (reversed from GeoPoint).
|
|
56
|
+
*/
|
|
57
|
+
export interface Point {
|
|
58
|
+
x: number
|
|
59
|
+
y: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Bounding box defined by two corners
|
|
64
|
+
*/
|
|
65
|
+
export interface BoundingBox {
|
|
66
|
+
/** Southwest corner (min lat/lng) */
|
|
67
|
+
sw: GeoPoint
|
|
68
|
+
/** Northeast corner (max lat/lng) */
|
|
69
|
+
ne: GeoPoint
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* PostgreSQL native box type (upper right, lower left corners)
|
|
74
|
+
*/
|
|
75
|
+
export interface Box {
|
|
76
|
+
high: Point
|
|
77
|
+
low: Point
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Polygon defined by a list of vertices
|
|
82
|
+
*/
|
|
83
|
+
export interface Polygon {
|
|
84
|
+
vertices: GeoPoint[]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Circle defined by center point and radius
|
|
89
|
+
*/
|
|
90
|
+
export interface Circle {
|
|
91
|
+
center: GeoPoint
|
|
92
|
+
/** Radius in the specified unit */
|
|
93
|
+
radius: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Distance units supported by earthdistance calculations
|
|
98
|
+
*/
|
|
99
|
+
export type DistanceUnit = 'meters' | 'm' | 'kilometers' | 'km' | 'miles' | 'mi' | 'nautical_miles' | 'nm'
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Options for creating location tables
|
|
103
|
+
*/
|
|
104
|
+
export interface LocationTableOptions {
|
|
105
|
+
/** Additional columns to include */
|
|
106
|
+
additionalColumns?: string
|
|
107
|
+
/** Primary key column type: 'serial' | 'uuid' | 'bigserial' */
|
|
108
|
+
idColumn?: 'serial' | 'uuid' | 'bigserial'
|
|
109
|
+
/** Name column for the location */
|
|
110
|
+
includeNameColumn?: boolean
|
|
111
|
+
/** Description column */
|
|
112
|
+
includeDescriptionColumn?: boolean
|
|
113
|
+
/** Created/updated timestamps */
|
|
114
|
+
includeTimestamps?: boolean
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Options for radius search queries
|
|
119
|
+
*/
|
|
120
|
+
export interface RadiusSearchOptions {
|
|
121
|
+
/** Column name for latitude (default: 'latitude') */
|
|
122
|
+
latColumn?: string
|
|
123
|
+
/** Column name for longitude (default: 'longitude') */
|
|
124
|
+
lngColumn?: string
|
|
125
|
+
/** Columns to select (default: '*') */
|
|
126
|
+
select?: string | string[]
|
|
127
|
+
/** Additional WHERE conditions */
|
|
128
|
+
where?: string
|
|
129
|
+
/** ORDER BY clause (default: distance ascending) */
|
|
130
|
+
orderBy?: string
|
|
131
|
+
/** Maximum results to return */
|
|
132
|
+
limit?: number
|
|
133
|
+
/** Include distance in results */
|
|
134
|
+
includeDistance?: boolean
|
|
135
|
+
/** Alias for distance column (default: 'distance') */
|
|
136
|
+
distanceAlias?: string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Options for bounding box search queries
|
|
141
|
+
*/
|
|
142
|
+
export interface BoundingBoxSearchOptions {
|
|
143
|
+
/** Column name for latitude (default: 'latitude') */
|
|
144
|
+
latColumn?: string
|
|
145
|
+
/** Column name for longitude (default: 'longitude') */
|
|
146
|
+
lngColumn?: string
|
|
147
|
+
/** Columns to select (default: '*') */
|
|
148
|
+
select?: string | string[]
|
|
149
|
+
/** Additional WHERE conditions */
|
|
150
|
+
where?: string
|
|
151
|
+
/** ORDER BY clause */
|
|
152
|
+
orderBy?: string
|
|
153
|
+
/** Maximum results to return */
|
|
154
|
+
limit?: number
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ============================================================================
|
|
158
|
+
// Constants
|
|
159
|
+
// ============================================================================
|
|
160
|
+
|
|
161
|
+
/** Earth radius in meters (used by earthdistance extension) */
|
|
162
|
+
export const EARTH_RADIUS_METERS = 6371000
|
|
163
|
+
|
|
164
|
+
/** Earth radius in kilometers */
|
|
165
|
+
export const EARTH_RADIUS_KM = 6371
|
|
166
|
+
|
|
167
|
+
/** Earth radius in miles */
|
|
168
|
+
export const EARTH_RADIUS_MILES = 3958.8
|
|
169
|
+
|
|
170
|
+
/** Earth radius in nautical miles */
|
|
171
|
+
export const EARTH_RADIUS_NM = 3440.065
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Conversion factors to meters
|
|
175
|
+
*/
|
|
176
|
+
export const DISTANCE_TO_METERS: Record<DistanceUnit, number> = {
|
|
177
|
+
meters: 1,
|
|
178
|
+
m: 1,
|
|
179
|
+
kilometers: 1000,
|
|
180
|
+
km: 1000,
|
|
181
|
+
miles: 1609.344,
|
|
182
|
+
mi: 1609.344,
|
|
183
|
+
nautical_miles: 1852,
|
|
184
|
+
nm: 1852,
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// GeoExtension Object
|
|
189
|
+
// ============================================================================
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Geospatial Extension utilities for PostgreSQL
|
|
193
|
+
*
|
|
194
|
+
* Provides SQL generation helpers for earthdistance/cube extensions
|
|
195
|
+
* and PostgreSQL's native geometric types.
|
|
196
|
+
*/
|
|
197
|
+
export const GeoExtension = {
|
|
198
|
+
name: 'geo' as const,
|
|
199
|
+
displayName: 'Geospatial' as const,
|
|
200
|
+
description: 'Geospatial utilities using earthdistance, cube, and native PostgreSQL types',
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get the extension definitions required for geospatial support
|
|
204
|
+
*/
|
|
205
|
+
getDefinitions(): ExtensionDefinition[] {
|
|
206
|
+
return [
|
|
207
|
+
{
|
|
208
|
+
name: 'cube',
|
|
209
|
+
displayName: 'cube',
|
|
210
|
+
description: 'Multi-dimensional cube data type',
|
|
211
|
+
bundlePath: '../../pglite/release/cube.tar.gz',
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: 'earthdistance',
|
|
215
|
+
displayName: 'earthdistance',
|
|
216
|
+
description: 'Earth distance calculations using great circle math',
|
|
217
|
+
bundlePath: '../../pglite/release/earthdistance.tar.gz',
|
|
218
|
+
dependencies: ['cube'],
|
|
219
|
+
},
|
|
220
|
+
]
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Generate SQL to create the required extensions
|
|
225
|
+
* Note: cube must be created before earthdistance
|
|
226
|
+
*/
|
|
227
|
+
createExtensionsSQL(): string {
|
|
228
|
+
return `-- Create cube extension (required by earthdistance)
|
|
229
|
+
CREATE EXTENSION IF NOT EXISTS cube;
|
|
230
|
+
|
|
231
|
+
-- Create earthdistance extension
|
|
232
|
+
CREATE EXTENSION IF NOT EXISTS earthdistance;`
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Generate SQL to create a table with location columns
|
|
237
|
+
*/
|
|
238
|
+
createLocationTableSQL(tableName: string, options: LocationTableOptions = {}): string {
|
|
239
|
+
const {
|
|
240
|
+
additionalColumns,
|
|
241
|
+
idColumn = 'serial',
|
|
242
|
+
includeNameColumn = true,
|
|
243
|
+
includeDescriptionColumn = false,
|
|
244
|
+
includeTimestamps = true,
|
|
245
|
+
} = options
|
|
246
|
+
|
|
247
|
+
const columns: string[] = []
|
|
248
|
+
|
|
249
|
+
// Primary key
|
|
250
|
+
switch (idColumn) {
|
|
251
|
+
case 'uuid':
|
|
252
|
+
columns.push('id UUID PRIMARY KEY DEFAULT gen_random_uuid()')
|
|
253
|
+
break
|
|
254
|
+
case 'bigserial':
|
|
255
|
+
columns.push('id BIGSERIAL PRIMARY KEY')
|
|
256
|
+
break
|
|
257
|
+
default:
|
|
258
|
+
columns.push('id SERIAL PRIMARY KEY')
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Name column
|
|
262
|
+
if (includeNameColumn) {
|
|
263
|
+
columns.push('name VARCHAR(255) NOT NULL')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Description column
|
|
267
|
+
if (includeDescriptionColumn) {
|
|
268
|
+
columns.push('description TEXT')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Location columns
|
|
272
|
+
columns.push('latitude DOUBLE PRECISION NOT NULL')
|
|
273
|
+
columns.push('longitude DOUBLE PRECISION NOT NULL')
|
|
274
|
+
|
|
275
|
+
// Additional columns
|
|
276
|
+
if (additionalColumns) {
|
|
277
|
+
columns.push(additionalColumns)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Timestamps
|
|
281
|
+
if (includeTimestamps) {
|
|
282
|
+
columns.push('created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()')
|
|
283
|
+
columns.push('updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()')
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return `CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
287
|
+
${columns.join(',\n ')}
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
-- Create index for faster distance queries using cube
|
|
291
|
+
CREATE INDEX IF NOT EXISTS idx_${tableName}_location ON ${tableName}
|
|
292
|
+
USING gist (ll_to_earth(latitude, longitude));`
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Generate SQL to find locations within a radius
|
|
297
|
+
*
|
|
298
|
+
* Uses the earthdistance extension's earth_distance function
|
|
299
|
+
* which calculates great circle distance between two points.
|
|
300
|
+
*
|
|
301
|
+
* @param tableName Table to search
|
|
302
|
+
* @param center Center point for the search
|
|
303
|
+
* @param radius Search radius
|
|
304
|
+
* @param unit Distance unit (default: meters)
|
|
305
|
+
* @param options Additional search options
|
|
306
|
+
*/
|
|
307
|
+
findWithinRadiusSQL(
|
|
308
|
+
tableName: string,
|
|
309
|
+
center: GeoPoint,
|
|
310
|
+
radius: number,
|
|
311
|
+
unit: DistanceUnit = 'meters',
|
|
312
|
+
options: RadiusSearchOptions = {}
|
|
313
|
+
): string {
|
|
314
|
+
const {
|
|
315
|
+
latColumn = 'latitude',
|
|
316
|
+
lngColumn = 'longitude',
|
|
317
|
+
select = '*',
|
|
318
|
+
where,
|
|
319
|
+
orderBy,
|
|
320
|
+
limit,
|
|
321
|
+
includeDistance = true,
|
|
322
|
+
distanceAlias = 'distance',
|
|
323
|
+
} = options
|
|
324
|
+
|
|
325
|
+
const radiusMeters = radius * DISTANCE_TO_METERS[unit]
|
|
326
|
+
const selectClause = Array.isArray(select) ? select.join(', ') : select
|
|
327
|
+
|
|
328
|
+
// Build the distance expression
|
|
329
|
+
const distanceExpr = `earth_distance(
|
|
330
|
+
ll_to_earth(${latColumn}, ${lngColumn}),
|
|
331
|
+
ll_to_earth(${center.lat}, ${center.lng})
|
|
332
|
+
)`
|
|
333
|
+
|
|
334
|
+
// Build select with optional distance
|
|
335
|
+
const finalSelect = includeDistance
|
|
336
|
+
? `${selectClause}, ${distanceExpr} AS ${distanceAlias}`
|
|
337
|
+
: selectClause
|
|
338
|
+
|
|
339
|
+
// Build WHERE clause
|
|
340
|
+
const whereConditions = [`${distanceExpr} <= ${radiusMeters}`]
|
|
341
|
+
if (where) {
|
|
342
|
+
whereConditions.push(`(${where})`)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Build ORDER BY
|
|
346
|
+
const orderByClause = orderBy || `${distanceAlias} ASC`
|
|
347
|
+
|
|
348
|
+
// Build full query
|
|
349
|
+
let sql = `SELECT ${finalSelect}
|
|
350
|
+
FROM ${tableName}
|
|
351
|
+
WHERE ${whereConditions.join(' AND ')}
|
|
352
|
+
ORDER BY ${orderByClause}`
|
|
353
|
+
|
|
354
|
+
if (limit) {
|
|
355
|
+
sql += `\nLIMIT ${limit}`
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return sql + ';'
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Generate SQL to find locations within a bounding box
|
|
363
|
+
*
|
|
364
|
+
* More efficient for initial filtering before applying
|
|
365
|
+
* precise distance calculations.
|
|
366
|
+
*/
|
|
367
|
+
findWithinBoundingBoxSQL(
|
|
368
|
+
tableName: string,
|
|
369
|
+
bounds: BoundingBox,
|
|
370
|
+
options: BoundingBoxSearchOptions = {}
|
|
371
|
+
): string {
|
|
372
|
+
const {
|
|
373
|
+
latColumn = 'latitude',
|
|
374
|
+
lngColumn = 'longitude',
|
|
375
|
+
select = '*',
|
|
376
|
+
where,
|
|
377
|
+
orderBy,
|
|
378
|
+
limit,
|
|
379
|
+
} = options
|
|
380
|
+
|
|
381
|
+
const selectClause = Array.isArray(select) ? select.join(', ') : select
|
|
382
|
+
|
|
383
|
+
// Build WHERE clause
|
|
384
|
+
const whereConditions = [
|
|
385
|
+
`${latColumn} BETWEEN ${bounds.sw.lat} AND ${bounds.ne.lat}`,
|
|
386
|
+
`${lngColumn} BETWEEN ${bounds.sw.lng} AND ${bounds.ne.lng}`,
|
|
387
|
+
]
|
|
388
|
+
if (where) {
|
|
389
|
+
whereConditions.push(`(${where})`)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let sql = `SELECT ${selectClause}
|
|
393
|
+
FROM ${tableName}
|
|
394
|
+
WHERE ${whereConditions.join(' AND ')}`
|
|
395
|
+
|
|
396
|
+
if (orderBy) {
|
|
397
|
+
sql += `\nORDER BY ${orderBy}`
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (limit) {
|
|
401
|
+
sql += `\nLIMIT ${limit}`
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return sql + ';'
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Generate SQL to calculate distance between two points
|
|
409
|
+
*/
|
|
410
|
+
distanceSQL(point1: GeoPoint, point2: GeoPoint, unit: DistanceUnit = 'meters'): string {
|
|
411
|
+
const divisor = DISTANCE_TO_METERS[unit]
|
|
412
|
+
return `SELECT earth_distance(
|
|
413
|
+
ll_to_earth(${point1.lat}, ${point1.lng}),
|
|
414
|
+
ll_to_earth(${point2.lat}, ${point2.lng})
|
|
415
|
+
) / ${divisor} AS distance;`
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Generate SQL expression for distance calculation (for use in queries)
|
|
420
|
+
*/
|
|
421
|
+
distanceExpression(
|
|
422
|
+
latColumn: string,
|
|
423
|
+
lngColumn: string,
|
|
424
|
+
center: GeoPoint,
|
|
425
|
+
unit: DistanceUnit = 'meters'
|
|
426
|
+
): string {
|
|
427
|
+
const divisor = DISTANCE_TO_METERS[unit]
|
|
428
|
+
return `earth_distance(ll_to_earth(${latColumn}, ${lngColumn}), ll_to_earth(${center.lat}, ${center.lng})) / ${divisor}`
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Generate SQL to find K nearest neighbors
|
|
433
|
+
*
|
|
434
|
+
* @param tableName Table to search
|
|
435
|
+
* @param center Reference point
|
|
436
|
+
* @param k Number of nearest neighbors to find
|
|
437
|
+
* @param options Search options
|
|
438
|
+
*/
|
|
439
|
+
findKNearestSQL(
|
|
440
|
+
tableName: string,
|
|
441
|
+
center: GeoPoint,
|
|
442
|
+
k: number,
|
|
443
|
+
options: RadiusSearchOptions = {}
|
|
444
|
+
): string {
|
|
445
|
+
const {
|
|
446
|
+
latColumn = 'latitude',
|
|
447
|
+
lngColumn = 'longitude',
|
|
448
|
+
select = '*',
|
|
449
|
+
where,
|
|
450
|
+
includeDistance = true,
|
|
451
|
+
distanceAlias = 'distance',
|
|
452
|
+
} = options
|
|
453
|
+
|
|
454
|
+
const selectClause = Array.isArray(select) ? select.join(', ') : select
|
|
455
|
+
|
|
456
|
+
// Build the distance expression
|
|
457
|
+
const distanceExpr = `earth_distance(
|
|
458
|
+
ll_to_earth(${latColumn}, ${lngColumn}),
|
|
459
|
+
ll_to_earth(${center.lat}, ${center.lng})
|
|
460
|
+
)`
|
|
461
|
+
|
|
462
|
+
// Build select with optional distance
|
|
463
|
+
const finalSelect = includeDistance
|
|
464
|
+
? `${selectClause}, ${distanceExpr} AS ${distanceAlias}`
|
|
465
|
+
: selectClause
|
|
466
|
+
|
|
467
|
+
// Build WHERE clause
|
|
468
|
+
const whereClause = where ? `WHERE ${where}\n` : ''
|
|
469
|
+
|
|
470
|
+
return `SELECT ${finalSelect}
|
|
471
|
+
FROM ${tableName}
|
|
472
|
+
${whereClause}ORDER BY ${distanceExpr} ASC
|
|
473
|
+
LIMIT ${k};`
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Calculate a bounding box for a given center point and radius
|
|
478
|
+
*
|
|
479
|
+
* Useful for creating efficient queries that first filter by bounding box
|
|
480
|
+
* before applying precise distance calculations.
|
|
481
|
+
*/
|
|
482
|
+
calculateBoundingBox(center: GeoPoint, radius: number, unit: DistanceUnit = 'meters'): BoundingBox {
|
|
483
|
+
const radiusKm = (radius * DISTANCE_TO_METERS[unit]) / 1000
|
|
484
|
+
|
|
485
|
+
// Approximate degrees per km at the equator
|
|
486
|
+
const kmPerDegreeLat = 111.32
|
|
487
|
+
const kmPerDegreeLng = 111.32 * Math.cos((center.lat * Math.PI) / 180)
|
|
488
|
+
|
|
489
|
+
const latDelta = radiusKm / kmPerDegreeLat
|
|
490
|
+
const lngDelta = radiusKm / kmPerDegreeLng
|
|
491
|
+
|
|
492
|
+
return {
|
|
493
|
+
sw: {
|
|
494
|
+
lat: center.lat - latDelta,
|
|
495
|
+
lng: center.lng - lngDelta,
|
|
496
|
+
},
|
|
497
|
+
ne: {
|
|
498
|
+
lat: center.lat + latDelta,
|
|
499
|
+
lng: center.lng + lngDelta,
|
|
500
|
+
},
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// ============================================================================
|
|
506
|
+
// PostgreSQL Native Geometric Types
|
|
507
|
+
// ============================================================================
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* PostgreSQL Native Geometric Types
|
|
511
|
+
*
|
|
512
|
+
* PostgreSQL includes several built-in geometric types that work without
|
|
513
|
+
* any extensions. These are useful for simple geometric operations.
|
|
514
|
+
*
|
|
515
|
+
* Types:
|
|
516
|
+
* - point: A point in 2D space (x, y)
|
|
517
|
+
* - box: A rectangular box defined by two corner points
|
|
518
|
+
* - circle: A circle defined by center point and radius
|
|
519
|
+
* - polygon: A closed path defined by a list of points
|
|
520
|
+
* - path: Open or closed path of connected line segments
|
|
521
|
+
* - line: Infinite line (Ax + By + C = 0)
|
|
522
|
+
* - lseg: Line segment defined by two points
|
|
523
|
+
*/
|
|
524
|
+
export const PostgresGeoTypes = {
|
|
525
|
+
/**
|
|
526
|
+
* SQL to create a table with native PostgreSQL point column
|
|
527
|
+
*/
|
|
528
|
+
createPointTableSQL(tableName: string, pointColumn: string = 'location'): string {
|
|
529
|
+
return `CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
530
|
+
id SERIAL PRIMARY KEY,
|
|
531
|
+
${pointColumn} POINT NOT NULL
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
-- Create GiST index for spatial queries on point column
|
|
535
|
+
CREATE INDEX IF NOT EXISTS idx_${tableName}_${pointColumn} ON ${tableName}
|
|
536
|
+
USING gist (${pointColumn});`
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* SQL to create a table with native PostgreSQL box column
|
|
541
|
+
*/
|
|
542
|
+
createBoxTableSQL(tableName: string, boxColumn: string = 'bounds'): string {
|
|
543
|
+
return `CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
544
|
+
id SERIAL PRIMARY KEY,
|
|
545
|
+
${boxColumn} BOX NOT NULL
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
-- Create GiST index for spatial queries on box column
|
|
549
|
+
CREATE INDEX IF NOT EXISTS idx_${tableName}_${boxColumn} ON ${tableName}
|
|
550
|
+
USING gist (${boxColumn});`
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* SQL to find points within a box using native PostgreSQL operators
|
|
555
|
+
*
|
|
556
|
+
* @param tableName Table to search
|
|
557
|
+
* @param pointColumn Column containing point data
|
|
558
|
+
* @param box Bounding box to search within
|
|
559
|
+
*/
|
|
560
|
+
pointsWithinBoxSQL(tableName: string, pointColumn: string, box: Box): string {
|
|
561
|
+
const boxStr = `'(${box.high.x},${box.high.y}),(${box.low.x},${box.low.y})'::box`
|
|
562
|
+
return `SELECT * FROM ${tableName}
|
|
563
|
+
WHERE ${pointColumn} <@ ${boxStr};`
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* SQL to find points within a circle using native PostgreSQL operators
|
|
568
|
+
*/
|
|
569
|
+
pointsWithinCircleSQL(
|
|
570
|
+
tableName: string,
|
|
571
|
+
pointColumn: string,
|
|
572
|
+
center: Point,
|
|
573
|
+
radius: number
|
|
574
|
+
): string {
|
|
575
|
+
const circleStr = `'<(${center.x},${center.y}),${radius}>'::circle`
|
|
576
|
+
return `SELECT * FROM ${tableName}
|
|
577
|
+
WHERE ${pointColumn} <@ ${circleStr};`
|
|
578
|
+
},
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* SQL to calculate distance between two native PostgreSQL points
|
|
582
|
+
*/
|
|
583
|
+
pointDistanceSQL(point1: Point, point2: Point): string {
|
|
584
|
+
return `SELECT '(${point1.x},${point1.y})'::point <-> '(${point2.x},${point2.y})'::point AS distance;`
|
|
585
|
+
},
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* SQL expression for point distance (for use in queries)
|
|
589
|
+
*/
|
|
590
|
+
pointDistanceExpression(pointColumn: string, target: Point): string {
|
|
591
|
+
return `${pointColumn} <-> '(${target.x},${target.y})'::point`
|
|
592
|
+
},
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// ============================================================================
|
|
596
|
+
// Parsing and Serialization Functions
|
|
597
|
+
// ============================================================================
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Parse a PostgreSQL point string to a Point object
|
|
601
|
+
*
|
|
602
|
+
* @param value PostgreSQL point string like "(x,y)"
|
|
603
|
+
* @returns Point object or null if invalid
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```typescript
|
|
607
|
+
* const point = parsePoint('(1.5,2.5)')
|
|
608
|
+
* // { x: 1.5, y: 2.5 }
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
export function parsePoint(value: string): Point | null {
|
|
612
|
+
if (!value || typeof value !== 'string') {
|
|
613
|
+
return null
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const trimmed = value.trim()
|
|
617
|
+
if (!trimmed.startsWith('(') || !trimmed.endsWith(')')) {
|
|
618
|
+
return null
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const inner = trimmed.slice(1, -1)
|
|
622
|
+
const parts = inner.split(',')
|
|
623
|
+
|
|
624
|
+
if (parts.length !== 2) {
|
|
625
|
+
return null
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const part0 = parts[0]
|
|
629
|
+
const part1 = parts[1]
|
|
630
|
+
if (part0 === undefined || part1 === undefined) {
|
|
631
|
+
return null
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
const x = parseFloat(part0.trim())
|
|
635
|
+
const y = parseFloat(part1.trim())
|
|
636
|
+
|
|
637
|
+
if (isNaN(x) || isNaN(y)) {
|
|
638
|
+
return null
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return { x, y }
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Serialize a Point to PostgreSQL point string
|
|
646
|
+
*
|
|
647
|
+
* @param point Point object
|
|
648
|
+
* @returns PostgreSQL point string like "(x,y)"
|
|
649
|
+
*/
|
|
650
|
+
export function serializePoint(point: Point): string {
|
|
651
|
+
return `(${point.x},${point.y})`
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Parse a PostgreSQL point string to a GeoPoint (lat/lng)
|
|
656
|
+
*
|
|
657
|
+
* Note: PostgreSQL points are (x, y) where x = longitude, y = latitude
|
|
658
|
+
*
|
|
659
|
+
* @param value PostgreSQL point string
|
|
660
|
+
* @returns GeoPoint or null if invalid
|
|
661
|
+
*/
|
|
662
|
+
export function parseGeoPoint(value: string): GeoPoint | null {
|
|
663
|
+
const point = parsePoint(value)
|
|
664
|
+
if (!point) return null
|
|
665
|
+
|
|
666
|
+
return {
|
|
667
|
+
lat: point.y, // y = latitude
|
|
668
|
+
lng: point.x, // x = longitude
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Serialize a GeoPoint to PostgreSQL point string
|
|
674
|
+
*
|
|
675
|
+
* Note: PostgreSQL points are (x, y) where x = longitude, y = latitude
|
|
676
|
+
*/
|
|
677
|
+
export function serializeGeoPoint(geoPoint: GeoPoint): string {
|
|
678
|
+
return `(${geoPoint.lng},${geoPoint.lat})` // (x=lng, y=lat)
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Parse a PostgreSQL box string to a Box object
|
|
683
|
+
*
|
|
684
|
+
* @param value PostgreSQL box string like "(x1,y1),(x2,y2)"
|
|
685
|
+
* @returns Box object or null if invalid
|
|
686
|
+
*/
|
|
687
|
+
export function parseBox(value: string): Box | null {
|
|
688
|
+
if (!value || typeof value !== 'string') {
|
|
689
|
+
return null
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Remove outer parens if present
|
|
693
|
+
let trimmed = value.trim()
|
|
694
|
+
|
|
695
|
+
// Box format can be "(x1,y1),(x2,y2)" or "((x1,y1),(x2,y2))"
|
|
696
|
+
if (trimmed.startsWith('(') && trimmed.endsWith(')') && trimmed.includes('),(')) {
|
|
697
|
+
// Find the two point strings
|
|
698
|
+
const midIndex = trimmed.indexOf('),(')
|
|
699
|
+
const point1Str = trimmed.slice(0, midIndex + 1)
|
|
700
|
+
const point2Str = trimmed.slice(midIndex + 2)
|
|
701
|
+
|
|
702
|
+
const point1 = parsePoint(point1Str)
|
|
703
|
+
const point2 = parsePoint(point2Str)
|
|
704
|
+
|
|
705
|
+
if (!point1 || !point2) return null
|
|
706
|
+
|
|
707
|
+
return {
|
|
708
|
+
high: point1,
|
|
709
|
+
low: point2,
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
return null
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Serialize a Box to PostgreSQL box string
|
|
718
|
+
*/
|
|
719
|
+
export function serializeBox(box: Box): string {
|
|
720
|
+
return `(${box.high.x},${box.high.y}),(${box.low.x},${box.low.y})`
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Parse a PostgreSQL polygon string to a Polygon object (as GeoPoints)
|
|
725
|
+
*
|
|
726
|
+
* @param value PostgreSQL polygon string like "((x1,y1),(x2,y2),(x3,y3))"
|
|
727
|
+
*/
|
|
728
|
+
export function parsePolygon(value: string): Polygon | null {
|
|
729
|
+
if (!value || typeof value !== 'string') {
|
|
730
|
+
return null
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// Polygon format: ((x1,y1),(x2,y2),...)
|
|
734
|
+
let trimmed = value.trim()
|
|
735
|
+
if (!trimmed.startsWith('((') || !trimmed.endsWith('))')) {
|
|
736
|
+
return null
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// Remove outer parens
|
|
740
|
+
const inner = trimmed.slice(1, -1)
|
|
741
|
+
|
|
742
|
+
// Split by "),(" to get individual points
|
|
743
|
+
const pointStrs = inner.split('),(')
|
|
744
|
+
const vertices: GeoPoint[] = []
|
|
745
|
+
|
|
746
|
+
for (let i = 0; i < pointStrs.length; i++) {
|
|
747
|
+
let pStr = pointStrs[i]
|
|
748
|
+
if (pStr === undefined) continue
|
|
749
|
+
// Add back parens that were removed by split
|
|
750
|
+
if (!pStr.startsWith('(')) pStr = '(' + pStr
|
|
751
|
+
if (!pStr.endsWith(')')) pStr = pStr + ')'
|
|
752
|
+
|
|
753
|
+
const point = parseGeoPoint(pStr)
|
|
754
|
+
if (!point) return null
|
|
755
|
+
vertices.push(point)
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return { vertices }
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Serialize a Polygon to PostgreSQL polygon string
|
|
763
|
+
*/
|
|
764
|
+
export function serializePolygon(polygon: Polygon): string {
|
|
765
|
+
const pointStrs = polygon.vertices.map(v => `(${v.lng},${v.lat})`)
|
|
766
|
+
return `(${pointStrs.join(',')})`
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// ============================================================================
|
|
770
|
+
// Distance Calculation Utilities (JavaScript)
|
|
771
|
+
// ============================================================================
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Calculate the Haversine distance between two points in JavaScript
|
|
775
|
+
*
|
|
776
|
+
* Useful for client-side distance calculations without hitting the database.
|
|
777
|
+
*
|
|
778
|
+
* @param point1 First point
|
|
779
|
+
* @param point2 Second point
|
|
780
|
+
* @param unit Distance unit (default: meters)
|
|
781
|
+
* @returns Distance in the specified unit
|
|
782
|
+
*/
|
|
783
|
+
export function haversineDistance(
|
|
784
|
+
point1: GeoPoint,
|
|
785
|
+
point2: GeoPoint,
|
|
786
|
+
unit: DistanceUnit = 'meters'
|
|
787
|
+
): number {
|
|
788
|
+
const toRadians = (deg: number) => (deg * Math.PI) / 180
|
|
789
|
+
|
|
790
|
+
const lat1 = toRadians(point1.lat)
|
|
791
|
+
const lat2 = toRadians(point2.lat)
|
|
792
|
+
const deltaLat = toRadians(point2.lat - point1.lat)
|
|
793
|
+
const deltaLng = toRadians(point2.lng - point1.lng)
|
|
794
|
+
|
|
795
|
+
// Haversine formula: 'haversineA' is the square of half the chord length between the points
|
|
796
|
+
const haversineA =
|
|
797
|
+
Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
|
|
798
|
+
Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2)
|
|
799
|
+
|
|
800
|
+
// Angular distance in radians
|
|
801
|
+
const angularDistance = 2 * Math.atan2(Math.sqrt(haversineA), Math.sqrt(1 - haversineA))
|
|
802
|
+
|
|
803
|
+
const distanceMeters = EARTH_RADIUS_METERS * angularDistance
|
|
804
|
+
|
|
805
|
+
return distanceMeters / DISTANCE_TO_METERS[unit]
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Check if a point is within a bounding box
|
|
810
|
+
*/
|
|
811
|
+
export function isPointInBoundingBox(point: GeoPoint, bounds: BoundingBox): boolean {
|
|
812
|
+
return (
|
|
813
|
+
point.lat >= bounds.sw.lat &&
|
|
814
|
+
point.lat <= bounds.ne.lat &&
|
|
815
|
+
point.lng >= bounds.sw.lng &&
|
|
816
|
+
point.lng <= bounds.ne.lng
|
|
817
|
+
)
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Check if a point is within a radius of another point
|
|
822
|
+
*/
|
|
823
|
+
export function isPointWithinRadius(
|
|
824
|
+
point: GeoPoint,
|
|
825
|
+
center: GeoPoint,
|
|
826
|
+
radius: number,
|
|
827
|
+
unit: DistanceUnit = 'meters'
|
|
828
|
+
): boolean {
|
|
829
|
+
return haversineDistance(point, center, unit) <= radius
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// ============================================================================
|
|
833
|
+
// Default Export
|
|
834
|
+
// ============================================================================
|
|
835
|
+
|
|
836
|
+
export default {
|
|
837
|
+
GeoExtension,
|
|
838
|
+
PostgresGeoTypes,
|
|
839
|
+
// Constants
|
|
840
|
+
EARTH_RADIUS_METERS,
|
|
841
|
+
EARTH_RADIUS_KM,
|
|
842
|
+
EARTH_RADIUS_MILES,
|
|
843
|
+
EARTH_RADIUS_NM,
|
|
844
|
+
DISTANCE_TO_METERS,
|
|
845
|
+
// Parsing functions
|
|
846
|
+
parsePoint,
|
|
847
|
+
serializePoint,
|
|
848
|
+
parseGeoPoint,
|
|
849
|
+
serializeGeoPoint,
|
|
850
|
+
parseBox,
|
|
851
|
+
serializeBox,
|
|
852
|
+
parsePolygon,
|
|
853
|
+
serializePolygon,
|
|
854
|
+
// Distance utilities
|
|
855
|
+
haversineDistance,
|
|
856
|
+
isPointInBoundingBox,
|
|
857
|
+
isPointWithinRadius,
|
|
858
|
+
}
|