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