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