@congruent-stack/congruent-api 0.11.4 → 0.12.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.cjs CHANGED
@@ -73,6 +73,9 @@ class ApiContract {
73
73
  cloneInitDef() {
74
74
  return ApiContract._deepCloneInitDef(this.definition, []);
75
75
  }
76
+ createRegistry() {
77
+ throw new Error("Not adapted yet");
78
+ }
76
79
  static _deepCloneInitDef(definition, path) {
77
80
  const result = {};
78
81
  for (const key in definition) {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,28 @@
1
1
  import z, { z as z$1 } from 'zod';
2
2
 
3
+ type StringLiteral<T extends string> = string extends T ? never : T;
4
+ type CapitalizedStringLiteral<T extends string> = string extends T ? never : T extends `${Uppercase<infer F>}${infer _}` ? F extends Lowercase<F> ? never : T : `❌ ERROR: Must start with uppercase letter`;
5
+ type DILifetime = 'singleton' | 'transient' | 'scoped';
6
+ type DIRegistryEntry<T> = {
7
+ factory: (scope: any) => T;
8
+ lifetime: DILifetime;
9
+ };
10
+ type DIRegistry = Record<string, DIRegistryEntry<any>>;
11
+ type DIScope<R extends DIRegistry> = {
12
+ [K in keyof R as `get${string & K}`]: () => R[K] extends DIRegistryEntry<infer T> ? T : never;
13
+ };
14
+ declare class DIContainerBase<R extends DIRegistry> {
15
+ createScope(): DIScope<R>;
16
+ }
17
+ declare class DIContainer<R extends DIRegistry = {}> extends DIContainerBase<R> {
18
+ register<K extends string, T>(serviceNameCapitalizedLiteral: CapitalizedStringLiteral<K>, factory: (scope: DIScope<R>) => T, lifetime: DILifetime): DIContainer<R & Record<K, DIRegistryEntry<T>>>;
19
+ createTestClone(): DIContainerTestClone<R, this>;
20
+ }
21
+ declare class DIContainerTestClone<R extends DIRegistry, TDIContainer extends DIContainer<R>> extends DIContainerBase<R> {
22
+ constructor(original: TDIContainer);
23
+ override<K extends keyof R & string>(serviceNameLiteral: K, factory: (scope: DIScope<R>) => R[K] extends DIRegistryEntry<infer T> ? T : never): this;
24
+ }
25
+
3
26
  declare enum HttpStatusCode {
4
27
  Continue_100 = 100,
5
28
  SwitchingProtocols_101 = 101,
@@ -64,20 +87,6 @@ declare class HttpMethodEndpoint<const TDef extends IHttpMethodEndpointDefinitio
64
87
  constructor(definition: TDef);
65
88
  }
66
89
 
67
- declare function apiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(definition: TDef): ApiContract<TDef>;
68
- interface IApiContractDefinition {
69
- readonly [key: string]: IApiContractDefinition | HttpMethodEndpoint<any>;
70
- }
71
- type ValidateApiContractDefinition<T> = {
72
- [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];
73
- };
74
- declare class ApiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
75
- readonly definition: TDef;
76
- constructor(definition: TDef);
77
- cloneInitDef(): TDef;
78
- private static _deepCloneInitDef;
79
- }
80
-
81
90
  /**
82
91
  * Extracts typed path parameters from a path string.
83
92
  * For example, given a path string like ":p1:p2:...:pn", it will return an object type with properties for each parameter.
@@ -131,6 +140,11 @@ type HttpRequestObject = {
131
140
  body: object;
132
141
  };
133
142
 
143
+ interface ICanTriggerAsync {
144
+ triggerNoStaticTypeCheck(diScope: DIScope<any>, requestObject: HttpRequestObject, context: any): Promise<any>;
145
+ get genericPath(): string;
146
+ }
147
+
134
148
  type HttpMethodEndpointHandlerOutput<TEndpointDefinition extends IHttpMethodEndpointDefinition> = {
135
149
  [THttpStatusCode in keyof TEndpointDefinition['responses'] & HttpStatusCode]: TEndpointDefinition['responses'][THttpStatusCode] extends HttpMethodEndpointResponse<THttpStatusCode, infer TRespDef> ? CreateHandlerOutput<THttpStatusCode, TRespDef> : never;
136
150
  }[keyof TEndpointDefinition['responses'] & HttpStatusCode];
@@ -200,34 +214,6 @@ type DecoratorHandlerContext = {
200
214
  type HttpMethodEndpointHandler<TDef extends IHttpMethodEndpointDefinition, TPathParams extends string, TInjected> = (input: HttpMethodEndpointHandlerInput<TDef, TPathParams>, context: EndpointHandlerContext<TInjected>) => Promise<HttpMethodEndpointHandlerOutput<TDef>>;
201
215
  type ClientHttpMethodEndpointHandler = (input: ClientHttpMethodEndpointHandlerInput) => Promise<ClientHttpMethodEndpointHandlerOutput>;
202
216
 
203
- type StringLiteral<T extends string> = string extends T ? never : T;
204
- type CapitalizedStringLiteral<T extends string> = string extends T ? never : T extends `${Uppercase<infer F>}${infer _}` ? F extends Lowercase<F> ? never : T : `❌ ERROR: Must start with uppercase letter`;
205
- type DILifetime = 'singleton' | 'transient' | 'scoped';
206
- type DIRegistryEntry<T> = {
207
- factory: (scope: any) => T;
208
- lifetime: DILifetime;
209
- };
210
- type DIRegistry = Record<string, DIRegistryEntry<any>>;
211
- type DIScope<R extends DIRegistry> = {
212
- [K in keyof R as `get${string & K}`]: () => R[K] extends DIRegistryEntry<infer T> ? T : never;
213
- };
214
- declare class DIContainerBase<R extends DIRegistry> {
215
- createScope(): DIScope<R>;
216
- }
217
- declare class DIContainer<R extends DIRegistry = {}> extends DIContainerBase<R> {
218
- register<K extends string, T>(serviceNameCapitalizedLiteral: CapitalizedStringLiteral<K>, factory: (scope: DIScope<R>) => T, lifetime: DILifetime): DIContainer<R & Record<K, DIRegistryEntry<T>>>;
219
- createTestClone(): DIContainerTestClone<R, this>;
220
- }
221
- declare class DIContainerTestClone<R extends DIRegistry, TDIContainer extends DIContainer<R>> extends DIContainerBase<R> {
222
- constructor(original: TDIContainer);
223
- override<K extends keyof R & string>(serviceNameLiteral: K, factory: (scope: DIScope<R>) => R[K] extends DIRegistryEntry<infer T> ? T : never): this;
224
- }
225
-
226
- interface ICanTriggerAsync {
227
- triggerNoStaticTypeCheck(diScope: DIScope<any>, requestObject: HttpRequestObject, context: any): Promise<any>;
228
- get genericPath(): string;
229
- }
230
-
231
217
  type MiddlewareHandlerSchemas = {
232
218
  headers?: z$1.ZodType;
233
219
  query?: z$1.ZodType;
@@ -452,6 +438,21 @@ type ApiHandlersRegistryDef<ObjType extends object, TDIContainer extends DIConta
452
438
  type ApiHandlersRegistry<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string = ""> = Omit<ApiHandlersRegistryDef<InnerApiHandlersRegistry<TDef, TDIContainer> & TDef, TDIContainer, TPathParams>, '_middlewareRegistry'>;
453
439
  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>;
454
440
 
441
+ declare function apiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(definition: TDef): ApiContract<TDef>;
442
+ interface IApiContractDefinition {
443
+ readonly [key: string]: IApiContractDefinition | HttpMethodEndpoint<any>;
444
+ }
445
+ type ValidateApiContractDefinition<T> = {
446
+ [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];
447
+ };
448
+ declare class ApiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
449
+ readonly definition: TDef;
450
+ constructor(definition: TDef);
451
+ cloneInitDef(): TDef;
452
+ createRegistry<TDIContainer extends DIContainer>(): ApiHandlersRegistry<TDef, TDIContainer>;
453
+ private static _deepCloneInitDef;
454
+ }
455
+
455
456
  declare function partialPathString<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TPathParams extends string, const TPath extends PartialPath<TApiDef>>(_apiReg: ApiHandlersRegistry<TApiDef, any, TPathParams>, path: TPath): string;
456
457
  type PartialPath<TDef, BasePath extends string = ""> = (BasePath extends "" ? "" : never) | {
457
458
  [K in keyof TDef & string]: TDef[K] extends HttpMethodEndpoint<infer _TEndpointDef> ? never : TDef[K] extends object ? `${BasePath}/${K}` | PartialPath<TDef[K], `${BasePath}/${K}`> : never;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,28 @@
1
1
  import z, { z as z$1 } from 'zod';
2
2
 
3
+ type StringLiteral<T extends string> = string extends T ? never : T;
4
+ type CapitalizedStringLiteral<T extends string> = string extends T ? never : T extends `${Uppercase<infer F>}${infer _}` ? F extends Lowercase<F> ? never : T : `❌ ERROR: Must start with uppercase letter`;
5
+ type DILifetime = 'singleton' | 'transient' | 'scoped';
6
+ type DIRegistryEntry<T> = {
7
+ factory: (scope: any) => T;
8
+ lifetime: DILifetime;
9
+ };
10
+ type DIRegistry = Record<string, DIRegistryEntry<any>>;
11
+ type DIScope<R extends DIRegistry> = {
12
+ [K in keyof R as `get${string & K}`]: () => R[K] extends DIRegistryEntry<infer T> ? T : never;
13
+ };
14
+ declare class DIContainerBase<R extends DIRegistry> {
15
+ createScope(): DIScope<R>;
16
+ }
17
+ declare class DIContainer<R extends DIRegistry = {}> extends DIContainerBase<R> {
18
+ register<K extends string, T>(serviceNameCapitalizedLiteral: CapitalizedStringLiteral<K>, factory: (scope: DIScope<R>) => T, lifetime: DILifetime): DIContainer<R & Record<K, DIRegistryEntry<T>>>;
19
+ createTestClone(): DIContainerTestClone<R, this>;
20
+ }
21
+ declare class DIContainerTestClone<R extends DIRegistry, TDIContainer extends DIContainer<R>> extends DIContainerBase<R> {
22
+ constructor(original: TDIContainer);
23
+ override<K extends keyof R & string>(serviceNameLiteral: K, factory: (scope: DIScope<R>) => R[K] extends DIRegistryEntry<infer T> ? T : never): this;
24
+ }
25
+
3
26
  declare enum HttpStatusCode {
4
27
  Continue_100 = 100,
5
28
  SwitchingProtocols_101 = 101,
@@ -64,20 +87,6 @@ declare class HttpMethodEndpoint<const TDef extends IHttpMethodEndpointDefinitio
64
87
  constructor(definition: TDef);
65
88
  }
66
89
 
67
- declare function apiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(definition: TDef): ApiContract<TDef>;
68
- interface IApiContractDefinition {
69
- readonly [key: string]: IApiContractDefinition | HttpMethodEndpoint<any>;
70
- }
71
- type ValidateApiContractDefinition<T> = {
72
- [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];
73
- };
74
- declare class ApiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
75
- readonly definition: TDef;
76
- constructor(definition: TDef);
77
- cloneInitDef(): TDef;
78
- private static _deepCloneInitDef;
79
- }
80
-
81
90
  /**
82
91
  * Extracts typed path parameters from a path string.
83
92
  * For example, given a path string like ":p1:p2:...:pn", it will return an object type with properties for each parameter.
@@ -131,6 +140,11 @@ type HttpRequestObject = {
131
140
  body: object;
132
141
  };
133
142
 
143
+ interface ICanTriggerAsync {
144
+ triggerNoStaticTypeCheck(diScope: DIScope<any>, requestObject: HttpRequestObject, context: any): Promise<any>;
145
+ get genericPath(): string;
146
+ }
147
+
134
148
  type HttpMethodEndpointHandlerOutput<TEndpointDefinition extends IHttpMethodEndpointDefinition> = {
135
149
  [THttpStatusCode in keyof TEndpointDefinition['responses'] & HttpStatusCode]: TEndpointDefinition['responses'][THttpStatusCode] extends HttpMethodEndpointResponse<THttpStatusCode, infer TRespDef> ? CreateHandlerOutput<THttpStatusCode, TRespDef> : never;
136
150
  }[keyof TEndpointDefinition['responses'] & HttpStatusCode];
@@ -200,34 +214,6 @@ type DecoratorHandlerContext = {
200
214
  type HttpMethodEndpointHandler<TDef extends IHttpMethodEndpointDefinition, TPathParams extends string, TInjected> = (input: HttpMethodEndpointHandlerInput<TDef, TPathParams>, context: EndpointHandlerContext<TInjected>) => Promise<HttpMethodEndpointHandlerOutput<TDef>>;
201
215
  type ClientHttpMethodEndpointHandler = (input: ClientHttpMethodEndpointHandlerInput) => Promise<ClientHttpMethodEndpointHandlerOutput>;
202
216
 
203
- type StringLiteral<T extends string> = string extends T ? never : T;
204
- type CapitalizedStringLiteral<T extends string> = string extends T ? never : T extends `${Uppercase<infer F>}${infer _}` ? F extends Lowercase<F> ? never : T : `❌ ERROR: Must start with uppercase letter`;
205
- type DILifetime = 'singleton' | 'transient' | 'scoped';
206
- type DIRegistryEntry<T> = {
207
- factory: (scope: any) => T;
208
- lifetime: DILifetime;
209
- };
210
- type DIRegistry = Record<string, DIRegistryEntry<any>>;
211
- type DIScope<R extends DIRegistry> = {
212
- [K in keyof R as `get${string & K}`]: () => R[K] extends DIRegistryEntry<infer T> ? T : never;
213
- };
214
- declare class DIContainerBase<R extends DIRegistry> {
215
- createScope(): DIScope<R>;
216
- }
217
- declare class DIContainer<R extends DIRegistry = {}> extends DIContainerBase<R> {
218
- register<K extends string, T>(serviceNameCapitalizedLiteral: CapitalizedStringLiteral<K>, factory: (scope: DIScope<R>) => T, lifetime: DILifetime): DIContainer<R & Record<K, DIRegistryEntry<T>>>;
219
- createTestClone(): DIContainerTestClone<R, this>;
220
- }
221
- declare class DIContainerTestClone<R extends DIRegistry, TDIContainer extends DIContainer<R>> extends DIContainerBase<R> {
222
- constructor(original: TDIContainer);
223
- override<K extends keyof R & string>(serviceNameLiteral: K, factory: (scope: DIScope<R>) => R[K] extends DIRegistryEntry<infer T> ? T : never): this;
224
- }
225
-
226
- interface ICanTriggerAsync {
227
- triggerNoStaticTypeCheck(diScope: DIScope<any>, requestObject: HttpRequestObject, context: any): Promise<any>;
228
- get genericPath(): string;
229
- }
230
-
231
217
  type MiddlewareHandlerSchemas = {
232
218
  headers?: z$1.ZodType;
233
219
  query?: z$1.ZodType;
@@ -452,6 +438,21 @@ type ApiHandlersRegistryDef<ObjType extends object, TDIContainer extends DIConta
452
438
  type ApiHandlersRegistry<TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>, TDIContainer extends DIContainer, TPathParams extends string = ""> = Omit<ApiHandlersRegistryDef<InnerApiHandlersRegistry<TDef, TDIContainer> & TDef, TDIContainer, TPathParams>, '_middlewareRegistry'>;
453
439
  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>;
454
440
 
441
+ declare function apiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>>(definition: TDef): ApiContract<TDef>;
442
+ interface IApiContractDefinition {
443
+ readonly [key: string]: IApiContractDefinition | HttpMethodEndpoint<any>;
444
+ }
445
+ type ValidateApiContractDefinition<T> = {
446
+ [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];
447
+ };
448
+ declare class ApiContract<const TDef extends IApiContractDefinition & ValidateApiContractDefinition<TDef>> {
449
+ readonly definition: TDef;
450
+ constructor(definition: TDef);
451
+ cloneInitDef(): TDef;
452
+ createRegistry<TDIContainer extends DIContainer>(): ApiHandlersRegistry<TDef, TDIContainer>;
453
+ private static _deepCloneInitDef;
454
+ }
455
+
455
456
  declare function partialPathString<TApiDef extends IApiContractDefinition & ValidateApiContractDefinition<TApiDef>, TPathParams extends string, const TPath extends PartialPath<TApiDef>>(_apiReg: ApiHandlersRegistry<TApiDef, any, TPathParams>, path: TPath): string;
456
457
  type PartialPath<TDef, BasePath extends string = ""> = (BasePath extends "" ? "" : never) | {
457
458
  [K in keyof TDef & string]: TDef[K] extends HttpMethodEndpoint<infer _TEndpointDef> ? never : TDef[K] extends object ? `${BasePath}/${K}` | PartialPath<TDef[K], `${BasePath}/${K}`> : never;
package/dist/index.mjs CHANGED
@@ -71,6 +71,9 @@ class ApiContract {
71
71
  cloneInitDef() {
72
72
  return ApiContract._deepCloneInitDef(this.definition, []);
73
73
  }
74
+ createRegistry() {
75
+ throw new Error("Not adapted yet");
76
+ }
74
77
  static _deepCloneInitDef(definition, path) {
75
78
  const result = {};
76
79
  for (const key in definition) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@congruent-stack/congruent-api",
3
3
  "type": "module",
4
- "version": "0.11.4",
4
+ "version": "0.12.0",
5
5
  "description": "Typescript schema-first tooling for agnostic REST APIs.",
6
6
  "keywords": [],
7
7
  "author": "congruent-stack",