mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 02:21:51 +08:00
8cf00738c2
#### PR Dependency Tree * **PR #14934** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Full realtime platform added: live notifications, comments, embedding progress, and transcription task updates via realtime subscriptions. * **Chores** * Frontend switched from polling/GraphQL queries to realtime channels; legacy query fields marked deprecated and client libs updated to use realtime APIs. [](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14934) <!-- end of auto-generated comment: release notes by coderabbit.ai --> #### PR Dependency Tree * **PR #14934** 👈 * **PR #14936** This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal)
226 lines
5.8 KiB
TypeScript
226 lines
5.8 KiB
TypeScript
import type {
|
|
RealtimeConfigureInput,
|
|
RealtimeRequestInputOf,
|
|
RealtimeRequestName,
|
|
RealtimeRequestOutputOf,
|
|
RealtimeStatus,
|
|
RealtimeSubscriptionReady,
|
|
RealtimeTopicEventOf,
|
|
RealtimeTopicInputOf,
|
|
RealtimeTopicName,
|
|
} from '@affine/realtime';
|
|
|
|
import type { AvailableStorageImplementations } from '../impls';
|
|
import type {
|
|
AggregateResult,
|
|
BlobRecord,
|
|
DocClock,
|
|
DocClocks,
|
|
DocDiff,
|
|
DocRecord,
|
|
DocUpdate,
|
|
ListedBlobRecord,
|
|
Query,
|
|
SearchResult,
|
|
StorageType,
|
|
} from '../storage';
|
|
import type { AwarenessRecord } from '../storage/awareness';
|
|
import type { BlobSyncBlobState, BlobSyncState } from '../sync/blob';
|
|
import type { DocSyncDocState, DocSyncState } from '../sync/doc';
|
|
import type { IndexerDocSyncState, IndexerSyncState } from '../sync/indexer';
|
|
import type {
|
|
TelemetryAck,
|
|
TelemetryContext,
|
|
TelemetryEvent,
|
|
TelemetryQueueState,
|
|
} from '../telemetry/types';
|
|
|
|
type StorageInitOptions = Values<{
|
|
[key in keyof AvailableStorageImplementations]: {
|
|
name: key;
|
|
opts: ConstructorParameters<AvailableStorageImplementations[key]>[0];
|
|
};
|
|
}>;
|
|
|
|
export interface StoreInitOptions {
|
|
local: { [key in StorageType]?: StorageInitOptions };
|
|
remotes: Record<string, { [key in StorageType]?: StorageInitOptions }>;
|
|
}
|
|
|
|
interface GroupedWorkerOps {
|
|
docStorage: {
|
|
getDoc: [string, DocRecord | null];
|
|
getDocDiff: [{ docId: string; state?: Uint8Array }, DocDiff | null];
|
|
pushDocUpdate: [{ update: DocUpdate; origin?: string }, DocClock];
|
|
getDocTimestamps: [Date | null, DocClocks];
|
|
getDocTimestamp: [string, DocClock | null];
|
|
deleteDoc: [string, void];
|
|
subscribeDocUpdate: [void, { update: DocRecord; origin?: string }];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
blobStorage: {
|
|
getBlob: [string, BlobRecord | null];
|
|
setBlob: [BlobRecord, void];
|
|
deleteBlob: [{ key: string; permanently: boolean }, void];
|
|
releaseBlobs: [void, void];
|
|
listBlobs: [void, ListedBlobRecord[]];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
awarenessStorage: {
|
|
update: [{ awareness: AwarenessRecord; origin?: string }, void];
|
|
subscribeUpdate: [
|
|
string,
|
|
(
|
|
| {
|
|
type: 'awareness-update';
|
|
awareness: AwarenessRecord;
|
|
origin?: string;
|
|
}
|
|
| { type: 'awareness-collect'; collectId: string }
|
|
),
|
|
];
|
|
collect: [{ collectId: string; awareness: AwarenessRecord }, void];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
docSync: {
|
|
state: [void, DocSyncState];
|
|
docState: [string, DocSyncDocState];
|
|
waitForSynced: [string | null, void];
|
|
addPriority: [{ docId: string; priority: number }, boolean];
|
|
resetSync: [void, void];
|
|
};
|
|
|
|
blobSync: {
|
|
state: [void, BlobSyncState];
|
|
blobState: [string, BlobSyncBlobState];
|
|
downloadBlob: [string, boolean];
|
|
uploadBlob: [{ blob: BlobRecord; force?: boolean }, true];
|
|
fullDownload: [string | null, void];
|
|
};
|
|
|
|
awarenessSync: {
|
|
update: [{ awareness: AwarenessRecord; origin?: string }, void];
|
|
subscribeUpdate: [
|
|
string,
|
|
(
|
|
| {
|
|
type: 'awareness-update';
|
|
awareness: AwarenessRecord;
|
|
origin?: string;
|
|
}
|
|
| { type: 'awareness-collect'; collectId: string }
|
|
),
|
|
];
|
|
collect: [{ collectId: string; awareness: AwarenessRecord }, void];
|
|
};
|
|
|
|
indexerSync: {
|
|
state: [void, IndexerSyncState];
|
|
docState: [string, IndexerDocSyncState];
|
|
addPriority: [{ docId: string; priority: number }, boolean];
|
|
waitForCompleted: [void, void];
|
|
waitForDocCompleted: [string, void];
|
|
search: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
options?: any;
|
|
},
|
|
SearchResult<any, any>,
|
|
];
|
|
aggregate: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
field: string;
|
|
options?: any;
|
|
},
|
|
AggregateResult<any, any>,
|
|
];
|
|
subscribeSearch: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
options?: any;
|
|
},
|
|
SearchResult<any, any>,
|
|
];
|
|
subscribeAggregate: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
field: string;
|
|
options?: any;
|
|
},
|
|
AggregateResult<any, any>,
|
|
];
|
|
};
|
|
sync: {
|
|
enableBatterySaveMode: [void, void];
|
|
disableBatterySaveMode: [void, void];
|
|
pauseSync: [void, void];
|
|
resumeSync: [void, void];
|
|
};
|
|
}
|
|
|
|
type Values<T> = T extends { [k in keyof T]: any } ? T[keyof T] : never;
|
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
|
|
x: infer I
|
|
) => void
|
|
? I
|
|
: never;
|
|
|
|
export type WorkerOps = UnionToIntersection<
|
|
Values<
|
|
Values<{
|
|
[k in keyof GroupedWorkerOps]: {
|
|
[k2 in keyof GroupedWorkerOps[k]]: k2 extends string
|
|
? Record<`${k}.${k2}`, GroupedWorkerOps[k][k2]>
|
|
: never;
|
|
};
|
|
}>
|
|
>
|
|
>;
|
|
|
|
export type WorkerManagerOps = {
|
|
open: [
|
|
{
|
|
port: MessagePort;
|
|
key: string;
|
|
closeKey: string;
|
|
options: StoreInitOptions;
|
|
},
|
|
string,
|
|
];
|
|
close: [string, void];
|
|
'telemetry.setContext': [TelemetryContext, void];
|
|
'telemetry.track': [TelemetryEvent, { queued: boolean }];
|
|
'telemetry.pageview': [TelemetryEvent, { queued: boolean }];
|
|
'telemetry.flush': [void, TelemetryAck];
|
|
'telemetry.getQueueState': [void, TelemetryQueueState];
|
|
'realtime.configure': [RealtimeConfigureInput, void];
|
|
'realtime.request': [
|
|
{
|
|
[Op in RealtimeRequestName]: {
|
|
op: Op;
|
|
input: RealtimeRequestInputOf<Op>;
|
|
timeoutMs?: number;
|
|
};
|
|
}[RealtimeRequestName],
|
|
RealtimeRequestOutputOf<RealtimeRequestName>,
|
|
];
|
|
'realtime.subscribe': [
|
|
{
|
|
[Topic in RealtimeTopicName]: {
|
|
topic: Topic;
|
|
input: RealtimeTopicInputOf<Topic>;
|
|
};
|
|
}[RealtimeTopicName],
|
|
RealtimeTopicEventOf<RealtimeTopicName> | RealtimeSubscriptionReady,
|
|
];
|
|
'realtime.status': [void, RealtimeStatus];
|
|
};
|