@upstash/redis 0.0.0-ci.ba685120 → 0.0.0-ci.bafaa360-20230119

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.
Files changed (91) hide show
  1. package/README.md +19 -17
  2. package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
  3. package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
  4. package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
  5. package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
  6. package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
  7. package/esm/pkg/commands/getdel.js +9 -0
  8. package/esm/pkg/commands/hgetall.js +0 -4
  9. package/esm/pkg/commands/hrandfield.js +39 -0
  10. package/esm/pkg/commands/lmove.js +9 -0
  11. package/esm/pkg/commands/lpos.js +19 -0
  12. package/esm/pkg/commands/mod.js +5 -0
  13. package/esm/pkg/commands/scan.js +3 -0
  14. package/esm/pkg/commands/sdiffstore.js +1 -1
  15. package/esm/pkg/commands/set.js +16 -4
  16. package/esm/pkg/commands/smismember.js +9 -0
  17. package/esm/pkg/commands/zdiffstore.js +9 -0
  18. package/esm/pkg/commands/zmscore.js +10 -0
  19. package/esm/pkg/commands/zrange.js +6 -0
  20. package/esm/pkg/http.js +99 -2
  21. package/esm/pkg/pipeline.js +80 -6
  22. package/esm/pkg/redis.js +125 -2
  23. package/esm/pkg/script.js +77 -0
  24. package/esm/platforms/cloudflare.js +10 -2
  25. package/esm/platforms/fastly.js +1 -0
  26. package/esm/platforms/node_with_fetch.js +27 -1
  27. package/esm/platforms/nodejs.js +22 -1
  28. package/esm/version.js +1 -0
  29. package/package.json +1 -39
  30. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  31. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  32. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  33. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  34. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  35. package/script/pkg/commands/getdel.js +13 -0
  36. package/script/pkg/commands/hgetall.js +0 -4
  37. package/script/pkg/commands/hrandfield.js +43 -0
  38. package/script/pkg/commands/lmove.js +13 -0
  39. package/script/pkg/commands/lpos.js +23 -0
  40. package/script/pkg/commands/mod.js +5 -0
  41. package/script/pkg/commands/scan.js +3 -0
  42. package/script/pkg/commands/sdiffstore.js +1 -1
  43. package/script/pkg/commands/set.js +16 -4
  44. package/script/pkg/commands/smismember.js +13 -0
  45. package/script/pkg/commands/zdiffstore.js +13 -0
  46. package/script/pkg/commands/zmscore.js +14 -0
  47. package/script/pkg/commands/zrange.js +6 -0
  48. package/script/pkg/http.js +99 -2
  49. package/script/pkg/pipeline.js +79 -5
  50. package/script/pkg/redis.js +124 -1
  51. package/script/pkg/script.js +81 -0
  52. package/script/platforms/cloudflare.js +10 -2
  53. package/script/platforms/fastly.js +1 -0
  54. package/script/platforms/node_with_fetch.js +27 -1
  55. package/script/platforms/nodejs.js +22 -1
  56. package/script/version.js +4 -0
  57. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  58. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  59. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  60. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  61. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  62. package/types/pkg/commands/bitop.d.ts +0 -1
  63. package/types/pkg/commands/bitpos.d.ts +1 -1
  64. package/types/pkg/commands/getdel.d.ts +7 -0
  65. package/types/pkg/commands/hrandfield.d.ts +9 -0
  66. package/types/pkg/commands/lmove.d.ts +12 -0
  67. package/types/pkg/commands/lpop.d.ts +1 -1
  68. package/types/pkg/commands/lpos.d.ts +15 -0
  69. package/types/pkg/commands/mget.d.ts +1 -1
  70. package/types/pkg/commands/mod.d.ts +5 -0
  71. package/types/pkg/commands/rpop.d.ts +2 -2
  72. package/types/pkg/commands/scan.d.ts +1 -0
  73. package/types/pkg/commands/sdiffstore.d.ts +1 -1
  74. package/types/pkg/commands/set.d.ts +31 -2
  75. package/types/pkg/commands/smembers.d.ts +2 -2
  76. package/types/pkg/commands/smismember.d.ts +7 -0
  77. package/types/pkg/commands/spop.d.ts +2 -2
  78. package/types/pkg/commands/zadd.d.ts +1 -1
  79. package/types/pkg/commands/zdiffstore.d.ts +7 -0
  80. package/types/pkg/commands/zmscore.d.ts +7 -0
  81. package/types/pkg/commands/zrange.d.ts +7 -0
  82. package/types/pkg/http.d.ts +38 -4
  83. package/types/pkg/pipeline.d.ts +46 -9
  84. package/types/pkg/redis.d.ts +65 -9
  85. package/types/pkg/script.d.ts +42 -0
  86. package/types/pkg/types.d.ts +17 -0
  87. package/types/platforms/cloudflare.d.ts +8 -7
  88. package/types/platforms/fastly.d.ts +2 -6
  89. package/types/platforms/node_with_fetch.d.ts +2 -21
  90. package/types/platforms/nodejs.d.ts +3 -6
  91. package/types/version.d.ts +1 -0
@@ -1,7 +1,8 @@
1
- import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
- import { Requester } from "./http.js";
1
+ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand, PingCommand, ScoreMember, ScriptExistsCommand, SetCommandOptions, TouchCommand, UnlinkCommand, ZAddCommandOptions, ZAddCommandOptionsWithIncr, ZRangeCommandOptions } from "./commands/mod.js";
2
+ import { Requester, UpstashRequest, UpstashResponse } from "./http.js";
3
3
  import { Pipeline } from "./pipeline.js";
4
4
  import type { CommandArgs } from "./types.js";
5
+ import { Script } from "./script.js";
5
6
  export declare type RedisOptions = {
6
7
  /**
7
8
  * Automatically try to deserialize the returned data from upstash using `JSON.deserialize`
@@ -14,7 +15,7 @@ export declare type RedisOptions = {
14
15
  * Serverless redis client for upstash.
15
16
  */
16
17
  export declare class Redis {
17
- protected readonly client: Requester;
18
+ protected client: Requester;
18
19
  protected opts?: CommandOptions<any, any>;
19
20
  /**
20
21
  * Create a new redis client
@@ -28,12 +29,31 @@ export declare class Redis {
28
29
  * ```
29
30
  */
30
31
  constructor(client: Requester, opts?: RedisOptions);
32
+ /**
33
+ * Wrap a new middleware around the HTTP client.
34
+ */
35
+ use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
36
+ /**
37
+ * Technically this is not private, we can hide it from intellisense by doing this
38
+ */
39
+ private addTelemetry;
40
+ createScript(script: string): Script;
31
41
  /**
32
42
  * Create a new pipeline that allows you to send requests in bulk.
33
43
  *
34
44
  * @see {@link Pipeline}
35
45
  */
36
46
  pipeline: () => Pipeline;
47
+ /**
48
+ * Create a new transaction to allow executing multiple steps atomically.
49
+ *
50
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
51
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
52
+ * guarantees that the commands are executed as a single isolated operation.
53
+ *
54
+ * @see {@link Pipeline}
55
+ */
56
+ multi: () => Pipeline;
37
57
  /**
38
58
  * @see https://redis.io/commands/append
39
59
  */
@@ -52,7 +72,7 @@ export declare class Redis {
52
72
  /**
53
73
  * @see https://redis.io/commands/bitpos
54
74
  */
55
- bitpos: (key: string, start: number, end: number) => Promise<number>;
75
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => Promise<number>;
56
76
  /**
57
77
  * @see https://redis.io/commands/dbsize
58
78
  */
@@ -111,6 +131,10 @@ export declare class Redis {
111
131
  * @see https://redis.io/commands/getbit
112
132
  */
113
133
  getbit: (key: string, offset: number) => Promise<0 | 1>;
134
+ /**
135
+ * @see https://redis.io/commands/getdel
136
+ */
137
+ getdel: <TData>(key: string) => Promise<TData | null>;
114
138
  /**
115
139
  * @see https://redis.io/commands/getrange
116
140
  */
@@ -161,6 +185,14 @@ export declare class Redis {
161
185
  hmset: <TData>(key: string, kv: {
162
186
  [field: string]: TData;
163
187
  }) => Promise<"OK">;
188
+ /**
189
+ * @see https://redis.io/commands/hrandfield
190
+ */
191
+ hrandfield: {
192
+ (key: string): Promise<string>;
193
+ (key: string, count: number): Promise<string[]>;
194
+ <TData extends Record<string, unknown>>(key: string, count: number, withValues: boolean): Promise<Partial<TData>>;
195
+ };
164
196
  /**
165
197
  * @see https://redis.io/commands/hscan
166
198
  */
@@ -211,10 +243,22 @@ export declare class Redis {
211
243
  * @see https://redis.io/commands/llen
212
244
  */
213
245
  llen: (key: string) => Promise<number>;
246
+ /**
247
+ * @see https://redis.io/commands/lmove
248
+ */
249
+ lmove: <TData = string>(source: string, destination: string, whereFrom: "left" | "right", whereTo: "left" | "right") => Promise<TData>;
214
250
  /**
215
251
  * @see https://redis.io/commands/lpop
216
252
  */
217
- lpop: <TData>(key: string) => Promise<TData | null>;
253
+ lpop: <TData>(key: string, count?: number | undefined) => Promise<TData | null>;
254
+ /**
255
+ * @see https://redis.io/commands/lpos
256
+ */
257
+ lpos: <TData = number>(key: string, element: unknown, opts?: {
258
+ rank?: number | undefined;
259
+ count?: number | undefined;
260
+ maxLen?: number | undefined;
261
+ } | undefined) => Promise<TData>;
218
262
  /**
219
263
  * @see https://redis.io/commands/lpush
220
264
  */
@@ -242,7 +286,7 @@ export declare class Redis {
242
286
  /**
243
287
  * @see https://redis.io/commands/mget
244
288
  */
245
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => Promise<TData>;
289
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => Promise<TData>;
246
290
  /**
247
291
  * @see https://redis.io/commands/mset
248
292
  */
@@ -298,7 +342,7 @@ export declare class Redis {
298
342
  /**
299
343
  * @see https://redis.io/commands/rpop
300
344
  */
301
- rpop: <TData = string>(key: string) => Promise<TData | null>;
345
+ rpop: <TData = string>(key: string, count?: number | undefined) => Promise<TData | null>;
302
346
  /**
303
347
  * @see https://redis.io/commands/rpush
304
348
  */
@@ -342,7 +386,7 @@ export declare class Redis {
342
386
  /**
343
387
  * @see https://redis.io/commands/set
344
388
  */
345
- set: <TData>(key: string, value: TData, opts?: SetCommandOptions | undefined) => Promise<TData>;
389
+ set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
346
390
  /**
347
391
  * @see https://redis.io/commands/setbit
348
392
  */
@@ -371,10 +415,14 @@ export declare class Redis {
371
415
  * @see https://redis.io/commands/sismember
372
416
  */
373
417
  sismember: <TData>(key: string, member: TData) => Promise<0 | 1>;
418
+ /**
419
+ * @see https://redis.io/commands/smismember
420
+ */
421
+ smismember: <TMembers extends unknown[]>(key: string, members: TMembers) => Promise<(0 | 1)[]>;
374
422
  /**
375
423
  * @see https://redis.io/commands/smembers
376
424
  */
377
- smembers: (key: string) => Promise<string[]>;
425
+ smembers: <TData extends unknown[] = string[]>(key: string) => Promise<TData>;
378
426
  /**
379
427
  * @see https://redis.io/commands/smove
380
428
  */
@@ -439,6 +487,10 @@ export declare class Redis {
439
487
  * @see https://redis.io/commands/zcount
440
488
  */
441
489
  zcount: (key: string, min: string | number, max: string | number) => Promise<number>;
490
+ /**
491
+ * @see https://redis.io/commands/zdiffstore
492
+ */
493
+ zdiffstore: (destination: string, numkeys: number, ...keys: string[]) => Promise<number>;
442
494
  /**
443
495
  * @see https://redis.io/commands/zincrby
444
496
  */
@@ -451,6 +503,10 @@ export declare class Redis {
451
503
  * @see https://redis.io/commands/zlexcount
452
504
  */
453
505
  zlexcount: (key: string, min: string, max: string) => Promise<number>;
506
+ /**
507
+ * @see https://redis.io/commands/zmscore
508
+ */
509
+ zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
454
510
  /**
455
511
  * @see https://redis.io/commands/zpopmax
456
512
  */
@@ -0,0 +1,42 @@
1
+ import { Redis } from "./redis.js";
2
+ /**
3
+ * Creates a new script.
4
+ *
5
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
6
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
7
+ * the entire script. Afterwards, the script is cached on the server.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const redis = new Redis({...})
12
+ *
13
+ * const script = redis.createScript<string>("return ARGV[1];")
14
+ * const arg1 = await script.eval([], ["Hello World"])
15
+ * assertEquals(arg1, "Hello World")
16
+ * ```
17
+ */
18
+ export declare class Script<TResult = unknown> {
19
+ readonly script: string;
20
+ readonly sha1: string;
21
+ private readonly redis;
22
+ constructor(redis: Redis, script: string);
23
+ /**
24
+ * Send an `EVAL` command to redis.
25
+ */
26
+ eval(keys: string[], args: string[]): Promise<TResult>;
27
+ /**
28
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
29
+ */
30
+ evalsha(keys: string[], args: string[]): Promise<TResult>;
31
+ /**
32
+ * Optimistically try to run `EVALSHA` first.
33
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
34
+ *
35
+ * Following calls will be able to use the cached script
36
+ */
37
+ exec(keys: string[], args: string[]): Promise<TResult>;
38
+ /**
39
+ * Compute the sha1 hash of the script and return its hex representation.
40
+ */
41
+ private digest;
42
+ }
@@ -1 +1,18 @@
1
1
  export declare type CommandArgs<TCommand extends new (...args: any) => any> = ConstructorParameters<TCommand>[0];
2
+ export declare type Telemetry = {
3
+ /**
4
+ * Upstash-Telemetry-Sdk
5
+ * @example @upstash/redis@v1.1.1
6
+ */
7
+ sdk?: string;
8
+ /**
9
+ * Upstash-Telemetry-Platform
10
+ * @example cloudflare
11
+ */
12
+ platform?: string;
13
+ /**
14
+ * Upstash-Telemetry-Runtime
15
+ * @example node@v18
16
+ */
17
+ runtime?: string;
18
+ };
@@ -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.
@@ -29,11 +29,8 @@ export declare type RedisConfigNodejs = {
29
29
  * }
30
30
  * ```
31
31
  */
32
- /**
33
- * Configure the retry behaviour in case of network errors
34
- */
35
- retry?: RetryConfig;
36
- } & core.RedisOptions;
32
+ agent?: any;
33
+ } & core.RedisOptions & RequesterConfig;
37
34
  /**
38
35
  * Serverless redis client for upstash.
39
36
  */
@@ -0,0 +1 @@
1
+ export declare const VERSION = "v0.0.0-ci.bafaa360-20230119";