@livestore/adapter-expo 0.4.0-dev.0 → 0.4.0-dev.10
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/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -21
- package/dist/index.js.map +1 -1
- package/dist/shutdown-channel.d.ts +1 -1
- package/dist/shutdown-channel.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +98 -17
package/dist/index.d.ts
CHANGED
|
@@ -15,9 +15,12 @@ export type MakeDbOptions = {
|
|
|
15
15
|
clientId?: string;
|
|
16
16
|
/** @default 'static' */
|
|
17
17
|
sessionId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Warning: This will reset both the app and eventlog database. This should only be used during development.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
resetPersistence?: boolean;
|
|
18
24
|
};
|
|
19
|
-
declare global {
|
|
20
|
-
var RN$Bridgeless: boolean | undefined;
|
|
21
|
-
}
|
|
22
25
|
export declare const makePersistedAdapter: (options?: MakeDbOptions) => Adapter;
|
|
23
26
|
//# 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,CAAA;AAEtB,OAAO,EACL,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAEtB,OAAO,EACL,KAAK,OAAO,EAQZ,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAA;AA2B1B,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,OAAO,CAAC,EAAE;QACR;;;;;WAKG;QACH,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB,CAAA;IAED,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAWD,eAAO,MAAM,oBAAoB,GAC9B,UAAS,aAAkB,KAAG,OA0FiF,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import "./polyfill.js";
|
|
2
|
-
import { ClientSessionLeaderThreadProxy, Devtools, liveStoreStorageFormatVersion, makeClientSession, UnexpectedError, } from '@livestore/common';
|
|
2
|
+
import { ClientSessionLeaderThreadProxy, Devtools, IntentionalShutdownCause, liveStoreStorageFormatVersion, makeClientSession, UnexpectedError, } from '@livestore/common';
|
|
3
3
|
import { Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread';
|
|
4
4
|
import { LiveStoreEvent } from '@livestore/common/schema';
|
|
5
5
|
import { shouldNeverHappen } from '@livestore/utils';
|
|
6
|
-
import { Effect, Exit, FetchHttpClient, Fiber, Layer, Queue, Stream, SubscriptionRef } from '@livestore/utils/effect';
|
|
6
|
+
import { Effect, Exit, FetchHttpClient, Fiber, Layer, Queue, Schedule, Stream, SubscriptionRef, } from '@livestore/utils/effect';
|
|
7
7
|
import * as Webmesh from '@livestore/webmesh';
|
|
8
8
|
import * as ExpoApplication from 'expo-application';
|
|
9
9
|
import * as SQLite from 'expo-sqlite';
|
|
10
10
|
import * as RN from 'react-native';
|
|
11
11
|
import { makeSqliteDb } from "./make-sqlite-db.js";
|
|
12
12
|
import { makeShutdownChannel } from "./shutdown-channel.js";
|
|
13
|
-
|
|
13
|
+
// Expo Go with the New Architecture enables Fabric and TurboModules, but may not run in "bridgeless" mode.
|
|
14
|
+
// Rely on Fabric/TurboModules feature detection instead of RN$Bridgeless.
|
|
15
|
+
const IS_NEW_ARCH =
|
|
16
|
+
// Fabric global – set when the new renderer is enabled
|
|
17
|
+
Boolean(globalThis.nativeFabricUIManager) ||
|
|
18
|
+
// TurboModule proxy – indicates new arch TurboModules
|
|
19
|
+
Boolean(globalThis.__turboModuleProxy);
|
|
14
20
|
// TODO refactor with leader-thread code from `@livestore/common/leader-thread`
|
|
15
21
|
export const makePersistedAdapter = (options = {}) => (adapterArgs) => Effect.gen(function* () {
|
|
16
22
|
if (IS_NEW_ARCH === false) {
|
|
@@ -19,12 +25,16 @@ export const makePersistedAdapter = (options = {}) => (adapterArgs) => Effect.ge
|
|
|
19
25
|
});
|
|
20
26
|
}
|
|
21
27
|
const { schema, shutdown, devtoolsEnabled, storeId, bootStatusQueue, syncPayload } = adapterArgs;
|
|
22
|
-
const { storage, clientId = yield* getDeviceId, sessionId = 'static', sync: syncOptions } = options;
|
|
28
|
+
const { storage, clientId = yield* getDeviceId, sessionId = 'static', sync: syncOptions, resetPersistence = false, } = options;
|
|
23
29
|
yield* Queue.offer(bootStatusQueue, { stage: 'loading' });
|
|
24
30
|
const lockStatus = yield* SubscriptionRef.make('has-lock');
|
|
25
31
|
const shutdownChannel = yield* makeShutdownChannel(storeId);
|
|
32
|
+
if (resetPersistence === true) {
|
|
33
|
+
yield* shutdownChannel.send(IntentionalShutdownCause.make({ reason: 'adapter-reset' }));
|
|
34
|
+
yield* resetExpoPersistence({ storeId, storage, schema });
|
|
35
|
+
}
|
|
26
36
|
yield* shutdownChannel.listen.pipe(Stream.flatten(), Stream.tap((cause) => shutdown(cause._tag === 'LiveStore.IntentionalShutdownCause' ? Exit.succeed(cause) : Exit.fail(cause))), Stream.runDrain, Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
27
|
-
const devtoolsUrl = getDevtoolsUrl().toString();
|
|
37
|
+
const devtoolsUrl = devtoolsEnabled ? getDevtoolsUrl().toString() : 'ws://127.0.0.1:4242';
|
|
28
38
|
const { leaderThread, initialSnapshot } = yield* makeLeaderThread({
|
|
29
39
|
storeId,
|
|
30
40
|
clientId,
|
|
@@ -67,14 +77,13 @@ export const makePersistedAdapter = (options = {}) => (adapterArgs) => Effect.ge
|
|
|
67
77
|
return clientSession;
|
|
68
78
|
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.provide(FetchHttpClient.layer), Effect.tapCauseLogPretty);
|
|
69
79
|
const makeLeaderThread = ({ storeId, clientId, schema, makeSqliteDb, syncOptions, storage, devtoolsEnabled, bootStatusQueue: bootStatusQueueClientSession, syncPayload, devtoolsUrl, }) => Effect.gen(function* () {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const dbEventlogPath = `${'livestore-'}eventlog@${liveStoreStorageFormatVersion}.db`;
|
|
80
|
+
const { directory, stateDatabaseName, eventlogDatabaseName } = resolveExpoPersistencePaths({
|
|
81
|
+
storeId,
|
|
82
|
+
storage,
|
|
83
|
+
schema,
|
|
84
|
+
});
|
|
76
85
|
const dbState = yield* makeSqliteDb({ _tag: 'file', databaseName: stateDatabaseName, directory });
|
|
77
|
-
const dbEventlog = yield* makeSqliteDb({ _tag: 'file', databaseName:
|
|
86
|
+
const dbEventlog = yield* makeSqliteDb({ _tag: 'file', databaseName: eventlogDatabaseName, directory });
|
|
78
87
|
const devtoolsOptions = yield* makeDevtoolsOptions({
|
|
79
88
|
devtoolsEnabled,
|
|
80
89
|
devtoolsUrl,
|
|
@@ -97,7 +106,7 @@ const makeLeaderThread = ({ storeId, clientId, schema, makeSqliteDb, syncOptions
|
|
|
97
106
|
syncPayload,
|
|
98
107
|
}).pipe(Layer.provideMerge(FetchHttpClient.layer)));
|
|
99
108
|
return yield* Effect.gen(function* () {
|
|
100
|
-
const { dbState: db, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState, bootStatusQueue, } = yield* LeaderThreadCtx;
|
|
109
|
+
const { dbState: db, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState, bootStatusQueue, networkStatus, } = yield* LeaderThreadCtx;
|
|
101
110
|
const bootStatusFiber = yield* Queue.takeBetween(bootStatusQueue, 1, 1000).pipe(Effect.tap((bootStatus) => Queue.offerAll(bootStatusQueueClientSession, bootStatus)), Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
102
111
|
yield* Queue.awaitShutdown(bootStatusQueueClientSession).pipe(Effect.andThen(Fiber.interrupt(bootStatusFiber)), Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
103
112
|
const initialLeaderHead = Eventlog.getClientHeadFromDb(dbEventlog);
|
|
@@ -113,11 +122,36 @@ const makeLeaderThread = ({ storeId, clientId, schema, makeSqliteDb, syncOptions
|
|
|
113
122
|
getEventlogData: Effect.sync(() => dbEventlog.export()),
|
|
114
123
|
getSyncState: syncProcessor.syncState,
|
|
115
124
|
sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
|
|
125
|
+
networkStatus,
|
|
116
126
|
});
|
|
117
127
|
const initialSnapshot = db.export();
|
|
118
128
|
return { leaderThread, initialSnapshot };
|
|
119
129
|
}).pipe(Effect.provide(layer));
|
|
120
130
|
});
|
|
131
|
+
const resolveExpoPersistencePaths = ({ storeId, storage, schema, }) => {
|
|
132
|
+
const subDirectory = storage?.subDirectory ? `${storage.subDirectory.replace(/\/$/, '')}/` : '';
|
|
133
|
+
const pathJoin = (...paths) => paths.join('/').replaceAll(/\/+/g, '/');
|
|
134
|
+
const directory = pathJoin(SQLite.defaultDatabaseDirectory, subDirectory, storeId);
|
|
135
|
+
const schemaHashSuffix = schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString();
|
|
136
|
+
const stateDatabaseName = `livestore-${schemaHashSuffix}@${liveStoreStorageFormatVersion}.db`;
|
|
137
|
+
const eventlogDatabaseName = `livestore-eventlog@${liveStoreStorageFormatVersion}.db`;
|
|
138
|
+
return { directory, stateDatabaseName, eventlogDatabaseName };
|
|
139
|
+
};
|
|
140
|
+
const resetExpoPersistence = ({ storeId, storage, schema, }) => Effect.try({
|
|
141
|
+
try: () => {
|
|
142
|
+
const { directory, stateDatabaseName, eventlogDatabaseName } = resolveExpoPersistencePaths({
|
|
143
|
+
storeId,
|
|
144
|
+
storage,
|
|
145
|
+
schema,
|
|
146
|
+
});
|
|
147
|
+
SQLite.deleteDatabaseSync(stateDatabaseName, directory);
|
|
148
|
+
SQLite.deleteDatabaseSync(eventlogDatabaseName, directory);
|
|
149
|
+
},
|
|
150
|
+
catch: (cause) => new UnexpectedError({
|
|
151
|
+
cause,
|
|
152
|
+
note: `@livestore/adapter-expo: Failed to reset persistence for store ${storeId}`,
|
|
153
|
+
}),
|
|
154
|
+
}).pipe(Effect.retry({ schedule: Schedule.exponentialBackoff10Sec }), Effect.withSpan('@livestore/adapter-expo:resetPersistence', { attributes: { storeId } }));
|
|
121
155
|
const makeDevtoolsOptions = ({ devtoolsEnabled, devtoolsUrl, dbState, dbEventlog, storeId, clientId, }) => Effect.sync(() => {
|
|
122
156
|
if (devtoolsEnabled === false) {
|
|
123
157
|
return {
|
|
@@ -157,15 +191,16 @@ const getDeviceId = Effect.gen(function* () {
|
|
|
157
191
|
}
|
|
158
192
|
});
|
|
159
193
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
194
|
+
* Determine the devtools WebSocket URL.
|
|
195
|
+
* Avoid relying on RN internal Devtools modules (deep imports), which can
|
|
196
|
+
* change across versions and caused crashes in dev. Prefer an explicit env var
|
|
197
|
+
* and fall back to localhost which works for iOS Simulator when
|
|
198
|
+
* `EXPO_USE_LOCALHOST=1` is set.
|
|
162
199
|
*/
|
|
163
200
|
const getDevtoolsUrl = () => {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const devServerUrl = new URL(devServer);
|
|
169
|
-
return new URL(`ws://${devServerUrl.hostname}:${port}`);
|
|
201
|
+
const fromEnv = process.env.EXPO_PUBLIC_LIVESTORE_DEVTOOLS_URL;
|
|
202
|
+
if (fromEnv && fromEnv.length > 0)
|
|
203
|
+
return new URL(fromEnv);
|
|
204
|
+
return new URL('ws://127.0.0.1:4242');
|
|
170
205
|
};
|
|
171
206
|
//# 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,CAAA;AAEtB,OAAO,EAGL,8BAA8B,EAC9B,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAEtB,OAAO,EAGL,8BAA8B,EAC9B,QAAQ,EACR,wBAAwB,EAExB,6BAA6B,EAC7B,iBAAiB,EAEjB,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AAElG,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EACL,MAAM,EACN,IAAI,EACJ,eAAe,EACf,KAAK,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,eAAe,GAChB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,eAAe,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAA;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AA0B3D,2GAA2G;AAC3G,0EAA0E;AAC1E,MAAM,WAAW;AACf,uDAAuD;AACvD,OAAO,CAAE,UAAkB,CAAC,qBAAqB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EAAE,OAAO,EAAE,CAAA;QACjD,CAAC,CAAC;KACH,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtC,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,eAAe,CAAC,YAAY,EAAE,CAAA;IACvC,CAAC;SAAM,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC,CAAA;QACnF,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,iBAAiB,CAAC,4BAA4B,CAAC,CAAA;QACxD,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;SAAM,CAAC;QACN,OAAO,iBAAiB,CAAC,sCAAsC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAA;IAClF,CAAC;AACH,CAAC,CAAC,CAAA;AAEF;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAA;IAC9D,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;IAC1D,OAAO,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { WebChannel } from '@livestore/utils/effect';
|
|
2
|
-
export declare const makeShutdownChannel: (storeId: string) => import("effect/Effect").Effect<WebChannel.WebChannel<import("@livestore/common").UnexpectedError | import("@livestore/common").IntentionalShutdownCause | import("@livestore/common").
|
|
2
|
+
export declare const makeShutdownChannel: (storeId: string) => import("effect/Effect").Effect<WebChannel.WebChannel<import("@livestore/common").UnexpectedError | import("@livestore/common").IntentionalShutdownCause | import("@livestore/common").IsOfflineError | import("@livestore/common").InvalidPushError | import("@livestore/common").InvalidPullError | import("@livestore/common").MaterializeError, import("@livestore/common").UnexpectedError | import("@livestore/common").IntentionalShutdownCause | import("@livestore/common").IsOfflineError | import("@livestore/common").InvalidPushError | import("@livestore/common").InvalidPullError | import("@livestore/common").MaterializeError, never>, never, import("effect/Scope").Scope>;
|
|
3
3
|
//# sourceMappingURL=shutdown-channel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown-channel.d.ts","sourceRoot":"","sources":["../src/shutdown-channel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGpD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"shutdown-channel.d.ts","sourceRoot":"","sources":["../src/shutdown-channel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGpD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,kqBAI/C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/adapter-expo",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@opentelemetry/api": "1.9.0",
|
|
11
|
-
"@livestore/common": "0.4.0-dev.
|
|
12
|
-
"@livestore/
|
|
13
|
-
"@livestore/
|
|
11
|
+
"@livestore/common": "0.4.0-dev.10",
|
|
12
|
+
"@livestore/utils": "0.4.0-dev.10",
|
|
13
|
+
"@livestore/webmesh": "0.4.0-dev.10"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"expo-application": "^
|
|
17
|
-
"expo-file-system": "^
|
|
18
|
-
"expo-sqlite": "^
|
|
19
|
-
"react-native": "^0.
|
|
16
|
+
"expo-application": "^7.0.7",
|
|
17
|
+
"expo-file-system": "^19.0.15",
|
|
18
|
+
"expo-sqlite": "^16.0.8",
|
|
19
|
+
"react-native": "^0.81.4"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"package.json",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"expo-application": "^
|
|
29
|
-
"expo-file-system": "^
|
|
30
|
-
"expo-sqlite": "^
|
|
28
|
+
"expo-application": "^7.0.7",
|
|
29
|
+
"expo-file-system": "^19.0.15",
|
|
30
|
+
"expo-sqlite": "^16.0.8"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type BootStatus,
|
|
6
6
|
ClientSessionLeaderThreadProxy,
|
|
7
7
|
Devtools,
|
|
8
|
+
IntentionalShutdownCause,
|
|
8
9
|
type LockStatus,
|
|
9
10
|
liveStoreStorageFormatVersion,
|
|
10
11
|
makeClientSession,
|
|
@@ -17,7 +18,17 @@ import type { LiveStoreSchema } from '@livestore/common/schema'
|
|
|
17
18
|
import { LiveStoreEvent } from '@livestore/common/schema'
|
|
18
19
|
import { shouldNeverHappen } from '@livestore/utils'
|
|
19
20
|
import type { Schema, Scope } from '@livestore/utils/effect'
|
|
20
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
Effect,
|
|
23
|
+
Exit,
|
|
24
|
+
FetchHttpClient,
|
|
25
|
+
Fiber,
|
|
26
|
+
Layer,
|
|
27
|
+
Queue,
|
|
28
|
+
Schedule,
|
|
29
|
+
Stream,
|
|
30
|
+
SubscriptionRef,
|
|
31
|
+
} from '@livestore/utils/effect'
|
|
21
32
|
import * as Webmesh from '@livestore/webmesh'
|
|
22
33
|
import * as ExpoApplication from 'expo-application'
|
|
23
34
|
import * as SQLite from 'expo-sqlite'
|
|
@@ -43,13 +54,21 @@ export type MakeDbOptions = {
|
|
|
43
54
|
clientId?: string
|
|
44
55
|
/** @default 'static' */
|
|
45
56
|
sessionId?: string
|
|
57
|
+
/**
|
|
58
|
+
* Warning: This will reset both the app and eventlog database. This should only be used during development.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
resetPersistence?: boolean
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
// Expo Go with the New Architecture enables Fabric and TurboModules, but may not run in "bridgeless" mode.
|
|
66
|
+
// Rely on Fabric/TurboModules feature detection instead of RN$Bridgeless.
|
|
67
|
+
const IS_NEW_ARCH =
|
|
68
|
+
// Fabric global – set when the new renderer is enabled
|
|
69
|
+
Boolean((globalThis as any).nativeFabricUIManager) ||
|
|
70
|
+
// TurboModule proxy – indicates new arch TurboModules
|
|
71
|
+
Boolean((globalThis as any).__turboModuleProxy)
|
|
53
72
|
|
|
54
73
|
// TODO refactor with leader-thread code from `@livestore/common/leader-thread`
|
|
55
74
|
export const makePersistedAdapter =
|
|
@@ -66,7 +85,13 @@ export const makePersistedAdapter =
|
|
|
66
85
|
|
|
67
86
|
const { schema, shutdown, devtoolsEnabled, storeId, bootStatusQueue, syncPayload } = adapterArgs
|
|
68
87
|
|
|
69
|
-
const {
|
|
88
|
+
const {
|
|
89
|
+
storage,
|
|
90
|
+
clientId = yield* getDeviceId,
|
|
91
|
+
sessionId = 'static',
|
|
92
|
+
sync: syncOptions,
|
|
93
|
+
resetPersistence = false,
|
|
94
|
+
} = options
|
|
70
95
|
|
|
71
96
|
yield* Queue.offer(bootStatusQueue, { stage: 'loading' })
|
|
72
97
|
|
|
@@ -74,6 +99,12 @@ export const makePersistedAdapter =
|
|
|
74
99
|
|
|
75
100
|
const shutdownChannel = yield* makeShutdownChannel(storeId)
|
|
76
101
|
|
|
102
|
+
if (resetPersistence === true) {
|
|
103
|
+
yield* shutdownChannel.send(IntentionalShutdownCause.make({ reason: 'adapter-reset' }))
|
|
104
|
+
|
|
105
|
+
yield* resetExpoPersistence({ storeId, storage, schema })
|
|
106
|
+
}
|
|
107
|
+
|
|
77
108
|
yield* shutdownChannel.listen.pipe(
|
|
78
109
|
Stream.flatten(),
|
|
79
110
|
Stream.tap((cause) =>
|
|
@@ -85,7 +116,7 @@ export const makePersistedAdapter =
|
|
|
85
116
|
Effect.forkScoped,
|
|
86
117
|
)
|
|
87
118
|
|
|
88
|
-
const devtoolsUrl = getDevtoolsUrl().toString()
|
|
119
|
+
const devtoolsUrl = devtoolsEnabled ? getDevtoolsUrl().toString() : 'ws://127.0.0.1:4242'
|
|
89
120
|
|
|
90
121
|
const { leaderThread, initialSnapshot } = yield* makeLeaderThread({
|
|
91
122
|
storeId,
|
|
@@ -159,17 +190,14 @@ const makeLeaderThread = ({
|
|
|
159
190
|
devtoolsUrl: string
|
|
160
191
|
}) =>
|
|
161
192
|
Effect.gen(function* () {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString()
|
|
168
|
-
const stateDatabaseName = `${'livestore-'}${schemaHashSuffix}@${liveStoreStorageFormatVersion}.db`
|
|
169
|
-
const dbEventlogPath = `${'livestore-'}eventlog@${liveStoreStorageFormatVersion}.db`
|
|
193
|
+
const { directory, stateDatabaseName, eventlogDatabaseName } = resolveExpoPersistencePaths({
|
|
194
|
+
storeId,
|
|
195
|
+
storage,
|
|
196
|
+
schema,
|
|
197
|
+
})
|
|
170
198
|
|
|
171
199
|
const dbState = yield* makeSqliteDb({ _tag: 'file', databaseName: stateDatabaseName, directory })
|
|
172
|
-
const dbEventlog = yield* makeSqliteDb({ _tag: 'file', databaseName:
|
|
200
|
+
const dbEventlog = yield* makeSqliteDb({ _tag: 'file', databaseName: eventlogDatabaseName, directory })
|
|
173
201
|
|
|
174
202
|
const devtoolsOptions = yield* makeDevtoolsOptions({
|
|
175
203
|
devtoolsEnabled,
|
|
@@ -204,6 +232,7 @@ const makeLeaderThread = ({
|
|
|
204
232
|
extraIncomingMessagesQueue,
|
|
205
233
|
initialState,
|
|
206
234
|
bootStatusQueue,
|
|
235
|
+
networkStatus,
|
|
207
236
|
} = yield* LeaderThreadCtx
|
|
208
237
|
|
|
209
238
|
const bootStatusFiber = yield* Queue.takeBetween(bootStatusQueue, 1, 1000).pipe(
|
|
@@ -237,6 +266,7 @@ const makeLeaderThread = ({
|
|
|
237
266
|
getEventlogData: Effect.sync(() => dbEventlog.export()),
|
|
238
267
|
getSyncState: syncProcessor.syncState,
|
|
239
268
|
sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
|
|
269
|
+
networkStatus,
|
|
240
270
|
})
|
|
241
271
|
|
|
242
272
|
const initialSnapshot = db.export()
|
|
@@ -245,6 +275,57 @@ const makeLeaderThread = ({
|
|
|
245
275
|
}).pipe(Effect.provide(layer))
|
|
246
276
|
})
|
|
247
277
|
|
|
278
|
+
const resolveExpoPersistencePaths = ({
|
|
279
|
+
storeId,
|
|
280
|
+
storage,
|
|
281
|
+
schema,
|
|
282
|
+
}: {
|
|
283
|
+
storeId: string
|
|
284
|
+
storage: { subDirectory?: string } | undefined
|
|
285
|
+
schema: LiveStoreSchema
|
|
286
|
+
}) => {
|
|
287
|
+
const subDirectory = storage?.subDirectory ? `${storage.subDirectory.replace(/\/$/, '')}/` : ''
|
|
288
|
+
const pathJoin = (...paths: string[]) => paths.join('/').replaceAll(/\/+/g, '/')
|
|
289
|
+
const directory = pathJoin(SQLite.defaultDatabaseDirectory, subDirectory, storeId)
|
|
290
|
+
|
|
291
|
+
const schemaHashSuffix =
|
|
292
|
+
schema.state.sqlite.migrations.strategy === 'manual' ? 'fixed' : schema.state.sqlite.hash.toString()
|
|
293
|
+
const stateDatabaseName = `livestore-${schemaHashSuffix}@${liveStoreStorageFormatVersion}.db`
|
|
294
|
+
const eventlogDatabaseName = `livestore-eventlog@${liveStoreStorageFormatVersion}.db`
|
|
295
|
+
|
|
296
|
+
return { directory, stateDatabaseName, eventlogDatabaseName }
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const resetExpoPersistence = ({
|
|
300
|
+
storeId,
|
|
301
|
+
storage,
|
|
302
|
+
schema,
|
|
303
|
+
}: {
|
|
304
|
+
storeId: string
|
|
305
|
+
storage: MakeDbOptions['storage']
|
|
306
|
+
schema: LiveStoreSchema
|
|
307
|
+
}) =>
|
|
308
|
+
Effect.try({
|
|
309
|
+
try: () => {
|
|
310
|
+
const { directory, stateDatabaseName, eventlogDatabaseName } = resolveExpoPersistencePaths({
|
|
311
|
+
storeId,
|
|
312
|
+
storage,
|
|
313
|
+
schema,
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
SQLite.deleteDatabaseSync(stateDatabaseName, directory)
|
|
317
|
+
SQLite.deleteDatabaseSync(eventlogDatabaseName, directory)
|
|
318
|
+
},
|
|
319
|
+
catch: (cause) =>
|
|
320
|
+
new UnexpectedError({
|
|
321
|
+
cause,
|
|
322
|
+
note: `@livestore/adapter-expo: Failed to reset persistence for store ${storeId}`,
|
|
323
|
+
}),
|
|
324
|
+
}).pipe(
|
|
325
|
+
Effect.retry({ schedule: Schedule.exponentialBackoff10Sec }),
|
|
326
|
+
Effect.withSpan('@livestore/adapter-expo:resetPersistence', { attributes: { storeId } }),
|
|
327
|
+
)
|
|
328
|
+
|
|
248
329
|
const makeDevtoolsOptions = ({
|
|
249
330
|
devtoolsEnabled,
|
|
250
331
|
devtoolsUrl,
|