@agentshouse/mdruntime 0.1.0-cef76ea952695 → 0.1.0-cefb421089d74

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 (283) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +0 -3
  3. package/dist/acceptance.d.ts.map +1 -1
  4. package/dist/acceptance.js +72 -158
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +8 -2
  9. package/dist/actions.d.ts.map +1 -1
  10. package/dist/actions.js +142 -72
  11. package/dist/adapter.d.ts +124 -28
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +0 -1
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +0 -5
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +345 -0
  19. package/dist/binary.d.ts +4 -0
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +9 -2
  22. package/dist/bootstrap.d.ts +1 -1
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +6 -19
  25. package/dist/change-set.d.ts +4 -0
  26. package/dist/change-set.d.ts.map +1 -1
  27. package/dist/change-set.js +6 -0
  28. package/dist/change.d.ts +4 -0
  29. package/dist/change.d.ts.map +1 -1
  30. package/dist/change.js +3 -0
  31. package/dist/chat-types.d.ts +0 -2
  32. package/dist/chat-types.d.ts.map +1 -1
  33. package/dist/chat-types.js +0 -2
  34. package/dist/client.d.ts +17 -20
  35. package/dist/client.d.ts.map +1 -1
  36. package/dist/client.js +44 -60
  37. package/dist/collection.d.ts +26 -4
  38. package/dist/collection.d.ts.map +1 -1
  39. package/dist/collection.js +28 -10
  40. package/dist/column.d.ts +5 -0
  41. package/dist/column.d.ts.map +1 -0
  42. package/dist/column.js +9 -0
  43. package/dist/compile.d.ts +2 -0
  44. package/dist/compile.d.ts.map +1 -1
  45. package/dist/compile.js +17 -5
  46. package/dist/connection.d.ts +1 -1
  47. package/dist/connection.d.ts.map +1 -1
  48. package/dist/connection.js +34 -27
  49. package/dist/context.d.ts.map +1 -1
  50. package/dist/context.js +1 -1
  51. package/dist/conversation-live.d.ts +25 -11
  52. package/dist/conversation-live.d.ts.map +1 -1
  53. package/dist/conversation-live.js +23 -11
  54. package/dist/conversation-row.d.ts +8 -1
  55. package/dist/conversation-row.d.ts.map +1 -1
  56. package/dist/conversation-row.js +20 -7
  57. package/dist/conversation.d.ts +36 -10
  58. package/dist/conversation.d.ts.map +1 -1
  59. package/dist/conversation.js +310 -184
  60. package/dist/declaration.d.ts +10 -0
  61. package/dist/declaration.d.ts.map +1 -0
  62. package/dist/declaration.js +24 -0
  63. package/dist/discovery.d.ts +3 -1
  64. package/dist/discovery.d.ts.map +1 -1
  65. package/dist/discovery.js +47 -47
  66. package/dist/download.d.ts +6 -0
  67. package/dist/download.d.ts.map +1 -0
  68. package/dist/download.js +42 -0
  69. package/dist/durability.d.ts +5 -0
  70. package/dist/durability.d.ts.map +1 -1
  71. package/dist/durability.js +7 -0
  72. package/dist/entry.d.ts +14 -0
  73. package/dist/entry.d.ts.map +1 -1
  74. package/dist/entry.js +45 -16
  75. package/dist/expectation.d.ts +25 -14
  76. package/dist/expectation.d.ts.map +1 -1
  77. package/dist/expectation.js +51 -20
  78. package/dist/failure.d.ts +2 -0
  79. package/dist/failure.d.ts.map +1 -1
  80. package/dist/failure.js +6 -1
  81. package/dist/figures.d.ts.map +1 -1
  82. package/dist/figures.js +4 -2
  83. package/dist/file.d.ts +1 -1
  84. package/dist/file.d.ts.map +1 -1
  85. package/dist/file.js +3 -2
  86. package/dist/host.d.ts +23 -4
  87. package/dist/host.d.ts.map +1 -1
  88. package/dist/host.js +84 -19
  89. package/dist/house-query.d.ts +15 -0
  90. package/dist/house-query.d.ts.map +1 -0
  91. package/dist/house-query.js +43 -0
  92. package/dist/index.d.ts +20 -11
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +15 -7
  95. package/dist/install.d.ts +10 -6
  96. package/dist/install.d.ts.map +1 -1
  97. package/dist/install.js +89 -108
  98. package/dist/lifecycle.d.ts +2 -2
  99. package/dist/lifecycle.d.ts.map +1 -1
  100. package/dist/lifecycle.js +74 -54
  101. package/dist/listing.d.ts +29 -22
  102. package/dist/listing.d.ts.map +1 -1
  103. package/dist/listing.js +71 -79
  104. package/dist/live.d.ts +5 -3
  105. package/dist/live.d.ts.map +1 -1
  106. package/dist/live.js +71 -30
  107. package/dist/loaded.d.ts +5 -0
  108. package/dist/loaded.d.ts.map +1 -0
  109. package/dist/loaded.js +40 -0
  110. package/dist/locks.d.ts +2 -4
  111. package/dist/locks.d.ts.map +1 -1
  112. package/dist/locks.js +10 -38
  113. package/dist/lost.d.ts.map +1 -1
  114. package/dist/lost.js +11 -23
  115. package/dist/media.d.ts +19 -3
  116. package/dist/media.d.ts.map +1 -1
  117. package/dist/media.js +167 -33
  118. package/dist/memory.d.ts +9 -3
  119. package/dist/memory.d.ts.map +1 -1
  120. package/dist/memory.js +93 -32
  121. package/dist/messages.d.ts +17 -3
  122. package/dist/messages.d.ts.map +1 -1
  123. package/dist/messages.js +34 -13
  124. package/dist/modal.d.ts +2 -0
  125. package/dist/modal.d.ts.map +1 -0
  126. package/dist/modal.js +11 -0
  127. package/dist/model.d.ts +4 -3
  128. package/dist/model.d.ts.map +1 -1
  129. package/dist/model.js +6 -5
  130. package/dist/models.d.ts +4 -8
  131. package/dist/models.d.ts.map +1 -1
  132. package/dist/models.js +94 -138
  133. package/dist/observation.d.ts +29 -12
  134. package/dist/observation.d.ts.map +1 -1
  135. package/dist/observation.js +206 -69
  136. package/dist/online.d.ts +7 -0
  137. package/dist/online.d.ts.map +1 -0
  138. package/dist/online.js +29 -0
  139. package/dist/opened.d.ts +1 -1
  140. package/dist/opened.d.ts.map +1 -1
  141. package/dist/opened.js +2 -2
  142. package/dist/opening.d.ts.map +1 -1
  143. package/dist/opening.js +21 -12
  144. package/dist/outcome.d.ts +24 -4
  145. package/dist/outcome.d.ts.map +1 -1
  146. package/dist/outcome.js +32 -2
  147. package/dist/overlay.d.ts +6 -2
  148. package/dist/overlay.d.ts.map +1 -1
  149. package/dist/overlay.js +37 -24
  150. package/dist/page-metadata.d.ts +8 -0
  151. package/dist/page-metadata.d.ts.map +1 -0
  152. package/dist/page-metadata.js +19 -0
  153. package/dist/parts.d.ts +4 -9
  154. package/dist/parts.d.ts.map +1 -1
  155. package/dist/parts.js +30 -15
  156. package/dist/preparation.d.ts +33 -7
  157. package/dist/preparation.d.ts.map +1 -1
  158. package/dist/preparation.js +207 -96
  159. package/dist/presence.d.ts +58 -0
  160. package/dist/presence.d.ts.map +1 -0
  161. package/dist/presence.js +231 -0
  162. package/dist/queries.d.ts +2 -2
  163. package/dist/queries.d.ts.map +1 -1
  164. package/dist/queries.js +85 -70
  165. package/dist/questions.d.ts +1 -5
  166. package/dist/questions.d.ts.map +1 -1
  167. package/dist/questions.js +3 -8
  168. package/dist/queue.d.ts +40 -0
  169. package/dist/queue.d.ts.map +1 -0
  170. package/dist/queue.js +480 -0
  171. package/dist/reach.d.ts +15 -6
  172. package/dist/reach.d.ts.map +1 -1
  173. package/dist/reach.js +175 -31
  174. package/dist/react.d.ts +11 -5
  175. package/dist/react.d.ts.map +1 -1
  176. package/dist/react.js +28 -5
  177. package/dist/readiness.d.ts +20 -4
  178. package/dist/readiness.d.ts.map +1 -1
  179. package/dist/readiness.js +17 -10
  180. package/dist/reads.d.ts +4 -2
  181. package/dist/reads.d.ts.map +1 -1
  182. package/dist/reads.js +7 -3
  183. package/dist/recovery.d.ts +4 -1
  184. package/dist/recovery.d.ts.map +1 -1
  185. package/dist/recovery.js +31 -8
  186. package/dist/refresh.js +2 -2
  187. package/dist/refusal.d.ts.map +1 -1
  188. package/dist/refusal.js +2 -4
  189. package/dist/replica.d.ts +5 -11
  190. package/dist/replica.d.ts.map +1 -1
  191. package/dist/replica.js +14 -16
  192. package/dist/retried.d.ts +30 -0
  193. package/dist/retried.d.ts.map +1 -0
  194. package/dist/retried.js +72 -0
  195. package/dist/room-draft.d.ts +30 -5
  196. package/dist/room-draft.d.ts.map +1 -1
  197. package/dist/room-draft.js +270 -63
  198. package/dist/room-drafts.d.ts.map +1 -1
  199. package/dist/room-drafts.js +5 -2
  200. package/dist/room-list.d.ts +10 -0
  201. package/dist/room-list.d.ts.map +1 -0
  202. package/dist/room-list.js +45 -0
  203. package/dist/rows.d.ts +2 -1
  204. package/dist/rows.d.ts.map +1 -1
  205. package/dist/rows.js +9 -10
  206. package/dist/running.d.ts +5 -0
  207. package/dist/running.d.ts.map +1 -0
  208. package/dist/running.js +10 -0
  209. package/dist/runtime.d.ts +11 -19
  210. package/dist/runtime.d.ts.map +1 -1
  211. package/dist/save.d.ts +42 -90
  212. package/dist/save.d.ts.map +1 -1
  213. package/dist/save.js +314 -223
  214. package/dist/saves.d.ts +4 -40
  215. package/dist/saves.d.ts.map +1 -1
  216. package/dist/saves.js +164 -712
  217. package/dist/seed.d.ts.map +1 -1
  218. package/dist/seed.js +4 -4
  219. package/dist/shown.d.ts +9 -5
  220. package/dist/shown.d.ts.map +1 -1
  221. package/dist/shown.js +93 -57
  222. package/dist/socket/lanes.d.ts +12 -4
  223. package/dist/socket/lanes.d.ts.map +1 -1
  224. package/dist/socket/lanes.js +34 -8
  225. package/dist/socket/session.d.ts +4 -1
  226. package/dist/socket/session.d.ts.map +1 -1
  227. package/dist/socket/session.js +3 -0
  228. package/dist/socket.d.ts +4 -6
  229. package/dist/socket.d.ts.map +1 -1
  230. package/dist/socket.js +4 -14
  231. package/dist/source.d.ts +5 -7
  232. package/dist/source.d.ts.map +1 -1
  233. package/dist/source.js +13 -2
  234. package/dist/store/installs.d.ts +2 -2
  235. package/dist/store/installs.d.ts.map +1 -1
  236. package/dist/store/installs.js +10 -4
  237. package/dist/store/readiness.d.ts +5 -4
  238. package/dist/store/readiness.d.ts.map +1 -1
  239. package/dist/store/readiness.js +28 -12
  240. package/dist/store/records.d.ts +21 -4
  241. package/dist/store/records.d.ts.map +1 -1
  242. package/dist/store/records.js +60 -20
  243. package/dist/store/rooms-shown.d.ts +8 -0
  244. package/dist/store/rooms-shown.d.ts.map +1 -0
  245. package/dist/store/rooms-shown.js +13 -0
  246. package/dist/store.d.ts +25 -15
  247. package/dist/store.d.ts.map +1 -1
  248. package/dist/store.js +50 -18
  249. package/dist/stored.d.ts +32 -14
  250. package/dist/stored.d.ts.map +1 -1
  251. package/dist/stored.js +187 -51
  252. package/dist/surface.d.ts +12 -6
  253. package/dist/surface.d.ts.map +1 -1
  254. package/dist/surface.js +64 -33
  255. package/dist/sync.d.ts +4 -2
  256. package/dist/sync.d.ts.map +1 -1
  257. package/dist/sync.js +126 -101
  258. package/dist/tables.d.ts +16 -52
  259. package/dist/tables.d.ts.map +1 -1
  260. package/dist/tables.js +86 -324
  261. package/dist/tallies.d.ts.map +1 -1
  262. package/dist/tallies.js +1 -2
  263. package/dist/validation.d.ts.map +1 -1
  264. package/dist/validation.js +4 -10
  265. package/dist/wire.d.ts +66 -7
  266. package/dist/wire.d.ts.map +1 -1
  267. package/dist/wire.js +25 -9
  268. package/package.json +3 -3
  269. package/dist/attempt.d.ts +0 -16
  270. package/dist/attempt.d.ts.map +0 -1
  271. package/dist/attempt.js +0 -70
  272. package/dist/job.d.ts +0 -5
  273. package/dist/job.d.ts.map +0 -1
  274. package/dist/job.js +0 -7
  275. package/dist/log.d.ts +0 -6
  276. package/dist/log.d.ts.map +0 -1
  277. package/dist/log.js +0 -14
  278. package/dist/socket/rooms.d.ts +0 -44
  279. package/dist/socket/rooms.d.ts.map +0 -1
  280. package/dist/socket/rooms.js +0 -90
  281. package/dist/store/fences.d.ts +0 -16
  282. package/dist/store/fences.d.ts.map +0 -1
  283. package/dist/store/fences.js +0 -26
@@ -1,4 +1,6 @@
1
- import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
1
+ import type { PendingRoom, QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
2
+ import type { ReadinessShown, RoomCoverage } from './readiness.js';
3
+ import type { AppRoom, ListedRooms } from './listing.js';
2
4
  export type Observation<T> = {
3
5
  current(): T;
4
6
  subscribe(listener: (value: T) => void): () => void;
@@ -9,15 +11,24 @@ export type KeyedResult = {
9
11
  result: QueryResult;
10
12
  keys: readonly RowKey[];
11
13
  };
12
- export type QueryChange = {
13
- changed: readonly (readonly [RowKey, QueryDocument | QueryGroup])[];
14
- removed: readonly RowKey[];
15
- order: readonly RowKey[] | null;
14
+ export type KeyedChange<K, T> = {
15
+ readonly changed: readonly (readonly [K, T])[];
16
+ readonly removed: readonly K[];
17
+ readonly order: readonly K[] | null;
18
+ };
19
+ export type QueryChange = KeyedChange<RowKey, QueryDocument | QueryGroup> & {
16
20
  coverage?: QueryCoverage;
17
21
  next?: string | null;
18
22
  total?: number;
19
23
  };
20
- export type QueryMessage = KeyedResult | QueryChange;
24
+ export type ReadinessChange = {
25
+ readonly shown: ReadinessShown;
26
+ readonly rooms: KeyedChange<string, RoomCoverage>;
27
+ };
28
+ export type PendingChange = {
29
+ readonly pending: KeyedChange<string, PendingRoom>;
30
+ };
31
+ export type QueryMessage = KeyedResult | QueryChange | PendingChange;
21
32
  export type Observed = {
22
33
  observation: Observation<unknown>;
23
34
  receive(message: unknown): void;
@@ -25,15 +36,21 @@ export type Observed = {
25
36
  };
26
37
  export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
27
38
  export declare function whole(message: QueryMessage): message is KeyedResult;
28
- export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
29
- export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
30
- export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
39
+ export declare function pendingChange(message: QueryMessage): message is PendingChange;
40
+ export declare function unchanged(change: KeyedChange<unknown, unknown>): boolean;
41
+ export declare function keyedChange<K, H, T>(held: ReadonlyMap<K, H>, keys: readonly K[], rows: readonly T[], same: (was: H, now: T) => boolean): KeyedChange<K, T>;
42
+ export declare function keyedAt<K, H, T>(held: ReadonlyMap<K, H>, at: ReadonlyMap<K, T | null>, same: (was: H, now: T) => boolean): KeyedChange<K, T> | null;
43
+ export declare function keyedInto<K, T>(held: Map<K, T>, change: KeyedChange<K, T>): void;
44
+ export declare function samePending(was: PendingRoom, now: PendingRoom): boolean;
45
+ export declare function appRooms({ rooms, models }: ListedRooms): readonly AppRoom[];
46
+ export declare function replaces(topic: string, message: unknown): boolean;
47
+ export declare function observed(first: unknown, stop: () => void, topic: string): Observed;
48
+ export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, topic: string): Promise<Observation<unknown>>;
31
49
  export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
32
50
  export type Digest = {
33
- readonly pending: string;
51
+ readonly pending: Map<string, PendingRoom>;
34
52
  } | {
35
- readonly keys: readonly RowKey[];
36
- readonly rows: ReadonlyMap<RowKey, number>;
53
+ readonly rows: Map<RowKey, number>;
37
54
  readonly coverage: string;
38
55
  readonly next: string | undefined;
39
56
  readonly total: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,C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AAI,KAC3B,MAAM,IAAI,WAEA,KAAK,YAAY,OAAO,EAAE,KAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAa1E;AAED,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CAAE,GAC9C;IACE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAEN,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa3C;AAMD,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,MAAM,CAU9D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAkB3E;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,YAAY,GAAG,IAAI,CAsBjF"}
@@ -6,49 +6,198 @@ export function rowsOf(result) {
6
6
  export function whole(message) {
7
7
  return 'result' in message;
8
8
  }
9
- export function applied(keyed, message) {
10
- if (whole(message))
11
- return message;
12
- const result = keyed.result;
13
- if ('pending' in result)
14
- return keyed;
15
- const rows = rowsOf(result);
16
- const byKey = new Map(keyed.keys.map((key, index) => [key, rows[index]]));
17
- for (const key of message.removed)
18
- byKey.delete(key);
19
- for (const [key, row] of message.changed)
20
- byKey.set(key, row);
21
- const keys = message.order ?? keyed.keys.filter((key) => byKey.has(key));
22
- const kept = keys.map((key) => byKey.get(key));
23
- const coverage = message.coverage ?? result.coverage;
24
- const next = message.next === undefined ? result.next : (message.next ?? undefined);
25
- const total = message.total ?? result.total;
26
- const window = {
27
- ...(next === undefined ? {} : { next }),
28
- ...(total === undefined ? {} : { total }),
9
+ export function pendingChange(message) {
10
+ return 'pending' in message;
11
+ }
12
+ export function unchanged(change) {
13
+ return change.changed.length === 0 && change.removed.length === 0 && change.order === null;
14
+ }
15
+ export function keyedChange(held, keys, rows, same) {
16
+ const present = new Set(keys);
17
+ const changed = keys.flatMap((key, at) => {
18
+ const was = held.get(key);
19
+ return was !== undefined && same(was, rows[at]) ? [] : [[key, rows[at]]];
20
+ });
21
+ const removed = [];
22
+ const kept = [];
23
+ for (const key of held.keys())
24
+ (present.has(key) ? kept : removed).push(key);
25
+ const moved = kept.length !== keys.length || kept.some((key, at) => keys[at] !== key);
26
+ return { changed, removed, order: moved ? keys : null };
27
+ }
28
+ export function keyedAt(held, at, same) {
29
+ const changed = [];
30
+ const removed = [];
31
+ for (const [key, now] of at) {
32
+ const was = held.get(key);
33
+ if (was === undefined) {
34
+ if (now !== null)
35
+ return null;
36
+ }
37
+ else if (now === null)
38
+ removed.push(key);
39
+ else if (!same(was, now))
40
+ changed.push([key, now]);
41
+ }
42
+ return { changed, removed, order: null };
43
+ }
44
+ export function keyedInto(held, change) {
45
+ for (const key of change.removed)
46
+ held.delete(key);
47
+ for (const [key, row] of change.changed)
48
+ held.set(key, row);
49
+ if (change.order === null)
50
+ return;
51
+ const placed = change.order.map((key) => [key, held.get(key)]);
52
+ held.clear();
53
+ for (const [key, row] of placed)
54
+ held.set(key, row);
55
+ }
56
+ export function samePending(was, now) {
57
+ return was.awaits === now.awaits;
58
+ }
59
+ function keyedRows(keys, rows) {
60
+ const held = new Map(keys.map((key, at) => [key, rows[at]]));
61
+ let shown = rows;
62
+ return {
63
+ rows: () => shown,
64
+ apply(change) {
65
+ if (unchanged(change))
66
+ return shown;
67
+ keyedInto(held, change);
68
+ shown = [...held.values()];
69
+ return shown;
70
+ },
71
+ };
72
+ }
73
+ function heldModels(held, sent) {
74
+ return new Map(Object.entries(sent).map(([key, types]) => [key, held.get(key) ?? types]));
75
+ }
76
+ function namedModels(models, rooms) {
77
+ const named = new Set(rooms.flatMap(({ model, typedSelection }) => [model.types, typedSelection?.model.types]));
78
+ return new Map([...models].filter(([, types]) => named.has(types)));
79
+ }
80
+ function typed(model, models) {
81
+ return model.types === null ? model : { ...model, types: models.get(model.types) };
82
+ }
83
+ function appRoom({ model, typedSelection, ...room }, models) {
84
+ return {
85
+ ...room,
86
+ model: typed(model, models),
87
+ typedSelection: typedSelection === null
88
+ ? null
89
+ : { roots: typedSelection.roots, model: typed(typedSelection.model, models) },
90
+ };
91
+ }
92
+ export function appRooms({ rooms, models }) {
93
+ const held = heldModels(new Map(), models);
94
+ return rooms.map((room) => appRoom(room, held));
95
+ }
96
+ function keyedRooms(first) {
97
+ let models = new Map();
98
+ let held = keyedRows([], []);
99
+ const whole = (listed) => {
100
+ models = heldModels(models, listed.models);
101
+ held = keyedRows(listed.rooms.map(({ locator }) => locator), listed.rooms.map((room) => appRoom(room, models)));
102
+ return held.rows();
103
+ };
104
+ return {
105
+ value: whole(first),
106
+ next(message) {
107
+ if ('rooms' in message)
108
+ return whole(message);
109
+ const change = message;
110
+ const sent = heldModels(models, change.models);
111
+ const rows = held.apply({
112
+ changed: change.changed.map(([locator, room]) => [locator, appRoom(room, sent)]),
113
+ removed: change.removed,
114
+ order: change.order,
115
+ });
116
+ models = namedModels(new Map([...models, ...sent]), rows);
117
+ return rows;
118
+ },
29
119
  };
120
+ }
121
+ function covered(readiness) {
122
+ return keyedRows(readiness.coverage.rooms.map(({ room }) => room), readiness.coverage.rooms);
123
+ }
124
+ function keyedReadiness(first) {
125
+ let held = covered(first);
30
126
  return {
31
- result: 'groups' in result
32
- ? { groups: kept, coverage, ...window }
33
- : { documents: kept, coverage, ...window },
34
- keys,
127
+ value: first,
128
+ next(message) {
129
+ if (!('shown' in message)) {
130
+ held = covered(message);
131
+ return message;
132
+ }
133
+ const { shown, rooms } = message;
134
+ return { ...shown, coverage: { ...shown.coverage, rooms: held.apply(rooms) } };
135
+ },
35
136
  };
36
137
  }
138
+ function awaiting(pending) {
139
+ return keyedRows(pending.map(({ room }) => room), pending);
140
+ }
37
141
  function keyedResult(first) {
38
- let keyed = first;
142
+ let result = first.result;
143
+ let rows = keyedRows([], []);
144
+ let pending = awaiting([]);
145
+ const take = ({ result: next, keys }) => {
146
+ result = next;
147
+ if ('pending' in next)
148
+ pending = awaiting(next.pending);
149
+ else
150
+ rows = keyedRows(keys, rowsOf(next));
151
+ return result;
152
+ };
153
+ take(first);
39
154
  return {
40
155
  value: first.result,
41
156
  next(message) {
42
- keyed = applied(keyed, message);
43
- return keyed.result;
157
+ const asked = message;
158
+ if (whole(asked))
159
+ return take(asked);
160
+ if (pendingChange(asked)) {
161
+ if ('pending' in result)
162
+ result = { pending: pending.apply(asked.pending) };
163
+ return result;
164
+ }
165
+ if ('pending' in result)
166
+ return result;
167
+ const kept = rows.apply(asked);
168
+ const coverage = asked.coverage ?? result.coverage;
169
+ const next = asked.next === undefined ? result.next : (asked.next ?? undefined);
170
+ const total = asked.total ?? result.total;
171
+ const window = {
172
+ ...(next === undefined ? {} : { next }),
173
+ ...(total === undefined ? {} : { total }),
174
+ };
175
+ result =
176
+ 'groups' in result
177
+ ? { groups: kept, coverage, ...window }
178
+ : { documents: kept, coverage, ...window };
179
+ return result;
44
180
  },
45
181
  };
46
182
  }
183
+ const FOLDS = {
184
+ query: (first) => keyedResult(first),
185
+ rooms: (first) => keyedRooms(first),
186
+ readiness: (first) => keyedReadiness(first),
187
+ };
188
+ const WHOLE = {
189
+ query: (message) => whole(message),
190
+ rooms: (message) => 'rooms' in message,
191
+ readiness: (message) => !('shown' in message),
192
+ };
193
+ export function replaces(topic, message) {
194
+ return WHOLE[topic]?.(message) ?? true;
195
+ }
47
196
  function replaced(first) {
48
197
  return { value: first, next: (message) => message };
49
198
  }
50
- export function observed(first, stop, keyed) {
51
- const reducer = keyed ? keyedResult(first) : replaced(first);
199
+ export function observed(first, stop, topic) {
200
+ const reducer = (FOLDS[topic] ?? replaced)(first);
52
201
  let value = reducer.value;
53
202
  let open = true;
54
203
  const listeners = new Set();
@@ -86,7 +235,7 @@ export function observed(first, stop, keyed) {
86
235
  end,
87
236
  };
88
237
  }
89
- export function opened(watch, keyed) {
238
+ export function opened(watch, topic) {
90
239
  return new Promise((resolve, reject) => {
91
240
  let handle;
92
241
  let stop = () => { };
@@ -95,7 +244,7 @@ export function opened(watch, keyed) {
95
244
  handle.receive(message);
96
245
  return;
97
246
  }
98
- handle = observed(message, () => stop(), keyed);
247
+ handle = observed(message, () => stop(), topic);
99
248
  resolve(handle.observation);
100
249
  }, (error) => {
101
250
  if (handle !== undefined)
@@ -108,7 +257,7 @@ export function opened(watch, keyed) {
108
257
  export function observing(watch) {
109
258
  return (topic, ...input) => opened((deliver, fail) => watch(topic, input, (message) => {
110
259
  deliver(structuredClone(message));
111
- }, fail), topic === 'query');
260
+ }, fail), topic);
112
261
  }
113
262
  export function hashed(text) {
114
263
  let first = 0xdeadbeef;
@@ -129,10 +278,9 @@ function rowDigest(row) {
129
278
  }
130
279
  export function digestOf({ result, keys }) {
131
280
  if ('pending' in result)
132
- return { pending: JSON.stringify(result) };
281
+ return { pending: new Map(result.pending.map((room) => [room.room, room])) };
133
282
  const rows = rowsOf(result);
134
283
  return {
135
- keys,
136
284
  rows: new Map(keys.map((key, index) => [key, rowDigest(rows[index])])),
137
285
  coverage: JSON.stringify(result.coverage),
138
286
  next: result.next,
@@ -140,16 +288,22 @@ export function digestOf({ result, keys }) {
140
288
  };
141
289
  }
142
290
  export function digestApplied(digest, message) {
143
- if (whole(message) || 'pending' in digest)
144
- return whole(message) ? digestOf(message) : digest;
145
- const rows = new Map(digest.rows);
146
- for (const key of message.removed)
147
- rows.delete(key);
148
- for (const [key, row] of message.changed)
149
- rows.set(key, rowDigest(row));
291
+ if (whole(message))
292
+ return digestOf(message);
293
+ if (pendingChange(message)) {
294
+ if ('pending' in digest)
295
+ keyedInto(digest.pending, message.pending);
296
+ return digest;
297
+ }
298
+ if ('pending' in digest)
299
+ return digest;
300
+ keyedInto(digest.rows, {
301
+ changed: message.changed.map(([key, row]) => [key, rowDigest(row)]),
302
+ removed: message.removed,
303
+ order: message.order,
304
+ });
150
305
  return {
151
- keys: message.order ?? digest.keys.filter((key) => rows.has(key)),
152
- rows,
306
+ rows: digest.rows,
153
307
  coverage: message.coverage === undefined ? digest.coverage : JSON.stringify(message.coverage),
154
308
  next: message.next === undefined ? digest.next : (message.next ?? undefined),
155
309
  total: message.total ?? digest.total,
@@ -157,35 +311,18 @@ export function digestApplied(digest, message) {
157
311
  }
158
312
  export function changeOf(previous, next) {
159
313
  const after = next.result;
160
- if ('pending' in previous || 'pending' in after) {
161
- return 'pending' in previous && 'pending' in after && previous.pending === JSON.stringify(after)
162
- ? null
163
- : next;
314
+ if ('pending' in previous && 'pending' in after) {
315
+ const pending = keyedChange(previous.pending, after.pending.map(({ room }) => room), after.pending, samePending);
316
+ return unchanged(pending) ? null : { pending };
164
317
  }
165
- const later = rowsOf(after);
166
- const present = new Set(next.keys);
167
- const changed = [];
168
- next.keys.forEach((key, index) => {
169
- const row = later[index];
170
- if (previous.rows.get(key) !== rowDigest(row))
171
- changed.push([key, row]);
172
- });
173
- const removed = previous.keys.filter((key) => !present.has(key));
174
- const kept = previous.keys.filter((key) => present.has(key));
175
- const moved = kept.length !== next.keys.length || kept.some((key, index) => next.keys[index] !== key);
176
- const coverage = JSON.stringify(after.coverage);
177
- const covered = previous.coverage !== coverage;
318
+ if ('pending' in previous || 'pending' in after)
319
+ return next;
320
+ const rows = keyedChange(previous.rows, next.keys, rowsOf(after), (was, row) => was === rowDigest(row));
321
+ const covered = previous.coverage !== JSON.stringify(after.coverage);
178
322
  const framing = reframed(previous, after);
179
- if (changed.length === 0 && removed.length === 0 && !moved && !covered && framing === null) {
323
+ if (unchanged(rows) && !covered && framing === null)
180
324
  return null;
181
- }
182
- return {
183
- changed,
184
- removed,
185
- order: moved ? next.keys : null,
186
- ...(covered ? { coverage: after.coverage } : {}),
187
- ...framing,
188
- };
325
+ return { ...rows, ...(covered ? { coverage: after.coverage } : {}), ...framing };
189
326
  }
190
327
  function reframed(before, after) {
191
328
  const next = before.next === after.next ? {} : { next: after.next ?? null };
@@ -0,0 +1,7 @@
1
+ import type { Authorization } from './adapter.js';
2
+ import type { Runtime } from './runtime.js';
3
+ export declare function offline(runtime: Runtime): Promise<boolean>;
4
+ export declare function askedOnline<T extends {
5
+ readonly kind: string;
6
+ }>(runtime: Runtime, ask: (authorization: Authorization) => Promise<T>): Promise<T | null>;
7
+ //# sourceMappingURL=online.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"online.d.ts","sourceRoot":"","sources":["../src/online.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAsB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAOhE;AAED,wBAAsB,WAAW,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EACnE,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAgBnB"}
package/dist/online.js ADDED
@@ -0,0 +1,29 @@
1
+ import { connectionNow } from './preparation.js';
2
+ import { refuse } from './refusal.js';
3
+ export async function offline(runtime) {
4
+ const { socket } = runtime;
5
+ return (socket.closed() ||
6
+ socket.session.now().refusal !== null ||
7
+ (await connectionNow(runtime)) !== 'connected');
8
+ }
9
+ export async function askedOnline(runtime, ask) {
10
+ const { socket } = runtime;
11
+ try {
12
+ await socket.authorize();
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ const { closed, authorization, refusal } = socket.session.now();
18
+ if (closed || authorization === undefined || refusal !== null)
19
+ return null;
20
+ try {
21
+ const answer = await ask(authorization);
22
+ if (answer.kind === 'revoked-authorization')
23
+ await refuse(runtime, 'revoked-authorization');
24
+ return answer;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
package/dist/opened.d.ts CHANGED
@@ -18,5 +18,5 @@ export type OpenedFiles = {
18
18
  find(name: OpenedName): Promise<KeptBinary | null>;
19
19
  fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
20
20
  };
21
- export declare function openedFiles(database: RuntimeDatabase, fenced: (locator: string) => boolean): OpenedFiles;
21
+ export declare function openedFiles(database: RuntimeDatabase, lost: (locator: string) => boolean): OpenedFiles;
22
22
  //# sourceMappingURL=opened.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opened.d.ts","sourceRoot":"","sources":["../src/opened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG;IACxB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,CAAC,UAAU,CAAC,CAAC;CACjF,CAAC;AAsBF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACjC,WAAW,CAsFb"}
package/dist/opened.js CHANGED
@@ -20,7 +20,7 @@ function taken(chunks, size) {
20
20
  }
21
21
  return part;
22
22
  }
23
- export function openedFiles(database, fenced) {
23
+ export function openedFiles(database, lost) {
24
24
  const fetching = new Map();
25
25
  async function find(name) {
26
26
  const held = await database.ask({ kind: 'opened.find', ...name });
@@ -41,7 +41,7 @@ export function openedFiles(database, fenced) {
41
41
  part += 1;
42
42
  };
43
43
  try {
44
- if (fenced(name.locator) ||
44
+ if (lost(name.locator) ||
45
45
  !(await database.ask({ kind: 'opened.begin', key, ...name, mediaType }))) {
46
46
  throw new Error();
47
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CA6CxF"}
1
+ {"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["../src/opening.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAsCxF"}
package/dist/opening.js CHANGED
@@ -4,9 +4,10 @@ import { uncaught } from './failure.js';
4
4
  import { sweep } from './install.js';
5
5
  import { eraseFenced } from './lost.js';
6
6
  import { prepare } from './preparation.js';
7
+ import { unpair } from './queue.js';
7
8
  import { emitRooms, emitStorageLoss, statusShown } from './shown.js';
8
9
  export async function open(runtime, opened) {
9
- const { store, socket, journal, shell, conversations, build, usableWhenHeld } = runtime;
10
+ const { store, socket, shell, conversations, build } = runtime;
10
11
  if (socket.closed())
11
12
  throw new Error('runtime closed');
12
13
  const interrupted = await opened.fences();
@@ -24,7 +25,7 @@ export async function open(runtime, opened) {
24
25
  }
25
26
  const held = await opened.opened();
26
27
  store.device.set({
27
- heldWhenOpened: usableWhenHeld.length > 0 && (await opened.covering()).rooms.size > 0,
28
+ completedWhenOpened: (await opened.facts(['lastCompleted'])).lastCompleted !== null,
28
29
  });
29
30
  try {
30
31
  await opened.demote();
@@ -41,20 +42,28 @@ export async function open(runtime, opened) {
41
42
  await conversationsOpened(conversations, opened);
42
43
  if (interrupted.length > 0) {
43
44
  queueMicrotask(() => {
44
- void eraseFenced(runtime, interrupted).catch((error) => {
45
- journal.record('erasure failed');
46
- uncaught(error);
47
- });
45
+ void eraseFenced(runtime, interrupted).catch(uncaught);
48
46
  });
49
47
  }
48
+ await factsKept(runtime, opened);
50
49
  statusShown(runtime);
51
50
  prepare(runtime);
52
51
  emitRooms(runtime);
53
- void store
54
- .exclusive(() => runtime.unpair(opened))
55
- .catch((error) => {
56
- journal.record('unpair failed');
57
- uncaught(error);
58
- });
52
+ void unpair(runtime).catch(uncaught);
59
53
  return opened;
60
54
  }
55
+ async function factsKept({ socket, adopt }, opened) {
56
+ const { session } = socket;
57
+ const { unstored } = session.now();
58
+ if (unstored !== null) {
59
+ queueMicrotask(() => {
60
+ void adopt(unstored).catch(uncaught);
61
+ });
62
+ return;
63
+ }
64
+ const { capabilities, queriesOnly } = await opened.facts(['capabilities', 'queriesOnly']);
65
+ if (queriesOnly.length > 0 && !session.now().roomsNamed)
66
+ session.set({ queriesOnly });
67
+ if (capabilities.length > 0)
68
+ socket.readyFromStore();
69
+ }
package/dist/outcome.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
1
+ import type { ActionResult, AdapterFailure, AttachResult, BinaryCopy, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
2
  import type { ChangeBatch } from './change.js';
3
+ import type { Attempt, Retries } from './retried.js';
3
4
  import type { KeptBinary, KeptResult } from './opened.js';
4
5
  type Refused<Kind extends string> = ProviderRefusal & {
5
6
  kind: Kind;
@@ -33,12 +34,24 @@ export type BinaryLinkAnswer = {
33
34
  name: string;
34
35
  mediaType: string;
35
36
  } | Refused<'rejected'> | Refused<'absent'> | Failure;
36
- export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
37
- export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
37
+ export type ShownLinkAnswer = Extract<BinaryLinkAnswer, {
38
+ kind: 'link';
39
+ }> & {
40
+ copies: readonly BinaryCopy[];
41
+ };
42
+ type ShownRefusal = Exclude<BinaryLinkAnswer, {
43
+ kind: 'link';
44
+ }>;
45
+ export type HeldShownAnswer = KeptBinary | ShownLinkAnswer | ShownRefusal;
46
+ export type ShownAnswer = BinaryAnswer | ShownLinkAnswer | ShownRefusal;
38
47
  export type AttachAnswer = {
39
48
  kind: 'attached';
40
49
  path: string;
41
50
  } | Offline | Refused<'rejected'> | Failure;
51
+ export type ConversationAttachAnswer = {
52
+ kind: 'attached';
53
+ link: string;
54
+ } | Offline | Refused<'rejected'> | Refused<'undeclared'> | Failure;
42
55
  export type DownloadAnswer = {
43
56
  kind: 'started';
44
57
  } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
@@ -56,9 +69,14 @@ export declare const UNREADABLE: Refused<'unreadable'>;
56
69
  export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
57
70
  export declare const ABSENT_TARGET: Refused<'absent'>;
58
71
  export declare function absentBinary(path: string): Refused<'absent'>;
72
+ export declare function declaredType(blob: Blob): string;
73
+ export declare function blobOf(binary: Extract<BinaryAnswer, {
74
+ kind: 'binary';
75
+ }>): Promise<Blob>;
59
76
  export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
60
77
  export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
61
78
  export declare function attachAnswer(result: AttachResult): AttachAnswer;
79
+ export declare function linkedAnswer(result: AttachResult): ConversationAttachAnswer;
62
80
  export declare const ROOM_LOCKED = "room-locked";
63
81
  export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
64
82
  locator: string;
@@ -69,7 +87,7 @@ export type Offline = {
69
87
  export declare const OFFLINE: Offline;
70
88
  export declare function answeredResult(value: unknown): boolean;
71
89
  export declare const UNCERTAIN: Failure;
72
- export declare function undeclared(name: string): CallResult;
90
+ export declare function undeclared(name: string): Refused<'undeclared'>;
73
91
  export declare function failure(result: AdapterFailure): Failure;
74
92
  export declare function calledResult(result: ActionResult): CallResult;
75
93
  export declare function historyAnswer(result: HistoryResult): HistoryAnswer;
@@ -84,5 +102,7 @@ export type QueueEntry = {
84
102
  } & (Submission | {
85
103
  readonly state: 'local';
86
104
  });
105
+ export declare const UNANSWERED: ActionResult;
106
+ export declare function handedOutcome(retries: Retries, attempt: Attempt | undefined, result: ActionResult): CallResult;
87
107
  export {};
88
108
  //# sourceMappingURL=outcome.d.ts.map