@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
|
@@ -69,6 +69,11 @@ let markCleanup!: () => void;
|
|
|
69
69
|
const cleanupAt = new Promise<void>(resolve => (markCleanup = resolve));
|
|
70
70
|
let completion: Promise<ShutdownResult> | undefined;
|
|
71
71
|
|
|
72
|
+
/** The signals that force cleanup when they come again: a second Ctrl-C, and
|
|
73
|
+
* for a gateway program a second SIGTERM, which is how the supervisor stops
|
|
74
|
+
* waiting for its drain. */
|
|
75
|
+
const forcing = new Set<NodeJS.Signals>(['SIGINT']);
|
|
76
|
+
|
|
72
77
|
/** The signal that began the shutdown: Encore then exits once it completes. */
|
|
73
78
|
let signalled: NodeJS.Signals | undefined;
|
|
74
79
|
let signalledAt = 0;
|
|
@@ -219,6 +224,11 @@ export function runUntilShutdown(r: Runtime): Promise<number> {
|
|
|
219
224
|
return r.runForever(true);
|
|
220
225
|
}
|
|
221
226
|
|
|
227
|
+
/** Has `sig` force cleanup when it comes again, as a second SIGINT does. */
|
|
228
|
+
export function forceCleanupOnRepeat(sig: NodeJS.Signals): void {
|
|
229
|
+
forcing.add(sig);
|
|
230
|
+
}
|
|
231
|
+
|
|
222
232
|
function onSignal(sig: NodeJS.Signals): void {
|
|
223
233
|
if (hosted) return begin();
|
|
224
234
|
if (signalled || begun) return repeated(sig);
|
|
@@ -254,7 +264,7 @@ function repeated(sig: NodeJS.Signals): void {
|
|
|
254
264
|
appHold.release();
|
|
255
265
|
return;
|
|
256
266
|
}
|
|
257
|
-
if (sig
|
|
267
|
+
if (forcing.has(sig) && Date.now() - signalledAt > REPEAT_MS) {
|
|
258
268
|
rt().forceShutdownCleanup();
|
|
259
269
|
}
|
|
260
270
|
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import {afterEach, describe, expect, test} from 'bun:test';
|
|
2
|
+
import {
|
|
3
|
+
createTraceState,
|
|
4
|
+
ROOT_CONTEXT,
|
|
5
|
+
trace,
|
|
6
|
+
TraceFlags,
|
|
7
|
+
} from '@opentelemetry/api';
|
|
8
|
+
import {recordOrigin, wrapFetch} from '../fetch';
|
|
9
|
+
import {withContext} from '../otel/context';
|
|
10
|
+
import {contextCtxBytes} from '../otel/span';
|
|
11
|
+
import * as reqfields from '../reqfields';
|
|
12
|
+
import {
|
|
13
|
+
outgoingContext,
|
|
14
|
+
setCarriedLookup,
|
|
15
|
+
withCarried,
|
|
16
|
+
type Carried,
|
|
17
|
+
} from './carry';
|
|
18
|
+
|
|
19
|
+
const wire = (value: unknown) =>
|
|
20
|
+
Buffer.from(JSON.stringify(value)).toString('base64url');
|
|
21
|
+
|
|
22
|
+
const TEST_TRACE = '0af7651916cd43dd8448eb211c80319c';
|
|
23
|
+
const TEST_SPAN = 'b7ad6b7169203331';
|
|
24
|
+
|
|
25
|
+
/** What the test `00f067aa0ba902b7` carries, as the core gives it. */
|
|
26
|
+
const carried: Carried = {
|
|
27
|
+
fieldName: 'encore-test',
|
|
28
|
+
field: wire('00f067aa0ba902b7'),
|
|
29
|
+
traceparent: `00-${TEST_TRACE}-${TEST_SPAN}-01`,
|
|
30
|
+
tracestate: 'encore=rc',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** A request's context: a span of its own, and the test it is made for. */
|
|
34
|
+
const requestContext = trace.setSpanContext(
|
|
35
|
+
reqfields.withFields(
|
|
36
|
+
{'encore-test': wire('another-test'), plan: wire('pro')},
|
|
37
|
+
ROOT_CONTEXT,
|
|
38
|
+
),
|
|
39
|
+
{
|
|
40
|
+
traceId: '1bf7651916cd43dd8448eb211c80319d',
|
|
41
|
+
spanId: 'c8ad6b7169203332',
|
|
42
|
+
traceFlags: TraceFlags.SAMPLED,
|
|
43
|
+
traceState: createTraceState('vendor=1'),
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
afterEach(() => setCarriedLookup(undefined));
|
|
48
|
+
|
|
49
|
+
describe('withCarried', () => {
|
|
50
|
+
test('adds the test to a context that has none', () => {
|
|
51
|
+
const ctx = withCarried(ROOT_CONTEXT, carried);
|
|
52
|
+
expect(reqfields.current(ctx)).toEqual({'encore-test': carried.field});
|
|
53
|
+
const span = trace.getSpanContext(ctx)!;
|
|
54
|
+
expect(span.traceId).toBe(TEST_TRACE);
|
|
55
|
+
expect(span.spanId).toBe(TEST_SPAN);
|
|
56
|
+
expect(span.traceFlags).toBe(TraceFlags.SAMPLED);
|
|
57
|
+
expect(span.traceState?.serialize()).toBe('encore=rc');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('is what the runtime is handed of a publish made for the test', () => {
|
|
61
|
+
// The test's span, for the publish to be under, then the test's field,
|
|
62
|
+
// for the span the runtime records of it.
|
|
63
|
+
const bytes = contextCtxBytes(withCarried(ROOT_CONTEXT, carried))!;
|
|
64
|
+
expect(bytes.subarray(0, 25).toString('hex')).toBe(
|
|
65
|
+
`${TEST_TRACE}${TEST_SPAN}01`,
|
|
66
|
+
);
|
|
67
|
+
expect(bytes.subarray(25).toString('latin1')).toBe(carried.field);
|
|
68
|
+
// Where the process records no spans, the field alone.
|
|
69
|
+
const spanless = contextCtxBytes(
|
|
70
|
+
withCarried(ROOT_CONTEXT, {...carried, traceparent: null}),
|
|
71
|
+
)!;
|
|
72
|
+
expect(spanless.subarray(0, 25)).toEqual(Buffer.alloc(25));
|
|
73
|
+
expect(spanless.subarray(25).toString('latin1')).toBe(carried.field);
|
|
74
|
+
// A context of no test hands over its span, or nothing.
|
|
75
|
+
expect(contextCtxBytes(ROOT_CONTEXT)).toBeUndefined();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('keeps the fields a context has beside it', () => {
|
|
79
|
+
const ctx = withCarried(
|
|
80
|
+
reqfields.withFields({plan: wire('pro')}, ROOT_CONTEXT),
|
|
81
|
+
carried,
|
|
82
|
+
);
|
|
83
|
+
expect(reqfields.current(ctx)).toEqual({
|
|
84
|
+
plan: wire('pro'),
|
|
85
|
+
'encore-test': carried.field,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('keeps the test and the span a context already has', () => {
|
|
90
|
+
const ctx = withCarried(requestContext, carried);
|
|
91
|
+
expect(ctx).toBe(requestContext);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('adds each where only the other is there', () => {
|
|
95
|
+
const spanOnly = trace.setSpanContext(
|
|
96
|
+
ROOT_CONTEXT,
|
|
97
|
+
trace.getSpanContext(requestContext)!,
|
|
98
|
+
);
|
|
99
|
+
const withField = withCarried(spanOnly, carried);
|
|
100
|
+
expect(reqfields.current(withField)['encore-test']).toBe(carried.field);
|
|
101
|
+
expect(trace.getSpanContext(withField)!.spanId).toBe('c8ad6b7169203332');
|
|
102
|
+
|
|
103
|
+
const fieldOnly = reqfields.withFields(
|
|
104
|
+
{'encore-test': wire('another-test')},
|
|
105
|
+
ROOT_CONTEXT,
|
|
106
|
+
);
|
|
107
|
+
const withSpan = withCarried(fieldOnly, carried);
|
|
108
|
+
expect(reqfields.current(withSpan)['encore-test']).toBe(
|
|
109
|
+
wire('another-test'),
|
|
110
|
+
);
|
|
111
|
+
expect(trace.getSpanContext(withSpan)!.spanId).toBe(TEST_SPAN);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('adds no span where the process records none', () => {
|
|
115
|
+
const ctx = withCarried(ROOT_CONTEXT, {
|
|
116
|
+
fieldName: 'encore-test',
|
|
117
|
+
field: carried.field,
|
|
118
|
+
traceparent: null,
|
|
119
|
+
tracestate: null,
|
|
120
|
+
});
|
|
121
|
+
expect(reqfields.current(ctx)).toEqual({'encore-test': carried.field});
|
|
122
|
+
expect(trace.getSpanContext(ctx)).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('outgoingContext', () => {
|
|
127
|
+
test('is the context itself outside a system test', () => {
|
|
128
|
+
expect(outgoingContext(ROOT_CONTEXT)).toBe(ROOT_CONTEXT);
|
|
129
|
+
expect(outgoingContext(requestContext)).toBe(requestContext);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('is the context itself where there is no current test', () => {
|
|
133
|
+
setCarriedLookup(() => null);
|
|
134
|
+
expect(outgoingContext(ROOT_CONTEXT)).toBe(ROOT_CONTEXT);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('adds the current test', () => {
|
|
138
|
+
setCarriedLookup(() => carried);
|
|
139
|
+
const ctx = outgoingContext(ROOT_CONTEXT);
|
|
140
|
+
expect(reqfields.current(ctx)).toEqual({'encore-test': carried.field});
|
|
141
|
+
expect(
|
|
142
|
+
reqfields.messageAttributes({source: 'web'}, outgoingContext()),
|
|
143
|
+
).toEqual({source: 'web', 'encore-ctx-encore-test': carried.field});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("makes what the test's own code does the test's", () => {
|
|
147
|
+
// A query, an object read: the runtime's spans of it are under the
|
|
148
|
+
// test's span, and carry its id.
|
|
149
|
+
setCarriedLookup(() => carried);
|
|
150
|
+
const bytes = contextCtxBytes(ROOT_CONTEXT)!;
|
|
151
|
+
expect(bytes.subarray(0, 25).toString('hex')).toBe(
|
|
152
|
+
`${TEST_TRACE}${TEST_SPAN}01`,
|
|
153
|
+
);
|
|
154
|
+
expect(bytes.subarray(25).toString('latin1')).toBe(carried.field);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('a call made in a system test', () => {
|
|
159
|
+
/** A `fetch` that records the headers of what it is asked to send. */
|
|
160
|
+
function recording() {
|
|
161
|
+
const sent: {url: string; headers: Record<string, string>}[] = [];
|
|
162
|
+
const base = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
163
|
+
sent.push({
|
|
164
|
+
url: String(input instanceof Request ? input.url : input),
|
|
165
|
+
headers: Object.fromEntries(new Headers(init?.headers)),
|
|
166
|
+
});
|
|
167
|
+
return new Response('ok');
|
|
168
|
+
}) as typeof globalThis.fetch;
|
|
169
|
+
return {sent, fetch: wrapFetch(base)};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const SERVICE = 'http://127.0.0.1:4000/orders';
|
|
173
|
+
recordOrigin(SERVICE);
|
|
174
|
+
|
|
175
|
+
test('carries the test, and continues its span', async () => {
|
|
176
|
+
setCarriedLookup(() => carried);
|
|
177
|
+
const {sent, fetch} = recording();
|
|
178
|
+
await fetch(`${SERVICE}/1`, {headers: {accept: 'application/json'}});
|
|
179
|
+
expect(sent[0]!.headers).toEqual({
|
|
180
|
+
accept: 'application/json',
|
|
181
|
+
'x-encore-meta-ctx-encore-test': carried.field,
|
|
182
|
+
traceparent: `00-${TEST_TRACE}-${TEST_SPAN}-01`,
|
|
183
|
+
tracestate: 'encore=rc',
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('keeps the test and the span of the context it is made in', async () => {
|
|
188
|
+
setCarriedLookup(() => carried);
|
|
189
|
+
const {sent, fetch} = recording();
|
|
190
|
+
await withContext(requestContext, () => fetch(`${SERVICE}/1`));
|
|
191
|
+
expect(sent[0]!.headers).toEqual({
|
|
192
|
+
'x-encore-meta-ctx-encore-test': wire('another-test'),
|
|
193
|
+
'x-encore-meta-ctx-plan': wire('pro'),
|
|
194
|
+
traceparent: '00-1bf7651916cd43dd8448eb211c80319d-c8ad6b7169203332-01',
|
|
195
|
+
tracestate: 'vendor=1',
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('keeps a traceparent the request carries', async () => {
|
|
200
|
+
setCarriedLookup(() => carried);
|
|
201
|
+
const {sent, fetch} = recording();
|
|
202
|
+
const traceparent =
|
|
203
|
+
'00-2cf7651916cd43dd8448eb211c80319e-d9ad6b7169203333-01';
|
|
204
|
+
await fetch(`${SERVICE}/1`, {headers: {traceparent}});
|
|
205
|
+
expect(sent[0]!.headers).toEqual({
|
|
206
|
+
'x-encore-meta-ctx-encore-test': carried.field,
|
|
207
|
+
traceparent,
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('carries nothing to anything but the app’s services', async () => {
|
|
212
|
+
setCarriedLookup(() => carried);
|
|
213
|
+
const {sent, fetch} = recording();
|
|
214
|
+
await fetch('http://127.0.0.1:9/hook', {headers: {accept: 'text/plain'}});
|
|
215
|
+
expect(sent[0]!.headers).toEqual({accept: 'text/plain'});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('refuses a call to a service where no test can be told from another', async () => {
|
|
219
|
+
// As `./scope` answers when several tests run at once and none is
|
|
220
|
+
// current: a call sent then would carry no test.
|
|
221
|
+
setCarriedLookup(() => {
|
|
222
|
+
throw new Error('several tests are running at once');
|
|
223
|
+
});
|
|
224
|
+
const {sent, fetch} = recording();
|
|
225
|
+
await expect(fetch(`${SERVICE}/1`)).rejects.toThrow(
|
|
226
|
+
'several tests are running at once',
|
|
227
|
+
);
|
|
228
|
+
expect(sent).toEqual([]);
|
|
229
|
+
expect(() => outgoingContext(ROOT_CONTEXT)).toThrow();
|
|
230
|
+
// A call to anything else carries no test anyway, and what is only
|
|
231
|
+
// recorded is recorded as no test's.
|
|
232
|
+
await fetch('http://127.0.0.1:9/hook');
|
|
233
|
+
expect(sent[0]!.headers).toEqual({});
|
|
234
|
+
expect(contextCtxBytes(ROOT_CONTEXT)).toBeUndefined();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('carries nothing outside a system test', async () => {
|
|
238
|
+
const {sent, fetch} = recording();
|
|
239
|
+
await fetch(`${SERVICE}/1`);
|
|
240
|
+
expect(sent[0]!.headers).toEqual({});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a system test's calls and messages carry of the test: the Request
|
|
3
|
+
* Context field that holds its id, and its span for them to continue, so
|
|
4
|
+
* that what the app does for the test can be told from the rest.
|
|
5
|
+
*
|
|
6
|
+
* Apart from the module that knows the tests (`./scope`), which needs the
|
|
7
|
+
* runtime: what sends calls loads without it, and asks here. Outside a
|
|
8
|
+
* system test nothing is registered, and a context is sent as it is.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
createTraceState,
|
|
14
|
+
isSpanContextValid,
|
|
15
|
+
trace,
|
|
16
|
+
type Context,
|
|
17
|
+
} from '@opentelemetry/api';
|
|
18
|
+
import {activeContext} from '../otel/context';
|
|
19
|
+
import {parseTraceparent} from '../otel/propagator';
|
|
20
|
+
import * as reqfields from '../reqfields';
|
|
21
|
+
|
|
22
|
+
/** What one system test's calls and messages carry. */
|
|
23
|
+
export interface Carried {
|
|
24
|
+
/** The name of the Request Context field that holds the test's id. */
|
|
25
|
+
readonly fieldName: string;
|
|
26
|
+
/** The field's value, in a field's wire form. */
|
|
27
|
+
readonly field: string;
|
|
28
|
+
/** The test's span as a `traceparent`, where the process records spans. */
|
|
29
|
+
readonly traceparent?: string | null;
|
|
30
|
+
/** The `tracestate` that goes with it. */
|
|
31
|
+
readonly tracestate?: string | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Finds what the current test carries: `null` when there is none. It
|
|
35
|
+
* throws where several tests run at once and none is current, as it cannot
|
|
36
|
+
* tell which one a call belongs to. */
|
|
37
|
+
let lookup: (() => Carried | null) | undefined;
|
|
38
|
+
|
|
39
|
+
/** Registers how the current system test is found: by `./scope`, in a
|
|
40
|
+
* system test's process only. */
|
|
41
|
+
export function setCarriedLookup(fn: (() => Carried | null) | undefined): void {
|
|
42
|
+
lookup = fn;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The context a call or a publish made in `ctx` is made in: in a system
|
|
47
|
+
* test, `ctx` with what the current test carries added where `ctx` has none
|
|
48
|
+
* (see {@link withCarried}). Anywhere else, `ctx` itself.
|
|
49
|
+
*
|
|
50
|
+
* It throws where several tests run at once and none is current: a call
|
|
51
|
+
* sent then would carry no test, and what the app did for it would be done
|
|
52
|
+
* on data no test sees and waited for by none.
|
|
53
|
+
*/
|
|
54
|
+
export function outgoingContext(ctx: Context = activeContext()): Context {
|
|
55
|
+
if (lookup === undefined) return ctx;
|
|
56
|
+
const carried = lookup();
|
|
57
|
+
return carried === null ? ctx : withCarried(ctx, carried);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* {@link outgoingContext}, for what is recorded or sent elsewhere than to
|
|
62
|
+
* the app: where no test can be told from another, `ctx` itself.
|
|
63
|
+
*/
|
|
64
|
+
export function outgoingContextIfKnown(ctx: Context): Context {
|
|
65
|
+
try {
|
|
66
|
+
return outgoingContext(ctx);
|
|
67
|
+
} catch {
|
|
68
|
+
return ctx;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `ctx` with what a test carries added where `ctx` has none: the field that
|
|
74
|
+
* holds the test's id, unless `ctx` holds one, as the context of a request
|
|
75
|
+
* made for another test does, and the test's span, unless `ctx` has a span
|
|
76
|
+
* of its own.
|
|
77
|
+
*/
|
|
78
|
+
export function withCarried(ctx: Context, carried: Carried): Context {
|
|
79
|
+
let out = ctx;
|
|
80
|
+
const fields = reqfields.current(ctx);
|
|
81
|
+
if (!Object.hasOwn(fields, carried.fieldName)) {
|
|
82
|
+
out = reqfields.withFields(
|
|
83
|
+
{...fields, [carried.fieldName]: carried.field},
|
|
84
|
+
out,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const span = trace.getSpanContext(ctx);
|
|
88
|
+
if (
|
|
89
|
+
(span === undefined || !isSpanContextValid(span)) &&
|
|
90
|
+
carried.traceparent
|
|
91
|
+
) {
|
|
92
|
+
const parent = parseTraceparent(carried.traceparent);
|
|
93
|
+
if (parent !== undefined) {
|
|
94
|
+
if (carried.tracestate) {
|
|
95
|
+
parent.traceState = createTraceState(carried.tracestate);
|
|
96
|
+
}
|
|
97
|
+
out = trace.setSpanContext(out, parent);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imported first by each runner adapter of `@encore.dev/sdk/testing`: the
|
|
3
|
+
* process is a test runner's, whatever its environment says, which the
|
|
4
|
+
* runtime reads when it is made.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
(globalThis as Record<symbol, unknown>)[Symbol.for('encore.testRunner')] = true;
|
|
9
|
+
|
|
10
|
+
export {};
|