@orion-js/echoes 3.2.3 → 3.2.4
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/lib/echo/index.d.ts +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/requestsHandler/getEcho.d.ts +1 -1
- package/lib/requestsHandler/index.d.ts +1 -1
- package/lib/service/index.d.ts +8 -0
- package/lib/service/index.js +54 -0
- package/lib/service/index.test.d.ts +1 -0
- package/lib/service/index.test.js +51 -0
- package/lib/types.d.ts +6 -7
- package/package.json +6 -3
package/lib/echo/index.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function (method: string): import("..").
|
|
1
|
+
export default function (method: string): import("..").EchoType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EchoConfig, EchoesMap } from '../types';
|
|
2
|
+
export declare function Echoes(): ClassDecorator;
|
|
3
|
+
export interface EchoesPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
|
|
4
|
+
value?: EchoConfig['resolve'];
|
|
5
|
+
}
|
|
6
|
+
export declare function EchoRequest(options?: Omit<EchoConfig, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: EchoesPropertyDescriptor) => void;
|
|
7
|
+
export declare function EchoEvent(options?: Omit<EchoConfig, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: EchoesPropertyDescriptor) => void;
|
|
8
|
+
export declare function getServiceEchoes(target: any): EchoesMap;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getServiceEchoes = exports.EchoEvent = exports.EchoRequest = exports.Echoes = void 0;
|
|
7
|
+
const services_1 = require("@orion-js/services");
|
|
8
|
+
const echo_1 = __importDefault(require("../echo"));
|
|
9
|
+
function Echoes() {
|
|
10
|
+
return function (target) {
|
|
11
|
+
(0, services_1.Service)()(target);
|
|
12
|
+
target.prototype.service = target;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.Echoes = Echoes;
|
|
16
|
+
function EchoRequest(options = {}) {
|
|
17
|
+
return function (target, propertyKey, descriptor) {
|
|
18
|
+
if (!descriptor.value)
|
|
19
|
+
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
20
|
+
target.echoes = target.echoes || {};
|
|
21
|
+
target.echoes[propertyKey] = (0, echo_1.default)({
|
|
22
|
+
...options,
|
|
23
|
+
type: 'request',
|
|
24
|
+
resolve: async (params, viewer) => {
|
|
25
|
+
const instance = (0, services_1.getInstance)(target.service);
|
|
26
|
+
return await instance[propertyKey](params, viewer);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.EchoRequest = EchoRequest;
|
|
32
|
+
function EchoEvent(options = {}) {
|
|
33
|
+
return function (target, propertyKey, descriptor) {
|
|
34
|
+
if (!descriptor.value)
|
|
35
|
+
throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
36
|
+
target.echoes = target.echoes || {};
|
|
37
|
+
target.echoes[propertyKey] = (0, echo_1.default)({
|
|
38
|
+
...options,
|
|
39
|
+
type: 'event',
|
|
40
|
+
resolve: async (params, viewer) => {
|
|
41
|
+
const instance = (0, services_1.getInstance)(target.service);
|
|
42
|
+
return await instance[propertyKey](params, viewer);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.EchoEvent = EchoEvent;
|
|
48
|
+
function getServiceEchoes(target) {
|
|
49
|
+
if (!target.prototype) {
|
|
50
|
+
throw new Error('You must pass a class to getServiceRoutes');
|
|
51
|
+
}
|
|
52
|
+
return target.prototype.echoes || {};
|
|
53
|
+
}
|
|
54
|
+
exports.getServiceEchoes = getServiceEchoes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,51 @@
|
|
|
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 _1 = require(".");
|
|
14
|
+
describe('Echoes with service injections', () => {
|
|
15
|
+
it('Should define a echoes map using services', async () => {
|
|
16
|
+
let ExampleEchoesService = class ExampleEchoesService {
|
|
17
|
+
async echo() {
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
async echoEvent() {
|
|
21
|
+
return 2;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, _1.EchoRequest)(),
|
|
26
|
+
__metadata("design:type", Function),
|
|
27
|
+
__metadata("design:paramtypes", []),
|
|
28
|
+
__metadata("design:returntype", Promise)
|
|
29
|
+
], ExampleEchoesService.prototype, "echo", null);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, _1.EchoEvent)(),
|
|
32
|
+
__metadata("design:type", Function),
|
|
33
|
+
__metadata("design:paramtypes", []),
|
|
34
|
+
__metadata("design:returntype", Promise)
|
|
35
|
+
], ExampleEchoesService.prototype, "echoEvent", null);
|
|
36
|
+
ExampleEchoesService = __decorate([
|
|
37
|
+
(0, _1.Echoes)()
|
|
38
|
+
], ExampleEchoesService);
|
|
39
|
+
const echoes = (0, _1.getServiceEchoes)(ExampleEchoesService);
|
|
40
|
+
expect(echoes).toMatchObject({
|
|
41
|
+
echo: {
|
|
42
|
+
type: 'request',
|
|
43
|
+
onRequest: expect.any(Function)
|
|
44
|
+
},
|
|
45
|
+
echoEvent: {
|
|
46
|
+
type: 'event',
|
|
47
|
+
resolve: expect.any(Function)
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
package/lib/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface EchoConfig {
|
|
|
3
3
|
type: 'event' | 'request';
|
|
4
4
|
resolve(params: any, context?: any): Promise<any>;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface EchoType extends EchoConfig {
|
|
7
7
|
onMessage(messageData: EachMessagePayload): Promise<void>;
|
|
8
8
|
onRequest(serializedParams: string): any;
|
|
9
9
|
}
|
|
@@ -54,20 +54,19 @@ export interface RequestsConfig {
|
|
|
54
54
|
*/
|
|
55
55
|
makeRequest?: RequestMaker;
|
|
56
56
|
}
|
|
57
|
+
export interface EchoesMap {
|
|
58
|
+
[key: string]: EchoType;
|
|
59
|
+
}
|
|
57
60
|
export interface EchoesOptions {
|
|
58
61
|
client?: KafkaConfig;
|
|
59
62
|
producer?: ProducerConfig;
|
|
60
63
|
consumer?: ConsumerConfig;
|
|
61
64
|
requests?: RequestsConfig;
|
|
62
|
-
echoes:
|
|
63
|
-
[key: string]: Echo;
|
|
64
|
-
};
|
|
65
|
+
echoes: EchoesMap;
|
|
65
66
|
}
|
|
66
67
|
export interface EchoesConfigHandler {
|
|
67
68
|
producer?: Producer;
|
|
68
69
|
consumer?: Consumer;
|
|
69
70
|
requests?: RequestsConfig;
|
|
70
|
-
echoes?:
|
|
71
|
-
[key: string]: Echo;
|
|
72
|
-
};
|
|
71
|
+
echoes?: EchoesMap;
|
|
73
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/echoes",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,10 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/helpers": "^3.2.0",
|
|
21
|
-
"@orion-js/http": "^3.2.
|
|
21
|
+
"@orion-js/http": "^3.2.4",
|
|
22
|
+
"@orion-js/services": "^3.2.0",
|
|
22
23
|
"axios": "^0.24.0",
|
|
23
24
|
"jssha": "^3.2.0",
|
|
24
25
|
"kafkajs": "^1.15.0",
|
|
26
|
+
"lodash": "^4.17.21",
|
|
25
27
|
"serialize-javascript": "^6.0.0"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
@@ -29,6 +31,7 @@
|
|
|
29
31
|
"@types/jest": "27.0.2",
|
|
30
32
|
"@types/supertest": "2.0.11",
|
|
31
33
|
"jest": "27.3.1",
|
|
34
|
+
"reflect-metadata": "^0.1.13",
|
|
32
35
|
"supertest": "^6.1.6",
|
|
33
36
|
"ts-jest": "27.0.7",
|
|
34
37
|
"typescript": "^4.4.4"
|
|
@@ -36,5 +39,5 @@
|
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|
|
38
41
|
},
|
|
39
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a1c4cff581b31f24896ec96a0a180d043dbf802a"
|
|
40
43
|
}
|