@encore.dev/sdk 0.0.0 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +362 -0
- package/README.md +245 -2
- package/app_meta.test.ts +154 -0
- package/app_meta.ts +226 -0
- package/config/config.test.ts +384 -0
- package/config/config.ts +236 -0
- package/config/mod.ts +15 -0
- package/config/secrets.ts +173 -0
- package/config/value.ts +239 -0
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +62 -0
- package/dist/app_meta.d.ts +126 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +67 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +135 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +115 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +5 -0
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +124 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +73 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +54 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +181 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +57 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +39 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +171 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +284 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +108 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +349 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +67 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +271 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +52 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +11 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +23 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +114 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +65 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +8 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +74 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +15 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +13 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +22 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/span.d.ts +75 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +234 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +16 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +71 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +12 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +18 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +59 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +308 -0
- package/dist/internal/runtime/napi/napi.d.cts +1249 -0
- package/dist/internal/runtime/shutdown.d.ts +91 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +299 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +112 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +346 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +10 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +40 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +125 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +21 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +10 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +242 -0
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +353 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +3 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +10 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +8 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +18 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +7 -0
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +20 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +223 -0
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +121 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +218 -0
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +281 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +171 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +187 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +60 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/shutdown/mod.js +59 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/clickhouse/database.d.ts +262 -0
- package/dist/storage/clickhouse/database.d.ts.map +1 -0
- package/dist/storage/clickhouse/database.js +362 -0
- package/dist/storage/clickhouse/database.js.map +1 -0
- package/dist/storage/clickhouse/errors.d.ts +67 -0
- package/dist/storage/clickhouse/errors.d.ts.map +1 -0
- package/dist/storage/clickhouse/errors.js +91 -0
- package/dist/storage/clickhouse/errors.js.map +1 -0
- package/dist/storage/clickhouse/mod.d.ts +31 -0
- package/dist/storage/clickhouse/mod.d.ts.map +1 -0
- package/dist/storage/clickhouse/mod.js +29 -0
- package/dist/storage/clickhouse/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +522 -0
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +414 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +24 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +105 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +5 -0
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +47 -0
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +26 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +365 -0
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +480 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +5 -0
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +4 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +657 -0
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +759 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +336 -0
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +398 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +115 -0
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +109 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +16 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +21 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +90 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +55 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +290 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +611 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +12 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +92 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +49 -0
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +93 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +102 -0
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +309 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +43 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +418 -0
- package/internal/clients/grpc.test.ts +664 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +481 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +320 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/http.ts +92 -0
- package/internal/otel/index.ts +14 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +26 -0
- package/internal/otel/span.ts +281 -0
- package/internal/otel/tracer.test.ts +380 -0
- package/internal/otel/tracer.ts +111 -0
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +81 -0
- package/internal/runtime/napi/napi.cjs +308 -0
- package/internal/runtime/napi/napi.d.cts +1249 -0
- package/internal/runtime/shutdown.test.ts +464 -0
- package/internal/runtime/shutdown.ts +350 -0
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +384 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +341 -0
- package/metrics/mod.test.ts +177 -0
- package/metrics/mod.ts +450 -0
- package/mod.ts +15 -0
- package/otel.test.ts +98 -0
- package/otel.ts +17 -0
- package/package.json +208 -5
- package/pubsub/encoding.ts +18 -0
- package/pubsub/mod.ts +26 -0
- package/pubsub/pubsub.test.ts +405 -0
- package/pubsub/refs.ts +38 -0
- package/pubsub/subscription.ts +359 -0
- package/pubsub/topic.test.ts +147 -0
- package/pubsub/topic.ts +431 -0
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +393 -0
- package/services/index.ts +215 -0
- package/shutdown/mod.ts +78 -0
- package/storage/clickhouse/database.integration.test.ts +337 -0
- package/storage/clickhouse/database.test.ts +279 -0
- package/storage/clickhouse/database.ts +586 -0
- package/storage/clickhouse/errors.ts +130 -0
- package/storage/clickhouse/mod.ts +37 -0
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +968 -0
- package/storage/objects/error.ts +121 -0
- package/storage/objects/mod.ts +50 -0
- package/storage/objects/refs.ts +117 -0
- package/storage/postgres/database.integration.test.ts +450 -0
- package/storage/postgres/database.test.ts +428 -0
- package/storage/postgres/database.ts +658 -0
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +19 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +1471 -0
- package/storage/redis/database.ts +520 -0
- package/storage/redis/mod.ts +171 -0
- package/storage/redis/native.ts +22 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +866 -0
- package/storage/redis/reply.ts +780 -0
- package/storage/redis/runtime.test.ts +248 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +134 -0
- package/storage/redis/wire.ts +345 -0
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +276 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { Runtime } from './napi/napi.cjs';
|
|
5
|
+
/** A phase of Encore's shutdown.
|
|
6
|
+
*
|
|
7
|
+
* - `not-started`: shutdown has not begun.
|
|
8
|
+
* - `started`: Pub/Sub intake has stopped; Encore waits for the message
|
|
9
|
+
* handlers in flight, and for the app's holds.
|
|
10
|
+
* - `cleanup`: Encore is closing its resources and flushing telemetry.
|
|
11
|
+
* - `completed`: cleanup has finished, whatever its result. */
|
|
12
|
+
export type ShutdownPhase = 'not-started' | 'started' | 'cleanup' | 'completed';
|
|
13
|
+
/** How a completed shutdown went: `success` if cleanup finished within the
|
|
14
|
+
* shutdown deadline, else `timeout`. A failed cleanup is a
|
|
15
|
+
* {@link ShutdownError}. */
|
|
16
|
+
export type ShutdownResult = 'success' | 'timeout';
|
|
17
|
+
/** Encore's cleanup failed, or the shutdown was used before it began. */
|
|
18
|
+
export declare class ShutdownError extends Error {
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
/** Work the shutdown waits for before Encore cleans up: until it is
|
|
22
|
+
* released, or the shutdown deadline passes. Releasing it twice is harmless.
|
|
23
|
+
* As a `Disposable`, `using` releases it at the end of its scope. */
|
|
24
|
+
export interface ShutdownHold extends Disposable {
|
|
25
|
+
release(): void;
|
|
26
|
+
}
|
|
27
|
+
/** What a shutdown callback is told. */
|
|
28
|
+
export interface ShutdownContext {
|
|
29
|
+
/** Aborts when cleanup begins, the callback done or not: the shutdown
|
|
30
|
+
* deadline passed, or cleanup was forced. */
|
|
31
|
+
signal: AbortSignal;
|
|
32
|
+
/** When the shutdown deadline passes, in milliseconds since the epoch, as
|
|
33
|
+
* `Date.now()` counts them. */
|
|
34
|
+
deadline: number;
|
|
35
|
+
}
|
|
36
|
+
/** Called when shutdown begins. Cleanup waits for what it returns to settle. */
|
|
37
|
+
export type ShutdownCallback = (ctx: ShutdownContext) => void | Promise<void>;
|
|
38
|
+
/** Aborts when shutdown begins: Encore takes no new Pub/Sub messages, and the
|
|
39
|
+
* app should stop taking work too. */
|
|
40
|
+
export declare const signal: AbortSignal;
|
|
41
|
+
/** Sets the runtime the shutdown runs on. */
|
|
42
|
+
export declare function setShutdownRuntime(rt: Runtime): void;
|
|
43
|
+
/** Holds the shutdown back: Encore cleans up once every hold is released, or
|
|
44
|
+
* the shutdown deadline passes. A hold taken once the app has drained, or
|
|
45
|
+
* cleanup has begun, comes released: cleanup does not wait for it. */
|
|
46
|
+
export declare function hold(): ShutdownHold;
|
|
47
|
+
/** Holds the shutdown back until `work` settles. A rejection is logged. */
|
|
48
|
+
export declare function waitUntil(work: PromiseLike<unknown>): void;
|
|
49
|
+
/** Calls `callback` when shutdown begins, or at once if it has, holding
|
|
50
|
+
* cleanup back until it settles. Disposing of the returned value
|
|
51
|
+
* unregisters it. */
|
|
52
|
+
export declare function onShutdown(callback: ShutdownCallback): Disposable;
|
|
53
|
+
/** Registers `callback` as {@link onShutdown} does, as Encore's own: it
|
|
54
|
+
* doesn't stop Encore from waiting for an app that handles the signal itself. */
|
|
55
|
+
export declare function onShutdownInternal(callback: ShutdownCallback): Disposable;
|
|
56
|
+
/** Begins the shutdown, once: Encore stops taking Pub/Sub messages,
|
|
57
|
+
* {@link signal} aborts, and the {@link onShutdown} callbacks run. Encore
|
|
58
|
+
* cleans up once every hold is released, or the shutdown deadline passes.
|
|
59
|
+
* SIGTERM and SIGINT begin it, outside tests. */
|
|
60
|
+
export declare function begin(): void;
|
|
61
|
+
/** The shutdown's phase now. */
|
|
62
|
+
export declare function phase(): ShutdownPhase;
|
|
63
|
+
/** Resolves once the shutdown has begun and Pub/Sub intake has stopped.
|
|
64
|
+
* Waiting does not keep the process alive. */
|
|
65
|
+
export declare function started(): Promise<void>;
|
|
66
|
+
/** Resolves once cleanup begins: the app drained, the shutdown deadline
|
|
67
|
+
* passed, or cleanup was forced. Waiting does not keep the process alive. */
|
|
68
|
+
export declare function cleanup(): Promise<void>;
|
|
69
|
+
/** Resolves with the shutdown's result once cleanup has completed, after the
|
|
70
|
+
* deadline too; rejects with a {@link ShutdownError} if cleanup failed.
|
|
71
|
+
* Waiting keeps the process alive once the shutdown has begun. */
|
|
72
|
+
export declare function completed(): Promise<ShutdownResult>;
|
|
73
|
+
/** Begins cleanup without waiting for the app's holds or the Pub/Sub
|
|
74
|
+
* handlers in flight. Work still running may find its resources closed. */
|
|
75
|
+
export declare function forceCleanup(): void;
|
|
76
|
+
/** Begins the shutdown on SIGTERM or SIGINT, and exits once it completes:
|
|
77
|
+
* with `process.exitCode` (0 unless the app set it) if cleanup finished
|
|
78
|
+
* within the shutdown deadline, else 1. A second SIGINT, a second Ctrl-C,
|
|
79
|
+
* forces cleanup.
|
|
80
|
+
*
|
|
81
|
+
* An app that listens for the signal itself and holds nothing is waited for
|
|
82
|
+
* until it raises the signal again, exits, or has closed everything it had
|
|
83
|
+
* open. */
|
|
84
|
+
export declare function watchShutdownSignals(): void;
|
|
85
|
+
/** Runs `rt` until its shutdown completes, returning the exit code. The
|
|
86
|
+
* runtime handles SIGTERM and SIGINT; on them the shutdown begins here too,
|
|
87
|
+
* and cleanup waits for the app's holds. */
|
|
88
|
+
export declare function runUntilShutdown(r: Runtime): Promise<number>;
|
|
89
|
+
/** Has `sig` force cleanup when it comes again, as a second SIGINT does. */
|
|
90
|
+
export declare function forceCleanupOnRepeat(sig: NodeJS.Signals): void;
|
|
91
|
+
//# sourceMappingURL=shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../../internal/runtime/shutdown.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AAE7C;;;;;;+DAM+D;AAC/D,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAA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AAS,IAAI,OAAO,CAAC,cAAc,CAAC,CASnD;AAED;2EAC2E;AAC3E,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAED;;;;;;;WAOW;AACX,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;4CAE4C;AAC5C,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAI5D;AAED,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAE9D"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/** Encore's cleanup failed, or the shutdown was used before it began. */
|
|
2
|
+
export class ShutdownError extends Error {
|
|
3
|
+
name = 'ShutdownError';
|
|
4
|
+
}
|
|
5
|
+
const SIGNALS = ['SIGTERM', 'SIGINT'];
|
|
6
|
+
/** How long after the first signal the same one again is a new one, not the
|
|
7
|
+
* first delivered twice: a process group's runner may forward the signal its
|
|
8
|
+
* members already received. */
|
|
9
|
+
const REPEAT_MS = 1000;
|
|
10
|
+
let runtime;
|
|
11
|
+
/** Whether the runtime runs the process ({@link runUntilShutdown}): it
|
|
12
|
+
* handles the signals natively, and its caller exits. */
|
|
13
|
+
let hosted = false;
|
|
14
|
+
const callbacks = new Set();
|
|
15
|
+
/** The callbacks Encore registered itself, as its API framework's server
|
|
16
|
+
* does: they don't say the app tells Encore of its shutdown. */
|
|
17
|
+
const ownCallbacks = new WeakSet();
|
|
18
|
+
let holds = 0;
|
|
19
|
+
let begun = false;
|
|
20
|
+
let markBegun;
|
|
21
|
+
const begunAt = new Promise(resolve => (markBegun = resolve));
|
|
22
|
+
let deadline = 0;
|
|
23
|
+
/** Whether Encore was told the app has drained: holds count no longer. */
|
|
24
|
+
let drained = false;
|
|
25
|
+
let cleaningUp = false;
|
|
26
|
+
const startAbort = new AbortController();
|
|
27
|
+
const cleanupAbort = new AbortController();
|
|
28
|
+
let markStarted;
|
|
29
|
+
const startedAt = new Promise(resolve => (markStarted = resolve));
|
|
30
|
+
let markCleanup;
|
|
31
|
+
const cleanupAt = new Promise(resolve => (markCleanup = resolve));
|
|
32
|
+
let completion;
|
|
33
|
+
/** The signals that force cleanup when they come again: a second Ctrl-C, and
|
|
34
|
+
* for a gateway program a second SIGTERM, which is how the supervisor stops
|
|
35
|
+
* waiting for its drain. */
|
|
36
|
+
const forcing = new Set(['SIGINT']);
|
|
37
|
+
/** The signal that began the shutdown: Encore then exits once it completes. */
|
|
38
|
+
let signalled;
|
|
39
|
+
let signalledAt = 0;
|
|
40
|
+
/** Held for an app that handles the signal itself without telling Encore of
|
|
41
|
+
* its shutdown, until it is done. */
|
|
42
|
+
let appHold;
|
|
43
|
+
/** The signal the app raised again, to die of once Encore has cleaned up. */
|
|
44
|
+
let reraised;
|
|
45
|
+
/** Whether Encore waits for cleanup to complete, to exit. */
|
|
46
|
+
let exiting = false;
|
|
47
|
+
/** Whether the process is on its way out, cleanup completed. */
|
|
48
|
+
let finished = false;
|
|
49
|
+
/** Aborts when shutdown begins: Encore takes no new Pub/Sub messages, and the
|
|
50
|
+
* app should stop taking work too. */
|
|
51
|
+
export const signal = startAbort.signal;
|
|
52
|
+
/** Sets the runtime the shutdown runs on. */
|
|
53
|
+
export function setShutdownRuntime(rt) {
|
|
54
|
+
runtime = rt;
|
|
55
|
+
}
|
|
56
|
+
function rt() {
|
|
57
|
+
if (!runtime)
|
|
58
|
+
throw new ShutdownError('the Encore runtime is not loaded');
|
|
59
|
+
return runtime;
|
|
60
|
+
}
|
|
61
|
+
/** Holds the shutdown back: Encore cleans up once every hold is released, or
|
|
62
|
+
* the shutdown deadline passes. A hold taken once the app has drained, or
|
|
63
|
+
* cleanup has begun, comes released: cleanup does not wait for it. */
|
|
64
|
+
export function hold() {
|
|
65
|
+
if (drained || cleaningUp) {
|
|
66
|
+
console.warn('encore: a shutdown hold was taken after the app drained; cleanup does not wait for it');
|
|
67
|
+
const release = () => { };
|
|
68
|
+
return { release, [Symbol.dispose]: release };
|
|
69
|
+
}
|
|
70
|
+
holds++;
|
|
71
|
+
let held = true;
|
|
72
|
+
const release = () => {
|
|
73
|
+
if (!held)
|
|
74
|
+
return;
|
|
75
|
+
held = false;
|
|
76
|
+
holds--;
|
|
77
|
+
settle();
|
|
78
|
+
};
|
|
79
|
+
return { release, [Symbol.dispose]: release };
|
|
80
|
+
}
|
|
81
|
+
/** Holds the shutdown back until `work` settles. A rejection is logged. */
|
|
82
|
+
export function waitUntil(work) {
|
|
83
|
+
const held = hold();
|
|
84
|
+
Promise.resolve(work)
|
|
85
|
+
.then(undefined, err => console.error('encore: shutdown work failed:', err))
|
|
86
|
+
.finally(() => held.release());
|
|
87
|
+
}
|
|
88
|
+
/** Calls `callback` when shutdown begins, or at once if it has, holding
|
|
89
|
+
* cleanup back until it settles. Disposing of the returned value
|
|
90
|
+
* unregisters it. */
|
|
91
|
+
export function onShutdown(callback) {
|
|
92
|
+
callbacks.add(callback);
|
|
93
|
+
if (begun)
|
|
94
|
+
run(callback);
|
|
95
|
+
return { [Symbol.dispose]: () => void callbacks.delete(callback) };
|
|
96
|
+
}
|
|
97
|
+
/** Registers `callback` as {@link onShutdown} does, as Encore's own: it
|
|
98
|
+
* doesn't stop Encore from waiting for an app that handles the signal itself. */
|
|
99
|
+
export function onShutdownInternal(callback) {
|
|
100
|
+
ownCallbacks.add(callback);
|
|
101
|
+
return onShutdown(callback);
|
|
102
|
+
}
|
|
103
|
+
/** Begins the shutdown, once: Encore stops taking Pub/Sub messages,
|
|
104
|
+
* {@link signal} aborts, and the {@link onShutdown} callbacks run. Encore
|
|
105
|
+
* cleans up once every hold is released, or the shutdown deadline passes.
|
|
106
|
+
* SIGTERM and SIGINT begin it, outside tests. */
|
|
107
|
+
export function begin() {
|
|
108
|
+
if (begun)
|
|
109
|
+
return;
|
|
110
|
+
const r = rt();
|
|
111
|
+
begun = true;
|
|
112
|
+
r.beginShutdown(true);
|
|
113
|
+
deadline = Date.now() + r.shutdownTimeoutMs();
|
|
114
|
+
r.watchShutdown(onPhase);
|
|
115
|
+
if (!hosted)
|
|
116
|
+
process.once('exit', finishOnExit);
|
|
117
|
+
markBegun();
|
|
118
|
+
startAbort.abort();
|
|
119
|
+
for (const callback of callbacks)
|
|
120
|
+
run(callback);
|
|
121
|
+
settle();
|
|
122
|
+
}
|
|
123
|
+
/** The shutdown's phase now. */
|
|
124
|
+
export function phase() {
|
|
125
|
+
return (runtime?.shutdownPhase() ?? 'not-started');
|
|
126
|
+
}
|
|
127
|
+
/** Resolves once the shutdown has begun and Pub/Sub intake has stopped.
|
|
128
|
+
* Waiting does not keep the process alive. */
|
|
129
|
+
export function started() {
|
|
130
|
+
return startedAt;
|
|
131
|
+
}
|
|
132
|
+
/** Resolves once cleanup begins: the app drained, the shutdown deadline
|
|
133
|
+
* passed, or cleanup was forced. Waiting does not keep the process alive. */
|
|
134
|
+
export function cleanup() {
|
|
135
|
+
return cleanupAt;
|
|
136
|
+
}
|
|
137
|
+
/** Resolves with the shutdown's result once cleanup has completed, after the
|
|
138
|
+
* deadline too; rejects with a {@link ShutdownError} if cleanup failed.
|
|
139
|
+
* Waiting keeps the process alive once the shutdown has begun. */
|
|
140
|
+
export function completed() {
|
|
141
|
+
return (completion ??= begunAt
|
|
142
|
+
.then(() => rt().shutdownCompleted())
|
|
143
|
+
.then(result => {
|
|
144
|
+
if (result === 'failed') {
|
|
145
|
+
throw new ShutdownError('Encore resource cleanup failed');
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
/** Begins cleanup without waiting for the app's holds or the Pub/Sub
|
|
151
|
+
* handlers in flight. Work still running may find its resources closed. */
|
|
152
|
+
export function forceCleanup() {
|
|
153
|
+
if (!begun)
|
|
154
|
+
throw new ShutdownError('shutdown has not begun');
|
|
155
|
+
rt().forceShutdownCleanup();
|
|
156
|
+
}
|
|
157
|
+
/** Begins the shutdown on SIGTERM or SIGINT, and exits once it completes:
|
|
158
|
+
* with `process.exitCode` (0 unless the app set it) if cleanup finished
|
|
159
|
+
* within the shutdown deadline, else 1. A second SIGINT, a second Ctrl-C,
|
|
160
|
+
* forces cleanup.
|
|
161
|
+
*
|
|
162
|
+
* An app that listens for the signal itself and holds nothing is waited for
|
|
163
|
+
* until it raises the signal again, exits, or has closed everything it had
|
|
164
|
+
* open. */
|
|
165
|
+
export function watchShutdownSignals() {
|
|
166
|
+
for (const s of SIGNALS)
|
|
167
|
+
process.on(s, onSignal);
|
|
168
|
+
}
|
|
169
|
+
/** Runs `rt` until its shutdown completes, returning the exit code. The
|
|
170
|
+
* runtime handles SIGTERM and SIGINT; on them the shutdown begins here too,
|
|
171
|
+
* and cleanup waits for the app's holds. */
|
|
172
|
+
export function runUntilShutdown(r) {
|
|
173
|
+
runtime = r;
|
|
174
|
+
hosted = true;
|
|
175
|
+
return r.runForever(true);
|
|
176
|
+
}
|
|
177
|
+
/** Has `sig` force cleanup when it comes again, as a second SIGINT does. */
|
|
178
|
+
export function forceCleanupOnRepeat(sig) {
|
|
179
|
+
forcing.add(sig);
|
|
180
|
+
}
|
|
181
|
+
function onSignal(sig) {
|
|
182
|
+
if (hosted)
|
|
183
|
+
return begin();
|
|
184
|
+
if (signalled || begun)
|
|
185
|
+
return repeated(sig);
|
|
186
|
+
signalled = sig;
|
|
187
|
+
signalledAt = Date.now();
|
|
188
|
+
if (!appTellsShutdown() && process.listenerCount(sig) > 1) {
|
|
189
|
+
// The app's own listeners run after this one, and may take their time.
|
|
190
|
+
appHold = hold();
|
|
191
|
+
console.warn(`encore: the app handles ${sig} itself; Encore cleans up once it is done. ` +
|
|
192
|
+
'Register its shutdown with onShutdown() from @encore.dev/sdk/shutdown to say when.');
|
|
193
|
+
}
|
|
194
|
+
process.on('beforeExit', onIdle);
|
|
195
|
+
begin();
|
|
196
|
+
}
|
|
197
|
+
/** Whether the app holds the shutdown back, or has callbacks of its own. */
|
|
198
|
+
function appTellsShutdown() {
|
|
199
|
+
if (holds > 0)
|
|
200
|
+
return true;
|
|
201
|
+
for (const callback of callbacks) {
|
|
202
|
+
if (!ownCallbacks.has(callback))
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function repeated(sig) {
|
|
208
|
+
if (!signalled)
|
|
209
|
+
return;
|
|
210
|
+
if (appHold && sig === signalled && process.listenerCount(sig) === 1) {
|
|
211
|
+
// The app raised the signal again, having removed its own listener. Only
|
|
212
|
+
// the signal it handled counts: another may arrive while it still runs.
|
|
213
|
+
reraised = sig;
|
|
214
|
+
appHold.release();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (forcing.has(sig) && Date.now() - signalledAt > REPEAT_MS) {
|
|
218
|
+
rt().forceShutdownCleanup();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** The event loop emptied. An app handling the signal itself is done; other
|
|
222
|
+
* holds are still waited for, until the deadline, as work that holds nothing
|
|
223
|
+
* open on the event loop may yet release them. */
|
|
224
|
+
function onIdle() {
|
|
225
|
+
// A turn later, as a signal the app raised as it closed its last handle is
|
|
226
|
+
// read in that turn: it says how the app meant to end.
|
|
227
|
+
setImmediate(() => {
|
|
228
|
+
appHold?.release();
|
|
229
|
+
if (!finished)
|
|
230
|
+
exitOnCompletion();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function settle() {
|
|
234
|
+
if (begun && !drained && holds === 0)
|
|
235
|
+
markDrained();
|
|
236
|
+
}
|
|
237
|
+
function markDrained() {
|
|
238
|
+
drained = true;
|
|
239
|
+
rt().markApplicationDrained();
|
|
240
|
+
// Now the app is done, the wait may hold the event loop open.
|
|
241
|
+
if (signalled)
|
|
242
|
+
exitOnCompletion();
|
|
243
|
+
}
|
|
244
|
+
/** Exits once cleanup completes, holding the event loop open till then. */
|
|
245
|
+
function exitOnCompletion() {
|
|
246
|
+
if (exiting)
|
|
247
|
+
return;
|
|
248
|
+
exiting = true;
|
|
249
|
+
completed().then(result => exit(result), () => exit('failed'));
|
|
250
|
+
}
|
|
251
|
+
function onPhase(phase, result) {
|
|
252
|
+
reached(phase);
|
|
253
|
+
// Cleanup also completes once the shutdown deadline passes, the app done
|
|
254
|
+
// or not; the exit code then says it was cut short.
|
|
255
|
+
if (phase === 'completed' && signalled)
|
|
256
|
+
exit(result ?? 'failed');
|
|
257
|
+
}
|
|
258
|
+
/** Settles what waits for `phase`, and for the phases before it. */
|
|
259
|
+
function reached(phase) {
|
|
260
|
+
if (phase === 'cleanup' || phase === 'completed') {
|
|
261
|
+
cleaningUp = true;
|
|
262
|
+
cleanupAbort.abort();
|
|
263
|
+
markCleanup();
|
|
264
|
+
}
|
|
265
|
+
markStarted();
|
|
266
|
+
}
|
|
267
|
+
/** Exits with 1 if cleanup failed or timed out, else as the app meant to:
|
|
268
|
+
* dying of the signal it raised again, or with its own exit code. */
|
|
269
|
+
function exit(result) {
|
|
270
|
+
if (finished)
|
|
271
|
+
return;
|
|
272
|
+
finished = true;
|
|
273
|
+
// Completion may be heard of before the phases leading to it.
|
|
274
|
+
reached('completed');
|
|
275
|
+
if (result !== 'success')
|
|
276
|
+
process.exit(1);
|
|
277
|
+
if (reraised) {
|
|
278
|
+
for (const s of SIGNALS)
|
|
279
|
+
process.off(s, onSignal);
|
|
280
|
+
process.kill(process.pid, reraised);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
process.exit();
|
|
284
|
+
}
|
|
285
|
+
/** An app that exits itself leaves no turn of the event loop to wait in:
|
|
286
|
+
* cleanup finishes here, blocking, and a failure overrides its exit code. */
|
|
287
|
+
function finishOnExit() {
|
|
288
|
+
if (finished)
|
|
289
|
+
return;
|
|
290
|
+
finished = true;
|
|
291
|
+
const code = rt().finishShutdownSync();
|
|
292
|
+
if (code !== 0)
|
|
293
|
+
process.exitCode = code;
|
|
294
|
+
}
|
|
295
|
+
function run(callback) {
|
|
296
|
+
const ctx = { signal: cleanupAbort.signal, deadline };
|
|
297
|
+
waitUntil((async () => callback(ctx))());
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../../internal/runtime/shutdown.ts"],"names":[],"mappings":"AAgBA,yEAAyE;AACzE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,GAAG,eAAe,CAAC;CACjC;AAsBD,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAU,CAAC;AAC/C;;+BAE+B;AAC/B,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAI,OAA4B,CAAC;AACjC;yDACyD;AACzD,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;AAC9C;gEACgE;AAChE,MAAM,YAAY,GAAG,IAAI,OAAO,EAAoB,CAAC;AACrD,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,IAAI,KAAK,GAAG,KAAK,CAAC;AAClB,IAAI,SAAsB,CAAC;AAC3B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;AACpE,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,0EAA0E;AAC1E,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,IAAI,UAAU,GAAG,KAAK,CAAC;AACvB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;AACzC,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;AAC3C,IAAI,WAAwB,CAAC;AAC7B,MAAM,SAAS,GAAG,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;AACxE,IAAI,WAAwB,CAAC;AAC7B,MAAM,SAAS,GAAG,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,CAAC,WAAW,GA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AAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { type Context } from '@opentelemetry/api';
|
|
13
|
+
/** What one system test's calls and messages carry. */
|
|
14
|
+
export interface Carried {
|
|
15
|
+
/** The name of the Request Context field that holds the test's id. */
|
|
16
|
+
readonly fieldName: string;
|
|
17
|
+
/** The field's value, in a field's wire form. */
|
|
18
|
+
readonly field: string;
|
|
19
|
+
/** The test's span as a `traceparent`, where the process records spans. */
|
|
20
|
+
readonly traceparent?: string | null;
|
|
21
|
+
/** The `tracestate` that goes with it. */
|
|
22
|
+
readonly tracestate?: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** Registers how the current system test is found: by `./scope`, in a
|
|
25
|
+
* system test's process only. */
|
|
26
|
+
export declare function setCarriedLookup(fn: (() => Carried | null) | undefined): void;
|
|
27
|
+
/**
|
|
28
|
+
* The context a call or a publish made in `ctx` is made in: in a system
|
|
29
|
+
* test, `ctx` with what the current test carries added where `ctx` has none
|
|
30
|
+
* (see {@link withCarried}). Anywhere else, `ctx` itself.
|
|
31
|
+
*
|
|
32
|
+
* It throws where several tests run at once and none is current: a call
|
|
33
|
+
* sent then would carry no test, and what the app did for it would be done
|
|
34
|
+
* on data no test sees and waited for by none.
|
|
35
|
+
*/
|
|
36
|
+
export declare function outgoingContext(ctx?: Context): Context;
|
|
37
|
+
/**
|
|
38
|
+
* {@link outgoingContext}, for what is recorded or sent elsewhere than to
|
|
39
|
+
* the app: where no test can be told from another, `ctx` itself.
|
|
40
|
+
*/
|
|
41
|
+
export declare function outgoingContextIfKnown(ctx: Context): Context;
|
|
42
|
+
/**
|
|
43
|
+
* `ctx` with what a test carries added where `ctx` has none: the field that
|
|
44
|
+
* holds the test's id, unless `ctx` holds one, as the context of a request
|
|
45
|
+
* made for another test does, and the test's span, unless `ctx` has a span
|
|
46
|
+
* of its own.
|
|
47
|
+
*/
|
|
48
|
+
export declare function withCarried(ctx: Context, carried: Carried): Context;
|
|
49
|
+
//# sourceMappingURL=carry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry.d.ts","sourceRoot":"","sources":["../../../internal/testing/carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,oBAAoB,CAAC;AAK5B,uDAAuD;AACvD,MAAM,WAAW,OAAO;IACtB,sEAAsE;IACtE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAOD;iCACiC;AACjC,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,CAE7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,GAAE,OAAyB,GAAG,OAAO,CAIvE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAM5D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAuBnE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { createTraceState, isSpanContextValid, trace, } from '@opentelemetry/api';
|
|
13
|
+
import { activeContext } from '../otel/context.js';
|
|
14
|
+
import { parseTraceparent } from '../otel/propagator.js';
|
|
15
|
+
import * as reqfields from '../reqfields.js';
|
|
16
|
+
/** Finds what the current test carries: `null` when there is none. It
|
|
17
|
+
* throws where several tests run at once and none is current, as it cannot
|
|
18
|
+
* tell which one a call belongs to. */
|
|
19
|
+
let lookup;
|
|
20
|
+
/** Registers how the current system test is found: by `./scope`, in a
|
|
21
|
+
* system test's process only. */
|
|
22
|
+
export function setCarriedLookup(fn) {
|
|
23
|
+
lookup = fn;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The context a call or a publish made in `ctx` is made in: in a system
|
|
27
|
+
* test, `ctx` with what the current test carries added where `ctx` has none
|
|
28
|
+
* (see {@link withCarried}). Anywhere else, `ctx` itself.
|
|
29
|
+
*
|
|
30
|
+
* It throws where several tests run at once and none is current: a call
|
|
31
|
+
* sent then would carry no test, and what the app did for it would be done
|
|
32
|
+
* on data no test sees and waited for by none.
|
|
33
|
+
*/
|
|
34
|
+
export function outgoingContext(ctx = activeContext()) {
|
|
35
|
+
if (lookup === undefined)
|
|
36
|
+
return ctx;
|
|
37
|
+
const carried = lookup();
|
|
38
|
+
return carried === null ? ctx : withCarried(ctx, carried);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* {@link outgoingContext}, for what is recorded or sent elsewhere than to
|
|
42
|
+
* the app: where no test can be told from another, `ctx` itself.
|
|
43
|
+
*/
|
|
44
|
+
export function outgoingContextIfKnown(ctx) {
|
|
45
|
+
try {
|
|
46
|
+
return outgoingContext(ctx);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return ctx;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `ctx` with what a test carries added where `ctx` has none: the field that
|
|
54
|
+
* holds the test's id, unless `ctx` holds one, as the context of a request
|
|
55
|
+
* made for another test does, and the test's span, unless `ctx` has a span
|
|
56
|
+
* of its own.
|
|
57
|
+
*/
|
|
58
|
+
export function withCarried(ctx, carried) {
|
|
59
|
+
let out = ctx;
|
|
60
|
+
const fields = reqfields.current(ctx);
|
|
61
|
+
if (!Object.hasOwn(fields, carried.fieldName)) {
|
|
62
|
+
out = reqfields.withFields({ ...fields, [carried.fieldName]: carried.field }, out);
|
|
63
|
+
}
|
|
64
|
+
const span = trace.getSpanContext(ctx);
|
|
65
|
+
if ((span === undefined || !isSpanContextValid(span)) &&
|
|
66
|
+
carried.traceparent) {
|
|
67
|
+
const parent = parseTraceparent(carried.traceparent);
|
|
68
|
+
if (parent !== undefined) {
|
|
69
|
+
if (carried.tracestate) {
|
|
70
|
+
parent.traceState = createTraceState(carried.tracestate);
|
|
71
|
+
}
|
|
72
|
+
out = trace.setSpanContext(out, parent);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=carry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carry.js","sourceRoot":"","sources":["../../../internal/testing/carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,GAEN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,M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,CAAC;QACjD,OAAO,CAAC,WAAW,EACnB,CAAC;QACD,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3D,CAAC;YACD,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../internal/testing/runner.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,CAAC"}
|
|
@@ -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[Symbol.for('encore.testRunner')] = true;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../internal/testing/runner.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACF,UAAsC,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,GAAG,IAAI,CAAC"}
|