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