@agentshouse/mdruntime 0.1.0-cf04ede9fb796 → 0.1.0-cf08df9b663d8

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 (322) 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 +105 -166
  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 +175 -85
  11. package/dist/adapter.d.ts +226 -74
  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 +2 -7
  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 +1 -1
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +6 -19
  25. package/dist/chain.d.ts +1 -1
  26. package/dist/chain.d.ts.map +1 -1
  27. package/dist/chain.js +5 -2
  28. package/dist/change-set.d.ts +4 -0
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +6 -0
  31. package/dist/change.d.ts +6 -2
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +7 -2
  34. package/dist/chat-types.d.ts +0 -2
  35. package/dist/chat-types.d.ts.map +1 -1
  36. package/dist/chat-types.js +2 -4
  37. package/dist/client.d.ts +30 -23
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +55 -68
  40. package/dist/collection.d.ts +27 -4
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +34 -10
  43. package/dist/column.d.ts +5 -0
  44. package/dist/column.d.ts.map +1 -0
  45. package/dist/column.js +9 -0
  46. package/dist/compile.d.ts +4 -1
  47. package/dist/compile.d.ts.map +1 -1
  48. package/dist/compile.js +101 -63
  49. package/dist/connection.d.ts +1 -1
  50. package/dist/connection.d.ts.map +1 -1
  51. package/dist/connection.js +42 -27
  52. package/dist/context.d.ts.map +1 -1
  53. package/dist/context.js +1 -1
  54. package/dist/conversation-live.d.ts +29 -15
  55. package/dist/conversation-live.d.ts.map +1 -1
  56. package/dist/conversation-live.js +26 -14
  57. package/dist/conversation-row.d.ts +23 -1
  58. package/dist/conversation-row.d.ts.map +1 -1
  59. package/dist/conversation-row.js +37 -8
  60. package/dist/conversation.d.ts +48 -16
  61. package/dist/conversation.d.ts.map +1 -1
  62. package/dist/conversation.js +368 -262
  63. package/dist/declaration.d.ts +10 -0
  64. package/dist/declaration.d.ts.map +1 -0
  65. package/dist/declaration.js +24 -0
  66. package/dist/discovery.d.ts +3 -1
  67. package/dist/discovery.d.ts.map +1 -1
  68. package/dist/discovery.js +47 -47
  69. package/dist/download.d.ts +6 -0
  70. package/dist/download.d.ts.map +1 -0
  71. package/dist/download.js +42 -0
  72. package/dist/durability.d.ts +6 -1
  73. package/dist/durability.d.ts.map +1 -1
  74. package/dist/durability.js +7 -0
  75. package/dist/entry.d.ts +26 -1
  76. package/dist/entry.d.ts.map +1 -1
  77. package/dist/entry.js +126 -36
  78. package/dist/expectation.d.ts +26 -13
  79. package/dist/expectation.d.ts.map +1 -1
  80. package/dist/expectation.js +72 -19
  81. package/dist/failure.d.ts +3 -0
  82. package/dist/failure.d.ts.map +1 -1
  83. package/dist/failure.js +8 -0
  84. package/dist/figures.d.ts +1 -1
  85. package/dist/figures.d.ts.map +1 -1
  86. package/dist/figures.js +6 -4
  87. package/dist/file.d.ts +1 -1
  88. package/dist/file.d.ts.map +1 -1
  89. package/dist/file.js +3 -2
  90. package/dist/holdings.d.ts.map +1 -1
  91. package/dist/holdings.js +5 -3
  92. package/dist/host.d.ts +24 -4
  93. package/dist/host.d.ts.map +1 -1
  94. package/dist/host.js +108 -32
  95. package/dist/house-query.d.ts +24 -0
  96. package/dist/house-query.d.ts.map +1 -0
  97. package/dist/house-query.js +102 -0
  98. package/dist/identity.d.ts +1 -1
  99. package/dist/identity.d.ts.map +1 -1
  100. package/dist/identity.js +1 -1
  101. package/dist/index.d.ts +29 -16
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +19 -9
  104. package/dist/install.d.ts +10 -6
  105. package/dist/install.d.ts.map +1 -1
  106. package/dist/install.js +92 -111
  107. package/dist/lifecycle.d.ts +2 -2
  108. package/dist/lifecycle.d.ts.map +1 -1
  109. package/dist/lifecycle.js +80 -54
  110. package/dist/linked-file.d.ts +7 -0
  111. package/dist/linked-file.d.ts.map +1 -0
  112. package/dist/linked-file.js +13 -0
  113. package/dist/listing.d.ts +29 -22
  114. package/dist/listing.d.ts.map +1 -1
  115. package/dist/listing.js +71 -79
  116. package/dist/live.d.ts +19 -3
  117. package/dist/live.d.ts.map +1 -1
  118. package/dist/live.js +97 -39
  119. package/dist/loaded.d.ts +7 -0
  120. package/dist/loaded.d.ts.map +1 -0
  121. package/dist/loaded.js +46 -0
  122. package/dist/locks.d.ts +2 -4
  123. package/dist/locks.d.ts.map +1 -1
  124. package/dist/locks.js +12 -39
  125. package/dist/lost.d.ts.map +1 -1
  126. package/dist/lost.js +11 -23
  127. package/dist/media.d.ts +20 -4
  128. package/dist/media.d.ts.map +1 -1
  129. package/dist/media.js +184 -37
  130. package/dist/memory.d.ts +10 -4
  131. package/dist/memory.d.ts.map +1 -1
  132. package/dist/memory.js +105 -41
  133. package/dist/messages.d.ts +21 -6
  134. package/dist/messages.d.ts.map +1 -1
  135. package/dist/messages.js +53 -41
  136. package/dist/modal.d.ts +2 -0
  137. package/dist/modal.d.ts.map +1 -0
  138. package/dist/modal.js +11 -0
  139. package/dist/model.d.ts +10 -8
  140. package/dist/model.d.ts.map +1 -1
  141. package/dist/model.js +6 -5
  142. package/dist/models.d.ts +4 -8
  143. package/dist/models.d.ts.map +1 -1
  144. package/dist/models.js +97 -139
  145. package/dist/name.d.ts +0 -1
  146. package/dist/name.d.ts.map +1 -1
  147. package/dist/name.js +3 -7
  148. package/dist/observation.d.ts +29 -12
  149. package/dist/observation.d.ts.map +1 -1
  150. package/dist/observation.js +217 -85
  151. package/dist/online.d.ts +7 -0
  152. package/dist/online.d.ts.map +1 -0
  153. package/dist/online.js +29 -0
  154. package/dist/opened.d.ts +6 -6
  155. package/dist/opened.d.ts.map +1 -1
  156. package/dist/opened.js +7 -7
  157. package/dist/opening.d.ts.map +1 -1
  158. package/dist/opening.js +24 -10
  159. package/dist/outcome.d.ts +33 -13
  160. package/dist/outcome.d.ts.map +1 -1
  161. package/dist/outcome.js +36 -6
  162. package/dist/overlay.d.ts +23 -8
  163. package/dist/overlay.d.ts.map +1 -1
  164. package/dist/overlay.js +132 -48
  165. package/dist/page-metadata.d.ts +8 -0
  166. package/dist/page-metadata.d.ts.map +1 -0
  167. package/dist/page-metadata.js +19 -0
  168. package/dist/parts.d.ts +6 -59
  169. package/dist/parts.d.ts.map +1 -1
  170. package/dist/parts.js +32 -122
  171. package/dist/paths.d.ts +1 -1
  172. package/dist/paths.js +1 -1
  173. package/dist/preparation.d.ts +33 -7
  174. package/dist/preparation.d.ts.map +1 -1
  175. package/dist/preparation.js +210 -92
  176. package/dist/presence.d.ts +58 -0
  177. package/dist/presence.d.ts.map +1 -0
  178. package/dist/presence.js +231 -0
  179. package/dist/queries.d.ts +2 -2
  180. package/dist/queries.d.ts.map +1 -1
  181. package/dist/queries.js +138 -80
  182. package/dist/query.d.ts +2 -3
  183. package/dist/query.d.ts.map +1 -1
  184. package/dist/questions.d.ts +1 -5
  185. package/dist/questions.d.ts.map +1 -1
  186. package/dist/questions.js +3 -8
  187. package/dist/queue.d.ts +40 -0
  188. package/dist/queue.d.ts.map +1 -0
  189. package/dist/queue.js +482 -0
  190. package/dist/reach.d.ts +15 -6
  191. package/dist/reach.d.ts.map +1 -1
  192. package/dist/reach.js +200 -40
  193. package/dist/react.d.ts +17 -1
  194. package/dist/react.d.ts.map +1 -1
  195. package/dist/react.js +33 -1
  196. package/dist/readiness.d.ts +23 -4
  197. package/dist/readiness.d.ts.map +1 -1
  198. package/dist/readiness.js +18 -10
  199. package/dist/reads.d.ts +5 -3
  200. package/dist/reads.d.ts.map +1 -1
  201. package/dist/reads.js +30 -15
  202. package/dist/recovery.d.ts +4 -1
  203. package/dist/recovery.d.ts.map +1 -1
  204. package/dist/recovery.js +31 -8
  205. package/dist/refresh.d.ts +1 -1
  206. package/dist/refresh.js +6 -6
  207. package/dist/refusal.d.ts.map +1 -1
  208. package/dist/refusal.js +5 -6
  209. package/dist/replica.d.ts +6 -17
  210. package/dist/replica.d.ts.map +1 -1
  211. package/dist/replica.js +18 -20
  212. package/dist/retried.d.ts +30 -0
  213. package/dist/retried.d.ts.map +1 -0
  214. package/dist/retried.js +72 -0
  215. package/dist/room-draft.d.ts +32 -9
  216. package/dist/room-draft.d.ts.map +1 -1
  217. package/dist/room-draft.js +282 -72
  218. package/dist/room-drafts.d.ts.map +1 -1
  219. package/dist/room-drafts.js +29 -23
  220. package/dist/room-list.d.ts +10 -0
  221. package/dist/room-list.d.ts.map +1 -0
  222. package/dist/room-list.js +47 -0
  223. package/dist/rows.d.ts +11 -3
  224. package/dist/rows.d.ts.map +1 -1
  225. package/dist/rows.js +28 -15
  226. package/dist/run-tables.d.ts +25 -0
  227. package/dist/run-tables.d.ts.map +1 -0
  228. package/dist/run-tables.js +98 -0
  229. package/dist/running.d.ts +5 -0
  230. package/dist/running.d.ts.map +1 -0
  231. package/dist/running.js +10 -0
  232. package/dist/runs.d.ts +27 -0
  233. package/dist/runs.d.ts.map +1 -0
  234. package/dist/runs.js +92 -0
  235. package/dist/runtime.d.ts +15 -20
  236. package/dist/runtime.d.ts.map +1 -1
  237. package/dist/save.d.ts +43 -90
  238. package/dist/save.d.ts.map +1 -1
  239. package/dist/save.js +338 -236
  240. package/dist/saves.d.ts +9 -45
  241. package/dist/saves.d.ts.map +1 -1
  242. package/dist/saves.js +208 -752
  243. package/dist/seed.d.ts.map +1 -1
  244. package/dist/seed.js +4 -5
  245. package/dist/selector.d.ts +3 -0
  246. package/dist/selector.d.ts.map +1 -0
  247. package/dist/selector.js +22 -0
  248. package/dist/shared.d.ts +0 -5
  249. package/dist/shared.d.ts.map +1 -1
  250. package/dist/shared.js +4 -90
  251. package/dist/shown.d.ts +10 -6
  252. package/dist/shown.d.ts.map +1 -1
  253. package/dist/shown.js +105 -73
  254. package/dist/socket/lanes.d.ts +12 -4
  255. package/dist/socket/lanes.d.ts.map +1 -1
  256. package/dist/socket/lanes.js +34 -8
  257. package/dist/socket/session.d.ts +4 -2
  258. package/dist/socket/session.d.ts.map +1 -1
  259. package/dist/socket/session.js +3 -0
  260. package/dist/socket.d.ts +9 -7
  261. package/dist/socket.d.ts.map +1 -1
  262. package/dist/socket.js +19 -18
  263. package/dist/source.d.ts +42 -7
  264. package/dist/source.d.ts.map +1 -1
  265. package/dist/source.js +81 -13
  266. package/dist/store/installs.d.ts +2 -2
  267. package/dist/store/installs.d.ts.map +1 -1
  268. package/dist/store/installs.js +10 -4
  269. package/dist/store/readiness.d.ts +5 -4
  270. package/dist/store/readiness.d.ts.map +1 -1
  271. package/dist/store/readiness.js +28 -12
  272. package/dist/store/records.d.ts +32 -10
  273. package/dist/store/records.d.ts.map +1 -1
  274. package/dist/store/records.js +71 -28
  275. package/dist/store/rooms-shown.d.ts +8 -0
  276. package/dist/store/rooms-shown.d.ts.map +1 -0
  277. package/dist/store/rooms-shown.js +13 -0
  278. package/dist/store/space.d.ts +1 -1
  279. package/dist/store/space.d.ts.map +1 -1
  280. package/dist/store/space.js +0 -2
  281. package/dist/store/watchers.js +1 -2
  282. package/dist/store.d.ts +25 -15
  283. package/dist/store.d.ts.map +1 -1
  284. package/dist/store.js +50 -18
  285. package/dist/stored.d.ts +42 -17
  286. package/dist/stored.d.ts.map +1 -1
  287. package/dist/stored.js +220 -62
  288. package/dist/surface.d.ts +20 -8
  289. package/dist/surface.d.ts.map +1 -1
  290. package/dist/surface.js +70 -35
  291. package/dist/sync.d.ts +4 -2
  292. package/dist/sync.d.ts.map +1 -1
  293. package/dist/sync.js +134 -109
  294. package/dist/tables.d.ts +40 -57
  295. package/dist/tables.d.ts.map +1 -1
  296. package/dist/tables.js +114 -334
  297. package/dist/tallies.d.ts.map +1 -1
  298. package/dist/tallies.js +8 -9
  299. package/dist/validation.d.ts +2 -0
  300. package/dist/validation.d.ts.map +1 -1
  301. package/dist/validation.js +51 -11
  302. package/dist/wire.d.ts +72 -12
  303. package/dist/wire.d.ts.map +1 -1
  304. package/dist/wire.js +31 -14
  305. package/package.json +4 -3
  306. package/dist/attempt.d.ts +0 -16
  307. package/dist/attempt.d.ts.map +0 -1
  308. package/dist/attempt.js +0 -70
  309. package/dist/binary.d.ts.map +0 -1
  310. package/dist/binary.js +0 -8
  311. package/dist/job.d.ts +0 -33
  312. package/dist/job.d.ts.map +0 -1
  313. package/dist/job.js +0 -54
  314. package/dist/log.d.ts +0 -6
  315. package/dist/log.d.ts.map +0 -1
  316. package/dist/log.js +0 -14
  317. package/dist/socket/rooms.d.ts +0 -44
  318. package/dist/socket/rooms.d.ts.map +0 -1
  319. package/dist/socket/rooms.js +0 -90
  320. package/dist/store/fences.d.ts +0 -16
  321. package/dist/store/fences.d.ts.map +0 -1
  322. package/dist/store/fences.js +0 -26
@@ -1,26 +1,27 @@
1
- import { parse, VERSION } from '@agentshouse/mdmodel';
1
+ import { definitionAt, folderType, parse, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
3
  import { hashed } from './observation.js';
4
4
  import { sortedKeys } from './shared.js';
5
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
6
6
  const typesPrinted = new WeakMap();
7
- function typesPrint(model) {
8
- if (model.status === 'unavailable')
9
- return '';
10
- let print = typesPrinted.get(model.types);
7
+ export function typesPrint(types) {
8
+ let print = typesPrinted.get(types);
11
9
  if (print === undefined) {
12
- print = hashed(JSON.stringify(model.types)).toString(36);
13
- typesPrinted.set(model.types, print);
10
+ print = hashed(JSON.stringify(types)).toString(36);
11
+ typesPrinted.set(types, print);
14
12
  }
15
13
  return print;
16
14
  }
15
+ function modelPrint(model) {
16
+ return model.status === 'unavailable' ? '' : typesPrint(model.types);
17
+ }
17
18
  export function composedOf(composition) {
18
19
  const { model, selection } = composition;
19
20
  return {
20
21
  composition,
21
22
  fingerprint: JSON.stringify([
22
- typesPrint(model),
23
- selection === null ? null : [selection.roots, typesPrint(selection.model)],
23
+ modelPrint(model),
24
+ selection === null ? null : [selection.roots, modelPrint(selection.model)],
24
25
  ]),
25
26
  };
26
27
  }
@@ -33,6 +34,16 @@ export function governing(composition, path) {
33
34
  ? composition.selection.model
34
35
  : composition.model;
35
36
  }
37
+ function definitionsUnder(composition, path, typedPaths, typesOf) {
38
+ const types = typesOf(governing(composition, path));
39
+ return types === null ? () => undefined : definitionAt({ types }, path, typedPaths);
40
+ }
41
+ export function definitionsAt(composition, path) {
42
+ return definitionsUnder(composition, path, composition.typedPaths, (model) => model.status === 'unavailable' ? null : model.types);
43
+ }
44
+ export function definitionsIn(room, path, typedPaths) {
45
+ return definitionsUnder({ model: room.model, selection: room.typedSelection }, path, typedPaths, ({ types }) => types === null ? null : Object.fromEntries(types.map((type) => [type.name, type])));
46
+ }
36
47
  export function collectionOf(text, composition) {
37
48
  const parsed = new Map();
38
49
  return {
@@ -44,7 +55,7 @@ export function collectionOf(text, composition) {
44
55
  const content = text[path];
45
56
  if (content === undefined)
46
57
  return undefined;
47
- const read = parse(content, path);
58
+ const read = parse(content, path, definitionsAt(composition, path));
48
59
  parsed.set(path, read.ok ? read.document : null);
49
60
  return read.ok ? read.document : undefined;
50
61
  },
@@ -63,6 +74,19 @@ export function* documentsOf(collection) {
63
74
  export function validRoot(root) {
64
75
  return typeof root === 'string' && normalize(root) === root;
65
76
  }
77
+ export const UNTYPED = 'any';
78
+ export function textType(read) {
79
+ return read.ok ? (read.document.type ?? UNTYPED) : undefined;
80
+ }
81
+ export function typeAt(composition, path, read) {
82
+ if (!read.ok || read.document.type !== undefined)
83
+ return textType(read);
84
+ const model = governing(composition, path);
85
+ return (model.status === 'unavailable' ? undefined : folderType(model, path)) ?? UNTYPED;
86
+ }
87
+ export function typedText(read) {
88
+ return (textType(read) ?? UNTYPED) !== UNTYPED;
89
+ }
66
90
  export function available(composition) {
67
91
  return composition.model.status !== 'unavailable';
68
92
  }
@@ -0,0 +1,5 @@
1
+ import type { Row, Value } from './tables.js';
2
+ export declare function text(value: Value | undefined): string;
3
+ export declare function texts(rows: readonly Row[], column: string): string[];
4
+ export declare function count(value: Value | undefined): number;
5
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAErD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAEtD"}
package/dist/column.js ADDED
@@ -0,0 +1,9 @@
1
+ export function text(value) {
2
+ return typeof value === 'string' ? value : String(value);
3
+ }
4
+ export function texts(rows, column) {
5
+ return rows.map((row) => text(row[column]));
6
+ }
7
+ export function count(value) {
8
+ return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
9
+ }
package/dist/compile.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { sql } from '@agentshouse/mdmodel';
2
+ import { type Composition } from './collection.js';
2
3
  import type { Plan, QueryRows } from './query.js';
3
4
  import type { Connection } from './tables.js';
4
5
  export type QueryRoom = {
5
6
  readonly locator: string;
6
7
  readonly key: number;
8
+ readonly composition?: Composition;
7
9
  };
8
10
  type Fragment = sql.Fragment;
9
11
  export declare const VISIBLE: (alias: string) => string;
@@ -11,6 +13,7 @@ export declare function within(alias: string, path: string): Fragment;
11
13
  export type QueryAnswer = QueryRows & {
12
14
  readonly more?: string;
13
15
  };
14
- export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
16
+ export declare function namedHandles(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], handles: readonly string[]): readonly string[];
17
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null, follows?: readonly QueryRoom[]): QueryAnswer;
15
18
  export {};
16
19
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAOJ,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MACkC,CAAC;AAa3E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAM5D;AA0cD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAmajE,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAUb"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAQJ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACpC,CAAC;AAEF,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAAyD,CAAC;AAsBlG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE5D;AAufD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkajE,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE,CAenB;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,OAAO,GAAE,SAAS,SAAS,EAAO,GACjC,WAAW,CAUb"}
package/dist/compile.js CHANGED
@@ -1,19 +1,24 @@
1
1
  import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
2
- import { binaryRecord } from './binary.js';
2
+ import { attachmentRecord } from './attachment.js';
3
+ import { definitionsAt, UNTYPED } from './collection.js';
3
4
  import { documentKey, pathOfKey, roomOfKey } from './rows.js';
5
+ import { ROOM_HANDLE } from './stored.js';
4
6
  import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
5
7
  const { all, any, exists, fragment, grouped, joined, listed } = sql;
6
- export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1 AND ${alias}.queried = 1`;
8
+ export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1`;
7
9
  function located(alias) {
8
10
  return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
9
11
  }
10
- export function within(alias, path) {
11
- return fragment(`(${alias}.path = ? OR (${alias}.path >= ? AND ${alias}.path < ?))`, [
12
- path,
13
- `${path}/`,
14
- `${path}0`,
12
+ function inside(path, folder) {
13
+ return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
14
+ folder,
15
+ `${folder}/`,
16
+ `${folder}0`,
15
17
  ]);
16
18
  }
19
+ export function within(alias, path) {
20
+ return inside(`${alias}.path`, path);
21
+ }
17
22
  function ancestors(area) {
18
23
  const depth = area.path.split('/').length;
19
24
  return area.open.flatMap((open) => {
@@ -21,18 +26,18 @@ function ancestors(area) {
21
26
  return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
22
27
  });
23
28
  }
24
- function fenced(alias, key, area, folders) {
29
+ function fenced(key, path, held, area, folders) {
25
30
  const opened = any([
26
- ...area.open.map((open) => within(alias, open)),
27
- ...(folders ? ancestors(area).map((path) => fragment(`${alias}.path = ?`, [path])) : []),
31
+ ...area.open.map((open) => inside(path, open)),
32
+ ...(folders ? ancestors(area).map((ancestor) => fragment(`${path} = ?`, [ancestor])) : []),
28
33
  ]);
29
34
  return all([
30
- fragment(`${alias}.key = ?`, [key]),
31
- within(alias, area.path),
35
+ fragment(`${key} = ?`, [held]),
36
+ inside(path, area.path),
32
37
  fragment(`NOT ${grouped(opened).sql}`, opened.bind),
33
38
  ]);
34
39
  }
35
- function reached(bound, alias) {
40
+ function reached(bound, key, path) {
36
41
  const reach = bound.reach;
37
42
  if (reach === null)
38
43
  return fragment('1');
@@ -45,49 +50,65 @@ function reached(bound, alias) {
45
50
  return key === undefined ? [] : [[key, pathOfKey(held)]];
46
51
  });
47
52
  const outside = any(reach.areas.flatMap((area) => {
48
- const key = bound.keys.get(area.room);
49
- return key === undefined ? [] : [fenced(alias, key, area, false)];
53
+ const held = bound.keys.get(area.room);
54
+ return held === undefined ? [] : [fenced(key, path, held, area, false)];
50
55
  }));
51
56
  return all([
52
57
  any([
53
- ...(rooms.length === 0 ? [] : [fragment(`${alias}.key IN ${listed(rooms).sql}`, rooms)]),
58
+ ...(rooms.length === 0 ? [] : [fragment(`${key} IN ${listed(rooms).sql}`, rooms)]),
54
59
  ...(documents.length === 0
55
60
  ? []
56
61
  : [
57
- fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${alias}.key AND j.value ->> 1 = ${alias}.path)`, [JSON.stringify(documents)]),
62
+ fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${key} AND j.value ->> 1 = ${path})`, [JSON.stringify(documents)]),
58
63
  ]),
59
64
  ]),
60
65
  ...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
61
66
  ]);
62
67
  }
68
+ function handled(bound, link) {
69
+ return fragment(`FROM replica_rooms h WHERE ${ROOM_HANDLE('h')} = ${link}.handle AND h.key IN (SELECT value FROM json_each(?))`, [bound.follows]);
70
+ }
71
+ function followed(bound) {
72
+ return {
73
+ targets: (link, document) => {
74
+ const room = handled(bound, link);
75
+ return joined([
76
+ fragment(`replica_entries ${document} ON ${document}.key = CASE WHEN ${link}.handle IS NULL THEN d.key ELSE (SELECT h.key ${room.sql}) END AND ${document}.path = ${link}.target AND ${VISIBLE(document)} AND`, room.bind),
77
+ grouped(reached(bound, `${document}.key`, `${document}.path`)),
78
+ ], ' ');
79
+ },
80
+ unfollowed: (link) => {
81
+ const own = reached(bound, 'd.key', `${link}.target`);
82
+ const room = handled(bound, link);
83
+ const other = reached(bound, 'h.key', `${link}.target`);
84
+ return fragment(`NOT ((${link}.handle IS NULL AND ${own.sql}) OR EXISTS (SELECT 1 ${room.sql} AND ${other.sql}))`, [...own.bind, ...room.bind, ...other.bind]);
85
+ },
86
+ };
87
+ }
63
88
  function related(bound, plan) {
64
89
  const parts = [];
65
- if (plan.hop !== null) {
66
- parts.push(exists(joined([
67
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries m ON m.key = d.key AND m.path = l.target AND ${VISIBLE('m')} WHERE l.doc = d.id AND l.kind = 'field' AND`),
68
- grouped(sql.placed('l', plan.hop.field, 'link')),
69
- fragment('AND'),
70
- grouped(all([sql.scoped('m', plan.hop), reached(bound, 'm')])),
71
- ], ' ')));
72
- }
90
+ if (plan.hop !== null)
91
+ parts.push(sql.hopped('d', plan.hop, followed(bound)));
73
92
  if (plan.backlinks !== null) {
74
93
  const field = plan.backlinks.field;
75
94
  parts.push(exists(joined([
76
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.target = d.path AND l.kind = 'field' AND`),
95
+ fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.handle IS NULL AND l.target = d.path AND l.kind = 'field' AND`),
77
96
  ...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
78
- grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
97
+ grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's.key', 's.path')])),
79
98
  ], ' ')));
80
99
  }
81
100
  return parts;
82
101
  }
83
- function filtered(bound, plan) {
102
+ function tested(bound, plan) {
84
103
  const keys = bound.rooms.map(({ key }) => key);
85
- return all([
104
+ return [
86
105
  fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
87
- reached(bound, 'd'),
106
+ reached(bound, 'd.key', 'd.path'),
88
107
  sql.tests('d', plan),
89
- ...related(bound, plan),
90
- ]);
108
+ ];
109
+ }
110
+ function filtered(bound, plan) {
111
+ return all([...tested(bound, plan), ...related(bound, plan)]);
91
112
  }
92
113
  function orderingOf(options) {
93
114
  const stringSort = options.stringSort ?? 'locale';
@@ -310,11 +331,20 @@ function sectionsOf(sections, names) {
310
331
  return sections;
311
332
  return Object.fromEntries(names.flatMap((name) => (Object.hasOwn(sections, name) ? [[name, sections[name]]] : [])));
312
333
  }
313
- function documentOf(shape, room, row, linked) {
334
+ function freeParts(room, path, type, content) {
335
+ const definitions = room.composition === undefined ? undefined : definitionsAt(room.composition, path);
336
+ const definition = definitions?.(type === UNTYPED ? undefined : type);
337
+ if (definition === undefined && type !== UNTYPED)
338
+ return null;
339
+ const read = parse(content, path, definition);
340
+ return read.ok ? read.document : null;
341
+ }
342
+ function documentOf(shape, queried, row, linked) {
343
+ const room = queried.locator;
314
344
  const path = row.path;
315
345
  const type = row.type;
316
- const fileId = row.file_id ?? null;
317
- const revision = row.revision ?? null;
346
+ const fileId = row.file_id;
347
+ const revision = row.revision;
318
348
  if (type === null) {
319
349
  const binary = row.binary === null ? null : JSON.parse(row.binary);
320
350
  const content = row.content ?? null;
@@ -324,7 +354,7 @@ function documentOf(shape, room, row, linked) {
324
354
  ...(binary === null
325
355
  ? {}
326
356
  : {
327
- binaryFile: binaryRecord(path, binary, revision ?? undefined),
357
+ attachment: attachmentRecord(path, binary, revision ?? undefined),
328
358
  }),
329
359
  ...(shape.markdown && content !== null ? { markdown: content } : {}),
330
360
  ...(shape.change ? { change: changeOf(row) } : {}),
@@ -333,8 +363,9 @@ function documentOf(shape, room, row, linked) {
333
363
  ...heldFacts(shape, row),
334
364
  };
335
365
  }
336
- const read = bodied(shape) ? parse(row.content, path) : null;
337
- const body = read?.ok === true ? read.document : null;
366
+ const body = shape.sections !== null || shape.preamble
367
+ ? freeParts(queried, path, type, row.content)
368
+ : null;
338
369
  const fields = JSON.parse(row.fields ?? '{}');
339
370
  return {
340
371
  room,
@@ -365,7 +396,7 @@ function changeOf(row) {
365
396
  function heldFacts(shape, row) {
366
397
  return {
367
398
  ...(shape.size ? { size: row.bytes === null ? null : Number(row.bytes) } : {}),
368
- ...(shape.created ? { created: row.created ?? null } : {}),
399
+ ...(shape.created ? { created: row.created } : {}),
369
400
  };
370
401
  }
371
402
  function backlinksOf(connection, bound, rows) {
@@ -377,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
377
408
  held.push(row.path);
378
409
  byKey.set(key, held);
379
410
  }
411
+ const reach = reached(bound, 's.key', 's.path');
380
412
  for (const [key, targets] of byKey) {
381
- const reach = reached(bound, 's');
382
413
  const room = bound.rooms.find((one) => one.key === key).locator;
383
- const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
414
+ const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND handle IS NULL AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
384
415
  for (const row of found) {
385
416
  const at = documentKey(room, row.target);
386
417
  const held = linked.get(at) ?? [];
@@ -395,22 +426,19 @@ function documents(connection, bound, plan, shape, budget) {
395
426
  const filter = filtered(bound, plan);
396
427
  const cursor = plan.after?.values ?? null;
397
428
  const room = located('d');
398
- const tie = cursor === null
429
+ const after = cursor === null
399
430
  ? null
400
431
  : (() => {
401
432
  const key = cursor[shape.orderBy.length];
402
- return any([
433
+ return sql.following(terms.map(({ term }, index) => sql.beyond(bound.collate, term, cursor[index])), any([
403
434
  fragment(`${room.sql} > ?`, [...room.bind, roomOfKey(key)]),
404
435
  fragment(`${room.sql} = ? AND d.path > ?`, [
405
436
  ...room.bind,
406
437
  roomOfKey(key),
407
438
  pathOfKey(key),
408
439
  ]),
409
- ]);
440
+ ]));
410
441
  })();
411
- const after = cursor === null || tie === null
412
- ? null
413
- : sql.following(terms.map(({ term }, index) => sql.beyond(bound.collate, term, cursor[index])), tie);
414
442
  const selected = joined([
415
443
  fragment('SELECT d.id, d.key, d.path, d.type, d.binary, d.revision, d.fields, d.change, d.file_id, d.bytes, d.created'),
416
444
  ...terms.map(({ term }, index) => joined([
@@ -431,8 +459,9 @@ function documents(connection, bound, plan, shape, budget) {
431
459
  const kept = bodied(shape) ? withContent(connection, windowed, budget) : windowed;
432
460
  const cut = kept.length;
433
461
  const roomOf = new Map(bound.rooms.map(({ key, locator }) => [key, locator]));
462
+ const queried = new Map(bound.rooms.map((one) => [one.key, one]));
434
463
  const linked = shape.backlinks ? backlinksOf(connection, bound, kept) : new Map();
435
- const found = kept.map((row) => documentOf(shape, roomOf.get(Number(row.key)), row, linked));
464
+ const found = kept.map((row) => documentOf(shape, queried.get(Number(row.key)), row, linked));
436
465
  const last = kept.at(-1);
437
466
  const cursorAt = (row) => cursorOf([
438
467
  ...shape.orderBy.map(({ key }, index) => decodedKey(key, row, index)),
@@ -497,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
497
526
  const key = bound.keys.get(area.room);
498
527
  if (key === undefined)
499
528
  return [];
500
- const fence = fenced('f', key, area, true);
529
+ const fence = fenced('f.key', 'f.path', key, area, true);
501
530
  return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
502
531
  });
503
532
  const under = prefix === ''
@@ -645,17 +674,14 @@ function groups(connection, bound, plan, shape) {
645
674
  { ordering: GROUP_TIES, kind: fragment("'string'"), value: fragment(`k${index}`) },
646
675
  ]);
647
676
  const cursor = plan.after?.values ?? null;
648
- const tieValues = cursor === null
677
+ const after = cursor === null
649
678
  ? null
650
- : cursor[shape.orderBy.length].flatMap((value) => [
651
- value,
652
- heldKind(value ?? null),
653
- ]);
654
- const after = cursor === null || tieValues === null
655
- ? null
656
- : sql.following(ordered.map((term, index) => sql.beyond(bound.collate, term, cursor[index])), sql.following(ties
657
- .slice(0, -1)
658
- .map((term, index) => sql.beyond(bound.collate, term, tieValues[index])), sql.beyond(bound.collate, ties.at(-1), tieValues.at(-1)).beyond));
679
+ : (() => {
680
+ const tieValues = cursor[shape.orderBy.length].flatMap((value) => [value, heldKind(value ?? null)]);
681
+ return sql.following(ordered.map((term, index) => sql.beyond(bound.collate, term, cursor[index])), sql.following(ties
682
+ .slice(0, -1)
683
+ .map((term, index) => sql.beyond(bound.collate, term, tieValues[index])), sql.beyond(bound.collate, ties.at(-1), tieValues.at(-1)).beyond));
684
+ })();
659
685
  const grouping = joined([fragment(`SELECT ${columns} FROM (`), ranked, fragment(`) GROUP BY ${held}`)], '');
660
686
  const windowed = joined([
661
687
  fragment('SELECT * FROM ('),
@@ -696,16 +722,28 @@ function groups(connection, bound, plan, shape) {
696
722
  ...(total === undefined ? {} : { total }),
697
723
  };
698
724
  }
699
- function boundOf(connection, plan, rooms) {
725
+ function boundOf(connection, plan, rooms, follows) {
700
726
  return {
701
727
  rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
702
- keys: new Map(rooms.map(({ locator, key }) => [locator, key])),
728
+ keys: new Map([...rooms, ...follows].map(({ locator, key }) => [locator, key])),
729
+ follows: JSON.stringify(follows.map(({ key }) => key)),
703
730
  reach: plan.reach,
704
731
  collate: collating(connection),
705
732
  };
706
733
  }
707
- export function answerQuery(connection, plan, rooms, budget = null) {
708
- const bound = boundOf(connection, plan, rooms);
734
+ export function namedHandles(connection, plan, rooms, handles) {
735
+ if (plan.hop === null)
736
+ return [];
737
+ const statement = joined([
738
+ fragment("SELECT DISTINCT l.handle FROM replica_entries d JOIN replica_links l ON l.doc = d.id AND l.kind = 'field' AND l.handle IN (SELECT value FROM json_each(?)) AND ", [JSON.stringify(handles)]),
739
+ grouped(sql.placed('l', plan.hop.field, 'link')),
740
+ fragment(' WHERE '),
741
+ all(tested(boundOf(connection, plan, rooms, []), plan)),
742
+ ], '');
743
+ return connection.rows(statement.sql, statement.bind).map((row) => row.handle);
744
+ }
745
+ export function answerQuery(connection, plan, rooms, budget = null, follows = []) {
746
+ const bound = boundOf(connection, plan, rooms, follows);
709
747
  if (rooms.length === 0) {
710
748
  return plan.shape.kind === 'groups'
711
749
  ? { groups: [], ...(plan.total ? { total: 0 } : {}) }
@@ -10,8 +10,8 @@ export type MdRuntimeOptions = {
10
10
  authorization?: Authorization;
11
11
  signal?: AbortSignal;
12
12
  recovery?: Recovery;
13
- usableWhenHeld?: readonly string[];
14
13
  build?: string;
14
+ storeOnNeed?: boolean;
15
15
  };
16
16
  export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
17
17
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUrE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAGrE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA+FzE"}
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsC,MAAM,cAAc,CAAC;AAI/F,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUrE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAOrE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA6GzE"}
@@ -1,33 +1,40 @@
1
- import { submitLater, unpair } from './acceptance.js';
1
+ import { notReadyWaitMs } from '@agentshouse/mdmodel';
2
+ import { submitLater } from './acceptance.js';
2
3
  import { invokeAction, called, readConversationHistory, resendLater } from './actions.js';
3
- import { builtInModel, roomTypesOf } from './attached-model.js';
4
+ import { builtInModel, NO_ROOM_TYPES } from './attached-model.js';
4
5
  import { createLiveConversations } from './conversation-live.js';
6
+ import { writeRule } from './declaration.js';
5
7
  import { refusedForSpace } from './durability.js';
8
+ import { uncaught } from './failure.js';
6
9
  import { createFigures } from './figures.js';
7
10
  import { scheduleCurrency, spaceFreed, start } from './lifecycle.js';
8
11
  import { createLiveQueries } from './live.js';
9
- import { createLog } from './log.js';
10
- import { scoped } from './models.js';
11
12
  import { open } from './opening.js';
12
- import { deliverOwedReadiness, filled } from './preparation.js';
13
+ import { deliverOwedReadiness, filled, prepare } from './preparation.js';
14
+ import { createPresence } from './presence.js';
13
15
  import { answeredPlan, figuresCover, roomTallies } from './queries.js';
14
16
  import { readAnswers } from './reads.js';
15
17
  import { createRecovery } from './recovery.js';
16
- import { settle } from './saves.js';
18
+ import { createRetries } from './retried.js';
17
19
  import { publishChangeSet, show } from './shown.js';
18
20
  import { createSocket } from './socket.js';
19
21
  import { createStore } from './store.js';
20
22
  import { composedRuntime } from './surface.js';
21
- import { advanced, withhold } from './sync.js';
23
+ import { adopt, discover } from './sync.js';
24
+ function writable(room) {
25
+ return room !== undefined && room.operations.write.length > 0;
26
+ }
22
27
  const ROOM_ATTEMPTS = 16;
23
28
  export function composeRuntime(options) {
24
29
  const { adapter, shell } = options;
25
- const roomTypes = roomTypesOf(adapter.roomTypes, adapter.nameableRoomTypes);
30
+ const roomTypes = adapter.roomTypes ?? NO_ROOM_TYPES;
26
31
  const builtIn = builtInModel(roomTypes);
27
32
  const typedPaths = adapter.typedPaths ?? [];
28
- const journal = createLog();
29
- const socket = createSocket(adapter, journal, options.authorization);
33
+ const retries = createRetries(shell);
34
+ const socket = createSocket(adapter, retries, options.authorization);
35
+ const presence = createPresence(notReadyWaitMs);
30
36
  const store = createStore({
37
+ retries,
31
38
  database: {
32
39
  async ask(request) {
33
40
  try {
@@ -44,30 +51,39 @@ export function composeRuntime(options) {
44
51
  builtIn,
45
52
  typedPaths,
46
53
  persistence: shell.persistence,
54
+ lost: presence.lost,
55
+ losing: presence.losing,
47
56
  opening: (local) => open(runtime, local),
48
- unpublished(error) {
49
- journal.record(`publication failed ${error instanceof Error ? error.name : 'unknown'}`);
57
+ unpublished: uncaught,
58
+ changed(set) {
59
+ if (set.unindexed.length > 0)
60
+ prepare(runtime, set.unindexed);
61
+ for (const locator of set.due)
62
+ submitLater(runtime, locator);
63
+ return publishChangeSet(runtime, set);
50
64
  },
51
- changed: (set) => publishChangeSet(runtime, set),
52
- deliverReadiness: (owed) => deliverOwedReadiness(runtime, owed),
65
+ deliverReadiness: (owed, rooms) => deliverOwedReadiness(runtime, owed, rooms),
53
66
  spaceFreed: () => spaceFreed(runtime),
54
67
  });
55
68
  const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
56
69
  const runtime = {
57
70
  store,
58
71
  socket,
59
- journal,
72
+ presence,
60
73
  recovery,
74
+ retries,
61
75
  shell,
62
- localSaves: adapter.localSaves === true,
76
+ savesLocally: (locator) => adapter.localSaves === true && !writable(presence.room(locator)),
63
77
  roomTypes,
64
78
  builtIn,
65
79
  typedPaths,
66
- pathRule: adapter.pathRule ?? (() => true),
67
- usableWhenHeld: options.usableWhenHeld ?? [],
80
+ renamedActions: adapter.renamedActions ?? new Map(),
81
+ rewrittenInputs: adapter.rewrittenInputs ?? new Map(),
82
+ keptInput: adapter.keptInput ?? ((input) => input),
83
+ writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true && !writable(declaration)),
68
84
  build: options.build ?? '',
69
85
  conversations: createLiveConversations({
70
- call: (name, input) => invokeAction(runtime, name, input),
86
+ call: (name, input, attempt) => invokeAction(runtime, name, input, { attempt }),
71
87
  history: (request) => readConversationHistory(runtime, request),
72
88
  durably: store.durably,
73
89
  local: store.open,
@@ -83,7 +99,9 @@ export function composeRuntime(options) {
83
99
  full: store.space.full,
84
100
  closed: socket.closed,
85
101
  unanswered: () => resendLater(runtime),
102
+ heard: (operation, lost) => socket.lanes.settle(operation, lost),
86
103
  recovery: recovery.scope(),
104
+ retries,
87
105
  }),
88
106
  liveQueries: createLiveQueries((plan, cover) => answeredPlan(runtime, plan, cover), store.covering),
89
107
  figures: createFigures({
@@ -97,20 +115,17 @@ export function composeRuntime(options) {
97
115
  unkept: adapter.unkeptReads ?? [],
98
116
  leading: adapter.leadingReads ?? [],
99
117
  recovery: recovery.scope(),
100
- call: (name, input) => called(runtime, name, input),
118
+ retries,
119
+ call: (name, input, attempt) => called(runtime, name, input, attempt),
101
120
  online: socket.reached,
102
121
  streaming: socket.isOpen,
103
122
  closed: socket.closed,
104
123
  full: store.space.full,
105
124
  filled: () => filled(runtime),
106
125
  }),
107
- settle: (...held) => settle(runtime, ...held),
108
- scoped: (...held) => scoped(runtime, ...held),
109
- submitLater: (locator) => submitLater(runtime, locator),
110
- unpair: (local) => unpair(runtime, local),
111
- advanced: (...held) => advanced(runtime, ...held),
112
- withhold: (...held) => withhold(runtime, ...held),
126
+ discover: () => discover(runtime),
127
+ adopt: (unstored) => adopt(runtime, unstored),
113
128
  };
114
- start(runtime, options.signal);
129
+ start(runtime, options.signal, options.storeOnNeed === true);
115
130
  return composedRuntime(runtime);
116
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIpD"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKpD"}
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function contextFigure(tokens) {
2
- if (tokens >= 1_000_000)
2
+ if (Math.round(tokens / 1_000) >= 1_000)
3
3
  return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
4
4
  if (tokens >= 1_000)
5
5
  return `${Math.round(tokens / 1_000)}k`;