@yongdall/permission-model 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 +32 -0
- package/index.mjs +3 -0
- package/package.json +22 -0
- package/permission-model-Bx3r4kMo.mjs +105 -0
- package/permission-model-Bx3r4kMo.mjs.map +1 -0
- package/yongdall/migration.mjs +10 -0
- package/yongdall/migration.mjs.map +1 -0
- package/yongdall/model.mjs +10 -0
- package/yongdall/model.mjs.map +1 -0
- package/yongdall.plugin.yml +1 -0
package/index.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as imodel0 from "imodel";
|
|
2
|
+
import * as _yongdall_model0 from "@yongdall/model";
|
|
3
|
+
import { Permission } from "@yongdall/types";
|
|
4
|
+
|
|
5
|
+
//#region plugins/permission-model/models/ModelPermissionGroup.d.mts
|
|
6
|
+
declare const _default: _yongdall_model0.ModelTable<{
|
|
7
|
+
modelId: imodel0.FieldDefine<"string", false, false>;
|
|
8
|
+
groupId: imodel0.FieldDefine<"string", false, false>;
|
|
9
|
+
default: imodel0.FieldDefine<"bool", false, false>;
|
|
10
|
+
permissions: imodel0.FieldDefine<_yongdall_model0.ModelTable<{
|
|
11
|
+
modelId: imodel0.FieldDefine<"string", false, false>;
|
|
12
|
+
groupId: imodel0.FieldDefine<"string", false, false>;
|
|
13
|
+
no: imodel0.FieldDefine<"string", false, false>;
|
|
14
|
+
organizationField: imodel0.FieldDefine<"string", false, false>;
|
|
15
|
+
permission: imodel0.FieldDefine<"string", false, false>;
|
|
16
|
+
group: imodel0.FieldDefine<"string", false, false>;
|
|
17
|
+
fields: imodel0.FieldDefine<"string", true, false>;
|
|
18
|
+
constraints: imodel0.FieldDefine<"object", false, false>;
|
|
19
|
+
authorizations: imodel0.FieldDefine<"string", true, false>;
|
|
20
|
+
}, "modelPermission">, true, false>;
|
|
21
|
+
}, "modelPermissionGroup">;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region plugins/permission-model/index.d.mts
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {string} modelId
|
|
27
|
+
* @param {string?} [groupId]
|
|
28
|
+
* @returns {Promise<Permission[]>}
|
|
29
|
+
*/
|
|
30
|
+
declare function getModelPermissions(modelId: string, groupId?: string | null): Promise<Permission[]>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { _default as ModelPermissionGroup, getModelPermissions };
|
package/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/permission-model",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./index.mjs",
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@yongdall/connection": "^0.5.0",
|
|
12
|
+
"@yongdall/model": "^0.5.0",
|
|
13
|
+
"@yongdall/core": "^0.5.0",
|
|
14
|
+
"@yongdall/types": "^0.5.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@yongdall/migrate": "^0.5.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./index.mjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Query, createField, createModel, getDefinePermission } from "@yongdall/model";
|
|
2
|
+
import { connect } from "@yongdall/connection";
|
|
3
|
+
import { getModel } from "@yongdall/core";
|
|
4
|
+
|
|
5
|
+
//#region plugins/permission-model/models/ModelPermissionGroup.mjs
|
|
6
|
+
const ModelPermission = createModel("modelPermission", {
|
|
7
|
+
modelId: createField("string", {
|
|
8
|
+
nullable: false,
|
|
9
|
+
index: true,
|
|
10
|
+
primary: 1
|
|
11
|
+
}),
|
|
12
|
+
groupId: createField("string", {
|
|
13
|
+
nullable: false,
|
|
14
|
+
index: true,
|
|
15
|
+
primary: 2
|
|
16
|
+
}),
|
|
17
|
+
no: createField("string", {
|
|
18
|
+
nullable: false,
|
|
19
|
+
index: true,
|
|
20
|
+
primary: 3
|
|
21
|
+
}),
|
|
22
|
+
organizationField: createField("string", {
|
|
23
|
+
nullable: false,
|
|
24
|
+
default: ""
|
|
25
|
+
}),
|
|
26
|
+
permission: createField("string", {
|
|
27
|
+
nullable: false,
|
|
28
|
+
default: ""
|
|
29
|
+
}),
|
|
30
|
+
group: createField("string", { nullable: false }),
|
|
31
|
+
fields: createField("string", {
|
|
32
|
+
array: true,
|
|
33
|
+
nullable: false,
|
|
34
|
+
default: []
|
|
35
|
+
}),
|
|
36
|
+
constraints: createField("object", {
|
|
37
|
+
nullable: false,
|
|
38
|
+
default: {}
|
|
39
|
+
}),
|
|
40
|
+
authorizations: createField("string", {
|
|
41
|
+
array: true,
|
|
42
|
+
nullable: false,
|
|
43
|
+
default: []
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
var ModelPermissionGroup_default = createModel("modelPermissionGroup", {
|
|
47
|
+
modelId: createField("string", {
|
|
48
|
+
nullable: false,
|
|
49
|
+
index: true,
|
|
50
|
+
primary: 1
|
|
51
|
+
}),
|
|
52
|
+
groupId: createField("string", {
|
|
53
|
+
nullable: false,
|
|
54
|
+
index: true,
|
|
55
|
+
primary: 2
|
|
56
|
+
}),
|
|
57
|
+
default: createField("bool", {
|
|
58
|
+
nullable: false,
|
|
59
|
+
default: false
|
|
60
|
+
}),
|
|
61
|
+
permissions: createField(ModelPermission, {
|
|
62
|
+
array: true,
|
|
63
|
+
constraints: {
|
|
64
|
+
modelId: { field: "modelId" },
|
|
65
|
+
groupId: { field: "groupId" },
|
|
66
|
+
no: { noField: true }
|
|
67
|
+
},
|
|
68
|
+
label: "权限列表"
|
|
69
|
+
})
|
|
70
|
+
}, { hooks: {
|
|
71
|
+
async beforeCreate(conn, Model, document) {
|
|
72
|
+
if (!document.default) return;
|
|
73
|
+
await conn.update(new Query(Model).where("modelId", document.modelId).where("groupId", "=", document.groupId, true), { default: false });
|
|
74
|
+
},
|
|
75
|
+
async beforeUpdate(conn, Model, document) {
|
|
76
|
+
if (!document.default) return;
|
|
77
|
+
await conn.update(new Query(Model).where("modelId", document.modelId).where("groupId", "=", document.groupId, true), { default: false });
|
|
78
|
+
}
|
|
79
|
+
} });
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region plugins/permission-model/index.mjs
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {string} modelId
|
|
86
|
+
* @param {string?} [groupId]
|
|
87
|
+
* @returns {Promise<Permission[]>}
|
|
88
|
+
*/
|
|
89
|
+
async function getModelPermissions(modelId, groupId) {
|
|
90
|
+
if (groupId) return await connect("rdb").select(new Query(ModelPermission).where({
|
|
91
|
+
modelId,
|
|
92
|
+
groupId
|
|
93
|
+
}));
|
|
94
|
+
/** @type {ModelPermissionGroup?} */
|
|
95
|
+
const permissionGroup = await connect("rdb").first(new Query(ModelPermissionGroup_default).where({
|
|
96
|
+
modelId,
|
|
97
|
+
default: true
|
|
98
|
+
}));
|
|
99
|
+
if (permissionGroup) return permissionGroup.permissions;
|
|
100
|
+
return getDefinePermission(await getModel(modelId));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ModelPermissionGroup_default as n, getModelPermissions as t };
|
|
105
|
+
//# sourceMappingURL=permission-model-Bx3r4kMo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-model-Bx3r4kMo.mjs","names":["ModelPermissionGroup"],"sources":["../../plugins/permission-model/models/ModelPermissionGroup.mjs","../../plugins/permission-model/index.mjs"],"sourcesContent":["import { createField, createModel, Query } from '@yongdall/model';\n\nexport const ModelPermission = createModel('modelPermission', {\n\tmodelId: createField('string', { nullable: false, index: true, primary: 1 }),\n\tgroupId: createField('string', { nullable: false, index: true, primary: 2 }),\n\tno: createField('string', { nullable: false, index: true, primary: 3 }),\n\n\torganizationField: createField('string', { nullable: false, default: '' }),\n\tpermission: createField('string', { nullable: false, default: '' }),\n\tgroup: createField('string', { nullable: false }),\n\tfields: createField('string', { array: true, nullable: false, default: [] }),\n\tconstraints: createField('object', { nullable: false, default: {} }),\n\tauthorizations: createField('string', { array: true, nullable: false, default: [] }),\n});\n\nexport default createModel('modelPermissionGroup', {\n\tmodelId: createField('string', { nullable: false, index: true, primary: 1 }),\n\tgroupId: createField('string', { nullable: false, index: true, primary: 2 }),\n\tdefault: createField('bool', { nullable: false, default: false }),\n\tpermissions: createField(ModelPermission, { array: true, constraints: { modelId: { field: 'modelId' }, groupId: { field: 'groupId' }, no: { noField: true } }, label: '权限列表' }),\n}, {\n\thooks: {\n\t\tasync beforeCreate(conn, Model, document) {\n\t\t\tif (!document.default) { return }\n\t\t\tawait conn.update(\n\t\t\t\tnew Query(Model)\n\t\t\t\t\t.where('modelId', document.modelId)\n\t\t\t\t\t.where('groupId', '=', document.groupId, true),\n\t\t\t\t{ default: false });\n\t\t},\n\t\tasync beforeUpdate(conn, Model, document) {\n\t\t\tif (!document.default) { return }\n\t\t\tawait conn.update(\n\t\t\t\tnew Query(Model)\n\t\t\t\t\t.where('modelId', document.modelId)\n\t\t\t\t\t.where('groupId', '=', document.groupId, true),\n\t\t\t\t{ default: false });\n\t\t},\n\t}\n});\n","import { Query } from '@yongdall/model';\nimport ModelPermissionGroup, { ModelPermission } from './models/ModelPermissionGroup.mjs';\nimport { connect } from '@yongdall/connection';\nimport { getModel } from '@yongdall/core';\nimport { getDefinePermission } from '@yongdall/model';\n/** @import { Permission } from '@yongdall/types' */\n\n\nexport * from './models/index.mjs';\n/**\n * \n * @param {string} modelId \n * @param {string?} [groupId] \n * @returns {Promise<Permission[]>}\n */\nexport async function getModelPermissions(modelId, groupId) {\n\tif (groupId) {\n\t\treturn await connect('rdb').select(new Query(ModelPermission).where({ modelId, groupId: groupId }));\n\t}\n\t/** @type {ModelPermissionGroup?} */\n\tconst permissionGroup = await connect('rdb').first(new Query(ModelPermissionGroup).where({ modelId, default: true }));\n\tif (permissionGroup) {\n\t\treturn permissionGroup.permissions;\n\t}\n\treturn getDefinePermission(await getModel(modelId));\n}\n"],"mappings":";;;;;AAEA,MAAa,kBAAkB,YAAY,mBAAmB;CAC7D,SAAS,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CAC5E,SAAS,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CAC5E,IAAI,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CAEvE,mBAAmB,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,CAAC;CAC1E,YAAY,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,CAAC;CACnE,OAAO,YAAY,UAAU,EAAE,UAAU,OAAO,CAAC;CACjD,QAAQ,YAAY,UAAU;EAAE,OAAO;EAAM,UAAU;EAAO,SAAS,EAAE;EAAE,CAAC;CAC5E,aAAa,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS,EAAE;EAAE,CAAC;CACpE,gBAAgB,YAAY,UAAU;EAAE,OAAO;EAAM,UAAU;EAAO,SAAS,EAAE;EAAE,CAAC;CACpF,CAAC;AAEF,mCAAe,YAAY,wBAAwB;CAClD,SAAS,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CAC5E,SAAS,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CAC5E,SAAS,YAAY,QAAQ;EAAE,UAAU;EAAO,SAAS;EAAO,CAAC;CACjE,aAAa,YAAY,iBAAiB;EAAE,OAAO;EAAM,aAAa;GAAE,SAAS,EAAE,OAAO,WAAW;GAAE,SAAS,EAAE,OAAO,WAAW;GAAE,IAAI,EAAE,SAAS,MAAM;GAAE;EAAE,OAAO;EAAQ,CAAC;CAC/K,EAAE,EACF,OAAO;CACN,MAAM,aAAa,MAAM,OAAO,UAAU;AACzC,MAAI,CAAC,SAAS,QAAW;AACzB,QAAM,KAAK,OACV,IAAI,MAAM,MAAM,CACd,MAAM,WAAW,SAAS,QAAQ,CAClC,MAAM,WAAW,KAAK,SAAS,SAAS,KAAK,EAC/C,EAAE,SAAS,OAAO,CAAC;;CAErB,MAAM,aAAa,MAAM,OAAO,UAAU;AACzC,MAAI,CAAC,SAAS,QAAW;AACzB,QAAM,KAAK,OACV,IAAI,MAAM,MAAM,CACd,MAAM,WAAW,SAAS,QAAQ,CAClC,MAAM,WAAW,KAAK,SAAS,SAAS,KAAK,EAC/C,EAAE,SAAS,OAAO,CAAC;;CAErB,EACD,CAAC;;;;;;;;;;ACxBF,eAAsB,oBAAoB,SAAS,SAAS;AAC3D,KAAI,QACH,QAAO,MAAM,QAAQ,MAAM,CAAC,OAAO,IAAI,MAAM,gBAAgB,CAAC,MAAM;EAAE;EAAkB;EAAS,CAAC,CAAC;;CAGpG,MAAM,kBAAkB,MAAM,QAAQ,MAAM,CAAC,MAAM,IAAI,MAAMA,6BAAqB,CAAC,MAAM;EAAE;EAAS,SAAS;EAAM,CAAC,CAAC;AACrH,KAAI,gBACH,QAAO,gBAAgB;AAExB,QAAO,oBAAoB,MAAM,SAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as ModelPermissionGroup_default, t as getModelPermissions } from "../permission-model-Bx3r4kMo.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/permission-model/yongdall/migration.mjs
|
|
4
|
+
/** @import { Profile } from '@yongdall/migrate' */
|
|
5
|
+
/** @type {Profile['models']} */
|
|
6
|
+
const models = [ModelPermissionGroup_default];
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getModelPermissions, models };
|
|
10
|
+
//# sourceMappingURL=migration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.mjs","names":["ModelPermissionGroup"],"sources":["../../../plugins/permission-model/yongdall/migration.mjs"],"sourcesContent":["/** @import { Profile } from '@yongdall/migrate' */\nimport { ModelPermissionGroup } from '../index.mjs';\n\nexport { getModelPermissions } from '../index.mjs';\n\n/** @type {Profile['models']} */\nexport const models = [\n\tModelPermissionGroup,\n]\n"],"mappings":";;;;;AAMA,MAAa,SAAS,CACrBA,6BACA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as ModelPermissionGroup_default, t as getModelPermissions } from "../permission-model-Bx3r4kMo.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/permission-model/yongdall/model.mjs
|
|
4
|
+
/** @import { ModelProfile } from '@yongdall/core' */
|
|
5
|
+
/** @type {ModelProfile['models']} */
|
|
6
|
+
const models = { modelPermissionGroup: ModelPermissionGroup_default };
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getModelPermissions, models };
|
|
10
|
+
//# sourceMappingURL=model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.mjs","names":["ModelPermissionGroup"],"sources":["../../../plugins/permission-model/yongdall/model.mjs"],"sourcesContent":["/** @import { ModelProfile } from '@yongdall/core' */\nimport { ModelPermissionGroup } from '../index.mjs';\n\nexport { getModelPermissions } from '../index.mjs';\n\n/** @type {ModelProfile['models']} */\nexport const models = {\n\tmodelPermissionGroup: ModelPermissionGroup,\n};\n"],"mappings":";;;;;AAMA,MAAa,SAAS,EACrB,sBAAsBA,8BACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
label: 模块自定义权限支持
|