@livestore/adapter-web 0.4.0-dev.2 → 0.4.0-dev.20
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/in-memory/in-memory-adapter.d.ts +15 -5
- package/dist/in-memory/in-memory-adapter.d.ts.map +1 -1
- package/dist/in-memory/in-memory-adapter.js +29 -15
- package/dist/in-memory/in-memory-adapter.js.map +1 -1
- package/dist/web-worker/client-session/client-session-devtools.d.ts +1 -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 +14 -3
- package/dist/web-worker/client-session/client-session-devtools.js.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.d.ts +15 -0
- package/dist/web-worker/client-session/persisted-adapter.d.ts.map +1 -1
- package/dist/web-worker/client-session/persisted-adapter.js +67 -46
- 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 +23 -7
- package/dist/web-worker/common/persisted-sqlite.d.ts.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.js +114 -76
- 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 +103 -58
- package/dist/web-worker/common/worker-schema.d.ts.map +1 -1
- package/dist/web-worker/common/worker-schema.js +48 -36
- package/dist/web-worker/common/worker-schema.js.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.d.ts +4 -2
- package/dist/web-worker/leader-worker/make-leader-worker.d.ts.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.js +47 -21
- 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 +65 -49
- package/dist/web-worker/shared-worker/make-shared-worker.js.map +1 -1
- package/dist/web-worker/vite-dev-polyfill.js +1 -0
- package/dist/web-worker/vite-dev-polyfill.js.map +1 -1
- package/package.json +8 -9
- package/src/in-memory/in-memory-adapter.ts +36 -20
- package/src/web-worker/ambient.d.ts +7 -24
- package/src/web-worker/client-session/client-session-devtools.ts +18 -3
- package/src/web-worker/client-session/persisted-adapter.ts +112 -59
- package/src/web-worker/client-session/sqlite-loader.ts +19 -0
- package/src/web-worker/common/persisted-sqlite.ts +219 -113
- 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 +62 -35
- package/src/web-worker/leader-worker/make-leader-worker.ts +58 -33
- package/src/web-worker/shared-worker/make-shared-worker.ts +95 -75
- package/src/web-worker/vite-dev-polyfill.ts +1 -0
- 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,16 @@
|
|
|
1
|
+
import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
|
|
2
|
+
/**
|
|
3
|
+
* Browser sessions benefit from downloading and compiling the wasm binary as soon as
|
|
4
|
+
* possible to hide network and IO latency behind the rest of the boot process. We kick
|
|
5
|
+
* that work off eagerly on the client while still returning the shared promise.
|
|
6
|
+
*
|
|
7
|
+
* The Cloudflare / Workerd runtime has stricter rules: async fetches during module
|
|
8
|
+
* evaluation are blocked, so we defer loading until the worker asks for it.
|
|
9
|
+
*/
|
|
10
|
+
const isServerRuntime = String(import.meta.env?.SSR) === 'true' || typeof window === 'undefined';
|
|
11
|
+
let sqlite3Promise;
|
|
12
|
+
if (isServerRuntime === false) {
|
|
13
|
+
sqlite3Promise = loadSqlite3Wasm();
|
|
14
|
+
}
|
|
15
|
+
export const loadSqlite3 = () => (isServerRuntime ? loadSqlite3Wasm() : (sqlite3Promise ?? loadSqlite3Wasm()));
|
|
16
|
+
//# sourceMappingURL=sqlite-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-loader.js","sourceRoot":"","sources":["../../../src/web-worker/client-session/sqlite-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAElE;;;;;;;GAOG;AACH,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,MAAM,IAAI,OAAO,MAAM,KAAK,WAAW,CAAA;AAEhG,IAAI,cAA8D,CAAA;AAElE,IAAI,eAAe,KAAK,KAAK,EAAE,CAAC;IAC9B,cAAc,GAAG,eAAe,EAAE,CAAA;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,IAAI,eAAe,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1,24 +1,40 @@
|
|
|
1
|
-
import { UnexpectedError } from '@livestore/common';
|
|
2
1
|
import type { LiveStoreSchema } from '@livestore/common/schema';
|
|
2
|
+
import { type WebDatabaseMetadataOpfs } from '@livestore/sqlite-wasm/browser';
|
|
3
3
|
import { Effect, Schema } from '@livestore/utils/effect';
|
|
4
|
+
import { Opfs, type WebError } from '@livestore/utils/effect/browser';
|
|
4
5
|
import type * as WorkerSchema from './worker-schema.ts';
|
|
5
6
|
declare const PersistedSqliteError_base: Schema.TaggedErrorClass<PersistedSqliteError, "PersistedSqliteError", {
|
|
6
7
|
readonly _tag: Schema.tag<"PersistedSqliteError">;
|
|
7
8
|
} & {
|
|
8
|
-
|
|
9
|
+
message: typeof Schema.String;
|
|
10
|
+
cause: Schema.optional<typeof Schema.Defect>;
|
|
9
11
|
}>;
|
|
10
12
|
export declare class PersistedSqliteError extends PersistedSqliteError_base {
|
|
11
13
|
}
|
|
12
|
-
export declare const
|
|
14
|
+
export declare const readPersistedStateDbFromClientSession: (args: {
|
|
13
15
|
storageOptions: WorkerSchema.StorageType;
|
|
14
16
|
storeId: string;
|
|
15
17
|
schema: LiveStoreSchema;
|
|
16
|
-
}) => Effect.Effect<Uint8Array<ArrayBuffer
|
|
17
|
-
export declare const resetPersistedDataFromClientSession: (
|
|
18
|
+
}) => Effect.Effect<Uint8Array<ArrayBuffer>, PersistedSqliteError | WebError.UnknownError | WebError.TypeError | WebError.NotFoundError | WebError.NotAllowedError | WebError.TypeMismatchError | WebError.SecurityError | Opfs.OpfsError, Opfs.Opfs>;
|
|
19
|
+
export declare const resetPersistedDataFromClientSession: (args_0: {
|
|
18
20
|
storageOptions: WorkerSchema.StorageType;
|
|
19
21
|
storeId: string;
|
|
20
|
-
}) => Effect.Effect<void,
|
|
21
|
-
export declare const sanitizeOpfsDir: (directory: string | undefined, storeId: string) => string
|
|
22
|
+
}) => Effect.Effect.AsEffect<Effect.Effect<void, PersistedSqliteError | WebError.UnknownError | WebError.TypeError | WebError.NotAllowedError | WebError.TypeMismatchError | WebError.SecurityError | Opfs.OpfsError | WebError.NoModificationAllowedError | WebError.InvalidModificationError, Opfs.Opfs>>;
|
|
23
|
+
export declare const sanitizeOpfsDir: (directory: string | undefined, storeId: string) => Effect.Effect<string, PersistedSqliteError, never>;
|
|
22
24
|
export declare const getStateDbFileName: (schema: LiveStoreSchema) => string;
|
|
25
|
+
export declare const MAX_ARCHIVED_STATE_DBS_IN_DEV = 3;
|
|
26
|
+
export declare const ARCHIVE_DIR_NAME = "archive";
|
|
27
|
+
/**
|
|
28
|
+
* Cleanup old state database files after successful migration.
|
|
29
|
+
* This prevents OPFS file pool capacity from being exhausted by accumulated schema files.
|
|
30
|
+
*
|
|
31
|
+
* @param vfs - The AccessHandlePoolVFS instance for safe file operations
|
|
32
|
+
* @param currentSchema - Current schema (to avoid deleting the active database)
|
|
33
|
+
*/
|
|
34
|
+
export declare const cleanupOldStateDbFiles: (options: {
|
|
35
|
+
vfs: WebDatabaseMetadataOpfs['vfs'];
|
|
36
|
+
currentSchema: LiveStoreSchema;
|
|
37
|
+
opfsDirectory: string;
|
|
38
|
+
}) => Effect.Effect<void, WebError.AbortError | WebError.DataCloneError | WebError.EvalError | WebError.InvalidModificationError | WebError.InvalidStateError | WebError.NoModificationAllowedError | WebError.NotAllowedError | WebError.NotFoundError | WebError.QuotaExceededError | WebError.RangeError | WebError.ReferenceError | WebError.SecurityError | WebError.TypeError | WebError.TypeMismatchError | WebError.URIError | WebError.UnknownError | Opfs.OpfsError | PersistedSqliteError, Opfs.Opfs>;
|
|
23
39
|
export {};
|
|
24
40
|
//# sourceMappingURL=persisted-sqlite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted-sqlite.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/persisted-sqlite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"persisted-sqlite.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/persisted-sqlite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MA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Q,CAAC,SAAS,GAClB,QAAQ,CAAC,wBAAwB,GACjC,QAAQ,CAAC,iBAAiB,GAC1B,QAAQ,CAAC,0BAA0B,GACnC,QAAQ,CAAC,eAAe,GACxB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,kBAAkB,GAC3B,QAAQ,CAAC,UAAU,GACnB,QAAQ,CAAC,cAAc,GACvB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,SAAS,GAClB,QAAQ,CAAC,iBAAiB,GAC1B,QAAQ,CAAC,QAAQ,GACjB,QAAQ,CAAC,YAAY,GACrB,IAAI,CAAC,SAAS,GACd,oBAAoB,EACtB,IAAI,CAAC,IAAI,CA+DT,CAAA"}
|
|
@@ -1,92 +1,130 @@
|
|
|
1
|
-
import { liveStoreStorageFormatVersion
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { liveStoreStorageFormatVersion } from '@livestore/common';
|
|
2
|
+
import { decodeAccessHandlePoolFilename, HEADER_OFFSET_DATA, } from '@livestore/sqlite-wasm/browser';
|
|
3
|
+
import { isDevEnv } from '@livestore/utils';
|
|
4
|
+
import { Chunk, Effect, Option, Order, Schedule, Schema, Stream } from '@livestore/utils/effect';
|
|
5
|
+
import { Opfs } from '@livestore/utils/effect/browser';
|
|
5
6
|
export class PersistedSqliteError extends Schema.TaggedError()('PersistedSqliteError', {
|
|
6
|
-
|
|
7
|
+
message: Schema.String,
|
|
8
|
+
cause: Schema.optional(Schema.Defect),
|
|
7
9
|
}) {
|
|
8
10
|
}
|
|
9
|
-
export const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export const readPersistedStateDbFromClientSession = Effect.fn('@livestore/adapter-web:readPersistedStateDbFromClientSession')(function* ({ storageOptions, storeId, schema }) {
|
|
12
|
+
const accessHandlePoolDirString = yield* sanitizeOpfsDir(storageOptions.directory, storeId);
|
|
13
|
+
const accessHandlePoolDirHandle = yield* Opfs.getDirectoryHandleByPath(accessHandlePoolDirString);
|
|
14
|
+
const stateDbFileName = `/${getStateDbFileName(schema)}`;
|
|
15
|
+
const handlesStream = yield* Opfs.Opfs.values(accessHandlePoolDirHandle);
|
|
16
|
+
const stateDbFileOption = yield* handlesStream.pipe(Stream.filter((handle) => handle.kind === 'file'), Stream.mapEffect((fileHandle) => Effect.gen(function* () {
|
|
17
|
+
const file = yield* Opfs.Opfs.getFile(fileHandle);
|
|
18
|
+
const fileName = yield* Effect.promise(() => decodeAccessHandlePoolFilename(file));
|
|
19
|
+
return { file, fileName };
|
|
20
|
+
}), { concurrency: 'unbounded' }), Stream.find(({ fileName }) => fileName === stateDbFileName), Stream.runHead);
|
|
21
|
+
if (Option.isNone(stateDbFileOption)) {
|
|
22
|
+
return yield* new PersistedSqliteError({
|
|
23
|
+
message: `State database file not found in client session (expected '${stateDbFileName}' in '${accessHandlePoolDirString}')`,
|
|
24
|
+
});
|
|
14
25
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for await (const value of asyncIterator) {
|
|
23
|
-
if (value.kind === 'file') {
|
|
24
|
-
results.push(value);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return results;
|
|
28
|
-
};
|
|
29
|
-
const files = await getAllFiles(sahPoolOpaqueDir.values());
|
|
30
|
-
const fileResults = await Promise.all(files.map(tryGetDbFile));
|
|
31
|
-
const appDbFileName = `/${getStateDbFileName(schema)}`;
|
|
32
|
-
const dbFileRes = fileResults.find((_) => _?.fileName === appDbFileName);
|
|
33
|
-
// console.debug('fileResults', fileResults, 'dbFileRes', dbFileRes)
|
|
34
|
-
if (dbFileRes !== undefined) {
|
|
35
|
-
const data = await dbFileRes.file.slice(HEADER_OFFSET_DATA).arrayBuffer();
|
|
36
|
-
// console.debug('readPersistedAppDbFromClientSession', data.byteLength, data)
|
|
37
|
-
// Given the SAH pool always eagerly creates files with empty non-header data,
|
|
38
|
-
// we want to return undefined if the file exists but is empty
|
|
39
|
-
if (data.byteLength === 0) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
return new Uint8Array(data);
|
|
26
|
+
const stateDbBuffer = yield* Effect.promise(() => stateDbFileOption.value.file.slice(HEADER_OFFSET_DATA).arrayBuffer());
|
|
27
|
+
// Given the access handle pool always eagerly creates files with empty non-header data,
|
|
28
|
+
// we want to return undefined if the file exists but is empty
|
|
29
|
+
if (stateDbBuffer.byteLength === 0) {
|
|
30
|
+
return yield* new PersistedSqliteError({
|
|
31
|
+
message: `State database file is empty in client session (expected '${stateDbFileName}' in '${accessHandlePoolDirString}')`,
|
|
32
|
+
});
|
|
43
33
|
}
|
|
44
|
-
return
|
|
45
|
-
}
|
|
34
|
+
return new Uint8Array(stateDbBuffer);
|
|
35
|
+
}, Effect.logWarnIfTakesLongerThan({
|
|
46
36
|
duration: 1000,
|
|
47
|
-
label: '@livestore/adapter-web:
|
|
48
|
-
}), Effect.withPerformanceMeasure('@livestore/adapter-web:
|
|
49
|
-
export const resetPersistedDataFromClientSession = ({ storageOptions, storeId
|
|
50
|
-
const directory = sanitizeOpfsDir(storageOptions.directory, storeId);
|
|
51
|
-
yield*
|
|
52
|
-
|
|
37
|
+
label: '@livestore/adapter-web:readPersistedStateDbFromClientSession',
|
|
38
|
+
}), Effect.withPerformanceMeasure('@livestore/adapter-web:readPersistedStateDbFromClientSession'));
|
|
39
|
+
export const resetPersistedDataFromClientSession = Effect.fn('@livestore/adapter-web:resetPersistedDataFromClientSession')(function* ({ storageOptions, storeId }) {
|
|
40
|
+
const directory = yield* sanitizeOpfsDir(storageOptions.directory, storeId);
|
|
41
|
+
yield* Opfs.remove(directory).pipe(
|
|
42
|
+
// We ignore NotFoundError here as it may not exist or have already been deleted
|
|
43
|
+
Effect.catchTag('@livestore/utils/Web/NotFoundError', () => Effect.void));
|
|
44
|
+
}, Effect.retry({
|
|
53
45
|
schedule: Schedule.exponentialBackoff10Sec,
|
|
54
|
-
})
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const root = await OpfsUtils.rootHandlePromise;
|
|
58
|
-
// Split the absolute path to traverse directories
|
|
59
|
-
const pathParts = absPath.split('/').filter((part) => part.length);
|
|
60
|
-
try {
|
|
61
|
-
// Traverse to the target file handle
|
|
62
|
-
let currentDir = root;
|
|
63
|
-
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
64
|
-
currentDir = await currentDir.getDirectoryHandle(pathParts[i]);
|
|
65
|
-
}
|
|
66
|
-
// Delete the file
|
|
67
|
-
await currentDir.removeEntry(pathParts.at(-1), { recursive: true });
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
if (error instanceof DOMException && error.name === 'NotFoundError') {
|
|
71
|
-
// Can ignore as it's already been deleted or not there in the first place
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-web:worker:opfsDeleteFile', { attributes: { absFilePath: absPath } }));
|
|
79
|
-
export const sanitizeOpfsDir = (directory, storeId) => {
|
|
80
|
-
// Root dir should be `''` not `/`
|
|
81
|
-
if (directory === undefined || directory === '' || directory === '/')
|
|
46
|
+
}));
|
|
47
|
+
export const sanitizeOpfsDir = Effect.fn('@livestore/adapter-web:sanitizeOpfsDir')(function* (directory, storeId) {
|
|
48
|
+
if (directory === undefined || directory === '' || directory === '/') {
|
|
82
49
|
return `livestore-${storeId}@${liveStoreStorageFormatVersion}`;
|
|
50
|
+
}
|
|
83
51
|
if (directory.includes('/')) {
|
|
84
|
-
|
|
52
|
+
return yield* new PersistedSqliteError({
|
|
53
|
+
message: `Nested directories are not yet supported ('${directory}')`,
|
|
54
|
+
});
|
|
85
55
|
}
|
|
86
56
|
return `${directory}@${liveStoreStorageFormatVersion}`;
|
|
87
|
-
};
|
|
57
|
+
});
|
|
88
58
|
export const getStateDbFileName = (schema) => {
|
|
89
59
|
const schemaHashSuffix = schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString();
|
|
90
60
|
return `state${schemaHashSuffix}.db`;
|
|
91
61
|
};
|
|
62
|
+
export const MAX_ARCHIVED_STATE_DBS_IN_DEV = 3;
|
|
63
|
+
export const ARCHIVE_DIR_NAME = 'archive';
|
|
64
|
+
/**
|
|
65
|
+
* Cleanup old state database files after successful migration.
|
|
66
|
+
* This prevents OPFS file pool capacity from being exhausted by accumulated schema files.
|
|
67
|
+
*
|
|
68
|
+
* @param vfs - The AccessHandlePoolVFS instance for safe file operations
|
|
69
|
+
* @param currentSchema - Current schema (to avoid deleting the active database)
|
|
70
|
+
*/
|
|
71
|
+
export const cleanupOldStateDbFiles = Effect.fn('@livestore/adapter-web:cleanupOldStateDbFiles')(function* ({ vfs, currentSchema, opfsDirectory }) {
|
|
72
|
+
// Only cleanup for auto migration strategy because:
|
|
73
|
+
// - Auto strategy: Creates new database files per schema change (e.g., state123.db, state456.db)
|
|
74
|
+
// which accumulate over time and can exhaust OPFS file pool capacity
|
|
75
|
+
// - Manual strategy: Always reuses the same database file (statefixed.db) across schema changes,
|
|
76
|
+
// so there are never multiple old files to clean up
|
|
77
|
+
if (currentSchema.state.sqlite.migrations.strategy === 'manual') {
|
|
78
|
+
yield* Effect.logDebug('Skipping state db cleanup - manual migration strategy uses fixed filename');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const isDev = isDevEnv();
|
|
82
|
+
const currentDbFileName = getStateDbFileName(currentSchema);
|
|
83
|
+
const currentPath = `/${currentDbFileName}`;
|
|
84
|
+
const allPaths = yield* Effect.sync(() => vfs.getTrackedFilePaths());
|
|
85
|
+
const oldStateDbPaths = allPaths.filter((path) => path.startsWith('/state') && path.endsWith('.db') && path !== currentPath);
|
|
86
|
+
if (oldStateDbPaths.length === 0) {
|
|
87
|
+
yield* Effect.logDebug('No old database files found');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const absoluteArchiveDirName = `${opfsDirectory}/${ARCHIVE_DIR_NAME}`;
|
|
91
|
+
if (isDev && !(yield* Opfs.exists(absoluteArchiveDirName)))
|
|
92
|
+
yield* Opfs.makeDirectory(absoluteArchiveDirName);
|
|
93
|
+
for (const path of oldStateDbPaths) {
|
|
94
|
+
const fileName = path.startsWith('/') ? path.slice(1) : path;
|
|
95
|
+
if (isDev) {
|
|
96
|
+
const archiveFileData = yield* vfs.readFilePayload(fileName);
|
|
97
|
+
const archiveFileName = `${Date.now()}-${fileName}`;
|
|
98
|
+
yield* Opfs.writeFile(`${opfsDirectory}/archive/${archiveFileName}`, new Uint8Array(archiveFileData));
|
|
99
|
+
}
|
|
100
|
+
const vfsResultCode = yield* Effect.try({
|
|
101
|
+
try: () => vfs.jDelete(fileName, 0),
|
|
102
|
+
catch: (cause) => new PersistedSqliteError({ message: `Failed to delete old state database file: ${fileName}`, cause }),
|
|
103
|
+
});
|
|
104
|
+
// 0 indicates a successful result in SQLite.
|
|
105
|
+
// See https://www.sqlite.org/c3ref/c_abort.html
|
|
106
|
+
if (vfsResultCode !== 0) {
|
|
107
|
+
return yield* new PersistedSqliteError({
|
|
108
|
+
message: `Failed to delete old state database file: ${fileName}, got result code: ${vfsResultCode}`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
yield* Effect.logDebug(`Deleted old state database file: ${fileName}`);
|
|
112
|
+
}
|
|
113
|
+
if (isDev) {
|
|
114
|
+
yield* pruneArchiveDirectory({
|
|
115
|
+
archiveDirectory: absoluteArchiveDirName,
|
|
116
|
+
keep: MAX_ARCHIVED_STATE_DBS_IN_DEV,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const pruneArchiveDirectory = Effect.fn('@livestore/adapter-web:pruneArchiveDirectory')(function* ({ archiveDirectory, keep, }) {
|
|
121
|
+
const archiveDirHandle = yield* Opfs.getDirectoryHandleByPath(archiveDirectory);
|
|
122
|
+
const handlesStream = yield* Opfs.Opfs.values(archiveDirHandle);
|
|
123
|
+
const filesWithMetadata = yield* handlesStream.pipe(Stream.filter((handle) => handle.kind === 'file'), Stream.mapEffect((fileHandle) => Opfs.getMetadata(fileHandle)), Stream.runCollect);
|
|
124
|
+
const filesToDelete = filesWithMetadata.pipe(Chunk.sort(Order.mapInput(Order.number, (entry) => entry.lastModified)), Chunk.drop(keep), Chunk.toReadonlyArray);
|
|
125
|
+
if (filesToDelete.length === 0)
|
|
126
|
+
return;
|
|
127
|
+
yield* Effect.forEach(filesToDelete, ({ name }) => Opfs.Opfs.removeEntry(archiveDirHandle, name));
|
|
128
|
+
yield* Effect.logDebug(`Pruned ${filesToDelete.length} old database file(s) from archive directory`);
|
|
129
|
+
});
|
|
92
130
|
//# sourceMappingURL=persisted-sqlite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted-sqlite.js","sourceRoot":"","sources":["../../../src/web-worker/common/persisted-sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,
|
|
1
|
+
{"version":3,"file":"persisted-sqlite.js","sourceRoot":"","sources":["../../../src/web-worker/common/persisted-sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAEjE,OAAO,EACL,8BAA8B,EAC9B,kBAAkB,GAEnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChG,OAAO,EAAE,IAAI,EAAiB,MAAM,iCAAiC,CAAA;AAGrE,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAAC,sBAAsB,EAAE;IAC3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M,8CAA8C,CAAC,CAAA;AACtG,CAAC,CAAC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ShutdownChannel } from '@livestore/common/leader-thread';
|
|
2
|
+
import type { Effect, Scope, WebChannel } from '@livestore/utils/effect';
|
|
3
|
+
export declare const makeShutdownChannel: (storeId: string) => Effect.Effect<WebChannel.WebChannel<typeof ShutdownChannel.All.Type, typeof ShutdownChannel.All.Type>, never, Scope.Scope>;
|
|
3
4
|
//# sourceMappingURL=shutdown-channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown-channel.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/shutdown-channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shutdown-channel.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/shutdown-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGxE,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,KACd,MAAM,CAAC,MAAM,CACd,UAAU,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EACvF,KAAK,EACL,KAAK,CAAC,KAAK,CAKT,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ShutdownChannel } from '@livestore/common/leader-thread';
|
|
2
|
-
import {
|
|
3
|
-
export const makeShutdownChannel = (storeId) =>
|
|
2
|
+
import { WebChannelBrowser } from '@livestore/utils/effect/browser';
|
|
3
|
+
export const makeShutdownChannel = (storeId) => WebChannelBrowser.broadcastChannel({
|
|
4
4
|
channelName: `livestore.shutdown.${storeId}`,
|
|
5
5
|
schema: ShutdownChannel.All,
|
|
6
6
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown-channel.js","sourceRoot":"","sources":["../../../src/web-worker/common/shutdown-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"shutdown-channel.js","sourceRoot":"","sources":["../../../src/web-worker/common/shutdown-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAe,EAKf,EAAE,CACF,iBAAiB,CAAC,gBAAgB,CAAC;IACjC,WAAW,EAAE,sBAAsB,OAAO,EAAE;IAC5C,MAAM,EAAE,eAAe,CAAC,GAAG;CAC5B,CAAC,CAAA"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Schema, WebChannel } from '@livestore/utils/effect';
|
|
1
|
+
import { type Effect, Schema, type Scope, type WebChannel } from '@livestore/utils/effect';
|
|
2
2
|
declare const DedicatedWorkerDisconnectBroadcast_base: Schema.TaggedStruct<"DedicatedWorkerDisconnectBroadcast", {}>;
|
|
3
3
|
export declare class DedicatedWorkerDisconnectBroadcast extends DedicatedWorkerDisconnectBroadcast_base {
|
|
4
4
|
}
|
|
5
5
|
/** Used across workers for leader election purposes */
|
|
6
|
-
export declare const makeWorkerDisconnectChannel: (storeId: string) =>
|
|
7
|
-
readonly _tag: "DedicatedWorkerDisconnectBroadcast";
|
|
8
|
-
}, {
|
|
9
|
-
readonly _tag: "DedicatedWorkerDisconnectBroadcast";
|
|
10
|
-
}, never>, never, import("effect/Scope").Scope>;
|
|
6
|
+
export declare const makeWorkerDisconnectChannel: (storeId: string) => Effect.Effect<WebChannel.WebChannel<typeof DedicatedWorkerDisconnectBroadcast.Type, typeof DedicatedWorkerDisconnectBroadcast.Type>, never, Scope.Scope>;
|
|
11
7
|
export {};
|
|
12
8
|
//# sourceMappingURL=worker-disconnect-channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-disconnect-channel.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/worker-disconnect-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;;
|
|
1
|
+
{"version":3,"file":"worker-disconnect-channel.d.ts","sourceRoot":"","sources":["../../../src/web-worker/common/worker-disconnect-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAA;;AAG1F,qBAAa,kCAAmC,SAAQ,uCAA6D;CAAG;AAExH,uDAAuD;AACvD,eAAO,MAAM,2BAA2B,GACtC,SAAS,MAAM,KACd,MAAM,CAAC,MAAM,CACd,UAAU,CAAC,UAAU,CAAC,OAAO,kCAAkC,CAAC,IAAI,EAAE,OAAO,kCAAkC,CAAC,IAAI,CAAC,EACrH,KAAK,EACL,KAAK,CAAC,KAAK,CAKT,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from '@livestore/utils/effect';
|
|
2
|
+
import { WebChannelBrowser } from '@livestore/utils/effect/browser';
|
|
2
3
|
export class DedicatedWorkerDisconnectBroadcast extends Schema.TaggedStruct('DedicatedWorkerDisconnectBroadcast', {}) {
|
|
3
4
|
}
|
|
4
5
|
/** Used across workers for leader election purposes */
|
|
5
|
-
export const makeWorkerDisconnectChannel = (storeId) =>
|
|
6
|
+
export const makeWorkerDisconnectChannel = (storeId) => WebChannelBrowser.broadcastChannel({
|
|
6
7
|
channelName: `livestore.worker-disconnect.${storeId}`,
|
|
7
8
|
schema: DedicatedWorkerDisconnectBroadcast,
|
|
8
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-disconnect-channel.js","sourceRoot":"","sources":["../../../src/web-worker/common/worker-disconnect-channel.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"worker-disconnect-channel.js","sourceRoot":"","sources":["../../../src/web-worker/common/worker-disconnect-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAA+B,MAAM,yBAAyB,CAAA;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEnE,MAAM,OAAO,kCAAmC,SAAQ,MAAM,CAAC,YAAY,CAAC,oCAAoC,EAAE,EAAE,CAAC;CAAG;AAExH,uDAAuD;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,OAAe,EAKf,EAAE,CACF,iBAAiB,CAAC,gBAAgB,CAAC;IACjC,WAAW,EAAE,+BAA+B,OAAO,EAAE;IACrD,MAAM,EAAE,kCAAkC;CAC3C,CAAC,CAAA"}
|