index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.pushLatestArgument = exports.transformMRangeWithLabelsReply = exports.transformMRangeReply = exports.transformRangeReply = exports.pushMRangeWithLabelsArguments = exports.pushWithLabelsArgument = exports.pushMRangeArguments = exports.pushFilterArgument = exports.pushMRangeGroupByArguments = exports.pushRangeArguments = exports.TimeSeriesBucketTimestamp = exports.transformSampleReply = exports.transformIncrDecrArguments = exports.pushLabelsArgument = exports.transformLablesReply = exports.pushDuplicatePolicy = exports.pushChunkSizeArgument = exports.pushEncodingArgument = exports.TimeSeriesEncoding = exports.pushRetentionArgument = exports.transformTimestampArgument = exports.TimeSeriesReducers = exports.TimeSeriesDuplicatePolicies = exports.TimeSeriesAggregationType = void 0;
  4. const ADD = require("./ADD");
  5. const ALTER = require("./ALTER");
  6. const CREATE = require("./CREATE");
  7. const CREATERULE = require("./CREATERULE");
  8. const DECRBY = require("./DECRBY");
  9. const DEL = require("./DEL");
  10. const DELETERULE = require("./DELETERULE");
  11. const GET = require("./GET");
  12. const INCRBY = require("./INCRBY");
  13. const INFO_DEBUG = require("./INFO_DEBUG");
  14. const INFO = require("./INFO");
  15. const MADD = require("./MADD");
  16. const MGET = require("./MGET");
  17. const MGET_WITHLABELS = require("./MGET_WITHLABELS");
  18. const QUERYINDEX = require("./QUERYINDEX");
  19. const RANGE = require("./RANGE");
  20. const REVRANGE = require("./REVRANGE");
  21. const MRANGE = require("./MRANGE");
  22. const MRANGE_WITHLABELS = require("./MRANGE_WITHLABELS");
  23. const MREVRANGE = require("./MREVRANGE");
  24. const MREVRANGE_WITHLABELS = require("./MREVRANGE_WITHLABELS");
  25. const generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
  26. exports.default = {
  27. ADD,
  28. add: ADD,
  29. ALTER,
  30. alter: ALTER,
  31. CREATE,
  32. create: CREATE,
  33. CREATERULE,
  34. createRule: CREATERULE,
  35. DECRBY,
  36. decrBy: DECRBY,
  37. DEL,
  38. del: DEL,
  39. DELETERULE,
  40. deleteRule: DELETERULE,
  41. GET,
  42. get: GET,
  43. INCRBY,
  44. incrBy: INCRBY,
  45. INFO_DEBUG,
  46. infoDebug: INFO_DEBUG,
  47. INFO,
  48. info: INFO,
  49. MADD,
  50. mAdd: MADD,
  51. MGET,
  52. mGet: MGET,
  53. MGET_WITHLABELS,
  54. mGetWithLabels: MGET_WITHLABELS,
  55. QUERYINDEX,
  56. queryIndex: QUERYINDEX,
  57. RANGE,
  58. range: RANGE,
  59. REVRANGE,
  60. revRange: REVRANGE,
  61. MRANGE,
  62. mRange: MRANGE,
  63. MRANGE_WITHLABELS,
  64. mRangeWithLabels: MRANGE_WITHLABELS,
  65. MREVRANGE,
  66. mRevRange: MREVRANGE,
  67. MREVRANGE_WITHLABELS,
  68. mRevRangeWithLabels: MREVRANGE_WITHLABELS
  69. };
  70. var TimeSeriesAggregationType;
  71. (function (TimeSeriesAggregationType) {
  72. TimeSeriesAggregationType["AVG"] = "AVG";
  73. // @deprecated
  74. TimeSeriesAggregationType["AVERAGE"] = "AVG";
  75. TimeSeriesAggregationType["FIRST"] = "FIRST";
  76. TimeSeriesAggregationType["LAST"] = "LAST";
  77. TimeSeriesAggregationType["MIN"] = "MIN";
  78. // @deprecated
  79. TimeSeriesAggregationType["MINIMUM"] = "MIN";
  80. TimeSeriesAggregationType["MAX"] = "MAX";
  81. // @deprecated
  82. TimeSeriesAggregationType["MAXIMUM"] = "MAX";
  83. TimeSeriesAggregationType["SUM"] = "SUM";
  84. TimeSeriesAggregationType["RANGE"] = "RANGE";
  85. TimeSeriesAggregationType["COUNT"] = "COUNT";
  86. TimeSeriesAggregationType["STD_P"] = "STD.P";
  87. TimeSeriesAggregationType["STD_S"] = "STD.S";
  88. TimeSeriesAggregationType["VAR_P"] = "VAR.P";
  89. TimeSeriesAggregationType["VAR_S"] = "VAR.S";
  90. TimeSeriesAggregationType["TWA"] = "TWA";
  91. })(TimeSeriesAggregationType || (exports.TimeSeriesAggregationType = TimeSeriesAggregationType = {}));
  92. var TimeSeriesDuplicatePolicies;
  93. (function (TimeSeriesDuplicatePolicies) {
  94. TimeSeriesDuplicatePolicies["BLOCK"] = "BLOCK";
  95. TimeSeriesDuplicatePolicies["FIRST"] = "FIRST";
  96. TimeSeriesDuplicatePolicies["LAST"] = "LAST";
  97. TimeSeriesDuplicatePolicies["MIN"] = "MIN";
  98. TimeSeriesDuplicatePolicies["MAX"] = "MAX";
  99. TimeSeriesDuplicatePolicies["SUM"] = "SUM";
  100. })(TimeSeriesDuplicatePolicies || (exports.TimeSeriesDuplicatePolicies = TimeSeriesDuplicatePolicies = {}));
  101. var TimeSeriesReducers;
  102. (function (TimeSeriesReducers) {
  103. TimeSeriesReducers["AVG"] = "AVG";
  104. TimeSeriesReducers["SUM"] = "SUM";
  105. TimeSeriesReducers["MIN"] = "MIN";
  106. // @deprecated
  107. TimeSeriesReducers["MINIMUM"] = "MIN";
  108. TimeSeriesReducers["MAX"] = "MAX";
  109. // @deprecated
  110. TimeSeriesReducers["MAXIMUM"] = "MAX";
  111. TimeSeriesReducers["RANGE"] = "range";
  112. TimeSeriesReducers["COUNT"] = "COUNT";
  113. TimeSeriesReducers["STD_P"] = "STD.P";
  114. TimeSeriesReducers["STD_S"] = "STD.S";
  115. TimeSeriesReducers["VAR_P"] = "VAR.P";
  116. TimeSeriesReducers["VAR_S"] = "VAR.S";
  117. })(TimeSeriesReducers || (exports.TimeSeriesReducers = TimeSeriesReducers = {}));
  118. function transformTimestampArgument(timestamp) {
  119. if (typeof timestamp === 'string')
  120. return timestamp;
  121. return (typeof timestamp === 'number' ?
  122. timestamp :
  123. timestamp.getTime()).toString();
  124. }
  125. exports.transformTimestampArgument = transformTimestampArgument;
  126. function pushRetentionArgument(args, retention) {
  127. if (retention !== undefined) {
  128. args.push('RETENTION', retention.toString());
  129. }
  130. return args;
  131. }
  132. exports.pushRetentionArgument = pushRetentionArgument;
  133. var TimeSeriesEncoding;
  134. (function (TimeSeriesEncoding) {
  135. TimeSeriesEncoding["COMPRESSED"] = "COMPRESSED";
  136. TimeSeriesEncoding["UNCOMPRESSED"] = "UNCOMPRESSED";
  137. })(TimeSeriesEncoding || (exports.TimeSeriesEncoding = TimeSeriesEncoding = {}));
  138. function pushEncodingArgument(args, encoding) {
  139. if (encoding !== undefined) {
  140. args.push('ENCODING', encoding);
  141. }
  142. return args;
  143. }
  144. exports.pushEncodingArgument = pushEncodingArgument;
  145. function pushChunkSizeArgument(args, chunkSize) {
  146. if (chunkSize !== undefined) {
  147. args.push('CHUNK_SIZE', chunkSize.toString());
  148. }
  149. return args;
  150. }
  151. exports.pushChunkSizeArgument = pushChunkSizeArgument;
  152. function pushDuplicatePolicy(args, duplicatePolicy) {
  153. if (duplicatePolicy !== undefined) {
  154. args.push('DUPLICATE_POLICY', duplicatePolicy);
  155. }
  156. return args;
  157. }
  158. exports.pushDuplicatePolicy = pushDuplicatePolicy;
  159. function transformLablesReply(reply) {
  160. const labels = {};
  161. for (const [key, value] of reply) {
  162. labels[key] = value;
  163. }
  164. return labels;
  165. }
  166. exports.transformLablesReply = transformLablesReply;
  167. function pushLabelsArgument(args, labels) {
  168. if (labels) {
  169. args.push('LABELS');
  170. for (const [label, value] of Object.entries(labels)) {
  171. args.push(label, value);
  172. }
  173. }
  174. return args;
  175. }
  176. exports.pushLabelsArgument = pushLabelsArgument;
  177. function transformIncrDecrArguments(command, key, value, options) {
  178. const args = [
  179. command,
  180. key,
  181. value.toString()
  182. ];
  183. if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) {
  184. args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP));
  185. }
  186. pushRetentionArgument(args, options?.RETENTION);
  187. if (options?.UNCOMPRESSED) {
  188. args.push('UNCOMPRESSED');
  189. }
  190. pushChunkSizeArgument(args, options?.CHUNK_SIZE);
  191. pushLabelsArgument(args, options?.LABELS);
  192. return args;
  193. }
  194. exports.transformIncrDecrArguments = transformIncrDecrArguments;
  195. function transformSampleReply(reply) {
  196. return {
  197. timestamp: reply[0],
  198. value: Number(reply[1])
  199. };
  200. }
  201. exports.transformSampleReply = transformSampleReply;
  202. var TimeSeriesBucketTimestamp;
  203. (function (TimeSeriesBucketTimestamp) {
  204. TimeSeriesBucketTimestamp["LOW"] = "-";
  205. TimeSeriesBucketTimestamp["HIGH"] = "+";
  206. TimeSeriesBucketTimestamp["MID"] = "~";
  207. })(TimeSeriesBucketTimestamp || (exports.TimeSeriesBucketTimestamp = TimeSeriesBucketTimestamp = {}));
  208. function pushRangeArguments(args, fromTimestamp, toTimestamp, options) {
  209. args.push(transformTimestampArgument(fromTimestamp), transformTimestampArgument(toTimestamp));
  210. pushLatestArgument(args, options?.LATEST);
  211. if (options?.FILTER_BY_TS) {
  212. args.push('FILTER_BY_TS');
  213. for (const ts of options.FILTER_BY_TS) {
  214. args.push(transformTimestampArgument(ts));
  215. }
  216. }
  217. if (options?.FILTER_BY_VALUE) {
  218. args.push('FILTER_BY_VALUE', options.FILTER_BY_VALUE.min.toString(), options.FILTER_BY_VALUE.max.toString());
  219. }
  220. if (options?.COUNT) {
  221. args.push('COUNT', options.COUNT.toString());
  222. }
  223. if (options?.ALIGN) {
  224. args.push('ALIGN', transformTimestampArgument(options.ALIGN));
  225. }
  226. if (options?.AGGREGATION) {
  227. args.push('AGGREGATION', options.AGGREGATION.type, transformTimestampArgument(options.AGGREGATION.timeBucket));
  228. if (options.AGGREGATION.BUCKETTIMESTAMP) {
  229. args.push('BUCKETTIMESTAMP', options.AGGREGATION.BUCKETTIMESTAMP);
  230. }
  231. if (options.AGGREGATION.EMPTY) {
  232. args.push('EMPTY');
  233. }
  234. }
  235. return args;
  236. }
  237. exports.pushRangeArguments = pushRangeArguments;
  238. function pushMRangeGroupByArguments(args, groupBy) {
  239. if (groupBy) {
  240. args.push('GROUPBY', groupBy.label, 'REDUCE', groupBy.reducer);
  241. }
  242. return args;
  243. }
  244. exports.pushMRangeGroupByArguments = pushMRangeGroupByArguments;
  245. function pushFilterArgument(args, filter) {
  246. args.push('FILTER');
  247. return (0, generic_transformers_1.pushVerdictArguments)(args, filter);
  248. }
  249. exports.pushFilterArgument = pushFilterArgument;
  250. function pushMRangeArguments(args, fromTimestamp, toTimestamp, filter, options) {
  251. args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
  252. args = pushFilterArgument(args, filter);
  253. return pushMRangeGroupByArguments(args, options?.GROUPBY);
  254. }
  255. exports.pushMRangeArguments = pushMRangeArguments;
  256. function pushWithLabelsArgument(args, selectedLabels) {
  257. if (!selectedLabels) {
  258. args.push('WITHLABELS');
  259. }
  260. else {
  261. args.push('SELECTED_LABELS');
  262. args = (0, generic_transformers_1.pushVerdictArguments)(args, selectedLabels);
  263. }
  264. return args;
  265. }
  266. exports.pushWithLabelsArgument = pushWithLabelsArgument;
  267. function pushMRangeWithLabelsArguments(args, fromTimestamp, toTimestamp, filter, options) {
  268. args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
  269. args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
  270. args = pushFilterArgument(args, filter);
  271. return pushMRangeGroupByArguments(args, options?.GROUPBY);
  272. }
  273. exports.pushMRangeWithLabelsArguments = pushMRangeWithLabelsArguments;
  274. function transformRangeReply(reply) {
  275. return reply.map(transformSampleReply);
  276. }
  277. exports.transformRangeReply = transformRangeReply;
  278. function transformMRangeReply(reply) {
  279. const args = [];
  280. for (const [key, _, sample] of reply) {
  281. args.push({
  282. key,
  283. samples: sample.map(transformSampleReply)
  284. });
  285. }
  286. return args;
  287. }
  288. exports.transformMRangeReply = transformMRangeReply;
  289. function transformMRangeWithLabelsReply(reply) {
  290. const args = [];
  291. for (const [key, labels, samples] of reply) {
  292. args.push({
  293. key,
  294. labels: transformLablesReply(labels),
  295. samples: samples.map(transformSampleReply)
  296. });
  297. }
  298. return args;
  299. }
  300. exports.transformMRangeWithLabelsReply = transformMRangeWithLabelsReply;
  301. function pushLatestArgument(args, latest) {
  302. if (latest) {
  303. args.push('LATEST');
  304. }
  305. return args;
  306. }
  307. exports.pushLatestArgument = pushLatestArgument;