@agentshouse/mdruntime 0.1.0-cfbf80d8d4644 → 0.1.0-cfcbb238a5fa0

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 (201) hide show
  1. package/AGENTS.md +270 -203
  2. package/README.md +20 -10
  3. package/dist/acquisition.d.ts +14 -0
  4. package/dist/acquisition.d.ts.map +1 -0
  5. package/dist/acquisition.js +24 -0
  6. package/dist/adapter.d.ts +83 -20
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +15 -2
  10. package/dist/attempt.d.ts +16 -0
  11. package/dist/attempt.d.ts.map +1 -0
  12. package/dist/attempt.js +70 -0
  13. package/dist/binary.d.ts +23 -0
  14. package/dist/binary.d.ts.map +1 -0
  15. package/dist/binary.js +8 -0
  16. package/dist/bootstrap.d.ts +18 -5
  17. package/dist/bootstrap.d.ts.map +1 -1
  18. package/dist/bootstrap.js +113 -37
  19. package/dist/change-set.d.ts +2 -0
  20. package/dist/change-set.d.ts.map +1 -1
  21. package/dist/change-set.js +49 -16
  22. package/dist/change.d.ts +15 -0
  23. package/dist/change.d.ts.map +1 -1
  24. package/dist/change.js +26 -1
  25. package/dist/chat/acts.d.ts +33 -0
  26. package/dist/chat/acts.d.ts.map +1 -0
  27. package/dist/chat/acts.js +36 -0
  28. package/dist/chat/context.d.ts +3 -0
  29. package/dist/chat/context.d.ts.map +1 -0
  30. package/dist/chat/context.js +10 -0
  31. package/dist/chat/input.d.ts +9 -0
  32. package/dist/chat/input.d.ts.map +1 -0
  33. package/dist/chat/input.js +99 -0
  34. package/dist/chat/kit.d.ts +61 -0
  35. package/dist/chat/kit.d.ts.map +1 -0
  36. package/dist/chat/kit.js +123 -0
  37. package/dist/chat/lasting.d.ts +6 -0
  38. package/dist/chat/lasting.d.ts.map +1 -0
  39. package/dist/chat/lasting.js +19 -0
  40. package/dist/chat/list.d.ts +27 -0
  41. package/dist/chat/list.d.ts.map +1 -0
  42. package/dist/chat/list.js +63 -0
  43. package/dist/chat/markdown.d.ts +20 -0
  44. package/dist/chat/markdown.d.ts.map +1 -0
  45. package/dist/chat/markdown.js +188 -0
  46. package/dist/chat/message.d.ts +6 -0
  47. package/dist/chat/message.d.ts.map +1 -0
  48. package/dist/chat/message.js +192 -0
  49. package/dist/chat/messages.d.ts +22 -0
  50. package/dist/chat/messages.d.ts.map +1 -0
  51. package/dist/chat/messages.js +155 -0
  52. package/dist/chat/name.d.ts +6 -0
  53. package/dist/chat/name.d.ts.map +1 -0
  54. package/dist/chat/name.js +37 -0
  55. package/dist/chat/opened.d.ts +11 -0
  56. package/dist/chat/opened.d.ts.map +1 -0
  57. package/dist/chat/opened.js +17 -0
  58. package/dist/chat/overlay.d.ts +31 -0
  59. package/dist/chat/overlay.d.ts.map +1 -0
  60. package/dist/chat/overlay.js +97 -0
  61. package/dist/chat/parts.d.ts +57 -0
  62. package/dist/chat/parts.d.ts.map +1 -0
  63. package/dist/chat/parts.js +119 -0
  64. package/dist/chat/process.d.ts +20 -0
  65. package/dist/chat/process.d.ts.map +1 -0
  66. package/dist/chat/process.js +32 -0
  67. package/dist/chat/provider.d.ts +63 -0
  68. package/dist/chat/provider.d.ts.map +1 -0
  69. package/dist/chat/provider.js +629 -0
  70. package/dist/chat/question.d.ts +9 -0
  71. package/dist/chat/question.d.ts.map +1 -0
  72. package/dist/chat/question.js +80 -0
  73. package/dist/chat/questions.d.ts +31 -0
  74. package/dist/chat/questions.d.ts.map +1 -0
  75. package/dist/chat/questions.js +111 -0
  76. package/dist/chat/read.d.ts +5 -0
  77. package/dist/chat/read.d.ts.map +1 -0
  78. package/dist/chat/read.js +13 -0
  79. package/dist/chat/ready.d.ts +34 -0
  80. package/dist/chat/ready.d.ts.map +1 -0
  81. package/dist/chat/ready.js +91 -0
  82. package/dist/chat/style.d.ts +4 -0
  83. package/dist/chat/style.d.ts.map +1 -0
  84. package/dist/chat/style.js +302 -0
  85. package/dist/chat.d.ts +14 -0
  86. package/dist/chat.d.ts.map +1 -0
  87. package/dist/chat.js +8 -0
  88. package/dist/client.d.ts +25 -12
  89. package/dist/client.d.ts.map +1 -1
  90. package/dist/client.js +75 -16
  91. package/dist/collection.d.ts +21 -12
  92. package/dist/collection.d.ts.map +1 -1
  93. package/dist/collection.js +271 -23
  94. package/dist/connection.d.ts +44 -15
  95. package/dist/connection.d.ts.map +1 -1
  96. package/dist/connection.js +1788 -400
  97. package/dist/conversation.d.ts +26 -10
  98. package/dist/conversation.d.ts.map +1 -1
  99. package/dist/conversation.js +414 -148
  100. package/dist/durability.d.ts +7 -1
  101. package/dist/durability.d.ts.map +1 -1
  102. package/dist/entry.d.ts +17 -0
  103. package/dist/entry.d.ts.map +1 -0
  104. package/dist/entry.js +156 -0
  105. package/dist/expectation.d.ts +21 -0
  106. package/dist/expectation.d.ts.map +1 -0
  107. package/dist/expectation.js +70 -0
  108. package/dist/failure.d.ts +13 -0
  109. package/dist/failure.d.ts.map +1 -0
  110. package/dist/failure.js +19 -0
  111. package/dist/fence.d.ts +6 -0
  112. package/dist/fence.d.ts.map +1 -0
  113. package/dist/fence.js +10 -0
  114. package/dist/host.d.ts +18 -2
  115. package/dist/host.d.ts.map +1 -1
  116. package/dist/host.js +97 -19
  117. package/dist/identity.d.ts +5 -0
  118. package/dist/identity.d.ts.map +1 -1
  119. package/dist/identity.js +19 -1
  120. package/dist/index.d.ts +16 -8
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +5 -0
  123. package/dist/memory.d.ts +11 -4
  124. package/dist/memory.d.ts.map +1 -1
  125. package/dist/memory.js +87 -25
  126. package/dist/model.d.ts +14 -4
  127. package/dist/model.d.ts.map +1 -1
  128. package/dist/model.js +12 -1
  129. package/dist/observation.d.ts +5 -2
  130. package/dist/observation.d.ts.map +1 -1
  131. package/dist/observation.js +22 -11
  132. package/dist/open.d.ts +2 -0
  133. package/dist/open.d.ts.map +1 -0
  134. package/dist/open.js +1 -0
  135. package/dist/outcome.d.ts +32 -3
  136. package/dist/outcome.d.ts.map +1 -1
  137. package/dist/outcome.js +42 -1
  138. package/dist/overlay.d.ts +16 -3
  139. package/dist/overlay.d.ts.map +1 -1
  140. package/dist/overlay.js +118 -77
  141. package/dist/query.d.ts +40 -4
  142. package/dist/query.d.ts.map +1 -1
  143. package/dist/query.js +60 -21
  144. package/dist/reach.d.ts +8 -3
  145. package/dist/reach.d.ts.map +1 -1
  146. package/dist/reach.js +60 -24
  147. package/dist/react.d.ts +31 -18
  148. package/dist/react.d.ts.map +1 -1
  149. package/dist/react.js +15 -11
  150. package/dist/read-side.d.ts +13 -6
  151. package/dist/read-side.d.ts.map +1 -1
  152. package/dist/read-side.js +394 -129
  153. package/dist/readiness.d.ts +53 -0
  154. package/dist/readiness.d.ts.map +1 -0
  155. package/dist/readiness.js +33 -0
  156. package/dist/reads.d.ts +11 -0
  157. package/dist/reads.d.ts.map +1 -0
  158. package/dist/reads.js +98 -0
  159. package/dist/recovery.d.ts +25 -0
  160. package/dist/recovery.d.ts.map +1 -0
  161. package/dist/recovery.js +197 -0
  162. package/dist/refresh.d.ts +13 -3
  163. package/dist/refresh.d.ts.map +1 -1
  164. package/dist/refresh.js +49 -38
  165. package/dist/replica.d.ts +9 -6
  166. package/dist/replica.d.ts.map +1 -1
  167. package/dist/replica.js +125 -68
  168. package/dist/room-draft.d.ts +38 -9
  169. package/dist/room-draft.d.ts.map +1 -1
  170. package/dist/room-draft.js +134 -25
  171. package/dist/rows.d.ts +11 -14
  172. package/dist/rows.d.ts.map +1 -1
  173. package/dist/rows.js +89 -49
  174. package/dist/save.d.ts +31 -1
  175. package/dist/save.d.ts.map +1 -1
  176. package/dist/save.js +376 -47
  177. package/dist/search.d.ts +39 -8
  178. package/dist/search.d.ts.map +1 -1
  179. package/dist/search.js +132 -46
  180. package/dist/seed.d.ts +16 -0
  181. package/dist/seed.d.ts.map +1 -0
  182. package/dist/seed.js +61 -0
  183. package/dist/shared.d.ts +11 -0
  184. package/dist/shared.d.ts.map +1 -0
  185. package/dist/shared.js +368 -0
  186. package/dist/status.d.ts +6 -2
  187. package/dist/status.d.ts.map +1 -1
  188. package/dist/status.js +0 -8
  189. package/dist/store.d.ts +75 -18
  190. package/dist/store.d.ts.map +1 -1
  191. package/dist/store.js +539 -200
  192. package/dist/turn.d.ts +7 -0
  193. package/dist/turn.d.ts.map +1 -0
  194. package/dist/turn.js +45 -0
  195. package/dist/wire.d.ts +141 -33
  196. package/dist/wire.d.ts.map +1 -1
  197. package/dist/wire.js +61 -31
  198. package/package.json +26 -14
  199. package/dist/attachment.d.ts +0 -3
  200. package/dist/attachment.d.ts.map +0 -1
  201. package/dist/attachment.js +0 -8
@@ -1,8 +1,14 @@
1
+ import type { Persistence } from './readiness.js';
2
+ export type StorageEstimate = {
3
+ readonly usage: number;
4
+ readonly quota: number;
5
+ };
1
6
  export type RuntimeShell = {
2
- persistentStorage: boolean;
7
+ persistence: Persistence;
3
8
  generation: string | null;
4
9
  keepGeneration(value: string): void | Promise<void>;
5
10
  dropGeneration(): void | Promise<void>;
11
+ estimate?(): Promise<StorageEstimate | null>;
6
12
  };
7
13
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
8
14
  export declare function nextGeneration(stored: string | null, reported: string | null): string;
@@ -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,eAAe,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,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,QAAQ,CAAC,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CAC9C,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"}
@@ -0,0 +1,17 @@
1
+ import { type QueryRows } from './query.js';
2
+ export { QueryError } from './query.js';
3
+ export type EntryRoom = {
4
+ locator: string;
5
+ schema: string | null;
6
+ documents: Readonly<Record<string, string>>;
7
+ };
8
+ export type EntryArguments = Readonly<Record<string, string>>;
9
+ export type EntryParameterKind = 'string' | 'integer' | 'number' | 'boolean';
10
+ export declare function boundQuery(template: unknown, args: EntryArguments): unknown;
11
+ export declare function entryParameters(template: unknown): readonly string[];
12
+ export declare function entryRefusal(template: unknown): string | null;
13
+ export type EntryScope = {
14
+ results(queries: Readonly<Record<string, unknown>>): Promise<Record<string, QueryRows>>;
15
+ };
16
+ export declare function entryScope(rooms: readonly EntryRoom[]): EntryScope;
17
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +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,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,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,UAAU,CAsDlE"}
package/dist/entry.js ADDED
@@ -0,0 +1,156 @@
1
+ import { attachedModel } from './attached-model.js';
2
+ import { collectionOf, passingFrontmatter } from './collection.js';
3
+ import { NO_MODEL } from './model.js';
4
+ import { invalid, planOf, plain, QueryError, } from './query.js';
5
+ import { createReadSide } from './read-side.js';
6
+ import { rowsOf } from './rows.js';
7
+ export { QueryError } from './query.js';
8
+ const PARAMETER = '$param';
9
+ const KIND = 'as';
10
+ const INTEGER = /^-?(?:0|[1-9][0-9]*)$/u;
11
+ const NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/u;
12
+ function parameterOf(value) {
13
+ if (!plain(value) || !Object.hasOwn(value, PARAMETER))
14
+ return null;
15
+ const { [PARAMETER]: name, [KIND]: kind = 'string', ...rest } = value;
16
+ if (typeof name !== 'string' || Object.keys(rest).length > 0)
17
+ return null;
18
+ if (kind !== 'string' && kind !== 'integer' && kind !== 'number' && kind !== 'boolean') {
19
+ return null;
20
+ }
21
+ return { name, kind };
22
+ }
23
+ function converted(text, kind, at) {
24
+ if (kind === 'string')
25
+ return text;
26
+ if (kind === 'boolean') {
27
+ if (text === 'true' || text === 'false')
28
+ return text === 'true';
29
+ return invalid(at, 'expects true or false');
30
+ }
31
+ if (!(kind === 'integer' ? INTEGER : NUMBER).test(text))
32
+ invalid(at, `expects ${kind === 'integer' ? 'an integer' : 'a number'}`);
33
+ const number = Number(text);
34
+ if (!Number.isFinite(number) || (kind === 'integer' && !Number.isSafeInteger(number))) {
35
+ invalid(at, 'is out of range');
36
+ }
37
+ return number;
38
+ }
39
+ function bound(template, args, at) {
40
+ const parameter = parameterOf(template);
41
+ if (parameter !== null) {
42
+ const text = args[parameter.name];
43
+ if (text === undefined || !Object.hasOwn(args, parameter.name)) {
44
+ invalid(at, `names the parameter ${parameter.name}, which the route lacks`);
45
+ }
46
+ return converted(text, parameter.kind, at);
47
+ }
48
+ if (Array.isArray(template)) {
49
+ return template.map((item, index) => bound(item, args, `${at}[${index}]`));
50
+ }
51
+ if (plain(template)) {
52
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [
53
+ name,
54
+ bound(value, args, at === '' ? name : `${at}.${name}`),
55
+ ]));
56
+ }
57
+ return template;
58
+ }
59
+ export function boundQuery(template, args) {
60
+ return bound(template, args, '');
61
+ }
62
+ export function entryParameters(template) {
63
+ const parameter = parameterOf(template);
64
+ if (parameter !== null)
65
+ return [parameter.name];
66
+ if (Array.isArray(template))
67
+ return [...new Set(template.flatMap(entryParameters))];
68
+ if (plain(template))
69
+ return [...new Set(Object.values(template).flatMap(entryParameters))];
70
+ return [];
71
+ }
72
+ const SAMPLED = {
73
+ direction: 'asc',
74
+ nulls: 'last',
75
+ stringSort: 'lexical',
76
+ locale: 'en',
77
+ limit: 0,
78
+ pathPrefix: 'entry',
79
+ field: '/entry',
80
+ fields: '/entry',
81
+ types: 'any',
82
+ $in: 'entry',
83
+ $nin: 'entry',
84
+ $all: 'entry',
85
+ $size: 0,
86
+ $exists: true,
87
+ $gt: 0,
88
+ $gte: 0,
89
+ $lt: 0,
90
+ $lte: 0,
91
+ };
92
+ function sampled(template, key) {
93
+ if (parameterOf(template) !== null)
94
+ return Object.hasOwn(SAMPLED, key) ? SAMPLED[key] : null;
95
+ if (Array.isArray(template))
96
+ return template.map((item) => sampled(item, key));
97
+ if (plain(template)) {
98
+ return Object.fromEntries(Object.entries(template).map(([name, value]) => [name, sampled(value, name)]));
99
+ }
100
+ return template;
101
+ }
102
+ export function entryRefusal(template) {
103
+ try {
104
+ planOf(sampled(template, ''), { listed: false, rooms: [] });
105
+ return null;
106
+ }
107
+ catch (error) {
108
+ if (error instanceof QueryError)
109
+ return error.message;
110
+ throw error;
111
+ }
112
+ }
113
+ export function entryScope(rooms) {
114
+ const readSide = createReadSide();
115
+ const held = [];
116
+ const documents = rooms.flatMap((room) => {
117
+ const model = attachedModel({
118
+ kind: 'model',
119
+ snapshot: { identity: room.locator, version: '', schema: room.schema, revision: null },
120
+ }, NO_MODEL).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 collection = collectionOf(room.documents, composition);
128
+ return Object.keys(room.documents)
129
+ .sort()
130
+ .map((path) => ({
131
+ locator: room.locator,
132
+ path,
133
+ before: [],
134
+ after: rowsOf(room.locator, path, passingFrontmatter(collection, path) ?? null, composition, null, null, null),
135
+ }));
136
+ });
137
+ readSide.apply({
138
+ documents,
139
+ drafts: [],
140
+ rooms: [],
141
+ queues: [],
142
+ presentations: [],
143
+ messages: [],
144
+ conversations: [],
145
+ });
146
+ const planned = { listed: true, rooms: held };
147
+ return {
148
+ async results(queries) {
149
+ const results = {};
150
+ for (const [name, query] of Object.entries(queries)) {
151
+ results[name] = (await readSide.query(planOf(query, planned), () => null)).rows;
152
+ }
153
+ return results;
154
+ },
155
+ };
156
+ }
@@ -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/host.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { type MdRuntimeOptions } from './connection.js';
2
+ import type { RuntimeDemand } from './acquisition.js';
2
3
  import type { PortReach } from './reach.js';
4
+ import type { CapacityCause, CodeAvailability, Persistence, Readiness, SearchObligation } from './readiness.js';
5
+ import type { EntrySeed } from './seed.js';
3
6
  import { type RuntimePort } from './wire.js';
4
7
  export type MdRuntimeHostOptions = MdRuntimeOptions & {
5
8
  deploymentFacts?: unknown;
@@ -7,13 +10,26 @@ export type MdRuntimeHostOptions = MdRuntimeOptions & {
7
10
  export type AttachedPort = {
8
11
  detach(): void;
9
12
  narrow(reach: PortReach): void;
13
+ readiness(deliver: (readiness: Readiness) => void): () => void;
14
+ answered(queries: readonly unknown[], done: () => void): void;
15
+ code(code: CodeAvailability, capacity: CapacityCause | null): void;
16
+ search(search: SearchObligation): void;
10
17
  };
11
18
  export type MdRuntimeHost = {
12
- attach(port: RuntimePort, app: string, release?: string, reach?: PortReach): AttachedPort;
13
- endAuthorization(): Promise<void>;
19
+ attach(port: RuntimePort, app: string, release?: string, reach?: PortReach, code?: CodeAvailability, search?: SearchObligation): AttachedPort;
20
+ acquire(demand: RuntimeDemand): void;
21
+ seed(entry: EntrySeed): void;
22
+ persisted(answer: Persistence): void;
23
+ endAuthorization(holder?: string): Promise<void>;
24
+ lose(locators: readonly string[]): Promise<void>;
14
25
  stop(): Promise<void>;
15
26
  };
16
27
  export declare function serveMdRuntime(options: MdRuntimeHostOptions): MdRuntimeHost;
28
+ export type { RuntimeDemand } from './acquisition.js';
29
+ export { entrySeedOf, type EntrySeed } from './seed.js';
17
30
  export type { PortReach, ReachedDocument } from './reach.js';
31
+ export type { CapacityCause, CodeAvailability, Persistence, SearchObligation, } from './readiness.js';
32
+ export { createRecovery, retryDelay, type Attempt, type Attempted, type AttemptOptions, type Recovery, type RecoveryOptions, } from './recovery.js';
33
+ export { AUTHORED_SCHEMA, authoredBinding, authoredBy, authoredHolder, bindAuthored, openDatabase, STORE_SCHEMA, } from './store.js';
18
34
  export type { RuntimePort } from './wire.js';
19
35
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,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,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AA0EF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAwH3E;AAED,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EAGtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,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;IAC/B,SAAS,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC9D,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;IACnE,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CACJ,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,gBAAgB,EACvB,MAAM,CAAC,EAAE,gBAAgB,GACxB,YAAY,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IACrC,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAqGF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAyK3E;AAED,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EACd,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/host.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { composeRuntime, } from './connection.js';
2
+ import { queryKey } from './query.js';
3
+ import { described } from './failure.js';
2
4
  import { removeRuntimeStore } from './store.js';
3
- import { AUTHORIZATION_ENDED, request, WIRE_REACH, } from './wire.js';
5
+ import { AUTHORIZATION_ENDED, request, WIRE, } from './wire.js';
4
6
  const NARROWED = new Set(['within', 'whole']);
5
7
  function answered(md, app, writtenBy, member, input) {
6
8
  switch (member) {
@@ -16,6 +18,10 @@ function answered(md, app, writtenBy, member, input) {
16
18
  return md.save(input[0], input[1], writtenBy);
17
19
  case 'history':
18
20
  return md.history(input[0], input[1], input[2]);
21
+ case 'binaryFile.read':
22
+ return md.binaryFile.read(input[0], input[1], input[2]);
23
+ case 'binaryFile.readReference':
24
+ return md.binaryFile.readReference(input[0]);
19
25
  case 'call':
20
26
  return md.call(input[0], input[1]);
21
27
  case 'reached':
@@ -24,6 +30,8 @@ function answered(md, app, writtenBy, member, input) {
24
30
  return md.log();
25
31
  case 'persistence':
26
32
  return md.persistence();
33
+ case 'retry':
34
+ return md.retry();
27
35
  case 'reauthorize':
28
36
  return md.reauthorize();
29
37
  case 'roomDraft.list':
@@ -45,7 +53,7 @@ function answered(md, app, writtenBy, member, input) {
45
53
  case 'conversation.create':
46
54
  return md.conversation.create(input[0]);
47
55
  case 'conversation.send':
48
- return md.conversation.send(input[0]);
56
+ return md.conversation.send(input[0], input[1], input[2]);
49
57
  case 'conversation.answer':
50
58
  return md.conversation.answer(input[0], input[1]);
51
59
  case 'conversation.interrupt':
@@ -57,11 +65,19 @@ function answered(md, app, writtenBy, member, input) {
57
65
  case 'conversation.delete':
58
66
  return md.conversation.delete(input[0]);
59
67
  case 'chatDraft.write':
60
- return md.chatDraft.write(input[0], input[1]);
68
+ return md.chatDraft.write(input[0], input[1], input[2]);
61
69
  case 'chatDraft.discard':
62
70
  return md.chatDraft.discard(input[0]);
63
71
  }
64
72
  }
73
+ function answeredResult(value) {
74
+ return typeof value === 'object' && value !== null && !('pending' in value);
75
+ }
76
+ function answeredMessage(value) {
77
+ if (typeof value !== 'object' || value === null)
78
+ return false;
79
+ return !('result' in value) || answeredResult(value.result);
80
+ }
65
81
  export function serveMdRuntime(options) {
66
82
  const deploymentFacts = structuredClone(options.deploymentFacts);
67
83
  const closing = new AbortController();
@@ -79,13 +95,25 @@ export function serveMdRuntime(options) {
79
95
  deliver(structuredClone(deploymentFacts));
80
96
  return () => { };
81
97
  };
82
- function attach(port, app, release, reach) {
98
+ function attach(port, app, release, reach, code = 'stored', search = 'unused') {
83
99
  if (!authorized)
84
100
  throw new Error(AUTHORIZATION_ENDED);
85
101
  const writtenBy = release === undefined ? undefined : { app, release };
86
- const view = runtime.within(reach ?? null);
102
+ let facts = { target: app, code, capacity: null, search };
103
+ const view = runtime.within(reach ?? null, facts);
87
104
  const observations = new Map();
105
+ const followed = new Set();
106
+ const answeredKeys = new Set();
107
+ let awaited = null;
88
108
  let serving = true;
109
+ const answeredQuery = (query) => {
110
+ answeredKeys.add(queryKey(query));
111
+ if (awaited === null || !awaited.keys.every((key) => answeredKeys.has(key)))
112
+ return;
113
+ const { done } = awaited;
114
+ awaited = null;
115
+ done();
116
+ };
89
117
  const send = (message) => {
90
118
  port.postMessage(message);
91
119
  };
@@ -96,6 +124,8 @@ export function serveMdRuntime(options) {
96
124
  for (const end of observations.values())
97
125
  end();
98
126
  observations.clear();
127
+ for (const end of [...followed])
128
+ end();
99
129
  attachments.delete(detach);
100
130
  };
101
131
  const observe = (id, topic, input) => {
@@ -105,10 +135,12 @@ export function serveMdRuntime(options) {
105
135
  return;
106
136
  send(resolved ? { kind: 'event', id, value } : { kind: 'result', id, value });
107
137
  resolved = true;
138
+ if (topic === 'query' && answeredMessage(value))
139
+ answeredQuery(input[0]);
108
140
  };
109
141
  observations.set(id, topic === 'deployment-facts'
110
142
  ? watchFacts(deliver)
111
- : (NARROWED.has(WIRE_REACH.topics[topic]) ? view : runtime).watch(topic, topic === 'presentation' ? [app] : input, deliver));
143
+ : (NARROWED.has(WIRE.topics[topic]) ? view : runtime).watch(topic, topic === 'presentation' ? [app] : input, deliver));
112
144
  };
113
145
  const serve = async (message) => {
114
146
  if (message.kind === 'hello')
@@ -126,18 +158,16 @@ export function serveMdRuntime(options) {
126
158
  observe(message.id, message.topic, message.input);
127
159
  return;
128
160
  }
129
- const value = await answered(NARROWED.has(WIRE_REACH.members[message.member]) ? view.md : md, app, writtenBy, message.member, message.input);
130
- if (serving)
131
- send({ kind: 'result', id: message.id, value });
161
+ const value = await answered(NARROWED.has(WIRE.members[message.member].reach) ? view.md : md, app, writtenBy, message.member, message.input);
162
+ if (!serving)
163
+ return;
164
+ send({ kind: 'result', id: message.id, value });
165
+ if (message.member === 'query' && answeredResult(value))
166
+ answeredQuery(message.input[0]);
132
167
  }
133
168
  catch (error) {
134
- if (serving) {
135
- send({
136
- kind: 'failure',
137
- id: message.id,
138
- message: error instanceof Error ? error.message : String(error),
139
- });
140
- }
169
+ if (serving)
170
+ send({ kind: 'failure', id: message.id, ...described(error) });
141
171
  }
142
172
  };
143
173
  port.addEventListener('message', (event) => {
@@ -157,22 +187,70 @@ export function serveMdRuntime(options) {
157
187
  if (serving)
158
188
  view.narrow(next);
159
189
  },
190
+ code(next, capacity) {
191
+ if (!serving)
192
+ return;
193
+ facts = { ...facts, code: next, capacity };
194
+ view.facts(facts);
195
+ },
196
+ search(next) {
197
+ if (!serving)
198
+ return;
199
+ facts = { ...facts, search: next };
200
+ view.facts(facts);
201
+ },
202
+ answered(queries, done) {
203
+ const keys = queries.map(queryKey);
204
+ if (keys.every((key) => answeredKeys.has(key)))
205
+ done();
206
+ else
207
+ awaited = { keys, done };
208
+ },
209
+ readiness(deliver) {
210
+ if (!serving)
211
+ return () => { };
212
+ const stop = view.watch('readiness', [], (value) => {
213
+ if (serving)
214
+ deliver(value);
215
+ });
216
+ const end = () => {
217
+ followed.delete(end);
218
+ stop();
219
+ };
220
+ followed.add(end);
221
+ return end;
222
+ },
160
223
  };
161
224
  }
162
225
  return {
163
226
  attach,
164
- async endAuthorization() {
227
+ acquire(demand) {
228
+ runtime.acquire(demand);
229
+ },
230
+ seed(entry) {
231
+ runtime.seed(entry);
232
+ },
233
+ persisted(answer) {
234
+ runtime.persisted(answer);
235
+ },
236
+ async endAuthorization(holder) {
165
237
  authorized = false;
166
238
  for (const [detach, send] of [...attachments]) {
167
239
  send({ kind: 'ended' });
168
240
  detach();
169
241
  }
170
242
  close();
171
- await removeRuntimeStore();
172
- await options.shell.dropGeneration();
243
+ if (!(await removeRuntimeStore(holder)))
244
+ await options.shell.dropGeneration();
245
+ },
246
+ lose(locators) {
247
+ return runtime.lose(locators);
173
248
  },
174
249
  stop() {
175
250
  return runtime.stop();
176
251
  },
177
252
  };
178
253
  }
254
+ export { entrySeedOf } from './seed.js';
255
+ export { createRecovery, retryDelay, } from './recovery.js';
256
+ export { AUTHORED_SCHEMA, authoredBinding, authoredBy, authoredHolder, bindAuthored, openDatabase, STORE_SCHEMA, } from './store.js';
@@ -1,3 +1,8 @@
1
1
  export declare function changeBatchIdentity(at?: number): string;
2
+ export declare function identityTime(identity: string): number;
2
3
  export declare function roomDraftRevision(): string;
4
+ export declare function chatDraftRevision(): string;
5
+ export declare function transferIdentity(): string;
6
+ export declare function indexGeneration(): string;
7
+ export declare function binaryLocalId(): string;
3
8
  //# sourceMappingURL=identity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAI1C"}
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
package/dist/identity.js CHANGED
@@ -10,8 +10,26 @@ export function changeBatchIdentity(at = Date.now()) {
10
10
  const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
11
11
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
12
12
  }
13
- export function roomDraftRevision() {
13
+ export function identityTime(identity) {
14
+ return Number.parseInt(identity.replaceAll('-', '').slice(0, 12), 16);
15
+ }
16
+ function randomIdentity() {
14
17
  const bytes = new Uint8Array(16);
15
18
  crypto.getRandomValues(bytes);
16
19
  return [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
17
20
  }
21
+ export function roomDraftRevision() {
22
+ return randomIdentity();
23
+ }
24
+ export function chatDraftRevision() {
25
+ return randomIdentity();
26
+ }
27
+ export function transferIdentity() {
28
+ return randomIdentity();
29
+ }
30
+ export function indexGeneration() {
31
+ return randomIdentity();
32
+ }
33
+ export function binaryLocalId() {
34
+ return randomIdentity();
35
+ }