@veloxts/client 0.6.79 → 0.6.81

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @veloxts/client
2
2
 
3
+ ## 0.6.81
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(client): update ProcedureCollection type inference for two-parameter interface
8
+
9
+ ## 0.6.80
10
+
11
+ ### Patch Changes
12
+
13
+ - fix(router,client): preserve procedure type literals for query/mutation discrimination + lint fixes
14
+
3
15
  ## 0.6.79
4
16
 
5
17
  ### Patch Changes
@@ -323,15 +323,14 @@ export interface VeloxMutationOptions<TOutput, TInput, TContext = unknown> exten
323
323
  * Resolves a procedure to its appropriate hook interface
324
324
  * based on whether it's a query or mutation
325
325
  *
326
- * Note: The type check uses 'mutation' first because CompiledProcedure's `type`
327
- * property may be widened to 'query' | 'mutation' union. We check mutation
328
- * explicitly and default to query for everything else.
326
+ * With the TType generic parameter preserved through the procedure builder chain,
327
+ * we can now properly discriminate between query and mutation types.
328
+ * The ClientProcedure<TInput, TOutput, TType> captures the literal 'query' or 'mutation'
329
+ * type, enabling accurate type resolution.
329
330
  *
330
331
  * @internal
331
332
  */
332
- type VeloxProcedureHooks<TProcedure> = TProcedure extends ClientProcedure<infer TInput, infer TOutput> ? TProcedure extends {
333
- readonly type: 'mutation';
334
- } ? VeloxMutationProcedure<TInput, TOutput> : VeloxQueryProcedure<TInput, TOutput> : never;
333
+ type VeloxProcedureHooks<TProcedure> = TProcedure extends ClientProcedure<infer TInput, infer TOutput, infer TType> ? TType extends 'mutation' ? VeloxMutationProcedure<TInput, TOutput> : TType extends 'query' ? VeloxQueryProcedure<TInput, TOutput> : VeloxQueryProcedure<TInput, TOutput> : never;
335
334
  /**
336
335
  * Maps a procedures record to hook interfaces
337
336
  *
@@ -17,13 +17,13 @@ import type { ClientConfig, ClientFromRouter, InferProcedureInput, InferProcedur
17
17
  * @template TNamespace - The namespace key (e.g., 'users', 'posts')
18
18
  * @template TProcedureName - The procedure name (e.g., 'getUser', 'listUsers')
19
19
  */
20
- export type GetProcedure<TRouter, TNamespace extends keyof TRouter, TProcedureName extends keyof GetProceduresFromCollection<TRouter[TNamespace]>> = TRouter[TNamespace] extends ProcedureCollection<infer TProcedures> ? TProcedureName extends keyof TProcedures ? TProcedures[TProcedureName] : never : never;
20
+ export type GetProcedure<TRouter, TNamespace extends keyof TRouter, TProcedureName extends keyof GetProceduresFromCollection<TRouter[TNamespace]>> = TRouter[TNamespace] extends ProcedureCollection<infer _TN, infer TProcedures> ? TProcedureName extends keyof TProcedures ? TProcedures[TProcedureName] : never : never;
21
21
  /**
22
22
  * Extracts the procedures record from a collection
23
23
  *
24
24
  * @template TCollection - The procedure collection type
25
25
  */
26
- export type GetProceduresFromCollection<TCollection> = TCollection extends ProcedureCollection ? TCollection['procedures'] : never;
26
+ export type GetProceduresFromCollection<TCollection> = TCollection extends ProcedureCollection<string, infer TProcedures> ? TProcedures : never;
27
27
  /**
28
28
  * Options for useQuery hook
29
29
  *
package/dist/types.d.ts CHANGED
@@ -19,12 +19,13 @@ export type ProcedureType = 'query' | 'mutation';
19
19
  *
20
20
  * @template TInput - The validated input type
21
21
  * @template TOutput - The handler output type
22
+ * @template TType - The procedure type literal ('query' or 'mutation')
22
23
  *
23
24
  * @see {@link https://github.com/veloxts/velox-ts-framework/velox | @veloxts/router CompiledProcedure}
24
25
  */
25
- export interface ClientProcedure<TInput = unknown, TOutput = unknown> {
26
+ export interface ClientProcedure<TInput = unknown, TOutput = unknown, TType extends ProcedureType = ProcedureType> {
26
27
  /** Whether this is a query or mutation */
27
- readonly type: ProcedureType;
28
+ readonly type: TType;
28
29
  /** The procedure handler function - uses `any` for ctx to enable contravariant matching with CompiledProcedure */
29
30
  readonly handler: (args: {
30
31
  input: TInput;
@@ -58,7 +59,7 @@ export interface ClientProcedure<TInput = unknown, TOutput = unknown> {
58
59
  *
59
60
  * NOTE: Uses `any` for variance compatibility with @veloxts/router's ProcedureRecord
60
61
  */
61
- export type ProcedureRecord = Record<string, ClientProcedure<any, any>>;
62
+ export type ProcedureRecord = Record<string, ClientProcedure<any, any, any>>;
62
63
  /**
63
64
  * Procedure collection with namespace
64
65
  *
@@ -80,13 +81,19 @@ export interface ProcedureCollection<TNamespace extends string = string, TProced
80
81
  *
81
82
  * Works with both ClientProcedure and @veloxts/router's CompiledProcedure
82
83
  */
83
- export type InferProcedureInput<T> = T extends ClientProcedure<infer I, unknown> ? I : never;
84
+ export type InferProcedureInput<T> = T extends ClientProcedure<infer I, unknown, ProcedureType> ? I : never;
84
85
  /**
85
86
  * Extracts the output type from a procedure
86
87
  *
87
88
  * Works with both ClientProcedure and @veloxts/router's CompiledProcedure
88
89
  */
89
- export type InferProcedureOutput<T> = T extends ClientProcedure<unknown, infer O> ? O : never;
90
+ export type InferProcedureOutput<T> = T extends ClientProcedure<unknown, infer O, ProcedureType> ? O : never;
91
+ /**
92
+ * Extracts the type (query/mutation) from a procedure
93
+ *
94
+ * Works with both ClientProcedure and @veloxts/router's CompiledProcedure
95
+ */
96
+ export type InferProcedureType<T> = T extends ClientProcedure<unknown, unknown, infer TType> ? TType : never;
90
97
  /**
91
98
  * Builds a callable client interface from a single procedure collection
92
99
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/client",
3
- "version": "0.6.79",
3
+ "version": "0.6.81",
4
4
  "description": "Type-safe frontend API client for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",