@yongdall/core 0.4.3 → 0.5.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BootConfiguration, Hook, Search } from "@yongdall/common";
2
- import { ClassDecorator, FieldDefine, Fields, Hooks, ModelTable, TableDefine, Where } from "@yongdall/model";
2
+ import { ClassDecorator, FieldDefine, Hooks, ModelTable, Where } from "@yongdall/model";
3
3
  import { Field, Permission, Permissions, Tenant } from "@yongdall/types";
4
4
 
5
5
  //#region packages/core/types.d.mts
@@ -23,6 +23,14 @@ interface WhereHook {
23
23
  interface TenantManager {
24
24
  (): MaybePromise<Tenant | null> | Tenant | null;
25
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>;
33
+ }
26
34
  interface UserManager {
27
35
  get(): MaybePromise<string | null>;
28
36
  set(user: string | null): MaybePromise<string | null>;
@@ -40,48 +48,11 @@ 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
54
  tenantManager: TenantManager;
80
- permission: PermissionHook;
81
55
  [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
56
  where: Record<string, Record<string, WhereHook>>;
86
57
  }
87
58
  declare namespace Hooks$1 {
@@ -143,10 +114,6 @@ declare function getModel(ident: string | string[]): Promise<ModelTable | null>;
143
114
  * @returns {Promise<Permission[]?>}
144
115
  */
145
116
  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
117
  /** @type {(modelId: string, groupId?: string?) => Promise<Permission[]?>} */
151
118
  declare const getModelPermissions: (modelId: string, groupId?: string | null) => Promise<Permission[] | null>;
152
119
  //#endregion
@@ -269,7 +236,39 @@ declare const loadUserPermissions: (user?: string | null) => Promise<Set<string>
269
236
  declare const loadUserOrganizationAllPermissions: (user?: string | null) => Promise<Set<string>>;
270
237
  /** @type {(user?: string?) => Promise<Record<string, Set<string>>>} */
271
238
  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];
239
+ type UserState = [result: string | null, UserManager["set"] | null, UserManager["exit"] | null, user: string | null, sUser: string | null];
240
+ //#endregion
241
+ //#region packages/core/visitor.d.mts
242
+ /**
243
+ *
244
+ * @param {string} visitorId
245
+ * @returns {Promise<boolean>}
246
+ */
247
+ declare function existVisitor(visitorId: string): Promise<boolean>;
248
+ /**
249
+ *
250
+ * @returns {Promise<string?>}
251
+ */
252
+ declare function getVisitor(): Promise<string | null>;
253
+ /**
254
+ *
255
+ * @param {string?} visitorId
256
+ * @returns {Promise<string?>}
257
+ */
258
+ declare function setVisitor(visitorId: string | null): Promise<string | null>;
259
+ /**
260
+ *
261
+ * @param {Record<string, unknown>} loginName
262
+ * @returns {Promise<string>}
263
+ */
264
+ declare function findVisitor(loginName: Record<string, unknown>): Promise<string>;
265
+ /**
266
+ *
267
+ * @param {string} visitorId
268
+ * @returns {Promise<Record<string, any>>}
269
+ */
270
+ declare function loadVisitor(visitorId: string): Promise<Record<string, any>>;
271
+ type VisitorState = [result: string | null, VisitorManager["set"] | null, VisitorManager["exit"] | null, visitor: string | null];
273
272
  //#endregion
274
273
  //#region packages/core/permission/createPermissionMatches.d.mts
275
274
  /**
@@ -364,6 +363,18 @@ declare function bindModelHooks({
364
363
  */
365
364
  declare function modelHook(...hookNames: (string | string[])[]): ClassDecorator;
366
365
  //#endregion
366
+ //#region packages/core/safe.d.mts
367
+ /**
368
+ * 使用 HMAC-SHA256 对一个或多个值进行哈希,使用 salt 作为密钥。
369
+ * 输出为 base64url 格式。
370
+ *
371
+ * @param {string | ArrayBuffer | ArrayBufferView<ArrayBuffer>} salt
372
+ * @param {string | number} value
373
+ * @param {...(string | number)} values
374
+ * @returns {Promise<string>}
375
+ */
376
+ declare function hashSHA256(salt: string | ArrayBuffer | ArrayBufferView<ArrayBuffer>, value: string | number, ...values: (string | number)[]): Promise<string>;
377
+ //#endregion
367
378
  //#region packages/core/tenant.d.mts
368
379
  /**
369
380
  *
@@ -375,11 +386,16 @@ declare function useTenant(): Promise<Tenant>;
375
386
  declare class ServerError extends Error {
376
387
  /**
377
388
  *
378
- * @param {string} message
389
+ * @param {string | {code?: string; message: string; status?: number}} message
379
390
  * @param {number} [status]
380
391
  */
381
- constructor(message: string, status?: number);
392
+ constructor(message: string | {
393
+ code?: string;
394
+ message: string;
395
+ status?: number;
396
+ }, status?: number);
382
397
  status: number;
398
+ code: string;
383
399
  }
384
400
  //#endregion
385
401
  //#region packages/core/toDocumentFields.d.mts
@@ -419,4 +435,4 @@ declare function search2where(fields: Record<string, FieldDefine>, and?: Search.
419
435
  */
420
436
  declare function initSystem(tenant: Partial<Omit<Tenant, "id">>, boot: object, pluginHooks: Record<string, Partial<Hooks$1>>): void;
421
437
  //#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 };
438
+ 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, mainTenant, modelHook, nestedSetTree, search2where, setUser, setUserVerify, setVisitor, testPermissionConstraints, testPermissions, toDocumentFields, useTenant, verifyUser };