@teyik0/furin 0.2.0-alpha.3 → 0.2.0-alpha.5

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 (98) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +37 -33
  3. package/dist/adapter/bun.d.ts +17 -1
  4. package/dist/adapter/package.d.ts +26 -0
  5. package/dist/build/client.d.ts +1 -1
  6. package/dist/build/compile-entry.d.ts +3 -3
  7. package/dist/build/compile-entry.ts +114 -109
  8. package/dist/build/entry-template.d.ts +35 -9
  9. package/dist/build/entry-template.ts +206 -156
  10. package/dist/build/hydrate.d.ts +1 -1
  11. package/dist/build/index.js +643 -247
  12. package/dist/build/scan-server.d.ts +10 -4
  13. package/dist/build/server-routes-entry.d.ts +3 -3
  14. package/dist/build/server-routes-entry.ts +30 -36
  15. package/dist/build/ssg-cache.d.ts +1 -1
  16. package/dist/build/types.d.ts +36 -1
  17. package/dist/cli/config.d.ts +6 -1
  18. package/dist/cli/index.js +662 -260
  19. package/dist/client/link.js +163 -16
  20. package/dist/client/router/abort.d.ts +1 -0
  21. package/dist/client/router/sync-catch-up.d.ts +29 -0
  22. package/dist/config.d.ts +11 -2
  23. package/dist/config.js +5 -1
  24. package/dist/furin.d.ts +37 -19
  25. package/dist/furin.js +982 -378
  26. package/dist/server/auto-invalidate/registry.d.ts +8 -1
  27. package/dist/server/cache/dev-loader.d.ts +3 -2
  28. package/dist/server/cache/invalidation.d.ts +19 -0
  29. package/dist/server/cache/isr.d.ts +6 -2
  30. package/dist/server/cache/registry.d.ts +3 -3
  31. package/dist/server/cache/ssg.d.ts +6 -2
  32. package/dist/server/cache/store-view.d.ts +11 -0
  33. package/dist/server/instance.d.ts +86 -0
  34. package/dist/server/internal.d.ts +16 -1
  35. package/dist/server/internal.js +72 -5
  36. package/dist/server/render/template.d.ts +3 -2
  37. package/dist/server/sync/adapter.d.ts +62 -0
  38. package/dist/server/sync/config.d.ts +11 -0
  39. package/dist/server/sync/fingerprint.d.ts +6 -0
  40. package/dist/server/sync/index.d.ts +2 -2
  41. package/dist/server/sync/memory-adapter.d.ts +17 -0
  42. package/dist/server/sync/plugin.d.ts +12 -195
  43. package/dist/server/sync/response.d.ts +4 -0
  44. package/dist/server/sync/stream.d.ts +24 -5
  45. package/dist/shared/prefix.d.ts +15 -0
  46. package/package.json +6 -1
  47. package/src/adapter/README.md +13 -13
  48. package/src/adapter/bun.ts +113 -50
  49. package/src/adapter/package.ts +206 -0
  50. package/src/build/client.ts +158 -152
  51. package/src/build/compile-entry.ts +114 -109
  52. package/src/build/entry-template.ts +206 -156
  53. package/src/build/hydrate.ts +342 -340
  54. package/src/build/index.ts +223 -152
  55. package/src/build/route-types.ts +145 -145
  56. package/src/build/scan-server.ts +111 -95
  57. package/src/build/server-routes-entry.ts +30 -36
  58. package/src/build/shared.ts +80 -80
  59. package/src/build/ssg-cache.ts +36 -32
  60. package/src/build/types.ts +125 -89
  61. package/src/cli/config.ts +9 -3
  62. package/src/cli/index.ts +21 -3
  63. package/src/client/router/abort.ts +5 -0
  64. package/src/client/router/link-utils.ts +184 -184
  65. package/src/client/router/provider.tsx +883 -804
  66. package/src/client/router/sync-catch-up.ts +113 -0
  67. package/src/client/router/types.ts +276 -276
  68. package/src/client/sync.ts +98 -98
  69. package/src/client.ts +369 -369
  70. package/src/config.ts +14 -1
  71. package/src/furin.ts +619 -465
  72. package/src/server/auto-invalidate/registry.ts +23 -1
  73. package/src/server/auto-invalidate/runtime.ts +159 -134
  74. package/src/server/cache/dev-loader.ts +77 -38
  75. package/src/server/cache/invalidation.ts +71 -30
  76. package/src/server/cache/isr.ts +20 -5
  77. package/src/server/cache/registry.ts +17 -20
  78. package/src/server/cache/ssg.ts +19 -4
  79. package/src/server/cache/store-view.ts +30 -0
  80. package/src/server/dev-page-plugin.ts +454 -454
  81. package/src/server/instance.ts +252 -0
  82. package/src/server/internal.ts +100 -5
  83. package/src/server/render/assemble.ts +160 -160
  84. package/src/server/render/isr.ts +323 -323
  85. package/src/server/render/not-found.ts +9 -3
  86. package/src/server/render/ssr.ts +603 -585
  87. package/src/server/render/template.ts +57 -24
  88. package/src/server/router/plugin.ts +384 -384
  89. package/src/server/sync/adapter.ts +65 -0
  90. package/src/server/sync/config.ts +60 -29
  91. package/src/server/sync/fingerprint.ts +44 -0
  92. package/src/server/sync/index.ts +15 -14
  93. package/src/server/sync/memory-adapter.ts +196 -0
  94. package/src/server/sync/plugin.ts +199 -108
  95. package/src/server/sync/response.ts +77 -0
  96. package/src/server/sync/stream.ts +162 -144
  97. package/src/shared/deferred-ndjson.ts +7 -0
  98. package/src/shared/prefix.ts +38 -0
@@ -1,47 +1,77 @@
1
- // ── Dev template ─────────────────────────────────────────────────────────────
1
+ // ── HTML template state (per furin instance) ────────────────────────────────
2
2
 
3
3
  import { readFileSync } from "node:fs";
4
+ import {
5
+ allStateBuckets,
6
+ currentInstance,
7
+ defaultInstanceBucket,
8
+ type FurinInstance,
9
+ instanceSlot,
10
+ } from "../instance.ts";
4
11
 
5
- let _prodTemplatePath: string | null = null;
6
- let _prodTemplateContent: string | null = null;
12
+ interface TemplateState {
13
+ devCache: { html: string; ts: number } | null;
14
+ prodContent: string | null;
15
+ prodPath: string | null;
16
+ }
17
+
18
+ const instanceTemplateState = instanceSlot(
19
+ (): TemplateState => ({ devCache: null, prodContent: null, prodPath: null })
20
+ );
7
21
 
8
- /** Dev template cache — avoids a loopback HTTP fetch on every SSR request. */
9
- let _devTemplateCache: { html: string; ts: number } | null = null;
10
22
  const DEV_TEMPLATE_TTL_MS = 1000;
11
23
 
12
24
  export async function getDevTemplate(origin: string): Promise<string> {
13
- if (_devTemplateCache && Date.now() - _devTemplateCache.ts < DEV_TEMPLATE_TTL_MS) {
14
- return _devTemplateCache.html;
25
+ const instance = currentInstance();
26
+ const state = instanceTemplateState(instance);
27
+ if (state.devCache && Date.now() - state.devCache.ts < DEV_TEMPLATE_TTL_MS) {
28
+ return state.devCache.html;
15
29
  }
16
- const r = await fetch(`${origin}/_bun_hmr_entry`);
30
+ // Each instance's HMR entry is mounted under its own prefix.
31
+ const entryPath = `${instance.prefix}/_bun_hmr_entry`;
32
+ const r = await fetch(`${origin}${entryPath}`);
17
33
  if (!r.ok) {
18
- throw new Error(`/_bun_hmr_entry returned ${r.status}`);
34
+ throw new Error(`${entryPath} returned ${r.status}`);
19
35
  }
20
36
  const html = await r.text();
21
- _devTemplateCache = { html, ts: Date.now() };
37
+ state.devCache = { html, ts: Date.now() };
22
38
  return html;
23
39
  }
24
40
 
25
- export function setProductionTemplatePath(path: string | null): void {
26
- _prodTemplatePath = path;
27
- _prodTemplateContent = null;
41
+ export function setProductionTemplatePath(path: string | null, instance?: FurinInstance): void {
42
+ const state = instanceTemplateState(instance);
43
+ state.prodPath = path;
44
+ state.prodContent = null;
28
45
  }
29
46
 
30
- export function setProductionTemplateContent(content: string): void {
31
- _prodTemplatePath = null;
32
- _prodTemplateContent = content;
47
+ export function setProductionTemplateContent(content: string, instance?: FurinInstance): void {
48
+ const state = instanceTemplateState(instance);
49
+ state.prodPath = null;
50
+ state.prodContent = content;
33
51
  }
34
52
 
35
53
  export function getProductionTemplate(): string | null {
36
- if (_prodTemplateContent !== null) {
37
- return _prodTemplateContent;
54
+ const own = readTemplate(instanceTemplateState());
55
+ if (own !== null) {
56
+ return own;
57
+ }
58
+ // Config-before-mount fallback: `setProductionTemplateContent()` called
59
+ // before any furin() registration lands on the default bucket — treat that
60
+ // as a process-wide default template.
61
+ const fallback = instanceTemplateState(defaultInstanceBucket());
62
+ return readTemplate(fallback);
63
+ }
64
+
65
+ function readTemplate(state: TemplateState): string | null {
66
+ if (state.prodContent !== null) {
67
+ return state.prodContent;
38
68
  }
39
- if (!_prodTemplatePath) {
69
+ if (!state.prodPath) {
40
70
  return null;
41
71
  }
42
72
  try {
43
- _prodTemplateContent = readFileSync(_prodTemplatePath, "utf8");
44
- return _prodTemplateContent;
73
+ state.prodContent = readFileSync(state.prodPath, "utf8");
74
+ return state.prodContent;
45
75
  } catch {
46
76
  return null;
47
77
  }
@@ -49,7 +79,10 @@ export function getProductionTemplate(): string | null {
49
79
 
50
80
  /** @internal test-only — resets all template state */
51
81
  export function __resetTemplateState(): void {
52
- _prodTemplatePath = null;
53
- _prodTemplateContent = null;
54
- _devTemplateCache = null;
82
+ for (const instance of allStateBuckets()) {
83
+ const state = instanceTemplateState(instance);
84
+ state.devCache = null;
85
+ state.prodContent = null;
86
+ state.prodPath = null;
87
+ }
55
88
  }