@nocobase/plugin-data-source-main 1.2.12-alpha → 1.3.0-alpha.20240710084543
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/package.json +2 -2
- package/dist/client/index.d.ts +0 -13
- package/dist/client/index.js +0 -10
- package/dist/externalVersion.js +0 -21
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -48
- package/dist/locale/en-US.json +0 -3
- package/dist/locale/zh-CN.json +0 -3
- package/dist/server/collections/collectionCategories.d.ts +0 -11
- package/dist/server/collections/collectionCategories.js +0 -61
- package/dist/server/collections/collections.d.ts +0 -11
- package/dist/server/collections/collections.js +0 -101
- package/dist/server/collections/fields.d.ts +0 -11
- package/dist/server/collections/fields.js +0 -103
- package/dist/server/errors/field-name-exists-error.d.ts +0 -13
- package/dist/server/errors/field-name-exists-error.js +0 -45
- package/dist/server/hooks/afterCreateForForeignKeyField.d.ts +0 -10
- package/dist/server/hooks/afterCreateForForeignKeyField.js +0 -217
- package/dist/server/hooks/afterCreateForReverseField.d.ts +0 -12
- package/dist/server/hooks/afterCreateForReverseField.js +0 -46
- package/dist/server/hooks/afterDestroyForForeignKeyField.d.ts +0 -10
- package/dist/server/hooks/afterDestroyForForeignKeyField.js +0 -98
- package/dist/server/hooks/beforeCreateForChildrenCollection.d.ts +0 -13
- package/dist/server/hooks/beforeCreateForChildrenCollection.js +0 -67
- package/dist/server/hooks/beforeCreateForReverseField.d.ts +0 -12
- package/dist/server/hooks/beforeCreateForReverseField.js +0 -73
- package/dist/server/hooks/beforeCreateForValidateField.d.ts +0 -15
- package/dist/server/hooks/beforeCreateForValidateField.js +0 -76
- package/dist/server/hooks/beforeCreateForViewCollection.d.ts +0 -13
- package/dist/server/hooks/beforeCreateForViewCollection.js +0 -39
- package/dist/server/hooks/beforeDestroyForeignKey.d.ts +0 -10
- package/dist/server/hooks/beforeDestroyForeignKey.js +0 -75
- package/dist/server/hooks/beforeInitOptions.d.ts +0 -23
- package/dist/server/hooks/beforeInitOptions.js +0 -137
- package/dist/server/hooks/index.d.ts +0 -13
- package/dist/server/hooks/index.js +0 -38
- package/dist/server/index.d.ts +0 -12
- package/dist/server/index.js +0 -54
- package/dist/server/migrations/20220613103214-alert-sub-table.d.ts +0 -13
- package/dist/server/migrations/20220613103214-alert-sub-table.js +0 -50
- package/dist/server/migrations/20220704225714-drop-foreign-keys.d.ts +0 -13
- package/dist/server/migrations/20220704225714-drop-foreign-keys.js +0 -79
- package/dist/server/migrations/20221101111110-update-foreign-fields.d.ts +0 -13
- package/dist/server/migrations/20221101111110-update-foreign-fields.js +0 -74
- package/dist/server/migrations/20221104151410-update-collections-hidden.d.ts +0 -13
- package/dist/server/migrations/20221104151410-update-collections-hidden.js +0 -57
- package/dist/server/migrations/20221121111110-update-fk-type.d.ts +0 -13
- package/dist/server/migrations/20221121111110-update-fk-type.js +0 -155
- package/dist/server/migrations/20221121111113-update-id-to-bigint.d.ts +0 -13
- package/dist/server/migrations/20221121111113-update-id-to-bigint.js +0 -189
- package/dist/server/migrations/20221221103220-timestamps.d.ts +0 -13
- package/dist/server/migrations/20221221103220-timestamps.js +0 -55
- package/dist/server/migrations/20230225111112-drop-ui-schema-relation.d.ts +0 -13
- package/dist/server/migrations/20230225111112-drop-ui-schema-relation.js +0 -97
- package/dist/server/migrations/20230509111114-alert-ui-schema.d.ts +0 -13
- package/dist/server/migrations/20230509111114-alert-ui-schema.js +0 -87
- package/dist/server/migrations/20230623145414-number-step.d.ts +0 -13
- package/dist/server/migrations/20230623145414-number-step.js +0 -81
- package/dist/server/migrations/20230704222935-tableoid.d.ts +0 -13
- package/dist/server/migrations/20230704222935-tableoid.js +0 -83
- package/dist/server/migrations/20230918024546-set-collection-schema.d.ts +0 -13
- package/dist/server/migrations/20230918024546-set-collection-schema.js +0 -55
- package/dist/server/migrations/20240220153103-install-main-datasource.d.ts +0 -14
- package/dist/server/migrations/20240220153103-install-main-datasource.js +0 -51
- package/dist/server/migrations/20240419182147-fix-created-by-field-target.d.ts +0 -14
- package/dist/server/migrations/20240419182147-fix-created-by-field-target.js +0 -49
- package/dist/server/migrations/20240420105949-add-sort-field.d.ts +0 -14
- package/dist/server/migrations/20240420105949-add-sort-field.js +0 -81
- package/dist/server/migrations/20240517101001-fix-target-option-in-tree-collection.d.ts +0 -14
- package/dist/server/migrations/20240517101001-fix-target-option-in-tree-collection.js +0 -54
- package/dist/server/models/collection.d.ts +0 -27
- package/dist/server/models/collection.js +0 -194
- package/dist/server/models/field.d.ts +0 -26
- package/dist/server/models/field.js +0 -173
- package/dist/server/models/index.d.ts +0 -10
- package/dist/server/models/index.js +0 -32
- package/dist/server/repositories/collection-repository.d.ts +0 -20
- package/dist/server/repositories/collection-repository.js +0 -169
- package/dist/server/repositories/index.d.ts +0 -9
- package/dist/server/repositories/index.js +0 -30
- package/dist/server/resourcers/collections.d.ts +0 -12
- package/dist/server/resourcers/collections.js +0 -102
- package/dist/server/resourcers/views.d.ts +0 -17
- package/dist/server/resourcers/views.js +0 -116
- package/dist/server/server.d.ts +0 -19
- package/dist/server/server.js +0 -384
- package/dist/swagger/index.d.ts +0 -413
- package/dist/swagger/index.js +0 -440
|
@@ -1,217 +0,0 @@
|
|
|
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 afterCreateForForeignKeyField_exports = {};
|
|
28
|
-
__export(afterCreateForForeignKeyField_exports, {
|
|
29
|
-
afterCreateForForeignKeyField: () => afterCreateForForeignKeyField
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(afterCreateForForeignKeyField_exports);
|
|
32
|
-
function afterCreateForForeignKeyField(db) {
|
|
33
|
-
function generateFkOptions(collectionName, foreignKey) {
|
|
34
|
-
const collection = db.getCollection(collectionName);
|
|
35
|
-
if (!collection) {
|
|
36
|
-
throw new Error("collection not found");
|
|
37
|
-
}
|
|
38
|
-
const M = collection.model;
|
|
39
|
-
const attr = M.rawAttributes[foreignKey];
|
|
40
|
-
if (!attr) {
|
|
41
|
-
throw new Error(`${collectionName}.${foreignKey} does not exists`);
|
|
42
|
-
}
|
|
43
|
-
return attribute2field(attr);
|
|
44
|
-
}
|
|
45
|
-
function attribute2field(attribute) {
|
|
46
|
-
let type = "bigInt";
|
|
47
|
-
if (attribute.type.constructor.name === "INTEGER") {
|
|
48
|
-
type = "integer";
|
|
49
|
-
} else if (attribute.type.constructor.name === "STRING") {
|
|
50
|
-
type = "string";
|
|
51
|
-
} else if (attribute.type.constructor.name === "UUID") {
|
|
52
|
-
type = "uuid";
|
|
53
|
-
}
|
|
54
|
-
const name = attribute.fieldName;
|
|
55
|
-
const data = {
|
|
56
|
-
interface: "integer",
|
|
57
|
-
name,
|
|
58
|
-
type,
|
|
59
|
-
uiSchema: {
|
|
60
|
-
type: "number",
|
|
61
|
-
title: name,
|
|
62
|
-
"x-component": "InputNumber",
|
|
63
|
-
"x-read-pretty": true
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
if (type === "string") {
|
|
67
|
-
data["interface"] = "input";
|
|
68
|
-
data["uiSchema"] = {
|
|
69
|
-
type: "string",
|
|
70
|
-
title: name,
|
|
71
|
-
"x-component": "Input",
|
|
72
|
-
"x-read-pretty": true
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (type === "uuid") {
|
|
76
|
-
data["interface"] = "uuid";
|
|
77
|
-
data["uiSchema"] = {
|
|
78
|
-
type: "string",
|
|
79
|
-
title: name,
|
|
80
|
-
"x-component": "Input",
|
|
81
|
-
"x-read-pretty": true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return data;
|
|
85
|
-
}
|
|
86
|
-
async function createFieldIfNotExists({ values, transaction }) {
|
|
87
|
-
const { collectionName, name } = values;
|
|
88
|
-
if (!collectionName || !name) {
|
|
89
|
-
throw new Error(`field options invalid`);
|
|
90
|
-
}
|
|
91
|
-
const r = db.getRepository("fields");
|
|
92
|
-
const instance = await r.findOne({
|
|
93
|
-
filter: {
|
|
94
|
-
collectionName,
|
|
95
|
-
name
|
|
96
|
-
},
|
|
97
|
-
transaction
|
|
98
|
-
});
|
|
99
|
-
if (instance) {
|
|
100
|
-
if (instance.type !== values.type) {
|
|
101
|
-
throw new Error(`fk type invalid`);
|
|
102
|
-
}
|
|
103
|
-
instance.set("sort", 1);
|
|
104
|
-
instance.set("isForeignKey", true);
|
|
105
|
-
await instance.save({ transaction });
|
|
106
|
-
} else {
|
|
107
|
-
const creatInstance = await r.create({
|
|
108
|
-
values: {
|
|
109
|
-
isForeignKey: true,
|
|
110
|
-
...values
|
|
111
|
-
},
|
|
112
|
-
transaction
|
|
113
|
-
});
|
|
114
|
-
creatInstance.set("sort", 1);
|
|
115
|
-
await creatInstance.save({ transaction });
|
|
116
|
-
}
|
|
117
|
-
await r.update({
|
|
118
|
-
filter: {
|
|
119
|
-
collectionName,
|
|
120
|
-
options: {
|
|
121
|
-
primaryKey: true
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
values: {
|
|
125
|
-
sort: 0
|
|
126
|
-
},
|
|
127
|
-
transaction
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
const hook = async (model, { transaction, context }) => {
|
|
131
|
-
if (!context) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const {
|
|
135
|
-
type,
|
|
136
|
-
interface: interfaceType,
|
|
137
|
-
collectionName,
|
|
138
|
-
target,
|
|
139
|
-
through,
|
|
140
|
-
foreignKey,
|
|
141
|
-
otherKey,
|
|
142
|
-
source
|
|
143
|
-
} = model.get();
|
|
144
|
-
if (source)
|
|
145
|
-
return;
|
|
146
|
-
if (["oho", "o2m"].includes(interfaceType)) {
|
|
147
|
-
const values = generateFkOptions(target, foreignKey);
|
|
148
|
-
await createFieldIfNotExists({
|
|
149
|
-
values: {
|
|
150
|
-
collectionName: target,
|
|
151
|
-
...values
|
|
152
|
-
},
|
|
153
|
-
transaction
|
|
154
|
-
});
|
|
155
|
-
} else if (["obo", "m2o"].includes(interfaceType)) {
|
|
156
|
-
const values = generateFkOptions(collectionName, foreignKey);
|
|
157
|
-
await createFieldIfNotExists({
|
|
158
|
-
values: { collectionName, ...values },
|
|
159
|
-
transaction
|
|
160
|
-
});
|
|
161
|
-
} else if (["linkTo", "m2m"].includes(interfaceType)) {
|
|
162
|
-
if (type !== "belongsToMany") {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const r = db.getRepository("collections");
|
|
166
|
-
const instance = await r.findOne({
|
|
167
|
-
filter: {
|
|
168
|
-
name: through
|
|
169
|
-
},
|
|
170
|
-
transaction
|
|
171
|
-
});
|
|
172
|
-
if (!instance) {
|
|
173
|
-
await r.create({
|
|
174
|
-
values: {
|
|
175
|
-
name: through,
|
|
176
|
-
title: through,
|
|
177
|
-
timestamps: true,
|
|
178
|
-
autoGenId: false,
|
|
179
|
-
hidden: true,
|
|
180
|
-
autoCreate: true,
|
|
181
|
-
isThrough: true,
|
|
182
|
-
sortable: false
|
|
183
|
-
},
|
|
184
|
-
context,
|
|
185
|
-
transaction
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const opts1 = generateFkOptions(through, foreignKey);
|
|
189
|
-
const opts2 = generateFkOptions(through, otherKey);
|
|
190
|
-
await createFieldIfNotExists({
|
|
191
|
-
values: {
|
|
192
|
-
collectionName: through,
|
|
193
|
-
...opts1
|
|
194
|
-
},
|
|
195
|
-
transaction
|
|
196
|
-
});
|
|
197
|
-
await createFieldIfNotExists({
|
|
198
|
-
values: {
|
|
199
|
-
collectionName: through,
|
|
200
|
-
...opts2
|
|
201
|
-
},
|
|
202
|
-
transaction
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
return async (model, options) => {
|
|
207
|
-
try {
|
|
208
|
-
await hook(model, options);
|
|
209
|
-
} catch (error) {
|
|
210
|
-
console.log(error);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
215
|
-
0 && (module.exports = {
|
|
216
|
-
afterCreateForForeignKeyField
|
|
217
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
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 Database from '@nocobase/database';
|
|
10
|
-
export declare function afterCreateForReverseField(db: Database): (model: any, { transaction }: {
|
|
11
|
-
transaction: any;
|
|
12
|
-
}) => Promise<void>;
|
|
@@ -1,46 +0,0 @@
|
|
|
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 afterCreateForReverseField_exports = {};
|
|
28
|
-
__export(afterCreateForReverseField_exports, {
|
|
29
|
-
afterCreateForReverseField: () => afterCreateForReverseField
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(afterCreateForReverseField_exports);
|
|
32
|
-
function afterCreateForReverseField(db) {
|
|
33
|
-
return async (model, { transaction }) => {
|
|
34
|
-
const Field = db.getCollection("fields");
|
|
35
|
-
const reverseKey = model.get("reverseKey");
|
|
36
|
-
if (!reverseKey) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const reverse = await Field.model.findByPk(reverseKey, { transaction });
|
|
40
|
-
await reverse.update({ reverseKey: model.get("key") }, { hooks: false, transaction });
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
-
0 && (module.exports = {
|
|
45
|
-
afterCreateForReverseField
|
|
46
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
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 Database from '@nocobase/database';
|
|
10
|
-
export declare function afterDestroyForForeignKeyField(db: Database): (model: any, opts: any) => Promise<void>;
|
|
@@ -1,98 +0,0 @@
|
|
|
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 afterDestroyForForeignKeyField_exports = {};
|
|
28
|
-
__export(afterDestroyForForeignKeyField_exports, {
|
|
29
|
-
afterDestroyForForeignKeyField: () => afterDestroyForForeignKeyField
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(afterDestroyForForeignKeyField_exports);
|
|
32
|
-
async function destroyFields(db, transaction, fieldRecords) {
|
|
33
|
-
const fieldsRepo = db.getRepository("fields");
|
|
34
|
-
for (const fieldRecord of fieldRecords) {
|
|
35
|
-
await fieldsRepo.destroy({
|
|
36
|
-
filter: {
|
|
37
|
-
name: fieldRecord.get("name"),
|
|
38
|
-
collectionName: fieldRecord.get("collectionName")
|
|
39
|
-
},
|
|
40
|
-
transaction
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function afterDestroyForForeignKeyField(db) {
|
|
45
|
-
return async (model, opts) => {
|
|
46
|
-
const { transaction } = opts;
|
|
47
|
-
const options = model.get("options");
|
|
48
|
-
if (!(options == null ? void 0 : options.isForeignKey)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const collectionRepo = db.getRepository("collections");
|
|
52
|
-
const foreignKey = model.get("name");
|
|
53
|
-
const foreignKeyCollectionName = model.get("collectionName");
|
|
54
|
-
const collectionRecord = await collectionRepo.findOne({
|
|
55
|
-
filter: {
|
|
56
|
-
name: foreignKeyCollectionName
|
|
57
|
-
},
|
|
58
|
-
transaction
|
|
59
|
-
});
|
|
60
|
-
const collectionOptions = collectionRecord.get("options");
|
|
61
|
-
const fieldsRepo = db.getRepository("fields");
|
|
62
|
-
if (collectionOptions == null ? void 0 : collectionOptions.isThrough) {
|
|
63
|
-
const fieldRecords = await fieldsRepo.find({
|
|
64
|
-
filter: {
|
|
65
|
-
options: { through: foreignKeyCollectionName, foreignKey }
|
|
66
|
-
},
|
|
67
|
-
transaction
|
|
68
|
-
});
|
|
69
|
-
await destroyFields(db, transaction, fieldRecords);
|
|
70
|
-
} else {
|
|
71
|
-
await destroyFields(
|
|
72
|
-
db,
|
|
73
|
-
transaction,
|
|
74
|
-
await fieldsRepo.find({
|
|
75
|
-
filter: {
|
|
76
|
-
collectionName: foreignKeyCollectionName,
|
|
77
|
-
options: { foreignKey }
|
|
78
|
-
},
|
|
79
|
-
transaction
|
|
80
|
-
})
|
|
81
|
-
);
|
|
82
|
-
await destroyFields(
|
|
83
|
-
db,
|
|
84
|
-
transaction,
|
|
85
|
-
await fieldsRepo.find({
|
|
86
|
-
filter: {
|
|
87
|
-
options: { foreignKey, target: foreignKeyCollectionName }
|
|
88
|
-
},
|
|
89
|
-
transaction
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
-
0 && (module.exports = {
|
|
97
|
-
afterDestroyForForeignKeyField
|
|
98
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
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 Database from '@nocobase/database';
|
|
10
|
-
export declare function beforeCreateForChildrenCollection(db: Database): (model: any, { transaction, context }: {
|
|
11
|
-
transaction: any;
|
|
12
|
-
context: any;
|
|
13
|
-
}) => Promise<void>;
|
|
@@ -1,67 +0,0 @@
|
|
|
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 beforeCreateForChildrenCollection_exports = {};
|
|
28
|
-
__export(beforeCreateForChildrenCollection_exports, {
|
|
29
|
-
beforeCreateForChildrenCollection: () => beforeCreateForChildrenCollection
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(beforeCreateForChildrenCollection_exports);
|
|
32
|
-
function beforeCreateForChildrenCollection(db) {
|
|
33
|
-
return async (model, { transaction, context }) => {
|
|
34
|
-
const Collection = db.getCollection("collections");
|
|
35
|
-
const Field = db.getCollection("fields");
|
|
36
|
-
const parentKey = model.get("parentKey");
|
|
37
|
-
if (!parentKey) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const parent = await Field.model.findByPk(parentKey, { transaction });
|
|
41
|
-
const parentTarget = parent.get("target");
|
|
42
|
-
model.set("collectionName", parentTarget);
|
|
43
|
-
const collection = await Collection.model.findOne({
|
|
44
|
-
transaction,
|
|
45
|
-
where: {
|
|
46
|
-
name: parentTarget
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
if (!collection) {
|
|
50
|
-
await Collection.repository.create({
|
|
51
|
-
values: {
|
|
52
|
-
name: parentTarget,
|
|
53
|
-
createdBy: true,
|
|
54
|
-
updatedBy: true,
|
|
55
|
-
sortable: true,
|
|
56
|
-
inherit: true
|
|
57
|
-
},
|
|
58
|
-
transaction,
|
|
59
|
-
context
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
-
0 && (module.exports = {
|
|
66
|
-
beforeCreateForChildrenCollection
|
|
67
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
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 Database from '@nocobase/database';
|
|
10
|
-
export declare function beforeCreateForReverseField(db: Database): (model: any, { transaction }: {
|
|
11
|
-
transaction: any;
|
|
12
|
-
}) => Promise<void>;
|
|
@@ -1,73 +0,0 @@
|
|
|
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 beforeCreateForReverseField_exports = {};
|
|
28
|
-
__export(beforeCreateForReverseField_exports, {
|
|
29
|
-
beforeCreateForReverseField: () => beforeCreateForReverseField
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(beforeCreateForReverseField_exports);
|
|
32
|
-
function beforeCreateForReverseField(db) {
|
|
33
|
-
return async (model, { transaction }) => {
|
|
34
|
-
const Field = db.getCollection("fields");
|
|
35
|
-
const reverseKey = model.get("reverseKey");
|
|
36
|
-
if (!reverseKey) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const reverse = await Field.model.findByPk(reverseKey, { transaction });
|
|
40
|
-
model.set("collectionName", reverse.get("target"));
|
|
41
|
-
model.set("target", reverse.get("collectionName"));
|
|
42
|
-
if (reverse.get("onDelete")) {
|
|
43
|
-
model.set("onDelete", reverse.get("onDelete"));
|
|
44
|
-
}
|
|
45
|
-
const reverseType = reverse.get("type");
|
|
46
|
-
if (["hasMany", "hasOne"].includes(reverseType)) {
|
|
47
|
-
model.set("type", "belongsTo");
|
|
48
|
-
model.set("targetKey", reverse.get("sourceKey"));
|
|
49
|
-
model.set("foreignKey", reverse.get("foreignKey"));
|
|
50
|
-
model.set("sourceKey", reverse.get("targetKey"));
|
|
51
|
-
}
|
|
52
|
-
if (["belongsTo"].includes(reverseType)) {
|
|
53
|
-
if (!model.get("type")) {
|
|
54
|
-
model.set("type", "hasMany");
|
|
55
|
-
}
|
|
56
|
-
model.set("sourceKey", reverse.get("targetKey"));
|
|
57
|
-
model.set("foreignKey", reverse.get("foreignKey"));
|
|
58
|
-
model.set("targetKey", reverse.get("sourceKey"));
|
|
59
|
-
}
|
|
60
|
-
if (["belongsToMany"].includes(reverseType)) {
|
|
61
|
-
model.set("type", "belongsToMany");
|
|
62
|
-
model.set("through", reverse.get("through"));
|
|
63
|
-
model.set("sourceKey", reverse.get("targetKey"));
|
|
64
|
-
model.set("foreignKey", reverse.get("otherKey"));
|
|
65
|
-
model.set("targetKey", reverse.get("sourceKey"));
|
|
66
|
-
model.set("otherKey", reverse.get("foreignKey"));
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
-
0 && (module.exports = {
|
|
72
|
-
beforeCreateForReverseField
|
|
73
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
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 { Database } from '@nocobase/database';
|
|
10
|
-
export declare function beforeCreateForValidateField(db: Database): (model: any, { transaction }: {
|
|
11
|
-
transaction: any;
|
|
12
|
-
}) => Promise<void>;
|
|
13
|
-
export declare function beforeUpdateForValidateField(db: Database): (model: any, { transaction }: {
|
|
14
|
-
transaction: any;
|
|
15
|
-
}) => Promise<void>;
|
|
@@ -1,76 +0,0 @@
|
|
|
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 beforeCreateForValidateField_exports = {};
|
|
28
|
-
__export(beforeCreateForValidateField_exports, {
|
|
29
|
-
beforeCreateForValidateField: () => beforeCreateForValidateField,
|
|
30
|
-
beforeUpdateForValidateField: () => beforeUpdateForValidateField
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(beforeCreateForValidateField_exports);
|
|
33
|
-
function beforeCreateForValidateField(db) {
|
|
34
|
-
return async (model, { transaction }) => {
|
|
35
|
-
if (model.type === "belongsToMany") {
|
|
36
|
-
if (model.get("foreignKey") === model.get("otherKey")) {
|
|
37
|
-
throw new Error("foreignKey and otherKey can not be the same");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const isPrimaryKey = model.get("primaryKey");
|
|
41
|
-
if (isPrimaryKey) {
|
|
42
|
-
const collection = db.getCollection(model.get("collectionName"));
|
|
43
|
-
if (!collection) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
47
|
-
if (primaryKey !== model.get("name") && collection.model.rawAttributes[primaryKey]) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`add field ${model.get("name")} failed, collection ${collection.name} already has primary key ${primaryKey}`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function beforeUpdateForValidateField(db) {
|
|
56
|
-
return async (model, { transaction }) => {
|
|
57
|
-
const isPrimaryKey = model.get("primaryKey");
|
|
58
|
-
if (isPrimaryKey) {
|
|
59
|
-
const collection = db.getCollection(model.get("collectionName"));
|
|
60
|
-
if (!collection) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
64
|
-
if (primaryKey !== model.get("name") && collection.model.rawAttributes[primaryKey]) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`update field ${model.get("name")} failed, collection ${collection.name} already has primary key ${primaryKey}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
beforeCreateForValidateField,
|
|
75
|
-
beforeUpdateForValidateField
|
|
76
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
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 { Database } from '@nocobase/database';
|
|
10
|
-
export declare function beforeCreateForViewCollection(db: Database): (model: any, { transaction, context }: {
|
|
11
|
-
transaction: any;
|
|
12
|
-
context: any;
|
|
13
|
-
}) => Promise<void>;
|