@squadbase/vite-server 0.1.3-dev.8 → 0.1.3-dev.9

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.
Files changed (3) hide show
  1. package/dist/index.js +84 -47
  2. package/dist/main.js +84 -47
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39679,7 +39679,7 @@ __export(lib_exports, {
39679
39679
  FetchError: () => FetchError,
39680
39680
  Headers: () => Headers2,
39681
39681
  Request: () => Request2,
39682
- Response: () => Response,
39682
+ Response: () => Response2,
39683
39683
  default: () => lib_default
39684
39684
  });
39685
39685
  import Stream from "stream";
@@ -40205,7 +40205,7 @@ function fetch2(url, opts) {
40205
40205
  };
40206
40206
  const codings = headers.get("Content-Encoding");
40207
40207
  if (!request2.compress || request2.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
40208
- response = new Response(body, response_options);
40208
+ response = new Response2(body, response_options);
40209
40209
  resolve(response);
40210
40210
  return;
40211
40211
  }
@@ -40215,7 +40215,7 @@ function fetch2(url, opts) {
40215
40215
  };
40216
40216
  if (codings == "gzip" || codings == "x-gzip") {
40217
40217
  body = body.pipe(zlib.createGunzip(zlibOptions));
40218
- response = new Response(body, response_options);
40218
+ response = new Response2(body, response_options);
40219
40219
  resolve(response);
40220
40220
  return;
40221
40221
  }
@@ -40227,12 +40227,12 @@ function fetch2(url, opts) {
40227
40227
  } else {
40228
40228
  body = body.pipe(zlib.createInflateRaw());
40229
40229
  }
40230
- response = new Response(body, response_options);
40230
+ response = new Response2(body, response_options);
40231
40231
  resolve(response);
40232
40232
  });
40233
40233
  raw.on("end", function() {
40234
40234
  if (!response) {
40235
- response = new Response(body, response_options);
40235
+ response = new Response2(body, response_options);
40236
40236
  resolve(response);
40237
40237
  }
40238
40238
  });
@@ -40240,11 +40240,11 @@ function fetch2(url, opts) {
40240
40240
  }
40241
40241
  if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
40242
40242
  body = body.pipe(zlib.createBrotliDecompress());
40243
- response = new Response(body, response_options);
40243
+ response = new Response2(body, response_options);
40244
40244
  resolve(response);
40245
40245
  return;
40246
40246
  }
40247
- response = new Response(body, response_options);
40247
+ response = new Response2(body, response_options);
40248
40248
  resolve(response);
40249
40249
  });
40250
40250
  writeToStream(req, request2);
@@ -40277,7 +40277,7 @@ function destroyStream(stream, err) {
40277
40277
  stream.end();
40278
40278
  }
40279
40279
  }
40280
- var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
40280
+ var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response2, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
40281
40281
  var init_lib2 = __esm({
40282
40282
  "../../node_modules/node-fetch/lib/index.mjs"() {
40283
40283
  "use strict";
@@ -40720,7 +40720,7 @@ var init_lib2 = __esm({
40720
40720
  });
40721
40721
  INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
40722
40722
  STATUS_CODES = http.STATUS_CODES;
40723
- Response = class _Response {
40723
+ Response2 = class _Response {
40724
40724
  constructor() {
40725
40725
  let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
40726
40726
  let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
@@ -40778,8 +40778,8 @@ var init_lib2 = __esm({
40778
40778
  });
40779
40779
  }
40780
40780
  };
40781
- Body.mixIn(Response.prototype);
40782
- Object.defineProperties(Response.prototype, {
40781
+ Body.mixIn(Response2.prototype);
40782
+ Object.defineProperties(Response2.prototype, {
40783
40783
  url: { enumerable: true },
40784
40784
  status: { enumerable: true },
40785
40785
  ok: { enumerable: true },
@@ -40788,7 +40788,7 @@ var init_lib2 = __esm({
40788
40788
  headers: { enumerable: true },
40789
40789
  clone: { enumerable: true }
40790
40790
  });
40791
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
40791
+ Object.defineProperty(Response2.prototype, Symbol.toStringTag, {
40792
40792
  value: "Response",
40793
40793
  writable: false,
40794
40794
  enumerable: false,
@@ -86428,11 +86428,42 @@ function buildCacheKey(slug, params) {
86428
86428
 
86429
86429
  // src/routes/server-logic.ts
86430
86430
  var app = new Hono();
86431
- function buildSqlResponse(c6, result) {
86432
- return c6.json({ data: result });
86431
+ function buildSqlResponseFromRows(c6, rows) {
86432
+ return c6.json({ data: rows });
86433
86433
  }
86434
- function buildTypescriptResponse(result) {
86435
- return result;
86434
+ function buildTypescriptResponseFromJsonBody(jsonBody) {
86435
+ return Response.json(jsonBody);
86436
+ }
86437
+ function buildResponseFromCache(c6, data) {
86438
+ if (data.type === "sql") {
86439
+ return buildSqlResponseFromRows(c6, data.rows);
86440
+ }
86441
+ return buildTypescriptResponseFromJsonBody(data.jsonBody);
86442
+ }
86443
+ function isJsonContentType(response) {
86444
+ const header = response.headers.get("content-type") ?? "";
86445
+ const lower = header.toLowerCase();
86446
+ return lower.startsWith("application/json") || lower.includes("+json");
86447
+ }
86448
+ async function cacheTypescriptResponse(response) {
86449
+ if (response.status !== 200 || !isJsonContentType(response)) {
86450
+ return { cacheable: false, response };
86451
+ }
86452
+ const jsonBody = await response.json();
86453
+ return {
86454
+ cacheable: true,
86455
+ data: { type: "typescript", jsonBody },
86456
+ response: buildTypescriptResponseFromJsonBody(jsonBody)
86457
+ };
86458
+ }
86459
+ function withCacheHeaders(c6, status, ageSeconds, ttl) {
86460
+ c6.header("X-Cache", status);
86461
+ c6.header("X-Cache-Age", String(ageSeconds));
86462
+ if (status === "STALE") {
86463
+ c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
86464
+ } else {
86465
+ c6.header("Cache-Control", `max-age=${Math.max(0, ttl - ageSeconds)}`);
86466
+ }
86436
86467
  }
86437
86468
  app.get("/:slug", async (c6) => {
86438
86469
  const slug = c6.req.param("slug");
@@ -86444,10 +86475,10 @@ app.get("/:slug", async (c6) => {
86444
86475
  if (ds._isTypescript && ds._tsHandlerPath) {
86445
86476
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86446
86477
  const result = await handler(c6);
86447
- return buildTypescriptResponse(result);
86478
+ return result;
86448
86479
  } else {
86449
- const result = await ds.handler({});
86450
- return buildSqlResponse(c6, result);
86480
+ const rows = await ds.handler({});
86481
+ return buildSqlResponseFromRows(c6, rows);
86451
86482
  }
86452
86483
  } catch (e6) {
86453
86484
  console.error(`[server-logic] ${slug} error:`, e6);
@@ -86471,61 +86502,67 @@ app.post("/:slug", async (c6) => {
86471
86502
  if (ttl <= 0) {
86472
86503
  if (ds._isTypescript && ds._tsHandlerPath) {
86473
86504
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86474
- const result2 = await handler(c6);
86475
- return buildTypescriptResponse(result2);
86505
+ const result = await handler(c6);
86506
+ return result;
86476
86507
  } else {
86477
- const result2 = await ds.handler(params);
86478
- return buildSqlResponse(c6, result2);
86508
+ const rows2 = await ds.handler(params);
86509
+ return buildSqlResponseFromRows(c6, rows2);
86479
86510
  }
86480
86511
  }
86481
86512
  const cacheKey = buildCacheKey(slug, params);
86482
86513
  const cached = cacheGet(cacheKey);
86483
- const buildResponse = ds._isTypescript ? (r6) => buildTypescriptResponse(r6) : (r6) => buildSqlResponse(c6, r6);
86484
86514
  if (cached) {
86485
86515
  if (isFresh(cached)) {
86486
86516
  recordHit(cacheKey);
86487
86517
  const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
86488
- c6.header("X-Cache", "HIT");
86489
- c6.header("X-Cache-Age", String(ageSeconds));
86490
- c6.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
86491
- return buildResponse(cached.data);
86518
+ withCacheHeaders(c6, "HIT", ageSeconds, ttl);
86519
+ return buildResponseFromCache(c6, cached.data);
86492
86520
  }
86493
86521
  if (cacheConfig?.staleWhileRevalidate) {
86494
86522
  recordHit(cacheKey);
86495
86523
  const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
86496
- c6.header("X-Cache", "STALE");
86497
- c6.header("X-Cache-Age", String(ageSeconds));
86498
- c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
86524
+ withCacheHeaders(c6, "STALE", ageSeconds, ttl);
86499
86525
  void (async () => {
86500
86526
  try {
86501
- let freshData;
86502
86527
  if (ds._isTypescript && ds._tsHandlerPath) {
86503
86528
  const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
86504
- freshData = await tsHandler(c6);
86529
+ const freshResponse = await tsHandler(c6);
86530
+ const outcome = await cacheTypescriptResponse(freshResponse);
86531
+ if (outcome.cacheable) {
86532
+ cacheSet(cacheKey, outcome.data, ttl);
86533
+ console.log(`[cache] background revalidated: ${cacheKey}`);
86534
+ } else {
86535
+ console.log(
86536
+ `[cache] background revalidation skipped (non-cacheable response) for ${cacheKey}`
86537
+ );
86538
+ }
86505
86539
  } else {
86506
- freshData = await ds.handler(params);
86540
+ const rows2 = await ds.handler(params);
86541
+ cacheSet(cacheKey, { type: "sql", rows: rows2 }, ttl);
86542
+ console.log(`[cache] background revalidated: ${cacheKey}`);
86507
86543
  }
86508
- cacheSet(cacheKey, freshData, ttl);
86509
- console.log(`[cache] background revalidated: ${cacheKey}`);
86510
86544
  } catch (e6) {
86511
86545
  console.error(`[cache] background revalidation failed for ${slug}:`, e6);
86512
86546
  }
86513
86547
  })();
86514
- return buildResponse(cached.data);
86548
+ return buildResponseFromCache(c6, cached.data);
86515
86549
  }
86516
86550
  }
86517
- let result;
86518
86551
  if (ds._isTypescript && ds._tsHandlerPath) {
86519
86552
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86520
- result = await handler(c6);
86521
- } else {
86522
- result = await ds.handler(params);
86523
- }
86524
- cacheSet(cacheKey, result, ttl);
86525
- c6.header("X-Cache", "MISS");
86526
- c6.header("X-Cache-Age", "0");
86527
- c6.header("Cache-Control", `max-age=${ttl}`);
86528
- return buildResponse(result);
86553
+ const response = await handler(c6);
86554
+ const outcome = await cacheTypescriptResponse(response);
86555
+ if (outcome.cacheable) {
86556
+ cacheSet(cacheKey, outcome.data, ttl);
86557
+ withCacheHeaders(c6, "MISS", 0, ttl);
86558
+ return outcome.response;
86559
+ }
86560
+ return outcome.response;
86561
+ }
86562
+ const rows = await ds.handler(params);
86563
+ cacheSet(cacheKey, { type: "sql", rows }, ttl);
86564
+ withCacheHeaders(c6, "MISS", 0, ttl);
86565
+ return buildSqlResponseFromRows(c6, rows);
86529
86566
  } catch (e6) {
86530
86567
  console.error(`[server-logic] ${slug} error:`, e6);
86531
86568
  return c6.json(
package/dist/main.js CHANGED
@@ -39679,7 +39679,7 @@ __export(lib_exports, {
39679
39679
  FetchError: () => FetchError,
39680
39680
  Headers: () => Headers2,
39681
39681
  Request: () => Request2,
39682
- Response: () => Response,
39682
+ Response: () => Response2,
39683
39683
  default: () => lib_default
39684
39684
  });
39685
39685
  import Stream from "stream";
@@ -40205,7 +40205,7 @@ function fetch2(url, opts) {
40205
40205
  };
40206
40206
  const codings = headers.get("Content-Encoding");
40207
40207
  if (!request2.compress || request2.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
40208
- response = new Response(body, response_options);
40208
+ response = new Response2(body, response_options);
40209
40209
  resolve(response);
40210
40210
  return;
40211
40211
  }
@@ -40215,7 +40215,7 @@ function fetch2(url, opts) {
40215
40215
  };
40216
40216
  if (codings == "gzip" || codings == "x-gzip") {
40217
40217
  body = body.pipe(zlib.createGunzip(zlibOptions));
40218
- response = new Response(body, response_options);
40218
+ response = new Response2(body, response_options);
40219
40219
  resolve(response);
40220
40220
  return;
40221
40221
  }
@@ -40227,12 +40227,12 @@ function fetch2(url, opts) {
40227
40227
  } else {
40228
40228
  body = body.pipe(zlib.createInflateRaw());
40229
40229
  }
40230
- response = new Response(body, response_options);
40230
+ response = new Response2(body, response_options);
40231
40231
  resolve(response);
40232
40232
  });
40233
40233
  raw.on("end", function() {
40234
40234
  if (!response) {
40235
- response = new Response(body, response_options);
40235
+ response = new Response2(body, response_options);
40236
40236
  resolve(response);
40237
40237
  }
40238
40238
  });
@@ -40240,11 +40240,11 @@ function fetch2(url, opts) {
40240
40240
  }
40241
40241
  if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
40242
40242
  body = body.pipe(zlib.createBrotliDecompress());
40243
- response = new Response(body, response_options);
40243
+ response = new Response2(body, response_options);
40244
40244
  resolve(response);
40245
40245
  return;
40246
40246
  }
40247
- response = new Response(body, response_options);
40247
+ response = new Response2(body, response_options);
40248
40248
  resolve(response);
40249
40249
  });
40250
40250
  writeToStream(req, request2);
@@ -40277,7 +40277,7 @@ function destroyStream(stream, err) {
40277
40277
  stream.end();
40278
40278
  }
40279
40279
  }
40280
- var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
40280
+ var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response2, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
40281
40281
  var init_lib2 = __esm({
40282
40282
  "../../node_modules/node-fetch/lib/index.mjs"() {
40283
40283
  "use strict";
@@ -40720,7 +40720,7 @@ var init_lib2 = __esm({
40720
40720
  });
40721
40721
  INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
40722
40722
  STATUS_CODES = http.STATUS_CODES;
40723
- Response = class _Response {
40723
+ Response2 = class _Response {
40724
40724
  constructor() {
40725
40725
  let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
40726
40726
  let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
@@ -40778,8 +40778,8 @@ var init_lib2 = __esm({
40778
40778
  });
40779
40779
  }
40780
40780
  };
40781
- Body.mixIn(Response.prototype);
40782
- Object.defineProperties(Response.prototype, {
40781
+ Body.mixIn(Response2.prototype);
40782
+ Object.defineProperties(Response2.prototype, {
40783
40783
  url: { enumerable: true },
40784
40784
  status: { enumerable: true },
40785
40785
  ok: { enumerable: true },
@@ -40788,7 +40788,7 @@ var init_lib2 = __esm({
40788
40788
  headers: { enumerable: true },
40789
40789
  clone: { enumerable: true }
40790
40790
  });
40791
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
40791
+ Object.defineProperty(Response2.prototype, Symbol.toStringTag, {
40792
40792
  value: "Response",
40793
40793
  writable: false,
40794
40794
  enumerable: false,
@@ -86167,11 +86167,42 @@ function buildCacheKey(slug, params) {
86167
86167
 
86168
86168
  // src/routes/server-logic.ts
86169
86169
  var app = new Hono();
86170
- function buildSqlResponse(c6, result) {
86171
- return c6.json({ data: result });
86170
+ function buildSqlResponseFromRows(c6, rows) {
86171
+ return c6.json({ data: rows });
86172
86172
  }
86173
- function buildTypescriptResponse(result) {
86174
- return result;
86173
+ function buildTypescriptResponseFromJsonBody(jsonBody) {
86174
+ return Response.json(jsonBody);
86175
+ }
86176
+ function buildResponseFromCache(c6, data) {
86177
+ if (data.type === "sql") {
86178
+ return buildSqlResponseFromRows(c6, data.rows);
86179
+ }
86180
+ return buildTypescriptResponseFromJsonBody(data.jsonBody);
86181
+ }
86182
+ function isJsonContentType(response) {
86183
+ const header = response.headers.get("content-type") ?? "";
86184
+ const lower = header.toLowerCase();
86185
+ return lower.startsWith("application/json") || lower.includes("+json");
86186
+ }
86187
+ async function cacheTypescriptResponse(response) {
86188
+ if (response.status !== 200 || !isJsonContentType(response)) {
86189
+ return { cacheable: false, response };
86190
+ }
86191
+ const jsonBody = await response.json();
86192
+ return {
86193
+ cacheable: true,
86194
+ data: { type: "typescript", jsonBody },
86195
+ response: buildTypescriptResponseFromJsonBody(jsonBody)
86196
+ };
86197
+ }
86198
+ function withCacheHeaders(c6, status, ageSeconds, ttl) {
86199
+ c6.header("X-Cache", status);
86200
+ c6.header("X-Cache-Age", String(ageSeconds));
86201
+ if (status === "STALE") {
86202
+ c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
86203
+ } else {
86204
+ c6.header("Cache-Control", `max-age=${Math.max(0, ttl - ageSeconds)}`);
86205
+ }
86175
86206
  }
86176
86207
  app.get("/:slug", async (c6) => {
86177
86208
  const slug = c6.req.param("slug");
@@ -86183,10 +86214,10 @@ app.get("/:slug", async (c6) => {
86183
86214
  if (ds._isTypescript && ds._tsHandlerPath) {
86184
86215
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86185
86216
  const result = await handler(c6);
86186
- return buildTypescriptResponse(result);
86217
+ return result;
86187
86218
  } else {
86188
- const result = await ds.handler({});
86189
- return buildSqlResponse(c6, result);
86219
+ const rows = await ds.handler({});
86220
+ return buildSqlResponseFromRows(c6, rows);
86190
86221
  }
86191
86222
  } catch (e6) {
86192
86223
  console.error(`[server-logic] ${slug} error:`, e6);
@@ -86210,61 +86241,67 @@ app.post("/:slug", async (c6) => {
86210
86241
  if (ttl <= 0) {
86211
86242
  if (ds._isTypescript && ds._tsHandlerPath) {
86212
86243
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86213
- const result2 = await handler(c6);
86214
- return buildTypescriptResponse(result2);
86244
+ const result = await handler(c6);
86245
+ return result;
86215
86246
  } else {
86216
- const result2 = await ds.handler(params);
86217
- return buildSqlResponse(c6, result2);
86247
+ const rows2 = await ds.handler(params);
86248
+ return buildSqlResponseFromRows(c6, rows2);
86218
86249
  }
86219
86250
  }
86220
86251
  const cacheKey = buildCacheKey(slug, params);
86221
86252
  const cached = cacheGet(cacheKey);
86222
- const buildResponse = ds._isTypescript ? (r6) => buildTypescriptResponse(r6) : (r6) => buildSqlResponse(c6, r6);
86223
86253
  if (cached) {
86224
86254
  if (isFresh(cached)) {
86225
86255
  recordHit(cacheKey);
86226
86256
  const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
86227
- c6.header("X-Cache", "HIT");
86228
- c6.header("X-Cache-Age", String(ageSeconds));
86229
- c6.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
86230
- return buildResponse(cached.data);
86257
+ withCacheHeaders(c6, "HIT", ageSeconds, ttl);
86258
+ return buildResponseFromCache(c6, cached.data);
86231
86259
  }
86232
86260
  if (cacheConfig?.staleWhileRevalidate) {
86233
86261
  recordHit(cacheKey);
86234
86262
  const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
86235
- c6.header("X-Cache", "STALE");
86236
- c6.header("X-Cache-Age", String(ageSeconds));
86237
- c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
86263
+ withCacheHeaders(c6, "STALE", ageSeconds, ttl);
86238
86264
  void (async () => {
86239
86265
  try {
86240
- let freshData;
86241
86266
  if (ds._isTypescript && ds._tsHandlerPath) {
86242
86267
  const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
86243
- freshData = await tsHandler(c6);
86268
+ const freshResponse = await tsHandler(c6);
86269
+ const outcome = await cacheTypescriptResponse(freshResponse);
86270
+ if (outcome.cacheable) {
86271
+ cacheSet(cacheKey, outcome.data, ttl);
86272
+ console.log(`[cache] background revalidated: ${cacheKey}`);
86273
+ } else {
86274
+ console.log(
86275
+ `[cache] background revalidation skipped (non-cacheable response) for ${cacheKey}`
86276
+ );
86277
+ }
86244
86278
  } else {
86245
- freshData = await ds.handler(params);
86279
+ const rows2 = await ds.handler(params);
86280
+ cacheSet(cacheKey, { type: "sql", rows: rows2 }, ttl);
86281
+ console.log(`[cache] background revalidated: ${cacheKey}`);
86246
86282
  }
86247
- cacheSet(cacheKey, freshData, ttl);
86248
- console.log(`[cache] background revalidated: ${cacheKey}`);
86249
86283
  } catch (e6) {
86250
86284
  console.error(`[cache] background revalidation failed for ${slug}:`, e6);
86251
86285
  }
86252
86286
  })();
86253
- return buildResponse(cached.data);
86287
+ return buildResponseFromCache(c6, cached.data);
86254
86288
  }
86255
86289
  }
86256
- let result;
86257
86290
  if (ds._isTypescript && ds._tsHandlerPath) {
86258
86291
  const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
86259
- result = await handler(c6);
86260
- } else {
86261
- result = await ds.handler(params);
86262
- }
86263
- cacheSet(cacheKey, result, ttl);
86264
- c6.header("X-Cache", "MISS");
86265
- c6.header("X-Cache-Age", "0");
86266
- c6.header("Cache-Control", `max-age=${ttl}`);
86267
- return buildResponse(result);
86292
+ const response = await handler(c6);
86293
+ const outcome = await cacheTypescriptResponse(response);
86294
+ if (outcome.cacheable) {
86295
+ cacheSet(cacheKey, outcome.data, ttl);
86296
+ withCacheHeaders(c6, "MISS", 0, ttl);
86297
+ return outcome.response;
86298
+ }
86299
+ return outcome.response;
86300
+ }
86301
+ const rows = await ds.handler(params);
86302
+ cacheSet(cacheKey, { type: "sql", rows }, ttl);
86303
+ withCacheHeaders(c6, "MISS", 0, ttl);
86304
+ return buildSqlResponseFromRows(c6, rows);
86268
86305
  } catch (e6) {
86269
86306
  console.error(`[server-logic] ${slug} error:`, e6);
86270
86307
  return c6.json(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squadbase/vite-server",
3
- "version": "0.1.3-dev.8",
3
+ "version": "0.1.3-dev.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {