@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,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calling the app's other services.
|
|
3
|
+
*
|
|
4
|
+
* {@link client} returns a client for one service, whose `fetch` takes the
|
|
5
|
+
* service's paths:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import {client} from '@encore.dev/sdk/services';
|
|
9
|
+
*
|
|
10
|
+
* const billing = client('billing');
|
|
11
|
+
*
|
|
12
|
+
* export async function invoices(): Promise<Invoice[]> {
|
|
13
|
+
* const res = await billing.fetch('/invoices?limit=10');
|
|
14
|
+
* if (!res.ok) throw new Error(`billing: ${res.status}`);
|
|
15
|
+
* return res.json();
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Its calls, and those made with this module's {@link fetch}, carry the
|
|
20
|
+
* trace and Request Context (`@encore.dev/sdk/reqctx`) of the active context
|
|
21
|
+
* to the app's services, so the services they reach continue the request
|
|
22
|
+
* they are made for. A request to anything else carries no Request Context:
|
|
23
|
+
* who a request is made for is no business of a third party's. Pass
|
|
24
|
+
* {@link fetch} to a library that takes one, such as a generated client.
|
|
25
|
+
*
|
|
26
|
+
* A service that lists another in its `encore.service.json` `clients` gets
|
|
27
|
+
* generated clients for calling it in `encore_gen/clients`: a module per
|
|
28
|
+
* service, with a module per API the service declares. Each operation is a
|
|
29
|
+
* function of its module, so there is no client to make first:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import {catalog} from "./encore_gen/clients/index.js";
|
|
33
|
+
*
|
|
34
|
+
* const product = await catalog.openapi.getProduct("xyz");
|
|
35
|
+
* const users = await catalog.openapi.listUsers({limit: 10});
|
|
36
|
+
* const stuff = await catalog.grpc.stuffService.doStuff({});
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Importing the index loads every client of every service, cheaply: a gRPC
|
|
40
|
+
* client loads connect-es only for its first call. A deep import loads one
|
|
41
|
+
* alone: `import * as openapi from "./encore_gen/clients/catalog/openapi.js"`.
|
|
42
|
+
*
|
|
43
|
+
* A gRPC client's messages are protobuf-es's, which protoc-gen-es generates
|
|
44
|
+
* in `encore_gen/protos`, a module per `.proto` file, which every client of
|
|
45
|
+
* the service shares. A call takes its request as a message or its init,
|
|
46
|
+
* as protobuf-es's `create` does, and gives its answer as a message:
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* import {create} from "@bufbuild/protobuf";
|
|
50
|
+
* import {anyPack} from "@bufbuild/protobuf/wkt";
|
|
51
|
+
* import {NoteSchema} from "./encore_gen/protos/catalog/v1/catalog_pb.js";
|
|
52
|
+
*
|
|
53
|
+
* const note = anyPack(NoteSchema, create(NoteSchema, {text: "hi"}));
|
|
54
|
+
* const stuff = await catalog.grpc.stuffService.doStuff({id: "x", note});
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* A generated call that fails throws a {@link CallError}, whatever kind of
|
|
58
|
+
* API it calls, which `instanceof CallError` tells from any other error. Its
|
|
59
|
+
* code is the service's answer to the caller, not the caller's to its own
|
|
60
|
+
* clients: one an `@encore.dev/api` handler lets escape answers internal, as
|
|
61
|
+
* any error but an APIError does. A handler answers with a code of its own
|
|
62
|
+
* where it means one, and {@link unlessNotFound} makes a `not_found` failure
|
|
63
|
+
* `undefined`, for a call for something that may not be there:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import {APIError} from "@encore.dev/api";
|
|
67
|
+
* import {CallError, unlessNotFound} from "@encore.dev/sdk/services";
|
|
68
|
+
*
|
|
69
|
+
* try {
|
|
70
|
+
* await catalog.openapi.deleteProduct("xyz");
|
|
71
|
+
* } catch (err) {
|
|
72
|
+
* if (err instanceof CallError && err.code === "not_found") {
|
|
73
|
+
* throw APIError.notFound("no such product");
|
|
74
|
+
* }
|
|
75
|
+
* throw err; // internal
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* Every generated call also takes {@link CallOptions}: a timeout, in
|
|
82
|
+
* milliseconds, headers and an `AbortSignal` of its own, which go over its
|
|
83
|
+
* client's. A module's `Client` holds {@link ClientOptions} for every call
|
|
84
|
+
* made with it:
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* const fresh = await catalog.openapi.getProduct("xyz", {timeout: 2_000});
|
|
88
|
+
* const slow = new catalog.openapi.Client({timeout: 10_000});
|
|
89
|
+
* const mocked = new catalog.openapi.Client({baseUrl: mockServer.url});
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* The generated clients send through this module's {@link fetch}, so their
|
|
93
|
+
* calls carry the trace and Request Context as {@link client}'s do. The gRPC
|
|
94
|
+
* ones speak gRPC over HTTP/2, which fetch cannot, and carry them the same:
|
|
95
|
+
* h2c to an `http://` base URL, TLS to an `https://` one, with one
|
|
96
|
+
* connection per base URL that every call to it shares. A gRPC error
|
|
97
|
+
* answer's status details are a {@link CallError}'s `grpcDetails`. A client
|
|
98
|
+
* holds only its settings, so one made for a single call costs nothing, and
|
|
99
|
+
* there is nothing to close.
|
|
100
|
+
*
|
|
101
|
+
* Looking up a service's URL, or making a client for it, makes the calling
|
|
102
|
+
* service depend on it. Encore reads the dependency from the code, as it
|
|
103
|
+
* reads which resources a service uses: so the name must be a string
|
|
104
|
+
* literal, the function must be called directly rather than stored or passed
|
|
105
|
+
* around, and the call must be in a service.
|
|
106
|
+
*
|
|
107
|
+
* No service runs under `encore test`. Every service still has a base URL
|
|
108
|
+
* there, but a call to it is answered with `501 Not Implemented` and an error
|
|
109
|
+
* saying which service and path the test called: mock the call in the test
|
|
110
|
+
* instead. A system test's calls do reach the services, which start when
|
|
111
|
+
* first called (`system` of `@encore.dev/sdk/testing`).
|
|
112
|
+
*
|
|
113
|
+
* @module
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
import {fetch, recordOrigin} from '../internal/fetch';
|
|
117
|
+
import {runtimeConfig} from '../internal/runtime/mod';
|
|
118
|
+
|
|
119
|
+
export {fetch, wrapFetch} from '../internal/fetch';
|
|
120
|
+
export {
|
|
121
|
+
CallError,
|
|
122
|
+
httpStatus,
|
|
123
|
+
isErrCode,
|
|
124
|
+
unlessNotFound,
|
|
125
|
+
type CallOptions,
|
|
126
|
+
type ClientOptions,
|
|
127
|
+
type ErrCode,
|
|
128
|
+
type GraphQLError,
|
|
129
|
+
type GrpcDetail,
|
|
130
|
+
} from '../internal/clients/call';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The base URL the calling service reaches `service` at, without a trailing
|
|
134
|
+
* slash: a call's path goes after it, `` `${baseUrl("orders")}/orders/1` ``.
|
|
135
|
+
*
|
|
136
|
+
* Throws if the service is unknown to this process: the app has no service of
|
|
137
|
+
* that name, or the process was started without the app's service discovery.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* import {baseUrl} from "@encore.dev/sdk/services";
|
|
141
|
+
* const res = await fetch(`${baseUrl("orders")}/orders/1`);
|
|
142
|
+
*/
|
|
143
|
+
export function baseUrl(service: string): string {
|
|
144
|
+
return lookup(service).replace(/\/+$/, '');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The base URL of `service` as a `URL`, ending in `/`. Resolve relative paths
|
|
149
|
+
* against it: `new URL("orders/1", serviceUrl("orders"))`. Throws if the
|
|
150
|
+
* service is unknown to this process.
|
|
151
|
+
*
|
|
152
|
+
* Looking it up makes the calling service depend on `service`, as
|
|
153
|
+
* {@link baseUrl} does, under the same rules.
|
|
154
|
+
*
|
|
155
|
+
* @deprecated Use {@link baseUrl}, which returns the URL as a string without a
|
|
156
|
+
* trailing slash, as the other Encore SDKs do.
|
|
157
|
+
*/
|
|
158
|
+
export function serviceUrl(service: string): URL {
|
|
159
|
+
const u = new URL(lookup(service));
|
|
160
|
+
if (!u.pathname.endsWith('/')) u.pathname += '/';
|
|
161
|
+
return u;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The base URL of `service` as the runtime config gives it, whose origin
|
|
165
|
+
* it records as one of the app's services'. */
|
|
166
|
+
function lookup(service: string): string {
|
|
167
|
+
const base = runtimeConfig().services[service];
|
|
168
|
+
if (base === undefined) {
|
|
169
|
+
throw new Error(`encore: unknown service ${JSON.stringify(service)}`);
|
|
170
|
+
}
|
|
171
|
+
recordOrigin(base);
|
|
172
|
+
return base;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** A client for one of the app's services. */
|
|
176
|
+
export interface ServiceClient {
|
|
177
|
+
/** The service's base URL, without a trailing slash, as {@link baseUrl}
|
|
178
|
+
* returns it. */
|
|
179
|
+
readonly baseUrl: string;
|
|
180
|
+
/**
|
|
181
|
+
* Calls the service, as this module's {@link fetch} does. `path` is the
|
|
182
|
+
* service's: it is joined to the base URL with a single `/`, so
|
|
183
|
+
* `'/invoices'` and `'invoices'` are the same call. An absolute URL is
|
|
184
|
+
* used as it is.
|
|
185
|
+
*/
|
|
186
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A client for `service`, for service-to-service calls: its `fetch` takes the
|
|
191
|
+
* service's paths, and carries the trace and Request Context of the active
|
|
192
|
+
* context.
|
|
193
|
+
*
|
|
194
|
+
* Like {@link baseUrl}, it makes the calling service depend on `service`, so
|
|
195
|
+
* the name must be a string literal and the call made directly, in a service.
|
|
196
|
+
* Throws if the service is unknown to this process.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* import {client} from "@encore.dev/sdk/services";
|
|
200
|
+
* const orders = client("orders");
|
|
201
|
+
* const res = await orders.fetch("/orders/1");
|
|
202
|
+
*/
|
|
203
|
+
export function client(service: string): ServiceClient {
|
|
204
|
+
const base = baseUrl(service);
|
|
205
|
+
return {
|
|
206
|
+
baseUrl: base,
|
|
207
|
+
fetch: (path, init) => fetch(join(base, path), init),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** `path` under `base`, with one `/` between; an absolute URL as it is. */
|
|
212
|
+
function join(base: string, path: string): string {
|
|
213
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(path)) return path;
|
|
214
|
+
return `${base}/${path.replace(/^\/+/, '')}`;
|
|
215
|
+
}
|
package/shutdown/mod.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graceful shutdown on SIGTERM or SIGINT.
|
|
3
|
+
*
|
|
4
|
+
* On the signal Encore stops Pub/Sub intake, waits for in-flight message
|
|
5
|
+
* handlers and for the app's own work, closes its resources, flushes metrics
|
|
6
|
+
* and telemetry, and exits: with `process.exitCode` (0 unless the app set it)
|
|
7
|
+
* when this finished within the shutdown deadline, else 1. A second SIGINT,
|
|
8
|
+
* a second Ctrl-C, stops waiting for the app.
|
|
9
|
+
*
|
|
10
|
+
* The app tells Encore what to wait for. A server drains its requests in an
|
|
11
|
+
* {@link onShutdown} callback:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { onShutdown } from "@encore.dev/sdk/shutdown";
|
|
15
|
+
*
|
|
16
|
+
* const server = app.listen(port);
|
|
17
|
+
* onShutdown(() => new Promise((resolve) => server.close(() => resolve())));
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* A framework that runs shutdown hooks of its own closes in one, rather than
|
|
21
|
+
* on a signal listener of its own; with NestJS, instead of
|
|
22
|
+
* `enableShutdownHooks()`:
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* onShutdown(() => app.close());
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Work that isn't a callback holds the shutdown back with {@link hold}, or
|
|
29
|
+
* {@link waitUntil} for a promise. `using` releases a hold at the end of its
|
|
30
|
+
* scope, a job's for example:
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import * as shutdown from "@encore.dev/sdk/shutdown";
|
|
34
|
+
*
|
|
35
|
+
* async function processJob(job: Job) {
|
|
36
|
+
* using _ = shutdown.hold();
|
|
37
|
+
* await handle(job);
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Encore cleans up once every hold is released, or the shutdown deadline
|
|
42
|
+
* passes, whichever comes first. {@link signal} aborts when the shutdown
|
|
43
|
+
* begins; a callback's own signal aborts when cleanup does.
|
|
44
|
+
*
|
|
45
|
+
* An app that listens for the signal itself and holds nothing, as NestJS's
|
|
46
|
+
* `enableShutdownHooks()` does, is waited for: Encore stops taking work at
|
|
47
|
+
* once and cleans up once the app raises the signal again, exits, or has
|
|
48
|
+
* closed everything it had open. The process then ends as the app meant it
|
|
49
|
+
* to, with its own exit code, unless the shutdown deadline passed first:
|
|
50
|
+
* then the exit code is 1.
|
|
51
|
+
*
|
|
52
|
+
* Connections the app's own database pools hold, as `pg` and Drizzle's do,
|
|
53
|
+
* stay open until the app closes them or the process exits.
|
|
54
|
+
*
|
|
55
|
+
* @module
|
|
56
|
+
*/
|
|
57
|
+
import '../internal/runtime/mod';
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
begin,
|
|
61
|
+
cleanup,
|
|
62
|
+
completed,
|
|
63
|
+
forceCleanup,
|
|
64
|
+
hold,
|
|
65
|
+
onShutdown,
|
|
66
|
+
phase,
|
|
67
|
+
signal,
|
|
68
|
+
started,
|
|
69
|
+
waitUntil,
|
|
70
|
+
ShutdownError,
|
|
71
|
+
} from '../internal/runtime/shutdown';
|
|
72
|
+
export type {
|
|
73
|
+
ShutdownCallback,
|
|
74
|
+
ShutdownContext,
|
|
75
|
+
ShutdownHold,
|
|
76
|
+
ShutdownPhase,
|
|
77
|
+
ShutdownResult,
|
|
78
|
+
} from '../internal/runtime/shutdown';
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import {afterAll, beforeAll, expect, test} from 'bun:test';
|
|
2
|
+
|
|
3
|
+
// A live ClickHouse server, as the core's live tests take it:
|
|
4
|
+
// `http://user:password@host:port`, a user that may create databases and
|
|
5
|
+
// users. Each run makes a database and users of its own, and drops them.
|
|
6
|
+
const serverUrl = process.env.ENCORE_CLICKHOUSE_TEST_URL;
|
|
7
|
+
|
|
8
|
+
const prefix = `ch_ts_${process.pid}_${Date.now() % 1_000_000}`;
|
|
9
|
+
const database = prefix;
|
|
10
|
+
const users = {read: `${prefix}_r`, write: `${prefix}_w`, admin: `${prefix}_a`};
|
|
11
|
+
const password = 'ch-ts-test';
|
|
12
|
+
|
|
13
|
+
/** Runs SQL as the server URL's user. */
|
|
14
|
+
async function admin(sql: string): Promise<string> {
|
|
15
|
+
const url = new URL(serverUrl!);
|
|
16
|
+
const res = await fetch(`${url.protocol}//${url.host}/`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: {
|
|
19
|
+
'X-ClickHouse-User': decodeURIComponent(url.username || 'default'),
|
|
20
|
+
'X-ClickHouse-Key': decodeURIComponent(url.password),
|
|
21
|
+
},
|
|
22
|
+
body: sql,
|
|
23
|
+
});
|
|
24
|
+
const text = await res.text();
|
|
25
|
+
if (!res.ok) throw new Error(`${sql}: ${text}`);
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
if (!serverUrl) return;
|
|
31
|
+
await admin(`CREATE DATABASE ${database}`);
|
|
32
|
+
for (const user of Object.values(users)) {
|
|
33
|
+
await admin(
|
|
34
|
+
`CREATE USER ${user} IDENTIFIED WITH plaintext_password BY '${password}'`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
await admin(`GRANT SELECT, SHOW ON ${database}.* TO ${users.read}`);
|
|
38
|
+
await admin(
|
|
39
|
+
`GRANT SELECT, SHOW, INSERT, ALTER UPDATE, ALTER DELETE ON ${database}.* TO ${users.write}`,
|
|
40
|
+
);
|
|
41
|
+
await admin(`GRANT ALL ON ${database}.* TO ${users.admin}`);
|
|
42
|
+
// For long and endless streams.
|
|
43
|
+
await admin(
|
|
44
|
+
`GRANT SELECT ON system.numbers TO ${Object.values(users).join(', ')}`,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterAll(async () => {
|
|
49
|
+
if (!serverUrl) return;
|
|
50
|
+
for (const user of Object.values(users)) {
|
|
51
|
+
await admin(`DROP USER IF EXISTS ${user}`);
|
|
52
|
+
}
|
|
53
|
+
await admin(`DROP DATABASE IF EXISTS ${database}`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Runs `script` in a child process whose runtime config names the test
|
|
57
|
+
* database: `events` with a user per access level, and `events-write-only`,
|
|
58
|
+
* the same database with only the write user. */
|
|
59
|
+
function run(script: string) {
|
|
60
|
+
const proc = Bun.spawnSync({
|
|
61
|
+
cmd: [process.execPath, '-e', script],
|
|
62
|
+
env: {
|
|
63
|
+
...process.env,
|
|
64
|
+
NODE_ENV: 'test',
|
|
65
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(),
|
|
66
|
+
},
|
|
67
|
+
timeout: 60_000,
|
|
68
|
+
});
|
|
69
|
+
expect(proc.exitCode, proc.stderr.toString()).toBe(0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const imports = `
|
|
73
|
+
import assert from "node:assert/strict";
|
|
74
|
+
import { Database, DatabaseError, TooManyRowsError, typed } from ${JSON.stringify(`${import.meta.dir}/mod.ts`)};
|
|
75
|
+
import { Decimal } from ${JSON.stringify(`${import.meta.dir}/../../types/mod.ts`)};
|
|
76
|
+
const db = new Database("events");
|
|
77
|
+
const rejects = async (p, check) => {
|
|
78
|
+
try { await p; } catch (err) { check(err); return; }
|
|
79
|
+
assert.fail("expected the call to fail");
|
|
80
|
+
};
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
test.skipIf(!serverUrl)(
|
|
84
|
+
'ClickHouse values round-trip through inserts, parameters and rows',
|
|
85
|
+
() => {
|
|
86
|
+
run(`${imports}
|
|
87
|
+
await db.admin().exec\`CREATE TABLE t (
|
|
88
|
+
id UInt64, name String DEFAULT 'none', at DateTime64(3, 'UTC'), day Date,
|
|
89
|
+
tags Array(String), attrs Map(String, UInt32), price Decimal(10, 2),
|
|
90
|
+
big UInt64, uid UUID, ip IPv4, fs FixedString(2), opt Nullable(String),
|
|
91
|
+
j JSON
|
|
92
|
+
) ENGINE = MergeTree ORDER BY id\`;
|
|
93
|
+
|
|
94
|
+
const at = new Date("2024-05-01T12:34:56.789Z");
|
|
95
|
+
const uid = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
96
|
+
assert.deepEqual(await db.insert("t", []), { rowsWritten: 0, bytesWritten: 0, rowsRead: 0, queryId: "" });
|
|
97
|
+
const res = await db.insert("t", [
|
|
98
|
+
{ id: 1, name: "a\\tb'c", at, day: "2024-05-01", tags: ["x", "y"], attrs: { k: 1 },
|
|
99
|
+
price: new Decimal("12.30"), big: 18446744073709551615n, uid, ip: "10.0.0.1", fs: "ok",
|
|
100
|
+
j: { a: { b: "c" } } },
|
|
101
|
+
new Map([["id", 2], ["at", at], ["day", typed(new Date("2024-05-02T23:59:59Z"), "Date")],
|
|
102
|
+
["attrs", new Map([["m", 2]])], ["price", "1.5"], ["big", 5], ["uid", uid], ["ip", "10.0.0.2"],
|
|
103
|
+
["fs", "no"], ["opt", "set"], ["j", {}]]),
|
|
104
|
+
], { queryId: "${prefix}_insert" });
|
|
105
|
+
assert.equal(res.rowsWritten, 2);
|
|
106
|
+
assert.equal(res.queryId, "${prefix}_insert");
|
|
107
|
+
// Bytes that aren't UTF-8 go in as a parameter.
|
|
108
|
+
await db.exec\`INSERT INTO t (id, at, day, big, uid, ip, fs, j)
|
|
109
|
+
VALUES (\${3}, \${at}, \${"2024-05-03"}, \${0}, \${typed(uid, "UUID")}, \${"10.0.0.3"}, \${Buffer.from([0xff, 0x00])}, \${"{}"})\`;
|
|
110
|
+
|
|
111
|
+
const rows = await db.queryAll\`SELECT * FROM t WHERE has(\${[1, 2, 3]}, id) ORDER BY id\`;
|
|
112
|
+
assert.equal(rows.length, 3);
|
|
113
|
+
const [a, b, c] = rows;
|
|
114
|
+
assert.equal(a.id, 1);
|
|
115
|
+
assert.equal(a.name, "a\\tb'c");
|
|
116
|
+
assert.ok(a.at instanceof Date);
|
|
117
|
+
assert.equal(a.at.getTime(), at.getTime());
|
|
118
|
+
assert.equal(a.day, "2024-05-01");
|
|
119
|
+
assert.deepEqual(a.tags, ["x", "y"]);
|
|
120
|
+
assert.deepEqual(a.attrs, { k: 1 });
|
|
121
|
+
assert.equal(a.price, "12.30");
|
|
122
|
+
assert.equal(a.big, 18446744073709551615n);
|
|
123
|
+
assert.equal(a.uid, uid);
|
|
124
|
+
assert.equal(a.ip, "10.0.0.1");
|
|
125
|
+
assert.equal(a.fs, "ok");
|
|
126
|
+
assert.equal(a.opt, null);
|
|
127
|
+
assert.deepEqual(a.j, { a: { b: "c" } });
|
|
128
|
+
assert.equal(b.name, "none", "a missing column takes its default");
|
|
129
|
+
assert.equal(b.day, "2024-05-02");
|
|
130
|
+
assert.deepEqual(b.attrs, { m: 2 });
|
|
131
|
+
assert.equal(b.price, "1.50");
|
|
132
|
+
assert.equal(b.big, 5);
|
|
133
|
+
assert.equal(b.opt, "set");
|
|
134
|
+
assert.ok(Buffer.isBuffer(c.fs), "a FixedString that isn't UTF-8 is a Buffer");
|
|
135
|
+
assert.deepEqual([...c.fs], [0xff, 0x00]);
|
|
136
|
+
|
|
137
|
+
// Streaming, and the batches a cursor reads.
|
|
138
|
+
let n = 0;
|
|
139
|
+
for await (const row of db.rawQuery("SELECT number FROM system.numbers LIMIT 5000")) {
|
|
140
|
+
assert.equal(row.number, n++);
|
|
141
|
+
}
|
|
142
|
+
assert.equal(n, 5000);
|
|
143
|
+
// Leaving an endless query early stops it.
|
|
144
|
+
n = 0;
|
|
145
|
+
for await (const _ of db.read().rawQuery("SELECT number FROM system.numbers")) {
|
|
146
|
+
if (++n === 10) break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Decoded types.
|
|
150
|
+
const v = await db.queryRow\`SELECT
|
|
151
|
+
toInt128('-170141183460469231731687303715884105728') AS i128,
|
|
152
|
+
toUInt256('115792089237316195423570985008687907853269984665640564039457584007913129639935') AS u256,
|
|
153
|
+
toInt64(-9007199254740993) AS i64,
|
|
154
|
+
toInt64(-9007199254740991) AS safe,
|
|
155
|
+
map(1, 'a') AS m, tuple(1, 'a') AS tup, toFloat32(0.5) AS f32,
|
|
156
|
+
toDateTime('2024-05-01 00:00:00', 'Asia/Tokyo') AS tokyo,
|
|
157
|
+
CAST('b', 'Enum8(\\\\'a\\\\' = 1, \\\\'b\\\\' = 2)') AS e,
|
|
158
|
+
toIPv6('::1') AS ip6, toDecimal64(-1.5, 3) AS d\`;
|
|
159
|
+
assert.equal(v.i128, -(2n ** 127n));
|
|
160
|
+
assert.equal(v.u256, 2n ** 256n - 1n);
|
|
161
|
+
assert.equal(v.i64, -9007199254740993n);
|
|
162
|
+
assert.equal(v.safe, -9007199254740991);
|
|
163
|
+
assert.ok(v.m instanceof Map);
|
|
164
|
+
assert.equal(v.m.get(1), "a");
|
|
165
|
+
assert.deepEqual(v.tup, [1, "a"]);
|
|
166
|
+
assert.equal(v.f32, 0.5);
|
|
167
|
+
assert.equal(v.tokyo.toISOString(), "2024-04-30T15:00:00.000Z");
|
|
168
|
+
assert.equal(v.e, "b");
|
|
169
|
+
assert.equal(v.ip6, "::1");
|
|
170
|
+
assert.equal(v.d, "-1.500");
|
|
171
|
+
|
|
172
|
+
// Inferred parameter types, and values that survive the trip.
|
|
173
|
+
const s = "tab\\there\\nnewline 'quote' back\\\\slash";
|
|
174
|
+
const types = await db.queryRow\`SELECT
|
|
175
|
+
toTypeName(\${1}) AS int, toTypeName(\${1.5}) AS float, toTypeName(\${"s"}) AS str,
|
|
176
|
+
toTypeName(\${true}) AS bool, toTypeName(\${at}) AS time, toTypeName(\${[1, null]}) AS arr,
|
|
177
|
+
toTypeName(\${{ k: 1 }}) AS map, toTypeName(\${null}) AS nul, toTypeName(\${2n ** 63n}) AS u64,
|
|
178
|
+
toTypeName(\${new Decimal("1.25")}) AS dec, toTypeName(\${typed(uid, "UUID")}) AS uuid,
|
|
179
|
+
\${s} AS s, \${at} AS at, \${-(2n ** 100n)} AS neg, \${2n ** 63n} AS big,
|
|
180
|
+
\${new Decimal("1.25")} AS decv, \${[["a"], []]} AS nested,
|
|
181
|
+
\${typed(new Date("2024-05-01T23:00:00Z"), "Date")} AS date,
|
|
182
|
+
toUnixTimestamp(\${typed(at, "DateTime")}) AS secs,
|
|
183
|
+
\${new Map([[1, "x"]])} AS imap\`;
|
|
184
|
+
assert.deepEqual({ ...types, at: undefined, imap: undefined }, {
|
|
185
|
+
int: "Int64", float: "Float64", str: "String", bool: "Bool",
|
|
186
|
+
time: "DateTime64(6, 'UTC')", arr: "Array(Nullable(Int64))", map: "Map(String, Int64)",
|
|
187
|
+
nul: "Nullable(String)", u64: "UInt64", dec: "Decimal(76, 2)", uuid: "UUID",
|
|
188
|
+
s, at: undefined, neg: -(2n ** 100n), big: 2n ** 63n, decv: "1.25",
|
|
189
|
+
nested: [["a"], []], date: "2024-05-01", secs: 1714566896, imap: undefined,
|
|
190
|
+
});
|
|
191
|
+
assert.equal(types.at.getTime(), at.getTime());
|
|
192
|
+
assert.deepEqual([...types.imap], [[1, "x"]]);
|
|
193
|
+
|
|
194
|
+
// Named parameters, options, and the one-row forms.
|
|
195
|
+
assert.deepEqual(await db.rawQueryRow("SELECT {x:UInt8} + 1 AS y", { x: 4 }), { y: 5 });
|
|
196
|
+
assert.equal(await db.queryRow\`SELECT 1 WHERE 0\`, null);
|
|
197
|
+
await rejects(db.rawQueryRow("SELECT number FROM system.numbers LIMIT 3"), err => {
|
|
198
|
+
assert.ok(err instanceof TooManyRowsError);
|
|
199
|
+
assert.ok(err instanceof DatabaseError);
|
|
200
|
+
assert.equal(err.kind, "too_many_rows");
|
|
201
|
+
});
|
|
202
|
+
const ran = await db.rawExec("SELECT 1", {}, { queryId: "${prefix}_q", settings: { use_query_cache: false } });
|
|
203
|
+
assert.equal(ran.queryId, "${prefix}_q");
|
|
204
|
+
await rejects(db.rawQueryAll("SELECT number FROM system.numbers LIMIT 10", {},
|
|
205
|
+
{ settings: { max_result_rows: 1, result_overflow_mode: "throw" } }), err => {
|
|
206
|
+
assert.ok(err instanceof DatabaseError, String(err));
|
|
207
|
+
assert.equal(err.codeName, "TOO_MANY_ROWS_OR_BYTES");
|
|
208
|
+
});
|
|
209
|
+
await db.rawExec("ALTER TABLE t DELETE WHERE id = {id:UInt64}", { id: 3 }, { settings: { mutations_sync: 1 } });
|
|
210
|
+
assert.equal((await db.queryRow\`SELECT count() AS n FROM t\`).n, 2);
|
|
211
|
+
|
|
212
|
+
// Errors.
|
|
213
|
+
await rejects(db.queryAll\`SELECT * FROM nope\`, err => {
|
|
214
|
+
assert.ok(err instanceof DatabaseError);
|
|
215
|
+
assert.equal(err.name, "DatabaseError");
|
|
216
|
+
assert.equal(err.kind, "server");
|
|
217
|
+
assert.equal(err.code, 60);
|
|
218
|
+
assert.equal(err.codeName, "UNKNOWN_TABLE");
|
|
219
|
+
});
|
|
220
|
+
await rejects(db.queryAll\`SELECT \${Symbol("x")}\`, err => {
|
|
221
|
+
assert.ok(err instanceof DatabaseError, String(err));
|
|
222
|
+
assert.equal(err.kind, "invalid_argument");
|
|
223
|
+
assert.match(err.message, /p0/);
|
|
224
|
+
});
|
|
225
|
+
await rejects(db.queryAll\`SELECT \${typed(1, "Nope")}\`, err => {
|
|
226
|
+
assert.equal(err.kind, "invalid_argument");
|
|
227
|
+
});
|
|
228
|
+
await rejects(db.insert("t", [{ id: () => 1 }]), err => {
|
|
229
|
+
assert.equal(err.kind, "invalid_argument");
|
|
230
|
+
assert.match(err.message, /row 0/);
|
|
231
|
+
});
|
|
232
|
+
`);
|
|
233
|
+
},
|
|
234
|
+
65_000,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
test.skipIf(!serverUrl)(
|
|
238
|
+
'ClickHouse access levels are their own users, and a missing one falls back up',
|
|
239
|
+
() => {
|
|
240
|
+
run(`${imports}
|
|
241
|
+
await db.admin().rawExec("CREATE TABLE a (id UInt64) ENGINE = MergeTree ORDER BY id");
|
|
242
|
+
await db.write().insert("a", [{ id: 1 }]);
|
|
243
|
+
assert.equal((await db.read().queryRow\`SELECT count() AS n FROM a\`).n, 1);
|
|
244
|
+
await rejects(db.read().insert("a", [{ id: 2 }]), err => {
|
|
245
|
+
assert.equal(err.codeName, "ACCESS_DENIED");
|
|
246
|
+
});
|
|
247
|
+
await rejects(db.write().rawExec("CREATE TABLE b (id UInt64) ENGINE = Memory"), err => {
|
|
248
|
+
assert.equal(err.codeName, "ACCESS_DENIED");
|
|
249
|
+
});
|
|
250
|
+
const conn = new URL(db.read().connectionString);
|
|
251
|
+
assert.equal(conn.username, "${users.read}");
|
|
252
|
+
assert.equal(conn.pathname, "/${database}");
|
|
253
|
+
assert.equal(new URL(db.connectionString).username, "${users.write}");
|
|
254
|
+
|
|
255
|
+
// Only the write user: reads use it with readonly = 2, and there is no admin.
|
|
256
|
+
const writeOnly = new Database("events-write-only");
|
|
257
|
+
assert.equal(new URL(writeOnly.read().connectionString).username, "${users.write}");
|
|
258
|
+
assert.equal((await writeOnly.read().queryRow\`SELECT count() AS n FROM a\`).n, 1);
|
|
259
|
+
await rejects(writeOnly.read().rawExec("INSERT INTO a VALUES (3)"), err => {
|
|
260
|
+
assert.equal(err.codeName, "READONLY");
|
|
261
|
+
});
|
|
262
|
+
await rejects(writeOnly.admin().rawExec("DROP TABLE a"), err => {
|
|
263
|
+
assert.equal(err.kind, "unavailable");
|
|
264
|
+
assert.match(err.message, /no user for admin access/);
|
|
265
|
+
});
|
|
266
|
+
assert.throws(() => writeOnly.admin().connectionString, err => err instanceof DatabaseError);
|
|
267
|
+
`);
|
|
268
|
+
},
|
|
269
|
+
65_000,
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
/** A runtime config, encoded as `ENCORE_RUNTIME_CONFIG` takes it. */
|
|
273
|
+
function runtimeConfig(): string {
|
|
274
|
+
function varint(n: number): Buffer {
|
|
275
|
+
const bytes: number[] = [];
|
|
276
|
+
while (n > 127) {
|
|
277
|
+
bytes.push((n & 127) | 128);
|
|
278
|
+
n >>>= 7;
|
|
279
|
+
}
|
|
280
|
+
return Buffer.from([...bytes, n]);
|
|
281
|
+
}
|
|
282
|
+
function message(field: number, data: Buffer): Buffer {
|
|
283
|
+
return Buffer.concat([varint(field * 8 + 2), varint(data.length), data]);
|
|
284
|
+
}
|
|
285
|
+
const str = (field: number, value: string) =>
|
|
286
|
+
message(field, Buffer.from(value));
|
|
287
|
+
const num = (field: number, value: number) =>
|
|
288
|
+
Buffer.concat([varint(field * 8), varint(value)]);
|
|
289
|
+
const url = new URL(serverUrl!);
|
|
290
|
+
// ClickHouseServer{rid, url, kind: PRIMARY}
|
|
291
|
+
const server = Buffer.concat([
|
|
292
|
+
str(1, 'ch:server'),
|
|
293
|
+
str(2, `${url.protocol}//${url.host}`),
|
|
294
|
+
num(3, 1),
|
|
295
|
+
]);
|
|
296
|
+
// ClickHouseDatabase{rid, encore_name, cloud_name, read/write/admin user rids}
|
|
297
|
+
const events = Buffer.concat([
|
|
298
|
+
str(1, 'ch:events'),
|
|
299
|
+
str(2, 'events'),
|
|
300
|
+
str(3, database),
|
|
301
|
+
str(4, 'ch:read'),
|
|
302
|
+
str(5, 'ch:write'),
|
|
303
|
+
str(6, 'ch:admin'),
|
|
304
|
+
]);
|
|
305
|
+
const writeOnly = Buffer.concat([
|
|
306
|
+
str(1, 'ch:events-write-only'),
|
|
307
|
+
str(2, 'events-write-only'),
|
|
308
|
+
str(3, database),
|
|
309
|
+
str(5, 'ch:write'),
|
|
310
|
+
]);
|
|
311
|
+
const cluster = Buffer.concat([
|
|
312
|
+
str(1, 'ch:cluster'),
|
|
313
|
+
message(2, server),
|
|
314
|
+
message(3, events),
|
|
315
|
+
message(3, writeOnly),
|
|
316
|
+
]);
|
|
317
|
+
// ClickHouseUser{rid, username, password: SecretData{embedded}}
|
|
318
|
+
const user = (rid: string, name: string) =>
|
|
319
|
+
message(
|
|
320
|
+
4,
|
|
321
|
+
Buffer.concat([str(1, rid), str(2, name), message(3, str(1, password))]),
|
|
322
|
+
);
|
|
323
|
+
const credentials = Buffer.concat([
|
|
324
|
+
user('ch:read', users.read),
|
|
325
|
+
user('ch:write', users.write),
|
|
326
|
+
user('ch:admin', users.admin),
|
|
327
|
+
]);
|
|
328
|
+
// Infrastructure{resources: {clickhouse_clusters = 13}, credentials}
|
|
329
|
+
const infra = Buffer.concat([
|
|
330
|
+
message(1, message(13, cluster)),
|
|
331
|
+
message(2, credentials),
|
|
332
|
+
]);
|
|
333
|
+
return Buffer.concat([
|
|
334
|
+
message(1, str(1, 'ts-clickhouse-test')),
|
|
335
|
+
message(2, infra),
|
|
336
|
+
]).toString('base64');
|
|
337
|
+
}
|