@nocobase/data-source-manager 2.0.38 → 2.0.40
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.
|
@@ -58,19 +58,34 @@ const _DatabaseDataSource = class _DatabaseDataSource extends import_data_source
|
|
|
58
58
|
const loadedCollection = loadedCollections[collection.name];
|
|
59
59
|
if (!loadedCollection) return collection;
|
|
60
60
|
const collectionFields = collection.fields || [];
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const loadedFieldsByName = Object.fromEntries((loadedCollection.fields || []).map((f) => [f.name, f]));
|
|
62
|
+
const loadedFieldsByColumn = (loadedCollection.fields || []).reduce(
|
|
63
|
+
(result, field) => {
|
|
64
|
+
const key = field.columnName || field.field || field.name;
|
|
65
|
+
result[key] = result[key] || [];
|
|
66
|
+
result[key].push(field);
|
|
67
|
+
return result;
|
|
68
|
+
},
|
|
69
|
+
{}
|
|
63
70
|
);
|
|
71
|
+
const isAliasField = /* @__PURE__ */ __name((field) => Boolean((field == null ? void 0 : field.field) && field.name !== field.field), "isAliasField");
|
|
64
72
|
const newFields = collectionFields.map((field) => {
|
|
65
|
-
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const loadedField = loadedFieldsByName[field.name] || ((_a = loadedFieldsByColumn[field.columnName || field.field || field.name]) == null ? void 0 : _a.find(
|
|
75
|
+
(candidate) => !isAliasField(candidate)
|
|
76
|
+
)) || ((_b = loadedFieldsByColumn[field.columnName || field.field || field.name]) == null ? void 0 : _b[0]);
|
|
66
77
|
if (!loadedField) return field;
|
|
67
78
|
if (loadedField.possibleTypes) {
|
|
68
79
|
loadedField.possibleTypes = field.possibleTypes;
|
|
69
80
|
}
|
|
70
81
|
return this.mergeFieldOptions(field, loadedField);
|
|
71
82
|
});
|
|
83
|
+
const loadedMappedFields = (loadedCollection.fields || []).filter(
|
|
84
|
+
(field) => isAliasField(field) && !newFields.find((newField) => newField.name === field.name)
|
|
85
|
+
);
|
|
86
|
+
newFields.push(...loadedMappedFields);
|
|
72
87
|
const loadedAssociationFields = (loadedCollection.fields || []).filter(
|
|
73
|
-
(field) => ["belongsTo", "belongsToMany", "hasMany", "hasOne", "belongsToArray"].includes(field.type)
|
|
88
|
+
(field) => ["belongsTo", "belongsToMany", "hasMany", "hasOne", "belongsToArray"].includes(field.type) && !newFields.find((newField) => newField.name === field.name)
|
|
74
89
|
);
|
|
75
90
|
newFields.push(...loadedAssociationFields);
|
|
76
91
|
return {
|
|
@@ -86,7 +101,8 @@ const _DatabaseDataSource = class _DatabaseDataSource extends import_data_source
|
|
|
86
101
|
...modelOptions
|
|
87
102
|
};
|
|
88
103
|
const incomingPossibleTypes = Array.isArray(fieldOptions.possibleTypes) ? fieldOptions.possibleTypes : fieldOptions.type ? [fieldOptions.type] : [];
|
|
89
|
-
const
|
|
104
|
+
const hasCompatibleStorageType = this.hasCompatibleStorageType(fieldOptions.type, modelOptions.type);
|
|
105
|
+
const shouldUseIncomingType = Boolean(fieldOptions.rawType) && (modelOptions.rawType ? fieldOptions.rawType !== modelOptions.rawType && !hasCompatibleStorageType : !incomingPossibleTypes.includes(modelOptions.type) && !hasCompatibleStorageType);
|
|
90
106
|
if (shouldUseIncomingType) {
|
|
91
107
|
newOptions.type = fieldOptions.type;
|
|
92
108
|
newOptions.interface = fieldOptions.interface;
|
|
@@ -99,6 +115,60 @@ const _DatabaseDataSource = class _DatabaseDataSource extends import_data_source
|
|
|
99
115
|
}
|
|
100
116
|
return newOptions;
|
|
101
117
|
}
|
|
118
|
+
hasCompatibleStorageType(incomingType, loadedType) {
|
|
119
|
+
if (!incomingType || !loadedType || incomingType === loadedType) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const incomingStorageType = this.getFieldStorageType(incomingType);
|
|
123
|
+
const loadedStorageType = this.getFieldStorageType(loadedType);
|
|
124
|
+
if (!incomingStorageType || !loadedStorageType) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return incomingStorageType === loadedStorageType;
|
|
128
|
+
}
|
|
129
|
+
getFieldStorageType(type) {
|
|
130
|
+
var _a, _b, _c, _d;
|
|
131
|
+
if (!type) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const db = (_a = this.collectionManager) == null ? void 0 : _a.db;
|
|
135
|
+
if (!db) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const fieldClass = db.fieldTypes.get(type);
|
|
140
|
+
if (!fieldClass) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const descriptor = Object.getOwnPropertyDescriptor(fieldClass.prototype, "dataType");
|
|
144
|
+
const collection = {
|
|
145
|
+
name: "__sync_probe__",
|
|
146
|
+
options: {
|
|
147
|
+
underscored: false
|
|
148
|
+
},
|
|
149
|
+
isView() {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const dataType = (_b = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _b.call({
|
|
154
|
+
options: {
|
|
155
|
+
type
|
|
156
|
+
},
|
|
157
|
+
database: db,
|
|
158
|
+
collection,
|
|
159
|
+
context: {
|
|
160
|
+
database: db,
|
|
161
|
+
collection
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
if (typeof dataType === "string") {
|
|
165
|
+
return dataType;
|
|
166
|
+
}
|
|
167
|
+
return (dataType == null ? void 0 : dataType.key) || ((_c = dataType == null ? void 0 : dataType.constructor) == null ? void 0 : _c.key) || ((_d = dataType == null ? void 0 : dataType.constructor) == null ? void 0 : _d.name);
|
|
168
|
+
} catch {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
102
172
|
};
|
|
103
173
|
__name(_DatabaseDataSource, "DatabaseDataSource");
|
|
104
174
|
let DatabaseDataSource = _DatabaseDataSource;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/data-source-manager",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.40",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/actions": "2.0.
|
|
10
|
-
"@nocobase/cache": "2.0.
|
|
11
|
-
"@nocobase/database": "2.0.
|
|
12
|
-
"@nocobase/resourcer": "2.0.
|
|
13
|
-
"@nocobase/utils": "2.0.
|
|
9
|
+
"@nocobase/actions": "2.0.40",
|
|
10
|
+
"@nocobase/cache": "2.0.40",
|
|
11
|
+
"@nocobase/database": "2.0.40",
|
|
12
|
+
"@nocobase/resourcer": "2.0.40",
|
|
13
|
+
"@nocobase/utils": "2.0.40",
|
|
14
14
|
"@types/jsonwebtoken": "^8.5.8",
|
|
15
15
|
"jsonwebtoken": "^9.0.2"
|
|
16
16
|
},
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
20
20
|
"directory": "packages/auth"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "31cef2047fddf5a609cc820328bc88eea79c7b82"
|
|
23
23
|
}
|