@agentshouse/mdruntime 0.1.0-c3903a68dcbbf → 0.1.0-c3a5b012b4a8c

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 (197) hide show
  1. package/README.md +26 -13
  2. package/dist/adapter.d.ts +244 -88
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +1 -9
  5. package/dist/attached-model.d.ts +8 -0
  6. package/dist/attached-model.d.ts.map +1 -0
  7. package/dist/attached-model.js +46 -0
  8. package/dist/attempt.d.ts +16 -0
  9. package/dist/attempt.d.ts.map +1 -0
  10. package/dist/attempt.js +70 -0
  11. package/dist/binary.d.ts +18 -0
  12. package/dist/binary.d.ts.map +1 -0
  13. package/dist/binary.js +8 -0
  14. package/dist/bootstrap.d.ts +40 -6
  15. package/dist/bootstrap.d.ts.map +1 -1
  16. package/dist/bootstrap.js +336 -52
  17. package/dist/chain.d.ts +12 -0
  18. package/dist/chain.d.ts.map +1 -0
  19. package/dist/chain.js +64 -0
  20. package/dist/change-set.d.ts +9 -14
  21. package/dist/change-set.d.ts.map +1 -1
  22. package/dist/change-set.js +11 -60
  23. package/dist/change.d.ts +46 -0
  24. package/dist/change.d.ts.map +1 -1
  25. package/dist/change.js +34 -0
  26. package/dist/client.d.ts +44 -24
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +161 -36
  29. package/dist/collection.d.ts +13 -16
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +52 -66
  32. package/dist/compile.d.ts +11 -0
  33. package/dist/compile.d.ts.map +1 -0
  34. package/dist/compile.js +717 -0
  35. package/dist/connection.d.ts +69 -44
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +4581 -1472
  38. package/dist/context.d.ts +2 -0
  39. package/dist/context.d.ts.map +1 -0
  40. package/dist/context.js +7 -0
  41. package/dist/conversation-row.d.ts +33 -0
  42. package/dist/conversation-row.d.ts.map +1 -0
  43. package/dist/conversation-row.js +47 -0
  44. package/dist/conversation.d.ts +76 -27
  45. package/dist/conversation.d.ts.map +1 -1
  46. package/dist/conversation.js +1052 -273
  47. package/dist/digest.d.ts +7 -0
  48. package/dist/digest.d.ts.map +1 -0
  49. package/dist/digest.js +113 -0
  50. package/dist/durability.d.ts +10 -1
  51. package/dist/durability.d.ts.map +1 -1
  52. package/dist/durability.js +5 -0
  53. package/dist/entry.d.ts +20 -0
  54. package/dist/entry.d.ts.map +1 -0
  55. package/dist/entry.js +161 -0
  56. package/dist/expectation.d.ts +21 -0
  57. package/dist/expectation.d.ts.map +1 -0
  58. package/dist/expectation.js +70 -0
  59. package/dist/failure.d.ts +13 -0
  60. package/dist/failure.d.ts.map +1 -0
  61. package/dist/failure.js +19 -0
  62. package/dist/file.d.ts +2 -19
  63. package/dist/file.d.ts.map +1 -1
  64. package/dist/file.js +7 -122
  65. package/dist/host.d.ts +17 -3
  66. package/dist/host.d.ts.map +1 -1
  67. package/dist/host.js +163 -75
  68. package/dist/identity.d.ts +3 -0
  69. package/dist/identity.d.ts.map +1 -1
  70. package/dist/identity.js +13 -1
  71. package/dist/index.d.ts +26 -11
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +12 -1
  74. package/dist/job.d.ts +33 -0
  75. package/dist/job.d.ts.map +1 -0
  76. package/dist/job.js +54 -0
  77. package/dist/live.d.ts +23 -0
  78. package/dist/live.d.ts.map +1 -0
  79. package/dist/live.js +165 -0
  80. package/dist/media.d.ts +8 -0
  81. package/dist/media.d.ts.map +1 -0
  82. package/dist/media.js +218 -0
  83. package/dist/memory.d.ts +30 -9
  84. package/dist/memory.d.ts.map +1 -1
  85. package/dist/memory.js +337 -87
  86. package/dist/messages.d.ts +52 -0
  87. package/dist/messages.d.ts.map +1 -0
  88. package/dist/messages.js +168 -0
  89. package/dist/model.d.ts +17 -16
  90. package/dist/model.d.ts.map +1 -1
  91. package/dist/model.js +9 -9
  92. package/dist/name.d.ts +4 -0
  93. package/dist/name.d.ts.map +1 -0
  94. package/dist/name.js +122 -0
  95. package/dist/observation.d.ts +22 -2
  96. package/dist/observation.d.ts.map +1 -1
  97. package/dist/observation.js +133 -17
  98. package/dist/open.d.ts +2 -0
  99. package/dist/open.d.ts.map +1 -0
  100. package/dist/open.js +1 -0
  101. package/dist/opened.d.ts +22 -0
  102. package/dist/opened.d.ts.map +1 -0
  103. package/dist/opened.js +107 -0
  104. package/dist/outcome.d.ts +72 -21
  105. package/dist/outcome.d.ts.map +1 -1
  106. package/dist/outcome.js +81 -1
  107. package/dist/overlay.d.ts +16 -5
  108. package/dist/overlay.d.ts.map +1 -1
  109. package/dist/overlay.js +147 -180
  110. package/dist/parts.d.ts +59 -0
  111. package/dist/parts.d.ts.map +1 -0
  112. package/dist/parts.js +118 -0
  113. package/dist/paths.d.ts +1 -1
  114. package/dist/paths.d.ts.map +1 -1
  115. package/dist/paths.js +4 -16
  116. package/dist/query.d.ts +56 -180
  117. package/dist/query.d.ts.map +1 -1
  118. package/dist/query.js +3 -422
  119. package/dist/questions.d.ts +32 -0
  120. package/dist/questions.d.ts.map +1 -0
  121. package/dist/questions.js +118 -0
  122. package/dist/reach.d.ts +54 -0
  123. package/dist/reach.d.ts.map +1 -0
  124. package/dist/reach.js +483 -0
  125. package/dist/react.d.ts +45 -0
  126. package/dist/react.d.ts.map +1 -0
  127. package/dist/react.js +54 -0
  128. package/dist/read.d.ts +7 -0
  129. package/dist/read.d.ts.map +1 -0
  130. package/dist/read.js +17 -0
  131. package/dist/readiness.d.ts +50 -0
  132. package/dist/readiness.d.ts.map +1 -0
  133. package/dist/readiness.js +27 -0
  134. package/dist/recovery.d.ts +26 -0
  135. package/dist/recovery.d.ts.map +1 -0
  136. package/dist/recovery.js +232 -0
  137. package/dist/refresh.d.ts +21 -7
  138. package/dist/refresh.d.ts.map +1 -1
  139. package/dist/refresh.js +155 -55
  140. package/dist/replica.d.ts +61 -33
  141. package/dist/replica.d.ts.map +1 -1
  142. package/dist/replica.js +355 -162
  143. package/dist/room-draft.d.ts +62 -11
  144. package/dist/room-draft.d.ts.map +1 -1
  145. package/dist/room-draft.js +281 -83
  146. package/dist/rows.d.ts +32 -34
  147. package/dist/rows.d.ts.map +1 -1
  148. package/dist/rows.js +65 -87
  149. package/dist/save.d.ts +74 -6
  150. package/dist/save.d.ts.map +1 -1
  151. package/dist/save.js +902 -183
  152. package/dist/search.d.ts +15 -54
  153. package/dist/search.d.ts.map +1 -1
  154. package/dist/search.js +10 -121
  155. package/dist/seed.d.ts +16 -0
  156. package/dist/seed.d.ts.map +1 -0
  157. package/dist/seed.js +75 -0
  158. package/dist/shared.d.ts +15 -0
  159. package/dist/shared.d.ts.map +1 -0
  160. package/dist/shared.js +421 -0
  161. package/dist/source.d.ts +61 -0
  162. package/dist/source.d.ts.map +1 -0
  163. package/dist/source.js +81 -0
  164. package/dist/status.d.ts +7 -4
  165. package/dist/status.d.ts.map +1 -1
  166. package/dist/status.js +3 -15
  167. package/dist/store.d.ts +178 -80
  168. package/dist/store.d.ts.map +1 -1
  169. package/dist/store.js +372 -381
  170. package/dist/stored.d.ts +156 -0
  171. package/dist/stored.d.ts.map +1 -0
  172. package/dist/stored.js +637 -0
  173. package/dist/tables.d.ts +388 -0
  174. package/dist/tables.d.ts.map +1 -0
  175. package/dist/tables.js +706 -0
  176. package/dist/transfer.d.ts +0 -5
  177. package/dist/transfer.d.ts.map +1 -1
  178. package/dist/turn.d.ts +9 -0
  179. package/dist/turn.d.ts.map +1 -0
  180. package/dist/turn.js +75 -0
  181. package/dist/validation.d.ts +29 -0
  182. package/dist/validation.d.ts.map +1 -0
  183. package/dist/validation.js +104 -0
  184. package/dist/windows.d.ts +11 -0
  185. package/dist/windows.d.ts.map +1 -0
  186. package/dist/windows.js +16 -0
  187. package/dist/wire.d.ts +199 -19
  188. package/dist/wire.d.ts.map +1 -1
  189. package/dist/wire.js +92 -67
  190. package/package.json +33 -10
  191. package/AGENTS.md +0 -210
  192. package/dist/attachment.d.ts +0 -3
  193. package/dist/attachment.d.ts.map +0 -1
  194. package/dist/attachment.js +0 -8
  195. package/dist/read-side.d.ts +0 -14
  196. package/dist/read-side.d.ts.map +0 -1
  197. package/dist/read-side.js +0 -371
@@ -0,0 +1,8 @@
1
+ import { type VerifiedModel } from '@agentshouse/mdmodel';
2
+ import type { ModelResult, ModelState } from './model.js';
3
+ export declare const NO_ROOM_TYPES: VerifiedModel;
4
+ export declare function roomTypesOf(schema: string | undefined, nameable?: readonly string[]): VerifiedModel;
5
+ export declare function builtInModel(roomTypes: VerifiedModel): ModelState;
6
+ export declare function schemaTypes(schema: string | null, roomTypes: VerifiedModel): VerifiedModel['types'];
7
+ export declare function attachedModel(answer: ModelResult, roomTypes: VerifiedModel): ModelState;
8
+ //# sourceMappingURL=attached-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attached-model.d.ts","sourceRoot":"","sources":["../src/attached-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,eAAO,MAAM,aAAa,EAAE,aAA2D,CAAC;AAExF,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,GAAE,SAAS,MAAM,EAAO,GAC/B,aAAa,CAGf;AAOD,wBAAgB,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,UAAU,CAEjE;AAoBD,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,SAAS,EAAE,aAAa,GACvB,aAAa,CAAC,OAAO,CAAC,CAExB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,GAAG,UAAU,CAUvF"}
@@ -0,0 +1,46 @@
1
+ import { readTypes } from '@agentshouse/mdmodel';
2
+ import { MD_MODEL } from './collection.js';
3
+ export const NO_ROOM_TYPES = Object.freeze({ types: Object.freeze({}) });
4
+ export function roomTypesOf(schema, nameable = []) {
5
+ if (schema === undefined)
6
+ return NO_ROOM_TYPES;
7
+ return Object.freeze({ ...readTypes(schema), nameable });
8
+ }
9
+ const BUILT_IN = {
10
+ kind: 'model',
11
+ snapshot: { identity: 'built-in', version: '', schema: null, revision: null },
12
+ };
13
+ export function builtInModel(roomTypes) {
14
+ return attachedModel(BUILT_IN, roomTypes);
15
+ }
16
+ const READ_SCHEMAS = 64;
17
+ const read = new WeakMap();
18
+ function typesRead(schema, roomTypes) {
19
+ let held = read.get(roomTypes);
20
+ if (held === undefined) {
21
+ held = new Map();
22
+ read.set(roomTypes, held);
23
+ }
24
+ const known = held.get(schema);
25
+ if (known !== undefined)
26
+ return known;
27
+ const types = readTypes(schema, roomTypes);
28
+ if (held.size >= READ_SCHEMAS)
29
+ held.delete(held.keys().next().value);
30
+ held.set(schema, types);
31
+ return types;
32
+ }
33
+ export function schemaTypes(schema, roomTypes) {
34
+ return (schema === null ? roomTypes : typesRead(schema, roomTypes)).types;
35
+ }
36
+ export function attachedModel(answer, roomTypes) {
37
+ if (answer.kind === 'model-unavailable') {
38
+ return { status: 'unavailable', reason: answer.reason };
39
+ }
40
+ return {
41
+ status: 'current',
42
+ snapshot: structuredClone(answer.snapshot),
43
+ verifiedWith: MD_MODEL,
44
+ types: schemaTypes(answer.snapshot.schema, roomTypes),
45
+ };
46
+ }
@@ -0,0 +1,16 @@
1
+ export type Answered = 'accepted' | 'refused' | 'unanswered' | 'offline';
2
+ export type Identities = {
3
+ of(intent: string): string;
4
+ settle(answered: Answered): void;
5
+ };
6
+ export declare function identities(mint?: () => string): Identities;
7
+ export declare function intentOf(name: string, about: unknown): string;
8
+ export type Attempt = {
9
+ identity(intent: string): string;
10
+ settle(answered: Answered, drop: (act: number) => void): void;
11
+ };
12
+ export type Attempts = {
13
+ begin(act: number): Attempt;
14
+ };
15
+ export declare function attempts(mint?: () => string): Attempts;
16
+ //# sourceMappingURL=attempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../src/attempt.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAM,MAAoC,GAAG,UAAU,CAmBvF;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAa7D;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,QAAQ,CAyBtD"}
@@ -0,0 +1,70 @@
1
+ import { changeBatchIdentity } from './identity.js';
2
+ export function identities(mint = () => changeBatchIdentity()) {
3
+ const kept = new Map();
4
+ let used = new Map();
5
+ return {
6
+ of(intent) {
7
+ const one = used.get(intent) ?? kept.get(intent) ?? mint();
8
+ used.set(intent, one);
9
+ return one;
10
+ },
11
+ settle(answered) {
12
+ if (answered !== 'offline') {
13
+ for (const [intent, one] of used) {
14
+ if (answered === 'unanswered')
15
+ kept.set(intent, one);
16
+ else
17
+ kept.delete(intent);
18
+ }
19
+ }
20
+ used = new Map();
21
+ },
22
+ };
23
+ }
24
+ const blobs = new WeakMap();
25
+ export function intentOf(name, about) {
26
+ const carried = [];
27
+ const json = JSON.stringify(about, (_key, value) => {
28
+ if (!(value instanceof Blob))
29
+ return value;
30
+ let identity = blobs.get(value);
31
+ if (identity === undefined) {
32
+ identity = changeBatchIdentity();
33
+ blobs.set(value, identity);
34
+ }
35
+ carried.push(identity);
36
+ return null;
37
+ });
38
+ return `${name}\u0000${json}\u0000${carried.join(',')}`;
39
+ }
40
+ export function attempts(mint) {
41
+ const numbers = identities(mint);
42
+ const waiting = new Map();
43
+ return {
44
+ begin(act) {
45
+ const intents = [];
46
+ return {
47
+ identity(intent) {
48
+ intents.push(intent);
49
+ return numbers.of(intent);
50
+ },
51
+ settle(answered, drop) {
52
+ numbers.settle(answered);
53
+ if (answered === 'refused' || answered === 'offline')
54
+ drop(act);
55
+ if (answered === 'offline')
56
+ return;
57
+ for (const intent of intents) {
58
+ const earlier = waiting.get(intent);
59
+ if (earlier !== undefined && earlier !== act)
60
+ drop(earlier);
61
+ if (answered === 'unanswered')
62
+ waiting.set(intent, act);
63
+ else
64
+ waiting.delete(intent);
65
+ }
66
+ },
67
+ };
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,18 @@
1
+ import type { HeldBinary } from './overlay.js';
2
+ export type BinaryFileRecord = {
3
+ readonly state: 'accepted';
4
+ readonly revision: string;
5
+ readonly path: string;
6
+ readonly byteLength: number;
7
+ readonly mediaType: string;
8
+ readonly sha256: string;
9
+ } | {
10
+ readonly state: 'pending';
11
+ readonly localId: string;
12
+ readonly path: string;
13
+ readonly byteLength: number;
14
+ readonly mediaType: string;
15
+ readonly sha256: string;
16
+ };
17
+ export declare function binaryRecord(path: string, held: HeldBinary, revision: string | undefined): BinaryFileRecord;
18
+ //# sourceMappingURL=binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,gBAAgB,GACxB;IACE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEN,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,gBAAgB,CAKlB"}
package/dist/binary.js ADDED
@@ -0,0 +1,8 @@
1
+ export function binaryRecord(path, held, revision) {
2
+ const facts = { byteLength: held.byteLength, mediaType: held.mediaType, sha256: held.sha256 };
3
+ if (held.state === 'pending')
4
+ return { state: 'pending', localId: held.localId, path, ...facts };
5
+ if (revision === undefined)
6
+ throw new Error(`the accepted binary file ${path} has no revision`);
7
+ return { state: 'accepted', revision, path, ...facts };
8
+ }
@@ -1,10 +1,44 @@
1
1
  import type { ModelState } from './model.js';
2
- import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom } from './adapter.js';
3
- import { type Staged } from './replica.js';
2
+ import type { Adapter, TypedPath, AdapterFailure, Authorization, BootstrapPart, DiscoveredRoom, NotReady, RetryableRefusal, RoomModels } from './adapter.js';
3
+ import type { Composition } from './collection.js';
4
+ import type { InstallationStep } from './readiness.js';
5
+ import { type Refreshing } from './refresh.js';
6
+ import type { ReplicaRecord } from './replica.js';
7
+ import type { StagedPage, TransferRecord } from './store.js';
4
8
  import { type Unconfirmed } from './transfer.js';
5
- export type BootstrapOutcome = Staged | Unconfirmed | AdapterFailure;
6
- export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom, models: {
9
+ export type Bootstrapped = {
10
+ kind: 'staged';
11
+ record: ReplicaRecord;
12
+ refreshed: boolean;
13
+ };
14
+ export type BootstrapOutcome = Bootstrapped | Unconfirmed | NotReady | RetryableRefusal | AdapterFailure;
15
+ export type HeldModels = {
7
16
  collection: ModelState;
8
- selection: ModelState;
9
- }, continuing: () => boolean): Promise<BootstrapOutcome>;
17
+ };
18
+ export type Remodel = (models: RoomModels | undefined, held: HeldModels) => HeldModels;
19
+ export type Reads = Pick<Adapter, 'bootstrap' | 'refresh' | 'reached'>;
20
+ export type Arriving = {
21
+ at(bytes: number): void;
22
+ end(): void;
23
+ };
24
+ export type Resumed = {
25
+ readonly record: TransferRecord | null;
26
+ readonly staged: ReadonlySet<string>;
27
+ };
28
+ export type Staging = {
29
+ held(locator: string): TransferRecord | null;
30
+ turn(locator: string, step: InstallationStep): Promise<() => void>;
31
+ unqueued(): Promise<void>;
32
+ queued(text: number): () => void;
33
+ arriving(locator: string): Arriving;
34
+ readonly streamed: boolean;
35
+ stage(record: TransferRecord, page: StagedPage, composition: Composition): Promise<TransferRecord | null>;
36
+ resume(record: TransferRecord, parts: readonly BootstrapPart[], composition: Composition): Promise<Resumed | null>;
37
+ derive(locator: string, key: number, composition: Composition): Promise<boolean>;
38
+ refreshing(locator: string, key: number, composition: Composition): Promise<Refreshing>;
39
+ abandon(locator: string): Promise<void>;
40
+ setAside(locator: string): Promise<void>;
41
+ release(key: number): Promise<void>;
42
+ };
43
+ export declare function bootstrapRoom(adapter: Reads, authorization: Authorization, room: DiscoveredRoom, held: HeldModels, builtIn: ModelState, typedPaths: readonly TypedPath[], remodel: Remodel, continuing: () => boolean, staging: Staging): Promise<BootstrapOutcome>;
10
44
  //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,EACb,cAAc,EAGf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,GAAG,cAAc,CAAC;AAErE,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,EACzD,UAAU,EAAE,MAAM,OAAO,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAgD3B"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,aAAa,EAEb,aAAa,EAEb,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,KAAK,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redAttachments } from './attachment.js';
2
- import { readStaged } from './replica.js';
1
+ import { transferIdentity } from './identity.js';
2
+ import { advancement, pageEntries } from './refresh.js';
3
+ import { entriesIn } from './shared.js';
3
4
  import { unconfirmed } from './transfer.js';
4
- export async function bootstrapRoom(adapter, authorization, room, models, continuing) {
5
- const first = await adapter.bootstrap(authorization, {
6
- locator: room.locator,
7
- selection: room.replica.selection,
8
- });
9
- if (first.kind !== 'bootstrap')
5
+ const NOTHING_PRIOR = () => Promise.resolve(new Map());
6
+ const PARTS_IN_FLIGHT = 6;
7
+ function textOf(page) {
8
+ let text = 0;
9
+ for (const [, content] of entriesIn(page.documents))
10
+ text += content.length;
11
+ return text;
12
+ }
13
+ async function pageOf(page, part) {
14
+ return {
15
+ entries: await pageEntries(page, [], page.roomVersion, NOTHING_PRIOR),
16
+ folders: page.folders ?? [],
17
+ ...(part === undefined ? {} : { part }),
18
+ };
19
+ }
20
+ export async function bootstrapRoom(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging) {
21
+ if (staging.held(room.locator) !== null)
22
+ await staging.abandon(room.locator);
23
+ const begun = () => started(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging);
24
+ const first = await begun();
25
+ if (first.kind !== 'expired')
10
26
  return first;
11
- const roomVersion = first.roomVersion;
12
- const documents = { ...first.documents };
13
- const revisions = { ...first.revisions };
14
- const changes = { ...first.changes };
15
- const binaryTargets = new Set(first.binaryTargets);
16
- const attachments = [first.attachments ?? []];
17
- let pageToken = first.pageToken;
18
- while (pageToken !== undefined) {
19
- if (!continuing())
20
- return unconfirmed;
21
- const page = await adapter.bootstrap(authorization, {
22
- locator: room.locator,
23
- selection: room.replica.selection,
24
- pageToken,
25
- });
26
- if (page.kind !== 'bootstrap')
27
- return page;
28
- if (page.roomVersion !== roomVersion)
29
- return unconfirmed;
30
- Object.assign(documents, page.documents);
31
- Object.assign(revisions, page.revisions);
32
- Object.assign(changes, page.changes);
33
- for (const target of page.binaryTargets)
34
- binaryTargets.add(target);
35
- attachments.push(page.attachments ?? []);
36
- pageToken = page.pageToken;
37
- }
38
- return readStaged({
39
- locator: room.locator,
40
- name: room.name,
41
- operations: room.operations,
42
- replica: room.replica,
43
- attachedModel: room.attachedModel,
27
+ await staging.setAside(room.locator);
28
+ try {
29
+ const replacement = await begun();
30
+ if (replacement.kind !== 'expired')
31
+ return replacement;
32
+ await staging.abandon(room.locator);
33
+ return unconfirmed;
34
+ }
35
+ finally {
36
+ if (first.key !== null)
37
+ await staging.release(first.key);
38
+ }
39
+ }
40
+ function dropped(ahead) {
41
+ void ahead?.fetched.then(({ next, written }) => {
42
+ written();
43
+ dropped(next);
44
+ }, () => { });
45
+ }
46
+ function compositionFor(room, models, builtIn, typedPaths) {
47
+ return {
44
48
  model: models.collection,
45
- typedSelection: room.typedSelection ?? null,
46
- selectionModel: models.selection,
47
- untypedFolders: room.untypedFolders ?? [],
48
- providerOwnedPaths: room.providerOwnedPaths,
49
- roomVersion,
50
- documents,
51
- binaryTargets: [...binaryTargets].sort(),
52
- revisions,
53
- changes,
54
- written: Object.fromEntries(Object.keys(documents).map((path) => [path, roomVersion])),
55
- attachments: declaredAttachments(attachments),
49
+ selection: room.typedSelection === undefined
50
+ ? null
51
+ : { roots: room.typedSelection.roots, model: builtIn },
52
+ typedPaths,
53
+ };
54
+ }
55
+ async function started(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging) {
56
+ const mode = { paged: false };
57
+ let outcome;
58
+ try {
59
+ outcome = await bundle(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging, mode);
60
+ }
61
+ catch (error) {
62
+ await stopped(staging, room.locator, mode).catch(() => { });
63
+ throw error;
64
+ }
65
+ if (outcome.kind !== 'staged' && outcome.kind !== 'expired') {
66
+ await stopped(staging, room.locator, mode);
67
+ }
68
+ return outcome;
69
+ }
70
+ function stopped(staging, locator, mode) {
71
+ return mode.paged ? staging.abandon(locator) : staging.setAside(locator);
72
+ }
73
+ async function bundle(adapter, authorization, room, held, builtIn, typedPaths, remodel, continuing, staging, mode) {
74
+ const locator = room.locator;
75
+ const selection = room.replica.selection;
76
+ const ending = new AbortController();
77
+ const arriving = staging.arriving(locator);
78
+ const downloaded = await staging.turn(locator, 'downloading');
79
+ const asking = (token) => adapter.bootstrap(authorization, {
80
+ locator,
81
+ selection,
82
+ signal: ending.signal,
83
+ ...(token === null
84
+ ? { arriving: (bytes) => arriving.at(bytes) }
85
+ : { pageToken: token }),
56
86
  });
87
+ const fetching = (token) => {
88
+ const fetched = (async () => {
89
+ await staging.unqueued();
90
+ const page = continuing() ? await asking(token) : unconfirmed;
91
+ if (page.kind !== 'bootstrap')
92
+ return { page, next: null, written: () => { } };
93
+ const written = staging.queued(textOf(page));
94
+ const later = page.pageToken;
95
+ if (later === undefined && page.parts === undefined) {
96
+ downloaded();
97
+ arriving.end();
98
+ }
99
+ return { page, written, next: later === undefined || !continuing() ? null : fetching(later) };
100
+ })();
101
+ fetched.catch(() => { });
102
+ return { fetched };
103
+ };
104
+ let transfer = null;
105
+ let ahead = fetching(null);
106
+ try {
107
+ while (ahead !== null) {
108
+ if (!continuing())
109
+ return unconfirmed;
110
+ const fetched = await ahead.fetched;
111
+ ahead = fetched.next;
112
+ try {
113
+ if (!continuing())
114
+ return unconfirmed;
115
+ const page = fetched.page;
116
+ if (page.kind === 'beyond-horizon')
117
+ return { kind: 'expired', key: transfer?.key ?? null };
118
+ if (page.kind !== 'bootstrap')
119
+ return page;
120
+ if (transfer === null && page.parts !== undefined) {
121
+ const parted = await parts(page, page.parts);
122
+ if (parted.kind !== 'parted')
123
+ return parted;
124
+ transfer = parted.transfer;
125
+ continue;
126
+ }
127
+ if (transfer === null)
128
+ mode.paged = true;
129
+ const models = remodel(page.models, transfer?.models ?? held);
130
+ const staged = await staging.stage({
131
+ locator,
132
+ transfer: transfer?.transfer ?? transferIdentity(),
133
+ selection,
134
+ from: transfer !== null && adapter.reached(locator, page.roomVersion, transfer.from)
135
+ ? transfer.from
136
+ : page.roomVersion,
137
+ last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
138
+ ? transfer.last
139
+ : page.roomVersion,
140
+ done: { bytes: (transfer?.done.bytes ?? 0) + (page.bytes ?? 0) },
141
+ models,
142
+ key: transfer?.key ?? null,
143
+ }, await pageOf(page), compositionFor(room, models, builtIn, typedPaths));
144
+ if (staged === null)
145
+ return unconfirmed;
146
+ transfer = staged;
147
+ }
148
+ finally {
149
+ fetched.written();
150
+ }
151
+ }
152
+ }
153
+ finally {
154
+ ending.abort();
155
+ downloaded();
156
+ arriving.end();
157
+ dropped(ahead);
158
+ }
159
+ if (transfer === null)
160
+ return unconfirmed;
161
+ return installed(transfer);
162
+ async function parts(head, listed) {
163
+ const models = remodel(head.models, held);
164
+ const composition = compositionFor(room, models, builtIn, typedPaths);
165
+ const resumed = await staging.resume({
166
+ locator,
167
+ transfer: transferIdentity(),
168
+ selection,
169
+ from: head.roomVersion,
170
+ last: head.roomVersion,
171
+ done: { bytes: 0 },
172
+ models,
173
+ key: null,
174
+ }, listed, composition);
175
+ if (resumed === null)
176
+ return unconfirmed;
177
+ let staged = resumed.record ?? {
178
+ locator,
179
+ transfer: transferIdentity(),
180
+ selection,
181
+ from: head.roomVersion,
182
+ last: head.roomVersion,
183
+ done: { bytes: 0 },
184
+ models,
185
+ key: null,
186
+ };
187
+ const wanted = listed.filter((part) => !resumed.staged.has(part.id));
188
+ let arrived = staged.done.bytes;
189
+ const partial = new Map();
190
+ const report = () => {
191
+ let bytes = arrived;
192
+ for (const held of partial.values())
193
+ bytes += held;
194
+ arriving.at(bytes);
195
+ };
196
+ report();
197
+ const arrivals = [];
198
+ let woken = null;
199
+ let next = 0;
200
+ let flying = 0;
201
+ let halted = false;
202
+ let stopped = false;
203
+ let admitted = Promise.resolve();
204
+ const fetched = () => {
205
+ if ((next < wanted.length && !halted) || flying > 0)
206
+ return;
207
+ downloaded();
208
+ arriving.end();
209
+ };
210
+ const landed = (one) => {
211
+ flying -= 1;
212
+ if (stopped)
213
+ one.written();
214
+ else
215
+ arrivals.push(one);
216
+ woken?.();
217
+ ask();
218
+ fetched();
219
+ };
220
+ const fetch = async (part) => {
221
+ let written = () => { };
222
+ const admission = admitted.then(async () => {
223
+ await staging.unqueued();
224
+ written = staging.queued(part.bytes);
225
+ });
226
+ admitted = admission;
227
+ await admission;
228
+ const page = continuing()
229
+ ? await adapter.bootstrap(authorization, {
230
+ locator,
231
+ selection,
232
+ signal: ending.signal,
233
+ pageToken: part.id,
234
+ arriving: (bytes) => {
235
+ partial.set(part.id, Math.min(bytes, part.bytes));
236
+ report();
237
+ },
238
+ })
239
+ : unconfirmed;
240
+ landed({ part, page, written });
241
+ };
242
+ const ask = () => {
243
+ while (!stopped && !halted && flying < PARTS_IN_FLIGHT && next < wanted.length) {
244
+ const part = wanted[next];
245
+ next += 1;
246
+ flying += 1;
247
+ fetch(part).catch((error) => landed({ part, page: unconfirmed, written: () => { }, error }));
248
+ }
249
+ };
250
+ let failed = null;
251
+ ask();
252
+ fetched();
253
+ try {
254
+ for (;;) {
255
+ while (arrivals.length === 0) {
256
+ if (flying === 0 && (halted || next >= wanted.length))
257
+ break;
258
+ await new Promise((wake) => (woken = wake));
259
+ woken = null;
260
+ }
261
+ const one = arrivals.shift();
262
+ if (one === undefined)
263
+ break;
264
+ const { part, page, written, error } = one;
265
+ try {
266
+ if (error !== undefined)
267
+ throw error;
268
+ if (!continuing())
269
+ return unconfirmed;
270
+ if (page.kind !== 'bootstrap') {
271
+ halted = true;
272
+ failed ??= page.kind === 'beyond-horizon' ? unconfirmed : page;
273
+ continue;
274
+ }
275
+ partial.delete(part.id);
276
+ arrived += part.bytes;
277
+ report();
278
+ const kept = await staging.stage({ ...staged, done: { bytes: staged.done.bytes + part.bytes } }, await pageOf({ ...page, roomVersion: head.roomVersion }, part.id), composition);
279
+ if (kept === null)
280
+ return unconfirmed;
281
+ staged = kept;
282
+ }
283
+ finally {
284
+ written();
285
+ }
286
+ }
287
+ }
288
+ finally {
289
+ stopped = true;
290
+ for (const one of arrivals.splice(0))
291
+ one.written();
292
+ }
293
+ if (failed !== null)
294
+ return failed;
295
+ if (staged.key === null) {
296
+ const empty = await staging.stage(staged, { entries: [], folders: [] }, composition);
297
+ if (empty === null)
298
+ return unconfirmed;
299
+ staged = empty;
300
+ }
301
+ return { kind: 'parted', transfer: staged };
302
+ }
303
+ async function installed(transfer) {
304
+ const composition = compositionFor(room, transfer.models, builtIn, typedPaths);
305
+ if (!(await staging.derive(locator, transfer.key, composition)))
306
+ return unconfirmed;
307
+ await staging.turn(locator, 'replaying');
308
+ if (!continuing())
309
+ return unconfirmed;
310
+ const record = {
311
+ locator,
312
+ name: room.name,
313
+ handle: room.handle,
314
+ operations: room.operations,
315
+ replica: room.replica,
316
+ model: transfer.models.collection,
317
+ typedSelection: room.typedSelection ?? null,
318
+ providerOwnedPaths: room.providerOwnedPaths,
319
+ roomVersion: transfer.from,
320
+ transfer: transfer.transfer,
321
+ inventory: transfer.done,
322
+ key: transfer.key,
323
+ };
324
+ const last = transfer.last;
325
+ const refresh = adapter.refresh;
326
+ const reconciled = last === transfer.from &&
327
+ (staging.streamed || adapter.reached(locator, last, room.roomVersion))
328
+ ? { kind: 'still-current' }
329
+ : refresh === undefined
330
+ ? unconfirmed
331
+ : await advancement(refresh, authorization, record, remodel, continuing, await staging.refreshing(locator, record.key, composition));
332
+ if (reconciled.kind === 'advanced') {
333
+ return { kind: 'staged', record: reconciled.record, refreshed: true };
334
+ }
335
+ if (reconciled.kind === 'still-current')
336
+ return { kind: 'staged', record, refreshed: false };
337
+ if (reconciled.kind === 'beyond-horizon')
338
+ return { kind: 'expired', key: record.key };
339
+ return reconciled;
340
+ }
57
341
  }
@@ -0,0 +1,12 @@
1
+ import type { DocumentQuery, GroupQuery } from '@agentshouse/mdmodel';
2
+ import type { MdRuntimeClient } from './client.js';
3
+ import type { DocumentResult, GroupResult, PendingResult } from './query.js';
4
+ type Rows = DocumentResult | GroupResult;
5
+ export type WindowAnswer = Rows | PendingResult;
6
+ export type WindowChain = {
7
+ want(count: number): void;
8
+ close(): void;
9
+ };
10
+ export declare function chainedWindows(runtime: MdRuntimeClient, query: DocumentQuery | GroupQuery, count: number, publish: (answers: readonly (WindowAnswer | null)[], settled: boolean) => void): WindowChain;
11
+ export {};
12
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE7E,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}