@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2d73b235d7d7
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/README.md +24 -20
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +328 -0
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +345 -0
- package/dist/adapter.d.ts +315 -122
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +33 -49
- package/dist/{binary.d.ts → attachment.d.ts} +8 -9
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +30 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +305 -140
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +67 -0
- package/dist/change-set.d.ts +10 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -90
- package/dist/change.d.ts +7 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +53 -31
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +66 -29
- package/dist/collection.d.ts +33 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +57 -366
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +19 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +755 -0
- package/dist/connection.d.ts +6 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +117 -4210
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +2 -5
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +260 -0
- package/dist/conversation-row.d.ts +55 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +82 -0
- package/dist/conversation.d.ts +84 -54
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1043 -823
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +20 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +12 -0
- package/dist/entry.d.ts +30 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +135 -41
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -4
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +25 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +157 -61
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -3
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -7
- package/dist/index.d.ts +49 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -8
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +292 -0
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +39 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +223 -0
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +24 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +365 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +311 -120
- package/dist/messages.d.ts +67 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +180 -0
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +15 -15
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -22
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +40 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +265 -44
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +71 -0
- package/dist/outcome.d.ts +46 -16
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +51 -7
- package/dist/overlay.d.ts +24 -11
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +138 -193
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +7 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +46 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +344 -0
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +330 -0
- package/dist/query.d.ts +22 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -494
- package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +14 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +31 -15
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +385 -176
- package/dist/react.d.ts +27 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +36 -21
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +20 -18
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +174 -83
- package/dist/recovery.d.ts +4 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +59 -2
- package/dist/refresh.d.ts +18 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -79
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +45 -38
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +319 -229
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +53 -13
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +405 -115
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +222 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +40 -32
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +72 -123
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +45 -87
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +402 -286
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +464 -0
- package/dist/search.d.ts +12 -95
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -317
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +1 -10
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -135
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +327 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +172 -0
- package/dist/source.d.ts +96 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +149 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +234 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +474 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +115 -160
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +171 -762
- package/dist/stored.d.ts +181 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +807 -0
- package/dist/surface.d.ts +100 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +258 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +362 -204
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +378 -264
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +1 -1
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +28 -20
- package/dist/validation.d.ts +31 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +144 -0
- package/dist/windows.d.ts +1 -11
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -70
- package/dist/wire.d.ts +89 -17
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +38 -15
- package/package.json +16 -20
- package/AGENTS.md +0 -308
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -237
- package/dist/chat/messages.d.ts +0 -29
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -190
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -68
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -619
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -306
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/read-side.d.ts +0 -27
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -1179
package/dist/tables.js
CHANGED
|
@@ -1,57 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import { answerQuery, namedHandles } from './compile.js';
|
|
3
|
+
import { amended, authoredLocators, authoredPart, call, callRecords, chatDraft, chatDraftConversations, chatDraftRecord, chatDraftRecords, chatDraftsDropped, claim, fact, fenced, fencedWork, fences, FILE_PART_BYTES, authoredEmptied, heldOrder, kept, moving, pendingBatch, pendingState, queuedLocators, queueOf, queues, remember, roomDraft, roomDraftRecords, spooled, unfenced, unsent, unsentStatus, } from './authored.js';
|
|
4
|
+
import { count, text, texts } from './column.js';
|
|
5
|
+
import { conversationFacts, conversationRows, forgottenConversations, heldConversations, keptFact, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
|
|
6
|
+
import { forgottenRuns, heldRuns, keptRuns, RUN_TABLES, runMarks, runsLeft, } from './run-tables.js';
|
|
7
|
+
import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
|
|
8
|
+
import { conversationTallies, roomTallies, } from './tallies.js';
|
|
9
|
+
import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, holders, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
|
|
10
|
+
export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
|
|
11
|
+
const STATEMENTS_HELD = 256;
|
|
12
|
+
export function sqliteConnection(engine, database) {
|
|
13
|
+
const decoder = new TextDecoder();
|
|
14
|
+
const held = new Map();
|
|
15
|
+
database.createFunction(sql.HOLDS_PHRASE, sql.holdsPhrase, {
|
|
16
|
+
arity: 2,
|
|
17
|
+
deterministic: true,
|
|
18
|
+
});
|
|
19
|
+
function prepared(sql) {
|
|
20
|
+
if (sql.includes(';'))
|
|
21
|
+
return null;
|
|
22
|
+
const found = held.get(sql);
|
|
23
|
+
held.delete(sql);
|
|
24
|
+
const statement = found ?? database.prepare(sql);
|
|
25
|
+
held.set(sql, statement);
|
|
26
|
+
if (held.size > STATEMENTS_HELD) {
|
|
27
|
+
const [oldest, evicted] = held.entries().next().value;
|
|
28
|
+
held.delete(oldest);
|
|
29
|
+
evicted.finalize();
|
|
30
|
+
}
|
|
31
|
+
return statement;
|
|
32
|
+
}
|
|
33
|
+
function stepped(statement, bind, each) {
|
|
34
|
+
try {
|
|
35
|
+
if (bind.length > 0 && statement.parameterCount > 0)
|
|
36
|
+
statement.bind(bind);
|
|
37
|
+
while (statement.step())
|
|
38
|
+
each();
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
statement.resetNoThrow(true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
run(sql, bind = []) {
|
|
46
|
+
const statement = prepared(sql);
|
|
47
|
+
if (statement === null)
|
|
48
|
+
database.exec({ sql, bind });
|
|
49
|
+
else
|
|
50
|
+
stepped(statement, bind, () => { });
|
|
51
|
+
},
|
|
52
|
+
rows(sql, bind = []) {
|
|
53
|
+
const statement = prepared(sql);
|
|
54
|
+
if (statement === null) {
|
|
55
|
+
return database.exec({ sql, bind, rowMode: 'object', returnValue: 'resultRows' });
|
|
56
|
+
}
|
|
57
|
+
const names = statement.getColumnNames([]);
|
|
58
|
+
const rows = [];
|
|
59
|
+
stepped(statement, bind, () => {
|
|
60
|
+
const values = statement.get([]);
|
|
61
|
+
const row = Object.create(null);
|
|
62
|
+
for (const [index, name] of names.entries())
|
|
63
|
+
row[name] = values[index] ?? null;
|
|
64
|
+
rows.push(row);
|
|
65
|
+
});
|
|
66
|
+
return rows;
|
|
67
|
+
},
|
|
68
|
+
collate(name, compare) {
|
|
69
|
+
const answered = engine.capi.sqlite3_create_collation_v2(database.pointer, name, engine.capi.SQLITE_UTF8, 0, (_argument, leftLength, left, rightLength, right) => {
|
|
70
|
+
const heap = engine.wasm.heap8u();
|
|
71
|
+
return Math.sign(compare(decoder.decode(heap.subarray(left, left + leftLength)), decoder.decode(heap.subarray(right, right + rightLength))));
|
|
72
|
+
}, 0);
|
|
73
|
+
if (answered !== 0)
|
|
74
|
+
throw new Error(`the database refused the collation ${name}`);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const PROBE_BYTES = 4 * FILE_PART_BYTES;
|
|
17
79
|
export const RUNTIME_TABLES = [
|
|
18
|
-
...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
|
|
19
|
-
'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
|
|
20
80
|
'CREATE TABLE opened_files (key TEXT PRIMARY KEY, locator TEXT NOT NULL, path TEXT NOT NULL, revision TEXT NOT NULL, media_type TEXT NOT NULL, sha256 TEXT, byte_length INTEGER) WITHOUT ROWID',
|
|
21
81
|
'CREATE INDEX opened_files_name ON opened_files (locator, path, revision)',
|
|
82
|
+
'CREATE TABLE opened_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
|
|
83
|
+
...REPLICA_TABLES,
|
|
84
|
+
...MESSAGE_TABLES,
|
|
85
|
+
...READ_TABLES,
|
|
86
|
+
...RUN_TABLES,
|
|
22
87
|
];
|
|
23
|
-
const
|
|
24
|
-
const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
|
|
25
|
-
const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
|
|
88
|
+
const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
|
|
26
89
|
const READS = new Set([
|
|
27
|
-
'authored.
|
|
90
|
+
'authored.status',
|
|
91
|
+
'authored.moving',
|
|
92
|
+
'authored.pending',
|
|
93
|
+
'authored.batch',
|
|
94
|
+
'authored.order',
|
|
95
|
+
'authored.queued',
|
|
28
96
|
'authored.roomDrafts',
|
|
97
|
+
'authored.chatDraft.read',
|
|
29
98
|
'authored.chatDrafts',
|
|
30
99
|
'authored.calls',
|
|
31
100
|
'authored.fences',
|
|
101
|
+
'authored.unsent',
|
|
32
102
|
'authored.fact',
|
|
33
103
|
'authored.file',
|
|
104
|
+
'replica.open',
|
|
105
|
+
'replica.rooms',
|
|
106
|
+
'replica.room',
|
|
107
|
+
'replica.covering',
|
|
108
|
+
'replica.offline',
|
|
109
|
+
'replica.held',
|
|
110
|
+
'replica.facts',
|
|
111
|
+
'replica.presentation',
|
|
112
|
+
'replica.query',
|
|
113
|
+
'replica.named',
|
|
114
|
+
'replica.tallies',
|
|
115
|
+
'replica.entries',
|
|
116
|
+
'replica.typed',
|
|
117
|
+
'replica.referrers',
|
|
118
|
+
'replica.holders',
|
|
119
|
+
'replica.folders',
|
|
120
|
+
'replica.typedWithin',
|
|
34
121
|
'opened.find',
|
|
122
|
+
'opened.held',
|
|
35
123
|
'file.part',
|
|
124
|
+
'conversation.held',
|
|
125
|
+
'conversation.window',
|
|
126
|
+
'conversation.count',
|
|
127
|
+
'conversation.turn',
|
|
128
|
+
'conversation.rows',
|
|
129
|
+
'conversation.tallies',
|
|
130
|
+
'conversation.facts',
|
|
131
|
+
'conversation.stored',
|
|
132
|
+
'read.stored',
|
|
133
|
+
'run.marks',
|
|
134
|
+
'run.held',
|
|
36
135
|
]);
|
|
37
136
|
const KINDS = new Set([
|
|
38
137
|
...READS,
|
|
39
|
-
'authored.keep',
|
|
40
138
|
'authored.amend',
|
|
41
139
|
'authored.roomDraft',
|
|
42
140
|
'authored.chatDraft',
|
|
43
141
|
'authored.call',
|
|
44
|
-
'authored.fence',
|
|
45
|
-
'authored.unfence',
|
|
46
|
-
'authored.discard',
|
|
47
142
|
'authored.remember',
|
|
48
143
|
'authored.claim',
|
|
49
144
|
'authored.end',
|
|
145
|
+
'replica.stage',
|
|
146
|
+
'replica.resume',
|
|
147
|
+
'replica.refresh',
|
|
148
|
+
'replica.unrefresh',
|
|
149
|
+
'replica.commit',
|
|
150
|
+
'replica.fence',
|
|
151
|
+
'replica.erase',
|
|
152
|
+
'replica.abandon',
|
|
153
|
+
'replica.unfence',
|
|
154
|
+
'replica.release',
|
|
155
|
+
'replica.rederive',
|
|
156
|
+
'replica.demote',
|
|
157
|
+
'replica.fact',
|
|
158
|
+
'replica.present',
|
|
50
159
|
'opened.begin',
|
|
51
160
|
'opened.part',
|
|
52
161
|
'opened.keep',
|
|
53
162
|
'opened.drop',
|
|
54
163
|
'opened.clean',
|
|
164
|
+
'conversation.keep',
|
|
165
|
+
'conversation.fact',
|
|
166
|
+
'conversation.drop',
|
|
167
|
+
'space.probe',
|
|
168
|
+
'read.keep',
|
|
169
|
+
'read.builds',
|
|
170
|
+
'run.keep',
|
|
171
|
+
'run.left',
|
|
55
172
|
]);
|
|
56
173
|
export function isRuntime(request) {
|
|
57
174
|
return KINDS.has(request.kind);
|
|
@@ -59,235 +176,76 @@ export function isRuntime(request) {
|
|
|
59
176
|
export function readsRuntime(request) {
|
|
60
177
|
return READS.has(request.kind);
|
|
61
178
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
function texts(rows, column) {
|
|
66
|
-
return rows.map((row) => text(row[column]));
|
|
67
|
-
}
|
|
68
|
-
function owned(files) {
|
|
69
|
-
return JSON.stringify([...new Set(files)]);
|
|
70
|
-
}
|
|
71
|
-
function fact(connection, name) {
|
|
72
|
-
const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
|
|
73
|
-
return held === undefined ? null : text(held.value);
|
|
74
|
-
}
|
|
75
|
-
function remember(connection, name, value) {
|
|
76
|
-
connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
|
|
77
|
-
name,
|
|
78
|
-
value,
|
|
79
|
-
]);
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
function fenced(connection, locator) {
|
|
83
|
-
return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
|
|
84
|
-
}
|
|
85
|
-
function stored(connection, key) {
|
|
86
|
-
return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
|
|
87
|
-
}
|
|
88
|
-
function storedPart(connection, key, part, bytes) {
|
|
89
|
-
connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
|
|
90
|
-
}
|
|
91
|
-
async function storedFiles(connection, files) {
|
|
92
|
-
for (const { key, blob } of files) {
|
|
93
|
-
if (stored(connection, key))
|
|
94
|
-
continue;
|
|
95
|
-
for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
|
|
96
|
-
const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
|
|
97
|
-
storedPart(connection, key, part, bytes);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function filePart(connection, key, part) {
|
|
102
|
-
const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
|
|
103
|
-
key,
|
|
104
|
-
part,
|
|
105
|
-
]);
|
|
106
|
-
return held?.bytes instanceof Uint8Array ? held.bytes : null;
|
|
107
|
-
}
|
|
108
|
-
function* fileParts(connection, key) {
|
|
109
|
-
for (let part = 0;; part += 1) {
|
|
110
|
-
const bytes = filePart(connection, key, part);
|
|
111
|
-
if (bytes === null)
|
|
112
|
-
return;
|
|
113
|
-
yield bytes;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function spooled(connection, spool, { key, type }) {
|
|
117
|
-
for (const held of [...spool.held()]) {
|
|
118
|
-
if (held !== key && !stored(connection, held))
|
|
119
|
-
await spool.drop(held);
|
|
120
|
-
}
|
|
121
|
-
return spool.spool(key, type, fileParts(connection, key));
|
|
122
|
-
}
|
|
123
|
-
function unowned(connection) {
|
|
124
|
-
connection.run(UNOWNED_PARTS);
|
|
125
|
-
}
|
|
126
|
-
function queued(connection) {
|
|
179
|
+
function heldWork(connection, locator) {
|
|
180
|
+
const room = heldRoom(connection, locator);
|
|
127
181
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
ids: JSON.parse(text(row.ids)),
|
|
131
|
-
})),
|
|
132
|
-
pending: connection
|
|
133
|
-
.rows('SELECT locator, id, batch, state FROM authored_pending')
|
|
134
|
-
.map((row) => ({
|
|
135
|
-
locator: text(row.locator),
|
|
136
|
-
id: text(row.id),
|
|
137
|
-
batch: text(row.batch),
|
|
138
|
-
state: text(row.state),
|
|
139
|
-
})),
|
|
182
|
+
room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
|
|
183
|
+
queue: queueOf(connection, locator),
|
|
140
184
|
};
|
|
141
185
|
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
for (const path of consumedRoomDrafts ?? []) {
|
|
148
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
|
|
149
|
-
locator,
|
|
150
|
-
path,
|
|
151
|
-
]);
|
|
152
|
-
}
|
|
153
|
-
for (const { path, record, files } of roomDrafts ?? []) {
|
|
154
|
-
connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
|
|
155
|
-
}
|
|
156
|
-
if (order === undefined)
|
|
157
|
-
return;
|
|
158
|
-
const before = new Set(heldOrder(connection, locator));
|
|
159
|
-
const after = new Set(order);
|
|
160
|
-
if (after.size === 0)
|
|
161
|
-
connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
|
|
162
|
-
else {
|
|
163
|
-
connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
|
|
164
|
-
locator,
|
|
165
|
-
JSON.stringify([...after]),
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
168
|
-
for (const id of before) {
|
|
169
|
-
if (!after.has(id)) {
|
|
170
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
for (const { id, batch, state, files } of added ?? []) {
|
|
174
|
-
if (before.has(id) || !after.has(id))
|
|
175
|
-
continue;
|
|
176
|
-
connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files) VALUES (?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files)]);
|
|
177
|
-
}
|
|
178
|
-
for (const { id, batch, files } of founded ?? []) {
|
|
179
|
-
if (!before.has(id))
|
|
180
|
-
continue;
|
|
181
|
-
connection.run('UPDATE authored_pending SET batch = ?, files = ? WHERE locator = ? AND id = ?', [batch, owned(files), locator, id]);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async function kept(connection, { writes, files, whole }) {
|
|
185
|
-
const refused = writes.find(({ locator }) => fenced(connection, locator));
|
|
186
|
-
if (refused !== undefined && whole)
|
|
187
|
-
return refused.locator;
|
|
188
|
-
await storedFiles(connection, files);
|
|
189
|
-
for (const write of writes) {
|
|
190
|
-
if (!fenced(connection, write.locator))
|
|
191
|
-
keptRows(connection, write);
|
|
192
|
-
}
|
|
193
|
-
unowned(connection);
|
|
194
|
-
return refused?.locator ?? null;
|
|
186
|
+
function status(connection) {
|
|
187
|
+
return {
|
|
188
|
+
...unsentStatus(connection),
|
|
189
|
+
lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
|
|
190
|
+
};
|
|
195
191
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return null;
|
|
202
|
-
connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
|
|
203
|
-
JSON.stringify({
|
|
204
|
-
...JSON.parse(text(held.state)),
|
|
205
|
-
...JSON.parse(amendment),
|
|
206
|
-
}),
|
|
207
|
-
locator,
|
|
208
|
-
id,
|
|
209
|
-
]);
|
|
210
|
-
return null;
|
|
192
|
+
function pendingOf(connection, locator, id) {
|
|
193
|
+
return {
|
|
194
|
+
state: pendingState(connection, locator, id),
|
|
195
|
+
room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
|
|
196
|
+
};
|
|
211
197
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
198
|
+
function storedConversations(connection, conversations) {
|
|
199
|
+
const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
|
|
200
|
+
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
201
|
+
return [
|
|
202
|
+
...new Set([
|
|
203
|
+
...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
|
|
204
|
+
...chatDraftConversations(connection, conversations),
|
|
205
|
+
]),
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
function droppedConversations(connection, conversations) {
|
|
209
|
+
const held = storedConversations(connection, conversations);
|
|
210
|
+
for (const table of tablesOf(MESSAGE_TABLES)) {
|
|
211
|
+
connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
|
|
212
|
+
JSON.stringify(conversations),
|
|
220
213
|
]);
|
|
221
214
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
unowned(connection);
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
function chatDraft(connection, { kept: drafts, dropped }) {
|
|
229
|
-
for (const conversation of dropped) {
|
|
230
|
-
connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
|
|
231
|
-
}
|
|
232
|
-
for (const { conversation, record } of drafts) {
|
|
233
|
-
connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
|
|
234
|
-
}
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
async function call(connection, { operation, kept: held, files }) {
|
|
238
|
-
await storedFiles(connection, files);
|
|
239
|
-
if (held === null)
|
|
240
|
-
connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
|
|
241
|
-
else {
|
|
242
|
-
connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
|
|
243
|
-
}
|
|
244
|
-
unowned(connection);
|
|
245
|
-
return null;
|
|
215
|
+
chatDraftsDropped(connection, conversations);
|
|
216
|
+
return held;
|
|
246
217
|
}
|
|
247
|
-
function
|
|
248
|
-
connection.run(
|
|
249
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
|
|
218
|
+
function unopened(connection) {
|
|
219
|
+
connection.run(UNOPENED_PARTS);
|
|
250
220
|
}
|
|
251
221
|
function fence(connection, locators) {
|
|
222
|
+
fencedWork(connection, locators);
|
|
252
223
|
for (const locator of locators) {
|
|
253
|
-
connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
|
|
254
|
-
roomWork(connection, locator);
|
|
255
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
|
|
256
224
|
connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
|
|
257
225
|
}
|
|
258
|
-
|
|
259
|
-
return
|
|
226
|
+
unopened(connection);
|
|
227
|
+
return fenceRooms(connection, locators);
|
|
260
228
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
|
|
264
|
-
}
|
|
265
|
-
return null;
|
|
229
|
+
function erased(connection, { locator, limit }) {
|
|
230
|
+
return erase(connection, locator, limit);
|
|
266
231
|
}
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
function claim(connection, holder) {
|
|
273
|
-
const held = fact(connection, 'holder');
|
|
274
|
-
if (held !== null)
|
|
275
|
-
return held === holder;
|
|
276
|
-
remember(connection, 'holder', holder);
|
|
277
|
-
return true;
|
|
232
|
+
function unfencedRooms(connection, locators) {
|
|
233
|
+
const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
|
|
234
|
+
.length === 0);
|
|
235
|
+
unfenced(connection, erased);
|
|
236
|
+
return erased;
|
|
278
237
|
}
|
|
279
238
|
function end(connection, holder) {
|
|
239
|
+
ended(connection);
|
|
240
|
+
forgottenConversations(connection);
|
|
241
|
+
forgottenRuns(connection);
|
|
280
242
|
if (holder !== null && claim(connection, holder))
|
|
281
243
|
return true;
|
|
282
|
-
|
|
283
|
-
connection.run(`DELETE FROM ${table}`);
|
|
244
|
+
authoredEmptied(connection);
|
|
284
245
|
connection.run('DELETE FROM opened_files');
|
|
285
|
-
connection.run('DELETE FROM
|
|
246
|
+
connection.run('DELETE FROM opened_parts');
|
|
286
247
|
return false;
|
|
287
248
|
}
|
|
288
|
-
function count(value) {
|
|
289
|
-
return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
|
|
290
|
-
}
|
|
291
249
|
function openedFile(connection, { locator, path, revision }) {
|
|
292
250
|
const [held] = connection.rows('SELECT key, media_type, byte_length FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NOT NULL', [locator, path, revision]);
|
|
293
251
|
return held === undefined
|
|
@@ -302,7 +260,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
|
|
|
302
260
|
if (fenced(connection, locator))
|
|
303
261
|
return false;
|
|
304
262
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
|
|
305
|
-
|
|
263
|
+
unopened(connection);
|
|
306
264
|
connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
|
|
307
265
|
return true;
|
|
308
266
|
}
|
|
@@ -315,22 +273,26 @@ function fetching(connection, key) {
|
|
|
315
273
|
function openedPart(connection, { key, part, bytes }) {
|
|
316
274
|
if (fetching(connection, key) === null)
|
|
317
275
|
return false;
|
|
318
|
-
|
|
276
|
+
connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
|
|
277
|
+
key,
|
|
278
|
+
part,
|
|
279
|
+
bytes,
|
|
280
|
+
]);
|
|
319
281
|
return true;
|
|
320
282
|
}
|
|
321
283
|
function dropped(connection, key) {
|
|
322
284
|
connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
|
|
323
|
-
connection.run('DELETE FROM
|
|
285
|
+
connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
|
|
324
286
|
return null;
|
|
325
287
|
}
|
|
326
288
|
function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
327
289
|
const fetched = fetching(connection, key);
|
|
328
290
|
if (fetched === null)
|
|
329
291
|
return false;
|
|
330
|
-
const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM
|
|
331
|
-
const whole = count(held
|
|
332
|
-
count(held
|
|
333
|
-
(parts === 0 || (count(held
|
|
292
|
+
const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts WHERE key = ?', [key]);
|
|
293
|
+
const whole = count(held.parts) === parts &&
|
|
294
|
+
count(held.bytes) === byteLength &&
|
|
295
|
+
(parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
|
|
334
296
|
if (!whole) {
|
|
335
297
|
dropped(connection, key);
|
|
336
298
|
return false;
|
|
@@ -341,53 +303,161 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
|
341
303
|
key,
|
|
342
304
|
]);
|
|
343
305
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
|
|
344
|
-
|
|
306
|
+
unopened(connection);
|
|
345
307
|
return true;
|
|
346
308
|
}
|
|
309
|
+
function heldPart(connection, key, part) {
|
|
310
|
+
const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
|
|
311
|
+
key,
|
|
312
|
+
part,
|
|
313
|
+
]);
|
|
314
|
+
return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
|
|
315
|
+
}
|
|
316
|
+
function cleanable(connection) {
|
|
317
|
+
const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
|
|
318
|
+
return count(held.bytes);
|
|
319
|
+
}
|
|
347
320
|
function cleaned(connection) {
|
|
348
321
|
connection.run('DELETE FROM opened_files');
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
return
|
|
322
|
+
const freed = cleanable(connection);
|
|
323
|
+
unopened(connection);
|
|
324
|
+
return freed;
|
|
325
|
+
}
|
|
326
|
+
function openedHeld(connection) {
|
|
327
|
+
return {
|
|
328
|
+
rooms: connection
|
|
329
|
+
.rows('SELECT locator, count(*) AS files, sum(byte_length) AS bytes FROM opened_files WHERE byte_length IS NOT NULL GROUP BY locator ORDER BY locator')
|
|
330
|
+
.map((row) => ({ room: text(row.locator), count: count(row.files), size: count(row.bytes) })),
|
|
331
|
+
cleanable: cleanable(connection),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
async function committed(connection, { authored, rooms }) {
|
|
335
|
+
const refused = authored === undefined ? null : await kept(connection, authored);
|
|
336
|
+
if (refused !== null && authored?.whole === true) {
|
|
337
|
+
return { fenced: refused, changed: {}, indexed: {} };
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
fenced: refused,
|
|
341
|
+
...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
|
|
342
|
+
};
|
|
352
343
|
}
|
|
353
344
|
export function answerRuntime(connection, request, spool) {
|
|
354
345
|
switch (request.kind) {
|
|
355
|
-
case 'authored.
|
|
356
|
-
return
|
|
346
|
+
case 'authored.status':
|
|
347
|
+
return status(connection);
|
|
348
|
+
case 'authored.moving':
|
|
349
|
+
return moving(connection);
|
|
350
|
+
case 'authored.pending':
|
|
351
|
+
return pendingOf(connection, request.locator, request.id);
|
|
352
|
+
case 'authored.batch':
|
|
353
|
+
return pendingBatch(connection, request.locator, request.id);
|
|
354
|
+
case 'authored.order':
|
|
355
|
+
return heldOrder(connection, request.locator);
|
|
356
|
+
case 'authored.queued':
|
|
357
|
+
return queuedLocators(connection);
|
|
357
358
|
case 'authored.roomDrafts':
|
|
358
|
-
return
|
|
359
|
+
return roomDraftRecords(connection, request.locator, request.paths);
|
|
360
|
+
case 'authored.chatDraft.read':
|
|
361
|
+
return chatDraftRecord(connection, request.conversation);
|
|
359
362
|
case 'authored.chatDrafts':
|
|
360
|
-
return
|
|
363
|
+
return chatDraftRecords(connection);
|
|
361
364
|
case 'authored.calls':
|
|
362
|
-
return
|
|
365
|
+
return callRecords(connection);
|
|
363
366
|
case 'authored.fences':
|
|
364
|
-
return
|
|
367
|
+
return fences(connection);
|
|
368
|
+
case 'authored.unsent':
|
|
369
|
+
return unsent(connection);
|
|
365
370
|
case 'authored.fact':
|
|
366
371
|
return fact(connection, request.name);
|
|
367
372
|
case 'authored.file':
|
|
368
|
-
return spooled(connection, spool, request);
|
|
369
|
-
case 'authored.keep':
|
|
370
|
-
return kept(connection, request);
|
|
373
|
+
return spooled(connection, spool, request.key, request.type);
|
|
371
374
|
case 'authored.amend':
|
|
372
|
-
return amended(connection, request);
|
|
375
|
+
return amended(connection, request.locator, request.id, request.amendment);
|
|
373
376
|
case 'authored.roomDraft':
|
|
374
|
-
return roomDraft(connection, request);
|
|
377
|
+
return roomDraft(connection, request.locator, request.path, request.kept, request.files);
|
|
375
378
|
case 'authored.chatDraft':
|
|
376
|
-
return chatDraft(connection, request);
|
|
379
|
+
return chatDraft(connection, request.kept, request.dropped);
|
|
377
380
|
case 'authored.call':
|
|
378
|
-
return call(connection, request);
|
|
379
|
-
case 'authored.fence':
|
|
380
|
-
return fence(connection, request.locators);
|
|
381
|
-
case 'authored.unfence':
|
|
382
|
-
return unfence(connection, request.locators);
|
|
383
|
-
case 'authored.discard':
|
|
384
|
-
return discard(connection, request.locator);
|
|
381
|
+
return call(connection, request.operation, request.kept, request.files);
|
|
385
382
|
case 'authored.remember':
|
|
386
383
|
return remember(connection, request.name, request.value);
|
|
387
384
|
case 'authored.claim':
|
|
388
385
|
return claim(connection, request.holder);
|
|
389
386
|
case 'authored.end':
|
|
390
387
|
return end(connection, request.holder);
|
|
388
|
+
case 'replica.open':
|
|
389
|
+
return opened(connection);
|
|
390
|
+
case 'replica.rooms':
|
|
391
|
+
return heldRooms(connection, request.locators);
|
|
392
|
+
case 'replica.room':
|
|
393
|
+
return heldWork(connection, request.locator);
|
|
394
|
+
case 'replica.covering':
|
|
395
|
+
return { ...covering(connection, request.since), queues: queues(connection) };
|
|
396
|
+
case 'replica.offline':
|
|
397
|
+
return offlineMode(connection, request.locator);
|
|
398
|
+
case 'replica.held':
|
|
399
|
+
return {
|
|
400
|
+
held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
|
|
401
|
+
staged: stagedLocators(connection),
|
|
402
|
+
};
|
|
403
|
+
case 'replica.demote':
|
|
404
|
+
return demoted(connection);
|
|
405
|
+
case 'replica.facts':
|
|
406
|
+
return facts(connection, request.names);
|
|
407
|
+
case 'replica.presentation':
|
|
408
|
+
return presentation(connection, request.app);
|
|
409
|
+
case 'replica.query':
|
|
410
|
+
return answerQuery(connection, request.plan, request.rooms, request.budget, request.follows);
|
|
411
|
+
case 'replica.named':
|
|
412
|
+
return namedHandles(connection, request.plan, request.rooms, request.handles);
|
|
413
|
+
case 'replica.tallies':
|
|
414
|
+
return roomTallies(connection, request.totals, request.rooms, request.since);
|
|
415
|
+
case 'replica.entries':
|
|
416
|
+
return entries(connection, request.key, request.view, request.paths);
|
|
417
|
+
case 'replica.typed':
|
|
418
|
+
return typed(connection, request.key, request.view, request.paths);
|
|
419
|
+
case 'replica.referrers':
|
|
420
|
+
return referrers(connection, request.key, request.view, request.targets);
|
|
421
|
+
case 'replica.holders':
|
|
422
|
+
return holders(connection, request.key, request.view, request.sought);
|
|
423
|
+
case 'replica.folders':
|
|
424
|
+
return folders(connection, request.key, request.paths);
|
|
425
|
+
case 'replica.typedWithin':
|
|
426
|
+
return typedWithin(connection, request.key, request.view, request.roots, request.within);
|
|
427
|
+
case 'replica.stage':
|
|
428
|
+
return fenced(connection, request.locator) ? null : stage(connection, request);
|
|
429
|
+
case 'replica.resume':
|
|
430
|
+
return fenced(connection, request.locator) ? null : resume(connection, request);
|
|
431
|
+
case 'replica.refresh':
|
|
432
|
+
return refreshing(connection, request);
|
|
433
|
+
case 'replica.unrefresh':
|
|
434
|
+
return unrefresh(connection, request.key);
|
|
435
|
+
case 'replica.commit':
|
|
436
|
+
return committed(connection, request);
|
|
437
|
+
case 'replica.fence':
|
|
438
|
+
return fence(connection, request.locators);
|
|
439
|
+
case 'replica.erase':
|
|
440
|
+
return erased(connection, request);
|
|
441
|
+
case 'replica.abandon':
|
|
442
|
+
return abandon(connection, request.locator);
|
|
443
|
+
case 'replica.unfence':
|
|
444
|
+
return unfencedRooms(connection, request.locators);
|
|
445
|
+
case 'replica.release':
|
|
446
|
+
return release(connection, request.key);
|
|
447
|
+
case 'replica.rederive':
|
|
448
|
+
return rederive(connection, request.key, request.composed, request.bytes, request.ms, request.floor);
|
|
449
|
+
case 'replica.fact':
|
|
450
|
+
connection.run('INSERT OR REPLACE INTO replica_facts (name, value) VALUES (?, ?)', [
|
|
451
|
+
request.name,
|
|
452
|
+
request.value,
|
|
453
|
+
]);
|
|
454
|
+
return null;
|
|
455
|
+
case 'replica.present':
|
|
456
|
+
connection.run('INSERT OR REPLACE INTO replica_presentation (app, value) VALUES (?, ?)', [
|
|
457
|
+
request.app,
|
|
458
|
+
request.value,
|
|
459
|
+
]);
|
|
460
|
+
return null;
|
|
391
461
|
case 'opened.find':
|
|
392
462
|
return openedFile(connection, request);
|
|
393
463
|
case 'opened.begin':
|
|
@@ -400,7 +470,51 @@ export function answerRuntime(connection, request, spool) {
|
|
|
400
470
|
return dropped(connection, request.key);
|
|
401
471
|
case 'opened.clean':
|
|
402
472
|
return cleaned(connection);
|
|
473
|
+
case 'opened.held':
|
|
474
|
+
return openedHeld(connection);
|
|
403
475
|
case 'file.part':
|
|
404
|
-
return
|
|
476
|
+
return heldPart(connection, request.key, request.part);
|
|
477
|
+
case 'conversation.held':
|
|
478
|
+
return heldConversations(connection, request.conversations);
|
|
479
|
+
case 'conversation.keep': {
|
|
480
|
+
const { kind: _kind, ...write } = request;
|
|
481
|
+
return keptMessages(connection, write);
|
|
482
|
+
}
|
|
483
|
+
case 'conversation.window':
|
|
484
|
+
return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
|
|
485
|
+
case 'conversation.count':
|
|
486
|
+
return messageCount(connection, request.conversation, request.phrase);
|
|
487
|
+
case 'conversation.turn':
|
|
488
|
+
return turnArrived(connection, request.conversation, request.turn);
|
|
489
|
+
case 'conversation.rows':
|
|
490
|
+
return conversationRows(connection, request.conversations);
|
|
491
|
+
case 'conversation.tallies':
|
|
492
|
+
return conversationTallies(connection, request.conversations, request.since);
|
|
493
|
+
case 'conversation.facts':
|
|
494
|
+
return conversationFacts(connection);
|
|
495
|
+
case 'conversation.fact': {
|
|
496
|
+
const { kind: _kind, ...fact } = request;
|
|
497
|
+
return keptFact(connection, fact);
|
|
498
|
+
}
|
|
499
|
+
case 'conversation.stored':
|
|
500
|
+
return storedConversations(connection, null);
|
|
501
|
+
case 'conversation.drop':
|
|
502
|
+
return droppedConversations(connection, request.conversations);
|
|
503
|
+
case 'space.probe':
|
|
504
|
+
return spool.probe(PROBE_BYTES).then(() => null);
|
|
505
|
+
case 'read.stored':
|
|
506
|
+
return storedRead(connection, request);
|
|
507
|
+
case 'read.keep':
|
|
508
|
+
return keptRead(connection, request, request.answer);
|
|
509
|
+
case 'read.builds':
|
|
510
|
+
return readsOfOtherBuildsForgotten(connection, request.build);
|
|
511
|
+
case 'run.marks':
|
|
512
|
+
return runMarks(connection);
|
|
513
|
+
case 'run.held':
|
|
514
|
+
return heldRuns(connection, request.asked, request.sight);
|
|
515
|
+
case 'run.keep':
|
|
516
|
+
return keptRuns(connection, request.event);
|
|
517
|
+
case 'run.left':
|
|
518
|
+
return runsLeft(connection, request.sight);
|
|
405
519
|
}
|
|
406
520
|
}
|