From 54c3a66c72abae26aae4e46b491b8100cd568582 Mon Sep 17 00:00:00 2001 From: Leibale Date: Tue, 11 Jul 2023 13:11:13 -0400 Subject: [PATCH] time-series --- packages/time-series/lib/commands/ADD.spec.ts | 10 +- .../time-series/lib/commands/ALTER.spec.ts | 16 +- packages/time-series/lib/commands/ALTER.ts | 10 +- .../time-series/lib/commands/CREATE.spec.ts | 12 +- packages/time-series/lib/commands/CREATE.ts | 6 +- .../lib/commands/CREATERULE.spec.ts | 19 +- .../time-series/lib/commands/CREATERULE.ts | 21 +- .../time-series/lib/commands/DECRBY.spec.ts | 8 +- packages/time-series/lib/commands/DECRBY.ts | 14 +- packages/time-series/lib/commands/DEL.spec.ts | 12 +- .../lib/commands/DELETERULE.spec.ts | 14 +- packages/time-series/lib/commands/GET.spec.ts | 30 +- packages/time-series/lib/commands/GET.ts | 9 +- .../time-series/lib/commands/INCRBY.spec.ts | 8 +- packages/time-series/lib/commands/INCRBY.ts | 43 +- .../time-series/lib/commands/INFO.spec.ts | 2 +- .../lib/commands/INFO_DEBUG.spec.ts | 2 +- .../time-series/lib/commands/MADD.spec.ts | 26 +- packages/time-series/lib/commands/MADD.ts | 4 +- .../time-series/lib/commands/MGET.spec.ts | 2 +- .../lib/commands/MGET_WITHLABELS.spec.ts | 2 +- .../time-series/lib/commands/MRANGE.spec.ts | 2 +- .../lib/commands/MRANGE_WITHLABELS.spec.ts | 2 +- .../lib/commands/MREVRANGE.spec.ts | 2 +- .../lib/commands/MREVRANGE_WITHLABELS.spec.ts | 2 +- .../lib/commands/QUERYINDEX.spec.ts | 2 +- .../time-series/lib/commands/RANGE.spec.ts | 2 +- .../time-series/lib/commands/REVRANGE.spec.ts | 2 +- .../time-series/lib/commands/index.spec.ts | 790 +++++++++--------- packages/time-series/lib/commands/index.ts | 708 +++++++--------- packages/time-series/lib/index.ts | 10 +- packages/time-series/lib/test-utils.ts | 20 +- 32 files changed, 879 insertions(+), 933 deletions(-) diff --git a/packages/time-series/lib/commands/ADD.spec.ts b/packages/time-series/lib/commands/ADD.spec.ts index 898f42ee77..0c0e588aa7 100644 --- a/packages/time-series/lib/commands/ADD.spec.ts +++ b/packages/time-series/lib/commands/ADD.spec.ts @@ -1,7 +1,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import ADD from './ADD'; -import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.'; +import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.'; describe('TS.ADD', () => { describe('transformArguments', () => { @@ -24,7 +24,7 @@ describe('TS.ADD', () => { it('with ENCODING', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { - ENCODING: TimeSeriesEncoding.UNCOMPRESSED + ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED }), ['TS.ADD', 'key', '*', '1', 'ENCODING', 'UNCOMPRESSED'] ); @@ -42,7 +42,7 @@ describe('TS.ADD', () => { it('with ON_DUPLICATE', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { - ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK + ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK }), ['TS.ADD', 'key', '*', '1', 'ON_DUPLICATE', 'BLOCK'] ); @@ -61,9 +61,9 @@ describe('TS.ADD', () => { assert.deepEqual( ADD.transformArguments('key', '*', 1, { RETENTION: 1, - ENCODING: TimeSeriesEncoding.UNCOMPRESSED, + ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED, CHUNK_SIZE: 1, - ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK, + ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' } }), ['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value'] diff --git a/packages/time-series/lib/commands/ALTER.spec.ts b/packages/time-series/lib/commands/ALTER.spec.ts index 0a7d7cb2ca..6889cd2b2c 100644 --- a/packages/time-series/lib/commands/ALTER.spec.ts +++ b/packages/time-series/lib/commands/ALTER.spec.ts @@ -1,7 +1,7 @@ import { strict as assert } from 'assert'; -import { TimeSeriesDuplicatePolicies } from '.'; import testUtils, { GLOBAL } from '../test-utils'; import ALTER from './ALTER'; +import { TIME_SERIES_DUPLICATE_POLICIES } from '.'; describe('TS.ALTER', () => { describe('transformArguments', () => { @@ -33,7 +33,7 @@ describe('TS.ALTER', () => { it('with DUPLICATE_POLICY', () => { assert.deepEqual( ALTER.transformArguments('key', { - DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK + DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK }), ['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK'] ); @@ -53,7 +53,7 @@ describe('TS.ALTER', () => { ALTER.transformArguments('key', { RETENTION: 1, CHUNK_SIZE: 1, - DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK, + DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' } }), ['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] @@ -62,11 +62,11 @@ describe('TS.ALTER', () => { }); testUtils.testWithClient('client.ts.alter', async client => { - await client.ts.create('key'); + const [, reply] = await Promise.all([ + client.ts.create('key'), + client.ts.alter('key', { RETENTION: 1 }) + ]); - assert.equal( - await client.ts.alter('key', { RETENTION: 1 }), - 'OK' - ); + assert.equal(reply, 'OK'); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/ALTER.ts b/packages/time-series/lib/commands/ALTER.ts index bf4e4d528c..ae30799b2e 100644 --- a/packages/time-series/lib/commands/ALTER.ts +++ b/packages/time-series/lib/commands/ALTER.ts @@ -1,12 +1,8 @@ -import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.'; import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types'; +import { TsCreateOptions } from './CREATE'; +import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.'; -export interface TsAlterOptions { - RETENTION?: number; - CHUNK_SIZE?: number; - DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies; - LABELS?: Labels; -} +export type TsAlterOptions = Pick; export default { FIRST_KEY_INDEX: 1, diff --git a/packages/time-series/lib/commands/CREATE.spec.ts b/packages/time-series/lib/commands/CREATE.spec.ts index 33717b607c..d77c4117eb 100644 --- a/packages/time-series/lib/commands/CREATE.spec.ts +++ b/packages/time-series/lib/commands/CREATE.spec.ts @@ -1,9 +1,9 @@ import { strict as assert } from 'assert'; -import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.'; import testUtils, { GLOBAL } from '../test-utils'; import CREATE from './CREATE'; +import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.'; -describe('CREATE', () => { +describe('TS.CREATE', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( @@ -24,7 +24,7 @@ describe('CREATE', () => { it('with ENCODING', () => { assert.deepEqual( CREATE.transformArguments('key', { - ENCODING: TimeSeriesEncoding.UNCOMPRESSED + ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED }), ['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED'] ); @@ -42,7 +42,7 @@ describe('CREATE', () => { it('with DUPLICATE_POLICY', () => { assert.deepEqual( CREATE.transformArguments('key', { - DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK + DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK }), ['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK'] ); @@ -61,9 +61,9 @@ describe('CREATE', () => { assert.deepEqual( CREATE.transformArguments('key', { RETENTION: 1, - ENCODING: TimeSeriesEncoding.UNCOMPRESSED, + ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED, CHUNK_SIZE: 1, - DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK, + DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK, LABELS: { label: 'value' } }), ['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value'] diff --git a/packages/time-series/lib/commands/CREATE.ts b/packages/time-series/lib/commands/CREATE.ts index da28112d28..b028a47027 100644 --- a/packages/time-series/lib/commands/CREATE.ts +++ b/packages/time-series/lib/commands/CREATE.ts @@ -1,14 +1,14 @@ +import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types'; import { pushRetentionArgument, TimeSeriesEncoding, pushEncodingArgument, pushChunkSizeArgument, TimeSeriesDuplicatePolicies, + pushDuplicatePolicy, Labels, - pushLabelsArgument, - pushDuplicatePolicy + pushLabelsArgument } from '.'; -import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types'; export interface TsCreateOptions { RETENTION?: number; diff --git a/packages/time-series/lib/commands/CREATERULE.spec.ts b/packages/time-series/lib/commands/CREATERULE.spec.ts index bd336b78df..c06d27671a 100644 --- a/packages/time-series/lib/commands/CREATERULE.spec.ts +++ b/packages/time-series/lib/commands/CREATERULE.spec.ts @@ -1,34 +1,31 @@ import { strict as assert } from 'assert'; -import { TimeSeriesAggregationType } from '.'; import testUtils, { GLOBAL } from '../test-utils'; -import CREATERULE from './CREATERULE'; +import CREATERULE, { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE'; -describe('CREATERULE', () => { +describe('TS.CREATERULE', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( - CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1), + CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1), ['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1'] ); }); it('with alignTimestamp', () => { assert.deepEqual( - CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1, 1), + CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1, 1), ['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1'] ); }); }); testUtils.testWithClient('client.ts.createRule', async client => { - await Promise.all([ + const [, , reply] = await Promise.all([ client.ts.create('source'), - client.ts.create('destination') + client.ts.create('destination'), + client.ts.createRule('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1) ]); - assert.equal( - await client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1), - 'OK' - ); + assert.equal(reply, 'OK'); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/CREATERULE.ts b/packages/time-series/lib/commands/CREATERULE.ts index 8c4536f039..bd074d7107 100644 --- a/packages/time-series/lib/commands/CREATERULE.ts +++ b/packages/time-series/lib/commands/CREATERULE.ts @@ -1,6 +1,23 @@ -import { TimeSeriesAggregationType } from '.'; import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types'; +export const TIME_SERIES_AGGREGATION_TYPE = { + AVG: 'AVG', + FIRST: 'FIRST', + LAST: 'LAST', + MIN: 'MIN', + MAX: 'MAX', + SUM: 'SUM', + RANGE: 'RANGE', + COUNT: 'COUNT', + STD_P: 'STD.P', + STD_S: 'STD.S', + VAR_P: 'VAR.P', + VAR_S: 'VAR.S', + TWA: 'TWA' +} as const; + +export type TimeSeriesAggregationType = typeof TIME_SERIES_AGGREGATION_TYPE[keyof typeof TIME_SERIES_AGGREGATION_TYPE]; + export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, @@ -20,7 +37,7 @@ export default { bucketDuration.toString() ]; - if (alignTimestamp) { + if (alignTimestamp !== undefined) { args.push(alignTimestamp.toString()); } diff --git a/packages/time-series/lib/commands/DECRBY.spec.ts b/packages/time-series/lib/commands/DECRBY.spec.ts index 8efa09ce42..0f7679b794 100644 --- a/packages/time-series/lib/commands/DECRBY.spec.ts +++ b/packages/time-series/lib/commands/DECRBY.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import DECRBY from './DECRBY'; -describe('DECRBY', () => { +describe('TS.DECRBY', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( @@ -72,10 +72,8 @@ describe('DECRBY', () => { testUtils.testWithClient('client.ts.decrBy', async client => { assert.equal( - await client.ts.decrBy('key', 1, { - TIMESTAMP: 0 - }), - 0 + typeof await client.ts.decrBy('key', 1), + 'number' ); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/DECRBY.ts b/packages/time-series/lib/commands/DECRBY.ts index 181568d1a8..a5ee01efb0 100644 --- a/packages/time-series/lib/commands/DECRBY.ts +++ b/packages/time-series/lib/commands/DECRBY.ts @@ -1,11 +1,9 @@ -import { IncrDecrOptions, transformIncrDecrArguments } from '.'; -import { RedisArgument, Command, NumberReply } from '@redis/client/dist/lib/RESP/types'; +import { Command } from '@redis/client/dist/lib/RESP/types'; +import INCRBY, { transformIncrByArguments } from './INCRBY'; export default { - FIRST_KEY_INDEX: 1, - IS_READ_ONLY: false, - transformArguments(key: RedisArgument, value: number, options?: IncrDecrOptions) { - return transformIncrDecrArguments('TS.DECRBY', key, value, options); - }, - transformReply: undefined as unknown as () => NumberReply + FIRST_KEY_INDEX: INCRBY.FIRST_KEY_INDEX, + IS_READ_ONLY: INCRBY.IS_READ_ONLY, + transformArguments: transformIncrByArguments.bind(undefined, 'TS.DECRBY'), + transformReply: INCRBY.transformReply } as const satisfies Command; diff --git a/packages/time-series/lib/commands/DEL.spec.ts b/packages/time-series/lib/commands/DEL.spec.ts index a0fdabedd6..d6f90d2e2a 100644 --- a/packages/time-series/lib/commands/DEL.spec.ts +++ b/packages/time-series/lib/commands/DEL.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import DEL from './DEL'; -describe('DEL', () => { +describe('TS.DEL', () => { it('transformArguments', () => { assert.deepEqual( DEL.transformArguments('key', '-', '+'), @@ -11,11 +11,11 @@ describe('DEL', () => { }); testUtils.testWithClient('client.ts.del', async client => { - await client.ts.create('key'); + const [, reply] = await Promise.all([ + client.ts.create('key'), + client.ts.del('key', '-', '+') + ]); - assert.equal( - await client.ts.del('key', '-', '+'), - 0 - ); + assert.equal(reply, 0); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/DELETERULE.spec.ts b/packages/time-series/lib/commands/DELETERULE.spec.ts index c131dbcef1..1ee0de3993 100644 --- a/packages/time-series/lib/commands/DELETERULE.spec.ts +++ b/packages/time-series/lib/commands/DELETERULE.spec.ts @@ -1,9 +1,9 @@ import { strict as assert } from 'assert'; -import { TimeSeriesAggregationType } from '.'; import testUtils, { GLOBAL } from '../test-utils'; import DELETERULE from './DELETERULE'; +import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE'; -describe('DELETERULE', () => { +describe('TS.DELETERULE', () => { it('transformArguments', () => { assert.deepEqual( DELETERULE.transformArguments('source', 'destination'), @@ -12,15 +12,13 @@ describe('DELETERULE', () => { }); testUtils.testWithClient('client.ts.deleteRule', async client => { - await Promise.all([ + const [, , , reply] = await Promise.all([ client.ts.create('source'), client.ts.create('destination'), - client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1) + client.ts.createRule('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1), + client.ts.deleteRule('source', 'destination') ]); - assert.equal( - await client.ts.deleteRule('source', 'destination'), - 'OK' - ); + assert.equal(reply, 'OK'); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/GET.spec.ts b/packages/time-series/lib/commands/GET.spec.ts index 3af57f7510..4c0925e014 100644 --- a/packages/time-series/lib/commands/GET.spec.ts +++ b/packages/time-series/lib/commands/GET.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import GET from './GET'; -describe('GET', () => { +describe('TS.GET', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( @@ -23,24 +23,24 @@ describe('GET', () => { describe('client.ts.get', () => { testUtils.testWithClient('null', async client => { - await client.ts.create('key'); + const [, reply] = await Promise.all([ + client.ts.create('key'), + client.ts.get('key') + ]); - assert.equal( - await client.ts.get('key'), - null - ); + assert.equal(reply, null); }, GLOBAL.SERVERS.OPEN); - testUtils.testWithClient('with samples', async client => { - await client.ts.add('key', 0, 1); + testUtils.testWithClient('with sample', async client => { + const [, reply] = await Promise.all([ + client.ts.add('key', 0, 1), + client.ts.get('key') + ]); - assert.deepEqual( - await client.ts.get('key'), - { - timestamp: 0, - value: 1 - } - ); + assert.deepEqual(reply, { + timestamp: 0, + value: 1 + }); }, GLOBAL.SERVERS.OPEN); }); }); diff --git a/packages/time-series/lib/commands/GET.ts b/packages/time-series/lib/commands/GET.ts index e2de752a0d..514b51edd2 100644 --- a/packages/time-series/lib/commands/GET.ts +++ b/packages/time-series/lib/commands/GET.ts @@ -1,5 +1,4 @@ import { RedisArgument, TuplesReply, NumberReply, DoubleReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types'; -import { pushLatestArgument } from '.'; export interface TsGetOptions { LATEST?: boolean; @@ -11,7 +10,13 @@ export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: true, transformArguments(key: RedisArgument, options?: TsGetOptions) { - return pushLatestArgument(['TS.GET', key], options?.LATEST); + const args = ['TS.GET', key]; + + if (options?.LATEST) { + args.push('LATEST'); + } + + return args; }, transformReply: { 2(reply: Resp2Reply) { diff --git a/packages/time-series/lib/commands/INCRBY.spec.ts b/packages/time-series/lib/commands/INCRBY.spec.ts index 0745a1d26f..8cd57ee4a2 100644 --- a/packages/time-series/lib/commands/INCRBY.spec.ts +++ b/packages/time-series/lib/commands/INCRBY.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import INCRBY from './INCRBY'; -describe('INCRBY', () => { +describe('TS.INCRBY', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( @@ -82,10 +82,8 @@ describe('INCRBY', () => { testUtils.testWithClient('client.ts.incrBy', async client => { assert.equal( - await client.ts.incrBy('key', 1, { - TIMESTAMP: 0 - }), - 0 + typeof await client.ts.incrBy('key', 1), + 'number' ); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/INCRBY.ts b/packages/time-series/lib/commands/INCRBY.ts index 413c33643a..ece5defee6 100644 --- a/packages/time-series/lib/commands/INCRBY.ts +++ b/packages/time-series/lib/commands/INCRBY.ts @@ -1,11 +1,46 @@ -import { IncrDecrOptions, transformIncrDecrArguments } from '.'; import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; +import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument } from '.'; + +export interface TsIncrByOptions { + TIMESTAMP?: Timestamp; + RETENTION?: number; + UNCOMPRESSED?: boolean; + CHUNK_SIZE?: number; + LABELS?: Labels; +} + +export function transformIncrByArguments( + command: RedisArgument, + key: RedisArgument, + value: number, + options?: TsIncrByOptions +) { + const args = [ + command, + key, + value.toString() + ]; + + if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) { + args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP)); + } + + pushRetentionArgument(args, options?.RETENTION); + + if (options?.UNCOMPRESSED) { + args.push('UNCOMPRESSED'); + } + + pushChunkSizeArgument(args, options?.CHUNK_SIZE); + + pushLabelsArgument(args, options?.LABELS); + + return args; +} export default { FIRST_KEY_INDEX: 1, IS_READ_ONLY: false, - transformArguments(key: RedisArgument, value: number, options?: IncrDecrOptions) { - return transformIncrDecrArguments('TS.INCRBY', key, value, options); - }, + transformArguments: transformIncrByArguments.bind(undefined, 'TS.INCRBY'), transformReply: undefined as unknown as () => NumberReply } as const satisfies Command; diff --git a/packages/time-series/lib/commands/INFO.spec.ts b/packages/time-series/lib/commands/INFO.spec.ts index c02cdd6da4..a03049f03b 100644 --- a/packages/time-series/lib/commands/INFO.spec.ts +++ b/packages/time-series/lib/commands/INFO.spec.ts @@ -3,7 +3,7 @@ import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.'; import testUtils, { GLOBAL } from '../test-utils'; import { InfoReply, transformArguments } from './INFO'; -describe('INFO', () => { +describe('TS.INFO', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('key'), diff --git a/packages/time-series/lib/commands/INFO_DEBUG.spec.ts b/packages/time-series/lib/commands/INFO_DEBUG.spec.ts index 666689f519..caff0e177f 100644 --- a/packages/time-series/lib/commands/INFO_DEBUG.spec.ts +++ b/packages/time-series/lib/commands/INFO_DEBUG.spec.ts @@ -4,7 +4,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { assertInfo } from './INFO.spec'; import { transformArguments } from './INFO_DEBUG'; -describe('INFO_DEBUG', () => { +describe('TS.INFO_DEBUG', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('key'), diff --git a/packages/time-series/lib/commands/MADD.spec.ts b/packages/time-series/lib/commands/MADD.spec.ts index d544676331..119fcfce60 100644 --- a/packages/time-series/lib/commands/MADD.spec.ts +++ b/packages/time-series/lib/commands/MADD.spec.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import MADD from './MADD'; +import { SimpleError } from '@redis/client/lib/errors'; -describe('MADD', () => { +describe.only('TS.MADD', () => { it('transformArguments', () => { assert.deepEqual( MADD.transformArguments([{ @@ -18,22 +19,23 @@ describe('MADD', () => { ); }); - // Should we check empty array? - testUtils.testWithClient('client.ts.mAdd', async client => { - await client.ts.create('key'); - - assert.deepEqual( - await client.ts.mAdd([{ + const [, reply] = await Promise.all([ + client.ts.create('key'), + client.ts.mAdd([{ key: 'key', timestamp: 0, - value: 0 + value: 1 }, { key: 'key', - timestamp: 1, + timestamp: 0, value: 1 - }]), - [0, 1] - ); + }]) + ]); + + assert.ok(Array.isArray(reply)); + assert.equal(reply.length, 2); + assert.equal(reply[0], 0); + assert.ok(reply[1] instanceof SimpleError); }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/time-series/lib/commands/MADD.ts b/packages/time-series/lib/commands/MADD.ts index fc4d22d13a..59c1ed59bd 100644 --- a/packages/time-series/lib/commands/MADD.ts +++ b/packages/time-series/lib/commands/MADD.ts @@ -1,5 +1,5 @@ import { Timestamp, transformTimestampArgument } from '.'; -import { ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types'; +import { ArrayReply, NumberReply, SimpleErrorReply, Command } from '@redis/client/dist/lib/RESP/types'; export interface TsMAddSample { key: string; @@ -23,5 +23,5 @@ export default { return args; }, - transformReply: undefined as unknown as () => ArrayReply + transformReply: undefined as unknown as () => ArrayReply } as const satisfies Command; diff --git a/packages/time-series/lib/commands/MGET.spec.ts b/packages/time-series/lib/commands/MGET.spec.ts index 61da3b9638..c932ff704a 100644 --- a/packages/time-series/lib/commands/MGET.spec.ts +++ b/packages/time-series/lib/commands/MGET.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MGET'; -describe('MGET', () => { +describe('TS.MGET', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( diff --git a/packages/time-series/lib/commands/MGET_WITHLABELS.spec.ts b/packages/time-series/lib/commands/MGET_WITHLABELS.spec.ts index 55fcfde409..67c3a4c7b3 100644 --- a/packages/time-series/lib/commands/MGET_WITHLABELS.spec.ts +++ b/packages/time-series/lib/commands/MGET_WITHLABELS.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MGET_WITHLABELS'; -describe('MGET_WITHLABELS', () => { +describe('TS.MGET_WITHLABELS', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( diff --git a/packages/time-series/lib/commands/MRANGE.spec.ts b/packages/time-series/lib/commands/MRANGE.spec.ts index 4228cc06fb..5f5a7930e5 100644 --- a/packages/time-series/lib/commands/MRANGE.spec.ts +++ b/packages/time-series/lib/commands/MRANGE.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MRANGE'; import { TimeSeriesAggregationType, TimeSeriesReducers } from '.'; -describe('MRANGE', () => { +describe('TS.MRANGE', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('-', '+', 'label=value', { diff --git a/packages/time-series/lib/commands/MRANGE_WITHLABELS.spec.ts b/packages/time-series/lib/commands/MRANGE_WITHLABELS.spec.ts index 983114f840..729e32f19a 100644 --- a/packages/time-series/lib/commands/MRANGE_WITHLABELS.spec.ts +++ b/packages/time-series/lib/commands/MRANGE_WITHLABELS.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MRANGE_WITHLABELS'; import { TimeSeriesAggregationType, TimeSeriesReducers } from '.'; -describe('MRANGE_WITHLABELS', () => { +describe('TS.MRANGE_WITHLABELS', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('-', '+', 'label=value', { diff --git a/packages/time-series/lib/commands/MREVRANGE.spec.ts b/packages/time-series/lib/commands/MREVRANGE.spec.ts index 6e5825d36d..e5dcf5f5f7 100644 --- a/packages/time-series/lib/commands/MREVRANGE.spec.ts +++ b/packages/time-series/lib/commands/MREVRANGE.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MREVRANGE'; import { TimeSeriesAggregationType, TimeSeriesReducers } from '.'; -describe('MREVRANGE', () => { +describe('TS.MREVRANGE', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('-', '+', 'label=value', { diff --git a/packages/time-series/lib/commands/MREVRANGE_WITHLABELS.spec.ts b/packages/time-series/lib/commands/MREVRANGE_WITHLABELS.spec.ts index 7e80e965d4..a3e50b7f26 100644 --- a/packages/time-series/lib/commands/MREVRANGE_WITHLABELS.spec.ts +++ b/packages/time-series/lib/commands/MREVRANGE_WITHLABELS.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './MREVRANGE_WITHLABELS'; import { TimeSeriesAggregationType, TimeSeriesReducers } from '.'; -describe('MREVRANGE_WITHLABELS', () => { +describe('TS.MREVRANGE_WITHLABELS', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('-', '+', 'label=value', { diff --git a/packages/time-series/lib/commands/QUERYINDEX.spec.ts b/packages/time-series/lib/commands/QUERYINDEX.spec.ts index 010c5c8f63..68e473918a 100644 --- a/packages/time-series/lib/commands/QUERYINDEX.spec.ts +++ b/packages/time-series/lib/commands/QUERYINDEX.spec.ts @@ -2,7 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './QUERYINDEX'; -describe('QUERYINDEX', () => { +describe('TS.QUERYINDEX', () => { describe('transformArguments', () => { it('single filter', () => { assert.deepEqual( diff --git a/packages/time-series/lib/commands/RANGE.spec.ts b/packages/time-series/lib/commands/RANGE.spec.ts index 1e6a995880..bc3c549803 100644 --- a/packages/time-series/lib/commands/RANGE.spec.ts +++ b/packages/time-series/lib/commands/RANGE.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './RANGE'; import { TimeSeriesAggregationType } from '.'; -describe('RANGE', () => { +describe('TS.RANGE', () => { it('transformArguments', () => { assert.deepEqual( transformArguments('key', '-', '+', { diff --git a/packages/time-series/lib/commands/REVRANGE.spec.ts b/packages/time-series/lib/commands/REVRANGE.spec.ts index ffd90268c8..6fd0f6a45a 100644 --- a/packages/time-series/lib/commands/REVRANGE.spec.ts +++ b/packages/time-series/lib/commands/REVRANGE.spec.ts @@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './REVRANGE'; import { TimeSeriesAggregationType } from '.'; -describe('REVRANGE', () => { +describe('TS.REVRANGE', () => { describe('transformArguments', () => { it('without options', () => { assert.deepEqual( diff --git a/packages/time-series/lib/commands/index.spec.ts b/packages/time-series/lib/commands/index.spec.ts index a29eefe860..ba71ce777c 100644 --- a/packages/time-series/lib/commands/index.spec.ts +++ b/packages/time-series/lib/commands/index.spec.ts @@ -1,439 +1,439 @@ -import { RedisCommandArguments } from '@redis/client/dist/lib/commands'; -import { strict as assert } from 'assert'; -import { - transformTimestampArgument, - pushRetentionArgument, - TimeSeriesEncoding, - pushEncodingArgument, - pushChunkSizeArgument, - pushDuplicatePolicy, - pushLabelsArgument, - transformIncrDecrArguments, - transformSampleReply, - TimeSeriesAggregationType, - pushRangeArguments, - pushMRangeGroupByArguments, - TimeSeriesReducers, - pushFilterArgument, - pushMRangeArguments, - pushWithLabelsArgument, - pushMRangeWithLabelsArguments, - transformRangeReply, - transformMRangeReply, - transformMRangeWithLabelsReply, - TimeSeriesDuplicatePolicies, - pushLatestArgument, - TimeSeriesBucketTimestamp -} from '.'; +// import { RedisCommandArguments } from '@redis/client/dist/lib/commands'; +// import { strict as assert } from 'assert'; +// import { +// transformTimestampArgument, +// pushRetentionArgument, +// TimeSeriesEncoding, +// pushEncodingArgument, +// pushChunkSizeArgument, +// pushDuplicatePolicy, +// pushLabelsArgument, +// transformIncrDecrArguments, +// transformSampleReply, +// TimeSeriesAggregationType, +// pushRangeArguments, +// pushMRangeGroupByArguments, +// TimeSeriesReducers, +// pushFilterArgument, +// pushMRangeArguments, +// pushWithLabelsArgument, +// pushMRangeWithLabelsArguments, +// transformRangeReply, +// transformMRangeReply, +// transformMRangeWithLabelsReply, +// TimeSeriesDuplicatePolicies, +// pushLatestArgument, +// TimeSeriesBucketTimestamp +// } from '.'; -describe('transformTimestampArgument', () => { - it('number', () => { - assert.equal( - transformTimestampArgument(0), - '0' - ); - }); +// describe('transformTimestampArgument', () => { +// it('number', () => { +// assert.equal( +// transformTimestampArgument(0), +// '0' +// ); +// }); - it('Date', () => { - assert.equal( - transformTimestampArgument(new Date(0)), - '0' - ); - }); +// it('Date', () => { +// assert.equal( +// transformTimestampArgument(new Date(0)), +// '0' +// ); +// }); - it('string', () => { - assert.equal( - transformTimestampArgument('*'), - '*' - ); - }); -}); +// it('string', () => { +// assert.equal( +// transformTimestampArgument('*'), +// '*' +// ); +// }); +// }); -function testOptionalArgument(fn: (args: RedisCommandArguments) => unknown): void { - it('undefined', () => { - assert.deepEqual( - fn([]), - [] - ); - }); -} +// function testOptionalArgument(fn: (args: RedisCommandArguments) => unknown): void { +// it('undefined', () => { +// assert.deepEqual( +// fn([]), +// [] +// ); +// }); +// } -describe('pushRetentionArgument', () => { - testOptionalArgument(pushRetentionArgument); +// describe('pushRetentionArgument', () => { +// testOptionalArgument(pushRetentionArgument); - it('number', () => { - assert.deepEqual( - pushRetentionArgument([], 1), - ['RETENTION', '1'] - ); - }); -}); +// it('number', () => { +// assert.deepEqual( +// pushRetentionArgument([], 1), +// ['RETENTION', '1'] +// ); +// }); +// }); -describe('pushEncodingArgument', () => { - testOptionalArgument(pushEncodingArgument); +// describe('pushEncodingArgument', () => { +// testOptionalArgument(pushEncodingArgument); - it('UNCOMPRESSED', () => { - assert.deepEqual( - pushEncodingArgument([], TimeSeriesEncoding.UNCOMPRESSED), - ['ENCODING', 'UNCOMPRESSED'] - ); - }); -}); +// it('UNCOMPRESSED', () => { +// assert.deepEqual( +// pushEncodingArgument([], TimeSeriesEncoding.UNCOMPRESSED), +// ['ENCODING', 'UNCOMPRESSED'] +// ); +// }); +// }); -describe('pushChunkSizeArgument', () => { - testOptionalArgument(pushChunkSizeArgument); +// describe('pushChunkSizeArgument', () => { +// testOptionalArgument(pushChunkSizeArgument); - it('number', () => { - assert.deepEqual( - pushChunkSizeArgument([], 1), - ['CHUNK_SIZE', '1'] - ); - }); -}); +// it('number', () => { +// assert.deepEqual( +// pushChunkSizeArgument([], 1), +// ['CHUNK_SIZE', '1'] +// ); +// }); +// }); -describe('pushDuplicatePolicy', () => { - testOptionalArgument(pushDuplicatePolicy); +// describe('pushDuplicatePolicy', () => { +// testOptionalArgument(pushDuplicatePolicy); - it('BLOCK', () => { - assert.deepEqual( - pushDuplicatePolicy([], TimeSeriesDuplicatePolicies.BLOCK), - ['DUPLICATE_POLICY', 'BLOCK'] - ); - }); -}); +// it('BLOCK', () => { +// assert.deepEqual( +// pushDuplicatePolicy([], TimeSeriesDuplicatePolicies.BLOCK), +// ['DUPLICATE_POLICY', 'BLOCK'] +// ); +// }); +// }); -describe('pushLabelsArgument', () => { - testOptionalArgument(pushLabelsArgument); +// describe('pushLabelsArgument', () => { +// testOptionalArgument(pushLabelsArgument); - it("{ label: 'value' }", () => { - assert.deepEqual( - pushLabelsArgument([], { label: 'value' }), - ['LABELS', 'label', 'value'] - ); - }); -}); +// it("{ label: 'value' }", () => { +// assert.deepEqual( +// pushLabelsArgument([], { label: 'value' }), +// ['LABELS', 'label', 'value'] +// ); +// }); +// }); -describe('transformIncrDecrArguments', () => { - it('without options', () => { - assert.deepEqual( - transformIncrDecrArguments('TS.INCRBY', 'key', 1), - ['TS.INCRBY', 'key', '1'] - ); - }); +// describe('transformIncrDecrArguments', () => { +// it('without options', () => { +// assert.deepEqual( +// transformIncrDecrArguments('TS.INCRBY', 'key', 1), +// ['TS.INCRBY', 'key', '1'] +// ); +// }); - it('with TIMESTAMP', () => { - assert.deepEqual( - transformIncrDecrArguments('TS.INCRBY', 'key', 1, { - TIMESTAMP: '*' - }), - ['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*'] - ); - }); +// it('with TIMESTAMP', () => { +// assert.deepEqual( +// transformIncrDecrArguments('TS.INCRBY', 'key', 1, { +// TIMESTAMP: '*' +// }), +// ['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*'] +// ); +// }); - it('with UNCOMPRESSED', () => { - assert.deepEqual( - transformIncrDecrArguments('TS.INCRBY', 'key', 1, { - UNCOMPRESSED: true - }), - ['TS.INCRBY', 'key', '1', 'UNCOMPRESSED'] - ); - }); +// it('with UNCOMPRESSED', () => { +// assert.deepEqual( +// transformIncrDecrArguments('TS.INCRBY', 'key', 1, { +// UNCOMPRESSED: true +// }), +// ['TS.INCRBY', 'key', '1', 'UNCOMPRESSED'] +// ); +// }); - it('with UNCOMPRESSED false', () => { - assert.deepEqual( - transformIncrDecrArguments('TS.INCRBY', 'key', 1, { - UNCOMPRESSED: false - }), - ['TS.INCRBY', 'key', '1'] - ); - }); -}); +// it('with UNCOMPRESSED false', () => { +// assert.deepEqual( +// transformIncrDecrArguments('TS.INCRBY', 'key', 1, { +// UNCOMPRESSED: false +// }), +// ['TS.INCRBY', 'key', '1'] +// ); +// }); +// }); -it('transformSampleReply', () => { - assert.deepEqual( - transformSampleReply([1, '1.1']), - { - timestamp: 1, - value: 1.1 - } - ); -}); +// it('transformSampleReply', () => { +// assert.deepEqual( +// transformSampleReply([1, '1.1']), +// { +// timestamp: 1, +// value: 1.1 +// } +// ); +// }); -describe('pushRangeArguments', () => { - it('without options', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+'), - ['-', '+'] - ); - }); +// describe('pushRangeArguments', () => { +// it('without options', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+'), +// ['-', '+'] +// ); +// }); - describe('with FILTER_BY_TS', () => { - it('string', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - FILTER_BY_TS: ['ts'] - }), - ['-', '+', 'FILTER_BY_TS', 'ts'] - ); - }); +// describe('with FILTER_BY_TS', () => { +// it('string', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// FILTER_BY_TS: ['ts'] +// }), +// ['-', '+', 'FILTER_BY_TS', 'ts'] +// ); +// }); - it('Array', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - FILTER_BY_TS: ['1', '2'] - }), - ['-', '+', 'FILTER_BY_TS', '1', '2'] - ); - }); - }); +// it('Array', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// FILTER_BY_TS: ['1', '2'] +// }), +// ['-', '+', 'FILTER_BY_TS', '1', '2'] +// ); +// }); +// }); - it('with FILTER_BY_VALUE', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - FILTER_BY_VALUE: { - min: 1, - max: 2 - } - }), - ['-', '+', 'FILTER_BY_VALUE', '1', '2'] - ); - }); +// it('with FILTER_BY_VALUE', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// FILTER_BY_VALUE: { +// min: 1, +// max: 2 +// } +// }), +// ['-', '+', 'FILTER_BY_VALUE', '1', '2'] +// ); +// }); - it('with COUNT', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - COUNT: 1 - }), - ['-', '+', 'COUNT', '1'] - ); - }); +// it('with COUNT', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// COUNT: 1 +// }), +// ['-', '+', 'COUNT', '1'] +// ); +// }); - it('with ALIGN', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - ALIGN: 1 - }), - ['-', '+', 'ALIGN', '1'] - ); - }); +// it('with ALIGN', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// ALIGN: 1 +// }), +// ['-', '+', 'ALIGN', '1'] +// ); +// }); - describe('with AGGREGATION', () => { - it('without options', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - AGGREGATION: { - type: TimeSeriesAggregationType.FIRST, - timeBucket: 1 - } - }), - ['-', '+', 'AGGREGATION', 'FIRST', '1'] - ); - }); +// describe('with AGGREGATION', () => { +// it('without options', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// AGGREGATION: { +// type: TimeSeriesAggregationType.FIRST, +// timeBucket: 1 +// } +// }), +// ['-', '+', 'AGGREGATION', 'FIRST', '1'] +// ); +// }); - it('with BUCKETTIMESTAMP', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - AGGREGATION: { - type: TimeSeriesAggregationType.FIRST, - timeBucket: 1, - BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW - } - }), - ['-', '+', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-'] - ); - }); +// it('with BUCKETTIMESTAMP', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// AGGREGATION: { +// type: TimeSeriesAggregationType.FIRST, +// timeBucket: 1, +// BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW +// } +// }), +// ['-', '+', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-'] +// ); +// }); - it('with BUCKETTIMESTAMP', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - AGGREGATION: { - type: TimeSeriesAggregationType.FIRST, - timeBucket: 1, - EMPTY: true - } - }), - ['-', '+', 'AGGREGATION', 'FIRST', '1', 'EMPTY'] - ); - }); - }); +// it('with BUCKETTIMESTAMP', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// AGGREGATION: { +// type: TimeSeriesAggregationType.FIRST, +// timeBucket: 1, +// EMPTY: true +// } +// }), +// ['-', '+', 'AGGREGATION', 'FIRST', '1', 'EMPTY'] +// ); +// }); +// }); - it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => { - assert.deepEqual( - pushRangeArguments([], '-', '+', { - FILTER_BY_TS: ['ts'], - FILTER_BY_VALUE: { - min: 1, - max: 2 - }, - COUNT: 1, - ALIGN: 1, - AGGREGATION: { - type: TimeSeriesAggregationType.FIRST, - timeBucket: 1, - BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW, - EMPTY: true - } - }), - ['-', '+', 'FILTER_BY_TS', 'ts', 'FILTER_BY_VALUE', '1', '2', - 'COUNT', '1', 'ALIGN', '1', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-', 'EMPTY'] - ); - }); -}); +// it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => { +// assert.deepEqual( +// pushRangeArguments([], '-', '+', { +// FILTER_BY_TS: ['ts'], +// FILTER_BY_VALUE: { +// min: 1, +// max: 2 +// }, +// COUNT: 1, +// ALIGN: 1, +// AGGREGATION: { +// type: TimeSeriesAggregationType.FIRST, +// timeBucket: 1, +// BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW, +// EMPTY: true +// } +// }), +// ['-', '+', 'FILTER_BY_TS', 'ts', 'FILTER_BY_VALUE', '1', '2', +// 'COUNT', '1', 'ALIGN', '1', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-', 'EMPTY'] +// ); +// }); +// }); -describe('pushMRangeGroupByArguments', () => { - it('undefined', () => { - assert.deepEqual( - pushMRangeGroupByArguments([]), - [] - ); - }); +// describe('pushMRangeGroupByArguments', () => { +// it('undefined', () => { +// assert.deepEqual( +// pushMRangeGroupByArguments([]), +// [] +// ); +// }); - it('with GROUPBY', () => { - assert.deepEqual( - pushMRangeGroupByArguments([], { - label: 'label', - reducer: TimeSeriesReducers.MAXIMUM - }), - ['GROUPBY', 'label', 'REDUCE', 'MAX'] - ); - }); -}); +// it('with GROUPBY', () => { +// assert.deepEqual( +// pushMRangeGroupByArguments([], { +// label: 'label', +// reducer: TimeSeriesReducers.MAXIMUM +// }), +// ['GROUPBY', 'label', 'REDUCE', 'MAX'] +// ); +// }); +// }); -describe('pushFilterArgument', () => { - it('string', () => { - assert.deepEqual( - pushFilterArgument([], 'label=value'), - ['FILTER', 'label=value'] - ); - }); +// describe('pushFilterArgument', () => { +// it('string', () => { +// assert.deepEqual( +// pushFilterArgument([], 'label=value'), +// ['FILTER', 'label=value'] +// ); +// }); - it('Array', () => { - assert.deepEqual( - pushFilterArgument([], ['1=1', '2=2']), - ['FILTER', '1=1', '2=2'] - ); - }); -}); +// it('Array', () => { +// assert.deepEqual( +// pushFilterArgument([], ['1=1', '2=2']), +// ['FILTER', '1=1', '2=2'] +// ); +// }); +// }); -describe('pushMRangeArguments', () => { - it('without options', () => { - assert.deepEqual( - pushMRangeArguments([], '-', '+', 'label=value'), - ['-', '+', 'FILTER', 'label=value'] - ); - }); +// describe('pushMRangeArguments', () => { +// it('without options', () => { +// assert.deepEqual( +// pushMRangeArguments([], '-', '+', 'label=value'), +// ['-', '+', 'FILTER', 'label=value'] +// ); +// }); - it('with GROUPBY', () => { - assert.deepEqual( - pushMRangeArguments([], '-', '+', 'label=value', { - GROUPBY: { - label: 'label', - reducer: TimeSeriesReducers.MAXIMUM - } - }), - ['-', '+', 'FILTER', 'label=value', 'GROUPBY', 'label', 'REDUCE', 'MAX'] - ); - }); -}); +// it('with GROUPBY', () => { +// assert.deepEqual( +// pushMRangeArguments([], '-', '+', 'label=value', { +// GROUPBY: { +// label: 'label', +// reducer: TimeSeriesReducers.MAXIMUM +// } +// }), +// ['-', '+', 'FILTER', 'label=value', 'GROUPBY', 'label', 'REDUCE', 'MAX'] +// ); +// }); +// }); -describe('pushWithLabelsArgument', () => { - it('without selected labels', () => { - assert.deepEqual( - pushWithLabelsArgument([]), - ['WITHLABELS'] - ); - }); +// describe('pushWithLabelsArgument', () => { +// it('without selected labels', () => { +// assert.deepEqual( +// pushWithLabelsArgument([]), +// ['WITHLABELS'] +// ); +// }); - it('with selected labels', () => { - assert.deepEqual( - pushWithLabelsArgument([], ['label']), - ['SELECTED_LABELS', 'label'] - ); - }); -}); +// it('with selected labels', () => { +// assert.deepEqual( +// pushWithLabelsArgument([], ['label']), +// ['SELECTED_LABELS', 'label'] +// ); +// }); +// }); -it('pushMRangeWithLabelsArguments', () => { - assert.deepEqual( - pushMRangeWithLabelsArguments([], '-', '+', 'label=value'), - ['-', '+', 'WITHLABELS', 'FILTER', 'label=value'] - ); -}); +// it('pushMRangeWithLabelsArguments', () => { +// assert.deepEqual( +// pushMRangeWithLabelsArguments([], '-', '+', 'label=value'), +// ['-', '+', 'WITHLABELS', 'FILTER', 'label=value'] +// ); +// }); -it('transformRangeReply', () => { - assert.deepEqual( - transformRangeReply([[1, '1.1'], [2, '2.2']]), - [{ - timestamp: 1, - value: 1.1 - }, { - timestamp: 2, - value: 2.2 - }] - ); -}); +// it('transformRangeReply', () => { +// assert.deepEqual( +// transformRangeReply([[1, '1.1'], [2, '2.2']]), +// [{ +// timestamp: 1, +// value: 1.1 +// }, { +// timestamp: 2, +// value: 2.2 +// }] +// ); +// }); -describe('transformMRangeReply', () => { - assert.deepEqual( - transformMRangeReply([[ - 'key', - [], - [[1, '1.1'], [2, '2.2']] - ]]), - [{ - key: 'key', - samples: [{ - timestamp: 1, - value: 1.1 - }, { - timestamp: 2, - value: 2.2 - }] - }] - ); -}); +// describe('transformMRangeReply', () => { +// assert.deepEqual( +// transformMRangeReply([[ +// 'key', +// [], +// [[1, '1.1'], [2, '2.2']] +// ]]), +// [{ +// key: 'key', +// samples: [{ +// timestamp: 1, +// value: 1.1 +// }, { +// timestamp: 2, +// value: 2.2 +// }] +// }] +// ); +// }); -describe('transformMRangeWithLabelsReply', () => { - assert.deepEqual( - transformMRangeWithLabelsReply([[ - 'key', - [['label', 'value']], - [[1, '1.1'], [2, '2.2']] - ]]), - [{ - key: 'key', - labels: { - label: 'value' - }, - samples: [{ - timestamp: 1, - value: 1.1 - }, { - timestamp: 2, - value: 2.2 - }] - }] - ); -}); +// describe('transformMRangeWithLabelsReply', () => { +// assert.deepEqual( +// transformMRangeWithLabelsReply([[ +// 'key', +// [['label', 'value']], +// [[1, '1.1'], [2, '2.2']] +// ]]), +// [{ +// key: 'key', +// labels: { +// label: 'value' +// }, +// samples: [{ +// timestamp: 1, +// value: 1.1 +// }, { +// timestamp: 2, +// value: 2.2 +// }] +// }] +// ); +// }); -describe('pushLatestArgument', () => { - it('undefined', () => { - assert.deepEqual( - pushLatestArgument([]), - [] - ); - }); +// describe('pushLatestArgument', () => { +// it('undefined', () => { +// assert.deepEqual( +// pushLatestArgument([]), +// [] +// ); +// }); - it('false', () => { - assert.deepEqual( - pushLatestArgument([], false), - [] - ); - }); +// it('false', () => { +// assert.deepEqual( +// pushLatestArgument([], false), +// [] +// ); +// }); - it('true', () => { - assert.deepEqual( - pushLatestArgument([], true), - ['LATEST'] - ); - }); -}) +// it('true', () => { +// assert.deepEqual( +// pushLatestArgument([], true), +// ['LATEST'] +// ); +// }); +// }) diff --git a/packages/time-series/lib/commands/index.ts b/packages/time-series/lib/commands/index.ts index 0b0b56d263..2c8fb48ce6 100644 --- a/packages/time-series/lib/commands/index.ts +++ b/packages/time-series/lib/commands/index.ts @@ -1,467 +1,367 @@ -import * as ADD from './ADD'; -import * as ALTER from './ALTER'; -import * as CREATE from './CREATE'; -import * as CREATERULE from './CREATERULE'; -import * as DECRBY from './DECRBY'; -import * as DEL from './DEL'; -import * as DELETERULE from './DELETERULE'; -import * as GET from './GET'; -import * as INCRBY from './INCRBY'; -import * as INFO_DEBUG from './INFO_DEBUG'; -import * as INFO from './INFO'; -import * as MADD from './MADD'; -import * as MGET from './MGET'; -import * as MGET_WITHLABELS from './MGET_WITHLABELS'; -import * as QUERYINDEX from './QUERYINDEX'; -import * as RANGE from './RANGE'; -import * as REVRANGE from './REVRANGE'; -import * as MRANGE from './MRANGE'; -import * as MRANGE_WITHLABELS from './MRANGE_WITHLABELS'; -import * as MREVRANGE from './MREVRANGE'; -import * as MREVRANGE_WITHLABELS from './MREVRANGE_WITHLABELS'; -import { RedisCommandArguments } from '@redis/client/dist/lib/commands'; -import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers'; +import type { RedisArgument, RedisCommands } from '@redis/client/dist/lib/RESP/types'; +import ADD from './ADD'; +import ALTER from './ALTER'; +import CREATE from './CREATE'; +import CREATERULE from './CREATERULE'; +import DECRBY from './DECRBY'; +import DEL from './DEL'; +import DELETERULE from './DELETERULE'; +import GET from './GET'; +import INCRBY from './INCRBY'; +// import INFO_DEBUG from './INFO_DEBUG'; +// import INFO from './INFO'; +import MADD from './MADD'; +// import MGET from './MGET'; +// import MGET_WITHLABELS from './MGET_WITHLABELS'; +// import QUERYINDEX from './QUERYINDEX'; +// import RANGE from './RANGE'; +// import REVRANGE from './REVRANGE'; +// import MRANGE from './MRANGE'; +// import MRANGE_WITHLABELS from './MRANGE_WITHLABELS'; +// import MREVRANGE from './MREVRANGE'; +// import MREVRANGE_WITHLABELS from './MREVRANGE_WITHLABELS'; export default { - ADD, - add: ADD, - ALTER, - alter: ALTER, - CREATE, - create: CREATE, - CREATERULE, - createRule: CREATERULE, - DECRBY, - decrBy: DECRBY, - DEL, - del: DEL, - DELETERULE, - deleteRule: DELETERULE, - GET, - get: GET, - INCRBY, - incrBy: INCRBY, - INFO_DEBUG, - infoDebug: INFO_DEBUG, - INFO, - info: INFO, - MADD, - mAdd: MADD, - MGET, - mGet: MGET, - MGET_WITHLABELS, - mGetWithLabels: MGET_WITHLABELS, - QUERYINDEX, - queryIndex: QUERYINDEX, - RANGE, - range: RANGE, - REVRANGE, - revRange: REVRANGE, - MRANGE, - mRange: MRANGE, - MRANGE_WITHLABELS, - mRangeWithLabels: MRANGE_WITHLABELS, - MREVRANGE, - mRevRange: MREVRANGE, - MREVRANGE_WITHLABELS, - mRevRangeWithLabels: MREVRANGE_WITHLABELS -}; + ADD, + add: ADD, + ALTER, + alter: ALTER, + CREATE, + create: CREATE, + CREATERULE, + createRule: CREATERULE, + DECRBY, + decrBy: DECRBY, + DEL, + del: DEL, + DELETERULE, + deleteRule: DELETERULE, + GET, + get: GET, + INCRBY, + incrBy: INCRBY, + // INFO_DEBUG, + // infoDebug: INFO_DEBUG, + // INFO, + // info: INFO, + MADD, + mAdd: MADD, + // MGET, + // mGet: MGET, + // MGET_WITHLABELS, + // mGetWithLabels: MGET_WITHLABELS, + // QUERYINDEX, + // queryIndex: QUERYINDEX, + // RANGE, + // range: RANGE, + // REVRANGE, + // revRange: REVRANGE, + // MRANGE, + // mRange: MRANGE, + // MRANGE_WITHLABELS, + // mRangeWithLabels: MRANGE_WITHLABELS, + // MREVRANGE, + // mRevRange: MREVRANGE, + // MREVRANGE_WITHLABELS, + // mRevRangeWithLabels: MREVRANGE_WITHLABELS +} as const satisfies RedisCommands; -export enum TimeSeriesAggregationType { - AVG = 'AVG', - // @deprecated - AVERAGE = 'AVG', - FIRST = 'FIRST', - LAST = 'LAST', - MIN = 'MIN', - // @deprecated - MINIMUM = 'MIN', - MAX = 'MAX', - // @deprecated - MAXIMUM = 'MAX', - SUM = 'SUM', - RANGE = 'RANGE', - COUNT = 'COUNT', - STD_P = 'STD.P', - STD_S = 'STD.S', - VAR_P = 'VAR.P', - VAR_S = 'VAR.S', - TWA = 'TWA' +export function pushRetentionArgument(args: Array, retention?: number) { + if (retention !== undefined) { + args.push('RETENTION', retention.toString()); + } } -export enum TimeSeriesDuplicatePolicies { - BLOCK = 'BLOCK', - FIRST = 'FIRST', - LAST = 'LAST', - MIN = 'MIN', - MAX = 'MAX', - SUM = 'SUM' +export const TIME_SERIES_ENCODING = { + COMPRESSED: 'COMPRESSED', + UNCOMPRESSED: 'UNCOMPRESSED' +} as const; + +export type TimeSeriesEncoding = typeof TIME_SERIES_ENCODING[keyof typeof TIME_SERIES_ENCODING]; + +export function pushEncodingArgument(args: Array, encoding?: TimeSeriesEncoding) { + if (encoding !== undefined) { + args.push('ENCODING', encoding); + } } -export enum TimeSeriesReducers { - AVG = 'AVG', - SUM = 'SUM', - MIN = 'MIN', - // @deprecated - MINIMUM = 'MIN', - MAX = 'MAX', - // @deprecated - MAXIMUM = 'MAX', - RANGE = 'range', - COUNT = 'COUNT', - STD_P = 'STD.P', - STD_S = 'STD.S', - VAR_P = 'VAR.P', - VAR_S = 'VAR.S', +export function pushChunkSizeArgument(args: Array, chunkSize?: number) { + if (chunkSize !== undefined) { + args.push('CHUNK_SIZE', chunkSize.toString()); + } +} + +export const TIME_SERIES_DUPLICATE_POLICIES = { + BLOCK: 'BLOCK', + FIRST: 'FIRST', + LAST: 'LAST', + MIN: 'MIN', + MAX: 'MAX', + SUM: 'SUM' +} as const; + +export type TimeSeriesDuplicatePolicies = typeof TIME_SERIES_DUPLICATE_POLICIES[keyof typeof TIME_SERIES_DUPLICATE_POLICIES]; + +export function pushDuplicatePolicy(args: Array, duplicatePolicy?: TimeSeriesDuplicatePolicies) { + if (duplicatePolicy !== undefined) { + args.push('DUPLICATE_POLICY', duplicatePolicy); + } } export type Timestamp = number | Date | string; export function transformTimestampArgument(timestamp: Timestamp): string { - if (typeof timestamp === 'string') return timestamp; + if (typeof timestamp === 'string') return timestamp; - return ( - typeof timestamp === 'number' ? - timestamp : - timestamp.getTime() - ).toString(); + return ( + typeof timestamp === 'number' ? + timestamp : + timestamp.getTime() + ).toString(); } -export function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments { - if (retention !== undefined) { - args.push( - 'RETENTION', - retention.toString() - ); - } - - return args; -} - -export enum TimeSeriesEncoding { - COMPRESSED = 'COMPRESSED', - UNCOMPRESSED = 'UNCOMPRESSED' -} - -export function pushEncodingArgument(args: RedisCommandArguments, encoding?: TimeSeriesEncoding): RedisCommandArguments { - if (encoding !== undefined) { - args.push( - 'ENCODING', - encoding - ); - } - - return args; -} - -export function pushChunkSizeArgument(args: RedisCommandArguments, chunkSize?: number): RedisCommandArguments { - if (chunkSize !== undefined) { - args.push( - 'CHUNK_SIZE', - chunkSize.toString() - ); - } - - return args; -} - -export function pushDuplicatePolicy(args: RedisCommandArguments, duplicatePolicy?: TimeSeriesDuplicatePolicies): RedisCommandArguments { - if (duplicatePolicy !== undefined) { - args.push( - 'DUPLICATE_POLICY', - duplicatePolicy - ); - } - - return args; -} - -export type RawLabels = Array<[label: string, value: string]>; - export type Labels = { - [label: string]: string; + [label: string]: string; }; -export function transformLablesReply(reply: RawLabels): Labels { - const labels: Labels = {}; +export function pushLabelsArgument(args: Array, labels?: Labels) { + if (labels) { + args.push('LABELS'); - for (const [key, value] of reply) { - labels[key] = value; + for (const [label, value] of Object.entries(labels)) { + args.push(label, value); } + } - return labels + return args; } -export function pushLabelsArgument(args: RedisCommandArguments, labels?: Labels): RedisCommandArguments { - if (labels) { - args.push('LABELS'); +// export type RawLabelsReply = ArrayReply>; - for (const [label, value] of Object.entries(labels)) { - args.push(label, value); - } - } +// export function transformLablesReply(reply: RawLabelsReply) { +// const labels: Record = {}; - return args; -} +// for (const [key, value] of reply) { +// labels[key.toString()] = value; +// } -export interface IncrDecrOptions { - TIMESTAMP?: Timestamp; - RETENTION?: number; - UNCOMPRESSED?: boolean; - CHUNK_SIZE?: number; - LABELS?: Labels; -} +// return labels +// } -export function transformIncrDecrArguments( - command: 'TS.INCRBY' | 'TS.DECRBY', - key: string, - value: number, - options?: IncrDecrOptions -): RedisCommandArguments { - const args = [ - command, - key, - value.toString() - ]; - if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) { - args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP)); - } +// export type SampleRawReply = [timestamp: number, value: string]; - pushRetentionArgument(args, options?.RETENTION); +// export interface SampleReply { +// timestamp: number; +// value: number; +// } - if (options?.UNCOMPRESSED) { - args.push('UNCOMPRESSED'); - } +// export function transformSampleReply(reply: SampleRawReply): SampleReply { +// return { +// timestamp: reply[0], +// value: Number(reply[1]) +// }; +// } - pushChunkSizeArgument(args, options?.CHUNK_SIZE); +// export enum TimeSeriesBucketTimestamp { +// LOW = '-', +// HIGH = '+', +// MID = '~' +// } - pushLabelsArgument(args, options?.LABELS); +// export interface RangeOptions { +// LATEST?: boolean; +// FILTER_BY_TS?: Array; +// FILTER_BY_VALUE?: { +// min: number; +// max: number; +// }; +// COUNT?: number; +// ALIGN?: Timestamp; +// AGGREGATION?: { +// type: TimeSeriesAggregationType; +// timeBucket: Timestamp; +// BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp; +// EMPTY?: boolean; +// }; +// } - return args; -} +// export function pushRangeArguments( +// args: RedisCommandArguments, +// fromTimestamp: Timestamp, +// toTimestamp: Timestamp, +// options?: RangeOptions +// ): RedisCommandArguments { +// args.push( +// transformTimestampArgument(fromTimestamp), +// transformTimestampArgument(toTimestamp) +// ); -export type SampleRawReply = [timestamp: number, value: string]; +// pushLatestArgument(args, options?.LATEST); -export interface SampleReply { - timestamp: number; - value: number; -} +// if (options?.FILTER_BY_TS) { +// args.push('FILTER_BY_TS'); +// for (const ts of options.FILTER_BY_TS) { +// args.push(transformTimestampArgument(ts)); +// } +// } -export function transformSampleReply(reply: SampleRawReply): SampleReply { - return { - timestamp: reply[0], - value: Number(reply[1]) - }; -} +// if (options?.FILTER_BY_VALUE) { +// args.push( +// 'FILTER_BY_VALUE', +// options.FILTER_BY_VALUE.min.toString(), +// options.FILTER_BY_VALUE.max.toString() +// ); +// } -export enum TimeSeriesBucketTimestamp { - LOW = '-', - HIGH = '+', - MID = '~' -} +// if (options?.COUNT) { +// args.push( +// 'COUNT', +// options.COUNT.toString() +// ); +// } -export interface RangeOptions { - LATEST?: boolean; - FILTER_BY_TS?: Array; - FILTER_BY_VALUE?: { - min: number; - max: number; - }; - COUNT?: number; - ALIGN?: Timestamp; - AGGREGATION?: { - type: TimeSeriesAggregationType; - timeBucket: Timestamp; - BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp; - EMPTY?: boolean; - }; -} +// if (options?.ALIGN) { +// args.push( +// 'ALIGN', +// transformTimestampArgument(options.ALIGN) +// ); +// } -export function pushRangeArguments( - args: RedisCommandArguments, - fromTimestamp: Timestamp, - toTimestamp: Timestamp, - options?: RangeOptions -): RedisCommandArguments { - args.push( - transformTimestampArgument(fromTimestamp), - transformTimestampArgument(toTimestamp) - ); +// if (options?.AGGREGATION) { +// args.push( +// 'AGGREGATION', +// options.AGGREGATION.type, +// transformTimestampArgument(options.AGGREGATION.timeBucket) +// ); - pushLatestArgument(args, options?.LATEST); +// if (options.AGGREGATION.BUCKETTIMESTAMP) { +// args.push( +// 'BUCKETTIMESTAMP', +// options.AGGREGATION.BUCKETTIMESTAMP +// ); +// } - if (options?.FILTER_BY_TS) { - args.push('FILTER_BY_TS'); - for (const ts of options.FILTER_BY_TS) { - args.push(transformTimestampArgument(ts)); - } - } +// if (options.AGGREGATION.EMPTY) { +// args.push('EMPTY'); +// } +// } - if (options?.FILTER_BY_VALUE) { - args.push( - 'FILTER_BY_VALUE', - options.FILTER_BY_VALUE.min.toString(), - options.FILTER_BY_VALUE.max.toString() - ); - } +// return args; +// } - if (options?.COUNT) { - args.push( - 'COUNT', - options.COUNT.toString() - ); - } +// interface MRangeGroupBy { +// label: string; +// reducer: TimeSeriesReducers; +// } - if (options?.ALIGN) { - args.push( - 'ALIGN', - transformTimestampArgument(options.ALIGN) - ); - } +// export function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments { +// if (groupBy) { +// args.push( +// 'GROUPBY', +// groupBy.label, +// 'REDUCE', +// groupBy.reducer +// ); +// } - if (options?.AGGREGATION) { - args.push( - 'AGGREGATION', - options.AGGREGATION.type, - transformTimestampArgument(options.AGGREGATION.timeBucket) - ); +// return args; +// } - if (options.AGGREGATION.BUCKETTIMESTAMP) { - args.push( - 'BUCKETTIMESTAMP', - options.AGGREGATION.BUCKETTIMESTAMP - ); - } +// export type Filter = string | Array; - if (options.AGGREGATION.EMPTY) { - args.push('EMPTY'); - } - } +// export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array): RedisCommandArguments { +// args.push('FILTER'); +// return pushVariadicArguments(args, filter); +// } - return args; -} +// export interface MRangeOptions extends RangeOptions { +// GROUPBY?: MRangeGroupBy; +// } -interface MRangeGroupBy { - label: string; - reducer: TimeSeriesReducers; -} +// export function pushMRangeArguments( +// args: RedisCommandArguments, +// fromTimestamp: Timestamp, +// toTimestamp: Timestamp, +// filter: Filter, +// options?: MRangeOptions +// ): RedisCommandArguments { +// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options); +// args = pushFilterArgument(args, filter); +// return pushMRangeGroupByArguments(args, options?.GROUPBY); +// } -export function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments { - if (groupBy) { - args.push( - 'GROUPBY', - groupBy.label, - 'REDUCE', - groupBy.reducer - ); - } +// export type SelectedLabels = string | Array; - return args; -} +// export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabels?: SelectedLabels): RedisCommandArguments { +// if (!selectedLabels) { +// args.push('WITHLABELS'); +// } else { +// args.push('SELECTED_LABELS'); +// args = pushVariadicArguments(args, selectedLabels); +// } -export type Filter = string | Array; +// return args; +// } -export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array): RedisCommandArguments { - args.push('FILTER'); - return pushVariadicArguments(args, filter); -} +// export interface MRangeWithLabelsOptions extends MRangeOptions { +// SELECTED_LABELS?: SelectedLabels; +// } -export interface MRangeOptions extends RangeOptions { - GROUPBY?: MRangeGroupBy; -} +// export function pushMRangeWithLabelsArguments( +// args: RedisCommandArguments, +// fromTimestamp: Timestamp, +// toTimestamp: Timestamp, +// filter: Filter, +// options?: MRangeWithLabelsOptions +// ): RedisCommandArguments { +// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options); +// args = pushWithLabelsArgument(args, options?.SELECTED_LABELS); +// args = pushFilterArgument(args, filter); +// return pushMRangeGroupByArguments(args, options?.GROUPBY); +// } -export function pushMRangeArguments( - args: RedisCommandArguments, - fromTimestamp: Timestamp, - toTimestamp: Timestamp, - filter: Filter, - options?: MRangeOptions -): RedisCommandArguments { - args = pushRangeArguments(args, fromTimestamp, toTimestamp, options); - args = pushFilterArgument(args, filter); - return pushMRangeGroupByArguments(args, options?.GROUPBY); -} +// export function transformRangeReply(reply: Array): Array { +// return reply.map(transformSampleReply); +// } -export type SelectedLabels = string | Array; +// type MRangeRawReply = Array<[ +// key: string, +// labels: RawLabels, +// samples: Array +// ]>; -export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabels?: SelectedLabels): RedisCommandArguments { - if (!selectedLabels) { - args.push('WITHLABELS'); - } else { - args.push('SELECTED_LABELS'); - args = pushVariadicArguments(args, selectedLabels); - } +// interface MRangeReplyItem { +// key: string; +// samples: Array; +// } - return args; -} +// export function transformMRangeReply(reply: MRangeRawReply): Array { +// const args = []; -export interface MRangeWithLabelsOptions extends MRangeOptions { - SELECTED_LABELS?: SelectedLabels; -} +// for (const [key, _, sample] of reply) { +// args.push({ +// key, +// samples: sample.map(transformSampleReply) +// }); +// } -export function pushMRangeWithLabelsArguments( - args: RedisCommandArguments, - fromTimestamp: Timestamp, - toTimestamp: Timestamp, - filter: Filter, - options?: MRangeWithLabelsOptions -): RedisCommandArguments { - args = pushRangeArguments(args, fromTimestamp, toTimestamp, options); - args = pushWithLabelsArgument(args, options?.SELECTED_LABELS); - args = pushFilterArgument(args, filter); - return pushMRangeGroupByArguments(args, options?.GROUPBY); -} +// return args; +// } +// export interface MRangeWithLabelsReplyItem extends MRangeReplyItem { +// labels: Labels; +// } -export function transformRangeReply(reply: Array): Array { - return reply.map(transformSampleReply); -} +// export function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array { +// const args = []; -type MRangeRawReply = Array<[ - key: string, - labels: RawLabels, - samples: Array -]>; +// for (const [key, labels, samples] of reply) { +// args.push({ +// key, +// labels: transformLablesReply(labels), +// samples: samples.map(transformSampleReply) +// }); +// } -interface MRangeReplyItem { - key: string; - samples: Array; -} - -export function transformMRangeReply(reply: MRangeRawReply): Array { - const args = []; - - for (const [key, _, sample] of reply) { - args.push({ - key, - samples: sample.map(transformSampleReply) - }); - } - - return args; -} -export interface MRangeWithLabelsReplyItem extends MRangeReplyItem { - labels: Labels; -} - -export function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array { - const args = []; - - for (const [key, labels, samples] of reply) { - args.push({ - key, - labels: transformLablesReply(labels), - samples: samples.map(transformSampleReply) - }); - } - - return args; -} - -export function pushLatestArgument(args: RedisCommandArguments, latest?: boolean): RedisCommandArguments { - if (latest) { - args.push('LATEST'); - } - - return args; -} +// return args; +// } diff --git a/packages/time-series/lib/index.ts b/packages/time-series/lib/index.ts index 6002556ca1..e0b3c96705 100644 --- a/packages/time-series/lib/index.ts +++ b/packages/time-series/lib/index.ts @@ -1,9 +1,11 @@ export { default } from './commands'; export { - TimeSeriesDuplicatePolicies, + TIME_SERIES_ENCODING, TimeSeriesEncoding, - TimeSeriesAggregationType, - TimeSeriesReducers, - TimeSeriesBucketTimestamp + TIME_SERIES_DUPLICATE_POLICIES, + TimeSeriesDuplicatePolicies, + // TimeSeriesBucketTimestamp } from './commands'; + +export { TIME_SERIES_AGGREGATION_TYPE, TimeSeriesAggregationType } from './commands/CREATERULE'; diff --git a/packages/time-series/lib/test-utils.ts b/packages/time-series/lib/test-utils.ts index 6d534cccce..3c7fb035ae 100644 --- a/packages/time-series/lib/test-utils.ts +++ b/packages/time-series/lib/test-utils.ts @@ -2,19 +2,19 @@ import TestUtils from '@redis/test-utils'; import TimeSeries from '.'; export default new TestUtils({ - dockerImageName: 'redislabs/redistimeseries', - dockerImageVersionArgument: 'timeseries-version' + dockerImageName: 'redislabs/redistimeseries', + dockerImageVersionArgument: 'timeseries-version' }); export const GLOBAL = { - SERVERS: { - OPEN: { - serverArguments: ['--loadmodule /usr/lib/redis/modules/redistimeseries.so'], - clientOptions: { - modules: { - ts: TimeSeries - } - } + SERVERS: { + OPEN: { + serverArguments: ['--loadmodule /usr/lib/redis/modules/redistimeseries.so'], + clientOptions: { + modules: { + ts: TimeSeries } + } } + } };