From c7fe5b1a4bbe48106bf364bae4bda7f8287acf0d Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 5 May 2021 09:40:03 +0300 Subject: [PATCH 01/12] feat(redis-client): Fix of issue when redis is restarted after shutting down. Two new methods for getting clients. --- package-lock.json | 181 ++++++++++++++++--------------- package.json | 2 +- ts/index.ts | 5 + ts/lib/request_response/index.ts | 11 +- 4 files changed, 109 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0dd44f9..4f511f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,8 +36,8 @@ "resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.6.tgz", "integrity": "sha512-kaSI4XQwCfJtPiuyCXvLxCaw2N0fMZesdob3Jh01W20vNFct+3lfvJ/4yCJxbSopXOBOzpg+pGxkW6uWZrPZHA==", "requires": { - "@types/events": "1.2.0", - "@types/node": "8.0.20" + "@types/events": "*", + "@types/node": "*" } }, "@types/uuid": { @@ -45,7 +45,7 @@ "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.3.tgz", "integrity": "sha512-5fRLCYhLtDb3hMWqQyH10qtF+Ud2JnNCXTCZ+9ktNdCcgslcuXkDTkFcJNk++MT29yDntDnlF1+jD+uVGumsbw==", "requires": { - "@types/node": "8.0.20" + "@types/node": "*" } }, "bluebird": { @@ -59,12 +59,12 @@ "integrity": "sha1-nkHoCOF6fxCAdyHirFpYnVuwkII=", "dev": true, "requires": { - "assertion-error": "1.1.0", - "check-error": "1.0.2", - "deep-eql": "2.0.2", - "get-func-name": "2.0.0", - "pathval": "1.1.0", - "type-detect": "4.0.8" + "assertion-error": "^1.0.1", + "check-error": "^1.0.1", + "deep-eql": "^2.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.0.0", + "type-detect": "^4.0.0" }, "dependencies": { "assertion-error": { @@ -85,7 +85,7 @@ "integrity": "sha1-sbrAblbwp2d3aG1Qyf63XC7XZ5o=", "dev": true, "requires": { - "type-detect": "3.0.0" + "type-detect": "^3.0.0" }, "dependencies": { "type-detect": { @@ -116,6 +116,11 @@ } } }, + "denque": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz", + "integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==" + }, "mocha": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.0.tgz", @@ -147,7 +152,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { - "balanced-match": "1.0.0", + "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, @@ -163,7 +168,7 @@ "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", "dev": true, "requires": { - "graceful-readlink": "1.0.1" + "graceful-readlink": ">= 1.0.0" } }, "concat-map": { @@ -205,12 +210,12 @@ "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", "dev": true, "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.2", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "graceful-readlink": { @@ -237,8 +242,8 @@ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -259,8 +264,8 @@ "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=", "dev": true, "requires": { - "lodash._basecopy": "3.0.1", - "lodash.keys": "3.1.2" + "lodash._basecopy": "^3.0.0", + "lodash.keys": "^3.0.0" } }, "lodash._basecopy": { @@ -293,9 +298,9 @@ "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=", "dev": true, "requires": { - "lodash._baseassign": "3.2.0", - "lodash._basecreate": "3.0.3", - "lodash._isiterateecall": "3.0.9" + "lodash._baseassign": "^3.0.0", + "lodash._basecreate": "^3.0.0", + "lodash._isiterateecall": "^3.0.0" } }, "lodash.isarguments": { @@ -316,9 +321,9 @@ "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=", "dev": true, "requires": { - "lodash._getnative": "3.9.1", - "lodash.isarguments": "3.1.0", - "lodash.isarray": "3.0.4" + "lodash._getnative": "^3.0.0", + "lodash.isarguments": "^3.0.0", + "lodash.isarray": "^3.0.0" } }, "minimatch": { @@ -327,7 +332,7 @@ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { - "brace-expansion": "1.1.11" + "brace-expansion": "^1.1.7" } }, "minimist": { @@ -357,7 +362,7 @@ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "path-is-absolute": { @@ -372,7 +377,7 @@ "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=", "dev": true, "requires": { - "has-flag": "1.0.0" + "has-flag": "^1.0.0" } }, "wrappy": { @@ -384,30 +389,32 @@ } }, "redis": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/redis/-/redis-2.7.1.tgz", - "integrity": "sha1-fVb3h1uYsgQQtxU58dh47Vjr9Go=", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz", + "integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==", "requires": { - "double-ended-queue": "2.1.0-0", - "redis-commands": "1.3.5", - "redis-parser": "2.6.0" - }, - "dependencies": { - "double-ended-queue": { - "version": "2.1.0-0", - "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz", - "integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw=" - }, - "redis-commands": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.3.5.tgz", - "integrity": "sha512-foGF8u6MXGFF++1TZVC6icGXuMYPftKXt1FBT2vrfU9ZATNtZJ8duRC5d1lEfE8hyVe3jhelHGB91oB7I6qLsA==" - }, - "redis-parser": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz", - "integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs=" - } + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" + } + }, + "redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=" + }, + "redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=", + "requires": { + "redis-errors": "^1.0.0" } }, "tslint": { @@ -416,16 +423,16 @@ "integrity": "sha1-EOjas+MGH6YelELozuOYKs8gpqo=", "dev": true, "requires": { - "babel-code-frame": "6.26.0", - "colors": "1.2.1", - "commander": "2.15.1", - "diff": "3.5.0", - "glob": "7.1.2", - "minimatch": "3.0.4", - "resolve": "1.7.1", - "semver": "5.5.0", - "tslib": "1.9.0", - "tsutils": "2.26.1" + "babel-code-frame": "^6.22.0", + "colors": "^1.1.2", + "commander": "^2.9.0", + "diff": "^3.2.0", + "glob": "^7.1.1", + "minimatch": "^3.0.4", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.7.1", + "tsutils": "^2.5.1" }, "dependencies": { "ansi-regex": { @@ -446,9 +453,9 @@ "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", "dev": true, "requires": { - "chalk": "1.1.3", - "esutils": "2.0.2", - "js-tokens": "3.0.2" + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" } }, "balanced-match": { @@ -463,7 +470,7 @@ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { - "balanced-match": "1.0.0", + "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, @@ -473,11 +480,11 @@ "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" } }, "colors": { @@ -528,12 +535,12 @@ "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "has-ansi": { @@ -542,7 +549,7 @@ "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", "dev": true, "requires": { - "ansi-regex": "2.1.1" + "ansi-regex": "^2.0.0" } }, "inflight": { @@ -551,8 +558,8 @@ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -573,7 +580,7 @@ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { - "brace-expansion": "1.1.11" + "brace-expansion": "^1.1.7" } }, "once": { @@ -582,7 +589,7 @@ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "path-is-absolute": { @@ -603,7 +610,7 @@ "integrity": "sha512-c7rwLofp8g1U+h1KNyHL/jicrKg1Ek4q+Lr33AL65uZTinUZHe30D5HlyN5V9NW0JX1D5dXQ4jqW5l7Sy/kGfw==", "dev": true, "requires": { - "path-parse": "1.0.5" + "path-parse": "^1.0.5" } }, "semver": { @@ -618,7 +625,7 @@ "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { - "ansi-regex": "2.1.1" + "ansi-regex": "^2.0.0" } }, "supports-color": { @@ -639,7 +646,7 @@ "integrity": "sha512-bnm9bcjOqOr1UljleL94wVCDlpa6KjfGaTkefeLch4GRafgDkROxPizbB/FxTEdI++5JqhxczRy/Qub0syNqZA==", "dev": true, "requires": { - "tslib": "1.9.0" + "tslib": "^1.8.1" } }, "wrappy": { diff --git a/package.json b/package.json index 12a248c..3484dac 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@types/uuid": "3.4.3", "@types/node": "8.0.20", "bluebird": "3.5.0", - "redis": "2.7.1", + "redis": "^3.1.2", "uuid": "3.2.1" }, "devDependencies": { diff --git a/ts/index.ts b/ts/index.ts index 0e6ba6e..cd74104 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -3,6 +3,7 @@ import { request, server, closeAllClients, enableServers, disableServers } from import { EpicurusRedisConfig, serverCallback, subscribeCallback } from './interface' import * as redis from 'redis' import * as bluebird from 'bluebird' +import { RedisClient } from 'redis' bluebird.promisifyAll(redis.RedisClient.prototype) bluebird.promisifyAll(redis.Multi.prototype) @@ -20,6 +21,8 @@ export default function Epicurus (redisConfig: EpicurusRedisConfig = { enableServers() return { + getRedisClient: () => redisClient, + getRedisSubClient: () => redisSub, subscribe: (channel: string, callback: subscribeCallback) => subscribe(redisSub, channel, callback), publish: (channel: string, body: any) => publish(redisClient, channel, body), server: (channel: string, callback: serverCallback) => server(redisClient, channel, callback), @@ -39,6 +42,8 @@ export default function Epicurus (redisConfig: EpicurusRedisConfig = { } export type EpicurusPublicInterface = { + getRedisClient: () => RedisClient + getRedisSubClient: () => RedisClient subscribe: (channel: string, callback: subscribeCallback) => Promise publish: (channel: string, body: any) => void server: (channel: string, callback: serverCallback) => Promise diff --git a/ts/lib/request_response/index.ts b/ts/lib/request_response/index.ts index beb7cca..84d0190 100644 --- a/ts/lib/request_response/index.ts +++ b/ts/lib/request_response/index.ts @@ -77,10 +77,17 @@ export async function server(redisClient, channel: string, callback: serve function brpop () { clientClone.brpop(channel, 0, async function (_null, popInfo) { + if (_null) { + console.error('BRPOP ERROR', _null) + } if (enableServers) { brpop() } + if (!popInfo) { + return + } + const reqId = popInfo[1] const rawRequest: string = await redisClient.getAsync(`${reqId}-ref`) await redisClient.delAsync(`${reqId}-ref`) @@ -90,8 +97,8 @@ export async function server(redisClient, channel: string, callback: serve if (req.ttl > Date.now() - config.requestValidityPeriod) { callback(req.body, async function (error, result) { const errorRef = error - ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1 } - : null + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1 } + : null let redisResponse: EpicurusResponse = { error: errorRef, From 0aade77ca6c8993c674c75277ab5191843f2eaa2 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 5 May 2021 10:23:44 +0300 Subject: [PATCH 02/12] AUTH-75. Fix of issue when redis is restarted after shutting down. Two new methods for getting clients. --- .gitignore | 2 +- js/config.d.ts | 3 + js/config.js | 6 ++ js/config.js.map | 1 + js/index.d.ts | 13 +++ js/index.js | 38 ++++++++ js/index.js.map | 1 + js/integration/client.d.ts | 1 + js/integration/client.js | 22 +++++ js/integration/client.js.map | 1 + js/integration/server.d.ts | 1 + js/integration/server.js | 15 +++ js/integration/server.js.map | 1 + js/interface.d.ts | 22 +++++ js/interface.js | 3 + js/interface.js.map | 1 + js/lib/error.d.ts | 17 ++++ js/lib/error.js | 18 ++++ js/lib/error.js.map | 1 + js/lib/pub_sub/index.d.ts | 6 ++ js/lib/pub_sub/index.js | 50 ++++++++++ js/lib/pub_sub/index.js.map | 1 + js/lib/request_response/index.d.ts | 6 ++ js/lib/request_response/index.js | 133 +++++++++++++++++++++++++++ js/lib/request_response/index.js.map | 1 + js/test/pub_sub.spec.d.ts | 1 + js/test/pub_sub.spec.js | 73 +++++++++++++++ js/test/pub_sub.spec.js.map | 1 + js/test/request_response.spec.d.ts | 1 + js/test/request_response.spec.js | 111 ++++++++++++++++++++++ js/test/request_response.spec.js.map | 1 + 31 files changed, 551 insertions(+), 1 deletion(-) create mode 100644 js/config.d.ts create mode 100644 js/config.js create mode 100644 js/config.js.map create mode 100644 js/index.d.ts create mode 100644 js/index.js create mode 100644 js/index.js.map create mode 100644 js/integration/client.d.ts create mode 100644 js/integration/client.js create mode 100644 js/integration/client.js.map create mode 100644 js/integration/server.d.ts create mode 100644 js/integration/server.js create mode 100644 js/integration/server.js.map create mode 100644 js/interface.d.ts create mode 100644 js/interface.js create mode 100644 js/interface.js.map create mode 100644 js/lib/error.d.ts create mode 100644 js/lib/error.js create mode 100644 js/lib/error.js.map create mode 100644 js/lib/pub_sub/index.d.ts create mode 100644 js/lib/pub_sub/index.js create mode 100644 js/lib/pub_sub/index.js.map create mode 100644 js/lib/request_response/index.d.ts create mode 100644 js/lib/request_response/index.js create mode 100644 js/lib/request_response/index.js.map create mode 100644 js/test/pub_sub.spec.d.ts create mode 100644 js/test/pub_sub.spec.js create mode 100644 js/test/pub_sub.spec.js.map create mode 100644 js/test/request_response.spec.d.ts create mode 100644 js/test/request_response.spec.js create mode 100644 js/test/request_response.spec.js.map diff --git a/.gitignore b/.gitignore index 091f0a9..eb79dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ node_modules -js +.idea diff --git a/js/config.d.ts b/js/config.d.ts new file mode 100644 index 0000000..1401757 --- /dev/null +++ b/js/config.d.ts @@ -0,0 +1,3 @@ +export declare const config: { + requestValidityPeriod: number; +}; diff --git a/js/config.js b/js/config.js new file mode 100644 index 0000000..286d043 --- /dev/null +++ b/js/config.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.config = { + requestValidityPeriod: 10000 +}; +//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/js/config.js.map b/js/config.js.map new file mode 100644 index 0000000..6843f87 --- /dev/null +++ b/js/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["../ts/config.ts"],"names":[],"mappings":";;AAAa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,KAAK;CAC7B,CAAA"} \ No newline at end of file diff --git a/js/index.d.ts b/js/index.d.ts new file mode 100644 index 0000000..8a1ee98 --- /dev/null +++ b/js/index.d.ts @@ -0,0 +1,13 @@ +import { EpicurusRedisConfig, serverCallback, subscribeCallback } from './interface'; +import { RedisClient } from 'redis'; +export default function Epicurus(redisConfig?: EpicurusRedisConfig): EpicurusPublicInterface; +export declare type EpicurusPublicInterface = { + getRedisClient: () => RedisClient; + getRedisSubClient: () => RedisClient; + subscribe: (channel: string, callback: subscribeCallback) => Promise; + publish: (channel: string, body: any) => void; + server: (channel: string, callback: serverCallback) => Promise; + request: (channel: string, body: any) => Promise; + shutdown: () => void; + close: () => void; +}; diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..ffa000d --- /dev/null +++ b/js/index.js @@ -0,0 +1,38 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const pub_sub_1 = require("./lib/pub_sub"); +const request_response_1 = require("./lib/request_response"); +const redis = require("redis"); +const bluebird = require("bluebird"); +bluebird.promisifyAll(redis.RedisClient.prototype); +bluebird.promisifyAll(redis.Multi.prototype); +function Epicurus(redisConfig = { + host: 'localhost', + port: 6379 +}) { + const redisClient = redis.createClient(redisConfig); + const redisSub = redis.createClient(redisConfig); + pub_sub_1.setupSubscriptionListener(redisSub); + request_response_1.enableServers(); + return { + getRedisClient: () => redisClient, + getRedisSubClient: () => redisSub, + subscribe: (channel, callback) => pub_sub_1.subscribe(redisSub, channel, callback), + publish: (channel, body) => pub_sub_1.publish(redisClient, channel, body), + server: (channel, callback) => request_response_1.server(redisClient, channel, callback), + request: (channel, body) => request_response_1.request(redisClient, channel, body), + shutdown: () => { + pub_sub_1.shutdownSubscribers(); + request_response_1.disableServers(); + }, + close: () => { + redisSub.unsubscribe(); + redisSub.quit(); + redisClient.quit(); + pub_sub_1.removeCallbacks(); + request_response_1.closeAllClients(); + } + }; +} +exports.default = Epicurus; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/js/index.js.map b/js/index.js.map new file mode 100644 index 0000000..1f6e184 --- /dev/null +++ b/js/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;AAAA,2CAAmH;AACnH,6DAAwG;AAExG,+BAA8B;AAC9B,qCAAoC;AAEpC,QAAQ,CAAC,YAAY,CAA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;KACF,CAAA;AACH,CAAC;AAhCD,2BAgCC"} \ No newline at end of file diff --git a/js/integration/client.d.ts b/js/integration/client.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/js/integration/client.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/js/integration/client.js b/js/integration/client.js new file mode 100644 index 0000000..f0eb3bd --- /dev/null +++ b/js/integration/client.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const http = require("http"); +const index_1 = require("../index"); +const epicurus = index_1.default(); +const server = http.createServer((req, res) => { + epicurus.request('findAccountBalanceHistory', { hello: 'world' }).then((r) => { + res.setHeader('Content-Type', 'text/html'); + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('ok'); + }).catch((e) => { + console.log(e.message); + res.writeHead(500, { 'Content-Type': 'text/plain' }); + res.end(); + }); +}); +server.on('clientError', (err, socket) => { + socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); +}); +server.listen(22222); +console.log('Epicurus Client booted on 22222. Will request findAccountBalanceHistory'); +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/js/integration/client.js.map b/js/integration/client.js.map new file mode 100644 index 0000000..fca6b19 --- /dev/null +++ b/js/integration/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../../ts/integration/client.ts"],"names":[],"mappings":";;AAAA,6BAA4B;AAC5B,oCAAwC;AACxC,MAAM,QAAQ,GAAG,eAAiB,EAAE,CAAA;AAEpC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC5C,QAAQ,CAAC,OAAO,CAAC,2BAA2B,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QAEzE,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAC1C,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAC,cAAc,EAAE,YAAY,EAAC,CAAC,CAAA;QAClD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QACtB,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAC,cAAc,EAAE,YAAY,EAAC,CAAC,CAAA;QAClD,GAAG,CAAC,GAAG,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;IACvC,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAA;AAChD,CAAC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACpB,OAAO,CAAC,GAAG,CAAC,yEAAyE,CAAC,CAAA"} \ No newline at end of file diff --git a/js/integration/server.d.ts b/js/integration/server.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/js/integration/server.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/js/integration/server.js b/js/integration/server.js new file mode 100644 index 0000000..d438266 --- /dev/null +++ b/js/integration/server.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_1 = require("../index"); +const epicurus = index_1.default(); +epicurus.server('findAccountBalanceHistory', function (msg, done) { + const responseBody = { + key: 'cake', + speed: 'slow', + distance: 'close', + when: 'now' + }; + done(null, responseBody); +}); +console.log('Epicurus Server booted. Listening on findAccountBalanceHistory'); +//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/js/integration/server.js.map b/js/integration/server.js.map new file mode 100644 index 0000000..a991429 --- /dev/null +++ b/js/integration/server.js.map @@ -0,0 +1 @@ +{"version":3,"file":"server.js","sourceRoot":"","sources":["../../ts/integration/server.ts"],"names":[],"mappings":";;AAAA,oCAAwC;AACxC,MAAM,QAAQ,GAAG,eAAiB,EAAE,CAAA;AAEpC,QAAQ,CAAC,MAAM,CAAC,2BAA2B,EAAE,UAAU,GAAG,EAAE,IAAI;IAC9D,MAAM,YAAY,GAAG;QACnB,GAAG,EAAE,MAAM;QACX,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,KAAK;KACZ,CAAA;IAED,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;AAC1B,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,GAAG,CAAC,gEAAgE,CAAC,CAAA"} \ No newline at end of file diff --git a/js/interface.d.ts b/js/interface.d.ts new file mode 100644 index 0000000..6713b22 --- /dev/null +++ b/js/interface.d.ts @@ -0,0 +1,22 @@ +export declare type serverCallback = (body: T & { + channel: string; +}, responseCallback: (error: any, response?: S) => any) => any; +export declare type subscribeCallback = (body: T & { + channel: string; +}) => any; +export interface EpicurusPubSubCallbackReference { + [channel: string]: Function[]; +} +export interface EpicurusRequest { + reqId: string; + body: any; + ttl: number; +} +export interface EpicurusResponse { + error?: any; + result?: any; +} +export interface EpicurusRedisConfig { + host: string; + port: number; +} diff --git a/js/interface.js b/js/interface.js new file mode 100644 index 0000000..d549d1f --- /dev/null +++ b/js/interface.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=interface.js.map \ No newline at end of file diff --git a/js/interface.js.map b/js/interface.js.map new file mode 100644 index 0000000..593f380 --- /dev/null +++ b/js/interface.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interface.js","sourceRoot":"","sources":["../ts/interface.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/js/lib/error.d.ts b/js/lib/error.d.ts new file mode 100644 index 0000000..d8b3219 --- /dev/null +++ b/js/lib/error.d.ts @@ -0,0 +1,17 @@ +export declare class EpicurusError extends Error { + id: number; + context: {}; + status: {}; + severity: number; + constructor(message: string, meta: { + context?: {}; + args?: any; + requestReference?: any; + severity: number; + status?: number; + id?: number; + stack?: string; + name?: string; + }); + toString(): string; +} diff --git a/js/lib/error.js b/js/lib/error.js new file mode 100644 index 0000000..f526d2b --- /dev/null +++ b/js/lib/error.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class EpicurusError extends Error { + constructor(message, meta) { + super(message); + this.id = meta.id || Number((Math.random() * 100000).toFixed(0)); + this.name = meta.name || this.name; + this.context = meta.context; + this.stack = new Error().stack; + this.status = meta.stack || meta.status; + this.severity = meta.severity; + } + toString() { + return this.name + ': ' + this.message; + } +} +exports.EpicurusError = EpicurusError; +//# sourceMappingURL=error.js.map \ No newline at end of file diff --git a/js/lib/error.js.map b/js/lib/error.js.map new file mode 100644 index 0000000..54be11b --- /dev/null +++ b/js/lib/error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"error.js","sourceRoot":"","sources":["../../ts/lib/error.ts"],"names":[],"mappings":";;AAAA,mBAA2B,SAAQ,KAAK;IAMtC,YACE,OAAe,EACf,IASC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAS,IAAI,KAAK,EAAG,CAAC,KAAK,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC/B,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAA;IACxC,CAAC;CACF;AA/BD,sCA+BC"} \ No newline at end of file diff --git a/js/lib/pub_sub/index.d.ts b/js/lib/pub_sub/index.d.ts new file mode 100644 index 0000000..93249a3 --- /dev/null +++ b/js/lib/pub_sub/index.d.ts @@ -0,0 +1,6 @@ +import { subscribeCallback } from '../../interface'; +export declare function subscribe(subClient: any, channel: string, callback: subscribeCallback): Promise; +export declare function publish(redisClient: any, channel: string, body: any): void; +export declare function setupSubscriptionListener(subClient: any): void; +export declare function shutdownSubscribers(): void; +export declare function removeCallbacks(): void; diff --git a/js/lib/pub_sub/index.js b/js/lib/pub_sub/index.js new file mode 100644 index 0000000..c8deeaa --- /dev/null +++ b/js/lib/pub_sub/index.js @@ -0,0 +1,50 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +let callbackReference = {}; +let enableMessageEvents; +function subscribe(subClient, channel, callback) { + subClient.subscribe(channel); + if (callbackReference[channel]) { + callbackReference[channel].push(callback); + } + else { + callbackReference[channel] = [callback]; + } + return new Promise((res) => { + subClient.on('subscribe', (channelSubscribedTo) => { + if (channel === channelSubscribedTo) { + res(); + } + }); + }); +} +exports.subscribe = subscribe; +function publish(redisClient, channel, body) { + const message = JSON.stringify(body); + redisClient.publish(channel, message); +} +exports.publish = publish; +function setupSubscriptionListener(subClient) { + enableMessageEvents = true; + subClient.on('message', function (channel, message) { + if (!enableMessageEvents) { + return; + } + const callbacks = callbackReference[channel]; + if (callbacks) { + let response = JSON.parse(message); + response.channel = channel; + callbacks.forEach(callback => callback(response)); + } + }); +} +exports.setupSubscriptionListener = setupSubscriptionListener; +function shutdownSubscribers() { + enableMessageEvents = false; +} +exports.shutdownSubscribers = shutdownSubscribers; +function removeCallbacks() { + callbackReference = {}; +} +exports.removeCallbacks = removeCallbacks; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/js/lib/pub_sub/index.js.map b/js/lib/pub_sub/index.js.map new file mode 100644 index 0000000..726edfa --- /dev/null +++ b/js/lib/pub_sub/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/pub_sub/index.ts"],"names":[],"mappings":";;AAEA,IAAI,iBAAiB,GAAoC,EAAE,CAAA;AAC3D,IAAI,mBAAmB,CAAA;AAEvB,mBAA6B,SAAS,EAAE,OAAe,EAAE,QAA8B;IACrF,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAE5B,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;QAC9B,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAC1C;SAAM;QACL,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;KACxC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,mBAAmB,EAAE,EAAE;YAChD,IAAI,OAAO,KAAK,mBAAmB,EAAE;gBACnC,GAAG,EAAE,CAAA;aACN;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAhBD,8BAgBC;AAED,iBAAwB,WAAW,EAAE,OAAe,EAAE,IAAI;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACpC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC;AAHD,0BAGC;AAED,mCAA2C,SAAS;IAClD,mBAAmB,GAAG,IAAI,CAAA;IAE1B,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,OAAe,EAAE,OAAO;QACxD,IAAI,CAAC,mBAAmB,EAAE;YACxB,OAAM;SACP;QAED,MAAM,SAAS,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC5C,IAAI,SAAS,EAAE;YACb,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAClC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAA;YAC1B,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;SAClD;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAfD,8DAeC;AAED;IACE,mBAAmB,GAAG,KAAK,CAAA;AAC7B,CAAC;AAFD,kDAEC;AAED;IACE,iBAAiB,GAAG,EAAE,CAAA;AACxB,CAAC;AAFD,0CAEC"} \ No newline at end of file diff --git a/js/lib/request_response/index.d.ts b/js/lib/request_response/index.d.ts new file mode 100644 index 0000000..6fe6e23 --- /dev/null +++ b/js/lib/request_response/index.d.ts @@ -0,0 +1,6 @@ +import { serverCallback } from '../../interface'; +export declare function request(redisClient: any, channel: string, body: any): Promise; +export declare function server(redisClient: any, channel: string, callback: serverCallback): Promise; +export declare function disableServers(): void; +export declare function enableServers(): void; +export declare function closeAllClients(): void; diff --git a/js/lib/request_response/index.js b/js/lib/request_response/index.js new file mode 100644 index 0000000..ecd27f2 --- /dev/null +++ b/js/lib/request_response/index.js @@ -0,0 +1,133 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const v4 = require("uuid/v4"); +const config_1 = require("../../config"); +const error_1 = require("../error"); +let clients = []; +let serversEnabled; +function request(redisClient, channel, body) { + return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () { + let responseValid = true; + const reqId = v4(); + const ttl = Date.now(); + const redisBody = { reqId, body, ttl }; + let timeout; + let timeoutFallback; + const clientClone = redisClient.duplicate(); + timeout = setTimeout(function () { + return __awaiter(this, void 0, void 0, function* () { + const reqCheck = yield redisClient.getAsync(`${reqId}-ref`); + if (!reqCheck) { + timeoutFallback = setTimeout(function () { + return __awaiter(this, void 0, void 0, function* () { + rej(new error_1.EpicurusError('No response from server', { + context: { originalRequest: body, channel: channel }, + severity: 2 + })); + responseValid = false; + clientClone.quit(); + }); + }, config_1.config.requestValidityPeriod); + } + else { + rej(new error_1.EpicurusError('Server not found', { + context: { originalRequest: body, channel: channel }, + severity: 2 + })); + responseValid = false; + clientClone.quit(); + } + }); + }, config_1.config.requestValidityPeriod + 100); + clientClone.brpop(reqId, 0, function (_null, popInfo) { + clearTimeout(timeout); + clearTimeout(timeoutFallback); + if (!responseValid) { + return; + } + const redisResponse = popInfo[1]; + const response = JSON.parse(redisResponse); + if (response.error) { + rej(new error_1.EpicurusError(response.error.message, { + severity: response.error.severity, + context: { + context: { originalRequest: body, channel: channel }, + stack: response.error.stack, + name: response.error.name + } + })); + } + else { + res(response.result); + } + clientClone.quit(); + }); + yield redisClient.setAsync(`${reqId}-ref`, JSON.stringify(redisBody)); + yield redisClient.lpushAsync(channel, reqId); + })); +} +exports.request = request; +function server(redisClient, channel, callback) { + return __awaiter(this, void 0, void 0, function* () { + const clientClone = redisClient.duplicate(); + clients.push(clientClone); + function brpop() { + clientClone.brpop(channel, 0, function (_null, popInfo) { + return __awaiter(this, void 0, void 0, function* () { + if (_null) { + console.error('BRPOP ERROR', _null); + } + if (enableServers) { + brpop(); + } + if (!popInfo) { + return; + } + const reqId = popInfo[1]; + const rawRequest = yield redisClient.getAsync(`${reqId}-ref`); + yield redisClient.delAsync(`${reqId}-ref`); + const req = JSON.parse(rawRequest); + req.body.channel = channel; + if (req.ttl > Date.now() - config_1.config.requestValidityPeriod) { + callback(req.body, function (error, result) { + return __awaiter(this, void 0, void 0, function* () { + const errorRef = error + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1 } + : null; + let redisResponse = { + error: errorRef, + result: result + }; + redisClient.lpush(req.reqId, JSON.stringify(redisResponse)); + }); + }); + } + }); + }); + } + brpop(); + }); +} +exports.server = server; +function disableServers() { + serversEnabled = false; + closeAllClients(); +} +exports.disableServers = disableServers; +function enableServers() { + serversEnabled = true; +} +exports.enableServers = enableServers; +function closeAllClients() { + clients.forEach(c => c.end(false)); +} +exports.closeAllClients = closeAllClients; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/js/lib/request_response/index.js.map b/js/lib/request_response/index.js.map new file mode 100644 index 0000000..1eef314 --- /dev/null +++ b/js/lib/request_response/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAC7B,yCAAqC;AACrC,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS;IAChE,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX,IAAI,eAAe,CAAA;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;QAE3C,OAAO,GAAG,UAAU,CAAC;;gBACnB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,CAAA;gBAG3D,IAAI,CAAC,QAAQ,EAAE;oBACb,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nD,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;oBAE1B,IAAI,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,eAAM,CAAC,qBAAqB,EAAE;wBACvD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,UAAgB,KAAK,EAAE,MAAM;;gCAC9C,MAAM,QAAQ,GAAG,KAAK;oCACpB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE;oCACjG,CAAC,CAAC,IAAI,CAAA;gCAER,IAAI,aAAa,GAAqB;oCACpC,KAAK,EAAE,QAAQ;oCACf,MAAM,EAAE,MAAM;iCACf,CAAA;gCAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;4BAC7D,CAAC;yBAAA,CAAC,CAAA;qBACH;gBACH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;CAAA;AAzCD,wBAyCC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file diff --git a/js/test/pub_sub.spec.d.ts b/js/test/pub_sub.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/js/test/pub_sub.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/js/test/pub_sub.spec.js b/js/test/pub_sub.spec.js new file mode 100644 index 0000000..8b416ca --- /dev/null +++ b/js/test/pub_sub.spec.js @@ -0,0 +1,73 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const index_1 = require("../index"); +describe('pubsub', () => { + let epicurus; + beforeEach(() => { + epicurus = index_1.default(); + }); + afterEach(() => { + epicurus.close(); + }); + describe('subscribe', () => { + it('a subscriber receives the correct message as an object', (done) => { + const msg = { hello: 'world' }; + epicurus.subscribe('sampleChannel', (msgReceived) => { + chai_1.expect(msgReceived).to.eql({ hello: 'world', channel: 'sampleChannel' }); + done(); + }).then(() => { + epicurus.publish('sampleChannel', msg); + }).catch(done); + }); + it('subscribers are correctly selective on message identity', (done) => { + const msg = { hello: 'world' }; + epicurus.subscribe('sampleChannel', (msgReceived) => { + chai_1.expect(msgReceived).to.eql({ hello: 'world', channel: 'sampleChannel' }); + done(); + }).then(() => { + return epicurus.subscribe('settlementReserved', (msgReceived) => { + done(new Error('Incorrect sub block')); + }); + }).then(() => { + epicurus.publish('sampleChannel', msg); + }).catch(done); + }); + it('does not process a message after the shutdown event has been received', (done) => { + const msg = { hello: 'world' }; + epicurus.subscribe('sampleChannel', (msgReceived) => { + done(new Error('Message should not have been received')); + }).then(() => { + epicurus.shutdown(); + epicurus.publish('sampleChannel', msg); + setTimeout(() => { + done(); + }, 10); + }).catch(done); + }); + }); + describe('publish', () => { + it('is able to send a message to multiple subscribers', (done) => { + let count = 0; + const msg = { hello: 'world' }; + epicurus.subscribe('sampleChannel', (msgReceived) => { + chai_1.expect(msgReceived).to.eql({ hello: 'world', channel: 'sampleChannel' }); + count++; + if (count === 2) { + done(); + } + }).then(() => { + return epicurus.subscribe('sampleChannel', (msgReceived) => { + chai_1.expect(msgReceived).to.eql({ hello: 'world', channel: 'sampleChannel' }); + count++; + if (count === 2) { + done(); + } + }); + }).then(() => { + epicurus.publish('sampleChannel', msg); + }).catch(done); + }); + }); +}); +//# sourceMappingURL=pub_sub.spec.js.map \ No newline at end of file diff --git a/js/test/pub_sub.spec.js.map b/js/test/pub_sub.spec.js.map new file mode 100644 index 0000000..542bf8b --- /dev/null +++ b/js/test/pub_sub.spec.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pub_sub.spec.js","sourceRoot":"","sources":["../../ts/test/pub_sub.spec.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,oCAA+B;AAE/B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,IAAI,QAAqC,CAAA;IACzC,UAAU,CAAC,GAAG,EAAE;QACd,QAAQ,GAAG,eAAQ,EAAE,CAAA;IACvB,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,wDAAwD,EAAE,CAAC,IAAI,EAAE,EAAE;YACpE,MAAM,GAAG,GAAG,EAAC,KAAK,EAAE,OAAO,EAAC,CAAA;YAE5B,QAAQ,CAAC,SAAS,CAAoB,eAAe,EAAE,CAAC,WAAW,EAAE,EAAE;gBACrE,aAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAC,CAAC,CAAA;gBACtE,IAAI,EAAE,CAAA;YACR,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gBACX,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;YACxC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,yDAAyD,EAAE,CAAC,IAAI,EAAE,EAAE;YACrE,MAAM,GAAG,GAAG,EAAC,KAAK,EAAE,OAAO,EAAC,CAAA;YAC5B,QAAQ,CAAC,SAAS,CAAC,e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AE,CAAC,mDAAmD,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/D,IAAI,KAAK,GAAG,CAAC,CAAA;YACb,MAAM,GAAG,GAAG,EAAC,KAAK,EAAE,OAAO,EAAC,CAAA;YAE5B,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,EAAE;gBAClD,aAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAC,CAAC,CAAA;gBACtE,KAAK,EAAE,CAAA;gBACP,IAAI,KAAK,KAAK,CAAC,EAAE;oBACf,IAAI,EAAE,CAAA;iBACP;YACH,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gBACX,OAAO,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,EAAE;oBACzD,aAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAC,CAAC,CAAA;oBACtE,KAAK,EAAE,CAAA;oBACP,IAAI,KAAK,KAAK,CAAC,EAAE;wBACf,IAAI,EAAE,CAAA;qBACP;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gBACX,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;YACxC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAEhB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/js/test/request_response.spec.d.ts b/js/test/request_response.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/js/test/request_response.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/js/test/request_response.spec.js b/js/test/request_response.spec.js new file mode 100644 index 0000000..6fde319 --- /dev/null +++ b/js/test/request_response.spec.js @@ -0,0 +1,111 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const index_1 = require("../index"); +describe('request response', () => { + let epicurus; + beforeEach(() => { + epicurus = index_1.default(); + }); + afterEach(() => { + epicurus.close(); + }); + describe('request', () => { + it('a request returns a promise that is resolved when the server finishes its callback', () => __awaiter(this, void 0, void 0, function* () { + epicurus.server('sampleEndpoint', function (request, callback) { + callback(null, { msg: 'hello' }); + }); + const result = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(result).to.eql({ msg: 'hello' }); + })); + it('a request is appropriately selective', () => __awaiter(this, void 0, void 0, function* () { + epicurus.server('sampleEndpoint', function (request, callback) { + callback(null, { msg: 'hello' }); + }); + epicurus.server('nonValidEndpoint', function (request, callback) { + callback(null, { msg: 'goodbye' }); + }); + const result = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(result).to.eql({ msg: 'hello' }); + })); + it('a request can receive multiple responses from the one server', () => __awaiter(this, void 0, void 0, function* () { + epicurus.server('sampleEndpoint', function (request, callback) { + callback(null, { msg: 'hello' }); + }); + const result = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(result).to.eql({ msg: 'hello' }); + const resultTwo = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(resultTwo).to.eql({ msg: 'hello' }); + const resultThree = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(resultThree).to.eql({ msg: 'hello' }); + })); + it('a request promise will be rejected if the server callbacks with an error', (done) => { + epicurus.server('sampleEndpoint', function (request, callback) { + callback(new Error('Err')); + }); + epicurus.request('sampleEndpoint', {}).catch((e) => { + chai_1.expect(e.name).to.eql('Error'); + chai_1.expect(e.message).to.eql('Err'); + done(); + }); + }); + it('only a single server receives a request', () => __awaiter(this, void 0, void 0, function* () { + let count = 0; + epicurus.server('sampleEndpoint', function (request, callback) { + count++; + callback(null, { msg: 'hello' }); + }); + epicurus.server('sampleEndpoint', function (request, callback) { + count++; + callback(null, { msg: 'hello' }); + }); + const result = yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(result).to.eql({ msg: 'hello' }); + chai_1.expect(count).to.eql(1); + })); + it('a server receives a request with the channel on it', () => __awaiter(this, void 0, void 0, function* () { + let serverChannelName = ''; + epicurus.server('sampleEndpoint', function (request, callback) { + serverChannelName = request.channel; + callback(null, { msg: 'hello' }); + }); + yield epicurus.request('sampleEndpoint', {}); + chai_1.expect(serverChannelName).to.eql('sampleEndpoint'); + })); + it('a server stops processing requests when shutdown is called', () => __awaiter(this, void 0, void 0, function* () { + const epicurusTwo = index_1.default(); + let count = 0; + let countTwo = 0; + epicurus.server('sampleEndpoint', (request, callback) => { + count++; + callback(null, { msg: 'hello' }); + }); + yield epicurus.request('sampleEndpoint', {}); + epicurus.shutdown(); + yield Promise.all([ + epicurus.request('sampleEndpoint', {}).then(() => { + chai_1.expect(count).to.eql(1); + chai_1.expect(countTwo).to.eql(1); + }), + new Promise((res, rej) => { + setTimeout(() => { + res(); + epicurusTwo.server('sampleEndpoint', (request, callback) => { + countTwo++; + callback(null, { msg: 'hello' }); + }); + }, 20); + }) + ]); + })); + }); +}); +//# sourceMappingURL=request_response.spec.js.map \ No newline at end of file diff --git a/js/test/request_response.spec.js.map b/js/test/request_response.spec.js.map new file mode 100644 index 0000000..6fdda4a --- /dev/null +++ b/js/test/request_response.spec.js.map @@ -0,0 +1 @@ +{"version":3,"file":"request_response.spec.js","sourceRoot":"","sources":["../../ts/test/request_response.spec.ts"],"names":[],"mappings":";;;;;;;;;;AA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,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;4BACzD,QAAQ,EAAE,CAAA;4BACV,QAAQ,CAAC,IAAI,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC,CAAC,CAAA;wBAChC,CAAC,CAAC,CAAA;oBACJ,CAAC,EAAE,EAAE,CAAC,CAAA;gBACR,CAAC,CAAC;aACH,CAAC,CAAA;QACJ,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} \ No newline at end of file From e6e11a85b264c3cd229835a07f3e41cdced3c901 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 17 May 2021 11:32:32 +0300 Subject: [PATCH 03/12] AUTH-75. Add error status to server response --- ts/lib/request_response/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/lib/request_response/index.ts b/ts/lib/request_response/index.ts index 84d0190..6326915 100644 --- a/ts/lib/request_response/index.ts +++ b/ts/lib/request_response/index.ts @@ -97,7 +97,7 @@ export async function server(redisClient, channel: string, callback: serve if (req.ttl > Date.now() - config.requestValidityPeriod) { callback(req.body, async function (error, result) { const errorRef = error - ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1 } + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } : null let redisResponse: EpicurusResponse = { From 212aa7ef9f0eee2f58e8225717fdfeb45f65812d Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 17 May 2021 11:33:32 +0300 Subject: [PATCH 04/12] AUTH-75. Up to v.0.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3484dac..3846f0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "epicurus-node", - "version": "0.3.0", + "version": "0.3.1", "description": "Redis request/response and PubSub sugar", "main": "js/index.js", "types": "js/index.d.ts", From ae07422a8a5df1e9ac2400be97a407d266f098a5 Mon Sep 17 00:00:00 2001 From: abhinavpaliwal271contentstack Date: Mon, 17 May 2021 14:16:32 +0530 Subject: [PATCH 05/12] AUTH-75 | Upgrade minor version --- package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3846f0d..e2e95ed 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,15 @@ { - "name": "epicurus-node", - "version": "0.3.1", + "name": "@contentstack/epicurus-node", + "version": "0.3.2", "description": "Redis request/response and PubSub sugar", "main": "js/index.js", "types": "js/index.d.ts", "files": [ "js/" ], + "publishConfig": { + "registry": "https://npm.pkg.github.com" + }, "scripts": { "prepublish": "npm run lint && rm -rf js/* && tsc --sourcemap -p ts/", "lint": "tslint 'ts/**/*.ts'", @@ -15,7 +18,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/ABXTrading/epicurus-node.git" + "url": "git+https://github.com/contentstack/epicurus-node.git" }, "keywords": [ "Redis" From 5ec29d89199c2d0711d1e76fb2769d51e0ebfae6 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 17 May 2021 11:51:17 +0300 Subject: [PATCH 06/12] AUTH-75. Up to v.0.3.2 --- js/lib/request_response/index.js | 2 +- js/lib/request_response/index.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/lib/request_response/index.js b/js/lib/request_response/index.js index ecd27f2..fcf5784 100644 --- a/js/lib/request_response/index.js +++ b/js/lib/request_response/index.js @@ -100,7 +100,7 @@ function server(redisClient, channel, callback) { callback(req.body, function (error, result) { return __awaiter(this, void 0, void 0, function* () { const errorRef = error - ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1 } + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } : null; let redisResponse = { error: errorRef, diff --git a/js/lib/request_response/index.js.map b/js/lib/request_response/index.js.map index 1eef314..3be7f10 100644 --- a/js/lib/request_response/index.js.map +++ b/js/lib/request_response/index.js.map @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AAI,CAAA;gCAER,IAAI,aAAa,GAAqB;oCACpC,KAAK,EAAE,QAAQ;oCACf,MAAM,EAAE,MAAM;iCACf,CAAA;gCAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;4BAC7D,CAAC;yBAAA,CAAC,CAAA;qBACH;gBACH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;CAAA;AAzCD,wBAyCC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAC7B,yCAAqC;AACrC,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS;IAChE,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX,IAAI,eAAe,CAAA;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;QAE3C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AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file From 3351237258bc3fabb223d79cd6b51cf84e9f793e Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 17 May 2021 12:02:25 +0300 Subject: [PATCH 07/12] AUTH-75. Add error status to request error handling --- ts/lib/error.ts | 2 +- ts/lib/request_response/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ts/lib/error.ts b/ts/lib/error.ts index ad996da..e6edfdb 100644 --- a/ts/lib/error.ts +++ b/ts/lib/error.ts @@ -22,7 +22,7 @@ export class EpicurusError extends Error { this.name = meta.name || this.name this.context = meta.context this.stack = (new Error()).stack - this.status = meta.stack || meta.status + this.status = meta.status || meta.stack this.severity = meta.severity } diff --git a/ts/lib/request_response/index.ts b/ts/lib/request_response/index.ts index 6326915..2ad5b10 100644 --- a/ts/lib/request_response/index.ts +++ b/ts/lib/request_response/index.ts @@ -52,6 +52,7 @@ export function request(redisClient, channel: string, body: any): Promise if (response.error) { rej(new EpicurusError(response.error.message, { + status: response.error.status, severity: response.error.severity, context: { context: { originalRequest: body, channel: channel }, From dde3b6136dc2428ca25636098c530674f619cba7 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 17 May 2021 12:07:49 +0300 Subject: [PATCH 08/12] AUTH-75. Add error status to request error handling --- js/lib/error.js | 2 +- js/lib/error.js.map | 2 +- js/lib/request_response/index.js | 1 + js/lib/request_response/index.js.map | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/js/lib/error.js b/js/lib/error.js index f526d2b..9f917bf 100644 --- a/js/lib/error.js +++ b/js/lib/error.js @@ -7,7 +7,7 @@ class EpicurusError extends Error { this.name = meta.name || this.name; this.context = meta.context; this.stack = new Error().stack; - this.status = meta.stack || meta.status; + this.status = meta.status || meta.stack; this.severity = meta.severity; } toString() { diff --git a/js/lib/error.js.map b/js/lib/error.js.map index 54be11b..3c08b30 100644 --- a/js/lib/error.js.map +++ b/js/lib/error.js.map @@ -1 +1 @@ -{"version":3,"file":"error.js","sourceRoot":"","sources":["../../ts/lib/error.ts"],"names":[],"mappings":";;AAAA,mBAA2B,SAAQ,KAAK;IAMtC,YACE,OAAe,EACf,IASC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAS,IAAI,KAAK,EAAG,CAAC,KAAK,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC/B,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAA;IACxC,CAAC;CACF;AA/BD,sCA+BC"} \ No newline at end of file +{"version":3,"file":"error.js","sourceRoot":"","sources":["../../ts/lib/error.ts"],"names":[],"mappings":";;AAAA,mBAA2B,SAAQ,KAAK;IAMtC,YACE,OAAe,EACf,IASC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3B,IAAI,CAAC,KAAK,GAAS,IAAI,KAAK,EAAG,CAAC,KAAK,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC/B,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAA;IACxC,CAAC;CACF;AA/BD,sCA+BC"} \ No newline at end of file diff --git a/js/lib/request_response/index.js b/js/lib/request_response/index.js index fcf5784..4d86dc7 100644 --- a/js/lib/request_response/index.js +++ b/js/lib/request_response/index.js @@ -57,6 +57,7 @@ function request(redisClient, channel, body) { const response = JSON.parse(redisResponse); if (response.error) { rej(new error_1.EpicurusError(response.error.message, { + status: response.error.status, severity: response.error.severity, context: { context: { originalRequest: body, channel: channel }, diff --git a/js/lib/request_response/index.js.map b/js/lib/request_response/index.js.map index 3be7f10..248121e 100644 --- a/js/lib/request_response/index.js.map +++ b/js/lib/request_response/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAC7B,yCAAqC;AACrC,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS;IAChE,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX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,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAC7B,yCAAqC;AACrC,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS;IAChE,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX,IAAI,eAAe,CAAA;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;QAE3C,OAAO,GAAG,UAAU,CAAC;;gBACnB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,CAAA;gBAG3D,IAAI,CAAC,QAAQ,EAAE;oBACb,eAAe,GAAG,UAAU,CAAC;;4BAC3B,GAAG,CAAC,IAAI,qBAAa,CAAC,yBAAyB,EAAE;gCAC/C,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;gCACpD,QAAQ,EAAE,CAAC;6BACZ,CAAC,CAAC,CAAA;4BAEH,aAAa,GAAG,KAAK,CAAA;4BACrB,WAAW,CAAC,IAAI,EAAE,CAAA;wBACpB,CAAC;qBAAA,EAAE,eAAM,CAAC,qBAAqB,CAAC,CAAA;iBACjC;qBAAM;oBACL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IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;oCACvH,CAAC,CAAC,IAAI,CAAA;gCAER,IAAI,aAAa,GAAqB;oCACpC,KAAK,EAAE,QAAQ;oCACf,MAAM,EAAE,MAAM;iCACf,CAAA;gCAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;4BAC7D,CAAC;yBAAA,CAAC,CAAA;qBACH;gBACH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;CAAA;AAzCD,wBAyCC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file From 9b6aa2d6c35d3f40f8df6466de788813f8d49191 Mon Sep 17 00:00:00 2001 From: anujcontentstack Date: Tue, 3 Aug 2021 13:15:35 +0530 Subject: [PATCH 09/12] AUTH-98 | Reduce requestValidityPeriod from 10s to 1s --- js/config.js | 2 +- js/config.js.map | 2 +- package-lock.json | 4 +-- package.json | 2 +- ts/config.ts | 2 +- ts/index.ts | 43 ++++++++++++++++++++++++-------- ts/lib/request_response/index.ts | 19 ++++++++------ 7 files changed, 51 insertions(+), 23 deletions(-) diff --git a/js/config.js b/js/config.js index 286d043..0e6b7e8 100644 --- a/js/config.js +++ b/js/config.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.config = { - requestValidityPeriod: 10000 + requestValidityPeriod: 1 * 1000 }; //# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/js/config.js.map b/js/config.js.map index 6843f87..0b90ddc 100644 --- a/js/config.js.map +++ b/js/config.js.map @@ -1 +1 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../ts/config.ts"],"names":[],"mappings":";;AAAa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,KAAK;CAC7B,CAAA"} \ No newline at end of file +{"version":3,"file":"config.js","sourceRoot":"","sources":["../ts/config.ts"],"names":[],"mappings":";;AAAa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,CAAC,GAAG,IAAI;CAChC,CAAA"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4f511f9..977106c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "epicurus-node", - "version": "0.3.0", + "name": "@contentstack/epicurus-node", + "version": "0.3.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e2e95ed..ec8f2e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/epicurus-node", - "version": "0.3.2", + "version": "0.3.4", "description": "Redis request/response and PubSub sugar", "main": "js/index.js", "types": "js/index.d.ts", diff --git a/ts/config.ts b/ts/config.ts index 20c6e17..6001dea 100644 --- a/ts/config.ts +++ b/ts/config.ts @@ -1,3 +1,3 @@ export const config = { - requestValidityPeriod: 10000 // milliseconds + requestValidityPeriod: 1 * 1000 // milliseconds } diff --git a/ts/index.ts b/ts/index.ts index cd74104..c8609c8 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,21 +1,44 @@ -import { subscribe, publish, setupSubscriptionListener, removeCallbacks, shutdownSubscribers } from './lib/pub_sub' -import { request, server, closeAllClients, enableServers, disableServers } from './lib/request_response' -import { EpicurusRedisConfig, serverCallback, subscribeCallback } from './interface' -import * as redis from 'redis' import * as bluebird from 'bluebird' +import * as redis from 'redis' import { RedisClient } from 'redis' + +import { config } from './config' +import { + EpicurusRedisConfig, + serverCallback, + subscribeCallback, +} from './interface' +import { + publish, + removeCallbacks, + setupSubscriptionListener, + shutdownSubscribers, + subscribe, +} from './lib/pub_sub' +import { + closeAllClients, + disableServers, + enableServers, + request, + server, +} from './lib/request_response' + bluebird.promisifyAll(redis.RedisClient.prototype) bluebird.promisifyAll(redis.Multi.prototype) -export default function Epicurus (redisConfig: EpicurusRedisConfig = { - host: 'localhost', - port: 6379 -}): EpicurusPublicInterface { +export default function Epicurus ( + redisConfig: EpicurusRedisConfig = { + host: 'localhost', + port: 6379 + }, + requestTimeout?: number +): EpicurusPublicInterface { // A separate subscription Redis client is required as once a client has // called SUBSCRIBE, it is put into a slave mode the does not allow any other // kind of action const redisClient = redis.createClient(redisConfig) const redisSub = redis.createClient(redisConfig) + const requestValidityPeriod = requestTimeout || config.requestValidityPeriod setupSubscriptionListener(redisSub) enableServers() @@ -25,8 +48,8 @@ export default function Epicurus (redisConfig: EpicurusRedisConfig = { getRedisSubClient: () => redisSub, subscribe: (channel: string, callback: subscribeCallback) => subscribe(redisSub, channel, callback), publish: (channel: string, body: any) => publish(redisClient, channel, body), - server: (channel: string, callback: serverCallback) => server(redisClient, channel, callback), - request: (channel: string, body: any) => request(redisClient, channel, body), + server: (channel: string, callback: serverCallback) => server(redisClient, channel, callback, requestValidityPeriod), + request: (channel: string, body: any) => request(redisClient, channel, body, requestValidityPeriod), shutdown: () => { shutdownSubscribers() disableServers() diff --git a/ts/lib/request_response/index.ts b/ts/lib/request_response/index.ts index 2ad5b10..874cb84 100644 --- a/ts/lib/request_response/index.ts +++ b/ts/lib/request_response/index.ts @@ -1,11 +1,16 @@ import * as v4 from 'uuid/v4' -import { config } from '../../config' + +import { + EpicurusRequest, + EpicurusResponse, + serverCallback, +} from '../../interface' import { EpicurusError } from '../error' -import { EpicurusRequest, EpicurusResponse, serverCallback } from '../../interface' + let clients = [] let serversEnabled -export function request(redisClient, channel: string, body: any): Promise { +export function request(redisClient, channel: string, body: any, requestValidityPeriod: number): Promise { return new Promise(async (res, rej) => { let responseValid = true const reqId = v4() @@ -28,7 +33,7 @@ export function request(redisClient, channel: string, body: any): Promise responseValid = false clientClone.quit() - }, config.requestValidityPeriod) + }, requestValidityPeriod) } else { rej(new EpicurusError('Server not found', { context: { originalRequest: body, channel: channel }, @@ -38,7 +43,7 @@ export function request(redisClient, channel: string, body: any): Promise responseValid = false clientClone.quit() } - }, config.requestValidityPeriod + 100) + }, requestValidityPeriod + 100) clientClone.brpop(reqId, 0, function (_null, popInfo) { clearTimeout(timeout) @@ -72,7 +77,7 @@ export function request(redisClient, channel: string, body: any): Promise }) } -export async function server(redisClient, channel: string, callback: serverCallback): Promise { +export async function server(redisClient, channel: string, callback: serverCallback, serverValidityPeriod: number): Promise { const clientClone = redisClient.duplicate() clients.push(clientClone) @@ -95,7 +100,7 @@ export async function server(redisClient, channel: string, callback: serve const req: EpicurusRequest = JSON.parse(rawRequest) req.body.channel = channel - if (req.ttl > Date.now() - config.requestValidityPeriod) { + if (req.ttl > Date.now() - serverValidityPeriod) { callback(req.body, async function (error, result) { const errorRef = error ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } From a96a2fc53d035d9cb38de466c7d449c3db952894 Mon Sep 17 00:00:00 2001 From: anujcontentstack Date: Tue, 3 Aug 2021 19:33:05 +0530 Subject: [PATCH 10/12] AUTH-98 | Run compile for epicurus package --- js/index.d.ts | 4 ++-- js/index.js | 12 +++++++----- js/index.js.map | 2 +- js/lib/request_response/index.d.ts | 4 ++-- js/lib/request_response/index.js | 11 +++++------ js/lib/request_response/index.js.map | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/js/index.d.ts b/js/index.d.ts index 8a1ee98..7b3c27f 100644 --- a/js/index.d.ts +++ b/js/index.d.ts @@ -1,6 +1,6 @@ -import { EpicurusRedisConfig, serverCallback, subscribeCallback } from './interface'; import { RedisClient } from 'redis'; -export default function Epicurus(redisConfig?: EpicurusRedisConfig): EpicurusPublicInterface; +import { EpicurusRedisConfig, serverCallback, subscribeCallback } from './interface'; +export default function Epicurus(redisConfig?: EpicurusRedisConfig, requestTimeout?: number): EpicurusPublicInterface; export declare type EpicurusPublicInterface = { getRedisClient: () => RedisClient; getRedisSubClient: () => RedisClient; diff --git a/js/index.js b/js/index.js index ffa000d..4bd422d 100644 --- a/js/index.js +++ b/js/index.js @@ -1,17 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const bluebird = require("bluebird"); +const redis = require("redis"); +const config_1 = require("./config"); const pub_sub_1 = require("./lib/pub_sub"); const request_response_1 = require("./lib/request_response"); -const redis = require("redis"); -const bluebird = require("bluebird"); bluebird.promisifyAll(redis.RedisClient.prototype); bluebird.promisifyAll(redis.Multi.prototype); function Epicurus(redisConfig = { host: 'localhost', port: 6379 -}) { +}, requestTimeout) { const redisClient = redis.createClient(redisConfig); const redisSub = redis.createClient(redisConfig); + const requestValidityPeriod = requestTimeout || config_1.config.requestValidityPeriod; pub_sub_1.setupSubscriptionListener(redisSub); request_response_1.enableServers(); return { @@ -19,8 +21,8 @@ function Epicurus(redisConfig = { getRedisSubClient: () => redisSub, subscribe: (channel, callback) => pub_sub_1.subscribe(redisSub, channel, callback), publish: (channel, body) => pub_sub_1.publish(redisClient, channel, body), - server: (channel, callback) => request_response_1.server(redisClient, channel, callback), - request: (channel, body) => request_response_1.request(redisClient, channel, body), + server: (channel, callback) => request_response_1.server(redisClient, channel, callback, requestValidityPeriod), + request: (channel, body) => request_response_1.request(redisClient, channel, body, requestValidityPeriod), shutdown: () => { pub_sub_1.shutdownSubscribers(); request_response_1.disableServers(); diff --git a/js/index.js.map b/js/index.js.map index 1f6e184..238c27a 100644 --- a/js/index.js.map +++ b/js/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;AAAA,2CAAmH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AAU,OAAe,EAAE,IAAS,EAAE,EAAE,CAAC,0BAAO,CAAI,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,qBAAqB,CAAC;QAC/G,QAAQ,EAAE,GAAG,EAAE;YACb,6BAAmB,EAAE,CAAA;YACrB,iCAAc,EAAE,CAAA;QAClB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,QAAQ,CAAC,WAAW,EAAE,CAAA;YACtB,QAAQ,CAAC,IAAI,EAAE,CAAA;YACf,WAAW,CAAC,IAAI,EAAE,CAAA;YAClB,yBAAe,EAAE,CAAA;YACjB,kCAAe,EAAE,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC;AApCD,2BAoCC"} \ No newline at end of file diff --git a/js/lib/request_response/index.d.ts b/js/lib/request_response/index.d.ts index 6fe6e23..da9eda2 100644 --- a/js/lib/request_response/index.d.ts +++ b/js/lib/request_response/index.d.ts @@ -1,6 +1,6 @@ import { serverCallback } from '../../interface'; -export declare function request(redisClient: any, channel: string, body: any): Promise; -export declare function server(redisClient: any, channel: string, callback: serverCallback): Promise; +export declare function request(redisClient: any, channel: string, body: any, requestValidityPeriod: number): Promise; +export declare function server(redisClient: any, channel: string, callback: serverCallback, serverValidityPeriod: number): Promise; export declare function disableServers(): void; export declare function enableServers(): void; export declare function closeAllClients(): void; diff --git a/js/lib/request_response/index.js b/js/lib/request_response/index.js index 4d86dc7..ab06695 100644 --- a/js/lib/request_response/index.js +++ b/js/lib/request_response/index.js @@ -9,11 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); const v4 = require("uuid/v4"); -const config_1 = require("../../config"); const error_1 = require("../error"); let clients = []; let serversEnabled; -function request(redisClient, channel, body) { +function request(redisClient, channel, body, requestValidityPeriod) { return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () { let responseValid = true; const reqId = v4(); @@ -35,7 +34,7 @@ function request(redisClient, channel, body) { responseValid = false; clientClone.quit(); }); - }, config_1.config.requestValidityPeriod); + }, requestValidityPeriod); } else { rej(new error_1.EpicurusError('Server not found', { @@ -46,7 +45,7 @@ function request(redisClient, channel, body) { clientClone.quit(); } }); - }, config_1.config.requestValidityPeriod + 100); + }, requestValidityPeriod + 100); clientClone.brpop(reqId, 0, function (_null, popInfo) { clearTimeout(timeout); clearTimeout(timeoutFallback); @@ -76,7 +75,7 @@ function request(redisClient, channel, body) { })); } exports.request = request; -function server(redisClient, channel, callback) { +function server(redisClient, channel, callback, serverValidityPeriod) { return __awaiter(this, void 0, void 0, function* () { const clientClone = redisClient.duplicate(); clients.push(clientClone); @@ -97,7 +96,7 @@ function server(redisClient, channel, callback) { yield redisClient.delAsync(`${reqId}-ref`); const req = JSON.parse(rawRequest); req.body.channel = channel; - if (req.ttl > Date.now() - config_1.config.requestValidityPeriod) { + if (req.ttl > Date.now() - serverValidityPeriod) { callback(req.body, function (error, result) { return __awaiter(this, void 0, void 0, function* () { const errorRef = error diff --git a/js/lib/request_response/index.js.map b/js/lib/request_response/index.js.map index 248121e..0afb236 100644 --- a/js/lib/request_response/index.js.map +++ b/js/lib/request_response/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAC7B,yCAAqC;AACrC,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS;IAChE,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACv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cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAO7B,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS,EAAE,qBAA6B;IAC/F,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX,IAAI,eAAe,CAAA;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;QAE3C,OAAO,GAAG,UAAU,CAAC;;gBACnB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,CAAA;gBAG3D,IAAI,CAAC,QAAQ,EAAE;oBACb,eAAe,GAAG,UAAU,CAAC;;4BAC3B,GAAG,CAAC,IAAI,qBAAa,CAAC,yBAAyB,EAAE;gCAC/C,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;gCACpD,QAAQ,EAAE,CAAC;6BACZ,CAAC,CAAC,CAAA;4BAEH,aAAa,GAAG,KAAK,CAAA;4BACrB,WAAW,CAAC,IAAI,EAAE,CAAA;w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G,KAAK;oCACpB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;oCACvH,CAAC,CAAC,IAAI,CAAA;gCAER,IAAI,aAAa,GAAqB;oCACpC,KAAK,EAAE,QAAQ;oCACf,MAAM,EAAE,MAAM;iCACf,CAAA;gCAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;4BAC7D,CAAC;yBAAA,CAAC,CAAA;qBACH;gBACH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;CAAA;AAzCD,wBAyCC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file From 4a4d76ffc3f212378a61bb24bb0ce0813642b856 Mon Sep 17 00:00:00 2001 From: anujcontentstack Date: Fri, 10 Dec 2021 12:51:14 +0530 Subject: [PATCH 11/12] AUTH-165 | Remove serverValidityPeriod check and add a ttl on redis response lpush --- js/lib/request_response/index.js | 26 +++++++++++----------- js/lib/request_response/index.js.map | 2 +- ts/lib/request_response/index.ts | 33 ++++++++++++++-------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/js/lib/request_response/index.js b/js/lib/request_response/index.js index ab06695..7bafe92 100644 --- a/js/lib/request_response/index.js +++ b/js/lib/request_response/index.js @@ -77,6 +77,7 @@ function request(redisClient, channel, body, requestValidityPeriod) { exports.request = request; function server(redisClient, channel, callback, serverValidityPeriod) { return __awaiter(this, void 0, void 0, function* () { + const REDIS_RESPONSE_TTL_IN_SECONDS = 1; const clientClone = redisClient.duplicate(); clients.push(clientClone); function brpop() { @@ -96,20 +97,19 @@ function server(redisClient, channel, callback, serverValidityPeriod) { yield redisClient.delAsync(`${reqId}-ref`); const req = JSON.parse(rawRequest); req.body.channel = channel; - if (req.ttl > Date.now() - serverValidityPeriod) { - callback(req.body, function (error, result) { - return __awaiter(this, void 0, void 0, function* () { - const errorRef = error - ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } - : null; - let redisResponse = { - error: errorRef, - result: result - }; - redisClient.lpush(req.reqId, JSON.stringify(redisResponse)); - }); + callback(req.body, function (error, result) { + return __awaiter(this, void 0, void 0, function* () { + const errorRef = error + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } + : null; + let redisResponse = { + error: errorRef, + result: result + }; + redisClient.lpush(req.reqId, JSON.stringify(redisResponse)); + redisClient.expire(req.reqId, REDIS_RESPONSE_TTL_IN_SECONDS); }); - } + }); }); }); } diff --git a/js/lib/request_response/index.js.map b/js/lib/request_response/index.js.map index 0afb236..e95a768 100644 --- a/js/lib/request_response/index.js.map +++ b/js/lib/request_response/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAO7B,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS,EAAE,qBAA6B;IAC/F,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,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AAE,CAAA;IACT,CAAC;CAAA;AAzCD,wBAyCC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/lib/request_response/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,8BAA6B;AAO7B,oCAAwC;AAExC,IAAI,OAAO,GAAG,EAAE,CAAA;AAChB,IAAI,cAAc,CAAA;AAElB,iBAA2B,WAAW,EAAE,OAAe,EAAE,IAAS,EAAE,qBAA6B;IAC/F,OAAO,IAAI,OAAO,CAAC,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,aAAa,GAAG,IAAI,CAAA;QACxB,MAAM,KAAK,GAAG,EAAE,EAAE,CAAA;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,SAAS,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;QACvD,IAAI,OAAO,CAAA;QACX,IAAI,eAAe,CAAA;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;QAE3C,OAAO,GAAG,UAAU,CAAC;;gBACnB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,CAAA;gBAG3D,IAAI,CAAC,QAAQ,EAAE;oBACb,eAAe,GAAG,UAAU,CAAC;;4BAC3B,GAAG,CAAC,IAAI,qBAAa,CAAC,yBAAyB,EAAE;gCAC/C,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAA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B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,UAAgB,KAAK,EAAE,MAAM;;4BAC9C,MAAM,QAAQ,GAAG,KAAK;gCACpB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;gCACvH,CAAC,CAAC,IAAI,CAAA;4BAER,IAAI,aAAa,GAAqB;gCACpC,KAAK,EAAE,QAAQ;gCACf,MAAM,EAAE,MAAM;6BACf,CAAA;4BAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;4BAC3D,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAA;wBAC9D,CAAC;qBAAA,CAAC,CAAA;gBAEJ,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,EAAE,CAAA;IACT,CAAC;CAAA;AA1CD,wBA0CC;AAED;IACE,cAAc,GAAG,KAAK,CAAA;IACtB,eAAe,EAAE,CAAA;AACnB,CAAC;AAHD,wCAGC;AAED;IACE,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC;AAFD,sCAEC;AAED;IACE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAFD,0CAEC"} \ No newline at end of file diff --git a/ts/lib/request_response/index.ts b/ts/lib/request_response/index.ts index 874cb84..f9cd874 100644 --- a/ts/lib/request_response/index.ts +++ b/ts/lib/request_response/index.ts @@ -78,10 +78,11 @@ export function request(redisClient, channel: string, body: any, requestValid } export async function server(redisClient, channel: string, callback: serverCallback, serverValidityPeriod: number): Promise { + const REDIS_RESPONSE_TTL_IN_SECONDS = 1 const clientClone = redisClient.duplicate() clients.push(clientClone) - function brpop () { + function brpop() { clientClone.brpop(channel, 0, async function (_null, popInfo) { if (_null) { console.error('BRPOP ERROR', _null) @@ -100,35 +101,35 @@ export async function server(redisClient, channel: string, callback: serve const req: EpicurusRequest = JSON.parse(rawRequest) req.body.channel = channel - if (req.ttl > Date.now() - serverValidityPeriod) { - callback(req.body, async function (error, result) { - const errorRef = error - ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } - : null + callback(req.body, async function (error, result) { + const errorRef = error + ? { name: error.name, message: error.message, stack: error.stack, severity: error.severity || 1, status: error.status } + : null - let redisResponse: EpicurusResponse = { - error: errorRef, - result: result - } + let redisResponse: EpicurusResponse = { + error: errorRef, + result: result + } + + redisClient.lpush(req.reqId, JSON.stringify(redisResponse)) + redisClient.expire(req.reqId, REDIS_RESPONSE_TTL_IN_SECONDS) + }) - redisClient.lpush(req.reqId, JSON.stringify(redisResponse)) - }) - } }) } brpop() } -export function disableServers () { +export function disableServers() { serversEnabled = false closeAllClients() } -export function enableServers () { +export function enableServers() { serversEnabled = true } -export function closeAllClients () { +export function closeAllClients() { clients.forEach(c => c.end(false)) } From 4bfcedf18efcb5c5e43ce4dcf03c04eaa866d54c Mon Sep 17 00:00:00 2001 From: anujcontentstack Date: Fri, 10 Dec 2021 12:56:36 +0530 Subject: [PATCH 12/12] AUTH-156 | Update package version to publish a new package --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ec8f2e5..3ec1aca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/epicurus-node", - "version": "0.3.4", + "version": "0.3.7", "description": "Redis request/response and PubSub sugar", "main": "js/index.js", "types": "js/index.d.ts", @@ -46,4 +46,4 @@ "tslint": "5.5.0", "mocha": "3.5.0" } -} +} \ No newline at end of file