@veloxts/client 0.6.78 → 0.6.80

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.80
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(router,client): preserve procedure type literals for query/mutation discrimination + lint fixes
8
+
9
+ ## 0.6.79
10
+
11
+ ### Patch Changes
12
+
13
+ - fix(router,client): preserve namespace literal types for proper type narrowing
14
+
3
15
  ## 0.6.78
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
  *
@@ -363,7 +362,7 @@ export type VeloxNamespace<TProcedures extends ProcedureRecord> = {
363
362
  * ```
364
363
  */
365
364
  export type VeloxHooks<TRouter> = {
366
- [K in keyof TRouter]: TRouter[K] extends ProcedureCollection<infer TProcedures> ? VeloxNamespace<TProcedures> : never;
365
+ [K in keyof TRouter]: TRouter[K] extends ProcedureCollection<infer _TNamespace, infer TProcedures> ? VeloxNamespace<TProcedures> : never;
367
366
  };
368
367
  /**
369
368
  * Configuration for createVeloxHooks
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,15 +59,20 @@ 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
  *
65
- * Matches the structure of @veloxts/router's ProcedureCollection
66
+ * Matches the structure of @veloxts/router's ProcedureCollection.
67
+ * The TNamespace parameter captures the literal namespace string for proper
68
+ * type narrowing in router types.
69
+ *
70
+ * @template TNamespace - The literal namespace string (e.g., 'users', 'posts')
71
+ * @template TProcedures - The record of named procedures
66
72
  */
67
- export interface ProcedureCollection<TProcedures extends ProcedureRecord = ProcedureRecord> {
73
+ export interface ProcedureCollection<TNamespace extends string = string, TProcedures extends ProcedureRecord = ProcedureRecord> {
68
74
  /** Resource namespace (e.g., 'users', 'posts') */
69
- readonly namespace: string;
75
+ readonly namespace: TNamespace;
70
76
  /** Named procedures in this collection */
71
77
  readonly procedures: TProcedures;
72
78
  }
@@ -75,13 +81,19 @@ export interface ProcedureCollection<TProcedures extends ProcedureRecord = Proce
75
81
  *
76
82
  * Works with both ClientProcedure and @veloxts/router's CompiledProcedure
77
83
  */
78
- 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;
79
85
  /**
80
86
  * Extracts the output type from a procedure
81
87
  *
82
88
  * Works with both ClientProcedure and @veloxts/router's CompiledProcedure
83
89
  */
84
- 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;
85
97
  /**
86
98
  * Builds a callable client interface from a single procedure collection
87
99
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/client",
3
- "version": "0.6.78",
3
+ "version": "0.6.80",
4
4
  "description": "Type-safe frontend API client for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",