@hotmeshio/hotmesh 0.3.6 → 0.3.7

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 (120) hide show
  1. package/build/index.d.ts +2 -1
  2. package/build/index.js +7 -1
  3. package/build/modules/key.js +1 -62
  4. package/build/modules/utils.js +1 -267
  5. package/build/package.json +12 -8
  6. package/build/services/activities/activity.js +1 -495
  7. package/build/services/activities/await.js +1 -109
  8. package/build/services/activities/cycle.js +1 -96
  9. package/build/services/activities/hook.js +1 -154
  10. package/build/services/activities/index.js +1 -20
  11. package/build/services/activities/interrupt.js +1 -149
  12. package/build/services/activities/signal.js +1 -118
  13. package/build/services/activities/trigger.js +1 -237
  14. package/build/services/activities/worker.js +1 -101
  15. package/build/services/collator/index.js +1 -197
  16. package/build/services/compiler/deployer.d.ts +3 -1
  17. package/build/services/compiler/deployer.js +1 -455
  18. package/build/services/compiler/index.d.ts +3 -1
  19. package/build/services/compiler/index.js +1 -91
  20. package/build/services/compiler/validator.js +1 -122
  21. package/build/services/engine/index.d.ts +5 -2
  22. package/build/services/engine/index.js +1 -562
  23. package/build/services/exporter/index.js +1 -93
  24. package/build/services/mapper/index.js +1 -67
  25. package/build/services/meshdata/index.d.ts +0 -1
  26. package/build/services/meshdata/index.js +16 -24
  27. package/build/services/meshflow/client.js +4 -8
  28. package/build/services/meshflow/exporter.js +1 -186
  29. package/build/services/meshflow/search.d.ts +4 -5
  30. package/build/services/meshflow/search.js +45 -35
  31. package/build/services/meshflow/workflow.d.ts +1 -1
  32. package/build/services/meshflow/workflow.js +3 -28
  33. package/build/services/pipe/functions/array.js +1 -74
  34. package/build/services/pipe/functions/bitwise.js +1 -24
  35. package/build/services/pipe/functions/conditional.js +1 -36
  36. package/build/services/pipe/functions/cron.js +1 -32
  37. package/build/services/pipe/functions/date.js +1 -164
  38. package/build/services/pipe/functions/index.js +1 -30
  39. package/build/services/pipe/functions/json.js +1 -12
  40. package/build/services/pipe/functions/logical.js +1 -12
  41. package/build/services/pipe/functions/math.js +1 -182
  42. package/build/services/pipe/functions/number.js +1 -60
  43. package/build/services/pipe/functions/object.js +1 -81
  44. package/build/services/pipe/functions/string.js +1 -69
  45. package/build/services/pipe/functions/symbol.js +1 -33
  46. package/build/services/pipe/functions/unary.js +1 -18
  47. package/build/services/pipe/index.js +1 -221
  48. package/build/services/quorum/index.d.ts +1 -1
  49. package/build/services/quorum/index.js +1 -219
  50. package/build/services/reporter/index.js +1 -331
  51. package/build/services/router/index.js +1 -420
  52. package/build/services/search/factory.d.ts +7 -0
  53. package/build/services/search/factory.js +20 -0
  54. package/build/services/search/index.d.ts +21 -0
  55. package/build/services/search/index.js +10 -0
  56. package/build/services/search/providers/redis/ioredis.d.ts +18 -0
  57. package/build/services/search/providers/redis/ioredis.js +1 -0
  58. package/build/services/search/providers/redis/redis.d.ts +18 -0
  59. package/build/services/search/providers/redis/redis.js +1 -0
  60. package/build/services/serializer/index.js +1 -265
  61. package/build/services/store/factory.d.ts +2 -1
  62. package/build/services/store/factory.js +2 -2
  63. package/build/services/store/index.d.ts +71 -97
  64. package/build/services/store/index.js +2 -939
  65. package/build/services/store/providers/postgres/postgres.d.ts +0 -0
  66. package/build/services/store/providers/postgres/postgres.js +0 -0
  67. package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
  68. package/build/services/store/providers/postgres/types/hash.js +0 -0
  69. package/build/services/store/providers/postgres/types/list.d.ts +0 -0
  70. package/build/services/store/providers/postgres/types/list.js +0 -0
  71. package/build/services/store/providers/postgres/types/string.d.ts +0 -0
  72. package/build/services/store/providers/postgres/types/string.js +0 -0
  73. package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
  74. package/build/services/store/providers/postgres/types/zset.js +0 -0
  75. package/build/services/store/providers/redis/_base.d.ts +98 -0
  76. package/build/services/store/providers/redis/_base.js +1 -0
  77. package/build/services/store/providers/redis/ioredis.d.ts +12 -0
  78. package/build/services/store/providers/redis/ioredis.js +1 -0
  79. package/build/services/store/providers/redis/redis.d.ts +13 -0
  80. package/build/services/store/providers/redis/redis.js +1 -0
  81. package/build/services/store/providers/store-initializable.d.ts +5 -0
  82. package/build/services/store/providers/store-initializable.js +1 -0
  83. package/build/services/stream/factory.d.ts +2 -1
  84. package/build/services/stream/factory.js +5 -5
  85. package/build/services/stream/index.d.ts +13 -14
  86. package/build/services/stream/index.js +3 -2
  87. package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
  88. package/build/services/stream/providers/postgres/_deploy.js +1 -0
  89. package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
  90. package/build/services/stream/providers/redis/ioredis.js +1 -0
  91. package/build/services/stream/providers/redis/redis.d.ts +21 -0
  92. package/build/services/stream/providers/redis/redis.js +1 -0
  93. package/build/services/stream/providers/stream-initializable.d.ts +5 -0
  94. package/build/services/stream/providers/stream-initializable.js +1 -0
  95. package/build/services/sub/factory.d.ts +1 -1
  96. package/build/services/sub/factory.js +5 -5
  97. package/build/services/sub/index.d.ts +9 -7
  98. package/build/services/sub/index.js +3 -2
  99. package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
  100. package/build/services/sub/providers/redis/ioredis.js +1 -0
  101. package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
  102. package/build/services/sub/providers/redis/redis.js +1 -0
  103. package/build/services/task/index.js +1 -171
  104. package/build/services/telemetry/index.js +1 -225
  105. package/build/services/worker/index.d.ts +2 -2
  106. package/build/services/worker/index.js +1 -158
  107. package/build/types/redis.d.ts +5 -5
  108. package/index.ts +15 -1
  109. package/package.json +12 -8
  110. package/types/redis.ts +5 -5
  111. package/build/services/store/clients/ioredis.d.ts +0 -30
  112. package/build/services/store/clients/ioredis.js +0 -220
  113. package/build/services/store/clients/redis.d.ts +0 -32
  114. package/build/services/store/clients/redis.js +0 -319
  115. package/build/services/stream/clients/ioredis.d.ts +0 -24
  116. package/build/services/stream/clients/ioredis.js +0 -121
  117. package/build/services/stream/clients/redis.d.ts +0 -24
  118. package/build/services/stream/clients/redis.js +0 -161
  119. package/build/services/sub/clients/ioredis.js +0 -72
  120. package/build/services/sub/clients/redis.js +0 -63
@@ -1,420 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Router = void 0;
4
- const enums_1 = require("../../modules/enums");
5
- const key_1 = require("../../modules/key");
6
- const utils_1 = require("../../modules/utils");
7
- const telemetry_1 = require("../telemetry");
8
- const stream_1 = require("../../types/stream");
9
- class Router {
10
- constructor(config, stream, store, logger) {
11
- this.throttle = 0;
12
- this.errorCount = 0;
13
- this.counts = {};
14
- this.currentTimerId = null;
15
- this.sleepPromiseResolve = null;
16
- this.innerPromiseResolve = null;
17
- this.isSleeping = false;
18
- this.sleepTimout = null;
19
- this.appId = config.appId;
20
- this.guid = config.guid;
21
- this.role = config.role;
22
- this.topic = config.topic;
23
- this.stream = stream;
24
- this.store = store;
25
- this.throttle = config.throttle;
26
- this.reclaimDelay = config.reclaimDelay || enums_1.HMSH_XCLAIM_DELAY_MS;
27
- this.reclaimCount = config.reclaimCount || enums_1.HMSH_XCLAIM_COUNT;
28
- this.logger = logger;
29
- this.readonly = config.readonly || false;
30
- this.resetThrottleState();
31
- }
32
- resetThrottleState() {
33
- this.sleepPromiseResolve = null;
34
- this.innerPromiseResolve = null;
35
- this.isSleeping = false;
36
- this.sleepTimout = null;
37
- }
38
- async createGroup(stream, group) {
39
- try {
40
- await this.store.xgroup('CREATE', stream, group, '$', 'MKSTREAM');
41
- }
42
- catch (err) {
43
- this.logger.debug('router-stream-group-exists', { stream, group });
44
- }
45
- }
46
- async publishMessage(topic, streamData, multi) {
47
- const code = streamData?.code || '200';
48
- this.counts[code] = (this.counts[code] || 0) + 1;
49
- const stream = this.store.mintKey(key_1.KeyType.STREAMS, {
50
- appId: this.store.appId,
51
- topic,
52
- });
53
- return await this.store.xadd(stream, '*', 'message', JSON.stringify(streamData), multi);
54
- }
55
- async customSleep() {
56
- if (this.throttle === 0)
57
- return;
58
- if (this.isSleeping)
59
- return;
60
- this.isSleeping = true;
61
- const startTime = Date.now();
62
- await new Promise(async (outerResolve) => {
63
- this.sleepPromiseResolve = outerResolve;
64
- let elapsedTime = Date.now() - startTime;
65
- while (elapsedTime < this.throttle) {
66
- await new Promise((innerResolve) => {
67
- this.innerPromiseResolve = innerResolve;
68
- this.sleepTimout = setTimeout(innerResolve, this.throttle - elapsedTime);
69
- });
70
- elapsedTime = Date.now() - startTime;
71
- }
72
- this.resetThrottleState();
73
- outerResolve();
74
- });
75
- }
76
- async consumeMessages(stream, group, consumer, callback) {
77
- if (this.readonly) {
78
- this.logger.info(`router-stream-readonly`, { group, consumer, stream });
79
- return;
80
- }
81
- this.logger.info(`router-stream-starting`, { group, consumer, stream });
82
- Router.instances.add(this);
83
- this.shouldConsume = true;
84
- await this.createGroup(stream, group);
85
- let lastCheckedPendingMessagesAt = Date.now();
86
- async function consume() {
87
- await this.customSleep();
88
- if (this.isStopped(group, consumer, stream)) {
89
- return;
90
- }
91
- else if (this.isPaused()) {
92
- setImmediate(consume.bind(this));
93
- return;
94
- }
95
- try {
96
- const streamDuration = enums_1.HMSH_BLOCK_TIME_MS + Math.round(enums_1.HMSH_BLOCK_TIME_MS * Math.random());
97
- const result = await this.stream.xreadgroup('GROUP', group, consumer, 'BLOCK', streamDuration, 'STREAMS', stream, '>');
98
- if (this.isStopped(group, consumer, stream)) {
99
- return;
100
- }
101
- else if (this.isPaused()) {
102
- setImmediate(consume.bind(this));
103
- return;
104
- }
105
- if (this.isStreamMessage(result)) {
106
- const [[, messages]] = result;
107
- for (const [id, message] of messages) {
108
- await this.consumeOne(stream, group, id, message, callback);
109
- }
110
- }
111
- const now = Date.now();
112
- if (now - lastCheckedPendingMessagesAt > this.reclaimDelay) {
113
- lastCheckedPendingMessagesAt = now;
114
- const pendingMessages = await this.claimUnacknowledged(stream, group, consumer);
115
- for (const [id, message] of pendingMessages) {
116
- await this.consumeOne(stream, group, id, message, callback);
117
- }
118
- }
119
- setImmediate(consume.bind(this));
120
- }
121
- catch (err) {
122
- if (this.shouldConsume && process.env.NODE_ENV !== 'test') {
123
- this.logger.error(`router-stream-error`, {
124
- err,
125
- stream,
126
- group,
127
- consumer,
128
- });
129
- this.errorCount++;
130
- const timeout = Math.min(enums_1.HMSH_GRADUATED_INTERVAL_MS * 2 ** this.errorCount, enums_1.HMSH_MAX_TIMEOUT_MS);
131
- setTimeout(consume.bind(this), timeout);
132
- }
133
- }
134
- }
135
- consume.call(this);
136
- }
137
- isStreamMessage(result) {
138
- return Array.isArray(result) && Array.isArray(result[0]);
139
- }
140
- isPaused() {
141
- return this.throttle === enums_1.MAX_DELAY;
142
- }
143
- isStopped(group, consumer, stream) {
144
- if (!this.shouldConsume) {
145
- this.logger.info(`router-stream-stopped`, {
146
- group,
147
- consumer,
148
- stream,
149
- });
150
- }
151
- return !this.shouldConsume;
152
- }
153
- async consumeOne(stream, group, id, message, callback) {
154
- this.logger.debug(`stream-read-one`, { group, stream, id });
155
- const [err, input] = this.parseStreamData(message[1]);
156
- let output;
157
- let telemetry;
158
- try {
159
- telemetry = new telemetry_1.TelemetryService(this.appId);
160
- telemetry.startStreamSpan(input, this.role);
161
- output = await this.execStreamLeg(input, stream, id, callback.bind(this));
162
- if (output?.status === stream_1.StreamStatus.ERROR) {
163
- telemetry.setStreamError(`Function Status Code ${output.code || enums_1.HMSH_CODE_UNKNOWN}`);
164
- }
165
- this.errorCount = 0;
166
- }
167
- catch (err) {
168
- this.logger.error(`stream-read-one-error`, { group, stream, id, err });
169
- telemetry.setStreamError(err.message);
170
- }
171
- const messageId = await this.publishResponse(input, output);
172
- telemetry.setStreamAttributes({ 'app.worker.mid': messageId });
173
- await this.ackAndDelete(stream, group, id);
174
- telemetry.endStreamSpan();
175
- this.logger.debug(`stream-read-one-end`, { group, stream, id });
176
- }
177
- async execStreamLeg(input, stream, id, callback) {
178
- let output;
179
- try {
180
- output = await callback(input);
181
- }
182
- catch (error) {
183
- this.logger.error(`stream-call-function-error`, {
184
- ...error,
185
- input: input,
186
- stack: error.stack,
187
- message: error.message,
188
- name: error.name,
189
- stream,
190
- id,
191
- });
192
- output = this.structureUnhandledError(input, error);
193
- }
194
- return output;
195
- }
196
- async ackAndDelete(stream, group, id) {
197
- const multi = this.stream.getMulti();
198
- await this.stream.xack(stream, group, id, multi);
199
- await this.stream.xdel(stream, id, multi);
200
- await multi.exec();
201
- }
202
- async publishResponse(input, output) {
203
- if (output && typeof output === 'object') {
204
- if (output.status === 'error') {
205
- const [shouldRetry, timeout] = this.shouldRetry(input, output);
206
- if (shouldRetry) {
207
- await (0, utils_1.sleepFor)(timeout);
208
- return (await this.publishMessage(input.metadata.topic, {
209
- data: input.data,
210
- metadata: { ...input.metadata, try: (input.metadata.try || 0) + 1 },
211
- policies: input.policies,
212
- }));
213
- }
214
- else {
215
- output = this.structureError(input, output);
216
- }
217
- }
218
- else if (typeof output.metadata !== 'object') {
219
- output.metadata = { ...input.metadata, guid: (0, utils_1.guid)() };
220
- }
221
- else {
222
- output.metadata.guid = (0, utils_1.guid)();
223
- }
224
- output.type = stream_1.StreamDataType.RESPONSE;
225
- return (await this.publishMessage(null, output));
226
- }
227
- }
228
- shouldRetry(input, output) {
229
- const policies = input.policies?.retry;
230
- const errorCode = output.code.toString();
231
- const policy = policies?.[errorCode];
232
- const maxRetries = policy?.[0];
233
- const tryCount = Math.min(input.metadata.try || 0, enums_1.HMSH_MAX_RETRIES);
234
- if (maxRetries > tryCount) {
235
- return [true, Math.pow(10, tryCount + 1)];
236
- }
237
- return [false, 0];
238
- }
239
- structureUnhandledError(input, err) {
240
- const error = {};
241
- if (typeof err.message === 'string') {
242
- error.message = err.message;
243
- }
244
- else {
245
- error.message = enums_1.HMSH_STATUS_UNKNOWN;
246
- }
247
- if (typeof err.stack === 'string') {
248
- error.stack = err.stack;
249
- }
250
- if (typeof err.name === 'string') {
251
- error.name = err.name;
252
- }
253
- return {
254
- status: 'error',
255
- code: enums_1.HMSH_CODE_UNKNOWN,
256
- metadata: { ...input.metadata, guid: (0, utils_1.guid)() },
257
- data: error,
258
- };
259
- }
260
- structureUnacknowledgedError(input) {
261
- const message = 'stream message max delivery count exceeded';
262
- const code = enums_1.HMSH_CODE_UNACKED;
263
- const data = { message, code };
264
- const output = {
265
- metadata: { ...input.metadata, guid: (0, utils_1.guid)() },
266
- status: stream_1.StreamStatus.ERROR,
267
- code,
268
- data,
269
- };
270
- delete output.metadata.topic;
271
- return output;
272
- }
273
- structureError(input, output) {
274
- const message = output.data?.message
275
- ? output.data?.message.toString()
276
- : enums_1.HMSH_STATUS_UNKNOWN;
277
- const statusCode = output.code || output.data?.code;
278
- const code = isNaN(statusCode)
279
- ? enums_1.HMSH_CODE_UNKNOWN
280
- : parseInt(statusCode.toString());
281
- const stack = output.data?.stack
282
- ? output.data?.stack.toString()
283
- : undefined;
284
- const data = { message, code, stack };
285
- if (typeof output.data?.error === 'object') {
286
- data.error = { ...output.data.error };
287
- }
288
- return {
289
- status: stream_1.StreamStatus.ERROR,
290
- code,
291
- stack,
292
- metadata: { ...input.metadata, guid: (0, utils_1.guid)() },
293
- data,
294
- };
295
- }
296
- static async stopConsuming() {
297
- for (const instance of [...Router.instances]) {
298
- instance.stopConsuming();
299
- }
300
- await (0, utils_1.sleepFor)(enums_1.HMSH_BLOCK_TIME_MS * 2);
301
- }
302
- async stopConsuming() {
303
- this.shouldConsume = false;
304
- this.logger.info(`router-stream-stopping`, this.topic ? { topic: this.topic } : undefined);
305
- this.cancelThrottle();
306
- }
307
- cancelThrottle() {
308
- if (this.sleepTimout) {
309
- clearTimeout(this.sleepTimout);
310
- }
311
- this.resetThrottleState();
312
- }
313
- setThrottle(delayInMillis) {
314
- if (!Number.isInteger(delayInMillis) ||
315
- delayInMillis < 0 ||
316
- delayInMillis > enums_1.MAX_DELAY) {
317
- throw new Error(`Throttle must be a non-negative integer and not exceed ${enums_1.MAX_DELAY} ms; send -1 to throttle indefinitely`);
318
- }
319
- const wasDecreased = delayInMillis < this.throttle;
320
- this.throttle = delayInMillis;
321
- if (wasDecreased) {
322
- if (this.sleepTimout) {
323
- clearTimeout(this.sleepTimout);
324
- }
325
- if (this.innerPromiseResolve) {
326
- this.innerPromiseResolve();
327
- }
328
- }
329
- }
330
- async claimUnacknowledged(stream, group, consumer, idleTimeMs = this.reclaimDelay, limit = enums_1.HMSH_XPENDING_COUNT) {
331
- let pendingMessages = [];
332
- const pendingMessagesInfo = await this.stream.xpending(stream, group, '-', '+', limit);
333
- for (const pendingMessageInfo of pendingMessagesInfo) {
334
- if (Array.isArray(pendingMessageInfo)) {
335
- const [id, , elapsedTimeMs, deliveryCount] = pendingMessageInfo;
336
- if (elapsedTimeMs > idleTimeMs) {
337
- const reclaimedMessage = await this.stream.xclaim(stream, group, consumer, idleTimeMs, id);
338
- if (reclaimedMessage.length) {
339
- if (deliveryCount <= this.reclaimCount) {
340
- pendingMessages = pendingMessages.concat(reclaimedMessage);
341
- }
342
- else {
343
- await this.expireUnacknowledged(reclaimedMessage, stream, group, consumer, id, deliveryCount);
344
- }
345
- }
346
- }
347
- }
348
- }
349
- return pendingMessages;
350
- }
351
- async expireUnacknowledged(reclaimedMessage, stream, group, consumer, id, count) {
352
- this.logger.error('stream-message-max-delivery-count-exceeded', {
353
- id,
354
- stream,
355
- group,
356
- consumer,
357
- code: enums_1.HMSH_CODE_UNACKED,
358
- count,
359
- });
360
- const streamData = reclaimedMessage[0]?.[1]?.[1];
361
- const [err, input] = this.parseStreamData(streamData);
362
- if (err) {
363
- return this.logger.error('expire-unacknowledged-parse-fatal-error', {
364
- id,
365
- err,
366
- });
367
- }
368
- else if (!input || !input.metadata) {
369
- return this.logger.error('expire-unacknowledged-parse-fatal-error', {
370
- id,
371
- });
372
- }
373
- let telemetry;
374
- let messageId;
375
- try {
376
- telemetry = new telemetry_1.TelemetryService(this.appId);
377
- telemetry.startStreamSpan(input, stream_1.StreamRole.SYSTEM);
378
- telemetry.setStreamError(`Stream Message Max Delivery Count Exceeded`);
379
- const output = this.structureUnacknowledgedError(input);
380
- messageId = await this.publishResponse(input, output);
381
- telemetry.setStreamAttributes({ 'app.worker.mid': messageId });
382
- await this.ackAndDelete(stream, group, id);
383
- }
384
- catch (err) {
385
- if (messageId) {
386
- this.logger.error('expire-unacknowledged-pub-fatal-error', {
387
- id,
388
- err,
389
- ...input.metadata,
390
- });
391
- telemetry.setStreamAttributes({
392
- 'app.system.fatal': 'expire-unacknowledged-pub-fatal-error',
393
- });
394
- }
395
- else {
396
- this.logger.error('expire-unacknowledged-ack-fatal-error', {
397
- id,
398
- err,
399
- ...input.metadata,
400
- });
401
- telemetry.setStreamAttributes({
402
- 'app.system.fatal': 'expire-unacknowledged-ack-fatal-error',
403
- });
404
- }
405
- }
406
- finally {
407
- telemetry.endStreamSpan();
408
- }
409
- }
410
- parseStreamData(str) {
411
- try {
412
- return [, JSON.parse(str)];
413
- }
414
- catch (e) {
415
- return [e];
416
- }
417
- }
418
- }
419
- exports.Router = Router;
420
- Router.instances = new Set();
1
+ 'use strict';function _0x7f5b(){const _0x1ffc9e=['41379asqgoH','6610wECXXU','3972OkFuvd','6267CEFhWy','2lgbYhr','6SBXwwl','16fROYrJ','256491fJoyXt','635blmpOj','1580831pLUaZz','4436808INEVwC','1441zWaISZ'];_0x7f5b=function(){return _0x1ffc9e;};return _0x7f5b();}(function(_0x3ed74f,_0x5caa0f){const _0x421a7f=_0x5ec2,_0x1806c4=_0x3ed74f();while(!![]){try{const _0x10ae63=parseInt(_0x421a7f(0x1db))/0x1+-parseInt(_0x421a7f(0x1d3))/0x2*(parseInt(_0x421a7f(0x1d2))/0x3)+-parseInt(_0x421a7f(0x1d1))/0x4*(-parseInt(_0x421a7f(0x1d7))/0x5)+-parseInt(_0x421a7f(0x1d4))/0x6*(-parseInt(_0x421a7f(0x1d8))/0x7)+-parseInt(_0x421a7f(0x1d5))/0x8*(-parseInt(_0x421a7f(0x1d6))/0x9)+parseInt(_0x421a7f(0x1d0))/0xa*(parseInt(_0x421a7f(0x1da))/0xb)+-parseInt(_0x421a7f(0x1d9))/0xc;if(_0x10ae63===_0x5caa0f)break;else _0x1806c4['push'](_0x1806c4['shift']());}catch(_0x2a49ff){_0x1806c4['push'](_0x1806c4['shift']());}}}(_0x7f5b,0x284e1));function _0x5ec2(_0x4a3dfc,_0x30322d){const _0x7f5b6d=_0x7f5b();return _0x5ec2=function(_0x5ec21e,_0x29d1f6){_0x5ec21e=_0x5ec21e-0x1d0;let _0x25f2a0=_0x7f5b6d[_0x5ec21e];return _0x25f2a0;},_0x5ec2(_0x4a3dfc,_0x30322d);}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['Router']=void 0x0;const enums_1=require('../../modules/enums'),key_1=require('../../modules/key'),utils_1=require('../../modules/utils'),telemetry_1=require('../telemetry'),stream_1=require('../../types/stream');class Router{constructor(_0x1c8a68,_0x140dfe,_0x31f8e9,_0x3a98d4){this['throttle']=0x0,this['errorCount']=0x0,this['counts']={},this['currentTimerId']=null,this['sleepPromiseResolve']=null,this['innerPromiseResolve']=null,this['isSleeping']=![],this['sleepTimout']=null,this['appId']=_0x1c8a68['appId'],this['guid']=_0x1c8a68['guid'],this['role']=_0x1c8a68['role'],this['topic']=_0x1c8a68['topic'],this['stream']=_0x140dfe,this['store']=_0x31f8e9,this['throttle']=_0x1c8a68['throttle'],this['reclaimDelay']=_0x1c8a68['reclaimDelay']||enums_1['HMSH_XCLAIM_DELAY_MS'],this['reclaimCount']=_0x1c8a68['reclaimCount']||enums_1['HMSH_XCLAIM_COUNT'],this['logger']=_0x3a98d4,this['readonly']=_0x1c8a68['readonly']||![],this['resetThrottleState']();}['resetThrottleState'](){this['sleepPromiseResolve']=null,this['innerPromiseResolve']=null,this['isSleeping']=![],this['sleepTimout']=null;}async['createGroup'](_0x4d6dd4,_0x4ff7da){try{await this['stream']['createConsumerGroup'](_0x4d6dd4,_0x4ff7da);}catch(_0x5bbca3){this['logger']['debug']('router-stream-group-exists',{'stream':_0x4d6dd4,'group':_0x4ff7da});}}async['publishMessage'](_0x30dfad,_0x46dff3,_0x4f74d5){const _0x587d94=_0x46dff3?.['code']||'200';this['counts'][_0x587d94]=(this['counts'][_0x587d94]||0x0)+0x1;const _0xc7b8a7=this['store']['mintKey'](key_1['KeyType']['STREAMS'],{'appId':this['store']['appId'],'topic':_0x30dfad});return await this['stream']['publishMessage'](_0xc7b8a7,'*','message',JSON['stringify'](_0x46dff3),_0x4f74d5);}async['customSleep'](){if(this['throttle']===0x0)return;if(this['isSleeping'])return;this['isSleeping']=!![];const _0x6b17cd=Date['now']();await new Promise(async _0x3ca34c=>{this['sleepPromiseResolve']=_0x3ca34c;let _0x2320af=Date['now']()-_0x6b17cd;while(_0x2320af<this['throttle']){await new Promise(_0x131212=>{this['innerPromiseResolve']=_0x131212,this['sleepTimout']=setTimeout(_0x131212,this['throttle']-_0x2320af);}),_0x2320af=Date['now']()-_0x6b17cd;}this['resetThrottleState'](),_0x3ca34c();});}async['consumeMessages'](_0x14e5fe,_0x351723,_0x43ea6b,_0x3a0ea9){if(this['readonly']){this['logger']['info']('router-stream-readonly',{'group':_0x351723,'consumer':_0x43ea6b,'stream':_0x14e5fe});return;}this['logger']['info']('router-stream-starting',{'group':_0x351723,'consumer':_0x43ea6b,'stream':_0x14e5fe}),Router['instances']['add'](this),this['shouldConsume']=!![],await this['createGroup'](_0x14e5fe,_0x351723);let _0x8b0600=Date['now']();async function _0xcb405c(){await this['customSleep']();if(this['isStopped'](_0x351723,_0x43ea6b,_0x14e5fe))return;else{if(this['isPaused']()){setImmediate(_0xcb405c['bind'](this));return;}}try{const _0x1cc7ea=enums_1['HMSH_BLOCK_TIME_MS']+Math['round'](enums_1['HMSH_BLOCK_TIME_MS']*Math['random']()),_0x331b71=await this['stream']['consumeMessages'](_0x351723,_0x43ea6b,_0x1cc7ea,_0x14e5fe);if(this['isStopped'](_0x351723,_0x43ea6b,_0x14e5fe))return;else{if(this['isPaused']()){setImmediate(_0xcb405c['bind'](this));return;}}if(this['isStreamMessage'](_0x331b71)){const [[,_0x2048db]]=_0x331b71;for(const [_0x4a63d4,_0x3940f0]of _0x2048db){await this['consumeOne'](_0x14e5fe,_0x351723,_0x4a63d4,_0x3940f0,_0x3a0ea9);}}const _0x119337=Date['now']();if(_0x119337-_0x8b0600>this['reclaimDelay']){_0x8b0600=_0x119337;const _0x3885f1=await this['claimUnacknowledged'](_0x14e5fe,_0x351723,_0x43ea6b);for(const [_0x49ddc6,_0x2400a6]of _0x3885f1){await this['consumeOne'](_0x14e5fe,_0x351723,_0x49ddc6,_0x2400a6,_0x3a0ea9);}}setImmediate(_0xcb405c['bind'](this));}catch(_0x822292){if(this['shouldConsume']&&process['env']['NODE_ENV']!=='test'){this['logger']['error']('router-stream-error',{'err':_0x822292,'stream':_0x14e5fe,'group':_0x351723,'consumer':_0x43ea6b}),this['errorCount']++;const _0x2a10d5=Math['min'](enums_1['HMSH_GRADUATED_INTERVAL_MS']*0x2**this['errorCount'],enums_1['HMSH_MAX_TIMEOUT_MS']);setTimeout(_0xcb405c['bind'](this),_0x2a10d5);}}}_0xcb405c['call'](this);}['isStreamMessage'](_0x244925){return Array['isArray'](_0x244925)&&Array['isArray'](_0x244925[0x0]);}['isPaused'](){return this['throttle']===enums_1['MAX_DELAY'];}['isStopped'](_0x233e36,_0x51a882,_0x2b04b6){return!this['shouldConsume']&&this['logger']['info']('router-stream-stopped',{'group':_0x233e36,'consumer':_0x51a882,'stream':_0x2b04b6}),!this['shouldConsume'];}async['consumeOne'](_0x392ae5,_0x1c97b8,_0x35ef0c,_0x8464b4,_0x24f2f6){this['logger']['debug']('stream-read-one',{'group':_0x1c97b8,'stream':_0x392ae5,'id':_0x35ef0c});const [_0x585c48,_0x2ff106]=this['parseStreamData'](_0x8464b4[0x1]);let _0x1b921c,_0x4e1543;try{_0x4e1543=new telemetry_1['TelemetryService'](this['appId']),_0x4e1543['startStreamSpan'](_0x2ff106,this['role']),_0x1b921c=await this['execStreamLeg'](_0x2ff106,_0x392ae5,_0x35ef0c,_0x24f2f6['bind'](this)),_0x1b921c?.['status']===stream_1['StreamStatus']['ERROR']&&_0x4e1543['setStreamError']('Function\x20Status\x20Code\x20'+(_0x1b921c['code']||enums_1['HMSH_CODE_UNKNOWN'])),this['errorCount']=0x0;}catch(_0x3df24b){this['logger']['error']('stream-read-one-error',{'group':_0x1c97b8,'stream':_0x392ae5,'id':_0x35ef0c,'err':_0x3df24b}),_0x4e1543['setStreamError'](_0x3df24b['message']);}const _0x3453e7=await this['publishResponse'](_0x2ff106,_0x1b921c);_0x4e1543['setStreamAttributes']({'app.worker.mid':_0x3453e7}),await this['ackAndDelete'](_0x392ae5,_0x1c97b8,_0x35ef0c),_0x4e1543['endStreamSpan'](),this['logger']['debug']('stream-read-one-end',{'group':_0x1c97b8,'stream':_0x392ae5,'id':_0x35ef0c});}async['execStreamLeg'](_0x17687b,_0x13211a,_0x443ecf,_0x79d350){let _0x5daa9e;try{_0x5daa9e=await _0x79d350(_0x17687b);}catch(_0x2b5cff){this['logger']['error']('stream-call-function-error',{..._0x2b5cff,'input':_0x17687b,'stack':_0x2b5cff['stack'],'message':_0x2b5cff['message'],'name':_0x2b5cff['name'],'stream':_0x13211a,'id':_0x443ecf}),_0x5daa9e=this['structureUnhandledError'](_0x17687b,_0x2b5cff);}return _0x5daa9e;}async['ackAndDelete'](_0x23b744,_0x5ba95f,_0x114ff6){await this['stream']['ackAndDelete'](_0x23b744,_0x5ba95f,_0x114ff6);}async['publishResponse'](_0x21721e,_0x5088a5){if(_0x5088a5&&typeof _0x5088a5==='object'){if(_0x5088a5['status']==='error'){const [_0x5c1431,_0x36875e]=this['shouldRetry'](_0x21721e,_0x5088a5);if(_0x5c1431)return await(0x0,utils_1['sleepFor'])(_0x36875e),await this['publishMessage'](_0x21721e['metadata']['topic'],{'data':_0x21721e['data'],'metadata':{..._0x21721e['metadata'],'try':(_0x21721e['metadata']['try']||0x0)+0x1},'policies':_0x21721e['policies']});else _0x5088a5=this['structureError'](_0x21721e,_0x5088a5);}else typeof _0x5088a5['metadata']!=='object'?_0x5088a5['metadata']={..._0x21721e['metadata'],'guid':(0x0,utils_1['guid'])()}:_0x5088a5['metadata']['guid']=(0x0,utils_1['guid'])();return _0x5088a5['type']=stream_1['StreamDataType']['RESPONSE'],await this['publishMessage'](null,_0x5088a5);}}['shouldRetry'](_0xda1198,_0x5d2310){const _0x4403de=_0xda1198['policies']?.['retry'],_0x4a2c3e=_0x5d2310['code']['toString'](),_0x32ffc5=_0x4403de?.[_0x4a2c3e],_0x4d5b13=_0x32ffc5?.[0x0],_0x2d9a86=Math['min'](_0xda1198['metadata']['try']||0x0,enums_1['HMSH_MAX_RETRIES']);if(_0x4d5b13>_0x2d9a86)return[!![],Math['pow'](0xa,_0x2d9a86+0x1)];return[![],0x0];}['structureUnhandledError'](_0x57822c,_0x1d3d18){const _0x46235f={};return typeof _0x1d3d18['message']==='string'?_0x46235f['message']=_0x1d3d18['message']:_0x46235f['message']=enums_1['HMSH_STATUS_UNKNOWN'],typeof _0x1d3d18['stack']==='string'&&(_0x46235f['stack']=_0x1d3d18['stack']),typeof _0x1d3d18['name']==='string'&&(_0x46235f['name']=_0x1d3d18['name']),{'status':'error','code':enums_1['HMSH_CODE_UNKNOWN'],'metadata':{..._0x57822c['metadata'],'guid':(0x0,utils_1['guid'])()},'data':_0x46235f};}['structureUnacknowledgedError'](_0x493cec){const _0x206ba4='stream\x20message\x20max\x20delivery\x20count\x20exceeded',_0x427b45=enums_1['HMSH_CODE_UNACKED'],_0x97ba46={'message':_0x206ba4,'code':_0x427b45},_0x16878a={'metadata':{..._0x493cec['metadata'],'guid':(0x0,utils_1['guid'])()},'status':stream_1['StreamStatus']['ERROR'],'code':_0x427b45,'data':_0x97ba46};return delete _0x16878a['metadata']['topic'],_0x16878a;}['structureError'](_0x1419f2,_0xb9534e){const _0x383efc=_0xb9534e['data']?.['message']?_0xb9534e['data']?.['message']['toString']():enums_1['HMSH_STATUS_UNKNOWN'],_0x2ea097=_0xb9534e['code']||_0xb9534e['data']?.['code'],_0x2ace6a=isNaN(_0x2ea097)?enums_1['HMSH_CODE_UNKNOWN']:parseInt(_0x2ea097['toString']()),_0x21d77c=_0xb9534e['data']?.['stack']?_0xb9534e['data']?.['stack']['toString']():undefined,_0x3c3ab6={'message':_0x383efc,'code':_0x2ace6a,'stack':_0x21d77c};return typeof _0xb9534e['data']?.['error']==='object'&&(_0x3c3ab6['error']={..._0xb9534e['data']['error']}),{'status':stream_1['StreamStatus']['ERROR'],'code':_0x2ace6a,'stack':_0x21d77c,'metadata':{..._0x1419f2['metadata'],'guid':(0x0,utils_1['guid'])()},'data':_0x3c3ab6};}static async['stopConsuming'](){for(const _0x23de6a of[...Router['instances']]){_0x23de6a['stopConsuming']();}await(0x0,utils_1['sleepFor'])(enums_1['HMSH_BLOCK_TIME_MS']*0x2);}async['stopConsuming'](){this['shouldConsume']=![],this['logger']['info']('router-stream-stopping',this['topic']?{'topic':this['topic']}:undefined),this['cancelThrottle']();}['cancelThrottle'](){this['sleepTimout']&&clearTimeout(this['sleepTimout']),this['resetThrottleState']();}['setThrottle'](_0x373fbc){if(!Number['isInteger'](_0x373fbc)||_0x373fbc<0x0||_0x373fbc>enums_1['MAX_DELAY'])throw new Error('Throttle\x20must\x20be\x20a\x20non-negative\x20integer\x20and\x20not\x20exceed\x20'+enums_1['MAX_DELAY']+'\x20ms;\x20send\x20-1\x20to\x20throttle\x20indefinitely');const _0x4bef19=_0x373fbc<this['throttle'];this['throttle']=_0x373fbc,_0x4bef19&&(this['sleepTimout']&&clearTimeout(this['sleepTimout']),this['innerPromiseResolve']&&this['innerPromiseResolve']());}async['claimUnacknowledged'](_0xc2fec2,_0x2046a4,_0x4ef5e3,_0x783da0=this['reclaimDelay'],_0x4a2c2b=enums_1['HMSH_XPENDING_COUNT']){let _0xca382d=[];const _0x30d516=await this['stream']['getPendingMessages'](_0xc2fec2,_0x2046a4,_0x4a2c2b);for(const _0x4d909f of _0x30d516){if(Array['isArray'](_0x4d909f)){const [_0x3c3db9,,_0x53088d,_0x405598]=_0x4d909f;if(_0x53088d>_0x783da0){const _0x211ad9=await this['stream']['claimMessage'](_0xc2fec2,_0x2046a4,_0x4ef5e3,_0x783da0,_0x3c3db9);_0x211ad9['length']&&(_0x405598<=this['reclaimCount']?_0xca382d=_0xca382d['concat'](_0x211ad9):await this['expireUnacknowledged'](_0x211ad9,_0xc2fec2,_0x2046a4,_0x4ef5e3,_0x3c3db9,_0x405598));}}}return _0xca382d;}async['expireUnacknowledged'](_0x344cc6,_0x101c9b,_0x51806e,_0x58f24f,_0x2f2191,_0xddeb08){this['logger']['error']('stream-message-max-delivery-count-exceeded',{'id':_0x2f2191,'stream':_0x101c9b,'group':_0x51806e,'consumer':_0x58f24f,'code':enums_1['HMSH_CODE_UNACKED'],'count':_0xddeb08});const _0x315051=_0x344cc6[0x0]?.[0x1]?.[0x1],[_0x3dc73e,_0x2c9e41]=this['parseStreamData'](_0x315051);if(_0x3dc73e)return this['logger']['error']('expire-unacknowledged-parse-fatal-error',{'id':_0x2f2191,'err':_0x3dc73e});else{if(!_0x2c9e41||!_0x2c9e41['metadata'])return this['logger']['error']('expire-unacknowledged-parse-fatal-error',{'id':_0x2f2191});}let _0x400fff,_0x36c081;try{_0x400fff=new telemetry_1['TelemetryService'](this['appId']),_0x400fff['startStreamSpan'](_0x2c9e41,stream_1['StreamRole']['SYSTEM']),_0x400fff['setStreamError']('Stream\x20Message\x20Max\x20Delivery\x20Count\x20Exceeded');const _0x1ff90b=this['structureUnacknowledgedError'](_0x2c9e41);_0x36c081=await this['publishResponse'](_0x2c9e41,_0x1ff90b),_0x400fff['setStreamAttributes']({'app.worker.mid':_0x36c081}),await this['ackAndDelete'](_0x101c9b,_0x51806e,_0x2f2191);}catch(_0x2eda89){_0x36c081?(this['logger']['error']('expire-unacknowledged-pub-fatal-error',{'id':_0x2f2191,'err':_0x2eda89,..._0x2c9e41['metadata']}),_0x400fff['setStreamAttributes']({'app.system.fatal':'expire-unacknowledged-pub-fatal-error'})):(this['logger']['error']('expire-unacknowledged-ack-fatal-error',{'id':_0x2f2191,'err':_0x2eda89,..._0x2c9e41['metadata']}),_0x400fff['setStreamAttributes']({'app.system.fatal':'expire-unacknowledged-ack-fatal-error'}));}finally{_0x400fff['endStreamSpan']();}}['parseStreamData'](_0x185676){try{return[,JSON['parse'](_0x185676)];}catch(_0x59c897){return[_0x59c897];}}}exports['Router']=Router,Router['instances']=new Set();
@@ -0,0 +1,7 @@
1
+ import { RedisClient } from '../../types/redis';
2
+ import { ILogger } from '../logger';
3
+ import { SearchService } from './index';
4
+ declare class SearchServiceFactory {
5
+ static init(redisClient: RedisClient, redisStoreClient: RedisClient | undefined, namespace: string, appId: string, logger: ILogger): Promise<SearchService<any>>;
6
+ }
7
+ export { SearchServiceFactory };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchServiceFactory = void 0;
4
+ const utils_1 = require("../../modules/utils");
5
+ const ioredis_1 = require("./providers/redis/ioredis");
6
+ const redis_1 = require("./providers/redis/redis");
7
+ class SearchServiceFactory {
8
+ static async init(redisClient, redisStoreClient, namespace, appId, logger) {
9
+ let service;
10
+ if ((0, utils_1.identifyRedisType)(redisClient) === 'redis') {
11
+ service = new redis_1.RedisSearchService(redisClient, redisStoreClient);
12
+ }
13
+ else {
14
+ service = new ioredis_1.IORedisSearchService(redisClient, redisStoreClient);
15
+ }
16
+ await service.init(namespace, appId, logger);
17
+ return service;
18
+ }
19
+ }
20
+ exports.SearchServiceFactory = SearchServiceFactory;
@@ -0,0 +1,21 @@
1
+ import { ILogger } from '../logger';
2
+ declare abstract class SearchService<Client> {
3
+ protected searchClient: Client;
4
+ protected storeClient: Client;
5
+ protected namespace: string;
6
+ protected logger: ILogger;
7
+ protected appId: string;
8
+ constructor(searchClient: Client, storeClient?: Client);
9
+ abstract init(namespace: string, appId: string, logger: ILogger): Promise<void>;
10
+ abstract createSearchIndex(indexName: string, prefixes: string[], schema: string[]): Promise<void>;
11
+ abstract listSearchIndexes(): Promise<string[]>;
12
+ abstract setFields(key: string, fields: Record<string, string>): Promise<number>;
13
+ abstract getField(key: string, field: string): Promise<string>;
14
+ abstract getFields(key: string, fields: string[]): Promise<string[]>;
15
+ abstract getAllFields(key: string): Promise<Record<string, string>>;
16
+ abstract deleteFields(key: string, fields: string[]): Promise<number>;
17
+ abstract incrementFieldByFloat(key: string, field: string, increment: number): Promise<number>;
18
+ abstract sendQuery(query: any): Promise<any>;
19
+ abstract sendIndexedQuery(index: string, query: any[]): Promise<any>;
20
+ }
21
+ export { SearchService };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchService = void 0;
4
+ class SearchService {
5
+ constructor(searchClient, storeClient) {
6
+ this.searchClient = searchClient;
7
+ this.storeClient = storeClient;
8
+ }
9
+ }
10
+ exports.SearchService = SearchService;
@@ -0,0 +1,18 @@
1
+ import { SearchService } from '../../index';
2
+ import { ILogger } from '../../../logger';
3
+ import { IORedisClientType } from '../../../../types/redis';
4
+ declare class IORedisSearchService extends SearchService<IORedisClientType> {
5
+ constructor(searchClient: IORedisClientType, storeClient?: IORedisClientType);
6
+ init(namespace: string, appId: string, logger: ILogger): Promise<void>;
7
+ createSearchIndex(indexName: string, prefixes: string[], schema: string[]): Promise<void>;
8
+ listSearchIndexes(): Promise<string[]>;
9
+ setFields(key: string, fields: Record<string, string>): Promise<number>;
10
+ getField(key: string, field: string): Promise<string>;
11
+ getFields(key: string, fields: string[]): Promise<string[]>;
12
+ getAllFields(key: string): Promise<Record<string, string>>;
13
+ deleteFields(key: string, fields: string[]): Promise<number>;
14
+ incrementFieldByFloat(key: string, field: string, increment: number): Promise<number>;
15
+ sendQuery(...query: [string, ...string[]]): Promise<any>;
16
+ sendIndexedQuery(index: string, query: string[]): Promise<string[]>;
17
+ }
18
+ export { IORedisSearchService };
@@ -0,0 +1 @@
1
+ 'use strict';(function(_0x1b0580,_0x54110c){const _0x569611=_0x1974,_0x7ce801=_0x1b0580();while(!![]){try{const _0x3d91a4=parseInt(_0x569611(0x150))/0x1*(parseInt(_0x569611(0x14c))/0x2)+-parseInt(_0x569611(0x14d))/0x3*(parseInt(_0x569611(0x151))/0x4)+parseInt(_0x569611(0x14f))/0x5+parseInt(_0x569611(0x152))/0x6+parseInt(_0x569611(0x153))/0x7*(parseInt(_0x569611(0x156))/0x8)+parseInt(_0x569611(0x14e))/0x9*(parseInt(_0x569611(0x155))/0xa)+-parseInt(_0x569611(0x154))/0xb;if(_0x3d91a4===_0x54110c)break;else _0x7ce801['push'](_0x7ce801['shift']());}catch(_0x4fd483){_0x7ce801['push'](_0x7ce801['shift']());}}}(_0xdb74,0x9ce85));function _0x1974(_0x4d7dd4,_0x34462a){const _0xdb741=_0xdb74();return _0x1974=function(_0x197489,_0x2294b1){_0x197489=_0x197489-0x14c;let _0x53fd15=_0xdb741[_0x197489];return _0x53fd15;},_0x1974(_0x4d7dd4,_0x34462a);}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['IORedisSearchService']=void 0x0;const index_1=require('../../index');function _0xdb74(){const _0xd1d4dc=['6007312JmNlMK','45608ZfTRJh','27nxUzFo','45171NELeFe','1774195IBpJHi','28iNTrdF','229224mlMYbw','7556772ebMaqK','7zTKubl','20794961jphkSN','90crosnh'];_0xdb74=function(){return _0xd1d4dc;};return _0xdb74();}class IORedisSearchService extends index_1['SearchService']{constructor(_0xb97ce6,_0x519205){super(_0xb97ce6,_0x519205);}async['init'](_0x2969cf,_0x1a6c3b,_0x3ab00c){this['namespace']=_0x2969cf,this['appId']=_0x1a6c3b,this['logger']=_0x3ab00c;}async['createSearchIndex'](_0x1dd185,_0x4f8560,_0x4b8bc0){try{await this['searchClient']['call']('FT.CREATE',_0x1dd185,'ON','HASH','PREFIX',_0x4f8560['length']['toString'](),..._0x4f8560,'SCHEMA',..._0x4b8bc0);}catch(_0x5687e4){this['logger']['info']('Error\x20creating\x20search\x20index',{'error':_0x5687e4});throw _0x5687e4;}}async['listSearchIndexes'](){try{const _0x1c1a23=await this['searchClient']['call']('FT._LIST');return _0x1c1a23;}catch(_0x46504b){this['logger']['info']('Error\x20listing\x20search\x20indexes',{'error':_0x46504b});throw _0x46504b;}}async['setFields'](_0x286e69,_0xc5cd0f){try{const _0x45d48c=await this['searchClient']['hset'](_0x286e69,_0xc5cd0f);return Number(_0x45d48c);}catch(_0x3081a1){this['logger']['error']('Error\x20setting\x20fields\x20for\x20key:\x20'+_0x286e69,{'error':_0x3081a1});throw _0x3081a1;}}async['getField'](_0x2b9bf8,_0x2c7ca5){try{return await this['searchClient']['hget'](_0x2b9bf8,_0x2c7ca5);}catch(_0x211e6e){this['logger']['error']('Error\x20getting\x20field\x20'+_0x2c7ca5+'\x20for\x20key:\x20'+_0x2b9bf8,{'error':_0x211e6e});throw _0x211e6e;}}async['getFields'](_0x523a71,_0x43946b){try{return await this['searchClient']['hmget'](_0x523a71,[..._0x43946b]);}catch(_0x34a47a){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x523a71,{'error':_0x34a47a});throw _0x34a47a;}}async['getAllFields'](_0x3e40ae){try{return await this['searchClient']['hgetall'](_0x3e40ae);}catch(_0x223e50){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x3e40ae,{'error':_0x223e50});throw _0x223e50;}}async['deleteFields'](_0x57bb54,_0x1d08c2){try{const _0xed0066=await this['searchClient']['hdel'](_0x57bb54,..._0x1d08c2);return Number(_0xed0066);}catch(_0x3cda5c){this['logger']['error']('Error\x20deleting\x20fields\x20for\x20key:\x20'+_0x57bb54,{'error':_0x3cda5c});throw _0x3cda5c;}}async['incrementFieldByFloat'](_0x42ba48,_0x25738b,_0xa1c839){try{const _0x3ac7a9=await this['searchClient']['hincrbyfloat'](_0x42ba48,_0x25738b,_0xa1c839);return Number(_0x3ac7a9);}catch(_0xeeede5){this['logger']['error']('Error\x20incrementing\x20field\x20'+_0x25738b+'\x20for\x20key:\x20'+_0x42ba48,{'error':_0xeeede5});throw _0xeeede5;}}async['sendQuery'](..._0x2effc5){try{return await this['searchClient']['call'](..._0x2effc5);}catch(_0x16c614){this['logger']['error']('Error\x20executing\x20query',{'error':_0x16c614});throw _0x16c614;}}async['sendIndexedQuery'](_0x23f536,_0x4e9575){try{if(_0x4e9575[0x0]?.['startsWith']('FT.')){const [_0x53aff5,..._0x1ce62b]=_0x4e9575;return await this['searchClient']['call'](_0x53aff5,..._0x1ce62b);}return await this['searchClient']['call']('FT.SEARCH',_0x23f536,..._0x4e9575);}catch(_0x4e4054){this['logger']['error']('Error\x20executing\x20query',{'error':_0x4e4054});throw _0x4e4054;}}}exports['IORedisSearchService']=IORedisSearchService;
@@ -0,0 +1,18 @@
1
+ import { SearchService } from '../../index';
2
+ import { ILogger } from '../../../logger';
3
+ import { RedisRedisClientType } from '../../../../types/redis';
4
+ declare class RedisSearchService extends SearchService<RedisRedisClientType> {
5
+ constructor(searchClient: RedisRedisClientType, storeClient?: RedisRedisClientType);
6
+ init(namespace: string, appId: string, logger: ILogger): Promise<void>;
7
+ createSearchIndex(indexName: string, prefixes: string[], schema: string[]): Promise<void>;
8
+ listSearchIndexes(): Promise<string[]>;
9
+ setFields(key: string, fields: Record<string, string>): Promise<number>;
10
+ getField(key: string, field: string): Promise<string>;
11
+ getFields(key: string, fields: string[]): Promise<string[]>;
12
+ getAllFields(key: string): Promise<Record<string, string>>;
13
+ deleteFields(key: string, fields: string[]): Promise<number>;
14
+ incrementFieldByFloat(key: string, field: string, increment: number): Promise<number>;
15
+ sendQuery(...query: any[]): Promise<any>;
16
+ sendIndexedQuery(index: string, query: string[]): Promise<string[]>;
17
+ }
18
+ export { RedisSearchService };
@@ -0,0 +1 @@
1
+ 'use strict';(function(_0x40f4f0,_0x3d9601){const _0x32c7f2=_0x1e42,_0xfa50a3=_0x40f4f0();while(!![]){try{const _0x2e5533=parseInt(_0x32c7f2(0x122))/0x1+-parseInt(_0x32c7f2(0x11f))/0x2+parseInt(_0x32c7f2(0x11a))/0x3+parseInt(_0x32c7f2(0x121))/0x4*(-parseInt(_0x32c7f2(0x11b))/0x5)+parseInt(_0x32c7f2(0x11c))/0x6+parseInt(_0x32c7f2(0x11e))/0x7*(-parseInt(_0x32c7f2(0x11d))/0x8)+-parseInt(_0x32c7f2(0x123))/0x9*(parseInt(_0x32c7f2(0x120))/0xa);if(_0x2e5533===_0x3d9601)break;else _0xfa50a3['push'](_0xfa50a3['shift']());}catch(_0x5eb1b6){_0xfa50a3['push'](_0xfa50a3['shift']());}}}(_0x91ac,0x49bcf));function _0x91ac(){const _0x3b9fe5=['431954OEEbES','5264739uartoR','1787481qioEKh','1135oExlch','2432058waKXvz','65488NcGsKx','308zlciuW','54530akKMXJ','10rPQmQa','2796jSpgUo'];_0x91ac=function(){return _0x3b9fe5;};return _0x91ac();}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['RedisSearchService']=void 0x0;function _0x1e42(_0x571076,_0x53878a){const _0x91ac6a=_0x91ac();return _0x1e42=function(_0x1e42c7,_0x2f9f7d){_0x1e42c7=_0x1e42c7-0x11a;let _0x17f0e4=_0x91ac6a[_0x1e42c7];return _0x17f0e4;},_0x1e42(_0x571076,_0x53878a);}const index_1=require('../../index');class RedisSearchService extends index_1['SearchService']{constructor(_0x4990f9,_0x2a2366){super(_0x4990f9,_0x2a2366);}async['init'](_0x4b00b0,_0x2d55a8,_0x3f6017){this['namespace']=_0x4b00b0,this['appId']=_0x2d55a8,this['logger']=_0x3f6017;}async['createSearchIndex'](_0x10311c,_0x31c546,_0x536f0b){try{await this['searchClient']['sendCommand'](['FT.CREATE',_0x10311c,'ON','HASH','PREFIX',_0x31c546['length']['toString'](),..._0x31c546,'SCHEMA',..._0x536f0b]);}catch(_0x423d3d){this['logger']['info']('Error\x20creating\x20search\x20index',{'error':_0x423d3d});throw _0x423d3d;}}async['listSearchIndexes'](){try{const _0x38e02b=await this['searchClient']['sendCommand'](['FT._LIST']);return _0x38e02b;}catch(_0x7b98da){this['logger']['info']('Error\x20listing\x20search\x20indexes',{'error':_0x7b98da});throw _0x7b98da;}}async['setFields'](_0x27a78c,_0x15dc02){try{const _0x333bca=await this['searchClient']['HSET'](_0x27a78c,_0x15dc02);return Number(_0x333bca);}catch(_0x54c9a9){this['logger']['error']('Error\x20setting\x20fields\x20for\x20key:\x20'+_0x27a78c,{'error':_0x54c9a9});throw _0x54c9a9;}}async['getField'](_0x26e872,_0x388884){try{return await this['searchClient']['HGET'](_0x26e872,_0x388884);}catch(_0x582938){this['logger']['error']('Error\x20getting\x20field\x20'+_0x388884+'\x20for\x20key:\x20'+_0x26e872,{'error':_0x582938});throw _0x582938;}}async['getFields'](_0x5865a8,_0x539eb6){try{return await this['searchClient']['HMGET'](_0x5865a8,[..._0x539eb6]);}catch(_0x47c6d4){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x5865a8,{'error':_0x47c6d4});throw _0x47c6d4;}}async['getAllFields'](_0x406e1e){try{return await this['searchClient']['HGETALL'](_0x406e1e);}catch(_0x4430f1){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x406e1e,{'error':_0x4430f1});throw _0x4430f1;}}async['deleteFields'](_0x10a196,_0x8a54f0){try{const _0x3c6698=await this['searchClient']['HDEL'](_0x10a196,_0x8a54f0);return Number(_0x3c6698);}catch(_0x4210c4){this['logger']['error']('Error\x20deleting\x20fields\x20for\x20key:\x20'+_0x10a196,{'error':_0x4210c4});throw _0x4210c4;}}async['incrementFieldByFloat'](_0x4d7609,_0x254625,_0x5d3bbf){try{const _0xe5c954=await this['searchClient']['HINCRBYFLOAT'](_0x4d7609,_0x254625,_0x5d3bbf);return Number(_0xe5c954);}catch(_0x565c30){this['logger']['error']('Error\x20incrementing\x20field\x20'+_0x254625+'\x20for\x20key:\x20'+_0x4d7609,{'error':_0x565c30});throw _0x565c30;}}async['sendQuery'](..._0x5490cd){try{return await this['searchClient']['sendCommand'](_0x5490cd);}catch(_0x1d39b8){this['logger']['error']('Error\x20executing\x20query',{'error':_0x1d39b8});throw _0x1d39b8;}}async['sendIndexedQuery'](_0x1d25cf,_0x10284b){try{if(_0x10284b[0x0]?.['startsWith']('FT.'))return await this['searchClient']['sendCommand'](_0x10284b);return await this['searchClient']['sendCommand'](['FT.SEARCH',_0x1d25cf,..._0x10284b]);}catch(_0x320d01){this['logger']['error']('Error\x20executing\x20query',{'error':_0x320d01});throw _0x320d01;}}}exports['RedisSearchService']=RedisSearchService;