@teyik0/furin 0.1.0-alpha.13 → 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.
Files changed (69) hide show
  1. package/README.md +14 -232
  2. package/dist/auto-invalidate/index.d.ts +4 -0
  3. package/dist/auto-invalidate/plugin.d.ts +38 -0
  4. package/dist/auto-invalidate/registry.d.ts +9 -0
  5. package/dist/auto-invalidate/runtime.d.ts +9 -0
  6. package/dist/auto-invalidate/types.d.ts +12 -0
  7. package/dist/await.d.ts +67 -0
  8. package/dist/build/index.js +2095 -185
  9. package/dist/cli/index.js +2070 -182
  10. package/dist/client.d.ts +51 -4
  11. package/dist/client.js +65 -1
  12. package/dist/deferred-ndjson.d.ts +32 -0
  13. package/dist/error.d.ts +14 -0
  14. package/dist/furin.d.ts +8 -0
  15. package/dist/furin.js +2927 -319
  16. package/dist/lang-detect.d.ts +5 -0
  17. package/dist/link.d.ts +1 -0
  18. package/dist/link.js +1453 -95
  19. package/dist/plugin/index.js +96 -25
  20. package/dist/plugin/transform-client.d.ts +2 -1
  21. package/dist/render/assemble.d.ts +32 -0
  22. package/dist/render/cache.d.ts +7 -0
  23. package/dist/render/element.d.ts +17 -1
  24. package/dist/render/index.d.ts +10 -1
  25. package/dist/render/index.ts +250 -44
  26. package/dist/render/loaders.d.ts +46 -3
  27. package/dist/render/shell.d.ts +16 -6
  28. package/dist/render/shell.ts +27 -12
  29. package/dist/router-provider.d.ts +86 -18
  30. package/dist/router.d.ts +66 -0
  31. package/dist/router.js +2909 -374
  32. package/dist/router.ts +586 -54
  33. package/dist/server-error.d.ts +12 -0
  34. package/dist/utils.d.ts +7 -0
  35. package/package.json +8 -7
  36. package/src/adapter/bun.ts +3 -3
  37. package/src/adapter/static.ts +73 -31
  38. package/src/auto-invalidate/index.ts +10 -0
  39. package/src/auto-invalidate/plugin.ts +25 -0
  40. package/src/auto-invalidate/registry.ts +60 -0
  41. package/src/auto-invalidate/runtime.ts +133 -0
  42. package/src/auto-invalidate/types.ts +16 -0
  43. package/src/await.tsx +175 -0
  44. package/src/build/client.ts +4 -8
  45. package/src/build/hydrate.ts +67 -1
  46. package/src/build/route-types.ts +29 -3
  47. package/src/build/scan-server.ts +6 -23
  48. package/src/client.ts +80 -3
  49. package/src/deferred-ndjson.ts +212 -0
  50. package/src/dev-page-plugin.ts +2 -0
  51. package/src/error.ts +18 -1
  52. package/src/furin.ts +19 -2
  53. package/src/lang-detect.ts +46 -0
  54. package/src/link.tsx +16 -3
  55. package/src/plugin/index.ts +7 -8
  56. package/src/plugin/transform-client.ts +108 -39
  57. package/src/render/assemble.ts +67 -0
  58. package/src/render/boundaries.tsx +23 -5
  59. package/src/render/cache.ts +14 -0
  60. package/src/render/default-screens.tsx +4 -11
  61. package/src/render/dev-cache.ts +5 -0
  62. package/src/render/element.tsx +26 -3
  63. package/src/render/index.ts +250 -44
  64. package/src/render/loaders.ts +219 -18
  65. package/src/render/shell.ts +27 -12
  66. package/src/router-provider.tsx +414 -122
  67. package/src/router.ts +586 -54
  68. package/src/server-error.ts +47 -0
  69. package/src/utils.ts +31 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Server-thrown error carrying an HTTP status and a server-computed digest
3
+ * across SSR and SPA navigation.
4
+ *
5
+ * Why a class (not property-stamping):
6
+ * - Mirrors the `FurinNotFoundError` pattern (consistency).
7
+ * - Type-narrowable via `instanceof` and the brand check.
8
+ * - Survives error wrappers (Sentry / monitoring libs that re-throw
9
+ * `new Error(original.message)` would strip property stamps).
10
+ *
11
+ * Used by:
12
+ * - `FurinErrorBoundary.getDerivedStateFromError` — to honour the server's
13
+ * digest instead of recomputing one client-side (the latter would produce a
14
+ * different hash because the public message + synthetic stack differ from the
15
+ * original server-side error).
16
+ * - SPA navigation: `RouterProvider` throws this during render of the route
17
+ * position when `__furinError` was sentinelled into the NDJSON payload, so
18
+ * the nearest error boundary catches it without forcing a full-page reload.
19
+ */
20
+ const SERVER_ERROR_BRAND = "FURIN_SERVER_ERROR" as const;
21
+
22
+ export interface FurinServerErrorPayload {
23
+ digest: string;
24
+ message: string;
25
+ status: number;
26
+ }
27
+
28
+ export class FurinServerError extends Error {
29
+ readonly __furinBrand = SERVER_ERROR_BRAND;
30
+ readonly digest: string;
31
+ readonly status: number;
32
+
33
+ constructor(args: FurinServerErrorPayload) {
34
+ super(args.message);
35
+ this.status = args.status;
36
+ this.digest = args.digest;
37
+ }
38
+ }
39
+
40
+ export function isFurinServerError(err: unknown): err is FurinServerError {
41
+ return (
42
+ err instanceof FurinServerError ||
43
+ (typeof err === "object" &&
44
+ err !== null &&
45
+ (err as { __furinBrand?: unknown }).__furinBrand === SERVER_ERROR_BRAND)
46
+ );
47
+ }
package/src/utils.ts CHANGED
@@ -45,6 +45,37 @@ export function hasCycle(route: RuntimeRoute): boolean {
45
45
  return false;
46
46
  }
47
47
 
48
+ /**
49
+ * Maps over `items` with a bounded worker pool, preserving input order.
50
+ * Use whenever an `await Promise.all(items.map(...))` would open as many
51
+ * concurrent async operations as there are items — unbounded fan-out can
52
+ * exhaust file descriptors, sockets, or memory on large inputs.
53
+ */
54
+ export async function mapWithConcurrency<T, R>(
55
+ items: readonly T[],
56
+ concurrency: number,
57
+ fn: (item: T, index: number) => Promise<R>
58
+ ): Promise<R[]> {
59
+ if (items.length === 0) {
60
+ return [];
61
+ }
62
+ const results = new Array<R>(items.length);
63
+ let cursor = 0;
64
+ const workerCount = Math.min(Math.max(concurrency, 1), items.length);
65
+ await Promise.all(
66
+ Array.from({ length: workerCount }, async () => {
67
+ while (true) {
68
+ const index = cursor++;
69
+ if (index >= items.length) {
70
+ return;
71
+ }
72
+ results[index] = await fn(items[index] as T, index);
73
+ }
74
+ })
75
+ );
76
+ return results;
77
+ }
78
+
48
79
  export function validateRouteChain(
49
80
  chain: RuntimeRoute[],
50
81
  root: RuntimeRoute,