@polymathnetwork/launchpad-redis 1.0.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.
- package/README.md +56 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +180 -0
- package/dist/client/index.js.map +1 -0
- package/dist/config/constants.d.ts +4 -0
- package/dist/config/constants.js +15 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/monitoring/datadog.d.ts +2 -0
- package/dist/monitoring/datadog.js +9 -0
- package/dist/monitoring/datadog.js.map +1 -0
- package/dist/monitoring/logger.d.ts +2 -0
- package/dist/monitoring/logger.js +28 -0
- package/dist/monitoring/logger.js.map +1 -0
- package/dist/scripts.d.ts +2 -0
- package/dist/scripts.js +91 -0
- package/dist/scripts.js.map +1 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/redis.d.ts +6 -0
- package/dist/types/redis.js +3 -0
- package/dist/types/redis.js.map +1 -0
- package/dist/util/client.d.ts +3 -0
- package/dist/util/client.js +22 -0
- package/dist/util/client.js.map +1 -0
- package/dist/util/command.d.ts +1 -0
- package/dist/util/command.js +19 -0
- package/dist/util/command.js.map +1 -0
- package/dist/util/script.d.ts +3 -0
- package/dist/util/script.js +19 -0
- package/dist/util/script.js.map +1 -0
- package/dist/util/search.d.ts +5 -0
- package/dist/util/search.js +26 -0
- package/dist/util/search.js.map +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
## launchpad-redis
|
|
2
|
+
|
|
3
|
+
## Setup redis instance:
|
|
4
|
+
|
|
5
|
+
RUN `docker pull redis/redis-stack`
|
|
6
|
+
|
|
7
|
+
RUN `docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -e REDIS_ARGS="--requirepass mypassword" redis/redis-stack:latest`
|
|
8
|
+
|
|
9
|
+
The docker run command above also exposes RedisInsight on port 8001. You can use RedisInsight by pointing your browser to http://localhost:8001
|
|
10
|
+
|
|
11
|
+
## Redis client Usage:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
const client = createRedisClient({
|
|
15
|
+
url: 'redis://:mypassword@localhost:6379',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await client.connect();
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await client.set('key', 'value');
|
|
22
|
+
} catch (error: any) {
|
|
23
|
+
logger.error(`SET ERROR: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const result = await client.get('key');
|
|
28
|
+
logger.info(`GET RESULT: ${result}`);
|
|
29
|
+
} catch (error: any) {
|
|
30
|
+
logger.error(`GET ERROR: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Client configuration options:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
connection: {
|
|
38
|
+
retryDelay: number;
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
};
|
|
41
|
+
commands: {
|
|
42
|
+
readCommandTimeout?: number;
|
|
43
|
+
};
|
|
44
|
+
scripts: LuaScriptDefinition[];
|
|
45
|
+
disableOfflineQueue: boolean;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
retryDelay (in ms): Attempt reconnection with redis server after retryAttemptNumber\*retryDelay
|
|
49
|
+
|
|
50
|
+
maxRetires: terminate redis client if connection to redis server fails after this number of retries
|
|
51
|
+
|
|
52
|
+
readCommandTimeout (in ms): read commands fail to resolve if this much time has passed without a response from the redis server
|
|
53
|
+
|
|
54
|
+
scripts: lua srcipts that will loaded onto redis and executable by calling `client.<script-name>`
|
|
55
|
+
|
|
56
|
+
disableOfflineQueue: determines whether or not commands are queued when the client is disconnected. If set to true, commands sent while the client is offline will be discarded instead of being queued for execution when the connection is restored. This can be useful to prevent unexpected behavior or memory issues in cases where the application should not continue processing commands during downtime.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createRedisClient = void 0;
|
|
16
|
+
const constants_1 = require("../config/constants");
|
|
17
|
+
const events_1 = __importDefault(require("events"));
|
|
18
|
+
const logger_1 = __importDefault(require("../monitoring/logger"));
|
|
19
|
+
const redis_1 = require("redis");
|
|
20
|
+
const scripts_1 = require("../scripts");
|
|
21
|
+
const command_1 = require("../util/command");
|
|
22
|
+
const script_1 = require("../util/script");
|
|
23
|
+
const search_1 = require("../util/search");
|
|
24
|
+
const client_1 = require("../util/client");
|
|
25
|
+
const createRedisClient = (config) => {
|
|
26
|
+
if (!config.url) {
|
|
27
|
+
throw new Error('Redis URL is required to create a client.');
|
|
28
|
+
}
|
|
29
|
+
let isReconnecting = false;
|
|
30
|
+
const options = Object.assign(Object.assign({}, constants_1.DEFAULT_CLIENT_CONFIG_OPTIONS), config.options);
|
|
31
|
+
const event = new events_1.default();
|
|
32
|
+
const client = (0, redis_1.createClient)({
|
|
33
|
+
url: config.url,
|
|
34
|
+
socket: {
|
|
35
|
+
connectTimeout: constants_1.CONNECTION_TIMEOUT,
|
|
36
|
+
reconnectStrategy: createReconnectStrategy(options.connection.retryDelay, options.connection.maxRetries),
|
|
37
|
+
},
|
|
38
|
+
scripts: Object.assign(Object.assign({}, scripts_1.systemScripts), (0, script_1.generateUserScripts)(options.scripts)),
|
|
39
|
+
disableOfflineQueue: options.disableOfflineQueue,
|
|
40
|
+
});
|
|
41
|
+
// EVENT LISTENERS
|
|
42
|
+
client.on('connect', () => {
|
|
43
|
+
logger_1.default.info('Connecting to Redis...');
|
|
44
|
+
});
|
|
45
|
+
client.on('reconnecting', () => {
|
|
46
|
+
isReconnecting = true;
|
|
47
|
+
logger_1.default.info('Attempting to reconnect to Redis...');
|
|
48
|
+
});
|
|
49
|
+
client.on('ready', () => {
|
|
50
|
+
if (isReconnecting) {
|
|
51
|
+
logger_1.default.info('Redis client reconnected successfully.');
|
|
52
|
+
event.emit('reconnected');
|
|
53
|
+
isReconnecting = false;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logger_1.default.info('Redis client is ready and connected.');
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
client.on('error', (err) => {
|
|
60
|
+
logger_1.default.error('Redis error:', err);
|
|
61
|
+
});
|
|
62
|
+
client.on('end', () => {
|
|
63
|
+
logger_1.default.info('Redis connection closed successfully.');
|
|
64
|
+
});
|
|
65
|
+
// PRIVATE METHODS
|
|
66
|
+
const deleteIndex = (indexName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
yield client.ft.dropIndex(indexName, {
|
|
69
|
+
DD: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger_1.default.error('Error deleting index:', error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const createIndex = (indexName, schema) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const schemaArgs = [
|
|
79
|
+
'FT.CREATE',
|
|
80
|
+
indexName,
|
|
81
|
+
'ON',
|
|
82
|
+
'JSON',
|
|
83
|
+
'PREFIX',
|
|
84
|
+
'1',
|
|
85
|
+
`${indexName}:`,
|
|
86
|
+
];
|
|
87
|
+
const redisearchSchema = (0, search_1.convertToRedisearchSchema)(schema);
|
|
88
|
+
try {
|
|
89
|
+
yield client.sendCommand([...schemaArgs, ...redisearchSchema]);
|
|
90
|
+
logger_1.default.info(`Index ${indexName} created successfully`);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logger_1.default.error(`Error creating index ${indexName}:`, error);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// PUBLIC METHODS
|
|
98
|
+
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
try {
|
|
100
|
+
client.connect();
|
|
101
|
+
if (options.disableOfflineQueue) {
|
|
102
|
+
yield (0, client_1.waitForReady)(client);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logger_1.default.error('Connection Failed.');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const quit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
client.quit();
|
|
111
|
+
});
|
|
112
|
+
const set = (key, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
return client.set(key, value);
|
|
114
|
+
});
|
|
115
|
+
const get = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
if (options.commands.readCommandTimeout) {
|
|
117
|
+
return (0, command_1.withCommandTimeout)(client, 'get', options.commands.readCommandTimeout, key);
|
|
118
|
+
}
|
|
119
|
+
return client.get(key);
|
|
120
|
+
});
|
|
121
|
+
const checkAndSetJson = (indexName, fieldName, fieldValue, jsonPayload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
return client.checkAndSetJson(indexName, fieldName, fieldValue, jsonPayload);
|
|
123
|
+
});
|
|
124
|
+
const getMostRecentEntryByDateField = (indexName, dateFieldName, filterFieldName, filterFieldValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
return client.getMostRecentEntryByDateField(indexName, dateFieldName, filterFieldName !== null && filterFieldName !== void 0 ? filterFieldName : '', filterFieldValue !== null && filterFieldValue !== void 0 ? filterFieldValue : '');
|
|
126
|
+
});
|
|
127
|
+
const loadOrResetIndex = (indexName, documentIdentifier, documentSchema, dataset) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
try {
|
|
129
|
+
const indexList = yield client.ft._list();
|
|
130
|
+
if (indexList.includes(indexName)) {
|
|
131
|
+
yield deleteIndex(indexName);
|
|
132
|
+
}
|
|
133
|
+
yield createIndex(indexName, documentSchema);
|
|
134
|
+
const redisearchDataset = (0, search_1.convertToRedisearchDataset)(dataset, indexName, documentIdentifier);
|
|
135
|
+
const result = yield client.loadDataScript(indexName, redisearchDataset);
|
|
136
|
+
logger_1.default.info(result);
|
|
137
|
+
return { ok: true };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
logger_1.default.error('Error loading or resetting index:', error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const baseMethods = {
|
|
145
|
+
connect,
|
|
146
|
+
quit,
|
|
147
|
+
get,
|
|
148
|
+
set,
|
|
149
|
+
checkAndSetJson,
|
|
150
|
+
getMostRecentEntryByDateField,
|
|
151
|
+
loadOrResetIndex,
|
|
152
|
+
};
|
|
153
|
+
if (options.scripts.length) {
|
|
154
|
+
attachUserScripts(client, baseMethods, options.scripts);
|
|
155
|
+
}
|
|
156
|
+
return Object.assign(Object.assign({}, baseMethods), { event });
|
|
157
|
+
};
|
|
158
|
+
exports.createRedisClient = createRedisClient;
|
|
159
|
+
const createReconnectStrategy = (reconnectDelay, maxRetries) => (retries, cause) => {
|
|
160
|
+
logger_1.default.error(`Connection failed. Cause: ${cause.message}`);
|
|
161
|
+
if (maxRetries && retries > maxRetries) {
|
|
162
|
+
logger_1.default.error('Too many attempts to reconnect. Redis connection was terminated');
|
|
163
|
+
return new Error('Too many retries.');
|
|
164
|
+
}
|
|
165
|
+
const jitter = Math.floor(Math.random() * 5) + 1;
|
|
166
|
+
const retryDelay = Math.min(retries * reconnectDelay, constants_1.MAX_RECONNECT_DELAY + jitter);
|
|
167
|
+
logger_1.default.info(`Attempting reconnection in ${retryDelay}ms`);
|
|
168
|
+
return retryDelay;
|
|
169
|
+
};
|
|
170
|
+
const attachUserScripts = (redisClient, baseMethods, scripts) => {
|
|
171
|
+
scripts.forEach(({ name }) => {
|
|
172
|
+
if (typeof baseMethods[name] === 'function') {
|
|
173
|
+
throw new Error(`${name} is a reserved name. Use a different script name`);
|
|
174
|
+
}
|
|
175
|
+
if (typeof redisClient[name] === 'function') {
|
|
176
|
+
baseMethods[name] = (...args) => redisClient[name](...args);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAI6B;AAC7B,oDAAkC;AAClC,kEAA0C;AAC1C,iCAAqC;AACrC,wCAA2C;AAQ3C,6CAAqD;AACrD,2CAAqD;AACrD,2CAIwB;AACxB,2CAA8C;AAEvC,MAAM,iBAAiB,GAAG,CAC/B,MAA2B,EACT,EAAE;IACpB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,OAAO,mCACR,yCAA6B,GAC7B,MAAM,CAAC,OAAO,CAClB,CAAC;IAEF,MAAM,KAAK,GAAG,IAAI,gBAAY,EAAE,CAAC;IAEjC,MAAM,MAAM,GAA4B,IAAA,oB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I,UAAU,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;QACvC,gBAAM,CAAC,KAAK,CACV,iEAAiE,CAClE,CAAC;QACF,OAAO,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CACzB,OAAO,GAAG,cAAc,EACxB,+BAAmB,GAAG,MAAM,CAC7B,CAAC;IACF,gBAAM,CAAC,IAAI,CAAC,8BAA8B,UAAU,IAAI,CAAC,CAAC;IAC1D,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEJ,MAAM,iBAAiB,GAAG,CACxB,WAAgB,EAChB,WAAgB,EAChB,OAA8B,EAC9B,EAAE;IACF,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;QAC3B,IAAI,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,kDAAkD,CAC1D,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YAC5C,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CLIENT_CONFIG_OPTIONS = exports.CONNECTION_TIMEOUT = exports.MAX_RECONNECT_DELAY = void 0;
|
|
4
|
+
exports.MAX_RECONNECT_DELAY = 1800000; // 30 minutes
|
|
5
|
+
exports.CONNECTION_TIMEOUT = 5000;
|
|
6
|
+
exports.DEFAULT_CLIENT_CONFIG_OPTIONS = {
|
|
7
|
+
connection: {
|
|
8
|
+
retryDelay: 500,
|
|
9
|
+
maxRetries: 15,
|
|
10
|
+
},
|
|
11
|
+
disableOfflineQueue: false,
|
|
12
|
+
commands: {},
|
|
13
|
+
scripts: [],
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/config/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,mBAAmB,GAAG,OAAO,CAAC,CAAC,aAAa;AAE5C,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAE1B,QAAA,6BAA6B,GAA+B;IACvE,UAAU,EAAE;QACV,UAAU,EAAE,GAAG;QACf,UAAU,EAAE,EAAE;KACf;IACD,mBAAmB,EAAE,KAAK;IAC1B,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,EAAE;CACZ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRedisClient = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "createRedisClient", { enumerable: true, get: function () { return client_1.createRedisClient; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAA6C;AAEpC,kGAFA,0BAAiB,OAEA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 dd_trace_1 = __importDefault(require("dd-trace"));
|
|
7
|
+
dd_trace_1.default.init();
|
|
8
|
+
exports.default = dd_trace_1.default;
|
|
9
|
+
//# sourceMappingURL=datadog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datadog.js","sourceRoot":"","sources":["../../src/monitoring/datadog.ts"],"names":[],"mappings":";;;;;AAAA,wDAA8B;AAE9B,kBAAM,CAAC,IAAI,EAAE,CAAC;AAEd,kBAAe,kBAAM,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 dd_trace_1 = __importDefault(require("dd-trace"));
|
|
7
|
+
const formats_1 = __importDefault(require("dd-trace/ext/formats"));
|
|
8
|
+
const winston_1 = require("winston");
|
|
9
|
+
const formatInfo = (0, winston_1.format)((info) => {
|
|
10
|
+
const span = dd_trace_1.default.scope().active();
|
|
11
|
+
if (span) {
|
|
12
|
+
dd_trace_1.default.inject(span.context(), formats_1.default.LOG, info);
|
|
13
|
+
}
|
|
14
|
+
return info;
|
|
15
|
+
});
|
|
16
|
+
function createProductionLogger() {
|
|
17
|
+
return (0, winston_1.createLogger)({
|
|
18
|
+
transports: [
|
|
19
|
+
new winston_1.transports.Console({
|
|
20
|
+
level: 'info',
|
|
21
|
+
format: winston_1.format.combine(formatInfo(), winston_1.format.json()),
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
exitOnError: false,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.default = createProductionLogger();
|
|
28
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/monitoring/logger.ts"],"names":[],"mappings":";;;;;AAAA,wDAA8B;AAC9B,mEAA2C;AAC3C,qCAA2D;AAE3D,MAAM,UAAU,GAAG,IAAA,gBAAM,EAAC,CAAC,IAAI,EAAE,EAAE;IACjC,MAAM,IAAI,GAAG,kBAAM,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC;IAErC,IAAI,IAAI,EAAE,CAAC;QACT,kBAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,iBAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,SAAS,sBAAsB;IAC7B,OAAO,IAAA,sBAAY,EAAC;QAClB,UAAU,EAAE;YACV,IAAI,oBAAU,CAAC,OAAO,CAAC;gBACrB,KAAK,EAAE,MAAM;gBACb,MAAM,EAAE,gBAAM,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,gBAAM,CAAC,IAAI,EAAE,CAAC;aACpD,CAAC;SACH;QACD,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;AACL,CAAC;AAED,kBAAe,sBAAsB,EAAE,CAAC"}
|
package/dist/scripts.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.systemScripts = void 0;
|
|
4
|
+
const redis_1 = require("redis");
|
|
5
|
+
exports.systemScripts = {
|
|
6
|
+
checkAndSetJson: (0, redis_1.defineScript)({
|
|
7
|
+
NUMBER_OF_KEYS: 1,
|
|
8
|
+
SCRIPT: `
|
|
9
|
+
local indexName = KEYS[1]
|
|
10
|
+
local fieldName = ARGV[1]
|
|
11
|
+
local fieldValue = ARGV[2]
|
|
12
|
+
local jsonPayload = ARGV[3]
|
|
13
|
+
|
|
14
|
+
local searchResult = redis.call('FT.SEARCH', indexName, '@' .. fieldName .. ':(' .. fieldValue .. ')', 'NOCONTENT')
|
|
15
|
+
|
|
16
|
+
if tonumber(searchResult[1]) > 0 then
|
|
17
|
+
return cjson.encode({ ok = "Field-value pair already exists, no new document created" })
|
|
18
|
+
else
|
|
19
|
+
local docId = indexName .. ':' .. fieldValue
|
|
20
|
+
redis.call('JSON.SET', docId, '$', jsonPayload)
|
|
21
|
+
return cjson.encode({ ok = "Document created successfully", id = docId })
|
|
22
|
+
end
|
|
23
|
+
`,
|
|
24
|
+
transformArguments(indexName, fieldName, fieldValue, jsonPayload) {
|
|
25
|
+
return [indexName, fieldName, fieldValue, JSON.stringify(jsonPayload)];
|
|
26
|
+
},
|
|
27
|
+
transformReply(reply) {
|
|
28
|
+
return JSON.parse(reply);
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
getMostRecentEntryByDateField: (0, redis_1.defineScript)({
|
|
32
|
+
NUMBER_OF_KEYS: 0,
|
|
33
|
+
SCRIPT: `
|
|
34
|
+
local indexName = ARGV[1]
|
|
35
|
+
local dateFieldName = ARGV[2]
|
|
36
|
+
local filterFieldName = ARGV[3]
|
|
37
|
+
local filterFieldValue = ARGV[4]
|
|
38
|
+
|
|
39
|
+
local query
|
|
40
|
+
|
|
41
|
+
if filterFieldName ~= '' and filterFieldValue ~= '' then
|
|
42
|
+
query = '@' .. filterFieldName .. ':(' .. filterFieldValue .. ')'
|
|
43
|
+
else
|
|
44
|
+
query = '*'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
local searchResult = redis.call('FT.SEARCH', indexName, query, 'SORTBY', dateFieldName, 'DESC', 'LIMIT', '0', '1')
|
|
48
|
+
|
|
49
|
+
if #searchResult == 0 then
|
|
50
|
+
return nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
local docID = searchResult[2]
|
|
54
|
+
return redis.call('JSON.GET', docID)
|
|
55
|
+
`,
|
|
56
|
+
transformArguments(indexName, dateFieldName, filterFieldName, filterFieldValue) {
|
|
57
|
+
return [indexName, dateFieldName, filterFieldName, filterFieldValue];
|
|
58
|
+
},
|
|
59
|
+
transformReply(reply) {
|
|
60
|
+
if (reply === null) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(reply);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw new Error('Failed to parse JSON reply: ' + e.message);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
loadDataScript: (0, redis_1.defineScript)({
|
|
72
|
+
NUMBER_OF_KEYS: 0,
|
|
73
|
+
SCRIPT: `
|
|
74
|
+
local indexName = ARGV[1]
|
|
75
|
+
local dataset = cjson.decode(ARGV[2])
|
|
76
|
+
|
|
77
|
+
for _, doc in ipairs(dataset) do
|
|
78
|
+
redis.call('JSON.SET', doc.id, '$', cjson.encode(doc))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
return 'Dataset has been loaded successfully'
|
|
82
|
+
`,
|
|
83
|
+
transformArguments(indexName, dataset) {
|
|
84
|
+
return [indexName, JSON.stringify(dataset)];
|
|
85
|
+
},
|
|
86
|
+
transformReply(reply) {
|
|
87
|
+
return reply;
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":";;;AAAA,iCAAmD;AAEtC,QAAA,aAAa,GAAiB;IACzC,eAAe,EAAE,IAAA,oBAAY,EAAC;QAC5B,cAAc,EAAE,CAAC;QACjB,MAAM,EAAE;;;;;;;;;;;;;;;OAeL;QACH,kBAAkB,CAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,WAAgC;YAEhC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;QACzE,CAAC;QACD,cAAc,CAAC,KAAa;YAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC;IAEF,6BAA6B,EAAE,IAAA,oBAAY,EAAC;QAC1C,cAAc,EAAE,CAAC;QACjB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;OAsBL;QACH,kBAAkB,CAChB,SAAiB,EACjB,aAAqB,EACrB,eAAuB,EACvB,gBAAwB;YAExB,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC;QACvE,CAAC;QACD,cAAc,CAAC,KAAa;YAC1B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;KACF,CAAC;IAEF,cAAc,EAAE,IAAA,oBAAY,EAAC;QAC3B,cAAc,EAAE,CAAC;QACjB,MAAM,EAAE;;;;;;;;;KASP;QACD,kBAAkB,CAAC,SAAiB,EAAE,OAA8B;YAClE,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,cAAc,CAAC,KAAa;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SchemaRecord } from '../util/search';
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
export type LuaScriptDefinition = {
|
|
4
|
+
name: string;
|
|
5
|
+
script: string;
|
|
6
|
+
numberOfKeys: number;
|
|
7
|
+
};
|
|
8
|
+
export type ClientConfigurationOptions = {
|
|
9
|
+
connection: {
|
|
10
|
+
retryDelay: number;
|
|
11
|
+
maxRetries?: number;
|
|
12
|
+
};
|
|
13
|
+
commands: {
|
|
14
|
+
readCommandTimeout?: number;
|
|
15
|
+
};
|
|
16
|
+
scripts: LuaScriptDefinition[];
|
|
17
|
+
disableOfflineQueue: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type ClientConfiguration = {
|
|
20
|
+
url: string;
|
|
21
|
+
options?: Partial<ClientConfigurationOptions>;
|
|
22
|
+
};
|
|
23
|
+
export type ClientReturnType = {
|
|
24
|
+
connect: () => Promise<void>;
|
|
25
|
+
quit: () => Promise<void>;
|
|
26
|
+
get: (key: string) => Promise<string | null>;
|
|
27
|
+
set: (key: string, value: string) => Promise<string | null>;
|
|
28
|
+
checkAndSetJson: (indexName: string, fieldName: string, fieldValue: string, jsonPayload: Record<string, any>) => Promise<Record<string, any>>;
|
|
29
|
+
getMostRecentEntryByDateField: (indexName: string, dateFieldName: string, filterFieldName?: string, filterFieldValue?: string) => Promise<Record<string, any> | null>;
|
|
30
|
+
loadOrResetIndex: (indexName: string, documentIdentifier: string, documentSchema: SchemaRecord, dataset: Record<string, any>[]) => Promise<{
|
|
31
|
+
ok: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
event: EventEmitter;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RedisClientType as OriginalRedisClientType, RedisModules, RedisDefaultModules, RedisFunctions, RedisScripts } from 'redis';
|
|
2
|
+
export type ExtendedRedisClientType<M extends RedisModules = RedisDefaultModules, F extends RedisFunctions = Record<string, never>, S extends RedisScripts = Record<string, never>> = OriginalRedisClientType<M, F, S> & {
|
|
3
|
+
checkAndSetJson: (indexName: string, fieldName: string, fieldValue: string, jsonPayload: Record<string, any>) => Promise<Record<string, any>>;
|
|
4
|
+
getMostRecentEntryByDateField: (indexName: string, dateFieldName: string, filterFieldName?: string, filterFieldValue?: string) => Promise<Record<string, any> | null>;
|
|
5
|
+
loadDataScript: (indexName: string, dataset: Record<string, any>) => Promise<Record<string, any>>;
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/types/redis.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForReady = exports.REDIS_URL_REGEX = void 0;
|
|
4
|
+
const constants_1 = require("../config/constants");
|
|
5
|
+
exports.REDIS_URL_REGEX = /^rediss?:\/\/(?:[a-zA-Z0-9._-]+(?::[a-zA-Z0-9._-]+)?@)?[a-zA-Z0-9.-]+:[0-9]{1,5}$/;
|
|
6
|
+
const waitForReady = (client) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const timeout = setTimeout(() => {
|
|
9
|
+
reject(new Error('Connection timeout'));
|
|
10
|
+
}, constants_1.CONNECTION_TIMEOUT);
|
|
11
|
+
client.once('ready', () => {
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
resolve();
|
|
14
|
+
});
|
|
15
|
+
client.once('error', (err) => {
|
|
16
|
+
clearTimeout(timeout);
|
|
17
|
+
reject(err);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.waitForReady = waitForReady;
|
|
22
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/util/client.ts"],"names":[],"mappings":";;;AAAA,mDAAyD;AAG5C,QAAA,eAAe,GAC1B,mFAAmF,CAAC;AAE/E,MAAM,YAAY,GAAG,CAC1B,MAA+B,EAChB,EAAE;IACjB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC1C,CAAC,EAAE,8BAAkB,CAAC,CAAC;QAEvB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YACxB,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAlBW,QAAA,YAAY,gBAkBvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const withCommandTimeout: (client: any, command: string, readCommandTimeout: number, ...args: any[]) => Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withCommandTimeout = void 0;
|
|
4
|
+
const withCommandTimeout = (client, command, readCommandTimeout, ...args) => new Promise((resolve, reject) => {
|
|
5
|
+
const timeout = setTimeout(() => {
|
|
6
|
+
reject(new Error(`Read command timeout: ${command}`));
|
|
7
|
+
}, readCommandTimeout);
|
|
8
|
+
client[command](...args)
|
|
9
|
+
.then((result) => {
|
|
10
|
+
clearTimeout(timeout);
|
|
11
|
+
resolve(result);
|
|
12
|
+
})
|
|
13
|
+
.catch((err) => {
|
|
14
|
+
clearTimeout(timeout);
|
|
15
|
+
reject(err);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
exports.withCommandTimeout = withCommandTimeout;
|
|
19
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/util/command.ts"],"names":[],"mappings":";;;AAAO,MAAM,kBAAkB,GAAG,CAChC,MAAW,EACX,OAAe,EACf,kBAA0B,EAC1B,GAAG,IAAW,EACG,EAAE,CACnB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9B,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAEvB,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;SACrB,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE;QACvB,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE;QAClB,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,MAAM,CAAC,GAAG,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AApBQ,QAAA,kBAAkB,sBAoB1B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUserScripts = void 0;
|
|
4
|
+
const redis_1 = require("redis");
|
|
5
|
+
const generateUserScripts = (scripts) => {
|
|
6
|
+
const redisScripts = {};
|
|
7
|
+
scripts.map(({ name, script, numberOfKeys }) => {
|
|
8
|
+
redisScripts[name] = (0, redis_1.defineScript)({
|
|
9
|
+
SCRIPT: script,
|
|
10
|
+
NUMBER_OF_KEYS: numberOfKeys,
|
|
11
|
+
transformArguments: (...args) => {
|
|
12
|
+
return args.map((arg) => arg.toString());
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return redisScripts;
|
|
17
|
+
};
|
|
18
|
+
exports.generateUserScripts = generateUserScripts;
|
|
19
|
+
//# sourceMappingURL=script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../src/util/script.ts"],"names":[],"mappings":";;;AAAA,iCAAmD;AAG5C,MAAM,mBAAmB,GAAG,CACjC,OAA8B,EAChB,EAAE;IAChB,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE;QAC7C,YAAY,CAAC,IAAI,CAAC,GAAG,IAAA,oBAAY,EAAC;YAChC,MAAM,EAAE,MAAM;YACd,cAAc,EAAE,YAAY;YAC5B,kBAAkB,EAAE,CAClB,GAAG,IAAmC,EACvB,EAAE;gBACjB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAjBW,QAAA,mBAAmB,uBAiB9B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type FieldType = 'TEXT' | 'NUMERIC' | 'TAG' | 'GEO' | 'DATE';
|
|
2
|
+
export type SchemaRecord = Record<string, FieldType>;
|
|
3
|
+
export declare const convertToRedisearchSchema: (schemaRecord: SchemaRecord) => string[];
|
|
4
|
+
export declare const convertToRedisearchDataset: (dataset: Record<string, any>[], prefix: string, documentIdentifier: string) => Record<string, any>[];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToRedisearchDataset = exports.convertToRedisearchSchema = void 0;
|
|
4
|
+
const convertToRedisearchSchema = (schemaRecord) => {
|
|
5
|
+
const schemaArgs = ['SCHEMA'];
|
|
6
|
+
for (const [fieldName, fieldType] of Object.entries(schemaRecord)) {
|
|
7
|
+
schemaArgs.push(`$.${fieldName}`);
|
|
8
|
+
schemaArgs.push(`AS`);
|
|
9
|
+
schemaArgs.push(fieldName);
|
|
10
|
+
schemaArgs.push(fieldType);
|
|
11
|
+
}
|
|
12
|
+
return schemaArgs;
|
|
13
|
+
};
|
|
14
|
+
exports.convertToRedisearchSchema = convertToRedisearchSchema;
|
|
15
|
+
const convertToRedisearchDataset = (dataset, prefix, documentIdentifier) => {
|
|
16
|
+
const result = [];
|
|
17
|
+
dataset.forEach((dataObject) => {
|
|
18
|
+
if (!dataObject[documentIdentifier]) {
|
|
19
|
+
throw new Error(`Bad Dataset. Missing document identifier field ${documentIdentifier}`);
|
|
20
|
+
}
|
|
21
|
+
result.push(Object.assign({ id: `${prefix}:${dataObject[documentIdentifier]}` }, dataObject));
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
exports.convertToRedisearchDataset = convertToRedisearchDataset;
|
|
26
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/util/search.ts"],"names":[],"mappings":";;;AAIO,MAAM,yBAAyB,GAAG,CACvC,YAA0B,EAChB,EAAE;IACZ,MAAM,UAAU,GAAa,CAAC,QAAQ,CAAC,CAAC;IACxC,KAAK,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAClE,UAAU,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC;QAClC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAZW,QAAA,yBAAyB,6BAYpC;AAEK,MAAM,0BAA0B,GAAG,CACxC,OAA8B,EAC9B,MAAc,EACd,kBAA0B,EACH,EAAE;IACzB,MAAM,MAAM,GAA0B,EAAE,CAAC;IAEzC,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7B,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,kDAAkD,kBAAkB,EAAE,CACvE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,IAAI,iBACT,EAAE,EAAE,GAAG,MAAM,IAAI,UAAU,CAAC,kBAAkB,CAAC,EAAE,IAC9C,UAAU,EACb,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AApBW,QAAA,0BAA0B,8BAoBrC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polymathnetwork/launchpad-redis",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "redis client abstraction for pcp services",
|
|
5
|
+
"author": "PolymathNetwork",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"private": false,
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": "18.0.0"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/PolymathNetwork/launchpad-redis"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rm -rf dist && tsc",
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
|
+
"semantic-release": "semantic-release"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
33
|
+
"@semantic-release/git": "^10.0.1",
|
|
34
|
+
"esbuild": "^0.20.2",
|
|
35
|
+
"semantic-release": "^19.0.5",
|
|
36
|
+
"typescript": "^5.4.5"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"dd-trace": "^5.20.0",
|
|
40
|
+
"redis": "^4.7.0",
|
|
41
|
+
"winston": "^3.14.1"
|
|
42
|
+
}
|
|
43
|
+
}
|