@veloxts/router 0.6.64 → 0.6.65

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,14 @@
1
1
  # @veloxts/router
2
2
 
3
+ ## 0.6.65
4
+
5
+ ### Patch Changes
6
+
7
+ - improve ai integration and simplify api router definition
8
+ - Updated dependencies
9
+ - @veloxts/core@0.6.65
10
+ - @veloxts/validation@0.6.65
11
+
3
12
  ## 0.6.64
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -55,8 +55,6 @@ export type { AnyRouter, InferAppRouter, TRPCInstance, TRPCPluginOptions, } from
55
55
  export { appRouter, buildTRPCRouter, createTRPCContextFactory, registerTRPCPlugin, trpc, veloxErrorToTRPCError, } from './trpc/index.js';
56
56
  export type { DiscoveryOptions, DiscoveryResult, DiscoveryWarning } from './discovery/index.js';
57
57
  export { DiscoveryError, DiscoveryErrorCode, directoryNotFound, discoverProcedures, discoverProceduresVerbose, fileLoadError, invalidExport, invalidFileType, isDiscoveryError, noProceduresFound, permissionDenied, } from './discovery/index.js';
58
- export type { ContractDefinition, ContractEntry, HttpMethodRoute, InferContract, InferRouterFromContracts, RouteDefinition, RoutesDefinition, } from './contracts.js';
59
- export { defineContract, defineRoutes } from './contracts.js';
60
58
  export type { ServeOptions } from './expose.js';
61
59
  export { serve } from './expose.js';
62
60
  /**
package/dist/index.js CHANGED
@@ -59,7 +59,6 @@ export {
59
59
  // tRPC utilities
60
60
  appRouter, buildTRPCRouter, createTRPCContextFactory, registerTRPCPlugin, trpc, veloxErrorToTRPCError, } from './trpc/index.js';
61
61
  export { DiscoveryError, DiscoveryErrorCode, directoryNotFound, discoverProcedures, discoverProceduresVerbose, fileLoadError, invalidExport, invalidFileType, isDiscoveryError, noProceduresFound, permissionDenied, } from './discovery/index.js';
62
- export { defineContract, defineRoutes } from './contracts.js';
63
62
  export { serve } from './expose.js';
64
63
  // ============================================================================
65
64
  // Dependency Injection
@@ -7,5 +7,5 @@ export type { RestAdapterOptions, RestPlugin, RestRoute } from './adapter.js';
7
7
  export { generateRestRoutes, getRouteSummary, registerRestRoutes, rest, } from './adapter.js';
8
8
  export type { RestMapping } from './naming.js';
9
9
  export { buildNestedRestPath, buildRestPath, followsNamingConvention, inferResourceName, parseNamingConvention, } from './naming.js';
10
- export type { ExtractRoutesType, RouteMap } from './routes.js';
10
+ export type { ExtractRoutesType, RouteEntry, RouteMap } from './routes.js';
11
11
  export { extractRoutes } from './routes.js';
@@ -9,35 +9,47 @@
9
9
  */
10
10
  import type { ProcedureCollection, ProcedureRecord } from '../types.js';
11
11
  /**
12
- * Route map type - maps namespace -> procedure -> path
12
+ * A single route entry with method, path, and procedure kind
13
+ *
14
+ * Matches the RouteEntry interface in @veloxts/client
15
+ */
16
+ export interface RouteEntry {
17
+ method: string;
18
+ path: string;
19
+ kind: 'query' | 'mutation';
20
+ }
21
+ /**
22
+ * Route map type - maps namespace -> procedure -> RouteEntry
13
23
  *
14
24
  * @example
15
25
  * ```typescript
16
26
  * {
17
27
  * auth: {
18
- * createSession: '/auth/login',
19
- * createAccount: '/auth/register',
28
+ * createSession: { method: 'POST', path: '/auth/login', kind: 'mutation' },
29
+ * createAccount: { method: 'POST', path: '/auth/register', kind: 'mutation' },
20
30
  * },
21
31
  * users: {
22
- * getProfile: '/users/me',
32
+ * getProfile: { method: 'GET', path: '/users/me', kind: 'query' },
33
+ * listUsers: { method: 'GET', path: '/users', kind: 'query' },
23
34
  * },
24
35
  * }
25
36
  * ```
26
37
  */
27
- export type RouteMap = Record<string, Record<string, string>>;
38
+ export type RouteMap = Record<string, Record<string, RouteEntry>>;
28
39
  /**
29
40
  * Extracts REST route mappings from procedure collections
30
41
  *
31
- * Reads `.rest()` override metadata from compiled procedures and generates
32
- * a RouteMap that frontend clients can import directly. This eliminates
33
- * the need to manually duplicate route mappings between backend and frontend.
42
+ * Generates a RouteMap with method, path, and kind for ALL procedures,
43
+ * enabling frontend clients to:
44
+ * 1. Know the correct REST endpoint for each procedure
45
+ * 2. Override naming convention heuristics with explicit `kind` field
34
46
  *
35
- * Only procedures with explicit `.rest({ path: '...' })` overrides are included.
36
- * Procedures using naming conventions (getUser, listUsers, etc.) don't need
37
- * explicit mappings since the client infers their paths automatically.
47
+ * For procedures with `.rest()` overrides, uses the specified path/method.
48
+ * For procedures following naming conventions, infers method/path automatically.
49
+ * For non-conventional procedures (like `health`), uses POST as default method.
38
50
  *
39
51
  * @param collections - Array of procedure collections to extract routes from
40
- * @returns RouteMap object with namespace -> procedure -> path mappings
52
+ * @returns RouteMap with namespace -> procedure -> { method, path, kind } mappings
41
53
  *
42
54
  * @example
43
55
  * ```typescript
@@ -46,15 +58,17 @@ export type RouteMap = Record<string, Record<string, string>>;
46
58
  * import { authProcedures } from './procedures/auth.js';
47
59
  * import { userProcedures } from './procedures/users.js';
48
60
  *
49
- * // Export for frontend
61
+ * // Export for frontend (includes kind for type detection)
50
62
  * export const routes = extractRoutes([authProcedures, userProcedures]);
51
63
  * export type AppRouter = typeof router;
52
64
  *
53
- * // Frontend: main.tsx
65
+ * // Frontend: api.ts
66
+ * import { createVeloxHooks } from '@veloxts/client/react';
54
67
  * import { routes } from '../../api/src/index.js';
55
68
  * import type { AppRouter } from '../../api/src/index.js';
56
69
  *
57
- * <VeloxProvider<AppRouter> config={{ baseUrl: '/api', routes }}>
70
+ * // Routes provide explicit kind for non-conventional procedure names
71
+ * export const api = createVeloxHooks<AppRouter>({ routes });
58
72
  * ```
59
73
  */
60
74
  export declare function extractRoutes(collections: ProcedureCollection[]): RouteMap;
@@ -7,19 +7,21 @@
7
7
  *
8
8
  * @module rest/routes
9
9
  */
10
+ import { buildRestPath, parseNamingConvention } from './naming.js';
10
11
  /**
11
12
  * Extracts REST route mappings from procedure collections
12
13
  *
13
- * Reads `.rest()` override metadata from compiled procedures and generates
14
- * a RouteMap that frontend clients can import directly. This eliminates
15
- * the need to manually duplicate route mappings between backend and frontend.
14
+ * Generates a RouteMap with method, path, and kind for ALL procedures,
15
+ * enabling frontend clients to:
16
+ * 1. Know the correct REST endpoint for each procedure
17
+ * 2. Override naming convention heuristics with explicit `kind` field
16
18
  *
17
- * Only procedures with explicit `.rest({ path: '...' })` overrides are included.
18
- * Procedures using naming conventions (getUser, listUsers, etc.) don't need
19
- * explicit mappings since the client infers their paths automatically.
19
+ * For procedures with `.rest()` overrides, uses the specified path/method.
20
+ * For procedures following naming conventions, infers method/path automatically.
21
+ * For non-conventional procedures (like `health`), uses POST as default method.
20
22
  *
21
23
  * @param collections - Array of procedure collections to extract routes from
22
- * @returns RouteMap object with namespace -> procedure -> path mappings
24
+ * @returns RouteMap with namespace -> procedure -> { method, path, kind } mappings
23
25
  *
24
26
  * @example
25
27
  * ```typescript
@@ -28,15 +30,17 @@
28
30
  * import { authProcedures } from './procedures/auth.js';
29
31
  * import { userProcedures } from './procedures/users.js';
30
32
  *
31
- * // Export for frontend
33
+ * // Export for frontend (includes kind for type detection)
32
34
  * export const routes = extractRoutes([authProcedures, userProcedures]);
33
35
  * export type AppRouter = typeof router;
34
36
  *
35
- * // Frontend: main.tsx
37
+ * // Frontend: api.ts
38
+ * import { createVeloxHooks } from '@veloxts/client/react';
36
39
  * import { routes } from '../../api/src/index.js';
37
40
  * import type { AppRouter } from '../../api/src/index.js';
38
41
  *
39
- * <VeloxProvider<AppRouter> config={{ baseUrl: '/api', routes }}>
42
+ * // Routes provide explicit kind for non-conventional procedure names
43
+ * export const api = createVeloxHooks<AppRouter>({ routes });
40
44
  * ```
41
45
  */
42
46
  export function extractRoutes(collections) {
@@ -44,15 +48,45 @@ export function extractRoutes(collections) {
44
48
  for (const collection of collections) {
45
49
  const namespaceRoutes = {};
46
50
  for (const [procedureName, procedure] of Object.entries(collection.procedures)) {
47
- // Only include procedures with explicit .rest() path overrides
51
+ const kind = procedure.type;
52
+ // Check for explicit .rest() override first
48
53
  if (procedure.restOverride?.path) {
49
- namespaceRoutes[procedureName] = procedure.restOverride.path;
54
+ const method = procedure.restOverride.method ?? inferMethodFromKind(kind);
55
+ namespaceRoutes[procedureName] = {
56
+ method,
57
+ path: procedure.restOverride.path,
58
+ kind,
59
+ };
60
+ continue;
50
61
  }
62
+ // Try to infer from naming convention
63
+ const mapping = parseNamingConvention(procedureName, kind);
64
+ if (mapping) {
65
+ namespaceRoutes[procedureName] = {
66
+ method: mapping.method,
67
+ path: buildRestPath(collection.namespace, mapping),
68
+ kind,
69
+ };
70
+ continue;
71
+ }
72
+ // Fallback for non-conventional names: use namespace path with POST for mutations
73
+ namespaceRoutes[procedureName] = {
74
+ method: inferMethodFromKind(kind),
75
+ path: `/${collection.namespace}`,
76
+ kind,
77
+ };
51
78
  }
52
- // Only add namespace if it has custom routes
79
+ // Always add namespace (all procedures are included now)
53
80
  if (Object.keys(namespaceRoutes).length > 0) {
54
81
  routes[collection.namespace] = namespaceRoutes;
55
82
  }
56
83
  }
57
84
  return routes;
58
85
  }
86
+ /**
87
+ * Infer HTTP method from procedure kind
88
+ * @internal
89
+ */
90
+ function inferMethodFromKind(kind) {
91
+ return kind === 'query' ? 'GET' : 'POST';
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/router",
3
- "version": "0.6.64",
3
+ "version": "0.6.65",
4
4
  "description": "Procedure definitions with tRPC and REST routing for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,8 +40,8 @@
40
40
  "@trpc/server": "11.8.0",
41
41
  "fastify": "5.6.2",
42
42
  "zod-to-json-schema": "3.24.5",
43
- "@veloxts/core": "0.6.64",
44
- "@veloxts/validation": "0.6.64"
43
+ "@veloxts/core": "0.6.65",
44
+ "@veloxts/validation": "0.6.65"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@vitest/coverage-v8": "4.0.16",