@klapeks/micro-db-utils 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/backups/mysql.backup.d.ts +7 -0
  2. package/dist/backups/mysql.backup.js +156 -0
  3. package/dist/connections/cloud/s3.d.ts +23 -0
  4. package/dist/connections/cloud/s3.js +169 -0
  5. package/dist/connections/index.d.ts +5 -0
  6. package/dist/connections/index.js +25 -0
  7. package/dist/connections/kafka/index.d.ts +3 -0
  8. package/dist/connections/kafka/index.js +21 -0
  9. package/dist/connections/kafka/kafka.consumer.d.ts +13 -0
  10. package/dist/connections/kafka/kafka.consumer.js +128 -0
  11. package/dist/connections/kafka/kafka.d.ts +16 -0
  12. package/dist/connections/kafka/kafka.js +205 -0
  13. package/dist/connections/kafka/kafka.producer.d.ts +11 -0
  14. package/dist/connections/kafka/kafka.producer.js +101 -0
  15. package/dist/connections/mysql.connection.d.ts +15 -0
  16. package/dist/connections/mysql.connection.js +165 -0
  17. package/dist/connections/nosql/mongo.d.ts +56 -0
  18. package/dist/connections/nosql/mongo.js +192 -0
  19. package/dist/connections/nosql/redis.d.ts +310 -0
  20. package/dist/connections/nosql/redis.js +129 -0
  21. package/dist/connections/quiet.require.d.ts +1 -0
  22. package/dist/connections/quiet.require.js +12 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.js +20 -0
  25. package/dist/migrations/index.d.ts +1 -0
  26. package/dist/migrations/index.js +17 -0
  27. package/dist/migrations/mysql.migrations.d.ts +6 -0
  28. package/dist/migrations/mysql.migrations.js +220 -0
  29. package/dist/selectors/abstract.select.handler.d.ts +26 -0
  30. package/dist/selectors/abstract.select.handler.js +202 -0
  31. package/dist/selectors/index.d.ts +3 -0
  32. package/dist/selectors/index.js +19 -0
  33. package/dist/selectors/raw-mysql.select.handler.d.ts +17 -0
  34. package/dist/selectors/raw-mysql.select.handler.js +149 -0
  35. package/dist/selectors/typeorm.select.handler.d.ts +21 -0
  36. package/dist/selectors/typeorm.select.handler.js +187 -0
  37. package/dist/utils/columns.types.d.ts +100 -0
  38. package/dist/utils/columns.types.js +29 -0
  39. package/dist/utils/index.d.ts +3 -0
  40. package/dist/utils/index.js +21 -0
  41. package/dist/utils/iso.date.time.d.ts +2 -0
  42. package/dist/utils/iso.date.time.js +27 -0
  43. package/dist/utils/sqlite3.utils.d.ts +4 -0
  44. package/dist/utils/sqlite3.utils.js +60 -0
  45. package/dist/utils/where.utils.d.ts +3 -0
  46. package/dist/utils/where.utils.js +22 -0
  47. package/index.d.ts +1 -0
  48. package/index.js +2 -0
  49. package/package.json +37 -0
@@ -0,0 +1,192 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.MongoGeoPoint = exports.MongoDBConnection = exports.cursorOffsetAggregation = exports.flattenForUpdate = void 0;
40
+ var utils_1 = require("@klapeks/utils");
41
+ var quiet_require_1 = require("../quiet.require");
42
+ var mongooseModule = (0, quiet_require_1.quietRequire)('mongoose');
43
+ function flattenForUpdate(object, prefix) {
44
+ if (prefix === void 0) { prefix = ''; }
45
+ var _o = object;
46
+ var result = {};
47
+ for (var _i = 0, _a = Object.keys(object); _i < _a.length; _i++) {
48
+ var key = _a[_i];
49
+ if (typeof key != 'string' && typeof key != 'number')
50
+ continue;
51
+ if (_o[key] === undefined)
52
+ continue;
53
+ if (_o[key] === null || Array.isArray(_o[key]) || (_o[key] instanceof Date)) {
54
+ result[prefix + key] = _o[key];
55
+ continue;
56
+ }
57
+ if (typeof _o[key] == 'object') {
58
+ var nested = flattenForUpdate(_o[key], prefix + key + '.');
59
+ Object.assign(result, nested);
60
+ continue;
61
+ }
62
+ result[prefix + key] = _o[key];
63
+ }
64
+ return result;
65
+ }
66
+ exports.flattenForUpdate = flattenForUpdate;
67
+ function cursorOffsetAggregation(sortField, lastValue, fieldSort, idField, lastId) {
68
+ var _a, _b, _c;
69
+ return {
70
+ $match: {
71
+ $or: [(_a = {},
72
+ _a[sortField] = (_b = {}, _b[fieldSort == 'asc' ? '$gt' : '$lt'] = lastValue, _b),
73
+ _a), (_c = {},
74
+ _c[sortField] = lastValue,
75
+ _c[idField] = { $gt: lastId },
76
+ _c)]
77
+ }
78
+ };
79
+ }
80
+ exports.cursorOffsetAggregation = cursorOffsetAggregation;
81
+ var _databaseName = '';
82
+ var MongoDBConnection = /** @class */ (function () {
83
+ function MongoDBConnection() {
84
+ }
85
+ MongoDBConnection.createCounter = function (name) {
86
+ var _this = this;
87
+ if (name === void 0) { name = 'Counter'; }
88
+ // @ts-ignore
89
+ var _CounterSchema = new mongoose.Schema({
90
+ model: { type: String, required: true, unique: true },
91
+ counter: { type: Number, default: 0 }
92
+ }, {
93
+ versionKey: false
94
+ });
95
+ var CounterModel = mongooseModule === null || mongooseModule === void 0 ? void 0 : mongooseModule.model(name, _CounterSchema);
96
+ return {
97
+ model: CounterModel,
98
+ increment: function (model, increment) {
99
+ if (increment === void 0) { increment = 1; }
100
+ return __awaiter(_this, void 0, void 0, function () {
101
+ var counter;
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0: return [4 /*yield*/, CounterModel.findOneAndUpdate({ model: model }, { $inc: { counter: increment } }, // безопасно при параллелизме
105
+ { new: true, upsert: true } // создаёт запись при первом вызове
106
+ )];
107
+ case 1:
108
+ counter = _a.sent();
109
+ return [2 /*return*/, counter.counter];
110
+ }
111
+ });
112
+ });
113
+ },
114
+ set: function (model, value) { return __awaiter(_this, void 0, void 0, function () {
115
+ var counter;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0: return [4 /*yield*/, CounterModel.findOneAndUpdate({ model: model }, { $set: { counter: value } }, // безопасно при параллелизме
119
+ { new: true, upsert: true } // создаёт запись при первом вызове
120
+ )];
121
+ case 1:
122
+ counter = _a.sent();
123
+ return [2 /*return*/, counter.counter];
124
+ }
125
+ });
126
+ }); }
127
+ };
128
+ };
129
+ MongoDBConnection.getOptions = function () {
130
+ return {
131
+ // type: "mongo",
132
+ type: "mongo",
133
+ host: process.env.MONGO_DATABASE_HOST || '127.0.0.1',
134
+ port: Number(process.env.MONGO_DATABASE_PORT || '27017'),
135
+ username: process.env.MONGO_DATABASE_LOGIN || '',
136
+ password: process.env.MONGO_DATABASE_PASSWORD || '',
137
+ logging: true,
138
+ database: ""
139
+ };
140
+ };
141
+ MongoDBConnection.init = function (databaseName) {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var _a, host, port, password, username, mongoURI;
144
+ return __generator(this, function (_b) {
145
+ switch (_b.label) {
146
+ case 0:
147
+ if (_databaseName)
148
+ return [2 /*return*/];
149
+ _a = this.getOptions(), host = _a.host, port = _a.port, password = _a.password, username = _a.username;
150
+ mongoURI = 'mongodb://' + host + ':' + port + '/' + databaseName;
151
+ // logger.log(mongoURI);
152
+ if (!mongooseModule)
153
+ throw new Error("No mongoose module");
154
+ return [4 /*yield*/, mongooseModule.connect(mongoURI, {
155
+ auth: username ? {
156
+ username: username,
157
+ password: password,
158
+ } : undefined,
159
+ authSource: "admin"
160
+ })];
161
+ case 1:
162
+ _b.sent();
163
+ _databaseName = databaseName;
164
+ utils_1.logger.log("Mongo connected to database:", databaseName);
165
+ return [2 /*return*/];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ return MongoDBConnection;
171
+ }());
172
+ exports.MongoDBConnection = MongoDBConnection;
173
+ function _createDefaultMongoSchemas() {
174
+ if (!mongooseModule)
175
+ return {};
176
+ return {
177
+ // @ts-ignore
178
+ MongoGeoPoint: new mongooseModule.Schema({
179
+ type: {
180
+ type: String,
181
+ enum: ['Point'],
182
+ required: true,
183
+ default: 'Point'
184
+ },
185
+ coordinates: {
186
+ type: [Number],
187
+ required: true
188
+ }
189
+ }, { _id: false })
190
+ };
191
+ }
192
+ exports.MongoGeoPoint = _createDefaultMongoSchemas().MongoGeoPoint;
@@ -0,0 +1,310 @@
1
+ import type { createClient as REDIS_createClient } from 'redis';
2
+ export declare class RedisConnection {
3
+ readonly options: {
4
+ clientName: string;
5
+ keyPrefix: string;
6
+ };
7
+ readonly redisClient: ReturnType<typeof REDIS_createClient>;
8
+ constructor(options: {
9
+ clientName: string;
10
+ keyPrefix: string;
11
+ });
12
+ get keyPrefix(): string;
13
+ initialize(): Promise<import("@redis/client").RedisClientType<{
14
+ graph: {
15
+ CONFIG_GET: typeof import("@redis/graph/dist/commands/CONFIG_GET");
16
+ configGet: typeof import("@redis/graph/dist/commands/CONFIG_GET");
17
+ CONFIG_SET: typeof import("@redis/graph/dist/commands/CONFIG_SET");
18
+ configSet: typeof import("@redis/graph/dist/commands/CONFIG_SET");
19
+ DELETE: typeof import("@redis/graph/dist/commands/DELETE");
20
+ delete: typeof import("@redis/graph/dist/commands/DELETE");
21
+ EXPLAIN: typeof import("@redis/graph/dist/commands/EXPLAIN");
22
+ explain: typeof import("@redis/graph/dist/commands/EXPLAIN");
23
+ LIST: typeof import("@redis/graph/dist/commands/LIST");
24
+ list: typeof import("@redis/graph/dist/commands/LIST");
25
+ PROFILE: typeof import("@redis/graph/dist/commands/PROFILE");
26
+ profile: typeof import("@redis/graph/dist/commands/PROFILE");
27
+ QUERY: typeof import("@redis/graph/dist/commands/QUERY");
28
+ query: typeof import("@redis/graph/dist/commands/QUERY");
29
+ RO_QUERY: typeof import("@redis/graph/dist/commands/RO_QUERY");
30
+ roQuery: typeof import("@redis/graph/dist/commands/RO_QUERY");
31
+ SLOWLOG: typeof import("@redis/graph/dist/commands/SLOWLOG");
32
+ slowLog: typeof import("@redis/graph/dist/commands/SLOWLOG");
33
+ };
34
+ json: {
35
+ ARRAPPEND: typeof import("@redis/json/dist/commands/ARRAPPEND");
36
+ arrAppend: typeof import("@redis/json/dist/commands/ARRAPPEND");
37
+ ARRINDEX: typeof import("@redis/json/dist/commands/ARRINDEX");
38
+ arrIndex: typeof import("@redis/json/dist/commands/ARRINDEX");
39
+ ARRINSERT: typeof import("@redis/json/dist/commands/ARRINSERT");
40
+ arrInsert: typeof import("@redis/json/dist/commands/ARRINSERT");
41
+ ARRLEN: typeof import("@redis/json/dist/commands/ARRLEN");
42
+ arrLen: typeof import("@redis/json/dist/commands/ARRLEN");
43
+ ARRPOP: typeof import("@redis/json/dist/commands/ARRPOP");
44
+ arrPop: typeof import("@redis/json/dist/commands/ARRPOP");
45
+ ARRTRIM: typeof import("@redis/json/dist/commands/ARRTRIM");
46
+ arrTrim: typeof import("@redis/json/dist/commands/ARRTRIM");
47
+ DEBUG_MEMORY: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
48
+ debugMemory: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
49
+ DEL: typeof import("@redis/json/dist/commands/DEL");
50
+ del: typeof import("@redis/json/dist/commands/DEL");
51
+ FORGET: typeof import("@redis/json/dist/commands/FORGET");
52
+ forget: typeof import("@redis/json/dist/commands/FORGET");
53
+ GET: typeof import("@redis/json/dist/commands/GET");
54
+ get: typeof import("@redis/json/dist/commands/GET");
55
+ MERGE: typeof import("@redis/json/dist/commands/MERGE");
56
+ merge: typeof import("@redis/json/dist/commands/MERGE");
57
+ MGET: typeof import("@redis/json/dist/commands/MGET");
58
+ mGet: typeof import("@redis/json/dist/commands/MGET");
59
+ MSET: typeof import("@redis/json/dist/commands/MSET");
60
+ mSet: typeof import("@redis/json/dist/commands/MSET");
61
+ NUMINCRBY: typeof import("@redis/json/dist/commands/NUMINCRBY");
62
+ numIncrBy: typeof import("@redis/json/dist/commands/NUMINCRBY");
63
+ NUMMULTBY: typeof import("@redis/json/dist/commands/NUMMULTBY");
64
+ numMultBy: typeof import("@redis/json/dist/commands/NUMMULTBY");
65
+ OBJKEYS: typeof import("@redis/json/dist/commands/OBJKEYS");
66
+ objKeys: typeof import("@redis/json/dist/commands/OBJKEYS");
67
+ OBJLEN: typeof import("@redis/json/dist/commands/OBJLEN");
68
+ objLen: typeof import("@redis/json/dist/commands/OBJLEN");
69
+ RESP: typeof import("@redis/json/dist/commands/RESP");
70
+ resp: typeof import("@redis/json/dist/commands/RESP");
71
+ SET: typeof import("@redis/json/dist/commands/SET");
72
+ set: typeof import("@redis/json/dist/commands/SET");
73
+ STRAPPEND: typeof import("@redis/json/dist/commands/STRAPPEND");
74
+ strAppend: typeof import("@redis/json/dist/commands/STRAPPEND");
75
+ STRLEN: typeof import("@redis/json/dist/commands/STRLEN");
76
+ strLen: typeof import("@redis/json/dist/commands/STRLEN");
77
+ TYPE: typeof import("@redis/json/dist/commands/TYPE");
78
+ type: typeof import("@redis/json/dist/commands/TYPE");
79
+ };
80
+ ft: {
81
+ _LIST: typeof import("@redis/search/dist/commands/_LIST");
82
+ _list: typeof import("@redis/search/dist/commands/_LIST");
83
+ ALTER: typeof import("@redis/search/dist/commands/ALTER");
84
+ alter: typeof import("@redis/search/dist/commands/ALTER");
85
+ AGGREGATE_WITHCURSOR: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
86
+ aggregateWithCursor: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
87
+ AGGREGATE: typeof import("@redis/search/dist/commands/AGGREGATE");
88
+ aggregate: typeof import("@redis/search/dist/commands/AGGREGATE");
89
+ ALIASADD: typeof import("@redis/search/dist/commands/ALIASADD");
90
+ aliasAdd: typeof import("@redis/search/dist/commands/ALIASADD");
91
+ ALIASDEL: typeof import("@redis/search/dist/commands/ALIASDEL");
92
+ aliasDel: typeof import("@redis/search/dist/commands/ALIASDEL");
93
+ ALIASUPDATE: typeof import("@redis/search/dist/commands/ALIASUPDATE");
94
+ aliasUpdate: typeof import("@redis/search/dist/commands/ALIASUPDATE");
95
+ CONFIG_GET: typeof import("@redis/search/dist/commands/CONFIG_GET");
96
+ configGet: typeof import("@redis/search/dist/commands/CONFIG_GET");
97
+ CONFIG_SET: typeof import("@redis/search/dist/commands/CONFIG_SET");
98
+ configSet: typeof import("@redis/search/dist/commands/CONFIG_SET");
99
+ CREATE: typeof import("@redis/search/dist/commands/CREATE");
100
+ create: typeof import("@redis/search/dist/commands/CREATE");
101
+ CURSOR_DEL: typeof import("@redis/search/dist/commands/CURSOR_DEL");
102
+ cursorDel: typeof import("@redis/search/dist/commands/CURSOR_DEL");
103
+ CURSOR_READ: typeof import("@redis/search/dist/commands/CURSOR_READ");
104
+ cursorRead: typeof import("@redis/search/dist/commands/CURSOR_READ");
105
+ DICTADD: typeof import("@redis/search/dist/commands/DICTADD");
106
+ dictAdd: typeof import("@redis/search/dist/commands/DICTADD");
107
+ DICTDEL: typeof import("@redis/search/dist/commands/DICTDEL");
108
+ dictDel: typeof import("@redis/search/dist/commands/DICTDEL");
109
+ DICTDUMP: typeof import("@redis/search/dist/commands/DICTDUMP");
110
+ dictDump: typeof import("@redis/search/dist/commands/DICTDUMP");
111
+ DROPINDEX: typeof import("@redis/search/dist/commands/DROPINDEX");
112
+ dropIndex: typeof import("@redis/search/dist/commands/DROPINDEX");
113
+ EXPLAIN: typeof import("@redis/search/dist/commands/EXPLAIN");
114
+ explain: typeof import("@redis/search/dist/commands/EXPLAIN");
115
+ EXPLAINCLI: typeof import("@redis/search/dist/commands/EXPLAINCLI");
116
+ explainCli: typeof import("@redis/search/dist/commands/EXPLAINCLI");
117
+ INFO: typeof import("@redis/search/dist/commands/INFO");
118
+ info: typeof import("@redis/search/dist/commands/INFO");
119
+ PROFILESEARCH: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
120
+ profileSearch: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
121
+ PROFILEAGGREGATE: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
122
+ profileAggregate: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
123
+ SEARCH: typeof import("@redis/search/dist/commands/SEARCH");
124
+ search: typeof import("@redis/search/dist/commands/SEARCH");
125
+ SEARCH_NOCONTENT: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
126
+ searchNoContent: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
127
+ SPELLCHECK: typeof import("@redis/search/dist/commands/SPELLCHECK");
128
+ spellCheck: typeof import("@redis/search/dist/commands/SPELLCHECK");
129
+ SUGADD: typeof import("@redis/search/dist/commands/SUGADD");
130
+ sugAdd: typeof import("@redis/search/dist/commands/SUGADD");
131
+ SUGDEL: typeof import("@redis/search/dist/commands/SUGDEL");
132
+ sugDel: typeof import("@redis/search/dist/commands/SUGDEL");
133
+ SUGGET_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
134
+ sugGetWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
135
+ SUGGET_WITHSCORES_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
136
+ sugGetWithScoresWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
137
+ SUGGET_WITHSCORES: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
138
+ sugGetWithScores: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
139
+ SUGGET: typeof import("@redis/search/dist/commands/SUGGET");
140
+ sugGet: typeof import("@redis/search/dist/commands/SUGGET");
141
+ SUGLEN: typeof import("@redis/search/dist/commands/SUGLEN");
142
+ sugLen: typeof import("@redis/search/dist/commands/SUGLEN");
143
+ SYNDUMP: typeof import("@redis/search/dist/commands/SYNDUMP");
144
+ synDump: typeof import("@redis/search/dist/commands/SYNDUMP");
145
+ SYNUPDATE: typeof import("@redis/search/dist/commands/SYNUPDATE");
146
+ synUpdate: typeof import("@redis/search/dist/commands/SYNUPDATE");
147
+ TAGVALS: typeof import("@redis/search/dist/commands/TAGVALS");
148
+ tagVals: typeof import("@redis/search/dist/commands/TAGVALS");
149
+ };
150
+ ts: {
151
+ ADD: typeof import("@redis/time-series/dist/commands/ADD");
152
+ add: typeof import("@redis/time-series/dist/commands/ADD");
153
+ ALTER: typeof import("@redis/time-series/dist/commands/ALTER");
154
+ alter: typeof import("@redis/time-series/dist/commands/ALTER");
155
+ CREATE: typeof import("@redis/time-series/dist/commands/CREATE");
156
+ create: typeof import("@redis/time-series/dist/commands/CREATE");
157
+ CREATERULE: typeof import("@redis/time-series/dist/commands/CREATERULE");
158
+ createRule: typeof import("@redis/time-series/dist/commands/CREATERULE");
159
+ DECRBY: typeof import("@redis/time-series/dist/commands/DECRBY");
160
+ decrBy: typeof import("@redis/time-series/dist/commands/DECRBY");
161
+ DEL: typeof import("@redis/time-series/dist/commands/DEL");
162
+ del: typeof import("@redis/time-series/dist/commands/DEL");
163
+ DELETERULE: typeof import("@redis/time-series/dist/commands/DELETERULE");
164
+ deleteRule: typeof import("@redis/time-series/dist/commands/DELETERULE");
165
+ GET: typeof import("@redis/time-series/dist/commands/GET");
166
+ get: typeof import("@redis/time-series/dist/commands/GET");
167
+ INCRBY: typeof import("@redis/time-series/dist/commands/INCRBY");
168
+ incrBy: typeof import("@redis/time-series/dist/commands/INCRBY");
169
+ INFO_DEBUG: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
170
+ infoDebug: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
171
+ INFO: typeof import("@redis/time-series/dist/commands/INFO");
172
+ info: typeof import("@redis/time-series/dist/commands/INFO");
173
+ MADD: typeof import("@redis/time-series/dist/commands/MADD");
174
+ mAdd: typeof import("@redis/time-series/dist/commands/MADD");
175
+ MGET: typeof import("@redis/time-series/dist/commands/MGET");
176
+ mGet: typeof import("@redis/time-series/dist/commands/MGET");
177
+ MGET_WITHLABELS: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
178
+ mGetWithLabels: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
179
+ QUERYINDEX: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
180
+ queryIndex: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
181
+ RANGE: typeof import("@redis/time-series/dist/commands/RANGE");
182
+ range: typeof import("@redis/time-series/dist/commands/RANGE");
183
+ REVRANGE: typeof import("@redis/time-series/dist/commands/REVRANGE");
184
+ revRange: typeof import("@redis/time-series/dist/commands/REVRANGE");
185
+ MRANGE: typeof import("@redis/time-series/dist/commands/MRANGE");
186
+ mRange: typeof import("@redis/time-series/dist/commands/MRANGE");
187
+ MRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
188
+ mRangeWithLabels: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
189
+ MREVRANGE: typeof import("@redis/time-series/dist/commands/MREVRANGE");
190
+ mRevRange: typeof import("@redis/time-series/dist/commands/MREVRANGE");
191
+ MREVRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
192
+ mRevRangeWithLabels: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
193
+ };
194
+ bf: {
195
+ ADD: typeof import("@redis/bloom/dist/commands/bloom/ADD");
196
+ add: typeof import("@redis/bloom/dist/commands/bloom/ADD");
197
+ CARD: typeof import("@redis/bloom/dist/commands/bloom/CARD");
198
+ card: typeof import("@redis/bloom/dist/commands/bloom/CARD");
199
+ EXISTS: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
200
+ exists: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
201
+ INFO: typeof import("@redis/bloom/dist/commands/bloom/INFO");
202
+ info: typeof import("@redis/bloom/dist/commands/bloom/INFO");
203
+ INSERT: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
204
+ insert: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
205
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
206
+ loadChunk: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
207
+ MADD: typeof import("@redis/bloom/dist/commands/bloom/MADD");
208
+ mAdd: typeof import("@redis/bloom/dist/commands/bloom/MADD");
209
+ MEXISTS: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
210
+ mExists: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
211
+ RESERVE: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
212
+ reserve: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
213
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
214
+ scanDump: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
215
+ };
216
+ cms: {
217
+ INCRBY: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
218
+ incrBy: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
219
+ INFO: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
220
+ info: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
221
+ INITBYDIM: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
222
+ initByDim: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
223
+ INITBYPROB: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
224
+ initByProb: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
225
+ MERGE: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
226
+ merge: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
227
+ QUERY: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
228
+ query: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
229
+ };
230
+ cf: {
231
+ ADD: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
232
+ add: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
233
+ ADDNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
234
+ addNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
235
+ COUNT: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
236
+ count: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
237
+ DEL: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
238
+ del: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
239
+ EXISTS: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
240
+ exists: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
241
+ INFO: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
242
+ info: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
243
+ INSERT: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
244
+ insert: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
245
+ INSERTNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
246
+ insertNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
247
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
248
+ loadChunk: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
249
+ RESERVE: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
250
+ reserve: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
251
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
252
+ scanDump: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
253
+ };
254
+ tDigest: {
255
+ ADD: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
256
+ add: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
257
+ BYRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
258
+ byRank: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
259
+ BYREVRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
260
+ byRevRank: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
261
+ CDF: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
262
+ cdf: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
263
+ CREATE: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
264
+ create: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
265
+ INFO: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
266
+ info: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
267
+ MAX: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
268
+ max: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
269
+ MERGE: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
270
+ merge: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
271
+ MIN: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
272
+ min: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
273
+ QUANTILE: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
274
+ quantile: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
275
+ RANK: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
276
+ rank: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
277
+ RESET: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
278
+ reset: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
279
+ REVRANK: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
280
+ revRank: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
281
+ TRIMMED_MEAN: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
282
+ trimmedMean: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
283
+ };
284
+ topK: {
285
+ ADD: typeof import("@redis/bloom/dist/commands/top-k/ADD");
286
+ add: typeof import("@redis/bloom/dist/commands/top-k/ADD");
287
+ COUNT: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
288
+ count: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
289
+ INCRBY: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
290
+ incrBy: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
291
+ INFO: typeof import("@redis/bloom/dist/commands/top-k/INFO");
292
+ info: typeof import("@redis/bloom/dist/commands/top-k/INFO");
293
+ LIST_WITHCOUNT: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
294
+ listWithCount: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
295
+ LIST: typeof import("@redis/bloom/dist/commands/top-k/LIST");
296
+ list: typeof import("@redis/bloom/dist/commands/top-k/LIST");
297
+ QUERY: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
298
+ query: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
299
+ RESERVE: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
300
+ reserve: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
301
+ };
302
+ } & import("redis").RedisModules, import("redis").RedisFunctions, import("redis").RedisScripts>>;
303
+ remove(key: string): Promise<boolean>;
304
+ get<T = any>(key: string): Promise<T | null>;
305
+ setExpired(key: string, value: any, options?: {
306
+ expiredAt?: Date | number;
307
+ /** in seconds */
308
+ expiredInSeconds?: number;
309
+ }): Promise<void>;
310
+ }
@@ -0,0 +1,129 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.RedisConnection = void 0;
40
+ var utils_1 = require("@klapeks/utils");
41
+ var quiet_require_1 = require("../quiet.require");
42
+ var redisModule = (0, quiet_require_1.quietRequire)('redis');
43
+ var logger = new utils_1.Logger("Redis");
44
+ var RedisConnection = /** @class */ (function () {
45
+ function RedisConnection(options) {
46
+ this.options = options;
47
+ if (!redisModule)
48
+ throw new Error("Redis module is not installed");
49
+ if (!options.keyPrefix.endsWith(':')) {
50
+ options.keyPrefix = options.keyPrefix + ':';
51
+ }
52
+ this.redisClient = redisModule.createClient({ name: options.clientName });
53
+ }
54
+ Object.defineProperty(RedisConnection.prototype, "keyPrefix", {
55
+ get: function () {
56
+ return this.options.keyPrefix;
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ RedisConnection.prototype.initialize = function () {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ return [2 /*return*/, this.redisClient.connect()];
65
+ });
66
+ });
67
+ };
68
+ RedisConnection.prototype.remove = function (key) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var result;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4 /*yield*/, this.redisClient.del(this.keyPrefix + key)];
74
+ case 1:
75
+ result = _a.sent();
76
+ return [2 /*return*/, result === 1];
77
+ }
78
+ });
79
+ });
80
+ };
81
+ RedisConnection.prototype.get = function (key) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var data;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0: return [4 /*yield*/, this.redisClient.get(this.keyPrefix + key)];
87
+ case 1:
88
+ data = _a.sent();
89
+ return [2 /*return*/, data ? JSON.parse(data) : null];
90
+ }
91
+ });
92
+ });
93
+ };
94
+ RedisConnection.prototype.setExpired = function (key, value, options) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var expire, err_1;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ expire = (options === null || options === void 0 ? void 0 : options.expiredInSeconds) || -1;
101
+ if (options === null || options === void 0 ? void 0 : options.expiredAt) {
102
+ if (options.expiredAt instanceof Date) {
103
+ expire = options.expiredAt.getTime();
104
+ }
105
+ else
106
+ expire = options.expiredAt;
107
+ expire = ((expire - Date.now()) / 1000) | 0;
108
+ }
109
+ if (!expire || expire <= 0)
110
+ expire = undefined;
111
+ _a.label = 1;
112
+ case 1:
113
+ _a.trys.push([1, 3, , 4]);
114
+ return [4 /*yield*/, this.redisClient.set(this.keyPrefix + key, JSON.stringify(value), { EX: expire })];
115
+ case 2:
116
+ _a.sent();
117
+ return [3 /*break*/, 4];
118
+ case 3:
119
+ err_1 = _a.sent();
120
+ logger.error("Error while setting", value, "with expire of", expire);
121
+ throw err_1;
122
+ case 4: return [2 /*return*/];
123
+ }
124
+ });
125
+ });
126
+ };
127
+ return RedisConnection;
128
+ }());
129
+ exports.RedisConnection = RedisConnection;
@@ -0,0 +1 @@
1
+ export declare function quietRequire<T>(module: string): T | undefined;