@nocobase/database 2.0.0-alpha.52 → 2.0.0-alpha.54

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/collection.js CHANGED
@@ -295,6 +295,7 @@ const _Collection = class _Collection extends import_events.EventEmitter {
295
295
  this.model.options.modelName = this.options.name;
296
296
  if (!autoGenId) {
297
297
  this.model.removeAttribute("id");
298
+ this.model.autoIncrementAttribute = null;
298
299
  }
299
300
  this.model.database = this.context.database;
300
301
  this.model.collection = this;
package/lib/database.js CHANGED
@@ -438,7 +438,7 @@ const _Database = class _Database extends import_events.EventEmitter {
438
438
  this.emit("beforeDefineCollection", options);
439
439
  const collection = this.collectionFactory.createCollection(options);
440
440
  this.collections.set(collection.name, collection);
441
- this.emit("afterDefineCollection", collection);
441
+ this.emit("afterDefineCollection", collection, { fieldModels: options.fieldModels });
442
442
  return collection;
443
443
  }
444
444
  getTablePrefix() {
@@ -487,6 +487,9 @@ const _Database = class _Database extends import_events.EventEmitter {
487
487
  }
488
488
  removeCollection(name) {
489
489
  const collection = this.collections.get(name);
490
+ if (!collection) {
491
+ return;
492
+ }
490
493
  this.emit("beforeRemoveCollection", collection);
491
494
  collection.resetFields();
492
495
  const result = this.collections.delete(name);
@@ -78,7 +78,7 @@ const queryParentSQL = /* @__PURE__ */ __name((options) => {
78
78
  return `WITH RECURSIVE cte AS (
79
79
  SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
80
80
  FROM ${tableName}
81
- WHERE ${q(targetKeyField)} IN (${nodeIds.join(",")})
81
+ WHERE ${q(targetKeyField)} IN ('${nodeIds.join("','")}')
82
82
  UNION ALL
83
83
  SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
84
84
  FROM ${tableName} AS t
@@ -131,12 +131,16 @@ const _Field = class _Field {
131
131
  Object.assign(this.options, obj);
132
132
  }
133
133
  bind() {
134
+ var _a;
134
135
  const { model } = this.context.collection;
135
136
  model.rawAttributes[this.name] = this.toSequelize();
136
137
  model.refreshAttributes();
137
138
  if (this.options.index) {
138
139
  this.context.collection.addIndex([this.name]);
139
140
  }
141
+ if (((_a = this.options) == null ? void 0 : _a.autoIncrement) === true && !model.autoIncrementAttribute) {
142
+ model._findAutoIncrementAttribute();
143
+ }
140
144
  }
141
145
  unbind() {
142
146
  const { model } = this.context.collection;
@@ -49,9 +49,17 @@ const _SnowflakeIdField = class _SnowflakeIdField extends import_field.Field {
49
49
  }
50
50
  }
51
51
  init() {
52
- const { name } = this.options;
53
- this.listener = (instance) => this.setId(name, instance);
52
+ const { name, autoFill } = this.options;
53
+ this.listener = (instance) => {
54
+ if (autoFill === false) {
55
+ return;
56
+ }
57
+ this.setId(name, instance);
58
+ };
54
59
  this.bulkListener = async (instances) => {
60
+ if (autoFill === false) {
61
+ return;
62
+ }
55
63
  for (const instance of instances) {
56
64
  this.setId(name, instance);
57
65
  }
@@ -26,7 +26,9 @@ export declare class OptionsParser {
26
26
  static appendInheritInspectAttribute(include: any, collection: any): any;
27
27
  isAssociation(key: string): boolean;
28
28
  isAssociationPath(path: string): boolean;
29
- filterByTkToWhereOption(): {};
29
+ filterByTkToWhereOption(): string | number | import("./repository").MultiTargetKey[] | {
30
+ [x: string]: import("./repository").TargetKey;
31
+ };
30
32
  toSequelizeParams(options?: {
31
33
  parseSort?: boolean;
32
34
  }): any;
@@ -41,9 +41,9 @@ __export(options_parser_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(options_parser_exports);
43
43
  var import_lodash = __toESM(require("lodash"));
44
+ var import_qs = __toESM(require("qs"));
44
45
  var import_sequelize = require("sequelize");
45
46
  var import_filter_parser = __toESM(require("./filter-parser"));
46
- var import_qs = __toESM(require("qs"));
47
47
  const debug = require("debug")("noco-database");
48
48
  const _OptionsParser = class _OptionsParser {
49
49
  options;
@@ -96,14 +96,21 @@ const _OptionsParser = class _OptionsParser {
96
96
  if (!filterByTkOption) {
97
97
  return {};
98
98
  }
99
- if (import_lodash.default.isPlainObject(this.options.filterByTk)) {
100
- const where = {};
101
- for (const [key, value] of Object.entries(filterByTkOption)) {
102
- where[key] = value;
103
- }
104
- return where;
99
+ if (Array.isArray(filterByTkOption) && filterByTkOption.length === 0) {
100
+ return {};
105
101
  }
106
102
  const filterTargetKey = this.context.targetKey || this.collection.filterTargetKey;
103
+ if (Array.isArray(filterByTkOption) && Array.isArray(filterTargetKey)) {
104
+ if (!filterByTkOption.every(import_lodash.default.isPlainObject)) {
105
+ throw new Error("filterByTk array item must be plain object");
106
+ }
107
+ return {
108
+ [import_sequelize.Op.or]: filterByTkOption
109
+ };
110
+ }
111
+ if (import_lodash.default.isPlainObject(filterByTkOption)) {
112
+ return filterByTkOption;
113
+ }
107
114
  if (Array.isArray(filterTargetKey)) {
108
115
  throw new Error("multi filter target key value must be object");
109
116
  }
@@ -30,7 +30,7 @@ export interface FilterAble {
30
30
  }
31
31
  export type BaseTargetKey = string | number;
32
32
  export type MultiTargetKey = Record<string, BaseTargetKey>;
33
- export type TargetKey = BaseTargetKey | MultiTargetKey;
33
+ export type TargetKey = BaseTargetKey | MultiTargetKey | MultiTargetKey[];
34
34
  export type TK = TargetKey | TargetKey[];
35
35
  type FieldValue = string | number | bigint | boolean | Date | Buffer | null | FieldValue[] | FilterWithOperator;
36
36
  type Operators = keyof typeof operators & keyof WhereOperators;
package/lib/repository.js CHANGED
@@ -71,8 +71,8 @@ var import_hasmany_repository = require("./relation-repository/hasmany-repositor
71
71
  var import_hasone_repository = require("./relation-repository/hasone-repository");
72
72
  var import_update_associations = require("./update-associations");
73
73
  var import_update_guard = require("./update-guard");
74
- var import_filter_utils = require("./utils/filter-utils");
75
74
  var import_utils2 = require("./utils");
75
+ var import_filter_utils = require("./utils/filter-utils");
76
76
  var import_sequelize2 = require("sequelize");
77
77
  const debug = require("debug")("noco-database");
78
78
  const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.0.0-alpha.52",
3
+ "version": "2.0.0-alpha.54",
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": "2.0.0-alpha.52",
10
- "@nocobase/utils": "2.0.0-alpha.52",
9
+ "@nocobase/logger": "2.0.0-alpha.54",
10
+ "@nocobase/utils": "2.0.0-alpha.54",
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": "b32992d8baeb4ca6616d839ca2f9c023d49476a9"
42
+ "gitHead": "68c84deaabba0ebec7407bf7245376b8d843449c"
43
43
  }