@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.
- package/esm/pkg/commands/mod.js +1 -0
- package/esm/pkg/commands/set.js +1 -1
- package/esm/pkg/commands/xadd.js +26 -0
- package/esm/pkg/http.js +16 -9
- package/esm/pkg/pipeline.js +1 -0
- package/esm/pkg/redis.js +4 -0
- package/esm/version.js +1 -1
- package/package.json +1 -1
- package/script/pkg/commands/mod.js +1 -0
- package/script/pkg/commands/set.js +1 -1
- package/script/pkg/commands/xadd.js +30 -0
- package/script/pkg/http.js +16 -9
- package/script/pkg/pipeline.js +1 -0
- package/script/pkg/redis.js +4 -0
- package/script/version.js +1 -1
- package/types/pkg/commands/mod.d.ts +1 -0
- package/types/pkg/commands/xadd.d.ts +31 -0
- package/types/version.d.ts +1 -1
package/esm/pkg/commands/mod.js
CHANGED
package/esm/pkg/commands/set.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
144
|
+
switch (typeof raw) {
|
|
138
145
|
case "undefined":
|
|
139
146
|
return raw;
|
|
140
147
|
case "number": {
|
|
141
|
-
result = raw
|
|
148
|
+
result = raw;
|
|
142
149
|
break;
|
|
143
150
|
}
|
|
144
151
|
case "object": {
|
|
145
|
-
if (Array.isArray(raw
|
|
146
|
-
result = raw.
|
|
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(
|
|
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
|
|
167
|
+
result = raw === "OK" ? "OK" : base64decode(raw);
|
|
161
168
|
break;
|
|
162
169
|
}
|
|
163
170
|
default:
|
|
164
171
|
break;
|
|
165
172
|
}
|
|
166
|
-
return
|
|
173
|
+
return result;
|
|
167
174
|
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -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 = "
|
|
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": "
|
|
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);
|
|
@@ -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;
|
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
|
@@ -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}`);
|
package/script/pkg/redis.js
CHANGED
|
@@ -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
|
@@ -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 {};
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "
|
|
1
|
+
export declare const VERSION = "v0.0.0";
|