@nocobase/plugin-data-source-manager 0.21.0-alpha.9 → 1.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.
- package/dist/client/DatabaseConnectionProvider.d.ts +8 -0
- package/dist/client/ThridDataSource.d.ts +8 -0
- package/dist/client/component/BreadcumbTitle.d.ts +8 -0
- package/dist/client/component/CollectionsManager/AddFieldAction.d.ts +8 -0
- package/dist/client/component/CollectionsManager/CollectionFields.d.ts +8 -0
- package/dist/client/component/CollectionsManager/ConfigurationTable.d.ts +8 -0
- package/dist/client/component/CollectionsManager/ConfigurationTabs.d.ts +8 -0
- package/dist/client/component/CollectionsManager/EditCollectionAction.d.ts +8 -0
- package/dist/client/component/CollectionsManager/EditFieldAction.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/CollectionFieldInterfaceSelect.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/CollectionName.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/FieldTitleInput.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/FieldType.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/TitleField.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/UnSupportFields.d.ts +8 -0
- package/dist/client/component/CollectionsManager/components/index.d.ts +8 -0
- package/dist/client/component/CollectionsManager/hooks.d.ts +8 -0
- package/dist/client/component/CollectionsManager/index.d.ts +8 -0
- package/dist/client/component/CollectionsManager/schema/collectionFields.d.ts +8 -0
- package/dist/client/component/CollectionsManager/schema/collections.d.ts +8 -0
- package/dist/client/component/CreateDatabaseConnectAction.d.ts +8 -0
- package/dist/client/component/DatabaseConnectionManager.d.ts +8 -0
- package/dist/client/component/EditDatabaseConnectionAction.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/AddCategoryAction.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/CollectionFields.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTable.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTabs.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/EditCategoryAction.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/index.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/interfaces.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/schemas/collectionFields.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/Configuration/schemas/collections.d.ts +8 -0
- package/dist/client/component/MainDataSourceManager/index.d.ts +8 -0
- package/dist/client/component/PermissionManager/DataSourceTable.d.ts +8 -0
- package/dist/client/component/PermissionManager/PermisionProvider.d.ts +8 -0
- package/dist/client/component/PermissionManager/RoleConfigure.d.ts +8 -0
- package/dist/client/component/PermissionManager/RolesResourcesActions.d.ts +8 -0
- package/dist/client/component/PermissionManager/ScopeSelect.d.ts +8 -0
- package/dist/client/component/PermissionManager/StrategyActions.d.ts +8 -0
- package/dist/client/component/PermissionManager/index.d.ts +8 -0
- package/dist/client/component/PermissionManager/schemas/dataSourceTable.d.ts +8 -0
- package/dist/client/component/PermissionManager/schemas/roleCollections.d.ts +8 -0
- package/dist/client/component/PermissionManager/schemas/scopes.d.ts +8 -0
- package/dist/client/component/PermissionManager/schemas/useRoleResourceValues.d.ts +8 -0
- package/dist/client/component/PermissionManager/schemas/useSaveRoleResourceAction.d.ts +8 -0
- package/dist/client/component/PermissionManager/style.d.ts +8 -0
- package/dist/client/component/ViewDatabaseConnectionAction.d.ts +8 -0
- package/dist/client/constant.d.ts +8 -0
- package/dist/client/hooks/index.d.ts +8 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +20 -11
- package/dist/client/locale/index.d.ts +8 -0
- package/dist/client/schema/index.d.ts +8 -0
- package/dist/externalVersion.js +15 -6
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/server/collections/data-sources-collections.d.ts +8 -0
- package/dist/server/collections/data-sources-collections.js +9 -0
- package/dist/server/collections/data-sources-fields.d.ts +8 -0
- package/dist/server/collections/data-sources-fields.js +9 -0
- package/dist/server/collections/data-sources-roles-resources-actions.d.ts +8 -0
- package/dist/server/collections/data-sources-roles-resources-actions.js +9 -0
- package/dist/server/collections/data-sources-roles-resources-scopes.d.ts +8 -0
- package/dist/server/collections/data-sources-roles-resources-scopes.js +9 -0
- package/dist/server/collections/data-sources-roles-resources.d.ts +8 -0
- package/dist/server/collections/data-sources-roles-resources.js +9 -0
- package/dist/server/collections/data-sources-roles.d.ts +8 -0
- package/dist/server/collections/data-sources-roles.js +9 -0
- package/dist/server/collections/data-sources.d.ts +8 -0
- package/dist/server/collections/data-sources.js +9 -0
- package/dist/server/errors/type-infer-error.d.ts +8 -0
- package/dist/server/errors/type-infer-error.js +9 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +9 -0
- package/dist/server/migrations/20240301164024-migrate-acl-resources.d.ts +8 -0
- package/dist/server/migrations/20240301164024-migrate-acl-resources.js +10 -0
- package/dist/server/migrations/20240414103927-update-snippet-name.d.ts +8 -0
- package/dist/server/migrations/20240414103927-update-snippet-name.js +9 -0
- package/dist/server/models/connections-roles-resources-action.d.ts +8 -0
- package/dist/server/models/connections-roles-resources-action.js +9 -0
- package/dist/server/models/connections-roles-resources.d.ts +8 -0
- package/dist/server/models/connections-roles-resources.js +9 -0
- package/dist/server/models/data-source.d.ts +8 -0
- package/dist/server/models/data-source.js +11 -4
- package/dist/server/models/data-sources-collection-model.d.ts +8 -0
- package/dist/server/models/data-sources-collection-model.js +9 -0
- package/dist/server/models/data-sources-field-model.d.ts +8 -0
- package/dist/server/models/data-sources-field-model.js +9 -0
- package/dist/server/models/data-sources-roles-model.d.ts +8 -2
- package/dist/server/models/data-sources-roles-model.js +10 -3
- package/dist/server/plugin.d.ts +8 -0
- package/dist/server/plugin.js +34 -31
- package/dist/server/resourcers/data-sources-collections-fields.d.ts +8 -0
- package/dist/server/resourcers/data-sources-collections-fields.js +9 -0
- package/dist/server/resourcers/data-sources-collections.d.ts +8 -0
- package/dist/server/resourcers/data-sources-collections.js +9 -0
- package/dist/server/resourcers/data-sources-resources.d.ts +8 -0
- package/dist/server/resourcers/data-sources-resources.js +9 -0
- package/dist/server/resourcers/data-sources-roles.d.ts +8 -0
- package/dist/server/resourcers/data-sources-roles.js +9 -0
- package/dist/server/resourcers/roles-data-sources-collections.d.ts +8 -0
- package/dist/server/resourcers/roles-data-sources-collections.js +9 -0
- package/dist/server/services/full-data-repository.d.ts +8 -0
- package/dist/server/services/full-data-repository.js +9 -0
- package/dist/server/services/type-interface-map.d.ts +8 -0
- package/dist/server/services/type-interface-map.js +10 -0
- package/dist/server/utils.d.ts +8 -0
- package/dist/server/utils.js +9 -0
- package/package.json +5 -5
- package/dist/server/services/collection-manager.d.ts +0 -6
- package/dist/server/services/collection-manager.js +0 -33
- package/dist/server/services/database-introspector.d.ts +0 -70
- package/dist/server/services/database-introspector.js +0 -235
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var database_introspector_exports = {};
|
|
29
|
-
__export(database_introspector_exports, {
|
|
30
|
-
DatabaseIntrospector: () => DatabaseIntrospector
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(database_introspector_exports);
|
|
33
|
-
var import_database = require("@nocobase/database");
|
|
34
|
-
var import_lodash = __toESM(require("lodash"));
|
|
35
|
-
var import_type_interface_map = __toESM(require("./type-interface-map"));
|
|
36
|
-
class DatabaseIntrospector {
|
|
37
|
-
constructor(db) {
|
|
38
|
-
this.db = db;
|
|
39
|
-
}
|
|
40
|
-
async getCollections(options = {}) {
|
|
41
|
-
const tableList = await this.db.sequelize.getQueryInterface().showAllTables();
|
|
42
|
-
const batchSize = 5;
|
|
43
|
-
const results = [];
|
|
44
|
-
for (let i = 0; i < tableList.length; i += batchSize) {
|
|
45
|
-
const batch = tableList.slice(i, i + batchSize);
|
|
46
|
-
const batchResults = await Promise.all(
|
|
47
|
-
batch.map(async (tableName) => {
|
|
48
|
-
var _a;
|
|
49
|
-
const tableInfo = {
|
|
50
|
-
tableName
|
|
51
|
-
};
|
|
52
|
-
const collectionOptions = this.tableInfoToCollectionOptions(tableInfo);
|
|
53
|
-
const localOptions = (_a = options.localData) == null ? void 0 : _a[collectionOptions.name];
|
|
54
|
-
try {
|
|
55
|
-
return await this.getCollection({
|
|
56
|
-
tableInfo,
|
|
57
|
-
localOptions
|
|
58
|
-
});
|
|
59
|
-
} catch (e) {
|
|
60
|
-
if (e.message.includes("No description found for")) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
results.push(...batchResults);
|
|
68
|
-
}
|
|
69
|
-
return results.filter(Boolean);
|
|
70
|
-
}
|
|
71
|
-
async getCollection(options) {
|
|
72
|
-
const { tableInfo } = options;
|
|
73
|
-
const columnsInfo = await this.db.sequelize.getQueryInterface().describeTable(tableInfo);
|
|
74
|
-
const collectionOptions = this.tableInfoToCollectionOptions(tableInfo);
|
|
75
|
-
const constraints = await this.db.sequelize.getQueryInterface().showIndex(this.db.inDialect("postgres") ? tableInfo : tableInfo.tableName);
|
|
76
|
-
try {
|
|
77
|
-
const fields = Object.keys(columnsInfo).map((columnName) => {
|
|
78
|
-
return this.columnInfoToFieldOptions(columnsInfo, columnName, constraints);
|
|
79
|
-
});
|
|
80
|
-
const unsupportedFields = fields.filter((field) => {
|
|
81
|
-
return field.supported === false;
|
|
82
|
-
});
|
|
83
|
-
const supportFields = fields.filter((field) => {
|
|
84
|
-
return field.supported !== false;
|
|
85
|
-
});
|
|
86
|
-
const remoteCollectionInfo = {
|
|
87
|
-
...collectionOptions,
|
|
88
|
-
...this.collectionOptionsByFields(supportFields),
|
|
89
|
-
fields: supportFields
|
|
90
|
-
};
|
|
91
|
-
if (unsupportedFields.length) {
|
|
92
|
-
remoteCollectionInfo.unsupportedFields = unsupportedFields;
|
|
93
|
-
}
|
|
94
|
-
return this.mergeLocalDataIntoCollectionOptions(remoteCollectionInfo, options.localOptions);
|
|
95
|
-
} catch (e) {
|
|
96
|
-
throw new Error(`table ${tableInfo.tableName} introspection error: ${e.message}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
loadCollection(options) {
|
|
100
|
-
this.db.collection({
|
|
101
|
-
...options,
|
|
102
|
-
introspected: true
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
loadCollections(options) {
|
|
106
|
-
options.collections.forEach((collection) => {
|
|
107
|
-
this.loadCollection(collection);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
tableInfoToCollectionOptions(tableInfo) {
|
|
111
|
-
return {
|
|
112
|
-
name: tableInfo.tableName,
|
|
113
|
-
title: tableInfo.tableName,
|
|
114
|
-
schema: tableInfo.schema,
|
|
115
|
-
tableName: tableInfo.tableName
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
collectionOptionsByFields(fields) {
|
|
119
|
-
const options = {
|
|
120
|
-
timestamps: false
|
|
121
|
-
};
|
|
122
|
-
const autoIncrementField = fields.find((field) => field.autoIncrement);
|
|
123
|
-
if (autoIncrementField) {
|
|
124
|
-
options.filterTargetKey = autoIncrementField.name;
|
|
125
|
-
}
|
|
126
|
-
const primaryKeys = fields.filter((field) => field.primaryKey);
|
|
127
|
-
if (!options.filterTargetKey && primaryKeys.length == 1) {
|
|
128
|
-
options.filterTargetKey = primaryKeys[0].name;
|
|
129
|
-
}
|
|
130
|
-
const uniques = fields.filter((field) => field.unique);
|
|
131
|
-
if (!options.filterTargetKey && uniques.length == 1) {
|
|
132
|
-
options.filterTargetKey = uniques[0].name;
|
|
133
|
-
}
|
|
134
|
-
return options;
|
|
135
|
-
}
|
|
136
|
-
mergeLocalDataIntoCollectionOptions(collectionOptions, localData) {
|
|
137
|
-
var _a;
|
|
138
|
-
if (!localData) {
|
|
139
|
-
return collectionOptions;
|
|
140
|
-
}
|
|
141
|
-
const collectionFields = collectionOptions.fields || [];
|
|
142
|
-
const localFieldsAsObject = import_lodash.default.keyBy(localData.fields, "name");
|
|
143
|
-
const newFields = collectionFields.map((field) => {
|
|
144
|
-
const localField = localFieldsAsObject[field.name];
|
|
145
|
-
if (!localField) {
|
|
146
|
-
return field;
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
...field,
|
|
150
|
-
...localField
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
const localAssociationFields = (_a = localData.fields) == null ? void 0 : _a.filter((field) => {
|
|
154
|
-
return ["belongsTo", "belongsToMany", "hasMany", "hasOne"].includes(field.type);
|
|
155
|
-
});
|
|
156
|
-
if (localAssociationFields) {
|
|
157
|
-
newFields.push(...localAssociationFields);
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
...collectionOptions,
|
|
161
|
-
...import_lodash.default.omit(localData, ["fields"]),
|
|
162
|
-
fields: newFields
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
columnInfoToFieldOptions(columnsInfo, columnName, indexes) {
|
|
166
|
-
const columnInfo = columnsInfo[columnName];
|
|
167
|
-
let fieldOptions = {
|
|
168
|
-
...this.columnAttribute(columnsInfo, columnName, indexes),
|
|
169
|
-
...import_database.ViewFieldInference.inferToFieldType({
|
|
170
|
-
dialect: this.db.options.dialect,
|
|
171
|
-
type: columnInfo.type,
|
|
172
|
-
name: columnName
|
|
173
|
-
}),
|
|
174
|
-
rawType: columnInfo.type,
|
|
175
|
-
name: columnName
|
|
176
|
-
};
|
|
177
|
-
const interfaceConfig = this.getDefaultInterfaceByType(columnsInfo, columnName, fieldOptions.type);
|
|
178
|
-
if (typeof interfaceConfig === "string") {
|
|
179
|
-
fieldOptions.interface = interfaceConfig;
|
|
180
|
-
} else {
|
|
181
|
-
fieldOptions = {
|
|
182
|
-
...fieldOptions,
|
|
183
|
-
...interfaceConfig
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
if (!fieldOptions.type) {
|
|
187
|
-
return {
|
|
188
|
-
rawType: columnInfo.type,
|
|
189
|
-
name: columnName,
|
|
190
|
-
supported: false
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
import_lodash.default.set(fieldOptions, "uiSchema.title", columnName);
|
|
194
|
-
return fieldOptions;
|
|
195
|
-
}
|
|
196
|
-
getDefaultInterfaceByType(columnsInfo, columnName, type) {
|
|
197
|
-
const interfaceConfig = import_type_interface_map.default[type];
|
|
198
|
-
if (typeof interfaceConfig === "function") {
|
|
199
|
-
return interfaceConfig(columnsInfo[columnName]);
|
|
200
|
-
}
|
|
201
|
-
return interfaceConfig;
|
|
202
|
-
}
|
|
203
|
-
columnAttribute(columnsInfo, columnName, indexes) {
|
|
204
|
-
const columnInfo = columnsInfo[columnName];
|
|
205
|
-
const attr = {
|
|
206
|
-
type: columnInfo.type,
|
|
207
|
-
allowNull: columnInfo.allowNull,
|
|
208
|
-
primaryKey: columnInfo.primaryKey,
|
|
209
|
-
unique: false
|
|
210
|
-
};
|
|
211
|
-
if (columnInfo.defaultValue && typeof columnInfo.defaultValue === "string") {
|
|
212
|
-
const isSerial = columnInfo.defaultValue.match(/^nextval\(/);
|
|
213
|
-
const isUUID = columnInfo.defaultValue.match(/^uuid_generate_v4\(/);
|
|
214
|
-
if (!isSerial && !isUUID) {
|
|
215
|
-
attr.defaultValue = columnInfo.defaultValue;
|
|
216
|
-
}
|
|
217
|
-
if (isSerial || isUUID) {
|
|
218
|
-
attr.autoIncrement = true;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
for (const index of indexes) {
|
|
222
|
-
if (index.fields.length == 1 && index.fields[0].attribute == columnName && index.unique) {
|
|
223
|
-
attr.unique = true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (attr.primaryKey && columnName == "id") {
|
|
227
|
-
attr.autoIncrement = true;
|
|
228
|
-
}
|
|
229
|
-
return attr;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
-
0 && (module.exports = {
|
|
234
|
-
DatabaseIntrospector
|
|
235
|
-
});
|