@teyik0/furin 0.1.0-alpha.14 → 0.1.0-alpha.15

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.
@@ -0,0 +1,4 @@
1
+ export { furinInvalidate } from "./plugin.ts";
2
+ export { AutoInvalidateRegistry, autoInvalidateRegistry } from "./registry.ts";
3
+ export { appendPendingInvalidationHeader, isSuccessfulMutationResponse, revalidateTag, runInvalidationRules, } from "./runtime.ts";
4
+ export type { InvalidationInput, InvalidationRule } from "./types.ts";
@@ -0,0 +1,38 @@
1
+ import { type AfterHandler, Elysia } from "elysia";
2
+ import type { InvalidationInput } from "./types.ts";
3
+ type AnyAfterHandleContext = Parameters<AfterHandler>[0];
4
+ export declare function furinInvalidate(): Elysia<"", {
5
+ decorator: {};
6
+ store: {};
7
+ derive: {};
8
+ resolve: {};
9
+ }, {
10
+ typebox: {};
11
+ error: {};
12
+ }, {
13
+ schema: {};
14
+ standaloneSchema: {};
15
+ macro: Partial<{
16
+ readonly invalidate: InvalidationInput;
17
+ }>;
18
+ macroFn: {
19
+ readonly invalidate: (rules: InvalidationInput) => {
20
+ readonly afterHandle: (ctx: AnyAfterHandleContext) => void;
21
+ };
22
+ };
23
+ parser: {};
24
+ response: {};
25
+ }, {}, {
26
+ derive: {};
27
+ resolve: {};
28
+ schema: {};
29
+ standaloneSchema: {};
30
+ response: {};
31
+ }, {
32
+ derive: {};
33
+ resolve: {};
34
+ schema: {};
35
+ standaloneSchema: {};
36
+ response: {};
37
+ }>;
38
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class AutoInvalidateRegistry {
2
+ private readonly pathToTags;
3
+ private readonly tagToPaths;
4
+ registerLoaderTags(urlPath: string, tags: readonly string[] | undefined): void;
5
+ pathsForTags(tags: readonly string[]): string[];
6
+ unregisterPath(urlPath: string): void;
7
+ reset(): void;
8
+ }
9
+ export declare const autoInvalidateRegistry: AutoInvalidateRegistry;
@@ -0,0 +1,9 @@
1
+ import type { Context } from "elysia";
2
+ import type { InvalidationInput } from "./types.ts";
3
+ export declare function isSuccessfulMutationResponse(ctx: Pick<Context, "set"> & {
4
+ responseValue?: unknown;
5
+ response?: unknown;
6
+ }): boolean;
7
+ export declare function appendPendingInvalidationHeader(set: Context["set"]): void;
8
+ export declare function revalidateTag(tags: string | readonly string[]): boolean;
9
+ export declare function runInvalidationRules(input: InvalidationInput): boolean;
@@ -0,0 +1,12 @@
1
+ import type { CacheTag } from "../furin.ts";
2
+ import type { RevalidateType } from "../render/route-cache.ts";
3
+ export type InvalidationRule = {
4
+ path: string;
5
+ tags?: readonly CacheTag[];
6
+ type: RevalidateType;
7
+ } | {
8
+ path?: never;
9
+ tags: readonly CacheTag[];
10
+ type?: never;
11
+ };
12
+ export type InvalidationInput = InvalidationRule | readonly InvalidationRule[];
@@ -1620,14 +1620,31 @@ function schemaToTypeString(schema) {
1620
1620
  return "unknown";
1621
1621
  }
1622
1622
  }
1623
+ function tagKeyToPropertyName(tag) {
1624
+ return /^[$A-Z_a-z][$\w]*$/.test(tag) ? tag : JSON.stringify(tag);
1625
+ }
1626
+ function tagToStringLiteral(tag) {
1627
+ const json = JSON.stringify(tag);
1628
+ return `'${json.slice(1, -1).replaceAll("'", "\\'")}'`;
1629
+ }
1623
1630
  function writeRouteTypes(routes, projectRoot) {
1624
- const entries = routes.map((r) => {
1631
+ const sortedRoutes = [...routes].sort((a, b) => a.pattern.localeCompare(b.pattern));
1632
+ const entries = sortedRoutes.map((r) => {
1625
1633
  const typeKey = patternToTypeString(r.pattern);
1626
1634
  const isDynamic = typeKey.startsWith("`");
1627
1635
  const querySchema = r.routeChain?.find((rt) => rt.query)?.query;
1628
1636
  const searchType = querySchema ? schemaToTypeString(querySchema) : "never";
1629
1637
  return isDynamic ? ` [key: ${typeKey}]: { search?: ${searchType} }` : ` ${typeKey}: { search?: ${searchType} }`;
1630
1638
  });
1639
+ const sortedTags = [...new Set(routes.flatMap((route) => route.tags ?? []))].sort();
1640
+ const tagBlock = sortedTags.length > 0 ? `
1641
+
1642
+ declare module "@teyik0/furin" {
1643
+ interface FurinCacheTags {
1644
+ ${sortedTags.map((tag) => ` ${tagKeyToPropertyName(tag)}: ${tagToStringLiteral(tag)};`).join(`
1645
+ `)}
1646
+ }
1647
+ }` : "";
1631
1648
  const content = `// Auto-generated by Furin. Do not edit manually.
1632
1649
  /// <reference types="@teyik0/furin/env" />
1633
1650
  import "@teyik0/furin/link";
@@ -1637,7 +1654,7 @@ declare module "@teyik0/furin/link" {
1637
1654
  ${entries.join(`;
1638
1655
  `)};
1639
1656
  }
1640
- }
1657
+ }${tagBlock}
1641
1658
  `;
1642
1659
  const typesPath = join(projectRoot, "furin-env.d.ts");
1643
1660
  const existing = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : "";
@@ -5301,6 +5318,60 @@ function validateRouteChain(chain, root, pagePath) {
5301
5318
  // src/render/cache.ts
5302
5319
  import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
5303
5320
 
5321
+ // src/auto-invalidate/registry.ts
5322
+ class AutoInvalidateRegistry {
5323
+ pathToTags = new Map;
5324
+ tagToPaths = new Map;
5325
+ registerLoaderTags(urlPath, tags) {
5326
+ if (!tags || tags.length === 0) {
5327
+ this.unregisterPath(urlPath);
5328
+ return;
5329
+ }
5330
+ this.unregisterPath(urlPath);
5331
+ const uniqueTags = new Set(tags);
5332
+ this.pathToTags.set(urlPath, uniqueTags);
5333
+ for (const tag of uniqueTags) {
5334
+ let paths = this.tagToPaths.get(tag);
5335
+ if (!paths) {
5336
+ paths = new Set;
5337
+ this.tagToPaths.set(tag, paths);
5338
+ }
5339
+ paths.add(urlPath);
5340
+ }
5341
+ }
5342
+ pathsForTags(tags) {
5343
+ const paths = new Set;
5344
+ for (const tag of tags) {
5345
+ for (const path of this.tagToPaths.get(tag) ?? []) {
5346
+ paths.add(path);
5347
+ }
5348
+ }
5349
+ return [...paths];
5350
+ }
5351
+ unregisterPath(urlPath) {
5352
+ const tags = this.pathToTags.get(urlPath);
5353
+ if (!tags) {
5354
+ return;
5355
+ }
5356
+ for (const tag of tags) {
5357
+ const paths = this.tagToPaths.get(tag);
5358
+ if (!paths) {
5359
+ continue;
5360
+ }
5361
+ paths.delete(urlPath);
5362
+ if (paths.size === 0) {
5363
+ this.tagToPaths.delete(tag);
5364
+ }
5365
+ }
5366
+ this.pathToTags.delete(urlPath);
5367
+ }
5368
+ reset() {
5369
+ this.pathToTags.clear();
5370
+ this.tagToPaths.clear();
5371
+ }
5372
+ }
5373
+ var autoInvalidateRegistry = new AutoInvalidateRegistry;
5374
+
5304
5375
  // src/context-logger.ts
5305
5376
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
5306
5377
 
@@ -5738,11 +5809,17 @@ var MAX_ISR_CACHE_SIZE = 1000;
5738
5809
  var MAX_SSG_CACHE_SIZE = 1000;
5739
5810
  var isrRouteCache = createRouteCache({
5740
5811
  maxSize: MAX_ISR_CACHE_SIZE,
5741
- name: "render:isr-html"
5812
+ name: "render:isr-html",
5813
+ onDelete: (key) => {
5814
+ autoInvalidateRegistry.unregisterPath(key);
5815
+ }
5742
5816
  });
5743
5817
  var ssgRouteCache = createRouteCache({
5744
5818
  maxSize: MAX_SSG_CACHE_SIZE,
5745
- name: "render:ssg-html"
5819
+ name: "render:ssg-html",
5820
+ onDelete: (key) => {
5821
+ autoInvalidateRegistry.unregisterPath(key);
5822
+ }
5746
5823
  });
5747
5824
  var isrCache = isrRouteCache.store;
5748
5825
  var ssgCache = ssgRouteCache.store;
@@ -5910,36 +5987,40 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
5910
5987
  }
5911
5988
  });
5912
5989
  }
5913
- function splitDeferredResult(pageResult, routeChainData) {
5914
- const syncData = {};
5915
- const deferredPromises = {};
5916
- for (const [key, value] of Object.entries(routeChainData)) {
5917
- syncData[key] = value;
5918
- }
5919
- for (const [key, value] of Object.entries(pageResult)) {
5990
+ function splitOneLoaderResult(result) {
5991
+ const sync = {};
5992
+ const deferred = {};
5993
+ const isDef = isDeferred(result);
5994
+ for (const [key, value] of Object.entries(result)) {
5920
5995
  if (key === "__isDeferred") {
5921
5996
  continue;
5922
5997
  }
5923
- if (isPromiseLike(value)) {
5924
- deferredPromises[key] = Promise.resolve(value);
5998
+ if (isDef && isPromiseLike(value)) {
5999
+ deferred[key] = Promise.resolve(value);
5925
6000
  } else {
5926
- syncData[key] = value;
6001
+ sync[key] = value;
5927
6002
  }
5928
6003
  }
5929
- return {
5930
- syncData,
5931
- deferredPromises: Object.keys(deferredPromises).length > 0 ? deferredPromises : undefined
5932
- };
6004
+ return { sync, deferred };
5933
6005
  }
5934
6006
  function isPromiseLike(value) {
5935
6007
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
5936
6008
  }
5937
- function assertNoDeferredInRouteLoaders(routeResults) {
5938
- for (const result of routeResults) {
5939
- if (isDeferred(result)) {
5940
- throw new Error("[furin] defer() is only supported in a page loader (route.page({ loader })). A route/layout loader returned a deferred object; move the deferred fields to the page loader, or `await` them in the route loader and return resolved values.");
6009
+ function mergeLoaderResults(results) {
6010
+ const allSync = {};
6011
+ const allDeferred = {};
6012
+ for (const result of results) {
6013
+ const { sync, deferred } = splitOneLoaderResult(result);
6014
+ for (const k of Object.keys(sync)) {
6015
+ delete allDeferred[k];
5941
6016
  }
6017
+ for (const k of Object.keys(deferred)) {
6018
+ delete allSync[k];
6019
+ }
6020
+ Object.assign(allSync, sync);
6021
+ Object.assign(allDeferred, deferred);
5942
6022
  }
6023
+ return { allSync, allDeferred };
5943
6024
  }
5944
6025
  async function runLoaders(route, ctx) {
5945
6026
  try {
@@ -5962,22 +6043,14 @@ async function runLoaders(route, ctx) {
5962
6043
  const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
5963
6044
  const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
5964
6045
  const results = await Promise.all([...loaderMap.values(), pagePromise]);
5965
- const merged = Object.assign({}, ...results);
5966
6046
  const headers = {};
5967
6047
  Object.assign(headers, ctx.set.headers);
5968
- const routeOnlyResults = results.slice(0, loaderMap.size);
5969
- const pageResult = results[loaderMap.size];
5970
- assertNoDeferredInRouteLoaders(routeOnlyResults);
6048
+ const { allSync, allDeferred } = mergeLoaderResults(results);
5971
6049
  const routeCtx = { params: ctx.params, query: ctx.query, path: ctx.path };
5972
- if (isDeferred(pageResult)) {
5973
- const routeMerged = Object.assign({}, ...routeOnlyResults);
5974
- const { syncData, deferredPromises } = splitDeferredResult(pageResult, routeMerged);
5975
- return { type: "data", syncData: { ...syncData, ...routeCtx }, deferredPromises, headers };
5976
- }
5977
6050
  return {
5978
6051
  type: "data",
5979
- syncData: { ...merged, ...routeCtx },
5980
- deferredPromises: undefined,
6052
+ syncData: { ...allSync, ...routeCtx },
6053
+ deferredPromises: Object.keys(allDeferred).length > 0 ? allDeferred : undefined,
5981
6054
  headers
5982
6055
  };
5983
6056
  } catch (err) {
@@ -6190,6 +6263,7 @@ async function prerenderSSG(route, params, root, origin, basePath) {
6190
6263
  status: result.status
6191
6264
  };
6192
6265
  setSSGCache(resolvedPath, entry);
6266
+ autoInvalidateRegistry.registerLoaderTags(resolvedPath, route.tags);
6193
6267
  return entry;
6194
6268
  }
6195
6269
  var pendingRevalidations = new Set;
@@ -6408,6 +6482,18 @@ function getCompileContext() {
6408
6482
  }
6409
6483
 
6410
6484
  // src/router.ts
6485
+ function collectRouteTags(routeChain, page) {
6486
+ const tags = new Set;
6487
+ for (const route of routeChain) {
6488
+ for (const tag of route.tags ?? []) {
6489
+ tags.add(tag);
6490
+ }
6491
+ }
6492
+ for (const tag of page?.tags ?? []) {
6493
+ tags.add(tag);
6494
+ }
6495
+ return tags.size > 0 ? [...tags] : undefined;
6496
+ }
6411
6497
  async function scanPages(pagesDir) {
6412
6498
  const root = await scanRootLayout(pagesDir);
6413
6499
  const routes = await scanPageFiles(pagesDir, root);
@@ -6502,7 +6588,8 @@ async function scanPageFiles(pagesDir, root) {
6502
6588
  mode: resolveMode(page, routeChain),
6503
6589
  notFound,
6504
6590
  error: errorComponent,
6505
- segmentBoundaries
6591
+ segmentBoundaries,
6592
+ tags: collectRouteTags(routeChain, page)
6506
6593
  });
6507
6594
  }
6508
6595
  return routes;
@@ -6584,6 +6671,7 @@ async function buildDevRoute(absolutePath, relativePath, root) {
6584
6671
  mode: page ? resolveMode(page, routeChain) : "ssr",
6585
6672
  page: page ?? devStubPage,
6586
6673
  routeChain,
6674
+ tags: collectRouteTags(routeChain, page),
6587
6675
  segmentBoundaries: []
6588
6676
  };
6589
6677
  }
package/dist/cli/index.js CHANGED
@@ -5216,6 +5216,60 @@ function validateRouteChain(chain, root, pagePath) {
5216
5216
  // src/render/cache.ts
5217
5217
  import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
5218
5218
 
5219
+ // src/auto-invalidate/registry.ts
5220
+ class AutoInvalidateRegistry {
5221
+ pathToTags = new Map;
5222
+ tagToPaths = new Map;
5223
+ registerLoaderTags(urlPath, tags) {
5224
+ if (!tags || tags.length === 0) {
5225
+ this.unregisterPath(urlPath);
5226
+ return;
5227
+ }
5228
+ this.unregisterPath(urlPath);
5229
+ const uniqueTags = new Set(tags);
5230
+ this.pathToTags.set(urlPath, uniqueTags);
5231
+ for (const tag of uniqueTags) {
5232
+ let paths = this.tagToPaths.get(tag);
5233
+ if (!paths) {
5234
+ paths = new Set;
5235
+ this.tagToPaths.set(tag, paths);
5236
+ }
5237
+ paths.add(urlPath);
5238
+ }
5239
+ }
5240
+ pathsForTags(tags) {
5241
+ const paths = new Set;
5242
+ for (const tag of tags) {
5243
+ for (const path of this.tagToPaths.get(tag) ?? []) {
5244
+ paths.add(path);
5245
+ }
5246
+ }
5247
+ return [...paths];
5248
+ }
5249
+ unregisterPath(urlPath) {
5250
+ const tags = this.pathToTags.get(urlPath);
5251
+ if (!tags) {
5252
+ return;
5253
+ }
5254
+ for (const tag of tags) {
5255
+ const paths = this.tagToPaths.get(tag);
5256
+ if (!paths) {
5257
+ continue;
5258
+ }
5259
+ paths.delete(urlPath);
5260
+ if (paths.size === 0) {
5261
+ this.tagToPaths.delete(tag);
5262
+ }
5263
+ }
5264
+ this.pathToTags.delete(urlPath);
5265
+ }
5266
+ reset() {
5267
+ this.pathToTags.clear();
5268
+ this.tagToPaths.clear();
5269
+ }
5270
+ }
5271
+ var autoInvalidateRegistry = new AutoInvalidateRegistry;
5272
+
5219
5273
  // src/context-logger.ts
5220
5274
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
5221
5275
 
@@ -5653,11 +5707,17 @@ var MAX_ISR_CACHE_SIZE = 1000;
5653
5707
  var MAX_SSG_CACHE_SIZE = 1000;
5654
5708
  var isrRouteCache = createRouteCache({
5655
5709
  maxSize: MAX_ISR_CACHE_SIZE,
5656
- name: "render:isr-html"
5710
+ name: "render:isr-html",
5711
+ onDelete: (key) => {
5712
+ autoInvalidateRegistry.unregisterPath(key);
5713
+ }
5657
5714
  });
5658
5715
  var ssgRouteCache = createRouteCache({
5659
5716
  maxSize: MAX_SSG_CACHE_SIZE,
5660
- name: "render:ssg-html"
5717
+ name: "render:ssg-html",
5718
+ onDelete: (key) => {
5719
+ autoInvalidateRegistry.unregisterPath(key);
5720
+ }
5661
5721
  });
5662
5722
  var isrCache = isrRouteCache.store;
5663
5723
  var ssgCache = ssgRouteCache.store;
@@ -5825,36 +5885,40 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
5825
5885
  }
5826
5886
  });
5827
5887
  }
5828
- function splitDeferredResult(pageResult, routeChainData) {
5829
- const syncData = {};
5830
- const deferredPromises = {};
5831
- for (const [key, value] of Object.entries(routeChainData)) {
5832
- syncData[key] = value;
5833
- }
5834
- for (const [key, value] of Object.entries(pageResult)) {
5888
+ function splitOneLoaderResult(result) {
5889
+ const sync = {};
5890
+ const deferred = {};
5891
+ const isDef = isDeferred(result);
5892
+ for (const [key, value] of Object.entries(result)) {
5835
5893
  if (key === "__isDeferred") {
5836
5894
  continue;
5837
5895
  }
5838
- if (isPromiseLike(value)) {
5839
- deferredPromises[key] = Promise.resolve(value);
5896
+ if (isDef && isPromiseLike(value)) {
5897
+ deferred[key] = Promise.resolve(value);
5840
5898
  } else {
5841
- syncData[key] = value;
5899
+ sync[key] = value;
5842
5900
  }
5843
5901
  }
5844
- return {
5845
- syncData,
5846
- deferredPromises: Object.keys(deferredPromises).length > 0 ? deferredPromises : undefined
5847
- };
5902
+ return { sync, deferred };
5848
5903
  }
5849
5904
  function isPromiseLike(value) {
5850
5905
  return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
5851
5906
  }
5852
- function assertNoDeferredInRouteLoaders(routeResults) {
5853
- for (const result of routeResults) {
5854
- if (isDeferred(result)) {
5855
- throw new Error("[furin] defer() is only supported in a page loader (route.page({ loader })). A route/layout loader returned a deferred object; move the deferred fields to the page loader, or `await` them in the route loader and return resolved values.");
5907
+ function mergeLoaderResults(results) {
5908
+ const allSync = {};
5909
+ const allDeferred = {};
5910
+ for (const result of results) {
5911
+ const { sync, deferred } = splitOneLoaderResult(result);
5912
+ for (const k of Object.keys(sync)) {
5913
+ delete allDeferred[k];
5914
+ }
5915
+ for (const k of Object.keys(deferred)) {
5916
+ delete allSync[k];
5856
5917
  }
5918
+ Object.assign(allSync, sync);
5919
+ Object.assign(allDeferred, deferred);
5857
5920
  }
5921
+ return { allSync, allDeferred };
5858
5922
  }
5859
5923
  async function runLoaders(route, ctx) {
5860
5924
  try {
@@ -5877,22 +5941,14 @@ async function runLoaders(route, ctx) {
5877
5941
  const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
5878
5942
  const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
5879
5943
  const results = await Promise.all([...loaderMap.values(), pagePromise]);
5880
- const merged = Object.assign({}, ...results);
5881
5944
  const headers = {};
5882
5945
  Object.assign(headers, ctx.set.headers);
5883
- const routeOnlyResults = results.slice(0, loaderMap.size);
5884
- const pageResult = results[loaderMap.size];
5885
- assertNoDeferredInRouteLoaders(routeOnlyResults);
5946
+ const { allSync, allDeferred } = mergeLoaderResults(results);
5886
5947
  const routeCtx = { params: ctx.params, query: ctx.query, path: ctx.path };
5887
- if (isDeferred(pageResult)) {
5888
- const routeMerged = Object.assign({}, ...routeOnlyResults);
5889
- const { syncData, deferredPromises } = splitDeferredResult(pageResult, routeMerged);
5890
- return { type: "data", syncData: { ...syncData, ...routeCtx }, deferredPromises, headers };
5891
- }
5892
5948
  return {
5893
5949
  type: "data",
5894
- syncData: { ...merged, ...routeCtx },
5895
- deferredPromises: undefined,
5950
+ syncData: { ...allSync, ...routeCtx },
5951
+ deferredPromises: Object.keys(allDeferred).length > 0 ? allDeferred : undefined,
5896
5952
  headers
5897
5953
  };
5898
5954
  } catch (err) {
@@ -6105,6 +6161,7 @@ async function prerenderSSG(route, params, root, origin, basePath) {
6105
6161
  status: result.status
6106
6162
  };
6107
6163
  setSSGCache(resolvedPath, entry);
6164
+ autoInvalidateRegistry.registerLoaderTags(resolvedPath, route.tags);
6108
6165
  return entry;
6109
6166
  }
6110
6167
  var pendingRevalidations = new Set;
@@ -6323,6 +6380,18 @@ function getCompileContext() {
6323
6380
  }
6324
6381
 
6325
6382
  // src/router.ts
6383
+ function collectRouteTags(routeChain, page) {
6384
+ const tags = new Set;
6385
+ for (const route of routeChain) {
6386
+ for (const tag of route.tags ?? []) {
6387
+ tags.add(tag);
6388
+ }
6389
+ }
6390
+ for (const tag of page?.tags ?? []) {
6391
+ tags.add(tag);
6392
+ }
6393
+ return tags.size > 0 ? [...tags] : undefined;
6394
+ }
6326
6395
  async function scanPages(pagesDir) {
6327
6396
  const root = await scanRootLayout(pagesDir);
6328
6397
  const routes = await scanPageFiles(pagesDir, root);
@@ -6417,7 +6486,8 @@ async function scanPageFiles(pagesDir, root) {
6417
6486
  mode: resolveMode(page, routeChain),
6418
6487
  notFound,
6419
6488
  error: errorComponent,
6420
- segmentBoundaries
6489
+ segmentBoundaries,
6490
+ tags: collectRouteTags(routeChain, page)
6421
6491
  });
6422
6492
  }
6423
6493
  return routes;
@@ -6499,6 +6569,7 @@ async function buildDevRoute(absolutePath, relativePath, root) {
6499
6569
  mode: page ? resolveMode(page, routeChain) : "ssr",
6500
6570
  page: page ?? devStubPage,
6501
6571
  routeChain,
6572
+ tags: collectRouteTags(routeChain, page),
6502
6573
  segmentBoundaries: []
6503
6574
  };
6504
6575
  }
package/dist/client.d.ts CHANGED
@@ -14,9 +14,15 @@ type NormalizeUnset<T> = [T] extends [Unset] ? {} : T;
14
14
  * Transforms each key of a parent-data record into an individual `Promise<T>`.
15
15
  * This is what child loaders see for inherited fields — direct values from
16
16
  * `RouteContext` (request, params, set, …) remain unchanged.
17
+ *
18
+ * `Awaited<T[K]>` mirrors the JS Promise-chaining auto-flatten used by
19
+ * `createLoaderCtx`: when an ancestor wrapped a field with `defer()` (so the
20
+ * raw value is itself a `Promise<U>`), the type collapses to `Promise<U>`
21
+ * instead of `Promise<Promise<U>>`. Otherwise TypeScript would force a
22
+ * redundant `await await ctx.field` dance.
17
23
  */
18
24
  type PromisifyData<T extends Record<string, unknown>> = {
19
- [K in keyof T]: Promise<T[K]>;
25
+ [K in keyof T]: Promise<Awaited<T[K]>>;
20
26
  };
21
27
  export interface RouteContext<TParams = {}, TQuery = {}> {
22
28
  cookie: Record<string, Cookie<unknown>>;
@@ -48,7 +54,7 @@ type ResolveParent<T> = T extends RouteRef<infer D, infer P, infer Q> ? {
48
54
  query: Unset;
49
55
  };
50
56
  interface Resolved<TParentRef, TLoaderData, TParamsSchema = Unset, TQuerySchema = Unset> {
51
- data: ToRecord<ResolveParent<TParentRef>["data"] & TLoaderData>;
57
+ data: ToRecord<ResolveParent<TParentRef>["data"] & Omit<TLoaderData, "__isDeferred">>;
52
58
  params: MergeSchema<ResolveParent<TParentRef>["params"], ResolvedSchema<TParamsSchema>>;
53
59
  query: MergeSchema<ResolveParent<TParentRef>["query"], ResolvedSchema<TQuerySchema>>;
54
60
  }
@@ -107,6 +113,7 @@ export interface PageConfig<TParentData extends Record<string, unknown>, TParams
107
113
  head?: (ctx: ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData) => HeadOptions;
108
114
  loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => Promise<TPageLoaderData> | TPageLoaderData;
109
115
  staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
116
+ tags?: string[];
110
117
  }
111
118
  export interface RuntimeRoute {
112
119
  __type: "FURIN_ROUTE";
@@ -119,6 +126,7 @@ export interface RuntimeRoute {
119
126
  parent?: RuntimeRoute;
120
127
  query?: unknown;
121
128
  revalidate?: number;
129
+ tags?: string[];
122
130
  }
123
131
  export interface RuntimePage {
124
132
  __type: "FURIN_PAGE";
@@ -127,6 +135,7 @@ export interface RuntimePage {
127
135
  head?(ctx: Record<string, unknown>): HeadOptions;
128
136
  loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
129
137
  staticParams?(): Promise<Record<string, string>[]> | Record<string, string>[];
138
+ tags?: string[];
130
139
  }
131
140
  export interface RouteRef<TData extends Record<string, unknown> = Record<string, unknown>, TParams = unknown, TQuery = unknown> {
132
141
  readonly __brand: "FURIN_ROUTE_REF";
@@ -142,6 +151,7 @@ interface PageResult<TData extends Record<string, unknown>, TParams, TQuery, TPa
142
151
  component: React.FC<TData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
143
152
  head?: (ctx: ComponentProps<TParams, TQuery> & TData & TPageLoaderData) => HeadOptions;
144
153
  loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TData>) => Promise<TPageLoaderData> | TPageLoaderData;
154
+ tags?: string[];
145
155
  }
146
156
  export interface Route<TParentData extends Record<string, unknown>, TParams, TQuery> {
147
157
  __type: "FURIN_ROUTE";
@@ -155,6 +165,7 @@ export interface Route<TParentData extends Record<string, unknown>, TParams, TQu
155
165
  mode?: "ssr" | "ssg" | "isr";
156
166
  revalidate?: number;
157
167
  staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
168
+ tags?: string[];
158
169
  component: React.FC<NoInfer<TParentData & TPageLoaderData & ComponentProps<TParams, TQuery>>>;
159
170
  head?: (ctx: NoInfer<ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData>) => HeadOptions;
160
171
  }): PageResult<TParentData, TParams, TQuery, TPageLoaderData>;
@@ -162,6 +173,7 @@ export interface Route<TParentData extends Record<string, unknown>, TParams, TQu
162
173
  mode?: "ssr" | "ssg" | "isr";
163
174
  revalidate?: number;
164
175
  staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
176
+ tags?: string[];
165
177
  component: React.FC<TParentData & ComponentProps<TParams, TQuery>>;
166
178
  head?: (ctx: ComponentProps<TParams, TQuery> & TParentData) => HeadOptions;
167
179
  }): PageResult<TParentData, TParams, TQuery, {}>;
@@ -171,6 +183,7 @@ export interface Route<TParentData extends Record<string, unknown>, TParams, TQu
171
183
  /** Branded ref for type inference when used as a parent. */
172
184
  ref: RouteRef<TParentData, TParams, TQuery>;
173
185
  revalidate?: number;
186
+ tags?: string[];
174
187
  }
175
188
  export declare function createRoute<TParentRef extends RouteRef | undefined = undefined, TParamsSchema extends AnySchema | Unset = Unset, TQuerySchema extends AnySchema | Unset = Unset, TLoaderData extends object = {}>(config?: {
176
189
  parent?: {
@@ -182,6 +195,7 @@ export declare function createRoute<TParentRef extends RouteRef | undefined = un
182
195
  revalidate?: number;
183
196
  params?: TParamsSchema;
184
197
  query?: TQuerySchema;
198
+ tags?: string[];
185
199
  loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & PromisifyData<ResolveParent<TParentRef>["data"]>) => Promise<TLoaderData> | TLoaderData;
186
200
  layout?: React.FC<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["data"] & {
187
201
  children: React.ReactNode;
@@ -216,7 +230,9 @@ export type DeferredData<T extends Record<string, unknown>> = T & {
216
230
  * Wraps loader data so that Promise-valued fields are streamed lazily while
217
231
  * scalar fields are embedded in the initial HTML shell immediately.
218
232
  *
219
- * Use inside a page loader only (not in route / layout loaders — v1 restriction).
233
+ * Use in any loader — page (`route.page({ loader })`) or route/layout
234
+ * (`createRoute({ loader })`). Promise-valued fields are streamed lazily;
235
+ * scalar fields are embedded in the initial HTML shell.
220
236
  */
221
237
  export declare function defer<T extends Record<string, unknown>>(data: T): DeferredData<T>;
222
238
  /**
package/dist/furin.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Elysia } from "elysia";
2
2
  import { type EvlogElysiaOptions } from "evlog/elysia";
3
+ export interface FurinCacheTags {
4
+ }
5
+ export type CacheTag = keyof FurinCacheTags extends never ? string : keyof FurinCacheTags;
3
6
  /**
4
7
  * Main Furin plugin.
5
8
  *
@@ -45,6 +48,8 @@ export declare function furin({ pagesDir, logger, }: {
45
48
  standaloneSchema: {};
46
49
  response: {};
47
50
  }>>;
51
+ export type { InvalidationInput, InvalidationRule } from "./auto-invalidate/index.ts";
52
+ export { furinInvalidate, revalidateTag } from "./auto-invalidate/index.ts";
48
53
  export { Await, useAsyncError, useAsyncValue } from "./await.tsx";
49
54
  export type { DeferredData } from "./client.ts";
50
55
  export { defer, isDeferred } from "./client.ts";