@agentshouse/mdruntime 0.1.0-cfe148b32e3d8 → 0.1.0-cfe9798bf3c30
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 +279 -121
- 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 +347 -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 +117 -5016
- 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 +52 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +76 -0
- package/dist/conversation.d.ts +83 -54
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1044 -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 +28 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +120 -33
- 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 +6 -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 +480 -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/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- 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 -17
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +64 -159
- 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 +463 -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 +326 -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 +72 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +116 -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 +163 -104
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +277 -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,70 @@
|
|
|
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 { kindedRevision } from './reference-forms.js';
|
|
11
|
+
export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
|
|
12
|
+
const STATEMENTS_HELD = 256;
|
|
5
13
|
export function sqliteConnection(engine, database) {
|
|
6
14
|
const decoder = new TextDecoder();
|
|
15
|
+
const held = new Map();
|
|
16
|
+
database.createFunction(sql.HOLDS_PHRASE, sql.holdsPhrase, {
|
|
17
|
+
arity: 2,
|
|
18
|
+
deterministic: true,
|
|
19
|
+
});
|
|
20
|
+
function prepared(sql) {
|
|
21
|
+
if (sql.includes(';'))
|
|
22
|
+
return null;
|
|
23
|
+
const found = held.get(sql);
|
|
24
|
+
held.delete(sql);
|
|
25
|
+
const statement = found ?? database.prepare(sql);
|
|
26
|
+
held.set(sql, statement);
|
|
27
|
+
if (held.size > STATEMENTS_HELD) {
|
|
28
|
+
const [oldest, evicted] = held.entries().next().value;
|
|
29
|
+
held.delete(oldest);
|
|
30
|
+
evicted.finalize();
|
|
31
|
+
}
|
|
32
|
+
return statement;
|
|
33
|
+
}
|
|
34
|
+
function stepped(statement, bind, each) {
|
|
35
|
+
try {
|
|
36
|
+
if (bind.length > 0 && statement.parameterCount > 0)
|
|
37
|
+
statement.bind(bind);
|
|
38
|
+
while (statement.step())
|
|
39
|
+
each();
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
statement.resetNoThrow(true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
7
45
|
return {
|
|
8
46
|
run(sql, bind = []) {
|
|
9
|
-
|
|
47
|
+
const statement = prepared(sql);
|
|
48
|
+
if (statement === null)
|
|
49
|
+
database.exec({ sql, bind });
|
|
50
|
+
else
|
|
51
|
+
stepped(statement, bind, () => { });
|
|
10
52
|
},
|
|
11
53
|
rows(sql, bind = []) {
|
|
12
|
-
|
|
54
|
+
const statement = prepared(sql);
|
|
55
|
+
if (statement === null) {
|
|
56
|
+
return database.exec({ sql, bind, rowMode: 'object', returnValue: 'resultRows' });
|
|
57
|
+
}
|
|
58
|
+
const names = statement.getColumnNames([]);
|
|
59
|
+
const rows = [];
|
|
60
|
+
stepped(statement, bind, () => {
|
|
61
|
+
const values = statement.get([]);
|
|
62
|
+
const row = Object.create(null);
|
|
63
|
+
for (const [index, name] of names.entries())
|
|
64
|
+
row[name] = values[index] ?? null;
|
|
65
|
+
rows.push(row);
|
|
66
|
+
});
|
|
67
|
+
return rows;
|
|
13
68
|
},
|
|
14
69
|
collate(name, compare) {
|
|
15
70
|
const answered = engine.capi.sqlite3_create_collation_v2(database.pointer, name, engine.capi.SQLITE_UTF8, 0, (_argument, leftLength, left, rightLength, right) => {
|
|
@@ -21,61 +76,63 @@ export function sqliteConnection(engine, database) {
|
|
|
21
76
|
},
|
|
22
77
|
};
|
|
23
78
|
}
|
|
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
|
-
];
|
|
79
|
+
const PROBE_BYTES = 4 * FILE_PART_BYTES;
|
|
40
80
|
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
81
|
'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
82
|
'CREATE INDEX opened_files_name ON opened_files (locator, path, revision)',
|
|
83
|
+
'CREATE TABLE opened_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
|
|
45
84
|
...REPLICA_TABLES,
|
|
46
85
|
...MESSAGE_TABLES,
|
|
47
|
-
...
|
|
86
|
+
...READ_TABLES,
|
|
87
|
+
...RUN_TABLES,
|
|
48
88
|
];
|
|
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)`;
|
|
89
|
+
const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
|
|
52
90
|
const READS = new Set([
|
|
53
|
-
'authored.
|
|
91
|
+
'authored.status',
|
|
92
|
+
'authored.moving',
|
|
93
|
+
'authored.pending',
|
|
94
|
+
'authored.batch',
|
|
95
|
+
'authored.order',
|
|
96
|
+
'authored.queued',
|
|
54
97
|
'authored.roomDrafts',
|
|
98
|
+
'authored.chatDraft.read',
|
|
55
99
|
'authored.chatDrafts',
|
|
56
100
|
'authored.calls',
|
|
57
101
|
'authored.fences',
|
|
102
|
+
'authored.unsent',
|
|
58
103
|
'authored.fact',
|
|
59
104
|
'authored.file',
|
|
60
105
|
'replica.open',
|
|
106
|
+
'replica.rooms',
|
|
107
|
+
'replica.room',
|
|
108
|
+
'replica.covering',
|
|
109
|
+
'replica.offline',
|
|
110
|
+
'replica.held',
|
|
111
|
+
'replica.facts',
|
|
112
|
+
'replica.presentation',
|
|
61
113
|
'replica.query',
|
|
114
|
+
'replica.named',
|
|
115
|
+
'replica.tallies',
|
|
62
116
|
'replica.entries',
|
|
63
117
|
'replica.typed',
|
|
64
118
|
'replica.referrers',
|
|
65
|
-
'replica.
|
|
66
|
-
'replica.
|
|
119
|
+
'replica.holders',
|
|
120
|
+
'replica.folders',
|
|
67
121
|
'replica.typedWithin',
|
|
68
|
-
'replica.counts',
|
|
69
|
-
'replica.search',
|
|
70
|
-
'replica.received',
|
|
71
|
-
'replica.receivedParts',
|
|
72
|
-
'replica.transferPart',
|
|
73
122
|
'opened.find',
|
|
123
|
+
'opened.held',
|
|
74
124
|
'file.part',
|
|
75
125
|
'conversation.held',
|
|
76
126
|
'conversation.window',
|
|
77
127
|
'conversation.count',
|
|
78
128
|
'conversation.turn',
|
|
129
|
+
'conversation.rows',
|
|
130
|
+
'conversation.tallies',
|
|
131
|
+
'conversation.facts',
|
|
132
|
+
'conversation.stored',
|
|
133
|
+
'read.stored',
|
|
134
|
+
'run.marks',
|
|
135
|
+
'run.held',
|
|
79
136
|
]);
|
|
80
137
|
const KINDS = new Set([
|
|
81
138
|
...READS,
|
|
@@ -87,26 +144,32 @@ const KINDS = new Set([
|
|
|
87
144
|
'authored.claim',
|
|
88
145
|
'authored.end',
|
|
89
146
|
'replica.stage',
|
|
90
|
-
'replica.
|
|
147
|
+
'replica.resume',
|
|
91
148
|
'replica.refresh',
|
|
92
149
|
'replica.unrefresh',
|
|
93
150
|
'replica.commit',
|
|
94
151
|
'replica.fence',
|
|
95
152
|
'replica.erase',
|
|
96
153
|
'replica.abandon',
|
|
154
|
+
'replica.unfence',
|
|
97
155
|
'replica.release',
|
|
98
156
|
'replica.rederive',
|
|
157
|
+
'replica.demote',
|
|
99
158
|
'replica.fact',
|
|
100
159
|
'replica.present',
|
|
101
|
-
'replica.receive',
|
|
102
|
-
'replica.unreceive',
|
|
103
160
|
'opened.begin',
|
|
104
161
|
'opened.part',
|
|
105
162
|
'opened.keep',
|
|
106
163
|
'opened.drop',
|
|
107
164
|
'opened.clean',
|
|
108
165
|
'conversation.keep',
|
|
166
|
+
'conversation.fact',
|
|
109
167
|
'conversation.drop',
|
|
168
|
+
'space.probe',
|
|
169
|
+
'read.keep',
|
|
170
|
+
'read.builds',
|
|
171
|
+
'run.keep',
|
|
172
|
+
'run.left',
|
|
110
173
|
]);
|
|
111
174
|
export function isRuntime(request) {
|
|
112
175
|
return KINDS.has(request.kind);
|
|
@@ -114,239 +177,76 @@ export function isRuntime(request) {
|
|
|
114
177
|
export function readsRuntime(request) {
|
|
115
178
|
return READS.has(request.kind);
|
|
116
179
|
}
|
|
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) {
|
|
180
|
+
function heldWork(connection, locator) {
|
|
181
|
+
const room = heldRoom(connection, locator);
|
|
182
182
|
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
|
-
})),
|
|
183
|
+
room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
|
|
184
|
+
queue: queueOf(connection, locator),
|
|
195
185
|
};
|
|
196
186
|
}
|
|
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;
|
|
187
|
+
function status(connection) {
|
|
188
|
+
return {
|
|
189
|
+
...unsentStatus(connection),
|
|
190
|
+
lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
|
|
191
|
+
};
|
|
256
192
|
}
|
|
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;
|
|
193
|
+
function pendingOf(connection, locator, id) {
|
|
194
|
+
return {
|
|
195
|
+
state: pendingState(connection, locator, id),
|
|
196
|
+
room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
|
|
197
|
+
};
|
|
272
198
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
199
|
+
function storedConversations(connection, conversations) {
|
|
200
|
+
const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
|
|
201
|
+
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
202
|
+
return [
|
|
203
|
+
...new Set([
|
|
204
|
+
...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
|
|
205
|
+
...chatDraftConversations(connection, conversations),
|
|
206
|
+
]),
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
function droppedConversations(connection, conversations) {
|
|
210
|
+
const held = storedConversations(connection, conversations);
|
|
211
|
+
for (const table of tablesOf(MESSAGE_TABLES)) {
|
|
212
|
+
connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
|
|
213
|
+
JSON.stringify(conversations),
|
|
281
214
|
]);
|
|
282
215
|
}
|
|
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;
|
|
216
|
+
chatDraftsDropped(connection, conversations);
|
|
217
|
+
return held;
|
|
307
218
|
}
|
|
308
|
-
function
|
|
309
|
-
connection.run(
|
|
310
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
|
|
219
|
+
function unopened(connection) {
|
|
220
|
+
connection.run(UNOPENED_PARTS);
|
|
311
221
|
}
|
|
312
222
|
function fence(connection, locators) {
|
|
223
|
+
fencedWork(connection, locators);
|
|
313
224
|
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
225
|
connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
|
|
318
226
|
}
|
|
319
|
-
|
|
227
|
+
unopened(connection);
|
|
320
228
|
return fenceRooms(connection, locators);
|
|
321
229
|
}
|
|
322
230
|
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;
|
|
231
|
+
return erase(connection, locator, limit);
|
|
328
232
|
}
|
|
329
|
-
function
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return true;
|
|
233
|
+
function unfencedRooms(connection, locators) {
|
|
234
|
+
const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
|
|
235
|
+
.length === 0);
|
|
236
|
+
unfenced(connection, erased);
|
|
237
|
+
return erased;
|
|
335
238
|
}
|
|
336
239
|
function end(connection, holder) {
|
|
337
240
|
ended(connection);
|
|
338
|
-
|
|
241
|
+
forgottenConversations(connection);
|
|
242
|
+
forgottenRuns(connection);
|
|
339
243
|
if (holder !== null && claim(connection, holder))
|
|
340
244
|
return true;
|
|
341
|
-
|
|
342
|
-
connection.run(`DELETE FROM ${table}`);
|
|
245
|
+
authoredEmptied(connection);
|
|
343
246
|
connection.run('DELETE FROM opened_files');
|
|
344
|
-
connection.run('DELETE FROM
|
|
247
|
+
connection.run('DELETE FROM opened_parts');
|
|
345
248
|
return false;
|
|
346
249
|
}
|
|
347
|
-
function count(value) {
|
|
348
|
-
return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
|
|
349
|
-
}
|
|
350
250
|
function openedFile(connection, { locator, path, revision }) {
|
|
351
251
|
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
252
|
return held === undefined
|
|
@@ -361,7 +261,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
|
|
|
361
261
|
if (fenced(connection, locator))
|
|
362
262
|
return false;
|
|
363
263
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
|
|
364
|
-
|
|
264
|
+
unopened(connection);
|
|
365
265
|
connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
|
|
366
266
|
return true;
|
|
367
267
|
}
|
|
@@ -374,22 +274,26 @@ function fetching(connection, key) {
|
|
|
374
274
|
function openedPart(connection, { key, part, bytes }) {
|
|
375
275
|
if (fetching(connection, key) === null)
|
|
376
276
|
return false;
|
|
377
|
-
|
|
277
|
+
connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
|
|
278
|
+
key,
|
|
279
|
+
part,
|
|
280
|
+
bytes,
|
|
281
|
+
]);
|
|
378
282
|
return true;
|
|
379
283
|
}
|
|
380
284
|
function dropped(connection, key) {
|
|
381
285
|
connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
|
|
382
|
-
connection.run('DELETE FROM
|
|
286
|
+
connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
|
|
383
287
|
return null;
|
|
384
288
|
}
|
|
385
289
|
function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
386
290
|
const fetched = fetching(connection, key);
|
|
387
291
|
if (fetched === null)
|
|
388
292
|
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
|
|
293
|
+
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]);
|
|
294
|
+
const whole = count(held.parts) === parts &&
|
|
295
|
+
count(held.bytes) === byteLength &&
|
|
296
|
+
(parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
|
|
393
297
|
if (!whole) {
|
|
394
298
|
dropped(connection, key);
|
|
395
299
|
return false;
|
|
@@ -400,71 +304,82 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
|
400
304
|
key,
|
|
401
305
|
]);
|
|
402
306
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
|
|
403
|
-
|
|
307
|
+
unopened(connection);
|
|
404
308
|
return true;
|
|
405
309
|
}
|
|
310
|
+
function heldPart(connection, key, part) {
|
|
311
|
+
const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
|
|
312
|
+
key,
|
|
313
|
+
part,
|
|
314
|
+
]);
|
|
315
|
+
return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
|
|
316
|
+
}
|
|
317
|
+
function cleanable(connection) {
|
|
318
|
+
const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
|
|
319
|
+
return count(held.bytes);
|
|
320
|
+
}
|
|
406
321
|
function cleaned(connection) {
|
|
407
322
|
connection.run('DELETE FROM opened_files');
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
return
|
|
323
|
+
const freed = cleanable(connection);
|
|
324
|
+
unopened(connection);
|
|
325
|
+
return freed;
|
|
326
|
+
}
|
|
327
|
+
function openedHeld(connection) {
|
|
328
|
+
return {
|
|
329
|
+
rooms: connection
|
|
330
|
+
.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')
|
|
331
|
+
.map((row) => ({ room: text(row.locator), count: count(row.files), size: count(row.bytes) })),
|
|
332
|
+
cleanable: cleanable(connection),
|
|
333
|
+
};
|
|
411
334
|
}
|
|
412
335
|
async function committed(connection, { authored, rooms }) {
|
|
413
336
|
const refused = authored === undefined ? null : await kept(connection, authored);
|
|
414
337
|
if (refused !== null && authored?.whole === true) {
|
|
415
|
-
return { fenced: refused,
|
|
338
|
+
return { fenced: refused, changed: {}, indexed: {} };
|
|
416
339
|
}
|
|
417
340
|
return {
|
|
418
341
|
fenced: refused,
|
|
419
342
|
...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
|
|
420
343
|
};
|
|
421
344
|
}
|
|
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
345
|
export function answerRuntime(connection, request, spool) {
|
|
445
346
|
switch (request.kind) {
|
|
446
|
-
case 'authored.
|
|
447
|
-
return
|
|
347
|
+
case 'authored.status':
|
|
348
|
+
return status(connection);
|
|
349
|
+
case 'authored.moving':
|
|
350
|
+
return moving(connection);
|
|
351
|
+
case 'authored.pending':
|
|
352
|
+
return pendingOf(connection, request.locator, request.id);
|
|
353
|
+
case 'authored.batch':
|
|
354
|
+
return pendingBatch(connection, request.locator, request.id);
|
|
355
|
+
case 'authored.order':
|
|
356
|
+
return heldOrder(connection, request.locator);
|
|
357
|
+
case 'authored.queued':
|
|
358
|
+
return queuedLocators(connection);
|
|
448
359
|
case 'authored.roomDrafts':
|
|
449
|
-
return
|
|
360
|
+
return roomDraftRecords(connection, request.locator, request.paths);
|
|
361
|
+
case 'authored.chatDraft.read':
|
|
362
|
+
return chatDraftRecord(connection, request.conversation);
|
|
450
363
|
case 'authored.chatDrafts':
|
|
451
|
-
return
|
|
364
|
+
return chatDraftRecords(connection);
|
|
452
365
|
case 'authored.calls':
|
|
453
|
-
return
|
|
366
|
+
return callRecords(connection);
|
|
454
367
|
case 'authored.fences':
|
|
455
|
-
return
|
|
368
|
+
return fences(connection);
|
|
369
|
+
case 'authored.unsent':
|
|
370
|
+
return unsent(connection);
|
|
456
371
|
case 'authored.fact':
|
|
457
372
|
return fact(connection, request.name);
|
|
458
373
|
case 'authored.file':
|
|
459
|
-
return spooled(connection, spool, request);
|
|
374
|
+
return spooled(connection, spool, request.key, request.type);
|
|
460
375
|
case 'authored.amend':
|
|
461
|
-
return amended(connection, request);
|
|
376
|
+
return amended(connection, request.locator, request.id, request.amendment);
|
|
462
377
|
case 'authored.roomDraft':
|
|
463
|
-
return roomDraft(connection, request);
|
|
378
|
+
return roomDraft(connection, request.locator, request.path, request.kept, request.files);
|
|
464
379
|
case 'authored.chatDraft':
|
|
465
|
-
return chatDraft(connection, request);
|
|
380
|
+
return chatDraft(connection, request.kept, request.dropped);
|
|
466
381
|
case 'authored.call':
|
|
467
|
-
return call(connection, request);
|
|
382
|
+
return call(connection, request.operation, request.kept, request.files);
|
|
468
383
|
case 'authored.remember':
|
|
469
384
|
return remember(connection, request.name, request.value);
|
|
470
385
|
case 'authored.claim':
|
|
@@ -473,39 +388,47 @@ export function answerRuntime(connection, request, spool) {
|
|
|
473
388
|
return end(connection, request.holder);
|
|
474
389
|
case 'replica.open':
|
|
475
390
|
return opened(connection);
|
|
391
|
+
case 'replica.rooms':
|
|
392
|
+
return heldRooms(connection, request.locators);
|
|
393
|
+
case 'replica.room':
|
|
394
|
+
return heldWork(connection, request.locator);
|
|
395
|
+
case 'replica.covering':
|
|
396
|
+
return { ...covering(connection, request.since), queues: queues(connection) };
|
|
397
|
+
case 'replica.offline':
|
|
398
|
+
return offlineMode(connection, request.locator);
|
|
399
|
+
case 'replica.held':
|
|
400
|
+
return {
|
|
401
|
+
held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
|
|
402
|
+
staged: stagedLocators(connection),
|
|
403
|
+
};
|
|
404
|
+
case 'replica.demote':
|
|
405
|
+
return demoted(connection);
|
|
406
|
+
case 'replica.facts':
|
|
407
|
+
return facts(connection, request.names);
|
|
408
|
+
case 'replica.presentation':
|
|
409
|
+
return presentation(connection, request.app);
|
|
476
410
|
case 'replica.query':
|
|
477
|
-
return answerQuery(connection, request.plan, request.rooms, request.budget);
|
|
411
|
+
return answerQuery(connection, request.plan, request.rooms, request.budget, request.follows);
|
|
412
|
+
case 'replica.named':
|
|
413
|
+
return namedHandles(connection, request.plan, request.rooms, request.handles);
|
|
414
|
+
case 'replica.tallies':
|
|
415
|
+
return roomTallies(connection, request.totals, request.rooms, request.since);
|
|
478
416
|
case 'replica.entries':
|
|
479
417
|
return entries(connection, request.key, request.view, request.paths);
|
|
480
418
|
case 'replica.typed':
|
|
481
419
|
return typed(connection, request.key, request.view, request.paths);
|
|
482
420
|
case 'replica.referrers':
|
|
483
|
-
return referrers(connection, request.key, request.view, request.targets
|
|
484
|
-
case 'replica.
|
|
485
|
-
return
|
|
486
|
-
case 'replica.
|
|
487
|
-
return
|
|
421
|
+
return referrers(connection, request.key, request.view, request.targets);
|
|
422
|
+
case 'replica.holders':
|
|
423
|
+
return holders(connection, request.key, request.view, request.sought);
|
|
424
|
+
case 'replica.folders':
|
|
425
|
+
return folders(connection, request.key, request.paths);
|
|
488
426
|
case 'replica.typedWithin':
|
|
489
427
|
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
428
|
case 'replica.stage':
|
|
504
429
|
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);
|
|
430
|
+
case 'replica.resume':
|
|
431
|
+
return fenced(connection, request.locator) ? null : resume(connection, request);
|
|
509
432
|
case 'replica.refresh':
|
|
510
433
|
return refreshing(connection, request);
|
|
511
434
|
case 'replica.unrefresh':
|
|
@@ -517,11 +440,13 @@ export function answerRuntime(connection, request, spool) {
|
|
|
517
440
|
case 'replica.erase':
|
|
518
441
|
return erased(connection, request);
|
|
519
442
|
case 'replica.abandon':
|
|
520
|
-
return abandon(connection, request.locator
|
|
443
|
+
return abandon(connection, request.locator);
|
|
444
|
+
case 'replica.unfence':
|
|
445
|
+
return unfencedRooms(connection, request.locators);
|
|
521
446
|
case 'replica.release':
|
|
522
447
|
return release(connection, request.key);
|
|
523
448
|
case 'replica.rederive':
|
|
524
|
-
return rederive(connection, request.key, request.
|
|
449
|
+
return rederive(connection, request.key, request.composed, request.bytes, request.ms, request.floor);
|
|
525
450
|
case 'replica.fact':
|
|
526
451
|
connection.run('INSERT OR REPLACE INTO replica_facts (name, value) VALUES (?, ?)', [
|
|
527
452
|
request.name,
|
|
@@ -534,10 +459,6 @@ export function answerRuntime(connection, request, spool) {
|
|
|
534
459
|
request.value,
|
|
535
460
|
]);
|
|
536
461
|
return null;
|
|
537
|
-
case 'replica.receive':
|
|
538
|
-
return receive(connection, request);
|
|
539
|
-
case 'replica.unreceive':
|
|
540
|
-
return unreceive(connection, request.keys);
|
|
541
462
|
case 'opened.find':
|
|
542
463
|
return openedFile(connection, request);
|
|
543
464
|
case 'opened.begin':
|
|
@@ -550,27 +471,51 @@ export function answerRuntime(connection, request, spool) {
|
|
|
550
471
|
return dropped(connection, request.key);
|
|
551
472
|
case 'opened.clean':
|
|
552
473
|
return cleaned(connection);
|
|
474
|
+
case 'opened.held':
|
|
475
|
+
return openedHeld(connection);
|
|
553
476
|
case 'file.part':
|
|
554
|
-
return
|
|
477
|
+
return heldPart(connection, request.key, request.part);
|
|
555
478
|
case 'conversation.held':
|
|
556
|
-
return heldConversations(connection);
|
|
479
|
+
return heldConversations(connection, request.conversations);
|
|
557
480
|
case 'conversation.keep': {
|
|
558
481
|
const { kind: _kind, ...write } = request;
|
|
559
482
|
return keptMessages(connection, write);
|
|
560
483
|
}
|
|
561
484
|
case 'conversation.window':
|
|
562
|
-
return messageWindow(connection, request.conversation, request.limit, request.before);
|
|
485
|
+
return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
|
|
563
486
|
case 'conversation.count':
|
|
564
|
-
return messageCount(connection, request.conversation);
|
|
487
|
+
return messageCount(connection, request.conversation, request.phrase);
|
|
565
488
|
case 'conversation.turn':
|
|
566
489
|
return turnArrived(connection, request.conversation, request.turn);
|
|
490
|
+
case 'conversation.rows':
|
|
491
|
+
return conversationRows(connection, request.conversations);
|
|
492
|
+
case 'conversation.tallies':
|
|
493
|
+
return conversationTallies(connection, request.conversations, request.since);
|
|
494
|
+
case 'conversation.facts':
|
|
495
|
+
return conversationFacts(connection);
|
|
496
|
+
case 'conversation.fact': {
|
|
497
|
+
const { kind: _kind, ...fact } = request;
|
|
498
|
+
return keptFact(connection, fact);
|
|
499
|
+
}
|
|
500
|
+
case 'conversation.stored':
|
|
501
|
+
return storedConversations(connection, null);
|
|
567
502
|
case 'conversation.drop':
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return
|
|
503
|
+
return droppedConversations(connection, request.conversations);
|
|
504
|
+
case 'space.probe':
|
|
505
|
+
return spool.probe(PROBE_BYTES).then(() => null);
|
|
506
|
+
case 'read.stored':
|
|
507
|
+
return storedRead(connection, request);
|
|
508
|
+
case 'read.keep':
|
|
509
|
+
return keptRead(connection, request, request.answer);
|
|
510
|
+
case 'read.builds':
|
|
511
|
+
return readsOfOtherBuildsForgotten(connection, request.build);
|
|
512
|
+
case 'run.marks':
|
|
513
|
+
return runMarks(connection);
|
|
514
|
+
case 'run.held':
|
|
515
|
+
return heldRuns(connection, request.asked, request.sight);
|
|
516
|
+
case 'run.keep':
|
|
517
|
+
return keptRuns(connection, request.event);
|
|
518
|
+
case 'run.left':
|
|
519
|
+
return runsLeft(connection, request.sight);
|
|
575
520
|
}
|
|
576
521
|
}
|