@zdavison/nestjs-rpc-toolkit 0.1.5 → 0.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/dist/bin/bootstrap.js +0 -0
- package/dist/codecs/index.d.ts +106 -0
- package/dist/codecs/index.d.ts.map +1 -0
- package/dist/codecs/index.js +146 -0
- package/dist/codecs/index.js.map +1 -0
- package/dist/generators/rpc-types-generator.d.ts +28 -13
- package/dist/generators/rpc-types-generator.d.ts.map +1 -1
- package/dist/generators/rpc-types-generator.js +296 -363
- package/dist/generators/rpc-types-generator.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/rpc/rpc-client.d.ts +62 -2
- package/dist/rpc/rpc-client.d.ts.map +1 -1
- package/dist/rpc/rpc-client.js +66 -5
- package/dist/rpc/rpc-client.js.map +1 -1
- package/dist/types/serializable.d.ts +122 -8
- package/dist/types/serializable.d.ts.map +1 -1
- package/dist/types/serializable.js +158 -0
- package/dist/types/serializable.js.map +1 -1
- package/package.json +7 -7
- package/dist/utils/package-manager.utils.d.ts +0 -7
- package/dist/utils/package-manager.utils.d.ts.map +0 -1
- package/dist/utils/package-manager.utils.js +0 -78
- package/dist/utils/package-manager.utils.js.map +0 -1
package/dist/bin/bootstrap.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC Codec System
|
|
3
|
+
*
|
|
4
|
+
* Codecs handle serialization/deserialization of types that aren't natively JSON-serializable.
|
|
5
|
+
* Built-in codecs handle Date. Users can register custom codecs for their own types.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Built-in Date codec is auto-registered
|
|
10
|
+
* const registry = new RpcCodecRegistry();
|
|
11
|
+
*
|
|
12
|
+
* // Add custom codec
|
|
13
|
+
* registry.register({
|
|
14
|
+
* name: 'BigInt',
|
|
15
|
+
* canEncode: (value): value is bigint => typeof value === 'bigint',
|
|
16
|
+
* encode: (value) => value.toString(),
|
|
17
|
+
* decode: (value) => BigInt(value),
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A codec transforms values between runtime types and wire-safe formats.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam T - The runtime type (e.g., Date, BigInt)
|
|
25
|
+
* @typeParam W - The wire type (e.g., string)
|
|
26
|
+
*/
|
|
27
|
+
export interface RpcCodec<T = unknown, W = unknown> {
|
|
28
|
+
/** Unique name for this codec, used in metadata (e.g., 'Date', 'BigInt') */
|
|
29
|
+
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* Check if this codec can encode a value.
|
|
32
|
+
* Used for runtime detection during encoding.
|
|
33
|
+
*/
|
|
34
|
+
canEncode(value: unknown): value is T;
|
|
35
|
+
/**
|
|
36
|
+
* Encode a value for wire transport.
|
|
37
|
+
* @param value - The runtime value to encode
|
|
38
|
+
* @returns The wire-safe representation
|
|
39
|
+
*/
|
|
40
|
+
encode(value: T): W;
|
|
41
|
+
/**
|
|
42
|
+
* Decode a value from wire format.
|
|
43
|
+
* @param value - The wire value to decode
|
|
44
|
+
* @returns The runtime value
|
|
45
|
+
*/
|
|
46
|
+
decode(value: W): T;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Metadata that maps type fields to their codec names.
|
|
50
|
+
* Generated by the RPC type generator.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const RpcCodecFields = {
|
|
55
|
+
* User: { createdAt: 'Date', updatedAt: 'Date' },
|
|
56
|
+
* Transaction: { amount: 'BigInt' },
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export type RpcCodecMetadata = Record<string, Record<string, string>>;
|
|
61
|
+
/**
|
|
62
|
+
* Built-in Date codec.
|
|
63
|
+
* Transforms Date <-> ISO 8601 string.
|
|
64
|
+
*/
|
|
65
|
+
export declare const dateCodec: RpcCodec<Date, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Registry for RPC codecs.
|
|
68
|
+
* Handles encoding/decoding using registered codecs.
|
|
69
|
+
*/
|
|
70
|
+
export declare class RpcCodecRegistry {
|
|
71
|
+
private codecs;
|
|
72
|
+
constructor(codecs?: RpcCodec[]);
|
|
73
|
+
/**
|
|
74
|
+
* Register a codec.
|
|
75
|
+
* @param codec - The codec to register
|
|
76
|
+
*/
|
|
77
|
+
register(codec: RpcCodec): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get a codec by name.
|
|
80
|
+
* @param name - The codec name
|
|
81
|
+
*/
|
|
82
|
+
get(name: string): RpcCodec | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Recursively encode a value, transforming any codec-handled types.
|
|
85
|
+
* Uses runtime detection (canEncode) to find matching codecs.
|
|
86
|
+
*
|
|
87
|
+
* @param value - The value to encode
|
|
88
|
+
* @returns The encoded value safe for wire transport
|
|
89
|
+
*/
|
|
90
|
+
encode<T>(value: T): T;
|
|
91
|
+
/**
|
|
92
|
+
* Recursively decode a value, transforming fields based on metadata.
|
|
93
|
+
* Uses metadata to know which fields to decode with which codec.
|
|
94
|
+
*
|
|
95
|
+
* Metadata format:
|
|
96
|
+
* - `{ field: 'Date' }` - field uses the Date codec
|
|
97
|
+
* - `{ field: '@TypeName' }` - field is a nested type with codec fields (@ prefix)
|
|
98
|
+
*
|
|
99
|
+
* @param value - The wire value to decode
|
|
100
|
+
* @param metadata - Maps type names to field codec mappings
|
|
101
|
+
* @param typeName - The type name to look up in metadata
|
|
102
|
+
* @returns The decoded value with runtime types restored
|
|
103
|
+
*/
|
|
104
|
+
decode<T>(value: T, metadata: RpcCodecMetadata, typeName?: string): T;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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ec System
|
|
4
|
+
*
|
|
5
|
+
* Codecs handle serialization/deserialization of types that aren't natively JSON-serializable.
|
|
6
|
+
* Built-in codecs handle Date. Users can register custom codecs for their own types.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Built-in Date codec is auto-registered
|
|
11
|
+
* const registry = new RpcCodecRegistry();
|
|
12
|
+
*
|
|
13
|
+
* // Add custom codec
|
|
14
|
+
* registry.register({
|
|
15
|
+
* name: 'BigInt',
|
|
16
|
+
* canEncode: (value): value is bigint => typeof value === 'bigint',
|
|
17
|
+
* encode: (value) => value.toString(),
|
|
18
|
+
* decode: (value) => BigInt(value),
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.RpcCodecRegistry = exports.dateCodec = void 0;
|
|
24
|
+
/**
|
|
25
|
+
* Built-in Date codec.
|
|
26
|
+
* Transforms Date <-> ISO 8601 string.
|
|
27
|
+
*/
|
|
28
|
+
exports.dateCodec = {
|
|
29
|
+
name: 'Date',
|
|
30
|
+
canEncode: (value) => value instanceof Date,
|
|
31
|
+
encode: (value) => value.toISOString(),
|
|
32
|
+
decode: (value) => new Date(value),
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Registry for RPC codecs.
|
|
36
|
+
* Handles encoding/decoding using registered codecs.
|
|
37
|
+
*/
|
|
38
|
+
class RpcCodecRegistry {
|
|
39
|
+
constructor(codecs = [exports.dateCodec]) {
|
|
40
|
+
this.codecs = new Map();
|
|
41
|
+
codecs.forEach((codec) => this.register(codec));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register a codec.
|
|
45
|
+
* @param codec - The codec to register
|
|
46
|
+
*/
|
|
47
|
+
register(codec) {
|
|
48
|
+
this.codecs.set(codec.name, codec);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get a codec by name.
|
|
52
|
+
* @param name - The codec name
|
|
53
|
+
*/
|
|
54
|
+
get(name) {
|
|
55
|
+
return this.codecs.get(name);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Recursively encode a value, transforming any codec-handled types.
|
|
59
|
+
* Uses runtime detection (canEncode) to find matching codecs.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to encode
|
|
62
|
+
* @returns The encoded value safe for wire transport
|
|
63
|
+
*/
|
|
64
|
+
encode(value) {
|
|
65
|
+
if (value === null || value === undefined) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
// Check if any codec can encode this value
|
|
69
|
+
for (const codec of this.codecs.values()) {
|
|
70
|
+
if (codec.canEncode(value)) {
|
|
71
|
+
return codec.encode(value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Not a primitive, recurse into objects/arrays
|
|
75
|
+
if (typeof value !== 'object') {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
return value.map((item) => this.encode(item));
|
|
80
|
+
}
|
|
81
|
+
const result = {};
|
|
82
|
+
for (const key of Object.keys(value)) {
|
|
83
|
+
result[key] = this.encode(value[key]);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Recursively decode a value, transforming fields based on metadata.
|
|
89
|
+
* Uses metadata to know which fields to decode with which codec.
|
|
90
|
+
*
|
|
91
|
+
* Metadata format:
|
|
92
|
+
* - `{ field: 'Date' }` - field uses the Date codec
|
|
93
|
+
* - `{ field: '@TypeName' }` - field is a nested type with codec fields (@ prefix)
|
|
94
|
+
*
|
|
95
|
+
* @param value - The wire value to decode
|
|
96
|
+
* @param metadata - Maps type names to field codec mappings
|
|
97
|
+
* @param typeName - The type name to look up in metadata
|
|
98
|
+
* @returns The decoded value with runtime types restored
|
|
99
|
+
*/
|
|
100
|
+
decode(value, metadata, typeName) {
|
|
101
|
+
if (value === null || value === undefined) {
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
if (typeof value !== 'object') {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(value)) {
|
|
108
|
+
return value.map((item) => this.decode(item, metadata, typeName));
|
|
109
|
+
}
|
|
110
|
+
// Get field mappings for this type
|
|
111
|
+
const fieldMappings = typeName ? metadata[typeName] : undefined;
|
|
112
|
+
const result = {};
|
|
113
|
+
for (const key of Object.keys(value)) {
|
|
114
|
+
const val = value[key];
|
|
115
|
+
const codecName = fieldMappings?.[key];
|
|
116
|
+
if (codecName && val !== null && val !== undefined) {
|
|
117
|
+
// Check if this is a nested type reference (prefixed with @)
|
|
118
|
+
if (codecName.startsWith('@')) {
|
|
119
|
+
const nestedTypeName = codecName.slice(1);
|
|
120
|
+
result[key] = this.decode(val, metadata, nestedTypeName);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// This field should be decoded with a specific codec
|
|
124
|
+
const codec = this.codecs.get(codecName);
|
|
125
|
+
if (codec) {
|
|
126
|
+
result[key] = codec.decode(val);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.warn(`RPC Codec '${codecName}' not found for field '${key}'`);
|
|
130
|
+
result[key] = val;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (typeof val === 'object' && val !== null) {
|
|
135
|
+
// Recurse into nested objects without specific type info
|
|
136
|
+
result[key] = this.decode(val, metadata, undefined);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result[key] = val;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.RpcCodecRegistry = RpcCodecRegistry;
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codecs/index.ts"],"names":[],"mappings":";A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are class RpcTypesGenerator {
|
|
|
17
17
|
private packageFiles;
|
|
18
18
|
private expandedPackages;
|
|
19
19
|
private fileToModuleMap;
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
20
|
+
/** Maps type names to their codec fields (field name -> codec name) */
|
|
21
|
+
private codecFields;
|
|
22
|
+
/** Pending nested type checks to resolve after all types are processed */
|
|
23
|
+
private pendingNestedTypes;
|
|
23
24
|
constructor(options: GeneratorOptions);
|
|
24
25
|
private expandPackagePaths;
|
|
25
26
|
private initializePackageProject;
|
|
26
27
|
private findTsConfigForPackage;
|
|
27
28
|
private loadConfig;
|
|
28
29
|
generate(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve pending nested type references.
|
|
32
|
+
* For each type, check if any of its fields reference other types that have codec fields.
|
|
33
|
+
* If so, add a nested type reference (prefixed with @) to the codec fields.
|
|
34
|
+
*/
|
|
35
|
+
private resolveNestedTypeReferences;
|
|
29
36
|
private scanForRpcMethods;
|
|
30
37
|
private extractTypesFromFile;
|
|
31
|
-
private extractImports;
|
|
32
|
-
private resolvePackageVersion;
|
|
33
38
|
private extractInterface;
|
|
34
39
|
private extractClassAsInterface;
|
|
40
|
+
/**
|
|
41
|
+
* Built-in codec mappings: source type -> { codecName, wireType }
|
|
42
|
+
* Extensible: add more entries to support additional types.
|
|
43
|
+
*/
|
|
44
|
+
private readonly codecMappings;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a type needs a codec and return codec info.
|
|
47
|
+
* Returns undefined if the type doesn't need a codec.
|
|
48
|
+
*/
|
|
49
|
+
private getCodecForType;
|
|
35
50
|
private extractTypeAlias;
|
|
36
51
|
private extractEnum;
|
|
37
52
|
private isRelevantInterface;
|
|
38
53
|
private getModuleForFile;
|
|
39
54
|
private isInternalType;
|
|
40
|
-
private collectExternalImports;
|
|
41
55
|
private processMethod;
|
|
42
56
|
private extractJsDoc;
|
|
43
57
|
private generateTypesFile;
|
|
44
58
|
private generateModuleTypesFile;
|
|
59
|
+
/** Generate codec metadata for types belonging to this module only */
|
|
60
|
+
private generateCodecFieldsMetadata;
|
|
61
|
+
/** Generate function metadata for RPC patterns (params and returns) */
|
|
62
|
+
private generateRpcFunctionInfo;
|
|
63
|
+
/** Extract the main type name from a type string (e.g., "User" from "Promise<User>") */
|
|
64
|
+
private extractMainTypeName;
|
|
65
|
+
/** Generate imports and re-exports for codec fields from module files */
|
|
66
|
+
private generateCodecFieldReExports;
|
|
45
67
|
private generateMainTypesFile;
|
|
46
|
-
private updateOutputPackageJson;
|
|
47
|
-
private findPackageJsonForOutput;
|
|
48
68
|
private generateParamsType;
|
|
49
69
|
private cleanReturnType;
|
|
50
70
|
private cleanTypeString;
|
|
@@ -53,10 +73,5 @@ export declare class RpcTypesGenerator {
|
|
|
53
73
|
private isBuiltInType;
|
|
54
74
|
private generateCommonTypeExports;
|
|
55
75
|
private generateAllRpcMethodsType;
|
|
56
|
-
/**
|
|
57
|
-
* Topologically sort types so that dependencies come before dependents.
|
|
58
|
-
* This ensures type aliases and interfaces are defined before they are used.
|
|
59
|
-
*/
|
|
60
|
-
private topologicalSortTypes;
|
|
61
76
|
}
|
|
62
77
|
//# sourceMappingURL=rpc-types-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types-generator.d.ts","sourceRoot":"","sources":["../../src/generators/rpc-types-generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc-types-generator.d.ts","sourceRoot":"","sources":["../../src/generators/rpc-types-generator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,8FAA8F;IAC9F,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AA2BD,qBAAa,iBAAiB;IAchB,OAAO,CAAC,OAAO;IAb3B,OAAO,CAAC,Q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