@encore.dev/sdk 0.0.0 → 2.0.0-beta.11
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 +271 -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 +1249 -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 +320 -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 +1249 -0
- package/internal/runtime/shutdown.test.ts +464 -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 +341 -0
- package/metrics/mod.test.ts +177 -0
- package/metrics/mod.ts +450 -0
- package/mod.ts +15 -0
- package/otel.test.ts +98 -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 +393 -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 +276 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors and options of the service clients Encore generates, which
|
|
3
|
+
* `@encore.dev/sdk/services` exports, and what the clients' calls share to
|
|
4
|
+
* make and limit one.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
/// <reference types="node" />
|
|
10
|
+
/** The code of a failed call: what went wrong, as Encore's errors say. */
|
|
11
|
+
export type ErrCode = 'canceled' | 'unknown' | 'invalid_argument' | 'deadline_exceeded' | 'not_found' | 'already_exists' | 'permission_denied' | 'resource_exhausted' | 'failed_precondition' | 'aborted' | 'out_of_range' | 'unimplemented' | 'internal' | 'unavailable' | 'data_loss' | 'unauthenticated';
|
|
12
|
+
/** The HTTP status Encore answers `code` with: 404 for `not_found`. */
|
|
13
|
+
export declare function httpStatus(code: ErrCode): number;
|
|
14
|
+
/** Whether `code` is one of the codes. */
|
|
15
|
+
export declare function isErrCode(code: unknown): code is ErrCode;
|
|
16
|
+
/** One error of a GraphQL answer, as the service sent it. */
|
|
17
|
+
export interface GraphQLError {
|
|
18
|
+
message: string;
|
|
19
|
+
path?: (string | number)[];
|
|
20
|
+
locations?: {
|
|
21
|
+
line: number;
|
|
22
|
+
column: number;
|
|
23
|
+
}[];
|
|
24
|
+
extensions?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A detail of a gRPC error answer's status: a protobuf-es message, of the
|
|
28
|
+
* type its `$typeName` names, which `isMessage` of the generated schema
|
|
29
|
+
* tells: `if (isMessage(d, ReasonSchema)) use(d.why)`. One of a type the
|
|
30
|
+
* client's generated files lack is the `google.protobuf.Any` it came in,
|
|
31
|
+
* with its `typeUrl` and `value`.
|
|
32
|
+
*/
|
|
33
|
+
export interface GrpcDetail {
|
|
34
|
+
readonly $typeName: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A call to another service that failed: an error answer, or none at all.
|
|
38
|
+
*
|
|
39
|
+
* `err instanceof CallError` knows one from any copy of this package, as a
|
|
40
|
+
* monorepo with two versions of it installed has, not only from its own.
|
|
41
|
+
*/
|
|
42
|
+
export declare class CallError extends Error {
|
|
43
|
+
/**
|
|
44
|
+
* The failure's code: the one the service answered with, in Encore's
|
|
45
|
+
* error body or as its gRPC status; `unavailable` when no answer came;
|
|
46
|
+
* `deadline_exceeded` when the call took longer than its timeout;
|
|
47
|
+
* `canceled` when its signal aborted it; else the one the answer's HTTP
|
|
48
|
+
* status means, as `not_found` for 404.
|
|
49
|
+
*/
|
|
50
|
+
readonly code: ErrCode;
|
|
51
|
+
/**
|
|
52
|
+
* The HTTP status of the service's answer: the answer's own, when it was
|
|
53
|
+
* an error status, else (a gRPC or GraphQL error) the one Encore answers
|
|
54
|
+
* {@link code} with. 0 when the call got no answer, or failed before it
|
|
55
|
+
* was sent.
|
|
56
|
+
*/
|
|
57
|
+
readonly status: number;
|
|
58
|
+
/**
|
|
59
|
+
* A GraphQL answer's errors, as it sent them. Empty for any other
|
|
60
|
+
* failure. Its code is the first error's `extensions.code` when that is
|
|
61
|
+
* one of Encore's codes, and `unknown` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
readonly graphqlErrors: GraphQLError[];
|
|
64
|
+
/**
|
|
65
|
+
* A gRPC error answer's status details, as it sent them, decoded. Empty
|
|
66
|
+
* for any other failure.
|
|
67
|
+
*/
|
|
68
|
+
readonly grpcDetails: GrpcDetail[];
|
|
69
|
+
/**
|
|
70
|
+
* The service's answer with `code` and `message`, and the HTTP status
|
|
71
|
+
* Encore answers `code` with unless `options` says another: as a mock of
|
|
72
|
+
* a call throws one.
|
|
73
|
+
*/
|
|
74
|
+
constructor(code: ErrCode, message: string, options?: {
|
|
75
|
+
status?: number;
|
|
76
|
+
graphqlErrors?: GraphQLError[];
|
|
77
|
+
grpcDetails?: GrpcDetail[];
|
|
78
|
+
cause?: unknown;
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Whether `value` is a CallError: one of this copy of the package, or of
|
|
82
|
+
* another, known by its name and code.
|
|
83
|
+
*/
|
|
84
|
+
static [Symbol.hasInstance](value: unknown): value is CallError;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The error of a call that failed before or without an answer: with `code`
|
|
88
|
+
* and `message`, what the client saw, and no status.
|
|
89
|
+
*/
|
|
90
|
+
export declare function failure(code: ErrCode, message: string, cause?: unknown): CallError;
|
|
91
|
+
/**
|
|
92
|
+
* The headers of a call made with `client` and `options`, the call's over
|
|
93
|
+
* its client's, and `more` over both. Throws an `invalid_argument`
|
|
94
|
+
* {@link CallError} for one no request can carry.
|
|
95
|
+
*/
|
|
96
|
+
export declare function callHeaders(client: ClientOptions, options: CallOptions | undefined, more?: Iterable<[string, string]>): Headers;
|
|
97
|
+
/** The settings of one call, which go over its client's. */
|
|
98
|
+
export interface CallOptions {
|
|
99
|
+
/** A limit on the call, in milliseconds, in place of its client's: `null`
|
|
100
|
+
* lifts the client's, leaving the call no limit but its signal. */
|
|
101
|
+
timeout?: number | null;
|
|
102
|
+
/** Headers sent with the call, over its client's. */
|
|
103
|
+
headers?: Record<string, string>;
|
|
104
|
+
/** Aborts the call: it then fails with `canceled`. */
|
|
105
|
+
signal?: AbortSignal;
|
|
106
|
+
}
|
|
107
|
+
/** The settings of a client, for every call made with it. */
|
|
108
|
+
export interface ClientOptions {
|
|
109
|
+
/**
|
|
110
|
+
* In place of the base URL Encore gives the service, as a mock server's.
|
|
111
|
+
* A client with one never looks the service up. Its calls carry the
|
|
112
|
+
* Request Context only to the origin the app's services are reached at,
|
|
113
|
+
* where Encore serves nothing else: a mock server's carry none.
|
|
114
|
+
*/
|
|
115
|
+
baseUrl?: string;
|
|
116
|
+
/** A limit on each call, in milliseconds, unless the call sets its own. */
|
|
117
|
+
timeout?: number;
|
|
118
|
+
/** Sent with every call, under the call's own. */
|
|
119
|
+
headers?: Record<string, string>;
|
|
120
|
+
/**
|
|
121
|
+
* Sends the calls in place of the global `fetch`, as an instrumented or
|
|
122
|
+
* retrying one: it is wrapped as `@encore.dev/sdk/services`' `wrapFetch`
|
|
123
|
+
* wraps it, so the calls still carry their context. A gRPC client's calls
|
|
124
|
+
* are not sent with it, nor with any fetch: they speak HTTP/2 of their
|
|
125
|
+
* own, which fetch cannot. Point `baseUrl` at a mock gRPC server instead.
|
|
126
|
+
*/
|
|
127
|
+
fetch?: typeof globalThis.fetch;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* What `call` resolves to, or `undefined` when it fails with a
|
|
131
|
+
* {@link CallError} whose code is `not_found`: for a call for something that
|
|
132
|
+
* may not be there. Any other failure is thrown as it is.
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function unlessNotFound<T>(call: Promise<T>): Promise<T | undefined>;
|
|
139
|
+
/** The `fetch` `client`'s calls are sent with: its own, or the global
|
|
140
|
+
* one, wrapped to carry the context. */
|
|
141
|
+
export declare function fetchFor(client: ClientOptions): typeof globalThis.fetch;
|
|
142
|
+
/**
|
|
143
|
+
* The limits of one call: its timeout and its signal, and the error a call
|
|
144
|
+
* they ended failed with.
|
|
145
|
+
*/
|
|
146
|
+
export interface Deadline {
|
|
147
|
+
/** Aborts the call: undefined when nothing limits it. */
|
|
148
|
+
readonly signal: AbortSignal | undefined;
|
|
149
|
+
/** The call's timeout, in milliseconds, if it has one. */
|
|
150
|
+
readonly timeout: number | undefined;
|
|
151
|
+
/** Whether the timeout has run out: its timer may not have fired yet,
|
|
152
|
+
* when what ended the call came first, as a service ending it at the
|
|
153
|
+
* same deadline does. */
|
|
154
|
+
expired(): boolean;
|
|
155
|
+
/** The error `err`, which the call failed with doing `what`, is: the
|
|
156
|
+
* timeout's or the signal's when either ended it, else `code`'s. */
|
|
157
|
+
error(err: unknown, what: string, code: ErrCode): CallError;
|
|
158
|
+
/** Ends the timeout. */
|
|
159
|
+
done(): void;
|
|
160
|
+
}
|
|
161
|
+
/** The limits of a call made with `client` and `options`. */
|
|
162
|
+
export declare function deadline(client: ClientOptions, options: CallOptions | undefined): Deadline;
|
|
163
|
+
/** A signal aborted when either `a` or `b` is, with its reason. */
|
|
164
|
+
export declare function anySignal(a: AbortSignal, b: AbortSignal): AbortSignal;
|
|
165
|
+
export declare function errorText(err: unknown): string;
|
|
166
|
+
/**
|
|
167
|
+
* The error an error answer with body `text` is: the code and message of
|
|
168
|
+
* Encore's error body, else those its status means.
|
|
169
|
+
*/
|
|
170
|
+
export declare function errorBody(res: Response, text: string): CallError;
|
|
171
|
+
//# sourceMappingURL=call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../../internal/clients/call.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;;AAIH,0EAA0E;AAC1E,MAAM,MAAM,OAAO,GACf,UAAU,GACV,SAAS,GACT,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,GACpB,qBAAqB,GACrB,SAAS,GACT,cAAc,GACd,eAAe,GACf,UAAU,GACV,aAAa,GACb,WAAW,GACX,iBAAiB,CAAC;AAsBtB,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,0CAA0C;AAC1C,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,OAAO,CAExD;AAED,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IAC7C,UAAU,C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AC,EAAE,WAAW,GAAG,WAAW,CAWrE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAO9C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAuBhE"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors and options of the service clients Encore generates, which
|
|
3
|
+
* `@encore.dev/sdk/services` exports, and what the clients' calls share to
|
|
4
|
+
* make and limit one.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { fetch as servicesFetch, wrapFetch } from '../fetch.js';
|
|
9
|
+
/** Each code, with the HTTP status Encore answers it with. */
|
|
10
|
+
const STATUS = {
|
|
11
|
+
canceled: 499,
|
|
12
|
+
unknown: 500,
|
|
13
|
+
invalid_argument: 400,
|
|
14
|
+
deadline_exceeded: 504,
|
|
15
|
+
not_found: 404,
|
|
16
|
+
already_exists: 409,
|
|
17
|
+
permission_denied: 403,
|
|
18
|
+
resource_exhausted: 429,
|
|
19
|
+
failed_precondition: 400,
|
|
20
|
+
aborted: 409,
|
|
21
|
+
out_of_range: 400,
|
|
22
|
+
unimplemented: 501,
|
|
23
|
+
internal: 500,
|
|
24
|
+
unavailable: 503,
|
|
25
|
+
data_loss: 500,
|
|
26
|
+
unauthenticated: 401,
|
|
27
|
+
};
|
|
28
|
+
/** The HTTP status Encore answers `code` with: 404 for `not_found`. */
|
|
29
|
+
export function httpStatus(code) {
|
|
30
|
+
return STATUS[code];
|
|
31
|
+
}
|
|
32
|
+
/** Whether `code` is one of the codes. */
|
|
33
|
+
export function isErrCode(code) {
|
|
34
|
+
return typeof code === 'string' && Object.hasOwn(STATUS, code);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A call to another service that failed: an error answer, or none at all.
|
|
38
|
+
*
|
|
39
|
+
* `err instanceof CallError` knows one from any copy of this package, as a
|
|
40
|
+
* monorepo with two versions of it installed has, not only from its own.
|
|
41
|
+
*/
|
|
42
|
+
export class CallError extends Error {
|
|
43
|
+
/**
|
|
44
|
+
* The failure's code: the one the service answered with, in Encore's
|
|
45
|
+
* error body or as its gRPC status; `unavailable` when no answer came;
|
|
46
|
+
* `deadline_exceeded` when the call took longer than its timeout;
|
|
47
|
+
* `canceled` when its signal aborted it; else the one the answer's HTTP
|
|
48
|
+
* status means, as `not_found` for 404.
|
|
49
|
+
*/
|
|
50
|
+
code;
|
|
51
|
+
/**
|
|
52
|
+
* The HTTP status of the service's answer: the answer's own, when it was
|
|
53
|
+
* an error status, else (a gRPC or GraphQL error) the one Encore answers
|
|
54
|
+
* {@link code} with. 0 when the call got no answer, or failed before it
|
|
55
|
+
* was sent.
|
|
56
|
+
*/
|
|
57
|
+
status;
|
|
58
|
+
/**
|
|
59
|
+
* A GraphQL answer's errors, as it sent them. Empty for any other
|
|
60
|
+
* failure. Its code is the first error's `extensions.code` when that is
|
|
61
|
+
* one of Encore's codes, and `unknown` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
graphqlErrors;
|
|
64
|
+
/**
|
|
65
|
+
* A gRPC error answer's status details, as it sent them, decoded. Empty
|
|
66
|
+
* for any other failure.
|
|
67
|
+
*/
|
|
68
|
+
grpcDetails;
|
|
69
|
+
/**
|
|
70
|
+
* The service's answer with `code` and `message`, and the HTTP status
|
|
71
|
+
* Encore answers `code` with unless `options` says another: as a mock of
|
|
72
|
+
* a call throws one.
|
|
73
|
+
*/
|
|
74
|
+
constructor(code, message, options) {
|
|
75
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
76
|
+
this.code = code;
|
|
77
|
+
this.status = options?.status ?? httpStatus(code);
|
|
78
|
+
this.graphqlErrors = options?.graphqlErrors ?? [];
|
|
79
|
+
this.grpcDetails = options?.grpcDetails ?? [];
|
|
80
|
+
// Not enumerable, as an Error's own name.
|
|
81
|
+
Object.defineProperty(this, 'name', {
|
|
82
|
+
value: 'CallError',
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Whether `value` is a CallError: one of this copy of the package, or of
|
|
89
|
+
* another, known by its name and code.
|
|
90
|
+
*/
|
|
91
|
+
static [Symbol.hasInstance](value) {
|
|
92
|
+
if (Function.prototype[Symbol.hasInstance].call(this, value))
|
|
93
|
+
return true;
|
|
94
|
+
return (this === CallError &&
|
|
95
|
+
value instanceof Error &&
|
|
96
|
+
value.name === 'CallError' &&
|
|
97
|
+
isErrCode(value.code));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The error of a call that failed before or without an answer: with `code`
|
|
102
|
+
* and `message`, what the client saw, and no status.
|
|
103
|
+
*/
|
|
104
|
+
export function failure(code, message, cause) {
|
|
105
|
+
return new CallError(code, message, { status: 0, cause });
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The headers of a call made with `client` and `options`, the call's over
|
|
109
|
+
* its client's, and `more` over both. Throws an `invalid_argument`
|
|
110
|
+
* {@link CallError} for one no request can carry.
|
|
111
|
+
*/
|
|
112
|
+
export function callHeaders(client, options, more = []) {
|
|
113
|
+
const headers = new Headers();
|
|
114
|
+
try {
|
|
115
|
+
for (const [name, value] of Object.entries(client.headers ?? {})) {
|
|
116
|
+
headers.set(name, value);
|
|
117
|
+
}
|
|
118
|
+
for (const [name, value] of Object.entries(options?.headers ?? {})) {
|
|
119
|
+
headers.set(name, value);
|
|
120
|
+
}
|
|
121
|
+
for (const [name, value] of more)
|
|
122
|
+
headers.set(name, value);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw failure('invalid_argument', `invalid header: ${errorText(err)}`, err);
|
|
126
|
+
}
|
|
127
|
+
return headers;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* What `call` resolves to, or `undefined` when it fails with a
|
|
131
|
+
* {@link CallError} whose code is `not_found`: for a call for something that
|
|
132
|
+
* may not be there. Any other failure is thrown as it is.
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export async function unlessNotFound(call) {
|
|
139
|
+
try {
|
|
140
|
+
return await call;
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
if (err instanceof CallError && err.code === 'not_found')
|
|
144
|
+
return undefined;
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Each `fetch` of a client's, wrapped. */
|
|
149
|
+
const wrapped = new WeakMap();
|
|
150
|
+
/** The `fetch` `client`'s calls are sent with: its own, or the global
|
|
151
|
+
* one, wrapped to carry the context. */
|
|
152
|
+
export function fetchFor(client) {
|
|
153
|
+
if (client.fetch === undefined)
|
|
154
|
+
return servicesFetch;
|
|
155
|
+
let fetch = wrapped.get(client.fetch);
|
|
156
|
+
if (fetch === undefined) {
|
|
157
|
+
fetch = wrapFetch(client.fetch);
|
|
158
|
+
wrapped.set(client.fetch, fetch);
|
|
159
|
+
}
|
|
160
|
+
return fetch;
|
|
161
|
+
}
|
|
162
|
+
/** The limits of a call made with `client` and `options`. */
|
|
163
|
+
export function deadline(client, options) {
|
|
164
|
+
const timeout = options?.timeout === null
|
|
165
|
+
? undefined
|
|
166
|
+
: (options?.timeout ?? client.timeout);
|
|
167
|
+
const user = options?.signal;
|
|
168
|
+
const start = performance.now();
|
|
169
|
+
const timer = timeout === undefined ? undefined : new AbortController();
|
|
170
|
+
const expired = () => timer?.signal.aborted === true ||
|
|
171
|
+
(timeout !== undefined && performance.now() - start >= timeout);
|
|
172
|
+
const handle = timer === undefined || timeout === undefined
|
|
173
|
+
? undefined
|
|
174
|
+
: setTimeout(() => timer.abort(failure('deadline_exceeded', timedOut(timeout))), timeout);
|
|
175
|
+
let signal = user;
|
|
176
|
+
if (timer !== undefined) {
|
|
177
|
+
signal = user === undefined ? timer.signal : anySignal(user, timer.signal);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
signal,
|
|
181
|
+
timeout,
|
|
182
|
+
expired,
|
|
183
|
+
error(err, what, code) {
|
|
184
|
+
if (err instanceof CallError)
|
|
185
|
+
return err;
|
|
186
|
+
if (expired() && timeout !== undefined) {
|
|
187
|
+
return failure('deadline_exceeded', timedOut(timeout), err);
|
|
188
|
+
}
|
|
189
|
+
if (user?.aborted === true) {
|
|
190
|
+
return failure('canceled', `${what}: the call was aborted`, err);
|
|
191
|
+
}
|
|
192
|
+
return failure(code, `${what}: ${errorText(err)}`, err);
|
|
193
|
+
},
|
|
194
|
+
done() {
|
|
195
|
+
if (handle !== undefined)
|
|
196
|
+
clearTimeout(handle);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function timedOut(timeout) {
|
|
201
|
+
return `the call took longer than its timeout of ${timeout}ms`;
|
|
202
|
+
}
|
|
203
|
+
/** A signal aborted when either `a` or `b` is, with its reason. */
|
|
204
|
+
export function anySignal(a, b) {
|
|
205
|
+
if (typeof AbortSignal.any === 'function')
|
|
206
|
+
return AbortSignal.any([a, b]);
|
|
207
|
+
const both = new AbortController();
|
|
208
|
+
for (const s of [a, b]) {
|
|
209
|
+
if (s.aborted) {
|
|
210
|
+
both.abort(s.reason);
|
|
211
|
+
return both.signal;
|
|
212
|
+
}
|
|
213
|
+
s.addEventListener('abort', () => both.abort(s.reason), { once: true });
|
|
214
|
+
}
|
|
215
|
+
return both.signal;
|
|
216
|
+
}
|
|
217
|
+
export function errorText(err) {
|
|
218
|
+
if (err instanceof Error) {
|
|
219
|
+
// Node's fetch says only "fetch failed", and why in its cause.
|
|
220
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : '';
|
|
221
|
+
return err.message + cause;
|
|
222
|
+
}
|
|
223
|
+
return String(err);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The error an error answer with body `text` is: the code and message of
|
|
227
|
+
* Encore's error body, else those its status means.
|
|
228
|
+
*/
|
|
229
|
+
export function errorBody(res, text) {
|
|
230
|
+
let parsed;
|
|
231
|
+
try {
|
|
232
|
+
const value = JSON.parse(text);
|
|
233
|
+
if (typeof value === 'object' && value !== null) {
|
|
234
|
+
parsed = value;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
parsed = undefined;
|
|
239
|
+
}
|
|
240
|
+
// In either case, as Go's client reads it.
|
|
241
|
+
const named = typeof parsed?.code === 'string' ? parsed.code.toLowerCase() : undefined;
|
|
242
|
+
const code = isErrCode(named) ? named : statusCode(res.status);
|
|
243
|
+
const message = typeof parsed?.message === 'string'
|
|
244
|
+
? parsed.message
|
|
245
|
+
: text !== ''
|
|
246
|
+
? text
|
|
247
|
+
: res.statusText;
|
|
248
|
+
return new CallError(code, message, {
|
|
249
|
+
status: res.status >= 400 ? res.status : httpStatus(code),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** The code an error answer without Encore's error body means: as the
|
|
253
|
+
* other SDKs' generated clients read it. */
|
|
254
|
+
function statusCode(status) {
|
|
255
|
+
switch (status) {
|
|
256
|
+
case 400:
|
|
257
|
+
return 'invalid_argument';
|
|
258
|
+
case 401:
|
|
259
|
+
return 'unauthenticated';
|
|
260
|
+
case 403:
|
|
261
|
+
return 'permission_denied';
|
|
262
|
+
case 404:
|
|
263
|
+
return 'not_found';
|
|
264
|
+
case 408:
|
|
265
|
+
case 504:
|
|
266
|
+
return 'deadline_exceeded';
|
|
267
|
+
case 409:
|
|
268
|
+
return 'already_exists';
|
|
269
|
+
case 429:
|
|
270
|
+
return 'resource_exhausted';
|
|
271
|
+
case 499:
|
|
272
|
+
return 'canceled';
|
|
273
|
+
case 500:
|
|
274
|
+
return 'internal';
|
|
275
|
+
case 501:
|
|
276
|
+
return 'unimplemented';
|
|
277
|
+
case 502:
|
|
278
|
+
case 503:
|
|
279
|
+
return 'unavailable';
|
|
280
|
+
default:
|
|
281
|
+
return 'unknown';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../internal/clients/call.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,KAAK,IAAI,aAAa,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAqB3D,8DAA8D;AAC9D,MAAM,MAAM,GAA4B;IACtC,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,gBAAgB,EAAE,GAAG;IACrB,iBAAiB,EAAE,GAAG;IACtB,SAAS,EAAE,GAAG;IACd,cAAc,EAAE,GAAG;IACnB,iBAAiB,EAAE,GAAG;IACtB,kBAAkB,EAAE,GAAG;IACvB,mBAAmB,EAAE,GAAG;IACxB,OAAO,EAAE,GAAG;IACZ,YAAY,EAAE,GAAG;IACjB,aAAa,EAAE,GAAG;IAClB,QAAQ,EAAE,GAAG;IACb,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,GAAG;IACd,eAAe,EAAE,GAAG;CACrB,CAAC;AAEF,uEAAuE;AACvE,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAqBD;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC;;;;;;OAMG;IACM,IAAI,CAAU;IACvB;;;;;OAKG;IACM,MAAM,CAAS;IACxB;;;;OAIG;IACM,aAAa,CAAiB;IACvC;;;OAGG;IACM,WAAW,CAAe;IAEnC;;;;OA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AC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls of the generated gRPC clients: the gRPC protocol, over HTTP/2. For
|
|
3
|
+
* the generated code: it may change with the generator.
|
|
4
|
+
*
|
|
5
|
+
* It needs `@bufbuild/protobuf`, `@connectrpc/connect` and
|
|
6
|
+
* `@connectrpc/connect-node`, optional peer dependencies of the SDK that a
|
|
7
|
+
* service with gRPC clients installs:
|
|
8
|
+
*
|
|
9
|
+
* ```sh
|
|
10
|
+
* npm install @bufbuild/protobuf@^2.17 @connectrpc/connect@^2.2 @connectrpc/connect-node@^2.2
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* A client's messages are protobuf-es's, which `protoc-gen-es` generates
|
|
14
|
+
* in the consumer's `encore_gen/protos`, a module per `.proto` file: a call
|
|
15
|
+
* takes its method's descriptor of the generated `GenService`, makes its
|
|
16
|
+
* request a message with protobuf-es's `create`, and gives its answers as
|
|
17
|
+
* protobuf-es decodes them, keeping the fields and enum values their schema
|
|
18
|
+
* lacks.
|
|
19
|
+
*
|
|
20
|
+
* Calls go through connect-es's gRPC transport for Node, which speaks
|
|
21
|
+
* HTTP/2 with `node:http2`, under Node and Bun alike: cleartext with prior
|
|
22
|
+
* knowledge (h2c) to an `http://` base URL, and TLS, offering only `h2`, to
|
|
23
|
+
* an `https://` one, trusting the certificates Node's TLS trusts, as those
|
|
24
|
+
* `NODE_EXTRA_CA_CERTS` adds. `fetch` can do neither, nor read trailers, so
|
|
25
|
+
* no gRPC call is sent with a fetch, nor with a client's `fetch` option.
|
|
26
|
+
* The calls to one base URL share one connection, which keeps no process
|
|
27
|
+
* alive while none is in flight.
|
|
28
|
+
*
|
|
29
|
+
* A call carries the trace and Request Context of the context it is made
|
|
30
|
+
* in to the app's own services, as `fetch` of `@encore.dev/sdk/services`
|
|
31
|
+
* does, and nothing of them anywhere else: a stream, of the context it is
|
|
32
|
+
* called in rather than the one it is first read in. A unary call returns a
|
|
33
|
+
* `Promise`; a server stream is an `AsyncIterable`. Streams are full duplex:
|
|
34
|
+
* a bidirectional stream's answers come as the service sends them, while its
|
|
35
|
+
* requests are still being sent. An answer compressed with gzip or brotli
|
|
36
|
+
* is read; requests are sent uncompressed.
|
|
37
|
+
*
|
|
38
|
+
* Every failure of a call is a {@link CallError}: the status the service
|
|
39
|
+
* answered with, with its details decoded (`grpcDetails`) by the generated
|
|
40
|
+
* files of the client's API, and the files they import; `unavailable` when
|
|
41
|
+
* no answer came, as when the connection failed or was reset;
|
|
42
|
+
* `deadline_exceeded` when the call's timeout, which it sends as its
|
|
43
|
+
* deadline and which runs from its start to its last answer, ran out;
|
|
44
|
+
* `canceled` when its signal aborted it. A request that cannot be made a
|
|
45
|
+
* message fails it with `invalid_argument`. The one failure that is no
|
|
46
|
+
* CallError is the caller's own: a client or bidirectional stream whose
|
|
47
|
+
* requests' iterable throws ends the call, and fails with what it threw, as
|
|
48
|
+
* it was thrown.
|
|
49
|
+
*
|
|
50
|
+
* `@bufbuild/protobuf` is loaded on import, as the generated messages load
|
|
51
|
+
* it. connect-es is loaded by the first call: a module importing the
|
|
52
|
+
* generated clients loads without it, and with no top-level await, so
|
|
53
|
+
* `require()` loads it too. A call made without it fails saying what to
|
|
54
|
+
* install.
|
|
55
|
+
*
|
|
56
|
+
* @hidden
|
|
57
|
+
* @module
|
|
58
|
+
*/
|
|
59
|
+
import { type DescFile, type DescMessage, type DescMethod, type DescService, type MessageInitShape, type MessageShape } from '@bufbuild/protobuf';
|
|
60
|
+
import { type CallOptions, type ClientOptions } from './call.js';
|
|
61
|
+
import type { Service } from './mod.js';
|
|
62
|
+
/** A method of a generated `GenService` of kind `K`, from messages of `I`
|
|
63
|
+
* to messages of `O`. */
|
|
64
|
+
export type Method<K extends DescMethod['methodKind'], I extends DescMessage, O extends DescMessage> = Omit<DescMethod, 'methodKind' | 'input' | 'output'> & {
|
|
65
|
+
readonly methodKind: K;
|
|
66
|
+
readonly input: I;
|
|
67
|
+
readonly output: O;
|
|
68
|
+
};
|
|
69
|
+
/** The calls of one gRPC service of a service's, made with a client's
|
|
70
|
+
* settings. */
|
|
71
|
+
export declare class ServiceClient {
|
|
72
|
+
private readonly svc;
|
|
73
|
+
private readonly client;
|
|
74
|
+
private readonly desc;
|
|
75
|
+
private readonly files;
|
|
76
|
+
/** The registry of {@link files}, once a status's details needed it. */
|
|
77
|
+
private registry;
|
|
78
|
+
/**
|
|
79
|
+
* `desc` is the gRPC service's generated `GenService`, and `files` the
|
|
80
|
+
* generated files of its API, which a status's details are decoded with,
|
|
81
|
+
* together with the files they import.
|
|
82
|
+
*/
|
|
83
|
+
constructor(svc: Service, client: ClientOptions, desc: DescService, files?: readonly DescFile[]);
|
|
84
|
+
/** Calls unary `method` with `request`. */
|
|
85
|
+
unary<I extends DescMessage, O extends DescMessage>(method: Method<'unary', I, O>, request: MessageInitShape<I>, options?: CallOptions): Promise<MessageShape<O>>;
|
|
86
|
+
/** Calls server-streaming `method` with `request`: its answers. */
|
|
87
|
+
serverStream<I extends DescMessage, O extends DescMessage>(method: Method<'server_streaming', I, O>, request: MessageInitShape<I>, options?: CallOptions): AsyncIterable<MessageShape<O>>;
|
|
88
|
+
/** Calls client-streaming `method` with `requests`: its one answer. */
|
|
89
|
+
clientStream<I extends DescMessage, O extends DescMessage>(method: Method<'client_streaming', I, O>, requests: AsyncIterable<MessageInitShape<I>>, options?: CallOptions): Promise<MessageShape<O>>;
|
|
90
|
+
/** Calls bidirectional-streaming `method` with `requests`: its answers. */
|
|
91
|
+
bidiStream<I extends DescMessage, O extends DescMessage>(method: Method<'bidi_streaming', I, O>, requests: AsyncIterable<MessageInitShape<I>>, options?: CallOptions): AsyncIterable<MessageShape<O>>;
|
|
92
|
+
/** The answers of streaming method `m`, made in `ctx`, sent the messages
|
|
93
|
+
* `requests` makes, under the call's limits; failing with a CallError
|
|
94
|
+
* unless the caller's requests threw. */
|
|
95
|
+
private answers;
|
|
96
|
+
/** The transport of a call of `m` made in `ctx`, and its headers: with
|
|
97
|
+
* the context's trace and Request Context when the call is for the app's
|
|
98
|
+
* services. */
|
|
99
|
+
private prepare;
|
|
100
|
+
/** The error a call of `m` failed with `err` is: what the caller's
|
|
101
|
+
* requests threw, if they did; its timeout's or signal's when either
|
|
102
|
+
* ended it; the status the service answered with; `unavailable` when no
|
|
103
|
+
* answer came; else connect-es's own. */
|
|
104
|
+
private error;
|
|
105
|
+
/** The messages of {@link files} and of the files they import. */
|
|
106
|
+
private types;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=grpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc.d.ts","sourceRoot":"","sources":["../../../internal/clients/grpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAElB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,aAAa,EAInB,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAgDnC;yBACyB;AACzB,MAAM,MAAM,MAAM,CAChB,CAAC,SAAS,UAAU,CAAC,YAAY,CAAC,EAClC,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,IACnB,IAAI,CAAC,UAAU,EAAE,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG;IACxD,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACpB,CAAC;AAQF;eACe;AACf,qBAAa,aAAa;IAUtB,OAAO,CAAC,QAA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