@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9
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 +109 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +51 -12
- package/config/config.test.ts +18 -15
- package/config/config.ts +89 -31
- package/config/mod.ts +4 -3
- package/config/secrets.ts +79 -53
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +41 -2
- package/dist/app_meta.d.ts +44 -12
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +2 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -28
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +46 -18
- package/dist/config/config.js.map +1 -1
- package/dist/config/mod.d.ts +5 -4
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +2 -2
- package/dist/config/mod.js.map +1 -1
- package/dist/config/secrets.d.ts +71 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +31 -38
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +8 -5
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +36 -1
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +31 -1
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +147 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +274 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +90 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +355 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +58 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +251 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +2 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/context.d.ts +1 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +1 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/encode.d.ts +2 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +2 -2
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +1 -2
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/meter.d.ts +1 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/propagator.d.ts +1 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/provider.d.ts +4 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +15 -1
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +30 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/otel/tracer.d.ts +1 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +11 -5
- package/dist/internal/otel/tracer.js.map +1 -1
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +1 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/mod.d.ts +6 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +32 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +192 -16
- package/dist/internal/runtime/napi/napi.d.cts +573 -33
- package/dist/internal/runtime/shutdown.d.ts +5 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +9 -1
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +109 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +335 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +1 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/logger.d.ts +2 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/runtime.d.ts +2 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/stderr.d.ts +1 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/metrics/mod.d.ts +45 -118
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +44 -179
- package/dist/metrics/mod.js.map +1 -1
- package/dist/mod.d.ts +2 -3
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/dist/otel.d.ts +1 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/pubsub/encoding.d.ts +5 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +10 -2
- package/dist/pubsub/encoding.js.map +1 -1
- package/dist/pubsub/mod.d.ts +5 -4
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +2 -2
- package/dist/pubsub/mod.js.map +1 -1
- package/dist/pubsub/refs.d.ts +8 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +110 -15
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +98 -16
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +101 -31
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +168 -51
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +147 -5
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +157 -9
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +1 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/storage/objects/bucket.d.ts +313 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +306 -15
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +10 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +25 -1
- package/dist/storage/objects/error.js.map +1 -1
- package/dist/storage/objects/mod.d.ts +4 -3
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +20 -4
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +6 -0
- package/dist/storage/objects/refs.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +85 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +129 -37
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +4 -1
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +223 -139
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +128 -6
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +56 -22
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +62 -0
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +31 -4
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +26 -1
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +10 -0
- package/dist/storage/redis/native.js.map +1 -1
- package/dist/storage/redis/options.d.ts +1 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +2 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/reply.d.ts +34 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +40 -1
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +1 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/script.d.ts +1 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/target.d.ts +5 -3
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +39 -28
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +7 -10
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +8 -32
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +389 -0
- package/internal/clients/grpc.test.ts +368 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +464 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +287 -0
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +31 -2
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +192 -16
- package/internal/runtime/napi/napi.d.cts +573 -33
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +372 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +1 -8
- package/otel.test.ts +13 -6
- package/package.json +92 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +16 -4
- package/pubsub/pubsub.test.ts +233 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +200 -21
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +255 -36
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +185 -9
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +650 -20
- package/storage/objects/error.ts +28 -1
- package/storage/objects/mod.ts +15 -0
- package/storage/objects/refs.ts +51 -3
- package/storage/postgres/database.integration.test.ts +275 -0
- package/storage/postgres/database.test.ts +193 -6
- package/storage/postgres/database.ts +206 -55
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +4 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +271 -21
- package/storage/redis/database.ts +77 -23
- package/storage/redis/mod.ts +38 -2
- package/storage/redis/native.ts +11 -0
- package/storage/redis/redis.test.ts +170 -10
- package/storage/redis/reply.ts +76 -1
- package/storage/redis/runtime.test.ts +15 -0
- package/storage/redis/target.ts +47 -44
- package/storage/redis/wire.ts +8 -32
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +267 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/dist/internal/otel/request_context.d.ts +0 -11
- package/dist/internal/otel/request_context.js +0 -20
- package/dist/internal/otel/request_context.js.map +0 -1
- package/dist/internal/reqtrack/mod.d.ts +0 -6
- package/dist/internal/reqtrack/mod.js +0 -28
- package/dist/internal/reqtrack/mod.js.map +0 -1
- package/dist/req_meta.d.ts +0 -47
- package/dist/req_meta.js +0 -26
- package/dist/req_meta.js.map +0 -1
- package/internal/otel/request_context.ts +0 -32
- package/internal/reqtrack/mod.ts +0 -39
- package/req_meta.ts +0 -75
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of error a database reported, by its SQLSTATE: the cases an app
|
|
3
|
+
* most often handles. `other` is any other; the SQLSTATE says what.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* try {
|
|
7
|
+
* await db.exec`INSERT INTO users (email) VALUES (${email})`;
|
|
8
|
+
* } catch (err) {
|
|
9
|
+
* if (err instanceof DatabaseError && err.code === ErrorCode.UniqueViolation) {
|
|
10
|
+
* return {taken: true};
|
|
11
|
+
* }
|
|
12
|
+
* throw err;
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export declare const ErrorCode: {
|
|
16
|
+
/** None of the others; the SQLSTATE says what. */
|
|
17
|
+
readonly Other: "other";
|
|
18
|
+
/** A `NOT NULL` constraint would be violated (23502). */
|
|
19
|
+
readonly NotNullViolation: "not_null_violation";
|
|
20
|
+
/** A foreign key constraint would be violated (23503). */
|
|
21
|
+
readonly ForeignKeyViolation: "foreign_key_violation";
|
|
22
|
+
/** A unique constraint would be violated (23505). */
|
|
23
|
+
readonly UniqueViolation: "unique_violation";
|
|
24
|
+
/** A check constraint would be violated (23514). */
|
|
25
|
+
readonly CheckViolation: "check_violation";
|
|
26
|
+
/** An exclusion constraint would be violated (23P01). */
|
|
27
|
+
readonly ExcludeViolation: "exclude_violation";
|
|
28
|
+
/** A statement ran in a transaction an earlier statement failed (25P02). */
|
|
29
|
+
readonly TransactionFailed: "transaction_failed";
|
|
30
|
+
/** A deadlock was detected (40P01). */
|
|
31
|
+
readonly DeadlockDetected: "deadlock_detected";
|
|
32
|
+
/** The server refused a connection: it has as many as it allows (53300). */
|
|
33
|
+
readonly TooManyConnections: "too_many_connections";
|
|
34
|
+
/**
|
|
35
|
+
* A serializable or repeatable read transaction could not be serialized
|
|
36
|
+
* with a concurrent one (40001); retrying it may succeed.
|
|
37
|
+
*/
|
|
38
|
+
readonly SerializationFailure: "serialization_failure";
|
|
39
|
+
/** A write in a read-only transaction (25006), such as one through a read handle. */
|
|
40
|
+
readonly ReadOnlyTransaction: "read_only_transaction";
|
|
41
|
+
/**
|
|
42
|
+
* A lock could not be taken without waiting (55P03), as with
|
|
43
|
+
* `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
44
|
+
*/
|
|
45
|
+
readonly LockNotAvailable: "lock_not_available";
|
|
46
|
+
/** The statement was canceled (57014): by a timeout, or on request. */
|
|
47
|
+
readonly QueryCanceled: "query_canceled";
|
|
48
|
+
/** The database could not be reached, or the connection to it was lost (class 08). */
|
|
49
|
+
readonly ConnectionFailure: "connection_failure";
|
|
50
|
+
};
|
|
51
|
+
/** One of the {@link ErrorCode} values: `'unique_violation'`. */
|
|
52
|
+
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
53
|
+
/**
|
|
54
|
+
* An error a database reported, or a failure to reach it.
|
|
55
|
+
*
|
|
56
|
+
* A failure to reach the database, which the server can't report, has
|
|
57
|
+
* `sqlState` `"08001"`, `code` `connection_failure`, the client's message
|
|
58
|
+
* and none of the optional fields. The caller's own mistakes, such as a
|
|
59
|
+
* parameter of the wrong type, and using a busy or closed handle, are plain
|
|
60
|
+
* errors instead.
|
|
61
|
+
*
|
|
62
|
+
* The optional fields are sent only for some errors (see
|
|
63
|
+
* https://www.postgresql.org/docs/current/protocol-error-fields.html); one
|
|
64
|
+
* being there says nothing about the others.
|
|
65
|
+
*
|
|
66
|
+
* Its `message` reads `ERROR: duplicate key value violates unique constraint
|
|
67
|
+
* "users_pkey" (Code unique_violation: SQLSTATE 23505)`. A subscription
|
|
68
|
+
* handler that throws one fails with the API error code of its SQLSTATE:
|
|
69
|
+
* `already_exists` for a unique violation.
|
|
70
|
+
*/
|
|
71
|
+
export declare class DatabaseError extends Error {
|
|
72
|
+
readonly name: 'DatabaseError';
|
|
73
|
+
/** What kind of error it is, by its SQLSTATE. */
|
|
74
|
+
readonly code: ErrorCode;
|
|
75
|
+
/** The SQLSTATE: `"23505"`. */
|
|
76
|
+
readonly sqlState: string;
|
|
77
|
+
/** `ERROR`, `FATAL` or `PANIC`. */
|
|
78
|
+
readonly severity: string;
|
|
79
|
+
/**
|
|
80
|
+
* A secondary message with more detail, such as the key a unique
|
|
81
|
+
* violation conflicted on.
|
|
82
|
+
*/
|
|
83
|
+
readonly detail?: string;
|
|
84
|
+
/** A suggestion what to do about it. */
|
|
85
|
+
readonly hint?: string;
|
|
86
|
+
/** The schema of the object the error is about. */
|
|
87
|
+
readonly schemaName?: string;
|
|
88
|
+
/** The table the error is about. */
|
|
89
|
+
readonly tableName?: string;
|
|
90
|
+
/** The column the error is about. */
|
|
91
|
+
readonly columnName?: string;
|
|
92
|
+
/** The data type the error is about. */
|
|
93
|
+
readonly dataTypeName?: string;
|
|
94
|
+
/** The constraint the error is about; an index counts as one. */
|
|
95
|
+
readonly constraintName?: string;
|
|
96
|
+
constructor(fields: {
|
|
97
|
+
message: string;
|
|
98
|
+
code: ErrorCode;
|
|
99
|
+
sqlState: string;
|
|
100
|
+
severity: string;
|
|
101
|
+
detail?: string;
|
|
102
|
+
hint?: string;
|
|
103
|
+
schemaName?: string;
|
|
104
|
+
tableName?: string;
|
|
105
|
+
columnName?: string;
|
|
106
|
+
dataTypeName?: string;
|
|
107
|
+
constraintName?: string;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/** Thrown by `queryRow` and `rawQueryRow` for a query that returns more than one row. */
|
|
111
|
+
export declare class TooManyRowsError extends Error {
|
|
112
|
+
readonly name: 'TooManyRowsError';
|
|
113
|
+
constructor();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Awaits a native database call, throwing the error it rejects with as a
|
|
117
|
+
* `DatabaseError` if it is one.
|
|
118
|
+
*/
|
|
119
|
+
export declare function native<T>(call: Promise<T>): Promise<T>;
|
|
120
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../storage/postgres/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS;IACpB,kDAAkD;;IAElD,yDAAyD;;IAEzD,0DAA0D;;IAE1D,qDAAqD;;IAErD,oDAAoD;;IAEpD,yDAAyD;;IAEzD,4EAA4E;;IAE5E,uCAAuC;;IAEvC,4EAA4E;;IAE5E;;;OAGG;;IAEH,qFAAqF;;IAErF;;;OAGG;;IAEH,uEAAuE;;IAEvE,sFAAsF;;CAE9E,CAAC;AAEX,iEAAiE;AACjE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAiB,IAAI,EAAE,eAAe,CAAC;IACvC,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,oCAAoC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,iEAAiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;gBAErB,MAAM,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,SAAS,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;CAkBF;AAED,yFAAyF;AACzF,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAiB,IAAI,EAAE,kBAAkB,CAAC;;CAU3C;AASD;;;GAGG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM5D"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of error a database reported, by its SQLSTATE: the cases an app
|
|
3
|
+
* most often handles. `other` is any other; the SQLSTATE says what.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* try {
|
|
7
|
+
* await db.exec`INSERT INTO users (email) VALUES (${email})`;
|
|
8
|
+
* } catch (err) {
|
|
9
|
+
* if (err instanceof DatabaseError && err.code === ErrorCode.UniqueViolation) {
|
|
10
|
+
* return {taken: true};
|
|
11
|
+
* }
|
|
12
|
+
* throw err;
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export const ErrorCode = {
|
|
16
|
+
/** None of the others; the SQLSTATE says what. */
|
|
17
|
+
Other: 'other',
|
|
18
|
+
/** A `NOT NULL` constraint would be violated (23502). */
|
|
19
|
+
NotNullViolation: 'not_null_violation',
|
|
20
|
+
/** A foreign key constraint would be violated (23503). */
|
|
21
|
+
ForeignKeyViolation: 'foreign_key_violation',
|
|
22
|
+
/** A unique constraint would be violated (23505). */
|
|
23
|
+
UniqueViolation: 'unique_violation',
|
|
24
|
+
/** A check constraint would be violated (23514). */
|
|
25
|
+
CheckViolation: 'check_violation',
|
|
26
|
+
/** An exclusion constraint would be violated (23P01). */
|
|
27
|
+
ExcludeViolation: 'exclude_violation',
|
|
28
|
+
/** A statement ran in a transaction an earlier statement failed (25P02). */
|
|
29
|
+
TransactionFailed: 'transaction_failed',
|
|
30
|
+
/** A deadlock was detected (40P01). */
|
|
31
|
+
DeadlockDetected: 'deadlock_detected',
|
|
32
|
+
/** The server refused a connection: it has as many as it allows (53300). */
|
|
33
|
+
TooManyConnections: 'too_many_connections',
|
|
34
|
+
/**
|
|
35
|
+
* A serializable or repeatable read transaction could not be serialized
|
|
36
|
+
* with a concurrent one (40001); retrying it may succeed.
|
|
37
|
+
*/
|
|
38
|
+
SerializationFailure: 'serialization_failure',
|
|
39
|
+
/** A write in a read-only transaction (25006), such as one through a read handle. */
|
|
40
|
+
ReadOnlyTransaction: 'read_only_transaction',
|
|
41
|
+
/**
|
|
42
|
+
* A lock could not be taken without waiting (55P03), as with
|
|
43
|
+
* `FOR UPDATE NOWAIT` or `lock_timeout`.
|
|
44
|
+
*/
|
|
45
|
+
LockNotAvailable: 'lock_not_available',
|
|
46
|
+
/** The statement was canceled (57014): by a timeout, or on request. */
|
|
47
|
+
QueryCanceled: 'query_canceled',
|
|
48
|
+
/** The database could not be reached, or the connection to it was lost (class 08). */
|
|
49
|
+
ConnectionFailure: 'connection_failure',
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* An error a database reported, or a failure to reach it.
|
|
53
|
+
*
|
|
54
|
+
* A failure to reach the database, which the server can't report, has
|
|
55
|
+
* `sqlState` `"08001"`, `code` `connection_failure`, the client's message
|
|
56
|
+
* and none of the optional fields. The caller's own mistakes, such as a
|
|
57
|
+
* parameter of the wrong type, and using a busy or closed handle, are plain
|
|
58
|
+
* errors instead.
|
|
59
|
+
*
|
|
60
|
+
* The optional fields are sent only for some errors (see
|
|
61
|
+
* https://www.postgresql.org/docs/current/protocol-error-fields.html); one
|
|
62
|
+
* being there says nothing about the others.
|
|
63
|
+
*
|
|
64
|
+
* Its `message` reads `ERROR: duplicate key value violates unique constraint
|
|
65
|
+
* "users_pkey" (Code unique_violation: SQLSTATE 23505)`. A subscription
|
|
66
|
+
* handler that throws one fails with the API error code of its SQLSTATE:
|
|
67
|
+
* `already_exists` for a unique violation.
|
|
68
|
+
*/
|
|
69
|
+
export class DatabaseError extends Error {
|
|
70
|
+
/** What kind of error it is, by its SQLSTATE. */
|
|
71
|
+
code;
|
|
72
|
+
/** The SQLSTATE: `"23505"`. */
|
|
73
|
+
sqlState;
|
|
74
|
+
/** `ERROR`, `FATAL` or `PANIC`. */
|
|
75
|
+
severity;
|
|
76
|
+
/**
|
|
77
|
+
* A secondary message with more detail, such as the key a unique
|
|
78
|
+
* violation conflicted on.
|
|
79
|
+
*/
|
|
80
|
+
detail;
|
|
81
|
+
/** A suggestion what to do about it. */
|
|
82
|
+
hint;
|
|
83
|
+
/** The schema of the object the error is about. */
|
|
84
|
+
schemaName;
|
|
85
|
+
/** The table the error is about. */
|
|
86
|
+
tableName;
|
|
87
|
+
/** The column the error is about. */
|
|
88
|
+
columnName;
|
|
89
|
+
/** The data type the error is about. */
|
|
90
|
+
dataTypeName;
|
|
91
|
+
/** The constraint the error is about; an index counts as one. */
|
|
92
|
+
constraintName;
|
|
93
|
+
constructor(fields) {
|
|
94
|
+
super(fields.message);
|
|
95
|
+
Object.defineProperty(this, 'name', {
|
|
96
|
+
value: 'DatabaseError',
|
|
97
|
+
enumerable: false,
|
|
98
|
+
configurable: true,
|
|
99
|
+
});
|
|
100
|
+
this.code = fields.code;
|
|
101
|
+
this.sqlState = fields.sqlState;
|
|
102
|
+
this.severity = fields.severity;
|
|
103
|
+
this.detail = fields.detail;
|
|
104
|
+
this.hint = fields.hint;
|
|
105
|
+
this.schemaName = fields.schemaName;
|
|
106
|
+
this.tableName = fields.tableName;
|
|
107
|
+
this.columnName = fields.columnName;
|
|
108
|
+
this.dataTypeName = fields.dataTypeName;
|
|
109
|
+
this.constraintName = fields.constraintName;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Thrown by `queryRow` and `rawQueryRow` for a query that returns more than one row. */
|
|
113
|
+
export class TooManyRowsError extends Error {
|
|
114
|
+
constructor() {
|
|
115
|
+
super('query returned more than one row');
|
|
116
|
+
Object.defineProperty(this, 'name', {
|
|
117
|
+
value: 'TooManyRowsError',
|
|
118
|
+
enumerable: false,
|
|
119
|
+
configurable: true,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Begins the message of an error the native module rejects with for a
|
|
125
|
+
* `DatabaseError`, which the rest of the message holds as JSON. The same as
|
|
126
|
+
* `DATABASE_ERROR_PREFIX` in `sdk/ts/src/postgres.rs`.
|
|
127
|
+
*/
|
|
128
|
+
const DATABASE_ERROR_PREFIX = 'encore:postgres.DatabaseError:';
|
|
129
|
+
/**
|
|
130
|
+
* Awaits a native database call, throwing the error it rejects with as a
|
|
131
|
+
* `DatabaseError` if it is one.
|
|
132
|
+
*/
|
|
133
|
+
export async function native(call) {
|
|
134
|
+
try {
|
|
135
|
+
return await call;
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
throw fromNative(err);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** `err`, a native database call's, as a `DatabaseError` if it is one. */
|
|
142
|
+
function fromNative(err) {
|
|
143
|
+
if (!(err instanceof Error) ||
|
|
144
|
+
!err.message.startsWith(DATABASE_ERROR_PREFIX)) {
|
|
145
|
+
return err;
|
|
146
|
+
}
|
|
147
|
+
const f = JSON.parse(err.message.slice(DATABASE_ERROR_PREFIX.length));
|
|
148
|
+
return new DatabaseError({
|
|
149
|
+
message: f.message,
|
|
150
|
+
code: f.code,
|
|
151
|
+
sqlState: f.sqlState,
|
|
152
|
+
severity: f.severity,
|
|
153
|
+
detail: f.detail ?? undefined,
|
|
154
|
+
hint: f.hint ?? undefined,
|
|
155
|
+
schemaName: f.schemaName ?? undefined,
|
|
156
|
+
tableName: f.tableName ?? undefined,
|
|
157
|
+
columnName: f.columnName ?? undefined,
|
|
158
|
+
dataTypeName: f.dataTypeName ?? undefined,
|
|
159
|
+
constraintName: f.constraintName ?? undefined,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../storage/postgres/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,kDAAkD;IAClD,KAAK,EAAE,OAAO;IACd,yDAAyD;IACzD,gBAAgB,EAAE,oBAAoB;IACtC,0DAA0D;IAC1D,mBAAmB,EAAE,uBAAuB;IAC5C,qDAAqD;IACrD,eAAe,EAAE,kBAAkB;IACnC,oDAAoD;IACpD,cAAc,EAAE,iBAAiB;IACjC,yDAAyD;IACzD,gBAAgB,EAAE,mBAAmB;IACrC,4EAA4E;IAC5E,iBAA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AC,CAAC,IAAI;QACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,SAAS;QAC7B,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS;QACzB,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;QACrC,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS;QACnC,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;QACrC,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;QACzC,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,SAAS;KAC9C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Postgres `interval`, exactly as Postgres holds it: months, days and
|
|
3
|
+
* microseconds apart, since a month has no fixed number of days, nor a day
|
|
4
|
+
* (across a change of daylight saving time) of microseconds.
|
|
5
|
+
*
|
|
6
|
+
* An `interval` column comes back as a string in ISO 8601's form, as
|
|
7
|
+
* Postgres writes one (`'P1Y2M3DT4H5M6.5S'`, and `'P1M-2D'` where the parts'
|
|
8
|
+
* signs differ), which {@link Interval.parse} reads. A parameter of type
|
|
9
|
+
* `interval` takes an `Interval`, a `Temporal.Duration`, or a string in any
|
|
10
|
+
* form Postgres parses (`'1 day 02:00:00'`, `'P1DT2H'`, `'90 minutes'`).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const row = await db.queryRow`SELECT ${new Interval(1, 0, 0)} + now() AS due`;
|
|
14
|
+
* const {d} = await db.queryRow`SELECT interval '1 day 2 hours' AS d`;
|
|
15
|
+
* Interval.parse(d); // months 0, days 1, microseconds 7_200_000_000
|
|
16
|
+
*/
|
|
17
|
+
export declare class Interval {
|
|
18
|
+
readonly months: number;
|
|
19
|
+
readonly days: number;
|
|
20
|
+
readonly microseconds: number;
|
|
21
|
+
/**
|
|
22
|
+
* @param months - Whole months, within a Postgres `int4`.
|
|
23
|
+
* @param days - Whole days, within a Postgres `int4`.
|
|
24
|
+
* @param microseconds - Whole microseconds, a safe integer.
|
|
25
|
+
*/
|
|
26
|
+
constructor(months: number, days: number, microseconds: number);
|
|
27
|
+
/**
|
|
28
|
+
* Parses an interval in ISO 8601's form (`P1Y2M3DT4H5M6.5S`, `P2W`), as
|
|
29
|
+
* an `interval` column comes back, or in the form Postgres writes one by
|
|
30
|
+
* default (`1 year 2 mons 3 days 04:05:06.5`, `-1 days +02:00:00`).
|
|
31
|
+
* Postgres's infinite intervals (`infinity`, `-infinity`) have no exact
|
|
32
|
+
* form, and throw. Each part but the seconds is a whole
|
|
33
|
+
* number. To have Postgres parse other forms, pass the string as a query
|
|
34
|
+
* parameter instead.
|
|
35
|
+
*
|
|
36
|
+
* @throws {TypeError} if `s` is in neither form.
|
|
37
|
+
*/
|
|
38
|
+
static parse(s: string): Interval;
|
|
39
|
+
/** The interval in ISO 8601's form, as Postgres writes it: `P1Y2M3DT4H5M6.5S`, `PT0S`. */
|
|
40
|
+
toString(): string;
|
|
41
|
+
toJSON(): string;
|
|
42
|
+
private get __encore_interval();
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=interval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,QAAQ;IAOjB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM;IAR/B;;;;OAIG;gBAEQ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM;IAO/B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ;IAUjC,0FAA0F;IAC1F,QAAQ,IAAI,MAAM;IAqBlB,MAAM,IAAI,MAAM;IAIhB,OAAO,KAAK,iBAAiB,GAE5B;CACF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const MICROS_PER_SECOND = 1000000;
|
|
2
|
+
const MICROS_PER_MINUTE = 60 * MICROS_PER_SECOND;
|
|
3
|
+
const MICROS_PER_HOUR = 60 * MICROS_PER_MINUTE;
|
|
4
|
+
const INT32_MAX = 2 ** 31 - 1;
|
|
5
|
+
/**
|
|
6
|
+
* A Postgres `interval`, exactly as Postgres holds it: months, days and
|
|
7
|
+
* microseconds apart, since a month has no fixed number of days, nor a day
|
|
8
|
+
* (across a change of daylight saving time) of microseconds.
|
|
9
|
+
*
|
|
10
|
+
* An `interval` column comes back as a string in ISO 8601's form, as
|
|
11
|
+
* Postgres writes one (`'P1Y2M3DT4H5M6.5S'`, and `'P1M-2D'` where the parts'
|
|
12
|
+
* signs differ), which {@link Interval.parse} reads. A parameter of type
|
|
13
|
+
* `interval` takes an `Interval`, a `Temporal.Duration`, or a string in any
|
|
14
|
+
* form Postgres parses (`'1 day 02:00:00'`, `'P1DT2H'`, `'90 minutes'`).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const row = await db.queryRow`SELECT ${new Interval(1, 0, 0)} + now() AS due`;
|
|
18
|
+
* const {d} = await db.queryRow`SELECT interval '1 day 2 hours' AS d`;
|
|
19
|
+
* Interval.parse(d); // months 0, days 1, microseconds 7_200_000_000
|
|
20
|
+
*/
|
|
21
|
+
export class Interval {
|
|
22
|
+
months;
|
|
23
|
+
days;
|
|
24
|
+
microseconds;
|
|
25
|
+
/**
|
|
26
|
+
* @param months - Whole months, within a Postgres `int4`.
|
|
27
|
+
* @param days - Whole days, within a Postgres `int4`.
|
|
28
|
+
* @param microseconds - Whole microseconds, a safe integer.
|
|
29
|
+
*/
|
|
30
|
+
constructor(months, days, microseconds) {
|
|
31
|
+
this.months = months;
|
|
32
|
+
this.days = days;
|
|
33
|
+
this.microseconds = microseconds;
|
|
34
|
+
check('months', months, INT32_MAX);
|
|
35
|
+
check('days', days, INT32_MAX);
|
|
36
|
+
check('microseconds', microseconds, Number.MAX_SAFE_INTEGER);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses an interval in ISO 8601's form (`P1Y2M3DT4H5M6.5S`, `P2W`), as
|
|
40
|
+
* an `interval` column comes back, or in the form Postgres writes one by
|
|
41
|
+
* default (`1 year 2 mons 3 days 04:05:06.5`, `-1 days +02:00:00`).
|
|
42
|
+
* Postgres's infinite intervals (`infinity`, `-infinity`) have no exact
|
|
43
|
+
* form, and throw. Each part but the seconds is a whole
|
|
44
|
+
* number. To have Postgres parse other forms, pass the string as a query
|
|
45
|
+
* parameter instead.
|
|
46
|
+
*
|
|
47
|
+
* @throws {TypeError} if `s` is in neither form.
|
|
48
|
+
*/
|
|
49
|
+
static parse(s) {
|
|
50
|
+
const parsed = parseISO(s) ?? parsePostgres(s);
|
|
51
|
+
if (parsed === null) {
|
|
52
|
+
throw new TypeError(`invalid interval ${JSON.stringify(s)}: expected ISO 8601 ("P1M2DT3S") or Postgres ("1 mon 2 days 00:00:03")`);
|
|
53
|
+
}
|
|
54
|
+
return new Interval(parsed.months, parsed.days, parsed.microseconds);
|
|
55
|
+
}
|
|
56
|
+
/** The interval in ISO 8601's form, as Postgres writes it: `P1Y2M3DT4H5M6.5S`, `PT0S`. */
|
|
57
|
+
toString() {
|
|
58
|
+
const years = Math.trunc(this.months / 12);
|
|
59
|
+
const months = this.months % 12;
|
|
60
|
+
const hours = Math.trunc(this.microseconds / MICROS_PER_HOUR);
|
|
61
|
+
let rest = this.microseconds % MICROS_PER_HOUR;
|
|
62
|
+
const minutes = Math.trunc(rest / MICROS_PER_MINUTE);
|
|
63
|
+
rest %= MICROS_PER_MINUTE;
|
|
64
|
+
const date = part(years, 'Y') + part(months, 'M') + part(this.days, 'D');
|
|
65
|
+
let time = part(hours, 'H') + part(minutes, 'M');
|
|
66
|
+
if (rest !== 0) {
|
|
67
|
+
const sign = rest < 0 ? '-' : '';
|
|
68
|
+
const abs = Math.abs(rest);
|
|
69
|
+
const fraction = String(abs % MICROS_PER_SECOND)
|
|
70
|
+
.padStart(6, '0')
|
|
71
|
+
.replace(/0+$/, '');
|
|
72
|
+
time += `${sign}${Math.trunc(abs / MICROS_PER_SECOND)}${fraction ? '.' + fraction : ''}S`;
|
|
73
|
+
}
|
|
74
|
+
if (date === '' && time === '')
|
|
75
|
+
return 'PT0S';
|
|
76
|
+
return 'P' + date + (time ? 'T' + time : '');
|
|
77
|
+
}
|
|
78
|
+
toJSON() {
|
|
79
|
+
return this.toString();
|
|
80
|
+
}
|
|
81
|
+
get __encore_interval() {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function check(name, value, max) {
|
|
86
|
+
if (!Number.isInteger(value) || Math.abs(value) > max) {
|
|
87
|
+
throw new RangeError(`an Interval's ${name} must be an integer of at most ${max} in magnitude, not ${value}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function part(n, unit) {
|
|
91
|
+
return n === 0 ? '' : `${n}${unit}`;
|
|
92
|
+
}
|
|
93
|
+
const ISO = /^P(?:([+-]?\d+)Y)?(?:([+-]?\d+)M)?(?:([+-]?\d+)W)?(?:([+-]?\d+)D)?(?:T(?:([+-]?\d+)H)?(?:([+-]?\d+)M)?(?:([+-]?\d+(?:\.\d{1,6})?)S)?)?$/i;
|
|
94
|
+
function parseISO(s) {
|
|
95
|
+
const m = ISO.exec(s.trim());
|
|
96
|
+
// "P" and "PT" alone name no part.
|
|
97
|
+
if (m === null || m.slice(1).every(g => g === undefined))
|
|
98
|
+
return null;
|
|
99
|
+
const n = (g) => (g === undefined ? 0 : Number(g));
|
|
100
|
+
return {
|
|
101
|
+
months: n(m[1]) * 12 + n(m[2]),
|
|
102
|
+
days: n(m[3]) * 7 + n(m[4]),
|
|
103
|
+
microseconds: n(m[5]) * MICROS_PER_HOUR +
|
|
104
|
+
n(m[6]) * MICROS_PER_MINUTE +
|
|
105
|
+
seconds(m[7] ?? '0'),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const UNITS = {
|
|
109
|
+
year: 'years',
|
|
110
|
+
years: 'years',
|
|
111
|
+
mon: 'months',
|
|
112
|
+
mons: 'months',
|
|
113
|
+
day: 'days',
|
|
114
|
+
days: 'days',
|
|
115
|
+
};
|
|
116
|
+
const TIME = /^([+-])?(\d+):(\d{2}):(\d{2}(?:\.\d{1,6})?)$/;
|
|
117
|
+
function parsePostgres(s) {
|
|
118
|
+
const words = s.trim().split(/\s+/);
|
|
119
|
+
const parts = { months: 0, days: 0, microseconds: 0 };
|
|
120
|
+
let any = false;
|
|
121
|
+
for (let i = 0; i < words.length; i++) {
|
|
122
|
+
const time = TIME.exec(words[i]);
|
|
123
|
+
if (time !== null) {
|
|
124
|
+
const sign = time[1] === '-' ? -1 : 1;
|
|
125
|
+
parts.microseconds +=
|
|
126
|
+
sign *
|
|
127
|
+
(Number(time[2]) * MICROS_PER_HOUR +
|
|
128
|
+
Number(time[3]) * MICROS_PER_MINUTE +
|
|
129
|
+
seconds(time[4]));
|
|
130
|
+
any = true;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const unit = UNITS[words[i + 1]?.toLowerCase()];
|
|
134
|
+
if (!/^[+-]?\d+$/.test(words[i]) || unit === undefined)
|
|
135
|
+
return null;
|
|
136
|
+
const n = Number(words[i]);
|
|
137
|
+
if (unit === 'years')
|
|
138
|
+
parts.months += n * 12;
|
|
139
|
+
else
|
|
140
|
+
parts[unit] += n;
|
|
141
|
+
any = true;
|
|
142
|
+
i++;
|
|
143
|
+
}
|
|
144
|
+
return any ? parts : null;
|
|
145
|
+
}
|
|
146
|
+
/** `s`, a number of seconds with up to six decimals, in microseconds. */
|
|
147
|
+
function seconds(s) {
|
|
148
|
+
const negative = s.startsWith('-');
|
|
149
|
+
const [whole, fraction = ''] = s.replace(/^[+-]/, '').split('.');
|
|
150
|
+
const micros = Number(whole) * MICROS_PER_SECOND + Number(fraction.padEnd(6, '0'));
|
|
151
|
+
return negative ? -micros : micros;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=interval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.js","sourceRoot":"","sources":["../../../storage/postgres/interval.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,OAAS,CAAC;AACpC,MAAM,iBAAiB,GAAG,EAAE,GAAG,iBAAiB,CAAC;AACjD,MAAM,eAAe,GAAG,EAAE,GAAG,iBAAiB,CAAC;AAC/C,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,QAAQ;IAOR;IACA;IACA;IARX;;;;OAIG;IACH,YACW,MAAc,EACd,IAAY,EACZ,YAAoB;QAFpB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAQ;QAE7B,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACnC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/B,KAAK,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAC,CAAS;QACpB,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,MAAM,IAAI,SAAS,CACjB,oBAAoB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,wEAAwE,CAC9G,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,QAAQ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,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjE,MAAM,MAAM,GACV,MAAM,CAAC,KAAK,CAAC,GAAG,iBAAiB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACtE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACrC,CAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { Database, DatabaseRef, Queryable, Transaction, Connection, } from './database.js';
|
|
2
|
-
export
|
|
2
|
+
export { DatabaseError, ErrorCode, TooManyRowsError } from './errors.js';
|
|
3
|
+
export { Interval } from './interval.js';
|
|
4
|
+
export type { DatabaseConfig, ReadOptions, ExecResult, IsolationLevel, MigrationsConfig, Primitive, Row as ResultRow, TransactionOptions, } from './database.js';
|
|
5
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../storage/postgres/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,YAAY,EACV,cAAc,EACd,WAAW,EACX,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,GAAG,IAAI,SAAS,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../storage/postgres/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../storage/postgres/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Target } from './target.js';
|
|
2
|
+
import { Cmd } from './wire.js';
|
|
3
|
+
/** A bitfield integer's type: signed or unsigned, and its width: `"u8"`, `"i5"`. */
|
|
4
|
+
export type BitfieldType = `${'i' | 'u'}${number}`;
|
|
5
|
+
/**
|
|
6
|
+
* Where a bitfield integer starts: at a bit, or at a multiple of its type's
|
|
7
|
+
* width (`"#2"` of a `u8` is bit 16).
|
|
8
|
+
*/
|
|
9
|
+
export type BitOffset = number | `#${number}`;
|
|
10
|
+
/**
|
|
11
|
+
* What a `set` or `incrBy` that leaves its type's range does, from the
|
|
12
|
+
* `overflow` that says so on: wrap around (the default), stop at the type's
|
|
13
|
+
* smallest or largest value, or fail, leaving the value as it was and replying
|
|
14
|
+
* `null`.
|
|
15
|
+
*/
|
|
16
|
+
export type Overflow = 'wrap' | 'sat' | 'fail';
|
|
17
|
+
/**
|
|
18
|
+
* A string's bitfield integers, read only (`BITFIELD_RO`), made by
|
|
19
|
+
* `bitmap.bitfieldRo`: add the reads, then {@link BitfieldRo.invoke}.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BitfieldRo {
|
|
22
|
+
protected readonly t: Target;
|
|
23
|
+
protected readonly c: Cmd;
|
|
24
|
+
/** @internal */
|
|
25
|
+
constructor(t: Target, c: Cmd);
|
|
26
|
+
/** Reads the integer of type `type` at `offset`. */
|
|
27
|
+
get(type: BitfieldType, offset: BitOffset): this;
|
|
28
|
+
/**
|
|
29
|
+
* Runs the operations, replying one value per `get`, `set` and `incrBy`, in
|
|
30
|
+
* order: `null` for one an `overflow('fail')` stopped. Throws a
|
|
31
|
+
* `RangeError` for a value a `number` can't hold exactly.
|
|
32
|
+
*/
|
|
33
|
+
invoke(): Promise<(number | null)[]>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A string's bitfield integers, made by `bitmap.bitfield`: add the
|
|
37
|
+
* operations, which run in order as one command, then {@link Bitfield.invoke}.
|
|
38
|
+
*/
|
|
39
|
+
export declare class Bitfield extends BitfieldRo {
|
|
40
|
+
/** Sets the integer of type `type` at `offset`, replying what it was. */
|
|
41
|
+
set(type: BitfieldType, offset: BitOffset, value: number | bigint): this;
|
|
42
|
+
/** Adds `increment` to the integer at `offset`, replying what it is then. */
|
|
43
|
+
incrBy(type: BitfieldType, offset: BitOffset, increment: number | bigint): this;
|
|
44
|
+
/** What the `set`s and `incrBy`s after this do when they leave their range. */
|
|
45
|
+
overflow(mode: Overflow): this;
|
|
46
|
+
}
|
|
47
|
+
/** A {@link BitfieldRo} being queued on a pipeline or a transaction. */
|
|
48
|
+
export declare class QueuedBitfieldRo {
|
|
49
|
+
protected readonly queued: Cmd[];
|
|
50
|
+
protected readonly c: Cmd;
|
|
51
|
+
/** @internal */
|
|
52
|
+
constructor(queued: Cmd[], c: Cmd);
|
|
53
|
+
/** Reads the integer of type `type` at `offset`. */
|
|
54
|
+
get(type: BitfieldType, offset: BitOffset): this;
|
|
55
|
+
/** Queues the operations, as one command. */
|
|
56
|
+
queue(): void;
|
|
57
|
+
}
|
|
58
|
+
/** A {@link Bitfield} being queued on a pipeline or a transaction. */
|
|
59
|
+
export declare class QueuedBitfield extends QueuedBitfieldRo {
|
|
60
|
+
/** Sets the integer of type `type` at `offset`, replying what it was. */
|
|
61
|
+
set(type: BitfieldType, offset: BitOffset, value: number | bigint): this;
|
|
62
|
+
/** Adds `increment` to the integer at `offset`, replying what it is then. */
|
|
63
|
+
incrBy(type: BitfieldType, offset: BitOffset, increment: number | bigint): this;
|
|
64
|
+
/** What the `set`s and `incrBy`s after this do when they leave their range. */
|
|
65
|
+
overflow(mode: Overflow): this;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=bitfield.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitfield.d.ts","sourceRoot":"","sources":["../../../storage/redis/bitfield.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AACrC,OAAO,EAAC,GAAG,EAA0B,MAAM,QAAQ,CAAC;AAEpD,oFAAoF;AACpF,MAAM,MAAM,YAAY,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AA4C/C;;;GAGG;AACH,qBAAa,UAAU;IAGnB,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM;IAC5B,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG;IAH3B,gBAAgB;gBAEK,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,GAAG;IAG3B,oDAAoD;IACpD,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI;IAKhD;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAG3C;AAED;;;GAGG;AACH,qBAAa,QAAS,SAAQ,UAAU;IACtC,yEAAyE;IACzE,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK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