@tachybase/module-ui-schema 0.23.8
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/.turbo/turbo-build.log +6 -0
- package/LICENSE +201 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +1 -0
- package/dist/externalVersion.js +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +30 -0
- package/dist/server/actions/ui-schema-action.d.ts +17 -0
- package/dist/server/actions/ui-schema-action.js +133 -0
- package/dist/server/collections/uiSchemaServerHooks.d.ts +3 -0
- package/dist/server/collections/uiSchemaServerHooks.js +49 -0
- package/dist/server/collections/uiSchemaTemplates.d.ts +2 -0
- package/dist/server/collections/uiSchemaTemplates.js +66 -0
- package/dist/server/collections/uiSchemaTreePath.d.ts +3 -0
- package/dist/server/collections/uiSchemaTreePath.js +64 -0
- package/dist/server/collections/uiSchemas.d.ts +3 -0
- package/dist/server/collections/uiSchemas.js +53 -0
- package/dist/server/dao/ui_schema_dao.d.ts +4 -0
- package/dist/server/dao/ui_schema_dao.js +31 -0
- package/dist/server/dao/ui_schema_node_dao.d.ts +22 -0
- package/dist/server/dao/ui_schema_node_dao.js +32 -0
- package/dist/server/helper.d.ts +0 -0
- package/dist/server/helper.js +0 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +32 -0
- package/dist/server/migrations/20230330214649-filter-form-block.d.ts +5 -0
- package/dist/server/migrations/20230330214649-filter-form-block.js +48 -0
- package/dist/server/migrations/20230509221649-association-select.d.ts +5 -0
- package/dist/server/migrations/20230509221649-association-select.js +61 -0
- package/dist/server/migrations/20230509235247-record-picker.d.ts +8 -0
- package/dist/server/migrations/20230509235247-record-picker.js +111 -0
- package/dist/server/migrations/20230522231231-association-field.d.ts +5 -0
- package/dist/server/migrations/20230522231231-association-field.js +64 -0
- package/dist/server/migrations/20231015125000-support-filter-blocks-in-select-record-drawer.d.ts +5 -0
- package/dist/server/migrations/20231015125000-support-filter-blocks-in-select-record-drawer.js +45 -0
- package/dist/server/migrations/2024082000001-update-uiSchemas_customDesigner.d.ts +6 -0
- package/dist/server/migrations/2024082000001-update-uiSchemas_customDesigner.js +37 -0
- package/dist/server/migrations/20241120132559-modify-schema.d.ts +6 -0
- package/dist/server/migrations/20241120132559-modify-schema.js +119 -0
- package/dist/server/model.d.ts +6 -0
- package/dist/server/model.js +33 -0
- package/dist/server/repository.d.ts +85 -0
- package/dist/server/repository.js +969 -0
- package/dist/server/server-hooks/hooks/bind-menu-to-role.d.ts +5 -0
- package/dist/server/server-hooks/hooks/bind-menu-to-role.js +40 -0
- package/dist/server/server-hooks/hooks/factory.d.ts +6 -0
- package/dist/server/server-hooks/hooks/factory.js +33 -0
- package/dist/server/server-hooks/hooks/index.d.ts +6 -0
- package/dist/server/server-hooks/hooks/index.js +36 -0
- package/dist/server/server-hooks/hooks/remove-parents-if-no-children.d.ts +6 -0
- package/dist/server/server-hooks/hooks/remove-parents-if-no-children.js +35 -0
- package/dist/server/server-hooks/hooks/remove-schema.d.ts +6 -0
- package/dist/server/server-hooks/hooks/remove-schema.js +42 -0
- package/dist/server/server-hooks/index.d.ts +25 -0
- package/dist/server/server-hooks/index.js +165 -0
- package/dist/server/server-hooks/model.d.ts +3 -0
- package/dist/server/server-hooks/model.js +29 -0
- package/dist/server/server.d.ts +8 -0
- package/dist/server/server.js +136 -0
- package/dist/swagger/index.d.ts +326 -0
- package/dist/swagger/index.js +354 -0
- package/package.json +32 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var bind_menu_to_role_exports = {};
|
|
19
|
+
__export(bind_menu_to_role_exports, {
|
|
20
|
+
bindMenuToRole: () => bindMenuToRole
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(bind_menu_to_role_exports);
|
|
23
|
+
async function bindMenuToRole({ schemaInstance, db, options }) {
|
|
24
|
+
const { transaction } = options;
|
|
25
|
+
const addNewMenuRoles = await db.getRepository("roles").find({
|
|
26
|
+
filter: {
|
|
27
|
+
allowNewMenu: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
for (const role of addNewMenuRoles) {
|
|
31
|
+
await db.getRepository("roles.menuUiSchemas", role.get("name")).add({
|
|
32
|
+
tk: schemaInstance.get("x-uid"),
|
|
33
|
+
transaction
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
bindMenuToRole
|
|
40
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var factory_exports = {};
|
|
19
|
+
__export(factory_exports, {
|
|
20
|
+
hookFactory: () => hookFactory
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(factory_exports);
|
|
23
|
+
function hookFactory(hookType, hookName, hookFunc) {
|
|
24
|
+
return {
|
|
25
|
+
hookType,
|
|
26
|
+
hookName,
|
|
27
|
+
hookFunc
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
hookFactory
|
|
33
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var hooks_exports = {};
|
|
19
|
+
__export(hooks_exports, {
|
|
20
|
+
hooks: () => hooks
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
23
|
+
var import_bind_menu_to_role = require("./bind-menu-to-role");
|
|
24
|
+
var import_factory = require("./factory");
|
|
25
|
+
var import_remove_parents_if_no_children = require("./remove-parents-if-no-children");
|
|
26
|
+
var import_remove_schema = require("./remove-schema");
|
|
27
|
+
const hooks = [
|
|
28
|
+
(0, import_factory.hookFactory)("onCollectionDestroy", "removeSchema", import_remove_schema.removeSchema),
|
|
29
|
+
(0, import_factory.hookFactory)("onCollectionFieldDestroy", "removeSchema", import_remove_schema.removeSchema),
|
|
30
|
+
(0, import_factory.hookFactory)("onSelfCreate", "bindMenuToRole", import_bind_menu_to_role.bindMenuToRole),
|
|
31
|
+
(0, import_factory.hookFactory)("onSelfMove", "removeParentsIfNoChildren", import_remove_parents_if_no_children.removeParentsIfNoChildren)
|
|
32
|
+
];
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
hooks
|
|
36
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var remove_parents_if_no_children_exports = {};
|
|
19
|
+
__export(remove_parents_if_no_children_exports, {
|
|
20
|
+
removeParentsIfNoChildren: () => removeParentsIfNoChildren
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(remove_parents_if_no_children_exports);
|
|
23
|
+
async function removeParentsIfNoChildren({ schemaInstance, db, options, params }) {
|
|
24
|
+
const { transaction, oldParentUid } = options;
|
|
25
|
+
const uiSchemaRepository = db.getRepository("uiSchemas");
|
|
26
|
+
await uiSchemaRepository.recursivelyRemoveIfNoChildren({
|
|
27
|
+
transaction,
|
|
28
|
+
uid: oldParentUid,
|
|
29
|
+
breakRemoveOn: params == null ? void 0 : params.breakRemoveOn
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
removeParentsIfNoChildren
|
|
35
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var remove_schema_exports = {};
|
|
19
|
+
__export(remove_schema_exports, {
|
|
20
|
+
removeSchema: () => removeSchema
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(remove_schema_exports);
|
|
23
|
+
async function removeSchema({ schemaInstance, options, db, params }) {
|
|
24
|
+
const { transaction } = options;
|
|
25
|
+
const uiSchemaRepository = db.getRepository("uiSchemas");
|
|
26
|
+
const uid = schemaInstance.get("x-uid");
|
|
27
|
+
if (params == null ? void 0 : params.removeParentsIfNoChildren) {
|
|
28
|
+
await uiSchemaRepository.removeEmptyParents({
|
|
29
|
+
uid,
|
|
30
|
+
breakRemoveOn: params["breakRemoveOn"],
|
|
31
|
+
transaction
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
await uiSchemaRepository.remove(uid, {
|
|
35
|
+
transaction
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
removeSchema
|
|
42
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Database } from '@tachybase/database';
|
|
2
|
+
export type HookType = 'onSelfDestroy' | 'onCollectionDestroy' | 'onCollectionFieldDestroy' | 'onAnyCollectionFieldDestroy' | 'onSelfCreate' | 'onSelfSave' | 'onSelfMove';
|
|
3
|
+
export declare class ServerHooks {
|
|
4
|
+
protected db: Database;
|
|
5
|
+
hooks: Map<HookType, Map<string, any>>;
|
|
6
|
+
constructor(db: Database);
|
|
7
|
+
registerHooks(): void;
|
|
8
|
+
listen(): void;
|
|
9
|
+
protected callSchemaInstanceHooksByType(schemaInstance: any, options: any, type: HookType): Promise<void>;
|
|
10
|
+
protected onUiSchemaMove(schemaInstance: any, options: any): Promise<void>;
|
|
11
|
+
protected onCollectionDestroy(collectionModel: any, options: any): Promise<void>;
|
|
12
|
+
protected onAnyCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
|
|
13
|
+
protected onCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
|
|
14
|
+
protected onUiSchemaCreate(schemaInstance: any, options: any): Promise<void>;
|
|
15
|
+
protected onUiSchemaSave(schemaInstance: any, options: any): Promise<void>;
|
|
16
|
+
protected findHooksAndCall(hooksFilter: any, hooksArgs: any, transaction: any): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* register a server hook function
|
|
19
|
+
* @param type type of server hook
|
|
20
|
+
* @param name name of server hook
|
|
21
|
+
* @param hookFunc server hook function
|
|
22
|
+
*/
|
|
23
|
+
register(type: HookType, name: string, hookFunc: any): void;
|
|
24
|
+
remove(type: HookType, name: string): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var server_hooks_exports = {};
|
|
19
|
+
__export(server_hooks_exports, {
|
|
20
|
+
ServerHooks: () => ServerHooks
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(server_hooks_exports);
|
|
23
|
+
var import_hooks = require("./hooks");
|
|
24
|
+
class ServerHooks {
|
|
25
|
+
constructor(db) {
|
|
26
|
+
this.db = db;
|
|
27
|
+
this.listen();
|
|
28
|
+
this.registerHooks();
|
|
29
|
+
}
|
|
30
|
+
hooks = /* @__PURE__ */ new Map();
|
|
31
|
+
registerHooks() {
|
|
32
|
+
import_hooks.hooks.forEach((hook) => this.register(hook.hookType, hook.hookName, hook.hookFunc));
|
|
33
|
+
}
|
|
34
|
+
listen() {
|
|
35
|
+
this.db.on("fields.afterDestroy", async (model, options) => {
|
|
36
|
+
await this.onCollectionFieldDestroy(model, options);
|
|
37
|
+
await this.onAnyCollectionFieldDestroy(model, options);
|
|
38
|
+
});
|
|
39
|
+
this.db.on("collections.afterDestroy", async (model, options) => {
|
|
40
|
+
await this.onCollectionDestroy(model, options);
|
|
41
|
+
});
|
|
42
|
+
this.db.on("uiSchemas.afterCreateWithAssociations", async (model, options) => {
|
|
43
|
+
await this.onUiSchemaCreate(model, options);
|
|
44
|
+
});
|
|
45
|
+
this.db.on("uiSchemaMove", async (model, options) => {
|
|
46
|
+
await this.onUiSchemaMove(model, options);
|
|
47
|
+
});
|
|
48
|
+
this.db.on("uiSchemas.afterSave", async (model, options) => {
|
|
49
|
+
await this.onUiSchemaSave(model, options);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async callSchemaInstanceHooksByType(schemaInstance, options, type) {
|
|
53
|
+
var _a;
|
|
54
|
+
const { transaction } = options;
|
|
55
|
+
const hooks2 = schemaInstance.getServerHooksByType(type);
|
|
56
|
+
for (const hook of hooks2) {
|
|
57
|
+
const hookFunc = (_a = this.hooks.get(type)) == null ? void 0 : _a.get(hook["method"]);
|
|
58
|
+
await (hookFunc == null ? void 0 : hookFunc({
|
|
59
|
+
schemaInstance,
|
|
60
|
+
options,
|
|
61
|
+
db: this.db,
|
|
62
|
+
params: hook["params"]
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async onUiSchemaMove(schemaInstance, options) {
|
|
67
|
+
await this.callSchemaInstanceHooksByType(schemaInstance, options, "onSelfMove");
|
|
68
|
+
}
|
|
69
|
+
async onCollectionDestroy(collectionModel, options) {
|
|
70
|
+
const { transaction } = options;
|
|
71
|
+
await this.findHooksAndCall(
|
|
72
|
+
{
|
|
73
|
+
type: "onCollectionDestroy",
|
|
74
|
+
collection: collectionModel.get("name")
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
collectionInstance: collectionModel,
|
|
78
|
+
options
|
|
79
|
+
},
|
|
80
|
+
transaction
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
async onAnyCollectionFieldDestroy(fieldModel, options) {
|
|
84
|
+
const { transaction } = options;
|
|
85
|
+
const collectionName = fieldModel.get("collectionName");
|
|
86
|
+
await this.findHooksAndCall(
|
|
87
|
+
{
|
|
88
|
+
type: "onAnyCollectionFieldDestroy",
|
|
89
|
+
collection: collectionName
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
collectionFieldInstance: fieldModel,
|
|
93
|
+
options
|
|
94
|
+
},
|
|
95
|
+
transaction
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
async onCollectionFieldDestroy(fieldModel, options) {
|
|
99
|
+
const { transaction } = options;
|
|
100
|
+
const collectionName = fieldModel.get("collectionName");
|
|
101
|
+
const fieldName = fieldModel.get("name");
|
|
102
|
+
await this.findHooksAndCall(
|
|
103
|
+
{
|
|
104
|
+
type: "onCollectionFieldDestroy",
|
|
105
|
+
collection: collectionName,
|
|
106
|
+
field: fieldName
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
collectionFieldInstance: fieldModel,
|
|
110
|
+
options
|
|
111
|
+
},
|
|
112
|
+
transaction
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
async onUiSchemaCreate(schemaInstance, options) {
|
|
116
|
+
await this.callSchemaInstanceHooksByType(schemaInstance, options, "onSelfCreate");
|
|
117
|
+
}
|
|
118
|
+
async onUiSchemaSave(schemaInstance, options) {
|
|
119
|
+
await this.callSchemaInstanceHooksByType(schemaInstance, options, "onSelfSave");
|
|
120
|
+
}
|
|
121
|
+
async findHooksAndCall(hooksFilter, hooksArgs, transaction) {
|
|
122
|
+
var _a;
|
|
123
|
+
const hooks2 = await this.db.getRepository("uiSchemaServerHooks").find({
|
|
124
|
+
filter: hooksFilter,
|
|
125
|
+
appends: ["uiSchema"],
|
|
126
|
+
transaction
|
|
127
|
+
});
|
|
128
|
+
for (const hookRecord of hooks2) {
|
|
129
|
+
const hoodMethodName = hookRecord.get("method");
|
|
130
|
+
const hookFunc = (_a = this.hooks.get(hookRecord.get("type"))) == null ? void 0 : _a.get(hoodMethodName);
|
|
131
|
+
if (hookFunc) {
|
|
132
|
+
await hookFunc({
|
|
133
|
+
...hooksArgs,
|
|
134
|
+
schemaInstance: hookRecord.uiSchema,
|
|
135
|
+
db: this.db,
|
|
136
|
+
params: hookRecord.get("params")
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* register a server hook function
|
|
143
|
+
* @param type type of server hook
|
|
144
|
+
* @param name name of server hook
|
|
145
|
+
* @param hookFunc server hook function
|
|
146
|
+
*/
|
|
147
|
+
register(type, name, hookFunc) {
|
|
148
|
+
if (!this.hooks.has(type)) {
|
|
149
|
+
this.hooks.set(type, /* @__PURE__ */ new Map());
|
|
150
|
+
}
|
|
151
|
+
const hookTypeMap = this.hooks.get(type);
|
|
152
|
+
hookTypeMap.set(name, hookFunc);
|
|
153
|
+
}
|
|
154
|
+
remove(type, name) {
|
|
155
|
+
if (!this.hooks.has(type)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const hookTypeMap = this.hooks.get(type);
|
|
159
|
+
hookTypeMap.delete(name);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
ServerHooks
|
|
165
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var model_exports = {};
|
|
19
|
+
__export(model_exports, {
|
|
20
|
+
ServerHookModel: () => ServerHookModel
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(model_exports);
|
|
23
|
+
var import_database = require("@tachybase/database");
|
|
24
|
+
class ServerHookModel extends import_database.Model {
|
|
25
|
+
}
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
ServerHookModel
|
|
29
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '@tachybase/server';
|
|
2
|
+
import { ServerHooks } from './server-hooks';
|
|
3
|
+
export declare class ModuleUiSchema extends Plugin {
|
|
4
|
+
serverHooks: ServerHooks;
|
|
5
|
+
registerRepository(): void;
|
|
6
|
+
beforeLoad(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default ModuleUiSchema;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
ModuleUiSchema: () => ModuleUiSchema,
|
|
31
|
+
default: () => server_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(server_exports);
|
|
34
|
+
var import_database = require("@tachybase/database");
|
|
35
|
+
var import_server = require("@tachybase/server");
|
|
36
|
+
var import_utils = require("@tachybase/utils");
|
|
37
|
+
var import_ui_schema_action = require("./actions/ui-schema-action");
|
|
38
|
+
var import_model = require("./model");
|
|
39
|
+
var import_repository = __toESM(require("./repository"));
|
|
40
|
+
var import_server_hooks = require("./server-hooks");
|
|
41
|
+
var import_model2 = require("./server-hooks/model");
|
|
42
|
+
class ModuleUiSchema extends import_server.Plugin {
|
|
43
|
+
serverHooks;
|
|
44
|
+
registerRepository() {
|
|
45
|
+
this.app.db.registerRepositories({
|
|
46
|
+
UiSchemaRepository: import_repository.default
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async beforeLoad() {
|
|
50
|
+
const db = this.app.db;
|
|
51
|
+
this.serverHooks = new import_server_hooks.ServerHooks(db);
|
|
52
|
+
this.app.db.registerModels({ MagicAttributeModel: import_database.MagicAttributeModel, UiSchemaModel: import_model.UiSchemaModel, ServerHookModel: import_model2.ServerHookModel });
|
|
53
|
+
this.registerRepository();
|
|
54
|
+
this.app.acl.registerSnippet({
|
|
55
|
+
name: `pm.${this.name}.block-templates`,
|
|
56
|
+
actions: ["uiSchemaTemplates:*"]
|
|
57
|
+
});
|
|
58
|
+
this.app.acl.registerSnippet({
|
|
59
|
+
name: "ui.uiSchemas",
|
|
60
|
+
actions: [
|
|
61
|
+
"uiSchemas:insert",
|
|
62
|
+
"uiSchemas:insertNewSchema",
|
|
63
|
+
"uiSchemas:remove",
|
|
64
|
+
"uiSchemas:patch",
|
|
65
|
+
"uiSchemas:batchPatch",
|
|
66
|
+
"uiSchemas:clearAncestor",
|
|
67
|
+
"uiSchemas:insertBeforeBegin",
|
|
68
|
+
"uiSchemas:insertAfterBegin",
|
|
69
|
+
"uiSchemas:insertBeforeEnd",
|
|
70
|
+
"uiSchemas:insertAfterEnd",
|
|
71
|
+
"uiSchemas:insertAdjacent",
|
|
72
|
+
"uiSchemas:saveAsTemplate"
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
db.on("uiSchemas.beforeCreate", function setUid(model) {
|
|
76
|
+
if (!model.get("name")) {
|
|
77
|
+
model.set("name", (0, import_utils.uid)());
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
db.on("uiSchemas.afterCreate", async function insertSchema(model, options) {
|
|
81
|
+
const { transaction } = options;
|
|
82
|
+
const uiSchemaRepository = db.getCollection("uiSchemas").repository;
|
|
83
|
+
const context = options.context;
|
|
84
|
+
if (context == null ? void 0 : context.disableInsertHook) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
await uiSchemaRepository.insert(model.toJSON(), {
|
|
88
|
+
transaction
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
db.on("uiSchemas.afterUpdate", async function patchSchema(model, options) {
|
|
92
|
+
const { transaction } = options;
|
|
93
|
+
const uiSchemaRepository = db.getCollection("uiSchemas").repository;
|
|
94
|
+
await uiSchemaRepository.patch(model.toJSON(), {
|
|
95
|
+
transaction
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
this.app.resourcer.use(
|
|
99
|
+
async (ctx, next) => {
|
|
100
|
+
var _a;
|
|
101
|
+
const { resourceName, actionName } = ctx.action.params;
|
|
102
|
+
if (resourceName === "uiSchemas" && actionName === "remove") {
|
|
103
|
+
const skip = await ctx.app.acl.allowManager.isAllowed(resourceName, actionName, ctx);
|
|
104
|
+
if (skip) {
|
|
105
|
+
return next();
|
|
106
|
+
}
|
|
107
|
+
const role = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentRole;
|
|
108
|
+
if (!role) {
|
|
109
|
+
ctx.throw(403, "No Permission: Role not found");
|
|
110
|
+
}
|
|
111
|
+
const aclRole = ctx.app.acl.roles.get(role);
|
|
112
|
+
if (!aclRole) {
|
|
113
|
+
ctx.throw(403, "No Permission: Role not found");
|
|
114
|
+
}
|
|
115
|
+
const snippetAllowed = aclRole.snippetAllowed(`${resourceName}:${actionName}`);
|
|
116
|
+
if (!snippetAllowed) {
|
|
117
|
+
ctx.throw(403, "No Permission: Role lacks remove permission for uiSchemas");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
await next();
|
|
121
|
+
},
|
|
122
|
+
{ tag: "intercept-ui-schema-remove", after: "acl" }
|
|
123
|
+
);
|
|
124
|
+
this.app.resourcer.define({
|
|
125
|
+
name: "uiSchemas",
|
|
126
|
+
actions: import_ui_schema_action.uiSchemaActions
|
|
127
|
+
});
|
|
128
|
+
this.app.acl.allow("uiSchemas", ["getProperties", "getJsonSchema"], "loggedIn");
|
|
129
|
+
this.app.acl.allow("uiSchemaTemplates", ["get", "list"], "public");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
var server_default = ModuleUiSchema;
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
ModuleUiSchema
|
|
136
|
+
});
|