@agentshouse/mdruntime 0.1.0-cd50a4607cb7d → 0.1.0-cd9e28a590f84

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 (226) hide show
  1. package/README.md +19 -16
  2. package/dist/adapter.d.ts +146 -70
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +38 -4
  7. package/dist/binary.d.ts +0 -5
  8. package/dist/binary.d.ts.map +1 -1
  9. package/dist/binary.js +1 -1
  10. package/dist/bootstrap.d.ts +26 -10
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +180 -99
  13. package/dist/chain.d.ts +11 -0
  14. package/dist/chain.d.ts.map +1 -0
  15. package/dist/chain.js +64 -0
  16. package/dist/change-set.d.ts +9 -16
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -88
  19. package/dist/change.d.ts +31 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +22 -10
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +97 -11
  25. package/dist/collection.d.ts +10 -21
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +39 -291
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +789 -0
  31. package/dist/connection.d.ts +37 -12
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +3425 -1118
  34. package/dist/conversation.d.ts +31 -14
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +521 -202
  37. package/dist/digest.d.ts +7 -0
  38. package/dist/digest.d.ts.map +1 -0
  39. package/dist/digest.js +113 -0
  40. package/dist/durability.d.ts +4 -1
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/durability.js +5 -0
  43. package/dist/entry.d.ts +4 -1
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +19 -23
  46. package/dist/file.d.ts +2 -19
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +7 -122
  49. package/dist/host.d.ts +10 -3
  50. package/dist/host.d.ts.map +1 -1
  51. package/dist/host.js +118 -19
  52. package/dist/identity.d.ts +0 -1
  53. package/dist/identity.d.ts.map +1 -1
  54. package/dist/identity.js +0 -3
  55. package/dist/index.d.ts +15 -10
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +6 -1
  58. package/dist/live.d.ts +22 -0
  59. package/dist/live.d.ts.map +1 -0
  60. package/dist/live.js +123 -0
  61. package/dist/media.d.ts +8 -0
  62. package/dist/media.d.ts.map +1 -0
  63. package/dist/media.js +218 -0
  64. package/dist/memory.d.ts +16 -6
  65. package/dist/memory.d.ts.map +1 -1
  66. package/dist/memory.js +207 -96
  67. package/dist/messages.d.ts +28 -0
  68. package/dist/messages.d.ts.map +1 -0
  69. package/dist/messages.js +89 -0
  70. package/dist/model.d.ts +9 -3
  71. package/dist/model.d.ts.map +1 -1
  72. package/dist/model.js +8 -11
  73. package/dist/name.d.ts +4 -0
  74. package/dist/name.d.ts.map +1 -0
  75. package/dist/name.js +122 -0
  76. package/dist/observation.d.ts +15 -0
  77. package/dist/observation.d.ts.map +1 -1
  78. package/dist/observation.js +93 -3
  79. package/dist/opened.d.ts +22 -0
  80. package/dist/opened.d.ts.map +1 -0
  81. package/dist/opened.js +107 -0
  82. package/dist/outcome.d.ts +45 -7
  83. package/dist/outcome.d.ts.map +1 -1
  84. package/dist/outcome.js +39 -0
  85. package/dist/overlay.d.ts +3 -5
  86. package/dist/overlay.d.ts.map +1 -1
  87. package/dist/overlay.js +95 -156
  88. package/dist/paths.d.ts +1 -0
  89. package/dist/paths.d.ts.map +1 -1
  90. package/dist/paths.js +4 -0
  91. package/dist/phrase.d.ts +3 -0
  92. package/dist/phrase.d.ts.map +1 -0
  93. package/dist/phrase.js +8 -0
  94. package/dist/query.d.ts +43 -2
  95. package/dist/query.d.ts.map +1 -1
  96. package/dist/query.js +67 -7
  97. package/dist/reach.d.ts +16 -4
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +218 -74
  100. package/dist/react.d.ts +6 -3
  101. package/dist/react.d.ts.map +1 -1
  102. package/dist/react.js +7 -17
  103. package/dist/readiness.d.ts +50 -0
  104. package/dist/readiness.d.ts.map +1 -0
  105. package/dist/readiness.js +27 -0
  106. package/dist/recovery.d.ts +3 -2
  107. package/dist/recovery.d.ts.map +1 -1
  108. package/dist/recovery.js +34 -7
  109. package/dist/refresh.d.ts +17 -14
  110. package/dist/refresh.d.ts.map +1 -1
  111. package/dist/refresh.js +155 -52
  112. package/dist/replica.d.ts +55 -33
  113. package/dist/replica.d.ts.map +1 -1
  114. package/dist/replica.js +300 -182
  115. package/dist/room-draft.d.ts +36 -5
  116. package/dist/room-draft.d.ts.map +1 -1
  117. package/dist/room-draft.js +161 -74
  118. package/dist/rows.d.ts +39 -29
  119. package/dist/rows.d.ts.map +1 -1
  120. package/dist/rows.js +178 -94
  121. package/dist/save.d.ts +53 -14
  122. package/dist/save.d.ts.map +1 -1
  123. package/dist/save.js +529 -185
  124. package/dist/search.d.ts +15 -77
  125. package/dist/search.d.ts.map +1 -1
  126. package/dist/search.js +10 -186
  127. package/dist/seed.d.ts +16 -0
  128. package/dist/seed.d.ts.map +1 -0
  129. package/dist/seed.js +75 -0
  130. package/dist/shared.d.ts +7 -3
  131. package/dist/shared.d.ts.map +1 -1
  132. package/dist/shared.js +119 -66
  133. package/dist/status.d.ts +4 -3
  134. package/dist/status.d.ts.map +1 -1
  135. package/dist/status.js +3 -1
  136. package/dist/store.d.ts +104 -94
  137. package/dist/store.d.ts.map +1 -1
  138. package/dist/store.js +337 -637
  139. package/dist/stored.d.ts +162 -0
  140. package/dist/stored.d.ts.map +1 -0
  141. package/dist/stored.js +549 -0
  142. package/dist/tables.d.ts +353 -0
  143. package/dist/tables.d.ts.map +1 -0
  144. package/dist/tables.js +585 -0
  145. package/dist/transfer.d.ts +0 -5
  146. package/dist/transfer.d.ts.map +1 -1
  147. package/dist/turn.d.ts +5 -3
  148. package/dist/turn.d.ts.map +1 -1
  149. package/dist/turn.js +51 -21
  150. package/dist/validation.d.ts +29 -0
  151. package/dist/validation.d.ts.map +1 -0
  152. package/dist/validation.js +101 -0
  153. package/dist/windows.d.ts +22 -0
  154. package/dist/windows.d.ts.map +1 -0
  155. package/dist/windows.js +89 -0
  156. package/dist/wire.d.ts +165 -32
  157. package/dist/wire.d.ts.map +1 -1
  158. package/dist/wire.js +56 -31
  159. package/package.json +18 -19
  160. package/AGENTS.md +0 -296
  161. package/dist/chat/acts.d.ts +0 -33
  162. package/dist/chat/acts.d.ts.map +0 -1
  163. package/dist/chat/acts.js +0 -36
  164. package/dist/chat/context.d.ts +0 -3
  165. package/dist/chat/context.d.ts.map +0 -1
  166. package/dist/chat/context.js +0 -10
  167. package/dist/chat/input.d.ts +0 -9
  168. package/dist/chat/input.d.ts.map +0 -1
  169. package/dist/chat/input.js +0 -99
  170. package/dist/chat/kit.d.ts +0 -60
  171. package/dist/chat/kit.d.ts.map +0 -1
  172. package/dist/chat/kit.js +0 -123
  173. package/dist/chat/lasting.d.ts +0 -6
  174. package/dist/chat/lasting.d.ts.map +0 -1
  175. package/dist/chat/lasting.js +0 -19
  176. package/dist/chat/list.d.ts +0 -26
  177. package/dist/chat/list.d.ts.map +0 -1
  178. package/dist/chat/list.js +0 -62
  179. package/dist/chat/markdown.d.ts +0 -20
  180. package/dist/chat/markdown.d.ts.map +0 -1
  181. package/dist/chat/markdown.js +0 -188
  182. package/dist/chat/message.d.ts +0 -6
  183. package/dist/chat/message.d.ts.map +0 -1
  184. package/dist/chat/message.js +0 -192
  185. package/dist/chat/messages.d.ts +0 -21
  186. package/dist/chat/messages.d.ts.map +0 -1
  187. package/dist/chat/messages.js +0 -151
  188. package/dist/chat/name.d.ts +0 -6
  189. package/dist/chat/name.d.ts.map +0 -1
  190. package/dist/chat/name.js +0 -37
  191. package/dist/chat/opened.d.ts +0 -11
  192. package/dist/chat/opened.d.ts.map +0 -1
  193. package/dist/chat/opened.js +0 -17
  194. package/dist/chat/overlay.d.ts +0 -31
  195. package/dist/chat/overlay.d.ts.map +0 -1
  196. package/dist/chat/overlay.js +0 -97
  197. package/dist/chat/parts.d.ts +0 -57
  198. package/dist/chat/parts.d.ts.map +0 -1
  199. package/dist/chat/parts.js +0 -119
  200. package/dist/chat/process.d.ts +0 -20
  201. package/dist/chat/process.d.ts.map +0 -1
  202. package/dist/chat/process.js +0 -32
  203. package/dist/chat/provider.d.ts +0 -63
  204. package/dist/chat/provider.d.ts.map +0 -1
  205. package/dist/chat/provider.js +0 -620
  206. package/dist/chat/question.d.ts +0 -9
  207. package/dist/chat/question.d.ts.map +0 -1
  208. package/dist/chat/question.js +0 -80
  209. package/dist/chat/questions.d.ts +0 -31
  210. package/dist/chat/questions.d.ts.map +0 -1
  211. package/dist/chat/questions.js +0 -111
  212. package/dist/chat/read.d.ts +0 -5
  213. package/dist/chat/read.d.ts.map +0 -1
  214. package/dist/chat/read.js +0 -13
  215. package/dist/chat/ready.d.ts +0 -33
  216. package/dist/chat/ready.d.ts.map +0 -1
  217. package/dist/chat/ready.js +0 -91
  218. package/dist/chat/style.d.ts +0 -4
  219. package/dist/chat/style.d.ts.map +0 -1
  220. package/dist/chat/style.js +0 -302
  221. package/dist/chat.d.ts +0 -14
  222. package/dist/chat.d.ts.map +0 -1
  223. package/dist/chat.js +0 -8
  224. package/dist/read-side.d.ts +0 -25
  225. package/dist/read-side.d.ts.map +0 -1
  226. package/dist/read-side.js +0 -639
@@ -0,0 +1,7 @@
1
+ export type Digest = {
2
+ update(bytes: Uint8Array): void;
3
+ hex(): string;
4
+ };
5
+ export declare function digest(): Digest;
6
+ export declare function sha256(blob: Blob): Promise<string>;
7
+ //# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AA0EA,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,GAAG,IAAI,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,MAAM,IAAI,MAAM,CAoC/B;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAMxD"}
package/dist/digest.js ADDED
@@ -0,0 +1,113 @@
1
+ import { FILE_PART_BYTES } from './tables.js';
2
+ const ROUNDS = new Uint32Array([
3
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
4
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
5
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
6
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
7
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
8
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
9
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
10
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
11
+ ]);
12
+ const INITIAL = [
13
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
14
+ ];
15
+ const BLOCK = 64;
16
+ function rotated(value, by) {
17
+ return (value >>> by) | (value << (32 - by));
18
+ }
19
+ function compressed(state, words, bytes, at) {
20
+ for (let index = 0; index < 16; index += 1) {
21
+ const from = at + index * 4;
22
+ words[index] =
23
+ (bytes[from] << 24) | (bytes[from + 1] << 16) | (bytes[from + 2] << 8) | bytes[from + 3];
24
+ }
25
+ for (let index = 16; index < 64; index += 1) {
26
+ const early = words[index - 15];
27
+ const late = words[index - 2];
28
+ const lower = rotated(early, 7) ^ rotated(early, 18) ^ (early >>> 3);
29
+ const upper = rotated(late, 17) ^ rotated(late, 19) ^ (late >>> 10);
30
+ words[index] = (words[index - 16] + lower + words[index - 7] + upper) | 0;
31
+ }
32
+ let a = state[0];
33
+ let b = state[1];
34
+ let c = state[2];
35
+ let d = state[3];
36
+ let e = state[4];
37
+ let f = state[5];
38
+ let g = state[6];
39
+ let h = state[7];
40
+ for (let index = 0; index < 64; index += 1) {
41
+ const chosen = (e & f) ^ (~e & g);
42
+ const first = (h +
43
+ (rotated(e, 6) ^ rotated(e, 11) ^ rotated(e, 25)) +
44
+ chosen +
45
+ ROUNDS[index] +
46
+ words[index]) |
47
+ 0;
48
+ const second = ((rotated(a, 2) ^ rotated(a, 13) ^ rotated(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
49
+ h = g;
50
+ g = f;
51
+ f = e;
52
+ e = (d + first) | 0;
53
+ d = c;
54
+ c = b;
55
+ b = a;
56
+ a = (first + second) | 0;
57
+ }
58
+ state[0] += a;
59
+ state[1] += b;
60
+ state[2] += c;
61
+ state[3] += d;
62
+ state[4] += e;
63
+ state[5] += f;
64
+ state[6] += g;
65
+ state[7] += h;
66
+ }
67
+ export function digest() {
68
+ const state = new Uint32Array(INITIAL);
69
+ const words = new Uint32Array(64);
70
+ const pending = new Uint8Array(BLOCK);
71
+ let held = 0;
72
+ let size = 0;
73
+ return {
74
+ update(bytes) {
75
+ size += bytes.length;
76
+ let from = 0;
77
+ if (held > 0) {
78
+ const taken = Math.min(BLOCK - held, bytes.length);
79
+ pending.set(bytes.subarray(0, taken), held);
80
+ held += taken;
81
+ from = taken;
82
+ if (held < BLOCK)
83
+ return;
84
+ compressed(state, words, pending, 0);
85
+ held = 0;
86
+ }
87
+ for (; from + BLOCK <= bytes.length; from += BLOCK)
88
+ compressed(state, words, bytes, from);
89
+ pending.set(bytes.subarray(from), 0);
90
+ held = bytes.length - from;
91
+ },
92
+ hex() {
93
+ const bits = size * 8;
94
+ const tail = new Uint8Array(held < 56 ? BLOCK : BLOCK * 2);
95
+ tail.set(pending.subarray(0, held));
96
+ tail[held] = 0x80;
97
+ const length = new DataView(tail.buffer, tail.length - 8);
98
+ length.setUint32(0, Math.floor(bits / 0x1_0000_0000));
99
+ length.setUint32(4, bits >>> 0);
100
+ const final = new Uint32Array(state);
101
+ for (let from = 0; from < tail.length; from += BLOCK)
102
+ compressed(final, words, tail, from);
103
+ return [...final].map((word) => word.toString(16).padStart(8, '0')).join('');
104
+ },
105
+ };
106
+ }
107
+ export async function sha256(blob) {
108
+ const hashed = digest();
109
+ for (let at = 0; at < blob.size; at += FILE_PART_BYTES) {
110
+ hashed.update(new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer()));
111
+ }
112
+ return hashed.hex();
113
+ }
@@ -1,9 +1,12 @@
1
+ import type { Persistence } from './readiness.js';
1
2
  export type RuntimeShell = {
2
- persistentStorage: boolean;
3
+ persistence: Persistence;
3
4
  generation: string | null;
4
5
  keepGeneration(value: string): void | Promise<void>;
5
6
  dropGeneration(): void | Promise<void>;
7
+ cleanUp?(): Promise<number>;
6
8
  };
9
+ export declare function refusedForSpace(error: unknown): boolean;
7
10
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
8
11
  export declare function nextGeneration(stored: string | null, reported: string | null): string;
9
12
  //# sourceMappingURL=durability.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAG/F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGrF"}
1
+ {"version":3,"file":"durability.d.ts","sourceRoot":"","sources":["../src/durability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMvD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAG/F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGrF"}
@@ -1,4 +1,9 @@
1
1
  const STORAGE_LOSS_CODE = 'storage-loss';
2
+ export function refusedForSpace(error) {
3
+ return (typeof error === 'object' &&
4
+ error !== null &&
5
+ error.name === 'QuotaExceededError');
6
+ }
2
7
  export function detectStorageLoss(stored, reported) {
3
8
  if (reported === null || reported === stored)
4
9
  return null;
package/dist/entry.d.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import type { VerifiedModel } from '@agentshouse/mdmodel';
1
2
  import { type QueryRows } from './query.js';
3
+ import type { Connection } from './tables.js';
2
4
  export { QueryError } from './query.js';
3
5
  export type EntryRoom = {
4
6
  locator: string;
5
7
  schema: string | null;
6
8
  documents: Readonly<Record<string, string>>;
9
+ revisions?: Readonly<Record<string, string>>;
7
10
  };
8
11
  export type EntryArguments = Readonly<Record<string, string>>;
9
12
  export type EntryParameterKind = 'string' | 'integer' | 'number' | 'boolean';
@@ -13,5 +16,5 @@ export declare function entryRefusal(template: unknown): string | null;
13
16
  export type EntryScope = {
14
17
  results(queries: Readonly<Record<string, unknown>>): Promise<Record<string, QueryRows>>;
15
18
  };
16
- export declare function entryScope(rooms: readonly EntryRoom[]): EntryScope;
19
+ export declare function entryScope(rooms: readonly EntryRoom[], roomTypes: VerifiedModel, connection: Connection): EntryScope;
17
20
  //# sourceMappingURL=entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,SAAS,EAEf,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,QAAQ,CAAC,MAAM,CA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AAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AA0D7E,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAE3E;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAMpE;AAkCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQ7D;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CACzF,CAAC;AAEF,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,SAAS,EAAE,aAAa,EACxB,UAAU,EAAE,UAAU,GACrB,UAAU,CAoDZ"}
package/dist/entry.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { attachedModel } from './attached-model.js';
2
- import { collectionOf, passingFrontmatter } from './collection.js';
2
+ import { answerQuery } from './compile.js';
3
3
  import { NO_MODEL } from './model.js';
4
4
  import { invalid, planOf, plain, QueryError, } from './query.js';
5
- import { createReadSide } from './read-side.js';
6
- import { rowsOf } from './rows.js';
5
+ import { entered, REPLICA_TABLES } from './stored.js';
7
6
  export { QueryError } from './query.js';
8
7
  const PARAMETER = '$param';
9
8
  const KIND = 'as';
@@ -110,45 +109,42 @@ export function entryRefusal(template) {
110
109
  throw error;
111
110
  }
112
111
  }
113
- export function entryScope(rooms) {
114
- const readSide = createReadSide();
112
+ export function entryScope(rooms, roomTypes, connection) {
113
+ for (const table of REPLICA_TABLES)
114
+ connection.run(table);
115
115
  const held = [];
116
- const documents = rooms.flatMap((room) => {
116
+ const keys = rooms.map((room) => {
117
117
  const model = attachedModel({
118
118
  kind: 'model',
119
119
  snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
120
- }, NO_MODEL).state;
120
+ }, NO_MODEL, roomTypes).state;
121
121
  held.push({
122
122
  locator: room.locator,
123
123
  available: model.status !== 'unavailable',
124
124
  types: model.status === 'unavailable' ? [] : Object.values(model.types),
125
125
  });
126
126
  const composition = { model, selection: null };
127
- const collection = collectionOf(room.documents, composition);
128
- return Object.keys(room.documents)
127
+ const key = entered(connection, room.locator, composition, Object.keys(room.documents)
129
128
  .sort()
130
129
  .map((path) => ({
131
- locator: room.locator,
132
130
  path,
133
- before: [],
134
- after: rowsOf(room.locator, path, passingFrontmatter(collection, path) ?? null, composition, null, null),
135
- }));
136
- });
137
- readSide.apply({
138
- documents,
139
- drafts: [],
140
- rooms: [],
141
- queues: [],
142
- presentations: [],
143
- messages: [],
144
- conversations: [],
131
+ content: room.documents[path],
132
+ outline: null,
133
+ binary: null,
134
+ revision: room.revisions?.[path] ?? null,
135
+ fileId: null,
136
+ change: null,
137
+ written: null,
138
+ })));
139
+ return { locator: room.locator, key };
145
140
  });
146
141
  const planned = { listed: true, rooms: held };
147
142
  return {
148
143
  async results(queries) {
149
144
  const results = {};
150
145
  for (const [name, query] of Object.entries(queries)) {
151
- results[name] = (await readSide.query(planOf(query, planned), () => null)).rows;
146
+ const plan = planOf(query, planned);
147
+ results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
152
148
  }
153
149
  return results;
154
150
  },
package/dist/file.d.ts CHANGED
@@ -1,20 +1,3 @@
1
- export type ChatDraftFile = {
2
- name: string;
3
- blob: Blob;
4
- };
5
- export type FileDeclaration = {
6
- name: string;
7
- mediaType: string;
8
- byteLength: number;
9
- contentHash: string;
10
- width?: number;
11
- height?: number;
12
- };
13
- export type Extent = {
14
- width: number;
15
- height: number;
16
- };
17
- export declare function extentOf(bytes: Uint8Array): Extent | null;
18
- export declare function hexDigest(digest: ArrayBuffer): string;
19
- export declare function declaredFile(file: ChatDraftFile): Promise<FileDeclaration>;
1
+ import type { AttachRequest } from './adapter.js';
2
+ export declare function attachedFile(locator: string, file: File): Promise<AttachRequest>;
20
3
  //# sourceMappingURL=file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA2GvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAQzD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAErD;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAUhF"}
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAStF"}
package/dist/file.js CHANGED
@@ -1,126 +1,11 @@
1
- const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
2
- const WEBP_SYNC = [0x9d, 0x01, 0x2a];
3
- const SHAPELESS_JPEG_MARKERS = new Set([0xc4, 0xc8, 0xcc]);
4
- const BMFF_CONTAINERS = new Set(['meta', 'iprp', 'ipco']);
5
- function starts(bytes, signature, at = 0) {
6
- return signature.every((value, index) => bytes[at + index] === value);
7
- }
8
- function text(bytes, at, length) {
9
- return String.fromCharCode(...bytes.subarray(at, at + length));
10
- }
11
- function bigEndian(bytes, at, length) {
12
- let value = 0;
13
- for (let index = 0; index < length; index += 1)
14
- value = value * 256 + (bytes[at + index] ?? 0);
15
- return value;
16
- }
17
- function littleEndian(bytes, at, length) {
18
- let value = 0;
19
- for (let index = length - 1; index >= 0; index -= 1)
20
- value = value * 256 + (bytes[at + index] ?? 0);
21
- return value;
22
- }
23
- function pngExtent(bytes) {
24
- if (bytes.length < 24 || !starts(bytes, PNG_SIGNATURE))
25
- return null;
26
- if (text(bytes, 12, 4) !== 'IHDR')
27
- return null;
28
- return { width: bigEndian(bytes, 16, 4), height: bigEndian(bytes, 20, 4) };
29
- }
30
- function gifExtent(bytes) {
31
- if (bytes.length < 10 || text(bytes, 0, 3) !== 'GIF')
32
- return null;
33
- return { width: littleEndian(bytes, 6, 2), height: littleEndian(bytes, 8, 2) };
34
- }
35
- function jpegExtent(bytes) {
36
- if (bytes.length < 4 || bytes[0] !== 0xff || bytes[1] !== 0xd8)
37
- return null;
38
- let at = 2;
39
- while (at + 9 < bytes.length) {
40
- if (bytes[at] !== 0xff)
41
- return null;
42
- const marker = bytes[at + 1] ?? 0;
43
- if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
44
- at += 2;
45
- continue;
46
- }
47
- const length = bigEndian(bytes, at + 2, 2);
48
- if (marker >= 0xc0 && marker <= 0xcf && !SHAPELESS_JPEG_MARKERS.has(marker)) {
49
- return { width: bigEndian(bytes, at + 7, 2), height: bigEndian(bytes, at + 5, 2) };
50
- }
51
- if (length < 2)
52
- return null;
53
- at += 2 + length;
54
- }
55
- return null;
56
- }
57
- function webpExtent(bytes) {
58
- if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP')
59
- return null;
60
- const chunk = text(bytes, 12, 4);
61
- if (chunk === 'VP8X') {
62
- return {
63
- width: littleEndian(bytes, 24, 3) + 1,
64
- height: littleEndian(bytes, 27, 3) + 1,
65
- };
66
- }
67
- if (chunk === 'VP8 ' && starts(bytes, WEBP_SYNC, 23)) {
68
- return {
69
- width: littleEndian(bytes, 26, 2) & 0x3fff,
70
- height: littleEndian(bytes, 28, 2) & 0x3fff,
71
- };
72
- }
73
- if (chunk === 'VP8L' && bytes[20] === 0x2f) {
74
- const packed = littleEndian(bytes, 21, 4);
75
- return { width: (packed & 0x3fff) + 1, height: ((packed >>> 14) & 0x3fff) + 1 };
76
- }
77
- return null;
78
- }
79
- function spatialExtent(bytes, from, to) {
80
- let at = from;
81
- while (at + 8 <= to) {
82
- const size = bigEndian(bytes, at, 4);
83
- const name = text(bytes, at + 4, 4);
84
- const end = size === 0 ? to : at + size;
85
- if (size === 1 || end <= at || end > to)
86
- return null;
87
- if (name === 'ispe') {
88
- if (end < at + 20)
89
- return null;
90
- return { width: bigEndian(bytes, at + 12, 4), height: bigEndian(bytes, at + 16, 4) };
91
- }
92
- if (BMFF_CONTAINERS.has(name)) {
93
- const inner = spatialExtent(bytes, at + (name === 'meta' ? 12 : 8), end);
94
- if (inner !== null)
95
- return inner;
96
- }
97
- at = end;
98
- }
99
- return null;
100
- }
101
- function bmffExtent(bytes) {
102
- if (bytes.length < 16 || text(bytes, 4, 4) !== 'ftyp')
103
- return null;
104
- return spatialExtent(bytes, 0, bytes.length);
105
- }
106
- export function extentOf(bytes) {
107
- return (pngExtent(bytes) ??
108
- jpegExtent(bytes) ??
109
- gifExtent(bytes) ??
110
- webpExtent(bytes) ??
111
- bmffExtent(bytes));
112
- }
113
- export function hexDigest(digest) {
114
- return [...new Uint8Array(digest)].map((value) => value.toString(16).padStart(2, '0')).join('');
115
- }
116
- export async function declaredFile(file) {
117
- const bytes = new Uint8Array(await file.blob.arrayBuffer());
118
- const extent = file.blob.type.startsWith('image/') ? extentOf(bytes) : null;
1
+ import { sha256 } from './digest.js';
2
+ export async function attachedFile(locator, file) {
119
3
  return {
4
+ locator,
120
5
  name: file.name,
121
- mediaType: file.blob.type,
122
- byteLength: bytes.byteLength,
123
- contentHash: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
124
- ...(extent === null ? {} : extent),
6
+ mediaType: file.type,
7
+ byteLength: file.size,
8
+ sha256: await sha256(file),
9
+ blob: file,
125
10
  };
126
11
  }
package/dist/host.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type MdRuntimeOptions } from './connection.js';
2
2
  import type { PortReach } from './reach.js';
3
+ import type { CodeAvailability, Persistence, Readiness, Space } from './readiness.js';
4
+ import type { EntrySeed } from './seed.js';
3
5
  import { type RuntimePort } from './wire.js';
4
6
  export type MdRuntimeHostOptions = MdRuntimeOptions & {
5
7
  deploymentFacts?: unknown;
@@ -7,16 +9,21 @@ export type MdRuntimeHostOptions = MdRuntimeOptions & {
7
9
  export type AttachedPort = {
8
10
  detach(): void;
9
11
  narrow(reach: PortReach): void;
12
+ readiness(deliver: (readiness: Readiness) => void): () => void;
13
+ answered(queries: readonly unknown[], done: () => void): void;
14
+ code(code: CodeAvailability, space: Space | null): void;
10
15
  };
11
16
  export type MdRuntimeHost = {
12
- attach(port: RuntimePort, app: string, release?: string, reach?: PortReach): AttachedPort;
17
+ attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability): AttachedPort;
18
+ seed(entry: EntrySeed): void;
19
+ persisted(answer: Persistence): void;
13
20
  endAuthorization(holder?: string): Promise<void>;
14
- lose(locators: readonly string[]): Promise<void>;
15
21
  stop(): Promise<void>;
16
22
  };
17
23
  export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
24
+ export { entrySeedOf, type EntrySeed } from './seed.js';
18
25
  export type { PortReach, ReachedDocument } from './reach.js';
26
+ export type { CodeAvailability, Persistence, Space } from './readiness.js';
19
27
  export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
20
- export { AUTHORED_SCHEMA, authoredBinding, authoredBy, authoredHolder, bindAuthored, STORE_SCHEMA, } from './store.js';
21
28
  export type { RuntimePort } from './wire.js';
22
29
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,OAAO,EAGL,KAAK,WAAW,EAOjB,MAAM,WAAW,CAAC;AAInB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC;IAC1F,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,O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