mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
refactor(server): plugin modules (#5630)
- [x] separates modules into `fundamental`, `core`, `plugins`
- [x] optional modules with `@OptionalModule` decorator to install modules with requirements met(`requires`, `if`)
- [x] `module.contributesTo` defines optional features that will be enabled if module registered
- [x] `AFFiNE.plugins.use('payment', {})` to enable a optional/plugin module
- [x] `PaymentModule` is the first plugin module
- [x] GraphQLSchema will not be generated for non-included modules
- [x] Frontend can use `ServerConfigType` query to detect which features are enabled
- [x] override existing provider globally
This commit is contained in:
@@ -10,7 +10,7 @@ import type { Express } from 'express';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { FeatureManagementService } from '../src/modules/features';
|
||||
import { FeatureManagementService } from '../src/core/features';
|
||||
import { createTestingApp } from './utils';
|
||||
|
||||
const gql = '/graphql';
|
||||
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AuthService } from '../src/core/auth/service';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import {
|
||||
changeEmail,
|
||||
createTestingApp,
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
|
||||
import { AuthResolver } from '../src/core/auth/resolver';
|
||||
import { AuthService } from '../src/core/auth/service';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import {
|
||||
mintChallengeResponse,
|
||||
verifyChallengeResponse,
|
||||
} from '../src/fundamentals/storage';
|
||||
import { AuthResolver } from '../src/modules/auth/resolver';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
let authService: AuthService;
|
||||
|
||||
@@ -11,10 +11,10 @@ import {
|
||||
encodeStateAsUpdate,
|
||||
} from 'yjs';
|
||||
|
||||
import { DocManager, DocModule } from '../src/core/doc';
|
||||
import { QuotaModule } from '../src/core/quota';
|
||||
import { StorageModule } from '../src/core/storage';
|
||||
import { Config } from '../src/fundamentals/config';
|
||||
import { DocManager, DocModule } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { StorageModule } from '../src/modules/storage';
|
||||
import { createTestingModule, initTestingDB } from './utils';
|
||||
|
||||
const createModule = () => {
|
||||
|
||||
@@ -4,17 +4,17 @@ import { INestApplication, Injectable } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { AuthService } from '../src/core/auth/service';
|
||||
import {
|
||||
FeatureManagementService,
|
||||
FeatureModule,
|
||||
FeatureService,
|
||||
FeatureType,
|
||||
} from '../src/modules/features';
|
||||
import { UserType } from '../src/modules/users/types';
|
||||
import { WorkspaceResolver } from '../src/modules/workspaces/resolvers';
|
||||
import { Permission } from '../src/modules/workspaces/types';
|
||||
} from '../src/core/features';
|
||||
import { UserType } from '../src/core/users/types';
|
||||
import { WorkspaceResolver } from '../src/core/workspaces/resolvers';
|
||||
import { Permission } from '../src/core/workspaces/types';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { createTestingApp } from './utils';
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -4,10 +4,10 @@ import { PrismaClient } from '@prisma/client';
|
||||
import test from 'ava';
|
||||
import * as Sinon from 'sinon';
|
||||
|
||||
import { DocHistoryManager } from '../src/core/doc';
|
||||
import { QuotaModule } from '../src/core/quota';
|
||||
import { StorageModule } from '../src/core/storage';
|
||||
import { type EventPayload } from '../src/fundamentals/event';
|
||||
import { DocHistoryManager } from '../src/modules/doc';
|
||||
import { QuotaModule } from '../src/modules/quota';
|
||||
import { StorageModule } from '../src/modules/storage';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
let m: TestingModule;
|
||||
|
||||
@@ -10,8 +10,8 @@ import { TestingModule } from '@nestjs/testing';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AuthService } from '../src/core/auth/service';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
|
||||
@@ -7,9 +7,9 @@ import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { FeatureKind, FeatureManagementService } from '../src/core/features';
|
||||
import { Quotas } from '../src/core/quota';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { FeatureKind, FeatureManagementService } from '../src/modules/features';
|
||||
import { Quotas } from '../src/modules/quota';
|
||||
import {
|
||||
createTestingApp,
|
||||
createWorkspace,
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
import { TestingModule } from '@nestjs/testing';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AuthService } from '../src/modules/auth';
|
||||
import { AuthService } from '../src/core/auth';
|
||||
import {
|
||||
QuotaManagementService,
|
||||
QuotaModule,
|
||||
Quotas,
|
||||
QuotaService,
|
||||
QuotaType,
|
||||
} from '../src/modules/quota';
|
||||
import { StorageModule } from '../src/modules/storage';
|
||||
} from '../src/core/quota';
|
||||
import { StorageModule } from '../src/core/storage';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
|
||||
@@ -4,7 +4,6 @@ import { TestingModule } from '@nestjs/testing';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { CacheModule } from '../src/fundamentals/cache';
|
||||
import { ConfigModule } from '../src/fundamentals/config';
|
||||
import { SessionModule, SessionService } from '../src/fundamentals/session';
|
||||
import { createTestingModule } from './utils';
|
||||
|
||||
@@ -15,15 +14,7 @@ const test = ava as TestFn<{
|
||||
|
||||
test.beforeEach(async t => {
|
||||
const module = await createTestingModule({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
redis: {
|
||||
enabled: false,
|
||||
},
|
||||
}),
|
||||
CacheModule,
|
||||
SessionModule,
|
||||
],
|
||||
imports: [CacheModule, SessionModule],
|
||||
});
|
||||
const session = module.get(SessionService);
|
||||
t.context.module = module;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
|
||||
import type { InvitationType } from '../../src/modules/workspaces';
|
||||
import type { InvitationType } from '../../src/core/workspaces';
|
||||
import { gql } from './common';
|
||||
|
||||
export async function inviteUser(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
|
||||
import type { TokenType } from '../../src/modules/auth';
|
||||
import type { UserType } from '../../src/modules/users';
|
||||
import type { TokenType } from '../../src/core/auth';
|
||||
import type { UserType } from '../../src/core/users';
|
||||
import { gql } from './common';
|
||||
|
||||
export async function signUp(
|
||||
|
||||
@@ -5,6 +5,7 @@ import { PrismaClient } from '@prisma/client';
|
||||
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
||||
|
||||
import { AppModule, FunctionalityModules } from '../../src/app.module';
|
||||
import { AuthModule } from '../../src/core/auth';
|
||||
import { UserFeaturesInit1698652531198 } from '../../src/data/migrations/1698652531198-user-features-init';
|
||||
import { GqlModule } from '../../src/fundamentals/graphql';
|
||||
|
||||
@@ -68,7 +69,12 @@ export async function createTestingModule(
|
||||
imports =
|
||||
imports[0] === AppModule
|
||||
? [AppModule]
|
||||
: dedupeModules([...FunctionalityModules, GqlModule, ...imports]);
|
||||
: dedupeModules([
|
||||
...FunctionalityModules,
|
||||
AuthModule,
|
||||
GqlModule,
|
||||
...imports,
|
||||
]);
|
||||
|
||||
const builder = Test.createTestingModule({
|
||||
imports,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import request from 'supertest';
|
||||
|
||||
import type { WorkspaceType } from '../../src/modules/workspaces';
|
||||
import type { WorkspaceType } from '../../src/core/workspaces';
|
||||
import { gql } from './common';
|
||||
|
||||
export async function createWorkspace(
|
||||
|
||||
@@ -3,8 +3,8 @@ import test from 'ava';
|
||||
import request from 'supertest';
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { FeatureManagementService, FeatureType } from '../src/modules/features';
|
||||
import { QuotaService, QuotaType } from '../src/modules/quota';
|
||||
import { FeatureManagementService, FeatureType } from '../src/core/features';
|
||||
import { QuotaService, QuotaType } from '../src/core/quota';
|
||||
import {
|
||||
checkBlobSize,
|
||||
collectAllBlobSizes,
|
||||
|
||||
@@ -7,8 +7,8 @@ import { PrismaClient } from '@prisma/client';
|
||||
import ava, { type TestFn } from 'ava';
|
||||
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { AuthService } from '../src/core/auth/service';
|
||||
import { MailService } from '../src/fundamentals/mailer';
|
||||
import { AuthService } from '../src/modules/auth/service';
|
||||
import {
|
||||
acceptInviteById,
|
||||
createTestingApp,
|
||||
|
||||
Reference in New Issue
Block a user