@upstash/redis 0.0.0-ci.abef0b14 → 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 (31) hide show
  1. package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
  2. package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
  3. package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
  4. package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
  5. package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
  6. package/esm/pkg/commands/scan.js +3 -0
  7. package/esm/pkg/commands/set.js +16 -4
  8. package/esm/pkg/redis.js +4 -0
  9. package/esm/pkg/script.js +77 -0
  10. package/esm/platforms/nodejs.js +15 -6
  11. package/package.json +1 -39
  12. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  13. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  14. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  15. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  16. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  17. package/script/pkg/commands/scan.js +3 -0
  18. package/script/pkg/commands/set.js +16 -4
  19. package/script/pkg/redis.js +4 -0
  20. package/script/pkg/script.js +81 -0
  21. package/script/platforms/nodejs.js +15 -6
  22. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  23. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  24. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  25. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  26. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  27. package/types/pkg/commands/scan.d.ts +1 -0
  28. package/types/pkg/commands/set.d.ts +31 -2
  29. package/types/pkg/pipeline.d.ts +1 -1
  30. package/types/pkg/redis.d.ts +3 -1
  31. package/types/pkg/script.d.ts +42 -0
@@ -2,6 +2,7 @@ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand
2
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`
@@ -32,6 +33,7 @@ export declare class Redis {
32
33
  * Wrap a new middleware around the HTTP client.
33
34
  */
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;
35
37
  /**
36
38
  * Create a new pipeline that allows you to send requests in bulk.
37
39
  *
@@ -354,7 +356,7 @@ export declare class Redis {
354
356
  /**
355
357
  * @see https://redis.io/commands/set
356
358
  */
357
- set: <TData>(key: string, value: TData, opts?: SetCommandOptions | undefined) => Promise<TData>;
359
+ set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
358
360
  /**
359
361
  * @see https://redis.io/commands/setbit
360
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
+ }