@livestore/common 0.2.0 → 0.3.0-dev.1
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/__tests__/fixture.d.ts +163 -1
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +3 -1
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/adapter-types.d.ts +53 -38
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +5 -7
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts +2 -2
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/debug-info.d.ts +13 -13
- package/dist/derived-mutations.d.ts +1 -1
- package/dist/derived-mutations.d.ts.map +1 -1
- package/dist/devtools/devtools-bridge.d.ts +2 -2
- package/dist/devtools/devtools-bridge.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.d.ts +84 -196
- package/dist/devtools/devtools-messages.d.ts.map +1 -1
- package/dist/devtools/devtools-messages.js +55 -61
- package/dist/devtools/devtools-messages.js.map +1 -1
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/index.js +1 -2
- package/dist/devtools/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/init-singleton-tables.d.ts +1 -1
- package/dist/init-singleton-tables.d.ts.map +1 -1
- package/dist/leader-thread/apply-mutation.d.ts +8 -0
- package/dist/leader-thread/apply-mutation.d.ts.map +1 -0
- package/dist/leader-thread/apply-mutation.js +95 -0
- package/dist/leader-thread/apply-mutation.js.map +1 -0
- package/dist/leader-thread/connection.d.ts +11 -0
- package/dist/leader-thread/connection.d.ts.map +1 -0
- package/dist/leader-thread/connection.js +44 -0
- package/dist/leader-thread/connection.js.map +1 -0
- package/dist/leader-thread/leader-sync-processor.d.ts +47 -0
- package/dist/leader-thread/leader-sync-processor.d.ts.map +1 -0
- package/dist/leader-thread/leader-sync-processor.js +422 -0
- package/dist/leader-thread/leader-sync-processor.js.map +1 -0
- package/dist/leader-thread/leader-worker-devtools.d.ts +6 -0
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -0
- package/dist/leader-thread/leader-worker-devtools.js +216 -0
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -0
- package/dist/leader-thread/make-leader-thread-layer.d.ts +20 -0
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -0
- package/dist/leader-thread/make-leader-thread-layer.js +106 -0
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -0
- package/dist/leader-thread/mod.d.ts +7 -0
- package/dist/leader-thread/mod.d.ts.map +1 -0
- package/dist/leader-thread/mod.js +7 -0
- package/dist/leader-thread/mod.js.map +1 -0
- package/dist/leader-thread/mutationlog.d.ts +23 -0
- package/dist/leader-thread/mutationlog.d.ts.map +1 -0
- package/dist/leader-thread/mutationlog.js +27 -0
- package/dist/leader-thread/mutationlog.js.map +1 -0
- package/dist/leader-thread/pull-queue-set.d.ts +7 -0
- package/dist/leader-thread/pull-queue-set.d.ts.map +1 -0
- package/dist/leader-thread/pull-queue-set.js +39 -0
- package/dist/leader-thread/pull-queue-set.js.map +1 -0
- package/dist/leader-thread/recreate-db.d.ts +7 -0
- package/dist/leader-thread/recreate-db.d.ts.map +1 -0
- package/dist/leader-thread/recreate-db.js +69 -0
- package/dist/leader-thread/recreate-db.js.map +1 -0
- package/dist/leader-thread/shutdown-channel.d.ts +15 -0
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -0
- package/dist/leader-thread/shutdown-channel.js +7 -0
- package/dist/leader-thread/shutdown-channel.js.map +1 -0
- package/dist/leader-thread/types.d.ts +87 -0
- package/dist/leader-thread/types.d.ts.map +1 -0
- package/dist/leader-thread/types.js +11 -0
- package/dist/leader-thread/types.js.map +1 -0
- package/dist/mutation.d.ts +3 -4
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutation.js +0 -14
- package/dist/mutation.js.map +1 -1
- package/dist/otel.d.ts +7 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +11 -0
- package/dist/otel.js.map +1 -0
- package/dist/query-builder/api.d.ts +2 -2
- package/dist/query-builder/api.d.ts.map +1 -1
- package/dist/query-builder/api.js.map +1 -1
- package/dist/query-builder/impl.d.ts +1 -1
- package/dist/query-builder/impl.d.ts.map +1 -1
- package/dist/query-builder/impl.js +21 -4
- package/dist/query-builder/impl.js.map +1 -1
- package/dist/query-builder/impl.test.js +24 -1
- package/dist/query-builder/impl.test.js.map +1 -1
- package/dist/query-info.d.ts +1 -1
- package/dist/query-info.d.ts.map +1 -1
- package/dist/rehydrate-from-mutationlog.d.ts +1 -1
- package/dist/rehydrate-from-mutationlog.d.ts.map +1 -1
- package/dist/rehydrate-from-mutationlog.js +6 -6
- package/dist/rehydrate-from-mutationlog.js.map +1 -1
- package/dist/schema/EventId.d.ts +37 -0
- package/dist/schema/EventId.d.ts.map +1 -0
- package/dist/schema/EventId.js +30 -0
- package/dist/schema/EventId.js.map +1 -0
- package/dist/schema/MutationEvent.d.ts +191 -0
- package/dist/schema/MutationEvent.d.ts.map +1 -0
- package/dist/schema/MutationEvent.js +56 -0
- package/dist/schema/MutationEvent.js.map +1 -0
- package/dist/schema/mod.d.ts +8 -0
- package/dist/schema/mod.d.ts.map +1 -0
- package/dist/schema/mod.js +8 -0
- package/dist/schema/mod.js.map +1 -0
- package/dist/schema/mutations.d.ts +3 -123
- package/dist/schema/mutations.d.ts.map +1 -1
- package/dist/schema/mutations.js +0 -26
- package/dist/schema/mutations.js.map +1 -1
- package/dist/schema/{index.d.ts → schema.d.ts} +1 -5
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/{index.js → schema.js} +1 -5
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/system-tables.d.ts +55 -29
- package/dist/schema/system-tables.d.ts.map +1 -1
- package/dist/schema/system-tables.js +10 -5
- package/dist/schema/system-tables.js.map +1 -1
- package/dist/schema-management/migrations.d.ts +1 -1
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +6 -1
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-mutation-defs.d.ts +1 -1
- package/dist/schema-management/validate-mutation-defs.d.ts.map +1 -1
- package/dist/sync/client-session-sync-processor.d.ts +45 -0
- package/dist/sync/client-session-sync-processor.d.ts.map +1 -0
- package/dist/sync/client-session-sync-processor.js +131 -0
- package/dist/sync/client-session-sync-processor.js.map +1 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/next/compact-events.d.ts +1 -1
- package/dist/sync/next/compact-events.d.ts.map +1 -1
- package/dist/sync/next/compact-events.js +2 -1
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts +5 -5
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +1 -1
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +30 -0
- package/dist/sync/next/history-dag-common.d.ts.map +1 -0
- package/dist/sync/next/history-dag-common.js +20 -0
- package/dist/sync/next/history-dag-common.js.map +1 -0
- package/dist/sync/next/history-dag.d.ts +4 -27
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +1 -19
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/mod.d.ts +1 -0
- package/dist/sync/next/mod.d.ts.map +1 -1
- package/dist/sync/next/mod.js +1 -0
- package/dist/sync/next/mod.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +3 -2
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.d.ts.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +2 -1
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/mutation-fixtures.d.ts +1 -1
- package/dist/sync/next/test/mutation-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/mutation-fixtures.js +4 -3
- package/dist/sync/next/test/mutation-fixtures.js.map +1 -1
- package/dist/sync/sync.d.ts +33 -12
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +10 -1
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/syncstate.d.ts +123 -0
- package/dist/sync/syncstate.d.ts.map +1 -0
- package/dist/sync/syncstate.js +248 -0
- package/dist/sync/syncstate.js.map +1 -0
- package/dist/sync/syncstate.test.d.ts +2 -0
- package/dist/sync/syncstate.test.d.ts.map +1 -0
- package/dist/sync/syncstate.test.js +399 -0
- package/dist/sync/syncstate.test.js.map +1 -0
- package/dist/sync/validate-push-payload.d.ts +5 -0
- package/dist/sync/validate-push-payload.d.ts.map +1 -0
- package/dist/sync/validate-push-payload.js +15 -0
- package/dist/sync/validate-push-payload.js.map +1 -0
- package/dist/util.d.ts +2 -2
- package/dist/util.d.ts.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/package.json +13 -6
- package/src/__tests__/fixture.ts +5 -1
- package/src/adapter-types.ts +60 -34
- package/src/derived-mutations.test.ts +1 -1
- package/src/derived-mutations.ts +1 -1
- package/src/devtools/devtools-bridge.ts +2 -2
- package/src/devtools/devtools-messages.ts +70 -74
- package/src/devtools/index.ts +1 -2
- package/src/index.ts +2 -1
- package/src/init-singleton-tables.ts +1 -1
- package/src/leader-thread/apply-mutation.ts +143 -0
- package/src/leader-thread/connection.ts +67 -0
- package/src/leader-thread/leader-sync-processor.ts +666 -0
- package/src/leader-thread/leader-worker-devtools.ts +358 -0
- package/src/leader-thread/make-leader-thread-layer.ts +192 -0
- package/src/leader-thread/mod.ts +6 -0
- package/src/leader-thread/mutationlog.ts +42 -0
- package/src/leader-thread/pull-queue-set.ts +58 -0
- package/src/leader-thread/recreate-db.ts +109 -0
- package/src/leader-thread/shutdown-channel.ts +13 -0
- package/src/leader-thread/types.ts +129 -0
- package/src/mutation.ts +3 -21
- package/src/otel.ts +20 -0
- package/src/query-builder/api.ts +3 -2
- package/src/query-builder/impl.test.ts +28 -1
- package/src/query-builder/impl.ts +21 -5
- package/src/query-info.ts +1 -1
- package/src/rehydrate-from-mutationlog.ts +7 -11
- package/src/schema/EventId.ts +46 -0
- package/src/schema/MutationEvent.ts +161 -0
- package/src/schema/mod.ts +7 -0
- package/src/schema/mutations.ts +5 -126
- package/src/schema/{index.ts → schema.ts} +0 -5
- package/src/schema/system-tables.ts +18 -5
- package/src/schema-management/migrations.ts +9 -2
- package/src/schema-management/validate-mutation-defs.ts +1 -1
- package/src/sync/client-session-sync-processor.ts +207 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/next/compact-events.ts +3 -2
- package/src/sync/next/facts.ts +11 -5
- package/src/sync/next/history-dag-common.ts +44 -0
- package/src/sync/next/history-dag.ts +3 -45
- package/src/sync/next/mod.ts +1 -0
- package/src/sync/next/rebase-events.ts +6 -5
- package/src/sync/next/test/compact-events.test.ts +3 -2
- package/src/sync/next/test/mutation-fixtures.ts +7 -6
- package/src/sync/sync.ts +32 -12
- package/src/sync/syncstate.test.ts +464 -0
- package/src/sync/syncstate.ts +385 -0
- package/src/sync/validate-push-payload.ts +18 -0
- package/src/version.ts +2 -2
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js.map +0 -1
- package/dist/sync/next-mutation-event-id-pair.d.ts +0 -14
- package/dist/sync/next-mutation-event-id-pair.d.ts.map +0 -1
- package/dist/sync/next-mutation-event-id-pair.js +0 -13
- package/dist/sync/next-mutation-event-id-pair.js.map +0 -1
- package/src/sync/next-mutation-event-id-pair.ts +0 -20
@@ -0,0 +1,358 @@
|
|
1
|
+
import { Effect, FiberMap, Option, PubSub, Queue, Stream, SubscriptionRef } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
import { Devtools, IntentionalShutdownCause, liveStoreVersion, UnexpectedError } from '../index.js'
|
4
|
+
import { MUTATION_LOG_META_TABLE, SCHEMA_META_TABLE, SCHEMA_MUTATIONS_META_TABLE } from '../schema/mod.js'
|
5
|
+
import type { ShutdownChannel } from './shutdown-channel.js'
|
6
|
+
import type { DevtoolsOptions, PersistenceInfoPair } from './types.js'
|
7
|
+
import { LeaderThreadCtx } from './types.js'
|
8
|
+
|
9
|
+
type SendMessageToDevtools = (
|
10
|
+
message: Devtools.MessageFromAppLeader,
|
11
|
+
options?: {
|
12
|
+
/** Send message even if not connected (e.g. for initial broadcast messages) */
|
13
|
+
force: boolean
|
14
|
+
},
|
15
|
+
) => Effect.Effect<void>
|
16
|
+
|
17
|
+
// TODO bind scope to the webchannel lifetime
|
18
|
+
export const bootDevtools = (options: DevtoolsOptions) =>
|
19
|
+
Effect.gen(function* () {
|
20
|
+
if (options.enabled === false) {
|
21
|
+
return
|
22
|
+
}
|
23
|
+
|
24
|
+
const { persistenceInfo, shutdownChannel, devtoolsWebChannel } = yield* options.makeContext
|
25
|
+
|
26
|
+
const isConnected = yield* SubscriptionRef.make(true)
|
27
|
+
|
28
|
+
const incomingMessagesPubSub = yield* PubSub.unbounded<Devtools.MessageToAppLeader>().pipe(
|
29
|
+
Effect.acquireRelease(PubSub.shutdown),
|
30
|
+
)
|
31
|
+
|
32
|
+
const incomingMessages = Stream.fromPubSub(incomingMessagesPubSub)
|
33
|
+
|
34
|
+
const outgoingMessagesQueue = yield* Queue.unbounded<Devtools.MessageFromAppLeader>().pipe(
|
35
|
+
Effect.acquireRelease(Queue.shutdown),
|
36
|
+
)
|
37
|
+
|
38
|
+
const devtoolsCoordinatorChannel = devtoolsWebChannel
|
39
|
+
// coordinatorMessagePortOrChannel instanceof MessagePort
|
40
|
+
// ? yield* WebChannel.messagePortChannel({
|
41
|
+
// port: coordinatorMessagePortOrChannel,
|
42
|
+
// schema: { send: Devtools.MessageFromAppLeader, listen: Devtools.MessageToAppLeader },
|
43
|
+
// })
|
44
|
+
// : coordinatorMessagePortOrChannel
|
45
|
+
|
46
|
+
const sendMessage: SendMessageToDevtools = (message, options) =>
|
47
|
+
Effect.gen(function* () {
|
48
|
+
if (options?.force === true || (yield* isConnected)) {
|
49
|
+
yield* devtoolsCoordinatorChannel.send(message)
|
50
|
+
} else {
|
51
|
+
yield* Queue.offer(outgoingMessagesQueue, message)
|
52
|
+
}
|
53
|
+
}).pipe(
|
54
|
+
Effect.withSpan('@livestore/common:leader-thread:devtools:sendToDevtools'),
|
55
|
+
Effect.interruptible,
|
56
|
+
Effect.ignoreLogged,
|
57
|
+
)
|
58
|
+
|
59
|
+
// broadcastCallbacks.add((message) => sendMessage(message))
|
60
|
+
|
61
|
+
const { connectedClientSessionPullQueues, syncProcessor } = yield* LeaderThreadCtx
|
62
|
+
const { localHead } = yield* syncProcessor.syncState
|
63
|
+
|
64
|
+
// TODO close queue when devtools disconnects
|
65
|
+
const pullQueue = yield* connectedClientSessionPullQueues.makeQueue(localHead)
|
66
|
+
|
67
|
+
yield* Stream.fromQueue(pullQueue).pipe(
|
68
|
+
Stream.tap((msg) =>
|
69
|
+
Effect.gen(function* () {
|
70
|
+
if (msg.payload._tag === 'upstream-advance') {
|
71
|
+
for (const mutationEventEncoded of msg.payload.newEvents) {
|
72
|
+
yield* sendMessage(
|
73
|
+
Devtools.MutationBroadcast.make({
|
74
|
+
mutationEventEncoded,
|
75
|
+
|
76
|
+
liveStoreVersion,
|
77
|
+
}),
|
78
|
+
)
|
79
|
+
}
|
80
|
+
} else {
|
81
|
+
yield* Effect.logWarning('TODO implement rebases in devtools')
|
82
|
+
}
|
83
|
+
}),
|
84
|
+
),
|
85
|
+
Stream.runDrain,
|
86
|
+
Effect.forkScoped,
|
87
|
+
)
|
88
|
+
|
89
|
+
yield* devtoolsCoordinatorChannel.listen.pipe(
|
90
|
+
Stream.flatten(),
|
91
|
+
// Stream.tapLogWithLabel('@livestore/common:leader-thread:devtools:onPortMessage'),
|
92
|
+
Stream.tap((msg) =>
|
93
|
+
Effect.gen(function* () {
|
94
|
+
// yield* Effect.logDebug(`[@livestore/common:leader-thread:devtools] message from port: ${msg._tag}`, msg)
|
95
|
+
// if (msg._tag === 'LSD.MessagePortForStoreRes') {
|
96
|
+
// yield* Deferred.succeed(storeMessagePortDeferred, msg.port)
|
97
|
+
// } else {
|
98
|
+
yield* PubSub.publish(incomingMessagesPubSub, msg)
|
99
|
+
// }
|
100
|
+
}),
|
101
|
+
),
|
102
|
+
Stream.runDrain,
|
103
|
+
Effect.withSpan(`@livestore/common:leader-thread:devtools:onPortMessage`),
|
104
|
+
Effect.ignoreLogged,
|
105
|
+
Effect.forkScoped,
|
106
|
+
)
|
107
|
+
|
108
|
+
// yield* sendMessage(Devtools.AppHostReady.make({ appHostId, liveStoreVersion, isLeader }), { force: true })
|
109
|
+
|
110
|
+
// yield* sendMessage(Devtools.MessagePortForStoreReq.make({ appHostId, liveStoreVersion, requestId: nanoid() }), {
|
111
|
+
// force: true,
|
112
|
+
// })
|
113
|
+
|
114
|
+
yield* listenToDevtools({
|
115
|
+
incomingMessages,
|
116
|
+
sendMessage,
|
117
|
+
// isConnected,
|
118
|
+
// disconnect,
|
119
|
+
// storeId,
|
120
|
+
// appHostId,
|
121
|
+
// isLeader,
|
122
|
+
persistenceInfo,
|
123
|
+
shutdownChannel,
|
124
|
+
})
|
125
|
+
}).pipe(Effect.withSpan('@livestore/common:leader-thread:devtools:boot'))
|
126
|
+
|
127
|
+
const listenToDevtools = ({
|
128
|
+
incomingMessages,
|
129
|
+
sendMessage,
|
130
|
+
// isConnected,
|
131
|
+
// disconnect,
|
132
|
+
// appHostId,
|
133
|
+
// storeId,
|
134
|
+
// isLeader,
|
135
|
+
persistenceInfo,
|
136
|
+
shutdownChannel,
|
137
|
+
}: {
|
138
|
+
incomingMessages: Stream.Stream<Devtools.MessageToAppLeader>
|
139
|
+
sendMessage: SendMessageToDevtools
|
140
|
+
// isConnected: SubscriptionRef.SubscriptionRef<boolean>
|
141
|
+
// disconnect: Effect.Effect<void>
|
142
|
+
// appHostId: string
|
143
|
+
// storeId: string
|
144
|
+
// isLeader: boolean
|
145
|
+
persistenceInfo: PersistenceInfoPair
|
146
|
+
shutdownChannel: ShutdownChannel
|
147
|
+
}) =>
|
148
|
+
Effect.gen(function* () {
|
149
|
+
const innerWorkerCtx = yield* LeaderThreadCtx
|
150
|
+
const { syncBackend, makeSyncDb, db, dbLog, shutdownStateSubRef, syncProcessor } = innerWorkerCtx
|
151
|
+
|
152
|
+
type RequestId = string
|
153
|
+
const subscriptionFiberMap = yield* FiberMap.make<RequestId>()
|
154
|
+
|
155
|
+
yield* incomingMessages.pipe(
|
156
|
+
Stream.tap((decodedEvent) =>
|
157
|
+
Effect.gen(function* () {
|
158
|
+
// yield* Effect.logDebug('[@livestore/common:leader-thread:devtools] incomingMessage', decodedEvent)
|
159
|
+
|
160
|
+
if (decodedEvent._tag === 'LSD.Disconnect') {
|
161
|
+
// yield* SubscriptionRef.set(isConnected, false)
|
162
|
+
|
163
|
+
// yield* disconnect
|
164
|
+
|
165
|
+
// TODO is there a better place for this?
|
166
|
+
// yield* sendMessage(Devtools.AppHostReady.make({ appHostId, liveStoreVersion, isLeader }), {
|
167
|
+
// force: true,
|
168
|
+
// })
|
169
|
+
|
170
|
+
return
|
171
|
+
}
|
172
|
+
|
173
|
+
const { requestId } = decodedEvent
|
174
|
+
const reqPayload = { requestId, liveStoreVersion }
|
175
|
+
|
176
|
+
switch (decodedEvent._tag) {
|
177
|
+
case 'LSD.Ping': {
|
178
|
+
yield* sendMessage(Devtools.Pong.make({ ...reqPayload }))
|
179
|
+
return
|
180
|
+
}
|
181
|
+
case 'LSD.Leader.SnapshotReq': {
|
182
|
+
const snapshot = db.export()
|
183
|
+
|
184
|
+
yield* sendMessage(Devtools.SnapshotRes.make({ snapshot, ...reqPayload }))
|
185
|
+
|
186
|
+
return
|
187
|
+
}
|
188
|
+
case 'LSD.Leader.LoadDatabaseFileReq': {
|
189
|
+
const { data } = decodedEvent
|
190
|
+
|
191
|
+
let tableNames: Set<string>
|
192
|
+
|
193
|
+
try {
|
194
|
+
const tmpSyncDb = yield* makeSyncDb({ _tag: 'in-memory' })
|
195
|
+
tmpSyncDb.import(data)
|
196
|
+
const tableNameResults = tmpSyncDb.select<{ name: string }>(
|
197
|
+
`select name from sqlite_master where type = 'table'`,
|
198
|
+
)
|
199
|
+
|
200
|
+
tableNames = new Set(tableNameResults.map((_) => _.name))
|
201
|
+
|
202
|
+
tmpSyncDb.close()
|
203
|
+
} catch (e) {
|
204
|
+
yield* Effect.logError(`Error importing database file`, e)
|
205
|
+
yield* sendMessage(Devtools.LoadDatabaseFileRes.make({ ...reqPayload, status: 'unsupported-file' }))
|
206
|
+
|
207
|
+
return
|
208
|
+
}
|
209
|
+
|
210
|
+
if (tableNames.has(MUTATION_LOG_META_TABLE)) {
|
211
|
+
yield* SubscriptionRef.set(shutdownStateSubRef, 'shutting-down')
|
212
|
+
|
213
|
+
dbLog.import(data)
|
214
|
+
|
215
|
+
db.destroy()
|
216
|
+
} else if (tableNames.has(SCHEMA_META_TABLE) && tableNames.has(SCHEMA_MUTATIONS_META_TABLE)) {
|
217
|
+
yield* SubscriptionRef.set(shutdownStateSubRef, 'shutting-down')
|
218
|
+
|
219
|
+
db.import(data)
|
220
|
+
|
221
|
+
dbLog.destroy()
|
222
|
+
} else {
|
223
|
+
yield* sendMessage(Devtools.LoadDatabaseFileRes.make({ ...reqPayload, status: 'unsupported-database' }))
|
224
|
+
return
|
225
|
+
}
|
226
|
+
|
227
|
+
yield* sendMessage(Devtools.LoadDatabaseFileRes.make({ ...reqPayload, status: 'ok' }))
|
228
|
+
|
229
|
+
yield* shutdownChannel.send(IntentionalShutdownCause.make({ reason: 'devtools-import' }))
|
230
|
+
|
231
|
+
return
|
232
|
+
}
|
233
|
+
case 'LSD.Leader.ResetAllDataReq': {
|
234
|
+
const { mode } = decodedEvent
|
235
|
+
|
236
|
+
yield* SubscriptionRef.set(shutdownStateSubRef, 'shutting-down')
|
237
|
+
|
238
|
+
db.destroy()
|
239
|
+
|
240
|
+
if (mode === 'all-data') {
|
241
|
+
dbLog.destroy()
|
242
|
+
}
|
243
|
+
|
244
|
+
yield* sendMessage(Devtools.ResetAllDataRes.make({ ...reqPayload }))
|
245
|
+
|
246
|
+
yield* shutdownChannel.send(IntentionalShutdownCause.make({ reason: 'devtools-reset' }))
|
247
|
+
|
248
|
+
return
|
249
|
+
}
|
250
|
+
case 'LSD.Leader.DatabaseFileInfoReq': {
|
251
|
+
const dbSizeQuery = `SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size();`
|
252
|
+
const dbFileSize = db.select<{ size: number }>(dbSizeQuery, undefined)[0]!.size
|
253
|
+
const mutationLogFileSize = dbLog.select<{ size: number }>(dbSizeQuery, undefined)[0]!.size
|
254
|
+
|
255
|
+
yield* sendMessage(
|
256
|
+
Devtools.DatabaseFileInfoRes.make({
|
257
|
+
db: { fileSize: dbFileSize, persistenceInfo: persistenceInfo.db },
|
258
|
+
mutationLog: { fileSize: mutationLogFileSize, persistenceInfo: persistenceInfo.mutationLog },
|
259
|
+
...reqPayload,
|
260
|
+
}),
|
261
|
+
)
|
262
|
+
|
263
|
+
return
|
264
|
+
}
|
265
|
+
case 'LSD.Leader.MutationLogReq': {
|
266
|
+
const mutationLog = dbLog.export()
|
267
|
+
|
268
|
+
yield* sendMessage(Devtools.MutationLogRes.make({ mutationLog, ...reqPayload }))
|
269
|
+
|
270
|
+
return
|
271
|
+
}
|
272
|
+
case 'LSD.Leader.RunMutationReq': {
|
273
|
+
yield* syncProcessor.pushPartial(decodedEvent.mutationEventEncoded)
|
274
|
+
|
275
|
+
yield* sendMessage(Devtools.RunMutationRes.make({ ...reqPayload }))
|
276
|
+
|
277
|
+
return
|
278
|
+
}
|
279
|
+
case 'LSD.Leader.SyncHistorySubscribe': {
|
280
|
+
const { requestId } = decodedEvent
|
281
|
+
|
282
|
+
if (syncBackend !== undefined) {
|
283
|
+
// TODO consider piggybacking on the existing leader-thread sync-pulling
|
284
|
+
yield* syncBackend.pull(Option.none()).pipe(
|
285
|
+
Stream.map((_) => _.batch),
|
286
|
+
Stream.flattenIterables,
|
287
|
+
Stream.tap(({ mutationEventEncoded, metadata }) =>
|
288
|
+
sendMessage(Devtools.SyncHistoryRes.make({ mutationEventEncoded, metadata, ...reqPayload })),
|
289
|
+
),
|
290
|
+
Stream.runDrain,
|
291
|
+
Effect.acquireRelease(() => Effect.log('syncHistorySubscribe done')),
|
292
|
+
Effect.interruptible,
|
293
|
+
Effect.tapCauseLogPretty,
|
294
|
+
FiberMap.run(subscriptionFiberMap, requestId),
|
295
|
+
)
|
296
|
+
}
|
297
|
+
|
298
|
+
return
|
299
|
+
}
|
300
|
+
case 'LSD.Leader.SyncHistoryUnsubscribe': {
|
301
|
+
const { requestId } = decodedEvent
|
302
|
+
console.log('LSD.SyncHistoryUnsubscribe', requestId)
|
303
|
+
|
304
|
+
yield* FiberMap.remove(subscriptionFiberMap, requestId)
|
305
|
+
|
306
|
+
return
|
307
|
+
}
|
308
|
+
case 'LSD.Leader.SyncingInfoReq': {
|
309
|
+
const syncingInfo = Devtools.SyncingInfo.make({
|
310
|
+
enabled: syncBackend !== undefined,
|
311
|
+
metadata: {},
|
312
|
+
})
|
313
|
+
|
314
|
+
yield* sendMessage(Devtools.SyncingInfoRes.make({ syncingInfo, ...reqPayload }))
|
315
|
+
|
316
|
+
return
|
317
|
+
}
|
318
|
+
case 'LSD.Leader.NetworkStatusSubscribe': {
|
319
|
+
if (syncBackend !== undefined) {
|
320
|
+
const { requestId } = decodedEvent
|
321
|
+
|
322
|
+
// TODO investigate and fix bug. seems that when sending messages right after
|
323
|
+
// the devtools have connected get sometimes lost
|
324
|
+
// This is probably the same "flaky databrowser loading" bug as we're seeing in the playwright tests
|
325
|
+
yield* Effect.sleep(1000)
|
326
|
+
|
327
|
+
yield* syncBackend.isConnected.changes.pipe(
|
328
|
+
Stream.tap((isConnected) =>
|
329
|
+
sendMessage(
|
330
|
+
Devtools.NetworkStatusRes.make({
|
331
|
+
networkStatus: { isConnected, timestampMs: Date.now() },
|
332
|
+
...reqPayload,
|
333
|
+
}),
|
334
|
+
),
|
335
|
+
),
|
336
|
+
Stream.runDrain,
|
337
|
+
Effect.interruptible,
|
338
|
+
Effect.tapCauseLogPretty,
|
339
|
+
FiberMap.run(subscriptionFiberMap, requestId),
|
340
|
+
)
|
341
|
+
}
|
342
|
+
|
343
|
+
return
|
344
|
+
}
|
345
|
+
case 'LSD.Leader.NetworkStatusUnsubscribe': {
|
346
|
+
const { requestId } = decodedEvent
|
347
|
+
|
348
|
+
yield* FiberMap.remove(subscriptionFiberMap, requestId)
|
349
|
+
|
350
|
+
return
|
351
|
+
}
|
352
|
+
}
|
353
|
+
}).pipe(Effect.withSpan(`@livestore/common:leader-thread:onDevtoolsMessage:${decodedEvent._tag}`)),
|
354
|
+
),
|
355
|
+
UnexpectedError.mapToUnexpectedErrorStream,
|
356
|
+
Stream.runDrain,
|
357
|
+
)
|
358
|
+
})
|
@@ -0,0 +1,192 @@
|
|
1
|
+
import type { HttpClient, Scope, WebChannel } from '@livestore/utils/effect'
|
2
|
+
import { Deferred, Effect, FiberSet, Layer, Queue, SubscriptionRef } from '@livestore/utils/effect'
|
3
|
+
|
4
|
+
import type { BootStatus, MakeSynchronousDatabase, SqliteError, SynchronousDatabase } from '../adapter-types.js'
|
5
|
+
import { UnexpectedError } from '../adapter-types.js'
|
6
|
+
import type { LiveStoreSchema } from '../schema/mod.js'
|
7
|
+
import { EventId, MutationEvent, mutationLogMetaTable, SYNC_STATUS_TABLE, syncStatusTable } from '../schema/mod.js'
|
8
|
+
import { migrateTable } from '../schema-management/migrations.js'
|
9
|
+
import type { InvalidPullError, IsOfflineError, SyncBackend } from '../sync/sync.js'
|
10
|
+
import { sql } from '../util.js'
|
11
|
+
import { execSql } from './connection.js'
|
12
|
+
import { makeLeaderSyncProcessor } from './leader-sync-processor.js'
|
13
|
+
import { bootDevtools } from './leader-worker-devtools.js'
|
14
|
+
import { makePullQueueSet } from './pull-queue-set.js'
|
15
|
+
import { recreateDb } from './recreate-db.js'
|
16
|
+
import type { DevtoolsOptions, InitialBlockingSyncContext, InitialSyncOptions, ShutdownState } from './types.js'
|
17
|
+
import { LeaderThreadCtx } from './types.js'
|
18
|
+
|
19
|
+
export const makeLeaderThreadLayer = ({
|
20
|
+
schema,
|
21
|
+
storeId,
|
22
|
+
originId,
|
23
|
+
makeSyncDb,
|
24
|
+
makeSyncBackend,
|
25
|
+
db,
|
26
|
+
dbLog,
|
27
|
+
devtoolsOptions,
|
28
|
+
initialSyncOptions = { _tag: 'Skip' },
|
29
|
+
}: {
|
30
|
+
storeId: string
|
31
|
+
originId: string
|
32
|
+
schema: LiveStoreSchema
|
33
|
+
makeSyncDb: MakeSynchronousDatabase
|
34
|
+
makeSyncBackend: Effect.Effect<SyncBackend, UnexpectedError, Scope.Scope> | undefined
|
35
|
+
db: SynchronousDatabase
|
36
|
+
dbLog: SynchronousDatabase
|
37
|
+
devtoolsOptions: DevtoolsOptions
|
38
|
+
initialSyncOptions: InitialSyncOptions | undefined
|
39
|
+
}): Layer.Layer<LeaderThreadCtx, UnexpectedError, Scope.Scope | HttpClient.HttpClient> =>
|
40
|
+
Effect.gen(function* () {
|
41
|
+
const bootStatusQueue = yield* Queue.unbounded<BootStatus>().pipe(Effect.acquireRelease(Queue.shutdown))
|
42
|
+
|
43
|
+
// TODO do more validation here than just checking the count of tables
|
44
|
+
// Either happens on initial boot or if schema changes
|
45
|
+
const dbMissing = db.select<{ count: number }>(sql`select count(*) as count from sqlite_master`)[0]!.count === 0
|
46
|
+
|
47
|
+
const syncBackend = makeSyncBackend === undefined ? undefined : yield* makeSyncBackend
|
48
|
+
|
49
|
+
const initialBlockingSyncContext = yield* makeInitialBlockingSyncContext({ initialSyncOptions, bootStatusQueue })
|
50
|
+
|
51
|
+
const syncProcessor = yield* makeLeaderSyncProcessor({ schema, dbMissing, dbLog, initialBlockingSyncContext })
|
52
|
+
|
53
|
+
const ctx = {
|
54
|
+
schema,
|
55
|
+
bootStatusQueue,
|
56
|
+
storeId,
|
57
|
+
originId,
|
58
|
+
db,
|
59
|
+
dbLog,
|
60
|
+
makeSyncDb,
|
61
|
+
mutationEventSchema: MutationEvent.makeMutationEventSchema(schema),
|
62
|
+
shutdownStateSubRef: yield* SubscriptionRef.make<ShutdownState>('running'),
|
63
|
+
syncBackend,
|
64
|
+
syncProcessor,
|
65
|
+
connectedClientSessionPullQueues: yield* makePullQueueSet,
|
66
|
+
} satisfies typeof LeaderThreadCtx.Service
|
67
|
+
|
68
|
+
// @ts-expect-error For debugging purposes
|
69
|
+
globalThis.__leaderThreadCtx = ctx
|
70
|
+
|
71
|
+
const layer = Layer.succeed(LeaderThreadCtx, ctx)
|
72
|
+
|
73
|
+
yield* bootLeaderThread({ dbMissing, initialBlockingSyncContext, devtoolsOptions }).pipe(Effect.provide(layer))
|
74
|
+
|
75
|
+
return layer
|
76
|
+
}).pipe(
|
77
|
+
Effect.withSpan('@livestore/common:leader-thread:boot'),
|
78
|
+
Effect.withSpanScoped('@livestore/common:leader-thread'),
|
79
|
+
UnexpectedError.mapToUnexpectedError,
|
80
|
+
Layer.unwrapScoped,
|
81
|
+
)
|
82
|
+
|
83
|
+
const makeInitialBlockingSyncContext = ({
|
84
|
+
initialSyncOptions,
|
85
|
+
bootStatusQueue,
|
86
|
+
}: {
|
87
|
+
initialSyncOptions: InitialSyncOptions
|
88
|
+
bootStatusQueue: Queue.Queue<BootStatus>
|
89
|
+
}) =>
|
90
|
+
Effect.gen(function* () {
|
91
|
+
const ctx = {
|
92
|
+
isDone: false,
|
93
|
+
processedMutations: 0,
|
94
|
+
total: -1,
|
95
|
+
}
|
96
|
+
|
97
|
+
const blockingDeferred = initialSyncOptions._tag === 'Blocking' ? yield* Deferred.make<void>() : undefined
|
98
|
+
|
99
|
+
if (blockingDeferred !== undefined && initialSyncOptions._tag === 'Blocking') {
|
100
|
+
yield* Deferred.succeed(blockingDeferred, void 0).pipe(
|
101
|
+
Effect.delay(initialSyncOptions.timeout),
|
102
|
+
Effect.forkScoped,
|
103
|
+
)
|
104
|
+
}
|
105
|
+
|
106
|
+
return {
|
107
|
+
blockingDeferred,
|
108
|
+
update: ({ processed, remaining }) =>
|
109
|
+
Effect.gen(function* () {
|
110
|
+
if (ctx.isDone === true) return
|
111
|
+
|
112
|
+
if (ctx.total === -1) {
|
113
|
+
ctx.total = remaining + processed
|
114
|
+
}
|
115
|
+
|
116
|
+
ctx.processedMutations += processed
|
117
|
+
yield* Queue.offer(bootStatusQueue, {
|
118
|
+
stage: 'syncing',
|
119
|
+
progress: { done: ctx.processedMutations, total: ctx.total },
|
120
|
+
})
|
121
|
+
|
122
|
+
if (remaining === 0 && blockingDeferred !== undefined) {
|
123
|
+
yield* Deferred.succeed(blockingDeferred, void 0)
|
124
|
+
ctx.isDone = true
|
125
|
+
}
|
126
|
+
}),
|
127
|
+
} satisfies InitialBlockingSyncContext
|
128
|
+
})
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Blocks until the leader thread has finished its initial setup.
|
132
|
+
* It also starts various background processes (e.g. syncing)
|
133
|
+
*/
|
134
|
+
const bootLeaderThread = ({
|
135
|
+
dbMissing,
|
136
|
+
initialBlockingSyncContext,
|
137
|
+
devtoolsOptions,
|
138
|
+
}: {
|
139
|
+
dbMissing: boolean
|
140
|
+
initialBlockingSyncContext: InitialBlockingSyncContext
|
141
|
+
devtoolsOptions: DevtoolsOptions
|
142
|
+
}): Effect.Effect<
|
143
|
+
void,
|
144
|
+
UnexpectedError | SqliteError | IsOfflineError | InvalidPullError,
|
145
|
+
LeaderThreadCtx | Scope.Scope | HttpClient.HttpClient
|
146
|
+
> =>
|
147
|
+
Effect.gen(function* () {
|
148
|
+
const { dbLog, bootStatusQueue, syncProcessor } = yield* LeaderThreadCtx
|
149
|
+
|
150
|
+
yield* migrateTable({
|
151
|
+
db: dbLog,
|
152
|
+
behaviour: 'create-if-not-exists',
|
153
|
+
tableAst: mutationLogMetaTable.sqliteDef.ast,
|
154
|
+
skipMetaTable: true,
|
155
|
+
})
|
156
|
+
|
157
|
+
yield* migrateTable({
|
158
|
+
db: dbLog,
|
159
|
+
behaviour: 'create-if-not-exists',
|
160
|
+
tableAst: syncStatusTable.sqliteDef.ast,
|
161
|
+
skipMetaTable: true,
|
162
|
+
})
|
163
|
+
|
164
|
+
// Create sync status row if it doesn't exist
|
165
|
+
yield* execSql(
|
166
|
+
dbLog,
|
167
|
+
sql`INSERT INTO ${SYNC_STATUS_TABLE} (head)
|
168
|
+
SELECT ${EventId.ROOT.global}
|
169
|
+
WHERE NOT EXISTS (SELECT 1 FROM ${SYNC_STATUS_TABLE})`,
|
170
|
+
{},
|
171
|
+
)
|
172
|
+
|
173
|
+
const dbReady = yield* Deferred.make<void>()
|
174
|
+
|
175
|
+
// We're already starting pulling from the sync backend concurrently but wait until the db is ready before
|
176
|
+
// processing any incoming mutations
|
177
|
+
yield* syncProcessor.boot({ dbReady })
|
178
|
+
|
179
|
+
if (dbMissing) {
|
180
|
+
yield* recreateDb
|
181
|
+
}
|
182
|
+
|
183
|
+
yield* Deferred.succeed(dbReady, void 0)
|
184
|
+
|
185
|
+
if (initialBlockingSyncContext.blockingDeferred !== undefined) {
|
186
|
+
yield* initialBlockingSyncContext.blockingDeferred
|
187
|
+
}
|
188
|
+
|
189
|
+
yield* Queue.offer(bootStatusQueue, { stage: 'done' })
|
190
|
+
|
191
|
+
yield* bootDevtools(devtoolsOptions).pipe(Effect.tapCauseLogPretty, Effect.forkScoped)
|
192
|
+
})
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { Effect, Schema } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
import type { SynchronousDatabase } from '../adapter-types.js'
|
4
|
+
import * as EventId from '../schema/EventId.js'
|
5
|
+
import { MUTATION_LOG_META_TABLE, mutationLogMetaTable, SYNC_STATUS_TABLE } from '../schema/system-tables.js'
|
6
|
+
import { prepareBindValues, sql } from '../util.js'
|
7
|
+
import { LeaderThreadCtx } from './types.js'
|
8
|
+
|
9
|
+
export const getMutationEventsSince = (since: EventId.EventId) =>
|
10
|
+
Effect.gen(function* () {
|
11
|
+
const { dbLog } = yield* LeaderThreadCtx
|
12
|
+
|
13
|
+
const query = mutationLogMetaTable.query.where('idGlobal', '>=', since.global).asSql()
|
14
|
+
const pendingMutationEventsRaw = dbLog.select(query.query, prepareBindValues(query.bindValues, query.query))
|
15
|
+
const pendingMutationEvents = Schema.decodeUnknownSync(mutationLogMetaTable.schema.pipe(Schema.Array))(
|
16
|
+
pendingMutationEventsRaw,
|
17
|
+
)
|
18
|
+
|
19
|
+
return pendingMutationEvents
|
20
|
+
.map((_) => ({
|
21
|
+
mutation: _.mutation,
|
22
|
+
args: _.argsJson,
|
23
|
+
id: { global: _.idGlobal, local: _.idLocal },
|
24
|
+
parentId: { global: _.parentIdGlobal, local: _.parentIdLocal },
|
25
|
+
}))
|
26
|
+
.filter((_) => EventId.compare(_.id, since) > 0)
|
27
|
+
})
|
28
|
+
|
29
|
+
export const getLocalHeadFromDb = (dbLog: SynchronousDatabase) => {
|
30
|
+
const res = dbLog.select<{ idGlobal: number; idLocal: number }>(
|
31
|
+
sql`select idGlobal, idLocal from ${MUTATION_LOG_META_TABLE} order by idGlobal DESC, idLocal DESC limit 1`,
|
32
|
+
)[0]
|
33
|
+
|
34
|
+
return res ? { global: res.idGlobal, local: res.idLocal } : EventId.ROOT
|
35
|
+
}
|
36
|
+
|
37
|
+
export const getBackendHeadFromDb = (dbLog: SynchronousDatabase) =>
|
38
|
+
dbLog.select<{ head: number }>(sql`select head from ${SYNC_STATUS_TABLE}`)[0]?.head ?? EventId.ROOT.global
|
39
|
+
|
40
|
+
// TODO use prepared statements
|
41
|
+
export const updateBackendHead = (dbLog: SynchronousDatabase, head: EventId.EventId) =>
|
42
|
+
dbLog.execute(sql`UPDATE ${SYNC_STATUS_TABLE} SET head = ${head.global}`)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { Effect, Queue } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
import * as MutationEvent from '../schema/MutationEvent.js'
|
4
|
+
import { getMutationEventsSince } from './mutationlog.js'
|
5
|
+
import { type PullQueueItem, type PullQueueSet } from './types.js'
|
6
|
+
|
7
|
+
export const makePullQueueSet = Effect.gen(function* () {
|
8
|
+
const set = new Set<Queue.Queue<PullQueueItem>>()
|
9
|
+
|
10
|
+
yield* Effect.addFinalizer(() =>
|
11
|
+
Effect.gen(function* () {
|
12
|
+
for (const queue of set) {
|
13
|
+
yield* Queue.shutdown(queue)
|
14
|
+
}
|
15
|
+
|
16
|
+
set.clear()
|
17
|
+
}),
|
18
|
+
)
|
19
|
+
|
20
|
+
const makeQueue: PullQueueSet['makeQueue'] = (since) =>
|
21
|
+
Effect.gen(function* () {
|
22
|
+
const queue = yield* Queue.unbounded<PullQueueItem>().pipe(Effect.acquireRelease(Queue.shutdown))
|
23
|
+
|
24
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => set.delete(queue)))
|
25
|
+
|
26
|
+
const mutationEvents = yield* getMutationEventsSince(since)
|
27
|
+
|
28
|
+
if (mutationEvents.length > 0) {
|
29
|
+
const newEvents = mutationEvents.map((mutationEvent) => new MutationEvent.EncodedWithMeta(mutationEvent))
|
30
|
+
yield* queue.offer({ payload: { _tag: 'upstream-advance', newEvents }, remaining: 0 })
|
31
|
+
}
|
32
|
+
|
33
|
+
set.add(queue)
|
34
|
+
|
35
|
+
return queue
|
36
|
+
})
|
37
|
+
|
38
|
+
const offer: PullQueueSet['offer'] = (item) =>
|
39
|
+
Effect.gen(function* () {
|
40
|
+
// Short-circuit if the payload is an empty upstream advance
|
41
|
+
if (
|
42
|
+
item.payload._tag === 'upstream-advance' &&
|
43
|
+
item.payload.newEvents.length === 0 &&
|
44
|
+
item.payload.trimRollbackUntil === undefined
|
45
|
+
) {
|
46
|
+
return
|
47
|
+
}
|
48
|
+
|
49
|
+
for (const queue of set) {
|
50
|
+
yield* Queue.offer(queue, item)
|
51
|
+
}
|
52
|
+
})
|
53
|
+
|
54
|
+
return {
|
55
|
+
makeQueue,
|
56
|
+
offer,
|
57
|
+
}
|
58
|
+
})
|