@superblocksteam/sdk-api 2.0.105 → 2.0.106-next.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.
- package/README.md +439 -89
- package/dist/api/definition.d.ts +11 -6
- package/dist/api/definition.d.ts.map +1 -1
- package/dist/api/definition.js +19 -12
- package/dist/api/definition.js.map +1 -1
- package/dist/api/definition.test.js +39 -15
- package/dist/api/definition.test.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +10 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/integrations/base/index.d.ts +2 -1
- package/dist/integrations/base/index.d.ts.map +1 -1
- package/dist/integrations/base/index.js +1 -0
- package/dist/integrations/base/index.js.map +1 -1
- package/dist/integrations/base/rest-api-client-base.d.ts +48 -0
- package/dist/integrations/base/rest-api-client-base.d.ts.map +1 -0
- package/dist/integrations/base/rest-api-client-base.js +98 -0
- package/dist/integrations/base/rest-api-client-base.js.map +1 -0
- package/dist/integrations/base/rest-api-integration-client.d.ts +10 -20
- package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.js +10 -65
- package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
- package/dist/integrations/box/types.d.ts +1 -1
- package/dist/integrations/declarations.d.ts +5 -73
- package/dist/integrations/declarations.d.ts.map +1 -1
- package/dist/integrations/declarations.js +5 -68
- package/dist/integrations/declarations.js.map +1 -1
- package/dist/integrations/documentation.test.js +0 -2
- package/dist/integrations/documentation.test.js.map +1 -1
- package/dist/integrations/googledrive/types.d.ts +1 -1
- package/dist/integrations/index.d.ts +1 -11
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +1 -7
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/registry.d.ts +1 -11
- package/dist/integrations/registry.d.ts.map +1 -1
- package/dist/integrations/registry.js +0 -29
- package/dist/integrations/registry.js.map +1 -1
- package/dist/integrations/slack/client.d.ts +13 -9
- package/dist/integrations/slack/client.d.ts.map +1 -1
- package/dist/integrations/slack/client.js +60 -8
- package/dist/integrations/slack/client.js.map +1 -1
- package/dist/integrations/slack/client.test.d.ts +11 -0
- package/dist/integrations/slack/client.test.d.ts.map +1 -0
- package/dist/integrations/slack/client.test.js +368 -0
- package/dist/integrations/slack/client.test.js.map +1 -0
- package/dist/integrations/slack/index.d.ts +2 -1
- package/dist/integrations/slack/index.d.ts.map +1 -1
- package/dist/integrations/slack/index.js +1 -0
- package/dist/integrations/slack/index.js.map +1 -1
- package/dist/integrations/slack/types.d.ts +127 -28
- package/dist/integrations/slack/types.d.ts.map +1 -1
- package/dist/integrations/slack/types.js +27 -1
- package/dist/integrations/slack/types.js.map +1 -1
- package/dist/integrations/snowflake/client.d.ts +2 -2
- package/dist/integrations/snowflake/client.js +2 -2
- package/dist/runtime/context.d.ts +1 -1
- package/dist/runtime/executor.d.ts +2 -2
- package/dist/types.d.ts +15 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/api/definition.test.ts +40 -15
- package/src/api/definition.ts +19 -12
- package/src/errors.ts +1 -1
- package/src/index.ts +13 -33
- package/src/integrations/asana/README.md +12 -12
- package/src/integrations/base/index.ts +2 -1
- package/src/integrations/base/rest-api-client-base.ts +134 -0
- package/src/integrations/base/rest-api-integration-client.ts +12 -89
- package/src/integrations/bitbucket/README.md +19 -19
- package/src/integrations/box/README.md +24 -24
- package/src/integrations/box/types.ts +1 -1
- package/src/integrations/circleci/README.md +18 -18
- package/src/integrations/declarations.ts +5 -105
- package/src/integrations/documentation.test.ts +0 -2
- package/src/integrations/googledrive/README.md +25 -22
- package/src/integrations/googledrive/types.ts +1 -1
- package/src/integrations/graphql/README.md +2 -2
- package/src/integrations/groq/README.md +8 -8
- package/src/integrations/index.ts +0 -51
- package/src/integrations/mongodb/README.md +65 -12
- package/src/integrations/perplexity/README.md +39 -48
- package/src/integrations/registry.ts +1 -39
- package/src/integrations/salesforce/README.md +11 -9
- package/src/integrations/slack/README.md +62 -19
- package/src/integrations/slack/client.test.ts +553 -0
- package/src/integrations/slack/client.ts +92 -12
- package/src/integrations/slack/index.ts +6 -1
- package/src/integrations/slack/types.ts +142 -29
- package/src/integrations/snowflake/client.ts +2 -2
- package/src/integrations/zoom/README.md +15 -15
- package/src/runtime/context.ts +1 -1
- package/src/runtime/executor.ts +2 -2
- package/src/types.ts +15 -6
- package/dist/integrations/couchbase/client.d.ts +0 -36
- package/dist/integrations/couchbase/client.d.ts.map +0 -1
- package/dist/integrations/couchbase/client.js +0 -148
- package/dist/integrations/couchbase/client.js.map +0 -1
- package/dist/integrations/couchbase/index.d.ts +0 -8
- package/dist/integrations/couchbase/index.d.ts.map +0 -1
- package/dist/integrations/couchbase/index.js +0 -7
- package/dist/integrations/couchbase/index.js.map +0 -1
- package/dist/integrations/couchbase/types.d.ts +0 -100
- package/dist/integrations/couchbase/types.d.ts.map +0 -1
- package/dist/integrations/couchbase/types.js +0 -5
- package/dist/integrations/couchbase/types.js.map +0 -1
- package/dist/integrations/kafka/client.d.ts +0 -25
- package/dist/integrations/kafka/client.d.ts.map +0 -1
- package/dist/integrations/kafka/client.js +0 -124
- package/dist/integrations/kafka/client.js.map +0 -1
- package/dist/integrations/kafka/index.d.ts +0 -8
- package/dist/integrations/kafka/index.d.ts.map +0 -1
- package/dist/integrations/kafka/index.js +0 -7
- package/dist/integrations/kafka/index.js.map +0 -1
- package/dist/integrations/kafka/types.d.ts +0 -113
- package/dist/integrations/kafka/types.d.ts.map +0 -1
- package/dist/integrations/kafka/types.js +0 -5
- package/dist/integrations/kafka/types.js.map +0 -1
- package/dist/integrations/kinesis/client.d.ts +0 -31
- package/dist/integrations/kinesis/client.d.ts.map +0 -1
- package/dist/integrations/kinesis/client.js +0 -101
- package/dist/integrations/kinesis/client.js.map +0 -1
- package/dist/integrations/kinesis/index.d.ts +0 -8
- package/dist/integrations/kinesis/index.d.ts.map +0 -1
- package/dist/integrations/kinesis/index.js +0 -7
- package/dist/integrations/kinesis/index.js.map +0 -1
- package/dist/integrations/kinesis/types.d.ts +0 -97
- package/dist/integrations/kinesis/types.d.ts.map +0 -1
- package/dist/integrations/kinesis/types.js +0 -7
- package/dist/integrations/kinesis/types.js.map +0 -1
- package/dist/integrations/python/client.d.ts +0 -42
- package/dist/integrations/python/client.d.ts.map +0 -1
- package/dist/integrations/python/client.js +0 -89
- package/dist/integrations/python/client.js.map +0 -1
- package/dist/integrations/python/client.test.d.ts +0 -5
- package/dist/integrations/python/client.test.d.ts.map +0 -1
- package/dist/integrations/python/client.test.js +0 -214
- package/dist/integrations/python/client.test.js.map +0 -1
- package/dist/integrations/python/index.d.ts +0 -6
- package/dist/integrations/python/index.d.ts.map +0 -1
- package/dist/integrations/python/index.js +0 -5
- package/dist/integrations/python/index.js.map +0 -1
- package/dist/integrations/python/types.d.ts +0 -85
- package/dist/integrations/python/types.d.ts.map +0 -1
- package/dist/integrations/python/types.js +0 -5
- package/dist/integrations/python/types.js.map +0 -1
- package/dist/integrations/redis/client.d.ts +0 -43
- package/dist/integrations/redis/client.d.ts.map +0 -1
- package/dist/integrations/redis/client.js +0 -142
- package/dist/integrations/redis/client.js.map +0 -1
- package/dist/integrations/redis/index.d.ts +0 -8
- package/dist/integrations/redis/index.d.ts.map +0 -1
- package/dist/integrations/redis/index.js +0 -7
- package/dist/integrations/redis/index.js.map +0 -1
- package/dist/integrations/redis/types.d.ts +0 -137
- package/dist/integrations/redis/types.d.ts.map +0 -1
- package/dist/integrations/redis/types.js +0 -5
- package/dist/integrations/redis/types.js.map +0 -1
- package/src/integrations/couchbase/README.md +0 -138
- package/src/integrations/couchbase/client.ts +0 -225
- package/src/integrations/couchbase/index.ts +0 -8
- package/src/integrations/couchbase/types.ts +0 -126
- package/src/integrations/kafka/README.md +0 -144
- package/src/integrations/kafka/client.ts +0 -216
- package/src/integrations/kafka/index.ts +0 -14
- package/src/integrations/kafka/types.ts +0 -128
- package/src/integrations/kinesis/README.md +0 -153
- package/src/integrations/kinesis/client.ts +0 -146
- package/src/integrations/kinesis/index.ts +0 -14
- package/src/integrations/kinesis/types.ts +0 -114
- package/src/integrations/python/README.md +0 -566
- package/src/integrations/python/client.test.ts +0 -341
- package/src/integrations/python/client.ts +0 -136
- package/src/integrations/python/index.ts +0 -6
- package/src/integrations/python/types.ts +0 -92
- package/src/integrations/redis/README.md +0 -200
- package/src/integrations/redis/client.ts +0 -208
- package/src/integrations/redis/index.ts +0 -8
- package/src/integrations/redis/types.ts +0 -167
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
# Redis Client
|
|
2
|
-
|
|
3
|
-
Execute Redis commands with full type safety and runtime validation.
|
|
4
|
-
|
|
5
|
-
## Methods
|
|
6
|
-
|
|
7
|
-
| Method | Description |
|
|
8
|
-
| ------------------------------------- | --------------------------- |
|
|
9
|
-
| `command(command, schema, metadata?)` | Execute a raw Redis command |
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### GET Command
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { api, z, redis } from "@superblocksteam/sdk-api";
|
|
17
|
-
|
|
18
|
-
// Integration ID from the integrations panel
|
|
19
|
-
const PROD_REDIS = "a1b2c3d4-5678-90ab-cdef-redis0000001";
|
|
20
|
-
|
|
21
|
-
export default api({
|
|
22
|
-
integrations: {
|
|
23
|
-
redis: redis(PROD_REDIS),
|
|
24
|
-
},
|
|
25
|
-
name: "RedisExample",
|
|
26
|
-
input: z.object({
|
|
27
|
-
key: z.string(),
|
|
28
|
-
}),
|
|
29
|
-
output: z.object({
|
|
30
|
-
value: z.string().nullable(),
|
|
31
|
-
}),
|
|
32
|
-
async run(ctx, { key }) {
|
|
33
|
-
const value = await ctx.integrations.redis.command(
|
|
34
|
-
`GET ${key}`,
|
|
35
|
-
z.string().nullable(),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return { value };
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### SET Command
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
await ctx.integrations.redis.command('SET mykey "hello"', z.string());
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### SET with Expiration
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
// Set with 1 hour TTL
|
|
53
|
-
await ctx.integrations.redis.command('SET mykey "hello" EX 3600', z.string());
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### DELETE Command
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
const deleted = await ctx.integrations.redis.command("DEL mykey", z.number());
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Hash Operations
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
// HSET
|
|
66
|
-
await ctx.integrations.redis.command(
|
|
67
|
-
'HSET user:1 name "John" age "30"',
|
|
68
|
-
z.number(),
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// HGET
|
|
72
|
-
const name = await ctx.integrations.redis.command(
|
|
73
|
-
"HGET user:1 name",
|
|
74
|
-
z.string().nullable(),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// HGETALL
|
|
78
|
-
const user = await ctx.integrations.redis.command(
|
|
79
|
-
"HGETALL user:1",
|
|
80
|
-
z.record(z.string()),
|
|
81
|
-
);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### List Operations
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
// LPUSH
|
|
88
|
-
await ctx.integrations.redis.command('LPUSH mylist "a" "b" "c"', z.number());
|
|
89
|
-
|
|
90
|
-
// LRANGE
|
|
91
|
-
const items = await ctx.integrations.redis.command(
|
|
92
|
-
"LRANGE mylist 0 -1",
|
|
93
|
-
z.array(z.string()),
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
// LLEN
|
|
97
|
-
const length = await ctx.integrations.redis.command("LLEN mylist", z.number());
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Set Operations
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
// SADD
|
|
104
|
-
await ctx.integrations.redis.command('SADD myset "a" "b" "c"', z.number());
|
|
105
|
-
|
|
106
|
-
// SMEMBERS
|
|
107
|
-
const members = await ctx.integrations.redis.command(
|
|
108
|
-
"SMEMBERS myset",
|
|
109
|
-
z.array(z.string()),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
// SISMEMBER
|
|
113
|
-
const isMember = await ctx.integrations.redis.command(
|
|
114
|
-
'SISMEMBER myset "a"',
|
|
115
|
-
z.number(),
|
|
116
|
-
);
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Counter Operations
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// INCR
|
|
123
|
-
const newValue = await ctx.integrations.redis.command(
|
|
124
|
-
"INCR counter",
|
|
125
|
-
z.number(),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// INCRBY
|
|
129
|
-
const newValue2 = await ctx.integrations.redis.command(
|
|
130
|
-
"INCRBY counter 5",
|
|
131
|
-
z.number(),
|
|
132
|
-
);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### TTL Operations
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
// Set expiration
|
|
139
|
-
await ctx.integrations.redis.command("EXPIRE mykey 3600", z.number());
|
|
140
|
-
|
|
141
|
-
// Get TTL
|
|
142
|
-
const ttl = await ctx.integrations.redis.command("TTL mykey", z.number());
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Trace Metadata
|
|
146
|
-
|
|
147
|
-
All methods accept an optional `metadata` parameter as the last argument for diagnostics labeling. See the [root SDK README](../../../README.md#trace-metadata) for details.
|
|
148
|
-
|
|
149
|
-
## Common Pitfalls
|
|
150
|
-
|
|
151
|
-
### Quote String Values
|
|
152
|
-
|
|
153
|
-
String values with spaces need quotes:
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
// CORRECT
|
|
157
|
-
await ctx.integrations.redis.command('SET mykey "hello world"', z.string());
|
|
158
|
-
|
|
159
|
-
// WRONG - will fail
|
|
160
|
-
await ctx.integrations.redis.command("SET mykey hello world", z.string());
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### Nullable Results
|
|
164
|
-
|
|
165
|
-
GET returns null for non-existent keys:
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
const value = await ctx.integrations.redis.command(
|
|
169
|
-
"GET nonexistent",
|
|
170
|
-
z.string().nullable(),
|
|
171
|
-
);
|
|
172
|
-
// value is null
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Error Handling
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
import {
|
|
179
|
-
RestApiValidationError,
|
|
180
|
-
IntegrationError,
|
|
181
|
-
} from "@superblocksteam/sdk-api";
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
const value = await ctx.integrations.redis.command(
|
|
185
|
-
"GET mykey",
|
|
186
|
-
z.string().nullable(),
|
|
187
|
-
);
|
|
188
|
-
} catch (error) {
|
|
189
|
-
if (error instanceof RestApiValidationError) {
|
|
190
|
-
console.error("Validation failed:", error.details.zodError);
|
|
191
|
-
} else if (error instanceof IntegrationError) {
|
|
192
|
-
console.error("Redis error:", error.message);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## API Reference
|
|
198
|
-
|
|
199
|
-
- [Redis Commands](https://redis.io/commands/)
|
|
200
|
-
- [Redis Data Types](https://redis.io/docs/data-types/)
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redis client implementation.
|
|
3
|
-
*
|
|
4
|
-
* Uses the native Redis plugin type from @superblocksteam/types.
|
|
5
|
-
* Supports raw Redis commands and typed structured operations
|
|
6
|
-
* (get, set, del, keys, hget, hset, hgetall, etc.).
|
|
7
|
-
*
|
|
8
|
-
* Request format matches the Redis plugin proto's oneof structure:
|
|
9
|
-
* - Raw: `{ raw: { singleton: { query: "..." } } }`
|
|
10
|
-
* - Structured: `{ structured: { set: { key: "...", value: "..." } } }`
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { z } from "zod";
|
|
14
|
-
|
|
15
|
-
import { RestApiValidationError } from "../../errors.js";
|
|
16
|
-
import { IntegrationError } from "../../runtime/errors.js";
|
|
17
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
18
|
-
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
19
|
-
import type { RedisClient } from "./types.js";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Build a raw Redis command request matching the proto JSON format.
|
|
23
|
-
*
|
|
24
|
-
* Proto structure: `oneof command_type { Raw raw = 3; }`
|
|
25
|
-
* Raw structure: `oneof action { Singleton singleton = 1; }`
|
|
26
|
-
*/
|
|
27
|
-
function buildRawRequest(command: string): Record<string, unknown> {
|
|
28
|
-
return {
|
|
29
|
-
raw: {
|
|
30
|
-
singleton: {
|
|
31
|
-
query: command,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Build a structured Redis command request matching the proto JSON format.
|
|
39
|
-
*
|
|
40
|
-
* Proto structure: `oneof command_type { Structured structured = 4; }`
|
|
41
|
-
* Structured structure: `oneof action { Get get = 6; Set set = 7; ... }`
|
|
42
|
-
*
|
|
43
|
-
* @param actionName - The structured action name (e.g., 'get', 'set')
|
|
44
|
-
* @param value - The action-specific parameters
|
|
45
|
-
*/
|
|
46
|
-
function buildStructuredRequest(
|
|
47
|
-
actionName: string,
|
|
48
|
-
value: Record<string, unknown>,
|
|
49
|
-
): Record<string, unknown> {
|
|
50
|
-
return {
|
|
51
|
-
structured: {
|
|
52
|
-
[actionName]: value,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Internal implementation of RedisClient.
|
|
59
|
-
*
|
|
60
|
-
* Provides both raw and structured Redis command execution.
|
|
61
|
-
*/
|
|
62
|
-
export class RedisClientImpl implements RedisClient, IntegrationClientImpl {
|
|
63
|
-
readonly config: IntegrationConfig;
|
|
64
|
-
private readonly executeQuery: QueryExecutor;
|
|
65
|
-
|
|
66
|
-
constructor(config: IntegrationConfig, executeQuery: QueryExecutor) {
|
|
67
|
-
this.config = config;
|
|
68
|
-
this.executeQuery = executeQuery;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get name(): string {
|
|
72
|
-
return this.config.name;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get pluginId(): string {
|
|
76
|
-
return this.config.pluginId;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Execute a request and wrap errors.
|
|
81
|
-
*/
|
|
82
|
-
private async exec(
|
|
83
|
-
request: Record<string, unknown>,
|
|
84
|
-
operation: string,
|
|
85
|
-
metadata?: TraceMetadata,
|
|
86
|
-
): Promise<unknown> {
|
|
87
|
-
try {
|
|
88
|
-
return await this.executeQuery(request, undefined, metadata);
|
|
89
|
-
} catch (error) {
|
|
90
|
-
if (
|
|
91
|
-
error instanceof RestApiValidationError ||
|
|
92
|
-
error instanceof IntegrationError
|
|
93
|
-
) {
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
throw new IntegrationError(this.config.name, operation, error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async command<T>(
|
|
102
|
-
command: string,
|
|
103
|
-
schema: z.ZodSchema<T>,
|
|
104
|
-
metadata?: TraceMetadata,
|
|
105
|
-
): Promise<T> {
|
|
106
|
-
const request = buildRawRequest(command);
|
|
107
|
-
const rawResult = await this.exec(request, "command", metadata);
|
|
108
|
-
|
|
109
|
-
// The Redis plugin wraps raw command results in { response: ... }.
|
|
110
|
-
// Unwrap to the actual value so callers can validate against the expected type.
|
|
111
|
-
const result =
|
|
112
|
-
rawResult !== null &&
|
|
113
|
-
typeof rawResult === "object" &&
|
|
114
|
-
"response" in (rawResult as object)
|
|
115
|
-
? (rawResult as { response: unknown }).response
|
|
116
|
-
: rawResult;
|
|
117
|
-
|
|
118
|
-
const parseResult = schema.safeParse(result);
|
|
119
|
-
|
|
120
|
-
if (!parseResult.success) {
|
|
121
|
-
throw new RestApiValidationError(
|
|
122
|
-
`Result validation failed: ${parseResult.error.message}`,
|
|
123
|
-
{
|
|
124
|
-
zodError: parseResult.error,
|
|
125
|
-
data: result,
|
|
126
|
-
},
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return parseResult.data;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async get(key: string, metadata?: TraceMetadata): Promise<unknown> {
|
|
134
|
-
const request = buildStructuredRequest("get", { key });
|
|
135
|
-
return this.exec(request, "get", metadata);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async set(
|
|
139
|
-
key: string,
|
|
140
|
-
value: string,
|
|
141
|
-
expirationMs?: number,
|
|
142
|
-
metadata?: TraceMetadata,
|
|
143
|
-
): Promise<unknown> {
|
|
144
|
-
const params: Record<string, unknown> = { key, value };
|
|
145
|
-
if (expirationMs !== undefined) {
|
|
146
|
-
params.expirationMs = expirationMs;
|
|
147
|
-
}
|
|
148
|
-
const request = buildStructuredRequest("set", params);
|
|
149
|
-
return this.exec(request, "set", metadata);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async del(key: string, metadata?: TraceMetadata): Promise<unknown> {
|
|
153
|
-
const request = buildStructuredRequest("del", { key });
|
|
154
|
-
return this.exec(request, "del", metadata);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async keys(pattern: string, metadata?: TraceMetadata): Promise<unknown> {
|
|
158
|
-
const request = buildStructuredRequest("keys", { pattern });
|
|
159
|
-
return this.exec(request, "keys", metadata);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async hget(
|
|
163
|
-
key: string,
|
|
164
|
-
field: string,
|
|
165
|
-
metadata?: TraceMetadata,
|
|
166
|
-
): Promise<unknown> {
|
|
167
|
-
const request = buildStructuredRequest("hget", { key, field });
|
|
168
|
-
return this.exec(request, "hget", metadata);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async hset(
|
|
172
|
-
key: string,
|
|
173
|
-
field: string,
|
|
174
|
-
value: string,
|
|
175
|
-
metadata?: TraceMetadata,
|
|
176
|
-
): Promise<unknown> {
|
|
177
|
-
const request = buildStructuredRequest("hset", { key, field, value });
|
|
178
|
-
return this.exec(request, "hset", metadata);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async hgetall(key: string, metadata?: TraceMetadata): Promise<unknown> {
|
|
182
|
-
const request = buildStructuredRequest("hgetall", { key });
|
|
183
|
-
return this.exec(request, "hgetall", metadata);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async hdel(
|
|
187
|
-
key: string,
|
|
188
|
-
field: string,
|
|
189
|
-
metadata?: TraceMetadata,
|
|
190
|
-
): Promise<unknown> {
|
|
191
|
-
const request = buildStructuredRequest("hdel", { key, field });
|
|
192
|
-
return this.exec(request, "hdel", metadata);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async expire(
|
|
196
|
-
key: string,
|
|
197
|
-
seconds: number,
|
|
198
|
-
metadata?: TraceMetadata,
|
|
199
|
-
): Promise<unknown> {
|
|
200
|
-
const request = buildStructuredRequest("expire", { key, seconds });
|
|
201
|
-
return this.exec(request, "expire", metadata);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async ttl(key: string, metadata?: TraceMetadata): Promise<unknown> {
|
|
205
|
-
const request = buildStructuredRequest("ttl", { key });
|
|
206
|
-
return this.exec(request, "ttl", metadata);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redis client types.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { z } from "zod";
|
|
6
|
-
|
|
7
|
-
import type { BaseIntegrationClient } from "../../types.js";
|
|
8
|
-
import type { TraceMetadata } from "../registry.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Redis client for executing commands.
|
|
12
|
-
*
|
|
13
|
-
* Provides typed methods for common Redis operations as well as a
|
|
14
|
-
* generic command() method for executing raw Redis commands.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Declare in api(): integrations: { redis: redis(INTEGRATION_ID) }
|
|
19
|
-
* // In run(), access via ctx.integrations.redis
|
|
20
|
-
*
|
|
21
|
-
* // Typed string operations
|
|
22
|
-
* await redis.set('user:1', 'Alice');
|
|
23
|
-
* const name = await redis.get('user:1');
|
|
24
|
-
*
|
|
25
|
-
* // Typed hash operations
|
|
26
|
-
* await redis.hset('user:1', 'name', 'Alice');
|
|
27
|
-
* const val = await redis.hget('user:1', 'name');
|
|
28
|
-
* const all = await redis.hgetall('user:1');
|
|
29
|
-
*
|
|
30
|
-
* // Key operations
|
|
31
|
-
* await redis.del('user:1');
|
|
32
|
-
* const userKeys = await redis.keys('user:*');
|
|
33
|
-
*
|
|
34
|
-
* // Raw command for anything not covered by typed methods
|
|
35
|
-
* const result = await redis.command(
|
|
36
|
-
* 'LRANGE mylist 0 -1',
|
|
37
|
-
* z.array(z.string())
|
|
38
|
-
* );
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export interface RedisClient extends BaseIntegrationClient {
|
|
42
|
-
/**
|
|
43
|
-
* Execute a raw Redis command.
|
|
44
|
-
*
|
|
45
|
-
* Use this for commands not covered by the typed methods.
|
|
46
|
-
*
|
|
47
|
-
* @param command - The Redis command string (e.g., "LRANGE mylist 0 -1")
|
|
48
|
-
* @param schema - Zod schema for validating the result
|
|
49
|
-
* @returns The validated result
|
|
50
|
-
*/
|
|
51
|
-
command<T>(
|
|
52
|
-
command: string,
|
|
53
|
-
schema: z.ZodSchema<T>,
|
|
54
|
-
metadata?: TraceMetadata,
|
|
55
|
-
): Promise<T>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Get the value of a key.
|
|
59
|
-
*
|
|
60
|
-
* @param key - The key to get
|
|
61
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
62
|
-
* @returns The value, or null if the key does not exist
|
|
63
|
-
*/
|
|
64
|
-
get(key: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Set the value of a key.
|
|
68
|
-
*
|
|
69
|
-
* @param key - The key to set
|
|
70
|
-
* @param value - The value to set
|
|
71
|
-
* @param expirationMs - Optional expiration time in milliseconds
|
|
72
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
73
|
-
* @returns The result (typically "OK")
|
|
74
|
-
*/
|
|
75
|
-
set(
|
|
76
|
-
key: string,
|
|
77
|
-
value: string,
|
|
78
|
-
expirationMs?: number,
|
|
79
|
-
metadata?: TraceMetadata,
|
|
80
|
-
): Promise<unknown>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Delete a key.
|
|
84
|
-
*
|
|
85
|
-
* @param key - The key to delete
|
|
86
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
87
|
-
* @returns The number of keys removed
|
|
88
|
-
*/
|
|
89
|
-
del(key: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Find all keys matching a pattern.
|
|
93
|
-
*
|
|
94
|
-
* @param pattern - The glob-style pattern to match (e.g., "user:*")
|
|
95
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
96
|
-
* @returns Array of matching keys
|
|
97
|
-
*/
|
|
98
|
-
keys(pattern: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the value of a hash field.
|
|
102
|
-
*
|
|
103
|
-
* @param key - The hash key
|
|
104
|
-
* @param field - The field name
|
|
105
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
106
|
-
* @returns The field value, or null if the field does not exist
|
|
107
|
-
*/
|
|
108
|
-
hget(key: string, field: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Set the value of a hash field.
|
|
112
|
-
*
|
|
113
|
-
* @param key - The hash key
|
|
114
|
-
* @param field - The field name
|
|
115
|
-
* @param value - The value to set
|
|
116
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
117
|
-
* @returns The number of fields that were added
|
|
118
|
-
*/
|
|
119
|
-
hset(
|
|
120
|
-
key: string,
|
|
121
|
-
field: string,
|
|
122
|
-
value: string,
|
|
123
|
-
metadata?: TraceMetadata,
|
|
124
|
-
): Promise<unknown>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Get all fields and values of a hash.
|
|
128
|
-
*
|
|
129
|
-
* @param key - The hash key
|
|
130
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
131
|
-
* @returns Object with all field-value pairs
|
|
132
|
-
*/
|
|
133
|
-
hgetall(key: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Delete a hash field.
|
|
137
|
-
*
|
|
138
|
-
* @param key - The hash key
|
|
139
|
-
* @param field - The field to delete
|
|
140
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
141
|
-
* @returns The number of fields that were removed
|
|
142
|
-
*/
|
|
143
|
-
hdel(key: string, field: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Set expiration on a key.
|
|
147
|
-
*
|
|
148
|
-
* @param key - The key to set expiration on
|
|
149
|
-
* @param seconds - Time to live in seconds
|
|
150
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
151
|
-
* @returns 1 if timeout was set, 0 if key does not exist
|
|
152
|
-
*/
|
|
153
|
-
expire(
|
|
154
|
-
key: string,
|
|
155
|
-
seconds: number,
|
|
156
|
-
metadata?: TraceMetadata,
|
|
157
|
-
): Promise<unknown>;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get the remaining time to live of a key.
|
|
161
|
-
*
|
|
162
|
-
* @param key - The key to check
|
|
163
|
-
* @param metadata - Optional trace metadata for diagnostics
|
|
164
|
-
* @returns TTL in seconds, -2 if key does not exist, -1 if no expiration
|
|
165
|
-
*/
|
|
166
|
-
ttl(key: string, metadata?: TraceMetadata): Promise<unknown>;
|
|
167
|
-
}
|