@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,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Context in its wire form, as the OpenTelemetry context holds it.
|
|
3
|
+
*
|
|
4
|
+
* A request's fields (ADR 0014) travel with the context of the code handling
|
|
5
|
+
* it: each field's name, and its value as it travels, base64url (without
|
|
6
|
+
* padding) of its JSON. They are kept in that form, so moving them costs
|
|
7
|
+
* nothing; only reading one decodes it. Every field a request carries is kept
|
|
8
|
+
* and sent on, those this process declares nothing about included, so a
|
|
9
|
+
* service passes on the fields of the services it sits between.
|
|
10
|
+
*
|
|
11
|
+
* `@encore.dev/sdk/reqctx` reads and sets fields and takes them from and puts
|
|
12
|
+
* them on requests; `pubsub` hands the runtime every field a message is
|
|
13
|
+
* published with, and the runtime carries those declared with `pubsub`.
|
|
14
|
+
*
|
|
15
|
+
* How a field travels is its declaration's, wherever it is: the runtime
|
|
16
|
+
* config lists every field the app declares ({@link configOf}).
|
|
17
|
+
*/
|
|
18
|
+
import {
|
|
19
|
+
createContextKey,
|
|
20
|
+
type Context,
|
|
21
|
+
type TextMapGetter,
|
|
22
|
+
type TextMapPropagator,
|
|
23
|
+
} from '@opentelemetry/api';
|
|
24
|
+
import {activeContext} from './otel/context';
|
|
25
|
+
|
|
26
|
+
/** The header a field travels in on a request, before its name. */
|
|
27
|
+
export const HEADER_PREFIX = 'x-encore-meta-ctx-';
|
|
28
|
+
/** The attribute a field travels in on a Pub/Sub message, before its name. */
|
|
29
|
+
export const ATTRIBUTE_PREFIX = 'encore-ctx-';
|
|
30
|
+
/** The span attribute a field declared with `trace` is, before its name. */
|
|
31
|
+
export const SPAN_ATTRIBUTE_PREFIX = 'encore.ctx.';
|
|
32
|
+
/** Encore's own field under test: the id of the test a request is made for. */
|
|
33
|
+
export const TEST_FIELD = 'encore-test';
|
|
34
|
+
/** The span attribute the test's id is, on every span of what it caused. */
|
|
35
|
+
export const TEST_ID_ATTRIBUTE = 'encore.test.id';
|
|
36
|
+
|
|
37
|
+
/** The most one field encodes to, in bytes. */
|
|
38
|
+
export const MAX_VALUE_SIZE = 4096;
|
|
39
|
+
/** The most a field declared with `pubsub` encodes to, in bytes: GCP
|
|
40
|
+
* Pub/Sub's limit on an attribute's value. */
|
|
41
|
+
export const MAX_PUBSUB_VALUE_SIZE = 1024;
|
|
42
|
+
/** The most all of a request's fields encode to, in bytes. */
|
|
43
|
+
export const MAX_SIZE = 8192;
|
|
44
|
+
|
|
45
|
+
/** A context's fields: name to wire form. Never changed once in a context,
|
|
46
|
+
* but those of a gateway hook's ({@link withLiveFields}). */
|
|
47
|
+
export type Fields = Readonly<Record<string, string>>;
|
|
48
|
+
|
|
49
|
+
const KEY = createContextKey('encore-request-context');
|
|
50
|
+
|
|
51
|
+
const NAME = /^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
52
|
+
const BASE64URL = /^[A-Za-z0-9_-]*$/;
|
|
53
|
+
|
|
54
|
+
/** How a field travels, as its declaration says. */
|
|
55
|
+
export interface Config {
|
|
56
|
+
/** Carried on the Pub/Sub messages published with it set. */
|
|
57
|
+
pubsub: boolean;
|
|
58
|
+
/** Put on the spans started with it set. */
|
|
59
|
+
trace: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const NONE: Config = {pubsub: false, trace: false};
|
|
63
|
+
|
|
64
|
+
/** The configs of the fields this process declares. */
|
|
65
|
+
const configs = new Map<string, Config>();
|
|
66
|
+
|
|
67
|
+
/** The configs the runtime config lists, memoised by name. */
|
|
68
|
+
const declared = new Map<string, Config | null>();
|
|
69
|
+
let lookup: ((name: string) => Config | null) | undefined;
|
|
70
|
+
|
|
71
|
+
/** Whether `name` can be a field's: what the parser lets a declaration
|
|
72
|
+
* have, kebab-case, 1 to 63 lowercase letters, digits and hyphens, starting
|
|
73
|
+
* with a letter and ending with a letter or digit. The parser checks the
|
|
74
|
+
* declarations; this only keeps what a request or message carries to names a
|
|
75
|
+
* field could have. */
|
|
76
|
+
export function validName(name: unknown): name is string {
|
|
77
|
+
return typeof name === 'string' && NAME.test(name);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Records the config of the field `name`, declared in this process. */
|
|
81
|
+
export function declare(name: string, config: Config): void {
|
|
82
|
+
configs.set(name, config);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Where {@link configOf} reads the runtime config's fields: set by the
|
|
86
|
+
* runtime as it loads, so this module needs no native code. */
|
|
87
|
+
export function setDeclaredLookup(fn: (name: string) => Config | null): void {
|
|
88
|
+
lookup = fn;
|
|
89
|
+
declared.clear();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The config of the field `name`, as the app declares it.
|
|
94
|
+
*
|
|
95
|
+
* The runtime config lists every field the app declares, so a field this
|
|
96
|
+
* process only binds by name travels as declared. A field it does not list,
|
|
97
|
+
* as without Encore's tooling, has the config this process declares it with,
|
|
98
|
+
* or none.
|
|
99
|
+
*/
|
|
100
|
+
export function configOf(name: string): Config {
|
|
101
|
+
if (lookup !== undefined) {
|
|
102
|
+
let config = declared.get(name);
|
|
103
|
+
if (config === undefined) {
|
|
104
|
+
config = lookup(name);
|
|
105
|
+
declared.set(name, config);
|
|
106
|
+
}
|
|
107
|
+
if (config !== null) return config;
|
|
108
|
+
}
|
|
109
|
+
return configs.get(name) ?? NONE;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The wire form of a JSON value. Throws a `TypeError` when it has none. */
|
|
113
|
+
export function encode(value: unknown): string {
|
|
114
|
+
const json = JSON.stringify(value);
|
|
115
|
+
if (json === undefined) {
|
|
116
|
+
throw new TypeError(`a ${typeOf(value)} has no JSON form`);
|
|
117
|
+
}
|
|
118
|
+
return Buffer.from(json, 'utf8').toString('base64url');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function typeOf(value: unknown): string {
|
|
122
|
+
return value === null ? 'null' : typeof value;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The JSON value of a field's wire form. Throws when it is not base64url
|
|
127
|
+
* without padding, or what that holds is not JSON. Says where it is wrong,
|
|
128
|
+
* never what it holds: a field may hold who a request is made for.
|
|
129
|
+
*/
|
|
130
|
+
export function decode(value: string): unknown {
|
|
131
|
+
if (!BASE64URL.test(value) || value.length % 4 === 1) {
|
|
132
|
+
throw new Error('it is not base64url without padding');
|
|
133
|
+
}
|
|
134
|
+
let text: string;
|
|
135
|
+
try {
|
|
136
|
+
text = new TextDecoder('utf-8', {fatal: true}).decode(
|
|
137
|
+
Buffer.from(value, 'base64url'),
|
|
138
|
+
);
|
|
139
|
+
} catch {
|
|
140
|
+
throw new Error('it is not UTF-8');
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(text);
|
|
144
|
+
} catch {
|
|
145
|
+
throw new Error('it is not valid JSON');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The fields of `ctx`, or of the active context: name to wire form. */
|
|
150
|
+
export function current(ctx: Context = activeContext()): Fields {
|
|
151
|
+
const fields = ctx.getValue(KEY);
|
|
152
|
+
return isFields(fields) ? fields : {};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isFields(value: unknown): value is Fields {
|
|
156
|
+
return typeof value === 'object' && value !== null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A copy of `ctx` holding exactly `fields`. */
|
|
160
|
+
export function withFields(
|
|
161
|
+
fields: Record<string, string>,
|
|
162
|
+
ctx: Context = activeContext(),
|
|
163
|
+
): Context {
|
|
164
|
+
return ctx.setValue(KEY, Object.freeze({...fields}));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A copy of `ctx` holding `fields` itself, not a copy of them: a field set
|
|
169
|
+
* in `fields` later shows in the context, and in every context made from
|
|
170
|
+
* it, until one of those sets a field of its own. A gateway Middleware's
|
|
171
|
+
* hook runs in one, so its calls carry what it has set on its request so
|
|
172
|
+
* far.
|
|
173
|
+
*/
|
|
174
|
+
export function withLiveFields(
|
|
175
|
+
fields: Record<string, string>,
|
|
176
|
+
ctx: Context = activeContext(),
|
|
177
|
+
): Context {
|
|
178
|
+
return ctx.setValue(KEY, fields);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A copy of `ctx` with the field `name` set to `value`, a wire form.
|
|
183
|
+
*
|
|
184
|
+
* Throws a `RangeError`, saying what the value does, when it is bigger than
|
|
185
|
+
* the field may be, or makes the fields bigger than a request's may be.
|
|
186
|
+
*/
|
|
187
|
+
export function withValue(
|
|
188
|
+
name: string,
|
|
189
|
+
value: string,
|
|
190
|
+
ctx: Context = activeContext(),
|
|
191
|
+
): Context {
|
|
192
|
+
if (value.length > MAX_VALUE_SIZE) {
|
|
193
|
+
throw new RangeError(
|
|
194
|
+
`encodes to ${value.length} bytes, more than the ${MAX_VALUE_SIZE} a field may`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (configOf(name).pubsub && value.length > MAX_PUBSUB_VALUE_SIZE) {
|
|
198
|
+
throw new RangeError(
|
|
199
|
+
`encodes to ${value.length} bytes, more than the ${MAX_PUBSUB_VALUE_SIZE} ` +
|
|
200
|
+
'a field carried on Pub/Sub messages may',
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
const fields = {...current(ctx), [name]: value};
|
|
204
|
+
const size = Object.values(fields).reduce((n, v) => n + v.length, 0);
|
|
205
|
+
if (size > MAX_SIZE) {
|
|
206
|
+
throw new RangeError(
|
|
207
|
+
`makes the request's fields encode to ${size} bytes, more than the ${MAX_SIZE} they may`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return withFields(fields, ctx);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** A copy of `ctx` without the field `name`. */
|
|
214
|
+
export function without(name: string, ctx: Context = activeContext()): Context {
|
|
215
|
+
const fields = current(ctx);
|
|
216
|
+
if (!Object.hasOwn(fields, name)) return ctx;
|
|
217
|
+
const rest: Record<string, string> = {...fields};
|
|
218
|
+
delete rest[name];
|
|
219
|
+
return withFields(rest, ctx);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** The field the header `name` carries, if it carries one. */
|
|
223
|
+
export function headerField(name: string): string | undefined {
|
|
224
|
+
const lowered = name.toLowerCase();
|
|
225
|
+
if (!lowered.startsWith(HEADER_PREFIX)) return undefined;
|
|
226
|
+
const field = lowered.slice(HEADER_PREFIX.length);
|
|
227
|
+
return validName(field) ? field : undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** A fetch `Headers`, or anything with its methods. */
|
|
231
|
+
export interface HeadersLike {
|
|
232
|
+
get(name: string): string | null;
|
|
233
|
+
set(name: string, value: string): void;
|
|
234
|
+
delete(name: string): void;
|
|
235
|
+
forEach(fn: (value: string, name: string) => void): void;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A request's headers: a fetch `Headers`, Node's `IncomingHttpHeaders`, or
|
|
239
|
+
* a plain record. */
|
|
240
|
+
export type HeaderSource =
|
|
241
|
+
| HeadersLike
|
|
242
|
+
| Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
243
|
+
|
|
244
|
+
/** An outbound request's headers: a fetch `Headers`, or a plain record. */
|
|
245
|
+
export type HeaderSink = HeadersLike | Record<string, string | string[]>;
|
|
246
|
+
|
|
247
|
+
function isHeadersLike(headers: object): headers is HeadersLike {
|
|
248
|
+
return (
|
|
249
|
+
typeof (headers as HeadersLike).forEach === 'function' &&
|
|
250
|
+
typeof (headers as HeadersLike).get === 'function'
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The fields a request's headers carry: the first value of each, under a
|
|
255
|
+
* name in any case. */
|
|
256
|
+
export function fromHeaders(headers: HeaderSource): Record<string, string> {
|
|
257
|
+
const fields: Record<string, string> = {};
|
|
258
|
+
const take = (
|
|
259
|
+
name: string,
|
|
260
|
+
value: string | readonly string[] | undefined,
|
|
261
|
+
) => {
|
|
262
|
+
const field = headerField(name);
|
|
263
|
+
if (field === undefined || Object.hasOwn(fields, field)) return;
|
|
264
|
+
// Fetch joins a repeated header's values with ", ".
|
|
265
|
+
const first = typeof value === 'string' ? value.split(',')[0] : value?.[0];
|
|
266
|
+
if (first !== undefined) fields[field] = first.trim();
|
|
267
|
+
};
|
|
268
|
+
if (isHeadersLike(headers)) {
|
|
269
|
+
headers.forEach((value, name) => take(name, value));
|
|
270
|
+
} else {
|
|
271
|
+
for (const [name, value] of Object.entries(headers)) take(name, value);
|
|
272
|
+
}
|
|
273
|
+
return fields;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Sets the fields of `ctx` on a request's headers, in place of any it
|
|
277
|
+
* carried. */
|
|
278
|
+
export function toHeaders(headers: HeaderSink, ctx: Context): void {
|
|
279
|
+
const fields = current(ctx);
|
|
280
|
+
if (isHeadersLike(headers)) {
|
|
281
|
+
const stale: string[] = [];
|
|
282
|
+
headers.forEach((_, name) => {
|
|
283
|
+
if (name.toLowerCase().startsWith(HEADER_PREFIX)) stale.push(name);
|
|
284
|
+
});
|
|
285
|
+
for (const name of stale) headers.delete(name);
|
|
286
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
287
|
+
headers.set(HEADER_PREFIX + name, value);
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
for (const name of Object.keys(headers)) {
|
|
292
|
+
if (name.toLowerCase().startsWith(HEADER_PREFIX)) delete headers[name];
|
|
293
|
+
}
|
|
294
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
295
|
+
headers[HEADER_PREFIX + name] = value;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Whether the message attribute `key` carries a field. */
|
|
300
|
+
export function isAttribute(key: string): boolean {
|
|
301
|
+
return key.startsWith(ATTRIBUTE_PREFIX);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* `attributes`, with the fields of `ctx` in place of any field attributes
|
|
306
|
+
* they had: every field `ctx` holds. The runtime publishes the message with
|
|
307
|
+
* those the app declares with `pubsub`, and leaves the rest off it.
|
|
308
|
+
*/
|
|
309
|
+
export function messageAttributes(
|
|
310
|
+
attributes: Record<string, string> | undefined,
|
|
311
|
+
ctx: Context = activeContext(),
|
|
312
|
+
): Record<string, string> | undefined {
|
|
313
|
+
const fields = current(ctx);
|
|
314
|
+
const names = Object.keys(fields);
|
|
315
|
+
if (names.length === 0 && attributes === undefined) return undefined;
|
|
316
|
+
const out: Record<string, string> = {};
|
|
317
|
+
for (const [key, value] of Object.entries(attributes ?? {})) {
|
|
318
|
+
if (!isAttribute(key)) out[key] = value;
|
|
319
|
+
}
|
|
320
|
+
for (const name of names) out[ATTRIBUTE_PREFIX + name] = fields[name]!;
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The fields a delivered message carries, and its other attributes.
|
|
326
|
+
*
|
|
327
|
+
* A message's attributes are its publisher's to write, and nothing signs
|
|
328
|
+
* them: the runtime hands a handler only those of fields the app declares
|
|
329
|
+
* with `pubsub`, and of those only ones under a valid name and within their
|
|
330
|
+
* limit are taken, so a forged attribute can at most claim a field the app
|
|
331
|
+
* chose to carry on messages.
|
|
332
|
+
*/
|
|
333
|
+
export function fromMessageAttributes(attributes: Record<string, string>): {
|
|
334
|
+
fields: Record<string, string>;
|
|
335
|
+
rest: Record<string, string>;
|
|
336
|
+
} {
|
|
337
|
+
const fields: Record<string, string> = {};
|
|
338
|
+
const rest: Record<string, string> = {};
|
|
339
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
340
|
+
if (!isAttribute(key)) {
|
|
341
|
+
rest[key] = value;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const name = key.slice(ATTRIBUTE_PREFIX.length);
|
|
345
|
+
if (validName(name) && value.length <= MAX_PUBSUB_VALUE_SIZE) {
|
|
346
|
+
fields[name] = value;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return {fields, rest};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The span attributes of the fields of `ctx` declared with `trace`: each
|
|
354
|
+
* `encore.ctx.<name>`, the value's JSON, as a string. Encore's own field
|
|
355
|
+
* under test is `encore.test.id`, the test's id as it is: one name and one
|
|
356
|
+
* form, whichever SDK's process records the span, is what a test's spans are
|
|
357
|
+
* found by.
|
|
358
|
+
*/
|
|
359
|
+
export function spanAttributes(ctx: Context): Record<string, string> {
|
|
360
|
+
const out: Record<string, string> = {};
|
|
361
|
+
for (const [name, value] of Object.entries(current(ctx))) {
|
|
362
|
+
if (!configOf(name).trace || !BASE64URL.test(value)) continue;
|
|
363
|
+
const json = Buffer.from(value, 'base64url').toString('utf8');
|
|
364
|
+
if (name === TEST_FIELD) {
|
|
365
|
+
const id = testId(json);
|
|
366
|
+
if (id !== undefined) out[TEST_ID_ATTRIBUTE] = id;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
out[SPAN_ATTRIBUTE_PREFIX + name] = json;
|
|
370
|
+
}
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** The test's id the field under test holds: its JSON is a string's. */
|
|
375
|
+
function testId(json: string): string | undefined {
|
|
376
|
+
try {
|
|
377
|
+
const id: unknown = JSON.parse(json);
|
|
378
|
+
return typeof id === 'string' ? id : undefined;
|
|
379
|
+
} catch {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* An OpenTelemetry propagator that extracts the fields a request carries into
|
|
386
|
+
* its context, and injects none. Compose it into the app's global propagator,
|
|
387
|
+
* so a server instrumented for tracing has them:
|
|
388
|
+
*
|
|
389
|
+
* ```ts
|
|
390
|
+
* propagation.setGlobalPropagator(
|
|
391
|
+
* new CompositePropagator({
|
|
392
|
+
* propagators: [new W3CTraceContextPropagator(), new reqctx.Propagator()],
|
|
393
|
+
* }),
|
|
394
|
+
* );
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* It never injects: an instrumented client sends whatever the global
|
|
398
|
+
* propagator injects to whatever it calls, the app's own services or not, so
|
|
399
|
+
* fields are sent only where the app asks. Send them to the app's services
|
|
400
|
+
* with `reqctx.inject`.
|
|
401
|
+
*/
|
|
402
|
+
export class Propagator implements TextMapPropagator {
|
|
403
|
+
/** `ctx` with the fields `carrier` carries, in place of its own. */
|
|
404
|
+
extract(ctx: Context, carrier: unknown, getter: TextMapGetter): Context {
|
|
405
|
+
const fields: Record<string, string> = {};
|
|
406
|
+
for (const key of getter.keys(carrier)) {
|
|
407
|
+
const name = headerField(key);
|
|
408
|
+
if (name === undefined || Object.hasOwn(fields, name)) continue;
|
|
409
|
+
const value = getter.get(carrier, key);
|
|
410
|
+
const first = Array.isArray(value) ? value[0] : value;
|
|
411
|
+
if (typeof first === 'string') fields[name] = first;
|
|
412
|
+
}
|
|
413
|
+
return Object.keys(fields).length === 0 ? ctx : withFields(fields, ctx);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Injects nothing: see the class's documentation. */
|
|
417
|
+
inject(): void {}
|
|
418
|
+
|
|
419
|
+
/** None: {@link inject} sets nothing. */
|
|
420
|
+
fields(): string[] {
|
|
421
|
+
return [];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {Meter} from '@opentelemetry/api';
|
|
2
|
+
import {MeterProvider} from '../otel/meter';
|
|
3
|
+
import {RT, Runtime, runtimeConfig} from './mod';
|
|
4
|
+
|
|
5
|
+
let provider: MeterProvider | undefined;
|
|
6
|
+
let cached: Meter | undefined;
|
|
7
|
+
|
|
8
|
+
/** Encore's meter provider, over the runtime. Encore metrics record
|
|
9
|
+
* through it; pass it to an instrumentation, or register it with
|
|
10
|
+
* `metrics.setGlobalMeterProvider`. */
|
|
11
|
+
export function meterProvider(): MeterProvider {
|
|
12
|
+
provider ??= new MeterProvider(RT.meters());
|
|
13
|
+
return provider;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The meter Encore metrics are instruments of: `encore`, of the runtime's
|
|
17
|
+
* version, from Encore's meter provider. */
|
|
18
|
+
export function meter(): Meter {
|
|
19
|
+
cached ??= meterProvider().getMeter('encore', Runtime.version());
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The service this process hosts; undefined for none. */
|
|
24
|
+
export function hostedService(): string | undefined {
|
|
25
|
+
return runtimeConfig().currentService;
|
|
26
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {Decimal} from '../../types/mod';
|
|
2
|
+
import {printRuntimeLine} from '../../log/runtime';
|
|
3
|
+
import {setShutdownRuntime, watchShutdownSignals} from './shutdown';
|
|
4
|
+
import {Runtime, setRuntimeLogHandler} from './napi/napi.cjs';
|
|
5
|
+
import {setDeclaredLookup} from '../reqfields';
|
|
6
|
+
|
|
7
|
+
export * from './napi/napi.cjs';
|
|
8
|
+
|
|
9
|
+
/** `ENCORE_TEST=0` (or `false`, `off`): the process is not run as a test. */
|
|
10
|
+
const optedOut = ['0', 'false', 'off'].includes(
|
|
11
|
+
process.env.ENCORE_TEST?.trim() ?? '',
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const testMode = process.env.NODE_ENV === 'test' && !optedOut;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a test runner runs the process: vitest, jest and bun set
|
|
18
|
+
* `NODE_ENV=test`, vitest `VITEST` too, and `node --test` starts each file's
|
|
19
|
+
* process with `NODE_TEST_CONTEXT`. A runner adapter of
|
|
20
|
+
* `@encore.dev/sdk/testing` says so for a runner that sets none of them. The
|
|
21
|
+
* core then runs the process as a test, unless its environment says
|
|
22
|
+
* otherwise (`ENCORE_TEST=0`, a runtime config).
|
|
23
|
+
*/
|
|
24
|
+
const testRunner =
|
|
25
|
+
testMode ||
|
|
26
|
+
!!process.env.VITEST ||
|
|
27
|
+
!!process.env.NODE_TEST_CONTEXT ||
|
|
28
|
+
(globalThis as Record<symbol, unknown>)[Symbol.for('encore.testRunner')] ===
|
|
29
|
+
true;
|
|
30
|
+
|
|
31
|
+
setRuntimeLogHandler(printRuntimeLine);
|
|
32
|
+
|
|
33
|
+
export const RT = new Runtime({
|
|
34
|
+
testMode,
|
|
35
|
+
testRunner,
|
|
36
|
+
typeConstructors: {
|
|
37
|
+
decimal: (val: string | number | bigint) => new Decimal(val),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** Each test's infrastructure: null outside test mode. */
|
|
42
|
+
export const TEST_SCOPES = RT.testScopes();
|
|
43
|
+
|
|
44
|
+
if (TEST_SCOPES !== null) {
|
|
45
|
+
// What the app's .env files set, which `encore test` would have started
|
|
46
|
+
// the process with: the variables it lacks.
|
|
47
|
+
for (const [name, value] of Object.entries(RT.testDotenv())) {
|
|
48
|
+
if (process.env[name] === undefined) process.env[name] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setShutdownRuntime(RT);
|
|
53
|
+
// How each Request Context field travels, as the app declares it.
|
|
54
|
+
setDeclaredLookup(name => RT.reqctxField(name));
|
|
55
|
+
if (!testMode && TEST_SCOPES === null) watchShutdownSignals();
|
|
56
|
+
|
|
57
|
+
export {runUntilShutdown} from './shutdown';
|
|
58
|
+
|
|
59
|
+
export interface RuntimeConfig {
|
|
60
|
+
/** The service hosted by this process, if any. */
|
|
61
|
+
currentService?: string;
|
|
62
|
+
/** The Worker of that service this process runs, if any: none for the
|
|
63
|
+
* service's main process. */
|
|
64
|
+
currentWorker?: string;
|
|
65
|
+
/** Base URLs of the services this process can reach, keyed by service
|
|
66
|
+
* name. */
|
|
67
|
+
services: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let cached: RuntimeConfig | null = null;
|
|
71
|
+
export function runtimeConfig(): RuntimeConfig {
|
|
72
|
+
if (cached === null) {
|
|
73
|
+
const cfg = RT.runtimeConfig();
|
|
74
|
+
cached = {
|
|
75
|
+
currentService: cfg.currentService,
|
|
76
|
+
currentWorker: cfg.currentWorker ?? undefined,
|
|
77
|
+
services: cfg.services ?? {},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return cached;
|
|
81
|
+
}
|