@agentshouse/mdruntime 0.1.0-ca6edc1abd618 → 0.1.0-ca73fc3c2800a

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 (365) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +328 -0
  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 +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +341 -0
  11. package/dist/adapter.d.ts +303 -122
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +3 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +28 -51
  16. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  17. package/dist/attachment.d.ts.map +1 -0
  18. package/dist/attachment.js +15 -0
  19. package/dist/authored.d.ts +88 -0
  20. package/dist/authored.d.ts.map +1 -0
  21. package/dist/authored.js +345 -0
  22. package/dist/bootstrap.d.ts +17 -15
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +266 -135
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +3 -2
  29. package/dist/chain.d.ts.map +1 -1
  30. package/dist/chain.js +5 -2
  31. package/dist/change-set.d.ts +4 -0
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +6 -0
  34. package/dist/change.d.ts +7 -2
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +7 -2
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +50 -28
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +63 -27
  43. package/dist/collection.d.ts +33 -7
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +49 -19
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +10 -7
  50. package/dist/compile.d.ts.map +1 -1
  51. package/dist/compile.js +349 -315
  52. package/dist/connection.d.ts +6 -141
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +118 -4981
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/context.js +7 -0
  58. package/dist/conversation-live.d.ts +150 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +260 -0
  61. package/dist/conversation-row.d.ts +55 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +82 -0
  64. package/dist/conversation.d.ts +82 -55
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1028 -842
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/discovery.d.ts +12 -0
  71. package/dist/discovery.d.ts.map +1 -0
  72. package/dist/discovery.js +175 -0
  73. package/dist/download.d.ts +6 -0
  74. package/dist/download.d.ts.map +1 -0
  75. package/dist/download.js +42 -0
  76. package/dist/durability.d.ts +20 -1
  77. package/dist/durability.d.ts.map +1 -1
  78. package/dist/durability.js +7 -0
  79. package/dist/entry.d.ts +29 -3
  80. package/dist/entry.d.ts.map +1 -1
  81. package/dist/entry.js +134 -34
  82. package/dist/expectation.d.ts +26 -13
  83. package/dist/expectation.d.ts.map +1 -1
  84. package/dist/expectation.js +72 -19
  85. package/dist/failure.d.ts +3 -0
  86. package/dist/failure.d.ts.map +1 -1
  87. package/dist/failure.js +8 -0
  88. package/dist/figures.d.ts +49 -0
  89. package/dist/figures.d.ts.map +1 -0
  90. package/dist/figures.js +199 -0
  91. package/dist/file.d.ts +2 -11
  92. package/dist/file.d.ts.map +1 -1
  93. package/dist/file.js +7 -4
  94. package/dist/holdings.d.ts +29 -0
  95. package/dist/holdings.d.ts.map +1 -0
  96. package/dist/holdings.js +95 -0
  97. package/dist/host.d.ts +25 -8
  98. package/dist/host.d.ts.map +1 -1
  99. package/dist/host.js +130 -54
  100. package/dist/house-query.d.ts +24 -0
  101. package/dist/house-query.d.ts.map +1 -0
  102. package/dist/house-query.js +102 -0
  103. package/dist/identity.d.ts +1 -2
  104. package/dist/identity.d.ts.map +1 -1
  105. package/dist/identity.js +1 -4
  106. package/dist/index.d.ts +48 -18
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +24 -7
  109. package/dist/install.d.ts +60 -0
  110. package/dist/install.d.ts.map +1 -0
  111. package/dist/install.js +537 -0
  112. package/dist/lifecycle.d.ts +7 -0
  113. package/dist/lifecycle.d.ts.map +1 -0
  114. package/dist/lifecycle.js +292 -0
  115. package/dist/listing.d.ts +60 -0
  116. package/dist/listing.d.ts.map +1 -0
  117. package/dist/listing.js +168 -0
  118. package/dist/live.d.ts +23 -6
  119. package/dist/live.d.ts.map +1 -1
  120. package/dist/live.js +138 -38
  121. package/dist/loaded.d.ts +7 -0
  122. package/dist/loaded.d.ts.map +1 -0
  123. package/dist/loaded.js +46 -0
  124. package/dist/locks.d.ts +7 -0
  125. package/dist/locks.d.ts.map +1 -0
  126. package/dist/locks.js +34 -0
  127. package/dist/lost.d.ts +5 -0
  128. package/dist/lost.d.ts.map +1 -0
  129. package/dist/lost.js +49 -0
  130. package/dist/media.d.ts +24 -0
  131. package/dist/media.d.ts.map +1 -0
  132. package/dist/media.js +365 -0
  133. package/dist/memory.d.ts +21 -8
  134. package/dist/memory.d.ts.map +1 -1
  135. package/dist/memory.js +297 -104
  136. package/dist/messages.d.ts +44 -5
  137. package/dist/messages.d.ts.map +1 -1
  138. package/dist/messages.js +129 -39
  139. package/dist/modal.d.ts +2 -0
  140. package/dist/modal.d.ts.map +1 -0
  141. package/dist/modal.js +11 -0
  142. package/dist/model.d.ts +15 -15
  143. package/dist/model.d.ts.map +1 -1
  144. package/dist/model.js +11 -22
  145. package/dist/models.d.ts +10 -0
  146. package/dist/models.d.ts.map +1 -0
  147. package/dist/models.js +153 -0
  148. package/dist/name.d.ts +0 -1
  149. package/dist/name.d.ts.map +1 -1
  150. package/dist/name.js +3 -7
  151. package/dist/observation.d.ts +31 -13
  152. package/dist/observation.d.ts.map +1 -1
  153. package/dist/observation.js +219 -82
  154. package/dist/online.d.ts +7 -0
  155. package/dist/online.d.ts.map +1 -0
  156. package/dist/online.js +29 -0
  157. package/dist/opened.d.ts +6 -6
  158. package/dist/opened.d.ts.map +1 -1
  159. package/dist/opened.js +7 -7
  160. package/dist/opening.d.ts +4 -0
  161. package/dist/opening.d.ts.map +1 -0
  162. package/dist/opening.js +71 -0
  163. package/dist/outcome.d.ts +46 -15
  164. package/dist/outcome.d.ts.map +1 -1
  165. package/dist/outcome.js +52 -5
  166. package/dist/overlay.d.ts +24 -8
  167. package/dist/overlay.d.ts.map +1 -1
  168. package/dist/overlay.js +143 -48
  169. package/dist/page-metadata.d.ts +8 -0
  170. package/dist/page-metadata.d.ts.map +1 -0
  171. package/dist/page-metadata.js +19 -0
  172. package/dist/parts.d.ts +6 -0
  173. package/dist/parts.d.ts.map +1 -0
  174. package/dist/parts.js +36 -0
  175. package/dist/paths.d.ts +2 -0
  176. package/dist/paths.d.ts.map +1 -1
  177. package/dist/paths.js +26 -0
  178. package/dist/preparation.d.ts +46 -0
  179. package/dist/preparation.d.ts.map +1 -0
  180. package/dist/preparation.js +344 -0
  181. package/dist/presence.d.ts +58 -0
  182. package/dist/presence.d.ts.map +1 -0
  183. package/dist/presence.js +231 -0
  184. package/dist/queries.d.ts +16 -0
  185. package/dist/queries.d.ts.map +1 -0
  186. package/dist/queries.js +330 -0
  187. package/dist/query.d.ts +20 -210
  188. package/dist/query.d.ts.map +1 -1
  189. package/dist/query.js +3 -505
  190. package/dist/questions.d.ts +30 -0
  191. package/dist/questions.d.ts.map +1 -0
  192. package/dist/questions.js +117 -0
  193. package/dist/queue.d.ts +40 -0
  194. package/dist/queue.d.ts.map +1 -0
  195. package/dist/queue.js +482 -0
  196. package/dist/reach.d.ts +31 -13
  197. package/dist/reach.d.ts.map +1 -1
  198. package/dist/reach.js +386 -146
  199. package/dist/react.d.ts +27 -3
  200. package/dist/react.d.ts.map +1 -1
  201. package/dist/react.js +33 -1
  202. package/dist/read.d.ts +7 -0
  203. package/dist/read.d.ts.map +1 -0
  204. package/dist/read.js +17 -0
  205. package/dist/readiness.d.ts +26 -22
  206. package/dist/readiness.d.ts.map +1 -1
  207. package/dist/readiness.js +22 -20
  208. package/dist/reads.d.ts +38 -10
  209. package/dist/reads.d.ts.map +1 -1
  210. package/dist/reads.js +174 -85
  211. package/dist/recovery.d.ts +4 -0
  212. package/dist/recovery.d.ts.map +1 -1
  213. package/dist/recovery.js +59 -2
  214. package/dist/refresh.d.ts +7 -5
  215. package/dist/refresh.d.ts.map +1 -1
  216. package/dist/refresh.js +37 -9
  217. package/dist/refusal.d.ts +5 -0
  218. package/dist/refusal.d.ts.map +1 -0
  219. package/dist/refusal.js +55 -0
  220. package/dist/replica.d.ts +13 -24
  221. package/dist/replica.d.ts.map +1 -1
  222. package/dist/replica.js +71 -40
  223. package/dist/retried.d.ts +30 -0
  224. package/dist/retried.d.ts.map +1 -0
  225. package/dist/retried.js +72 -0
  226. package/dist/room-draft.d.ts +52 -13
  227. package/dist/room-draft.d.ts.map +1 -1
  228. package/dist/room-draft.js +372 -115
  229. package/dist/room-drafts.d.ts +24 -0
  230. package/dist/room-drafts.d.ts.map +1 -0
  231. package/dist/room-drafts.js +222 -0
  232. package/dist/room-list.d.ts +10 -0
  233. package/dist/room-list.d.ts.map +1 -0
  234. package/dist/room-list.js +47 -0
  235. package/dist/rows.d.ts +28 -18
  236. package/dist/rows.d.ts.map +1 -1
  237. package/dist/rows.js +65 -160
  238. package/dist/run-tables.d.ts +25 -0
  239. package/dist/run-tables.d.ts.map +1 -0
  240. package/dist/run-tables.js +98 -0
  241. package/dist/running.d.ts +5 -0
  242. package/dist/running.d.ts.map +1 -0
  243. package/dist/running.js +10 -0
  244. package/dist/runs.d.ts +27 -0
  245. package/dist/runs.d.ts.map +1 -0
  246. package/dist/runs.js +92 -0
  247. package/dist/runtime.d.ts +37 -0
  248. package/dist/runtime.d.ts.map +1 -0
  249. package/dist/runtime.js +1 -0
  250. package/dist/save.d.ts +43 -84
  251. package/dist/save.d.ts.map +1 -1
  252. package/dist/save.js +342 -232
  253. package/dist/saves.d.ts +34 -0
  254. package/dist/saves.d.ts.map +1 -0
  255. package/dist/saves.js +464 -0
  256. package/dist/search.d.ts +12 -63
  257. package/dist/search.d.ts.map +1 -1
  258. package/dist/search.js +9 -52
  259. package/dist/seed.d.ts +11 -2
  260. package/dist/seed.d.ts.map +1 -1
  261. package/dist/seed.js +71 -1
  262. package/dist/selector.d.ts +3 -0
  263. package/dist/selector.d.ts.map +1 -0
  264. package/dist/selector.js +22 -0
  265. package/dist/shared.d.ts +1 -7
  266. package/dist/shared.d.ts.map +1 -1
  267. package/dist/shared.js +13 -105
  268. package/dist/shown.d.ts +35 -0
  269. package/dist/shown.d.ts.map +1 -0
  270. package/dist/shown.js +327 -0
  271. package/dist/socket/admission.d.ts +7 -0
  272. package/dist/socket/admission.d.ts.map +1 -0
  273. package/dist/socket/admission.js +39 -0
  274. package/dist/socket/answers.d.ts +6 -0
  275. package/dist/socket/answers.d.ts.map +1 -0
  276. package/dist/socket/answers.js +20 -0
  277. package/dist/socket/lanes.d.ts +28 -0
  278. package/dist/socket/lanes.d.ts.map +1 -0
  279. package/dist/socket/lanes.js +103 -0
  280. package/dist/socket/reads.d.ts +10 -0
  281. package/dist/socket/reads.d.ts.map +1 -0
  282. package/dist/socket/reads.js +31 -0
  283. package/dist/socket/session.d.ts +41 -0
  284. package/dist/socket/session.d.ts.map +1 -0
  285. package/dist/socket/session.js +26 -0
  286. package/dist/socket.d.ts +70 -0
  287. package/dist/socket.d.ts.map +1 -0
  288. package/dist/socket.js +172 -0
  289. package/dist/source.d.ts +96 -0
  290. package/dist/source.d.ts.map +1 -0
  291. package/dist/source.js +149 -0
  292. package/dist/status.d.ts +4 -5
  293. package/dist/status.d.ts.map +1 -1
  294. package/dist/status.js +3 -7
  295. package/dist/store/installs.d.ts +30 -0
  296. package/dist/store/installs.d.ts.map +1 -0
  297. package/dist/store/installs.js +40 -0
  298. package/dist/store/readiness.d.ts +11 -0
  299. package/dist/store/readiness.d.ts.map +1 -0
  300. package/dist/store/readiness.js +68 -0
  301. package/dist/store/records.d.ts +234 -0
  302. package/dist/store/records.d.ts.map +1 -0
  303. package/dist/store/records.js +474 -0
  304. package/dist/store/room-held.d.ts +8 -0
  305. package/dist/store/room-held.d.ts.map +1 -0
  306. package/dist/store/room-held.js +17 -0
  307. package/dist/store/rooms-shown.d.ts +8 -0
  308. package/dist/store/rooms-shown.d.ts.map +1 -0
  309. package/dist/store/rooms-shown.js +13 -0
  310. package/dist/store/space.d.ts +11 -0
  311. package/dist/store/space.d.ts.map +1 -0
  312. package/dist/store/space.js +41 -0
  313. package/dist/store/watchers.d.ts +17 -0
  314. package/dist/store/watchers.d.ts.map +1 -0
  315. package/dist/store/watchers.js +56 -0
  316. package/dist/store/writes.d.ts +24 -0
  317. package/dist/store/writes.d.ts.map +1 -0
  318. package/dist/store/writes.js +125 -0
  319. package/dist/store.d.ts +114 -156
  320. package/dist/store.d.ts.map +1 -1
  321. package/dist/store.js +174 -400
  322. package/dist/stored.d.ts +96 -60
  323. package/dist/stored.d.ts.map +1 -1
  324. package/dist/stored.js +531 -291
  325. package/dist/surface.d.ts +100 -0
  326. package/dist/surface.d.ts.map +1 -0
  327. package/dist/surface.js +258 -0
  328. package/dist/sync.d.ts +21 -0
  329. package/dist/sync.d.ts.map +1 -0
  330. package/dist/sync.js +557 -0
  331. package/dist/tables.d.ts +151 -105
  332. package/dist/tables.d.ts.map +1 -1
  333. package/dist/tables.js +226 -330
  334. package/dist/tallies.d.ts +18 -0
  335. package/dist/tallies.d.ts.map +1 -0
  336. package/dist/tallies.js +128 -0
  337. package/dist/transfer.d.ts +0 -5
  338. package/dist/transfer.d.ts.map +1 -1
  339. package/dist/validation.d.ts +5 -4
  340. package/dist/validation.d.ts.map +1 -1
  341. package/dist/validation.js +87 -105
  342. package/dist/windows.d.ts +1 -12
  343. package/dist/windows.d.ts.map +1 -1
  344. package/dist/windows.js +2 -75
  345. package/dist/wire.d.ts +92 -16
  346. package/dist/wire.d.ts.map +1 -1
  347. package/dist/wire.js +38 -14
  348. package/package.json +4 -3
  349. package/dist/attempt.d.ts +0 -16
  350. package/dist/attempt.d.ts.map +0 -1
  351. package/dist/attempt.js +0 -70
  352. package/dist/binary.d.ts.map +0 -1
  353. package/dist/binary.js +0 -8
  354. package/dist/fence.d.ts +0 -6
  355. package/dist/fence.d.ts.map +0 -1
  356. package/dist/fence.js +0 -10
  357. package/dist/fulltext.d.ts +0 -27
  358. package/dist/fulltext.d.ts.map +0 -1
  359. package/dist/fulltext.js +0 -368
  360. package/dist/log.d.ts +0 -5
  361. package/dist/log.d.ts.map +0 -1
  362. package/dist/log.js +0 -14
  363. package/dist/words.d.ts +0 -19
  364. package/dist/words.d.ts.map +0 -1
  365. package/dist/words.js +0 -150
@@ -0,0 +1,34 @@
1
+ import { type ChangeBatch, type WrittenBy } from './change.js';
2
+ import type { ConversationFiles } from './conversation.js';
3
+ import { type AttachAnswer, type AttachmentLinkAnswer, type HeldAttachmentAnswer, type HeldShownAnswer } from './outcome.js';
4
+ import { type RoomDraftParts } from './room-draft.js';
5
+ import type { Runtime } from './runtime.js';
6
+ import { type SaveRefusal } from './save.js';
7
+ import type { Store } from './store.js';
8
+ export type SaveResult = {
9
+ outcome: 'saved';
10
+ identifier: string;
11
+ } | ({
12
+ outcome: 'refused';
13
+ } & SaveRefusal);
14
+ export type SavedRoomDraft = {
15
+ readonly path: string;
16
+ readonly revision: string;
17
+ };
18
+ export type SavedParts = {
19
+ readonly path: string;
20
+ readonly parts: RoomDraftParts;
21
+ };
22
+ export type AttachmentSurface = {
23
+ read(room: string, path: string, revision?: string): Promise<HeldAttachmentAnswer>;
24
+ link(room: string, path: string, revision?: string): Promise<AttachmentLinkAnswer>;
25
+ show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
26
+ attach(room: string, file: File): Promise<AttachAnswer>;
27
+ part(file: string, part: number): Promise<Uint8Array | null>;
28
+ };
29
+ export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
30
+ export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
31
+ export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
32
+ export declare function conversationFiles(runtime: Runtime): ConversationFiles;
33
+ export declare function attachmentSurface(runtime: Runtime): AttachmentSurface;
34
+ //# sourceMappingURL=saves.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAUA,OAAO,EAA2B,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAGzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAatB,OAAO,EAQL,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAsB,KAAK,EAAoB,MAAM,YAAY,CAAC;AAK9E,MA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,CAsCrB;AAuBD,wBAAgB,SAAS,CACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,SAAS,EAAE,SAAS,GAAG,SAAS,GAC/B,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAwOD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAK9F;AA+RD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAQrE"}
package/dist/saves.js ADDED
@@ -0,0 +1,464 @@
1
+ import { isImageType, parse } from '@agentshouse/mdmodel';
2
+ import { attachmentRecord } from './attachment.js';
3
+ import { changeSet } from './change-set.js';
4
+ import { queuedFile } from './change.js';
5
+ import { available, definitionsAt, typeAt } from './collection.js';
6
+ import { runtimeError } from './failure.js';
7
+ import { attachedFile } from './file.js';
8
+ import { roomDraftRevision } from './identity.js';
9
+ import { compositionFor } from './listing.js';
10
+ import { scoped } from './models.js';
11
+ import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
12
+ import { sameAttachment } from './overlay.js';
13
+ import { ancestors } from './paths.js';
14
+ import { connectionNow } from './preparation.js';
15
+ import { append, sliceAt, withdrawable } from './queue.js';
16
+ import { entryAt, replaying, slicing, } from './replica.js';
17
+ import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
18
+ import { refuse } from './refusal.js';
19
+ import { visibleOf } from './room-drafts.js';
20
+ import { destination, planSave, } from './save.js';
21
+ import { pendingShown } from './shown.js';
22
+ import { paced, ROW_WEIGHT, stepped } from './turn.js';
23
+ import { validatedNeighbourhood } from './validation.js';
24
+ const FULL = { outcome: 'refused', code: 'durable-write', retryable: true };
25
+ async function savedRoom({ store, presence }, locator) {
26
+ const replica = await store.replica(locator);
27
+ if (replica === undefined || presence.lost(locator)) {
28
+ throw runtimeError('unknown-room', `Unknown Room ${locator}`);
29
+ }
30
+ return replica;
31
+ }
32
+ export function saveRoomDrafts(runtime, locator, named, writtenBy) {
33
+ const { store } = runtime;
34
+ return store.exclusive(async () => {
35
+ if (store.space.full())
36
+ return FULL;
37
+ const replica = await savedRoom(runtime, locator);
38
+ const drafts = new Map((await store.drafts(locator, named.map(({ path }) => path))).map((record) => [record.path, record]));
39
+ const saved = [];
40
+ for (const { path, revision } of named) {
41
+ const record = drafts.get(path);
42
+ if (record === undefined || record.revision !== revision) {
43
+ return { outcome: 'refused', code: 'stale', retryable: false, file: path };
44
+ }
45
+ if (!saved.some((draft) => draft.path === path))
46
+ saved.push({ path, parts: record.parts });
47
+ }
48
+ const result = await loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
49
+ if (result.outcome !== 'refused' || result.code !== 'changed-underneath')
50
+ return result;
51
+ return joinedUnderneath(runtime, locator, saved.map(({ path }) => drafts.get(path)), result);
52
+ });
53
+ }
54
+ async function joinedUnderneath({ store }, locator, records, refused) {
55
+ const visible = (await visibleOf(store, locator, records.map(({ path }) => path)));
56
+ const joined = records.flatMap((record) => {
57
+ const join = joinedOver(record.parts, record.marks, record.path, visible);
58
+ return join === null ? [] : [{ ...record, ...join, revision: roomDraftRevision() }];
59
+ });
60
+ if (joined.length === 0)
61
+ return refused;
62
+ await (await store.open()).commit({ rooms: [], writes: [{ locator, roomDrafts: joined }] });
63
+ await store.changed(changeSet(locator, { drafts: joined.map(({ path }) => path) }));
64
+ return refused;
65
+ }
66
+ export function saveParts(runtime, locator, named, writtenBy) {
67
+ const { store } = runtime;
68
+ return store.exclusive(async () => {
69
+ const read = readSavedParts(named);
70
+ if (store.space.full())
71
+ return FULL;
72
+ const replica = await savedRoom(runtime, locator);
73
+ const saved = [];
74
+ const files = [];
75
+ const filed = read.filter(({ parts }) => parts.file !== undefined).map(({ path }) => path);
76
+ const visible = filed.length === 0 ? undefined : await visibleOf(store, locator, filed);
77
+ for (const { path, parts } of read) {
78
+ const file = parts.file === undefined
79
+ ? undefined
80
+ : await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
81
+ if (parts.file !== undefined && file !== undefined) {
82
+ files.push({ key: file.localId, blob: parts.file.blob });
83
+ }
84
+ saved.push({ path, parts: held(undefined, parts, file) });
85
+ }
86
+ return loaded(runtime, locator, replica, saved, new Set(), files, writtenBy);
87
+ });
88
+ }
89
+ async function unmodeledIn(runtime, record) {
90
+ const composition = compositionFor(runtime, record);
91
+ if (available(composition))
92
+ return false;
93
+ const local = await runtime.store.open();
94
+ const roots = record.declaration.typedSelection?.roots ?? [];
95
+ return local.typedWithin(record.key, 'visible', roots, false);
96
+ }
97
+ async function savingRoom(runtime, replica, changes, extra, drafted) {
98
+ const { store } = runtime;
99
+ const { record, queue, states } = replica;
100
+ const local = await store.open();
101
+ const paths = [
102
+ ...extra,
103
+ ...changes.flatMap((change) => change.kind === 'move' ? [change.path, change.to] : [change.path]),
104
+ ];
105
+ const moved = changes.flatMap((change) => (change.kind === 'move' ? [change.path] : []));
106
+ const removed = changes.flatMap((change) => (change.kind === 'remove' ? [change.path] : []));
107
+ const referring = removed.length === 0
108
+ ? []
109
+ : (await local.referrers(record.key, 'confirmed', removed)).map(({ path }) => path);
110
+ const confirmed = await sliceAt(store, record, 'confirmed', queue, [...paths, ...paths.flatMap(ancestors), ...referring], moved);
111
+ const composition = store.composed(record);
112
+ const changeable = withdrawable(states);
113
+ return {
114
+ held: { replica, confirmed },
115
+ room: {
116
+ record,
117
+ rule: runtime.writeRule(record.declaration),
118
+ composition: compositionFor(runtime, record),
119
+ queue,
120
+ changeable: new Set(queue.filter(changeable).map(({ id }) => id)),
121
+ saved: new Map([...states].map(([id, state]) => [id, state.drafts])),
122
+ *replay(over) {
123
+ return (yield* replaying(confirmed, over, record.locator, composition)).visible;
124
+ },
125
+ folders: new Set(await local.folders(record.key, paths)),
126
+ modelled: !(await unmodeledIn(runtime, record)),
127
+ drafts: new Map(drafted.length === 0
128
+ ? []
129
+ : (await store.drafts(record.locator, drafted)).map((held) => [held.path, held])),
130
+ validate: validatorOf(runtime, record, confirmed),
131
+ },
132
+ };
133
+ }
134
+ function targetsOf(saved) {
135
+ return saved.flatMap(({ parts }) => (parts.move === undefined ? [] : [moveTarget(parts.move)]));
136
+ }
137
+ async function loaded(runtime, locator, replica, saved, consumed, files, writtenBy) {
138
+ const { store } = runtime;
139
+ const localSaves = runtime.savesLocally(locator);
140
+ const into = destination(locator, saved);
141
+ const target = into === null ? undefined : await savedRoom(runtime, into);
142
+ const paths = saved.map(({ path }) => path);
143
+ const targets = targetsOf(saved);
144
+ const parts = saved.map(({ path, parts: held }) => changesOf(path, held));
145
+ const source = target === undefined
146
+ ? await savingRoom(runtime, replica, parts.flatMap(({ changes }) => changes), [...paths, ...parts.flatMap(({ bases }) => bases.map(({ path }) => path))], targets.length === 0 ? [] : [...paths, ...targets])
147
+ : await savingRoom(runtime, replica, paths.map((path) => ({ kind: 'remove', path })), paths, paths);
148
+ const arriving = target === undefined ? undefined : await savingRoom(runtime, target, [], targets, targets);
149
+ const { providerLimits } = await (await store.open()).facts();
150
+ const plan = await planSave({ saved, consumed, writtenBy, local: localSaves, providerLimits }, source.room, arriving?.room);
151
+ return append(runtime, {
152
+ plan,
153
+ files,
154
+ held: new Map([source, ...(arriving === undefined ? [] : [arriving])].map(({ room, held }) => [
155
+ room.record.locator,
156
+ held,
157
+ ])),
158
+ after: () => pendingShown(runtime, locator),
159
+ });
160
+ }
161
+ function textDiffers(left, right) {
162
+ return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
163
+ !sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
164
+ }
165
+ function textOf(entry) {
166
+ if (entry === null)
167
+ return undefined;
168
+ return entry.binary !== null ? null : entry.content;
169
+ }
170
+ function lookupOf(local, key, view) {
171
+ return async (paths) => {
172
+ if (paths.length === 0)
173
+ return new Map();
174
+ return new Map((await local.typed(key, view, paths)).map(({ path, type, binary }) => [
175
+ path,
176
+ { type: type ?? undefined, binary },
177
+ ]));
178
+ };
179
+ }
180
+ function declaredOf(composition, path, entry) {
181
+ if (entry.binary !== null)
182
+ return { type: undefined, binary: true };
183
+ const content = entry.content ?? '';
184
+ return {
185
+ type: typeAt(composition, path, parse(content, path, definitionsAt(composition, path))),
186
+ binary: false,
187
+ };
188
+ }
189
+ function overriddenLookup(composition, lookup, overrides) {
190
+ return async (paths) => {
191
+ const known = new Map(await lookup(paths.filter((path) => !overrides.has(path))));
192
+ for (const path of paths) {
193
+ const entry = overrides.get(path);
194
+ if (entry === undefined)
195
+ continue;
196
+ if (entry === null)
197
+ known.delete(path);
198
+ else
199
+ known.set(path, declaredOf(composition, path, entry));
200
+ }
201
+ return known;
202
+ };
203
+ }
204
+ function validatorOf(runtime, record, confirmedLayer) {
205
+ return async (resulting, touched) => {
206
+ const local = await runtime.store.open();
207
+ const changes = [];
208
+ const overrides = new Map();
209
+ const pace = paced();
210
+ for (const path of new Set([...confirmedLayer.held, ...touched])) {
211
+ await pace(ROW_WEIGHT);
212
+ const was = entryAt(confirmedLayer, path);
213
+ const now = entryAt(resulting, path);
214
+ if (!textDiffers(was, now))
215
+ continue;
216
+ overrides.set(path, now);
217
+ if (textOf(was) !== textOf(now))
218
+ changes.push({ path, was: textOf(was), now: textOf(now) });
219
+ }
220
+ const composition = compositionFor(runtime, record);
221
+ return validatedNeighbourhood(changes, composition, {
222
+ lookup: overriddenLookup(composition, lookupOf(local, record.key, 'confirmed'), overrides),
223
+ texts: textsOf(local, record.key, 'confirmed'),
224
+ referrers: referrersOf(local, record.key, 'confirmed'),
225
+ holders: (sought) => local.holders(record.key, 'confirmed', sought),
226
+ });
227
+ };
228
+ }
229
+ function textsOf(local, key, view) {
230
+ return async (paths) => new Map((await local.entries(key, view, paths)).map(({ path, content, binary }) => [
231
+ path,
232
+ binary !== null ? null : content,
233
+ ]));
234
+ }
235
+ function referrersOf(local, key, view) {
236
+ return async (targets) => [
237
+ ...new Set((await local.referrers(key, view, targets)).map(({ path }) => path)),
238
+ ];
239
+ }
240
+ async function queuedFacts(store, locator, path, localId) {
241
+ for (const batch of (await store.replica(locator))?.queue ?? []) {
242
+ const change = batch.changes[queuedFile(batch, path, localId)];
243
+ if (change?.kind === 'binary')
244
+ return change;
245
+ }
246
+ const drafted = (await store.draft(locator, path))?.parts.file;
247
+ return drafted?.localId === localId ? drafted : null;
248
+ }
249
+ export function batchFile(store, batch) {
250
+ return async (localId) => {
251
+ const change = batch.changes.find((held) => held.kind === 'binary' && held.localId === localId);
252
+ return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
253
+ };
254
+ }
255
+ async function transferAttachment(runtime, request, transfer, answer) {
256
+ const { store, socket, presence } = runtime;
257
+ const { session } = socket;
258
+ if (socket.closed() || session.now().refusal !== null)
259
+ return UNCERTAIN;
260
+ await socket.firstDiscovery;
261
+ if (!session.now().roomsNamed)
262
+ return UNCERTAIN;
263
+ try {
264
+ await socket.authorize();
265
+ }
266
+ catch {
267
+ return UNCERTAIN;
268
+ }
269
+ const { closed, authorization, refusal } = session.now();
270
+ if (closed || authorization === undefined || refusal !== null)
271
+ return UNCERTAIN;
272
+ const since = presence.losses();
273
+ try {
274
+ const result = await transfer(authorization);
275
+ const settled = result;
276
+ if (request.locator !== null && presence.lostSince(request.locator, since))
277
+ return failure({ kind: 'room-not-readable', locator: request.locator });
278
+ if (settled.kind === 'scoped-refusal') {
279
+ const room = await store.record(settled.locator);
280
+ if (room !== undefined)
281
+ await scoped(runtime, settled, room.locator, room.declaration);
282
+ }
283
+ if (settled.kind === 'revoked-authorization')
284
+ await refuse(runtime, 'revoked-authorization');
285
+ return answer(result);
286
+ }
287
+ catch {
288
+ return UNCERTAIN;
289
+ }
290
+ }
291
+ function fetchAttachment(runtime, request, name) {
292
+ const { store, socket } = runtime;
293
+ return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
294
+ }
295
+ async function readAttachment(runtime, request, name) {
296
+ if (runtime.socket.closed())
297
+ return UNCERTAIN;
298
+ const held = await runtime.store.opened.find(name);
299
+ if (held !== null)
300
+ return held;
301
+ return fetchAttachment(runtime, request, name);
302
+ }
303
+ async function attachmentPath(store, locator, path, revision) {
304
+ if (revision !== undefined)
305
+ return { kind: 'path', locator, path, revision };
306
+ const replica = await store.replica(locator);
307
+ const local = await store.open();
308
+ const [held] = replica === undefined ? [] : await local.entries(replica.record.key, 'visible', [path]);
309
+ const attached = held === undefined ? store.attached.of(locator, path) : undefined;
310
+ if (attached !== undefined)
311
+ return { kind: 'path', locator, path, revision: attached.revision };
312
+ if (replica === undefined || held?.binary === undefined || held.binary === null)
313
+ return null;
314
+ if (held.binary.state === 'pending')
315
+ return { kind: 'pending', localId: held.binary.localId };
316
+ const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
317
+ if (record.state !== 'accepted')
318
+ return null;
319
+ const queued = replica.queue.flatMap((batch) => batch.changes);
320
+ const sources = queued.flatMap((change) => (change.kind === 'move' ? [change.path] : []));
321
+ const confirmedLayer = await stepped(slicing(await local.entries(replica.record.key, 'confirmed', [path, ...sources]), [
322
+ path,
323
+ ...sources,
324
+ ]));
325
+ const holds = (at) => {
326
+ const kept = confirmedLayer.binaries[at];
327
+ return (kept?.state === 'accepted' &&
328
+ kept.sha256 === record.sha256 &&
329
+ confirmedLayer.revisions[at] === record.revision);
330
+ };
331
+ let confirmedAt = path;
332
+ for (let index = queued.length - 1; index >= 0 && !holds(confirmedAt); index -= 1) {
333
+ const change = queued[index];
334
+ if (change.kind === 'move' && change.to === confirmedAt)
335
+ confirmedAt = change.path;
336
+ }
337
+ return {
338
+ kind: 'path',
339
+ locator,
340
+ path: confirmedAt,
341
+ revision: record.revision,
342
+ };
343
+ }
344
+ async function askedAttachment({ store, socket }, locator, path, revision) {
345
+ await socket.ready;
346
+ const drafted = (await store.draft(locator, path))?.parts.file;
347
+ return drafted !== undefined && drafted.localId === revision
348
+ ? { kind: 'pending', localId: revision }
349
+ : attachmentPath(store, locator, path, revision);
350
+ }
351
+ async function pendingAttachment(store, locator, path, localId) {
352
+ const facts = await queuedFacts(store, locator, path, localId);
353
+ return facts === null
354
+ ? absentAttachment(path)
355
+ : {
356
+ kind: 'binary',
357
+ file: localId,
358
+ byteLength: facts.byteLength,
359
+ mediaType: facts.mediaType,
360
+ };
361
+ }
362
+ async function readAttachmentPath(runtime, locator, path, revision) {
363
+ const asked = await askedAttachment(runtime, locator, path, revision);
364
+ if (asked === null)
365
+ return absentAttachment(path);
366
+ if (asked.kind === 'pending')
367
+ return pendingAttachment(runtime.store, locator, path, asked.localId);
368
+ return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
369
+ }
370
+ async function heldMediaType(store, locator, path) {
371
+ const replica = await store.record(locator);
372
+ const [held] = replica === undefined ? [] : await (await store.open()).entries(replica.key, 'visible', [path]);
373
+ return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
374
+ }
375
+ function linkOf(runtime, asked, held) {
376
+ return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
377
+ }
378
+ async function linkAttachmentPath(runtime, locator, path, revision) {
379
+ const { store, socket } = runtime;
380
+ await socket.ready;
381
+ const asked = await attachmentPath(store, locator, path, revision);
382
+ if (asked === null || asked.kind === 'pending')
383
+ return absentAttachment(path);
384
+ return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
385
+ }
386
+ function shownImage(runtime, asked, name) {
387
+ const { store, socket } = runtime;
388
+ return new Promise((answer) => {
389
+ void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
390
+ const read = await socket.binary(authorization, asked);
391
+ const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
392
+ if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
393
+ answer({
394
+ kind: 'link',
395
+ url: read.url,
396
+ name: asked.path.slice(asked.path.lastIndexOf('/') + 1),
397
+ mediaType: read.mediaType,
398
+ copies,
399
+ });
400
+ }
401
+ return read;
402
+ }), attachmentAnswer).then(answer);
403
+ });
404
+ }
405
+ async function showAttachmentPath(runtime, locator, path, revision) {
406
+ const { store } = runtime;
407
+ const asked = await askedAttachment(runtime, locator, path, revision);
408
+ if (asked === null)
409
+ return absentAttachment(path);
410
+ if (asked.kind === 'pending')
411
+ return pendingAttachment(store, locator, path, asked.localId);
412
+ if (runtime.socket.closed())
413
+ return UNCERTAIN;
414
+ const name = { locator, path: asked.path, revision: asked.revision };
415
+ const kept = await store.opened.find(name);
416
+ if (kept !== null)
417
+ return kept;
418
+ const mediaType = await heldMediaType(store, locator, path);
419
+ if (mediaType !== undefined && isImageType(mediaType))
420
+ return shownImage(runtime, asked, name);
421
+ const linked = await linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
422
+ return linked.kind === 'link' ? { ...linked, copies: [] } : linked;
423
+ }
424
+ async function attachFile(runtime, locator, file, answer) {
425
+ const { store, socket } = runtime;
426
+ await socket.ready;
427
+ await socket.firstDiscovery;
428
+ if (socket.closed() ||
429
+ !socket.session.now().roomsNamed ||
430
+ (await connectionNow(runtime)) === 'unreachable' ||
431
+ socket.session.now().refusal !== null)
432
+ return OFFLINE;
433
+ const request = await attachedFile(locator, file);
434
+ return transferAttachment(runtime, { locator }, async (held) => {
435
+ const result = await socket.attach(held, request);
436
+ if (result.kind === 'attached' && locator !== null) {
437
+ store.attached.hold(locator, result.path, {
438
+ revision: result.revision,
439
+ mediaType: request.mediaType,
440
+ });
441
+ }
442
+ return result;
443
+ }, answer);
444
+ }
445
+ async function keyedAttachment(runtime, link) {
446
+ await runtime.socket.ready;
447
+ const asked = { kind: 'key', link };
448
+ return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
449
+ }
450
+ export function conversationFiles(runtime) {
451
+ return {
452
+ attach: (file) => attachFile(runtime, null, file, linkedAnswer),
453
+ attachment: (link) => keyedAttachment(runtime, link),
454
+ };
455
+ }
456
+ export function attachmentSurface(runtime) {
457
+ return {
458
+ part: runtime.store.part,
459
+ read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
460
+ link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
461
+ show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
462
+ attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
463
+ };
464
+ }
package/dist/search.d.ts CHANGED
@@ -1,73 +1,22 @@
1
- import type { ProviderRefusal } from './adapter.js';
2
- import { type CoveredRoom, type Filter, type PendingRoom } from './query.js';
3
- import type { Open } from './open.js';
4
- export type DocumentPart = Open<'fields' | 'sections' | 'preamble' | 'path'>;
1
+ import type { ProviderRefusal, SearchHit } from './adapter.js';
2
+ import type { Failure, Offline } from './outcome.js';
5
3
  export type SearchRequest = {
6
4
  text: string;
7
- documents?: Filter;
8
- collection?: true;
9
- conversations?: readonly string[];
10
- limit?: number;
11
- after?: string;
12
- total?: true;
5
+ rooms?: readonly string[];
13
6
  };
14
- export type MessagePart = Open<'text'>;
15
- export type Snippet<Part extends string> = {
16
- part: Part;
17
- text: string;
18
- at: readonly [number, number];
19
- };
20
- export type DocumentHit = {
21
- room: string;
22
- path: string;
23
- type: string;
24
- score: number;
25
- matches: Readonly<Record<string, readonly DocumentPart[]>>;
26
- snippet?: Snippet<DocumentPart>;
27
- };
28
- export type MessageHit = {
29
- conversation: string;
30
- identity: string;
31
- score: number;
32
- matches: Readonly<Record<string, readonly MessagePart[]>>;
33
- snippet?: Snippet<MessagePart>;
34
- };
35
- export type SearchCoverage = {
36
- rooms: readonly CoveredRoom[];
37
- conversations: readonly string[];
38
- overlay: readonly string[];
7
+ export type { SearchHit } from './adapter.js';
8
+ export type SearchFound = {
9
+ kind: 'found';
10
+ documents: readonly SearchHit[];
39
11
  };
40
- export type SearchHits = {
41
- documents: readonly DocumentHit[];
42
- messages: readonly MessageHit[];
43
- };
44
- export type SearchWindow = SearchHits & {
45
- next?: string;
46
- total?: {
47
- documents: number;
48
- messages: number;
49
- };
50
- };
51
- export type SearchPending = SearchHits & {
52
- pending: readonly PendingRoom[];
53
- coverage: SearchCoverage;
54
- };
55
- export type SearchUndeclared = ProviderRefusal & {
12
+ export type SearchResult = SearchFound | Offline | (ProviderRefusal & {
13
+ kind: 'rejected';
14
+ }) | (ProviderRefusal & {
56
15
  kind: 'undeclared';
57
- };
58
- export type SearchResult = (SearchWindow & {
59
- coverage: SearchCoverage;
60
- }) | SearchPending | SearchUndeclared;
61
- export declare function undeclaredSearch(): SearchUndeclared;
62
- export type HitCursor = readonly [number, string, string] | readonly [] | null;
16
+ }) | Failure;
63
17
  export type SearchPlan = {
64
18
  text: string;
65
- documents: unknown;
66
- collection: boolean;
67
- conversations: readonly string[] | null;
68
- limit: number | null;
69
- after: readonly [HitCursor, HitCursor] | null;
70
- total: boolean;
19
+ rooms: readonly string[] | null;
71
20
  };
72
21
  export declare function searchPlanOf(input: unknown): SearchPlan;
73
22
  //# sourceMappingURL=search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,S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.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAExE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,CAAC;AAE7E,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,OAAO,GACP,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,GACxC,CAAC,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,GAC1C,OAAO,CAAC;AAEZ,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAYvD"}
package/dist/search.js CHANGED
@@ -1,57 +1,14 @@
1
- import { flag, invalid, known, limitOf, plain, } from './query.js';
2
- import { decodedCursor } from './windows.js';
3
- export function undeclaredSearch() {
4
- return {
5
- kind: 'undeclared',
6
- code: 'search-undeclared',
7
- fields: { name: 'local_search' },
8
- retryable: false,
9
- };
10
- }
11
- function hitCursor(input) {
12
- if (input === null)
13
- return null;
14
- if (!Array.isArray(input))
15
- return undefined;
16
- if (input.length === 0)
17
- return [];
18
- const [score, first, second] = input;
19
- return input.length === 3 &&
20
- typeof score === 'number' &&
21
- typeof first === 'string' &&
22
- typeof second === 'string'
23
- ? [score, first, second]
24
- : undefined;
25
- }
26
- function searchAfter(input) {
27
- if (input === undefined)
28
- return null;
29
- const decoded = typeof input === 'string' ? decodedCursor(input) : null;
30
- const documents = decoded?.length === 2 ? hitCursor(decoded[0]) : undefined;
31
- const messages = decoded?.length === 2 ? hitCursor(decoded[1]) : undefined;
32
- if (documents === undefined || messages === undefined) {
33
- invalid('after', 'expects the next an earlier search returned');
34
- }
35
- return [documents, messages];
36
- }
1
+ import { invalid, known, plain } from '@agentshouse/mdmodel';
37
2
  export function searchPlanOf(input) {
38
3
  if (!plain(input))
39
4
  invalid('search', 'expects a search object');
40
- known(input, ['text', 'documents', 'collection', 'conversations', 'limit', 'after', 'total'], '');
41
- if (typeof input.text !== 'string')
42
- invalid('text', 'expects text');
43
- const conversations = input.conversations;
44
- if (conversations !== undefined &&
45
- (!Array.isArray(conversations) || conversations.some((named) => typeof named !== 'string'))) {
46
- invalid('conversations', 'expects a list of conversations');
5
+ known(input, ['text', 'rooms'], '');
6
+ if (typeof input.text !== 'string' || input.text.trim() === '')
7
+ invalid('text', 'expects words');
8
+ const rooms = input.rooms;
9
+ if (rooms !== undefined &&
10
+ (!Array.isArray(rooms) || rooms.some((named) => typeof named !== 'string'))) {
11
+ invalid('rooms', 'expects a list of Rooms');
47
12
  }
48
- return {
49
- text: input.text,
50
- documents: input.documents,
51
- collection: flag(input.collection, 'collection'),
52
- conversations: conversations ?? null,
53
- limit: limitOf(input.limit),
54
- after: searchAfter(input.after),
55
- total: flag(input.total, 'total'),
56
- };
13
+ return { text: input.text, rooms: rooms ?? null };
57
14
  }