@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +51 -12
- package/config/config.test.ts +18 -15
- package/config/config.ts +89 -31
- package/config/mod.ts +4 -3
- package/config/secrets.ts +79 -53
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +41 -2
- package/dist/app_meta.d.ts +44 -12
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +2 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -28
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +46 -18
- package/dist/config/config.js.map +1 -1
- package/dist/config/mod.d.ts +5 -4
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +2 -2
- package/dist/config/mod.js.map +1 -1
- package/dist/config/secrets.d.ts +71 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +31 -38
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +8 -5
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +36 -1
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +31 -1
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +147 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +274 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +90 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +355 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +58 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +251 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +2 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/context.d.ts +1 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +1 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/encode.d.ts +2 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +2 -2
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +1 -2
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/meter.d.ts +1 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/propagator.d.ts +1 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/provider.d.ts +4 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +15 -1
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +30 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/otel/tracer.d.ts +1 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +11 -5
- package/dist/internal/otel/tracer.js.map +1 -1
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +1 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/mod.d.ts +6 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +32 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +192 -16
- package/dist/internal/runtime/napi/napi.d.cts +573 -33
- package/dist/internal/runtime/shutdown.d.ts +5 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +9 -1
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +109 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +335 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +1 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/logger.d.ts +2 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/runtime.d.ts +2 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/stderr.d.ts +1 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/metrics/mod.d.ts +45 -118
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +44 -179
- package/dist/metrics/mod.js.map +1 -1
- package/dist/mod.d.ts +2 -3
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/dist/otel.d.ts +1 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/pubsub/encoding.d.ts +5 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +10 -2
- package/dist/pubsub/encoding.js.map +1 -1
- package/dist/pubsub/mod.d.ts +5 -4
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +2 -2
- package/dist/pubsub/mod.js.map +1 -1
- package/dist/pubsub/refs.d.ts +8 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +110 -15
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +98 -16
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +101 -31
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +168 -51
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +147 -5
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +157 -9
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +1 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/storage/objects/bucket.d.ts +313 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +306 -15
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +10 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +25 -1
- package/dist/storage/objects/error.js.map +1 -1
- package/dist/storage/objects/mod.d.ts +4 -3
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +20 -4
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +6 -0
- package/dist/storage/objects/refs.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +85 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +129 -37
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +4 -1
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +223 -139
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +128 -6
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +56 -22
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +62 -0
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +31 -4
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +26 -1
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +10 -0
- package/dist/storage/redis/native.js.map +1 -1
- package/dist/storage/redis/options.d.ts +1 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +2 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/reply.d.ts +34 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +40 -1
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +1 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/script.d.ts +1 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/target.d.ts +5 -3
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +39 -28
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +7 -10
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +8 -32
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +389 -0
- package/internal/clients/grpc.test.ts +368 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +464 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +287 -0
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +31 -2
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +192 -16
- package/internal/runtime/napi/napi.d.cts +573 -33
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +372 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +1 -8
- package/otel.test.ts +13 -6
- package/package.json +92 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +16 -4
- package/pubsub/pubsub.test.ts +233 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +200 -21
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +255 -36
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +185 -9
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +650 -20
- package/storage/objects/error.ts +28 -1
- package/storage/objects/mod.ts +15 -0
- package/storage/objects/refs.ts +51 -3
- package/storage/postgres/database.integration.test.ts +275 -0
- package/storage/postgres/database.test.ts +193 -6
- package/storage/postgres/database.ts +206 -55
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +4 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +271 -21
- package/storage/redis/database.ts +77 -23
- package/storage/redis/mod.ts +38 -2
- package/storage/redis/native.ts +11 -0
- package/storage/redis/redis.test.ts +170 -10
- package/storage/redis/reply.ts +76 -1
- package/storage/redis/runtime.test.ts +15 -0
- package/storage/redis/target.ts +47 -44
- package/storage/redis/wire.ts +8 -32
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +267 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/dist/internal/otel/request_context.d.ts +0 -11
- package/dist/internal/otel/request_context.js +0 -20
- package/dist/internal/otel/request_context.js.map +0 -1
- package/dist/internal/reqtrack/mod.d.ts +0 -6
- package/dist/internal/reqtrack/mod.js +0 -28
- package/dist/internal/reqtrack/mod.js.map +0 -1
- package/dist/req_meta.d.ts +0 -47
- package/dist/req_meta.js +0 -26
- package/dist/req_meta.js.map +0 -1
- package/internal/otel/request_context.ts +0 -32
- package/internal/reqtrack/mod.ts +0 -39
- package/req_meta.ts +0 -75
package/README.md
CHANGED
|
@@ -116,6 +116,115 @@ handlers that parse JSON manually should use the decoded value, or explicitly
|
|
|
116
116
|
select `encoding: "raw"`. Consumer termination no longer starts another consumer
|
|
117
117
|
after a timer: failures are logged, and normal completion leaves it stopped.
|
|
118
118
|
|
|
119
|
+
## Tracing
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import {span} from '@encore.dev/sdk/tracing';
|
|
123
|
+
import log from '@encore.dev/sdk/log';
|
|
124
|
+
|
|
125
|
+
const items = await span(
|
|
126
|
+
'place_order',
|
|
127
|
+
{attributes: {'order.id': orderId}},
|
|
128
|
+
async current => {
|
|
129
|
+
const count = await span('validate_order', () => validate(orderId));
|
|
130
|
+
current.setAttribute('order.items', count);
|
|
131
|
+
log.info('Order placed', {order_id: orderId});
|
|
132
|
+
return count;
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`span(name, callback)` omits attributes. The callback gets
|
|
138
|
+
an OpenTelemetry `Span`; the helper owns completion, so do not call `end()`.
|
|
139
|
+
Synchronous callbacks return or throw synchronously. PromiseLike results become
|
|
140
|
+
Promises, and the span ends after settlement. Throws and rejections record an
|
|
141
|
+
exception and ERROR status, preserving the original value. OTel's OK status is
|
|
142
|
+
final: setting it prevents a later ERROR status. Successful callbacks leave
|
|
143
|
+
status UNSET unless the callback sets it.
|
|
144
|
+
|
|
145
|
+
Use bounded span names; put order IDs and other variable data in attributes.
|
|
146
|
+
Nested spans, logs, metric exemplars, and service calls share the active context
|
|
147
|
+
across awaits and timers. Detached work must manage its own lifetime.
|
|
148
|
+
|
|
149
|
+
Encore always uses its cached, owned provider, independent of OTel globals.
|
|
150
|
+
Importing or using tracing registers no global provider, context manager,
|
|
151
|
+
propagator, meter, or logger. Native `span` works without OTel setup. For OTel
|
|
152
|
+
interop, the app owns its context manager and configures it through normal OTel
|
|
153
|
+
setup before instrumented work. Pass Encore's tracer provider explicitly:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import {span, tracerProvider} from '@encore.dev/sdk/tracing';
|
|
157
|
+
|
|
158
|
+
// Configure the app's OTel context manager before instrumented work.
|
|
159
|
+
const tracer = tracerProvider().getTracer('orders');
|
|
160
|
+
await tracer.startActiveSpan('order_request', async current => {
|
|
161
|
+
try {
|
|
162
|
+
await span('place_order', () => placeOrder());
|
|
163
|
+
} finally {
|
|
164
|
+
current.end(); // OTel callbacks own their span lifetime.
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The app may choose `trace.setGlobalTracerProvider(tracerProvider())` for libraries
|
|
170
|
+
that use the global API; Encore never does this automatically. `tracerProvider`
|
|
171
|
+
remains available from `@encore.dev/sdk`. See the paired
|
|
172
|
+
[tracing fixtures](../../../tests/ts/telemetry) for runnable examples.
|
|
173
|
+
|
|
174
|
+
### HTTP handlers
|
|
175
|
+
|
|
176
|
+
Wrap a Web `Request` → `Response` handler to continue incoming traces:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import {instrumentHTTP} from '@encore.dev/sdk/tracing';
|
|
180
|
+
|
|
181
|
+
Bun.serve({fetch: instrumentHTTP(handleRequest)});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`instrumentHTTP` extracts W3C trace context and Encore Request Context, then
|
|
185
|
+
runs the handler with an Encore-owned SERVER span active. Nested spans, logs,
|
|
186
|
+
metrics and service calls inherit it. Extra handler arguments and `this` are
|
|
187
|
+
preserved; no OTel globals are registered or replaced.
|
|
188
|
+
|
|
189
|
+
Span names use the HTTP method. Raw URL paths and queries are not recorded:
|
|
190
|
+
paths may contain credentials or personal identifiers. Framework adapters can
|
|
191
|
+
add a safe `http.route` template. Response status is recorded;
|
|
192
|
+
5xx responses and thrown errors mark the span ERROR. Exceptions are rethrown.
|
|
193
|
+
The original response and its body are untouched: the span ends when the
|
|
194
|
+
handler returns a response, not when a streaming body finishes. Handlers must
|
|
195
|
+
return a `Response`; WebSocket upgrades need a runtime-specific adapter.
|
|
196
|
+
Only accept Encore Request Context headers from trusted Encore ingress; the
|
|
197
|
+
wrapper decodes them, not authenticates them.
|
|
198
|
+
|
|
199
|
+
### Node HTTP handlers
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import {createServer} from 'node:http';
|
|
203
|
+
import {instrumentHTTP} from '@encore.dev/sdk/tracing/node';
|
|
204
|
+
|
|
205
|
+
createServer(
|
|
206
|
+
instrumentHTTP((request, response) => {
|
|
207
|
+
response.writeHead(200);
|
|
208
|
+
response.end('ok');
|
|
209
|
+
}),
|
|
210
|
+
).listen(3000);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The Node adapter accepts native `IncomingMessage`/`ServerResponse` listeners;
|
|
214
|
+
request and response bodies are not converted or buffered. It shares trace
|
|
215
|
+
and Request Context extraction with the Fetch wrapper and preserves `this`.
|
|
216
|
+
During response processing, request/response event callbacks run in the
|
|
217
|
+
request's context.
|
|
218
|
+
|
|
219
|
+
Its span lasts until response `finish`, premature `close`, response error,
|
|
220
|
+
or a thrown/rejected handler failure. A handler returning before a streamed
|
|
221
|
+
response finishes does not end the span. Premature closes mark it ERROR.
|
|
222
|
+
The adapter records and rethrows handler failures; the application remains
|
|
223
|
+
responsible for error responses and handling rejected async listeners.
|
|
224
|
+
Failures before headers are sent have no recorded HTTP response status.
|
|
225
|
+
Synchronous return values are preserved; PromiseLike results become Promises.
|
|
226
|
+
HTTP upgrade and CONNECT events require separate instrumentation.
|
|
227
|
+
|
|
119
228
|
## Formatting and linting
|
|
120
229
|
|
|
121
230
|
Use Node.js 24 LTS for SDK development and install dependencies with `npm ci`.
|
package/app_meta.test.ts
CHANGED
|
@@ -53,11 +53,23 @@ describe('appMeta', () => {
|
|
|
53
53
|
expect(Object.keys(md.gateways).sort()).toEqual(['admin', 'api']);
|
|
54
54
|
expect(md.gateways.api).toEqual({
|
|
55
55
|
name: 'api',
|
|
56
|
-
|
|
56
|
+
url: 'https://api.example.com',
|
|
57
|
+
origins: ['https://api.example.com', '*'],
|
|
57
58
|
});
|
|
58
59
|
expect(md.gateways.admin).toEqual({
|
|
59
60
|
name: 'admin',
|
|
60
|
-
|
|
61
|
+
url: 'https://admin.example.com',
|
|
62
|
+
origins: ['https://admin.example.com'],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('reports every frontend, keyed by name', () => {
|
|
67
|
+
expect(md.frontends).toEqual({
|
|
68
|
+
web: {
|
|
69
|
+
name: 'web',
|
|
70
|
+
url: 'https://example.com',
|
|
71
|
+
origins: ['https://example.com', 'https://*.example.com'],
|
|
72
|
+
},
|
|
61
73
|
});
|
|
62
74
|
});
|
|
63
75
|
|
|
@@ -108,19 +120,27 @@ function runtimeConfig(): string {
|
|
|
108
120
|
...enumField(5, 1), // TYPE_DEVELOPMENT
|
|
109
121
|
...enumField(6, 4), // CLOUD_GCP
|
|
110
122
|
];
|
|
111
|
-
// Gateway{rid=1, encore_name=2,
|
|
123
|
+
// Gateway{rid=1, encore_name=2, origins=3}
|
|
112
124
|
const api = [
|
|
113
125
|
...str(1, 'gw:api'),
|
|
114
126
|
...str(2, 'api'),
|
|
115
127
|
...str(3, 'https://api.example.com'),
|
|
128
|
+
...str(3, '*'),
|
|
116
129
|
];
|
|
117
130
|
const admin = [
|
|
118
131
|
...str(1, 'gw:admin'),
|
|
119
132
|
...str(2, 'admin'),
|
|
120
133
|
...str(3, 'https://admin.example.com'),
|
|
121
134
|
];
|
|
122
|
-
//
|
|
123
|
-
const
|
|
135
|
+
// Frontend{rid=1, encore_name=2, origins=3}
|
|
136
|
+
const web = [
|
|
137
|
+
...str(1, 'fe:web'),
|
|
138
|
+
...str(2, 'web'),
|
|
139
|
+
...str(3, 'https://example.com'),
|
|
140
|
+
...str(3, 'https://*.example.com'),
|
|
141
|
+
];
|
|
142
|
+
// Infrastructure.Resources{gateways=1, frontends=11}; Infrastructure{resources=1}
|
|
143
|
+
const infra = msg(1, [...msg(1, api), ...msg(1, admin), ...msg(11, web)]);
|
|
124
144
|
// Deployment{deploy_id=1, hosted_services=5, revision=11}
|
|
125
145
|
const deployment = [
|
|
126
146
|
...str(1, 'deploy-1'),
|
package/app_meta.ts
CHANGED
|
@@ -19,15 +19,25 @@ export interface AppMeta {
|
|
|
19
19
|
appSlug: string;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* The API gateways
|
|
22
|
+
* The API gateways of this application this service is given, keyed by
|
|
23
|
+
* gateway name: those its code looks up the URL of, and the one it hosts.
|
|
23
24
|
*
|
|
24
25
|
* An application can declare several gateways, so there is no single base URL for
|
|
25
|
-
* the API — look up the gateway you mean by name.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* the API — look up the gateway you mean by name. A service's processes, its
|
|
27
|
+
* Workers' included, list the gateways its code names (`url("api")` from
|
|
28
|
+
* `@encore.dev/sdk/gateways`) and the one it hosts, and no other, the default
|
|
29
|
+
* included; one told of none, as under `encore test`, reports an empty object.
|
|
28
30
|
*/
|
|
29
31
|
gateways: Record<string, GatewayMeta>;
|
|
30
32
|
|
|
33
|
+
/**
|
|
34
|
+
* The frontends of this application this service is given — those its code
|
|
35
|
+
* looks up the URL of (`url("web")` from `@encore.dev/sdk/frontends`), and
|
|
36
|
+
* the one it hosts — keyed by name, with where each is reached. One the
|
|
37
|
+
* environment gives no origins is left out.
|
|
38
|
+
*/
|
|
39
|
+
frontends: Record<string, FrontendMeta>;
|
|
40
|
+
|
|
31
41
|
/** Information about the environment the app is running in. */
|
|
32
42
|
environment: EnvironmentMeta;
|
|
33
43
|
|
|
@@ -44,15 +54,35 @@ export interface GatewayMeta {
|
|
|
44
54
|
name: string;
|
|
45
55
|
|
|
46
56
|
/**
|
|
47
|
-
* The
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
* The URL the API of this running application is called at through this
|
|
58
|
+
* gateway: the first of its origins. Empty when the environment gives the
|
|
59
|
+
* gateway no origins.
|
|
60
|
+
*/
|
|
61
|
+
url: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Every origin the gateway is reached at in this environment
|
|
65
|
+
* (`scheme://host[:port]`), the first its URL. After the first, an entry may
|
|
66
|
+
* be a pattern of one, `https://*.example.com`, or `*`, which makes the
|
|
67
|
+
* gateway the one serving requests no other origin matches.
|
|
68
|
+
*/
|
|
69
|
+
origins: string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Describes a frontend of the application, and where it is reached. */
|
|
73
|
+
export interface FrontendMeta {
|
|
74
|
+
/** The name of the frontend: for one a service hosts, the service's. */
|
|
75
|
+
name: string;
|
|
76
|
+
|
|
77
|
+
/** The URL the frontend is reached at: the first of its origins. */
|
|
78
|
+
url: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Every origin the frontend is reached at in this environment, the first its
|
|
82
|
+
* URL; after the first, an entry may be a pattern of one,
|
|
83
|
+
* `https://*.example.com`.
|
|
54
84
|
*/
|
|
55
|
-
|
|
85
|
+
origins: string[];
|
|
56
86
|
}
|
|
57
87
|
|
|
58
88
|
/** Describes the environment the Encore application is running in. */
|
|
@@ -111,6 +141,13 @@ export interface DeployMeta {
|
|
|
111
141
|
|
|
112
142
|
/** The services hosted by this deployment, keyed by the service name. */
|
|
113
143
|
hostedServices: Record<string, HostedService>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The Worker of its service this process runs: a long-running process of
|
|
147
|
+
* the service that serves no requests, declared in the `workers` section of
|
|
148
|
+
* its `encore.service.json`. Undefined for the service's main process.
|
|
149
|
+
*/
|
|
150
|
+
worker?: string;
|
|
114
151
|
}
|
|
115
152
|
|
|
116
153
|
export interface HostedService {
|
|
@@ -132,6 +169,7 @@ export function appMeta(): AppMeta {
|
|
|
132
169
|
appId: rt.appId,
|
|
133
170
|
appSlug: rt.appSlug,
|
|
134
171
|
gateways: rt.gateways,
|
|
172
|
+
frontends: rt.frontends,
|
|
135
173
|
environment: {
|
|
136
174
|
name: rt.environment.name,
|
|
137
175
|
type: envType(rt.environment.type),
|
|
@@ -144,6 +182,7 @@ export function appMeta(): AppMeta {
|
|
|
144
182
|
id: rt.deploy.id,
|
|
145
183
|
time: new Date(rt.deploy.deployTime),
|
|
146
184
|
hostedServices: rt.deploy.hostedServices,
|
|
185
|
+
worker: rt.deploy.worker ?? undefined,
|
|
147
186
|
},
|
|
148
187
|
};
|
|
149
188
|
}
|
package/config/config.test.ts
CHANGED
|
@@ -86,7 +86,7 @@ describe('build', () => {
|
|
|
86
86
|
},
|
|
87
87
|
],
|
|
88
88
|
},
|
|
89
|
-
apiKey: {'x-encore-secret':
|
|
89
|
+
apiKey: {'x-encore-secret': 'StripeKey'},
|
|
90
90
|
name: {type: 'string'},
|
|
91
91
|
},
|
|
92
92
|
};
|
|
@@ -100,10 +100,10 @@ describe('build', () => {
|
|
|
100
100
|
retries: ['1s', '5s'],
|
|
101
101
|
windows: {eu: '2m'},
|
|
102
102
|
payment: {kind: 'card', hold: '10m'},
|
|
103
|
-
apiKey: {$encore_secret:
|
|
103
|
+
apiKey: {$encore_secret: 'StripeKey'},
|
|
104
104
|
name: '30s',
|
|
105
105
|
},
|
|
106
|
-
|
|
106
|
+
name => `secret ${name}`,
|
|
107
107
|
) as any;
|
|
108
108
|
expect(value.timeout).toBeInstanceOf(Duration);
|
|
109
109
|
expect(value.timeout.seconds).toBe(30);
|
|
@@ -111,13 +111,13 @@ describe('build', () => {
|
|
|
111
111
|
expect(value.retries.map((d: Duration) => d.seconds)).toEqual([1, 5]);
|
|
112
112
|
expect(value.windows.eu.seconds).toBe(120);
|
|
113
113
|
expect(value.payment.hold.seconds).toBe(600);
|
|
114
|
-
expect(value.apiKey).toBe('secret StripeKey
|
|
114
|
+
expect(value.apiKey).toBe('secret StripeKey');
|
|
115
115
|
// A string the schema doesn't mark stays a string.
|
|
116
116
|
expect(value.name).toBe('30s');
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
test('makes a secret only of a field the schema says reads one', () => {
|
|
120
|
-
const forged = {$encore_secret:
|
|
120
|
+
const forged = {$encore_secret: 'StripeKey'};
|
|
121
121
|
const value = build(
|
|
122
122
|
{type: 'object', properties: {extra: {}, name: {type: 'string'}}},
|
|
123
123
|
{extra: forged},
|
|
@@ -129,11 +129,7 @@ describe('build', () => {
|
|
|
129
129
|
|
|
130
130
|
const secretOf = (name: string) => `secret ${name}`;
|
|
131
131
|
expect(() =>
|
|
132
|
-
build(
|
|
133
|
-
schema,
|
|
134
|
-
{apiKey: {$encore_secret: {name: 'Other', scope: 'shared'}}},
|
|
135
|
-
secretOf,
|
|
136
|
-
),
|
|
132
|
+
build(schema, {apiKey: {$encore_secret: 'Other'}}, secretOf),
|
|
137
133
|
).toThrow('a secret field reads the secret StripeKey');
|
|
138
134
|
expect(() => build(schema, {apiKey: 'sk_live_123'}, secretOf)).not.toThrow(
|
|
139
135
|
/sk_live/,
|
|
@@ -186,11 +182,13 @@ describe('config', () => {
|
|
|
186
182
|
const mod = JSON.stringify(`${import.meta.dir}/mod`);
|
|
187
183
|
const out = run(`
|
|
188
184
|
import { writeFileSync } from "node:fs";
|
|
189
|
-
import { config,
|
|
185
|
+
import { config, secret, Duration } from ${mod};
|
|
190
186
|
const checkout = config("checkout");
|
|
191
|
-
const flags =
|
|
187
|
+
const flags = config("flags", { scope: "shared" });
|
|
192
188
|
const missing = config("nothing");
|
|
193
189
|
const a = checkout(), b = checkout();
|
|
190
|
+
let unset;
|
|
191
|
+
try { secret("Unset")(); } catch (e) { unset = e.message; }
|
|
194
192
|
console.log(JSON.stringify({
|
|
195
193
|
maxItems: a.max_items,
|
|
196
194
|
timeout: a.timeout instanceof Duration ? a.timeout.seconds : null,
|
|
@@ -201,6 +199,7 @@ describe('config', () => {
|
|
|
201
199
|
flagKey: flags().key(),
|
|
202
200
|
missing: missing(),
|
|
203
201
|
name: checkout.name,
|
|
202
|
+
unset,
|
|
204
203
|
}));
|
|
205
204
|
const stop = checkout.onChange((v) => {
|
|
206
205
|
console.log(JSON.stringify({ changed: v.max_items, timeout: v.timeout.seconds, now: checkout().max_items }));
|
|
@@ -223,6 +222,8 @@ describe('config', () => {
|
|
|
223
222
|
flagKey: 'shared-flag-key',
|
|
224
223
|
missing: {},
|
|
225
224
|
name: 'checkout',
|
|
225
|
+
// Not set is an error wherever the app runs, locally too.
|
|
226
|
+
unset: 'secret Unset is not set',
|
|
226
227
|
});
|
|
227
228
|
expect(out[1]).toEqual({changed: 7, timeout: 60, now: 7});
|
|
228
229
|
});
|
|
@@ -321,7 +322,7 @@ function runtimeConfig(live: string): string {
|
|
|
321
322
|
properties: {
|
|
322
323
|
max_items: {type: 'integer', minimum: 1},
|
|
323
324
|
timeout: {type: 'string', 'x-encore-format': 'duration'},
|
|
324
|
-
stripe_key: {'x-encore-secret':
|
|
325
|
+
stripe_key: {'x-encore-secret': 'StripeKey'},
|
|
325
326
|
},
|
|
326
327
|
required: ['max_items'],
|
|
327
328
|
additionalProperties: false,
|
|
@@ -330,11 +331,12 @@ function runtimeConfig(live: string): string {
|
|
|
330
331
|
type: 'object',
|
|
331
332
|
properties: {
|
|
332
333
|
new_checkout: {type: 'boolean'},
|
|
333
|
-
key: {'x-encore-secret':
|
|
334
|
+
key: {'x-encore-secret': 'FlagKey'},
|
|
334
335
|
},
|
|
335
336
|
additionalProperties: false,
|
|
336
337
|
};
|
|
337
|
-
// AppConfig{rid=1, encore_name=2,
|
|
338
|
+
// AppConfig{rid=1, encore_name=2, services=3, json_schema=4, value=5}: the
|
|
339
|
+
// service's own config given to orders, the shared one to every service.
|
|
338
340
|
const checkout = [
|
|
339
341
|
...str(1, 'config:orders.checkout'),
|
|
340
342
|
...str(2, 'checkout'),
|
|
@@ -345,6 +347,7 @@ function runtimeConfig(live: string): string {
|
|
|
345
347
|
const flags = [
|
|
346
348
|
...str(1, 'config:flags'),
|
|
347
349
|
...str(2, 'flags'),
|
|
350
|
+
...str(3, '*'),
|
|
348
351
|
...str(4, JSON.stringify(flagsSchema)),
|
|
349
352
|
...str(5, JSON.stringify({new_checkout: true})),
|
|
350
353
|
];
|
package/config/config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as runtime from '../internal/runtime/mod';
|
|
2
|
+
import {lookupScope, testMode, type Scope} from '../internal/testing/scope';
|
|
2
3
|
import {secretOfField} from './secrets';
|
|
3
4
|
import {build} from './value';
|
|
4
5
|
|
|
@@ -8,24 +9,24 @@ export {Duration} from './value';
|
|
|
8
9
|
* A config: a typed value a service reads, written in files beside the code
|
|
9
10
|
* and changed while the app runs. Calling it reads the value now.
|
|
10
11
|
*
|
|
11
|
-
* Declare one with {@link config},
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* against it before the value reaches the code.
|
|
12
|
+
* Declare one with {@link config}, giving the value's type as the type
|
|
13
|
+
* argument. Encore reads that type to know what the config's files may hold,
|
|
14
|
+
* and checks them against it before the value reaches the code.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* interface Checkout {
|
|
20
|
+
* // Most items one order may hold.
|
|
21
|
+
* maxItems: number & Int & Min<1> & Max<500>;
|
|
22
|
+
* currencies?: string[];
|
|
23
|
+
* paymentTimeout: Duration;
|
|
24
|
+
* }
|
|
25
25
|
*
|
|
26
|
-
*
|
|
26
|
+
* export const checkout = config<Checkout>("checkout");
|
|
27
27
|
*
|
|
28
|
-
*
|
|
28
|
+
* if (items.length > checkout().maxItems) { ... }
|
|
29
|
+
* ```
|
|
29
30
|
*
|
|
30
31
|
* # Values
|
|
31
32
|
*
|
|
@@ -57,31 +58,83 @@ export interface Config<T> {
|
|
|
57
58
|
onChange(listener: (value: T) => void): () => void;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
/** The options a config is declared with. */
|
|
62
|
+
export interface ConfigOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Who the config belongs to, written as a string literal for Encore to
|
|
65
|
+
* read:
|
|
66
|
+
*
|
|
67
|
+
* - `"service"`, the default: the service that declares it, which holds
|
|
68
|
+
* its own value for it. Two services may each declare a config of the
|
|
69
|
+
* same name. The declaration must live inside a service.
|
|
70
|
+
* - `"shared"`: the whole app, with one value. A service that reads it is
|
|
71
|
+
* recorded as using it. It may be declared outside a service.
|
|
72
|
+
* - `"global"`: the whole app, with one value available to every service
|
|
73
|
+
* without being recorded as used. It may be declared outside a service.
|
|
74
|
+
*
|
|
75
|
+
* A config name has one scope across the app, as a secret's has: a name
|
|
76
|
+
* declared shared or global can't also be a service's own.
|
|
77
|
+
*/
|
|
78
|
+
scope?: 'service' | 'shared' | 'global';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Tags that classify the config, for policies to read: written out as
|
|
82
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
83
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
84
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
85
|
+
*/
|
|
86
|
+
tags?: Record<string, string>;
|
|
68
87
|
}
|
|
69
88
|
|
|
70
89
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
90
|
+
* config declares a {@link Config}, by default belonging to the service that
|
|
91
|
+
* declares it (see {@link ConfigOptions.scope}). The declaration is a
|
|
92
|
+
* module-level `export const`, with the name a string literal.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* // A config several services read.
|
|
97
|
+
* export const flags = config<Flags>("flags", {scope: "shared"});
|
|
98
|
+
* ```
|
|
74
99
|
*/
|
|
75
|
-
export function
|
|
76
|
-
|
|
100
|
+
export function config<T>(
|
|
101
|
+
name: string,
|
|
102
|
+
// The options are Encore's parser's to read: a config is read by name
|
|
103
|
+
// whatever its scope, a name having one scope across the app.
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
+
opts?: ConfigOptions,
|
|
106
|
+
): Config<T> {
|
|
107
|
+
const handle = makeConfig<T>(name, runtime.RT.config(name));
|
|
108
|
+
names.set(handle, name);
|
|
109
|
+
return handle;
|
|
77
110
|
}
|
|
78
111
|
|
|
112
|
+
/** The name of the config each handle reads. */
|
|
113
|
+
const names = new WeakMap<Config<any>, string>();
|
|
114
|
+
|
|
79
115
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
116
|
+
* Gives `cfg` the value `value` for the test `scope`, once the core has
|
|
117
|
+
* checked it against the config's schema: reading the config in the test
|
|
118
|
+
* returns it from then on. For `@encore.dev/sdk/testing`.
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
82
121
|
*/
|
|
83
|
-
export function
|
|
84
|
-
|
|
122
|
+
export function setTestValue<T>(scope: Scope, cfg: Config<T>, value: T): void {
|
|
123
|
+
const name = names.get(cfg);
|
|
124
|
+
if (name === undefined) {
|
|
125
|
+
throw new TypeError('setConfig takes a config declared with `config()`');
|
|
126
|
+
}
|
|
127
|
+
const json = JSON.stringify(value);
|
|
128
|
+
if (json === undefined) {
|
|
129
|
+
throw new TypeError(`config ${name}: the value has no JSON form`);
|
|
130
|
+
}
|
|
131
|
+
const prepared = JSON.parse(scope.native.setConfig(name, json));
|
|
132
|
+
const impl = runtime.RT.config(name);
|
|
133
|
+
const built =
|
|
134
|
+
impl === null
|
|
135
|
+
? prepared
|
|
136
|
+
: build(JSON.parse(impl.schema()), prepared, secretOfField);
|
|
137
|
+
scope.configs.set(name, built);
|
|
85
138
|
}
|
|
86
139
|
|
|
87
140
|
/** The native handle to a config, when the runtime config has it. */
|
|
@@ -116,6 +169,11 @@ function makeConfig<T>(name: string, impl: Impl | null): Config<T> {
|
|
|
116
169
|
};
|
|
117
170
|
|
|
118
171
|
const read = (): T => {
|
|
172
|
+
if (testMode) {
|
|
173
|
+
// The value the current test gave it, if it did.
|
|
174
|
+
const configs = lookupScope()?.configs;
|
|
175
|
+
if (configs?.has(name)) return configs.get(name) as T;
|
|
176
|
+
}
|
|
119
177
|
if (impl === null) {
|
|
120
178
|
// No value at all: every field takes its default, which in TypeScript is
|
|
121
179
|
// none. The runtime config has every config the app declares, so this
|
package/config/mod.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type {Secret, AnySecret} from './secrets';
|
|
2
|
-
export {secret
|
|
1
|
+
export type {Secret, AnySecret, SecretOptions} from './secrets';
|
|
2
|
+
export {secret} from './secrets';
|
|
3
3
|
export type {
|
|
4
4
|
Config,
|
|
5
|
+
ConfigOptions,
|
|
5
6
|
Min,
|
|
6
7
|
Max,
|
|
7
8
|
Int,
|
|
@@ -11,4 +12,4 @@ export type {
|
|
|
11
12
|
MinItems,
|
|
12
13
|
MaxItems,
|
|
13
14
|
} from './config';
|
|
14
|
-
export {config,
|
|
15
|
+
export {config, Duration} from './config';
|