Skip to content

Commit 6e60233

Browse files
committed
address leibele's comments + more time series stuff I found in process
1 parent f08e94f commit 6e60233

File tree

16 files changed

+108
-98
lines changed

16 files changed

+108
-98
lines changed

packages/json/lib/commands/TYPE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
},
1919
transformReply: {
2020
2: undefined as unknown as () => NullReply | BlobStringReply | ArrayReply<BlobStringReply>,
21-
3: undefined as unknown as () => ArrayReply<NullReply | BlobStringReply | ArrayReply<BlobStringReply>>
21+
3: undefined as unknown as () => ArrayReply<NullReply | BlobStringReply | ArrayReply<BlobStringReply | NullReply>>
2222
},
2323
unstableResp3Module: true
2424
} as const satisfies Command;

packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RedisArgument, Command, ReplyUnion } from '@redis/client/dist/lib/RESP/types';
1+
import { RedisArgument, Command, ReplyUnion, NumberReply } from '@redis/client/dist/lib/RESP/types';
22
import AGGREGATE, { AggregateRawReply, AggregateReply, FtAggregateOptions } from './AGGREGATE';
33

44
export interface FtAggregateWithCursorOptions extends FtAggregateOptions {
@@ -9,11 +9,11 @@ export interface FtAggregateWithCursorOptions extends FtAggregateOptions {
99

1010
type AggregateWithCursorRawReply = [
1111
result: AggregateRawReply,
12-
cursor: number
12+
cursor: NumberReply
1313
];
1414

1515
export interface AggregateWithCursorReply extends AggregateReply {
16-
cursor: number;
16+
cursor: NumberReply;
1717
}
1818

1919
export default {

packages/search/lib/commands/CURSOR_DEL.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { SimpleStringReply, Command, RedisArgument } from '@redis/client/dist/lib/RESP/types';
1+
import { SimpleStringReply, Command, RedisArgument, NumberReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
22

33
export default {
44
FIRST_KEY_INDEX: undefined,
55
IS_READ_ONLY: true,
6-
transformArguments(index: RedisArgument, cursorId: number) {
6+
transformArguments(index: RedisArgument, cursorId: UnwrapReply<NumberReply>) {
77
return ['FT.CURSOR', 'DEL', index, cursorId.toString()];
88
},
99
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>

packages/search/lib/commands/CURSOR_READ.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
1+
import { RedisArgument, Command, UnwrapReply, NumberReply } from '@redis/client/dist/lib/RESP/types';
22
import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
33

44
export interface FtCursorReadOptions {
@@ -8,7 +8,7 @@ export interface FtCursorReadOptions {
88
export default {
99
FIRST_KEY_INDEX: undefined,
1010
IS_READ_ONLY: true,
11-
transformArguments(index: RedisArgument, cursor: number, options?: FtCursorReadOptions) {
11+
transformArguments(index: RedisArgument, cursor: UnwrapReply<NumberReply>, options?: FtCursorReadOptions) {
1212
const args = ['FT.CURSOR', 'READ', index, cursor.toString()];
1313

1414
if (options?.COUNT !== undefined) {

packages/time-series/lib/commands/INFO.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { strict as assert } from 'node:assert';
2-
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
2+
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
33
import testUtils, { GLOBAL } from '../test-utils';
4-
import { InfoReply, transformArguments } from './INFO';
4+
import INFO, { InfoReply } from './INFO';
5+
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
56

67
describe('TS.INFO', () => {
78
it('transformArguments', () => {
89
assert.deepEqual(
9-
transformArguments('key'),
10+
INFO.transformArguments('key'),
1011
['TS.INFO', 'key']
1112
);
1213
});
@@ -15,10 +16,10 @@ describe('TS.INFO', () => {
1516
await Promise.all([
1617
client.ts.create('key', {
1718
LABELS: { id: '1' },
18-
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
19+
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.LAST
1920
}),
2021
client.ts.create('key2'),
21-
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
22+
client.ts.createRule('key', 'key2', TIME_SERIES_AGGREGATION_TYPE.COUNT, 5),
2223
client.ts.add('key', 1, 10)
2324
]);
2425

packages/time-series/lib/commands/INFO_DEBUG.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { strict as assert } from 'node:assert';
2-
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
2+
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
33
import testUtils, { GLOBAL } from '../test-utils';
44
import { assertInfo } from './INFO.spec';
5-
import { transformArguments } from './INFO_DEBUG';
5+
import INFO_DEBUG from './INFO_DEBUG';
6+
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
67

78
describe('TS.INFO_DEBUG', () => {
89
it('transformArguments', () => {
910
assert.deepEqual(
10-
transformArguments('key'),
11+
INFO_DEBUG.transformArguments('key'),
1112
['TS.INFO', 'key', 'DEBUG']
1213
);
1314
});
1415

15-
testUtils.testWithClient('client.ts.get', async client => {
16+
testUtils.testWithClient('client.ts.infoDebug', async client => {
1617
await Promise.all([
1718
client.ts.create('key', {
1819
LABELS: { id: '1' },
19-
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
20+
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.LAST
2021
}),
2122
client.ts.create('key2'),
22-
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
23+
client.ts.createRule('key', 'key2', TIME_SERIES_AGGREGATION_TYPE.COUNT, 5),
2324
client.ts.add('key', 1, 10)
2425
]);
2526

packages/time-series/lib/commands/INFO_DEBUG.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type InfoDebugRawReply = [
2020
]>
2121
];
2222

23-
interface InfoDebugReply extends InfoReply {
23+
export interface InfoDebugReply extends InfoReply {
2424
keySelfName: BlobStringReply,
2525
chunks: Array<{
2626
startTimestamp: NumberReply;
@@ -31,28 +31,27 @@ interface InfoDebugReply extends InfoReply {
3131
}>;
3232
}
3333

34-
3534
export default {
36-
FIRST_KEY_INDEX: INFO.FIRST_KEY_INDEX,
37-
IS_READ_ONLY: INFO.IS_READ_ONLY,
38-
transformArguments(key: string) {
39-
const args = INFO.transformArguments(key);
40-
args.push('DEBUG');
41-
return args;
42-
},
43-
transformReply: {
44-
2: (rawReply: InfoDebugRawReply): InfoDebugReply => {
45-
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply);
46-
(reply as InfoDebugReply).keySelfName = rawReply[25];
47-
(reply as InfoDebugReply).chunks = rawReply[27].map(chunk => ({
48-
startTimestamp: chunk[1],
49-
endTimestamp: chunk[3],
50-
samples: chunk[5],
51-
size: chunk[7],
52-
bytesPerSample: chunk[9]
53-
}));
54-
return reply as InfoDebugReply;
55-
},
56-
3: undefined as unknown as () => InfoDebugReply
57-
}
58-
} as const satisfies Command;
35+
FIRST_KEY_INDEX: INFO.FIRST_KEY_INDEX,
36+
IS_READ_ONLY: INFO.IS_READ_ONLY,
37+
transformArguments(key: string) {
38+
const args = INFO.transformArguments(key);
39+
args.push('DEBUG');
40+
return args;
41+
},
42+
transformReply: {
43+
2: (rawReply: InfoDebugRawReply): InfoDebugReply => {
44+
const reply = INFO.transformReply[2](rawReply as unknown as InfoRawReply);
45+
(reply as InfoDebugReply).keySelfName = rawReply[25];
46+
(reply as InfoDebugReply).chunks = rawReply[27].map(chunk => ({
47+
startTimestamp: chunk[1],
48+
endTimestamp: chunk[3],
49+
samples: chunk[5],
50+
size: chunk[7],
51+
bytesPerSample: chunk[9]
52+
}));
53+
return reply as InfoDebugReply;
54+
},
55+
3: undefined as unknown as () => InfoDebugReply
56+
}
57+
} as const satisfies Command;

packages/time-series/lib/commands/MGET.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommandArguments, Command } from '@redis/client/dist/lib/RESP/types';
1+
import { CommandArguments, Command, BlobStringReply, ArrayReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
22
import { RedisVariadicArgument, pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
33
import { RawLabels, SampleRawReply2, SampleRawReply3, SampleReply2, SampleReply3, transformSampleReply } from '.';
44

@@ -19,25 +19,25 @@ export function pushFilterArgument(args: CommandArguments, filter: RedisVariadic
1919
return pushVariadicArguments(args, filter);
2020
}
2121

22-
export type MGetRawReply2 = Array<[
23-
key: string,
22+
export type MGetRawReply2 = ArrayReply<[
23+
key: BlobStringReply,
2424
labels: RawLabels,
2525
sample: SampleRawReply2
2626
]>;
2727

28-
export type MGetRawReply3 = Array<[
29-
key: string,
28+
export type MGetRawReply3 = ArrayReply<[
29+
key: BlobStringReply,
3030
labels: RawLabels,
3131
sample: SampleRawReply3
3232
]>;
3333

3434
export interface MGetReply2 {
35-
key: string;
35+
key: BlobStringReply;
3636
sample: SampleReply2;
3737
}
3838

3939
export interface MGetReply3 {
40-
key: string;
40+
key: BlobStringReply;
4141
sample: SampleReply3;
4242
}
4343

@@ -49,13 +49,13 @@ export default {
4949
return pushFilterArgument(args, filter);
5050
},
5151
transformReply: {
52-
2(reply: MGetRawReply2): Array<MGetReply2> {
52+
2(reply: UnwrapReply<MGetRawReply2>): Array<MGetReply2> {
5353
return reply.map(([key, _, sample]) => ({
5454
key,
55-
sample: transformSampleReply[2](sample)
55+
sample: transformSampleReply[2](sample as unknown as UnwrapReply<SampleRawReply2>)
5656
}));
5757
},
58-
3(reply: MGetRawReply3): Array<MGetReply3> {
58+
3(reply: UnwrapReply<MGetRawReply3>): Array<MGetReply3> {
5959
return reply.map(([key, _, sample]) => ({
6060
key,
6161
sample: transformSampleReply[3](sample)

packages/time-series/lib/commands/MGET_WITHLABELS.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Command, ReplyUnion } from '@redis/client/dist/lib/RESP/types';
1+
import { Command, ReplyUnion, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
22
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
33
import { TsMGetOptions, pushLatestArgument, pushFilterArgument, MGetReply2, MGetRawReply2 } from './MGET';
4-
import { Labels, pushWithLabelsArgument, transformLablesReply, transformSampleReply } from '.';
4+
import { Labels, SampleRawReply2, pushWithLabelsArgument, transformLablesReply, transformSampleReply } from '.';
55

66
export interface TsMGetWithLabelsOptions extends TsMGetOptions {
77
SELECTED_LABELS?: RedisVariadicArgument;
@@ -20,11 +20,11 @@ export default {
2020
return pushFilterArgument(args, filter);
2121
},
2222
transformReply: {
23-
2: (reply: MGetRawReply2): Array<MGetWithLabelsReply2> => {
23+
2: (reply: UnwrapReply<MGetRawReply2>): Array<MGetWithLabelsReply2> => {
2424
return reply.map(([key, labels, sample]) => ({
2525
key,
2626
labels: transformLablesReply(labels),
27-
sample: transformSampleReply[2](sample)
27+
sample: transformSampleReply[2](sample as unknown as UnwrapReply<SampleRawReply2>)
2828
}));
2929
},
3030
3: undefined as unknown as () => ReplyUnion

packages/time-series/lib/commands/MRANGE.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { strict as assert } from 'node:assert';
22
import testUtils, { GLOBAL } from '../test-utils';
3-
import MRANGE from './MRANGE';
4-
import { TimeSeriesAggregationType, TimeSeriesReducers } from '.';
3+
import MRANGE, { TIME_SERIES_REDUCERS } from './MRANGE';
4+
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
55

66
describe('TS.MRANGE', () => {
77
it('transformArguments', () => {
@@ -15,12 +15,12 @@ describe('TS.MRANGE', () => {
1515
COUNT: 1,
1616
ALIGN: '-',
1717
AGGREGATION: {
18-
type: TimeSeriesAggregationType.AVERAGE,
18+
type: TIME_SERIES_AGGREGATION_TYPE.AVG,
1919
timeBucket: 1
2020
},
2121
GROUPBY: {
2222
label: 'label',
23-
reducer: TimeSeriesReducers.SUM
23+
reducer: TIME_SERIES_REDUCERS.SUM
2424
},
2525
}),
2626
[

0 commit comments

Comments
 (0)