@yongdall/core 0.4.5 → 0.5.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BootConfiguration, Hook, Search } from "@yongdall/common";
2
- import { ClassDecorator, FieldDefine, Fields, Hooks, ModelTable, TableDefine, Where } from "@yongdall/model";
3
- import { Field, Permission, Permissions, Tenant } from "@yongdall/types";
2
+ import { ClassDecorator, FieldDefine, Hooks, ModelTable, Where } from "@yongdall/model";
3
+ import { Field, Permission, Permissions, Realm } from "@yongdall/types";
4
4
 
5
5
  //#region packages/core/types.d.mts
6
6
  type MaybePromise<T> = PromiseLike<T> | T;
@@ -20,8 +20,16 @@ interface WhereHook {
20
20
  notLabel?: string;
21
21
  not?: boolean | string;
22
22
  }
23
- interface TenantManager {
24
- (): MaybePromise<Tenant | null> | Tenant | null;
23
+ interface RealmManager {
24
+ (): MaybePromise<Realm | null> | Realm | null;
25
+ }
26
+ interface VisitorManager {
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
+ find: (account: string | Record<string, unknown>) => MaybePromise<string | null>;
32
+ exist(userId: string): MaybePromise<boolean>;
25
33
  }
26
34
  interface UserManager {
27
35
  get(): MaybePromise<string | null>;
@@ -40,48 +48,12 @@ interface UserManager {
40
48
  getOrganizationPermissions(user: string): MaybePromise<Record<string, Set<string> | string[]> | null>;
41
49
  getOrganizationAllPermissions(user: string): MaybePromise<Set<string> | string[] | null>;
42
50
  }
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
51
  /** 应用配置 */
71
52
  interface Hooks$1 {
72
- pages: PluginPages;
73
53
  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;
54
+ /** @deprecated */
55
+ tenantManager: RealmManager;
81
56
  [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
57
  where: Record<string, Record<string, WhereHook>>;
86
58
  }
87
59
  declare namespace Hooks$1 {
@@ -96,7 +68,7 @@ declare const hooks: Hook<Hooks$1>;
96
68
  //#region packages/core/config.d.mts
97
69
  /**
98
70
  *
99
- * @param {Partial<Omit<Tenant, 'id'>>} tenant
71
+ * @param {Partial<Omit<Realm, 'id'>>} realm
100
72
  * @param {object} boot
101
73
  * @returns
102
74
  */
@@ -105,11 +77,13 @@ declare function initConfig({
105
77
  single,
106
78
  providers,
107
79
  salt
108
- }: Partial<Omit<Tenant, "id">>, boot: object): void;
109
- /** @import { Tenant } from '@yongdall/types' */
80
+ }: Partial<Omit<Realm, "id">>, boot: object): void;
81
+ /** @import { Realm } from '@yongdall/types' */
110
82
  /** @import { BootConfiguration } from '@yongdall/common' */
111
- /** @type {Tenant} */
112
- declare const mainTenant: Tenant;
83
+ /** @type {Realm} */
84
+ declare const mainRealm: Realm;
85
+ /** @deprecated */
86
+ declare const mainTenant: Realm;
113
87
  /** @type {BootConfiguration} */
114
88
  declare const bootConfiguration: BootConfiguration;
115
89
  //#endregion
@@ -143,10 +117,6 @@ declare function getModel(ident: string | string[]): Promise<ModelTable | null>;
143
117
  * @returns {Promise<Permission[]?>}
144
118
  */
145
119
  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
120
  /** @type {(modelId: string, groupId?: string?) => Promise<Permission[]?>} */
151
121
  declare const getModelPermissions: (modelId: string, groupId?: string | null) => Promise<Permission[] | null>;
152
122
  //#endregion
@@ -269,7 +239,39 @@ declare const loadUserPermissions: (user?: string | null) => Promise<Set<string>
269
239
  declare const loadUserOrganizationAllPermissions: (user?: string | null) => Promise<Set<string>>;
270
240
  /** @type {(user?: string?) => Promise<Record<string, Set<string>>>} */
271
241
  declare const loadUserOrganizationPermissions: (user?: string | null) => Promise<Record<string, Set<string>>>;
272
- type State = [result: string | null, UserManager["set"] | null, UserManager["exit"] | null, user: string | null, sUser: string | null];
242
+ type UserState = [result: string | null, UserManager["set"] | null, UserManager["exit"] | null, user: string | null, sUser: string | null];
243
+ //#endregion
244
+ //#region packages/core/visitor.d.mts
245
+ /**
246
+ *
247
+ * @param {string} visitorId
248
+ * @returns {Promise<boolean>}
249
+ */
250
+ declare function existVisitor(visitorId: string): Promise<boolean>;
251
+ /**
252
+ *
253
+ * @returns {Promise<string?>}
254
+ */
255
+ declare function getVisitor(): Promise<string | null>;
256
+ /**
257
+ *
258
+ * @param {string?} visitorId
259
+ * @returns {Promise<string?>}
260
+ */
261
+ declare function setVisitor(visitorId: string | null): Promise<string | null>;
262
+ /**
263
+ *
264
+ * @param {Record<string, unknown>} loginName
265
+ * @returns {Promise<string>}
266
+ */
267
+ declare function findVisitor(loginName: Record<string, unknown>): Promise<string>;
268
+ /**
269
+ *
270
+ * @param {string} visitorId
271
+ * @returns {Promise<Record<string, any>>}
272
+ */
273
+ declare function loadVisitor(visitorId: string): Promise<Record<string, any>>;
274
+ type VisitorState = [result: string | null, VisitorManager["set"] | null, VisitorManager["exit"] | null, visitor: string | null];
273
275
  //#endregion
274
276
  //#region packages/core/permission/createPermissionMatches.d.mts
275
277
  /**
@@ -364,22 +366,32 @@ declare function bindModelHooks({
364
366
  */
365
367
  declare function modelHook(...hookNames: (string | string[])[]): ClassDecorator;
366
368
  //#endregion
367
- //#region packages/core/tenant.d.mts
369
+ //#region packages/core/safe.d.mts
368
370
  /**
371
+ * 使用 HMAC-SHA256 对一个或多个值进行哈希,使用 salt 作为密钥。
372
+ * 输出为 base64url 格式。
369
373
  *
370
- * @returns {Promise<Tenant>}
374
+ * @param {string | ArrayBuffer | ArrayBufferView<ArrayBuffer>} salt
375
+ * @param {string | number} value
376
+ * @param {...(string | number)} values
377
+ * @returns {Promise<string>}
371
378
  */
372
- declare function useTenant(): Promise<Tenant>;
379
+ declare function hashSHA256(salt: string | ArrayBuffer | ArrayBufferView<ArrayBuffer>, value: string | number, ...values: (string | number)[]): Promise<string>;
373
380
  //#endregion
374
381
  //#region packages/core/ServerError.d.mts
375
382
  declare class ServerError extends Error {
376
383
  /**
377
384
  *
378
- * @param {string} message
385
+ * @param {string | {code?: string; message: string; status?: number}} message
379
386
  * @param {number} [status]
380
387
  */
381
- constructor(message: string, status?: number);
388
+ constructor(message: string | {
389
+ code?: string;
390
+ message: string;
391
+ status?: number;
392
+ }, status?: number);
382
393
  status: number;
394
+ code: string;
383
395
  }
384
396
  //#endregion
385
397
  //#region packages/core/toDocumentFields.d.mts
@@ -409,14 +421,24 @@ declare function getEnumerations(name: string): Promise<Record<string, any>[]>;
409
421
  */
410
422
  declare function search2where(fields: Record<string, FieldDefine>, and?: Search.AndList, or?: Search.OrList, or2?: Search.OrList): Promise<Where | null>;
411
423
  //#endregion
424
+ //#region packages/core/realm.d.mts
425
+ /**
426
+ *
427
+ * @returns {Promise<Realm>}
428
+ */
429
+ declare function useRealm(): Promise<Realm>;
430
+ declare function useSalt(): Promise<string | Uint8Array<ArrayBuffer>>;
431
+ /** @deprecated */
432
+ declare function useTenant(): Promise<Realm>;
433
+ //#endregion
412
434
  //#region packages/core/index.d.mts
413
435
  /**
414
436
  *
415
- * @param {Partial<Omit<Tenant, 'id'>>} tenant
437
+ * @param {Partial<Omit<Realm, 'id'>>} realm
416
438
  * @param {object} boot
417
439
  * @param {Record<string, Partial<Hooks>>} pluginHooks
418
440
  * @returns
419
441
  */
420
- declare function initSystem(tenant: Partial<Omit<Tenant, "id">>, boot: object, pluginHooks: Record<string, Partial<Hooks$1>>): void;
442
+ declare function initSystem(realm: Partial<Omit<Realm, "id">>, boot: object, pluginHooks: Record<string, Partial<Hooks$1>>): void;
421
443
  //#endregion
422
- export { ServerError, State, bindModelHooks, bootConfiguration, createPermissionMatches, initSystem as default, existUser, filterPermissionDocument, filterPermissionUpdate, filterPermissions, findModel, findUser, getEnumerations, getMenus, getModel, getModelAuthorizationPermissions, getModelPermissions, getUser, getUserOrganizationAllPermissions, getUserOrganizationPermissions, getUserPermissions, hasUserOrganizationPermissions, hasUserPermission, hooks, initConfig, isSingleUser, loadPluginUser, loadUser, loadUserOrganizationAllPermissions, loadUserOrganizationPermissions, loadUserPermissions, mainTenant, modelHook, modelLoaders, models, nestedSetTree, search2where, setUser, setUserVerify, testPermissionConstraints, testPermissions, toDocumentFields, useTenant, verifyUser };
444
+ export { ServerError, UserState, VisitorState, bindModelHooks, bootConfiguration, createPermissionMatches, initSystem as default, existUser, existVisitor, filterPermissionDocument, filterPermissionUpdate, filterPermissions, findModel, findUser, findVisitor, getEnumerations, getMenus, getModel, getModelAuthorizationPermissions, getModelPermissions, getUser, getUserOrganizationAllPermissions, getUserOrganizationPermissions, getUserPermissions, getVisitor, hasUserOrganizationPermissions, hasUserPermission, hashSHA256, hooks, initConfig, isSingleUser, loadPluginUser, loadUser, loadUserOrganizationAllPermissions, loadUserOrganizationPermissions, loadUserPermissions, loadVisitor, mainRealm, mainTenant, modelHook, nestedSetTree, search2where, setUser, setUserVerify, setVisitor, testPermissionConstraints, testPermissions, toDocumentFields, useRealm, useSalt, useTenant, verifyUser };