@orion-js/echoes 3.11.8 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/index.cjs +74298 -0
  2. package/dist/index.d.ts +124 -0
  3. package/dist/index.js +74262 -0
  4. package/package.json +25 -19
  5. package/LICENSE +0 -21
  6. package/lib/config.d.ts +0 -3
  7. package/lib/config.js +0 -4
  8. package/lib/echo/deserialize.d.ts +0 -1
  9. package/lib/echo/deserialize.js +0 -11
  10. package/lib/echo/index.d.ts +0 -9
  11. package/lib/echo/index.js +0 -29
  12. package/lib/echo/types.d.ts +0 -5
  13. package/lib/echo/types.js +0 -6
  14. package/lib/index.d.ts +0 -7
  15. package/lib/index.js +0 -43
  16. package/lib/publish/index.d.ts +0 -5
  17. package/lib/publish/index.js +0 -29
  18. package/lib/publish/serialize.d.ts +0 -1
  19. package/lib/publish/serialize.js +0 -13
  20. package/lib/request/getPassword.d.ts +0 -1
  21. package/lib/request/getPassword.js +0 -16
  22. package/lib/request/getSignature.d.ts +0 -1
  23. package/lib/request/getSignature.js +0 -15
  24. package/lib/request/getURL.d.ts +0 -1
  25. package/lib/request/getURL.js +0 -16
  26. package/lib/request/index.d.ts +0 -2
  27. package/lib/request/index.js +0 -57
  28. package/lib/request/makeRequest.d.ts +0 -2
  29. package/lib/request/makeRequest.js +0 -26
  30. package/lib/requestsHandler/checkSignature.d.ts +0 -1
  31. package/lib/requestsHandler/checkSignature.js +0 -13
  32. package/lib/requestsHandler/getEcho.d.ts +0 -1
  33. package/lib/requestsHandler/getEcho.js +0 -18
  34. package/lib/requestsHandler/index.d.ts +0 -3
  35. package/lib/requestsHandler/index.js +0 -44
  36. package/lib/service/index.d.ts +0 -8
  37. package/lib/service/index.js +0 -54
  38. package/lib/service/index.test.d.ts +0 -1
  39. package/lib/service/index.test.js +0 -51
  40. package/lib/startService/KafkaManager.d.ts +0 -24
  41. package/lib/startService/KafkaManager.js +0 -146
  42. package/lib/startService/index.d.ts +0 -3
  43. package/lib/startService/index.js +0 -33
  44. package/lib/tests/requests/index.test.d.ts +0 -1
  45. package/lib/tests/requests/index.test.js +0 -99
  46. package/lib/types.d.ts +0 -98
  47. package/lib/types.js +0 -2
package/package.json CHANGED
@@ -1,27 +1,28 @@
1
1
  {
2
2
  "name": "@orion-js/echoes",
3
- "version": "3.11.8",
4
- "main": "lib/index.js",
5
- "types": "lib/index.d.ts",
3
+ "version": "3.12.0",
4
+ "main": "./dist/index.cjs",
5
+ "types": "./dist/index.d.ts",
6
6
  "files": [
7
- "/lib"
7
+ "dist"
8
8
  ],
9
9
  "author": "nicolaslopezj",
10
10
  "license": "MIT",
11
11
  "scripts": {
12
- "test": "jest",
12
+ "test": "bun test",
13
13
  "prepare": "yarn run build",
14
- "clean": "rm -rf ./lib",
15
- "build": "yarn run clean && tsc",
14
+ "clean": "rm -rf ./dist",
15
+ "build": "bun run build.ts",
16
16
  "watch": "tsc -w",
17
- "upgrade-interactive": "yarn upgrade-interactive"
17
+ "upgrade-interactive": "yarn upgrade-interactive",
18
+ "dev": "bun --watch src/index.ts"
18
19
  },
19
20
  "dependencies": {
20
- "@orion-js/env": "^3.11.8",
21
- "@orion-js/helpers": "^3.11.8",
22
- "@orion-js/http": "^3.11.8",
23
- "@orion-js/schema": "^3.11.8",
24
- "@orion-js/services": "^3.11.8",
21
+ "@orion-js/env": "^4.0.0-alpha.2",
22
+ "@orion-js/helpers": "^4.0.0-alpha.2",
23
+ "@orion-js/http": "^4.0.0-alpha.2",
24
+ "@orion-js/schema": "^4.0.0-alpha.2",
25
+ "@orion-js/services": "^4.0.0-alpha.2",
25
26
  "axios": "^0.24.0",
26
27
  "jssha": "^3.2.0",
27
28
  "kafkajs": "^2.2.4",
@@ -29,16 +30,21 @@
29
30
  "serialize-javascript": "^6.0.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@types/jest": "27.0.2",
33
33
  "@types/supertest": "2.0.11",
34
- "jest": "27.3.1",
35
34
  "reflect-metadata": "^0.1.13",
36
35
  "supertest": "^6.1.6",
37
- "ts-jest": "27.0.7",
38
- "typescript": "^4.4.4"
36
+ "typescript": "^5.4.5",
37
+ "@types/bun": "^1.2.4"
39
38
  },
40
39
  "publishConfig": {
41
40
  "access": "public"
42
41
  },
43
- "gitHead": "78d70ac414964ec657cc000cedfad8a5efff5cc3"
44
- }
42
+ "gitHead": "9fd28b6f6b348cebc9f0dc207805647969277372",
43
+ "type": "module",
44
+ "module": "./dist/index.js",
45
+ "exports": {
46
+ "types": "./dist/index.d.ts",
47
+ "import": "./dist/index.js",
48
+ "require": "./dist/index.cjs"
49
+ }
50
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Orionjs Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/lib/config.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { EchoesConfigHandler } from './types';
2
- declare const config: EchoesConfigHandler;
3
- export default config;
package/lib/config.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {};
4
- exports.default = config;
@@ -1 +0,0 @@
1
- export default function (serializedJavascript: string): any;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1(serializedJavascript) {
4
- try {
5
- return eval('(' + serializedJavascript + ')');
6
- }
7
- catch (error) {
8
- throw new Error('Error deserializing echo message');
9
- }
10
- }
11
- exports.default = default_1;
@@ -1,9 +0,0 @@
1
- import { EchoType, EchoConfig } from '../types';
2
- declare const echo: {
3
- (options: EchoConfig): EchoType;
4
- types: {
5
- event: string;
6
- request: string;
7
- };
8
- };
9
- export default echo;
package/lib/echo/index.js DELETED
@@ -1,29 +0,0 @@
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
- const deserialize_1 = __importDefault(require("./deserialize"));
7
- const types_1 = __importDefault(require("./types"));
8
- const echo = function createNewEcho(options) {
9
- return {
10
- ...options,
11
- onMessage: async (messageData) => {
12
- const { message } = messageData;
13
- const data = (0, deserialize_1.default)(message.value.toString());
14
- const context = {
15
- ...messageData,
16
- data
17
- };
18
- await options.resolve(data.params || {}, context);
19
- },
20
- onRequest: async (serializedParams) => {
21
- const context = {};
22
- const params = (0, deserialize_1.default)(serializedParams);
23
- const result = await options.resolve(params || {}, context);
24
- return result;
25
- }
26
- };
27
- };
28
- echo.types = types_1.default;
29
- exports.default = echo;
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- event: string;
3
- request: string;
4
- };
5
- export default _default;
package/lib/echo/types.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- event: 'event',
5
- request: 'request'
6
- };
package/lib/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import startService, { stopService } from './startService';
2
- import publish from './publish';
3
- import echo from './echo';
4
- import request from './request';
5
- export * from './types';
6
- export * from './service';
7
- export { publish, startService, stopService, echo, request };
package/lib/index.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.request = exports.echo = exports.stopService = exports.startService = exports.publish = void 0;
33
- const startService_1 = __importStar(require("./startService"));
34
- exports.startService = startService_1.default;
35
- Object.defineProperty(exports, "stopService", { enumerable: true, get: function () { return startService_1.stopService; } });
36
- const publish_1 = __importDefault(require("./publish"));
37
- exports.publish = publish_1.default;
38
- const echo_1 = __importDefault(require("./echo"));
39
- exports.echo = echo_1.default;
40
- const request_1 = __importDefault(require("./request"));
41
- exports.request = request_1.default;
42
- __exportStar(require("./types"), exports);
43
- __exportStar(require("./service"), exports);
@@ -1,5 +0,0 @@
1
- import { PublishOptions } from '../types';
2
- /**
3
- * Publish
4
- */
5
- export default function publish<TParams = any>(options: PublishOptions<TParams>): Promise<import("kafkajs").RecordMetadata[]>;
@@ -1,29 +0,0 @@
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
- const config_1 = __importDefault(require("../config"));
7
- const serialize_1 = __importDefault(require("./serialize"));
8
- /**
9
- * Publish
10
- */
11
- async function publish(options) {
12
- if (!config_1.default.producer) {
13
- throw new Error('You must initialize echoes configruation to use publish');
14
- }
15
- const payload = {
16
- params: options.params,
17
- };
18
- return await config_1.default.producer.send({
19
- acks: options.acks,
20
- timeout: options.timeout,
21
- topic: options.topic,
22
- messages: [
23
- {
24
- value: (0, serialize_1.default)(payload),
25
- },
26
- ],
27
- });
28
- }
29
- exports.default = publish;
@@ -1 +0,0 @@
1
- export default function (data: any): string;
@@ -1,13 +0,0 @@
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
- const serialize_javascript_1 = __importDefault(require("serialize-javascript"));
7
- const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
8
- function default_1(data) {
9
- const cloned = (0, cloneDeep_1.default)(data);
10
- const serialized = (0, serialize_javascript_1.default)(cloned, { ignoreFunction: true });
11
- return serialized;
12
- }
13
- exports.default = default_1;
@@ -1 +0,0 @@
1
- export declare function getEchoesPassword(): string;
@@ -1,16 +0,0 @@
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.getEchoesPassword = void 0;
7
- const config_1 = __importDefault(require("../config"));
8
- const env_1 = require("@orion-js/env");
9
- function getEchoesPassword() {
10
- const secret = config_1.default?.requests?.key || (0, env_1.internalGetEnv)('echoes_password', 'ECHOES_PASSWORD');
11
- if (!secret) {
12
- console.warn('Warning: no secret key found for echoes requests. Init echoes or set the env var "echoes_password" or process.env.ECHOES_PASSWORD');
13
- }
14
- return secret;
15
- }
16
- exports.getEchoesPassword = getEchoesPassword;
@@ -1 +0,0 @@
1
- export default function (body: any): string;
@@ -1,15 +0,0 @@
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
- const jssha_1 = __importDefault(require("jssha"));
7
- const getPassword_1 = require("./getPassword");
8
- function default_1(body) {
9
- const password = (0, getPassword_1.getEchoesPassword)();
10
- const shaObj = new jssha_1.default('SHA-1', 'TEXT');
11
- shaObj.setHMACKey(password, 'TEXT');
12
- shaObj.update(body);
13
- return shaObj.getHMAC('HEX');
14
- }
15
- exports.default = default_1;
@@ -1 +0,0 @@
1
- export default function (serviceName: string): string;
@@ -1,16 +0,0 @@
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
- const config_1 = __importDefault(require("../config"));
7
- function default_1(serviceName) {
8
- if (serviceName.startsWith('http'))
9
- return serviceName;
10
- const url = config_1.default?.requests?.services[serviceName];
11
- if (!url) {
12
- throw new Error(`No URL found in echoes config for service ${serviceName}`);
13
- }
14
- return url;
15
- }
16
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { RequestOptions } from '../types';
2
- export default function request<TData = any, TParams = any>(options: RequestOptions<TParams>): Promise<TData>;
@@ -1,57 +0,0 @@
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
- const getURL_1 = __importDefault(require("./getURL"));
7
- const getSignature_1 = __importDefault(require("./getSignature"));
8
- const serialize_1 = __importDefault(require("../publish/serialize"));
9
- const deserialize_1 = __importDefault(require("../echo/deserialize"));
10
- const config_1 = __importDefault(require("../config"));
11
- const makeRequest_1 = require("./makeRequest");
12
- const schema_1 = require("@orion-js/schema");
13
- const helpers_1 = require("@orion-js/helpers");
14
- async function request(options) {
15
- const { method, service, params } = options;
16
- const serializedParams = (0, serialize_1.default)(params);
17
- const date = new Date();
18
- const body = { method, service, serializedParams, date };
19
- const signature = (0, getSignature_1.default)(body);
20
- try {
21
- const requestMaker = config_1.default?.requests?.makeRequest || makeRequest_1.makeRequest;
22
- const requestOptions = {
23
- url: (0, getURL_1.default)(service),
24
- retries: options.retries,
25
- timeout: options.timeout,
26
- data: {
27
- body,
28
- signature,
29
- },
30
- };
31
- const result = await requestMaker(requestOptions);
32
- if (result.statusCode !== 200) {
33
- throw new Error(`Wrong status code ${result.statusCode}`);
34
- }
35
- const data = result.data;
36
- if (data.error) {
37
- const info = data.errorInfo;
38
- if (info) {
39
- if (data.isValidationError) {
40
- throw new schema_1.ValidationError(info.validationErrors);
41
- }
42
- if (data.isUserError) {
43
- throw new helpers_1.UserError(info.error, info.message, info.extra);
44
- }
45
- }
46
- throw new Error(`${data.error}`);
47
- }
48
- const response = (0, deserialize_1.default)(data.result);
49
- return response;
50
- }
51
- catch (error) {
52
- if (error.isOrionError)
53
- throw error;
54
- throw new Error(`Echoes request network error calling ${service}/${method}: ${error.message}`);
55
- }
56
- }
57
- exports.default = request;
@@ -1,2 +0,0 @@
1
- import { RequestMaker } from '../types';
2
- export declare const makeRequest: RequestMaker;
@@ -1,26 +0,0 @@
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.makeRequest = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const helpers_1 = require("@orion-js/helpers");
9
- const makeRequest = async (options) => {
10
- const result = await (0, helpers_1.executeWithRetries)(async () => {
11
- return await (0, axios_1.default)({
12
- method: 'post',
13
- url: options.url,
14
- timeout: options.timeout,
15
- headers: {
16
- 'User-Agent': 'Orionjs-Echoes/1.1'
17
- },
18
- data: options.data
19
- });
20
- }, options.retries, 200);
21
- return {
22
- data: result.data,
23
- statusCode: result.status
24
- };
25
- };
26
- exports.makeRequest = makeRequest;
@@ -1 +0,0 @@
1
- export default function (body: any, signature: string): void;
@@ -1,13 +0,0 @@
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
- const getSignature_1 = __importDefault(require("../request/getSignature"));
7
- function default_1(body, signature) {
8
- const generatedSignature = (0, getSignature_1.default)(body);
9
- if (generatedSignature !== signature) {
10
- throw new Error('Echoes invalid signature');
11
- }
12
- }
13
- exports.default = default_1;
@@ -1 +0,0 @@
1
- export default function (method: string): import("..").EchoType;
@@ -1,18 +0,0 @@
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
- const config_1 = __importDefault(require("../config"));
7
- const types_1 = __importDefault(require("../echo/types"));
8
- function default_1(method) {
9
- const echo = config_1.default.echoes[method];
10
- if (!echo) {
11
- throw new Error(`Echo named ${method} not found in this service`);
12
- }
13
- if (echo.type !== types_1.default.request) {
14
- throw new Error(`Echo named ${method} is not of type request`);
15
- }
16
- return echo;
17
- }
18
- exports.default = default_1;
@@ -1,3 +0,0 @@
1
- import { EchoesOptions } from '../types';
2
- declare const _default: (options: EchoesOptions) => import("@orion-js/http").RouteType;
3
- export default _default;
@@ -1,44 +0,0 @@
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
- const getEcho_1 = __importDefault(require("./getEcho"));
7
- const serialize_1 = __importDefault(require("../publish/serialize"));
8
- const checkSignature_1 = __importDefault(require("./checkSignature"));
9
- const http_1 = require("@orion-js/http");
10
- exports.default = (options) => (0, http_1.route)({
11
- method: 'post',
12
- path: options.requests.handlerPath || '/echoes-services',
13
- bodyParser: 'json',
14
- bodyParserOptions: {
15
- limit: '10mb',
16
- },
17
- async resolve(req) {
18
- try {
19
- const { body, signature } = req.body;
20
- (0, checkSignature_1.default)(body, signature);
21
- const { method, serializedParams } = body;
22
- const echo = (0, getEcho_1.default)(method);
23
- const result = await echo.onRequest(serializedParams);
24
- return {
25
- body: {
26
- result: (0, serialize_1.default)(result),
27
- },
28
- };
29
- }
30
- catch (error) {
31
- if (!error.getInfo) {
32
- console.error('Error at echo requests handler:', error);
33
- }
34
- return {
35
- body: {
36
- error: error.message,
37
- errorInfo: error.getInfo ? error.getInfo() : null,
38
- isValidationError: !!error.isValidationError,
39
- isUserError: !!error.isUserError,
40
- },
41
- };
42
- }
43
- },
44
- });
@@ -1,8 +0,0 @@
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;
@@ -1,54 +0,0 @@
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;
@@ -1 +0,0 @@
1
- import 'reflect-metadata';
@@ -1,51 +0,0 @@
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
- });