@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17
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 +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
package/dist/frontends/mod.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Look up the URLs where the application's frontends are served.
|
|
3
3
|
*
|
|
4
|
-
* {@link url}
|
|
5
|
-
*
|
|
4
|
+
* {@link url} returns a frontend's base URL in the current environment, for
|
|
5
|
+
* example when redirecting a user or constructing links to frontend pages:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* import * as frontends from '@encore.dev/sdk/frontends';
|
|
@@ -10,26 +10,27 @@
|
|
|
10
10
|
* const reset = `${frontends.url('web')}/reset?token=${token}`;
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Calling `url()` registers a dependency from the calling service to that
|
|
14
|
+
* frontend. Because Encore resolves these references statically, the frontend
|
|
15
|
+
* name must be a string literal matching the frontend's declared name, `url`
|
|
16
|
+
* must be called directly (not aliased or passed around), and the call must
|
|
17
|
+
* appear inside a service.
|
|
18
18
|
*
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* `
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
22
|
+
* Returns the base URL where `frontend` is served in this environment, without
|
|
23
|
+
* a trailing slash (so paths can be appended directly, e.g.
|
|
24
|
+
* `` `${url("web")}/reset` ``). This is the first origin listed for the
|
|
25
|
+
* frontend in {@link appMeta}.
|
|
26
|
+
*
|
|
27
|
+
* The name must match the frontend's declared name in `encore.frontend.json`
|
|
28
|
+
* (or the hosting service's name): for example, `"web_app"` will not match
|
|
29
|
+
* `"web-app"`.
|
|
30
|
+
*
|
|
31
|
+
* Throws if no URL is available for `frontend` — either because no frontend
|
|
32
|
+
* with that name exists in the app (which Encore's parser reports) or because
|
|
33
|
+
* no origins are configured for it in this environment.
|
|
33
34
|
*
|
|
34
35
|
* @example
|
|
35
36
|
* import {url} from "@encore.dev/sdk/frontends";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAS5C"}
|
package/dist/frontends/mod.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Look up the URLs where the application's frontends are served.
|
|
3
3
|
*
|
|
4
|
-
* {@link url}
|
|
5
|
-
*
|
|
4
|
+
* {@link url} returns a frontend's base URL in the current environment, for
|
|
5
|
+
* example when redirecting a user or constructing links to frontend pages:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* import * as frontends from '@encore.dev/sdk/frontends';
|
|
@@ -10,27 +10,28 @@
|
|
|
10
10
|
* const reset = `${frontends.url('web')}/reset?token=${token}`;
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Calling `url()` registers a dependency from the calling service to that
|
|
14
|
+
* frontend. Because Encore resolves these references statically, the frontend
|
|
15
|
+
* name must be a string literal matching the frontend's declared name, `url`
|
|
16
|
+
* must be called directly (not aliased or passed around), and the call must
|
|
17
|
+
* appear inside a service.
|
|
18
18
|
*
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
import { appMeta } from '../app_meta.js';
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* Returns the base URL where `frontend` is served in this environment, without
|
|
24
|
+
* a trailing slash (so paths can be appended directly, e.g.
|
|
25
|
+
* `` `${url("web")}/reset` ``). This is the first origin listed for the
|
|
26
|
+
* frontend in {@link appMeta}.
|
|
26
27
|
*
|
|
27
|
-
* The name
|
|
28
|
-
*
|
|
29
|
-
* `web-app`.
|
|
28
|
+
* The name must match the frontend's declared name in `encore.frontend.json`
|
|
29
|
+
* (or the hosting service's name): for example, `"web_app"` will not match
|
|
30
|
+
* `"web-app"`.
|
|
30
31
|
*
|
|
31
|
-
* Throws if
|
|
32
|
-
* that name
|
|
33
|
-
* origins.
|
|
32
|
+
* Throws if no URL is available for `frontend` — either because no frontend
|
|
33
|
+
* with that name exists in the app (which Encore's parser reports) or because
|
|
34
|
+
* no origins are configured for it in this environment.
|
|
34
35
|
*
|
|
35
36
|
* @example
|
|
36
37
|
* import {url} from "@encore.dev/sdk/frontends";
|
|
@@ -39,8 +40,8 @@ import { appMeta } from '../app_meta.js';
|
|
|
39
40
|
export function url(frontend) {
|
|
40
41
|
const found = appMeta().frontends[frontend]?.origins[0]?.replace(/\/+$/, '');
|
|
41
42
|
if (!found) {
|
|
42
|
-
throw new Error(`encore: no URL is known for frontend ${JSON.stringify(frontend)}:
|
|
43
|
-
'frontend
|
|
43
|
+
throw new Error(`encore: no URL is known for frontend ${JSON.stringify(frontend)}: ` +
|
|
44
|
+
'no frontend with that name exists, or no origins are configured for it in this environment');
|
|
44
45
|
}
|
|
45
46
|
return found;
|
|
46
47
|
}
|
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../frontends/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;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,IAAI;YAClE,4FAA4F,CAC/F,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/gateway/errors.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* has. They are the codes a service's errors answer with.
|
|
2
|
+
* Standard Encore error codes used with {@link reject}, matching the error
|
|
3
|
+
* codes returned by Encore services and their corresponding HTTP status codes.
|
|
5
4
|
*/
|
|
6
5
|
export declare enum ErrCode {
|
|
7
6
|
/** 499. */
|
|
@@ -37,45 +36,43 @@ export declare enum ErrCode {
|
|
|
37
36
|
/** 401. */
|
|
38
37
|
Unauthenticated = "unauthenticated"
|
|
39
38
|
}
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
/**
|
|
40
|
+
* Returns the HTTP status code corresponding to `code` (e.g. 401 for
|
|
41
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}).
|
|
42
|
+
*/
|
|
43
43
|
export declare function httpStatus(code: ErrCode): number;
|
|
44
|
-
/** Response headers
|
|
44
|
+
/** Response headers, either as a record or as name-value pairs for repeated headers. */
|
|
45
45
|
export type Headers = Record<string, string> | ReadonlyArray<[string, string]>;
|
|
46
46
|
/**
|
|
47
|
-
* A
|
|
48
|
-
*
|
|
49
|
-
* gateway's CORS headers
|
|
47
|
+
* A middleware response that short-circuits a request in `onRequest`. Return
|
|
48
|
+
* or throw a `Rejection` to have the gateway respond directly to the client
|
|
49
|
+
* (including the gateway's CORS headers) without forwarding the request.
|
|
50
50
|
*
|
|
51
|
-
* {@link reject}
|
|
52
|
-
*
|
|
53
|
-
* such as a redirect.
|
|
51
|
+
* Create one with {@link reject} for a standard Encore error response, or
|
|
52
|
+
* {@link respond} for a custom HTTP response such as a redirect.
|
|
54
53
|
*/
|
|
55
54
|
export declare class Rejection extends Error {
|
|
56
55
|
name: string;
|
|
57
|
-
/** The HTTP status
|
|
56
|
+
/** The HTTP status code sent to the client. */
|
|
58
57
|
readonly status: number;
|
|
59
|
-
/** The Encore error code
|
|
60
|
-
* {@link respond}. */
|
|
58
|
+
/** The Encore error code (set for {@link reject}, undefined for {@link respond}). */
|
|
61
59
|
readonly code: ErrCode | undefined;
|
|
62
|
-
/**
|
|
60
|
+
/** The error message (set for {@link reject}, empty for {@link respond}). */
|
|
63
61
|
readonly errorMessage: string;
|
|
64
|
-
/** The response
|
|
62
|
+
/** The response headers as `[name, value]` pairs. */
|
|
65
63
|
readonly headers: Array<[string, string]>;
|
|
66
|
-
/** The response
|
|
64
|
+
/** The raw response body (set for {@link respond}). */
|
|
67
65
|
readonly body: Uint8Array | undefined;
|
|
68
|
-
/** @internal
|
|
66
|
+
/** @internal Created by {@link reject} and {@link respond}. */
|
|
69
67
|
constructor(status: number, code: ErrCode | undefined, message: string, headers: Array<[string, string]>, body: Uint8Array | undefined);
|
|
70
|
-
/**
|
|
71
|
-
* the rejection. */
|
|
68
|
+
/** Appends a header (such as `Retry-After` on a 429) and returns `this`. */
|
|
72
69
|
withHeader(name: string, value: string): this;
|
|
73
70
|
}
|
|
74
71
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* {@link ErrCode.
|
|
78
|
-
* {@link ErrCode.
|
|
72
|
+
* Creates a {@link Rejection} that responds with a standard Encore error
|
|
73
|
+
* containing `code` and `message`, using the HTTP status mapped from `code`
|
|
74
|
+
* (e.g. 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
75
|
+
* {@link ErrCode.PermissionDenied}, 429 for {@link ErrCode.ResourceExhausted}).
|
|
79
76
|
*
|
|
80
77
|
* ```typescript
|
|
81
78
|
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
@@ -83,8 +80,8 @@ export declare class Rejection extends Error {
|
|
|
83
80
|
*/
|
|
84
81
|
export declare function reject(code: ErrCode, message: string): Rejection;
|
|
85
82
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
* Creates a {@link Rejection} that responds directly with `status`, `headers`,
|
|
84
|
+
* and `body`, for example to issue a redirect:
|
|
88
85
|
*
|
|
89
86
|
* ```typescript
|
|
90
87
|
* return gateway.respond(302, { location: "/login" });
|
|
@@ -92,8 +89,9 @@ export declare function reject(code: ErrCode, message: string): Rejection;
|
|
|
92
89
|
*/
|
|
93
90
|
export declare function respond(status: number, headers?: Headers, body?: Uint8Array | string): Rejection;
|
|
94
91
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
92
|
+
* Thrown when the gateway cannot be started — for example, when a middleware
|
|
93
|
+
* definition is invalid, the process is not running as an Encore gateway, or
|
|
94
|
+
* `serve` has already been called.
|
|
97
95
|
*/
|
|
98
96
|
export declare class GatewayError extends Error {
|
|
99
97
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;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;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,wFAAwF;AACxF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE/E;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,KAAK;IACzB,IAAI,SAAe;IAE5B,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAEtC,+DAA+D;gBAE7D,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAChC,IAAI,EAAE,UAAU,GAAG,SAAS;IAa9B,4EAA4E;IAC5E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAI9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAKhE;AAMD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAY,EACrB,IAAI,GAAE,UAAU,GAAG,MAAyB,GAC3C,SAAS,CAUX;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC"}
|
package/dist/gateway/errors.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* has. They are the codes a service's errors answer with.
|
|
2
|
+
* Standard Encore error codes used with {@link reject}, matching the error
|
|
3
|
+
* codes returned by Encore services and their corresponding HTTP status codes.
|
|
5
4
|
*/
|
|
6
5
|
export var ErrCode;
|
|
7
6
|
(function (ErrCode) {
|
|
@@ -56,35 +55,34 @@ const STATUS = {
|
|
|
56
55
|
[ErrCode.DataLoss]: 500,
|
|
57
56
|
[ErrCode.Unauthenticated]: 401,
|
|
58
57
|
};
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
58
|
+
/**
|
|
59
|
+
* Returns the HTTP status code corresponding to `code` (e.g. 401 for
|
|
60
|
+
* {@link ErrCode.Unauthenticated}, 404 for {@link ErrCode.NotFound}).
|
|
61
|
+
*/
|
|
62
62
|
export function httpStatus(code) {
|
|
63
63
|
return STATUS[code];
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* A
|
|
67
|
-
*
|
|
68
|
-
* gateway's CORS headers
|
|
66
|
+
* A middleware response that short-circuits a request in `onRequest`. Return
|
|
67
|
+
* or throw a `Rejection` to have the gateway respond directly to the client
|
|
68
|
+
* (including the gateway's CORS headers) without forwarding the request.
|
|
69
69
|
*
|
|
70
|
-
* {@link reject}
|
|
71
|
-
*
|
|
72
|
-
* such as a redirect.
|
|
70
|
+
* Create one with {@link reject} for a standard Encore error response, or
|
|
71
|
+
* {@link respond} for a custom HTTP response such as a redirect.
|
|
73
72
|
*/
|
|
74
73
|
export class Rejection extends Error {
|
|
75
74
|
name = 'Rejection';
|
|
76
|
-
/** The HTTP status
|
|
75
|
+
/** The HTTP status code sent to the client. */
|
|
77
76
|
status;
|
|
78
|
-
/** The Encore error code
|
|
79
|
-
* {@link respond}. */
|
|
77
|
+
/** The Encore error code (set for {@link reject}, undefined for {@link respond}). */
|
|
80
78
|
code;
|
|
81
|
-
/**
|
|
79
|
+
/** The error message (set for {@link reject}, empty for {@link respond}). */
|
|
82
80
|
errorMessage;
|
|
83
|
-
/** The response
|
|
81
|
+
/** The response headers as `[name, value]` pairs. */
|
|
84
82
|
headers;
|
|
85
|
-
/** The response
|
|
83
|
+
/** The raw response body (set for {@link respond}). */
|
|
86
84
|
body;
|
|
87
|
-
/** @internal
|
|
85
|
+
/** @internal Created by {@link reject} and {@link respond}. */
|
|
88
86
|
constructor(status, code, message, headers, body) {
|
|
89
87
|
super(`rejected with ${status}` +
|
|
90
88
|
(code !== undefined ? ` ${code}: ${message}` : ''));
|
|
@@ -94,18 +92,17 @@ export class Rejection extends Error {
|
|
|
94
92
|
this.headers = headers;
|
|
95
93
|
this.body = body;
|
|
96
94
|
}
|
|
97
|
-
/**
|
|
98
|
-
* the rejection. */
|
|
95
|
+
/** Appends a header (such as `Retry-After` on a 429) and returns `this`. */
|
|
99
96
|
withHeader(name, value) {
|
|
100
97
|
this.headers.push([name, value]);
|
|
101
98
|
return this;
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
101
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* {@link ErrCode.
|
|
108
|
-
* {@link ErrCode.
|
|
102
|
+
* Creates a {@link Rejection} that responds with a standard Encore error
|
|
103
|
+
* containing `code` and `message`, using the HTTP status mapped from `code`
|
|
104
|
+
* (e.g. 401 for {@link ErrCode.Unauthenticated}, 403 for
|
|
105
|
+
* {@link ErrCode.PermissionDenied}, 429 for {@link ErrCode.ResourceExhausted}).
|
|
109
106
|
*
|
|
110
107
|
* ```typescript
|
|
111
108
|
* return gateway.reject(ErrCode.Unauthenticated, "missing token");
|
|
@@ -113,14 +110,14 @@ export class Rejection extends Error {
|
|
|
113
110
|
*/
|
|
114
111
|
export function reject(code, message) {
|
|
115
112
|
if (!(code in REVERSE)) {
|
|
116
|
-
throw new TypeError(`${String(code)} is not
|
|
113
|
+
throw new TypeError(`${String(code)} is not a valid ErrCode`);
|
|
117
114
|
}
|
|
118
115
|
return new Rejection(STATUS[code], code, message, [], undefined);
|
|
119
116
|
}
|
|
120
117
|
const REVERSE = Object.fromEntries(Object.values(ErrCode).map(c => [c, true]));
|
|
121
118
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
119
|
+
* Creates a {@link Rejection} that responds directly with `status`, `headers`,
|
|
120
|
+
* and `body`, for example to issue a redirect:
|
|
124
121
|
*
|
|
125
122
|
* ```typescript
|
|
126
123
|
* return gateway.respond(302, { location: "/login" });
|
|
@@ -128,7 +125,7 @@ const REVERSE = Object.fromEntries(Object.values(ErrCode).map(c => [c, true]));
|
|
|
128
125
|
*/
|
|
129
126
|
export function respond(status, headers = [], body = new Uint8Array()) {
|
|
130
127
|
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
131
|
-
throw new RangeError(`status ${status} is not
|
|
128
|
+
throw new RangeError(`status ${status} is not a valid HTTP status code`);
|
|
132
129
|
}
|
|
133
130
|
const pairs = Array.isArray(headers)
|
|
134
131
|
? headers.map(([n, v]) => [n, v])
|
|
@@ -137,8 +134,9 @@ export function respond(status, headers = [], body = new Uint8Array()) {
|
|
|
137
134
|
return new Rejection(status, undefined, '', pairs, bytes);
|
|
138
135
|
}
|
|
139
136
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
137
|
+
* Thrown when the gateway cannot be started — for example, when a middleware
|
|
138
|
+
* definition is invalid, the process is not running as an Encore gateway, or
|
|
139
|
+
* `serve` has already been called.
|
|
142
140
|
*/
|
|
143
141
|
export class GatewayError extends Error {
|
|
144
142
|
name = 'GatewayError';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../gateway/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;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;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;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,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,kCAAkC,CAAC,CAAC;IAC3E,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;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,GAAG,cAAc,CAAC;CAChC"}
|
package/dist/gateway/match.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Matchers that select which requests trigger a middleware.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* JavaScript
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Encore evaluates every {@link Matcher} natively before a request reaches
|
|
5
|
+
* JavaScript, so unmatched requests incur no JS overhead. Matchers inspect the
|
|
6
|
+
* original client request — header edits by earlier middleware do not affect
|
|
7
|
+
* which later middleware run — and a middleware does not need to read a field
|
|
8
|
+
* in order to match on it.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* {@link anyOf} and {@link not}:
|
|
10
|
+
* Combine matchers with `.and()`, `.or()`, and `.not()`, or with {@link allOf},
|
|
11
|
+
* {@link anyOf}, and {@link not}:
|
|
12
12
|
*
|
|
13
13
|
* ```typescript
|
|
14
14
|
* import { match } from "@encore.dev/sdk/gateway";
|
|
@@ -20,107 +20,107 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @module
|
|
22
22
|
*/
|
|
23
|
-
/**
|
|
23
|
+
/** Serialized matcher or condition JSON consumed by the gateway core. */
|
|
24
24
|
type Expr = Record<string, unknown>;
|
|
25
25
|
/**
|
|
26
|
-
* A
|
|
27
|
-
* query parameters or cookies.
|
|
26
|
+
* A predicate over incoming requests (by service, route, method, path,
|
|
27
|
+
* headers, query parameters, or cookies). Construct matchers using the
|
|
28
|
+
* functions in this module.
|
|
28
29
|
*/
|
|
29
30
|
export declare class Matcher {
|
|
30
31
|
/** @internal */
|
|
31
32
|
readonly expr: Expr;
|
|
32
33
|
/** @internal */
|
|
33
34
|
constructor(expr: Expr);
|
|
34
|
-
/** Matches
|
|
35
|
+
/** Matches requests that satisfy both this matcher and `other`. */
|
|
35
36
|
and(other: Matcher): Matcher;
|
|
36
|
-
/** Matches
|
|
37
|
+
/** Matches requests that satisfy either this matcher or `other`. */
|
|
37
38
|
or(other: Matcher): Matcher;
|
|
38
|
-
/** Matches
|
|
39
|
+
/** Matches requests that do not satisfy this matcher. */
|
|
39
40
|
not(): Matcher;
|
|
40
|
-
/**
|
|
41
|
+
/** Serializes the matcher to the gateway core's JSON format. */
|
|
41
42
|
toJSON(): Expr;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* this module
|
|
45
|
+
* A value condition for {@link header}, {@link query}, or {@link cookie}.
|
|
46
|
+
* When a field appears multiple times, any condition other than {@link absent}
|
|
47
|
+
* matches if at least one value satisfies it. Construct conditions using the
|
|
48
|
+
* functions in this module.
|
|
48
49
|
*/
|
|
49
50
|
export declare class Cond {
|
|
50
51
|
/** @internal */
|
|
51
52
|
readonly expr: Expr;
|
|
52
53
|
/** @internal */
|
|
53
54
|
constructor(expr: Expr);
|
|
54
|
-
/**
|
|
55
|
+
/** Serializes the condition to the gateway core's JSON format. */
|
|
55
56
|
toJSON(): Expr;
|
|
56
57
|
}
|
|
57
|
-
/** Matches
|
|
58
|
-
* are none. */
|
|
58
|
+
/** Matches requests that satisfy every matcher in `ms` (matches all requests when empty). */
|
|
59
59
|
export declare function allOf(...ms: Matcher[]): Matcher;
|
|
60
|
-
/** Matches
|
|
60
|
+
/** Matches requests that satisfy at least one matcher in `ms` (matches no requests when empty). */
|
|
61
61
|
export declare function anyOf(...ms: Matcher[]): Matcher;
|
|
62
|
-
/** Matches
|
|
62
|
+
/** Matches requests that do not satisfy `m` (equivalent to `m.not()`). */
|
|
63
63
|
export declare function not(m: Matcher): Matcher;
|
|
64
|
-
/** Matches
|
|
64
|
+
/** Matches requests routed to any of the given `services`. */
|
|
65
65
|
export declare function service(...services: string[]): Matcher;
|
|
66
66
|
/**
|
|
67
|
-
* Matches
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
67
|
+
* Matches requests routed to the route matching `template` (e.g.
|
|
68
|
+
* `/users/{id}`) and `method` (or any HTTP method if `method` is `undefined`).
|
|
69
|
+
* Path parameter names are ignored, matching router behavior (`/users/{userId}`
|
|
70
|
+
* matches the same route).
|
|
71
71
|
*/
|
|
72
72
|
export declare function route(method: string | undefined, template: string): Matcher;
|
|
73
|
-
/** Matches
|
|
73
|
+
/** Matches requests using any of the given HTTP `methods` (e.g. `"POST"`). */
|
|
74
74
|
export declare function method(...methods: string[]): Matcher;
|
|
75
75
|
/**
|
|
76
|
-
* Matches
|
|
77
|
-
*
|
|
78
|
-
* router.
|
|
76
|
+
* Matches requests whose raw (non-percent-decoded) path equals `path`.
|
|
77
|
+
* Trailing slashes are ignored, matching router behavior.
|
|
79
78
|
*/
|
|
80
79
|
export declare function path(path: string): Matcher;
|
|
81
80
|
/**
|
|
82
|
-
* Matches
|
|
83
|
-
* `/admin` matches `/admin` and `/admin/users`, not
|
|
81
|
+
* Matches requests whose path starts with `prefix` on whole-segment boundaries
|
|
82
|
+
* (for example, `/admin` matches `/admin` and `/admin/users`, but not
|
|
83
|
+
* `/administrators`).
|
|
84
84
|
*/
|
|
85
85
|
export declare function pathPrefix(prefix: string): Matcher;
|
|
86
86
|
/**
|
|
87
|
-
* Matches
|
|
88
|
-
*
|
|
89
|
-
* `/users
|
|
90
|
-
* `/users/1/posts/2`.
|
|
87
|
+
* Matches requests whose path matches `glob`, where `*` matches a single path
|
|
88
|
+
* segment and `**` matches zero or more segments (e.g. `/users/*` matches
|
|
89
|
+
* `/users/1`, and `/users/**` matches `/users` and `/users/1/posts/2`).
|
|
91
90
|
*/
|
|
92
91
|
export declare function pathGlob(glob: string): Matcher;
|
|
93
92
|
/**
|
|
94
|
-
* Matches
|
|
95
|
-
*
|
|
93
|
+
* Matches requests whose header `name` satisfies `cond`, or is present when
|
|
94
|
+
* `cond` is omitted. Header names are case-insensitive; values are compared as
|
|
96
95
|
* sent.
|
|
97
96
|
*/
|
|
98
97
|
export declare function header(name: string, cond?: Cond): Matcher;
|
|
99
98
|
/**
|
|
100
|
-
* Matches
|
|
101
|
-
*
|
|
102
|
-
*
|
|
99
|
+
* Matches requests whose query parameter `name` satisfies `cond`, or is
|
|
100
|
+
* present when `cond` is omitted. Parameter names are case-sensitive; values
|
|
101
|
+
* are percent-decoded before comparison.
|
|
103
102
|
*/
|
|
104
103
|
export declare function query(name: string, cond?: Cond): Matcher;
|
|
105
104
|
/**
|
|
106
|
-
* Matches
|
|
107
|
-
*
|
|
105
|
+
* Matches requests whose cookie `name` satisfies `cond`, or is present when
|
|
106
|
+
* `cond` is omitted. Cookie names are case-sensitive; values are compared as
|
|
107
|
+
* sent.
|
|
108
108
|
*/
|
|
109
109
|
export declare function cookie(name: string, cond?: Cond): Matcher;
|
|
110
|
-
/**
|
|
110
|
+
/** Matches when the field is present. */
|
|
111
111
|
export declare function present(): Cond;
|
|
112
|
-
/**
|
|
112
|
+
/** Matches when the field is absent. */
|
|
113
113
|
export declare function absent(): Cond;
|
|
114
|
-
/**
|
|
114
|
+
/** Matches when the field equals `value`. */
|
|
115
115
|
export declare function equals(value: string): Cond;
|
|
116
|
-
/**
|
|
116
|
+
/** Matches when the field starts with `prefix` (e.g. `"Bearer "`). */
|
|
117
117
|
export declare function prefix(prefix: string): Cond;
|
|
118
|
-
/**
|
|
118
|
+
/** Matches when the field equals one of `values`. */
|
|
119
119
|
export declare function oneOf(...values: string[]): Cond;
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
* Matches when `pattern` matches the field's entire value. Uses RE2 syntax
|
|
122
|
+
* (not JavaScript RegExp syntax) because Encore evaluates it natively. An
|
|
123
|
+
* invalid pattern causes `serve` to reject.
|
|
124
124
|
*/
|
|
125
125
|
export declare function regex(pattern: string): Cond;
|
|
126
126
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../gateway/match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../gateway/match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yEAAyE;AACzE,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpC;;;;GAIG;AACH,qBAAa,OAAO;IAClB,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAEpB,gBAAgB;gBACJ,IAAI,EAAE,IAAI;IAItB,mEA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