@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.
Files changed (143) hide show
  1. package/README.md +37 -0
  2. package/dist/adapter/bun/app.d.ts +1 -0
  3. package/dist/adapter/bun.d.ts +3 -1
  4. package/dist/adapter/runtime-build.d.ts +8 -5
  5. package/dist/adapter/vercel.js +8 -8
  6. package/dist/build/client.d.ts +2 -2
  7. package/dist/build/discover-mounts-process.d.ts +1 -1
  8. package/dist/build/discover-pages-process.d.ts +1 -0
  9. package/dist/build/discover-pages.d.ts +11 -0
  10. package/dist/build/discovery-module.d.ts +3 -0
  11. package/dist/build/discovery-plugins.d.ts +34 -0
  12. package/dist/build/elysia-aot.d.ts +1 -1
  13. package/dist/build/entry-template.ts +6 -1
  14. package/dist/build/hydrate.d.ts +3 -2
  15. package/dist/build/index.js +7688 -8458
  16. package/dist/build/preload-manifest.d.ts +2 -2
  17. package/dist/build/route-metadata.d.ts +31 -0
  18. package/dist/build/route-types.d.ts +1 -1
  19. package/dist/build/shared.d.ts +2 -2
  20. package/dist/build/types.d.ts +11 -0
  21. package/dist/cli/dev-worker.d.ts +1 -0
  22. package/dist/cli/dev-worker.ts +123 -0
  23. package/dist/cli/dev.d.ts +1 -0
  24. package/dist/cli/index.js +7811 -8477
  25. package/dist/client/browser-events-runtime.d.ts +2 -2
  26. package/dist/client/browser-events.d.ts +2 -0
  27. package/dist/client/chunks/{client-brdfd773.js → client-rjhxgt64.js} +187 -4
  28. package/dist/client/dev-error-overlay.ts +18 -1
  29. package/dist/client/link.js +110 -156
  30. package/dist/client/query-store.d.ts +5 -0
  31. package/dist/client/router/navigation-controller.d.ts +2 -0
  32. package/dist/client/router/use-fetch-interception.d.ts +1 -1
  33. package/dist/client/router/use-sync-stream.d.ts +1 -1
  34. package/dist/client/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +5 -3
  35. package/dist/client/sync-client.d.ts +74 -0
  36. package/dist/client.d.ts +1 -0
  37. package/dist/client.js +533 -145
  38. package/dist/config.d.ts +6 -1
  39. package/dist/config.js +3 -1
  40. package/dist/define-route.d.ts +3 -3
  41. package/dist/furin.d.ts +2 -1
  42. package/dist/furin.js +1119 -346
  43. package/dist/plugin/index.js +5 -5
  44. package/dist/plugin/route-registry.d.ts +22 -2
  45. package/dist/rsc/build/index.d.ts +4 -3
  46. package/dist/server/dev/server-only-module.d.ts +5 -0
  47. package/dist/server/internal.js +201 -91
  48. package/dist/server/logging/ingest-plugin.d.ts +1 -2
  49. package/dist/server/production-server.js +36 -33
  50. package/dist/server/server-entry.d.ts +5 -0
  51. package/dist/server/server-entry.js +36 -0
  52. package/dist/server/static-export.js +201 -91
  53. package/dist/server/sync/adapter.d.ts +4 -3
  54. package/dist/server/sync/config.d.ts +7 -0
  55. package/dist/server/sync/connection.d.ts +13 -0
  56. package/dist/server/sync/drizzle/index.js +5 -4
  57. package/dist/server/sync/index.d.ts +3 -0
  58. package/dist/server/sync/index.js +1361 -243
  59. package/dist/server/sync/invalidate-sync.d.ts +6 -2
  60. package/dist/server/sync/local-client.d.ts +9 -0
  61. package/dist/server/sync/postgres/index.d.ts +1 -1
  62. package/dist/server/sync/postgres/index.js +2 -2
  63. package/dist/server/sync/prisma/index.js +2 -2
  64. package/dist/server/sync/redis/index.d.ts +1 -1
  65. package/dist/server/sync/redis/index.js +4 -3
  66. package/dist/server/sync/redis/scripts.d.ts +1 -1
  67. package/dist/server/sync/runtime.d.ts +3 -0
  68. package/dist/server/sync/sqlite/index.d.ts +1 -1
  69. package/dist/server/sync/sqlite/index.js +3 -2
  70. package/dist/shared/browser-events.d.ts +4 -0
  71. package/dist/sync-client.d.ts +3 -0
  72. package/dist/sync-client.js +1600 -0
  73. package/package.json +12 -7
  74. package/src/adapter/README.md +7 -0
  75. package/src/adapter/build.ts +34 -33
  76. package/src/adapter/bun/app.ts +5 -0
  77. package/src/adapter/bun/server.ts +2 -2
  78. package/src/adapter/bun.ts +18 -2
  79. package/src/adapter/furin-app.d.ts +1 -0
  80. package/src/adapter/package.ts +1 -0
  81. package/src/adapter/runtime-build.ts +18 -12
  82. package/src/adapter/static.ts +17 -13
  83. package/src/build/client.ts +7 -5
  84. package/src/build/discover-mounts-process.ts +5 -1
  85. package/src/build/discover-pages-process.ts +151 -0
  86. package/src/build/discover-pages.ts +69 -0
  87. package/src/build/discovery-module.ts +70 -0
  88. package/src/build/discovery-plugins.ts +101 -0
  89. package/src/build/elysia-aot-worker.ts +9 -8
  90. package/src/build/elysia-aot.ts +110 -75
  91. package/src/build/entry-template.ts +6 -1
  92. package/src/build/hydrate.ts +11 -8
  93. package/src/build/index.ts +6 -50
  94. package/src/build/preload-manifest.ts +3 -3
  95. package/src/build/route-metadata.ts +90 -0
  96. package/src/build/route-types.ts +1 -1
  97. package/src/build/shared.ts +6 -8
  98. package/src/build/types.ts +9 -0
  99. package/src/cli/config.ts +4 -0
  100. package/src/cli/dev-worker.ts +123 -0
  101. package/src/cli/dev.ts +91 -0
  102. package/src/cli/index.ts +24 -1
  103. package/src/client/browser-events-runtime.ts +97 -23
  104. package/src/client/browser-events.ts +8 -0
  105. package/src/client/dev-error-overlay.ts +18 -1
  106. package/src/client/query-store.ts +54 -3
  107. package/src/client/router/navigation-controller.ts +45 -12
  108. package/src/client/router/provider.tsx +6 -2
  109. package/src/client/router/use-fetch-interception.ts +1 -1
  110. package/src/client/router/use-sync-stream.ts +96 -44
  111. package/src/client/{router/sync-catch-up.ts → sync-catch-up.ts} +28 -12
  112. package/src/client/sync-client.ts +528 -0
  113. package/src/client/sync.ts +11 -4
  114. package/src/client.ts +10 -0
  115. package/src/config.ts +17 -10
  116. package/src/furin.ts +5 -0
  117. package/src/plugin/route-registry.ts +53 -7
  118. package/src/rsc/build/index.ts +6 -3
  119. package/src/server/browser-events/plugin.ts +79 -25
  120. package/src/server/dev/rewrite-module-specifiers.ts +2 -1
  121. package/src/server/dev/server-only-module.ts +23 -0
  122. package/src/server/dev/symbolicate.ts +4 -3
  123. package/src/server/dev-page-imports.ts +3 -1
  124. package/src/server/dev-page-plugin.ts +18 -1
  125. package/src/server/logging/ingest-plugin.ts +3 -9
  126. package/src/server/server-entry.ts +39 -0
  127. package/src/server/sync/adapter.ts +7 -3
  128. package/src/server/sync/config.ts +12 -6
  129. package/src/server/sync/connection.ts +71 -0
  130. package/src/server/sync/index.ts +3 -0
  131. package/src/server/sync/invalidate-sync.ts +30 -5
  132. package/src/server/sync/local-client.ts +84 -0
  133. package/src/server/sync/plugin.ts +27 -20
  134. package/src/server/sync/postgres/index.ts +9 -2
  135. package/src/server/sync/redis/index.ts +5 -1
  136. package/src/server/sync/redis/scripts.ts +1 -1
  137. package/src/server/sync/runtime.ts +56 -18
  138. package/src/server/sync/sqlite/index.ts +6 -2
  139. package/src/server/sync/stream.ts +17 -5
  140. package/src/shared/browser-events.ts +1 -1
  141. package/src/sync-client.ts +14 -0
  142. package/dist/server/logger.d.ts +0 -10
  143. 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>>): Promise<void>;
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
- return this.database.transaction(() => this.appendChangeSync(invalidations, null)).immediate();
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();
@@ -13,6 +13,10 @@ export type BrowserEventEnvelope = {
13
13
  channel: "sync";
14
14
  data: {
15
15
  cursor: string;
16
+ context?: never;
17
+ } | {
18
+ context: "changed";
19
+ cursor?: never;
16
20
  };
17
21
  version: typeof BROWSER_EVENT_PROTOCOL_VERSION;
18
22
  };
@@ -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";