@agentshouse/mdruntime 0.1.0-cacb4c3f6734e → 0.1.0-cae97ad2e9142

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 (179) hide show
  1. package/README.md +23 -10
  2. package/dist/adapter.d.ts +126 -30
  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 +36 -6
  7. package/dist/attempt.d.ts +16 -0
  8. package/dist/attempt.d.ts.map +1 -0
  9. package/dist/attempt.js +70 -0
  10. package/dist/binary.d.ts +18 -0
  11. package/dist/binary.d.ts.map +1 -0
  12. package/dist/binary.js +8 -0
  13. package/dist/bootstrap.d.ts +40 -6
  14. package/dist/bootstrap.d.ts.map +1 -1
  15. package/dist/bootstrap.js +186 -45
  16. package/dist/chain.d.ts +11 -0
  17. package/dist/chain.d.ts.map +1 -0
  18. package/dist/chain.js +64 -0
  19. package/dist/change-set.d.ts +9 -14
  20. package/dist/change-set.d.ts.map +1 -1
  21. package/dist/change-set.js +11 -56
  22. package/dist/change.d.ts +45 -0
  23. package/dist/change.d.ts.map +1 -1
  24. package/dist/change.js +34 -0
  25. package/dist/client.d.ts +35 -14
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +107 -17
  28. package/dist/collection.d.ts +9 -13
  29. package/dist/collection.d.ts.map +1 -1
  30. package/dist/collection.js +46 -56
  31. package/dist/compile.d.ts +16 -0
  32. package/dist/compile.d.ts.map +1 -0
  33. package/dist/compile.js +767 -0
  34. package/dist/connection.d.ts +58 -19
  35. package/dist/connection.d.ts.map +1 -1
  36. package/dist/connection.js +3659 -726
  37. package/dist/conversation.d.ts +41 -12
  38. package/dist/conversation.d.ts.map +1 -1
  39. package/dist/conversation.js +588 -180
  40. package/dist/digest.d.ts +7 -0
  41. package/dist/digest.d.ts.map +1 -0
  42. package/dist/digest.js +113 -0
  43. package/dist/durability.d.ts +5 -1
  44. package/dist/durability.d.ts.map +1 -1
  45. package/dist/durability.js +5 -0
  46. package/dist/entry.d.ts +19 -0
  47. package/dist/entry.d.ts.map +1 -0
  48. package/dist/entry.js +151 -0
  49. package/dist/expectation.d.ts +21 -0
  50. package/dist/expectation.d.ts.map +1 -0
  51. package/dist/expectation.js +70 -0
  52. package/dist/failure.d.ts +13 -0
  53. package/dist/failure.d.ts.map +1 -0
  54. package/dist/failure.js +19 -0
  55. package/dist/fence.d.ts +6 -0
  56. package/dist/fence.d.ts.map +1 -0
  57. package/dist/fence.js +10 -0
  58. package/dist/file.d.ts +2 -10
  59. package/dist/file.d.ts.map +1 -1
  60. package/dist/file.js +3 -120
  61. package/dist/fulltext.d.ts +27 -0
  62. package/dist/fulltext.d.ts.map +1 -0
  63. package/dist/fulltext.js +368 -0
  64. package/dist/host.d.ts +15 -2
  65. package/dist/host.d.ts.map +1 -1
  66. package/dist/host.js +132 -21
  67. package/dist/identity.d.ts +4 -0
  68. package/dist/identity.d.ts.map +1 -1
  69. package/dist/identity.js +16 -1
  70. package/dist/index.d.ts +20 -9
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +8 -0
  73. package/dist/live.d.ts +22 -0
  74. package/dist/live.d.ts.map +1 -0
  75. package/dist/live.js +124 -0
  76. package/dist/memory.d.ts +13 -5
  77. package/dist/memory.d.ts.map +1 -1
  78. package/dist/memory.js +99 -31
  79. package/dist/messages.d.ts +28 -0
  80. package/dist/messages.d.ts.map +1 -0
  81. package/dist/messages.js +90 -0
  82. package/dist/model.d.ts +14 -4
  83. package/dist/model.d.ts.map +1 -1
  84. package/dist/model.js +13 -2
  85. package/dist/name.d.ts +4 -0
  86. package/dist/name.d.ts.map +1 -0
  87. package/dist/name.js +122 -0
  88. package/dist/observation.d.ts +19 -2
  89. package/dist/observation.d.ts.map +1 -1
  90. package/dist/observation.js +113 -12
  91. package/dist/open.d.ts +2 -0
  92. package/dist/open.d.ts.map +1 -0
  93. package/dist/open.js +1 -0
  94. package/dist/opened.d.ts +22 -0
  95. package/dist/opened.d.ts.map +1 -0
  96. package/dist/opened.js +107 -0
  97. package/dist/outcome.d.ts +62 -3
  98. package/dist/outcome.d.ts.map +1 -1
  99. package/dist/outcome.js +67 -1
  100. package/dist/overlay.d.ts +15 -5
  101. package/dist/overlay.d.ts.map +1 -1
  102. package/dist/overlay.js +136 -180
  103. package/dist/query.d.ts +70 -4
  104. package/dist/query.d.ts.map +1 -1
  105. package/dist/query.js +53 -38
  106. package/dist/reach.d.ts +17 -4
  107. package/dist/reach.d.ts.map +1 -1
  108. package/dist/reach.js +226 -65
  109. package/dist/react.d.ts +31 -20
  110. package/dist/react.d.ts.map +1 -1
  111. package/dist/react.js +13 -21
  112. package/dist/readiness.d.ts +64 -0
  113. package/dist/readiness.d.ts.map +1 -0
  114. package/dist/readiness.js +33 -0
  115. package/dist/reads.d.ts +11 -0
  116. package/dist/reads.d.ts.map +1 -0
  117. package/dist/reads.js +100 -0
  118. package/dist/recovery.d.ts +25 -0
  119. package/dist/recovery.d.ts.map +1 -0
  120. package/dist/recovery.js +198 -0
  121. package/dist/refresh.d.ts +19 -8
  122. package/dist/refresh.d.ts.map +1 -1
  123. package/dist/refresh.js +125 -57
  124. package/dist/replica.d.ts +59 -33
  125. package/dist/replica.d.ts.map +1 -1
  126. package/dist/replica.js +321 -155
  127. package/dist/room-draft.d.ts +41 -9
  128. package/dist/room-draft.d.ts.map +1 -1
  129. package/dist/room-draft.js +186 -37
  130. package/dist/rows.d.ts +37 -35
  131. package/dist/rows.d.ts.map +1 -1
  132. package/dist/rows.js +168 -100
  133. package/dist/save.d.ts +71 -4
  134. package/dist/save.d.ts.map +1 -1
  135. package/dist/save.js +815 -146
  136. package/dist/search.d.ts +41 -29
  137. package/dist/search.d.ts.map +1 -1
  138. package/dist/search.js +37 -105
  139. package/dist/seed.d.ts +16 -0
  140. package/dist/seed.d.ts.map +1 -0
  141. package/dist/seed.js +75 -0
  142. package/dist/shared.d.ts +16 -0
  143. package/dist/shared.d.ts.map +1 -0
  144. package/dist/shared.js +431 -0
  145. package/dist/status.d.ts +6 -2
  146. package/dist/status.d.ts.map +1 -1
  147. package/dist/status.js +0 -8
  148. package/dist/store.d.ts +124 -58
  149. package/dist/store.d.ts.map +1 -1
  150. package/dist/store.js +362 -344
  151. package/dist/stored.d.ts +150 -0
  152. package/dist/stored.d.ts.map +1 -0
  153. package/dist/stored.js +564 -0
  154. package/dist/tables.d.ts +354 -0
  155. package/dist/tables.d.ts.map +1 -0
  156. package/dist/tables.js +624 -0
  157. package/dist/turn.d.ts +9 -0
  158. package/dist/turn.d.ts.map +1 -0
  159. package/dist/turn.js +75 -0
  160. package/dist/validation.d.ts +30 -0
  161. package/dist/validation.d.ts.map +1 -0
  162. package/dist/validation.js +162 -0
  163. package/dist/windows.d.ts +22 -0
  164. package/dist/windows.d.ts.map +1 -0
  165. package/dist/windows.js +89 -0
  166. package/dist/wire.d.ts +169 -33
  167. package/dist/wire.d.ts.map +1 -1
  168. package/dist/wire.js +68 -31
  169. package/dist/words.d.ts +19 -0
  170. package/dist/words.d.ts.map +1 -0
  171. package/dist/words.js +150 -0
  172. package/package.json +26 -15
  173. package/AGENTS.md +0 -244
  174. package/dist/attachment.d.ts +0 -3
  175. package/dist/attachment.d.ts.map +0 -1
  176. package/dist/attachment.js +0 -8
  177. package/dist/read-side.d.ts +0 -18
  178. package/dist/read-side.d.ts.map +0 -1
  179. package/dist/read-side.js +0 -433
@@ -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,13 @@
1
+ import type { Persistence } from './readiness.js';
1
2
  export type RuntimeShell = {
2
- persistentStorage: boolean;
3
+ persistence: Persistence;
3
4
  generation: string | null;
5
+ onScreen: boolean;
4
6
  keepGeneration(value: string): void | Promise<void>;
5
7
  dropGeneration(): void | Promise<void>;
8
+ cleanUp?(): Promise<number>;
6
9
  };
10
+ export declare function refusedForSpace(error: unknown): boolean;
7
11
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
8
12
  export declare function nextGeneration(stored: string | null, reported: string | null): string;
9
13
  //# 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,QAAQ,EAAE,OAAO,CAAC;IAClB,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;
@@ -0,0 +1,19 @@
1
+ import type { VerifiedModel } from '@agentshouse/mdmodel';
2
+ import { type QueryRows } from './query.js';
3
+ import type { Connection } from './tables.js';
4
+ export { QueryError } from './query.js';
5
+ export type EntryRoom = {
6
+ locator: string;
7
+ schema: string | null;
8
+ documents: Readonly<Record<string, string>>;
9
+ };
10
+ export type EntryArguments = Readonly<Record<string, string>>;
11
+ export type EntryParameterKind = 'string' | 'integer' | 'number' | 'boolean';
12
+ export declare function boundQuery(template: unknown, args: EntryArguments): unknown;
13
+ export declare function entryParameters(template: unknown): readonly string[];
14
+ export declare function entryRefusal(template: unknown): string | null;
15
+ export type EntryScope = {
16
+ results(queries: Readonly<Record<string, unknown>>): Promise<Record<string, QueryRows>>;
17
+ };
18
+ export declare function entryScope(rooms: readonly EntryRoom[], roomTypes: VerifiedModel, connection: Connection): EntryScope;
19
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
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;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,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 ADDED
@@ -0,0 +1,151 @@
1
+ import { attachedModel } from './attached-model.js';
2
+ import { answerQuery } from './compile.js';
3
+ import { NO_MODEL } from './model.js';
4
+ import { invalid, planOf, plain, QueryError, } from './query.js';
5
+ import { entered, REPLICA_TABLES } from './stored.js';
6
+ export { QueryError } from './query.js';
7
+ const PARAMETER = '$param';
8
+ const KIND = 'as';
9
+ const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
10
+ const NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/u;
11
+ function parameterOf(value) {
12
+ if (!plain(value) || !Object.hasOwn(value, PARAMETER))
13
+ return null;
14
+ const { [PARAMETER]: name, [KIND]: kind = 'string', ...rest } = value;
15
+ if (typeof name !== 'string' || Object.keys(rest).length > 0)
16
+ return null;
17
+ if (kind !== 'string' && kind !== 'integer' && kind !== 'number' && kind !== 'boolean') {
18
+ return null;
19
+ }
20
+ return { name, kind };
21
+ }
22
+ function converted(text, kind, at) {
23
+ if (kind === 'string')
24
+ return text;
25
+ if (kind === 'boolean') {
26
+ if (text === 'true' || text === 'false')
27
+ return text === 'true';
28
+ return invalid(at, 'expects true or false');
29
+ }
30
+ if (!(kind === 'integer' ? INTEGER : NUMBER).test(text))
31
+ invalid(at, `expects ${kind === 'integer' ? 'an integer' : 'a number'}`);
32
+ const number = Number(text);
33
+ if (!Number.isFinite(number) || (kind === 'integer' && !Number.isSafeInteger(number))) {
34
+ invalid(at, 'is out of range');
35
+ }
36
+ return number;
37
+ }
38
+ function bound(template, args, at) {
39
+ const parameter = parameterOf(template);
40
+ if (parameter !== null) {
41
+ const text = args[parameter.name];
42
+ if (text === undefined || !Object.hasOwn(args, parameter.name)) {
43
+ invalid(at, `names the parameter ${parameter.name}, which the route lacks`);
44
+ }
45
+ return converted(text, parameter.kind, at);
46
+ }
47
+ if (Array.isArray(template)) {
48
+ return template.map((item, index) => bound(item, args, `${at}[${index}]`));
49
+ }
50
+ if (plain(template)) {
51
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [
52
+ name,
53
+ bound(value, args, at === '' ? name : `${at}.${name}`),
54
+ ]));
55
+ }
56
+ return template;
57
+ }
58
+ export function boundQuery(template, args) {
59
+ return bound(template, args, '');
60
+ }
61
+ export function entryParameters(template) {
62
+ const parameter = parameterOf(template);
63
+ if (parameter !== null)
64
+ return [parameter.name];
65
+ if (Array.isArray(template))
66
+ return [...new Set(template.flatMap(entryParameters))];
67
+ if (plain(template))
68
+ return [...new Set(Object.values(template).flatMap(entryParameters))];
69
+ return [];
70
+ }
71
+ const SAMPLED = {
72
+ direction: 'asc',
73
+ nulls: 'last',
74
+ stringSort: 'lexical',
75
+ locale: 'en',
76
+ limit: 0,
77
+ pathPrefix: 'entry',
78
+ field: '/entry',
79
+ fields: '/entry',
80
+ types: 'any',
81
+ $in: 'entry',
82
+ $nin: 'entry',
83
+ $all: 'entry',
84
+ $size: 0,
85
+ $exists: true,
86
+ $gt: 0,
87
+ $gte: 0,
88
+ $lt: 0,
89
+ $lte: 0,
90
+ };
91
+ function sampled(template, key) {
92
+ if (parameterOf(template) !== null)
93
+ return Object.hasOwn(SAMPLED, key) ? SAMPLED[key] : null;
94
+ if (Array.isArray(template))
95
+ return template.map((item) => sampled(item, key));
96
+ if (plain(template)) {
97
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [name, sampled(value, name)]));
98
+ }
99
+ return template;
100
+ }
101
+ export function entryRefusal(template) {
102
+ try {
103
+ planOf(sampled(template, ''), { listed: false, rooms: [] });
104
+ return null;
105
+ }
106
+ catch (error) {
107
+ if (error instanceof QueryError)
108
+ return error.message;
109
+ throw error;
110
+ }
111
+ }
112
+ export function entryScope(rooms, roomTypes, connection) {
113
+ for (const table of REPLICA_TABLES)
114
+ connection.run(table);
115
+ const held = [];
116
+ const keys = rooms.map((room) => {
117
+ const model = attachedModel({
118
+ kind: 'model',
119
+ snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
120
+ }, NO_MODEL, roomTypes).state;
121
+ held.push({
122
+ locator: room.locator,
123
+ available: model.status !== 'unavailable',
124
+ types: model.status === 'unavailable' ? [] : Object.values(model.types),
125
+ });
126
+ const composition = { model, selection: null };
127
+ const key = entered(connection, room.locator, composition, Object.keys(room.documents)
128
+ .sort()
129
+ .map((path) => ({
130
+ path,
131
+ content: room.documents[path],
132
+ binary: null,
133
+ revision: null,
134
+ fileId: null,
135
+ change: null,
136
+ written: null,
137
+ })));
138
+ return { locator: room.locator, key };
139
+ });
140
+ const planned = { listed: true, rooms: held };
141
+ return {
142
+ async results(queries) {
143
+ const results = {};
144
+ for (const [name, query] of Object.entries(queries)) {
145
+ const plan = planOf(query, planned);
146
+ results[name] = answerQuery(connection, plan, keys.filter(({ locator }) => plan.rooms === null || plan.rooms.includes(locator)));
147
+ }
148
+ return results;
149
+ },
150
+ };
151
+ }
@@ -0,0 +1,21 @@
1
+ export type ExpectedOf<E extends {
2
+ readonly key: string;
3
+ }> = E | readonly E[] | null;
4
+ export type Expecting<E extends {
5
+ readonly key: string;
6
+ }> = {
7
+ subscribe(listener: () => void): () => void;
8
+ version(): number;
9
+ begin(): number;
10
+ expect(act: number, expected: ExpectedOf<E>, settled?: (one: E) => boolean): void;
11
+ drop(act: number): void;
12
+ heard(shown: (one: E) => boolean): void;
13
+ drawn(): readonly E[];
14
+ };
15
+ export declare function expectedList<E extends {
16
+ readonly key: string;
17
+ }>(expected: ExpectedOf<E>): readonly E[];
18
+ export declare function expecting<E extends {
19
+ readonly key: string;
20
+ }>(): Expecting<E>;
21
+ //# sourceMappingURL=expectation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expectation.d.ts","sourceRoot":"","sources":["../src/expectation.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC;AAErF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,IAAI;IAC1D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,OAAO,IAAI,MAAM,CAAC;IAClB,KAAK,IAAI,MAAM,CAAC;IAChB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IAClF,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,SAAS,CAAC,EAAE,CAAC;CACvB,CAAC;AAIF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC7D,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,GACtB,SAAS,CAAC,EAAE,CAGd;AAwBD,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,SAAS,CAAC,CAAC,CAAC,CA4C5E"}
@@ -0,0 +1,70 @@
1
+ export function expectedList(expected) {
2
+ if (expected === null)
3
+ return [];
4
+ return 'key' in expected ? [expected] : expected;
5
+ }
6
+ function superseded(entries, at) {
7
+ const key = entries[at]?.expectation.key;
8
+ return entries.slice(at + 1).some((later) => later.expectation.key === key);
9
+ }
10
+ function unended(entries, ends) {
11
+ const ended = new Set();
12
+ const kept = [];
13
+ for (const one of [...entries].reverse()) {
14
+ if (ended.has(one.expectation.key))
15
+ continue;
16
+ if (ends(one.expectation))
17
+ ended.add(one.expectation.key);
18
+ else
19
+ kept.unshift(one);
20
+ }
21
+ return kept;
22
+ }
23
+ export function expecting() {
24
+ let entries = [];
25
+ let version = 0;
26
+ let acts = 0;
27
+ const listeners = new Set();
28
+ const set = (next) => {
29
+ if (next.length === entries.length && next.every((one, at) => one === entries[at]))
30
+ return;
31
+ entries = next;
32
+ version += 1;
33
+ for (const listener of listeners)
34
+ listener();
35
+ };
36
+ return {
37
+ subscribe(listener) {
38
+ listeners.add(listener);
39
+ return () => {
40
+ listeners.delete(listener);
41
+ };
42
+ },
43
+ version: () => version,
44
+ begin() {
45
+ acts += 1;
46
+ return acts;
47
+ },
48
+ expect(act, expected, settled = () => false) {
49
+ const fresh = expectedList(expected);
50
+ if (fresh.length === 0)
51
+ return;
52
+ const keys = new Set(fresh.map((one) => one.key));
53
+ const kept = entries.filter((one) => one.act !== act || !keys.has(one.expectation.key));
54
+ const over = new Set(kept.map((one) => one.expectation.key));
55
+ set([
56
+ ...kept,
57
+ ...fresh
58
+ .filter((one) => over.has(one.key) || !settled(one))
59
+ .map((expectation) => ({ act, expectation })),
60
+ ]);
61
+ },
62
+ drop(act) {
63
+ set(entries.filter((one) => one.act !== act));
64
+ },
65
+ heard(shown) {
66
+ set(unended(entries, shown));
67
+ },
68
+ drawn: () => entries.flatMap((one, at) => (superseded(entries, at) ? [] : [one.expectation])),
69
+ };
70
+ }
@@ -0,0 +1,13 @@
1
+ export type RuntimeError = Error & {
2
+ readonly code: string;
3
+ readonly retryable: boolean;
4
+ };
5
+ export type Described = {
6
+ message: string;
7
+ code: string;
8
+ retryable: boolean;
9
+ };
10
+ export declare function runtimeError(code: string, message?: string, retryable?: boolean): RuntimeError;
11
+ export declare function failed(error: unknown): RuntimeError;
12
+ export declare function described(error: unknown): Described;
13
+ //# sourceMappingURL=failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1F,MAAM,MAAM,SAAS,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAa,EACtB,SAAS,UAAQ,GAChB,YAAY,CAEd;AAYD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAGnD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAGnD"}
@@ -0,0 +1,19 @@
1
+ export function runtimeError(code, message = code, retryable = false) {
2
+ return Object.assign(new Error(message), { code, retryable });
3
+ }
4
+ function coded(error) {
5
+ return (error instanceof Error &&
6
+ 'code' in error &&
7
+ typeof error.code === 'string' &&
8
+ 'retryable' in error &&
9
+ typeof error.retryable === 'boolean');
10
+ }
11
+ export function failed(error) {
12
+ if (coded(error))
13
+ return error;
14
+ return runtimeError('runtime-failure', error instanceof Error ? error.message : String(error));
15
+ }
16
+ export function described(error) {
17
+ const { message, code, retryable } = failed(error);
18
+ return { message, code, retryable };
19
+ }
@@ -0,0 +1,6 @@
1
+ export declare class FencedMap<V> extends Map<string, V> {
2
+ #private;
3
+ constructor(fenced: (locator: string) => boolean);
4
+ set(locator: string, value: V): this;
5
+ }
6
+ //# sourceMappingURL=fence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../src/fence.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;;IAG9C,YAAY,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,EAG/C;IAEQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAE5C;CACF"}
package/dist/fence.js ADDED
@@ -0,0 +1,10 @@
1
+ export class FencedMap extends Map {
2
+ #fenced;
3
+ constructor(fenced) {
4
+ super();
5
+ this.#fenced = fenced;
6
+ }
7
+ set(locator, value) {
8
+ return this.#fenced(locator) ? this : super.set(locator, value);
9
+ }
10
+ }
package/dist/file.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type ChatDraftFile = {
1
+ export type ChosenFile = {
2
2
  name: string;
3
3
  blob: Blob;
4
4
  };
@@ -7,14 +7,6 @@ export type FileDeclaration = {
7
7
  mediaType: string;
8
8
  byteLength: number;
9
9
  contentHash: string;
10
- width?: number;
11
- height?: number;
12
10
  };
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>;
11
+ export declare function declaredFile(file: ChosenFile): Promise<FileDeclaration>;
20
12
  //# 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":"AAEA,MAAM,MAAM,UAAU,GAAG;IACvB,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;CACrB,CAAC;AAEF,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,CAO7E"}
package/dist/file.js CHANGED
@@ -1,126 +1,9 @@
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
- }
1
+ import { sha256 } from './digest.js';
116
2
  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;
119
3
  return {
120
4
  name: file.name,
121
5
  mediaType: file.blob.type,
122
- byteLength: bytes.byteLength,
123
- contentHash: hexDigest(await crypto.subtle.digest('SHA-256', bytes)),
124
- ...(extent === null ? {} : extent),
6
+ byteLength: file.blob.size,
7
+ contentHash: await sha256(file.blob),
125
8
  };
126
9
  }