-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
base.ts
247 lines (218 loc) · 5.25 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
import { MessageCenter } from '../message';
import { Logger, User } from '../types';
import type { WorkspaceUnitCollectionScope } from '../workspace-unit-collection';
import type { WorkspaceUnitCtorParams, WorkspaceUnit } from '../workspace-unit';
import { Member } from './affine/apis';
import { Permission } from './affine/apis/workspace';
const defaultLogger = () => {
return;
};
export interface ProviderConstructorParams {
logger?: Logger;
workspaces: WorkspaceUnitCollectionScope;
messageCenter: MessageCenter;
}
export type WorkspaceMeta0 = WorkspaceUnitCtorParams;
export type CreateWorkspaceInfoParams = Pick<WorkspaceUnitCtorParams, 'name'>;
export type UpdateWorkspaceMetaParams = Partial<
Pick<WorkspaceUnitCtorParams, 'name' | 'avatar'>
>;
export class BaseProvider {
/** provider id */
public readonly id: string = 'base';
/** workspace unit collection */
protected _workspaces!: WorkspaceUnitCollectionScope;
protected _logger!: Logger;
/** send message with message center */
protected _sendMessage!: ReturnType<
InstanceType<typeof MessageCenter>['getMessageSender']
>;
public constructor({
logger,
workspaces,
messageCenter,
}: ProviderConstructorParams) {
this._logger = (logger || defaultLogger) as Logger;
this._workspaces = workspaces;
this._sendMessage = messageCenter.getMessageSender(this.id);
}
/**
* hook after provider registered
*/
public async init() {
return;
}
/**
* auth provider
*/
public async auth() {
return;
}
/**
* logout provider
*/
public async logout() {
return;
}
public getToken(): string {
return '';
}
/**
* warp workspace with provider functions
* @param workspace
* @returns
*/
public async warpWorkspace(
workspace: BlocksuiteWorkspace
): Promise<BlocksuiteWorkspace> {
return workspace;
}
/**
* @deprecated Temporary for public workspace
* @param blocksuiteWorkspace
* @returns
*/
public async loadPublicWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) {
return blocksuiteWorkspace;
}
/**
* load workspaces
**/
public async loadWorkspaces(): Promise<WorkspaceUnit[]> {
throw new Error(`provider: ${this.id} loadWorkSpace Not implemented`);
}
/**
* get auth user info
* @returns
*/
public async getUserInfo(): Promise<User | undefined> {
return;
}
// async getBlob(id: string): Promise<string | null> {
// return await this._blobs.get(id);
// }
// async setBlob(blob: Blob): Promise<string> {
// return await this._blobs.set(blob);
// }
/**
* clear all local data in provider
*/
async clear() {
// this._blobs.clear();
}
/**
* delete workspace include all data
* @param id workspace id
*/
public async deleteWorkspace(id: string): Promise<void> {
id;
return;
}
/**
* leave workspace by workspace id
* @param id workspace id
*/
public async leaveWorkspace(id: string): Promise<void> {
id;
return;
}
/**
* close db link and websocket connection and other resources
* @param id workspace id
*/
public async closeWorkspace(id: string) {
id;
return;
}
/**
* invite workspace member
* @param id workspace id
*/
public async invite(id: string, email: string): Promise<void> {
id;
email;
return;
}
/**
* remove workspace member by permission id
* @param permissionId
*/
public async removeMember(permissionId: number): Promise<void> {
permissionId;
return;
}
public async publish(id: string, isPublish: boolean): Promise<void> {
id;
isPublish;
return;
}
/**
* change workspace meta by workspace id , work for cached list in different provider
* @param id
* @param meta
* @returns
*/
public async updateWorkspaceMeta(
id: string,
params: UpdateWorkspaceMetaParams
): Promise<void> {
id;
params;
return;
}
/**
* create workspace by workspace meta
* @param {CreateWorkspaceInfoParams} meta
*/
public async createWorkspace(
meta: CreateWorkspaceInfoParams
): Promise<WorkspaceUnit | undefined> {
throw new Error(`provider: ${this.id} createWorkspace not implemented`);
}
public async extendWorkspace(
workspaceUnit: WorkspaceUnit
): Promise<WorkspaceUnit | undefined> {
throw new Error(`provider: ${this.id} extendWorkspace not implemented`);
}
/**
* get user by email
* @param {string} id
* @param {string} email
* @returns
*/
public async getUserByEmail(id: string, email: string): Promise<User | null> {
email;
return null;
}
/**
* link workspace to local caches
* @param workspace
* @returns
*/
public async linkLocal(
workspace: BlocksuiteWorkspace
): Promise<BlocksuiteWorkspace> {
return workspace;
}
/**
* get workspace members
* @param {string} workspaceId
* @returns
*/
public getWorkspaceMembers(workspaceId: string): Promise<Member[]> {
workspaceId;
return Promise.resolve([]);
}
/**
* accept invitation
* @param {string} inviteCode
* @returns
*/
public async acceptInvitation(
inviteCode: string
): Promise<Permission | null> {
inviteCode;
return null;
}
}