@nocobase/plugin-collection-tree 1.7.0-beta.8 → 1.7.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/LICENSE.txt +4 -4
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +5 -5
- package/dist/server/commands/sync-path.d.ts +10 -0
- package/dist/server/commands/sync-path.js +116 -0
- package/dist/server/migrations/20240802141435-collection-tree.js +1 -13
- package/dist/server/plugin.js +8 -4
- package/package.json +2 -2
package/LICENSE.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Updated Date:
|
|
1
|
+
Updated Date: April 1, 2025
|
|
2
2
|
|
|
3
3
|
NocoBase License Agreement
|
|
4
4
|
|
|
@@ -88,7 +88,7 @@ Except for Third-Party Open Source Software, the Company owns all copyrights, tr
|
|
|
88
88
|
|
|
89
89
|
6.6 Can sell plugins developed for Software in the Marketplace.
|
|
90
90
|
|
|
91
|
-
6.7 The User with
|
|
91
|
+
6.7 The User with a Professional or Enterprise Edition License can sell Upper Layer Application to their clients.
|
|
92
92
|
|
|
93
93
|
6.8 Not restricted by the AGPL-3.0 agreement.
|
|
94
94
|
|
|
@@ -106,9 +106,9 @@ Except for Third-Party Open Source Software, the Company owns all copyrights, tr
|
|
|
106
106
|
|
|
107
107
|
7.4 It is not allowed to provide any form of no-code, zero-code, low-code platform SaaS products to the public using the original or modified Software.
|
|
108
108
|
|
|
109
|
-
7.5 It is not allowed for the User withot
|
|
109
|
+
7.5 It is not allowed for the User withot a Professional or Enterprise Edition license to sell Upper Layer Application to clients without a Commercial license.
|
|
110
110
|
|
|
111
|
-
7.6 It is not allowed for the User with
|
|
111
|
+
7.6 It is not allowed for the User with a Professional or Enterprise Edition license to sell Upper Layer Application to clients without a Commercial license with access to further development and configuration.
|
|
112
112
|
|
|
113
113
|
7.7 It is not allowed to publicly sell plugins developed for Software outside of the Marketplace.
|
|
114
114
|
|
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-tree",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-tree"]=t(require("@nocobase/client")):e["@nocobase/plugin-collection-tree"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={772:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.r(o),r.d(o,{PluginCollectionTreeClient:function(){return
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client")):"function"==typeof define&&define.amd?define("@nocobase/plugin-collection-tree",["@nocobase/client"],t):"object"==typeof exports?exports["@nocobase/plugin-collection-tree"]=t(require("@nocobase/client")):e["@nocobase/plugin-collection-tree"]=t(e["@nocobase/client"])}(self,function(e){return function(){"use strict";var t={772:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var u=n[e]={exports:{}};return t[e](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return!function(){r.r(o),r.d(o,{PluginCollectionTreeClient:function(){return p}});var e=r(772);function t(e,t,n,r,o,u,i){try{var c=e[u](i),l=c.value}catch(e){n(e);return}c.done?t(l):Promise.resolve(l).then(r,o)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(o,u){var i=e.apply(n,r);function c(e){t(i,o,u,c,l,"next",e)}function l(e){t(i,o,u,c,l,"throw",e)}c(void 0)})}}function u(e,t,n){return(u=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}function f(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(u){return function(c){var l=[u,c];if(n)throw TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}var p=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&c(r,e),t=[{key:"afterAdd",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"beforeLoad",value:function(){return n(function(){return f(this,function(e){return[2]})})()}},{key:"load",value:function(){return n(function(){return f(this,function(e){return[2]})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(l(e.Plugin));o.default=p}(),o}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.7.0
|
|
12
|
-
"@nocobase/database": "1.7.0
|
|
13
|
-
"@nocobase/utils": "1.7.0
|
|
11
|
+
"@nocobase/client": "1.7.0",
|
|
12
|
+
"@nocobase/database": "1.7.0",
|
|
13
|
+
"@nocobase/utils": "1.7.0",
|
|
14
14
|
"lodash": "4.17.21",
|
|
15
|
-
"@nocobase/data-source-manager": "1.7.0
|
|
16
|
-
"@nocobase/server": "1.7.0
|
|
15
|
+
"@nocobase/data-source-manager": "1.7.0",
|
|
16
|
+
"@nocobase/server": "1.7.0",
|
|
17
17
|
"sequelize": "6.35.2"
|
|
18
18
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Application } from '@nocobase/server';
|
|
10
|
+
export default function (app: Application): void;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var sync_path_exports = {};
|
|
38
|
+
__export(sync_path_exports, {
|
|
39
|
+
default: () => sync_path_default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(sync_path_exports);
|
|
42
|
+
var import_lodash = __toESM(require("lodash"));
|
|
43
|
+
async function getTreePath(db, model, path, collection, pathCollectionName, transaction) {
|
|
44
|
+
if (model.get("parentId") !== null) {
|
|
45
|
+
const parent = await db.getRepository(collection).findOne({
|
|
46
|
+
filter: { id: model.get("parentId") },
|
|
47
|
+
transaction
|
|
48
|
+
});
|
|
49
|
+
if (parent && parent.get("parentId") !== model.get("id")) {
|
|
50
|
+
path = `/${parent.get("id")}${path}`;
|
|
51
|
+
const collectionTreePath = db.getCollection(pathCollectionName);
|
|
52
|
+
const nodePkColumnName = collectionTreePath.getField("nodePk").columnName();
|
|
53
|
+
const parentPathData = await db.getRepository(pathCollectionName).findOne({
|
|
54
|
+
filter: { [nodePkColumnName]: parent.get("id") },
|
|
55
|
+
transaction
|
|
56
|
+
});
|
|
57
|
+
const parentPath = import_lodash.default.get(parentPathData, "path", null);
|
|
58
|
+
if (parentPath == null) {
|
|
59
|
+
path = await getTreePath(db, parent, path, collection, pathCollectionName, transaction);
|
|
60
|
+
} else {
|
|
61
|
+
path = `${parentPath}/${model.get("id")}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return path;
|
|
66
|
+
}
|
|
67
|
+
function sync_path_default(app) {
|
|
68
|
+
app.command("tree-collection:sync-path").preload().option("-c, --collection [collection]").action(async (options) => {
|
|
69
|
+
const { collection: name } = options || {};
|
|
70
|
+
const mainData = app.pm.get("data-source-main");
|
|
71
|
+
mainData.setLoadFilter({
|
|
72
|
+
name
|
|
73
|
+
});
|
|
74
|
+
await app.emitAsync("beforeStart");
|
|
75
|
+
if (!name) {
|
|
76
|
+
throw new Error("Collection name is required");
|
|
77
|
+
}
|
|
78
|
+
const collection = app.db.getCollection(name);
|
|
79
|
+
if (!collection) {
|
|
80
|
+
throw new Error(`Collection ${name} not found`);
|
|
81
|
+
}
|
|
82
|
+
const isTree = collection.options.tree;
|
|
83
|
+
if (!isTree) {
|
|
84
|
+
throw new Error(`Collection ${name} is not a tree collection`);
|
|
85
|
+
}
|
|
86
|
+
const pathTableName = `main_${name}_path`;
|
|
87
|
+
const pathRepo = app.db.getRepository(pathTableName);
|
|
88
|
+
const nodeRepo = app.db.getRepository(name);
|
|
89
|
+
const chunkSize = 1e3;
|
|
90
|
+
await app.db.sequelize.transaction(async (transaction) => {
|
|
91
|
+
await pathRepo.destroy({ truncate: true, transaction });
|
|
92
|
+
console.log(`Truncated table ${pathTableName}`);
|
|
93
|
+
await nodeRepo.chunk({
|
|
94
|
+
chunkSize,
|
|
95
|
+
callback: async (records, options2) => {
|
|
96
|
+
const toInsert = [];
|
|
97
|
+
for (const record of records) {
|
|
98
|
+
const id = record.get("id");
|
|
99
|
+
let path = `/${id}`;
|
|
100
|
+
path = await getTreePath(app.db, record, path, name, pathTableName, transaction);
|
|
101
|
+
toInsert.push({
|
|
102
|
+
nodePk: id,
|
|
103
|
+
path,
|
|
104
|
+
rootPk: path.split("/")[1]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (toInsert.length > 0) {
|
|
108
|
+
await app.db.getModel(pathTableName).bulkCreate(toInsert, { transaction });
|
|
109
|
+
console.log(`Inserted ${toInsert.length} records into ${pathTableName}`);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
transaction
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -59,6 +59,7 @@ class collection_tree_default extends import_server.Migration {
|
|
|
59
59
|
await this.db.sequelize.transaction(async (transaction) => {
|
|
60
60
|
const treeCollections = await this.getTreeCollections({ transaction });
|
|
61
61
|
for (const treeCollection of treeCollections) {
|
|
62
|
+
await treeCollection.load({ transaction });
|
|
62
63
|
const name = `main_${treeCollection.name}_path`;
|
|
63
64
|
const collectionOptions = {
|
|
64
65
|
name,
|
|
@@ -84,19 +85,6 @@ class collection_tree_default extends import_server.Migration {
|
|
|
84
85
|
const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
|
|
85
86
|
if (!treeExistsInDb) {
|
|
86
87
|
await this.app.db.getCollection(name).sync({ transaction });
|
|
87
|
-
const opts = {
|
|
88
|
-
name: treeCollection.name,
|
|
89
|
-
autoGenId: false,
|
|
90
|
-
timestamps: false,
|
|
91
|
-
fields: [
|
|
92
|
-
{ type: "integer", name: "id" },
|
|
93
|
-
{ type: "integer", name: "parentId" }
|
|
94
|
-
]
|
|
95
|
-
};
|
|
96
|
-
if (treeCollectionSchema != this.app.db.options.schema) {
|
|
97
|
-
opts["schema"] = treeCollectionSchema;
|
|
98
|
-
}
|
|
99
|
-
this.app.db.collection(opts);
|
|
100
88
|
const chunkSize = 1e3;
|
|
101
89
|
await this.app.db.getRepository(treeCollection.name).chunk({
|
|
102
90
|
chunkSize,
|
package/dist/server/plugin.js
CHANGED
|
@@ -119,7 +119,7 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
119
119
|
});
|
|
120
120
|
this.db.on(`${collection.name}.beforeSave`, async (model) => {
|
|
121
121
|
const tk = collection.filterTargetKey;
|
|
122
|
-
if (model.get(parentForeignKey) === model.get(tk)) {
|
|
122
|
+
if (model.get(tk) && model.get(parentForeignKey) === model.get(tk)) {
|
|
123
123
|
throw new Error("Cannot set itself as the parent node");
|
|
124
124
|
}
|
|
125
125
|
});
|
|
@@ -200,11 +200,15 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
200
200
|
},
|
|
201
201
|
transaction
|
|
202
202
|
});
|
|
203
|
+
const basePath = pathData.get("path");
|
|
203
204
|
const relatedNodes = await this.app.db.getRepository(pathCollectionName).find({
|
|
204
205
|
filter: {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
$or: [
|
|
207
|
+
{ path: basePath },
|
|
208
|
+
// 自身节点
|
|
209
|
+
{ path: { $startsWith: `${basePath}/` } }
|
|
210
|
+
// 确保是子节点(路径段)
|
|
211
|
+
]
|
|
208
212
|
},
|
|
209
213
|
transaction
|
|
210
214
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-collection-tree",
|
|
3
|
-
"version": "1.7.0
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"displayName": "Collection: Tree",
|
|
5
5
|
"displayName.zh-CN": "数据表:树",
|
|
6
6
|
"description": "Provides tree collection template",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"@nocobase/server": "1.x",
|
|
15
15
|
"@nocobase/test": "1.x"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "767ae089e404a104d718962272289c0bec01803a"
|
|
18
18
|
}
|