@nocobase/plugin-data-source-main 1.9.0-beta.8 → 2.0.0-alpha.10

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,13 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.9.0-beta.8",
11
+ "@nocobase/client": "2.0.0-alpha.10",
12
12
  "lodash": "4.17.21",
13
- "@nocobase/database": "1.9.0-beta.8",
14
- "@nocobase/plugin-error-handler": "1.9.0-beta.8",
15
- "@nocobase/server": "1.9.0-beta.8",
16
- "@nocobase/test": "1.9.0-beta.8",
17
- "@nocobase/utils": "1.9.0-beta.8",
13
+ "@nocobase/database": "2.0.0-alpha.10",
14
+ "@nocobase/plugin-error-handler": "2.0.0-alpha.10",
15
+ "@nocobase/server": "2.0.0-alpha.10",
16
+ "@nocobase/test": "2.0.0-alpha.10",
17
+ "@nocobase/utils": "2.0.0-alpha.10",
18
18
  "sequelize": "6.35.2",
19
19
  "dayjs": "1.11.13"
20
20
  };
@@ -36,9 +36,14 @@ var collectionCategories_default = {
36
36
  migrationRules: ["overwrite", "schema-only"],
37
37
  shared: true,
38
38
  name: "collectionCategories",
39
- autoGenId: true,
40
39
  sortable: true,
41
40
  fields: [
41
+ {
42
+ name: "id",
43
+ type: "snowflakeId",
44
+ primaryKey: true,
45
+ allowNull: false
46
+ },
42
47
  {
43
48
  type: "string",
44
49
  name: "name",
@@ -1,2 +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
+ */
1
9
  import { Database } from '@nocobase/database';
2
10
  export declare function beforeDestoryField(db: Database): (model: any, opts: any) => Promise<void>;
@@ -32,8 +32,13 @@ module.exports = __toCommonJS(beforeDestoryField_exports);
32
32
  var import_field_is_depended_on_by_other = require("../errors/field-is-depended-on-by-other");
33
33
  function beforeDestoryField(db) {
34
34
  return async (model, opts) => {
35
+ var _a;
35
36
  const { transaction } = opts;
36
37
  const { name, type, collectionName } = model.get();
38
+ const collection = db.getCollection(model.get("collectionName"));
39
+ if ((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.uiManageable) {
40
+ throw new Error("Cannot remove a UI manageable field");
41
+ }
37
42
  if (["belongsTo", "hasOne", "hasMany", "belongsToMany"].includes(type)) {
38
43
  return;
39
44
  }
@@ -15,6 +15,7 @@ export declare class CollectionRepository extends Repository {
15
15
  private app;
16
16
  setApp(app: any): void;
17
17
  load(options?: LoadOptions): Promise<void>;
18
+ db2cmCollections(collectionNames: string[]): Promise<void>;
18
19
  db2cm(collectionName: string): Promise<void>;
19
20
  }
20
21
  export {};
@@ -140,6 +140,9 @@ class CollectionRepository extends import_database.Repository {
140
140
  }
141
141
  this.database.logger.debug("collections loaded");
142
142
  }
143
+ async db2cmCollections(collectionNames) {
144
+ await Promise.all(collectionNames.map((collectionName) => this.db2cm(collectionName)));
145
+ }
143
146
  async db2cm(collectionName) {
144
147
  const collection = this.database.getCollection(collectionName);
145
148
  if (await this.findOne({ filter: { name: collectionName } })) {
@@ -10,9 +10,11 @@ import { Filter } from '@nocobase/database';
10
10
  import { Plugin } from '@nocobase/server';
11
11
  export declare class PluginDataSourceMainServer extends Plugin {
12
12
  private loadFilter;
13
+ private db2cmCollections;
13
14
  setLoadFilter(filter: Filter): void;
14
15
  handleSyncMessage(message: any): Promise<void>;
15
16
  beforeLoad(): Promise<void>;
17
+ private db2cm;
16
18
  load(): Promise<void>;
17
19
  install(): Promise<void>;
18
20
  }
@@ -57,6 +57,7 @@ var import_collections = __toESM(require("./resourcers/collections"));
57
57
  var import_views = __toESM(require("./resourcers/views"));
58
58
  class PluginDataSourceMainServer extends import_server.Plugin {
59
59
  loadFilter = {};
60
+ db2cmCollections = [];
60
61
  setLoadFilter(filter) {
61
62
  this.loadFilter = filter;
62
63
  }
@@ -128,6 +129,9 @@ class PluginDataSourceMainServer extends import_server.Plugin {
128
129
  }
129
130
  );
130
131
  this.app.db.on("collections.beforeDestroy", async (model, options) => {
132
+ if (model.options.uiManageable) {
133
+ throw new Error("Cannot remove a UI manageable collection");
134
+ }
131
135
  const removeOptions = {};
132
136
  if (options.transaction) {
133
137
  removeOptions["transaction"] = options.transaction;
@@ -359,6 +363,22 @@ class PluginDataSourceMainServer extends import_server.Plugin {
359
363
  name: `pm.data-source-manager.collection-view `,
360
364
  actions: ["dbViews:*"]
361
365
  });
366
+ this.app.db.on("afterDefineCollection", async (collection) => {
367
+ var _a;
368
+ if ((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.uiManageable) {
369
+ this.db2cmCollections.push(collection.name);
370
+ }
371
+ });
372
+ this.app.on("afterEnablePlugin", this.db2cm.bind(this));
373
+ this.app.on("afterInstall", this.db2cm.bind(this));
374
+ this.app.on("afterUpgrade", this.db2cm.bind(this));
375
+ }
376
+ async db2cm() {
377
+ if (this.db2cmCollections.length) {
378
+ await this.app.db.getRepository("collections").db2cmCollections(this.db2cmCollections);
379
+ this.log.info(`collections synced to collection manager: ${this.db2cmCollections.join(", ")}`);
380
+ this.db2cmCollections = [];
381
+ }
362
382
  }
363
383
  async load() {
364
384
  this.db.getRepository("collections").setApp(this.app);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据源:主数据库",
5
5
  "description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
6
6
  "description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
7
- "version": "1.9.0-beta.8",
7
+ "version": "2.0.0-alpha.10",
8
8
  "main": "./dist/server/index.js",
9
9
  "homepage": "https://docs.nocobase.com/handbook/data-source-main",
10
10
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/data-source-main",
@@ -14,15 +14,15 @@
14
14
  "toposort": "^2.0.2"
15
15
  },
16
16
  "peerDependencies": {
17
- "@nocobase/client": "1.x",
18
- "@nocobase/database": "1.x",
19
- "@nocobase/plugin-error-handler": "1.x",
20
- "@nocobase/plugin-field-sort": "1.x",
21
- "@nocobase/server": "1.x",
22
- "@nocobase/test": "1.x",
23
- "@nocobase/utils": "1.x"
17
+ "@nocobase/client": "2.x",
18
+ "@nocobase/database": "2.x",
19
+ "@nocobase/plugin-error-handler": "2.x",
20
+ "@nocobase/plugin-field-sort": "2.x",
21
+ "@nocobase/server": "2.x",
22
+ "@nocobase/test": "2.x",
23
+ "@nocobase/utils": "2.x"
24
24
  },
25
- "gitHead": "f3d4f3d1ba7adbf4d4c60e656c23da45565769c8",
25
+ "gitHead": "6422cfb6fa6c8450de2efa3294fd29a28b228990",
26
26
  "keywords": [
27
27
  "Data sources"
28
28
  ]