@agentshouse/app-bridge 0.1.0-ca354d1b3bbdd → 0.1.0-ca3af8d8e77bf

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 (63) hide show
  1. package/README.md +11 -9
  2. package/dist/index.d.ts +867 -5
  3. package/dist/mdmodel/blocks.d.ts +10 -0
  4. package/dist/mdmodel/condition.d.ts +178 -0
  5. package/dist/mdmodel/definition.d.ts +81 -0
  6. package/dist/mdmodel/divide.d.ts +2 -0
  7. package/dist/mdmodel/document.d.ts +16 -0
  8. package/dist/mdmodel/fields.d.ts +5 -0
  9. package/dist/mdmodel/index.d.ts +30 -0
  10. package/dist/mdmodel/kinds.d.ts +17 -0
  11. package/dist/mdmodel/links.d.ts +28 -0
  12. package/dist/mdmodel/paths.d.ts +25 -0
  13. package/dist/mdmodel/profile.d.ts +5 -0
  14. package/dist/mdmodel/project.d.ts +21 -0
  15. package/dist/mdmodel/query/language.d.ts +217 -0
  16. package/dist/mdmodel/query/match.d.ts +11 -0
  17. package/dist/mdmodel/query/rows.d.ts +31 -0
  18. package/dist/mdmodel/query/sql.d.ts +38 -0
  19. package/dist/mdmodel/references.d.ts +3 -0
  20. package/dist/mdmodel/reserved.d.ts +4 -0
  21. package/dist/mdmodel/types.d.ts +179 -0
  22. package/dist/mdmodel/validate.d.ts +32 -0
  23. package/dist/mdmodel/version.d.ts +1 -0
  24. package/dist/mdmodel/yaml.d.ts +55 -0
  25. package/dist/mdruntime/adapter.d.ts +551 -0
  26. package/dist/mdruntime/binary.d.ts +17 -0
  27. package/dist/mdruntime/chain.d.ts +11 -0
  28. package/dist/mdruntime/change-set.d.ts +27 -0
  29. package/dist/mdruntime/change.d.ts +118 -0
  30. package/dist/mdruntime/client.d.ts +91 -0
  31. package/dist/mdruntime/collection.d.ts +28 -0
  32. package/dist/mdruntime/compile.d.ts +10 -0
  33. package/dist/mdruntime/connection.d.ts +152 -0
  34. package/dist/mdruntime/conversation.d.ts +120 -0
  35. package/dist/mdruntime/durability.d.ts +11 -0
  36. package/dist/mdruntime/failure.d.ts +12 -0
  37. package/dist/mdruntime/identity.d.ts +6 -0
  38. package/dist/mdruntime/media.d.ts +7 -0
  39. package/dist/mdruntime/messages.d.ts +27 -0
  40. package/dist/mdruntime/model.d.ts +61 -0
  41. package/dist/mdruntime/observation.d.ts +44 -0
  42. package/dist/mdruntime/open.d.ts +1 -0
  43. package/dist/mdruntime/opened.d.ts +21 -0
  44. package/dist/mdruntime/outcome.d.ts +84 -0
  45. package/dist/mdruntime/overlay.d.ts +24 -0
  46. package/dist/mdruntime/query.d.ts +79 -0
  47. package/dist/mdruntime/reach.d.ts +53 -0
  48. package/dist/mdruntime/readiness.d.ts +49 -0
  49. package/dist/mdruntime/recovery.d.ts +25 -0
  50. package/dist/mdruntime/replica.d.ts +68 -0
  51. package/dist/mdruntime/room-draft.d.ts +174 -0
  52. package/dist/mdruntime/save.d.ts +102 -0
  53. package/dist/mdruntime/search.d.ts +21 -0
  54. package/dist/mdruntime/seed.d.ts +15 -0
  55. package/dist/mdruntime/status.d.ts +27 -0
  56. package/dist/mdruntime/store.d.ts +162 -0
  57. package/dist/mdruntime/stored.d.ts +161 -0
  58. package/dist/mdruntime/tables.d.ts +352 -0
  59. package/dist/mdruntime/wire.d.ts +235 -0
  60. package/dist/test-host.d.ts +8 -2
  61. package/dist/test-host.js +48 -11
  62. package/docs/families.md +69 -13
  63. package/package.json +8 -6
@@ -0,0 +1,44 @@
1
+ import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
2
+ export type Observation<T> = {
3
+ current(): T;
4
+ subscribe(listener: (value: T) => void): () => void;
5
+ close(): void;
6
+ };
7
+ export type RowKey = string | number;
8
+ export type KeyedResult = {
9
+ result: QueryResult;
10
+ keys: readonly RowKey[];
11
+ };
12
+ export type QueryChange = {
13
+ changed: readonly (readonly [RowKey, QueryDocument | QueryGroup])[];
14
+ removed: readonly RowKey[];
15
+ order: readonly RowKey[] | null;
16
+ coverage?: QueryCoverage;
17
+ next?: string | null;
18
+ total?: number;
19
+ };
20
+ export type QueryMessage = KeyedResult | QueryChange;
21
+ export type Observed = {
22
+ observation: Observation<unknown>;
23
+ receive(message: unknown): void;
24
+ end(): void;
25
+ };
26
+ export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
27
+ export declare function whole(message: QueryMessage): message is KeyedResult;
28
+ export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
29
+ export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
30
+ export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
31
+ export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
32
+ export type Digest = {
33
+ readonly pending: string;
34
+ } | {
35
+ readonly keys: readonly RowKey[];
36
+ readonly rows: ReadonlyMap<RowKey, number>;
37
+ readonly coverage: string;
38
+ readonly next: string | undefined;
39
+ readonly total: number | undefined;
40
+ };
41
+ export declare function hashed(text: string): number;
42
+ export declare function digestOf({ result, keys }: KeyedResult): Digest;
43
+ export declare function digestApplied(digest: Digest, message: QueryMessage): Digest;
44
+ export declare function changeOf(previous: Digest, next: KeyedResult): QueryMessage | null;
@@ -0,0 +1 @@
1
+ export type Open<Value extends string> = Value | (string & {});
@@ -0,0 +1,21 @@
1
+ import type { BinaryResult } from './adapter.js';
2
+ import { type RuntimeDatabase } from './tables.js';
3
+ export type OpenedName = {
4
+ readonly locator: string;
5
+ readonly path: string;
6
+ readonly revision: string;
7
+ };
8
+ export type KeptBinary = {
9
+ readonly kind: 'binary';
10
+ readonly file: string;
11
+ readonly byteLength: number;
12
+ readonly mediaType: string;
13
+ };
14
+ export type KeptResult = KeptBinary | Exclude<BinaryResult, {
15
+ kind: 'binary';
16
+ }>;
17
+ export type OpenedFiles = {
18
+ find(name: OpenedName): Promise<KeptBinary | null>;
19
+ fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
20
+ };
21
+ export declare function openedFiles(database: RuntimeDatabase, fenced: (locator: string) => boolean): OpenedFiles;
@@ -0,0 +1,84 @@
1
+ import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
+ import type { ChangeBatch } from './change.js';
3
+ import type { KeptBinary, KeptResult } from './opened.js';
4
+ type Refused<Kind extends string> = ProviderRefusal & {
5
+ kind: Kind;
6
+ };
7
+ export type Failure = Refused<'transport-uncertainty'> | Refused<'revoked-authorization'> | (Refused<'room-not-readable'> & {
8
+ locator: string;
9
+ }) | (Refused<'room-locked'> & {
10
+ locator: string;
11
+ }) | ScopedRefusal;
12
+ export type CallResult = {
13
+ kind: 'action';
14
+ result: unknown;
15
+ at?: RoomVersionAt;
16
+ } | Refused<'rejected'> | Refused<'undeclared'> | Failure;
17
+ export type HistoryAnswer = Exclude<HistoryResult, {
18
+ kind: Failure['kind'];
19
+ }> | Failure;
20
+ type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
21
+ export type BinaryAnswer = {
22
+ kind: 'binary';
23
+ stream: ReadableStream<Uint8Array>;
24
+ byteLength: number;
25
+ mediaType: string;
26
+ } | BinaryRefusal;
27
+ export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
28
+ export type BinaryLinkAnswer = {
29
+ kind: 'link';
30
+ url: string;
31
+ name: string;
32
+ mediaType: string;
33
+ } | Refused<'rejected'> | Refused<'absent'> | Failure;
34
+ export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
35
+ export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
36
+ export type AttachAnswer = {
37
+ kind: 'attached';
38
+ path: string;
39
+ } | Offline | Refused<'rejected'> | Failure;
40
+ export type DownloadAnswer = {
41
+ kind: 'started';
42
+ } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
43
+ export type Resolution = {
44
+ readonly kind: 'document';
45
+ readonly room: string;
46
+ readonly path: string;
47
+ } | {
48
+ readonly kind: 'deleted';
49
+ readonly room: string;
50
+ readonly path: string;
51
+ readonly revision: HistoryRevision;
52
+ } | Refused<'unreadable'> | Refused<'absent'> | Failure;
53
+ export declare const UNREADABLE: Refused<'unreadable'>;
54
+ export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
55
+ export declare const ABSENT_TARGET: Refused<'absent'>;
56
+ export declare function absentBinary(path: string): Refused<'absent'>;
57
+ export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
58
+ export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
59
+ export declare function attachAnswer(result: AttachResult): AttachAnswer;
60
+ export declare const ROOM_LOCKED = "room-locked";
61
+ export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
62
+ locator: string;
63
+ };
64
+ export type Offline = {
65
+ readonly kind: 'offline';
66
+ };
67
+ export declare const OFFLINE: Offline;
68
+ export declare const UNCERTAIN: Failure;
69
+ export declare function undeclared(name: string): CallResult;
70
+ export declare function failure(result: AdapterFailure): Failure;
71
+ export declare function calledResult(result: ActionResult): CallResult;
72
+ export declare function historyAnswer(result: HistoryResult): HistoryAnswer;
73
+ export type Submission = {
74
+ readonly state: 'waiting' | 'submitted';
75
+ } | {
76
+ readonly state: 'reset';
77
+ readonly reset: string;
78
+ };
79
+ export type QueueEntry = {
80
+ readonly batch: ChangeBatch;
81
+ } & (Submission | {
82
+ readonly state: 'local';
83
+ });
84
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { BinaryFile, HeadChange } from './adapter.js';
2
+ import type { ChangeBatch } from './change.js';
3
+ export type Heads = {
4
+ revisions: Readonly<Record<string, string>>;
5
+ fileIds: Readonly<Record<string, string>>;
6
+ changes: Readonly<Record<string, HeadChange>>;
7
+ };
8
+ export type HeldBinary = ({
9
+ readonly state: 'accepted';
10
+ } & BinaryFile) | {
11
+ readonly state: 'pending';
12
+ readonly localId: string;
13
+ readonly byteLength: number;
14
+ readonly mediaType: string;
15
+ readonly sha256: string;
16
+ };
17
+ export type Layer = Heads & {
18
+ documents: Readonly<Record<string, string>>;
19
+ binaries: Readonly<Record<string, HeldBinary>>;
20
+ };
21
+ export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
22
+ export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
23
+ export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
24
+ export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Generator<number, Layer, void>;
@@ -0,0 +1,79 @@
1
+ import { type HeldRooms, type QueryPlan } from '../mdmodel/index.js';
2
+ import type { HeadChange } from './adapter.js';
3
+ import type { BinaryFileRecord } from './binary.js';
4
+ import type { Open } from './open.js';
5
+ export type Backlink = {
6
+ path: string;
7
+ type: string;
8
+ field: string;
9
+ };
10
+ export type QueryDocument = {
11
+ room: string;
12
+ path: string;
13
+ type?: string;
14
+ fields?: Readonly<Record<string, unknown>>;
15
+ sections?: Readonly<Record<string, string>>;
16
+ preamble?: string;
17
+ markdown?: string;
18
+ textHeld?: false;
19
+ backlinks?: readonly Backlink[];
20
+ change?: HeadChange | null;
21
+ fileId?: string | null;
22
+ revision?: string | null;
23
+ binaryFile?: BinaryFileRecord;
24
+ };
25
+ export type QueryGroup = {
26
+ key: readonly unknown[];
27
+ count: number;
28
+ };
29
+ export type CoveredRoom = {
30
+ room: string;
31
+ generation: string;
32
+ current: boolean;
33
+ };
34
+ export type QueryCoverage = {
35
+ rooms: readonly CoveredRoom[];
36
+ indexes: readonly string[];
37
+ overlay: readonly string[];
38
+ };
39
+ export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
40
+ export type PendingRoom = {
41
+ room: string;
42
+ awaits: Awaits;
43
+ };
44
+ export type PendingResult = {
45
+ pending: readonly PendingRoom[];
46
+ };
47
+ export type DocumentRows = {
48
+ documents: readonly QueryDocument[];
49
+ next?: string;
50
+ total?: number;
51
+ };
52
+ export type GroupRows = {
53
+ groups: readonly QueryGroup[];
54
+ next?: string;
55
+ total?: number;
56
+ };
57
+ export type QueryRows = DocumentRows | GroupRows;
58
+ export type DocumentResult = DocumentRows & {
59
+ coverage: QueryCoverage;
60
+ };
61
+ export type GroupResult = GroupRows & {
62
+ coverage: QueryCoverage;
63
+ };
64
+ export type QueryResult = DocumentResult | GroupResult | PendingResult;
65
+ export type PlanArea = {
66
+ room: string;
67
+ path: string;
68
+ open: readonly string[];
69
+ };
70
+ export type PlanReach = {
71
+ rooms: readonly string[];
72
+ documents: readonly string[];
73
+ areas: readonly PlanArea[];
74
+ };
75
+ export type Plan = QueryPlan & {
76
+ reach: PlanReach | null;
77
+ locked: readonly string[];
78
+ };
79
+ export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
@@ -0,0 +1,53 @@
1
+ import type { AppRoom, MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
2
+ import type { Plan, PlanReach, QueryResult } from './query.js';
3
+ import type { Readiness } from './readiness.js';
4
+ import type { SearchResult } from './search.js';
5
+ export type ReachedDocument = {
6
+ readonly room: string;
7
+ readonly path: string;
8
+ };
9
+ export type ReachedArea = {
10
+ readonly room: string;
11
+ readonly path: string;
12
+ readonly open: readonly string[];
13
+ };
14
+ export type PortReach = {
15
+ readonly rooms: readonly string[];
16
+ readonly documents: readonly ReachedDocument[];
17
+ readonly areas?: readonly ReachedArea[];
18
+ readonly conversations: boolean;
19
+ };
20
+ export type Deliver = (message: unknown) => void;
21
+ export type Fail = (error: unknown) => void;
22
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
23
+ export type RuntimeView = {
24
+ md: MdRuntime;
25
+ watch: Watch;
26
+ };
27
+ export type NarrowedView = RuntimeView & {
28
+ narrow(reach: PortReach | null): void;
29
+ };
30
+ export type Reachable = RuntimeView & {
31
+ plan(input: unknown, reach: PortReach | null): Plan;
32
+ query(plan: Plan): Promise<QueryResult>;
33
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
34
+ search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
35
+ watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
36
+ locked(room: string): boolean;
37
+ lockedRooms(): readonly string[];
38
+ watchLocks(notify: () => void): () => void;
39
+ located(room: string, path: string, destination: string): ReachedDocument | null;
40
+ room(locator: string): AppRoom | undefined;
41
+ };
42
+ export declare function holds(reach: PortReach | null, room: string): boolean;
43
+ export declare function governs(reach: PortReach | null, room: {
44
+ readonly locator: string;
45
+ readonly typedSelection: {
46
+ roots: readonly string[];
47
+ } | null;
48
+ }): {
49
+ readonly collection: boolean;
50
+ readonly selection: boolean;
51
+ };
52
+ export declare function planReach(reach: PortReach | null): PlanReach | null;
53
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -0,0 +1,49 @@
1
+ import type { Open } from './open.js';
2
+ export type CodeAvailability = Open<'stored' | 'absent'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
4
+ export type RoomCoverage = {
5
+ readonly room: string;
6
+ readonly state: RoomPreparation;
7
+ };
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
9
+ export type TargetCoverage = {
10
+ readonly complete: boolean;
11
+ readonly listed: boolean;
12
+ readonly rooms: readonly RoomCoverage[];
13
+ readonly conversations: ConversationCoverage;
14
+ };
15
+ export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
16
+ export type Durability = Open<'persistent' | 'best-effort'>;
17
+ export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
18
+ export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
19
+ export type Space = Open<'full'>;
20
+ export type InstallationStep = Open<'downloading' | 'writing' | 'replaying'>;
21
+ export type InstallationAmount = {
22
+ readonly done: number;
23
+ readonly total: number;
24
+ };
25
+ export type Installation = {
26
+ readonly step: InstallationStep | null;
27
+ readonly rooms: InstallationAmount;
28
+ readonly bytes: InstallationAmount;
29
+ };
30
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
31
+ export type Readiness = {
32
+ readonly status: ReadinessStatus;
33
+ readonly ready: boolean;
34
+ readonly usable: boolean;
35
+ readonly code: CodeAvailability;
36
+ readonly coverage: TargetCoverage;
37
+ readonly durability: Durability;
38
+ readonly persistence: Persistence;
39
+ readonly connection: ConnectionAvailability;
40
+ readonly house: HouseOutcome;
41
+ readonly space: Space | null;
42
+ readonly installation: Installation;
43
+ readonly lost: boolean;
44
+ };
45
+ export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
46
+ readonly coverage: Omit<TargetCoverage, 'complete'>;
47
+ readonly established: boolean;
48
+ };
49
+ export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -0,0 +1,25 @@
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 maxMs?: 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, maxMs?: number): number;
24
+ export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
25
+ export declare function createRecovery(options?: RecoveryOptions): Recovery;
@@ -0,0 +1,68 @@
1
+ import { type TypedPath } from '../mdmodel/index.js';
2
+ import type { BootstrapInventory, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
3
+ import { type ChangeBatch, type Precondition } from './change.js';
4
+ import { type Collection, type Composition } from './collection.js';
5
+ import { type ModelState } from './model.js';
6
+ import { type Layer } from './overlay.js';
7
+ import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
8
+ export type ReplicaRecord = {
9
+ readonly locator: string;
10
+ readonly name: string;
11
+ readonly handle: string;
12
+ readonly operations: OperationScopes;
13
+ readonly replica: ReplicaAdmission;
14
+ readonly model: ModelState;
15
+ readonly typedSelection: TypedSelection | null;
16
+ readonly providerOwnedPaths: readonly string[];
17
+ readonly roomVersion: string;
18
+ readonly transfer: string;
19
+ readonly inventory: BootstrapInventory;
20
+ readonly key: number;
21
+ };
22
+ export type HeldReplica = {
23
+ readonly record: ReplicaRecord;
24
+ readonly queue: readonly ChangeBatch[];
25
+ readonly overlaid: ReadonlySet<string>;
26
+ readonly count: number;
27
+ readonly confirmed: number;
28
+ readonly indexed: boolean;
29
+ };
30
+ export type VisibleLayer = Layer & {
31
+ readonly collection: Collection;
32
+ };
33
+ export type Slice = Layer & {
34
+ readonly written: Readonly<Record<string, string>>;
35
+ readonly held: ReadonlySet<string>;
36
+ };
37
+ export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
38
+ export declare function storedRecord(record: ReplicaRecord): string;
39
+ export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
40
+ export declare function entryAt(layer: Layer & {
41
+ readonly written?: Readonly<Record<string, string>>;
42
+ }, path: string): StoredEntry | null;
43
+ export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
44
+ export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
45
+ export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
46
+ export type Replayed = {
47
+ readonly visible: VisibleLayer;
48
+ readonly touched: ReadonlySet<string>;
49
+ };
50
+ export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
51
+ export declare function overlayOf(visible: Layer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
52
+ export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
53
+ export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
54
+ export type Standing = {
55
+ readonly withdrawn: readonly ChangeBatch[];
56
+ readonly kept: readonly ChangeBatch[];
57
+ };
58
+ export declare function standing(confirmed: Slice, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean, locator: string, composition: Composition): Generator<number, Standing, void>;
59
+ type Accepted = Extract<MutationResult, {
60
+ kind: 'accepted';
61
+ }>;
62
+ export type Returned = {
63
+ readonly set: readonly StoredEntry[];
64
+ readonly removed: readonly string[];
65
+ };
66
+ export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
67
+ export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string): Generator<number, Returned, void>;
68
+ export {};
@@ -0,0 +1,174 @@
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 room?: string;
36
+ readonly base?: string | null;
37
+ };
38
+ readonly removal?: {
39
+ readonly base?: string | null;
40
+ };
41
+ readonly file?: {
42
+ readonly blob: Blob;
43
+ readonly base?: string | null;
44
+ };
45
+ };
46
+ export type HeldFile = {
47
+ readonly localId: string;
48
+ readonly name?: string;
49
+ readonly byteLength: number;
50
+ readonly mediaType: string;
51
+ readonly sha256: string;
52
+ readonly base: string | null;
53
+ };
54
+ type HeldParts = {
55
+ readonly fields?: Readonly<Record<string, {
56
+ readonly value: unknown;
57
+ readonly base: FieldValue;
58
+ }>>;
59
+ readonly sections?: Readonly<Record<string, {
60
+ readonly value: string;
61
+ readonly base: string;
62
+ }>>;
63
+ readonly preamble?: {
64
+ readonly value: string;
65
+ readonly base: string;
66
+ };
67
+ readonly markdown?: {
68
+ readonly value: string;
69
+ readonly base: string;
70
+ };
71
+ readonly creation?: RoomDraftCreation;
72
+ readonly move?: {
73
+ readonly to: string;
74
+ readonly room?: string;
75
+ readonly base: string | null;
76
+ };
77
+ readonly removal?: {
78
+ readonly base: string | null;
79
+ };
80
+ readonly file?: HeldFile;
81
+ };
82
+ type ChangedUnderneath = {
83
+ readonly fields?: Readonly<Record<string, FieldValue>>;
84
+ readonly sections?: Readonly<Record<string, string | null>>;
85
+ readonly preamble?: string | null;
86
+ readonly markdown?: string | null;
87
+ readonly creation?: string;
88
+ readonly move?: string | null;
89
+ readonly removal?: string | null;
90
+ readonly file?: string | null;
91
+ };
92
+ export type ReturnReason = ProviderRefusal & {
93
+ readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
94
+ };
95
+ export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
96
+ export type RoomDraft = {
97
+ readonly room: string;
98
+ readonly path: string;
99
+ readonly revision: string;
100
+ readonly parts: HeldParts;
101
+ readonly changedUnderneath: ChangedUnderneath;
102
+ readonly returned: ReturnReason | null;
103
+ };
104
+ export type RoomDraftWrite = {
105
+ readonly outcome: 'written';
106
+ readonly roomDraft: RoomDraft | null;
107
+ } | {
108
+ readonly outcome: 'stale';
109
+ readonly code: string;
110
+ readonly retryable: boolean;
111
+ readonly current: RoomDraft | null;
112
+ };
113
+ export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
114
+ export type ChangedPart = {
115
+ readonly path: string;
116
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
117
+ readonly name?: string;
118
+ };
119
+ export type RoomDraftRecord = {
120
+ readonly locator: string;
121
+ readonly path: string;
122
+ readonly revision: string;
123
+ readonly parts: HeldParts;
124
+ readonly returned: ReturnReason | null;
125
+ };
126
+ export type SavedDraft = {
127
+ readonly path: string;
128
+ readonly parts: HeldParts;
129
+ };
130
+ export declare function readParts(value: unknown, path: string): RoomDraftParts;
131
+ export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
132
+ export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
133
+ export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
134
+ export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
135
+ export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
136
+ export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
137
+ export declare function lineEnded(text: string): string;
138
+ export type TextParts = {
139
+ readonly fields?: Readonly<Record<string, {
140
+ readonly value: unknown;
141
+ }>>;
142
+ readonly sections?: Readonly<Record<string, {
143
+ readonly value: string;
144
+ }>>;
145
+ readonly preamble?: {
146
+ readonly value: string;
147
+ };
148
+ };
149
+ export declare function partsAfter(markdown: string, parts: TextParts): string;
150
+ export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
151
+ export declare function moveTarget(move: {
152
+ readonly to: string;
153
+ }): string;
154
+ export declare function readSavedParts(named: readonly {
155
+ readonly path: string;
156
+ readonly parts: unknown;
157
+ }[]): readonly {
158
+ readonly path: string;
159
+ readonly parts: RoomDraftParts;
160
+ }[];
161
+ export declare function partsChanges(named: readonly {
162
+ readonly path: string;
163
+ readonly parts: unknown;
164
+ }[]): {
165
+ readonly changes: readonly Change[];
166
+ readonly preconditions: readonly Precondition[];
167
+ };
168
+ export declare function changesOf(path: string, parts: HeldParts): {
169
+ changes: readonly Change[];
170
+ bases: readonly Precondition[];
171
+ };
172
+ export declare function joinedDraft(carried: SavedDraft, saved: readonly SavedDraft[]): SavedDraft;
173
+ export declare function withdrawnDrafts(drafts: readonly SavedDraft[], changes: readonly Change[]): readonly SavedDraft[];
174
+ export {};