@agentshouse/mdruntime 0.1.0-c01d4615bfe46 → 0.1.0-c024a9c474f5e
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 +14 -13
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +32 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +58 -19
- package/dist/adapter.d.ts +183 -21
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.js +2 -2
- package/dist/client.d.ts +23 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +25 -54
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- 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 +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +73 -42
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +16 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +8 -5
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +5 -3
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +20 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +102 -68
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- 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 +2 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +1 -1
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +70 -29
- 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 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +42 -25
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- 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.map +1 -1
- package/dist/locks.js +4 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +177 -27
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -16
- package/dist/messages.d.ts +12 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +28 -6
- 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 +10 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -3
- 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 +26 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +200 -69
- 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 +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +20 -2
- package/dist/outcome.d.ts +27 -14
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +14 -5
- package/dist/overlay.d.ts +20 -9
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +110 -41
- package/dist/parts.d.ts +4 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +195 -78
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +115 -67
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +55 -23
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +140 -25
- package/dist/react.d.ts +11 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +22 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +2 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +21 -13
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/room-draft.d.ts +29 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +237 -16
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- 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 +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- 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 +7 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +31 -96
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +108 -54
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +4 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +73 -48
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +6 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +14 -2
- package/dist/source.d.ts +42 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -9
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +24 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +59 -24
- 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.d.ts +15 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +40 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +18 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -16
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +47 -25
- package/dist/tables.d.ts +34 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +84 -325
- package/dist/tallies.js +2 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +29 -14
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +18 -13
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
package/dist/tables.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
-
import { answerQuery } from './compile.js';
|
|
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';
|
|
3
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';
|
|
4
7
|
import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
|
|
5
8
|
import { conversationTallies, roomTallies, } from './tallies.js';
|
|
6
|
-
import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
|
|
9
|
+
import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, holders, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
|
|
10
|
+
export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
|
|
7
11
|
const STATEMENTS_HELD = 256;
|
|
8
12
|
export function sqliteConnection(engine, database) {
|
|
9
13
|
const decoder = new TextDecoder();
|
|
@@ -71,36 +75,17 @@ export function sqliteConnection(engine, database) {
|
|
|
71
75
|
},
|
|
72
76
|
};
|
|
73
77
|
}
|
|
74
|
-
export const FILE_PART_BYTES = 1_048_576;
|
|
75
78
|
const PROBE_BYTES = 4 * FILE_PART_BYTES;
|
|
76
|
-
const TABLES = [
|
|
77
|
-
['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
|
|
78
|
-
['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
|
|
79
|
-
[
|
|
80
|
-
'authored_pending',
|
|
81
|
-
'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, paths TEXT NOT NULL, moving INTEGER NOT NULL, PRIMARY KEY (locator, id)',
|
|
82
|
-
],
|
|
83
|
-
[
|
|
84
|
-
'authored_room_drafts',
|
|
85
|
-
'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
|
|
86
|
-
],
|
|
87
|
-
['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
|
|
88
|
-
['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
|
|
89
|
-
['authored_fences', 'locator TEXT PRIMARY KEY'],
|
|
90
|
-
];
|
|
91
79
|
export const RUNTIME_TABLES = [
|
|
92
|
-
...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
|
|
93
|
-
'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
|
|
94
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',
|
|
95
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))',
|
|
96
83
|
...REPLICA_TABLES,
|
|
97
84
|
...MESSAGE_TABLES,
|
|
98
85
|
...READ_TABLES,
|
|
86
|
+
...RUN_TABLES,
|
|
99
87
|
];
|
|
100
|
-
const
|
|
101
|
-
const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
|
|
102
|
-
const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
|
|
103
|
-
const CLEANABLE_BYTES = `SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS})`;
|
|
88
|
+
const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
|
|
104
89
|
const READS = new Set([
|
|
105
90
|
'authored.status',
|
|
106
91
|
'authored.moving',
|
|
@@ -125,10 +110,12 @@ const READS = new Set([
|
|
|
125
110
|
'replica.facts',
|
|
126
111
|
'replica.presentation',
|
|
127
112
|
'replica.query',
|
|
113
|
+
'replica.named',
|
|
128
114
|
'replica.tallies',
|
|
129
115
|
'replica.entries',
|
|
130
116
|
'replica.typed',
|
|
131
117
|
'replica.referrers',
|
|
118
|
+
'replica.holders',
|
|
132
119
|
'replica.folders',
|
|
133
120
|
'replica.typedWithin',
|
|
134
121
|
'opened.find',
|
|
@@ -143,6 +130,8 @@ const READS = new Set([
|
|
|
143
130
|
'conversation.facts',
|
|
144
131
|
'conversation.stored',
|
|
145
132
|
'read.stored',
|
|
133
|
+
'run.marks',
|
|
134
|
+
'run.held',
|
|
146
135
|
]);
|
|
147
136
|
const KINDS = new Set([
|
|
148
137
|
...READS,
|
|
@@ -178,6 +167,8 @@ const KINDS = new Set([
|
|
|
178
167
|
'space.probe',
|
|
179
168
|
'read.keep',
|
|
180
169
|
'read.builds',
|
|
170
|
+
'run.keep',
|
|
171
|
+
'run.left',
|
|
181
172
|
]);
|
|
182
173
|
export function isRuntime(request) {
|
|
183
174
|
return KINDS.has(request.kind);
|
|
@@ -185,309 +176,76 @@ export function isRuntime(request) {
|
|
|
185
176
|
export function readsRuntime(request) {
|
|
186
177
|
return READS.has(request.kind);
|
|
187
178
|
}
|
|
188
|
-
function text(value) {
|
|
189
|
-
return typeof value === 'string' ? value : String(value);
|
|
190
|
-
}
|
|
191
|
-
function texts(rows, column) {
|
|
192
|
-
return rows.map((row) => text(row[column]));
|
|
193
|
-
}
|
|
194
|
-
function owned(files) {
|
|
195
|
-
return JSON.stringify([...new Set(files)]);
|
|
196
|
-
}
|
|
197
|
-
function fact(connection, name) {
|
|
198
|
-
const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
|
|
199
|
-
return held === undefined ? null : text(held.value);
|
|
200
|
-
}
|
|
201
|
-
function remember(connection, name, value) {
|
|
202
|
-
connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
|
|
203
|
-
name,
|
|
204
|
-
value,
|
|
205
|
-
]);
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
function fenced(connection, locator) {
|
|
209
|
-
return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
|
|
210
|
-
}
|
|
211
|
-
function stored(connection, key) {
|
|
212
|
-
return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
|
|
213
|
-
}
|
|
214
|
-
function storedPart(connection, key, part, bytes) {
|
|
215
|
-
connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
|
|
216
|
-
}
|
|
217
|
-
async function storedFiles(connection, files) {
|
|
218
|
-
for (const { key, blob } of files) {
|
|
219
|
-
if (stored(connection, key))
|
|
220
|
-
continue;
|
|
221
|
-
for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
|
|
222
|
-
const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
|
|
223
|
-
storedPart(connection, key, part, bytes);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
function filePart(connection, key, part) {
|
|
228
|
-
const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
|
|
229
|
-
key,
|
|
230
|
-
part,
|
|
231
|
-
]);
|
|
232
|
-
return held?.bytes instanceof Uint8Array ? held.bytes : null;
|
|
233
|
-
}
|
|
234
|
-
function* fileParts(connection, key) {
|
|
235
|
-
for (let part = 0;; part += 1) {
|
|
236
|
-
const bytes = filePart(connection, key, part);
|
|
237
|
-
if (bytes === null)
|
|
238
|
-
return;
|
|
239
|
-
yield bytes;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
async function spooled(connection, spool, { key, type }) {
|
|
243
|
-
for (const held of [...spool.held()]) {
|
|
244
|
-
if (held !== key && !stored(connection, held))
|
|
245
|
-
await spool.drop(held);
|
|
246
|
-
}
|
|
247
|
-
return spool.spool(key, type, fileParts(connection, key));
|
|
248
|
-
}
|
|
249
|
-
function unowned(connection) {
|
|
250
|
-
connection.run(UNOWNED_PARTS);
|
|
251
|
-
}
|
|
252
|
-
function queued(connection) {
|
|
253
|
-
return connection.rows('SELECT locator, ids FROM authored_queues').map((row) => ({
|
|
254
|
-
locator: text(row.locator),
|
|
255
|
-
ids: JSON.parse(text(row.ids)),
|
|
256
|
-
}));
|
|
257
|
-
}
|
|
258
179
|
function heldWork(connection, locator) {
|
|
259
180
|
const room = heldRoom(connection, locator);
|
|
260
|
-
const pending = new Map(connection
|
|
261
|
-
.rows('SELECT id, batch, state FROM authored_pending WHERE locator = ?', [locator])
|
|
262
|
-
.map((row) => [
|
|
263
|
-
text(row.id),
|
|
264
|
-
{ id: text(row.id), batch: text(row.batch), state: text(row.state) },
|
|
265
|
-
]));
|
|
266
181
|
return {
|
|
267
182
|
room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
|
|
268
|
-
queue:
|
|
269
|
-
const held = pending.get(id);
|
|
270
|
-
if (held === undefined)
|
|
271
|
-
throw new Error(`Missing Pending Change ${locator}/${id}`);
|
|
272
|
-
return held;
|
|
273
|
-
}),
|
|
183
|
+
queue: queueOf(connection, locator),
|
|
274
184
|
};
|
|
275
185
|
}
|
|
276
186
|
function status(connection) {
|
|
277
|
-
const [completed] = connection.rows("SELECT value FROM replica_facts WHERE name = 'lastCompleted'");
|
|
278
187
|
return {
|
|
279
|
-
|
|
280
|
-
lastCompleted:
|
|
281
|
-
changes: connection
|
|
282
|
-
.rows('SELECT p.locator, c.value AS path FROM authored_pending p, json_each(p.paths) c')
|
|
283
|
-
.map((row) => ({ locator: text(row.locator), path: text(row.path) })),
|
|
284
|
-
resets: connection
|
|
285
|
-
.rows(`SELECT locator, json_extract(state, '$.submission.reset') AS reset FROM authored_pending
|
|
286
|
-
WHERE json_extract(state, '$.submission.state') = 'reset'`)
|
|
287
|
-
.map((row) => ({ locator: text(row.locator), reset: text(row.reset) })),
|
|
288
|
-
returned: texts(connection.rows(`SELECT record FROM authored_room_drafts WHERE json_type(record, '$.returned') = 'object'`), 'record'),
|
|
188
|
+
...unsentStatus(connection),
|
|
189
|
+
lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
|
|
289
190
|
};
|
|
290
191
|
}
|
|
291
192
|
function pendingOf(connection, locator, id) {
|
|
292
|
-
const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
293
193
|
return {
|
|
294
|
-
state:
|
|
194
|
+
state: pendingState(connection, locator, id),
|
|
295
195
|
room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
|
|
296
196
|
};
|
|
297
197
|
}
|
|
298
|
-
function roomDraftRecords(connection, locator, paths) {
|
|
299
|
-
if (locator === null) {
|
|
300
|
-
return texts(connection.rows('SELECT record FROM authored_room_drafts'), 'record');
|
|
301
|
-
}
|
|
302
|
-
if (paths === null) {
|
|
303
|
-
return texts(connection.rows('SELECT record FROM authored_room_drafts WHERE locator = ?', [locator]), 'record');
|
|
304
|
-
}
|
|
305
|
-
return texts(connection.rows('SELECT record FROM authored_room_drafts WHERE locator = ? AND path IN (SELECT value FROM json_each(?))', [locator, JSON.stringify(paths)]), 'record');
|
|
306
|
-
}
|
|
307
|
-
function chatDraftRecord(connection, conversation) {
|
|
308
|
-
const [held] = connection.rows('SELECT record FROM authored_chat_drafts WHERE conversation = ?', [
|
|
309
|
-
conversation,
|
|
310
|
-
]);
|
|
311
|
-
return held === undefined ? null : text(held.record);
|
|
312
|
-
}
|
|
313
|
-
function heldOrder(connection, locator) {
|
|
314
|
-
const [held] = connection.rows('SELECT ids FROM authored_queues WHERE locator = ?', [locator]);
|
|
315
|
-
return held === undefined ? [] : JSON.parse(text(held.ids));
|
|
316
|
-
}
|
|
317
|
-
function keptRows(connection, { locator, order, added, founded, roomDrafts, consumedRoomDrafts }) {
|
|
318
|
-
for (const path of consumedRoomDrafts ?? []) {
|
|
319
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
|
|
320
|
-
locator,
|
|
321
|
-
path,
|
|
322
|
-
]);
|
|
323
|
-
}
|
|
324
|
-
for (const { path, record, files } of roomDrafts ?? []) {
|
|
325
|
-
connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
|
|
326
|
-
}
|
|
327
|
-
if (order === undefined)
|
|
328
|
-
return;
|
|
329
|
-
const before = new Set(heldOrder(connection, locator));
|
|
330
|
-
const after = new Set(order);
|
|
331
|
-
if (after.size === 0)
|
|
332
|
-
connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
|
|
333
|
-
else {
|
|
334
|
-
connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
|
|
335
|
-
locator,
|
|
336
|
-
JSON.stringify([...after]),
|
|
337
|
-
]);
|
|
338
|
-
}
|
|
339
|
-
for (const id of before) {
|
|
340
|
-
if (!after.has(id)) {
|
|
341
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
for (const { id, batch, state, files, paths, moving } of added ?? []) {
|
|
345
|
-
if (before.has(id))
|
|
346
|
-
continue;
|
|
347
|
-
connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files, paths, moving) VALUES (?, ?, ?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files), JSON.stringify(paths), moving ? 1 : 0]);
|
|
348
|
-
}
|
|
349
|
-
for (const { id, batch, files, paths, moving } of founded ?? []) {
|
|
350
|
-
const [held] = connection.rows('SELECT files FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
351
|
-
if (held === undefined || !before.has(id))
|
|
352
|
-
continue;
|
|
353
|
-
connection.run('UPDATE authored_pending SET batch = ?, files = ?, paths = ?, moving = ? WHERE locator = ? AND id = ?', [
|
|
354
|
-
batch,
|
|
355
|
-
owned([...JSON.parse(text(held.files)), ...files]),
|
|
356
|
-
JSON.stringify(paths),
|
|
357
|
-
moving ? 1 : 0,
|
|
358
|
-
locator,
|
|
359
|
-
id,
|
|
360
|
-
]);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
async function kept(connection, { writes, files, whole }) {
|
|
364
|
-
const refused = writes.find(({ locator }) => fenced(connection, locator));
|
|
365
|
-
if (refused !== undefined && whole)
|
|
366
|
-
return refused.locator;
|
|
367
|
-
await storedFiles(connection, files);
|
|
368
|
-
for (const write of writes) {
|
|
369
|
-
if (!fenced(connection, write.locator))
|
|
370
|
-
keptRows(connection, write);
|
|
371
|
-
}
|
|
372
|
-
unowned(connection);
|
|
373
|
-
return refused?.locator ?? null;
|
|
374
|
-
}
|
|
375
|
-
function amended(connection, { locator, id, amendment }) {
|
|
376
|
-
if (fenced(connection, locator))
|
|
377
|
-
return null;
|
|
378
|
-
const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
|
|
379
|
-
if (held === undefined)
|
|
380
|
-
return null;
|
|
381
|
-
connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
|
|
382
|
-
JSON.stringify({
|
|
383
|
-
...JSON.parse(text(held.state)),
|
|
384
|
-
...JSON.parse(amendment),
|
|
385
|
-
}),
|
|
386
|
-
locator,
|
|
387
|
-
id,
|
|
388
|
-
]);
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
async function roomDraft(connection, { locator, path, kept: draft, files }) {
|
|
392
|
-
if (fenced(connection, locator))
|
|
393
|
-
return locator;
|
|
394
|
-
await storedFiles(connection, files);
|
|
395
|
-
if (draft === null) {
|
|
396
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
|
|
397
|
-
locator,
|
|
398
|
-
path,
|
|
399
|
-
]);
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, draft.record, owned(draft.files)]);
|
|
403
|
-
}
|
|
404
|
-
unowned(connection);
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
function conversationTables() {
|
|
408
|
-
return [...tablesOf(MESSAGE_TABLES), 'authored_chat_drafts'];
|
|
409
|
-
}
|
|
410
198
|
function storedConversations(connection, conversations) {
|
|
411
199
|
const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
|
|
412
200
|
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
413
201
|
return [
|
|
414
|
-
...new Set(
|
|
202
|
+
...new Set([
|
|
203
|
+
...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
|
|
204
|
+
...chatDraftConversations(connection, conversations),
|
|
205
|
+
]),
|
|
415
206
|
];
|
|
416
207
|
}
|
|
417
208
|
function droppedConversations(connection, conversations) {
|
|
418
209
|
const held = storedConversations(connection, conversations);
|
|
419
|
-
for (const table of
|
|
210
|
+
for (const table of tablesOf(MESSAGE_TABLES)) {
|
|
420
211
|
connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
|
|
421
212
|
JSON.stringify(conversations),
|
|
422
213
|
]);
|
|
423
214
|
}
|
|
215
|
+
chatDraftsDropped(connection, conversations);
|
|
424
216
|
return held;
|
|
425
217
|
}
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
|
|
429
|
-
}
|
|
430
|
-
for (const { conversation, record } of drafts) {
|
|
431
|
-
connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
|
|
432
|
-
}
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
async function call(connection, { operation, kept: held, files }) {
|
|
436
|
-
await storedFiles(connection, files);
|
|
437
|
-
if (held === null)
|
|
438
|
-
connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
|
|
439
|
-
else {
|
|
440
|
-
connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
|
|
441
|
-
}
|
|
442
|
-
unowned(connection);
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
function roomWork(connection, locator) {
|
|
446
|
-
connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
|
|
447
|
-
connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
|
|
218
|
+
function unopened(connection) {
|
|
219
|
+
connection.run(UNOPENED_PARTS);
|
|
448
220
|
}
|
|
449
221
|
function fence(connection, locators) {
|
|
222
|
+
fencedWork(connection, locators);
|
|
450
223
|
for (const locator of locators) {
|
|
451
|
-
connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
|
|
452
|
-
roomWork(connection, locator);
|
|
453
|
-
connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
|
|
454
224
|
connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
|
|
455
225
|
}
|
|
456
|
-
|
|
226
|
+
unopened(connection);
|
|
457
227
|
return fenceRooms(connection, locators);
|
|
458
228
|
}
|
|
459
229
|
function erased(connection, { locator, limit }) {
|
|
460
230
|
return erase(connection, locator, limit);
|
|
461
231
|
}
|
|
462
|
-
function
|
|
232
|
+
function unfencedRooms(connection, locators) {
|
|
463
233
|
const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
|
|
464
234
|
.length === 0);
|
|
465
|
-
|
|
466
|
-
connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
|
|
467
|
-
}
|
|
235
|
+
unfenced(connection, erased);
|
|
468
236
|
return erased;
|
|
469
237
|
}
|
|
470
|
-
function claim(connection, holder) {
|
|
471
|
-
const held = fact(connection, 'holder');
|
|
472
|
-
if (held !== null)
|
|
473
|
-
return held === holder;
|
|
474
|
-
remember(connection, 'holder', holder);
|
|
475
|
-
return true;
|
|
476
|
-
}
|
|
477
238
|
function end(connection, holder) {
|
|
478
239
|
ended(connection);
|
|
479
240
|
forgottenConversations(connection);
|
|
241
|
+
forgottenRuns(connection);
|
|
480
242
|
if (holder !== null && claim(connection, holder))
|
|
481
243
|
return true;
|
|
482
|
-
|
|
483
|
-
connection.run(`DELETE FROM ${table}`);
|
|
244
|
+
authoredEmptied(connection);
|
|
484
245
|
connection.run('DELETE FROM opened_files');
|
|
485
|
-
connection.run('DELETE FROM
|
|
246
|
+
connection.run('DELETE FROM opened_parts');
|
|
486
247
|
return false;
|
|
487
248
|
}
|
|
488
|
-
function count(value) {
|
|
489
|
-
return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
|
|
490
|
-
}
|
|
491
249
|
function openedFile(connection, { locator, path, revision }) {
|
|
492
250
|
const [held] = connection.rows('SELECT key, media_type, byte_length FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NOT NULL', [locator, path, revision]);
|
|
493
251
|
return held === undefined
|
|
@@ -502,7 +260,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
|
|
|
502
260
|
if (fenced(connection, locator))
|
|
503
261
|
return false;
|
|
504
262
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
|
|
505
|
-
|
|
263
|
+
unopened(connection);
|
|
506
264
|
connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
|
|
507
265
|
return true;
|
|
508
266
|
}
|
|
@@ -515,19 +273,23 @@ function fetching(connection, key) {
|
|
|
515
273
|
function openedPart(connection, { key, part, bytes }) {
|
|
516
274
|
if (fetching(connection, key) === null)
|
|
517
275
|
return false;
|
|
518
|
-
|
|
276
|
+
connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
|
|
277
|
+
key,
|
|
278
|
+
part,
|
|
279
|
+
bytes,
|
|
280
|
+
]);
|
|
519
281
|
return true;
|
|
520
282
|
}
|
|
521
283
|
function dropped(connection, key) {
|
|
522
284
|
connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
|
|
523
|
-
connection.run('DELETE FROM
|
|
285
|
+
connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
|
|
524
286
|
return null;
|
|
525
287
|
}
|
|
526
288
|
function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
527
289
|
const fetched = fetching(connection, key);
|
|
528
290
|
if (fetched === null)
|
|
529
291
|
return false;
|
|
530
|
-
const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM
|
|
292
|
+
const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts WHERE key = ?', [key]);
|
|
531
293
|
const whole = count(held.parts) === parts &&
|
|
532
294
|
count(held.bytes) === byteLength &&
|
|
533
295
|
(parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
|
|
@@ -541,27 +303,24 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
|
|
|
541
303
|
key,
|
|
542
304
|
]);
|
|
543
305
|
connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
|
|
544
|
-
|
|
306
|
+
unopened(connection);
|
|
545
307
|
return true;
|
|
546
308
|
}
|
|
547
|
-
|
|
548
|
-
['
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
function unsent(connection) {
|
|
554
|
-
const [held] = connection.rows(`SELECT ${UNSENT.map(([kind, table]) => `(SELECT count(*) FROM ${table}) AS "${kind}"`).join(', ')}`);
|
|
555
|
-
return UNSENT.map(([kind]) => ({ kind, count: count(held[kind]) })).filter((work) => work.count > 0);
|
|
309
|
+
function heldPart(connection, key, part) {
|
|
310
|
+
const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
|
|
311
|
+
key,
|
|
312
|
+
part,
|
|
313
|
+
]);
|
|
314
|
+
return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
|
|
556
315
|
}
|
|
557
316
|
function cleanable(connection) {
|
|
558
|
-
const [held] = connection.rows(
|
|
317
|
+
const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
|
|
559
318
|
return count(held.bytes);
|
|
560
319
|
}
|
|
561
320
|
function cleaned(connection) {
|
|
562
321
|
connection.run('DELETE FROM opened_files');
|
|
563
322
|
const freed = cleanable(connection);
|
|
564
|
-
|
|
323
|
+
unopened(connection);
|
|
565
324
|
return freed;
|
|
566
325
|
}
|
|
567
326
|
function openedHeld(connection) {
|
|
@@ -587,51 +346,39 @@ export function answerRuntime(connection, request, spool) {
|
|
|
587
346
|
case 'authored.status':
|
|
588
347
|
return status(connection);
|
|
589
348
|
case 'authored.moving':
|
|
590
|
-
return
|
|
591
|
-
queues: queued(connection),
|
|
592
|
-
pending: connection
|
|
593
|
-
.rows('SELECT locator, id, batch, state FROM authored_pending WHERE moving = 1 ORDER BY locator')
|
|
594
|
-
.map((row) => ({
|
|
595
|
-
locator: text(row.locator),
|
|
596
|
-
id: text(row.id),
|
|
597
|
-
batch: text(row.batch),
|
|
598
|
-
state: text(row.state),
|
|
599
|
-
})),
|
|
600
|
-
};
|
|
349
|
+
return moving(connection);
|
|
601
350
|
case 'authored.pending':
|
|
602
351
|
return pendingOf(connection, request.locator, request.id);
|
|
603
|
-
case 'authored.batch':
|
|
604
|
-
|
|
605
|
-
return held === undefined ? null : text(held.batch);
|
|
606
|
-
}
|
|
352
|
+
case 'authored.batch':
|
|
353
|
+
return pendingBatch(connection, request.locator, request.id);
|
|
607
354
|
case 'authored.order':
|
|
608
355
|
return heldOrder(connection, request.locator);
|
|
609
356
|
case 'authored.queued':
|
|
610
|
-
return
|
|
357
|
+
return queuedLocators(connection);
|
|
611
358
|
case 'authored.roomDrafts':
|
|
612
359
|
return roomDraftRecords(connection, request.locator, request.paths);
|
|
613
360
|
case 'authored.chatDraft.read':
|
|
614
361
|
return chatDraftRecord(connection, request.conversation);
|
|
615
362
|
case 'authored.chatDrafts':
|
|
616
|
-
return
|
|
363
|
+
return chatDraftRecords(connection);
|
|
617
364
|
case 'authored.calls':
|
|
618
|
-
return
|
|
365
|
+
return callRecords(connection);
|
|
619
366
|
case 'authored.fences':
|
|
620
|
-
return
|
|
367
|
+
return fences(connection);
|
|
621
368
|
case 'authored.unsent':
|
|
622
369
|
return unsent(connection);
|
|
623
370
|
case 'authored.fact':
|
|
624
371
|
return fact(connection, request.name);
|
|
625
372
|
case 'authored.file':
|
|
626
|
-
return spooled(connection, spool, request);
|
|
373
|
+
return spooled(connection, spool, request.key, request.type);
|
|
627
374
|
case 'authored.amend':
|
|
628
|
-
return amended(connection, request);
|
|
375
|
+
return amended(connection, request.locator, request.id, request.amendment);
|
|
629
376
|
case 'authored.roomDraft':
|
|
630
|
-
return roomDraft(connection, request);
|
|
377
|
+
return roomDraft(connection, request.locator, request.path, request.kept, request.files);
|
|
631
378
|
case 'authored.chatDraft':
|
|
632
|
-
return chatDraft(connection, request);
|
|
379
|
+
return chatDraft(connection, request.kept, request.dropped);
|
|
633
380
|
case 'authored.call':
|
|
634
|
-
return call(connection, request);
|
|
381
|
+
return call(connection, request.operation, request.kept, request.files);
|
|
635
382
|
case 'authored.remember':
|
|
636
383
|
return remember(connection, request.name, request.value);
|
|
637
384
|
case 'authored.claim':
|
|
@@ -645,22 +392,24 @@ export function answerRuntime(connection, request, spool) {
|
|
|
645
392
|
case 'replica.room':
|
|
646
393
|
return heldWork(connection, request.locator);
|
|
647
394
|
case 'replica.covering':
|
|
648
|
-
return {
|
|
649
|
-
rooms: covering(connection),
|
|
650
|
-
queues: queued(connection),
|
|
651
|
-
};
|
|
395
|
+
return { ...covering(connection, request.since), queues: queues(connection) };
|
|
652
396
|
case 'replica.offline':
|
|
653
397
|
return offlineMode(connection, request.locator);
|
|
654
398
|
case 'replica.held':
|
|
655
|
-
return {
|
|
399
|
+
return {
|
|
400
|
+
held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
|
|
401
|
+
staged: stagedLocators(connection),
|
|
402
|
+
};
|
|
656
403
|
case 'replica.demote':
|
|
657
404
|
return demoted(connection);
|
|
658
405
|
case 'replica.facts':
|
|
659
|
-
return facts(connection);
|
|
406
|
+
return facts(connection, request.names);
|
|
660
407
|
case 'replica.presentation':
|
|
661
408
|
return presentation(connection, request.app);
|
|
662
409
|
case 'replica.query':
|
|
663
|
-
return answerQuery(connection, request.plan, request.rooms, request.budget);
|
|
410
|
+
return answerQuery(connection, request.plan, request.rooms, request.budget, request.follows);
|
|
411
|
+
case 'replica.named':
|
|
412
|
+
return namedHandles(connection, request.plan, request.rooms, request.handles);
|
|
664
413
|
case 'replica.tallies':
|
|
665
414
|
return roomTallies(connection, request.totals, request.rooms, request.since);
|
|
666
415
|
case 'replica.entries':
|
|
@@ -669,6 +418,8 @@ export function answerRuntime(connection, request, spool) {
|
|
|
669
418
|
return typed(connection, request.key, request.view, request.paths);
|
|
670
419
|
case 'replica.referrers':
|
|
671
420
|
return referrers(connection, request.key, request.view, request.targets);
|
|
421
|
+
case 'replica.holders':
|
|
422
|
+
return holders(connection, request.key, request.view, request.sought);
|
|
672
423
|
case 'replica.folders':
|
|
673
424
|
return folders(connection, request.key, request.paths);
|
|
674
425
|
case 'replica.typedWithin':
|
|
@@ -690,7 +441,7 @@ export function answerRuntime(connection, request, spool) {
|
|
|
690
441
|
case 'replica.abandon':
|
|
691
442
|
return abandon(connection, request.locator);
|
|
692
443
|
case 'replica.unfence':
|
|
693
|
-
return
|
|
444
|
+
return unfencedRooms(connection, request.locators);
|
|
694
445
|
case 'replica.release':
|
|
695
446
|
return release(connection, request.key);
|
|
696
447
|
case 'replica.rederive':
|
|
@@ -722,7 +473,7 @@ export function answerRuntime(connection, request, spool) {
|
|
|
722
473
|
case 'opened.held':
|
|
723
474
|
return openedHeld(connection);
|
|
724
475
|
case 'file.part':
|
|
725
|
-
return
|
|
476
|
+
return heldPart(connection, request.key, request.part);
|
|
726
477
|
case 'conversation.held':
|
|
727
478
|
return heldConversations(connection, request.conversations);
|
|
728
479
|
case 'conversation.keep': {
|
|
@@ -757,5 +508,13 @@ export function answerRuntime(connection, request, spool) {
|
|
|
757
508
|
return keptRead(connection, request, request.answer);
|
|
758
509
|
case 'read.builds':
|
|
759
510
|
return readsOfOtherBuildsForgotten(connection, request.build);
|
|
511
|
+
case 'run.marks':
|
|
512
|
+
return runMarks(connection);
|
|
513
|
+
case 'run.held':
|
|
514
|
+
return heldRuns(connection, request.asked, request.sight);
|
|
515
|
+
case 'run.keep':
|
|
516
|
+
return keptRuns(connection, request.event);
|
|
517
|
+
case 'run.left':
|
|
518
|
+
return runsLeft(connection, request.sight);
|
|
760
519
|
}
|
|
761
520
|
}
|
package/dist/tallies.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { CHAT_MESSAGE_TYPE, CHAT_TYPE, instantKey, sql } from '@agentshouse/mdmodel';
|
|
2
2
|
import { answerQuery, VISIBLE, within } from './compile.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HOUSE_FOLDER } from './figures.js';
|
|
4
4
|
const NONE = { count: 0, size: 0 };
|
|
5
5
|
const { all, fragment, joined } = sql;
|
|
6
6
|
function instant(value) {
|
|
7
7
|
return typeof value === 'string' ? value : null;
|
|
8
8
|
}
|
|
9
9
|
function held(alias, keys) {
|
|
10
|
-
const reserved = within(alias,
|
|
10
|
+
const reserved = within(alias, HOUSE_FOLDER);
|
|
11
11
|
return all([
|
|
12
12
|
fragment(`${alias}.key IN (SELECT value FROM json_each(?))`, [JSON.stringify(keys)]),
|
|
13
13
|
fragment(VISIBLE(alias)),
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Validation } from '@agentshouse/mdmodel';
|
|
2
2
|
import { type Composition } from './collection.js';
|
|
3
|
+
import type { Holder, Sought } from './stored.js';
|
|
3
4
|
type Examined = {
|
|
4
5
|
readonly path: string;
|
|
5
6
|
readonly content: string | null;
|
|
@@ -23,6 +24,7 @@ type Neighbourhood = {
|
|
|
23
24
|
readonly lookup: Lookup;
|
|
24
25
|
readonly texts: (paths: readonly string[]) => Promise<ReadonlyMap<string, string | null>>;
|
|
25
26
|
readonly referrers: (targets: readonly string[]) => Promise<readonly string[]>;
|
|
27
|
+
readonly holders: (sought: readonly Sought[]) => Promise<readonly Holder[]>;
|
|
26
28
|
};
|
|
27
29
|
export declare function validatedNeighbourhood(changes: readonly Changed[], composition: Composition, source: Neighbourhood): Promise<Validation>;
|
|
28
30
|
export {};
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKlD,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,IAAI,GAAG,CACjB,KAAK,EAAE,MAAM,GAAG,IAAI,KACjB,OAAO,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAAC;AAEtF,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAoBvF,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,UAAU,CAAC,CA6CrB;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1F,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IAC/E,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;CAC7E,CAAC;AA0EF,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,UAAU,CAAC,CAmCrB"}
|