ts-procedures 1.1.0 → 2.0.0

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.
Files changed (39) hide show
  1. package/README.md +3 -3
  2. package/build/implementations/http/client/index.d.ts +1 -0
  3. package/build/implementations/http/client/index.js +2 -0
  4. package/build/implementations/http/client/index.js.map +1 -0
  5. package/build/implementations/http/express/index.d.ts +2 -1
  6. package/build/implementations/http/express/index.js.map +1 -1
  7. package/build/implementations/http/express/types.d.ts +17 -0
  8. package/build/implementations/http/express/types.js +2 -0
  9. package/build/implementations/http/express/types.js.map +1 -0
  10. package/build/implementations/http/express-rpc/index.d.ts +82 -0
  11. package/build/implementations/http/express-rpc/index.js +140 -0
  12. package/build/implementations/http/express-rpc/index.js.map +1 -0
  13. package/build/implementations/http/express-rpc/index.test.d.ts +1 -0
  14. package/build/implementations/http/express-rpc/index.test.js +445 -0
  15. package/build/implementations/http/express-rpc/index.test.js.map +1 -0
  16. package/build/implementations/http/express-rpc/types.d.ts +28 -0
  17. package/build/implementations/http/express-rpc/types.js +2 -0
  18. package/build/implementations/http/express-rpc/types.js.map +1 -0
  19. package/build/implementations/types.d.ts +17 -0
  20. package/build/implementations/types.js +2 -0
  21. package/build/implementations/types.js.map +1 -0
  22. package/build/schema/parser.js +2 -1
  23. package/build/schema/parser.js.map +1 -1
  24. package/package.json +13 -7
  25. package/src/implementations/http/express-rpc/README.md +321 -0
  26. package/src/implementations/http/express-rpc/index.test.ts +614 -0
  27. package/src/implementations/http/express-rpc/index.ts +180 -0
  28. package/src/implementations/http/express-rpc/types.ts +29 -0
  29. package/src/implementations/types.ts +20 -0
  30. package/src/schema/parser.ts +5 -4
  31. package/src/schema/types.ts +0 -1
  32. package/src/implementations/http/express/README.md +0 -351
  33. package/src/implementations/http/express/example/factories.ts +0 -25
  34. package/src/implementations/http/express/example/procedures/auth.ts +0 -24
  35. package/src/implementations/http/express/example/procedures/users.ts +0 -32
  36. package/src/implementations/http/express/example/server.test.ts +0 -133
  37. package/src/implementations/http/express/example/server.ts +0 -67
  38. package/src/implementations/http/express/index.test.ts +0 -526
  39. package/src/implementations/http/express/index.ts +0 -108
package/README.md CHANGED
@@ -336,8 +336,8 @@ Create('ListUsers', { schema: { params: Type.Object({}) } }, async () => {})
336
336
  const procedures = getProcedures()
337
337
 
338
338
  // Generate OpenAPI spec
339
- for (const [name, { config }] of procedures) {
340
- console.log(`${name}:`, config.schema)
339
+ for (const config of procedures) {
340
+ console.log(`${config.name}:`, config.schema)
341
341
  }
342
342
  ```
343
343
 
@@ -413,7 +413,7 @@ Creates a procedure factory.
413
413
 
414
414
  **Returns:**
415
415
  - `Create` - Function to define procedures
416
- - `getProcedures()` - Returns `Map` of all registered procedures
416
+ - `getProcedures()` - Returns `Array` of all registered procedures
417
417
 
418
418
  ### Create(name, config, handler)
419
419
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/implementations/http/client/index.ts"],"names":[],"mappings":""}
@@ -1,5 +1,6 @@
1
1
  import express from 'express';
2
2
  import { TProcedureRegistration } from '../../../index.js';
3
+ import { ExpressHttpRouteHelpersContext } from './types.js';
3
4
  /**
4
5
  * Maps path parameters from Express route to an object
5
6
  *
@@ -20,7 +21,7 @@ export declare function mapPathParamsToObject(path: string, url: string): Record
20
21
  */
21
22
  export declare function registerExpressRoutes<ProceduresContext>(app: express.Application, callbacks: {
22
23
  /** Get procedure factory context for handler */
23
- getContext: (req: express.Request, res: express.Response) => Promise<ProceduresContext>;
24
+ getContext: (req: express.Request, res: express.Response) => Promise<ProceduresContext & ExpressHttpRouteHelpersContext>;
24
25
  /** Optional error handler for procedure handler errors */
25
26
  onHandlerError?: (error: Error, req: express.Request, res: express.Response) => void;
26
27
  /** Optional validation error handler */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","source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AAC,OAAc,EAAE,SAAS,CAAC,CAAA;gBAEvD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,SAAS,CAAC,cAAc,EAAE,CAAC;oBAC7B,SAAS,CAAC,cAAc,CAAC,KAAc,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;oBAClD,OAAM;gBACR,CAAC;gBACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC,CAAA;YAC3D,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type express from 'express';
2
+ export interface ExpressHttpRouteHelpersContext {
3
+ req: {
4
+ getHeaders: () => Record<string, string | string[]>;
5
+ getHeader: (header: string) => string | string[] | undefined;
6
+ getQueryParams: () => Record<string, any>;
7
+ getQueryParam: (param: string) => any;
8
+ getPathParams: () => Record<string, string>;
9
+ getPathParam: (param: string) => string;
10
+ };
11
+ res: {
12
+ setCookie: (name: string, value: string, options?: express.CookieOptions) => void;
13
+ setHeader: (header: string, value: string | string[]) => void;
14
+ getHeader: (header: string) => string | string[] | undefined;
15
+ setStatus: (statusCode: number) => void;
16
+ };
17
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/implementations/http/express/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,82 @@
1
+ import express from 'express';
2
+ import { TProcedureRegistration } from '../../../index.js';
3
+ import { RPCConfig, RPCHttpRouteDoc } from '../../types.js';
4
+ import { ExtractContext, ProceduresFactory } from './types.js';
5
+ export type { RPCConfig, RPCHttpRouteDoc };
6
+ /**
7
+ * Builder class for creating an Express application with RPC routes.
8
+ *
9
+ * Usage:
10
+ * const PublicRPC = Procedures<PublicRPCContext, RPCConfig>()
11
+ * const ProtectedRPC = Procedures<ProtectedRPCContext, RPCConfig>()
12
+ *
13
+ * const rpcApp = new ExpressRPCAppBuilder()
14
+ * .register(PublicRPC, (req): Promise<PublicRPCContext> => { /* context resolution logic * / })
15
+ * .register(ProtectedRPC, (req): Promise<ProtectedRPCContext> => { /* context resolution logic * / })
16
+ * .build();
17
+ *
18
+ * const app = rpcApp.app; // Express application
19
+ * const docs = rpcApp.docs; // RPC route documentation
20
+ */
21
+ export declare class ExpressRPCAppBuilder {
22
+ readonly config?: {
23
+ /**
24
+ * An existing Express application instance to use.
25
+ * When provided, ensure to set up necessary middleware (e.g., json/body parser) beforehand.
26
+ * If not provided, a new instance will be created.
27
+ */
28
+ app?: express.Express;
29
+ onRequestStart?: (req: express.Request) => void;
30
+ onRequestEnd?: (req: express.Request, res: express.Response) => void;
31
+ onSuccess?: (procedure: TProcedureRegistration, req: express.Request, res: express.Response) => void;
32
+ error?: (procedure: TProcedureRegistration, req: express.Request, res: express.Response, error: Error) => void;
33
+ } | undefined;
34
+ /**
35
+ * Constructor for ExpressRPCAppBuilder.
36
+ *
37
+ * @param config
38
+ */
39
+ constructor(config?: {
40
+ /**
41
+ * An existing Express application instance to use.
42
+ * When provided, ensure to set up necessary middleware (e.g., json/body parser) beforehand.
43
+ * If not provided, a new instance will be created.
44
+ */
45
+ app?: express.Express;
46
+ onRequestStart?: (req: express.Request) => void;
47
+ onRequestEnd?: (req: express.Request, res: express.Response) => void;
48
+ onSuccess?: (procedure: TProcedureRegistration, req: express.Request, res: express.Response) => void;
49
+ error?: (procedure: TProcedureRegistration, req: express.Request, res: express.Response, error: Error) => void;
50
+ } | undefined);
51
+ private factories;
52
+ private _app;
53
+ private _docs;
54
+ get app(): express.Express;
55
+ get docs(): RPCHttpRouteDoc[];
56
+ /**
57
+ * Registers a procedure factory with its context resolver.
58
+ * @param factory
59
+ * @param contextResolver
60
+ */
61
+ register<TFactory extends ProceduresFactory>(factory: TFactory, contextResolver: (req: express.Request) => ExtractContext<TFactory>): this;
62
+ /**
63
+ * Builds and returns the Express application with registered RPC routes.
64
+ * @return express.Application
65
+ */
66
+ build(): express.Application;
67
+ /**
68
+ * Generates the RPC HTTP route for the given procedure.
69
+ * @param procedure
70
+ */
71
+ buildRpcHttpRouteDoc(procedure: TProcedureRegistration<any, RPCConfig>): RPCHttpRouteDoc;
72
+ /**
73
+ * Generates the RPC route path based on the RPC configuration.
74
+ * The RPCConfig name can be a string or an array of strings to form nested paths.
75
+ *
76
+ * Example
77
+ * name: ['string', 'string-string', 'string']
78
+ * path: /rpc/string/string-string/string/version
79
+ * @param config
80
+ */
81
+ makeRPCHttpRoutePath(config: RPCConfig): string;
82
+ }
@@ -0,0 +1,140 @@
1
+ import express from 'express';
2
+ import { kebabCase } from 'es-toolkit/string';
3
+ import { castArray } from 'es-toolkit/compat';
4
+ /**
5
+ * Builder class for creating an Express application with RPC routes.
6
+ *
7
+ * Usage:
8
+ * const PublicRPC = Procedures<PublicRPCContext, RPCConfig>()
9
+ * const ProtectedRPC = Procedures<ProtectedRPCContext, RPCConfig>()
10
+ *
11
+ * const rpcApp = new ExpressRPCAppBuilder()
12
+ * .register(PublicRPC, (req): Promise<PublicRPCContext> => { /* context resolution logic * / })
13
+ * .register(ProtectedRPC, (req): Promise<ProtectedRPCContext> => { /* context resolution logic * / })
14
+ * .build();
15
+ *
16
+ * const app = rpcApp.app; // Express application
17
+ * const docs = rpcApp.docs; // RPC route documentation
18
+ */
19
+ export class ExpressRPCAppBuilder {
20
+ config;
21
+ /**
22
+ * Constructor for ExpressRPCAppBuilder.
23
+ *
24
+ * @param config
25
+ */
26
+ constructor(config) {
27
+ this.config = config;
28
+ if (config?.app) {
29
+ this._app = config.app;
30
+ }
31
+ else {
32
+ // Default middleware if no app is provided
33
+ this._app.use(express.json());
34
+ }
35
+ if (config?.onRequestStart) {
36
+ this._app.use((req, res, next) => {
37
+ config.onRequestStart(req);
38
+ next();
39
+ });
40
+ }
41
+ if (config?.onRequestEnd) {
42
+ this._app.use((req, res, next) => {
43
+ res.on('finish', () => {
44
+ config.onRequestEnd(req, res);
45
+ });
46
+ next();
47
+ });
48
+ }
49
+ }
50
+ factories = [];
51
+ _app = express();
52
+ _docs = [];
53
+ get app() {
54
+ return this._app;
55
+ }
56
+ get docs() {
57
+ return this._docs;
58
+ }
59
+ /**
60
+ * Registers a procedure factory with its context resolver.
61
+ * @param factory
62
+ * @param contextResolver
63
+ */
64
+ register(factory, contextResolver) {
65
+ this.factories.push({ factory, contextResolver });
66
+ return this;
67
+ }
68
+ /**
69
+ * Builds and returns the Express application with registered RPC routes.
70
+ * @return express.Application
71
+ */
72
+ build() {
73
+ this.factories.forEach(({ factory, contextResolver }) => {
74
+ factory.getProcedures().map((procedure) => {
75
+ const route = this.buildRpcHttpRouteDoc(procedure);
76
+ this._docs.push(route);
77
+ this._app[route.method](route.path, async (req, res) => {
78
+ try {
79
+ res.json(await procedure.handler(contextResolver(req), req.body));
80
+ if (this.config?.onSuccess) {
81
+ this.config.onSuccess(procedure, req, res);
82
+ }
83
+ // if status not set, set to 200
84
+ if (!res.status) {
85
+ res.status(200);
86
+ }
87
+ }
88
+ catch (error) {
89
+ if (this.config?.error) {
90
+ this.config.error(procedure, req, res, error);
91
+ return;
92
+ }
93
+ if (!res.status) {
94
+ res.status(500);
95
+ }
96
+ // if no res.json set, set default error message
97
+ if (!res.headersSent) {
98
+ res.json({ error: error.message });
99
+ }
100
+ }
101
+ });
102
+ });
103
+ });
104
+ return this._app;
105
+ }
106
+ /**
107
+ * Generates the RPC HTTP route for the given procedure.
108
+ * @param procedure
109
+ */
110
+ buildRpcHttpRouteDoc(procedure) {
111
+ const { config } = procedure;
112
+ const path = this.makeRPCHttpRoutePath(config);
113
+ const method = 'post'; // RPCs use POST method
114
+ const jsonSchema = {};
115
+ if (config.schema?.params) {
116
+ jsonSchema.body = config.schema.params;
117
+ }
118
+ if (config.schema?.returnType) {
119
+ jsonSchema.response = config.schema.returnType;
120
+ }
121
+ return {
122
+ path,
123
+ method,
124
+ jsonSchema,
125
+ };
126
+ }
127
+ /**
128
+ * Generates the RPC route path based on the RPC configuration.
129
+ * The RPCConfig name can be a string or an array of strings to form nested paths.
130
+ *
131
+ * Example
132
+ * name: ['string', 'string-string', 'string']
133
+ * path: /rpc/string/string-string/string/version
134
+ * @param config
135
+ */
136
+ makeRPCHttpRoutePath(config) {
137
+ return `/rpc/${castArray(config.name).map(kebabCase).join('/')}/${String(config.version).trim()}`;
138
+ }
139
+ }
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/implementations/http/express-rpc/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAI7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,oBAAoB;IAOpB;IANX;;;;OAIG;IACH,YACW,MAoBR;QApBQ,WAAM,GAAN,MAAM,CAoBd;QAED,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAA;QACxB,CAAC;aAAM,CAAC;YACN,2CAA2C;YAC3C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/B,CAAC;QAED,IAAI,MAAM,EAAE,cAAc,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;gBAC/B,MAAM,CAAC,cAAe,CAAC,GAAG,CAAC,CAAA;gBAC3B,IAAI,EAAE,CAAA;YACR,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,MAAM,EAAE,YAAY,E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