@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +51 -12
- package/config/config.test.ts +18 -15
- package/config/config.ts +89 -31
- package/config/mod.ts +4 -3
- package/config/secrets.ts +79 -53
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +41 -2
- package/dist/app_meta.d.ts +44 -12
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +2 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -28
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +46 -18
- package/dist/config/config.js.map +1 -1
- package/dist/config/mod.d.ts +5 -4
- package/dist/config/mod.d.ts.map +1 -0
- package/dist/config/mod.js +2 -2
- package/dist/config/mod.js.map +1 -1
- package/dist/config/secrets.d.ts +71 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +31 -38
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +8 -5
- package/dist/config/value.d.ts.map +1 -0
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +36 -1
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +31 -1
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/errors.d.ts +101 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +146 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/match.d.ts +127 -0
- package/dist/gateway/match.d.ts.map +1 -0
- package/dist/gateway/match.js +206 -0
- package/dist/gateway/match.js.map +1 -0
- package/dist/gateway/middleware.d.ts +108 -0
- package/dist/gateway/middleware.d.ts.map +1 -0
- package/dist/gateway/middleware.js +9 -0
- package/dist/gateway/middleware.js.map +1 -0
- package/dist/gateway/mod.d.ts +130 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +188 -0
- package/dist/gateway/mod.js.map +1 -0
- package/dist/gateway/request.d.ts +304 -0
- package/dist/gateway/request.d.ts.map +1 -0
- package/dist/gateway/request.js +403 -0
- package/dist/gateway/request.js.map +1 -0
- package/dist/gateway/serve.d.ts +114 -0
- package/dist/gateway/serve.d.ts.map +1 -0
- package/dist/gateway/serve.js +510 -0
- package/dist/gateway/serve.js.map +1 -0
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/clients/call.d.ts +147 -0
- package/dist/internal/clients/call.d.ts.map +1 -0
- package/dist/internal/clients/call.js +274 -0
- package/dist/internal/clients/call.js.map +1 -0
- package/dist/internal/clients/grpc.d.ts +90 -0
- package/dist/internal/clients/grpc.d.ts.map +1 -0
- package/dist/internal/clients/grpc.js +355 -0
- package/dist/internal/clients/grpc.js.map +1 -0
- package/dist/internal/clients/mod.d.ts +81 -0
- package/dist/internal/clients/mod.d.ts.map +1 -0
- package/dist/internal/clients/mod.js +237 -0
- package/dist/internal/clients/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +58 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +251 -0
- package/dist/internal/fetch.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +2 -0
- package/dist/internal/otel/backend.d.ts.map +1 -0
- package/dist/internal/otel/context.d.ts +1 -0
- package/dist/internal/otel/context.d.ts.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +1 -0
- package/dist/internal/otel/context_manager.d.ts.map +1 -0
- package/dist/internal/otel/encode.d.ts +2 -0
- package/dist/internal/otel/encode.d.ts.map +1 -0
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +2 -2
- package/dist/internal/otel/index.d.ts.map +1 -0
- package/dist/internal/otel/index.js +1 -2
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/meter.d.ts +1 -0
- package/dist/internal/otel/meter.d.ts.map +1 -0
- package/dist/internal/otel/propagator.d.ts +1 -0
- package/dist/internal/otel/propagator.d.ts.map +1 -0
- package/dist/internal/otel/provider.d.ts +4 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +15 -1
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +30 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/otel/tracer.d.ts +1 -0
- package/dist/internal/otel/tracer.d.ts.map +1 -0
- package/dist/internal/otel/tracer.js +11 -5
- package/dist/internal/otel/tracer.js.map +1 -1
- package/dist/internal/reqfields.d.ts +170 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +349 -0
- package/dist/internal/reqfields.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +1 -0
- package/dist/internal/runtime/meter.d.ts.map +1 -0
- package/dist/internal/runtime/mod.d.ts +6 -0
- package/dist/internal/runtime/mod.d.ts.map +1 -0
- package/dist/internal/runtime/mod.js +32 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +192 -16
- package/dist/internal/runtime/napi/napi.d.cts +573 -33
- package/dist/internal/runtime/shutdown.d.ts +5 -0
- package/dist/internal/runtime/shutdown.d.ts.map +1 -0
- package/dist/internal/runtime/shutdown.js +9 -1
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/runner.d.ts +2 -0
- package/dist/internal/testing/runner.d.ts.map +1 -0
- package/dist/internal/testing/runner.js +10 -0
- package/dist/internal/testing/runner.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +109 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +335 -0
- package/dist/internal/testing/scope.js.map +1 -0
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +1 -0
- package/dist/internal/utils/constraints.d.ts.map +1 -0
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/logger.d.ts +2 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/runtime.d.ts +2 -0
- package/dist/log/runtime.d.ts.map +1 -0
- package/dist/log/stderr.d.ts +1 -0
- package/dist/log/stderr.d.ts.map +1 -0
- package/dist/metrics/mod.d.ts +45 -118
- package/dist/metrics/mod.d.ts.map +1 -0
- package/dist/metrics/mod.js +44 -179
- package/dist/metrics/mod.js.map +1 -1
- package/dist/mod.d.ts +2 -3
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/dist/otel.d.ts +1 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/pubsub/encoding.d.ts +5 -0
- package/dist/pubsub/encoding.d.ts.map +1 -0
- package/dist/pubsub/encoding.js +10 -2
- package/dist/pubsub/encoding.js.map +1 -1
- package/dist/pubsub/mod.d.ts +5 -4
- package/dist/pubsub/mod.d.ts.map +1 -0
- package/dist/pubsub/mod.js +2 -2
- package/dist/pubsub/mod.js.map +1 -1
- package/dist/pubsub/refs.d.ts +8 -0
- package/dist/pubsub/refs.d.ts.map +1 -0
- package/dist/pubsub/refs.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +110 -15
- package/dist/pubsub/subscription.d.ts.map +1 -0
- package/dist/pubsub/subscription.js +98 -16
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +101 -31
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +168 -51
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +174 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +144 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +147 -5
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +157 -9
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +1 -0
- package/dist/shutdown/mod.d.ts.map +1 -0
- package/dist/storage/objects/bucket.d.ts +313 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +306 -15
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +10 -0
- package/dist/storage/objects/error.d.ts.map +1 -0
- package/dist/storage/objects/error.js +25 -1
- package/dist/storage/objects/error.js.map +1 -1
- package/dist/storage/objects/mod.d.ts +4 -3
- package/dist/storage/objects/mod.d.ts.map +1 -0
- package/dist/storage/objects/mod.js +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +20 -4
- package/dist/storage/objects/refs.d.ts.map +1 -0
- package/dist/storage/objects/refs.js +6 -0
- package/dist/storage/objects/refs.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +85 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +129 -37
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +120 -0
- package/dist/storage/postgres/errors.d.ts.map +1 -0
- package/dist/storage/postgres/errors.js +162 -0
- package/dist/storage/postgres/errors.js.map +1 -0
- package/dist/storage/postgres/interval.d.ts +44 -0
- package/dist/storage/postgres/interval.d.ts.map +1 -0
- package/dist/storage/postgres/interval.js +153 -0
- package/dist/storage/postgres/interval.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +4 -1
- package/dist/storage/postgres/mod.d.ts.map +1 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +67 -0
- package/dist/storage/redis/bitfield.d.ts.map +1 -0
- package/dist/storage/redis/bitfield.js +114 -0
- package/dist/storage/redis/bitfield.js.map +1 -0
- package/dist/storage/redis/command.d.ts +45 -0
- package/dist/storage/redis/command.d.ts.map +1 -0
- package/dist/storage/redis/command.js +78 -0
- package/dist/storage/redis/command.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +223 -139
- package/dist/storage/redis/commands.d.ts.map +1 -0
- package/dist/storage/redis/commands.js +128 -6
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +56 -22
- package/dist/storage/redis/database.d.ts.map +1 -0
- package/dist/storage/redis/database.js +62 -0
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +31 -4
- package/dist/storage/redis/mod.d.ts.map +1 -0
- package/dist/storage/redis/mod.js +26 -1
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.d.ts.map +1 -0
- package/dist/storage/redis/native.js +10 -0
- package/dist/storage/redis/native.js.map +1 -1
- package/dist/storage/redis/options.d.ts +1 -0
- package/dist/storage/redis/options.d.ts.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +2 -0
- package/dist/storage/redis/pubsub.d.ts.map +1 -0
- package/dist/storage/redis/reply.d.ts +34 -0
- package/dist/storage/redis/reply.d.ts.map +1 -0
- package/dist/storage/redis/reply.js +40 -1
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +1 -0
- package/dist/storage/redis/scan.d.ts.map +1 -0
- package/dist/storage/redis/script.d.ts +1 -0
- package/dist/storage/redis/script.d.ts.map +1 -0
- package/dist/storage/redis/target.d.ts +5 -3
- package/dist/storage/redis/target.d.ts.map +1 -0
- package/dist/storage/redis/target.js +39 -28
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +7 -10
- package/dist/storage/redis/wire.d.ts.map +1 -0
- package/dist/storage/redis/wire.js +8 -32
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/bun.d.ts +8 -0
- package/dist/testing/bun.d.ts.map +1 -0
- package/dist/testing/bun.js +13 -0
- package/dist/testing/bun.js.map +1 -0
- package/dist/testing/jest.d.ts +8 -0
- package/dist/testing/jest.d.ts.map +1 -0
- package/dist/testing/jest.js +11 -0
- package/dist/testing/jest.js.map +1 -0
- package/dist/testing/mod.d.ts +183 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +271 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/testing/node.d.ts +9 -0
- package/dist/testing/node.d.ts.map +1 -0
- package/dist/testing/node.js +12 -0
- package/dist/testing/node.js.map +1 -0
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/testing/vitest.d.ts +8 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +13 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +20 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +47 -0
- package/dist/tracing/mod.js.map +1 -0
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mod.d.ts +1 -0
- package/dist/types/mod.d.ts.map +1 -0
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/errors.ts +172 -0
- package/gateway/gateway.e2e.test.ts +297 -0
- package/gateway/gateway.test.ts +891 -0
- package/gateway/match.ts +239 -0
- package/gateway/middleware.ts +134 -0
- package/gateway/mod.ts +211 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -0
- package/gateways/mod.ts +60 -0
- package/internal/clients/call.ts +389 -0
- package/internal/clients/grpc.test.ts +368 -0
- package/internal/clients/grpc.ts +485 -0
- package/internal/clients/mod.test.ts +464 -0
- package/internal/clients/mod.ts +337 -0
- package/internal/fetch.ts +287 -0
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +31 -2
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +423 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +192 -16
- package/internal/runtime/napi/napi.d.cts +573 -33
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +372 -0
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +1 -8
- package/otel.test.ts +13 -6
- package/package.json +92 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +16 -4
- package/pubsub/pubsub.test.ts +233 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +200 -21
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +255 -36
- package/reqctx/mod.ts +267 -0
- package/reqctx/reqctx.test.ts +216 -0
- package/scripts/postprocess-docs.test.ts +58 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +185 -9
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +650 -20
- package/storage/objects/error.ts +28 -1
- package/storage/objects/mod.ts +15 -0
- package/storage/objects/refs.ts +51 -3
- package/storage/postgres/database.integration.test.ts +275 -0
- package/storage/postgres/database.test.ts +193 -6
- package/storage/postgres/database.ts +206 -55
- package/storage/postgres/errors.ts +186 -0
- package/storage/postgres/interval.test.ts +72 -0
- package/storage/postgres/interval.ts +170 -0
- package/storage/postgres/mod.ts +4 -0
- package/storage/redis/bitfield.ts +162 -0
- package/storage/redis/command.ts +84 -0
- package/storage/redis/commands.ts +271 -21
- package/storage/redis/database.ts +77 -23
- package/storage/redis/mod.ts +38 -2
- package/storage/redis/native.ts +11 -0
- package/storage/redis/redis.test.ts +170 -10
- package/storage/redis/reply.ts +76 -1
- package/storage/redis/runtime.test.ts +15 -0
- package/storage/redis/target.ts +47 -44
- package/storage/redis/wire.ts +8 -32
- package/testing/bun.ts +13 -0
- package/testing/jest.ts +11 -0
- package/testing/mod.ts +393 -0
- package/testing/node.ts +12 -0
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/testing/vitest.ts +13 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +83 -0
- package/tracing/native.test.ts +267 -0
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +953 -0
- package/dist/internal/otel/request_context.d.ts +0 -11
- package/dist/internal/otel/request_context.js +0 -20
- package/dist/internal/otel/request_context.js.map +0 -1
- package/dist/internal/reqtrack/mod.d.ts +0 -6
- package/dist/internal/reqtrack/mod.js +0 -28
- package/dist/internal/reqtrack/mod.js.map +0 -1
- package/dist/req_meta.d.ts +0 -47
- package/dist/req_meta.js +0 -26
- package/dist/req_meta.js.map +0 -1
- package/internal/otel/request_context.ts +0 -32
- package/internal/reqtrack/mod.ts +0 -39
- package/req_meta.ts +0 -75
package/dist/config/config.js
CHANGED
|
@@ -1,30 +1,52 @@
|
|
|
1
1
|
import * as runtime from '../internal/runtime/mod.js';
|
|
2
|
+
import { lookupScope, testMode } from '../internal/testing/scope.js';
|
|
2
3
|
import { secretOfField } from './secrets.js';
|
|
3
4
|
import { build } from './value.js';
|
|
4
5
|
export { Duration } from './value.js';
|
|
5
6
|
/**
|
|
6
|
-
* config declares a {@link Config} belonging to the service that
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* config declares a {@link Config}, by default belonging to the service that
|
|
8
|
+
* declares it (see {@link ConfigOptions.scope}). The declaration is a
|
|
9
|
+
* module-level `export const`, with the name a string literal.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // A config several services read.
|
|
14
|
+
* export const flags = config<Flags>("flags", {scope: "shared"});
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
|
-
export function config(name
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export function sharedConfig(name) {
|
|
20
|
-
return makeConfig(name, runtime.RT.sharedConfig(name));
|
|
17
|
+
export function config(name,
|
|
18
|
+
// The options are Encore's parser's to read: a config is read by name
|
|
19
|
+
// whatever its scope, a name having one scope across the app.
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
opts) {
|
|
22
|
+
const handle = makeConfig(name, runtime.RT.config(name));
|
|
23
|
+
names.set(handle, name);
|
|
24
|
+
return handle;
|
|
21
25
|
}
|
|
26
|
+
/** The name of the config each handle reads. */
|
|
27
|
+
const names = new WeakMap();
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
29
|
+
* Gives `cfg` the value `value` for the test `scope`, once the core has
|
|
30
|
+
* checked it against the config's schema: reading the config in the test
|
|
31
|
+
* returns it from then on. For `@encore.dev/sdk/testing`.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
25
34
|
*/
|
|
26
|
-
export function
|
|
27
|
-
|
|
35
|
+
export function setTestValue(scope, cfg, value) {
|
|
36
|
+
const name = names.get(cfg);
|
|
37
|
+
if (name === undefined) {
|
|
38
|
+
throw new TypeError('setConfig takes a config declared with `config()`');
|
|
39
|
+
}
|
|
40
|
+
const json = JSON.stringify(value);
|
|
41
|
+
if (json === undefined) {
|
|
42
|
+
throw new TypeError(`config ${name}: the value has no JSON form`);
|
|
43
|
+
}
|
|
44
|
+
const prepared = JSON.parse(scope.native.setConfig(name, json));
|
|
45
|
+
const impl = runtime.RT.config(name);
|
|
46
|
+
const built = impl === null
|
|
47
|
+
? prepared
|
|
48
|
+
: build(JSON.parse(impl.schema()), prepared, secretOfField);
|
|
49
|
+
scope.configs.set(name, built);
|
|
28
50
|
}
|
|
29
51
|
/**
|
|
30
52
|
* The native watches not yet stopped. A watch stops when it is collected, and
|
|
@@ -49,6 +71,12 @@ function makeConfig(name, impl) {
|
|
|
49
71
|
return value;
|
|
50
72
|
};
|
|
51
73
|
const read = () => {
|
|
74
|
+
if (testMode) {
|
|
75
|
+
// The value the current test gave it, if it did.
|
|
76
|
+
const configs = lookupScope()?.configs;
|
|
77
|
+
if (configs?.has(name))
|
|
78
|
+
return configs.get(name);
|
|
79
|
+
}
|
|
52
80
|
if (impl === null) {
|
|
53
81
|
// No value at all: every field takes its default, which in TypeScript is
|
|
54
82
|
// none. The runtime config has every config the app declares, so this
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AACxC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAa,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AACxC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAmFjC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CACpB,IAAY;AACZ,sEAAsE;AACtE,8DAA8D;AAC9D,6DAA6D;AAC7D,IAAoB;IAEpB,MAAM,MAAM,GAAG,UAAU,CAAI,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gDAAgD;AAChD,MAAM,KAAK,GAAG,IAAI,OAAO,EAAuB,CAAC;AAEjD;;;;;;GAM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AAc,CAAC;IAC3C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;IACrD,MAAM,CAAC,QAAQ,GAAG,CAAC,QAA4B,EAAE,EAAE;QACjD,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACrC,qEAAqE;YACrE,yBAAyB;YACzB,IAAI,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE;gBAAE,OAAO;YAC9C,uEAAuE;YACvE,YAAY;YACZ,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/config/mod.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { Secret, AnySecret } from './secrets.js';
|
|
2
|
-
export { secret
|
|
3
|
-
export type { Config, Min, Max, Int, MinLen, MaxLen, Pattern, MinItems, MaxItems, } from './config.js';
|
|
4
|
-
export { config,
|
|
1
|
+
export type { Secret, AnySecret, SecretOptions } from './secrets.js';
|
|
2
|
+
export { secret } from './secrets.js';
|
|
3
|
+
export type { Config, ConfigOptions, Min, Max, Int, MinLen, MaxLen, Pattern, MinItems, MaxItems, } from './config.js';
|
|
4
|
+
export { config, Duration } from './config.js';
|
|
5
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../config/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,WAAW,CAAC;AAChE,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACjC,YAAY,EACV,MAAM,EACN,aAAa,EACb,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,QAAQ,GACT,MAAM,UAAU,CAAC;AAClB,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAC"}
|
package/dist/config/mod.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { secret
|
|
2
|
-
export { config,
|
|
1
|
+
export { secret } from './secrets.js';
|
|
2
|
+
export { config, Duration } from './config.js';
|
|
3
3
|
//# sourceMappingURL=mod.js.map
|
package/dist/config/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../config/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../config/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AAajC,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,UAAU,CAAC"}
|
package/dist/config/secrets.d.ts
CHANGED
|
@@ -7,22 +7,25 @@ import { StringLiteral } from '../internal/utils/constraints.js';
|
|
|
7
7
|
* You can use {@link AnySecret} to represent any secret without knowing
|
|
8
8
|
* it's name.
|
|
9
9
|
*
|
|
10
|
+
* `T` is the type of the secret's value. Only `string` is supported.
|
|
11
|
+
*
|
|
10
12
|
* @example
|
|
11
13
|
*
|
|
12
14
|
* function doFoo(s: Secret<"foo">): void {
|
|
13
15
|
* const foo = s();
|
|
14
16
|
* }
|
|
15
17
|
*/
|
|
16
|
-
export interface Secret<Name extends string> {
|
|
18
|
+
export interface Secret<Name extends string, T extends string = string> {
|
|
17
19
|
/**
|
|
18
|
-
* Returns the
|
|
20
|
+
* Returns the value of the secret.
|
|
21
|
+
*
|
|
22
|
+
* The value is read once per process and does not change while it runs:
|
|
23
|
+
* a new value reaches a service when it restarts.
|
|
19
24
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* minutes. If you need to ensure you have the latest value, use
|
|
23
|
-
* `latest`.
|
|
25
|
+
* Throws an `Error` naming the secret when it has no value, in every
|
|
26
|
+
* environment, local development too.
|
|
24
27
|
*/
|
|
25
|
-
():
|
|
28
|
+
(): T;
|
|
26
29
|
/**
|
|
27
30
|
* The name of the secret.
|
|
28
31
|
*/
|
|
@@ -33,9 +36,8 @@ export interface Secret<Name extends string> {
|
|
|
33
36
|
*
|
|
34
37
|
* As a field of a config's type, `apiKey: Secret<"StripeKey">` reads the
|
|
35
38
|
* secret of that name in the config's own scope: the declaring service's
|
|
36
|
-
* own for
|
|
37
|
-
*
|
|
38
|
-
* {@link sharedSecret} or {@link globalSecret}.
|
|
39
|
+
* own for a service config, the app's for a shared or global one. The
|
|
40
|
+
* secret is declared as any other is, with {@link secret}.
|
|
39
41
|
*/
|
|
40
42
|
readonly '~encore.secret'?: true;
|
|
41
43
|
}
|
|
@@ -45,43 +47,72 @@ export interface Secret<Name extends string> {
|
|
|
45
47
|
*/
|
|
46
48
|
export type AnySecret = Secret<string>;
|
|
47
49
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* Two services may each declare a secret of the same name and hold different
|
|
51
|
-
* values in them, so adding a secret to one service can never collide with — or
|
|
52
|
-
* silently reuse — a name another service already took. The declaration must
|
|
53
|
-
* therefore live inside a service; Encore reports an error otherwise.
|
|
54
|
-
*
|
|
55
|
-
* For a value several services genuinely share, use {@link sharedSecret}.
|
|
56
|
-
*
|
|
57
|
-
* @example loading a single secret
|
|
58
|
-
* import {secret} from "@encore.dev/sdk/config";
|
|
59
|
-
* const foo = secret("foo");
|
|
50
|
+
* The options a secret is declared with. Read by Encore's parser, so the
|
|
51
|
+
* values must be literals.
|
|
60
52
|
*/
|
|
61
|
-
export
|
|
53
|
+
export interface SecretOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Who the secret belongs to, written as a string literal for Encore to
|
|
56
|
+
* read:
|
|
57
|
+
*
|
|
58
|
+
* - `"service"`, the default: the service that declares it. Two services
|
|
59
|
+
* may each declare a secret of the same name and hold different values
|
|
60
|
+
* in them, so adding a secret to one service can never collide with, or
|
|
61
|
+
* silently reuse, a name another service already took. The declaration
|
|
62
|
+
* must therefore live inside a service; Encore reports an error
|
|
63
|
+
* otherwise.
|
|
64
|
+
* - `"shared"`: the whole app, readable from any service, each that reads
|
|
65
|
+
* it recorded as using it. It may be declared outside a service. Use it
|
|
66
|
+
* only for a value several services genuinely share: a shared secret
|
|
67
|
+
* couples every service that reads it, and widening a secret's scope
|
|
68
|
+
* later is easier than narrowing it.
|
|
69
|
+
* - `"global"`: the whole app, with one value available to every service
|
|
70
|
+
* without being granted. It may be declared outside a service.
|
|
71
|
+
*/
|
|
72
|
+
scope?: 'service' | 'shared' | 'global';
|
|
73
|
+
/**
|
|
74
|
+
* What the secret is, who issues it and how to rotate it, shown wherever its
|
|
75
|
+
* values are managed. The declaration's doc comment wins when there is one.
|
|
76
|
+
*/
|
|
77
|
+
description?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Tags that classify the secret, for policies to read: written out as
|
|
80
|
+
* string literals, as in `{data: "pci"}`. Keys and values are lowercase
|
|
81
|
+
* letters, digits, `_` and `-`, at most 63 characters; a key starts with a
|
|
82
|
+
* letter, and not with `encore`, which is reserved. At most 32 tags.
|
|
83
|
+
*/
|
|
84
|
+
tags?: Record<string, string>;
|
|
85
|
+
}
|
|
62
86
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
87
|
+
* secret declares a {@link Secret}, by default belonging to the service that
|
|
88
|
+
* declares it. See {@link SecretOptions.scope} for a secret of the whole app.
|
|
65
89
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* easier than narrowing it.
|
|
90
|
+
* A doc comment on the declaration, or a `description` option, is shown
|
|
91
|
+
* wherever the secret's values are managed.
|
|
69
92
|
*
|
|
70
93
|
* @example
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* // Loading a single secret.
|
|
96
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
97
|
+
* const foo = secret("foo");
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* // A secret several services share.
|
|
103
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
104
|
+
* const signingKey = secret("SigningKey", {scope: "shared"});
|
|
105
|
+
* ```
|
|
79
106
|
*
|
|
80
107
|
* @example
|
|
81
|
-
*
|
|
82
|
-
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* // Documenting it.
|
|
110
|
+
* const apiKey = secret("ApiKey", {
|
|
111
|
+
* description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
83
114
|
*/
|
|
84
|
-
export declare function
|
|
115
|
+
export declare function secret<Name extends string>(name: StringLiteral<Name>, opts?: SecretOptions): Secret<Name>;
|
|
85
116
|
/**
|
|
86
117
|
* The secret a config's secret field reads: what the runtime's placeholder
|
|
87
118
|
* for the field stands for. A secret name has one scope across the app, so it
|
|
@@ -90,3 +121,4 @@ export declare function globalSecret<Name extends string>(name: StringLiteral<Na
|
|
|
90
121
|
* @internal
|
|
91
122
|
*/
|
|
92
123
|
export declare function secretOfField(name: string): AnySecret;
|
|
124
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../config/secrets.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,MAAM,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM;IACpE;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC;IAEN;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAEpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,IAAI,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAExC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,MAAM,CAAC,IAAI,SAAS,MAAM,EACxC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,EAIzB,IAAI,CAAC,EAAE,aAAa,GACnB,MAAM,CAAC,IAAI,CAAC,CAEd;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAErD"}
|
package/dist/config/secrets.js
CHANGED
|
@@ -1,46 +1,39 @@
|
|
|
1
1
|
import * as runtime from '../internal/runtime/mod.js';
|
|
2
|
+
import { lookupScope, testMode } from '../internal/testing/scope.js';
|
|
2
3
|
/**
|
|
3
|
-
* secret declares a {@link Secret} belonging to the service that
|
|
4
|
+
* secret declares a {@link Secret}, by default belonging to the service that
|
|
5
|
+
* declares it. See {@link SecretOptions.scope} for a secret of the whole app.
|
|
4
6
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* silently reuse — a name another service already took. The declaration must
|
|
8
|
-
* therefore live inside a service; Encore reports an error otherwise.
|
|
7
|
+
* A doc comment on the declaration, or a `description` option, is shown
|
|
8
|
+
* wherever the secret's values are managed.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
export function secret(name) {
|
|
17
|
-
return makeSecret(name, runtime.RT.secret(name));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* sharedSecret declares a {@link Secret} shared by the whole app, readable from
|
|
21
|
-
* any service. Unlike {@link secret} it may be declared outside a service.
|
|
22
|
-
*
|
|
23
|
-
* Use it only for a value several services genuinely share: a shared secret
|
|
24
|
-
* couples every service that reads it, and widening a secret's scope later is
|
|
25
|
-
* easier than narrowing it.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Loading a single secret.
|
|
13
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
14
|
+
* const foo = secret("foo");
|
|
15
|
+
* ```
|
|
26
16
|
*
|
|
27
17
|
* @example
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* globalSecret declares a {@link Secret} with one value for the whole app,
|
|
36
|
-
* available to every service without being granted. Like
|
|
37
|
-
* {@link sharedSecret} it may be declared outside a service.
|
|
18
|
+
* ```ts
|
|
19
|
+
* // A secret several services share.
|
|
20
|
+
* import {secret} from "@encore.dev/sdk/config";
|
|
21
|
+
* const signingKey = secret("SigningKey", {scope: "shared"});
|
|
22
|
+
* ```
|
|
38
23
|
*
|
|
39
24
|
* @example
|
|
40
|
-
*
|
|
41
|
-
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Documenting it.
|
|
27
|
+
* const apiKey = secret("ApiKey", {
|
|
28
|
+
* description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
42
31
|
*/
|
|
43
|
-
export function
|
|
32
|
+
export function secret(name,
|
|
33
|
+
// The options are Encore's parser's to read: a secret is read by name
|
|
34
|
+
// whatever its scope, a name having one scope across the app.
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
opts) {
|
|
44
37
|
return makeSecret(name, runtime.RT.secret(name));
|
|
45
38
|
}
|
|
46
39
|
/**
|
|
@@ -59,11 +52,11 @@ export function secretOfField(name) {
|
|
|
59
52
|
*/
|
|
60
53
|
function makeSecret(name, impl) {
|
|
61
54
|
const secretObj = () => {
|
|
55
|
+
// The value the current test gave it, if it did.
|
|
56
|
+
const override = testMode ? lookupScope()?.native.secret(name) : null;
|
|
57
|
+
if (override != null)
|
|
58
|
+
return override.toString('utf8');
|
|
62
59
|
if (impl === null) {
|
|
63
|
-
// During local development we don't consider missing secrets a fatal error.
|
|
64
|
-
if (runtime.RT.appMeta().environment.cloud === runtime.CloudProvider.Local) {
|
|
65
|
-
return '';
|
|
66
|
-
}
|
|
67
60
|
throw new Error(`secret ${name} is not set`);
|
|
68
61
|
}
|
|
69
62
|
return impl.cached();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../config/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../config/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,2BAA2B,CAAC;AA8FhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;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,14 @@ export declare class Duration {
|
|
|
34
34
|
toString(): string;
|
|
35
35
|
toJSON(): string;
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* The key of the runtime's placeholder for a secret field:
|
|
39
|
+
* `{"$encore_secret": "<name>"}`. The name alone says which secret it is: a
|
|
40
|
+
* secret's name has one scope across the app.
|
|
41
|
+
*/
|
|
38
42
|
export declare const PLACEHOLDER_KEY = "$encore_secret";
|
|
39
|
-
/**
|
|
40
|
-
export type
|
|
41
|
-
/** Builds the secret a placeholder stands for. */
|
|
42
|
-
export type SecretOf = (name: string, scope: SecretScope) => unknown;
|
|
43
|
+
/** Builds the secret a placeholder stands for, by its name. */
|
|
44
|
+
export type SecretOf = (name: string) => unknown;
|
|
43
45
|
type Schema = Record<string, any>;
|
|
44
46
|
/**
|
|
45
47
|
* `value`, as the declared type has it: the JSON the runtime hands over, with
|
|
@@ -49,3 +51,4 @@ type Schema = Record<string, any>;
|
|
|
49
51
|
*/
|
|
50
52
|
export declare function build(schema: Schema, value: unknown, secretOf: SecretOf): unknown;
|
|
51
53
|
export {};
|
|
54
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../config/value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH;;;;;;;;GAQG;AACH,qBAAa,QAAQ;IACnB;;;OAGG;IACH,SAAiB,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAE3C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAE5B,OAAO;IAIP,wDAAwD;IACxD,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAgBpC,uCAAuC;IACvC,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ;IAO3C,6DAA6D;IAC7D,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,+BAA+B;IAC/B,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,gEAAgE;IAChE,QAAQ,IAAI,MAAM;IAsBlB,MAAM,IAAI,MAAM;CAGjB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAEhD,+DAA+D;AAC/D,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAEjD,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElC;;;;;GAKG;AACH,wBAAgB,KAAK,CACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAET"}
|
package/dist/config/value.js
CHANGED
|
@@ -84,7 +84,11 @@ export class Duration {
|
|
|
84
84
|
return this.toString();
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
/**
|
|
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
|
+
*/
|
|
88
92
|
export const PLACEHOLDER_KEY = '$encore_secret';
|
|
89
93
|
/**
|
|
90
94
|
* `value`, as the declared type has it: the JSON the runtime hands over, with
|
|
@@ -114,15 +118,14 @@ function convert(root, schema, value, secretOf, depth) {
|
|
|
114
118
|
schema = resolve(root, schema);
|
|
115
119
|
// Only a field the schema says reads a secret is one: anywhere else, a
|
|
116
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.
|
|
117
122
|
const secret = schema['x-encore-secret'];
|
|
118
|
-
if (secret) {
|
|
119
|
-
if (!isPlaceholder(value) ||
|
|
120
|
-
value[PLACEHOLDER_KEY].name !== secret.name ||
|
|
121
|
-
value[PLACEHOLDER_KEY].scope !== secret.scope) {
|
|
123
|
+
if (typeof secret === 'string') {
|
|
124
|
+
if (!isPlaceholder(value) || value[PLACEHOLDER_KEY] !== secret) {
|
|
122
125
|
// Never say what the value is: it may be a pasted secret.
|
|
123
|
-
throw new Error(`a secret field reads the secret ${secret
|
|
126
|
+
throw new Error(`a secret field reads the secret ${secret}, and is not set in config`);
|
|
124
127
|
}
|
|
125
|
-
return secretOf(secret
|
|
128
|
+
return secretOf(secret);
|
|
126
129
|
}
|
|
127
130
|
if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
|
|
128
131
|
return Duration.parse(value);
|
package/dist/config/value.js.map
CHANGED
|
@@ -1 +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,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C,EAAE,CAAC;QACzE,KAAK,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"}
|
package/dist/cron/mod.d.ts
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
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";
|
|
2
25
|
export declare class CronJob {
|
|
3
26
|
readonly name: string;
|
|
4
|
-
|
|
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>;
|
|
5
32
|
constructor(name: string, cfg: CronJobConfig);
|
|
6
33
|
}
|
|
7
34
|
/**
|
|
@@ -15,8 +42,16 @@ export type CronJobConfig = {
|
|
|
15
42
|
/** The path the job requests of its service, starting with `/`. */
|
|
16
43
|
path: string;
|
|
17
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>;
|
|
18
52
|
} & ({
|
|
19
53
|
every: DurationString;
|
|
20
54
|
} | {
|
|
21
55
|
schedule: string;
|
|
22
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
CHANGED
|
@@ -1,9 +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';
|
|
1
24
|
export class CronJob {
|
|
2
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
|
+
*/
|
|
3
30
|
cfg;
|
|
4
31
|
constructor(name, cfg) {
|
|
5
32
|
this.name = name;
|
|
6
|
-
|
|
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);
|
|
7
37
|
}
|
|
8
38
|
}
|
|
9
39
|
//# sourceMappingURL=mod.js.map
|
package/dist/cron/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../cron/mod.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IACT,IAAI,CAAS;
|
|
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"}
|