@nocobase/database 1.9.32 → 1.9.33
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/lib/options-parser.d.ts
CHANGED
package/lib/options-parser.js
CHANGED
|
@@ -274,9 +274,25 @@ const _OptionsParser = class _OptionsParser {
|
|
|
274
274
|
}
|
|
275
275
|
return obj;
|
|
276
276
|
}
|
|
277
|
+
normalizeAppends(appends) {
|
|
278
|
+
if (Array.isArray(appends)) {
|
|
279
|
+
return appends.filter((item) => typeof item === "string" && item.length > 0);
|
|
280
|
+
}
|
|
281
|
+
if (import_lodash.default.isPlainObject(appends)) {
|
|
282
|
+
return Object.values(appends).filter((item) => typeof item === "string" && item.length > 0);
|
|
283
|
+
}
|
|
284
|
+
if (typeof appends === "string" && appends.length > 0) {
|
|
285
|
+
return [appends];
|
|
286
|
+
}
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
277
289
|
parseAppends(appends, filterParams) {
|
|
278
290
|
if (!appends) return filterParams;
|
|
279
|
-
|
|
291
|
+
const appendList = this.normalizeAppends(appends);
|
|
292
|
+
if (!appendList.length) {
|
|
293
|
+
return filterParams;
|
|
294
|
+
}
|
|
295
|
+
const sortedAppends = import_lodash.default.sortBy(appendList, (append) => append.split(".").length);
|
|
280
296
|
const setInclude = /* @__PURE__ */ __name((model, queryParams, append) => {
|
|
281
297
|
var _a;
|
|
282
298
|
const appendWithOptions = this.parseAppendWithOptions(append);
|
|
@@ -362,7 +378,7 @@ const _OptionsParser = class _OptionsParser {
|
|
|
362
378
|
);
|
|
363
379
|
}
|
|
364
380
|
}, "setInclude");
|
|
365
|
-
for (const append of
|
|
381
|
+
for (const append of sortedAppends) {
|
|
366
382
|
setInclude(this.model, filterParams, append);
|
|
367
383
|
}
|
|
368
384
|
debug("filter params: %o", filterParams);
|
|
@@ -11,6 +11,7 @@ import { RelationRepository } from './relation-repository';
|
|
|
11
11
|
import { AssociatedOptions, CountOptions, DestroyOptions, Filter, FindOptions, TargetKey, UpdateOptions, FirstOrCreateOptions } from './types';
|
|
12
12
|
export declare abstract class MultipleRelationRepository extends RelationRepository {
|
|
13
13
|
targetRepositoryFilterOptionsBySourceValue(): Promise<any>;
|
|
14
|
+
private normalizeScope;
|
|
14
15
|
find(options?: FindOptions): Promise<any>;
|
|
15
16
|
findAndCount(options?: FindOptions): Promise<[any[], number]>;
|
|
16
17
|
count(options?: CountOptions): Promise<number>;
|
|
@@ -65,6 +65,16 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
65
65
|
[this.association.foreignKey]: filterForeignKeyValue
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
normalizeScope(scope, model) {
|
|
69
|
+
const result = {};
|
|
70
|
+
for (const [key, value] of Object.entries(scope)) {
|
|
71
|
+
const attr = model.getAttributes()[key];
|
|
72
|
+
if (attr == null ? void 0 : attr.field) {
|
|
73
|
+
result[attr.field] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
68
78
|
async find(options) {
|
|
69
79
|
const targetRepository = this.targetCollection.repository;
|
|
70
80
|
const association = this.association;
|
|
@@ -74,6 +84,9 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
74
84
|
sourceKey: association.targetKey,
|
|
75
85
|
realAs: association.through.model.name
|
|
76
86
|
};
|
|
87
|
+
if (association.through.scope) {
|
|
88
|
+
oneFromTargetOptions["scope"] = this.normalizeScope(association.through.scope, association.through.model);
|
|
89
|
+
}
|
|
77
90
|
const pivotAssoc = new import_sequelize.HasOne(association.target, association.through.model, oneFromTargetOptions);
|
|
78
91
|
const appendFilter = {
|
|
79
92
|
isPivotFilter: true,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.9.
|
|
10
|
-
"@nocobase/utils": "1.9.
|
|
9
|
+
"@nocobase/logger": "1.9.33",
|
|
10
|
+
"@nocobase/utils": "1.9.33",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
40
40
|
"directory": "packages/database"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "705580251f0deffaf2a8c7c85006c770741941d3"
|
|
43
43
|
}
|