@hotmeshio/hotmesh 0.3.6 → 0.3.8

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 (124) hide show
  1. package/README.md +13 -1
  2. package/build/index.d.ts +3 -1
  3. package/build/index.js +10 -1
  4. package/build/modules/key.js +1 -62
  5. package/build/modules/utils.js +1 -267
  6. package/build/package.json +12 -8
  7. package/build/services/activities/activity.js +1 -495
  8. package/build/services/activities/await.js +1 -109
  9. package/build/services/activities/cycle.js +1 -96
  10. package/build/services/activities/hook.js +1 -154
  11. package/build/services/activities/index.js +1 -20
  12. package/build/services/activities/interrupt.js +1 -149
  13. package/build/services/activities/signal.js +1 -118
  14. package/build/services/activities/trigger.js +1 -237
  15. package/build/services/activities/worker.js +1 -101
  16. package/build/services/collator/index.js +1 -197
  17. package/build/services/compiler/deployer.d.ts +3 -1
  18. package/build/services/compiler/deployer.js +1 -455
  19. package/build/services/compiler/index.d.ts +3 -1
  20. package/build/services/compiler/index.js +1 -91
  21. package/build/services/compiler/validator.js +1 -122
  22. package/build/services/engine/index.d.ts +5 -2
  23. package/build/services/engine/index.js +1 -562
  24. package/build/services/exporter/index.js +1 -93
  25. package/build/services/mapper/index.js +1 -67
  26. package/build/services/meshdata/index.d.ts +0 -1
  27. package/build/services/meshdata/index.js +16 -24
  28. package/build/services/meshflow/client.js +4 -8
  29. package/build/services/meshflow/exporter.js +1 -186
  30. package/build/services/meshflow/index.d.ts +2 -0
  31. package/build/services/meshflow/index.js +2 -0
  32. package/build/services/meshflow/search.d.ts +4 -5
  33. package/build/services/meshflow/search.js +45 -35
  34. package/build/services/meshflow/workflow.d.ts +1 -1
  35. package/build/services/meshflow/workflow.js +3 -28
  36. package/build/services/pipe/functions/array.js +1 -74
  37. package/build/services/pipe/functions/bitwise.js +1 -24
  38. package/build/services/pipe/functions/conditional.js +1 -36
  39. package/build/services/pipe/functions/cron.js +1 -32
  40. package/build/services/pipe/functions/date.js +1 -164
  41. package/build/services/pipe/functions/index.js +1 -30
  42. package/build/services/pipe/functions/json.js +1 -12
  43. package/build/services/pipe/functions/logical.js +1 -12
  44. package/build/services/pipe/functions/math.js +1 -182
  45. package/build/services/pipe/functions/number.js +1 -60
  46. package/build/services/pipe/functions/object.js +1 -81
  47. package/build/services/pipe/functions/string.js +1 -69
  48. package/build/services/pipe/functions/symbol.js +1 -33
  49. package/build/services/pipe/functions/unary.js +1 -18
  50. package/build/services/pipe/index.js +1 -221
  51. package/build/services/quorum/index.d.ts +1 -1
  52. package/build/services/quorum/index.js +1 -219
  53. package/build/services/reporter/index.js +1 -331
  54. package/build/services/router/index.js +1 -420
  55. package/build/services/search/factory.d.ts +7 -0
  56. package/build/services/search/factory.js +20 -0
  57. package/build/services/search/index.d.ts +21 -0
  58. package/build/services/search/index.js +10 -0
  59. package/build/services/search/providers/redis/ioredis.d.ts +18 -0
  60. package/build/services/search/providers/redis/ioredis.js +1 -0
  61. package/build/services/search/providers/redis/redis.d.ts +18 -0
  62. package/build/services/search/providers/redis/redis.js +1 -0
  63. package/build/services/serializer/index.js +1 -265
  64. package/build/services/store/factory.d.ts +2 -1
  65. package/build/services/store/factory.js +2 -2
  66. package/build/services/store/index.d.ts +71 -97
  67. package/build/services/store/index.js +2 -939
  68. package/build/services/store/providers/postgres/postgres.d.ts +0 -0
  69. package/build/services/store/providers/postgres/postgres.js +0 -0
  70. package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
  71. package/build/services/store/providers/postgres/types/hash.js +0 -0
  72. package/build/services/store/providers/postgres/types/list.d.ts +0 -0
  73. package/build/services/store/providers/postgres/types/list.js +0 -0
  74. package/build/services/store/providers/postgres/types/string.d.ts +0 -0
  75. package/build/services/store/providers/postgres/types/string.js +0 -0
  76. package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
  77. package/build/services/store/providers/postgres/types/zset.js +0 -0
  78. package/build/services/store/providers/redis/_base.d.ts +98 -0
  79. package/build/services/store/providers/redis/_base.js +1 -0
  80. package/build/services/store/providers/redis/ioredis.d.ts +12 -0
  81. package/build/services/store/providers/redis/ioredis.js +1 -0
  82. package/build/services/store/providers/redis/redis.d.ts +13 -0
  83. package/build/services/store/providers/redis/redis.js +1 -0
  84. package/build/services/store/providers/store-initializable.d.ts +5 -0
  85. package/build/services/store/providers/store-initializable.js +1 -0
  86. package/build/services/stream/factory.d.ts +2 -1
  87. package/build/services/stream/factory.js +5 -5
  88. package/build/services/stream/index.d.ts +13 -14
  89. package/build/services/stream/index.js +3 -2
  90. package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
  91. package/build/services/stream/providers/postgres/_deploy.js +1 -0
  92. package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
  93. package/build/services/stream/providers/redis/ioredis.js +1 -0
  94. package/build/services/stream/providers/redis/redis.d.ts +21 -0
  95. package/build/services/stream/providers/redis/redis.js +1 -0
  96. package/build/services/stream/providers/stream-initializable.d.ts +5 -0
  97. package/build/services/stream/providers/stream-initializable.js +1 -0
  98. package/build/services/sub/factory.d.ts +1 -1
  99. package/build/services/sub/factory.js +5 -5
  100. package/build/services/sub/index.d.ts +9 -7
  101. package/build/services/sub/index.js +3 -2
  102. package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
  103. package/build/services/sub/providers/redis/ioredis.js +1 -0
  104. package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
  105. package/build/services/sub/providers/redis/redis.js +1 -0
  106. package/build/services/task/index.js +1 -171
  107. package/build/services/telemetry/index.js +1 -225
  108. package/build/services/worker/index.d.ts +2 -2
  109. package/build/services/worker/index.js +1 -158
  110. package/build/types/redis.d.ts +5 -5
  111. package/index.ts +18 -1
  112. package/package.json +12 -8
  113. package/typedoc.json +2 -1
  114. package/types/redis.ts +5 -5
  115. package/build/services/store/clients/ioredis.d.ts +0 -30
  116. package/build/services/store/clients/ioredis.js +0 -220
  117. package/build/services/store/clients/redis.d.ts +0 -32
  118. package/build/services/store/clients/redis.js +0 -319
  119. package/build/services/stream/clients/ioredis.d.ts +0 -24
  120. package/build/services/stream/clients/ioredis.js +0 -121
  121. package/build/services/stream/clients/redis.d.ts +0 -24
  122. package/build/services/stream/clients/redis.js +0 -161
  123. package/build/services/sub/clients/ioredis.js +0 -72
  124. 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(_0x59722d,_0x229905){const _0xbf2560=_0x1497,_0x3810af=_0x59722d();while(!![]){try{const _0x3a8fc5=parseInt(_0xbf2560(0x133))/0x1+-parseInt(_0xbf2560(0x132))/0x2+parseInt(_0xbf2560(0x12b))/0x3+parseInt(_0xbf2560(0x12f))/0x4+-parseInt(_0xbf2560(0x12c))/0x5*(-parseInt(_0xbf2560(0x12a))/0x6)+parseInt(_0xbf2560(0x130))/0x7*(parseInt(_0xbf2560(0x131))/0x8)+parseInt(_0xbf2560(0x12e))/0x9*(-parseInt(_0xbf2560(0x12d))/0xa);if(_0x3a8fc5===_0x229905)break;else _0x3810af['push'](_0x3810af['shift']());}catch(_0x22f558){_0x3810af['push'](_0x3810af['shift']());}}}(_0x3857,0xec2cc));Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['Router']=void 0x0;function _0x1497(_0xebafa5,_0x2c96c4){const _0x385716=_0x3857();return _0x1497=function(_0x149737,_0x498101){_0x149737=_0x149737-0x12a;let _0x40313=_0x385716[_0x149737];return _0x40313;},_0x1497(_0xebafa5,_0x2c96c4);}function _0x3857(){const _0x297259=['1687509fiKasR','23325qtJbSd','1444070CscMws','261jIVtFI','3448588lRoyEb','14ZDVEEE','6651448syIWjE','399446KRSgqH','1012501uIygYT','1614RdjOSS'];_0x3857=function(){return _0x297259;};return _0x3857();}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(_0x1bbcdc,_0x211153,_0x43c661,_0x3b4dfe){this['throttle']=0x0,this['errorCount']=0x0,this['counts']={},this['currentTimerId']=null,this['sleepPromiseResolve']=null,this['innerPromiseResolve']=null,this['isSleeping']=![],this['sleepTimout']=null,this['appId']=_0x1bbcdc['appId'],this['guid']=_0x1bbcdc['guid'],this['role']=_0x1bbcdc['role'],this['topic']=_0x1bbcdc['topic'],this['stream']=_0x211153,this['store']=_0x43c661,this['throttle']=_0x1bbcdc['throttle'],this['reclaimDelay']=_0x1bbcdc['reclaimDelay']||enums_1['HMSH_XCLAIM_DELAY_MS'],this['reclaimCount']=_0x1bbcdc['reclaimCount']||enums_1['HMSH_XCLAIM_COUNT'],this['logger']=_0x3b4dfe,this['readonly']=_0x1bbcdc['readonly']||![],this['resetThrottleState']();}['resetThrottleState'](){this['sleepPromiseResolve']=null,this['innerPromiseResolve']=null,this['isSleeping']=![],this['sleepTimout']=null;}async['createGroup'](_0x20434c,_0x3ede67){try{await this['stream']['createConsumerGroup'](_0x20434c,_0x3ede67);}catch(_0x507f2b){this['logger']['debug']('router-stream-group-exists',{'stream':_0x20434c,'group':_0x3ede67});}}async['publishMessage'](_0x62eba2,_0xe3a98a,_0x174b4a){const _0x244ad3=_0xe3a98a?.['code']||'200';this['counts'][_0x244ad3]=(this['counts'][_0x244ad3]||0x0)+0x1;const _0x55768d=this['store']['mintKey'](key_1['KeyType']['STREAMS'],{'appId':this['store']['appId'],'topic':_0x62eba2});return await this['stream']['publishMessage'](_0x55768d,'*','message',JSON['stringify'](_0xe3a98a),_0x174b4a);}async['customSleep'](){if(this['throttle']===0x0)return;if(this['isSleeping'])return;this['isSleeping']=!![];const _0x57e443=Date['now']();await new Promise(async _0x305289=>{this['sleepPromiseResolve']=_0x305289;let _0x4a54ac=Date['now']()-_0x57e443;while(_0x4a54ac<this['throttle']){await new Promise(_0xe5409f=>{this['innerPromiseResolve']=_0xe5409f,this['sleepTimout']=setTimeout(_0xe5409f,this['throttle']-_0x4a54ac);}),_0x4a54ac=Date['now']()-_0x57e443;}this['resetThrottleState'](),_0x305289();});}async['consumeMessages'](_0x1ed84f,_0x456233,_0xbf91a2,_0xa09e7c){if(this['readonly']){this['logger']['info']('router-stream-readonly',{'group':_0x456233,'consumer':_0xbf91a2,'stream':_0x1ed84f});return;}this['logger']['info']('router-stream-starting',{'group':_0x456233,'consumer':_0xbf91a2,'stream':_0x1ed84f}),Router['instances']['add'](this),this['shouldConsume']=!![],await this['createGroup'](_0x1ed84f,_0x456233);let _0x1c00cf=Date['now']();async function _0x13d0e3(){await this['customSleep']();if(this['isStopped'](_0x456233,_0xbf91a2,_0x1ed84f))return;else{if(this['isPaused']()){setImmediate(_0x13d0e3['bind'](this));return;}}try{const _0x2b8451=enums_1['HMSH_BLOCK_TIME_MS']+Math['round'](enums_1['HMSH_BLOCK_TIME_MS']*Math['random']()),_0x104a66=await this['stream']['consumeMessages'](_0x456233,_0xbf91a2,_0x2b8451,_0x1ed84f);if(this['isStopped'](_0x456233,_0xbf91a2,_0x1ed84f))return;else{if(this['isPaused']()){setImmediate(_0x13d0e3['bind'](this));return;}}if(this['isStreamMessage'](_0x104a66)){const [[,_0x1f92d8]]=_0x104a66;for(const [_0x43a09a,_0x44d96b]of _0x1f92d8){await this['consumeOne'](_0x1ed84f,_0x456233,_0x43a09a,_0x44d96b,_0xa09e7c);}}const _0x57053a=Date['now']();if(_0x57053a-_0x1c00cf>this['reclaimDelay']){_0x1c00cf=_0x57053a;const _0x141bd4=await this['claimUnacknowledged'](_0x1ed84f,_0x456233,_0xbf91a2);for(const [_0x468617,_0x8abd3f]of _0x141bd4){await this['consumeOne'](_0x1ed84f,_0x456233,_0x468617,_0x8abd3f,_0xa09e7c);}}setImmediate(_0x13d0e3['bind'](this));}catch(_0x3ef181){if(this['shouldConsume']&&process['env']['NODE_ENV']!=='test'){this['logger']['error']('router-stream-error',{'err':_0x3ef181,'stream':_0x1ed84f,'group':_0x456233,'consumer':_0xbf91a2}),this['errorCount']++;const _0x340004=Math['min'](enums_1['HMSH_GRADUATED_INTERVAL_MS']*0x2**this['errorCount'],enums_1['HMSH_MAX_TIMEOUT_MS']);setTimeout(_0x13d0e3['bind'](this),_0x340004);}}}_0x13d0e3['call'](this);}['isStreamMessage'](_0x384b96){return Array['isArray'](_0x384b96)&&Array['isArray'](_0x384b96[0x0]);}['isPaused'](){return this['throttle']===enums_1['MAX_DELAY'];}['isStopped'](_0x582ccb,_0xdaa0c9,_0x53101e){return!this['shouldConsume']&&this['logger']['info']('router-stream-stopped',{'group':_0x582ccb,'consumer':_0xdaa0c9,'stream':_0x53101e}),!this['shouldConsume'];}async['consumeOne'](_0xc902a,_0x478bd2,_0x471dec,_0x11d08d,_0x5e99c5){this['logger']['debug']('stream-read-one',{'group':_0x478bd2,'stream':_0xc902a,'id':_0x471dec});const [_0x53602f,_0x1afdac]=this['parseStreamData'](_0x11d08d[0x1]);let _0x3dfef7,_0x44e791;try{_0x44e791=new telemetry_1['TelemetryService'](this['appId']),_0x44e791['startStreamSpan'](_0x1afdac,this['role']),_0x3dfef7=await this['execStreamLeg'](_0x1afdac,_0xc902a,_0x471dec,_0x5e99c5['bind'](this)),_0x3dfef7?.['status']===stream_1['StreamStatus']['ERROR']&&_0x44e791['setStreamError']('Function\x20Status\x20Code\x20'+(_0x3dfef7['code']||enums_1['HMSH_CODE_UNKNOWN'])),this['errorCount']=0x0;}catch(_0x3b89b2){this['logger']['error']('stream-read-one-error',{'group':_0x478bd2,'stream':_0xc902a,'id':_0x471dec,'err':_0x3b89b2}),_0x44e791['setStreamError'](_0x3b89b2['message']);}const _0x42122a=await this['publishResponse'](_0x1afdac,_0x3dfef7);_0x44e791['setStreamAttributes']({'app.worker.mid':_0x42122a}),await this['ackAndDelete'](_0xc902a,_0x478bd2,_0x471dec),_0x44e791['endStreamSpan'](),this['logger']['debug']('stream-read-one-end',{'group':_0x478bd2,'stream':_0xc902a,'id':_0x471dec});}async['execStreamLeg'](_0x1f5d34,_0x3fe92c,_0x5452da,_0x27d2fe){let _0x3141d;try{_0x3141d=await _0x27d2fe(_0x1f5d34);}catch(_0xf6bbf1){this['logger']['error']('stream-call-function-error',{..._0xf6bbf1,'input':_0x1f5d34,'stack':_0xf6bbf1['stack'],'message':_0xf6bbf1['message'],'name':_0xf6bbf1['name'],'stream':_0x3fe92c,'id':_0x5452da}),_0x3141d=this['structureUnhandledError'](_0x1f5d34,_0xf6bbf1);}return _0x3141d;}async['ackAndDelete'](_0xd1a166,_0x435f48,_0x2b71bb){await this['stream']['ackAndDelete'](_0xd1a166,_0x435f48,_0x2b71bb);}async['publishResponse'](_0xb25818,_0x1061ad){if(_0x1061ad&&typeof _0x1061ad==='object'){if(_0x1061ad['status']==='error'){const [_0x4de53f,_0x514ec4]=this['shouldRetry'](_0xb25818,_0x1061ad);if(_0x4de53f)return await(0x0,utils_1['sleepFor'])(_0x514ec4),await this['publishMessage'](_0xb25818['metadata']['topic'],{'data':_0xb25818['data'],'metadata':{..._0xb25818['metadata'],'try':(_0xb25818['metadata']['try']||0x0)+0x1},'policies':_0xb25818['policies']});else _0x1061ad=this['structureError'](_0xb25818,_0x1061ad);}else typeof _0x1061ad['metadata']!=='object'?_0x1061ad['metadata']={..._0xb25818['metadata'],'guid':(0x0,utils_1['guid'])()}:_0x1061ad['metadata']['guid']=(0x0,utils_1['guid'])();return _0x1061ad['type']=stream_1['StreamDataType']['RESPONSE'],await this['publishMessage'](null,_0x1061ad);}}['shouldRetry'](_0x15b065,_0x4630c6){const _0x320c86=_0x15b065['policies']?.['retry'],_0x38d047=_0x4630c6['code']['toString'](),_0x270835=_0x320c86?.[_0x38d047],_0x2d0671=_0x270835?.[0x0],_0x4a2e7f=Math['min'](_0x15b065['metadata']['try']||0x0,enums_1['HMSH_MAX_RETRIES']);if(_0x2d0671>_0x4a2e7f)return[!![],Math['pow'](0xa,_0x4a2e7f+0x1)];return[![],0x0];}['structureUnhandledError'](_0x1cc755,_0x227eeb){const _0x4a753c={};return typeof _0x227eeb['message']==='string'?_0x4a753c['message']=_0x227eeb['message']:_0x4a753c['message']=enums_1['HMSH_STATUS_UNKNOWN'],typeof _0x227eeb['stack']==='string'&&(_0x4a753c['stack']=_0x227eeb['stack']),typeof _0x227eeb['name']==='string'&&(_0x4a753c['name']=_0x227eeb['name']),{'status':'error','code':enums_1['HMSH_CODE_UNKNOWN'],'metadata':{..._0x1cc755['metadata'],'guid':(0x0,utils_1['guid'])()},'data':_0x4a753c};}['structureUnacknowledgedError'](_0x4124c3){const _0x46e0f4='stream\x20message\x20max\x20delivery\x20count\x20exceeded',_0x17bfdb=enums_1['HMSH_CODE_UNACKED'],_0x540ddd={'message':_0x46e0f4,'code':_0x17bfdb},_0xb11a5e={'metadata':{..._0x4124c3['metadata'],'guid':(0x0,utils_1['guid'])()},'status':stream_1['StreamStatus']['ERROR'],'code':_0x17bfdb,'data':_0x540ddd};return delete _0xb11a5e['metadata']['topic'],_0xb11a5e;}['structureError'](_0x22b3bc,_0x1d2480){const _0x512ccf=_0x1d2480['data']?.['message']?_0x1d2480['data']?.['message']['toString']():enums_1['HMSH_STATUS_UNKNOWN'],_0x4ea3e2=_0x1d2480['code']||_0x1d2480['data']?.['code'],_0x2c2b25=isNaN(_0x4ea3e2)?enums_1['HMSH_CODE_UNKNOWN']:parseInt(_0x4ea3e2['toString']()),_0x22cc05=_0x1d2480['data']?.['stack']?_0x1d2480['data']?.['stack']['toString']():undefined,_0x573ab4={'message':_0x512ccf,'code':_0x2c2b25,'stack':_0x22cc05};return typeof _0x1d2480['data']?.['error']==='object'&&(_0x573ab4['error']={..._0x1d2480['data']['error']}),{'status':stream_1['StreamStatus']['ERROR'],'code':_0x2c2b25,'stack':_0x22cc05,'metadata':{..._0x22b3bc['metadata'],'guid':(0x0,utils_1['guid'])()},'data':_0x573ab4};}static async['stopConsuming'](){for(const _0x3d9a28 of[...Router['instances']]){_0x3d9a28['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'](_0x3cb4f1){if(!Number['isInteger'](_0x3cb4f1)||_0x3cb4f1<0x0||_0x3cb4f1>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 _0x4da5f8=_0x3cb4f1<this['throttle'];this['throttle']=_0x3cb4f1,_0x4da5f8&&(this['sleepTimout']&&clearTimeout(this['sleepTimout']),this['innerPromiseResolve']&&this['innerPromiseResolve']());}async['claimUnacknowledged'](_0x47d7da,_0x44fadb,_0x419390,_0xd34721=this['reclaimDelay'],_0x3e553d=enums_1['HMSH_XPENDING_COUNT']){let _0x2cd959=[];const _0x34e400=await this['stream']['getPendingMessages'](_0x47d7da,_0x44fadb,_0x3e553d);for(const _0x240e0f of _0x34e400){if(Array['isArray'](_0x240e0f)){const [_0x1f732a,,_0x39967a,_0x2ec6d3]=_0x240e0f;if(_0x39967a>_0xd34721){const _0x3f9973=await this['stream']['claimMessage'](_0x47d7da,_0x44fadb,_0x419390,_0xd34721,_0x1f732a);_0x3f9973['length']&&(_0x2ec6d3<=this['reclaimCount']?_0x2cd959=_0x2cd959['concat'](_0x3f9973):await this['expireUnacknowledged'](_0x3f9973,_0x47d7da,_0x44fadb,_0x419390,_0x1f732a,_0x2ec6d3));}}}return _0x2cd959;}async['expireUnacknowledged'](_0x33eb80,_0x3ff700,_0x3b82f1,_0x447e77,_0x17536a,_0x20f24f){this['logger']['error']('stream-message-max-delivery-count-exceeded',{'id':_0x17536a,'stream':_0x3ff700,'group':_0x3b82f1,'consumer':_0x447e77,'code':enums_1['HMSH_CODE_UNACKED'],'count':_0x20f24f});const _0x5c26d0=_0x33eb80[0x0]?.[0x1]?.[0x1],[_0x24d49f,_0x5f1ccd]=this['parseStreamData'](_0x5c26d0);if(_0x24d49f)return this['logger']['error']('expire-unacknowledged-parse-fatal-error',{'id':_0x17536a,'err':_0x24d49f});else{if(!_0x5f1ccd||!_0x5f1ccd['metadata'])return this['logger']['error']('expire-unacknowledged-parse-fatal-error',{'id':_0x17536a});}let _0x1ea3cd,_0x2d7626;try{_0x1ea3cd=new telemetry_1['TelemetryService'](this['appId']),_0x1ea3cd['startStreamSpan'](_0x5f1ccd,stream_1['StreamRole']['SYSTEM']),_0x1ea3cd['setStreamError']('Stream\x20Message\x20Max\x20Delivery\x20Count\x20Exceeded');const _0x36314c=this['structureUnacknowledgedError'](_0x5f1ccd);_0x2d7626=await this['publishResponse'](_0x5f1ccd,_0x36314c),_0x1ea3cd['setStreamAttributes']({'app.worker.mid':_0x2d7626}),await this['ackAndDelete'](_0x3ff700,_0x3b82f1,_0x17536a);}catch(_0x451ad5){_0x2d7626?(this['logger']['error']('expire-unacknowledged-pub-fatal-error',{'id':_0x17536a,'err':_0x451ad5,..._0x5f1ccd['metadata']}),_0x1ea3cd['setStreamAttributes']({'app.system.fatal':'expire-unacknowledged-pub-fatal-error'})):(this['logger']['error']('expire-unacknowledged-ack-fatal-error',{'id':_0x17536a,'err':_0x451ad5,..._0x5f1ccd['metadata']}),_0x1ea3cd['setStreamAttributes']({'app.system.fatal':'expire-unacknowledged-ack-fatal-error'}));}finally{_0x1ea3cd['endStreamSpan']();}}['parseStreamData'](_0x7d8d37){try{return[,JSON['parse'](_0x7d8d37)];}catch(_0x5eef93){return[_0x5eef93];}}}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(_0x140112,_0x3296e1){const _0x172cda=_0x32d6,_0x1063f7=_0x140112();while(!![]){try{const _0x53bfeb=parseInt(_0x172cda(0x173))/0x1*(-parseInt(_0x172cda(0x16c))/0x2)+-parseInt(_0x172cda(0x170))/0x3*(parseInt(_0x172cda(0x16e))/0x4)+parseInt(_0x172cda(0x16f))/0x5*(parseInt(_0x172cda(0x16b))/0x6)+-parseInt(_0x172cda(0x172))/0x7+parseInt(_0x172cda(0x174))/0x8+parseInt(_0x172cda(0x171))/0x9*(-parseInt(_0x172cda(0x175))/0xa)+parseInt(_0x172cda(0x16d))/0xb;if(_0x53bfeb===_0x3296e1)break;else _0x1063f7['push'](_0x1063f7['shift']());}catch(_0x4c23c4){_0x1063f7['push'](_0x1063f7['shift']());}}}(_0x1dc2,0x2f363));function _0x32d6(_0x543a26,_0x541f51){const _0x1dc29a=_0x1dc2();return _0x32d6=function(_0x32d6b1,_0xd16bb7){_0x32d6b1=_0x32d6b1-0x16b;let _0x239d7f=_0x1dc29a[_0x32d6b1];return _0x239d7f;},_0x32d6(_0x543a26,_0x541f51);}function _0x1dc2(){const _0x45e64a=['3VqlSKm','643128zYordL','462390KCvERZ','948zgdwQY','214010wekVlG','7485742dzhrkW','1222388oBbQja','8495Vocjvw','3azSChF','27ecHsqU','494529sUMbgv'];_0x1dc2=function(){return _0x45e64a;};return _0x1dc2();}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['IORedisSearchService']=void 0x0;const index_1=require('../../index');class IORedisSearchService extends index_1['SearchService']{constructor(_0x32106b,_0x2de46b){super(_0x32106b,_0x2de46b);}async['init'](_0x2acc28,_0x472757,_0x403a86){this['namespace']=_0x2acc28,this['appId']=_0x472757,this['logger']=_0x403a86;}async['createSearchIndex'](_0x2a8f94,_0x419f2a,_0x56184f){try{await this['searchClient']['call']('FT.CREATE',_0x2a8f94,'ON','HASH','PREFIX',_0x419f2a['length']['toString'](),..._0x419f2a,'SCHEMA',..._0x56184f);}catch(_0x13b7bf){this['logger']['info']('Error\x20creating\x20search\x20index',{'error':_0x13b7bf});throw _0x13b7bf;}}async['listSearchIndexes'](){try{const _0x335693=await this['searchClient']['call']('FT._LIST');return _0x335693;}catch(_0x2a946d){this['logger']['info']('Error\x20listing\x20search\x20indexes',{'error':_0x2a946d});throw _0x2a946d;}}async['setFields'](_0x2ab6be,_0x401373){try{const _0x22ce54=await this['searchClient']['hset'](_0x2ab6be,_0x401373);return Number(_0x22ce54);}catch(_0x179ad7){this['logger']['error']('Error\x20setting\x20fields\x20for\x20key:\x20'+_0x2ab6be,{'error':_0x179ad7});throw _0x179ad7;}}async['getField'](_0x14f333,_0x367a8f){try{return await this['searchClient']['hget'](_0x14f333,_0x367a8f);}catch(_0xcb004a){this['logger']['error']('Error\x20getting\x20field\x20'+_0x367a8f+'\x20for\x20key:\x20'+_0x14f333,{'error':_0xcb004a});throw _0xcb004a;}}async['getFields'](_0x2dfd26,_0x52d5b4){try{return await this['searchClient']['hmget'](_0x2dfd26,[..._0x52d5b4]);}catch(_0x381c30){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x2dfd26,{'error':_0x381c30});throw _0x381c30;}}async['getAllFields'](_0x5cba52){try{return await this['searchClient']['hgetall'](_0x5cba52);}catch(_0x41e8f9){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x5cba52,{'error':_0x41e8f9});throw _0x41e8f9;}}async['deleteFields'](_0x385947,_0x371d13){try{const _0x23294f=await this['searchClient']['hdel'](_0x385947,..._0x371d13);return Number(_0x23294f);}catch(_0x1b7bfd){this['logger']['error']('Error\x20deleting\x20fields\x20for\x20key:\x20'+_0x385947,{'error':_0x1b7bfd});throw _0x1b7bfd;}}async['incrementFieldByFloat'](_0x471399,_0x23a927,_0x463bc9){try{const _0x24c1a9=await this['searchClient']['hincrbyfloat'](_0x471399,_0x23a927,_0x463bc9);return Number(_0x24c1a9);}catch(_0x161a55){this['logger']['error']('Error\x20incrementing\x20field\x20'+_0x23a927+'\x20for\x20key:\x20'+_0x471399,{'error':_0x161a55});throw _0x161a55;}}async['sendQuery'](..._0x2a1678){try{return await this['searchClient']['call'](..._0x2a1678);}catch(_0x12a860){this['logger']['error']('Error\x20executing\x20query',{'error':_0x12a860});throw _0x12a860;}}async['sendIndexedQuery'](_0xe736f1,_0x387c2c){try{if(_0x387c2c[0x0]?.['startsWith']('FT.')){const [_0x159f80,..._0x474ab0]=_0x387c2c;return await this['searchClient']['call'](_0x159f80,..._0x474ab0);}return await this['searchClient']['call']('FT.SEARCH',_0xe736f1,..._0x387c2c);}catch(_0x4a715a){this['logger']['error']('Error\x20executing\x20query',{'error':_0x4a715a});throw _0x4a715a;}}}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(_0x2f1d8b,_0x2d6f3f){const _0x5c7c93=_0x26e5,_0x47095c=_0x2f1d8b();while(!![]){try{const _0x1113bf=-parseInt(_0x5c7c93(0x9b))/0x1+parseInt(_0x5c7c93(0x9e))/0x2*(parseInt(_0x5c7c93(0x97))/0x3)+-parseInt(_0x5c7c93(0x9d))/0x4*(parseInt(_0x5c7c93(0x98))/0x5)+-parseInt(_0x5c7c93(0x9a))/0x6+-parseInt(_0x5c7c93(0x95))/0x7*(parseInt(_0x5c7c93(0x9c))/0x8)+parseInt(_0x5c7c93(0x99))/0x9+parseInt(_0x5c7c93(0x96))/0xa;if(_0x1113bf===_0x2d6f3f)break;else _0x47095c['push'](_0x47095c['shift']());}catch(_0x3a3aeb){_0x47095c['push'](_0x47095c['shift']());}}}(_0x5a10,0x96174));Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['RedisSearchService']=void 0x0;const index_1=require('../../index');class RedisSearchService extends index_1['SearchService']{constructor(_0xd92816,_0x43ffe2){super(_0xd92816,_0x43ffe2);}async['init'](_0x2bdbea,_0x23e070,_0x582273){this['namespace']=_0x2bdbea,this['appId']=_0x23e070,this['logger']=_0x582273;}async['createSearchIndex'](_0x174cfa,_0x48bacb,_0x4bcf55){try{await this['searchClient']['sendCommand'](['FT.CREATE',_0x174cfa,'ON','HASH','PREFIX',_0x48bacb['length']['toString'](),..._0x48bacb,'SCHEMA',..._0x4bcf55]);}catch(_0x28b256){this['logger']['info']('Error\x20creating\x20search\x20index',{'error':_0x28b256});throw _0x28b256;}}async['listSearchIndexes'](){try{const _0x2f6d17=await this['searchClient']['sendCommand'](['FT._LIST']);return _0x2f6d17;}catch(_0x3a41e7){this['logger']['info']('Error\x20listing\x20search\x20indexes',{'error':_0x3a41e7});throw _0x3a41e7;}}async['setFields'](_0x37bf96,_0x17bca7){try{const _0x1fbb36=await this['searchClient']['HSET'](_0x37bf96,_0x17bca7);return Number(_0x1fbb36);}catch(_0x5431c7){this['logger']['error']('Error\x20setting\x20fields\x20for\x20key:\x20'+_0x37bf96,{'error':_0x5431c7});throw _0x5431c7;}}async['getField'](_0x4305e5,_0x5eedba){try{return await this['searchClient']['HGET'](_0x4305e5,_0x5eedba);}catch(_0x3489c4){this['logger']['error']('Error\x20getting\x20field\x20'+_0x5eedba+'\x20for\x20key:\x20'+_0x4305e5,{'error':_0x3489c4});throw _0x3489c4;}}async['getFields'](_0x24a8ec,_0x3812ec){try{return await this['searchClient']['HMGET'](_0x24a8ec,[..._0x3812ec]);}catch(_0x2d2b56){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x24a8ec,{'error':_0x2d2b56});throw _0x2d2b56;}}async['getAllFields'](_0x4d510d){try{return await this['searchClient']['HGETALL'](_0x4d510d);}catch(_0x2b0666){this['logger']['error']('Error\x20getting\x20fields\x20for\x20key:\x20'+_0x4d510d,{'error':_0x2b0666});throw _0x2b0666;}}async['deleteFields'](_0x4f7267,_0x9c9d93){try{const _0x76dd47=await this['searchClient']['HDEL'](_0x4f7267,_0x9c9d93);return Number(_0x76dd47);}catch(_0x3677c0){this['logger']['error']('Error\x20deleting\x20fields\x20for\x20key:\x20'+_0x4f7267,{'error':_0x3677c0});throw _0x3677c0;}}async['incrementFieldByFloat'](_0x168aac,_0x1134e5,_0x36a7c5){try{const _0x4d48ed=await this['searchClient']['HINCRBYFLOAT'](_0x168aac,_0x1134e5,_0x36a7c5);return Number(_0x4d48ed);}catch(_0x3a857f){this['logger']['error']('Error\x20incrementing\x20field\x20'+_0x1134e5+'\x20for\x20key:\x20'+_0x168aac,{'error':_0x3a857f});throw _0x3a857f;}}async['sendQuery'](..._0x2b6640){try{return await this['searchClient']['sendCommand'](_0x2b6640);}catch(_0x518ae8){this['logger']['error']('Error\x20executing\x20query',{'error':_0x518ae8});throw _0x518ae8;}}async['sendIndexedQuery'](_0x2ab5e4,_0x4a3ad1){try{if(_0x4a3ad1[0x0]?.['startsWith']('FT.'))return await this['searchClient']['sendCommand'](_0x4a3ad1);return await this['searchClient']['sendCommand'](['FT.SEARCH',_0x2ab5e4,..._0x4a3ad1]);}catch(_0x19ff6a){this['logger']['error']('Error\x20executing\x20query',{'error':_0x19ff6a});throw _0x19ff6a;}}}function _0x26e5(_0x13b726,_0x5bcc32){const _0x5a106d=_0x5a10();return _0x26e5=function(_0x26e5a3,_0x114b70){_0x26e5a3=_0x26e5a3-0x95;let _0x14d743=_0x5a106d[_0x26e5a3];return _0x14d743;},_0x26e5(_0x13b726,_0x5bcc32);}exports['RedisSearchService']=RedisSearchService;function _0x5a10(){const _0x389f01=['4094730eFGHuR','495082rjCIbT','6952224RXBMWU','76XLghbw','2TjoNMv','7wBBXQs','28747330gQZcLm','275511gwhqGk','154235oYeiSB','2527740VLohFK'];_0x5a10=function(){return _0x389f01;};return _0x5a10();}