@upstash/redis 0.0.0-ci.82657fb2-20221116 → 0.0.0-ci.8500f14d-20221123

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/README.md CHANGED
@@ -81,24 +81,6 @@ data = await redis.spop('animals', 1)
81
81
  console.log(data)
82
82
  ```
83
83
 
84
- ### Upgrading to v1.4.0 **(ReferenceError: fetch is not defined)**
85
-
86
- If you are running on nodejs v17 and earlier, `fetch` will not be natively
87
- supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
88
- for you. But if you are running on bare node, you need to either specify a
89
- polyfill yourself or change the import path to:
90
-
91
- ```typescript
92
- import { Redis } from "@upstash/redis/with-fetch";
93
- ```
94
-
95
- ### Upgrading from v0.2.0?
96
-
97
- Please read the
98
- [migration guide](https://docs.upstash.com/redis/sdks/javascriptsdk/migration).
99
- For further explanation we wrote a
100
- [blog post](https://blog.upstash.com/upstash-redis-sdk-v1).
101
-
102
84
  ## Docs
103
85
 
104
86
  See [the documentation](https://docs.upstash.com/features/javascriptsdk) for
@@ -119,5 +101,18 @@ the url and token
119
101
  UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
120
102
  ```
121
103
 
122
- ```
104
+ ### Telemetry
105
+
106
+ This library sends anonymous telemetry data to help us improve your experience.
107
+ We collect the following:
108
+
109
+ - SDK version
110
+ - Platform (Deno, Cloudflare, Vercel)
111
+ - Runtime version (node@18.x)
112
+
113
+ You can opt out by setting the `UPSTASH_DISABLE_TELEMETRY` environment variable
114
+ to any truthy value.
115
+
116
+ ```sh
117
+ UPSTASH_DISABLE_TELEMETRY=1
123
118
  ```
package/esm/pkg/http.js CHANGED
@@ -1,6 +1,4 @@
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";
4
2
  export class HttpClient {
5
3
  constructor(config) {
6
4
  Object.defineProperty(this, "baseUrl", {
@@ -27,13 +25,28 @@ export class HttpClient {
27
25
  writable: true,
28
26
  value: void 0
29
27
  });
28
+ this.options = {
29
+ backend: config.options?.backend,
30
+ agent: config.agent,
31
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
32
+ };
30
33
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
31
34
  this.headers = {
32
35
  "Content-Type": "application/json",
33
- "Upstash-Encoding": "base64",
34
36
  ...config.headers,
35
37
  };
36
- this.options = { backend: config.options?.backend, agent: config.agent };
38
+ if (config.telemetry?.runtime) {
39
+ this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
40
+ }
41
+ if (config.telemetry?.platform) {
42
+ this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
43
+ }
44
+ if (config.telemetry?.sdk) {
45
+ this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
46
+ }
47
+ if (this.options.responseEncoding === "base64") {
48
+ this.headers["Upstash-Encoding"] = "base64";
49
+ }
37
50
  if (typeof config?.retry === "boolean" && config?.retry === false) {
38
51
  this.retry = {
39
52
  attempts: 1,
@@ -79,34 +92,33 @@ export class HttpClient {
79
92
  if (!res.ok) {
80
93
  throw new UpstashError(body.error);
81
94
  }
82
- console.time("decode");
83
- const resp = Array.isArray(body) ? body.map(decode) : decode(body);
84
- console.timeEnd("decode");
85
- return resp;
95
+ if (this.options?.responseEncoding === "base64") {
96
+ return Array.isArray(body) ? body.map(decode) : decode(body);
97
+ }
98
+ return body;
86
99
  }
87
100
  }
88
101
  function base64decode(b64) {
89
102
  let dec = "";
90
103
  try {
91
- console.time("atob");
92
104
  /**
93
- * THIS WORKS
105
+ * Using only atob() is not enough because it doesn't work with unicode characters
94
106
  */
95
- const s = utf8.decode(base64.decode(b64));
96
- console.timeEnd("atob");
97
- console.time("escape");
98
- console.timeEnd("escape");
99
- dec = decodeURIComponent(s);
107
+ const binString = atob(b64);
108
+ const size = binString.length;
109
+ const bytes = new Uint8Array(size);
110
+ for (let i = 0; i < size; i++) {
111
+ bytes[i] = binString.charCodeAt(i);
112
+ }
113
+ dec = new TextDecoder().decode(bytes);
100
114
  }
101
- catch (e) {
102
- console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
103
- return dec;
115
+ catch {
116
+ dec = b64;
104
117
  }
105
118
  try {
106
119
  return decodeURIComponent(dec);
107
120
  }
108
- catch (e) {
109
- console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
121
+ catch {
110
122
  return dec;
111
123
  }
112
124
  }
@@ -1,5 +1,6 @@
1
1
  import * as core from "../pkg/redis.js";
2
2
  import { HttpClient } from "../pkg/http.js";
3
+ import { VERSION } from "../version.js";
3
4
  /**
4
5
  * Serverless redis client for upstash.
5
6
  */
@@ -15,7 +16,7 @@ export class Redis extends core.Redis {
15
16
  * });
16
17
  * ```
17
18
  */
18
- constructor(config) {
19
+ constructor(config, env) {
19
20
  if (config.url.startsWith(" ") ||
20
21
  config.url.endsWith(" ") ||
21
22
  /\r|\n/.test(config.url)) {
@@ -26,10 +27,17 @@ export class Redis extends core.Redis {
26
27
  /\r|\n/.test(config.token)) {
27
28
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
28
29
  }
30
+ const telemetry = {};
31
+ if (!env?.UPSTASH_DISABLE_TELEMETRY) {
32
+ telemetry.platform = "cloudflare";
33
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
34
+ }
29
35
  const client = new HttpClient({
30
36
  retry: config.retry,
31
37
  baseUrl: config.url,
32
38
  headers: { authorization: `Bearer ${config.token}` },
39
+ responseEncoding: config.responseEncoding,
40
+ telemetry,
33
41
  });
34
42
  super(client, {
35
43
  automaticDeserialization: config.automaticDeserialization,
@@ -57,6 +65,6 @@ export class Redis extends core.Redis {
57
65
  if (!token) {
58
66
  throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
59
67
  }
60
- return new Redis({ ...opts, url, token });
68
+ return new Redis({ ...opts, url, token }, env);
61
69
  }
62
70
  }
@@ -32,6 +32,7 @@ export class Redis extends core.Redis {
32
32
  retry: config.retry,
33
33
  headers: { authorization: `Bearer ${config.token}` },
34
34
  options: { backend: config.backend },
35
+ responseEncoding: config.responseEncoding,
35
36
  });
36
37
  super(client, {
37
38
  automaticDeserialization: config.automaticDeserialization,
@@ -1,6 +1,7 @@
1
1
  // deno-lint-ignore-file
2
2
  import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
+ import { VERSION } from "../version.js";
4
5
  import "isomorphic-fetch";
5
6
  /**
6
7
  * Serverless redis client for upstash.
@@ -21,11 +22,23 @@ export class Redis extends core.Redis {
21
22
  /\r|\n/.test(configOrRequester.token)) {
22
23
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
23
24
  }
25
+ const telemetry = {};
26
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
27
+ telemetry.runtime = `node@${process.version}`;
28
+ telemetry.platform = process.env.VERCEL
29
+ ? "vercel"
30
+ : process.env.AWS_REGION
31
+ ? "aws"
32
+ : "unknown";
33
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
34
+ }
24
35
  const client = new HttpClient({
25
36
  baseUrl: configOrRequester.url,
26
37
  retry: configOrRequester.retry,
27
38
  headers: { authorization: `Bearer ${configOrRequester.token}` },
28
- // agent: configOrRequester.agent,
39
+ // agent: configOrRequester.agent,
40
+ responseEncoding: configOrRequester.responseEncoding,
41
+ telemetry,
29
42
  });
30
43
  super(client, {
31
44
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -1,6 +1,7 @@
1
1
  // deno-lint-ignore-file
2
2
  import * as core from "../pkg/redis.js";
3
3
  import { HttpClient, } from "../pkg/http.js";
4
+ import { VERSION } from "../version.js";
4
5
  /**
5
6
  * Serverless redis client for upstash.
6
7
  */
@@ -20,11 +21,23 @@ export class Redis extends core.Redis {
20
21
  /\r|\n/.test(configOrRequester.token)) {
21
22
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
22
23
  }
24
+ const telemetry = {};
25
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
26
+ telemetry.runtime = `node@${process.version}`;
27
+ telemetry.platform = process.env.VERCEL
28
+ ? "vercel"
29
+ : process.env.AWS_REGION
30
+ ? "aws"
31
+ : "unknown";
32
+ telemetry.sdk = `@upstash/redis@${VERSION}`;
33
+ }
23
34
  const client = new HttpClient({
24
35
  baseUrl: configOrRequester.url,
25
36
  retry: configOrRequester.retry,
26
37
  headers: { authorization: `Bearer ${configOrRequester.token}` },
27
38
  agent: configOrRequester.agent,
39
+ responseEncoding: configOrRequester.responseEncoding,
40
+ telemetry,
28
41
  });
29
42
  super(client, {
30
43
  automaticDeserialization: configOrRequester.automaticDeserialization,
package/esm/version.js ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = "v0.0.0-ci.8500f14d-20221123";
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": "v0.0.0-ci.82657fb2-20221116",
6
+ "version": "v0.0.0-ci.8500f14d-20221123",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -1,32 +1,7 @@
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
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.HttpClient = void 0;
27
4
  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"));
30
5
  class HttpClient {
31
6
  constructor(config) {
32
7
  Object.defineProperty(this, "baseUrl", {
@@ -53,13 +28,28 @@ class HttpClient {
53
28
  writable: true,
54
29
  value: void 0
55
30
  });
31
+ this.options = {
32
+ backend: config.options?.backend,
33
+ agent: config.agent,
34
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
35
+ };
56
36
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
57
37
  this.headers = {
58
38
  "Content-Type": "application/json",
59
- "Upstash-Encoding": "base64",
60
39
  ...config.headers,
61
40
  };
62
- this.options = { backend: config.options?.backend, agent: config.agent };
41
+ if (config.telemetry?.runtime) {
42
+ this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
43
+ }
44
+ if (config.telemetry?.platform) {
45
+ this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
46
+ }
47
+ if (config.telemetry?.sdk) {
48
+ this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
49
+ }
50
+ if (this.options.responseEncoding === "base64") {
51
+ this.headers["Upstash-Encoding"] = "base64";
52
+ }
63
53
  if (typeof config?.retry === "boolean" && config?.retry === false) {
64
54
  this.retry = {
65
55
  attempts: 1,
@@ -105,35 +95,34 @@ class HttpClient {
105
95
  if (!res.ok) {
106
96
  throw new error_js_1.UpstashError(body.error);
107
97
  }
108
- console.time("decode");
109
- const resp = Array.isArray(body) ? body.map(decode) : decode(body);
110
- console.timeEnd("decode");
111
- return resp;
98
+ if (this.options?.responseEncoding === "base64") {
99
+ return Array.isArray(body) ? body.map(decode) : decode(body);
100
+ }
101
+ return body;
112
102
  }
113
103
  }
114
104
  exports.HttpClient = HttpClient;
115
105
  function base64decode(b64) {
116
106
  let dec = "";
117
107
  try {
118
- console.time("atob");
119
108
  /**
120
- * THIS WORKS
109
+ * Using only atob() is not enough because it doesn't work with unicode characters
121
110
  */
122
- const s = utf8.decode(base64.decode(b64));
123
- console.timeEnd("atob");
124
- console.time("escape");
125
- console.timeEnd("escape");
126
- dec = decodeURIComponent(s);
111
+ const binString = atob(b64);
112
+ const size = binString.length;
113
+ const bytes = new Uint8Array(size);
114
+ for (let i = 0; i < size; i++) {
115
+ bytes[i] = binString.charCodeAt(i);
116
+ }
117
+ dec = new TextDecoder().decode(bytes);
127
118
  }
128
- catch (e) {
129
- console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
130
- return dec;
119
+ catch {
120
+ dec = b64;
131
121
  }
132
122
  try {
133
123
  return decodeURIComponent(dec);
134
124
  }
135
- catch (e) {
136
- console.warn(`Unable to decode URI[${dec}]: ${e.message}`);
125
+ catch {
137
126
  return dec;
138
127
  }
139
128
  }
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Redis = void 0;
27
27
  const core = __importStar(require("../pkg/redis.js"));
28
28
  const http_js_1 = require("../pkg/http.js");
29
+ const version_js_1 = require("../version.js");
29
30
  /**
30
31
  * Serverless redis client for upstash.
31
32
  */
@@ -41,7 +42,7 @@ class Redis extends core.Redis {
41
42
  * });
42
43
  * ```
43
44
  */
44
- constructor(config) {
45
+ constructor(config, env) {
45
46
  if (config.url.startsWith(" ") ||
46
47
  config.url.endsWith(" ") ||
47
48
  /\r|\n/.test(config.url)) {
@@ -52,10 +53,17 @@ class Redis extends core.Redis {
52
53
  /\r|\n/.test(config.token)) {
53
54
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
54
55
  }
56
+ const telemetry = {};
57
+ if (!env?.UPSTASH_DISABLE_TELEMETRY) {
58
+ telemetry.platform = "cloudflare";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
55
61
  const client = new http_js_1.HttpClient({
56
62
  retry: config.retry,
57
63
  baseUrl: config.url,
58
64
  headers: { authorization: `Bearer ${config.token}` },
65
+ responseEncoding: config.responseEncoding,
66
+ telemetry,
59
67
  });
60
68
  super(client, {
61
69
  automaticDeserialization: config.automaticDeserialization,
@@ -83,7 +91,7 @@ class Redis extends core.Redis {
83
91
  if (!token) {
84
92
  throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
85
93
  }
86
- return new Redis({ ...opts, url, token });
94
+ return new Redis({ ...opts, url, token }, env);
87
95
  }
88
96
  }
89
97
  exports.Redis = Redis;
@@ -58,6 +58,7 @@ class Redis extends core.Redis {
58
58
  retry: config.retry,
59
59
  headers: { authorization: `Bearer ${config.token}` },
60
60
  options: { backend: config.backend },
61
+ responseEncoding: config.responseEncoding,
61
62
  });
62
63
  super(client, {
63
64
  automaticDeserialization: config.automaticDeserialization,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  require("isomorphic-fetch");
31
32
  /**
32
33
  * Serverless redis client for upstash.
@@ -47,11 +48,23 @@ class Redis extends core.Redis {
47
48
  /\r|\n/.test(configOrRequester.token)) {
48
49
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
49
50
  }
51
+ const telemetry = {};
52
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
53
+ telemetry.runtime = `node@${process.version}`;
54
+ telemetry.platform = process.env.VERCEL
55
+ ? "vercel"
56
+ : process.env.AWS_REGION
57
+ ? "aws"
58
+ : "unknown";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
50
61
  const client = new http_js_1.HttpClient({
51
62
  baseUrl: configOrRequester.url,
52
63
  retry: configOrRequester.retry,
53
64
  headers: { authorization: `Bearer ${configOrRequester.token}` },
54
- // agent: configOrRequester.agent,
65
+ // agent: configOrRequester.agent,
66
+ responseEncoding: configOrRequester.responseEncoding,
67
+ telemetry,
55
68
  });
56
69
  super(client, {
57
70
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  /**
31
32
  * Serverless redis client for upstash.
32
33
  */
@@ -46,11 +47,23 @@ class Redis extends core.Redis {
46
47
  /\r|\n/.test(configOrRequester.token)) {
47
48
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
48
49
  }
50
+ const telemetry = {};
51
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
52
+ telemetry.runtime = `node@${process.version}`;
53
+ telemetry.platform = process.env.VERCEL
54
+ ? "vercel"
55
+ : process.env.AWS_REGION
56
+ ? "aws"
57
+ : "unknown";
58
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
59
+ }
49
60
  const client = new http_js_1.HttpClient({
50
61
  baseUrl: configOrRequester.url,
51
62
  retry: configOrRequester.retry,
52
63
  headers: { authorization: `Bearer ${configOrRequester.token}` },
53
64
  agent: configOrRequester.agent,
65
+ responseEncoding: configOrRequester.responseEncoding,
66
+ telemetry,
54
67
  });
55
68
  super(client, {
56
69
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = "v0.0.0-ci.8500f14d-20221123";
@@ -29,22 +29,69 @@ export declare type RetryConfig = false | {
29
29
  */
30
30
  backoff?: (retryCount: number) => number;
31
31
  };
32
- declare type Options = {
32
+ export declare type Options = {
33
33
  backend?: string;
34
34
  };
35
+ export declare type RequesterConfig = {
36
+ /**
37
+ * Configure the retry behaviour in case of network errors
38
+ */
39
+ retry?: RetryConfig;
40
+ /**
41
+ * Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
42
+ * valid json and will therefore cause errors when deserializing. This used to happen very
43
+ * frequently with non-utf8 data, such as emojis.
44
+ *
45
+ * By default we will therefore encode the data as base64 on the server, before sending it to the
46
+ * client. The client will then decode the base64 data and parse it as utf8.
47
+ *
48
+ * For very large entries, this can add a few milliseconds, so if you are sure that your data is
49
+ * valid utf8, you can disable this behaviour by setting this option to false.
50
+ *
51
+ * Here's what the response body looks like:
52
+ *
53
+ * ```json
54
+ * {
55
+ * result?: "base64-encoded",
56
+ * error?: string
57
+ * }
58
+ * ```
59
+ *
60
+ * @default "base64"
61
+ */
62
+ responseEncoding?: false | "base64";
63
+ };
35
64
  export declare type HttpClientConfig = {
36
65
  headers?: Record<string, string>;
37
66
  baseUrl: string;
38
67
  options?: Options;
39
68
  retry?: RetryConfig;
40
69
  agent?: any;
41
- };
70
+ telemetry?: {
71
+ /**
72
+ * Upstash-Telemetry-Sdk
73
+ * @example @upstash/redis@v1.1.1
74
+ */
75
+ sdk?: string;
76
+ /**
77
+ * Upstash-Telemetry-Platform
78
+ * @example cloudflare
79
+ */
80
+ platform?: string;
81
+ /**
82
+ * Upstash-Telemetry-Runtime
83
+ * @example node@v18
84
+ */
85
+ runtime?: string;
86
+ };
87
+ } & RequesterConfig;
42
88
  export declare class HttpClient implements Requester {
43
89
  baseUrl: string;
44
90
  headers: Record<string, string>;
45
- readonly options?: {
91
+ readonly options: {
46
92
  backend?: string;
47
93
  agent: any;
94
+ responseEncoding?: false | "base64";
48
95
  };
49
96
  readonly retry: {
50
97
  attempts: number;
@@ -53,4 +100,3 @@ export declare class HttpClient implements Requester {
53
100
  constructor(config: HttpClientConfig);
54
101
  request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
55
102
  }
56
- export {};
@@ -1,5 +1,9 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
+ import { RequesterConfig } from "../pkg/http.js";
4
+ declare type Env = {
5
+ UPSTASH_DISABLE_TELEMETRY?: string;
6
+ };
3
7
  export type { Requester, UpstashRequest, UpstashResponse };
4
8
  /**
5
9
  * Connection credentials for upstash redis.
@@ -14,11 +18,7 @@ export declare type RedisConfigCloudflare = {
14
18
  * UPSTASH_REDIS_REST_TOKEN
15
19
  */
16
20
  token: string;
17
- /**
18
- * Configure the retry behaviour in case of network errors
19
- */
20
- retry?: RetryConfig;
21
- } & core.RedisOptions;
21
+ } & core.RedisOptions & RequesterConfig & Env;
22
22
  /**
23
23
  * Serverless redis client for upstash.
24
24
  */
@@ -34,9 +34,10 @@ export declare class Redis extends core.Redis {
34
34
  * });
35
35
  * ```
36
36
  */
37
- constructor(config: RedisConfigCloudflare);
37
+ constructor(config: RedisConfigCloudflare, env?: Env);
38
38
  static fromEnv(env?: {
39
39
  UPSTASH_REDIS_REST_URL: string;
40
40
  UPSTASH_REDIS_REST_TOKEN: string;
41
+ UPSTASH_DISABLE_TELEMETRY?: string;
41
42
  }, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
42
43
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -20,11 +20,7 @@ export declare type RedisConfigFastly = {
20
20
  * referenced by name.
21
21
  */
22
22
  backend: string;
23
- /**
24
- * Configure the retry behaviour in case of network errors
25
- */
26
- retry?: RetryConfig;
27
- } & core.RedisOptions;
23
+ } & core.RedisOptions & RequesterConfig;
28
24
  /**
29
25
  * Serverless redis client for upstash.
30
26
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  import "isomorphic-fetch";
4
4
  export type { Requester, UpstashRequest, UpstashResponse };
5
5
  /**
@@ -15,26 +15,7 @@ export declare type RedisConfigNodejs = {
15
15
  * UPSTASH_REDIS_REST_TOKEN
16
16
  */
17
17
  token: string;
18
- /**
19
- * An agent allows you to reuse connections to reduce latency for multiple sequential requests.
20
- *
21
- * This is a node specific implementation and is not supported in various runtimes like Vercel
22
- * edge functions.
23
- *
24
- * @example
25
- * ```ts
26
- * import https from "https"
27
- *
28
- * const options: RedisConfigNodejs = {
29
- * agent: new https.Agent({ keepAlive: true })
30
- * }
31
- * ```
32
- */
33
- /**
34
- * Configure the retry behaviour in case of network errors
35
- */
36
- retry?: RetryConfig;
37
- } & core.RedisOptions;
18
+ } & core.RedisOptions & RequesterConfig;
38
19
  /**
39
20
  * Serverless redis client for upstash.
40
21
  */
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RequesterConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -30,11 +30,7 @@ export declare type RedisConfigNodejs = {
30
30
  * ```
31
31
  */
32
32
  agent?: any;
33
- /**
34
- * Configure the retry behaviour in case of network errors
35
- */
36
- retry?: RetryConfig;
37
- } & core.RedisOptions;
33
+ } & core.RedisOptions & RequesterConfig;
38
34
  /**
39
35
  * Serverless redis client for upstash.
40
36
  */
@@ -0,0 +1 @@
1
+ export declare const VERSION = "v0.0.0-ci.8500f14d-20221123";
@@ -1,54 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,59 +0,0 @@
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;
@@ -1,18 +0,0 @@
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;
@@ -1,11 +0,0 @@
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;
@@ -1,8 +0,0 @@
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;