@yongdall/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +389 -0
- package/index.mjs +1709 -0
- package/index.mjs.map +1 -0
- package/package.json +21 -0
package/index.d.mts
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { BootConfiguration, Hook, Search } from "@yongdall/common";
|
|
2
|
+
import { ClassDecorator, FieldDefine, Fields, Hooks, ModelTable, TableDefine, Where } from "@yongdall/model";
|
|
3
|
+
import { Field, Permission, Tenant } from "@yongdall/types";
|
|
4
|
+
|
|
5
|
+
//#region packages/core/types.d.mts
|
|
6
|
+
type MaybePromise<T> = PromiseLike<T> | T;
|
|
7
|
+
declare namespace WhereHook {
|
|
8
|
+
type Value = (name: string, value: any, define: FieldDefine) => MaybePromise<Where | null>;
|
|
9
|
+
type Field = (name: string, field: any, define: FieldDefine, fieldDefine: FieldDefine) => MaybePromise<Where | null>;
|
|
10
|
+
type Named = (name: string, value: string, define: FieldDefine) => MaybePromise<Where | null>;
|
|
11
|
+
}
|
|
12
|
+
interface WhereHook {
|
|
13
|
+
label: string;
|
|
14
|
+
value?: WhereHook.Value | null;
|
|
15
|
+
named?: WhereHook.Named | null;
|
|
16
|
+
field?: WhereHook.Field | null;
|
|
17
|
+
notValue?: WhereHook.Value | null;
|
|
18
|
+
notNamed?: WhereHook.Named | null;
|
|
19
|
+
notField?: WhereHook.Field | null;
|
|
20
|
+
notLabel?: string;
|
|
21
|
+
not?: boolean | string;
|
|
22
|
+
}
|
|
23
|
+
interface TenantManager {
|
|
24
|
+
(): MaybePromise<Tenant | null> | Tenant | null;
|
|
25
|
+
}
|
|
26
|
+
interface UserManager {
|
|
27
|
+
get(): MaybePromise<string | null>;
|
|
28
|
+
set(user: string | null): MaybePromise<string | null>;
|
|
29
|
+
exit(user: string | null): MaybePromise<string | null>;
|
|
30
|
+
login(user: string | null): MaybePromise<string | null>;
|
|
31
|
+
suGet(): MaybePromise<string | null>;
|
|
32
|
+
switchable(user: string, su: string): MaybePromise<boolean | null | void>;
|
|
33
|
+
find: (account: string | Record<string, unknown>, loginTypes: Set<string>) => MaybePromise<string | null>;
|
|
34
|
+
verify: Record<string, (userId: string, password: string) => MaybePromise<number>>;
|
|
35
|
+
setVerify: Record<string, (userId: string, password: string | null, deadline?: Date | null) => MaybePromise<boolean>>;
|
|
36
|
+
load(userId: string): MaybePromise<Record<string, any>>;
|
|
37
|
+
loadPlugin(userId: string): MaybePromise<Record<string, any>>;
|
|
38
|
+
exist(userId: string, login?: boolean): MaybePromise<boolean>;
|
|
39
|
+
getPermissions(user: string): MaybePromise<Set<string> | string[] | null>;
|
|
40
|
+
getOrganizationPermissions(user: string): MaybePromise<Record<string, Set<string> | string[]> | null>;
|
|
41
|
+
getOrganizationAllPermissions(user: string): MaybePromise<Set<string> | string[] | null>;
|
|
42
|
+
}
|
|
43
|
+
/** 应用页面配置 */
|
|
44
|
+
interface PluginPages {
|
|
45
|
+
home?: string;
|
|
46
|
+
settings?: string;
|
|
47
|
+
todo?: string;
|
|
48
|
+
search?: string;
|
|
49
|
+
status?: string;
|
|
50
|
+
devtools?: string;
|
|
51
|
+
}
|
|
52
|
+
interface PermissionHook {
|
|
53
|
+
modelAccessible(model: TableDefine): MaybePromise<boolean>;
|
|
54
|
+
collectionAccessible(collection: TableDefine): MaybePromise<boolean>;
|
|
55
|
+
fieldAccessible(collection: TableDefine): MaybePromise<Iterable<string>>;
|
|
56
|
+
fields(collection: TableDefine): MaybePromise<Iterable<string>>;
|
|
57
|
+
match(collection: TableDefine): MaybePromise<Where>;
|
|
58
|
+
create(collection: TableDefine, document: object): MaybePromise<boolean>;
|
|
59
|
+
accessible(collection: TableDefine, document: object): MaybePromise<boolean>;
|
|
60
|
+
get(collection: TableDefine, data: object, document: object): MaybePromise<boolean>;
|
|
61
|
+
destroy(collection: TableDefine, document: object): MaybePromise<boolean>;
|
|
62
|
+
update(collection: TableDefine, document: object, data: object): MaybePromise<boolean>;
|
|
63
|
+
getDocPermissions(collection: TableDefine, document: object): MaybePromise<string[] | boolean | null>;
|
|
64
|
+
getModelPermissions(collection: TableDefine): MaybePromise<string[] | boolean | null>;
|
|
65
|
+
queryDataFilter(collection: TableDefine, list: [data: object, document: object][]): MaybePromise<void>;
|
|
66
|
+
}
|
|
67
|
+
interface ModelLoader<T extends ModelTable = ModelTable> {
|
|
68
|
+
(name: string[]): MaybePromise<T | null>;
|
|
69
|
+
}
|
|
70
|
+
/** 应用配置 */
|
|
71
|
+
interface Hooks$1 {
|
|
72
|
+
pages: PluginPages;
|
|
73
|
+
reset(): void;
|
|
74
|
+
models: Record<string, ModelTable>;
|
|
75
|
+
migrationModels: ModelTable;
|
|
76
|
+
modelLoaders: Record<string, ModelLoader<any>>;
|
|
77
|
+
modelExpands: Record<string, Fields<TableDefine>>;
|
|
78
|
+
userManager: UserManager;
|
|
79
|
+
tenantManager: TenantManager;
|
|
80
|
+
permission: PermissionHook;
|
|
81
|
+
[k: string]: unknown;
|
|
82
|
+
modelHook: Record<string, Hooks>;
|
|
83
|
+
getModelPermissions(modelId: string, groupId?: string | null): PromiseLike<Permission[] | null> | Permission[] | null;
|
|
84
|
+
enumerations: Record<string, Record<string, any> | Record<string, any>[] | (() => Record<string, any>[])>;
|
|
85
|
+
where: Record<string, Record<string, WhereHook>>;
|
|
86
|
+
}
|
|
87
|
+
declare namespace Hooks$1 {
|
|
88
|
+
type Define = Hook.Define<Hooks$1>;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region packages/core/hooks.d.mts
|
|
92
|
+
/** @import { Hooks } from './types.mjs' */
|
|
93
|
+
/** @type {Hook<Hooks>} */
|
|
94
|
+
declare const hooks: Hook<Hooks$1>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region packages/core/config.d.mts
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {Partial<Omit<Tenant, 'id'>>} tenant
|
|
100
|
+
* @param {object} boot
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
declare function initConfig({
|
|
104
|
+
label,
|
|
105
|
+
single,
|
|
106
|
+
providers,
|
|
107
|
+
salt
|
|
108
|
+
}: Partial<Omit<Tenant, "id">>, boot: object): void;
|
|
109
|
+
/** @import { Tenant } from '@yongdall/types' */
|
|
110
|
+
/** @import { BootConfiguration } from '@yongdall/common' */
|
|
111
|
+
/** @type {Tenant} */
|
|
112
|
+
declare const mainTenant: Tenant;
|
|
113
|
+
/** @type {BootConfiguration} */
|
|
114
|
+
declare const bootConfiguration: BootConfiguration;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region packages/core/menu.d.mts
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param {string} type
|
|
120
|
+
* @param {string} [group]
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
declare function getMenus(type: string, group?: string): any;
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region packages/core/models.d.mts
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @param {string | string[]} ident
|
|
129
|
+
* @returns {Promise<ModelTable?>}
|
|
130
|
+
*/
|
|
131
|
+
declare function findModel(ident: string | string[]): Promise<ModelTable | null>;
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
* @param {string | string[]} ident
|
|
135
|
+
* @returns {Promise<ModelTable?>}
|
|
136
|
+
*/
|
|
137
|
+
declare function getModel(ident: string | string[]): Promise<ModelTable | null>;
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param {string} modelId
|
|
141
|
+
* @param {string} authorization
|
|
142
|
+
* @param {string?} [groupId]
|
|
143
|
+
* @returns {Promise<Permission[]?>}
|
|
144
|
+
*/
|
|
145
|
+
declare function getModelAuthorizationPermissions(modelId: string, authorization: string, groupId?: string | null): Promise<Permission[] | null>;
|
|
146
|
+
/** @type {Hooks['models']} */
|
|
147
|
+
declare let models: Hooks$1["models"];
|
|
148
|
+
/** @type {Hooks['modelLoaders']} */
|
|
149
|
+
declare let modelLoaders: Hooks$1["modelLoaders"];
|
|
150
|
+
/** @type {(modelId: string, groupId?: string?) => Promise<Permission[]?>} */
|
|
151
|
+
declare const getModelPermissions: (modelId: string, groupId?: string | null) => Promise<Permission[] | null>;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region packages/core/user.d.mts
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
* @param {string} userId
|
|
157
|
+
* @param {boolean} [login]
|
|
158
|
+
* @returns {Promise<boolean>}
|
|
159
|
+
*/
|
|
160
|
+
declare function existUser(userId: string, login?: boolean): Promise<boolean>;
|
|
161
|
+
/**
|
|
162
|
+
* @param {boolean} [logged]
|
|
163
|
+
* @returns {Promise<boolean>}
|
|
164
|
+
*/
|
|
165
|
+
declare function isSingleUser(logged?: boolean): Promise<boolean>;
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* @param {boolean?} [logged] 是否为登陆用户
|
|
169
|
+
* @returns {Promise<string?>}
|
|
170
|
+
*/
|
|
171
|
+
declare function getUser(logged?: boolean | null): Promise<string | null>;
|
|
172
|
+
/**
|
|
173
|
+
*
|
|
174
|
+
* @param {string?} userId
|
|
175
|
+
* @param {boolean?} [sudo]
|
|
176
|
+
* @returns {Promise<string?>}
|
|
177
|
+
*/
|
|
178
|
+
declare function setUser(userId: string | null, sudo?: boolean | null): Promise<string | null>;
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
* @param {string | Record<string, unknown>} loginName
|
|
182
|
+
* @param {string | string[]} [loginType]
|
|
183
|
+
* @returns {Promise<string>}
|
|
184
|
+
*/
|
|
185
|
+
declare function findUser(loginName: string | Record<string, unknown>, loginType?: string | string[]): Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param {string} userId
|
|
189
|
+
* @param {string} password
|
|
190
|
+
* @param {string} type
|
|
191
|
+
* @param {boolean} [returnError]
|
|
192
|
+
* @returns {Promise<number>}
|
|
193
|
+
*/
|
|
194
|
+
declare function verifyUser(userId: string, password: string, type: string, returnError?: boolean): Promise<number>;
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param {string} userId
|
|
198
|
+
* @param {string} type
|
|
199
|
+
* @param {string?} password
|
|
200
|
+
* @param {Date?} [deadline]
|
|
201
|
+
* @returns {Promise<boolean>}
|
|
202
|
+
*/
|
|
203
|
+
declare function setUserVerify(userId: string, type: string, password: string | null, deadline?: Date | null): Promise<boolean>;
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param {boolean?} [logged] 是否为登陆用户
|
|
207
|
+
* @returns {Promise<Set<string>>}
|
|
208
|
+
*/
|
|
209
|
+
declare function getUserPermissions(logged?: boolean | null): Promise<Set<string>>;
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @param {boolean?} [logged] 是否为登陆用户
|
|
213
|
+
* @returns {Promise<Set<string>>}
|
|
214
|
+
*/
|
|
215
|
+
declare function getUserOrganizationAllPermissions(logged?: boolean | null): Promise<Set<string>>;
|
|
216
|
+
/**
|
|
217
|
+
*
|
|
218
|
+
* @param {boolean?} [logged] 是否为登陆用户
|
|
219
|
+
* @returns {Promise<Record<string, Set<string>>>}
|
|
220
|
+
*/
|
|
221
|
+
declare function getUserOrganizationPermissions(logged?: boolean | null): Promise<Record<string, Set<string>>>;
|
|
222
|
+
/**
|
|
223
|
+
*
|
|
224
|
+
* @param {string} userId
|
|
225
|
+
* @returns {Promise<Record<string, any>>}
|
|
226
|
+
*/
|
|
227
|
+
declare function loadPluginUser(userId: string): Promise<Record<string, any>>;
|
|
228
|
+
/**
|
|
229
|
+
*
|
|
230
|
+
* @param {string} userId
|
|
231
|
+
* @returns {Promise<Record<string, any>>}
|
|
232
|
+
*/
|
|
233
|
+
declare function loadUser(userId: string, plugin?: boolean): Promise<Record<string, any>>;
|
|
234
|
+
/** @type {(user?: string?) => Promise<Set<string>>} */
|
|
235
|
+
declare const loadUserPermissions: (user?: string | null) => Promise<Set<string>>;
|
|
236
|
+
/** @type {(user?: string?) => Promise<Set<string>>} */
|
|
237
|
+
declare const loadUserOrganizationAllPermissions: (user?: string | null) => Promise<Set<string>>;
|
|
238
|
+
/** @type {(user?: string?) => Promise<Record<string, Set<string>>>} */
|
|
239
|
+
declare const loadUserOrganizationPermissions: (user?: string | null) => Promise<Record<string, Set<string>>>;
|
|
240
|
+
type State = [result: string | null, UserManager["set"] | null, UserManager["exit"] | null, user: string | null, sUser: string | null];
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region packages/core/permission/createPermissionMatches.d.mts
|
|
243
|
+
/**
|
|
244
|
+
* @param {Permission[]} permissions
|
|
245
|
+
*/
|
|
246
|
+
declare function createPermissionMatches(permissions: Permission[]): Promise<Where | null>;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region packages/core/permission/filterPermissionDocument.d.mts
|
|
249
|
+
/**
|
|
250
|
+
* @param {ModelTable} model
|
|
251
|
+
* @param {Permission[]} permissions
|
|
252
|
+
* @param {Record<string, any>} document
|
|
253
|
+
*/
|
|
254
|
+
declare function filterPermissionDocument({
|
|
255
|
+
fields
|
|
256
|
+
}: ModelTable, permissions: Permission[], document: Record<string, any>): Promise<Record<string, any> | null>;
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region packages/core/permission/filterPermissions.d.mts
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @param {Permission[]} allPermissions
|
|
262
|
+
* @param {Record<string, any>} document
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
declare function filterPermissions(allPermissions: Permission[], document: Record<string, any>): Promise<Permission[]>;
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region packages/core/permission/filterPermissionUpdate.d.mts
|
|
268
|
+
/**
|
|
269
|
+
* @param {ModelTable} model
|
|
270
|
+
* @param {Permission[]} permissions
|
|
271
|
+
* @param {Record<string, any>} document
|
|
272
|
+
* @param {Record<string, any>} newDocument
|
|
273
|
+
*/
|
|
274
|
+
declare function filterPermissionUpdate({
|
|
275
|
+
fields
|
|
276
|
+
}: ModelTable, permissions: Permission[], document: Record<string, any>, newDocument: Record<string, any>): Promise<Record<string, any> | null>;
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region packages/core/permission/testPermissionConstraints.d.mts
|
|
279
|
+
/** @import { Permission } from '@yongdall/types' */
|
|
280
|
+
/**
|
|
281
|
+
*
|
|
282
|
+
* @param {Exclude<Permission['constraints'], void>} constraints
|
|
283
|
+
* @param {Record<string, any>} document
|
|
284
|
+
* @param {string?} userId
|
|
285
|
+
*/
|
|
286
|
+
declare function testPermissionConstraints(constraints: Exclude<Permission["constraints"], void>, document: Record<string, any>, userId: string | null): boolean;
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region packages/core/permission/testPermissions.d.mts
|
|
289
|
+
/** @import { Permission } from '@yongdall/types' */
|
|
290
|
+
/**
|
|
291
|
+
*
|
|
292
|
+
* @param {Permission[]?} [allPermissions]
|
|
293
|
+
* @param {Record<string, any>} [document]
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
declare function testPermissions(allPermissions?: Permission[] | null, document?: Record<string, any>): Promise<boolean>;
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region packages/core/decorators/nestedSetTree.d.mts
|
|
299
|
+
/**
|
|
300
|
+
*
|
|
301
|
+
* @param {string} parentField
|
|
302
|
+
* @param {string} lftField
|
|
303
|
+
* @param {string} rgtField
|
|
304
|
+
* @param {string} idField
|
|
305
|
+
* @param {...string} groupFields
|
|
306
|
+
*/
|
|
307
|
+
declare function nestedSetTree(parentField: string, lftField?: string, rgtField?: string, idField?: string, ...groupFields: string[]): (Model: any, ctx: ClassDecoratorContext) => void;
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region packages/core/decorators/modelHook.d.mts
|
|
310
|
+
/**
|
|
311
|
+
*
|
|
312
|
+
* @param {Partial<Hooks>} hooks
|
|
313
|
+
* @param {...string | string[]} hookNames
|
|
314
|
+
* @returns {Hooks}
|
|
315
|
+
*/
|
|
316
|
+
declare function bindModelHooks({
|
|
317
|
+
where,
|
|
318
|
+
beforeCreateMany,
|
|
319
|
+
afterCreateMany,
|
|
320
|
+
beforeCreate,
|
|
321
|
+
afterCreate,
|
|
322
|
+
beforeUpdate,
|
|
323
|
+
afterUpdate,
|
|
324
|
+
beforeDelete,
|
|
325
|
+
afterDelete
|
|
326
|
+
}: Partial<Hooks>, ...hookNames: (string | string[])[]): Hooks;
|
|
327
|
+
/**
|
|
328
|
+
*
|
|
329
|
+
* @param {...string | string[]} hookNames
|
|
330
|
+
* @returns {ClassDecorator}
|
|
331
|
+
*/
|
|
332
|
+
declare function modelHook(...hookNames: (string | string[])[]): ClassDecorator;
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region packages/core/tenant.d.mts
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* @returns {Promise<Tenant>}
|
|
338
|
+
*/
|
|
339
|
+
declare function useTenant(): Promise<Tenant>;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region packages/core/ServerError.d.mts
|
|
342
|
+
declare class ServerError extends Error {
|
|
343
|
+
/**
|
|
344
|
+
*
|
|
345
|
+
* @param {string} message
|
|
346
|
+
* @param {number} [status]
|
|
347
|
+
*/
|
|
348
|
+
constructor(message: string, status?: number);
|
|
349
|
+
status: number;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region packages/core/toDocumentFields.d.mts
|
|
353
|
+
/**
|
|
354
|
+
*
|
|
355
|
+
* @param {Record<string, FieldDefine>} fields
|
|
356
|
+
* @returns {Record<string, Field>}
|
|
357
|
+
*/
|
|
358
|
+
declare function toDocumentFields(fields: Record<string, FieldDefine>): Record<string, Field>;
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region packages/core/enumerations.d.mts
|
|
361
|
+
/**
|
|
362
|
+
*
|
|
363
|
+
* @param {string} name
|
|
364
|
+
* @returns {Promise<Record<string, any>[]>}
|
|
365
|
+
*/
|
|
366
|
+
declare function getEnumerations(name: string): Promise<Record<string, any>[]>;
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region packages/core/search2where/index.d.mts
|
|
369
|
+
/**
|
|
370
|
+
*
|
|
371
|
+
* @param {Record<string, FieldDefine>} fields
|
|
372
|
+
* @param {Search.AndList} [and]
|
|
373
|
+
* @param {Search.OrList} [or]
|
|
374
|
+
* @param {Search.OrList} [or2]
|
|
375
|
+
* @returns {Promise<Where?>}
|
|
376
|
+
*/
|
|
377
|
+
declare function search2where(fields: Record<string, FieldDefine>, and?: Search.AndList, or?: Search.OrList, or2?: Search.OrList): Promise<Where | null>;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region packages/core/index.d.mts
|
|
380
|
+
/**
|
|
381
|
+
*
|
|
382
|
+
* @param {Partial<Omit<Tenant, 'id'>>} tenant
|
|
383
|
+
* @param {object} boot
|
|
384
|
+
* @param {Record<string, Partial<Hooks>>} pluginHooks
|
|
385
|
+
* @returns
|
|
386
|
+
*/
|
|
387
|
+
declare function initSystem(tenant: Partial<Omit<Tenant, "id">>, boot: object, pluginHooks: Record<string, Partial<Hooks$1>>): void;
|
|
388
|
+
//#endregion
|
|
389
|
+
export { ServerError, State, bindModelHooks, bootConfiguration, createPermissionMatches, initSystem as default, existUser, filterPermissionDocument, filterPermissionUpdate, filterPermissions, findModel, findUser, getEnumerations, getMenus, getModel, getModelAuthorizationPermissions, getModelPermissions, getUser, getUserOrganizationAllPermissions, getUserOrganizationPermissions, getUserPermissions, hooks, initConfig, isSingleUser, loadPluginUser, loadUser, loadUserOrganizationAllPermissions, loadUserOrganizationPermissions, loadUserPermissions, mainTenant, modelHook, modelLoaders, models, nestedSetTree, search2where, setUser, setUserVerify, testPermissionConstraints, testPermissions, toDocumentFields, useTenant, verifyUser };
|