@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,3 +1,4 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  export declare class AutoInvalidateRegistry {
2
3
  private readonly pathToTags;
3
4
  private readonly tagToPaths;
@@ -6,4 +7,10 @@ export declare class AutoInvalidateRegistry {
6
7
  unregisterPath(urlPath: string): void;
7
8
  reset(): void;
8
9
  }
9
- export declare const autoInvalidateRegistry: AutoInvalidateRegistry;
10
+ /** The current furin instance's registry (see server/instance.ts). */
11
+ export declare function getAutoInvalidateRegistry(instance?: FurinInstance): AutoInvalidateRegistry;
12
+ /**
13
+ * Instance-scoped facade kept under the historical singleton name so call
14
+ * sites read the same — every method resolves the current instance's registry.
15
+ */
16
+ export declare const autoInvalidateRegistry: Pick<AutoInvalidateRegistry, "registerLoaderTags" | "pathsForTags" | "unregisterPath" | "reset">;
@@ -1,3 +1,4 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  import { type RevalidateType } from "./route-cache";
2
3
  export interface DevLoaderCacheEntry {
3
4
  dependencies: string[];
@@ -12,8 +13,6 @@ export interface InvalidateOutcome {
12
13
  isr: number;
13
14
  ssg: number;
14
15
  }
15
- export declare const devISRLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
16
- export declare const devSSGLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
17
16
  export declare function getDevISRLoaderCache(key: string): DevLoaderCacheEntry | undefined;
18
17
  export declare function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): void;
19
18
  export declare function getDevSSGLoaderCache(key: string): DevLoaderCacheEntry | undefined;
@@ -25,4 +24,6 @@ export declare function isDevLoaderCacheFresh(entry: DevLoaderCacheEntry): boole
25
24
  export declare function isDevLoaderCacheValid(entry: DevLoaderCacheEntry): boolean;
26
25
  export declare function getAllDevISRLoaderEntries(): [string, DevLoaderCacheEntry][];
27
26
  export declare function getAllDevSSGLoaderEntries(): [string, DevLoaderCacheEntry][];
27
+ /** @internal — clears dev loader caches for `instance` (default: current). */
28
+ export declare function clearDevLoaderCaches(instance?: FurinInstance): void;
28
29
  export declare function __resetDevLoaderCacheState(): void;
@@ -1,3 +1,4 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  import type { RevalidateType } from "./route-cache";
2
3
  export declare function setBuildId(id: string): void;
3
4
  export declare function getBuildId(): string;
@@ -6,7 +7,25 @@ export declare function consumePendingInvalidations(): string[];
6
7
  type CachePurger = (paths: string[]) => Promise<void>;
7
8
  export declare function setCachePurger(fn: CachePurger): void;
8
9
  export declare function callCachePurger(paths: string[]): void;
10
+ /**
11
+ * Invalidates `path` across EVERY mounted furin instance — paths are logical
12
+ * (unprefixed), and with shared data two apps can legitimately render the same
13
+ * logical path. This mirrors the historical shared-cache behaviour. Each
14
+ * instance's invalidation runs inside its own scope so cache `onDelete` hooks
15
+ * (auto-invalidate unregistration) hit the owning instance's registry.
16
+ */
9
17
  export declare function revalidatePath(path: string, type: RevalidateType): boolean;
18
+ /**
19
+ * Invalidates `path` against a SINGLE instance's caches. `revalidateTag` uses
20
+ * this because it knows which instance registered each path — the cross-app
21
+ * fan-out of `revalidatePath` would also evict a sibling app's unrelated page
22
+ * that merely shares the pathname. Does NOT call the CDN purger; callers
23
+ * batch the returned `purgedPaths` themselves.
24
+ */
25
+ export declare function revalidatePathForInstance(instance: FurinInstance, path: string, type: RevalidateType): {
26
+ deleted: boolean;
27
+ purgedPaths: string[];
28
+ };
10
29
  /** @internal — resets all module state between tests */
11
30
  export declare function __resetCacheState(): void;
12
31
  export {};
@@ -1,6 +1,10 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  import { type ISRCacheEntry } from "./isr-ssg";
2
- export declare const isrRouteCache: import("./route-cache").Cache<ISRCacheEntry>;
3
- export declare const isrCache: Map<string, ISRCacheEntry>;
3
+ import type { Cache } from "./route-cache";
4
+ import { type StoreView } from "./store-view";
5
+ export declare function isrRouteCache(instance?: FurinInstance): Cache<ISRCacheEntry>;
6
+ /** Raw store view over the current instance's ISR cache. */
7
+ export declare const isrCache: StoreView<ISRCacheEntry>;
4
8
  export declare function getISRCache(key: string): ISRCacheEntry | undefined;
5
9
  export declare function deleteISRCache(key: string): boolean;
6
10
  export declare function setISRCache(key: string, entry: ISRCacheEntry): void;
@@ -1,5 +1,5 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  import type { Cache } from "./route-cache";
2
3
  export type CacheInvalidator = Pick<Cache<unknown>, "invalidatePath" | "name">;
3
- export declare function registerCacheInvalidator(invalidator: CacheInvalidator): () => void;
4
- export declare function getCacheInvalidators(): IterableIterator<CacheInvalidator>;
5
- export declare function clearCacheInvalidators(): void;
4
+ export declare function registerCacheInvalidator(invalidator: CacheInvalidator, instance?: FurinInstance): () => void;
5
+ export declare function getCacheInvalidators(instance?: FurinInstance): IterableIterator<CacheInvalidator>;
@@ -1,5 +1,9 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  import { type SsgCacheEntry } from "./isr-ssg";
2
- export declare const ssgRouteCache: import("./route-cache").Cache<SsgCacheEntry>;
3
- export declare const ssgCache: Map<string, SsgCacheEntry>;
3
+ import type { Cache } from "./route-cache";
4
+ import { type StoreView } from "./store-view";
5
+ export declare function ssgRouteCache(instance?: FurinInstance): Cache<SsgCacheEntry>;
6
+ /** Raw store view over the current instance's SSG cache. */
7
+ export declare const ssgCache: StoreView<SsgCacheEntry>;
4
8
  export declare function getSSGCache(key: string): SsgCacheEntry | undefined;
5
9
  export declare function setSSGCache(key: string, entry: SsgCacheEntry): void;
@@ -0,0 +1,11 @@
1
+ export interface StoreView<Entry> {
2
+ clear(): void;
3
+ delete(key: string): boolean;
4
+ entries(): IterableIterator<[string, Entry]>;
5
+ get(key: string): Entry | undefined;
6
+ has(key: string): boolean;
7
+ keys(): IterableIterator<string>;
8
+ set(key: string, entry: Entry): void;
9
+ readonly size: number;
10
+ }
11
+ export declare function createStoreView<Entry>(resolve: () => Map<string, Entry>): StoreView<Entry>;
@@ -0,0 +1,86 @@
1
+ export interface FurinInstance {
2
+ buildId: string;
3
+ /** Absolute pagesDir — also the compile-context key. */
4
+ readonly pagesDir: string;
5
+ /** Mount prefix, `""` for the root app or `/admin`-style (no trailing slash). */
6
+ readonly prefix: string;
7
+ /** @internal Traffic epoch at registration time (see registerInstance). */
8
+ registrationEpoch: number;
9
+ /** Generic per-instance state bag backing `instanceSlot()`. */
10
+ readonly state: Map<symbol, unknown>;
11
+ /** Logical sync stream path (unprefixed) injected into HTML, or undefined. */
12
+ syncStreamPath: string | undefined;
13
+ }
14
+ export declare function createInstance(prefix: string, pagesDir: string): FurinInstance;
15
+ /** @internal Called by the request wrap for every served request. */
16
+ export declare function markTraffic(): void;
17
+ /**
18
+ * The process-wide fallback bucket. State written outside any instance scope
19
+ * before the first `furin()` registration lands here — config-like readers
20
+ * (e.g. the production template) treat it as a default.
21
+ */
22
+ export declare function defaultInstanceBucket(): FurinInstance;
23
+ /**
24
+ * Normalizes a user-provided mount prefix. Accepts `""`, `"/"` (both → root)
25
+ * or `/segment(/segment)*`. Throws on anything else so misconfiguration fails
26
+ * at startup instead of producing silently unreachable routes.
27
+ */
28
+ export declare function normalizePrefix(prefix: string | undefined): string;
29
+ /**
30
+ * Throws when mounting `pagesDir` under `prefix` would collide with a LIVE
31
+ * registration. Rules:
32
+ * - same pagesDir → idempotent re-mount (mirrors Elysia's name-based dedup);
33
+ * - different pagesDir, NO traffic since the existing registration → two apps
34
+ * composed into one server are claiming the same prefix: hard error;
35
+ * - different pagesDir, traffic flowed since → the existing registration is a
36
+ * leftover from a torn-down server (tests): replacement is allowed.
37
+ */
38
+ export declare function assertPrefixAvailable(prefix: string, pagesDir: string): void;
39
+ /** Registers an instance under its prefix (see assertPrefixAvailable). */
40
+ export declare function registerInstance(instance: FurinInstance): FurinInstance;
41
+ /**
42
+ * Resolves the instance owning `pathname` by longest-prefix match on a path
43
+ * boundary. Falls back to the root (`""`) instance when one is mounted, else
44
+ * the default bucket — never an arbitrary prefixed sibling, whose template/
45
+ * cache/build state would otherwise leak into parent-app routes.
46
+ */
47
+ export declare function resolveInstanceByPath(pathname: string): FurinInstance;
48
+ /**
49
+ * The instance the current code runs for. Resolution order:
50
+ * 1. request/render ALS scope, 2. sole registered instance, 3. default bucket.
51
+ * With ≥2 instances and no scope, state access is ambiguous — the default
52
+ * bucket keeps out-of-request writes (e.g. build-time template setup)
53
+ * self-consistent instead of leaking into an arbitrary app.
54
+ */
55
+ export declare function currentInstance(): FurinInstance;
56
+ /** All registered instances (used by cross-instance ops like revalidateTag). */
57
+ export declare function allInstances(): FurinInstance[];
58
+ /**
59
+ * @internal Every live state bucket: registered instances plus the default
60
+ * fallback bucket. Reset helpers iterate this so state written outside any
61
+ * registration (tests, config-before-mount) is covered too.
62
+ */
63
+ export declare function allStateBuckets(): FurinInstance[];
64
+ /**
65
+ * @internal test-only — forgets registered instances (fresh mounts get a
66
+ * clean registry) while PRESERVING the default bucket, so process-wide
67
+ * defaults installed once (e.g. a test template in `beforeAll`) survive.
68
+ */
69
+ export declare function __clearInstanceRegistry(): void;
70
+ export declare function hasRequestScope(): boolean;
71
+ /** Pending client-invalidation paths for the current request, if any. */
72
+ export declare function requestPendingInvalidations(): Set<string> | undefined;
73
+ /** Runs `fn` inside a fresh request scope bound to `instance`. */
74
+ export declare function runWithInstanceScope<T>(instance: FurinInstance, fn: () => T): T;
75
+ /**
76
+ * Runs `fn` bound to `instance` for synthetic (non-request) work — SSG cache
77
+ * warming, background ISR revalidation kicked off outside a live request.
78
+ */
79
+ export declare function withInstance<T>(instance: FurinInstance, fn: () => T): T;
80
+ /**
81
+ * Declares a lazily-initialized per-instance state slot. Returns an accessor
82
+ * that resolves against the current instance (or an explicit one). This is
83
+ * how state modules attach caches/registries to instances without this module
84
+ * importing them (avoids import cycles).
85
+ */
86
+ export declare function instanceSlot<T>(init: (instance: FurinInstance) => T): (instance?: FurinInstance) => T;
@@ -12,6 +12,8 @@ export interface CompileContext {
12
12
  buildId?: string;
13
13
  embedded?: EmbeddedAppData;
14
14
  modules: Record<string, unknown>;
15
+ /** Mount prefix this app was built for (`""` = root). */
16
+ prefix?: string;
15
17
  /** Root-level conventions discovered at compile time. */
16
18
  rootConventions?: {
17
19
  errorPath?: string;
@@ -31,5 +33,18 @@ export interface CompileContext {
31
33
  ssgCache?: Record<string, SsgCacheEntry>;
32
34
  }
33
35
  export declare function __setCompileContext(ctx: CompileContext): void;
34
- export declare function getCompileContext(): CompileContext | null;
36
+ /**
37
+ * Looks up the compile context for a (pagesDir, prefix) mount. Resolution
38
+ * order, from most to least specific:
39
+ * 1. exact (pagesDir, prefix) key — distinguishes the same app mounted twice;
40
+ * 2. sole context registered for `pagesDir` — callers that don't pass a
41
+ * prefix, and contexts emitted before the prefix field existed;
42
+ * 3. sole context registered for `prefix` — deployed binaries run from a
43
+ * different cwd than the build, so the absolute pagesDir key misses there,
44
+ * but the mount prefix is stable across machines;
45
+ * 4. the sole registered context (single-app back-compat).
46
+ */
47
+ export declare function getCompileContext(pagesDir?: string, prefix?: string): CompileContext | null;
48
+ /** All registered contexts, keyed by the composite (pagesDir, prefix) key. */
49
+ export declare function getAllCompileContexts(): ReadonlyMap<string, CompileContext>;
35
50
  export declare function __resetCompileContext(): void;
@@ -1,17 +1,84 @@
1
1
  // @bun
2
+ // src/server/instance.ts
3
+ import { AsyncLocalStorage } from "async_hooks";
4
+ var _requestScope = new AsyncLocalStorage;
5
+ var _instances = new Map;
6
+ function __clearInstanceRegistry() {
7
+ _instances.clear();
8
+ }
9
+
2
10
  // src/server/internal.ts
3
- var _compileCtx = null;
11
+ var _compileContexts = new Map;
12
+ function normalizeContextKey(path) {
13
+ return path.replaceAll("\\", "/");
14
+ }
15
+ function pagesDirOf(ctx) {
16
+ const rootPath = normalizeContextKey(ctx.rootPath);
17
+ const lastSlash = rootPath.lastIndexOf("/");
18
+ return lastSlash === -1 ? rootPath : rootPath.slice(0, lastSlash);
19
+ }
20
+ function contextKey(pagesDir, prefix) {
21
+ return `${pagesDir}\x00${prefix}`;
22
+ }
4
23
  function __setCompileContext(ctx) {
5
- _compileCtx = ctx;
24
+ _compileContexts.set(contextKey(pagesDirOf(ctx), ctx.prefix ?? ""), ctx);
25
+ }
26
+ function getCompileContext(pagesDir, prefix) {
27
+ if (pagesDir !== undefined) {
28
+ const dir = normalizeContextKey(pagesDir);
29
+ if (prefix !== undefined) {
30
+ const exact = _compileContexts.get(contextKey(dir, prefix));
31
+ if (exact) {
32
+ return exact;
33
+ }
34
+ }
35
+ const dirMatch = soleContextForPagesDir(dir);
36
+ if (dirMatch) {
37
+ return dirMatch;
38
+ }
39
+ }
40
+ if (prefix !== undefined) {
41
+ const prefixMatch = contextForPrefix(prefix);
42
+ if (prefixMatch) {
43
+ return prefixMatch;
44
+ }
45
+ }
46
+ if (_compileContexts.size === 1) {
47
+ return _compileContexts.values().next().value ?? null;
48
+ }
49
+ return null;
50
+ }
51
+ function soleContextForPagesDir(dir) {
52
+ let match = null;
53
+ for (const ctx of _compileContexts.values()) {
54
+ if (pagesDirOf(ctx) !== dir) {
55
+ continue;
56
+ }
57
+ if (match) {
58
+ return null;
59
+ }
60
+ match = ctx;
61
+ }
62
+ return match;
63
+ }
64
+ function contextForPrefix(prefix) {
65
+ for (const ctx of _compileContexts.values()) {
66
+ if ((ctx.prefix ?? "") === prefix) {
67
+ return ctx;
68
+ }
69
+ }
70
+ return null;
6
71
  }
7
- function getCompileContext() {
8
- return _compileCtx;
72
+ function getAllCompileContexts() {
73
+ return _compileContexts;
9
74
  }
10
75
  function __resetCompileContext() {
11
- _compileCtx = null;
76
+ _compileContexts.clear();
77
+ __clearInstanceRegistry();
12
78
  }
13
79
  export {
14
80
  getCompileContext,
81
+ getAllCompileContexts,
15
82
  __setCompileContext,
16
83
  __resetCompileContext
17
84
  };
@@ -1,6 +1,7 @@
1
+ import { type FurinInstance } from "../instance.ts";
1
2
  export declare function getDevTemplate(origin: string): Promise<string>;
2
- export declare function setProductionTemplatePath(path: string | null): void;
3
- export declare function setProductionTemplateContent(content: string): void;
3
+ export declare function setProductionTemplatePath(path: string | null, instance?: FurinInstance): void;
4
+ export declare function setProductionTemplateContent(content: string, instance?: FurinInstance): void;
4
5
  export declare function getProductionTemplate(): string | null;
5
6
  /** @internal test-only — resets all template state */
6
7
  export declare function __resetTemplateState(): void;
@@ -0,0 +1,62 @@
1
+ export interface StoredResponse {
2
+ body: Uint8Array;
3
+ headers: ReadonlyArray<readonly [string, string]>;
4
+ status: number;
5
+ }
6
+ export interface BeginMutationInput {
7
+ fingerprint: string;
8
+ key: string;
9
+ principal: string;
10
+ }
11
+ export type BeginMutationResult = {
12
+ kind: "execute";
13
+ mutationId: string;
14
+ } | {
15
+ kind: "replay";
16
+ response: StoredResponse;
17
+ } | {
18
+ kind: "conflict";
19
+ reason: "in-progress" | "payload-mismatch";
20
+ } | {
21
+ kind: "unavailable";
22
+ };
23
+ export interface CommitMutationInput {
24
+ mutationId: string;
25
+ response: StoredResponse;
26
+ }
27
+ export interface AbortMutationInput {
28
+ mutationId: string;
29
+ }
30
+ export interface SyncChange {
31
+ cursor: string;
32
+ invalidations: readonly string[];
33
+ }
34
+ export interface AppendChangesInput {
35
+ invalidations: readonly string[];
36
+ path: string;
37
+ }
38
+ export interface AppendChangesResult {
39
+ change: SyncChange;
40
+ }
41
+ export interface ReadChangesInput {
42
+ after: string | undefined;
43
+ limit: number;
44
+ path: string;
45
+ }
46
+ export interface ChangePage {
47
+ changes: readonly SyncChange[];
48
+ cursor: string;
49
+ hasMore: boolean;
50
+ reset: boolean;
51
+ }
52
+ export type SyncChangeListener = (change: SyncChange) => void;
53
+ type MaybePromise<T> = Promise<T> | T;
54
+ export interface SyncAdapter {
55
+ abortMutation(input: AbortMutationInput): MaybePromise<void>;
56
+ appendChanges(input: AppendChangesInput): MaybePromise<AppendChangesResult>;
57
+ beginMutation(input: BeginMutationInput): MaybePromise<BeginMutationResult>;
58
+ commitMutation(input: CommitMutationInput): MaybePromise<void>;
59
+ readChanges(input: ReadChangesInput): MaybePromise<ChangePage>;
60
+ subscribe(path: string, listener: SyncChangeListener): () => void;
61
+ }
62
+ export {};
@@ -2,5 +2,16 @@ export type FurinSyncOption = boolean | {
2
2
  streamPath?: string;
3
3
  };
4
4
  export declare function resolveSyncStreamPath(sync: FurinSyncOption | undefined): string | undefined;
5
+ /**
6
+ * Logical (unprefixed) sync stream path for the current request — injected
7
+ * into rendered HTML; the client prepends its own basePath before connecting.
8
+ */
5
9
  export declare function getSyncStreamPath(): string | undefined;
6
10
  export declare function runWithSyncStreamPath<T>(path: string | undefined, fn: () => T): T;
11
+ /**
12
+ * Physical adapter channels a sync publication must reach. An explicit
13
+ * override wins (historical single-channel behaviour); otherwise every
14
+ * sync-enabled instance gets notified — a mutation on a shared API must wake
15
+ * the SSE clients of every mounted app.
16
+ */
17
+ export declare function syncPublishChannels(): string[];
@@ -0,0 +1,6 @@
1
+ interface FingerprintInput {
2
+ body: unknown;
3
+ request: Request;
4
+ }
5
+ export declare function createMutationFingerprint(input: FingerprintInput): Promise<string>;
6
+ export {};
@@ -1,4 +1,4 @@
1
1
  export type { FurinSyncOption } from "./config.ts";
2
2
  export { getSyncStreamPath, resolveSyncStreamPath, runWithSyncStreamPath, } from "./config.ts";
3
- export { furinSync, type SyncInput } from "./plugin.ts";
4
- export { __resetSyncState, createSyncStreamPlugin, publishSyncInvalidation, type SyncInvalidationEvent, } from "./stream.ts";
3
+ export { furinSync, type SyncInput, type SyncRouteOption } from "./plugin.ts";
4
+ export { __resetSyncState, createSyncStreamPlugin, publishSyncInvalidation, type SyncChange, type SyncChangePage, } from "./stream.ts";
@@ -0,0 +1,17 @@
1
+ import type { AbortMutationInput, AppendChangesInput, AppendChangesResult, BeginMutationInput, BeginMutationResult, ChangePage, CommitMutationInput, ReadChangesInput, SyncAdapter, SyncChangeListener } from "./adapter.ts";
2
+ export declare class MemorySyncAdapter implements SyncAdapter {
3
+ private readonly changes;
4
+ private readonly mutationKeys;
5
+ private readonly mutations;
6
+ beginMutation(input: BeginMutationInput): BeginMutationResult;
7
+ commitMutation(input: CommitMutationInput): void;
8
+ abortMutation(input: AbortMutationInput): void;
9
+ appendChanges(input: AppendChangesInput): AppendChangesResult;
10
+ readChanges(input: ReadChangesInput): ChangePage;
11
+ subscribe(path: string, listener: SyncChangeListener): () => void;
12
+ reset(): void;
13
+ private evictMutations;
14
+ private deleteMutation;
15
+ private getChangeState;
16
+ }
17
+ export declare const memorySyncAdapter: MemorySyncAdapter;