@encore.dev/sdk 0.0.0 → 2.0.0-beta.10
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/LICENSE +362 -0
- package/README.md +245 -2
- package/app_meta.test.ts +154 -0
- package/app_meta.ts +226 -0
- package/config/config.test.ts +384 -0
- package/config/config.ts +236 -0
- package/config/mod.ts +15 -0
- package/config/secrets.ts +173 -0
- package/config/value.ts +239 -0
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +62 -0
- package/dist/app_meta.d.ts +126 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +67 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +135 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +115 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +5 -0
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +124 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +73 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +54 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +181 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +57 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +39 -0
- package/dist/cron/mod.js.map +1 -0
- 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 +171 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +284 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +108 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +349 -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 +67 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +264 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +52 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +11 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +23 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +114 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.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 +65 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +8 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +74 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +15 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +13 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +22 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/span.d.ts +75 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +234 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +16 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +71 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- 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 +12 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +18 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +59 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +308 -0
- package/dist/internal/runtime/napi/napi.d.cts +1251 -0
- package/dist/internal/runtime/shutdown.d.ts +91 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +299 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- 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 +112 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +346 -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 +10 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +40 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +125 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +21 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +10 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +242 -0
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +353 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +3 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +10 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +8 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +18 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +7 -0
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +20 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +223 -0
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +121 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +218 -0
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +281 -0
- package/dist/pubsub/topic.js.map +1 -0
- 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 +171 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +187 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +60 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/shutdown/mod.js +59 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/clickhouse/database.d.ts +262 -0
- package/dist/storage/clickhouse/database.d.ts.map +1 -0
- package/dist/storage/clickhouse/database.js +362 -0
- package/dist/storage/clickhouse/database.js.map +1 -0
- package/dist/storage/clickhouse/errors.d.ts +67 -0
- package/dist/storage/clickhouse/errors.d.ts.map +1 -0
- package/dist/storage/clickhouse/errors.js +91 -0
- package/dist/storage/clickhouse/errors.js.map +1 -0
- package/dist/storage/clickhouse/mod.d.ts +31 -0
- package/dist/storage/clickhouse/mod.d.ts.map +1 -0
- package/dist/storage/clickhouse/mod.js +29 -0
- package/dist/storage/clickhouse/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +522 -0
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +414 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +24 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +105 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +5 -0
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +47 -0
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +26 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +365 -0
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +480 -0
- package/dist/storage/postgres/database.js.map +1 -0
- 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 +5 -0
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +4 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- 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 +657 -0
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +759 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +336 -0
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +398 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +115 -0
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +109 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +16 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +21 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +90 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +55 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +290 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +611 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +12 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +92 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +49 -0
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +93 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +102 -0
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +309 -0
- package/dist/storage/redis/wire.js.map +1 -0
- 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 -0
- package/dist/types/mod.d.ts +43 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.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 +418 -0
- package/internal/clients/grpc.test.ts +664 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +481 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +305 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/http.ts +92 -0
- package/internal/otel/index.ts +14 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +26 -0
- package/internal/otel/span.ts +281 -0
- package/internal/otel/tracer.test.ts +380 -0
- package/internal/otel/tracer.ts +111 -0
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +81 -0
- package/internal/runtime/napi/napi.cjs +308 -0
- package/internal/runtime/napi/napi.d.cts +1251 -0
- package/internal/runtime/shutdown.test.ts +457 -0
- package/internal/runtime/shutdown.ts +350 -0
- 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 +384 -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/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +177 -0
- package/metrics/mod.ts +450 -0
- package/mod.ts +15 -0
- package/otel.test.ts +91 -0
- package/otel.ts +17 -0
- package/package.json +208 -5
- package/pubsub/encoding.ts +18 -0
- package/pubsub/mod.ts +26 -0
- package/pubsub/pubsub.test.ts +405 -0
- package/pubsub/refs.ts +38 -0
- package/pubsub/subscription.ts +359 -0
- package/pubsub/topic.test.ts +147 -0
- package/pubsub/topic.ts +431 -0
- 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 +370 -0
- package/services/index.ts +215 -0
- package/shutdown/mod.ts +78 -0
- package/storage/clickhouse/database.integration.test.ts +337 -0
- package/storage/clickhouse/database.test.ts +279 -0
- package/storage/clickhouse/database.ts +586 -0
- package/storage/clickhouse/errors.ts +130 -0
- package/storage/clickhouse/mod.ts +37 -0
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +968 -0
- package/storage/objects/error.ts +121 -0
- package/storage/objects/mod.ts +50 -0
- package/storage/objects/refs.ts +117 -0
- package/storage/postgres/database.integration.test.ts +450 -0
- package/storage/postgres/database.test.ts +428 -0
- package/storage/postgres/database.ts +658 -0
- 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 +19 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +1471 -0
- package/storage/redis/database.ts +520 -0
- package/storage/redis/mod.ts +171 -0
- package/storage/redis/native.ts +22 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +866 -0
- package/storage/redis/reply.ts +780 -0
- package/storage/redis/runtime.test.ts +248 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +134 -0
- package/storage/redis/wire.ts +345 -0
- 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 +272 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import {expect, test} from 'bun:test';
|
|
2
|
+
|
|
3
|
+
// A child process isolates native runtime initialization and other tests' mocks.
|
|
4
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
5
|
+
'native Postgres counts, cursor leases, connection transactions, and async disposal',
|
|
6
|
+
() => {
|
|
7
|
+
const proc = Bun.spawnSync({
|
|
8
|
+
cmd: [
|
|
9
|
+
process.execPath,
|
|
10
|
+
'-e',
|
|
11
|
+
`
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { Database } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
14
|
+
const db = new Database("postgres-tests");
|
|
15
|
+
await using conn = await db.write().acquire();
|
|
16
|
+
await conn.rawExec("CREATE TEMP TABLE encore_ts_sql_test (id int)");
|
|
17
|
+
const inserted = await conn.rawExec("INSERT INTO encore_ts_sql_test VALUES (1), (2) RETURNING id");
|
|
18
|
+
assert.equal(inserted.rowsAffected, 2n);
|
|
19
|
+
assert.equal(await conn.rawQueryRow("SELECT id FROM encore_ts_sql_test WHERE false"), null);
|
|
20
|
+
await assert.rejects(conn.rawQueryRow("SELECT id FROM encore_ts_sql_test"), /more than one row/);
|
|
21
|
+
assert.equal((await conn.rawQueryAll("SELECT id FROM encore_ts_sql_test")).length, 2);
|
|
22
|
+
|
|
23
|
+
const stream = conn.rawQuery("SELECT id FROM encore_ts_sql_test");
|
|
24
|
+
await stream.next();
|
|
25
|
+
await assert.rejects(conn.begin(), /active operation/);
|
|
26
|
+
await assert.rejects(conn.close(), /active operation/);
|
|
27
|
+
await stream.return();
|
|
28
|
+
{
|
|
29
|
+
await using tx = await conn.begin();
|
|
30
|
+
await assert.rejects(conn.rawQueryRow("SELECT 1"), /active operation/);
|
|
31
|
+
await assert.rejects(conn.close(), /active operation/);
|
|
32
|
+
const rows = tx.rawQuery("SELECT id FROM encore_ts_sql_test");
|
|
33
|
+
await rows.next();
|
|
34
|
+
await assert.rejects(tx.commit(), /active operation/);
|
|
35
|
+
await rows.return();
|
|
36
|
+
await tx.rawExec("INSERT INTO encore_ts_sql_test VALUES (3)");
|
|
37
|
+
// A previously rejected busy commit must not prevent disposal rollback.
|
|
38
|
+
}
|
|
39
|
+
assert.equal((await conn.rawQueryAll("SELECT id FROM encore_ts_sql_test")).length, 2);
|
|
40
|
+
{
|
|
41
|
+
await using tx = await conn.begin();
|
|
42
|
+
await tx.rawExec("INSERT INTO encore_ts_sql_test VALUES (3)");
|
|
43
|
+
await tx.commit();
|
|
44
|
+
await assert.rejects(tx.rawExec("SELECT 1"), /closed/);
|
|
45
|
+
}
|
|
46
|
+
assert.equal((await conn.rawQueryAll("SELECT id FROM encore_ts_sql_test")).length, 3);
|
|
47
|
+
{
|
|
48
|
+
await using tx = await conn.begin();
|
|
49
|
+
await assert.rejects(tx.rawExec("SELECT 1 / 0"));
|
|
50
|
+
}
|
|
51
|
+
assert.deepEqual(await conn.rawQueryRow("SELECT 1 AS id"), { id: 1 });
|
|
52
|
+
await conn.close();
|
|
53
|
+
await assert.rejects(conn.rawQueryRow("SELECT 1"), /closed/);
|
|
54
|
+
`,
|
|
55
|
+
],
|
|
56
|
+
env: {
|
|
57
|
+
...process.env,
|
|
58
|
+
NODE_ENV: 'test',
|
|
59
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
60
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
timeout: 30_000,
|
|
64
|
+
});
|
|
65
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
66
|
+
},
|
|
67
|
+
35_000,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// The pool has two connections: holding one, every handle runs on the other.
|
|
71
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
72
|
+
'native Postgres read handles refuse writes, and write handles still write on their connection',
|
|
73
|
+
() => {
|
|
74
|
+
const proc = Bun.spawnSync({
|
|
75
|
+
cmd: [
|
|
76
|
+
process.execPath,
|
|
77
|
+
'-e',
|
|
78
|
+
`
|
|
79
|
+
import assert from "node:assert/strict";
|
|
80
|
+
import { Database } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
81
|
+
const db = new Database("postgres-tests");
|
|
82
|
+
const table = "encore_ts_access_" + process.pid;
|
|
83
|
+
await db.rawExec("CREATE TABLE " + table + " (pid int)");
|
|
84
|
+
const write = "INSERT INTO " + table + " VALUES (pg_backend_pid())";
|
|
85
|
+
const refused = /cannot execute INSERT in a read-only transaction/;
|
|
86
|
+
try {
|
|
87
|
+
await using held = await db.write().acquire();
|
|
88
|
+
for (const reader of [db.read(), db.read({ primary: true })]) {
|
|
89
|
+
const { pid } = await reader.rawQueryRow("SELECT pg_backend_pid() AS pid");
|
|
90
|
+
await assert.rejects(reader.rawExec(write), refused);
|
|
91
|
+
{
|
|
92
|
+
await using tx = await reader.begin();
|
|
93
|
+
await assert.rejects(tx.rawExec(write), refused);
|
|
94
|
+
}
|
|
95
|
+
{
|
|
96
|
+
await using conn = await reader.acquire();
|
|
97
|
+
await assert.rejects(conn.rawExec(write), refused);
|
|
98
|
+
await using tx = await conn.begin();
|
|
99
|
+
await assert.rejects(tx.rawExec(write), refused);
|
|
100
|
+
}
|
|
101
|
+
for (const writer of [db.write(), db.admin(), db]) {
|
|
102
|
+
assert.equal((await writer.rawExec(write)).rowsAffected, 1n);
|
|
103
|
+
{
|
|
104
|
+
await using tx = await writer.begin();
|
|
105
|
+
await tx.rawExec(write);
|
|
106
|
+
await tx.commit();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Every write ran on the connection the read handle used.
|
|
110
|
+
const pids = await db.rawQueryAll("SELECT DISTINCT pid FROM " + table);
|
|
111
|
+
assert.deepEqual(pids, [{ pid }]);
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
await db.rawExec("DROP TABLE " + table);
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
117
|
+
],
|
|
118
|
+
env: {
|
|
119
|
+
...process.env,
|
|
120
|
+
NODE_ENV: 'test',
|
|
121
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
122
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
timeout: 30_000,
|
|
126
|
+
});
|
|
127
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
128
|
+
},
|
|
129
|
+
35_000,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
133
|
+
'native Postgres int8 is a number within ±(2^53−1) and an exact bigint beyond',
|
|
134
|
+
() => {
|
|
135
|
+
const proc = Bun.spawnSync({
|
|
136
|
+
cmd: [
|
|
137
|
+
process.execPath,
|
|
138
|
+
'-e',
|
|
139
|
+
`
|
|
140
|
+
import assert from "node:assert/strict";
|
|
141
|
+
import { Database } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
142
|
+
const db = new Database("postgres-tests");
|
|
143
|
+
// int8 inside the safe range is a number, outside it a bigint: never rounded.
|
|
144
|
+
const safe = await db.rawQueryRow(
|
|
145
|
+
"SELECT $1::int8 AS max, $2::int8 AS min, ARRAY[$1::int8, $2::int8] AS arr, $3::int8 AS from_bigint",
|
|
146
|
+
Number.MAX_SAFE_INTEGER, -Number.MAX_SAFE_INTEGER, 42n,
|
|
147
|
+
);
|
|
148
|
+
assert.deepEqual(safe.max, Number.MAX_SAFE_INTEGER);
|
|
149
|
+
assert.deepEqual(safe.min, -Number.MAX_SAFE_INTEGER);
|
|
150
|
+
assert.deepEqual(safe.from_bigint, 42);
|
|
151
|
+
assert.deepEqual(safe.arr, [Number.MAX_SAFE_INTEGER, -Number.MAX_SAFE_INTEGER]);
|
|
152
|
+
assert.deepEqual(await db.rawQueryRow("SELECT $1::int8 AS v", 9007199254740993n), { v: 9007199254740993n });
|
|
153
|
+
const big = { big: 9007199254740992n };
|
|
154
|
+
assert.deepEqual(await db.rawQueryRow("SELECT 9007199254740992::int8 AS big"), big);
|
|
155
|
+
assert.deepEqual(await db.rawQueryAll("SELECT 9007199254740992::int8 AS big"), [big]);
|
|
156
|
+
const rows = [];
|
|
157
|
+
for await (const row of db.rawQuery("SELECT 9007199254740992::int8 AS big")) rows.push(row);
|
|
158
|
+
assert.deepEqual(rows, [big]);
|
|
159
|
+
assert.deepEqual(
|
|
160
|
+
await db.rawQueryRow("SELECT (-9223372036854775808)::int8 AS min, ARRAY[1, 9223372036854775807]::int8[] AS arr"),
|
|
161
|
+
{ min: -9223372036854775808n, arr: [1, 9223372036854775807n] },
|
|
162
|
+
);
|
|
163
|
+
// A JSON number is not an int8, and converts the same way.
|
|
164
|
+
assert.deepEqual(
|
|
165
|
+
await db.rawQueryRow("SELECT 9223372036854775807::int8::text AS t, '9007199254740993'::jsonb AS j"),
|
|
166
|
+
{ t: "9223372036854775807", j: 9007199254740993n },
|
|
167
|
+
);
|
|
168
|
+
`,
|
|
169
|
+
],
|
|
170
|
+
env: {
|
|
171
|
+
...process.env,
|
|
172
|
+
NODE_ENV: 'test',
|
|
173
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
174
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
175
|
+
),
|
|
176
|
+
},
|
|
177
|
+
timeout: 30_000,
|
|
178
|
+
});
|
|
179
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
180
|
+
},
|
|
181
|
+
35_000,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// citext and the domain are made in a transaction that is rolled back.
|
|
185
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
186
|
+
'native Postgres intervals, and types the SDK does not decode',
|
|
187
|
+
() => {
|
|
188
|
+
const proc = Bun.spawnSync({
|
|
189
|
+
cmd: [
|
|
190
|
+
process.execPath,
|
|
191
|
+
'-e',
|
|
192
|
+
`
|
|
193
|
+
import assert from "node:assert/strict";
|
|
194
|
+
import { Database, Interval } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
195
|
+
const db = new Database("postgres-tests");
|
|
196
|
+
const HOUR = 3_600_000_000;
|
|
197
|
+
|
|
198
|
+
// interval comes back as ISO 8601, as Postgres writes it, and takes an
|
|
199
|
+
// Interval, a Temporal.Duration where there is one, or a string.
|
|
200
|
+
const iv = await db.rawQueryRow(
|
|
201
|
+
"SELECT '1 year 2 mons 3 days 04:05:06.5'::interval AS lit, $1::interval AS exact, " +
|
|
202
|
+
"$1::interval::text AS exact_text, $2::interval AS iso, $3::interval[] AS arr, " +
|
|
203
|
+
"$4::interval[] AS strs, NULL::interval AS nothing, '1 mon -2 days'::interval AS mixed, " +
|
|
204
|
+
"'2562047788:00:54.775807'::interval AS huge",
|
|
205
|
+
new Interval(-1, 40, -HOUR), "P1DT2H", [new Interval(0, 1, 0), null], ["2 hours"],
|
|
206
|
+
);
|
|
207
|
+
assert.equal(iv.lit, "P1Y2M3DT4H5M6.5S");
|
|
208
|
+
assert.deepEqual(
|
|
209
|
+
[Interval.parse(iv.lit).months, Interval.parse(iv.lit).days, Interval.parse(iv.lit).microseconds],
|
|
210
|
+
[14, 3, 4 * HOUR + 5 * 60_000_000 + 6_500_000],
|
|
211
|
+
);
|
|
212
|
+
assert.equal(iv.exact, "P-1M40DT-1H");
|
|
213
|
+
assert.equal(iv.exact_text, "-1 mons +40 days -01:00:00");
|
|
214
|
+
assert.equal(iv.iso, "P1DT2H");
|
|
215
|
+
assert.deepEqual(iv.arr, ["P1D", null]);
|
|
216
|
+
assert.deepEqual(iv.strs, ["PT2H"]);
|
|
217
|
+
assert.equal(iv.nothing, null);
|
|
218
|
+
assert.equal(iv.mixed, "P1M-2D");
|
|
219
|
+
// Beyond what a JS number holds exactly, still exact.
|
|
220
|
+
assert.equal(iv.huge, "PT2562047788H54.775807S");
|
|
221
|
+
if (typeof Temporal !== "undefined") {
|
|
222
|
+
const d = await db.rawQueryRow("SELECT $1::interval AS v", Temporal.Duration.from({months: 1, hours: 2}));
|
|
223
|
+
assert.equal(d.v, "P1MT2H");
|
|
224
|
+
assert.equal(Temporal.Duration.from(d.v).toString(), "P1MT2H");
|
|
225
|
+
}
|
|
226
|
+
await assert.rejects(db.rawQueryRow("SELECT $1::interval AS v", 5), /number not supported/);
|
|
227
|
+
// JSON data is JSON, whatever its keys are named.
|
|
228
|
+
const marked = JSON.parse('{"__encore_interval": true, "months": 1}');
|
|
229
|
+
assert.deepEqual((await db.rawQueryRow("SELECT $1::jsonb AS j", marked)).j, marked);
|
|
230
|
+
|
|
231
|
+
// Types the SDK doesn't decode are strings, as columns and parameters.
|
|
232
|
+
{
|
|
233
|
+
await using tx = await db.begin();
|
|
234
|
+
await tx.rawExec("CREATE EXTENSION IF NOT EXISTS citext");
|
|
235
|
+
await tx.rawExec("CREATE DOMAIN encore_ts_money AS money");
|
|
236
|
+
await tx.rawExec("SET LOCAL lc_monetary = 'C'");
|
|
237
|
+
await tx.rawExec("CREATE TEMP TABLE encore_ts_types (m money, t timetz, r int4range, b bit(3), x xml, c citext, p char(4), d encore_ts_money, rs int4range[], cs citext[]) ON COMMIT DROP");
|
|
238
|
+
await tx.rawExec(
|
|
239
|
+
"INSERT INTO encore_ts_types VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
|
240
|
+
"1.50", "04:05:06+02", "[1,5)", "101", "<a>b</a>", "MiXeD", "ab", "2.25", ["[1,2)", null, "empty"], ["A", "b"],
|
|
241
|
+
);
|
|
242
|
+
const row = await tx.rawQueryRow("SELECT *, c = 'mixed' AS c_eq, 'a fat cat'::tsvector AS v FROM encore_ts_types");
|
|
243
|
+
assert.deepEqual(row, {
|
|
244
|
+
m: "$1.50", t: "04:05:06+02", r: "[1,5)", b: "101", x: "<a>b</a>", c: "MiXeD", p: "ab ",
|
|
245
|
+
d: "$2.25", rs: ["[1,2)", null, "empty"], cs: ["A", "b"], c_eq: true, v: "'a' 'cat' 'fat'",
|
|
246
|
+
});
|
|
247
|
+
await assert.rejects(tx.rawExec("INSERT INTO encore_ts_types (m) VALUES ($1)", 5), /as a string/);
|
|
248
|
+
}
|
|
249
|
+
`,
|
|
250
|
+
],
|
|
251
|
+
env: {
|
|
252
|
+
...process.env,
|
|
253
|
+
NODE_ENV: 'test',
|
|
254
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
255
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
256
|
+
),
|
|
257
|
+
},
|
|
258
|
+
timeout: 30_000,
|
|
259
|
+
});
|
|
260
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
261
|
+
},
|
|
262
|
+
35_000,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
266
|
+
"native Postgres errors are DatabaseErrors with the server's fields",
|
|
267
|
+
() => {
|
|
268
|
+
const proc = Bun.spawnSync({
|
|
269
|
+
cmd: [
|
|
270
|
+
process.execPath,
|
|
271
|
+
'-e',
|
|
272
|
+
`
|
|
273
|
+
import assert from "node:assert/strict";
|
|
274
|
+
import { Database, DatabaseError, ErrorCode, TooManyRowsError } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
275
|
+
const db = new Database("postgres-tests");
|
|
276
|
+
const table = "encore_ts_errors_" + process.pid;
|
|
277
|
+
await db.rawExec("CREATE TABLE " + table + " (id int PRIMARY KEY, email text NOT NULL)");
|
|
278
|
+
try {
|
|
279
|
+
await db.rawExec("INSERT INTO " + table + " VALUES (1, 'a@example.com')");
|
|
280
|
+
|
|
281
|
+
// A unique violation, with the server's fields.
|
|
282
|
+
const dup = await db.write().rawExec("INSERT INTO " + table + " VALUES (1, 'b@example.com')").catch(e => e);
|
|
283
|
+
assert.ok(dup instanceof DatabaseError, String(dup));
|
|
284
|
+
assert.equal(dup.name, "DatabaseError");
|
|
285
|
+
assert.equal(dup.code, ErrorCode.UniqueViolation);
|
|
286
|
+
assert.equal(dup.sqlState, "23505");
|
|
287
|
+
assert.equal(dup.severity, "ERROR");
|
|
288
|
+
assert.equal(dup.schemaName, "public");
|
|
289
|
+
assert.equal(dup.tableName, table);
|
|
290
|
+
assert.equal(dup.constraintName, table + "_pkey");
|
|
291
|
+
assert.equal(dup.detail, "Key (id)=(1) already exists.");
|
|
292
|
+
assert.equal(dup.columnName, undefined);
|
|
293
|
+
assert.match(dup.message, /^ERROR: duplicate key value violates unique constraint .* \\(Code unique_violation: SQLSTATE 23505\\)$/);
|
|
294
|
+
|
|
295
|
+
// So is one in a transaction, as is the next statement in it.
|
|
296
|
+
{
|
|
297
|
+
await using tx = await db.begin();
|
|
298
|
+
const err = await tx.rawExec("INSERT INTO " + table + " (id) VALUES (2)").catch(e => e);
|
|
299
|
+
assert.ok(err instanceof DatabaseError, String(err));
|
|
300
|
+
assert.equal(err.code, "not_null_violation");
|
|
301
|
+
assert.equal(err.columnName, "email");
|
|
302
|
+
await assert.rejects(tx.rawQueryRow("SELECT 1"), e => e instanceof DatabaseError && e.code === "transaction_failed");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// A write through a read handle.
|
|
306
|
+
const ro = await db.read().rawExec("INSERT INTO " + table + " VALUES (3, 'c@example.com')").catch(e => e);
|
|
307
|
+
assert.ok(ro instanceof DatabaseError, String(ro));
|
|
308
|
+
assert.equal(ro.code, ErrorCode.ReadOnlyTransaction);
|
|
309
|
+
assert.equal(ro.sqlState, "25006");
|
|
310
|
+
|
|
311
|
+
// An error while reading rows.
|
|
312
|
+
await assert.rejects(
|
|
313
|
+
db.rawQueryAll("SELECT 1 / (id - 1) FROM " + table),
|
|
314
|
+
e => e instanceof DatabaseError && e.sqlState === "22012" && e.code === "other",
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
// The caller's mistakes are not.
|
|
318
|
+
const wrongType = await db.rawQueryRow("SELECT $1::interval AS v", 5).catch(e => e);
|
|
319
|
+
assert.ok(!(wrongType instanceof DatabaseError), String(wrongType));
|
|
320
|
+
|
|
321
|
+
await db.rawExec("INSERT INTO " + table + " VALUES (4, 'd@example.com')");
|
|
322
|
+
await assert.rejects(db.rawQueryRow("SELECT id FROM " + table), TooManyRowsError);
|
|
323
|
+
} finally {
|
|
324
|
+
await db.rawExec("DROP TABLE " + table);
|
|
325
|
+
}
|
|
326
|
+
`,
|
|
327
|
+
],
|
|
328
|
+
env: {
|
|
329
|
+
...process.env,
|
|
330
|
+
NODE_ENV: 'test',
|
|
331
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
332
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
333
|
+
),
|
|
334
|
+
},
|
|
335
|
+
timeout: 30_000,
|
|
336
|
+
});
|
|
337
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
338
|
+
},
|
|
339
|
+
35_000,
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
test.skipIf(!process.env.ENCORE_TS_POSTGRES_TEST_HOST)(
|
|
343
|
+
'native Postgres transaction options',
|
|
344
|
+
() => {
|
|
345
|
+
const proc = Bun.spawnSync({
|
|
346
|
+
cmd: [
|
|
347
|
+
process.execPath,
|
|
348
|
+
'-e',
|
|
349
|
+
`
|
|
350
|
+
import assert from "node:assert/strict";
|
|
351
|
+
import { Database, DatabaseError, ErrorCode } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
352
|
+
const db = new Database("postgres-tests");
|
|
353
|
+
const table = "encore_ts_tx_options_" + process.pid;
|
|
354
|
+
await db.rawExec("CREATE TABLE " + table + " (id int PRIMARY KEY)");
|
|
355
|
+
try {
|
|
356
|
+
{
|
|
357
|
+
await using tx = await db.begin({ isolation: "serializable", readOnly: true, deferrable: true });
|
|
358
|
+
const row = await tx.rawQueryRow(
|
|
359
|
+
"SELECT current_setting('transaction_isolation') AS iso, " +
|
|
360
|
+
"current_setting('transaction_read_only') AS ro, current_setting('transaction_deferrable') AS d",
|
|
361
|
+
);
|
|
362
|
+
assert.deepEqual(row, { iso: "serializable", ro: "on", d: "on" });
|
|
363
|
+
const err = await tx.rawExec("INSERT INTO " + table + " VALUES (9)").catch(e => e);
|
|
364
|
+
assert.ok(err instanceof DatabaseError, String(err));
|
|
365
|
+
assert.equal(err.code, ErrorCode.ReadOnlyTransaction);
|
|
366
|
+
}
|
|
367
|
+
{
|
|
368
|
+
await using tx = await db.write().begin({ isolation: "repeatable_read", readOnly: false });
|
|
369
|
+
const row = await tx.rawQueryRow("SELECT current_setting('transaction_isolation') AS iso");
|
|
370
|
+
assert.equal(row.iso, "repeatable read");
|
|
371
|
+
await tx.rawExec("INSERT INTO " + table + " VALUES (9)");
|
|
372
|
+
}
|
|
373
|
+
{
|
|
374
|
+
await using conn = await db.acquire();
|
|
375
|
+
await using tx = await conn.begin({ isolation: "read_committed", readOnly: true });
|
|
376
|
+
assert.equal((await tx.rawQueryRow("SELECT current_setting('transaction_read_only') AS ro")).ro, "on");
|
|
377
|
+
}
|
|
378
|
+
// A read handle's transactions are read-only, and say so.
|
|
379
|
+
for (const reader of [db.read(), db.read({ primary: true })]) {
|
|
380
|
+
await assert.rejects(reader.begin({ readOnly: false }), TypeError);
|
|
381
|
+
await using conn = await reader.acquire();
|
|
382
|
+
await assert.rejects(conn.begin({ readOnly: false }), TypeError);
|
|
383
|
+
await using tx = await reader.begin({ isolation: "serializable", readOnly: true });
|
|
384
|
+
const err = await tx.rawExec("INSERT INTO " + table + " VALUES (10)").catch(e => e);
|
|
385
|
+
assert.equal(err.code, ErrorCode.ReadOnlyTransaction);
|
|
386
|
+
}
|
|
387
|
+
await assert.rejects(db.begin({ isolation: "snapshot" }), TypeError);
|
|
388
|
+
} finally {
|
|
389
|
+
await db.rawExec("DROP TABLE " + table);
|
|
390
|
+
}
|
|
391
|
+
`,
|
|
392
|
+
],
|
|
393
|
+
env: {
|
|
394
|
+
...process.env,
|
|
395
|
+
NODE_ENV: 'test',
|
|
396
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(
|
|
397
|
+
process.env.ENCORE_TS_POSTGRES_TEST_HOST!,
|
|
398
|
+
),
|
|
399
|
+
},
|
|
400
|
+
timeout: 30_000,
|
|
401
|
+
});
|
|
402
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
403
|
+
},
|
|
404
|
+
35_000,
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
// Minimal RuntimeConfig protobuf, matching the Python SDK's test server setup.
|
|
408
|
+
function runtimeConfig(host: string): string {
|
|
409
|
+
function varint(n: number): Buffer {
|
|
410
|
+
const bytes: number[] = [];
|
|
411
|
+
while (n > 127) {
|
|
412
|
+
bytes.push((n & 127) | 128);
|
|
413
|
+
n >>>= 7;
|
|
414
|
+
}
|
|
415
|
+
return Buffer.from([...bytes, n]);
|
|
416
|
+
}
|
|
417
|
+
function message(field: number, data: Buffer): Buffer {
|
|
418
|
+
return Buffer.concat([varint(field * 8 + 2), varint(data.length), data]);
|
|
419
|
+
}
|
|
420
|
+
const str = (field: number, value: string) =>
|
|
421
|
+
message(field, Buffer.from(value));
|
|
422
|
+
const num = (field: number, value: number) =>
|
|
423
|
+
Buffer.concat([varint(field * 8), varint(value)]);
|
|
424
|
+
const server = Buffer.concat([str(1, 'sql:server'), str(2, host), num(3, 1)]);
|
|
425
|
+
const pool = Buffer.concat([str(2, 'sql:role'), num(4, 2)]);
|
|
426
|
+
const database = Buffer.concat([
|
|
427
|
+
str(1, 'sql:db'),
|
|
428
|
+
str(2, 'postgres-tests'),
|
|
429
|
+
str(3, 'postgres'),
|
|
430
|
+
message(4, pool),
|
|
431
|
+
]);
|
|
432
|
+
const cluster = Buffer.concat([
|
|
433
|
+
str(1, 'sql:cluster'),
|
|
434
|
+
message(2, server),
|
|
435
|
+
message(3, database),
|
|
436
|
+
]);
|
|
437
|
+
const role = Buffer.concat([
|
|
438
|
+
str(1, 'sql:role'),
|
|
439
|
+
str(2, 'postgres'),
|
|
440
|
+
message(3, str(1, 'encore-test')),
|
|
441
|
+
]);
|
|
442
|
+
const infra = Buffer.concat([
|
|
443
|
+
message(1, message(2, cluster)),
|
|
444
|
+
message(2, message(2, role)),
|
|
445
|
+
]);
|
|
446
|
+
return Buffer.concat([
|
|
447
|
+
message(1, str(1, 'ts-sql-test')),
|
|
448
|
+
message(2, infra),
|
|
449
|
+
]).toString('base64');
|
|
450
|
+
}
|