@teyik0/furin 0.2.0-alpha.4 → 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.
- package/dist/adapter/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +88 -83
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +106 -56
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +5 -11
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +36 -18
- package/dist/furin.js +630 -310
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/stream.d.ts +8 -1
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +9 -3
- package/src/build/compile-entry.ts +88 -83
- package/src/build/entry-template.ts +106 -56
- package/src/build/hydrate.ts +4 -2
- package/src/build/index.ts +99 -28
- package/src/build/scan-server.ts +23 -7
- package/src/build/server-routes-entry.ts +5 -11
- package/src/build/ssg-cache.ts +6 -2
- package/src/build/types.ts +37 -1
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/config.ts +14 -1
- package/src/furin.ts +297 -143
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +29 -4
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +16 -4
- package/src/server/render/template.ts +57 -24
- package/src/server/sync/config.ts +32 -1
- package/src/server/sync/plugin.ts +4 -5
- package/src/server/sync/stream.ts +19 -9
- package/src/shared/prefix.ts +38 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Elysia } from "elysia";
|
|
2
2
|
import type { SyncChange } from "./adapter.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { syncPublishChannels } from "./config.ts";
|
|
4
4
|
import { memorySyncAdapter } from "./memory-adapter.ts";
|
|
5
5
|
|
|
6
6
|
export type { ChangePage as SyncChangePage, SyncChange } from "./adapter.ts";
|
|
@@ -72,25 +72,35 @@ export function publishSyncInvalidation(invalidations: readonly string[]): void
|
|
|
72
72
|
if (invalidations.length === 0) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
for (const channel of syncPublishChannels()) {
|
|
76
|
+
memorySyncAdapter.appendChanges({
|
|
77
|
+
invalidations,
|
|
78
|
+
path: channel,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Builds the SSE plugin serving one instance's sync stream. Routes are
|
|
85
|
+
* registered at the logical `path` (the parent instance's Elysia prefix makes
|
|
86
|
+
* them physical); `channel` is the adapter key the stream reads from — pass
|
|
87
|
+
* the PHYSICAL path (`prefix + path`) so two mounted apps never share a
|
|
88
|
+
* cursor sequence.
|
|
89
|
+
*/
|
|
90
|
+
export function createSyncStreamPlugin(path?: string, channel?: string) {
|
|
82
91
|
const streamPath = path ?? defaultStreamPath;
|
|
83
|
-
|
|
92
|
+
const channelKey = channel ?? streamPath;
|
|
93
|
+
return new Elysia({ name: `furin-sync-stream-${channelKey}` })
|
|
84
94
|
.get(`${streamPath}/changes`, ({ request, set }) => {
|
|
85
95
|
set.headers["cache-control"] = "no-store";
|
|
86
96
|
const query = parseChangeQuery(request);
|
|
87
97
|
if ("error" in query) {
|
|
88
98
|
return query.error;
|
|
89
99
|
}
|
|
90
|
-
return memorySyncAdapter.readChanges({ ...query, path:
|
|
100
|
+
return memorySyncAdapter.readChanges({ ...query, path: channelKey });
|
|
91
101
|
})
|
|
92
102
|
.get(streamPath, () => {
|
|
93
|
-
const state = getStreamState(
|
|
103
|
+
const state = getStreamState(channelKey);
|
|
94
104
|
let controllerRef: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
95
105
|
let heartbeat: ReturnType<typeof setInterval> | undefined;
|
|
96
106
|
const stream = new ReadableStream<Uint8Array>({
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Naming helpers shared between the runtime (furin.ts) and the build
|
|
2
|
+
// pipeline (adapter/bun.ts) — both must agree on where a mounted app's
|
|
3
|
+
// client assets live on disk.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* On-disk client dir name for a mounted app: the root instance keeps the
|
|
7
|
+
* historical `client/`, prefixed instances get `client-<slug>/` next to it.
|
|
8
|
+
*/
|
|
9
|
+
export function clientDirNameForPrefix(prefix: string): string {
|
|
10
|
+
return prefix === "" ? "client" : `client-${prefixSlug(prefix)}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Filesystem-safe slug for a mount prefix (`/admin/v2` → `admin-v2`). */
|
|
14
|
+
export function prefixSlug(prefix: string): string {
|
|
15
|
+
return prefix.slice(1).replaceAll("/", "-");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `prefixSlug` is NOT injective: `/a-b` and `/a/b` both slug to `a-b`, so two
|
|
20
|
+
* distinct prefixes can claim the same client dir and silently overwrite each
|
|
21
|
+
* other's build output. A readable injective encoding is ambiguous anyway
|
|
22
|
+
* (escaping `-` as `--` still confuses `/a-/b` with `/a/-b`), so we detect the
|
|
23
|
+
* collision and fail fast instead.
|
|
24
|
+
*/
|
|
25
|
+
export function assertNoPrefixSlugCollisions(prefixes: string[]): void {
|
|
26
|
+
const byDirName = new Map<string, string>();
|
|
27
|
+
for (const prefix of prefixes) {
|
|
28
|
+
const dirName = clientDirNameForPrefix(prefix);
|
|
29
|
+
const existing = byDirName.get(dirName);
|
|
30
|
+
if (existing !== undefined && existing !== prefix) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`[furin] prefixes "${existing}" and "${prefix}" both map to the client directory ` +
|
|
33
|
+
`"${dirName}" — rename one of them so their slugs (\`/\` → \`-\`) no longer collide.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
byDirName.set(dirName, prefix);
|
|
37
|
+
}
|
|
38
|
+
}
|