@upstash/redis 1.0.0 → 1.0.3

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.
@@ -0,0 +1,158 @@
1
+ import { HttpClient } from './http';
2
+
3
+ /**
4
+ * Command offers default (de)serialization and the exec method to all commands.
5
+ *
6
+ * TData represents what the user will enter or receive,
7
+ * TResult is the raw data returned from upstash, which may need to be transformed or parsed.
8
+ */
9
+ declare class Command<TData, TResult> {
10
+ readonly command: string[];
11
+ deserialize: (result: TResult) => TData;
12
+ /**
13
+ * Create a new command instance.
14
+ *
15
+ * You can define a custom `deserialize` function. By default we try to deserialize as json.
16
+ */
17
+ constructor(command: (string | unknown)[], opts?: {
18
+ deserialize?: (result: TResult) => TData;
19
+ });
20
+ /**
21
+ * Execute the command using a client.
22
+ */
23
+ exec(client: HttpClient): Promise<TData>;
24
+ }
25
+
26
+ declare type NonEmptyArray<T> = [T, ...T[]];
27
+ declare type CommandArgs<TCommand extends new (...args: any) => any> = ConstructorParameters<TCommand>;
28
+
29
+ declare type ScanCommandOptions = {
30
+ match?: string;
31
+ count?: number;
32
+ };
33
+ /**
34
+ * @see https://redis.io/commands/scan
35
+ */
36
+ declare class ScanCommand extends Command<[number, string[]], [number, string[]]> {
37
+ constructor(cursor: number, opts?: ScanCommandOptions);
38
+ }
39
+
40
+ declare type SetCommandOptions = ({
41
+ ex: number;
42
+ px?: never;
43
+ } | {
44
+ ex?: never;
45
+ px: number;
46
+ } | {
47
+ ex?: never;
48
+ px?: never;
49
+ }) & ({
50
+ nx: true;
51
+ xx?: never;
52
+ } | {
53
+ xx: true;
54
+ nx?: never;
55
+ } | {
56
+ xx?: never;
57
+ nx?: never;
58
+ });
59
+ /**
60
+ * @see https://redis.io/commands/set
61
+ */
62
+ declare class SetCommand<TData, TResult = "OK"> extends Command<TData, TResult> {
63
+ constructor(key: string, value: TData, opts?: SetCommandOptions);
64
+ }
65
+
66
+ declare type Type = "string" | "list" | "set" | "zset" | "hash" | "none";
67
+ /**
68
+ * @see https://redis.io/commands/type
69
+ */
70
+ declare class TypeCommand extends Command<Type, Type> {
71
+ constructor(key: string);
72
+ }
73
+
74
+ /**
75
+ * @see https://redis.io/commands/unlink
76
+ */
77
+ declare class UnlinkCommand extends Command<number, number> {
78
+ constructor(...keys: string[]);
79
+ }
80
+
81
+ declare type ZAddCommandOptions = ({
82
+ nx: true;
83
+ xx?: never;
84
+ } | {
85
+ nx?: never;
86
+ xx: true;
87
+ } | {
88
+ nx?: never;
89
+ xx?: never;
90
+ }) & {
91
+ ch?: true;
92
+ };
93
+ declare type ZAddCommandOptionsWithIncr = ZAddCommandOptions & {
94
+ incr: true;
95
+ };
96
+ declare type ScoreMember<TData> = {
97
+ score: number;
98
+ member: TData;
99
+ };
100
+ /**
101
+ * @see https://redis.io/commands/zadd
102
+ */
103
+ declare class ZAddCommand<TData = string> extends Command<number | null, number | null> {
104
+ constructor(key: string, scoreMember: ScoreMember<TData>, ...scoreMemberPairs: ScoreMember<TData>[]);
105
+ constructor(key: string, opts: ZAddCommandOptions | ZAddCommandOptionsWithIncr, ...scoreMemberPairs: [ScoreMember<TData>, ...ScoreMember<TData>[]]);
106
+ }
107
+
108
+ declare type ZInterStoreCommandOptions = {
109
+ aggregate?: "sum" | "min" | "max";
110
+ } & ({
111
+ weight: number;
112
+ weights?: never;
113
+ } | {
114
+ weight?: never;
115
+ weights: number[];
116
+ } | {
117
+ weight?: never;
118
+ weights?: never;
119
+ });
120
+ /**
121
+ * @see https://redis.io/commands/zInterstore
122
+ */
123
+ declare class ZInterStoreCommand extends Command<number, number> {
124
+ constructor(destination: string, numKeys: 1, key: string, opts?: ZInterStoreCommandOptions);
125
+ constructor(destination: string, numKeys: number, keys: string[], opts?: ZInterStoreCommandOptions);
126
+ }
127
+
128
+ declare type ZRangeCommandOptions = {
129
+ withScores?: boolean;
130
+ };
131
+ /**
132
+ * @see https://redis.io/commands/zrange
133
+ */
134
+ declare class ZRangeCommand<TData extends unknown[]> extends Command<TData, string[]> {
135
+ constructor(key: string, min: number | `(${number}`, max: number | `(${number}`, opts?: ZRangeCommandOptions);
136
+ }
137
+
138
+ declare type ZUnionStoreCommandOptions = {
139
+ aggregate?: "sum" | "min" | "max";
140
+ } & ({
141
+ weight: number;
142
+ weights?: never;
143
+ } | {
144
+ weight?: never;
145
+ weights: number[];
146
+ } | {
147
+ weight?: never;
148
+ weights?: never;
149
+ });
150
+ /**
151
+ * @see https://redis.io/commands/zunionstore
152
+ */
153
+ declare class ZUnionStoreCommand extends Command<number, number> {
154
+ constructor(destination: string, numKeys: 1, key: string, opts?: ZUnionStoreCommandOptions);
155
+ constructor(destination: string, numKeys: number, keys: string[], opts?: ZUnionStoreCommandOptions);
156
+ }
157
+
158
+ export { CommandArgs as C, NonEmptyArray as N, ScanCommandOptions as S, Type as T, UnlinkCommand as U, ZAddCommandOptions as Z, SetCommandOptions as a, ScoreMember as b, ZAddCommandOptionsWithIncr as c, ZInterStoreCommandOptions as d, ZRangeCommandOptions as e, ZUnionStoreCommandOptions as f, Command as g, ScanCommand as h, SetCommand as i, TypeCommand as j, ZAddCommand as k, ZInterStoreCommand as l, ZRangeCommand as m, ZUnionStoreCommand as n };