@upstash/redis 0.0.0-ci.b1b216d3-20230414 → 0.0.0-ci.b3f07153-20231018
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/esm/pkg/commands/geo_add.js +27 -0
- package/esm/pkg/commands/geo_dist.js +11 -0
- package/esm/pkg/commands/hgetall.js +9 -1
- package/esm/pkg/commands/mod.js +5 -0
- package/esm/pkg/commands/set.js +1 -1
- package/esm/pkg/commands/xadd.js +26 -0
- package/esm/pkg/commands/xrange.js +36 -0
- package/esm/pkg/commands/zunion.js +30 -0
- package/esm/pkg/http.js +16 -9
- package/esm/pkg/pipeline.js +32 -8
- package/esm/pkg/redis.js +36 -1
- package/esm/platforms/nodejs.js +4 -2
- package/esm/version.js +1 -1
- package/package.json +13 -5
- package/script/pkg/commands/geo_add.js +31 -0
- package/script/pkg/commands/geo_dist.js +15 -0
- package/script/pkg/commands/hgetall.js +9 -1
- package/script/pkg/commands/mod.js +5 -0
- package/script/pkg/commands/set.js +1 -1
- package/script/pkg/commands/xadd.js +30 -0
- package/script/pkg/commands/xrange.js +40 -0
- package/script/pkg/commands/zunion.js +34 -0
- package/script/pkg/http.js +16 -9
- package/script/pkg/pipeline.js +31 -7
- package/script/pkg/redis.js +35 -0
- package/script/platforms/nodejs.js +4 -2
- package/script/version.js +1 -1
- package/types/pkg/commands/geo_add.d.ts +25 -0
- package/types/pkg/commands/geo_dist.d.ts +12 -0
- package/types/pkg/commands/hdel.d.ts +1 -1
- package/types/pkg/commands/mod.d.ts +5 -0
- package/types/pkg/commands/set.d.ts +2 -2
- package/types/pkg/commands/xadd.d.ts +31 -0
- package/types/pkg/commands/xrange.d.ts +9 -0
- package/types/pkg/commands/zunion.d.ts +29 -0
- package/types/pkg/http.d.ts +5 -1
- package/types/pkg/pipeline.d.ts +241 -150
- package/types/pkg/redis.d.ts +42 -4
- package/types/version.d.ts +1 -1
package/script/pkg/http.js
CHANGED
|
@@ -103,10 +103,17 @@ class HttpClient {
|
|
|
103
103
|
}
|
|
104
104
|
const body = (await res.json());
|
|
105
105
|
if (!res.ok) {
|
|
106
|
-
throw new error_js_1.UpstashError(body.error);
|
|
106
|
+
throw new error_js_1.UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`);
|
|
107
107
|
}
|
|
108
108
|
if (this.options?.responseEncoding === "base64") {
|
|
109
|
-
|
|
109
|
+
if (Array.isArray(body)) {
|
|
110
|
+
return body.map(({ result, error }) => ({
|
|
111
|
+
result: decode(result),
|
|
112
|
+
error,
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
const result = decode(body.result);
|
|
116
|
+
return { result, error: body.error };
|
|
110
117
|
}
|
|
111
118
|
return body;
|
|
112
119
|
}
|
|
@@ -138,19 +145,19 @@ function base64decode(b64) {
|
|
|
138
145
|
}
|
|
139
146
|
function decode(raw) {
|
|
140
147
|
let result = undefined;
|
|
141
|
-
switch (typeof raw
|
|
148
|
+
switch (typeof raw) {
|
|
142
149
|
case "undefined":
|
|
143
150
|
return raw;
|
|
144
151
|
case "number": {
|
|
145
|
-
result = raw
|
|
152
|
+
result = raw;
|
|
146
153
|
break;
|
|
147
154
|
}
|
|
148
155
|
case "object": {
|
|
149
|
-
if (Array.isArray(raw
|
|
150
|
-
result = raw.
|
|
156
|
+
if (Array.isArray(raw)) {
|
|
157
|
+
result = raw.map((v) => typeof v === "string"
|
|
151
158
|
? base64decode(v)
|
|
152
159
|
: Array.isArray(v)
|
|
153
|
-
? v.map(
|
|
160
|
+
? v.map(decode)
|
|
154
161
|
: v);
|
|
155
162
|
}
|
|
156
163
|
else {
|
|
@@ -161,11 +168,11 @@ function decode(raw) {
|
|
|
161
168
|
break;
|
|
162
169
|
}
|
|
163
170
|
case "string": {
|
|
164
|
-
result = raw
|
|
171
|
+
result = raw === "OK" ? "OK" : base64decode(raw);
|
|
165
172
|
break;
|
|
166
173
|
}
|
|
167
174
|
default:
|
|
168
175
|
break;
|
|
169
176
|
}
|
|
170
|
-
return
|
|
177
|
+
return result;
|
|
171
178
|
}
|
package/script/pkg/pipeline.js
CHANGED
|
@@ -34,7 +34,7 @@ const zdiffstore_js_1 = require("./commands/zdiffstore.js");
|
|
|
34
34
|
* const res = await p.set("key","value").get("key").exec()
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* Return types are inferred if all commands are chained, but you can still
|
|
38
38
|
* override the response type manually:
|
|
39
39
|
* ```ts
|
|
40
40
|
* redis.pipeline()
|
|
@@ -75,9 +75,11 @@ class Pipeline {
|
|
|
75
75
|
*
|
|
76
76
|
* Returns an array with the results of all pipelined commands.
|
|
77
77
|
*
|
|
78
|
-
* You can define a return type manually
|
|
78
|
+
* If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:
|
|
79
79
|
* ```ts
|
|
80
|
-
* redis.pipeline()
|
|
80
|
+
* const p = redis.pipeline()
|
|
81
|
+
* p.get("key")
|
|
82
|
+
* const result = p.exec<[{ greeting: string }]>()
|
|
81
83
|
* ```
|
|
82
84
|
*/
|
|
83
85
|
Object.defineProperty(this, "exec", {
|
|
@@ -1186,24 +1188,38 @@ class Pipeline {
|
|
|
1186
1188
|
writable: true,
|
|
1187
1189
|
value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
|
|
1188
1190
|
});
|
|
1191
|
+
/**
|
|
1192
|
+
* @see https://redis.io/commands/zunion
|
|
1193
|
+
*/
|
|
1194
|
+
Object.defineProperty(this, "zunion", {
|
|
1195
|
+
enumerable: true,
|
|
1196
|
+
configurable: true,
|
|
1197
|
+
writable: true,
|
|
1198
|
+
value: (...args) => this.chain(new mod_js_1.ZUnionCommand(args, this.commandOptions))
|
|
1199
|
+
});
|
|
1189
1200
|
this.client = opts.client;
|
|
1190
|
-
this.commands = [];
|
|
1201
|
+
this.commands = []; // the TCommands generic in the class definition is only used for carrying through chained command types and should never be explicitly set when instantiating the class
|
|
1191
1202
|
this.commandOptions = opts.commandOptions;
|
|
1192
1203
|
this.multiExec = opts.multiExec ?? false;
|
|
1193
1204
|
}
|
|
1194
1205
|
/**
|
|
1195
|
-
*
|
|
1206
|
+
* Returns the length of pipeline before the execution
|
|
1207
|
+
*/
|
|
1208
|
+
length() {
|
|
1209
|
+
return this.commands.length;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Pushes a command into the pipeline and returns a chainable instance of the
|
|
1196
1213
|
* pipeline
|
|
1197
1214
|
*/
|
|
1198
1215
|
chain(command) {
|
|
1199
1216
|
this.commands.push(command);
|
|
1200
|
-
return this;
|
|
1217
|
+
return this; // TS thinks we're returning Pipeline<[]> here, because we're not creating a new instance of the class, hence the cast
|
|
1201
1218
|
}
|
|
1202
1219
|
/**
|
|
1203
1220
|
* @see https://redis.io/commands/?group=json
|
|
1204
1221
|
*/
|
|
1205
1222
|
get json() {
|
|
1206
|
-
// For some reason we needed to define the types manually, otherwise Deno wouldn't build it
|
|
1207
1223
|
return {
|
|
1208
1224
|
/**
|
|
1209
1225
|
* @see https://redis.io/commands/json.arrappend
|
|
@@ -1241,6 +1257,14 @@ class Pipeline {
|
|
|
1241
1257
|
* @see https://redis.io/commands/json.forget
|
|
1242
1258
|
*/
|
|
1243
1259
|
forget: (...args) => this.chain(new mod_js_1.JsonForgetCommand(args, this.commandOptions)),
|
|
1260
|
+
/**
|
|
1261
|
+
* @see https://redis.io/commands/geoadd
|
|
1262
|
+
*/
|
|
1263
|
+
geoadd: (...args) => new mod_js_1.GeoAddCommand(args, this.commandOptions).exec(this.client),
|
|
1264
|
+
/**
|
|
1265
|
+
* @see https://redis.io/commands/geodist
|
|
1266
|
+
*/
|
|
1267
|
+
geodist: (...args) => new mod_js_1.GeoDistCommand(args, this.commandOptions).exec(this.client),
|
|
1244
1268
|
/**
|
|
1245
1269
|
* @see https://redis.io/commands/json.get
|
|
1246
1270
|
*/
|
package/script/pkg/redis.js
CHANGED
|
@@ -1008,6 +1008,24 @@ class Redis {
|
|
|
1008
1008
|
writable: true,
|
|
1009
1009
|
value: (...args) => new mod_js_1.UnlinkCommand(args, this.opts).exec(this.client)
|
|
1010
1010
|
});
|
|
1011
|
+
/**
|
|
1012
|
+
* @see https://redis.io/commands/xadd
|
|
1013
|
+
*/
|
|
1014
|
+
Object.defineProperty(this, "xadd", {
|
|
1015
|
+
enumerable: true,
|
|
1016
|
+
configurable: true,
|
|
1017
|
+
writable: true,
|
|
1018
|
+
value: (...args) => new mod_js_1.XAddCommand(args, this.opts).exec(this.client)
|
|
1019
|
+
});
|
|
1020
|
+
/**
|
|
1021
|
+
* @see https://redis.io/commands/xrange
|
|
1022
|
+
*/
|
|
1023
|
+
Object.defineProperty(this, "xrange", {
|
|
1024
|
+
enumerable: true,
|
|
1025
|
+
configurable: true,
|
|
1026
|
+
writable: true,
|
|
1027
|
+
value: (...args) => new mod_js_1.XRangeCommand(args, this.opts).exec(this.client)
|
|
1028
|
+
});
|
|
1011
1029
|
/**
|
|
1012
1030
|
* @see https://redis.io/commands/zadd
|
|
1013
1031
|
*/
|
|
@@ -1184,6 +1202,15 @@ class Redis {
|
|
|
1184
1202
|
writable: true,
|
|
1185
1203
|
value: (key, member) => new mod_js_1.ZScoreCommand([key, member], this.opts).exec(this.client)
|
|
1186
1204
|
});
|
|
1205
|
+
/**
|
|
1206
|
+
* @see https://redis.io/commands/zunion
|
|
1207
|
+
*/
|
|
1208
|
+
Object.defineProperty(this, "zunion", {
|
|
1209
|
+
enumerable: true,
|
|
1210
|
+
configurable: true,
|
|
1211
|
+
writable: true,
|
|
1212
|
+
value: (...args) => new mod_js_1.ZUnionCommand(args, this.opts).exec(this.client)
|
|
1213
|
+
});
|
|
1187
1214
|
/**
|
|
1188
1215
|
* @see https://redis.io/commands/zunionstore
|
|
1189
1216
|
*/
|
|
@@ -1235,6 +1262,14 @@ class Redis {
|
|
|
1235
1262
|
* @see https://redis.io/commands/json.forget
|
|
1236
1263
|
*/
|
|
1237
1264
|
forget: (...args) => new mod_js_1.JsonForgetCommand(args, this.opts).exec(this.client),
|
|
1265
|
+
/**
|
|
1266
|
+
* @see https://redis.io/commands/geoadd
|
|
1267
|
+
*/
|
|
1268
|
+
geoadd: (...args) => new mod_js_1.GeoAddCommand(args, this.opts).exec(this.client),
|
|
1269
|
+
/**
|
|
1270
|
+
* @see https://redis.io/commands/geodist
|
|
1271
|
+
*/
|
|
1272
|
+
geodist: (...args) => new mod_js_1.GeoDistCommand(args, this.opts).exec(this.client),
|
|
1238
1273
|
/**
|
|
1239
1274
|
* @see https://redis.io/commands/json.get
|
|
1240
1275
|
*/
|
|
@@ -61,14 +61,16 @@ class Redis extends core.Redis {
|
|
|
61
61
|
headers: { authorization: `Bearer ${configOrRequester.token}` },
|
|
62
62
|
agent: configOrRequester.agent,
|
|
63
63
|
responseEncoding: configOrRequester.responseEncoding,
|
|
64
|
-
cache: "no-store",
|
|
64
|
+
cache: configOrRequester.cache || "no-store",
|
|
65
65
|
});
|
|
66
66
|
super(client, {
|
|
67
67
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
68
68
|
enableTelemetry: !process.env.UPSTASH_DISABLE_TELEMETRY,
|
|
69
69
|
});
|
|
70
70
|
this.addTelemetry({
|
|
71
|
-
runtime:
|
|
71
|
+
runtime: typeof EdgeRuntime === "string"
|
|
72
|
+
? "edge-light"
|
|
73
|
+
: `node@${process.version}`,
|
|
72
74
|
platform: process.env.VERCEL
|
|
73
75
|
? "vercel"
|
|
74
76
|
: process.env.AWS_REGION
|
package/script/version.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
export type GeoAddCommandOptions = {
|
|
3
|
+
nx?: boolean;
|
|
4
|
+
xx?: never;
|
|
5
|
+
} | ({
|
|
6
|
+
nx?: never;
|
|
7
|
+
xx?: boolean;
|
|
8
|
+
} & {
|
|
9
|
+
ch?: boolean;
|
|
10
|
+
});
|
|
11
|
+
export interface GeoMember<TMemberType> {
|
|
12
|
+
latitude: number;
|
|
13
|
+
longitude: number;
|
|
14
|
+
member: TMemberType;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @see https://redis.io/commands/geoadd
|
|
18
|
+
*/
|
|
19
|
+
export declare class GeoAddCommand<TMemberType = string> extends Command<number | null, number | null> {
|
|
20
|
+
constructor([key, arg1, ...arg2]: [
|
|
21
|
+
string,
|
|
22
|
+
GeoMember<TMemberType> | GeoAddCommandOptions,
|
|
23
|
+
...GeoMember<TMemberType>[]
|
|
24
|
+
], opts?: CommandOptions<number | null, number | null>);
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/geodist
|
|
4
|
+
*/
|
|
5
|
+
export declare class GeoDistCommand extends Command<number | null, number | null> {
|
|
6
|
+
constructor([key, member1, member2, unit]: [
|
|
7
|
+
key: string,
|
|
8
|
+
member1: string,
|
|
9
|
+
member2: string,
|
|
10
|
+
unit?: "M" | "KM" | "FT" | "MI"
|
|
11
|
+
], opts?: CommandOptions<number | null, number | null>);
|
|
12
|
+
}
|
|
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
|
|
|
3
3
|
* @see https://redis.io/commands/hdel
|
|
4
4
|
*/
|
|
5
5
|
export declare class HDelCommand extends Command<"0" | "1", 0 | 1> {
|
|
6
|
-
constructor(cmd: [key: string,
|
|
6
|
+
constructor(cmd: [key: string, ...fields: string[]], opts?: CommandOptions<"0" | "1", 0 | 1>);
|
|
7
7
|
}
|
|
@@ -15,6 +15,8 @@ export * from "./expire.js";
|
|
|
15
15
|
export * from "./expireat.js";
|
|
16
16
|
export * from "./flushall.js";
|
|
17
17
|
export * from "./flushdb.js";
|
|
18
|
+
export * from "./geo_add.js";
|
|
19
|
+
export * from "./geo_dist.js";
|
|
18
20
|
export * from "./get.js";
|
|
19
21
|
export * from "./getbit.js";
|
|
20
22
|
export * from "./getdel.js";
|
|
@@ -137,4 +139,7 @@ export * from "./zremrangebyscore.js";
|
|
|
137
139
|
export * from "./zrevrank.js";
|
|
138
140
|
export * from "./zscan.js";
|
|
139
141
|
export * from "./zscore.js";
|
|
142
|
+
export * from "./zunion.js";
|
|
140
143
|
export * from "./zunionstore.js";
|
|
144
|
+
export * from "./xadd.js";
|
|
145
|
+
export * from "./xrange.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
type XAddCommandOptions = {
|
|
3
|
+
nomkStream?: boolean;
|
|
4
|
+
trim?: ({
|
|
5
|
+
type: "MAXLEN" | "maxlen";
|
|
6
|
+
threshold: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: "MINID" | "minid";
|
|
9
|
+
threshold: string;
|
|
10
|
+
}) & ({
|
|
11
|
+
comparison: "~";
|
|
12
|
+
limit?: number;
|
|
13
|
+
} | {
|
|
14
|
+
comparison: "=";
|
|
15
|
+
limit?: never;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @see https://redis.io/commands/xadd
|
|
20
|
+
*/
|
|
21
|
+
export declare class XAddCommand extends Command<string, string> {
|
|
22
|
+
constructor([key, id, entries, opts]: [
|
|
23
|
+
key: string,
|
|
24
|
+
id: "*" | string,
|
|
25
|
+
entries: {
|
|
26
|
+
[field: string]: unknown;
|
|
27
|
+
},
|
|
28
|
+
opts?: XAddCommandOptions
|
|
29
|
+
], commandOptions?: CommandOptions<string, string>);
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
export declare class XRangeCommand<TData extends Record<string, Record<string, unknown>>> extends Command<string[][], TData> {
|
|
3
|
+
constructor([key, start, end, count]: [
|
|
4
|
+
key: string,
|
|
5
|
+
start: string,
|
|
6
|
+
end: string,
|
|
7
|
+
count?: number
|
|
8
|
+
], opts?: CommandOptions<unknown[], TData[]>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
export type ZUnionCommandOptions = {
|
|
3
|
+
withScores?: boolean;
|
|
4
|
+
aggregate?: "sum" | "min" | "max";
|
|
5
|
+
} & ({
|
|
6
|
+
weight: number;
|
|
7
|
+
weights?: never;
|
|
8
|
+
} | {
|
|
9
|
+
weight?: never;
|
|
10
|
+
weights: number[];
|
|
11
|
+
} | {
|
|
12
|
+
weight?: never;
|
|
13
|
+
weights?: never;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* @see https://redis.io/commands/zunion
|
|
17
|
+
*/
|
|
18
|
+
export declare class ZUnionCommand<TData extends unknown[]> extends Command<string[], TData> {
|
|
19
|
+
constructor(cmd: [
|
|
20
|
+
numKeys: 1,
|
|
21
|
+
key: string,
|
|
22
|
+
opts?: ZUnionCommandOptions
|
|
23
|
+
], cmdOpts?: CommandOptions<string[], TData>);
|
|
24
|
+
constructor(cmd: [
|
|
25
|
+
numKeys: number,
|
|
26
|
+
keys: string[],
|
|
27
|
+
opts?: ZUnionCommandOptions
|
|
28
|
+
], cmdOpts?: CommandOptions<string[], TData>);
|
|
29
|
+
}
|
package/types/pkg/http.d.ts
CHANGED
|
@@ -62,6 +62,11 @@ export type RequesterConfig = {
|
|
|
62
62
|
* @default "base64"
|
|
63
63
|
*/
|
|
64
64
|
responseEncoding?: false | "base64";
|
|
65
|
+
/**
|
|
66
|
+
* Configure the cache behaviour
|
|
67
|
+
* @default "no-store"
|
|
68
|
+
*/
|
|
69
|
+
cache?: CacheSetting;
|
|
65
70
|
};
|
|
66
71
|
export type HttpClientConfig = {
|
|
67
72
|
headers?: Record<string, string>;
|
|
@@ -69,7 +74,6 @@ export type HttpClientConfig = {
|
|
|
69
74
|
options?: Options;
|
|
70
75
|
retry?: RetryConfig;
|
|
71
76
|
agent?: any;
|
|
72
|
-
cache?: CacheSetting;
|
|
73
77
|
} & RequesterConfig;
|
|
74
78
|
export declare class HttpClient implements Requester {
|
|
75
79
|
baseUrl: string;
|