@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.8
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 +55 -0
- package/app_meta.ts +8 -0
- package/config/config.test.ts +10 -3
- package/config/config.ts +75 -21
- package/config/mod.ts +4 -3
- package/config/secrets.ts +72 -55
- package/cron/mod.ts +32 -0
- package/dist/app_meta.d.ts +7 -0
- package/dist/app_meta.d.ts.map +1 -0
- package/dist/app_meta.js +1 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +44 -18
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +43 -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 +62 -39
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +21 -37
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +1 -0
- package/dist/config/value.d.ts.map +1 -0
- package/dist/cron/mod.d.ts +31 -0
- package/dist/cron/mod.d.ts.map +1 -0
- package/dist/cron/mod.js +23 -0
- package/dist/cron/mod.js.map +1 -1
- 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 +129 -0
- package/dist/gateway/mod.d.ts.map +1 -0
- package/dist/gateway/mod.js +187 -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/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 +54 -0
- package/dist/internal/fetch.d.ts.map +1 -0
- package/dist/internal/fetch.js +240 -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/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 +1 -0
- package/dist/internal/otel/provider.d.ts.map +1 -0
- package/dist/internal/otel/span.d.ts +4 -0
- package/dist/internal/otel/span.d.ts.map +1 -0
- package/dist/internal/otel/span.js +5 -0
- 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 +150 -0
- package/dist/internal/reqfields.d.ts.map +1 -0
- package/dist/internal/reqfields.js +312 -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 +160 -16
- package/dist/internal/runtime/napi/napi.d.cts +474 -29
- 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/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 +81 -0
- package/dist/internal/testing/scope.d.ts.map +1 -0
- package/dist/internal/testing/scope.js +237 -0
- package/dist/internal/testing/scope.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 +1 -2
- 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 +4 -3
- 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 +104 -10
- 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 +87 -23
- package/dist/pubsub/topic.d.ts.map +1 -0
- package/dist/pubsub/topic.js +143 -40
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +191 -0
- package/dist/reqctx/mod.d.ts.map +1 -0
- package/dist/reqctx/mod.js +160 -0
- package/dist/reqctx/mod.js.map +1 -0
- package/dist/services/index.d.ts +145 -4
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +155 -8
- 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 +312 -7
- package/dist/storage/objects/bucket.d.ts.map +1 -0
- package/dist/storage/objects/bucket.js +305 -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 +81 -25
- package/dist/storage/postgres/database.d.ts.map +1 -0
- package/dist/storage/postgres/database.js +125 -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 +160 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +227 -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/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/mod.d.ts +19 -0
- package/dist/tracing/mod.d.ts.map +1 -0
- package/dist/tracing/mod.js +46 -0
- package/dist/tracing/mod.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/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 +210 -0
- package/gateway/request.ts +578 -0
- package/gateway/serve.ts +738 -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 +276 -0
- package/internal/otel/index.ts +1 -7
- package/internal/otel/span.ts +6 -0
- package/internal/otel/tracer.test.ts +43 -15
- package/internal/otel/tracer.ts +12 -5
- package/internal/reqfields.ts +390 -0
- package/internal/runtime/mod.ts +41 -2
- package/internal/runtime/napi/napi.cjs +160 -16
- package/internal/runtime/napi/napi.d.cts +474 -29
- package/internal/runtime/shutdown.ts +11 -1
- package/internal/testing/runner.ts +10 -0
- package/internal/testing/scope.ts +273 -0
- package/metrics/mod.test.ts +13 -16
- package/metrics/mod.ts +57 -226
- package/mod.ts +0 -8
- package/otel.test.ts +13 -6
- package/package.json +67 -15
- package/pubsub/encoding.ts +11 -1
- package/pubsub/mod.ts +10 -3
- package/pubsub/pubsub.test.ts +232 -14
- package/pubsub/refs.ts +16 -0
- package/pubsub/subscription.ts +194 -16
- package/pubsub/topic.test.ts +26 -0
- package/pubsub/topic.ts +220 -25
- package/reqctx/mod.ts +284 -0
- package/reqctx/reqctx.test.ts +193 -0
- package/scripts/postprocess-docs.test.ts +48 -0
- package/services/index.test.ts +341 -1
- package/services/index.ts +183 -8
- package/storage/objects/bucket.test.ts +573 -0
- package/storage/objects/bucket.ts +649 -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 +202 -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 +337 -0
- package/testing/node.ts +12 -0
- package/testing/vitest.ts +13 -0
- package/tracing/mod.ts +82 -0
- package/tracing/native.test.ts +170 -0
- package/tracing/tracing.test.ts +317 -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,578 @@
|
|
|
1
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
2
|
+
import type {SpanContext} from '@opentelemetry/api';
|
|
3
|
+
import {createTraceState, ROOT_CONTEXT} from '@opentelemetry/api';
|
|
4
|
+
import {parseTraceparent} from '../internal/otel/propagator';
|
|
5
|
+
import * as reqfields from '../internal/reqfields';
|
|
6
|
+
import {Field} from '../reqctx/mod';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A request as the native runtime keeps it: its headers, query parameters
|
|
10
|
+
* and cookies are handed to JavaScript only as a hook reads them.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export interface NativeView {
|
|
14
|
+
readonly gateway: string;
|
|
15
|
+
readonly service: string;
|
|
16
|
+
readonly route: string;
|
|
17
|
+
readonly method: string;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly host?: string | null;
|
|
20
|
+
readonly clientIp?: string | null;
|
|
21
|
+
readonly traceparent?: string | null;
|
|
22
|
+
readonly tracestate?: string | null;
|
|
23
|
+
/** The Request Context fields earlier Middleware set, encoded. */
|
|
24
|
+
readonly context?: readonly NativeField[] | null;
|
|
25
|
+
pathParam(name: string): string | null | undefined;
|
|
26
|
+
headerValues(name: string): string[];
|
|
27
|
+
queryValues(name: string): string[];
|
|
28
|
+
cookie(name: string): string | null | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A response's headers as the native runtime keeps them. @internal */
|
|
32
|
+
export interface NativeHeaders {
|
|
33
|
+
values(name: string): string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A set of a Middleware's later hooks, which {@link Request.skip} narrows,
|
|
38
|
+
* combined with `|`: `Hook.Response | Hook.Complete`. `onRequest` is not
|
|
39
|
+
* among them: it is the hook that skips.
|
|
40
|
+
*/
|
|
41
|
+
export const Hook = {
|
|
42
|
+
/** `onRequestBody`. */
|
|
43
|
+
RequestBody: 1 << 1,
|
|
44
|
+
/** `onResponse`. */
|
|
45
|
+
Response: 1 << 2,
|
|
46
|
+
/** `onResponseBody`. */
|
|
47
|
+
ResponseBody: 1 << 3,
|
|
48
|
+
/** `onComplete`. */
|
|
49
|
+
Complete: 1 << 4,
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
/** A value of {@link Hook}, or several combined with `|`. */
|
|
53
|
+
export type Hooks = number;
|
|
54
|
+
|
|
55
|
+
/** The value of an attribute of a request's span. */
|
|
56
|
+
export type AttributeValue = string | boolean | number;
|
|
57
|
+
|
|
58
|
+
/** An edit to headers: op 0 sets, 1 adds, 2 removes. @internal */
|
|
59
|
+
export interface HeaderEdit {
|
|
60
|
+
op: number;
|
|
61
|
+
name: string;
|
|
62
|
+
value: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A Request Context field, encoded, as the native runtime shows and takes
|
|
66
|
+
* it: a null value clears it. @internal */
|
|
67
|
+
export interface NativeField {
|
|
68
|
+
name: string;
|
|
69
|
+
value?: string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** An attribute as the native runtime takes it. @internal */
|
|
73
|
+
export interface NativeAttribute {
|
|
74
|
+
key: string;
|
|
75
|
+
value: AttributeValue;
|
|
76
|
+
integer: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const SET = 0;
|
|
80
|
+
const ADD = 1;
|
|
81
|
+
const REMOVE = 2;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Whether a Middleware may not edit the header `name`, lowercase: Encore's
|
|
85
|
+
* headers, the trace context's, those framing the message, and CORS's. The
|
|
86
|
+
* gateway refuses the same edits.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export function isProtected(name: string): boolean {
|
|
90
|
+
return (
|
|
91
|
+
name.startsWith('x-encore-') ||
|
|
92
|
+
name.startsWith('access-control-') ||
|
|
93
|
+
PROTECTED.has(name)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const PROTECTED = new Set([
|
|
98
|
+
'traceparent',
|
|
99
|
+
'tracestate',
|
|
100
|
+
'content-length',
|
|
101
|
+
'transfer-encoding',
|
|
102
|
+
'connection',
|
|
103
|
+
'keep-alive',
|
|
104
|
+
'proxy-connection',
|
|
105
|
+
'te',
|
|
106
|
+
'trailer',
|
|
107
|
+
'upgrade',
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
/** Header values edited by a Middleware, by lowercase name, as they read
|
|
111
|
+
* now. */
|
|
112
|
+
type Overrides = Map<string, string[]>;
|
|
113
|
+
|
|
114
|
+
function overridden(
|
|
115
|
+
overrides: Overrides | undefined,
|
|
116
|
+
op: number,
|
|
117
|
+
name: string,
|
|
118
|
+
value: string,
|
|
119
|
+
current: string[],
|
|
120
|
+
): Overrides {
|
|
121
|
+
const out = overrides ?? new Map();
|
|
122
|
+
if (op === SET) out.set(name, [value]);
|
|
123
|
+
else if (op === ADD) out.set(name, [...current, value]);
|
|
124
|
+
else out.set(name, []);
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** One Middleware's state for one request, shared by the Requests its hooks
|
|
129
|
+
* are shown. @internal */
|
|
130
|
+
export interface Lane {
|
|
131
|
+
state: unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** One run of a timed hook, `onRequest` or `onResponse`: expired once it
|
|
135
|
+
* has timed out and the gateway went on without it. @internal */
|
|
136
|
+
export interface HookRun {
|
|
137
|
+
expired: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The timed hook the code running now is part of, following its `await`s,
|
|
141
|
+
* timers and callbacks: so that what a timed-out hook goes on doing cannot
|
|
142
|
+
* change the state its later hooks are shown. @internal */
|
|
143
|
+
export const hookRuns = new AsyncLocalStorage<HookRun>();
|
|
144
|
+
|
|
145
|
+
/** Never aborts: the signal of a hook without a timeout. */
|
|
146
|
+
const NEVER = new AbortController().signal;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A public request the gateway serves, as a Middleware is shown it. Made by
|
|
150
|
+
* Encore: the same object is passed to each of one Middleware's hooks for
|
|
151
|
+
* one request.
|
|
152
|
+
*
|
|
153
|
+
* It reads the request's headers, query parameters and cookies as the hook
|
|
154
|
+
* asks for them, as the Middleware before this one left them, and with this
|
|
155
|
+
* one's edits. Encore's own headers, `x-encore-*`, are never shown. Edits
|
|
156
|
+
* are only allowed in `onRequest`; elsewhere they throw.
|
|
157
|
+
*/
|
|
158
|
+
export class Request {
|
|
159
|
+
/** Identifies the request among those in flight; unique while it is. */
|
|
160
|
+
readonly id: number;
|
|
161
|
+
|
|
162
|
+
/** @internal */ readonly middleware: string;
|
|
163
|
+
/** @internal */ readonly view: NativeView | undefined;
|
|
164
|
+
/** @internal */ readonly lane: Lane;
|
|
165
|
+
/** @internal */ overrides: Overrides | undefined;
|
|
166
|
+
/** @internal */ deciding = false;
|
|
167
|
+
/** @internal */ edits: HeaderEdit[] = [];
|
|
168
|
+
/** @internal The request's Request Context fields, encoded, with this
|
|
169
|
+
* Middleware's changes: changed in place, as the context its hooks run in
|
|
170
|
+
* holds this record. */
|
|
171
|
+
readonly fields: Record<string, string> = {};
|
|
172
|
+
/** @internal The changes `set` and `unset` made, for the gateway. */
|
|
173
|
+
fieldEdits: NativeField[] = [];
|
|
174
|
+
/** @internal */ attributes: NativeAttribute[] = [];
|
|
175
|
+
/** @internal */ skipped = 0;
|
|
176
|
+
/** @internal */ hookSignal: AbortSignal = NEVER;
|
|
177
|
+
|
|
178
|
+
/** @internal Made by Encore. */
|
|
179
|
+
constructor(
|
|
180
|
+
middleware: string,
|
|
181
|
+
id: number,
|
|
182
|
+
view: NativeView | undefined,
|
|
183
|
+
lane: Lane,
|
|
184
|
+
) {
|
|
185
|
+
this.middleware = middleware;
|
|
186
|
+
this.id = id;
|
|
187
|
+
this.view = view;
|
|
188
|
+
this.lane = lane;
|
|
189
|
+
for (const {name, value} of view?.context ?? []) {
|
|
190
|
+
if (typeof value === 'string') this.fields[name] = value;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The HTTP method, upper case. */
|
|
195
|
+
get method(): string {
|
|
196
|
+
return this.view?.method ?? '';
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The host the client addressed, from its Host header, if any. */
|
|
200
|
+
get host(): string | undefined {
|
|
201
|
+
return this.view?.host ?? undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The path, as the client sent it: not percent-decoded, without the
|
|
205
|
+
* query. */
|
|
206
|
+
get path(): string {
|
|
207
|
+
return this.view?.path ?? '';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The service the gateway routes the request to. */
|
|
211
|
+
get service(): string {
|
|
212
|
+
return this.view?.service ?? '';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The route template it matched, such as `/users/{id}`. */
|
|
216
|
+
get route(): string {
|
|
217
|
+
return this.view?.route ?? '';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The address of the client the gateway took the request from, if
|
|
221
|
+
* known. */
|
|
222
|
+
get clientIp(): string | undefined {
|
|
223
|
+
return this.view?.clientIp ?? undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Aborts when the hook running now runs out of time: `onRequest` and
|
|
228
|
+
* `onResponse` have their Middleware's timeout, and the gateway goes on
|
|
229
|
+
* without them then. Pass it to what the hook awaits, as `fetch`, so the
|
|
230
|
+
* work stops too. It never aborts in the other hooks.
|
|
231
|
+
*/
|
|
232
|
+
get signal(): AbortSignal {
|
|
233
|
+
return this.hookSignal;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The value of the path parameter `name` of the matched route, as it was
|
|
237
|
+
* sent, not percent-decoded; undefined when the route has none of that
|
|
238
|
+
* name. */
|
|
239
|
+
pathParam(name: string): string | undefined {
|
|
240
|
+
return this.view?.pathParam(name) ?? undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The first value of the request header `name`, as earlier Middleware
|
|
244
|
+
* left it; undefined when it is not sent. Any case. */
|
|
245
|
+
header(name: string): string | undefined {
|
|
246
|
+
return this.headerValues(name)[0];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Every value of the request header `name`, in order. Any case. */
|
|
250
|
+
headerValues(name: string): string[] {
|
|
251
|
+
const lower = name.toLowerCase();
|
|
252
|
+
const edited = this.overrides?.get(lower);
|
|
253
|
+
if (edited !== undefined) return [...edited];
|
|
254
|
+
return this.view?.headerValues(lower) ?? [];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The first value of the query parameter `name`, percent-decoded;
|
|
258
|
+
* undefined when it is not sent. */
|
|
259
|
+
query(name: string): string | undefined {
|
|
260
|
+
return this.queryValues(name)[0];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Every value of the query parameter `name`, percent-decoded, in
|
|
264
|
+
* order. */
|
|
265
|
+
queryValues(name: string): string[] {
|
|
266
|
+
return this.view?.queryValues(name) ?? [];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The value of the cookie `name`, from the `Cookie` headers as the
|
|
270
|
+
* Middleware before this one left them; undefined when it is not sent. */
|
|
271
|
+
cookie(name: string): string | undefined {
|
|
272
|
+
return this.view?.cookie(name) ?? undefined;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** The context of the request's span at the gateway, which the spans its
|
|
276
|
+
* hooks start are children of; undefined when the request is not
|
|
277
|
+
* traced. */
|
|
278
|
+
get spanContext(): SpanContext | undefined {
|
|
279
|
+
const tp = this.view?.traceparent;
|
|
280
|
+
if (!tp) return undefined;
|
|
281
|
+
const sc = parseTraceparent(tp);
|
|
282
|
+
if (sc && this.view?.tracestate) {
|
|
283
|
+
sc.traceState = createTraceState(this.view.tracestate);
|
|
284
|
+
}
|
|
285
|
+
return sc;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private mustDecide(method: string): void {
|
|
289
|
+
if (!this.deciding) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
`middleware ${JSON.stringify(this.middleware)}: Request.${method} is only for onRequest`,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private edit(method: string, op: number, name: string, value: string): void {
|
|
297
|
+
this.mustDecide(method);
|
|
298
|
+
const lower = name.toLowerCase();
|
|
299
|
+
if (isProtected(lower)) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
`middleware ${JSON.stringify(this.middleware)}: Request.${method}(${JSON.stringify(name)}): ` +
|
|
302
|
+
"the header is Encore's to set",
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
const current = op === ADD ? this.headerValues(lower) : [];
|
|
306
|
+
this.edits.push({op, name, value});
|
|
307
|
+
this.overrides = overridden(this.overrides, op, lower, value, current);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Sets the request header `name` to `value`, replacing any values, for the
|
|
312
|
+
* Middleware after this one and the service. Only in `onRequest`. Not for
|
|
313
|
+
* Encore's headers (`x-encore-*`, the trace context), those framing the
|
|
314
|
+
* message (`content-length` and the like) and CORS's: those throw.
|
|
315
|
+
*/
|
|
316
|
+
setHeader(name: string, value: string): void {
|
|
317
|
+
this.edit('setHeader', SET, name, String(value));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Adds `value` to the request header `name`, keeping its values. As
|
|
321
|
+
* {@link Request.setHeader}. */
|
|
322
|
+
addHeader(name: string, value: string): void {
|
|
323
|
+
this.edit('addHeader', ADD, name, String(value));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Removes the request header `name`. As {@link Request.setHeader}. */
|
|
327
|
+
delHeader(name: string): void {
|
|
328
|
+
this.edit('delHeader', REMOVE, name, '');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Sets attributes of the request's span at the gateway, as a user or
|
|
333
|
+
* tenant id to find its trace by. Never secrets. Only in `onRequest`. An
|
|
334
|
+
* integer number is recorded as an integer, another as a float.
|
|
335
|
+
*/
|
|
336
|
+
setAttributes(attributes: Record<string, AttributeValue>): void {
|
|
337
|
+
this.mustDecide('setAttributes');
|
|
338
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
339
|
+
switch (typeof value) {
|
|
340
|
+
case 'string':
|
|
341
|
+
case 'boolean':
|
|
342
|
+
this.attributes.push({key, value, integer: false});
|
|
343
|
+
break;
|
|
344
|
+
case 'number':
|
|
345
|
+
this.attributes.push({
|
|
346
|
+
key,
|
|
347
|
+
value,
|
|
348
|
+
integer: Number.isSafeInteger(value),
|
|
349
|
+
});
|
|
350
|
+
break;
|
|
351
|
+
default:
|
|
352
|
+
throw new TypeError(
|
|
353
|
+
`span attribute ${JSON.stringify(key)} is a ${typeof value}; ` +
|
|
354
|
+
'a span attribute is a string, boolean or number',
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Skips this Middleware's later `hooks` for this request, as an
|
|
361
|
+
* `onResponse` a request without a session has no use for:
|
|
362
|
+
* `req.skip(Hook.Response | Hook.Complete)`. Only in `onRequest`. */
|
|
363
|
+
skip(hooks: Hooks): void {
|
|
364
|
+
this.mustDecide('skip');
|
|
365
|
+
if (!Number.isInteger(hooks) || hooks < 0 || hooks > 0xff) {
|
|
366
|
+
throw new TypeError(
|
|
367
|
+
'skip takes Hook flags, as Hook.Response | Hook.Complete',
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
this.skipped |= hooks & ~1;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The Request Context field's value for the request; undefined when it is
|
|
375
|
+
* not set: as the Middleware before this one set it, or this one did. In
|
|
376
|
+
* a hook, `field.get()` reads the same, as hooks run in their request's
|
|
377
|
+
* context; in `onComplete`, as the request was forwarded. A value that is
|
|
378
|
+
* not JSON reads as not set, as it does to `field.get()`.
|
|
379
|
+
*/
|
|
380
|
+
get<T>(field: Field<T>): T | undefined {
|
|
381
|
+
checkField('get', field);
|
|
382
|
+
return field.get(reqfields.withLiveFields(this.fields, ROOT_CONTEXT));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Sets the Request Context field to `value` for the request. The
|
|
387
|
+
* Middleware after this one, the service the request reaches, and every
|
|
388
|
+
* service it calls in turn with the request's context read it, with
|
|
389
|
+
* `field.get()`; so do the calls this hook makes from then on. It is how a
|
|
390
|
+
* Middleware that authenticates says who the request is for:
|
|
391
|
+
*
|
|
392
|
+
* ```ts
|
|
393
|
+
* export const currentUser = new Field<User>('user');
|
|
394
|
+
*
|
|
395
|
+
* class Auth implements gateway.Middleware {
|
|
396
|
+
* async onRequest(req: gateway.Request) {
|
|
397
|
+
* const user = await verify(req.header('authorization'), req.signal);
|
|
398
|
+
* if (user === undefined) {
|
|
399
|
+
* return gateway.reject(ErrCode.Unauthenticated, 'invalid token');
|
|
400
|
+
* }
|
|
401
|
+
* req.set(currentUser, user);
|
|
402
|
+
* }
|
|
403
|
+
* }
|
|
404
|
+
* ```
|
|
405
|
+
*
|
|
406
|
+
* Only in `onRequest`. The request takes the fields once the hook
|
|
407
|
+
* returns: none when it fails or answers the request.
|
|
408
|
+
*
|
|
409
|
+
* @throws TypeError - The value has no JSON form, or `field` is not a
|
|
410
|
+
* {@link Field}.
|
|
411
|
+
* @throws RangeError - The value encodes to more than a field may: 4 KiB,
|
|
412
|
+
* or 1 KiB for a field declared with `pubsub`; or it makes the request's
|
|
413
|
+
* fields encode to more than 8 KiB.
|
|
414
|
+
*/
|
|
415
|
+
set<T>(field: Field<T>, value: T): void {
|
|
416
|
+
this.mustDecide('set');
|
|
417
|
+
checkField('set', field);
|
|
418
|
+
const ctx = field.context(
|
|
419
|
+
value,
|
|
420
|
+
reqfields.withFields(this.fields, ROOT_CONTEXT),
|
|
421
|
+
);
|
|
422
|
+
const encoded = reqfields.current(ctx)[field.name]!;
|
|
423
|
+
this.fields[field.name] = encoded;
|
|
424
|
+
this.fieldEdits.push({name: field.name, value: encoded});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Clears the Request Context field for the request, as one the
|
|
428
|
+
* Middleware before this one set. As {@link Request.set} sets it. */
|
|
429
|
+
unset(field: Field<unknown>): void {
|
|
430
|
+
this.mustDecide('unset');
|
|
431
|
+
checkField('unset', field);
|
|
432
|
+
delete this.fields[field.name];
|
|
433
|
+
this.fieldEdits.push({name: field.name, value: null});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* What this Middleware kept for the request, for its later hooks: the
|
|
438
|
+
* user `onRequest` found, for `onComplete` to bill. Undefined until set.
|
|
439
|
+
* Encore drops it when the request is done.
|
|
440
|
+
*
|
|
441
|
+
* When `onRequest` or `onResponse` fails or times out, `state` goes back
|
|
442
|
+
* to the object it was before the hook; what the hook changed inside that
|
|
443
|
+
* object stays, since Encore does not copy it. A hook that may fail after
|
|
444
|
+
* changing it should set a new object, as `req.state = {...req.state,
|
|
445
|
+
* billed: true}`, rather than change the one it has. A hook that goes on
|
|
446
|
+
* after it timed out may no longer set it: that throws.
|
|
447
|
+
*/
|
|
448
|
+
get state(): unknown {
|
|
449
|
+
return this.lane.state;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
set state(value: unknown) {
|
|
453
|
+
if (hookRuns.getStore()?.expired) {
|
|
454
|
+
throw new Error(
|
|
455
|
+
`middleware ${JSON.stringify(this.middleware)}: Request.state is not set by a hook ` +
|
|
456
|
+
'that timed out: the gateway went on without it',
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
this.lane.state = value;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function checkField(method: string, field: unknown): void {
|
|
464
|
+
if (!(field instanceof Field)) {
|
|
465
|
+
const what =
|
|
466
|
+
field === null
|
|
467
|
+
? 'null'
|
|
468
|
+
: typeof field === 'object'
|
|
469
|
+
? `a ${field.constructor?.name ?? 'object'}`
|
|
470
|
+
: `a ${typeof field}`;
|
|
471
|
+
throw new TypeError(
|
|
472
|
+
`Request.${method} takes a Field of @encore.dev/sdk/reqctx, not ${what}`,
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* A response to a request the gateway served, in `onResponse`. Made by
|
|
479
|
+
* Encore. It reads the response's headers as the hook asks for them, as the
|
|
480
|
+
* Middleware after this one left them, and with this one's edits.
|
|
481
|
+
*/
|
|
482
|
+
export class Response {
|
|
483
|
+
/** The HTTP status. */
|
|
484
|
+
readonly status: number;
|
|
485
|
+
|
|
486
|
+
/** @internal */ readonly middleware: string;
|
|
487
|
+
/** @internal */ readonly headers: NativeHeaders | undefined;
|
|
488
|
+
/** @internal */ overrides: Overrides | undefined;
|
|
489
|
+
/** @internal */ editing = false;
|
|
490
|
+
/** @internal */ edits: HeaderEdit[] = [];
|
|
491
|
+
|
|
492
|
+
/** @internal Made by Encore. */
|
|
493
|
+
constructor(
|
|
494
|
+
middleware: string,
|
|
495
|
+
status: number,
|
|
496
|
+
headers: NativeHeaders | undefined,
|
|
497
|
+
) {
|
|
498
|
+
this.middleware = middleware;
|
|
499
|
+
this.status = status;
|
|
500
|
+
this.headers = headers;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** The first value of the response header `name`, if any. Any case. */
|
|
504
|
+
header(name: string): string | undefined {
|
|
505
|
+
return this.headerValues(name)[0];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Every value of the response header `name`, in order. Any case. */
|
|
509
|
+
headerValues(name: string): string[] {
|
|
510
|
+
const lower = name.toLowerCase();
|
|
511
|
+
const edited = this.overrides?.get(lower);
|
|
512
|
+
if (edited !== undefined) return [...edited];
|
|
513
|
+
return this.headers?.values(lower) ?? [];
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private edit(method: string, op: number, name: string, value: string): void {
|
|
517
|
+
if (!this.editing) {
|
|
518
|
+
throw new Error(
|
|
519
|
+
`middleware ${JSON.stringify(this.middleware)}: Response.${method} is only for onResponse`,
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
const lower = name.toLowerCase();
|
|
523
|
+
if (isProtected(lower)) {
|
|
524
|
+
throw new Error(
|
|
525
|
+
`middleware ${JSON.stringify(this.middleware)}: Response.${method}(${JSON.stringify(name)}): ` +
|
|
526
|
+
"the header is Encore's to set",
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
const current = op === ADD ? this.headerValues(lower) : [];
|
|
530
|
+
this.edits.push({op, name, value});
|
|
531
|
+
this.overrides = overridden(this.overrides, op, lower, value, current);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Sets the response header `name` to `value`, replacing any values,
|
|
535
|
+
* before it is written to the client. Not for the headers
|
|
536
|
+
* {@link Request.setHeader} may not set. */
|
|
537
|
+
setHeader(name: string, value: string): void {
|
|
538
|
+
this.edit('setHeader', SET, name, String(value));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Adds `value` to the response header `name`. */
|
|
542
|
+
addHeader(name: string, value: string): void {
|
|
543
|
+
this.edit('addHeader', ADD, name, String(value));
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Removes the response header `name`. */
|
|
547
|
+
delHeader(name: string): void {
|
|
548
|
+
this.edit('delHeader', REMOVE, name, '');
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** A request the gateway is done with, for `onComplete`. */
|
|
553
|
+
export interface Completed {
|
|
554
|
+
/** The request, with the headers as they were forwarded, and the state
|
|
555
|
+
* its earlier hooks kept. */
|
|
556
|
+
readonly request: Request;
|
|
557
|
+
/** The status the client was answered with; undefined when it was never
|
|
558
|
+
* answered, as when it disconnected first. */
|
|
559
|
+
readonly status: number | undefined;
|
|
560
|
+
/** The name of the Middleware that answered the request, or `"gateway"`
|
|
561
|
+
* when the gateway did, as for a route it does not expose; undefined when
|
|
562
|
+
* the service answered. */
|
|
563
|
+
readonly rejectedBy: string | undefined;
|
|
564
|
+
/** Why the request failed, if it did: a hook that failed, or a service
|
|
565
|
+
* that could not be reached. */
|
|
566
|
+
readonly error: string | undefined;
|
|
567
|
+
/** When the gateway received the request. */
|
|
568
|
+
readonly received: Date;
|
|
569
|
+
/** How long the gateway took to answer it, in milliseconds. */
|
|
570
|
+
readonly durationMs: number;
|
|
571
|
+
/** How long the service took, in milliseconds, if the request was
|
|
572
|
+
* forwarded. */
|
|
573
|
+
readonly upstreamDurationMs: number | undefined;
|
|
574
|
+
/** The bytes of the request's body. */
|
|
575
|
+
readonly requestBodySize: number;
|
|
576
|
+
/** The bytes of the response's body. */
|
|
577
|
+
readonly responseBodySize: number;
|
|
578
|
+
}
|