@upstash/redis 1.0.0-alpha.1 → 1.0.0-alpha.4

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/fastly.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import {
2
+ Redis
3
+ } from "./chunk-Y5TC4HX2.mjs";
4
+ import "./chunk-ZIB6XPPC.mjs";
5
+ import {
6
+ HttpClient
7
+ } from "./chunk-HIDCSH5S.mjs";
8
+ import "./chunk-7YUZYRJS.mjs";
9
+
10
+ // pkg/fastly.ts
11
+ var Redis2 = class extends Redis {
12
+ constructor(config) {
13
+ const client = new HttpClient({
14
+ baseUrl: config.url,
15
+ headers: {
16
+ authorization: `Bearer ${config.token}`
17
+ },
18
+ options: { backend: config.backend }
19
+ });
20
+ super(client);
21
+ }
22
+ };
23
+ export {
24
+ Redis2 as Redis
25
+ };
package/http.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ declare type HttpRequest = {
2
+ path?: string[];
3
+ /**
4
+ * Request body will be serialized to json
5
+ */
6
+ body?: unknown;
7
+ };
8
+ declare type UpstashResponse<TResult> = {
9
+ result?: TResult;
10
+ error?: string;
11
+ };
12
+ declare type HttpClientConfig = {
13
+ headers?: Record<string, string>;
14
+ baseUrl: string;
15
+ options?: {
16
+ backend?: string;
17
+ };
18
+ };
19
+ declare class HttpClient {
20
+ baseUrl: string;
21
+ headers: Record<string, string>;
22
+ readonly options?: {
23
+ backend?: string;
24
+ };
25
+ constructor(config: HttpClientConfig);
26
+ request<TResponse>(req: HttpRequest): Promise<TResponse>;
27
+ }
28
+
29
+ export { HttpClient, HttpClientConfig, HttpRequest, UpstashResponse };
package/http.js ADDED
@@ -0,0 +1,83 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __reExport = (target, module2, copyDefault, desc) => {
25
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
26
+ for (let key of __getOwnPropNames(module2))
27
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
28
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
29
+ }
30
+ return target;
31
+ };
32
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
33
+ return (module2, temp) => {
34
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
35
+ };
36
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
37
+
38
+ // pkg/http.ts
39
+ var http_exports = {};
40
+ __export(http_exports, {
41
+ HttpClient: () => HttpClient
42
+ });
43
+
44
+ // pkg/error.ts
45
+ var UpstashError = class extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "UpstashError";
49
+ }
50
+ };
51
+
52
+ // pkg/http.ts
53
+ var HttpClient = class {
54
+ constructor(config) {
55
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
56
+ this.headers = __spreadValues({
57
+ "Content-Type": "application/json"
58
+ }, config.headers);
59
+ this.options = config.options;
60
+ }
61
+ async request(req) {
62
+ var _a;
63
+ if (!req.path) {
64
+ req.path = [];
65
+ }
66
+ const res = await fetch([this.baseUrl, ...req.path].join("/"), {
67
+ method: "POST",
68
+ headers: this.headers,
69
+ body: JSON.stringify(req.body),
70
+ backend: (_a = this.options) == null ? void 0 : _a.backend
71
+ });
72
+ const body = await res.json();
73
+ if (!res.ok) {
74
+ throw new UpstashError(body.error);
75
+ }
76
+ return body;
77
+ }
78
+ };
79
+ module.exports = __toCommonJS(http_exports);
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ HttpClient
83
+ });
package/http.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ HttpClient
3
+ } from "./chunk-HIDCSH5S.mjs";
4
+ import "./chunk-7YUZYRJS.mjs";
5
+ export {
6
+ HttpClient
7
+ };
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export { Redis, RedisConfigNodejs } from './nodejs';
2
+ import './redis-dd052782';
3
+ import './zunionstore-dffa797d';
4
+ import './http';
5
+
6
+ /**
7
+ * Result of a bad request to upstash
8
+ */
9
+ declare class UpstashError extends Error {
10
+ constructor(message: string);
11
+ }
12
+
13
+ export { UpstashError };
@@ -38,13 +38,10 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
38
38
  // pkg/index.ts
39
39
  var pkg_exports = {};
40
40
  __export(pkg_exports, {
41
- Redis: () => Redis,
41
+ Redis: () => Redis2,
42
42
  UpstashError: () => UpstashError
43
43
  });
44
44
 
45
- // pkg/http.ts
46
- var import_isomorphic_fetch = require("isomorphic-fetch");
47
-
48
45
  // pkg/error.ts
49
46
  var UpstashError = class extends Error {
50
47
  constructor(message) {
@@ -53,39 +50,6 @@ var UpstashError = class extends Error {
53
50
  }
54
51
  };
55
52
 
56
- // pkg/http.ts
57
- var HttpClient = class {
58
- constructor(config) {
59
- var _a;
60
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
61
- this.headers = (_a = config.headers) != null ? _a : {};
62
- this.options = config.options;
63
- }
64
- async request(method, req) {
65
- var _a;
66
- if (!req.path) {
67
- req.path = [];
68
- }
69
- const headers = __spreadValues(__spreadValues({
70
- "Content-Type": "application/json"
71
- }, this.headers), req.headers);
72
- const res = await fetch([this.baseUrl, ...req.path].join("/"), {
73
- method,
74
- headers,
75
- body: JSON.stringify(req.body),
76
- backend: (_a = this.options) == null ? void 0 : _a.backend
77
- });
78
- const body = await res.json();
79
- if (!res.ok) {
80
- throw new UpstashError(body.error);
81
- }
82
- return body;
83
- }
84
- async post(req) {
85
- return await this.request("POST", req);
86
- }
87
- };
88
-
89
53
  // pkg/util.ts
90
54
  function parseRecursive(obj) {
91
55
  return Array.isArray(obj) ? obj.map((o) => {
@@ -112,7 +76,7 @@ var Command = class {
112
76
  this.deserialize = (_a = opts == null ? void 0 : opts.deserialize) != null ? _a : parseResponse;
113
77
  }
114
78
  async exec(client) {
115
- const { result, error } = await client.post({
79
+ const { result, error } = await client.request({
116
80
  body: this.command
117
81
  });
118
82
  if (error) {
@@ -1044,7 +1008,7 @@ var Pipeline = class {
1044
1008
  if (this.commands.length === 0) {
1045
1009
  throw new Error("Pipeline is empty");
1046
1010
  }
1047
- const res = await this.client.post({
1011
+ const res = await this.client.request({
1048
1012
  path: ["pipeline"],
1049
1013
  body: Object.values(this.commands).map((c) => c.command)
1050
1014
  });
@@ -1384,39 +1348,8 @@ var Pipeline = class {
1384
1348
 
1385
1349
  // pkg/redis.ts
1386
1350
  var Redis = class {
1387
- constructor(config) {
1388
- this.client = new HttpClient({
1389
- baseUrl: config.url,
1390
- headers: {
1391
- authorization: `Bearer ${config.token}`
1392
- },
1393
- options: config.requestOptions
1394
- });
1395
- }
1396
- static fromEnv() {
1397
- if (typeof (process == null ? void 0 : process.env) === "undefined") {
1398
- throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `fromCloudflareEnv()` instead");
1399
- }
1400
- const url = process.env["UPSTASH_REDIS_REST_URL"];
1401
- if (!url) {
1402
- throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
1403
- }
1404
- const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
1405
- if (!token) {
1406
- throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
1407
- }
1408
- return new Redis({ url, token });
1409
- }
1410
- static fromCloudflareEnv() {
1411
- const url = UPSTASH_REDIS_REST_URL;
1412
- const token = UPSTASH_REDIS_REST_TOKEN;
1413
- if (!url) {
1414
- throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
1415
- }
1416
- if (!token) {
1417
- throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
1418
- }
1419
- return new Redis({ url, token });
1351
+ constructor(client) {
1352
+ this.client = client;
1420
1353
  }
1421
1354
  pipeline() {
1422
1355
  return new Pipeline(this.client);
@@ -1746,6 +1679,62 @@ var Redis = class {
1746
1679
  return new ZUnionStoreCommand(...args).exec(this.client);
1747
1680
  }
1748
1681
  };
1682
+
1683
+ // pkg/http.ts
1684
+ var HttpClient = class {
1685
+ constructor(config) {
1686
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
1687
+ this.headers = __spreadValues({
1688
+ "Content-Type": "application/json"
1689
+ }, config.headers);
1690
+ this.options = config.options;
1691
+ }
1692
+ async request(req) {
1693
+ var _a;
1694
+ if (!req.path) {
1695
+ req.path = [];
1696
+ }
1697
+ const res = await fetch([this.baseUrl, ...req.path].join("/"), {
1698
+ method: "POST",
1699
+ headers: this.headers,
1700
+ body: JSON.stringify(req.body),
1701
+ backend: (_a = this.options) == null ? void 0 : _a.backend
1702
+ });
1703
+ const body = await res.json();
1704
+ if (!res.ok) {
1705
+ throw new UpstashError(body.error);
1706
+ }
1707
+ return body;
1708
+ }
1709
+ };
1710
+
1711
+ // pkg/nodejs.ts
1712
+ var import_isomorphic_fetch = require("isomorphic-fetch");
1713
+ var Redis2 = class extends Redis {
1714
+ constructor(config) {
1715
+ const client = new HttpClient({
1716
+ baseUrl: config.url,
1717
+ headers: {
1718
+ authorization: `Bearer ${config.token}`
1719
+ }
1720
+ });
1721
+ super(client);
1722
+ }
1723
+ static fromEnv() {
1724
+ if (typeof (process == null ? void 0 : process.env) === "undefined") {
1725
+ throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `Redis.onCloudflare()` instead");
1726
+ }
1727
+ const url = process.env["UPSTASH_REDIS_REST_URL"];
1728
+ if (!url) {
1729
+ throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
1730
+ }
1731
+ const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
1732
+ if (!token) {
1733
+ throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
1734
+ }
1735
+ return new Redis2({ url, token });
1736
+ }
1737
+ };
1749
1738
  module.exports = __toCommonJS(pkg_exports);
1750
1739
  // Annotate the CommonJS export names for ESM import in node:
1751
1740
  0 && (module.exports = {
package/index.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ Redis
3
+ } from "./chunk-6GEVIAL6.mjs";
4
+ import "./chunk-Y5TC4HX2.mjs";
5
+ import "./chunk-ZIB6XPPC.mjs";
6
+ import "./chunk-HIDCSH5S.mjs";
7
+ import {
8
+ UpstashError
9
+ } from "./chunk-7YUZYRJS.mjs";
10
+ export {
11
+ Redis,
12
+ UpstashError
13
+ };
package/nodejs.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { R as Redis$1 } from './redis-dd052782';
2
+ import './zunionstore-dffa797d';
3
+ import './http';
4
+
5
+ /**
6
+ * Connection credentials for upstash redis.
7
+ * Get them from https://console.upstash.com/redis/<uuid>
8
+ */
9
+ declare type RedisConfigNodejs = {
10
+ /**
11
+ * UPSTASH_REDIS_REST_URL
12
+ */
13
+ url: string;
14
+ /**
15
+ * UPSTASH_REDIS_REST_TOKEN
16
+ */
17
+ token: string;
18
+ };
19
+ /**
20
+ * Serverless redis client for upstash.
21
+ */
22
+ declare class Redis extends Redis$1 {
23
+ /**
24
+ * Create a new redis client
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const redis = new Redis({
29
+ * url: "<UPSTASH_REDIS_REST_URL>",
30
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
31
+ * });
32
+ * ```
33
+ */
34
+ constructor(config: RedisConfigNodejs);
35
+ /**
36
+ * Create a new Upstash Redis instance from environment variables.
37
+ *
38
+ * Use this to automatically load connection secrets from your environment
39
+ * variables. For instance when using the Vercel integration.
40
+ *
41
+ * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
42
+ * your environment using `process.env`.
43
+ */
44
+ static fromEnv(): Redis;
45
+ }
46
+
47
+ export { Redis, RedisConfigNodejs };