@livestore/adapter-cloudflare 0.4.0-dev.9 → 0.4.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/dist/.tsbuildinfo +1 -1
- package/dist/WebSocket.d.ts +5 -5
- package/dist/WebSocket.d.ts.map +1 -1
- package/dist/WebSocket.js +18 -15
- package/dist/WebSocket.js.map +1 -1
- package/dist/create-store-do.d.ts +78 -7
- package/dist/create-store-do.d.ts.map +1 -1
- package/dist/create-store-do.js +73 -4
- package/dist/create-store-do.js.map +1 -1
- package/dist/make-adapter.d.ts +2 -2
- package/dist/make-adapter.d.ts.map +1 -1
- package/dist/make-adapter.js +58 -45
- package/dist/make-adapter.js.map +1 -1
- package/dist/make-sqlite-db.d.ts +4 -4
- package/dist/make-sqlite-db.d.ts.map +1 -1
- package/dist/make-sqlite-db.js +41 -12
- package/dist/make-sqlite-db.js.map +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +1 -1
- package/package.json +60 -17
- package/src/WebSocket.ts +23 -18
- package/src/create-store-do.ts +86 -11
- package/src/make-adapter.ts +76 -53
- package/src/make-sqlite-db.ts +52 -21
- package/src/mod.ts +1 -6
- package/dist/cf-types.d.ts +0 -2
- package/dist/cf-types.d.ts.map +0 -1
- package/dist/cf-types.js +0 -2
- package/dist/cf-types.js.map +0 -1
- package/dist/make-client-durable-object.d.ts +0 -48
- package/dist/make-client-durable-object.d.ts.map +0 -1
- package/dist/make-client-durable-object.js +0 -26
- package/dist/make-client-durable-object.js.map +0 -1
- package/src/cf-types.ts +0 -20
package/dist/WebSocket.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Effect,
|
|
3
|
-
import
|
|
1
|
+
import type { CfTypes } from '@livestore/common-cf';
|
|
2
|
+
import { Effect, type Schedule, type Scope } from '@livestore/utils/effect';
|
|
3
|
+
import { WebSocket } from '@livestore/utils/effect/browser';
|
|
4
4
|
/**
|
|
5
5
|
* Creates a WebSocket connection and waits for the connection to be established.
|
|
6
6
|
* Automatically closes the connection when the scope is closed.
|
|
7
7
|
*/
|
|
8
8
|
export declare const makeWebSocket: ({ reconnect, url, durableObject, }: {
|
|
9
9
|
/** CF Sync Backend DO with `/sync` endpoint */
|
|
10
|
-
durableObject:
|
|
10
|
+
durableObject: CfTypes.DurableObjectStub;
|
|
11
11
|
url: URL;
|
|
12
12
|
reconnect?: Schedule.Schedule<unknown> | false;
|
|
13
|
-
}) => Effect.Effect<
|
|
13
|
+
}) => Effect.Effect<CfTypes.WebSocket, WebSocket.WebSocketError, Scope.Scope>;
|
|
14
14
|
//# sourceMappingURL=WebSocket.d.ts.map
|
package/dist/WebSocket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../src/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../src/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAkB,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAO3D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,oCAK3B;IACD,+CAA+C;IAC/C,aAAa,EAAE,OAAO,CAAC,iBAAiB,CAAA;IACxC,GAAG,EAAE,GAAG,CAAA;IACR,SAAS,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;CAC/C,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAkDtE,CAAA"}
|
package/dist/WebSocket.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Effect, Exit, identity
|
|
1
|
+
import { Effect, Exit, identity } from '@livestore/utils/effect';
|
|
2
|
+
import { WebSocket } from '@livestore/utils/effect/browser';
|
|
2
3
|
// TODO refactor using Effect socket implementation
|
|
3
4
|
// https://github.com/Effect-TS/effect/blob/main/packages%2Fexperimental%2Fsrc%2FDevTools%2FClient.ts#L113
|
|
4
5
|
// "In a Stream pipeline everything above the pipeThrough is the outgoing (send) messages. Everything below is the incoming (message event) messages."
|
|
@@ -12,14 +13,16 @@ export const makeWebSocket = ({
|
|
|
12
13
|
reconnect, url, durableObject, }) => Effect.gen(function* () {
|
|
13
14
|
// yield* validateUrl(url)
|
|
14
15
|
const socket = yield* Effect.tryPromise({
|
|
15
|
-
try: () =>
|
|
16
|
-
|
|
16
|
+
try: () =>
|
|
17
|
+
// NOTE: .toString() required due to type mismatch between standard URL and CF's URL types
|
|
18
|
+
durableObject.fetch(url.toString(), { headers: { Upgrade: 'websocket' } }).then((res) => {
|
|
19
|
+
if (res.webSocket == null) {
|
|
17
20
|
throw new Error('WebSocket upgrade failed');
|
|
18
21
|
}
|
|
19
22
|
return res.webSocket;
|
|
20
23
|
}),
|
|
21
24
|
catch: (cause) => new WebSocket.WebSocketError({ cause }),
|
|
22
|
-
}).pipe(reconnect ? Effect.retry(reconnect) : identity, Effect.withSpan('make-websocket-durable-object'));
|
|
25
|
+
}).pipe(reconnect !== undefined && reconnect !== false ? Effect.retry(reconnect) : identity, Effect.withSpan('make-websocket-durable-object'));
|
|
23
26
|
socket.accept();
|
|
24
27
|
/**
|
|
25
28
|
* Common WebSocket close codes: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
|
|
@@ -35,17 +38,17 @@ reconnect, url, durableObject, }) => Effect.gen(function* () {
|
|
|
35
38
|
* 4000-4999: Available for applications
|
|
36
39
|
*/
|
|
37
40
|
yield* Effect.addFinalizer(Effect.fn(function* (exit) {
|
|
38
|
-
try
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
41
|
+
yield* Effect.try({
|
|
42
|
+
try: () => {
|
|
43
|
+
if (Exit.isFailure(exit) === true) {
|
|
44
|
+
socket.close(3000);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
socket.close(1000);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
catch: (error) => new WebSocket.WebSocketError({ cause: error }),
|
|
51
|
+
}).pipe(Effect.orDie);
|
|
49
52
|
}));
|
|
50
53
|
return socket;
|
|
51
54
|
});
|
package/dist/WebSocket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../src/WebSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../src/WebSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAA6B,MAAM,yBAAyB,CAAA;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAE3D,mDAAmD;AACnD,0GAA0G;AAC1G,sJAAsJ;AACtJ,2FAA2F;AAE3F;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;AAC5B,MAAM;AACN,SAAS,EACT,GAAG,EACH,aAAa,GAMd,EAA2E,EAAE,CAC5E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,0BAA0B;IAE1B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;QACtC,GAAG,EAAE,GAAG,EAAE;QACR,0FAA0F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AC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAC,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { LogConfig, type SyncOptions } from '@livestore/common';
|
|
2
|
+
import type { CfTypes, HelperTypes } from '@livestore/common-cf';
|
|
2
3
|
import { type LiveStoreSchema } from '@livestore/livestore';
|
|
3
4
|
import type * as CfSyncBackend from '@livestore/sync-cf/cf-worker';
|
|
4
5
|
import { Effect } from '@livestore/utils/effect';
|
|
5
|
-
import type * as CfWorker from './cf-types.ts';
|
|
6
6
|
export type Env = {
|
|
7
|
-
SYNC_BACKEND_DO:
|
|
7
|
+
SYNC_BACKEND_DO: CfTypes.DurableObjectNamespace<CfSyncBackend.SyncBackendRpcInterface>;
|
|
8
8
|
};
|
|
9
9
|
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState> = {
|
|
10
10
|
/** LiveStore schema that defines state, migrations, and validators. */
|
|
@@ -25,7 +25,7 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState>
|
|
|
25
25
|
bindingName: HelperTypes.ExtractDurableObjectKeys<NoInfer<TEnv>>;
|
|
26
26
|
};
|
|
27
27
|
/** RPC stub pointing at the sync backend Durable Object used for replication. */
|
|
28
|
-
syncBackendStub:
|
|
28
|
+
syncBackendStub: CfTypes.DurableObjectStub<CfSyncBackend.SyncBackendRpcInterface>;
|
|
29
29
|
/**
|
|
30
30
|
* Enables live pull mode to receive sync updates via Durable Object RPC callbacks.
|
|
31
31
|
*
|
|
@@ -38,7 +38,78 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState>
|
|
|
38
38
|
* Note: Only use this for development purposes.
|
|
39
39
|
*/
|
|
40
40
|
resetPersistence?: boolean;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Controls how initial sync behaves when the store boots.
|
|
43
|
+
*
|
|
44
|
+
* @default { _tag: 'Blocking', timeout: 500 }
|
|
45
|
+
*/
|
|
46
|
+
initialSyncOptions?: SyncOptions['initialSyncOptions'];
|
|
47
|
+
} & LogConfig.WithLoggerOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a LiveStore instance inside a Cloudflare Durable Object.
|
|
50
|
+
*
|
|
51
|
+
* This function bootstraps a full LiveStore client within a Durable Object, enabling
|
|
52
|
+
* persistent state management with automatic sync to a sync backend. Use this when you
|
|
53
|
+
* need server-side LiveStore instances that can communicate with other clients.
|
|
54
|
+
*
|
|
55
|
+
* Returns an Effect that resolves to a Store instance. For a Promise-based API,
|
|
56
|
+
* use `createStoreDoPromise` instead.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { createStoreDo } from '@livestore/adapter-cloudflare'
|
|
61
|
+
* import { schema } from './schema'
|
|
62
|
+
*
|
|
63
|
+
* export class MyDurableObject extends DurableObject {
|
|
64
|
+
* store: Store | undefined
|
|
65
|
+
*
|
|
66
|
+
* async fetch(request: Request) {
|
|
67
|
+
* if (!this.store) {
|
|
68
|
+
* this.store = await createStoreDo({
|
|
69
|
+
* schema,
|
|
70
|
+
* storeId: 'my-store',
|
|
71
|
+
* clientId: this.ctx.id.toString(),
|
|
72
|
+
* sessionId: 'do-session',
|
|
73
|
+
* durableObject: {
|
|
74
|
+
* ctx: this.ctx,
|
|
75
|
+
* env: this.env,
|
|
76
|
+
* bindingName: 'MY_DO',
|
|
77
|
+
* },
|
|
78
|
+
* syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
|
|
79
|
+
* }).pipe(Effect.runPromise)
|
|
80
|
+
* }
|
|
81
|
+
* // Use this.store...
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @see https://livestore.dev/docs/reference/adapters/cloudflare for setup guide
|
|
87
|
+
*/
|
|
88
|
+
export declare const createStoreDo: <TSchema extends LiveStoreSchema, TEnv, TState extends CfTypes.DurableObjectState = CfTypes.DurableObjectState>({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull, resetPersistence, initialSyncOptions, }: CreateStoreDoOptions<TSchema, TEnv, TState>) => Effect.Effect<import("@livestore/livestore").Store<TSchema, {}>, import("@livestore/common").UnknownError, never>;
|
|
89
|
+
/**
|
|
90
|
+
* Promise-based wrapper around `createStoreDo` for simpler async/await usage.
|
|
91
|
+
*
|
|
92
|
+
* Equivalent to calling `createStoreDo(options).pipe(Effect.runPromise)` with
|
|
93
|
+
* logging configured automatically.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { createStoreDoPromise } from '@livestore/adapter-cloudflare'
|
|
98
|
+
*
|
|
99
|
+
* export class MyDurableObject extends DurableObject {
|
|
100
|
+
* async fetch(request: Request) {
|
|
101
|
+
* const store = await createStoreDoPromise({
|
|
102
|
+
* schema,
|
|
103
|
+
* storeId: 'my-store',
|
|
104
|
+
* clientId: this.ctx.id.toString(),
|
|
105
|
+
* sessionId: 'do-session',
|
|
106
|
+
* durableObject: { ctx: this.ctx, env: this.env, bindingName: 'MY_DO' },
|
|
107
|
+
* syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
|
|
108
|
+
* })
|
|
109
|
+
* // Use store...
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare const createStoreDoPromise: <TSchema extends LiveStoreSchema, TEnv, TState extends CfTypes.DurableObjectState = CfTypes.DurableObjectState>(options: CreateStoreDoOptions<TSchema, TEnv, TState>) => Promise<import("@livestore/livestore").Store<TSchema, {}>>;
|
|
44
115
|
//# 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,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"create-store-do.d.ts","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAe,KAAK,eAAe,EAAe,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,KAAK,aAAa,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAA;AAI/D,MAAM,MAAM,GAAG,GAAG;IAChB,eAAe,EAAE,OAAO,CAAC,sBAAsB,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAA;CACvF,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,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAA;IACjF;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;CACvD,GAAG,SAAS,CAAC,iBAAiB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,EACtE,2HAUC,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,sHAuB1C,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,EAEtE,SAAS,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,+DASnD,CAAA"}
|
package/dist/create-store-do.js
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
|
+
import { LogConfig } from '@livestore/common';
|
|
1
2
|
import { createStore, provideOtel } from '@livestore/livestore';
|
|
2
3
|
import { makeDoRpcSync } from '@livestore/sync-cf/client';
|
|
3
|
-
import { Effect, Logger,
|
|
4
|
+
import { Effect, Logger, Scope } from '@livestore/utils/effect';
|
|
4
5
|
import { makeAdapter } from "./make-adapter.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a LiveStore instance inside a Cloudflare Durable Object.
|
|
8
|
+
*
|
|
9
|
+
* This function bootstraps a full LiveStore client within a Durable Object, enabling
|
|
10
|
+
* persistent state management with automatic sync to a sync backend. Use this when you
|
|
11
|
+
* need server-side LiveStore instances that can communicate with other clients.
|
|
12
|
+
*
|
|
13
|
+
* Returns an Effect that resolves to a Store instance. For a Promise-based API,
|
|
14
|
+
* use `createStoreDoPromise` instead.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createStoreDo } from '@livestore/adapter-cloudflare'
|
|
19
|
+
* import { schema } from './schema'
|
|
20
|
+
*
|
|
21
|
+
* export class MyDurableObject extends DurableObject {
|
|
22
|
+
* store: Store | undefined
|
|
23
|
+
*
|
|
24
|
+
* async fetch(request: Request) {
|
|
25
|
+
* if (!this.store) {
|
|
26
|
+
* this.store = await createStoreDo({
|
|
27
|
+
* schema,
|
|
28
|
+
* storeId: 'my-store',
|
|
29
|
+
* clientId: this.ctx.id.toString(),
|
|
30
|
+
* sessionId: 'do-session',
|
|
31
|
+
* durableObject: {
|
|
32
|
+
* ctx: this.ctx,
|
|
33
|
+
* env: this.env,
|
|
34
|
+
* bindingName: 'MY_DO',
|
|
35
|
+
* },
|
|
36
|
+
* syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
|
|
37
|
+
* }).pipe(Effect.runPromise)
|
|
38
|
+
* }
|
|
39
|
+
* // Use this.store...
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see https://livestore.dev/docs/reference/adapters/cloudflare for setup guide
|
|
45
|
+
*/
|
|
5
46
|
// 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* () {
|
|
47
|
+
export const createStoreDo = ({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull = false, resetPersistence = false, initialSyncOptions = { _tag: 'Blocking', timeout: 500 }, }) => Effect.gen(function* () {
|
|
7
48
|
const { ctx, bindingName } = durableObject;
|
|
8
49
|
const storage = ctx.storage;
|
|
9
50
|
const durableObjectId = ctx.id.toString();
|
|
@@ -19,10 +60,38 @@ export const createStoreDo = ({ schema, storeId, clientId, sessionId, durableObj
|
|
|
19
60
|
durableObjectContext: { bindingName, durableObjectId },
|
|
20
61
|
}),
|
|
21
62
|
livePull, // Uses DO RPC callbacks for reactive pull
|
|
22
|
-
initialSyncOptions
|
|
63
|
+
initialSyncOptions,
|
|
23
64
|
},
|
|
24
65
|
});
|
|
25
66
|
return yield* createStore({ schema, adapter, storeId }).pipe(Scope.extend(scope), provideOtel({}));
|
|
26
67
|
});
|
|
27
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Promise-based wrapper around `createStoreDo` for simpler async/await usage.
|
|
70
|
+
*
|
|
71
|
+
* Equivalent to calling `createStoreDo(options).pipe(Effect.runPromise)` with
|
|
72
|
+
* logging configured automatically.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { createStoreDoPromise } from '@livestore/adapter-cloudflare'
|
|
77
|
+
*
|
|
78
|
+
* export class MyDurableObject extends DurableObject {
|
|
79
|
+
* async fetch(request: Request) {
|
|
80
|
+
* const store = await createStoreDoPromise({
|
|
81
|
+
* schema,
|
|
82
|
+
* storeId: 'my-store',
|
|
83
|
+
* clientId: this.ctx.id.toString(),
|
|
84
|
+
* sessionId: 'do-session',
|
|
85
|
+
* durableObject: { ctx: this.ctx, env: this.env, bindingName: 'MY_DO' },
|
|
86
|
+
* syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
|
|
87
|
+
* })
|
|
88
|
+
* // Use store...
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export const createStoreDoPromise = (options) => createStoreDo(options).pipe(LogConfig.withLoggerConfig(options, {
|
|
94
|
+
threadName: 'DoClient',
|
|
95
|
+
defaultLogger: Logger.consoleWithThread('DoClient'),
|
|
96
|
+
}), Effect.tapCauseLogPretty, Effect.runPromise);
|
|
28
97
|
//# sourceMappingURL=create-store-do.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-store-do.js","sourceRoot":"","sources":["../src/create-store-do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,EAAE,0CAA0C;YACpD,kBAAkB;SACnB;KACF,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;AACpG,CAAC,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAKlC,OAAoD,EACpD,EAAE,CACF,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,CACzB,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAClC,UAAU,EAAE,UAAU;IACtB,aAAa,EAAE,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC;CACpD,CAAC,EACF,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,UAAU,CAClB,CAAA"}
|
package/dist/make-adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Adapter, type SyncOptions } from '@livestore/common';
|
|
2
|
-
import type
|
|
2
|
+
import type { CfTypes } from '@livestore/common-cf';
|
|
3
3
|
export declare const makeAdapter: ({ storage, clientId, syncOptions, sessionId, resetPersistence, }: {
|
|
4
|
-
storage:
|
|
4
|
+
storage: CfTypes.DurableObjectStorage;
|
|
5
5
|
clientId: string;
|
|
6
6
|
syncOptions: SyncOptions;
|
|
7
7
|
sessionId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-adapter.d.ts","sourceRoot":"","sources":["../src/make-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAKZ,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"make-adapter.d.ts","sourceRoot":"","sources":["../src/make-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAKZ,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAcnD,eAAO,MAAM,WAAW,GACrB,kEAME;IACD,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,KAAG,OA+ID,CAAA"}
|
package/dist/make-adapter.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import { ClientSessionLeaderThreadProxy, liveStoreStorageFormatVersion, makeClientSession,
|
|
2
|
-
import { Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread';
|
|
1
|
+
import { ClientSessionLeaderThreadProxy, liveStoreStorageFormatVersion, makeClientSession, UnknownError, } from '@livestore/common';
|
|
2
|
+
import { Eventlog, LeaderThreadCtx, makeLeaderThreadLayer, streamEventsWithSyncState, } from '@livestore/common/leader-thread';
|
|
3
3
|
import { LiveStoreEvent } from '@livestore/livestore';
|
|
4
|
-
import { sqliteDbFactory } from '@livestore/sqlite-wasm/cf';
|
|
4
|
+
import { CF_SQL_VFS_REQUIRED_PRAGMAS, sqliteDbFactory } from '@livestore/sqlite-wasm/cf';
|
|
5
|
+
import { makeSqliteDb as makeDoSqliteDb } from "./make-sqlite-db.js";
|
|
5
6
|
import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
|
|
6
7
|
import { Effect, FetchHttpClient, Layer, Schedule, SubscriptionRef, WebChannel } from '@livestore/utils/effect';
|
|
7
8
|
export const makeAdapter = ({ storage, clientId, syncOptions, sessionId, resetPersistence = false, }) => (adapterArgs) => Effect.gen(function* () {
|
|
8
|
-
const { storeId,
|
|
9
|
+
const { storeId,
|
|
10
|
+
/* devtoolsEnabled, shutdown, bootStatusQueue, */
|
|
11
|
+
syncPayloadEncoded, syncPayloadSchema, schema, } = adapterArgs;
|
|
9
12
|
const devtoolsOptions = { enabled: false };
|
|
10
13
|
const sqlite3 = yield* Effect.promise(() => loadSqlite3Wasm());
|
|
11
14
|
const makeSqliteDb = sqliteDbFactory({ sqlite3 });
|
|
12
|
-
const syncInMemoryDb = yield* makeSqliteDb({ _tag: 'in-memory', storage, configureDb: () => { } }).pipe(
|
|
15
|
+
const syncInMemoryDb = yield* makeSqliteDb({ _tag: 'in-memory', storage, configureDb: () => { } }).pipe(UnknownError.mapToUnknownError);
|
|
13
16
|
const schemaHashSuffix = schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString();
|
|
14
|
-
const stateDbFileName = getStateDbFileName(schemaHashSuffix);
|
|
15
|
-
const eventlogDbFileName = getEventlogDbFileName();
|
|
16
17
|
if (resetPersistence === true) {
|
|
17
|
-
yield* resetDurableObjectPersistence({
|
|
18
|
-
storage,
|
|
19
|
-
storeId,
|
|
20
|
-
dbFileNames: [stateDbFileName, eventlogDbFileName],
|
|
21
|
-
});
|
|
18
|
+
yield* resetDurableObjectPersistence({ storage, storeId });
|
|
22
19
|
}
|
|
20
|
+
const stateDbFileName = getStateDbFileName(schemaHashSuffix);
|
|
23
21
|
const dbState = yield* makeSqliteDb({
|
|
24
22
|
_tag: 'storage',
|
|
25
23
|
storage,
|
|
26
24
|
fileName: stateDbFileName,
|
|
25
|
+
configureDb: (db) => db.execute([...CF_SQL_VFS_REQUIRED_PRAGMAS, 'cache_size=-8000'].map((p) => `PRAGMA ${p}`).join(';\n')),
|
|
26
|
+
}).pipe(UnknownError.mapToUnknownError);
|
|
27
|
+
// dbEventlog runs on DO SQLite directly (not through the VFS). SQL-level transaction
|
|
28
|
+
// control (BEGIN/COMMIT/ROLLBACK) is silently dropped — see isTransactionControlStatement
|
|
29
|
+
// in make-sqlite-db.ts for details on why this is safe.
|
|
30
|
+
const dbEventlog = yield* makeDoSqliteDb({
|
|
31
|
+
_tag: 'file',
|
|
32
|
+
db: storage.sql,
|
|
27
33
|
configureDb: () => { },
|
|
28
|
-
}).pipe(
|
|
29
|
-
const dbEventlog = yield* makeSqliteDb({
|
|
30
|
-
_tag: 'storage',
|
|
31
|
-
storage,
|
|
32
|
-
fileName: eventlogDbFileName,
|
|
33
|
-
configureDb: () => { },
|
|
34
|
-
}).pipe(UnexpectedError.mapToUnexpectedError);
|
|
34
|
+
}).pipe(UnknownError.mapToUnknownError);
|
|
35
35
|
const shutdownChannel = yield* WebChannel.noopChannel();
|
|
36
|
-
// Use Durable Object sync backend if no backend is specified
|
|
37
36
|
const layer = yield* Layer.build(makeLeaderThreadLayer({
|
|
38
37
|
schema,
|
|
39
38
|
storeId,
|
|
@@ -44,22 +43,33 @@ export const makeAdapter = ({ storage, clientId, syncOptions, sessionId, resetPe
|
|
|
44
43
|
dbEventlog,
|
|
45
44
|
devtoolsOptions,
|
|
46
45
|
shutdownChannel,
|
|
47
|
-
|
|
46
|
+
syncPayloadEncoded,
|
|
47
|
+
syncPayloadSchema,
|
|
48
48
|
}));
|
|
49
49
|
const { leaderThread, initialSnapshot } = yield* Effect.gen(function* () {
|
|
50
|
-
const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState } = yield* LeaderThreadCtx;
|
|
50
|
+
const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState, networkStatus } = yield* LeaderThreadCtx;
|
|
51
51
|
const initialLeaderHead = Eventlog.getClientHeadFromDb(dbEventlog);
|
|
52
52
|
// const initialLeaderHead = EventSequenceNumber.ROOT
|
|
53
53
|
const leaderThread = ClientSessionLeaderThreadProxy.of({
|
|
54
54
|
events: {
|
|
55
55
|
pull: ({ cursor }) => syncProcessor.pull({ cursor }),
|
|
56
|
-
push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.EncodedWithMeta(item)), { waitForProcessing: true }),
|
|
56
|
+
push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.Client.EncodedWithMeta(item)), { waitForProcessing: true }),
|
|
57
|
+
stream: (options) => streamEventsWithSyncState({
|
|
58
|
+
dbEventlog,
|
|
59
|
+
syncState: syncProcessor.syncState,
|
|
60
|
+
options,
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
initialState: {
|
|
64
|
+
leaderHead: initialLeaderHead,
|
|
65
|
+
migrationsReport: initialState.migrationsReport,
|
|
66
|
+
storageMode: 'persisted',
|
|
57
67
|
},
|
|
58
|
-
initialState: { leaderHead: initialLeaderHead, migrationsReport: initialState.migrationsReport },
|
|
59
68
|
export: Effect.sync(() => dbState.export()),
|
|
60
69
|
getEventlogData: Effect.sync(() => dbEventlog.export()),
|
|
61
|
-
|
|
70
|
+
syncState: syncProcessor.syncState,
|
|
62
71
|
sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
|
|
72
|
+
networkStatus,
|
|
63
73
|
}, {
|
|
64
74
|
// overrides: testing?.overrides?.clientSession?.leaderThreadProxy
|
|
65
75
|
});
|
|
@@ -73,14 +83,14 @@ export const makeAdapter = ({ storage, clientId, syncOptions, sessionId, resetPe
|
|
|
73
83
|
sqliteDb: syncInMemoryDb,
|
|
74
84
|
webmeshMode: 'proxy',
|
|
75
85
|
connectWebmeshNode: Effect.fnUntraced(function* ({ webmeshNode }) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
if (devtoolsOptions.enabled === true) {
|
|
87
|
+
console.log('connectWebmeshNode', { webmeshNode });
|
|
88
|
+
// yield* Webmesh.connectViaWebSocket({
|
|
89
|
+
// node: webmeshNode,
|
|
90
|
+
// url: `ws://${devtoolsOptions.host}:${devtoolsOptions.port}`,
|
|
91
|
+
// openTimeout: 500,
|
|
92
|
+
// }).pipe(Effect.tapCauseLogPretty, Effect.forkScoped)
|
|
93
|
+
}
|
|
84
94
|
}),
|
|
85
95
|
leaderThread,
|
|
86
96
|
lockStatus,
|
|
@@ -89,34 +99,37 @@ export const makeAdapter = ({ storage, clientId, syncOptions, sessionId, resetPe
|
|
|
89
99
|
isLeader: true,
|
|
90
100
|
// Not really applicable for node as there is no "reload the app" concept
|
|
91
101
|
registerBeforeUnload: (_onBeforeUnload) => () => { },
|
|
102
|
+
origin: undefined,
|
|
92
103
|
});
|
|
93
104
|
return clientSession;
|
|
94
105
|
}).pipe(Effect.withSpan('@livestore/adapter-cloudflare:makeAdapter', { attributes: { clientId, sessionId } }), Effect.provide(FetchHttpClient.layer));
|
|
95
106
|
const getStateDbFileName = (suffix) => `state${suffix}@${liveStoreStorageFormatVersion}.db`;
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
const resetDurableObjectPersistence = ({ storage, storeId, }) => Effect.try({
|
|
108
|
+
try: () =>
|
|
109
|
+
// All three tables live in the DO's single storage.sql database but are
|
|
110
|
+
// owned by different layers during normal operation:
|
|
111
|
+
// - vfs_pages: written by the wa-sqlite VFS layer (backs dbState)
|
|
112
|
+
// - eventlog, __livestore_sync_status: written directly by dbEventlog via storage.sql
|
|
113
|
+
storage.transactionSync(() => {
|
|
114
|
+
safeSqlExec(storage, 'DELETE FROM vfs_pages');
|
|
115
|
+
safeSqlExec(storage, 'DELETE FROM eventlog');
|
|
116
|
+
safeSqlExec(storage, 'DELETE FROM __livestore_sync_status');
|
|
104
117
|
}),
|
|
105
|
-
catch: (cause) => new
|
|
118
|
+
catch: (cause) => new UnknownError({
|
|
106
119
|
cause,
|
|
107
120
|
note: `@livestore/adapter-cloudflare: Failed to reset persistence for store ${storeId}`,
|
|
108
121
|
}),
|
|
109
122
|
}).pipe(Effect.retry({ schedule: Schedule.exponentialBackoff10Sec }), Effect.withSpan('@livestore/adapter-cloudflare:resetPersistence', { attributes: { storeId } }));
|
|
110
123
|
const safeSqlExec = (storage, query, binding) => {
|
|
111
124
|
try {
|
|
112
|
-
storage.sql.exec(query, binding);
|
|
125
|
+
binding !== undefined ? storage.sql.exec(query, binding) : storage.sql.exec(query);
|
|
113
126
|
}
|
|
114
127
|
catch (error) {
|
|
115
|
-
if (
|
|
128
|
+
if (isMissingTableError(error) === true) {
|
|
116
129
|
return;
|
|
117
130
|
}
|
|
118
131
|
throw error;
|
|
119
132
|
}
|
|
120
133
|
};
|
|
121
|
-
const
|
|
134
|
+
const isMissingTableError = (error) => error instanceof Error && error.message.toLowerCase().includes('no such table');
|
|
122
135
|
//# sourceMappingURL=make-adapter.js.map
|
package/dist/make-adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-adapter.js","sourceRoot":"","sources":["../src/make-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAE9B,6BAA6B,EAC7B,iBAAiB,EAEjB,
|
|
1
|
+
{"version":3,"file":"make-adapter.js","sourceRoot":"","sources":["../src/make-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAE9B,6BAA6B,EAC7B,iBAAiB,EAEjB,YAAY,GACb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAEL,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AACxF,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAE/G,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,EACC,O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
2
|
-
import type
|
|
2
|
+
import type { CfTypes } from '@livestore/common-cf';
|
|
3
3
|
type Metadata = {
|
|
4
4
|
_tag: 'file';
|
|
5
5
|
dbPointer: number;
|
|
@@ -9,11 +9,11 @@ type Metadata = {
|
|
|
9
9
|
};
|
|
10
10
|
type CloudflareDatabaseInput = {
|
|
11
11
|
_tag: 'file';
|
|
12
|
-
db:
|
|
12
|
+
db: CfTypes.SqlStorage;
|
|
13
13
|
configureDb: (db: SqliteDb) => void;
|
|
14
14
|
} | {
|
|
15
15
|
_tag: 'in-memory';
|
|
16
|
-
db:
|
|
16
|
+
db: CfTypes.SqlStorage;
|
|
17
17
|
configureDb: (db: SqliteDb) => void;
|
|
18
18
|
};
|
|
19
19
|
export type MakeCloudflareSqliteDb = MakeSqliteDb<Metadata, CloudflareDatabaseInput, {
|
|
@@ -24,7 +24,7 @@ export declare const makeSqliteDb_: <TMetadata extends {
|
|
|
24
24
|
persistenceInfo: PersistenceInfo;
|
|
25
25
|
configureDb: (db: SqliteDb<TMetadata>) => void;
|
|
26
26
|
}>({ sqlStorage, metadata, }: {
|
|
27
|
-
sqlStorage:
|
|
27
|
+
sqlStorage: CfTypes.SqlStorage;
|
|
28
28
|
metadata: TMetadata;
|
|
29
29
|
}) => SqliteDb<TMetadata>;
|
|
30
30
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-sqlite-db.d.ts","sourceRoot":"","sources":["../src/make-sqlite-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAGf,QAAQ,EAGT,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"make-sqlite-db.d.ts","sourceRoot":"","sources":["../src/make-sqlite-db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAGf,QAAQ,EAGT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAA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