@livestore/adapter-cloudflare 0.0.0-snapshot-8452e32b7fbfc129741b253b9c853f866b52129f
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/LICENSE +201 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/WebSocket.d.ts +14 -0
- package/dist/WebSocket.d.ts.map +1 -0
- package/dist/WebSocket.js +52 -0
- package/dist/WebSocket.js.map +1 -0
- package/dist/cf-types.d.ts +2 -0
- package/dist/cf-types.d.ts.map +1 -0
- package/dist/cf-types.js +2 -0
- package/dist/cf-types.js.map +1 -0
- package/dist/make-adapter.d.ts +9 -0
- package/dist/make-adapter.d.ts.map +1 -0
- package/dist/make-adapter.js +87 -0
- package/dist/make-adapter.js.map +1 -0
- package/dist/make-client-durable-object.d.ts +34 -0
- package/dist/make-client-durable-object.d.ts.map +1 -0
- package/dist/make-client-durable-object.js +25 -0
- package/dist/make-client-durable-object.js.map +1 -0
- package/dist/make-sqlite-db.d.ts +31 -0
- package/dist/make-sqlite-db.d.ts.map +1 -0
- package/dist/make-sqlite-db.js +194 -0
- package/dist/make-sqlite-db.js.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -0
- package/dist/polyfill.d.ts +2 -0
- package/dist/polyfill.d.ts.map +1 -0
- package/dist/polyfill.js +40 -0
- package/dist/polyfill.js.map +1 -0
- package/dist/sync-provider-client.d.ts +12 -0
- package/dist/sync-provider-client.d.ts.map +1 -0
- package/dist/sync-provider-client.js +24 -0
- package/dist/sync-provider-client.js.map +1 -0
- package/dist/sync-provider-rpc-client.d.ts +2 -0
- package/dist/sync-provider-rpc-client.d.ts.map +1 -0
- package/dist/sync-provider-rpc-client.js +139 -0
- package/dist/sync-provider-rpc-client.js.map +1 -0
- package/dist/sync-provider-ws-client.d.ts +2 -0
- package/dist/sync-provider-ws-client.d.ts.map +1 -0
- package/dist/sync-provider-ws-client.js +40 -0
- package/dist/sync-provider-ws-client.js.map +1 -0
- package/package.json +38 -0
- package/src/WebSocket.ts +69 -0
- package/src/cf-types.ts +20 -0
- package/src/make-adapter.ts +144 -0
- package/src/make-client-durable-object.ts +91 -0
- package/src/make-sqlite-db.ts +261 -0
- package/src/mod.ts +12 -0
- package/src/polyfill.ts +44 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Schedule, Scope } from '@livestore/utils/effect';
|
|
2
|
+
import { Effect, WebSocket } from '@livestore/utils/effect';
|
|
3
|
+
import type * as CfWorker from './cf-types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a WebSocket connection and waits for the connection to be established.
|
|
6
|
+
* Automatically closes the connection when the scope is closed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const makeWebSocket: ({ reconnect, url, durableObject, }: {
|
|
9
|
+
/** CF Sync Backend DO with `/sync` endpoint */
|
|
10
|
+
durableObject: CfWorker.DurableObjectStub;
|
|
11
|
+
url: URL;
|
|
12
|
+
reconnect?: Schedule.Schedule<unknown> | false;
|
|
13
|
+
}) => Effect.Effect<CfWorker.WebSocket, WebSocket.WebSocketError, Scope.Scope>;
|
|
14
|
+
//# sourceMappingURL=WebSocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../src/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC3E,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAO9C;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,oCAK3B;IACD,+CAA+C;IAC/C,aAAa,EAAE,QAAQ,CAAC,iBAAiB,CAAA;IACzC,GAAG,EAAE,GAAG,CAAA;IACR,SAAS,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;CAC/C,KAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CA6CvE,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Effect, Exit, identity, WebSocket } from '@livestore/utils/effect';
|
|
2
|
+
// TODO refactor using Effect socket implementation
|
|
3
|
+
// https://github.com/Effect-TS/effect/blob/main/packages%2Fexperimental%2Fsrc%2FDevTools%2FClient.ts#L113
|
|
4
|
+
// "In a Stream pipeline everything above the pipeThrough is the outgoing (send) messages. Everything below is the incoming (message event) messages."
|
|
5
|
+
// https://github.com/Effect-TS/effect/blob/main/packages%2Fplatform%2Fsrc%2FSocket.ts#L451
|
|
6
|
+
/**
|
|
7
|
+
* Creates a WebSocket connection and waits for the connection to be established.
|
|
8
|
+
* Automatically closes the connection when the scope is closed.
|
|
9
|
+
*/
|
|
10
|
+
export const makeWebSocket = ({
|
|
11
|
+
// do,
|
|
12
|
+
reconnect, url, durableObject, }) => Effect.gen(function* () {
|
|
13
|
+
// yield* validateUrl(url)
|
|
14
|
+
const socket = yield* Effect.tryPromise({
|
|
15
|
+
try: () => durableObject.fetch(url, { headers: { Upgrade: 'websocket' } }).then((res) => {
|
|
16
|
+
if (!res.webSocket) {
|
|
17
|
+
throw new Error('WebSocket upgrade failed');
|
|
18
|
+
}
|
|
19
|
+
return res.webSocket;
|
|
20
|
+
}),
|
|
21
|
+
catch: (cause) => new WebSocket.WebSocketError({ cause }),
|
|
22
|
+
}).pipe(reconnect ? Effect.retry(reconnect) : identity, Effect.withSpan('make-websocket-durable-object'));
|
|
23
|
+
socket.accept();
|
|
24
|
+
/**
|
|
25
|
+
* Common WebSocket close codes: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
|
|
26
|
+
* 1000: Normal closure
|
|
27
|
+
* 1001: Endpoint is going away, a server is terminating the connection because it has received a request that indicates the client is ending the connection.
|
|
28
|
+
* 1002: Protocol error, a server is terminating the connection because it has received data on the connection that was not consistent with the type of the connection.
|
|
29
|
+
* 1011: Internal server error, a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
|
|
30
|
+
*
|
|
31
|
+
* For reference, here are the valid WebSocket close code ranges:
|
|
32
|
+
* 1000-1999: Reserved for protocol usage
|
|
33
|
+
* 2000-2999: Reserved for WebSocket extensions
|
|
34
|
+
* 3000-3999: Available for libraries and frameworks
|
|
35
|
+
* 4000-4999: Available for applications
|
|
36
|
+
*/
|
|
37
|
+
yield* Effect.addFinalizer(Effect.fn(function* (exit) {
|
|
38
|
+
try {
|
|
39
|
+
if (Exit.isFailure(exit)) {
|
|
40
|
+
socket.close(3000);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
socket.close(1000);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
yield* Effect.die(new WebSocket.WebSocketError({ cause: error }));
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return socket;
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=WebSocket.js.map
|
|
@@ -0,0 +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,yBAAyB,CAAA;AAG3E,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,EAA4E,EAAE,CAC7E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,0BAA0B;IAE1B,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,U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f,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { type D1Database, type D1Result, type DurableObject, type DurableObjectNamespace, type DurableObjectState, type DurableObjectStorage, type DurableObjectStub, type MessageEvent, Request, Response, Rpc, type SqlStorage, SqlStorageCursor, SqlStorageStatement, type SqlStorageValue, WebSocket, WebSocketPair, WebSocketRequestResponsePair, } from '@cloudflare/workers-types';
|
|
2
|
+
//# sourceMappingURL=cf-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-types.d.ts","sourceRoot":"","sources":["../src/cf-types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,OAAO,EACP,QAAQ,EACR,GAAG,EACH,KAAK,UAAU,EACf,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,eAAe,EACpB,SAAS,EACT,aAAa,EACb,4BAA4B,GAC7B,MAAM,2BAA2B,CAAA"}
|
package/dist/cf-types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-types.js","sourceRoot":"","sources":["../src/cf-types.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,OAAO,EACP,QAAQ,EACR,GAAG,EAEH,gBAAgB,EAChB,mBAAmB,EAEnB,SAAS,EACT,aAAa,EACb,4BAA4B,GAC7B,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Adapter, type SyncOptions } from '@livestore/common';
|
|
2
|
+
import type * as CfWorker from './cf-types.ts';
|
|
3
|
+
export declare const makeAdapter: ({ storage, clientId, syncOptions, sessionId, }: {
|
|
4
|
+
storage: CfWorker.DurableObjectStorage;
|
|
5
|
+
clientId: string;
|
|
6
|
+
syncOptions: SyncOptions;
|
|
7
|
+
sessionId: string;
|
|
8
|
+
}) => Adapter;
|
|
9
|
+
//# sourceMappingURL=make-adapter.d.ts.map
|
|
@@ -0,0 +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;AAM1B,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAE9C,eAAO,MAAM,WAAW,GACrB,gDAKE;IACD,OAAO,EAAE,QAAQ,CAAC,oBAAoB,CAAA;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAkHD,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ClientSessionLeaderThreadProxy, liveStoreStorageFormatVersion, makeClientSession, UnexpectedError, } from '@livestore/common';
|
|
2
|
+
import { Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread';
|
|
3
|
+
import { LiveStoreEvent } from '@livestore/livestore';
|
|
4
|
+
import { sqliteDbFactory } from '@livestore/sqlite-wasm/cf';
|
|
5
|
+
import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
|
|
6
|
+
import { Effect, FetchHttpClient, Layer, SubscriptionRef, WebChannel } from '@livestore/utils/effect';
|
|
7
|
+
export const makeAdapter = ({ storage, clientId, syncOptions, sessionId, }) => (adapterArgs) => Effect.gen(function* () {
|
|
8
|
+
const { storeId, /* devtoolsEnabled, shutdown, bootStatusQueue, */ syncPayload, schema } = adapterArgs;
|
|
9
|
+
const devtoolsOptions = { enabled: false };
|
|
10
|
+
const sqlite3 = yield* Effect.promise(() => loadSqlite3Wasm());
|
|
11
|
+
const makeSqliteDb = sqliteDbFactory({ sqlite3 });
|
|
12
|
+
const syncInMemoryDb = yield* makeSqliteDb({ _tag: 'in-memory', storage, configureDb: () => { } }).pipe(UnexpectedError.mapToUnexpectedError);
|
|
13
|
+
const schemaHashSuffix = schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString();
|
|
14
|
+
const dbState = yield* makeSqliteDb({
|
|
15
|
+
_tag: 'storage',
|
|
16
|
+
storage,
|
|
17
|
+
fileName: getStateDbFileName(schemaHashSuffix),
|
|
18
|
+
configureDb: () => { },
|
|
19
|
+
}).pipe(UnexpectedError.mapToUnexpectedError);
|
|
20
|
+
const dbEventlog = yield* makeSqliteDb({
|
|
21
|
+
_tag: 'storage',
|
|
22
|
+
storage,
|
|
23
|
+
fileName: `eventlog@${liveStoreStorageFormatVersion}.db`,
|
|
24
|
+
configureDb: () => { },
|
|
25
|
+
}).pipe(UnexpectedError.mapToUnexpectedError);
|
|
26
|
+
const shutdownChannel = yield* WebChannel.noopChannel();
|
|
27
|
+
// Use Durable Object sync backend if no backend is specified
|
|
28
|
+
const layer = yield* Layer.build(makeLeaderThreadLayer({
|
|
29
|
+
schema,
|
|
30
|
+
storeId,
|
|
31
|
+
clientId,
|
|
32
|
+
makeSqliteDb,
|
|
33
|
+
syncOptions,
|
|
34
|
+
dbState,
|
|
35
|
+
dbEventlog,
|
|
36
|
+
devtoolsOptions,
|
|
37
|
+
shutdownChannel,
|
|
38
|
+
syncPayload,
|
|
39
|
+
}));
|
|
40
|
+
const { leaderThread, initialSnapshot } = yield* Effect.gen(function* () {
|
|
41
|
+
const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState } = yield* LeaderThreadCtx;
|
|
42
|
+
const initialLeaderHead = Eventlog.getClientHeadFromDb(dbEventlog);
|
|
43
|
+
// const initialLeaderHead = EventSequenceNumber.ROOT
|
|
44
|
+
const leaderThread = ClientSessionLeaderThreadProxy.of({
|
|
45
|
+
events: {
|
|
46
|
+
pull: ({ cursor }) => syncProcessor.pull({ cursor }),
|
|
47
|
+
push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.EncodedWithMeta(item)), { waitForProcessing: true }),
|
|
48
|
+
},
|
|
49
|
+
initialState: { leaderHead: initialLeaderHead, migrationsReport: initialState.migrationsReport },
|
|
50
|
+
export: Effect.sync(() => dbState.export()),
|
|
51
|
+
getEventlogData: Effect.sync(() => dbEventlog.export()),
|
|
52
|
+
getSyncState: syncProcessor.syncState,
|
|
53
|
+
sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
|
|
54
|
+
}, {
|
|
55
|
+
// overrides: testing?.overrides?.clientSession?.leaderThreadProxy
|
|
56
|
+
});
|
|
57
|
+
const initialSnapshot = dbState.export();
|
|
58
|
+
return { leaderThread, initialSnapshot };
|
|
59
|
+
}).pipe(Effect.provide(layer));
|
|
60
|
+
syncInMemoryDb.import(initialSnapshot);
|
|
61
|
+
const lockStatus = yield* SubscriptionRef.make('has-lock');
|
|
62
|
+
const clientSession = yield* makeClientSession({
|
|
63
|
+
...adapterArgs,
|
|
64
|
+
sqliteDb: syncInMemoryDb,
|
|
65
|
+
webmeshMode: 'proxy',
|
|
66
|
+
connectWebmeshNode: Effect.fnUntraced(function* ({ webmeshNode }) {
|
|
67
|
+
console.log('connectWebmeshNode', { webmeshNode });
|
|
68
|
+
// if (devtoolsOptions.enabled) {
|
|
69
|
+
// yield* Webmesh.connectViaWebSocket({
|
|
70
|
+
// node: webmeshNode,
|
|
71
|
+
// url: `ws://${devtoolsOptions.host}:${devtoolsOptions.port}`,
|
|
72
|
+
// openTimeout: 500,
|
|
73
|
+
// }).pipe(Effect.tapCauseLogPretty, Effect.forkScoped)
|
|
74
|
+
// }
|
|
75
|
+
}),
|
|
76
|
+
leaderThread,
|
|
77
|
+
lockStatus,
|
|
78
|
+
clientId,
|
|
79
|
+
sessionId,
|
|
80
|
+
isLeader: true,
|
|
81
|
+
// Not really applicable for node as there is no "reload the app" concept
|
|
82
|
+
registerBeforeUnload: (_onBeforeUnload) => () => { },
|
|
83
|
+
});
|
|
84
|
+
return clientSession;
|
|
85
|
+
}).pipe(Effect.withSpan('@livestore/adapter-cloudflare:makeAdapter', { attributes: { clientId, sessionId } }), Effect.provide(FetchHttpClient.layer));
|
|
86
|
+
const getStateDbFileName = (suffix) => `state${suffix}@${liveStoreStorageFormatVersion}.db`;
|
|
87
|
+
//# sourceMappingURL=make-adapter.js.map
|
|
@@ -0,0 +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,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAwB,QAAQ,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACxH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGrG,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,EACC,OAAO,EACP,QAAQ,EACR,WAAW,EACX,SAAS,GAMV,EAAW,EAAE,CACd,CAAC,WAAW,EAAE,EAAE,CACd,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,OAAO,EAAE,kDAAkD,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,WAAW,CAAA;IAEvG,MAAM,eAAe,GAAG,EAAE,OAAO,EAAE,KAAK,EAAqB,CAAA;IAE7D,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAA;IAE9D,MAAM,YAAY,GAAG,eAAe,CAA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estore/livestore';
|
|
3
|
+
import type * as CfSyncBackend from '@livestore/sync-cf/cf-worker';
|
|
4
|
+
import { Effect } from '@livestore/utils/effect';
|
|
5
|
+
import type * as CfWorker from './cf-types.ts';
|
|
6
|
+
export type MakeDurableObjectClassOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = {
|
|
7
|
+
schema: TSchema;
|
|
8
|
+
clientId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
onStoreReady?: (store: Store<TSchema>) => Effect.SyncOrPromiseOrEffect<void, UnexpectedError>;
|
|
11
|
+
registerQueries?: (store: Store<TSchema>) => Effect.SyncOrPromiseOrEffect<ReadonlyArray<Unsubscribe>>;
|
|
12
|
+
syncBackendUrl?: string;
|
|
13
|
+
handleCustomRequest?: (request: CfWorker.Request, ensureStore: Effect.Effect<Store<TSchema>, UnexpectedError, never>) => Effect.SyncOrPromiseOrEffect<CfWorker.Response | undefined, UnexpectedError>;
|
|
14
|
+
};
|
|
15
|
+
export type Env = {
|
|
16
|
+
SYNC_BACKEND_DO: CfWorker.DurableObjectNamespace;
|
|
17
|
+
};
|
|
18
|
+
export type MakeDurableObjectClass = <TSchema extends LiveStoreSchema = LiveStoreSchema.Any>(options: MakeDurableObjectClassOptions<TSchema>) => {
|
|
19
|
+
new (ctx: CfWorker.DurableObjectState, env: Env): CfWorker.DurableObject & CfWorker.Rpc.DurableObjectBranded;
|
|
20
|
+
};
|
|
21
|
+
export type CreateStoreDoOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = {
|
|
22
|
+
schema: TSchema;
|
|
23
|
+
storeId: string;
|
|
24
|
+
clientId: string;
|
|
25
|
+
sessionId: string;
|
|
26
|
+
storage: CfWorker.DurableObjectStorage;
|
|
27
|
+
syncBackendDurableObject: CfWorker.DurableObjectStub<CfSyncBackend.SyncBackendRpcInterface>;
|
|
28
|
+
durableObjectId: string;
|
|
29
|
+
bindingName: string;
|
|
30
|
+
livePull?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare const createStoreDo: <TSchema extends LiveStoreSchema = LiveStoreSchema.Any>({ schema, storeId, clientId, sessionId, storage, syncBackendDurableObject, durableObjectId, bindingName, livePull, }: CreateStoreDoOptions<TSchema>) => Effect.Effect<Store<TSchema, {}>, UnexpectedError, never>;
|
|
33
|
+
export declare const createStoreDoPromise: <TSchema extends LiveStoreSchema = LiveStoreSchema.Any>(options: CreateStoreDoOptions<TSchema>) => Promise<Store<TSchema, {}>>;
|
|
34
|
+
//# sourceMappingURL=make-client-durable-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-client-durable-object.d.ts","sourceRoot":"","sources":["../src/make-client-durable-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAe,KAAK,eAAe,EAAe,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACnH,OAAO,KAAK,KAAK,aAAa,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,MAAM,EAA2B,MAAM,yBAAyB,CAAA;AACzE,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAK9C,MAAM,MAAM,6BAA6B,CAAC,OAAO,SAAS,eAAe,GAAG,eAAe,CAAC,GAAG,IAAI;IACjG,MAAM,EAAE,OAAO,CAAA;IAEf,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAA;IAG7F,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,qBAAqB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAA;IACrG,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB,mBA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eAAe,GAAG,eAAe,CAAC,GAAG,EACxF,SAAS,oBAAoB,CAAC,OAAO,CAAC,gCAOrC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createStore, provideOtel } from '@livestore/livestore';
|
|
2
|
+
import { makeDoRpcSync } from '@livestore/sync-cf/client';
|
|
3
|
+
import { Effect, Logger, LogLevel, Scope } from '@livestore/utils/effect';
|
|
4
|
+
import { makeAdapter } from "./make-adapter.js";
|
|
5
|
+
export const createStoreDo = ({ schema, storeId, clientId, sessionId, storage, syncBackendDurableObject, durableObjectId, bindingName, livePull = false, }) => Effect.gen(function* () {
|
|
6
|
+
const scope = yield* Scope.make();
|
|
7
|
+
const adapter = makeAdapter({
|
|
8
|
+
clientId,
|
|
9
|
+
sessionId,
|
|
10
|
+
storage,
|
|
11
|
+
syncOptions: {
|
|
12
|
+
backend: makeDoRpcSync({
|
|
13
|
+
syncBackendStub: syncBackendDurableObject,
|
|
14
|
+
durableObjectContext: { bindingName, durableObjectId },
|
|
15
|
+
}),
|
|
16
|
+
livePull, // Uses DO RPC callbacks for reactive pull
|
|
17
|
+
// backend: makeHttpSync({ url: `http://localhost:8787`, livePull: { pollInterval: 500 } }),
|
|
18
|
+
initialSyncOptions: { _tag: 'Blocking', timeout: 500 },
|
|
19
|
+
// backend: makeWsSyncProviderClient({ durableObject: syncBackendDurableObject }),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return yield* createStore({ schema, adapter, storeId }).pipe(Scope.extend(scope), provideOtel({}));
|
|
23
|
+
});
|
|
24
|
+
export const createStoreDoPromise = (options) => createStoreDo(options).pipe(Logger.withMinimumLogLevel(LogLevel.Debug), Effect.provide(Logger.consoleWithThread('DoClient')), Effect.tapCauseLogPretty, Effect.runPromise);
|
|
25
|
+
//# sourceMappingURL=make-client-durable-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-client-durable-object.js","sourceRoot":"","sources":["../src/make-client-durable-object.ts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C,CAAC,IAAI,CACzB,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC1C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,EACpD,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,UAAU,CAClB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MakeSqliteDb, PersistenceInfo, SqliteDb } from '@livestore/common';
|
|
2
|
+
import type * as CfWorker from './cf-types.ts';
|
|
3
|
+
type Metadata = {
|
|
4
|
+
_tag: 'file';
|
|
5
|
+
dbPointer: number;
|
|
6
|
+
persistenceInfo: PersistenceInfo;
|
|
7
|
+
input: CloudflareDatabaseInput;
|
|
8
|
+
configureDb: (db: SqliteDb) => void;
|
|
9
|
+
};
|
|
10
|
+
type CloudflareDatabaseInput = {
|
|
11
|
+
_tag: 'file';
|
|
12
|
+
db: CfWorker.SqlStorage;
|
|
13
|
+
configureDb: (db: SqliteDb) => void;
|
|
14
|
+
} | {
|
|
15
|
+
_tag: 'in-memory';
|
|
16
|
+
db: CfWorker.SqlStorage;
|
|
17
|
+
configureDb: (db: SqliteDb) => void;
|
|
18
|
+
};
|
|
19
|
+
export type MakeCloudflareSqliteDb = MakeSqliteDb<Metadata, CloudflareDatabaseInput, {
|
|
20
|
+
_tag: 'cloudflare';
|
|
21
|
+
} & Metadata>;
|
|
22
|
+
export declare const makeSqliteDb: MakeCloudflareSqliteDb;
|
|
23
|
+
export declare const makeSqliteDb_: <TMetadata extends {
|
|
24
|
+
persistenceInfo: PersistenceInfo;
|
|
25
|
+
configureDb: (db: SqliteDb<TMetadata>) => void;
|
|
26
|
+
}>({ sqlStorage, metadata, }: {
|
|
27
|
+
sqlStorage: CfWorker.SqlStorage;
|
|
28
|
+
metadata: TMetadata;
|
|
29
|
+
}) => SqliteDb<TMetadata>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=make-sqlite-db.d.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AQ,CAAC,SAAS,CAuHrB,CAAA"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { SqliteDbHelper, SqliteError } from '@livestore/common';
|
|
2
|
+
import { EventSequenceNumber } from '@livestore/common/schema';
|
|
3
|
+
import { Effect } from '@livestore/utils/effect';
|
|
4
|
+
// Simplified prepared statement implementation using only public API
|
|
5
|
+
class CloudflarePreparedStatement {
|
|
6
|
+
sqlStorage;
|
|
7
|
+
sql;
|
|
8
|
+
constructor(sqlStorage, sql) {
|
|
9
|
+
this.sqlStorage = sqlStorage;
|
|
10
|
+
this.sql = sql;
|
|
11
|
+
}
|
|
12
|
+
execute = (bindValues, options) => {
|
|
13
|
+
try {
|
|
14
|
+
const cursor = this.sqlStorage.exec(this.sql, ...(bindValues ? Object.values(bindValues) : []));
|
|
15
|
+
// Count affected rows by iterating through cursor
|
|
16
|
+
let changedCount = 0;
|
|
17
|
+
for (const _row of cursor) {
|
|
18
|
+
changedCount++;
|
|
19
|
+
}
|
|
20
|
+
if (options?.onRowsChanged) {
|
|
21
|
+
options.onRowsChanged(changedCount);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw new SqliteError({
|
|
26
|
+
query: { bindValues: bindValues ?? {}, sql: this.sql },
|
|
27
|
+
code: e.code ?? -1,
|
|
28
|
+
cause: e,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
select = (bindValues) => {
|
|
33
|
+
try {
|
|
34
|
+
const cursor = this.sqlStorage.exec(this.sql, ...(bindValues ? Object.values(bindValues) : []));
|
|
35
|
+
const results = [];
|
|
36
|
+
for (const row of cursor) {
|
|
37
|
+
results.push(row);
|
|
38
|
+
}
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw new SqliteError({
|
|
43
|
+
query: { bindValues: bindValues ?? {}, sql: this.sql },
|
|
44
|
+
code: e.code ?? -1,
|
|
45
|
+
cause: e,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
finalize = () => {
|
|
50
|
+
// No-op for public API - statements are automatically cleaned up
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export const makeSqliteDb = (input) => Effect.gen(function* () {
|
|
54
|
+
// console.log('makeSqliteDb', input)
|
|
55
|
+
if (input._tag === 'in-memory') {
|
|
56
|
+
return makeSqliteDb_({
|
|
57
|
+
sqlStorage: input.db,
|
|
58
|
+
metadata: {
|
|
59
|
+
_tag: 'file',
|
|
60
|
+
dbPointer: 0,
|
|
61
|
+
// persistenceInfo: { fileName: ':memory:' },
|
|
62
|
+
persistenceInfo: { fileName: 'cf' },
|
|
63
|
+
input,
|
|
64
|
+
configureDb: input.configureDb,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (input._tag === 'file') {
|
|
69
|
+
return makeSqliteDb_({
|
|
70
|
+
sqlStorage: input.db,
|
|
71
|
+
metadata: {
|
|
72
|
+
_tag: 'file',
|
|
73
|
+
dbPointer: 0,
|
|
74
|
+
// persistenceInfo: { fileName: `${input.directory}/${input.databaseName}` },
|
|
75
|
+
persistenceInfo: { fileName: 'cf' },
|
|
76
|
+
input,
|
|
77
|
+
configureDb: input.configureDb,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
export const makeSqliteDb_ = ({ sqlStorage, metadata, }) => {
|
|
83
|
+
const preparedStmts = [];
|
|
84
|
+
let isClosed = false;
|
|
85
|
+
const sqliteDb = {
|
|
86
|
+
_tag: 'SqliteDb',
|
|
87
|
+
metadata,
|
|
88
|
+
debug: {
|
|
89
|
+
// Setting initially to root but will be set to correct value shortly after
|
|
90
|
+
head: EventSequenceNumber.ROOT,
|
|
91
|
+
},
|
|
92
|
+
prepare: (queryStr) => {
|
|
93
|
+
try {
|
|
94
|
+
const preparedStmt = new CloudflarePreparedStatement(sqlStorage, queryStr.trim());
|
|
95
|
+
preparedStmts.push(preparedStmt);
|
|
96
|
+
return preparedStmt;
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
throw new SqliteError({
|
|
100
|
+
query: { sql: queryStr, bindValues: {} },
|
|
101
|
+
code: e.code ?? -1,
|
|
102
|
+
cause: e,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
export: () => {
|
|
107
|
+
// NOTE: Database export not supported with public API
|
|
108
|
+
// This functionality requires undocumented serialize() method
|
|
109
|
+
// throw new SqliteError({
|
|
110
|
+
// query: { sql: 'export', bindValues: {} },
|
|
111
|
+
// code: -1,
|
|
112
|
+
// cause: 'Database export not supported with public SqlStorage API',
|
|
113
|
+
// })
|
|
114
|
+
return new Uint8Array();
|
|
115
|
+
},
|
|
116
|
+
execute: SqliteDbHelper.makeExecute((queryStr, bindValues, options) => {
|
|
117
|
+
const stmt = sqliteDb.prepare(queryStr);
|
|
118
|
+
stmt.execute(bindValues, options);
|
|
119
|
+
stmt.finalize();
|
|
120
|
+
}),
|
|
121
|
+
select: SqliteDbHelper.makeSelect((queryStr, bindValues) => {
|
|
122
|
+
const stmt = sqliteDb.prepare(queryStr);
|
|
123
|
+
const results = stmt.select(bindValues);
|
|
124
|
+
stmt.finalize();
|
|
125
|
+
return results;
|
|
126
|
+
}),
|
|
127
|
+
destroy: () => {
|
|
128
|
+
sqliteDb.close();
|
|
129
|
+
// metadata.deleteDb()
|
|
130
|
+
throw new SqliteError({
|
|
131
|
+
code: -1,
|
|
132
|
+
cause: 'Database destroy not supported with public SqlStorage API',
|
|
133
|
+
});
|
|
134
|
+
// if (metadata._tag === 'opfs') {
|
|
135
|
+
// metadata.vfs.resetAccessHandle(metadata.fileName)
|
|
136
|
+
// }
|
|
137
|
+
},
|
|
138
|
+
close: () => {
|
|
139
|
+
if (isClosed) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const stmt of preparedStmts) {
|
|
143
|
+
stmt.finalize();
|
|
144
|
+
}
|
|
145
|
+
// NOTE: Database close not supported with public API
|
|
146
|
+
// The database is automatically cleaned up by the runtime
|
|
147
|
+
isClosed = true;
|
|
148
|
+
},
|
|
149
|
+
import: (_source) => {
|
|
150
|
+
// NOTE: Database import not supported with public API
|
|
151
|
+
// This functionality requires undocumented deserialize() and backup() methods
|
|
152
|
+
// throw new SqliteError({
|
|
153
|
+
// query: { sql: 'import', bindValues: {} },
|
|
154
|
+
// code: -1,
|
|
155
|
+
// cause: 'Database import not supported with public SqlStorage API',
|
|
156
|
+
// })
|
|
157
|
+
},
|
|
158
|
+
session: () => {
|
|
159
|
+
// NOTE: Session tracking not supported with public API
|
|
160
|
+
// This functionality requires undocumented session_* methods
|
|
161
|
+
// throw new SqliteError({
|
|
162
|
+
// query: { sql: 'session', bindValues: {} },
|
|
163
|
+
// code: -1,
|
|
164
|
+
// cause: 'Session tracking not supported with public SqlStorage API',
|
|
165
|
+
// })
|
|
166
|
+
return {
|
|
167
|
+
changeset: () => new Uint8Array(),
|
|
168
|
+
finish: () => { },
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
makeChangeset: (_data) => {
|
|
172
|
+
// NOTE: Changeset operations not supported with public API
|
|
173
|
+
// This functionality requires undocumented changeset_* methods
|
|
174
|
+
const changeset = {
|
|
175
|
+
invert: () => {
|
|
176
|
+
throw new SqliteError({
|
|
177
|
+
code: -1,
|
|
178
|
+
cause: 'Changeset invert not supported with public SqlStorage API',
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
apply: () => {
|
|
182
|
+
throw new SqliteError({
|
|
183
|
+
code: -1,
|
|
184
|
+
cause: 'Changeset apply not supported with public SqlStorage API',
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
return changeset;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
metadata.configureDb(sqliteDb);
|
|
192
|
+
return sqliteDb;
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingUR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AAI,CAAA;QACjB,CAAC;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,sDAAsD;YACtD,8EAA8E;YAC9E,0BAA0B;YAC1B,8CAA8C;YAC9C,cAAc;YACd,uEAAuE;YACvE,KAAK;QACP,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,uDAAuD;YACvD,6DAA6D;YAC7D,0BAA0B;YAC1B,+CAA+C;YAC/C,cAAc;YACd,wEAAwE;YACxE,KAAK;YACL,OAAO;gBACL,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,UAAU,EAAE;gBACjC,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;aACS,CAAA;QAC7B,CAAC;QACD,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;YACvB,2DAA2D;YAC3D,+DAA+D;YAC/D,MAAM,SAAS,GAAG;gBAChB,MAAM,EAAE,GAAG,EAAE;oBACX,MAAM,IAAI,WAAW,CAAC;wBACpB,IAAI,EAAE,CAAC,CAAC;wBACR,KAAK,EAAE,2DAA2D;qBACnE,CAAC,CAAA;gBACJ,CAAC;gBACD,KAAK,EAAE,GAAG,EAAE;oBACV,MAAM,IAAI,WAAW,CAAC;wBACpB,IAAI,EAAE,CAAC,CAAC;wBACR,KAAK,EAAE,0DAA0D;qBAClE,CAAC,CAAA;gBACJ,CAAC;aAC0B,CAAA;YAE7B,OAAO,SAAS,CAAA;QAClB,CAAC;KAC4B,CAAA;IAE/B,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IAE9B,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import './polyfill.ts';
|
|
2
|
+
export type { ClientDoWithRpcCallback } from '@livestore/common-cf';
|
|
3
|
+
export { makeAdapter } from './make-adapter.ts';
|
|
4
|
+
export { type CreateStoreDoOptions, createStoreDo, createStoreDoPromise, type Env, type MakeDurableObjectClass, type MakeDurableObjectClassOptions, } from './make-client-durable-object.ts';
|
|
5
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAEtB,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EACL,KAAK,oBAAoB,EACzB,aAAa,EACb,oBAAoB,EACpB,KAAK,GAAG,EACR,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,GACnC,MAAM,iCAAiC,CAAA"}
|
package/dist/mod.js
ADDED
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAEL,aAAa,EACb,oBAAoB,GAIrB,MAAM,iCAAiC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":""}
|
package/dist/polyfill.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
// TODO remove all unused polyfills once we're closer to the release
|
|
3
|
+
globalThis.performance = globalThis.performance ?? {};
|
|
4
|
+
globalThis.performance.mark = globalThis.performance.mark ?? (() => { });
|
|
5
|
+
globalThis.performance.measure = globalThis.performance.measure ?? (() => { });
|
|
6
|
+
globalThis.performance.now = globalThis.performance.now ?? (() => -1);
|
|
7
|
+
if (typeof globalThis.location === 'undefined') {
|
|
8
|
+
globalThis.location = {
|
|
9
|
+
href: 'https://worker.cloudflare.com/',
|
|
10
|
+
origin: 'https://worker.cloudflare.com',
|
|
11
|
+
protocol: 'https:',
|
|
12
|
+
host: 'worker.cloudflare.com',
|
|
13
|
+
hostname: 'worker.cloudflare.com',
|
|
14
|
+
port: '',
|
|
15
|
+
pathname: '/',
|
|
16
|
+
search: '',
|
|
17
|
+
hash: '',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (typeof globalThis.document === 'undefined') {
|
|
21
|
+
globalThis.document = {
|
|
22
|
+
createElement: () => ({ href: '', pathname: '', search: '', origin: '' }),
|
|
23
|
+
head: { appendChild: () => { } },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// WeakRef polyfill for Cloudflare Workers
|
|
27
|
+
if (typeof WeakRef === 'undefined') {
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
globalThis.WeakRef = class WeakRef {
|
|
30
|
+
target;
|
|
31
|
+
constructor(target) {
|
|
32
|
+
this.target = target;
|
|
33
|
+
}
|
|
34
|
+
deref() {
|
|
35
|
+
return this.target;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,oEAAoE;AACpE,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,IAAI,EAAE,CAAA;AACrD,UAAU,CAAC,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AACvE,UAAU,CAAC,WAAW,CAAC,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AAC7E,UAAU,CAAC,WAAW,CAAC,GAAG,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAErE,IAAI,OAAO,UAAU,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;IAC/C,UAAU,CAAC,QAAQ,GAAG;QACpB,IAAI,EAAE,gCAAgC;QACtC,MAAM,EAAE,+BAA+B;QACvC,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,uBAAuB;QAC7B,QAAQ,EAAE,uBAAuB;QACjC,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,GAAG;QACb,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;KACG,CAAA;AACf,CAAC;AAED,IAAI,OAAO,UAAU,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;IAC/C,UAAU,CAAC,QAAQ,GAAG;QACpB,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACzE,IAAI,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE;KACzB,CAAA;AACV,CAAC;AAED,0CAA0C;AAC1C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;IACnC,mBAAmB;IACnB,UAAU,CAAC,OAAO,GAAG,MAAM,OAAO;QACxB,MAAM,CAAe;QAE7B,YAAY,MAAS;YACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,CAAC;QAED,KAAK;YACH,OAAO,IAAI,CAAC,MAAM,CAAA;QACpB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SyncBackendConstructor } from '@livestore/common';
|
|
2
|
+
import type { WSMessage } from '@livestore/sync-cf/common';
|
|
3
|
+
import type * as CfWorker from './cf-types.ts';
|
|
4
|
+
export type MakeDurableObjectSyncBackendOptions = {
|
|
5
|
+
/** WebSocket URL to connect to the sync backend Durable Object */
|
|
6
|
+
durableObject: CfWorker.DurableObjectStub;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Specialized sync backend used for Cloudflare Workers compatible only with `@livestore/sync-cf`
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeSyncProviderClient: ({ durableObject }: MakeDurableObjectSyncBackendOptions) => SyncBackendConstructor<WSMessage.SyncMetadata>;
|
|
12
|
+
//# sourceMappingURL=sync-provider-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-provider-client.d.ts","sourceRoot":"","sources":["../src/sync-provider-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAG9C,MAAM,MAAM,mCAAmC,GAAG;IAChD,kEAAkE;IAClE,aAAa,EAAE,QAAQ,CAAC,iBAAiB,CAAA;CAC1C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAChC,mBAAmB,mCAAmC,KAAG,sBAAsB,CAAC,SAAS,CAAC,YAAY,CAqBtG,CAAA"}
|