@beignet/core 0.0.1 → 0.0.2
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/CHANGELOG.md +11 -0
- package/README.md +149 -4
- package/dist/application/index.d.ts +93 -9
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +11 -11
- package/dist/application/index.js.map +1 -1
- package/dist/client/client.d.ts +73 -12
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +37 -12
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +69 -8
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +84 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +36 -0
- package/dist/config/index.js.map +1 -1
- package/dist/contracts/contract-builder.d.ts +49 -22
- package/dist/contracts/contract-builder.d.ts.map +1 -1
- package/dist/contracts/contract-builder.js +48 -21
- package/dist/contracts/contract-builder.js.map +1 -1
- package/dist/contracts/contract-group.d.ts +35 -19
- package/dist/contracts/contract-group.d.ts.map +1 -1
- package/dist/contracts/contract-group.js +35 -19
- package/dist/contracts/contract-group.js.map +1 -1
- package/dist/contracts/contract-like.d.ts +4 -4
- package/dist/contracts/contract-like.d.ts.map +1 -1
- package/dist/contracts/contract-like.js +2 -1
- package/dist/contracts/contract-like.js.map +1 -1
- package/dist/contracts/index.d.ts +28 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +12 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/openapi-meta.d.ts +8 -8
- package/dist/contracts/openapi-meta.d.ts.map +1 -1
- package/dist/contracts/path-template.d.ts +27 -0
- package/dist/contracts/path-template.d.ts.map +1 -1
- package/dist/contracts/path-template.js +6 -0
- package/dist/contracts/path-template.js.map +1 -1
- package/dist/contracts/types.d.ts +104 -10
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/types.js +15 -0
- package/dist/contracts/types.js.map +1 -1
- package/dist/contracts/utils.d.ts +6 -0
- package/dist/contracts/utils.d.ts.map +1 -1
- package/dist/contracts/utils.js +6 -0
- package/dist/contracts/utils.js.map +1 -1
- package/dist/domain/entity.d.ts +22 -11
- package/dist/domain/entity.d.ts.map +1 -1
- package/dist/domain/entity.js +5 -1
- package/dist/domain/entity.js.map +1 -1
- package/dist/domain/events.d.ts +5 -2
- package/dist/domain/events.d.ts.map +1 -1
- package/dist/domain/events.js +4 -1
- package/dist/domain/events.js.map +1 -1
- package/dist/domain/value-object.d.ts +19 -9
- package/dist/domain/value-object.d.ts.map +1 -1
- package/dist/domain/value-object.js +5 -1
- package/dist/domain/value-object.js.map +1 -1
- package/dist/errors/catalog.d.ts +40 -16
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +18 -7
- package/dist/errors/catalog.js.map +1 -1
- package/dist/errors/response.d.ts +16 -4
- package/dist/errors/response.d.ts.map +1 -1
- package/dist/errors/response.js +3 -3
- package/dist/errors/response.js.map +1 -1
- package/dist/errors/validation.d.ts +10 -1
- package/dist/errors/validation.d.ts.map +1 -1
- package/dist/errors/validation.js +3 -0
- package/dist/errors/validation.js.map +1 -1
- package/dist/events/index.d.ts +133 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +30 -0
- package/dist/events/index.js.map +1 -1
- package/dist/idempotency/index.d.ts +355 -0
- package/dist/idempotency/index.d.ts.map +1 -0
- package/dist/idempotency/index.js +360 -0
- package/dist/idempotency/index.js.map +1 -0
- package/dist/jobs/index.d.ts +110 -0
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +22 -0
- package/dist/jobs/index.js.map +1 -1
- package/dist/mail/index.d.ts +149 -0
- package/dist/mail/index.d.ts.map +1 -1
- package/dist/mail/index.js +30 -0
- package/dist/mail/index.js.map +1 -1
- package/dist/notifications/index.d.ts +369 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +310 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/openapi/index.d.ts +132 -16
- package/dist/openapi/index.d.ts.map +1 -1
- package/dist/openapi/index.js +1 -1
- package/dist/openapi/index.js.map +1 -1
- package/dist/outbox/index.d.ts +469 -0
- package/dist/outbox/index.d.ts.map +1 -0
- package/dist/outbox/index.js +482 -0
- package/dist/outbox/index.js.map +1 -0
- package/dist/pagination/index.d.ts +166 -0
- package/dist/pagination/index.d.ts.map +1 -0
- package/dist/pagination/index.js +96 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/ports/audit.d.ts +271 -0
- package/dist/ports/audit.d.ts.map +1 -1
- package/dist/ports/audit.js +128 -0
- package/dist/ports/audit.js.map +1 -1
- package/dist/ports/auth.d.ts +70 -0
- package/dist/ports/auth.d.ts.map +1 -1
- package/dist/ports/auth.js +30 -0
- package/dist/ports/auth.js.map +1 -1
- package/dist/ports/cache.d.ts +41 -0
- package/dist/ports/cache.d.ts.map +1 -1
- package/dist/ports/cache.js +10 -0
- package/dist/ports/cache.js.map +1 -1
- package/dist/ports/clock.d.ts +38 -0
- package/dist/ports/clock.d.ts.map +1 -1
- package/dist/ports/clock.js +20 -0
- package/dist/ports/clock.js.map +1 -1
- package/dist/ports/id-generator.d.ts +37 -0
- package/dist/ports/id-generator.d.ts.map +1 -1
- package/dist/ports/id-generator.js +22 -0
- package/dist/ports/id-generator.js.map +1 -1
- package/dist/ports/index.d.ts +83 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +41 -5
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/logger.d.ts +56 -0
- package/dist/ports/logger.d.ts.map +1 -1
- package/dist/ports/logger.js +17 -0
- package/dist/ports/logger.js.map +1 -1
- package/dist/ports/policy.d.ts +132 -0
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +45 -0
- package/dist/ports/policy.js.map +1 -1
- package/dist/ports/rate-limit.d.ts +25 -0
- package/dist/ports/rate-limit.d.ts.map +1 -1
- package/dist/ports/rate-limit.js +10 -0
- package/dist/ports/rate-limit.js.map +1 -1
- package/dist/ports/redaction.d.ts +101 -0
- package/dist/ports/redaction.d.ts.map +1 -1
- package/dist/ports/redaction.js +59 -0
- package/dist/ports/redaction.js.map +1 -1
- package/dist/ports/storage.d.ts +100 -0
- package/dist/ports/storage.d.ts.map +1 -1
- package/dist/ports/storage.js +10 -0
- package/dist/ports/storage.js.map +1 -1
- package/dist/ports/testing.d.ts +47 -0
- package/dist/ports/testing.d.ts.map +1 -1
- package/dist/ports/testing.js +23 -0
- package/dist/ports/testing.js.map +1 -1
- package/dist/ports/unit-of-work.d.ts +60 -3
- package/dist/ports/unit-of-work.d.ts.map +1 -1
- package/dist/ports/unit-of-work.js +11 -2
- package/dist/ports/unit-of-work.js.map +1 -1
- package/dist/providers/instrumentation.d.ts +204 -0
- package/dist/providers/instrumentation.d.ts.map +1 -1
- package/dist/providers/instrumentation.js +14 -0
- package/dist/providers/instrumentation.js.map +1 -1
- package/dist/providers/provider.d.ts +14 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js.map +1 -1
- package/dist/schedules/index.d.ts +246 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +27 -0
- package/dist/schedules/index.js.map +1 -1
- package/dist/server/health.d.ts +14 -5
- package/dist/server/health.d.ts.map +1 -1
- package/dist/server/health.js +5 -2
- package/dist/server/health.js.map +1 -1
- package/dist/server/hooks/auth.d.ts +57 -0
- package/dist/server/hooks/auth.d.ts.map +1 -1
- package/dist/server/hooks/auth.js.map +1 -1
- package/dist/server/hooks/cors.d.ts +27 -0
- package/dist/server/hooks/cors.d.ts.map +1 -1
- package/dist/server/hooks/cors.js +12 -0
- package/dist/server/hooks/cors.js.map +1 -1
- package/dist/server/hooks/errors.d.ts +15 -6
- package/dist/server/hooks/errors.d.ts.map +1 -1
- package/dist/server/hooks/errors.js.map +1 -1
- package/dist/server/hooks/index.d.ts +3 -0
- package/dist/server/hooks/index.d.ts.map +1 -1
- package/dist/server/hooks/index.js +3 -0
- package/dist/server/hooks/index.js.map +1 -1
- package/dist/server/hooks/logging.d.ts +36 -0
- package/dist/server/hooks/logging.d.ts.map +1 -1
- package/dist/server/hooks/logging.js +6 -0
- package/dist/server/hooks/logging.js.map +1 -1
- package/dist/server/hooks/rate-limit.d.ts +33 -0
- package/dist/server/hooks/rate-limit.d.ts.map +1 -1
- package/dist/server/hooks/rate-limit.js +11 -0
- package/dist/server/hooks/rate-limit.js.map +1 -1
- package/dist/server/http.d.ts +170 -0
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/openapi.d.ts +5 -3
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/openapi.js +4 -2
- package/dist/server/openapi.js.map +1 -1
- package/dist/server/providers/loadProviderConfig.d.ts +9 -0
- package/dist/server/providers/loadProviderConfig.d.ts.map +1 -1
- package/dist/server/providers/loadProviderConfig.js +9 -0
- package/dist/server/providers/loadProviderConfig.js.map +1 -1
- package/dist/server/server.d.ts +107 -8
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +27 -7
- package/dist/server/server.js.map +1 -1
- package/dist/testing/index.d.ts +167 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +119 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +21 -1
- package/src/application/index.ts +85 -22
- package/src/client/client.ts +73 -12
- package/src/client/index.ts +12 -0
- package/src/client/types.ts +70 -9
- package/src/config/index.ts +86 -0
- package/src/contracts/contract-builder.ts +49 -22
- package/src/contracts/contract-group.ts +35 -19
- package/src/contracts/contract-like.ts +4 -4
- package/src/contracts/index.ts +28 -1
- package/src/contracts/openapi-meta.ts +8 -8
- package/src/contracts/path-template.ts +27 -0
- package/src/contracts/types.ts +111 -10
- package/src/contracts/utils.ts +6 -0
- package/src/domain/entity.ts +22 -11
- package/src/domain/events.ts +5 -2
- package/src/domain/value-object.ts +19 -9
- package/src/errors/catalog.ts +40 -16
- package/src/errors/response.ts +16 -4
- package/src/errors/validation.ts +10 -1
- package/src/events/index.ts +134 -0
- package/src/idempotency/index.ts +767 -0
- package/src/jobs/index.ts +111 -0
- package/src/mail/index.ts +149 -0
- package/src/notifications/index.ts +771 -0
- package/src/openapi/index.ts +133 -16
- package/src/outbox/index.ts +1024 -0
- package/src/pagination/index.ts +278 -0
- package/src/ports/audit.ts +271 -0
- package/src/ports/auth.ts +70 -0
- package/src/ports/cache.ts +41 -0
- package/src/ports/clock.ts +38 -0
- package/src/ports/id-generator.ts +37 -0
- package/src/ports/index.ts +106 -11
- package/src/ports/logger.ts +56 -0
- package/src/ports/policy.ts +133 -0
- package/src/ports/rate-limit.ts +25 -0
- package/src/ports/redaction.ts +101 -0
- package/src/ports/storage.ts +100 -0
- package/src/ports/testing.ts +47 -0
- package/src/ports/unit-of-work.ts +60 -3
- package/src/providers/instrumentation.ts +204 -0
- package/src/providers/provider.ts +14 -1
- package/src/schedules/index.ts +247 -0
- package/src/server/health.ts +14 -5
- package/src/server/hooks/auth.ts +58 -0
- package/src/server/hooks/cors.ts +27 -0
- package/src/server/hooks/errors.ts +15 -6
- package/src/server/hooks/index.ts +3 -0
- package/src/server/hooks/logging.ts +36 -0
- package/src/server/hooks/rate-limit.ts +33 -0
- package/src/server/http.ts +170 -1
- package/src/server/index.ts +18 -1
- package/src/server/openapi.ts +5 -3
- package/src/server/providers/loadProviderConfig.ts +9 -0
- package/src/server/server.ts +107 -9
- package/src/testing/index.ts +337 -0
package/dist/server/http.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { HttpContractConfig, InferHeaderSchemaOutput, InferOutput, StandardSchema } from "../contracts";
|
|
2
2
|
import type { AnyPorts } from "../ports";
|
|
3
|
+
/**
|
|
4
|
+
* Framework-neutral request shape consumed by Beignet server adapters.
|
|
5
|
+
*
|
|
6
|
+
* Platform adapters should convert their native request into this shape before
|
|
7
|
+
* passing it to `server.api(...)` or a single route handler.
|
|
8
|
+
*/
|
|
3
9
|
export interface HttpRequestLike {
|
|
10
|
+
/**
|
|
11
|
+
* HTTP method as received from the platform.
|
|
12
|
+
*/
|
|
4
13
|
method: string;
|
|
14
|
+
/**
|
|
15
|
+
* Absolute request URL.
|
|
16
|
+
*/
|
|
5
17
|
url: string;
|
|
18
|
+
/**
|
|
19
|
+
* Request headers.
|
|
20
|
+
*/
|
|
6
21
|
headers: Headers;
|
|
7
22
|
/**
|
|
8
23
|
* The platform request when an adapter has one available.
|
|
@@ -11,45 +26,138 @@ export interface HttpRequestLike {
|
|
|
11
26
|
* framework-agnostic methods below when possible.
|
|
12
27
|
*/
|
|
13
28
|
raw?: Request;
|
|
29
|
+
/**
|
|
30
|
+
* Parse the request body as JSON.
|
|
31
|
+
*/
|
|
14
32
|
json(): Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Parse the request body as text.
|
|
35
|
+
*/
|
|
15
36
|
text(): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Parse the request body as an array buffer when the platform supports it.
|
|
39
|
+
*/
|
|
16
40
|
arrayBuffer?(): Promise<ArrayBuffer>;
|
|
41
|
+
/**
|
|
42
|
+
* Parse the request body as a Blob when the platform supports it.
|
|
43
|
+
*/
|
|
17
44
|
blob?(): Promise<Blob>;
|
|
45
|
+
/**
|
|
46
|
+
* Parse the request body as form data when the platform supports it.
|
|
47
|
+
*/
|
|
18
48
|
formData?(): Promise<FormData>;
|
|
49
|
+
/**
|
|
50
|
+
* Clone the request when the platform supports replaying the body.
|
|
51
|
+
*/
|
|
19
52
|
clone?(): HttpRequestLike;
|
|
20
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Framework-neutral response object returned by route handlers and hooks.
|
|
56
|
+
*/
|
|
21
57
|
export interface HttpResponseLike {
|
|
58
|
+
/**
|
|
59
|
+
* HTTP status code.
|
|
60
|
+
*/
|
|
22
61
|
status: number;
|
|
62
|
+
/**
|
|
63
|
+
* Response headers.
|
|
64
|
+
*/
|
|
23
65
|
headers?: Record<string, string>;
|
|
66
|
+
/**
|
|
67
|
+
* JSON-serializable body or an adapter-specific body value.
|
|
68
|
+
*/
|
|
24
69
|
body?: unknown;
|
|
25
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Response accepted by Beignet handlers.
|
|
73
|
+
*
|
|
74
|
+
* Use `HttpResponseLike` for framework-neutral responses. Return a native
|
|
75
|
+
* `Response` only when the current adapter can pass it through unchanged.
|
|
76
|
+
*/
|
|
26
77
|
export type HttpResponse = HttpResponseLike | Response;
|
|
27
78
|
type InferSchemaOrFallback<T extends StandardSchema | null, Fallback> = T extends StandardSchema ? InferOutput<T> : Fallback;
|
|
79
|
+
/**
|
|
80
|
+
* Infer the handler path parameter type for a contract.
|
|
81
|
+
*/
|
|
28
82
|
export type InferPath<C extends HttpContractConfig> = InferSchemaOrFallback<C["pathParams"], Record<string, string>>;
|
|
83
|
+
/**
|
|
84
|
+
* Infer the handler query parameter type for a contract.
|
|
85
|
+
*/
|
|
29
86
|
export type InferQuery<C extends HttpContractConfig> = InferSchemaOrFallback<C["query"], Record<string, string | string[]>>;
|
|
87
|
+
/**
|
|
88
|
+
* Infer the handler request body type for a contract.
|
|
89
|
+
*/
|
|
30
90
|
export type InferBody<C extends HttpContractConfig> = InferSchemaOrFallback<C["body"], unknown>;
|
|
91
|
+
/**
|
|
92
|
+
* Infer the merged request header type for a contract.
|
|
93
|
+
*/
|
|
31
94
|
export type InferHeaders<C extends HttpContractConfig> = InferHeaderSchemaOutput<Exclude<C["headers"], undefined>> extends undefined ? Record<string, string> : InferHeaderSchemaOutput<Exclude<C["headers"], undefined>>;
|
|
95
|
+
/**
|
|
96
|
+
* Arguments passed to a route handler after request parsing and validation.
|
|
97
|
+
*/
|
|
32
98
|
export interface HandlerArgs<Ctx, C extends HttpContractConfig> {
|
|
99
|
+
/**
|
|
100
|
+
* Framework-neutral request.
|
|
101
|
+
*/
|
|
33
102
|
req: HttpRequestLike;
|
|
103
|
+
/**
|
|
104
|
+
* Application context returned by `createContext`.
|
|
105
|
+
*/
|
|
34
106
|
ctx: Ctx;
|
|
107
|
+
/**
|
|
108
|
+
* Matched contract config.
|
|
109
|
+
*/
|
|
35
110
|
contract: C;
|
|
111
|
+
/**
|
|
112
|
+
* Parsed path parameters.
|
|
113
|
+
*/
|
|
36
114
|
path: InferPath<C>;
|
|
115
|
+
/**
|
|
116
|
+
* Parsed query parameters.
|
|
117
|
+
*/
|
|
37
118
|
query: InferQuery<C>;
|
|
119
|
+
/**
|
|
120
|
+
* Parsed request headers.
|
|
121
|
+
*/
|
|
38
122
|
headers: InferHeaders<C>;
|
|
123
|
+
/**
|
|
124
|
+
* Parsed request body.
|
|
125
|
+
*/
|
|
39
126
|
body: InferBody<C>;
|
|
40
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Route handler function for a contract.
|
|
130
|
+
*/
|
|
41
131
|
export type Handler<Ctx, C extends HttpContractConfig> = (args: HandlerArgs<Ctx, C>) => Promise<HttpResponse> | HttpResponse;
|
|
132
|
+
/**
|
|
133
|
+
* Value or promise of that value.
|
|
134
|
+
*/
|
|
42
135
|
export type MaybePromise<T> = T | Promise<T>;
|
|
136
|
+
/**
|
|
137
|
+
* Hook that runs after a route is matched but before request parsing and
|
|
138
|
+
* context creation.
|
|
139
|
+
*
|
|
140
|
+
* Returning a response short-circuits the rest of the request pipeline.
|
|
141
|
+
*/
|
|
43
142
|
export type OnRequestHook<Ports extends AnyPorts = AnyPorts, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
44
143
|
req: HttpRequestLike;
|
|
45
144
|
ports: Ports;
|
|
46
145
|
contract: C;
|
|
47
146
|
params: Record<string, string>;
|
|
48
147
|
}) => MaybePromise<HttpResponse | undefined>;
|
|
148
|
+
/**
|
|
149
|
+
* Result from a `beforeHandle` hook.
|
|
150
|
+
*
|
|
151
|
+
* Returning a plain response short-circuits the handler. Returning an object can
|
|
152
|
+
* replace the context, short-circuit with a response, or do both.
|
|
153
|
+
*/
|
|
49
154
|
export type BeforeHandleResult<Ctx> = undefined | HttpResponse | {
|
|
50
155
|
ctx?: Ctx;
|
|
51
156
|
response?: HttpResponse;
|
|
52
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* Hook that runs after request parsing/context creation and before the handler.
|
|
160
|
+
*/
|
|
53
161
|
export type BeforeHandleHook<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
54
162
|
req: HttpRequestLike;
|
|
55
163
|
ctx: Ctx;
|
|
@@ -59,6 +167,12 @@ export type BeforeHandleHook<Ctx, C extends HttpContractConfig = HttpContractCon
|
|
|
59
167
|
headers: InferHeaders<C>;
|
|
60
168
|
body: InferBody<C>;
|
|
61
169
|
}) => MaybePromise<BeforeHandleResult<Ctx>>;
|
|
170
|
+
/**
|
|
171
|
+
* Hook that runs before a framework-neutral response is returned.
|
|
172
|
+
*
|
|
173
|
+
* Return a response to replace or decorate the outgoing response. Hooks run in
|
|
174
|
+
* declaration order.
|
|
175
|
+
*/
|
|
62
176
|
export type BeforeSendHook<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
63
177
|
req: HttpRequestLike;
|
|
64
178
|
ctx?: Ctx;
|
|
@@ -70,6 +184,12 @@ export type BeforeSendHook<Ctx, C extends HttpContractConfig = HttpContractConfi
|
|
|
70
184
|
response: HttpResponseLike;
|
|
71
185
|
error?: unknown;
|
|
72
186
|
}) => MaybePromise<HttpResponseLike | undefined>;
|
|
187
|
+
/**
|
|
188
|
+
* Hook that runs after the response has been prepared.
|
|
189
|
+
*
|
|
190
|
+
* This is for logging and observability. Errors thrown by `afterSend` hooks are
|
|
191
|
+
* ignored by the server pipeline.
|
|
192
|
+
*/
|
|
73
193
|
export type AfterSendHook<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
74
194
|
req: HttpRequestLike;
|
|
75
195
|
ctx?: Ctx;
|
|
@@ -82,6 +202,9 @@ export type AfterSendHook<Ctx, C extends HttpContractConfig = HttpContractConfig
|
|
|
82
202
|
error?: unknown;
|
|
83
203
|
durationMs: number;
|
|
84
204
|
}) => MaybePromise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Hook notified when the framework catches an error while handling a request.
|
|
207
|
+
*/
|
|
85
208
|
export type ServerCaughtErrorHook<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
86
209
|
err: unknown;
|
|
87
210
|
req: HttpRequestLike;
|
|
@@ -92,6 +215,12 @@ export type ServerCaughtErrorHook<Ctx, C extends HttpContractConfig = HttpContra
|
|
|
92
215
|
headers?: InferHeaders<C>;
|
|
93
216
|
body?: InferBody<C>;
|
|
94
217
|
}) => MaybePromise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Hook that may map an unexpected error to a custom response.
|
|
220
|
+
*
|
|
221
|
+
* Return `undefined` to let the server's default unhandled-error mapper create
|
|
222
|
+
* the response.
|
|
223
|
+
*/
|
|
95
224
|
export type ServerUnhandledErrorMapper<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
96
225
|
err: unknown;
|
|
97
226
|
req: HttpRequestLike;
|
|
@@ -102,18 +231,59 @@ export type ServerUnhandledErrorMapper<Ctx, C extends HttpContractConfig = HttpC
|
|
|
102
231
|
headers?: InferHeaders<C>;
|
|
103
232
|
body?: InferBody<C>;
|
|
104
233
|
}) => MaybePromise<HttpResponse | undefined>;
|
|
234
|
+
/**
|
|
235
|
+
* Server lifecycle hook collection.
|
|
236
|
+
*
|
|
237
|
+
* Hooks run in the order they are registered. `onRequest` can short-circuit
|
|
238
|
+
* before context creation; `beforeHandle` can replace context or short-circuit;
|
|
239
|
+
* `beforeSend` can replace the outgoing response; `afterSend` observes the
|
|
240
|
+
* final response.
|
|
241
|
+
*/
|
|
105
242
|
export interface ServerHook<Ctx, Ports extends AnyPorts = AnyPorts> {
|
|
243
|
+
/**
|
|
244
|
+
* Optional name used in diagnostics and devtools.
|
|
245
|
+
*/
|
|
106
246
|
name?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Runs after route matching and before body/query/header parsing.
|
|
249
|
+
*/
|
|
107
250
|
onRequest?: OnRequestHook<Ports>;
|
|
251
|
+
/**
|
|
252
|
+
* Runs after request parsing and context creation.
|
|
253
|
+
*/
|
|
108
254
|
beforeHandle?: BeforeHandleHook<Ctx>;
|
|
255
|
+
/**
|
|
256
|
+
* Runs before a framework-neutral response is returned.
|
|
257
|
+
*/
|
|
109
258
|
beforeSend?: BeforeSendHook<Ctx>;
|
|
259
|
+
/**
|
|
260
|
+
* Observes the final response after send preparation.
|
|
261
|
+
*/
|
|
110
262
|
afterSend?: AfterSendHook<Ctx>;
|
|
263
|
+
/**
|
|
264
|
+
* Observes framework-caught errors.
|
|
265
|
+
*/
|
|
111
266
|
onCaughtError?: ServerCaughtErrorHook<Ctx>;
|
|
267
|
+
/**
|
|
268
|
+
* Maps unexpected errors to responses.
|
|
269
|
+
*/
|
|
112
270
|
mapUnhandledError?: ServerUnhandledErrorMapper<Ctx>;
|
|
113
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Compiled route entry used by server internals and adapter helpers.
|
|
274
|
+
*/
|
|
114
275
|
export type ResolvedRoute<_Ctx, C extends HttpContractConfig> = {
|
|
276
|
+
/**
|
|
277
|
+
* Contract config for the route.
|
|
278
|
+
*/
|
|
115
279
|
contract: C;
|
|
280
|
+
/**
|
|
281
|
+
* Handler that receives the raw request and optional path params.
|
|
282
|
+
*/
|
|
116
283
|
handler: (req: HttpRequestLike, params?: Record<string, string>) => Promise<HttpResponse>;
|
|
284
|
+
/**
|
|
285
|
+
* Test whether the route matches an incoming method and pathname.
|
|
286
|
+
*/
|
|
117
287
|
match: (method: string, pathname: string) => {
|
|
118
288
|
matched: true;
|
|
119
289
|
} | {
|
|
@@ -1 +1 @@
|
|
|
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AAK,EAAE,CACL,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,KACb;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC;CAC7C,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,16 +4,34 @@
|
|
|
4
4
|
* Framework-agnostic HTTP server runtime for Beignet.
|
|
5
5
|
* Shared by Beignet server adapters.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Contract and schema types re-exported for server users.
|
|
9
|
+
*/
|
|
7
10
|
export type { HttpContractConfig, InferOutput, StandardSchema, StandardSchemaV1, } from "../contracts";
|
|
11
|
+
/**
|
|
12
|
+
* Application error base class re-exported for server users.
|
|
13
|
+
*/
|
|
8
14
|
export { AppError } from "../errors";
|
|
15
|
+
/**
|
|
16
|
+
* Any-ports helper type re-exported for server users.
|
|
17
|
+
*/
|
|
9
18
|
export type { AnyPorts } from "../ports";
|
|
19
|
+
/**
|
|
20
|
+
* Provider type re-exported for server users.
|
|
21
|
+
*/
|
|
10
22
|
export type { ServiceProvider } from "../providers";
|
|
11
23
|
export * from "./health";
|
|
12
24
|
export * from "./hooks";
|
|
13
25
|
export * from "./http";
|
|
14
26
|
export * from "./openapi";
|
|
15
27
|
export * from "./providers";
|
|
28
|
+
/**
|
|
29
|
+
* Server configuration and route types.
|
|
30
|
+
*/
|
|
16
31
|
export type { CreateServerOptions, RouteDef, RouteGroup, ServerInstance, } from "./server";
|
|
32
|
+
/**
|
|
33
|
+
* Server runtime helpers.
|
|
34
|
+
*/
|
|
17
35
|
export { contractsFromRoutes, createServer, defineRouteGroup, defineRoutes, } from "./server";
|
|
18
36
|
export * from "./types";
|
|
19
37
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC;;GAEG;AACH,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC;;GAEG;AACH,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B;;GAEG;AACH,YAAY,EACV,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,cAAc,GACf,MAAM,UAAU,CAAC;AAClB;;GAEG;AACH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,cAAc,SAAS,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
* Framework-agnostic HTTP server runtime for Beignet.
|
|
5
5
|
* Shared by Beignet server adapters.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Application error base class re-exported for server users.
|
|
9
|
+
*/
|
|
7
10
|
export { AppError } from "../errors";
|
|
8
11
|
export * from "./health";
|
|
9
12
|
export * from "./hooks";
|
|
10
13
|
export * from "./http";
|
|
11
14
|
export * from "./openapi";
|
|
12
15
|
export * from "./providers";
|
|
16
|
+
/**
|
|
17
|
+
* Server runtime helpers.
|
|
18
|
+
*/
|
|
13
19
|
export { contractsFromRoutes, createServer, defineRouteGroup, defineRoutes, } from "./server";
|
|
14
20
|
export * from "./types";
|
|
15
21
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AASrC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAU5B;;GAEG;AACH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,cAAc,SAAS,CAAC"}
|
package/dist/server/openapi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { HttpContractConfig } from "../contracts";
|
|
|
6
6
|
import type { AppEnvironment } from "./health";
|
|
7
7
|
import type { HttpRequestLike, HttpResponseLike } from "./types";
|
|
8
8
|
/**
|
|
9
|
-
* OpenAPI configuration
|
|
9
|
+
* OpenAPI route handler configuration.
|
|
10
10
|
*/
|
|
11
11
|
export interface OpenAPIConfig {
|
|
12
12
|
/** Enable OpenAPI endpoint (default: false) */
|
|
@@ -25,8 +25,10 @@ export interface OpenAPIConfig {
|
|
|
25
25
|
description?: string;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Create
|
|
29
|
-
*
|
|
28
|
+
* Create a framework-neutral OpenAPI JSON handler.
|
|
29
|
+
*
|
|
30
|
+
* The OpenAPI document is generated lazily on the first request and then cached
|
|
31
|
+
* for the lifetime of the handler.
|
|
30
32
|
*/
|
|
31
33
|
export declare function createOpenAPIHandler(contracts: readonly HttpContractConfig[], openapiConfig: OpenAPIConfig | undefined, _env: AppEnvironment): (req: HttpRequestLike) => Promise<HttpResponseLike>;
|
|
32
34
|
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/server/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/server/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,kBAAkB,EAAE,EACxC,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,IAAI,EAAE,cAAc,GACnB,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAkCrD"}
|
package/dist/server/openapi.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* OpenAPI helpers for the Beignet server runtime.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Create
|
|
7
|
-
*
|
|
6
|
+
* Create a framework-neutral OpenAPI JSON handler.
|
|
7
|
+
*
|
|
8
|
+
* The OpenAPI document is generated lazily on the first request and then cached
|
|
9
|
+
* for the lifetime of the handler.
|
|
8
10
|
*/
|
|
9
11
|
export function createOpenAPIHandler(contracts, openapiConfig, _env) {
|
|
10
12
|
// Lazily generate OpenAPI spec on first request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/server/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/server/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAwC,EACxC,aAAwC,EACxC,IAAoB;IAEpB,gDAAgD;IAChD,IAAI,UAAU,GAAkB,IAAI,CAAC;IAErC,OAAO,KAAK,EAAE,IAAqB,EAA6B,EAAE;QAChE,8BAA8B;QAC9B,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,0CAA0C;gBAC1C,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC1D,UAAU,GAAG,kBAAkB,CAAC,SAAS,EAAE;oBACzC,KAAK,EAAE,aAAa,EAAE,KAAK,IAAI,aAAa;oBAC5C,OAAO,EAAE,aAAa,EAAE,OAAO,IAAI,OAAO;oBAC1C,WAAW,EAAE,aAAa,EAAE,WAAW;iBACxC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,4BAA4B;gBAC5B,OAAO;oBACL,MAAM,EAAE,GAAG;oBACX,IAAI,EAAE;wBACJ,KAAK,EAAE,2BAA2B;wBAClC,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;qBAClE;oBACD,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;iBAChD,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -2,6 +2,15 @@ import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
2
2
|
import type { AnyPorts } from "../../ports";
|
|
3
3
|
import type { ServiceProvider } from "../../providers";
|
|
4
4
|
declare function parseStandardSchema<Schema extends StandardSchemaV1<unknown, unknown>>(schema: Schema, input: unknown): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
5
|
+
/**
|
|
6
|
+
* Load and validate config for a provider.
|
|
7
|
+
*
|
|
8
|
+
* Explicit overrides take precedence over env-derived config. When a provider
|
|
9
|
+
* declares `envPrefix`, matching env keys are stripped before validation.
|
|
10
|
+
*/
|
|
5
11
|
export declare function loadProviderConfig<Ports extends AnyPorts, Schema extends StandardSchemaV1<unknown, unknown>>(provider: ServiceProvider<Ports, Schema>, env: Record<string, string | undefined>, overrides: Record<string, unknown>): Promise<StandardSchemaV1.InferOutput<Schema> | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Parse provider config with Standard Schema and normalize validation errors.
|
|
14
|
+
*/
|
|
6
15
|
export { parseStandardSchema };
|
|
7
16
|
//# sourceMappingURL=loadProviderConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadProviderConfig.d.ts","sourceRoot":"","sources":["../../../src/server/providers/loadProviderConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAOvD,iBAAe,mBAAmB,CAChC,MAAM,SAAS,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAEjD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAU/C;AAED,wBAAsB,kBAAkB,CACtC,KAAK,SAAS,QAAQ,EACtB,MAAM,SAAS,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAEjD,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CA8B3D;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"loadProviderConfig.d.ts","sourceRoot":"","sources":["../../../src/server/providers/loadProviderConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAOvD,iBAAe,mBAAmB,CAChC,MAAM,SAAS,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAEjD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAU/C;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,SAAS,QAAQ,EACtB,MAAM,SAAS,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAEjD,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CA8B3D;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -11,6 +11,12 @@ async function parseStandardSchema(schema, input) {
|
|
|
11
11
|
throw error;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Load and validate config for a provider.
|
|
16
|
+
*
|
|
17
|
+
* Explicit overrides take precedence over env-derived config. When a provider
|
|
18
|
+
* declares `envPrefix`, matching env keys are stripped before validation.
|
|
19
|
+
*/
|
|
14
20
|
export async function loadProviderConfig(provider, env, overrides) {
|
|
15
21
|
const configDef = provider.config;
|
|
16
22
|
if (!configDef)
|
|
@@ -38,5 +44,8 @@ export async function loadProviderConfig(provider, env, overrides) {
|
|
|
38
44
|
throw new Error(`Failed to load config for provider "${provider.name}"${suffix}: ${error.message}${hint}`);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse provider config with Standard Schema and normalize validation errors.
|
|
49
|
+
*/
|
|
41
50
|
export { parseStandardSchema };
|
|
42
51
|
//# sourceMappingURL=loadProviderConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadProviderConfig.js","sourceRoot":"","sources":["../../../src/server/providers/loadProviderConfig.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AASrD,KAAK,UAAU,mBAAmB,CAGhC,MAAc,EACd,KAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAItC,QAAwC,EACxC,GAAuC,EACvC,SAAkC;IAElC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAA+C,CAAC;IAC3E,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAEjC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,WAAW;QACvB,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC1B,CAAC,CAAC,SAAS;YACT,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YACrC,CAAC,CAAC,EAAE,CAAC;IAET,IAAI,CAAC;QACH,OAAO,MAAM,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,eAAe,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,SAAS;YACrB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CACrB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CACvD;YACH,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,GAAG,SAAS;YACpB,CAAC,CAAC,KAAK,CAAC,MAAM;gBACZ,CAAC,CAAC,mCAAmC,SAAS,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACtE,CAAC,CAAC,sCAAsC,SAAS,GAAG;YACtD,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,KAAK,CACb,uCAAuC,QAAQ,CAAC,IAAI,IAAI,MAAM,KAAM,KAAe,CAAC,OAAO,GAAG,IAAI,EAAE,CACrG,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"loadProviderConfig.js","sourceRoot":"","sources":["../../../src/server/providers/loadProviderConfig.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AASrD,KAAK,UAAU,mBAAmB,CAGhC,MAAc,EACd,KAAc;IAEd,IAAI,CAAC;QACH,OAAO,MAAM,wBAAwB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;QAED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,sCAAsC,SAAS,GAAG;YACtD,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,KAAK,CACb,uCAAuC,QAAQ,CAAC,IAAI,IAAI,MAAM,KAAM,KAAe,CAAC,OAAO,GAAG,IAAI,EAAE,CACrG,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -5,16 +5,41 @@ import type { ProvidedPortsOfList, ServiceProvider } from "../providers";
|
|
|
5
5
|
import type { ContractLike, ResolveContract } from "./contract-like";
|
|
6
6
|
import type { Handler, HttpRequestLike, HttpResponse, ServerCaughtErrorHook, ServerHook, ServerUnhandledErrorMapper } from "./http";
|
|
7
7
|
/**
|
|
8
|
-
* Route
|
|
8
|
+
* Route registration for one contract.
|
|
9
|
+
*
|
|
10
|
+
* Route definitions connect a contract to the handler that implements it. Most
|
|
11
|
+
* apps keep these in `features/<feature>/routes.ts` and compose them with
|
|
12
|
+
* `defineRoutes(...)`.
|
|
9
13
|
*/
|
|
10
14
|
export type RouteDef<Ctx, CLike extends ContractLike = ContractLike> = {
|
|
15
|
+
/**
|
|
16
|
+
* Contract builder or plain contract config for this route.
|
|
17
|
+
*/
|
|
11
18
|
contract: CLike;
|
|
19
|
+
/**
|
|
20
|
+
* Handler that implements the contract.
|
|
21
|
+
*/
|
|
12
22
|
handle: Handler<Ctx, ResolveContract<CLike>>;
|
|
13
23
|
};
|
|
14
24
|
declare const ROUTE_GROUP_KIND = "beignet.route-group";
|
|
25
|
+
/**
|
|
26
|
+
* Named collection of related route registrations.
|
|
27
|
+
*
|
|
28
|
+
* Route groups are an organization helper only. `defineRoutes(...)` flattens
|
|
29
|
+
* them before server registration.
|
|
30
|
+
*/
|
|
15
31
|
export type RouteGroup<Ctx, Routes extends readonly RouteDef<Ctx, any>[] = readonly RouteDef<Ctx, any>[]> = {
|
|
32
|
+
/**
|
|
33
|
+
* Internal marker used by `defineRoutes(...)`.
|
|
34
|
+
*/
|
|
16
35
|
kind: typeof ROUTE_GROUP_KIND;
|
|
36
|
+
/**
|
|
37
|
+
* Human-readable group name.
|
|
38
|
+
*/
|
|
17
39
|
name: string;
|
|
40
|
+
/**
|
|
41
|
+
* Route definitions in this group.
|
|
42
|
+
*/
|
|
18
43
|
routes: Routes;
|
|
19
44
|
};
|
|
20
45
|
type RouteInput<Ctx> = RouteDef<Ctx, any> | RouteGroup<Ctx, readonly RouteDef<Ctx, any>[]>;
|
|
@@ -23,60 +48,134 @@ type FlattenRouteInputs<Inputs extends readonly unknown[]> = number extends Inpu
|
|
|
23
48
|
type ContractsFromRouteList<Routes extends readonly RouteDef<any, any>[]> = {
|
|
24
49
|
readonly [Index in keyof Routes]: Routes[Index] extends RouteDef<any, infer CLike> ? ResolveContract<CLike> : never;
|
|
25
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Options for creating a Beignet server instance.
|
|
53
|
+
*/
|
|
26
54
|
export type CreateServerOptions<Ctx, Ports extends AnyPorts, Routes extends readonly RouteDef<Ctx, any>[] = readonly RouteDef<Ctx, any>[], Providers extends readonly ServiceProvider<unknown, StandardSchemaV1<any, any>, AnyPorts>[] = readonly []> = {
|
|
55
|
+
/**
|
|
56
|
+
* App-owned ports available to context creation, hooks, and handlers.
|
|
57
|
+
*/
|
|
27
58
|
ports: Ports;
|
|
59
|
+
/**
|
|
60
|
+
* Providers installed during server startup.
|
|
61
|
+
*
|
|
62
|
+
* Provider ports are merged into `ports` before request handling and are
|
|
63
|
+
* stopped in reverse setup order when `server.stop()` runs.
|
|
64
|
+
*/
|
|
28
65
|
providers?: Providers;
|
|
66
|
+
/**
|
|
67
|
+
* Runtime env used by providers. Defaults to `process.env`.
|
|
68
|
+
*/
|
|
29
69
|
providerEnv?: Record<string, string | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Provider config overrides keyed by provider name.
|
|
72
|
+
*/
|
|
30
73
|
providerConfig?: Record<string, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Create request context after a route is matched.
|
|
76
|
+
*
|
|
77
|
+
* The `ports` argument includes app ports plus ports provided during server
|
|
78
|
+
* startup.
|
|
79
|
+
*/
|
|
31
80
|
createContext: (args: {
|
|
32
81
|
req: HttpRequestLike;
|
|
33
82
|
ports: Ports & ProvidedPortsOfList<Providers>;
|
|
34
83
|
contract?: HttpContractConfig;
|
|
35
84
|
}) => Ctx | Promise<Ctx>;
|
|
85
|
+
/**
|
|
86
|
+
* Server hooks that wrap every registered route.
|
|
87
|
+
*/
|
|
36
88
|
hooks?: ServerHook<Ctx, Ports & ProvidedPortsOfList<Providers>>[];
|
|
89
|
+
/**
|
|
90
|
+
* Route list to register up front.
|
|
91
|
+
*/
|
|
37
92
|
routes?: Routes;
|
|
93
|
+
/**
|
|
94
|
+
* Global caught-error observer.
|
|
95
|
+
*/
|
|
38
96
|
onCaughtError?: ServerCaughtErrorHook<Ctx>;
|
|
97
|
+
/**
|
|
98
|
+
* Global mapper for unexpected errors not handled by app error catalogs.
|
|
99
|
+
*/
|
|
39
100
|
mapUnhandledError?: ServerUnhandledErrorMapper<Ctx>;
|
|
40
101
|
};
|
|
41
102
|
interface RouteBuilder<Ctx, C extends HttpContractConfig> {
|
|
42
103
|
handle: (fn: Handler<Ctx, C>) => (req: HttpRequestLike) => Promise<HttpResponse>;
|
|
43
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Runtime server object returned by `createServer(...)`.
|
|
107
|
+
*/
|
|
44
108
|
export interface ServerInstance<Ctx, Ports extends AnyPorts = AnyPorts> {
|
|
109
|
+
/**
|
|
110
|
+
* Catch-all request handler for platform adapters.
|
|
111
|
+
*/
|
|
45
112
|
api: (req: HttpRequestLike) => Promise<HttpResponse>;
|
|
113
|
+
/**
|
|
114
|
+
* Register and build a single route handler imperatively.
|
|
115
|
+
*/
|
|
46
116
|
route: <CLike extends ContractLike>(contractLike: CLike) => RouteBuilder<Ctx, ResolveContract<CLike>>;
|
|
117
|
+
/**
|
|
118
|
+
* Contract configs registered through the `routes` option.
|
|
119
|
+
*/
|
|
47
120
|
contracts: readonly HttpContractConfig[];
|
|
121
|
+
/**
|
|
122
|
+
* Stop installed providers in reverse setup order.
|
|
123
|
+
*/
|
|
48
124
|
stop: () => Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Final app ports after provider setup.
|
|
127
|
+
*/
|
|
49
128
|
ports: Ports;
|
|
50
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a Beignet server instance.
|
|
132
|
+
*
|
|
133
|
+
* The server owns route registration, provider setup/startup, request
|
|
134
|
+
* validation, hook execution, response validation, and framework error mapping.
|
|
135
|
+
* Use adapter packages such as `@beignet/next` to expose `server.api` to a
|
|
136
|
+
* specific runtime.
|
|
137
|
+
*
|
|
138
|
+
* @param options - Ports, providers, routes, hooks, context factory, and error
|
|
139
|
+
* mapping hooks for the server.
|
|
140
|
+
* @returns A started server instance with final ports and a catch-all handler.
|
|
141
|
+
*/
|
|
51
142
|
export declare function createServer<Ctx, Ports extends AnyPorts, Routes extends readonly RouteDef<Ctx, any>[] = readonly RouteDef<Ctx, any>[], Providers extends readonly ServiceProvider<unknown, StandardSchemaV1<any, any>, AnyPorts>[] = readonly []>(options: CreateServerOptions<Ctx, Ports, Routes, Providers>): Promise<ServerInstance<Ctx, Ports & ProvidedPortsOfList<Providers>>>;
|
|
52
143
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
144
|
+
* Define and flatten route registrations with strong type inference.
|
|
145
|
+
*
|
|
146
|
+
* Pass route definitions and route groups here before `createServer(...)`.
|
|
147
|
+
* Group entries are flattened so downstream tooling receives one route list.
|
|
55
148
|
*
|
|
56
149
|
* @example
|
|
150
|
+
* ```ts
|
|
57
151
|
* const routes = defineRoutes<AppContext>([
|
|
58
|
-
* { contract:
|
|
152
|
+
* { contract: listPosts, handle: async ({ ctx }) => ctx.posts.list() },
|
|
59
153
|
* ]);
|
|
154
|
+
* ```
|
|
60
155
|
*/
|
|
61
156
|
export declare function defineRoutes<Ctx, const R extends readonly RouteInput<Ctx>[] = readonly RouteInput<Ctx>[]>(routes: R): FlattenRouteInputs<R>;
|
|
62
157
|
/**
|
|
63
|
-
* Extract contract configs from a route list.
|
|
64
|
-
*
|
|
158
|
+
* Extract contract configs from a route list.
|
|
159
|
+
*
|
|
160
|
+
* Use this to drive clients, OpenAPI, and docs from the same route list passed
|
|
161
|
+
* to `createServer(...)`.
|
|
65
162
|
*/
|
|
66
163
|
export declare function contractsFromRoutes<const R extends readonly RouteDef<any, any>[]>(routes: R): ContractsFromRouteList<R>;
|
|
67
164
|
/**
|
|
68
|
-
*
|
|
165
|
+
* Define a named group of related route registrations.
|
|
69
166
|
*
|
|
70
167
|
* Route groups are flattened by defineRoutes, so createServer still receives
|
|
71
168
|
* a regular route list while app code can keep feature route wiring colocated.
|
|
72
169
|
*
|
|
73
170
|
* @example
|
|
171
|
+
* ```ts
|
|
74
172
|
* const todoRoutes = defineRouteGroup<AppContext>({
|
|
75
173
|
* name: "todos",
|
|
76
174
|
* routes: [
|
|
77
|
-
* { contract: listTodos, handle: async ({ ctx }) =>
|
|
175
|
+
* { contract: listTodos, handle: async ({ ctx }) => ctx.todos.list() },
|
|
78
176
|
* ]
|
|
79
177
|
* });
|
|
178
|
+
* ```
|
|
80
179
|
*/
|
|
81
180
|
export declare function defineRouteGroup<Ctx, const R extends readonly RouteDef<Ctx, any>[] = readonly RouteDef<Ctx, any>[]>(group: {
|
|
82
181
|
name: string;
|