@agentshouse/mdruntime 0.1.0-c2af3ddcc243b → 0.1.0-c2d73b235d7d7

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.
Files changed (266) hide show
  1. package/README.md +14 -13
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -3
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +62 -19
  6. package/dist/adapter.d.ts +201 -28
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts +0 -1
  9. package/dist/attached-model.d.ts.map +1 -1
  10. package/dist/attached-model.js +2 -7
  11. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  12. package/dist/attachment.d.ts.map +1 -0
  13. package/dist/attachment.js +15 -0
  14. package/dist/authored.d.ts +88 -0
  15. package/dist/authored.d.ts.map +1 -0
  16. package/dist/authored.js +345 -0
  17. package/dist/chain.d.ts +1 -1
  18. package/dist/chain.d.ts.map +1 -1
  19. package/dist/chain.js +5 -2
  20. package/dist/change.d.ts +6 -2
  21. package/dist/change.d.ts.map +1 -1
  22. package/dist/change.js +3 -0
  23. package/dist/chat-types.d.ts +0 -2
  24. package/dist/chat-types.d.ts.map +1 -1
  25. package/dist/chat-types.js +2 -4
  26. package/dist/client.d.ts +24 -8
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +26 -56
  29. package/dist/collection.d.ts +6 -1
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +23 -9
  32. package/dist/column.d.ts +5 -0
  33. package/dist/column.d.ts.map +1 -0
  34. package/dist/column.js +9 -0
  35. package/dist/compile.d.ts +2 -1
  36. package/dist/compile.d.ts.map +1 -1
  37. package/dist/compile.js +73 -42
  38. package/dist/connection.d.ts +1 -1
  39. package/dist/connection.d.ts.map +1 -1
  40. package/dist/connection.js +18 -8
  41. package/dist/context.d.ts.map +1 -1
  42. package/dist/context.js +1 -1
  43. package/dist/conversation-live.d.ts +19 -9
  44. package/dist/conversation-live.d.ts.map +1 -1
  45. package/dist/conversation-live.js +18 -8
  46. package/dist/conversation-row.d.ts +23 -1
  47. package/dist/conversation-row.d.ts.map +1 -1
  48. package/dist/conversation-row.js +37 -8
  49. package/dist/conversation.d.ts +26 -12
  50. package/dist/conversation.d.ts.map +1 -1
  51. package/dist/conversation.js +213 -160
  52. package/dist/declaration.js +3 -3
  53. package/dist/discovery.d.ts +3 -1
  54. package/dist/discovery.d.ts.map +1 -1
  55. package/dist/discovery.js +30 -5
  56. package/dist/download.d.ts +6 -0
  57. package/dist/download.d.ts.map +1 -0
  58. package/dist/download.js +42 -0
  59. package/dist/durability.d.ts +1 -0
  60. package/dist/durability.d.ts.map +1 -1
  61. package/dist/durability.js +3 -0
  62. package/dist/entry.d.ts +26 -1
  63. package/dist/entry.d.ts.map +1 -1
  64. package/dist/entry.js +126 -36
  65. package/dist/failure.d.ts.map +1 -1
  66. package/dist/failure.js +3 -1
  67. package/dist/figures.d.ts +1 -1
  68. package/dist/figures.d.ts.map +1 -1
  69. package/dist/figures.js +6 -4
  70. package/dist/file.d.ts +1 -1
  71. package/dist/file.d.ts.map +1 -1
  72. package/dist/file.js +3 -2
  73. package/dist/host.d.ts +7 -2
  74. package/dist/host.d.ts.map +1 -1
  75. package/dist/host.js +71 -29
  76. package/dist/house-query.d.ts +24 -0
  77. package/dist/house-query.d.ts.map +1 -0
  78. package/dist/house-query.js +102 -0
  79. package/dist/identity.d.ts +1 -1
  80. package/dist/identity.d.ts.map +1 -1
  81. package/dist/identity.js +1 -1
  82. package/dist/index.d.ts +21 -12
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +11 -5
  85. package/dist/install.d.ts +8 -2
  86. package/dist/install.d.ts.map +1 -1
  87. package/dist/install.js +40 -33
  88. package/dist/lifecycle.d.ts +1 -1
  89. package/dist/lifecycle.d.ts.map +1 -1
  90. package/dist/lifecycle.js +40 -25
  91. package/dist/linked-file.d.ts +7 -0
  92. package/dist/linked-file.d.ts.map +1 -0
  93. package/dist/linked-file.js +16 -0
  94. package/dist/listing.d.ts +24 -12
  95. package/dist/listing.d.ts.map +1 -1
  96. package/dist/listing.js +50 -21
  97. package/dist/live.d.ts +19 -3
  98. package/dist/live.d.ts.map +1 -1
  99. package/dist/live.js +94 -36
  100. package/dist/loaded.d.ts +7 -0
  101. package/dist/loaded.d.ts.map +1 -0
  102. package/dist/loaded.js +46 -0
  103. package/dist/locks.d.ts.map +1 -1
  104. package/dist/locks.js +4 -2
  105. package/dist/lost.js +1 -1
  106. package/dist/media.d.ts +19 -3
  107. package/dist/media.d.ts.map +1 -1
  108. package/dist/media.js +181 -34
  109. package/dist/memory.d.ts +7 -3
  110. package/dist/memory.d.ts.map +1 -1
  111. package/dist/memory.js +64 -23
  112. package/dist/messages.d.ts +12 -1
  113. package/dist/messages.d.ts.map +1 -1
  114. package/dist/messages.js +28 -6
  115. package/dist/modal.d.ts +2 -0
  116. package/dist/modal.d.ts.map +1 -0
  117. package/dist/modal.js +11 -0
  118. package/dist/model.d.ts +10 -7
  119. package/dist/model.d.ts.map +1 -1
  120. package/dist/model.js +7 -1
  121. package/dist/models.d.ts.map +1 -1
  122. package/dist/models.js +3 -3
  123. package/dist/name.d.ts +0 -1
  124. package/dist/name.d.ts.map +1 -1
  125. package/dist/name.js +3 -7
  126. package/dist/observation.d.ts +29 -12
  127. package/dist/observation.d.ts.map +1 -1
  128. package/dist/observation.js +206 -69
  129. package/dist/online.d.ts +7 -0
  130. package/dist/online.d.ts.map +1 -0
  131. package/dist/online.js +29 -0
  132. package/dist/opened.d.ts +5 -5
  133. package/dist/opened.d.ts.map +1 -1
  134. package/dist/opened.js +2 -2
  135. package/dist/opening.d.ts.map +1 -1
  136. package/dist/opening.js +20 -2
  137. package/dist/outcome.d.ts +30 -13
  138. package/dist/outcome.d.ts.map +1 -1
  139. package/dist/outcome.js +21 -6
  140. package/dist/overlay.d.ts +20 -9
  141. package/dist/overlay.d.ts.map +1 -1
  142. package/dist/overlay.js +110 -41
  143. package/dist/parts.d.ts +4 -1
  144. package/dist/parts.d.ts.map +1 -1
  145. package/dist/parts.js +30 -7
  146. package/dist/paths.d.ts +1 -1
  147. package/dist/paths.js +1 -1
  148. package/dist/preparation.d.ts +33 -7
  149. package/dist/preparation.d.ts.map +1 -1
  150. package/dist/preparation.js +195 -78
  151. package/dist/presence.d.ts +8 -2
  152. package/dist/presence.d.ts.map +1 -1
  153. package/dist/presence.js +24 -13
  154. package/dist/queries.d.ts +1 -1
  155. package/dist/queries.d.ts.map +1 -1
  156. package/dist/queries.js +115 -67
  157. package/dist/query.d.ts +2 -2
  158. package/dist/query.d.ts.map +1 -1
  159. package/dist/questions.d.ts +1 -0
  160. package/dist/questions.d.ts.map +1 -1
  161. package/dist/questions.js +3 -1
  162. package/dist/queue.d.ts +1 -1
  163. package/dist/queue.d.ts.map +1 -1
  164. package/dist/queue.js +55 -23
  165. package/dist/reach.d.ts +15 -6
  166. package/dist/reach.d.ts.map +1 -1
  167. package/dist/reach.js +140 -25
  168. package/dist/react.d.ts +12 -1
  169. package/dist/react.d.ts.map +1 -1
  170. package/dist/readiness.d.ts +22 -3
  171. package/dist/readiness.d.ts.map +1 -1
  172. package/dist/readiness.js +18 -10
  173. package/dist/reads.d.ts +1 -1
  174. package/dist/reads.d.ts.map +1 -1
  175. package/dist/reads.js +17 -6
  176. package/dist/recovery.d.ts +1 -0
  177. package/dist/recovery.d.ts.map +1 -1
  178. package/dist/recovery.js +2 -1
  179. package/dist/refresh.d.ts +1 -1
  180. package/dist/refresh.js +4 -4
  181. package/dist/replica.d.ts +3 -8
  182. package/dist/replica.d.ts.map +1 -1
  183. package/dist/replica.js +5 -5
  184. package/dist/room-draft.d.ts +29 -4
  185. package/dist/room-draft.d.ts.map +1 -1
  186. package/dist/room-draft.js +239 -18
  187. package/dist/room-drafts.d.ts.map +1 -1
  188. package/dist/room-drafts.js +12 -7
  189. package/dist/room-list.d.ts +10 -0
  190. package/dist/room-list.d.ts.map +1 -0
  191. package/dist/room-list.js +47 -0
  192. package/dist/rows.d.ts +11 -3
  193. package/dist/rows.d.ts.map +1 -1
  194. package/dist/rows.js +25 -11
  195. package/dist/run-tables.d.ts +25 -0
  196. package/dist/run-tables.d.ts.map +1 -0
  197. package/dist/run-tables.js +98 -0
  198. package/dist/running.d.ts +5 -0
  199. package/dist/running.d.ts.map +1 -0
  200. package/dist/running.js +10 -0
  201. package/dist/runs.d.ts +27 -0
  202. package/dist/runs.d.ts.map +1 -0
  203. package/dist/runs.js +92 -0
  204. package/dist/runtime.d.ts +7 -3
  205. package/dist/runtime.d.ts.map +1 -1
  206. package/dist/save.d.ts +1 -0
  207. package/dist/save.d.ts.map +1 -1
  208. package/dist/save.js +31 -96
  209. package/dist/saves.d.ts +7 -5
  210. package/dist/saves.d.ts.map +1 -1
  211. package/dist/saves.js +109 -55
  212. package/dist/seed.d.ts.map +1 -1
  213. package/dist/seed.js +2 -2
  214. package/dist/selector.d.ts +3 -0
  215. package/dist/selector.d.ts.map +1 -0
  216. package/dist/selector.js +22 -0
  217. package/dist/shown.d.ts +4 -2
  218. package/dist/shown.d.ts.map +1 -1
  219. package/dist/shown.js +83 -51
  220. package/dist/socket/session.d.ts +4 -1
  221. package/dist/socket/session.d.ts.map +1 -1
  222. package/dist/socket/session.js +3 -0
  223. package/dist/socket.d.ts +4 -1
  224. package/dist/socket.d.ts.map +1 -1
  225. package/dist/socket.js +8 -0
  226. package/dist/source.d.ts +42 -0
  227. package/dist/source.d.ts.map +1 -1
  228. package/dist/source.js +76 -9
  229. package/dist/store/installs.d.ts +2 -2
  230. package/dist/store/installs.d.ts.map +1 -1
  231. package/dist/store/installs.js +10 -4
  232. package/dist/store/readiness.d.ts +5 -4
  233. package/dist/store/readiness.d.ts.map +1 -1
  234. package/dist/store/readiness.js +28 -12
  235. package/dist/store/records.d.ts +25 -5
  236. package/dist/store/records.d.ts.map +1 -1
  237. package/dist/store/records.js +59 -23
  238. package/dist/store/rooms-shown.d.ts +8 -0
  239. package/dist/store/rooms-shown.d.ts.map +1 -0
  240. package/dist/store/rooms-shown.js +13 -0
  241. package/dist/store.d.ts +15 -10
  242. package/dist/store.d.ts.map +1 -1
  243. package/dist/store.js +12 -5
  244. package/dist/stored.d.ts +40 -16
  245. package/dist/stored.d.ts.map +1 -1
  246. package/dist/stored.js +210 -52
  247. package/dist/surface.d.ts +19 -7
  248. package/dist/surface.d.ts.map +1 -1
  249. package/dist/surface.js +55 -17
  250. package/dist/sync.d.ts +4 -2
  251. package/dist/sync.d.ts.map +1 -1
  252. package/dist/sync.js +49 -27
  253. package/dist/tables.d.ts +34 -49
  254. package/dist/tables.d.ts.map +1 -1
  255. package/dist/tables.js +84 -325
  256. package/dist/tallies.d.ts.map +1 -1
  257. package/dist/tallies.js +3 -4
  258. package/dist/validation.d.ts +2 -0
  259. package/dist/validation.d.ts.map +1 -1
  260. package/dist/validation.js +50 -10
  261. package/dist/wire.d.ts +30 -14
  262. package/dist/wire.d.ts.map +1 -1
  263. package/dist/wire.js +19 -13
  264. package/package.json +4 -4
  265. package/dist/binary.d.ts.map +0 -1
  266. 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 OWNERS = ['authored_pending', 'authored_room_drafts', 'authored_calls'];
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: heldOrder(connection, locator).map((id) => {
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
- queued: texts(connection.rows('SELECT locator FROM authored_queues'), 'locator'),
280
- lastCompleted: completed === undefined ? null : text(completed.value),
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: held === undefined ? null : text(held.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(conversationTables().flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation'))),
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 conversationTables()) {
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 chatDraft(connection, { kept: drafts, dropped }) {
427
- for (const conversation of dropped) {
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
- unowned(connection);
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 unfenced(connection, locators) {
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
- for (const locator of erased) {
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
- for (const [table] of TABLES)
483
- connection.run(`DELETE FROM ${table}`);
244
+ authoredEmptied(connection);
484
245
  connection.run('DELETE FROM opened_files');
485
- connection.run('DELETE FROM file_parts');
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
- unowned(connection);
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
- storedPart(connection, key, part, bytes);
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 file_parts WHERE key = ?', [key]);
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 file_parts WHERE key = ?', [key]);
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
- unowned(connection);
306
+ unopened(connection);
545
307
  return true;
546
308
  }
547
- const UNSENT = [
548
- ['pending-change', 'authored_pending'],
549
- ['call', 'authored_calls'],
550
- ['room-draft', 'authored_room_drafts'],
551
- ['chat-draft', 'authored_chat_drafts'],
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(CLEANABLE_BYTES);
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
- unowned(connection);
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
- const [held] = connection.rows('SELECT batch FROM authored_pending WHERE locator = ? AND id = ?', [request.locator, request.id]);
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 texts(connection.rows('SELECT locator FROM authored_queues'), 'locator');
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 texts(connection.rows('SELECT record FROM authored_chat_drafts'), 'record');
363
+ return chatDraftRecords(connection);
617
364
  case 'authored.calls':
618
- return texts(connection.rows('SELECT record FROM authored_calls'), 'record');
365
+ return callRecords(connection);
619
366
  case 'authored.fences':
620
- return texts(connection.rows('SELECT locator FROM authored_fences'), 'locator');
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 { held: heldLocators(connection), staged: stagedLocators(connection) };
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 unfenced(connection, request.locators);
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 filePart(connection, request.key, request.part);
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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tallies.d.ts","sourceRoot":"","sources":["../src/tallies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAI1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;IAC7E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAmHpG,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAwBb;AA0BD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EACvC,KAAK,EAAE,MAAM,GACZ,iBAAiB,EAAE,CAerB"}
1
+ {"version":3,"file":"tallies.d.ts","sourceRoot":"","sources":["../src/tallies.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAI1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;IAC7E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAmHpG,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,EAAE,CAwBb;AA0BD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EACvC,KAAK,EAAE,MAAM,GACZ,iBAAiB,EAAE,CAerB"}
package/dist/tallies.js CHANGED
@@ -1,14 +1,13 @@
1
- import { instantKey, sql } from '@agentshouse/mdmodel';
2
- import { CHAT_MESSAGE_TYPE, CHAT_TYPE } from './chat-types.js';
1
+ import { CHAT_MESSAGE_TYPE, CHAT_TYPE, instantKey, sql } from '@agentshouse/mdmodel';
3
2
  import { answerQuery, VISIBLE, within } from './compile.js';
4
- import { HOUSE_DIRECTORY } from './figures.js';
3
+ import { HOUSE_FOLDER } from './figures.js';
5
4
  const NONE = { count: 0, size: 0 };
6
5
  const { all, fragment, joined } = sql;
7
6
  function instant(value) {
8
7
  return typeof value === 'string' ? value : null;
9
8
  }
10
9
  function held(alias, keys) {
11
- const reserved = within(alias, HOUSE_DIRECTORY);
10
+ const reserved = within(alias, HOUSE_FOLDER);
12
11
  return all([
13
12
  fragment(`${alias}.key IN (SELECT value FROM json_each(?))`, [JSON.stringify(keys)]),
14
13
  fragment(VISIBLE(alias)),
@@ -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 {};