@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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the app's frontends are reached.
|
|
3
|
+
*
|
|
4
|
+
* {@link url} is a frontend's URL in the environment the code runs in, as to
|
|
5
|
+
* send a user there or to build a link to one of its pages:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import * as frontends from '@encore.dev/sdk/frontends';
|
|
9
|
+
*
|
|
10
|
+
* const reset = `${frontends.url('web')}/reset?token=${token}`;
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Looking a frontend's URL up links the calling service to it. Encore reads
|
|
14
|
+
* the link from the code, as it reads which services a service depends on: so
|
|
15
|
+
* the name must be a string literal, written as the frontend declares it, the
|
|
16
|
+
* function must be called directly rather than passed around, and the call
|
|
17
|
+
* must be in a service.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { appMeta } from '../app_meta.js';
|
|
22
|
+
/**
|
|
23
|
+
* The URL `frontend` is reached at in this environment, without a trailing
|
|
24
|
+
* slash: a path goes after it, `` `${url("web")}/reset` ``. It is the first of
|
|
25
|
+
* the frontend's origins, as {@link appMeta} lists them.
|
|
26
|
+
*
|
|
27
|
+
* The name is the one the frontend is declared with, in its
|
|
28
|
+
* `encore.frontend.json` or as the service hosting it: `web_app` does not find
|
|
29
|
+
* `web-app`.
|
|
30
|
+
*
|
|
31
|
+
* Throws if the runtime knows no URL for `frontend`: the app has no frontend of
|
|
32
|
+
* that name, which Encore's parser reports, or the environment gives it no
|
|
33
|
+
* origins.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import {url} from "@encore.dev/sdk/frontends";
|
|
37
|
+
* const home = url("web");
|
|
38
|
+
*/
|
|
39
|
+
export function url(frontend) {
|
|
40
|
+
const found = appMeta().frontends[frontend]?.origins[0]?.replace(/\/+$/, '');
|
|
41
|
+
if (!found) {
|
|
42
|
+
throw new Error(`encore: no URL is known for frontend ${JSON.stringify(frontend)}: the app has no ` +
|
|
43
|
+
'frontend of that name, or the environment gives it no origins');
|
|
44
|
+
}
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,GAAG,CAAC,QAAgB;IAClC,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,wCAAwC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,mBAAmB;YACjF,+DAA+D,CAClE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code of an Encore error, which a {@link reject}ion answers with: what
|
|
3
|
+
* went wrong, as Encore's clients read it, and the HTTP status the answer
|
|
4
|
+
* has. They are the codes a service's errors answer with.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ErrCode {
|
|
7
|
+
/** 499. */
|
|
8
|
+
Canceled = "canceled",
|
|
9
|
+
/** 500. */
|
|
10
|
+
Unknown = "unknown",
|
|
11
|
+
/** 400. */
|
|
12
|
+
InvalidArgument = "invalid_argument",
|
|
13
|
+
/** 504. */
|
|
14
|
+
DeadlineExceeded = "deadline_exceeded",
|
|
15
|
+
/** 404. */
|
|
16
|
+
NotFound = "not_found",
|
|
17
|
+
/** 409. */
|
|
18
|
+
AlreadyExists = "already_exists",
|
|
19
|
+
/** 403. */
|
|
20
|
+
PermissionDenied = "permission_denied",
|
|
21
|
+
/** 429. */
|
|
22
|
+
ResourceExhausted = "resource_exhausted",
|
|
23
|
+
/** 400. */
|
|
24
|
+
FailedPrecondition = "failed_precondition",
|
|
25
|
+
/** 409. */
|
|
26
|
+
Aborted = "aborted",
|
|
27
|
+
/** 400. */
|
|
28
|
+
OutOfRange = "out_of_range",
|
|
29
|
+
/** 501. */
|
|
30
|
+
Unimplemented = "unimplemented",
|
|
31
|
+
/** 500. */
|
|
32
|
+
Internal = "internal",
|
|
33
|
+
/** 503. */
|
|
34
|
+
Unavailable = "unavailable",
|
|
35
|
+
/** 500. */
|
|
36
|
+
DataLoss = "data_loss",
|
|
37
|
+
/** 401. */
|
|
38
|
+
Unauthenticated = "unauthenticated"
|
|
39
|
+
}
|
|
40
|
+
/** The HTTP status an answer with `code` has: 401 for
|
|
41
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}, and so
|
|
42
|
+
* on. */
|
|
43
|
+
export declare function httpStatus(code: ErrCode): number;
|
|
44
|
+
/** Response headers: a record, or pairs for a header sent more than once. */
|
|
45
|
+
export type Headers = Record<string, string> | ReadonlyArray<[string, string]>;
|
|
46
|
+
/**
|
|
47
|
+
* A Middleware's answer to a request it does not let through: `onRequest`
|
|
48
|
+
* returns or throws one, and the gateway writes it to the client, with the
|
|
49
|
+
* gateway's CORS headers, rather than forwarding the request.
|
|
50
|
+
*
|
|
51
|
+
* {@link reject} answers as a service answers with an Encore error, which
|
|
52
|
+
* Encore's clients read as one; {@link respond} answers with any response,
|
|
53
|
+
* such as a redirect.
|
|
54
|
+
*/
|
|
55
|
+
export declare class Rejection extends Error {
|
|
56
|
+
name: string;
|
|
57
|
+
/** The HTTP status the request is answered with. */
|
|
58
|
+
readonly status: number;
|
|
59
|
+
/** The Encore error code, for a {@link reject}; undefined for a
|
|
60
|
+
* {@link respond}. */
|
|
61
|
+
readonly code: ErrCode | undefined;
|
|
62
|
+
/** What went wrong, for a {@link reject}; empty for a {@link respond}. */
|
|
63
|
+
readonly errorMessage: string;
|
|
64
|
+
/** The response's headers, as name and value pairs. */
|
|
65
|
+
readonly headers: Array<[string, string]>;
|
|
66
|
+
/** The response's body, for a {@link respond}. */
|
|
67
|
+
readonly body: Uint8Array | undefined;
|
|
68
|
+
/** @internal Made by {@link reject} and {@link respond}. */
|
|
69
|
+
constructor(status: number, code: ErrCode | undefined, message: string, headers: Array<[string, string]>, body: Uint8Array | undefined);
|
|
70
|
+
/** Adds a header to the response, as `Retry-After` to a 429, and returns
|
|
71
|
+
* the rejection. */
|
|
72
|
+
withHeader(name: string, value: string): this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Answers a request with an Encore error with `code` and `message`, and the
|
|
76
|
+
* HTTP status of the code: 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
77
|
+
* {@link ErrCode.PermissionDenied}, 429 for
|
|
78
|
+
* {@link ErrCode.ResourceExhausted}, and so on.
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function reject(code: ErrCode, message: string): Rejection;
|
|
85
|
+
/**
|
|
86
|
+
* Answers a request with `status`, `headers` and `body` as they are, as a
|
|
87
|
+
* redirect to sign in:
|
|
88
|
+
*
|
|
89
|
+
* ```typescript
|
|
90
|
+
* return gateway.respond(302, { location: "/login" });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function respond(status: number, headers?: Headers, body?: Uint8Array | string): Rejection;
|
|
94
|
+
/**
|
|
95
|
+
* The gateway cannot be served: a Middleware is invalid, the process is not
|
|
96
|
+
* a gateway program Encore runs, or the gateway is already served.
|
|
97
|
+
*/
|
|
98
|
+
export declare class GatewayError extends Error {
|
|
99
|
+
name: string;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,OAAO;IACjB,WAAW;IACX,QAAQ,aAAa;IACrB,WAAW;IACX,OAAO,YAAY;IACnB,WAAW;IACX,eAAe,qBAAqB;IACpC,WAAW;IACX,gBAAgB,sBAAsB;IACtC,WAAW;IACX,QAAQ,cAAc;IACtB,WAAW;IACX,aAAa,mBAAmB;IAChC,WAAW;IACX,gBAAgB,sBAAsB;IACtC,WAAW;IACX,iBAAiB,uBAAuB;IACxC,WAAW;IACX,kBAAkB,wBAAwB;IAC1C,WAAW;IACX,OAAO,YAAY;IACnB,WAAW;IACX,UAAU,iBAAiB;IAC3B,WAAW;IACX,aAAa,kBAAkB;IAC/B,WAAW;IACX,QAAQ,aAAa;IACrB,WAAW;IACX,WAAW,gBAAgB;IAC3B,WAAW;IACX,QAAQ,cAAc;IACtB,WAAW;IACX,eAAe,oBAAoB;CACpC;AAqBD;;SAES;AACT,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GA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
|
1
|
+
/**
|
|
2
|
+
* The code of an Encore error, which a {@link reject}ion answers with: what
|
|
3
|
+
* went wrong, as Encore's clients read it, and the HTTP status the answer
|
|
4
|
+
* has. They are the codes a service's errors answer with.
|
|
5
|
+
*/
|
|
6
|
+
export var ErrCode;
|
|
7
|
+
(function (ErrCode) {
|
|
8
|
+
/** 499. */
|
|
9
|
+
ErrCode["Canceled"] = "canceled";
|
|
10
|
+
/** 500. */
|
|
11
|
+
ErrCode["Unknown"] = "unknown";
|
|
12
|
+
/** 400. */
|
|
13
|
+
ErrCode["InvalidArgument"] = "invalid_argument";
|
|
14
|
+
/** 504. */
|
|
15
|
+
ErrCode["DeadlineExceeded"] = "deadline_exceeded";
|
|
16
|
+
/** 404. */
|
|
17
|
+
ErrCode["NotFound"] = "not_found";
|
|
18
|
+
/** 409. */
|
|
19
|
+
ErrCode["AlreadyExists"] = "already_exists";
|
|
20
|
+
/** 403. */
|
|
21
|
+
ErrCode["PermissionDenied"] = "permission_denied";
|
|
22
|
+
/** 429. */
|
|
23
|
+
ErrCode["ResourceExhausted"] = "resource_exhausted";
|
|
24
|
+
/** 400. */
|
|
25
|
+
ErrCode["FailedPrecondition"] = "failed_precondition";
|
|
26
|
+
/** 409. */
|
|
27
|
+
ErrCode["Aborted"] = "aborted";
|
|
28
|
+
/** 400. */
|
|
29
|
+
ErrCode["OutOfRange"] = "out_of_range";
|
|
30
|
+
/** 501. */
|
|
31
|
+
ErrCode["Unimplemented"] = "unimplemented";
|
|
32
|
+
/** 500. */
|
|
33
|
+
ErrCode["Internal"] = "internal";
|
|
34
|
+
/** 503. */
|
|
35
|
+
ErrCode["Unavailable"] = "unavailable";
|
|
36
|
+
/** 500. */
|
|
37
|
+
ErrCode["DataLoss"] = "data_loss";
|
|
38
|
+
/** 401. */
|
|
39
|
+
ErrCode["Unauthenticated"] = "unauthenticated";
|
|
40
|
+
})(ErrCode || (ErrCode = {}));
|
|
41
|
+
const STATUS = {
|
|
42
|
+
[ErrCode.Canceled]: 499,
|
|
43
|
+
[ErrCode.Unknown]: 500,
|
|
44
|
+
[ErrCode.InvalidArgument]: 400,
|
|
45
|
+
[ErrCode.DeadlineExceeded]: 504,
|
|
46
|
+
[ErrCode.NotFound]: 404,
|
|
47
|
+
[ErrCode.AlreadyExists]: 409,
|
|
48
|
+
[ErrCode.PermissionDenied]: 403,
|
|
49
|
+
[ErrCode.ResourceExhausted]: 429,
|
|
50
|
+
[ErrCode.FailedPrecondition]: 400,
|
|
51
|
+
[ErrCode.Aborted]: 409,
|
|
52
|
+
[ErrCode.OutOfRange]: 400,
|
|
53
|
+
[ErrCode.Unimplemented]: 501,
|
|
54
|
+
[ErrCode.Internal]: 500,
|
|
55
|
+
[ErrCode.Unavailable]: 503,
|
|
56
|
+
[ErrCode.DataLoss]: 500,
|
|
57
|
+
[ErrCode.Unauthenticated]: 401,
|
|
58
|
+
};
|
|
59
|
+
/** The HTTP status an answer with `code` has: 401 for
|
|
60
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}, and so
|
|
61
|
+
* on. */
|
|
62
|
+
export function httpStatus(code) {
|
|
63
|
+
return STATUS[code];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A Middleware's answer to a request it does not let through: `onRequest`
|
|
67
|
+
* returns or throws one, and the gateway writes it to the client, with the
|
|
68
|
+
* gateway's CORS headers, rather than forwarding the request.
|
|
69
|
+
*
|
|
70
|
+
* {@link reject} answers as a service answers with an Encore error, which
|
|
71
|
+
* Encore's clients read as one; {@link respond} answers with any response,
|
|
72
|
+
* such as a redirect.
|
|
73
|
+
*/
|
|
74
|
+
export class Rejection extends Error {
|
|
75
|
+
name = 'Rejection';
|
|
76
|
+
/** The HTTP status the request is answered with. */
|
|
77
|
+
status;
|
|
78
|
+
/** The Encore error code, for a {@link reject}; undefined for a
|
|
79
|
+
* {@link respond}. */
|
|
80
|
+
code;
|
|
81
|
+
/** What went wrong, for a {@link reject}; empty for a {@link respond}. */
|
|
82
|
+
errorMessage;
|
|
83
|
+
/** The response's headers, as name and value pairs. */
|
|
84
|
+
headers;
|
|
85
|
+
/** The response's body, for a {@link respond}. */
|
|
86
|
+
body;
|
|
87
|
+
/** @internal Made by {@link reject} and {@link respond}. */
|
|
88
|
+
constructor(status, code, message, headers, body) {
|
|
89
|
+
super(`rejected with ${status}` +
|
|
90
|
+
(code !== undefined ? ` ${code}: ${message}` : ''));
|
|
91
|
+
this.status = status;
|
|
92
|
+
this.code = code;
|
|
93
|
+
this.errorMessage = message;
|
|
94
|
+
this.headers = headers;
|
|
95
|
+
this.body = body;
|
|
96
|
+
}
|
|
97
|
+
/** Adds a header to the response, as `Retry-After` to a 429, and returns
|
|
98
|
+
* the rejection. */
|
|
99
|
+
withHeader(name, value) {
|
|
100
|
+
this.headers.push([name, value]);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Answers a request with an Encore error with `code` and `message`, and the
|
|
106
|
+
* HTTP status of the code: 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
107
|
+
* {@link ErrCode.PermissionDenied}, 429 for
|
|
108
|
+
* {@link ErrCode.ResourceExhausted}, and so on.
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function reject(code, message) {
|
|
115
|
+
if (!(code in REVERSE)) {
|
|
116
|
+
throw new TypeError(`${String(code)} is not an ErrCode`);
|
|
117
|
+
}
|
|
118
|
+
return new Rejection(STATUS[code], code, message, [], undefined);
|
|
119
|
+
}
|
|
120
|
+
const REVERSE = Object.fromEntries(Object.values(ErrCode).map(c => [c, true]));
|
|
121
|
+
/**
|
|
122
|
+
* Answers a request with `status`, `headers` and `body` as they are, as a
|
|
123
|
+
* redirect to sign in:
|
|
124
|
+
*
|
|
125
|
+
* ```typescript
|
|
126
|
+
* return gateway.respond(302, { location: "/login" });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function respond(status, headers = [], body = new Uint8Array()) {
|
|
130
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
131
|
+
throw new RangeError(`status ${status} is not an HTTP status`);
|
|
132
|
+
}
|
|
133
|
+
const pairs = Array.isArray(headers)
|
|
134
|
+
? headers.map(([n, v]) => [n, v])
|
|
135
|
+
: Object.entries(headers);
|
|
136
|
+
const bytes = typeof body === 'string' ? new TextEncoder().encode(body) : body;
|
|
137
|
+
return new Rejection(status, undefined, '', pairs, bytes);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The gateway cannot be served: a Middleware is invalid, the process is not
|
|
141
|
+
* a gateway program Encore runs, or the gateway is already served.
|
|
142
|
+
*/
|
|
143
|
+
export class GatewayError extends Error {
|
|
144
|
+
name = 'GatewayError';
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAiCX;AAjCD,WAAY,OAAO;IACjB,WAAW;IACX,gCAAqB,CAAA;IACrB,WAAW;IACX,8BAAmB,CAAA;IACnB,WAAW;IACX,+CAAoC,CAAA;IACpC,WAAW;IACX,iDAAsC,CAAA;IACtC,WAAW;IACX,iCAAsB,CAAA;IACtB,WAAW;IACX,2CAAgC,CAAA;IAChC,WAAW;IACX,iDAAsC,CAAA;IACtC,WAAW;IACX,mDAAwC,CAAA;IACxC,WAAW;IACX,qDAA0C,CAAA;IAC1C,WAAW;IACX,8BAAmB,CAAA;IACnB,WAAW;IACX,sCAA2B,CAAA;IAC3B,WAAW;IACX,0CAA+B,CAAA;IAC/B,WAAW;IACX,gCAAqB,CAAA;IACrB,WAAW;IACX,sCAA2B,CAAA;IAC3B,WAAW;IACX,iCAAsB,CA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,CACrB,MAAc,EACd,UAAmB,EAAE,EACrB,OAA4B,IAAI,UAAU,EAAE;IAE5C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;QAC9D,MAAM,IAAI,UAAU,CAAC,UAAU,MAAM,wBAAwB,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,KAAK,GAA4B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAC3D,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAiC,CAAC,CAAC;IACtD,MAAM,KAAK,GACT,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,GAAG,cAAc,CAAC;CAChC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which requests a Middleware is called for.
|
|
3
|
+
*
|
|
4
|
+
* A {@link Matcher} is checked by Encore before a request reaches
|
|
5
|
+
* JavaScript: a request no Middleware matches costs the program nothing.
|
|
6
|
+
* Matching sees the request as the client sent it, so the header edits of an
|
|
7
|
+
* earlier Middleware do not change which later ones are called, and a
|
|
8
|
+
* Middleware need not read what it matches on.
|
|
9
|
+
*
|
|
10
|
+
* Matchers combine with `.and()`, `.or()` and `.not()`, or {@link allOf},
|
|
11
|
+
* {@link anyOf} and {@link not}:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { match } from "@encore.dev/sdk/gateway";
|
|
15
|
+
*
|
|
16
|
+
* const admin = match.pathPrefix("/admin").and(match.method("OPTIONS").not());
|
|
17
|
+
* const bearer = match.header("authorization", match.prefix("Bearer "));
|
|
18
|
+
* const either = match.service("billing", "orders").or(match.route("GET", "/users/{id}"));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
/** A matcher or condition as the gateway core's JSON spells it. */
|
|
24
|
+
type Expr = Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* A condition on a request: on its service, route, method, path, headers,
|
|
27
|
+
* query parameters or cookies. Made by this module's functions.
|
|
28
|
+
*/
|
|
29
|
+
export declare class Matcher {
|
|
30
|
+
/** @internal */
|
|
31
|
+
readonly expr: Expr;
|
|
32
|
+
/** @internal */
|
|
33
|
+
constructor(expr: Expr);
|
|
34
|
+
/** Matches the requests both match. */
|
|
35
|
+
and(other: Matcher): Matcher;
|
|
36
|
+
/** Matches the requests either matches. */
|
|
37
|
+
or(other: Matcher): Matcher;
|
|
38
|
+
/** Matches the requests this does not. */
|
|
39
|
+
not(): Matcher;
|
|
40
|
+
/** The matcher as the gateway core's JSON spells it. */
|
|
41
|
+
toJSON(): Expr;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What a header, query parameter or cookie must be, for {@link header},
|
|
45
|
+
* {@link query} and {@link cookie}. One sent more than once satisfies a
|
|
46
|
+
* condition, other than {@link absent}, when any of its values does. Made by
|
|
47
|
+
* this module's functions.
|
|
48
|
+
*/
|
|
49
|
+
export declare class Cond {
|
|
50
|
+
/** @internal */
|
|
51
|
+
readonly expr: Expr;
|
|
52
|
+
/** @internal */
|
|
53
|
+
constructor(expr: Expr);
|
|
54
|
+
/** The condition as the gateway core's JSON spells it. */
|
|
55
|
+
toJSON(): Expr;
|
|
56
|
+
}
|
|
57
|
+
/** Matches the requests every one of `ms` matches: every request when there
|
|
58
|
+
* are none. */
|
|
59
|
+
export declare function allOf(...ms: Matcher[]): Matcher;
|
|
60
|
+
/** Matches the requests any of `ms` matches: none when there are none. */
|
|
61
|
+
export declare function anyOf(...ms: Matcher[]): Matcher;
|
|
62
|
+
/** Matches the requests `m` does not, as `m.not()`. */
|
|
63
|
+
export declare function not(m: Matcher): Matcher;
|
|
64
|
+
/** Matches the requests the gateway routes to any of `services`. */
|
|
65
|
+
export declare function service(...services: string[]): Matcher;
|
|
66
|
+
/**
|
|
67
|
+
* Matches the requests routed by the gateway's route with `template`, such
|
|
68
|
+
* as `/users/{id}`, answering `method`, or any method when it is undefined.
|
|
69
|
+
* The names of the template's parameters do not matter, as they do not to
|
|
70
|
+
* the router: `/users/{userId}` names the same route.
|
|
71
|
+
*/
|
|
72
|
+
export declare function route(method: string | undefined, template: string): Matcher;
|
|
73
|
+
/** Matches the requests with any of `methods`, such as `"POST"`. */
|
|
74
|
+
export declare function method(...methods: string[]): Matcher;
|
|
75
|
+
/**
|
|
76
|
+
* Matches the requests for exactly `path`, as the client sent it, not
|
|
77
|
+
* percent-decoded. A trailing slash does not matter, as it does not to the
|
|
78
|
+
* router.
|
|
79
|
+
*/
|
|
80
|
+
export declare function path(path: string): Matcher;
|
|
81
|
+
/**
|
|
82
|
+
* Matches the requests whose path starts with `prefix`, by whole segments:
|
|
83
|
+
* `/admin` matches `/admin` and `/admin/users`, not `/administrators`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function pathPrefix(prefix: string): Matcher;
|
|
86
|
+
/**
|
|
87
|
+
* Matches the requests whose path the glob matches: a `*` segment matches
|
|
88
|
+
* any one segment, and a `**` segment any number of them, none included.
|
|
89
|
+
* `/users/*` matches `/users/1`, and `/users/**` matches `/users` and
|
|
90
|
+
* `/users/1/posts/2`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function pathGlob(glob: string): Matcher;
|
|
93
|
+
/**
|
|
94
|
+
* Matches the requests whose header `name` satisfies `cond`, or is sent,
|
|
95
|
+
* without one. Header names are case-insensitive; values are compared as
|
|
96
|
+
* sent.
|
|
97
|
+
*/
|
|
98
|
+
export declare function header(name: string, cond?: Cond): Matcher;
|
|
99
|
+
/**
|
|
100
|
+
* Matches the requests whose query parameter `name` satisfies `cond`, or is
|
|
101
|
+
* sent, without one. Names are case-sensitive; values are percent-decoded
|
|
102
|
+
* before they are compared.
|
|
103
|
+
*/
|
|
104
|
+
export declare function query(name: string, cond?: Cond): Matcher;
|
|
105
|
+
/**
|
|
106
|
+
* Matches the requests whose cookie `name` satisfies `cond`, or is sent,
|
|
107
|
+
* without one. Names are case-sensitive; values are compared as sent.
|
|
108
|
+
*/
|
|
109
|
+
export declare function cookie(name: string, cond?: Cond): Matcher;
|
|
110
|
+
/** Holds when the field is sent. */
|
|
111
|
+
export declare function present(): Cond;
|
|
112
|
+
/** Holds when the field is not sent. */
|
|
113
|
+
export declare function absent(): Cond;
|
|
114
|
+
/** Holds when the field's value is `value`. */
|
|
115
|
+
export declare function equals(value: string): Cond;
|
|
116
|
+
/** Holds when the field's value starts with `prefix`, as `"Bearer "`. */
|
|
117
|
+
export declare function prefix(prefix: string): Cond;
|
|
118
|
+
/** Holds when the field's value is one of `values`. */
|
|
119
|
+
export declare function oneOf(...values: string[]): Cond;
|
|
120
|
+
/**
|
|
121
|
+
* Holds when the regular expression matches the field's whole value. In RE2
|
|
122
|
+
* syntax, not JavaScript's: Encore checks it before a request reaches
|
|
123
|
+
* JavaScript. An invalid one makes `serve` fail.
|
|
124
|
+
*/
|
|
125
|
+
export declare function regex(pattern: string): Cond;
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../gateway/match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,mEAAmE;AACnE,KAAK,IAAI,GAAG,MAAM,CAAC,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,GAAG,OAAO,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9C;AAUD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,CAExD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,CAEzD;AAED,oCAAoC;AACpC,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED,wCAAwC;AACxC,wBAAgB,MAAM,IAAI,IAAI,CAE7B;AAED,+CAA+C;AAC/C,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,yEAAyE;AACzE,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3C"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which requests a Middleware is called for.
|
|
3
|
+
*
|
|
4
|
+
* A {@link Matcher} is checked by Encore before a request reaches
|
|
5
|
+
* JavaScript: a request no Middleware matches costs the program nothing.
|
|
6
|
+
* Matching sees the request as the client sent it, so the header edits of an
|
|
7
|
+
* earlier Middleware do not change which later ones are called, and a
|
|
8
|
+
* Middleware need not read what it matches on.
|
|
9
|
+
*
|
|
10
|
+
* Matchers combine with `.and()`, `.or()` and `.not()`, or {@link allOf},
|
|
11
|
+
* {@link anyOf} and {@link not}:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { match } from "@encore.dev/sdk/gateway";
|
|
15
|
+
*
|
|
16
|
+
* const admin = match.pathPrefix("/admin").and(match.method("OPTIONS").not());
|
|
17
|
+
* const bearer = match.header("authorization", match.prefix("Bearer "));
|
|
18
|
+
* const either = match.service("billing", "orders").or(match.route("GET", "/users/{id}"));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* A condition on a request: on its service, route, method, path, headers,
|
|
25
|
+
* query parameters or cookies. Made by this module's functions.
|
|
26
|
+
*/
|
|
27
|
+
export class Matcher {
|
|
28
|
+
/** @internal */
|
|
29
|
+
expr;
|
|
30
|
+
/** @internal */
|
|
31
|
+
constructor(expr) {
|
|
32
|
+
this.expr = expr;
|
|
33
|
+
}
|
|
34
|
+
/** Matches the requests both match. */
|
|
35
|
+
and(other) {
|
|
36
|
+
return allOf(this, other);
|
|
37
|
+
}
|
|
38
|
+
/** Matches the requests either matches. */
|
|
39
|
+
or(other) {
|
|
40
|
+
return anyOf(this, other);
|
|
41
|
+
}
|
|
42
|
+
/** Matches the requests this does not. */
|
|
43
|
+
not() {
|
|
44
|
+
return not(this);
|
|
45
|
+
}
|
|
46
|
+
/** The matcher as the gateway core's JSON spells it. */
|
|
47
|
+
toJSON() {
|
|
48
|
+
return this.expr;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* What a header, query parameter or cookie must be, for {@link header},
|
|
53
|
+
* {@link query} and {@link cookie}. One sent more than once satisfies a
|
|
54
|
+
* condition, other than {@link absent}, when any of its values does. Made by
|
|
55
|
+
* this module's functions.
|
|
56
|
+
*/
|
|
57
|
+
export class Cond {
|
|
58
|
+
/** @internal */
|
|
59
|
+
expr;
|
|
60
|
+
/** @internal */
|
|
61
|
+
constructor(expr) {
|
|
62
|
+
this.expr = expr;
|
|
63
|
+
}
|
|
64
|
+
/** The condition as the gateway core's JSON spells it. */
|
|
65
|
+
toJSON() {
|
|
66
|
+
return this.expr;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function matchers(what, ms) {
|
|
70
|
+
return ms.map(m => {
|
|
71
|
+
if (!(m instanceof Matcher)) {
|
|
72
|
+
throw new TypeError(`match.${what} takes Matchers, not ${describe(m)}`);
|
|
73
|
+
}
|
|
74
|
+
return m.expr;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function strings(what, values) {
|
|
78
|
+
for (const v of values) {
|
|
79
|
+
if (typeof v !== 'string') {
|
|
80
|
+
throw new TypeError(`match.${what} takes strings, not ${describe(v)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [...values];
|
|
84
|
+
}
|
|
85
|
+
function describe(v) {
|
|
86
|
+
return v === null
|
|
87
|
+
? 'null'
|
|
88
|
+
: typeof v === 'object'
|
|
89
|
+
? v.constructor.name
|
|
90
|
+
: typeof v;
|
|
91
|
+
}
|
|
92
|
+
/** Matches the requests every one of `ms` matches: every request when there
|
|
93
|
+
* are none. */
|
|
94
|
+
export function allOf(...ms) {
|
|
95
|
+
return new Matcher({ all: matchers('allOf', ms) });
|
|
96
|
+
}
|
|
97
|
+
/** Matches the requests any of `ms` matches: none when there are none. */
|
|
98
|
+
export function anyOf(...ms) {
|
|
99
|
+
return new Matcher({ anyOf: matchers('anyOf', ms) });
|
|
100
|
+
}
|
|
101
|
+
/** Matches the requests `m` does not, as `m.not()`. */
|
|
102
|
+
export function not(m) {
|
|
103
|
+
return new Matcher({ not: matchers('not', [m])[0] });
|
|
104
|
+
}
|
|
105
|
+
/** Matches the requests the gateway routes to any of `services`. */
|
|
106
|
+
export function service(...services) {
|
|
107
|
+
return new Matcher({ service: strings('service', services) });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Matches the requests routed by the gateway's route with `template`, such
|
|
111
|
+
* as `/users/{id}`, answering `method`, or any method when it is undefined.
|
|
112
|
+
* The names of the template's parameters do not matter, as they do not to
|
|
113
|
+
* the router: `/users/{userId}` names the same route.
|
|
114
|
+
*/
|
|
115
|
+
export function route(method, template) {
|
|
116
|
+
return new Matcher({
|
|
117
|
+
route: method === undefined ? { template } : { method, template },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** Matches the requests with any of `methods`, such as `"POST"`. */
|
|
121
|
+
export function method(...methods) {
|
|
122
|
+
return new Matcher({ method: strings('method', methods) });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Matches the requests for exactly `path`, as the client sent it, not
|
|
126
|
+
* percent-decoded. A trailing slash does not matter, as it does not to the
|
|
127
|
+
* router.
|
|
128
|
+
*/
|
|
129
|
+
export function path(path) {
|
|
130
|
+
return new Matcher({ path: { exact: path } });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Matches the requests whose path starts with `prefix`, by whole segments:
|
|
134
|
+
* `/admin` matches `/admin` and `/admin/users`, not `/administrators`.
|
|
135
|
+
*/
|
|
136
|
+
export function pathPrefix(prefix) {
|
|
137
|
+
return new Matcher({ path: { prefix } });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Matches the requests whose path the glob matches: a `*` segment matches
|
|
141
|
+
* any one segment, and a `**` segment any number of them, none included.
|
|
142
|
+
* `/users/*` matches `/users/1`, and `/users/**` matches `/users` and
|
|
143
|
+
* `/users/1/posts/2`.
|
|
144
|
+
*/
|
|
145
|
+
export function pathGlob(glob) {
|
|
146
|
+
return new Matcher({ path: { glob } });
|
|
147
|
+
}
|
|
148
|
+
function field(kind, name, cond) {
|
|
149
|
+
const c = cond ?? present();
|
|
150
|
+
if (!(c instanceof Cond)) {
|
|
151
|
+
throw new TypeError(`match.${kind} takes a Cond, not ${describe(c)}`);
|
|
152
|
+
}
|
|
153
|
+
return new Matcher({ [kind]: { name, cond: c.expr } });
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Matches the requests whose header `name` satisfies `cond`, or is sent,
|
|
157
|
+
* without one. Header names are case-insensitive; values are compared as
|
|
158
|
+
* sent.
|
|
159
|
+
*/
|
|
160
|
+
export function header(name, cond) {
|
|
161
|
+
return field('header', name, cond);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Matches the requests whose query parameter `name` satisfies `cond`, or is
|
|
165
|
+
* sent, without one. Names are case-sensitive; values are percent-decoded
|
|
166
|
+
* before they are compared.
|
|
167
|
+
*/
|
|
168
|
+
export function query(name, cond) {
|
|
169
|
+
return field('query', name, cond);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Matches the requests whose cookie `name` satisfies `cond`, or is sent,
|
|
173
|
+
* without one. Names are case-sensitive; values are compared as sent.
|
|
174
|
+
*/
|
|
175
|
+
export function cookie(name, cond) {
|
|
176
|
+
return field('cookie', name, cond);
|
|
177
|
+
}
|
|
178
|
+
/** Holds when the field is sent. */
|
|
179
|
+
export function present() {
|
|
180
|
+
return new Cond({ present: true });
|
|
181
|
+
}
|
|
182
|
+
/** Holds when the field is not sent. */
|
|
183
|
+
export function absent() {
|
|
184
|
+
return new Cond({ absent: true });
|
|
185
|
+
}
|
|
186
|
+
/** Holds when the field's value is `value`. */
|
|
187
|
+
export function equals(value) {
|
|
188
|
+
return new Cond({ equals: value });
|
|
189
|
+
}
|
|
190
|
+
/** Holds when the field's value starts with `prefix`, as `"Bearer "`. */
|
|
191
|
+
export function prefix(prefix) {
|
|
192
|
+
return new Cond({ prefix });
|
|
193
|
+
}
|
|
194
|
+
/** Holds when the field's value is one of `values`. */
|
|
195
|
+
export function oneOf(...values) {
|
|
196
|
+
return new Cond({ oneOf: strings('oneOf', values) });
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Holds when the regular expression matches the field's whole value. In RE2
|
|
200
|
+
* syntax, not JavaScript's: Encore checks it before a request reaches
|
|
201
|
+
* JavaScript. An invalid one makes `serve` fail.
|
|
202
|
+
*/
|
|
203
|
+
export function regex(pattern) {
|
|
204
|
+
return new Cond({ regex: pattern });
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../gateway/match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH;;;GAGG;AACH,MAAM,OAAO,OAAO;IAClB,gBAAgB;IACP,IAAI,CAAO;IAEpB,gBAAgB;IAChB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,uCAAuC;IACvC,GAAG,CAAC,KAAc;QAChB,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,2CAA2C;IAC3C,EAAE,CAAC,KAAc;QACf,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,0CAA0C;IAC1C,GAAG;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,wDAAwD;IACxD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,IAAI;IACf,gBAAgB;IACP,IAAI,CAAO;IAEpB,gBAAgB;IAChB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,0DAA0D;IAC1D,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,EAAsB;IACpD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QAChB,IAAI,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,SAAS,CAAC,SAAS,IAAI,wBAAwB,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC1E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