@nocobase/data-source-manager 2.0.39 → 2.0.41

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.
@@ -23,4 +23,6 @@ export declare abstract class DatabaseDataSource<T extends DatabaseIntrospector
23
23
  };
24
24
  }): CollectionOptions[];
25
25
  private mergeFieldOptions;
26
+ private hasCompatibleStorageType;
27
+ private getFieldStorageType;
26
28
  }
@@ -101,7 +101,8 @@ const _DatabaseDataSource = class _DatabaseDataSource extends import_data_source
101
101
  ...modelOptions
102
102
  };
103
103
  const incomingPossibleTypes = Array.isArray(fieldOptions.possibleTypes) ? fieldOptions.possibleTypes : fieldOptions.type ? [fieldOptions.type] : [];
104
- const shouldUseIncomingType = Boolean(fieldOptions.rawType) && (modelOptions.rawType ? fieldOptions.rawType !== modelOptions.rawType : !incomingPossibleTypes.includes(modelOptions.type));
104
+ const hasCompatibleStorageType = this.hasCompatibleStorageType(fieldOptions.type, modelOptions.type);
105
+ const shouldUseIncomingType = Boolean(fieldOptions.rawType) && Boolean(modelOptions.rawType || modelOptions.type) && (modelOptions.rawType ? fieldOptions.rawType !== modelOptions.rawType && !hasCompatibleStorageType : !incomingPossibleTypes.includes(modelOptions.type) && !hasCompatibleStorageType);
105
106
  if (shouldUseIncomingType) {
106
107
  newOptions.type = fieldOptions.type;
107
108
  newOptions.interface = fieldOptions.interface;
@@ -114,6 +115,60 @@ const _DatabaseDataSource = class _DatabaseDataSource extends import_data_source
114
115
  }
115
116
  return newOptions;
116
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
+ }
117
172
  };
118
173
  __name(_DatabaseDataSource, "DatabaseDataSource");
119
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.39",
3
+ "version": "2.0.41",
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.39",
10
- "@nocobase/cache": "2.0.39",
11
- "@nocobase/database": "2.0.39",
12
- "@nocobase/resourcer": "2.0.39",
13
- "@nocobase/utils": "2.0.39",
9
+ "@nocobase/actions": "2.0.41",
10
+ "@nocobase/cache": "2.0.41",
11
+ "@nocobase/database": "2.0.41",
12
+ "@nocobase/resourcer": "2.0.41",
13
+ "@nocobase/utils": "2.0.41",
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": "1bef474287b73aeef2580e2b949a587435639756"
22
+ "gitHead": "53a937012eb64a52cf0776a2193dce41c7c90ac5"
23
23
  }