@agentshouse/mdruntime 0.1.0-cec6690d5712e → 0.1.0-cedb03eaa48b6

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 (155) hide show
  1. package/AGENTS.md +277 -271
  2. package/README.md +8 -8
  3. package/dist/adapter.d.ts +85 -20
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/attempt.d.ts.map +1 -1
  6. package/dist/attempt.js +14 -1
  7. package/dist/binary.d.ts +23 -0
  8. package/dist/binary.d.ts.map +1 -0
  9. package/dist/binary.js +8 -0
  10. package/dist/bootstrap.d.ts +3 -2
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +37 -14
  13. package/dist/change-set.d.ts +2 -0
  14. package/dist/change-set.d.ts.map +1 -1
  15. package/dist/change-set.js +40 -13
  16. package/dist/change.d.ts +11 -0
  17. package/dist/change.d.ts.map +1 -1
  18. package/dist/change.js +26 -1
  19. package/dist/chat/acts.d.ts +3 -4
  20. package/dist/chat/acts.d.ts.map +1 -1
  21. package/dist/chat/acts.js +10 -10
  22. package/dist/chat/earlier.d.ts +10 -0
  23. package/dist/chat/earlier.d.ts.map +1 -0
  24. package/dist/chat/earlier.js +54 -0
  25. package/dist/chat/kit.d.ts +2 -1
  26. package/dist/chat/kit.d.ts.map +1 -1
  27. package/dist/chat/kit.js +3 -3
  28. package/dist/chat/list.d.ts +8 -1
  29. package/dist/chat/list.d.ts.map +1 -1
  30. package/dist/chat/list.js +48 -8
  31. package/dist/chat/markdown.d.ts +2 -1
  32. package/dist/chat/markdown.d.ts.map +1 -1
  33. package/dist/chat/markdown.js +7 -6
  34. package/dist/chat/message.d.ts.map +1 -1
  35. package/dist/chat/message.js +2 -2
  36. package/dist/chat/messages.d.ts +1 -0
  37. package/dist/chat/messages.d.ts.map +1 -1
  38. package/dist/chat/messages.js +4 -0
  39. package/dist/chat/provider.d.ts +1 -1
  40. package/dist/chat/provider.d.ts.map +1 -1
  41. package/dist/chat/provider.js +62 -79
  42. package/dist/chat/question.d.ts +1 -1
  43. package/dist/chat/question.d.ts.map +1 -1
  44. package/dist/chat/question.js +7 -18
  45. package/dist/chat/ready.d.ts +1 -0
  46. package/dist/chat/ready.d.ts.map +1 -1
  47. package/dist/chat/ready.js +4 -4
  48. package/dist/chat/style.js +5 -5
  49. package/dist/client.d.ts +22 -9
  50. package/dist/client.d.ts.map +1 -1
  51. package/dist/client.js +23 -6
  52. package/dist/collection.d.ts +17 -3
  53. package/dist/collection.d.ts.map +1 -1
  54. package/dist/collection.js +260 -19
  55. package/dist/connection.d.ts +39 -12
  56. package/dist/connection.d.ts.map +1 -1
  57. package/dist/connection.js +1769 -385
  58. package/dist/conversation.d.ts +20 -7
  59. package/dist/conversation.d.ts.map +1 -1
  60. package/dist/conversation.js +474 -163
  61. package/dist/durability.d.ts +7 -1
  62. package/dist/durability.d.ts.map +1 -1
  63. package/dist/entry.d.ts +17 -0
  64. package/dist/entry.d.ts.map +1 -0
  65. package/dist/entry.js +157 -0
  66. package/dist/fence.d.ts +6 -0
  67. package/dist/fence.d.ts.map +1 -0
  68. package/dist/fence.js +10 -0
  69. package/dist/host.d.ts +15 -3
  70. package/dist/host.d.ts.map +1 -1
  71. package/dist/host.js +98 -12
  72. package/dist/identity.d.ts +3 -0
  73. package/dist/identity.d.ts.map +1 -1
  74. package/dist/identity.js +9 -0
  75. package/dist/index.d.ts +12 -7
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +3 -0
  78. package/dist/memory.d.ts +10 -4
  79. package/dist/memory.d.ts.map +1 -1
  80. package/dist/memory.js +64 -17
  81. package/dist/model.d.ts +4 -2
  82. package/dist/model.d.ts.map +1 -1
  83. package/dist/model.js +10 -1
  84. package/dist/observation.d.ts +7 -2
  85. package/dist/observation.d.ts.map +1 -1
  86. package/dist/observation.js +29 -12
  87. package/dist/outcome.d.ts +17 -1
  88. package/dist/outcome.d.ts.map +1 -1
  89. package/dist/outcome.js +10 -0
  90. package/dist/overlay.d.ts +15 -2
  91. package/dist/overlay.d.ts.map +1 -1
  92. package/dist/overlay.js +99 -62
  93. package/dist/query.d.ts +58 -4
  94. package/dist/query.d.ts.map +1 -1
  95. package/dist/query.js +36 -7
  96. package/dist/reach.d.ts +8 -3
  97. package/dist/reach.d.ts.map +1 -1
  98. package/dist/reach.js +53 -6
  99. package/dist/react.d.ts +8 -6
  100. package/dist/react.d.ts.map +1 -1
  101. package/dist/react.js +7 -17
  102. package/dist/read-side.d.ts +16 -7
  103. package/dist/read-side.d.ts.map +1 -1
  104. package/dist/read-side.js +493 -102
  105. package/dist/readiness.d.ts +53 -0
  106. package/dist/readiness.d.ts.map +1 -0
  107. package/dist/readiness.js +33 -0
  108. package/dist/reads.d.ts +11 -0
  109. package/dist/reads.d.ts.map +1 -0
  110. package/dist/reads.js +98 -0
  111. package/dist/recovery.d.ts +25 -0
  112. package/dist/recovery.d.ts.map +1 -0
  113. package/dist/recovery.js +197 -0
  114. package/dist/refresh.d.ts +4 -4
  115. package/dist/refresh.d.ts.map +1 -1
  116. package/dist/refresh.js +27 -25
  117. package/dist/replica.d.ts +11 -4
  118. package/dist/replica.d.ts.map +1 -1
  119. package/dist/replica.js +106 -48
  120. package/dist/room-draft.d.ts +32 -3
  121. package/dist/room-draft.d.ts.map +1 -1
  122. package/dist/room-draft.js +121 -3
  123. package/dist/rows.d.ts +8 -13
  124. package/dist/rows.d.ts.map +1 -1
  125. package/dist/rows.js +12 -13
  126. package/dist/save.d.ts +29 -0
  127. package/dist/save.d.ts.map +1 -1
  128. package/dist/save.js +358 -30
  129. package/dist/search.d.ts +49 -6
  130. package/dist/search.d.ts.map +1 -1
  131. package/dist/search.js +192 -47
  132. package/dist/seed.d.ts +16 -0
  133. package/dist/seed.d.ts.map +1 -0
  134. package/dist/seed.js +75 -0
  135. package/dist/shared.d.ts +11 -0
  136. package/dist/shared.d.ts.map +1 -0
  137. package/dist/shared.js +368 -0
  138. package/dist/status.d.ts +4 -0
  139. package/dist/status.d.ts.map +1 -1
  140. package/dist/store.d.ts +68 -21
  141. package/dist/store.d.ts.map +1 -1
  142. package/dist/store.js +463 -206
  143. package/dist/turn.d.ts +7 -0
  144. package/dist/turn.d.ts.map +1 -0
  145. package/dist/turn.js +51 -0
  146. package/dist/windows.d.ts +26 -0
  147. package/dist/windows.d.ts.map +1 -0
  148. package/dist/windows.js +93 -0
  149. package/dist/wire.d.ts +152 -30
  150. package/dist/wire.d.ts.map +1 -1
  151. package/dist/wire.js +52 -29
  152. package/package.json +12 -8
  153. package/dist/attachment.d.ts +0 -3
  154. package/dist/attachment.d.ts.map +0 -1
  155. package/dist/attachment.js +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAkC,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,UAAU,GAA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';
2
- import { invalid, known, limitOf, plain } from './query.js';
2
+ import { indexGeneration } from './identity.js';
3
+ import { flag, invalid, known, limitOf, plain, } from './query.js';
4
+ import { beneath } from './paths.js';
5
+ import { inUnits, ROW_WEIGHT } from './turn.js';
6
+ import { decodedCursor } from './windows.js';
7
+ export function undeclaredSearch() {
8
+ return {
9
+ kind: 'undeclared',
10
+ code: 'search-undeclared',
11
+ fields: { name: 'local_search' },
12
+ retryable: false,
13
+ };
14
+ }
3
15
  const FIELDS = ['fields', 'sections', 'preamble', 'path', 'text'];
4
16
  function documentId(room, path) {
5
17
  return JSON.stringify(['document', room, path]);
@@ -16,10 +28,36 @@ function scalars(value) {
16
28
  return Object.values(value).flatMap(scalars);
17
29
  return [String(value)];
18
30
  }
31
+ function hitCursor(input) {
32
+ if (input === null)
33
+ return null;
34
+ if (!Array.isArray(input))
35
+ return undefined;
36
+ if (input.length === 0)
37
+ return [];
38
+ const [score, first, second] = input;
39
+ return input.length === 3 &&
40
+ typeof score === 'number' &&
41
+ typeof first === 'string' &&
42
+ typeof second === 'string'
43
+ ? [score, first, second]
44
+ : undefined;
45
+ }
46
+ function searchAfter(input) {
47
+ if (input === undefined)
48
+ return null;
49
+ const decoded = typeof input === 'string' ? decodedCursor(input) : null;
50
+ const documents = decoded?.length === 2 ? hitCursor(decoded[0]) : undefined;
51
+ const messages = decoded?.length === 2 ? hitCursor(decoded[1]) : undefined;
52
+ if (documents === undefined || messages === undefined) {
53
+ invalid('after', 'expects the next an earlier search returned');
54
+ }
55
+ return [documents, messages];
56
+ }
19
57
  export function searchPlanOf(input) {
20
58
  if (!plain(input))
21
59
  invalid('search', 'expects a search object');
22
- known(input, ['text', 'documents', 'conversations', 'limit'], '');
60
+ known(input, ['text', 'documents', 'collection', 'conversations', 'limit', 'after', 'total'], '');
23
61
  if (typeof input.text !== 'string')
24
62
  invalid('text', 'expects text');
25
63
  const conversations = input.conversations;
@@ -30,20 +68,49 @@ export function searchPlanOf(input) {
30
68
  return {
31
69
  text: input.text,
32
70
  documents: input.documents,
71
+ collection: flag(input.collection, 'collection'),
33
72
  conversations: conversations ?? null,
34
73
  limit: limitOf(input.limit),
74
+ after: searchAfter(input.after),
75
+ total: flag(input.total, 'total'),
35
76
  };
36
77
  }
78
+ function pair(left, right) {
79
+ if (left[0] !== right[0])
80
+ return left[0] < right[0] ? -1 : 1;
81
+ if (left[1] !== right[1])
82
+ return left[1] < right[1] ? -1 : 1;
83
+ return 0;
84
+ }
85
+ function hitWindow(found, cursor, limit, tie) {
86
+ if (cursor === null)
87
+ return { kept: [], cursor: null };
88
+ const start = cursor.length === 0
89
+ ? 0
90
+ : found.findIndex((hit) => hit.score < cursor[0] ||
91
+ (hit.score === cursor[0] && pair(tie(hit), [cursor[1], cursor[2]]) > 0));
92
+ const following = start === -1 ? [] : found.slice(start);
93
+ if (limit === null || following.length <= limit)
94
+ return { kept: following, cursor: null };
95
+ const kept = following.slice(0, limit);
96
+ const last = kept[kept.length - 1];
97
+ return { kept, cursor: last === undefined ? cursor : [last.score, ...tie(last)] };
98
+ }
37
99
  export function createSearchIndex(source) {
38
- let index = null;
100
+ const generation = indexGeneration();
101
+ const index = new MiniSearch({ fields: FIELDS });
39
102
  const documents = new Map();
40
103
  const messages = new Map();
104
+ const rooms = new Set();
105
+ const filling = new Set();
106
+ const conversations = new Set();
107
+ const acquiring = new Set();
41
108
  const changedDocuments = new Map();
42
- const changedMessages = new Map();
43
- function addDocument(built, document) {
109
+ let changes = 0;
110
+ function addDocument(document) {
44
111
  const id = documentId(document.room, document.path);
45
- documents.set(id, { room: document.room, path: document.path, type: document.type });
46
- built.add({
112
+ discard(id, documents);
113
+ index.add({
47
114
  id,
48
115
  fields: scalars(document.fields).join('\n'),
49
116
  sections: Object.entries(document.sections)
@@ -52,73 +119,151 @@ export function createSearchIndex(source) {
52
119
  preamble: document.preamble,
53
120
  path: document.path,
54
121
  });
122
+ documents.set(id, { room: document.room, path: document.path, type: document.type });
55
123
  }
56
- function addMessage(built, message) {
124
+ function addMessage(message) {
57
125
  const id = messageId(message.conversation, message.identity);
126
+ discard(id, messages);
127
+ index.add({ id, text: message.text });
58
128
  messages.set(id, { conversation: message.conversation, identity: message.identity });
59
- built.add({ id, text: message.text });
60
129
  }
61
- function current() {
62
- if (index === null) {
63
- const built = new MiniSearch({ fields: FIELDS });
64
- for (const document of source.documents())
65
- addDocument(built, document);
66
- for (const message of source.messages())
67
- addMessage(built, message);
68
- index = built;
69
- return built;
130
+ function discard(id, entries) {
131
+ if (entries.delete(id))
132
+ index.discard(id);
133
+ }
134
+ function* pending() {
135
+ for (;;) {
136
+ const next = changedDocuments.entries().next();
137
+ if (next.done === true)
138
+ return;
139
+ changedDocuments.delete(next.value[0]);
140
+ yield next.value;
70
141
  }
71
- const built = index;
72
- for (const [id, { room, path }] of changedDocuments) {
73
- if (documents.delete(id))
74
- built.discard(id);
142
+ }
143
+ let catching = null;
144
+ function caughtUp() {
145
+ if (catching !== null)
146
+ return catching;
147
+ const running = inUnits(pending(), ([id, { room, path }]) => {
148
+ discard(id, documents);
75
149
  const document = source.document(room, path);
76
- if (document !== null)
77
- addDocument(built, document);
78
- }
79
- changedDocuments.clear();
80
- for (const [id, { conversation, identity }] of changedMessages) {
81
- if (messages.delete(id))
82
- built.discard(id);
83
- const message = source.message(conversation, identity);
84
- if (message !== null)
85
- addMessage(built, message);
86
- }
87
- changedMessages.clear();
88
- return built;
150
+ if (document === null)
151
+ return ROW_WEIGHT;
152
+ addDocument(document);
153
+ return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
154
+ });
155
+ if (!(running instanceof Promise))
156
+ return Promise.resolve();
157
+ catching = running.finally(() => {
158
+ catching = null;
159
+ });
160
+ return catching;
89
161
  }
90
- function ranked(built, text, entries, keep, limit) {
91
- const found = built.search(text, {
162
+ function ranked(text, entries, keep, tie) {
163
+ const found = index.search(text, {
92
164
  filter: ({ id }) => {
93
165
  const entry = entries.get(id);
94
166
  return entry !== undefined && keep(entry, id);
95
167
  },
96
168
  });
97
- return (limit === null ? found : found.slice(0, limit)).map(({ id, score, match }) => ({
169
+ found.sort((left, right) => right.score - left.score ||
170
+ pair(tie(entries.get(left.id)), tie(entries.get(right.id))));
171
+ return found.map(({ id, score, match }) => ({
98
172
  ...entries.get(id),
99
173
  score,
100
174
  match,
101
175
  }));
102
176
  }
103
177
  return {
104
- changed(set) {
105
- if (index === null)
178
+ generation: () => generation,
179
+ rooms: () => rooms,
180
+ conversations: () => conversations,
181
+ async indexRoom(room) {
182
+ if (rooms.has(room) || filling.has(room))
183
+ return;
184
+ filling.add(room);
185
+ try {
186
+ await inUnits(source.room(room), (path) => {
187
+ const document = filling.has(room) ? source.document(room, path) : null;
188
+ if (document === null)
189
+ return ROW_WEIGHT;
190
+ addDocument(document);
191
+ return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
192
+ });
193
+ if (filling.has(room))
194
+ rooms.add(room);
195
+ }
196
+ finally {
197
+ filling.delete(room);
198
+ }
199
+ },
200
+ indexMessages(conversation, arriving, whole) {
201
+ for (const message of arriving)
202
+ addMessage(message);
203
+ if (!whole) {
204
+ acquiring.add(conversation);
106
205
  return;
206
+ }
207
+ acquiring.delete(conversation);
208
+ conversations.add(conversation);
209
+ },
210
+ forget(leaving) {
211
+ const gone = new Set(leaving);
212
+ for (const [id, entry] of documents)
213
+ if (gone.has(entry.room))
214
+ discard(id, documents);
215
+ for (const room of leaving) {
216
+ rooms.delete(room);
217
+ filling.delete(room);
218
+ }
219
+ },
220
+ changed(set) {
221
+ changes += 1;
107
222
  for (const { locator, path } of set.documents) {
108
- changedDocuments.set(documentId(locator, path), { room: locator, path });
223
+ if (rooms.has(locator) || filling.has(locator)) {
224
+ changedDocuments.set(documentId(locator, path), { room: locator, path });
225
+ }
109
226
  }
110
- for (const { conversation, identity } of set.messages) {
111
- changedMessages.set(messageId(conversation, identity), { conversation, identity });
227
+ for (const { conversation, identity, text } of set.messages) {
228
+ if (!conversations.has(conversation) && !acquiring.has(conversation))
229
+ continue;
230
+ const id = messageId(conversation, identity);
231
+ if (text === null)
232
+ discard(id, messages);
233
+ else
234
+ addMessage({ conversation, identity, text });
112
235
  }
113
236
  },
114
- search({ text, conversations, limit }, selected) {
115
- const built = current();
237
+ changes: () => changes,
238
+ caughtUp,
239
+ search({ text, limit, after, total }, selected, named, within, selections) {
116
240
  const chosen = selected === null
117
241
  ? null
118
242
  : new Set(selected.map(({ room, path }) => documentId(room, path)));
243
+ const asked = new Set(named);
244
+ const documentTie = ({ room, path }) => [room, path];
245
+ const messageTie = ({ conversation, identity }) => [conversation, identity];
246
+ const foundDocuments = ranked(text, documents, ({ room, path }, id) => (chosen === null || chosen.has(id)) &&
247
+ (within === null || within.has(room)) &&
248
+ !(selections?.get(room) ?? []).some((root) => beneath(root, path)), documentTie);
249
+ const foundMessages = ranked(text, messages, ({ conversation }) => asked.has(conversation), messageTie);
250
+ const [documentsAfter, messagesAfter] = after ?? [[], []];
251
+ const documentWindow = hitWindow(foundDocuments, documentsAfter, limit, documentTie);
252
+ const messageWindow = hitWindow(foundMessages, messagesAfter, limit, messageTie);
253
+ const more = documentWindow.cursor !== null || messageWindow.cursor !== null;
119
254
  return {
120
- documents: ranked(built, text, documents, (_entry, id) => chosen === null || chosen.has(id), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
121
- messages: ranked(built, text, messages, ({ conversation }) => conversations === null || conversations.includes(conversation), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
255
+ documents: documentWindow.kept.map(({ match, ...hit }) => ({
256
+ ...hit,
257
+ matches: match,
258
+ })),
259
+ messages: messageWindow.kept.map(({ match, ...hit }) => ({
260
+ ...hit,
261
+ matches: match,
262
+ })),
263
+ ...(more ? { next: JSON.stringify([documentWindow.cursor, messageWindow.cursor]) } : {}),
264
+ ...(total
265
+ ? { total: { documents: foundDocuments.length, messages: foundMessages.length } }
266
+ : {}),
122
267
  };
123
268
  },
124
269
  };
package/dist/seed.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { KeyedResult } from './observation.js';
2
+ import type { QueryRows } from './query.js';
3
+ export type EntrySeed = {
4
+ readonly at: Readonly<Record<string, string>>;
5
+ readonly queries: readonly {
6
+ readonly query: unknown;
7
+ readonly rows: QueryRows;
8
+ }[];
9
+ };
10
+ export type Seeded = {
11
+ readonly rows: QueryRows;
12
+ readonly at: Readonly<Record<string, string>>;
13
+ };
14
+ export declare function entrySeedOf(value: unknown): EntrySeed | null;
15
+ export declare function seededResult(seed: Seeded): KeyedResult;
16
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAA4C,SAAS,EAAE,MAAM,YAAY,CAAC;AAGtF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAwCjG,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAe5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAoBtD"}
package/dist/seed.js ADDED
@@ -0,0 +1,75 @@
1
+ import { documentKey } from './rows.js';
2
+ function plain(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
5
+ function windowOf(value) {
6
+ const { next, total } = value;
7
+ if (next !== undefined && typeof next !== 'string')
8
+ return null;
9
+ if (total !== undefined && !Number.isSafeInteger(total))
10
+ return null;
11
+ return {
12
+ ...(next === undefined ? {} : { next }),
13
+ ...(total === undefined ? {} : { total: total }),
14
+ };
15
+ }
16
+ function rowsOf(value) {
17
+ if (!plain(value))
18
+ return null;
19
+ const window = windowOf(value);
20
+ if (window === null)
21
+ return null;
22
+ if (Array.isArray(value.groups)) {
23
+ const groups = value.groups;
24
+ return groups.every((group) => plain(group) && Array.isArray(group.key) && typeof group.count === 'number')
25
+ ? { groups: groups, ...window }
26
+ : null;
27
+ }
28
+ if (!Array.isArray(value.documents))
29
+ return null;
30
+ const documents = value.documents;
31
+ return documents.every((document) => plain(document) && typeof document.room === 'string' && typeof document.path === 'string')
32
+ ? { documents: documents, ...window }
33
+ : null;
34
+ }
35
+ export function entrySeedOf(value) {
36
+ if (!plain(value) || !plain(value.at) || !Array.isArray(value.queries))
37
+ return null;
38
+ const at = {};
39
+ for (const [room, version] of Object.entries(value.at)) {
40
+ if (typeof version !== 'string')
41
+ return null;
42
+ at[room] = version;
43
+ }
44
+ const queries = [];
45
+ for (const entry of value.queries) {
46
+ if (!plain(entry) || !plain(entry.query))
47
+ return null;
48
+ const rows = rowsOf(entry.rows);
49
+ if (rows === null)
50
+ return null;
51
+ queries.push({ query: entry.query, rows });
52
+ }
53
+ return { at, queries };
54
+ }
55
+ export function seededResult(seed) {
56
+ const coverage = {
57
+ rooms: Object.entries(seed.at).map(([room, generation]) => ({
58
+ room,
59
+ generation,
60
+ current: false,
61
+ })),
62
+ indexes: [],
63
+ overlay: [],
64
+ };
65
+ if ('groups' in seed.rows) {
66
+ return {
67
+ result: { ...seed.rows, coverage },
68
+ keys: seed.rows.groups.map((_group, index) => index),
69
+ };
70
+ }
71
+ return {
72
+ result: { ...seed.rows, coverage },
73
+ keys: seed.rows.documents.map((document) => documentKey(document.room, document.path)),
74
+ };
75
+ }
@@ -0,0 +1,11 @@
1
+ export type Paths<V> = Readonly<Record<string, V>>;
2
+ type Weigh<V> = (key: string, value: V) => number;
3
+ export declare function shared<V>(map: Paths<V>): Paths<V>;
4
+ export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
5
+ export declare function tally<V>(map: Paths<V>, weigh: Weigh<V>): number;
6
+ export declare function sizeOf<V>(map: Paths<V>): number;
7
+ export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
8
+ export declare function drafted<V>(base: Paths<V>): Record<string, V>;
9
+ export declare function settled<V>(draft: Record<string, V>): Paths<V>;
10
+ export {};
11
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAkBnD,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;AA6LlD,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAEjD;AAED,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAM,GAC7B,KAAK,CAAC,CAAC,CAAC,CA8BV;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAA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