@squadbase/vite-server 0.0.1-build-9 → 0.0.1-build-11
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 +77 -3
- package/dist/index.d.ts +11 -1
- package/dist/index.js +156 -25
- package/dist/main.js +90 -25
- package/dist/types/data-source.d.ts +176 -54
- package/dist/types/data-source.js +71 -0
- package/dist/vite-plugin.d.ts +0 -1
- package/dist/vite-plugin.js +73 -3
- package/package.json +5 -4
package/dist/cli/index.js
CHANGED
|
@@ -469,6 +469,70 @@ import path3 from "path";
|
|
|
469
469
|
import { readdir, readFile as readFile2, mkdir } from "fs/promises";
|
|
470
470
|
import { watch as fsWatch2 } from "fs";
|
|
471
471
|
import path2 from "path";
|
|
472
|
+
|
|
473
|
+
// src/types/data-source.ts
|
|
474
|
+
import { z } from "zod";
|
|
475
|
+
var parameterMetaSchema = z.object({
|
|
476
|
+
name: z.string(),
|
|
477
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
478
|
+
description: z.string(),
|
|
479
|
+
required: z.boolean().optional(),
|
|
480
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
481
|
+
});
|
|
482
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
483
|
+
ttl: z.number(),
|
|
484
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
485
|
+
});
|
|
486
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
487
|
+
() => z.object({
|
|
488
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
489
|
+
format: z.string().optional(),
|
|
490
|
+
description: z.string().optional(),
|
|
491
|
+
nullable: z.boolean().optional(),
|
|
492
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
493
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
494
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
495
|
+
required: z.array(z.string()).optional(),
|
|
496
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
497
|
+
minimum: z.number().optional(),
|
|
498
|
+
maximum: z.number().optional(),
|
|
499
|
+
minLength: z.number().optional(),
|
|
500
|
+
maxLength: z.number().optional(),
|
|
501
|
+
pattern: z.string().optional()
|
|
502
|
+
})
|
|
503
|
+
);
|
|
504
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
505
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
506
|
+
example: z.unknown().optional()
|
|
507
|
+
});
|
|
508
|
+
var dataSourceResponseSchema = z.object({
|
|
509
|
+
description: z.string().optional(),
|
|
510
|
+
defaultContentType: z.string().optional(),
|
|
511
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
512
|
+
});
|
|
513
|
+
var jsonBaseFields = {
|
|
514
|
+
description: z.string(),
|
|
515
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
516
|
+
response: dataSourceResponseSchema.optional(),
|
|
517
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
518
|
+
};
|
|
519
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
520
|
+
...jsonBaseFields,
|
|
521
|
+
type: z.literal("sql").optional(),
|
|
522
|
+
query: z.string(),
|
|
523
|
+
connectionId: z.string()
|
|
524
|
+
});
|
|
525
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
526
|
+
...jsonBaseFields,
|
|
527
|
+
type: z.literal("typescript"),
|
|
528
|
+
handlerPath: z.string()
|
|
529
|
+
});
|
|
530
|
+
var anyJsonDataSourceSchema = z.union([
|
|
531
|
+
jsonTypeScriptDataSourceSchema,
|
|
532
|
+
jsonSqlDataSourceSchema
|
|
533
|
+
]);
|
|
534
|
+
|
|
535
|
+
// src/registry.ts
|
|
472
536
|
function buildQuery(queryTemplate, parameterMeta, runtimeParams) {
|
|
473
537
|
const defaults = new Map(
|
|
474
538
|
parameterMeta.map((p) => [p.name, p.default ?? null])
|
|
@@ -605,7 +669,17 @@ async function runDataSource(slug, dirPath, params, limit) {
|
|
|
605
669
|
let def;
|
|
606
670
|
try {
|
|
607
671
|
const raw = await readFile3(jsonPath, "utf-8");
|
|
608
|
-
|
|
672
|
+
const parsed = anyJsonDataSourceSchema.safeParse(JSON.parse(raw));
|
|
673
|
+
if (!parsed.success) {
|
|
674
|
+
return {
|
|
675
|
+
slug,
|
|
676
|
+
rows: [],
|
|
677
|
+
rowCount: 0,
|
|
678
|
+
durationMs: 0,
|
|
679
|
+
error: new Error(`Invalid data source definition: ${parsed.error.message}`)
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
def = parsed.data;
|
|
609
683
|
} catch {
|
|
610
684
|
return {
|
|
611
685
|
slug,
|
|
@@ -811,8 +885,8 @@ Total: ${results.length}, Failed: ${failed}`);
|
|
|
811
885
|
let paramMeta = [];
|
|
812
886
|
try {
|
|
813
887
|
const raw = await readFile4(jsonPath, "utf-8");
|
|
814
|
-
const
|
|
815
|
-
paramMeta =
|
|
888
|
+
const parsed = anyJsonDataSourceSchema.safeParse(JSON.parse(raw));
|
|
889
|
+
if (parsed.success) paramMeta = parsed.data.parameters ?? [];
|
|
816
890
|
} catch {
|
|
817
891
|
}
|
|
818
892
|
const interactiveParams = await inputParameters2(paramMeta);
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,16 @@ declare const getClient: (connectionId: string) => Promise<{
|
|
|
126
126
|
}>;
|
|
127
127
|
declare const loadConnections: () => Promise<ConnectionsMap>;
|
|
128
128
|
|
|
129
|
+
type ConnectionFetchOptions = {
|
|
130
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
131
|
+
headers?: Record<string, string>;
|
|
132
|
+
body?: unknown;
|
|
133
|
+
timeoutMs?: number;
|
|
134
|
+
};
|
|
135
|
+
declare function connection(connectionId: string): {
|
|
136
|
+
fetch(url: string, options?: ConnectionFetchOptions): Promise<Response>;
|
|
137
|
+
};
|
|
138
|
+
|
|
129
139
|
declare const app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
130
140
|
|
|
131
|
-
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionsMap, type DatabaseClient, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type WixStoreClient, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getClient, loadConnections };
|
|
141
|
+
export { type AirtableClient, type AirtableRecord, type ConnectionEntry, type ConnectionFetchOptions, type ConnectionsMap, type DatabaseClient, type DbtClient, type GoogleAnalyticsClient, type KintoneClient, type WixStoreClient, connection, createAirtableClient, createDbtClient, createGoogleAnalyticsClient, createKintoneClient, createWixStoreClient, app as default, getClient, loadConnections };
|
package/dist/index.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
|
|
|
@@ -80,7 +81,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
80
81
|
async query(sql) {
|
|
81
82
|
const snowflake = (await import("snowflake-sdk")).default;
|
|
82
83
|
snowflake.configure({ logLevel: "ERROR" });
|
|
83
|
-
const
|
|
84
|
+
const connection2 = snowflake.createConnection({
|
|
84
85
|
account: accountIdentifier,
|
|
85
86
|
username: user,
|
|
86
87
|
role,
|
|
@@ -89,13 +90,13 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
89
90
|
privateKey
|
|
90
91
|
});
|
|
91
92
|
await new Promise((resolve, reject) => {
|
|
92
|
-
|
|
93
|
+
connection2.connect((err) => {
|
|
93
94
|
if (err) reject(new Error(`Snowflake connect failed: ${err.message}`));
|
|
94
95
|
else resolve();
|
|
95
96
|
});
|
|
96
97
|
});
|
|
97
98
|
const rows = await new Promise((resolve, reject) => {
|
|
98
|
-
|
|
99
|
+
connection2.execute({
|
|
99
100
|
sqlText: sql,
|
|
100
101
|
complete: (err, _stmt, rows2) => {
|
|
101
102
|
if (err) reject(new Error(`Snowflake query failed: ${err.message}`));
|
|
@@ -103,7 +104,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
103
104
|
}
|
|
104
105
|
});
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
+
connection2.destroy((err) => {
|
|
107
108
|
if (err) console.warn(`[connector-client] Snowflake destroy error: ${err.message}`);
|
|
108
109
|
});
|
|
109
110
|
return { rows };
|
|
@@ -640,6 +641,68 @@ function createDbtClient(entry, slug) {
|
|
|
640
641
|
// src/connector-client/index.ts
|
|
641
642
|
var { getClient, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
642
643
|
|
|
644
|
+
// src/types/data-source.ts
|
|
645
|
+
import { z } from "zod";
|
|
646
|
+
var parameterMetaSchema = z.object({
|
|
647
|
+
name: z.string(),
|
|
648
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
649
|
+
description: z.string(),
|
|
650
|
+
required: z.boolean().optional(),
|
|
651
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
652
|
+
});
|
|
653
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
654
|
+
ttl: z.number(),
|
|
655
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
656
|
+
});
|
|
657
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
658
|
+
() => z.object({
|
|
659
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
660
|
+
format: z.string().optional(),
|
|
661
|
+
description: z.string().optional(),
|
|
662
|
+
nullable: z.boolean().optional(),
|
|
663
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
664
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
665
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
666
|
+
required: z.array(z.string()).optional(),
|
|
667
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
668
|
+
minimum: z.number().optional(),
|
|
669
|
+
maximum: z.number().optional(),
|
|
670
|
+
minLength: z.number().optional(),
|
|
671
|
+
maxLength: z.number().optional(),
|
|
672
|
+
pattern: z.string().optional()
|
|
673
|
+
})
|
|
674
|
+
);
|
|
675
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
676
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
677
|
+
example: z.unknown().optional()
|
|
678
|
+
});
|
|
679
|
+
var dataSourceResponseSchema = z.object({
|
|
680
|
+
description: z.string().optional(),
|
|
681
|
+
defaultContentType: z.string().optional(),
|
|
682
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
683
|
+
});
|
|
684
|
+
var jsonBaseFields = {
|
|
685
|
+
description: z.string(),
|
|
686
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
687
|
+
response: dataSourceResponseSchema.optional(),
|
|
688
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
689
|
+
};
|
|
690
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
691
|
+
...jsonBaseFields,
|
|
692
|
+
type: z.literal("sql").optional(),
|
|
693
|
+
query: z.string(),
|
|
694
|
+
connectionId: z.string()
|
|
695
|
+
});
|
|
696
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
697
|
+
...jsonBaseFields,
|
|
698
|
+
type: z.literal("typescript"),
|
|
699
|
+
handlerPath: z.string()
|
|
700
|
+
});
|
|
701
|
+
var anyJsonDataSourceSchema = z.union([
|
|
702
|
+
jsonTypeScriptDataSourceSchema,
|
|
703
|
+
jsonSqlDataSourceSchema
|
|
704
|
+
]);
|
|
705
|
+
|
|
643
706
|
// src/registry.ts
|
|
644
707
|
var dataSources = /* @__PURE__ */ new Map();
|
|
645
708
|
var currentDirPath = "";
|
|
@@ -705,26 +768,18 @@ async function initialize() {
|
|
|
705
768
|
jsonFiles.map(async (file) => {
|
|
706
769
|
const slug = file.replace(/\.json$/, "");
|
|
707
770
|
const raw = await readFile2(`${dirPath}/${file}`, "utf-8");
|
|
708
|
-
const
|
|
709
|
-
if (!
|
|
710
|
-
console.warn(`[registry] Skipping ${file}:
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (!def.connectionId) {
|
|
714
|
-
console.warn(`[registry] Skipping ${file}: missing connectionId`);
|
|
771
|
+
const parsed = anyJsonDataSourceSchema.safeParse(JSON.parse(raw));
|
|
772
|
+
if (!parsed.success) {
|
|
773
|
+
console.warn(`[registry] Skipping ${file}: ${parsed.error.message}`);
|
|
715
774
|
return;
|
|
716
775
|
}
|
|
776
|
+
const def = parsed.data;
|
|
717
777
|
if (def.type === "typescript") {
|
|
718
|
-
if (!def.handlerPath) {
|
|
719
|
-
console.warn(`[registry] Skipping ${file}: missing handlerPath`);
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
778
|
const absoluteHandlerPath = validateHandlerPath(dirPath, def.handlerPath);
|
|
723
779
|
const dataSourceDef = {
|
|
724
780
|
description: def.description,
|
|
725
781
|
parameters: def.parameters ?? [],
|
|
726
782
|
response: def.response,
|
|
727
|
-
connectionId: def.connectionId,
|
|
728
783
|
cacheConfig: def.cache,
|
|
729
784
|
handler: async () => {
|
|
730
785
|
throw new Error("TypeScript handler must be called via _tsHandlerPath");
|
|
@@ -736,10 +791,6 @@ async function initialize() {
|
|
|
736
791
|
console.log(`[registry] registered (typescript): ${slug}`);
|
|
737
792
|
} else {
|
|
738
793
|
const sqlDef = def;
|
|
739
|
-
if (!sqlDef.query) {
|
|
740
|
-
console.warn(`[registry] Skipping ${file}: missing query`);
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
794
|
const dataSourceDef = {
|
|
744
795
|
description: sqlDef.description,
|
|
745
796
|
parameters: sqlDef.parameters ?? [],
|
|
@@ -829,17 +880,26 @@ function getDataSource(slug) {
|
|
|
829
880
|
return dataSources.get(slug);
|
|
830
881
|
}
|
|
831
882
|
function buildMeta(slug, def) {
|
|
832
|
-
|
|
883
|
+
const base = {
|
|
833
884
|
slug,
|
|
834
885
|
description: def.description,
|
|
835
|
-
type: def._isTypescript ? "typescript" : "sql",
|
|
836
886
|
parameters: def.parameters,
|
|
837
887
|
response: def.response,
|
|
838
|
-
query: def._query,
|
|
839
|
-
connectionId: def.connectionId,
|
|
840
|
-
handlerPath: def._tsHandlerPath ? path2.relative(currentDirPath, def._tsHandlerPath) : void 0,
|
|
841
888
|
cache: def.cacheConfig
|
|
842
889
|
};
|
|
890
|
+
if (def._isTypescript) {
|
|
891
|
+
return {
|
|
892
|
+
...base,
|
|
893
|
+
type: "typescript",
|
|
894
|
+
handlerPath: path2.relative(currentDirPath, def._tsHandlerPath)
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return {
|
|
898
|
+
...base,
|
|
899
|
+
type: "sql",
|
|
900
|
+
connectionId: def.connectionId,
|
|
901
|
+
query: def._query
|
|
902
|
+
};
|
|
843
903
|
}
|
|
844
904
|
function getAllMeta() {
|
|
845
905
|
return Array.from(dataSources.entries()).map(
|
|
@@ -1175,8 +1235,78 @@ app4.get("/runtime-data", (c) => {
|
|
|
1175
1235
|
});
|
|
1176
1236
|
var pages_default = app4;
|
|
1177
1237
|
|
|
1238
|
+
// src/connection.ts
|
|
1239
|
+
import { getContext } from "hono/context-storage";
|
|
1240
|
+
import { getCookie } from "hono/cookie";
|
|
1241
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
1242
|
+
var PREVIEW_SESSION_COOKIE_NAME = "squadbase-preview-session";
|
|
1243
|
+
var APP_BASE_DOMAIN = "squadbase.app";
|
|
1244
|
+
var PREVIEW_BASE_DOMAIN = "preview.app.squadbase.dev";
|
|
1245
|
+
var SANDBOX_ID_ENV_NAME = "INTERNAL_SQUADBASE_SANDBOX_ID";
|
|
1246
|
+
var MACHINE_CREDENTIAL_ENV_NAME = "INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL";
|
|
1247
|
+
function resolveProxyUrl(connectionId) {
|
|
1248
|
+
const connectionPath = `/_sqcore/connections/${connectionId}/request`;
|
|
1249
|
+
const sandboxId = process.env[SANDBOX_ID_ENV_NAME];
|
|
1250
|
+
if (sandboxId) {
|
|
1251
|
+
const baseDomain2 = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? PREVIEW_BASE_DOMAIN;
|
|
1252
|
+
return `https://${sandboxId}.${baseDomain2}${connectionPath}`;
|
|
1253
|
+
}
|
|
1254
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
1255
|
+
if (!projectId) {
|
|
1256
|
+
throw new Error(
|
|
1257
|
+
"Project ID is required. Please set SQUADBASE_PROJECT_ID environment variable."
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? APP_BASE_DOMAIN;
|
|
1261
|
+
return `https://${projectId}.${baseDomain}${connectionPath}`;
|
|
1262
|
+
}
|
|
1263
|
+
function resolveAuthHeaders() {
|
|
1264
|
+
const machineCredential = process.env[MACHINE_CREDENTIAL_ENV_NAME];
|
|
1265
|
+
if (machineCredential) {
|
|
1266
|
+
return { Authorization: `Bearer ${machineCredential}` };
|
|
1267
|
+
}
|
|
1268
|
+
const c = getContext();
|
|
1269
|
+
const cookies = getCookie(c);
|
|
1270
|
+
const previewSession = cookies[PREVIEW_SESSION_COOKIE_NAME];
|
|
1271
|
+
if (previewSession) {
|
|
1272
|
+
return {
|
|
1273
|
+
Cookie: `${PREVIEW_SESSION_COOKIE_NAME}=${previewSession}`
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
const appSession = cookies[APP_SESSION_COOKIE_NAME];
|
|
1277
|
+
if (appSession) {
|
|
1278
|
+
return { Authorization: `Bearer ${appSession}` };
|
|
1279
|
+
}
|
|
1280
|
+
throw new Error(
|
|
1281
|
+
"No authentication method available for connection proxy. Expected one of: INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL env var, preview session cookie, or app session cookie."
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
function connection(connectionId) {
|
|
1285
|
+
return {
|
|
1286
|
+
async fetch(url, options) {
|
|
1287
|
+
const proxyUrl = resolveProxyUrl(connectionId);
|
|
1288
|
+
const authHeaders = resolveAuthHeaders();
|
|
1289
|
+
return await fetch(proxyUrl, {
|
|
1290
|
+
method: "POST",
|
|
1291
|
+
headers: {
|
|
1292
|
+
"Content-Type": "application/json",
|
|
1293
|
+
...authHeaders
|
|
1294
|
+
},
|
|
1295
|
+
body: JSON.stringify({
|
|
1296
|
+
url,
|
|
1297
|
+
method: options?.method,
|
|
1298
|
+
headers: options?.headers,
|
|
1299
|
+
body: options?.body,
|
|
1300
|
+
timeoutMs: options?.timeoutMs
|
|
1301
|
+
})
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1178
1307
|
// src/index.ts
|
|
1179
1308
|
var apiApp = new Hono5();
|
|
1309
|
+
apiApp.use("/*", contextStorage());
|
|
1180
1310
|
apiApp.use("/*", cors());
|
|
1181
1311
|
apiApp.route("/data-source", data_source_default);
|
|
1182
1312
|
apiApp.route("/data-source-meta", data_source_meta_default);
|
|
@@ -1191,6 +1321,7 @@ app5.get("/healthz", (c) => c.json({ status: "ok" }));
|
|
|
1191
1321
|
app5.route("/api", apiApp);
|
|
1192
1322
|
var src_default = app5;
|
|
1193
1323
|
export {
|
|
1324
|
+
connection,
|
|
1194
1325
|
createAirtableClient,
|
|
1195
1326
|
createDbtClient,
|
|
1196
1327
|
createGoogleAnalyticsClient,
|
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
|
|
|
@@ -80,7 +81,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
80
81
|
async query(sql) {
|
|
81
82
|
const snowflake = (await import("snowflake-sdk")).default;
|
|
82
83
|
snowflake.configure({ logLevel: "ERROR" });
|
|
83
|
-
const
|
|
84
|
+
const connection2 = snowflake.createConnection({
|
|
84
85
|
account: accountIdentifier,
|
|
85
86
|
username: user,
|
|
86
87
|
role,
|
|
@@ -89,13 +90,13 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
89
90
|
privateKey
|
|
90
91
|
});
|
|
91
92
|
await new Promise((resolve, reject) => {
|
|
92
|
-
|
|
93
|
+
connection2.connect((err) => {
|
|
93
94
|
if (err) reject(new Error(`Snowflake connect failed: ${err.message}`));
|
|
94
95
|
else resolve();
|
|
95
96
|
});
|
|
96
97
|
});
|
|
97
98
|
const rows = await new Promise((resolve, reject) => {
|
|
98
|
-
|
|
99
|
+
connection2.execute({
|
|
99
100
|
sqlText: sql,
|
|
100
101
|
complete: (err, _stmt, rows2) => {
|
|
101
102
|
if (err) reject(new Error(`Snowflake query failed: ${err.message}`));
|
|
@@ -103,7 +104,7 @@ function createSnowflakeClient(entry, connectionId) {
|
|
|
103
104
|
}
|
|
104
105
|
});
|
|
105
106
|
});
|
|
106
|
-
|
|
107
|
+
connection2.destroy((err) => {
|
|
107
108
|
if (err) console.warn(`[connector-client] Snowflake destroy error: ${err.message}`);
|
|
108
109
|
});
|
|
109
110
|
return { rows };
|
|
@@ -378,6 +379,68 @@ function createConnectorRegistry() {
|
|
|
378
379
|
// src/connector-client/index.ts
|
|
379
380
|
var { getClient, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
380
381
|
|
|
382
|
+
// src/types/data-source.ts
|
|
383
|
+
import { z } from "zod";
|
|
384
|
+
var parameterMetaSchema = z.object({
|
|
385
|
+
name: z.string(),
|
|
386
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
387
|
+
description: z.string(),
|
|
388
|
+
required: z.boolean().optional(),
|
|
389
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
390
|
+
});
|
|
391
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
392
|
+
ttl: z.number(),
|
|
393
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
394
|
+
});
|
|
395
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
396
|
+
() => z.object({
|
|
397
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
398
|
+
format: z.string().optional(),
|
|
399
|
+
description: z.string().optional(),
|
|
400
|
+
nullable: z.boolean().optional(),
|
|
401
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
402
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
403
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
404
|
+
required: z.array(z.string()).optional(),
|
|
405
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
406
|
+
minimum: z.number().optional(),
|
|
407
|
+
maximum: z.number().optional(),
|
|
408
|
+
minLength: z.number().optional(),
|
|
409
|
+
maxLength: z.number().optional(),
|
|
410
|
+
pattern: z.string().optional()
|
|
411
|
+
})
|
|
412
|
+
);
|
|
413
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
414
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
415
|
+
example: z.unknown().optional()
|
|
416
|
+
});
|
|
417
|
+
var dataSourceResponseSchema = z.object({
|
|
418
|
+
description: z.string().optional(),
|
|
419
|
+
defaultContentType: z.string().optional(),
|
|
420
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
421
|
+
});
|
|
422
|
+
var jsonBaseFields = {
|
|
423
|
+
description: z.string(),
|
|
424
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
425
|
+
response: dataSourceResponseSchema.optional(),
|
|
426
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
427
|
+
};
|
|
428
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
429
|
+
...jsonBaseFields,
|
|
430
|
+
type: z.literal("sql").optional(),
|
|
431
|
+
query: z.string(),
|
|
432
|
+
connectionId: z.string()
|
|
433
|
+
});
|
|
434
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
435
|
+
...jsonBaseFields,
|
|
436
|
+
type: z.literal("typescript"),
|
|
437
|
+
handlerPath: z.string()
|
|
438
|
+
});
|
|
439
|
+
var anyJsonDataSourceSchema = z.union([
|
|
440
|
+
jsonTypeScriptDataSourceSchema,
|
|
441
|
+
jsonSqlDataSourceSchema
|
|
442
|
+
]);
|
|
443
|
+
|
|
381
444
|
// src/registry.ts
|
|
382
445
|
var dataSources = /* @__PURE__ */ new Map();
|
|
383
446
|
var currentDirPath = "";
|
|
@@ -443,26 +506,18 @@ async function initialize() {
|
|
|
443
506
|
jsonFiles.map(async (file) => {
|
|
444
507
|
const slug = file.replace(/\.json$/, "");
|
|
445
508
|
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`);
|
|
509
|
+
const parsed = anyJsonDataSourceSchema.safeParse(JSON.parse(raw));
|
|
510
|
+
if (!parsed.success) {
|
|
511
|
+
console.warn(`[registry] Skipping ${file}: ${parsed.error.message}`);
|
|
453
512
|
return;
|
|
454
513
|
}
|
|
514
|
+
const def = parsed.data;
|
|
455
515
|
if (def.type === "typescript") {
|
|
456
|
-
if (!def.handlerPath) {
|
|
457
|
-
console.warn(`[registry] Skipping ${file}: missing handlerPath`);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
516
|
const absoluteHandlerPath = validateHandlerPath(dirPath, def.handlerPath);
|
|
461
517
|
const dataSourceDef = {
|
|
462
518
|
description: def.description,
|
|
463
519
|
parameters: def.parameters ?? [],
|
|
464
520
|
response: def.response,
|
|
465
|
-
connectionId: def.connectionId,
|
|
466
521
|
cacheConfig: def.cache,
|
|
467
522
|
handler: async () => {
|
|
468
523
|
throw new Error("TypeScript handler must be called via _tsHandlerPath");
|
|
@@ -474,10 +529,6 @@ async function initialize() {
|
|
|
474
529
|
console.log(`[registry] registered (typescript): ${slug}`);
|
|
475
530
|
} else {
|
|
476
531
|
const sqlDef = def;
|
|
477
|
-
if (!sqlDef.query) {
|
|
478
|
-
console.warn(`[registry] Skipping ${file}: missing query`);
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
532
|
const dataSourceDef = {
|
|
482
533
|
description: sqlDef.description,
|
|
483
534
|
parameters: sqlDef.parameters ?? [],
|
|
@@ -567,17 +618,26 @@ function getDataSource(slug) {
|
|
|
567
618
|
return dataSources.get(slug);
|
|
568
619
|
}
|
|
569
620
|
function buildMeta(slug, def) {
|
|
570
|
-
|
|
621
|
+
const base = {
|
|
571
622
|
slug,
|
|
572
623
|
description: def.description,
|
|
573
|
-
type: def._isTypescript ? "typescript" : "sql",
|
|
574
624
|
parameters: def.parameters,
|
|
575
625
|
response: def.response,
|
|
576
|
-
query: def._query,
|
|
577
|
-
connectionId: def.connectionId,
|
|
578
|
-
handlerPath: def._tsHandlerPath ? path2.relative(currentDirPath, def._tsHandlerPath) : void 0,
|
|
579
626
|
cache: def.cacheConfig
|
|
580
627
|
};
|
|
628
|
+
if (def._isTypescript) {
|
|
629
|
+
return {
|
|
630
|
+
...base,
|
|
631
|
+
type: "typescript",
|
|
632
|
+
handlerPath: path2.relative(currentDirPath, def._tsHandlerPath)
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
...base,
|
|
637
|
+
type: "sql",
|
|
638
|
+
connectionId: def.connectionId,
|
|
639
|
+
query: def._query
|
|
640
|
+
};
|
|
581
641
|
}
|
|
582
642
|
function getAllMeta() {
|
|
583
643
|
return Array.from(dataSources.entries()).map(
|
|
@@ -913,8 +973,13 @@ app4.get("/runtime-data", (c) => {
|
|
|
913
973
|
});
|
|
914
974
|
var pages_default = app4;
|
|
915
975
|
|
|
976
|
+
// src/connection.ts
|
|
977
|
+
import { getContext } from "hono/context-storage";
|
|
978
|
+
import { getCookie } from "hono/cookie";
|
|
979
|
+
|
|
916
980
|
// src/index.ts
|
|
917
981
|
var apiApp = new Hono5();
|
|
982
|
+
apiApp.use("/*", contextStorage());
|
|
918
983
|
apiApp.use("/*", cors());
|
|
919
984
|
apiApp.route("/data-source", data_source_default);
|
|
920
985
|
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
|
+
};
|
package/dist/vite-plugin.d.ts
CHANGED
package/dist/vite-plugin.js
CHANGED
|
@@ -380,6 +380,68 @@ function createConnectorRegistry() {
|
|
|
380
380
|
// src/connector-client/index.ts
|
|
381
381
|
var { getClient, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
382
382
|
|
|
383
|
+
// src/types/data-source.ts
|
|
384
|
+
import { z } from "zod";
|
|
385
|
+
var parameterMetaSchema = z.object({
|
|
386
|
+
name: z.string(),
|
|
387
|
+
type: z.enum(["string", "number", "boolean"]),
|
|
388
|
+
description: z.string(),
|
|
389
|
+
required: z.boolean().optional(),
|
|
390
|
+
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
391
|
+
});
|
|
392
|
+
var dataSourceCacheConfigSchema = z.object({
|
|
393
|
+
ttl: z.number(),
|
|
394
|
+
staleWhileRevalidate: z.boolean().optional()
|
|
395
|
+
});
|
|
396
|
+
var dataSourceSchemaObjectSchema = z.lazy(
|
|
397
|
+
() => z.object({
|
|
398
|
+
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
399
|
+
format: z.string().optional(),
|
|
400
|
+
description: z.string().optional(),
|
|
401
|
+
nullable: z.boolean().optional(),
|
|
402
|
+
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
403
|
+
items: dataSourceSchemaObjectSchema.optional(),
|
|
404
|
+
properties: z.record(z.string(), dataSourceSchemaObjectSchema).optional(),
|
|
405
|
+
required: z.array(z.string()).optional(),
|
|
406
|
+
additionalProperties: z.union([z.boolean(), dataSourceSchemaObjectSchema]).optional(),
|
|
407
|
+
minimum: z.number().optional(),
|
|
408
|
+
maximum: z.number().optional(),
|
|
409
|
+
minLength: z.number().optional(),
|
|
410
|
+
maxLength: z.number().optional(),
|
|
411
|
+
pattern: z.string().optional()
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
var dataSourceMediaTypeSchema = z.object({
|
|
415
|
+
schema: dataSourceSchemaObjectSchema.optional(),
|
|
416
|
+
example: z.unknown().optional()
|
|
417
|
+
});
|
|
418
|
+
var dataSourceResponseSchema = z.object({
|
|
419
|
+
description: z.string().optional(),
|
|
420
|
+
defaultContentType: z.string().optional(),
|
|
421
|
+
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
422
|
+
});
|
|
423
|
+
var jsonBaseFields = {
|
|
424
|
+
description: z.string(),
|
|
425
|
+
parameters: z.array(parameterMetaSchema).optional(),
|
|
426
|
+
response: dataSourceResponseSchema.optional(),
|
|
427
|
+
cache: dataSourceCacheConfigSchema.optional()
|
|
428
|
+
};
|
|
429
|
+
var jsonSqlDataSourceSchema = z.object({
|
|
430
|
+
...jsonBaseFields,
|
|
431
|
+
type: z.literal("sql").optional(),
|
|
432
|
+
query: z.string(),
|
|
433
|
+
connectionId: z.string()
|
|
434
|
+
});
|
|
435
|
+
var jsonTypeScriptDataSourceSchema = z.object({
|
|
436
|
+
...jsonBaseFields,
|
|
437
|
+
type: z.literal("typescript"),
|
|
438
|
+
handlerPath: z.string()
|
|
439
|
+
});
|
|
440
|
+
var anyJsonDataSourceSchema = z.union([
|
|
441
|
+
jsonTypeScriptDataSourceSchema,
|
|
442
|
+
jsonSqlDataSourceSchema
|
|
443
|
+
]);
|
|
444
|
+
|
|
383
445
|
// src/registry.ts
|
|
384
446
|
var viteServer = null;
|
|
385
447
|
function setViteServer(server) {
|
|
@@ -414,8 +476,17 @@ function squadbasePlugin(options = {}) {
|
|
|
414
476
|
const {
|
|
415
477
|
buildEntry = "@squadbase/vite-server/main",
|
|
416
478
|
devEntry = "@squadbase/vite-server",
|
|
417
|
-
|
|
418
|
-
|
|
479
|
+
external = [
|
|
480
|
+
"pg",
|
|
481
|
+
"@google-cloud/bigquery",
|
|
482
|
+
"snowflake-sdk",
|
|
483
|
+
"mysql2",
|
|
484
|
+
"@databricks/sql",
|
|
485
|
+
"@aws-sdk/client-athena",
|
|
486
|
+
"@aws-sdk/client-redshift-data",
|
|
487
|
+
"@google-analytics/data",
|
|
488
|
+
"@kintone/rest-api-client"
|
|
489
|
+
],
|
|
419
490
|
exclude = DEFAULT_EXCLUDE
|
|
420
491
|
} = options;
|
|
421
492
|
const isServerBuild = (_, { command, mode }) => command === "build" && mode !== "client";
|
|
@@ -423,7 +494,6 @@ function squadbasePlugin(options = {}) {
|
|
|
423
494
|
entry: resolveEntry(buildEntry),
|
|
424
495
|
outputDir: "./dist/server",
|
|
425
496
|
output: "index.js",
|
|
426
|
-
port,
|
|
427
497
|
external
|
|
428
498
|
});
|
|
429
499
|
const rawDevServerPlugin = devServer({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squadbase/vite-server",
|
|
3
|
-
"version": "0.0.1-build-
|
|
3
|
+
"version": "0.0.1-build-11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"@google-cloud/bigquery": "^7.9.4",
|
|
43
43
|
"@hono/node-server": "^1.19.9",
|
|
44
44
|
"@hono/vite-build": "^1.10.0",
|
|
45
|
-
"@hono/vite-dev-server": "^0.
|
|
45
|
+
"@hono/vite-dev-server": "^0.25.0",
|
|
46
46
|
"@kintone/rest-api-client": "^5.5.0",
|
|
47
47
|
"hono": "^4.11.9",
|
|
48
48
|
"mysql2": "^3.11.0",
|
|
49
49
|
"pg": "^8.18.0",
|
|
50
|
-
"snowflake-sdk": "^1.15.0"
|
|
50
|
+
"snowflake-sdk": "^1.15.0",
|
|
51
|
+
"zod": "^4.3.6"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@clack/prompts": "^0.9.1",
|
|
@@ -57,6 +58,6 @@
|
|
|
57
58
|
"tsup": "^8.4.0",
|
|
58
59
|
"tsx": "^4.19.3",
|
|
59
60
|
"typescript": "~5.7.0",
|
|
60
|
-
"vite": "^
|
|
61
|
+
"vite": "^7.0.0"
|
|
61
62
|
}
|
|
62
63
|
}
|