@agentshouse/app-bridge 0.1.0-c58a055eeaa71 → 0.1.0-c70153aac6ee3

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 (55) hide show
  1. package/README.md +3 -1
  2. package/dist/calls.d.ts +117 -0
  3. package/dist/calls.js +1 -0
  4. package/dist/index.d.ts +23 -10
  5. package/dist/mdmodel/blocks.d.ts +10 -0
  6. package/dist/mdmodel/condition.d.ts +149 -0
  7. package/dist/mdmodel/definition.d.ts +65 -0
  8. package/dist/mdmodel/divide.d.ts +2 -0
  9. package/dist/mdmodel/document.d.ts +15 -0
  10. package/dist/mdmodel/fields.d.ts +5 -0
  11. package/dist/mdmodel/index.d.ts +18 -0
  12. package/dist/mdmodel/paths.d.ts +17 -0
  13. package/dist/mdmodel/profile.d.ts +5 -0
  14. package/dist/mdmodel/project.d.ts +20 -0
  15. package/dist/mdmodel/references.d.ts +3 -0
  16. package/dist/mdmodel/types.d.ts +143 -0
  17. package/dist/mdmodel/validate.d.ts +7 -0
  18. package/dist/mdmodel/version.d.ts +1 -0
  19. package/dist/mdmodel/yaml.d.ts +55 -0
  20. package/dist/mdruntime/acquisition.d.ts +13 -0
  21. package/dist/mdruntime/adapter.d.ts +477 -0
  22. package/dist/mdruntime/binary.d.ts +22 -0
  23. package/dist/mdruntime/change-set.d.ts +34 -0
  24. package/dist/mdruntime/change.d.ts +88 -0
  25. package/dist/mdruntime/client.d.ts +81 -0
  26. package/dist/mdruntime/collection.d.ts +38 -0
  27. package/dist/mdruntime/connection.d.ts +138 -0
  28. package/dist/mdruntime/conversation.d.ts +103 -0
  29. package/dist/mdruntime/durability.d.ts +14 -0
  30. package/dist/mdruntime/failure.d.ts +12 -0
  31. package/dist/mdruntime/file.d.ts +19 -0
  32. package/dist/mdruntime/model.d.ts +56 -0
  33. package/dist/mdruntime/observation.d.ts +29 -0
  34. package/dist/mdruntime/open.d.ts +1 -0
  35. package/dist/mdruntime/outcome.d.ts +46 -0
  36. package/dist/mdruntime/overlay.d.ts +26 -0
  37. package/dist/mdruntime/query.d.ts +246 -0
  38. package/dist/mdruntime/reach.d.ts +45 -0
  39. package/dist/mdruntime/readiness.d.ts +52 -0
  40. package/dist/mdruntime/recovery.d.ts +24 -0
  41. package/dist/mdruntime/replica.d.ts +45 -0
  42. package/dist/mdruntime/room-draft.d.ts +143 -0
  43. package/dist/mdruntime/rows.d.ts +36 -0
  44. package/dist/mdruntime/save.d.ts +63 -0
  45. package/dist/mdruntime/search.d.ts +83 -0
  46. package/dist/mdruntime/shared.d.ts +10 -0
  47. package/dist/mdruntime/status.d.ts +26 -0
  48. package/dist/mdruntime/store.d.ts +159 -0
  49. package/dist/mdruntime/transfer.d.ts +9 -0
  50. package/dist/mdruntime/turn.d.ts +6 -0
  51. package/dist/mdruntime/wire.d.ts +104 -0
  52. package/dist/test-host.d.ts +5 -5
  53. package/dist/test-host.js +56 -21
  54. package/docs/families.md +40 -2
  55. package/package.json +1 -4
@@ -0,0 +1,246 @@
1
+ import { type Definition } from '../mdmodel/index.js';
2
+ import type { HeadChange } from './adapter.js';
3
+ import type { BinaryFileRecord } from './binary.js';
4
+ export type Value = string | number | boolean | null;
5
+ export type Predicate = Value | {
6
+ $eq: Value;
7
+ } | {
8
+ $ne: Value;
9
+ } | {
10
+ $in: readonly Value[];
11
+ } | {
12
+ $nin: readonly Value[];
13
+ } | {
14
+ $gt?: Value;
15
+ $gte?: Value;
16
+ $lt?: Value;
17
+ $lte?: Value;
18
+ } | {
19
+ $all: readonly Value[];
20
+ } | {
21
+ $size: number;
22
+ } | {
23
+ $exists: boolean;
24
+ };
25
+ export type Where = {
26
+ $and?: readonly Where[];
27
+ $or?: readonly Where[];
28
+ [field: string]: Predicate | readonly Where[] | undefined;
29
+ };
30
+ export type Related = {
31
+ types?: readonly string[];
32
+ where?: Where;
33
+ pathPrefix?: string;
34
+ };
35
+ export type Filter = {
36
+ rooms?: readonly string[];
37
+ types?: readonly string[];
38
+ where?: Where;
39
+ pathPrefix?: string;
40
+ hop?: Related & {
41
+ field: string;
42
+ };
43
+ backlinks?: Related & {
44
+ field?: string;
45
+ };
46
+ };
47
+ export type Key = 'room' | 'path' | 'type' | {
48
+ field: string;
49
+ };
50
+ export type Select = 'all' | {
51
+ fields?: 'all' | readonly string[];
52
+ sections?: 'all' | readonly string[];
53
+ preamble?: true;
54
+ markdown?: true;
55
+ backlinks?: true;
56
+ change?: true;
57
+ };
58
+ export type OrderOptions = {
59
+ nulls?: 'first' | 'last';
60
+ stringSort?: 'lexical' | 'locale';
61
+ locale?: string;
62
+ localeOptions?: Readonly<Record<string, unknown>>;
63
+ };
64
+ export type Direction = 'asc' | 'desc';
65
+ export type DocumentQuery = Filter & {
66
+ select: Select;
67
+ orderBy?: readonly ({
68
+ by: Key;
69
+ direction?: Direction;
70
+ } & OrderOptions)[];
71
+ limit?: number;
72
+ };
73
+ export type GroupQuery = Filter & {
74
+ groupBy: readonly Exclude<Key, 'path'>[];
75
+ orderBy?: readonly {
76
+ by: 'count' | Exclude<Key, 'path'>;
77
+ direction?: Direction;
78
+ }[];
79
+ limit?: number;
80
+ };
81
+ export type LocalQuery = DocumentQuery | GroupQuery;
82
+ export type Backlink = {
83
+ path: string;
84
+ type: string;
85
+ field: string;
86
+ };
87
+ export type QueryDocument = {
88
+ room: string;
89
+ path: string;
90
+ type?: string;
91
+ fields?: Readonly<Record<string, unknown>>;
92
+ sections?: Readonly<Record<string, string>>;
93
+ preamble?: string;
94
+ markdown?: string;
95
+ backlinks?: readonly Backlink[];
96
+ change?: HeadChange | null;
97
+ binaryFile?: BinaryFileRecord;
98
+ };
99
+ export type QueryGroup = {
100
+ key: readonly unknown[];
101
+ count: number;
102
+ };
103
+ export type CoveredRoom = {
104
+ room: string;
105
+ generation: string;
106
+ current: boolean;
107
+ };
108
+ export type QueryCoverage = {
109
+ rooms: readonly CoveredRoom[];
110
+ indexes: readonly string[];
111
+ overlay: readonly string[];
112
+ };
113
+ export type Awaits = 'acquisition' | 'preparation' | 'index';
114
+ export type PendingRoom = {
115
+ room: string;
116
+ awaits: Awaits;
117
+ };
118
+ export type PendingResult = {
119
+ pending: readonly PendingRoom[];
120
+ };
121
+ export type DocumentRows = {
122
+ documents: readonly QueryDocument[];
123
+ };
124
+ export type GroupRows = {
125
+ groups: readonly QueryGroup[];
126
+ };
127
+ export type QueryRows = DocumentRows | GroupRows;
128
+ export type DocumentResult = DocumentRows & {
129
+ coverage: QueryCoverage;
130
+ };
131
+ export type GroupResult = GroupRows & {
132
+ coverage: QueryCoverage;
133
+ };
134
+ export type QueryResult = DocumentResult | GroupResult | PendingResult;
135
+ export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
136
+ export type RoomFacts = {
137
+ locator: string;
138
+ available: boolean;
139
+ types: readonly Definition[];
140
+ };
141
+ export type HeldRooms = {
142
+ listed: boolean;
143
+ rooms: readonly RoomFacts[];
144
+ };
145
+ export type Test = {
146
+ op: 'eq';
147
+ value: Value;
148
+ } | {
149
+ op: 'ne';
150
+ value: Value;
151
+ } | {
152
+ op: 'in';
153
+ values: readonly Value[];
154
+ } | {
155
+ op: 'nin';
156
+ values: readonly Value[];
157
+ } | {
158
+ op: 'range';
159
+ bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
160
+ } | {
161
+ op: 'all';
162
+ values: readonly Value[];
163
+ } | {
164
+ op: 'size';
165
+ size: number;
166
+ } | {
167
+ op: 'exists';
168
+ exists: boolean;
169
+ };
170
+ export type Condition = {
171
+ every: readonly Condition[];
172
+ } | {
173
+ some: readonly Condition[];
174
+ } | {
175
+ field: string;
176
+ test: Test;
177
+ };
178
+ export type Scope = {
179
+ types: readonly string[] | null;
180
+ where: Condition | null;
181
+ pathPrefix: string | null;
182
+ };
183
+ export type KeyPlan = {
184
+ of: 'room';
185
+ } | {
186
+ of: 'path';
187
+ } | {
188
+ of: 'type';
189
+ } | {
190
+ of: 'field';
191
+ field: string;
192
+ };
193
+ export type DocumentShape = {
194
+ kind: 'documents';
195
+ fields: 'all' | readonly string[] | null;
196
+ sections: 'all' | readonly string[] | null;
197
+ preamble: boolean;
198
+ markdown: boolean;
199
+ backlinks: boolean;
200
+ change: boolean;
201
+ orderBy: readonly {
202
+ key: KeyPlan;
203
+ options: OrderOptions & {
204
+ direction: Direction;
205
+ };
206
+ }[];
207
+ };
208
+ export type GroupShape = {
209
+ kind: 'groups';
210
+ groupBy: readonly KeyPlan[];
211
+ orderBy: readonly {
212
+ by: 'count' | number;
213
+ direction: Direction;
214
+ }[];
215
+ };
216
+ export type PlanReach = {
217
+ rooms: readonly string[];
218
+ documents: readonly string[];
219
+ };
220
+ export type Plan = {
221
+ rooms: readonly string[] | null;
222
+ reach: PlanReach | null;
223
+ root: Scope;
224
+ hop: (Scope & {
225
+ field: string;
226
+ }) | null;
227
+ backlinks: (Scope & {
228
+ field: string | null;
229
+ }) | null;
230
+ shape: DocumentShape | GroupShape;
231
+ limit: number | null;
232
+ };
233
+ export declare class QueryError extends Error {
234
+ readonly code: QueryErrorCode;
235
+ readonly retryable = false;
236
+ constructor(code: QueryErrorCode, at: string, problem: string);
237
+ }
238
+ type Entries = Readonly<Record<string, unknown>>;
239
+ export declare function invalid(at: string, problem: string): never;
240
+ export declare function plain(value: unknown): value is Entries;
241
+ export declare function known(value: Entries, allowed: readonly string[], at: string): void;
242
+ export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
243
+ export declare function limitOf(input: unknown): number | null;
244
+ export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
245
+ export declare function identityOf(plan: Plan): string;
246
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { ReferrerScope } from './adapter.js';
2
+ import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
3
+ import type { Plan, PlanReach, QueryResult } from './query.js';
4
+ import type { Readiness } from './readiness.js';
5
+ import type { SearchResult } from './search.js';
6
+ export type ReachedDocument = {
7
+ readonly room: string;
8
+ readonly path: string;
9
+ };
10
+ export type PortReach = {
11
+ readonly rooms: readonly string[];
12
+ readonly documents: readonly ReachedDocument[];
13
+ readonly conversations: boolean;
14
+ };
15
+ export type Deliver = (message: unknown) => void;
16
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
17
+ export type RuntimeView = {
18
+ md: MdRuntime;
19
+ watch: Watch;
20
+ };
21
+ export type NarrowedView = RuntimeView & {
22
+ narrow(reach: PortReach | null): void;
23
+ facts(port: ReadinessPort): void;
24
+ };
25
+ export type Reachable = RuntimeView & {
26
+ plan(input: unknown, reach: PortReach | null): Plan;
27
+ query(plan: Plan): Promise<QueryResult>;
28
+ watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
29
+ search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
30
+ searching(target: string): void;
31
+ watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
32
+ referrerScope(referrer: unknown): ReferrerScope | null;
33
+ };
34
+ export declare function holds(reach: PortReach | null, room: string): boolean;
35
+ export declare function governs(reach: PortReach | null, room: {
36
+ readonly locator: string;
37
+ readonly typedSelection: {
38
+ roots: readonly string[];
39
+ } | null;
40
+ }): {
41
+ readonly collection: boolean;
42
+ readonly selection: boolean;
43
+ };
44
+ export declare function planReach(reach: PortReach | null): PlanReach | null;
45
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
@@ -0,0 +1,52 @@
1
+ import type { Open } from './open.js';
2
+ export type CodeAvailability = Open<'stored' | 'absent'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'indexing' | 'refused' | 'unadmitted'>;
4
+ export type RoomCoverage = {
5
+ readonly room: string;
6
+ readonly state: RoomPreparation;
7
+ };
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'indexing' | 'undeclared'>;
9
+ export type SearchObligation = Open<'required' | 'unused'>;
10
+ export type TargetCoverage = {
11
+ readonly complete: boolean;
12
+ readonly listed: boolean;
13
+ readonly rooms: readonly RoomCoverage[];
14
+ readonly conversations: ConversationCoverage;
15
+ readonly search: SearchObligation;
16
+ };
17
+ export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
18
+ export type Durability = Open<'persistent' | 'best-effort'>;
19
+ export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
20
+ export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
21
+ export type CapacityCause = {
22
+ readonly cause: Open<'insufficient-space' | 'quota-exceeded'>;
23
+ readonly needed: number | null;
24
+ readonly available: number | null;
25
+ };
26
+ export type RefusedRoom = {
27
+ readonly room: string;
28
+ readonly file: string;
29
+ readonly rule: string;
30
+ readonly location: string | null;
31
+ };
32
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'refused' | 'ready' | 'lost'>;
33
+ export type Readiness = {
34
+ readonly status: ReadinessStatus;
35
+ readonly ready: boolean;
36
+ readonly usable: boolean;
37
+ readonly code: CodeAvailability;
38
+ readonly coverage: TargetCoverage;
39
+ readonly durability: Durability;
40
+ readonly persistence: Persistence;
41
+ readonly connection: ConnectionAvailability;
42
+ readonly house: HouseOutcome;
43
+ readonly capacity: CapacityCause | null;
44
+ readonly refused: readonly RefusedRoom[];
45
+ readonly lost: boolean;
46
+ };
47
+ export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
48
+ readonly coverage: Omit<TargetCoverage, 'complete'>;
49
+ readonly established: boolean;
50
+ };
51
+ export declare const SETTLED_ROOMS: ReadonlySet<string>;
52
+ export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -0,0 +1,24 @@
1
+ export type Attempted = 'done' | 'again' | {
2
+ readonly at: number;
3
+ };
4
+ export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
5
+ export type AttemptOptions = {
6
+ readonly at?: number;
7
+ readonly again?: boolean;
8
+ };
9
+ export type RecoveryOptions = {
10
+ readonly firstMs?: number;
11
+ readonly ceilingMs?: number;
12
+ readonly attempts?: number;
13
+ readonly inFlight?: number;
14
+ };
15
+ export type Recovery = {
16
+ attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
17
+ pending(intent: string): boolean;
18
+ resume(): void;
19
+ cancel(intent: string): void;
20
+ scope(inFlight?: number): Recovery;
21
+ retire(): Promise<void>;
22
+ };
23
+ export declare function retryDelay(tries: number, firstMs?: number, ceilingMs?: number): number;
24
+ export declare function createRecovery(options?: RecoveryOptions): Recovery;
@@ -0,0 +1,45 @@
1
+ import { type ChangeBatch } from './change.js';
2
+ import { type Collection, type Composition } from './collection.js';
3
+ import { type Layer } from './overlay.js';
4
+ import type { MutationResult } from './adapter.js';
5
+ import type { ReplicaRecord } from './store.js';
6
+ import type { Refused } from './transfer.js';
7
+ export type ConfirmedLayer = {
8
+ record: ReplicaRecord;
9
+ collection: Collection;
10
+ };
11
+ export type VisibleLayer = Layer & {
12
+ collection: Collection;
13
+ };
14
+ export type Staged = {
15
+ kind: 'staged';
16
+ confirmed: ConfirmedLayer;
17
+ } | Refused;
18
+ export type Replica = {
19
+ confirmed: ConfirmedLayer;
20
+ queue: readonly ChangeBatch[];
21
+ visible: VisibleLayer;
22
+ replay: readonly ReplayStep[];
23
+ };
24
+ type ReplayStep = {
25
+ id: string;
26
+ before: Layer;
27
+ after: Layer;
28
+ effective: ChangeBatch;
29
+ collection?: Collection;
30
+ };
31
+ export declare function compositionOf(record: ReplicaRecord): Composition;
32
+ export declare function confirmedOf(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer;
33
+ export declare function sameMembership(record: ReplicaRecord, other: ReplicaRecord): boolean;
34
+ export declare function readStaged(staged: ReplicaRecord, previous?: ConfirmedLayer): Staged;
35
+ export declare function readReclassified(record: ReplicaRecord, previous: ConfirmedLayer): Staged | {
36
+ kind: 'deferred';
37
+ };
38
+ type Accepted = Extract<MutationResult, {
39
+ kind: 'accepted';
40
+ }>;
41
+ export declare function applyReturned(confirmed: ConfirmedLayer, submitted: ChangeBatch, accepted: Accepted, roomVersion: string, writtenAt: string): Staged;
42
+ export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Replica;
43
+ export declare function landed(batch: ChangeBatch, confirmed: ConfirmedLayer, current?: Readonly<Record<string, string>>): boolean;
44
+ export declare function withdrawals(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean): readonly ChangeBatch[];
45
+ export {};
@@ -0,0 +1,143 @@
1
+ import type { ProviderRefusal } from './adapter.js';
2
+ import type { Open } from './open.js';
3
+ import type { Change, Precondition } from './change.js';
4
+ import type { VisibleLayer } from './replica.js';
5
+ export type FieldValue = {
6
+ readonly value: unknown;
7
+ } | null;
8
+ export type RoomDraftCreation = {
9
+ readonly type: string;
10
+ readonly fields: Readonly<Record<string, unknown>>;
11
+ readonly sections: Readonly<Record<string, string>>;
12
+ } | {
13
+ readonly markdown: string;
14
+ };
15
+ export type RoomDraftParts = {
16
+ readonly fields?: Readonly<Record<string, {
17
+ readonly value: unknown;
18
+ readonly base?: FieldValue;
19
+ }>>;
20
+ readonly sections?: Readonly<Record<string, {
21
+ readonly value: string;
22
+ readonly base?: string;
23
+ }>>;
24
+ readonly preamble?: {
25
+ readonly value: string;
26
+ readonly base?: string;
27
+ };
28
+ readonly markdown?: {
29
+ readonly value: string;
30
+ readonly base?: string;
31
+ };
32
+ readonly creation?: RoomDraftCreation;
33
+ readonly move?: {
34
+ readonly to: string;
35
+ readonly base?: string | null;
36
+ };
37
+ readonly removal?: {
38
+ readonly base?: string | null;
39
+ };
40
+ readonly file?: {
41
+ readonly blob: Blob;
42
+ };
43
+ };
44
+ export type HeldFile = {
45
+ readonly blob: Blob;
46
+ readonly localId: string;
47
+ readonly byteLength: number;
48
+ readonly mediaType: string;
49
+ readonly sha256: string;
50
+ readonly base: string | null;
51
+ };
52
+ type HeldParts = {
53
+ readonly fields?: Readonly<Record<string, {
54
+ readonly value: unknown;
55
+ readonly base: FieldValue;
56
+ }>>;
57
+ readonly sections?: Readonly<Record<string, {
58
+ readonly value: string;
59
+ readonly base: string;
60
+ }>>;
61
+ readonly preamble?: {
62
+ readonly value: string;
63
+ readonly base: string;
64
+ };
65
+ readonly markdown?: {
66
+ readonly value: string;
67
+ readonly base: string;
68
+ };
69
+ readonly creation?: RoomDraftCreation;
70
+ readonly move?: {
71
+ readonly to: string;
72
+ readonly base: string | null;
73
+ };
74
+ readonly removal?: {
75
+ readonly base: string | null;
76
+ };
77
+ readonly file?: HeldFile;
78
+ };
79
+ type ChangedUnderneath = {
80
+ readonly fields?: Readonly<Record<string, FieldValue>>;
81
+ readonly sections?: Readonly<Record<string, string | null>>;
82
+ readonly preamble?: string | null;
83
+ readonly markdown?: string | null;
84
+ readonly creation?: string;
85
+ readonly move?: string | null;
86
+ readonly removal?: string | null;
87
+ readonly file?: string | null;
88
+ };
89
+ export type ReturnReason = ProviderRefusal & {
90
+ readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn';
91
+ };
92
+ export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
93
+ export type RoomDraft = {
94
+ readonly room: string;
95
+ readonly path: string;
96
+ readonly revision: string;
97
+ readonly parts: HeldParts;
98
+ readonly changedUnderneath: ChangedUnderneath;
99
+ readonly returned: ReturnReason | null;
100
+ };
101
+ export type RoomDraftWrite = {
102
+ readonly outcome: 'written';
103
+ readonly roomDraft: RoomDraft | null;
104
+ } | {
105
+ readonly outcome: 'stale';
106
+ readonly code: string;
107
+ readonly retryable: boolean;
108
+ readonly current: RoomDraft | null;
109
+ };
110
+ export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
111
+ export type ChangedPart = {
112
+ readonly path: string;
113
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
114
+ readonly name?: string;
115
+ };
116
+ export type RoomDraftRecord = {
117
+ readonly locator: string;
118
+ readonly path: string;
119
+ readonly revision: string;
120
+ readonly parts: HeldParts;
121
+ readonly returned: ReturnReason | null;
122
+ };
123
+ export type SavedDraft = {
124
+ readonly path: string;
125
+ readonly parts: HeldParts;
126
+ };
127
+ export declare function readParts(value: unknown): RoomDraftParts;
128
+ export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
129
+ export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
130
+ export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
131
+ export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
132
+ export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
133
+ export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
134
+ export declare function moveTarget(move: {
135
+ readonly to: string;
136
+ }): string;
137
+ export declare function changesOf(path: string, parts: HeldParts): {
138
+ changes: readonly Change[];
139
+ bases: readonly Precondition[];
140
+ };
141
+ export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
142
+ export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
143
+ export {};
@@ -0,0 +1,36 @@
1
+ import { type Frontmatter } from '../mdmodel/index.js';
2
+ import type { HeadChange } from './adapter.js';
3
+ import type { BinaryFileRecord } from './binary.js';
4
+ import { type Composition } from './collection.js';
5
+ type Fields = Readonly<Record<string, unknown>>;
6
+ export type DocumentRow = {
7
+ key: string;
8
+ kind: 'document';
9
+ room: string;
10
+ path: string;
11
+ type: string | null;
12
+ fields: Fields;
13
+ values: Fields;
14
+ reached: Readonly<Record<string, readonly unknown[]>>;
15
+ directories: readonly string[];
16
+ text: string | null;
17
+ change: HeadChange | null;
18
+ binary: BinaryFileRecord | null;
19
+ };
20
+ export type ReferenceRow = {
21
+ key: string;
22
+ kind: 'reference';
23
+ room: string;
24
+ source: string;
25
+ target: string;
26
+ field: string;
27
+ forms: readonly string[];
28
+ path: string;
29
+ type: string;
30
+ };
31
+ export type Row = DocumentRow | ReferenceRow;
32
+ export declare function documentKey(room: string, path: string): string;
33
+ export declare function roomOfKey(key: string): string;
34
+ export declare function markdownPath(path: string): boolean;
35
+ export declare function rowsOf(room: string, path: string, document: Frontmatter | null, composition: Composition, change: HeadChange | null, binary: BinaryFileRecord | null): readonly Row[];
36
+ export {};
@@ -0,0 +1,63 @@
1
+ import type { ProviderLimit } from './adapter.js';
2
+ import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from './change.js';
3
+ import { type Composition } from './collection.js';
4
+ import type { VisibleLayer } from './replica.js';
5
+ import type { ChangedPart } from './room-draft.js';
6
+ export type SaveRefusal = {
7
+ code: string;
8
+ retryable: boolean;
9
+ file?: string;
10
+ location?: string;
11
+ referrers?: readonly string[];
12
+ parts?: readonly ChangedPart[];
13
+ };
14
+ export type SaveInput = {
15
+ local: boolean;
16
+ composition: Composition;
17
+ baseRoomVersion: string;
18
+ operations: import('./adapter.js').OperationScopes;
19
+ providerOwnedPaths: readonly string[];
20
+ providerLimits: readonly ProviderLimit[];
21
+ visible: VisibleLayer;
22
+ handle: string;
23
+ changes: readonly Change[];
24
+ bases: readonly Precondition[];
25
+ queued?: ReadonlySet<string>;
26
+ writtenBy?: WrittenBy;
27
+ clean?: {
28
+ text: Readonly<Record<string, string>>;
29
+ binaries: Readonly<Record<string, unknown>>;
30
+ composition: Composition;
31
+ };
32
+ };
33
+ export type BatchResult = {
34
+ kind: 'batch';
35
+ batch: ChangeBatch;
36
+ } | {
37
+ kind: 'refused';
38
+ refusal: SaveRefusal;
39
+ };
40
+ export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch;
41
+ export type Requeued = {
42
+ kind: 'requeued';
43
+ queue: readonly ChangeBatch[];
44
+ changes: readonly Change[];
45
+ queued: ReadonlySet<string>;
46
+ withdrawn: ReadonlyMap<string, ChangeBatch | null>;
47
+ owners: ReadonlySet<string>;
48
+ } | {
49
+ kind: 'refused';
50
+ refusal: SaveRefusal;
51
+ };
52
+ export type Joining = {
53
+ kind: 'joined';
54
+ batch: ChangeBatch;
55
+ queue: readonly ChangeBatch[];
56
+ } | {
57
+ kind: 'refused';
58
+ refusal: SaveRefusal;
59
+ };
60
+ export declare function requeued(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: (queue: readonly ChangeBatch[]) => VisibleLayer): Requeued;
61
+ export declare function joined(queue: readonly ChangeBatch[], owner: ChangeBatch, extra: ChangeBatch): Joining;
62
+ export declare function limitedIn(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: (queue: readonly ChangeBatch[]) => VisibleLayer): SaveRefusal | null;
63
+ export declare function buildBatch(input: SaveInput): BatchResult;