@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,27 +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, { Collection, MagicAttributeModel, SyncOptions, Transactionable } from '@nocobase/database';
|
|
10
|
-
import { QueryInterfaceDropTableOptions } from 'sequelize';
|
|
11
|
-
interface LoadOptions extends Transactionable {
|
|
12
|
-
skipField?: boolean | Array<string>;
|
|
13
|
-
skipExist?: boolean;
|
|
14
|
-
resetFields?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class CollectionModel extends MagicAttributeModel {
|
|
17
|
-
get db(): Database;
|
|
18
|
-
toJSON(): any;
|
|
19
|
-
load(loadOptions?: LoadOptions): Promise<Collection<any, any>>;
|
|
20
|
-
loadFields(options?: Transactionable & {
|
|
21
|
-
skipField?: Array<string>;
|
|
22
|
-
includeFields?: Array<string>;
|
|
23
|
-
}): Promise<void>;
|
|
24
|
-
remove(options?: Transactionable & QueryInterfaceDropTableOptions): Promise<void>;
|
|
25
|
-
migrate(options?: SyncOptions & Transactionable): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,194 +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 __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var collection_exports = {};
|
|
38
|
-
__export(collection_exports, {
|
|
39
|
-
CollectionModel: () => CollectionModel
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(collection_exports);
|
|
42
|
-
var import_database = require("@nocobase/database");
|
|
43
|
-
var import_lodash = __toESM(require("lodash"));
|
|
44
|
-
class CollectionModel extends import_database.MagicAttributeModel {
|
|
45
|
-
get db() {
|
|
46
|
-
return this.constructor.database;
|
|
47
|
-
}
|
|
48
|
-
toJSON() {
|
|
49
|
-
const json = super.toJSON();
|
|
50
|
-
if (!json.filterTargetKey) {
|
|
51
|
-
const collection = this.db.getCollection(json.name);
|
|
52
|
-
json.filterTargetKey = collection == null ? void 0 : collection.filterTargetKey;
|
|
53
|
-
}
|
|
54
|
-
return json;
|
|
55
|
-
}
|
|
56
|
-
async load(loadOptions = {}) {
|
|
57
|
-
const { skipExist, skipField, resetFields, transaction } = loadOptions;
|
|
58
|
-
const name = this.get("name");
|
|
59
|
-
let collection;
|
|
60
|
-
const collectionOptions = {
|
|
61
|
-
origin: "@nocobase/plugin-data-source-main",
|
|
62
|
-
...this.get(),
|
|
63
|
-
fields: [],
|
|
64
|
-
loadedFromCollectionManager: true
|
|
65
|
-
};
|
|
66
|
-
if (!this.db.inDialect("postgres") && collectionOptions.schema) {
|
|
67
|
-
delete collectionOptions.schema;
|
|
68
|
-
}
|
|
69
|
-
if (this.db.hasCollection(name)) {
|
|
70
|
-
collection = this.db.getCollection(name);
|
|
71
|
-
if (skipExist) {
|
|
72
|
-
return collection;
|
|
73
|
-
}
|
|
74
|
-
if (resetFields) {
|
|
75
|
-
collection.resetFields();
|
|
76
|
-
}
|
|
77
|
-
collection.updateOptions(collectionOptions);
|
|
78
|
-
} else {
|
|
79
|
-
if (!collectionOptions.dumpRules) {
|
|
80
|
-
import_lodash.default.set(collectionOptions, "dumpRules.group", "custom");
|
|
81
|
-
}
|
|
82
|
-
collection = this.db.collection(collectionOptions);
|
|
83
|
-
}
|
|
84
|
-
if (!skipField) {
|
|
85
|
-
await this.loadFields({ transaction });
|
|
86
|
-
}
|
|
87
|
-
if (import_lodash.default.isArray(skipField)) {
|
|
88
|
-
await this.loadFields({ transaction, skipField });
|
|
89
|
-
}
|
|
90
|
-
await this.db.emitAsync("collection:loaded", {
|
|
91
|
-
collection,
|
|
92
|
-
transaction
|
|
93
|
-
});
|
|
94
|
-
return collection;
|
|
95
|
-
}
|
|
96
|
-
async loadFields(options = {}) {
|
|
97
|
-
let fields = this.get("fields") || [];
|
|
98
|
-
if (!fields.length) {
|
|
99
|
-
fields = await this.getFields(options);
|
|
100
|
-
}
|
|
101
|
-
if (options.skipField) {
|
|
102
|
-
fields = fields.filter((field) => !options.skipField.includes(field.name));
|
|
103
|
-
}
|
|
104
|
-
if (options.includeFields) {
|
|
105
|
-
fields = fields.filter((field) => options.includeFields.includes(field.name));
|
|
106
|
-
}
|
|
107
|
-
if (this.options.view && fields.find((f) => f.name == "id")) {
|
|
108
|
-
fields = fields.map((field) => {
|
|
109
|
-
if (field.name == "id") {
|
|
110
|
-
field.set("primaryKey", true);
|
|
111
|
-
} else {
|
|
112
|
-
field.set("primaryKey", false);
|
|
113
|
-
}
|
|
114
|
-
return field;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
const instances = fields;
|
|
118
|
-
instances.sort((a, b) => {
|
|
119
|
-
if (a.isAssociationField() && !b.isAssociationField()) {
|
|
120
|
-
return 1;
|
|
121
|
-
}
|
|
122
|
-
if (!a.isAssociationField() && b.isAssociationField()) {
|
|
123
|
-
return -1;
|
|
124
|
-
}
|
|
125
|
-
return 0;
|
|
126
|
-
});
|
|
127
|
-
for (const instance of instances) {
|
|
128
|
-
await instance.load(options);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async remove(options) {
|
|
132
|
-
const { transaction } = options || {};
|
|
133
|
-
const name = this.get("name");
|
|
134
|
-
const collection = this.db.getCollection(name);
|
|
135
|
-
if (!collection) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const fields = await this.db.getRepository("fields").find({
|
|
139
|
-
filter: {
|
|
140
|
-
"type.$in": ["belongsToMany", "belongsTo", "hasMany", "hasOne"]
|
|
141
|
-
},
|
|
142
|
-
transaction
|
|
143
|
-
});
|
|
144
|
-
for (const field of fields) {
|
|
145
|
-
if (field.get("target") && field.get("target") === name) {
|
|
146
|
-
await field.destroy({ transaction });
|
|
147
|
-
} else if (field.get("through") && field.get("through") === name) {
|
|
148
|
-
await field.destroy({ transaction });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
await collection.removeFromDb(options);
|
|
152
|
-
}
|
|
153
|
-
async migrate(options) {
|
|
154
|
-
const pendingFieldsTargetToThis = this.db.pendingFields.get(this.get("name")) || [];
|
|
155
|
-
const getPendingField = () => pendingFieldsTargetToThis.map((field) => {
|
|
156
|
-
return {
|
|
157
|
-
name: field.get("name"),
|
|
158
|
-
collectionName: field.get("collectionName")
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
const beforePendingFields = getPendingField();
|
|
162
|
-
const collection = await this.load({
|
|
163
|
-
transaction: options == null ? void 0 : options.transaction
|
|
164
|
-
});
|
|
165
|
-
const afterPendingFields = getPendingField();
|
|
166
|
-
const resolvedPendingFields = import_lodash.default.differenceWith(beforePendingFields, afterPendingFields, import_lodash.default.isEqual);
|
|
167
|
-
const resolvedPendingFieldsCollections = import_lodash.default.uniq(resolvedPendingFields.map((field) => field.collectionName));
|
|
168
|
-
if (Object.keys(collection.model.tableAttributes).length == 0 && !this.db.inDialect("postgres")) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
const syncOptions = {
|
|
173
|
-
force: false,
|
|
174
|
-
alter: {
|
|
175
|
-
drop: false
|
|
176
|
-
},
|
|
177
|
-
...options
|
|
178
|
-
};
|
|
179
|
-
await collection.sync(syncOptions);
|
|
180
|
-
for (const collectionName of resolvedPendingFieldsCollections) {
|
|
181
|
-
await this.db.getCollection(collectionName).sync(syncOptions);
|
|
182
|
-
}
|
|
183
|
-
} catch (error) {
|
|
184
|
-
console.error(error);
|
|
185
|
-
const name = this.get("name");
|
|
186
|
-
this.db.removeCollection(name);
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
192
|
-
0 && (module.exports = {
|
|
193
|
-
CollectionModel
|
|
194
|
-
});
|
|
@@ -1,26 +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, { Collection, MagicAttributeModel, Transactionable } from '@nocobase/database';
|
|
10
|
-
interface LoadOptions extends Transactionable {
|
|
11
|
-
skipExist?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class FieldModel extends MagicAttributeModel {
|
|
14
|
-
get db(): Database;
|
|
15
|
-
isAssociationField(): boolean;
|
|
16
|
-
load(loadOptions?: LoadOptions): Promise<import("@nocobase/database").Field>;
|
|
17
|
-
syncSortByField(options: Transactionable): Promise<void>;
|
|
18
|
-
remove(options?: any): Promise<void>;
|
|
19
|
-
syncUniqueIndex(options: Transactionable): Promise<void>;
|
|
20
|
-
syncDefaultValue(options: Transactionable & {
|
|
21
|
-
defaultValue: any;
|
|
22
|
-
}): Promise<void>;
|
|
23
|
-
syncReferenceCheckOption(options: Transactionable): Promise<void>;
|
|
24
|
-
protected getFieldCollection(): Collection | null;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
@@ -1,173 +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 field_exports = {};
|
|
28
|
-
__export(field_exports, {
|
|
29
|
-
FieldModel: () => FieldModel
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(field_exports);
|
|
32
|
-
var import_database = require("@nocobase/database");
|
|
33
|
-
class FieldModel extends import_database.MagicAttributeModel {
|
|
34
|
-
get db() {
|
|
35
|
-
return this.constructor.database;
|
|
36
|
-
}
|
|
37
|
-
isAssociationField() {
|
|
38
|
-
return ["belongsTo", "hasOne", "hasMany", "belongsToMany"].includes(this.get("type"));
|
|
39
|
-
}
|
|
40
|
-
async load(loadOptions) {
|
|
41
|
-
const { skipExist = false, transaction } = loadOptions || {};
|
|
42
|
-
const collectionName = this.get("collectionName");
|
|
43
|
-
if (!this.db.hasCollection(collectionName)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const collection = this.db.getCollection(collectionName);
|
|
47
|
-
const name = this.get("name");
|
|
48
|
-
if (skipExist && collection.hasField(name)) {
|
|
49
|
-
return collection.getField(name);
|
|
50
|
-
}
|
|
51
|
-
const options = this.get();
|
|
52
|
-
const field = await (async () => {
|
|
53
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
54
|
-
return collection.setField(name, options);
|
|
55
|
-
})();
|
|
56
|
-
await this.db.emitAsync("field:loaded", {
|
|
57
|
-
fieldKey: this.get("key"),
|
|
58
|
-
transaction
|
|
59
|
-
});
|
|
60
|
-
return field;
|
|
61
|
-
}
|
|
62
|
-
async syncSortByField(options) {
|
|
63
|
-
const collectionName = this.get("collectionName");
|
|
64
|
-
const collection = this.db.getCollection(collectionName);
|
|
65
|
-
await this.load(options);
|
|
66
|
-
await collection.sync({
|
|
67
|
-
force: false,
|
|
68
|
-
alter: {
|
|
69
|
-
drop: false
|
|
70
|
-
},
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
transaction: options.transaction
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async remove(options) {
|
|
76
|
-
const collection = this.getFieldCollection();
|
|
77
|
-
if (!collection) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
return collection.removeFieldFromDb(this.get("name"), {
|
|
81
|
-
transaction: options.transaction
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async syncUniqueIndex(options) {
|
|
85
|
-
const unique = this.get("unique");
|
|
86
|
-
const collection = this.getFieldCollection();
|
|
87
|
-
const field = collection.getField(this.get("name"));
|
|
88
|
-
const columnName = collection.model.rawAttributes[this.get("name")].field;
|
|
89
|
-
const tableName = collection.model.tableName;
|
|
90
|
-
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
91
|
-
const existsIndexes = await queryInterface.showIndex(collection.getTableNameWithSchema(), {
|
|
92
|
-
transaction: options.transaction
|
|
93
|
-
});
|
|
94
|
-
const existUniqueIndex = existsIndexes.find((item) => {
|
|
95
|
-
return item.unique && item.fields[0].attribute === columnName && item.fields.length === 1;
|
|
96
|
-
});
|
|
97
|
-
let existsUniqueConstraint;
|
|
98
|
-
const constraintName = `${tableName}_${field.name}_uk`;
|
|
99
|
-
if (existUniqueIndex) {
|
|
100
|
-
const existsUniqueConstraints = await queryInterface.showConstraint(
|
|
101
|
-
collection.getTableNameWithSchema(),
|
|
102
|
-
constraintName,
|
|
103
|
-
{}
|
|
104
|
-
);
|
|
105
|
-
existsUniqueConstraint = existsUniqueConstraints[0];
|
|
106
|
-
}
|
|
107
|
-
if (unique && !existsUniqueConstraint) {
|
|
108
|
-
await collection.sync({ ...options, force: false, alter: { drop: false } });
|
|
109
|
-
await queryInterface.addConstraint(collection.getTableNameWithSchema(), {
|
|
110
|
-
type: "unique",
|
|
111
|
-
fields: [columnName],
|
|
112
|
-
name: constraintName,
|
|
113
|
-
transaction: options.transaction
|
|
114
|
-
});
|
|
115
|
-
this.db.logger.info(`add unique index ${constraintName}`);
|
|
116
|
-
}
|
|
117
|
-
if (!unique && existsUniqueConstraint) {
|
|
118
|
-
await queryInterface.removeConstraint(collection.getTableNameWithSchema(), constraintName, {
|
|
119
|
-
transaction: options.transaction
|
|
120
|
-
});
|
|
121
|
-
this.db.logger.info(`remove unique index ${constraintName}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async syncDefaultValue(options) {
|
|
125
|
-
const collection = this.getFieldCollection();
|
|
126
|
-
if (!collection) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (collection.isView()) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const field = collection.getField(this.get("name"));
|
|
133
|
-
if (field.get("overriding")) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const queryInterface = collection.db.sequelize.getQueryInterface();
|
|
137
|
-
await queryInterface.changeColumn(
|
|
138
|
-
collection.getTableNameWithSchema(),
|
|
139
|
-
collection.model.rawAttributes[this.get("name")].field,
|
|
140
|
-
{
|
|
141
|
-
type: field.dataType,
|
|
142
|
-
defaultValue: options.defaultValue
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
transaction: options.transaction
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
async syncReferenceCheckOption(options) {
|
|
150
|
-
const reverseKey = this.get("reverseKey");
|
|
151
|
-
if (!reverseKey)
|
|
152
|
-
return;
|
|
153
|
-
const reverseField = await this.db.getCollection("fields").repository.findOne({
|
|
154
|
-
filterByTk: reverseKey,
|
|
155
|
-
transaction: options.transaction
|
|
156
|
-
});
|
|
157
|
-
if (!reverseField)
|
|
158
|
-
return;
|
|
159
|
-
reverseField.set("onDelete", this.get("onDelete"));
|
|
160
|
-
await reverseField.save({ hooks: false, transaction: options.transaction });
|
|
161
|
-
}
|
|
162
|
-
getFieldCollection() {
|
|
163
|
-
const collectionName = this.get("collectionName");
|
|
164
|
-
if (!this.db.hasCollection(collectionName)) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
return this.db.getCollection(collectionName);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
-
0 && (module.exports = {
|
|
172
|
-
FieldModel
|
|
173
|
-
});
|
|
@@ -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
|
-
export * from './collection';
|
|
10
|
-
export * from './field';
|
|
@@ -1,32 +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 __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var models_exports = {};
|
|
25
|
-
module.exports = __toCommonJS(models_exports);
|
|
26
|
-
__reExport(models_exports, require("./collection"), module.exports);
|
|
27
|
-
__reExport(models_exports, require("./field"), module.exports);
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
...require("./collection"),
|
|
31
|
-
...require("./field")
|
|
32
|
-
});
|
|
@@ -1,20 +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 { Repository } from '@nocobase/database';
|
|
10
|
-
interface LoadOptions {
|
|
11
|
-
filter?: any;
|
|
12
|
-
skipExist?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare class CollectionRepository extends Repository {
|
|
15
|
-
private app;
|
|
16
|
-
setApp(app: any): void;
|
|
17
|
-
load(options?: LoadOptions): Promise<void>;
|
|
18
|
-
db2cm(collectionName: string): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,169 +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 __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __export = (target, all) => {
|
|
17
|
-
for (var name in all)
|
|
18
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
var collection_repository_exports = {};
|
|
38
|
-
__export(collection_repository_exports, {
|
|
39
|
-
CollectionRepository: () => CollectionRepository
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(collection_repository_exports);
|
|
42
|
-
var import_database = require("@nocobase/database");
|
|
43
|
-
var import_utils = require("@nocobase/utils");
|
|
44
|
-
var import_lodash = __toESM(require("lodash"));
|
|
45
|
-
class CollectionRepository extends import_database.Repository {
|
|
46
|
-
app;
|
|
47
|
-
setApp(app) {
|
|
48
|
-
this.app = app;
|
|
49
|
-
}
|
|
50
|
-
async load(options = {}) {
|
|
51
|
-
this.database.logger.debug("loading collections...");
|
|
52
|
-
const { filter, skipExist } = options;
|
|
53
|
-
const instances = await this.find({ filter, appends: ["fields"] });
|
|
54
|
-
const graphlib = import_utils.CollectionsGraph.graphlib();
|
|
55
|
-
const graph = new graphlib.Graph();
|
|
56
|
-
const nameMap = {};
|
|
57
|
-
const viewCollections = [];
|
|
58
|
-
for (const instance of instances) {
|
|
59
|
-
graph.setNode(instance.get("name"));
|
|
60
|
-
if (instance.get("view") || instance.get("sql")) {
|
|
61
|
-
viewCollections.push(instance.get("name"));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
for (const instance of instances) {
|
|
65
|
-
const collectionName = instance.get("name");
|
|
66
|
-
nameMap[collectionName] = instance;
|
|
67
|
-
if (instance.get("inherits")) {
|
|
68
|
-
for (const parent of instance.get("inherits")) {
|
|
69
|
-
graph.setEdge(parent, collectionName);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (graph.nodeCount() === 0)
|
|
74
|
-
return;
|
|
75
|
-
if (!graphlib.alg.isAcyclic(graph)) {
|
|
76
|
-
const cycles = graphlib.alg.findCycles(graph);
|
|
77
|
-
throw new Error(`Cyclic dependencies: ${cycles.map((cycle) => cycle.join(" -> ")).join(", ")}`);
|
|
78
|
-
}
|
|
79
|
-
const sortedNames = graphlib.alg.topsort(graph);
|
|
80
|
-
const lazyCollectionFields = /* @__PURE__ */ new Map();
|
|
81
|
-
for (const instanceName of sortedNames) {
|
|
82
|
-
if (!nameMap[instanceName])
|
|
83
|
-
continue;
|
|
84
|
-
const skipField = (() => {
|
|
85
|
-
if (viewCollections.includes(instanceName)) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
const fields = nameMap[instanceName].get("fields");
|
|
89
|
-
return fields.filter((field) => field["type"] === "belongsTo" || field["type"] === "belongsToMany").map((field) => field.get("name"));
|
|
90
|
-
})();
|
|
91
|
-
if (import_lodash.default.isArray(skipField) && skipField.length) {
|
|
92
|
-
lazyCollectionFields.set(instanceName, skipField);
|
|
93
|
-
}
|
|
94
|
-
this.database.logger.trace(`load ${instanceName} collection`, {
|
|
95
|
-
submodule: "CollectionRepository",
|
|
96
|
-
method: "load"
|
|
97
|
-
});
|
|
98
|
-
this.app.setMaintainingMessage(`load ${instanceName} collection`);
|
|
99
|
-
await nameMap[instanceName].load({ skipField });
|
|
100
|
-
}
|
|
101
|
-
const fieldWithSourceAttributes = /* @__PURE__ */ new Map();
|
|
102
|
-
for (const viewCollectionName of viewCollections) {
|
|
103
|
-
this.database.logger.trace(`load collection fields`, {
|
|
104
|
-
submodule: "CollectionRepository",
|
|
105
|
-
method: "load",
|
|
106
|
-
viewCollectionName
|
|
107
|
-
});
|
|
108
|
-
const skipField = (() => {
|
|
109
|
-
const fields = nameMap[viewCollectionName].get("fields");
|
|
110
|
-
return fields.filter((field) => {
|
|
111
|
-
var _a;
|
|
112
|
-
if (((_a = field.options) == null ? void 0 : _a.source) && (field["type"] === "belongsTo" || field["type"] === "belongsToMany")) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}).map((field) => field.get("name"));
|
|
117
|
-
})();
|
|
118
|
-
this.app.setMaintainingMessage(`load ${viewCollectionName} collection fields`);
|
|
119
|
-
if (import_lodash.default.isArray(skipField) && skipField.length) {
|
|
120
|
-
fieldWithSourceAttributes.set(viewCollectionName, skipField);
|
|
121
|
-
}
|
|
122
|
-
await nameMap[viewCollectionName].loadFields({ skipField });
|
|
123
|
-
}
|
|
124
|
-
for (const [collectionName, skipField] of lazyCollectionFields) {
|
|
125
|
-
this.database.logger.trace(`load collection fields`, {
|
|
126
|
-
submodule: "CollectionRepository",
|
|
127
|
-
method: "load",
|
|
128
|
-
collectionName
|
|
129
|
-
});
|
|
130
|
-
this.app.setMaintainingMessage(`load ${collectionName} collection fields`);
|
|
131
|
-
await nameMap[collectionName].loadFields({ includeFields: skipField });
|
|
132
|
-
}
|
|
133
|
-
for (const [collectionName, skipField] of fieldWithSourceAttributes) {
|
|
134
|
-
this.database.logger.trace(`load collection fields`, {
|
|
135
|
-
submodule: "CollectionRepository",
|
|
136
|
-
method: "load",
|
|
137
|
-
collectionName
|
|
138
|
-
});
|
|
139
|
-
this.app.setMaintainingMessage(`load ${collectionName} collection fields`);
|
|
140
|
-
await nameMap[collectionName].loadFields({ includeFields: skipField });
|
|
141
|
-
}
|
|
142
|
-
this.database.logger.debug("collections loaded");
|
|
143
|
-
}
|
|
144
|
-
async db2cm(collectionName) {
|
|
145
|
-
const collection = this.database.getCollection(collectionName);
|
|
146
|
-
if (await this.findOne({ filter: { name: collectionName } })) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const options = collection.options;
|
|
150
|
-
const fields = [];
|
|
151
|
-
for (const [name, field] of collection.fields) {
|
|
152
|
-
fields.push({
|
|
153
|
-
name,
|
|
154
|
-
...field.options
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
await this.create({
|
|
158
|
-
values: {
|
|
159
|
-
...options,
|
|
160
|
-
fields,
|
|
161
|
-
from: "db2cm"
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
167
|
-
0 && (module.exports = {
|
|
168
|
-
CollectionRepository
|
|
169
|
-
});
|
|
@@ -1,9 +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
|
-
export * from './collection-repository';
|