@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,464 @@
|
|
|
1
|
+
import {afterAll, describe, expect, test} from 'bun:test';
|
|
2
|
+
import http2 from 'node:http2';
|
|
3
|
+
import type {AddressInfo} from 'node:net';
|
|
4
|
+
import {join} from 'node:path';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Spans reach the collector when the process is stopped with a signal. The app
|
|
8
|
+
* runs in a child process exporting to an OTLP/gRPC receiver here, and is
|
|
9
|
+
* stopped with SIGTERM.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Spans received, as (name, finished). */
|
|
13
|
+
const received: {name: string; finished: boolean}[] = [];
|
|
14
|
+
|
|
15
|
+
const receiver = http2.createServer((req, res) => {
|
|
16
|
+
const chunks: Buffer[] = [];
|
|
17
|
+
req.on('data', (c: Buffer) => chunks.push(c));
|
|
18
|
+
req.on('end', () => {
|
|
19
|
+
// gRPC frame: 1 byte compression flag, 4 bytes length, message.
|
|
20
|
+
const body = Buffer.concat(chunks).subarray(5);
|
|
21
|
+
if (req.url.endsWith('TraceService/Export')) received.push(...spans(body));
|
|
22
|
+
res.writeHead(200, {
|
|
23
|
+
'content-type': 'application/grpc',
|
|
24
|
+
'grpc-accept-encoding': 'identity',
|
|
25
|
+
});
|
|
26
|
+
res.addTrailers({'grpc-status': '0'});
|
|
27
|
+
res.end(Buffer.alloc(5));
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
receiver.listen(0, '127.0.0.1');
|
|
31
|
+
await new Promise(resolve => receiver.once('listening', resolve));
|
|
32
|
+
const collector = `http://127.0.0.1:${(receiver.address() as AddressInfo).port}`;
|
|
33
|
+
|
|
34
|
+
afterAll(() => {
|
|
35
|
+
receiver.close();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/** A module beside this one, as a string literal for a script to import: a
|
|
39
|
+
* Windows path's backslashes spliced in bare would be escapes. */
|
|
40
|
+
const here = (path: string) => JSON.stringify(join(import.meta.dir, path));
|
|
41
|
+
|
|
42
|
+
const APP = `
|
|
43
|
+
import { tracerProvider } from ${here('../../otel')};
|
|
44
|
+
|
|
45
|
+
tracerProvider().getTracer("app").startSpan("ended before signal").end();
|
|
46
|
+
// Keeps the process alive, as a server does.
|
|
47
|
+
setInterval(() => {}, 1000);
|
|
48
|
+
console.log("ready");
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const DRAINING = `
|
|
52
|
+
import { tracerProvider } from ${here('../../otel')};
|
|
53
|
+
import { onShutdown } from ${here('../../shutdown/mod')};
|
|
54
|
+
|
|
55
|
+
const span = tracerProvider().getTracer("app").startSpan("in flight at signal");
|
|
56
|
+
const timer = setInterval(() => {}, 1000);
|
|
57
|
+
onShutdown(async () => {
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
59
|
+
span.end();
|
|
60
|
+
clearInterval(timer);
|
|
61
|
+
});
|
|
62
|
+
console.log("ready");
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
// Shuts down as NestJS's enableShutdownHooks() does: its own listener awaits
|
|
66
|
+
// the app's hooks, then removes itself and re-raises the signal.
|
|
67
|
+
const OWN_HOOKS = `
|
|
68
|
+
import ${here('mod')};
|
|
69
|
+
|
|
70
|
+
const timer = setInterval(() => {}, 1000);
|
|
71
|
+
const onSignal = async (signal) => {
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
73
|
+
clearInterval(timer);
|
|
74
|
+
console.log("hooks done");
|
|
75
|
+
process.off("SIGTERM", onSignal);
|
|
76
|
+
process.kill(process.pid, signal);
|
|
77
|
+
};
|
|
78
|
+
process.on("SIGTERM", onSignal);
|
|
79
|
+
console.log("ready");
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
// Shuts down in its own listener, then exits with a code of its own.
|
|
83
|
+
const OWN_EXIT = `
|
|
84
|
+
import ${here('mod')};
|
|
85
|
+
|
|
86
|
+
setInterval(() => {}, 1000);
|
|
87
|
+
process.on("SIGTERM", async () => {
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
89
|
+
console.log("hooks done");
|
|
90
|
+
process.exit(3);
|
|
91
|
+
});
|
|
92
|
+
console.log("ready");
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
// Closes everything it has open in its own listener, setting an exit code.
|
|
96
|
+
const OWN_IDLE = `
|
|
97
|
+
import ${here('mod')};
|
|
98
|
+
|
|
99
|
+
const timer = setInterval(() => {}, 1000);
|
|
100
|
+
process.on("SIGTERM", async () => {
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
102
|
+
clearInterval(timer);
|
|
103
|
+
console.log("hooks done");
|
|
104
|
+
process.exitCode = 4;
|
|
105
|
+
});
|
|
106
|
+
console.log("ready");
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
// Shuts down as OWN_HOOKS does, beside a drain Encore registered itself, as
|
|
110
|
+
// its API framework's server does.
|
|
111
|
+
const OWN_HOOKS_SERVED = `
|
|
112
|
+
import ${here('mod')};
|
|
113
|
+
import { onShutdownInternal } from ${here('shutdown')};
|
|
114
|
+
|
|
115
|
+
onShutdownInternal(() => {});
|
|
116
|
+
const timer = setInterval(() => {}, 1000);
|
|
117
|
+
const onSignal = async (signal) => {
|
|
118
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
119
|
+
clearInterval(timer);
|
|
120
|
+
console.log("hooks done");
|
|
121
|
+
process.off("SIGTERM", onSignal);
|
|
122
|
+
process.kill(process.pid, signal);
|
|
123
|
+
};
|
|
124
|
+
process.on("SIGTERM", onSignal);
|
|
125
|
+
console.log("ready");
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
// Handles the signal itself, holding the shutdown back until it is done; a
|
|
129
|
+
// timer it leaves running doesn't keep the process alive.
|
|
130
|
+
const OWN_HOLD = `
|
|
131
|
+
import * as shutdown from ${here('../../shutdown/mod')};
|
|
132
|
+
|
|
133
|
+
setInterval(() => {}, 1000);
|
|
134
|
+
const held = shutdown.hold();
|
|
135
|
+
process.on("SIGTERM", async () => {
|
|
136
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
137
|
+
console.log("hooks done");
|
|
138
|
+
held.release();
|
|
139
|
+
});
|
|
140
|
+
console.log("ready");
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
// A job in flight at the signal holds the shutdown back for its scope.
|
|
144
|
+
const USING = `
|
|
145
|
+
import * as shutdown from ${here('../../shutdown/mod')};
|
|
146
|
+
|
|
147
|
+
async function job() {
|
|
148
|
+
using _ = shutdown.hold();
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
150
|
+
console.log("job done");
|
|
151
|
+
}
|
|
152
|
+
void job();
|
|
153
|
+
console.log("ready");
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
// A callback is told the shutdown began, and when cleanup does.
|
|
157
|
+
const CONTEXT = `
|
|
158
|
+
import * as shutdown from ${here('../../shutdown/mod')};
|
|
159
|
+
|
|
160
|
+
setInterval(() => {}, 1000);
|
|
161
|
+
shutdown.onShutdown(({ signal, deadline }) => {
|
|
162
|
+
console.log("began", shutdown.signal.aborted, deadline > Date.now());
|
|
163
|
+
signal.addEventListener("abort", () => console.log("cleanup"));
|
|
164
|
+
});
|
|
165
|
+
console.log("ready");
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
// Never releases its hold: only the deadline or a second Ctrl-C ends it.
|
|
169
|
+
const STUCK = `
|
|
170
|
+
import * as shutdown from ${here('../../shutdown/mod')};
|
|
171
|
+
|
|
172
|
+
setInterval(() => {}, 1000);
|
|
173
|
+
shutdown.hold();
|
|
174
|
+
console.log("ready");
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
// Runs the runtime as encore.dev's \`run\` does, which handles the signals.
|
|
178
|
+
const HOSTED = `
|
|
179
|
+
import { tracerProvider } from ${here('../../otel')};
|
|
180
|
+
import { RT, runUntilShutdown } from ${here('mod')};
|
|
181
|
+
import { onShutdown } from ${here('../../shutdown/mod')};
|
|
182
|
+
|
|
183
|
+
const span = tracerProvider().getTracer("app").startSpan("in flight at signal");
|
|
184
|
+
onShutdown(async () => {
|
|
185
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
186
|
+
span.end();
|
|
187
|
+
});
|
|
188
|
+
const exited = runUntilShutdown(RT);
|
|
189
|
+
// The runtime listens for the signal once it runs.
|
|
190
|
+
setTimeout(() => console.log("ready"), 500);
|
|
191
|
+
process.exit(await exited);
|
|
192
|
+
`;
|
|
193
|
+
|
|
194
|
+
type Signal = 'SIGTERM' | 'SIGINT';
|
|
195
|
+
|
|
196
|
+
/** Runs `script` as the app, stops it with `signals` of `kind` (or the
|
|
197
|
+
* signals listed, in order), `gap` ms apart, once it prints `ready`, and returns its exit code and how long it
|
|
198
|
+
* took to exit after the first signal. */
|
|
199
|
+
async function runApp(
|
|
200
|
+
script: string,
|
|
201
|
+
signals = 1,
|
|
202
|
+
telemetry = true,
|
|
203
|
+
kind: Signal | Signal[] = 'SIGTERM',
|
|
204
|
+
gap = 100,
|
|
205
|
+
): Promise<{
|
|
206
|
+
code: number | null;
|
|
207
|
+
signal: string | null;
|
|
208
|
+
out: string;
|
|
209
|
+
ms: number;
|
|
210
|
+
}> {
|
|
211
|
+
const proc = Bun.spawn({
|
|
212
|
+
cmd: [process.execPath, '-e', script],
|
|
213
|
+
cwd: import.meta.dir,
|
|
214
|
+
env: {
|
|
215
|
+
...process.env,
|
|
216
|
+
NODE_ENV: 'production',
|
|
217
|
+
ENCORE_RUNTIME_CONFIG: runtimeConfig(collector, telemetry),
|
|
218
|
+
// Nothing is exported on a timer while the test runs.
|
|
219
|
+
OTEL_BSP_SCHEDULE_DELAY: '60000',
|
|
220
|
+
},
|
|
221
|
+
stdout: 'pipe',
|
|
222
|
+
stderr: 'inherit',
|
|
223
|
+
});
|
|
224
|
+
const decoder = new TextDecoder();
|
|
225
|
+
const reader = proc.stdout.getReader();
|
|
226
|
+
let out = '';
|
|
227
|
+
const read = async (): Promise<boolean> => {
|
|
228
|
+
const {done, value} = await reader.read();
|
|
229
|
+
if (!done) out += decoder.decode(value);
|
|
230
|
+
return !done;
|
|
231
|
+
};
|
|
232
|
+
while (!out.split('\n').some(l => l.trim() === 'ready') && (await read()));
|
|
233
|
+
const start = performance.now();
|
|
234
|
+
const kinds = Array.isArray(kind) ? kind : Array<Signal>(signals).fill(kind);
|
|
235
|
+
for (const [i, k] of kinds.entries()) {
|
|
236
|
+
if (i > 0) await Bun.sleep(gap);
|
|
237
|
+
proc.kill(k);
|
|
238
|
+
}
|
|
239
|
+
const timeout = setTimeout(() => proc.kill('SIGKILL'), 20_000);
|
|
240
|
+
while (await read());
|
|
241
|
+
await proc.exited;
|
|
242
|
+
clearTimeout(timeout);
|
|
243
|
+
const ms = performance.now() - start;
|
|
244
|
+
return {code: proc.exitCode, signal: proc.signalCode, out, ms};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* POSIX only: each test stops its app with a signal, which Windows has none
|
|
249
|
+
* of to send it. There `kill()` ends the process at once, and Ctrl-Break, the
|
|
250
|
+
* signal a child can be sent alone, ends a Bun process whatever it listens
|
|
251
|
+
* for; the runtime run by `runUntilShutdown` takes it, but the app's own
|
|
252
|
+
* shutdown work, begun from the signal's listener, doesn't run.
|
|
253
|
+
*/
|
|
254
|
+
describe.skipIf(process.platform === 'win32')('shutdown', () => {
|
|
255
|
+
test('SIGTERM flushes ended spans', async () => {
|
|
256
|
+
const {code} = await runApp(APP);
|
|
257
|
+
expect(received).toContainEqual({
|
|
258
|
+
name: 'ended before signal',
|
|
259
|
+
finished: true,
|
|
260
|
+
});
|
|
261
|
+
expect(code).toBe(0);
|
|
262
|
+
}, 30_000);
|
|
263
|
+
|
|
264
|
+
test('SIGTERM waits for the app to drain', async () => {
|
|
265
|
+
received.length = 0;
|
|
266
|
+
const {code} = await runApp(DRAINING);
|
|
267
|
+
expect(received).toContainEqual({
|
|
268
|
+
name: 'in flight at signal',
|
|
269
|
+
finished: true,
|
|
270
|
+
});
|
|
271
|
+
expect(code).toBe(0);
|
|
272
|
+
}, 30_000);
|
|
273
|
+
|
|
274
|
+
test('a host running the runtime runs the drains on SIGTERM', async () => {
|
|
275
|
+
received.length = 0;
|
|
276
|
+
const {code} = await runApp(HOSTED);
|
|
277
|
+
expect(received).toContainEqual({
|
|
278
|
+
name: 'in flight at signal',
|
|
279
|
+
finished: true,
|
|
280
|
+
});
|
|
281
|
+
expect(code).toBe(0);
|
|
282
|
+
}, 30_000);
|
|
283
|
+
|
|
284
|
+
test("an app's own signal handling finishes before cleanup", async () => {
|
|
285
|
+
received.length = 0;
|
|
286
|
+
const {code, signal, out} = await runApp(OWN_HOOKS, 1, false);
|
|
287
|
+
expect(out).toContain('hooks done');
|
|
288
|
+
// It dies of the signal it re-raised, as it meant to.
|
|
289
|
+
expect(code).toBeNull();
|
|
290
|
+
expect(signal).toBe('SIGTERM');
|
|
291
|
+
}, 30_000);
|
|
292
|
+
|
|
293
|
+
test("an app's own signal handling is waited for beside Encore's drain", async () => {
|
|
294
|
+
const {code, signal, out} = await runApp(OWN_HOOKS_SERVED, 1, false);
|
|
295
|
+
expect(out).toContain('hooks done');
|
|
296
|
+
expect(code).toBeNull();
|
|
297
|
+
expect(signal).toBe('SIGTERM');
|
|
298
|
+
}, 30_000);
|
|
299
|
+
|
|
300
|
+
test("another signal isn't taken for the app's own raised again", async () => {
|
|
301
|
+
const {code, signal, out} = await runApp(OWN_HOOKS, 2, false, [
|
|
302
|
+
'SIGTERM',
|
|
303
|
+
'SIGINT',
|
|
304
|
+
]);
|
|
305
|
+
// The SIGINT came while its hooks ran; it still dies of its own SIGTERM.
|
|
306
|
+
expect(out).toContain('hooks done');
|
|
307
|
+
expect(code).toBeNull();
|
|
308
|
+
expect(signal).toBe('SIGTERM');
|
|
309
|
+
}, 30_000);
|
|
310
|
+
|
|
311
|
+
test('an app that exits itself keeps its exit code', async () => {
|
|
312
|
+
received.length = 0;
|
|
313
|
+
const {code, out} = await runApp(OWN_EXIT, 1, false);
|
|
314
|
+
expect(out).toContain('hooks done');
|
|
315
|
+
expect(code).toBe(3);
|
|
316
|
+
}, 30_000);
|
|
317
|
+
|
|
318
|
+
test('an app that closes everything keeps its exit code', async () => {
|
|
319
|
+
received.length = 0;
|
|
320
|
+
const {code, out} = await runApp(OWN_IDLE, 1, false);
|
|
321
|
+
expect(out).toContain('hooks done');
|
|
322
|
+
expect(code).toBe(4);
|
|
323
|
+
}, 30_000);
|
|
324
|
+
|
|
325
|
+
test('an app holding the shutdown is done once it releases it', async () => {
|
|
326
|
+
const {code, out, ms} = await runApp(OWN_HOLD, 1, false);
|
|
327
|
+
expect(out).toContain('hooks done');
|
|
328
|
+
expect(code).toBe(0);
|
|
329
|
+
// Its timer is left running: Encore exits, well before the deadline.
|
|
330
|
+
expect(ms).toBeLessThan(4000);
|
|
331
|
+
}, 30_000);
|
|
332
|
+
|
|
333
|
+
test('a hold taken with using is released at the end of its scope', async () => {
|
|
334
|
+
const {code, out} = await runApp(USING, 1, false);
|
|
335
|
+
expect(out).toContain('job done');
|
|
336
|
+
expect(code).toBe(0);
|
|
337
|
+
}, 30_000);
|
|
338
|
+
|
|
339
|
+
test('a shutdown callback is told when shutdown and cleanup begin', async () => {
|
|
340
|
+
const {code, out} = await runApp(CONTEXT, 1, false);
|
|
341
|
+
expect(out).toContain('began true true');
|
|
342
|
+
expect(out).toContain('cleanup');
|
|
343
|
+
expect(code).toBe(0);
|
|
344
|
+
}, 30_000);
|
|
345
|
+
|
|
346
|
+
test('a hold never released is cut off at the deadline', async () => {
|
|
347
|
+
const {code} = await runApp(STUCK, 1, false);
|
|
348
|
+
expect(code).toBe(1);
|
|
349
|
+
}, 30_000);
|
|
350
|
+
|
|
351
|
+
test('a second Ctrl-C stops waiting for the app', async () => {
|
|
352
|
+
const {code, ms} = await runApp(STUCK, 2, false, 'SIGINT', 1500);
|
|
353
|
+
// Forced, cleanup finishes in time.
|
|
354
|
+
expect(code).toBe(0);
|
|
355
|
+
expect(ms).toBeLessThan(4000);
|
|
356
|
+
}, 30_000);
|
|
357
|
+
|
|
358
|
+
test('a repeated signal does not cut shutdown short', async () => {
|
|
359
|
+
received.length = 0;
|
|
360
|
+
const {code} = await runApp(DRAINING, 2);
|
|
361
|
+
expect(received).toContainEqual({
|
|
362
|
+
name: 'in flight at signal',
|
|
363
|
+
finished: true,
|
|
364
|
+
});
|
|
365
|
+
expect(code).toBe(0);
|
|
366
|
+
}, 30_000);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
/** The spans of an `ExportTraceServiceRequest`. */
|
|
370
|
+
function spans(buf: Uint8Array): {name: string; finished: boolean}[] {
|
|
371
|
+
const out: {name: string; finished: boolean}[] = [];
|
|
372
|
+
// ExportTraceServiceRequest{resource_spans=1}, ResourceSpans{scope_spans=2},
|
|
373
|
+
// ScopeSpans{spans=2}, Span{name=5, end_time_unix_nano=8}.
|
|
374
|
+
for (const rs of fields(buf, 1))
|
|
375
|
+
for (const ss of fields(rs, 2))
|
|
376
|
+
for (const span of fields(ss, 2)) {
|
|
377
|
+
const [name] = fields(span, 5);
|
|
378
|
+
const [end] = fields(span, 8);
|
|
379
|
+
out.push({
|
|
380
|
+
name: new TextDecoder().decode(name),
|
|
381
|
+
finished: !!end && end.some(b => b !== 0),
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** The raw values of field `want` in protobuf message `buf`. */
|
|
388
|
+
function fields(buf: Uint8Array, want: number): Uint8Array[] {
|
|
389
|
+
const out: Uint8Array[] = [];
|
|
390
|
+
let i = 0;
|
|
391
|
+
const varint = (): number => {
|
|
392
|
+
let n = 0;
|
|
393
|
+
let shift = 1;
|
|
394
|
+
for (;;) {
|
|
395
|
+
const b = buf[i++]!;
|
|
396
|
+
n += (b & 0x7f) * shift;
|
|
397
|
+
if (b < 0x80) return n;
|
|
398
|
+
shift *= 128;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
while (i < buf.length) {
|
|
402
|
+
const key = varint();
|
|
403
|
+
const field = Math.floor(key / 8);
|
|
404
|
+
const start = i;
|
|
405
|
+
switch (key & 7) {
|
|
406
|
+
case 0:
|
|
407
|
+
varint();
|
|
408
|
+
break;
|
|
409
|
+
case 1:
|
|
410
|
+
i += 8;
|
|
411
|
+
break;
|
|
412
|
+
case 2: {
|
|
413
|
+
const len = varint();
|
|
414
|
+
if (field === want) out.push(buf.subarray(i, i + len));
|
|
415
|
+
i += len;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
case 5:
|
|
419
|
+
i += 4;
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
throw new Error(`unsupported wire type in key ${key}`);
|
|
423
|
+
}
|
|
424
|
+
if (field === want) out.push(buf.subarray(start, i));
|
|
425
|
+
}
|
|
426
|
+
return out;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** A serialized `encore.runtime.v1.RuntimeConfig` exporting to `collector`,
|
|
430
|
+
* base64-encoded. */
|
|
431
|
+
/** A runtime config hosting `svc`, exporting spans to `collector` if
|
|
432
|
+
* `telemetry`. */
|
|
433
|
+
function runtimeConfig(collector: string, telemetry: boolean): string {
|
|
434
|
+
const varint = (n: number): number[] => {
|
|
435
|
+
const out: number[] = [];
|
|
436
|
+
for (;;) {
|
|
437
|
+
const b = n & 0x7f;
|
|
438
|
+
n >>>= 7;
|
|
439
|
+
out.push(n ? b | 0x80 : b);
|
|
440
|
+
if (!n) return out;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const msg = (field: number, body: number[]): number[] => [
|
|
444
|
+
...varint((field << 3) | 2),
|
|
445
|
+
...varint(body.length),
|
|
446
|
+
...body,
|
|
447
|
+
];
|
|
448
|
+
const str = (field: number, value: string): number[] =>
|
|
449
|
+
msg(field, [...new TextEncoder().encode(value)]);
|
|
450
|
+
|
|
451
|
+
// Environment{app_id=1, env_name=4}
|
|
452
|
+
const environment = [...str(1, 'app'), ...str(4, 'test')];
|
|
453
|
+
// Deployment{hosted_services=5, observability=7}; HostedService{name=1};
|
|
454
|
+
// Observability{tracing=1}; TracingProvider{otlp_grpc=11};
|
|
455
|
+
// OtlpGrpc{endpoint=1}
|
|
456
|
+
const provider = msg(11, str(1, collector));
|
|
457
|
+
const deployment = [
|
|
458
|
+
...msg(5, str(1, 'svc')),
|
|
459
|
+
...(telemetry ? msg(7, msg(1, provider)) : []),
|
|
460
|
+
];
|
|
461
|
+
// RuntimeConfig{environment=1, deployment=3}
|
|
462
|
+
const cfg = [...msg(1, environment), ...msg(3, deployment)];
|
|
463
|
+
return Buffer.from(Uint8Array.from(cfg)).toString('base64');
|
|
464
|
+
}
|