@upstash/redis 0.0.0-ci.b4d4a1cc → 0.0.0-ci.b984c0e9-20220826

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 (66) hide show
  1. package/README.md +36 -274
  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/lpos.js +19 -0
  8. package/esm/pkg/commands/mod.js +1 -0
  9. package/esm/pkg/commands/scan.js +3 -0
  10. package/esm/pkg/commands/sdiffstore.js +1 -1
  11. package/esm/pkg/commands/set.js +16 -4
  12. package/esm/pkg/commands/zrange.js +6 -0
  13. package/esm/pkg/http.js +35 -7
  14. package/esm/pkg/pipeline.js +10 -1
  15. package/esm/pkg/redis.js +26 -1
  16. package/esm/pkg/script.js +77 -0
  17. package/esm/platforms/cloudflare.js +5 -25
  18. package/esm/platforms/fastly.js +4 -25
  19. package/esm/platforms/node_with_fetch.js +4 -25
  20. package/esm/platforms/nodejs.js +19 -31
  21. package/package.json +1 -39
  22. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  23. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  24. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  25. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  26. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  27. package/script/pkg/commands/lpos.js +23 -0
  28. package/script/pkg/commands/mod.js +1 -0
  29. package/script/pkg/commands/scan.js +3 -0
  30. package/script/pkg/commands/sdiffstore.js +1 -1
  31. package/script/pkg/commands/set.js +16 -4
  32. package/script/pkg/commands/zrange.js +6 -0
  33. package/script/pkg/http.js +35 -7
  34. package/script/pkg/pipeline.js +9 -0
  35. package/script/pkg/redis.js +25 -0
  36. package/script/pkg/script.js +81 -0
  37. package/script/platforms/cloudflare.js +5 -25
  38. package/script/platforms/fastly.js +4 -25
  39. package/script/platforms/node_with_fetch.js +4 -25
  40. package/script/platforms/nodejs.js +19 -31
  41. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  42. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  43. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  44. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  45. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  46. package/types/pkg/commands/bitop.d.ts +0 -1
  47. package/types/pkg/commands/bitpos.d.ts +1 -1
  48. package/types/pkg/commands/lpop.d.ts +1 -1
  49. package/types/pkg/commands/lpos.d.ts +15 -0
  50. package/types/pkg/commands/mget.d.ts +1 -1
  51. package/types/pkg/commands/mod.d.ts +1 -0
  52. package/types/pkg/commands/rpop.d.ts +2 -2
  53. package/types/pkg/commands/scan.d.ts +1 -0
  54. package/types/pkg/commands/sdiffstore.d.ts +1 -1
  55. package/types/pkg/commands/set.d.ts +31 -2
  56. package/types/pkg/commands/spop.d.ts +2 -2
  57. package/types/pkg/commands/zadd.d.ts +1 -1
  58. package/types/pkg/commands/zrange.d.ts +7 -0
  59. package/types/pkg/http.d.ts +27 -3
  60. package/types/pkg/pipeline.d.ts +14 -6
  61. package/types/pkg/redis.d.ts +22 -8
  62. package/types/pkg/script.d.ts +42 -0
  63. package/types/platforms/cloudflare.d.ts +6 -2
  64. package/types/platforms/fastly.d.ts +5 -1
  65. package/types/platforms/node_with_fetch.d.ts +20 -1
  66. package/types/platforms/nodejs.d.ts +20 -1
@@ -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,6 +29,11 @@ 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
+ createScript(script: string): Script;
31
37
  /**
32
38
  * Create a new pipeline that allows you to send requests in bulk.
33
39
  *
@@ -52,7 +58,7 @@ export declare class Redis {
52
58
  /**
53
59
  * @see https://redis.io/commands/bitpos
54
60
  */
55
- bitpos: (key: string, start: number, end: number) => Promise<number>;
61
+ bitpos: (key: string, bit: 0 | 1, start?: number | undefined, end?: number | undefined) => Promise<number>;
56
62
  /**
57
63
  * @see https://redis.io/commands/dbsize
58
64
  */
@@ -214,7 +220,15 @@ export declare class Redis {
214
220
  /**
215
221
  * @see https://redis.io/commands/lpop
216
222
  */
217
- lpop: <TData>(key: string) => Promise<TData | null>;
223
+ lpop: <TData>(key: string, count?: number | undefined) => Promise<TData | null>;
224
+ /**
225
+ * @see https://redis.io/commands/lpos
226
+ */
227
+ lpos: <TData = number>(key: string, element: unknown, opts?: {
228
+ rank?: number | undefined;
229
+ count?: number | undefined;
230
+ maxLen?: number | undefined;
231
+ } | undefined) => Promise<TData>;
218
232
  /**
219
233
  * @see https://redis.io/commands/lpush
220
234
  */
@@ -242,7 +256,7 @@ export declare class Redis {
242
256
  /**
243
257
  * @see https://redis.io/commands/mget
244
258
  */
245
- mget: <TData extends unknown[]>(args_0: string, ...args_1: string[]) => Promise<TData>;
259
+ mget: <TData extends unknown[]>(...args: CommandArgs<typeof MGetCommand>) => Promise<TData>;
246
260
  /**
247
261
  * @see https://redis.io/commands/mset
248
262
  */
@@ -298,7 +312,7 @@ export declare class Redis {
298
312
  /**
299
313
  * @see https://redis.io/commands/rpop
300
314
  */
301
- rpop: <TData = string>(key: string) => Promise<TData | null>;
315
+ rpop: <TData = string>(key: string, count?: number | undefined) => Promise<TData | null>;
302
316
  /**
303
317
  * @see https://redis.io/commands/rpush
304
318
  */
@@ -342,7 +356,7 @@ export declare class Redis {
342
356
  /**
343
357
  * @see https://redis.io/commands/set
344
358
  */
345
- set: <TData>(key: string, value: TData, opts?: SetCommandOptions | undefined) => Promise<TData>;
359
+ set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
346
360
  /**
347
361
  * @see https://redis.io/commands/setbit
348
362
  */
@@ -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,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -14,6 +14,10 @@ export declare type RedisConfigCloudflare = {
14
14
  * UPSTASH_REDIS_REST_TOKEN
15
15
  */
16
16
  token: string;
17
+ /**
18
+ * Configure the retry behaviour in case of network errors
19
+ */
20
+ retry?: RetryConfig;
17
21
  } & core.RedisOptions;
18
22
  /**
19
23
  * Serverless redis client for upstash.
@@ -34,5 +38,5 @@ export declare class Redis extends core.Redis {
34
38
  static fromEnv(env?: {
35
39
  UPSTASH_REDIS_REST_URL: string;
36
40
  UPSTASH_REDIS_REST_TOKEN: string;
37
- }): Redis;
41
+ }, opts?: Omit<RedisConfigCloudflare, "url" | "token">): Redis;
38
42
  }
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import type { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import type { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -20,6 +20,10 @@ 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;
23
27
  } & core.RedisOptions;
24
28
  /**
25
29
  * Serverless redis client for upstash.
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  import "isomorphic-fetch";
4
4
  export type { Requester, UpstashRequest, UpstashResponse };
5
5
  /**
@@ -15,6 +15,25 @@ 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;
18
37
  } & core.RedisOptions;
19
38
  /**
20
39
  * Serverless redis client for upstash.
@@ -1,5 +1,5 @@
1
1
  import * as core from "../pkg/redis.js";
2
- import { Requester, UpstashRequest, UpstashResponse } from "../pkg/http.js";
2
+ import { Requester, RetryConfig, UpstashRequest, UpstashResponse } from "../pkg/http.js";
3
3
  export type { Requester, UpstashRequest, UpstashResponse };
4
4
  /**
5
5
  * Connection credentials for upstash redis.
@@ -14,6 +14,25 @@ export declare type RedisConfigNodejs = {
14
14
  * UPSTASH_REDIS_REST_TOKEN
15
15
  */
16
16
  token: string;
17
+ /**
18
+ * An agent allows you to reuse connections to reduce latency for multiple sequential requests.
19
+ *
20
+ * This is a node specific implementation and is not supported in various runtimes like Vercel
21
+ * edge functions.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import https from "https"
26
+ *
27
+ * const options: RedisConfigNodejs = {
28
+ * agent: new https.Agent({ keepAlive: true })
29
+ * }
30
+ * ```
31
+ */
32
+ /**
33
+ * Configure the retry behaviour in case of network errors
34
+ */
35
+ retry?: RetryConfig;
17
36
  } & core.RedisOptions;
18
37
  /**
19
38
  * Serverless redis client for upstash.