@velajs/vela 1.17.0 → 1.17.1

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.
@@ -1,7 +1,7 @@
1
1
  export { LiveModule } from './live.module';
2
2
  export { LiveResolver, LiveQuery, getLiveQueries } from './live.decorators';
3
3
  export { LiveEngine, LIVE_SUBS_DATA_KEY, readPersistedLiveSubscriptions } from './live.engine';
4
- export { LiveInvalidation, localLive, stampCommitHeaders } from './live.invalidation';
4
+ export { LiveInvalidation, localLive, perAppLiveDriver, stampCommitHeaders } from './live.invalidation';
5
5
  export { InMemoryCursorLog } from './live.cursor';
6
6
  export { encodeSubscriptionUpdate } from './live.delta';
7
7
  export { PresenceService, PresenceResolver, presenceTag, PRESENCE_ROSTER_QUERY } from './presence';
@@ -6,7 +6,7 @@
6
6
  export { LiveModule } from "./live.module.js";
7
7
  export { LiveResolver, LiveQuery, getLiveQueries } from "./live.decorators.js";
8
8
  export { LiveEngine, LIVE_SUBS_DATA_KEY, readPersistedLiveSubscriptions } from "./live.engine.js";
9
- export { LiveInvalidation, localLive, stampCommitHeaders } from "./live.invalidation.js";
9
+ export { LiveInvalidation, localLive, perAppLiveDriver, stampCommitHeaders } from "./live.invalidation.js";
10
10
  export { InMemoryCursorLog } from "./live.cursor.js";
11
11
  export { encodeSubscriptionUpdate } from "./live.delta.js";
12
12
  export { PresenceService, PresenceResolver, presenceTag, PRESENCE_ROSTER_QUERY } from "./presence.js";
@@ -1,6 +1,24 @@
1
1
  import type { CommitStamp, InvalidationCommand, LiveDriver } from './live.types';
2
2
  /** Single-scope default driver: deliver straight to this process's engine. */
3
3
  export declare function localLive(): LiveDriver;
4
+ /**
5
+ * Per-app wrapper around a (possibly SHARED) driver instance.
6
+ *
7
+ * A driver passed to `LiveModule.forRoot({ driver })` is a plain config object
8
+ * — and on Cloudflare the SAME app module (thus the same driver object)
9
+ * bootstraps in the Worker isolate AND inside each Durable Object, often
10
+ * within one isolate. Mutable per-app state must therefore never live on the
11
+ * driver itself: the DO flipping a shared `durableObjectLive()` into local
12
+ * mode would otherwise poison the Worker's engine, which then executes the
13
+ * DO's storage handle in the wrong request context ("Cannot perform I/O on
14
+ * behalf of a different request").
15
+ *
16
+ * The wrapper owns the per-app sink and the per-app local-mode flag; isolate-
17
+ * wide concerns (env capture) forward to the underlying driver. Platform init
18
+ * hooks (`_setLocalMode`, `_initializeEnv`) are exposed pass-through so
19
+ * platform packages can keep type-guarding on their presence.
20
+ */
21
+ export declare function perAppLiveDriver(underlying: LiveDriver): LiveDriver;
4
22
  /**
5
23
  * The injectable invalidation surface for custom (non-CRUD) write paths:
6
24
  *
@@ -12,6 +12,49 @@ import { getContext } from "hono/context-storage";
12
12
  }
13
13
  };
14
14
  }
15
+ /**
16
+ * Per-app wrapper around a (possibly SHARED) driver instance.
17
+ *
18
+ * A driver passed to `LiveModule.forRoot({ driver })` is a plain config object
19
+ * — and on Cloudflare the SAME app module (thus the same driver object)
20
+ * bootstraps in the Worker isolate AND inside each Durable Object, often
21
+ * within one isolate. Mutable per-app state must therefore never live on the
22
+ * driver itself: the DO flipping a shared `durableObjectLive()` into local
23
+ * mode would otherwise poison the Worker's engine, which then executes the
24
+ * DO's storage handle in the wrong request context ("Cannot perform I/O on
25
+ * behalf of a different request").
26
+ *
27
+ * The wrapper owns the per-app sink and the per-app local-mode flag; isolate-
28
+ * wide concerns (env capture) forward to the underlying driver. Platform init
29
+ * hooks (`_setLocalMode`, `_initializeEnv`) are exposed pass-through so
30
+ * platform packages can keep type-guarding on their presence.
31
+ */ export function perAppLiveDriver(underlying) {
32
+ let ownSink;
33
+ let localMode = false;
34
+ const cfHooks = underlying;
35
+ return {
36
+ get kind () {
37
+ return underlying.kind;
38
+ },
39
+ bind (sink) {
40
+ ownSink = sink;
41
+ underlying.bind(sink);
42
+ },
43
+ dispatch (cmd) {
44
+ if (localMode && ownSink) return ownSink.applyInvalidation(cmd);
45
+ return underlying.dispatch(cmd);
46
+ },
47
+ start: underlying.start ? ()=>underlying.start?.() : undefined,
48
+ stop: underlying.stop ? ()=>underlying.stop?.() : undefined,
49
+ // Platform hooks (Cloudflare): local mode is PER APP; env is per isolate.
50
+ _setLocalMode () {
51
+ localMode = true;
52
+ },
53
+ _initializeEnv (env) {
54
+ cfHooks._initializeEnv?.(env);
55
+ }
56
+ };
57
+ }
15
58
  /**
16
59
  * The injectable invalidation surface for custom (non-CRUD) write paths:
17
60
  *
@@ -1,7 +1,7 @@
1
1
  import { defineModule } from "../index.js";
2
2
  import { InMemoryCursorLog } from "./live.cursor.js";
3
3
  import { LiveEngine } from "./live.engine.js";
4
- import { LiveInvalidation, localLive } from "./live.invalidation.js";
4
+ import { LiveInvalidation, localLive, perAppLiveDriver } from "./live.invalidation.js";
5
5
  import { LIVE_CURSOR_LOG, LIVE_DRIVER, LIVE_MODULE_OPTIONS } from "./live.tokens.js";
6
6
  import { PresenceResolver, PresenceService } from "./presence.js";
7
7
  /**
@@ -39,7 +39,11 @@ import { PresenceResolver, PresenceService } from "./presence.js";
39
39
  },
40
40
  {
41
41
  provide: LIVE_DRIVER,
42
- useFactory: (o)=>o.driver ?? localLive(),
42
+ // Wrapped per app: user-supplied drivers are shared config objects
43
+ // (the same module bootstraps in the Worker AND in each Durable
44
+ // Object), so per-app sink/mode state lives in the wrapper — see
45
+ // perAppLiveDriver.
46
+ useFactory: (o)=>perAppLiveDriver(o.driver ?? localLive()),
43
47
  inject: [
44
48
  OPTIONS
45
49
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/vela",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "NestJS-compatible framework for edge runtimes, powered by Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",