@tachybase/database 0.23.17 → 0.23.20

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.
@@ -83,6 +83,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
83
83
  findField(callback: (field: Field) => boolean): any;
84
84
  hasField(name: string): boolean;
85
85
  getField<F extends Field>(name: string): F;
86
+ getFieldByField(field: string): Field;
86
87
  getFields(): any[];
87
88
  addField(name: string, options: FieldOptions): Field;
88
89
  checkFieldType(name: string, options: FieldOptions): void;
package/lib/collection.js CHANGED
@@ -210,7 +210,7 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
210
210
  if (typeof repository === "string") {
211
211
  repo = this.context.database.repositories.get(repository) || import_repository.Repository;
212
212
  }
213
- if (this.options.tree == "adjacency-list" || this.options.tree == "adjacencyList") {
213
+ if (this.options.tree === "adjacency-list" || this.options.tree === "adjacencyList") {
214
214
  repo = import_adjacency_list_repository.AdjacencyListRepository;
215
215
  }
216
216
  this.repository = new repo(this);
@@ -227,6 +227,9 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
227
227
  getField(name) {
228
228
  return this.fields.get(name);
229
229
  }
230
+ getFieldByField(field) {
231
+ return this.findField((f) => f.options.field === field);
232
+ }
230
233
  getFields() {
231
234
  return [...this.fields.values()];
232
235
  }
@@ -291,7 +294,7 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
291
294
  }
292
295
  );
293
296
  const oldField = this.fields.get(name);
294
- if (oldField && oldField.options.inherit && field.typeToString() != oldField.typeToString()) {
297
+ if (oldField && oldField.options.inherit && field.typeToString() !== oldField.typeToString()) {
295
298
  throw new Error(
296
299
  `Field type conflict: cannot set "${name}" on "${this.name}" to ${options.type}, parent "${name}" type is ${oldField.options.type}`
297
300
  );
@@ -387,12 +390,15 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
387
390
  field.remove();
388
391
  return;
389
392
  }
390
- const columnReferencesCount = import_lodash.default.filter(this.model.rawAttributes, (attr) => attr.field == field.columnName()).length;
393
+ const columnReferencesCount = import_lodash.default.filter(
394
+ this.model.rawAttributes,
395
+ (attr) => attr.field === field.columnName()
396
+ ).length;
391
397
  if (await field.existsInDb({
392
398
  transaction: options == null ? void 0 : options.transaction
393
- }) && columnReferencesCount == 1) {
399
+ }) && columnReferencesCount === 1) {
394
400
  const columns = await this.model.sequelize.getQueryInterface().describeTable(this.getTableNameWithSchema(), options);
395
- if (Object.keys(columns).length == 1) {
401
+ if (Object.keys(columns).length === 1) {
396
402
  await this.removeFromDb({
397
403
  ...options,
398
404
  cascade: true,
@@ -669,7 +675,7 @@ const _Collection = class _Collection extends (_a = import_events.EventEmitter,
669
675
  checkTableName() {
670
676
  const tableName = this.tableName();
671
677
  for (const [k, collection] of this.db.collections) {
672
- if (collection.name != this.options.name && tableName === collection.tableName() && collection.collectionSchema() === this.collectionSchema()) {
678
+ if (collection.name !== this.options.name && tableName === collection.tableName() && collection.collectionSchema() === this.collectionSchema()) {
673
679
  throw new Error(`collection ${collection.name} and ${this.name} have same tableName "${tableName}"`);
674
680
  }
675
681
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/database",
3
- "version": "0.23.17",
3
+ "version": "0.23.20",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./lib/index.js",
@@ -24,8 +24,8 @@
24
24
  "semver": "^7.6.3",
25
25
  "sequelize": "^6.37.5",
26
26
  "umzug": "^3.8.2",
27
- "@tachybase/logger": "0.23.17",
28
- "@tachybase/utils": "0.23.17"
27
+ "@tachybase/logger": "0.23.20",
28
+ "@tachybase/utils": "0.23.20"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/flat": "^5.0.5",