@upstash/redis 1.16.0-next.3 → 1.16.1-rc.0

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,54 @@
1
+ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2
+ // deno-fmt-ignore
3
+ const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
4
+ "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
5
+ "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
6
+ "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
7
+ "5", "6", "7", "8", "9", "+", "/"];
8
+ /**
9
+ * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
10
+ * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
11
+ * @param data
12
+ */
13
+ export function encode(data) {
14
+ const uint8 = typeof data === "string"
15
+ ? new TextEncoder().encode(data)
16
+ : data instanceof Uint8Array
17
+ ? data
18
+ : new Uint8Array(data);
19
+ let result = "", i;
20
+ const l = uint8.length;
21
+ for (i = 2; i < l; i += 3) {
22
+ result += base64abc[uint8[i - 2] >> 2];
23
+ result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
24
+ result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
25
+ result += base64abc[uint8[i] & 0x3f];
26
+ }
27
+ if (i === l + 1) {
28
+ // 1 octet yet to write
29
+ result += base64abc[uint8[i - 2] >> 2];
30
+ result += base64abc[(uint8[i - 2] & 0x03) << 4];
31
+ result += "==";
32
+ }
33
+ if (i === l) {
34
+ // 2 octets yet to write
35
+ result += base64abc[uint8[i - 2] >> 2];
36
+ result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
37
+ result += base64abc[(uint8[i - 1] & 0x0f) << 2];
38
+ result += "=";
39
+ }
40
+ return result;
41
+ }
42
+ /**
43
+ * Decodes a given RFC4648 base64 encoded string
44
+ * @param b64
45
+ */
46
+ export function decode(b64) {
47
+ const binString = atob(b64);
48
+ const size = binString.length;
49
+ const bytes = new Uint8Array(size);
50
+ for (let i = 0; i < size; i++) {
51
+ bytes[i] = binString.charCodeAt(i);
52
+ }
53
+ return bytes;
54
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2
+ /** A default TextEncoder instance */
3
+ export const encoder = new TextEncoder();
4
+ /** Shorthand for new TextEncoder().encode() */
5
+ export function encode(input) {
6
+ return encoder.encode(input);
7
+ }
8
+ /** A default TextDecoder instance */
9
+ export const decoder = new TextDecoder();
10
+ /** Shorthand for new TextDecoder().decode() */
11
+ export function decode(input) {
12
+ return decoder.decode(input);
13
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getdel
4
+ */
5
+ export class GetDelCommand extends Command {
6
+ constructor(cmd, opts) {
7
+ super(["getdel", ...cmd], opts);
8
+ }
9
+ }
@@ -19,6 +19,7 @@ export * from "./get.js";
19
19
  export * from "./getbit.js";
20
20
  export * from "./getrange.js";
21
21
  export * from "./getset.js";
22
+ export * from "./getdel.js";
22
23
  export * from "./hdel.js";
23
24
  export * from "./hexists.js";
24
25
  export * from "./hget.js";
package/esm/pkg/http.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { UpstashError } from "./error.js";
2
+ import * as utf8 from "../deps/deno.land/std@0.82.0/encoding/utf8.js";
3
+ import * as base64 from "../deps/deno.land/std@0.82.0/encoding/base64.js";
2
4
  export class HttpClient {
3
5
  constructor(config) {
4
6
  Object.defineProperty(this, "baseUrl", {
@@ -77,13 +79,24 @@ export class HttpClient {
77
79
  if (!res.ok) {
78
80
  throw new UpstashError(body.error);
79
81
  }
80
- return Array.isArray(body) ? body.map(decode) : decode(body);
82
+ console.time("decode");
83
+ const resp = Array.isArray(body) ? body.map(decode) : decode(body);
84
+ console.timeEnd("decode");
85
+ return resp;
81
86
  }
82
87
  }
83
88
  function base64decode(b64) {
84
89
  let dec = "";
85
90
  try {
86
- dec = atob(b64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("");
91
+ console.time("atob");
92
+ /**
93
+ * THIS WORKS
94
+ */
95
+ const s = utf8.decode(base64.decode(b64));
96
+ console.timeEnd("atob");
97
+ console.time("escape");
98
+ console.timeEnd("escape");
99
+ dec = decodeURIComponent(s);
87
100
  }
88
101
  catch (e) {
89
102
  console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
@@ -93,7 +106,7 @@ function base64decode(b64) {
93
106
  return decodeURIComponent(dec);
94
107
  }
95
108
  catch (e) {
96
- console.warn(`Unable to decode URI [${dec}]: ${e.message}`);
109
+ console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
97
110
  return dec;
98
111
  }
99
112
  }
@@ -102,10 +115,11 @@ function decode(raw) {
102
115
  switch (typeof raw.result) {
103
116
  case "undefined":
104
117
  return raw;
105
- case "number":
118
+ case "number": {
106
119
  result = raw.result;
107
120
  break;
108
- case "object":
121
+ }
122
+ case "object": {
109
123
  if (Array.isArray(raw.result)) {
110
124
  result = raw.result.map((v) => typeof v === "string"
111
125
  ? base64decode(v)
@@ -119,9 +133,11 @@ function decode(raw) {
119
133
  result = null;
120
134
  }
121
135
  break;
122
- case "string":
136
+ }
137
+ case "string": {
123
138
  result = raw.result === "OK" ? "OK" : base64decode(raw.result);
124
139
  break;
140
+ }
125
141
  default:
126
142
  break;
127
143
  }
@@ -1,4 +1,4 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { UpstashError } from "./error.js";
3
3
  import { ZMScoreCommand } from "./commands/zmscore.js";
4
4
  /**
@@ -258,6 +258,15 @@ export class Pipeline {
258
258
  writable: true,
259
259
  value: (...args) => this.chain(new GetBitCommand(args, this.commandOptions))
260
260
  });
261
+ /**
262
+ * @see https://redis.io/commands/getdel
263
+ */
264
+ Object.defineProperty(this, "getdel", {
265
+ enumerable: true,
266
+ configurable: true,
267
+ writable: true,
268
+ value: (...args) => this.chain(new GetDelCommand(args, this.commandOptions))
269
+ });
261
270
  /**
262
271
  * @see https://redis.io/commands/getrange
263
272
  */
package/esm/pkg/redis.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
1
+ import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
2
2
  import { Pipeline } from "./pipeline.js";
3
3
  import { Script } from "./script.js";
4
4
  import { ZMScoreCommand } from "./commands/zmscore.js";
@@ -238,6 +238,15 @@ export class Redis {
238
238
  writable: true,
239
239
  value: (...args) => new GetBitCommand(args, this.opts).exec(this.client)
240
240
  });
241
+ /**
242
+ * @see https://redis.io/commands/getdel
243
+ */
244
+ Object.defineProperty(this, "getdel", {
245
+ enumerable: true,
246
+ configurable: true,
247
+ writable: true,
248
+ value: (...args) => new GetDelCommand(args, this.opts).exec(this.client)
249
+ });
241
250
  /**
242
251
  * @see https://redis.io/commands/getrange
243
252
  */
package/package.json CHANGED
@@ -3,6 +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.16.1-rc.0",
6
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
7
8
  "repository": {
8
9
  "type": "git",
@@ -58,6 +59,5 @@
58
59
  "require": "./script/platforms/node_with_fetch.js",
59
60
  "types": "./types/platforms/node_with_fetch.d.ts"
60
61
  }
61
- },
62
- "version": "1.16.0-next.3"
62
+ }
63
63
  }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.decode = exports.encode = void 0;
5
+ // deno-fmt-ignore
6
+ const base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
7
+ "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
8
+ "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
9
+ "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4",
10
+ "5", "6", "7", "8", "9", "+", "/"];
11
+ /**
12
+ * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
13
+ * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
14
+ * @param data
15
+ */
16
+ function encode(data) {
17
+ const uint8 = typeof data === "string"
18
+ ? new TextEncoder().encode(data)
19
+ : data instanceof Uint8Array
20
+ ? data
21
+ : new Uint8Array(data);
22
+ let result = "", i;
23
+ const l = uint8.length;
24
+ for (i = 2; i < l; i += 3) {
25
+ result += base64abc[uint8[i - 2] >> 2];
26
+ result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
27
+ result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
28
+ result += base64abc[uint8[i] & 0x3f];
29
+ }
30
+ if (i === l + 1) {
31
+ // 1 octet yet to write
32
+ result += base64abc[uint8[i - 2] >> 2];
33
+ result += base64abc[(uint8[i - 2] & 0x03) << 4];
34
+ result += "==";
35
+ }
36
+ if (i === l) {
37
+ // 2 octets yet to write
38
+ result += base64abc[uint8[i - 2] >> 2];
39
+ result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
40
+ result += base64abc[(uint8[i - 1] & 0x0f) << 2];
41
+ result += "=";
42
+ }
43
+ return result;
44
+ }
45
+ exports.encode = encode;
46
+ /**
47
+ * Decodes a given RFC4648 base64 encoded string
48
+ * @param b64
49
+ */
50
+ function decode(b64) {
51
+ const binString = atob(b64);
52
+ const size = binString.length;
53
+ const bytes = new Uint8Array(size);
54
+ for (let i = 0; i < size; i++) {
55
+ bytes[i] = binString.charCodeAt(i);
56
+ }
57
+ return bytes;
58
+ }
59
+ exports.decode = decode;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.decode = exports.decoder = exports.encode = exports.encoder = void 0;
5
+ /** A default TextEncoder instance */
6
+ exports.encoder = new TextEncoder();
7
+ /** Shorthand for new TextEncoder().encode() */
8
+ function encode(input) {
9
+ return exports.encoder.encode(input);
10
+ }
11
+ exports.encode = encode;
12
+ /** A default TextDecoder instance */
13
+ exports.decoder = new TextDecoder();
14
+ /** Shorthand for new TextDecoder().decode() */
15
+ function decode(input) {
16
+ return exports.decoder.decode(input);
17
+ }
18
+ exports.decode = decode;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetDelCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/getdel
7
+ */
8
+ class GetDelCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ super(["getdel", ...cmd], opts);
11
+ }
12
+ }
13
+ exports.GetDelCommand = GetDelCommand;
@@ -35,6 +35,7 @@ __exportStar(require("./get.js"), exports);
35
35
  __exportStar(require("./getbit.js"), exports);
36
36
  __exportStar(require("./getrange.js"), exports);
37
37
  __exportStar(require("./getset.js"), exports);
38
+ __exportStar(require("./getdel.js"), exports);
38
39
  __exportStar(require("./hdel.js"), exports);
39
40
  __exportStar(require("./hexists.js"), exports);
40
41
  __exportStar(require("./hget.js"), exports);
@@ -1,7 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.HttpClient = void 0;
4
27
  const error_js_1 = require("./error.js");
28
+ const utf8 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/utf8.js"));
29
+ const base64 = __importStar(require("../deps/deno.land/std@0.82.0/encoding/base64.js"));
5
30
  class HttpClient {
6
31
  constructor(config) {
7
32
  Object.defineProperty(this, "baseUrl", {
@@ -80,14 +105,25 @@ class HttpClient {
80
105
  if (!res.ok) {
81
106
  throw new error_js_1.UpstashError(body.error);
82
107
  }
83
- return Array.isArray(body) ? body.map(decode) : decode(body);
108
+ console.time("decode");
109
+ const resp = Array.isArray(body) ? body.map(decode) : decode(body);
110
+ console.timeEnd("decode");
111
+ return resp;
84
112
  }
85
113
  }
86
114
  exports.HttpClient = HttpClient;
87
115
  function base64decode(b64) {
88
116
  let dec = "";
89
117
  try {
90
- dec = atob(b64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("");
118
+ console.time("atob");
119
+ /**
120
+ * THIS WORKS
121
+ */
122
+ const s = utf8.decode(base64.decode(b64));
123
+ console.timeEnd("atob");
124
+ console.time("escape");
125
+ console.timeEnd("escape");
126
+ dec = decodeURIComponent(s);
91
127
  }
92
128
  catch (e) {
93
129
  console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
@@ -97,7 +133,7 @@ function base64decode(b64) {
97
133
  return decodeURIComponent(dec);
98
134
  }
99
135
  catch (e) {
100
- console.warn(`Unable to decode URI [${dec}]: ${e.message}`);
136
+ console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
101
137
  return dec;
102
138
  }
103
139
  }
@@ -106,10 +142,11 @@ function decode(raw) {
106
142
  switch (typeof raw.result) {
107
143
  case "undefined":
108
144
  return raw;
109
- case "number":
145
+ case "number": {
110
146
  result = raw.result;
111
147
  break;
112
- case "object":
148
+ }
149
+ case "object": {
113
150
  if (Array.isArray(raw.result)) {
114
151
  result = raw.result.map((v) => typeof v === "string"
115
152
  ? base64decode(v)
@@ -123,9 +160,11 @@ function decode(raw) {
123
160
  result = null;
124
161
  }
125
162
  break;
126
- case "string":
163
+ }
164
+ case "string": {
127
165
  result = raw.result === "OK" ? "OK" : base64decode(raw.result);
128
166
  break;
167
+ }
129
168
  default:
130
169
  break;
131
170
  }
@@ -261,6 +261,15 @@ class Pipeline {
261
261
  writable: true,
262
262
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
263
263
  });
264
+ /**
265
+ * @see https://redis.io/commands/getdel
266
+ */
267
+ Object.defineProperty(this, "getdel", {
268
+ enumerable: true,
269
+ configurable: true,
270
+ writable: true,
271
+ value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
272
+ });
264
273
  /**
265
274
  * @see https://redis.io/commands/getrange
266
275
  */
@@ -241,6 +241,15 @@ class Redis {
241
241
  writable: true,
242
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
243
243
  });
244
+ /**
245
+ * @see https://redis.io/commands/getdel
246
+ */
247
+ Object.defineProperty(this, "getdel", {
248
+ enumerable: true,
249
+ configurable: true,
250
+ writable: true,
251
+ value: (...args) => new mod_js_1.GetDelCommand(args, this.opts).exec(this.client)
252
+ });
244
253
  /**
245
254
  * @see https://redis.io/commands/getrange
246
255
  */
@@ -0,0 +1,11 @@
1
+ /**
2
+ * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
3
+ * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
4
+ * @param data
5
+ */
6
+ export declare function encode(data: ArrayBuffer | string): string;
7
+ /**
8
+ * Decodes a given RFC4648 base64 encoded string
9
+ * @param b64
10
+ */
11
+ export declare function decode(b64: string): Uint8Array;
@@ -0,0 +1,8 @@
1
+ /** A default TextEncoder instance */
2
+ export declare const encoder: any;
3
+ /** Shorthand for new TextEncoder().encode() */
4
+ export declare function encode(input?: string): Uint8Array;
5
+ /** A default TextDecoder instance */
6
+ export declare const decoder: any;
7
+ /** Shorthand for new TextDecoder().decode() */
8
+ export declare function decode(input?: Uint8Array): string;
@@ -0,0 +1,7 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getdel
4
+ */
5
+ export declare class GetDelCommand<TData = string> extends Command<unknown | null, TData | null> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
7
+ }
@@ -19,6 +19,7 @@ export * from "./get.js";
19
19
  export * from "./getbit.js";
20
20
  export * from "./getrange.js";
21
21
  export * from "./getset.js";
22
+ export * from "./getdel.js";
22
23
  export * from "./hdel.js";
23
24
  export * from "./hexists.js";
24
25
  export * from "./hget.js";
@@ -143,6 +143,10 @@ export declare class Pipeline {
143
143
  * @see https://redis.io/commands/getbit
144
144
  */
145
145
  getbit: (key: string, offset: number) => this;
146
+ /**
147
+ * @see https://redis.io/commands/getdel
148
+ */
149
+ getdel: <TData>(key: string) => this;
146
150
  /**
147
151
  * @see https://redis.io/commands/getrange
148
152
  */
@@ -127,6 +127,10 @@ export declare class Redis {
127
127
  * @see https://redis.io/commands/getbit
128
128
  */
129
129
  getbit: (key: string, offset: number) => Promise<0 | 1>;
130
+ /**
131
+ * @see https://redis.io/commands/getdel
132
+ */
133
+ getdel: <TData>(key: string) => Promise<TData | null>;
130
134
  /**
131
135
  * @see https://redis.io/commands/getrange
132
136
  */