@nocobase/plugin-data-source-main 1.2.25-alpha → 1.2.26-alpha

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,14 +8,14 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.2.25-alpha",
12
- "@nocobase/database": "1.2.25-alpha",
13
- "@nocobase/plugin-error-handler": "1.2.25-alpha",
14
- "@nocobase/server": "1.2.25-alpha",
11
+ "@nocobase/client": "1.2.26-alpha",
12
+ "@nocobase/database": "1.2.26-alpha",
13
+ "@nocobase/plugin-error-handler": "1.2.26-alpha",
14
+ "@nocobase/server": "1.2.26-alpha",
15
15
  "async-mutex": "0.3.2",
16
16
  "lodash": "4.17.21",
17
- "@nocobase/test": "1.2.25-alpha",
18
- "@nocobase/utils": "1.2.25-alpha",
17
+ "@nocobase/test": "1.2.26-alpha",
18
+ "@nocobase/utils": "1.2.26-alpha",
19
19
  "sequelize": "6.35.2",
20
20
  "dayjs": "1.11.10"
21
21
  };
@@ -0,0 +1,11 @@
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 declare function beforeCreateCheckFieldInMySQL(db: any): (model: any, { transaction }: {
10
+ transaction: any;
11
+ }) => Promise<void>;
@@ -0,0 +1,62 @@
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 beforeCreateCheckFieldInMySQL_exports = {};
28
+ __export(beforeCreateCheckFieldInMySQL_exports, {
29
+ beforeCreateCheckFieldInMySQL: () => beforeCreateCheckFieldInMySQL
30
+ });
31
+ module.exports = __toCommonJS(beforeCreateCheckFieldInMySQL_exports);
32
+ function beforeCreateCheckFieldInMySQL(db) {
33
+ return async (model, { transaction }) => {
34
+ if (!db.isMySQLCompatibleDialect()) {
35
+ return;
36
+ }
37
+ const fieldOptions = model.get();
38
+ if (fieldOptions.autoIncrement) {
39
+ const collection = db.getCollection(fieldOptions.collectionName);
40
+ if (!collection) {
41
+ return;
42
+ }
43
+ const rawAttributes = collection.model.rawAttributes;
44
+ const fields = Object.keys(rawAttributes);
45
+ for (const key of fields) {
46
+ if (key === fieldOptions.name) {
47
+ continue;
48
+ }
49
+ const field = rawAttributes[key];
50
+ if (field.autoIncrement) {
51
+ throw new Error(
52
+ `Can not add field ${fieldOptions.name}, autoIncrement field ${key} is already in a table ${collection.getTableNameWithSchemaAsString()}`
53
+ );
54
+ }
55
+ }
56
+ }
57
+ };
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ beforeCreateCheckFieldInMySQL
62
+ });
@@ -56,6 +56,7 @@ var import_views = __toESM(require("./resourcers/views"));
56
56
  var import_field_name_exists_error = require("./errors/field-name-exists-error");
57
57
  var import_beforeDestoryField = require("./hooks/beforeDestoryField");
58
58
  var import_field_is_depended_on_by_other = require("./errors/field-is-depended-on-by-other");
59
+ var import_beforeCreateCheckFieldInMySQL = require("./hooks/beforeCreateCheckFieldInMySQL");
59
60
  class PluginDataSourceMainServer extends import_server.Plugin {
60
61
  schema;
61
62
  loadFilter = {};
@@ -107,6 +108,7 @@ class PluginDataSourceMainServer extends import_server.Plugin {
107
108
  }
108
109
  await model.remove(removeOptions);
109
110
  });
111
+ this.app.db.on("fields.beforeCreate", (0, import_beforeCreateCheckFieldInMySQL.beforeCreateCheckFieldInMySQL)(this.app.db));
110
112
  this.app.db.on("fields.beforeCreate", (0, import_hooks.beforeCreateForReverseField)(this.app.db));
111
113
  this.app.db.on("fields.beforeCreate", async (model, options) => {
112
114
  const collectionName = model.get("collectionName");
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据源:主数据库",
5
5
  "description": "NocoBase main database, supports relational databases such as MySQL, PostgreSQL, SQLite and so on.",
6
6
  "description.zh-CN": "NocoBase 主数据库,支持 MySQL、PostgreSQL、SQLite 等关系型数据库。",
7
- "version": "1.2.25-alpha",
7
+ "version": "1.2.26-alpha",
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",
@@ -22,7 +22,7 @@
22
22
  "@nocobase/test": "1.x",
23
23
  "@nocobase/utils": "1.x"
24
24
  },
25
- "gitHead": "72a6f9a73afc615b7f16fac6197ad44c29bf1e0f",
25
+ "gitHead": "a463b25b4f7de08f71f43a22cb6171f0a58aa66a",
26
26
  "keywords": [
27
27
  "Data sources"
28
28
  ]