@agentshouse/app-bridge 0.1.0-c8d8dc6285bbd → 0.1.0-c8eb04e6114fb

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 (94) hide show
  1. package/README.md +7 -7
  2. package/dist/index.d.ts +910 -18
  3. package/dist/mdmodel/definition.d.ts +1 -1
  4. package/dist/mdmodel/document.d.ts +2 -1
  5. package/dist/mdmodel/event.d.ts +77 -0
  6. package/dist/mdmodel/facts.d.ts +14 -0
  7. package/dist/mdmodel/index.d.ts +19 -6
  8. package/dist/mdmodel/kinds.d.ts +18 -0
  9. package/dist/mdmodel/pattern.d.ts +9 -0
  10. package/dist/mdmodel/query/language.d.ts +253 -0
  11. package/dist/mdmodel/query/match.d.ts +13 -0
  12. package/dist/mdmodel/query/rows.d.ts +31 -0
  13. package/dist/mdmodel/query/sql.d.ts +38 -0
  14. package/dist/mdmodel/reserved.d.ts +4 -0
  15. package/dist/mdmodel/types.d.ts +11 -0
  16. package/dist/mdmodel/validate.d.ts +7 -5
  17. package/dist/mdruntime/actions.d.ts +19 -0
  18. package/dist/mdruntime/adapter.d.ts +107 -71
  19. package/dist/mdruntime/attached-model.d.ts +7 -0
  20. package/dist/mdruntime/bootstrap.d.ts +43 -0
  21. package/dist/mdruntime/cell.d.ts +5 -0
  22. package/dist/mdruntime/chain.d.ts +2 -1
  23. package/dist/mdruntime/change.d.ts +1 -0
  24. package/dist/mdruntime/client.d.ts +25 -10
  25. package/dist/mdruntime/collection.d.ts +7 -4
  26. package/dist/mdruntime/compile.d.ts +6 -6
  27. package/dist/mdruntime/conversation-live.d.ts +135 -0
  28. package/dist/mdruntime/conversation-row.d.ts +32 -0
  29. package/dist/mdruntime/conversation.d.ts +41 -45
  30. package/dist/mdruntime/durability.d.ts +15 -1
  31. package/dist/mdruntime/figures.d.ts +48 -0
  32. package/dist/mdruntime/holdings.d.ts +28 -0
  33. package/dist/mdruntime/identity.d.ts +0 -1
  34. package/dist/mdruntime/install.d.ts +55 -0
  35. package/dist/mdruntime/job.d.ts +32 -0
  36. package/dist/mdruntime/listing.d.ts +52 -0
  37. package/dist/mdruntime/live.d.ts +22 -0
  38. package/dist/mdruntime/log.d.ts +5 -0
  39. package/dist/mdruntime/media.d.ts +7 -0
  40. package/dist/mdruntime/messages.d.ts +27 -3
  41. package/dist/mdruntime/model.d.ts +8 -10
  42. package/dist/mdruntime/observation.d.ts +3 -2
  43. package/dist/mdruntime/outcome.d.ts +17 -6
  44. package/dist/mdruntime/overlay.d.ts +1 -0
  45. package/dist/mdruntime/preparation.d.ts +19 -0
  46. package/dist/mdruntime/query.d.ts +18 -207
  47. package/dist/mdruntime/reach.d.ts +20 -11
  48. package/dist/mdruntime/readiness.d.ts +3 -18
  49. package/dist/mdruntime/reads.d.ts +36 -0
  50. package/dist/mdruntime/recovery.d.ts +1 -0
  51. package/dist/mdruntime/refresh.d.ts +26 -0
  52. package/dist/mdruntime/replica.d.ts +11 -12
  53. package/dist/mdruntime/room-draft.d.ts +21 -5
  54. package/dist/mdruntime/room-drafts.d.ts +23 -0
  55. package/dist/mdruntime/runtime.d.ts +42 -0
  56. package/dist/mdruntime/save.d.ts +7 -1
  57. package/dist/mdruntime/saves.d.ts +69 -0
  58. package/dist/mdruntime/search.d.ts +12 -63
  59. package/dist/mdruntime/seed.d.ts +11 -2
  60. package/dist/mdruntime/socket/admission.d.ts +6 -0
  61. package/dist/mdruntime/socket/answers.d.ts +5 -0
  62. package/dist/mdruntime/socket/lanes.d.ts +19 -0
  63. package/dist/mdruntime/socket/rooms.d.ts +43 -0
  64. package/dist/mdruntime/socket/session.d.ts +38 -0
  65. package/dist/mdruntime/socket.d.ts +69 -0
  66. package/dist/mdruntime/source.d.ts +60 -0
  67. package/dist/mdruntime/status.d.ts +4 -5
  68. package/dist/mdruntime/store/fences.d.ts +15 -0
  69. package/dist/mdruntime/store/installs.d.ts +29 -0
  70. package/dist/mdruntime/store/readiness.d.ts +9 -0
  71. package/dist/mdruntime/store/records.d.ts +211 -0
  72. package/dist/mdruntime/store/room-held.d.ts +7 -0
  73. package/dist/mdruntime/store/space.d.ts +10 -0
  74. package/dist/mdruntime/store/watchers.d.ts +16 -0
  75. package/dist/mdruntime/store/writes.d.ts +23 -0
  76. package/dist/mdruntime/store.d.ts +105 -158
  77. package/dist/mdruntime/stored.d.ts +66 -55
  78. package/dist/mdruntime/surface.d.ts +87 -0
  79. package/dist/mdruntime/tables.d.ts +131 -69
  80. package/dist/mdruntime/tallies.d.ts +17 -0
  81. package/dist/mdruntime/transfer.d.ts +0 -5
  82. package/dist/mdruntime/turn.d.ts +8 -0
  83. package/dist/mdruntime/wire.d.ts +25 -9
  84. package/dist/test-host.d.ts +1 -4
  85. package/dist/test-host.js +2 -28
  86. package/docs/families.md +48 -52
  87. package/package.json +1 -1
  88. package/dist/calls.d.ts +0 -1007
  89. package/dist/calls.js +0 -1
  90. package/dist/mdmodel/condition.d.ts +0 -160
  91. package/dist/mdruntime/connection.d.ts +0 -151
  92. package/dist/mdruntime/file.d.ts +0 -11
  93. package/dist/mdruntime/fulltext.d.ts +0 -26
  94. package/dist/mdruntime/shared.d.ts +0 -15
@@ -0,0 +1,29 @@
1
+ import type { InstallationAmount } from '../readiness.js';
2
+ import type { TransferRecord } from './records.js';
3
+ type OwedIndex = {
4
+ readonly bytes: number;
5
+ readonly text: number;
6
+ };
7
+ export type RoomInstall = {
8
+ readonly transfer: TransferRecord | null;
9
+ readonly arrived: number | null;
10
+ readonly streaming: boolean;
11
+ readonly underived: number;
12
+ readonly unindexed: readonly OwedIndex[];
13
+ readonly startedOver: InstallationAmount | null;
14
+ readonly installing: boolean;
15
+ readonly catching: boolean;
16
+ readonly highest: string | null;
17
+ readonly beyondHorizon: boolean;
18
+ readonly confirmations: number;
19
+ };
20
+ export declare const NO_INSTALL: RoomInstall;
21
+ export type Installs = {
22
+ of(locator: string): RoomInstall;
23
+ change(locator: string, next: (held: RoomInstall) => RoomInstall): void;
24
+ underway(): ReadonlySet<string>;
25
+ transferring(): readonly string[];
26
+ arrivalDue(now: number, everyMs: number): boolean;
27
+ };
28
+ export declare function createInstalls(): Installs;
29
+ export {};
@@ -0,0 +1,9 @@
1
+ export type ReadinessQueue<W> = {
2
+ add(watch: W): () => void;
3
+ held(watch: W): boolean;
4
+ changed(watch: W, reading: string): boolean;
5
+ owe(watches: readonly W[]): void;
6
+ queue(): void;
7
+ close(): void;
8
+ };
9
+ export declare function createReadinessQueue<W>(deliver: (owed: readonly W[]) => Promise<void>, unpublished: (error: unknown) => void): ReadinessQueue<W>;
@@ -0,0 +1,211 @@
1
+ import type { BootstrapInventory, Capability, ListedConversation, Member, ProviderLimit } from '../adapter.js';
2
+ import type { ChangeBatch } from '../change.js';
3
+ import { type Composition } from '../collection.js';
4
+ import type { Plan } from '../query.js';
5
+ import type { ReplicaRecord } from '../replica.js';
6
+ import type { Submission } from '../outcome.js';
7
+ import type { RoomDraftRecord, SavedDraft } from '../room-draft.js';
8
+ import type { ModelState, StoredModel } from '../model.js';
9
+ import type { CommittedWrite, ConversationWrite, HeldConversation, HeldRow, HeldEntry, MessageWindow, QueryAnswer, QueryRoom, Referrer, ReplicaOpened, RoomCommit, RuntimeDatabase, StoredEntry, StoredFile, TypedEntry, View } from '../tables.js';
10
+ import type { JobMarker } from '../job.js';
11
+ export type { ConversationWrite, HeldConversation, MessageWindow } from '../tables.js';
12
+ export type TransferRecord = {
13
+ readonly locator: string;
14
+ readonly transfer: string;
15
+ readonly selection: string;
16
+ readonly from: string;
17
+ readonly last: string;
18
+ readonly done: BootstrapInventory;
19
+ readonly models: {
20
+ readonly collection: ModelState;
21
+ };
22
+ readonly key: number | null;
23
+ };
24
+ export type StoredReplica = Omit<ReplicaRecord, 'model'> & {
25
+ readonly model: StoredModel;
26
+ };
27
+ export type PendingState = {
28
+ readonly drafts: readonly SavedDraft[];
29
+ readonly submission: Submission;
30
+ readonly lost: boolean;
31
+ readonly upload?: unknown;
32
+ };
33
+ export type TargetRecord = {
34
+ established: boolean;
35
+ };
36
+ export type PresentationRecord = {
37
+ app: string;
38
+ value: unknown;
39
+ };
40
+ export type ChatSubmission = {
41
+ readonly operation: string;
42
+ readonly text: string;
43
+ readonly turn: string | null;
44
+ };
45
+ export type ChatDraftRecord = {
46
+ conversation: string;
47
+ text: string;
48
+ revision: string;
49
+ submitted?: readonly ChatSubmission[];
50
+ moves?: readonly string[];
51
+ };
52
+ export type CallRecord = {
53
+ readonly operation: string;
54
+ readonly name: string;
55
+ readonly input: unknown;
56
+ };
57
+ export type AuthoredWrite = {
58
+ locator: string;
59
+ queue?: readonly ChangeBatch[];
60
+ stored?: readonly ChangeBatch[];
61
+ founded?: readonly ChangeBatch[];
62
+ saved?: ReadonlyMap<string, readonly SavedDraft[]>;
63
+ roomDrafts?: readonly RoomDraftRecord[];
64
+ consumedRoomDrafts?: readonly string[];
65
+ };
66
+ export type StagedPage = {
67
+ readonly entries: readonly StoredEntry[];
68
+ readonly folders: readonly string[];
69
+ readonly part?: string;
70
+ };
71
+ export type ResumedTransfer = {
72
+ readonly key: number | null;
73
+ readonly transfer: string;
74
+ readonly staged: readonly string[];
75
+ };
76
+ export type RefreshedPage = StagedPage & {
77
+ readonly removals: readonly string[];
78
+ readonly folderRemovals: readonly string[];
79
+ };
80
+ export type HeldRoom = {
81
+ readonly record: StoredReplica;
82
+ readonly indexed: boolean;
83
+ readonly documents: number;
84
+ };
85
+ export type QueuedChange = {
86
+ readonly batch: ChangeBatch;
87
+ readonly state: PendingState;
88
+ };
89
+ export type HeldWork = {
90
+ readonly room: (HeldRoom & {
91
+ readonly overlaid: ReadonlySet<string>;
92
+ }) | null;
93
+ readonly queue: readonly QueuedChange[];
94
+ };
95
+ export type CoveredRoom = {
96
+ readonly key: number;
97
+ readonly transfer: string;
98
+ readonly roomVersion: string;
99
+ readonly indexed: boolean;
100
+ readonly documents: number;
101
+ readonly bytes: number;
102
+ readonly offline: string;
103
+ };
104
+ export type HeldCover = {
105
+ readonly rooms: ReadonlyMap<string, CoveredRoom>;
106
+ readonly queues: ReadonlyMap<string, readonly string[]>;
107
+ };
108
+ export type HeldStatus = {
109
+ readonly queued: readonly string[];
110
+ readonly lastCompleted: string | null;
111
+ readonly unsent: readonly {
112
+ readonly room: string;
113
+ readonly path: string;
114
+ }[];
115
+ readonly resets: readonly {
116
+ readonly locator: string;
117
+ readonly reset: string;
118
+ }[];
119
+ readonly returned: readonly RoomDraftRecord[];
120
+ };
121
+ export type Facts = {
122
+ readonly lastCompleted: string | null;
123
+ readonly providerLimits: readonly ProviderLimit[];
124
+ readonly capabilities: readonly Capability[];
125
+ readonly member: Member | null;
126
+ readonly targets: Readonly<Record<string, TargetRecord>>;
127
+ readonly conversationList: readonly ListedConversation[] | null;
128
+ readonly conversationCursor: string | null;
129
+ };
130
+ export type Commit = {
131
+ readonly rooms: readonly RoomCommit[];
132
+ readonly writes?: readonly AuthoredWrite[];
133
+ readonly files?: readonly StoredFile[];
134
+ readonly whole?: boolean;
135
+ };
136
+ export type RuntimeStore = {
137
+ opened(): Promise<ReplicaOpened>;
138
+ rooms(locators?: readonly string[]): Promise<readonly HeldRoom[]>;
139
+ room(locator: string): Promise<HeldWork>;
140
+ covering(): Promise<HeldCover>;
141
+ offline(locator: string): Promise<string | null>;
142
+ held(): Promise<{
143
+ readonly held: ReadonlySet<string>;
144
+ readonly staged: ReadonlySet<string>;
145
+ }>;
146
+ status(): Promise<HeldStatus>;
147
+ batch(locator: string, id: string): Promise<ChangeBatch | null>;
148
+ order(locator: string): Promise<readonly string[]>;
149
+ queued(): Promise<readonly string[]>;
150
+ moving(): Promise<{
151
+ readonly queued: ReadonlyMap<string, readonly string[]>;
152
+ readonly moving: readonly (QueuedChange & {
153
+ readonly locator: string;
154
+ })[];
155
+ }>;
156
+ pending(locator: string, id: string): Promise<{
157
+ readonly state: PendingState | undefined;
158
+ readonly room: boolean;
159
+ }>;
160
+ facts(): Promise<Facts>;
161
+ presentation(app: string): Promise<unknown>;
162
+ demote(): Promise<void>;
163
+ query(plan: Plan, rooms: readonly QueryRoom[], budget: number | null): Promise<QueryAnswer>;
164
+ changes(keys: readonly number[]): number;
165
+ entries(key: number, view: View, paths: readonly string[]): Promise<readonly HeldEntry[]>;
166
+ typed(key: number, view: View, paths: readonly string[]): Promise<readonly TypedEntry[]>;
167
+ referrers(key: number, view: View, targets: readonly string[]): Promise<readonly Referrer[]>;
168
+ folders(key: number, paths: readonly string[]): Promise<readonly string[]>;
169
+ typedWithin(key: number, view: View, roots: readonly string[], within: boolean): Promise<boolean>;
170
+ stage(record: TransferRecord, composition: Composition, page: StagedPage): Promise<number | null>;
171
+ resume(record: TransferRecord, composition: Composition, parts: readonly string[], published: number | null): Promise<ResumedTransfer | null>;
172
+ refresh(key: number, composition: Composition, page: RefreshedPage): Promise<void>;
173
+ unrefresh(key: number): Promise<void>;
174
+ commit(commit: Commit): Promise<CommittedWrite>;
175
+ fence(locators: readonly string[]): Promise<void>;
176
+ erase(locator: string | null, limit: number): Promise<boolean>;
177
+ abandon(locator: string): Promise<void>;
178
+ unfence(locators: readonly string[]): Promise<ReadonlySet<string>>;
179
+ release(key: number): Promise<void>;
180
+ rederive(key: number, composition: Composition, bytes: number, ms: number, floor: number): Promise<{
181
+ readonly done: boolean;
182
+ readonly text: number;
183
+ }>;
184
+ fact(name: string, value: unknown): Promise<void>;
185
+ submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
186
+ keepUpload(locator: string, id: string, upload: unknown): Promise<void>;
187
+ roomDrafts(locator?: string, paths?: readonly string[]): Promise<readonly RoomDraftRecord[]>;
188
+ present(record: PresentationRecord): Promise<void>;
189
+ conversations(conversations?: readonly string[]): Promise<readonly HeldConversation[]>;
190
+ keepMessages(write: ConversationWrite): Promise<void>;
191
+ messageWindow(conversation: string, limit: number, before: readonly [string, string] | null, phrase?: string | null): Promise<MessageWindow>;
192
+ messageCount(conversation: string, phrase?: string | null): Promise<number>;
193
+ turnArrived(conversation: string, turn: string): Promise<boolean>;
194
+ conversationRows(conversations: readonly string[]): Promise<readonly HeldRow[]>;
195
+ jobMarkers(conversation: string): Promise<readonly JobMarker[]>;
196
+ dropConversations(conversations: readonly string[]): Promise<void>;
197
+ chatDrafts(): Promise<readonly ChatDraftRecord[]>;
198
+ chatDraft(conversation: string): Promise<ChatDraftRecord | null>;
199
+ keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
200
+ dropChatDraft(conversation: string): Promise<void>;
201
+ calls(): Promise<readonly CallRecord[]>;
202
+ keepCall(record: CallRecord): Promise<void>;
203
+ dropCall(operation: string): Promise<void>;
204
+ keepRoomDraft(record: RoomDraftRecord, files: readonly StoredFile[]): Promise<void>;
205
+ discardRoomDraft(locator: string, path: string): Promise<void>;
206
+ fences(): Promise<readonly string[]>;
207
+ generation(): Promise<string | null>;
208
+ rememberGeneration(value: string): Promise<void>;
209
+ file(key: string, type: string): Promise<Blob>;
210
+ };
211
+ export declare function openRuntimeStore(database: RuntimeDatabase): RuntimeStore;
@@ -0,0 +1,7 @@
1
+ export type RoomHeld<T> = {
2
+ of(locator: string, key: string): T | undefined;
3
+ hold(locator: string, key: string, value: T): void;
4
+ drop(locator: string, key: string): void;
5
+ forget(locator: string): void;
6
+ };
7
+ export declare function createRoomHeld<T>(): RoomHeld<T>;
@@ -0,0 +1,10 @@
1
+ import type { RuntimeDatabase } from '../tables.js';
2
+ export type Space = {
3
+ full(): boolean;
4
+ fill(): boolean;
5
+ probing(): boolean;
6
+ probeEachMinute(): void;
7
+ probe(): Promise<void>;
8
+ stop(): void;
9
+ };
10
+ export declare function createSpace(database: RuntimeDatabase, freed: () => void): Space;
@@ -0,0 +1,16 @@
1
+ export type Watcher = {
2
+ held(): boolean;
3
+ stop(): void;
4
+ answer(value: unknown): void;
5
+ };
6
+ export type Watching = 'all' | 'waiting' | 'ready';
7
+ type Watchers = {
8
+ publication(work: () => Promise<void>): Promise<void>;
9
+ owing<T>(topic: string, add: (owed: T | undefined) => T, work: (owed: T) => Promise<void>): Promise<void>;
10
+ watch(topic: string, notify: (value: unknown) => void): Watcher;
11
+ watching(topic: string, which?: Watching): readonly Watcher[];
12
+ tell(topic: string, value: unknown): void;
13
+ close(): void;
14
+ };
15
+ export declare function createWatchers(unpublished: (error: unknown) => void): Watchers;
16
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { Composition } from '../collection.js';
2
+ import type { RefreshedPage, RuntimeStore } from './records.js';
3
+ export type InstallHold = {
4
+ take(): void;
5
+ release(): void;
6
+ };
7
+ type Writes = {
8
+ exclusive<T>(work: () => Promise<T>): Promise<T>;
9
+ gathered<I, T>(key: string, input: I, merge: (earlier: I, later: I) => I | null, work: (input: I) => Promise<T>): Promise<T>;
10
+ written(): Promise<unknown>;
11
+ startingWrite<T>(work: () => Promise<T>): Promise<T>;
12
+ finishingWrite<T>(work: () => Promise<T>): Promise<T>;
13
+ ahead<T>(work: (hold: InstallHold) => Promise<T>): Promise<T>;
14
+ rederive(local: RuntimeStore, key: number, composition: Composition): Promise<{
15
+ readonly done: boolean;
16
+ readonly text: number;
17
+ }>;
18
+ refreshPage(local: RuntimeStore, key: number, composition: Composition, page: RefreshedPage): Promise<void>;
19
+ stageBytes(): number;
20
+ deriveBytes(): number;
21
+ };
22
+ export declare function createWrites(): Writes;
23
+ export {};
@@ -1,169 +1,116 @@
1
- import type { BootstrapInventory, Capability, KeptReceipt, Member, ProviderLimit } from './adapter.js';
1
+ import type { TypedPath } from './adapter.js';
2
+ import { schemaTypes } from './attached-model.js';
3
+ import { type Cell } from './cell.js';
2
4
  import type { ChangeBatch } from './change.js';
5
+ import type { ChangeSet } from './change-set.js';
3
6
  import type { Composition } from './collection.js';
4
- import type { Plan } from './query.js';
5
- import type { ReplicaRecord } from './replica.js';
6
- import type { Submission } from './outcome.js';
7
- import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
7
+ import type { ReadinessWatch } from './preparation.js';
8
+ import type { Persistence } from './readiness.js';
9
+ import type { Listing } from './listing.js';
10
+ import type { Seeded } from './seed.js';
8
11
  import type { ModelState } from './model.js';
9
- import type { SearchWindow } from './search.js';
10
- import type { CommittedWrite, ConversationWrite, CountedRoom, HeldConversation, HeldEntry, MessageWindow, QueryAnswer, QueryRoom, Referrer, RoomCommit, RuntimeDatabase, SearchAsk, StoredEntry, StoredFile, TypedEntry, View, Walked } from './tables.js';
11
- export type { ConversationWrite, HeldConversation, MessageWindow } from './tables.js';
12
- export type TransferWriting = {
13
- readonly token: string | null;
14
- readonly written: number;
12
+ import { type OpenedFiles } from './opened.js';
13
+ import { type HeldReplica, type ReplicaRecord } from './replica.js';
14
+ import type { RoomDraftRecord } from './room-draft.js';
15
+ import { type SyncStatus } from './status.js';
16
+ import type { RuntimeDatabase } from './tables.js';
17
+ import { type Fences } from './store/fences.js';
18
+ import { type Installs } from './store/installs.js';
19
+ import { type HeldCover, type PendingState, type RuntimeStore } from './store/records.js';
20
+ import { type ReadinessQueue } from './store/readiness.js';
21
+ import { type RoomHeld } from './store/room-held.js';
22
+ import { type Space } from './store/space.js';
23
+ import { type Watcher, type Watching } from './store/watchers.js';
24
+ import { createWrites, type InstallHold } from './store/writes.js';
25
+ export { NO_INSTALL, type RoomInstall } from './store/installs.js';
26
+ export type { AuthoredWrite, ChatDraftRecord, ChatSubmission, CoveredRoom, Facts, HeldConversation, HeldCover, PendingState, RefreshedPage, RuntimeStore, StagedPage, TransferRecord, } from './store/records.js';
27
+ export type { InstallHold } from './store/writes.js';
28
+ export type { CommittedWrite, QueryRoom, RoomCommit, RuntimeDatabase, StoredEntry, StoredFile, View, } from './tables.js';
29
+ export type Stored = {
30
+ readonly record: ReplicaRecord;
31
+ readonly indexed: boolean;
32
+ readonly documents: number;
15
33
  };
16
- export type TransferRecord = {
17
- readonly locator: string;
18
- readonly transfer: string;
19
- readonly selection: string;
20
- readonly from: string;
21
- readonly last: string;
22
- readonly pageToken: string | null;
23
- readonly writing: TransferWriting | null;
24
- readonly inventory: BootstrapInventory | null;
25
- readonly done: BootstrapInventory;
26
- readonly models: {
27
- readonly collection: ModelState;
28
- readonly selection: ModelState;
29
- };
30
- readonly key: number | null;
34
+ export type Held = HeldReplica & {
35
+ readonly states: ReadonlyMap<string, PendingState>;
31
36
  };
32
- export type PendingState = {
33
- readonly drafts: readonly SavedDraft[];
34
- readonly submission: Submission;
35
- readonly lost: boolean;
36
- readonly upload?: unknown;
37
- readonly accepted?: string;
37
+ export type Work = {
38
+ readonly replica: Held | undefined;
39
+ readonly queue: readonly ChangeBatch[];
40
+ readonly states: ReadonlyMap<string, PendingState>;
38
41
  };
39
- export type TargetRecord = {
40
- established: boolean;
42
+ type LandedAhead = Readonly<Record<string, string | undefined>>;
43
+ type AttachedFile = {
44
+ readonly revision: string;
45
+ readonly mediaType: string;
41
46
  };
42
- export type QueueRecord = {
43
- locator: string;
44
- pending: readonly {
45
- batch: ChangeBatch;
46
- state: PendingState;
47
- }[];
47
+ type Seeds = {
48
+ of(key: string): Seeded | undefined;
49
+ keep(key: string, seed: Seeded): void;
50
+ drop(key: string): void;
48
51
  };
49
- export type PresentationRecord = {
50
- app: string;
51
- value: unknown;
52
+ type Device = {
53
+ readonly persistence: Persistence;
54
+ readonly storageLoss: string | null;
55
+ readonly heldWhenOpened: boolean;
56
+ readonly preparing: boolean;
57
+ readonly sweeping: boolean;
58
+ readonly unpreparedDemand: ReadonlySet<string>;
59
+ readonly establishing: ReadonlySet<string>;
60
+ readonly status: SyncStatus;
61
+ readonly roomsShown: Listing | null;
52
62
  };
53
- export type ChatSubmission = {
54
- readonly operation: string;
55
- readonly text: string;
56
- readonly turn: string | null;
63
+ type StoreOptions = {
64
+ readonly database: RuntimeDatabase;
65
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
66
+ readonly builtIn: ModelState;
67
+ readonly typedPaths: readonly TypedPath[];
68
+ readonly persistence: Persistence;
69
+ opening(records: RuntimeStore): Promise<RuntimeStore>;
70
+ unpublished(error: unknown): void;
71
+ changed(set: ChangeSet): Promise<void>;
72
+ deliverReadiness(owed: readonly ReadinessWatch[]): Promise<void>;
73
+ spaceFreed(): void;
57
74
  };
58
- export type ChatDraftRecord = {
59
- conversation: string;
60
- text: string;
61
- revision: string;
62
- submitted?: readonly ChatSubmission[];
63
- moves?: readonly string[];
75
+ export type Store = {
76
+ readonly device: Cell<Device>;
77
+ readonly space: Space;
78
+ readonly readiness: ReadinessQueue<ReadinessWatch>;
79
+ ask: RuntimeDatabase['ask'];
80
+ changed(set: ChangeSet): Promise<void>;
81
+ open(): Promise<RuntimeStore>;
82
+ durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
83
+ exclusive<T>(work: () => Promise<T>): Promise<T>;
84
+ gathered<I, T>(key: string, input: I, merge: (earlier: I, later: I) => I | null, work: (input: I) => Promise<T>): Promise<T>;
85
+ written(): Promise<unknown>;
86
+ startingWrite<T>(work: () => Promise<T>): Promise<T>;
87
+ finishingWrite<T>(work: () => Promise<T>): Promise<T>;
88
+ ahead<T>(work: (hold: InstallHold) => Promise<T>): Promise<T>;
89
+ rederive: ReturnType<typeof createWrites>['rederive'];
90
+ refreshPage: ReturnType<typeof createWrites>['refreshPage'];
91
+ stageBytes(): number;
92
+ deriveBytes(): number;
93
+ rooms(locators?: readonly string[]): Promise<ReadonlyMap<string, Stored>>;
94
+ record(locator: string): Promise<ReplicaRecord | undefined>;
95
+ work(locator: string): Promise<Work>;
96
+ replica(locator: string): Promise<Held | undefined>;
97
+ covering(): Promise<HeldCover>;
98
+ drafts(locator?: string, paths?: readonly string[]): Promise<readonly RoomDraftRecord[]>;
99
+ draft(locator: string, path: string): Promise<RoomDraftRecord | undefined>;
100
+ composed(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>): Composition;
101
+ publication(work: () => Promise<void>): Promise<void>;
102
+ owing<T>(topic: string, add: (owed: T | undefined) => T, work: (owed: T) => Promise<void>): Promise<void>;
103
+ watch(topic: string, notify: (value: unknown) => void): Watcher;
104
+ watching(topic: string, which?: Watching): readonly Watcher[];
105
+ tell(topic: string, value: unknown): void;
106
+ readonly fences: Fences;
107
+ readonly installs: Installs;
108
+ readonly seeds: Seeds;
109
+ readonly landed: RoomHeld<LandedAhead>;
110
+ readonly attached: RoomHeld<AttachedFile>;
111
+ readonly opened: OpenedFiles;
112
+ part(file: string, part: number): Promise<Uint8Array | null>;
113
+ forget(locator: string): void;
114
+ close(): void;
64
115
  };
65
- export type CallRecord = {
66
- readonly operation: string;
67
- readonly name: string;
68
- readonly input: unknown;
69
- };
70
- export type AuthoredWrite = {
71
- locator: string;
72
- queue?: readonly ChangeBatch[];
73
- founded?: readonly ChangeBatch[];
74
- saved?: ReadonlyMap<string, readonly SavedDraft[]>;
75
- roomDrafts?: readonly RoomDraftRecord[];
76
- consumedRoomDrafts?: readonly string[];
77
- accepted?: readonly {
78
- readonly id: string;
79
- readonly roomVersion: string;
80
- }[];
81
- };
82
- export type StagedPage = {
83
- readonly entries: readonly StoredEntry[];
84
- readonly folders: readonly string[];
85
- };
86
- export type RefreshedPage = StagedPage & {
87
- readonly removals: readonly string[];
88
- readonly folderRemovals: readonly string[];
89
- };
90
- export type Opened = {
91
- readonly rooms: ReadonlyMap<string, ReplicaRecord>;
92
- readonly transfers: ReadonlyMap<string, TransferRecord>;
93
- readonly unindexed: ReadonlySet<number>;
94
- readonly overlaid: ReadonlyMap<number, ReadonlySet<string>>;
95
- readonly erasing: boolean;
96
- readonly orphans: readonly number[];
97
- readonly lastCompleted: string | null;
98
- readonly providerLimits: readonly ProviderLimit[];
99
- readonly capabilities: readonly Capability[];
100
- readonly member: Member | null;
101
- readonly targets: Readonly<Record<string, TargetRecord>>;
102
- readonly presentation: readonly PresentationRecord[];
103
- };
104
- export type Commit = {
105
- readonly rooms: readonly RoomCommit[];
106
- readonly writes?: readonly AuthoredWrite[];
107
- readonly files?: readonly StoredFile[];
108
- readonly whole?: boolean;
109
- readonly discards?: readonly string[];
110
- };
111
- export type RuntimeStore = {
112
- opened(): Promise<Opened>;
113
- counts(rooms: readonly CountedRoom[]): Promise<readonly number[]>;
114
- query(plan: Plan, rooms: readonly QueryRoom[], budget: number | null): Promise<QueryAnswer>;
115
- changes(keys: readonly number[]): number;
116
- entries(key: number, view: View, paths: readonly string[]): Promise<readonly HeldEntry[]>;
117
- typed(key: number, view: View, paths: readonly string[]): Promise<readonly TypedEntry[]>;
118
- referrers(key: number, view: View, targets: readonly string[], kinds: readonly string[]): Promise<readonly Referrer[]>;
119
- walk(key: number, view: View, after: string | null, bytes: number): Promise<Walked>;
120
- files(key: number, view: View, after: string | null, limit: number): Promise<readonly {
121
- readonly path: string;
122
- readonly revision: string;
123
- }[]>;
124
- typedWithin(key: number, view: View, roots: readonly string[], within: boolean): Promise<boolean>;
125
- search(ask: SearchAsk): Promise<SearchWindow>;
126
- stage(record: TransferRecord, composition: Composition, page: StagedPage, written?: string): Promise<number | null>;
127
- transferPart(locator: string, token: string): Promise<Uint8Array | null>;
128
- keepPart(locator: string, token: string, part: Uint8Array): Promise<void>;
129
- refresh(key: number, page: RefreshedPage): Promise<void>;
130
- unrefresh(key: number): Promise<void>;
131
- commit(commit: Commit): Promise<CommittedWrite>;
132
- fence(locators: readonly string[]): Promise<void>;
133
- erase(locator: string | null, limit: number): Promise<boolean>;
134
- abandon(locator: string, kept?: boolean): Promise<number | null>;
135
- release(key: number): Promise<void>;
136
- rederive(key: number, limit: number): Promise<boolean>;
137
- fact(name: string, value: unknown): Promise<void>;
138
- queues(): Promise<readonly QueueRecord[]>;
139
- submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
140
- keepUpload(locator: string, id: string, upload: unknown): Promise<void>;
141
- roomDrafts(): Promise<readonly RoomDraftRecord[]>;
142
- present(record: PresentationRecord): Promise<void>;
143
- conversations(): Promise<readonly HeldConversation[]>;
144
- keepMessages(write: ConversationWrite): Promise<void>;
145
- messageWindow(conversation: string, limit: number, before: readonly [string, string] | null): Promise<MessageWindow>;
146
- messageCount(conversation: string): Promise<number>;
147
- turnArrived(conversation: string, turn: string): Promise<boolean>;
148
- dropConversations(conversations: readonly string[]): Promise<void>;
149
- chatDrafts(): Promise<readonly ChatDraftRecord[]>;
150
- keepChatDrafts(records: readonly ChatDraftRecord[]): Promise<void>;
151
- dropChatDraft(conversation: string): Promise<void>;
152
- calls(): Promise<readonly CallRecord[]>;
153
- keepCall(record: CallRecord): Promise<void>;
154
- dropCall(operation: string): Promise<void>;
155
- keepRoomDraft(record: RoomDraftRecord, files: readonly StoredFile[]): Promise<void>;
156
- discardRoomDraft(locator: string, path: string): Promise<void>;
157
- fences(): Promise<readonly string[]>;
158
- receivedHeads(): Promise<readonly KeptReceipt[]>;
159
- receivedParts(key: string, count: number): Promise<readonly unknown[]>;
160
- keepReceived(key: string, head: unknown, part?: {
161
- index: number;
162
- value: unknown;
163
- }): Promise<void>;
164
- dropReceived(keys: readonly string[]): Promise<void>;
165
- generation(): Promise<string | null>;
166
- rememberGeneration(value: string): Promise<void>;
167
- file(key: string, type: string): Promise<Blob>;
168
- };
169
- export declare function openRuntimeStore(fenced: (locator: string) => boolean, authored: RuntimeDatabase): RuntimeStore;
116
+ export declare function createStore(options: StoreOptions): Store;