@nocobase/plugin-field-m2m-array 2.4.0-alpha.1 → 2.4.0-alpha.11

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.
@@ -11,13 +11,13 @@ module.exports = {
11
11
  "@formily/react": "2.3.7",
12
12
  "antd": "5.24.2",
13
13
  "react": "18.2.0",
14
- "@nocobase/client": "2.4.0-alpha.1",
14
+ "@nocobase/client": "2.4.0-alpha.11",
15
15
  "react-router-dom": "6.30.1",
16
- "@nocobase/utils": "2.4.0-alpha.1",
17
- "@nocobase/client-v2": "2.4.0-alpha.1",
18
- "@nocobase/flow-engine": "2.4.0-alpha.1",
19
- "@nocobase/database": "2.4.0-alpha.1",
16
+ "@nocobase/utils": "2.4.0-alpha.11",
17
+ "@nocobase/client-v2": "2.4.0-alpha.11",
18
+ "@nocobase/flow-engine": "2.4.0-alpha.11",
19
+ "@nocobase/database": "2.4.0-alpha.11",
20
20
  "lodash": "4.18.1",
21
- "@nocobase/server": "2.4.0-alpha.1",
22
- "@nocobase/data-source-manager": "2.4.0-alpha.1"
21
+ "@nocobase/server": "2.4.0-alpha.11",
22
+ "@nocobase/data-source-manager": "2.4.0-alpha.11"
23
23
  };
@@ -0,0 +1,14 @@
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
+ export default class extends Migration {
11
+ on: string;
12
+ up(): Promise<void>;
13
+ private hasValidAssociationKeys;
14
+ }
@@ -0,0 +1,72 @@
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 remove_self_source_exports = {};
28
+ __export(remove_self_source_exports, {
29
+ default: () => remove_self_source_default
30
+ });
31
+ module.exports = __toCommonJS(remove_self_source_exports);
32
+ var import_server = require("@nocobase/server");
33
+ var import_belongs_to_array_field = require("../belongs-to-array-field");
34
+ const FOREIGN_KEY_TYPES = ["set", "array", "json", "jsonb"];
35
+ class remove_self_source_default extends import_server.Migration {
36
+ on = "afterLoad";
37
+ // 'beforeLoad' or 'afterLoad'
38
+ async up() {
39
+ const fields = await this.db.getRepository("fields").find({
40
+ filter: {
41
+ type: "belongsToArray"
42
+ }
43
+ });
44
+ for (const field of fields) {
45
+ if (field.get("source") !== field.get("collectionName")) {
46
+ continue;
47
+ }
48
+ if (!await this.hasValidAssociationKeys(field)) {
49
+ continue;
50
+ }
51
+ field.set("source", void 0);
52
+ await field.save({ hooks: false });
53
+ }
54
+ }
55
+ async hasValidAssociationKeys(field) {
56
+ const fieldRepo = this.db.getRepository("fields");
57
+ const foreignField = await fieldRepo.findOne({
58
+ filter: { collectionName: field.get("collectionName"), name: field.get("foreignKey") }
59
+ });
60
+ const targetField = await fieldRepo.findOne({
61
+ filter: { collectionName: field.get("target"), name: field.get("targetKey") }
62
+ });
63
+ if (!foreignField || !targetField || !FOREIGN_KEY_TYPES.includes(foreignField.get("type"))) {
64
+ return false;
65
+ }
66
+ if (!this.db.inDialect("postgres") || foreignField.get("dataType") !== "array") {
67
+ return true;
68
+ }
69
+ const targetType = targetField.get("type");
70
+ return foreignField.get("elementType") === (import_belongs_to_array_field.elementTypeMap[targetType] || targetType);
71
+ }
72
+ }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model.",
7
7
  "description.ru-RU": "Позволяет создавать отношения «многие ко многим» между двумя моделями, сохраняя массив уникальных ключей целевой модели.",
8
8
  "description.zh-CN": "支持通过在数组中存储目标表唯一键的方式建立多对多关系。",
9
- "version": "2.4.0-alpha.1",
9
+ "version": "2.4.0-alpha.11",
10
10
  "main": "dist/server/index.js",
11
11
  "peerDependencies": {
12
12
  "@nocobase/client": "2.x",
@@ -18,5 +18,5 @@
18
18
  "Collection fields"
19
19
  ],
20
20
  "license": "Apache-2.0",
21
- "gitHead": "82ecd3aed067e4cc98c32e7a0039b6e55cee76a7"
21
+ "gitHead": "99aeb1bc859eb31d9710073d761ac72c97341e9d"
22
22
  }