@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,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a config's value is built from: the JSON the runtime hands over,
|
|
3
|
+
* turned into what the declared type says, guided by the config's schema.
|
|
4
|
+
* Durations become {@link Duration}s, and the runtime's placeholder for each
|
|
5
|
+
* secret field becomes the secret itself. Kept apart from the runtime, so it
|
|
6
|
+
* can be tested without one.
|
|
7
|
+
*/
|
|
8
|
+
/** What a duration string looks like: one or more numbers, each with a unit. */
|
|
9
|
+
const DURATION = /^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$/;
|
|
10
|
+
const UNIT_MS = {
|
|
11
|
+
ns: 1e-6,
|
|
12
|
+
us: 1e-3,
|
|
13
|
+
µs: 1e-3,
|
|
14
|
+
ms: 1,
|
|
15
|
+
s: 1000,
|
|
16
|
+
m: 60000,
|
|
17
|
+
h: 3600000,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A length of time, written in config files as a number with a unit, or
|
|
21
|
+
* several: `"30s"`, `"250ms"`, `"1h30m"` (units `ns`, `us`, `ms`, `s`, `m`,
|
|
22
|
+
* `h`, as Go's `time.ParseDuration` reads them, without a sign).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* interface Checkout { paymentTimeout: Duration }
|
|
26
|
+
* setTimeout(retry, checkout().paymentTimeout.milliseconds);
|
|
27
|
+
*/
|
|
28
|
+
export class Duration {
|
|
29
|
+
ms;
|
|
30
|
+
constructor(ms) {
|
|
31
|
+
this.ms = ms;
|
|
32
|
+
}
|
|
33
|
+
/** Reads a duration string; throws on anything else. */
|
|
34
|
+
static parse(text) {
|
|
35
|
+
if (!DURATION.test(text)) {
|
|
36
|
+
throw new Error(`${JSON.stringify(text)} is not a duration, such as "30s", "250ms" or "1h30m"`);
|
|
37
|
+
}
|
|
38
|
+
let ms = 0;
|
|
39
|
+
for (const m of text.matchAll(/([0-9]+(?:\.[0-9]+)?)(ns|us|µs|ms|s|m|h)/g)) {
|
|
40
|
+
ms += parseFloat(m[1]) * UNIT_MS[m[2]];
|
|
41
|
+
}
|
|
42
|
+
// Whole nanoseconds, so that "0.1s" is 100ms rather than 100.00000000000001.
|
|
43
|
+
return new Duration(Math.round(ms * 1e6) / 1e6);
|
|
44
|
+
}
|
|
45
|
+
/** A duration of `ms` milliseconds. */
|
|
46
|
+
static ofMilliseconds(ms) {
|
|
47
|
+
if (!(ms >= 0)) {
|
|
48
|
+
throw new Error('a duration is not negative');
|
|
49
|
+
}
|
|
50
|
+
return new Duration(ms);
|
|
51
|
+
}
|
|
52
|
+
/** The duration in milliseconds: what `setTimeout` takes. */
|
|
53
|
+
get milliseconds() {
|
|
54
|
+
return this.ms;
|
|
55
|
+
}
|
|
56
|
+
/** The duration in seconds. */
|
|
57
|
+
get seconds() {
|
|
58
|
+
return this.ms / 1000;
|
|
59
|
+
}
|
|
60
|
+
/** As a config file writes it: `"1h30m"`, `"250ms"`, `"0s"`. */
|
|
61
|
+
toString() {
|
|
62
|
+
let ms = this.ms;
|
|
63
|
+
if (ms === 0)
|
|
64
|
+
return '0s';
|
|
65
|
+
let out = '';
|
|
66
|
+
for (const [unit, size] of [
|
|
67
|
+
['h', 3600000],
|
|
68
|
+
['m', 60000],
|
|
69
|
+
['s', 1000],
|
|
70
|
+
]) {
|
|
71
|
+
const n = Math.floor(ms / size);
|
|
72
|
+
if (n > 0) {
|
|
73
|
+
out += `${n}${unit}`;
|
|
74
|
+
ms -= n * size;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (ms > 0) {
|
|
78
|
+
// What is left is under a second.
|
|
79
|
+
out += Number.isInteger(ms) ? `${ms}ms` : `${Math.round(ms * 1e6)}ns`;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
toJSON() {
|
|
84
|
+
return this.toString();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The key of the runtime's placeholder for a secret field:
|
|
89
|
+
* `{"$encore_secret": "<name>"}`. The name alone says which secret it is: a
|
|
90
|
+
* secret's name has one scope across the app.
|
|
91
|
+
*/
|
|
92
|
+
export const PLACEHOLDER_KEY = '$encore_secret';
|
|
93
|
+
/**
|
|
94
|
+
* `value`, as the declared type has it: the JSON the runtime hands over, with
|
|
95
|
+
* each duration string `schema` marks made a {@link Duration}, and the
|
|
96
|
+
* runtime's placeholder at each secret field `schema` marks made the secret
|
|
97
|
+
* `secretOf` builds.
|
|
98
|
+
*/
|
|
99
|
+
export function build(schema, value, secretOf) {
|
|
100
|
+
return convert(schema, schema, value, secretOf, 0);
|
|
101
|
+
}
|
|
102
|
+
function resolve(root, schema) {
|
|
103
|
+
const ref = schema?.['$ref'];
|
|
104
|
+
if (typeof ref === 'string' && ref.startsWith('#/')) {
|
|
105
|
+
let node = root;
|
|
106
|
+
for (const token of ref.slice(2).split('/')) {
|
|
107
|
+
node = node?.[token.replace(/~1/g, '/').replace(/~0/g, '~')];
|
|
108
|
+
}
|
|
109
|
+
if (node && typeof node === 'object')
|
|
110
|
+
return node;
|
|
111
|
+
}
|
|
112
|
+
return schema;
|
|
113
|
+
}
|
|
114
|
+
function convert(root, schema, value, secretOf, depth) {
|
|
115
|
+
if (!schema || typeof schema !== 'object' || depth > 128) {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
schema = resolve(root, schema);
|
|
119
|
+
// Only a field the schema says reads a secret is one: anywhere else, a
|
|
120
|
+
// value shaped like a placeholder is just data, and must not reach a secret.
|
|
121
|
+
// The keyword is the secret's name: its scope is the config's.
|
|
122
|
+
const secret = schema['x-encore-secret'];
|
|
123
|
+
if (typeof secret === 'string') {
|
|
124
|
+
if (!isPlaceholder(value) || value[PLACEHOLDER_KEY] !== secret) {
|
|
125
|
+
// Never say what the value is: it may be a pasted secret.
|
|
126
|
+
throw new Error(`a secret field reads the secret ${secret}, and is not set in config`);
|
|
127
|
+
}
|
|
128
|
+
return secretOf(secret);
|
|
129
|
+
}
|
|
130
|
+
if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
|
|
131
|
+
return Duration.parse(value);
|
|
132
|
+
}
|
|
133
|
+
if (Array.isArray(schema.anyOf) && value !== null) {
|
|
134
|
+
// `T | null`: the value is a `T`.
|
|
135
|
+
const branch = schema.anyOf.find((b) => b?.type !== 'null');
|
|
136
|
+
return convert(root, branch, value, secretOf, depth + 1);
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(schema.oneOf)) {
|
|
139
|
+
return convert(root, branchOf(root, schema.oneOf, value), value, secretOf, depth + 1);
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
return value.map(item => convert(root, schema.items, item, secretOf, depth + 1));
|
|
143
|
+
}
|
|
144
|
+
if (value !== null && typeof value === 'object') {
|
|
145
|
+
const props = schema.properties ?? {};
|
|
146
|
+
const extra = typeof schema.additionalProperties === 'object'
|
|
147
|
+
? schema.additionalProperties
|
|
148
|
+
: undefined;
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const [k, v] of Object.entries(value)) {
|
|
151
|
+
out[k] = convert(root, props[k] ?? extra, v, secretOf, depth + 1);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
/** The branch of a `oneOf` a value is: the one whose constant tag it has. */
|
|
158
|
+
function branchOf(root, branches, value) {
|
|
159
|
+
const resolved = branches.map(b => resolve(root, b));
|
|
160
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
161
|
+
for (const b of resolved) {
|
|
162
|
+
const props = b?.properties;
|
|
163
|
+
if (!props)
|
|
164
|
+
continue;
|
|
165
|
+
const tagged = Object.entries(props).every(([k, p]) => !('const' in (p ?? {})) ||
|
|
166
|
+
value[k] === p.const);
|
|
167
|
+
if (tagged &&
|
|
168
|
+
Object.values(props).some((p) => 'const' in (p ?? {}))) {
|
|
169
|
+
return b;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
function isPlaceholder(value) {
|
|
176
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
177
|
+
return false;
|
|
178
|
+
const keys = Object.keys(value);
|
|
179
|
+
return keys.length === 1 && keys[0] === PLACEHOLDER_KEY;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../config/value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gFAAgF;AAChF,MAAM,QAAQ,GAAG,2CAA2C,CAAC;AAC7D,MAAM,OAAO,GAA2B;IACtC,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,KAAM;IACT,CAAC,EAAE,OAAS;CACb,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAQ;IAOF,EAAE,CAAS;IAE5B,YAAoB,EAAU;QAC5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED,wDAAwD;IACxD,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,uDAAuD,CAC/E,CAAC;QACJ,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAC3B,2CAA2C,CAC5C,EAAE,CAAC;YACF,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAE,CAAE,CAAC;QAC5C,CAAC;QACD,6EAA6E;QAC7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K,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,CAAC,EAAE,UAAU,CAAC;YAC5B,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CACxC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAgB,EAAE,EAAE,CACxB,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBACtB,KAAiC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CACpD,CAAC;YACF,IACE,MAAM;gBACN,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAC3D,CAAC;gBACD,OAAO,CAAC,CAAC;YACX,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DurationString } from '../types/mod.js';
|
|
2
|
+
/**
|
|
3
|
+
* The header with a run's idempotency key: an id that is the same each time
|
|
4
|
+
* Encore sends the run, as when it sends it again after a failure. A job
|
|
5
|
+
* that must not do its work twice can check whether it has seen the key
|
|
6
|
+
* before:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* app.post('/internal/cleanup', (req, res) => {
|
|
10
|
+
* const key = req.get(IDEMPOTENCY_KEY_HEADER);
|
|
11
|
+
* // ...
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Only Encore sends it: a gateway removes it from the requests it takes from
|
|
16
|
+
* clients. `encore cron trigger <name>` runs a job locally, as Encore runs it
|
|
17
|
+
* when it is due.
|
|
18
|
+
*/
|
|
19
|
+
export declare const IDEMPOTENCY_KEY_HEADER = "x-encore-cron-execution";
|
|
20
|
+
/**
|
|
21
|
+
* The header that says why a job runs: `scheduled`, when it was due, or
|
|
22
|
+
* `manual`, when someone asked for it to run now.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TRIGGER_HEADER = "x-encore-cron-trigger";
|
|
25
|
+
export declare class CronJob {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/**
|
|
28
|
+
* What the job was declared with. Read-only: Encore schedules the job from
|
|
29
|
+
* the declaration in the source, so a changed path would not be requested.
|
|
30
|
+
*/
|
|
31
|
+
readonly cfg: Readonly<CronJobConfig>;
|
|
32
|
+
constructor(name: string, cfg: CronJobConfig);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The configuration of a cron job: the path it requests and when.
|
|
36
|
+
*
|
|
37
|
+
* When the job is due, Encore sends a `POST` request for `path` to the service
|
|
38
|
+
* that declares the job. The fields must be literals: Encore reads them from
|
|
39
|
+
* the source.
|
|
40
|
+
*/
|
|
41
|
+
export type CronJobConfig = {
|
|
42
|
+
/** The path the job requests of its service, starting with `/`. */
|
|
43
|
+
path: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Tags that classify the cron job, for policies to read: written out as
|
|
47
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
48
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
49
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
50
|
+
*/
|
|
51
|
+
tags?: Record<string, string>;
|
|
52
|
+
} & ({
|
|
53
|
+
every: DurationString;
|
|
54
|
+
} | {
|
|
55
|
+
schedule: string;
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../cron/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,cAAc,0BAA0B,CAAC;AAEtD,qBAAa,OAAO;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;gBAC1B,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa;CAO7C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,GAAG,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC"}
|
package/dist/cron/mod.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The header with a run's idempotency key: an id that is the same each time
|
|
3
|
+
* Encore sends the run, as when it sends it again after a failure. A job
|
|
4
|
+
* that must not do its work twice can check whether it has seen the key
|
|
5
|
+
* before:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* app.post('/internal/cleanup', (req, res) => {
|
|
9
|
+
* const key = req.get(IDEMPOTENCY_KEY_HEADER);
|
|
10
|
+
* // ...
|
|
11
|
+
* });
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Only Encore sends it: a gateway removes it from the requests it takes from
|
|
15
|
+
* clients. `encore cron trigger <name>` runs a job locally, as Encore runs it
|
|
16
|
+
* when it is due.
|
|
17
|
+
*/
|
|
18
|
+
export const IDEMPOTENCY_KEY_HEADER = 'x-encore-cron-execution';
|
|
19
|
+
/**
|
|
20
|
+
* The header that says why a job runs: `scheduled`, when it was due, or
|
|
21
|
+
* `manual`, when someone asked for it to run now.
|
|
22
|
+
*/
|
|
23
|
+
export const TRIGGER_HEADER = 'x-encore-cron-trigger';
|
|
24
|
+
export class CronJob {
|
|
25
|
+
name;
|
|
26
|
+
/**
|
|
27
|
+
* What the job was declared with. Read-only: Encore schedules the job from
|
|
28
|
+
* the declaration in the source, so a changed path would not be requested.
|
|
29
|
+
*/
|
|
30
|
+
cfg;
|
|
31
|
+
constructor(name, cfg) {
|
|
32
|
+
this.name = name;
|
|
33
|
+
// Frozen as well as typed `readonly`, so a write throws in an app that
|
|
34
|
+
// runs without `tsc` checking it.
|
|
35
|
+
this.cfg = Object.freeze({ ...cfg });
|
|
36
|
+
Object.freeze(this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../cron/mod.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,yBAAyB,CAAC;AAEhE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAEtD,MAAM,OAAO,OAAO;IACT,IAAI,CAAS;IACtB;;;OAGG;IACM,GAAG,CAA0B;IACtC,YAAY,IAAY,EAAE,GAAkB;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,uEAAuE;QACvE,kCAAkC;QAClC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,GAAG,GAAG,EAAC,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the app's frontends are reached.
|
|
3
|
+
*
|
|
4
|
+
* {@link url} is a frontend's URL in the environment the code runs in, as to
|
|
5
|
+
* send a user there or to build a link to one of its pages:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import * as frontends from '@encore.dev/sdk/frontends';
|
|
9
|
+
*
|
|
10
|
+
* const reset = `${frontends.url('web')}/reset?token=${token}`;
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Looking a frontend's URL up links the calling service to it. Encore reads
|
|
14
|
+
* the link from the code, as it reads which services a service depends on: so
|
|
15
|
+
* the name must be a string literal, written as the frontend declares it, the
|
|
16
|
+
* function must be called directly rather than passed around, and the call
|
|
17
|
+
* must be in a service.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The URL `frontend` is reached at in this environment, without a trailing
|
|
23
|
+
* slash: a path goes after it, `` `${url("web")}/reset` ``. It is the first of
|
|
24
|
+
* the frontend's origins, as {@link appMeta} lists them.
|
|
25
|
+
*
|
|
26
|
+
* The name is the one the frontend is declared with, in its
|
|
27
|
+
* `encore.frontend.json` or as the service hosting it: `web_app` does not find
|
|
28
|
+
* `web-app`.
|
|
29
|
+
*
|
|
30
|
+
* Throws if the runtime knows no URL for `frontend`: the app has no frontend of
|
|
31
|
+
* that name, which Encore's parser reports, or the environment gives it no
|
|
32
|
+
* origins.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* import {url} from "@encore.dev/sdk/frontends";
|
|
36
|
+
* const home = url("web");
|
|
37
|
+
*/
|
|
38
|
+
export declare function url(frontend: string): string;
|
|
39
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAS5C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the app's frontends are reached.
|
|
3
|
+
*
|
|
4
|
+
* {@link url} is a frontend's URL in the environment the code runs in, as to
|
|
5
|
+
* send a user there or to build a link to one of its pages:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import * as frontends from '@encore.dev/sdk/frontends';
|
|
9
|
+
*
|
|
10
|
+
* const reset = `${frontends.url('web')}/reset?token=${token}`;
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Looking a frontend's URL up links the calling service to it. Encore reads
|
|
14
|
+
* the link from the code, as it reads which services a service depends on: so
|
|
15
|
+
* the name must be a string literal, written as the frontend declares it, the
|
|
16
|
+
* function must be called directly rather than passed around, and the call
|
|
17
|
+
* must be in a service.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { appMeta } from '../app_meta.js';
|
|
22
|
+
/**
|
|
23
|
+
* The URL `frontend` is reached at in this environment, without a trailing
|
|
24
|
+
* slash: a path goes after it, `` `${url("web")}/reset` ``. It is the first of
|
|
25
|
+
* the frontend's origins, as {@link appMeta} lists them.
|
|
26
|
+
*
|
|
27
|
+
* The name is the one the frontend is declared with, in its
|
|
28
|
+
* `encore.frontend.json` or as the service hosting it: `web_app` does not find
|
|
29
|
+
* `web-app`.
|
|
30
|
+
*
|
|
31
|
+
* Throws if the runtime knows no URL for `frontend`: the app has no frontend of
|
|
32
|
+
* that name, which Encore's parser reports, or the environment gives it no
|
|
33
|
+
* origins.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import {url} from "@encore.dev/sdk/frontends";
|
|
37
|
+
* const home = url("web");
|
|
38
|
+
*/
|
|
39
|
+
export function url(frontend) {
|
|
40
|
+
const found = appMeta().frontends[frontend]?.origins[0]?.replace(/\/+$/, '');
|
|
41
|
+
if (!found) {
|
|
42
|
+
throw new Error(`encore: no URL is known for frontend ${JSON.stringify(frontend)}: the app has no ` +
|
|
43
|
+
'frontend of that name, or the environment gives it no origins');
|
|
44
|
+
}
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,GAAG,CAAC,QAAgB;IAClC,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,wCAAwC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,mBAAmB;YACjF,+DAA+D,CAClE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code of an Encore error, which a {@link reject}ion answers with: what
|
|
3
|
+
* went wrong, as Encore's clients read it, and the HTTP status the answer
|
|
4
|
+
* has. They are the codes a service's errors answer with.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ErrCode {
|
|
7
|
+
/** 499. */
|
|
8
|
+
Canceled = "canceled",
|
|
9
|
+
/** 500. */
|
|
10
|
+
Unknown = "unknown",
|
|
11
|
+
/** 400. */
|
|
12
|
+
InvalidArgument = "invalid_argument",
|
|
13
|
+
/** 504. */
|
|
14
|
+
DeadlineExceeded = "deadline_exceeded",
|
|
15
|
+
/** 404. */
|
|
16
|
+
NotFound = "not_found",
|
|
17
|
+
/** 409. */
|
|
18
|
+
AlreadyExists = "already_exists",
|
|
19
|
+
/** 403. */
|
|
20
|
+
PermissionDenied = "permission_denied",
|
|
21
|
+
/** 429. */
|
|
22
|
+
ResourceExhausted = "resource_exhausted",
|
|
23
|
+
/** 400. */
|
|
24
|
+
FailedPrecondition = "failed_precondition",
|
|
25
|
+
/** 409. */
|
|
26
|
+
Aborted = "aborted",
|
|
27
|
+
/** 400. */
|
|
28
|
+
OutOfRange = "out_of_range",
|
|
29
|
+
/** 501. */
|
|
30
|
+
Unimplemented = "unimplemented",
|
|
31
|
+
/** 500. */
|
|
32
|
+
Internal = "internal",
|
|
33
|
+
/** 503. */
|
|
34
|
+
Unavailable = "unavailable",
|
|
35
|
+
/** 500. */
|
|
36
|
+
DataLoss = "data_loss",
|
|
37
|
+
/** 401. */
|
|
38
|
+
Unauthenticated = "unauthenticated"
|
|
39
|
+
}
|
|
40
|
+
/** The HTTP status an answer with `code` has: 401 for
|
|
41
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}, and so
|
|
42
|
+
* on. */
|
|
43
|
+
export declare function httpStatus(code: ErrCode): number;
|
|
44
|
+
/** Response headers: a record, or pairs for a header sent more than once. */
|
|
45
|
+
export type Headers = Record<string, string> | ReadonlyArray<[string, string]>;
|
|
46
|
+
/**
|
|
47
|
+
* A Middleware's answer to a request it does not let through: `onRequest`
|
|
48
|
+
* returns or throws one, and the gateway writes it to the client, with the
|
|
49
|
+
* gateway's CORS headers, rather than forwarding the request.
|
|
50
|
+
*
|
|
51
|
+
* {@link reject} answers as a service answers with an Encore error, which
|
|
52
|
+
* Encore's clients read as one; {@link respond} answers with any response,
|
|
53
|
+
* such as a redirect.
|
|
54
|
+
*/
|
|
55
|
+
export declare class Rejection extends Error {
|
|
56
|
+
name: string;
|
|
57
|
+
/** The HTTP status the request is answered with. */
|
|
58
|
+
readonly status: number;
|
|
59
|
+
/** The Encore error code, for a {@link reject}; undefined for a
|
|
60
|
+
* {@link respond}. */
|
|
61
|
+
readonly code: ErrCode | undefined;
|
|
62
|
+
/** What went wrong, for a {@link reject}; empty for a {@link respond}. */
|
|
63
|
+
readonly errorMessage: string;
|
|
64
|
+
/** The response's headers, as name and value pairs. */
|
|
65
|
+
readonly headers: Array<[string, string]>;
|
|
66
|
+
/** The response's body, for a {@link respond}. */
|
|
67
|
+
readonly body: Uint8Array | undefined;
|
|
68
|
+
/** @internal Made by {@link reject} and {@link respond}. */
|
|
69
|
+
constructor(status: number, code: ErrCode | undefined, message: string, headers: Array<[string, string]>, body: Uint8Array | undefined);
|
|
70
|
+
/** Adds a header to the response, as `Retry-After` to a 429, and returns
|
|
71
|
+
* the rejection. */
|
|
72
|
+
withHeader(name: string, value: string): this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Answers a request with an Encore error with `code` and `message`, and the
|
|
76
|
+
* HTTP status of the code: 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
77
|
+
* {@link ErrCode.PermissionDenied}, 429 for
|
|
78
|
+
* {@link ErrCode.ResourceExhausted}, and so on.
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function reject(code: ErrCode, message: string): Rejection;
|
|
85
|
+
/**
|
|
86
|
+
* Answers a request with `status`, `headers` and `body` as they are, as a
|
|
87
|
+
* redirect to sign in:
|
|
88
|
+
*
|
|
89
|
+
* ```typescript
|
|
90
|
+
* return gateway.respond(302, { location: "/login" });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function respond(status: number, headers?: Headers, body?: Uint8Array | string): Rejection;
|
|
94
|
+
/**
|
|
95
|
+
* The gateway cannot be served: a Middleware is invalid, the process is not
|
|
96
|
+
* a gateway program Encore runs, or the gateway is already served.
|
|
97
|
+
*/
|
|
98
|
+
export declare class GatewayError extends Error {
|
|
99
|
+
name: string;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,OAAO;IACjB,WAAW;IACX,QAAQ,aAAa;IACrB,WAAW;IACX,OAAO,YAAY;IACnB,WAAW;IACX,eAAe,qBAAqB;IACpC,WAAW;IACX,gBAAgB,sBAAsB;IACtC,WAAW;IACX,QAAQ,cAAc;IACtB,WAAW;IACX,aAAa,mBAAmB;IAChC,WAAW;IACX,gBAAgB,sBAAsB;IACtC,WAAW;IACX,iBAAiB,uBAAuB;IACxC,WAAW;IACX,kBAAkB,wBAAwB;IAC1C,WAAW;IACX,OAAO,YAAY;IACnB,WAAW;IACX,UAAU,iBAAiB;IAC3B,WAAW;IACX,aAAa,kBAAkB;IAC/B,WAAW;IACX,QAAQ,aAAa;IACrB,WAAW;IACX,WAAW,gBAAgB;IAC3B,WAAW;IACX,QAAQ,cAAc;IACtB,WAAW;IACX,eAAe,oBAAoB;CACpC;AAqBD;;SAES;AACT,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,6EAA6E;AAC7E,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE/E;;;;;;;;GAQG;AACH,qBAAa,SAAU,SAAQ,KAAK;IACzB,IAAI,SAAe;IAE5B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;0BACsB;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAEtC,4DAA4D;gBAE1D,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAChC,IAAI,EAAE,UAAU,GAAG,SAAS;IAa9B;wBACoB;IACpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAI9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAKhE;AAMD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAY,EACrB,IAAI,GAAE,UAAU,GAAG,MAAyB,GAC3C,SAAS,CAUX;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code of an Encore error, which a {@link reject}ion answers with: what
|
|
3
|
+
* went wrong, as Encore's clients read it, and the HTTP status the answer
|
|
4
|
+
* has. They are the codes a service's errors answer with.
|
|
5
|
+
*/
|
|
6
|
+
export var ErrCode;
|
|
7
|
+
(function (ErrCode) {
|
|
8
|
+
/** 499. */
|
|
9
|
+
ErrCode["Canceled"] = "canceled";
|
|
10
|
+
/** 500. */
|
|
11
|
+
ErrCode["Unknown"] = "unknown";
|
|
12
|
+
/** 400. */
|
|
13
|
+
ErrCode["InvalidArgument"] = "invalid_argument";
|
|
14
|
+
/** 504. */
|
|
15
|
+
ErrCode["DeadlineExceeded"] = "deadline_exceeded";
|
|
16
|
+
/** 404. */
|
|
17
|
+
ErrCode["NotFound"] = "not_found";
|
|
18
|
+
/** 409. */
|
|
19
|
+
ErrCode["AlreadyExists"] = "already_exists";
|
|
20
|
+
/** 403. */
|
|
21
|
+
ErrCode["PermissionDenied"] = "permission_denied";
|
|
22
|
+
/** 429. */
|
|
23
|
+
ErrCode["ResourceExhausted"] = "resource_exhausted";
|
|
24
|
+
/** 400. */
|
|
25
|
+
ErrCode["FailedPrecondition"] = "failed_precondition";
|
|
26
|
+
/** 409. */
|
|
27
|
+
ErrCode["Aborted"] = "aborted";
|
|
28
|
+
/** 400. */
|
|
29
|
+
ErrCode["OutOfRange"] = "out_of_range";
|
|
30
|
+
/** 501. */
|
|
31
|
+
ErrCode["Unimplemented"] = "unimplemented";
|
|
32
|
+
/** 500. */
|
|
33
|
+
ErrCode["Internal"] = "internal";
|
|
34
|
+
/** 503. */
|
|
35
|
+
ErrCode["Unavailable"] = "unavailable";
|
|
36
|
+
/** 500. */
|
|
37
|
+
ErrCode["DataLoss"] = "data_loss";
|
|
38
|
+
/** 401. */
|
|
39
|
+
ErrCode["Unauthenticated"] = "unauthenticated";
|
|
40
|
+
})(ErrCode || (ErrCode = {}));
|
|
41
|
+
const STATUS = {
|
|
42
|
+
[ErrCode.Canceled]: 499,
|
|
43
|
+
[ErrCode.Unknown]: 500,
|
|
44
|
+
[ErrCode.InvalidArgument]: 400,
|
|
45
|
+
[ErrCode.DeadlineExceeded]: 504,
|
|
46
|
+
[ErrCode.NotFound]: 404,
|
|
47
|
+
[ErrCode.AlreadyExists]: 409,
|
|
48
|
+
[ErrCode.PermissionDenied]: 403,
|
|
49
|
+
[ErrCode.ResourceExhausted]: 429,
|
|
50
|
+
[ErrCode.FailedPrecondition]: 400,
|
|
51
|
+
[ErrCode.Aborted]: 409,
|
|
52
|
+
[ErrCode.OutOfRange]: 400,
|
|
53
|
+
[ErrCode.Unimplemented]: 501,
|
|
54
|
+
[ErrCode.Internal]: 500,
|
|
55
|
+
[ErrCode.Unavailable]: 503,
|
|
56
|
+
[ErrCode.DataLoss]: 500,
|
|
57
|
+
[ErrCode.Unauthenticated]: 401,
|
|
58
|
+
};
|
|
59
|
+
/** The HTTP status an answer with `code` has: 401 for
|
|
60
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}, and so
|
|
61
|
+
* on. */
|
|
62
|
+
export function httpStatus(code) {
|
|
63
|
+
return STATUS[code];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A Middleware's answer to a request it does not let through: `onRequest`
|
|
67
|
+
* returns or throws one, and the gateway writes it to the client, with the
|
|
68
|
+
* gateway's CORS headers, rather than forwarding the request.
|
|
69
|
+
*
|
|
70
|
+
* {@link reject} answers as a service answers with an Encore error, which
|
|
71
|
+
* Encore's clients read as one; {@link respond} answers with any response,
|
|
72
|
+
* such as a redirect.
|
|
73
|
+
*/
|
|
74
|
+
export class Rejection extends Error {
|
|
75
|
+
name = 'Rejection';
|
|
76
|
+
/** The HTTP status the request is answered with. */
|
|
77
|
+
status;
|
|
78
|
+
/** The Encore error code, for a {@link reject}; undefined for a
|
|
79
|
+
* {@link respond}. */
|
|
80
|
+
code;
|
|
81
|
+
/** What went wrong, for a {@link reject}; empty for a {@link respond}. */
|
|
82
|
+
errorMessage;
|
|
83
|
+
/** The response's headers, as name and value pairs. */
|
|
84
|
+
headers;
|
|
85
|
+
/** The response's body, for a {@link respond}. */
|
|
86
|
+
body;
|
|
87
|
+
/** @internal Made by {@link reject} and {@link respond}. */
|
|
88
|
+
constructor(status, code, message, headers, body) {
|
|
89
|
+
super(`rejected with ${status}` +
|
|
90
|
+
(code !== undefined ? ` ${code}: ${message}` : ''));
|
|
91
|
+
this.status = status;
|
|
92
|
+
this.code = code;
|
|
93
|
+
this.errorMessage = message;
|
|
94
|
+
this.headers = headers;
|
|
95
|
+
this.body = body;
|
|
96
|
+
}
|
|
97
|
+
/** Adds a header to the response, as `Retry-After` to a 429, and returns
|
|
98
|
+
* the rejection. */
|
|
99
|
+
withHeader(name, value) {
|
|
100
|
+
this.headers.push([name, value]);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Answers a request with an Encore error with `code` and `message`, and the
|
|
106
|
+
* HTTP status of the code: 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
107
|
+
* {@link ErrCode.PermissionDenied}, 429 for
|
|
108
|
+
* {@link ErrCode.ResourceExhausted}, and so on.
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function reject(code, message) {
|
|
115
|
+
if (!(code in REVERSE)) {
|
|
116
|
+
throw new TypeError(`${String(code)} is not an ErrCode`);
|
|
117
|
+
}
|
|
118
|
+
return new Rejection(STATUS[code], code, message, [], undefined);
|
|
119
|
+
}
|
|
120
|
+
const REVERSE = Object.fromEntries(Object.values(ErrCode).map(c => [c, true]));
|
|
121
|
+
/**
|
|
122
|
+
* Answers a request with `status`, `headers` and `body` as they are, as a
|
|
123
|
+
* redirect to sign in:
|
|
124
|
+
*
|
|
125
|
+
* ```typescript
|
|
126
|
+
* return gateway.respond(302, { location: "/login" });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function respond(status, headers = [], body = new Uint8Array()) {
|
|
130
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
131
|
+
throw new RangeError(`status ${status} is not an HTTP status`);
|
|
132
|
+
}
|
|
133
|
+
const pairs = Array.isArray(headers)
|
|
134
|
+
? headers.map(([n, v]) => [n, v])
|
|
135
|
+
: Object.entries(headers);
|
|
136
|
+
const bytes = typeof body === 'string' ? new TextEncoder().encode(body) : body;
|
|
137
|
+
return new Rejection(status, undefined, '', pairs, bytes);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The gateway cannot be served: a Middleware is invalid, the process is not
|
|
141
|
+
* a gateway program Encore runs, or the gateway is already served.
|
|
142
|
+
*/
|
|
143
|
+
export class GatewayError extends Error {
|
|
144
|
+
name = 'GatewayError';
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAiCX;AAjCD,WAAY,OAAO;IACjB,WAAW;IACX,gCAAqB,CAAA;IACrB,WAAW;IACX,8BAAmB,CAAA;IACnB,WAAW;IACX,+CAAoC,CAAA;IACpC,WAAW;IACX,iDAAsC,CAAA;IACtC,WAAW;IACX,iCAAsB,CAAA;IACtB,WAAW;IACX,2CAAgC,CAAA;IAChC,WAAW;IACX,iDAAsC,CAAA;IACtC,WAAW;IACX,mDAAwC,CAAA;IACxC,WAAW;IACX,qDAA0C,CAAA;IAC1C,WAAW;IACX,8BAAmB,CAAA;IACnB,WAAW;IACX,sCAA2B,CAAA;IAC3B,WAAW;IACX,0CAA+B,CAAA;IAC/B,WAAW;IACX,gCAAqB,CAAA;IACrB,WAAW;IACX,sCAA2B,CAAA;IAC3B,WAAW;IACX,iCAAsB,CAAA;IACtB,WAAW;IACX,8CAAmC,CAAA;AACrC,CAAC,EAjCW,OAAO,KAAP,OAAO,QAiClB;AAED,MAAM,MAAM,GAA4B;IACtC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG;IACvB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG;IACtB,CAAC,OAAO,CAAC,eAAe,CAAC,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