@squadbase/vite-server 0.0.8 → 0.0.10
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 +42 -42
- package/dist/index.js +51 -51
- package/dist/main.js +51 -51
- package/dist/types/{data-source.d.ts → server-logic.d.ts} +38 -38
- package/dist/types/{data-source.js → server-logic.js} +25 -25
- package/dist/vite-plugin.js +18 -18
- package/package.json +5 -5
package/dist/cli/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var interactive_exports = {};
|
|
|
14
14
|
__export(interactive_exports, {
|
|
15
15
|
confirmRunAll: () => confirmRunAll,
|
|
16
16
|
inputParameters: () => inputParameters,
|
|
17
|
-
|
|
17
|
+
selectServerLogic: () => selectServerLogic
|
|
18
18
|
});
|
|
19
19
|
async function getPrompts() {
|
|
20
20
|
try {
|
|
@@ -26,10 +26,10 @@ async function getPrompts() {
|
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
async function
|
|
29
|
+
async function selectServerLogic(slugs) {
|
|
30
30
|
const { select, isCancel } = await getPrompts();
|
|
31
31
|
const result = await select({
|
|
32
|
-
message: "Select a
|
|
32
|
+
message: "Select a server logic to test:",
|
|
33
33
|
options: slugs.map((s) => ({ value: s, label: s }))
|
|
34
34
|
});
|
|
35
35
|
if (isCancel(result)) return null;
|
|
@@ -68,7 +68,7 @@ async function inputParameters(params) {
|
|
|
68
68
|
async function confirmRunAll() {
|
|
69
69
|
const { confirm, isCancel } = await getPrompts();
|
|
70
70
|
const result = await confirm({
|
|
71
|
-
message: "Run all
|
|
71
|
+
message: "Run all server logics?"
|
|
72
72
|
});
|
|
73
73
|
if (isCancel(result)) return false;
|
|
74
74
|
return result;
|
|
@@ -280,7 +280,7 @@ import { readdir, readFile as readFile2, mkdir } from "fs/promises";
|
|
|
280
280
|
import { watch as fsWatch2 } from "fs";
|
|
281
281
|
import path2 from "path";
|
|
282
282
|
|
|
283
|
-
// src/types/
|
|
283
|
+
// src/types/server-logic.ts
|
|
284
284
|
import { z } from "zod";
|
|
285
285
|
var parameterMetaSchema = z.object({
|
|
286
286
|
name: z.string(),
|
|
@@ -289,21 +289,21 @@ var parameterMetaSchema = z.object({
|
|
|
289
289
|
required: z.boolean().optional(),
|
|
290
290
|
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
291
291
|
});
|
|
292
|
-
var
|
|
292
|
+
var serverLogicCacheConfigSchema = z.object({
|
|
293
293
|
ttl: z.number(),
|
|
294
294
|
staleWhileRevalidate: z.boolean().optional()
|
|
295
295
|
});
|
|
296
|
-
var
|
|
296
|
+
var serverLogicSchemaObjectSchema = z.lazy(
|
|
297
297
|
() => z.object({
|
|
298
298
|
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
299
299
|
format: z.string().optional(),
|
|
300
300
|
description: z.string().optional(),
|
|
301
301
|
nullable: z.boolean().optional(),
|
|
302
302
|
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
303
|
-
items:
|
|
304
|
-
properties: z.record(z.string(),
|
|
303
|
+
items: serverLogicSchemaObjectSchema.optional(),
|
|
304
|
+
properties: z.record(z.string(), serverLogicSchemaObjectSchema).optional(),
|
|
305
305
|
required: z.array(z.string()).optional(),
|
|
306
|
-
additionalProperties: z.union([z.boolean(),
|
|
306
|
+
additionalProperties: z.union([z.boolean(), serverLogicSchemaObjectSchema]).optional(),
|
|
307
307
|
minimum: z.number().optional(),
|
|
308
308
|
maximum: z.number().optional(),
|
|
309
309
|
minLength: z.number().optional(),
|
|
@@ -311,34 +311,34 @@ var dataSourceSchemaObjectSchema = z.lazy(
|
|
|
311
311
|
pattern: z.string().optional()
|
|
312
312
|
})
|
|
313
313
|
);
|
|
314
|
-
var
|
|
315
|
-
schema:
|
|
314
|
+
var serverLogicMediaTypeSchema = z.object({
|
|
315
|
+
schema: serverLogicSchemaObjectSchema.optional(),
|
|
316
316
|
example: z.unknown().optional()
|
|
317
317
|
});
|
|
318
|
-
var
|
|
318
|
+
var serverLogicResponseSchema = z.object({
|
|
319
319
|
description: z.string().optional(),
|
|
320
|
-
content: z.record(z.string(),
|
|
320
|
+
content: z.record(z.string(), serverLogicMediaTypeSchema).optional()
|
|
321
321
|
});
|
|
322
322
|
var jsonBaseFields = {
|
|
323
323
|
description: z.string(),
|
|
324
324
|
parameters: z.array(parameterMetaSchema).optional(),
|
|
325
|
-
response:
|
|
326
|
-
cache:
|
|
325
|
+
response: serverLogicResponseSchema.optional(),
|
|
326
|
+
cache: serverLogicCacheConfigSchema.optional()
|
|
327
327
|
};
|
|
328
|
-
var
|
|
328
|
+
var jsonSqlServerLogicSchema = z.object({
|
|
329
329
|
...jsonBaseFields,
|
|
330
330
|
type: z.literal("sql").optional(),
|
|
331
331
|
query: z.string(),
|
|
332
332
|
connectionId: z.string()
|
|
333
333
|
});
|
|
334
|
-
var
|
|
334
|
+
var jsonTypeScriptServerLogicSchema = z.object({
|
|
335
335
|
...jsonBaseFields,
|
|
336
336
|
type: z.literal("typescript"),
|
|
337
337
|
handlerPath: z.string()
|
|
338
338
|
});
|
|
339
|
-
var
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
var anyJsonServerLogicSchema = z.union([
|
|
340
|
+
jsonTypeScriptServerLogicSchema,
|
|
341
|
+
jsonSqlServerLogicSchema
|
|
342
342
|
]);
|
|
343
343
|
|
|
344
344
|
// src/registry.ts
|
|
@@ -357,7 +357,7 @@ function applyDefaults(parameterMeta, runtimeParams) {
|
|
|
357
357
|
}
|
|
358
358
|
return result;
|
|
359
359
|
}
|
|
360
|
-
var
|
|
360
|
+
var defaultServerLogicDir = path2.join(process.cwd(), "server-logic");
|
|
361
361
|
|
|
362
362
|
// src/cli/runner.ts
|
|
363
363
|
function createStubContext(params) {
|
|
@@ -388,7 +388,7 @@ function createStubContext(params) {
|
|
|
388
388
|
};
|
|
389
389
|
return stub;
|
|
390
390
|
}
|
|
391
|
-
async function
|
|
391
|
+
async function runSqlServerLogic(slug, def, params, limit) {
|
|
392
392
|
const start = Date.now();
|
|
393
393
|
try {
|
|
394
394
|
const query = await getQuery(def.connectionId);
|
|
@@ -412,7 +412,7 @@ async function runSqlDataSource(slug, def, params, limit) {
|
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
async function
|
|
415
|
+
async function runTypescriptServerLogic(slug, handlerPath, params) {
|
|
416
416
|
const start = Date.now();
|
|
417
417
|
try {
|
|
418
418
|
const mod = await import(pathToFileURL(handlerPath).href);
|
|
@@ -446,19 +446,19 @@ async function runTypescriptDataSource(slug, handlerPath, params) {
|
|
|
446
446
|
};
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
-
async function
|
|
449
|
+
async function runServerLogic(slug, dirPath, params, limit) {
|
|
450
450
|
const jsonPath = path3.join(dirPath, `${slug}.json`);
|
|
451
451
|
let def;
|
|
452
452
|
try {
|
|
453
453
|
const raw = await readFile3(jsonPath, "utf-8");
|
|
454
|
-
const parsed =
|
|
454
|
+
const parsed = anyJsonServerLogicSchema.safeParse(JSON.parse(raw));
|
|
455
455
|
if (!parsed.success) {
|
|
456
456
|
return {
|
|
457
457
|
slug,
|
|
458
458
|
rows: [],
|
|
459
459
|
rowCount: 0,
|
|
460
460
|
durationMs: 0,
|
|
461
|
-
error: new Error(`Invalid
|
|
461
|
+
error: new Error(`Invalid server logic definition: ${parsed.error.message}`)
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
464
|
def = parsed.data;
|
|
@@ -468,14 +468,14 @@ async function runDataSource(slug, dirPath, params, limit) {
|
|
|
468
468
|
rows: [],
|
|
469
469
|
rowCount: 0,
|
|
470
470
|
durationMs: 0,
|
|
471
|
-
error: new Error(`
|
|
471
|
+
error: new Error(`Server logic not found: ${jsonPath}`)
|
|
472
472
|
};
|
|
473
473
|
}
|
|
474
474
|
if (def.type === "typescript") {
|
|
475
475
|
const absolutePath = path3.resolve(dirPath, def.handlerPath);
|
|
476
|
-
return
|
|
476
|
+
return runTypescriptServerLogic(slug, absolutePath, params);
|
|
477
477
|
}
|
|
478
|
-
return
|
|
478
|
+
return runSqlServerLogic(slug, def, params, limit);
|
|
479
479
|
}
|
|
480
480
|
async function listSlugs(dirPath) {
|
|
481
481
|
try {
|
|
@@ -487,7 +487,7 @@ async function listSlugs(dirPath) {
|
|
|
487
487
|
}
|
|
488
488
|
async function runAll(dirPath, params, limit) {
|
|
489
489
|
const slugs = await listSlugs(dirPath);
|
|
490
|
-
return Promise.all(slugs.map((slug) =>
|
|
490
|
+
return Promise.all(slugs.map((slug) => runServerLogic(slug, dirPath, params, limit)));
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
// src/cli/display.ts
|
|
@@ -570,14 +570,14 @@ function displayError(error) {
|
|
|
570
570
|
|
|
571
571
|
// src/cli/index.ts
|
|
572
572
|
var HELP = `
|
|
573
|
-
Usage: squadbase-
|
|
573
|
+
Usage: squadbase-sl-test [options]
|
|
574
574
|
|
|
575
575
|
Options:
|
|
576
|
-
--slug <slug> Run a specific
|
|
577
|
-
--all Run all
|
|
576
|
+
--slug <slug> Run a specific server logic
|
|
577
|
+
--all Run all server logics
|
|
578
578
|
--params k=v,... Comma-separated key=value parameters
|
|
579
579
|
--env <path> Path to .env file (default: ../../.env)
|
|
580
|
-
--dir <path>
|
|
580
|
+
--dir <path> Server logic directory (default: ./server-logic)
|
|
581
581
|
--format table|json Output format (default: table)
|
|
582
582
|
--limit <n> Max rows to display (default: 50)
|
|
583
583
|
--debug Show SQL query and parameter values
|
|
@@ -609,7 +609,7 @@ async function main() {
|
|
|
609
609
|
process.exit(0);
|
|
610
610
|
}
|
|
611
611
|
const cwd = process.cwd();
|
|
612
|
-
const dirPath = values.dir ? path4.resolve(cwd, values.dir) : path4.join(cwd, "
|
|
612
|
+
const dirPath = values.dir ? path4.resolve(cwd, values.dir) : path4.join(cwd, "server-logic");
|
|
613
613
|
const envPath = values.env ? path4.resolve(cwd, values.env) : path4.join(cwd, "../../.env");
|
|
614
614
|
const limit = parseInt(values.limit ?? "50", 10);
|
|
615
615
|
const format = values.format ?? "table";
|
|
@@ -625,7 +625,7 @@ async function main() {
|
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
if (values.slug) {
|
|
628
|
-
const result = await
|
|
628
|
+
const result = await runServerLogic(values.slug, dirPath, params, limit);
|
|
629
629
|
if (format === "json") {
|
|
630
630
|
displayJson([result]);
|
|
631
631
|
} else {
|
|
@@ -653,12 +653,12 @@ Total: ${results.length}, Failed: ${failed}`);
|
|
|
653
653
|
} else {
|
|
654
654
|
const slugs = await listSlugs(dirPath);
|
|
655
655
|
if (slugs.length === 0) {
|
|
656
|
-
displayError(new Error(`No
|
|
656
|
+
displayError(new Error(`No server logics found in ${dirPath}`));
|
|
657
657
|
process.exit(1);
|
|
658
658
|
}
|
|
659
659
|
try {
|
|
660
|
-
const {
|
|
661
|
-
const slug = await
|
|
660
|
+
const { selectServerLogic: selectServerLogic2, inputParameters: inputParameters2 } = await Promise.resolve().then(() => (init_interactive(), interactive_exports));
|
|
661
|
+
const slug = await selectServerLogic2(slugs);
|
|
662
662
|
if (!slug) {
|
|
663
663
|
console.log("Cancelled.");
|
|
664
664
|
process.exit(0);
|
|
@@ -667,13 +667,13 @@ Total: ${results.length}, Failed: ${failed}`);
|
|
|
667
667
|
let paramMeta = [];
|
|
668
668
|
try {
|
|
669
669
|
const raw = await readFile4(jsonPath, "utf-8");
|
|
670
|
-
const parsed =
|
|
670
|
+
const parsed = anyJsonServerLogicSchema.safeParse(JSON.parse(raw));
|
|
671
671
|
if (parsed.success) paramMeta = parsed.data.parameters ?? [];
|
|
672
672
|
} catch {
|
|
673
673
|
}
|
|
674
674
|
const interactiveParams = await inputParameters2(paramMeta);
|
|
675
675
|
const merged = { ...interactiveParams, ...params };
|
|
676
|
-
const result = await
|
|
676
|
+
const result = await runServerLogic(slug, dirPath, merged, limit);
|
|
677
677
|
displaySummary(result);
|
|
678
678
|
if (values.debug) displayDebug(result);
|
|
679
679
|
if (!result.error) displayTable(result.rows, limit);
|
package/dist/index.js
CHANGED
|
@@ -451,7 +451,7 @@ function createDbtClient(entry, slug) {
|
|
|
451
451
|
// src/connector-client/index.ts
|
|
452
452
|
var { getQuery, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
453
453
|
|
|
454
|
-
// src/types/
|
|
454
|
+
// src/types/server-logic.ts
|
|
455
455
|
import { z } from "zod";
|
|
456
456
|
var parameterMetaSchema = z.object({
|
|
457
457
|
name: z.string(),
|
|
@@ -460,21 +460,21 @@ var parameterMetaSchema = z.object({
|
|
|
460
460
|
required: z.boolean().optional(),
|
|
461
461
|
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
462
462
|
});
|
|
463
|
-
var
|
|
463
|
+
var serverLogicCacheConfigSchema = z.object({
|
|
464
464
|
ttl: z.number(),
|
|
465
465
|
staleWhileRevalidate: z.boolean().optional()
|
|
466
466
|
});
|
|
467
|
-
var
|
|
467
|
+
var serverLogicSchemaObjectSchema = z.lazy(
|
|
468
468
|
() => z.object({
|
|
469
469
|
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
470
470
|
format: z.string().optional(),
|
|
471
471
|
description: z.string().optional(),
|
|
472
472
|
nullable: z.boolean().optional(),
|
|
473
473
|
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
474
|
-
items:
|
|
475
|
-
properties: z.record(z.string(),
|
|
474
|
+
items: serverLogicSchemaObjectSchema.optional(),
|
|
475
|
+
properties: z.record(z.string(), serverLogicSchemaObjectSchema).optional(),
|
|
476
476
|
required: z.array(z.string()).optional(),
|
|
477
|
-
additionalProperties: z.union([z.boolean(),
|
|
477
|
+
additionalProperties: z.union([z.boolean(), serverLogicSchemaObjectSchema]).optional(),
|
|
478
478
|
minimum: z.number().optional(),
|
|
479
479
|
maximum: z.number().optional(),
|
|
480
480
|
minLength: z.number().optional(),
|
|
@@ -482,45 +482,45 @@ var dataSourceSchemaObjectSchema = z.lazy(
|
|
|
482
482
|
pattern: z.string().optional()
|
|
483
483
|
})
|
|
484
484
|
);
|
|
485
|
-
var
|
|
486
|
-
schema:
|
|
485
|
+
var serverLogicMediaTypeSchema = z.object({
|
|
486
|
+
schema: serverLogicSchemaObjectSchema.optional(),
|
|
487
487
|
example: z.unknown().optional()
|
|
488
488
|
});
|
|
489
|
-
var
|
|
489
|
+
var serverLogicResponseSchema = z.object({
|
|
490
490
|
description: z.string().optional(),
|
|
491
|
-
content: z.record(z.string(),
|
|
491
|
+
content: z.record(z.string(), serverLogicMediaTypeSchema).optional()
|
|
492
492
|
});
|
|
493
493
|
var jsonBaseFields = {
|
|
494
494
|
description: z.string(),
|
|
495
495
|
parameters: z.array(parameterMetaSchema).optional(),
|
|
496
|
-
response:
|
|
497
|
-
cache:
|
|
496
|
+
response: serverLogicResponseSchema.optional(),
|
|
497
|
+
cache: serverLogicCacheConfigSchema.optional()
|
|
498
498
|
};
|
|
499
|
-
var
|
|
499
|
+
var jsonSqlServerLogicSchema = z.object({
|
|
500
500
|
...jsonBaseFields,
|
|
501
501
|
type: z.literal("sql").optional(),
|
|
502
502
|
query: z.string(),
|
|
503
503
|
connectionId: z.string()
|
|
504
504
|
});
|
|
505
|
-
var
|
|
505
|
+
var jsonTypeScriptServerLogicSchema = z.object({
|
|
506
506
|
...jsonBaseFields,
|
|
507
507
|
type: z.literal("typescript"),
|
|
508
508
|
handlerPath: z.string()
|
|
509
509
|
});
|
|
510
|
-
var
|
|
511
|
-
|
|
512
|
-
|
|
510
|
+
var anyJsonServerLogicSchema = z.union([
|
|
511
|
+
jsonTypeScriptServerLogicSchema,
|
|
512
|
+
jsonSqlServerLogicSchema
|
|
513
513
|
]);
|
|
514
514
|
|
|
515
515
|
// src/registry.ts
|
|
516
|
-
var
|
|
516
|
+
var serverLogics = /* @__PURE__ */ new Map();
|
|
517
517
|
var currentDirPath = "";
|
|
518
518
|
var viteServer = null;
|
|
519
519
|
function validateHandlerPath(dirPath, handlerPath) {
|
|
520
520
|
const absolute = path2.resolve(dirPath, handlerPath);
|
|
521
521
|
const normalizedDir = path2.resolve(dirPath);
|
|
522
522
|
if (!absolute.startsWith(normalizedDir + path2.sep)) {
|
|
523
|
-
throw new Error(`Handler path escapes
|
|
523
|
+
throw new Error(`Handler path escapes server-logic directory: ${handlerPath}`);
|
|
524
524
|
}
|
|
525
525
|
if (!absolute.endsWith(".ts")) {
|
|
526
526
|
throw new Error(`Handler must be a .ts file: ${handlerPath}`);
|
|
@@ -558,13 +558,13 @@ function applyDefaults(parameterMeta, runtimeParams) {
|
|
|
558
558
|
}
|
|
559
559
|
return result;
|
|
560
560
|
}
|
|
561
|
-
var
|
|
561
|
+
var defaultServerLogicDir = path2.join(process.cwd(), "server-logic");
|
|
562
562
|
async function initialize() {
|
|
563
563
|
console.log(
|
|
564
|
-
`[registry] loading
|
|
564
|
+
`[registry] loading server logics from ${defaultServerLogicDir}...`
|
|
565
565
|
);
|
|
566
|
-
|
|
567
|
-
const dirPath = process.env.DATA_SOURCE_DIR ||
|
|
566
|
+
serverLogics.clear();
|
|
567
|
+
const dirPath = process.env.SERVER_LOGIC_DIR || process.env.DATA_SOURCE_DIR || defaultServerLogicDir;
|
|
568
568
|
currentDirPath = dirPath;
|
|
569
569
|
await mkdir(dirPath, { recursive: true });
|
|
570
570
|
const files = await readdir(dirPath);
|
|
@@ -573,7 +573,7 @@ async function initialize() {
|
|
|
573
573
|
jsonFiles.map(async (file) => {
|
|
574
574
|
const slug = file.replace(/\.json$/, "");
|
|
575
575
|
const raw = await readFile2(`${dirPath}/${file}`, "utf-8");
|
|
576
|
-
const parsed =
|
|
576
|
+
const parsed = anyJsonServerLogicSchema.safeParse(JSON.parse(raw));
|
|
577
577
|
if (!parsed.success) {
|
|
578
578
|
console.warn(`[registry] Skipping ${file}: ${parsed.error.message}`);
|
|
579
579
|
return;
|
|
@@ -581,7 +581,7 @@ async function initialize() {
|
|
|
581
581
|
const def = parsed.data;
|
|
582
582
|
if (def.type === "typescript") {
|
|
583
583
|
const absoluteHandlerPath = validateHandlerPath(dirPath, def.handlerPath);
|
|
584
|
-
const
|
|
584
|
+
const serverLogicDef = {
|
|
585
585
|
description: def.description,
|
|
586
586
|
parameters: def.parameters ?? [],
|
|
587
587
|
response: def.response,
|
|
@@ -592,11 +592,11 @@ async function initialize() {
|
|
|
592
592
|
_isTypescript: true,
|
|
593
593
|
_tsHandlerPath: absoluteHandlerPath
|
|
594
594
|
};
|
|
595
|
-
|
|
595
|
+
serverLogics.set(slug, serverLogicDef);
|
|
596
596
|
console.log(`[registry] registered (typescript): ${slug}`);
|
|
597
597
|
} else {
|
|
598
598
|
const sqlDef = def;
|
|
599
|
-
const
|
|
599
|
+
const serverLogicDef = {
|
|
600
600
|
description: sqlDef.description,
|
|
601
601
|
parameters: sqlDef.parameters ?? [],
|
|
602
602
|
response: sqlDef.response,
|
|
@@ -613,7 +613,7 @@ async function initialize() {
|
|
|
613
613
|
return result.rows;
|
|
614
614
|
}
|
|
615
615
|
};
|
|
616
|
-
|
|
616
|
+
serverLogics.set(slug, serverLogicDef);
|
|
617
617
|
console.log(`[registry] registered: ${slug}`);
|
|
618
618
|
}
|
|
619
619
|
})
|
|
@@ -626,29 +626,29 @@ async function initialize() {
|
|
|
626
626
|
);
|
|
627
627
|
}
|
|
628
628
|
});
|
|
629
|
-
console.log(`[registry] ${
|
|
629
|
+
console.log(`[registry] ${serverLogics.size} server logic(s) ready`);
|
|
630
630
|
}
|
|
631
631
|
var reloadTimer = null;
|
|
632
632
|
function startWatching() {
|
|
633
|
-
const dirPath = process.env.DATA_SOURCE_DIR ||
|
|
633
|
+
const dirPath = process.env.SERVER_LOGIC_DIR || process.env.DATA_SOURCE_DIR || defaultServerLogicDir;
|
|
634
634
|
try {
|
|
635
635
|
fsWatch2(dirPath, { persistent: false }, (_event, filename) => {
|
|
636
636
|
if (!filename?.endsWith(".json") && !filename?.endsWith(".ts")) return;
|
|
637
637
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
638
638
|
reloadTimer = setTimeout(async () => {
|
|
639
|
-
console.log("[registry]
|
|
639
|
+
console.log("[registry] server-logic changed, reloading...");
|
|
640
640
|
await initialize();
|
|
641
641
|
}, 300);
|
|
642
642
|
});
|
|
643
|
-
console.log("[registry] watching
|
|
643
|
+
console.log("[registry] watching server-logic directory");
|
|
644
644
|
} catch {
|
|
645
645
|
console.warn(
|
|
646
|
-
"[registry] could not watch
|
|
646
|
+
"[registry] could not watch server-logic directory (static load only)"
|
|
647
647
|
);
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
|
-
function
|
|
651
|
-
return
|
|
650
|
+
function getServerLogic(slug) {
|
|
651
|
+
return serverLogics.get(slug);
|
|
652
652
|
}
|
|
653
653
|
function buildMeta(slug, def) {
|
|
654
654
|
const base = {
|
|
@@ -673,17 +673,17 @@ function buildMeta(slug, def) {
|
|
|
673
673
|
};
|
|
674
674
|
}
|
|
675
675
|
function getAllMeta() {
|
|
676
|
-
return Array.from(
|
|
676
|
+
return Array.from(serverLogics.entries()).map(
|
|
677
677
|
([slug, def]) => buildMeta(slug, def)
|
|
678
678
|
);
|
|
679
679
|
}
|
|
680
680
|
function getMeta(slug) {
|
|
681
|
-
const def =
|
|
681
|
+
const def = serverLogics.get(slug);
|
|
682
682
|
if (!def) return void 0;
|
|
683
683
|
return buildMeta(slug, def);
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
-
// src/routes/
|
|
686
|
+
// src/routes/server-logic.ts
|
|
687
687
|
import { Hono } from "hono";
|
|
688
688
|
|
|
689
689
|
// src/cache.ts
|
|
@@ -776,7 +776,7 @@ function buildCacheKey(slug, params) {
|
|
|
776
776
|
return `${slug}:${JSON.stringify(sortedParams)}`;
|
|
777
777
|
}
|
|
778
778
|
|
|
779
|
-
// src/routes/
|
|
779
|
+
// src/routes/server-logic.ts
|
|
780
780
|
var app = new Hono();
|
|
781
781
|
function buildSqlResponse(c, result) {
|
|
782
782
|
return c.json({ data: result });
|
|
@@ -786,9 +786,9 @@ function buildTypescriptResponse(result) {
|
|
|
786
786
|
}
|
|
787
787
|
app.get("/:slug", async (c) => {
|
|
788
788
|
const slug = c.req.param("slug");
|
|
789
|
-
const ds =
|
|
789
|
+
const ds = getServerLogic(slug);
|
|
790
790
|
if (!ds) {
|
|
791
|
-
return c.json({ error: `
|
|
791
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
792
792
|
}
|
|
793
793
|
try {
|
|
794
794
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
@@ -800,7 +800,7 @@ app.get("/:slug", async (c) => {
|
|
|
800
800
|
return buildSqlResponse(c, result);
|
|
801
801
|
}
|
|
802
802
|
} catch (e) {
|
|
803
|
-
console.error(`[
|
|
803
|
+
console.error(`[server-logic] ${slug} error:`, e);
|
|
804
804
|
return c.json(
|
|
805
805
|
{ error: e instanceof Error ? e.message : "Internal error" },
|
|
806
806
|
500
|
|
@@ -809,9 +809,9 @@ app.get("/:slug", async (c) => {
|
|
|
809
809
|
});
|
|
810
810
|
app.post("/:slug", async (c) => {
|
|
811
811
|
const slug = c.req.param("slug");
|
|
812
|
-
const ds =
|
|
812
|
+
const ds = getServerLogic(slug);
|
|
813
813
|
if (!ds) {
|
|
814
|
-
return c.json({ error: `
|
|
814
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
815
815
|
}
|
|
816
816
|
try {
|
|
817
817
|
const body = await c.req.json().catch(() => ({}));
|
|
@@ -877,16 +877,16 @@ app.post("/:slug", async (c) => {
|
|
|
877
877
|
c.header("Cache-Control", `max-age=${ttl}`);
|
|
878
878
|
return buildResponse(result);
|
|
879
879
|
} catch (e) {
|
|
880
|
-
console.error(`[
|
|
880
|
+
console.error(`[server-logic] ${slug} error:`, e);
|
|
881
881
|
return c.json(
|
|
882
882
|
{ error: e instanceof Error ? e.message : "Internal error" },
|
|
883
883
|
500
|
|
884
884
|
);
|
|
885
885
|
}
|
|
886
886
|
});
|
|
887
|
-
var
|
|
887
|
+
var server_logic_default = app;
|
|
888
888
|
|
|
889
|
-
// src/routes/
|
|
889
|
+
// src/routes/server-logic-meta.ts
|
|
890
890
|
import { Hono as Hono2 } from "hono";
|
|
891
891
|
var app2 = new Hono2();
|
|
892
892
|
app2.get("/", (c) => {
|
|
@@ -896,11 +896,11 @@ app2.get("/:slug", (c) => {
|
|
|
896
896
|
const slug = c.req.param("slug");
|
|
897
897
|
const meta = getMeta(slug);
|
|
898
898
|
if (!meta) {
|
|
899
|
-
return c.json({ error: `
|
|
899
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
900
900
|
}
|
|
901
901
|
return c.json(meta);
|
|
902
902
|
});
|
|
903
|
-
var
|
|
903
|
+
var server_logic_meta_default = app2;
|
|
904
904
|
|
|
905
905
|
// src/routes/cache.ts
|
|
906
906
|
import { Hono as Hono3 } from "hono";
|
|
@@ -1060,8 +1060,8 @@ function connection(connectionId) {
|
|
|
1060
1060
|
var apiApp = new Hono5();
|
|
1061
1061
|
apiApp.use("/*", contextStorage());
|
|
1062
1062
|
apiApp.use("/*", cors());
|
|
1063
|
-
apiApp.route("/
|
|
1064
|
-
apiApp.route("/
|
|
1063
|
+
apiApp.route("/server-logic", server_logic_default);
|
|
1064
|
+
apiApp.route("/server-logic-meta", server_logic_meta_default);
|
|
1065
1065
|
apiApp.route("/cache", cache_default);
|
|
1066
1066
|
apiApp.route("/", pages_default);
|
|
1067
1067
|
reloadEnvFile(path4.join(process.cwd(), ".env"));
|
package/dist/main.js
CHANGED
|
@@ -189,7 +189,7 @@ function resolveParams(entry, connectionId, plugin) {
|
|
|
189
189
|
// src/connector-client/index.ts
|
|
190
190
|
var { getQuery, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
191
191
|
|
|
192
|
-
// src/types/
|
|
192
|
+
// src/types/server-logic.ts
|
|
193
193
|
import { z } from "zod";
|
|
194
194
|
var parameterMetaSchema = z.object({
|
|
195
195
|
name: z.string(),
|
|
@@ -198,21 +198,21 @@ var parameterMetaSchema = z.object({
|
|
|
198
198
|
required: z.boolean().optional(),
|
|
199
199
|
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
200
200
|
});
|
|
201
|
-
var
|
|
201
|
+
var serverLogicCacheConfigSchema = z.object({
|
|
202
202
|
ttl: z.number(),
|
|
203
203
|
staleWhileRevalidate: z.boolean().optional()
|
|
204
204
|
});
|
|
205
|
-
var
|
|
205
|
+
var serverLogicSchemaObjectSchema = z.lazy(
|
|
206
206
|
() => z.object({
|
|
207
207
|
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
208
208
|
format: z.string().optional(),
|
|
209
209
|
description: z.string().optional(),
|
|
210
210
|
nullable: z.boolean().optional(),
|
|
211
211
|
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
212
|
-
items:
|
|
213
|
-
properties: z.record(z.string(),
|
|
212
|
+
items: serverLogicSchemaObjectSchema.optional(),
|
|
213
|
+
properties: z.record(z.string(), serverLogicSchemaObjectSchema).optional(),
|
|
214
214
|
required: z.array(z.string()).optional(),
|
|
215
|
-
additionalProperties: z.union([z.boolean(),
|
|
215
|
+
additionalProperties: z.union([z.boolean(), serverLogicSchemaObjectSchema]).optional(),
|
|
216
216
|
minimum: z.number().optional(),
|
|
217
217
|
maximum: z.number().optional(),
|
|
218
218
|
minLength: z.number().optional(),
|
|
@@ -220,45 +220,45 @@ var dataSourceSchemaObjectSchema = z.lazy(
|
|
|
220
220
|
pattern: z.string().optional()
|
|
221
221
|
})
|
|
222
222
|
);
|
|
223
|
-
var
|
|
224
|
-
schema:
|
|
223
|
+
var serverLogicMediaTypeSchema = z.object({
|
|
224
|
+
schema: serverLogicSchemaObjectSchema.optional(),
|
|
225
225
|
example: z.unknown().optional()
|
|
226
226
|
});
|
|
227
|
-
var
|
|
227
|
+
var serverLogicResponseSchema = z.object({
|
|
228
228
|
description: z.string().optional(),
|
|
229
|
-
content: z.record(z.string(),
|
|
229
|
+
content: z.record(z.string(), serverLogicMediaTypeSchema).optional()
|
|
230
230
|
});
|
|
231
231
|
var jsonBaseFields = {
|
|
232
232
|
description: z.string(),
|
|
233
233
|
parameters: z.array(parameterMetaSchema).optional(),
|
|
234
|
-
response:
|
|
235
|
-
cache:
|
|
234
|
+
response: serverLogicResponseSchema.optional(),
|
|
235
|
+
cache: serverLogicCacheConfigSchema.optional()
|
|
236
236
|
};
|
|
237
|
-
var
|
|
237
|
+
var jsonSqlServerLogicSchema = z.object({
|
|
238
238
|
...jsonBaseFields,
|
|
239
239
|
type: z.literal("sql").optional(),
|
|
240
240
|
query: z.string(),
|
|
241
241
|
connectionId: z.string()
|
|
242
242
|
});
|
|
243
|
-
var
|
|
243
|
+
var jsonTypeScriptServerLogicSchema = z.object({
|
|
244
244
|
...jsonBaseFields,
|
|
245
245
|
type: z.literal("typescript"),
|
|
246
246
|
handlerPath: z.string()
|
|
247
247
|
});
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
var anyJsonServerLogicSchema = z.union([
|
|
249
|
+
jsonTypeScriptServerLogicSchema,
|
|
250
|
+
jsonSqlServerLogicSchema
|
|
251
251
|
]);
|
|
252
252
|
|
|
253
253
|
// src/registry.ts
|
|
254
|
-
var
|
|
254
|
+
var serverLogics = /* @__PURE__ */ new Map();
|
|
255
255
|
var currentDirPath = "";
|
|
256
256
|
var viteServer = null;
|
|
257
257
|
function validateHandlerPath(dirPath, handlerPath) {
|
|
258
258
|
const absolute = path2.resolve(dirPath, handlerPath);
|
|
259
259
|
const normalizedDir = path2.resolve(dirPath);
|
|
260
260
|
if (!absolute.startsWith(normalizedDir + path2.sep)) {
|
|
261
|
-
throw new Error(`Handler path escapes
|
|
261
|
+
throw new Error(`Handler path escapes server-logic directory: ${handlerPath}`);
|
|
262
262
|
}
|
|
263
263
|
if (!absolute.endsWith(".ts")) {
|
|
264
264
|
throw new Error(`Handler must be a .ts file: ${handlerPath}`);
|
|
@@ -296,13 +296,13 @@ function applyDefaults(parameterMeta, runtimeParams) {
|
|
|
296
296
|
}
|
|
297
297
|
return result;
|
|
298
298
|
}
|
|
299
|
-
var
|
|
299
|
+
var defaultServerLogicDir = path2.join(process.cwd(), "server-logic");
|
|
300
300
|
async function initialize() {
|
|
301
301
|
console.log(
|
|
302
|
-
`[registry] loading
|
|
302
|
+
`[registry] loading server logics from ${defaultServerLogicDir}...`
|
|
303
303
|
);
|
|
304
|
-
|
|
305
|
-
const dirPath = process.env.DATA_SOURCE_DIR ||
|
|
304
|
+
serverLogics.clear();
|
|
305
|
+
const dirPath = process.env.SERVER_LOGIC_DIR || process.env.DATA_SOURCE_DIR || defaultServerLogicDir;
|
|
306
306
|
currentDirPath = dirPath;
|
|
307
307
|
await mkdir(dirPath, { recursive: true });
|
|
308
308
|
const files = await readdir(dirPath);
|
|
@@ -311,7 +311,7 @@ async function initialize() {
|
|
|
311
311
|
jsonFiles.map(async (file) => {
|
|
312
312
|
const slug = file.replace(/\.json$/, "");
|
|
313
313
|
const raw = await readFile2(`${dirPath}/${file}`, "utf-8");
|
|
314
|
-
const parsed =
|
|
314
|
+
const parsed = anyJsonServerLogicSchema.safeParse(JSON.parse(raw));
|
|
315
315
|
if (!parsed.success) {
|
|
316
316
|
console.warn(`[registry] Skipping ${file}: ${parsed.error.message}`);
|
|
317
317
|
return;
|
|
@@ -319,7 +319,7 @@ async function initialize() {
|
|
|
319
319
|
const def = parsed.data;
|
|
320
320
|
if (def.type === "typescript") {
|
|
321
321
|
const absoluteHandlerPath = validateHandlerPath(dirPath, def.handlerPath);
|
|
322
|
-
const
|
|
322
|
+
const serverLogicDef = {
|
|
323
323
|
description: def.description,
|
|
324
324
|
parameters: def.parameters ?? [],
|
|
325
325
|
response: def.response,
|
|
@@ -330,11 +330,11 @@ async function initialize() {
|
|
|
330
330
|
_isTypescript: true,
|
|
331
331
|
_tsHandlerPath: absoluteHandlerPath
|
|
332
332
|
};
|
|
333
|
-
|
|
333
|
+
serverLogics.set(slug, serverLogicDef);
|
|
334
334
|
console.log(`[registry] registered (typescript): ${slug}`);
|
|
335
335
|
} else {
|
|
336
336
|
const sqlDef = def;
|
|
337
|
-
const
|
|
337
|
+
const serverLogicDef = {
|
|
338
338
|
description: sqlDef.description,
|
|
339
339
|
parameters: sqlDef.parameters ?? [],
|
|
340
340
|
response: sqlDef.response,
|
|
@@ -351,7 +351,7 @@ async function initialize() {
|
|
|
351
351
|
return result.rows;
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
|
-
|
|
354
|
+
serverLogics.set(slug, serverLogicDef);
|
|
355
355
|
console.log(`[registry] registered: ${slug}`);
|
|
356
356
|
}
|
|
357
357
|
})
|
|
@@ -364,29 +364,29 @@ async function initialize() {
|
|
|
364
364
|
);
|
|
365
365
|
}
|
|
366
366
|
});
|
|
367
|
-
console.log(`[registry] ${
|
|
367
|
+
console.log(`[registry] ${serverLogics.size} server logic(s) ready`);
|
|
368
368
|
}
|
|
369
369
|
var reloadTimer = null;
|
|
370
370
|
function startWatching() {
|
|
371
|
-
const dirPath = process.env.DATA_SOURCE_DIR ||
|
|
371
|
+
const dirPath = process.env.SERVER_LOGIC_DIR || process.env.DATA_SOURCE_DIR || defaultServerLogicDir;
|
|
372
372
|
try {
|
|
373
373
|
fsWatch2(dirPath, { persistent: false }, (_event, filename) => {
|
|
374
374
|
if (!filename?.endsWith(".json") && !filename?.endsWith(".ts")) return;
|
|
375
375
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
376
376
|
reloadTimer = setTimeout(async () => {
|
|
377
|
-
console.log("[registry]
|
|
377
|
+
console.log("[registry] server-logic changed, reloading...");
|
|
378
378
|
await initialize();
|
|
379
379
|
}, 300);
|
|
380
380
|
});
|
|
381
|
-
console.log("[registry] watching
|
|
381
|
+
console.log("[registry] watching server-logic directory");
|
|
382
382
|
} catch {
|
|
383
383
|
console.warn(
|
|
384
|
-
"[registry] could not watch
|
|
384
|
+
"[registry] could not watch server-logic directory (static load only)"
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
-
function
|
|
389
|
-
return
|
|
388
|
+
function getServerLogic(slug) {
|
|
389
|
+
return serverLogics.get(slug);
|
|
390
390
|
}
|
|
391
391
|
function buildMeta(slug, def) {
|
|
392
392
|
const base = {
|
|
@@ -411,17 +411,17 @@ function buildMeta(slug, def) {
|
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
413
|
function getAllMeta() {
|
|
414
|
-
return Array.from(
|
|
414
|
+
return Array.from(serverLogics.entries()).map(
|
|
415
415
|
([slug, def]) => buildMeta(slug, def)
|
|
416
416
|
);
|
|
417
417
|
}
|
|
418
418
|
function getMeta(slug) {
|
|
419
|
-
const def =
|
|
419
|
+
const def = serverLogics.get(slug);
|
|
420
420
|
if (!def) return void 0;
|
|
421
421
|
return buildMeta(slug, def);
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
// src/routes/
|
|
424
|
+
// src/routes/server-logic.ts
|
|
425
425
|
import { Hono } from "hono";
|
|
426
426
|
|
|
427
427
|
// src/cache.ts
|
|
@@ -514,7 +514,7 @@ function buildCacheKey(slug, params) {
|
|
|
514
514
|
return `${slug}:${JSON.stringify(sortedParams)}`;
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
-
// src/routes/
|
|
517
|
+
// src/routes/server-logic.ts
|
|
518
518
|
var app = new Hono();
|
|
519
519
|
function buildSqlResponse(c, result) {
|
|
520
520
|
return c.json({ data: result });
|
|
@@ -524,9 +524,9 @@ function buildTypescriptResponse(result) {
|
|
|
524
524
|
}
|
|
525
525
|
app.get("/:slug", async (c) => {
|
|
526
526
|
const slug = c.req.param("slug");
|
|
527
|
-
const ds =
|
|
527
|
+
const ds = getServerLogic(slug);
|
|
528
528
|
if (!ds) {
|
|
529
|
-
return c.json({ error: `
|
|
529
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
530
530
|
}
|
|
531
531
|
try {
|
|
532
532
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
@@ -538,7 +538,7 @@ app.get("/:slug", async (c) => {
|
|
|
538
538
|
return buildSqlResponse(c, result);
|
|
539
539
|
}
|
|
540
540
|
} catch (e) {
|
|
541
|
-
console.error(`[
|
|
541
|
+
console.error(`[server-logic] ${slug} error:`, e);
|
|
542
542
|
return c.json(
|
|
543
543
|
{ error: e instanceof Error ? e.message : "Internal error" },
|
|
544
544
|
500
|
|
@@ -547,9 +547,9 @@ app.get("/:slug", async (c) => {
|
|
|
547
547
|
});
|
|
548
548
|
app.post("/:slug", async (c) => {
|
|
549
549
|
const slug = c.req.param("slug");
|
|
550
|
-
const ds =
|
|
550
|
+
const ds = getServerLogic(slug);
|
|
551
551
|
if (!ds) {
|
|
552
|
-
return c.json({ error: `
|
|
552
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
553
553
|
}
|
|
554
554
|
try {
|
|
555
555
|
const body = await c.req.json().catch(() => ({}));
|
|
@@ -615,16 +615,16 @@ app.post("/:slug", async (c) => {
|
|
|
615
615
|
c.header("Cache-Control", `max-age=${ttl}`);
|
|
616
616
|
return buildResponse(result);
|
|
617
617
|
} catch (e) {
|
|
618
|
-
console.error(`[
|
|
618
|
+
console.error(`[server-logic] ${slug} error:`, e);
|
|
619
619
|
return c.json(
|
|
620
620
|
{ error: e instanceof Error ? e.message : "Internal error" },
|
|
621
621
|
500
|
|
622
622
|
);
|
|
623
623
|
}
|
|
624
624
|
});
|
|
625
|
-
var
|
|
625
|
+
var server_logic_default = app;
|
|
626
626
|
|
|
627
|
-
// src/routes/
|
|
627
|
+
// src/routes/server-logic-meta.ts
|
|
628
628
|
import { Hono as Hono2 } from "hono";
|
|
629
629
|
var app2 = new Hono2();
|
|
630
630
|
app2.get("/", (c) => {
|
|
@@ -634,11 +634,11 @@ app2.get("/:slug", (c) => {
|
|
|
634
634
|
const slug = c.req.param("slug");
|
|
635
635
|
const meta = getMeta(slug);
|
|
636
636
|
if (!meta) {
|
|
637
|
-
return c.json({ error: `
|
|
637
|
+
return c.json({ error: `Server logic '${slug}' not found` }, 404);
|
|
638
638
|
}
|
|
639
639
|
return c.json(meta);
|
|
640
640
|
});
|
|
641
|
-
var
|
|
641
|
+
var server_logic_meta_default = app2;
|
|
642
642
|
|
|
643
643
|
// src/routes/cache.ts
|
|
644
644
|
import { Hono as Hono3 } from "hono";
|
|
@@ -733,8 +733,8 @@ import { getCookie as getCookie2 } from "hono/cookie";
|
|
|
733
733
|
var apiApp = new Hono5();
|
|
734
734
|
apiApp.use("/*", contextStorage());
|
|
735
735
|
apiApp.use("/*", cors());
|
|
736
|
-
apiApp.route("/
|
|
737
|
-
apiApp.route("/
|
|
736
|
+
apiApp.route("/server-logic", server_logic_default);
|
|
737
|
+
apiApp.route("/server-logic-meta", server_logic_meta_default);
|
|
738
738
|
apiApp.route("/cache", cache_default);
|
|
739
739
|
apiApp.route("/", pages_default);
|
|
740
740
|
reloadEnvFile(path4.join(process.cwd(), ".env"));
|
|
@@ -12,42 +12,42 @@ declare const parameterMetaSchema: z.ZodObject<{
|
|
|
12
12
|
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
13
13
|
}, z.core.$strip>;
|
|
14
14
|
type ParameterMeta = z.infer<typeof parameterMetaSchema>;
|
|
15
|
-
declare const
|
|
15
|
+
declare const serverLogicCacheConfigSchema: z.ZodObject<{
|
|
16
16
|
ttl: z.ZodNumber;
|
|
17
17
|
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
18
18
|
}, z.core.$strip>;
|
|
19
|
-
type
|
|
20
|
-
declare const
|
|
21
|
-
interface
|
|
19
|
+
type ServerLogicCacheConfig = z.infer<typeof serverLogicCacheConfigSchema>;
|
|
20
|
+
declare const serverLogicSchemaObjectSchema: z.ZodType<ServerLogicSchemaObject>;
|
|
21
|
+
interface ServerLogicSchemaObject {
|
|
22
22
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
23
23
|
format?: string;
|
|
24
24
|
description?: string;
|
|
25
25
|
nullable?: boolean;
|
|
26
26
|
enum?: (string | number | boolean | null)[];
|
|
27
|
-
items?:
|
|
28
|
-
properties?: Record<string,
|
|
27
|
+
items?: ServerLogicSchemaObject;
|
|
28
|
+
properties?: Record<string, ServerLogicSchemaObject>;
|
|
29
29
|
required?: string[];
|
|
30
|
-
additionalProperties?: boolean |
|
|
30
|
+
additionalProperties?: boolean | ServerLogicSchemaObject;
|
|
31
31
|
minimum?: number;
|
|
32
32
|
maximum?: number;
|
|
33
33
|
minLength?: number;
|
|
34
34
|
maxLength?: number;
|
|
35
35
|
pattern?: string;
|
|
36
36
|
}
|
|
37
|
-
declare const
|
|
38
|
-
schema: z.ZodOptional<z.ZodType<
|
|
37
|
+
declare const serverLogicMediaTypeSchema: z.ZodObject<{
|
|
38
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
39
39
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
40
40
|
}, z.core.$strip>;
|
|
41
|
-
type
|
|
42
|
-
declare const
|
|
41
|
+
type ServerLogicMediaType = z.infer<typeof serverLogicMediaTypeSchema>;
|
|
42
|
+
declare const serverLogicResponseSchema: z.ZodObject<{
|
|
43
43
|
description: z.ZodOptional<z.ZodString>;
|
|
44
44
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
45
|
-
schema: z.ZodOptional<z.ZodType<
|
|
45
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
46
46
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
47
47
|
}, z.core.$strip>>>;
|
|
48
48
|
}, z.core.$strip>;
|
|
49
|
-
type
|
|
50
|
-
declare const
|
|
49
|
+
type ServerLogicResponse = z.infer<typeof serverLogicResponseSchema>;
|
|
50
|
+
declare const jsonSqlServerLogicSchema: z.ZodObject<{
|
|
51
51
|
type: z.ZodOptional<z.ZodLiteral<"sql">>;
|
|
52
52
|
query: z.ZodString;
|
|
53
53
|
connectionId: z.ZodString;
|
|
@@ -66,7 +66,7 @@ declare const jsonSqlDataSourceSchema: z.ZodObject<{
|
|
|
66
66
|
response: z.ZodOptional<z.ZodObject<{
|
|
67
67
|
description: z.ZodOptional<z.ZodString>;
|
|
68
68
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
69
|
-
schema: z.ZodOptional<z.ZodType<
|
|
69
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
70
70
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
71
71
|
}, z.core.$strip>>>;
|
|
72
72
|
}, z.core.$strip>>;
|
|
@@ -75,8 +75,8 @@ declare const jsonSqlDataSourceSchema: z.ZodObject<{
|
|
|
75
75
|
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
76
76
|
}, z.core.$strip>>;
|
|
77
77
|
}, z.core.$strip>;
|
|
78
|
-
type
|
|
79
|
-
declare const
|
|
78
|
+
type JsonSqlServerLogicDefinition = z.infer<typeof jsonSqlServerLogicSchema>;
|
|
79
|
+
declare const jsonTypeScriptServerLogicSchema: z.ZodObject<{
|
|
80
80
|
type: z.ZodLiteral<"typescript">;
|
|
81
81
|
handlerPath: z.ZodString;
|
|
82
82
|
description: z.ZodString;
|
|
@@ -94,7 +94,7 @@ declare const jsonTypeScriptDataSourceSchema: z.ZodObject<{
|
|
|
94
94
|
response: z.ZodOptional<z.ZodObject<{
|
|
95
95
|
description: z.ZodOptional<z.ZodString>;
|
|
96
96
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
97
|
-
schema: z.ZodOptional<z.ZodType<
|
|
97
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
98
98
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
99
99
|
}, z.core.$strip>>>;
|
|
100
100
|
}, z.core.$strip>>;
|
|
@@ -103,8 +103,8 @@ declare const jsonTypeScriptDataSourceSchema: z.ZodObject<{
|
|
|
103
103
|
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
104
104
|
}, z.core.$strip>>;
|
|
105
105
|
}, z.core.$strip>;
|
|
106
|
-
type
|
|
107
|
-
declare const
|
|
106
|
+
type JsonTypeScriptServerLogicDefinition = z.infer<typeof jsonTypeScriptServerLogicSchema>;
|
|
107
|
+
declare const anyJsonServerLogicSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
108
108
|
type: z.ZodLiteral<"typescript">;
|
|
109
109
|
handlerPath: z.ZodString;
|
|
110
110
|
description: z.ZodString;
|
|
@@ -122,7 +122,7 @@ declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
122
122
|
response: z.ZodOptional<z.ZodObject<{
|
|
123
123
|
description: z.ZodOptional<z.ZodString>;
|
|
124
124
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
125
|
-
schema: z.ZodOptional<z.ZodType<
|
|
125
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
126
126
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
127
127
|
}, z.core.$strip>>>;
|
|
128
128
|
}, z.core.$strip>>;
|
|
@@ -149,7 +149,7 @@ declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
149
149
|
response: z.ZodOptional<z.ZodObject<{
|
|
150
150
|
description: z.ZodOptional<z.ZodString>;
|
|
151
151
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
152
|
-
schema: z.ZodOptional<z.ZodType<
|
|
152
|
+
schema: z.ZodOptional<z.ZodType<ServerLogicSchemaObject, unknown, z.core.$ZodTypeInternals<ServerLogicSchemaObject, unknown>>>;
|
|
153
153
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
154
154
|
}, z.core.$strip>>>;
|
|
155
155
|
}, z.core.$strip>>;
|
|
@@ -158,48 +158,48 @@ declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
158
158
|
staleWhileRevalidate: z.ZodOptional<z.ZodBoolean>;
|
|
159
159
|
}, z.core.$strip>>;
|
|
160
160
|
}, z.core.$strip>]>;
|
|
161
|
-
type
|
|
162
|
-
interface
|
|
161
|
+
type AnyJsonServerLogicDefinition = z.infer<typeof anyJsonServerLogicSchema>;
|
|
162
|
+
interface BaseServerLogicDefinition {
|
|
163
163
|
description: string;
|
|
164
164
|
parameters: ParameterMeta[];
|
|
165
|
-
response?:
|
|
166
|
-
cacheConfig?:
|
|
165
|
+
response?: ServerLogicResponse;
|
|
166
|
+
cacheConfig?: ServerLogicCacheConfig;
|
|
167
167
|
handler: (params: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
168
168
|
}
|
|
169
|
-
interface
|
|
169
|
+
interface SqlServerLogicDefinition extends BaseServerLogicDefinition {
|
|
170
170
|
connectionId: string;
|
|
171
171
|
_query: string;
|
|
172
172
|
_isTypescript?: false;
|
|
173
173
|
_tsHandlerPath?: undefined;
|
|
174
174
|
}
|
|
175
|
-
interface
|
|
175
|
+
interface TypeScriptServerLogicDefinition extends BaseServerLogicDefinition {
|
|
176
176
|
_isTypescript: true;
|
|
177
177
|
_tsHandlerPath: string;
|
|
178
178
|
connectionId?: undefined;
|
|
179
179
|
_query?: undefined;
|
|
180
180
|
}
|
|
181
|
-
type
|
|
182
|
-
interface
|
|
181
|
+
type ServerLogicDefinition = SqlServerLogicDefinition | TypeScriptServerLogicDefinition;
|
|
182
|
+
interface BaseServerLogicMeta {
|
|
183
183
|
slug: string;
|
|
184
184
|
description: string;
|
|
185
185
|
parameters: ParameterMeta[];
|
|
186
|
-
response?:
|
|
187
|
-
cache?:
|
|
186
|
+
response?: ServerLogicResponse;
|
|
187
|
+
cache?: ServerLogicCacheConfig;
|
|
188
188
|
}
|
|
189
|
-
interface
|
|
189
|
+
interface SqlServerLogicMeta extends BaseServerLogicMeta {
|
|
190
190
|
type: "sql";
|
|
191
191
|
connectionId: string;
|
|
192
192
|
query: string;
|
|
193
193
|
handlerPath?: undefined;
|
|
194
194
|
}
|
|
195
|
-
interface
|
|
195
|
+
interface TypeScriptServerLogicMeta extends BaseServerLogicMeta {
|
|
196
196
|
type: "typescript";
|
|
197
197
|
handlerPath: string;
|
|
198
198
|
connectionId?: undefined;
|
|
199
199
|
query?: undefined;
|
|
200
200
|
}
|
|
201
|
-
type
|
|
202
|
-
/** @deprecated Use
|
|
203
|
-
type
|
|
201
|
+
type ServerLogicMeta = SqlServerLogicMeta | TypeScriptServerLogicMeta;
|
|
202
|
+
/** @deprecated Use JsonSqlServerLogicDefinition */
|
|
203
|
+
type JsonServerLogicDefinition = JsonSqlServerLogicDefinition;
|
|
204
204
|
|
|
205
|
-
export { type
|
|
205
|
+
export { type AnyJsonServerLogicDefinition, type JsonServerLogicDefinition, type JsonSqlServerLogicDefinition, type JsonTypeScriptServerLogicDefinition, type ParameterMeta, type ServerLogicCacheConfig, type ServerLogicDefinition, type ServerLogicMediaType, type ServerLogicMeta, type ServerLogicResponse, type ServerLogicSchemaObject, type SqlServerLogicDefinition, type SqlServerLogicMeta, type TypeScriptServerLogicDefinition, type TypeScriptServerLogicMeta, anyJsonServerLogicSchema, jsonSqlServerLogicSchema, jsonTypeScriptServerLogicSchema, parameterMetaSchema, serverLogicCacheConfigSchema, serverLogicMediaTypeSchema, serverLogicResponseSchema, serverLogicSchemaObjectSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/types/
|
|
1
|
+
// src/types/server-logic.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
var parameterMetaSchema = z.object({
|
|
4
4
|
name: z.string(),
|
|
@@ -7,21 +7,21 @@ var parameterMetaSchema = z.object({
|
|
|
7
7
|
required: z.boolean().optional(),
|
|
8
8
|
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
9
9
|
});
|
|
10
|
-
var
|
|
10
|
+
var serverLogicCacheConfigSchema = z.object({
|
|
11
11
|
ttl: z.number(),
|
|
12
12
|
staleWhileRevalidate: z.boolean().optional()
|
|
13
13
|
});
|
|
14
|
-
var
|
|
14
|
+
var serverLogicSchemaObjectSchema = z.lazy(
|
|
15
15
|
() => z.object({
|
|
16
16
|
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
17
17
|
format: z.string().optional(),
|
|
18
18
|
description: z.string().optional(),
|
|
19
19
|
nullable: z.boolean().optional(),
|
|
20
20
|
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
21
|
-
items:
|
|
22
|
-
properties: z.record(z.string(),
|
|
21
|
+
items: serverLogicSchemaObjectSchema.optional(),
|
|
22
|
+
properties: z.record(z.string(), serverLogicSchemaObjectSchema).optional(),
|
|
23
23
|
required: z.array(z.string()).optional(),
|
|
24
|
-
additionalProperties: z.union([z.boolean(),
|
|
24
|
+
additionalProperties: z.union([z.boolean(), serverLogicSchemaObjectSchema]).optional(),
|
|
25
25
|
minimum: z.number().optional(),
|
|
26
26
|
maximum: z.number().optional(),
|
|
27
27
|
minLength: z.number().optional(),
|
|
@@ -29,42 +29,42 @@ var dataSourceSchemaObjectSchema = z.lazy(
|
|
|
29
29
|
pattern: z.string().optional()
|
|
30
30
|
})
|
|
31
31
|
);
|
|
32
|
-
var
|
|
33
|
-
schema:
|
|
32
|
+
var serverLogicMediaTypeSchema = z.object({
|
|
33
|
+
schema: serverLogicSchemaObjectSchema.optional(),
|
|
34
34
|
example: z.unknown().optional()
|
|
35
35
|
});
|
|
36
|
-
var
|
|
36
|
+
var serverLogicResponseSchema = z.object({
|
|
37
37
|
description: z.string().optional(),
|
|
38
|
-
content: z.record(z.string(),
|
|
38
|
+
content: z.record(z.string(), serverLogicMediaTypeSchema).optional()
|
|
39
39
|
});
|
|
40
40
|
var jsonBaseFields = {
|
|
41
41
|
description: z.string(),
|
|
42
42
|
parameters: z.array(parameterMetaSchema).optional(),
|
|
43
|
-
response:
|
|
44
|
-
cache:
|
|
43
|
+
response: serverLogicResponseSchema.optional(),
|
|
44
|
+
cache: serverLogicCacheConfigSchema.optional()
|
|
45
45
|
};
|
|
46
|
-
var
|
|
46
|
+
var jsonSqlServerLogicSchema = z.object({
|
|
47
47
|
...jsonBaseFields,
|
|
48
48
|
type: z.literal("sql").optional(),
|
|
49
49
|
query: z.string(),
|
|
50
50
|
connectionId: z.string()
|
|
51
51
|
});
|
|
52
|
-
var
|
|
52
|
+
var jsonTypeScriptServerLogicSchema = z.object({
|
|
53
53
|
...jsonBaseFields,
|
|
54
54
|
type: z.literal("typescript"),
|
|
55
55
|
handlerPath: z.string()
|
|
56
56
|
});
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
var anyJsonServerLogicSchema = z.union([
|
|
58
|
+
jsonTypeScriptServerLogicSchema,
|
|
59
|
+
jsonSqlServerLogicSchema
|
|
60
60
|
]);
|
|
61
61
|
export {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
anyJsonServerLogicSchema,
|
|
63
|
+
jsonSqlServerLogicSchema,
|
|
64
|
+
jsonTypeScriptServerLogicSchema,
|
|
65
|
+
parameterMetaSchema,
|
|
66
|
+
serverLogicCacheConfigSchema,
|
|
67
|
+
serverLogicMediaTypeSchema,
|
|
68
|
+
serverLogicResponseSchema,
|
|
69
|
+
serverLogicSchemaObjectSchema
|
|
70
70
|
};
|
package/dist/vite-plugin.js
CHANGED
|
@@ -190,7 +190,7 @@ function resolveParams(entry, connectionId, plugin) {
|
|
|
190
190
|
// src/connector-client/index.ts
|
|
191
191
|
var { getQuery, loadConnections, reloadEnvFile, watchConnectionsFile } = createConnectorRegistry();
|
|
192
192
|
|
|
193
|
-
// src/types/
|
|
193
|
+
// src/types/server-logic.ts
|
|
194
194
|
import { z } from "zod";
|
|
195
195
|
var parameterMetaSchema = z.object({
|
|
196
196
|
name: z.string(),
|
|
@@ -199,21 +199,21 @@ var parameterMetaSchema = z.object({
|
|
|
199
199
|
required: z.boolean().optional(),
|
|
200
200
|
default: z.union([z.string(), z.number(), z.boolean()]).optional()
|
|
201
201
|
});
|
|
202
|
-
var
|
|
202
|
+
var serverLogicCacheConfigSchema = z.object({
|
|
203
203
|
ttl: z.number(),
|
|
204
204
|
staleWhileRevalidate: z.boolean().optional()
|
|
205
205
|
});
|
|
206
|
-
var
|
|
206
|
+
var serverLogicSchemaObjectSchema = z.lazy(
|
|
207
207
|
() => z.object({
|
|
208
208
|
type: z.enum(["string", "number", "integer", "boolean", "object", "array", "null"]).optional(),
|
|
209
209
|
format: z.string().optional(),
|
|
210
210
|
description: z.string().optional(),
|
|
211
211
|
nullable: z.boolean().optional(),
|
|
212
212
|
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
213
|
-
items:
|
|
214
|
-
properties: z.record(z.string(),
|
|
213
|
+
items: serverLogicSchemaObjectSchema.optional(),
|
|
214
|
+
properties: z.record(z.string(), serverLogicSchemaObjectSchema).optional(),
|
|
215
215
|
required: z.array(z.string()).optional(),
|
|
216
|
-
additionalProperties: z.union([z.boolean(),
|
|
216
|
+
additionalProperties: z.union([z.boolean(), serverLogicSchemaObjectSchema]).optional(),
|
|
217
217
|
minimum: z.number().optional(),
|
|
218
218
|
maximum: z.number().optional(),
|
|
219
219
|
minLength: z.number().optional(),
|
|
@@ -221,34 +221,34 @@ var dataSourceSchemaObjectSchema = z.lazy(
|
|
|
221
221
|
pattern: z.string().optional()
|
|
222
222
|
})
|
|
223
223
|
);
|
|
224
|
-
var
|
|
225
|
-
schema:
|
|
224
|
+
var serverLogicMediaTypeSchema = z.object({
|
|
225
|
+
schema: serverLogicSchemaObjectSchema.optional(),
|
|
226
226
|
example: z.unknown().optional()
|
|
227
227
|
});
|
|
228
|
-
var
|
|
228
|
+
var serverLogicResponseSchema = z.object({
|
|
229
229
|
description: z.string().optional(),
|
|
230
|
-
content: z.record(z.string(),
|
|
230
|
+
content: z.record(z.string(), serverLogicMediaTypeSchema).optional()
|
|
231
231
|
});
|
|
232
232
|
var jsonBaseFields = {
|
|
233
233
|
description: z.string(),
|
|
234
234
|
parameters: z.array(parameterMetaSchema).optional(),
|
|
235
|
-
response:
|
|
236
|
-
cache:
|
|
235
|
+
response: serverLogicResponseSchema.optional(),
|
|
236
|
+
cache: serverLogicCacheConfigSchema.optional()
|
|
237
237
|
};
|
|
238
|
-
var
|
|
238
|
+
var jsonSqlServerLogicSchema = z.object({
|
|
239
239
|
...jsonBaseFields,
|
|
240
240
|
type: z.literal("sql").optional(),
|
|
241
241
|
query: z.string(),
|
|
242
242
|
connectionId: z.string()
|
|
243
243
|
});
|
|
244
|
-
var
|
|
244
|
+
var jsonTypeScriptServerLogicSchema = z.object({
|
|
245
245
|
...jsonBaseFields,
|
|
246
246
|
type: z.literal("typescript"),
|
|
247
247
|
handlerPath: z.string()
|
|
248
248
|
});
|
|
249
|
-
var
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
var anyJsonServerLogicSchema = z.union([
|
|
250
|
+
jsonTypeScriptServerLogicSchema,
|
|
251
|
+
jsonSqlServerLogicSchema
|
|
252
252
|
]);
|
|
253
253
|
|
|
254
254
|
// src/registry.ts
|
|
@@ -256,7 +256,7 @@ var viteServer = null;
|
|
|
256
256
|
function setViteServer(server) {
|
|
257
257
|
viteServer = server;
|
|
258
258
|
}
|
|
259
|
-
var
|
|
259
|
+
var defaultServerLogicDir = path2.join(process.cwd(), "server-logic");
|
|
260
260
|
|
|
261
261
|
// src/vite-plugin.ts
|
|
262
262
|
var DEFAULT_EXCLUDE = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squadbase/vite-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"types": "./dist/main.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"./types": {
|
|
15
|
-
"import": "./dist/types/
|
|
16
|
-
"types": "./dist/types/
|
|
15
|
+
"import": "./dist/types/server-logic.js",
|
|
16
|
+
"types": "./dist/types/server-logic.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"./plugin": {
|
|
19
19
|
"import": "./dist/vite-plugin.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"bin": {
|
|
38
|
-
"squadbase-
|
|
38
|
+
"squadbase-sl-test": "./dist/cli/index.js"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"cli": "tsx src/cli/index.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build:cli": "tsup src/cli/index.ts --out-dir dist/cli --format esm --platform node --no-splitting --external pg --external snowflake-sdk --external @google-cloud/bigquery --external mysql2 --external @aws-sdk/client-athena --external @aws-sdk/client-redshift-data --external @databricks/sql --external @google-analytics/data --external @kintone/rest-api-client --external hono --external @clack/prompts"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@squadbase/connectors": "^0.0.
|
|
48
|
+
"@squadbase/connectors": "^0.0.16",
|
|
49
49
|
"@aws-sdk/client-athena": "^3.750.0",
|
|
50
50
|
"@aws-sdk/client-redshift-data": "^3.750.0",
|
|
51
51
|
"@databricks/sql": "^1.8.0",
|