@agentshouse/mdruntime 0.1.0-c4ca57eefb98a → 0.1.0-c4d7cf2ec26a6

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 (289) hide show
  1. package/README.md +2 -2
  2. package/dist/acceptance.d.ts +6 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +386 -0
  5. package/dist/actions.d.ts +20 -0
  6. package/dist/actions.d.ts.map +1 -0
  7. package/dist/actions.js +251 -0
  8. package/dist/adapter.d.ts +86 -67
  9. package/dist/adapter.d.ts.map +1 -1
  10. package/dist/attached-model.d.ts +3 -10
  11. package/dist/attached-model.d.ts.map +1 -1
  12. package/dist/attached-model.js +21 -56
  13. package/dist/bootstrap.d.ts +11 -10
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +219 -82
  16. package/dist/cell.d.ts +6 -0
  17. package/dist/cell.d.ts.map +1 -0
  18. package/dist/cell.js +9 -0
  19. package/dist/chain.d.ts +2 -1
  20. package/dist/chain.d.ts.map +1 -1
  21. package/dist/chain.js +3 -7
  22. package/dist/change.d.ts +1 -0
  23. package/dist/change.d.ts.map +1 -1
  24. package/dist/change.js +4 -2
  25. package/dist/chat-types.d.ts +5 -0
  26. package/dist/chat-types.d.ts.map +1 -0
  27. package/dist/chat-types.js +13 -0
  28. package/dist/client.d.ts +21 -6
  29. package/dist/client.d.ts.map +1 -1
  30. package/dist/client.js +3 -1
  31. package/dist/collection.d.ts +2 -4
  32. package/dist/collection.d.ts.map +1 -1
  33. package/dist/collection.js +1 -17
  34. package/dist/compile.d.ts +6 -6
  35. package/dist/compile.d.ts.map +1 -1
  36. package/dist/compile.js +267 -323
  37. package/dist/connection.d.ts +5 -143
  38. package/dist/connection.d.ts.map +1 -1
  39. package/dist/connection.js +102 -5311
  40. package/dist/context.d.ts +2 -0
  41. package/dist/context.d.ts.map +1 -0
  42. package/dist/context.js +7 -0
  43. package/dist/conversation-live.d.ts +136 -0
  44. package/dist/conversation-live.d.ts.map +1 -0
  45. package/dist/conversation-live.js +248 -0
  46. package/dist/conversation-row.d.ts +33 -0
  47. package/dist/conversation-row.d.ts.map +1 -0
  48. package/dist/conversation-row.js +53 -0
  49. package/dist/conversation.d.ts +41 -45
  50. package/dist/conversation.d.ts.map +1 -1
  51. package/dist/conversation.js +860 -869
  52. package/dist/discovery.d.ts +10 -0
  53. package/dist/discovery.d.ts.map +1 -0
  54. package/dist/discovery.js +175 -0
  55. package/dist/durability.d.ts +15 -1
  56. package/dist/durability.d.ts.map +1 -1
  57. package/dist/entry.d.ts +2 -2
  58. package/dist/entry.d.ts.map +1 -1
  59. package/dist/entry.js +17 -7
  60. package/dist/figures.d.ts +49 -0
  61. package/dist/figures.d.ts.map +1 -0
  62. package/dist/figures.js +197 -0
  63. package/dist/holdings.d.ts +29 -0
  64. package/dist/holdings.d.ts.map +1 -0
  65. package/dist/holdings.js +95 -0
  66. package/dist/host.d.ts +4 -7
  67. package/dist/host.d.ts.map +1 -1
  68. package/dist/host.js +29 -31
  69. package/dist/identity.d.ts +0 -1
  70. package/dist/identity.d.ts.map +1 -1
  71. package/dist/identity.js +0 -3
  72. package/dist/index.d.ts +26 -8
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +8 -1
  75. package/dist/install.d.ts +56 -0
  76. package/dist/install.d.ts.map +1 -0
  77. package/dist/install.js +554 -0
  78. package/dist/job.d.ts +33 -0
  79. package/dist/job.d.ts.map +1 -0
  80. package/dist/job.js +54 -0
  81. package/dist/lifecycle.d.ts +7 -0
  82. package/dist/lifecycle.d.ts.map +1 -0
  83. package/dist/lifecycle.js +268 -0
  84. package/dist/listing.d.ts +53 -0
  85. package/dist/listing.d.ts.map +1 -0
  86. package/dist/listing.js +176 -0
  87. package/dist/live.d.ts +5 -4
  88. package/dist/live.d.ts.map +1 -1
  89. package/dist/live.js +62 -23
  90. package/dist/locks.d.ts +9 -0
  91. package/dist/locks.d.ts.map +1 -0
  92. package/dist/locks.js +61 -0
  93. package/dist/log.d.ts +1 -0
  94. package/dist/log.d.ts.map +1 -1
  95. package/dist/lost.d.ts +5 -0
  96. package/dist/lost.d.ts.map +1 -0
  97. package/dist/lost.js +61 -0
  98. package/dist/media.d.ts +1 -1
  99. package/dist/media.d.ts.map +1 -1
  100. package/dist/media.js +19 -9
  101. package/dist/memory.d.ts +11 -4
  102. package/dist/memory.d.ts.map +1 -1
  103. package/dist/memory.js +172 -82
  104. package/dist/messages.d.ts +27 -3
  105. package/dist/messages.d.ts.map +1 -1
  106. package/dist/messages.js +97 -19
  107. package/dist/model.d.ts +2 -10
  108. package/dist/model.d.ts.map +1 -1
  109. package/dist/model.js +0 -18
  110. package/dist/models.d.ts +14 -0
  111. package/dist/models.d.ts.map +1 -0
  112. package/dist/models.js +195 -0
  113. package/dist/observation.d.ts +2 -2
  114. package/dist/observation.d.ts.map +1 -1
  115. package/dist/observation.js +14 -14
  116. package/dist/opened.js +3 -3
  117. package/dist/opening.d.ts +4 -0
  118. package/dist/opening.d.ts.map +1 -0
  119. package/dist/opening.js +57 -0
  120. package/dist/outcome.d.ts +4 -4
  121. package/dist/outcome.d.ts.map +1 -1
  122. package/dist/outcome.js +3 -0
  123. package/dist/overlay.d.ts +1 -0
  124. package/dist/overlay.d.ts.map +1 -1
  125. package/dist/overlay.js +11 -0
  126. package/dist/parts.d.ts +60 -0
  127. package/dist/parts.d.ts.map +1 -0
  128. package/dist/parts.js +126 -0
  129. package/dist/paths.d.ts +1 -0
  130. package/dist/paths.d.ts.map +1 -1
  131. package/dist/paths.js +22 -0
  132. package/dist/preparation.d.ts +20 -0
  133. package/dist/preparation.d.ts.map +1 -0
  134. package/dist/preparation.js +226 -0
  135. package/dist/queries.d.ts +16 -0
  136. package/dist/queries.d.ts.map +1 -0
  137. package/dist/queries.js +272 -0
  138. package/dist/query.d.ts +14 -209
  139. package/dist/query.d.ts.map +1 -1
  140. package/dist/query.js +3 -505
  141. package/dist/questions.d.ts +34 -0
  142. package/dist/questions.d.ts.map +1 -0
  143. package/dist/questions.js +122 -0
  144. package/dist/reach.d.ts +15 -13
  145. package/dist/reach.d.ts.map +1 -1
  146. package/dist/reach.js +183 -137
  147. package/dist/react.d.ts +10 -2
  148. package/dist/react.d.ts.map +1 -1
  149. package/dist/read.d.ts +7 -0
  150. package/dist/read.d.ts.map +1 -0
  151. package/dist/read.js +17 -0
  152. package/dist/readiness.d.ts +2 -16
  153. package/dist/readiness.d.ts.map +1 -1
  154. package/dist/readiness.js +4 -10
  155. package/dist/reads.d.ts +36 -10
  156. package/dist/reads.d.ts.map +1 -1
  157. package/dist/reads.js +158 -78
  158. package/dist/recovery.d.ts +1 -0
  159. package/dist/recovery.d.ts.map +1 -1
  160. package/dist/recovery.js +35 -1
  161. package/dist/refresh.d.ts +7 -5
  162. package/dist/refresh.d.ts.map +1 -1
  163. package/dist/refresh.js +33 -5
  164. package/dist/refusal.d.ts +5 -0
  165. package/dist/refusal.d.ts.map +1 -0
  166. package/dist/refusal.js +56 -0
  167. package/dist/replica.d.ts +9 -9
  168. package/dist/replica.d.ts.map +1 -1
  169. package/dist/replica.js +53 -21
  170. package/dist/room-draft.d.ts +4 -3
  171. package/dist/room-draft.d.ts.map +1 -1
  172. package/dist/room-draft.js +67 -54
  173. package/dist/room-drafts.d.ts +24 -0
  174. package/dist/room-drafts.d.ts.map +1 -0
  175. package/dist/room-drafts.js +217 -0
  176. package/dist/rows.d.ts +14 -21
  177. package/dist/rows.d.ts.map +1 -1
  178. package/dist/rows.js +48 -184
  179. package/dist/runtime.d.ts +43 -0
  180. package/dist/runtime.d.ts.map +1 -0
  181. package/dist/runtime.js +1 -0
  182. package/dist/save.d.ts +5 -1
  183. package/dist/save.d.ts.map +1 -1
  184. package/dist/save.js +21 -20
  185. package/dist/saves.d.ts +70 -0
  186. package/dist/saves.d.ts.map +1 -0
  187. package/dist/saves.js +1005 -0
  188. package/dist/search.d.ts +12 -63
  189. package/dist/search.d.ts.map +1 -1
  190. package/dist/search.js +9 -52
  191. package/dist/seed.d.ts +11 -2
  192. package/dist/seed.d.ts.map +1 -1
  193. package/dist/seed.js +71 -0
  194. package/dist/shared.d.ts +1 -7
  195. package/dist/shared.d.ts.map +1 -1
  196. package/dist/shared.js +13 -105
  197. package/dist/shown.d.ts +31 -0
  198. package/dist/shown.d.ts.map +1 -0
  199. package/dist/shown.js +292 -0
  200. package/dist/socket/admission.d.ts +7 -0
  201. package/dist/socket/admission.d.ts.map +1 -0
  202. package/dist/socket/admission.js +39 -0
  203. package/dist/socket/answers.d.ts +6 -0
  204. package/dist/socket/answers.d.ts.map +1 -0
  205. package/dist/socket/answers.js +20 -0
  206. package/dist/socket/lanes.d.ts +20 -0
  207. package/dist/socket/lanes.d.ts.map +1 -0
  208. package/dist/socket/lanes.js +77 -0
  209. package/dist/socket/reads.d.ts +10 -0
  210. package/dist/socket/reads.d.ts.map +1 -0
  211. package/dist/socket/reads.js +31 -0
  212. package/dist/socket/rooms.d.ts +44 -0
  213. package/dist/socket/rooms.d.ts.map +1 -0
  214. package/dist/socket/rooms.js +90 -0
  215. package/dist/socket/session.d.ts +39 -0
  216. package/dist/socket/session.d.ts.map +1 -0
  217. package/dist/socket/session.js +23 -0
  218. package/dist/socket.d.ts +70 -0
  219. package/dist/socket.d.ts.map +1 -0
  220. package/dist/socket.js +175 -0
  221. package/dist/source.d.ts +61 -0
  222. package/dist/source.d.ts.map +1 -0
  223. package/dist/source.js +82 -0
  224. package/dist/status.d.ts +0 -6
  225. package/dist/status.d.ts.map +1 -1
  226. package/dist/status.js +0 -6
  227. package/dist/store/fences.d.ts +16 -0
  228. package/dist/store/fences.d.ts.map +1 -0
  229. package/dist/store/fences.js +26 -0
  230. package/dist/store/installs.d.ts +30 -0
  231. package/dist/store/installs.d.ts.map +1 -0
  232. package/dist/store/installs.js +34 -0
  233. package/dist/store/readiness.d.ts +10 -0
  234. package/dist/store/readiness.d.ts.map +1 -0
  235. package/dist/store/readiness.js +52 -0
  236. package/dist/store/records.d.ts +212 -0
  237. package/dist/store/records.d.ts.map +1 -0
  238. package/dist/store/records.js +431 -0
  239. package/dist/store/room-held.d.ts +8 -0
  240. package/dist/store/room-held.d.ts.map +1 -0
  241. package/dist/store/room-held.js +17 -0
  242. package/dist/store/space.d.ts +11 -0
  243. package/dist/store/space.d.ts.map +1 -0
  244. package/dist/store/space.js +41 -0
  245. package/dist/store/watchers.d.ts +17 -0
  246. package/dist/store/watchers.d.ts.map +1 -0
  247. package/dist/store/watchers.js +56 -0
  248. package/dist/store/writes.d.ts +24 -0
  249. package/dist/store/writes.d.ts.map +1 -0
  250. package/dist/store/writes.js +125 -0
  251. package/dist/store.d.ts +107 -157
  252. package/dist/store.d.ts.map +1 -1
  253. package/dist/store.js +143 -395
  254. package/dist/stored.d.ts +59 -38
  255. package/dist/stored.d.ts.map +1 -1
  256. package/dist/stored.js +285 -205
  257. package/dist/surface.d.ts +88 -0
  258. package/dist/surface.d.ts.map +1 -0
  259. package/dist/surface.js +223 -0
  260. package/dist/sync.d.ts +19 -0
  261. package/dist/sync.d.ts.map +1 -0
  262. package/dist/sync.js +532 -0
  263. package/dist/tables.d.ts +120 -56
  264. package/dist/tables.d.ts.map +1 -1
  265. package/dist/tables.js +217 -98
  266. package/dist/tallies.d.ts +18 -0
  267. package/dist/tallies.d.ts.map +1 -0
  268. package/dist/tallies.js +129 -0
  269. package/dist/transfer.d.ts +0 -5
  270. package/dist/transfer.d.ts.map +1 -1
  271. package/dist/validation.d.ts +3 -4
  272. package/dist/validation.d.ts.map +1 -1
  273. package/dist/validation.js +42 -100
  274. package/dist/windows.d.ts +1 -12
  275. package/dist/windows.d.ts.map +1 -1
  276. package/dist/windows.js +2 -75
  277. package/dist/wire.d.ts +17 -5
  278. package/dist/wire.d.ts.map +1 -1
  279. package/dist/wire.js +7 -1
  280. package/package.json +2 -2
  281. package/dist/fence.d.ts +0 -6
  282. package/dist/fence.d.ts.map +0 -1
  283. package/dist/fence.js +0 -10
  284. package/dist/fulltext.d.ts +0 -27
  285. package/dist/fulltext.d.ts.map +0 -1
  286. package/dist/fulltext.js +0 -370
  287. package/dist/words.d.ts +0 -19
  288. package/dist/words.d.ts.map +0 -1
  289. package/dist/words.js +0 -156
@@ -0,0 +1,24 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
24
+ //# sourceMappingURL=room-drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,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S,CAAC,CAMnC;AA0CD,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,WAAW,EAAE,OAAO,EACpB,OAAO,GAAE,SAAS,CAAC,WAAW,CAAC,GAAG,IAAW,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuBf;AAOD,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvF;AAoDD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAkDnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CA8BzE;AAED,wBAAgB,eAAe,CAC7B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CAiBZ;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CASZ"}
@@ -0,0 +1,217 @@
1
+ import { plain } from '@agentshouse/mdmodel';
2
+ import { changeSet } from './change-set.js';
3
+ import { collectionOf } from './collection.js';
4
+ import { runtimeError } from './failure.js';
5
+ import { roomDraftRevision } from './identity.js';
6
+ import { normalize } from './paths.js';
7
+ import { slicing } from './replica.js';
8
+ import { binaryBase, gatheredParts, held, heldFile, readParts, staleWrite, underneath, } from './room-draft.js';
9
+ import { stepped } from './turn.js';
10
+ const ROOM_DRAFTS = 'room-drafts';
11
+ const presentationTopic = (app) => `presentation\u0000${app}`;
12
+ export async function visibleOf(store, locator, paths) {
13
+ const kept = await store.record(locator);
14
+ if (kept === undefined)
15
+ return undefined;
16
+ const local = await store.open();
17
+ const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
18
+ return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
19
+ }
20
+ function roomDraftOf(record, visible) {
21
+ return structuredClone({
22
+ room: record.locator,
23
+ path: record.path,
24
+ revision: record.revision,
25
+ parts: record.parts,
26
+ changedUnderneath: underneath(record.parts, record.path, visible),
27
+ returned: record.returned,
28
+ });
29
+ }
30
+ async function roomDraftsOf(store, records) {
31
+ const rooms = new Map();
32
+ for (const record of records) {
33
+ const paths = rooms.get(record.locator) ?? [];
34
+ paths.push(record.path);
35
+ rooms.set(record.locator, paths);
36
+ }
37
+ const layers = new Map();
38
+ for (const [locator, paths] of rooms) {
39
+ layers.set(locator, await visibleOf(store, locator, paths));
40
+ }
41
+ return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
42
+ }
43
+ function inOrder(records) {
44
+ return [...records].sort((left, right) => {
45
+ if (left.locator !== right.locator)
46
+ return left.locator < right.locator ? -1 : 1;
47
+ if (left.path !== right.path)
48
+ return left.path < right.path ? -1 : 1;
49
+ return 0;
50
+ });
51
+ }
52
+ async function snapshotRoomDrafts(store) {
53
+ return roomDraftsOf(store, inOrder(await store.drafts()));
54
+ }
55
+ export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
56
+ const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
57
+ if (unwatched())
58
+ return Promise.resolve();
59
+ return store.publication(async () => {
60
+ if (unwatched())
61
+ return;
62
+ const records = await store.drafts();
63
+ if (socket.closed())
64
+ return;
65
+ if (touched !== null &&
66
+ !records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
67
+ return;
68
+ }
69
+ const value = await roomDraftsOf(store, inOrder(records));
70
+ if (socket.closed())
71
+ return;
72
+ const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
73
+ for (const watcher of answered)
74
+ watcher.answer(value);
75
+ });
76
+ }
77
+ async function presentationOf(store, app) {
78
+ const value = await (await store.open()).presentation(app);
79
+ return value === undefined ? null : structuredClone(value);
80
+ }
81
+ export function emitPresentation({ store, socket }, app) {
82
+ const topic = presentationTopic(app);
83
+ const listening = () => store.watching(topic, 'ready');
84
+ if (socket.closed() || listening().length === 0)
85
+ return Promise.resolve();
86
+ return store.publication(async () => {
87
+ if (socket.closed() || listening().length === 0)
88
+ return;
89
+ const value = await presentationOf(store, app);
90
+ if (socket.closed())
91
+ return;
92
+ for (const watcher of listening())
93
+ watcher.answer(value);
94
+ });
95
+ }
96
+ async function writtenRoomDraft({ store }, room, path, revision, input, next) {
97
+ const parts = readParts(input, path);
98
+ if (path === '' || normalize(path) !== path)
99
+ throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
100
+ const local = await store.open();
101
+ const current = await store.draft(room, path);
102
+ if ((current?.revision ?? null) !== revision) {
103
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
104
+ }
105
+ const file = parts.file === undefined
106
+ ? undefined
107
+ : await heldFile(parts.file.blob, parts.file.base === undefined
108
+ ? binaryBase(await visibleOf(store, room, [path]), path)
109
+ : parts.file.base);
110
+ const record = {
111
+ locator: room,
112
+ path,
113
+ revision: next,
114
+ parts: held(current?.parts, parts, file),
115
+ returned: current?.returned ?? null,
116
+ };
117
+ await local.keepRoomDraft(record, parts.file === undefined || file === undefined
118
+ ? []
119
+ : [{ key: file.localId, blob: parts.file.blob }]);
120
+ await store.changed(changeSet(room, { drafts: [path] }));
121
+ return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
122
+ }
123
+ async function keptPresentation({ store }, app, value) {
124
+ await (await store.open()).present({ app, value });
125
+ await store.changed(changeSet('', { presentation: app }));
126
+ }
127
+ export function roomDraftSurface(runtime) {
128
+ const { store } = runtime;
129
+ return {
130
+ list() {
131
+ return store
132
+ .exclusive(async () => {
133
+ await store.open();
134
+ return snapshotRoomDrafts(store);
135
+ })
136
+ .then((listed) => {
137
+ publishRoomDrafts(runtime, true);
138
+ return listed;
139
+ });
140
+ },
141
+ async read(room, path) {
142
+ const record = await store.draft(room, path);
143
+ return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
144
+ },
145
+ write(room, path, revision, input, next = roomDraftRevision()) {
146
+ if (typeof next !== 'string' || next === '')
147
+ return Promise.reject(runtimeError('room-draft-malformed'));
148
+ return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
149
+ if (later.revision !== earlier.next)
150
+ return null;
151
+ const parts = gatheredParts(earlier.input, later.input);
152
+ return parts === null
153
+ ? null
154
+ : { revision: earlier.revision, input: parts, next: later.next };
155
+ }, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
156
+ },
157
+ discard(room, path, revision) {
158
+ return store.exclusive(async () => {
159
+ const local = await store.open();
160
+ const current = await store.draft(room, path);
161
+ if (current === undefined || current.revision !== revision) {
162
+ return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
163
+ }
164
+ await local.discardRoomDraft(room, path);
165
+ await store.changed(changeSet(room, { drafts: [path] }));
166
+ return { outcome: 'written', roomDraft: null };
167
+ });
168
+ },
169
+ };
170
+ }
171
+ export function presentationSurface(runtime) {
172
+ const { store } = runtime;
173
+ return {
174
+ read(app) {
175
+ return store.exclusive(() => presentationOf(store, app));
176
+ },
177
+ write(app, value) {
178
+ return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
179
+ },
180
+ edit(app, members) {
181
+ return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
182
+ const kept = await (await store.open()).presentation(app);
183
+ await keptPresentation(runtime, app, Object.fromEntries([
184
+ ...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
185
+ ...Object.entries(edited).filter(([, value]) => value !== null),
186
+ ]));
187
+ });
188
+ },
189
+ };
190
+ }
191
+ export function watchRoomDrafts({ store, socket }, deliver) {
192
+ const watcher = store.watch(ROOM_DRAFTS, deliver);
193
+ const unwatched = () => socket.closed() || !watcher.held();
194
+ void store
195
+ .exclusive(async () => {
196
+ await store.open();
197
+ })
198
+ .then(() => store.publication(async () => {
199
+ if (unwatched())
200
+ return;
201
+ const value = await snapshotRoomDrafts(store);
202
+ if (!unwatched())
203
+ watcher.answer(value);
204
+ }), () => { });
205
+ return watcher.stop;
206
+ }
207
+ export function watchPresentation({ store, socket }, app, deliver) {
208
+ const watcher = store.watch(presentationTopic(app), deliver);
209
+ void store
210
+ .exclusive(async () => {
211
+ const value = await presentationOf(store, app);
212
+ if (!socket.closed() && watcher.held())
213
+ watcher.answer(value);
214
+ })
215
+ .catch(() => { });
216
+ return watcher.stop;
217
+ }
package/dist/rows.d.ts CHANGED
@@ -1,14 +1,7 @@
1
+ import { type HeldValue } from '@agentshouse/mdmodel';
2
+ import type { SavedFacts } from './adapter.js';
1
3
  import { type Composition } from './collection.js';
2
- export type ValueKind = 'string' | 'number' | 'boolean' | 'null' | 'array' | 'object' | 'undefined';
3
- type HeldValue = {
4
- readonly keys: string;
5
- readonly places: string;
6
- readonly item: number;
7
- readonly kind: ValueKind;
8
- readonly value: string | number | null;
9
- readonly size: number | null;
10
- };
11
- type LinkKind = 'field' | 'section' | 'body';
4
+ type LinkKind = 'field' | 'link';
12
5
  type HeldLink = {
13
6
  readonly kind: LinkKind;
14
7
  readonly keys: string;
@@ -22,8 +15,14 @@ export type Described = {
22
15
  readonly queried: boolean;
23
16
  readonly folder: string;
24
17
  readonly fields: string | null;
18
+ readonly links: string | null;
19
+ };
20
+ export type Held = {
21
+ readonly type: string | null;
22
+ readonly fields: Readonly<Record<string, unknown>> | null;
23
+ readonly links: readonly string[];
25
24
  };
26
- export type Derived = Described & {
25
+ export type Derived = {
27
26
  readonly values: readonly HeldValue[];
28
27
  readonly links: readonly HeldLink[];
29
28
  };
@@ -32,15 +31,9 @@ export declare function roomOfKey(key: string): string;
32
31
  export declare function pathOfKey(key: string): string;
33
32
  export declare function markdownPath(path: string): boolean;
34
33
  export declare function folderOf(path: string): string;
35
- export type Reach = 'exact' | 'value' | 'link';
36
- export type Placed = {
37
- readonly keys: string;
38
- readonly places: string;
39
- readonly glob: boolean;
40
- };
41
- export declare function placedOf(pointer: string, reach: Reach): Placed;
42
- export declare function kindOf(value: unknown): ValueKind;
43
- export declare function described(path: string, content: string | null): Described;
44
- export declare function derived(path: string, content: string | null, composition: Composition): Derived;
34
+ export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
35
+ export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
36
+ export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
37
+ export declare function derived(path: string, held: Held, composition: Composition): Derived;
45
38
  export {};
46
39
  //# sourceMappingURL=rows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAWA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpG,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,KAAK,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7C,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE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I,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAYnF"}
package/dist/rows.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ARRAY_INDEX, bodyAfterFrontmatter, bodyLinks, escapePointer, parseFrontmatter, references, sectionReferences, target, } from '@agentshouse/mdmodel';
1
+ import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
2
2
  import { governing } from './collection.js';
3
3
  import { definitionOf } from './model.js';
4
4
  function keyOf(...parts) {
@@ -19,196 +19,60 @@ export function markdownPath(path) {
19
19
  export function folderOf(path) {
20
20
  return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
21
21
  }
22
- export function placedOf(pointer, reach) {
23
- const [first = '', ...rest] = pointer.split('/').slice(1);
24
- const keys = [first];
25
- const gaps = [[]];
26
- for (const segment of rest) {
27
- if (ARRAY_INDEX.test(segment)) {
28
- gaps.at(-1).push(segment);
29
- continue;
30
- }
31
- keys.push(segment);
32
- gaps.push([]);
33
- }
34
- const places = gaps
35
- .map((gap, at) => {
36
- const open = at < gaps.length - 1 ? reach !== 'exact' : reach === 'link';
37
- return `/${gap.map((number) => `[.:]${number}`).join('')}.${open ? '*' : ''}`;
38
- })
39
- .join('');
40
- return {
41
- keys: keys.map((key) => `/${key}`).join(''),
42
- places,
43
- glob: /[[*]/u.test(places),
44
- };
45
- }
46
- function placesOf({ done, head, tail }) {
47
- return `${done}/${head}${tail}.`;
48
- }
49
- function throughOf(keys, places) {
50
- const gaps = places.split('/').slice(1);
51
- return keys
52
- .split('/')
53
- .slice(1)
54
- .map((key, at) => `/${key}${gaps[at].replace(/\.\d*/gu, '').replaceAll(':', '/')}`)
55
- .join('');
56
- }
57
- function plainObject(value) {
58
- return typeof value === 'object' && value !== null && !Array.isArray(value);
59
- }
60
- function compared(reading, exact, value) {
61
- if (!reading.references.has(exact))
62
- return value;
63
- return (typeof value === 'string' ? target(reading.path, value) : null) ?? undefined;
64
- }
65
- export function kindOf(value) {
66
- if (value === undefined)
67
- return 'undefined';
68
- if (value === null)
69
- return 'null';
70
- if (Array.isArray(value))
71
- return 'array';
72
- if (typeof value === 'object')
73
- return 'object';
74
- return typeof value;
75
- }
76
- function scalarOf(value) {
77
- if (typeof value === 'string' || typeof value === 'number')
22
+ function byKey(_key, value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
78
24
  return value;
79
- if (typeof value === 'boolean')
80
- return value ? 1 : 0;
81
- if (Array.isArray(value))
82
- return JSON.stringify(value);
83
- return null;
25
+ return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
84
26
  }
85
- function held(reading, keys, places, value) {
86
- reading.values.push({
87
- keys,
88
- places,
89
- item: -1,
90
- kind: kindOf(value),
91
- value: scalarOf(value),
92
- size: Array.isArray(value) ? value.length : null,
93
- });
94
- if (!Array.isArray(value))
95
- return;
96
- value.forEach((item, index) => {
97
- const itemKind = kindOf(item);
98
- reading.values.push({
99
- keys,
100
- places,
101
- item: index,
102
- kind: itemKind,
103
- value: itemKind === 'array' ? null : scalarOf(item),
104
- size: null,
105
- });
106
- });
27
+ function fieldsText(fields) {
28
+ return JSON.stringify(fields, byKey);
107
29
  }
108
- function record(reading, node, at) {
109
- const value = Array.isArray(node)
110
- ? node.map((item, index) => compared(reading, `${at.exact}/${index}`, item))
111
- : compared(reading, at.exact, node);
112
- const places = placesOf(at);
113
- held(reading, at.keys, places, value);
114
- if (typeof value !== 'string' || !reading.references.has(at.exact))
115
- return;
116
- reading.links.push({
117
- kind: 'field',
118
- keys: at.keys,
119
- places,
120
- target: value,
121
- field: throughOf(at.keys, places),
30
+ export function writtenFacts(path, content, composition) {
31
+ const model = governing(composition, path);
32
+ const facts = documentFacts(path, parse(content, path), {
33
+ types: model.status === 'unavailable' ? {} : model.types,
122
34
  });
35
+ return facts === null
36
+ ? null
37
+ : { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
123
38
  }
124
- function walk(reading, node, at) {
125
- record(reading, node, at);
126
- if (Array.isArray(node)) {
127
- node.forEach((item, index) => walk(reading, item, { ...at, tail: `${at.tail}.${index}`, exact: `${at.exact}/${index}` }));
128
- return;
129
- }
130
- if (!plainObject(node))
131
- return;
132
- for (const [key, value] of Object.entries(node)) {
133
- const segment = escapePointer(key);
134
- const exact = `${at.exact}/${segment}`;
135
- walk(reading, value, ARRAY_INDEX.test(segment)
136
- ? { ...at, head: `${at.head}${at.tail.replaceAll('.', ':')}:${segment}`, tail: '', exact }
137
- : { keys: `${at.keys}/${segment}`, done: placesOf(at), head: '', tail: '', exact });
138
- }
139
- }
140
- function bodyTargets(path, content) {
141
- const seen = new Set();
142
- const found = [];
143
- for (const { target: reached } of bodyLinks(bodyAfterFrontmatter(content), path)) {
144
- if (seen.has(reached))
145
- continue;
146
- seen.add(reached);
147
- found.push({ kind: 'body', keys: '', places: '', target: reached, field: '' });
148
- }
149
- return found;
150
- }
151
- function typedRows(path, content, document, composition) {
152
- const definition = definitionOf(governing(composition, path), document.type);
153
- const reading = {
154
- path,
155
- references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
156
- values: [],
157
- links: [],
158
- };
159
- for (const [name, value] of Object.entries(document.fields)) {
160
- const segment = escapePointer(name);
161
- walk(reading, value, {
162
- keys: `/${segment}`,
163
- done: '',
164
- head: '',
165
- tail: '',
166
- exact: `/${segment}`,
167
- });
168
- }
169
- const links = reading.links;
170
- if (definition !== undefined) {
171
- const sectioned = new Set();
172
- for (const { target: reached } of sectionReferences(path, content, definition)) {
173
- if (reached === null || sectioned.has(reached))
174
- continue;
175
- sectioned.add(reached);
176
- links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
177
- }
178
- }
179
- return { values: reading.values, links: [...links, ...bodyTargets(path, content)] };
180
- }
181
- function read(path, content) {
39
+ export function described(path, content, facts) {
182
40
  const folder = folderOf(path);
183
- const unread = { fields: null, folder, type: null };
184
- if (content === null) {
185
- return { described: { ...unread, declared: null, queried: true }, document: null };
186
- }
187
- const parsed = parseFrontmatter(content, path);
188
- const declared = parsed.ok ? (parsed.frontmatter.type ?? 'any') : null;
189
- if (!markdownPath(path) || !parsed.ok) {
190
- return { described: { ...unread, declared, queried: !markdownPath(path) }, document: null };
191
- }
192
- const document = parsed.frontmatter;
41
+ const unread = { type: null, fields: null, links: null, folder };
42
+ if (content === null)
43
+ return { ...unread, declared: null, queried: true };
44
+ if (facts === null)
45
+ return { ...unread, declared: null, queried: !markdownPath(path) };
46
+ const links = JSON.stringify(facts.links);
47
+ if (!markdownPath(path))
48
+ return { ...unread, declared: facts.type, queried: true, links };
193
49
  return {
194
- described: {
195
- type: document.type ?? 'any',
196
- declared,
197
- queried: true,
198
- folder,
199
- fields: JSON.stringify(document.fields),
200
- },
201
- document,
50
+ type: facts.type,
51
+ declared: facts.type,
52
+ queried: true,
53
+ folder,
54
+ fields: fieldsText(facts.fields),
55
+ links,
202
56
  };
203
57
  }
204
- export function described(path, content) {
205
- return read(path, content).described;
206
- }
207
- export function derived(path, content, composition) {
208
- const { described: columns, document } = read(path, content);
209
- if (document !== null) {
210
- return { ...columns, ...typedRows(path, content, document, composition) };
211
- }
212
- const links = content === null || markdownPath(path) ? [] : bodyTargets(path, content);
213
- return { ...columns, values: [], links };
58
+ export function heldOf(path, content, facts) {
59
+ if (content === null || facts === null)
60
+ return { type: null, fields: null, links: [] };
61
+ return markdownPath(path)
62
+ ? { type: facts.type, fields: facts.fields, links: facts.links }
63
+ : { type: null, fields: null, links: facts.links };
64
+ }
65
+ export function derived(path, held, composition) {
66
+ const stored = held.links.map((target) => ({
67
+ kind: 'link',
68
+ keys: '',
69
+ places: '',
70
+ target,
71
+ field: '',
72
+ }));
73
+ if (held.type === null || held.fields === null)
74
+ return { values: [], links: stored };
75
+ const definition = definitionOf(governing(composition, path), held.type);
76
+ const { values, links: fields } = indexed(path, held.fields, definition);
77
+ return { values, links: [...fields, ...stored] };
214
78
  }
@@ -0,0 +1,43 @@
1
+ import type { Authorization, DiscoveredRoom, PathRule, ScopedRefusal, TypedPath } from './adapter.js';
2
+ import type { ChangeSet } from './change-set.js';
3
+ import type { ChangeBatch } from './change.js';
4
+ import type { RuntimeShell } from './durability.js';
5
+ import type { LiveConversations } from './conversation-live.js';
6
+ import type { FiguresRead } from './figures.js';
7
+ import type { Withheld } from './install.js';
8
+ import type { LiveQueries } from './live.js';
9
+ import type { Log } from './log.js';
10
+ import type { ModelState } from './model.js';
11
+ import type { ReadAnswers } from './reads.js';
12
+ import type { Recovery } from './recovery.js';
13
+ import type { ReplicaRecord } from './replica.js';
14
+ import type { RuntimeSocket, RoomDeclaration } from './socket.js';
15
+ import type { CycleProgress } from './status.js';
16
+ import type { Settling } from './saves.js';
17
+ import type { HeldCover, RuntimeStore, Store, Work } from './store.js';
18
+ import type { schemaTypes } from './attached-model.js';
19
+ export type Runtime = {
20
+ readonly store: Store;
21
+ readonly socket: RuntimeSocket;
22
+ readonly journal: Log;
23
+ readonly recovery: Recovery;
24
+ readonly shell: RuntimeShell;
25
+ readonly localSaves: boolean;
26
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
27
+ readonly builtIn: ModelState;
28
+ readonly typedPaths: readonly TypedPath[];
29
+ readonly pathRule: PathRule;
30
+ readonly usableWhenHeld: readonly string[];
31
+ readonly build: string;
32
+ readonly conversations: LiveConversations;
33
+ readonly liveQueries: LiveQueries<HeldCover>;
34
+ readonly figures: FiguresRead;
35
+ readonly lastAnswers: ReadAnswers;
36
+ settle(local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
37
+ scoped(result: ScopedRefusal, room: RoomDeclaration, local: RuntimeStore): Promise<void>;
38
+ submitLater(locator: string): void;
39
+ unpair(local: RuntimeStore): Promise<void>;
40
+ advanced(room: DiscoveredRoom, local: RuntimeStore, authorized: Authorization): Promise<Withheld | null>;
41
+ withhold(withheld: Withheld, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress): Promise<void>;
42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GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,QAAQ,CACN,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,aAAa,GACxB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,QAAQ,CACN,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/save.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Validation } from '@agentshouse/mdmodel';
2
- import type { OperationScopes, ProviderLimit } from './adapter.js';
2
+ import type { OperationScopes, PathRule, ProviderLimit } from './adapter.js';
3
3
  import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from './change.js';
4
4
  import { type Composition } from './collection.js';
5
5
  import { type Layer } from './overlay.js';
@@ -19,7 +19,9 @@ export type SaveInput = {
19
19
  baseRoomVersion: string;
20
20
  operations: import('./adapter.js').OperationScopes;
21
21
  providerOwnedPaths: readonly string[];
22
+ authoredPaths?: readonly string[];
22
23
  providerLimits: readonly ProviderLimit[];
24
+ pathRule: PathRule;
23
25
  visible: VisibleLayer;
24
26
  folders: ReadonlySet<string>;
25
27
  handle: string;
@@ -75,6 +77,7 @@ export type MoveSide = {
75
77
  composition: Composition;
76
78
  operations: OperationScopes;
77
79
  providerOwnedPaths: readonly string[];
80
+ authoredPaths?: readonly string[];
78
81
  visible: VisibleLayer;
79
82
  folders: ReadonlySet<string>;
80
83
  queued: ReadonlySet<string>;
@@ -89,6 +92,7 @@ export type MoveInput = {
89
92
  readonly to: string;
90
93
  }[];
91
94
  providerLimits: readonly ProviderLimit[];
95
+ pathRule: PathRule;
92
96
  local: boolean;
93
97
  writtenBy?: WrittenBy;
94
98
  };