@jdevel/tnest 0.0.2 → 0.0.3
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/README.md +38 -46
- package/dist/__tests__/constants.spec.d.ts +1 -0
- package/dist/__tests__/constants.spec.js +21 -0
- package/dist/__tests__/constants.spec.js.map +1 -0
- package/dist/__tests__/tnest-module.spec.d.ts +1 -0
- package/dist/__tests__/tnest-module.spec.js +88 -0
- package/dist/__tests__/tnest-module.spec.js.map +1 -0
- package/dist/client/__tests__/typed-client-factory.spec.d.ts +1 -0
- package/dist/client/__tests__/typed-client-factory.spec.js +35 -0
- package/dist/client/__tests__/typed-client-factory.spec.js.map +1 -0
- package/dist/client/__tests__/typed-client-types.spec.d.ts +1 -0
- package/dist/client/__tests__/typed-client-types.spec.js +18 -0
- package/dist/client/__tests__/typed-client-types.spec.js.map +1 -0
- package/dist/client/__tests__/typed-client.spec.d.ts +1 -0
- package/dist/client/__tests__/typed-client.spec.js +59 -0
- package/dist/client/__tests__/typed-client.spec.js.map +1 -0
- package/dist/contracts/__tests__/contract-types.spec.d.ts +1 -0
- package/dist/contracts/__tests__/contract-types.spec.js +91 -0
- package/dist/contracts/__tests__/contract-types.spec.js.map +1 -0
- package/dist/contracts/__tests__/define-helpers.spec.d.ts +1 -0
- package/dist/contracts/__tests__/define-helpers.spec.js +52 -0
- package/dist/contracts/__tests__/define-helpers.spec.js.map +1 -0
- package/dist/contracts/define-helpers.js.map +1 -1
- package/dist/handlers/__tests__/handler-types.spec.d.ts +1 -0
- package/dist/handlers/__tests__/handler-types.spec.js +17 -0
- package/dist/handlers/__tests__/handler-types.spec.js.map +1 -0
- package/dist/handlers/__tests__/typed-event-pattern.spec.d.ts +1 -0
- package/dist/handlers/__tests__/typed-event-pattern.spec.js +33 -0
- package/dist/handlers/__tests__/typed-event-pattern.spec.js.map +1 -0
- package/dist/handlers/__tests__/typed-message-pattern.spec.d.ts +1 -0
- package/dist/handlers/__tests__/typed-message-pattern.spec.js +49 -0
- package/dist/handlers/__tests__/typed-message-pattern.spec.js.map +1 -0
- package/dist/handlers/typed-event-pattern.decorator.js.map +1 -1
- package/dist/handlers/typed-message-pattern.decorator.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/module-options.d.ts +1 -0
- package/dist/serialization/__tests__/default-serializer.spec.d.ts +1 -0
- package/dist/serialization/__tests__/default-serializer.spec.js +32 -0
- package/dist/serialization/__tests__/default-serializer.spec.js.map +1 -0
- package/dist/testing/__tests__/mock-typed-client.spec.d.ts +1 -0
- package/dist/testing/__tests__/mock-typed-client.spec.js +70 -0
- package/dist/testing/__tests__/mock-typed-client.spec.js.map +1 -0
- package/dist/testing/__tests__/test-contract-module.spec.d.ts +1 -0
- package/dist/testing/__tests__/test-contract-module.spec.js +30 -0
- package/dist/testing/__tests__/test-contract-module.spec.js.map +1 -0
- package/dist/testing/mock-typed-client.js.map +1 -1
- package/dist/tnest.module.d.ts +1 -0
- package/dist/tnest.module.js +21 -20
- package/dist/tnest.module.js.map +1 -1
- package/dist/validation/__tests__/validate-contract.spec.d.ts +1 -0
- package/dist/validation/__tests__/validate-contract.spec.js +102 -0
- package/dist/validation/__tests__/validate-contract.spec.js.map +1 -0
- package/dist/validation/validate-contract.decorator.js.map +1 -1
- package/package.json +27 -4
package/README.md
CHANGED
|
@@ -30,11 +30,11 @@ npm install @nestjs/common @nestjs/microservices reflect-metadata rxjs
|
|
|
30
30
|
|
|
31
31
|
Contracts describe the messages exchanged between services. There are three kinds:
|
|
32
32
|
|
|
33
|
-
| Type
|
|
34
|
-
|
|
35
|
-
| `Command` | Write operation (request/response) | Yes
|
|
36
|
-
| `Query`
|
|
37
|
-
| `Event`
|
|
33
|
+
| Type | Purpose | Has response? |
|
|
34
|
+
| --------- | ---------------------------------- | ------------- |
|
|
35
|
+
| `Command` | Write operation (request/response) | Yes |
|
|
36
|
+
| `Query` | Read operation (request/response) | Yes |
|
|
37
|
+
| `Event` | Notification (fire-and-forget) | No |
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
// contracts/user.contracts.ts
|
|
@@ -120,9 +120,7 @@ export class OrderService {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
async createOrder(userId: string) {
|
|
123
|
-
const user = await firstValueFrom(
|
|
124
|
-
this.users.send('user.get', { id: userId }),
|
|
125
|
-
);
|
|
123
|
+
const user = await firstValueFrom(this.users.send('user.get', { id: userId }));
|
|
126
124
|
|
|
127
125
|
this.users.emit('user.created', {
|
|
128
126
|
userId: user.id,
|
|
@@ -194,9 +192,7 @@ mock.setResponse('user.get', {
|
|
|
194
192
|
const user = await firstValueFrom(mock.send('user.get', { id: '42' }));
|
|
195
193
|
// user.id === '42'
|
|
196
194
|
|
|
197
|
-
expect(mock.messages).toEqual([
|
|
198
|
-
{ type: 'send', pattern: 'user.get', payload: { id: '42' } },
|
|
199
|
-
]);
|
|
195
|
+
expect(mock.messages).toEqual([{ type: 'send', pattern: 'user.get', payload: { id: '42' } }]);
|
|
200
196
|
```
|
|
201
197
|
|
|
202
198
|
For integration tests, `TestContractModule` swaps real clients for mocks:
|
|
@@ -209,11 +205,7 @@ import type { UserContracts } from './contracts/user.contracts';
|
|
|
209
205
|
const mock = new MockTypedClient<UserContracts>();
|
|
210
206
|
|
|
211
207
|
const module = await Test.createTestingModule({
|
|
212
|
-
imports: [
|
|
213
|
-
TestContractModule.register([
|
|
214
|
-
{ name: 'USER_SERVICE', mock },
|
|
215
|
-
]),
|
|
216
|
-
],
|
|
208
|
+
imports: [TestContractModule.register([{ name: 'USER_SERVICE', mock }])],
|
|
217
209
|
providers: [OrderService],
|
|
218
210
|
}).compile();
|
|
219
211
|
```
|
|
@@ -318,40 +310,40 @@ import type {
|
|
|
318
310
|
QueriesOf,
|
|
319
311
|
} from '@jdevel/tnest';
|
|
320
312
|
|
|
321
|
-
type Payload = PayloadOf<UserContracts['user.create']>;
|
|
322
|
-
type Response = ResponseOf<UserContracts['user.create']>;
|
|
323
|
-
type Cmds = CommandPatterns<UserContracts>;
|
|
324
|
-
type Evts = EventPatterns<UserContracts>;
|
|
325
|
-
type Qrys = QueryPatterns<UserContracts>;
|
|
326
|
-
type Sendable = SendablePatterns<UserContracts>;
|
|
313
|
+
type Payload = PayloadOf<UserContracts['user.create']>; // CreateUserDto
|
|
314
|
+
type Response = ResponseOf<UserContracts['user.create']>; // User
|
|
315
|
+
type Cmds = CommandPatterns<UserContracts>; // 'user.create'
|
|
316
|
+
type Evts = EventPatterns<UserContracts>; // 'user.created'
|
|
317
|
+
type Qrys = QueryPatterns<UserContracts>; // 'user.get'
|
|
318
|
+
type Sendable = SendablePatterns<UserContracts>; // 'user.create' | 'user.get'
|
|
327
319
|
```
|
|
328
320
|
|
|
329
321
|
## API Reference
|
|
330
322
|
|
|
331
|
-
| Export
|
|
332
|
-
|
|
333
|
-
| `TnestModule`
|
|
334
|
-
| `TypedClient`
|
|
335
|
-
| `TypedClientFactory`
|
|
336
|
-
| `TypedMessagePattern`
|
|
337
|
-
| `TypedEventPattern`
|
|
338
|
-
| `MockTypedClient`
|
|
339
|
-
| `TestContractModule`
|
|
340
|
-
| `ValidateContract`
|
|
341
|
-
| `getClientToken`
|
|
342
|
-
| `defineRegistry`
|
|
343
|
-
| `command` / `event` / `query`
|
|
344
|
-
| `Command` / `Event` / `Query`
|
|
345
|
-
| `ContractRegistry`
|
|
346
|
-
| `PayloadOf` / `ResponseOf` / `PatternOf`
|
|
347
|
-
| `CommandsOf` / `EventsOf` / `QueriesOf`
|
|
348
|
-
| `CommandPatterns` / `EventPatterns` / `QueryPatterns` | Type
|
|
349
|
-
| `SendablePatterns`
|
|
350
|
-
| `ContractValidator`
|
|
351
|
-
| `PayloadSerializer` / `PayloadDeserializer`
|
|
352
|
-
| `CONTRACT_VALIDATOR`
|
|
353
|
-
| `PAYLOAD_SERIALIZER` / `PAYLOAD_DESERIALIZER`
|
|
323
|
+
| Export | Kind | Description |
|
|
324
|
+
| ----------------------------------------------------- | --------- | ----------------------------------------------- |
|
|
325
|
+
| `TnestModule` | Module | Dynamic module with `forRoot` / `forRootAsync` |
|
|
326
|
+
| `TypedClient` | Class | Type-safe wrapper around `ClientProxy` |
|
|
327
|
+
| `TypedClientFactory` | Service | Creates `TypedClient` instances |
|
|
328
|
+
| `TypedMessagePattern` | Decorator | Typed `@MessagePattern` for commands/queries |
|
|
329
|
+
| `TypedEventPattern` | Decorator | Typed `@EventPattern` for events |
|
|
330
|
+
| `MockTypedClient` | Class | Test double that records messages |
|
|
331
|
+
| `TestContractModule` | Module | Registers mock clients for testing |
|
|
332
|
+
| `ValidateContract` | Decorator | Opt-in runtime payload validation |
|
|
333
|
+
| `getClientToken` | Function | Returns injection token for a named client |
|
|
334
|
+
| `defineRegistry` | Function | Builder helper for defining contract registries |
|
|
335
|
+
| `command` / `event` / `query` | Functions | Builder helpers for individual contracts |
|
|
336
|
+
| `Command` / `Event` / `Query` | Type | Contract type interfaces |
|
|
337
|
+
| `ContractRegistry` | Type | Base type for a registry of contracts |
|
|
338
|
+
| `PayloadOf` / `ResponseOf` / `PatternOf` | Type | Extract parts of a contract |
|
|
339
|
+
| `CommandsOf` / `EventsOf` / `QueriesOf` | Type | Filter registry by contract kind |
|
|
340
|
+
| `CommandPatterns` / `EventPatterns` / `QueryPatterns` | Type | Pattern string unions by kind |
|
|
341
|
+
| `SendablePatterns` | Type | Union of command + query patterns |
|
|
342
|
+
| `ContractValidator` | Interface | Implement for runtime validation |
|
|
343
|
+
| `PayloadSerializer` / `PayloadDeserializer` | Interface | Implement for custom serialization |
|
|
344
|
+
| `CONTRACT_VALIDATOR` | Token | Injection token for validator |
|
|
345
|
+
| `PAYLOAD_SERIALIZER` / `PAYLOAD_DESERIALIZER` | Token | Injection tokens for serialization |
|
|
354
346
|
|
|
355
347
|
## License
|
|
356
348
|
|
|
357
|
-
MIT
|
|
349
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
describe('TNEST_OPTIONS', () => {
|
|
5
|
+
it('is a Symbol', () => {
|
|
6
|
+
expect(typeof constants_1.TNEST_OPTIONS).toBe('symbol');
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
describe('getClientToken()', () => {
|
|
10
|
+
it('returns a string prefixed with TNEST_CLIENT_PREFIX', () => {
|
|
11
|
+
const token = (0, constants_1.getClientToken)('USER_SERVICE');
|
|
12
|
+
expect(token).toBe(`${constants_1.TNEST_CLIENT_PREFIX}USER_SERVICE`);
|
|
13
|
+
});
|
|
14
|
+
it('returns deterministic tokens for the same name', () => {
|
|
15
|
+
expect((0, constants_1.getClientToken)('SVC')).toBe((0, constants_1.getClientToken)('SVC'));
|
|
16
|
+
});
|
|
17
|
+
it('returns different tokens for different names', () => {
|
|
18
|
+
expect((0, constants_1.getClientToken)('A')).not.toBe((0, constants_1.getClientToken)('B'));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=constants.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.spec.js","sourceRoot":"","sources":["../../src/__tests__/constants.spec.ts"],"names":[],"mappings":";;AAAA,4CAAkF;AAElF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;QACrB,MAAM,CAAC,OAAO,yBAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,KAAK,GAAG,IAAA,0BAAc,EAAC,cAAc,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,+BAAmB,cAAc,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,IAAA,0BAAc,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAA,0BAAc,EAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,IAAA,0BAAc,EAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,0BAAc,EAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const tnest_module_1 = require("../tnest.module");
|
|
5
|
+
const client_1 = require("../client");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
describe('TnestModule', () => {
|
|
8
|
+
describe('forRoot()', () => {
|
|
9
|
+
it('provides TypedClientFactory', async () => {
|
|
10
|
+
const module = await testing_1.Test.createTestingModule({
|
|
11
|
+
imports: [tnest_module_1.TnestModule.forRoot()],
|
|
12
|
+
}).compile();
|
|
13
|
+
const factory = module.get(client_1.TypedClientFactory);
|
|
14
|
+
expect(factory).toBeInstanceOf(client_1.TypedClientFactory);
|
|
15
|
+
});
|
|
16
|
+
it('provides TNEST_OPTIONS', async () => {
|
|
17
|
+
const options = { clients: [] };
|
|
18
|
+
const module = await testing_1.Test.createTestingModule({
|
|
19
|
+
imports: [tnest_module_1.TnestModule.forRoot(options)],
|
|
20
|
+
}).compile();
|
|
21
|
+
const resolved = module.get(constants_1.TNEST_OPTIONS);
|
|
22
|
+
expect(resolved).toBe(options);
|
|
23
|
+
});
|
|
24
|
+
it('registers named client tokens from client definitions', async () => {
|
|
25
|
+
const module = await testing_1.Test.createTestingModule({
|
|
26
|
+
imports: [
|
|
27
|
+
tnest_module_1.TnestModule.forRoot({
|
|
28
|
+
clients: [{ name: 'USER_SERVICE', options: { transport: 0 } }],
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
}).compile();
|
|
32
|
+
const token = (0, constants_1.getClientToken)('USER_SERVICE');
|
|
33
|
+
const client = module.get(token);
|
|
34
|
+
expect(client).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('forRootAsync()', () => {
|
|
38
|
+
it('provides TypedClientFactory', async () => {
|
|
39
|
+
const module = await testing_1.Test.createTestingModule({
|
|
40
|
+
imports: [
|
|
41
|
+
tnest_module_1.TnestModule.forRootAsync({
|
|
42
|
+
useFactory: () => ({ clients: [] }),
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
}).compile();
|
|
46
|
+
const factory = module.get(client_1.TypedClientFactory);
|
|
47
|
+
expect(factory).toBeInstanceOf(client_1.TypedClientFactory);
|
|
48
|
+
});
|
|
49
|
+
it('resolves TNEST_OPTIONS from factory', async () => {
|
|
50
|
+
const options = { clients: [] };
|
|
51
|
+
const module = await testing_1.Test.createTestingModule({
|
|
52
|
+
imports: [
|
|
53
|
+
tnest_module_1.TnestModule.forRootAsync({
|
|
54
|
+
useFactory: () => options,
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
}).compile();
|
|
58
|
+
const resolved = module.get(constants_1.TNEST_OPTIONS);
|
|
59
|
+
expect(resolved).toBe(options);
|
|
60
|
+
});
|
|
61
|
+
it('registers named client tokens when clientNames are provided', async () => {
|
|
62
|
+
const module = await testing_1.Test.createTestingModule({
|
|
63
|
+
imports: [
|
|
64
|
+
tnest_module_1.TnestModule.forRootAsync({
|
|
65
|
+
clientNames: ['USER_SERVICE'],
|
|
66
|
+
useFactory: () => ({
|
|
67
|
+
clients: [{ name: 'USER_SERVICE', options: { transport: 0 } }],
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
}).compile();
|
|
72
|
+
const token = (0, constants_1.getClientToken)('USER_SERVICE');
|
|
73
|
+
const client = module.get(token);
|
|
74
|
+
expect(client).toBeDefined();
|
|
75
|
+
});
|
|
76
|
+
it('throws when clientName is not found in resolved options', async () => {
|
|
77
|
+
await expect(testing_1.Test.createTestingModule({
|
|
78
|
+
imports: [
|
|
79
|
+
tnest_module_1.TnestModule.forRootAsync({
|
|
80
|
+
clientNames: ['MISSING_SERVICE'],
|
|
81
|
+
useFactory: () => ({ clients: [] }),
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
}).compile()).rejects.toThrow(/client "MISSING_SERVICE" was declared in clientNames but not found/);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=tnest-module.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tnest-module.spec.js","sourceRoot":"","sources":["../../src/__tests__/tnest-module.spec.ts"],"names":[],"mappings":";;AAAA,6CAAuC;AACvC,kDAA8C;AAC9C,sCAA+C;AAC/C,4CAA6D;AAG7D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;gBAC5C,OAAO,EAAE,CAAC,0BAAW,CAAC,OAAO,EAAE,CAAC;aACjC,CAAC,CAAC,OAAO,EAAE,CAAC;YAEb,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,2BAAkB,CAAC,CAAC;YAC/C,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC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AA,0BAAc,EAAC,cAAc,CAAC,CAAC;YAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;YACvE,MAAM,MAAM,CACV,cAAI,CAAC,mBAAmB,CAAC;gBACvB,OAAO,EAAE;oBACP,0BAAW,CAAC,YAAY,CAAC;wBACvB,WAAW,EAAE,CAAC,iBAAiB,CAAC;wBAChC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;qBACpC,CAAC;iBACH;aACF,CAAC,CAAC,OAAO,EAAE,CACb,CAAC,OAAO,CAAC,OAAO,CAAC,oEAAoE,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rxjs_1 = require("rxjs");
|
|
4
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
+
const typed_client_factory_1 = require("../typed-client-factory");
|
|
6
|
+
const typed_client_1 = require("../typed-client");
|
|
7
|
+
describe('TypedClientFactory', () => {
|
|
8
|
+
let factory;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
factory = new typed_client_factory_1.TypedClientFactory();
|
|
11
|
+
});
|
|
12
|
+
it('creates a TypedClient from a ClientProxy instance', () => {
|
|
13
|
+
const mockProxy = {
|
|
14
|
+
send: jest.fn().mockReturnValue((0, rxjs_1.of)(undefined)),
|
|
15
|
+
emit: jest.fn().mockReturnValue((0, rxjs_1.of)(undefined)),
|
|
16
|
+
connect: jest.fn().mockResolvedValue(undefined),
|
|
17
|
+
close: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
const client = factory.create(mockProxy);
|
|
20
|
+
expect(client).toBeInstanceOf(typed_client_1.TypedClient);
|
|
21
|
+
});
|
|
22
|
+
it('creates a TypedClient from ClientOptions using ClientProxyFactory', () => {
|
|
23
|
+
const mockProxy = {
|
|
24
|
+
send: jest.fn(),
|
|
25
|
+
emit: jest.fn(),
|
|
26
|
+
connect: jest.fn(),
|
|
27
|
+
close: jest.fn(),
|
|
28
|
+
};
|
|
29
|
+
jest.spyOn(microservices_1.ClientProxyFactory, 'create').mockReturnValue(mockProxy);
|
|
30
|
+
const client = factory.create({ transport: 0 });
|
|
31
|
+
expect(microservices_1.ClientProxyFactory.create).toHaveBeenCalledWith({ transport: 0 });
|
|
32
|
+
expect(client).toBeInstanceOf(typed_client_1.TypedClient);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=typed-client-factory.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-client-factory.spec.js","sourceRoot":"","sources":["../../../src/client/__tests__/typed-client-factory.spec.ts"],"names":[],"mappings":";;AAAA,+BAA0B;AAC1B,yDAAwE;AACxE,kEAA6D;AAC7D,kDAA8C;AAQ9C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAI,OAA2B,CAAC;IAEhC,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,IAAI,yCAAkB,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,SAAS,GAAG;YAChB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,SAAE,EAAC,SAAS,CAAC,CAAC;YAC9C,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,SAAE,EAAC,SAAS,CAAC,CAAC;YAC9C,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;YAC/C,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;SACS,CAAC;QAE5B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAe,SAAS,CAAC,CAAC;QAEvD,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,0BAAW,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC3E,MAAM,SAAS,GAAG;YAChB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;YAClB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;SACS,CAAC;QAE5B,IAAI,CAAC,KAAK,CAAC,kCAAkB,EAAE,QAAQ,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAEpE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAe,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;QAE9D,MAAM,CAAC,kCAAkB,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,0BAAW,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expect_type_1 = require("expect-type");
|
|
4
|
+
describe('TypedClient type constraints', () => {
|
|
5
|
+
it('send() returns Observable of correct response type for command', () => {
|
|
6
|
+
(0, expect_type_1.expectTypeOf)().parameter(0).toMatchTypeOf();
|
|
7
|
+
});
|
|
8
|
+
it('send() infers response type from pattern', () => {
|
|
9
|
+
(0, expect_type_1.expectTypeOf)().toMatchTypeOf();
|
|
10
|
+
});
|
|
11
|
+
it('emit() accepts only event patterns', () => {
|
|
12
|
+
(0, expect_type_1.expectTypeOf)().parameter(0).toEqualTypeOf();
|
|
13
|
+
});
|
|
14
|
+
it('emit() returns Observable<undefined>', () => {
|
|
15
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=typed-client-types.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-client-types.spec.js","sourceRoot":"","sources":["../../../src/client/__tests__/typed-client-types.spec.ts"],"names":[],"mappings":";;AAAA,6CAA2C;AAgB3C,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACxE,IAAA,0BAAY,GAAkB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,EAA8B,CAAC;IAC1F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAElD,IAAA,0BAAY,GAAc,CAAC,aAAa,EAAuB,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,IAAA,0BAAY,GAAkB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,EAAkB,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAE9C,IAAA,0BAAY,GAAc,CAAC,aAAa,EAAyB,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rxjs_1 = require("rxjs");
|
|
4
|
+
const rxjs_2 = require("rxjs");
|
|
5
|
+
const typed_client_1 = require("../typed-client");
|
|
6
|
+
function createMockClientProxy() {
|
|
7
|
+
return {
|
|
8
|
+
send: jest.fn().mockReturnValue((0, rxjs_1.of)(undefined)),
|
|
9
|
+
emit: jest.fn().mockReturnValue((0, rxjs_1.of)(undefined)),
|
|
10
|
+
connect: jest.fn().mockResolvedValue(undefined),
|
|
11
|
+
close: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
describe('TypedClient', () => {
|
|
15
|
+
let mockProxy;
|
|
16
|
+
let client;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockProxy = createMockClientProxy();
|
|
19
|
+
client = new typed_client_1.TypedClient(mockProxy);
|
|
20
|
+
});
|
|
21
|
+
describe('send()', () => {
|
|
22
|
+
it('delegates to ClientProxy.send() with pattern and payload', async () => {
|
|
23
|
+
const payload = { name: 'Alice' };
|
|
24
|
+
const response = { id: '123' };
|
|
25
|
+
mockProxy.send.mockReturnValue((0, rxjs_1.of)(response));
|
|
26
|
+
const result = await (0, rxjs_2.firstValueFrom)(client.send('user.create', payload));
|
|
27
|
+
expect(mockProxy.send).toHaveBeenCalledWith('user.create', payload);
|
|
28
|
+
expect(result).toEqual(response);
|
|
29
|
+
});
|
|
30
|
+
it('works with query patterns', async () => {
|
|
31
|
+
const payload = { id: '123' };
|
|
32
|
+
const response = { name: 'Alice' };
|
|
33
|
+
mockProxy.send.mockReturnValue((0, rxjs_1.of)(response));
|
|
34
|
+
const result = await (0, rxjs_2.firstValueFrom)(client.send('user.get', payload));
|
|
35
|
+
expect(mockProxy.send).toHaveBeenCalledWith('user.get', payload);
|
|
36
|
+
expect(result).toEqual(response);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('emit()', () => {
|
|
40
|
+
it('delegates to ClientProxy.emit() with pattern and payload', async () => {
|
|
41
|
+
const payload = { userId: '123' };
|
|
42
|
+
await (0, rxjs_2.firstValueFrom)(client.emit('user.created', payload));
|
|
43
|
+
expect(mockProxy.emit).toHaveBeenCalledWith('user.created', payload);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('connect()', () => {
|
|
47
|
+
it('delegates to ClientProxy.connect()', async () => {
|
|
48
|
+
await client.connect();
|
|
49
|
+
expect(mockProxy.connect).toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('close()', () => {
|
|
53
|
+
it('delegates to ClientProxy.close()', () => {
|
|
54
|
+
client.close();
|
|
55
|
+
expect(mockProxy.close).toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=typed-client.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-client.spec.js","sourceRoot":"","sources":["../../../src/client/__tests__/typed-client.spec.ts"],"names":[],"mappings":";;AAAA,+BAA0B;AAC1B,+BAAsC;AAEtC,kDAA8C;AAY9C,SAAS,qBAAqB;IAC5B,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,SAAE,EAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAA,SAAE,EAAC,SAAS,CAAC,CAAC;QAC9C,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;QAC/C,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;KACsB,CAAC;AAC3C,CAAC;AAED,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,SAAmC,CAAC;IACxC,IAAI,MAAiC,CAAC;IAEtC,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG,qBAAqB,EAAE,CAAC;QACpC,MAAM,GAAG,IAAI,0BA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H,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;YACxE,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YAElC,MAAM,IAAA,qBAAc,EAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;YAE3D,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;YAClD,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;YAC1C,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expect_type_1 = require("expect-type");
|
|
4
|
+
describe('Contract type branding', () => {
|
|
5
|
+
it('Command has __type "command"', () => {
|
|
6
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('__type');
|
|
7
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
8
|
+
});
|
|
9
|
+
it('Event has __type "event"', () => {
|
|
10
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('__type');
|
|
11
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
12
|
+
});
|
|
13
|
+
it('Query has __type "query"', () => {
|
|
14
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('__type');
|
|
15
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
16
|
+
});
|
|
17
|
+
it('Command carries pattern, payload, and response', () => {
|
|
18
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
19
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
20
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
21
|
+
});
|
|
22
|
+
it('Event carries pattern and payload', () => {
|
|
23
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
24
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
25
|
+
});
|
|
26
|
+
it('Query carries pattern, payload, and response', () => {
|
|
27
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
28
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
29
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('Utility types', () => {
|
|
33
|
+
it('PatternOf extracts pattern from any contract', () => {
|
|
34
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
35
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
36
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
37
|
+
});
|
|
38
|
+
it('PayloadOf extracts payload from any contract', () => {
|
|
39
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
40
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
41
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
42
|
+
});
|
|
43
|
+
it('ResponseOf extracts response from Command and Query', () => {
|
|
44
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
45
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
46
|
+
});
|
|
47
|
+
it('ResponseOf returns undefined for Event', () => {
|
|
48
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('Registry filter types', () => {
|
|
52
|
+
it('CommandsOf filters to commands only', () => {
|
|
53
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('user.create');
|
|
54
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
55
|
+
});
|
|
56
|
+
it('EventsOf filters to events only', () => {
|
|
57
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('user.created');
|
|
58
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
59
|
+
});
|
|
60
|
+
it('QueriesOf filters to queries only', () => {
|
|
61
|
+
(0, expect_type_1.expectTypeOf)().toHaveProperty('user.get');
|
|
62
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
63
|
+
});
|
|
64
|
+
it('CommandPatterns produces correct string union', () => {
|
|
65
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
66
|
+
});
|
|
67
|
+
it('EventPatterns produces correct string union', () => {
|
|
68
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
69
|
+
});
|
|
70
|
+
it('QueryPatterns produces correct string union', () => {
|
|
71
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
72
|
+
});
|
|
73
|
+
it('SendablePatterns is union of command and query patterns', () => {
|
|
74
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('ValidateRegistry', () => {
|
|
78
|
+
it('accepts a valid registry (patterns match keys)', () => {
|
|
79
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
80
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
81
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('AnyContract', () => {
|
|
85
|
+
it('accepts Command, Event, and Query', () => {
|
|
86
|
+
(0, expect_type_1.expectTypeOf)().toMatchTypeOf();
|
|
87
|
+
(0, expect_type_1.expectTypeOf)().toMatchTypeOf();
|
|
88
|
+
(0, expect_type_1.expectTypeOf)().toMatchTypeOf();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=contract-types.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-types.spec.js","sourceRoot":"","sources":["../../../src/contracts/__tests__/contract-types.spec.ts"],"names":[],"mappings":";;AAAA,6CAA2C;AA2C3C,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,IAAA,0BAAY,GAAmC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzE,IAAA,0BAAY,GAA6C,CAAC,aAAa,EAAa,CAAC;IACvF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,IAAA,0BAAY,GAAyB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC/D,IAAA,0BAAY,GAAmC,CAAC,aAAa,EAAW,CAAC;IAC3E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,IAAA,0BAAY,GAAiC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACvE,IAAA,0BAAY,GAA2C,CAAC,aAAa,EAAW,CAAC;IACnF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EA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CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QAExD,IAAA,0BAAY,GAAwB,CAAC,aAAa,EAA+B,CAAC;QAClF,IAAA,0BAAY,GAAyB,CAAC,aAAa,EAAgC,CAAC;QACpF,IAAA,0BAAY,GAAqB,CAAC,aAAa,EAA4B,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,IAAA,0BAAY,GAAgC,CAAC,aAAa,EAAe,CAAC;QAC1E,IAAA,0BAAY,GAAsB,CAAC,aAAa,EAAe,CAAC;QAChE,IAAA,0BAAY,GAA8B,CAAC,aAAa,EAAe,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expect_type_1 = require("expect-type");
|
|
4
|
+
const define_helpers_1 = require("../define-helpers");
|
|
5
|
+
describe('command()', () => {
|
|
6
|
+
it('returns Command type with given payload and response', () => {
|
|
7
|
+
const c = (0, define_helpers_1.command)();
|
|
8
|
+
(0, expect_type_1.expectTypeOf)(c).toMatchTypeOf();
|
|
9
|
+
});
|
|
10
|
+
it('defaults payload to void and response to void', () => {
|
|
11
|
+
const c = (0, define_helpers_1.command)();
|
|
12
|
+
(0, expect_type_1.expectTypeOf)(c).toMatchTypeOf();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe('event()', () => {
|
|
16
|
+
it('returns Event type with given payload', () => {
|
|
17
|
+
const e = (0, define_helpers_1.event)();
|
|
18
|
+
(0, expect_type_1.expectTypeOf)(e).toMatchTypeOf();
|
|
19
|
+
});
|
|
20
|
+
it('defaults payload to void', () => {
|
|
21
|
+
const e = (0, define_helpers_1.event)();
|
|
22
|
+
(0, expect_type_1.expectTypeOf)(e).toMatchTypeOf();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('query()', () => {
|
|
26
|
+
it('returns Query type with given payload and response', () => {
|
|
27
|
+
const q = (0, define_helpers_1.query)();
|
|
28
|
+
(0, expect_type_1.expectTypeOf)(q).toMatchTypeOf();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('defineRegistry()', () => {
|
|
32
|
+
const registry = (0, define_helpers_1.defineRegistry)({
|
|
33
|
+
'user.create': (0, define_helpers_1.command)(),
|
|
34
|
+
'user.created': (0, define_helpers_1.event)(),
|
|
35
|
+
'user.get': (0, define_helpers_1.query)(),
|
|
36
|
+
});
|
|
37
|
+
it('infers pattern keys from object keys', () => {
|
|
38
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
39
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
40
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
41
|
+
});
|
|
42
|
+
it('preserves payload types', () => {
|
|
43
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
44
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
45
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
46
|
+
});
|
|
47
|
+
it('preserves response types', () => {
|
|
48
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
49
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=define-helpers.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-helpers.spec.js","sourceRoot":"","sources":["../../../src/contracts/__tests__/define-helpers.spec.ts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A,+BAAc,EAAC;QAC9B,aAAa,EAAE,IAAA,wBAAO,GAAoC;QAC1D,cAAc,EAAE,IAAA,sBAAK,GAAsB;QAC3C,UAAU,EAAE,IAAA,sBAAK,GAAoC;KACtD,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,IAAA,0BAAY,GAAoC,CAAC,aAAa,EAAiB,CAAC;QAChF,IAAA,0BAAY,GAAkC,CAAC,aAAa,EAAkB,CAAC;QAC/E,IAAA,0BAAY,GAAkC,CAAC,aAAa,EAAc,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,IAAA,0BAAY,GAA+C,CAAC,aAAa,EAAoB,CAAC;QAC9F,IAAA,0BAAY,GAAgD,CAAC,aAAa,EAEtE,CAAC;QACL,IAAA,0BAAY,GAA4C,CAAC,aAAa,EAAkB,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,IAAA,0BAAY,GAAgD,CAAC,aAAa,EAAkB,CAAC;QAC7F,IAAA,0BAAY,GAA6C,CAAC,aAAa,EAAoB,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-helpers.js","sourceRoot":"","sources":["../../src/contracts/define-helpers.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define-helpers.js","sourceRoot":"","sources":["../../src/contracts/define-helpers.ts"],"names":[],"mappings":";;AAOA,0BAEC;AAED,sBAEC;AAED,sBAEC;AAYD,wCAIC;AA1BD,SAAgB,OAAO;IACrB,OAAO,SAAgB,CAAC;AAC1B,CAAC;AAED,SAAgB,KAAK;IACnB,OAAO,SAAgB,CAAC;AAC1B,CAAC;AAED,SAAgB,KAAK;IACnB,OAAO,SAAgB,CAAC;AAC1B,CAAC;AAYD,SAAgB,cAAc,CAC5B,SAAY;IAEZ,OAAO,SAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expect_type_1 = require("expect-type");
|
|
4
|
+
describe('TypedMessageHandler', () => {
|
|
5
|
+
it('accepts payload and returns response for command', () => {
|
|
6
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
7
|
+
});
|
|
8
|
+
it('accepts payload and returns response for query', () => {
|
|
9
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe('TypedEventHandler', () => {
|
|
13
|
+
it('accepts payload and returns void', () => {
|
|
14
|
+
(0, expect_type_1.expectTypeOf)().toEqualTypeOf();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=handler-types.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-types.spec.js","sourceRoot":"","sources":["../../../src/handlers/__tests__/handler-types.spec.ts"],"names":[],"mappings":";;AAAA,6CAA2C;AAa3C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAE1D,IAAA,0BAAY,GAAuB,CAAC,aAAa,EAAsB,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QAExD,IAAA,0BAAY,GAAuB,CAAC,aAAa,EAAoB,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAE1C,IAAA,0BAAY,GAAuB,CAAC,aAAa,EAAwB,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const constants_1 = require("@nestjs/microservices/constants");
|
|
14
|
+
const typed_event_pattern_decorator_1 = require("../typed-event-pattern.decorator");
|
|
15
|
+
describe('TypedEventPattern', () => {
|
|
16
|
+
it('applies @EventPattern metadata with the given pattern', () => {
|
|
17
|
+
class TestHandler {
|
|
18
|
+
handle(_payload) {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typed_event_pattern_decorator_1.TypedEventPattern)('user.created'),
|
|
23
|
+
__metadata("design:type", Function),
|
|
24
|
+
__metadata("design:paramtypes", [Object]),
|
|
25
|
+
__metadata("design:returntype", void 0)
|
|
26
|
+
], TestHandler.prototype, "handle", null);
|
|
27
|
+
const metadata = Reflect.getMetadata(constants_1.PATTERN_METADATA, TestHandler.prototype.handle);
|
|
28
|
+
const handlerType = Reflect.getMetadata(constants_1.PATTERN_HANDLER_METADATA, TestHandler.prototype.handle);
|
|
29
|
+
expect(metadata).toEqual(['user.created']);
|
|
30
|
+
expect(handlerType).toBe(2);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=typed-event-pattern.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-event-pattern.spec.js","sourceRoot":"","sources":["../../../src/handlers/__tests__/typed-event-pattern.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAA0B;AAC1B,+DAA6F;AAC7F,oFAAqE;AAQrE,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,MAAM,WAAW;YAEf,MAAM,CAAC,QAA4B;YAEnC,CAAC;SACF;QAHC;YADC,IAAA,iDAAiB,EAAe,cAAc,CAAC;;;;iDAG/C;QAGH,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,4BAAgB,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACrF,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEhG,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const constants_1 = require("@nestjs/microservices/constants");
|
|
14
|
+
const typed_message_pattern_decorator_1 = require("../typed-message-pattern.decorator");
|
|
15
|
+
describe('TypedMessagePattern', () => {
|
|
16
|
+
it('applies @MessagePattern metadata with the given pattern', () => {
|
|
17
|
+
class TestHandler {
|
|
18
|
+
handle(_payload) {
|
|
19
|
+
return { id: '1' };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, typed_message_pattern_decorator_1.TypedMessagePattern)('user.create'),
|
|
24
|
+
__metadata("design:type", Function),
|
|
25
|
+
__metadata("design:paramtypes", [Object]),
|
|
26
|
+
__metadata("design:returntype", Object)
|
|
27
|
+
], TestHandler.prototype, "handle", null);
|
|
28
|
+
const metadata = Reflect.getMetadata(constants_1.PATTERN_METADATA, TestHandler.prototype.handle);
|
|
29
|
+
const handlerType = Reflect.getMetadata(constants_1.PATTERN_HANDLER_METADATA, TestHandler.prototype.handle);
|
|
30
|
+
expect(metadata).toEqual(['user.create']);
|
|
31
|
+
expect(handlerType).toBe(1);
|
|
32
|
+
});
|
|
33
|
+
it('works with query patterns', () => {
|
|
34
|
+
class TestHandler {
|
|
35
|
+
handle(_payload) {
|
|
36
|
+
return { name: 'Alice' };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typed_message_pattern_decorator_1.TypedMessagePattern)('user.get'),
|
|
41
|
+
__metadata("design:type", Function),
|
|
42
|
+
__metadata("design:paramtypes", [Object]),
|
|
43
|
+
__metadata("design:returntype", Object)
|
|
44
|
+
], TestHandler.prototype, "handle", null);
|
|
45
|
+
const metadata = Reflect.getMetadata(constants_1.PATTERN_METADATA, TestHandler.prototype.handle);
|
|
46
|
+
expect(metadata).toEqual(['user.get']);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=typed-message-pattern.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-message-pattern.spec.js","sourceRoot":"","sources":["../../../src/handlers/__tests__/typed-message-pattern.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAA0B;AAC1B,+DAA6F;AAC7F,wFAAyE;AAUzE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,WAAW;YAEf,MAAM,CAAC,QAA0B;gBAC/B,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;YACrB,CAAC;SACF;QAHC;YADC,IAAA,qDAAmB,EAAe,aAAa,CAAC;;;;iDAGhD;QAGH,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,4BAAgB,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACrF,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEhG,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,WAAW;YAEf,MAAM,CAAC,QAAwB;gBAC7B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;YAC3B,CAAC;SACF;QAHC;YADC,IAAA,qDAAmB,EAAe,UAAU,CAAC;;;;iDAG7C;QAGH,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,4BAAgB,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAErF,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-event-pattern.decorator.js","sourceRoot":"","sources":["../../src/handlers/typed-event-pattern.decorator.ts"],"names":[],"mappings":";;AAGA,8CAIC;AAPD,yDAAqD;AAGrD,SAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"typed-event-pattern.decorator.js","sourceRoot":"","sources":["../../src/handlers/typed-event-pattern.decorator.ts"],"names":[],"mappings":";;AAGA,8CAIC;AAPD,yDAAqD;AAGrD,SAAgB,iBAAiB,CAC/B,OAAiC;IAEjC,OAAO,IAAA,4BAAY,EAAC,OAAO,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-message-pattern.decorator.js","sourceRoot":"","sources":["../../src/handlers/typed-message-pattern.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"typed-message-pattern.decorator.js","sourceRoot":"","sources":["../../src/handlers/typed-message-pattern.decorator.ts"],"names":[],"mappings":";;AAGA,kDAIC;AAPD,yDAAuD;AAGvD,SAAgB,mBAAmB,CACjC,OAA8D;IAE9D,OAAO,IAAA,8BAAc,EAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type { TnestClientDefinition, TnestModuleOptions, TnestOptionsFactory, Tn
|
|
|
11
11
|
export { ValidateContract } from './validation';
|
|
12
12
|
export { CONTRACT_VALIDATOR } from './validation';
|
|
13
13
|
export type { ContractValidator } from './validation';
|
|
14
|
-
export { DefaultPayloadSerializer, PAYLOAD_SERIALIZER, PAYLOAD_DESERIALIZER } from './serialization';
|
|
14
|
+
export { DefaultPayloadSerializer, PAYLOAD_SERIALIZER, PAYLOAD_DESERIALIZER, } from './serialization';
|
|
15
15
|
export type { PayloadSerializer, PayloadDeserializer } from './serialization';
|
|
16
16
|
export { MockTypedClient } from './testing';
|
|
17
17
|
export { TestContractModule } from './testing';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAGpB,yCAA4D;AAAnD,0GAAA,aAAa,OAAA;AAAE,2GAAA,cAAc,OAAA;AAqBtC,yCAAoE;AAA3D,oGAAA,OAAO,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,2GAAA,cAAc,OAAA;AAG9C,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AACpB,mCAA8C;AAArC,4GAAA,kBAAkB,OAAA;AAG3B,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA;AAC5B,uCAA+C;AAAtC,6GAAA,iBAAiB,OAAA;AAY1B,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA;AAI3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAGpB,yCAA4D;AAAnD,0GAAA,aAAa,OAAA;AAAE,2GAAA,cAAc,OAAA;AAqBtC,yCAAoE;AAA3D,oGAAA,OAAO,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,2GAAA,cAAc,OAAA;AAG9C,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AACpB,mCAA8C;AAArC,4GAAA,kBAAkB,OAAA;AAG3B,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA;AAC5B,uCAA+C;AAAtC,6GAAA,iBAAiB,OAAA;AAY1B,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA;AAI3B,iDAIyB;AAHvB,yHAAA,wBAAwB,OAAA;AACxB,mHAAA,kBAAkB,OAAA;AAClB,qHAAA,oBAAoB,OAAA;AAKtB,qCAA4C;AAAnC,0GAAA,eAAe,OAAA;AACxB,qCAA+C;AAAtC,6GAAA,kBAAkB,OAAA"}
|
|
@@ -11,6 +11,7 @@ export interface TnestOptionsFactory {
|
|
|
11
11
|
createTnestOptions(): TnestModuleOptions | Promise<TnestModuleOptions>;
|
|
12
12
|
}
|
|
13
13
|
export interface TnestModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
14
|
+
clientNames?: string[];
|
|
14
15
|
useFactory?: (...args: any[]) => TnestModuleOptions | Promise<TnestModuleOptions>;
|
|
15
16
|
useClass?: Type<TnestOptionsFactory>;
|
|
16
17
|
useExisting?: Type<TnestOptionsFactory>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const default_serializer_1 = require("../default-serializer");
|
|
4
|
+
describe('DefaultPayloadSerializer', () => {
|
|
5
|
+
let serializer;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
serializer = new default_serializer_1.DefaultPayloadSerializer();
|
|
8
|
+
});
|
|
9
|
+
describe('serialize()', () => {
|
|
10
|
+
it('passes through the payload unchanged', () => {
|
|
11
|
+
const payload = { name: 'Alice', age: 30 };
|
|
12
|
+
expect(serializer.serialize(payload)).toBe(payload);
|
|
13
|
+
});
|
|
14
|
+
it('passes through primitives', () => {
|
|
15
|
+
expect(serializer.serialize('hello')).toBe('hello');
|
|
16
|
+
expect(serializer.serialize(42)).toBe(42);
|
|
17
|
+
expect(serializer.serialize(null)).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('deserialize()', () => {
|
|
21
|
+
it('passes through the data unchanged', () => {
|
|
22
|
+
const data = { name: 'Alice', age: 30 };
|
|
23
|
+
expect(serializer.deserialize(data)).toBe(data);
|
|
24
|
+
});
|
|
25
|
+
it('passes through primitives', () => {
|
|
26
|
+
expect(serializer.deserialize('hello')).toBe('hello');
|
|
27
|
+
expect(serializer.deserialize(42)).toBe(42);
|
|
28
|
+
expect(serializer.deserialize(null)).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=default-serializer.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-serializer.spec.js","sourceRoot":"","sources":["../../../src/serialization/__tests__/default-serializer.spec.ts"],"names":[],"mappings":";;AAAA,8DAAiE;AAEjE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,UAAoC,CAAC;IAEzC,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG,IAAI,6CAAwB,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC,CAA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|
4
|
+
const mock_typed_client_1 = require("../mock-typed-client");
|
|
5
|
+
describe('MockTypedClient', () => {
|
|
6
|
+
let mock;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
mock = new mock_typed_client_1.MockTypedClient();
|
|
9
|
+
});
|
|
10
|
+
describe('send()', () => {
|
|
11
|
+
it('records sent messages', () => {
|
|
12
|
+
mock.send('user.create', { name: 'Alice' });
|
|
13
|
+
expect(mock.messages).toHaveLength(1);
|
|
14
|
+
expect(mock.messages[0]).toEqual({
|
|
15
|
+
type: 'send',
|
|
16
|
+
pattern: 'user.create',
|
|
17
|
+
payload: { name: 'Alice' },
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it('returns canned response when set', async () => {
|
|
21
|
+
mock.setResponse('user.create', { id: '42' });
|
|
22
|
+
const result = await (0, rxjs_1.firstValueFrom)(mock.send('user.create', { name: 'Alice' }));
|
|
23
|
+
expect(result).toEqual({ id: '42' });
|
|
24
|
+
});
|
|
25
|
+
it('returns undefined when no response is set', async () => {
|
|
26
|
+
const result = await (0, rxjs_1.firstValueFrom)(mock.send('user.create', { name: 'Alice' }));
|
|
27
|
+
expect(result).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('emit()', () => {
|
|
31
|
+
it('records emitted messages', () => {
|
|
32
|
+
mock.emit('user.created', { userId: '42' });
|
|
33
|
+
expect(mock.messages).toHaveLength(1);
|
|
34
|
+
expect(mock.messages[0]).toEqual({
|
|
35
|
+
type: 'emit',
|
|
36
|
+
pattern: 'user.created',
|
|
37
|
+
payload: { userId: '42' },
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it('returns Observable<undefined>', async () => {
|
|
41
|
+
const result = await (0, rxjs_1.firstValueFrom)(mock.emit('user.created', { userId: '42' }));
|
|
42
|
+
expect(result).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('connect()', () => {
|
|
46
|
+
it('resolves immediately', async () => {
|
|
47
|
+
await expect(mock.connect()).resolves.toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('close()', () => {
|
|
51
|
+
it('is a no-op', () => {
|
|
52
|
+
expect(() => mock.close()).not.toThrow();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('reset()', () => {
|
|
56
|
+
it('clears recorded messages', () => {
|
|
57
|
+
mock.send('user.create', { name: 'Alice' });
|
|
58
|
+
mock.emit('user.created', { userId: '42' });
|
|
59
|
+
mock.reset();
|
|
60
|
+
expect(mock.messages).toHaveLength(0);
|
|
61
|
+
});
|
|
62
|
+
it('clears canned responses', async () => {
|
|
63
|
+
mock.setResponse('user.create', { id: '42' });
|
|
64
|
+
mock.reset();
|
|
65
|
+
const result = await (0, rxjs_1.firstValueFrom)(mock.send('user.create', { name: 'Alice' }));
|
|
66
|
+
expect(result).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=mock-typed-client.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-typed-client.spec.js","sourceRoot":"","sources":["../../../src/testing/__tests__/mock-typed-client.spec.ts"],"names":[],"mappings":";;AAAA,+BAAsC;AACtC,4DAAuD;AAYvD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,IAAmC,CAAC;IAExC,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,GAAG,IAAI,mCAAe,EAAgB,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAC/B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAE5C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACtC,MA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AY,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;YACvC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;YAEb,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAc,EAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YAEjF,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const test_contract_module_1 = require("../test-contract-module");
|
|
5
|
+
const mock_typed_client_1 = require("../mock-typed-client");
|
|
6
|
+
const client_1 = require("../../client");
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
describe('TestContractModule', () => {
|
|
9
|
+
it('registers mock clients as injectable by token', async () => {
|
|
10
|
+
const mockClient = new mock_typed_client_1.MockTypedClient();
|
|
11
|
+
const module = await testing_1.Test.createTestingModule({
|
|
12
|
+
imports: [
|
|
13
|
+
test_contract_module_1.TestContractModule.register([
|
|
14
|
+
{ name: 'TEST_SERVICE', mock: mockClient },
|
|
15
|
+
]),
|
|
16
|
+
],
|
|
17
|
+
}).compile();
|
|
18
|
+
const token = (0, constants_1.getClientToken)('TEST_SERVICE');
|
|
19
|
+
const resolved = module.get(token);
|
|
20
|
+
expect(resolved).toBe(mockClient);
|
|
21
|
+
});
|
|
22
|
+
it('provides TypedClientFactory', async () => {
|
|
23
|
+
const module = await testing_1.Test.createTestingModule({
|
|
24
|
+
imports: [test_contract_module_1.TestContractModule.register([])],
|
|
25
|
+
}).compile();
|
|
26
|
+
const factory = module.get(client_1.TypedClientFactory);
|
|
27
|
+
expect(factory).toBeInstanceOf(client_1.TypedClientFactory);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=test-contract-module.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-contract-module.spec.js","sourceRoot":"","sources":["../../../src/testing/__tests__/test-contract-module.spec.ts"],"names":[],"mappings":";;AAAA,6CAAuC;AACvC,kEAA6D;AAC7D,4DAAuD;AACvD,yCAAkD;AAClD,+CAAiD;AAQjD,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,UAAU,GAAG,IAAI,mCAAe,EAAgB,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC5C,OAAO,EAAE;gBACP,yCAAkB,CAAC,QAAQ,CAAC;oBAC1B,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,UAAoC,EAAE;iBACrE,CAAC;aACH;SACF,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,MAAM,KAAK,GAAG,IAAA,0BAAc,EAAC,cAAc,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC5C,OAAO,EAAE,CAAC,yCAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SAC3C,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,2BAAkB,CAAC,CAAC;QAC/C,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,2BAAkB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-typed-client.js","sourceRoot":"","sources":["../../src/testing/mock-typed-client.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAgB3C,MAAa,eAAe;IAA5B;
|
|
1
|
+
{"version":3,"file":"mock-typed-client.js","sourceRoot":"","sources":["../../src/testing/mock-typed-client.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAgB3C,MAAa,eAAe;IAA5B;QAImB,cAAS,GAAsB,EAAE,CAAC;QAClC,eAAU,GAAG,IAAI,GAAG,EAAmB,CAAC;IA0C3D,CAAC;IAxCC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,WAAW,CACT,OAAU,EACV,QAAkC;QAElC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CACF,OAAU,EACV,OAAgC;QAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAA6B,CAAC;QAC1E,OAAO,IAAA,SAAE,EAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CACF,OAAU,EACV,OAAgC;QAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,IAAA,SAAE,EAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IAED,OAAO;QACL,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK;IAEL,CAAC;IAED,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AA/CD,0CA+CC"}
|
package/dist/tnest.module.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { TnestModuleOptions, TnestModuleAsyncOptions } from './interfaces';
|
|
|
3
3
|
export declare class TnestModule {
|
|
4
4
|
static forRoot(options?: TnestModuleOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: TnestModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncClientProviders;
|
|
6
7
|
private static createClientProviders;
|
|
7
8
|
private static createAsyncProviders;
|
|
8
9
|
}
|
package/dist/tnest.module.js
CHANGED
|
@@ -23,35 +23,33 @@ let TnestModule = TnestModule_1 = class TnestModule {
|
|
|
23
23
|
client_1.TypedClientFactory,
|
|
24
24
|
...clientProviders,
|
|
25
25
|
],
|
|
26
|
-
exports: [
|
|
27
|
-
client_1.TypedClientFactory,
|
|
28
|
-
...clientProviders.map((p) => p.provide),
|
|
29
|
-
],
|
|
26
|
+
exports: [client_1.TypedClientFactory, ...clientProviders.map((p) => p.provide)],
|
|
30
27
|
};
|
|
31
28
|
}
|
|
32
29
|
static forRootAsync(options) {
|
|
33
30
|
const asyncProviders = TnestModule_1.createAsyncProviders(options);
|
|
34
|
-
const clientProviders = [
|
|
35
|
-
{
|
|
36
|
-
provide: 'TNEST_CLIENT_PROVIDERS',
|
|
37
|
-
useFactory: (tnestOptions) => {
|
|
38
|
-
return TnestModule_1.createClientProviders(tnestOptions);
|
|
39
|
-
},
|
|
40
|
-
inject: [constants_1.TNEST_OPTIONS],
|
|
41
|
-
},
|
|
42
|
-
];
|
|
31
|
+
const clientProviders = TnestModule_1.createAsyncClientProviders(options.clientNames ?? []);
|
|
43
32
|
return {
|
|
44
33
|
module: TnestModule_1,
|
|
45
34
|
global: true,
|
|
46
35
|
imports: options.imports ?? [],
|
|
47
|
-
providers: [
|
|
48
|
-
|
|
49
|
-
client_1.TypedClientFactory,
|
|
50
|
-
...clientProviders,
|
|
51
|
-
],
|
|
52
|
-
exports: [client_1.TypedClientFactory, constants_1.TNEST_OPTIONS],
|
|
36
|
+
providers: [...asyncProviders, client_1.TypedClientFactory, ...clientProviders],
|
|
37
|
+
exports: [client_1.TypedClientFactory, constants_1.TNEST_OPTIONS, ...clientProviders.map((p) => p.provide)],
|
|
53
38
|
};
|
|
54
39
|
}
|
|
40
|
+
static createAsyncClientProviders(clientNames) {
|
|
41
|
+
return clientNames.map((name) => ({
|
|
42
|
+
provide: (0, constants_1.getClientToken)(name),
|
|
43
|
+
useFactory: (tnestOptions) => {
|
|
44
|
+
const clientDef = tnestOptions.clients?.find((c) => c.name === name);
|
|
45
|
+
if (!clientDef) {
|
|
46
|
+
throw new Error(`TnestModule: client "${name}" was declared in clientNames but not found in resolved options.clients`);
|
|
47
|
+
}
|
|
48
|
+
return microservices_1.ClientProxyFactory.create(clientDef.options);
|
|
49
|
+
},
|
|
50
|
+
inject: [constants_1.TNEST_OPTIONS],
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
55
53
|
static createClientProviders(options) {
|
|
56
54
|
if (!options.clients?.length)
|
|
57
55
|
return [];
|
|
@@ -70,7 +68,10 @@ let TnestModule = TnestModule_1 = class TnestModule {
|
|
|
70
68
|
},
|
|
71
69
|
];
|
|
72
70
|
}
|
|
73
|
-
const useClass =
|
|
71
|
+
const useClass = options.useClass ?? options.useExisting;
|
|
72
|
+
if (!useClass) {
|
|
73
|
+
throw new Error('TnestModule.forRootAsync() requires one of: useFactory, useClass, or useExisting');
|
|
74
|
+
}
|
|
74
75
|
const providers = [
|
|
75
76
|
{
|
|
76
77
|
provide: constants_1.TNEST_OPTIONS,
|
package/dist/tnest.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tnest.module.js","sourceRoot":"","sources":["../src/tnest.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"tnest.module.js","sourceRoot":"","sources":["../src/tnest.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiG;AACjG,yDAA2D;AAC3D,qCAA8C;AAC9C,2CAA4D;AAQrD,IAAM,WAAW,mBAAjB,MAAM,WAAW;IACtB,MAAM,CAAC,OAAO,CAAC,UAA8B,EAAE;QAC7C,MAAM,eAAe,GAAG,aAAW,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAEnE,OAAO;YACL,MAAM,EAAE,aAAW;YACnB,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,yBAAa,EAAE,QAAQ,EAAE,OAAO,EAAE;gBAC7C,2BAAkB;gBAClB,GAAG,eAAe;aACnB;YACD,OAAO,EAAE,CAAC,2BAAkB,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACxE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAgC;QAClD,MAAM,cAAc,GAAG,aAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,eAAe,GAAG,aAAW,CAAC,0BAA0B,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAE1F,OAAO;YACL,MAAM,EAAE,aAAW;YACnB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE,CAAC,GAAG,cAAc,EAAE,2BAAkB,EAAE,GAAG,eAAe,CAAC;YACtE,OAAO,EAAE,CAAC,2BAAkB,EAAE,yBAAa,EAAE,GAAG,eAAe,CAA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OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;iBAC7B;aACF,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;QACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAe;YAC5B;gBACE,OAAO,EAAE,yBAAa;gBACtB,UAAU,EAAE,KAAK,EAAE,OAA4B,EAAE,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE;gBAChF,MAAM,EAAE,CAAC,QAAQ,CAAC;aACnB;SACF,CAAC;QAEF,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAtFY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,WAAW,CAsFvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const validate_contract_decorator_1 = require("../validate-contract.decorator");
|
|
14
|
+
describe('ValidateContract', () => {
|
|
15
|
+
it('calls validator.validate() before the handler', async () => {
|
|
16
|
+
const validator = {
|
|
17
|
+
validate: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
class TestHandler {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.__contractValidator = validator;
|
|
22
|
+
}
|
|
23
|
+
async handle(payload) {
|
|
24
|
+
return `processed: ${String(payload)}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, validate_contract_decorator_1.ValidateContract)(),
|
|
29
|
+
__metadata("design:type", Function),
|
|
30
|
+
__metadata("design:paramtypes", [Object]),
|
|
31
|
+
__metadata("design:returntype", Promise)
|
|
32
|
+
], TestHandler.prototype, "handle", null);
|
|
33
|
+
const handler = new TestHandler();
|
|
34
|
+
const result = await handler.handle('test-data');
|
|
35
|
+
expect(validator.validate).toHaveBeenCalledWith('test-data');
|
|
36
|
+
expect(result).toBe('processed: test-data');
|
|
37
|
+
});
|
|
38
|
+
it('runs handler without validation when no validator is set', async () => {
|
|
39
|
+
class TestHandler {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.__contractValidator = undefined;
|
|
42
|
+
}
|
|
43
|
+
async handle(payload) {
|
|
44
|
+
return `processed: ${String(payload)}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, validate_contract_decorator_1.ValidateContract)(),
|
|
49
|
+
__metadata("design:type", Function),
|
|
50
|
+
__metadata("design:paramtypes", [Object]),
|
|
51
|
+
__metadata("design:returntype", Promise)
|
|
52
|
+
], TestHandler.prototype, "handle", null);
|
|
53
|
+
const handler = new TestHandler();
|
|
54
|
+
const result = await handler.handle('test-data');
|
|
55
|
+
expect(result).toBe('processed: test-data');
|
|
56
|
+
});
|
|
57
|
+
it('propagates validation errors', async () => {
|
|
58
|
+
const validator = {
|
|
59
|
+
validate: jest.fn().mockRejectedValue(new Error('Validation failed')),
|
|
60
|
+
};
|
|
61
|
+
class TestHandler {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.__contractValidator = validator;
|
|
64
|
+
}
|
|
65
|
+
async handle(payload) {
|
|
66
|
+
return `processed: ${String(payload)}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, validate_contract_decorator_1.ValidateContract)(),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [Object]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], TestHandler.prototype, "handle", null);
|
|
75
|
+
const handler = new TestHandler();
|
|
76
|
+
await expect(handler.handle('bad-data')).rejects.toThrow('Validation failed');
|
|
77
|
+
});
|
|
78
|
+
it('supports synchronous validators', async () => {
|
|
79
|
+
const validator = {
|
|
80
|
+
validate: jest.fn(),
|
|
81
|
+
};
|
|
82
|
+
class TestHandler {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.__contractValidator = validator;
|
|
85
|
+
}
|
|
86
|
+
handle(payload) {
|
|
87
|
+
return `processed: ${String(payload)}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, validate_contract_decorator_1.ValidateContract)(),
|
|
92
|
+
__metadata("design:type", Function),
|
|
93
|
+
__metadata("design:paramtypes", [Object]),
|
|
94
|
+
__metadata("design:returntype", String)
|
|
95
|
+
], TestHandler.prototype, "handle", null);
|
|
96
|
+
const handler = new TestHandler();
|
|
97
|
+
const result = await handler.handle('sync-data');
|
|
98
|
+
expect(validator.validate).toHaveBeenCalledWith('sync-data');
|
|
99
|
+
expect(result).toBe('processed: sync-data');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=validate-contract.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-contract.spec.js","sourceRoot":"","sources":["../../../src/validation/__tests__/validate-contract.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAA0B;AAC1B,gFAAkE;AAGlE,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,SAAS,GAAsB;YACnC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;SACpB,CAAC;QAEF,MAAM,WAAW;YAAjB;gBACE,wBAAmB,GAAG,SAAS,CAAC;YAMlC,CAAC;YAHO,AAAN,KAAK,CAAC,MAAM,CAAC,OAAgB;gBAC3B,OAAO,cAAc,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACzC,CAAC;SACF;QAHO;YADL,IAAA,8CAAgB,GAAE;;;;iDAGlB;QAGH,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAEjD,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,WAAW;YAAjB;gBACE,wBAAmB,GAAkC,SAAS,CAAC;YAMjE,CAAC;YAHO,AAAN,KAAK,CAAC,MAAM,CAAC,OAAgB;gBAC3B,OAAO,cAAc,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACzC,CAAC;SACF;QAHO;YADL,IAAA,8CAAgB,GAAE;;;;iDAGlB;QAGH,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AAG,MAAM,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAEjD,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-contract.decorator.js","sourceRoot":"","sources":["../../src/validation/validate-contract.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"validate-contract.decorator.js","sourceRoot":"","sources":["../../src/validation/validate-contract.decorator.ts"],"names":[],"mappings":";;AAKA,4CAsBC;AA3BD,2CAAwC;AACxC,+DAAmF;AAInF,SAAgB,gBAAgB;IAC9B,MAAM,eAAe,GAAG,IAAA,eAAM,EAAC,wCAAkB,CAAC,CAAC;IAEnD,OAAO,CACL,MAAc,EACd,WAA4B,EAC5B,UAAwC,EACxC,EAAE;QACF,eAAe,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;QAE/C,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAsB,OAAgB,EAAE,GAAG,IAAe;YAChF,MAAM,SAAS,GAAkC,IAAI,CAAC,mBAAmB,CAAC;YAC1E,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jdevel/tnest",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Type-safe communication between NestJS microservices via shared contracts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -9,8 +9,13 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "./node_modules/.bin/tsc",
|
|
12
|
-
"lint": "eslint src/",
|
|
13
|
-
"lint:fix": "eslint src/ --fix",
|
|
12
|
+
"lint": "./node_modules/.bin/eslint src/",
|
|
13
|
+
"lint:fix": "./node_modules/.bin/eslint src/ --fix",
|
|
14
|
+
"test": "./node_modules/.bin/jest",
|
|
15
|
+
"test:watch": "./node_modules/.bin/jest --watch",
|
|
16
|
+
"test:cov": "./node_modules/.bin/jest --coverage",
|
|
17
|
+
"format": "./node_modules/.bin/prettier --write .",
|
|
18
|
+
"format:check": "./node_modules/.bin/prettier --check .",
|
|
14
19
|
"prepublishOnly": "npm run build"
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
@@ -23,11 +28,29 @@
|
|
|
23
28
|
"@eslint/js": "^10.0.1",
|
|
24
29
|
"@nestjs/common": "^11.0.0",
|
|
25
30
|
"@nestjs/microservices": "^11.1.17",
|
|
31
|
+
"@nestjs/testing": "^11.1.17",
|
|
32
|
+
"@types/jest": "^30.0.0",
|
|
26
33
|
"eslint": "^10.1.0",
|
|
34
|
+
"eslint-config-prettier": "^10.1.8",
|
|
35
|
+
"expect-type": "^1.3.0",
|
|
36
|
+
"jest": "^30.3.0",
|
|
37
|
+
"prettier": "^3.8.1",
|
|
27
38
|
"reflect-metadata": "^0.2.0",
|
|
28
39
|
"rxjs": "^7.8.1",
|
|
40
|
+
"ts-jest": "^29.4.6",
|
|
29
41
|
"typescript": "^5.7.0",
|
|
30
42
|
"typescript-eslint": "^8.57.2"
|
|
31
43
|
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"nestjs",
|
|
46
|
+
"microservices",
|
|
47
|
+
"type-safe",
|
|
48
|
+
"contracts",
|
|
49
|
+
"typescript",
|
|
50
|
+
"messaging"
|
|
51
|
+
],
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18"
|
|
54
|
+
},
|
|
32
55
|
"license": "MIT"
|
|
33
56
|
}
|