@superblocksteam/sdk-api 2.0.102 → 2.0.103
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 +47 -41
- package/dist/api/definition.d.ts +1 -1
- package/dist/api/definition.d.ts.map +1 -1
- package/dist/api/definition.js.map +1 -1
- package/dist/api/definition.test.js.map +1 -1
- package/dist/api/streaming.d.ts +1 -1
- package/dist/api/streaming.d.ts.map +1 -1
- package/dist/api/streaming.js.map +1 -1
- package/dist/api/streaming.test.js +2 -2
- package/dist/api/streaming.test.js.map +1 -1
- package/dist/integrations/athena/client.d.ts +1 -1
- package/dist/integrations/athena/client.d.ts.map +1 -1
- package/dist/integrations/athena/client.js.map +1 -1
- package/dist/integrations/athena/types.d.ts.map +1 -1
- package/dist/integrations/base/graphql-integration-client.d.ts +2 -2
- package/dist/integrations/base/graphql-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/graphql-integration-client.js.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.d.ts +3 -3
- package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
- package/dist/integrations/base/types.d.ts.map +1 -1
- package/dist/integrations/bigquery/client.d.ts +1 -1
- package/dist/integrations/bigquery/client.d.ts.map +1 -1
- package/dist/integrations/bigquery/client.js.map +1 -1
- package/dist/integrations/bigquery/types.d.ts.map +1 -1
- package/dist/integrations/cockroachdb/client.d.ts +1 -1
- package/dist/integrations/cockroachdb/client.d.ts.map +1 -1
- package/dist/integrations/cockroachdb/client.js.map +1 -1
- package/dist/integrations/cockroachdb/types.d.ts.map +1 -1
- package/dist/integrations/cosmosdb/client.d.ts +1 -1
- package/dist/integrations/cosmosdb/client.d.ts.map +1 -1
- package/dist/integrations/cosmosdb/client.js.map +1 -1
- package/dist/integrations/cosmosdb/client.test.js.map +1 -1
- package/dist/integrations/cosmosdb/types.d.ts.map +1 -1
- package/dist/integrations/couchbase/client.d.ts +9 -3
- package/dist/integrations/couchbase/client.d.ts.map +1 -1
- package/dist/integrations/couchbase/client.js +27 -33
- package/dist/integrations/couchbase/client.js.map +1 -1
- package/dist/integrations/couchbase/types.d.ts.map +1 -1
- package/dist/integrations/databricks/client.d.ts +1 -1
- package/dist/integrations/databricks/client.d.ts.map +1 -1
- package/dist/integrations/databricks/client.js.map +1 -1
- package/dist/integrations/databricks/types.d.ts.map +1 -1
- package/dist/integrations/declarations.d.ts +36 -36
- package/dist/integrations/declarations.d.ts.map +1 -1
- package/dist/integrations/declarations.test.js.map +1 -1
- package/dist/integrations/dynamodb/client.d.ts +1 -1
- package/dist/integrations/dynamodb/client.d.ts.map +1 -1
- package/dist/integrations/dynamodb/client.js.map +1 -1
- package/dist/integrations/dynamodb/types.d.ts.map +1 -1
- package/dist/integrations/gcs/client.d.ts +1 -1
- package/dist/integrations/gcs/client.d.ts.map +1 -1
- package/dist/integrations/gcs/client.js.map +1 -1
- package/dist/integrations/gcs/types.d.ts.map +1 -1
- package/dist/integrations/graphql/types.d.ts +1 -1
- package/dist/integrations/graphql/types.d.ts.map +1 -1
- package/dist/integrations/gsheets/client.d.ts +1 -1
- package/dist/integrations/gsheets/client.d.ts.map +1 -1
- package/dist/integrations/gsheets/client.js.map +1 -1
- package/dist/integrations/gsheets/types.d.ts.map +1 -1
- package/dist/integrations/kafka/client.d.ts +1 -1
- package/dist/integrations/kafka/client.d.ts.map +1 -1
- package/dist/integrations/kafka/client.js.map +1 -1
- package/dist/integrations/kafka/types.d.ts.map +1 -1
- package/dist/integrations/kinesis/client.d.ts +1 -1
- package/dist/integrations/kinesis/client.d.ts.map +1 -1
- package/dist/integrations/kinesis/client.js.map +1 -1
- package/dist/integrations/lakebase/client.d.ts +1 -1
- package/dist/integrations/lakebase/client.d.ts.map +1 -1
- package/dist/integrations/lakebase/client.js.map +1 -1
- package/dist/integrations/lakebase/types.d.ts.map +1 -1
- package/dist/integrations/mariadb/client.d.ts +1 -1
- package/dist/integrations/mariadb/client.d.ts.map +1 -1
- package/dist/integrations/mariadb/client.js.map +1 -1
- package/dist/integrations/mariadb/types.d.ts.map +1 -1
- package/dist/integrations/mongodb/client.d.ts +1 -1
- package/dist/integrations/mongodb/client.d.ts.map +1 -1
- package/dist/integrations/mongodb/client.js.map +1 -1
- package/dist/integrations/mongodb/types.d.ts.map +1 -1
- package/dist/integrations/mssql/client.d.ts +1 -1
- package/dist/integrations/mssql/client.d.ts.map +1 -1
- package/dist/integrations/mssql/client.js.map +1 -1
- package/dist/integrations/mssql/types.d.ts.map +1 -1
- package/dist/integrations/mysql/client.d.ts +1 -1
- package/dist/integrations/mysql/client.d.ts.map +1 -1
- package/dist/integrations/mysql/client.js.map +1 -1
- package/dist/integrations/mysql/types.d.ts.map +1 -1
- package/dist/integrations/oracledb/client.d.ts +1 -1
- package/dist/integrations/oracledb/client.d.ts.map +1 -1
- package/dist/integrations/oracledb/client.js.map +1 -1
- package/dist/integrations/oracledb/types.d.ts.map +1 -1
- package/dist/integrations/postgres/client.d.ts +2 -2
- package/dist/integrations/postgres/client.d.ts.map +1 -1
- package/dist/integrations/postgres/client.js.map +1 -1
- package/dist/integrations/postgres/types.d.ts.map +1 -1
- package/dist/integrations/python/client.d.ts +2 -2
- package/dist/integrations/python/client.d.ts.map +1 -1
- package/dist/integrations/python/client.js.map +1 -1
- package/dist/integrations/python/client.test.js.map +1 -1
- package/dist/integrations/python/types.d.ts.map +1 -1
- package/dist/integrations/redis/client.d.ts +1 -1
- package/dist/integrations/redis/client.d.ts.map +1 -1
- package/dist/integrations/redis/client.js.map +1 -1
- package/dist/integrations/redis/types.d.ts.map +1 -1
- package/dist/integrations/redshift/client.d.ts +1 -1
- package/dist/integrations/redshift/client.d.ts.map +1 -1
- package/dist/integrations/redshift/client.js.map +1 -1
- package/dist/integrations/redshift/types.d.ts.map +1 -1
- package/dist/integrations/registry.d.ts.map +1 -1
- package/dist/integrations/registry.js +22 -22
- package/dist/integrations/registry.js.map +1 -1
- package/dist/integrations/registry.test.js.map +1 -1
- package/dist/integrations/s3/client.d.ts +1 -1
- package/dist/integrations/s3/client.d.ts.map +1 -1
- package/dist/integrations/s3/client.js.map +1 -1
- package/dist/integrations/s3/types.d.ts +3 -1
- package/dist/integrations/s3/types.d.ts.map +1 -1
- package/dist/integrations/salesforce/client.d.ts +1 -1
- package/dist/integrations/salesforce/client.d.ts.map +1 -1
- package/dist/integrations/salesforce/client.js.map +1 -1
- package/dist/integrations/salesforce/types.d.ts.map +1 -1
- package/dist/integrations/smtp/client.d.ts +1 -1
- package/dist/integrations/smtp/client.d.ts.map +1 -1
- package/dist/integrations/smtp/client.js.map +1 -1
- package/dist/integrations/snowflake/client.d.ts +1 -1
- package/dist/integrations/snowflake/client.d.ts.map +1 -1
- package/dist/integrations/snowflake/client.js.map +1 -1
- package/dist/integrations/snowflake/types.d.ts.map +1 -1
- package/dist/integrations/snowflakepostgres/client.d.ts +1 -1
- package/dist/integrations/snowflakepostgres/client.d.ts.map +1 -1
- package/dist/integrations/snowflakepostgres/client.js.map +1 -1
- package/dist/integrations/snowflakepostgres/types.d.ts.map +1 -1
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/streaming-context.d.ts +2 -2
- package/dist/runtime/streaming-context.d.ts.map +1 -1
- package/dist/runtime/streaming-context.js.map +1 -1
- package/dist/runtime/streaming-executor.d.ts.map +1 -1
- package/dist/runtime/streaming-executor.js +1 -1
- package/dist/runtime/streaming-executor.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/definition.test.ts +1 -0
- package/src/api/definition.ts +1 -1
- package/src/api/streaming.test.ts +3 -2
- package/src/api/streaming.ts +2 -1
- package/src/integrations/athena/client.ts +5 -3
- package/src/integrations/athena/types.ts +1 -0
- package/src/integrations/base/graphql-integration-client.ts +3 -2
- package/src/integrations/base/rest-api-integration-client.ts +9 -7
- package/src/integrations/base/types.ts +1 -0
- package/src/integrations/bigquery/client.ts +5 -3
- package/src/integrations/bigquery/types.ts +1 -0
- package/src/integrations/cockroachdb/client.ts +5 -3
- package/src/integrations/cockroachdb/types.ts +1 -0
- package/src/integrations/cosmosdb/client.test.ts +2 -1
- package/src/integrations/cosmosdb/client.ts +5 -3
- package/src/integrations/cosmosdb/types.ts +1 -0
- package/src/integrations/couchbase/client.ts +34 -46
- package/src/integrations/couchbase/types.ts +1 -0
- package/src/integrations/databricks/client.ts +5 -3
- package/src/integrations/databricks/types.ts +1 -0
- package/src/integrations/declarations.test.ts +1 -0
- package/src/integrations/declarations.ts +36 -36
- package/src/integrations/dynamodb/client.ts +3 -2
- package/src/integrations/dynamodb/types.ts +1 -0
- package/src/integrations/gcs/client.ts +5 -3
- package/src/integrations/gcs/types.ts +1 -0
- package/src/integrations/graphql/types.ts +2 -1
- package/src/integrations/gsheets/client.ts +5 -3
- package/src/integrations/gsheets/types.ts +1 -0
- package/src/integrations/kafka/client.ts +3 -2
- package/src/integrations/kafka/types.ts +1 -0
- package/src/integrations/kinesis/client.ts +2 -2
- package/src/integrations/lakebase/README.md +242 -0
- package/src/integrations/lakebase/client.ts +6 -4
- package/src/integrations/lakebase/types.ts +1 -0
- package/src/integrations/mariadb/client.ts +5 -3
- package/src/integrations/mariadb/types.ts +1 -0
- package/src/integrations/mongodb/client.ts +5 -3
- package/src/integrations/mongodb/types.ts +1 -0
- package/src/integrations/mssql/client.ts +5 -3
- package/src/integrations/mssql/types.ts +1 -0
- package/src/integrations/mysql/client.ts +5 -3
- package/src/integrations/mysql/types.ts +1 -0
- package/src/integrations/oracledb/client.ts +5 -3
- package/src/integrations/oracledb/types.ts +1 -0
- package/src/integrations/postgres/client.ts +6 -4
- package/src/integrations/postgres/types.ts +1 -0
- package/src/integrations/python/client.test.ts +3 -2
- package/src/integrations/python/client.ts +5 -3
- package/src/integrations/python/types.ts +1 -0
- package/src/integrations/redis/client.ts +3 -2
- package/src/integrations/redis/types.ts +1 -0
- package/src/integrations/redshift/client.ts +5 -3
- package/src/integrations/redshift/types.ts +1 -0
- package/src/integrations/registry.test.ts +1 -0
- package/src/integrations/registry.ts +23 -23
- package/src/integrations/restapiintegration/README.md +359 -0
- package/src/integrations/s3/client.ts +5 -3
- package/src/integrations/s3/types.ts +4 -1
- package/src/integrations/salesforce/client.ts +3 -2
- package/src/integrations/salesforce/types.ts +1 -0
- package/src/integrations/smtp/README.md +220 -0
- package/src/integrations/smtp/client.ts +4 -2
- package/src/integrations/snowflake/client.ts +5 -3
- package/src/integrations/snowflake/types.ts +1 -0
- package/src/integrations/snowflakecortex/README.md +216 -0
- package/src/integrations/snowflakepostgres/README.md +233 -0
- package/src/integrations/snowflakepostgres/client.ts +1 -1
- package/src/integrations/snowflakepostgres/types.ts +1 -0
- package/src/runtime/context.ts +10 -10
- package/src/runtime/streaming-context.ts +10 -10
- package/src/runtime/streaming-executor.ts +4 -4
- package/src/types.ts +1 -0
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Uses the native GCS plugin type from @superblocksteam/types.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { z } from "zod";
|
|
8
7
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
|
|
9
10
|
import type { Plugin as GCSPlugin } from "@superblocksteam/types/dist/src/plugins/gcs/v1/plugin_pb";
|
|
10
|
-
|
|
11
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
11
|
+
|
|
12
12
|
import { RestApiValidationError } from "../../errors.js";
|
|
13
13
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
14
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
15
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
14
16
|
import type {
|
|
15
17
|
GCSClient,
|
|
16
18
|
GCSAction,
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* GraphQL client types.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import type { z } from "zod";
|
|
6
|
+
|
|
5
7
|
import type { BaseIntegrationClient } from "../../types.js";
|
|
6
8
|
import type { TraceMetadata } from "../registry.js";
|
|
7
|
-
import type { z } from "zod";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* GraphQL client for executing queries and mutations.
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Uses the native Google Sheets plugin type from @superblocksteam/types.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { z } from "zod";
|
|
8
7
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
|
|
9
10
|
import type { Plugin as GSheetsPlugin } from "@superblocksteam/types/dist/src/plugins/gsheets/v1/plugin_pb";
|
|
10
|
-
|
|
11
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
11
|
+
|
|
12
12
|
import { RestApiValidationError } from "../../errors.js";
|
|
13
13
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
14
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
15
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
14
16
|
import type {
|
|
15
17
|
GoogleSheetsClient,
|
|
16
18
|
GoogleSheetsAction,
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { z } from "zod";
|
|
8
|
-
|
|
9
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
8
|
+
|
|
10
9
|
import { RestApiValidationError } from "../../errors.js";
|
|
11
10
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
11
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
12
13
|
import type {
|
|
13
14
|
KafkaClient,
|
|
14
15
|
KafkaConsumeParams,
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Supports PUT (write records) and GET (read records) operations.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
9
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
10
8
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
9
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
10
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
11
11
|
import type {
|
|
12
12
|
KinesisClient,
|
|
13
13
|
KinesisPutParams,
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Lakebase Client
|
|
2
|
+
|
|
3
|
+
Execute SQL queries and statements against Lakebase databases with full type safety and runtime validation.
|
|
4
|
+
|
|
5
|
+
## Methods
|
|
6
|
+
|
|
7
|
+
| Method | Description |
|
|
8
|
+
| ------------------------------------------- | -------------------------------------------------------------------------- |
|
|
9
|
+
| `query<T>(sql, schema, params?, metadata?)` | Execute a SELECT query and return validated, typed results |
|
|
10
|
+
| `execute(sql, params?, metadata?)` | Execute a statement (INSERT, UPDATE, DELETE) and return affected row count |
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Basic Query with Schema Validation
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { api, z, lakebase } from "@superblocksteam/sdk-api";
|
|
18
|
+
|
|
19
|
+
// Integration ID from the integrations panel
|
|
20
|
+
const LAKEBASE_DB = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
21
|
+
|
|
22
|
+
const UserSchema = z.object({
|
|
23
|
+
id: z.string(),
|
|
24
|
+
name: z.string(),
|
|
25
|
+
email: z.string(),
|
|
26
|
+
created_at: z.string(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default api({
|
|
30
|
+
name: "GetUsers",
|
|
31
|
+
integrations: {
|
|
32
|
+
db: lakebase(LAKEBASE_DB),
|
|
33
|
+
},
|
|
34
|
+
input: z.object({
|
|
35
|
+
status: z.string(),
|
|
36
|
+
}),
|
|
37
|
+
output: z.object({
|
|
38
|
+
users: z.array(UserSchema),
|
|
39
|
+
}),
|
|
40
|
+
async run(ctx, { status }) {
|
|
41
|
+
const users = await ctx.integrations.db.query(
|
|
42
|
+
"SELECT id, name, email, created_at FROM users WHERE status = $1",
|
|
43
|
+
UserSchema,
|
|
44
|
+
[status],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return { users };
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Executing INSERT, UPDATE, DELETE Statements
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { api, z, lakebase } from "@superblocksteam/sdk-api";
|
|
56
|
+
|
|
57
|
+
const LAKEBASE_DB = "a1b2c3d4-5678-90ab-cdef-111111111111";
|
|
58
|
+
|
|
59
|
+
export default api({
|
|
60
|
+
name: "ManageUsers",
|
|
61
|
+
integrations: {
|
|
62
|
+
db: lakebase(LAKEBASE_DB),
|
|
63
|
+
},
|
|
64
|
+
input: z.object({
|
|
65
|
+
name: z.string(),
|
|
66
|
+
email: z.string(),
|
|
67
|
+
}),
|
|
68
|
+
output: z.object({ success: z.boolean() }),
|
|
69
|
+
|
|
70
|
+
async run(ctx, { name, email }) {
|
|
71
|
+
// INSERT
|
|
72
|
+
await ctx.integrations.db.execute(
|
|
73
|
+
"INSERT INTO users (name, email) VALUES ($1, $2)",
|
|
74
|
+
[name, email],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// UPDATE
|
|
78
|
+
const updateResult = await ctx.integrations.db.execute(
|
|
79
|
+
"UPDATE users SET last_login = NOW() WHERE email = $1",
|
|
80
|
+
[email],
|
|
81
|
+
);
|
|
82
|
+
console.log(`Updated ${updateResult.rowCount} rows`);
|
|
83
|
+
|
|
84
|
+
// DELETE
|
|
85
|
+
const deleteResult = await ctx.integrations.db.execute(
|
|
86
|
+
"DELETE FROM sessions WHERE expires_at < NOW()",
|
|
87
|
+
);
|
|
88
|
+
console.log(`Deleted ${deleteResult.rowCount} expired sessions`);
|
|
89
|
+
|
|
90
|
+
return { success: true };
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Query with JOIN
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
const OrderSchema = z.object({
|
|
99
|
+
order_id: z.string(),
|
|
100
|
+
customer_name: z.string(),
|
|
101
|
+
total: z.string(), // NUMERIC as string
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const orders = await ctx.integrations.db.query(
|
|
105
|
+
`SELECT o.id as order_id, c.name as customer_name, o.total
|
|
106
|
+
FROM orders o
|
|
107
|
+
JOIN customers c ON o.customer_id = c.id
|
|
108
|
+
WHERE o.status = $1`,
|
|
109
|
+
OrderSchema,
|
|
110
|
+
["pending"],
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Trace Metadata
|
|
115
|
+
|
|
116
|
+
All methods accept an optional `metadata` parameter as the last argument for diagnostics labeling:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const users = await ctx.integrations.db.query(
|
|
120
|
+
"SELECT * FROM users WHERE status = $1",
|
|
121
|
+
UserSchema,
|
|
122
|
+
["active"],
|
|
123
|
+
{ label: "Fetch active users" },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
await ctx.integrations.db.execute(
|
|
127
|
+
"DELETE FROM sessions WHERE expires_at < NOW()",
|
|
128
|
+
undefined, // no params
|
|
129
|
+
{ label: "Clean expired sessions" },
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
When `includeDiagnostics` is enabled, `label` and `description` appear in the trace view. See the [root SDK README](../../../README.md#trace-metadata) for details.
|
|
134
|
+
|
|
135
|
+
## Common Pitfalls
|
|
136
|
+
|
|
137
|
+
### Uses `$1` Placeholders (PostgreSQL-Style)
|
|
138
|
+
|
|
139
|
+
Lakebase uses `$1, $2, ...` for parameter placeholders, following PostgreSQL conventions:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// WRONG - Question-mark placeholders
|
|
143
|
+
const users = await ctx.integrations.db.query(
|
|
144
|
+
"SELECT * FROM users WHERE name = ? AND status = ?",
|
|
145
|
+
UserSchema,
|
|
146
|
+
[name, status],
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// CORRECT - Use $1, $2, ... placeholders
|
|
150
|
+
const users = await ctx.integrations.db.query(
|
|
151
|
+
"SELECT * FROM users WHERE name = $1 AND status = $2",
|
|
152
|
+
UserSchema,
|
|
153
|
+
[name, status],
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Schema Parameter is Required
|
|
158
|
+
|
|
159
|
+
The `query()` method requires a Zod schema for runtime validation:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// WRONG - Missing schema parameter
|
|
163
|
+
const users = await ctx.integrations.db.query(
|
|
164
|
+
"SELECT * FROM users",
|
|
165
|
+
[
|
|
166
|
+
/* params */
|
|
167
|
+
], // This is wrong - params are 3rd argument
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// CORRECT - Schema is the second parameter
|
|
171
|
+
const users = await ctx.integrations.db.query(
|
|
172
|
+
"SELECT * FROM users WHERE id = $1",
|
|
173
|
+
UserSchema, // Schema is required
|
|
174
|
+
[userId], // Params are optional, third argument
|
|
175
|
+
);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Use Parameterized Queries to Prevent SQL Injection
|
|
179
|
+
|
|
180
|
+
Always use `$1, $2, ...` placeholders instead of string interpolation:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// WRONG - SQL injection vulnerability
|
|
184
|
+
const users = await ctx.integrations.db.query(
|
|
185
|
+
`SELECT * FROM users WHERE name = '${userName}'`, // DANGEROUS!
|
|
186
|
+
UserSchema,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// CORRECT - Use parameterized queries
|
|
190
|
+
const users = await ctx.integrations.db.query(
|
|
191
|
+
"SELECT * FROM users WHERE name = $1",
|
|
192
|
+
UserSchema,
|
|
193
|
+
[userName], // Safe - value is escaped
|
|
194
|
+
);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### NUMERIC/DECIMAL Values Returned as Strings
|
|
198
|
+
|
|
199
|
+
Large `NUMERIC` and `DECIMAL` columns are returned as strings to preserve precision:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// WRONG - May lose precision
|
|
203
|
+
const schema = z.object({ price: z.number() });
|
|
204
|
+
|
|
205
|
+
// CORRECT - Keep as string or transform
|
|
206
|
+
const schema = z.object({
|
|
207
|
+
price: z.string().transform((val) => parseFloat(val)),
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Handling NULL Values
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// WRONG - Will fail if column contains NULL
|
|
215
|
+
const schema = z.object({ bio: z.string() });
|
|
216
|
+
|
|
217
|
+
// CORRECT - Mark nullable columns
|
|
218
|
+
const schema = z.object({ bio: z.string().nullable() });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Error Handling
|
|
222
|
+
|
|
223
|
+
### QueryValidationError
|
|
224
|
+
|
|
225
|
+
Thrown when query results fail schema validation:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import { QueryValidationError } from "@superblocksteam/sdk-api";
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const users = await ctx.integrations.db.query(
|
|
232
|
+
"SELECT * FROM users",
|
|
233
|
+
UserSchema,
|
|
234
|
+
);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error instanceof QueryValidationError) {
|
|
237
|
+
console.error("Row index:", error.details.rowIndex);
|
|
238
|
+
console.error("Validation errors:", error.details.errors);
|
|
239
|
+
console.error("Actual row data:", error.details.row);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
* Supports server-side parameterized SQL queries via the `parameters` field.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as LakebasePlugin } from "@superblocksteam/types/dist/src/plugins/lakebase/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
13
|
-
import type { LakebaseClient } from "./types.js";
|
|
12
|
+
|
|
14
13
|
import { QueryValidationError } from "../../errors.js";
|
|
15
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
16
17
|
import { describeType } from "../utils.js";
|
|
18
|
+
import type { LakebaseClient } from "./types.js";
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Lakebase request type derived from proto definition.
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* runtime validation using Zod schemas.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as MariaDBPlugin } from "@superblocksteam/types/dist/src/plugins/mariadb/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
|
|
13
13
|
import { QueryValidationError } from "../../errors.js";
|
|
14
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
15
17
|
import { describeType } from "../utils.js";
|
|
16
18
|
import type { MariaDBClient } from "./types.js";
|
|
17
19
|
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Uses the native MongoDB plugin type from @superblocksteam/types.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { z } from "zod";
|
|
8
7
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
|
|
9
10
|
import type { Plugin as MongoDBPlugin } from "@superblocksteam/types/dist/src/plugins/mongodb/v1/plugin_pb";
|
|
10
|
-
|
|
11
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
11
|
+
|
|
12
12
|
import { RestApiValidationError } from "../../errors.js";
|
|
13
13
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
14
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
15
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
14
16
|
import type { MongoDBClient, MongoDBAction, MongoDBParams } from "./types.js";
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* runtime validation using Zod schemas.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as MSSQLPlugin } from "@superblocksteam/types/dist/src/plugins/mssql/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
|
|
13
13
|
import { QueryValidationError } from "../../errors.js";
|
|
14
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
15
17
|
import { describeType } from "../utils.js";
|
|
16
18
|
import type { MSSQLClient } from "./types.js";
|
|
17
19
|
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* runtime validation using Zod schemas.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as MySQLPlugin } from "@superblocksteam/types/dist/src/plugins/mysql/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
|
|
13
13
|
import { QueryValidationError } from "../../errors.js";
|
|
14
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
15
17
|
import { describeType } from "../utils.js";
|
|
16
18
|
import type { MySQLClient } from "./types.js";
|
|
17
19
|
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* runtime validation using Zod schemas.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as OracleDBPlugin } from "@superblocksteam/types/dist/src/plugins/oracledb/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
|
|
13
13
|
import { QueryValidationError } from "../../errors.js";
|
|
14
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
15
17
|
import { describeType } from "../utils.js";
|
|
16
18
|
import type { OracleDBClient } from "./types.js";
|
|
17
19
|
|
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
* for type-safe request building.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as PostgresPlugin } from "@superblocksteam/types/dist/src/plugins/postgresql/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
13
|
-
import type { PostgresClient } from "./types.js";
|
|
12
|
+
|
|
14
13
|
import { QueryValidationError } from "../../errors.js";
|
|
15
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
16
17
|
import { describeType } from "../utils.js";
|
|
18
|
+
import type { PostgresClient } from "./types.js";
|
|
17
19
|
/**
|
|
18
20
|
* PostgreSQL request type derived from proto definition.
|
|
19
21
|
* Using PartialMessage allows optional fields.
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, it, expect, vi } from "vitest";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
import type { IntegrationConfig } from "../types.js";
|
|
7
|
+
|
|
9
8
|
import type { QueryExecutor } from "../registry.js";
|
|
9
|
+
import type { IntegrationConfig } from "../types.js";
|
|
10
|
+
import { PythonClientImpl } from "./client.js";
|
|
10
11
|
|
|
11
12
|
/** Helper to compute expected base64-encoded json.loads preamble. */
|
|
12
13
|
function expectedBindingsLine(bindings: Record<string, unknown>): string {
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* Executes Python code via the orchestrator with type-safe bindings.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { z } from "zod";
|
|
8
7
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
|
|
9
10
|
import type { Plugin as PythonPlugin } from "@superblocksteam/types/dist/src/plugins/python/v1/plugin_pb";
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
import { CodeExecutionError } from "../../errors.js";
|
|
11
13
|
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
14
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
12
15
|
import type { PythonClient } from "./types.js";
|
|
13
|
-
import { CodeExecutionError } from "../../errors.js";
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Python plugin request type derived from proto definition.
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { z } from "zod";
|
|
14
|
-
|
|
15
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
14
|
+
|
|
16
15
|
import { RestApiValidationError } from "../../errors.js";
|
|
17
16
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
17
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
18
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
18
19
|
import type { RedisClient } from "./types.js";
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* runtime validation using Zod schemas.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { z } from "zod";
|
|
9
8
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
|
|
10
11
|
import type { Plugin as RedshiftPlugin } from "@superblocksteam/types/dist/src/plugins/redshift/v1/plugin_pb";
|
|
11
|
-
|
|
12
|
-
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
12
|
+
|
|
13
13
|
import { QueryValidationError } from "../../errors.js";
|
|
14
14
|
import { IntegrationError } from "../../runtime/errors.js";
|
|
15
|
+
import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
16
|
+
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
15
17
|
import { describeType } from "../utils.js";
|
|
16
18
|
import type { RedshiftClient } from "./types.js";
|
|
17
19
|
|