@agentshouse/mdruntime 0.1.0-c698c0ebd65bd → 0.1.0-c6dd3e87e3f5e

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 (229) hide show
  1. package/README.md +18 -15
  2. package/dist/adapter.d.ts +125 -50
  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 +27 -11
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +184 -85
  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 -14
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +11 -63
  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 +25 -14
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +97 -11
  25. package/dist/collection.d.ts +10 -7
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +38 -79
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +786 -0
  31. package/dist/connection.d.ts +44 -17
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +3496 -976
  34. package/dist/conversation.d.ts +33 -14
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +571 -242
  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 +6 -3
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +18 -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/fulltext.d.ts +27 -0
  50. package/dist/fulltext.d.ts.map +1 -0
  51. package/dist/fulltext.js +370 -0
  52. package/dist/host.d.ts +12 -3
  53. package/dist/host.d.ts.map +1 -1
  54. package/dist/host.js +125 -19
  55. package/dist/identity.d.ts +1 -0
  56. package/dist/identity.d.ts.map +1 -1
  57. package/dist/identity.js +3 -0
  58. package/dist/index.d.ts +16 -10
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -0
  61. package/dist/live.d.ts +22 -0
  62. package/dist/live.d.ts.map +1 -0
  63. package/dist/live.js +123 -0
  64. package/dist/media.d.ts +8 -0
  65. package/dist/media.d.ts.map +1 -0
  66. package/dist/media.js +218 -0
  67. package/dist/memory.d.ts +14 -6
  68. package/dist/memory.d.ts.map +1 -1
  69. package/dist/memory.js +198 -94
  70. package/dist/messages.d.ts +28 -0
  71. package/dist/messages.d.ts.map +1 -0
  72. package/dist/messages.js +90 -0
  73. package/dist/model.d.ts +9 -2
  74. package/dist/model.d.ts.map +1 -1
  75. package/dist/model.js +8 -2
  76. package/dist/name.d.ts +4 -0
  77. package/dist/name.d.ts.map +1 -0
  78. package/dist/name.js +122 -0
  79. package/dist/observation.d.ts +20 -2
  80. package/dist/observation.d.ts.map +1 -1
  81. package/dist/observation.js +113 -12
  82. package/dist/opened.d.ts +22 -0
  83. package/dist/opened.d.ts.map +1 -0
  84. package/dist/opened.js +107 -0
  85. package/dist/outcome.d.ts +45 -7
  86. package/dist/outcome.d.ts.map +1 -1
  87. package/dist/outcome.js +39 -0
  88. package/dist/overlay.d.ts +3 -4
  89. package/dist/overlay.d.ts.map +1 -1
  90. package/dist/overlay.js +100 -182
  91. package/dist/paths.d.ts +1 -0
  92. package/dist/paths.d.ts.map +1 -1
  93. package/dist/paths.js +4 -0
  94. package/dist/query.d.ts +66 -4
  95. package/dist/query.d.ts.map +1 -1
  96. package/dist/query.js +48 -7
  97. package/dist/reach.d.ts +18 -6
  98. package/dist/reach.d.ts.map +1 -1
  99. package/dist/reach.js +220 -73
  100. package/dist/react.d.ts +8 -6
  101. package/dist/react.d.ts.map +1 -1
  102. package/dist/react.js +7 -17
  103. package/dist/readiness.d.ts +52 -0
  104. package/dist/readiness.d.ts.map +1 -0
  105. package/dist/readiness.js +27 -0
  106. package/dist/recovery.d.ts +26 -0
  107. package/dist/recovery.d.ts.map +1 -0
  108. package/dist/recovery.js +224 -0
  109. package/dist/refresh.d.ts +16 -14
  110. package/dist/refresh.d.ts.map +1 -1
  111. package/dist/refresh.js +115 -51
  112. package/dist/replica.d.ts +55 -33
  113. package/dist/replica.d.ts.map +1 -1
  114. package/dist/replica.js +297 -154
  115. package/dist/room-draft.d.ts +34 -4
  116. package/dist/room-draft.d.ts.map +1 -1
  117. package/dist/room-draft.js +105 -31
  118. package/dist/rows.d.ts +37 -37
  119. package/dist/rows.d.ts.map +1 -1
  120. package/dist/rows.js +173 -104
  121. package/dist/save.d.ts +53 -9
  122. package/dist/save.d.ts.map +1 -1
  123. package/dist/save.js +537 -170
  124. package/dist/search.d.ts +39 -28
  125. package/dist/search.d.ts.map +1 -1
  126. package/dist/search.js +37 -105
  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 +15 -0
  131. package/dist/shared.d.ts.map +1 -0
  132. package/dist/shared.js +421 -0
  133. package/dist/status.d.ts +5 -0
  134. package/dist/status.d.ts.map +1 -1
  135. package/dist/status.js +3 -1
  136. package/dist/store.d.ts +96 -80
  137. package/dist/store.d.ts.map +1 -1
  138. package/dist/store.js +306 -523
  139. package/dist/stored.d.ts +130 -0
  140. package/dist/stored.d.ts.map +1 -0
  141. package/dist/stored.js +560 -0
  142. package/dist/tables.d.ts +325 -0
  143. package/dist/tables.d.ts.map +1 -0
  144. package/dist/tables.js +578 -0
  145. package/dist/transfer.d.ts +0 -5
  146. package/dist/transfer.d.ts.map +1 -1
  147. package/dist/turn.d.ts +9 -0
  148. package/dist/turn.d.ts.map +1 -0
  149. package/dist/turn.js +75 -0
  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 +164 -32
  157. package/dist/wire.d.ts.map +1 -1
  158. package/dist/wire.js +55 -31
  159. package/dist/words.d.ts +19 -0
  160. package/dist/words.d.ts.map +1 -0
  161. package/dist/words.js +156 -0
  162. package/package.json +18 -19
  163. package/AGENTS.md +0 -299
  164. package/dist/chat/acts.d.ts +0 -33
  165. package/dist/chat/acts.d.ts.map +0 -1
  166. package/dist/chat/acts.js +0 -36
  167. package/dist/chat/context.d.ts +0 -3
  168. package/dist/chat/context.d.ts.map +0 -1
  169. package/dist/chat/context.js +0 -10
  170. package/dist/chat/input.d.ts +0 -9
  171. package/dist/chat/input.d.ts.map +0 -1
  172. package/dist/chat/input.js +0 -99
  173. package/dist/chat/kit.d.ts +0 -60
  174. package/dist/chat/kit.d.ts.map +0 -1
  175. package/dist/chat/kit.js +0 -123
  176. package/dist/chat/lasting.d.ts +0 -6
  177. package/dist/chat/lasting.d.ts.map +0 -1
  178. package/dist/chat/lasting.js +0 -19
  179. package/dist/chat/list.d.ts +0 -26
  180. package/dist/chat/list.d.ts.map +0 -1
  181. package/dist/chat/list.js +0 -62
  182. package/dist/chat/markdown.d.ts +0 -20
  183. package/dist/chat/markdown.d.ts.map +0 -1
  184. package/dist/chat/markdown.js +0 -188
  185. package/dist/chat/message.d.ts +0 -6
  186. package/dist/chat/message.d.ts.map +0 -1
  187. package/dist/chat/message.js +0 -192
  188. package/dist/chat/messages.d.ts +0 -21
  189. package/dist/chat/messages.d.ts.map +0 -1
  190. package/dist/chat/messages.js +0 -151
  191. package/dist/chat/name.d.ts +0 -6
  192. package/dist/chat/name.d.ts.map +0 -1
  193. package/dist/chat/name.js +0 -37
  194. package/dist/chat/opened.d.ts +0 -11
  195. package/dist/chat/opened.d.ts.map +0 -1
  196. package/dist/chat/opened.js +0 -17
  197. package/dist/chat/overlay.d.ts +0 -31
  198. package/dist/chat/overlay.d.ts.map +0 -1
  199. package/dist/chat/overlay.js +0 -97
  200. package/dist/chat/parts.d.ts +0 -57
  201. package/dist/chat/parts.d.ts.map +0 -1
  202. package/dist/chat/parts.js +0 -119
  203. package/dist/chat/process.d.ts +0 -20
  204. package/dist/chat/process.d.ts.map +0 -1
  205. package/dist/chat/process.js +0 -32
  206. package/dist/chat/provider.d.ts +0 -63
  207. package/dist/chat/provider.d.ts.map +0 -1
  208. package/dist/chat/provider.js +0 -620
  209. package/dist/chat/question.d.ts +0 -9
  210. package/dist/chat/question.d.ts.map +0 -1
  211. package/dist/chat/question.js +0 -80
  212. package/dist/chat/questions.d.ts +0 -31
  213. package/dist/chat/questions.d.ts.map +0 -1
  214. package/dist/chat/questions.js +0 -111
  215. package/dist/chat/read.d.ts +0 -5
  216. package/dist/chat/read.d.ts.map +0 -1
  217. package/dist/chat/read.js +0 -13
  218. package/dist/chat/ready.d.ts +0 -33
  219. package/dist/chat/ready.d.ts.map +0 -1
  220. package/dist/chat/ready.js +0 -91
  221. package/dist/chat/style.d.ts +0 -4
  222. package/dist/chat/style.d.ts.map +0 -1
  223. package/dist/chat/style.js +0 -302
  224. package/dist/chat.d.ts +0 -14
  225. package/dist/chat.d.ts.map +0 -1
  226. package/dist/chat.js +0 -8
  227. package/dist/read-side.d.ts +0 -18
  228. package/dist/read-side.d.ts.map +0 -1
  229. package/dist/read-side.js +0 -440
@@ -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 QueryResult } from './query.js';
1
+ import type { VerifiedModel } from '@agentshouse/mdmodel';
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';
@@ -11,7 +14,7 @@ export declare function boundQuery(template: unknown, args: EntryArguments): unk
11
14
  export declare function entryParameters(template: unknown): readonly string[];
12
15
  export declare function entryRefusal(template: unknown): string | null;
13
16
  export type EntryScope = {
14
- results(queries: Readonly<Record<string, unknown>>): Promise<Record<string, QueryResult>>;
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,WAAW,EAEjB,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,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7C,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,WAAW,CAAC,CAAC,CAAC;CAC3F,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,UAAU,CAqDlE"}
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D,OAAO,EAML,KAAK,SAAS,EAEf,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,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,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,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,CAmDZ"}
package/dist/entry.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { attachedModel } from './attached-model.js';
2
- import { collectionOf, passingDocument } 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,41 @@ 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, passingDocument(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
+ binary: null,
133
+ revision: room.revisions?.[path] ?? null,
134
+ fileId: null,
135
+ change: null,
136
+ written: null,
137
+ })));
138
+ return { locator: room.locator, key };
145
139
  });
146
140
  const planned = { listed: true, rooms: held };
147
141
  return {
148
142
  async results(queries) {
149
143
  const results = {};
150
144
  for (const [name, query] of Object.entries(queries)) {
151
- results[name] = await readSide.query(planOf(query, planned));
145
+ const plan = planOf(query, planned);
146
+ results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
152
147
  }
153
148
  return results;
154
149
  },
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
  }
@@ -0,0 +1,27 @@
1
+ import { type QueryRoom } from './compile.js';
2
+ import type { Plan } from './query.js';
3
+ import type { HitCursor, SearchWindow } from './search.js';
4
+ import type { Connection } from './tables.js';
5
+ export declare const SEARCH_TABLES: readonly string[];
6
+ export type SearchAsk = {
7
+ readonly text: string;
8
+ readonly limit: number;
9
+ readonly after: readonly [HitCursor, HitCursor] | null;
10
+ readonly total: boolean;
11
+ readonly documents: {
12
+ readonly plan: Plan;
13
+ readonly rooms: readonly QueryRoom[];
14
+ readonly beneath: readonly {
15
+ readonly key: number;
16
+ readonly roots: readonly string[];
17
+ }[];
18
+ } | null;
19
+ readonly conversations: readonly string[];
20
+ };
21
+ export declare function indexDocument(connection: Connection, id: number, path: string, content: string): void;
22
+ export declare function indexMessage(connection: Connection, id: number, text: string): void;
23
+ export declare function unindexDocuments(connection: Connection, ids: Iterable<number>): void;
24
+ export declare function unindexMessages(connection: Connection, ids: Iterable<number>): void;
25
+ export declare function unindexAll(connection: Connection): void;
26
+ export declare function searched(connection: Connection, ask: SearchAsk): SearchWindow;
27
+ //# sourceMappingURL=fulltext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fulltext.d.ts","sourceRoot":"","sources":["../src/fulltext.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAGV,SAAS,EAET,YAAY,EAEb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,aAAa,CAAC;AAoBrD,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAG1C,CAAC;AAsCF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;QACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,OAAO,EAAE,SAAS;YAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;SAAE,EAAE,CAAC;KAC1F,GAAG,IAAI,CAAC;IACT,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AA2CF,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,IAAI,CAgBN;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAOnF;AAWD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAEpF;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAEnF;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAIvD;AAkTD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,GAAG,YAAY,CAsB7E"}