@upstash/redis 0.0.0-ci.9cbc6e25-20230504 → 0.0.0-ci.9d88b94d-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.
Files changed (38) hide show
  1. package/esm/pkg/commands/geo_add.js +27 -0
  2. package/esm/pkg/commands/geo_pos.js +26 -0
  3. package/esm/pkg/commands/hgetall.js +9 -1
  4. package/esm/pkg/commands/mod.js +5 -0
  5. package/esm/pkg/commands/set.js +1 -1
  6. package/esm/pkg/commands/xadd.js +26 -0
  7. package/esm/pkg/commands/xrange.js +36 -0
  8. package/esm/pkg/commands/zunion.js +30 -0
  9. package/esm/pkg/http.js +16 -9
  10. package/esm/pkg/pipeline.js +28 -8
  11. package/esm/pkg/redis.js +36 -1
  12. package/esm/platforms/nodejs.js +1 -1
  13. package/esm/version.js +1 -1
  14. package/package.json +13 -5
  15. package/script/pkg/commands/geo_add.js +31 -0
  16. package/script/pkg/commands/geo_pos.js +30 -0
  17. package/script/pkg/commands/hgetall.js +9 -1
  18. package/script/pkg/commands/mod.js +5 -0
  19. package/script/pkg/commands/set.js +1 -1
  20. package/script/pkg/commands/xadd.js +30 -0
  21. package/script/pkg/commands/xrange.js +40 -0
  22. package/script/pkg/commands/zunion.js +34 -0
  23. package/script/pkg/http.js +16 -9
  24. package/script/pkg/pipeline.js +27 -7
  25. package/script/pkg/redis.js +35 -0
  26. package/script/platforms/nodejs.js +1 -1
  27. package/script/version.js +1 -1
  28. package/types/pkg/commands/geo_add.d.ts +25 -0
  29. package/types/pkg/commands/geo_pos.d.ts +12 -0
  30. package/types/pkg/commands/mod.d.ts +5 -0
  31. package/types/pkg/commands/set.d.ts +2 -2
  32. package/types/pkg/commands/xadd.d.ts +31 -0
  33. package/types/pkg/commands/xrange.d.ts +9 -0
  34. package/types/pkg/commands/zunion.d.ts +29 -0
  35. package/types/pkg/http.d.ts +5 -1
  36. package/types/pkg/pipeline.d.ts +237 -150
  37. package/types/pkg/redis.d.ts +40 -3
  38. package/types/version.d.ts +1 -1
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZUnionCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/zunion
7
+ */
8
+ class ZUnionCommand extends command_js_1.Command {
9
+ constructor([numKeys, keyOrKeys, opts], cmdOpts) {
10
+ const command = ["zunion", numKeys];
11
+ if (Array.isArray(keyOrKeys)) {
12
+ command.push(...keyOrKeys);
13
+ }
14
+ else {
15
+ command.push(keyOrKeys);
16
+ }
17
+ if (opts) {
18
+ if ("weights" in opts && opts.weights) {
19
+ command.push("weights", ...opts.weights);
20
+ }
21
+ else if ("weight" in opts && typeof opts.weight === "number") {
22
+ command.push("weights", opts.weight);
23
+ }
24
+ if ("aggregate" in opts) {
25
+ command.push("aggregate", opts.aggregate);
26
+ }
27
+ if (opts?.withScores) {
28
+ command.push("withscores");
29
+ }
30
+ }
31
+ super(command, cmdOpts);
32
+ }
33
+ }
34
+ exports.ZUnionCommand = ZUnionCommand;
@@ -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
- return Array.isArray(body) ? body.map(decode) : decode(body);
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.result) {
148
+ switch (typeof raw) {
142
149
  case "undefined":
143
150
  return raw;
144
151
  case "number": {
145
- result = raw.result;
152
+ result = raw;
146
153
  break;
147
154
  }
148
155
  case "object": {
149
- if (Array.isArray(raw.result)) {
150
- result = raw.result.map((v) => typeof v === "string"
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(base64decode)
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.result === "OK" ? "OK" : base64decode(raw.result);
171
+ result = raw === "OK" ? "OK" : base64decode(raw);
165
172
  break;
166
173
  }
167
174
  default:
168
175
  break;
169
176
  }
170
- return { result, error: raw.error };
177
+ return result;
171
178
  }
@@ -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
- * It's not possible to infer correct types with a dynamic pipeline, so you can
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 to make working in typescript easier
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().get("key").exec<[{ greeting: string }]>()
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
- * Pushes a command into the pipelien and returns a chainable instance of the
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,10 @@ 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/geopos
1262
+ */
1263
+ geopos: (...args) => new mod_js_1.GeoPosCommand(args, this.commandOptions).exec(this.client),
1244
1264
  /**
1245
1265
  * @see https://redis.io/commands/json.get
1246
1266
  */
@@ -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/geopos
1271
+ */
1272
+ geopos: (...args) => new mod_js_1.GeoPosCommand(args, this.opts).exec(this.client),
1238
1273
  /**
1239
1274
  * @see https://redis.io/commands/json.get
1240
1275
  */
@@ -61,7 +61,7 @@ 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,
package/script/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "v0.0.0-ci.9cbc6e25-20230504";
4
+ exports.VERSION = "v0.0.0-ci.9d88b94d-20231018";
@@ -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
+ type Coordinates = {
3
+ lng: string;
4
+ lat: string;
5
+ };
6
+ /**
7
+ * @see https://redis.io/commands/geopos
8
+ */
9
+ export declare class GeoPosCommand<TData extends Coordinates[]> extends Command<(string | null)[][], TData> {
10
+ constructor(cmd: [string, ...string[]] | [string, string[]], opts?: CommandOptions<(string | null)[][], TData>);
11
+ }
12
+ export {};
@@ -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_pos.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";
@@ -1,7 +1,7 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
2
  export type SetCommandOptions = {
3
- get: boolean;
4
- } | ({
3
+ get?: boolean;
4
+ } & ({
5
5
  ex: number;
6
6
  px?: never;
7
7
  exat?: never;
@@ -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
+ }
@@ -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;