mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 04:21:40 +08:00
fix: move workspace to top level (#2717)
(cherry picked from commit 4958d096b0)
This commit is contained in:
@@ -6,6 +6,11 @@ import 'fake-indexeddb/auto';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
import { MessageCode } from '@affine/env/constant';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
createWorkspaceResponseSchema,
|
||||
usageResponseSchema,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
import user1 from '@affine-test/fixtures/built-in-user1.json';
|
||||
import user2 from '@affine-test/fixtures/built-in-user2.json';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
@@ -17,15 +22,8 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { WebSocket } from 'ws';
|
||||
import { applyUpdate } from 'yjs';
|
||||
|
||||
import { WorkspaceFlavour } from '../../type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
import {
|
||||
createUserApis,
|
||||
createWorkspaceApis,
|
||||
createWorkspaceResponseSchema,
|
||||
RequestError,
|
||||
usageResponseSchema,
|
||||
} from '../api';
|
||||
import { createUserApis, createWorkspaceApis, RequestError } from '../api';
|
||||
import { createStatusApis } from '../api/status';
|
||||
import { KeckProvider } from '../keck';
|
||||
import {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { Workspace } from '@affine/env/workspace/legacy-cloud';
|
||||
import { PermissionType } from '@affine/env/workspace/legacy-cloud';
|
||||
import user1 from '@affine-test/fixtures/built-in-user1.json';
|
||||
import user2 from '@affine-test/fixtures/built-in-user2.json';
|
||||
import type { ParagraphBlockModel } from '@blocksuite/blocks/models';
|
||||
@@ -13,10 +16,8 @@ import { WebSocket } from 'ws';
|
||||
|
||||
import type { LoginResponse } from '../../affine/login';
|
||||
import { loginResponseSchema } from '../../affine/login';
|
||||
import { WorkspaceFlavour } from '../../type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
import type { Workspace } from '../api';
|
||||
import { createWorkspaceApis, PermissionType } from '../api';
|
||||
import { createWorkspaceApis } from '../api';
|
||||
import { KeckProvider } from '../keck';
|
||||
|
||||
declare module '@blocksuite/store' {
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
import { MessageCode, Messages } from '@affine/env';
|
||||
import { z } from 'zod';
|
||||
import type {
|
||||
AcceptInvitingParams,
|
||||
DeleteWorkspaceParams,
|
||||
GetUserByEmailParams,
|
||||
GetWorkspaceDetailParams,
|
||||
InviteMemberParams,
|
||||
LeaveWorkspaceParams,
|
||||
Member,
|
||||
Permission,
|
||||
RemoveMemberParams,
|
||||
UpdateWorkspaceParams,
|
||||
UsageResponse,
|
||||
User,
|
||||
Workspace,
|
||||
WorkspaceDetail,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
|
||||
import { checkLoginStorage } from '../login';
|
||||
|
||||
@@ -28,28 +43,6 @@ function sendMessage(code: (typeof MessageCode)[keyof typeof MessageCode]) {
|
||||
);
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
create_at: string;
|
||||
}
|
||||
|
||||
export interface GetUserByEmailParams {
|
||||
email: string;
|
||||
workspace_id: string;
|
||||
}
|
||||
|
||||
export const usageResponseSchema = z.object({
|
||||
blob_usage: z.object({
|
||||
usage: z.number(),
|
||||
max_usage: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type UsageResponse = z.infer<typeof usageResponseSchema>;
|
||||
|
||||
export function createUserApis(prefixUrl = '/') {
|
||||
return {
|
||||
getUsage: async (): Promise<UsageResponse> => {
|
||||
@@ -78,112 +71,6 @@ export function createUserApis(prefixUrl = '/') {
|
||||
} as const;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceDetailParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export enum WorkspaceType {
|
||||
Private = 0,
|
||||
Normal = 1,
|
||||
}
|
||||
|
||||
export enum PermissionType {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Admin = 10,
|
||||
Owner = 99,
|
||||
}
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
avatar_url: z.string(),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
public: z.boolean(),
|
||||
permission: z.nativeEnum(PermissionType),
|
||||
});
|
||||
|
||||
export type Workspace = z.infer<typeof workspaceSchema>;
|
||||
|
||||
export const workspaceDetailSchema = z.object({
|
||||
...workspaceSchema.shape,
|
||||
permission: z.undefined(),
|
||||
owner: userSchema,
|
||||
member_count: z.number(),
|
||||
});
|
||||
|
||||
export type WorkspaceDetail = z.infer<typeof workspaceDetailSchema>;
|
||||
|
||||
export interface Permission {
|
||||
id: string;
|
||||
type: PermissionType;
|
||||
workspace_id: string;
|
||||
user_id: string;
|
||||
user_email: string;
|
||||
accepted: boolean;
|
||||
create_at: number;
|
||||
}
|
||||
|
||||
export interface RegisteredUser extends User {
|
||||
type: 'Registered';
|
||||
}
|
||||
|
||||
export interface UnregisteredUser {
|
||||
type: 'Unregistered';
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface Member extends Permission {
|
||||
user: RegisteredUser | UnregisteredUser;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceMembersParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceParams {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UpdateWorkspaceParams {
|
||||
id: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
export interface DeleteWorkspaceParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface InviteMemberParams {
|
||||
id: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface RemoveMemberParams {
|
||||
permissionId: number;
|
||||
}
|
||||
|
||||
export interface AcceptInvitingParams {
|
||||
invitingCode: string;
|
||||
}
|
||||
|
||||
export interface LeaveWorkspaceParams {
|
||||
id: number | string;
|
||||
}
|
||||
|
||||
export const createWorkspaceResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
public: z.boolean(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export function createWorkspaceApis(prefixUrl = '/') {
|
||||
return {
|
||||
getWorkspaces: async (): Promise<Workspace[]> => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import * as url from 'lib0/url';
|
||||
import * as websocket from 'lib0/websocket';
|
||||
|
||||
import { getLoginStorage, isExpired, parseIdToken } from '../affine/login';
|
||||
import { WorkspaceFlavour } from '../type';
|
||||
import { cleanupWorkspace } from '../utils';
|
||||
|
||||
const RECONNECT_INTERVAL_TIME = 500;
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { websocketPrefixUrl } from '@affine/env/api';
|
||||
import type { WorkspaceCRUD } from '@affine/env/workspace';
|
||||
import type { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
workspaceDetailSchema,
|
||||
workspaceSchema,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { Disposable } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { workspaceDetailSchema, workspaceSchema } from '../affine/api';
|
||||
import { WebsocketClient } from '../affine/channel';
|
||||
import { storageChangeSlot } from '../affine/login';
|
||||
import { rootStore, rootWorkspacesMetadataAtom } from '../atom';
|
||||
import type { WorkspaceCRUD } from '../type';
|
||||
import type { WorkspaceFlavour } from '../type';
|
||||
|
||||
const logger = new DebugLogger('affine-sync');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user