@livestore/adapter-cloudflare 0.0.0-snapshot-c658b3579bb6ec902811ddff9d6358f98b809075 → 0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2
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,14 +1,12 @@
|
|
|
1
|
+
import type { HelperTypes } from '@livestore/common-cf';
|
|
1
2
|
import { type LiveStoreSchema } from '@livestore/livestore';
|
|
2
3
|
import type * as CfSyncBackend from '@livestore/sync-cf/cf-worker';
|
|
3
4
|
import { Effect } from '@livestore/utils/effect';
|
|
4
5
|
import type * as CfWorker from './cf-types.ts';
|
|
5
6
|
export type Env = {
|
|
6
|
-
SYNC_BACKEND_DO: CfWorker.DurableObjectNamespace
|
|
7
|
+
SYNC_BACKEND_DO: CfWorker.DurableObjectNamespace<CfSyncBackend.SyncBackendRpcInterface>;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
* Options used to initialize the LiveStore Durable Object runtime.
|
|
10
|
-
*/
|
|
11
|
-
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = {
|
|
9
|
+
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState> = {
|
|
12
10
|
/** LiveStore schema that defines state, migrations, and validators. */
|
|
13
11
|
schema: TSchema;
|
|
14
12
|
/** Logical identifier for the store instance persisted inside the Durable Object. */
|
|
@@ -17,22 +15,22 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSche
|
|
|
17
15
|
clientId: string;
|
|
18
16
|
/** Identifier for the LiveStore session running inside the Durable Object. */
|
|
19
17
|
sessionId: string;
|
|
20
|
-
/**
|
|
21
|
-
|
|
18
|
+
/** Runtime details about the Durable Object this store runs inside. Needed for sync backend to call back to this instance. */
|
|
19
|
+
durableObject: {
|
|
20
|
+
/** Durable Object state handle (e.g. `this.ctx`). */
|
|
21
|
+
ctx: TState;
|
|
22
|
+
/** Environment bindings associated with the Durable Object. */
|
|
23
|
+
env: TEnv;
|
|
24
|
+
/** Binding name Cloudflare uses to reach this Durable Object from other workers. */
|
|
25
|
+
bindingName: HelperTypes.ExtractDurableObjectKeys<NoInfer<TEnv>>;
|
|
26
|
+
};
|
|
22
27
|
/** RPC stub pointing at the sync backend Durable Object used for replication. */
|
|
23
|
-
|
|
28
|
+
syncBackendStub: CfWorker.DurableObjectStub<CfSyncBackend.SyncBackendRpcInterface>;
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
30
|
+
* Enables live pull mode to receive sync updates via Durable Object RPC callbacks.
|
|
26
31
|
*
|
|
27
|
-
* @
|
|
28
|
-
* ```ts
|
|
29
|
-
* const durableObjectId = this.state.id.toString()
|
|
30
|
-
* ```
|
|
32
|
+
* @default false
|
|
31
33
|
*/
|
|
32
|
-
durableObjectId: string;
|
|
33
|
-
/** Binding name Cloudflare uses to reach this Durable Object from other workers. */
|
|
34
|
-
bindingName: string;
|
|
35
|
-
/** Enables live pull mode to receive sync updates via Durable Object RPC callbacks. */
|
|
36
34
|
livePull?: boolean;
|
|
37
35
|
/**
|
|
38
36
|
* Clears existing Durable Object persistence before bootstrapping the store.
|
|
@@ -41,6 +39,6 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSche
|
|
|
41
39
|
*/
|
|
42
40
|
resetPersistence?: boolean;
|
|
43
41
|
};
|
|
44
|
-
export declare const createStoreDo: <TSchema extends LiveStoreSchema =
|
|
45
|
-
export declare const createStoreDoPromise: <TSchema extends LiveStoreSchema =
|
|
42
|
+
export declare const createStoreDo: <TSchema extends LiveStoreSchema, TEnv, TState extends CfWorker.DurableObjectState = CfWorker.DurableObjectState>({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull, resetPersistence, }: CreateStoreDoOptions<TSchema, TEnv, TState>) => Effect.Effect<import("@livestore/livestore").Store<TSchema, {}>, import("@livestore/common").UnexpectedError, never>;
|
|
43
|
+
export declare const createStoreDoPromise: <TSchema extends LiveStoreSchema, TEnv, TState extends CfWorker.DurableObjectState = CfWorker.DurableObjectState>(options: CreateStoreDoOptions<TSchema, TEnv, TState>) => Promise<import("@livestore/livestore").Store<TSchema, {}>>;
|
|
46
44
|
//# sourceMappingURL=create-store-do.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-store-do.d.ts","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,eAAe,EAAe,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,KAAK,aAAa,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,MAAM,EAA2B,MAAM,yBAAyB,CAAA;AACzE,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAG9C,MAAM,MAAM,GAAG,GAAG;IAChB,eAAe,EAAE,QAAQ,CAAC,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"create-store-do.d.ts","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAe,KAAK,eAAe,EAAe,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,KAAK,aAAa,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,MAAM,EAA2B,MAAM,yBAAyB,CAAA;AACzE,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAG9C,MAAM,MAAM,GAAG,GAAG;IAChB,eAAe,EAAE,QAAQ,CAAC,sBAAsB,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAA;CACxF,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,eAAe,EAAE,IAAI,EAAE,MAAM,IAAI;IAChF,uEAAuE;IACvE,MAAM,EAAE,OAAO,CAAA;IACf,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAA;IACf,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAA;IAChB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;IACjB,8HAA8H;IAC9H,aAAa,EAAE;QACb,qDAAqD;QACrD,GAAG,EAAE,MAAM,CAAA;QACX,+DAA+D;QAC/D,GAAG,EAAE,IAAI,CAAA;QACT,oFAAoF;QACpF,WAAW,EAAE,WAAW,CAAC,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;KACjE,CAAA;IACD,iFAAiF;IACjF,eAAe,EAAE,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAA;IAClF;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAGD,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,QAAQ,CAAC,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB,EACxE,uGASC,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,yHAuB1C,CAAA;AAEJ,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,QAAQ,CAAC,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB,EAExE,SAAS,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,+DAOnD,CAAA"}
|
package/dist/create-store-do.js
CHANGED
|
@@ -2,7 +2,11 @@ import { createStore, provideOtel } from '@livestore/livestore';
|
|
|
2
2
|
import { makeDoRpcSync } from '@livestore/sync-cf/client';
|
|
3
3
|
import { Effect, Logger, LogLevel, Scope } from '@livestore/utils/effect';
|
|
4
4
|
import { makeAdapter } from "./make-adapter.js";
|
|
5
|
-
|
|
5
|
+
// TODO Also support in Cloudflare workers outside of a durable object context.
|
|
6
|
+
export const createStoreDo = ({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull = false, resetPersistence = false, }) => Effect.gen(function* () {
|
|
7
|
+
const { ctx, bindingName } = durableObject;
|
|
8
|
+
const storage = ctx.storage;
|
|
9
|
+
const durableObjectId = ctx.id.toString();
|
|
6
10
|
const scope = yield* Scope.make();
|
|
7
11
|
const adapter = makeAdapter({
|
|
8
12
|
clientId,
|
|
@@ -11,7 +15,7 @@ export const createStoreDo = ({ schema, storeId, clientId, sessionId, storage, s
|
|
|
11
15
|
resetPersistence,
|
|
12
16
|
syncOptions: {
|
|
13
17
|
backend: makeDoRpcSync({
|
|
14
|
-
syncBackendStub
|
|
18
|
+
syncBackendStub,
|
|
15
19
|
durableObjectContext: { bindingName, durableObjectId },
|
|
16
20
|
}),
|
|
17
21
|
livePull, // Uses DO RPC callbacks for reactive pull
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-store-do.js","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-store-do.js","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAwB,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAErF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAwC/C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAI3B,EACA,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,GAAG,KAAK,EAChB,gBAAgB,GAAG,KAAK,GACoB,EAAE,EAAE,CAChD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,aAAa,CAAA;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
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./src/polyfill.ts",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@cloudflare/workers-types": "4.20250923.0",
|
|
15
|
-
"@livestore/common": "0.0.0-snapshot-
|
|
16
|
-
"@livestore/common-cf": "0.0.0-snapshot-
|
|
17
|
-
"@livestore/livestore": "0.0.0-snapshot-
|
|
18
|
-
"@livestore/sqlite-wasm": "0.0.0-snapshot-
|
|
19
|
-
"@livestore/sync-cf": "0.0.0-snapshot-
|
|
20
|
-
"@livestore/utils": "0.0.0-snapshot-
|
|
15
|
+
"@livestore/common": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2",
|
|
16
|
+
"@livestore/common-cf": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2",
|
|
17
|
+
"@livestore/livestore": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2",
|
|
18
|
+
"@livestore/sqlite-wasm": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2",
|
|
19
|
+
"@livestore/sync-cf": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2",
|
|
20
|
+
"@livestore/utils": "0.0.0-snapshot-a77b91f5d94e186cc27b3fbc5a7334fb969707c2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"wrangler": "4.38.0"
|
package/src/create-store-do.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HelperTypes } from '@livestore/common-cf'
|
|
1
2
|
import { createStore, type LiveStoreSchema, provideOtel } from '@livestore/livestore'
|
|
2
3
|
import type * as CfSyncBackend from '@livestore/sync-cf/cf-worker'
|
|
3
4
|
import { makeDoRpcSync } from '@livestore/sync-cf/client'
|
|
@@ -6,13 +7,10 @@ import type * as CfWorker from './cf-types.ts'
|
|
|
6
7
|
import { makeAdapter } from './make-adapter.ts'
|
|
7
8
|
|
|
8
9
|
export type Env = {
|
|
9
|
-
SYNC_BACKEND_DO: CfWorker.DurableObjectNamespace
|
|
10
|
+
SYNC_BACKEND_DO: CfWorker.DurableObjectNamespace<CfSyncBackend.SyncBackendRpcInterface>
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
* Options used to initialize the LiveStore Durable Object runtime.
|
|
14
|
-
*/
|
|
15
|
-
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = {
|
|
13
|
+
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState> = {
|
|
16
14
|
/** LiveStore schema that defines state, migrations, and validators. */
|
|
17
15
|
schema: TSchema
|
|
18
16
|
/** Logical identifier for the store instance persisted inside the Durable Object. */
|
|
@@ -21,22 +19,22 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSche
|
|
|
21
19
|
clientId: string
|
|
22
20
|
/** Identifier for the LiveStore session running inside the Durable Object. */
|
|
23
21
|
sessionId: string
|
|
24
|
-
/**
|
|
25
|
-
|
|
22
|
+
/** Runtime details about the Durable Object this store runs inside. Needed for sync backend to call back to this instance. */
|
|
23
|
+
durableObject: {
|
|
24
|
+
/** Durable Object state handle (e.g. `this.ctx`). */
|
|
25
|
+
ctx: TState
|
|
26
|
+
/** Environment bindings associated with the Durable Object. */
|
|
27
|
+
env: TEnv
|
|
28
|
+
/** Binding name Cloudflare uses to reach this Durable Object from other workers. */
|
|
29
|
+
bindingName: HelperTypes.ExtractDurableObjectKeys<NoInfer<TEnv>>
|
|
30
|
+
}
|
|
26
31
|
/** RPC stub pointing at the sync backend Durable Object used for replication. */
|
|
27
|
-
|
|
32
|
+
syncBackendStub: CfWorker.DurableObjectStub<CfSyncBackend.SyncBackendRpcInterface>
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Enables live pull mode to receive sync updates via Durable Object RPC callbacks.
|
|
30
35
|
*
|
|
31
|
-
* @
|
|
32
|
-
* ```ts
|
|
33
|
-
* const durableObjectId = this.state.id.toString()
|
|
34
|
-
* ```
|
|
36
|
+
* @default false
|
|
35
37
|
*/
|
|
36
|
-
durableObjectId: string
|
|
37
|
-
/** Binding name Cloudflare uses to reach this Durable Object from other workers. */
|
|
38
|
-
bindingName: string
|
|
39
|
-
/** Enables live pull mode to receive sync updates via Durable Object RPC callbacks. */
|
|
40
38
|
livePull?: boolean
|
|
41
39
|
/**
|
|
42
40
|
* Clears existing Durable Object persistence before bootstrapping the store.
|
|
@@ -46,19 +44,25 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSche
|
|
|
46
44
|
resetPersistence?: boolean
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
// TODO Also support in Cloudflare workers outside of a durable object context.
|
|
48
|
+
export const createStoreDo = <
|
|
49
|
+
TSchema extends LiveStoreSchema,
|
|
50
|
+
TEnv,
|
|
51
|
+
TState extends CfWorker.DurableObjectState = CfWorker.DurableObjectState,
|
|
52
|
+
>({
|
|
50
53
|
schema,
|
|
51
54
|
storeId,
|
|
52
55
|
clientId,
|
|
53
56
|
sessionId,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
durableObjectId,
|
|
57
|
-
bindingName,
|
|
57
|
+
durableObject,
|
|
58
|
+
syncBackendStub,
|
|
58
59
|
livePull = false,
|
|
59
60
|
resetPersistence = false,
|
|
60
|
-
}: CreateStoreDoOptions<TSchema>) =>
|
|
61
|
+
}: CreateStoreDoOptions<TSchema, TEnv, TState>) =>
|
|
61
62
|
Effect.gen(function* () {
|
|
63
|
+
const { ctx, bindingName } = durableObject
|
|
64
|
+
const storage = ctx.storage
|
|
65
|
+
const durableObjectId = ctx.id.toString()
|
|
62
66
|
const scope = yield* Scope.make()
|
|
63
67
|
|
|
64
68
|
const adapter = makeAdapter({
|
|
@@ -68,7 +72,7 @@ export const createStoreDo = <TSchema extends LiveStoreSchema = LiveStoreSchema.
|
|
|
68
72
|
resetPersistence,
|
|
69
73
|
syncOptions: {
|
|
70
74
|
backend: makeDoRpcSync({
|
|
71
|
-
syncBackendStub
|
|
75
|
+
syncBackendStub,
|
|
72
76
|
durableObjectContext: { bindingName, durableObjectId },
|
|
73
77
|
}),
|
|
74
78
|
livePull, // Uses DO RPC callbacks for reactive pull
|
|
@@ -79,8 +83,12 @@ export const createStoreDo = <TSchema extends LiveStoreSchema = LiveStoreSchema.
|
|
|
79
83
|
return yield* createStore({ schema, adapter, storeId }).pipe(Scope.extend(scope), provideOtel({}))
|
|
80
84
|
})
|
|
81
85
|
|
|
82
|
-
export const createStoreDoPromise = <
|
|
83
|
-
|
|
86
|
+
export const createStoreDoPromise = <
|
|
87
|
+
TSchema extends LiveStoreSchema,
|
|
88
|
+
TEnv,
|
|
89
|
+
TState extends CfWorker.DurableObjectState = CfWorker.DurableObjectState,
|
|
90
|
+
>(
|
|
91
|
+
options: CreateStoreDoOptions<TSchema, TEnv, TState>,
|
|
84
92
|
) =>
|
|
85
93
|
createStoreDo(options).pipe(
|
|
86
94
|
Logger.withMinimumLogLevel(LogLevel.Debug),
|