@squadbase/vite-server 0.0.1-build-10 → 0.0.1-build-12
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/dist/cli/index.js +230 -7
- package/dist/index.d.ts +11 -1
- package/dist/index.js +236 -25
- package/dist/main.js +235 -25
- package/dist/types/data-source.d.ts +176 -54
- package/dist/types/data-source.js +71 -0
- package/dist/vite-plugin.js +215 -4
- package/package.json +3 -2
package/dist/main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Hono as Hono5 } from "hono";
|
|
3
|
+
import { contextStorage } from "hono/context-storage";
|
|
3
4
|
import { cors } from "hono/cors";
|
|
4
5
|
import path4 from "path";
|
|
5
6
|
|
|
@@ -68,6 +69,152 @@ function createBigQueryClient(entry, connectionId) {
|
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// src/connection.ts
|
|
73
|
+
import { getContext } from "hono/context-storage";
|
|
74
|
+
import { getCookie } from "hono/cookie";
|
|
75
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
76
|
+
var PREVIEW_SESSION_COOKIE_NAME = "squadbase-preview-session";
|
|
77
|
+
var APP_BASE_DOMAIN = "squadbase.app";
|
|
78
|
+
var PREVIEW_BASE_DOMAIN = "preview.app.squadbase.dev";
|
|
79
|
+
var SANDBOX_ID_ENV_NAME = "INTERNAL_SQUADBASE_SANDBOX_ID";
|
|
80
|
+
var MACHINE_CREDENTIAL_ENV_NAME = "INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL";
|
|
81
|
+
function resolveProxyUrl(connectionId) {
|
|
82
|
+
const connectionPath = `/_sqcore/connections/${connectionId}/request`;
|
|
83
|
+
const sandboxId = process.env[SANDBOX_ID_ENV_NAME];
|
|
84
|
+
if (sandboxId) {
|
|
85
|
+
const baseDomain2 = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? PREVIEW_BASE_DOMAIN;
|
|
86
|
+
return `https://${sandboxId}.${baseDomain2}${connectionPath}`;
|
|
87
|
+
}
|
|
88
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
89
|
+
if (!projectId) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"Project ID is required. Please set SQUADBASE_PROJECT_ID environment variable."
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? APP_BASE_DOMAIN;
|
|
95
|
+
return `https://${projectId}.${baseDomain}${connectionPath}`;
|
|
96
|
+
}
|
|
97
|
+
function resolveAuthHeaders() {
|
|
98
|
+
const machineCredential = process.env[MACHINE_CREDENTIAL_ENV_NAME];
|
|
99
|
+
if (machineCredential) {
|
|
100
|
+
return { Authorization: `Bearer ${machineCredential}` };
|
|
101
|
+
}
|
|
102
|
+
const c = getContext();
|
|
103
|
+
const cookies = getCookie(c);
|
|
104
|
+
const previewSession = cookies[PREVIEW_SESSION_COOKIE_NAME];
|
|
105
|
+
if (previewSession) {
|
|
106
|
+
return {
|
|
107
|
+
Cookie: `${PREVIEW_SESSION_COOKIE_NAME}=${previewSession}`
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const appSession = cookies[APP_SESSION_COOKIE_NAME];
|
|
111
|
+
if (appSession) {
|
|
112
|
+
return { Authorization: `Bearer ${appSession}` };
|
|
113
|
+
}
|
|
114
|
+
throw new Error(
|
|
115
|
+
"No authentication method available for connection proxy. Expected one of: INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL env var, preview session cookie, or app session cookie."
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
function connection(connectionId) {
|
|
119
|
+
return {
|
|
120
|
+
async fetch(url, options) {
|
|
121
|
+
const proxyUrl = resolveProxyUrl(connectionId);
|
|
122
|
+
const authHeaders = resolveAuthHeaders();
|
|
123
|
+
return await fetch(proxyUrl, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: {
|
|
126
|
+
"Content-Type": "application/json",
|
|
127
|
+
...authHeaders
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify({
|
|
130
|
+
url,
|
|
131
|
+
method: options?.method,
|
|
132
|
+
headers: options?.headers,
|
|
133
|
+
body: options?.body,
|
|
134
|
+
timeoutMs: options?.timeoutMs
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/connector-client/bigquery-oauth.ts
|
|
142
|
+
var MAX_RESULTS = 1e4;
|
|
143
|
+
var POLL_INTERVAL_MS = 1e3;
|
|
144
|
+
var POLL_TIMEOUT_MS = 12e4;
|
|
145
|
+
function flattenRows(fields, rows) {
|
|
146
|
+
return rows.map((row) => {
|
|
147
|
+
const obj = {};
|
|
148
|
+
for (let i = 0; i < fields.length; i++) {
|
|
149
|
+
obj[fields[i].name] = row.f[i].v;
|
|
150
|
+
}
|
|
151
|
+
return obj;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function createBigQueryOAuthClient(entry, connectionId) {
|
|
155
|
+
const projectId = resolveEnvVar(entry, "project-id", connectionId);
|
|
156
|
+
const baseUrl = `https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}`;
|
|
157
|
+
return {
|
|
158
|
+
async query(sql) {
|
|
159
|
+
const conn = connection(connectionId);
|
|
160
|
+
const res = await conn.fetch(`${baseUrl}/queries`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
body: {
|
|
163
|
+
query: sql,
|
|
164
|
+
useLegacySql: false,
|
|
165
|
+
maxResults: MAX_RESULTS
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
if (!res.ok) {
|
|
169
|
+
const text = await res.text().catch(() => res.statusText);
|
|
170
|
+
throw new Error(`BigQuery query failed: HTTP ${res.status} ${text}`);
|
|
171
|
+
}
|
|
172
|
+
let data = await res.json();
|
|
173
|
+
if (data.errors?.length) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`BigQuery query error: ${data.errors.map((e) => e.message).join("; ")}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (!data.jobComplete) {
|
|
179
|
+
const jobId = data.jobReference.jobId;
|
|
180
|
+
const location = data.jobReference.location;
|
|
181
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
182
|
+
while (!data.jobComplete) {
|
|
183
|
+
if (Date.now() > deadline) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`BigQuery query timed out after ${POLL_TIMEOUT_MS / 1e3}s (jobId: ${jobId})`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
189
|
+
const params = new URLSearchParams({
|
|
190
|
+
maxResults: String(MAX_RESULTS)
|
|
191
|
+
});
|
|
192
|
+
if (location) params.set("location", location);
|
|
193
|
+
const pollRes = await conn.fetch(
|
|
194
|
+
`${baseUrl}/queries/${jobId}?${params}`,
|
|
195
|
+
{ method: "GET" }
|
|
196
|
+
);
|
|
197
|
+
if (!pollRes.ok) {
|
|
198
|
+
const text = await pollRes.text().catch(() => pollRes.statusText);
|
|
199
|
+
throw new Error(
|
|
200
|
+
`BigQuery poll failed: HTTP ${pollRes.status} ${text}`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
data = await pollRes.json();
|
|
204
|
+
if (data.errors?.length) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`BigQuery query error: ${data.errors.map((e) => e.message).join("; ")}`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const fields = data.schema?.fields ?? [];
|
|
212
|
+
const rawRows = data.rows ?? [];
|
|
213
|
+
return { rows: flattenRows(fields, rawRows) };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
71
218
|
// src/connector-client/snowflake.ts
|
|
72
219
|
function createSnowflakeClient(entry, connectionId) {
|
|
73
220
|
const accountIdentifier = resolveEnvVar(entry, "account", connectionId);
|
|
@@ -80,7 +227,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
80
227
|
async query(sql) {
|
|
81
228
|
const snowflake = (await import("snowflake-sdk")).default;
|
|
82
229
|
snowflake.configure({ logLevel: "ERROR" });
|
|
83
|
-
const
|
|
230
|
+
const connection2 = snowflake.createConnection({
|
|
84
231
|
account: accountIdentifier,
|
|
85
232
|
username: user,
|
|
86
233
|
role,
|
|
@@ -89,13 +236,13 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
89
236
|
privateKey
|
|
90
237
|
});
|
|
91
238
|
await new Promise((resolve, reject) => {
|
|
92
|
-
|
|
239
|
+
connection2.connect((err) => {
|
|
93
240
|
if (err) reject(new Error(`Snowflake connect failed: ${err.message}`));
|
|
94
241
|
else resolve();
|
|
95
242
|
});
|
|
96
243
|
});
|
|
97
244
|
const rows = await new Promise((resolve, reject) => {
|
|
98
|
-
|
|
245
|
+
connection2.execute({
|
|
99
246
|
sqlText: sql,
|
|
100
247
|
complete: (err, _stmt, rows2) => {
|
|
101
248
|
if (err) reject(new Error(`Snowflake query failed: ${err.message}`));
|
|
@@ -103,7 +250,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
103
250
|
}
|
|
104
251
|
});
|
|
105
252
|
});
|
|
106
|
-
|
|
253
|
+
connection2.destroy((err) => {
|
|
107
254
|
if (err) console.warn(`[connector-client] Snowflake destroy error: ${err.message}`);
|
|
108
255
|
});
|
|
109
256
|
return { rows };
|
|
@@ -309,6 +456,9 @@ function createConnectorRegistry() {
|
|
|
309
456
|
return { client: createSnowflakeClient(entry, connectionId), connectorSlug };
|
|
310
457
|
}
|
|
311
458
|
if (connectorSlug === "bigquery") {
|
|
459
|
+
if (entry.connector.authType === "oauth") {
|
|
460
|
+
return { client: createBigQueryOAuthClient(entry, connectionId), connectorSlug };
|
|
461
|
+
}
|
|
312
462
|
return { client: createBigQueryClient(entry, connectionId), connectorSlug };
|
|
313
463
|
}
|
|
314
464
|
if (connectorSlug === "athena") {
|
|
@@ -378,6 +528,68 @@ function createConnectorRegistry() {
|
|
|
378
528
|
// src/connector-client/index.ts
|
|
379
529
|
var { getClient, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
380
530
|
|
|
531
|
+
// src/types/data-source.ts
|
|
532
|
+
import { z } from "zod";
|
|
533
|
+
var parameterMetaSchema = z.object({
|
|
534
|
+
name: z.string(),
|
|
535
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
536
|
+
description: z.string(),
|
|
537
|
+
required: z.boolean().optional(),
|
|
538
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
539
|
+
});
|
|
540
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
541
|
+
ttl: z.number(),
|
|
542
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
543
|
+
});
|
|
544
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
545
|
+
() => z.object({
|
|
546
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
547
|
+
format: z.string().optional(),
|
|
548
|
+
description: z.string().optional(),
|
|
549
|
+
nullable: z.boolean().optional(),
|
|
550
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
551
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
552
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
553
|
+
required: z.array(z.string()).optional(),
|
|
554
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
555
|
+
minimum: z.number().optional(),
|
|
556
|
+
maximum: z.number().optional(),
|
|
557
|
+
minLength: z.number().optional(),
|
|
558
|
+
maxLength: z.number().optional(),
|
|
559
|
+
pattern: z.string().optional()
|
|
560
|
+
})
|
|
561
|
+
);
|
|
562
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
563
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
564
|
+
example: z.unknown().optional()
|
|
565
|
+
});
|
|
566
|
+
var dataSourceResponseSchema = z.object({
|
|
567
|
+
description: z.string().optional(),
|
|
568
|
+
defaultContentType: z.string().optional(),
|
|
569
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
570
|
+
});
|
|
571
|
+
var jsonBaseFields = {
|
|
572
|
+
description: z.string(),
|
|
573
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
574
|
+
response: dataSourceResponseSchema.optional(),
|
|
575
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
576
|
+
};
|
|
577
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
578
|
+
...jsonBaseFields,
|
|
579
|
+
type: z.literal("sql").optional(),
|
|
580
|
+
query: z.string(),
|
|
581
|
+
connectionId: z.string()
|
|
582
|
+
});
|
|
583
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
584
|
+
...jsonBaseFields,
|
|
585
|
+
type: z.literal("typescript"),
|
|
586
|
+
handlerPath: z.string()
|
|
587
|
+
});
|
|
588
|
+
var anyJsonDataSourceSchema = z.union([
|
|
589
|
+
jsonTypeScriptDataSourceSchema,
|
|
590
|
+
jsonSqlDataSourceSchema
|
|
591
|
+
]);
|
|
592
|
+
|
|
381
593
|
// src/registry.ts
|
|
382
594
|
var dataSources = /* @__PURE__ */ new Map();
|
|
383
595
|
var currentDirPath = "";
|
|
@@ -443,26 +655,18 @@ async function initialize() {
|
|
|
443
655
|
jsonFiles.map(async (file) => {
|
|
444
656
|
const slug = file.replace(/\.json$/, "");
|
|
445
657
|
const raw = await readFile2(`${dirPath}/${file}`, "utf-8");
|
|
446
|
-
const
|
|
447
|
-
if (!
|
|
448
|
-
console.warn(`[registry] Skipping ${file}:
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
if (!def.connectionId) {
|
|
452
|
-
console.warn(`[registry] Skipping ${file}: missing connectionId`);
|
|
658
|
+
const parsed = anyJsonDataSourceSchema.safeParse(JSON.parse(raw));
|
|
659
|
+
if (!parsed.success) {
|
|
660
|
+
console.warn(`[registry] Skipping ${file}: ${parsed.error.message}`);
|
|
453
661
|
return;
|
|
454
662
|
}
|
|
663
|
+
const def = parsed.data;
|
|
455
664
|
if (def.type === "typescript") {
|
|
456
|
-
if (!def.handlerPath) {
|
|
457
|
-
console.warn(`[registry] Skipping ${file}: missing handlerPath`);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
665
|
const absoluteHandlerPath = validateHandlerPath(dirPath, def.handlerPath);
|
|
461
666
|
const dataSourceDef = {
|
|
462
667
|
description: def.description,
|
|
463
668
|
parameters: def.parameters ?? [],
|
|
464
669
|
response: def.response,
|
|
465
|
-
connectionId: def.connectionId,
|
|
466
670
|
cacheConfig: def.cache,
|
|
467
671
|
handler: async () => {
|
|
468
672
|
throw new Error("TypeScript handler must be called via _tsHandlerPath");
|
|
@@ -474,10 +678,6 @@ async function initialize() {
|
|
|
474
678
|
console.log(`[registry] registered (typescript): ${slug}`);
|
|
475
679
|
} else {
|
|
476
680
|
const sqlDef = def;
|
|
477
|
-
if (!sqlDef.query) {
|
|
478
|
-
console.warn(`[registry] Skipping ${file}: missing query`);
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
681
|
const dataSourceDef = {
|
|
482
682
|
description: sqlDef.description,
|
|
483
683
|
parameters: sqlDef.parameters ?? [],
|
|
@@ -567,17 +767,26 @@ function getDataSource(slug) {
|
|
|
567
767
|
return dataSources.get(slug);
|
|
568
768
|
}
|
|
569
769
|
function buildMeta(slug, def) {
|
|
570
|
-
|
|
770
|
+
const base = {
|
|
571
771
|
slug,
|
|
572
772
|
description: def.description,
|
|
573
|
-
type: def._isTypescript ? "typescript" : "sql",
|
|
574
773
|
parameters: def.parameters,
|
|
575
774
|
response: def.response,
|
|
576
|
-
query: def._query,
|
|
577
|
-
connectionId: def.connectionId,
|
|
578
|
-
handlerPath: def._tsHandlerPath ? path2.relative(currentDirPath, def._tsHandlerPath) : void 0,
|
|
579
775
|
cache: def.cacheConfig
|
|
580
776
|
};
|
|
777
|
+
if (def._isTypescript) {
|
|
778
|
+
return {
|
|
779
|
+
...base,
|
|
780
|
+
type: "typescript",
|
|
781
|
+
handlerPath: path2.relative(currentDirPath, def._tsHandlerPath)
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
...base,
|
|
786
|
+
type: "sql",
|
|
787
|
+
connectionId: def.connectionId,
|
|
788
|
+
query: def._query
|
|
789
|
+
};
|
|
581
790
|
}
|
|
582
791
|
function getAllMeta() {
|
|
583
792
|
return Array.from(dataSources.entries()).map(
|
|
@@ -915,6 +1124,7 @@ var pages_default = app4;
|
|
|
915
1124
|
|
|
916
1125
|
// src/index.ts
|
|
917
1126
|
var apiApp = new Hono5();
|
|
1127
|
+
apiApp.use("/*", contextStorage());
|
|
918
1128
|
apiApp.use("/*", cors());
|
|
919
1129
|
apiApp.route("/data-source", data_source_default);
|
|
920
1130
|
apiApp.route("/data-source-meta", data_source_meta_default);
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const parameterMetaSchema: z.ZodObject<{
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
type: z.ZodEnum<{
|
|
6
|
+
string: "string";
|
|
7
|
+
number: "number";
|
|
8
|
+
boolean: "boolean";
|
|
9
|
+
}>;
|
|
10
|
+
description: z.ZodString;
|
|
11
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type ParameterMeta = z.infer<typeof parameterMetaSchema>;
|
|
15
|
+
declare const dataSourceCacheConfigSchema: z.ZodObject<{
|
|
16
|
+
ttl: z.ZodNumber;
|
|
17
|
+
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
type DataSourceCacheConfig = z.infer<typeof dataSourceCacheConfigSchema>;
|
|
20
|
+
declare const dataSourceSchemaObjectSchema: z.ZodType<DataSourceSchemaObject>;
|
|
21
21
|
interface DataSourceSchemaObject {
|
|
22
22
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
23
23
|
format?: string;
|
|
@@ -34,55 +34,177 @@ interface DataSourceSchemaObject {
|
|
|
34
34
|
maxLength?: number;
|
|
35
35
|
pattern?: string;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
schema
|
|
39
|
-
example
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
declare const dataSourceMediaTypeSchema: z.ZodObject<{
|
|
38
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
39
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
type DataSourceMediaType = z.infer<typeof dataSourceMediaTypeSchema>;
|
|
42
|
+
declare const dataSourceResponseSchema: z.ZodObject<{
|
|
43
|
+
description: z.ZodOptional<z.ZodString>;
|
|
44
|
+
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
45
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
46
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
47
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
}, z.core.$strip>>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
type DataSourceResponse = z.infer<typeof dataSourceResponseSchema>;
|
|
51
|
+
declare const jsonSqlDataSourceSchema: z.ZodObject<{
|
|
52
|
+
type: z.ZodOptional<z.ZodLiteral<"sql">>;
|
|
53
|
+
query: z.ZodString;
|
|
54
|
+
connectionId: z.ZodString;
|
|
55
|
+
description: z.ZodString;
|
|
56
|
+
parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
type: z.ZodEnum<{
|
|
59
|
+
string: "string";
|
|
60
|
+
number: "number";
|
|
61
|
+
boolean: "boolean";
|
|
62
|
+
}>;
|
|
63
|
+
description: z.ZodString;
|
|
64
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
66
|
+
}, z.core.$strip>>>;
|
|
67
|
+
response: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
description: z.ZodOptional<z.ZodString>;
|
|
69
|
+
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
70
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
71
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
72
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
73
|
+
}, z.core.$strip>>>;
|
|
74
|
+
}, z.core.$strip>>;
|
|
75
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
76
|
+
ttl: z.ZodNumber;
|
|
77
|
+
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
}, z.core.$strip>>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
type JsonSqlDataSourceDefinition = z.infer<typeof jsonSqlDataSourceSchema>;
|
|
81
|
+
declare const jsonTypeScriptDataSourceSchema: z.ZodObject<{
|
|
82
|
+
type: z.ZodLiteral<"typescript">;
|
|
83
|
+
handlerPath: z.ZodString;
|
|
84
|
+
description: z.ZodString;
|
|
85
|
+
parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
86
|
+
name: z.ZodString;
|
|
87
|
+
type: z.ZodEnum<{
|
|
88
|
+
string: "string";
|
|
89
|
+
number: "number";
|
|
90
|
+
boolean: "boolean";
|
|
91
|
+
}>;
|
|
92
|
+
description: z.ZodString;
|
|
93
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
95
|
+
}, z.core.$strip>>>;
|
|
96
|
+
response: z.ZodOptional<z.ZodObject<{
|
|
97
|
+
description: z.ZodOptional<z.ZodString>;
|
|
98
|
+
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
99
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
100
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
101
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
102
|
+
}, z.core.$strip>>>;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
105
|
+
ttl: z.ZodNumber;
|
|
106
|
+
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
type JsonTypeScriptDataSourceDefinition = z.infer<typeof jsonTypeScriptDataSourceSchema>;
|
|
110
|
+
declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
111
|
+
type: z.ZodLiteral<"typescript">;
|
|
112
|
+
handlerPath: z.ZodString;
|
|
113
|
+
description: z.ZodString;
|
|
114
|
+
parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
115
|
+
name: z.ZodString;
|
|
116
|
+
type: z.ZodEnum<{
|
|
117
|
+
string: "string";
|
|
118
|
+
number: "number";
|
|
119
|
+
boolean: "boolean";
|
|
120
|
+
}>;
|
|
121
|
+
description: z.ZodString;
|
|
122
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
124
|
+
}, z.core.$strip>>>;
|
|
125
|
+
response: z.ZodOptional<z.ZodObject<{
|
|
126
|
+
description: z.ZodOptional<z.ZodString>;
|
|
127
|
+
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
128
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
129
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
130
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
131
|
+
}, z.core.$strip>>>;
|
|
132
|
+
}, z.core.$strip>>;
|
|
133
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
134
|
+
ttl: z.ZodNumber;
|
|
135
|
+
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
type: z.ZodOptional<z.ZodLiteral<"sql">>;
|
|
139
|
+
query: z.ZodString;
|
|
140
|
+
connectionId: z.ZodString;
|
|
141
|
+
description: z.ZodString;
|
|
142
|
+
parameters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
143
|
+
name: z.ZodString;
|
|
144
|
+
type: z.ZodEnum<{
|
|
145
|
+
string: "string";
|
|
146
|
+
number: "number";
|
|
147
|
+
boolean: "boolean";
|
|
148
|
+
}>;
|
|
149
|
+
description: z.ZodString;
|
|
150
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
151
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
152
|
+
}, z.core.$strip>>>;
|
|
153
|
+
response: z.ZodOptional<z.ZodObject<{
|
|
154
|
+
description: z.ZodOptional<z.ZodString>;
|
|
155
|
+
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
156
|
+
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
157
|
+
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
158
|
+
example: z.ZodOptional<z.ZodUnknown>;
|
|
159
|
+
}, z.core.$strip>>>;
|
|
160
|
+
}, z.core.$strip>>;
|
|
161
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
162
|
+
ttl: z.ZodNumber;
|
|
163
|
+
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
}, z.core.$strip>>;
|
|
165
|
+
}, z.core.$strip>]>;
|
|
166
|
+
type AnyJsonDataSourceDefinition = z.infer<typeof anyJsonDataSourceSchema>;
|
|
167
|
+
interface BaseDataSourceDefinition {
|
|
47
168
|
description: string;
|
|
48
169
|
parameters: ParameterMeta[];
|
|
49
170
|
response?: DataSourceResponse;
|
|
50
|
-
connectionId: string;
|
|
51
171
|
cacheConfig?: DataSourceCacheConfig;
|
|
52
172
|
handler: (params: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
53
|
-
_isTypescript?: boolean;
|
|
54
|
-
_tsHandlerPath?: string;
|
|
55
|
-
_query?: string;
|
|
56
173
|
}
|
|
57
|
-
interface
|
|
174
|
+
interface SqlDataSourceDefinition extends BaseDataSourceDefinition {
|
|
175
|
+
connectionId: string;
|
|
176
|
+
_query: string;
|
|
177
|
+
_isTypescript?: false;
|
|
178
|
+
_tsHandlerPath?: undefined;
|
|
179
|
+
}
|
|
180
|
+
interface TypeScriptDataSourceDefinition extends BaseDataSourceDefinition {
|
|
181
|
+
_isTypescript: true;
|
|
182
|
+
_tsHandlerPath: string;
|
|
183
|
+
connectionId?: undefined;
|
|
184
|
+
_query?: undefined;
|
|
185
|
+
}
|
|
186
|
+
type DataSourceDefinition = SqlDataSourceDefinition | TypeScriptDataSourceDefinition;
|
|
187
|
+
interface BaseDataSourceMeta {
|
|
58
188
|
slug: string;
|
|
59
189
|
description: string;
|
|
60
|
-
type: "sql" | "typescript";
|
|
61
190
|
parameters: ParameterMeta[];
|
|
62
191
|
response?: DataSourceResponse;
|
|
63
|
-
query?: string;
|
|
64
|
-
connectionId: string;
|
|
65
|
-
handlerPath?: string;
|
|
66
192
|
cache?: DataSourceCacheConfig;
|
|
67
193
|
}
|
|
68
|
-
interface
|
|
69
|
-
|
|
70
|
-
type?: "sql";
|
|
71
|
-
parameters?: ParameterMeta[];
|
|
72
|
-
response?: DataSourceResponse;
|
|
73
|
-
query: string;
|
|
194
|
+
interface SqlDataSourceMeta extends BaseDataSourceMeta {
|
|
195
|
+
type: "sql";
|
|
74
196
|
connectionId: string;
|
|
75
|
-
|
|
197
|
+
query: string;
|
|
198
|
+
handlerPath?: undefined;
|
|
76
199
|
}
|
|
77
|
-
interface
|
|
78
|
-
description: string;
|
|
200
|
+
interface TypeScriptDataSourceMeta extends BaseDataSourceMeta {
|
|
79
201
|
type: "typescript";
|
|
80
202
|
handlerPath: string;
|
|
81
|
-
connectionId
|
|
82
|
-
|
|
83
|
-
response?: DataSourceResponse;
|
|
84
|
-
cache?: DataSourceCacheConfig;
|
|
203
|
+
connectionId?: undefined;
|
|
204
|
+
query?: undefined;
|
|
85
205
|
}
|
|
86
|
-
type
|
|
206
|
+
type DataSourceMeta = SqlDataSourceMeta | TypeScriptDataSourceMeta;
|
|
207
|
+
/** @deprecated Use JsonSqlDataSourceDefinition */
|
|
208
|
+
type JsonDataSourceDefinition = JsonSqlDataSourceDefinition;
|
|
87
209
|
|
|
88
|
-
export type
|
|
210
|
+
export { type AnyJsonDataSourceDefinition, type DataSourceCacheConfig, type DataSourceDefinition, type DataSourceMediaType, type DataSourceMeta, type DataSourceResponse, type DataSourceSchemaObject, type JsonDataSourceDefinition, type JsonSqlDataSourceDefinition, type JsonTypeScriptDataSourceDefinition, type ParameterMeta, type SqlDataSourceDefinition, type SqlDataSourceMeta, type TypeScriptDataSourceDefinition, type TypeScriptDataSourceMeta, anyJsonDataSourceSchema, dataSourceCacheConfigSchema, dataSourceMediaTypeSchema, dataSourceResponseSchema, dataSourceSchemaObjectSchema, jsonSqlDataSourceSchema, jsonTypeScriptDataSourceSchema, parameterMetaSchema };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/types/data-source.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var parameterMetaSchema = z.object({
|
|
4
|
+
name: z.string(),
|
|
5
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
6
|
+
description: z.string(),
|
|
7
|
+
required: z.boolean().optional(),
|
|
8
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
9
|
+
});
|
|
10
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
11
|
+
ttl: z.number(),
|
|
12
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
13
|
+
});
|
|
14
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
15
|
+
() => z.object({
|
|
16
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
17
|
+
format: z.string().optional(),
|
|
18
|
+
description: z.string().optional(),
|
|
19
|
+
nullable: z.boolean().optional(),
|
|
20
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
21
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
22
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
23
|
+
required: z.array(z.string()).optional(),
|
|
24
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
25
|
+
minimum: z.number().optional(),
|
|
26
|
+
maximum: z.number().optional(),
|
|
27
|
+
minLength: z.number().optional(),
|
|
28
|
+
maxLength: z.number().optional(),
|
|
29
|
+
pattern: z.string().optional()
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
33
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
34
|
+
example: z.unknown().optional()
|
|
35
|
+
});
|
|
36
|
+
var dataSourceResponseSchema = z.object({
|
|
37
|
+
description: z.string().optional(),
|
|
38
|
+
defaultContentType: z.string().optional(),
|
|
39
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
40
|
+
});
|
|
41
|
+
var jsonBaseFields = {
|
|
42
|
+
description: z.string(),
|
|
43
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
44
|
+
response: dataSourceResponseSchema.optional(),
|
|
45
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
46
|
+
};
|
|
47
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
48
|
+
...jsonBaseFields,
|
|
49
|
+
type: z.literal("sql").optional(),
|
|
50
|
+
query: z.string(),
|
|
51
|
+
connectionId: z.string()
|
|
52
|
+
});
|
|
53
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
54
|
+
...jsonBaseFields,
|
|
55
|
+
type: z.literal("typescript"),
|
|
56
|
+
handlerPath: z.string()
|
|
57
|
+
});
|
|
58
|
+
var anyJsonDataSourceSchema = z.union([
|
|
59
|
+
jsonTypeScriptDataSourceSchema,
|
|
60
|
+
jsonSqlDataSourceSchema
|
|
61
|
+
]);
|
|
62
|
+
export {
|
|
63
|
+
anyJsonDataSourceSchema,
|
|
64
|
+
dataSourceCacheConfigSchema,
|
|
65
|
+
dataSourceMediaTypeSchema,
|
|
66
|
+
dataSourceResponseSchema,
|
|
67
|
+
dataSourceSchemaObjectSchema,
|
|
68
|
+
jsonSqlDataSourceSchema,
|
|
69
|
+
jsonTypeScriptDataSourceSchema,
|
|
70
|
+
parameterMetaSchema
|
|
71
|
+
};
|