@pmate/chat-sdk 0.12.0-next.95 → 0.13.0-profile.0
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/lib/framework.d.ts +2 -0
- package/lib/framework.js +2 -0
- package/lib/messageView.d.ts +5 -0
- package/lib/messageView.js +2 -2
- package/lib/profile.d.ts +14 -0
- package/lib/profile.js +10 -0
- package/lib/profileWorker.d.ts +1 -0
- package/lib/profileWorker.js +3 -0
- package/lib/runtime/inboxClient.d.ts +3 -1
- package/lib/runtime/inboxClient.js +19 -1
- package/lib/runtime/profileChat.d.ts +135 -0
- package/lib/runtime/profileChat.js +299 -0
- package/lib/runtime/profileCommitQueue.d.ts +38 -0
- package/lib/runtime/profileCommitQueue.js +101 -0
- package/lib/runtime/profileCoordinator.d.ts +46 -0
- package/lib/runtime/profileCoordinator.js +135 -0
- package/lib/runtime/profileDatabase.d.ts +42 -0
- package/lib/runtime/profileDatabase.js +164 -0
- package/lib/runtime/profileGenerationBuilder.d.ts +18 -0
- package/lib/runtime/profileGenerationBuilder.js +112 -0
- package/lib/runtime/profileInboxFeed.d.ts +38 -0
- package/lib/runtime/profileInboxFeed.js +240 -0
- package/lib/runtime/profileMemoryStore.d.ts +113 -0
- package/lib/runtime/profileMemoryStore.js +259 -0
- package/lib/runtime/profileOutboxDispatcher.d.ts +31 -0
- package/lib/runtime/profileOutboxDispatcher.js +106 -0
- package/lib/runtime/profileOwner.d.ts +57 -0
- package/lib/runtime/profileOwner.js +202 -0
- package/lib/runtime/profileProjection.d.ts +77 -0
- package/lib/runtime/profileProjection.js +625 -0
- package/lib/runtime/profileReadingIndex.d.ts +17 -0
- package/lib/runtime/profileReadingIndex.js +99 -0
- package/lib/runtime/profileReplica.d.ts +59 -0
- package/lib/runtime/profileReplica.js +236 -0
- package/lib/runtime/profileStoreTypes.d.ts +163 -0
- package/lib/runtime/profileStoreTypes.js +1 -0
- package/lib/runtime/profileWindows.d.ts +38 -0
- package/lib/runtime/profileWindows.js +175 -0
- package/lib/runtime/profileWorkerHost.d.ts +33 -0
- package/lib/runtime/profileWorkerHost.js +156 -0
- package/package.json +11 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { voiceUploader } from "./voiceUpload.js";
|
|
2
|
+
/** Reads committed commands from owner memory. All status/ACK transitions return
|
|
3
|
+
* to the same durable queue; network waits never block local event processing. */
|
|
4
|
+
export class ProfileOutboxDispatcher {
|
|
5
|
+
options;
|
|
6
|
+
running;
|
|
7
|
+
timer;
|
|
8
|
+
scheduled;
|
|
9
|
+
off;
|
|
10
|
+
closed = false;
|
|
11
|
+
controller = new AbortController();
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
start() {
|
|
16
|
+
if (this.closed)
|
|
17
|
+
throw Error("PROFILE_OUTBOX_CLOSED");
|
|
18
|
+
if (!this.off)
|
|
19
|
+
this.off = this.options.owner.subscribeCommitted(() => this.schedule());
|
|
20
|
+
if (!this.timer)
|
|
21
|
+
this.timer = setInterval(() => this.schedule(), 10000);
|
|
22
|
+
this.schedule();
|
|
23
|
+
}
|
|
24
|
+
report(error) { try {
|
|
25
|
+
this.options.onError?.(error);
|
|
26
|
+
}
|
|
27
|
+
catch { } }
|
|
28
|
+
schedule() {
|
|
29
|
+
if (this.closed || this.scheduled || this.running)
|
|
30
|
+
return;
|
|
31
|
+
this.scheduled = setTimeout(() => { this.scheduled = undefined; void this.drain().catch(error => this.report(error)); }, 0);
|
|
32
|
+
}
|
|
33
|
+
drain() {
|
|
34
|
+
if (this.closed)
|
|
35
|
+
return Promise.reject(Error("PROFILE_OUTBOX_CLOSED"));
|
|
36
|
+
if (this.running)
|
|
37
|
+
return this.running;
|
|
38
|
+
const task = this.run();
|
|
39
|
+
this.running = task;
|
|
40
|
+
void task.finally(() => { if (this.running === task)
|
|
41
|
+
this.running = undefined; }).catch(() => { });
|
|
42
|
+
return task;
|
|
43
|
+
}
|
|
44
|
+
async transition(command, state) {
|
|
45
|
+
await this.options.owner.enqueue({ type: "commandResult", commandId: command.commandId, state }, 128, true);
|
|
46
|
+
}
|
|
47
|
+
async run() {
|
|
48
|
+
const owner = this.options.owner;
|
|
49
|
+
// Refresh from committed memory after each ACK so work accepted during a
|
|
50
|
+
// network wait is picked up without waiting for another ten-second tick.
|
|
51
|
+
while (!this.closed && owner.active) {
|
|
52
|
+
const command = owner.commands().sort((a, b) => a.createdAt - b.createdAt || a.commandId.localeCompare(b.commandId))[0];
|
|
53
|
+
if (!command)
|
|
54
|
+
return;
|
|
55
|
+
await this.transition(command, "sending");
|
|
56
|
+
if (this.closed || !owner.active)
|
|
57
|
+
return;
|
|
58
|
+
try {
|
|
59
|
+
if (command.kind === "message") {
|
|
60
|
+
const payload = command.payload;
|
|
61
|
+
let wire = payload.message ?? payload;
|
|
62
|
+
if (wire.hash !== command.messageId || wire.hash !== command.commandId || wire.from !== owner.identity.profileId)
|
|
63
|
+
throw Error("OUTBOX_MESSAGE_IDENTITY_MISMATCH");
|
|
64
|
+
if (payload.voiceBlob instanceof Blob) {
|
|
65
|
+
const url = await voiceUploader(owner.identity.profileId, this.options.uploadEndpoint, this.options.fetch)(payload.voiceBlob, this.controller.signal);
|
|
66
|
+
wire = structuredClone(wire);
|
|
67
|
+
const body = wire.body;
|
|
68
|
+
body.content.voice.url = url;
|
|
69
|
+
await owner.enqueue({ type: "commandPayload", commandId: command.commandId, message: wire }, 512, true);
|
|
70
|
+
}
|
|
71
|
+
await this.options.sendMessage(wire);
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
await this.reading(command);
|
|
75
|
+
if (!this.closed && owner.active)
|
|
76
|
+
await this.transition(command, "confirmed");
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (!this.closed && owner.active)
|
|
80
|
+
await this.transition(command, "failed");
|
|
81
|
+
this.report(error);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async reading(command) {
|
|
87
|
+
const response = await (this.options.fetch ?? fetch)(`${this.options.hubHttpUrl.replace(/\/$/, "")}/api/social/reading`, {
|
|
88
|
+
method: "POST", headers: { authorization: `Bearer ${await this.options.getToken()}`, "content-type": "application/json" },
|
|
89
|
+
body: JSON.stringify({ ...command.payload, operationId: command.commandId }),
|
|
90
|
+
signal: AbortSignal.any([this.controller.signal, AbortSignal.timeout(10000)]), cache: "no-store", redirect: "error",
|
|
91
|
+
});
|
|
92
|
+
if (!response.ok)
|
|
93
|
+
throw Error(`READ_SYNC_HTTP_${response.status}`);
|
|
94
|
+
const result = await response.json();
|
|
95
|
+
if (result.success !== true || result.data?.operationId !== command.commandId || result.data.accepted !== true || !Number.isSafeInteger(result.data.acceptedAt) || result.data.acceptedAt <= 0)
|
|
96
|
+
throw Error("INVALID_READING_RECEIPT");
|
|
97
|
+
}
|
|
98
|
+
async close() {
|
|
99
|
+
this.closed = true;
|
|
100
|
+
clearInterval(this.timer);
|
|
101
|
+
clearTimeout(this.scheduled);
|
|
102
|
+
this.off?.();
|
|
103
|
+
this.controller.abort();
|
|
104
|
+
await this.running;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ProfileDatabase } from "./profileDatabase.js";
|
|
2
|
+
import { ProfileMemoryStore, type ProfileDelta } from "./profileMemoryStore.js";
|
|
3
|
+
import { type ProfileOperation } from "./profileProjection.js";
|
|
4
|
+
import type { ProfileGenerationState } from "./profileStoreTypes.js";
|
|
5
|
+
import type { InboxBootstrap } from "./inboxStore.js";
|
|
6
|
+
export type ProfileOwnerOptions = {
|
|
7
|
+
database: ProfileDatabase;
|
|
8
|
+
epoch: string;
|
|
9
|
+
windowStart: number;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
onCommitted?: (delta: ProfileDelta) => void;
|
|
12
|
+
onError?: (error: unknown) => void;
|
|
13
|
+
windowMs?: number;
|
|
14
|
+
retryMs?: number;
|
|
15
|
+
};
|
|
16
|
+
/** The durable owner publishes only after commit. Network requests belong to
|
|
17
|
+
* the caller; neither the queue nor its transaction waits on connectivity. */
|
|
18
|
+
export declare class ProfileOwner {
|
|
19
|
+
private options;
|
|
20
|
+
readonly memory: ProfileMemoryStore;
|
|
21
|
+
private projection;
|
|
22
|
+
private queue;
|
|
23
|
+
private builder;
|
|
24
|
+
private lease;
|
|
25
|
+
private timer?;
|
|
26
|
+
private lost;
|
|
27
|
+
private closed;
|
|
28
|
+
private committedListeners;
|
|
29
|
+
private synchronizer;
|
|
30
|
+
private constructor();
|
|
31
|
+
static open(options: ProfileOwnerOptions): Promise<ProfileOwner>;
|
|
32
|
+
get current(): import("./profileStoreTypes.js").ProfileCurrentState;
|
|
33
|
+
get identity(): import("./inboxStore.js").InboxScope;
|
|
34
|
+
get active(): boolean;
|
|
35
|
+
get pending(): {
|
|
36
|
+
events: number;
|
|
37
|
+
bytes: number;
|
|
38
|
+
};
|
|
39
|
+
snapshot(): import("./profileMemoryStore.js").ProfileSnapshot;
|
|
40
|
+
commands(): import("./profileStoreTypes.js").ProfileOutboxCommand[];
|
|
41
|
+
subscribeCommitted(listener: (delta: ProfileDelta) => void): () => void;
|
|
42
|
+
setSynchronizer(synchronize: () => Promise<void>): void;
|
|
43
|
+
synchronize(): Promise<void>;
|
|
44
|
+
waitForCommand(commandId: string, signal: AbortSignal): Promise<void>;
|
|
45
|
+
enqueue(event: ProfileOperation, bytes: number, immediate?: boolean): Promise<void>;
|
|
46
|
+
flush(): void;
|
|
47
|
+
beginGeneration(bootstrap: InboxBootstrap, generation?: `${string}-${string}-${string}-${string}-${string}`): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
48
|
+
appendGeneration(generation: string, events: ProfileOperation[]): Promise<void>;
|
|
49
|
+
generationProgress(generation: string): Promise<ProfileGenerationState>;
|
|
50
|
+
pendingGenerations(): Promise<ProfileGenerationState[]>;
|
|
51
|
+
activateGeneration(generation: string): Promise<void>;
|
|
52
|
+
private report;
|
|
53
|
+
private renew;
|
|
54
|
+
private notify;
|
|
55
|
+
private commit;
|
|
56
|
+
close(): Promise<void>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { ProfileCommitQueue } from "./profileCommitQueue.js";
|
|
2
|
+
import { ProfileDatabase } from "./profileDatabase.js";
|
|
3
|
+
import { ProfileMemoryStore, PROFILE_PROTOCOL_VERSION } from "./profileMemoryStore.js";
|
|
4
|
+
import { ProfileProjection } from "./profileProjection.js";
|
|
5
|
+
import { ProfileGenerationBuilder } from "./profileGenerationBuilder.js";
|
|
6
|
+
/** The durable owner publishes only after commit. Network requests belong to
|
|
7
|
+
* the caller; neither the queue nor its transaction waits on connectivity. */
|
|
8
|
+
export class ProfileOwner {
|
|
9
|
+
options;
|
|
10
|
+
memory;
|
|
11
|
+
projection;
|
|
12
|
+
queue;
|
|
13
|
+
builder;
|
|
14
|
+
lease;
|
|
15
|
+
timer;
|
|
16
|
+
lost = false;
|
|
17
|
+
closed = false;
|
|
18
|
+
committedListeners = new Set();
|
|
19
|
+
synchronizer = () => Promise.resolve();
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.memory = new ProfileMemoryStore(options.onError, options.database.identity.profileId);
|
|
23
|
+
}
|
|
24
|
+
static async open(options) {
|
|
25
|
+
const owner = new ProfileOwner(options);
|
|
26
|
+
const ownerId = options.ownerId ?? crypto.randomUUID();
|
|
27
|
+
const lease = await options.database.claimWriter(ownerId);
|
|
28
|
+
if (!lease)
|
|
29
|
+
throw Error("PROFILE_OWNER_UNAVAILABLE");
|
|
30
|
+
owner.lease = lease;
|
|
31
|
+
try {
|
|
32
|
+
await options.database.initialize(ownerId, lease.fence, { activeGeneration: crypto.randomUUID(), epoch: options.epoch,
|
|
33
|
+
committedSeq: "0", projectionVersion: 1 });
|
|
34
|
+
const restored = await options.database.restore();
|
|
35
|
+
if (!restored.current || restored.current.epoch !== options.epoch)
|
|
36
|
+
throw Error("PROFILE_EPOCH_REBUILD_REQUIRED");
|
|
37
|
+
const snapshot = { ...restored, current: restored.current };
|
|
38
|
+
owner.projection = new ProfileProjection(options.database.identity, snapshot, options.windowStart);
|
|
39
|
+
owner.builder = new ProfileGenerationBuilder(options.database, () => owner.lease);
|
|
40
|
+
owner.memory.restore(snapshot);
|
|
41
|
+
owner.queue = new ProfileCommitQueue({ commit: events => owner.commit(events), windowMs: options.windowMs,
|
|
42
|
+
retryMs: options.retryMs, onError: error => owner.report(error) });
|
|
43
|
+
owner.timer = setInterval(() => { void owner.renew(); }, 10000);
|
|
44
|
+
return owner;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
await options.database.releaseWriter(ownerId, lease.fence);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
get current() { return this.projection.current; }
|
|
52
|
+
get identity() { return this.options.database.identity; }
|
|
53
|
+
get active() { return !this.closed && !this.lost && this.lease.expiresAt > Date.now(); }
|
|
54
|
+
get pending() { return this.queue.pending; }
|
|
55
|
+
snapshot() { return this.projection.snapshot(); }
|
|
56
|
+
commands() { return [...this.projection.outbox.values()]; }
|
|
57
|
+
subscribeCommitted(listener) { this.committedListeners.add(listener); return () => { this.committedListeners.delete(listener); }; }
|
|
58
|
+
setSynchronizer(synchronize) { this.synchronizer = synchronize; }
|
|
59
|
+
synchronize() { return this.synchronizer(); }
|
|
60
|
+
waitForCommand(commandId, signal) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const abort = () => { off(); reject(signal.reason ?? Error("PROFILE_OWNER_UNAVAILABLE")); };
|
|
63
|
+
const check = () => {
|
|
64
|
+
const command = this.projection.outbox.get(commandId);
|
|
65
|
+
if (!command || command.state === "confirmed") {
|
|
66
|
+
off();
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
else if (command.state === "failed") {
|
|
70
|
+
off();
|
|
71
|
+
reject(Error("PROFILE_COMMAND_FAILED"));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const unsubscribe = this.subscribeCommitted(check);
|
|
75
|
+
const off = () => { unsubscribe(); signal.removeEventListener("abort", abort); };
|
|
76
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
77
|
+
if (signal.aborted)
|
|
78
|
+
abort();
|
|
79
|
+
else
|
|
80
|
+
check();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
enqueue(event, bytes, immediate = false) {
|
|
84
|
+
if (this.closed || this.lost)
|
|
85
|
+
throw Error("PROFILE_OWNER_UNAVAILABLE");
|
|
86
|
+
return this.queue.enqueue(event, bytes, immediate);
|
|
87
|
+
}
|
|
88
|
+
flush() { this.queue.flush(); }
|
|
89
|
+
async beginGeneration(bootstrap, generation = crypto.randomUUID()) {
|
|
90
|
+
if (this.closed || this.lost)
|
|
91
|
+
throw Error("PROFILE_OWNER_UNAVAILABLE");
|
|
92
|
+
await this.queue.enqueue({ ownerType: "begin", generation, bootstrap }, new TextEncoder().encode(JSON.stringify(bootstrap)).byteLength, true, true);
|
|
93
|
+
return generation;
|
|
94
|
+
}
|
|
95
|
+
async appendGeneration(generation, events) {
|
|
96
|
+
if (this.closed || this.lost)
|
|
97
|
+
throw Error("PROFILE_OWNER_UNAVAILABLE");
|
|
98
|
+
await this.queue.enqueue({ ownerType: "append", generation, events }, new TextEncoder().encode(JSON.stringify(events)).byteLength, true, true);
|
|
99
|
+
}
|
|
100
|
+
generationProgress(generation) { return this.builder.progress(generation); }
|
|
101
|
+
async pendingGenerations() {
|
|
102
|
+
const rows = await this.options.database.inboxState.toArray();
|
|
103
|
+
return rows.filter((row) => row.key.startsWith("build:") && "status" in row && ["building", "validated"].includes(row.status));
|
|
104
|
+
}
|
|
105
|
+
async activateGeneration(generation) {
|
|
106
|
+
if (this.closed || this.lost)
|
|
107
|
+
throw Error("PROFILE_OWNER_UNAVAILABLE");
|
|
108
|
+
await this.queue.enqueue({ ownerType: "activate", generation }, 128, true, true);
|
|
109
|
+
}
|
|
110
|
+
report(error) {
|
|
111
|
+
if (error?.message === "PROFILE_WRITER_FENCED")
|
|
112
|
+
this.lost = true;
|
|
113
|
+
try {
|
|
114
|
+
this.options.onError?.(error);
|
|
115
|
+
}
|
|
116
|
+
catch { /* Reporting cannot break the commit loop. */ }
|
|
117
|
+
}
|
|
118
|
+
async renew() {
|
|
119
|
+
if (this.closed || this.lost)
|
|
120
|
+
return;
|
|
121
|
+
try {
|
|
122
|
+
const next = await this.options.database.claimWriter(this.lease.ownerId);
|
|
123
|
+
if (!next || next.fence !== this.lease.fence) {
|
|
124
|
+
this.lost = true;
|
|
125
|
+
this.report(Error("PROFILE_WRITER_FENCED"));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.lease = next;
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
this.report(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
notify(delta) {
|
|
135
|
+
try {
|
|
136
|
+
this.options.onCommitted?.(delta);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
this.report(error);
|
|
140
|
+
}
|
|
141
|
+
for (const listener of this.committedListeners) {
|
|
142
|
+
try {
|
|
143
|
+
listener(delta);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
this.report(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async commit(events) {
|
|
151
|
+
if (this.lost)
|
|
152
|
+
throw Error("PROFILE_WRITER_FENCED");
|
|
153
|
+
const first = events[0];
|
|
154
|
+
if (first && "ownerType" in first) {
|
|
155
|
+
if (events.length !== 1)
|
|
156
|
+
throw Error("PROFILE_BARRIER_NOT_ISOLATED");
|
|
157
|
+
if (first.ownerType === "begin")
|
|
158
|
+
await this.builder.begin(first.generation, first.bootstrap, this.current.commitRevision);
|
|
159
|
+
else if (first.ownerType === "append")
|
|
160
|
+
await this.builder.append(first.generation, first.events);
|
|
161
|
+
else {
|
|
162
|
+
const previous = this.current.commitRevision;
|
|
163
|
+
this.projection = await this.builder.activate(first.generation, this.projection);
|
|
164
|
+
const snapshot = this.projection.snapshot();
|
|
165
|
+
this.memory.restore(snapshot);
|
|
166
|
+
this.notify({ protocolVersion: PROFILE_PROTOCOL_VERSION, generation: this.current.activeGeneration,
|
|
167
|
+
fromRevision: previous, toRevision: this.current.commitRevision, current: this.current, threads: [], windows: [], messages: [] });
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const fromRevision = this.projection.current.commitRevision;
|
|
172
|
+
const prepared = this.projection.prepare(events);
|
|
173
|
+
const committed = await this.options.database.commit({ ...prepared, ownerId: this.lease.ownerId, fence: this.lease.fence,
|
|
174
|
+
generation: this.current.activeGeneration, expectedRevision: fromRevision, epoch: this.current.epoch,
|
|
175
|
+
committedSeq: prepared.current.committedSeq, receiptsReady: prepared.current.receiptsReady });
|
|
176
|
+
if (committed.commitRevision === fromRevision)
|
|
177
|
+
return;
|
|
178
|
+
prepared.current = committed;
|
|
179
|
+
const delta = { current: committed, threads: prepared.threads, windows: prepared.windows, messages: prepared.messages,
|
|
180
|
+
protocolVersion: PROFILE_PROTOCOL_VERSION, generation: committed.activeGeneration,
|
|
181
|
+
fromRevision, toRevision: committed.commitRevision };
|
|
182
|
+
this.projection.accept(prepared);
|
|
183
|
+
// Publication failures must never replay an already-committed transaction.
|
|
184
|
+
try {
|
|
185
|
+
this.memory.apply(delta);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
this.report(error);
|
|
189
|
+
this.memory.restore(this.projection.snapshot());
|
|
190
|
+
}
|
|
191
|
+
this.notify(delta);
|
|
192
|
+
}
|
|
193
|
+
async close() {
|
|
194
|
+
if (this.closed)
|
|
195
|
+
return;
|
|
196
|
+
// The producer must stop intake and await accepted enqueue promises first.
|
|
197
|
+
this.queue.close();
|
|
198
|
+
this.closed = true;
|
|
199
|
+
clearInterval(this.timer);
|
|
200
|
+
await this.options.database.releaseWriter(this.lease.ownerId, this.lease.fence);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type InboxEvent, type InboxBootstrap } from "./inboxStore.js";
|
|
2
|
+
import { ProfileReadingIndex } from "./profileReadingIndex.js";
|
|
3
|
+
import { ProfileWindowDirectory } from "./profileWindows.js";
|
|
4
|
+
import type { ProfileSnapshot } from "./profileMemoryStore.js";
|
|
5
|
+
import type { ProfileCurrentState, ProfileIdentity, ProfileMessage, ProfileOutboxCommand, ProfileThread, ProfileWindow } from "./profileStoreTypes.js";
|
|
6
|
+
import type { ChatRuntimeMessage } from "./protocol.js";
|
|
7
|
+
export declare const profileDiscussionId: (parent: string, root: string) => string;
|
|
8
|
+
export type ProfileLocalOperation = {
|
|
9
|
+
type: "register";
|
|
10
|
+
threadId: string;
|
|
11
|
+
kind: "group" | "dm";
|
|
12
|
+
targetId: string;
|
|
13
|
+
teamId: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "revoke";
|
|
17
|
+
threadId: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "send";
|
|
20
|
+
threadId: string;
|
|
21
|
+
parentThreadId?: string;
|
|
22
|
+
message: ChatRuntimeMessage;
|
|
23
|
+
command: ProfileOutboxCommand;
|
|
24
|
+
} | {
|
|
25
|
+
type: "commandPayload";
|
|
26
|
+
commandId: string;
|
|
27
|
+
message: ChatRuntimeMessage;
|
|
28
|
+
} | {
|
|
29
|
+
type: "observe";
|
|
30
|
+
threadId: string;
|
|
31
|
+
messageIds: string[];
|
|
32
|
+
policy: "visible" | "played";
|
|
33
|
+
commandId: string;
|
|
34
|
+
createdAt: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "commandResult";
|
|
37
|
+
commandId: string;
|
|
38
|
+
state: "pending" | "sending" | "failed" | "confirmed";
|
|
39
|
+
} | {
|
|
40
|
+
type: "restoreReading";
|
|
41
|
+
data: Record<string, unknown>;
|
|
42
|
+
} | {
|
|
43
|
+
type: "restoreReceipt";
|
|
44
|
+
data: Record<string, unknown>;
|
|
45
|
+
} | {
|
|
46
|
+
type: "receiptsReady";
|
|
47
|
+
};
|
|
48
|
+
export type ProfileOperation = InboxEvent | ProfileLocalOperation;
|
|
49
|
+
export type PreparedProfileProjection = {
|
|
50
|
+
current: ProfileCurrentState;
|
|
51
|
+
threads: ProfileThread[];
|
|
52
|
+
windows: ProfileWindow[];
|
|
53
|
+
messages: ProfileMessage[];
|
|
54
|
+
readingIndices: Map<string, ProfileReadingIndex>;
|
|
55
|
+
outbox: ProfileOutboxCommand[];
|
|
56
|
+
deleteOutbox: string[];
|
|
57
|
+
};
|
|
58
|
+
/** Committed authority for the replay reducer. Drafts contain only changed rows;
|
|
59
|
+
* failure discards the draft, leaving both entities and indexes untouched. */
|
|
60
|
+
export declare class ProfileProjection {
|
|
61
|
+
readonly identity: ProfileIdentity;
|
|
62
|
+
readonly windowStart: number;
|
|
63
|
+
readonly threads: Map<string, ProfileThread>;
|
|
64
|
+
readonly messages: Map<string, ProfileMessage>;
|
|
65
|
+
readonly directories: Map<string, ProfileWindowDirectory>;
|
|
66
|
+
readonly readingIndices: Map<string, ProfileReadingIndex>;
|
|
67
|
+
readonly children: Map<string, Set<string>>;
|
|
68
|
+
readonly outbox: Map<string, ProfileOutboxCommand>;
|
|
69
|
+
current: ProfileCurrentState;
|
|
70
|
+
constructor(identity: ProfileIdentity, snapshot: ProfileSnapshot & {
|
|
71
|
+
outbox?: ProfileOutboxCommand[];
|
|
72
|
+
}, windowStart: number);
|
|
73
|
+
prepare(events: readonly ProfileOperation[]): PreparedProfileProjection;
|
|
74
|
+
prepareBasis(bootstrap: InboxBootstrap): PreparedProfileProjection;
|
|
75
|
+
accept(prepared: PreparedProfileProjection): void;
|
|
76
|
+
snapshot(): ProfileSnapshot;
|
|
77
|
+
}
|