@veloxts/client 0.6.102 → 0.6.104
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 +12 -0
- package/dist/client.js +12 -12
- package/dist/react/proxy-types.d.ts +30 -6
- package/dist/types.d.ts +14 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @veloxts/client
|
|
2
2
|
|
|
3
|
+
## 0.6.104
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat(client): smart convention-based route inference, eliminate routes.ts
|
|
8
|
+
|
|
9
|
+
## 0.6.103
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- chore(deps): upgrade Zod from v3 to v4
|
|
14
|
+
|
|
3
15
|
## 0.6.102
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/client.js
CHANGED
|
@@ -98,29 +98,29 @@ function resolveRouteOverride(override, procedureName) {
|
|
|
98
98
|
* @internal
|
|
99
99
|
*/
|
|
100
100
|
function buildRestPath(namespace, procedureName, routes) {
|
|
101
|
-
// Check for explicit route
|
|
101
|
+
// 1. Check for explicit route override first
|
|
102
102
|
const override = routes?.[namespace]?.[procedureName];
|
|
103
103
|
if (override) {
|
|
104
104
|
const resolved = resolveRouteOverride(override, procedureName);
|
|
105
105
|
return resolved.path;
|
|
106
106
|
}
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
// 2. Convention inference — collection endpoints (no :id)
|
|
108
|
+
if (procedureName.startsWith('list') ||
|
|
109
|
+
procedureName.startsWith('find') ||
|
|
110
|
+
procedureName.startsWith('create') ||
|
|
111
|
+
procedureName.startsWith('add')) {
|
|
111
112
|
return `/${namespace}`;
|
|
112
113
|
}
|
|
113
|
-
//
|
|
114
|
+
// 3. Convention inference — single-resource endpoints (with :id)
|
|
114
115
|
if (procedureName.startsWith('get') ||
|
|
115
116
|
procedureName.startsWith('update') ||
|
|
116
|
-
procedureName.startsWith('
|
|
117
|
+
procedureName.startsWith('edit') ||
|
|
118
|
+
procedureName.startsWith('patch') ||
|
|
119
|
+
procedureName.startsWith('delete') ||
|
|
120
|
+
procedureName.startsWith('remove')) {
|
|
117
121
|
return `/${namespace}/:id`;
|
|
118
122
|
}
|
|
119
|
-
//
|
|
120
|
-
if (method === 'POST') {
|
|
121
|
-
return `/${namespace}`;
|
|
122
|
-
}
|
|
123
|
-
// Default: /namespace
|
|
123
|
+
// 4. Fallback: /{namespace}
|
|
124
124
|
return `/${namespace}`;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module @veloxts/client/react/proxy-types
|
|
8
8
|
*/
|
|
9
9
|
import type { QueryClient, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
10
|
-
import type { ClientFromRouter,
|
|
10
|
+
import type { ClientFromRouter, ProcedureCollection, ProcedureRecord, RouteMap } from '../types.js';
|
|
11
11
|
import type { VeloxQueryKey } from './types.js';
|
|
12
12
|
/**
|
|
13
13
|
* Hook methods available for query procedures
|
|
@@ -319,18 +319,42 @@ export interface VeloxMutationOptions<TOutput, TInput, TContext = unknown> exten
|
|
|
319
319
|
*/
|
|
320
320
|
autoInvalidate?: boolean | AutoInvalidationConfig;
|
|
321
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Extracts the input type from a procedure's inputSchema.parse return type
|
|
324
|
+
* Falls back to `void` when no input schema is defined (allows omitting the argument).
|
|
325
|
+
* @internal
|
|
326
|
+
*/
|
|
327
|
+
type ExtractInput<T> = T extends {
|
|
328
|
+
readonly inputSchema: {
|
|
329
|
+
parse: (x: unknown) => infer I;
|
|
330
|
+
};
|
|
331
|
+
} ? I : undefined;
|
|
332
|
+
/**
|
|
333
|
+
* Extracts the output type from a procedure's outputSchema.parse return type
|
|
334
|
+
* Falls back to the handler's return type when no output schema is defined.
|
|
335
|
+
* @internal
|
|
336
|
+
*/
|
|
337
|
+
type ExtractOutput<T> = T extends {
|
|
338
|
+
readonly outputSchema: {
|
|
339
|
+
parse: (x: unknown) => infer O;
|
|
340
|
+
};
|
|
341
|
+
} ? O : T extends {
|
|
342
|
+
readonly handler: (...args: never[]) => infer R;
|
|
343
|
+
} ? Awaited<R> : unknown;
|
|
322
344
|
/**
|
|
323
345
|
* Resolves a procedure to its appropriate hook interface
|
|
324
346
|
* based on whether it's a query or mutation
|
|
325
347
|
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
348
|
+
* Uses direct property access to extract types from the procedure,
|
|
349
|
+
* which is more reliable than structural inference via
|
|
350
|
+
* `extends ClientProcedure<infer I, infer O, infer T>` when working
|
|
351
|
+
* with complex types like CompiledProcedure that have many fields.
|
|
330
352
|
*
|
|
331
353
|
* @internal
|
|
332
354
|
*/
|
|
333
|
-
type VeloxProcedureHooks<TProcedure> = TProcedure extends
|
|
355
|
+
type VeloxProcedureHooks<TProcedure> = TProcedure extends {
|
|
356
|
+
readonly type: infer TType;
|
|
357
|
+
} ? TType extends 'mutation' ? VeloxMutationProcedure<ExtractInput<TProcedure>, ExtractOutput<TProcedure>> : VeloxQueryProcedure<ExtractInput<TProcedure>, ExtractOutput<TProcedure>> : never;
|
|
334
358
|
/**
|
|
335
359
|
* Maps a procedures record to hook interfaces
|
|
336
360
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -79,15 +79,25 @@ export interface ProcedureCollection<TNamespace extends string = string, TProced
|
|
|
79
79
|
/**
|
|
80
80
|
* Extracts the input type from a procedure
|
|
81
81
|
*
|
|
82
|
-
*
|
|
82
|
+
* Uses direct property access on inputSchema for reliable inference
|
|
83
|
+
* with both ClientProcedure and @veloxts/router's CompiledProcedure.
|
|
83
84
|
*/
|
|
84
|
-
export type InferProcedureInput<T> = T extends
|
|
85
|
+
export type InferProcedureInput<T> = T extends {
|
|
86
|
+
readonly inputSchema: {
|
|
87
|
+
parse: (x: unknown) => infer I;
|
|
88
|
+
};
|
|
89
|
+
} ? I : undefined;
|
|
85
90
|
/**
|
|
86
91
|
* Extracts the output type from a procedure
|
|
87
92
|
*
|
|
88
|
-
*
|
|
93
|
+
* Uses direct property access on outputSchema for reliable inference
|
|
94
|
+
* with both ClientProcedure and @veloxts/router's CompiledProcedure.
|
|
89
95
|
*/
|
|
90
|
-
export type InferProcedureOutput<T> = T extends
|
|
96
|
+
export type InferProcedureOutput<T> = T extends {
|
|
97
|
+
readonly outputSchema: {
|
|
98
|
+
parse: (x: unknown) => infer O;
|
|
99
|
+
};
|
|
100
|
+
} ? O : unknown;
|
|
91
101
|
/**
|
|
92
102
|
* Extracts the type (query/mutation) from a procedure
|
|
93
103
|
*
|