ts-procedures 3.0.1 → 3.1.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.
@@ -11,7 +11,8 @@ export type FactoryItem<C> = {
11
11
  factoryContext: (req: Request) => C
12
12
  }
13
13
 
14
- export interface RPCHttpRouteDoc {
14
+ export interface RPCHttpRouteDoc extends RPCConfig {
15
+ name: string // procedure name
15
16
  path: string
16
17
  method: 'post'
17
18
  jsonSchema: {
@@ -19,3 +20,40 @@ export interface RPCHttpRouteDoc {
19
20
  response?: object
20
21
  }
21
22
  }
23
+
24
+ // ================
25
+ // Utility types
26
+ // ================
27
+
28
+ /**
29
+ * Extracts the TContext type from a Procedures factory return type.
30
+ * Uses the first parameter of the handler function to infer the context type.
31
+ */
32
+ export type ExtractContext<TFactory> = TFactory extends {
33
+ getProcedures: () => Array<{ handler: (ctx: infer TContext, ...args: any[]) => any }>
34
+ }
35
+ ? TContext
36
+ : never
37
+
38
+ /**
39
+ * Extracts the TConfig type from a Procedures factory return type.
40
+ * Uses the config property of the procedure registration to infer the config type.
41
+ */
42
+ export type ExtractConfig<TFactory> = TFactory extends {
43
+ getProcedures: () => Array<{ config: infer TConfig }>
44
+ }
45
+ ? TConfig
46
+ : never
47
+
48
+ /**
49
+ * Minimal structural type for a Procedures factory.
50
+ * Uses explicit `any` types to avoid variance issues with generic constraints.
51
+ */
52
+ export type ProceduresFactory = {
53
+ getProcedures: () => Array<{
54
+ name: string
55
+ config: any
56
+ handler: (ctx: any, params?: any) => Promise<any>
57
+ }>
58
+ Create: (...args: any[]) => any
59
+ }