@upstash/redis 1.22.0 → 1.23.0-next.1

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.
@@ -120,6 +120,7 @@ export * from "./touch.js";
120
120
  export * from "./ttl.js";
121
121
  export * from "./type.js";
122
122
  export * from "./unlink.js";
123
+ export * from "./xadd.js";
123
124
  export * from "./zadd.js";
124
125
  export * from "./zcard.js";
125
126
  export * from "./zcount.js";
@@ -28,7 +28,7 @@ export class SetCommand extends Command {
28
28
  command.push("pxat", opts.pxat);
29
29
  }
30
30
  else if ("keepTtl" in opts && opts.keepTtl) {
31
- command.push("keepTtl", opts.keepTtl);
31
+ command.push("keepTtl");
32
32
  }
33
33
  }
34
34
  super(command, cmdOpts);
@@ -0,0 +1,26 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/xadd
4
+ */
5
+ export class XAddCommand extends Command {
6
+ constructor([key, id, entries, opts], commandOptions) {
7
+ const command = ["XADD", key];
8
+ if (opts) {
9
+ if (opts.nomkStream) {
10
+ command.push("NOMKSTREAM");
11
+ }
12
+ if (opts.trim) {
13
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
14
+ if (typeof opts.trim.limit !== "undefined") {
15
+ command.push("LIMIT", opts.trim.limit);
16
+ }
17
+ }
18
+ }
19
+ command.push(id);
20
+ // entries
21
+ Object.entries(entries).forEach(([k, v]) => {
22
+ command.push(k, v);
23
+ });
24
+ super(command, commandOptions);
25
+ }
26
+ }
package/esm/pkg/http.js CHANGED
@@ -100,10 +100,17 @@ export class HttpClient {
100
100
  }
101
101
  const body = (await res.json());
102
102
  if (!res.ok) {
103
- throw new UpstashError(body.error);
103
+ throw new UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`);
104
104
  }
105
105
  if (this.options?.responseEncoding === "base64") {
106
- return Array.isArray(body) ? body.map(decode) : decode(body);
106
+ if (Array.isArray(body)) {
107
+ return body.map(({ result, error }) => ({
108
+ result: decode(result),
109
+ error,
110
+ }));
111
+ }
112
+ const result = decode(body.result);
113
+ return { result, error: body.error };
107
114
  }
108
115
  return body;
109
116
  }
@@ -134,19 +141,19 @@ function base64decode(b64) {
134
141
  }
135
142
  function decode(raw) {
136
143
  let result = undefined;
137
- switch (typeof raw.result) {
144
+ switch (typeof raw) {
138
145
  case "undefined":
139
146
  return raw;
140
147
  case "number": {
141
- result = raw.result;
148
+ result = raw;
142
149
  break;
143
150
  }
144
151
  case "object": {
145
- if (Array.isArray(raw.result)) {
146
- result = raw.result.map((v) => typeof v === "string"
152
+ if (Array.isArray(raw)) {
153
+ result = raw.map((v) => typeof v === "string"
147
154
  ? base64decode(v)
148
155
  : Array.isArray(v)
149
- ? v.map(base64decode)
156
+ ? v.map(decode)
150
157
  : v);
151
158
  }
152
159
  else {
@@ -157,11 +164,11 @@ function decode(raw) {
157
164
  break;
158
165
  }
159
166
  case "string": {
160
- result = raw.result === "OK" ? "OK" : base64decode(raw.result);
167
+ result = raw === "OK" ? "OK" : base64decode(raw);
161
168
  break;
162
169
  }
163
170
  default:
164
171
  break;
165
172
  }
166
- return { result, error: raw.error };
173
+ return result;
167
174
  }
@@ -92,6 +92,7 @@ export class Pipeline {
92
92
  path,
93
93
  body: Object.values(this.commands).map((c) => c.command),
94
94
  }));
95
+ console.log("after req", { res });
95
96
  return res.map(({ error, result }, i) => {
96
97
  if (error) {
97
98
  throw new UpstashError(`Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`);
package/esm/pkg/redis.js CHANGED
@@ -1005,6 +1005,10 @@ export class Redis {
1005
1005
  writable: true,
1006
1006
  value: (...args) => new UnlinkCommand(args, this.opts).exec(this.client)
1007
1007
  });
1008
+ // /**
1009
+ // * @see https://redis.io/commands/xadd
1010
+ // */
1011
+ // xadd =
1008
1012
  /**
1009
1013
  * @see https://redis.io/commands/zadd
1010
1014
  */
package/esm/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "v1.22.0";
1
+ export const VERSION = "v0.0.0";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/platforms/nodejs.js",
4
4
  "types": "./types/platforms/nodejs.d.ts",
5
5
  "name": "@upstash/redis",
6
- "version": "v1.22.0",
6
+ "version": "1.23.0-next.1",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -136,6 +136,7 @@ __exportStar(require("./touch.js"), exports);
136
136
  __exportStar(require("./ttl.js"), exports);
137
137
  __exportStar(require("./type.js"), exports);
138
138
  __exportStar(require("./unlink.js"), exports);
139
+ __exportStar(require("./xadd.js"), exports);
139
140
  __exportStar(require("./zadd.js"), exports);
140
141
  __exportStar(require("./zcard.js"), exports);
141
142
  __exportStar(require("./zcount.js"), exports);
@@ -31,7 +31,7 @@ class SetCommand extends command_js_1.Command {
31
31
  command.push("pxat", opts.pxat);
32
32
  }
33
33
  else if ("keepTtl" in opts && opts.keepTtl) {
34
- command.push("keepTtl", opts.keepTtl);
34
+ command.push("keepTtl");
35
35
  }
36
36
  }
37
37
  super(command, cmdOpts);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XAddCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/xadd
7
+ */
8
+ class XAddCommand extends command_js_1.Command {
9
+ constructor([key, id, entries, opts], commandOptions) {
10
+ const command = ["XADD", key];
11
+ if (opts) {
12
+ if (opts.nomkStream) {
13
+ command.push("NOMKSTREAM");
14
+ }
15
+ if (opts.trim) {
16
+ command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
17
+ if (typeof opts.trim.limit !== "undefined") {
18
+ command.push("LIMIT", opts.trim.limit);
19
+ }
20
+ }
21
+ }
22
+ command.push(id);
23
+ // entries
24
+ Object.entries(entries).forEach(([k, v]) => {
25
+ command.push(k, v);
26
+ });
27
+ super(command, commandOptions);
28
+ }
29
+ }
30
+ exports.XAddCommand = XAddCommand;
@@ -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
  }
@@ -95,6 +95,7 @@ class Pipeline {
95
95
  path,
96
96
  body: Object.values(this.commands).map((c) => c.command),
97
97
  }));
98
+ console.log("after req", { res });
98
99
  return res.map(({ error, result }, i) => {
99
100
  if (error) {
100
101
  throw new error_js_1.UpstashError(`Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`);
@@ -1008,6 +1008,10 @@ 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
+ // xadd =
1011
1015
  /**
1012
1016
  * @see https://redis.io/commands/zadd
1013
1017
  */
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 = "v1.22.0";
4
+ exports.VERSION = "v0.0.0";
@@ -120,6 +120,7 @@ export * from "./touch.js";
120
120
  export * from "./ttl.js";
121
121
  export * from "./type.js";
122
122
  export * from "./unlink.js";
123
+ export * from "./xadd.js";
123
124
  export * from "./zadd.js";
124
125
  export * from "./zcard.js";
125
126
  export * from "./zcount.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 {};
@@ -1 +1 @@
1
- export declare const VERSION = "v1.22.0";
1
+ export declare const VERSION = "v0.0.0";