upstash-lua 0.3.0
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.
- package/README.md +319 -0
- package/dist/define-script.d.ts +250 -0
- package/dist/define-script.d.ts.map +1 -0
- package/dist/errors.d.ts +107 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/eval-with-cache.d.ts +73 -0
- package/dist/eval-with-cache.d.ts.map +1 -0
- package/dist/hash-result.d.ts +48 -0
- package/dist/hash-result.d.ts.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +304 -0
- package/dist/lua-template.d.ts +158 -0
- package/dist/lua-template.d.ts.map +1 -0
- package/dist/redis-like.d.ts +90 -0
- package/dist/redis-like.d.ts.map +1 -0
- package/dist/sha1.d.ts +28 -0
- package/dist/sha1.d.ts.map +1 -0
- package/dist/standard-schema.d.ts +112 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/version.d.ts +19 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal interface for Upstash Redis that support Lua script execution.
|
|
3
|
+
*
|
|
4
|
+
* This interface is designed to be compatible with Upstash Redis and possibly other
|
|
5
|
+
* Redis clients.
|
|
6
|
+
*
|
|
7
|
+
* **Compatibility:**
|
|
8
|
+
* - Upstash Redis (`@upstash/redis`) - Fully compatible
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { Redis } from "@upstash/redis"
|
|
13
|
+
*
|
|
14
|
+
* const redis = new Redis({
|
|
15
|
+
* url: process.env.UPSTASH_REDIS_REST_URL,
|
|
16
|
+
* token: process.env.UPSTASH_REDIS_REST_TOKEN,
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* // redis is compatible with RedisLike
|
|
20
|
+
* await myScript.run(redis, { keys: { key: "test" } })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
*/
|
|
25
|
+
export interface RedisLike {
|
|
26
|
+
/**
|
|
27
|
+
* Executes a Lua script directly.
|
|
28
|
+
*
|
|
29
|
+
* This method sends the full script source to Redis for execution.
|
|
30
|
+
* It is less efficient than `evalsha` for repeated executions of the
|
|
31
|
+
* same script, as the script must be parsed each time.
|
|
32
|
+
*
|
|
33
|
+
* @param script - The Lua script source code
|
|
34
|
+
* @param keys - Array of Redis keys used by the script (accessed as KEYS[1], KEYS[2], etc.)
|
|
35
|
+
* @param args - Array of additional arguments (accessed as ARGV[1], ARGV[2], etc.)
|
|
36
|
+
* @returns Promise resolving to the script's return value
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const result = await redis.eval(
|
|
41
|
+
* 'return redis.call("GET", KEYS[1])',
|
|
42
|
+
* ["mykey"],
|
|
43
|
+
* []
|
|
44
|
+
* )
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
eval(script: string, keys: string[], args: string[]): Promise<unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Executes a cached Lua script by its SHA1 hash.
|
|
50
|
+
*
|
|
51
|
+
* This is the preferred method for executing scripts, as it avoids
|
|
52
|
+
* sending the full script source over the network. The script must
|
|
53
|
+
* have been previously loaded using `scriptLoad`.
|
|
54
|
+
*
|
|
55
|
+
* If the script is not cached on the server, Redis returns a NOSCRIPT
|
|
56
|
+
* error. The library handles this automatically by loading the script
|
|
57
|
+
* and retrying.
|
|
58
|
+
*
|
|
59
|
+
* @param sha1 - The SHA1 hash of the script (40 hexadecimal characters)
|
|
60
|
+
* @param keys - Array of Redis keys used by the script
|
|
61
|
+
* @param args - Array of additional arguments
|
|
62
|
+
* @returns Promise resolving to the script's return value
|
|
63
|
+
* @throws Error with message containing "NOSCRIPT" if script is not cached
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const sha = await redis.scriptLoad('return "hello"')
|
|
68
|
+
* const result = await redis.evalsha(sha, [], [])
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
evalsha(sha1: string, keys: string[], args: string[]): Promise<unknown>;
|
|
72
|
+
/**
|
|
73
|
+
* Loads a Lua script into the Redis script cache.
|
|
74
|
+
*
|
|
75
|
+
* The script is cached on the server and can be executed later using
|
|
76
|
+
* `evalsha` with the returned SHA1 hash. This avoids sending the full
|
|
77
|
+
* script source for each execution.
|
|
78
|
+
*
|
|
79
|
+
* @param script - The Lua script source code to cache
|
|
80
|
+
* @returns Promise resolving to the SHA1 hash of the script
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const sha = await redis.scriptLoad('return redis.call("PING")')
|
|
85
|
+
* console.log(sha) // "e.g., a42059b356c875f0717db19a51f6aaa9161e77a2"
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
scriptLoad(script: string): Promise<string>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=redis-like.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-like.d.ts","sourceRoot":"","sources":["../src/redis-like.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAEtE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAEvE;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5C"}
|
package/dist/sha1.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the SHA1 hash of a string and returns it as a hexadecimal string.
|
|
3
|
+
*
|
|
4
|
+
* This implementation uses the WebCrypto API, which is available in:
|
|
5
|
+
* - Node.js 18+ (via `globalThis.crypto.subtle`)
|
|
6
|
+
* - Bun (full WebCrypto support)
|
|
7
|
+
* - Cloudflare Workers
|
|
8
|
+
* - Vercel Edge Runtime
|
|
9
|
+
* - Deno
|
|
10
|
+
*
|
|
11
|
+
* The SHA1 hash is used by Redis to identify cached Lua scripts for
|
|
12
|
+
* efficient execution via EVALSHA.
|
|
13
|
+
*
|
|
14
|
+
* @param text - The string to hash (typically a Lua script)
|
|
15
|
+
* @returns Promise resolving to the 40-character lowercase hexadecimal SHA1 hash
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const hash = await sha1Hex('return redis.call("PING")')
|
|
20
|
+
* console.log(hash) // "e.g., a42059b356c875f0717db19a51f6aaa9161e77a2"
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @throws {Error} If WebCrypto is not available in the runtime
|
|
24
|
+
*
|
|
25
|
+
* @since 0.1.0
|
|
26
|
+
*/
|
|
27
|
+
export declare function sha1Hex(text: string): Promise<string>;
|
|
28
|
+
//# sourceMappingURL=sha1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../src/sha1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa3D"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a validation issue from a StandardSchemaV1 schema.
|
|
4
|
+
* This is a simplified representation that works across different schema libraries.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
*/
|
|
8
|
+
export interface ValidationIssue {
|
|
9
|
+
/** Human-readable error message */
|
|
10
|
+
readonly message: string;
|
|
11
|
+
/** Path to the invalid value within the input */
|
|
12
|
+
readonly path?: ReadonlyArray<PropertyKey>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result of a successful validation.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
*/
|
|
19
|
+
export interface ValidationSuccess<T> {
|
|
20
|
+
readonly ok: true;
|
|
21
|
+
readonly value: T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of a failed validation.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
export interface ValidationFailure {
|
|
29
|
+
readonly ok: false;
|
|
30
|
+
readonly issues: readonly ValidationIssue[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Result of validating a value against a StandardSchemaV1 schema.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
*/
|
|
37
|
+
export type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
38
|
+
/**
|
|
39
|
+
* Validates a value against a StandardSchemaV1 schema.
|
|
40
|
+
*
|
|
41
|
+
* This function handles both synchronous and asynchronous validation,
|
|
42
|
+
* as StandardSchemaV1 allows either. It returns a discriminated union
|
|
43
|
+
* for easy handling of success/failure cases.
|
|
44
|
+
*
|
|
45
|
+
* @param schema - The StandardSchemaV1 schema to validate against
|
|
46
|
+
* @param value - The value to validate
|
|
47
|
+
* @returns A promise resolving to either `{ ok: true, value }` or `{ ok: false, issues }`
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { z } from "zod"
|
|
52
|
+
*
|
|
53
|
+
* const result = await validateStandard(z.string(), "hello")
|
|
54
|
+
* if (result.ok) {
|
|
55
|
+
* console.log(result.value) // "hello"
|
|
56
|
+
* } else {
|
|
57
|
+
* console.error(result.issues)
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @since 0.1.0
|
|
62
|
+
*/
|
|
63
|
+
export declare function validateStandard<I, O>(schema: StandardSchemaV1<I, O>, value: I): Promise<ValidationResult<O>>;
|
|
64
|
+
/**
|
|
65
|
+
* Context for parsing operations, used to generate meaningful error messages.
|
|
66
|
+
*
|
|
67
|
+
* @since 0.1.0
|
|
68
|
+
*/
|
|
69
|
+
export interface ParseContext {
|
|
70
|
+
/** Name of the script being executed */
|
|
71
|
+
readonly scriptName: string;
|
|
72
|
+
/** Path to the field being validated (e.g., "keys.userId" or "args.limit") */
|
|
73
|
+
readonly path: string;
|
|
74
|
+
/** Type of value being parsed: "input" for keys/args, "return" for script response */
|
|
75
|
+
readonly type: "input" | "return";
|
|
76
|
+
/** Raw value (only for return validation, used in error reporting) */
|
|
77
|
+
readonly raw?: unknown;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validates a value and throws a descriptive error on failure.
|
|
81
|
+
*
|
|
82
|
+
* This is a convenience wrapper around `validateStandard` that throws
|
|
83
|
+
* appropriate error types based on the context.
|
|
84
|
+
*
|
|
85
|
+
* @param schema - The StandardSchemaV1 schema to validate against
|
|
86
|
+
* @param value - The value to validate
|
|
87
|
+
* @param context - Context for error messages
|
|
88
|
+
* @returns The validated and potentially transformed value
|
|
89
|
+
* @throws {Error} When validation fails
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // For input validation:
|
|
94
|
+
* const validated = await parseStandard(schema, input, {
|
|
95
|
+
* scriptName: "myScript",
|
|
96
|
+
* path: "args.limit",
|
|
97
|
+
* type: "input"
|
|
98
|
+
* })
|
|
99
|
+
*
|
|
100
|
+
* // For return validation:
|
|
101
|
+
* const result = await parseStandard(schema, rawResult, {
|
|
102
|
+
* scriptName: "myScript",
|
|
103
|
+
* path: "return",
|
|
104
|
+
* type: "return",
|
|
105
|
+
* raw: rawResult
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @since 0.1.0
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseStandard<I, O>(schema: StandardSchemaV1<I, O>, value: I, context: ParseContext): Promise<O>;
|
|
112
|
+
//# sourceMappingURL=standard-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAA;CAC3C;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;IACjB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;IAClB,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAA;CAC5C;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAA;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EACzC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAC9B,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAsB9B;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAA;IACjC,sEAAsE;IACtE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,CAAC,EACtC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAC9B,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,CAAC,CAAC,CAkBZ"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* Represents any StandardSchemaV1 schema with arbitrary input and output types.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
*/
|
|
7
|
+
export type AnyStandardSchema = StandardSchemaV1<unknown, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the input type from a StandardSchemaV1 schema.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam S - The StandardSchemaV1 schema type
|
|
12
|
+
* @returns The input type that the schema accepts for validation
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // With Zod:
|
|
17
|
+
* type Input = StdInput<typeof z.string()> // string
|
|
18
|
+
* type Input2 = StdInput<typeof z.number().transform(String)> // number
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
*/
|
|
23
|
+
export type StdInput<S extends AnyStandardSchema> = S extends StandardSchemaV1<infer I, unknown> ? I : never;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the output type from a StandardSchemaV1 schema.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam S - The StandardSchemaV1 schema type
|
|
28
|
+
* @returns The output type after validation and transformation
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // With Zod:
|
|
33
|
+
* type Output = StdOutput<typeof z.string()> // string
|
|
34
|
+
* type Output2 = StdOutput<typeof z.number().transform(String)> // string
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
*/
|
|
39
|
+
export type StdOutput<S extends AnyStandardSchema> = S extends StandardSchemaV1<unknown, infer O> ? O : never;
|
|
40
|
+
/**
|
|
41
|
+
* A StandardSchemaV1 schema that outputs a string.
|
|
42
|
+
* Used for keys and args which must be strings when sent to Redis.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
*/
|
|
46
|
+
export type StringOutSchema = StandardSchemaV1<unknown, string>;
|
|
47
|
+
/**
|
|
48
|
+
* A record of named schemas that all output strings.
|
|
49
|
+
* Used for defining keys and args in script definitions.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.1.0
|
|
52
|
+
*/
|
|
53
|
+
export type StringSchemaRecord = Record<string, StringOutSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* Maps a record of schemas to their input types.
|
|
56
|
+
*
|
|
57
|
+
* @typeParam T - Record of StandardSchemaV1 schemas
|
|
58
|
+
* @returns Object type with same keys but input types as values
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* type Inputs = InputsOf<{
|
|
63
|
+
* key: typeof z.string(),
|
|
64
|
+
* limit: typeof z.number().transform(String)
|
|
65
|
+
* }>
|
|
66
|
+
* // { key: string; limit: number }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @since 0.1.0
|
|
70
|
+
*/
|
|
71
|
+
export type InputsOf<T extends Record<string, AnyStandardSchema>> = {
|
|
72
|
+
[K in keyof T]: StdInput<T[K]>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Maps a record of schemas to their output types.
|
|
76
|
+
*
|
|
77
|
+
* @typeParam T - Record of StandardSchemaV1 schemas
|
|
78
|
+
* @returns Object type with same keys but output types as values
|
|
79
|
+
*
|
|
80
|
+
* @since 0.1.0
|
|
81
|
+
*/
|
|
82
|
+
export type OutputsOf<T extends Record<string, AnyStandardSchema>> = {
|
|
83
|
+
[K in keyof T]: StdOutput<T[K]>;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Computes the input payload shape required by `run()`, depending on whether
|
|
87
|
+
* keys and/or args are defined (non-empty records).
|
|
88
|
+
*
|
|
89
|
+
* - If both are empty: `{}`
|
|
90
|
+
* - If only keys defined: `{ keys: ... }`
|
|
91
|
+
* - If only args defined: `{ args: ... }`
|
|
92
|
+
* - If both defined: `{ keys: ..., args: ... }`
|
|
93
|
+
*
|
|
94
|
+
* @typeParam K - The keys schema record
|
|
95
|
+
* @typeParam A - The args schema record
|
|
96
|
+
*
|
|
97
|
+
* @since 0.1.0
|
|
98
|
+
*/
|
|
99
|
+
export type ScriptCallInput<K extends StringSchemaRecord, A extends StringSchemaRecord> = (keyof K extends never ? object : {
|
|
100
|
+
keys: InputsOf<K>;
|
|
101
|
+
}) & (keyof A extends never ? object : {
|
|
102
|
+
args: InputsOf<A>;
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* Rest-parameter tuple type for `run()` method.
|
|
106
|
+
*
|
|
107
|
+
* - When no keys and no args: `[]` (no second argument)
|
|
108
|
+
* - Otherwise: `[input: ScriptCallInput<K, A>]`
|
|
109
|
+
*
|
|
110
|
+
* This enables clean call signatures:
|
|
111
|
+
* - `run(redis)` when keys and args are both empty
|
|
112
|
+
* - `run(redis, { keys, args })` otherwise
|
|
113
|
+
*
|
|
114
|
+
* @typeParam K - The keys schema record
|
|
115
|
+
* @typeParam A - The args schema record
|
|
116
|
+
*
|
|
117
|
+
* @since 0.1.0
|
|
118
|
+
*/
|
|
119
|
+
export type ScriptCallArgs<K extends StringSchemaRecord, A extends StringSchemaRecord> = keyof ScriptCallInput<K, A> extends never ? [] : [input: ScriptCallInput<K, A>];
|
|
120
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAElE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,iBAAiB,IAAI,CAAC,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAC5F,CAAC,GACD,KAAK,CAAA;AAET;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,iBAAiB,IAAI,CAAC,SAAS,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAC7F,CAAC,GACD,KAAK,CAAA;AAET;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAEhE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI;KACjE,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,IAAI;KAClE,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,kBAAkB,IAC1B,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,GAC1D,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAAA;AAE1D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,kBAAkB,IAC1B,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The current version of the upstash-lua library.
|
|
3
|
+
* Follows semantic versioning (semver).
|
|
4
|
+
*
|
|
5
|
+
* This constant is useful for:
|
|
6
|
+
* - Debugging: knowing which version is in use
|
|
7
|
+
* - Logging: including version in log messages
|
|
8
|
+
* - Compatibility checks: comparing versions programmatically
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { VERSION } from "upstash-lua"
|
|
13
|
+
* console.log(`Using upstash-lua v${VERSION}`)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @since 0.1.0
|
|
17
|
+
*/
|
|
18
|
+
export declare const VERSION: "0.3.0";
|
|
19
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,OAAO,EAAG,OAAgB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "upstash-lua",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Type-safe Lua scripts for Upstash with StandardSchema validation",
|
|
5
|
+
"author": "Villiam Strandh",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node && bun run build:types",
|
|
23
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
24
|
+
"test": "bun test",
|
|
25
|
+
"prepublishOnly": "bun run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"upstash",
|
|
29
|
+
"redis",
|
|
30
|
+
"lua",
|
|
31
|
+
"scripts",
|
|
32
|
+
"typescript",
|
|
33
|
+
"zod",
|
|
34
|
+
"validation",
|
|
35
|
+
"standard-schema"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": ""
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/bun": "latest",
|
|
46
|
+
"zod": "^4.3.5"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"typescript": "^5"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@standard-schema/spec": "^1.1.0"
|
|
53
|
+
}
|
|
54
|
+
}
|