refactor(core): initial multiple servers infra (#8745)

This is the initial refactoring of affine to support multiple servers, but many more changes are needed to make multi-server actually work.
This commit is contained in:
EYHN
2024-11-27 06:44:46 +00:00
parent 3f4cb5be40
commit 6b4a1aa917
80 changed files with 1141 additions and 519 deletions

View File

@@ -2,7 +2,6 @@ export type { Member } from './entities/members';
export { WorkspaceMembersService } from './services/members';
export { WorkspacePermissionService } from './services/permission';
import { GraphQLService } from '@affine/core/modules/cloud';
import {
type Framework,
WorkspaceScope,
@@ -10,6 +9,7 @@ import {
WorkspacesService,
} from '@toeverything/infra';
import { WorkspaceServerService } from '../cloud';
import { WorkspaceMembers } from './entities/members';
import { WorkspacePermission } from './entities/permission';
import { WorkspaceMembersService } from './services/members';
@@ -25,9 +25,9 @@ export function configurePermissionsModule(framework: Framework) {
WorkspacesService,
WorkspacePermissionStore,
])
.store(WorkspacePermissionStore, [GraphQLService])
.store(WorkspacePermissionStore, [WorkspaceServerService])
.entity(WorkspacePermission, [WorkspaceService, WorkspacePermissionStore])
.service(WorkspaceMembersService)
.store(WorkspaceMembersStore, [GraphQLService])
.store(WorkspaceMembersStore, [WorkspaceServerService])
.entity(WorkspaceMembers, [WorkspaceMembersStore, WorkspaceService]);
}

View File

@@ -1,10 +1,10 @@
import { getMembersByWorkspaceIdQuery } from '@affine/graphql';
import { Store } from '@toeverything/infra';
import type { GraphQLService } from '../../cloud';
import type { WorkspaceServerService } from '../../cloud';
export class WorkspaceMembersStore extends Store {
constructor(private readonly graphqlService: GraphQLService) {
constructor(private readonly workspaceServerService: WorkspaceServerService) {
super();
}
@@ -14,7 +14,10 @@ export class WorkspaceMembersStore extends Store {
take: number,
signal?: AbortSignal
) {
const data = await this.graphqlService.gql({
if (!this.workspaceServerService.server) {
throw new Error('No Server');
}
const data = await this.workspaceServerService.server.gql({
query: getMembersByWorkspaceIdQuery,
variables: {
workspaceId,

View File

@@ -1,14 +1,17 @@
import type { GraphQLService } from '@affine/core/modules/cloud';
import type { WorkspaceServerService } from '@affine/core/modules/cloud';
import { getIsOwnerQuery, leaveWorkspaceMutation } from '@affine/graphql';
import { Store } from '@toeverything/infra';
export class WorkspacePermissionStore extends Store {
constructor(private readonly graphqlService: GraphQLService) {
constructor(private readonly workspaceServerService: WorkspaceServerService) {
super();
}
async fetchIsOwner(workspaceId: string, signal?: AbortSignal) {
const isOwner = await this.graphqlService.gql({
if (!this.workspaceServerService.server) {
throw new Error('No Server');
}
const isOwner = await this.workspaceServerService.server.gql({
query: getIsOwnerQuery,
variables: {
workspaceId,
@@ -23,7 +26,10 @@ export class WorkspacePermissionStore extends Store {
* @param workspaceName for send email
*/
async leaveWorkspace(workspaceId: string, workspaceName: string) {
await this.graphqlService.gql({
if (!this.workspaceServerService.server) {
throw new Error('No Server');
}
await this.workspaceServerService.server.gql({
query: leaveWorkspaceMutation,
variables: {
workspaceId,