@nocobase/plugin-collection-tree 1.3.0-beta

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 ADDED
@@ -0,0 +1,121 @@
1
+ Updated Date: August 15, 2024
2
+
3
+ NocoBase License Agreement
4
+
5
+ NOCOBASE PTE. LTD.,a Singaporean Exempt Private Company Limited by Shares with its principal place of business located at #03-01 ROBINSON 112 ("The Company") https://www.nocobase.com/ issues this License Agreement ("Agreement") to you. You, as an individual or a company ("User"), will be deemed to voluntarily accept all terms of this Agreement by using NocoBase (including but not limited to obtaining NocoBase source code or installation package in any form, installing and using NocoBase, purchasing NocoBase commercial license and services, purchasing NocoBase commercial plugins). If the User does not agree to any term of this Agreement, or cannot accurately understand our interpretation of the relevant terms, please stop using it immediately.
6
+
7
+ This Agreement applies to any use, quotation, contract, invoice, and all software delivered by the Company. The User and the Company or NocoBase's agents can no longer sign a separate license agreement for the sale and delivery of the software.
8
+
9
+ The Company reserves the right to formulate and modify this Agreement from time to time as needed. If there are changes, the Company will announce them in the form of website announcements, without further individual notification. The changed Agreement will automatically take effect once it is announced, becoming part of this Agreement.
10
+
11
+ ==============
12
+ 1. Definitions
13
+ ==============
14
+
15
+ 1.1 "Software" refers to the NocoBase kernel and plugins placed in the same code repository as the kernel, including their source code, installation packages, images, and all their modifications, updates, and upgrades.
16
+
17
+ 1.2 "Marketplace" refers to the marketplace provided by the Company for selling Software plugins and solutions.
18
+
19
+ 1.3 "Commercial Plugin" refers to the paid plugins sold in the Marketplace.
20
+
21
+ 1.4 "Upper Layer Application" refers to a specific business use case application serving internal or external customers of the User, developed based on Software and Commercial Plugins, such as ERP/CRM.
22
+
23
+ 1.5 "Customer" refers to the clients who purchase the User's Upper Layer Application.
24
+
25
+ 1.6 "Third-Party Open Source Software" refers to open source software provided with Software and Commercial Plugins. They are licensed through various published open source software licenses or copyright notices accompanying such software.
26
+
27
+ ===================================
28
+ 2. Intellectual Property Protection
29
+ ===================================
30
+
31
+ Except for Third-Party Open Source Software, the Company owns all copyrights, trademark rights, patent rights, trade secrets, and other intellectual property rights of the Software, and has registered and protected them in relevant countries and regions according to the "Paris Convention" or "TRIPS Agreement", ensuring that the intellectual property rights of the Software and Commercial Plugins are internationally recognized and protected.
32
+
33
+ =============
34
+ 3. Disclaimer
35
+ =============
36
+
37
+ 3.1 Users shall not use the Software and Commercial Plugins to engage in activities that violate local laws and regulations, religious beliefs. All legal responsibilities and legal consequences arising from the use of Software and Commercial Plugins shall be borne by the User.
38
+
39
+ 3.2 The Company shall not be liable for any direct, indirect, special, incidental, or consequential damages (including but not limited to loss of profits, business interruption, data loss, or business information disclosure) caused by the User's use of the Software and Commercial Plugins, even if it has been previously informed of the possibility of such damages.
40
+
41
+ ===============
42
+ 4. License Type
43
+ ===============
44
+
45
+ 4.1 The Software uses a dual license type of AGPL-3.0 Open Source License https://www.gnu.org/licenses/agpl-3..en.htm and Commercial License.
46
+
47
+ 4.2 Commercial Plugins use Commercial License.
48
+
49
+ ================================================
50
+ 5. Rights and Obligations of Open Source License
51
+ ================================================
52
+
53
+ 5.1 The Software can be used for commercial purposes.
54
+
55
+ 5.2 User can sell plugins developed for the Software in the Marketplace.
56
+
57
+ 5.3 Outside the Marketplace, changes and plugins to the Software developed by User or third parties, and third-party applications developed based on the Software must all be open-sourced under the AGPL-3.0 license.
58
+
59
+ 5.4 It is not allowed to remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface, except for the main LOGO in the upper left corner of the page.
60
+
61
+ 5.5 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
62
+
63
+ 5.6 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.
64
+
65
+ 5.7 Comply with all requirements of the AGPL-3.0 agreement.
66
+
67
+ ===============================
68
+ 6. Rights of Commercial License
69
+ ===============================
70
+
71
+ 6.1 Obtain a permanent commercial license of the Software or Commercial Plugin.
72
+
73
+ 6.2 Get 12 months of upgrade and exclusive technical support.
74
+
75
+ 6.3 The licensed Software and Commercial Plugins can be used for commercial purposes with no restrictions on the number of applications and users.
76
+
77
+ 6.4 Changes and plugins to the Software, and applications integrated with the Software do not need to be open sourced.
78
+
79
+ 6.5 Can remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface.
80
+
81
+ 6.6 Can sell plugins developed for Software in the Marketplace.
82
+
83
+ 6.7 Users with a Professional or Enterprise Edition license can sell Upper Layer Application to their clients.
84
+
85
+ 6.8 Not restricted by the AGPL-3.0 agreement.
86
+
87
+ 6.9 If there are other agreements in the contract for the above rights, the contract agreement shall prevail.
88
+
89
+ ====================================
90
+ 7. Obligations of Commercial License
91
+ ====================================
92
+
93
+ 7.1 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
94
+
95
+ 7.2 It is not allowed to sell, transfer, lease, share, or give away the Commercial License.
96
+
97
+ 7.3 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.
98
+
99
+ 7.4 It is not allowed for Users with a standard license to sell Upper Layer Application to clients without a commercial license.
100
+
101
+ 7.5 It is not allowed to use reverse engineering, decompilation, and other means to try to discover the source code of Commercial Plugins that have not obtained source code license.
102
+
103
+ 7.6 It is not allowed to disclose the source code of Commercial Plugins to any third party.
104
+
105
+ 7.7 It is not allowed to publicly sell plugins developed for Software outside of the Marketplace.
106
+
107
+ 7.8 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
108
+
109
+ 7.9 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
110
+
111
+ =============================================================
112
+ 8. Legal Jurisdiction, Interpretation, and Dispute Resolution
113
+ =============================================================
114
+
115
+ 8.1 Except for Mainland China, the interpretation, application, and all matters related to this agreement are subject to the jurisdiction of Singapore law.
116
+
117
+ 8.2 Any dispute related to this Agreement should first be resolved through friendly negotiation. If the negotiation fails to resolve the dispute, the dispute should be submitted to the International Chamber of Commerce (ICC) for arbitration. The arbitration venue should be Singapore, conducted in English.
118
+
119
+ 8.3 All terms and conditions of this Agreement shall be deemed enforceable to the maximum extent permitted by applicable law. If any term of this Agreement is deemed invalid by any applicable law, the invalidity of that term does not affect the validity of any other term of this Agreement, and it should be deemed that the invalid term has been modified as much as possible to make it valid and enforceable, or if the term cannot be modified, it should be deemed to have been deleted from this Agreement.
120
+
121
+ 8.4 The arbitration award is final, binding on both parties, and can be enforced in any court with jurisdiction.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @nocobase/plugin-collection-tree
package/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/client';
2
+ export { default } from './dist/client';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/client/index.js');
@@ -0,0 +1,15 @@
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 { Plugin } from '@nocobase/client';
10
+ export declare class PluginCollectionTreeClient extends Plugin {
11
+ afterAdd(): Promise<void>;
12
+ beforeLoad(): Promise<void>;
13
+ load(): Promise<void>;
14
+ }
15
+ export default PluginCollectionTreeClient;
@@ -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
+
10
+ (function(e,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("@nocobase/client")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client"],n):(e=typeof globalThis!="undefined"?globalThis:e||self,n(e["@nocobase/plugin-collection-tree"]={},e["@nocobase/client"]))})(this,function(e,n){"use strict";var t=(e,n,o)=>new Promise((c,d)=>{var u=i=>{try{l(o.next(i))}catch(s){d(s)}},f=i=>{try{l(o.throw(i))}catch(s){d(s)}},l=i=>i.done?c(i.value):Promise.resolve(i.value).then(u,f);l((o=o.apply(e,n)).next())});class o extends n.Plugin{afterAdd(){return t(this,null,function*(){})}beforeLoad(){return t(this,null,function*(){})}load(){return t(this,null,function*(){console.log(this.app)})}}e.PluginCollectionTreeClient=o,e.default=o,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,18 @@
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
+ module.exports = {
11
+ "@nocobase/client": "1.3.0-beta",
12
+ "lodash": "4.17.21",
13
+ "@nocobase/database": "1.3.0-beta",
14
+ "@nocobase/utils": "1.3.0-beta",
15
+ "@nocobase/server": "1.3.0-beta",
16
+ "@nocobase/data-source-manager": "1.3.0-beta",
17
+ "sequelize": "6.35.2"
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
+ export * from './server';
10
+ export { default } from './server';
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var src_exports = {};
39
+ __export(src_exports, {
40
+ default: () => import_server.default
41
+ });
42
+ module.exports = __toCommonJS(src_exports);
43
+ __reExport(src_exports, require("./server"), module.exports);
44
+ var import_server = __toESM(require("./server"));
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ ...require("./server")
48
+ });
@@ -0,0 +1,47 @@
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 { CountOptions, FindOptions, Repository, FindAndCountOptions, Model } from '@nocobase/database';
10
+ import { TreeCollection } from './tree-collection';
11
+ export declare class AdjacencyListRepository extends Repository {
12
+ collection: TreeCollection;
13
+ update(options: any): Promise<any>;
14
+ buildRootNodeDataMap(nodeData: Model[]): {
15
+ [key: string]: Set<string>;
16
+ };
17
+ buildTree(paths: Model[], options?: FindOptions & {
18
+ addIndex?: boolean;
19
+ }, rootNodes?: Model[]): Promise<Model<any, any>[]>;
20
+ findWithoutFilter(options?: FindOptions & {
21
+ addIndex?: boolean;
22
+ }): Promise<any>;
23
+ countWithoutFilter(options: CountOptions & {
24
+ raw?: boolean;
25
+ tree?: boolean;
26
+ }): Promise<number>;
27
+ filterAndGetPaths(options?: FindOptions & {
28
+ addIndex?: boolean;
29
+ }): Promise<{
30
+ filterNodes: Model[];
31
+ paths: Model[];
32
+ }>;
33
+ find(options?: FindOptions & {
34
+ addIndex?: boolean;
35
+ }): Promise<any>;
36
+ countByPaths(paths: Model[]): number;
37
+ count(countOptions?: CountOptions & {
38
+ raw?: boolean;
39
+ tree?: boolean;
40
+ }): Promise<number>;
41
+ findAndCount(options?: FindAndCountOptions & {
42
+ filterByTk?: number | string;
43
+ }): Promise<[Model[], number]>;
44
+ private addIndex;
45
+ private queryPathByNode;
46
+ private queryPathByRoot;
47
+ }
@@ -0,0 +1,310 @@
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 adjacency_list_repository_exports = {};
38
+ __export(adjacency_list_repository_exports, {
39
+ AdjacencyListRepository: () => AdjacencyListRepository
40
+ });
41
+ module.exports = __toCommonJS(adjacency_list_repository_exports);
42
+ var import_lodash = __toESM(require("lodash"));
43
+ var import_database = require("@nocobase/database");
44
+ var import_utils = require("@nocobase/utils");
45
+ class AdjacencyListRepository extends import_database.Repository {
46
+ async update(options) {
47
+ return super.update({
48
+ ...options || {},
49
+ addIndex: false
50
+ });
51
+ }
52
+ buildRootNodeDataMap(nodeData) {
53
+ const rootPathDataMap = {};
54
+ for (const node of nodeData) {
55
+ const rootPk = node.get("rootPk");
56
+ const pathSet = new Set(
57
+ node.get("path").split("/").filter((item) => item !== "")
58
+ );
59
+ if (rootPathDataMap[rootPk]) {
60
+ const set = rootPathDataMap[rootPk];
61
+ for (const path of pathSet) {
62
+ set.add(path);
63
+ }
64
+ rootPathDataMap[rootPk] = set;
65
+ } else {
66
+ rootPathDataMap[rootPk] = pathSet;
67
+ }
68
+ }
69
+ return rootPathDataMap;
70
+ }
71
+ async buildTree(paths, options = {}, rootNodes) {
72
+ var _a;
73
+ const collection = this.collection;
74
+ const primaryKey = collection.model.primaryKeyAttribute;
75
+ const foreignKey = collection.treeForeignKey;
76
+ const childrenKey = ((_a = collection.treeChildrenField) == null ? void 0 : _a.name) ?? "children";
77
+ const treePathMap = this.buildRootNodeDataMap(paths);
78
+ if (!rootNodes) {
79
+ const rootIds = Object.keys(treePathMap);
80
+ if (!rootIds.length) {
81
+ this.database.logger.warn("adjacency-list-repository: rootIds is empty");
82
+ return [];
83
+ }
84
+ rootNodes = await super.find({
85
+ filter: {
86
+ [primaryKey]: {
87
+ $in: rootIds
88
+ }
89
+ },
90
+ ...import_lodash.default.omit(options, ["filter", "filterByTk"]),
91
+ transaction: options.transaction
92
+ });
93
+ }
94
+ const childIds = [];
95
+ for (const nodeIdSet of Object.values(treePathMap)) {
96
+ for (const nodeId of nodeIdSet) {
97
+ childIds.push(nodeId);
98
+ }
99
+ }
100
+ const findChildrenOptions = {
101
+ ...import_lodash.default.omit(options, ["limit", "offset", "filterByTk"]),
102
+ filter: {
103
+ [primaryKey]: childIds
104
+ }
105
+ };
106
+ if (findChildrenOptions.fields) {
107
+ [primaryKey, foreignKey].forEach((field) => {
108
+ if (!findChildrenOptions.fields.includes(field)) {
109
+ findChildrenOptions.fields.push(field);
110
+ }
111
+ });
112
+ }
113
+ const childInstances = await super.find(findChildrenOptions);
114
+ const nodeMap = {};
115
+ childInstances.forEach((node) => {
116
+ if (!nodeMap[`${node[foreignKey]}`]) {
117
+ nodeMap[`${node[foreignKey]}`] = [];
118
+ }
119
+ nodeMap[`${node[foreignKey]}`].push(node);
120
+ });
121
+ function buildTree(rootId) {
122
+ const children = nodeMap[rootId];
123
+ if (!children) {
124
+ return [];
125
+ }
126
+ return children.map((child) => {
127
+ const childrenValues = buildTree(child.id);
128
+ if (childrenValues.length > 0) {
129
+ child.setDataValue(childrenKey, childrenValues);
130
+ }
131
+ return child;
132
+ });
133
+ }
134
+ for (const root of rootNodes) {
135
+ const rootId = root[primaryKey];
136
+ const children = buildTree(rootId);
137
+ if (children.length > 0) {
138
+ root.setDataValue(childrenKey, children);
139
+ }
140
+ }
141
+ this.addIndex(rootNodes, childrenKey, options);
142
+ return rootNodes;
143
+ }
144
+ async findWithoutFilter(options = {}) {
145
+ var _a, _b;
146
+ const foreignKey = this.collection.treeForeignKey;
147
+ const rootNodes = await super.find({ ...options, filter: { [foreignKey]: null } });
148
+ if (!rootNodes.length) {
149
+ return [];
150
+ }
151
+ const collection = this.collection;
152
+ const primaryKey = collection.model.primaryKeyAttribute;
153
+ const rootPks = rootNodes.map((node) => node[primaryKey]);
154
+ const paths = await this.queryPathByRoot({
155
+ rootPks,
156
+ dataSourceName: ((_b = (_a = options.context) == null ? void 0 : _a.dataSource) == null ? void 0 : _b.name) ?? "main",
157
+ transaction: options.transaction
158
+ });
159
+ return await this.buildTree(paths, options, rootNodes);
160
+ }
161
+ async countWithoutFilter(options) {
162
+ const foreignKey = this.collection.treeForeignKey;
163
+ return await super.count({ ...options, filter: { [foreignKey]: null } });
164
+ }
165
+ async filterAndGetPaths(options = {}) {
166
+ var _a, _b;
167
+ const primaryKey = this.collection.model.primaryKeyAttribute;
168
+ const filterNodes = await super.find({
169
+ fields: [primaryKey],
170
+ ...import_lodash.default.omit(options, ["limit", "offset", "fields"])
171
+ });
172
+ if (!filterNodes.length) {
173
+ return { filterNodes: [], paths: [] };
174
+ }
175
+ const filterPks = filterNodes.map((node) => node[primaryKey]);
176
+ if (!filterPks.length) {
177
+ this.database.logger.debug("adjacency-list-repository: filterIds is empty");
178
+ return { filterNodes, paths: [] };
179
+ }
180
+ const paths = await this.queryPathByNode({
181
+ nodePks: filterPks,
182
+ dataSourceName: ((_b = (_a = options.context) == null ? void 0 : _a.dataSource) == null ? void 0 : _b.name) ?? "main",
183
+ transaction: options.transaction
184
+ });
185
+ return { filterNodes, paths };
186
+ }
187
+ async find(options = {}) {
188
+ if (options.raw || !options.tree) {
189
+ return await super.find(options);
190
+ }
191
+ const primaryKey = this.collection.model.primaryKeyAttribute;
192
+ if (options.fields && !options.fields.includes(primaryKey)) {
193
+ options.fields.push(primaryKey);
194
+ }
195
+ if (!(0, import_utils.isValidFilter)(options.filter) && !options.filterByTk) {
196
+ return await this.findWithoutFilter(options);
197
+ }
198
+ const { filterNodes, paths } = await this.filterAndGetPaths(options);
199
+ if (!paths.length) {
200
+ return filterNodes;
201
+ }
202
+ return await this.buildTree(paths, options);
203
+ }
204
+ countByPaths(paths) {
205
+ const rootIds = /* @__PURE__ */ new Set();
206
+ for (const path of paths) {
207
+ rootIds.add(path.get("rootPk"));
208
+ }
209
+ return rootIds.size;
210
+ }
211
+ async count(countOptions) {
212
+ if (countOptions.raw || !countOptions.tree) {
213
+ return await super.count(countOptions);
214
+ }
215
+ if (!(0, import_utils.isValidFilter)(countOptions.filter) && !countOptions.filterByTk) {
216
+ return await this.countWithoutFilter(countOptions);
217
+ }
218
+ const { paths } = await this.filterAndGetPaths(countOptions);
219
+ return this.countByPaths(paths);
220
+ }
221
+ async findAndCount(options) {
222
+ options = {
223
+ ...options,
224
+ transaction: await this.getTransaction(options.transaction)
225
+ };
226
+ if (options.raw || !options.tree) {
227
+ return await super.findAndCount(options);
228
+ }
229
+ if (!(0, import_utils.isValidFilter)(options.filter) && !options.filterByTk) {
230
+ const count2 = await this.countWithoutFilter(options);
231
+ const results2 = count2 ? await this.findWithoutFilter(options) : [];
232
+ return [results2, count2];
233
+ }
234
+ const { filterNodes, paths } = await this.filterAndGetPaths(options);
235
+ if (!paths.length) {
236
+ return [filterNodes, 0];
237
+ }
238
+ const results = await this.buildTree(paths, options);
239
+ const count = this.countByPaths(paths);
240
+ return [results, count];
241
+ }
242
+ addIndex(treeArray, childrenKey, options) {
243
+ function traverse(node, index) {
244
+ if (node._options.includeNames && !node._options.includeNames.includes(childrenKey)) {
245
+ node._options.includeNames.push(childrenKey);
246
+ }
247
+ if (options.addIndex !== false) {
248
+ node.setDataValue("__index", `${index}`);
249
+ }
250
+ const children = node.getDataValue(childrenKey);
251
+ if (children && children.length === 0) {
252
+ node.setDataValue(childrenKey, void 0);
253
+ }
254
+ if (children && children.length > 0) {
255
+ children.forEach((child, i) => {
256
+ traverse(child, `${index}.${childrenKey}.${i}`);
257
+ });
258
+ }
259
+ }
260
+ treeArray.forEach((tree, i) => {
261
+ traverse(tree, i);
262
+ });
263
+ }
264
+ async queryPathByNode({
265
+ nodePks,
266
+ dataSourceName,
267
+ transaction
268
+ }) {
269
+ const collection = this.collection;
270
+ const pathTableName = `${dataSourceName}_${collection.name}_path`;
271
+ const repo = this.database.getRepository(pathTableName);
272
+ if (repo) {
273
+ return await repo.find({
274
+ filter: {
275
+ nodePk: {
276
+ $in: nodePks
277
+ }
278
+ },
279
+ transaction
280
+ });
281
+ }
282
+ this.database.logger.warn(`Collection tree path table: ${pathTableName} not found`);
283
+ return [];
284
+ }
285
+ async queryPathByRoot({
286
+ rootPks,
287
+ dataSourceName,
288
+ transaction
289
+ }) {
290
+ const collection = this.collection;
291
+ const pathTableName = `${dataSourceName}_${collection.name}_path`;
292
+ const repo = this.database.getRepository(pathTableName);
293
+ if (repo) {
294
+ return await repo.find({
295
+ filter: {
296
+ rootPk: {
297
+ $in: rootPks
298
+ }
299
+ },
300
+ transaction
301
+ });
302
+ }
303
+ this.database.logger.warn(`Collection tree path table: ${pathTableName} not found`);
304
+ return [];
305
+ }
306
+ }
307
+ // Annotate the CommonJS export names for ESM import in node:
308
+ 0 && (module.exports = {
309
+ AdjacencyListRepository
310
+ });
@@ -0,0 +1,9 @@
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
+ export { default } from './plugin';
@@ -0,0 +1,42 @@
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 server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_plugin.default
40
+ });
41
+ module.exports = __toCommonJS(server_exports);
42
+ var import_plugin = __toESM(require("./plugin"));
@@ -0,0 +1,17 @@
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 { Migration } from '@nocobase/server';
10
+ import { Model } from '@nocobase/database';
11
+ import { Transaction } from 'sequelize';
12
+ export default class extends Migration {
13
+ on: string;
14
+ appVersion: string;
15
+ up(): Promise<void>;
16
+ getTreePath(model: Model, path: string, collection: Model, pathCollectionName: string, transaction: Transaction): Promise<string>;
17
+ }
@@ -0,0 +1,136 @@
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 collection_tree_exports = {};
38
+ __export(collection_tree_exports, {
39
+ default: () => collection_tree_default
40
+ });
41
+ module.exports = __toCommonJS(collection_tree_exports);
42
+ var import_server = require("@nocobase/server");
43
+ var import_lodash = __toESM(require("lodash"));
44
+ class collection_tree_default extends import_server.Migration {
45
+ on = "afterLoad";
46
+ // 'beforeLoad' or 'afterLoad'
47
+ appVersion = "<=1.3.0-beta";
48
+ async up() {
49
+ await this.db.sequelize.transaction(async (transaction) => {
50
+ const treeCollections = await this.app.db.getRepository("collections").find({
51
+ appends: ["fields"],
52
+ filter: {
53
+ "options.tree": "adjacencyList"
54
+ },
55
+ transaction
56
+ });
57
+ for (const treeCollection of treeCollections) {
58
+ const name = `main_${treeCollection.name}_path`;
59
+ this.app.db.collection({
60
+ name,
61
+ autoGenId: false,
62
+ timestamps: false,
63
+ fields: [
64
+ { type: "integer", name: "nodePk" },
65
+ { type: "string", name: "path", length: 1024 },
66
+ { type: "integer", name: "rootPk" }
67
+ ],
68
+ indexes: [
69
+ {
70
+ fields: [{ name: "path", length: 191 }]
71
+ }
72
+ ]
73
+ });
74
+ const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
75
+ if (!treeExistsInDb) {
76
+ await this.app.db.getCollection(name).sync({ transaction });
77
+ this.app.db.collection({
78
+ name: treeCollection.name,
79
+ autoGenId: false,
80
+ timestamps: false,
81
+ fields: [
82
+ { type: "integer", name: "id" },
83
+ { type: "integer", name: "parentId" }
84
+ ]
85
+ });
86
+ const chunkSize = 1e3;
87
+ await this.app.db.getRepository(treeCollection.name).chunk({
88
+ chunkSize,
89
+ callback: async (rows, options) => {
90
+ const pathData = [];
91
+ for (const data of rows) {
92
+ let path = `/${data.get("id")}`;
93
+ path = await this.getTreePath(data, path, treeCollection, name, transaction);
94
+ pathData.push({
95
+ nodePk: data.get("id"),
96
+ path,
97
+ rootPk: path.split("/")[1]
98
+ });
99
+ }
100
+ await this.app.db.getModel(name).bulkCreate(pathData, { transaction });
101
+ },
102
+ transaction
103
+ });
104
+ }
105
+ }
106
+ });
107
+ }
108
+ async getTreePath(model, path, collection, pathCollectionName, transaction) {
109
+ if (model.get("parentId") !== null) {
110
+ const parent = await this.app.db.getRepository(collection.name).findOne({
111
+ filter: {
112
+ id: model.get("parentId")
113
+ },
114
+ transaction
115
+ });
116
+ if (parent && parent.get("parentId") !== model.get("id")) {
117
+ path = `/${parent.get("id")}${path}`;
118
+ const collectionTreePath = this.app.db.getCollection(pathCollectionName);
119
+ const nodePkColumnName = collectionTreePath.getField("nodePk").columnName();
120
+ const parentPathData = await this.app.db.getRepository(pathCollectionName).findOne({
121
+ filter: {
122
+ [nodePkColumnName]: parent.get("id")
123
+ },
124
+ transaction
125
+ });
126
+ const parentPath = import_lodash.default.get(parentPathData, "path", null);
127
+ if (parentPath == null) {
128
+ path = await this.getTreePath(parent, path, collection, pathCollectionName, transaction);
129
+ } else {
130
+ path = `${parentPath}/${model.get("id")}`;
131
+ }
132
+ }
133
+ }
134
+ return path;
135
+ }
136
+ }
@@ -0,0 +1,15 @@
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 { Plugin } from '@nocobase/server';
10
+ declare class PluginCollectionTreeServer extends Plugin {
11
+ beforeLoad(): Promise<void>;
12
+ private defineTreePathCollection;
13
+ private getTreePath;
14
+ }
15
+ export default PluginCollectionTreeServer;
@@ -0,0 +1,198 @@
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 plugin_exports = {};
38
+ __export(plugin_exports, {
39
+ default: () => plugin_default
40
+ });
41
+ module.exports = __toCommonJS(plugin_exports);
42
+ var import_server = require("@nocobase/server");
43
+ var import_data_source_manager = require("@nocobase/data-source-manager");
44
+ var import_lodash = __toESM(require("lodash"));
45
+ var import_tree_collection = require("./tree-collection");
46
+ const getFilterTargetKey = (model) => {
47
+ return model.constructor.collection.filterTargetKey;
48
+ };
49
+ class PluginCollectionTreeServer extends import_server.Plugin {
50
+ async beforeLoad() {
51
+ const condition = (options) => {
52
+ return options.tree;
53
+ };
54
+ this.app.db.collectionFactory.registerCollectionType(import_tree_collection.TreeCollection, {
55
+ condition
56
+ });
57
+ this.app.dataSourceManager.afterAddDataSource((dataSource) => {
58
+ const collectionManager = dataSource.collectionManager;
59
+ if (collectionManager instanceof import_data_source_manager.SequelizeCollectionManager) {
60
+ collectionManager.db.on("afterDefineCollection", (collection) => {
61
+ var _a;
62
+ if (!condition(collection.options)) {
63
+ return;
64
+ }
65
+ const name = `${dataSource.name}_${collection.name}_path`;
66
+ const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
67
+ this.defineTreePathCollection(name);
68
+ collectionManager.db.on(`${collection.name}.afterSync`, async ({ transaction }) => {
69
+ await this.db.getCollection(name).sync({ transaction });
70
+ });
71
+ this.db.on(`${collection.name}.afterCreate`, async (model, options) => {
72
+ const { transaction } = options;
73
+ const tk = getFilterTargetKey(model);
74
+ let path = `/${model.get(tk)}`;
75
+ path = await this.getTreePath(model, path, collection, name, transaction);
76
+ const rootPk = path.split("/")[1];
77
+ await this.app.db.getRepository(name).create({
78
+ values: {
79
+ nodePk: model.get(tk),
80
+ path,
81
+ rootPk: rootPk ? Number(rootPk) : null
82
+ },
83
+ transaction
84
+ });
85
+ });
86
+ this.db.on(`${collection.name}.afterUpdate`, async (model, options) => {
87
+ const tk = getFilterTargetKey(model);
88
+ if (!(model._changed.has(tk) || model._changed.has(parentForeignKey))) {
89
+ return;
90
+ }
91
+ const { transaction } = options;
92
+ let path = `/${model.get(tk)}`;
93
+ path = await this.getTreePath(model, path, collection, name, transaction);
94
+ const collectionTreePath = this.db.getCollection(name);
95
+ const nodePkColumnName = collectionTreePath.getField("nodePk").columnName();
96
+ const pathData = await this.app.db.getRepository(name).findOne({
97
+ filter: {
98
+ [nodePkColumnName]: model.get(tk)
99
+ },
100
+ transaction
101
+ });
102
+ const relatedNodes = await this.app.db.getRepository(name).find({
103
+ filter: {
104
+ path: {
105
+ $startsWith: `${pathData.get("path")}`
106
+ }
107
+ },
108
+ transaction
109
+ });
110
+ const rootPk = path.split("/")[1];
111
+ for (const node of relatedNodes) {
112
+ await this.app.db.getRepository(name).update({
113
+ values: {
114
+ path: node.get("path").replace(`${pathData.get("path")}`, path),
115
+ rootPk: rootPk ? Number(rootPk) : null
116
+ },
117
+ filter: {
118
+ [nodePkColumnName]: node.get("nodePk")
119
+ },
120
+ transaction
121
+ });
122
+ }
123
+ });
124
+ this.db.on(`${collection.name}.afterDestroy`, async (model, options) => {
125
+ const tk = getFilterTargetKey(model);
126
+ await this.app.db.getRepository(name).destroy({
127
+ filter: {
128
+ nodePk: model.get(tk)
129
+ },
130
+ transaction: options.transaction
131
+ });
132
+ });
133
+ });
134
+ }
135
+ });
136
+ this.db.on("collections.afterDestroy", async (collection, { transaction }) => {
137
+ const name = `main_${collection.get("name")}_path`;
138
+ if (!condition(collection.options)) {
139
+ return;
140
+ }
141
+ const collectionTree = this.db.getCollection(name);
142
+ if (collectionTree) {
143
+ await this.db.getCollection(name).removeFromDb({ transaction });
144
+ }
145
+ });
146
+ }
147
+ async defineTreePathCollection(name) {
148
+ this.db.collection({
149
+ name,
150
+ autoGenId: false,
151
+ timestamps: false,
152
+ fields: [
153
+ { type: "integer", name: "nodePk" },
154
+ { type: "string", name: "path", length: 1024 },
155
+ { type: "integer", name: "rootPk" }
156
+ ],
157
+ indexes: [
158
+ {
159
+ fields: [{ name: "path", length: 191 }]
160
+ }
161
+ ]
162
+ });
163
+ }
164
+ async getTreePath(model, path, collection, pathCollectionName, transaction) {
165
+ var _a;
166
+ const tk = getFilterTargetKey(model);
167
+ const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
168
+ if (model.get(parentForeignKey) && model.get(parentForeignKey) !== null) {
169
+ const parent = await this.app.db.getRepository(collection.name).findOne({
170
+ filter: {
171
+ [tk]: model.get(parentForeignKey)
172
+ },
173
+ transaction
174
+ });
175
+ if (parent && parent.get(parentForeignKey) !== model.get(tk)) {
176
+ path = `/${parent.get(tk)}${path}`;
177
+ if (parent.get(parentForeignKey) !== null) {
178
+ const collectionTreePath = this.app.db.getCollection(pathCollectionName);
179
+ const nodePkColumnName = collectionTreePath.getField("nodePk").columnName();
180
+ const parentPathData = await this.app.db.getRepository(pathCollectionName).findOne({
181
+ filter: {
182
+ [nodePkColumnName]: parent.get(tk)
183
+ },
184
+ transaction
185
+ });
186
+ const parentPath = import_lodash.default.get(parentPathData, "path", null);
187
+ if (parentPath == null) {
188
+ path = await this.getTreePath(parent, path, collection, pathCollectionName, transaction);
189
+ } else {
190
+ path = `${parentPath}/${model.get(tk)}`;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ return path;
196
+ }
197
+ }
198
+ var plugin_default = PluginCollectionTreeServer;
@@ -0,0 +1,13 @@
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 { Collection } from '@nocobase/database';
10
+ export declare class TreeCollection extends Collection {
11
+ setRepository(): void;
12
+ get treeForeignKey(): any;
13
+ }
@@ -0,0 +1,46 @@
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 __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var tree_collection_exports = {};
28
+ __export(tree_collection_exports, {
29
+ TreeCollection: () => TreeCollection
30
+ });
31
+ module.exports = __toCommonJS(tree_collection_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var import_adjacency_list_repository = require("./adjacency-list-repository");
34
+ class TreeCollection extends import_database.Collection {
35
+ setRepository() {
36
+ this.repository = new import_adjacency_list_repository.AdjacencyListRepository(this);
37
+ }
38
+ get treeForeignKey() {
39
+ var _a;
40
+ return ((_a = this.treeParentField) == null ? void 0 : _a.options.foreignKey) || "parent";
41
+ }
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ TreeCollection
46
+ });
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@nocobase/plugin-collection-tree",
3
+ "version": "1.3.0-beta",
4
+ "displayName": "Collection: Tree",
5
+ "displayName.zh-CN": "数据表:树",
6
+ "description": "Provides tree collection template",
7
+ "description.zh-CN": "提供树数据表模板",
8
+ "keywords": [
9
+ "Collections"
10
+ ],
11
+ "main": "dist/server/index.js",
12
+ "peerDependencies": {
13
+ "@nocobase/client": "1.x",
14
+ "@nocobase/server": "1.x",
15
+ "@nocobase/test": "1.x"
16
+ },
17
+ "gitHead": "175a86dcc41577bff4f94ae614ebe778fd532f3f"
18
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');