@redis/time-series 1.0.3 → 1.0.5

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.
package/README.md CHANGED
@@ -4,4 +4,148 @@ This package provides support for the [RedisTimeSeries](https://redistimeseries.
4
4
 
5
5
  To use these extra commands, your Redis server must have the RedisTimeSeries module installed.
6
6
 
7
- For an example of how to add values to a time series, query a time series, and perform aggregated queries against a time series, see `time-series.js` in the Node Redis examples folder.
7
+ ## Usage
8
+
9
+ For a complete example, see [`time-series.js`](https://github.com/redis/node-redis/blob/master/examples/time-series.js) in the Node Redis examples folder.
10
+
11
+ ### Creating Time Series data structure in Redis
12
+
13
+ The [`TS.CREATE`](https://oss.redis.com/redistimeseries/commands/#tscreate) command creates a new time series.
14
+
15
+ Here, we'll create a new time series "`temperature`":
16
+
17
+ ```javascript
18
+
19
+ import { createClient } from 'redis';
20
+ import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding, TimeSeriesAggregationType } from '@redis/time-series';
21
+
22
+ ...
23
+
24
+ const created = await client.ts.create('temperature', {
25
+ RETENTION: 86400000, // 1 day in milliseconds
26
+ ENCODING: TimeSeriesEncoding.UNCOMPRESSED, // No compression - When not specified, the option is set to COMPRESSED
27
+ DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK, // No duplicates - When not specified: set to the global DUPLICATE_POLICY configuration of the database (which by default, is BLOCK).
28
+ });
29
+
30
+ if (created === 'OK') {
31
+ console.log('Created timeseries.');
32
+ } else {
33
+ console.log('Error creating timeseries :(');
34
+ process.exit(1);
35
+ }
36
+
37
+ ```
38
+
39
+ ### Adding new value to a Time Series data structure in Redis
40
+
41
+ With RedisTimeSeries, we can add a single value to time series data structure using the [`TS.ADD`](https://redis.io/commands/ts.add/) command and if we would like to add multiple values we can use the [`TS.MADD`](https://redis.io/commands/ts.madd/) command.
42
+
43
+ ```javascript
44
+
45
+ let value = Math.floor(Math.random() * 1000) + 1; // Random data point value
46
+ let currentTimestamp = 1640995200000; // Jan 1 2022 00:00:00
47
+ let num = 0;
48
+
49
+ while (num < 10000) {
50
+ // Add a new value to the timeseries, providing our own timestamp:
51
+ // https://redis.io/commands/ts.add/
52
+ await client.ts.add('temperature', currentTimestamp, value);
53
+ console.log(`Added timestamp ${currentTimestamp}, value ${value}.`);
54
+
55
+ num += 1;
56
+ value = Math.floor(Math.random() * 1000) + 1; // Get another random value
57
+ currentTimestamp += 1000; // Move on one second.
58
+ }
59
+
60
+ // Add multiple values to the timeseries in round trip to the server:
61
+ // https://redis.io/commands/ts.madd/
62
+ const response = await client.ts.mAdd([{
63
+ key: 'temperature',
64
+ timestamp: currentTimestamp + 60000,
65
+ value: Math.floor(Math.random() * 1000) + 1
66
+ }, {
67
+ key: 'temperature',
68
+ timestamp: currentTimestamp + 120000,
69
+ value: Math.floor(Math.random() * 1000) + 1
70
+ }]);
71
+
72
+
73
+ ```
74
+
75
+ ### Retrieving Time Series data from Redis
76
+
77
+ With RedisTimeSeries, we can retrieve the time series data using the [`TS.RANGE`](https://redis.io/commands/ts.range/) command by passing the criteria as follows:
78
+
79
+ ```javascript
80
+
81
+ // Query the timeseries with TS.RANGE:
82
+ // https://redis.io/commands/ts.range/
83
+ const fromTimestamp = 1640995200000; // Jan 1 2022 00:00:00
84
+ const toTimestamp = 1640995260000; // Jan 1 2022 00:01:00
85
+ const rangeResponse = await client.ts.range('temperature', fromTimestamp, toTimestamp, {
86
+ // Group into 10 second averages.
87
+ AGGREGATION: {
88
+ type: TimeSeriesAggregationType.AVERAGE,
89
+ timeBucket: 10000
90
+ }
91
+ });
92
+
93
+ console.log('RANGE RESPONSE:');
94
+ // rangeResponse looks like:
95
+ // [
96
+ // { timestamp: 1640995200000, value: 356.8 },
97
+ // { timestamp: 1640995210000, value: 534.8 },
98
+ // { timestamp: 1640995220000, value: 481.3 },
99
+ // { timestamp: 1640995230000, value: 437 },
100
+ // { timestamp: 1640995240000, value: 507.3 },
101
+ // { timestamp: 1640995250000, value: 581.2 },
102
+ // { timestamp: 1640995260000, value: 600 }
103
+ // ]
104
+
105
+ ```
106
+
107
+ ### Altering Time Series data Stored in Redis
108
+
109
+ RedisTimeSeries includes commands that can update values in a time series data structure.
110
+
111
+ Using the [`TS.ALTER`](https://redis.io/commands/ts.alter/) command, we can update time series retention like this:
112
+
113
+ ```javascript
114
+
115
+ // https://redis.io/commands/ts.alter/
116
+ const alterResponse = await client.ts.alter('temperature', {
117
+ RETENTION: 0 // Keep the entries forever
118
+ });
119
+
120
+ ```
121
+
122
+ ### Retrieving Information about the timeseries Stored in Redis
123
+
124
+ RedisTimeSeries also includes commands that can help to view the information on the state of a time series.
125
+
126
+ Using the [`TS.INFO`](https://redis.io/commands/ts.info/) command, we can view timeseries information like this:
127
+
128
+ ```javascript
129
+
130
+ // Get some information about the state of the timeseries.
131
+ // https://redis.io/commands/ts.info/
132
+ const tsInfo = await client.ts.info('temperature');
133
+
134
+ // tsInfo looks like this:
135
+ // {
136
+ // totalSamples: 1440,
137
+ // memoryUsage: 28904,
138
+ // firstTimestamp: 1641508920000,
139
+ // lastTimestamp: 1641595320000,
140
+ // retentionTime: 86400000,
141
+ // chunkCount: 7,
142
+ // chunkSize: 4096,
143
+ // chunkType: 'uncompressed',
144
+ // duplicatePolicy: 'block',
145
+ // labels: [],
146
+ // sourceKey: null,
147
+ // rules: []
148
+ // }
149
+
150
+ ```
151
+
@@ -1,7 +1,9 @@
1
- import { Labels } from '.';
1
+ import { Labels, TimeSeriesDuplicatePolicies } from '.';
2
2
  export declare const FIRST_KEY_INDEX = 1;
3
3
  interface AlterOptions {
4
4
  RETENTION?: number;
5
+ CHUNK_SIZE?: number;
6
+ DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
5
7
  LABELS?: Labels;
6
8
  }
7
9
  export declare function transformArguments(key: string, options?: AlterOptions): Array<string>;
@@ -6,6 +6,8 @@ exports.FIRST_KEY_INDEX = 1;
6
6
  function transformArguments(key, options) {
7
7
  const args = ['TS.ALTER', key];
8
8
  (0, _1.pushRetentionArgument)(args, options?.RETENTION);
9
+ (0, _1.pushChunkSizeArgument)(args, options?.CHUNK_SIZE);
10
+ (0, _1.pushDuplicatePolicy)(args, options?.DUPLICATE_POLICY);
9
11
  (0, _1.pushLabelsArgument)(args, options?.LABELS);
10
12
  return args;
11
13
  }
@@ -8,9 +8,7 @@ function transformArguments(key, options) {
8
8
  (0, _1.pushRetentionArgument)(args, options?.RETENTION);
9
9
  (0, _1.pushEncodingArgument)(args, options?.ENCODING);
10
10
  (0, _1.pushChunkSizeArgument)(args, options?.CHUNK_SIZE);
11
- if (options?.DUPLICATE_POLICY) {
12
- args.push('DUPLICATE_POLICY', options.DUPLICATE_POLICY);
13
- }
11
+ (0, _1.pushDuplicatePolicy)(args, options?.DUPLICATE_POLICY);
14
12
  (0, _1.pushLabelsArgument)(args, options?.LABELS);
15
13
  return args;
16
14
  }
@@ -1,4 +1,4 @@
1
1
  import { TimeSeriesAggregationType } from '.';
2
2
  export declare const FIRST_KEY_INDEX = 1;
3
- export declare function transformArguments(sourceKey: string, destinationKey: string, aggregationType: TimeSeriesAggregationType, timeBucket: number): Array<string>;
3
+ export declare function transformArguments(sourceKey: string, destinationKey: string, aggregationType: TimeSeriesAggregationType, bucketDuration: number, alignTimestamp?: number): Array<string>;
4
4
  export declare function transformReply(): 'OK';
@@ -2,14 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
4
4
  exports.FIRST_KEY_INDEX = 1;
5
- function transformArguments(sourceKey, destinationKey, aggregationType, timeBucket) {
6
- return [
5
+ function transformArguments(sourceKey, destinationKey, aggregationType, bucketDuration, alignTimestamp) {
6
+ const args = [
7
7
  'TS.CREATERULE',
8
8
  sourceKey,
9
9
  destinationKey,
10
10
  'AGGREGATION',
11
11
  aggregationType,
12
- timeBucket.toString()
12
+ bucketDuration.toString()
13
13
  ];
14
+ if (alignTimestamp) {
15
+ args.push(alignTimestamp.toString());
16
+ }
17
+ return args;
14
18
  }
15
19
  exports.transformArguments = transformArguments;
@@ -6,7 +6,7 @@ function transformArguments(sourceKey, destinationKey) {
6
6
  return [
7
7
  'TS.DELETERULE',
8
8
  sourceKey,
9
- destinationKey,
9
+ destinationKey
10
10
  ];
11
11
  }
12
12
  exports.transformArguments = transformArguments;
@@ -1,5 +1,10 @@
1
+ import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
1
2
  import { SampleRawReply, SampleReply } from '.';
2
3
  export declare const FIRST_KEY_INDEX = 1;
3
4
  export declare const IS_READ_ONLY = true;
4
- export declare function transformArguments(key: string): Array<string>;
5
+ interface GetOptions {
6
+ LATEST?: boolean;
7
+ }
8
+ export declare function transformArguments(key: string, options?: GetOptions): RedisCommandArguments;
5
9
  export declare function transformReply(reply: [] | SampleRawReply): null | SampleReply;
10
+ export {};
@@ -4,8 +4,8 @@ exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exp
4
4
  const _1 = require(".");
5
5
  exports.FIRST_KEY_INDEX = 1;
6
6
  exports.IS_READ_ONLY = true;
7
- function transformArguments(key) {
8
- return ['TS.GET', key];
7
+ function transformArguments(key, options) {
8
+ return (0, _1.pushLatestArgument)(['TS.GET', key], options?.LATEST);
9
9
  }
10
10
  exports.transformArguments = transformArguments;
11
11
  function transformReply(reply) {
@@ -2,31 +2,31 @@ import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
2
2
  export declare const FIRST_KEY_INDEX = 1;
3
3
  export declare const IS_READ_ONLY = true;
4
4
  export declare function transformArguments(key: string): Array<string>;
5
- export declare type InfoRawReply = [
6
- _: string,
7
- totalSamples: number,
8
- _: string,
9
- memoryUsage: number,
10
- _: string,
11
- firstTimestamp: number,
12
- _: string,
13
- lastTimestamp: number,
14
- _: string,
15
- retentionTime: number,
16
- _: string,
17
- chunkCount: number,
18
- _: string,
19
- chunkSize: number,
20
- _: string,
21
- chunkType: string,
22
- _: string,
23
- duplicatePolicy: TimeSeriesDuplicatePolicies | null,
24
- _: string,
25
- labels: Array<[name: string, value: string]>,
26
- _: string,
27
- sourceKey: string | null,
28
- _: string,
29
- rules: Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
5
+ export type InfoRawReply = [
6
+ 'totalSamples',
7
+ number,
8
+ 'memoryUsage',
9
+ number,
10
+ 'firstTimestamp',
11
+ number,
12
+ 'lastTimestamp',
13
+ number,
14
+ 'retentionTime',
15
+ number,
16
+ 'chunkCount',
17
+ number,
18
+ 'chunkSize',
19
+ number,
20
+ 'chunkType',
21
+ string,
22
+ 'duplicatePolicy',
23
+ TimeSeriesDuplicatePolicies | null,
24
+ 'labels',
25
+ Array<[name: string, value: string]>,
26
+ 'sourceKey',
27
+ string | null,
28
+ 'rules',
29
+ Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
30
30
  ];
31
31
  export interface InfoReply {
32
32
  totalSamples: number;
@@ -1,22 +1,22 @@
1
1
  import { InfoRawReply, InfoReply } from './INFO';
2
2
  export { IS_READ_ONLY, FIRST_KEY_INDEX } from './INFO';
3
3
  export declare function transformArguments(key: string): Array<string>;
4
- declare type InfoDebugRawReply = [
5
- ...infoArgs: InfoRawReply,
6
- _: string,
7
- keySelfName: string,
8
- _: string,
9
- chunks: Array<[
10
- _: string,
11
- startTimestamp: number,
12
- _: string,
13
- endTimestamp: number,
14
- _: string,
15
- samples: number,
16
- _: string,
17
- size: number,
18
- _: string,
19
- bytesPerSample: string
4
+ type InfoDebugRawReply = [
5
+ ...InfoRawReply,
6
+ 'keySelfName',
7
+ string,
8
+ 'chunks',
9
+ Array<[
10
+ 'startTimestamp',
11
+ number,
12
+ 'endTimestamp',
13
+ number,
14
+ 'samples',
15
+ number,
16
+ 'size',
17
+ number,
18
+ 'bytesPerSample',
19
+ string
20
20
  ]>
21
21
  ];
22
22
  interface InfoDebugReply extends InfoReply {
@@ -1,8 +1,11 @@
1
1
  import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
2
2
  import { Filter, RawLabels, SampleRawReply, SampleReply } from '.';
3
3
  export declare const IS_READ_ONLY = true;
4
- export declare function transformArguments(filter: Filter): RedisCommandArguments;
5
- export declare type MGetRawReply = Array<[
4
+ export interface MGetOptions {
5
+ LATEST?: boolean;
6
+ }
7
+ export declare function transformArguments(filter: Filter, options?: MGetOptions): RedisCommandArguments;
8
+ export type MGetRawReply = Array<[
6
9
  key: string,
7
10
  labels: RawLabels,
8
11
  sample: SampleRawReply
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = void 0;
4
4
  const _1 = require(".");
5
5
  exports.IS_READ_ONLY = true;
6
- function transformArguments(filter) {
7
- return (0, _1.pushFilterArgument)(['TS.MGET'], filter);
6
+ function transformArguments(filter, options) {
7
+ const args = (0, _1.pushLatestArgument)(['TS.MGET'], options?.LATEST);
8
+ return (0, _1.pushFilterArgument)(args, filter);
8
9
  }
9
10
  exports.transformArguments = transformArguments;
10
11
  function transformReply(reply) {
@@ -1,10 +1,11 @@
1
1
  import { SelectedLabels, Labels, Filter } from '.';
2
- import { MGetRawReply, MGetReply } from './MGET';
2
+ import { MGetOptions, MGetRawReply, MGetReply } from './MGET';
3
+ import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
3
4
  export declare const IS_READ_ONLY = true;
4
- interface MGetWithLabelsOptions {
5
+ interface MGetWithLabelsOptions extends MGetOptions {
5
6
  SELECTED_LABELS?: SelectedLabels;
6
7
  }
7
- export declare function transformArguments(filter: Filter, options?: MGetWithLabelsOptions): Array<string>;
8
+ export declare function transformArguments(filter: Filter, options?: MGetWithLabelsOptions): RedisCommandArguments;
8
9
  export interface MGetWithLabelsReply extends MGetReply {
9
10
  labels: Labels;
10
11
  }
@@ -4,10 +4,8 @@ exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = voi
4
4
  const _1 = require(".");
5
5
  exports.IS_READ_ONLY = true;
6
6
  function transformArguments(filter, options) {
7
- const args = ['TS.MGET'];
8
- (0, _1.pushWithLabelsArgument)(args, options?.SELECTED_LABELS);
9
- (0, _1.pushFilterArgument)(args, filter);
10
- return args;
7
+ const args = (0, _1.pushWithLabelsArgument)(['TS.MGET'], options?.SELECTED_LABELS);
8
+ return (0, _1.pushFilterArgument)(args, filter);
11
9
  }
12
10
  exports.transformArguments = transformArguments;
13
11
  ;
@@ -66,18 +66,22 @@ declare const _default: {
66
66
  };
67
67
  export default _default;
68
68
  export declare enum TimeSeriesAggregationType {
69
- AVERAGE = "avg",
70
- SUM = "sum",
71
- MINIMUM = "min",
72
- MAXIMUM = "max",
73
- RANGE = "range",
74
- COUNT = "count",
75
- FIRST = "first",
76
- LAST = "last",
77
- STD_P = "std.p",
78
- STD_S = "std.s",
79
- VAR_P = "var.p",
80
- VAR_S = "var.s"
69
+ AVG = "AVG",
70
+ AVERAGE = "AVG",
71
+ FIRST = "FIRST",
72
+ LAST = "LAST",
73
+ MIN = "MIN",
74
+ MINIMUM = "MIN",
75
+ MAX = "MAX",
76
+ MAXIMUM = "MAX",
77
+ SUM = "SUM",
78
+ RANGE = "RANGE",
79
+ COUNT = "COUNT",
80
+ STD_P = "STD.P",
81
+ STD_S = "STD.S",
82
+ VAR_P = "VAR.P",
83
+ VAR_S = "VAR.S",
84
+ TWA = "TWA"
81
85
  }
82
86
  export declare enum TimeSeriesDuplicatePolicies {
83
87
  BLOCK = "BLOCK",
@@ -88,11 +92,20 @@ export declare enum TimeSeriesDuplicatePolicies {
88
92
  SUM = "SUM"
89
93
  }
90
94
  export declare enum TimeSeriesReducers {
91
- SUM = "sum",
92
- MINIMUM = "min",
93
- MAXIMUM = "max"
95
+ AVG = "AVG",
96
+ SUM = "SUM",
97
+ MIN = "MIN",
98
+ MINIMUM = "MIN",
99
+ MAX = "MAX",
100
+ MAXIMUM = "MAX",
101
+ RANGE = "range",
102
+ COUNT = "COUNT",
103
+ STD_P = "STD.P",
104
+ STD_S = "STD.S",
105
+ VAR_P = "VAR.P",
106
+ VAR_S = "VAR.S"
94
107
  }
95
- export declare type Timestamp = number | Date | string;
108
+ export type Timestamp = number | Date | string;
96
109
  export declare function transformTimestampArgument(timestamp: Timestamp): string;
97
110
  export declare function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments;
98
111
  export declare enum TimeSeriesEncoding {
@@ -101,8 +114,9 @@ export declare enum TimeSeriesEncoding {
101
114
  }
102
115
  export declare function pushEncodingArgument(args: RedisCommandArguments, encoding?: TimeSeriesEncoding): RedisCommandArguments;
103
116
  export declare function pushChunkSizeArgument(args: RedisCommandArguments, chunkSize?: number): RedisCommandArguments;
104
- export declare type RawLabels = Array<[label: string, value: string]>;
105
- export declare type Labels = {
117
+ export declare function pushDuplicatePolicy(args: RedisCommandArguments, duplicatePolicy?: TimeSeriesDuplicatePolicies): RedisCommandArguments;
118
+ export type RawLabels = Array<[label: string, value: string]>;
119
+ export type Labels = {
106
120
  [label: string]: string;
107
121
  };
108
122
  export declare function transformLablesReply(reply: RawLabels): Labels;
@@ -115,13 +129,19 @@ export interface IncrDecrOptions {
115
129
  LABELS?: Labels;
116
130
  }
117
131
  export declare function transformIncrDecrArguments(command: 'TS.INCRBY' | 'TS.DECRBY', key: string, value: number, options?: IncrDecrOptions): RedisCommandArguments;
118
- export declare type SampleRawReply = [timestamp: number, value: string];
132
+ export type SampleRawReply = [timestamp: number, value: string];
119
133
  export interface SampleReply {
120
134
  timestamp: number;
121
135
  value: number;
122
136
  }
123
137
  export declare function transformSampleReply(reply: SampleRawReply): SampleReply;
138
+ export declare enum TimeSeriesBucketTimestamp {
139
+ LOW = "-",
140
+ HIGH = "+",
141
+ MID = "~"
142
+ }
124
143
  export interface RangeOptions {
144
+ LATEST?: boolean;
125
145
  FILTER_BY_TS?: Array<Timestamp>;
126
146
  FILTER_BY_VALUE?: {
127
147
  min: number;
@@ -132,6 +152,8 @@ export interface RangeOptions {
132
152
  AGGREGATION?: {
133
153
  type: TimeSeriesAggregationType;
134
154
  timeBucket: Timestamp;
155
+ BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp;
156
+ EMPTY?: boolean;
135
157
  };
136
158
  }
137
159
  export declare function pushRangeArguments(args: RedisCommandArguments, fromTimestamp: Timestamp, toTimestamp: Timestamp, options?: RangeOptions): RedisCommandArguments;
@@ -140,20 +162,20 @@ interface MRangeGroupBy {
140
162
  reducer: TimeSeriesReducers;
141
163
  }
142
164
  export declare function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments;
143
- export declare type Filter = string | Array<string>;
165
+ export type Filter = string | Array<string>;
144
166
  export declare function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments;
145
167
  export interface MRangeOptions extends RangeOptions {
146
168
  GROUPBY?: MRangeGroupBy;
147
169
  }
148
170
  export declare function pushMRangeArguments(args: RedisCommandArguments, fromTimestamp: Timestamp, toTimestamp: Timestamp, filter: Filter, options?: MRangeOptions): RedisCommandArguments;
149
- export declare type SelectedLabels = string | Array<string>;
171
+ export type SelectedLabels = string | Array<string>;
150
172
  export declare function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabels?: SelectedLabels): RedisCommandArguments;
151
173
  export interface MRangeWithLabelsOptions extends MRangeOptions {
152
174
  SELECTED_LABELS?: SelectedLabels;
153
175
  }
154
176
  export declare function pushMRangeWithLabelsArguments(args: RedisCommandArguments, fromTimestamp: Timestamp, toTimestamp: Timestamp, filter: Filter, options?: MRangeWithLabelsOptions): RedisCommandArguments;
155
177
  export declare function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply>;
156
- declare type MRangeRawReply = Array<[
178
+ type MRangeRawReply = Array<[
157
179
  key: string,
158
180
  labels: RawLabels,
159
181
  samples: Array<SampleRawReply>
@@ -167,3 +189,4 @@ export interface MRangeWithLabelsReplyItem extends MRangeReplyItem {
167
189
  labels: Labels;
168
190
  }
169
191
  export declare function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array<MRangeWithLabelsReplyItem>;
192
+ export declare function pushLatestArgument(args: RedisCommandArguments, latest?: boolean): RedisCommandArguments;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformMRangeWithLabelsReply = exports.transformMRangeReply = exports.transformRangeReply = exports.pushMRangeWithLabelsArguments = exports.pushWithLabelsArgument = exports.pushMRangeArguments = exports.pushFilterArgument = exports.pushMRangeGroupByArguments = exports.pushRangeArguments = exports.transformSampleReply = exports.transformIncrDecrArguments = exports.pushLabelsArgument = exports.transformLablesReply = exports.pushChunkSizeArgument = exports.pushEncodingArgument = exports.TimeSeriesEncoding = exports.pushRetentionArgument = exports.transformTimestampArgument = exports.TimeSeriesReducers = exports.TimeSeriesDuplicatePolicies = exports.TimeSeriesAggregationType = void 0;
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
4
  const ADD = require("./ADD");
5
5
  const ALTER = require("./ALTER");
6
6
  const CREATE = require("./CREATE");
@@ -69,19 +69,26 @@ exports.default = {
69
69
  };
70
70
  var TimeSeriesAggregationType;
71
71
  (function (TimeSeriesAggregationType) {
72
- TimeSeriesAggregationType["AVERAGE"] = "avg";
73
- TimeSeriesAggregationType["SUM"] = "sum";
74
- TimeSeriesAggregationType["MINIMUM"] = "min";
75
- TimeSeriesAggregationType["MAXIMUM"] = "max";
76
- TimeSeriesAggregationType["RANGE"] = "range";
77
- TimeSeriesAggregationType["COUNT"] = "count";
78
- TimeSeriesAggregationType["FIRST"] = "first";
79
- TimeSeriesAggregationType["LAST"] = "last";
80
- TimeSeriesAggregationType["STD_P"] = "std.p";
81
- TimeSeriesAggregationType["STD_S"] = "std.s";
82
- TimeSeriesAggregationType["VAR_P"] = "var.p";
83
- TimeSeriesAggregationType["VAR_S"] = "var.s";
84
- })(TimeSeriesAggregationType = exports.TimeSeriesAggregationType || (exports.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 = {}));
85
92
  var TimeSeriesDuplicatePolicies;
86
93
  (function (TimeSeriesDuplicatePolicies) {
87
94
  TimeSeriesDuplicatePolicies["BLOCK"] = "BLOCK";
@@ -90,13 +97,24 @@ var TimeSeriesDuplicatePolicies;
90
97
  TimeSeriesDuplicatePolicies["MIN"] = "MIN";
91
98
  TimeSeriesDuplicatePolicies["MAX"] = "MAX";
92
99
  TimeSeriesDuplicatePolicies["SUM"] = "SUM";
93
- })(TimeSeriesDuplicatePolicies = exports.TimeSeriesDuplicatePolicies || (exports.TimeSeriesDuplicatePolicies = {}));
100
+ })(TimeSeriesDuplicatePolicies || (exports.TimeSeriesDuplicatePolicies = TimeSeriesDuplicatePolicies = {}));
94
101
  var TimeSeriesReducers;
95
102
  (function (TimeSeriesReducers) {
96
- TimeSeriesReducers["SUM"] = "sum";
97
- TimeSeriesReducers["MINIMUM"] = "min";
98
- TimeSeriesReducers["MAXIMUM"] = "max";
99
- })(TimeSeriesReducers = exports.TimeSeriesReducers || (exports.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 = {}));
100
118
  function transformTimestampArgument(timestamp) {
101
119
  if (typeof timestamp === 'string')
102
120
  return timestamp;
@@ -106,7 +124,7 @@ function transformTimestampArgument(timestamp) {
106
124
  }
107
125
  exports.transformTimestampArgument = transformTimestampArgument;
108
126
  function pushRetentionArgument(args, retention) {
109
- if (retention) {
127
+ if (retention !== undefined) {
110
128
  args.push('RETENTION', retention.toString());
111
129
  }
112
130
  return args;
@@ -116,21 +134,28 @@ var TimeSeriesEncoding;
116
134
  (function (TimeSeriesEncoding) {
117
135
  TimeSeriesEncoding["COMPRESSED"] = "COMPRESSED";
118
136
  TimeSeriesEncoding["UNCOMPRESSED"] = "UNCOMPRESSED";
119
- })(TimeSeriesEncoding = exports.TimeSeriesEncoding || (exports.TimeSeriesEncoding = {}));
137
+ })(TimeSeriesEncoding || (exports.TimeSeriesEncoding = TimeSeriesEncoding = {}));
120
138
  function pushEncodingArgument(args, encoding) {
121
- if (encoding) {
139
+ if (encoding !== undefined) {
122
140
  args.push('ENCODING', encoding);
123
141
  }
124
142
  return args;
125
143
  }
126
144
  exports.pushEncodingArgument = pushEncodingArgument;
127
145
  function pushChunkSizeArgument(args, chunkSize) {
128
- if (chunkSize) {
146
+ if (chunkSize !== undefined) {
129
147
  args.push('CHUNK_SIZE', chunkSize.toString());
130
148
  }
131
149
  return args;
132
150
  }
133
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;
134
159
  function transformLablesReply(reply) {
135
160
  const labels = {};
136
161
  for (const [key, value] of reply) {
@@ -174,8 +199,15 @@ function transformSampleReply(reply) {
174
199
  };
175
200
  }
176
201
  exports.transformSampleReply = transformSampleReply;
202
+ var TimeSeriesBucketTimestamp;
203
+ (function (TimeSeriesBucketTimestamp) {
204
+ TimeSeriesBucketTimestamp["LOW"] = "-";
205
+ TimeSeriesBucketTimestamp["HIGH"] = "+";
206
+ TimeSeriesBucketTimestamp["MID"] = "~";
207
+ })(TimeSeriesBucketTimestamp || (exports.TimeSeriesBucketTimestamp = TimeSeriesBucketTimestamp = {}));
177
208
  function pushRangeArguments(args, fromTimestamp, toTimestamp, options) {
178
209
  args.push(transformTimestampArgument(fromTimestamp), transformTimestampArgument(toTimestamp));
210
+ pushLatestArgument(args, options?.LATEST);
179
211
  if (options?.FILTER_BY_TS) {
180
212
  args.push('FILTER_BY_TS');
181
213
  for (const ts of options.FILTER_BY_TS) {
@@ -193,6 +225,12 @@ function pushRangeArguments(args, fromTimestamp, toTimestamp, options) {
193
225
  }
194
226
  if (options?.AGGREGATION) {
195
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
+ }
196
234
  }
197
235
  return args;
198
236
  }
@@ -206,15 +244,13 @@ function pushMRangeGroupByArguments(args, groupBy) {
206
244
  exports.pushMRangeGroupByArguments = pushMRangeGroupByArguments;
207
245
  function pushFilterArgument(args, filter) {
208
246
  args.push('FILTER');
209
- (0, generic_transformers_1.pushVerdictArguments)(args, filter);
210
- return args;
247
+ return (0, generic_transformers_1.pushVerdictArguments)(args, filter);
211
248
  }
212
249
  exports.pushFilterArgument = pushFilterArgument;
213
250
  function pushMRangeArguments(args, fromTimestamp, toTimestamp, filter, options) {
214
- pushRangeArguments(args, fromTimestamp, toTimestamp, options);
215
- pushFilterArgument(args, filter);
216
- pushMRangeGroupByArguments(args, options?.GROUPBY);
217
- return args;
251
+ args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
252
+ args = pushFilterArgument(args, filter);
253
+ return pushMRangeGroupByArguments(args, options?.GROUPBY);
218
254
  }
219
255
  exports.pushMRangeArguments = pushMRangeArguments;
220
256
  function pushWithLabelsArgument(args, selectedLabels) {
@@ -223,17 +259,16 @@ function pushWithLabelsArgument(args, selectedLabels) {
223
259
  }
224
260
  else {
225
261
  args.push('SELECTED_LABELS');
226
- (0, generic_transformers_1.pushVerdictArguments)(args, selectedLabels);
262
+ args = (0, generic_transformers_1.pushVerdictArguments)(args, selectedLabels);
227
263
  }
228
264
  return args;
229
265
  }
230
266
  exports.pushWithLabelsArgument = pushWithLabelsArgument;
231
267
  function pushMRangeWithLabelsArguments(args, fromTimestamp, toTimestamp, filter, options) {
232
- pushRangeArguments(args, fromTimestamp, toTimestamp, options);
233
- pushWithLabelsArgument(args, options?.SELECTED_LABELS);
234
- pushFilterArgument(args, filter);
235
- pushMRangeGroupByArguments(args, options?.GROUPBY);
236
- return args;
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);
237
272
  }
238
273
  exports.pushMRangeWithLabelsArguments = pushMRangeWithLabelsArguments;
239
274
  function transformRangeReply(reply) {
@@ -263,3 +298,10 @@ function transformMRangeWithLabelsReply(reply) {
263
298
  return args;
264
299
  }
265
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;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { default } from './commands';
2
- export { TimeSeriesDuplicatePolicies, TimeSeriesEncoding, TimeSeriesAggregationType } from './commands';
2
+ export { TimeSeriesDuplicatePolicies, TimeSeriesEncoding, TimeSeriesAggregationType, TimeSeriesReducers, TimeSeriesBucketTimestamp } from './commands';
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeSeriesAggregationType = exports.TimeSeriesEncoding = exports.TimeSeriesDuplicatePolicies = exports.default = void 0;
3
+ exports.TimeSeriesBucketTimestamp = exports.TimeSeriesReducers = exports.TimeSeriesAggregationType = exports.TimeSeriesEncoding = exports.TimeSeriesDuplicatePolicies = exports.default = void 0;
4
4
  var commands_1 = require("./commands");
5
5
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return commands_1.default; } });
6
6
  var commands_2 = require("./commands");
7
7
  Object.defineProperty(exports, "TimeSeriesDuplicatePolicies", { enumerable: true, get: function () { return commands_2.TimeSeriesDuplicatePolicies; } });
8
8
  Object.defineProperty(exports, "TimeSeriesEncoding", { enumerable: true, get: function () { return commands_2.TimeSeriesEncoding; } });
9
9
  Object.defineProperty(exports, "TimeSeriesAggregationType", { enumerable: true, get: function () { return commands_2.TimeSeriesAggregationType; } });
10
+ Object.defineProperty(exports, "TimeSeriesReducers", { enumerable: true, get: function () { return commands_2.TimeSeriesReducers; } });
11
+ Object.defineProperty(exports, "TimeSeriesBucketTimestamp", { enumerable: true, get: function () { return commands_2.TimeSeriesBucketTimestamp; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redis/time-series",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,12 +18,24 @@
18
18
  "devDependencies": {
19
19
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
20
20
  "@redis/test-utils": "*",
21
- "@types/node": "^17.0.31",
21
+ "@types/node": "^20.5.3",
22
22
  "nyc": "^15.1.0",
23
- "release-it": "^15.0.0",
23
+ "release-it": "^16.1.5",
24
24
  "source-map-support": "^0.5.21",
25
- "ts-node": "^10.7.0",
26
- "typedoc": "^0.22.15",
27
- "typescript": "^4.6.4"
28
- }
25
+ "ts-node": "^10.9.1",
26
+ "typedoc": "^0.24.8",
27
+ "typescript": "^5.1.6"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git://github.com/redis/node-redis.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/redis/node-redis/issues"
35
+ },
36
+ "homepage": "https://github.com/redis/node-redis/tree/master/packages/time-series",
37
+ "keywords": [
38
+ "redis",
39
+ "RedisTimeSeries"
40
+ ]
29
41
  }