@congruent-stack/congruent-api 0.4.0 → 0.6.0

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/dist/index.d.cts CHANGED
@@ -1,3 +1,367 @@
1
- declare function getHelloWorldMessage(name: string): string;
1
+ import z, { z as z$1 } from 'zod';
2
2
 
3
- export { getHelloWorldMessage };
3
+ declare enum HttpStatusCode {
4
+ Continue_100 = 100,
5
+ SwitchingProtocols_101 = 101,
6
+ OK_200 = 200,
7
+ Created_201 = 201,
8
+ Accepted_202 = 202,
9
+ NoContent_204 = 204,
10
+ MultipleChoices_300 = 300,
11
+ MovedPermanently_301 = 301,
12
+ Found_302 = 302,
13
+ SeeOther_303 = 303,
14
+ NotModified_304 = 304,
15
+ BadRequest_400 = 400,
16
+ Unauthorized_401 = 401,
17
+ Forbidden_403 = 403,
18
+ NotFound_404 = 404,
19
+ Conflict_409 = 409,
20
+ InternalServerError_500 = 500,
21
+ NotImplemented_501 = 501,
22
+ BadGateway_502 = 502,
23
+ ServiceUnavailable_503 = 503,
24
+ GatewayTimeout_504 = 504
25
+ }
26
+ declare function isHttpStatusCode(value: any): value is HttpStatusCode;
27
+
28
+ type HttpMethod = "ALL" | "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
29
+ type LowerCasedHttpMethod = Lowercase<HttpMethod>;
30
+
31
+ declare function response<TStatus extends HttpStatusCode, TDef extends IHttpMethodEndpointResponseDefinition<TStatus>>(definition: TDef): HttpMethodEndpointResponse<TStatus, TDef>;
32
+ interface IHttpMethodEndpointResponseDefinition<_TStatus extends HttpStatusCode> {
33
+ headers?: Record<string, string>;
34
+ body?: z.ZodType;
35
+ }
36
+ declare class HttpMethodEndpointResponse<TStatus extends HttpStatusCode, TDef extends IHttpMethodEndpointResponseDefinition<TStatus>> {
37
+ private _definition;
38
+ get definition(): TDef;
39
+ constructor(definition: TDef);
40
+ }
41
+
42
+ declare function endpoint<TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>>(definition: TDef): HttpMethodEndpoint<TDef>;
43
+ interface IHttpMethodEndpointDefinition {
44
+ headers?: z$1.ZodType;
45
+ query?: z$1.ZodType;
46
+ body?: z$1.ZodType;
47
+ responses: HttpMethodEndpointResponses;
48
+ }
49
+ type ValidateHttpMethodEndpointDefinition<TDef extends IHttpMethodEndpointDefinition> = {
50
+ responses: {
51
+ [K in keyof TDef['responses']]: K extends HttpStatusCode ? TDef['responses'][K] extends HttpMethodEndpointResponse<infer TStatus, infer TResponseDef> ? HttpMethodEndpointResponse<TStatus, TResponseDef> : "❌ ERROR: HttpMethodEndpointResponse only allowed on HttpStatusCode key" : "❌ ERROR: HttpMethodEndpointResponse only allowed on HttpStatusCode key";
52
+ };
53
+ };
54
+ type HttpMethodEndpointResponses = Partial<{
55
+ readonly [status in HttpStatusCode]: HttpMethodEndpointResponse<status, any>;
56
+ }>;
57
+ declare class HttpMethodEndpoint<const TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>> {
58
+ private _definition;
59
+ get definition(): TDef;
60
+ private _pathSegments;
61
+ get pathSegments(): readonly string[];
62
+ private _cachedGenericPath;
63
+ get genericPath(): string;
64
+ private _method;
65
+ get method(): HttpMethod;
66
+ get lowerCasedMethod(): LowerCasedHttpMethod;
67
+ constructor(definition: TDef);
68
+ }
69
+
70
+ declare function apiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(definition: TDef): ApiContract<TDef>;
71
+ interface IApiContractDefinition {
72
+ readonly [key: string]: IApiContractDefinition | HttpMethodEndpoint<any>;
73
+ }
74
+ type ValidateApiContractDefinition<T> = {
75
+ [K in keyof T]: T[K] extends HttpMethodEndpoint<infer TEndpDef> ? K extends HttpMethod ? HttpMethodEndpoint<TEndpDef> : "❌ ERROR: HttpMethodEndpoint only allowed on HttpMethod key" : K extends HttpMethod ? " ❌ ERROR: method key must hold an HttpMethodEndpoint" : T[K] extends object ? ValidateApiContractDefinition<T[K]> : T[K];
76
+ };
77
+ declare class ApiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
78
+ readonly definition: TDef;
79
+ constructor(definition: TDef);
80
+ cloneInitDef(): TDef;
81
+ private static _deepCloneInitDef;
82
+ }
83
+
84
+ /**
85
+ * Extracts typed path parameters from a path string.
86
+ * For example, given a path string like ":p1:p2:...:pn", it will return an object type with properties for each parameter.
87
+ *
88
+ * @template TPathParams - The path parameters string, e.g., ":id:name:age".
89
+ * @returns An object type with properties for each parameter.
90
+ *
91
+ * @example
92
+ * ```
93
+ * const typedParams: TypedPathParams<':id:name'> = {
94
+ * id: '1',
95
+ * name: 'Bulbasaur'
96
+ * };
97
+ * console.log(typedParams.id); // "1"
98
+ * console.log(typedParams.name); // "Bulbasaur"
99
+ * ```
100
+ */
101
+ type TypedPathParams<TPathParams extends string> = TPathParams extends `:${infer ParamName}:${infer RestParams}` ? {
102
+ [K in ParamName]: string;
103
+ } & TypedPathParams<`:${RestParams}`> : TPathParams extends `:${infer ParamName}` ? {
104
+ [K in ParamName]: string;
105
+ } : {};
106
+ type ExtractConcatenatedParamNamesFromMethodFirstPath<TPath extends string> = TPath extends `${string} ${infer PathPart}` ? ExtractConcatenatedParamNamesFromPathSegments<PathPart> : never;
107
+ type ExtractConcatenatedParamNamesFromPathSegments<TPath extends string> = TPath extends `/${infer Segment}/${infer Rest}` ? Segment extends `:${infer ParamName}` ? `:${ParamName}${ExtractConcatenatedParamNamesFromPathSegments<`/${Rest}`> extends `:${infer RestParams}` ? `:${RestParams}` : ""}` : ExtractConcatenatedParamNamesFromPathSegments<`/${Rest}`> : TPath extends `/${infer Segment}` ? Segment extends `:${infer ParamName}` ? `:${ParamName}` : "" : "";
108
+ type ExtractConcatenatedParamNamesFromPath<TPath extends string> = TPath extends `${string} ${string}` ? ExtractConcatenatedParamNamesFromMethodFirstPath<TPath> : TPath extends `/${string}` ? ExtractConcatenatedParamNamesFromPathSegments<TPath> : never;
109
+
110
+ type HttpMethodEndpointHandlerInput<TEndpointDefinition extends IHttpMethodEndpointDefinition, TPathParams extends string, TInjected> = {
111
+ method: HttpMethod;
112
+ pathSegments: readonly string[];
113
+ path: string;
114
+ genericPath: string;
115
+ headers: TEndpointDefinition['headers'] extends z$1.ZodType ? z$1.output<TEndpointDefinition['headers']> : Record<string, string>;
116
+ pathParams: TypedPathParams<TPathParams>;
117
+ query: TEndpointDefinition['query'] extends z$1.ZodType ? z$1.output<TEndpointDefinition['query']> : null;
118
+ body: TEndpointDefinition['body'] extends z$1.ZodType ? z$1.output<TEndpointDefinition['body']> : null;
119
+ injected: Readonly<TInjected>;
120
+ };
121
+ type ClientHttpMethodEndpointHandlerInput = {
122
+ method: HttpMethod;
123
+ pathSegments: readonly string[];
124
+ path: string;
125
+ genericPath: string;
126
+ headers: Record<string, string>;
127
+ pathParams: Record<string, string>;
128
+ query?: any;
129
+ body?: any;
130
+ };
131
+
132
+ type HttpMethodEndpointHandlerOutput<TEndpointDefinition extends IHttpMethodEndpointDefinition> = {
133
+ [THttpStatusCode in keyof TEndpointDefinition['responses'] & HttpStatusCode]: TEndpointDefinition['responses'][THttpStatusCode] extends HttpMethodEndpointResponse<THttpStatusCode, infer TRespDef> ? CreateHandlerOutput<THttpStatusCode, TRespDef> : never;
134
+ }[keyof TEndpointDefinition['responses'] & HttpStatusCode];
135
+ type CreateHandlerOutput<THttpStatusCode extends HttpStatusCode, TRespDef> = TRespDef extends {
136
+ body: z$1.ZodType;
137
+ } ? {
138
+ code: THttpStatusCode;
139
+ body: z$1.input<TRespDef['body']>;
140
+ } : {
141
+ code: THttpStatusCode;
142
+ body?: never;
143
+ };
144
+ type ClientHttpMethodEndpointHandlerOutput = {
145
+ code: HttpStatusCode;
146
+ body: any;
147
+ };
148
+ type HttpResponseObject = {
149
+ code: HttpStatusCode;
150
+ body?: any;
151
+ };
152
+ declare function isHttpResponseObject(obj: any): obj is HttpResponseObject;
153
+
154
+ type HttpMethodEndpointHandler<TDef extends IHttpMethodEndpointDefinition, TPathParams extends string, TInjected> = (input: HttpMethodEndpointHandlerInput<TDef, TPathParams, TInjected>) => Promise<HttpMethodEndpointHandlerOutput<TDef>>;
155
+ type ClientHttpMethodEndpointHandler = (input: ClientHttpMethodEndpointHandlerInput) => Promise<ClientHttpMethodEndpointHandlerOutput>;
156
+
157
+ type StringLiteral<S> = S extends string ? string extends S ? never : S : never;
158
+ type DIClass<T> = new (...args: any[]) => T;
159
+ type DILifetime = 'singleton' | 'transient' | 'scoped';
160
+ type DIServiceRegistry = Record<string, any>;
161
+ /**
162
+ * A scoped container that provides typed method access to services.
163
+ */
164
+ type DIScope<R extends DIServiceRegistry> = {
165
+ [K in keyof R as `get${string & K}`]: () => R[K];
166
+ };
167
+ /**
168
+ * This is the core of the static typing. It's a "mapped type" that takes a
169
+ * ServiceRegistry `R` and creates a new type. For each key `K` in the registry,
170
+ * it adds a method named `getK` that returns an instance of the corresponding service type.
171
+ *
172
+ * For example, if R is `{ LoggerService: LoggerService }`, this type will be:
173
+ * { getLoggerService: () => LoggerService }
174
+ */
175
+ type DITypedContainer<R extends DIServiceRegistry> = DIContainer<R> & {
176
+ [K in keyof R as `get${string & K}`]: () => R[K];
177
+ };
178
+ /**
179
+ * A Dependency Injection (DI) Container that provides static typing for resolved services.
180
+ */
181
+ declare class DIContainer<R extends DIServiceRegistry = {}> {
182
+ private registry;
183
+ private singletons;
184
+ private proxy;
185
+ /**
186
+ * The constructor returns a Proxy. This is the runtime magic that intercepts
187
+ * calls to methods like `getLoggerService()`. It parses the method name,
188
+ * finds the corresponding service class in the registry, and resolves it.
189
+ */
190
+ constructor();
191
+ /**
192
+ * Registers a service with explicit service name (fully type-safe).
193
+ */
194
+ register<T, N extends string>(serviceNameLiteral: StringLiteral<N>, factory: (container: DITypedContainer<R>) => T, lifetime?: DILifetime): DITypedContainer<R & Record<N, T>>;
195
+ /**
196
+ * Resolves a service by service name.
197
+ */
198
+ private resolveByName;
199
+ /**
200
+ * Creates a scoped container with typed method access to services.
201
+ */
202
+ createScope(): DIScope<R>;
203
+ createTestClone(): this;
204
+ }
205
+
206
+ type PrepareRegistryEntryCallback<TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string> = (entry: MethodEndpointHandlerRegistryEntry<TDef, TDIContainer, TPathParams, any>) => void;
207
+ type OnHandlerRegisteredCallback<TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string> = (entry: MethodEndpointHandlerRegistryEntry<TDef, TDIContainer, TPathParams, any>) => void;
208
+ declare class MethodEndpointHandlerRegistryEntry<TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string, TInjected = {}> {
209
+ private _methodEndpoint;
210
+ get methodEndpoint(): HttpMethodEndpoint<TDef>;
211
+ private _dicontainer;
212
+ get dicontainer(): TDIContainer;
213
+ constructor(methodEndpoint: HttpMethodEndpoint<TDef>, dicontainer: TDIContainer);
214
+ private _handler;
215
+ get handler(): HttpMethodEndpointHandler<TDef, TPathParams, TInjected> | null;
216
+ register(handler: HttpMethodEndpointHandler<TDef, TPathParams, TInjected>): void;
217
+ private _onHandlerRegisteredCallback;
218
+ _onHandlerRegistered(callback: OnHandlerRegisteredCallback<TDef, TDIContainer, TPathParams>): void;
219
+ prepare(callback: PrepareRegistryEntryCallback<TDef, TDIContainer, TPathParams>): this;
220
+ private _injection;
221
+ get injection(): any;
222
+ inject<TNewInjected>(injection: (dicontainer: TDIContainer) => TNewInjected): MethodEndpointHandlerRegistryEntry<TDef, TDIContainer, TPathParams, TNewInjected>;
223
+ trigger(data: {
224
+ headers: Record<string, string>;
225
+ pathParams: Record<string, string>;
226
+ query: object;
227
+ body: object;
228
+ }): Promise<any>;
229
+ }
230
+
231
+ type MiddlewareHandlerInputSchemas = {
232
+ headers?: z$1.ZodType;
233
+ query?: z$1.ZodType;
234
+ body?: z$1.ZodType;
235
+ };
236
+ type MiddlewareHandlerInput<TPathParams extends string, InputSchemas extends MiddlewareHandlerInputSchemas, TInjected> = {
237
+ method: HttpMethod;
238
+ pathSegments: readonly string[];
239
+ path: string;
240
+ genericPath: string;
241
+ headers: InputSchemas['headers'] extends z$1.ZodType ? z$1.output<InputSchemas['headers']> : Record<string, string>;
242
+ pathParams: TypedPathParams<TPathParams>;
243
+ query: InputSchemas['query'] extends z$1.ZodType ? z$1.output<InputSchemas['query']> : null;
244
+ body: InputSchemas['body'] extends z$1.ZodType ? z$1.output<InputSchemas['body']> : null;
245
+ injected: Readonly<TInjected>;
246
+ };
247
+ type MiddlewareHandlerInputInternal<TInjected> = {
248
+ method: HttpMethod;
249
+ pathSegments: readonly string[];
250
+ path: string;
251
+ genericPath: string;
252
+ headers: Record<string, string>;
253
+ pathParams: Record<string, string>;
254
+ query: Record<string, any> | null;
255
+ body: Record<string, any> | null;
256
+ injected: Readonly<TInjected>;
257
+ };
258
+ type MiddlewareHandler<TPathParams extends string, InputSchemas extends MiddlewareHandlerInputSchemas, TInjected> = (input: MiddlewareHandlerInput<TPathParams, InputSchemas, TInjected>, next: () => void) => Promise<HttpResponseObject | void>;
259
+ type MiddlewareHandlerInternal<TInjected> = (input: MiddlewareHandlerInputInternal<TInjected>, next: () => void) => Promise<HttpResponseObject | void>;
260
+ declare function middleware<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TDIContainer extends DIContainer, TPathParams extends string, const TPath extends MiddlewarePath<TApiDef>, TInjected = {}>(apiReg: ApiHandlersRegistry<TApiDef, TDIContainer, TPathParams>, path: TPath): MiddlewareHandlersRegistryEntry<TApiDef, TDIContainer, TPathParams, TPath, TInjected>;
261
+ type MiddlewarePath<TDef, BasePath extends string = ""> = (BasePath extends "" ? "" : never) | {
262
+ [K in keyof TDef & string]: TDef[K] extends HttpMethodEndpoint<infer _TEndpointDef> ? `${K} ${BasePath}` : TDef[K] extends object ? `${BasePath}/${K}` | MiddlewarePath<TDef[K], `${BasePath}/${K}`> : never;
263
+ }[keyof TDef & string];
264
+ declare class MiddlewareHandlersRegistryEntryInternal<TDIContainer extends DIContainer, TInjected> {
265
+ private readonly _dicontainer;
266
+ private readonly _middlewareGenericPath;
267
+ get genericPath(): string;
268
+ private _splitMiddlewarePath;
269
+ private readonly _inputSchemas;
270
+ private readonly _handler;
271
+ constructor(diContainer: TDIContainer, middlewarePath: string, inputSchemas: MiddlewareHandlerInputSchemas, injection: (dicontainer: TDIContainer) => TInjected, handler: MiddlewareHandlerInternal<TInjected>);
272
+ private _injection;
273
+ trigger(data: {
274
+ headers: Record<string, string>;
275
+ pathParams: Record<string, string>;
276
+ query: object;
277
+ body: object;
278
+ }, next: () => void): Promise<any>;
279
+ }
280
+ declare class MiddlewareHandlersRegistryEntry<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TDIContainer extends DIContainer, TPathParams extends string, const TPath extends MiddlewarePath<TApiDef>, TInjected> {
281
+ private readonly _registry;
282
+ private readonly _path;
283
+ constructor(registry: MiddlewareHandlersRegistry<TDIContainer>, path: TPath);
284
+ private _injection;
285
+ get injection(): any;
286
+ inject<TNewInjected>(injection: (dicontainer: TDIContainer) => TNewInjected): MiddlewareHandlersRegistryEntry<TApiDef, TDIContainer, TPathParams, TPath, TNewInjected>;
287
+ register<const InputSchemas extends MiddlewareHandlerInputSchemas>(inputSchemas: InputSchemas, handler: MiddlewareHandler<`${TPathParams}${ExtractConcatenatedParamNamesFromPath<TPath>}`, InputSchemas, TInjected>): void;
288
+ }
289
+ type OnMiddlewareHandlerRegisteredCallback<TDIContainer extends DIContainer, TInjected> = (entry: MiddlewareHandlersRegistryEntryInternal<TDIContainer, TInjected>) => void;
290
+ declare class MiddlewareHandlersRegistry<TDIContainer extends DIContainer> {
291
+ readonly dicontainer: TDIContainer;
292
+ constructor(dicontainer: TDIContainer, callback: OnMiddlewareHandlerRegisteredCallback<TDIContainer, unknown>);
293
+ register<TInjected>(entry: MiddlewareHandlersRegistryEntryInternal<TDIContainer, TInjected>): void;
294
+ private _onHandlerRegisteredCallback;
295
+ _onHandlerRegistered(callback: OnMiddlewareHandlerRegisteredCallback<TDIContainer, unknown>): void;
296
+ }
297
+
298
+ declare function flatListAllRegistryEntries<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer>(registry: ApiHandlersRegistry<TDef, TDIContainer>): MethodEndpointHandlerRegistryEntry<any, any, any, any>[];
299
+ declare function createRegistry<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer>(diContainer: TDIContainer, contract: ApiContract<TDef>, settings: IRegistrySettings<TDIContainer>): ApiHandlersRegistry<TDef, TDIContainer, "">;
300
+ type GenericOnHandlerRegisteredCallback<TDIContainer extends DIContainer> = OnHandlerRegisteredCallback<IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<IHttpMethodEndpointDefinition>, TDIContainer, string>;
301
+ interface IRegistrySettings<TDIContainer extends DIContainer> {
302
+ handlerRegisteredCallback: GenericOnHandlerRegisteredCallback<TDIContainer>;
303
+ middlewareHandlerRegisteredCallback: OnMiddlewareHandlerRegisteredCallback<TDIContainer, unknown>;
304
+ }
305
+ declare class InnerApiHandlersRegistry<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer> {
306
+ constructor(dicontainer: TDIContainer, contract: ApiContract<TDef>, settings: IRegistrySettings<TDIContainer>);
307
+ private static _initialize;
308
+ }
309
+ type ApiHandlersRegistryDef<ObjType extends object, TDIContainer extends DIContainer, TPathParams extends string> = {
310
+ [Key in keyof ObjType]: Key extends `:${infer ParamName}` ? ObjType[Key] extends HttpMethodEndpoint<infer TMethodEndpointDef> ? MethodEndpointHandlerRegistryEntry<TMethodEndpointDef, TDIContainer, `${TPathParams}:${ParamName}`> : ObjType[Key] extends object ? ApiHandlersRegistryDef<ObjType[Key], TDIContainer, `${TPathParams}:${ParamName}`> : ObjType[Key] : ObjType[Key] extends HttpMethodEndpoint<infer TMethodEndpointDef> ? MethodEndpointHandlerRegistryEntry<TMethodEndpointDef, TDIContainer, TPathParams> : ObjType[Key] extends object ? ApiHandlersRegistryDef<ObjType[Key], TDIContainer, TPathParams> : ObjType[Key];
311
+ };
312
+ type ApiHandlersRegistry<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string = ""> = Omit<ApiHandlersRegistryDef<InnerApiHandlersRegistry<TDef, TDIContainer> & TDef, TDIContainer, TPathParams>, '_middlewareRegistry'>;
313
+ declare const ApiHandlersRegistry: new <TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string = "">(dicontainer: TDIContainer, contract: ApiContract<TDef>, settings: IRegistrySettings<TDIContainer>) => ApiHandlersRegistry<TDef, TDIContainer, TPathParams>;
314
+
315
+ declare function partialPathString<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TPathParams extends string, const TPath extends PartialPath<TApiDef>>(_apiReg: ApiHandlersRegistry<TApiDef, any, TPathParams>, path: TPath): string;
316
+ type PartialPath<TDef, BasePath extends string = ""> = (BasePath extends "" ? "" : never) | {
317
+ [K in keyof TDef & string]: TDef[K] extends HttpMethodEndpoint<infer _TEndpointDef> ? never : TDef[K] extends object ? `${BasePath}/${K}` | PartialPath<TDef[K], `${BasePath}/${K}`> : never;
318
+ }[keyof TDef & string];
319
+
320
+ declare function partial<TDIContainer extends DIContainer, TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TPathParams extends string, const TPath extends PartialPath<TApiDef>>(apiReg: ApiHandlersRegistry<TApiDef, TDIContainer, TPathParams>, path: TPath): PartialPathResult<TApiDef, TPath> extends infer TPartialApi ? TPartialApi extends IApiContractDefinition & ValidateApiContractDefinition<TPartialApi> ? ApiHandlersRegistry<TPartialApi, TDIContainer, ExtractConcatenatedParamNamesFromPathSegments<TPath>> : never : never;
321
+ type PartialPathResult<TApiDef extends IApiContractDefinition, TPath extends string> = TPath extends `/${infer Rest}` ? NavigateToPartialPath<TApiDef, SplitPath$1<Rest>> : NavigateToPartialPath<TApiDef, SplitPath$1<TPath>>;
322
+ type SplitPath$1<TPath extends string> = TPath extends `${infer First}/${infer Rest}` ? [First, ...SplitPath$1<Rest>] : TPath extends "" ? [] : [TPath];
323
+ type NavigateToPartialPath<TDef, TSegments extends readonly string[]> = TSegments extends readonly [
324
+ infer First extends string,
325
+ ...infer Rest extends readonly string[]
326
+ ] ? First extends keyof TDef ? Rest extends readonly [] ? TDef[First] extends object ? TDef[First] : never : NavigateToPartialPath<TDef[First], Rest> : never : TDef;
327
+
328
+ declare function route<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TDIContainer extends DIContainer, TPathParams extends string, const TPath extends MethodFirstPath<TApiDef>>(apiReg: ApiHandlersRegistry<TApiDef, TDIContainer, TPathParams>, path: TPath): MethodEndpointHandlerRegistryEntry<ExtractEndpointFromPath<TApiDef, TPath>, TDIContainer, `${TPathParams}${ExtractConcatenatedParamNamesFromMethodFirstPath<TPath>}`, {}>;
329
+ type MethodFirstPath<TDef, BasePath extends string = ""> = {
330
+ [K in keyof TDef & string]: TDef[K] extends HttpMethodEndpoint<infer _TEndpointDef> ? `${K} ${BasePath}` : TDef[K] extends object ? MethodFirstPath<TDef[K], `${BasePath}/${K}`> : never;
331
+ }[keyof TDef & string];
332
+ type ExtractEndpointFromPath<TApiDef, TPath extends string> = TPath extends `${infer Method} ${infer Path}` ? ExtractEndpointFromPathSegments<TApiDef, Path, Method> : never;
333
+ type ExtractEndpointFromPathSegments<TDef, TPath extends string, TMethod extends string, TSegments extends readonly string[] = SplitPath<TPath>> = NavigateToEndpoint<TDef, TSegments> extends infer TEndpointContainer ? TEndpointContainer extends Record<string, any> ? TMethod extends keyof TEndpointContainer ? TEndpointContainer[TMethod] extends HttpMethodEndpoint<infer TEndpointDef> ? TEndpointDef : never : never : never : never;
334
+ type SplitPath<TPath extends string> = TPath extends `/${infer Rest}` ? SplitPathSegments<Rest> : SplitPathSegments<TPath>;
335
+ type SplitPathSegments<TPath extends string> = TPath extends `${infer First}/${infer Rest}` ? [First, ...SplitPathSegments<Rest>] : TPath extends "" ? [] : [TPath];
336
+ type NavigateToEndpoint<TDef, TSegments extends readonly string[]> = TSegments extends readonly [
337
+ infer First extends string,
338
+ ...infer Rest extends readonly string[]
339
+ ] ? First extends keyof TDef ? NavigateToEndpoint<TDef[First], Rest> : never : TDef;
340
+
341
+ declare function register<const TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TDIContainer extends DIContainer, TPathParams extends string, const TPath extends MethodFirstPath<TApiDef>>(apiReg: ApiHandlersRegistry<TApiDef, TDIContainer, TPathParams>, path: TPath, handler: HttpMethodEndpointHandler<ExtractEndpointFromPath<TApiDef, TPath>, `${TPathParams}${ExtractConcatenatedParamNamesFromMethodFirstPath<TPath>}`, {}>): void;
342
+ declare function register<const TDef extends IHttpMethodEndpointDefinition & ValidateHttpMethodEndpointDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string>(endpointEntry: MethodEndpointHandlerRegistryEntry<TDef, TDIContainer, TPathParams>, handler: HttpMethodEndpointHandler<TDef, TPathParams, {}>): void;
343
+
344
+ type InferInputProp<T extends IHttpMethodEndpointDefinition, P extends keyof T> = T[P] extends z$1.ZodType<any, any> ? Record<P, z$1.input<T[P]>> : {};
345
+ type Merge3<A, B, C> = A & B & C;
346
+ type HttpMethodCallInput<T extends IHttpMethodEndpointDefinition> = Merge3<InferInputProp<T, "headers">, InferInputProp<T, "query">, InferInputProp<T, "body">> extends infer M ? keyof M extends never ? never : M : never;
347
+ type HttpMethodCallFunc<T extends IHttpMethodEndpointDefinition> = HttpMethodCallInput<T> extends never ? () => Promise<HttpMethodEndpointHandlerOutput<T>> : (input: HttpMethodCallInput<T>) => Promise<HttpMethodEndpointHandlerOutput<T>>;
348
+
349
+ declare function createClient<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(contract: ApiContract<TDef>, clientGenericHandler: ClientHttpMethodEndpointHandler): ApiClient<TDef>;
350
+ type PathParamFunc<TDef> = (value: string | number) => TDef;
351
+ interface IClientContext {
352
+ pathParameters: Record<string, string>;
353
+ }
354
+ declare class InnerApiClient<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
355
+ constructor(contract: ApiContract<TDef>, clientGenericHandler: ClientHttpMethodEndpointHandler);
356
+ private static _initNewContext;
357
+ private static _initialize;
358
+ }
359
+ type ApiClientDef<ObjType extends object> = {
360
+ [Key in keyof ObjType as Key extends `:${infer Param}` ? Param : Key]: Key extends `:${string}` ? ObjType[Key] extends object ? PathParamFunc<ApiClientDef<ObjType[Key]>> : never : ObjType[Key] extends HttpMethodEndpoint<infer TMethodEndpointDef> ? HttpMethodCallFunc<TMethodEndpointDef> : ObjType[Key] extends object ? ApiClientDef<ObjType[Key]> : ObjType[Key];
361
+ };
362
+ type ApiClient<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> = Omit<ApiClientDef<InnerApiClient<TDef> & TDef>, "__CONTEXT__">;
363
+ declare const ApiClient: new <TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(contract: ApiContract<TDef>, clientGenericHandler: ClientHttpMethodEndpointHandler) => ApiClient<TDef>;
364
+
365
+ declare function createInProcApiClient<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer>(contract: ApiContract<TDef>, testContainer: TDIContainer, registry: ApiHandlersRegistry<TDef, TDIContainer>): ApiClient<TDef>;
366
+
367
+ export { ApiClient, type ApiClientDef, ApiContract, ApiHandlersRegistry, type ApiHandlersRegistryDef, type ClientHttpMethodEndpointHandler, type ClientHttpMethodEndpointHandlerInput, type ClientHttpMethodEndpointHandlerOutput, type DIClass, DIContainer, type DILifetime, type DIScope, type ExtractConcatenatedParamNamesFromMethodFirstPath, type ExtractConcatenatedParamNamesFromPath, type ExtractConcatenatedParamNamesFromPathSegments, type ExtractEndpointFromPath, type GenericOnHandlerRegisteredCallback, type HttpMethod, type HttpMethodCallFunc, type HttpMethodCallInput, HttpMethodEndpoint, type HttpMethodEndpointHandler, type HttpMethodEndpointHandlerInput, type HttpMethodEndpointHandlerOutput, HttpMethodEndpointResponse, type HttpMethodEndpointResponses, type HttpResponseObject, HttpStatusCode, type IApiContractDefinition, type IClientContext, type IHttpMethodEndpointDefinition, type IHttpMethodEndpointResponseDefinition, type IRegistrySettings, type LowerCasedHttpMethod, MethodEndpointHandlerRegistryEntry, type MethodFirstPath, type MiddlewareHandler, type MiddlewareHandlerInput, type MiddlewareHandlerInputInternal, type MiddlewareHandlerInputSchemas, type MiddlewareHandlerInternal, MiddlewareHandlersRegistry, MiddlewareHandlersRegistryEntry, MiddlewareHandlersRegistryEntryInternal, type MiddlewarePath, type OnHandlerRegisteredCallback, type OnMiddlewareHandlerRegisteredCallback, type PartialPath, type PartialPathResult, type PathParamFunc, type PrepareRegistryEntryCallback, type TypedPathParams, type ValidateApiContractDefinition, type ValidateHttpMethodEndpointDefinition, apiContract, createClient, createInProcApiClient, createRegistry, endpoint, flatListAllRegistryEntries, isHttpResponseObject, isHttpStatusCode, middleware, partial, partialPathString, register, response, route };