@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,173 @@
|
|
|
1
|
+
import * as runtime from '../internal/runtime/mod';
|
|
2
|
+
import {lookupScope, testMode} from '../internal/testing/scope';
|
|
3
|
+
import {StringLiteral} from '../internal/utils/constraints';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Secret represents a single secret value that is loaded
|
|
7
|
+
* into the application. It is strongly typed for that secret,
|
|
8
|
+
* so that you can write functions which expect a specific one.
|
|
9
|
+
*
|
|
10
|
+
* You can use {@link AnySecret} to represent any secret without knowing
|
|
11
|
+
* it's name.
|
|
12
|
+
*
|
|
13
|
+
* `T` is the type of the secret's value. Only `string` is supported.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* function doFoo(s: Secret<"foo">): void {
|
|
18
|
+
* const foo = s();
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
export interface Secret<Name extends string, T extends string = string> {
|
|
22
|
+
/**
|
|
23
|
+
* Returns the value of the secret.
|
|
24
|
+
*
|
|
25
|
+
* The value is read once per process and does not change while it runs:
|
|
26
|
+
* a new value reaches a service when it restarts.
|
|
27
|
+
*
|
|
28
|
+
* Throws an `Error` naming the secret when it has no value, in every
|
|
29
|
+
* environment, local development too.
|
|
30
|
+
*/
|
|
31
|
+
(): T;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The name of the secret.
|
|
35
|
+
*/
|
|
36
|
+
readonly name: Name;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Marks the type as an Encore secret, for Encore's parser, which reads a
|
|
40
|
+
* config's type to know which of its fields read a secret. Never set.
|
|
41
|
+
*
|
|
42
|
+
* As a field of a config's type, `apiKey: Secret<"StripeKey">` reads the
|
|
43
|
+
* secret of that name in the config's own scope: the declaring service's
|
|
44
|
+
* own for a service config, the app's for a shared or global one. The
|
|
45
|
+
* secret is declared as any other is, with {@link secret}.
|
|
46
|
+
*/
|
|
47
|
+
readonly '~encore.secret'?: true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* AnySecret is a type which can be used to represent any {@link Secret}
|
|
52
|
+
* without knowing its name.
|
|
53
|
+
*/
|
|
54
|
+
export type AnySecret = Secret<string>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The options a secret is declared with. Read by Encore's parser, so the
|
|
58
|
+
* values must be literals.
|
|
59
|
+
*/
|
|
60
|
+
export interface SecretOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Who the secret belongs to, written as a string literal for Encore to
|
|
63
|
+
* read:
|
|
64
|
+
*
|
|
65
|
+
* - `"service"`, the default: the service that declares it. Two services
|
|
66
|
+
* may each declare a secret of the same name and hold different values
|
|
67
|
+
* in them, so adding a secret to one service can never collide with, or
|
|
68
|
+
* silently reuse, a name another service already took. The declaration
|
|
69
|
+
* must therefore live inside a service; Encore reports an error
|
|
70
|
+
* otherwise.
|
|
71
|
+
* - `"shared"`: the whole app, readable from any service, each that reads
|
|
72
|
+
* it recorded as using it. It may be declared outside a service. Use it
|
|
73
|
+
* only for a value several services genuinely share: a shared secret
|
|
74
|
+
* couples every service that reads it, and widening a secret's scope
|
|
75
|
+
* later is easier than narrowing it.
|
|
76
|
+
* - `"global"`: the whole app, with one value available to every service
|
|
77
|
+
* without being granted. It may be declared outside a service.
|
|
78
|
+
*/
|
|
79
|
+
scope?: 'service' | 'shared' | 'global';
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* What the secret is, who issues it and how to rotate it, shown wherever its
|
|
83
|
+
* values are managed. The declaration's doc comment wins when there is one.
|
|
84
|
+
*/
|
|
85
|
+
description?: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Tags that classify the secret, for policies to read: written out as
|
|
89
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
90
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
91
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
92
|
+
*/
|
|
93
|
+
tags?: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* secret declares a {@link Secret}, by default belonging to the service that
|
|
98
|
+
* declares it. See {@link SecretOptions.scope} for a secret of the whole app.
|
|
99
|
+
*
|
|
100
|
+
* A doc comment on the declaration, or a `description` option, is shown
|
|
101
|
+
* wherever the secret's values are managed.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* // Loading a single secret.
|
|
106
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
107
|
+
* const foo = secret("foo");
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* // A secret several services share.
|
|
113
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
114
|
+
* const signingKey = secret("SigningKey", {scope: "shared"});
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* // Documenting it.
|
|
120
|
+
* const apiKey = secret("ApiKey", {
|
|
121
|
+
* description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function secret<Name extends string>(
|
|
126
|
+
name: StringLiteral<Name>,
|
|
127
|
+
// The options are Encore's parser's to read: a secret is read by name
|
|
128
|
+
// whatever its scope, a name having one scope across the app.
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
+
opts?: SecretOptions,
|
|
131
|
+
): Secret<Name> {
|
|
132
|
+
return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The secret a config's secret field reads: what the runtime's placeholder
|
|
137
|
+
* for the field stands for. A secret name has one scope across the app, so it
|
|
138
|
+
* is read by name whatever the config's scope. Internal to the config module.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export function secretOfField(name: string): AnySecret {
|
|
143
|
+
return makeSecret<AnySecret>(name, runtime.RT.secret(name));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Builds the secret handle around an already-resolved implementation. `impl`
|
|
148
|
+
* is null when the runtime config gives the service no secret of that name.
|
|
149
|
+
*/
|
|
150
|
+
function makeSecret<S extends AnySecret>(
|
|
151
|
+
name: string,
|
|
152
|
+
impl: ReturnType<typeof runtime.RT.secret>,
|
|
153
|
+
): S {
|
|
154
|
+
const secretObj = () => {
|
|
155
|
+
// The value the current test gave it, if it did.
|
|
156
|
+
const override = testMode ? lookupScope()?.native.secret(name) : null;
|
|
157
|
+
if (override != null) return override.toString('utf8');
|
|
158
|
+
if (impl === null) {
|
|
159
|
+
throw new Error(`secret ${name} is not set`);
|
|
160
|
+
}
|
|
161
|
+
return impl.cached();
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
secretObj.toString = () => {
|
|
165
|
+
if (impl === null) {
|
|
166
|
+
return `Secret<${name}>(not set)`;
|
|
167
|
+
}
|
|
168
|
+
return `Secret<${name}>(*********)`;
|
|
169
|
+
};
|
|
170
|
+
Object.defineProperty(secretObj, 'name', {value: name});
|
|
171
|
+
|
|
172
|
+
return secretObj as unknown as S;
|
|
173
|
+
}
|
package/config/value.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
|
|
9
|
+
/** What a duration string looks like: one or more numbers, each with a unit. */
|
|
10
|
+
const DURATION = /^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$/;
|
|
11
|
+
const UNIT_MS: Record<string, number> = {
|
|
12
|
+
ns: 1e-6,
|
|
13
|
+
us: 1e-3,
|
|
14
|
+
µs: 1e-3,
|
|
15
|
+
ms: 1,
|
|
16
|
+
s: 1000,
|
|
17
|
+
m: 60_000,
|
|
18
|
+
h: 3_600_000,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A length of time, written in config files as a number with a unit, or
|
|
23
|
+
* several: `"30s"`, `"250ms"`, `"1h30m"` (units `ns`, `us`, `ms`, `s`, `m`,
|
|
24
|
+
* `h`, as Go's `time.ParseDuration` reads them, without a sign).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* interface Checkout { paymentTimeout: Duration }
|
|
28
|
+
* setTimeout(retry, checkout().paymentTimeout.milliseconds);
|
|
29
|
+
*/
|
|
30
|
+
export class Duration {
|
|
31
|
+
/**
|
|
32
|
+
* Marks the type as Encore's duration, for Encore's parser, which reads a
|
|
33
|
+
* config's type to know what its files may hold. Never set.
|
|
34
|
+
*/
|
|
35
|
+
declare readonly '~encore.duration'?: true;
|
|
36
|
+
|
|
37
|
+
private readonly ms: number;
|
|
38
|
+
|
|
39
|
+
private constructor(ms: number) {
|
|
40
|
+
this.ms = ms;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Reads a duration string; throws on anything else. */
|
|
44
|
+
static parse(text: string): Duration {
|
|
45
|
+
if (!DURATION.test(text)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`${JSON.stringify(text)} is not a duration, such as "30s", "250ms" or "1h30m"`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
let ms = 0;
|
|
51
|
+
for (const m of text.matchAll(
|
|
52
|
+
/([0-9]+(?:\.[0-9]+)?)(ns|us|µs|ms|s|m|h)/g,
|
|
53
|
+
)) {
|
|
54
|
+
ms += parseFloat(m[1]!) * UNIT_MS[m[2]!]!;
|
|
55
|
+
}
|
|
56
|
+
// Whole nanoseconds, so that "0.1s" is 100ms rather than 100.00000000000001.
|
|
57
|
+
return new Duration(Math.round(ms * 1e6) / 1e6);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A duration of `ms` milliseconds. */
|
|
61
|
+
static ofMilliseconds(ms: number): Duration {
|
|
62
|
+
if (!(ms >= 0)) {
|
|
63
|
+
throw new Error('a duration is not negative');
|
|
64
|
+
}
|
|
65
|
+
return new Duration(ms);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The duration in milliseconds: what `setTimeout` takes. */
|
|
69
|
+
get milliseconds(): number {
|
|
70
|
+
return this.ms;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The duration in seconds. */
|
|
74
|
+
get seconds(): number {
|
|
75
|
+
return this.ms / 1000;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** As a config file writes it: `"1h30m"`, `"250ms"`, `"0s"`. */
|
|
79
|
+
toString(): string {
|
|
80
|
+
let ms = this.ms;
|
|
81
|
+
if (ms === 0) return '0s';
|
|
82
|
+
let out = '';
|
|
83
|
+
for (const [unit, size] of [
|
|
84
|
+
['h', 3_600_000],
|
|
85
|
+
['m', 60_000],
|
|
86
|
+
['s', 1000],
|
|
87
|
+
] as const) {
|
|
88
|
+
const n = Math.floor(ms / size);
|
|
89
|
+
if (n > 0) {
|
|
90
|
+
out += `${n}${unit}`;
|
|
91
|
+
ms -= n * size;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (ms > 0) {
|
|
95
|
+
// What is left is under a second.
|
|
96
|
+
out += Number.isInteger(ms) ? `${ms}ms` : `${Math.round(ms * 1e6)}ns`;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
toJSON(): string {
|
|
102
|
+
return this.toString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The key of the runtime's placeholder for a secret field:
|
|
108
|
+
* `{"$encore_secret": "<name>"}`. The name alone says which secret it is: a
|
|
109
|
+
* secret's name has one scope across the app.
|
|
110
|
+
*/
|
|
111
|
+
export const PLACEHOLDER_KEY = '$encore_secret';
|
|
112
|
+
|
|
113
|
+
/** Builds the secret a placeholder stands for, by its name. */
|
|
114
|
+
export type SecretOf = (name: string) => unknown;
|
|
115
|
+
|
|
116
|
+
type Schema = Record<string, any>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `value`, as the declared type has it: the JSON the runtime hands over, with
|
|
120
|
+
* each duration string `schema` marks made a {@link Duration}, and the
|
|
121
|
+
* runtime's placeholder at each secret field `schema` marks made the secret
|
|
122
|
+
* `secretOf` builds.
|
|
123
|
+
*/
|
|
124
|
+
export function build(
|
|
125
|
+
schema: Schema,
|
|
126
|
+
value: unknown,
|
|
127
|
+
secretOf: SecretOf,
|
|
128
|
+
): unknown {
|
|
129
|
+
return convert(schema, schema, value, secretOf, 0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function resolve(root: Schema, schema: Schema): Schema {
|
|
133
|
+
const ref = schema?.['$ref'];
|
|
134
|
+
if (typeof ref === 'string' && ref.startsWith('#/')) {
|
|
135
|
+
let node: any = root;
|
|
136
|
+
for (const token of ref.slice(2).split('/')) {
|
|
137
|
+
node = node?.[token.replace(/~1/g, '/').replace(/~0/g, '~')];
|
|
138
|
+
}
|
|
139
|
+
if (node && typeof node === 'object') return node;
|
|
140
|
+
}
|
|
141
|
+
return schema;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function convert(
|
|
145
|
+
root: Schema,
|
|
146
|
+
schema: Schema | undefined,
|
|
147
|
+
value: unknown,
|
|
148
|
+
secretOf: SecretOf,
|
|
149
|
+
depth: number,
|
|
150
|
+
): unknown {
|
|
151
|
+
if (!schema || typeof schema !== 'object' || depth > 128) {
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
schema = resolve(root, schema);
|
|
155
|
+
|
|
156
|
+
// Only a field the schema says reads a secret is one: anywhere else, a
|
|
157
|
+
// value shaped like a placeholder is just data, and must not reach a secret.
|
|
158
|
+
// The keyword is the secret's name: its scope is the config's.
|
|
159
|
+
const secret = schema['x-encore-secret'];
|
|
160
|
+
if (typeof secret === 'string') {
|
|
161
|
+
if (!isPlaceholder(value) || value[PLACEHOLDER_KEY] !== secret) {
|
|
162
|
+
// Never say what the value is: it may be a pasted secret.
|
|
163
|
+
throw new Error(
|
|
164
|
+
`a secret field reads the secret ${secret}, and is not set in config`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return secretOf(secret);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
|
|
171
|
+
return Duration.parse(value);
|
|
172
|
+
}
|
|
173
|
+
if (Array.isArray(schema.anyOf) && value !== null) {
|
|
174
|
+
// `T | null`: the value is a `T`.
|
|
175
|
+
const branch = schema.anyOf.find((b: Schema) => b?.type !== 'null');
|
|
176
|
+
return convert(root, branch, value, secretOf, depth + 1);
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(schema.oneOf)) {
|
|
179
|
+
return convert(
|
|
180
|
+
root,
|
|
181
|
+
branchOf(root, schema.oneOf, value),
|
|
182
|
+
value,
|
|
183
|
+
secretOf,
|
|
184
|
+
depth + 1,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(value)) {
|
|
188
|
+
return value.map(item =>
|
|
189
|
+
convert(root, schema!.items, item, secretOf, depth + 1),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
if (value !== null && typeof value === 'object') {
|
|
193
|
+
const props: Schema = schema.properties ?? {};
|
|
194
|
+
const extra =
|
|
195
|
+
typeof schema.additionalProperties === 'object'
|
|
196
|
+
? schema.additionalProperties
|
|
197
|
+
: undefined;
|
|
198
|
+
const out: Record<string, unknown> = {};
|
|
199
|
+
for (const [k, v] of Object.entries(value)) {
|
|
200
|
+
out[k] = convert(root, props[k] ?? extra, v, secretOf, depth + 1);
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The branch of a `oneOf` a value is: the one whose constant tag it has. */
|
|
208
|
+
function branchOf(
|
|
209
|
+
root: Schema,
|
|
210
|
+
branches: Schema[],
|
|
211
|
+
value: unknown,
|
|
212
|
+
): Schema | undefined {
|
|
213
|
+
const resolved = branches.map(b => resolve(root, b));
|
|
214
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
215
|
+
for (const b of resolved) {
|
|
216
|
+
const props = b?.properties;
|
|
217
|
+
if (!props) continue;
|
|
218
|
+
const tagged = Object.entries(props).every(
|
|
219
|
+
([k, p]: [string, any]) =>
|
|
220
|
+
!('const' in (p ?? {})) ||
|
|
221
|
+
(value as Record<string, unknown>)[k] === p.const,
|
|
222
|
+
);
|
|
223
|
+
if (
|
|
224
|
+
tagged &&
|
|
225
|
+
Object.values(props).some((p: any) => 'const' in (p ?? {}))
|
|
226
|
+
) {
|
|
227
|
+
return b;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function isPlaceholder(value: unknown): value is {[PLACEHOLDER_KEY]: string} {
|
|
235
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
236
|
+
return false;
|
|
237
|
+
const keys = Object.keys(value);
|
|
238
|
+
return keys.length === 1 && keys[0] === PLACEHOLDER_KEY;
|
|
239
|
+
}
|
package/cron/mod.test.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {describe, expect, test} from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import {CronJob} from './mod';
|
|
4
|
+
|
|
5
|
+
describe('CronJob', () => {
|
|
6
|
+
test('reads as it was declared', () => {
|
|
7
|
+
const job = new CronJob('cleanup', {
|
|
8
|
+
title: 'Nightly cleanup',
|
|
9
|
+
every: '24h',
|
|
10
|
+
path: '/internal/cleanup',
|
|
11
|
+
});
|
|
12
|
+
expect(job.name).toBe('cleanup');
|
|
13
|
+
expect(job.cfg).toEqual({
|
|
14
|
+
title: 'Nightly cleanup',
|
|
15
|
+
every: '24h',
|
|
16
|
+
path: '/internal/cleanup',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Encore requests the declared path: a route from a changed one would
|
|
21
|
+
// never be called. `tsc` refuses the writes (below); an app run without it
|
|
22
|
+
// has them throw.
|
|
23
|
+
test('cannot be changed', () => {
|
|
24
|
+
const cfg = {every: '24h' as const, path: '/internal/cleanup'};
|
|
25
|
+
const job = new CronJob('cleanup', cfg);
|
|
26
|
+
const writable = job as unknown as {name: string; cfg: {path: string}};
|
|
27
|
+
expect(() => {
|
|
28
|
+
writable.cfg.path = '/other';
|
|
29
|
+
}).toThrow(TypeError);
|
|
30
|
+
expect(() => {
|
|
31
|
+
writable.cfg = {path: '/other'};
|
|
32
|
+
}).toThrow(TypeError);
|
|
33
|
+
expect(() => {
|
|
34
|
+
writable.name = 'other';
|
|
35
|
+
}).toThrow(TypeError);
|
|
36
|
+
expect(job.cfg.path).toBe('/internal/cleanup');
|
|
37
|
+
// The declaration's own object is the app's, and is left as it was.
|
|
38
|
+
expect(Object.isFrozen(cfg)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Compile-only: `tsc` checks that a job's config can be read but not changed.
|
|
43
|
+
// Never called.
|
|
44
|
+
function _cfgTyping(job: CronJob) {
|
|
45
|
+
const path: string = job.cfg.path;
|
|
46
|
+
void path;
|
|
47
|
+
// @ts-expect-error Encore requests the declared path, not a changed one
|
|
48
|
+
job.cfg.path = '/other';
|
|
49
|
+
// @ts-expect-error the title is read from the source, too
|
|
50
|
+
job.cfg.title = 'Other';
|
|
51
|
+
}
|
|
52
|
+
void _cfgTyping;
|
package/cron/mod.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {DurationString} from '../types/mod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The header with a run's idempotency key: an id that is the same each time
|
|
5
|
+
* Encore sends the run, as when it sends it again after a failure. A job
|
|
6
|
+
* that must not do its work twice can check whether it has seen the key
|
|
7
|
+
* before:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* app.post('/internal/cleanup', (req, res) => {
|
|
11
|
+
* const key = req.get(IDEMPOTENCY_KEY_HEADER);
|
|
12
|
+
* // ...
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Only Encore sends it: a gateway removes it from the requests it takes from
|
|
17
|
+
* clients. `encore cron trigger <name>` runs a job locally, as Encore runs it
|
|
18
|
+
* when it is due.
|
|
19
|
+
*/
|
|
20
|
+
export const IDEMPOTENCY_KEY_HEADER = 'x-encore-cron-execution';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The header that says why a job runs: `scheduled`, when it was due, or
|
|
24
|
+
* `manual`, when someone asked for it to run now.
|
|
25
|
+
*/
|
|
26
|
+
export const TRIGGER_HEADER = 'x-encore-cron-trigger';
|
|
27
|
+
|
|
28
|
+
export class CronJob {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
/**
|
|
31
|
+
* What the job was declared with. Read-only: Encore schedules the job from
|
|
32
|
+
* the declaration in the source, so a changed path would not be requested.
|
|
33
|
+
*/
|
|
34
|
+
readonly cfg: Readonly<CronJobConfig>;
|
|
35
|
+
constructor(name: string, cfg: CronJobConfig) {
|
|
36
|
+
this.name = name;
|
|
37
|
+
// Frozen as well as typed `readonly`, so a write throws in an app that
|
|
38
|
+
// runs without `tsc` checking it.
|
|
39
|
+
this.cfg = Object.freeze({...cfg});
|
|
40
|
+
Object.freeze(this);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The configuration of a cron job: the path it requests and when.
|
|
46
|
+
*
|
|
47
|
+
* When the job is due, Encore sends a `POST` request for `path` to the service
|
|
48
|
+
* that declares the job. The fields must be literals: Encore reads them from
|
|
49
|
+
* the source.
|
|
50
|
+
*/
|
|
51
|
+
export type CronJobConfig = {
|
|
52
|
+
/** The path the job requests of its service, starting with `/`. */
|
|
53
|
+
path: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Tags that classify the cron job, for policies to read: written out as
|
|
57
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
58
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
59
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
60
|
+
*/
|
|
61
|
+
tags?: Record<string, string>;
|
|
62
|
+
} & ({every: DurationString} | {schedule: string});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Describes the running Encore application. */
|
|
2
|
+
export interface AppMeta {
|
|
3
|
+
/**
|
|
4
|
+
* The Encore application ID. If the application is not linked to the Encore platform this will be an empty string.
|
|
5
|
+
* To link to the Encore platform run `encore cloud link` from your terminal in the root directory of the Encore app.
|
|
6
|
+
*/
|
|
7
|
+
appId: string;
|
|
8
|
+
/**
|
|
9
|
+
* The Encore application slug — the human-readable identifier shown in the Encore
|
|
10
|
+
* Cloud dashboard and used by the CLI. If the application is not linked to the
|
|
11
|
+
* Encore platform this will be an empty string.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from `appId`: the id is opaque and stable, the slug is readable and may
|
|
14
|
+
* be renamed. Locally the two are the same.
|
|
15
|
+
*/
|
|
16
|
+
appSlug: string;
|
|
17
|
+
/**
|
|
18
|
+
* The API gateways of this application this service is given, keyed by
|
|
19
|
+
* gateway name: those its code looks up the URL of, and the one it hosts.
|
|
20
|
+
*
|
|
21
|
+
* An application can declare several gateways, so there is no single base URL for
|
|
22
|
+
* the API — look up the gateway you mean by name. A service's processes, its
|
|
23
|
+
* Workers' included, list the gateways its code names (`url("api")` from
|
|
24
|
+
* `@encore.dev/sdk/gateways`) and the one it hosts, and no other; one told of
|
|
25
|
+
* none, as under `encore test`, reports an empty object.
|
|
26
|
+
*/
|
|
27
|
+
gateways: Record<string, GatewayMeta>;
|
|
28
|
+
/**
|
|
29
|
+
* The frontends of this application this service is given — those its code
|
|
30
|
+
* looks up the URL of (`url("web")` from `@encore.dev/sdk/frontends`), and
|
|
31
|
+
* the one it hosts — keyed by name, with where each is reached. One the
|
|
32
|
+
* environment gives no origins is left out.
|
|
33
|
+
*/
|
|
34
|
+
frontends: Record<string, FrontendMeta>;
|
|
35
|
+
/** Information about the environment the app is running in. */
|
|
36
|
+
environment: EnvironmentMeta;
|
|
37
|
+
/** Information about the build. */
|
|
38
|
+
build: BuildMeta;
|
|
39
|
+
/** Information about the deployment. */
|
|
40
|
+
deploy: DeployMeta;
|
|
41
|
+
}
|
|
42
|
+
/** Describes an API gateway serving the application. */
|
|
43
|
+
export interface GatewayMeta {
|
|
44
|
+
/** The name of the gateway, as declared by the application. */
|
|
45
|
+
name: string;
|
|
46
|
+
/**
|
|
47
|
+
* The URL the API of this running application is called at through this
|
|
48
|
+
* gateway: the first of its origins. Empty when the environment gives the
|
|
49
|
+
* gateway no origins.
|
|
50
|
+
*/
|
|
51
|
+
url: string;
|
|
52
|
+
/**
|
|
53
|
+
* Every origin the gateway is reached at in this environment
|
|
54
|
+
* (`scheme://host[:port]`), the first its URL. After the first, an entry may
|
|
55
|
+
* be a pattern of one, `https://*.example.com`, or `*`, which makes the
|
|
56
|
+
* gateway the one serving requests no other origin matches.
|
|
57
|
+
*/
|
|
58
|
+
origins: string[];
|
|
59
|
+
}
|
|
60
|
+
/** Describes a frontend of the application, and where it is reached. */
|
|
61
|
+
export interface FrontendMeta {
|
|
62
|
+
/** The name of the frontend: for one a service hosts, the service's. */
|
|
63
|
+
name: string;
|
|
64
|
+
/** The URL the frontend is reached at: the first of its origins. */
|
|
65
|
+
url: string;
|
|
66
|
+
/**
|
|
67
|
+
* Every origin the frontend is reached at in this environment, the first its
|
|
68
|
+
* URL; after the first, an entry may be a pattern of one,
|
|
69
|
+
* `https://*.example.com`.
|
|
70
|
+
*/
|
|
71
|
+
origins: string[];
|
|
72
|
+
}
|
|
73
|
+
/** Describes the environment the Encore application is running in. */
|
|
74
|
+
export interface EnvironmentMeta {
|
|
75
|
+
/**
|
|
76
|
+
* The name of environment that this application.
|
|
77
|
+
* For local development it is "local".
|
|
78
|
+
*/
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* The type of environment is this application running in.
|
|
82
|
+
* For local development it is "development".
|
|
83
|
+
*/
|
|
84
|
+
type: EnvironmentType;
|
|
85
|
+
/**
|
|
86
|
+
* The cloud this is running in.
|
|
87
|
+
* For local development it is "local".
|
|
88
|
+
*/
|
|
89
|
+
cloud: CloudProvider;
|
|
90
|
+
}
|
|
91
|
+
/** Describes what type of environment the application is running in. */
|
|
92
|
+
export type EnvironmentType = 'production' | 'development' | 'ephemeral' | 'test';
|
|
93
|
+
/** Describes what cloud provider the application is running in. */
|
|
94
|
+
export type CloudProvider = 'aws' | 'gcp' | 'azure' | 'encore' | 'local';
|
|
95
|
+
/** Information about the build that formed the running application. */
|
|
96
|
+
export interface BuildMeta {
|
|
97
|
+
/** The VCS revision the deployed application was built from. */
|
|
98
|
+
revision: string;
|
|
99
|
+
}
|
|
100
|
+
/** Information about the deployment of the running application. */
|
|
101
|
+
export interface DeployMeta {
|
|
102
|
+
/** The unique id of the deployment. Generated by the Encore Platform. */
|
|
103
|
+
id: string;
|
|
104
|
+
/** The time the Encore Platform deployed this build to the environment. */
|
|
105
|
+
time: Date;
|
|
106
|
+
/** The services hosted by this deployment, keyed by the service name. */
|
|
107
|
+
hostedServices: Record<string, HostedService>;
|
|
108
|
+
/**
|
|
109
|
+
* The Worker of its service this process runs: a long-running process of
|
|
110
|
+
* the service that serves no requests, declared in the `workers` section of
|
|
111
|
+
* its `encore.service.json`. Undefined for the service's main process.
|
|
112
|
+
*/
|
|
113
|
+
worker?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface HostedService {
|
|
116
|
+
/** The name of the service */
|
|
117
|
+
name: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns metadata about the running Encore application.
|
|
121
|
+
*
|
|
122
|
+
* The metadata is cached and is the same object each call,
|
|
123
|
+
* and therefore must not be modified by the caller.
|
|
124
|
+
*/
|
|
125
|
+
export declare function appMeta(): AppMeta;
|
|
126
|
+
//# sourceMappingURL=app_meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app_meta.d.ts","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAEA,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;;;OASG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEtC;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAExC,+DAA+D;IAC/D,WAAW,EAAE,eAAe,CAAC;IAE7B,mCAAmC;IACnC,KAAK,EAAE,SAAS,CAAC;IAEjB,wCAAwC;IACxC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,wDAAwD;AACxD,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;;OAKG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IAEb,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;OAIG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,eAAe,CAAC;IAEtB;;;OAGG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAEvB,YAAY,GAEZ,aAAa,GAEb,WAAW,GAEX,MAAM,CAAC;AAEX,mEAAmE;AACnE,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,KAAK,GACL,OAAO,GACP,QAAQ,GACR,OAAO,CAAC;AAEZ,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,yEAAyE;IACzE,EAAE,EAAE,MAAM,CAAC;IAEX,2EAA2E;IAC3E,IAAI,EAAE,IAAI,CAAC;IAEX,yEAAyE;IACzE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE9C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,IAAI,OAAO,CA2BjC"}
|