-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvention.ts
53 lines (48 loc) · 1.56 KB
/
convention.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
import type { AccessArgs } from "payload/types";
import basic from "./kit/basic";
import access from "./spec/access";
import type { Expectation, LenientOpts, Opts, Spec } from "./types";
const defaults: Opts = {
user: {
slug: "user",
tag: { singular: { en: "User", zh: "用户" } },
},
role: {
slug: "role",
tag: { singular: { en: "Role", zh: "角色" } },
},
label: {
active: { en: "Active Flag", zh: "生效标记" },
features: { en: "Features", zh: "功能" },
verbs: { en: "Verbs", zh: "谓词" },
traits: { en: "Traits", zh: "特征" },
feature: { en: "Feature", zh: "功能" },
roleName: { en: "Role Name", zh: "角色名" },
"<admin>": { en: "< Admin Panel >", zh: "< 管理面板 >" },
"<unlock>": { en: "< Unlock >", zh: "< 解锁用户 >" },
create: { en: "Create", zh: "新增" },
read: { en: "Read", zh: "读取" },
update: { en: "Update", zh: "更新" },
delete: { en: "Delete", zh: "删除" },
},
};
/**
* Produces conventional {@link Opts} with given extension {@link LenientOpts}.
*/
export function opts(ext: LenientOpts): Opts {
return basic.merge({}, defaults, ext) as Opts;
}
/**
* A conventional variant of {@link access.check} with the {@link Spec} set to
* the default user and role slugs.
*/
export function check(
ex: Expectation,
{
user = defaults.user.slug,
role = defaults.role.slug,
}: { user?: string; role?: string } = {},
): (a: AccessArgs<any, any>) => boolean | Promise<boolean> {
return access.check(ex, { user, role });
}
export default { opts, check };