@livestore/adapter-web 0.3.0-dev.33 → 0.3.0-dev.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/web-worker/client-session/client-session-devtools.d.ts +3 -1
- package/dist/web-worker/client-session/client-session-devtools.d.ts.map +1 -1
- package/dist/web-worker/client-session/client-session-devtools.js +4 -3
- package/dist/web-worker/client-session/client-session-devtools.js.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.d.ts.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.js +9 -4
- package/dist/web-worker/client-session/persisted-adapter.js.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.d.ts +1 -1
- package/dist/web-worker/common/persisted-sqlite.d.ts.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.js +37 -39
- package/dist/web-worker/common/persisted-sqlite.js.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.js +9 -9
- package/dist/web-worker/leader-worker/make-leader-worker.js.map +1 -1
- package/package.json +11 -6
- package/src/web-worker/ambient.d.ts +3 -0
- package/src/web-worker/client-session/client-session-devtools.ts +13 -3
- package/src/web-worker/client-session/persisted-adapter.ts +9 -4
- package/src/web-worker/common/persisted-sqlite.ts +38 -39
- package/src/web-worker/leader-worker/make-leader-worker.ts +11 -11
- package/.eslintrc.cjs +0 -6
- package/tmp/pack.tgz +0 -0
- package/tsconfig.json +0 -17
|
@@ -19,55 +19,53 @@ export const readPersistedAppDbFromClientSession = ({
|
|
|
19
19
|
storeId: string
|
|
20
20
|
schema: LiveStoreSchema
|
|
21
21
|
}) =>
|
|
22
|
-
Effect.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const sahPoolOpaqueDir = await OpfsUtils.getDirHandle(directory).catch(() => undefined)
|
|
22
|
+
Effect.promise(async () => {
|
|
23
|
+
const directory = sanitizeOpfsDir(storageOptions.directory, storeId)
|
|
24
|
+
const sahPoolOpaqueDir = await OpfsUtils.getDirHandle(directory).catch(() => undefined)
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (sahPoolOpaqueDir === undefined) {
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const tryGetDbFile = async (fileHandle: FileSystemFileHandle) => {
|
|
31
|
+
const file = await fileHandle.getFile()
|
|
32
|
+
const fileName = await decodeSAHPoolFilename(file)
|
|
33
|
+
return fileName ? { fileName, file } : undefined
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
36
|
+
const getAllFiles = async (asyncIterator: AsyncIterable<FileSystemHandle>): Promise<FileSystemFileHandle[]> => {
|
|
37
|
+
const results: FileSystemFileHandle[] = []
|
|
38
|
+
for await (const value of asyncIterator) {
|
|
39
|
+
if (value.kind === 'file') {
|
|
40
|
+
results.push(value as FileSystemFileHandle)
|
|
43
41
|
}
|
|
44
|
-
return results
|
|
45
42
|
}
|
|
43
|
+
return results
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const fileResults = await Promise.all(files.map(tryGetDbFile))
|
|
46
|
+
const files = await getAllFiles(sahPoolOpaqueDir.values())
|
|
50
47
|
|
|
51
|
-
|
|
48
|
+
const fileResults = await Promise.all(files.map(tryGetDbFile))
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
// console.debug('fileResults', fileResults, 'dbFileRes', dbFileRes)
|
|
50
|
+
const appDbFileName = '/' + getStateDbFileName(schema)
|
|
55
51
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// console.debug('readPersistedAppDbFromClientSession', data.byteLength, data)
|
|
52
|
+
const dbFileRes = fileResults.find((_) => _?.fileName === appDbFileName)
|
|
53
|
+
// console.debug('fileResults', fileResults, 'dbFileRes', dbFileRes)
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return undefined
|
|
64
|
-
}
|
|
55
|
+
if (dbFileRes !== undefined) {
|
|
56
|
+
const data = await dbFileRes.file.slice(HEADER_OFFSET_DATA).arrayBuffer()
|
|
57
|
+
// console.debug('readPersistedAppDbFromClientSession', data.byteLength, data)
|
|
65
58
|
|
|
66
|
-
|
|
59
|
+
// Given the SAH pool always eagerly creates files with empty non-header data,
|
|
60
|
+
// we want to return undefined if the file exists but is empty
|
|
61
|
+
if (data.byteLength === 0) {
|
|
62
|
+
return undefined
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
return
|
|
70
|
-
}
|
|
65
|
+
return new Uint8Array(data)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return undefined
|
|
71
69
|
}).pipe(
|
|
72
70
|
Effect.logWarnIfTakesLongerThan({
|
|
73
71
|
duration: 1000,
|
|
@@ -138,7 +136,8 @@ export const sanitizeOpfsDir = (directory: string | undefined, storeId: string)
|
|
|
138
136
|
return `${directory}@${liveStoreStorageFormatVersion}`
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
export const
|
|
142
|
-
const schemaHashSuffix =
|
|
143
|
-
|
|
139
|
+
export const getStateDbFileName = (schema: LiveStoreSchema) => {
|
|
140
|
+
const schemaHashSuffix =
|
|
141
|
+
schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString()
|
|
142
|
+
return `state${schemaHashSuffix}.db`
|
|
144
143
|
}
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
import type * as otel from '@opentelemetry/api'
|
|
28
28
|
|
|
29
29
|
import * as OpfsUtils from '../../opfs-utils.js'
|
|
30
|
-
import {
|
|
30
|
+
import { getStateDbFileName, sanitizeOpfsDir } from '../common/persisted-sqlite.js'
|
|
31
31
|
import { makeShutdownChannel } from '../common/shutdown-channel.js'
|
|
32
32
|
import * as WorkerSchema from '../common/worker-schema.js'
|
|
33
33
|
|
|
@@ -108,11 +108,11 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
108
108
|
const makeSqliteDb = sqliteDbFactory({ sqlite3 })
|
|
109
109
|
const runtime = yield* Effect.runtime<never>()
|
|
110
110
|
|
|
111
|
-
const makeDb = (kind: '
|
|
111
|
+
const makeDb = (kind: 'state' | 'eventlog') =>
|
|
112
112
|
makeSqliteDb({
|
|
113
113
|
_tag: 'opfs',
|
|
114
114
|
opfsDirectory: sanitizeOpfsDir(storageOptions.directory, storeId),
|
|
115
|
-
fileName: kind === '
|
|
115
|
+
fileName: kind === 'state' ? getStateDbFileName(schema) : 'eventlog.db',
|
|
116
116
|
configureDb: (db) =>
|
|
117
117
|
configureConnection(db, {
|
|
118
118
|
// The persisted databases use the AccessHandlePoolVFS which always uses a single database connection.
|
|
@@ -125,11 +125,11 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
125
125
|
}).pipe(Effect.acquireRelease((db) => Effect.try(() => db.close()).pipe(Effect.ignoreLogged)))
|
|
126
126
|
|
|
127
127
|
// Might involve some async work, so we're running them concurrently
|
|
128
|
-
const [
|
|
128
|
+
const [dbState, dbEventlog] = yield* Effect.all([makeDb('state'), makeDb('eventlog')], {
|
|
129
129
|
concurrency: 2,
|
|
130
130
|
})
|
|
131
131
|
|
|
132
|
-
const devtoolsOptions = yield* makeDevtoolsOptions({ devtoolsEnabled,
|
|
132
|
+
const devtoolsOptions = yield* makeDevtoolsOptions({ devtoolsEnabled, dbState, dbEventlog })
|
|
133
133
|
const shutdownChannel = yield* makeShutdownChannel(storeId)
|
|
134
134
|
|
|
135
135
|
return makeLeaderThreadLayer({
|
|
@@ -138,7 +138,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
138
138
|
clientId,
|
|
139
139
|
makeSqliteDb,
|
|
140
140
|
syncOptions,
|
|
141
|
-
|
|
141
|
+
dbState,
|
|
142
142
|
dbEventlog,
|
|
143
143
|
devtoolsOptions,
|
|
144
144
|
shutdownChannel,
|
|
@@ -162,7 +162,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
162
162
|
|
|
163
163
|
// return cachedSnapshot ?? workerCtx.db.export()
|
|
164
164
|
|
|
165
|
-
const snapshot = workerCtx.
|
|
165
|
+
const snapshot = workerCtx.dbState.export()
|
|
166
166
|
return { snapshot, migrationsReport: workerCtx.initialState.migrationsReport }
|
|
167
167
|
}).pipe(
|
|
168
168
|
UnexpectedError.mapToUnexpectedError,
|
|
@@ -186,7 +186,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
186
186
|
),
|
|
187
187
|
).pipe(Effect.uninterruptible, Effect.withSpan('@livestore/adapter-web:worker:PushToLeader')),
|
|
188
188
|
Export: () =>
|
|
189
|
-
Effect.andThen(LeaderThreadCtx, (_) => _.
|
|
189
|
+
Effect.andThen(LeaderThreadCtx, (_) => _.dbState.export()).pipe(
|
|
190
190
|
UnexpectedError.mapToUnexpectedError,
|
|
191
191
|
Effect.withSpan('@livestore/adapter-web:worker:Export'),
|
|
192
192
|
),
|
|
@@ -228,11 +228,11 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions }: WorkerOptions) =>
|
|
|
228
228
|
|
|
229
229
|
const makeDevtoolsOptions = ({
|
|
230
230
|
devtoolsEnabled,
|
|
231
|
-
|
|
231
|
+
dbState,
|
|
232
232
|
dbEventlog,
|
|
233
233
|
}: {
|
|
234
234
|
devtoolsEnabled: boolean
|
|
235
|
-
|
|
235
|
+
dbState: SqliteDb
|
|
236
236
|
dbEventlog: SqliteDb
|
|
237
237
|
}): Effect.Effect<DevtoolsOptions, UnexpectedError, Scope.Scope | WebmeshWorker.CacheService> =>
|
|
238
238
|
Effect.gen(function* () {
|
|
@@ -251,7 +251,7 @@ const makeDevtoolsOptions = ({
|
|
|
251
251
|
schema: { listen: Devtools.Leader.MessageToApp, send: Devtools.Leader.MessageFromApp },
|
|
252
252
|
}),
|
|
253
253
|
persistenceInfo: {
|
|
254
|
-
|
|
254
|
+
state: dbState.metadata.persistenceInfo,
|
|
255
255
|
eventlog: dbEventlog.metadata.persistenceInfo,
|
|
256
256
|
},
|
|
257
257
|
}
|
package/.eslintrc.cjs
DELETED
package/tmp/pack.tgz
DELETED
|
Binary file
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"resolveJsonModule": true,
|
|
7
|
-
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
|
8
|
-
},
|
|
9
|
-
"include": ["./src"],
|
|
10
|
-
"references": [
|
|
11
|
-
{ "path": "../common" },
|
|
12
|
-
{ "path": "../utils" },
|
|
13
|
-
{ "path": "../sqlite-wasm" },
|
|
14
|
-
{ "path": "../webmesh" },
|
|
15
|
-
{ "path": "../devtools-web-common" },
|
|
16
|
-
]
|
|
17
|
-
}
|