@upstash/redis 0.1.11 → 0.2.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.
@@ -1,536 +1,434 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import fetch from 'isomorphic-unfetch';
2
11
  /**
3
- * Upstash client
4
- * @param {string} url - database rest url
5
- * @param {string} token - database rest token
12
+ * Parse Options
6
13
  */
7
- export default function client(url, token) {
8
- var _a, _b, _c;
9
- let baseURL = (_b = (_a = url !== null && url !== void 0 ? url : process.env.UPSTASH_REDIS_EDGE_URL) !== null && _a !== void 0 ? _a : process.env.UPSTASH_REDIS_REST_URL) !== null && _b !== void 0 ? _b : '';
10
- let authToken = (_c = token !== null && token !== void 0 ? token : process.env.UPSTASH_REDIS_REST_TOKEN) !== null && _c !== void 0 ? _c : '';
11
- function auth(url, token) {
12
- baseURL = url;
13
- authToken = token;
14
+ function parseOptions(url, token, requestOptions = {}) {
15
+ if (typeof url === 'object' && url !== null) {
16
+ return parseOptions(url.url, url.token, url.requestOptions);
14
17
  }
15
- /**
16
- * Request
17
- * @param {function} callback - callback
18
- * @param {Object} parts - command, key, values, ...
19
- */
20
- function request(callback, ...parts) {
21
- const promise = new Promise((resolve, reject) => {
22
- return fetch(baseURL, {
23
- method: 'POST',
24
- body: JSON.stringify(parts),
25
- headers: {
26
- Authorization: `Bearer ${authToken}`,
27
- },
28
- })
29
- .then((res) => res.json().then())
30
- .then((data) => {
18
+ // try auto fill from env variables
19
+ if (!url && typeof window === 'undefined') {
20
+ url = process.env.UPSTASH_REDIS_REST_URL;
21
+ token = process.env.UPSTASH_REDIS_REST_TOKEN;
22
+ }
23
+ return { url: url, token, requestOptions };
24
+ }
25
+ /**
26
+ * Fetch
27
+ */
28
+ function fetchData(options, ...parts) {
29
+ var _a;
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ if (!options.url) {
32
+ throw 'Database url not found?';
33
+ }
34
+ try {
35
+ const res = yield fetch(options.url, Object.assign({ method: 'POST', body: JSON.stringify(parts), headers: Object.assign({ Authorization: `Bearer ${options.token}` }, (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.headers) }, options.requestOptions));
36
+ const data = yield res.json();
37
+ if (!res.ok) {
31
38
  if (data.error)
32
39
  throw data.error;
33
- resolve({
34
- data: data.result,
35
- error: null,
36
- });
37
- })
38
- .catch((error) => {
39
- resolve({
40
- data: null,
41
- error: typeof error === 'object' ? error.message : error,
42
- });
43
- });
44
- });
45
- if (callback) {
46
- return promise.then(callback);
40
+ throw `Upstash failed with (${res.status}): ${JSON.stringify(data, null, 2)}`;
41
+ }
42
+ return {
43
+ data: data.result,
44
+ error: null,
45
+ };
47
46
  }
48
- return promise;
47
+ catch (err) {
48
+ return {
49
+ data: null,
50
+ // @ts-ignore
51
+ error: err,
52
+ };
53
+ }
54
+ });
55
+ }
56
+ function upstash(url, token) {
57
+ const options = parseOptions(url, token);
58
+ /**
59
+ * Auth
60
+ */
61
+ function auth() {
62
+ Object.assign(options, {
63
+ url: undefined,
64
+ token: undefined,
65
+ }, parseOptions(arguments[0], arguments[1]));
49
66
  }
50
- /*
51
- ------------------------------------------------
52
- STRING
53
- ------------------------------------------------
67
+ /**
68
+ * STRING
54
69
  */
55
- function append(key, value, callback) {
56
- return request(callback, 'append', key, value);
70
+ function append() {
71
+ return fetchData(options, 'append', ...arguments);
57
72
  }
58
- function decr(key, callback) {
59
- return request(callback, 'decr', key);
73
+ function decr() {
74
+ return fetchData(options, 'decr', ...arguments);
60
75
  }
61
- function decrby(key, decrement, callback) {
62
- return request(callback, 'decrby', key, decrement);
76
+ function decrby() {
77
+ return fetchData(options, 'decrby', ...arguments);
63
78
  }
64
- function get(key, callback) {
65
- return request(callback, 'get', key);
79
+ function get() {
80
+ return fetchData(options, 'get', ...arguments);
66
81
  }
67
- function getrange(key, start, end, callback) {
68
- return request(callback, 'getrange', key, start, end);
82
+ function getrange() {
83
+ return fetchData(options, 'getrange', ...arguments);
69
84
  }
70
- function getset(key, value, callback) {
71
- return request(callback, 'getset', key, value);
85
+ function getset() {
86
+ return fetchData(options, 'getset', ...arguments);
72
87
  }
73
- function incr(key, callback) {
74
- return request(callback, 'incr', key);
88
+ function incr() {
89
+ return fetchData(options, 'incr', ...arguments);
75
90
  }
76
- function incrby(key, value, callback) {
77
- return request(callback, 'incrby', key, value);
91
+ function incrby() {
92
+ return fetchData(options, 'incrby', ...arguments);
78
93
  }
79
- function incrbyfloat(key, value, callback) {
80
- return request(callback, 'incrbyfloat', key, value);
94
+ function incrbyfloat() {
95
+ return fetchData(options, 'incrbyfloat', ...arguments);
81
96
  }
82
- function mget(values, callback) {
83
- return request(callback, 'mget', ...values);
97
+ function mget() {
98
+ return fetchData(options, 'mget', ...arguments);
84
99
  }
85
- function mset(values, callback) {
86
- return request(callback, 'mset', ...values);
100
+ function mset() {
101
+ return fetchData(options, 'mset', ...arguments);
87
102
  }
88
- function msetnx(values, callback) {
89
- return request(callback, 'msetnx', ...values);
103
+ function msetnx() {
104
+ return fetchData(options, 'msetnx', ...arguments);
90
105
  }
91
- function psetex(key, miliseconds, value, callback) {
92
- return request(callback, 'psetex', key, miliseconds, value);
106
+ function psetex() {
107
+ return fetchData(options, 'psetex', ...arguments);
93
108
  }
94
- function set(key, value, callback) {
95
- return request(callback, 'set', key, value);
109
+ function set() {
110
+ return fetchData(options, 'set', ...arguments);
96
111
  }
97
- function setex(key, seconds, value, callback) {
98
- return request(callback, 'setex', key, seconds, value);
112
+ function setex() {
113
+ return fetchData(options, 'setex', ...arguments);
99
114
  }
100
- function setnx(key, value, callback) {
101
- return request(callback, 'setnx', key, value);
115
+ function setnx() {
116
+ return fetchData(options, 'setnx', ...arguments);
102
117
  }
103
- function setrange(key, offset, value, callback) {
104
- return request(callback, 'setrange', key, offset, value);
118
+ function setrange() {
119
+ return fetchData(options, 'setrange', ...arguments);
105
120
  }
106
- function strlen(key, callback) {
107
- return request(callback, 'strlen', key);
121
+ function strlen() {
122
+ return fetchData(options, 'strlen', ...arguments);
108
123
  }
109
- /*
110
- ------------------------------------------------
111
- BITMAPS
112
- ------------------------------------------------
124
+ /**
125
+ * BITMAPS
113
126
  */
114
- function bitcount(key, start, end, callback) {
115
- if (start !== undefined && end !== undefined) {
116
- return request(callback, 'bitcount', key, start, end);
117
- }
118
- return request(callback, 'bitcount', key);
127
+ function bitcount() {
128
+ return fetchData(options, 'bitcount', ...arguments);
119
129
  }
120
- function bitop(operation, destinationKey, sourceKeys, callback) {
121
- return request(callback, 'bitop', operation, destinationKey, ...sourceKeys);
130
+ function bitop() {
131
+ return fetchData(options, 'bitop', ...arguments);
122
132
  }
123
- function bitpos(key, bit, start, end, callback) {
124
- if (start !== undefined && end !== undefined) {
125
- return request(callback, 'bitpos', key, bit, start, end);
126
- }
127
- else if (start !== undefined) {
128
- return request(callback, 'bitpos', key, bit, start);
129
- }
130
- return request(callback, 'bitpos', key, bit);
133
+ function bitpos() {
134
+ return fetchData(options, 'bitpos', ...arguments);
131
135
  }
132
- function getbit(key, offset, callback) {
133
- return request(callback, 'getbit', key, offset);
136
+ function getbit() {
137
+ return fetchData(options, 'getbit', ...arguments);
134
138
  }
135
- function setbit(key, offset, value, callback) {
136
- return request(callback, 'setbit', key, offset, value);
139
+ function setbit() {
140
+ return fetchData(options, 'setbit', ...arguments);
137
141
  }
138
- /*
139
- ------------------------------------------------
140
- CONNECTION
141
- ------------------------------------------------
142
+ /**
143
+ * CONNECTION
142
144
  */
143
- function echo(value, callback) {
144
- return request(callback, 'echo', value);
145
+ function echo() {
146
+ return fetchData(options, 'echo', ...arguments);
145
147
  }
146
- function ping(value, callback) {
147
- if (value) {
148
- return request(callback, 'ping', value);
149
- }
150
- return request(callback, 'ping');
148
+ function ping() {
149
+ return fetchData(options, 'ping', ...arguments);
151
150
  }
152
- /*
153
- ------------------------------------------------
154
- HASHES
155
- ------------------------------------------------
151
+ /**
152
+ * HASHES
156
153
  */
157
- function hdel(key, fields, callback) {
158
- return request(callback, 'hdel', key, ...fields);
154
+ function hdel() {
155
+ return fetchData(options, 'hdel', ...arguments);
159
156
  }
160
- function hexists(key, field, callback) {
161
- return request(callback, 'hexists', key, field);
157
+ function hexists() {
158
+ return fetchData(options, 'hexists', ...arguments);
162
159
  }
163
- function hget(key, field, callback) {
164
- return request(callback, 'hget', key, field);
160
+ function hget() {
161
+ return fetchData(options, 'hget', ...arguments);
165
162
  }
166
- function hgetall(key, callback) {
167
- return request(callback, 'hgetall', key);
163
+ function hgetall() {
164
+ return fetchData(options, 'hgetall', ...arguments);
168
165
  }
169
- function hincrby(key, field, increment, callback) {
170
- return request(callback, 'hincrby', key, field, increment);
166
+ function hincrby() {
167
+ return fetchData(options, 'hincrby', ...arguments);
171
168
  }
172
- function hincrbyfloat(key, field, increment, callback) {
173
- return request(callback, 'hincrbyfloat', key, field, increment);
169
+ function hincrbyfloat() {
170
+ return fetchData(options, 'hincrbyfloat', ...arguments);
174
171
  }
175
- function hkeys(key, callback) {
176
- return request(callback, 'hkeys', key);
172
+ function hkeys() {
173
+ return fetchData(options, 'hkeys', ...arguments);
177
174
  }
178
- function hlen(key, callback) {
179
- return request(callback, 'hlen', key);
175
+ function hlen() {
176
+ return fetchData(options, 'hlen', ...arguments);
180
177
  }
181
- function hmget(key, fields, callback) {
182
- return request(callback, 'hmget', key, ...fields);
178
+ function hmget() {
179
+ return fetchData(options, 'hmget', ...arguments);
183
180
  }
184
- function hmset(key, values, callback) {
185
- return request(callback, 'hmset', key, ...values);
181
+ function hmset() {
182
+ return fetchData(options, 'hmset', ...arguments);
186
183
  }
187
- function hscan(key, cursor, options, callback) {
188
- if ((options === null || options === void 0 ? void 0 : options.match) && (options === null || options === void 0 ? void 0 : options.count)) {
189
- return request(callback, 'hscan', key, cursor, 'match', options.match, 'count', options.count);
190
- }
191
- else if (options === null || options === void 0 ? void 0 : options.match) {
192
- return request(callback, 'hscan', key, cursor, 'match', options.match);
193
- }
194
- else if (options === null || options === void 0 ? void 0 : options.count) {
195
- return request(callback, 'hscan', key, cursor, 'count', options.count);
196
- }
197
- return request(callback, 'hscan', key, cursor);
184
+ function hscan() {
185
+ return fetchData(options, 'hscan', ...arguments);
198
186
  }
199
- function hset(key, values, callback) {
200
- return request(callback, 'hset', key, ...values);
187
+ function hset() {
188
+ return fetchData(options, 'hset', ...arguments);
201
189
  }
202
- function hsetnx(key, field, value, callback) {
203
- return request(callback, 'hsetnx', key, field, value);
190
+ function hsetnx() {
191
+ return fetchData(options, 'hsetnx', ...arguments);
204
192
  }
205
- function hvals(key, callback) {
206
- return request(callback, 'hvals', key);
193
+ function hvals() {
194
+ return fetchData(options, 'hvals', ...arguments);
207
195
  }
208
- /*
209
- ------------------------------------------------
210
- KEYS
211
- ------------------------------------------------
196
+ /**
197
+ * KEYS
212
198
  */
213
- function del(keys, callback) {
214
- return request(callback, 'del', ...keys);
199
+ function del() {
200
+ return fetchData(options, 'del', ...arguments);
215
201
  }
216
- function exists(keys, callback) {
217
- return request(callback, 'exists', ...keys);
202
+ function exists() {
203
+ return fetchData(options, 'exists', ...arguments);
218
204
  }
219
- function expire(key, seconds, callback) {
220
- return request(callback, 'expire', key, seconds);
205
+ function expire() {
206
+ return fetchData(options, 'expire', ...arguments);
221
207
  }
222
- function expireat(key, timestamp, callback) {
223
- return request(callback, 'expireat', key, timestamp);
208
+ function expireat() {
209
+ return fetchData(options, 'expireat', ...arguments);
224
210
  }
225
- function keys(pattern, callback) {
226
- return request(callback, 'keys', pattern);
211
+ function keys() {
212
+ return fetchData(options, 'keys', ...arguments);
227
213
  }
228
- function persist(key, callback) {
229
- return request(callback, 'persist', key);
214
+ function persist() {
215
+ return fetchData(options, 'persist', ...arguments);
230
216
  }
231
- function pexpire(key, miliseconds, callback) {
232
- return request(callback, 'pexpire', key, miliseconds);
217
+ function pexpire() {
218
+ return fetchData(options, 'pexpire', ...arguments);
233
219
  }
234
- function pexpireat(key, miliseconds, callback) {
235
- return request(callback, 'pexpireat', key, miliseconds);
220
+ function pexpireat() {
221
+ return fetchData(options, 'pexpireat', ...arguments);
236
222
  }
237
- function pttl(key, callback) {
238
- return request(callback, 'pttl', key);
223
+ function pttl() {
224
+ return fetchData(options, 'pttl', ...arguments);
239
225
  }
240
- function randomkey(callback) {
241
- return request(callback, 'randomkey');
226
+ function randomkey() {
227
+ return fetchData(options, 'randomkey', ...arguments);
242
228
  }
243
- function rename(key, newkey, callback) {
244
- return request(callback, 'rename', key, newkey);
229
+ function rename() {
230
+ return fetchData(options, 'rename', ...arguments);
245
231
  }
246
- function renamenx(key, newkey, callback) {
247
- return request(callback, 'renamenx', key, newkey);
232
+ function renamenx() {
233
+ return fetchData(options, 'renamenx', ...arguments);
248
234
  }
249
- function scan(cursor, opitons, callback) {
250
- if ((opitons === null || opitons === void 0 ? void 0 : opitons.match) && (opitons === null || opitons === void 0 ? void 0 : opitons.count)) {
251
- return request(callback, 'scan', cursor, 'match', opitons.match, 'count', opitons.count);
252
- }
253
- else if (opitons === null || opitons === void 0 ? void 0 : opitons.match) {
254
- return request(callback, 'scan', cursor, 'match', opitons.match);
255
- }
256
- else if (opitons === null || opitons === void 0 ? void 0 : opitons.count) {
257
- return request(callback, 'scan', cursor, 'count', opitons.count);
258
- }
259
- return request(callback, 'scan', cursor);
235
+ function scan() {
236
+ return fetchData(options, 'scan', ...arguments);
260
237
  }
261
- function touch(keys, callback) {
262
- return request(callback, 'touch', ...keys);
238
+ function touch() {
239
+ return fetchData(options, 'touch', ...arguments);
263
240
  }
264
- function ttl(key, callback) {
265
- return request(callback, 'ttl', key);
241
+ function ttl() {
242
+ return fetchData(options, 'ttl', ...arguments);
266
243
  }
267
- function type(key, callback) {
268
- return request(callback, 'type', key);
244
+ function type() {
245
+ return fetchData(options, 'type', ...arguments);
269
246
  }
270
- function unlink(keys, callback) {
271
- return request(callback, 'unlink', ...keys);
247
+ function unlink() {
248
+ return fetchData(options, 'unlink', ...arguments);
272
249
  }
273
- /*
274
- ------------------------------------------------
275
- LISTS
276
- ------------------------------------------------
250
+ /**
251
+ * LISTS
277
252
  */
278
- function lindex(key, index, callback) {
279
- return request(callback, 'lindex', key, index);
253
+ function lindex() {
254
+ return fetchData(options, 'lindex', ...arguments);
280
255
  }
281
- function linsert(key, option, pivot, element, callback) {
282
- return request(callback, 'linsert', key, option, pivot, element);
256
+ function linsert() {
257
+ return fetchData(options, 'linsert', ...arguments);
283
258
  }
284
- function llen(key, callback) {
285
- return request(callback, 'llen', key);
259
+ function llen() {
260
+ return fetchData(options, 'llen', ...arguments);
286
261
  }
287
- function lpop(key, callback) {
288
- return request(callback, 'lpop', key);
262
+ function lpop() {
263
+ return fetchData(options, 'lpop', ...arguments);
289
264
  }
290
- function lpush(key, elements, callback) {
291
- return request(callback, 'lpush', key, ...elements);
265
+ function lpush() {
266
+ return fetchData(options, 'lpush', ...arguments);
292
267
  }
293
- function lpushx(key, elements, callback) {
294
- return request(callback, 'lpushx', key, ...elements);
268
+ function lpushx() {
269
+ return fetchData(options, 'lpushx', ...arguments);
295
270
  }
296
- function lrange(key, start, stop, callback) {
297
- return request(callback, 'lrange', key, start, stop);
271
+ function lrange() {
272
+ return fetchData(options, 'lrange', ...arguments);
298
273
  }
299
- function lrem(key, count, element, callback) {
300
- return request(callback, 'lrem', key, count, element);
274
+ function lrem() {
275
+ return fetchData(options, 'lrem', ...arguments);
301
276
  }
302
- function lset(key, index, element, callback) {
303
- return request(callback, 'lset', key, index, element);
277
+ function lset() {
278
+ return fetchData(options, 'lset', ...arguments);
304
279
  }
305
- function ltrim(key, start, stop, callback) {
306
- return request(callback, 'ltrim', key, start, stop);
280
+ function ltrim() {
281
+ return fetchData(options, 'ltrim', ...arguments);
307
282
  }
308
- function rpop(key, callback) {
309
- return request(callback, 'rpop', key);
283
+ function rpop() {
284
+ return fetchData(options, 'rpop', ...arguments);
310
285
  }
311
- function rpoplpush(source, destination, callback) {
312
- return request(callback, 'rpoplpush', source, destination);
286
+ function rpoplpush() {
287
+ return fetchData(options, 'rpoplpush', ...arguments);
313
288
  }
314
- function rpush(key, elements, callback) {
315
- return request(callback, 'rpush', key, ...elements);
289
+ function rpush() {
290
+ return fetchData(options, 'rpush', ...arguments);
316
291
  }
317
- function rpushx(key, elements, callback) {
318
- return request(callback, 'rpushx', key, ...elements);
292
+ function rpushx() {
293
+ return fetchData(options, 'rpushx', ...arguments);
319
294
  }
320
- /*
321
- ------------------------------------------------
322
- SERVER
323
- ------------------------------------------------
295
+ /**
296
+ * SERVER
324
297
  */
325
- function dbsize(callback) {
326
- return request(callback, 'dbsize');
298
+ function dbsize() {
299
+ return fetchData(options, 'dbsize', ...arguments);
327
300
  }
328
- function flushall(mode, callback) {
329
- if (mode) {
330
- return request(callback, 'flushall', mode);
331
- }
332
- return request(callback, 'flushall');
301
+ function flushall() {
302
+ return fetchData(options, 'flushall', ...arguments);
333
303
  }
334
- function flushdb(mode, callback) {
335
- if (mode) {
336
- return request(callback, 'flushdb', mode);
337
- }
338
- return request(callback, 'flushdb');
304
+ function flushdb() {
305
+ return fetchData(options, 'flushdb', ...arguments);
339
306
  }
340
- function info(callback) {
341
- return request(callback, 'info');
307
+ function info() {
308
+ return fetchData(options, 'info', ...arguments);
342
309
  }
343
- function time(callback) {
344
- return request(callback, 'time');
310
+ function time() {
311
+ return fetchData(options, 'time', ...arguments);
345
312
  }
346
- /*
347
- ------------------------------------------------
348
- SET
349
- ------------------------------------------------
313
+ /**
314
+ * SET
350
315
  */
351
- function sadd(key, members, callback) {
352
- return request(callback, 'sadd', key, ...members);
316
+ function sadd() {
317
+ return fetchData(options, 'sadd', ...arguments);
353
318
  }
354
- function scard(key, callback) {
355
- return request(callback, 'scard', key);
319
+ function scard() {
320
+ return fetchData(options, 'scard', ...arguments);
356
321
  }
357
- function sdiff(keys, callback) {
358
- return request(callback, 'sdiff', ...keys);
322
+ function sdiff() {
323
+ return fetchData(options, 'sdiff', ...arguments);
359
324
  }
360
- function sdiffstore(destination, keys, callback) {
361
- return request(callback, 'sdiffstore', destination, ...keys);
325
+ function sdiffstore() {
326
+ return fetchData(options, 'sdiffstore', ...arguments);
362
327
  }
363
- function sinter(keys, callback) {
364
- return request(callback, 'sinter', ...keys);
328
+ function sinter() {
329
+ return fetchData(options, 'sinter', ...arguments);
365
330
  }
366
- function sinterstore(destination, keys, callback) {
367
- return request(callback, 'sinterstore', destination, ...keys);
331
+ function sinterstore() {
332
+ return fetchData(options, 'sinterstore', ...arguments);
368
333
  }
369
- function sismember(key, member, callback) {
370
- return request(callback, 'sismember', key, member);
334
+ function sismember() {
335
+ return fetchData(options, 'sismember', ...arguments);
371
336
  }
372
- function smembers(key, callback) {
373
- return request(callback, 'smembers', key);
337
+ function smembers() {
338
+ return fetchData(options, 'smembers', ...arguments);
374
339
  }
375
- function smove(source, destination, member, callback) {
376
- return request(callback, 'smove', source, destination, member);
340
+ function smove() {
341
+ return fetchData(options, 'smove', ...arguments);
377
342
  }
378
- function spop(key, count, callback) {
379
- if (count) {
380
- return request(callback, 'spop', key, count);
381
- }
382
- return request(callback, 'spop', key);
343
+ function spop() {
344
+ return fetchData(options, 'spop', ...arguments);
383
345
  }
384
- function srandmember(key, count, callback) {
385
- if (count) {
386
- return request(callback, 'srandmember', key, count);
387
- }
388
- return request(callback, 'srandmember', key);
346
+ function srandmember() {
347
+ return fetchData(options, 'srandmember', ...arguments);
348
+ }
349
+ function srem() {
350
+ return fetchData(options, 'srem', ...arguments);
389
351
  }
390
- function srem(key, members, callback) {
391
- return request(callback, 'srem', key, ...members);
352
+ function sscan() {
353
+ return fetchData(options, 'sscan', ...arguments);
392
354
  }
393
- function sunion(keys, callback) {
394
- return request(callback, 'sunion', ...keys);
355
+ function sunion() {
356
+ return fetchData(options, 'sunion', ...arguments);
395
357
  }
396
- function sunionstore(destination, keys, callback) {
397
- return request(callback, 'sunionstore', destination, ...keys);
358
+ function sunionstore() {
359
+ return fetchData(options, 'sunionstore', ...arguments);
398
360
  }
399
- /*
400
- ------------------------------------------------
401
- SORTED SETS
402
- ------------------------------------------------
361
+ /**
362
+ * SORTED SETS
403
363
  */
404
- function zadd(key, values, options, callback) {
405
- if (options) {
406
- const allOptions = Object.entries(options)
407
- .filter((e) => ['string', 'number', 'boolean'].includes(typeof e[1]))
408
- .map((e) => e[0].toUpperCase());
409
- return request(callback, 'zadd', key, ...allOptions, ...values);
410
- }
411
- return request(callback, 'zadd', key, ...values);
364
+ function zadd() {
365
+ return fetchData(options, 'zadd', ...arguments);
412
366
  }
413
- function zcard(key, callback) {
414
- return request(callback, 'zcard', key);
367
+ function zcard() {
368
+ return fetchData(options, 'zcard', ...arguments);
415
369
  }
416
- function zcount(key, min, max, callback) {
417
- return request(callback, 'zcount', key, min, max);
370
+ function zcount() {
371
+ return fetchData(options, 'zcount', ...arguments);
418
372
  }
419
- function zincrby(key, increment, member, callback) {
420
- return request(callback, 'zincrby', key, increment, member);
373
+ function zincrby() {
374
+ return fetchData(options, 'zincrby', ...arguments);
421
375
  }
422
- function zinterstore(destination, keys, options, callback) {
423
- if (options) {
424
- if (options.weights && options.aggregate) {
425
- return request(callback, 'zinterstore', destination, keys.length, ...keys, 'weights', ...options.weights, 'aggregate', options.aggregate);
426
- }
427
- else if (options.weights) {
428
- return request(callback, 'zinterstore', destination, keys.length, ...keys, 'weights', ...options.weights);
429
- }
430
- else if (options.aggregate) {
431
- return request(callback, 'zinterstore', destination, keys.length, ...keys, 'aggregate', options.aggregate);
432
- }
433
- }
434
- return request(callback, 'zinterstore', destination, keys.length, ...keys);
376
+ function zinterstore() {
377
+ return fetchData(options, 'zinterstore', ...arguments);
435
378
  }
436
- function zlexcount(key, min, max, callback) {
437
- return request(callback, 'zlexcount', key, min, max);
379
+ function zlexcount() {
380
+ return fetchData(options, 'zlexcount', ...arguments);
438
381
  }
439
- function zpopmax(key, count, callback) {
440
- if (count) {
441
- return request(callback, 'zpopmax', key, count);
442
- }
443
- return request(callback, 'zpopmax', key);
382
+ function zpopmax() {
383
+ return fetchData(options, 'zpopmax', ...arguments);
444
384
  }
445
- function zpopmin(key, count, callback) {
446
- if (count) {
447
- return request(callback, 'zpopmin', key, count);
448
- }
449
- return request(callback, 'zpopmin', key);
385
+ function zpopmin() {
386
+ return fetchData(options, 'zpopmin', ...arguments);
450
387
  }
451
- function zrange(key, min, max, options, callback) {
452
- if (options === null || options === void 0 ? void 0 : options.withScores) {
453
- return request(callback, 'zrange', key, min, max, 'WITHSCORES');
454
- }
455
- return request(callback, 'zrange', key, min, max);
388
+ function zrange() {
389
+ return fetchData(options, 'zrange', ...arguments);
456
390
  }
457
- function zrangebylex(key, min, max, offset, count, callback) {
458
- if (offset && count) {
459
- return request(callback, 'zrangebylex', key, min, max, 'LIMIT', offset, count);
460
- }
461
- return request(callback, 'zrangebylex', key, min, max);
391
+ function zrangebylex() {
392
+ return fetchData(options, 'zrangebylex', ...arguments);
462
393
  }
463
- function zrangebyscore(key, min, max, options, callback) {
464
- if ((options === null || options === void 0 ? void 0 : options.withScores) && (options === null || options === void 0 ? void 0 : options.limit)) {
465
- return request(callback, 'zrangebyscore', key, min, max, 'WITHSCORES', 'LIMIT', options.limit.offset, options.limit.count);
466
- }
467
- else if (options === null || options === void 0 ? void 0 : options.withScores) {
468
- return request(callback, 'zrangebyscore', key, min, max, 'WITHSCORES');
469
- }
470
- else if (options === null || options === void 0 ? void 0 : options.limit) {
471
- return request(callback, 'zrangebyscore', key, min, max, 'LIMIT', options.limit.offset, options.limit.count);
472
- }
473
- return request(callback, 'zrangebyscore', key, min, max);
394
+ function zrangebyscore() {
395
+ return fetchData(options, 'zrangebyscore', ...arguments);
474
396
  }
475
- function zrank(key, member, callback) {
476
- return request(callback, 'zrank', key, member);
397
+ function zrank() {
398
+ return fetchData(options, 'zrank', ...arguments);
477
399
  }
478
- function zrem(key, members, callback) {
479
- return request(callback, 'zrem', key, ...members);
400
+ function zrem() {
401
+ return fetchData(options, 'zrem', ...arguments);
480
402
  }
481
- function zremrangebylex(key, min, max, callback) {
482
- return request(callback, 'zremrangebylex', key, min, max);
403
+ function zremrangebylex() {
404
+ return fetchData(options, 'zremrangebylex', ...arguments);
483
405
  }
484
- function zremrangebyrank(key, start, stop, callback) {
485
- return request(callback, 'zremrangebyrank', key, start, stop);
406
+ function zremrangebyrank() {
407
+ return fetchData(options, 'zremrangebyrank', ...arguments);
486
408
  }
487
- function zremrangebyscore(key, min, max, callback) {
488
- return request(callback, 'zremrangebyscore', key, min, max);
409
+ function zremrangebyscore() {
410
+ return fetchData(options, 'zremrangebyscore', ...arguments);
489
411
  }
490
- function zrevrange(key, start, stop, options, callback) {
491
- if (options === null || options === void 0 ? void 0 : options.withScores) {
492
- return request(callback, 'zrevrange', key, start, stop, 'WITHSCORES');
493
- }
494
- return request(callback, 'zrevrange', key, start, stop);
412
+ function zrevrange() {
413
+ return fetchData(options, 'zrevrange', ...arguments);
495
414
  }
496
- function zrevrangebylex(key, max, min, offset, count, callback) {
497
- if (offset && count) {
498
- return request(callback, 'zrevrangebylex', key, max, min, 'LIMIT', offset, count);
499
- }
500
- return request(callback, 'zrevrangebylex', key, max, min);
501
- }
502
- function zrevrangebyscore(key, min, max, callback) {
503
- return request(callback, 'zrevrangebyscore', key, min, max);
504
- }
505
- // TODO
506
- // function zrevrank(
507
- // key: string,
508
- // start: number,
509
- // stop: number,
510
- // options?: { withScores: boolean },
511
- // callback?: Callback
512
- // ): MethodReturn {
513
- // if (options?.withScores) {
514
- // return request(callback, 'zrevrank', key, start, stop, 'WITHSCORES');
515
- // }
516
- // return request(callback, 'zrevrank', key, start, stop);
517
- // }
518
- function zscore(key, member, callback) {
519
- return request(callback, 'zscore', key, member);
520
- }
521
- function zunionstore(destination, keys, options, callback) {
522
- if (options) {
523
- if (options.weights && options.aggregate) {
524
- return request(callback, 'zunionstore', destination, keys.length, ...keys, 'weights', ...options.weights, 'aggregate', options.aggregate);
525
- }
526
- else if (options.weights) {
527
- return request(callback, 'zunionstore', destination, keys.length, ...keys, 'weights', ...options.weights);
528
- }
529
- else if (options.aggregate) {
530
- return request(callback, 'zunionstore', destination, keys.length, ...keys, 'aggregate', options.aggregate);
531
- }
532
- }
533
- return request(callback, 'zunionstore', destination, keys.length, ...keys);
415
+ function zrevrangebylex() {
416
+ return fetchData(options, 'zrevrangebylex', ...arguments);
417
+ }
418
+ function zrevrangebyscore() {
419
+ return fetchData(options, 'zrevrangebyscore', ...arguments);
420
+ }
421
+ function zrevrank() {
422
+ return fetchData(options, 'zrevrank', ...arguments);
423
+ }
424
+ function zscan() {
425
+ return fetchData(options, 'zscan', ...arguments);
426
+ }
427
+ function zscore() {
428
+ return fetchData(options, 'zscore', ...arguments);
429
+ }
430
+ function zunionstore() {
431
+ return fetchData(options, 'zunionstore', ...arguments);
534
432
  }
535
433
  return {
536
434
  auth,
@@ -562,7 +460,7 @@ export default function client(url, token) {
562
460
  // CONNECTION
563
461
  echo,
564
462
  ping,
565
- //HASHES
463
+ // HASHES
566
464
  hdel,
567
465
  hexists,
568
466
  hget,
@@ -573,10 +471,10 @@ export default function client(url, token) {
573
471
  hlen,
574
472
  hmget,
575
473
  hmset,
474
+ hscan,
576
475
  hset,
577
476
  hsetnx,
578
477
  hvals,
579
- hscan,
580
478
  // KEYS
581
479
  del,
582
480
  exists,
@@ -595,7 +493,7 @@ export default function client(url, token) {
595
493
  ttl,
596
494
  type,
597
495
  unlink,
598
- // LIST
496
+ // LISTS
599
497
  lindex,
600
498
  linsert,
601
499
  llen,
@@ -616,7 +514,7 @@ export default function client(url, token) {
616
514
  flushdb,
617
515
  info,
618
516
  time,
619
- //SET
517
+ // SET
620
518
  sadd,
621
519
  scard,
622
520
  sdiff,
@@ -629,9 +527,10 @@ export default function client(url, token) {
629
527
  spop,
630
528
  srandmember,
631
529
  srem,
530
+ sscan,
632
531
  sunion,
633
532
  sunionstore,
634
- //sorted
533
+ // SORTED SETS
635
534
  zadd,
636
535
  zcard,
637
536
  zcount,
@@ -651,9 +550,10 @@ export default function client(url, token) {
651
550
  zrevrange,
652
551
  zrevrangebylex,
653
552
  zrevrangebyscore,
654
- // zrevrank,
553
+ zrevrank,
554
+ zscan,
655
555
  zscore,
656
556
  zunionstore,
657
557
  };
658
558
  }
659
- //# sourceMappingURL=client.js.map
559
+ export default upstash;