@livestore/adapter-web 0.4.0-dev.8 → 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 +13 -20
- package/dist/web-worker/common/persisted-sqlite.d.ts.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.js +95 -102
- 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 +99 -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 +215 -170
- 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 +149 -71
- package/src/web-worker/shared-worker/make-shared-worker.ts +78 -90
- package/dist/opfs-utils.d.ts +0 -5
- 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
|
@@ -0,0 +1,271 @@
|
|
|
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 { IntentionalShutdownCause, isWorkerTransportError, makeClientSession, StoreInterrupted, sessionChangesetMetaTable, UnknownError, } from '@livestore/common';
|
|
16
|
+
import { EventSequenceNumber } from '@livestore/common/schema';
|
|
17
|
+
import { sqliteDbFactory } from '@livestore/sqlite-wasm/browser';
|
|
18
|
+
import { shouldNeverHappen, tryAsFunctionAndNew } from '@livestore/utils';
|
|
19
|
+
import { Cause, Effect, Exit, Fiber, Layer, Option, Queue, Schema, Stream, Subscribable, SubscriptionRef, Worker, } from '@livestore/utils/effect';
|
|
20
|
+
import { BrowserWorker, Opfs, WebError } from '@livestore/utils/effect/browser';
|
|
21
|
+
import { nanoid } from '@livestore/utils/nanoid';
|
|
22
|
+
import { loadSqlite3 } from "../web-worker/client-session/sqlite-loader.js";
|
|
23
|
+
import { readPersistedStateDbFromClientSession, resetPersistedDataFromClientSession, } from "../web-worker/common/persisted-sqlite.js";
|
|
24
|
+
import { makeShutdownChannel } from "../web-worker/common/shutdown-channel.js";
|
|
25
|
+
import * as WorkerSchema from "../web-worker/common/worker-schema.js";
|
|
26
|
+
/**
|
|
27
|
+
* Creates a single-tab web adapter with OPFS persistence.
|
|
28
|
+
*
|
|
29
|
+
* **This adapter is a fallback for browsers without SharedWorker support** (notably Android Chrome).
|
|
30
|
+
* It provides the same persistence capabilities as `makePersistedAdapter`, but without multi-tab
|
|
31
|
+
* synchronization. Each browser tab runs its own independent leader worker.
|
|
32
|
+
*
|
|
33
|
+
* In most cases, you should use `makePersistedAdapter` instead, which automatically falls back
|
|
34
|
+
* to this adapter when SharedWorker is unavailable.
|
|
35
|
+
*
|
|
36
|
+
* **Limitations**:
|
|
37
|
+
* - No multi-tab synchronization (each tab operates independently)
|
|
38
|
+
* - No devtools support (requires SharedWorker)
|
|
39
|
+
* - Opening multiple tabs with the same storeId may cause data conflicts
|
|
40
|
+
*
|
|
41
|
+
* @see https://github.com/livestorejs/livestore/issues/321 - LiveStore tracking issue
|
|
42
|
+
* @see https://issues.chromium.org/issues/40290702 - Chromium SharedWorker bug
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { makeSingleTabAdapter } from '@livestore/adapter-web'
|
|
47
|
+
* import LiveStoreWorker from './livestore.worker.ts?worker'
|
|
48
|
+
*
|
|
49
|
+
* // Only use this directly if you specifically need single-tab mode.
|
|
50
|
+
* // Prefer makePersistedAdapter which auto-detects SharedWorker support.
|
|
51
|
+
* const adapter = makeSingleTabAdapter({
|
|
52
|
+
* worker: LiveStoreWorker,
|
|
53
|
+
* storage: { type: 'opfs' },
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const makeSingleTabAdapter = (options) => (adapterArgs) => Effect.gen(function* () {
|
|
58
|
+
const { schema, storeId, bootStatusQueue, shutdown, syncPayloadEncoded } = adapterArgs;
|
|
59
|
+
// Note: devtoolsEnabled is ignored in single-tab mode (devtools require SharedWorker)
|
|
60
|
+
yield* ensureBrowserRequirements;
|
|
61
|
+
yield* Queue.offer(bootStatusQueue, { stage: 'loading' });
|
|
62
|
+
const sqlite3 = yield* Effect.promise(() => loadSqlite3());
|
|
63
|
+
const storageOptions = yield* Schema.decode(WorkerSchema.StorageType)(options.storage);
|
|
64
|
+
const shutdownChannel = yield* makeShutdownChannel(storeId);
|
|
65
|
+
// Check OPFS availability early and notify user if storage is unavailable (e.g. private browsing)
|
|
66
|
+
const opfsWarning = yield* checkOpfsAvailability;
|
|
67
|
+
if (opfsWarning !== undefined) {
|
|
68
|
+
yield* Effect.logWarning('[@livestore/adapter-web:single-tab] OPFS unavailable', opfsWarning);
|
|
69
|
+
}
|
|
70
|
+
if (options.resetPersistence === true && opfsWarning === undefined) {
|
|
71
|
+
yield* shutdownChannel.send(IntentionalShutdownCause.make({ reason: 'adapter-reset' }));
|
|
72
|
+
yield* resetPersistedDataFromClientSession({ storageOptions, storeId });
|
|
73
|
+
}
|
|
74
|
+
else if (options.resetPersistence === true) {
|
|
75
|
+
yield* Effect.logWarning('[@livestore/adapter-web:single-tab] Skipping persistence reset because storage is unavailable', opfsWarning);
|
|
76
|
+
}
|
|
77
|
+
// Fast-path: try to load snapshot directly from storage
|
|
78
|
+
const dataFromFile = options.experimental?.disableFastPath === true || opfsWarning !== undefined
|
|
79
|
+
? undefined
|
|
80
|
+
: yield* readPersistedStateDbFromClientSession({ storageOptions, storeId, schema }).pipe(Effect.tapError((error) => Effect.logDebug('[@livestore/adapter-web:single-tab] Could not read persisted state db', error, {
|
|
81
|
+
storeId,
|
|
82
|
+
})), Effect.orElseSucceed(() => undefined));
|
|
83
|
+
const clientId = options.clientId ?? getPersistedId(`clientId:${storeId}`, 'local');
|
|
84
|
+
const sessionId = options.sessionId ?? getPersistedId(`sessionId:${storeId}`, 'session');
|
|
85
|
+
yield* shutdownChannel.listen.pipe(Stream.flatten(), Stream.tap((cause) => shutdown(cause._tag === 'IntentionalShutdownCause' ? Exit.succeed(cause) : Exit.fail(cause))), Stream.runDrain, Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
86
|
+
// In single-tab mode, we always have the lock (we're always the leader)
|
|
87
|
+
const lockStatus = yield* SubscriptionRef.make('has-lock');
|
|
88
|
+
// Create MessageChannel for direct communication with the dedicated worker
|
|
89
|
+
const mc = new MessageChannel();
|
|
90
|
+
// Create the dedicated worker directly (no SharedWorker proxy)
|
|
91
|
+
const worker = tryAsFunctionAndNew(options.worker, { name: `livestore-worker-${storeId}-${sessionId}` });
|
|
92
|
+
// Set up communication with the dedicated worker via the outer protocol
|
|
93
|
+
const _dedicatedWorkerFiber = yield* Worker.makeSerialized({
|
|
94
|
+
initialMessage: () => new WorkerSchema.LeaderWorkerOuterInitialMessage({ port: mc.port1, storeId, clientId }),
|
|
95
|
+
}).pipe(Effect.provide(BrowserWorker.layer(() => worker)), UnknownError.mapToUnknownError, Effect.tapErrorCause((cause) => shutdown(Exit.failCause(cause))), Effect.withSpan('@livestore/adapter-web:single-tab:setupDedicatedWorker'), Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
96
|
+
// Set up the inner worker communication via port2 (like SharedWorker would do)
|
|
97
|
+
// BrowserWorker.layer accepts a MessagePort as well as a Worker
|
|
98
|
+
const innerWorkerContext = yield* Layer.build(BrowserWorker.layer(() => mc.port2));
|
|
99
|
+
const innerWorkerFiber = yield* Worker.makePoolSerialized({
|
|
100
|
+
size: 1,
|
|
101
|
+
concurrency: 100,
|
|
102
|
+
initialMessage: () => new WorkerSchema.LeaderWorkerInnerInitialMessage({
|
|
103
|
+
storageOptions,
|
|
104
|
+
storeId,
|
|
105
|
+
clientId,
|
|
106
|
+
// Devtools disabled in single-tab mode (requires SharedWorker)
|
|
107
|
+
devtoolsEnabled: false,
|
|
108
|
+
debugInstanceId: adapterArgs.debugInstanceId,
|
|
109
|
+
syncPayloadEncoded,
|
|
110
|
+
}),
|
|
111
|
+
}).pipe(Effect.provide(innerWorkerContext), Effect.tapCauseLogPretty, Effect.orDie, Effect.tapErrorCause((cause) => shutdown(Exit.failCause(cause))), Effect.withSpan('@livestore/adapter-web:single-tab:setupInnerWorker'), Effect.forkScoped);
|
|
112
|
+
// Helper to run requests against the worker
|
|
113
|
+
const runInWorker = (req) => Fiber.join(innerWorkerFiber).pipe(Effect.flatMap((worker) => worker.executeEffect(req)), Effect.catchIf(isWorkerTransportError, (e) => Effect.die(e)), Effect.logWarnIfTakesLongerThan({
|
|
114
|
+
label: `@livestore/adapter-web:single-tab:runInWorker:${req._tag}`,
|
|
115
|
+
duration: 2000,
|
|
116
|
+
}), Effect.withSpan(`@livestore/adapter-web:single-tab:runInWorker:${req._tag}`));
|
|
117
|
+
const runInWorkerStream = (req) => Effect.gen(function* () {
|
|
118
|
+
const innerWorker = yield* Fiber.join(innerWorkerFiber);
|
|
119
|
+
return innerWorker.execute(req).pipe(Stream.refineOrDie((e) => isWorkerTransportError(e) === true ? Option.none() : Option.some(e)), Stream.withSpan(`@livestore/adapter-web:single-tab:runInWorkerStream:${req._tag}`));
|
|
120
|
+
}).pipe(Stream.unwrap);
|
|
121
|
+
// Forward boot status from worker
|
|
122
|
+
const bootStatusFiber = yield* runInWorkerStream(new WorkerSchema.LeaderWorkerInnerBootStatusStream()).pipe(Stream.tap((_) => Queue.offer(bootStatusQueue, _)), Stream.runDrain, Effect.tapErrorCause((cause) => Cause.isInterruptedOnly(cause) === true ? Effect.void : shutdown(Exit.failCause(cause))), Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
123
|
+
yield* Queue.awaitShutdown(bootStatusQueue).pipe(Effect.andThen(Fiber.interrupt(bootStatusFiber)), Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
124
|
+
// Get initial snapshot (either from fast-path or from worker)
|
|
125
|
+
const initialResult = dataFromFile === undefined
|
|
126
|
+
? yield* runInWorker(new WorkerSchema.LeaderWorkerInnerGetRecreateSnapshot()).pipe(Effect.map(({ snapshot, migrationsReport }) => ({
|
|
127
|
+
_tag: 'from-leader-worker',
|
|
128
|
+
snapshot,
|
|
129
|
+
migrationsReport,
|
|
130
|
+
})))
|
|
131
|
+
: { _tag: 'fast-path', snapshot: dataFromFile };
|
|
132
|
+
const migrationsReport = initialResult._tag === 'from-leader-worker' ? initialResult.migrationsReport : { migrations: [] };
|
|
133
|
+
const makeSqliteDb = sqliteDbFactory({ sqlite3 });
|
|
134
|
+
const sqliteDb = yield* makeSqliteDb({ _tag: 'in-memory' });
|
|
135
|
+
sqliteDb.import(initialResult.snapshot);
|
|
136
|
+
const numberOfTables = sqliteDb.select(`select count(*) as count from sqlite_master`)[0]?.count ?? 0;
|
|
137
|
+
if (numberOfTables === 0) {
|
|
138
|
+
return yield* UnknownError.make({
|
|
139
|
+
cause: `Encountered empty or corrupted database`,
|
|
140
|
+
payload: { snapshotByteLength: initialResult.snapshot.byteLength, storageOptions: options.storage },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// Restore leader head from SESSION_CHANGESET_META_TABLE
|
|
144
|
+
const initialLeaderHeadRes = sqliteDb.select(sessionChangesetMetaTable
|
|
145
|
+
.select('seqNumClient', 'seqNumGlobal', 'seqNumRebaseGeneration')
|
|
146
|
+
.orderBy([
|
|
147
|
+
{ col: 'seqNumGlobal', direction: 'desc' },
|
|
148
|
+
{ col: 'seqNumClient', direction: 'desc' },
|
|
149
|
+
])
|
|
150
|
+
.first());
|
|
151
|
+
const initialLeaderHead = initialLeaderHeadRes !== undefined
|
|
152
|
+
? EventSequenceNumber.Client.Composite.make({
|
|
153
|
+
global: initialLeaderHeadRes.seqNumGlobal,
|
|
154
|
+
client: initialLeaderHeadRes.seqNumClient,
|
|
155
|
+
rebaseGeneration: initialLeaderHeadRes.seqNumRebaseGeneration,
|
|
156
|
+
})
|
|
157
|
+
: EventSequenceNumber.Client.ROOT;
|
|
158
|
+
yield* Effect.addFinalizer((ex) => Effect.gen(function* () {
|
|
159
|
+
if (Exit.isFailure(ex) === true &&
|
|
160
|
+
Exit.isInterrupted(ex) === false &&
|
|
161
|
+
Schema.is(IntentionalShutdownCause)(Cause.squash(ex.cause)) === false &&
|
|
162
|
+
Schema.is(StoreInterrupted)(Cause.squash(ex.cause)) === false) {
|
|
163
|
+
yield* Effect.logError('[@livestore/adapter-web:single-tab] client-session shutdown', ex.cause);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
yield* Effect.logDebug('[@livestore/adapter-web:single-tab] client-session shutdown', ex);
|
|
167
|
+
}
|
|
168
|
+
}).pipe(Effect.tapCauseLogPretty, Effect.orDie));
|
|
169
|
+
const leaderThread = {
|
|
170
|
+
export: runInWorker(new WorkerSchema.LeaderWorkerInnerExport()).pipe(Effect.timeoutOrDie(10_000), Effect.withSpan('@livestore/adapter-web:single-tab:export')),
|
|
171
|
+
events: {
|
|
172
|
+
pull: ({ cursor }) => runInWorkerStream(new WorkerSchema.LeaderWorkerInnerPullStream({ cursor })).pipe(Stream.orDie),
|
|
173
|
+
push: (batch) => runInWorker(new WorkerSchema.LeaderWorkerInnerPushToLeader({ batch })).pipe(Effect.withSpan('@livestore/adapter-web:single-tab:pushToLeader', {
|
|
174
|
+
attributes: { batchSize: batch.length },
|
|
175
|
+
})),
|
|
176
|
+
stream: (options) => runInWorkerStream(new WorkerSchema.LeaderWorkerInnerStreamEvents(options)).pipe(Stream.withSpan('@livestore/adapter-web:single-tab:streamEvents'), Stream.orDie),
|
|
177
|
+
},
|
|
178
|
+
initialState: {
|
|
179
|
+
leaderHead: initialLeaderHead,
|
|
180
|
+
migrationsReport,
|
|
181
|
+
storageMode: opfsWarning === undefined ? 'persisted' : 'in-memory',
|
|
182
|
+
},
|
|
183
|
+
getEventlogData: runInWorker(new WorkerSchema.LeaderWorkerInnerExportEventlog()).pipe(Effect.timeoutOrDie(10_000), Effect.withSpan('@livestore/adapter-web:single-tab:getEventlogData')),
|
|
184
|
+
syncState: Subscribable.make({
|
|
185
|
+
get: runInWorker(new WorkerSchema.LeaderWorkerInnerGetLeaderSyncState()).pipe(Effect.withSpan('@livestore/adapter-web:single-tab:getLeaderSyncState')),
|
|
186
|
+
changes: runInWorkerStream(new WorkerSchema.LeaderWorkerInnerSyncStateStream()).pipe(Stream.orDie),
|
|
187
|
+
}),
|
|
188
|
+
sendDevtoolsMessage: (_message) =>
|
|
189
|
+
// Devtools not supported in single-tab mode
|
|
190
|
+
Effect.void,
|
|
191
|
+
networkStatus: Subscribable.make({
|
|
192
|
+
get: runInWorker(new WorkerSchema.LeaderWorkerInnerGetNetworkStatus()).pipe(Effect.orDie),
|
|
193
|
+
changes: runInWorkerStream(new WorkerSchema.LeaderWorkerInnerNetworkStatusStream()).pipe(Stream.orDie),
|
|
194
|
+
}),
|
|
195
|
+
};
|
|
196
|
+
const clientSession = yield* makeClientSession({
|
|
197
|
+
...adapterArgs,
|
|
198
|
+
sqliteDb,
|
|
199
|
+
lockStatus,
|
|
200
|
+
clientId,
|
|
201
|
+
sessionId,
|
|
202
|
+
isLeader: true, // Always leader in single-tab mode
|
|
203
|
+
leaderThread,
|
|
204
|
+
webmeshMode: 'direct',
|
|
205
|
+
origin: globalThis.location?.origin,
|
|
206
|
+
// No webmesh connection in single-tab mode (devtools disabled)
|
|
207
|
+
connectWebmeshNode: () => Effect.void,
|
|
208
|
+
registerBeforeUnload: (onBeforeUnload) => {
|
|
209
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
210
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
211
|
+
return () => window.removeEventListener('beforeunload', onBeforeUnload);
|
|
212
|
+
}
|
|
213
|
+
return () => { };
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return clientSession;
|
|
217
|
+
}).pipe(Effect.provide(Opfs.Opfs.Default), UnknownError.mapToUnknownError);
|
|
218
|
+
/** Persists clientId/sessionId to storage */
|
|
219
|
+
const getPersistedId = (key, storageType) => {
|
|
220
|
+
const makeId = () => nanoid(5);
|
|
221
|
+
const storage = typeof window === 'undefined'
|
|
222
|
+
? undefined
|
|
223
|
+
: storageType === 'session'
|
|
224
|
+
? sessionStorage
|
|
225
|
+
: storageType === 'local'
|
|
226
|
+
? localStorage
|
|
227
|
+
: shouldNeverHappen(`[@livestore/adapter-web] Invalid storage type: ${String(storageType)}`);
|
|
228
|
+
if (storage === undefined) {
|
|
229
|
+
return makeId();
|
|
230
|
+
}
|
|
231
|
+
const fullKey = `livestore:${key}`;
|
|
232
|
+
const storedKey = storage.getItem(fullKey);
|
|
233
|
+
if (storedKey !== null)
|
|
234
|
+
return storedKey;
|
|
235
|
+
const newKey = makeId();
|
|
236
|
+
storage.setItem(fullKey, newKey);
|
|
237
|
+
return newKey;
|
|
238
|
+
};
|
|
239
|
+
const ensureBrowserRequirements = Effect.gen(function* () {
|
|
240
|
+
const validate = (condition, label) => Effect.gen(function* () {
|
|
241
|
+
if (condition === true) {
|
|
242
|
+
return yield* UnknownError.make({
|
|
243
|
+
cause: `[@livestore/adapter-web] Browser not supported. The LiveStore web adapter needs '${label}' to work properly`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
yield* Effect.all([
|
|
248
|
+
validate(typeof navigator === 'undefined', 'navigator'),
|
|
249
|
+
validate(navigator.locks === undefined, 'navigator.locks'),
|
|
250
|
+
validate(navigator.storage === undefined, 'navigator.storage'),
|
|
251
|
+
validate(crypto.randomUUID === undefined, 'crypto.randomUUID'),
|
|
252
|
+
validate(typeof window === 'undefined', 'window'),
|
|
253
|
+
validate(typeof sessionStorage === 'undefined', 'sessionStorage'),
|
|
254
|
+
]);
|
|
255
|
+
});
|
|
256
|
+
/**
|
|
257
|
+
* Attempts to access OPFS and returns a warning if unavailable.
|
|
258
|
+
*/
|
|
259
|
+
const checkOpfsAvailability = Effect.gen(function* () {
|
|
260
|
+
const opfs = yield* Opfs.Opfs;
|
|
261
|
+
return yield* opfs.getRootDirectoryHandle.pipe(Effect.as(undefined), Effect.catchAll((error) => {
|
|
262
|
+
const reason = Schema.is(WebError.SecurityError)(error) === true || Schema.is(WebError.NotAllowedError)(error) === true
|
|
263
|
+
? 'private-browsing'
|
|
264
|
+
: 'storage-unavailable';
|
|
265
|
+
const message = reason === 'private-browsing'
|
|
266
|
+
? 'Storage unavailable in private browsing mode. LiveStore will continue without persistence.'
|
|
267
|
+
: 'Storage access denied. LiveStore will continue without persistence.';
|
|
268
|
+
return Effect.succeed({ reason, message });
|
|
269
|
+
}));
|
|
270
|
+
});
|
|
271
|
+
//# sourceMappingURL=single-tab-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-tab-adapter.js","sourceRoot":"","sources":["../../src/single-tab/single-tab-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EACzB,YAAY,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,YAAY,EACZ,eAAe,EACf,MAAM,GACP,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAA;AAC3E,OAAO,EACL,qCAAqC,EACrC,mCAAmC,GACpC,MAAM,0CAA0C,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAC9E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AAC,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI;YACtG,CAAC,CAAC,kBAAkB;YACpB,CAAC,CAAC,qBAAqB,CAAA;QAC3B,MAAM,OAAO,GACX,MAAM,KAAK,kBAAkB;YAC3B,CAAC,CAAC,4FAA4F;YAC9F,CAAC,CAAC,qEAAqE,CAAA;QAC3E,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAW,CAAC,CAAA;IACrD,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -4,7 +4,7 @@ import * as DevtoolsWeb from '@livestore/devtools-web-common/web-channel';
|
|
|
4
4
|
import type { Worker } from '@livestore/utils/effect';
|
|
5
5
|
import { Effect } from '@livestore/utils/effect';
|
|
6
6
|
import * as Webmesh from '@livestore/webmesh';
|
|
7
|
-
export declare const logDevtoolsUrl: (
|
|
7
|
+
export declare const logDevtoolsUrl: (args_0: {
|
|
8
8
|
schema: LiveStoreSchema;
|
|
9
9
|
storeId: string;
|
|
10
10
|
clientId: string;
|
|
@@ -16,5 +16,5 @@ export declare const connectWebmeshNodeClientSession: (args_0: {
|
|
|
16
16
|
sharedWorker: Worker.SerializedWorkerPool<typeof DevtoolsWeb.WorkerSchema.Request.Type>;
|
|
17
17
|
devtoolsEnabled: boolean;
|
|
18
18
|
schema: LiveStoreSchema;
|
|
19
|
-
}) => Effect.Effect<void, import("@livestore/common").
|
|
19
|
+
}) => Effect.Effect<void, import("@livestore/common").UnknownError, import("effect/Scope").Scope>;
|
|
20
20
|
//# sourceMappingURL=client-session-devtools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-session-devtools.d.ts","sourceRoot":"","sources":["../../../src/web-worker/client-session/client-session-devtools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"client-session-devtools.d.ts","sourceRoot":"","sources":["../../../src/web-worker/client-session/client-session-devtools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,mBAAmB,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,4CAA4C,CAAA;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAU,MAAM,yBAAyB,CAAA;AAExD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,eAAO,MAAM,cAAc;YAMjB,eAAe;aACd,MAAM;cACL,MAAM;eACL,MAAM;uCA8BjB,CAAA;AAEF,eAAO,MAAM,+BAA+B;iBAO7B,OAAO,CAAC,QAAQ;iBAChB,QAAQ,CAAC,WAAW,CAAC,WAAW;kBAC/B,MAAM,CAAC,oBAAoB,CAAC,OAAO,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;qBACtE,OAAO;YAChB,eAAe;iGA4CvB,CAAA"}
|
|
@@ -1,25 +1,36 @@
|
|
|
1
|
-
import { Devtools } from '@livestore/common';
|
|
1
|
+
import { Devtools, liveStoreVersion } from '@livestore/common';
|
|
2
2
|
import * as DevtoolsWeb from '@livestore/devtools-web-common/web-channel';
|
|
3
3
|
import { isDevEnv } from '@livestore/utils';
|
|
4
|
-
import { Effect, Stream
|
|
4
|
+
import { Effect, Stream } from '@livestore/utils/effect';
|
|
5
|
+
import { WebChannelBrowser } from '@livestore/utils/effect/browser';
|
|
5
6
|
import * as Webmesh from '@livestore/webmesh';
|
|
6
|
-
export const logDevtoolsUrl = ({ schema, storeId, clientId, sessionId, })
|
|
7
|
-
if (isDevEnv()) {
|
|
7
|
+
export const logDevtoolsUrl = Effect.fn('@livestore/adapter-web:client-session:devtools:logDevtoolsUrl')(function* ({ schema, storeId, clientId, sessionId, }) {
|
|
8
|
+
if (isDevEnv() === true) {
|
|
8
9
|
const devtoolsPath = globalThis.LIVESTORE_DEVTOOLS_PATH ?? `/_livestore`;
|
|
9
10
|
const devtoolsBaseUrl = `${location.origin}${devtoolsPath}`;
|
|
10
11
|
// Check whether devtools are available and then log the URL
|
|
11
12
|
const response = yield* Effect.promise(() => fetch(devtoolsBaseUrl));
|
|
12
|
-
if (response.ok) {
|
|
13
|
+
if (response.ok === true) {
|
|
13
14
|
const text = yield* Effect.promise(() => response.text());
|
|
14
|
-
if (text.includes('<meta name="livestore-devtools" content="true" />')) {
|
|
15
|
+
if (text.includes('<meta name="livestore-devtools" content="true" />') === true) {
|
|
15
16
|
const url = `${devtoolsBaseUrl}/web/${storeId}/${clientId}/${sessionId}/${schema.devtools.alias}`;
|
|
16
17
|
yield* Effect.log(`[@livestore/adapter-web] Devtools ready on ${url}`);
|
|
17
18
|
}
|
|
19
|
+
// Check for DevTools Chrome extension presence via iframe container the extension injects
|
|
20
|
+
const hasExt = document.querySelector('[id^="livestore-devtools-iframe-"]') !== null;
|
|
21
|
+
if (hasExt === false) {
|
|
22
|
+
const g = globalThis;
|
|
23
|
+
if (g.__livestoreDevtoolsChromeNoticeShown !== true) {
|
|
24
|
+
g.__livestoreDevtoolsChromeNoticeShown = true;
|
|
25
|
+
const urlToLog = `https://github.com/livestorejs/livestore/releases/download/v${liveStoreVersion}/livestore-devtools-chrome-${liveStoreVersion}.zip`;
|
|
26
|
+
yield* Effect.log(`[@livestore/adapter-web] LiveStore DevTools Chrome extension not detected. Install v${liveStoreVersion}: ${urlToLog}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
}
|
|
19
30
|
}
|
|
20
|
-
})
|
|
31
|
+
});
|
|
21
32
|
export const connectWebmeshNodeClientSession = Effect.fn(function* ({ webmeshNode, sessionInfo, sharedWorker, devtoolsEnabled, schema, }) {
|
|
22
|
-
if (devtoolsEnabled) {
|
|
33
|
+
if (devtoolsEnabled === true) {
|
|
23
34
|
const { clientId, sessionId, storeId } = sessionInfo;
|
|
24
35
|
yield* logDevtoolsUrl({ clientId, sessionId, schema, storeId });
|
|
25
36
|
// This additional sessioninfo broadcast channel is needed since we can't use the shared worker
|
|
@@ -33,7 +44,7 @@ export const connectWebmeshNodeClientSession = Effect.fn(function* ({ webmeshNod
|
|
|
33
44
|
yield* clientSessionStaticChannel.send(DevtoolsWeb.ClientSessionContentscriptMainReq.make({ clientId, sessionId, storeId }));
|
|
34
45
|
const { tabId } = yield* clientSessionStaticChannel.listen.pipe(Stream.flatten(), Stream.runHead, Effect.flatten);
|
|
35
46
|
const contentscriptMainNodeName = DevtoolsWeb.makeNodeName.browserExtension.contentscriptMain(tabId);
|
|
36
|
-
const contentscriptMainChannel = yield*
|
|
47
|
+
const contentscriptMainChannel = yield* WebChannelBrowser.windowChannel({
|
|
37
48
|
listenWindow: window,
|
|
38
49
|
sendWindow: window,
|
|
39
50
|
schema: Webmesh.WebmeshSchema.Packet,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-session-devtools.js","sourceRoot":"","sources":["../../../src/web-worker/client-session/client-session-devtools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"client-session-devtools.js","sourceRoot":"","sources":["../../../src/web-worker/client-session/client-session-devtools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAE9D,OAAO,KAAK,WAAW,MAAM,4CAA4C,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,+DAA+D,CAAC,CAAC,QAAQ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CAAA;YAEjH,MAAM,yBAAyB,GAAG,WAAW,CAAC,YAAY,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;YAEpG,MAAM,wBAAwB,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,aAAa,CAAC;gBACtE,YAAY,EAAE,MAAM;gBACpB,UAAU,EAAE,MAAM;gBAClB,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM;gBACpC,GAAG,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;aACrE,CAAC,CAAA;YAEF,KAAK,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC,CAAA;QAC1G,CAAC,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,QAAQ,CAAC,kEAAkE,CAAC,EACnF,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,UAAU,CAClB,CAAA;QAED,KAAK,CAAC,CAAC,WAAW,CAAC,gBAAgB,CAAC;YAClC,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;YAC1D,MAAM,EAAE,YAAY;SACrB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { Adapter } from '@livestore/common';
|
|
2
2
|
import * as WorkerSchema from '../common/worker-schema.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if SharedWorker API is available in the current browser context.
|
|
5
|
+
*
|
|
6
|
+
* Returns false on Android Chrome and other browsers without SharedWorker support.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/livestorejs/livestore/issues/321
|
|
9
|
+
* @see https://issues.chromium.org/issues/40290702
|
|
10
|
+
*/
|
|
11
|
+
export declare const canUseSharedWorker: () => boolean;
|
|
3
12
|
export type WebAdapterOptions = {
|
|
4
13
|
worker: ((options: {
|
|
5
14
|
name: string;
|
|
@@ -75,6 +84,15 @@ export type WebAdapterOptions = {
|
|
|
75
84
|
* Creates a web adapter with persistent storage (currently only supports OPFS).
|
|
76
85
|
* Requires both a web worker and a shared worker.
|
|
77
86
|
*
|
|
87
|
+
* On browsers without SharedWorker support (e.g. Android Chrome), this adapter
|
|
88
|
+
* automatically falls back to single-tab mode. In single-tab mode:
|
|
89
|
+
* - Each tab runs independently with its own leader worker
|
|
90
|
+
* - Multi-tab synchronization is not available
|
|
91
|
+
* - Devtools are not supported
|
|
92
|
+
*
|
|
93
|
+
* @see https://github.com/livestorejs/livestore/issues/321 - SharedWorker tracking issue
|
|
94
|
+
* @see https://issues.chromium.org/issues/40290702 - Chromium SharedWorker bug
|
|
95
|
+
*
|
|
78
96
|
* @example
|
|
79
97
|
* ```ts
|
|
80
98
|
* import { makePersistedAdapter } from '@livestore/adapter-web'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted-adapter.d.ts","sourceRoot":"","sources":["../../../src/web-worker/client-session/persisted-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"persisted-adapter.d.ts","sourceRoot":"","sources":["../../../src/web-worker/client-session/persisted-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAgD,MAAM,mBAAmB,CAAA;AAyC9F,OAAO,KAAK,YAAY,MAAM,4BAA4B,CAAA;AAI1D;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAO,OAA8C,CAAA;AASpF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,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;IACnH;;;;;;;;;;;;;OAaG;IACH,YAAY,EACR,CAAC,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,UAAU,CAAC,YAAY,CAAC,GACxD,CAAC,KAAK,OAAO,EAAE;QACb,IAAI,EAAE,MAAM,CAAA;KACb,KAAK,UAAU,CAAC,YAAY,CAAC,CAAA;IAClC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,kBAAkB,CAAA;IACxC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE;QACb;;;;;WAKG;QACH,eAAe,CAAC,EAAE,OAAO,CAAA;QACzB;;;;;;;;;;;;;WAaG;QACH,4BAA4B,CAAC,EAAE,OAAO,CAAA;KACvC,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,oBAAoB,GAC9B,SAAS,iBAAiB,KAAG,OA8Z8C,CAAA"}
|