@tradejs/infra 2.0.8 → 2.0.9

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.
@@ -319,6 +319,28 @@ var setHashJsonField = async (key, field, data, options = {}) => {
319
319
  logger.log("error", "failed HSET %s[%s]: %s", key, field, String(e));
320
320
  }
321
321
  };
322
+ var setHashJsonFields = async (key, entries, options = {}) => {
323
+ if (redisUnavailable || entries.length === 0) return;
324
+ const { expire } = { ...DEFAULT_OPTIONS, ...options };
325
+ const redis = await getReadyRedis();
326
+ if (!redis) return;
327
+ try {
328
+ const chunkSize = 500;
329
+ for (let offset = 0; offset < entries.length; offset += chunkSize) {
330
+ const args = entries.slice(offset, offset + chunkSize).flatMap(({ field, data }) => [field, toJson(data)]);
331
+ await redis.call("HSET", key, ...args);
332
+ }
333
+ if (expire) {
334
+ await redis.expire(key, expire);
335
+ }
336
+ } catch (e) {
337
+ if (e instanceof Error && isRedisConnectivityError(e)) {
338
+ markRedisUnavailable(e);
339
+ return;
340
+ }
341
+ logger.log("error", "failed batched HSET %s: %s", key, String(e));
342
+ }
343
+ };
322
344
  var getHashJsonField = async (key, field, fallback = null) => {
323
345
  if (redisUnavailable) return fallback;
324
346
  const redis = await getReadyRedis();
@@ -518,6 +540,7 @@ export {
518
540
  delKeyWithOptions,
519
541
  setData,
520
542
  setHashJsonField,
543
+ setHashJsonFields,
521
544
  getHashJsonField,
522
545
  getHashJsonValues,
523
546
  incrHashFields,
package/dist/redis.d.mts CHANGED
@@ -20,6 +20,10 @@ declare class RedisWriteBlockedError extends Error {
20
20
  declare const delKeyWithOptions: (key: string, options?: DelKeyOptions) => Promise<boolean>;
21
21
  declare const setData: <T>(key: string, data: T, options?: Options) => Promise<void>;
22
22
  declare const setHashJsonField: <T>(key: string, field: string, data: T, options?: Options) => Promise<void>;
23
+ declare const setHashJsonFields: <T>(key: string, entries: ReadonlyArray<{
24
+ field: string;
25
+ data: T;
26
+ }>, options?: Options) => Promise<void>;
23
27
  declare const getHashJsonField: <T>(key: string, field: string, fallback?: T | null) => Promise<T | null>;
24
28
  declare const getHashJsonValues: <T>(key: string) => Promise<T[]>;
25
29
  declare const incrHashFields: (key: string, increments: Record<string, number>, options?: Options) => Promise<void>;
@@ -94,4 +98,4 @@ declare const redisKeys: {
94
98
  mlResult: (strategyName: string, signalId: string) => string;
95
99
  };
96
100
 
97
- export { RedisWriteBlockedError, closeRedisConnection, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getHashData, getHashJsonField, getHashJsonValues, getKeys, incrHashFields, publishData, redisKeys, setData, setHashJsonField };
101
+ export { RedisWriteBlockedError, closeRedisConnection, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getHashData, getHashJsonField, getHashJsonValues, getKeys, incrHashFields, publishData, redisKeys, setData, setHashJsonField, setHashJsonFields };
package/dist/redis.d.ts CHANGED
@@ -20,6 +20,10 @@ declare class RedisWriteBlockedError extends Error {
20
20
  declare const delKeyWithOptions: (key: string, options?: DelKeyOptions) => Promise<boolean>;
21
21
  declare const setData: <T>(key: string, data: T, options?: Options) => Promise<void>;
22
22
  declare const setHashJsonField: <T>(key: string, field: string, data: T, options?: Options) => Promise<void>;
23
+ declare const setHashJsonFields: <T>(key: string, entries: ReadonlyArray<{
24
+ field: string;
25
+ data: T;
26
+ }>, options?: Options) => Promise<void>;
23
27
  declare const getHashJsonField: <T>(key: string, field: string, fallback?: T | null) => Promise<T | null>;
24
28
  declare const getHashJsonValues: <T>(key: string) => Promise<T[]>;
25
29
  declare const incrHashFields: (key: string, increments: Record<string, number>, options?: Options) => Promise<void>;
@@ -94,4 +98,4 @@ declare const redisKeys: {
94
98
  mlResult: (strategyName: string, signalId: string) => string;
95
99
  };
96
100
 
97
- export { RedisWriteBlockedError, closeRedisConnection, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getHashData, getHashJsonField, getHashJsonValues, getKeys, incrHashFields, publishData, redisKeys, setData, setHashJsonField };
101
+ export { RedisWriteBlockedError, closeRedisConnection, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getHashData, getHashJsonField, getHashJsonValues, getKeys, incrHashFields, publishData, redisKeys, setData, setHashJsonField, setHashJsonFields };
package/dist/redis.js CHANGED
@@ -45,7 +45,8 @@ __export(redis_exports, {
45
45
  publishData: () => publishData,
46
46
  redisKeys: () => redisKeys,
47
47
  setData: () => setData,
48
- setHashJsonField: () => setHashJsonField
48
+ setHashJsonField: () => setHashJsonField,
49
+ setHashJsonFields: () => setHashJsonFields
49
50
  });
50
51
  module.exports = __toCommonJS(redis_exports);
51
52
  var import_crypto = require("crypto");
@@ -368,6 +369,28 @@ var setHashJsonField = async (key, field, data, options = {}) => {
368
369
  logger.log("error", "failed HSET %s[%s]: %s", key, field, String(e));
369
370
  }
370
371
  };
372
+ var setHashJsonFields = async (key, entries, options = {}) => {
373
+ if (redisUnavailable || entries.length === 0) return;
374
+ const { expire } = { ...DEFAULT_OPTIONS, ...options };
375
+ const redis = await getReadyRedis();
376
+ if (!redis) return;
377
+ try {
378
+ const chunkSize = 500;
379
+ for (let offset = 0; offset < entries.length; offset += chunkSize) {
380
+ const args = entries.slice(offset, offset + chunkSize).flatMap(({ field, data }) => [field, toJson(data)]);
381
+ await redis.call("HSET", key, ...args);
382
+ }
383
+ if (expire) {
384
+ await redis.expire(key, expire);
385
+ }
386
+ } catch (e) {
387
+ if (e instanceof Error && isRedisConnectivityError(e)) {
388
+ markRedisUnavailable(e);
389
+ return;
390
+ }
391
+ logger.log("error", "failed batched HSET %s: %s", key, String(e));
392
+ }
393
+ };
371
394
  var getHashJsonField = async (key, field, fallback = null) => {
372
395
  if (redisUnavailable) return fallback;
373
396
  const redis = await getReadyRedis();
@@ -573,5 +596,6 @@ var redisKeys = {
573
596
  publishData,
574
597
  redisKeys,
575
598
  setData,
576
- setHashJsonField
599
+ setHashJsonField,
600
+ setHashJsonFields
577
601
  });
package/dist/redis.mjs CHANGED
@@ -14,8 +14,9 @@ import {
14
14
  publishData,
15
15
  redisKeys,
16
16
  setData,
17
- setHashJsonField
18
- } from "./chunk-AVUYMV3N.mjs";
17
+ setHashJsonField,
18
+ setHashJsonFields
19
+ } from "./chunk-EFCQ7NGN.mjs";
19
20
  export {
20
21
  RedisWriteBlockedError,
21
22
  closeRedisConnection,
@@ -32,5 +33,6 @@ export {
32
33
  publishData,
33
34
  redisKeys,
34
35
  setData,
35
- setHashJsonField
36
+ setHashJsonField,
37
+ setHashJsonFields
36
38
  };
@@ -4,7 +4,7 @@ import {
4
4
  getKeys,
5
5
  redisKeys,
6
6
  setData
7
- } from "./chunk-AVUYMV3N.mjs";
7
+ } from "./chunk-EFCQ7NGN.mjs";
8
8
 
9
9
  // src/tradingAccounts.ts
10
10
  var normalizeId = (value, label) => {
@@ -2,7 +2,7 @@ import {
2
2
  getData,
3
3
  redisKeys,
4
4
  setData
5
- } from "./chunk-AVUYMV3N.mjs";
5
+ } from "./chunk-EFCQ7NGN.mjs";
6
6
  import {
7
7
  DEFAULT_AI_RESPONSE_LANGUAGE,
8
8
  normalizeAiResponseLanguage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/infra",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "MIT-licensed server infrastructure adapters for TradeJS: Redis, Timescale, ML, logging, and IO.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -93,7 +93,7 @@
93
93
  "dependencies": {
94
94
  "@grpc/grpc-js": "^1.14.4",
95
95
  "@grpc/proto-loader": "^0.8.1",
96
- "@tradejs/types": "^2.0.8",
96
+ "@tradejs/types": "^2.0.9",
97
97
  "chalk": "4.1.2",
98
98
  "ioredis": "5.11.1",
99
99
  "pg": "8.22.0",