@jdevel/tnest 0.0.1 → 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 +349 -0
- 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/client/index.d.ts +2 -0
- package/dist/client/index.js +8 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/typed-client-factory.d.ts +6 -0
- package/dist/client/typed-client-factory.js +25 -0
- package/dist/client/typed-client-factory.js.map +1 -0
- package/dist/client/typed-client.d.ts +11 -0
- package/dist/client/typed-client.js +22 -0
- package/dist/client/typed-client.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +10 -0
- package/dist/constants.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/command.d.ts +6 -0
- package/dist/contracts/command.js +3 -0
- package/dist/contracts/command.js.map +1 -0
- package/dist/contracts/define-helpers.d.ts +12 -0
- package/dist/contracts/define-helpers.js +19 -0
- package/dist/contracts/define-helpers.js.map +1 -0
- package/dist/contracts/event.d.ts +5 -0
- package/dist/contracts/event.js +3 -0
- package/dist/contracts/event.js.map +1 -0
- package/dist/contracts/index.d.ts +6 -0
- package/dist/contracts/index.js +9 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/query.d.ts +6 -0
- package/dist/contracts/query.js +3 -0
- package/dist/contracts/query.js.map +1 -0
- package/dist/contracts/registry.d.ts +8 -0
- package/dist/contracts/registry.js +3 -0
- package/dist/contracts/registry.js.map +1 -0
- package/dist/contracts/utility-types.d.ts +21 -0
- package/dist/contracts/utility-types.js +3 -0
- package/dist/contracts/utility-types.js.map +1 -0
- 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/handler-types.d.ts +4 -0
- package/dist/handlers/handler-types.js +3 -0
- package/dist/handlers/handler-types.js.map +1 -0
- package/dist/handlers/index.d.ts +3 -0
- package/dist/handlers/index.js +8 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/typed-event-pattern.decorator.d.ts +2 -0
- package/dist/handlers/typed-event-pattern.decorator.js +8 -0
- package/dist/handlers/typed-event-pattern.decorator.js.map +1 -0
- package/dist/handlers/typed-message-pattern.decorator.d.ts +2 -0
- package/dist/handlers/typed-message-pattern.decorator.js +8 -0
- package/dist/handlers/typed-message-pattern.decorator.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/module-options.d.ts +19 -0
- package/dist/interfaces/module-options.js +3 -0
- package/dist/interfaces/module-options.js.map +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/serialization/default-serializer.d.ts +5 -0
- package/dist/serialization/default-serializer.js +23 -0
- package/dist/serialization/default-serializer.js.map +1 -0
- package/dist/serialization/index.d.ts +3 -0
- package/dist/serialization/index.js +9 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/serializer.interface.d.ts +8 -0
- package/dist/serialization/serializer.interface.js +6 -0
- package/dist/serialization/serializer.interface.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/index.d.ts +2 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-typed-client.d.ts +20 -0
- package/dist/testing/mock-typed-client.js +36 -0
- package/dist/testing/mock-typed-client.js.map +1 -0
- package/dist/testing/test-contract-module.d.ts +10 -0
- package/dist/testing/test-contract-module.js +31 -0
- package/dist/testing/test-contract-module.js.map +1 -0
- package/dist/tnest.module.d.ts +7 -0
- package/dist/tnest.module.js +78 -7
- 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/index.d.ts +3 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/validate-contract.decorator.d.ts +1 -0
- package/dist/validation/validate-contract.decorator.js +21 -0
- package/dist/validation/validate-contract.decorator.js.map +1 -0
- package/dist/validation/validator.interface.d.ts +4 -0
- package/dist/validation/validator.interface.js +5 -0
- package/dist/validation/validator.interface.js.map +1 -0
- package/package.json +34 -4
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TypedClientFactory = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
12
|
+
const typed_client_1 = require("./typed-client");
|
|
13
|
+
let TypedClientFactory = class TypedClientFactory {
|
|
14
|
+
create(clientOrOptions) {
|
|
15
|
+
const client = clientOrOptions instanceof microservices_1.ClientProxy
|
|
16
|
+
? clientOrOptions
|
|
17
|
+
: microservices_1.ClientProxyFactory.create(clientOrOptions);
|
|
18
|
+
return new typed_client_1.TypedClient(client);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.TypedClientFactory = TypedClientFactory;
|
|
22
|
+
exports.TypedClientFactory = TypedClientFactory = __decorate([
|
|
23
|
+
(0, common_1.Injectable)()
|
|
24
|
+
], TypedClientFactory);
|
|
25
|
+
//# sourceMappingURL=typed-client-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-client-factory.js","sourceRoot":"","sources":["../../src/client/typed-client-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,yDAA4F;AAE5F,iDAA6C;AAGtC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,MAAM,CACJ,eAA4C;QAE5C,MAAM,MAAM,GACV,eAAe,YAAY,2BAAW;YACpC,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,kCAAkB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAEjD,OAAO,IAAI,0BAAW,CAAY,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAXY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAW9B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ClientProxy } from '@nestjs/microservices';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
import type { ContractRegistry, EventPatterns, PayloadOf, ResponseOf, SendablePatterns } from '../contracts';
|
|
4
|
+
export declare class TypedClient<TRegistry extends ContractRegistry> {
|
|
5
|
+
private readonly client;
|
|
6
|
+
constructor(client: ClientProxy);
|
|
7
|
+
send<P extends SendablePatterns<TRegistry>>(pattern: P, payload: PayloadOf<TRegistry[P]>): Observable<ResponseOf<TRegistry[P]>>;
|
|
8
|
+
emit<P extends EventPatterns<TRegistry>>(pattern: P, payload: PayloadOf<TRegistry[P]>): Observable<undefined>;
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
close(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedClient = void 0;
|
|
4
|
+
class TypedClient {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
send(pattern, payload) {
|
|
9
|
+
return this.client.send(pattern, payload);
|
|
10
|
+
}
|
|
11
|
+
emit(pattern, payload) {
|
|
12
|
+
return this.client.emit(pattern, payload);
|
|
13
|
+
}
|
|
14
|
+
connect() {
|
|
15
|
+
return this.client.connect();
|
|
16
|
+
}
|
|
17
|
+
close() {
|
|
18
|
+
this.client.close();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TypedClient = TypedClient;
|
|
22
|
+
//# sourceMappingURL=typed-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-client.js","sourceRoot":"","sources":["../../src/client/typed-client.ts"],"names":[],"mappings":";;;AAUA,MAAa,WAAW;IACtB,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAEpD,IAAI,CACF,OAAU,EACV,OAAgC;QAEhC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAA2B,OAAO,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,CACF,OAAU,EACV,OAAgC;QAEhC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAxBD,kCAwBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TNEST_CLIENT_PREFIX = exports.TNEST_OPTIONS = void 0;
|
|
4
|
+
exports.getClientToken = getClientToken;
|
|
5
|
+
exports.TNEST_OPTIONS = Symbol('TNEST_OPTIONS');
|
|
6
|
+
exports.TNEST_CLIENT_PREFIX = 'TNEST_CLIENT_';
|
|
7
|
+
function getClientToken(name) {
|
|
8
|
+
return `${exports.TNEST_CLIENT_PREFIX}${name}`;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAGA,wCAEC;AALY,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACxC,QAAA,mBAAmB,GAAG,eAAe,CAAC;AAEnD,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,GAAG,2BAAmB,GAAG,IAAI,EAAE,CAAC;AACzC,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,EAAE;QAExD,IAAA,0BAAY,GAAgB,CAAC,aAAa,EAAS,CAAC;QACpD,IAAA,0BAAY,GAAgB,CAAC,aAAa,EAAU,CAAC;QACrD,IAAA,0BAAY,GAAiB,CAAC,aAAa,EAAU,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAE3C,IAAA,0BAAY,GAAgB,CAAC,aAAa,EAAS,CAAC;QACpD,IAAA,0BAAY,GAAgB,CAAC,aAAa,EAAU,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C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3B,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"],"names":[],"mappings":";;AAAA,6CAA2C;AAC3C,sDAA0E;AAY1E,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,CAAC,GAAG,IAAA,wBAAO,GAAoC,CAAC;QACtD,IAAA,0BAAY,EAAC,CAAC,CAAC,CAAC,aAAa,EAAqD,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,GAAG,IAAA,wBAAO,GAAE,CAAC;QACpB,I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AC;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/contracts/command.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from './command';
|
|
2
|
+
import type { Event } from './event';
|
|
3
|
+
import type { Query } from './query';
|
|
4
|
+
import type { ContractRegistry } from './utility-types';
|
|
5
|
+
export declare function command<TPayload = void, TResponse = void>(): Command<string, TPayload, TResponse>;
|
|
6
|
+
export declare function event<TPayload = void>(): Event<string, TPayload>;
|
|
7
|
+
export declare function query<TPayload = void, TResponse = unknown>(): Query<string, TPayload, TResponse>;
|
|
8
|
+
type InferRegistry<T extends Record<string, any>> = {
|
|
9
|
+
[K in keyof T & string]: T[K] extends Command<any, infer P, infer R> ? Command<K, P, R> : T[K] extends Event<any, infer P> ? Event<K, P> : T[K] extends Query<any, infer P, infer R> ? Query<K, P, R> : never;
|
|
10
|
+
};
|
|
11
|
+
export declare function defineRegistry<T extends Record<string, any>>(contracts: T): InferRegistry<T> & ContractRegistry;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = command;
|
|
4
|
+
exports.event = event;
|
|
5
|
+
exports.query = query;
|
|
6
|
+
exports.defineRegistry = defineRegistry;
|
|
7
|
+
function command() {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
function event() {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
function query() {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function defineRegistry(contracts) {
|
|
17
|
+
return contracts;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=define-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Command } from './command';
|
|
2
|
+
export type { Event } from './event';
|
|
3
|
+
export type { Query } from './query';
|
|
4
|
+
export type { ValidateRegistry } from './registry';
|
|
5
|
+
export { command, event, query, defineRegistry } from './define-helpers';
|
|
6
|
+
export type { AnyContract, PatternOf, PayloadOf, ResponseOf, ContractRegistry, CommandsOf, EventsOf, QueriesOf, CommandPatterns, EventPatterns, QueryPatterns, SendablePatterns, } from './utility-types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineRegistry = exports.query = exports.event = exports.command = void 0;
|
|
4
|
+
var define_helpers_1 = require("./define-helpers");
|
|
5
|
+
Object.defineProperty(exports, "command", { enumerable: true, get: function () { return define_helpers_1.command; } });
|
|
6
|
+
Object.defineProperty(exports, "event", { enumerable: true, get: function () { return define_helpers_1.event; } });
|
|
7
|
+
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return define_helpers_1.query; } });
|
|
8
|
+
Object.defineProperty(exports, "defineRegistry", { enumerable: true, get: function () { return define_helpers_1.defineRegistry; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":";;;AAIA,mDAAyE;AAAhE,yGAAA,OAAO,OAAA;AAAE,uGAAA,KAAK,OAAA;AAAE,uGAAA,KAAK,OAAA;AAAE,gHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/contracts/query.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContractRegistry } from './utility-types';
|
|
2
|
+
export type ValidateRegistry<TRegistry extends ContractRegistry> = {
|
|
3
|
+
[K in keyof TRegistry]: TRegistry[K] extends {
|
|
4
|
+
pattern: infer P;
|
|
5
|
+
} ? P extends K ? TRegistry[K] : {
|
|
6
|
+
error: `Pattern '${P & string}' does not match registry key '${K & string}'`;
|
|
7
|
+
} : never;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/contracts/registry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Command } from './command';
|
|
2
|
+
import type { Event } from './event';
|
|
3
|
+
import type { Query } from './query';
|
|
4
|
+
export type AnyContract = Command<string, any, any> | Event<string, any> | Query<string, any, any>;
|
|
5
|
+
export type PatternOf<C extends AnyContract> = C['pattern'];
|
|
6
|
+
export type PayloadOf<C extends AnyContract> = C['payload'];
|
|
7
|
+
export type ResponseOf<C extends AnyContract> = C extends Command<any, any, infer R> ? R : C extends Query<any, any, infer R> ? R : C extends Event ? undefined : never;
|
|
8
|
+
export type ContractRegistry = Record<string, AnyContract>;
|
|
9
|
+
export type CommandsOf<TRegistry extends ContractRegistry> = {
|
|
10
|
+
[K in keyof TRegistry as TRegistry[K] extends Command<any, any, any> ? K : never]: TRegistry[K];
|
|
11
|
+
};
|
|
12
|
+
export type EventsOf<TRegistry extends ContractRegistry> = {
|
|
13
|
+
[K in keyof TRegistry as TRegistry[K] extends Event<any, any> ? K : never]: TRegistry[K];
|
|
14
|
+
};
|
|
15
|
+
export type QueriesOf<TRegistry extends ContractRegistry> = {
|
|
16
|
+
[K in keyof TRegistry as TRegistry[K] extends Query<any, any, any> ? K : never]: TRegistry[K];
|
|
17
|
+
};
|
|
18
|
+
export type CommandPatterns<TRegistry extends ContractRegistry> = keyof CommandsOf<TRegistry> & string;
|
|
19
|
+
export type EventPatterns<TRegistry extends ContractRegistry> = keyof EventsOf<TRegistry> & string;
|
|
20
|
+
export type QueryPatterns<TRegistry extends ContractRegistry> = keyof QueriesOf<TRegistry> & string;
|
|
21
|
+
export type SendablePatterns<TRegistry extends ContractRegistry> = CommandPatterns<TRegistry> | QueryPatterns<TRegistry>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility-types.js","sourceRoot":"","sources":["../../src/contracts/utility-types.ts"],"names":[],"mappings":""}
|
|
@@ -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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { ContractRegistry, CommandPatterns, EventPatterns, QueryPatterns, PayloadOf, ResponseOf } from '../contracts';
|
|
3
|
+
export type TypedMessageHandler<TRegistry extends ContractRegistry, P extends CommandPatterns<TRegistry> | QueryPatterns<TRegistry>> = (payload: PayloadOf<TRegistry[P]>) => ResponseOf<TRegistry[P]> | Promise<ResponseOf<TRegistry[P]>> | Observable<ResponseOf<TRegistry[P]>>;
|
|
4
|
+
export type TypedEventHandler<TRegistry extends ContractRegistry, P extends EventPatterns<TRegistry>> = (payload: PayloadOf<TRegistry[P]>) => void | Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-types.js","sourceRoot":"","sources":["../../src/handlers/handler-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedEventPattern = exports.TypedMessagePattern = void 0;
|
|
4
|
+
var typed_message_pattern_decorator_1 = require("./typed-message-pattern.decorator");
|
|
5
|
+
Object.defineProperty(exports, "TypedMessagePattern", { enumerable: true, get: function () { return typed_message_pattern_decorator_1.TypedMessagePattern; } });
|
|
6
|
+
var typed_event_pattern_decorator_1 = require("./typed-event-pattern.decorator");
|
|
7
|
+
Object.defineProperty(exports, "TypedEventPattern", { enumerable: true, get: function () { return typed_event_pattern_decorator_1.TypedEventPattern; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":";;;AAAA,qFAAwE;AAA/D,sIAAA,mBAAmB,OAAA;AAC5B,iFAAoE;AAA3D,kIAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedEventPattern = TypedEventPattern;
|
|
4
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
+
function TypedEventPattern(pattern) {
|
|
6
|
+
return (0, microservices_1.EventPattern)(pattern);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=typed-event-pattern.decorator.js.map
|
|
@@ -0,0 +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,CAC/B,OAAiC;IAEjC,OAAO,IAAA,4BAAY,EAAC,OAAO,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedMessagePattern = TypedMessagePattern;
|
|
4
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
+
function TypedMessagePattern(pattern) {
|
|
6
|
+
return (0, microservices_1.MessagePattern)(pattern);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=typed-message-pattern.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|