ts-procedures 3.0.2 → 3.2.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.
- package/build/errors.d.ts +14 -3
- package/build/errors.js +40 -5
- package/build/errors.js.map +1 -1
- package/build/errors.test.js +82 -0
- package/build/errors.test.js.map +1 -1
- package/build/exports.d.ts +1 -0
- package/build/exports.js +1 -0
- package/build/exports.js.map +1 -1
- package/build/implementations/http/express-rpc/index.d.ts +6 -3
- package/build/implementations/http/express-rpc/index.js +18 -6
- package/build/implementations/http/express-rpc/index.js.map +1 -1
- package/build/implementations/http/express-rpc/index.test.js +153 -0
- package/build/implementations/http/express-rpc/index.test.js.map +1 -1
- package/build/implementations/http/express-rpc/types.d.ts +6 -23
- package/build/implementations/http/hono-rpc/index.d.ts +6 -3
- package/build/implementations/http/hono-rpc/index.js +18 -6
- package/build/implementations/http/hono-rpc/index.js.map +1 -1
- package/build/implementations/http/hono-rpc/index.test.js +153 -0
- package/build/implementations/http/hono-rpc/index.test.js.map +1 -1
- package/build/implementations/http/hono-rpc/types.d.ts +6 -23
- package/build/implementations/types.d.ts +32 -1
- package/build/index.js +15 -5
- package/build/index.js.map +1 -1
- package/build/index.test.js +102 -0
- package/build/index.test.js.map +1 -1
- package/build/schema/compute-schema.d.ts +3 -1
- package/build/schema/compute-schema.js +5 -2
- package/build/schema/compute-schema.js.map +1 -1
- package/build/stack-utils.d.ts +25 -0
- package/build/stack-utils.js +95 -0
- package/build/stack-utils.js.map +1 -0
- package/build/stack-utils.test.d.ts +1 -0
- package/build/stack-utils.test.js +80 -0
- package/build/stack-utils.test.js.map +1 -0
- package/package.json +1 -1
- package/src/errors.test.ts +110 -0
- package/src/errors.ts +49 -3
- package/src/exports.ts +1 -0
- package/src/implementations/http/express-rpc/index.test.ts +225 -0
- package/src/implementations/http/express-rpc/index.ts +39 -10
- package/src/implementations/http/express-rpc/types.ts +8 -25
- package/src/implementations/http/hono-rpc/README.md +82 -42
- package/src/implementations/http/hono-rpc/index.test.ts +225 -0
- package/src/implementations/http/hono-rpc/index.ts +40 -11
- package/src/implementations/http/hono-rpc/types.ts +8 -25
- package/src/implementations/types.ts +39 -1
- package/src/index.test.ts +126 -0
- package/src/index.ts +21 -5
- package/src/schema/compute-schema.ts +5 -0
- package/src/stack-utils.test.ts +94 -0
- package/src/stack-utils.ts +129 -0
package/build/errors.d.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import { TSchemaValidationError } from './schema/parser.js';
|
|
2
|
+
import { DefinitionInfo, DefinitionLocation } from './stack-utils.js';
|
|
2
3
|
export declare class ProcedureError extends Error {
|
|
3
4
|
readonly procedureName: string;
|
|
4
5
|
readonly message: string;
|
|
5
6
|
readonly meta?: object | undefined;
|
|
6
7
|
cause?: unknown;
|
|
7
|
-
|
|
8
|
+
readonly definedAt?: DefinitionLocation;
|
|
9
|
+
readonly definitionStack?: string;
|
|
10
|
+
constructor(procedureName: string, message: string, meta?: object | undefined, definitionInfo?: DefinitionInfo);
|
|
11
|
+
/**
|
|
12
|
+
* Returns a formatted string showing where the procedure was defined.
|
|
13
|
+
*/
|
|
14
|
+
getDefinitionLocation(): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Enhances the error stack with definition location information.
|
|
17
|
+
*/
|
|
18
|
+
private enhanceStack;
|
|
8
19
|
}
|
|
9
20
|
export declare class ProcedureValidationError extends ProcedureError {
|
|
10
21
|
readonly procedureName: string;
|
|
11
22
|
readonly errors?: TSchemaValidationError[] | undefined;
|
|
12
|
-
constructor(procedureName: string, message: string, errors?: TSchemaValidationError[] | undefined);
|
|
23
|
+
constructor(procedureName: string, message: string, errors?: TSchemaValidationError[] | undefined, definitionInfo?: DefinitionInfo);
|
|
13
24
|
}
|
|
14
25
|
export declare class ProcedureRegistrationError extends ProcedureError {
|
|
15
26
|
readonly procedureName: string;
|
|
16
|
-
constructor(procedureName: string, message: string);
|
|
27
|
+
constructor(procedureName: string, message: string, definitionInfo?: DefinitionInfo);
|
|
17
28
|
}
|
package/build/errors.js
CHANGED
|
@@ -1,23 +1,56 @@
|
|
|
1
|
+
import { formatDefinitionInfo } from './stack-utils.js';
|
|
1
2
|
export class ProcedureError extends Error {
|
|
2
3
|
procedureName;
|
|
3
4
|
message;
|
|
4
5
|
meta;
|
|
5
6
|
cause;
|
|
6
|
-
|
|
7
|
+
definedAt;
|
|
8
|
+
definitionStack;
|
|
9
|
+
constructor(procedureName, message, meta,
|
|
10
|
+
// Used for error stack trace details
|
|
11
|
+
definitionInfo) {
|
|
7
12
|
super(message);
|
|
8
13
|
this.procedureName = procedureName;
|
|
9
14
|
this.message = message;
|
|
10
15
|
this.meta = meta;
|
|
11
16
|
this.name = 'ProcedureError';
|
|
17
|
+
if (definitionInfo) {
|
|
18
|
+
this.definedAt = definitionInfo.definedAt;
|
|
19
|
+
this.definitionStack = definitionInfo.definitionStack;
|
|
20
|
+
this.enhanceStack();
|
|
21
|
+
}
|
|
12
22
|
// https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/
|
|
13
23
|
Object.setPrototypeOf(this, ProcedureError.prototype);
|
|
14
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a formatted string showing where the procedure was defined.
|
|
27
|
+
*/
|
|
28
|
+
getDefinitionLocation() {
|
|
29
|
+
if (!this.definedAt) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return `${this.definedAt.file}:${this.definedAt.line}:${this.definedAt.column}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Enhances the error stack with definition location information.
|
|
36
|
+
*/
|
|
37
|
+
enhanceStack() {
|
|
38
|
+
if (!this.stack || !this.definedAt) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const definitionSection = formatDefinitionInfo({ definedAt: this.definedAt, definitionStack: this.definitionStack }, this.procedureName);
|
|
42
|
+
if (definitionSection) {
|
|
43
|
+
this.stack = this.stack + definitionSection;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
15
46
|
}
|
|
16
47
|
export class ProcedureValidationError extends ProcedureError {
|
|
17
48
|
procedureName;
|
|
18
49
|
errors;
|
|
19
|
-
constructor(procedureName, message, errors
|
|
20
|
-
|
|
50
|
+
constructor(procedureName, message, errors,
|
|
51
|
+
// Used for error stack trace details
|
|
52
|
+
definitionInfo) {
|
|
53
|
+
super(procedureName, message, undefined, definitionInfo);
|
|
21
54
|
this.procedureName = procedureName;
|
|
22
55
|
this.errors = errors;
|
|
23
56
|
this.name = 'ProcedureValidationError';
|
|
@@ -27,8 +60,10 @@ export class ProcedureValidationError extends ProcedureError {
|
|
|
27
60
|
}
|
|
28
61
|
export class ProcedureRegistrationError extends ProcedureError {
|
|
29
62
|
procedureName;
|
|
30
|
-
constructor(procedureName, message
|
|
31
|
-
|
|
63
|
+
constructor(procedureName, message,
|
|
64
|
+
// Used for error stack trace details
|
|
65
|
+
definitionInfo) {
|
|
66
|
+
super(procedureName, message, undefined, definitionInfo);
|
|
32
67
|
this.procedureName = procedureName;
|
|
33
68
|
this.name = 'ProcedureRegistrationError';
|
|
34
69
|
// https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/
|
package/build/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAE3F,MAAM,OAAO,cAAe,SAAQ,KAAK;IAM5B;IACA;IACA;IAPX,KAAK,CAAU;IACN,SAAS,CAAqB;IAC9B,eAAe,CAAS;IAEjC,YACW,aAAqB,EACrB,OAAe,EACf,IAAa;IACtB,qCAAqC;IACrC,cAA+B;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAA;QANL,kBAAa,GAAb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E,SAAS,EAAE,cAAc,CAAC,CAAA;QAN/C,kBAAa,GAAb,aAAa,CAAQ;QAErB,WAAM,GAAN,MAAM,CAA2B;QAK1C,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;QAEtC,mGAAmG;QACnG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAA;IACjE,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,cAAc;IAEjD;IADX,YACW,aAAqB,EAC9B,OAAe;IACf,qCAAqC;IACrC,cAA+B;QAE/B,KAAK,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAA;QAL/C,kBAAa,GAAb,aAAa,CAAQ;QAM9B,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QAExC,mGAAmG;QACnG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAA;IACnE,CAAC;CACF"}
|
package/build/errors.test.js
CHANGED
|
@@ -37,4 +37,86 @@ describe('Error Classes', () => {
|
|
|
37
37
|
expect(registrationErr.procedureName).toBe('Proc3');
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
|
+
describe('Error Classes - Definition Info', () => {
|
|
41
|
+
const mockDefinitionInfo = {
|
|
42
|
+
definedAt: {
|
|
43
|
+
file: '/app/procedures/user.ts',
|
|
44
|
+
line: 25,
|
|
45
|
+
column: 3,
|
|
46
|
+
raw: 'at Object.<anonymous> (/app/procedures/user.ts:25:3)',
|
|
47
|
+
},
|
|
48
|
+
definitionStack: 'Error\n at Object.<anonymous> (/app/procedures/user.ts:25:3)',
|
|
49
|
+
};
|
|
50
|
+
test('ProcedureError includes definedAt when provided', () => {
|
|
51
|
+
const err = new ProcedureError('TestProc', 'Something failed', undefined, mockDefinitionInfo);
|
|
52
|
+
expect(err.definedAt).toBeDefined();
|
|
53
|
+
expect(err.definedAt?.file).toBe('/app/procedures/user.ts');
|
|
54
|
+
expect(err.definedAt?.line).toBe(25);
|
|
55
|
+
expect(err.definedAt?.column).toBe(3);
|
|
56
|
+
});
|
|
57
|
+
test('ProcedureError includes definitionStack when provided', () => {
|
|
58
|
+
const err = new ProcedureError('TestProc', 'Something failed', undefined, mockDefinitionInfo);
|
|
59
|
+
expect(err.definitionStack).toBeDefined();
|
|
60
|
+
expect(err.definitionStack).toContain('/app/procedures/user.ts');
|
|
61
|
+
});
|
|
62
|
+
test('ProcedureError works without definitionInfo (backward compat)', () => {
|
|
63
|
+
const err = new ProcedureError('TestProc', 'Something failed', { code: 123 });
|
|
64
|
+
expect(err.definedAt).toBeUndefined();
|
|
65
|
+
expect(err.definitionStack).toBeUndefined();
|
|
66
|
+
expect(err.procedureName).toBe('TestProc');
|
|
67
|
+
expect(err.message).toBe('Something failed');
|
|
68
|
+
expect(err.meta).toEqual({ code: 123 });
|
|
69
|
+
});
|
|
70
|
+
test('ProcedureValidationError includes definedAt when provided', () => {
|
|
71
|
+
const err = new ProcedureValidationError('TestProc', 'Validation failed', [], mockDefinitionInfo);
|
|
72
|
+
expect(err.definedAt).toBeDefined();
|
|
73
|
+
expect(err.definedAt?.file).toBe('/app/procedures/user.ts');
|
|
74
|
+
expect(err.definedAt?.line).toBe(25);
|
|
75
|
+
});
|
|
76
|
+
test('ProcedureValidationError works without definitionInfo (backward compat)', () => {
|
|
77
|
+
const err = new ProcedureValidationError('TestProc', 'Validation failed', []);
|
|
78
|
+
expect(err.definedAt).toBeUndefined();
|
|
79
|
+
expect(err.definitionStack).toBeUndefined();
|
|
80
|
+
expect(err.name).toBe('ProcedureValidationError');
|
|
81
|
+
});
|
|
82
|
+
test('ProcedureRegistrationError includes definedAt when provided', () => {
|
|
83
|
+
const err = new ProcedureRegistrationError('TestProc', 'Registration failed', mockDefinitionInfo);
|
|
84
|
+
expect(err.definedAt).toBeDefined();
|
|
85
|
+
expect(err.definedAt?.file).toBe('/app/procedures/user.ts');
|
|
86
|
+
});
|
|
87
|
+
test('ProcedureRegistrationError works without definitionInfo (backward compat)', () => {
|
|
88
|
+
const err = new ProcedureRegistrationError('TestProc', 'Registration failed');
|
|
89
|
+
expect(err.definedAt).toBeUndefined();
|
|
90
|
+
expect(err.definitionStack).toBeUndefined();
|
|
91
|
+
expect(err.name).toBe('ProcedureRegistrationError');
|
|
92
|
+
});
|
|
93
|
+
test('getDefinitionLocation returns formatted location string', () => {
|
|
94
|
+
const err = new ProcedureError('TestProc', 'Something failed', undefined, mockDefinitionInfo);
|
|
95
|
+
const location = err.getDefinitionLocation();
|
|
96
|
+
expect(location).toBe('/app/procedures/user.ts:25:3');
|
|
97
|
+
});
|
|
98
|
+
test('getDefinitionLocation returns undefined when no definedAt', () => {
|
|
99
|
+
const err = new ProcedureError('TestProc', 'Something failed');
|
|
100
|
+
const location = err.getDefinitionLocation();
|
|
101
|
+
expect(location).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
test('enhanced stack contains definition location', () => {
|
|
104
|
+
const err = new ProcedureError('TestProc', 'Something failed', undefined, mockDefinitionInfo);
|
|
105
|
+
expect(err.stack).toContain('--- Procedure "TestProc" defined at ---');
|
|
106
|
+
expect(err.stack).toContain('/app/procedures/user.ts:25:3');
|
|
107
|
+
});
|
|
108
|
+
test('stack is not modified when no definitionInfo', () => {
|
|
109
|
+
const err = new ProcedureError('TestProc', 'Something failed');
|
|
110
|
+
expect(err.stack).toBeDefined();
|
|
111
|
+
expect(err.stack).not.toContain('--- Procedure');
|
|
112
|
+
});
|
|
113
|
+
test('all error types enhance stack with definition location', () => {
|
|
114
|
+
const baseErr = new ProcedureError('Proc1', 'message', undefined, mockDefinitionInfo);
|
|
115
|
+
const validationErr = new ProcedureValidationError('Proc2', 'message', [], mockDefinitionInfo);
|
|
116
|
+
const registrationErr = new ProcedureRegistrationError('Proc3', 'message', mockDefinitionInfo);
|
|
117
|
+
expect(baseErr.stack).toContain('--- Procedure "Proc1" defined at ---');
|
|
118
|
+
expect(validationErr.stack).toContain('--- Procedure "Proc2" defined at ---');
|
|
119
|
+
expect(registrationErr.stack).toContain('--- Procedure "Proc3" defined at ---');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
40
122
|
//# sourceMappingURL=errors.test.js.map
|
package/build/errors.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../src/errors.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../src/errors.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AAGpB,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;QACjD,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;QAE7E,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACvC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC1C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAC5C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;QACvC,MAAM,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,IAAI,CA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ClE,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAA;QACrF,MAAM,aAAa,GAAG,IAAI,wBAAwB,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAA;QAC9F,MAAM,eAAe,GAAG,IAAI,0BAA0B,CAAC,OAAO,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAA;QAE9F,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,sCAAsC,CAAC,CAAA;QACvE,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,sCAAsC,CAAC,CAAA;QAC7E,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,sCAAsC,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/build/exports.d.ts
CHANGED
package/build/exports.js
CHANGED
package/build/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oBAAoB,CAAA;AAClC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oBAAoB,CAAA;AAClC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { TProcedureRegistration } from '../../../index.js';
|
|
3
|
-
import { RPCConfig, RPCHttpRouteDoc } from '../../types.js';
|
|
4
|
-
import { ExtractContext, ProceduresFactory } from './types.js';
|
|
3
|
+
import { ExtractConfig, ExtractContext, ProceduresFactory, RPCConfig, RPCHttpRouteDoc } from '../../types.js';
|
|
5
4
|
export type { RPCConfig, RPCHttpRouteDoc };
|
|
6
5
|
export type ExpressRPCAppBuilderConfig = {
|
|
7
6
|
/**
|
|
@@ -76,8 +75,12 @@ export declare class ExpressRPCAppBuilder {
|
|
|
76
75
|
* @param factory - The procedure factory created by Procedures<Context, RPCConfig>()
|
|
77
76
|
* @param factoryContext - The context for procedure handlers. Can be a direct value,
|
|
78
77
|
* a sync function (req) => Context, or an async function (req) => Promise<Context>
|
|
78
|
+
* @param extendProcedureDoc - A custom function to extend the generated RPC route documentation for each procedure.
|
|
79
79
|
*/
|
|
80
|
-
register<TFactory extends ProceduresFactory>(factory: TFactory, factoryContext: ExtractContext<TFactory> | ((req: express.Request) => ExtractContext<TFactory> | Promise<ExtractContext<TFactory>>)
|
|
80
|
+
register<TFactory extends ProceduresFactory>(factory: TFactory, factoryContext: ExtractContext<TFactory> | ((req: express.Request) => ExtractContext<TFactory> | Promise<ExtractContext<TFactory>>), extendProcedureDoc?: (params: {
|
|
81
|
+
base: RPCHttpRouteDoc;
|
|
82
|
+
procedure: TProcedureRegistration<any, ExtractConfig<TFactory>>;
|
|
83
|
+
}) => Record<string, any>): this;
|
|
81
84
|
/**
|
|
82
85
|
* Builds and returns the Express application with registered RPC routes.
|
|
83
86
|
* @return express.Application
|
|
@@ -85,9 +85,10 @@ export class ExpressRPCAppBuilder {
|
|
|
85
85
|
* @param factory - The procedure factory created by Procedures<Context, RPCConfig>()
|
|
86
86
|
* @param factoryContext - The context for procedure handlers. Can be a direct value,
|
|
87
87
|
* a sync function (req) => Context, or an async function (req) => Promise<Context>
|
|
88
|
+
* @param extendProcedureDoc - A custom function to extend the generated RPC route documentation for each procedure.
|
|
88
89
|
*/
|
|
89
|
-
register(factory, factoryContext) {
|
|
90
|
-
this.factories.push({ factory, factoryContext });
|
|
90
|
+
register(factory, factoryContext, extendProcedureDoc) {
|
|
91
|
+
this.factories.push({ factory, factoryContext, extendProcedureDoc });
|
|
91
92
|
return this;
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
@@ -95,9 +96,9 @@ export class ExpressRPCAppBuilder {
|
|
|
95
96
|
* @return express.Application
|
|
96
97
|
*/
|
|
97
98
|
build() {
|
|
98
|
-
this.factories.forEach(({ factory, factoryContext }) => {
|
|
99
|
+
this.factories.forEach(({ factory, factoryContext, extendProcedureDoc }) => {
|
|
99
100
|
factory.getProcedures().map((procedure) => {
|
|
100
|
-
const route = this.buildRpcHttpRouteDoc(procedure);
|
|
101
|
+
const route = this.buildRpcHttpRouteDoc(procedure, extendProcedureDoc);
|
|
101
102
|
this._docs.push(route);
|
|
102
103
|
this._app[route.method](route.path, async (req, res) => {
|
|
103
104
|
try {
|
|
@@ -135,7 +136,7 @@ export class ExpressRPCAppBuilder {
|
|
|
135
136
|
* Generates the RPC HTTP route for the given procedure.
|
|
136
137
|
* @param procedure
|
|
137
138
|
*/
|
|
138
|
-
buildRpcHttpRouteDoc(procedure) {
|
|
139
|
+
buildRpcHttpRouteDoc(procedure, extendProcedureDoc) {
|
|
139
140
|
const { config } = procedure;
|
|
140
141
|
const path = ExpressRPCAppBuilder.makeRPCHttpRoutePath({
|
|
141
142
|
name: procedure.name,
|
|
@@ -150,11 +151,22 @@ export class ExpressRPCAppBuilder {
|
|
|
150
151
|
if (config.schema?.returnType) {
|
|
151
152
|
jsonSchema.response = config.schema.returnType;
|
|
152
153
|
}
|
|
153
|
-
|
|
154
|
+
const base = {
|
|
155
|
+
name: procedure.name,
|
|
156
|
+
version: config.version,
|
|
157
|
+
scope: config.scope,
|
|
154
158
|
path,
|
|
155
159
|
method,
|
|
156
160
|
jsonSchema,
|
|
157
161
|
};
|
|
162
|
+
let extendedDoc = {};
|
|
163
|
+
if (extendProcedureDoc) {
|
|
164
|
+
extendedDoc = extendProcedureDoc({ base, procedure });
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...extendedDoc,
|
|
168
|
+
...base,
|
|
169
|
+
};
|
|
158
170
|
}
|
|
159
171
|
}
|
|
160
172
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +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;
|
|
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;AAS7C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAoC7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,oBAAoB;IAMV;IALrB;;;;OAIG;IACH,YAAqB,MAAmC;QAAnC,WAAM,GAAN,MAAM,CAA6B;QACtD,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,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CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAA;QAChD,CAAC;QAED,MAAM,IAAI,GAAG;YACX,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI;YACJ,MAAM;YACN,UAAU;SACX,CAAA;QACD,IAAI,WAAW,GAAW,EAAE,CAAA;QAE5B,IAAI,kBAAkB,EAAE,CAAC;YACvB,WAAW,GAAG,kBAAkB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QACvD,CAAC;QAED,OAAO;YACL,GAAG,WAAW;YACd,GAAG,IAAI;SACR,CAAA;IACH,CAAC;CACF"}
|
|
@@ -452,6 +452,159 @@ describe('ExpressRPCAppBuilder', () => {
|
|
|
452
452
|
});
|
|
453
453
|
});
|
|
454
454
|
// --------------------------------------------------------------------------
|
|
455
|
+
// extendProcedureDoc Tests
|
|
456
|
+
// --------------------------------------------------------------------------
|
|
457
|
+
describe('extendProcedureDoc', () => {
|
|
458
|
+
test('adds custom properties to generated documentation', () => {
|
|
459
|
+
const builder = new ExpressRPCAppBuilder();
|
|
460
|
+
const RPC = Procedures();
|
|
461
|
+
RPC.Create('GetUser', { scope: 'users', version: 1 }, async () => ({ name: 'test' }));
|
|
462
|
+
builder.register(RPC, () => ({}), ({ base, procedure }) => ({
|
|
463
|
+
summary: `Get user endpoint`,
|
|
464
|
+
tags: ['users'],
|
|
465
|
+
operationId: procedure.name,
|
|
466
|
+
}));
|
|
467
|
+
builder.build();
|
|
468
|
+
const doc = builder.docs[0];
|
|
469
|
+
expect(doc).toHaveProperty('summary', 'Get user endpoint');
|
|
470
|
+
expect(doc).toHaveProperty('tags', ['users']);
|
|
471
|
+
expect(doc).toHaveProperty('operationId', 'GetUser');
|
|
472
|
+
});
|
|
473
|
+
test('receives correct base and procedure parameters', () => {
|
|
474
|
+
const extendFn = vi.fn(() => ({}));
|
|
475
|
+
const builder = new ExpressRPCAppBuilder();
|
|
476
|
+
const RPC = Procedures();
|
|
477
|
+
const paramsSchema = v.object({ id: v.string() });
|
|
478
|
+
RPC.Create('GetItem', { scope: 'items', version: 2, schema: { params: paramsSchema } }, async () => ({}));
|
|
479
|
+
builder.register(RPC, () => ({}), extendFn);
|
|
480
|
+
builder.build();
|
|
481
|
+
expect(extendFn).toHaveBeenCalledTimes(1);
|
|
482
|
+
const callArg = extendFn.mock.calls[0][0];
|
|
483
|
+
// Verify base properties
|
|
484
|
+
expect(callArg.base).toHaveProperty('name', 'GetItem');
|
|
485
|
+
expect(callArg.base).toHaveProperty('version', 2);
|
|
486
|
+
expect(callArg.base).toHaveProperty('scope', 'items');
|
|
487
|
+
expect(callArg.base).toHaveProperty('path', '/items/get-item/2');
|
|
488
|
+
expect(callArg.base).toHaveProperty('method', 'post');
|
|
489
|
+
expect(callArg.base.jsonSchema).toHaveProperty('body');
|
|
490
|
+
// Verify procedure properties
|
|
491
|
+
expect(callArg.procedure).toHaveProperty('name', 'GetItem');
|
|
492
|
+
expect(callArg.procedure).toHaveProperty('handler');
|
|
493
|
+
expect(callArg.procedure.config).toHaveProperty('scope', 'items');
|
|
494
|
+
expect(callArg.procedure.config).toHaveProperty('version', 2);
|
|
495
|
+
});
|
|
496
|
+
test('base properties take precedence over extended properties', () => {
|
|
497
|
+
const builder = new ExpressRPCAppBuilder();
|
|
498
|
+
const RPC = Procedures();
|
|
499
|
+
RPC.Create('Test', { scope: 'test', version: 1 }, async () => ({}));
|
|
500
|
+
builder.register(RPC, () => ({}), () => ({
|
|
501
|
+
name: 'OverriddenName',
|
|
502
|
+
path: '/overridden/path',
|
|
503
|
+
method: 'get',
|
|
504
|
+
customField: 'custom-value',
|
|
505
|
+
}));
|
|
506
|
+
builder.build();
|
|
507
|
+
const doc = builder.docs[0];
|
|
508
|
+
// Base properties should NOT be overridden
|
|
509
|
+
expect(doc.name).toBe('Test');
|
|
510
|
+
expect(doc.path).toBe('/test/test/1');
|
|
511
|
+
expect(doc.method).toBe('post');
|
|
512
|
+
// Custom field should be present
|
|
513
|
+
expect(doc).toHaveProperty('customField', 'custom-value');
|
|
514
|
+
});
|
|
515
|
+
test('different factories can have different extendProcedureDoc functions', () => {
|
|
516
|
+
const builder = new ExpressRPCAppBuilder();
|
|
517
|
+
const PublicRPC = Procedures();
|
|
518
|
+
const AdminRPC = Procedures();
|
|
519
|
+
PublicRPC.Create('GetPublic', { scope: 'public', version: 1 }, async () => ({}));
|
|
520
|
+
AdminRPC.Create('GetAdmin', { scope: 'admin', version: 1 }, async () => ({}));
|
|
521
|
+
builder
|
|
522
|
+
.register(PublicRPC, () => ({}), () => ({
|
|
523
|
+
security: [],
|
|
524
|
+
tags: ['public'],
|
|
525
|
+
}))
|
|
526
|
+
.register(AdminRPC, () => ({}), () => ({
|
|
527
|
+
security: [{ bearerAuth: [] }],
|
|
528
|
+
tags: ['admin'],
|
|
529
|
+
}));
|
|
530
|
+
builder.build();
|
|
531
|
+
const publicDoc = builder.docs.find((d) => d.name === 'GetPublic');
|
|
532
|
+
const adminDoc = builder.docs.find((d) => d.name === 'GetAdmin');
|
|
533
|
+
expect(publicDoc).toHaveProperty('security', []);
|
|
534
|
+
expect(publicDoc).toHaveProperty('tags', ['public']);
|
|
535
|
+
expect(adminDoc).toHaveProperty('security', [{ bearerAuth: [] }]);
|
|
536
|
+
expect(adminDoc).toHaveProperty('tags', ['admin']);
|
|
537
|
+
});
|
|
538
|
+
test('extendProcedureDoc is called for each procedure in factory', () => {
|
|
539
|
+
const extendFn = vi.fn(() => ({ extended: true }));
|
|
540
|
+
const builder = new ExpressRPCAppBuilder();
|
|
541
|
+
const RPC = Procedures();
|
|
542
|
+
RPC.Create('Method1', { scope: 'm1', version: 1 }, async () => ({}));
|
|
543
|
+
RPC.Create('Method2', { scope: 'm2', version: 1 }, async () => ({}));
|
|
544
|
+
RPC.Create('Method3', { scope: 'm3', version: 1 }, async () => ({}));
|
|
545
|
+
builder.register(RPC, () => ({}), extendFn);
|
|
546
|
+
builder.build();
|
|
547
|
+
expect(extendFn).toHaveBeenCalledTimes(3);
|
|
548
|
+
const procedureNames = extendFn.mock.calls.map((call) => call[0].procedure.name);
|
|
549
|
+
expect(procedureNames).toContain('Method1');
|
|
550
|
+
expect(procedureNames).toContain('Method2');
|
|
551
|
+
expect(procedureNames).toContain('Method3');
|
|
552
|
+
});
|
|
553
|
+
test('not providing extendProcedureDoc results in base documentation only', () => {
|
|
554
|
+
const builder = new ExpressRPCAppBuilder();
|
|
555
|
+
const RPC = Procedures();
|
|
556
|
+
RPC.Create('Test', { scope: 'test', version: 1 }, async () => ({}));
|
|
557
|
+
builder.register(RPC, () => ({})); // No extendProcedureDoc
|
|
558
|
+
builder.build();
|
|
559
|
+
const doc = builder.docs[0];
|
|
560
|
+
expect(doc.name).toBe('Test');
|
|
561
|
+
expect(doc.path).toBe('/test/test/1');
|
|
562
|
+
expect(doc.method).toBe('post');
|
|
563
|
+
// Should not have any extra properties
|
|
564
|
+
expect(Object.keys(doc)).toEqual(['name', 'version', 'scope', 'path', 'method', 'jsonSchema']);
|
|
565
|
+
});
|
|
566
|
+
test('extendProcedureDoc can access procedure config for conditional logic', () => {
|
|
567
|
+
const builder = new ExpressRPCAppBuilder();
|
|
568
|
+
const RPC = Procedures();
|
|
569
|
+
RPC.Create('PublicEndpoint', { scope: 'public', version: 1 }, async () => ({}));
|
|
570
|
+
RPC.Create('PrivateEndpoint', { scope: 'private', version: 1 }, async () => ({}));
|
|
571
|
+
builder.register(RPC, () => ({}), ({ procedure }) => ({
|
|
572
|
+
isPublic: procedure.config.scope === 'public',
|
|
573
|
+
description: `This is a ${procedure.config.scope} endpoint`,
|
|
574
|
+
}));
|
|
575
|
+
builder.build();
|
|
576
|
+
const publicDoc = builder.docs.find((d) => d.name === 'PublicEndpoint');
|
|
577
|
+
const privateDoc = builder.docs.find((d) => d.name === 'PrivateEndpoint');
|
|
578
|
+
expect(publicDoc).toHaveProperty('isPublic', true);
|
|
579
|
+
expect(publicDoc).toHaveProperty('description', 'This is a public endpoint');
|
|
580
|
+
expect(privateDoc).toHaveProperty('isPublic', false);
|
|
581
|
+
expect(privateDoc).toHaveProperty('description', 'This is a private endpoint');
|
|
582
|
+
});
|
|
583
|
+
test('extendProcedureDoc can use base jsonSchema for OpenAPI-style docs', () => {
|
|
584
|
+
const builder = new ExpressRPCAppBuilder();
|
|
585
|
+
const RPC = Procedures();
|
|
586
|
+
const paramsSchema = v.object({ userId: v.string() });
|
|
587
|
+
const returnSchema = v.object({ name: v.string(), email: v.string() });
|
|
588
|
+
RPC.Create('GetUser', { scope: 'users', version: 1, schema: { params: paramsSchema, returnType: returnSchema } }, async () => ({ name: 'test', email: 'test@example.com' }));
|
|
589
|
+
builder.register(RPC, () => ({}), ({ base }) => ({
|
|
590
|
+
requestBody: base.jsonSchema.body
|
|
591
|
+
? { content: { 'application/json': { schema: base.jsonSchema.body } } }
|
|
592
|
+
: undefined,
|
|
593
|
+
responses: {
|
|
594
|
+
200: base.jsonSchema.response
|
|
595
|
+
? { content: { 'application/json': { schema: base.jsonSchema.response } } }
|
|
596
|
+
: { description: 'Success' },
|
|
597
|
+
},
|
|
598
|
+
}));
|
|
599
|
+
builder.build();
|
|
600
|
+
const doc = builder.docs[0];
|
|
601
|
+
expect(doc).toHaveProperty('requestBody');
|
|
602
|
+
expect(doc.requestBody).toHaveProperty('content');
|
|
603
|
+
expect(doc).toHaveProperty('responses');
|
|
604
|
+
expect(doc.responses).toHaveProperty('200');
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
// --------------------------------------------------------------------------
|
|
455
608
|
// Integration Test
|
|
456
609
|
// --------------------------------------------------------------------------
|
|
457
610
|
describe('integration', () => {
|