@nocobase/plugin-collection-tree 1.3.0-beta → 1.3.2-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.
@@ -8,11 +8,11 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.3.0-beta",
11
+ "@nocobase/client": "1.3.2-beta",
12
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",
13
+ "@nocobase/database": "1.3.2-beta",
14
+ "@nocobase/utils": "1.3.2-beta",
15
+ "@nocobase/data-source-manager": "1.3.2-beta",
16
+ "@nocobase/server": "1.3.2-beta",
17
17
  "sequelize": "6.35.2"
18
18
  };
@@ -6,8 +6,8 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Migration } from '@nocobase/server';
10
9
  import { Model } from '@nocobase/database';
10
+ import { Migration } from '@nocobase/server';
11
11
  import { Transaction } from 'sequelize';
12
12
  export default class extends Migration {
13
13
  on: string;
@@ -56,7 +56,7 @@ class collection_tree_default extends import_server.Migration {
56
56
  });
57
57
  for (const treeCollection of treeCollections) {
58
58
  const name = `main_${treeCollection.name}_path`;
59
- this.app.db.collection({
59
+ const collectionOptions = {
60
60
  name,
61
61
  autoGenId: false,
62
62
  timestamps: false,
@@ -70,11 +70,15 @@ class collection_tree_default extends import_server.Migration {
70
70
  fields: [{ name: "path", length: 191 }]
71
71
  }
72
72
  ]
73
- });
73
+ };
74
+ if (treeCollection.options.schema) {
75
+ collectionOptions["schema"] = treeCollection.options.schema;
76
+ }
77
+ this.app.db.collection(collectionOptions);
74
78
  const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
75
79
  if (!treeExistsInDb) {
76
80
  await this.app.db.getCollection(name).sync({ transaction });
77
- this.app.db.collection({
81
+ const opts = {
78
82
  name: treeCollection.name,
79
83
  autoGenId: false,
80
84
  timestamps: false,
@@ -82,7 +86,11 @@ class collection_tree_default extends import_server.Migration {
82
86
  { type: "integer", name: "id" },
83
87
  { type: "integer", name: "parentId" }
84
88
  ]
85
- });
89
+ };
90
+ if (treeCollection.options.schema) {
91
+ opts["schema"] = treeCollection.options.schema;
92
+ }
93
+ this.app.db.collection(opts);
86
94
  const chunkSize = 1e3;
87
95
  await this.app.db.getRepository(treeCollection.name).chunk({
88
96
  chunkSize,
@@ -39,8 +39,8 @@ __export(plugin_exports, {
39
39
  default: () => plugin_default
40
40
  });
41
41
  module.exports = __toCommonJS(plugin_exports);
42
- var import_server = require("@nocobase/server");
43
42
  var import_data_source_manager = require("@nocobase/data-source-manager");
43
+ var import_server = require("@nocobase/server");
44
44
  var import_lodash = __toESM(require("lodash"));
45
45
  var import_tree_collection = require("./tree-collection");
46
46
  const getFilterTargetKey = (model) => {
@@ -64,12 +64,16 @@ class PluginCollectionTreeServer extends import_server.Plugin {
64
64
  }
65
65
  const name = `${dataSource.name}_${collection.name}_path`;
66
66
  const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
67
- this.defineTreePathCollection(name);
67
+ const options = {};
68
+ if (collection.options.schema) {
69
+ options["schema"] = collection.options.schema;
70
+ }
71
+ this.defineTreePathCollection(name, options);
68
72
  collectionManager.db.on(`${collection.name}.afterSync`, async ({ transaction }) => {
69
73
  await this.db.getCollection(name).sync({ transaction });
70
74
  });
71
- this.db.on(`${collection.name}.afterCreate`, async (model, options) => {
72
- const { transaction } = options;
75
+ this.db.on(`${collection.name}.afterCreate`, async (model, options2) => {
76
+ const { transaction } = options2;
73
77
  const tk = getFilterTargetKey(model);
74
78
  let path = `/${model.get(tk)}`;
75
79
  path = await this.getTreePath(model, path, collection, name, transaction);
@@ -83,12 +87,12 @@ class PluginCollectionTreeServer extends import_server.Plugin {
83
87
  transaction
84
88
  });
85
89
  });
86
- this.db.on(`${collection.name}.afterUpdate`, async (model, options) => {
90
+ this.db.on(`${collection.name}.afterUpdate`, async (model, options2) => {
87
91
  const tk = getFilterTargetKey(model);
88
92
  if (!(model._changed.has(tk) || model._changed.has(parentForeignKey))) {
89
93
  return;
90
94
  }
91
- const { transaction } = options;
95
+ const { transaction } = options2;
92
96
  let path = `/${model.get(tk)}`;
93
97
  path = await this.getTreePath(model, path, collection, name, transaction);
94
98
  const collectionTreePath = this.db.getCollection(name);
@@ -121,13 +125,13 @@ class PluginCollectionTreeServer extends import_server.Plugin {
121
125
  });
122
126
  }
123
127
  });
124
- this.db.on(`${collection.name}.afterDestroy`, async (model, options) => {
128
+ this.db.on(`${collection.name}.afterDestroy`, async (model, options2) => {
125
129
  const tk = getFilterTargetKey(model);
126
130
  await this.app.db.getRepository(name).destroy({
127
131
  filter: {
128
132
  nodePk: model.get(tk)
129
133
  },
130
- transaction: options.transaction
134
+ transaction: options2.transaction
131
135
  });
132
136
  });
133
137
  });
@@ -144,7 +148,7 @@ class PluginCollectionTreeServer extends import_server.Plugin {
144
148
  }
145
149
  });
146
150
  }
147
- async defineTreePathCollection(name) {
151
+ async defineTreePathCollection(name, options) {
148
152
  this.db.collection({
149
153
  name,
150
154
  autoGenId: false,
@@ -158,7 +162,8 @@ class PluginCollectionTreeServer extends import_server.Plugin {
158
162
  {
159
163
  fields: [{ name: "path", length: 191 }]
160
164
  }
161
- ]
165
+ ],
166
+ ...options
162
167
  });
163
168
  }
164
169
  async getTreePath(model, path, collection, pathCollectionName, transaction) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-collection-tree",
3
- "version": "1.3.0-beta",
3
+ "version": "1.3.2-beta",
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": "175a86dcc41577bff4f94ae614ebe778fd532f3f"
17
+ "gitHead": "7a411e2dec764d9d7800dc4eaae26b5ce0b1c751"
18
18
  }