@agentshouse/app-bridge 0.1.0-c646d0da70608 → 0.1.0-c64bbf5cda7ef

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 (100) hide show
  1. package/README.md +11 -11
  2. package/dist/index.d.ts +943 -19
  3. package/dist/mdmodel/definition.d.ts +17 -1
  4. package/dist/mdmodel/document.d.ts +6 -5
  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 +24 -9
  8. package/dist/mdmodel/kinds.d.ts +18 -0
  9. package/dist/mdmodel/links.d.ts +28 -0
  10. package/dist/mdmodel/paths.d.ts +9 -1
  11. package/dist/mdmodel/pattern.d.ts +9 -0
  12. package/dist/mdmodel/project.d.ts +1 -0
  13. package/dist/mdmodel/query/language.d.ts +253 -0
  14. package/dist/mdmodel/query/match.d.ts +13 -0
  15. package/dist/mdmodel/query/rows.d.ts +31 -0
  16. package/dist/mdmodel/query/sql.d.ts +38 -0
  17. package/dist/mdmodel/reserved.d.ts +4 -0
  18. package/dist/mdmodel/types.d.ts +39 -4
  19. package/dist/mdmodel/validate.d.ts +30 -4
  20. package/dist/mdruntime/actions.d.ts +19 -0
  21. package/dist/mdruntime/adapter.d.ts +151 -79
  22. package/dist/mdruntime/attached-model.d.ts +7 -0
  23. package/dist/mdruntime/binary.d.ts +0 -5
  24. package/dist/mdruntime/bootstrap.d.ts +43 -0
  25. package/dist/mdruntime/cell.d.ts +5 -0
  26. package/dist/mdruntime/chain.d.ts +11 -0
  27. package/dist/mdruntime/change-set.d.ts +9 -16
  28. package/dist/mdruntime/change.d.ts +32 -1
  29. package/dist/mdruntime/client.d.ts +33 -10
  30. package/dist/mdruntime/collection.d.ts +11 -21
  31. package/dist/mdruntime/compile.d.ts +15 -0
  32. package/dist/mdruntime/conversation-row.d.ts +32 -0
  33. package/dist/mdruntime/conversation.d.ts +43 -18
  34. package/dist/mdruntime/durability.d.ts +16 -4
  35. package/dist/mdruntime/figures.d.ts +47 -0
  36. package/dist/mdruntime/holdings.d.ts +28 -0
  37. package/dist/mdruntime/identity.d.ts +5 -0
  38. package/dist/mdruntime/install.d.ts +55 -0
  39. package/dist/mdruntime/job.d.ts +32 -0
  40. package/dist/mdruntime/listing.d.ts +52 -0
  41. package/dist/mdruntime/live.d.ts +22 -0
  42. package/dist/mdruntime/log.d.ts +5 -0
  43. package/dist/mdruntime/media.d.ts +7 -0
  44. package/dist/mdruntime/messages.d.ts +51 -0
  45. package/dist/mdruntime/model.d.ts +8 -10
  46. package/dist/mdruntime/observation.d.ts +17 -2
  47. package/dist/mdruntime/opened.d.ts +21 -0
  48. package/dist/mdruntime/outcome.d.ts +49 -8
  49. package/dist/mdruntime/overlay.d.ts +4 -5
  50. package/dist/mdruntime/preparation.d.ts +19 -0
  51. package/dist/mdruntime/query.d.ts +26 -185
  52. package/dist/mdruntime/reach.d.ts +19 -9
  53. package/dist/mdruntime/readiness.d.ts +14 -17
  54. package/dist/mdruntime/reads.d.ts +35 -0
  55. package/dist/mdruntime/recovery.d.ts +3 -2
  56. package/dist/mdruntime/refresh.d.ts +26 -0
  57. package/dist/mdruntime/replica.d.ts +55 -33
  58. package/dist/mdruntime/room-draft.d.ts +37 -6
  59. package/dist/mdruntime/room-drafts.d.ts +23 -0
  60. package/dist/mdruntime/runtime.d.ts +41 -0
  61. package/dist/mdruntime/save.d.ts +53 -14
  62. package/dist/mdruntime/saves.d.ts +69 -0
  63. package/dist/mdruntime/search.d.ts +15 -78
  64. package/dist/mdruntime/seed.d.ts +24 -0
  65. package/dist/mdruntime/socket/admission.d.ts +6 -0
  66. package/dist/mdruntime/socket/answers.d.ts +5 -0
  67. package/dist/mdruntime/socket/lanes.d.ts +19 -0
  68. package/dist/mdruntime/socket/rooms.d.ts +42 -0
  69. package/dist/mdruntime/socket/session.d.ts +38 -0
  70. package/dist/mdruntime/socket.d.ts +69 -0
  71. package/dist/mdruntime/source.d.ts +60 -0
  72. package/dist/mdruntime/status.d.ts +4 -5
  73. package/dist/mdruntime/store/fences.d.ts +15 -0
  74. package/dist/mdruntime/store/installs.d.ts +29 -0
  75. package/dist/mdruntime/store/readiness.d.ts +9 -0
  76. package/dist/mdruntime/store/records.d.ts +211 -0
  77. package/dist/mdruntime/store/room-held.d.ts +7 -0
  78. package/dist/mdruntime/store/space.d.ts +10 -0
  79. package/dist/mdruntime/store/watchers.d.ts +16 -0
  80. package/dist/mdruntime/store/writes.d.ts +23 -0
  81. package/dist/mdruntime/store.d.ts +106 -150
  82. package/dist/mdruntime/stored.d.ts +155 -0
  83. package/dist/mdruntime/surface.d.ts +87 -0
  84. package/dist/mdruntime/tables.d.ts +414 -0
  85. package/dist/mdruntime/tallies.d.ts +17 -0
  86. package/dist/mdruntime/transfer.d.ts +0 -5
  87. package/dist/mdruntime/turn.d.ts +5 -3
  88. package/dist/mdruntime/wire.d.ts +50 -6
  89. package/dist/test-host.d.ts +7 -4
  90. package/dist/test-host.js +19 -29
  91. package/docs/families.md +69 -53
  92. package/package.json +8 -3
  93. package/dist/calls.d.ts +0 -117
  94. package/dist/calls.js +0 -1
  95. package/dist/mdmodel/condition.d.ts +0 -149
  96. package/dist/mdruntime/acquisition.d.ts +0 -13
  97. package/dist/mdruntime/connection.d.ts +0 -138
  98. package/dist/mdruntime/file.d.ts +0 -19
  99. package/dist/mdruntime/rows.d.ts +0 -36
  100. package/dist/mdruntime/shared.d.ts +0 -10
@@ -1,5 +1,6 @@
1
- import type { ReferrerScope } from './adapter.js';
2
- import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
1
+ import type { AppRoom } from './listing.js';
2
+ import type { ReadinessPort } from './preparation.js';
3
+ import type { MdRuntime, RuntimeTopic } from './surface.js';
3
4
  import type { Plan, PlanReach, QueryResult } from './query.js';
4
5
  import type { Readiness } from './readiness.js';
5
6
  import type { SearchResult } from './search.js';
@@ -7,29 +8,38 @@ export type ReachedDocument = {
7
8
  readonly room: string;
8
9
  readonly path: string;
9
10
  };
11
+ export type ReachedArea = {
12
+ readonly room: string;
13
+ readonly path: string;
14
+ readonly open: readonly string[];
15
+ };
10
16
  export type PortReach = {
11
17
  readonly rooms: readonly string[];
12
18
  readonly documents: readonly ReachedDocument[];
19
+ readonly areas?: readonly ReachedArea[];
13
20
  readonly conversations: boolean;
14
21
  };
15
22
  export type Deliver = (message: unknown) => void;
16
- export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
23
+ export type Fail = (error: unknown) => void;
24
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
17
25
  export type RuntimeView = {
18
26
  md: MdRuntime;
19
27
  watch: Watch;
20
28
  };
21
29
  export type NarrowedView = RuntimeView & {
22
30
  narrow(reach: PortReach | null): void;
23
- facts(port: ReadinessPort): void;
24
31
  };
25
32
  export type Reachable = RuntimeView & {
26
- plan(input: unknown, reach: PortReach | null): Plan;
33
+ plan(input: unknown, reach: PortReach | null): Promise<Plan>;
27
34
  query(plan: Plan): Promise<QueryResult>;
28
- watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
35
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
29
36
  search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
30
- searching(target: string): void;
31
37
  watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
32
- referrerScope(referrer: unknown): ReferrerScope | null;
38
+ locked(room: string): Promise<boolean>;
39
+ lockedRooms(): Promise<readonly string[]>;
40
+ watchLocks(notify: () => void): () => void;
41
+ located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
42
+ room(locator: string): Promise<AppRoom | undefined>;
33
43
  };
34
44
  export declare function holds(reach: PortReach | null, room: string): boolean;
35
45
  export declare function governs(reach: PortReach | null, room: {
@@ -42,4 +52,4 @@ export declare function governs(reach: PortReach | null, room: {
42
52
  readonly selection: boolean;
43
53
  };
44
54
  export declare function planReach(reach: PortReach | null): PlanReach | null;
45
- export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
55
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -1,35 +1,33 @@
1
1
  import type { Open } from './open.js';
2
2
  export type CodeAvailability = Open<'stored' | 'absent'>;
3
- export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'indexing' | 'refused' | 'unadmitted'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
4
4
  export type RoomCoverage = {
5
5
  readonly room: string;
6
6
  readonly state: RoomPreparation;
7
7
  };
8
- export type ConversationCoverage = Open<'complete' | 'acquiring' | 'indexing' | 'undeclared'>;
9
- export type SearchObligation = Open<'required' | 'unused'>;
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
10
9
  export type TargetCoverage = {
11
10
  readonly complete: boolean;
12
11
  readonly listed: boolean;
13
12
  readonly rooms: readonly RoomCoverage[];
14
13
  readonly conversations: ConversationCoverage;
15
- readonly search: SearchObligation;
16
14
  };
17
15
  export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
18
16
  export type Durability = Open<'persistent' | 'best-effort'>;
19
17
  export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
20
18
  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;
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;
25
24
  };
26
- export type RefusedRoom = {
27
- readonly room: string;
28
- readonly file: string;
29
- readonly rule: string;
30
- readonly location: string | null;
25
+ export type Installation = {
26
+ readonly step: InstallationStep | null;
27
+ readonly rooms: InstallationAmount;
28
+ readonly bytes: InstallationAmount;
31
29
  };
32
- export type ReadinessStatus = Open<'preparing' | 'paused' | 'refused' | 'ready' | 'lost'>;
30
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
33
31
  export type Readiness = {
34
32
  readonly status: ReadinessStatus;
35
33
  readonly ready: boolean;
@@ -40,13 +38,12 @@ export type Readiness = {
40
38
  readonly persistence: Persistence;
41
39
  readonly connection: ConnectionAvailability;
42
40
  readonly house: HouseOutcome;
43
- readonly capacity: CapacityCause | null;
44
- readonly refused: readonly RefusedRoom[];
41
+ readonly space: Space | null;
42
+ readonly installation: Installation;
45
43
  readonly lost: boolean;
46
44
  };
47
45
  export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
48
46
  readonly coverage: Omit<TargetCoverage, 'complete'>;
49
47
  readonly established: boolean;
50
48
  };
51
- export declare const SETTLED_ROOMS: ReadonlySet<string>;
52
49
  export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -0,0 +1,35 @@
1
+ import { type CallResult } from './outcome.js';
2
+ import type { Recovery } from './recovery.js';
3
+ import type { Connection, RuntimeDatabase } from './tables.js';
4
+ export declare const READ_TABLES: readonly string[];
5
+ export type ReadAt = {
6
+ readonly name: string;
7
+ readonly input: string;
8
+ readonly build: string;
9
+ };
10
+ export type ObservedRead = {
11
+ readonly answer: unknown;
12
+ readonly failure: CallResult | null;
13
+ readonly kept: boolean;
14
+ };
15
+ export type ReadAnswers = {
16
+ watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
17
+ again(): void;
18
+ reopened(): void;
19
+ };
20
+ export type ReadAnswersOptions = {
21
+ readonly database: RuntimeDatabase;
22
+ readonly build: string;
23
+ readonly unkept: readonly string[];
24
+ readonly leading: readonly string[];
25
+ readonly recovery: Recovery;
26
+ call(name: string, input: unknown): Promise<CallResult>;
27
+ online(): boolean;
28
+ closed(): boolean;
29
+ full(): boolean;
30
+ filled(): void;
31
+ };
32
+ export declare function storedRead(connection: Connection, { name, input, build }: ReadAt): string | null;
33
+ export declare function keptRead(connection: Connection, { name, input, build }: ReadAt, answer: string): null;
34
+ export declare function readsOfOtherBuildsForgotten(connection: Connection, build: string): null;
35
+ export declare function readAnswers(options: ReadAnswersOptions): ReadAnswers;
@@ -8,7 +8,7 @@ export type AttemptOptions = {
8
8
  };
9
9
  export type RecoveryOptions = {
10
10
  readonly firstMs?: number;
11
- readonly ceilingMs?: number;
11
+ readonly maxMs?: number;
12
12
  readonly attempts?: number;
13
13
  readonly inFlight?: number;
14
14
  };
@@ -20,5 +20,6 @@ export type Recovery = {
20
20
  scope(inFlight?: number): Recovery;
21
21
  retire(): Promise<void>;
22
22
  };
23
- export declare function retryDelay(tries: number, firstMs?: number, ceilingMs?: number): number;
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>;
24
25
  export declare function createRecovery(options?: RecoveryOptions): Recovery;
@@ -0,0 +1,26 @@
1
+ import type { AdapterFailure, Authorization, RefreshPage, RefreshRequest, RefreshResult, RetryableRefusal } from './adapter.js';
2
+ import type { Remodel } from './bootstrap.js';
3
+ import type { ReplicaRecord } from './replica.js';
4
+ import type { RefreshedPage } from './store.js';
5
+ import type { HeldEntry, StoredEntry } from './tables.js';
6
+ import { type Unconfirmed } from './transfer.js';
7
+ export type Advancement = {
8
+ kind: 'still-current';
9
+ } | {
10
+ kind: 'advanced';
11
+ record: ReplicaRecord;
12
+ changed: ReadonlySet<string>;
13
+ } | {
14
+ kind: 'beyond-horizon';
15
+ } | RetryableRefusal | Unconfirmed | AdapterFailure;
16
+ export type Refresher = (authorization: Authorization, request: RefreshRequest) => Promise<RefreshResult>;
17
+ export type Refreshing = {
18
+ turn(): void;
19
+ prior(paths: readonly string[]): Promise<ReadonlyMap<string, HeldEntry>>;
20
+ later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
21
+ stage(page: RefreshedPage): Promise<boolean>;
22
+ };
23
+ type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'binaryFiles'>;
24
+ export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
25
+ export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
26
+ export {};
@@ -1,45 +1,67 @@
1
- import { type ChangeBatch } from './change.js';
1
+ import { type TypedPath } from '../mdmodel/index.js';
2
+ import type { BootstrapInventory, SavedFacts, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
3
+ import { type ChangeBatch, type Precondition } from './change.js';
2
4
  import { type Collection, type Composition } from './collection.js';
5
+ import { type ModelState } from './model.js';
3
6
  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;
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>;
10
26
  };
11
27
  export type VisibleLayer = Layer & {
12
- collection: Collection;
28
+ readonly collection: Collection;
13
29
  };
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[];
30
+ export type Slice = Layer & {
31
+ readonly written: Readonly<Record<string, string>>;
32
+ readonly facts: Readonly<Record<string, SavedFacts>>;
33
+ readonly held: ReadonlySet<string>;
23
34
  };
24
- type ReplayStep = {
25
- id: string;
26
- before: Layer;
27
- after: Layer;
28
- effective: ChangeBatch;
29
- collection?: Collection;
35
+ export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
36
+ export declare function storedRecord(record: ReplicaRecord): string;
37
+ export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
38
+ export type LayerEntry = Omit<StoredEntry, 'facts'>;
39
+ export declare function entryAt(layer: Layer & {
40
+ readonly written?: Readonly<Record<string, string>>;
41
+ }, path: string): LayerEntry | null;
42
+ export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
43
+ export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
44
+ export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
45
+ export type Replayed = {
46
+ readonly visible: VisibleLayer;
47
+ readonly touched: ReadonlySet<string>;
30
48
  };
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';
49
+ export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
50
+ export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
51
+ export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
52
+ export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
53
+ export type Standing = {
54
+ readonly withdrawn: readonly ChangeBatch[];
55
+ readonly kept: readonly ChangeBatch[];
37
56
  };
57
+ export declare function standing(confirmed: Slice, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean, locator: string, composition: Composition): Generator<number, Standing, void>;
38
58
  type Accepted = Extract<MutationResult, {
39
59
  kind: 'accepted';
40
60
  }>;
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[];
61
+ export type Returned = {
62
+ readonly set: readonly StoredEntry[];
63
+ readonly removed: readonly string[];
64
+ };
65
+ export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
66
+ export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
45
67
  export {};
@@ -32,6 +32,7 @@ export type RoomDraftParts = {
32
32
  readonly creation?: RoomDraftCreation;
33
33
  readonly move?: {
34
34
  readonly to: string;
35
+ readonly room?: string;
35
36
  readonly base?: string | null;
36
37
  };
37
38
  readonly removal?: {
@@ -39,11 +40,12 @@ export type RoomDraftParts = {
39
40
  };
40
41
  readonly file?: {
41
42
  readonly blob: Blob;
43
+ readonly base?: string | null;
42
44
  };
43
45
  };
44
46
  export type HeldFile = {
45
- readonly blob: Blob;
46
47
  readonly localId: string;
48
+ readonly name?: string;
47
49
  readonly byteLength: number;
48
50
  readonly mediaType: string;
49
51
  readonly sha256: string;
@@ -69,6 +71,7 @@ type HeldParts = {
69
71
  readonly creation?: RoomDraftCreation;
70
72
  readonly move?: {
71
73
  readonly to: string;
74
+ readonly room?: string;
72
75
  readonly base: string | null;
73
76
  };
74
77
  readonly removal?: {
@@ -87,9 +90,9 @@ type ChangedUnderneath = {
87
90
  readonly file?: string | null;
88
91
  };
89
92
  export type ReturnReason = ProviderRefusal & {
90
- readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
93
+ readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
91
94
  };
92
- export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
95
+ export declare function returnedBy(kind: 'withdrawn'): ReturnReason;
93
96
  export type RoomDraft = {
94
97
  readonly room: string;
95
98
  readonly path: string;
@@ -110,7 +113,7 @@ export type RoomDraftWrite = {
110
113
  export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
111
114
  export type ChangedPart = {
112
115
  readonly path: string;
113
- readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal' | 'file'>;
116
+ readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
114
117
  readonly name?: string;
115
118
  };
116
119
  export type RoomDraftRecord = {
@@ -124,16 +127,44 @@ export type SavedDraft = {
124
127
  readonly path: string;
125
128
  readonly parts: HeldParts;
126
129
  };
127
- export declare function readParts(value: unknown): RoomDraftParts;
130
+ export declare function readParts(value: unknown, path: string): RoomDraftParts;
131
+ export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
128
132
  export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
129
133
  export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
130
134
  export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
131
135
  export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
132
- export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
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;
133
150
  export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
134
151
  export declare function moveTarget(move: {
135
152
  readonly to: string;
136
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
+ };
137
168
  export declare function changesOf(path: string, parts: HeldParts): {
138
169
  changes: readonly Change[];
139
170
  bases: readonly Precondition[];
@@ -0,0 +1,23 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type VisibleLayer } from './replica.js';
3
+ import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { Store } from './store.js';
6
+ export type RoomDraftSurface = {
7
+ list(): Promise<readonly RoomDraft[]>;
8
+ read(room: string, path: string): Promise<RoomDraft | null>;
9
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
10
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
11
+ };
12
+ export type PresentationSurface = {
13
+ read(app: string): Promise<unknown>;
14
+ write(app: string, value: unknown): Promise<void>;
15
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
16
+ };
17
+ export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
18
+ export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
19
+ export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
20
+ export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
21
+ export declare function presentationSurface(runtime: Runtime): PresentationSurface;
22
+ export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
23
+ export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
@@ -0,0 +1,41 @@
1
+ import type { Authorization, DiscoveredRoom, ScopedRefusal, TypedPath } from './adapter.js';
2
+ import type { ChangeSet } from './change-set.js';
3
+ import type { ChangeBatch } from './change.js';
4
+ import type { RuntimeShell } from './durability.js';
5
+ import type { ConversationStore } from './conversation.js';
6
+ import type { FiguresRead } from './figures.js';
7
+ import type { Withheld } from './install.js';
8
+ import type { LiveQueries } from './live.js';
9
+ import type { Log } from './log.js';
10
+ import type { ModelState } from './model.js';
11
+ import type { ReadAnswers } from './reads.js';
12
+ import type { Recovery } from './recovery.js';
13
+ import type { ReplicaRecord } from './replica.js';
14
+ import type { RuntimeSocket, RoomDeclaration } from './socket.js';
15
+ import type { CycleProgress } from './status.js';
16
+ import type { Settling } from './saves.js';
17
+ import type { HeldCover, RuntimeStore, Store, Work } from './store.js';
18
+ import type { schemaTypes } from './attached-model.js';
19
+ export type Runtime = {
20
+ readonly store: Store;
21
+ readonly socket: RuntimeSocket;
22
+ readonly journal: Log;
23
+ readonly recovery: Recovery;
24
+ readonly shell: RuntimeShell;
25
+ readonly localSaves: boolean;
26
+ readonly roomTypes: Parameters<typeof schemaTypes>[1];
27
+ readonly builtIn: ModelState;
28
+ readonly typedPaths: readonly TypedPath[];
29
+ readonly usableWhenHeld: readonly string[];
30
+ readonly build: string;
31
+ readonly conversations: ConversationStore;
32
+ readonly liveQueries: LiveQueries<HeldCover>;
33
+ readonly figures: FiguresRead;
34
+ readonly lastAnswers: ReadAnswers;
35
+ settle(local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
36
+ scoped(result: ScopedRefusal, room: RoomDeclaration, local: RuntimeStore): Promise<void>;
37
+ submitLater(locator: string): void;
38
+ unpair(local: RuntimeStore): Promise<void>;
39
+ advanced(room: DiscoveredRoom, local: RuntimeStore, authorized: Authorization): Promise<Withheld | null>;
40
+ withhold(withheld: Withheld, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress): Promise<void>;
41
+ };
@@ -1,6 +1,8 @@
1
- import type { ProviderLimit } from './adapter.js';
1
+ import { type Validation } from '../mdmodel/index.js';
2
+ import type { OperationScopes, ProviderLimit } from './adapter.js';
2
3
  import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from './change.js';
3
4
  import { type Composition } from './collection.js';
5
+ import { type Layer } from './overlay.js';
4
6
  import type { VisibleLayer } from './replica.js';
5
7
  import type { ChangedPart } from './room-draft.js';
6
8
  export type SaveRefusal = {
@@ -19,25 +21,29 @@ export type SaveInput = {
19
21
  providerOwnedPaths: readonly string[];
20
22
  providerLimits: readonly ProviderLimit[];
21
23
  visible: VisibleLayer;
24
+ folders: ReadonlySet<string>;
22
25
  handle: string;
23
26
  changes: readonly Change[];
24
27
  bases: readonly Precondition[];
25
28
  queued?: ReadonlySet<string>;
26
29
  writtenBy?: WrittenBy;
27
- clean?: {
28
- text: Readonly<Record<string, string>>;
29
- binaries: Readonly<Record<string, unknown>>;
30
- composition: Composition;
31
- };
30
+ unmodeled: boolean;
31
+ validate: Validator;
32
32
  };
33
- export type BatchResult = {
34
- kind: 'batch';
35
- batch: ChangeBatch;
36
- } | {
33
+ export type Validator = (resulting: Layer, touched: readonly string[]) => Promise<Validation>;
34
+ type Refusing = {
37
35
  kind: 'refused';
38
36
  refusal: SaveRefusal;
39
37
  };
40
- export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): ChangeBatch;
38
+ export type BatchResult = {
39
+ kind: 'batch';
40
+ batch: ChangeBatch;
41
+ } | Refusing;
42
+ export declare function providerRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
43
+ export declare function leavingRewritten(batch: ChangeBatch, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
44
+ export declare function rewriting(batch: ChangeBatch, locator: string): boolean;
45
+ export declare function effectiveIn(batch: ChangeBatch, locator: string, visible: VisibleLayer): Generator<number, ChangeBatch, void>;
46
+ export declare function queuedDocuments(queue: readonly ChangeBatch[]): ReadonlySet<string>;
41
47
  export type Requeued = {
42
48
  kind: 'requeued';
43
49
  queue: readonly ChangeBatch[];
@@ -57,7 +63,40 @@ export type Joining = {
57
63
  kind: 'refused';
58
64
  refusal: SaveRefusal;
59
65
  };
60
- export declare function requeued(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: (queue: readonly ChangeBatch[]) => VisibleLayer): Requeued;
66
+ type VisibleOver = (queue: readonly ChangeBatch[]) => Generator<number, VisibleLayer, void>;
67
+ export declare function requeuing(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: VisibleOver): Generator<number, Requeued, void>;
61
68
  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;
69
+ export declare function limiting(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: VisibleOver): Generator<number, SaveRefusal | null, void>;
70
+ export declare const MOVE_DOCUMENTS = "move-documents";
71
+ export type MoveSide = {
72
+ room: string;
73
+ handle: string;
74
+ baseRoomVersion: string;
75
+ composition: Composition;
76
+ operations: OperationScopes;
77
+ providerOwnedPaths: readonly string[];
78
+ visible: VisibleLayer;
79
+ folders: ReadonlySet<string>;
80
+ queued: ReadonlySet<string>;
81
+ unmodeled: boolean;
82
+ validate: Validator;
83
+ };
84
+ export type MoveInput = {
85
+ source: MoveSide;
86
+ destination: MoveSide;
87
+ moves: readonly {
88
+ readonly path: string;
89
+ readonly to: string;
90
+ }[];
91
+ providerLimits: readonly ProviderLimit[];
92
+ local: boolean;
93
+ writtenBy?: WrittenBy;
94
+ };
95
+ export type MoveResult = {
96
+ kind: 'moved';
97
+ leaving: ChangeBatch;
98
+ arriving: ChangeBatch;
99
+ } | Refusing;
100
+ export declare function buildMove(input: MoveInput): Promise<MoveResult>;
101
+ export declare function buildBatch(input: SaveInput): Promise<BatchResult>;
102
+ export {};
@@ -0,0 +1,69 @@
1
+ import { type ChangeSet } from './change-set.js';
2
+ import { type ChangeBatch, type WrittenBy } from './change.js';
3
+ import { type AttachAnswer, type BinaryLinkAnswer, type HeldBinaryAnswer, type HeldShownAnswer } from './outcome.js';
4
+ import { type HeldReplica, type ReplicaRecord, type Slice, type VisibleLayer } from './replica.js';
5
+ import { type ReturnReason, type RoomDraftParts } from './room-draft.js';
6
+ import type { Runtime } from './runtime.js';
7
+ import { type SaveRefusal } from './save.js';
8
+ import type { AuthoredWrite, CommittedWrite, PendingState, RoomCommit, RuntimeStore, Store, StoredEntry, View, Work } from './store.js';
9
+ export type SaveResult = {
10
+ outcome: 'saved';
11
+ identifier: string;
12
+ } | ({
13
+ outcome: 'refused';
14
+ } & SaveRefusal);
15
+ export type SavedRoomDraft = {
16
+ readonly path: string;
17
+ readonly revision: string;
18
+ };
19
+ export type SavedParts = {
20
+ readonly path: string;
21
+ readonly parts: RoomDraftParts;
22
+ };
23
+ export type BinaryFileSurface = {
24
+ read(room: string, path: string, revision?: string): Promise<HeldBinaryAnswer>;
25
+ link(room: string, path: string, revision?: string): Promise<BinaryLinkAnswer>;
26
+ show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
27
+ attach(room: string, file: File): Promise<AttachAnswer>;
28
+ part(file: string, part: number): Promise<Uint8Array | null>;
29
+ };
30
+ export type Leaving = {
31
+ batch: ChangeBatch;
32
+ returned: ReturnReason | null;
33
+ };
34
+ export declare function withdrawable(states: ReadonlyMap<string, PendingState>): (batch: ChangeBatch) => boolean;
35
+ export declare function sliceAt(store: Store, record: ReplicaRecord, view: View, queue: readonly ChangeBatch[], extra?: Iterable<string>, moved?: Iterable<string>): Promise<Slice>;
36
+ export declare function landedWhole(store: Store, locator: string, batch: ChangeBatch, confirmedLayer: Slice, current?: Readonly<Record<string, string>>): Promise<boolean>;
37
+ export type Settling = {
38
+ leaving?: readonly Leaving[];
39
+ room?: boolean;
40
+ view?: View;
41
+ commit?: Pick<RoomCommit, 'published' | 'refreshed'>;
42
+ changes?: {
43
+ readonly set: readonly StoredEntry[];
44
+ readonly removed: readonly string[];
45
+ };
46
+ };
47
+ export declare function preparedAfter(runtime: Runtime, locator: string, answer: CommittedWrite): void;
48
+ export declare function replayed(store: Store, record: ReplicaRecord, confirmedLayer: Slice, queue: readonly ChangeBatch[]): import("./turn.js").Later<import("./replica.js").Replayed>;
49
+ export declare function overlayDiff(record: ReplicaRecord, before: HeldReplica | undefined, visible: VisibleLayer, touched: ReadonlySet<string>): Promise<{
50
+ overlay: NonNullable<RoomCommit['overlay']>;
51
+ touched: ReadonlySet<string>;
52
+ }>;
53
+ export type Settlement = {
54
+ readonly locator: string;
55
+ readonly left: readonly ChangeBatch[];
56
+ readonly commit: {
57
+ readonly rooms: readonly RoomCommit[];
58
+ readonly writes: readonly AuthoredWrite[];
59
+ };
60
+ apply(answer: CommittedWrite): ChangeSet;
61
+ };
62
+ export declare function settle(runtime: Runtime, local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
63
+ export declare function together(runtime: Runtime, local: RuntimeStore, settlements: readonly Settlement[]): Promise<ChangeSet>;
64
+ export declare function settlement(runtime: Runtime, local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<Settlement>;
65
+ export declare function unpairing(runtime: Runtime, local: RuntimeStore, locator: string, batches: readonly ChangeBatch[]): Promise<Settlement>;
66
+ export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
67
+ export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
68
+ export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
69
+ export declare function binaryFileSurface(runtime: Runtime): BinaryFileSurface;