@veloxts/client 0.7.1 → 0.7.3

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.7.3
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(cli): auto-populate Zod schemas from Prisma model fields
8
+
9
+ ## 0.7.2
10
+
11
+ ### Patch Changes
12
+
13
+ - simplify code for clarity and maintainability
14
+
3
15
  ## 0.7.1
4
16
 
5
17
  ### Patch Changes
package/dist/client.js CHANGED
@@ -61,11 +61,11 @@ function inferMethodFromName(procedureName) {
61
61
  * @internal
62
62
  */
63
63
  function isRouteEntry(value) {
64
- return (typeof value === 'object' &&
65
- value !== null &&
66
- 'method' in value &&
67
- 'path' in value &&
68
- typeof value.path === 'string');
64
+ if (typeof value !== 'object' || value === null) {
65
+ return false;
66
+ }
67
+ const obj = value;
68
+ return 'method' in obj && typeof obj.path === 'string';
69
69
  }
70
70
  /**
71
71
  * Resolves a route mapping to method and path
@@ -84,43 +84,39 @@ function resolveRouteOverride(override, procedureName) {
84
84
  return { method: inferMethodFromName(procedureName), path: override };
85
85
  }
86
86
  /**
87
- * Builds REST path from namespace and procedure name
87
+ * Prefixes that map to collection endpoints (no :id)
88
+ * @internal
89
+ */
90
+ const COLLECTION_PREFIXES = ['list', 'find', 'create', 'add'];
91
+ /**
92
+ * Prefixes that map to single-resource endpoints (with :id)
93
+ * @internal
94
+ */
95
+ const SINGLE_RESOURCE_PREFIXES = ['get', 'update', 'edit', 'patch', 'delete', 'remove'];
96
+ /**
97
+ * Infers REST path from namespace and procedure name using naming conventions
88
98
  *
89
- * First checks for explicit route mapping, then falls back to
90
- * naming convention inference.
99
+ * This function only handles convention-based inference. Route overrides
100
+ * are resolved by the caller (resolveMethodAndPath).
91
101
  *
92
102
  * @example
93
103
  * - namespace='users', name='getUser' -> '/users/:id'
94
104
  * - namespace='users', name='listUsers' -> '/users'
95
105
  * - namespace='posts', name='createPost' -> '/posts'
96
- * - namespace='auth', name='createAccount', routes={auth:{createAccount:{method:'POST',path:'/auth/register'}}} -> '/auth/register'
97
106
  *
98
107
  * @internal
99
108
  */
100
- function buildRestPath(namespace, procedureName, routes) {
101
- // 1. Check for explicit route override first
102
- const override = routes?.[namespace]?.[procedureName];
103
- if (override) {
104
- const resolved = resolveRouteOverride(override, procedureName);
105
- return resolved.path;
106
- }
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')) {
112
- return `/${namespace}`;
109
+ function inferRestPath(namespace, procedureName) {
110
+ for (const prefix of COLLECTION_PREFIXES) {
111
+ if (procedureName.startsWith(prefix)) {
112
+ return `/${namespace}`;
113
+ }
113
114
  }
114
- // 3. Convention inference single-resource endpoints (with :id)
115
- if (procedureName.startsWith('get') ||
116
- procedureName.startsWith('update') ||
117
- procedureName.startsWith('edit') ||
118
- procedureName.startsWith('patch') ||
119
- procedureName.startsWith('delete') ||
120
- procedureName.startsWith('remove')) {
121
- return `/${namespace}/:id`;
115
+ for (const prefix of SINGLE_RESOURCE_PREFIXES) {
116
+ if (procedureName.startsWith(prefix)) {
117
+ return `/${namespace}/:id`;
118
+ }
122
119
  }
123
- // 4. Fallback: /{namespace}
124
120
  return `/${namespace}`;
125
121
  }
126
122
  /**
@@ -273,7 +269,7 @@ function resolveMethodAndPath(namespace, procedureName, routes) {
273
269
  }
274
270
  // Fall back to naming convention inference
275
271
  const method = inferMethodFromName(procedureName);
276
- const path = buildRestPath(namespace, procedureName, routes);
272
+ const path = inferRestPath(namespace, procedureName);
277
273
  return { method, path };
278
274
  }
279
275
  /**
package/dist/errors.js CHANGED
@@ -242,8 +242,10 @@ function isErrorResponseLike(body) {
242
242
  if (typeof body !== 'object' || body === null) {
243
243
  return false;
244
244
  }
245
- const obj = body;
246
- return (typeof obj.error === 'string' &&
247
- typeof obj.message === 'string' &&
248
- typeof obj.statusCode === 'number');
245
+ return ('error' in body &&
246
+ typeof body.error === 'string' &&
247
+ 'message' in body &&
248
+ typeof body.message === 'string' &&
249
+ 'statusCode' in body &&
250
+ typeof body.statusCode === 'number');
249
251
  }
@@ -444,15 +444,10 @@ function createMutationProcedureProxy(namespace, procedureName, getClient) {
444
444
  * @returns true if the procedure is a query, false for mutation
445
445
  */
446
446
  function isProcedureQuery(namespace, procedureName, routes) {
447
- // Check routes for explicit kind first
448
447
  const routeEntry = routes?.[namespace]?.[procedureName];
449
- if (routeEntry) {
450
- // RouteEntry can be object with kind, or legacy string (path only)
451
- if (typeof routeEntry === 'object' && 'kind' in routeEntry) {
452
- return routeEntry.kind === 'query';
453
- }
448
+ if (typeof routeEntry === 'object' && 'kind' in routeEntry) {
449
+ return routeEntry.kind === 'query';
454
450
  }
455
- // Fall back to naming convention
456
451
  return isQueryProcedure(procedureName);
457
452
  }
458
453
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/client",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Type-safe frontend API client for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",