@livestore/adapter-web 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/README.md +5 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/in-memory/in-memory-adapter.d.ts +49 -5
- package/dist/in-memory/in-memory-adapter.d.ts.map +1 -1
- package/dist/in-memory/in-memory-adapter.js +77 -20
- package/dist/in-memory/in-memory-adapter.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/single-tab/mod.d.ts +15 -0
- package/dist/single-tab/mod.d.ts.map +1 -0
- package/dist/single-tab/mod.js +15 -0
- package/dist/single-tab/mod.js.map +1 -0
- package/dist/single-tab/single-tab-adapter.d.ts +108 -0
- package/dist/single-tab/single-tab-adapter.d.ts.map +1 -0
- package/dist/single-tab/single-tab-adapter.js +271 -0
- package/dist/single-tab/single-tab-adapter.js.map +1 -0
- package/dist/web-worker/client-session/client-session-devtools.d.ts +2 -2
- package/dist/web-worker/client-session/client-session-devtools.d.ts.map +1 -1
- package/dist/web-worker/client-session/client-session-devtools.js +20 -9
- package/dist/web-worker/client-session/client-session-devtools.js.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.d.ts +18 -0
- package/dist/web-worker/client-session/persisted-adapter.d.ts.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.js +141 -67
- package/dist/web-worker/client-session/persisted-adapter.js.map +1 -1
- package/dist/web-worker/client-session/sqlite-loader.d.ts +2 -0
- package/dist/web-worker/client-session/sqlite-loader.d.ts.map +1 -0
- package/dist/web-worker/client-session/sqlite-loader.js +16 -0
- package/dist/web-worker/client-session/sqlite-loader.js.map +1 -0
- package/dist/web-worker/common/persisted-sqlite.d.ts +11 -29
- package/dist/web-worker/common/persisted-sqlite.d.ts.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.js +87 -188
- package/dist/web-worker/common/persisted-sqlite.js.map +1 -1
- package/dist/web-worker/common/shutdown-channel.d.ts +3 -2
- package/dist/web-worker/common/shutdown-channel.d.ts.map +1 -1
- package/dist/web-worker/common/shutdown-channel.js +2 -2
- package/dist/web-worker/common/shutdown-channel.js.map +1 -1
- package/dist/web-worker/common/worker-disconnect-channel.d.ts +2 -6
- package/dist/web-worker/common/worker-disconnect-channel.d.ts.map +1 -1
- package/dist/web-worker/common/worker-disconnect-channel.js +3 -2
- package/dist/web-worker/common/worker-disconnect-channel.js.map +1 -1
- package/dist/web-worker/common/worker-schema.d.ts +152 -58
- package/dist/web-worker/common/worker-schema.d.ts.map +1 -1
- package/dist/web-worker/common/worker-schema.js +55 -37
- package/dist/web-worker/common/worker-schema.js.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.d.ts +5 -3
- package/dist/web-worker/leader-worker/make-leader-worker.d.ts.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.js +98 -38
- package/dist/web-worker/leader-worker/make-leader-worker.js.map +1 -1
- package/dist/web-worker/shared-worker/make-shared-worker.d.ts +2 -1
- package/dist/web-worker/shared-worker/make-shared-worker.d.ts.map +1 -1
- package/dist/web-worker/shared-worker/make-shared-worker.js +62 -52
- package/dist/web-worker/shared-worker/make-shared-worker.js.map +1 -1
- package/package.json +56 -18
- package/src/in-memory/in-memory-adapter.ts +92 -26
- package/src/index.ts +15 -1
- package/src/single-tab/mod.ts +15 -0
- package/src/single-tab/single-tab-adapter.ts +499 -0
- package/src/web-worker/ambient.d.ts +7 -24
- package/src/web-worker/client-session/client-session-devtools.ts +32 -18
- package/src/web-worker/client-session/persisted-adapter.ts +199 -103
- package/src/web-worker/client-session/sqlite-loader.ts +19 -0
- package/src/web-worker/common/persisted-sqlite.ts +200 -298
- package/src/web-worker/common/shutdown-channel.ts +10 -3
- package/src/web-worker/common/worker-disconnect-channel.ts +10 -3
- package/src/web-worker/common/worker-schema.ts +78 -38
- package/src/web-worker/leader-worker/make-leader-worker.ts +148 -71
- package/src/web-worker/shared-worker/make-shared-worker.ts +78 -90
- package/dist/opfs-utils.d.ts +0 -7
- package/dist/opfs-utils.d.ts.map +0 -1
- package/dist/opfs-utils.js +0 -43
- package/dist/opfs-utils.js.map +0 -1
- package/src/opfs-utils.ts +0 -61
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type Adapter, type SyncOptions,
|
|
1
|
+
import { type Adapter, type SyncOptions, UnknownError } from '@livestore/common';
|
|
2
2
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
3
3
|
import type * as WebmeshWorker from '@livestore/devtools-web-common/worker';
|
|
4
4
|
import type { MakeWebSqliteDb } from '@livestore/sqlite-wasm/browser';
|
|
5
|
-
import type
|
|
6
|
-
import { Fiber, Worker } from '@livestore/utils/effect';
|
|
5
|
+
import { Fiber, type Schema, Worker } from '@livestore/utils/effect';
|
|
7
6
|
export interface InMemoryAdapterOptions {
|
|
8
7
|
importSnapshot?: Uint8Array<ArrayBuffer>;
|
|
9
8
|
sync?: SyncOptions;
|
|
@@ -28,6 +27,50 @@ export interface InMemoryAdapterOptions {
|
|
|
28
27
|
}) => globalThis.SharedWorker);
|
|
29
28
|
};
|
|
30
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a web-only in-memory LiveStore adapter.
|
|
32
|
+
*
|
|
33
|
+
* This adapter runs entirely in memory with no persistence. Ideal for:
|
|
34
|
+
* - Unit tests and integration tests
|
|
35
|
+
* - Sandboxes and demos
|
|
36
|
+
* - Ephemeral sessions where persistence isn't needed
|
|
37
|
+
*
|
|
38
|
+
* **Characteristics:**
|
|
39
|
+
* - Fast, zero I/O overhead
|
|
40
|
+
* - Works in all browser contexts: Window, WebWorker, SharedWorker, ServiceWorker
|
|
41
|
+
* - Supports optional sync backends for real-time collaboration
|
|
42
|
+
* - No data persists after page reload
|
|
43
|
+
*
|
|
44
|
+
* For persistent storage, use `makePersistedAdapter` instead.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
49
|
+
*
|
|
50
|
+
* const adapter = makeInMemoryAdapter()
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // With sync backend for real-time collaboration
|
|
56
|
+
* import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
57
|
+
* import { makeWsSync } from '@livestore/sync-cf/client'
|
|
58
|
+
*
|
|
59
|
+
* const adapter = makeInMemoryAdapter({
|
|
60
|
+
* sync: {
|
|
61
|
+
* backend: makeWsSync({ url: 'wss://api.example.com/sync' }),
|
|
62
|
+
* },
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Pre-populate with existing data
|
|
69
|
+
* const adapter = makeInMemoryAdapter({
|
|
70
|
+
* importSnapshot: existingDbSnapshot,
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
31
74
|
export declare const makeInMemoryAdapter: (options?: InMemoryAdapterOptions) => Adapter;
|
|
32
75
|
export interface MakeLeaderThreadArgs {
|
|
33
76
|
schema: LiveStoreSchema;
|
|
@@ -35,11 +78,12 @@ export interface MakeLeaderThreadArgs {
|
|
|
35
78
|
clientId: string;
|
|
36
79
|
makeSqliteDb: MakeWebSqliteDb;
|
|
37
80
|
syncOptions: SyncOptions | undefined;
|
|
38
|
-
|
|
81
|
+
syncPayloadEncoded: Schema.JsonValue | undefined;
|
|
82
|
+
syncPayloadSchema: Schema.Schema<any> | undefined;
|
|
39
83
|
importSnapshot: Uint8Array<ArrayBuffer> | undefined;
|
|
40
84
|
devtoolsEnabled: boolean;
|
|
41
85
|
sharedWorkerFiber: SharedWorkerFiber | undefined;
|
|
42
86
|
}
|
|
43
|
-
type SharedWorkerFiber = Fiber.Fiber<Worker.SerializedWorkerPool<typeof WebmeshWorker.Schema.Request.Type>,
|
|
87
|
+
type SharedWorkerFiber = Fiber.Fiber<Worker.SerializedWorkerPool<typeof WebmeshWorker.Schema.Request.Type>, UnknownError>;
|
|
44
88
|
export {};
|
|
45
89
|
//# sourceMappingURL=in-memory-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-adapter.d.ts","sourceRoot":"","sources":["../../src/in-memory/in-memory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAMZ,KAAK,WAAW,EAChB,
|
|
1
|
+
{"version":3,"file":"in-memory-adapter.d.ts","sourceRoot":"","sources":["../../src/in-memory/in-memory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAMZ,KAAK,WAAW,EAChB,YAAY,EACb,MAAM,mBAAmB,CAAA;AAS1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG/D,OAAO,KAAK,KAAK,aAAa,MAAM,uCAAuC,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAIrE,OAAO,EAA2B,KAAK,EAAS,KAAK,MAAM,EAAmB,MAAM,EAAE,MAAM,yBAAyB,CAAA;AASrH,MAAM,WAAW,sBAAsB;IACrC,cAAc,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;IACxC,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,sGAAsG;IACtG,QAAQ,CAAC,EAAE;QACT,YAAY,EACR,CAAC,CAAC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,KAAK,UAAU,CAAC,YAAY,CAAC,GACxD,CAAC,KAAK,OAAO,EAAE;YACb,IAAI,EAAE,MAAM,CAAA;SACb,KAAK,UAAU,CAAC,YAAY,CAAC,CAAA;KACnC,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,mBAAmB,GAC7B,UAAS,sBAA2B,KAAG,OA+EwC,CAAA;AAElF,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,eAAe,CAAA;IAC7B,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;IACpC,kBAAkB,EAAE,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;IAChD,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;IACjD,cAAc,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;IACnD,eAAe,EAAE,OAAO,CAAA;IACxB,iBAAiB,EAAE,iBAAiB,GAAG,SAAS,CAAA;CACjD;AAoGD,KAAK,iBAAiB,GAAG,KAAK,CAAC,KAAK,CAClC,MAAM,CAAC,oBAAoB,CAAC,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EACrE,YAAY,CACb,CAAA"}
|
|
@@ -1,33 +1,76 @@
|
|
|
1
|
-
import { ClientSessionLeaderThreadProxy, Devtools, makeClientSession, migrateDb,
|
|
2
|
-
import { configureConnection, Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread';
|
|
1
|
+
import { ClientSessionLeaderThreadProxy, Devtools, makeClientSession, migrateDb, UnknownError, } from '@livestore/common';
|
|
2
|
+
import { configureConnection, Eventlog, LeaderThreadCtx, makeLeaderThreadLayer, streamEventsWithSyncState, } from '@livestore/common/leader-thread';
|
|
3
3
|
import { LiveStoreEvent } from '@livestore/common/schema';
|
|
4
4
|
import * as DevtoolsWeb from '@livestore/devtools-web-common/web-channel';
|
|
5
5
|
import { sqliteDbFactory } from '@livestore/sqlite-wasm/browser';
|
|
6
|
-
import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
|
|
7
6
|
import { tryAsFunctionAndNew } from '@livestore/utils';
|
|
8
|
-
import {
|
|
7
|
+
import { Effect, FetchHttpClient, Fiber, Layer, SubscriptionRef, Worker } from '@livestore/utils/effect';
|
|
8
|
+
import { BrowserWorker } from '@livestore/utils/effect/browser';
|
|
9
9
|
import { nanoid } from '@livestore/utils/nanoid';
|
|
10
10
|
import * as Webmesh from '@livestore/webmesh';
|
|
11
11
|
import { connectWebmeshNodeClientSession } from "../web-worker/client-session/client-session-devtools.js";
|
|
12
|
+
import { loadSqlite3 } from "../web-worker/client-session/sqlite-loader.js";
|
|
12
13
|
import { makeShutdownChannel } from "../web-worker/common/shutdown-channel.js";
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates a web-only in-memory LiveStore adapter.
|
|
16
|
+
*
|
|
17
|
+
* This adapter runs entirely in memory with no persistence. Ideal for:
|
|
18
|
+
* - Unit tests and integration tests
|
|
19
|
+
* - Sandboxes and demos
|
|
20
|
+
* - Ephemeral sessions where persistence isn't needed
|
|
21
|
+
*
|
|
22
|
+
* **Characteristics:**
|
|
23
|
+
* - Fast, zero I/O overhead
|
|
24
|
+
* - Works in all browser contexts: Window, WebWorker, SharedWorker, ServiceWorker
|
|
25
|
+
* - Supports optional sync backends for real-time collaboration
|
|
26
|
+
* - No data persists after page reload
|
|
27
|
+
*
|
|
28
|
+
* For persistent storage, use `makePersistedAdapter` instead.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
33
|
+
*
|
|
34
|
+
* const adapter = makeInMemoryAdapter()
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* // With sync backend for real-time collaboration
|
|
40
|
+
* import { makeInMemoryAdapter } from '@livestore/adapter-web'
|
|
41
|
+
* import { makeWsSync } from '@livestore/sync-cf/client'
|
|
42
|
+
*
|
|
43
|
+
* const adapter = makeInMemoryAdapter({
|
|
44
|
+
* sync: {
|
|
45
|
+
* backend: makeWsSync({ url: 'wss://api.example.com/sync' }),
|
|
46
|
+
* },
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Pre-populate with existing data
|
|
53
|
+
* const adapter = makeInMemoryAdapter({
|
|
54
|
+
* importSnapshot: existingDbSnapshot,
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
15
58
|
export const makeInMemoryAdapter = (options = {}) => (adapterArgs) => Effect.gen(function* () {
|
|
16
|
-
const { schema, shutdown,
|
|
17
|
-
const sqlite3 = yield* Effect.promise(() =>
|
|
59
|
+
const { schema, shutdown, syncPayloadEncoded, syncPayloadSchema, storeId, devtoolsEnabled } = adapterArgs;
|
|
60
|
+
const sqlite3 = yield* Effect.promise(() => loadSqlite3());
|
|
18
61
|
const sqliteDb = yield* sqliteDbFactory({ sqlite3 })({ _tag: 'in-memory' });
|
|
19
62
|
const clientId = options.clientId ?? nanoid(6);
|
|
20
63
|
const sessionId = options.sessionId ?? nanoid(6);
|
|
21
|
-
const sharedWebWorker = options.devtools?.sharedWorker
|
|
64
|
+
const sharedWebWorker = options.devtools?.sharedWorker !== undefined
|
|
22
65
|
? tryAsFunctionAndNew(options.devtools.sharedWorker, {
|
|
23
66
|
name: `livestore-shared-worker-${storeId}`,
|
|
24
67
|
})
|
|
25
68
|
: undefined;
|
|
26
|
-
const sharedWorkerFiber = sharedWebWorker
|
|
69
|
+
const sharedWorkerFiber = sharedWebWorker !== undefined
|
|
27
70
|
? yield* Worker.makePoolSerialized({
|
|
28
71
|
size: 1,
|
|
29
72
|
concurrency: 100,
|
|
30
|
-
}).pipe(Effect.provide(BrowserWorker.layer(() => sharedWebWorker)), Effect.tapCauseLogPretty,
|
|
73
|
+
}).pipe(Effect.provide(BrowserWorker.layer(() => sharedWebWorker)), Effect.tapCauseLogPretty, UnknownError.mapToUnknownError, Effect.forkScoped)
|
|
31
74
|
: undefined;
|
|
32
75
|
const { leaderThread, initialSnapshot } = yield* makeLeaderThread({
|
|
33
76
|
schema,
|
|
@@ -35,7 +78,8 @@ export const makeInMemoryAdapter = (options = {}) => (adapterArgs) => Effect.gen
|
|
|
35
78
|
clientId,
|
|
36
79
|
makeSqliteDb: sqliteDbFactory({ sqlite3 }),
|
|
37
80
|
syncOptions: options.sync,
|
|
38
|
-
|
|
81
|
+
syncPayloadEncoded,
|
|
82
|
+
syncPayloadSchema,
|
|
39
83
|
importSnapshot: options.importSnapshot,
|
|
40
84
|
devtoolsEnabled,
|
|
41
85
|
sharedWorkerFiber,
|
|
@@ -52,6 +96,8 @@ export const makeInMemoryAdapter = (options = {}) => (adapterArgs) => Effect.gen
|
|
|
52
96
|
lockStatus,
|
|
53
97
|
shutdown,
|
|
54
98
|
webmeshMode: 'direct',
|
|
99
|
+
// Can be undefined in Node.js
|
|
100
|
+
origin: globalThis.location?.origin,
|
|
55
101
|
connectWebmeshNode: ({ sessionInfo, webmeshNode }) => Effect.gen(function* () {
|
|
56
102
|
if (sharedWorkerFiber === undefined || devtoolsEnabled === false) {
|
|
57
103
|
return;
|
|
@@ -68,8 +114,8 @@ export const makeInMemoryAdapter = (options = {}) => (adapterArgs) => Effect.gen
|
|
|
68
114
|
},
|
|
69
115
|
});
|
|
70
116
|
return clientSession;
|
|
71
|
-
}).pipe(
|
|
72
|
-
const makeLeaderThread = ({ schema, storeId, clientId, makeSqliteDb, syncOptions,
|
|
117
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.provide(FetchHttpClient.layer));
|
|
118
|
+
const makeLeaderThread = ({ schema, storeId, clientId, makeSqliteDb, syncOptions, syncPayloadEncoded, syncPayloadSchema, importSnapshot, devtoolsEnabled, sharedWorkerFiber, }) => Effect.gen(function* () {
|
|
73
119
|
const runtime = yield* Effect.runtime();
|
|
74
120
|
const makeDb = (_kind) => {
|
|
75
121
|
return makeSqliteDb({
|
|
@@ -80,7 +126,7 @@ const makeLeaderThread = ({ schema, storeId, clientId, makeSqliteDb, syncOptions
|
|
|
80
126
|
const shutdownChannel = yield* makeShutdownChannel(storeId);
|
|
81
127
|
// Might involve some async work, so we're running them concurrently
|
|
82
128
|
const [dbState, dbEventlog] = yield* Effect.all([makeDb('state'), makeDb('eventlog')], { concurrency: 2 });
|
|
83
|
-
if (importSnapshot) {
|
|
129
|
+
if (importSnapshot !== undefined) {
|
|
84
130
|
dbState.import(importSnapshot);
|
|
85
131
|
const _migrationsReport = yield* migrateDb({ db: dbState, schema });
|
|
86
132
|
}
|
|
@@ -102,21 +148,32 @@ const makeLeaderThread = ({ schema, storeId, clientId, makeSqliteDb, syncOptions
|
|
|
102
148
|
dbEventlog,
|
|
103
149
|
devtoolsOptions,
|
|
104
150
|
shutdownChannel,
|
|
105
|
-
|
|
151
|
+
syncPayloadEncoded,
|
|
152
|
+
syncPayloadSchema,
|
|
106
153
|
}));
|
|
107
154
|
return yield* Effect.gen(function* () {
|
|
108
|
-
const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState } = yield* LeaderThreadCtx;
|
|
155
|
+
const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState, networkStatus } = yield* LeaderThreadCtx;
|
|
109
156
|
const initialLeaderHead = Eventlog.getClientHeadFromDb(dbEventlog);
|
|
110
157
|
const leaderThread = ClientSessionLeaderThreadProxy.of({
|
|
111
158
|
events: {
|
|
112
159
|
pull: ({ cursor }) => syncProcessor.pull({ cursor }),
|
|
113
|
-
push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.EncodedWithMeta(item)), { waitForProcessing: true }),
|
|
160
|
+
push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.Client.EncodedWithMeta(item)), { waitForProcessing: true }),
|
|
161
|
+
stream: (options) => streamEventsWithSyncState({
|
|
162
|
+
dbEventlog,
|
|
163
|
+
syncState: syncProcessor.syncState,
|
|
164
|
+
options,
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
initialState: {
|
|
168
|
+
leaderHead: initialLeaderHead,
|
|
169
|
+
migrationsReport: initialState.migrationsReport,
|
|
170
|
+
storageMode: 'in-memory',
|
|
114
171
|
},
|
|
115
|
-
initialState: { leaderHead: initialLeaderHead, migrationsReport: initialState.migrationsReport },
|
|
116
172
|
export: Effect.sync(() => dbState.export()),
|
|
117
173
|
getEventlogData: Effect.sync(() => dbEventlog.export()),
|
|
118
|
-
|
|
174
|
+
syncState: syncProcessor.syncState,
|
|
119
175
|
sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
|
|
176
|
+
networkStatus,
|
|
120
177
|
});
|
|
121
178
|
const initialSnapshot = dbState.export();
|
|
122
179
|
return { leaderThread, initialSnapshot };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-adapter.js","sourceRoot":"","sources":["../../src/in-memory/in-memory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,QAAQ,EAER,iBAAiB,EACjB,SAAS,EAET,
|
|
1
|
+
{"version":3,"file":"in-memory-adapter.js","sourceRoot":"","sources":["../../src/in-memory/in-memory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,QAAQ,EAER,iBAAiB,EACjB,SAAS,EAET,YAAY,GACb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAA;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,WAAW,MAAM,4CAA4C,CAAA;AAGzE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OA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C,IAAI;gBACJ,MAAM,EAAE,YAAY;gBACpB,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;aAC3D,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;YAEpD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QAClD,CAAC,CAAC;KACH,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export { makeInMemoryAdapter } from './in-memory/in-memory-adapter.ts';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Single-tab adapter for browsers without SharedWorker support (e.g. Android Chrome).
|
|
4
|
+
*
|
|
5
|
+
* In most cases, you should use `makePersistedAdapter` instead, which automatically
|
|
6
|
+
* falls back to single-tab mode when SharedWorker is unavailable.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/livestorejs/livestore/issues/321
|
|
9
|
+
* @see https://issues.chromium.org/issues/40290702
|
|
10
|
+
*/
|
|
11
|
+
export { makeSingleTabAdapter, type SingleTabAdapterOptions } from './single-tab/mod.ts';
|
|
12
|
+
export { canUseSharedWorker, makePersistedAdapter, type WebAdapterOptions, } from './web-worker/client-session/persisted-adapter.ts';
|
|
3
13
|
export * as WorkerSchema from './web-worker/common/worker-schema.ts';
|
|
4
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,oBAAoB,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE;;;;;;;;GAQG;AACH,OAAO,EAAE,oBAAoB,EAAE,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AACxF,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,iBAAiB,GACvB,MAAM,kDAAkD,CAAA;AACzD,OAAO,KAAK,YAAY,MAAM,sCAAsC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export { makeInMemoryAdapter } from "./in-memory/in-memory-adapter.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Single-tab adapter for browsers without SharedWorker support (e.g. Android Chrome).
|
|
4
|
+
*
|
|
5
|
+
* In most cases, you should use `makePersistedAdapter` instead, which automatically
|
|
6
|
+
* falls back to single-tab mode when SharedWorker is unavailable.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/livestorejs/livestore/issues/321
|
|
9
|
+
* @see https://issues.chromium.org/issues/40290702
|
|
10
|
+
*/
|
|
11
|
+
export { makeSingleTabAdapter } from "./single-tab/mod.js";
|
|
12
|
+
export { canUseSharedWorker, makePersistedAdapter, } from "./web-worker/client-session/persisted-adapter.js";
|
|
3
13
|
export * as WorkerSchema from "./web-worker/common/worker-schema.js";
|
|
4
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE;;;;;;;;GAQG;AACH,OAAO,EAAE,oBAAoB,EAAgC,MAAM,qBAAqB,CAAA;AACxF,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,kDAAkD,CAAA;AACzD,OAAO,KAAK,YAAY,MAAM,sCAAsC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-tab adapter module for browsers without SharedWorker support.
|
|
3
|
+
*
|
|
4
|
+
* **NOTE**: This module exists as a fallback for Android Chrome and similar browsers
|
|
5
|
+
* that don't support SharedWorker. It is intended to be deprecated and removed once
|
|
6
|
+
* SharedWorker support is available in these browsers.
|
|
7
|
+
*
|
|
8
|
+
* Track progress:
|
|
9
|
+
* - LiveStore issue: https://github.com/livestorejs/livestore/issues/321
|
|
10
|
+
* - Chromium bug: https://issues.chromium.org/issues/40290702
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
export { makeSingleTabAdapter, type SingleTabAdapterOptions } from './single-tab-adapter.ts';
|
|
15
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/single-tab/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,oBAAoB,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-tab adapter module for browsers without SharedWorker support.
|
|
3
|
+
*
|
|
4
|
+
* **NOTE**: This module exists as a fallback for Android Chrome and similar browsers
|
|
5
|
+
* that don't support SharedWorker. It is intended to be deprecated and removed once
|
|
6
|
+
* SharedWorker support is available in these browsers.
|
|
7
|
+
*
|
|
8
|
+
* Track progress:
|
|
9
|
+
* - LiveStore issue: https://github.com/livestorejs/livestore/issues/321
|
|
10
|
+
* - Chromium bug: https://issues.chromium.org/issues/40290702
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
export { makeSingleTabAdapter } from "./single-tab-adapter.js";
|
|
15
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/single-tab/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,oBAAoB,EAAgC,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-tab adapter for browsers without SharedWorker support (e.g. Android Chrome).
|
|
3
|
+
*
|
|
4
|
+
* This adapter is a fallback for browsers that don't support the SharedWorker API.
|
|
5
|
+
* It provides the same OPFS persistence as the regular persisted adapter, but without
|
|
6
|
+
* multi-tab synchronization capabilities.
|
|
7
|
+
*
|
|
8
|
+
* **IMPORTANT**: This code is intended to be removed once SharedWorker support is
|
|
9
|
+
* available in Android Chrome. Track progress at:
|
|
10
|
+
* - LiveStore issue: https://github.com/livestorejs/livestore/issues/321
|
|
11
|
+
* - Chromium bug: https://issues.chromium.org/issues/40290702
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import type { Adapter } from '@livestore/common';
|
|
16
|
+
import * as WorkerSchema from '../web-worker/common/worker-schema.ts';
|
|
17
|
+
/**
|
|
18
|
+
* Options for the single-tab adapter.
|
|
19
|
+
*
|
|
20
|
+
* This adapter is designed for browsers without SharedWorker support (e.g. Android Chrome).
|
|
21
|
+
* It provides OPFS persistence but without multi-tab synchronization.
|
|
22
|
+
*
|
|
23
|
+
* @see https://github.com/livestorejs/livestore/issues/321
|
|
24
|
+
* @see https://issues.chromium.org/issues/40290702
|
|
25
|
+
*/
|
|
26
|
+
export type SingleTabAdapterOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* The dedicated web worker that runs the LiveStore leader thread.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import LiveStoreWorker from './livestore.worker.ts?worker'
|
|
33
|
+
*
|
|
34
|
+
* const adapter = makeSingleTabAdapter({
|
|
35
|
+
* worker: LiveStoreWorker,
|
|
36
|
+
* storage: { type: 'opfs' },
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
worker: ((options: {
|
|
41
|
+
name: string;
|
|
42
|
+
}) => globalThis.Worker) | (new (options: {
|
|
43
|
+
name: string;
|
|
44
|
+
}) => globalThis.Worker);
|
|
45
|
+
/**
|
|
46
|
+
* Storage configuration. Currently only OPFS is supported.
|
|
47
|
+
*/
|
|
48
|
+
storage: WorkerSchema.StorageTypeEncoded;
|
|
49
|
+
/**
|
|
50
|
+
* Warning: This will reset both the app and eventlog database.
|
|
51
|
+
* This should only be used during development.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
resetPersistence?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* By default the adapter will initially generate a random clientId (via `nanoid(5)`),
|
|
58
|
+
* store it in `localStorage` and restore it for subsequent client sessions.
|
|
59
|
+
*/
|
|
60
|
+
clientId?: string;
|
|
61
|
+
/**
|
|
62
|
+
* By default the adapter will initially generate a random sessionId (via `nanoid(5)`),
|
|
63
|
+
* store it in `sessionStorage` and restore it for subsequent client sessions in the same tab.
|
|
64
|
+
*/
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
experimental?: {
|
|
67
|
+
/**
|
|
68
|
+
* When set to `true`, the adapter will always start with a snapshot from the leader
|
|
69
|
+
* instead of trying to load a snapshot from storage.
|
|
70
|
+
*
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
disableFastPath?: boolean;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Creates a single-tab web adapter with OPFS persistence.
|
|
78
|
+
*
|
|
79
|
+
* **This adapter is a fallback for browsers without SharedWorker support** (notably Android Chrome).
|
|
80
|
+
* It provides the same persistence capabilities as `makePersistedAdapter`, but without multi-tab
|
|
81
|
+
* synchronization. Each browser tab runs its own independent leader worker.
|
|
82
|
+
*
|
|
83
|
+
* In most cases, you should use `makePersistedAdapter` instead, which automatically falls back
|
|
84
|
+
* to this adapter when SharedWorker is unavailable.
|
|
85
|
+
*
|
|
86
|
+
* **Limitations**:
|
|
87
|
+
* - No multi-tab synchronization (each tab operates independently)
|
|
88
|
+
* - No devtools support (requires SharedWorker)
|
|
89
|
+
* - Opening multiple tabs with the same storeId may cause data conflicts
|
|
90
|
+
*
|
|
91
|
+
* @see https://github.com/livestorejs/livestore/issues/321 - LiveStore tracking issue
|
|
92
|
+
* @see https://issues.chromium.org/issues/40290702 - Chromium SharedWorker bug
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { makeSingleTabAdapter } from '@livestore/adapter-web'
|
|
97
|
+
* import LiveStoreWorker from './livestore.worker.ts?worker'
|
|
98
|
+
*
|
|
99
|
+
* // Only use this directly if you specifically need single-tab mode.
|
|
100
|
+
* // Prefer makePersistedAdapter which auto-detects SharedWorker support.
|
|
101
|
+
* const adapter = makeSingleTabAdapter({
|
|
102
|
+
* worker: LiveStoreWorker,
|
|
103
|
+
* storage: { type: 'opfs' },
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare const makeSingleTabAdapter: (options: SingleTabAdapterOptions) => Adapter;
|
|
108
|
+
//# sourceMappingURL=single-tab-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-tab-adapter.d.ts","sourceRoot":"","sources":["../../src/single-tab/single-tab-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAgD,MAAM,mBAAmB,CAAA;AAmC9F,OAAO,KAAK,YAAY,MAAM,uCAAuC,CAAA;AAErE;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,UAAU,CAAC,MAAM,CAAC,CAAA;IAEnH;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,kBAAkB,CAAA;IAExC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,YAAY,CAAC,EAAE;QACb;;;;;WAKG;QACH,eAAe,CAAC,EAAE,OAAO,CAAA;KAC1B,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,oBAAoB,GAC9B,SAAS,uBAAuB,KAAG,OA4RwC,CAAA"}
|