@agentshouse/mdruntime 0.1.0-c5f333dfa0583 → 0.1.0-c5fe3b2cddda7
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 +10 -8
- package/dist/adapter.d.ts +39 -40
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +2 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +28 -4
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +16 -8
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +142 -94
- package/dist/change-set.d.ts +1 -7
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +1 -4
- package/dist/client.d.ts +6 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -7
- package/dist/collection.d.ts +5 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +24 -19
- package/dist/compile.d.ts +6 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +94 -33
- package/dist/connection.d.ts +8 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1160 -1151
- package/dist/conversation.d.ts +7 -5
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +171 -55
- package/dist/durability.d.ts +1 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +1 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +1 -1
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +370 -0
- package/dist/host.d.ts +3 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +42 -18
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +2 -1
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +3 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +93 -38
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +6 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -10
- package/dist/observation.d.ts +1 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +1 -1
- package/dist/outcome.d.ts +13 -6
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +16 -5
- package/dist/overlay.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +10 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +12 -1
- package/dist/reach.d.ts +8 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +69 -46
- package/dist/readiness.d.ts +14 -15
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +9 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +64 -30
- package/dist/replica.d.ts +5 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -7
- package/dist/room-draft.d.ts +18 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +73 -6
- package/dist/rows.d.ts +15 -6
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +102 -74
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +13 -7
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -296
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +4 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +23 -58
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +37 -272
- package/dist/stored.d.ts +10 -23
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +217 -218
- package/dist/tables.d.ts +51 -46
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +94 -53
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +35 -96
- package/dist/wire.d.ts +5 -5
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -2
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +156 -0
- package/package.json +11 -19
- package/AGENTS.md +0 -312
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/context.js +0 -10
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -254
- package/dist/chat/messages.d.ts +0 -35
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -210
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -307
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -98
package/dist/store.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import type { Capability, Member, ProviderLimit } from './adapter.js';
|
|
2
|
-
import type { AcceptedMessage, KeptReceipt } from './adapter.js';
|
|
1
|
+
import type { BootstrapInventory, Capability, ListedConversation, Member, ProviderLimit } from './adapter.js';
|
|
3
2
|
import type { ChangeBatch } from './change.js';
|
|
4
|
-
import type
|
|
3
|
+
import { type Composition } from './collection.js';
|
|
5
4
|
import type { Plan } from './query.js';
|
|
6
5
|
import type { ReplicaRecord } from './replica.js';
|
|
7
|
-
import type { Later } from './turn.js';
|
|
8
6
|
import type { Submission } from './outcome.js';
|
|
9
7
|
import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
|
|
10
|
-
import type { ModelState } from './model.js';
|
|
11
|
-
import type {
|
|
12
|
-
import type { CommittedWrite, CountedRoom, HeldEntry, QueryAnswer, QueryRoom, Referrer, RoomCommit, RuntimeDatabase, StoredEntry, StoredFile, TypedEntry, View
|
|
13
|
-
export
|
|
8
|
+
import type { ModelState, StoredModel } from './model.js';
|
|
9
|
+
import type { SearchWindow } from './search.js';
|
|
10
|
+
import type { CommittedWrite, ConversationWrite, CountedRoom, HeldConversation, HeldEntry, MessageWindow, QueryAnswer, QueryRoom, Referrer, RoomCommit, RuntimeDatabase, SearchAsk, StoredEntry, StoredFile, TypedEntry, View } from './tables.js';
|
|
11
|
+
export type { ConversationWrite, HeldConversation, MessageWindow } from './tables.js';
|
|
14
12
|
export type TransferRecord = {
|
|
15
13
|
readonly locator: string;
|
|
16
14
|
readonly transfer: string;
|
|
17
15
|
readonly selection: string;
|
|
18
16
|
readonly from: string;
|
|
19
17
|
readonly last: string;
|
|
20
|
-
readonly
|
|
18
|
+
readonly done: BootstrapInventory;
|
|
21
19
|
readonly models: {
|
|
22
20
|
readonly collection: ModelState;
|
|
23
|
-
readonly selection: ModelState;
|
|
24
21
|
};
|
|
25
22
|
readonly key: number | null;
|
|
26
23
|
};
|
|
24
|
+
export type StoredReplica = Omit<ReplicaRecord, 'model'> & {
|
|
25
|
+
readonly model: StoredModel;
|
|
26
|
+
};
|
|
27
27
|
export type PendingState = {
|
|
28
28
|
readonly drafts: readonly SavedDraft[];
|
|
29
29
|
readonly submission: Submission;
|
|
30
30
|
readonly lost: boolean;
|
|
31
31
|
readonly upload?: unknown;
|
|
32
|
-
readonly accepted?: string;
|
|
33
32
|
};
|
|
34
33
|
export type TargetRecord = {
|
|
35
34
|
established: boolean;
|
|
@@ -45,23 +44,6 @@ export type PresentationRecord = {
|
|
|
45
44
|
app: string;
|
|
46
45
|
value: unknown;
|
|
47
46
|
};
|
|
48
|
-
export type HeldConversation = {
|
|
49
|
-
conversation: string;
|
|
50
|
-
read: string | null | undefined;
|
|
51
|
-
partial: boolean;
|
|
52
|
-
};
|
|
53
|
-
export type MessageWindow = {
|
|
54
|
-
messages: AcceptedMessage[];
|
|
55
|
-
more: boolean;
|
|
56
|
-
};
|
|
57
|
-
export type ConversationWrite = {
|
|
58
|
-
conversation: string;
|
|
59
|
-
messages: readonly AcceptedMessage[];
|
|
60
|
-
read?: {
|
|
61
|
-
at: string | null;
|
|
62
|
-
partial: boolean;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
47
|
export type ChatSubmission = {
|
|
66
48
|
readonly operation: string;
|
|
67
49
|
readonly text: string;
|
|
@@ -86,10 +68,6 @@ export type AuthoredWrite = {
|
|
|
86
68
|
saved?: ReadonlyMap<string, readonly SavedDraft[]>;
|
|
87
69
|
roomDrafts?: readonly RoomDraftRecord[];
|
|
88
70
|
consumedRoomDrafts?: readonly string[];
|
|
89
|
-
accepted?: readonly {
|
|
90
|
-
readonly id: string;
|
|
91
|
-
readonly roomVersion: string;
|
|
92
|
-
}[];
|
|
93
71
|
};
|
|
94
72
|
export type StagedPage = {
|
|
95
73
|
readonly entries: readonly StoredEntry[];
|
|
@@ -100,9 +78,8 @@ export type RefreshedPage = StagedPage & {
|
|
|
100
78
|
readonly folderRemovals: readonly string[];
|
|
101
79
|
};
|
|
102
80
|
export type Opened = {
|
|
103
|
-
readonly rooms: ReadonlyMap<string,
|
|
104
|
-
readonly
|
|
105
|
-
readonly unprepared: ReadonlySet<number>;
|
|
81
|
+
readonly rooms: ReadonlyMap<string, StoredReplica>;
|
|
82
|
+
readonly unindexed: ReadonlySet<number>;
|
|
106
83
|
readonly overlaid: ReadonlyMap<number, ReadonlySet<string>>;
|
|
107
84
|
readonly erasing: boolean;
|
|
108
85
|
readonly orphans: readonly number[];
|
|
@@ -112,6 +89,7 @@ export type Opened = {
|
|
|
112
89
|
readonly member: Member | null;
|
|
113
90
|
readonly targets: Readonly<Record<string, TargetRecord>>;
|
|
114
91
|
readonly presentation: readonly PresentationRecord[];
|
|
92
|
+
readonly conversationList: readonly ListedConversation[] | null;
|
|
115
93
|
};
|
|
116
94
|
export type Commit = {
|
|
117
95
|
readonly rooms: readonly RoomCommit[];
|
|
@@ -128,25 +106,25 @@ export type RuntimeStore = {
|
|
|
128
106
|
entries(key: number, view: View, paths: readonly string[]): Promise<readonly HeldEntry[]>;
|
|
129
107
|
typed(key: number, view: View, paths: readonly string[]): Promise<readonly TypedEntry[]>;
|
|
130
108
|
referrers(key: number, view: View, targets: readonly string[], kinds: readonly string[]): Promise<readonly Referrer[]>;
|
|
131
|
-
walk(key: number, view: View, after: string | null, bytes: number): Promise<Walked>;
|
|
132
109
|
files(key: number, view: View, after: string | null, limit: number): Promise<readonly {
|
|
133
110
|
readonly path: string;
|
|
134
111
|
readonly revision: string;
|
|
135
112
|
}[]>;
|
|
113
|
+
folders(key: number, view: View, paths: readonly string[]): Promise<readonly string[]>;
|
|
136
114
|
typedWithin(key: number, view: View, roots: readonly string[], within: boolean): Promise<boolean>;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}>;
|
|
141
|
-
stage(record: TransferRecord, composition: Composition, page: StagedPage, key: number | null, last: boolean): Promise<number | null>;
|
|
142
|
-
refresh(key: number, page: RefreshedPage): Promise<void>;
|
|
115
|
+
search(ask: SearchAsk): Promise<SearchWindow>;
|
|
116
|
+
stage(record: TransferRecord, composition: Composition, page: StagedPage): Promise<number | null>;
|
|
117
|
+
refresh(key: number, composition: Composition, page: RefreshedPage): Promise<void>;
|
|
143
118
|
unrefresh(key: number): Promise<void>;
|
|
144
119
|
commit(commit: Commit): Promise<CommittedWrite>;
|
|
145
120
|
fence(locators: readonly string[]): Promise<void>;
|
|
146
121
|
erase(locator: string | null, limit: number): Promise<boolean>;
|
|
147
|
-
abandon(locator: string
|
|
122
|
+
abandon(locator: string): Promise<void>;
|
|
148
123
|
release(key: number): Promise<void>;
|
|
149
|
-
rederive(key: number,
|
|
124
|
+
rederive(key: number, composition: Composition, bytes: number, ms: number, floor: number): Promise<{
|
|
125
|
+
readonly done: boolean;
|
|
126
|
+
readonly text: number;
|
|
127
|
+
}>;
|
|
150
128
|
fact(name: string, value: unknown): Promise<void>;
|
|
151
129
|
queues(): Promise<readonly QueueRecord[]>;
|
|
152
130
|
submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;
|
|
@@ -157,8 +135,6 @@ export type RuntimeStore = {
|
|
|
157
135
|
keepMessages(write: ConversationWrite): Promise<void>;
|
|
158
136
|
messageWindow(conversation: string, limit: number, before: readonly [string, string] | null): Promise<MessageWindow>;
|
|
159
137
|
messageCount(conversation: string): Promise<number>;
|
|
160
|
-
messagesAfter(conversation: string, identity: string | null): Promise<AcceptedMessage[]>;
|
|
161
|
-
messageIdentities(conversation: string): Promise<readonly string[]>;
|
|
162
138
|
turnArrived(conversation: string, turn: string): Promise<boolean>;
|
|
163
139
|
dropConversations(conversations: readonly string[]): Promise<void>;
|
|
164
140
|
chatDrafts(): Promise<readonly ChatDraftRecord[]>;
|
|
@@ -170,20 +146,9 @@ export type RuntimeStore = {
|
|
|
170
146
|
keepRoomDraft(record: RoomDraftRecord, files: readonly StoredFile[]): Promise<void>;
|
|
171
147
|
discardRoomDraft(locator: string, path: string): Promise<void>;
|
|
172
148
|
fences(): Promise<readonly string[]>;
|
|
173
|
-
receivedHeads(): Promise<readonly KeptReceipt[]>;
|
|
174
|
-
receivedParts(key: string, count: number): Promise<readonly unknown[]>;
|
|
175
|
-
keepReceived(key: string, head: unknown, part?: {
|
|
176
|
-
index: number;
|
|
177
|
-
value: unknown;
|
|
178
|
-
}): Promise<void>;
|
|
179
|
-
dropReceived(keys: readonly string[]): Promise<void>;
|
|
180
149
|
generation(): Promise<string | null>;
|
|
181
150
|
rememberGeneration(value: string): Promise<void>;
|
|
182
151
|
file(key: string, type: string): Promise<Blob>;
|
|
183
|
-
close(): void;
|
|
184
152
|
};
|
|
185
|
-
export declare function
|
|
186
|
-
export declare function endRuntimeStore(database: RuntimeDatabase, holder: string | undefined): Promise<boolean>;
|
|
187
|
-
export declare function openDatabase(name: string, version: number, upgrade: (opening: IDBOpenDBRequest, oldVersion: number) => void): Promise<IDBDatabase>;
|
|
188
|
-
export declare function openRuntimeStore(fenced: (locator: string) => boolean, authored: RuntimeDatabase): Promise<RuntimeStore>;
|
|
153
|
+
export declare function openRuntimeStore(fenced: (locator: string) => boolean, authored: RuntimeDatabase): RuntimeStore;
|
|
189
154
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":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E,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IACrC,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACrC,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC;AA6FF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,EACpC,QAAQ,EAAE,eAAe,GACxB,YAAY,CAkSd"}
|
package/dist/store.js
CHANGED
|
@@ -1,123 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { composedOf } from './collection.js';
|
|
2
2
|
import { binaryLocalId } from './identity.js';
|
|
3
|
-
const DATABASE = 'mdruntime';
|
|
4
|
-
const CONVERSATIONS = 'conversations';
|
|
5
|
-
const MESSAGES = 'messages';
|
|
6
3
|
const FILE = '\u0000file';
|
|
7
|
-
export const STORE_SCHEMA = 26;
|
|
8
|
-
const STORES = [
|
|
9
|
-
[CONVERSATIONS, { keyPath: 'conversation' }],
|
|
10
|
-
[MESSAGES, { keyPath: ['conversation', 'identity'] }],
|
|
11
|
-
];
|
|
12
|
-
const READ_BATCH = 256;
|
|
13
|
-
const MESSAGE_INDEXES = [
|
|
14
|
-
['conversation', 'conversation'],
|
|
15
|
-
['position', ['conversation', 'position']],
|
|
16
|
-
['turn', ['conversation', 'turn']],
|
|
17
|
-
];
|
|
18
|
-
function settled(request) {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
request.onsuccess = () => resolve(request.result);
|
|
21
|
-
request.onerror = () => reject(request.error);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const turns = new Map();
|
|
25
|
-
function idle(database) {
|
|
26
|
-
return turns.get(database.name) ?? Promise.resolve();
|
|
27
|
-
}
|
|
28
|
-
export function transacted(database, stores, mode, work) {
|
|
29
|
-
let release = () => { };
|
|
30
|
-
const turn = new Promise((resolve) => {
|
|
31
|
-
release = resolve;
|
|
32
|
-
});
|
|
33
|
-
const before = idle(database);
|
|
34
|
-
const queued = before.then(() => turn);
|
|
35
|
-
turns.set(database.name, queued);
|
|
36
|
-
void queued.then(() => {
|
|
37
|
-
if (turns.get(database.name) === queued)
|
|
38
|
-
turns.delete(database.name);
|
|
39
|
-
});
|
|
40
|
-
return before.then(() => {
|
|
41
|
-
let transaction;
|
|
42
|
-
try {
|
|
43
|
-
transaction = database.transaction(stores, mode);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
release();
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
const committed = new Promise((resolve, reject) => {
|
|
50
|
-
transaction.oncomplete = () => {
|
|
51
|
-
release();
|
|
52
|
-
resolve();
|
|
53
|
-
};
|
|
54
|
-
transaction.onabort = () => {
|
|
55
|
-
release();
|
|
56
|
-
reject(transaction.error);
|
|
57
|
-
};
|
|
58
|
-
transaction.onerror = () => reject(transaction.error);
|
|
59
|
-
});
|
|
60
|
-
let value;
|
|
61
|
-
try {
|
|
62
|
-
value = work(transaction);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
void committed.catch(() => { });
|
|
66
|
-
transaction.abort();
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
return Promise.all([value, committed]).then(([held]) => held);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function accepted({ conversation: _held, ...message }) {
|
|
73
|
-
return message;
|
|
74
|
-
}
|
|
75
|
-
function removeDatabase(name) {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const removal = indexedDB.deleteDatabase(name);
|
|
78
|
-
removal.onsuccess = () => resolve();
|
|
79
|
-
removal.onerror = () => reject(removal.error);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
export async function endRuntimeStore(database, holder) {
|
|
83
|
-
await removeDatabase(DATABASE);
|
|
84
|
-
return database.ask({ kind: 'authored.end', holder: holder ?? null });
|
|
85
|
-
}
|
|
86
|
-
export function openDatabase(name, version, upgrade) {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const opening = indexedDB.open(name, version);
|
|
89
|
-
opening.onupgradeneeded = (event) => upgrade(opening, event.oldVersion);
|
|
90
|
-
opening.onsuccess = () => resolve(opening.result);
|
|
91
|
-
opening.onerror = () => {
|
|
92
|
-
if (opening.error?.name !== 'VersionError') {
|
|
93
|
-
reject(opening.error);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
removeDatabase(name)
|
|
97
|
-
.then(() => openDatabase(name, version, upgrade))
|
|
98
|
-
.then(resolve, reject);
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function openConversations() {
|
|
103
|
-
return openDatabase(DATABASE, STORE_SCHEMA, (opening, oldVersion) => {
|
|
104
|
-
const database = opening.result;
|
|
105
|
-
if (oldVersion < STORE_SCHEMA) {
|
|
106
|
-
for (const name of [...database.objectStoreNames])
|
|
107
|
-
database.deleteObjectStore(name);
|
|
108
|
-
}
|
|
109
|
-
for (const [name, parameters] of STORES) {
|
|
110
|
-
if (database.objectStoreNames.contains(name))
|
|
111
|
-
continue;
|
|
112
|
-
database.createObjectStore(name, parameters);
|
|
113
|
-
}
|
|
114
|
-
const messages = opening.transaction.objectStore(MESSAGES);
|
|
115
|
-
for (const [name, keyPath] of MESSAGE_INDEXES) {
|
|
116
|
-
if (!messages.indexNames.contains(name))
|
|
117
|
-
messages.createIndex(name, keyPath);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
4
|
function batchFiles(batch) {
|
|
122
5
|
return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
|
|
123
6
|
}
|
|
@@ -127,7 +10,7 @@ function draftFiles(drafts) {
|
|
|
127
10
|
function roomDraftRow(record) {
|
|
128
11
|
return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
|
|
129
12
|
}
|
|
130
|
-
function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts
|
|
13
|
+
function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts }, held) {
|
|
131
14
|
return {
|
|
132
15
|
locator,
|
|
133
16
|
...(queue === undefined
|
|
@@ -161,14 +44,6 @@ function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoom
|
|
|
161
44
|
}),
|
|
162
45
|
...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
|
|
163
46
|
...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
|
|
164
|
-
...(accepted === undefined
|
|
165
|
-
? {}
|
|
166
|
-
: {
|
|
167
|
-
amendments: accepted.map(({ id, roomVersion }) => ({
|
|
168
|
-
id,
|
|
169
|
-
amendment: JSON.stringify({ accepted: roomVersion }),
|
|
170
|
-
})),
|
|
171
|
-
}),
|
|
172
47
|
};
|
|
173
48
|
}
|
|
174
49
|
function marked(value) {
|
|
@@ -206,8 +81,7 @@ async function filed(value, read) {
|
|
|
206
81
|
function json(value, fallback) {
|
|
207
82
|
return value === undefined ? fallback : JSON.parse(value);
|
|
208
83
|
}
|
|
209
|
-
export
|
|
210
|
-
const database = await openConversations();
|
|
84
|
+
export function openRuntimeStore(fenced, authored) {
|
|
211
85
|
const keys = new WeakMap();
|
|
212
86
|
const read = async (key, type) => {
|
|
213
87
|
const blob = await authored.ask({ kind: 'authored.file', key, type });
|
|
@@ -239,7 +113,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
239
113
|
return {
|
|
240
114
|
async opened() {
|
|
241
115
|
const held = await authored.ask({ kind: 'replica.open' });
|
|
242
|
-
const
|
|
116
|
+
const unindexed = new Set(held.keys.flatMap(({ key, rederiving, searching }) => rederiving === null && searching === null ? [] : [key]));
|
|
243
117
|
const overlaid = new Map();
|
|
244
118
|
for (const { key, path } of held.overlaid) {
|
|
245
119
|
const paths = overlaid.get(key) ?? new Set();
|
|
@@ -253,13 +127,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
253
127
|
locator,
|
|
254
128
|
{ ...JSON.parse(record), key },
|
|
255
129
|
])),
|
|
256
|
-
|
|
257
|
-
.filter(({ locator }) => !fenced(locator))
|
|
258
|
-
.map(({ locator, key, record }) => [
|
|
259
|
-
locator,
|
|
260
|
-
{ ...JSON.parse(record), key },
|
|
261
|
-
])),
|
|
262
|
-
unprepared,
|
|
130
|
+
unindexed,
|
|
263
131
|
overlaid,
|
|
264
132
|
erasing: held.erasing.length > 0,
|
|
265
133
|
orphans: held.orphans,
|
|
@@ -272,6 +140,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
272
140
|
app,
|
|
273
141
|
value: JSON.parse(value),
|
|
274
142
|
})),
|
|
143
|
+
conversationList: json(held.facts.conversationList, null),
|
|
275
144
|
};
|
|
276
145
|
},
|
|
277
146
|
counts(rooms) {
|
|
@@ -292,37 +161,36 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
292
161
|
referrers(key, view, targets, kinds) {
|
|
293
162
|
return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
|
|
294
163
|
},
|
|
295
|
-
walk(key, view, after, bytes) {
|
|
296
|
-
return authored.ask({ kind: 'replica.walk', key, view, after, bytes });
|
|
297
|
-
},
|
|
298
164
|
files(key, view, after, limit) {
|
|
299
165
|
return authored.ask({ kind: 'replica.files', key, view, after, limit });
|
|
300
166
|
},
|
|
167
|
+
folders(key, view, paths) {
|
|
168
|
+
return authored.ask({ kind: 'replica.folders', key, view, paths });
|
|
169
|
+
},
|
|
301
170
|
typedWithin(key, view, roots, within) {
|
|
302
171
|
return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
|
|
303
172
|
},
|
|
304
|
-
|
|
305
|
-
return authored.ask({ kind: 'replica.
|
|
173
|
+
search(ask) {
|
|
174
|
+
return authored.ask({ kind: 'replica.search', ...ask });
|
|
306
175
|
},
|
|
307
|
-
async stage(record, composition, page
|
|
176
|
+
async stage(record, composition, page) {
|
|
308
177
|
if (fenced(record.locator))
|
|
309
178
|
return null;
|
|
310
|
-
const { key: _key, ...kept } = record;
|
|
311
179
|
return authored.ask({
|
|
312
180
|
kind: 'replica.stage',
|
|
313
181
|
locator: record.locator,
|
|
314
182
|
transfer: record.transfer,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
composition,
|
|
183
|
+
key: record.key,
|
|
184
|
+
fingerprint: composedOf(composition).fingerprint,
|
|
318
185
|
entries: page.entries,
|
|
319
186
|
folders: page.folders,
|
|
320
187
|
});
|
|
321
188
|
},
|
|
322
|
-
async refresh(key, page) {
|
|
189
|
+
async refresh(key, composition, page) {
|
|
323
190
|
await authored.ask({
|
|
324
191
|
kind: 'replica.refresh',
|
|
325
192
|
key,
|
|
193
|
+
composed: composedOf(composition),
|
|
326
194
|
entries: page.entries,
|
|
327
195
|
removals: page.removals,
|
|
328
196
|
folders: page.folders,
|
|
@@ -336,7 +204,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
336
204
|
const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
|
|
337
205
|
const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
|
|
338
206
|
if (refused !== undefined) {
|
|
339
|
-
return { fenced: refused.locator, counts: {}, changed: {},
|
|
207
|
+
return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
|
|
340
208
|
}
|
|
341
209
|
for (const room of rooms)
|
|
342
210
|
change(room.key);
|
|
@@ -361,17 +229,24 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
361
229
|
async erase(locator, limit) {
|
|
362
230
|
return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
|
|
363
231
|
},
|
|
364
|
-
async abandon(locator
|
|
232
|
+
async abandon(locator) {
|
|
365
233
|
if (fenced(locator))
|
|
366
|
-
return
|
|
367
|
-
|
|
234
|
+
return;
|
|
235
|
+
await authored.ask({ kind: 'replica.abandon', locator });
|
|
368
236
|
},
|
|
369
237
|
async release(key) {
|
|
370
238
|
await authored.ask({ kind: 'replica.release', key });
|
|
371
239
|
},
|
|
372
|
-
async rederive(key,
|
|
240
|
+
async rederive(key, composition, bytes, ms, floor) {
|
|
373
241
|
change(key);
|
|
374
|
-
return
|
|
242
|
+
return authored.ask({
|
|
243
|
+
kind: 'replica.rederive',
|
|
244
|
+
key,
|
|
245
|
+
composed: composedOf(composition),
|
|
246
|
+
bytes,
|
|
247
|
+
ms,
|
|
248
|
+
floor,
|
|
249
|
+
});
|
|
375
250
|
},
|
|
376
251
|
async fact(name, value) {
|
|
377
252
|
await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
|
|
@@ -417,110 +292,22 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
417
292
|
});
|
|
418
293
|
},
|
|
419
294
|
conversations() {
|
|
420
|
-
return
|
|
421
|
-
const records = await settled(transaction.objectStore(CONVERSATIONS).getAll());
|
|
422
|
-
const held = new Map(records.map(({ conversation, read, partial }) => [
|
|
423
|
-
conversation,
|
|
424
|
-
{ conversation, read, partial: partial === true },
|
|
425
|
-
]));
|
|
426
|
-
const keys = transaction.objectStore(MESSAGES).index('conversation');
|
|
427
|
-
await new Promise((resolve, reject) => {
|
|
428
|
-
const cursor = keys.openKeyCursor(null, 'nextunique');
|
|
429
|
-
cursor.onerror = () => reject(cursor.error);
|
|
430
|
-
cursor.onsuccess = () => {
|
|
431
|
-
const at = cursor.result;
|
|
432
|
-
if (at === null) {
|
|
433
|
-
resolve();
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
const conversation = at.key;
|
|
437
|
-
if (!held.has(conversation)) {
|
|
438
|
-
held.set(conversation, { conversation, read: undefined, partial: true });
|
|
439
|
-
}
|
|
440
|
-
at.continue();
|
|
441
|
-
};
|
|
442
|
-
});
|
|
443
|
-
return [...held.values()];
|
|
444
|
-
});
|
|
295
|
+
return authored.ask({ kind: 'conversation.held' });
|
|
445
296
|
},
|
|
446
|
-
async keepMessages(
|
|
447
|
-
await
|
|
448
|
-
const stored = transaction.objectStore(MESSAGES);
|
|
449
|
-
for (const message of messages) {
|
|
450
|
-
stored.put({ ...message, conversation });
|
|
451
|
-
}
|
|
452
|
-
if (read !== undefined) {
|
|
453
|
-
transaction.objectStore(CONVERSATIONS).put({
|
|
454
|
-
conversation,
|
|
455
|
-
read: read.at,
|
|
456
|
-
...(read.partial ? { partial: true } : {}),
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
});
|
|
297
|
+
async keepMessages(write) {
|
|
298
|
+
await authored.ask({ kind: 'conversation.keep', ...write });
|
|
460
299
|
},
|
|
461
300
|
messageWindow(conversation, limit, before) {
|
|
462
|
-
return
|
|
463
|
-
const index = transaction.objectStore(MESSAGES).index('position');
|
|
464
|
-
const range = IDBKeyRange.bound([conversation], [conversation, before?.[0] ?? []]);
|
|
465
|
-
const latest = [];
|
|
466
|
-
let more = false;
|
|
467
|
-
await new Promise((resolve, reject) => {
|
|
468
|
-
const cursor = index.openCursor(range, 'prev');
|
|
469
|
-
cursor.onerror = () => reject(cursor.error);
|
|
470
|
-
cursor.onsuccess = () => {
|
|
471
|
-
const at = cursor.result;
|
|
472
|
-
if (at === null) {
|
|
473
|
-
resolve();
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const record = at.value;
|
|
477
|
-
if (!precedes(record, before)) {
|
|
478
|
-
at.continue();
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (latest.length === limit) {
|
|
482
|
-
more = true;
|
|
483
|
-
resolve();
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
latest.push(accepted(record));
|
|
487
|
-
at.continue();
|
|
488
|
-
};
|
|
489
|
-
});
|
|
490
|
-
return { messages: latest.reverse(), more };
|
|
491
|
-
});
|
|
301
|
+
return authored.ask({ kind: 'conversation.window', conversation, limit, before });
|
|
492
302
|
},
|
|
493
303
|
messageCount(conversation) {
|
|
494
|
-
return
|
|
495
|
-
},
|
|
496
|
-
async messagesAfter(conversation, identity) {
|
|
497
|
-
const range = identity === null
|
|
498
|
-
? IDBKeyRange.bound([conversation], [conversation, []])
|
|
499
|
-
: IDBKeyRange.bound([conversation, identity], [conversation, []], true);
|
|
500
|
-
const held = await transacted(database, MESSAGES, 'readonly', (transaction) => settled(transaction.objectStore(MESSAGES).getAll(range, READ_BATCH)));
|
|
501
|
-
return held.map(accepted);
|
|
502
|
-
},
|
|
503
|
-
async messageIdentities(conversation) {
|
|
504
|
-
const found = await transacted(database, MESSAGES, 'readonly', (transaction) => settled(transaction.objectStore(MESSAGES).index('conversation').getAllKeys(conversation)));
|
|
505
|
-
return found.map((key) => key[1]);
|
|
304
|
+
return authored.ask({ kind: 'conversation.count', conversation });
|
|
506
305
|
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
return held > 0;
|
|
306
|
+
turnArrived(conversation, turn) {
|
|
307
|
+
return authored.ask({ kind: 'conversation.turn', conversation, turn });
|
|
510
308
|
},
|
|
511
309
|
async dropConversations(conversations) {
|
|
512
|
-
await authored.ask({ kind: '
|
|
513
|
-
await transacted(database, [CONVERSATIONS, MESSAGES], 'readwrite', (transaction) => {
|
|
514
|
-
const messages = transaction.objectStore(MESSAGES);
|
|
515
|
-
for (const conversation of conversations) {
|
|
516
|
-
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
517
|
-
const held = messages.index('conversation').getAllKeys(conversation);
|
|
518
|
-
held.onsuccess = () => {
|
|
519
|
-
for (const key of held.result)
|
|
520
|
-
messages.delete(key);
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
});
|
|
310
|
+
await authored.ask({ kind: 'conversation.drop', conversations });
|
|
524
311
|
},
|
|
525
312
|
async chatDrafts() {
|
|
526
313
|
const records = await authored.ask({ kind: 'authored.chatDrafts' });
|
|
@@ -574,25 +361,6 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
574
361
|
fences() {
|
|
575
362
|
return authored.ask({ kind: 'authored.fences' });
|
|
576
363
|
},
|
|
577
|
-
receivedHeads() {
|
|
578
|
-
return authored.ask({ kind: 'replica.received' });
|
|
579
|
-
},
|
|
580
|
-
receivedParts(key, count) {
|
|
581
|
-
return authored.ask({ kind: 'replica.receivedParts', key, count });
|
|
582
|
-
},
|
|
583
|
-
async keepReceived(key, head, part) {
|
|
584
|
-
await authored.ask({
|
|
585
|
-
kind: 'replica.receive',
|
|
586
|
-
key,
|
|
587
|
-
head: JSON.stringify(head),
|
|
588
|
-
...(part === undefined
|
|
589
|
-
? {}
|
|
590
|
-
: { part: { index: part.index, value: JSON.stringify(part.value) } }),
|
|
591
|
-
});
|
|
592
|
-
},
|
|
593
|
-
async dropReceived(keys) {
|
|
594
|
-
await authored.ask({ kind: 'replica.unreceive', keys });
|
|
595
|
-
},
|
|
596
364
|
generation() {
|
|
597
365
|
return fact('generation');
|
|
598
366
|
},
|
|
@@ -602,8 +370,5 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
602
370
|
file(key, type) {
|
|
603
371
|
return authored.ask({ kind: 'authored.file', key, type });
|
|
604
372
|
},
|
|
605
|
-
close() {
|
|
606
|
-
void idle(database).then(() => database.close());
|
|
607
|
-
},
|
|
608
373
|
};
|
|
609
374
|
}
|