@livestore/adapter-web 0.4.0-dev.17 → 0.4.0-dev.19
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 +2 -2
- package/dist/in-memory/in-memory-adapter.d.ts.map +1 -1
- package/dist/in-memory/in-memory-adapter.js +6 -5
- 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 +3 -2
- 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 +27 -23
- package/dist/web-worker/client-session/persisted-adapter.js.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.d.ts +11 -29
- package/dist/web-worker/common/persisted-sqlite.d.ts.map +1 -1
- package/dist/web-worker/common/persisted-sqlite.js +70 -184
- 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 +69 -46
- package/dist/web-worker/common/worker-schema.d.ts.map +1 -1
- package/dist/web-worker/common/worker-schema.js +20 -20
- package/dist/web-worker/common/worker-schema.js.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.d.ts.map +1 -1
- package/dist/web-worker/leader-worker/make-leader-worker.js +19 -16
- package/dist/web-worker/leader-worker/make-leader-worker.js.map +1 -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 +10 -9
- package/dist/web-worker/shared-worker/make-shared-worker.js.map +1 -1
- package/package.json +7 -8
- package/src/in-memory/in-memory-adapter.ts +8 -16
- package/src/web-worker/ambient.d.ts +0 -20
- package/src/web-worker/client-session/client-session-devtools.ts +3 -2
- package/src/web-worker/client-session/persisted-adapter.ts +35 -27
- package/src/web-worker/common/persisted-sqlite.ts +186 -299
- 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 +21 -21
- package/src/web-worker/leader-worker/make-leader-worker.ts +22 -23
- package/src/web-worker/shared-worker/make-shared-worker.ts +14 -15
- package/dist/opfs-utils.d.ts +0 -7
- package/dist/opfs-utils.d.ts.map +0 -1
- package/dist/opfs-utils.js +0 -43
- package/dist/opfs-utils.js.map +0 -1
- package/src/opfs-utils.ts +0 -61
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
MigrationsReport,
|
|
7
7
|
SyncBackend,
|
|
8
8
|
SyncState,
|
|
9
|
-
|
|
9
|
+
UnknownError,
|
|
10
10
|
} from '@livestore/common'
|
|
11
11
|
import { EventSequenceNumber, LiveStoreEvent } from '@livestore/common/schema'
|
|
12
12
|
import * as WebmeshWorker from '@livestore/devtools-web-common/worker'
|
|
@@ -49,7 +49,7 @@ export class LeaderWorkerOuterInitialMessage extends Schema.TaggedRequest<Leader
|
|
|
49
49
|
{
|
|
50
50
|
payload: { port: Transferable.MessagePort, storeId: Schema.String, clientId: Schema.String },
|
|
51
51
|
success: Schema.Void,
|
|
52
|
-
failure:
|
|
52
|
+
failure: UnknownError,
|
|
53
53
|
},
|
|
54
54
|
) {}
|
|
55
55
|
|
|
@@ -68,7 +68,7 @@ export class LeaderWorkerInnerInitialMessage extends Schema.TaggedRequest<Leader
|
|
|
68
68
|
syncPayloadEncoded: Schema.UndefinedOr(Schema.JsonValue),
|
|
69
69
|
},
|
|
70
70
|
success: Schema.Void,
|
|
71
|
-
failure:
|
|
71
|
+
failure: UnknownError,
|
|
72
72
|
},
|
|
73
73
|
) {}
|
|
74
74
|
|
|
@@ -77,7 +77,7 @@ export class LeaderWorkerInnerBootStatusStream extends Schema.TaggedRequest<Lead
|
|
|
77
77
|
{
|
|
78
78
|
payload: {},
|
|
79
79
|
success: BootStatus,
|
|
80
|
-
failure:
|
|
80
|
+
failure: UnknownError,
|
|
81
81
|
},
|
|
82
82
|
) {}
|
|
83
83
|
|
|
@@ -85,27 +85,27 @@ export class LeaderWorkerInnerPushToLeader extends Schema.TaggedRequest<LeaderWo
|
|
|
85
85
|
'PushToLeader',
|
|
86
86
|
{
|
|
87
87
|
payload: {
|
|
88
|
-
batch: Schema.Array(LiveStoreEvent.
|
|
88
|
+
batch: Schema.Array(Schema.typeSchema(LiveStoreEvent.Client.Encoded)),
|
|
89
89
|
},
|
|
90
|
-
success: Schema.Void
|
|
91
|
-
failure: Schema.Union(
|
|
90
|
+
success: Schema.Void as Schema.Schema<void>,
|
|
91
|
+
failure: Schema.Union(UnknownError, LeaderAheadError),
|
|
92
92
|
},
|
|
93
93
|
) {}
|
|
94
94
|
|
|
95
95
|
export class LeaderWorkerInnerPullStream extends Schema.TaggedRequest<LeaderWorkerInnerPullStream>()('PullStream', {
|
|
96
96
|
payload: {
|
|
97
|
-
cursor: EventSequenceNumber.
|
|
97
|
+
cursor: Schema.typeSchema(EventSequenceNumber.Client.Composite),
|
|
98
98
|
},
|
|
99
99
|
success: Schema.Struct({
|
|
100
100
|
payload: SyncState.PayloadUpstream,
|
|
101
101
|
}),
|
|
102
|
-
failure:
|
|
102
|
+
failure: UnknownError,
|
|
103
103
|
}) {}
|
|
104
104
|
|
|
105
105
|
export class LeaderWorkerInnerExport extends Schema.TaggedRequest<LeaderWorkerInnerExport>()('Export', {
|
|
106
106
|
payload: {},
|
|
107
107
|
success: Transferable.Uint8Array as Schema.Schema<Uint8Array<ArrayBuffer>>,
|
|
108
|
-
failure:
|
|
108
|
+
failure: UnknownError,
|
|
109
109
|
}) {}
|
|
110
110
|
|
|
111
111
|
export class LeaderWorkerInnerExportEventlog extends Schema.TaggedRequest<LeaderWorkerInnerExportEventlog>()(
|
|
@@ -113,7 +113,7 @@ export class LeaderWorkerInnerExportEventlog extends Schema.TaggedRequest<Leader
|
|
|
113
113
|
{
|
|
114
114
|
payload: {},
|
|
115
115
|
success: Transferable.Uint8Array as Schema.Schema<Uint8Array<ArrayBuffer>>,
|
|
116
|
-
failure:
|
|
116
|
+
failure: UnknownError,
|
|
117
117
|
},
|
|
118
118
|
) {}
|
|
119
119
|
|
|
@@ -125,7 +125,7 @@ export class LeaderWorkerInnerGetRecreateSnapshot extends Schema.TaggedRequest<L
|
|
|
125
125
|
snapshot: Transferable.Uint8Array as Schema.Schema<Uint8Array<ArrayBuffer>>,
|
|
126
126
|
migrationsReport: MigrationsReport,
|
|
127
127
|
}),
|
|
128
|
-
failure:
|
|
128
|
+
failure: UnknownError,
|
|
129
129
|
},
|
|
130
130
|
) {}
|
|
131
131
|
|
|
@@ -133,8 +133,8 @@ export class LeaderWorkerInnerGetLeaderHead extends Schema.TaggedRequest<LeaderW
|
|
|
133
133
|
'GetLeaderHead',
|
|
134
134
|
{
|
|
135
135
|
payload: {},
|
|
136
|
-
success: EventSequenceNumber.
|
|
137
|
-
failure:
|
|
136
|
+
success: Schema.typeSchema(EventSequenceNumber.Client.Composite),
|
|
137
|
+
failure: UnknownError,
|
|
138
138
|
},
|
|
139
139
|
) {}
|
|
140
140
|
|
|
@@ -143,7 +143,7 @@ export class LeaderWorkerInnerGetLeaderSyncState extends Schema.TaggedRequest<Le
|
|
|
143
143
|
{
|
|
144
144
|
payload: {},
|
|
145
145
|
success: SyncState.SyncState,
|
|
146
|
-
failure:
|
|
146
|
+
failure: UnknownError,
|
|
147
147
|
},
|
|
148
148
|
) {}
|
|
149
149
|
|
|
@@ -152,7 +152,7 @@ export class LeaderWorkerInnerSyncStateStream extends Schema.TaggedRequest<Leade
|
|
|
152
152
|
{
|
|
153
153
|
payload: {},
|
|
154
154
|
success: SyncState.SyncState,
|
|
155
|
-
failure:
|
|
155
|
+
failure: UnknownError,
|
|
156
156
|
},
|
|
157
157
|
) {}
|
|
158
158
|
|
|
@@ -161,7 +161,7 @@ export class LeaderWorkerInnerGetNetworkStatus extends Schema.TaggedRequest<Lead
|
|
|
161
161
|
{
|
|
162
162
|
payload: {},
|
|
163
163
|
success: SyncBackend.NetworkStatus,
|
|
164
|
-
failure:
|
|
164
|
+
failure: UnknownError,
|
|
165
165
|
},
|
|
166
166
|
) {}
|
|
167
167
|
|
|
@@ -170,14 +170,14 @@ export class LeaderWorkerInnerNetworkStatusStream extends Schema.TaggedRequest<L
|
|
|
170
170
|
{
|
|
171
171
|
payload: {},
|
|
172
172
|
success: SyncBackend.NetworkStatus,
|
|
173
|
-
failure:
|
|
173
|
+
failure: UnknownError,
|
|
174
174
|
},
|
|
175
175
|
) {}
|
|
176
176
|
|
|
177
177
|
export class LeaderWorkerInnerShutdown extends Schema.TaggedRequest<LeaderWorkerInnerShutdown>()('Shutdown', {
|
|
178
178
|
payload: {},
|
|
179
179
|
success: Schema.Void,
|
|
180
|
-
failure:
|
|
180
|
+
failure: UnknownError,
|
|
181
181
|
}) {}
|
|
182
182
|
|
|
183
183
|
export class LeaderWorkerInnerExtraDevtoolsMessage extends Schema.TaggedRequest<LeaderWorkerInnerExtraDevtoolsMessage>()(
|
|
@@ -187,7 +187,7 @@ export class LeaderWorkerInnerExtraDevtoolsMessage extends Schema.TaggedRequest<
|
|
|
187
187
|
message: Devtools.Leader.MessageToApp,
|
|
188
188
|
},
|
|
189
189
|
success: Schema.Void,
|
|
190
|
-
failure:
|
|
190
|
+
failure: UnknownError,
|
|
191
191
|
},
|
|
192
192
|
) {}
|
|
193
193
|
|
|
@@ -226,7 +226,7 @@ export class SharedWorkerUpdateMessagePort extends Schema.TaggedRequest<SharedWo
|
|
|
226
226
|
initial: LeaderWorkerInnerInitialMessage,
|
|
227
227
|
},
|
|
228
228
|
success: Schema.Void,
|
|
229
|
-
failure:
|
|
229
|
+
failure: UnknownError,
|
|
230
230
|
},
|
|
231
231
|
) {}
|
|
232
232
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SqliteDb, SyncOptions } from '@livestore/common'
|
|
2
|
-
import { Devtools, LogConfig,
|
|
2
|
+
import { Devtools, LogConfig, UnknownError } from '@livestore/common'
|
|
3
3
|
import type { DevtoolsOptions } from '@livestore/common/leader-thread'
|
|
4
4
|
import { configureConnection, Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread'
|
|
5
5
|
import type { LiveStoreSchema } from '@livestore/common/schema'
|
|
@@ -10,7 +10,6 @@ import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm'
|
|
|
10
10
|
import { isDevEnv, LS_DEV } from '@livestore/utils'
|
|
11
11
|
import type { HttpClient, Scope, WorkerError } from '@livestore/utils/effect'
|
|
12
12
|
import {
|
|
13
|
-
BrowserWorkerRunner,
|
|
14
13
|
Effect,
|
|
15
14
|
FetchHttpClient,
|
|
16
15
|
identity,
|
|
@@ -22,9 +21,9 @@ import {
|
|
|
22
21
|
TaskTracing,
|
|
23
22
|
WorkerRunner,
|
|
24
23
|
} from '@livestore/utils/effect'
|
|
24
|
+
import { BrowserWorkerRunner, Opfs } from '@livestore/utils/effect/browser'
|
|
25
25
|
import type * as otel from '@opentelemetry/api'
|
|
26
26
|
|
|
27
|
-
import * as OpfsUtils from '../../opfs-utils.ts'
|
|
28
27
|
import { cleanupOldStateDbFiles, getStateDbFileName, sanitizeOpfsDir } from '../common/persisted-sqlite.ts'
|
|
29
28
|
import { makeShutdownChannel } from '../common/shutdown-channel.ts'
|
|
30
29
|
import * as WorkerSchema from '../common/worker-schema.ts'
|
|
@@ -40,7 +39,7 @@ export type WorkerOptions = {
|
|
|
40
39
|
|
|
41
40
|
if (isDevEnv()) {
|
|
42
41
|
globalThis.__debugLiveStoreUtils = {
|
|
43
|
-
opfs:
|
|
42
|
+
opfs: Opfs.debugUtils,
|
|
44
43
|
blobUrl: (buffer: Uint8Array<ArrayBuffer>) =>
|
|
45
44
|
URL.createObjectURL(new Blob([buffer], { type: 'application/octet-stream' })),
|
|
46
45
|
runSync: (effect: Effect.Effect<any, any, never>) => Effect.runSync(effect),
|
|
@@ -93,7 +92,12 @@ const makeWorkerRunnerOuter = (
|
|
|
93
92
|
Effect.withSpan('@livestore/adapter-web:worker:wrapper:InitialMessage:innerFiber'),
|
|
94
93
|
Effect.tapCauseLogPretty,
|
|
95
94
|
Effect.provide(
|
|
96
|
-
|
|
95
|
+
Layer.mergeAll(
|
|
96
|
+
Opfs.Opfs.Default,
|
|
97
|
+
WebmeshWorker.CacheService.layer({
|
|
98
|
+
nodeName: Devtools.makeNodeName.client.leader({ storeId, clientId }),
|
|
99
|
+
}),
|
|
100
|
+
),
|
|
97
101
|
),
|
|
98
102
|
Effect.forkScoped,
|
|
99
103
|
)
|
|
@@ -108,12 +112,13 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
108
112
|
Effect.gen(function* () {
|
|
109
113
|
const sqlite3 = yield* Effect.promise(() => loadSqlite3Wasm())
|
|
110
114
|
const makeSqliteDb = sqliteDbFactory({ sqlite3 })
|
|
115
|
+
const opfsDirectory = yield* sanitizeOpfsDir(storageOptions.directory, storeId)
|
|
111
116
|
const runtime = yield* Effect.runtime<never>()
|
|
112
117
|
|
|
113
118
|
const makeDb = (kind: 'state' | 'eventlog') =>
|
|
114
119
|
makeSqliteDb({
|
|
115
120
|
_tag: 'opfs',
|
|
116
|
-
opfsDirectory
|
|
121
|
+
opfsDirectory,
|
|
117
122
|
fileName: kind === 'state' ? getStateDbFileName(schema) : 'eventlog.db',
|
|
118
123
|
configureDb: (db) =>
|
|
119
124
|
configureConnection(db, {
|
|
@@ -159,7 +164,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
159
164
|
})
|
|
160
165
|
}).pipe(
|
|
161
166
|
Effect.tapCauseLogPretty,
|
|
162
|
-
|
|
167
|
+
UnknownError.mapToUnknownError,
|
|
163
168
|
Effect.withPerformanceMeasure('@livestore/adapter-web:worker:InitialMessage'),
|
|
164
169
|
Effect.withSpan('@livestore/adapter-web:worker:InitialMessage'),
|
|
165
170
|
Effect.annotateSpans({ debugInstanceId }),
|
|
@@ -177,10 +182,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
177
182
|
|
|
178
183
|
const snapshot = workerCtx.dbState.export()
|
|
179
184
|
return { snapshot, migrationsReport: workerCtx.initialState.migrationsReport }
|
|
180
|
-
}).pipe(
|
|
181
|
-
UnexpectedError.mapToUnexpectedError,
|
|
182
|
-
Effect.withSpan('@livestore/adapter-web:worker:GetRecreateSnapshot'),
|
|
183
|
-
),
|
|
185
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.withSpan('@livestore/adapter-web:worker:GetRecreateSnapshot')),
|
|
184
186
|
PullStream: ({ cursor }) =>
|
|
185
187
|
Effect.gen(function* () {
|
|
186
188
|
const { syncProcessor } = yield* LeaderThreadCtx
|
|
@@ -193,19 +195,19 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
193
195
|
PushToLeader: ({ batch }) =>
|
|
194
196
|
Effect.andThen(LeaderThreadCtx, ({ syncProcessor }) =>
|
|
195
197
|
syncProcessor.push(
|
|
196
|
-
batch.map((event) => new LiveStoreEvent.EncodedWithMeta(event)),
|
|
198
|
+
batch.map((event) => new LiveStoreEvent.Client.EncodedWithMeta(event)),
|
|
197
199
|
// We'll wait in order to keep back pressure on the client session
|
|
198
200
|
{ waitForProcessing: true },
|
|
199
201
|
),
|
|
200
202
|
).pipe(Effect.uninterruptible, Effect.withSpan('@livestore/adapter-web:worker:PushToLeader')),
|
|
201
203
|
Export: () =>
|
|
202
204
|
Effect.andThen(LeaderThreadCtx, (_) => _.dbState.export()).pipe(
|
|
203
|
-
|
|
205
|
+
UnknownError.mapToUnknownError,
|
|
204
206
|
Effect.withSpan('@livestore/adapter-web:worker:Export'),
|
|
205
207
|
),
|
|
206
208
|
ExportEventlog: () =>
|
|
207
209
|
Effect.andThen(LeaderThreadCtx, (_) => _.dbEventlog.export()).pipe(
|
|
208
|
-
|
|
210
|
+
UnknownError.mapToUnknownError,
|
|
209
211
|
Effect.withSpan('@livestore/adapter-web:worker:ExportEventlog'),
|
|
210
212
|
),
|
|
211
213
|
BootStatusStream: () =>
|
|
@@ -214,15 +216,12 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
214
216
|
Effect.gen(function* () {
|
|
215
217
|
const workerCtx = yield* LeaderThreadCtx
|
|
216
218
|
return Eventlog.getClientHeadFromDb(workerCtx.dbEventlog)
|
|
217
|
-
}).pipe(
|
|
219
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.withSpan('@livestore/adapter-web:worker:GetLeaderHead')),
|
|
218
220
|
GetLeaderSyncState: () =>
|
|
219
221
|
Effect.gen(function* () {
|
|
220
222
|
const workerCtx = yield* LeaderThreadCtx
|
|
221
223
|
return yield* workerCtx.syncProcessor.syncState
|
|
222
|
-
}).pipe(
|
|
223
|
-
UnexpectedError.mapToUnexpectedError,
|
|
224
|
-
Effect.withSpan('@livestore/adapter-web:worker:GetLeaderSyncState'),
|
|
225
|
-
),
|
|
224
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.withSpan('@livestore/adapter-web:worker:GetLeaderSyncState')),
|
|
226
225
|
SyncStateStream: () =>
|
|
227
226
|
Effect.gen(function* () {
|
|
228
227
|
const workerCtx = yield* LeaderThreadCtx
|
|
@@ -232,7 +231,7 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
232
231
|
Effect.gen(function* () {
|
|
233
232
|
const workerCtx = yield* LeaderThreadCtx
|
|
234
233
|
return yield* workerCtx.networkStatus
|
|
235
|
-
}).pipe(
|
|
234
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.withSpan('@livestore/adapter-web:worker:GetNetworkStatus')),
|
|
236
235
|
NetworkStatusStream: () =>
|
|
237
236
|
Effect.gen(function* () {
|
|
238
237
|
const workerCtx = yield* LeaderThreadCtx
|
|
@@ -245,10 +244,10 @@ const makeWorkerRunnerInner = ({ schema, sync: syncOptions, syncPayloadSchema }:
|
|
|
245
244
|
// Buy some time for Otel to flush
|
|
246
245
|
// TODO find a cleaner way to do this
|
|
247
246
|
yield* Effect.sleep(300)
|
|
248
|
-
}).pipe(
|
|
247
|
+
}).pipe(UnknownError.mapToUnknownError, Effect.withSpan('@livestore/adapter-web:worker:Shutdown')),
|
|
249
248
|
ExtraDevtoolsMessage: ({ message }) =>
|
|
250
249
|
Effect.andThen(LeaderThreadCtx, (_) => _.extraIncomingMessagesQueue.offer(message)).pipe(
|
|
251
|
-
|
|
250
|
+
UnknownError.mapToUnknownError,
|
|
252
251
|
Effect.withSpan('@livestore/adapter-web:worker:ExtraDevtoolsMessage'),
|
|
253
252
|
),
|
|
254
253
|
'DevtoolsWebCommon.CreateConnection': WebmeshWorker.CreateConnection,
|
|
@@ -262,7 +261,7 @@ const makeDevtoolsOptions = ({
|
|
|
262
261
|
devtoolsEnabled: boolean
|
|
263
262
|
dbState: SqliteDb
|
|
264
263
|
dbEventlog: SqliteDb
|
|
265
|
-
}): Effect.Effect<DevtoolsOptions,
|
|
264
|
+
}): Effect.Effect<DevtoolsOptions, UnknownError, Scope.Scope | WebmeshWorker.CacheService> =>
|
|
266
265
|
Effect.gen(function* () {
|
|
267
266
|
if (devtoolsEnabled === false) {
|
|
268
267
|
return { enabled: false }
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Devtools, LogConfig, liveStoreVersion,
|
|
1
|
+
import { Devtools, LogConfig, liveStoreVersion, UnknownError } from '@livestore/common'
|
|
2
2
|
import * as DevtoolsWeb from '@livestore/devtools-web-common/web-channel'
|
|
3
3
|
import * as WebmeshWorker from '@livestore/devtools-web-common/worker'
|
|
4
4
|
import { isDevEnv, isNotUndefined, LS_DEV } from '@livestore/utils'
|
|
5
5
|
import {
|
|
6
|
-
BrowserWorker,
|
|
7
|
-
BrowserWorkerRunner,
|
|
8
6
|
Deferred,
|
|
9
7
|
Effect,
|
|
10
8
|
Exit,
|
|
@@ -22,6 +20,7 @@ import {
|
|
|
22
20
|
WorkerError,
|
|
23
21
|
WorkerRunner,
|
|
24
22
|
} from '@livestore/utils/effect'
|
|
23
|
+
import { BrowserWorker, BrowserWorkerRunner } from '@livestore/utils/effect/browser'
|
|
25
24
|
|
|
26
25
|
import { makeShutdownChannel } from '../common/shutdown-channel.ts'
|
|
27
26
|
import * as WorkerSchema from '../common/worker-schema.ts'
|
|
@@ -66,10 +65,10 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
66
65
|
req: TReq,
|
|
67
66
|
): Effect.Effect<
|
|
68
67
|
Schema.WithResult.Success<TReq>,
|
|
69
|
-
|
|
68
|
+
UnknownError | Schema.WithResult.Failure<TReq>,
|
|
70
69
|
Schema.WithResult.Context<TReq>
|
|
71
70
|
> =>
|
|
72
|
-
// Forward the request to the active worker and normalize platform errors into
|
|
71
|
+
// Forward the request to the active worker and normalize platform errors into UnknownError.
|
|
73
72
|
waitForWorker.pipe(
|
|
74
73
|
// Effect.logBefore(`forwardRequest: ${req._tag}`),
|
|
75
74
|
Effect.andThen((worker) => worker.executeEffect(req) as Effect.Effect<unknown, unknown, unknown>),
|
|
@@ -81,17 +80,17 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
81
80
|
duration: 500,
|
|
82
81
|
}),
|
|
83
82
|
Effect.mapError((cause) =>
|
|
84
|
-
Schema.is(
|
|
83
|
+
Schema.is(UnknownError)(cause)
|
|
85
84
|
? cause
|
|
86
85
|
: ParseResult.isParseError(cause) || Schema.is(WorkerError.WorkerError)(cause)
|
|
87
|
-
? new
|
|
86
|
+
? new UnknownError({ cause })
|
|
88
87
|
: cause,
|
|
89
88
|
),
|
|
90
|
-
Effect.catchAllDefect((cause) => new
|
|
89
|
+
Effect.catchAllDefect((cause) => new UnknownError({ cause })),
|
|
91
90
|
Effect.tapCauseLogPretty,
|
|
92
91
|
) as Effect.Effect<
|
|
93
92
|
Schema.WithResult.Success<TReq>,
|
|
94
|
-
|
|
93
|
+
UnknownError | Schema.WithResult.Failure<TReq>,
|
|
95
94
|
Schema.WithResult.Context<TReq>
|
|
96
95
|
>
|
|
97
96
|
|
|
@@ -99,7 +98,7 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
99
98
|
req: TReq,
|
|
100
99
|
): Stream.Stream<
|
|
101
100
|
Schema.WithResult.Success<TReq>,
|
|
102
|
-
|
|
101
|
+
UnknownError | Schema.WithResult.Failure<TReq>,
|
|
103
102
|
Schema.WithResult.Context<TReq>
|
|
104
103
|
> =>
|
|
105
104
|
Effect.gen(function* () {
|
|
@@ -121,14 +120,14 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
121
120
|
return Stream.merge(stream, scopeShutdownStream, { haltStrategy: 'either' })
|
|
122
121
|
}).pipe(
|
|
123
122
|
Effect.interruptible,
|
|
124
|
-
|
|
123
|
+
UnknownError.mapToUnknownError,
|
|
125
124
|
Effect.tapCauseLogPretty,
|
|
126
125
|
Stream.unwrap,
|
|
127
126
|
Stream.ensuring(Effect.logDebug(`shutting down stream for ${req._tag}`)),
|
|
128
|
-
|
|
127
|
+
UnknownError.mapToUnknownErrorStream,
|
|
129
128
|
) as Stream.Stream<
|
|
130
129
|
Schema.WithResult.Success<TReq>,
|
|
131
|
-
|
|
130
|
+
UnknownError | Schema.WithResult.Failure<TReq>,
|
|
132
131
|
Schema.WithResult.Context<TReq>
|
|
133
132
|
>
|
|
134
133
|
|
|
@@ -186,7 +185,7 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
186
185
|
// Early return on mismatch to keep happy path linear
|
|
187
186
|
if (prev !== undefined && !sameInvariants(prev, invariants)) {
|
|
188
187
|
const diff = Schema.debugDiff(InvariantsSchema)(prev, invariants)
|
|
189
|
-
return yield* new
|
|
188
|
+
return yield* new UnknownError({
|
|
190
189
|
cause: 'Store invariants changed across leader transitions',
|
|
191
190
|
payload: { diff, previous: prev, next: invariants },
|
|
192
191
|
})
|
|
@@ -236,7 +235,7 @@ const makeWorkerRunner = Effect.gen(function* () {
|
|
|
236
235
|
}).pipe(Effect.tapCauseLogPretty, Scope.extend(scope), Effect.forkIn(scope))
|
|
237
236
|
}).pipe(
|
|
238
237
|
Effect.withSpan('@livestore/adapter-web:shared-worker:updateMessagePort'),
|
|
239
|
-
|
|
238
|
+
UnknownError.mapToUnknownError,
|
|
240
239
|
Effect.tapCauseLogPretty,
|
|
241
240
|
),
|
|
242
241
|
|
package/dist/opfs-utils.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const rootHandlePromise: Promise<FileSystemDirectoryHandle>;
|
|
2
|
-
export declare const getDirHandle: (absDirPath: string | undefined, options?: {
|
|
3
|
-
create?: boolean;
|
|
4
|
-
}) => Promise<FileSystemDirectoryHandle>;
|
|
5
|
-
export declare const printTree: (directoryHandle_?: FileSystemDirectoryHandle | Promise<FileSystemDirectoryHandle>, depth?: number, prefix?: string) => Promise<void>;
|
|
6
|
-
export declare const deleteAll: (directoryHandle: FileSystemDirectoryHandle) => Promise<void>;
|
|
7
|
-
//# sourceMappingURL=opfs-utils.d.ts.map
|
package/dist/opfs-utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"opfs-utils.d.ts","sourceRoot":"","sources":["../src/opfs-utils.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,oCAYQ,CAAA;AAEtC,eAAO,MAAM,YAAY,GAAU,YAAY,MAAM,GAAG,SAAS,EAAE,UAAS;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,uCAWpG,CAAA;AAED,eAAO,MAAM,SAAS,GACpB,mBAAkB,yBAAyB,GAAG,OAAO,CAAC,yBAAyB,CAAqB,EACpG,QAAO,MAAiC,EACxC,eAAW,KACV,OAAO,CAAC,IAAI,CAgBd,CAAA;AAED,eAAO,MAAM,SAAS,GAAU,iBAAiB,yBAAyB,kBAMzE,CAAA"}
|
package/dist/opfs-utils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// NOTE we're already firing off this promise call here since we'll need it anyway and need it cached
|
|
2
|
-
import { prettyBytes } from '@livestore/utils';
|
|
3
|
-
// To improve LiveStore compatibility with e.g. Node.js we're guarding for `navigator` / `navigator.storage` to be defined.
|
|
4
|
-
export const rootHandlePromise = typeof navigator === 'undefined' || navigator.storage === undefined
|
|
5
|
-
? // We're using a proxy here to make the promise reject lazy
|
|
6
|
-
new Proxy({}, {
|
|
7
|
-
get: () => Promise.reject(new Error(`Can't get OPFS root handle in this environment as navigator.storage is undefined`)),
|
|
8
|
-
})
|
|
9
|
-
: navigator.storage.getDirectory();
|
|
10
|
-
export const getDirHandle = async (absDirPath, options = {}) => {
|
|
11
|
-
const rootHandle = await rootHandlePromise;
|
|
12
|
-
if (absDirPath === undefined || absDirPath === '' || absDirPath === '/')
|
|
13
|
-
return rootHandle;
|
|
14
|
-
let dirHandle = rootHandle;
|
|
15
|
-
const directoryStack = absDirPath.split('/').filter(Boolean);
|
|
16
|
-
while (directoryStack.length > 0) {
|
|
17
|
-
dirHandle = await dirHandle.getDirectoryHandle(directoryStack.shift(), options);
|
|
18
|
-
}
|
|
19
|
-
return dirHandle;
|
|
20
|
-
};
|
|
21
|
-
export const printTree = async (directoryHandle_ = rootHandlePromise, depth = Number.POSITIVE_INFINITY, prefix = '') => {
|
|
22
|
-
if (depth < 0)
|
|
23
|
-
return;
|
|
24
|
-
const directoryHandle = await directoryHandle_;
|
|
25
|
-
const entries = directoryHandle.values();
|
|
26
|
-
for await (const entry of entries) {
|
|
27
|
-
const isDirectory = entry.kind === 'directory';
|
|
28
|
-
const size = entry.kind === 'file' ? await entry.getFile().then((file) => prettyBytes(file.size)) : undefined;
|
|
29
|
-
console.log(`${prefix}${isDirectory ? '📁' : '📄'} ${entry.name} ${size ? `(${size})` : ''}`);
|
|
30
|
-
if (isDirectory) {
|
|
31
|
-
const nestedDirectoryHandle = await directoryHandle.getDirectoryHandle(entry.name);
|
|
32
|
-
await printTree(nestedDirectoryHandle, depth - 1, `${prefix} `);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export const deleteAll = async (directoryHandle) => {
|
|
37
|
-
if (directoryHandle.kind !== 'directory')
|
|
38
|
-
return;
|
|
39
|
-
for await (const entryName of directoryHandle.keys()) {
|
|
40
|
-
await directoryHandle.removeEntry(entryName, { recursive: true });
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=opfs-utils.js.map
|
package/dist/opfs-utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"opfs-utils.js","sourceRoot":"","sources":["../src/opfs-utils.ts"],"names":[],"mappings":"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"}
|
package/src/opfs-utils.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// NOTE we're already firing off this promise call here since we'll need it anyway and need it cached
|
|
2
|
-
|
|
3
|
-
import { prettyBytes } from '@livestore/utils'
|
|
4
|
-
|
|
5
|
-
// To improve LiveStore compatibility with e.g. Node.js we're guarding for `navigator` / `navigator.storage` to be defined.
|
|
6
|
-
export const rootHandlePromise =
|
|
7
|
-
typeof navigator === 'undefined' || navigator.storage === undefined
|
|
8
|
-
? // We're using a proxy here to make the promise reject lazy
|
|
9
|
-
(new Proxy(
|
|
10
|
-
{},
|
|
11
|
-
{
|
|
12
|
-
get: () =>
|
|
13
|
-
Promise.reject(
|
|
14
|
-
new Error(`Can't get OPFS root handle in this environment as navigator.storage is undefined`),
|
|
15
|
-
),
|
|
16
|
-
},
|
|
17
|
-
) as never)
|
|
18
|
-
: navigator.storage.getDirectory()
|
|
19
|
-
|
|
20
|
-
export const getDirHandle = async (absDirPath: string | undefined, options: { create?: boolean } = {}) => {
|
|
21
|
-
const rootHandle = await rootHandlePromise
|
|
22
|
-
if (absDirPath === undefined || absDirPath === '' || absDirPath === '/') return rootHandle
|
|
23
|
-
|
|
24
|
-
let dirHandle = rootHandle
|
|
25
|
-
const directoryStack = absDirPath.split('/').filter(Boolean)
|
|
26
|
-
while (directoryStack.length > 0) {
|
|
27
|
-
dirHandle = await dirHandle.getDirectoryHandle(directoryStack.shift()!, options)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return dirHandle
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const printTree = async (
|
|
34
|
-
directoryHandle_: FileSystemDirectoryHandle | Promise<FileSystemDirectoryHandle> = rootHandlePromise,
|
|
35
|
-
depth: number = Number.POSITIVE_INFINITY,
|
|
36
|
-
prefix = '',
|
|
37
|
-
): Promise<void> => {
|
|
38
|
-
if (depth < 0) return
|
|
39
|
-
|
|
40
|
-
const directoryHandle = await directoryHandle_
|
|
41
|
-
const entries = directoryHandle.values()
|
|
42
|
-
|
|
43
|
-
for await (const entry of entries) {
|
|
44
|
-
const isDirectory = entry.kind === 'directory'
|
|
45
|
-
const size = entry.kind === 'file' ? await entry.getFile().then((file) => prettyBytes(file.size)) : undefined
|
|
46
|
-
console.log(`${prefix}${isDirectory ? '📁' : '📄'} ${entry.name} ${size ? `(${size})` : ''}`)
|
|
47
|
-
|
|
48
|
-
if (isDirectory) {
|
|
49
|
-
const nestedDirectoryHandle = await directoryHandle.getDirectoryHandle(entry.name)
|
|
50
|
-
await printTree(nestedDirectoryHandle, depth - 1, `${prefix} `)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const deleteAll = async (directoryHandle: FileSystemDirectoryHandle) => {
|
|
56
|
-
if (directoryHandle.kind !== 'directory') return
|
|
57
|
-
|
|
58
|
-
for await (const entryName of directoryHandle.keys()) {
|
|
59
|
-
await directoryHandle.removeEntry(entryName, { recursive: true })
|
|
60
|
-
}
|
|
61
|
-
}
|