@agentshouse/mdruntime 0.1.0-ccfc6404645a9 → 0.1.0-cd03d062ce447
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 +341 -0
- package/dist/adapter.d.ts +304 -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 -4
- 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 +17 -16
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +269 -158
- 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 +3 -2
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- 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 +52 -29
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +65 -28
- package/dist/collection.d.ts +33 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +50 -21
- 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 +10 -7
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +349 -315
- package/dist/connection.d.ts +6 -141
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +119 -4989
- 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 -55
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1030 -838
- 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 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +29 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +134 -34
- 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 +155 -59
- 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 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -4
- 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/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +23 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +138 -38
- 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 +21 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +299 -110
- package/dist/messages.d.ts +44 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +129 -39
- 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 +31 -13
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +219 -82
- 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 -15
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +52 -5
- package/dist/overlay.d.ts +24 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +143 -48
- 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 +20 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- 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 -13
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +382 -135
- 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 +26 -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 -85
- 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 +10 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +92 -34
- 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 +13 -25
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +71 -40
- 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 +28 -18
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -160
- 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 +37 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +43 -84
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +342 -232
- 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 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- 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 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- 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 +114 -157
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +174 -400
- package/dist/stored.d.ts +96 -60
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +531 -291
- 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 +161 -105
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +272 -332
- 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/validation.d.ts +5 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +87 -105
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +92 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +38 -14
- package/package.json +13 -19
- package/AGENTS.md +0 -317
- 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 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -229
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -254
- package/dist/chat/messages.d.ts +0 -35
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -210
- 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 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- 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 -307
- 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/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/tables.js
CHANGED
|
@@ -1,15 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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;
|
|
5
12
|
export function sqliteConnection(engine, database) {
|
|
6
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
|
+
}
|
|
7
44
|
return {
|
|
8
45
|
run(sql, bind = []) {
|
|
9
|
-
|
|
46
|
+
const statement = prepared(sql);
|
|
47
|
+
if (statement === null)
|
|
48
|
+
database.exec({ sql, bind });
|
|
49
|
+
else
|
|
50
|
+
stepped(statement, bind, () => { });
|
|
10
51
|
},
|
|
11
52
|
rows(sql, bind = []) {
|
|
12
|
-
|
|
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;
|
|
13
67
|
},
|
|
14
68
|
collate(name, compare) {
|
|
15
69
|
const answered = engine.capi.sqlite3_create_collation_v2(database.pointer, name, engine.capi.SQLITE_UTF8, 0, (_argument, leftLength, left, rightLength, right) => {
|
|
@@ -21,62 +75,63 @@ export function sqliteConnection(engine, database) {
|
|
|
21
75
|
},
|
|
22
76
|
};
|
|
23
77
|
}
|
|
24
|
-
export const FILE_PART_BYTES = 1_048_576;
|
|
25
78
|
const PROBE_BYTES = 4 * FILE_PART_BYTES;
|
|
26
|
-
const TABLES = [
|
|
27
|
-
['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
|
|
28
|
-
['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
|
|
29
|
-
[
|
|
30
|
-
'authored_pending',
|
|
31
|
-
'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, id)',
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
'authored_room_drafts',
|
|
35
|
-
'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
|
|
36
|
-
],
|
|
37
|
-
['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
|
|
38
|
-
['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
|
|
39
|
-
['authored_fences', 'locator TEXT PRIMARY KEY'],
|
|
40
|
-
];
|
|
41
79
|
export const RUNTIME_TABLES = [
|
|
42
|
-
...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
|
|
43
|
-
'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
|
|
44
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',
|
|
45
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))',
|
|
46
83
|
...REPLICA_TABLES,
|
|
47
84
|
...MESSAGE_TABLES,
|
|
48
|
-
...
|
|
85
|
+
...READ_TABLES,
|
|
86
|
+
...RUN_TABLES,
|
|
49
87
|
];
|
|
50
|
-
const
|
|
51
|
-
const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
|
|
52
|
-
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)';
|
|
53
89
|
const READS = new Set([
|
|
54
|
-
'authored.
|
|
90
|
+
'authored.status',
|
|
91
|
+
'authored.moving',
|
|
92
|
+
'authored.pending',
|
|
93
|
+
'authored.batch',
|
|
94
|
+
'authored.order',
|
|
95
|
+
'authored.queued',
|
|
55
96
|
'authored.roomDrafts',
|
|
97
|
+
'authored.chatDraft.read',
|
|
56
98
|
'authored.chatDrafts',
|
|
57
99
|
'authored.calls',
|
|
58
100
|
'authored.fences',
|
|
101
|
+
'authored.unsent',
|
|
59
102
|
'authored.fact',
|
|
60
103
|
'authored.file',
|
|
61
104
|
'replica.open',
|
|
105
|
+
'replica.rooms',
|
|
106
|
+
'replica.room',
|
|
107
|
+
'replica.covering',
|
|
108
|
+
'replica.offline',
|
|
109
|
+
'replica.held',
|
|
110
|
+
'replica.facts',
|
|
111
|
+
'replica.presentation',
|
|
62
112
|
'replica.query',
|
|
113
|
+
'replica.named',
|
|
114
|
+
'replica.tallies',
|
|
63
115
|
'replica.entries',
|
|
64
116
|
'replica.typed',
|
|
65
117
|
'replica.referrers',
|
|
66
|
-
'replica.
|
|
67
|
-
'replica.
|
|
118
|
+
'replica.holders',
|
|
119
|
+
'replica.folders',
|
|
68
120
|
'replica.typedWithin',
|
|
69
|
-
'replica.counts',
|
|
70
|
-
'replica.search',
|
|
71
|
-
'replica.received',
|
|
72
|
-
'replica.receivedParts',
|
|
73
|
-
'replica.transferPart',
|
|
74
121
|
'opened.find',
|
|
122
|
+
'opened.held',
|
|
75
123
|
'file.part',
|
|
76
124
|
'conversation.held',
|
|
77
125
|
'conversation.window',
|
|
78
126
|
'conversation.count',
|
|
79
127
|
'conversation.turn',
|
|
128
|
+
'conversation.rows',
|
|
129
|
+
'conversation.tallies',
|
|
130
|
+
'conversation.facts',
|
|
131
|
+
'conversation.stored',
|
|
132
|
+
'read.stored',
|
|
133
|
+
'run.marks',
|
|
134
|
+
'run.held',
|
|
80
135
|
]);
|
|
81
136
|
const KINDS = new Set([
|
|
82
137
|
...READS,
|
|
@@ -88,27 +143,32 @@ const KINDS = new Set([
|
|
|
88
143
|
'authored.claim',
|
|
89
144
|
'authored.end',
|
|
90
145
|
'replica.stage',
|
|
91
|
-
'replica.
|
|
146
|
+
'replica.resume',
|
|
92
147
|
'replica.refresh',
|
|
93
148
|
'replica.unrefresh',
|
|
94
149
|
'replica.commit',
|
|
95
150
|
'replica.fence',
|
|
96
151
|
'replica.erase',
|
|
97
152
|
'replica.abandon',
|
|
153
|
+
'replica.unfence',
|
|
98
154
|
'replica.release',
|
|
99
155
|
'replica.rederive',
|
|
156
|
+
'replica.demote',
|
|
100
157
|
'replica.fact',
|
|
101
158
|
'replica.present',
|
|
102
|
-
'replica.receive',
|
|
103
|
-
'replica.unreceive',
|
|
104
159
|
'opened.begin',
|
|
105
160
|
'opened.part',
|
|
106
161
|
'opened.keep',
|
|
107
162
|
'opened.drop',
|
|
108
163
|
'opened.clean',
|
|
109
164
|
'conversation.keep',
|
|
165
|
+
'conversation.fact',
|
|
110
166
|
'conversation.drop',
|
|
111
167
|
'space.probe',
|
|
168
|
+
'read.keep',
|
|
169
|
+
'read.builds',
|
|
170
|
+
'run.keep',
|
|
171
|
+
'run.left',
|
|
112
172
|
]);
|
|
113
173
|
export function isRuntime(request) {
|
|
114
174
|
return KINDS.has(request.kind);
|
|
@@ -116,239 +176,76 @@ export function isRuntime(request) {
|
|
|
116
176
|
export function readsRuntime(request) {
|
|
117
177
|
return READS.has(request.kind);
|
|
118
178
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
function texts(rows, column) {
|
|
123
|
-
return rows.map((row) => text(row[column]));
|
|
124
|
-
}
|
|
125
|
-
function owned(files) {
|
|
126
|
-
return JSON.stringify([...new Set(files)]);
|
|
127
|
-
}
|
|
128
|
-
function fact(connection, name) {
|
|
129
|
-
const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
|
|
130
|
-
return held === undefined ? null : text(held.value);
|
|
131
|
-
}
|
|
132
|
-
function remember(connection, name, value) {
|
|
133
|
-
connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
|
|
134
|
-
name,
|
|
135
|
-
value,
|
|
136
|
-
]);
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
function fenced(connection, locator) {
|
|
140
|
-
return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
|
|
141
|
-
}
|
|
142
|
-
function stored(connection, key) {
|
|
143
|
-
return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
|
|
144
|
-
}
|
|
145
|
-
function storedPart(connection, key, part, bytes) {
|
|
146
|
-
connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
|
|
147
|
-
}
|
|
148
|
-
async function storedFiles(connection, files) {
|
|
149
|
-
for (const { key, blob } of files) {
|
|
150
|
-
if (stored(connection, key))
|
|
151
|
-
continue;
|
|
152
|
-
for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
|
|
153
|
-
const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
|
|
154
|
-
storedPart(connection, key, part, bytes);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function filePart(connection, key, part) {
|
|
159
|
-
const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
|
|
160
|
-
key,
|
|
161
|
-
part,
|
|
162
|
-
]);
|
|
163
|
-
return held?.bytes instanceof Uint8Array ? held.bytes : null;
|
|
164
|
-
}
|
|
165
|
-
function* fileParts(connection, key) {
|
|
166
|
-
for (let part = 0;; part += 1) {
|
|
167
|
-
const bytes = filePart(connection, key, part);
|
|
168
|
-
if (bytes === null)
|
|
169
|
-
return;
|
|
170
|
-
yield bytes;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async function spooled(connection, spool, { key, type }) {
|
|
174
|
-
for (const held of [...spool.held()]) {
|
|
175
|
-
if (held !== key && !stored(connection, held))
|
|
176
|
-
await spool.drop(held);
|
|
177
|
-
}
|
|
178
|
-
return spool.spool(key, type, fileParts(connection, key));
|
|
179
|
-
}
|
|
180
|
-
function unowned(connection) {
|
|
181
|
-
connection.run(UNOWNED_PARTS);
|
|
182
|
-
}
|
|
183
|
-
function queued(connection) {
|
|
179
|
+
function heldWork(connection, locator) {
|
|
180
|
+
const room = heldRoom(connection, locator);
|
|
184
181
|
return {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ids: JSON.parse(text(row.ids)),
|
|
188
|
-
})),
|
|
189
|
-
pending: connection
|
|
190
|
-
.rows('SELECT locator, id, batch, state FROM authored_pending')
|
|
191
|
-
.map((row) => ({
|
|
192
|
-
locator: text(row.locator),
|
|
193
|
-
id: text(row.id),
|
|
194
|
-
batch: text(row.batch),
|
|
195
|
-
state: text(row.state),
|
|
196
|
-
})),
|
|
182
|
+
room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
|
|
183
|
+
queue: queueOf(connection, locator),
|
|
197
184
|
};
|
|
198
185
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
for (const { id, amendment } of amendments ?? []) {
|
|
205
|
-
amended(connection, { kind: 'authored.amend', locator, id, amendment });
|
|
206
|
-
}
|
|
207
|
-
for (const path of consumedRoomDrafts ?? []) {
|
|
208
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
|
|
209
|
-
locator,
|
|
210
|
-
path,
|
|
211
|
-
]);
|
|
212
|
-
}
|
|
213
|
-
for (const { path, record, files } of roomDrafts ?? []) {
|
|
214
|
-
connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
|
|
215
|
-
}
|
|
216
|
-
if (order === undefined)
|
|
217
|
-
return;
|
|
218
|
-
const before = new Set(heldOrder(connection, locator));
|
|
219
|
-
const after = new Set(order);
|
|
220
|
-
if (after.size === 0)
|
|
221
|
-
connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
|
|
222
|
-
else {
|
|
223
|
-
connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
|
|
224
|
-
locator,
|
|
225
|
-
JSON.stringify([...after]),
|
|
226
|
-
]);
|
|
227
|
-
}
|
|
228
|
-
for (const id of before) {
|
|
229
|
-
if (!after.has(id)) {
|
|
230
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
for (const { id, batch, state, files } of added ?? []) {
|
|
234
|
-
if (before.has(id) || !after.has(id))
|
|
235
|
-
continue;
|
|
236
|
-
connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files) VALUES (?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files)]);
|
|
237
|
-
}
|
|
238
|
-
for (const { id, batch, files } of founded ?? []) {
|
|
239
|
-
const [held] = connection.rows('SELECT files FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
240
|
-
if (held === undefined || !before.has(id))
|
|
241
|
-
continue;
|
|
242
|
-
connection.run('UPDATE authored_pending SET batch = ?, files = ? WHERE locator = ? AND id = ?', [batch, owned([...JSON.parse(text(held.files)), ...files]), locator, id]);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async function kept(connection, { writes, files, whole, discards }) {
|
|
246
|
-
const refused = writes.find(({ locator }) => fenced(connection, locator));
|
|
247
|
-
if (refused !== undefined && whole)
|
|
248
|
-
return refused.locator;
|
|
249
|
-
await storedFiles(connection, files);
|
|
250
|
-
for (const write of writes) {
|
|
251
|
-
if (!fenced(connection, write.locator))
|
|
252
|
-
keptRows(connection, write);
|
|
253
|
-
}
|
|
254
|
-
for (const locator of discards ?? [])
|
|
255
|
-
roomWork(connection, locator);
|
|
256
|
-
unowned(connection);
|
|
257
|
-
return refused?.locator ?? null;
|
|
186
|
+
function status(connection) {
|
|
187
|
+
return {
|
|
188
|
+
...unsentStatus(connection),
|
|
189
|
+
lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
|
|
190
|
+
};
|
|
258
191
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return null;
|
|
265
|
-
connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
|
|
266
|
-
JSON.stringify({
|
|
267
|
-
...JSON.parse(text(held.state)),
|
|
268
|
-
...JSON.parse(amendment),
|
|
269
|
-
}),
|
|
270
|
-
locator,
|
|
271
|
-
id,
|
|
272
|
-
]);
|
|
273
|
-
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
|
+
};
|
|
274
197
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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),
|
|
283
213
|
]);
|
|
284
214
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
unowned(connection);
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
function chatDraft(connection, { kept: drafts, dropped }) {
|
|
292
|
-
for (const conversation of dropped) {
|
|
293
|
-
connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
|
|
294
|
-
}
|
|
295
|
-
for (const { conversation, record } of drafts) {
|
|
296
|
-
connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
|
|
297
|
-
}
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
async function call(connection, { operation, kept: held, files }) {
|
|
301
|
-
await storedFiles(connection, files);
|
|
302
|
-
if (held === null)
|
|
303
|
-
connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
|
|
304
|
-
else {
|
|
305
|
-
connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
|
|
306
|
-
}
|
|
307
|
-
unowned(connection);
|
|
308
|
-
return null;
|
|
215
|
+
chatDraftsDropped(connection, conversations);
|
|
216
|
+
return held;
|
|
309
217
|
}
|
|
310
|
-
function
|
|
311
|
-
connection.run(
|
|
312
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
|
|
218
|
+
function unopened(connection) {
|
|
219
|
+
connection.run(UNOPENED_PARTS);
|
|
313
220
|
}
|
|
314
221
|
function fence(connection, locators) {
|
|
222
|
+
fencedWork(connection, locators);
|
|
315
223
|
for (const locator of locators) {
|
|
316
|
-
connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
|
|
317
|
-
roomWork(connection, locator);
|
|
318
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
|
|
319
224
|
connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
|
|
320
225
|
}
|
|
321
|
-
|
|
226
|
+
unopened(connection);
|
|
322
227
|
return fenceRooms(connection, locators);
|
|
323
228
|
}
|
|
324
229
|
function erased(connection, { locator, limit }) {
|
|
325
|
-
|
|
326
|
-
if (locator !== null && !done.remaining) {
|
|
327
|
-
connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
|
|
328
|
-
}
|
|
329
|
-
return done;
|
|
230
|
+
return erase(connection, locator, limit);
|
|
330
231
|
}
|
|
331
|
-
function
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
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;
|
|
337
237
|
}
|
|
338
238
|
function end(connection, holder) {
|
|
339
239
|
ended(connection);
|
|
340
|
-
|
|
240
|
+
forgottenConversations(connection);
|
|
241
|
+
forgottenRuns(connection);
|
|
341
242
|
if (holder !== null && claim(connection, holder))
|
|
342
243
|
return true;
|
|
343
|
-
|
|
344
|
-
connection.run(`DELETE FROM ${table}`);
|
|
244
|
+
authoredEmptied(connection);
|
|
345
245
|
connection.run('DELETE FROM opened_files');
|
|
346
|
-
connection.run('DELETE FROM
|
|
246
|
+
connection.run('DELETE FROM opened_parts');
|
|
347
247
|
return false;
|
|
348
248
|
}
|
|
349
|
-
function count(value) {
|
|
350
|
-
return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
|
|
351
|
-
}
|
|
352
249
|
function openedFile(connection, { locator, path, revision }) {
|
|
353
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]);
|
|
354
251
|
return held === undefined
|
|
@@ -363,7 +260,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
|
|
|
363
260
|
if (fenced(connection, locator))
|
|
364
261
|
return false;
|
|
365
262
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
|
|
366
|
-
|
|
263
|
+
unopened(connection);
|
|
367
264
|
connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
|
|
368
265
|
return true;
|
|
369
266
|
}
|
|
@@ -376,22 +273,26 @@ function fetching(connection, key) {
|
|
|
376
273
|
function openedPart(connection, { key, part, bytes }) {
|
|
377
274
|
if (fetching(connection, key) === null)
|
|
378
275
|
return false;
|
|
379
|
-
|
|
276
|
+
connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
|
|
277
|
+
key,
|
|
278
|
+
part,
|
|
279
|
+
bytes,
|
|
280
|
+
]);
|
|
380
281
|
return true;
|
|
381
282
|
}
|
|
382
283
|
function dropped(connection, key) {
|
|
383
284
|
connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
|
|
384
|
-
connection.run('DELETE FROM
|
|
285
|
+
connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
|
|
385
286
|
return null;
|
|
386
287
|
}
|
|
387
288
|
function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
388
289
|
const fetched = fetching(connection, key);
|
|
389
290
|
if (fetched === null)
|
|
390
291
|
return false;
|
|
391
|
-
const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM
|
|
392
|
-
const whole = count(held
|
|
393
|
-
count(held
|
|
394
|
-
(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));
|
|
395
296
|
if (!whole) {
|
|
396
297
|
dropped(connection, key);
|
|
397
298
|
return false;
|
|
@@ -402,71 +303,82 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
|
402
303
|
key,
|
|
403
304
|
]);
|
|
404
305
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
|
|
405
|
-
|
|
306
|
+
unopened(connection);
|
|
406
307
|
return true;
|
|
407
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
|
+
}
|
|
408
320
|
function cleaned(connection) {
|
|
409
321
|
connection.run('DELETE FROM opened_files');
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
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
|
+
};
|
|
413
333
|
}
|
|
414
334
|
async function committed(connection, { authored, rooms }) {
|
|
415
335
|
const refused = authored === undefined ? null : await kept(connection, authored);
|
|
416
336
|
if (refused !== null && authored?.whole === true) {
|
|
417
|
-
return { fenced: refused,
|
|
337
|
+
return { fenced: refused, changed: {}, indexed: {} };
|
|
418
338
|
}
|
|
419
339
|
return {
|
|
420
340
|
fenced: refused,
|
|
421
341
|
...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
|
|
422
342
|
};
|
|
423
343
|
}
|
|
424
|
-
function receivedParts(connection, key, count) {
|
|
425
|
-
return connection
|
|
426
|
-
.rows('SELECT value FROM replica_received_parts WHERE key = ? AND part < ? ORDER BY part', [
|
|
427
|
-
key,
|
|
428
|
-
count,
|
|
429
|
-
])
|
|
430
|
-
.map((row) => JSON.parse(text(row.value)));
|
|
431
|
-
}
|
|
432
|
-
function receive(connection, { key, head, part }) {
|
|
433
|
-
connection.run('INSERT OR REPLACE INTO replica_received (key, head) VALUES (?, ?)', [key, head]);
|
|
434
|
-
if (part !== undefined) {
|
|
435
|
-
connection.run('INSERT OR REPLACE INTO replica_received_parts (key, part, value) VALUES (?, ?, ?)', [key, part.index, part.value]);
|
|
436
|
-
}
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
function unreceive(connection, keys) {
|
|
440
|
-
for (const key of keys) {
|
|
441
|
-
connection.run('DELETE FROM replica_received WHERE key = ?', [key]);
|
|
442
|
-
connection.run('DELETE FROM replica_received_parts WHERE key = ?', [key]);
|
|
443
|
-
}
|
|
444
|
-
return null;
|
|
445
|
-
}
|
|
446
344
|
export function answerRuntime(connection, request, spool) {
|
|
447
345
|
switch (request.kind) {
|
|
448
|
-
case 'authored.
|
|
449
|
-
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);
|
|
450
358
|
case 'authored.roomDrafts':
|
|
451
|
-
return
|
|
359
|
+
return roomDraftRecords(connection, request.locator, request.paths);
|
|
360
|
+
case 'authored.chatDraft.read':
|
|
361
|
+
return chatDraftRecord(connection, request.conversation);
|
|
452
362
|
case 'authored.chatDrafts':
|
|
453
|
-
return
|
|
363
|
+
return chatDraftRecords(connection);
|
|
454
364
|
case 'authored.calls':
|
|
455
|
-
return
|
|
365
|
+
return callRecords(connection);
|
|
456
366
|
case 'authored.fences':
|
|
457
|
-
return
|
|
367
|
+
return fences(connection);
|
|
368
|
+
case 'authored.unsent':
|
|
369
|
+
return unsent(connection);
|
|
458
370
|
case 'authored.fact':
|
|
459
371
|
return fact(connection, request.name);
|
|
460
372
|
case 'authored.file':
|
|
461
|
-
return spooled(connection, spool, request);
|
|
373
|
+
return spooled(connection, spool, request.key, request.type);
|
|
462
374
|
case 'authored.amend':
|
|
463
|
-
return amended(connection, request);
|
|
375
|
+
return amended(connection, request.locator, request.id, request.amendment);
|
|
464
376
|
case 'authored.roomDraft':
|
|
465
|
-
return roomDraft(connection, request);
|
|
377
|
+
return roomDraft(connection, request.locator, request.path, request.kept, request.files);
|
|
466
378
|
case 'authored.chatDraft':
|
|
467
|
-
return chatDraft(connection, request);
|
|
379
|
+
return chatDraft(connection, request.kept, request.dropped);
|
|
468
380
|
case 'authored.call':
|
|
469
|
-
return call(connection, request);
|
|
381
|
+
return call(connection, request.operation, request.kept, request.files);
|
|
470
382
|
case 'authored.remember':
|
|
471
383
|
return remember(connection, request.name, request.value);
|
|
472
384
|
case 'authored.claim':
|
|
@@ -475,39 +387,47 @@ export function answerRuntime(connection, request, spool) {
|
|
|
475
387
|
return end(connection, request.holder);
|
|
476
388
|
case 'replica.open':
|
|
477
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);
|
|
478
409
|
case 'replica.query':
|
|
479
|
-
return answerQuery(connection, request.plan, request.rooms, request.budget);
|
|
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);
|
|
480
415
|
case 'replica.entries':
|
|
481
416
|
return entries(connection, request.key, request.view, request.paths);
|
|
482
417
|
case 'replica.typed':
|
|
483
418
|
return typed(connection, request.key, request.view, request.paths);
|
|
484
419
|
case 'replica.referrers':
|
|
485
|
-
return referrers(connection, request.key, request.view, request.targets
|
|
486
|
-
case 'replica.
|
|
487
|
-
return
|
|
488
|
-
case 'replica.
|
|
489
|
-
return
|
|
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);
|
|
490
425
|
case 'replica.typedWithin':
|
|
491
426
|
return typedWithin(connection, request.key, request.view, request.roots, request.within);
|
|
492
|
-
case 'replica.counts':
|
|
493
|
-
return counts(connection, request.rooms);
|
|
494
|
-
case 'replica.search': {
|
|
495
|
-
const { kind: _kind, ...ask } = request;
|
|
496
|
-
return searched(connection, ask);
|
|
497
|
-
}
|
|
498
|
-
case 'replica.received':
|
|
499
|
-
return connection.rows('SELECT key, head FROM replica_received').map((row) => ({
|
|
500
|
-
key: text(row.key),
|
|
501
|
-
head: JSON.parse(text(row.head)),
|
|
502
|
-
}));
|
|
503
|
-
case 'replica.receivedParts':
|
|
504
|
-
return receivedParts(connection, request.key, request.count);
|
|
505
427
|
case 'replica.stage':
|
|
506
428
|
return fenced(connection, request.locator) ? null : stage(connection, request);
|
|
507
|
-
case 'replica.
|
|
508
|
-
return
|
|
509
|
-
case 'replica.keepPart':
|
|
510
|
-
return fenced(connection, request.locator) ? null : keepPart(connection, request);
|
|
429
|
+
case 'replica.resume':
|
|
430
|
+
return fenced(connection, request.locator) ? null : resume(connection, request);
|
|
511
431
|
case 'replica.refresh':
|
|
512
432
|
return refreshing(connection, request);
|
|
513
433
|
case 'replica.unrefresh':
|
|
@@ -519,11 +439,13 @@ export function answerRuntime(connection, request, spool) {
|
|
|
519
439
|
case 'replica.erase':
|
|
520
440
|
return erased(connection, request);
|
|
521
441
|
case 'replica.abandon':
|
|
522
|
-
return abandon(connection, request.locator
|
|
442
|
+
return abandon(connection, request.locator);
|
|
443
|
+
case 'replica.unfence':
|
|
444
|
+
return unfencedRooms(connection, request.locators);
|
|
523
445
|
case 'replica.release':
|
|
524
446
|
return release(connection, request.key);
|
|
525
447
|
case 'replica.rederive':
|
|
526
|
-
return rederive(connection, request.key, request.
|
|
448
|
+
return rederive(connection, request.key, request.composed, request.bytes, request.ms, request.floor);
|
|
527
449
|
case 'replica.fact':
|
|
528
450
|
connection.run('INSERT OR REPLACE INTO replica_facts (name, value) VALUES (?, ?)', [
|
|
529
451
|
request.name,
|
|
@@ -536,10 +458,6 @@ export function answerRuntime(connection, request, spool) {
|
|
|
536
458
|
request.value,
|
|
537
459
|
]);
|
|
538
460
|
return null;
|
|
539
|
-
case 'replica.receive':
|
|
540
|
-
return receive(connection, request);
|
|
541
|
-
case 'replica.unreceive':
|
|
542
|
-
return unreceive(connection, request.keys);
|
|
543
461
|
case 'opened.find':
|
|
544
462
|
return openedFile(connection, request);
|
|
545
463
|
case 'opened.begin':
|
|
@@ -552,29 +470,51 @@ export function answerRuntime(connection, request, spool) {
|
|
|
552
470
|
return dropped(connection, request.key);
|
|
553
471
|
case 'opened.clean':
|
|
554
472
|
return cleaned(connection);
|
|
473
|
+
case 'opened.held':
|
|
474
|
+
return openedHeld(connection);
|
|
555
475
|
case 'file.part':
|
|
556
|
-
return
|
|
476
|
+
return heldPart(connection, request.key, request.part);
|
|
557
477
|
case 'conversation.held':
|
|
558
|
-
return heldConversations(connection);
|
|
478
|
+
return heldConversations(connection, request.conversations);
|
|
559
479
|
case 'conversation.keep': {
|
|
560
480
|
const { kind: _kind, ...write } = request;
|
|
561
481
|
return keptMessages(connection, write);
|
|
562
482
|
}
|
|
563
483
|
case 'conversation.window':
|
|
564
|
-
return messageWindow(connection, request.conversation, request.limit, request.before);
|
|
484
|
+
return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
|
|
565
485
|
case 'conversation.count':
|
|
566
|
-
return messageCount(connection, request.conversation);
|
|
486
|
+
return messageCount(connection, request.conversation, request.phrase);
|
|
567
487
|
case 'conversation.turn':
|
|
568
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);
|
|
569
501
|
case 'conversation.drop':
|
|
570
|
-
|
|
571
|
-
kind: 'authored.chatDraft',
|
|
572
|
-
kept: [],
|
|
573
|
-
dropped: request.conversations,
|
|
574
|
-
});
|
|
575
|
-
droppedMessages(connection, request.conversations);
|
|
576
|
-
return null;
|
|
502
|
+
return droppedConversations(connection, request.conversations);
|
|
577
503
|
case 'space.probe':
|
|
578
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);
|
|
579
519
|
}
|
|
580
520
|
}
|