@teyik0/furin 0.8.0-alpha.0 → 0.9.0-alpha.0
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/README.md +37 -0
- package/dist/adapter/bun/app.d.ts +1 -0
- package/dist/adapter/bun.d.ts +3 -1
- package/dist/adapter/runtime-build.d.ts +8 -5
- package/dist/adapter/vercel.js +8 -8
- package/dist/build/client.d.ts +2 -2
- package/dist/build/discover-mounts-process.d.ts +1 -1
- package/dist/build/discover-pages-process.d.ts +1 -0
- package/dist/build/discover-pages.d.ts +11 -0
- package/dist/build/discovery-module.d.ts +3 -0
- package/dist/build/discovery-plugins.d.ts +34 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.ts +6 -1
- package/dist/build/hydrate.d.ts +3 -2
- package/dist/build/index.js +7688 -8458
- package/dist/build/preload-manifest.d.ts +2 -2
- package/dist/build/route-metadata.d.ts +31 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/shared.d.ts +2 -2
- package/dist/build/types.d.ts +11 -0
- package/dist/cli/dev-worker.d.ts +1 -0
- package/dist/cli/dev-worker.ts +123 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/index.js +7811 -8477
- package/dist/client/browser-events-runtime.d.ts +2 -2
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/chunks/{client-brdfd773.js → client-rjhxgt64.js} +187 -4
- package/dist/client/dev-error-overlay.ts +18 -1
- package/dist/client/link.js +110 -156
- package/dist/client/query-store.d.ts +5 -0
- package/dist/client/router/navigation-controller.d.ts +2 -0
- package/dist/client/router/use-fetch-interception.d.ts +1 -1
- package/dist/client/router/use-sync-stream.d.ts +1 -1
- package/dist/client/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +5 -3
- package/dist/client/sync-client.d.ts +74 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +533 -145
- package/dist/config.d.ts +6 -1
- package/dist/config.js +3 -1
- package/dist/define-route.d.ts +3 -3
- package/dist/furin.d.ts +2 -1
- package/dist/furin.js +1119 -346
- package/dist/plugin/index.js +5 -5
- package/dist/plugin/route-registry.d.ts +22 -2
- package/dist/rsc/build/index.d.ts +4 -3
- package/dist/server/dev/server-only-module.d.ts +5 -0
- package/dist/server/internal.js +201 -91
- package/dist/server/logging/ingest-plugin.d.ts +1 -2
- package/dist/server/production-server.js +36 -33
- package/dist/server/server-entry.d.ts +5 -0
- package/dist/server/server-entry.js +36 -0
- package/dist/server/static-export.js +201 -91
- package/dist/server/sync/adapter.d.ts +4 -3
- package/dist/server/sync/config.d.ts +7 -0
- package/dist/server/sync/connection.d.ts +13 -0
- package/dist/server/sync/drizzle/index.js +5 -4
- package/dist/server/sync/index.d.ts +3 -0
- package/dist/server/sync/index.js +1361 -243
- package/dist/server/sync/invalidate-sync.d.ts +6 -2
- package/dist/server/sync/local-client.d.ts +9 -0
- package/dist/server/sync/postgres/index.d.ts +1 -1
- package/dist/server/sync/postgres/index.js +2 -2
- package/dist/server/sync/prisma/index.js +2 -2
- package/dist/server/sync/redis/index.d.ts +1 -1
- package/dist/server/sync/redis/index.js +4 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/runtime.d.ts +3 -0
- package/dist/server/sync/sqlite/index.d.ts +1 -1
- package/dist/server/sync/sqlite/index.js +3 -2
- package/dist/shared/browser-events.d.ts +4 -0
- package/dist/sync-client.d.ts +3 -0
- package/dist/sync-client.js +1600 -0
- package/package.json +12 -7
- package/src/adapter/README.md +7 -0
- package/src/adapter/build.ts +34 -33
- package/src/adapter/bun/app.ts +5 -0
- package/src/adapter/bun/server.ts +2 -2
- package/src/adapter/bun.ts +18 -2
- package/src/adapter/furin-app.d.ts +1 -0
- package/src/adapter/package.ts +1 -0
- package/src/adapter/runtime-build.ts +18 -12
- package/src/adapter/static.ts +17 -13
- package/src/build/client.ts +7 -5
- package/src/build/discover-mounts-process.ts +5 -1
- package/src/build/discover-pages-process.ts +151 -0
- package/src/build/discover-pages.ts +69 -0
- package/src/build/discovery-module.ts +70 -0
- package/src/build/discovery-plugins.ts +101 -0
- package/src/build/elysia-aot-worker.ts +9 -8
- package/src/build/elysia-aot.ts +110 -75
- package/src/build/entry-template.ts +6 -1
- package/src/build/hydrate.ts +11 -8
- package/src/build/index.ts +6 -50
- package/src/build/preload-manifest.ts +3 -3
- package/src/build/route-metadata.ts +90 -0
- package/src/build/route-types.ts +1 -1
- package/src/build/shared.ts +6 -8
- package/src/build/types.ts +9 -0
- package/src/cli/config.ts +4 -0
- package/src/cli/dev-worker.ts +123 -0
- package/src/cli/dev.ts +91 -0
- package/src/cli/index.ts +24 -1
- package/src/client/browser-events-runtime.ts +97 -23
- package/src/client/browser-events.ts +8 -0
- package/src/client/dev-error-overlay.ts +18 -1
- package/src/client/query-store.ts +54 -3
- package/src/client/router/navigation-controller.ts +45 -12
- package/src/client/router/provider.tsx +6 -2
- package/src/client/router/use-fetch-interception.ts +1 -1
- package/src/client/router/use-sync-stream.ts +96 -44
- package/src/client/{router/sync-catch-up.ts → sync-catch-up.ts} +28 -12
- package/src/client/sync-client.ts +528 -0
- package/src/client/sync.ts +11 -4
- package/src/client.ts +10 -0
- package/src/config.ts +17 -10
- package/src/furin.ts +5 -0
- package/src/plugin/route-registry.ts +53 -7
- package/src/rsc/build/index.ts +6 -3
- package/src/server/browser-events/plugin.ts +79 -25
- package/src/server/dev/rewrite-module-specifiers.ts +2 -1
- package/src/server/dev/server-only-module.ts +23 -0
- package/src/server/dev/symbolicate.ts +4 -3
- package/src/server/dev-page-imports.ts +3 -1
- package/src/server/dev-page-plugin.ts +18 -1
- package/src/server/logging/ingest-plugin.ts +3 -9
- package/src/server/server-entry.ts +39 -0
- package/src/server/sync/adapter.ts +7 -3
- package/src/server/sync/config.ts +12 -6
- package/src/server/sync/connection.ts +71 -0
- package/src/server/sync/index.ts +3 -0
- package/src/server/sync/invalidate-sync.ts +30 -5
- package/src/server/sync/local-client.ts +84 -0
- package/src/server/sync/plugin.ts +27 -20
- package/src/server/sync/postgres/index.ts +9 -2
- package/src/server/sync/redis/index.ts +5 -1
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/runtime.ts +56 -18
- package/src/server/sync/sqlite/index.ts +6 -2
- package/src/server/sync/stream.ts +17 -5
- package/src/shared/browser-events.ts +1 -1
- package/src/sync-client.ts +14 -0
- package/dist/server/logger.d.ts +0 -10
- package/src/server/logger.ts +0 -34
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { InvalidationRule } from "../auto-invalidate/types.ts";
|
|
2
2
|
import type { SyncRuntimeOptions } from "./adapter.ts";
|
|
3
3
|
import type { SyncParams, SyncPattern } from "./queries.ts";
|
|
4
|
+
export interface SyncInvalidationOptions {
|
|
5
|
+
/** Verified identity selected by trusted server code, never an untrusted request field. */
|
|
6
|
+
principal: string;
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Invalidates outside a request (cron, webhook) what the handler's `invalidate()` takes — a GET
|
|
6
10
|
* pattern and its params, cache tags or a page path: purges the pages built from it, then
|
|
7
11
|
* journals and broadcasts it through the runtime `sync` configures, as a mutation would.
|
|
8
12
|
*/
|
|
9
|
-
export declare function invalidateSync<Target extends SyncPattern>(sync: SyncRuntimeOptions, pattern: Target, params?: NoInfer<SyncParams<Target
|
|
10
|
-
export declare function invalidateSync(sync: SyncRuntimeOptions, rule: InvalidationRule): Promise<void>;
|
|
13
|
+
export declare function invalidateSync<Target extends SyncPattern>(sync: SyncRuntimeOptions, pattern: Target, params?: NoInfer<SyncParams<Target>>, options?: SyncInvalidationOptions): Promise<void>;
|
|
14
|
+
export declare function invalidateSync(sync: SyncRuntimeOptions, rule: InvalidationRule, options?: SyncInvalidationOptions): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyElysia } from "elysia";
|
|
2
|
+
import { type SyncClient, type SyncClientOptions } from "../../client/sync-client.ts";
|
|
3
|
+
import type { FurinSyncOptions } from "./config.ts";
|
|
4
|
+
export interface LocalSyncClientOptions extends Pick<SyncClientOptions, "headers" | "fetch" | "syncPath"> {
|
|
5
|
+
app: Pick<AnyElysia, "handle">;
|
|
6
|
+
sync: FurinSyncOptions;
|
|
7
|
+
}
|
|
8
|
+
/** Follow treaty(app) queries through the application's own authorized handlers. */
|
|
9
|
+
export declare function createLocalSyncClient(options: LocalSyncClientOptions): SyncClient;
|
|
@@ -22,7 +22,7 @@ export declare class PostgresSyncAdapter implements SyncAdapter {
|
|
|
22
22
|
/** Only used on the native transaction that already holds lockMutation's row lock. */
|
|
23
23
|
completeLockedMutation(input: CompleteMutationInput): Promise<CompleteMutationResult>;
|
|
24
24
|
private completeMutationInTransaction;
|
|
25
|
-
appendInvalidations(invalidations: readonly SyncInvalidation[]): Promise<string>;
|
|
25
|
+
appendInvalidations(invalidations: readonly SyncInvalidation[], principal?: string): Promise<string>;
|
|
26
26
|
private appendChangeInTransaction;
|
|
27
27
|
lockMutation(lease: MutationLease): Promise<boolean>;
|
|
28
28
|
private lockMutationInTransaction;
|
|
@@ -184,9 +184,9 @@ class PostgresSyncAdapter {
|
|
|
184
184
|
return { cursor, kind: "committed" };
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
appendInvalidations(invalidations) {
|
|
187
|
+
appendInvalidations(invalidations, principal) {
|
|
188
188
|
return this.sql.begin(async (tx) => {
|
|
189
|
-
const cursor = await this.appendChangeInTransaction(tx, invalidations, null);
|
|
189
|
+
const cursor = await this.appendChangeInTransaction(tx, invalidations, principal === undefined ? null : principalHash(this, principal));
|
|
190
190
|
if (this.publishesNotifications) {
|
|
191
191
|
await tx.notify(this.notificationChannel, cursor);
|
|
192
192
|
}
|
|
@@ -202,9 +202,9 @@ class PostgresSyncAdapter {
|
|
|
202
202
|
return { cursor, kind: "committed" };
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
appendInvalidations(invalidations) {
|
|
205
|
+
appendInvalidations(invalidations, principal) {
|
|
206
206
|
return this.sql.begin(async (tx) => {
|
|
207
|
-
const cursor = await this.appendChangeInTransaction(tx, invalidations, null);
|
|
207
|
+
const cursor = await this.appendChangeInTransaction(tx, invalidations, principal === undefined ? null : principalHash(this, principal));
|
|
208
208
|
if (this.publishesNotifications) {
|
|
209
209
|
await tx.notify(this.notificationChannel, cursor);
|
|
210
210
|
}
|
|
@@ -12,7 +12,7 @@ export declare class RedisSyncAdapter implements SyncAdapter {
|
|
|
12
12
|
beginMutation(input: BeginMutationInput): Promise<BeginMutationResult>;
|
|
13
13
|
renewMutation(lease: MutationLease): Promise<"lost" | "renewed">;
|
|
14
14
|
completeMutation(input: CompleteMutationInput): Promise<CompleteMutationResult>;
|
|
15
|
-
appendInvalidations(invalidations: readonly SyncInvalidation[]): Promise<string>;
|
|
15
|
+
appendInvalidations(invalidations: readonly SyncInvalidation[], principal?: string): Promise<string>;
|
|
16
16
|
abortMutation(lease: MutationLease): Promise<void>;
|
|
17
17
|
currentCursor(): Promise<string>;
|
|
18
18
|
readChanges(input: ReadChangesInput): Promise<ChangePage>;
|
|
@@ -96,7 +96,7 @@ if length >= tonumber(ARGV[2]) then
|
|
|
96
96
|
local oldest = redis.call('XRANGE', KEYS[1], '-', '+', 'COUNT', 1)
|
|
97
97
|
if oldest[1] then redis.call('SET', KEYS[2], oldest[1][1]) end
|
|
98
98
|
end
|
|
99
|
-
return redis.call('XADD', KEYS[1], 'MAXLEN', '=', ARGV[2], '*', 'data', ARGV[1])
|
|
99
|
+
return redis.call('XADD', KEYS[1], 'MAXLEN', '=', ARGV[2], '*', 'data', ARGV[1], 'principal', ARGV[3])
|
|
100
100
|
`;
|
|
101
101
|
|
|
102
102
|
// src/server/sync/redis/index.ts
|
|
@@ -266,14 +266,15 @@ class RedisSyncAdapter {
|
|
|
266
266
|
const cursor = stringResult(result[1], "complete mutation cursor");
|
|
267
267
|
return cursor.length === 0 ? { cursor: undefined, kind } : { cursor, kind };
|
|
268
268
|
}
|
|
269
|
-
async appendInvalidations(invalidations) {
|
|
269
|
+
async appendInvalidations(invalidations, principal) {
|
|
270
270
|
return stringResult(await this.client.send("EVAL", [
|
|
271
271
|
APPEND_INVALIDATIONS_SCRIPT,
|
|
272
272
|
"2",
|
|
273
273
|
this.streamKey,
|
|
274
274
|
this.trimmedKey,
|
|
275
275
|
JSON.stringify(invalidations),
|
|
276
|
-
String(CHANGE_RETENTION)
|
|
276
|
+
String(CHANGE_RETENTION),
|
|
277
|
+
principal === undefined ? "" : principalHash(this, principal)
|
|
277
278
|
]), "append invalidations cursor");
|
|
278
279
|
}
|
|
279
280
|
async abortMutation(lease) {
|
|
@@ -2,4 +2,4 @@ export declare const BEGIN_MUTATION_SCRIPT = "\nlocal raw = redis.call('GET', KE
|
|
|
2
2
|
export declare const RENEW_MUTATION_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 'lost' end\nlocal value = cjson.decode(raw)\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif value.state ~= 'in-progress' or value.id ~= ARGV[1] or value.leaseUntil <= now then\n return 'lost'\nend\nvalue.leaseUntil = now + tonumber(ARGV[2])\nredis.call('SET', KEYS[1], cjson.encode(value), 'PX', ARGV[3])\nreturn 'renewed'\n";
|
|
3
3
|
export declare const COMPLETE_MUTATION_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return {'lost'} end\nlocal value = cjson.decode(raw)\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif value.state ~= 'in-progress' or value.id ~= ARGV[1] or value.leaseUntil <= now then\n return {'lost'}\nend\nvalue.state = 'succeeded'\nvalue.response = ARGV[2]\nvalue.leaseUntil = nil\nlocal cursor = ''\nif ARGV[3] ~= '[]' then\n local length = redis.call('XLEN', KEYS[2])\n if length >= tonumber(ARGV[5]) then\n local oldest = redis.call('XRANGE', KEYS[2], '-', '+', 'COUNT', 1)\n if oldest[1] then redis.call('SET', KEYS[3], oldest[1][1]) end\n end\n cursor = redis.call('XADD', KEYS[2], 'MAXLEN', '=', ARGV[5], '*', 'data', ARGV[3], 'principal', ARGV[6])\nend\nredis.call('SET', KEYS[1], cjson.encode(value), 'PX', ARGV[4])\nreturn {'committed', cursor}\n";
|
|
4
4
|
export declare const ABORT_MUTATION_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 0 end\nlocal value = cjson.decode(raw)\nif value.state == 'in-progress' and value.id == ARGV[1] then\n return redis.call('DEL', KEYS[1])\nend\nreturn 0\n";
|
|
5
|
-
export declare const APPEND_INVALIDATIONS_SCRIPT = "\nlocal length = redis.call('XLEN', KEYS[1])\nif length >= tonumber(ARGV[2]) then\n local oldest = redis.call('XRANGE', KEYS[1], '-', '+', 'COUNT', 1)\n if oldest[1] then redis.call('SET', KEYS[2], oldest[1][1]) end\nend\nreturn redis.call('XADD', KEYS[1], 'MAXLEN', '=', ARGV[2], '*', 'data', ARGV[1])\n";
|
|
5
|
+
export declare const APPEND_INVALIDATIONS_SCRIPT = "\nlocal length = redis.call('XLEN', KEYS[1])\nif length >= tonumber(ARGV[2]) then\n local oldest = redis.call('XRANGE', KEYS[1], '-', '+', 'COUNT', 1)\n if oldest[1] then redis.call('SET', KEYS[2], oldest[1][1]) end\nend\nreturn redis.call('XADD', KEYS[1], 'MAXLEN', '=', ARGV[2], '*', 'data', ARGV[1], 'principal', ARGV[3])\n";
|
|
@@ -7,4 +7,7 @@ export interface ResolvedSyncRuntime {
|
|
|
7
7
|
}
|
|
8
8
|
/** Wakes subscribers, unless the adapter's commit already notified the notifier's channel. */
|
|
9
9
|
export declare function publishCursor(runtime: ResolvedSyncRuntime, cursor: string): void;
|
|
10
|
+
/** Prepare resources before listening; AOT only installs the same route behaviors. */
|
|
11
|
+
export declare function prepareSyncRuntime(options: SyncRuntimeOptions, development: boolean): void;
|
|
12
|
+
/** Reads a prepared factory adapter; request paths never invoke the factory. */
|
|
10
13
|
export declare function resolveSyncRuntime(options: SyncRuntimeOptions, development: boolean): ResolvedSyncRuntime;
|
|
@@ -14,7 +14,7 @@ export declare class SqliteSyncAdapter implements SyncAdapter {
|
|
|
14
14
|
protected beginMutationSync(input: BeginMutationInput): BeginMutationResult;
|
|
15
15
|
completeMutation(input: CompleteMutationInput): Promise<CompleteMutationResult>;
|
|
16
16
|
protected completeMutationSync(input: CompleteMutationInput): CompleteMutationResult;
|
|
17
|
-
appendInvalidations(invalidations: readonly SyncInvalidation[]): Promise<string>;
|
|
17
|
+
appendInvalidations(invalidations: readonly SyncInvalidation[], principal?: string): Promise<string>;
|
|
18
18
|
private appendChangeSync;
|
|
19
19
|
protected hasMutationLeaseSync(lease: MutationLease): boolean;
|
|
20
20
|
abortMutation(lease: MutationLease): Promise<void>;
|
|
@@ -204,8 +204,9 @@ class SqliteSyncAdapter {
|
|
|
204
204
|
});
|
|
205
205
|
return transaction.immediate(input);
|
|
206
206
|
}
|
|
207
|
-
async appendInvalidations(invalidations) {
|
|
208
|
-
|
|
207
|
+
async appendInvalidations(invalidations, principal) {
|
|
208
|
+
const hash = principal === undefined ? null : principalHash(this, principal);
|
|
209
|
+
return this.database.transaction(() => this.appendChangeSync(invalidations, hash)).immediate();
|
|
209
210
|
}
|
|
210
211
|
appendChangeSync(invalidations, principal) {
|
|
211
212
|
const now = Date.now();
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { LiveQuery } from "./client/query-store.ts";
|
|
2
|
+
export { furinSync } from "./client/sync.ts";
|
|
3
|
+
export { createSyncClient, type SyncClient, SyncClientError, type SyncClientOptions, type SyncConnectionState, type SyncQueryState, type SyncReconnectOptions, type SyncSocket, } from "./client/sync-client.ts";
|