@agentshouse/app-bridge 0.1.0-ccf413b4e709d → 0.1.0-cd2d3edbf9805
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.
- package/README.md +9 -7
- package/dist/calls.d.ts +747 -0
- package/dist/calls.js +1 -0
- package/dist/index.d.ts +44 -6
- package/dist/mdmodel/blocks.d.ts +10 -0
- package/dist/mdmodel/condition.d.ts +167 -0
- package/dist/mdmodel/definition.d.ts +81 -0
- package/dist/mdmodel/divide.d.ts +2 -0
- package/dist/mdmodel/document.d.ts +15 -0
- package/dist/mdmodel/fields.d.ts +5 -0
- package/dist/mdmodel/index.d.ts +20 -0
- package/dist/mdmodel/links.d.ts +28 -0
- package/dist/mdmodel/paths.d.ts +25 -0
- package/dist/mdmodel/profile.d.ts +5 -0
- package/dist/mdmodel/project.d.ts +21 -0
- package/dist/mdmodel/references.d.ts +3 -0
- package/dist/mdmodel/types.d.ts +167 -0
- package/dist/mdmodel/validate.d.ts +31 -0
- package/dist/mdmodel/version.d.ts +1 -0
- package/dist/mdmodel/yaml.d.ts +55 -0
- package/dist/mdruntime/adapter.d.ts +517 -0
- package/dist/mdruntime/binary.d.ts +17 -0
- package/dist/mdruntime/chain.d.ts +10 -0
- package/dist/mdruntime/change-set.d.ts +27 -0
- package/dist/mdruntime/change.d.ts +118 -0
- package/dist/mdruntime/client.d.ts +90 -0
- package/dist/mdruntime/collection.d.ts +27 -0
- package/dist/mdruntime/compile.d.ts +15 -0
- package/dist/mdruntime/connection.d.ts +152 -0
- package/dist/mdruntime/conversation.d.ts +113 -0
- package/dist/mdruntime/durability.d.ts +11 -0
- package/dist/mdruntime/failure.d.ts +12 -0
- package/dist/mdruntime/fulltext.d.ts +26 -0
- package/dist/mdruntime/identity.d.ts +6 -0
- package/dist/mdruntime/media.d.ts +7 -0
- package/dist/mdruntime/messages.d.ts +27 -0
- package/dist/mdruntime/model.d.ts +62 -0
- package/dist/mdruntime/observation.d.ts +44 -0
- package/dist/mdruntime/open.d.ts +1 -0
- package/dist/mdruntime/opened.d.ts +21 -0
- package/dist/mdruntime/outcome.d.ts +84 -0
- package/dist/mdruntime/overlay.d.ts +24 -0
- package/dist/mdruntime/query.d.ts +283 -0
- package/dist/mdruntime/reach.d.ts +53 -0
- package/dist/mdruntime/readiness.d.ts +51 -0
- package/dist/mdruntime/recovery.d.ts +25 -0
- package/dist/mdruntime/replica.d.ts +67 -0
- package/dist/mdruntime/room-draft.d.ts +173 -0
- package/dist/mdruntime/save.d.ts +102 -0
- package/dist/mdruntime/search.d.ts +72 -0
- package/dist/mdruntime/seed.d.ts +15 -0
- package/dist/mdruntime/status.d.ts +27 -0
- package/dist/mdruntime/store.d.ts +153 -0
- package/dist/mdruntime/stored.d.ts +129 -0
- package/dist/mdruntime/tables.d.ts +324 -0
- package/dist/mdruntime/wire.d.ts +238 -0
- package/dist/test-host.d.ts +8 -2
- package/dist/test-host.js +47 -11
- package/docs/families.md +55 -12
- package/package.json +8 -6
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Definition, ValueFacts, VerifiedModel } from '../mdmodel/index.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
3
|
+
export type ModelIdentity = {
|
|
4
|
+
identity: string;
|
|
5
|
+
version: string;
|
|
6
|
+
};
|
|
7
|
+
export type ModelSnapshot = ModelIdentity & {
|
|
8
|
+
schema: string | null;
|
|
9
|
+
revision: string | null;
|
|
10
|
+
};
|
|
11
|
+
export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired' | 'invalid'>;
|
|
12
|
+
export type ModelResult = {
|
|
13
|
+
kind: 'model';
|
|
14
|
+
snapshot: ModelSnapshot;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'model-unavailable';
|
|
17
|
+
reason: ModelUnavailableReason;
|
|
18
|
+
};
|
|
19
|
+
export type MdType = Definition;
|
|
20
|
+
export type ModelState = {
|
|
21
|
+
status: 'unavailable';
|
|
22
|
+
reason: ModelUnavailableReason;
|
|
23
|
+
schema?: string | null;
|
|
24
|
+
revision?: string | null;
|
|
25
|
+
} | {
|
|
26
|
+
status: 'current' | 'cached';
|
|
27
|
+
snapshot: ModelSnapshot;
|
|
28
|
+
verifiedWith: ModelIdentity;
|
|
29
|
+
types: VerifiedModel['types'];
|
|
30
|
+
};
|
|
31
|
+
export type StoredModel = Extract<ModelState, {
|
|
32
|
+
status: 'unavailable';
|
|
33
|
+
}> | Omit<Extract<ModelState, {
|
|
34
|
+
status: 'current' | 'cached';
|
|
35
|
+
}>, 'types'>;
|
|
36
|
+
export type TypesResult = {
|
|
37
|
+
status: Open<'unavailable'>;
|
|
38
|
+
reason: ModelUnavailableReason;
|
|
39
|
+
types: null;
|
|
40
|
+
schema?: string | null;
|
|
41
|
+
revision?: string | null;
|
|
42
|
+
} | {
|
|
43
|
+
status: Open<'current' | 'cached'>;
|
|
44
|
+
identity: string;
|
|
45
|
+
version: string;
|
|
46
|
+
verifiedWith: ModelIdentity;
|
|
47
|
+
types: readonly MdType[];
|
|
48
|
+
schema: string | null;
|
|
49
|
+
revision: string | null;
|
|
50
|
+
};
|
|
51
|
+
export type ValidationReceipt = {
|
|
52
|
+
identity: string;
|
|
53
|
+
version: string;
|
|
54
|
+
source: Open<'current' | 'cached'>;
|
|
55
|
+
};
|
|
56
|
+
export declare const NO_MODEL: ModelState;
|
|
57
|
+
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
58
|
+
export declare function modelTypes(state: ModelState): TypesResult;
|
|
59
|
+
export declare function storedModel(state: ModelState): StoredModel;
|
|
60
|
+
export declare function cached(state: ModelState): ModelState;
|
|
61
|
+
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
62
|
+
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
@@ -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) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
31
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: 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,283 @@
|
|
|
1
|
+
import { type Definition } 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 Value = string | number | boolean | null;
|
|
6
|
+
export type Predicate = Value | {
|
|
7
|
+
$eq: Value;
|
|
8
|
+
} | {
|
|
9
|
+
$ne: Value;
|
|
10
|
+
} | {
|
|
11
|
+
$in: readonly Value[];
|
|
12
|
+
} | {
|
|
13
|
+
$nin: readonly Value[];
|
|
14
|
+
} | {
|
|
15
|
+
$gt?: Value;
|
|
16
|
+
$gte?: Value;
|
|
17
|
+
$lt?: Value;
|
|
18
|
+
$lte?: Value;
|
|
19
|
+
} | {
|
|
20
|
+
$all: readonly Value[];
|
|
21
|
+
} | {
|
|
22
|
+
$size: number;
|
|
23
|
+
} | {
|
|
24
|
+
$exists: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type Where = {
|
|
27
|
+
$and?: readonly Where[];
|
|
28
|
+
$or?: readonly Where[];
|
|
29
|
+
[field: string]: Predicate | readonly Where[] | undefined;
|
|
30
|
+
};
|
|
31
|
+
export type Related = {
|
|
32
|
+
types?: readonly string[];
|
|
33
|
+
where?: Where;
|
|
34
|
+
pathPrefix?: string;
|
|
35
|
+
};
|
|
36
|
+
export type Filter = {
|
|
37
|
+
rooms?: readonly string[];
|
|
38
|
+
types?: readonly string[];
|
|
39
|
+
where?: Where;
|
|
40
|
+
pathPrefix?: string;
|
|
41
|
+
folder?: string;
|
|
42
|
+
paths?: readonly string[];
|
|
43
|
+
hop?: Related & {
|
|
44
|
+
field: string;
|
|
45
|
+
};
|
|
46
|
+
backlinks?: Related & {
|
|
47
|
+
field?: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type Key = 'room' | 'path' | 'type' | 'folder' | {
|
|
51
|
+
field: string;
|
|
52
|
+
};
|
|
53
|
+
export type Select = 'all' | {
|
|
54
|
+
fields?: 'all' | readonly string[];
|
|
55
|
+
sections?: 'all' | readonly string[];
|
|
56
|
+
preamble?: true;
|
|
57
|
+
markdown?: true;
|
|
58
|
+
backlinks?: true;
|
|
59
|
+
change?: true;
|
|
60
|
+
fileId?: true;
|
|
61
|
+
revision?: true;
|
|
62
|
+
};
|
|
63
|
+
export type OrderOptions = {
|
|
64
|
+
nulls?: 'first' | 'last';
|
|
65
|
+
stringSort?: 'lexical' | 'locale';
|
|
66
|
+
locale?: string;
|
|
67
|
+
localeOptions?: Readonly<Record<string, unknown>>;
|
|
68
|
+
};
|
|
69
|
+
export type Direction = 'asc' | 'desc';
|
|
70
|
+
export type DocumentQuery = Filter & {
|
|
71
|
+
select: Select;
|
|
72
|
+
orderBy?: readonly ({
|
|
73
|
+
by: Key;
|
|
74
|
+
direction?: Direction;
|
|
75
|
+
} & OrderOptions)[];
|
|
76
|
+
limit?: number;
|
|
77
|
+
after?: string;
|
|
78
|
+
total?: true;
|
|
79
|
+
};
|
|
80
|
+
export type GroupQuery = Filter & {
|
|
81
|
+
groupBy: readonly Exclude<Key, 'path'>[];
|
|
82
|
+
orderBy?: readonly {
|
|
83
|
+
by: 'count' | Exclude<Key, 'path'>;
|
|
84
|
+
direction?: Direction;
|
|
85
|
+
}[];
|
|
86
|
+
limit?: number;
|
|
87
|
+
after?: string;
|
|
88
|
+
total?: true;
|
|
89
|
+
};
|
|
90
|
+
export type LocalQuery = DocumentQuery | GroupQuery;
|
|
91
|
+
export type Backlink = {
|
|
92
|
+
path: string;
|
|
93
|
+
type: string;
|
|
94
|
+
field: string;
|
|
95
|
+
};
|
|
96
|
+
export type QueryDocument = {
|
|
97
|
+
room: string;
|
|
98
|
+
path: string;
|
|
99
|
+
type?: string;
|
|
100
|
+
fields?: Readonly<Record<string, unknown>>;
|
|
101
|
+
sections?: Readonly<Record<string, string>>;
|
|
102
|
+
preamble?: string;
|
|
103
|
+
markdown?: string;
|
|
104
|
+
backlinks?: readonly Backlink[];
|
|
105
|
+
change?: HeadChange | null;
|
|
106
|
+
fileId?: string | null;
|
|
107
|
+
revision?: string | null;
|
|
108
|
+
binaryFile?: BinaryFileRecord;
|
|
109
|
+
};
|
|
110
|
+
export type QueryGroup = {
|
|
111
|
+
key: readonly unknown[];
|
|
112
|
+
count: number;
|
|
113
|
+
};
|
|
114
|
+
export type CoveredRoom = {
|
|
115
|
+
room: string;
|
|
116
|
+
generation: string;
|
|
117
|
+
current: boolean;
|
|
118
|
+
};
|
|
119
|
+
export type QueryCoverage = {
|
|
120
|
+
rooms: readonly CoveredRoom[];
|
|
121
|
+
indexes: readonly string[];
|
|
122
|
+
overlay: readonly string[];
|
|
123
|
+
};
|
|
124
|
+
export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
|
|
125
|
+
export type PendingRoom = {
|
|
126
|
+
room: string;
|
|
127
|
+
awaits: Awaits;
|
|
128
|
+
};
|
|
129
|
+
export type PendingResult = {
|
|
130
|
+
pending: readonly PendingRoom[];
|
|
131
|
+
};
|
|
132
|
+
export type DocumentRows = {
|
|
133
|
+
documents: readonly QueryDocument[];
|
|
134
|
+
next?: string;
|
|
135
|
+
total?: number;
|
|
136
|
+
};
|
|
137
|
+
export type GroupRows = {
|
|
138
|
+
groups: readonly QueryGroup[];
|
|
139
|
+
next?: string;
|
|
140
|
+
total?: number;
|
|
141
|
+
};
|
|
142
|
+
export type QueryRows = DocumentRows | GroupRows;
|
|
143
|
+
export type DocumentResult = DocumentRows & {
|
|
144
|
+
coverage: QueryCoverage;
|
|
145
|
+
};
|
|
146
|
+
export type GroupResult = GroupRows & {
|
|
147
|
+
coverage: QueryCoverage;
|
|
148
|
+
};
|
|
149
|
+
export type QueryResult = DocumentResult | GroupResult | PendingResult;
|
|
150
|
+
export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
|
|
151
|
+
export type RoomFacts = {
|
|
152
|
+
locator: string;
|
|
153
|
+
available: boolean;
|
|
154
|
+
types: readonly Definition[];
|
|
155
|
+
};
|
|
156
|
+
export type HeldRooms = {
|
|
157
|
+
listed: boolean;
|
|
158
|
+
rooms: readonly RoomFacts[];
|
|
159
|
+
};
|
|
160
|
+
export type Test = {
|
|
161
|
+
op: 'eq';
|
|
162
|
+
value: Value;
|
|
163
|
+
} | {
|
|
164
|
+
op: 'ne';
|
|
165
|
+
value: Value;
|
|
166
|
+
} | {
|
|
167
|
+
op: 'in';
|
|
168
|
+
values: readonly Value[];
|
|
169
|
+
} | {
|
|
170
|
+
op: 'nin';
|
|
171
|
+
values: readonly Value[];
|
|
172
|
+
} | {
|
|
173
|
+
op: 'range';
|
|
174
|
+
bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
|
|
175
|
+
} | {
|
|
176
|
+
op: 'all';
|
|
177
|
+
values: readonly Value[];
|
|
178
|
+
} | {
|
|
179
|
+
op: 'size';
|
|
180
|
+
size: number;
|
|
181
|
+
} | {
|
|
182
|
+
op: 'exists';
|
|
183
|
+
exists: boolean;
|
|
184
|
+
};
|
|
185
|
+
export type Condition = {
|
|
186
|
+
every: readonly Condition[];
|
|
187
|
+
} | {
|
|
188
|
+
some: readonly Condition[];
|
|
189
|
+
} | {
|
|
190
|
+
field: string;
|
|
191
|
+
test: Test;
|
|
192
|
+
};
|
|
193
|
+
export type Scope = {
|
|
194
|
+
types: readonly string[] | null;
|
|
195
|
+
where: Condition | null;
|
|
196
|
+
pathPrefix: string | null;
|
|
197
|
+
};
|
|
198
|
+
export type KeyPlan = {
|
|
199
|
+
of: 'room';
|
|
200
|
+
} | {
|
|
201
|
+
of: 'path';
|
|
202
|
+
} | {
|
|
203
|
+
of: 'type';
|
|
204
|
+
} | {
|
|
205
|
+
of: 'folder';
|
|
206
|
+
} | {
|
|
207
|
+
of: 'field';
|
|
208
|
+
field: string;
|
|
209
|
+
};
|
|
210
|
+
export type DocumentShape = {
|
|
211
|
+
kind: 'documents';
|
|
212
|
+
fields: 'all' | readonly string[] | null;
|
|
213
|
+
sections: 'all' | readonly string[] | null;
|
|
214
|
+
preamble: boolean;
|
|
215
|
+
markdown: boolean;
|
|
216
|
+
backlinks: boolean;
|
|
217
|
+
change: boolean;
|
|
218
|
+
fileId: boolean;
|
|
219
|
+
revision: boolean;
|
|
220
|
+
orderBy: readonly {
|
|
221
|
+
key: KeyPlan;
|
|
222
|
+
options: OrderOptions & {
|
|
223
|
+
direction: Direction;
|
|
224
|
+
};
|
|
225
|
+
}[];
|
|
226
|
+
};
|
|
227
|
+
export type GroupShape = {
|
|
228
|
+
kind: 'groups';
|
|
229
|
+
groupBy: readonly KeyPlan[];
|
|
230
|
+
orderBy: readonly {
|
|
231
|
+
by: 'count' | number;
|
|
232
|
+
direction: Direction;
|
|
233
|
+
}[];
|
|
234
|
+
};
|
|
235
|
+
export type PlanArea = {
|
|
236
|
+
room: string;
|
|
237
|
+
path: string;
|
|
238
|
+
open: readonly string[];
|
|
239
|
+
};
|
|
240
|
+
export type PlanReach = {
|
|
241
|
+
rooms: readonly string[];
|
|
242
|
+
documents: readonly string[];
|
|
243
|
+
areas: readonly PlanArea[];
|
|
244
|
+
};
|
|
245
|
+
export type Continuation = {
|
|
246
|
+
text: string;
|
|
247
|
+
values: readonly unknown[] | null;
|
|
248
|
+
};
|
|
249
|
+
export type Plan = {
|
|
250
|
+
key: string;
|
|
251
|
+
rooms: readonly string[] | null;
|
|
252
|
+
reach: PlanReach | null;
|
|
253
|
+
locked: readonly string[];
|
|
254
|
+
root: Scope;
|
|
255
|
+
folder: string | null;
|
|
256
|
+
paths: readonly string[] | null;
|
|
257
|
+
hop: (Scope & {
|
|
258
|
+
field: string;
|
|
259
|
+
}) | null;
|
|
260
|
+
backlinks: (Scope & {
|
|
261
|
+
field: string | null;
|
|
262
|
+
}) | null;
|
|
263
|
+
shape: DocumentShape | GroupShape;
|
|
264
|
+
limit: number | null;
|
|
265
|
+
after: Continuation | null;
|
|
266
|
+
total: boolean;
|
|
267
|
+
};
|
|
268
|
+
export declare class QueryError extends Error {
|
|
269
|
+
readonly code: QueryErrorCode;
|
|
270
|
+
readonly retryable = false;
|
|
271
|
+
constructor(code: QueryErrorCode, at: string, problem: string);
|
|
272
|
+
}
|
|
273
|
+
type Entries = Readonly<Record<string, unknown>>;
|
|
274
|
+
export declare function invalid(at: string, problem: string): never;
|
|
275
|
+
export declare function plain(value: unknown): value is Entries;
|
|
276
|
+
export declare function known(value: Entries, allowed: readonly string[], at: string): void;
|
|
277
|
+
export declare function flag(input: unknown, at: string): boolean;
|
|
278
|
+
export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
279
|
+
export declare function limitOf(input: unknown): number | null;
|
|
280
|
+
export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
|
|
281
|
+
export declare function queryKey(query: unknown): string;
|
|
282
|
+
export declare function identityOf(plan: Plan): string;
|
|
283
|
+
export {};
|
|
@@ -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 Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
|
|
22
|
+
export type RuntimeView = {
|
|
23
|
+
md: MdRuntime;
|
|
24
|
+
watch: Watch;
|
|
25
|
+
};
|
|
26
|
+
export type NarrowedView = RuntimeView & {
|
|
27
|
+
narrow(reach: PortReach | null): void;
|
|
28
|
+
facts(port: ReadinessPort): 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: (message: unknown) => void): () => void;
|
|
34
|
+
search(input: unknown, reach: PortReach | null, locked: readonly string[]): 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, told: ReadinessPort): NarrowedView;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 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 Space = Open<'full'>;
|
|
22
|
+
export type InstallationStep = Open<'downloading' | 'writing' | 'replaying'>;
|
|
23
|
+
export type InstallationAmount = {
|
|
24
|
+
readonly done: number;
|
|
25
|
+
readonly total: number;
|
|
26
|
+
};
|
|
27
|
+
export type Installation = {
|
|
28
|
+
readonly step: InstallationStep | null;
|
|
29
|
+
readonly rooms: InstallationAmount;
|
|
30
|
+
readonly bytes: InstallationAmount;
|
|
31
|
+
};
|
|
32
|
+
export type ReadinessStatus = Open<'preparing' | 'paused' | '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 space: Space | null;
|
|
44
|
+
readonly installation: Installation;
|
|
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 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;
|