@veloxts/router 0.4.6 → 0.4.9
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/dist/expose.d.ts +84 -0
- package/dist/expose.d.ts.map +1 -0
- package/dist/expose.js +85 -0
- package/dist/expose.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/procedure/builder.d.ts +76 -4
- package/dist/procedure/builder.d.ts.map +1 -1
- package/dist/procedure/builder.js +71 -5
- package/dist/procedure/builder.js.map +1 -1
- package/dist/procedure/factory.d.ts +56 -0
- package/dist/procedure/factory.d.ts.map +1 -0
- package/dist/procedure/factory.js +58 -0
- package/dist/procedure/factory.js.map +1 -0
- package/dist/rest/index.d.ts +2 -0
- package/dist/rest/index.d.ts.map +1 -1
- package/dist/rest/index.js +1 -0
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/routes.d.ts +94 -0
- package/dist/rest/routes.d.ts.map +1 -0
- package/dist/rest/routes.js +59 -0
- package/dist/rest/routes.js.map +1 -0
- package/dist/warnings.d.ts +106 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js +176 -0
- package/dist/warnings.js.map +1 -0
- package/package.json +3 -3
package/dist/expose.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified API Registration
|
|
3
|
+
*
|
|
4
|
+
* Serves procedure collections as both REST and tRPC endpoints
|
|
5
|
+
* with a single, elegant function call.
|
|
6
|
+
*
|
|
7
|
+
* @module serve
|
|
8
|
+
*/
|
|
9
|
+
import { type VeloxApp } from '@veloxts/core';
|
|
10
|
+
import { type AnyRouter } from './trpc/index.js';
|
|
11
|
+
import type { ProcedureCollection } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Options for serving procedures
|
|
14
|
+
*/
|
|
15
|
+
export interface ServeOptions {
|
|
16
|
+
/**
|
|
17
|
+
* REST API prefix
|
|
18
|
+
*
|
|
19
|
+
* - `string`: Custom prefix (e.g., '/v1', '/api/v2')
|
|
20
|
+
* - `false`: Disable REST endpoints entirely
|
|
21
|
+
*
|
|
22
|
+
* @default '/api'
|
|
23
|
+
*/
|
|
24
|
+
api?: string | false;
|
|
25
|
+
/**
|
|
26
|
+
* tRPC endpoint prefix
|
|
27
|
+
*
|
|
28
|
+
* - `string`: Custom prefix (e.g., '/rpc')
|
|
29
|
+
* - `false`: Disable tRPC endpoints entirely
|
|
30
|
+
*
|
|
31
|
+
* @default '/trpc'
|
|
32
|
+
*/
|
|
33
|
+
rpc?: string | false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Serve procedures as REST and tRPC endpoints
|
|
37
|
+
*
|
|
38
|
+
* This is the recommended way to register your API.
|
|
39
|
+
* Define your procedures once, serve them everywhere.
|
|
40
|
+
*
|
|
41
|
+
* @param app - VeloxTS application instance
|
|
42
|
+
* @param procedures - Array of procedure collections to serve
|
|
43
|
+
* @param options - Optional configuration for API and RPC prefixes
|
|
44
|
+
* @returns The tRPC router for type exports
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Both REST (/api) and tRPC (/trpc) with zero config
|
|
49
|
+
* const router = await serve(app, [healthProcedures, userProcedures]);
|
|
50
|
+
* export type AppRouter = typeof router;
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // REST only (external API)
|
|
56
|
+
* await serve(app, [healthProcedures, userProcedures], { rpc: false });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // tRPC only (internal app)
|
|
62
|
+
* const router = await serve(app, [healthProcedures, userProcedures], { api: false });
|
|
63
|
+
* export type AppRouter = typeof router;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Custom prefixes
|
|
69
|
+
* const router = await serve(app, [healthProcedures, userProcedures], {
|
|
70
|
+
* api: '/v1',
|
|
71
|
+
* rpc: '/rpc',
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function serve(app: VeloxApp, procedures: ProcedureCollection[], options?: ServeOptions): Promise<AnyRouter>;
|
|
76
|
+
/** @deprecated Use `serve()` instead */
|
|
77
|
+
export declare const expose: typeof serve;
|
|
78
|
+
/** @deprecated Use `ServeOptions` instead */
|
|
79
|
+
export type ExposeOptions = ServeOptions;
|
|
80
|
+
/** @deprecated Use `ServeOptions` instead */
|
|
81
|
+
export type ExposeResult<TRouter extends AnyRouter = AnyRouter> = {
|
|
82
|
+
router: TRouter;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=expose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expose.d.ts","sourceRoot":"","sources":["../src/expose.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAE,KAAK,SAAS,EAAmD,MAAM,iBAAiB,CAAC;AAClG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAMtD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAErB;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACtB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,KAAK,CACzB,GAAG,EAAE,QAAQ,EACb,UAAU,EAAE,mBAAmB,EAAE,EACjC,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,SAAS,CAAC,CA8BpB;AAMD,wCAAwC;AACxC,eAAO,MAAM,MAAM,cAAQ,CAAC;AAE5B,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,IAAI;IAChE,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC"}
|
package/dist/expose.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified API Registration
|
|
3
|
+
*
|
|
4
|
+
* Serves procedure collections as both REST and tRPC endpoints
|
|
5
|
+
* with a single, elegant function call.
|
|
6
|
+
*
|
|
7
|
+
* @module serve
|
|
8
|
+
*/
|
|
9
|
+
import { fail } from '@veloxts/core';
|
|
10
|
+
import { rest } from './rest/index.js';
|
|
11
|
+
import { createAppRouter, createTRPC, registerTRPCPlugin } from './trpc/index.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Main Function
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Serve procedures as REST and tRPC endpoints
|
|
17
|
+
*
|
|
18
|
+
* This is the recommended way to register your API.
|
|
19
|
+
* Define your procedures once, serve them everywhere.
|
|
20
|
+
*
|
|
21
|
+
* @param app - VeloxTS application instance
|
|
22
|
+
* @param procedures - Array of procedure collections to serve
|
|
23
|
+
* @param options - Optional configuration for API and RPC prefixes
|
|
24
|
+
* @returns The tRPC router for type exports
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Both REST (/api) and tRPC (/trpc) with zero config
|
|
29
|
+
* const router = await serve(app, [healthProcedures, userProcedures]);
|
|
30
|
+
* export type AppRouter = typeof router;
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // REST only (external API)
|
|
36
|
+
* await serve(app, [healthProcedures, userProcedures], { rpc: false });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // tRPC only (internal app)
|
|
42
|
+
* const router = await serve(app, [healthProcedures, userProcedures], { api: false });
|
|
43
|
+
* export type AppRouter = typeof router;
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Custom prefixes
|
|
49
|
+
* const router = await serve(app, [healthProcedures, userProcedures], {
|
|
50
|
+
* api: '/v1',
|
|
51
|
+
* rpc: '/rpc',
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export async function serve(app, procedures, options = {}) {
|
|
56
|
+
const { api: apiPrefix = '/api', rpc: rpcPrefix = '/trpc' } = options;
|
|
57
|
+
// Validate inputs - using fail() for catalog-driven errors
|
|
58
|
+
if (procedures.length === 0) {
|
|
59
|
+
throw fail('VELOX-2006');
|
|
60
|
+
}
|
|
61
|
+
if (apiPrefix === false && rpcPrefix === false) {
|
|
62
|
+
throw fail('VELOX-2007');
|
|
63
|
+
}
|
|
64
|
+
// Router is created even when rpc is disabled - needed for AppRouter type export
|
|
65
|
+
const t = createTRPC();
|
|
66
|
+
const appRouter = createAppRouter(t, procedures);
|
|
67
|
+
// Register tRPC routes if enabled
|
|
68
|
+
if (rpcPrefix !== false) {
|
|
69
|
+
await registerTRPCPlugin(app.server, {
|
|
70
|
+
prefix: rpcPrefix,
|
|
71
|
+
router: appRouter,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Register REST routes if enabled
|
|
75
|
+
if (apiPrefix !== false) {
|
|
76
|
+
app.routes(rest(procedures, { prefix: apiPrefix }));
|
|
77
|
+
}
|
|
78
|
+
return appRouter;
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Backward Compatibility
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/** @deprecated Use `serve()` instead */
|
|
84
|
+
export const expose = serve;
|
|
85
|
+
//# sourceMappingURL=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AAC,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E,wCAAwC;AACxC,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -43,12 +43,18 @@ export type { CompiledProcedure, ContextExtensions, ContextFactory, ExtendedCont
|
|
|
43
43
|
export { PROCEDURE_METHOD_MAP, } from './types.js';
|
|
44
44
|
export type { GuardErrorResponse, RouterErrorCode } from './errors.js';
|
|
45
45
|
export { GuardError, isGuardError } from './errors.js';
|
|
46
|
+
export type { DefineProceduresOptions, } from './procedure/builder.js';
|
|
46
47
|
export { defineProcedures, executeProcedure, isCompiledProcedure, isProcedureCollection, procedure, } from './procedure/builder.js';
|
|
48
|
+
export { createProcedure, typedProcedure } from './procedure/factory.js';
|
|
47
49
|
export type { BuilderRuntimeState, InferProcedures, InferSchemaOutput, ProcedureBuilder, ProcedureBuilderState, ProcedureDefinitions, ValidSchema, } from './procedure/types.js';
|
|
48
|
-
export type {
|
|
49
|
-
export {
|
|
50
|
+
export type { NamingWarning, NamingWarningType, WarningConfig, WarningOption } from './warnings.js';
|
|
51
|
+
export { analyzeNamingConvention, isDevelopment, normalizeWarningOption } from './warnings.js';
|
|
52
|
+
export type { ExtractRoutesType, RestAdapterOptions, RestMapping, RestRoute, RouteMap, } from './rest/index.js';
|
|
53
|
+
export { buildNestedRestPath, buildRestPath, createRoutesRegistrar, extractRoutes, followsNamingConvention, generateRestRoutes, getRouteSummary, inferResourceName, parseNamingConvention, registerRestRoutes, rest, } from './rest/index.js';
|
|
50
54
|
export type { AnyRouter, InferAppRouter, TRPCInstance, TRPCPluginOptions, } from './trpc/index.js';
|
|
51
55
|
export { buildTRPCRouter, createAppRouter, createTRPC, createTRPCContextFactory, registerTRPCPlugin, veloxErrorToTRPCError, } from './trpc/index.js';
|
|
52
56
|
export type { DiscoveryOptions, DiscoveryResult, DiscoveryWarning } from './discovery/index.js';
|
|
53
57
|
export { DiscoveryError, DiscoveryErrorCode, directoryNotFound, discoverProcedures, discoverProceduresVerbose, fileLoadError, invalidExport, invalidFileType, isDiscoveryError, noProceduresFound, permissionDenied, } from './discovery/index.js';
|
|
58
|
+
export type { ExposeOptions, ExposeResult, ServeOptions } from './expose.js';
|
|
59
|
+
export { expose, serve } from './expose.js';
|
|
54
60
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAQH,6BAA6B;AAC7B,eAAO,MAAM,cAAc,EAAE,MAA+C,CAAC;AAO7E,YAAY,EAEV,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,eAAe,EAEf,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EAEnB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAEhB,oBAAoB,EAEpB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAMpB,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMvD,OAAO,EAEL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,SAAS,GACV,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["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ACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,mBAAmB,EACnB,aAAa,EAEb,qBAAqB,EAErB,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAElB,IAAI,GACL,MAAM,iBAAiB,CAAC;AAMzB,YAAY,EAEV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,eAAe,EACf,eAAe,EACf,UAAU,EACV,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAMzB,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAO9B,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -47,21 +47,24 @@ export {
|
|
|
47
47
|
// Constants
|
|
48
48
|
PROCEDURE_METHOD_MAP, } from './types.js';
|
|
49
49
|
export { GuardError, isGuardError } from './errors.js';
|
|
50
|
-
// ============================================================================
|
|
51
|
-
// Procedure Builder
|
|
52
|
-
// ============================================================================
|
|
53
50
|
export {
|
|
54
51
|
// Builder functions
|
|
55
52
|
defineProcedures, executeProcedure, isCompiledProcedure, isProcedureCollection, procedure, } from './procedure/builder.js';
|
|
53
|
+
// Typed procedure factory
|
|
54
|
+
export { createProcedure, typedProcedure } from './procedure/factory.js';
|
|
55
|
+
export { analyzeNamingConvention, isDevelopment, normalizeWarningOption } from './warnings.js';
|
|
56
56
|
export {
|
|
57
57
|
// Internal utilities
|
|
58
58
|
buildNestedRestPath, buildRestPath,
|
|
59
59
|
// Legacy API (deprecated)
|
|
60
|
-
createRoutesRegistrar,
|
|
60
|
+
createRoutesRegistrar,
|
|
61
|
+
// Route extraction for frontend clients
|
|
62
|
+
extractRoutes, followsNamingConvention, generateRestRoutes, getRouteSummary, inferResourceName, parseNamingConvention, registerRestRoutes,
|
|
61
63
|
// Succinct API (preferred)
|
|
62
64
|
rest, } from './rest/index.js';
|
|
63
65
|
export {
|
|
64
66
|
// tRPC utilities
|
|
65
67
|
buildTRPCRouter, createAppRouter, createTRPC, createTRPCContextFactory, registerTRPCPlugin, veloxErrorToTRPCError, } from './trpc/index.js';
|
|
66
68
|
export { DiscoveryError, DiscoveryErrorCode, directoryNotFound, discoverProcedures, discoverProceduresVerbose, fileLoadError, invalidExport, invalidFileType, isDiscoveryError, noProceduresFound, permissionDenied, } from './discovery/index.js';
|
|
69
|
+
export { expose, serve } from './expose.js';
|
|
67
70
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,6CAA6C;AAC7C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAEtE,6BAA6B;AAC7B,MAAM,CAAC,MAAM,cAAc,GAAW,WAAW,CAAC,OAAO,IAAI,eAAe,CAAC;AAmC7E,OAAO;AACL,YAAY;AACZ,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAE,UAAU,EA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zB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module procedure/builder
|
|
9
9
|
*/
|
|
10
|
-
import type
|
|
10
|
+
import { type BaseContext } from '@veloxts/core';
|
|
11
11
|
import type { CompiledProcedure, ProcedureCollection } from '../types.js';
|
|
12
|
+
import { type WarningOption } from '../warnings.js';
|
|
12
13
|
import type { InferProcedures, ProcedureBuilder, ProcedureDefinitions } from './types.js';
|
|
13
14
|
/**
|
|
14
15
|
* Creates a new procedure builder instance
|
|
@@ -16,10 +17,12 @@ import type { InferProcedures, ProcedureBuilder, ProcedureDefinitions } from './
|
|
|
16
17
|
* This is the primary entry point for defining procedures. The builder uses
|
|
17
18
|
* TypeScript's generic inference to track types through the fluent chain.
|
|
18
19
|
*
|
|
19
|
-
* @
|
|
20
|
+
* @template TContext - The context type (defaults to BaseContext)
|
|
21
|
+
* @returns New procedure builder with unknown input, unknown output, and TContext
|
|
20
22
|
*
|
|
21
23
|
* @example
|
|
22
24
|
* ```typescript
|
|
25
|
+
* // Basic usage with BaseContext
|
|
23
26
|
* const getUser = procedure()
|
|
24
27
|
* .input(z.object({ id: z.string().uuid() }))
|
|
25
28
|
* .output(UserSchema)
|
|
@@ -29,18 +32,57 @@ import type { InferProcedures, ProcedureBuilder, ProcedureDefinitions } from './
|
|
|
29
32
|
* // return type must match UserSchema
|
|
30
33
|
* return ctx.db.user.findUnique({ where: { id: input.id } });
|
|
31
34
|
* });
|
|
35
|
+
*
|
|
36
|
+
* // With custom context type
|
|
37
|
+
* const getUserTyped = procedure<AppContext>()
|
|
38
|
+
* .query(async ({ ctx }) => {
|
|
39
|
+
* // ctx is AppContext with full autocomplete
|
|
40
|
+
* return ctx.db.user.findMany();
|
|
41
|
+
* });
|
|
32
42
|
* ```
|
|
33
43
|
*/
|
|
34
|
-
export declare function procedure(): ProcedureBuilder<unknown, unknown,
|
|
44
|
+
export declare function procedure<TContext extends BaseContext = BaseContext>(): ProcedureBuilder<unknown, unknown, TContext>;
|
|
45
|
+
/**
|
|
46
|
+
* Options for defining a procedure collection
|
|
47
|
+
*/
|
|
48
|
+
export interface DefineProceduresOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for naming convention warnings
|
|
51
|
+
*
|
|
52
|
+
* Accepts three forms:
|
|
53
|
+
* - `false` - Disable all warnings
|
|
54
|
+
* - `'strict'` - Treat warnings as errors (fail fast)
|
|
55
|
+
* - `{ ... }` - Full configuration object
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Shorthand: disable warnings
|
|
60
|
+
* defineProcedures('legacy', procs, { warnings: false });
|
|
61
|
+
*
|
|
62
|
+
* // Shorthand: strict mode (CI/CD)
|
|
63
|
+
* defineProcedures('api', procs, { warnings: 'strict' });
|
|
64
|
+
*
|
|
65
|
+
* // Full config with exceptions
|
|
66
|
+
* defineProcedures('custom', procs, {
|
|
67
|
+
* warnings: { strict: true, except: ['customAction'] }
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
warnings?: WarningOption;
|
|
72
|
+
}
|
|
35
73
|
/**
|
|
36
74
|
* Defines a collection of procedures under a namespace
|
|
37
75
|
*
|
|
38
76
|
* Groups related procedures together for registration with routers.
|
|
39
77
|
* The namespace determines the base path for REST routes.
|
|
40
78
|
*
|
|
79
|
+
* In development mode, emits warnings for procedure names that don't follow
|
|
80
|
+
* naming conventions (which means they won't generate REST routes).
|
|
81
|
+
*
|
|
41
82
|
* @template TProcedures - The record of named procedures
|
|
42
83
|
* @param namespace - Resource namespace (e.g., 'users', 'posts')
|
|
43
84
|
* @param procedures - Object containing named procedures
|
|
85
|
+
* @param options - Optional configuration for warnings
|
|
44
86
|
* @returns Procedure collection with preserved types
|
|
45
87
|
*
|
|
46
88
|
* @example
|
|
@@ -63,8 +105,38 @@ export declare function procedure(): ProcedureBuilder<unknown, unknown, BaseCont
|
|
|
63
105
|
* // userProcedures.procedures.getUser.inputSchema -> { id: string }
|
|
64
106
|
* // userProcedures.procedures.createUser -> mutation type
|
|
65
107
|
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Disabling warnings
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Shorthand
|
|
112
|
+
* export const legacyProcedures = defineProcedures('legacy', procs, {
|
|
113
|
+
* warnings: false
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Excluding specific procedures
|
|
118
|
+
* ```typescript
|
|
119
|
+
* export const customProcedures = defineProcedures('custom', {
|
|
120
|
+
* doCustomThing: procedure().mutation(handler),
|
|
121
|
+
* }, {
|
|
122
|
+
* warnings: { except: ['doCustomThing'] }
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example Strict mode for CI/CD
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Shorthand
|
|
129
|
+
* export const strictProcedures = defineProcedures('api', procs, {
|
|
130
|
+
* warnings: 'strict'
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* // Or with exceptions
|
|
134
|
+
* export const strictProcedures = defineProcedures('api', procs, {
|
|
135
|
+
* warnings: { strict: true, except: ['legacyEndpoint'] }
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
66
138
|
*/
|
|
67
|
-
export declare function defineProcedures<TProcedures extends ProcedureDefinitions>(namespace: string, procedures: TProcedures): ProcedureCollection<InferProcedures<TProcedures>>;
|
|
139
|
+
export declare function defineProcedures<TProcedures extends ProcedureDefinitions>(namespace: string, procedures: TProcedures, options?: DefineProceduresOptions): ProcedureCollection<InferProcedures<TProcedures>>;
|
|
68
140
|
/**
|
|
69
141
|
* Executes a compiled procedure with the given input and context
|
|
70
142
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/procedure/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/procedure/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAkC,MAAM,eAAe,CAAC;AAGjF,OAAO,KAAK,EACV,iBAAiB,EAIjB,mBAAmB,EAGpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,eAAe,EAEf,gBAAgB,EAChB,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAyEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,QAAQ,SAAS,WAAW,GAAG,WAAW,KAAK,gBAAgB,CACvF,OAAO,EACP,OAAO,EACP,QAAQ,CACT,CASA;AA4ND;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,SAAS,oBAAoB,EACvE,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,WAAW,EACvB,OAAO,CAAC,EAAE,uBAAuB,GAChC,mBAAmB,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAwCnD;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,SAAS,WAAW,EAClF,SAAS,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACvD,QAAQ,EAAE,OAAO,EACjB,GAAG,EAAE,QAAQ,GACZ,OAAO,CAAC,OAAO,CAAC,CAyDlB;AAkDD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAa9E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAYlF"}
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module procedure/builder
|
|
9
9
|
*/
|
|
10
|
+
import { ConfigurationError, logWarning } from '@veloxts/core';
|
|
10
11
|
import { GuardError } from '../errors.js';
|
|
12
|
+
import { analyzeNamingConvention, isDevelopment, normalizeWarningOption, } from '../warnings.js';
|
|
11
13
|
// ============================================================================
|
|
12
14
|
// Utility Functions
|
|
13
15
|
// ============================================================================
|
|
@@ -81,10 +83,12 @@ function deriveParentParamName(namespace) {
|
|
|
81
83
|
* This is the primary entry point for defining procedures. The builder uses
|
|
82
84
|
* TypeScript's generic inference to track types through the fluent chain.
|
|
83
85
|
*
|
|
84
|
-
* @
|
|
86
|
+
* @template TContext - The context type (defaults to BaseContext)
|
|
87
|
+
* @returns New procedure builder with unknown input, unknown output, and TContext
|
|
85
88
|
*
|
|
86
89
|
* @example
|
|
87
90
|
* ```typescript
|
|
91
|
+
* // Basic usage with BaseContext
|
|
88
92
|
* const getUser = procedure()
|
|
89
93
|
* .input(z.object({ id: z.string().uuid() }))
|
|
90
94
|
* .output(UserSchema)
|
|
@@ -94,6 +98,13 @@ function deriveParentParamName(namespace) {
|
|
|
94
98
|
* // return type must match UserSchema
|
|
95
99
|
* return ctx.db.user.findUnique({ where: { id: input.id } });
|
|
96
100
|
* });
|
|
101
|
+
*
|
|
102
|
+
* // With custom context type
|
|
103
|
+
* const getUserTyped = procedure<AppContext>()
|
|
104
|
+
* .query(async ({ ctx }) => {
|
|
105
|
+
* // ctx is AppContext with full autocomplete
|
|
106
|
+
* return ctx.db.user.findMany();
|
|
107
|
+
* });
|
|
97
108
|
* ```
|
|
98
109
|
*/
|
|
99
110
|
export function procedure() {
|
|
@@ -271,18 +282,19 @@ function createPrecompiledMiddlewareExecutor(middlewares, handler) {
|
|
|
271
282
|
return result.output;
|
|
272
283
|
};
|
|
273
284
|
}
|
|
274
|
-
// ============================================================================
|
|
275
|
-
// Procedure Collection Factory
|
|
276
|
-
// ============================================================================
|
|
277
285
|
/**
|
|
278
286
|
* Defines a collection of procedures under a namespace
|
|
279
287
|
*
|
|
280
288
|
* Groups related procedures together for registration with routers.
|
|
281
289
|
* The namespace determines the base path for REST routes.
|
|
282
290
|
*
|
|
291
|
+
* In development mode, emits warnings for procedure names that don't follow
|
|
292
|
+
* naming conventions (which means they won't generate REST routes).
|
|
293
|
+
*
|
|
283
294
|
* @template TProcedures - The record of named procedures
|
|
284
295
|
* @param namespace - Resource namespace (e.g., 'users', 'posts')
|
|
285
296
|
* @param procedures - Object containing named procedures
|
|
297
|
+
* @param options - Optional configuration for warnings
|
|
286
298
|
* @returns Procedure collection with preserved types
|
|
287
299
|
*
|
|
288
300
|
* @example
|
|
@@ -305,8 +317,62 @@ function createPrecompiledMiddlewareExecutor(middlewares, handler) {
|
|
|
305
317
|
* // userProcedures.procedures.getUser.inputSchema -> { id: string }
|
|
306
318
|
* // userProcedures.procedures.createUser -> mutation type
|
|
307
319
|
* ```
|
|
320
|
+
*
|
|
321
|
+
* @example Disabling warnings
|
|
322
|
+
* ```typescript
|
|
323
|
+
* // Shorthand
|
|
324
|
+
* export const legacyProcedures = defineProcedures('legacy', procs, {
|
|
325
|
+
* warnings: false
|
|
326
|
+
* });
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* @example Excluding specific procedures
|
|
330
|
+
* ```typescript
|
|
331
|
+
* export const customProcedures = defineProcedures('custom', {
|
|
332
|
+
* doCustomThing: procedure().mutation(handler),
|
|
333
|
+
* }, {
|
|
334
|
+
* warnings: { except: ['doCustomThing'] }
|
|
335
|
+
* });
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @example Strict mode for CI/CD
|
|
339
|
+
* ```typescript
|
|
340
|
+
* // Shorthand
|
|
341
|
+
* export const strictProcedures = defineProcedures('api', procs, {
|
|
342
|
+
* warnings: 'strict'
|
|
343
|
+
* });
|
|
344
|
+
*
|
|
345
|
+
* // Or with exceptions
|
|
346
|
+
* export const strictProcedures = defineProcedures('api', procs, {
|
|
347
|
+
* warnings: { strict: true, except: ['legacyEndpoint'] }
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
308
350
|
*/
|
|
309
|
-
export function defineProcedures(namespace, procedures) {
|
|
351
|
+
export function defineProcedures(namespace, procedures, options) {
|
|
352
|
+
// Normalize warning options (handles shorthands)
|
|
353
|
+
const warnings = normalizeWarningOption(options?.warnings);
|
|
354
|
+
// Analyze naming conventions in development mode
|
|
355
|
+
if (isDevelopment() && !warnings.disabled) {
|
|
356
|
+
for (const [name, proc] of Object.entries(procedures)) {
|
|
357
|
+
// Skip if this procedure name is explicitly excluded
|
|
358
|
+
if (warnings.except?.includes(name)) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
// Skip if procedure has explicit .rest() override with both method and path
|
|
362
|
+
const compiledProc = proc;
|
|
363
|
+
if (compiledProc.restOverride?.method && compiledProc.restOverride?.path) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
// Analyze the naming convention
|
|
367
|
+
const warning = analyzeNamingConvention(name, compiledProc.type, namespace);
|
|
368
|
+
if (warning) {
|
|
369
|
+
if (warnings.strict) {
|
|
370
|
+
throw new ConfigurationError(`[${namespace}/${warning.procedureName}] ${warning.message}. ${warning.suggestion}`);
|
|
371
|
+
}
|
|
372
|
+
logWarning(`[${namespace}/${warning.procedureName}] ${warning.message}`, warning.suggestion);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
310
376
|
return {
|
|
311
377
|
namespace,
|
|
312
378
|
procedures: procedures,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/procedure/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/procedure/builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAoB,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAU1C,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,sBAAsB,GAEvB,MAAM,gBAAgB,CAAC;AAUxB,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAS,qBAAqB,CAAC,SAAiB;IAC9C,kCAAkC;IAClC,MAAM,UAAU,GAA2B;QACzC,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,OAAO;QACjB,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,WAAW;QACrB,SAAS,EAAE,YAAY;KACxB,CAAC;IAEF,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;IAClC,CAAC;IAED,+CAA+C;IAC/C,IAAI,QAAQ,GAAG,SAAS,CAAC;IAEzB,IAAI,SAAS,CAAC,QAAQ,CAAC,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AC,GAAG,CAAC,CAAC;oBAC/B,CAAC;oBACD,OAAO,WAAW,EAAE,CAAC;gBACvB,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,GAAG,GAAG,KAAgC,CAAC;IAE7C,OAAO,CACL,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC;QACjD,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU;QACjC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAC9B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,GAAG,GAAG,KAAgC,CAAC;IAE7C,OAAO,CACL,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ;QACjC,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ;QAClC,GAAG,CAAC,UAAU,KAAK,IAAI,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Procedure Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates a procedure builder bound to a specific context type,
|
|
5
|
+
* eliminating the need to specify context on each procedure.
|
|
6
|
+
*
|
|
7
|
+
* @module procedure/factory
|
|
8
|
+
*/
|
|
9
|
+
import type { BaseContext } from '@veloxts/core';
|
|
10
|
+
import type { ProcedureBuilder } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a procedure factory bound to your application's context type
|
|
13
|
+
*
|
|
14
|
+
* Use this to avoid repeating context types on every procedure definition.
|
|
15
|
+
* Define once in your procedures index, use everywhere.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // In api/procedures/index.ts
|
|
20
|
+
* import { createProcedure } from '@veloxts/router';
|
|
21
|
+
* import type { AppContext } from '../context.js';
|
|
22
|
+
*
|
|
23
|
+
* // Create typed procedure factory
|
|
24
|
+
* export const p = createProcedure<AppContext>();
|
|
25
|
+
*
|
|
26
|
+
* // In api/procedures/users.ts
|
|
27
|
+
* import { defineProcedures } from '@veloxts/router';
|
|
28
|
+
* import { p } from './index.js';
|
|
29
|
+
*
|
|
30
|
+
* export const userProcedures = defineProcedures('users', {
|
|
31
|
+
* getUser: p() // ctx is typed as AppContext
|
|
32
|
+
* .input(z.object({ id: z.string() }))
|
|
33
|
+
* .query(async ({ ctx }) => {
|
|
34
|
+
* // ctx.db is PrismaClient with full autocomplete
|
|
35
|
+
* return ctx.db.user.findUnique({ where: { id: input.id } });
|
|
36
|
+
* }),
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @template TContext - Your application's context type
|
|
41
|
+
* @returns A function that creates ProcedureBuilders with the bound context type
|
|
42
|
+
*/
|
|
43
|
+
export declare function createProcedure<TContext extends BaseContext>(): () => ProcedureBuilder<unknown, unknown, TContext>;
|
|
44
|
+
/**
|
|
45
|
+
* Alias for createProcedure with shorter name
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { typedProcedure } from '@veloxts/router';
|
|
50
|
+
* import type { AppContext } from '../context.js';
|
|
51
|
+
*
|
|
52
|
+
* export const p = typedProcedure<AppContext>();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const typedProcedure: typeof createProcedure;
|
|
56
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/procedure/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,WAAW,KAAK,MAAM,gBAAgB,CACrF,OAAO,EACP,OAAO,EACP,QAAQ,CACT,CAGA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,wBAAkB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Procedure Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates a procedure builder bound to a specific context type,
|
|
5
|
+
* eliminating the need to specify context on each procedure.
|
|
6
|
+
*
|
|
7
|
+
* @module procedure/factory
|
|
8
|
+
*/
|
|
9
|
+
import { procedure } from './builder.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a procedure factory bound to your application's context type
|
|
12
|
+
*
|
|
13
|
+
* Use this to avoid repeating context types on every procedure definition.
|
|
14
|
+
* Define once in your procedures index, use everywhere.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // In api/procedures/index.ts
|
|
19
|
+
* import { createProcedure } from '@veloxts/router';
|
|
20
|
+
* import type { AppContext } from '../context.js';
|
|
21
|
+
*
|
|
22
|
+
* // Create typed procedure factory
|
|
23
|
+
* export const p = createProcedure<AppContext>();
|
|
24
|
+
*
|
|
25
|
+
* // In api/procedures/users.ts
|
|
26
|
+
* import { defineProcedures } from '@veloxts/router';
|
|
27
|
+
* import { p } from './index.js';
|
|
28
|
+
*
|
|
29
|
+
* export const userProcedures = defineProcedures('users', {
|
|
30
|
+
* getUser: p() // ctx is typed as AppContext
|
|
31
|
+
* .input(z.object({ id: z.string() }))
|
|
32
|
+
* .query(async ({ ctx }) => {
|
|
33
|
+
* // ctx.db is PrismaClient with full autocomplete
|
|
34
|
+
* return ctx.db.user.findUnique({ where: { id: input.id } });
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @template TContext - Your application's context type
|
|
40
|
+
* @returns A function that creates ProcedureBuilders with the bound context type
|
|
41
|
+
*/
|
|
42
|
+
export function createProcedure() {
|
|
43
|
+
// Now type-safe: procedure() is generic and accepts TContext directly
|
|
44
|
+
return () => procedure();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Alias for createProcedure with shorter name
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { typedProcedure } from '@veloxts/router';
|
|
52
|
+
* import type { AppContext } from '../context.js';
|
|
53
|
+
*
|
|
54
|
+
* export const p = typedProcedure<AppContext>();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const typedProcedure = createProcedure;
|
|
58
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/procedure/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,eAAe;IAK7B,sEAAsE;IACtE,OAAO,GAAG,EAAE,CAAC,SAAS,EAAY,CAAC;AACrC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC"}
|
package/dist/rest/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export type { RestAdapterOptions, RestPlugin, RestRoute } from './adapter.js';
|
|
|
7
7
|
export { createRoutesRegistrar, 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';
|
|
11
|
+
export { extractRoutes } from './routes.js';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/rest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAEL,qBAAqB,EAErB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAElB,IAAI,GACL,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAEL,qBAAqB,EAErB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAElB,IAAI,GACL,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/rest/index.js
CHANGED
|
@@ -12,4 +12,5 @@ generateRestRoutes, getRouteSummary, registerRestRoutes,
|
|
|
12
12
|
// Succinct API (preferred)
|
|
13
13
|
rest, } from './adapter.js';
|
|
14
14
|
export { buildNestedRestPath, buildRestPath, followsNamingConvention, inferResourceName, parseNamingConvention, } from './naming.js';
|
|
15
|
+
export { extractRoutes } from './routes.js';
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/rest/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,4BAA4B;AAC5B,OAAO;AACL,0BAA0B;AAC1B,qBAAqB;AACrB,qBAAqB;AACrB,kBAAkB,EAClB,eAAe,EACf,kBAAkB;AAClB,2BAA2B;AAC3B,IAAI,GACL,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,4BAA4B;AAC5B,OAAO;AACL,0BAA0B;AAC1B,qBAAqB;AACrB,qBAAqB;AACrB,kBAAkB,EAClB,eAAe,EACf,kBAAkB;AAClB,2BAA2B;AAC3B,IAAI,GACL,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route extraction utilities for VeloxTS client
|
|
3
|
+
*
|
|
4
|
+
* Extracts REST route mappings from procedure collections, enabling
|
|
5
|
+
* frontend clients to import route configuration directly from backend
|
|
6
|
+
* without manual duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module rest/routes
|
|
9
|
+
*/
|
|
10
|
+
import type { ProcedureCollection, ProcedureRecord } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Route map type - maps namespace -> procedure -> path
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* {
|
|
17
|
+
* auth: {
|
|
18
|
+
* createSession: '/auth/login',
|
|
19
|
+
* createAccount: '/auth/register',
|
|
20
|
+
* },
|
|
21
|
+
* users: {
|
|
22
|
+
* getProfile: '/users/me',
|
|
23
|
+
* },
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type RouteMap = Record<string, Record<string, string>>;
|
|
28
|
+
/**
|
|
29
|
+
* Extracts REST route mappings from procedure collections
|
|
30
|
+
*
|
|
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.
|
|
34
|
+
*
|
|
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.
|
|
38
|
+
*
|
|
39
|
+
* @param collections - Array of procedure collections to extract routes from
|
|
40
|
+
* @returns RouteMap object with namespace -> procedure -> path mappings
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Backend: api/index.ts
|
|
45
|
+
* import { extractRoutes } from '@veloxts/router';
|
|
46
|
+
* import { authProcedures } from './procedures/auth.js';
|
|
47
|
+
* import { userProcedures } from './procedures/users.js';
|
|
48
|
+
*
|
|
49
|
+
* // Export for frontend
|
|
50
|
+
* export const routes = extractRoutes([authProcedures, userProcedures]);
|
|
51
|
+
* export type AppRouter = typeof router;
|
|
52
|
+
*
|
|
53
|
+
* // Frontend: main.tsx
|
|
54
|
+
* import { routes } from '../../api/src/index.js';
|
|
55
|
+
* import type { AppRouter } from '../../api/src/index.js';
|
|
56
|
+
*
|
|
57
|
+
* <VeloxProvider<AppRouter> config={{ baseUrl: '/api', routes }}>
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function extractRoutes(collections: ProcedureCollection[]): RouteMap;
|
|
61
|
+
/**
|
|
62
|
+
* Type-level route extraction from a router type
|
|
63
|
+
*
|
|
64
|
+
* Extracts route paths from procedure restOverride metadata at the type level.
|
|
65
|
+
* This enables TypeScript to infer the exact route map shape from the router type.
|
|
66
|
+
*
|
|
67
|
+
* @template TRouter - The router type containing procedure collections
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* type MyRoutes = ExtractRoutesType<AppRouter>;
|
|
72
|
+
* // Infers: { auth: { createSession: '/auth/login', ... }, ... }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export type ExtractRoutesType<TRouter> = {
|
|
76
|
+
[K in keyof TRouter]: TRouter[K] extends ProcedureCollection<infer P> ? ExtractNamespaceRoutes<P> : never;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Helper type to extract routes from a procedure record
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
type ExtractNamespaceRoutes<P extends ProcedureRecord> = {
|
|
83
|
+
[PK in keyof P as P[PK] extends {
|
|
84
|
+
restOverride: {
|
|
85
|
+
path: string;
|
|
86
|
+
};
|
|
87
|
+
} ? PK : never]: P[PK] extends {
|
|
88
|
+
restOverride: {
|
|
89
|
+
path: infer Path;
|
|
90
|
+
};
|
|
91
|
+
} ? Path : never;
|
|
92
|
+
};
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/rest/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,mBAAmB,EAAE,GAAG,QAAQ,CAoB1E;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,IAAI;KACtC,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,mBAAmB,CAAC,MAAM,CAAC,CAAC,GACjE,sBAAsB,CAAC,CAAC,CAAC,GACzB,KAAK;CACV,CAAC;AAEF;;;GAGG;AACH,KAAK,sBAAsB,CAAC,CAAC,SAAS,eAAe,IAAI;KACtD,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS;QAAE,YAAY,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS;QAC9F,YAAY,EAAE;YAAE,IAAI,EAAE,MAAM,IAAI,CAAA;SAAE,CAAC;KACpC,GACG,IAAI,GACJ,KAAK;CACV,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route extraction utilities for VeloxTS client
|
|
3
|
+
*
|
|
4
|
+
* Extracts REST route mappings from procedure collections, enabling
|
|
5
|
+
* frontend clients to import route configuration directly from backend
|
|
6
|
+
* without manual duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module rest/routes
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Extracts REST route mappings from procedure collections
|
|
12
|
+
*
|
|
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.
|
|
16
|
+
*
|
|
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.
|
|
20
|
+
*
|
|
21
|
+
* @param collections - Array of procedure collections to extract routes from
|
|
22
|
+
* @returns RouteMap object with namespace -> procedure -> path mappings
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Backend: api/index.ts
|
|
27
|
+
* import { extractRoutes } from '@veloxts/router';
|
|
28
|
+
* import { authProcedures } from './procedures/auth.js';
|
|
29
|
+
* import { userProcedures } from './procedures/users.js';
|
|
30
|
+
*
|
|
31
|
+
* // Export for frontend
|
|
32
|
+
* export const routes = extractRoutes([authProcedures, userProcedures]);
|
|
33
|
+
* export type AppRouter = typeof router;
|
|
34
|
+
*
|
|
35
|
+
* // Frontend: main.tsx
|
|
36
|
+
* import { routes } from '../../api/src/index.js';
|
|
37
|
+
* import type { AppRouter } from '../../api/src/index.js';
|
|
38
|
+
*
|
|
39
|
+
* <VeloxProvider<AppRouter> config={{ baseUrl: '/api', routes }}>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function extractRoutes(collections) {
|
|
43
|
+
const routes = {};
|
|
44
|
+
for (const collection of collections) {
|
|
45
|
+
const namespaceRoutes = {};
|
|
46
|
+
for (const [procedureName, procedure] of Object.entries(collection.procedures)) {
|
|
47
|
+
// Only include procedures with explicit .rest() path overrides
|
|
48
|
+
if (procedure.restOverride?.path) {
|
|
49
|
+
namespaceRoutes[procedureName] = procedure.restOverride.path;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Only add namespace if it has custom routes
|
|
53
|
+
if (Object.keys(namespaceRoutes).length > 0) {
|
|
54
|
+
routes[collection.namespace] = namespaceRoutes;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return routes;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/rest/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,aAAa,CAAC,WAAkC;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,eAAe,GAA2B,EAAE,CAAC;QAEnD,KAAK,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/E,+DAA+D;YAC/D,IAAI,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;gBACjC,eAAe,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,6CAA6C;QAC7C,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming Convention Warning System
|
|
3
|
+
*
|
|
4
|
+
* Provides development-time warnings for procedure naming issues.
|
|
5
|
+
* Zero runtime cost in production.
|
|
6
|
+
*
|
|
7
|
+
* @module warnings
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Warning types for naming convention analysis
|
|
11
|
+
*/
|
|
12
|
+
export type NamingWarningType = 'no-convention' | 'type-mismatch' | 'case-mismatch' | 'similar-name';
|
|
13
|
+
/**
|
|
14
|
+
* A naming convention warning with actionable suggestion
|
|
15
|
+
*/
|
|
16
|
+
export interface NamingWarning {
|
|
17
|
+
/** The procedure name that triggered the warning */
|
|
18
|
+
procedureName: string;
|
|
19
|
+
/** The namespace containing the procedure */
|
|
20
|
+
namespace: string;
|
|
21
|
+
/** Type of naming issue detected */
|
|
22
|
+
type: NamingWarningType;
|
|
23
|
+
/** Human-readable warning message */
|
|
24
|
+
message: string;
|
|
25
|
+
/** Actionable suggestion for fixing the issue */
|
|
26
|
+
suggestion: string;
|
|
27
|
+
/** Suggested corrected name (if applicable) */
|
|
28
|
+
suggestedName?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Configuration for naming convention warnings
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Disable warnings for specific procedures
|
|
36
|
+
* defineProcedures('custom', procs, {
|
|
37
|
+
* warnings: { except: ['customAction'] }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Enable strict mode (warnings become errors)
|
|
41
|
+
* defineProcedures('api', procs, {
|
|
42
|
+
* warnings: { strict: true }
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Disable all warnings
|
|
46
|
+
* defineProcedures('legacy', procs, {
|
|
47
|
+
* warnings: { disabled: true }
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface WarningConfig {
|
|
52
|
+
/** Disable all naming warnings (default: false) */
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/** Treat warnings as errors - throw instead of warn (default: false) */
|
|
55
|
+
strict?: boolean;
|
|
56
|
+
/** Specific procedure names to exclude from warnings */
|
|
57
|
+
except?: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Warning configuration option with shorthand support
|
|
61
|
+
*
|
|
62
|
+
* Supports three forms:
|
|
63
|
+
* - `false` - Disable all warnings
|
|
64
|
+
* - `'strict'` - Treat warnings as errors (fail fast)
|
|
65
|
+
* - `{ ... }` - Full configuration object
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Shorthand: disable warnings
|
|
70
|
+
* defineProcedures('legacy', procs, { warnings: false });
|
|
71
|
+
*
|
|
72
|
+
* // Shorthand: strict mode (CI/CD)
|
|
73
|
+
* defineProcedures('api', procs, { warnings: 'strict' });
|
|
74
|
+
*
|
|
75
|
+
* // Full config
|
|
76
|
+
* defineProcedures('custom', procs, {
|
|
77
|
+
* warnings: { strict: true, except: ['customAction'] }
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export type WarningOption = WarningConfig | 'strict' | false;
|
|
82
|
+
/**
|
|
83
|
+
* Normalizes a warning option to a full config object
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
export declare function normalizeWarningOption(option: WarningOption | undefined): WarningConfig;
|
|
87
|
+
/**
|
|
88
|
+
* Check if running in development mode
|
|
89
|
+
*/
|
|
90
|
+
export declare function isDevelopment(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Analyzes a procedure name for naming convention issues
|
|
93
|
+
*
|
|
94
|
+
* Checks for:
|
|
95
|
+
* 1. Names matching a convention but with wrong procedure type
|
|
96
|
+
* 2. Names matching a convention but with wrong casing
|
|
97
|
+
* 3. Names similar to conventions (common alternatives)
|
|
98
|
+
* 4. Names that don't match any convention
|
|
99
|
+
*
|
|
100
|
+
* @param name - The procedure name to analyze
|
|
101
|
+
* @param type - The procedure type ('query' or 'mutation')
|
|
102
|
+
* @param namespace - The namespace containing the procedure
|
|
103
|
+
* @returns Warning if issue detected, undefined if name follows conventions
|
|
104
|
+
*/
|
|
105
|
+
export declare function analyzeNamingConvention(name: string, type: 'query' | 'mutation', namespace: string): NamingWarning | undefined;
|
|
106
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,eAAe,GACf,eAAe,GACf,eAAe,GACf,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,CAWvF;AAiDD;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,SAAS,EAAE,MAAM,GAChB,aAAa,GAAG,SAAS,CAsF3B"}
|
package/dist/warnings.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming Convention Warning System
|
|
3
|
+
*
|
|
4
|
+
* Provides development-time warnings for procedure naming issues.
|
|
5
|
+
* Zero runtime cost in production.
|
|
6
|
+
*
|
|
7
|
+
* @module warnings
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes a warning option to a full config object
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeWarningOption(option) {
|
|
14
|
+
if (option === undefined) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
if (option === false) {
|
|
18
|
+
return { disabled: true };
|
|
19
|
+
}
|
|
20
|
+
if (option === 'strict') {
|
|
21
|
+
return { strict: true };
|
|
22
|
+
}
|
|
23
|
+
return option;
|
|
24
|
+
}
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Constants
|
|
27
|
+
// ============================================================================
|
|
28
|
+
/**
|
|
29
|
+
* Known prefixes with their expected types and path patterns
|
|
30
|
+
*/
|
|
31
|
+
const CONVENTION_PREFIXES = [
|
|
32
|
+
{ prefix: 'get', type: 'query', hasId: true },
|
|
33
|
+
{ prefix: 'list', type: 'query', hasId: false },
|
|
34
|
+
{ prefix: 'find', type: 'query', hasId: false },
|
|
35
|
+
{ prefix: 'create', type: 'mutation', hasId: false },
|
|
36
|
+
{ prefix: 'add', type: 'mutation', hasId: false },
|
|
37
|
+
{ prefix: 'update', type: 'mutation', hasId: true },
|
|
38
|
+
{ prefix: 'edit', type: 'mutation', hasId: true },
|
|
39
|
+
{ prefix: 'patch', type: 'mutation', hasId: true },
|
|
40
|
+
{ prefix: 'delete', type: 'mutation', hasId: true },
|
|
41
|
+
{ prefix: 'remove', type: 'mutation', hasId: true },
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Map of common alternative prefixes to their standard equivalents
|
|
45
|
+
*/
|
|
46
|
+
const SIMILAR_PATTERNS = {
|
|
47
|
+
fetch: 'get or list',
|
|
48
|
+
retrieve: 'get',
|
|
49
|
+
obtain: 'get',
|
|
50
|
+
load: 'get or list',
|
|
51
|
+
read: 'get',
|
|
52
|
+
query: 'get, list, or find',
|
|
53
|
+
search: 'find',
|
|
54
|
+
new: 'create',
|
|
55
|
+
insert: 'create',
|
|
56
|
+
make: 'create',
|
|
57
|
+
modify: 'update or patch',
|
|
58
|
+
change: 'update or patch',
|
|
59
|
+
set: 'update',
|
|
60
|
+
destroy: 'delete',
|
|
61
|
+
drop: 'delete',
|
|
62
|
+
erase: 'delete',
|
|
63
|
+
trash: 'delete',
|
|
64
|
+
};
|
|
65
|
+
// ============================================================================
|
|
66
|
+
// Utility Functions
|
|
67
|
+
// ============================================================================
|
|
68
|
+
/**
|
|
69
|
+
* Check if running in development mode
|
|
70
|
+
*/
|
|
71
|
+
export function isDevelopment() {
|
|
72
|
+
return process.env.NODE_ENV !== 'production';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Capitalize the first letter of a string
|
|
76
|
+
*/
|
|
77
|
+
function capitalize(str) {
|
|
78
|
+
if (!str)
|
|
79
|
+
return str;
|
|
80
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
81
|
+
}
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Analysis Functions
|
|
84
|
+
// ============================================================================
|
|
85
|
+
/**
|
|
86
|
+
* Analyzes a procedure name for naming convention issues
|
|
87
|
+
*
|
|
88
|
+
* Checks for:
|
|
89
|
+
* 1. Names matching a convention but with wrong procedure type
|
|
90
|
+
* 2. Names matching a convention but with wrong casing
|
|
91
|
+
* 3. Names similar to conventions (common alternatives)
|
|
92
|
+
* 4. Names that don't match any convention
|
|
93
|
+
*
|
|
94
|
+
* @param name - The procedure name to analyze
|
|
95
|
+
* @param type - The procedure type ('query' or 'mutation')
|
|
96
|
+
* @param namespace - The namespace containing the procedure
|
|
97
|
+
* @returns Warning if issue detected, undefined if name follows conventions
|
|
98
|
+
*/
|
|
99
|
+
export function analyzeNamingConvention(name, type, namespace) {
|
|
100
|
+
// Check each known prefix
|
|
101
|
+
for (const conv of CONVENTION_PREFIXES) {
|
|
102
|
+
// Check if name starts with this prefix (case-insensitive check first)
|
|
103
|
+
if (!name.toLowerCase().startsWith(conv.prefix.toLowerCase())) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const afterPrefix = name.slice(conv.prefix.length);
|
|
107
|
+
// Build the strict pattern that the router uses
|
|
108
|
+
const correctPattern = new RegExp(`^${conv.prefix}[A-Z][a-zA-Z]*$`);
|
|
109
|
+
// Check if name matches the correct pattern
|
|
110
|
+
if (correctPattern.test(name)) {
|
|
111
|
+
// Name format is correct - check if type matches
|
|
112
|
+
if (conv.type !== type) {
|
|
113
|
+
return {
|
|
114
|
+
procedureName: name,
|
|
115
|
+
namespace,
|
|
116
|
+
type: 'type-mismatch',
|
|
117
|
+
message: `"${name}" uses "${conv.prefix}" prefix but is defined as ${type} (expected ${conv.type})`,
|
|
118
|
+
suggestion: `Change to .${conv.type}() or rename to match a ${type} pattern`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Everything is correct - no warning needed
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
// Name starts with prefix but doesn't match pattern - check why
|
|
125
|
+
// Case issue: prefix is correct but first letter after prefix is lowercase
|
|
126
|
+
if (afterPrefix.length > 0 && afterPrefix[0] === afterPrefix[0].toLowerCase()) {
|
|
127
|
+
const correctedName = conv.prefix + capitalize(afterPrefix);
|
|
128
|
+
return {
|
|
129
|
+
procedureName: name,
|
|
130
|
+
namespace,
|
|
131
|
+
type: 'case-mismatch',
|
|
132
|
+
message: `"${name}" looks like "${conv.prefix}" pattern but has wrong casing`,
|
|
133
|
+
suggestion: `Rename to "${correctedName}" for REST route generation`,
|
|
134
|
+
suggestedName: correctedName,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// Prefix itself has wrong case (e.g., "Get" instead of "get")
|
|
138
|
+
if (name.startsWith(conv.prefix.charAt(0).toUpperCase())) {
|
|
139
|
+
const correctedName = conv.prefix + afterPrefix;
|
|
140
|
+
return {
|
|
141
|
+
procedureName: name,
|
|
142
|
+
namespace,
|
|
143
|
+
type: 'case-mismatch',
|
|
144
|
+
message: `"${name}" has incorrect prefix casing`,
|
|
145
|
+
suggestion: `Rename to "${correctedName}" (prefix should be lowercase)`,
|
|
146
|
+
suggestedName: correctedName,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Name doesn't start with any known prefix - check for similar patterns
|
|
151
|
+
const lowerName = name.toLowerCase();
|
|
152
|
+
for (const [pattern, suggestion] of Object.entries(SIMILAR_PATTERNS)) {
|
|
153
|
+
if (lowerName.startsWith(pattern)) {
|
|
154
|
+
const afterPattern = name.slice(pattern.length);
|
|
155
|
+
const primarySuggestion = suggestion.split(' or ')[0].split(', ')[0];
|
|
156
|
+
const suggestedName = primarySuggestion + capitalize(afterPattern);
|
|
157
|
+
return {
|
|
158
|
+
procedureName: name,
|
|
159
|
+
namespace,
|
|
160
|
+
type: 'similar-name',
|
|
161
|
+
message: `"${name}" won't generate a REST route`,
|
|
162
|
+
suggestion: `Consider using "${suggestion}" prefix instead (e.g., "${suggestedName}")`,
|
|
163
|
+
suggestedName,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Name doesn't match any pattern - generic warning
|
|
168
|
+
return {
|
|
169
|
+
procedureName: name,
|
|
170
|
+
namespace,
|
|
171
|
+
type: 'no-convention',
|
|
172
|
+
message: `"${name}" doesn't match any naming convention`,
|
|
173
|
+
suggestion: 'Use a standard prefix (get, list, find, create, update, patch, delete) or add .rest() override',
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=warnings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuFH;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAiC;IACtE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAgB,EAAE,KAAK,EAAE,IAAI,EAAE;IACtD,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAgB,EAAE,KAAK,EAAE,KAAK,EAAE;IACxD,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAgB,EAAE,KAAK,EAAE,KAAK,EAAE;IACxD,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAmB,EAAE,KAAK,EAAE,KAAK,EAAE;IAC7D,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAmB,EAAE,KAAK,EAAE,KAAK,EAAE;IAC1D,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAmB,EAAE,KAAK,EAAE,IAAI,EAAE;IAC5D,EA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IAAI,IAAI,+BAA+B;gBAChD,UAAU,EAAE,mBAAmB,UAAU,4BAA4B,aAAa,IAAI;gBACtF,aAAa;aACd,CAAC;QACJ,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,OAAO;QACL,aAAa,EAAE,IAAI;QACnB,SAAS;QACT,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,IAAI,IAAI,uCAAuC;QACxD,UAAU,EACR,gGAAgG;KACnG,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/router",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Procedure definitions with tRPC and REST routing for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@trpc/server": "11.7.2",
|
|
29
29
|
"fastify": "5.6.2",
|
|
30
|
-
"@veloxts/
|
|
31
|
-
"@veloxts/
|
|
30
|
+
"@veloxts/core": "0.4.9",
|
|
31
|
+
"@veloxts/validation": "0.4.9"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@vitest/coverage-v8": "4.0.15",
|