@squadbase/vite-server 0.0.1-build-24 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +0 -1
- package/dist/index.js +16 -36
- package/dist/main.js +16 -36
- package/dist/types/data-source.d.ts +0 -5
- package/dist/types/data-source.js +0 -1
- package/dist/vite-plugin.js +0 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -17199,7 +17199,6 @@ var dataSourceMediaTypeSchema = z16.object({
|
|
|
17199
17199
|
});
|
|
17200
17200
|
var dataSourceResponseSchema = z16.object({
|
|
17201
17201
|
description: z16.string().optional(),
|
|
17202
|
-
defaultContentType: z16.string().optional(),
|
|
17203
17202
|
content: z16.record(z16.string(), dataSourceMediaTypeSchema).optional()
|
|
17204
17203
|
});
|
|
17205
17204
|
var jsonBaseFields = {
|
package/dist/index.js
CHANGED
|
@@ -17380,7 +17380,6 @@ var dataSourceMediaTypeSchema = z16.object({
|
|
|
17380
17380
|
});
|
|
17381
17381
|
var dataSourceResponseSchema = z16.object({
|
|
17382
17382
|
description: z16.string().optional(),
|
|
17383
|
-
defaultContentType: z16.string().optional(),
|
|
17384
17383
|
content: z16.record(z16.string(), dataSourceMediaTypeSchema).optional()
|
|
17385
17384
|
});
|
|
17386
17385
|
var jsonBaseFields = {
|
|
@@ -17669,34 +17668,14 @@ function buildCacheKey(slug, params) {
|
|
|
17669
17668
|
return `${slug}:${JSON.stringify(sortedParams)}`;
|
|
17670
17669
|
}
|
|
17671
17670
|
|
|
17672
|
-
// src/lib/csv.ts
|
|
17673
|
-
function convertRowsToCsv(rows) {
|
|
17674
|
-
if (rows.length === 0) return "";
|
|
17675
|
-
const headers = Object.keys(rows[0]);
|
|
17676
|
-
const escape = (v) => {
|
|
17677
|
-
const s = v === null || v === void 0 ? "" : String(v);
|
|
17678
|
-
return s.includes(",") || s.includes('"') || s.includes("\n") ? `"${s.replace(/"/g, '""')}"` : s;
|
|
17679
|
-
};
|
|
17680
|
-
return [
|
|
17681
|
-
headers.join(","),
|
|
17682
|
-
...rows.map((r) => headers.map((h) => escape(r[h])).join(","))
|
|
17683
|
-
].join("\n");
|
|
17684
|
-
}
|
|
17685
|
-
|
|
17686
17671
|
// src/routes/data-source.ts
|
|
17687
17672
|
var app = new Hono();
|
|
17688
|
-
function
|
|
17689
|
-
const contentType = response?.defaultContentType ?? "application/json";
|
|
17690
|
-
if (contentType === "text/csv") {
|
|
17691
|
-
const csv = convertRowsToCsv(result);
|
|
17692
|
-
return c.text(csv, 200, { "Content-Type": "text/csv; charset=utf-8" });
|
|
17693
|
-
}
|
|
17694
|
-
const schema = response?.content?.["application/json"]?.schema;
|
|
17695
|
-
if (schema?.type === "object" && schema.properties) {
|
|
17696
|
-
return c.json(result);
|
|
17697
|
-
}
|
|
17673
|
+
function buildSqlResponse(c, result) {
|
|
17698
17674
|
return c.json({ data: result });
|
|
17699
17675
|
}
|
|
17676
|
+
function buildTypescriptResponse(result) {
|
|
17677
|
+
return result;
|
|
17678
|
+
}
|
|
17700
17679
|
app.get("/:slug", async (c) => {
|
|
17701
17680
|
const slug = c.req.param("slug");
|
|
17702
17681
|
const ds = getDataSource(slug);
|
|
@@ -17704,14 +17683,14 @@ app.get("/:slug", async (c) => {
|
|
|
17704
17683
|
return c.json({ error: `Data source '${slug}' not found` }, 404);
|
|
17705
17684
|
}
|
|
17706
17685
|
try {
|
|
17707
|
-
let result;
|
|
17708
17686
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
17709
17687
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
17710
|
-
result = await handler(c);
|
|
17688
|
+
const result = await handler(c);
|
|
17689
|
+
return buildTypescriptResponse(result);
|
|
17711
17690
|
} else {
|
|
17712
|
-
result =
|
|
17691
|
+
const result = await ds.handler({});
|
|
17692
|
+
return buildSqlResponse(c, result);
|
|
17713
17693
|
}
|
|
17714
|
-
return buildResponse(c, result, ds.response);
|
|
17715
17694
|
} catch (e) {
|
|
17716
17695
|
console.error(`[data-source] ${slug} error:`, e);
|
|
17717
17696
|
return c.json(
|
|
@@ -17732,17 +17711,18 @@ app.post("/:slug", async (c) => {
|
|
|
17732
17711
|
const cacheConfig = ds.cacheConfig;
|
|
17733
17712
|
const ttl = cacheConfig?.ttl ?? 0;
|
|
17734
17713
|
if (ttl <= 0) {
|
|
17735
|
-
let result2;
|
|
17736
17714
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
17737
17715
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
17738
|
-
result2 = await handler(c);
|
|
17716
|
+
const result2 = await handler(c);
|
|
17717
|
+
return buildTypescriptResponse(result2);
|
|
17739
17718
|
} else {
|
|
17740
|
-
result2 = await ds.handler(params);
|
|
17719
|
+
const result2 = await ds.handler(params);
|
|
17720
|
+
return buildSqlResponse(c, result2);
|
|
17741
17721
|
}
|
|
17742
|
-
return buildResponse(c, result2, ds.response);
|
|
17743
17722
|
}
|
|
17744
17723
|
const cacheKey = buildCacheKey(slug, params);
|
|
17745
17724
|
const cached = cacheGet(cacheKey);
|
|
17725
|
+
const buildResponse = ds._isTypescript ? (r) => buildTypescriptResponse(r) : (r) => buildSqlResponse(c, r);
|
|
17746
17726
|
if (cached) {
|
|
17747
17727
|
if (isFresh(cached)) {
|
|
17748
17728
|
recordHit(cacheKey);
|
|
@@ -17750,7 +17730,7 @@ app.post("/:slug", async (c) => {
|
|
|
17750
17730
|
c.header("X-Cache", "HIT");
|
|
17751
17731
|
c.header("X-Cache-Age", String(ageSeconds));
|
|
17752
17732
|
c.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
|
|
17753
|
-
return buildResponse(
|
|
17733
|
+
return buildResponse(cached.data);
|
|
17754
17734
|
}
|
|
17755
17735
|
if (cacheConfig?.staleWhileRevalidate) {
|
|
17756
17736
|
recordHit(cacheKey);
|
|
@@ -17773,7 +17753,7 @@ app.post("/:slug", async (c) => {
|
|
|
17773
17753
|
console.error(`[cache] background revalidation failed for ${slug}:`, e);
|
|
17774
17754
|
}
|
|
17775
17755
|
})();
|
|
17776
|
-
return buildResponse(
|
|
17756
|
+
return buildResponse(cached.data);
|
|
17777
17757
|
}
|
|
17778
17758
|
}
|
|
17779
17759
|
let result;
|
|
@@ -17787,7 +17767,7 @@ app.post("/:slug", async (c) => {
|
|
|
17787
17767
|
c.header("X-Cache", "MISS");
|
|
17788
17768
|
c.header("X-Cache-Age", "0");
|
|
17789
17769
|
c.header("Cache-Control", `max-age=${ttl}`);
|
|
17790
|
-
return buildResponse(
|
|
17770
|
+
return buildResponse(result);
|
|
17791
17771
|
} catch (e) {
|
|
17792
17772
|
console.error(`[data-source] ${slug} error:`, e);
|
|
17793
17773
|
return c.json(
|
package/dist/main.js
CHANGED
|
@@ -17118,7 +17118,6 @@ var dataSourceMediaTypeSchema = z16.object({
|
|
|
17118
17118
|
});
|
|
17119
17119
|
var dataSourceResponseSchema = z16.object({
|
|
17120
17120
|
description: z16.string().optional(),
|
|
17121
|
-
defaultContentType: z16.string().optional(),
|
|
17122
17121
|
content: z16.record(z16.string(), dataSourceMediaTypeSchema).optional()
|
|
17123
17122
|
});
|
|
17124
17123
|
var jsonBaseFields = {
|
|
@@ -17407,34 +17406,14 @@ function buildCacheKey(slug, params) {
|
|
|
17407
17406
|
return `${slug}:${JSON.stringify(sortedParams)}`;
|
|
17408
17407
|
}
|
|
17409
17408
|
|
|
17410
|
-
// src/lib/csv.ts
|
|
17411
|
-
function convertRowsToCsv(rows) {
|
|
17412
|
-
if (rows.length === 0) return "";
|
|
17413
|
-
const headers = Object.keys(rows[0]);
|
|
17414
|
-
const escape = (v) => {
|
|
17415
|
-
const s = v === null || v === void 0 ? "" : String(v);
|
|
17416
|
-
return s.includes(",") || s.includes('"') || s.includes("\n") ? `"${s.replace(/"/g, '""')}"` : s;
|
|
17417
|
-
};
|
|
17418
|
-
return [
|
|
17419
|
-
headers.join(","),
|
|
17420
|
-
...rows.map((r) => headers.map((h) => escape(r[h])).join(","))
|
|
17421
|
-
].join("\n");
|
|
17422
|
-
}
|
|
17423
|
-
|
|
17424
17409
|
// src/routes/data-source.ts
|
|
17425
17410
|
var app = new Hono();
|
|
17426
|
-
function
|
|
17427
|
-
const contentType = response?.defaultContentType ?? "application/json";
|
|
17428
|
-
if (contentType === "text/csv") {
|
|
17429
|
-
const csv = convertRowsToCsv(result);
|
|
17430
|
-
return c.text(csv, 200, { "Content-Type": "text/csv; charset=utf-8" });
|
|
17431
|
-
}
|
|
17432
|
-
const schema = response?.content?.["application/json"]?.schema;
|
|
17433
|
-
if (schema?.type === "object" && schema.properties) {
|
|
17434
|
-
return c.json(result);
|
|
17435
|
-
}
|
|
17411
|
+
function buildSqlResponse(c, result) {
|
|
17436
17412
|
return c.json({ data: result });
|
|
17437
17413
|
}
|
|
17414
|
+
function buildTypescriptResponse(result) {
|
|
17415
|
+
return result;
|
|
17416
|
+
}
|
|
17438
17417
|
app.get("/:slug", async (c) => {
|
|
17439
17418
|
const slug = c.req.param("slug");
|
|
17440
17419
|
const ds = getDataSource(slug);
|
|
@@ -17442,14 +17421,14 @@ app.get("/:slug", async (c) => {
|
|
|
17442
17421
|
return c.json({ error: `Data source '${slug}' not found` }, 404);
|
|
17443
17422
|
}
|
|
17444
17423
|
try {
|
|
17445
|
-
let result;
|
|
17446
17424
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
17447
17425
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
17448
|
-
result = await handler(c);
|
|
17426
|
+
const result = await handler(c);
|
|
17427
|
+
return buildTypescriptResponse(result);
|
|
17449
17428
|
} else {
|
|
17450
|
-
result =
|
|
17429
|
+
const result = await ds.handler({});
|
|
17430
|
+
return buildSqlResponse(c, result);
|
|
17451
17431
|
}
|
|
17452
|
-
return buildResponse(c, result, ds.response);
|
|
17453
17432
|
} catch (e) {
|
|
17454
17433
|
console.error(`[data-source] ${slug} error:`, e);
|
|
17455
17434
|
return c.json(
|
|
@@ -17470,17 +17449,18 @@ app.post("/:slug", async (c) => {
|
|
|
17470
17449
|
const cacheConfig = ds.cacheConfig;
|
|
17471
17450
|
const ttl = cacheConfig?.ttl ?? 0;
|
|
17472
17451
|
if (ttl <= 0) {
|
|
17473
|
-
let result2;
|
|
17474
17452
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
17475
17453
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
17476
|
-
result2 = await handler(c);
|
|
17454
|
+
const result2 = await handler(c);
|
|
17455
|
+
return buildTypescriptResponse(result2);
|
|
17477
17456
|
} else {
|
|
17478
|
-
result2 = await ds.handler(params);
|
|
17457
|
+
const result2 = await ds.handler(params);
|
|
17458
|
+
return buildSqlResponse(c, result2);
|
|
17479
17459
|
}
|
|
17480
|
-
return buildResponse(c, result2, ds.response);
|
|
17481
17460
|
}
|
|
17482
17461
|
const cacheKey = buildCacheKey(slug, params);
|
|
17483
17462
|
const cached = cacheGet(cacheKey);
|
|
17463
|
+
const buildResponse = ds._isTypescript ? (r) => buildTypescriptResponse(r) : (r) => buildSqlResponse(c, r);
|
|
17484
17464
|
if (cached) {
|
|
17485
17465
|
if (isFresh(cached)) {
|
|
17486
17466
|
recordHit(cacheKey);
|
|
@@ -17488,7 +17468,7 @@ app.post("/:slug", async (c) => {
|
|
|
17488
17468
|
c.header("X-Cache", "HIT");
|
|
17489
17469
|
c.header("X-Cache-Age", String(ageSeconds));
|
|
17490
17470
|
c.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
|
|
17491
|
-
return buildResponse(
|
|
17471
|
+
return buildResponse(cached.data);
|
|
17492
17472
|
}
|
|
17493
17473
|
if (cacheConfig?.staleWhileRevalidate) {
|
|
17494
17474
|
recordHit(cacheKey);
|
|
@@ -17511,7 +17491,7 @@ app.post("/:slug", async (c) => {
|
|
|
17511
17491
|
console.error(`[cache] background revalidation failed for ${slug}:`, e);
|
|
17512
17492
|
}
|
|
17513
17493
|
})();
|
|
17514
|
-
return buildResponse(
|
|
17494
|
+
return buildResponse(cached.data);
|
|
17515
17495
|
}
|
|
17516
17496
|
}
|
|
17517
17497
|
let result;
|
|
@@ -17525,7 +17505,7 @@ app.post("/:slug", async (c) => {
|
|
|
17525
17505
|
c.header("X-Cache", "MISS");
|
|
17526
17506
|
c.header("X-Cache-Age", "0");
|
|
17527
17507
|
c.header("Cache-Control", `max-age=${ttl}`);
|
|
17528
|
-
return buildResponse(
|
|
17508
|
+
return buildResponse(result);
|
|
17529
17509
|
} catch (e) {
|
|
17530
17510
|
console.error(`[data-source] ${slug} error:`, e);
|
|
17531
17511
|
return c.json(
|
|
@@ -41,7 +41,6 @@ declare const dataSourceMediaTypeSchema: z.ZodObject<{
|
|
|
41
41
|
type DataSourceMediaType = z.infer<typeof dataSourceMediaTypeSchema>;
|
|
42
42
|
declare const dataSourceResponseSchema: z.ZodObject<{
|
|
43
43
|
description: z.ZodOptional<z.ZodString>;
|
|
44
|
-
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
45
44
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
46
45
|
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
47
46
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -66,7 +65,6 @@ declare const jsonSqlDataSourceSchema: z.ZodObject<{
|
|
|
66
65
|
}, z.core.$strip>>>;
|
|
67
66
|
response: z.ZodOptional<z.ZodObject<{
|
|
68
67
|
description: z.ZodOptional<z.ZodString>;
|
|
69
|
-
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
70
68
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
71
69
|
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
72
70
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -95,7 +93,6 @@ declare const jsonTypeScriptDataSourceSchema: z.ZodObject<{
|
|
|
95
93
|
}, z.core.$strip>>>;
|
|
96
94
|
response: z.ZodOptional<z.ZodObject<{
|
|
97
95
|
description: z.ZodOptional<z.ZodString>;
|
|
98
|
-
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
99
96
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
100
97
|
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
101
98
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -124,7 +121,6 @@ declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
124
121
|
}, z.core.$strip>>>;
|
|
125
122
|
response: z.ZodOptional<z.ZodObject<{
|
|
126
123
|
description: z.ZodOptional<z.ZodString>;
|
|
127
|
-
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
128
124
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
129
125
|
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
130
126
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -152,7 +148,6 @@ declare const anyJsonDataSourceSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
152
148
|
}, z.core.$strip>>>;
|
|
153
149
|
response: z.ZodOptional<z.ZodObject<{
|
|
154
150
|
description: z.ZodOptional<z.ZodString>;
|
|
155
|
-
defaultContentType: z.ZodOptional<z.ZodString>;
|
|
156
151
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
157
152
|
schema: z.ZodOptional<z.ZodType<DataSourceSchemaObject, unknown, z.core.$ZodTypeInternals<DataSourceSchemaObject, unknown>>>;
|
|
158
153
|
example: z.ZodOptional<z.ZodUnknown>;
|
|
@@ -35,7 +35,6 @@ var dataSourceMediaTypeSchema = z.object({
|
|
|
35
35
|
});
|
|
36
36
|
var dataSourceResponseSchema = z.object({
|
|
37
37
|
description: z.string().optional(),
|
|
38
|
-
defaultContentType: z.string().optional(),
|
|
39
38
|
content: z.record(z.string(), dataSourceMediaTypeSchema).optional()
|
|
40
39
|
});
|
|
41
40
|
var jsonBaseFields = {
|
package/dist/vite-plugin.js
CHANGED
|
@@ -17119,7 +17119,6 @@ var dataSourceMediaTypeSchema = z16.object({
|
|
|
17119
17119
|
});
|
|
17120
17120
|
var dataSourceResponseSchema = z16.object({
|
|
17121
17121
|
description: z16.string().optional(),
|
|
17122
|
-
defaultContentType: z16.string().optional(),
|
|
17123
17122
|
content: z16.record(z16.string(), dataSourceMediaTypeSchema).optional()
|
|
17124
17123
|
});
|
|
17125
17124
|
var jsonBaseFields = {
|