@encore.dev/sdk 2.0.0-beta.14 → 2.0.0-beta.16
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 +144 -90
- package/app_meta.ts +56 -54
- package/config/config.test.ts +47 -13
- package/config/config.ts +60 -57
- package/config/secrets.ts +47 -50
- package/config/value.ts +23 -26
- package/cron/mod.test.ts +12 -0
- package/cron/mod.ts +37 -22
- 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 -50
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +11 -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 +34 -20
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -13
- 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/otel/http.d.ts +4 -2
- package/dist/internal/otel/http.d.ts.map +1 -1
- package/dist/internal/otel/http.js +32 -5
- package/dist/internal/otel/http.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +6 -5
- package/dist/internal/runtime/napi/napi.d.cts +58 -16
- 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/redaction/mod.d.ts +62 -0
- package/dist/redaction/mod.d.ts.map +1 -0
- package/dist/redaction/mod.js +102 -0
- package/dist/redaction/mod.js.map +1 -0
- 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 +230 -203
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +146 -106
- 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/objects/mod.d.ts +1 -1
- package/dist/storage/objects/mod.d.ts.map +1 -1
- package/dist/storage/objects/mod.js.map +1 -1
- package/dist/storage/objects/refs.d.ts +2 -5
- package/dist/storage/objects/refs.d.ts.map +1 -1
- package/dist/storage/objects/refs.js.map +1 -1
- 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/tracing/http.d.ts +2 -1
- package/dist/tracing/http.d.ts.map +1 -1
- package/dist/tracing/http.js +2 -1
- package/dist/tracing/http.js.map +1 -1
- package/dist/tracing/node.d.ts.map +1 -1
- package/dist/tracing/node.js +1 -1
- package/dist/tracing/node.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/otel/http.test.ts +50 -0
- package/internal/otel/http.ts +40 -5
- package/internal/runtime/napi/napi.cjs +6 -5
- package/internal/runtime/napi/napi.d.cts +58 -16
- 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 +6 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/redaction/bridge.test.ts +99 -0
- package/redaction/mod.test.ts +188 -0
- package/redaction/mod.ts +226 -0
- 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.test.ts +168 -16
- package/storage/objects/bucket.ts +336 -247
- package/storage/objects/error.ts +4 -4
- package/storage/objects/mod.ts +1 -0
- package/storage/objects/refs.ts +2 -5
- 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/tracing/http.ts +2 -1
- package/tracing/native.test.ts +158 -8
- package/tracing/node.ts +1 -0
package/dist/reqctx/mod.js
CHANGED
|
@@ -2,23 +2,23 @@ import log from '../log/index.js';
|
|
|
2
2
|
import { activeContext, withContext } from '../internal/otel/context.js';
|
|
3
3
|
import * as reqfields from '../internal/reqfields.js';
|
|
4
4
|
/**
|
|
5
|
-
* A Request Context field holding a JSON value of type `T`.
|
|
5
|
+
* A typed Request Context field holding a JSON-serializable value of type `T`.
|
|
6
6
|
*
|
|
7
|
-
* Declare
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Declare fields at module level (`new Field<User>("user")`). Encore extracts a
|
|
8
|
+
* schema from `T` and validates cross-service `Field.named` bindings against
|
|
9
|
+
* it. At runtime, values are decoded directly from JSON without custom
|
|
10
|
+
* deserializers.
|
|
11
11
|
*/
|
|
12
12
|
export class Field {
|
|
13
|
-
/** The name
|
|
13
|
+
/** The name this field was declared with. */
|
|
14
14
|
name;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Declares a Request Context field.
|
|
17
17
|
*
|
|
18
|
-
* @param name -
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param cfg -
|
|
18
|
+
* @param name - Unique kebab-case field name (lowercase letters, digits, and
|
|
19
|
+
* hyphens, starting with a letter and ending with a letter or digit). Must be
|
|
20
|
+
* a string literal for Encore's parser.
|
|
21
|
+
* @param cfg - Propagation and classification options.
|
|
22
22
|
*/
|
|
23
23
|
constructor(name, cfg) {
|
|
24
24
|
this.name = name;
|
|
@@ -28,11 +28,9 @@ export class Field {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* language.
|
|
33
|
-
* declaration's
|
|
34
|
-
* declaration says: carried on Pub/Sub messages, and put on spans, as
|
|
35
|
-
* declared.
|
|
31
|
+
* Binds to a field declared elsewhere in the app (including in another
|
|
32
|
+
* language). Encore validates `T` against the declaration, and the bound
|
|
33
|
+
* field inherits the declaration's `pubsub` and `trace` settings.
|
|
36
34
|
*/
|
|
37
35
|
static named(name) {
|
|
38
36
|
const field = Object.create(Field.prototype);
|
|
@@ -43,11 +41,11 @@ export class Field {
|
|
|
43
41
|
return field;
|
|
44
42
|
}
|
|
45
43
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* Returns this field's value from `ctx` (or the active context if omitted),
|
|
45
|
+
* or `undefined` if unset.
|
|
48
46
|
*
|
|
49
|
-
* Each call
|
|
50
|
-
*
|
|
47
|
+
* Each call returns a freshly decoded value that the caller may safely
|
|
48
|
+
* mutate. Invalid JSON values are treated as unset and logged once.
|
|
51
49
|
*/
|
|
52
50
|
get(ctx) {
|
|
53
51
|
const value = reqfields.current(ctx ?? activeContext())[this.name];
|
|
@@ -62,27 +60,26 @@ export class Field {
|
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
63
|
+
* Runs `fn` with this field set to `value` in the active context and returns
|
|
64
|
+
* its result (or promise for async functions).
|
|
67
65
|
*
|
|
68
|
-
* @throws TypeError
|
|
69
|
-
* `undefined
|
|
70
|
-
* @throws RangeError
|
|
71
|
-
* or 1 KiB
|
|
72
|
-
*
|
|
66
|
+
* @throws TypeError If `value` cannot be serialized to JSON (e.g. contains a
|
|
67
|
+
* `bigint`, circular reference, or is `undefined`).
|
|
68
|
+
* @throws RangeError If the encoded value exceeds the per-field limit (4 KiB,
|
|
69
|
+
* or 1 KiB when `pubsub` is enabled) or pushes total request fields past
|
|
70
|
+
* 8 KiB.
|
|
73
71
|
*/
|
|
74
72
|
with(value, fn) {
|
|
75
73
|
return withContext(this.context(value), fn);
|
|
76
74
|
}
|
|
77
|
-
/**
|
|
78
|
-
* makes. */
|
|
75
|
+
/** Runs `fn` with this field cleared from the active context. */
|
|
79
76
|
without(fn) {
|
|
80
77
|
return withContext(this.contextWithout(), fn);
|
|
81
78
|
}
|
|
82
79
|
/**
|
|
83
|
-
*
|
|
84
|
-
* `value
|
|
85
|
-
* {@link Field.with}
|
|
80
|
+
* Returns a copy of `ctx` (or the active context) with this field set to
|
|
81
|
+
* `value`, for code passing OpenTelemetry contexts explicitly. Throws the
|
|
82
|
+
* same errors as {@link Field.with}.
|
|
86
83
|
*/
|
|
87
84
|
context(value, ctx) {
|
|
88
85
|
let encoded;
|
|
@@ -99,19 +96,20 @@ export class Field {
|
|
|
99
96
|
throw new RangeError(`reqctx: field ${JSON.stringify(this.name)}: the value ${messageOf(err)}`, { cause: err });
|
|
100
97
|
}
|
|
101
98
|
}
|
|
102
|
-
/**
|
|
99
|
+
/** Returns a copy of `ctx` (or the active context) with this field removed. */
|
|
103
100
|
contextWithout(ctx) {
|
|
104
101
|
return reqfields.without(this.name, ctx ?? activeContext());
|
|
105
102
|
}
|
|
106
|
-
/** `Field("name")`. */
|
|
103
|
+
/** Returns `Field("name")`. */
|
|
107
104
|
toString() {
|
|
108
105
|
return `Field(${JSON.stringify(this.name)})`;
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
109
|
+
* Extracts Request Context fields from incoming request `headers` into a copy
|
|
110
|
+
* of `ctx` (or the active context), replacing any previously held fields.
|
|
111
|
+
* Reads the first value of each field header case-insensitively. Returns the
|
|
112
|
+
* base context unchanged if no fields are present.
|
|
115
113
|
*/
|
|
116
114
|
export function extract(headers, ctx) {
|
|
117
115
|
const base = ctx ?? activeContext();
|
|
@@ -121,11 +119,11 @@ export function extract(headers, ctx) {
|
|
|
121
119
|
: reqfields.withFields(fields, base);
|
|
122
120
|
}
|
|
123
121
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
122
|
+
* Writes the Request Context fields from `ctx` (or the active context) onto
|
|
123
|
+
* outgoing request `headers`, replacing any existing field headers.
|
|
126
124
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
125
|
+
* Only call this for requests to other Encore services in the same app so
|
|
126
|
+
* internal context is not sent to third parties.
|
|
129
127
|
*/
|
|
130
128
|
export function inject(headers, ctx) {
|
|
131
129
|
reqfields.toHeaders(headers, ctx ?? activeContext());
|
package/dist/reqctx/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../reqctx/mod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../reqctx/mod.ts"],"names":[],"mappings":"AAqEA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAkCnD;;;;;;;GAOG;AACH,MAAM,OAAO,KAAK;IAChB,6CAA6C;IACpC,IAAI,CAAS;IAEtB;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,GAAiB;QACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE;YACtB,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI;YAC5B,KAAK,EAAE,GAAG,EAAE,KAAK,KAAK,IAAI;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAI,IAAY;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAa,CAAC;QACzD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;YACnC,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,GAAa;QACf,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,IAAI,CAAC;YACH,OAAO,SAAS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,CAAC,6BAA6B,SAAS,CAAC,GAAG,CAAC,EAAE,EAChH,EAAC,KAAK,EAAE,IAAI,EAAC,CACd,CAAC;AACJ,CAAC"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Calling
|
|
2
|
+
* Calling other services within your Encore application.
|
|
3
3
|
*
|
|
4
|
-
* {@link client}
|
|
5
|
-
* service
|
|
4
|
+
* {@link client} creates a client for a target service whose `fetch` method
|
|
5
|
+
* accepts service-relative paths:
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* import {client} from '@encore.dev/sdk/services';
|
|
@@ -16,17 +16,19 @@
|
|
|
16
16
|
* }
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
* trace and Request Context
|
|
21
|
-
* to
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* Calls made with {@link client} or this module's {@link fetch} automatically
|
|
20
|
+
* propagate the active trace context and Request Context
|
|
21
|
+
* (`@encore.dev/sdk/reqctx`) to other services in the app. Requests to external
|
|
22
|
+
* URLs never receive Request Context headers so internal context is not leaked
|
|
23
|
+
* to third parties. Pass {@link fetch} to any HTTP library or generated client
|
|
24
|
+
* that accepts a custom fetch implementation.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* ## Generated clients
|
|
27
|
+
*
|
|
28
|
+
* When a service lists another service in `encore.service.json` under
|
|
29
|
+
* `clients`, Encore generates typed clients under `encore_gen/clients` (one
|
|
30
|
+
* module per service and API). Each endpoint is exported as a plain function,
|
|
31
|
+
* so no manual client setup is needed:
|
|
30
32
|
*
|
|
31
33
|
* ```ts
|
|
32
34
|
* import {catalog} from "./encore_gen/clients/index.js";
|
|
@@ -36,14 +38,14 @@
|
|
|
36
38
|
* const stuff = await catalog.grpc.stuffService.doStuff({});
|
|
37
39
|
* ```
|
|
38
40
|
*
|
|
39
|
-
* Importing the index
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* Importing the top-level index is lightweight — gRPC clients lazily load
|
|
42
|
+
* connect-es on their first call. You can also deep-import a single API:
|
|
43
|
+
* `import * as openapi from "./encore_gen/clients/catalog/openapi.js"`.
|
|
42
44
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* gRPC clients use protobuf-es messages generated in `encore_gen/protos` (one
|
|
46
|
+
* module per `.proto` file, shared across all clients of the service). Calls
|
|
47
|
+
* accept either a message instance or a plain init object (like protobuf-es's
|
|
48
|
+
* `create`) and return a message:
|
|
47
49
|
*
|
|
48
50
|
* ```ts
|
|
49
51
|
* import {create} from "@bufbuild/protobuf";
|
|
@@ -54,13 +56,14 @@
|
|
|
54
56
|
* const stuff = await catalog.grpc.stuffService.doStuff({id: "x", note});
|
|
55
57
|
* ```
|
|
56
58
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
59
|
+
* ## Error handling
|
|
60
|
+
*
|
|
61
|
+
* Failed generated calls throw a {@link CallError} regardless of protocol. Its
|
|
62
|
+
* `code` reflects the callee's response and is not automatically forwarded to
|
|
63
|
+
* your own callers — an uncaught `CallError` in an `@encore.dev/framework`
|
|
64
|
+
* handler becomes an internal error just like any non-`APIError` exception.
|
|
65
|
+
* Convert it explicitly when appropriate, or use {@link unlessNotFound} to turn
|
|
66
|
+
* `not_found` errors into `undefined`:
|
|
64
67
|
*
|
|
65
68
|
* ```ts
|
|
66
69
|
* import {APIError} from "@encore.dev/framework";
|
|
@@ -78,10 +81,12 @@
|
|
|
78
81
|
* const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
|
|
79
82
|
* ```
|
|
80
83
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
84
|
+
* ## Options and transport
|
|
85
|
+
*
|
|
86
|
+
* Every generated call accepts {@link CallOptions} (per-call `timeout` in
|
|
87
|
+
* milliseconds, extra `headers`, and an `AbortSignal`), which override client
|
|
88
|
+
* defaults. Construct a module's `Client` with {@link ClientOptions} to share
|
|
89
|
+
* settings across calls:
|
|
85
90
|
*
|
|
86
91
|
* ```ts
|
|
87
92
|
* const fresh = await catalog.openapi.getProduct("xyz", {timeout: 2_000});
|
|
@@ -89,26 +94,25 @@
|
|
|
89
94
|
* const mocked = new catalog.openapi.Client({baseUrl: mockServer.url});
|
|
90
95
|
* ```
|
|
91
96
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* first called (`system` of `@encore.dev/sdk/testing`).
|
|
97
|
+
* HTTP generated clients use this module's {@link fetch}, propagating traces
|
|
98
|
+
* and Request Context automatically. gRPC clients speak gRPC over HTTP/2
|
|
99
|
+
* (h2c for `http://`, TLS for `https://`), sharing one connection per base URL
|
|
100
|
+
* and propagating traces and Request Context the same way; gRPC status details
|
|
101
|
+
* are exposed on {@link CallError.grpcDetails}. Client instances hold only
|
|
102
|
+
* configuration, so creating one is cheap and requires no cleanup.
|
|
103
|
+
*
|
|
104
|
+
* ## Static dependencies and testing
|
|
105
|
+
*
|
|
106
|
+
* Calling {@link baseUrl}, {@link serviceUrl}, or {@link client} registers a
|
|
107
|
+
* static dependency from the calling service to the target service. Therefore,
|
|
108
|
+
* the service name must be a string literal, the function must be called
|
|
109
|
+
* directly (not aliased or passed around), and the call must occur inside a
|
|
110
|
+
* service.
|
|
111
|
+
*
|
|
112
|
+
* Under `encore test` (unit tests), no other services are running; service
|
|
113
|
+
* calls receive `501 Not Implemented` identifying the target service and path
|
|
114
|
+
* so you can mock them. In system tests (`system` from
|
|
115
|
+
* `@encore.dev/sdk/testing`), calls reach real services, which start on demand.
|
|
112
116
|
*
|
|
113
117
|
* @module
|
|
114
118
|
*/
|
|
@@ -117,11 +121,11 @@
|
|
|
117
121
|
export { fetch, wrapFetch } from '../internal/fetch.js';
|
|
118
122
|
export { CallError, httpStatus, isErrCode, unlessNotFound, type CallOptions, type ClientOptions, type ErrCode, type GraphQLError, type GrpcDetail, } from '../internal/clients/call.js';
|
|
119
123
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
124
|
+
* Returns the base URL for `service` without a trailing slash, so paths can be
|
|
125
|
+
* appended directly (e.g. `` `${baseUrl("orders")}/orders/1` ``).
|
|
122
126
|
*
|
|
123
|
-
* Throws if
|
|
124
|
-
*
|
|
127
|
+
* Throws if `service` is unknown to this process (either no such service exists
|
|
128
|
+
* or service discovery was not configured).
|
|
125
129
|
*
|
|
126
130
|
* @example
|
|
127
131
|
* import {baseUrl} from "@encore.dev/sdk/services";
|
|
@@ -129,38 +133,35 @@ export { CallError, httpStatus, isErrCode, unlessNotFound, type CallOptions, typ
|
|
|
129
133
|
*/
|
|
130
134
|
export declare function baseUrl(service: string): string;
|
|
131
135
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* service is unknown to this process.
|
|
136
|
+
* Returns the base URL of `service` as a `URL` ending with `/`, suitable for
|
|
137
|
+
* resolving relative paths (`new URL("orders/1", serviceUrl("orders"))`).
|
|
138
|
+
* Throws if `service` is unknown to this process.
|
|
135
139
|
*
|
|
136
|
-
*
|
|
137
|
-
* {@link baseUrl}
|
|
140
|
+
* Registers a static dependency on `service` under the same rules as
|
|
141
|
+
* {@link baseUrl}.
|
|
138
142
|
*
|
|
139
|
-
* @deprecated Use {@link baseUrl}, which returns
|
|
140
|
-
*
|
|
143
|
+
* @deprecated Use {@link baseUrl}, which returns a string without a trailing
|
|
144
|
+
* slash consistently across Encore SDKs.
|
|
141
145
|
*/
|
|
142
146
|
export declare function serviceUrl(service: string): URL;
|
|
143
|
-
/**
|
|
147
|
+
/** HTTP client scoped to a single Encore service. */
|
|
144
148
|
export interface ServiceClient {
|
|
145
|
-
/**
|
|
146
|
-
* returns it. */
|
|
149
|
+
/** Base URL of the target service without a trailing slash (same as {@link baseUrl}). */
|
|
147
150
|
readonly baseUrl: string;
|
|
148
151
|
/**
|
|
149
|
-
* Calls the service
|
|
150
|
-
*
|
|
151
|
-
* `'
|
|
152
|
-
* used as it is.
|
|
152
|
+
* Calls the service using this module's {@link fetch}. Relative `path` values
|
|
153
|
+
* are joined to `baseUrl` with a single `/` (so `'/invoices'` and
|
|
154
|
+
* `'invoices'` are equivalent); absolute URLs are used as-is.
|
|
153
155
|
*/
|
|
154
156
|
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
|
-
*
|
|
158
|
-
* service
|
|
159
|
-
* context.
|
|
159
|
+
* Returns a {@link ServiceClient} for `service` whose `fetch` accepts
|
|
160
|
+
* service-relative paths and propagates the active trace and Request Context.
|
|
160
161
|
*
|
|
161
|
-
* Like {@link baseUrl},
|
|
162
|
-
*
|
|
163
|
-
* Throws if
|
|
162
|
+
* Like {@link baseUrl}, registers a static dependency on `service`, so the name
|
|
163
|
+
* must be a string literal and the function must be called directly inside a
|
|
164
|
+
* service. Throws if `service` is unknown to this process.
|
|
164
165
|
*
|
|
165
166
|
* @example
|
|
166
167
|
* import {client} from "@encore.dev/sdk/services";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../services/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../services/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqHG;;;AAKH,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAI/C;AAYD,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,yFAAyF;IACzF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAMrD"}
|