@nocobase/database 1.4.0-alpha.8 → 1.4.0-alpha.9

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.
@@ -95,6 +95,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
95
95
  findField(callback: (field: Field) => boolean): any;
96
96
  hasField(name: string): boolean;
97
97
  getField<F extends Field>(name: string): F;
98
+ getFieldByField(field: string): Field;
98
99
  getFields(): any[];
99
100
  addField(name: string, options: FieldOptions): Field;
100
101
  checkFieldType(name: string, options: FieldOptions): void;
package/lib/collection.js CHANGED
@@ -113,6 +113,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
113
113
  var _a;
114
114
  const targetKey = (_a = this.options) == null ? void 0 : _a.filterTargetKey;
115
115
  if (Array.isArray(targetKey)) {
116
+ if (targetKey.length === 1) {
117
+ return targetKey[0];
118
+ }
116
119
  return targetKey;
117
120
  }
118
121
  if (targetKey && this.model.getAttributes()[targetKey]) {
@@ -258,6 +261,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
258
261
  getField(name) {
259
262
  return this.fields.get(name);
260
263
  }
264
+ getFieldByField(field) {
265
+ return this.findField((f) => f.options.field === field);
266
+ }
261
267
  getFields() {
262
268
  return [...this.fields.values()];
263
269
  }
@@ -36,6 +36,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
36
36
  if (!str) {
37
37
  return null;
38
38
  }
39
+ str = `${str}`.trim();
39
40
  const items = str.split(",");
40
41
  const { filterKey, targetCollection, transaction } = ctx;
41
42
  const targetInstances = await targetCollection.repository.find({
@@ -45,7 +46,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
45
46
  transaction
46
47
  });
47
48
  items.forEach((item) => {
48
- if (!targetInstances.find((targetInstance) => targetInstance[filterKey] === item)) {
49
+ if (!targetInstances.find((targetInstance) => targetInstance[filterKey] == item)) {
49
50
  throw new Error(`"${item}" not found in ${targetCollection.model.name} ${filterKey}`);
50
51
  }
51
52
  });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.4.0-alpha.8",
3
+ "version": "1.4.0-alpha.9",
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.4.0-alpha.8",
10
- "@nocobase/utils": "1.4.0-alpha.8",
9
+ "@nocobase/logger": "1.4.0-alpha.9",
10
+ "@nocobase/utils": "1.4.0-alpha.9",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "aa36bd20b2028c5e133a59e922c2f1ab22c86dde"
41
+ "gitHead": "af26b630a5b590f986e21231f0db289c65dd7f70"
42
42
  }