Merge branch 'canary' into stable

This commit is contained in:
李华桥
2023-12-01 16:12:17 +08:00
147 changed files with 1775 additions and 1993 deletions
+2 -19
View File
@@ -44,18 +44,9 @@ export const fetcher = gqlFetcherFactory(
* })
* ```
*/
export function useQuery<Query extends GraphQLQuery>(
options: QueryOptions<Query>
): SWRResponse<
QueryResponse<Query>,
GraphQLError | GraphQLError[],
{
suspense: true;
}
>;
export function useQuery<Query extends GraphQLQuery>(
options: QueryOptions<Query>,
config: Omit<
config?: Omit<
SWRConfiguration<
QueryResponse<Query>,
GraphQLError | GraphQLError[],
@@ -160,17 +151,9 @@ export function useQueryInfinite<Query extends GraphQLQuery>(
*
* trigger({ name: 'John Doe' })
*/
export function useMutation<Mutation extends GraphQLQuery, K extends Key = Key>(
options: Omit<MutationOptions<Mutation>, 'variables'>
): SWRMutationResponse<
QueryResponse<Mutation>,
GraphQLError | GraphQLError[],
K,
QueryVariables<Mutation>
>;
export function useMutation<Mutation extends GraphQLQuery, K extends Key = Key>(
options: Omit<MutationOptions<Mutation>, 'variables'>,
config: Omit<
config?: Omit<
SWRMutationConfiguration<
QueryResponse<Mutation>,
GraphQLError | GraphQLError[],
@@ -5,8 +5,8 @@ const logger = new DebugLogger('affine:blob-engine');
export class BlobEngine {
constructor(
private local: BlobStorage,
private remotes: BlobStorage[]
private readonly local: BlobStorage,
private readonly remotes: BlobStorage[]
) {}
get storages() {
@@ -24,13 +24,13 @@ export function createAffineAwarenessProvider(
const socket = getIoManager().socket('/');
const awarenessBroadcast = ({
workspaceId: remoteWorkspaceId,
workspaceId: wsId,
awarenessUpdate,
}: {
workspaceId: string;
awarenessUpdate: string;
}) => {
if (remoteWorkspaceId !== workspaceId) {
if (wsId !== workspaceId) {
return;
}
applyAwarenessUpdate(
@@ -15,12 +15,12 @@ interface SyncUpdateSender {
* - retryable, allow retry when previous sync request failed but with retry flag been set to true
*/
export class BatchSyncSender {
private buffered: Uint8Array[] = [];
private readonly buffered: Uint8Array[] = [];
private job: Promise<void> | null = null;
private started = true;
constructor(
private guid: string,
private readonly guid: string,
private readonly rawSender: SyncUpdateSender
) {}
@@ -0,0 +1,7 @@
export const MANUALLY_STOP = 'manually-stop';
export enum SyncEngineStep {
Stopped = 0,
Syncing = 1,
Synced = 2,
}
@@ -3,16 +3,9 @@ import { Slot } from '@blocksuite/global/utils';
import type { Doc } from 'yjs';
import type { Storage } from '../storage';
import { MANUALLY_STOP, SyncEngineStep } from './consts';
import { SyncPeer, type SyncPeerStatus, SyncPeerStep } from './peer';
export const MANUALLY_STOP = 'manually-stop';
export enum SyncEngineStep {
Stopped = 0,
Syncing = 1,
Synced = 2,
}
export interface SyncEngineStatus {
step: SyncEngineStep;
local: SyncPeerStatus | null;
@@ -70,9 +63,9 @@ export class SyncEngine {
private abort = new AbortController();
constructor(
private rootDoc: Doc,
private local: Storage,
private remotes: Storage[]
private readonly rootDoc: Doc,
private readonly local: Storage,
private readonly remotes: Storage[]
) {
this._status = {
step: SyncEngineStep.Stopped,
@@ -193,13 +186,13 @@ export class SyncEngine {
}
async waitForSynced(abort?: AbortSignal) {
if (this.status.step == SyncEngineStep.Synced) {
if (this.status.step === SyncEngineStep.Synced) {
return;
} else {
return Promise.race([
new Promise<void>(resolve => {
this.onStatusChange.on(status => {
if (status.step == SyncEngineStep.Synced) {
if (status.step === SyncEngineStep.Synced) {
resolve();
}
});
@@ -14,5 +14,6 @@
*
*/
export * from './consts';
export * from './engine';
export * from './peer';
@@ -7,7 +7,7 @@ import { applyUpdate, encodeStateAsUpdate, encodeStateVector } from 'yjs';
import { mergeUpdates, type Storage } from '../storage';
import { AsyncQueue } from '../utils/async-queue';
import { throwIfAborted } from '../utils/throw-if-aborted';
import { MANUALLY_STOP } from './engine';
import { MANUALLY_STOP } from './consts';
export enum SyncPeerStep {
Stopped = 0,
@@ -69,8 +69,8 @@ export class SyncPeer {
logger = new DebugLogger('affine:sync-peer:' + this.name);
constructor(
private rootDoc: Doc,
private storage: Storage
private readonly rootDoc: Doc,
private readonly storage: Storage
) {
this.logger.debug('peer start');
@@ -150,7 +150,7 @@ export class SyncPeer {
}
}
private state: {
private readonly state: {
connectedDocs: Map<string, Doc>;
pushUpdatesQueue: AsyncQueue<{
docId: string;